diff --git a/components/fakturoid/actions/cancel-uncancel-invoice/cancel-uncancel-invoice.mjs b/components/fakturoid/actions/cancel-uncancel-invoice/cancel-uncancel-invoice.mjs new file mode 100644 index 0000000000000..783fc302950e8 --- /dev/null +++ b/components/fakturoid/actions/cancel-uncancel-invoice/cancel-uncancel-invoice.mjs @@ -0,0 +1,49 @@ +import constants from "../../common/constants.mjs"; +import fakturoid from "../../fakturoid.app.mjs"; + +export default { + key: "fakturoid-cancel-uncancel-invoice", + name: "Cancel or Uncancel Invoice", + description: "Cancels an existing invoice or revokes previous cancellation. [See the documentation](https://www.fakturoid.cz/api/v3)", + version: "0.0.1", + type: "action", + props: { + fakturoid, + accountSlug: { + propDefinition: [ + fakturoid, + "accountSlug", + ], + }, + invoiceId: { + propDefinition: [ + fakturoid, + "invoiceId", + ({ accountSlug }) => ({ + accountSlug, + }), + ], + }, + action: { + type: "string", + label: "Action", + description: "The action to perform on the invoice (cancel or uncancel)", + options: constants.ACTION_OPTIONS, + }, + }, + async run({ $ }) { + const response = await this.fakturoid.fireInvoice({ + $, + accountSlug: this.accountSlug, + invoiceId: this.invoiceId, + params: { + event: this.action, + }, + }); + + $.export("$summary", `${this.action === "cancel" + ? "Cancelled" + : "Uncancelled"} invoice with ID ${this.invoiceId}`); + return response; + }, +}; diff --git a/components/fakturoid/actions/create-invoice/create-invoice.mjs b/components/fakturoid/actions/create-invoice/create-invoice.mjs new file mode 100644 index 0000000000000..f11db2fb28c54 --- /dev/null +++ b/components/fakturoid/actions/create-invoice/create-invoice.mjs @@ -0,0 +1,139 @@ +import constants, { parseObject } from "../../common/constants.mjs"; +import fakturoid from "../../fakturoid.app.mjs"; + +export default { + key: "fakturoid-create-invoice", + name: "Create Invoice", + description: "Creates a new invoice. [See the documentation](https://www.fakturoid.cz/api/v3/invoices)", + version: "0.0.1", + type: "action", + props: { + fakturoid, + accountSlug: { + propDefinition: [ + fakturoid, + "accountSlug", + ], + }, + customId: { + type: "string", + label: "Custom Id", + description: "Identifier in your application", + optional: true, + }, + documentType: { + type: "string", + label: "Document Type", + description: "Type of document", + options: constants.DOCUMENT_TYPE_OPTIONS, + reloadProps: true, + optional: true, + }, + subjectId: { + propDefinition: [ + fakturoid, + "subjectId", + ({ accountSlug }) => ({ + accountSlug, + }), + ], + }, + orderNumber: { + type: "string", + label: "Order Number", + description: "Order number in your application", + optional: true, + }, + note: { + type: "string", + label: "Note", + description: "Additional notes for the invoice", + optional: true, + }, + due: { + type: "string", + label: "Due", + description: "Invoice due date in number of days from today", + optional: true, + }, + issuedOn: { + type: "string", + label: "Issued On", + description: "Date of issue. **Format: YYYY-MM-DD**", + optional: true, + }, + taxableFulfillmentDue: { + type: "string", + label: "Taxable Fulfillment Due", + description: "Chargeable event date.", + optional: true, + }, + tags: { + type: "string[]", + label: "Tags", + description: "List of tags", + optional: true, + }, + roundTotal: { + type: "boolean", + label: "Round Total", + description: "Round total amount (VAT included)", + optional: true, + }, + subtotal: { + type: "string", + label: "Subtotal", + description: "Total without VAT", + optional: true, + }, + total: { + type: "string", + label: "Total", + description: "Total with VAT", + optional: true, + }, + lines: { + type: "string[]", + label: "Lines", + description: "List of object lines to invoice. [See the documentation](https://www.fakturoid.cz/api/v3/invoices#attributes). **Example: {\"name\": \"Hard work\",\"quantity\": \"1.0\",\"unit_name\": \"h\",\"unit_price\": \"40000\",\"vat_rate\": \"21\"}**", + }, + }, + async additionalProps() { + const props = {}; + if (this.documentType === "proforma") { + props.proformaFollowupDocument = { + type: "string", + label: "Proforma Followup Document", + description: "What to issue after a proforma is paid.", + options: constants.PROFORMA_OPTIONS, + optional: true, + }; + } + return props; + }, + async run({ $ }) { + const response = await this.fakturoid.createInvoice({ + $, + accountSlug: this.accountSlug, + data: { + custom_id: this.customId, + document_type: this.documentType, + proforma_followup_document: this.proformaFollowupDocument, + subject_id: this.subjectId, + order_number: this.orderNumber, + note: this.note, + due: this.due, + issued_on: this.issuedOn, + taxable_fulfillment_due: this.taxableFulfillmentDue, + tags: parseObject(this.tags), + round_total: this.roundTotal, + subtotal: this.subtotal && parseFloat(this.subtotal), + total: this.total && parseFloat(this.total), + lines: parseObject(this.lines), + }, + }); + + $.export("$summary", `Successfully created invoice with ID ${response.id}`); + return response; + }, +}; diff --git a/components/fakturoid/actions/pay-remove-payment-invoice/pay-remove-payment-invoice.mjs b/components/fakturoid/actions/pay-remove-payment-invoice/pay-remove-payment-invoice.mjs new file mode 100644 index 0000000000000..135fa078c2374 --- /dev/null +++ b/components/fakturoid/actions/pay-remove-payment-invoice/pay-remove-payment-invoice.mjs @@ -0,0 +1,109 @@ +import constants from "../../common/constants.mjs"; +import fakturoid from "../../fakturoid.app.mjs"; + +export default { + key: "fakturoid-pay-remove-payment-invoice", + name: "Pay or Remove Payment for Invoice", + description: "Executes payment for an invoice or removes an already applied payment. [See the documentation](https://www.fakturoid.cz/api/v3/invoice-payments)", + version: "0.0.1", + type: "action", + props: { + fakturoid, + accountSlug: { + propDefinition: [ + fakturoid, + "accountSlug", + ], + }, + invoiceId: { + propDefinition: [ + fakturoid, + "invoiceId", + ({ accountSlug }) => ({ + accountSlug, + }), + ], + }, + actionType: { + type: "string", + label: "Action Type", + description: "Specify if you want to execute or remove a payment", + options: constants.ACTION_TYPE_OPTIONS, + reloadProps: true, + }, + }, + async additionalProps() { + const props = {}; + if (this.actionType === "execute") { + props.paidOn = { + type: "string", + label: "Paid On", + description: "Payment date. **Format: YYYY-MM-DD** Default: Today", + optional: true, + }; + props.currency = { + type: "string", + label: "Currency", + description: "Currency [ISO Code](https://en.wikipedia.org/wiki/ISO_4217#List_of_ISO_4217_currency_codes) (same as invoice currency)", + optional: true, + }; + props.amount = { + type: "string", + label: "Amount", + description: "Paid amount in document currency. Default: Remaining amount to pay", + optional: true, + }; + props.markDocumentAsPaid = { + type: "boolean", + label: "Mark Document As Paid", + description: "Mark document as paid? Default: true if the total paid amount becomes greater or equal to remaining amount to pay", + optional: true, + }; + } else if (this.actionType === "remove") { + props.paymentId = { + type: "string", + label: "Payment ID", + description: "ID of the payment to be removed.", + options: async () => { + const { payments } = await this.fakturoid.getInvoice({ + accountSlug: this.accountSlug, + invoiceId: this.invoiceId, + }); + + return payments.map(({ + id: value, paid_on: pOn, currency, amount, + }) => ({ + label: `${currency} ${amount} (${pOn})`, + value, + })); + }, + }; + } + return props; + }, + async run({ $ }) { + if (this.actionType === "execute") { + const response = await this.fakturoid.payInvoice({ + accountSlug: this.accountSlug, + invoiceId: this.invoiceId, + data: { + paid_on: this.paidOn, + currency: this.currency, + amount: this.amount && parseFloat(this.amount), + mark_document_as_paid: this.markDocumentAsPaid, + }, + }); + $.export("$summary", `Successfully executed payment for invoice ID ${this.invoiceId}`); + return response; + } else if (this.actionType === "remove") { + const response = await this.fakturoid.removePayment({ + $, + accountSlug: this.accountSlug, + invoiceId: this.invoiceId, + paymentId: this.paymentId, + }); + $.export("$summary", `Successfully removed payment ID ${this.paymentId} from invoice ID ${this.invoiceId}`); + return response; + } + }, +}; diff --git a/components/fakturoid/common/constants.mjs b/components/fakturoid/common/constants.mjs new file mode 100644 index 0000000000000..97dbb8ff255b2 --- /dev/null +++ b/components/fakturoid/common/constants.mjs @@ -0,0 +1,159 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; + +const DOCUMENT_TYPE_OPTIONS = [ + { + label: "Invoice", + value: "invoice", + }, + { + label: "Proforma", + value: "proforma", + }, + { + label: "Legacy partial proforma (cannot be set for new documents)", + value: "partial_proforma", + }, + { + label: "Correction document for an invoice", + value: "correction", + }, + { + label: "Tax document for a received payment", + value: "tax_document", + }, + { + label: "Final invoice for tax documents", + value: "final_invoice", + }, +]; + +const PROFORMA_OPTIONS = [ + { + label: "Invoice paid", + value: "final_invoice_paid", + }, + { + label: "Invoice with edit", + value: "final_invoice", + }, + { + label: "Document to payment", + value: "tax_document", + }, + { + label: "None", + value: "none", + }, +]; + +const ACTION_OPTIONS = [ + { + label: "Cancel", + value: "cancel", + }, + { + label: "Uncancel", + value: "undo_cancel", + }, +]; + +const ACTION_TYPE_OPTIONS = [ + { + label: "Execute Payment", + value: "execute", + }, + { + label: "Remove Payment", + value: "remove", + }, +]; + +const EVENT_OPTIONS = [ + { + label: "Invoice was updated", + value: "invoice_updated", + }, + { + label: "Invoice was deleted and moved to the trash", + value: "invoice_removed", + }, + { + label: "Invoice was restored from the trash", + value: "invoice_restored", + }, + { + label: "Invoice was marked as overdue", + value: "invoice_overdue", + }, + { + label: "Payment was added to document and marked it as paid", + value: "invoice_paid", + }, + { + label: "Payment was added to the invoice, but didn't mark it as paid", + value: "invoice_payment_added", + }, + { + label: "Invoice was marked as unpaid, and the payments in the additional payload were removed", + value: "invoice_payment_removed", + }, + { + label: "Email with the invoice was sent to the subject", + value: "invoice_sent", + }, + { + label: "Invoice was locked", + value: "invoice_locked", + }, + { + label: "Invoice was unlocked", + value: "invoice_unlocked", + }, + { + label: "Invoice was marked as cancelled", + value: "invoice_cancelled", + }, + { + label: "Cancellation was removed", + value: "invoice_cancellation_removed", + }, + { + label: "Invoice was marked as uncollectible", + value: "invoice_uncollectible", + }, + { + label: "Uncollectibility was removed", + value: "invoice_uncollectible_removed", + }, +]; + +export default { + DOCUMENT_TYPE_OPTIONS, + PROFORMA_OPTIONS, + ACTION_OPTIONS, + ACTION_TYPE_OPTIONS, + EVENT_OPTIONS, +}; diff --git a/components/fakturoid/common/utils.mjs b/components/fakturoid/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/fakturoid/common/utils.mjs @@ -0,0 +1,24 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/fakturoid/fakturoid.app.mjs b/components/fakturoid/fakturoid.app.mjs index a6c9980621f13..e4c7d5228ab71 100644 --- a/components/fakturoid/fakturoid.app.mjs +++ b/components/fakturoid/fakturoid.app.mjs @@ -1,11 +1,167 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "fakturoid", - propDefinitions: {}, + propDefinitions: { + accountSlug: { + type: "string", + label: "Account", + description: "The account you want to use", + async options() { + const { accounts } = await this.getLoggedUser(); + + return accounts.map(({ + slug: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + subjectId: { + type: "string", + label: "Subject Id", + description: "The id of the subject", + async options({ + page, accountSlug, + }) { + const data = await this.listSubjects({ + accountSlug, + params: { + page: page + 1, + }, + }); + + return data.map(({ + id: value, name, full_name: fName, + }) => ({ + label: fName || name, + value, + })); + }, + }, + invoiceId: { + type: "string", + label: "Invoice ID", + description: "Unique identifier for the invoice", + async options({ + page, accountSlug, + }) { + const data = await this.listInvoices({ + accountSlug, + params: { + page: page + 1, + }, + }); + + return data.map(({ + id: value, client_name: cName, due_on: due, currency, total, + }) => ({ + label: `${cName} - ${currency} ${total} - Due On: ${due}`, + value, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl(accountSlug) { + return `https://app.fakturoid.cz/api/v3${accountSlug + ? `/accounts/${accountSlug}` + : ""}`; + }, + _headers() { + return { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }; + }, + _makeRequest({ + $ = this, accountSlug, path, ...opts + }) { + return axios($, { + url: this._baseUrl(accountSlug) + path, + headers: this._headers(), + ...opts, + }); + }, + getLoggedUser() { + return this._makeRequest({ + path: "/user.json", + }); + }, + getInvoice({ + invoiceId, ...opts + }) { + return this._makeRequest({ + path: `/invoices/${invoiceId}.json`, + ...opts, + }); + }, + listSubjects(opts = {}) { + return this._makeRequest({ + path: "/subjects.json", + ...opts, + }); + }, + listInvoices(opts = {}) { + return this._makeRequest({ + path: "/invoices.json", + ...opts, + }); + }, + createInvoice(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/invoices.json", + ...opts, + }); + }, + fireInvoice({ + invoiceId, ...opts + }) { + return this._makeRequest({ + method: "POST", + path: `/invoices/${invoiceId}/fire.json`, + ...opts, + }); + }, + payInvoice({ + invoiceId, ...opts + }) { + return this._makeRequest({ + method: "POST", + path: `/invoices/${invoiceId}/payments.json`, + ...opts, + }); + }, + removePayment({ + invoiceId, paymentId, ...opts + }) { + return this._makeRequest({ + method: "DELETE", + path: `/invoices/${invoiceId}/payments/${paymentId}.json`, + ...opts, + }); + }, + async *paginate({ + fn, params = {}, ...opts + }) { + let hasMore = false; + let page = 0; + + do { + params.page = ++page; + const data = await fn({ + params, + ...opts, + }); + for (const d of data) { + yield d; + } + + hasMore = data.length; + + } while (hasMore); }, }, -}; \ No newline at end of file +}; diff --git a/components/fakturoid/package.json b/components/fakturoid/package.json index 0b465740c1174..31085d2cedd89 100644 --- a/components/fakturoid/package.json +++ b/components/fakturoid/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/fakturoid", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Fakturoid Components", "main": "fakturoid.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} + diff --git a/components/fakturoid/sources/common/base.mjs b/components/fakturoid/sources/common/base.mjs new file mode 100644 index 0000000000000..45859d6c232b8 --- /dev/null +++ b/components/fakturoid/sources/common/base.mjs @@ -0,0 +1,77 @@ +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import fakturoid from "../../fakturoid.app.mjs"; + +export default { + props: { + fakturoid, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + accountSlug: { + propDefinition: [ + fakturoid, + "accountSlug", + ], + }, + }, + methods: { + _getLastDate() { + return this.db.get("lastDate") || "1970-01-01T00:00:00"; + }, + _setLastDate(lastDate) { + this.db.set("lastDate", lastDate); + }, + getParams(lastDate) { + return { + since: lastDate, + }; + }, + getDateField() { + return "created_at"; + }, + async emitEvent(maxResults = false) { + const lastDate = this._getLastDate(); + const dateField = this.getDateField(); + const response = this.fakturoid.paginate({ + fn: this.getFunction(), + accountSlug: this.accountSlug, + params: this.getParams(lastDate), + }); + + let responseArray = []; + for await (const item of response) { + responseArray.push(item); + } + + if (responseArray.length) { + responseArray = responseArray + .sort((a, b) => Date.parse(b[dateField]) - Date.parse(a[dateField])); + + if (maxResults && (responseArray.length > maxResults)) { + responseArray.length = maxResults; + } + this._setLastDate(responseArray[0][dateField]); + } + + for (const item of responseArray.reverse()) { + this.$emit(item, { + id: `${item.id}-${item[dateField]}`, + summary: this.getSummary(item), + ts: Date.parse(item[dateField]), + }); + } + }, + }, + hooks: { + async deploy() { + await this.emitEvent(25); + }, + }, + async run() { + await this.emitEvent(); + }, +}; diff --git a/components/fakturoid/sources/invoice-updated/invoice-updated.mjs b/components/fakturoid/sources/invoice-updated/invoice-updated.mjs new file mode 100644 index 0000000000000..7a632c6c3615a --- /dev/null +++ b/components/fakturoid/sources/invoice-updated/invoice-updated.mjs @@ -0,0 +1,30 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "fakturoid-invoice-updated", + name: "New Invoice Updated", + description: "Emit new event when an invoice is created or updated.", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getFunction() { + return this.fakturoid.listInvoices; + }, + getSummary(invoice) { + return `New invoice updated: ${invoice.number}`; + }, + getParams(lastDate) { + return { + updated_since: lastDate, + }; + }, + getDateField() { + return "updated_at"; + }, + }, + sampleEmit, +}; diff --git a/components/fakturoid/sources/invoice-updated/test-event.mjs b/components/fakturoid/sources/invoice-updated/test-event.mjs new file mode 100644 index 0000000000000..63e50c797044c --- /dev/null +++ b/components/fakturoid/sources/invoice-updated/test-event.mjs @@ -0,0 +1,146 @@ +export default { + "id": 27, + "custom_id": null, + "document_type": "invoice", + "proforma_followup_document": null, + "correction_id": null, + "number": "2023-0021", + "number_format_id": 31, + "variable_symbol": "20230021", + "your_name": "Alexandr Hejsek", + "your_street": "Hopsinková 14", + "your_city": "Praha", + "your_zip": "10000", + "your_country": "CZ", + "your_registration_no": "87654321", + "your_vat_no": "CZ12121212", + "your_local_vat_no": null, + "client_name": "Apple Czech s.r.o.", + "client_street": "Klimentská 1216/46", + "client_city": "Praha", + "client_zip": "11000", + "client_country": "CZ", + "client_registration_no": "28897501", + "client_vat_no": "CZ28897501", + "client_local_vat_no": null, + "client_has_delivery_address": false, + "client_delivery_name": null, + "client_delivery_street": null, + "client_delivery_city": null, + "client_delivery_zip": null, + "client_delivery_country": null, + "subject_id": 16, + "subject_custom_id": null, + "generator_id": null, + "related_id": null, + "paypal": false, + "gopay": false, + "token": "69UqMuxhiA", + "status": "sent", + "order_number": null, + "issued_on": "2023-11-30", + "taxable_fulfillment_due": "2023-11-30", + "due": 14, + "due_on": "2023-12-14", + "sent_at": "2023-12-01T09:05:47.117+01:00", + "paid_on": null, + "reminder_sent_at": null, + "cancelled_at": null, + "uncollectible_at": null, + "locked_at": null, + "webinvoice_seen_on": null, + "note": "Fakturujeme Vám následující položky", + "footer_note": "", + "private_note": null, + "tags": [], + "bank_account": "1234/2010", + "iban": null, + "swift_bic": null, + "iban_visibility": "automatically", + "show_already_paid_note_in_pdf": false, + "payment_method": "bank", + "custom_payment_method": null, + "hide_bank_account": false, + "currency": "CZK", + "exchange_rate": "1.0", + "language": "cz", + "transferred_tax_liability": false, + "supply_code": null, + "oss": "disabled", + "vat_price_mode": "with_vat", + "subtotal": "9133.6", + "total": "11000.0", + "native_subtotal": "9133.6", + "native_total": "11000.0", + "remaining_amount": "11000.0", + "remaining_native_amount": "11000.0", + "eet_records": [], + "lines": [ + { + "id": 46, + "name": "Grafická karta", + "quantity": "1.0", + "unit_name": "", + "unit_price": "8264.0", + "vat_rate": 21, + "unit_price_without_vat": "8264.0", + "unit_price_with_vat": "10000.0", + "total_price_without_vat": "8264.0", + "total_vat": "1736.0", + "native_total_price_without_vat": "8264.0", + "native_total_vat": "1736.0", + "inventory": { + "item_id": 26, + "sku": "KU994RUR8465", + "article_number_type": null, + "article_number": null, + "move_id": 56 + } + }, + { + "id": 47, + "name": "Jídlo", + "quantity": "5.0", + "unit_name": "", + "unit_price": "173.92", + "vat_rate": 15, + "unit_price_without_vat": "173.92", + "unit_price_with_vat": "200.0", + "total_price_without_vat": "869.6", + "total_vat": "130.4", + "native_total_price_without_vat": "869.6", + "native_total_vat": "130.4", + "inventory": null + } + ], + "vat_rates_summary": [ + { + "vat_rate": 21, + "base": "8264.0", + "vat": "1736.0", + "currency": "CZK", + "native_base": "8264.0", + "native_vat": "1736.0", + "native_currency": "CZK" + }, + { + "vat_rate": 15, + "base": "869.6", + "vat": "130.4", + "currency": "CZK", + "native_base": "869.6", + "native_vat": "130.4", + "native_currency": "CZK" + } + ], + "paid_advances": [], + "payments": [], + "attachments": null, + "html_url": "https://app.fakturoid.cz/applecorp/invoices/27", + "public_html_url": "https://app.fakturoid.cz/applecorp/p/69UqMuxhiA/2023-0021", + "url": "https://app.fakturoid.cz/api/v3/accounts/applecorp/invoices/27.json", + "pdf_url": "https://app.fakturoid.cz/api/v3/accounts/applecorp/invoices/27/download.pdf", + "subject_url": "https://app.fakturoid.cz/api/v3/accounts/applecorp/subjects/16.json", + "created_at": "2023-11-30T13:50:45.848+01:00", + "updated_at": "2023-12-01T09:05:47.187+01:00" +} \ No newline at end of file diff --git a/components/fakturoid/sources/new-contact/new-contact.mjs b/components/fakturoid/sources/new-contact/new-contact.mjs new file mode 100644 index 0000000000000..b90f04af741cf --- /dev/null +++ b/components/fakturoid/sources/new-contact/new-contact.mjs @@ -0,0 +1,22 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "fakturoid-new-contact", + name: "New Contact Added", + description: "Emit new event when a contact (subject) is added in Fakturoid.", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getFunction() { + return this.fakturoid.listSubjects; + }, + getSummary(contact) { + return `New Contact Added: ${contact.name}`; + }, + }, + sampleEmit, +}; diff --git a/components/fakturoid/sources/new-contact/test-event.mjs b/components/fakturoid/sources/new-contact/test-event.mjs new file mode 100644 index 0000000000000..4e23ba4496728 --- /dev/null +++ b/components/fakturoid/sources/new-contact/test-event.mjs @@ -0,0 +1,53 @@ +export default { + "id": 16, + "custom_id": null, + "user_id": null, + "type": "customer", + "name": "Apple Czech s.r.o.", + "full_name": null, + "email": "pokus@test.cz", + "email_copy": null, + "phone": null, + "web": "https://www.apple.cz", + "street": "Klimentská 1216/46", + "city": "Praha", + "zip": "11000", + "country": "CZ", + "has_delivery_address": false, + "delivery_name": null, + "delivery_street": null, + "delivery_city": null, + "delivery_zip": null, + "delivery_country": null, + "due": null, + "currency": null, + "language": null, + "private_note": null, + "registration_no": "28897501", + "vat_no": "CZ28897501", + "local_vat_no": null, + "unreliable": null, + "unreliable_checked_at": null, + "legal_form": null, + "vat_mode": null, + "bank_account": null, + "iban": null, + "swift_bic": null, + "variable_symbol": null, + "setting_update_from_ares": "inherit", + "ares_update": false, + "setting_invoice_pdf_attachments": "inherit", + "setting_estimate_pdf_attachments": "inherit", + "setting_invoice_send_reminders": "inherit", + "suggestion_enabled": true, + "custom_email_text": null, + "overdue_email_text": null, + "invoice_from_proforma_email_text": null, + "thank_you_email_text": null, + "custom_estimate_email_text": null, + "webinvoice_history": null, + "html_url": "https://app.fakturoid.cz/applecorp/subjects/16", + "url": "https://app.fakturoid.cz/api/v3/accounts/applecorp/subjects/16.json", + "created_at": "2023-08-22T10:59:00.330+02:00", + "updated_at": "2023-08-22T10:59:00.330+02:00" +} \ No newline at end of file diff --git a/components/fakturoid/sources/new-invoice/new-invoice.mjs b/components/fakturoid/sources/new-invoice/new-invoice.mjs new file mode 100644 index 0000000000000..9369ed5788fc9 --- /dev/null +++ b/components/fakturoid/sources/new-invoice/new-invoice.mjs @@ -0,0 +1,22 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "fakturoid-new-invoice", + name: "New Invoice Created", + description: "Emit new event when a new invoice is created in Fakturoid.", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getFunction() { + return this.fakturoid.listInvoices; + }, + getSummary(invoice) { + return `New invoice created: ${invoice.number}`; + }, + }, + sampleEmit, +}; diff --git a/components/fakturoid/sources/new-invoice/test-event.mjs b/components/fakturoid/sources/new-invoice/test-event.mjs new file mode 100644 index 0000000000000..63e50c797044c --- /dev/null +++ b/components/fakturoid/sources/new-invoice/test-event.mjs @@ -0,0 +1,146 @@ +export default { + "id": 27, + "custom_id": null, + "document_type": "invoice", + "proforma_followup_document": null, + "correction_id": null, + "number": "2023-0021", + "number_format_id": 31, + "variable_symbol": "20230021", + "your_name": "Alexandr Hejsek", + "your_street": "Hopsinková 14", + "your_city": "Praha", + "your_zip": "10000", + "your_country": "CZ", + "your_registration_no": "87654321", + "your_vat_no": "CZ12121212", + "your_local_vat_no": null, + "client_name": "Apple Czech s.r.o.", + "client_street": "Klimentská 1216/46", + "client_city": "Praha", + "client_zip": "11000", + "client_country": "CZ", + "client_registration_no": "28897501", + "client_vat_no": "CZ28897501", + "client_local_vat_no": null, + "client_has_delivery_address": false, + "client_delivery_name": null, + "client_delivery_street": null, + "client_delivery_city": null, + "client_delivery_zip": null, + "client_delivery_country": null, + "subject_id": 16, + "subject_custom_id": null, + "generator_id": null, + "related_id": null, + "paypal": false, + "gopay": false, + "token": "69UqMuxhiA", + "status": "sent", + "order_number": null, + "issued_on": "2023-11-30", + "taxable_fulfillment_due": "2023-11-30", + "due": 14, + "due_on": "2023-12-14", + "sent_at": "2023-12-01T09:05:47.117+01:00", + "paid_on": null, + "reminder_sent_at": null, + "cancelled_at": null, + "uncollectible_at": null, + "locked_at": null, + "webinvoice_seen_on": null, + "note": "Fakturujeme Vám následující položky", + "footer_note": "", + "private_note": null, + "tags": [], + "bank_account": "1234/2010", + "iban": null, + "swift_bic": null, + "iban_visibility": "automatically", + "show_already_paid_note_in_pdf": false, + "payment_method": "bank", + "custom_payment_method": null, + "hide_bank_account": false, + "currency": "CZK", + "exchange_rate": "1.0", + "language": "cz", + "transferred_tax_liability": false, + "supply_code": null, + "oss": "disabled", + "vat_price_mode": "with_vat", + "subtotal": "9133.6", + "total": "11000.0", + "native_subtotal": "9133.6", + "native_total": "11000.0", + "remaining_amount": "11000.0", + "remaining_native_amount": "11000.0", + "eet_records": [], + "lines": [ + { + "id": 46, + "name": "Grafická karta", + "quantity": "1.0", + "unit_name": "", + "unit_price": "8264.0", + "vat_rate": 21, + "unit_price_without_vat": "8264.0", + "unit_price_with_vat": "10000.0", + "total_price_without_vat": "8264.0", + "total_vat": "1736.0", + "native_total_price_without_vat": "8264.0", + "native_total_vat": "1736.0", + "inventory": { + "item_id": 26, + "sku": "KU994RUR8465", + "article_number_type": null, + "article_number": null, + "move_id": 56 + } + }, + { + "id": 47, + "name": "Jídlo", + "quantity": "5.0", + "unit_name": "", + "unit_price": "173.92", + "vat_rate": 15, + "unit_price_without_vat": "173.92", + "unit_price_with_vat": "200.0", + "total_price_without_vat": "869.6", + "total_vat": "130.4", + "native_total_price_without_vat": "869.6", + "native_total_vat": "130.4", + "inventory": null + } + ], + "vat_rates_summary": [ + { + "vat_rate": 21, + "base": "8264.0", + "vat": "1736.0", + "currency": "CZK", + "native_base": "8264.0", + "native_vat": "1736.0", + "native_currency": "CZK" + }, + { + "vat_rate": 15, + "base": "869.6", + "vat": "130.4", + "currency": "CZK", + "native_base": "869.6", + "native_vat": "130.4", + "native_currency": "CZK" + } + ], + "paid_advances": [], + "payments": [], + "attachments": null, + "html_url": "https://app.fakturoid.cz/applecorp/invoices/27", + "public_html_url": "https://app.fakturoid.cz/applecorp/p/69UqMuxhiA/2023-0021", + "url": "https://app.fakturoid.cz/api/v3/accounts/applecorp/invoices/27.json", + "pdf_url": "https://app.fakturoid.cz/api/v3/accounts/applecorp/invoices/27/download.pdf", + "subject_url": "https://app.fakturoid.cz/api/v3/accounts/applecorp/subjects/16.json", + "created_at": "2023-11-30T13:50:45.848+01:00", + "updated_at": "2023-12-01T09:05:47.187+01:00" +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1b466f7fb8e84..8c97b6c4673c6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3289,7 +3289,10 @@ importers: fs: 0.0.1-security components/fakturoid: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/faraday: specifiers: