Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions components/paddle/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import app from "../../paddle.app.mjs";

export default {
key: "paddle-create-customer",
name: "Create Customer",
description: "Create a new customer in Paddle. [See the documentation](https://developer.paddle.com/api-reference/customers/create-customer)",
version: "0.0.1",
annotations: {
openWorldHint: true,
destructiveHint: false,
readOnlyHint: false,
},
type: "action",
props: {
app,
email: {
propDefinition: [
app,
"email",
],
},
name: {
propDefinition: [
app,
"name",
],
},
customData: {
propDefinition: [
app,
"customData",
],
},
},
async run({ $ }) {
const customData = typeof this.customData === "string"
? JSON.parse(this.customData)
: this.customData;

const response = await this.app.createCustomer({
$,
data: {
email: this.email,
name: this.name,
custom_data: customData,
},
});
$.export("$summary", "Successfully created a new customer with the ID: " + response.data.id);
return response;
},
};
24 changes: 24 additions & 0 deletions components/paddle/actions/get-customers/get-customers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import app from "../../paddle.app.mjs";

export default {
key: "paddle-get-customers",
name: "Get Customers",
description: "Get a list of customers registered in Paddle. [See the documentation](https://developer.paddle.com/api-reference/customers/list-customers)",
version: "0.0.1",
annotations: {
openWorldHint: true,
destructiveHint: false,
readOnlyHint: true,
},
type: "action",
props: {
app,
},
async run({ $ }) {
const response = await this.app.getCustomers({
$,
});
$.export("$summary", "Successfully retrieved " + response.data.length + " customers");
return response;
},
};
65 changes: 65 additions & 0 deletions components/paddle/actions/update-customer/update-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import app from "../../paddle.app.mjs";

export default {
key: "paddle-update-customer",
name: "Update Customer",
description: "Update the customer with the specified ID. [See the documentation](https://developer.paddle.com/api-reference/customers/update-customer)",
version: "0.0.1",
annotations: {
openWorldHint: true,
destructiveHint: true,
readOnlyHint: false,
},
type: "action",
props: {
app,
customerId: {
propDefinition: [
app,
"customerId",
],
},
email: {
propDefinition: [
app,
"email",
],
},
name: {
propDefinition: [
app,
"name",
],
},
customData: {
propDefinition: [
app,
"customData",
],
},
status: {
propDefinition: [
app,
"status",
],
},
},
async run({ $ }) {
const customData = typeof this.customData === "string"
? JSON.parse(this.customData)
: this.customData;

const response = await this.app.updateCustomer({
$,
customerId: this.customerId,
data: {
email: this.email,
name: this.name,
custom_data: customData,
status: this.status,
},
});
$.export("$summary", "Successfully updated the customer with ID: " + this.customerId);
return response;
},
};
6 changes: 6 additions & 0 deletions components/paddle/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
STATUS_OPTIONS: [
"active",
"archived",
],
};
5 changes: 4 additions & 1 deletion components/paddle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/paddle",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Paddle Components",
"main": "paddle.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
91 changes: 86 additions & 5 deletions components/paddle/paddle.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,92 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "paddle",
propDefinitions: {},
propDefinitions: {
email: {
type: "string",
label: "Email",
description: "Customer's email address",
},
name: {
type: "string",
label: "Name",
description: "Customer's full name",
},
customData: {
type: "object",
label: "Custom Data",
description: "Your own structured key-value data",
optional: true,
},
status: {
type: "string",
label: "Status",
description: "Customer's status",
options: constants.STATUS_OPTIONS,
},
customerId: {
type: "string",
label: "Customer ID",
description: "Unique identifier of the customer",
async options() {
const response = await this.getCustomers();
const data = response.data;
return data.map(({
id, name,
}) => ({
value: id,
label: name,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.paddle.com";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
Authorization: `Bearer ${this.$auth.auth_code}`,
...headers,
},
});
},

async getCustomers(args = {}) {
return this._makeRequest({
path: "/customers",
...args,
});
},

async createCustomer(args = {}) {
return this._makeRequest({
path: "/customers",
method: "post",
...args,
});
},

async updateCustomer({
customerId, ...args
}) {
return this._makeRequest({
path: `/customers/${customerId}`,
method: "patch",
...args,
});
},
},
};
};
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading