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
139 changes: 139 additions & 0 deletions components/the_bookie/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { ConfigurationError } from "@pipedream/platform";
import thebookie from "../../the_bookie.app.mjs";

export default {
key: "the_bookie-create-contact",
name: "Create Contact",
description: "Instantly creates a new contact in the address book. [See the documentation](https://app.thebookie.nl/nl/help/article/api-documentatie/#contact_create)",
version: "0.0.1",
type: "action",
props: {
thebookie,
organisationName: {
type: "string",
label: "Organisation Name",
description: "The contact's organization name",
},
street: {
type: "string",
label: "Street",
description: "The contact's address street",
optional: true,
},
streetNumber: {
type: "string",
label: "Street Number",
description: "The contact's address number",
optional: true,
},
streetNumberAddition: {
type: "string",
label: "Street Number Addition",
description: "The contact's address number addition",
optional: true,
},
extraAddressLine: {
type: "string",
label: "Extra Address Line",
description: "The contact's extra address line",
optional: true,
},
postalCode: {
type: "string",
label: "Postal Code",
description: "The contact's address postal code",
optional: true,
},
town: {
type: "string",
label: "Town",
description: "The contact's city",
optional: true,
},
country: {
type: "string",
label: "Country",
description: "The contact's country",
optional: true,
},
isSupplier: {
type: "boolean",
label: "Is Supplier",
description: "Whether the contact is supplier or not",
optional: true,
},
isClient: {
type: "boolean",
label: "Is Client",
description: "Whether the contact is client or not",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "The contact's email address",
optional: true,
},
telephoneNumber: {
type: "string",
label: "Telephone Number",
description: "The contact's telephone number",
optional: true,
},
mobileNumber: {
type: "string",
label: "Mobile Number",
description: "The contact's mobile number",
optional: true,
},
firstName: {
type: "string",
label: "First Name",
description: "First name of the contact",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "Last name of the contact",
optional: true,
},
extraInfo: {
type: "string",
label: "Extra Info",
description: "An additional info",
optional: true,
},
},
async run({ $ }) {
if (!this.isClient && !this.isSupplier) {
throw new ConfigurationError("'Is Supplier' or 'Is Client' must be true (or both)");
}

const response = await this.thebookie.createContact({
$,
data: {
organisation_name: this.organisationName,
street: this.street,
street_number: this.streetNumber,
street_number_addition: this.streetNumberAddition,
extra_address_line: this.extraAddressLine,
postal_code: this.postalCode,
town: this.town,
country: this.country,
is_supplier: this.isSupplier,
is_client: this.isClient,
email: this.email,
telephone_number: this.telephoneNumber,
mobile_number: this.mobileNumber,
first_name: this.firstName,
last_name: this.lastName,
extra_info: this.extraInfo,
},
});

$.export("$summary", `Successfully created contact with ID ${response.id}`);

return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { ConfigurationError } from "@pipedream/platform";
import fs from "fs";
import {
checkTmp, parseObject,
} from "../../common/utils.mjs";
import theBookie from "../../the_bookie.app.mjs";

export default {
key: "the_bookie-create-sales-invoice",
name: "Create Sales Invoice",
description: "Creates a new sales invoice. [See the documentation](https://app.thebookie.nl/nl/help/article/api-documentatie/#salesentry_create)",
version: "0.0.1",
type: "action",
props: {
theBookie,
contactId: {
propDefinition: [
theBookie,
"contactId",
],
},
invoiceNumber: {
type: "string",
label: "Invoice Number",
description: "The number of the invoice",
},
invoiceDate: {
type: "string",
label: "Invoice Date",
description: "The date of the invoice. **Format: YYYY-MM-DD**",
},
expirationDate: {
type: "string",
label: "Expiration Date",
description: "The expiration date of the invoice. **Format: YYYY-MM-DD**",
},
btwShifted: {
type: "string",
label: "VAT shifted",
description: "The VAT type",
options: [
{
label: "No (standard)",
value: "NONE",
},
{
label: "Shifted within The Netherlands",
value: "NL",
},
{
label: "Shifted within EU",
value: "EU",
},
{
label: "Shifted outside EU",
value: "NON_EU",
},
],
optional: true,
},
journalEntryLines: {
type: "string[]",
label: "Journal Entry Lines",
description: "An array of stringified objects of item entry lines. **Example: { \"description\": \"Boekregel 1\", \"btw_type\": \"PROCENT_21\", \"amount\": \"1200.0\", \"quantity\": \"2.00\"}** btw_type can be only 'PERCENT_9', 'PERCENT_21' or 'PERCENT_0'",
optional: true,
},
attachment: {
type: "string",
label: "Attachment",
description: "The path to the pdf file saved to the `/tmp` directory (e.g. `/tmp/example.pdf`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).",
optional: true,
},
},
async run({ $ }) {
if (!this.journalEntryLines) {
throw new ConfigurationError("At least one (1) 'Journal Entry Line' should be added");
}
if (this.attachment) {
this.attachment = fs.readFileSync(checkTmp(this.attachment), {
encoding: "base64",
});
}
const response = await this.theBookie.createInvoice({
$,
data: {
contact_id: this.contactId,
invoice_number: this.invoiceNumber,
invoice_date: this.invoiceDate,
expiration_date: this.expirationDate,
btw_shifted: this.btwShifted,
journal_entry_lines: parseObject(this.journalEntryLines),
attachment: this.attachment,
},
});

$.export("$summary", `Successfully created invoice with number ${this.invoiceNumber}`);
return response;
},
};
51 changes: 51 additions & 0 deletions components/the_bookie/actions/find-contact/find-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { capitalize } from "../../common/utils.mjs";
import theBookie from "../../the_bookie.app.mjs";

export default {
key: "the_bookie-find-contact",
name: "Find Contacts",
description: "Find a contact from the address book. [See the documentation](https://app.thebookie.nl/nl/help/article/api-documentatie/#contact_list)",
version: "0.0.1",
type: "action",
props: {
theBookie,
search: {
type: "string",
label: "Search",
description: "Search by company name.",
optional: true,
},
isClient: {
type: "boolean",
label: "Is Client",
description: "Return only client contacts.",
optional: true,
},
isSupplier: {
type: "boolean",
label: "Is Supplier",
description: "Return only supplier contacts.",
optional: true,
},
},
async run({ $ }) {
const response = this.theBookie.paginate({
$,
fn: this.theBookie.searchContact,
params: {
search: this.search,
is_client: capitalize(this.isClient),
is_supplier: capitalize(this.isSupplier),
},
});

const responseArray = [];

for await (const item of response) {
responseArray.push(item);
}

$.export("$summary", `Found ${responseArray.length} contact(s)`);
return responseArray;
},
};
1 change: 1 addition & 0 deletions components/the_bookie/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LIMIT = 100;
37 changes: 37 additions & 0 deletions components/the_bookie/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export const checkTmp = (filename) => {
if (!filename.startsWith("/tmp")) {
return `/tmp/${filename}`;
}
return filename;
};

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;
};

export const capitalize = (string) => {
if (!string) return null;
string = string.toString();
return string[0].toUpperCase() + string.slice(1);
};
8 changes: 6 additions & 2 deletions components/the_bookie/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/the_bookie",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream The Bookie Components",
"main": "the_bookie.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.1"
}
}
}

Loading
Loading