diff --git a/components/tremendous/actions/create-order-email-reward/create-order-email-reward.mjs b/components/tremendous/actions/create-order-email-reward/create-order-email-reward.mjs new file mode 100644 index 0000000000000..692a06c6b46ca --- /dev/null +++ b/components/tremendous/actions/create-order-email-reward/create-order-email-reward.mjs @@ -0,0 +1,107 @@ +import app from "../../tremendous.app.mjs"; +import { DELIVERY_METHOD_OPTIONS } from "../../common/constants.mjs"; + +export default { + name: "Create Order Email Reward", + version: "0.0.1", + key: "tremendous-create-order-email-reward", + description: "Create an order to send out a reward. [See the documentation](https://developers.tremendous.com/reference/create-order)", + type: "action", + props: { + app, + campaignId: { + propDefinition: [ + app, + "campaignId", + ], + optional: true, + }, + products: { + propDefinition: [ + app, + "products", + ], + optional: true, + }, + infoBox: { + type: "alert", + alertType: "info", + content: "Either `Products` or `Campaign ID` must be specified. [See the documentation](https://developers.tremendous.com/reference/create-order) for more information.", + }, + fundingSourceId: { + propDefinition: [ + app, + "fundingSourceId", + ], + default: "balance", + }, + externalId: { + type: "string", + label: "External ID", + description: "Reference for this order. If set, any subsequent requests with the same `External ID` will not create any further orders, and simply return the initially created order.", + optional: true, + }, + valueAmount: { + type: "string", + label: "Value Amount", + description: "Amount of the reward.", + }, + valueCurrencyCode: { + type: "string", + label: "Value Currency Code", + description: "Currency of the reward.", + }, + recipientName: { + type: "string", + label: "Recipient Name", + description: "Name of the recipient.", + }, + recipientEmail: { + type: "string", + label: "Recipient Email", + description: "Email address of the recipient.", + }, + recipientPhone: { + type: "string", + label: "Recipient Phone", + description: "Phone number of the recipient. For non-US phone numbers, specify the country code (prefixed with `+`).", + }, + deliveryMethod: { + type: "string", + label: "Delivery Method", + description: "How to deliver the reward to the recipient.", + options: DELIVERY_METHOD_OPTIONS, + }, + }, + async run({ $ }) { + const response = await this.app.createOrder({ + $, + data: { + external_id: this.externalId, + payment: { + funding_source_id: this.fundingSourceId, + }, + reward: { + campaign_id: this.campaignId, + products: this.products, + value: { + denomination: this.valueAmount, + currency_code: this.valueCurrencyCode, + }, + recipient: { + name: this.recipientName, + email: this.recipientEmail, + phone: this.recipientPhone, + }, + delivery: { + method: this.deliveryMethod, + }, + }, + }, + }); + + $.export("$summary", `Successfully created order (ID: ${response?.order?.id})`); + + return response; + }, +}; diff --git a/components/tremendous/common/constants.mjs b/components/tremendous/common/constants.mjs new file mode 100644 index 0000000000000..8fa569a6180b0 --- /dev/null +++ b/components/tremendous/common/constants.mjs @@ -0,0 +1,15 @@ +export const DELIVERY_METHOD_OPTIONS = [ + { + value: "EMAIL", + label: "Deliver the reward to the recipient by email", + }, + { + value: "LINK", + label: "Deliver the reward to the recipient via a link.", + }, + + { + value: "PHONE", + label: "Deliver the reward to the recipient by SMS", + }, +]; diff --git a/components/tremendous/package.json b/components/tremendous/package.json new file mode 100644 index 0000000000000..e502f2a48a695 --- /dev/null +++ b/components/tremendous/package.json @@ -0,0 +1,18 @@ +{ + "name": "@pipedream/tremendous", + "version": "0.0.1", + "description": "Pipedream Tremendous Components", + "main": "tremendous.app.mjs", + "keywords": [ + "pipedream", + "tremendous" + ], + "homepage": "https://pipedream.com/apps/tremendous", + "author": "Pipedream (https://pipedream.com/)", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" + } +} diff --git a/components/tremendous/tremendous.app.mjs b/components/tremendous/tremendous.app.mjs index 6d0c587c8b121..6318f95bef4cc 100644 --- a/components/tremendous/tremendous.app.mjs +++ b/components/tremendous/tremendous.app.mjs @@ -1,11 +1,89 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "tremendous", - propDefinitions: {}, + propDefinitions: { + campaignId: { + type: "string", + label: "Campaign ID", + description: "ID of the campaign in your account, that defines the available products (different gift cards, charity, etc.) that the recipient can choose from.", + async options() { + const { campaigns } = await this.listCampaigns(); + return campaigns?.map(({ + id, name, + }) => ({ + label: name, + value: id, + })); + }, + }, + products: { + type: "string[]", + label: "Products", + description: "IDs of products (different gift cards, charity, etc.) that will be available to the recipient to choose from. If this and `Campaign ID` are specified, this will override the products made available by the campaign. It will not override other campaign attributes, like the message and customization of the look and feel.", + async options() { + const { products } = await this.listProducts(); + return products?.map(({ + id, name, + }) => ({ + label: name, + value: id, + })); + }, + }, + fundingSourceId: { + type: "string", + label: "Funding Source ID", + description: "Tremendous ID of the funding source that will be used to pay for the order. Use `balance` to use your Tremendous's balance.", + async options() { + const response = await this.listFundingSources(); + return response.funding_sources?.map(({ + id, method, + }) => ({ + label: `${id} - ${method}`, + value: id, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseRequest({ + $, headers, ...args + }) { + return axios($, { + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_key}`, + }, + baseURL: "https://testflight.tremendous.com/api/v2", + ...args, + }); + }, + createOrder(args) { + return this._baseRequest({ + method: "POST", + url: "/orders", + ...args, + }); + }, + listCampaigns() { + return this._baseRequest({ + method: "GET", + url: "/campaigns", + }); + }, + listProducts() { + return this._baseRequest({ + method: "GET", + url: "/products", + }); + }, + listFundingSources() { + return this._baseRequest({ + method: "GET", + url: "/funding_sources", + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4ffdb171ad85b..f8aff1a30ecac 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10390,6 +10390,12 @@ importers: mime: 4.0.4 ms: 2.1.3 + components/tremendous: + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 + components/trengo: specifiers: '@pipedream/platform': ^1.1.1