From 2af634d89656f0210b236b692efc774264678bc6 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 26 Sep 2024 16:53:17 -0300 Subject: [PATCH 1/3] l2s init --- .../create-shortened-url.mjs | 83 ++++++++++++++++ components/l2s/l2s.app.mjs | 97 ++++++++++++++++++- components/l2s/package.json | 2 +- 3 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 components/l2s/actions/create-shortened-url/create-shortened-url.mjs diff --git a/components/l2s/actions/create-shortened-url/create-shortened-url.mjs b/components/l2s/actions/create-shortened-url/create-shortened-url.mjs new file mode 100644 index 0000000000000..1bfd344cbda71 --- /dev/null +++ b/components/l2s/actions/create-shortened-url/create-shortened-url.mjs @@ -0,0 +1,83 @@ +import l2s from "../../l2s.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "l2s-create-shortened-url", + name: "Create Shortened URL", + description: "Generates a shortened URL utilizing L2S capabilities. [See the documentation](https://docs.l2s.is/)", + version: "0.0.{{ts}}", + type: "action", + props: { + l2s, + url: { + propDefinition: [ + l2s, + "url", + ], + }, + customKey: { + propDefinition: [ + l2s, + "customKey", + ], + }, + utmSource: { + propDefinition: [ + l2s, + "utmSource", + ], + }, + utmMedium: { + propDefinition: [ + l2s, + "utmMedium", + ], + }, + utmCampaign: { + propDefinition: [ + l2s, + "utmCampaign", + ], + }, + utmTerm: { + propDefinition: [ + l2s, + "utmTerm", + ], + }, + utmContent: { + propDefinition: [ + l2s, + "utmContent", + ], + }, + title: { + propDefinition: [ + l2s, + "title", + ], + }, + tags: { + propDefinition: [ + l2s, + "tags", + ], + }, + }, + async run({ $ }) { + const response = await this.l2s.shortenUrl({ + url: this.url, + customKey: this.customKey, + utmSource: this.utmSource, + utmMedium: this.utmMedium, + utmCampaign: this.utmCampaign, + utmTerm: this.utmTerm, + utmContent: this.utmContent, + title: this.title, + tags: this.tags, + }); + + $.export("$summary", "URL shortened successfully"); + return response; + }, +}; diff --git a/components/l2s/l2s.app.mjs b/components/l2s/l2s.app.mjs index ae1e0a9de75a6..3e6245432d235 100644 --- a/components/l2s/l2s.app.mjs +++ b/components/l2s/l2s.app.mjs @@ -1,11 +1,102 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "l2s", - propDefinitions: {}, + propDefinitions: { + url: { + type: "string", + label: "URL", + description: "The URL to be shortened", + }, + customKey: { + type: "string", + label: "Custom Key", + description: "Custom key for the shortened URL", + optional: true, + }, + utmSource: { + type: "string", + label: "UTM Source", + description: "UTM source parameter", + optional: true, + }, + utmMedium: { + type: "string", + label: "UTM Medium", + description: "UTM medium parameter", + optional: true, + }, + utmCampaign: { + type: "string", + label: "UTM Campaign", + description: "UTM campaign parameter", + optional: true, + }, + utmTerm: { + type: "string", + label: "UTM Term", + description: "UTM term parameter", + optional: true, + }, + utmContent: { + type: "string", + label: "UTM Content", + description: "UTM content parameter", + optional: true, + }, + title: { + type: "string", + label: "Title", + description: "Title for the shortened URL", + optional: true, + }, + tags: { + type: "string[]", + label: "Tags", + description: "Tags associated with the URL", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data authKeys() { console.log(Object.keys(this.$auth)); }, + _baseUrl() { + return "https://api.l2s.is"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, method = "POST", path = "/url", headers, data, + } = opts; + return axios($, { + method, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_token}`, + }, + data, + }); + }, + async shortenUrl(opts = {}) { + const { + url, customKey, utmSource, utmMedium, utmCampaign, utmTerm, utmContent, title, tags, + } = opts; + const data = { + url, + customKey, + utmSource, + utmMedium, + utmCampaign, + utmTerm, + utmContent, + title, + tags, + }; + return this._makeRequest({ + data, + }); + }, }, -}; \ No newline at end of file +}; diff --git a/components/l2s/package.json b/components/l2s/package.json index e05e3f6f52aa9..1a4445cbb82d9 100644 --- a/components/l2s/package.json +++ b/components/l2s/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} From 2aae9a9a4fcf7b8a1201f8335845673c5d1bd7ae Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 27 Sep 2024 11:58:19 -0300 Subject: [PATCH 2/3] [Components] l2s #14107 Actions - Create Shortened URL --- .../create-shortened-url.mjs | 104 +++++++++--------- components/l2s/common/utils.mjs | 24 ++++ components/l2s/l2s.app.mjs | 98 +++-------------- components/l2s/package.json | 5 +- 4 files changed, 97 insertions(+), 134 deletions(-) create mode 100644 components/l2s/common/utils.mjs diff --git a/components/l2s/actions/create-shortened-url/create-shortened-url.mjs b/components/l2s/actions/create-shortened-url/create-shortened-url.mjs index 1bfd344cbda71..6b1b0de8aaab8 100644 --- a/components/l2s/actions/create-shortened-url/create-shortened-url.mjs +++ b/components/l2s/actions/create-shortened-url/create-shortened-url.mjs @@ -1,83 +1,89 @@ +import { parseObject } from "../../common/utils.mjs"; import l2s from "../../l2s.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "l2s-create-shortened-url", name: "Create Shortened URL", description: "Generates a shortened URL utilizing L2S capabilities. [See the documentation](https://docs.l2s.is/)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { l2s, url: { - propDefinition: [ - l2s, - "url", - ], + type: "string", + label: "URL", + description: "The URL to be shortened", }, customKey: { - propDefinition: [ - l2s, - "customKey", - ], + type: "string", + label: "Custom Key", + description: "Custom key for the shortened URL", + optional: true, }, utmSource: { - propDefinition: [ - l2s, - "utmSource", - ], + type: "string", + label: "UTM Source", + description: "UTM source parameter", + optional: true, }, utmMedium: { - propDefinition: [ - l2s, - "utmMedium", - ], + type: "string", + label: "UTM Medium", + description: "UTM medium parameter", + optional: true, }, utmCampaign: { - propDefinition: [ - l2s, - "utmCampaign", - ], + type: "string", + label: "UTM Campaign", + description: "UTM campaign parameter", + optional: true, }, utmTerm: { - propDefinition: [ - l2s, - "utmTerm", - ], + type: "string", + label: "UTM Term", + description: "UTM term parameter", + optional: true, }, utmContent: { - propDefinition: [ - l2s, - "utmContent", - ], + type: "string", + label: "UTM Content", + description: "UTM content parameter", + optional: true, }, title: { - propDefinition: [ - l2s, - "title", - ], + type: "string", + label: "Title", + description: "Title for the shortened URL", + optional: true, }, tags: { - propDefinition: [ - l2s, - "tags", - ], + type: "string[]", + label: "Tags", + description: "Tags associated with the URL", + optional: true, }, }, async run({ $ }) { - const response = await this.l2s.shortenUrl({ - url: this.url, - customKey: this.customKey, - utmSource: this.utmSource, - utmMedium: this.utmMedium, - utmCampaign: this.utmCampaign, - utmTerm: this.utmTerm, - utmContent: this.utmContent, - title: this.title, - tags: this.tags, + const { + l2s, + tags, + ...data + } = this; + + if (tags) { + data.tags = parseObject(tags); + } + + const { response: { data: response } } = await l2s.shortenUrl({ + $, + data, }); + const shortUrl = `https://l2s.is/${response.key}`; $.export("$summary", "URL shortened successfully"); - return response; + return { + short_url: shortUrl, + ...response, + }; }, }; diff --git a/components/l2s/common/utils.mjs b/components/l2s/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/l2s/common/utils.mjs @@ -0,0 +1,24 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/l2s/l2s.app.mjs b/components/l2s/l2s.app.mjs index 3e6245432d235..9bee2e562f036 100644 --- a/components/l2s/l2s.app.mjs +++ b/components/l2s/l2s.app.mjs @@ -3,99 +3,29 @@ import { axios } from "@pipedream/platform"; export default { type: "app", app: "l2s", - propDefinitions: { - url: { - type: "string", - label: "URL", - description: "The URL to be shortened", - }, - customKey: { - type: "string", - label: "Custom Key", - description: "Custom key for the shortened URL", - optional: true, - }, - utmSource: { - type: "string", - label: "UTM Source", - description: "UTM source parameter", - optional: true, - }, - utmMedium: { - type: "string", - label: "UTM Medium", - description: "UTM medium parameter", - optional: true, - }, - utmCampaign: { - type: "string", - label: "UTM Campaign", - description: "UTM campaign parameter", - optional: true, - }, - utmTerm: { - type: "string", - label: "UTM Term", - description: "UTM term parameter", - optional: true, - }, - utmContent: { - type: "string", - label: "UTM Content", - description: "UTM content parameter", - optional: true, - }, - title: { - type: "string", - label: "Title", - description: "Title for the shortened URL", - optional: true, - }, - tags: { - type: "string[]", - label: "Tags", - description: "Tags associated with the URL", - optional: true, - }, - }, methods: { - authKeys() { - console.log(Object.keys(this.$auth)); - }, _baseUrl() { return "https://api.l2s.is"; }, - async _makeRequest(opts = {}) { - const { - $ = this, method = "POST", path = "/url", headers, data, - } = opts; + _headers() { + return { + Authorization: `Bearer ${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - method, url: this._baseUrl() + path, - headers: { - ...headers, - Authorization: `Bearer ${this.$auth.api_token}`, - }, - data, + headers: this._headers(), + ...opts, }); }, - async shortenUrl(opts = {}) { - const { - url, customKey, utmSource, utmMedium, utmCampaign, utmTerm, utmContent, title, tags, - } = opts; - const data = { - url, - customKey, - utmSource, - utmMedium, - utmCampaign, - utmTerm, - utmContent, - title, - tags, - }; + shortenUrl(opts = {}) { return this._makeRequest({ - data, + method: "POST", + path: "/url", + ...opts, }); }, }, diff --git a/components/l2s/package.json b/components/l2s/package.json index 1a4445cbb82d9..3fdf999b84f21 100644 --- a/components/l2s/package.json +++ b/components/l2s/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/l2s", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream L2S Components", "main": "l2s.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.1" } } From 1207fb0b17a3cce7e6a799ec15793d0b87608634 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 27 Sep 2024 12:00:03 -0300 Subject: [PATCH 3/3] pnpm update --- pnpm-lock.yaml | 107 +++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6f7260f345fb4..b7cbf05190d99 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5229,7 +5229,10 @@ importers: specifiers: {} components/l2s: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.1 + dependencies: + '@pipedream/platform': 3.0.3 components/l3mbda: specifiers: @@ -12815,6 +12818,55 @@ packages: - aws-crt dev: false + /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: + resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - '@aws-sdk/client-sts' + - aws-crt + dev: false + /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -13050,7 +13102,7 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -13092,55 +13144,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: - resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sso-oidc' - - aws-crt - dev: false - /@aws-sdk/core/3.556.0: resolution: {integrity: sha512-vJaSaHw2kPQlo11j/Rzuz0gk1tEaKdz+2ser0f0qZ5vwFlANjt08m/frU17ctnVKC1s58bxpctO/1P894fHLrA==} engines: {node: '>=14.0.0'} @@ -17467,7 +17470,7 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq + '@aws-sdk/client-sts': 3.600.0 '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 '@pipedream/platform': 1.6.6