diff --git a/components/imagior/actions/generate-image/generate-image.mjs b/components/imagior/actions/generate-image/generate-image.mjs new file mode 100644 index 0000000000000..b377d7839bbf3 --- /dev/null +++ b/components/imagior/actions/generate-image/generate-image.mjs @@ -0,0 +1,80 @@ +import imagior from "../../imagior.app.mjs"; + +export default { + key: "imagior-generate-image", + name: "Generate Image", + description: "Generates a unique and robust image using a provided template. [See the documentation](https://docs.imagior.com/api-reference/image-generate)", + version: "0.0.1", + type: "action", + props: { + imagior, + templateId: { + propDefinition: [ + imagior, + "templateId", + ], + reloadProps: true, + }, + }, + async additionalProps() { + const props = {}; + if (!this.templateId) { + return props; + } + const { elements } = await this.imagior.listTemplateElements({ + templateId: this.templateId, + }); + for (const [ + key, + value, + ] of Object.entries(elements)) { + props[`customize_${key}`] = { + type: "boolean", + label: `Customize ${key}`, + optional: true, + reloadProps: true, + }; + if (this[`customize_${key}`]) { + for (const elementKey of Object.keys(value)) { + props[`${key}_${elementKey}`] = { + type: "string", + label: `${key} - ${elementKey}`, + optional: true, + }; + } + } + } + return props; + }, + async run({ $ }) { + const elements = {}; + const { elements: allElements } = await this.imagior.listTemplateElements({ + $, + templateId: this.templateId, + }); + for (const [ + key, + value, + ] of Object.entries(allElements)) { + if (!this[`customize_${key}`]) { + continue; + } + elements[key] = {}; + for (const elementKey of Object.keys(value)) { + if (this[`${key}_${elementKey}`]) { + elements[key][elementKey] = this[`${key}_${elementKey}`]; + } + } + } + + const response = await this.imagior.generateImage({ + $, + data: { + templateId: this.templateId, + elements, + }, + }); + $.export("$summary", `${response.message}`); + return response; + }, +}; diff --git a/components/imagior/imagior.app.mjs b/components/imagior/imagior.app.mjs index d49fb813120c2..53d5897050d88 100644 --- a/components/imagior/imagior.app.mjs +++ b/components/imagior/imagior.app.mjs @@ -1,11 +1,62 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "imagior", - propDefinitions: {}, + propDefinitions: { + templateId: { + type: "string", + label: "Template ID", + description: "The unique ID of the design template to use", + async options() { + const templates = await this.listTemplates(); + return templates?.map(({ + id: value, name: label, + }) => ({ + value, + label, + })) || []; + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.imagior.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.api_key}`, + }, + }); + }, + listTemplates(opts = {}) { + return this._makeRequest({ + path: "/templates/all", + ...opts, + }); + }, + listTemplateElements({ + templateId, ...opts + }) { + return this._makeRequest({ + path: `/templates/${templateId}/elements`, + ...opts, + }); + }, + generateImage(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/image/generate", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/imagior/package.json b/components/imagior/package.json index 62a18b0c136c2..6d05708249593 100644 --- a/components/imagior/package.json +++ b/components/imagior/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/imagior", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Imagior Components", "main": "imagior.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/components/imagior/sources/new-template/new-template.mjs b/components/imagior/sources/new-template/new-template.mjs new file mode 100644 index 0000000000000..124e8fd1cb377 --- /dev/null +++ b/components/imagior/sources/new-template/new-template.mjs @@ -0,0 +1,63 @@ +import imagior from "../../imagior.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; + +export default { + key: "imagior-new-template", + name: "New Template Created", + description: "Emit new event when a new template is created.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + imagior, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + _getLastTs() { + return this.db.get("lastTs") || 0; + }, + _setLastTs(lastTs) { + this.db.set("lastTs", lastTs); + }, + generateMeta(template) { + return { + id: template.id, + summary: `New Template: ${template.name}`, + ts: Date.parse(template.createdAt), + }; + }, + }, + async run() { + const lastTs = this._getLastTs(); + + const templates = await this.imagior.listTemplates({ + params: { + sort: "createdAt", + order: "desc", + }, + }); + + if (!templates?.length) { + return; + } + + const newTemplates = templates.filter(({ createdAt }) => Date.parse(createdAt) >= lastTs); + + if (!newTemplates?.length) { + return; + } + + this._setLastTs(Date.parse(newTemplates[0].createdAt)); + + newTemplates.forEach((template) => { + const meta = this.generateMeta(template); + this.$emit(template, meta); + }); + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4001a5109bbf3..8015d52670291 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4817,7 +4817,10 @@ importers: form-data: 4.0.0 components/imagior: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/imap: specifiers: @@ -13036,6 +13039,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'} @@ -13271,7 +13323,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 @@ -13313,55 +13365,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'} @@ -17654,7 +17657,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