-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New Components - clear_books #15287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - clear_books #15287
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
571e89d
clear_books init
michelle0927 ed2c989
new-components
michelle0927 a72e5b3
updates
michelle0927 8647dec
pnpm-lock.yaml
michelle0927 427124c
Merge remote-tracking branch 'origin/master' into issue-15253
michelle0927 6366449
pnpm-lock.yaml
michelle0927 597a6d5
add lineItemsJson prop
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
84 changes: 84 additions & 0 deletions
84
components/clear_books/actions/create-customer/create-customer.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; | ||
85 changes: 85 additions & 0 deletions
85
components/clear_books/actions/create-purchase-document/create-purchase-document.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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`, | ||
| }; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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`], | ||
| }); | ||
| } | ||
michelle0927 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
84 changes: 84 additions & 0 deletions
84
components/clear_books/actions/create-supplier/create-supplier.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) { | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| console.log(`Error: ${e}`); | ||
| } | ||
| }, | ||
| }, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.