Skip to content

Commit b476fcf

Browse files
committed
zoho_sheet init
1 parent a7b1c4e commit b476fcf

File tree

7 files changed

+501
-0
lines changed

7 files changed

+501
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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",
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+
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.createRow({
27+
worksheet: this.worksheet,
28+
data: this.data,
29+
});
30+
31+
$.export("$summary", `Successfully created a row in the worksheet: ${this.worksheet}`);
32+
return response;
33+
},
34+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import zohoSheet from "../../zoho_sheet.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "zoho_sheet-search-delete-row",
6+
name: "Search and Delete Row",
7+
description: "Searches for a row based on provided criteria and deletes it. [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+
criteria: {
19+
propDefinition: [
20+
zohoSheet,
21+
"criteria",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.zohoSheet.deleteRow({
27+
worksheet: this.worksheet,
28+
criteria: this.criteria,
29+
});
30+
31+
$.export("$summary", `Row matching criteria deleted successfully from worksheet ${this.worksheet}`);
32+
return response;
33+
},
34+
};
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 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+
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: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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-or-updated-row-instant",
7+
name: "New or Updated Row Instant",
8+
description: "Emit new event whenever a row is added or modified. [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+
http: {
15+
type: "$.interface.http",
16+
customResponse: true,
17+
},
18+
db: "$.service.db",
19+
worksheet: {
20+
propDefinition: [
21+
zohoSheet,
22+
"worksheet",
23+
],
24+
},
25+
},
26+
methods: {
27+
_getWebhookId() {
28+
return this.db.get("webhookId");
29+
},
30+
_setWebhookId(id) {
31+
this.db.set("webhookId", id);
32+
},
33+
async _emitEvent(event) {
34+
this.$emit(event, {
35+
id: `${event.id}-${new Date().getTime()}`,
36+
summary: `Row ${event.type} in worksheet`,
37+
ts: new Date(),
38+
});
39+
},
40+
},
41+
hooks: {
42+
async deploy() {
43+
try {
44+
const events = await this.zohoSheet.emitNewRowEvent({
45+
worksheet: this.worksheet,
46+
});
47+
for (const event of events) {
48+
await this._emitEvent(event);
49+
}
50+
} catch (error) {
51+
console.error("Error during deploy:", error);
52+
}
53+
},
54+
async activate() {
55+
const hookId = await this.zohoSheet.emitRowChangeEvent({
56+
worksheet: this.worksheet,
57+
});
58+
this._setWebhookId(hookId);
59+
},
60+
async deactivate() {
61+
const id = this._getWebhookId();
62+
if (id) {
63+
// Assuming a method to delete webhook has a similar signature
64+
await this.zohoSheet.deleteWebhook({
65+
worksheet: this.worksheet,
66+
webhookId: id,
67+
});
68+
}
69+
},
70+
},
71+
async run(event) {
72+
try {
73+
const signature = event.headers["x-zoho-signature"];
74+
const rawBody = event.rawBody;
75+
const computedSignature = crypto.createHmac("sha256", this.zohoSheet.$auth.oauth_access_token).update(rawBody)
76+
.digest("base64");
77+
78+
if (signature !== computedSignature) {
79+
this.http.respond({
80+
status: 401,
81+
body: "Unauthorized",
82+
});
83+
return;
84+
}
85+
86+
const { data } = event.body;
87+
await this._emitEvent(data);
88+
89+
this.http.respond({
90+
status: 200,
91+
body: "OK",
92+
});
93+
} catch (error) {
94+
console.error("Error processing webhook:", error);
95+
this.http.respond({
96+
status: 500,
97+
body: "Error",
98+
});
99+
}
100+
},
101+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import zohoSheet from "../../zoho_sheet.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "zoho_sheet-new-row-instant",
6+
name: "New Row Created (Instant)",
7+
description: "Emit 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/)",
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+
_getWebhookId() {
27+
return this.db.get("webhookId");
28+
},
29+
_setWebhookId(id) {
30+
this.db.set("webhookId", id);
31+
},
32+
},
33+
hooks: {
34+
async deploy() {
35+
// Emits the 50 most recent row entries from the specified worksheet
36+
const recentRows = await this.zohoSheet.emitNewRowEvent({
37+
worksheet: this.worksheet,
38+
});
39+
for (const row of recentRows.slice(-50).reverse()) {
40+
this.$emit(row, {
41+
id: row.id,
42+
summary: `New row in worksheet: ${row.worksheetId}`,
43+
ts: Date.now(),
44+
});
45+
}
46+
},
47+
async activate() {
48+
const webhookId = await this.zohoSheet.emitNewRowEvent({
49+
worksheet: this.worksheet,
50+
});
51+
this._setWebhookId(webhookId);
52+
},
53+
async deactivate() {
54+
const id = this._getWebhookId();
55+
if (id) {
56+
await this.zohoSheet.deleteRow({
57+
worksheet: this.worksheet,
58+
criteria: {
59+
webhook_id: id,
60+
},
61+
});
62+
}
63+
},
64+
},
65+
async run(event) {
66+
const { body } = event;
67+
this.$emit(body, {
68+
id: body.id,
69+
summary: `New row created in worksheet: ${this.worksheet}`,
70+
ts: Date.now(),
71+
});
72+
},
73+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 whenever a new workbook is created. [See the documentation](https://www.zoho.com/sheet/help/api/)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
zohoSheet,
13+
db: "$.service.db",
14+
http: {
15+
type: "$.interface.http",
16+
customResponse: false,
17+
},
18+
location: {
19+
propDefinition: [
20+
zohoSheet,
21+
"location",
22+
],
23+
optional: true,
24+
},
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+
const events = await this.zohoSheet.emitNewWorkbookEvent({
37+
location: this.location,
38+
});
39+
events.slice(0, 50).forEach((event) => {
40+
this.$emit(event, {
41+
id: event.id,
42+
summary: `New workbook: ${event.name}`,
43+
ts: Date.parse(event.created_time),
44+
});
45+
});
46+
},
47+
async activate() {
48+
const options = {
49+
location: this.location,
50+
};
51+
const webhookId = await this.zohoSheet.emitNewWorkbookEvent(options);
52+
this._setWebhookId(webhookId);
53+
},
54+
async deactivate() {
55+
const id = this._getWebhookId();
56+
if (id) {
57+
await this.zohoSheet.emitNewWorkbookEvent({
58+
id,
59+
method: "DELETE",
60+
});
61+
}
62+
},
63+
},
64+
async run(event) {
65+
const { body } = event;
66+
this.$emit(body, {
67+
id: body.id,
68+
summary: `New workbook: ${body.name}`,
69+
ts: Date.parse(body.created_time),
70+
});
71+
},
72+
};

0 commit comments

Comments
 (0)