Skip to content

Commit 733e7a8

Browse files
committed
zoho-sheet init
1 parent 6b37fff commit 733e7a8

File tree

7 files changed

+471
-0
lines changed

7 files changed

+471
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import zohoSheet from "../../zoho-sheet.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "zoho-sheet-create-row",
6+
name: "Create Row in Zoho Sheet",
7+
description: "Creates a new row in a specified worksheet. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
zohoSheet,
12+
worksheet: {
13+
propDefinition: [
14+
zohoSheet,
15+
"worksheet",
16+
],
17+
},
18+
data: {
19+
propDefinition: [
20+
zohoSheet,
21+
"data",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.zohoSheet.addNewRow({
27+
worksheet: this.worksheet,
28+
data: this.data,
29+
});
30+
$.export("$summary", `Successfully added a new row to the worksheet ${this.worksheet}`);
31+
return response;
32+
},
33+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import zohoSheet from "../../zoho-sheet.app.mjs";
2+
3+
export default {
4+
key: "zoho-sheet-search-delete-row",
5+
name: "Search and Delete Row",
6+
description: "Searches for a row based on the provided criteria and deletes it. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
zohoSheet,
11+
worksheet: {
12+
propDefinition: [
13+
zohoSheet,
14+
"worksheet",
15+
],
16+
},
17+
criteria: {
18+
propDefinition: [
19+
zohoSheet,
20+
"criteria",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.zohoSheet.deleteRow({
26+
worksheet: this.worksheet,
27+
criteria: this.criteria,
28+
});
29+
$.export("$summary", "Successfully searched and deleted row(s) based on the provided criteria.");
30+
return response;
31+
},
32+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import zohoSheet from "../../zoho-sheet.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "zoho-sheet-update-row",
6+
name: "Update Row",
7+
description: "Finds a specific row via its index and updates its content. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
zohoSheet,
12+
worksheet: {
13+
propDefinition: [
14+
zohoSheet,
15+
"worksheet",
16+
],
17+
},
18+
rowIndex: {
19+
propDefinition: [
20+
zohoSheet,
21+
"rowIndex",
22+
],
23+
},
24+
data: {
25+
propDefinition: [
26+
zohoSheet,
27+
"data",
28+
],
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.zohoSheet.updateRow({
33+
worksheet: this.worksheet,
34+
rowIndex: this.rowIndex,
35+
data: this.data,
36+
});
37+
38+
$.export("$summary", `Successfully updated row ${this.rowIndex} in worksheet ${this.worksheet}`);
39+
return response;
40+
},
41+
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import zohoSheet from "../../zoho-sheet.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "zoho-sheet-new-or-updated-row-instant",
6+
name: "New or Updated Row Instant",
7+
description: "Emit new event whenever a row is added or modified. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
zohoSheet,
13+
http: {
14+
type: "$.interface.http",
15+
customResponse: false,
16+
},
17+
db: "$.service.db",
18+
worksheet: {
19+
propDefinition: [
20+
zohoSheet,
21+
"worksheet",
22+
],
23+
},
24+
},
25+
methods: {
26+
_getWebhookIds() {
27+
return this.db.get("webhookIds");
28+
},
29+
_setWebhookIds(ids) {
30+
this.db.set("webhookIds", ids);
31+
},
32+
},
33+
hooks: {
34+
async deploy() {
35+
// Handle deployment logic here if required, e.g., fetching past events
36+
},
37+
async activate() {
38+
const newRowWebhook = await this.zohoSheet.watchNewRow({
39+
worksheet: this.worksheet,
40+
});
41+
const rowChangeWebhook = await this.zohoSheet.watchRowChange({
42+
worksheet: this.worksheet,
43+
});
44+
45+
this._setWebhookIds({
46+
new_row: newRowWebhook,
47+
row_change: rowChangeWebhook,
48+
});
49+
},
50+
async deactivate() {
51+
const {
52+
new_row, row_change,
53+
} = this._getWebhookIds();
54+
if (new_row) {
55+
await this.zohoSheet._makeRequest({
56+
method: "POST",
57+
path: "/webhook",
58+
data: {
59+
method: "webhook.unsubscribe",
60+
webhook_id: new_row,
61+
},
62+
});
63+
}
64+
if (row_change) {
65+
await this.zohoSheet._makeRequest({
66+
method: "POST",
67+
path: "/webhook",
68+
data: {
69+
method: "webhook.unsubscribe",
70+
webhook_id: row_change,
71+
},
72+
});
73+
}
74+
},
75+
},
76+
async run(event) {
77+
const { body } = event;
78+
this.$emit(body, {
79+
id: body.id || Date.now(),
80+
summary: `New or updated row in worksheet: ${this.worksheet}`,
81+
ts: Date.now(),
82+
});
83+
},
84+
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import zohoSheet from "../../zoho-sheet.app.mjs";
2+
import crypto from "crypto";
3+
import { axios } from "@pipedream/platform";
4+
5+
export default {
6+
key: "zoho-sheet-new-row-instant",
7+
name: "New Row Instant",
8+
description: "Emit a new event each time a new row is created in a Zoho Sheet worksheet. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
9+
version: "0.0.{{ts}}",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
zohoSheet,
14+
worksheet: {
15+
propDefinition: [
16+
zohoSheet,
17+
"worksheet",
18+
],
19+
},
20+
http: {
21+
type: "$.interface.http",
22+
customResponse: true,
23+
},
24+
db: "$.service.db",
25+
},
26+
methods: {
27+
_getWebhookId() {
28+
return this.db.get("webhookId");
29+
},
30+
_setWebhookId(id) {
31+
this.db.set("webhookId", id);
32+
},
33+
},
34+
hooks: {
35+
async deploy() {
36+
// Implement fetching and emitting historical events if applicable with Zoho Sheet API
37+
},
38+
async activate() {
39+
const response = await this.zohoSheet.watchNewRow({
40+
worksheet: this.worksheet,
41+
});
42+
this._setWebhookId(response.webhookId);
43+
},
44+
async deactivate() {
45+
const webhookId = this._getWebhookId();
46+
if (webhookId) {
47+
await this.zohoSheet.deleteWebhook({
48+
id: webhookId,
49+
});
50+
}
51+
},
52+
},
53+
async run(event) {
54+
if (!this.http.body) {
55+
this.http.respond({
56+
status: 400,
57+
body: "Bad Request",
58+
});
59+
return;
60+
}
61+
62+
const webhookSignature = event.headers["x-zoho-signature"];
63+
const secretKey = this.zohoSheet.$auth.oauth_access_token;
64+
const rawBody = event.rawBody;
65+
66+
const computedSignature = crypto.createHmac("sha256", secretKey).update(rawBody)
67+
.digest("base64");
68+
if (computedSignature !== webhookSignature) {
69+
this.http.respond({
70+
status: 401,
71+
body: "Unauthorized",
72+
});
73+
return;
74+
}
75+
76+
this.http.respond({
77+
status: 200,
78+
body: "OK",
79+
});
80+
81+
const row = event.body;
82+
this.$emit(row, {
83+
id: row.id,
84+
summary: `New row added to worksheet ${this.worksheet}`,
85+
ts: Date.now(),
86+
});
87+
},
88+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import zohoSheet from "../../zoho-sheet.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "zoho-sheet-new-workbook-instant",
6+
name: "New Workbook Created",
7+
description: "Emit new event when a new workbook is created. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
zohoSheet: {
13+
type: "app",
14+
app: "zoho_sheet",
15+
},
16+
http: {
17+
type: "$.interface.http",
18+
customResponse: false,
19+
},
20+
db: "$.service.db",
21+
location: {
22+
propDefinition: [
23+
zohoSheet,
24+
"location",
25+
],
26+
},
27+
},
28+
hooks: {
29+
async deploy() {
30+
const workbooks = await this.zohoSheet._makeRequest({
31+
method: "GET",
32+
path: "/workbooks",
33+
});
34+
const recentWorkbooks = workbooks.slice(-50).reverse();
35+
for (const workbook of recentWorkbooks) {
36+
this.$emit(workbook, {
37+
id: workbook.id,
38+
summary: `New workbook created: ${workbook.name}`,
39+
ts: Date.parse(workbook.created_time),
40+
});
41+
}
42+
},
43+
async activate() {
44+
const webhookId = await this.zohoSheet.watchNewWorkbook({
45+
location: this.location,
46+
});
47+
this.db.set("webhookId", webhookId.id);
48+
},
49+
async deactivate() {
50+
const webhookId = this.db.get("webhookId");
51+
if (webhookId) {
52+
await axios(this, {
53+
method: "DELETE",
54+
url: `${this.zohoSheet._baseUrl()}/webhook/${webhookId}`,
55+
headers: {
56+
Authorization: `Bearer ${this.zohoSheet.$auth.oauth_access_token}`,
57+
},
58+
});
59+
}
60+
},
61+
},
62+
async run(event) {
63+
const workbook = event.body;
64+
this.$emit(workbook, {
65+
id: workbook.id,
66+
summary: `New workbook created: ${workbook.name}`,
67+
ts: Date.parse(workbook.created_time),
68+
});
69+
},
70+
};

0 commit comments

Comments
 (0)