Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion components/bluesnap/bluesnap.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
84 changes: 84 additions & 0 deletions components/clear_books/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import clearBooks from "../../clear_books.app.mjs";

export default {
key: "clear_books-create-customer",
name: "Create Customer",
description: "Creates a new customer in Clear Books. [See the documentation](https://u.pcloud.link/publink/show?code=XZkThJ5Z4zKewgCL6VBpfxlPeHPDdXXj0Cc7)",
version: "0.0.1",
type: "action",
props: {
clearBooks,
name: {
type: "string",
label: "Name",
description: "Name of the customer",
},
email: {
type: "string",
label: "Email",
description: "Email address of the customer",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "Phone number of the customer",
optional: true,
},
streetAddress: {
type: "string",
label: "Street Address",
description: "Street address of the customer",
optional: true,
},
town: {
type: "string",
label: "Town",
description: "Town of the customer",
optional: true,
},
county: {
type: "string",
label: "County",
description: "County of the customer",
optional: true,
},
postcode: {
type: "string",
label: "Postcode",
description: "Postcode of the customer",
optional: true,
},
countryCode: {
type: "string",
label: "Country Code",
description: "Country code of the customer",
optional: true,
},
},
async run({ $ }) {
const hasAddress = this.streetAddress
|| this.town
|| this.county
|| this.postcode
|| this.countryCode;

const response = await this.clearBooks.createCustomer({
$,
data: {
name: this.name,
email: this.email,
phone: this.phone,
address: hasAddress && {
line1: this.streetAddress,
town: this.town,
county: this.county,
postcode: this.postcode,
countryCode: this.countryCode,
},
},
});
$.export("$summary", `Successfully created customer with ID: ${response.id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import clearBooks from "../../clear_books.app.mjs";

export default {
key: "clear_books-create-purchase-document",
name: "Create Purchase Document",
description: "Creates a new Purchase Document in Clear Books. [See the documentation](https://u.pcloud.link/publink/show?code=XZkThJ5Z4zKewgCL6VBpfxlPeHPDdXXj0Cc7)",
version: "0.0.1",
type: "action",
props: {
clearBooks,
purchaseType: {
propDefinition: [
clearBooks,
"purchaseType",
],
},
date: {
type: "string",
label: "Date",
description: "The date of the purchase. Format: YYYY-MM-DD",
},
supplierId: {
propDefinition: [
clearBooks,
"supplierId",
],
},
description: {
type: "string",
label: "Description",
description: "Description of the purchase document",
optional: true,
},
numLineItems: {
type: "integer",
label: "Number of Line Items",
description: "The number of line items to create",
reloadProps: true,
},
},
additionalProps() {
const props = {};
if (!this.numLineItems) {
return props;
}
for (let i = 1; i <= this.numLineItems; i++) {
props[`line_item_${i}_unit_price`] = {
type: "string",
label: `Line Item ${i} - Unit Price`,
};
props[`line_item_${i}_quantity`] = {
type: "integer",
label: `Line Item ${i} - Quantity`,
};
props[`line_item_${i}_description`] = {
type: "string",
label: `Line Item ${i} - Description`,
};
}
return props;
},
async run({ $ }) {
const lineItems = [];
for (let i = 1; i <= this.numLineItems; i++) {
lineItems.push({
unitPrice: this[`line_item_${i}_unit_price`],
quantity: this[`line_item_${i}_quantity`],
description: this[`line_item_${i}_description`],
});
}

const response = await this.clearBooks.createPurchaseDocument({
$,
type: this.purchaseType,
data: {
date: this.date,
supplierId: this.supplierId,
description: this.description,
lineItems,
},
});
$.export("$summary", `Successfully created purchase document with ID ${response.id}`);
return response;
},
};
84 changes: 84 additions & 0 deletions components/clear_books/actions/create-supplier/create-supplier.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import clearBooks from "../../clear_books.app.mjs";

export default {
key: "clear_books-create-supplier",
name: "Create Supplier",
description: "Creates a new supplier in Clear Books. [See the documentation](https://u.pcloud.link/publink/show?code=XZkThJ5Z4zKewgCL6VBpfxlPeHPDdXXj0Cc7)",
version: "0.0.1",
type: "action",
props: {
clearBooks,
name: {
type: "string",
label: "Name",
description: "Name of the supplier",
},
email: {
type: "string",
label: "Email",
description: "Email address of the supplier",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "Phone number of the supplier",
optional: true,
},
streetAddress: {
type: "string",
label: "Street Address",
description: "Street address of the supplier",
optional: true,
},
town: {
type: "string",
label: "Town",
description: "Town of the supplier",
optional: true,
},
county: {
type: "string",
label: "County",
description: "County of the supplier",
optional: true,
},
postcode: {
type: "string",
label: "Postcode",
description: "Postcode of the supplier",
optional: true,
},
countryCode: {
type: "string",
label: "Country Code",
description: "Country code of the supplier",
optional: true,
},
},
async run({ $ }) {
const hasAddress = this.streetAddress
|| this.town
|| this.county
|| this.postcode
|| this.countryCode;

const response = await this.clearBooks.createSupplier({
$,
data: {
name: this.name,
email: this.email,
phone: this.phone,
address: hasAddress && {
line1: this.streetAddress,
town: this.town,
county: this.county,
postcode: this.postcode,
countryCode: this.countryCode,
},
},
});
$.export("$summary", `Successfully created supplier with ID: ${response.id}`);
return response;
},
};
129 changes: 125 additions & 4 deletions components/clear_books/clear_books.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,132 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "clear_books",
propDefinitions: {},
propDefinitions: {
supplierId: {
type: "string",
label: "Supplier ID",
description: "The identifier of a supplier",
async options({ page }) {
const suppliers = await this.listSuppliers({
params: {
page: page + 1,
},
});
return suppliers?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
purchaseType: {
type: "string",
label: "Purchase Type",
description: "Type of purchase document",
options: [
"bills",
"creditNotes",
],
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.clearbooks.co.uk/v1";
},
_makeRequest({
$ = this,
path,
...otherOpts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
},
...otherOpts,
});
},
listCustomers(opts = {}) {
return this._makeRequest({
path: "/accounting/customers",
...opts,
});
},
listPurchaseDocuments({
type, ...opts
}) {
return this._makeRequest({
path: `/accounting/purchases/${type}`,
...opts,
});
},
listTransactions(opts = {}) {
return this._makeRequest({
path: "/accounting/transactions",
...opts,
});
},
listSuppliers(opts = {}) {
return this._makeRequest({
path: "/accounting/suppliers",
...opts,
});
},
createCustomer(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/accounting/customers",
...opts,
});
},
createPurchaseDocument({
type, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/accounting/purchases/${type}`,
...opts,
});
},
createSupplier(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/accounting/suppliers",
...opts,
});
},
async *paginate({
fn,
args,
max,
}) {
args = {
...args,
params: {
...args?.params,
limit: 100,
page: 1,
},
};
let total, count = 0;
try {
do {
const results = await fn(args);
for (const item of results) {
yield item;
if (max && ++count >= max) {
return;
}
}
total = results?.length;
args.params.page++;
} while (total === args.params.limit);
} catch (e) {
console.log(`Error: ${e}`);
}
},
},
};
Loading
Loading