Skip to content

Commit cd6ade2

Browse files
authored
[Components] paddle #10926 (#18510)
* Added actions * Added actions * Added actions * Added actions
1 parent 88e141a commit cd6ade2

File tree

7 files changed

+241
-7
lines changed

7 files changed

+241
-7
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import app from "../../paddle.app.mjs";
2+
3+
export default {
4+
key: "paddle-create-customer",
5+
name: "Create Customer",
6+
description: "Create a new customer in Paddle. [See the documentation](https://developer.paddle.com/api-reference/customers/create-customer)",
7+
version: "0.0.1",
8+
annotations: {
9+
openWorldHint: true,
10+
destructiveHint: false,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
email: {
17+
propDefinition: [
18+
app,
19+
"email",
20+
],
21+
},
22+
name: {
23+
propDefinition: [
24+
app,
25+
"name",
26+
],
27+
},
28+
customData: {
29+
propDefinition: [
30+
app,
31+
"customData",
32+
],
33+
},
34+
},
35+
async run({ $ }) {
36+
const customData = typeof this.customData === "string"
37+
? JSON.parse(this.customData)
38+
: this.customData;
39+
40+
const response = await this.app.createCustomer({
41+
$,
42+
data: {
43+
email: this.email,
44+
name: this.name,
45+
custom_data: customData,
46+
},
47+
});
48+
$.export("$summary", "Successfully created a new customer with the ID: " + response.data.id);
49+
return response;
50+
},
51+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import app from "../../paddle.app.mjs";
2+
3+
export default {
4+
key: "paddle-get-customers",
5+
name: "Get Customers",
6+
description: "Get a list of customers registered in Paddle. [See the documentation](https://developer.paddle.com/api-reference/customers/list-customers)",
7+
version: "0.0.1",
8+
annotations: {
9+
openWorldHint: true,
10+
destructiveHint: false,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
},
17+
async run({ $ }) {
18+
const response = await this.app.getCustomers({
19+
$,
20+
});
21+
$.export("$summary", "Successfully retrieved " + response.data.length + " customers");
22+
return response;
23+
},
24+
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import app from "../../paddle.app.mjs";
2+
3+
export default {
4+
key: "paddle-update-customer",
5+
name: "Update Customer",
6+
description: "Update the customer with the specified ID. [See the documentation](https://developer.paddle.com/api-reference/customers/update-customer)",
7+
version: "0.0.1",
8+
annotations: {
9+
openWorldHint: true,
10+
destructiveHint: true,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
customerId: {
17+
propDefinition: [
18+
app,
19+
"customerId",
20+
],
21+
},
22+
email: {
23+
propDefinition: [
24+
app,
25+
"email",
26+
],
27+
},
28+
name: {
29+
propDefinition: [
30+
app,
31+
"name",
32+
],
33+
},
34+
customData: {
35+
propDefinition: [
36+
app,
37+
"customData",
38+
],
39+
},
40+
status: {
41+
propDefinition: [
42+
app,
43+
"status",
44+
],
45+
},
46+
},
47+
async run({ $ }) {
48+
const customData = typeof this.customData === "string"
49+
? JSON.parse(this.customData)
50+
: this.customData;
51+
52+
const response = await this.app.updateCustomer({
53+
$,
54+
customerId: this.customerId,
55+
data: {
56+
email: this.email,
57+
name: this.name,
58+
custom_data: customData,
59+
status: this.status,
60+
},
61+
});
62+
$.export("$summary", "Successfully updated the customer with ID: " + this.customerId);
63+
return response;
64+
},
65+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
STATUS_OPTIONS: [
3+
"active",
4+
"archived",
5+
],
6+
};

components/paddle/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/paddle",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Paddle Components",
55
"main": "paddle.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
1518
}

components/paddle/paddle.app.mjs

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,92 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "paddle",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
email: {
9+
type: "string",
10+
label: "Email",
11+
description: "Customer's email address",
12+
},
13+
name: {
14+
type: "string",
15+
label: "Name",
16+
description: "Customer's full name",
17+
},
18+
customData: {
19+
type: "object",
20+
label: "Custom Data",
21+
description: "Your own structured key-value data",
22+
optional: true,
23+
},
24+
status: {
25+
type: "string",
26+
label: "Status",
27+
description: "Customer's status",
28+
options: constants.STATUS_OPTIONS,
29+
},
30+
customerId: {
31+
type: "string",
32+
label: "Customer ID",
33+
description: "Unique identifier of the customer",
34+
async options() {
35+
const response = await this.getCustomers();
36+
const data = response.data;
37+
return data.map(({
38+
id, name,
39+
}) => ({
40+
value: id,
41+
label: name,
42+
}));
43+
},
44+
},
45+
},
546
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
47+
_baseUrl() {
48+
return "https://api.paddle.com";
49+
},
50+
async _makeRequest(opts = {}) {
51+
const {
52+
$ = this,
53+
path,
54+
headers,
55+
...otherOpts
56+
} = opts;
57+
return axios($, {
58+
...otherOpts,
59+
url: this._baseUrl() + path,
60+
headers: {
61+
Authorization: `Bearer ${this.$auth.auth_code}`,
62+
...headers,
63+
},
64+
});
65+
},
66+
67+
async getCustomers(args = {}) {
68+
return this._makeRequest({
69+
path: "/customers",
70+
...args,
71+
});
72+
},
73+
74+
async createCustomer(args = {}) {
75+
return this._makeRequest({
76+
path: "/customers",
77+
method: "post",
78+
...args,
79+
});
80+
},
81+
82+
async updateCustomer({
83+
customerId, ...args
84+
}) {
85+
return this._makeRequest({
86+
path: `/customers/${customerId}`,
87+
method: "patch",
88+
...args,
89+
});
990
},
1091
},
11-
};
92+
};

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)