Skip to content

Commit f3a8dc7

Browse files
luancazarinejcortes
authored andcommitted
New Components - zoho-sheet (#14633)
* zoho_sheet init * [Components] zoho_sheet #14584 Sources - New Row (Instant) - New Or Updated Row (Instant) - New Workbook (Instant) Actions - Create Row - Search Delete Row - Update Row * pnpm update * Update components/zoho_sheet/sources/common/base.mjs Co-authored-by: Jorge Cortes <[email protected]> --------- Co-authored-by: Jorge Cortes <[email protected]>
1 parent 0395d74 commit f3a8dc7

File tree

16 files changed

+615
-22
lines changed

16 files changed

+615
-22
lines changed

components/zoho_sheet/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import zohoSheet from "../../zoho_sheet.app.mjs";
3+
4+
export default {
5+
key: "zoho_sheet-create-row",
6+
name: "Create Row",
7+
description: "Creates a new row in the specified worksheet. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
zohoSheet,
12+
workbookId: {
13+
propDefinition: [
14+
zohoSheet,
15+
"workbookId",
16+
],
17+
},
18+
worksheet: {
19+
propDefinition: [
20+
zohoSheet,
21+
"worksheet",
22+
({ workbookId }) => ({
23+
workbookId,
24+
}),
25+
],
26+
},
27+
headerRow: {
28+
type: "integer",
29+
label: "Header Row",
30+
description: "Default value is 1. This can be mentioned if the table header is not in the first row of the worksheet.",
31+
optional: true,
32+
},
33+
data: {
34+
propDefinition: [
35+
zohoSheet,
36+
"data",
37+
],
38+
},
39+
},
40+
async run({ $ }) {
41+
const response = await this.zohoSheet.createRow({
42+
$,
43+
workbookId: this.workbookId,
44+
data: {
45+
worksheet_id: this.worksheet,
46+
header_row: this.headerRow || 1,
47+
json_data: JSON.stringify(parseObject(this.data)),
48+
},
49+
});
50+
51+
$.export("$summary", `Successfully created a row in the worksheet: ${response.sheet_name}`);
52+
return response;
53+
},
54+
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import zohoSheet from "../../zoho_sheet.app.mjs";
4+
5+
export default {
6+
key: "zoho_sheet-search-delete-row",
7+
name: "Search and Delete Row",
8+
description: "Searches for a row based on provided criteria and deletes it. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
zohoSheet,
13+
workbookId: {
14+
propDefinition: [
15+
zohoSheet,
16+
"workbookId",
17+
],
18+
},
19+
worksheet: {
20+
propDefinition: [
21+
zohoSheet,
22+
"worksheet",
23+
({ workbookId }) => ({
24+
workbookId,
25+
}),
26+
],
27+
},
28+
headerRow: {
29+
propDefinition: [
30+
zohoSheet,
31+
"headerRow",
32+
],
33+
optional: true,
34+
},
35+
criteria: {
36+
propDefinition: [
37+
zohoSheet,
38+
"criteria",
39+
],
40+
optional: true,
41+
},
42+
rowArray: {
43+
type: "integer[]",
44+
label: "Row Array",
45+
description: "Array of row indexs, which needs to be deleted.",
46+
optional: true,
47+
},
48+
firstMatchOnly: {
49+
propDefinition: [
50+
zohoSheet,
51+
"firstMatchOnly",
52+
],
53+
},
54+
isCaseSensitive: {
55+
propDefinition: [
56+
zohoSheet,
57+
"isCaseSensitive",
58+
],
59+
},
60+
deleteRows: {
61+
type: "boolean",
62+
label: "Delete Rows",
63+
description: "If true it will delete the rows completely, otherwise the records are only erased by default.",
64+
default: false,
65+
},
66+
},
67+
async run({ $ }) {
68+
if (!this.criteria && !this.rowArray) {
69+
throw new ConfigurationError("You must provide at least **Criteria** or **Row Array** to process this request.");
70+
}
71+
const response = await this.zohoSheet.deleteRow({
72+
$,
73+
workbookId: this.workbookId,
74+
data: {
75+
worksheet_id: this.worksheet,
76+
header_row: this.headerRow,
77+
criteria: this.criteria,
78+
row_array: JSON.stringify(parseObject(this.rowArray)),
79+
first_match_only: this.firstMatchOnly,
80+
is_case_sensitive: this.isCaseSensitive,
81+
delete_rows: this.deleteRows,
82+
},
83+
});
84+
85+
$.export("$summary", `Row matching criteria deleted successfully from worksheet ${this.worksheet}`);
86+
return response;
87+
},
88+
};
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import zohoSheet from "../../zoho_sheet.app.mjs";
3+
4+
export default {
5+
key: "zoho_sheet-update-row",
6+
name: "Update Row",
7+
description: "Finds a specific row by its index and updates its content. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
zohoSheet,
12+
workbookId: {
13+
propDefinition: [
14+
zohoSheet,
15+
"workbookId",
16+
],
17+
},
18+
worksheet: {
19+
propDefinition: [
20+
zohoSheet,
21+
"worksheet",
22+
({ workbookId }) => ({
23+
workbookId,
24+
}),
25+
],
26+
},
27+
headerRow: {
28+
propDefinition: [
29+
zohoSheet,
30+
"headerRow",
31+
],
32+
optional: true,
33+
},
34+
criteria: {
35+
propDefinition: [
36+
zohoSheet,
37+
"criteria",
38+
],
39+
description: "If criteria is not set all available rows will get updated. Mention the criteria as described above.",
40+
optional: true,
41+
},
42+
firstMatchOnly: {
43+
propDefinition: [
44+
zohoSheet,
45+
"firstMatchOnly",
46+
],
47+
description: "If true and if there are multiple records on the specified criteria, records will be updated for first match alone. Otherwise, all the matched records will be updated.",
48+
},
49+
isCaseSensitive: {
50+
propDefinition: [
51+
zohoSheet,
52+
"isCaseSensitive",
53+
],
54+
},
55+
data: {
56+
propDefinition: [
57+
zohoSheet,
58+
"data",
59+
],
60+
type: "object",
61+
description: "The JSON data that needs to be updated. Example:{\"Month\":\"May\",\"Amount\":50}",
62+
},
63+
},
64+
async run({ $ }) {
65+
const response = await this.zohoSheet.updateRow({
66+
$,
67+
workbookId: this.workbookId,
68+
data: {
69+
worksheet_id: this.worksheet,
70+
header_row: this.headerRow,
71+
criteria: this.criteria,
72+
first_match_only: this.firstMatchOnly,
73+
is_case_sensitive: this.isCaseSensitive,
74+
data: JSON.stringify(parseObject(this.data)),
75+
},
76+
});
77+
78+
$.export("$summary", `Successfully updated ${response.no_of_affected_rows} row(s) in worksheet ${this.worksheet}`);
79+
return response;
80+
},
81+
};

components/zoho_sheet/app/zoho_sheet.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/zoho_sheet/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "@pipedream/zoho_sheet",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "Pipedream Zoho Sheet Components",
5-
"main": "dist/app/zoho_sheet.app.mjs",
5+
"main": "zoho_sheet.app.mjs",
66
"keywords": [
77
"pipedream",
88
"zoho_sheet"
99
],
10-
"files": [
11-
"dist"
12-
],
1310
"homepage": "https://pipedream.com/apps/zoho_sheet",
1411
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1512
"publishConfig": {
1613
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1717
}
1818
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import zohoSheet from "../../zoho_sheet.app.mjs";
2+
3+
export default {
4+
props: {
5+
zohoSheet,
6+
http: "$.interface.http",
7+
db: "$.service.db",
8+
serviceName: {
9+
type: "string",
10+
label: "Service Name",
11+
description: "The name of the webhook.",
12+
},
13+
},
14+
methods: {
15+
getExtraData() {
16+
return {};
17+
},
18+
},
19+
hooks: {
20+
async activate() {
21+
await this.zohoSheet.createWebhook({
22+
data: {
23+
service_name: this.serviceName.replace(/\s/g, ""),
24+
target_url: this.http.endpoint,
25+
event: this.getEvent(),
26+
...this.getExtraData(),
27+
},
28+
});
29+
},
30+
async deactivate() {
31+
await this.zohoSheet.deleteWebhook({
32+
data: {
33+
target_url: this.http.endpoint,
34+
...this.getExtraData(),
35+
},
36+
});
37+
},
38+
},
39+
async run({ body }) {
40+
const ts = Date.parse(new Date());
41+
this.$emit(body, {
42+
id: `${ts}`,
43+
summary: this.getSummary(body),
44+
ts: ts,
45+
});
46+
},
47+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "zoho_sheet-new-or-updated-row-instant",
7+
name: "New or Updated Row (Instant)",
8+
description: "Emit new event whenever a row is added or modified.",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
...common.props,
14+
workbookId: {
15+
propDefinition: [
16+
common.props.zohoSheet,
17+
"workbookId",
18+
],
19+
},
20+
worksheetId: {
21+
propDefinition: [
22+
common.props.zohoSheet,
23+
"worksheet",
24+
({ workbookId }) => ({
25+
workbookId,
26+
}),
27+
],
28+
withLabel: true,
29+
},
30+
alert: {
31+
type: "alert",
32+
alertType: "info",
33+
content: "**New row** will be triggered only after the entire row is completed.",
34+
},
35+
},
36+
methods: {
37+
...common.methods,
38+
getEvent() {
39+
return "update_worksheet";
40+
},
41+
getExtraData() {
42+
return {
43+
resource_id: this.workbookId,
44+
worksheet_id: this.worksheetId.value,
45+
};
46+
},
47+
getSummary({ updated_rows }) {
48+
return `Row ${updated_rows[0].row_type === "NEW"
49+
? "created"
50+
: "updated"} in worksheet ${this.worksheetId.label}`;
51+
},
52+
},
53+
sampleEmit,
54+
};

0 commit comments

Comments
 (0)