Skip to content

Commit b579223

Browse files
GTFalcaolcaresia
authored andcommitted
Tremendous new component (#14351)
* App and package updates * pnpm * Create Order action * Prop definitions and requests * Type adjustment * Import fix * Adding and adjusting several props
1 parent c58aadb commit b579223

File tree

5 files changed

+228
-4
lines changed

5 files changed

+228
-4
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import app from "../../tremendous.app.mjs";
2+
import { DELIVERY_METHOD_OPTIONS } from "../../common/constants.mjs";
3+
4+
export default {
5+
name: "Create Order Email Reward",
6+
version: "0.0.1",
7+
key: "tremendous-create-order-email-reward",
8+
description: "Create an order to send out a reward. [See the documentation](https://developers.tremendous.com/reference/create-order)",
9+
type: "action",
10+
props: {
11+
app,
12+
campaignId: {
13+
propDefinition: [
14+
app,
15+
"campaignId",
16+
],
17+
optional: true,
18+
},
19+
products: {
20+
propDefinition: [
21+
app,
22+
"products",
23+
],
24+
optional: true,
25+
},
26+
infoBox: {
27+
type: "alert",
28+
alertType: "info",
29+
content: "Either `Products` or `Campaign ID` must be specified. [See the documentation](https://developers.tremendous.com/reference/create-order) for more information.",
30+
},
31+
fundingSourceId: {
32+
propDefinition: [
33+
app,
34+
"fundingSourceId",
35+
],
36+
default: "balance",
37+
},
38+
externalId: {
39+
type: "string",
40+
label: "External ID",
41+
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.",
42+
optional: true,
43+
},
44+
valueAmount: {
45+
type: "string",
46+
label: "Value Amount",
47+
description: "Amount of the reward.",
48+
},
49+
valueCurrencyCode: {
50+
type: "string",
51+
label: "Value Currency Code",
52+
description: "Currency of the reward.",
53+
},
54+
recipientName: {
55+
type: "string",
56+
label: "Recipient Name",
57+
description: "Name of the recipient.",
58+
},
59+
recipientEmail: {
60+
type: "string",
61+
label: "Recipient Email",
62+
description: "Email address of the recipient.",
63+
},
64+
recipientPhone: {
65+
type: "string",
66+
label: "Recipient Phone",
67+
description: "Phone number of the recipient. For non-US phone numbers, specify the country code (prefixed with `+`).",
68+
},
69+
deliveryMethod: {
70+
type: "string",
71+
label: "Delivery Method",
72+
description: "How to deliver the reward to the recipient.",
73+
options: DELIVERY_METHOD_OPTIONS,
74+
},
75+
},
76+
async run({ $ }) {
77+
const response = await this.app.createOrder({
78+
$,
79+
data: {
80+
external_id: this.externalId,
81+
payment: {
82+
funding_source_id: this.fundingSourceId,
83+
},
84+
reward: {
85+
campaign_id: this.campaignId,
86+
products: this.products,
87+
value: {
88+
denomination: this.valueAmount,
89+
currency_code: this.valueCurrencyCode,
90+
},
91+
recipient: {
92+
name: this.recipientName,
93+
email: this.recipientEmail,
94+
phone: this.recipientPhone,
95+
},
96+
delivery: {
97+
method: this.deliveryMethod,
98+
},
99+
},
100+
},
101+
});
102+
103+
$.export("$summary", `Successfully created order (ID: ${response?.order?.id})`);
104+
105+
return response;
106+
},
107+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const DELIVERY_METHOD_OPTIONS = [
2+
{
3+
value: "EMAIL",
4+
label: "Deliver the reward to the recipient by email",
5+
},
6+
{
7+
value: "LINK",
8+
label: "Deliver the reward to the recipient via a link.",
9+
},
10+
11+
{
12+
value: "PHONE",
13+
label: "Deliver the reward to the recipient by SMS",
14+
},
15+
];

components/tremendous/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/tremendous",
3+
"version": "0.0.1",
4+
"description": "Pipedream Tremendous Components",
5+
"main": "tremendous.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"tremendous"
9+
],
10+
"homepage": "https://pipedream.com/apps/tremendous",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
17+
}
18+
}
Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,89 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "tremendous",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
campaignId: {
8+
type: "string",
9+
label: "Campaign ID",
10+
description: "ID of the campaign in your account, that defines the available products (different gift cards, charity, etc.) that the recipient can choose from.",
11+
async options() {
12+
const { campaigns } = await this.listCampaigns();
13+
return campaigns?.map(({
14+
id, name,
15+
}) => ({
16+
label: name,
17+
value: id,
18+
}));
19+
},
20+
},
21+
products: {
22+
type: "string[]",
23+
label: "Products",
24+
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.",
25+
async options() {
26+
const { products } = await this.listProducts();
27+
return products?.map(({
28+
id, name,
29+
}) => ({
30+
label: name,
31+
value: id,
32+
}));
33+
},
34+
},
35+
fundingSourceId: {
36+
type: "string",
37+
label: "Funding Source ID",
38+
description: "Tremendous ID of the funding source that will be used to pay for the order. Use `balance` to use your Tremendous's balance.",
39+
async options() {
40+
const response = await this.listFundingSources();
41+
return response.funding_sources?.map(({
42+
id, method,
43+
}) => ({
44+
label: `${id} - ${method}`,
45+
value: id,
46+
}));
47+
},
48+
},
49+
},
550
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
51+
_baseRequest({
52+
$, headers, ...args
53+
}) {
54+
return axios($, {
55+
headers: {
56+
...headers,
57+
Authorization: `Bearer ${this.$auth.api_key}`,
58+
},
59+
baseURL: "https://testflight.tremendous.com/api/v2",
60+
...args,
61+
});
62+
},
63+
createOrder(args) {
64+
return this._baseRequest({
65+
method: "POST",
66+
url: "/orders",
67+
...args,
68+
});
69+
},
70+
listCampaigns() {
71+
return this._baseRequest({
72+
method: "GET",
73+
url: "/campaigns",
74+
});
75+
},
76+
listProducts() {
77+
return this._baseRequest({
78+
method: "GET",
79+
url: "/products",
80+
});
81+
},
82+
listFundingSources() {
83+
return this._baseRequest({
84+
method: "GET",
85+
url: "/funding_sources",
86+
});
987
},
1088
},
1189
};

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)