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

export default {
key: "remote-create-expense",
name: "Create Expense",
description: "Create an expense in Remote. [See the documentation](https://developer.remote.com/reference/post_create_expense)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
remote,
amount: {
type: "integer",
label: "Amount",
description: "The amount of the expense",
},
currency: {
type: "string",
label: "Currency",
description: "The currency of the expense",
options: [
"USD",
"EUR",
"CAD",
],
},
employmentId: {
propDefinition: [
remote,
"employmentId",
],
},
expenseCategorySlug: {
propDefinition: [
remote,
"expenseCategorySlug",
({ employmentId }) => ({
employmentId,
}),
],
},
expenseDate: {
type: "string",
label: "Expense Date",
description: "Date of the purchase, which must be in the past. **Format: YYYY-MM-DD**",
},
receiptContentFilePath: {
type: "string",
label: "Receipt Content File Path",
description: "The file of the receipt. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.pdf`)",
},
receiptFileName: {
type: "string",
label: "Receipt File Name",
description: "The file name",
},
reviewedAt: {
type: "string",
label: "Reviewed At",
description: "The date and time that the expense was reviewed in ISO8601 format. If not provided, it defaults to the current datetime. **Format: YYYY-MM-DDTHH:MM:SS**",
},
taxAmount: {
type: "integer",
label: "Tax Amount",
description: "The tax amount of the expense",
optional: true,
},
timezone: {
type: "string",
label: "Timezone",
description: "The timezone of the expense. [TZ identifier](https://www.iana.org/time-zones)",
optional: true,
},
title: {
type: "string",
label: "Title",
description: "The title of the expense",
},
syncDir: {
type: "dir",
accessMode: "read",
sync: true,
},
},
methods: {
async streamToBase64(stream) {
return new Promise((resolve, reject) => {
const chunks = [];

stream.on("data", (chunk) => {
chunks.push(chunk);
});

stream.on("end", () => {
const buffer = Buffer.concat(chunks);
resolve(buffer.toString("base64"));
});

stream.on("error", (err) => {
reject(err);
});
});
},
},
async run({ $ }) {
const {
stream, metadata,
} = await getFileStreamAndMetadata(this.receiptContentFilePath);
const base64String = await this.streamToBase64(stream);

const response = await this.remote.createExpense({
$,
data: {
amount: this.amount,
currency: this.currency,
employment_id: this.employmentId,
expense_date: this.expenseDate,
title: this.title,
receipt: {
content: `data:${metadata.contentType};base64,${base64String}`,
name: this.receiptFileName,
},
expense_category_slug: this.expenseCategorySlug,
reviewed_at: this.reviewedAt,
tax_amount: this.taxAmount,
timezone: this.timezone,
},
});

$.export("$summary", `Successfully created expense with ID: ${response?.data?.expense?.id}`);
return response;
},
};
72 changes: 72 additions & 0 deletions components/remote/actions/list-employments/list-employments.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import remote from "../../remote.app.mjs";

export default {
key: "remote-list-employments",
name: "List Employments",
description: "List employments in Remote. [See the documentation](https://developer.remote.com/reference/get_index_employment)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
remote,
email: {
type: "string",
label: "Email",
description: "Filters the results by employments whose login email matches the value",
optional: true,
},
employmentType: {
type: "string",
label: "Employment Type",
description: "Filters the results by employments whose employment product type matches the value",
optional: true,
options: [
"contractor",
"direct_employee",
"employee",
],
},
employmentModel: {
type: "string",
label: "Employment Model",
description: "Filters the results by employments whose employment model matches the value",
optional: true,
options: [
"global_payroll",
"peo",
"eor",
],
},
maxResults: {
type: "integer",
label: "Max Results",
description: "The maximum number of results to return",
optional: true,
},
},
async run({ $ }) {
const response = this.remote.paginate({
$,
dataKey: "employments",
fn: this.remote.listEmployments,
params: {
email: this.email,
employment_type: this.employmentType,
employment_model: this.employmentModel,
},
maxResults: this.maxResults,
});

const responseArray = [];
for await (const employment of response) {
responseArray.push(employment);
}

$.export("$summary", `Successfully listed ${responseArray.length} employments`);
return responseArray;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import remote from "../../remote.app.mjs";

export default {
key: "remote-show-timeoff-balance",
name: "Show Time Off Balance",
description: "Show the time off balance for an employment in Remote. [See the documentation](https://developer.remote.com/reference/get_show_timeoff_balance)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
remote,
employmentId: {
propDefinition: [
remote,
"employmentId",
],
},
},
async run({ $ }) {
const response = await this.remote.showTimeoffBalance({
$,
employmentId: this.employmentId,
});

$.export("$summary", `Successfully retrieved time off balance for employment with ID: ${this.employmentId}`);
return response;
},
};
5 changes: 4 additions & 1 deletion components/remote/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/remote",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Remote Components",
"main": "remote.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
Loading
Loading