Skip to content
Merged
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
56 changes: 56 additions & 0 deletions components/swell/actions/create-account/create-account.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import app from "../../swell.app.mjs";

export default {
key: "swell-create-account",
name: "Create Account",
description: "Create a new customer account. [See the documentation](https://developers.swell.is/backend-api/accounts/create-an-account)",
version: "0.0.1",
type: "action",
props: {
app,
email: {
propDefinition: [
app,
"email",
],
},
firstName: {
propDefinition: [
app,
"firstName",
],
},
lastName: {
propDefinition: [
app,
"lastName",
],
},
phone: {
propDefinition: [
app,
"phone",
],
},
notes: {
propDefinition: [
app,
"notes",
],
},
},
async run({ $ }) {
const response = await this.app.createAccount({
$,
data: {
email: this.email,
first_name: this.firstName,
last_name: this.lastName,
phone: this.phone,
notes: this.notes,
},
});
$.export("$summary", "Successfully created account with ID: " + response.id);
return response;
},
};
56 changes: 56 additions & 0 deletions components/swell/actions/create-product/create-product.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import app from "../../swell.app.mjs";

export default {
key: "swell-create-product",
name: "Create Product",
description: "Create a new product. [See the documentation](https://developers.swell.is/backend-api/products/create-a-product)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
propDefinition: [
app,
"name",
],
},
price: {
propDefinition: [
app,
"price",
],
},
active: {
propDefinition: [
app,
"active",
],
},
description: {
propDefinition: [
app,
"description",
],
},
discontinued: {
propDefinition: [
app,
"discontinued",
],
},
},
async run({ $ }) {
const response = await this.app.createProduct({
$,
data: {
name: this.name,
price: this.price,
active: this.active,
description: this.description,
discontinued: this.discontinued,
},
});
$.export("$summary", "Successfully created product with ID: " + response.id);
return response;
},
};
63 changes: 63 additions & 0 deletions components/swell/actions/update-account/update-account.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import app from "../../swell.app.mjs";

export default {
key: "swell-update-account",
name: "Update Account",
description: "Update an existing account with the corresponding ID. [See the documentation](https://developers.swell.is/backend-api/accounts/update-an-account)",
version: "0.0.1",
type: "action",
props: {
app,
email: {
propDefinition: [
app,
"email",
],
},
firstName: {
propDefinition: [
app,
"firstName",
],
},
lastName: {
propDefinition: [
app,
"lastName",
],
},
phone: {
propDefinition: [
app,
"phone",
],
},
notes: {
propDefinition: [
app,
"notes",
],
},
accountId: {
propDefinition: [
app,
"accountId",
],
},
},
async run({ $ }) {
const response = await this.app.updateAccount({
$,
accountId: this.accountId,
data: {
email: this.email,
first_name: this.firstName,
last_name: this.lastName,
phone: this.phone,
notes: this.notes,
},
});
$.export("$summary", "Successfully updated account with ID: " + this.id);
return response;
},
};
5 changes: 4 additions & 1 deletion components/swell/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/swell",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Swell Components",
"main": "swell.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
124 changes: 119 additions & 5 deletions components/swell/swell.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,125 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "swell",
propDefinitions: {},
propDefinitions: {
email: {
type: "string",
label: "Email",
description: "The account's email address",
},
firstName: {
type: "string",
label: "First Name",
description: "The account's first name",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "The account's last name",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "The account's phone number",
optional: true,
},
notes: {
type: "string",
label: "Notes",
description: "Additional notes about the account",
optional: true,
},
name: {
type: "string",
label: "Name",
description: "The product's full name or display name",
},
price: {
type: "string",
label: "Price",
description: "The price associated with the product",
optional: true,
},
active: {
type: "boolean",
label: "Active",
description: "Whether the product is active",
optional: true,
},
description: {
type: "string",
label: "Description",
description: "A description of the product",
optional: true,
},
discontinued: {
type: "boolean",
label: "Discontinued",
description: "Whether the product is discontinued",
optional: true,
},
accountId: {
type: "string",
label: "Account ID",
description: "ID of the account that will be updated",
async options() {
const { results } = await this.getAccounts();
return results.map(({
email, id,
}) => ({
label: email,
value: id,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return `https://${this.$auth.store_id}:${this.$auth.secret_key}@api.swell.store`;
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
});
},
async createAccount(args = {}) {
return this._makeRequest({
path: "/accounts",
method: "post",
...args,
});
},
async createProduct(args = {}) {
return this._makeRequest({
path: "/products",
method: "post",
...args,
});
},
async updateAccount({
accountId, ...args
}) {
return this._makeRequest({
path: `/accounts/${accountId}`,
method: "put",
...args,
});
},
async getAccounts(args = {}) {
return this._makeRequest({
path: "/accounts",
...args,
});
},
},
};
};
12 changes: 7 additions & 5 deletions pnpm-lock.yaml

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

Loading