From 2d6d0e0ff1802c6713bb649062cfef84908f47cd Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Mon, 16 Sep 2024 09:56:57 -0300 Subject: [PATCH 1/2] Added actions --- .../get-content-items/get-content-items.mjs | 28 ++ .../get-content-models/get-content-models.mjs | 21 ++ .../agility_cms/actions/get-item/get-item.mjs | 38 +++ components/agility_cms/agility_cms.app.mjs | 75 ++++- components/agility_cms/common/constants.mjs | 308 ++++++++++++++++++ components/agility_cms/package.json | 5 +- pnpm-lock.yaml | 16 +- 7 files changed, 484 insertions(+), 7 deletions(-) create mode 100644 components/agility_cms/actions/get-content-items/get-content-items.mjs create mode 100644 components/agility_cms/actions/get-content-models/get-content-models.mjs create mode 100644 components/agility_cms/actions/get-item/get-item.mjs create mode 100644 components/agility_cms/common/constants.mjs diff --git a/components/agility_cms/actions/get-content-items/get-content-items.mjs b/components/agility_cms/actions/get-content-items/get-content-items.mjs new file mode 100644 index 0000000000000..927bb20da1333 --- /dev/null +++ b/components/agility_cms/actions/get-content-items/get-content-items.mjs @@ -0,0 +1,28 @@ +import app from "../../agility_cms.app.mjs"; + +export default { + key: "agility_cms-get-content-items", + name: "Get Content Items", + description: "Retrieves all content items. [See the documentation](https://api.aglty.io/swagger/index.html#operations-Sync-get__guid___apitype___locale__sync_items)", + version: "0.0.1", + type: "action", + props: { + app, + locale: { + propDefinition: [ + app, + "locale", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getItems({ + $, + locale: this.locale, + }); + + $.export("$summary", `Successfully retrieved ${response.items.length} Items`); + + return response; + }, +}; diff --git a/components/agility_cms/actions/get-content-models/get-content-models.mjs b/components/agility_cms/actions/get-content-models/get-content-models.mjs new file mode 100644 index 0000000000000..5521d2896dc6e --- /dev/null +++ b/components/agility_cms/actions/get-content-models/get-content-models.mjs @@ -0,0 +1,21 @@ +import app from "../../agility_cms.app.mjs"; + +export default { + key: "agility_cms-get-content-models", + name: "Get Content Models", + description: "Retrieve content models for the Agility instance. [See the documentation](https://api.aglty.io/swagger/index.html#operations-ContentModels-get__guid___apitype__contentmodels)", + version: "0.0.1", + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.getContentModels({ + $, + }); + + $.export("$summary", `Successfully retrieved ${Object.keys(response).length} content models`); + + return response; + }, +}; diff --git a/components/agility_cms/actions/get-item/get-item.mjs b/components/agility_cms/actions/get-item/get-item.mjs new file mode 100644 index 0000000000000..fc35ced2d6cc8 --- /dev/null +++ b/components/agility_cms/actions/get-item/get-item.mjs @@ -0,0 +1,38 @@ +import app from "../../agility_cms.app.mjs"; + +export default { + key: "agility_cms-get-item", + name: "Get Item Details", + description: "Get details of the specified item. [See the documentation](https://api.aglty.io/swagger/index.html#operations-Item-get__guid___apitype___locale__item__id_)", + version: "0.0.1", + type: "action", + props: { + app, + locale: { + propDefinition: [ + app, + "locale", + ], + }, + itemId: { + propDefinition: [ + app, + "itemId", + (c) => ({ + locale: c.locale, + }), + ], + }, + }, + async run({ $ }) { + const response = await this.app.getItem({ + $, + locale: this.locale, + itemId: this.itemId, + }); + + $.export("$summary", `Successfully retrieved details of item ID '${response.contentID}'`); + + return response; + }, +}; diff --git a/components/agility_cms/agility_cms.app.mjs b/components/agility_cms/agility_cms.app.mjs index efccd252d7e44..c32458f84bb42 100644 --- a/components/agility_cms/agility_cms.app.mjs +++ b/components/agility_cms/agility_cms.app.mjs @@ -1,11 +1,76 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "agility_cms", - propDefinitions: {}, + propDefinitions: { + locale: { + type: "string", + label: "Locale", + description: "The locale code you want to retrieve content for (it must already be in `Locales Settings` of your Agility account)", + options: constants.LOCALE_OPTIONS, + default: "en-us", + }, + itemId: { + type: "string", + label: "Item ID", + description: "ID of the item to get details of", + async options({ locale }) { + const response = await this.getItems({ + locale, + }); + const itemsIds = response.items; + return itemsIds.map(({ + contentID, properties, + }) => ({ + value: contentID, + label: properties.referenceName, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `${this.$auth.api_url}/${this.$auth.guid}/${this.$auth.api_type}`; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "APIKey": `${this.$auth.api_key}`, + }, + }); + }, + async getContentModels(args = {}) { + return this._makeRequest({ + path: "/contentmodels", + ...args, + }); + }, + async getItems({ + locale, ...args + }) { + return this._makeRequest({ + path: `/${locale}/sync/items`, + ...args, + }); + }, + async getItem({ + locale, itemId, ...args + }) { + return this._makeRequest({ + path: `/${locale}/item/${itemId}`, + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/agility_cms/common/constants.mjs b/components/agility_cms/common/constants.mjs new file mode 100644 index 0000000000000..26c4cca06e8fc --- /dev/null +++ b/components/agility_cms/common/constants.mjs @@ -0,0 +1,308 @@ +export default { + LOCALE_OPTIONS: [ + { + value: "af-ZA", + label: "Afrikaans (South Africa)", + }, + { + value: "es-HN", + label: "Spanish (Honduras)", + }, + { + value: "ar-AE", + label: "Arabic (United Arab Emirates)", + }, + { + value: "es-LA", + label: "Spanish (Spanish)", + }, + { + value: "ar-AR", + label: "Arabic (Arabic)", + }, + { + value: "es-MX", + label: "Spanish (Mexico)", + }, + { + value: "ar-BH", + label: "Arabic (Bahrain)", + }, + { + value: "es-NI", + label: "Spanish (Nicaragua)", + }, + { + value: "ar-DJ", + label: "Arabic (Djibouti)", + }, + { + value: "es-PA", + label: "Spanish (Panama)", + }, + { + value: "ar-DZ", + label: "Arabic (Algeria)", + }, + { + value: "es-PE", + label: "Spanish (Peru)", + }, + { + value: "ar-EG", + label: "Arabic (Egypt)", + }, + { + value: "es-PR", + label: "Spanish (Puerto Rico)", + }, + { + value: "ar-EH", + label: "Arabic (Western Sahara)", + }, + { + value: "es-PY", + label: "Spanish (Paraguay)", + }, + { + value: "ar-ER", + label: "Arabic (Eritrea)", + }, + { + value: "es-SV", + label: "Spanish (El Salvador)", + }, + { + value: "ar-IL", + label: "Arabic (Israel)", + }, + { + value: "es-US", + label: "Spanish (United States)", + }, + { + value: "ar-IQ", + label: "Arabic (Iraq)", + }, + { + value: "es-UY", + label: "Spanish (Uruguay)", + }, + { + value: "ar-JO", + label: "Arabic (Jordan)", + }, + { + value: "es-VE", + label: "Spanish (Venezuela)", + }, + { + value: "ar-KM", + label: "Arabic (Comoros)", + }, + { + value: "et-EE", + label: "Estonian (Estonia)", + }, + { + value: "ar-KW", + label: "Arabic (Kuwait)", + }, + { + value: "eu-ES", + label: "Basque (Spain)", + }, + { + value: "ar-LB", + label: "Arabic (Lebanon)", + }, + { + value: "fa-IR", + label: "Persian (Iran)", + }, + { + value: "ar-LY", + label: "Arabic (Libya)", + }, + { + value: "fb-LT", + label: "Leet Speak", + }, + { + value: "ar-MA", + label: "Arabic (Morocco)", + }, + { + value: "fi-FI", + label: "Finnish (Finland)", + }, + { + value: "ar-MR", + label: "Arabic (Mauritania)", + }, + { + value: "fo-FO", + label: "Faroese (Faeroe Islands)", + }, + { + value: "ar-OM", + label: "Arabic (Oman)", + }, + { + value: "fr-BE", + label: "French (Belgium)", + }, + { + value: "ar-PS", + label: "Arabic (West Bank and Gaza)", + }, + { + value: "fr-BF", + label: "French (Burkina Faso)", + }, + { + value: "ar-QA", + label: "Arabic (Qatar)", + }, + { + value: "fr-BI", + label: "French (Burundi)", + }, + { + value: "ar-SA", + label: "Arabic (Saudi Arabia)", + }, + { + value: "fr-BJ", + label: "French (Benin)", + }, + { + value: "ar-SD", + label: "Arabic (Sudan)", + }, + { + value: "fr-CA", + label: "French (Canada)", + }, + { + value: "ar-SO", + label: "Arabic (Somalia)", + }, + { + value: "fr-CD", + label: "French (Dem. Rep. Congo)", + }, + { + value: "ar-SY", + label: "Arabic (Syria)", + }, + { + value: "fr-CF", + label: "French (Central African Republic)", + }, + { + value: "ar-TD", + label: "Arabic (Chad)", + }, + { + value: "fr-CG", + label: "French (Congo)", + }, + { + value: "ar-TN", + label: "Arabic (Tunisia)", + }, + { + value: "fr-CH", + label: "French (Switzerland)", + }, + { + value: "ar-YE", + label: "Arabic (Yemen)", + }, + { + value: "fr-CI", + label: "French (Côte d'Ivoire)", + }, + { + value: "az-AZ", + label: "Azerbaijani (Azerbaijan)", + }, + { + value: "fr-CM", + label: "French (Cameroon)", + }, + { + value: "be-BY", + label: "Belarusian (Belarus)", + }, + { + value: "fr-DJ", + label: "French (Djibouti)", + }, + { + value: "bg-BG", + label: "Bulgarian (Bulgaria)", + }, + { + value: "fr-FR", + label: "French (France)", + }, + { + value: "bn-IN", + label: "Bengali (India)", + }, + { + value: "fr-GA", + label: "French (Gabon)", + }, + { + value: "bs-BA", + label: "Bosnian (Bosnia and Herzegovina)", + }, + { + value: "fr-GD", + label: "French (Grenada)", + }, + { + value: "ca-AD", + label: "Catalan (Andorra)", + }, + { + value: "fr-GF", + label: "French (French Guianna)", + }, + { + value: "ca-ES", + label: "Catalan (Spain)", + }, + { + value: "fr-GN", + label: "French (Guinea)", + }, + { + value: "cs-CZ", + label: "Czech (Czech Republic)", + }, + { + value: "fr-GP", + label: "French (Guadeloupe)", + }, + { + value: "cs-SK", + label: "Czech (Slovak Republic)", + }, + { + value: "fr-GQ", + label: "French (Equatorial Guinea)", + }, + { + value: "cy-GB", + label: "Welsh (United Kingdom)", + }, + { + value: "fr-HT", + label: "French (Haiti)", + }, + ], +}; diff --git a/components/agility_cms/package.json b/components/agility_cms/package.json index fd33013efeed9..b3339b1a0cb31 100644 --- a/components/agility_cms/package.json +++ b/components/agility_cms/package.json @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.2" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eb4f815bd773b..9fde4af289a00 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -313,7 +313,10 @@ importers: '@pipedream/platform': 3.0.1 components/agility_cms: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.2 + dependencies: + '@pipedream/platform': 3.0.2 components/agrello: specifiers: {} @@ -17488,6 +17491,17 @@ packages: - debug dev: false + /@pipedream/platform/3.0.2: + resolution: {integrity: sha512-q/BYGJoNXOVaRlNTDWD7Gjgkcu114gbPrxQ5KCOFbuYfqnJu8AeDGMyMvEPaGPbrWUVwgxjvOnxw4EWqce8ZNQ==} + dependencies: + axios: 1.7.7 + fp-ts: 2.16.9 + io-ts: 2.2.21_fp-ts@2.16.9 + querystring: 0.2.1 + transitivePeerDependencies: + - debug + dev: false + /@pipedream/snowflake-sdk/1.0.8_asn1.js@5.4.1: resolution: {integrity: sha512-/nLCQNjlSCz71MUnOUZqWmnjZTbEX7mie91mstPspb8uDG/GvaDk/RynLGhhYfgEP5d1KWj+OPaI71hmPSxReg==} dependencies: From 0e65ef62c7b73836f47ec5ba66fcefc8d0db0a62 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Mon, 16 Sep 2024 09:59:48 -0300 Subject: [PATCH 2/2] Added actions --- components/agility_cms/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/agility_cms/package.json b/components/agility_cms/package.json index b3339b1a0cb31..530c8c9449b53 100644 --- a/components/agility_cms/package.json +++ b/components/agility_cms/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/agility_cms", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Agility CMS Components", "main": "agility_cms.app.mjs", "keywords": [