Skip to content

Commit

Permalink
zoho-sheet init
Browse files Browse the repository at this point in the history
  • Loading branch information
luancazarine committed Nov 12, 2024
1 parent 6b37fff commit 733e7a8
Show file tree
Hide file tree
Showing 7 changed files with 471 additions and 0 deletions.
33 changes: 33 additions & 0 deletions components/zoho-sheet/actions/create-row/create-row.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import zohoSheet from "../../zoho-sheet.app.mjs";
import { axios } from "@pipedream/platform";

Check failure on line 2 in components/zoho-sheet/actions/create-row/create-row.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used

export default {
key: "zoho-sheet-create-row",
name: "Create Row in Zoho Sheet",
description: "Creates a new row in a specified worksheet. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
version: "0.0.{{ts}}",
type: "action",
props: {
zohoSheet,
worksheet: {
propDefinition: [
zohoSheet,
"worksheet",
],
},
data: {
propDefinition: [
zohoSheet,
"data",
],
},
},
async run({ $ }) {
const response = await this.zohoSheet.addNewRow({
worksheet: this.worksheet,
data: this.data,
});
$.export("$summary", `Successfully added a new row to the worksheet ${this.worksheet}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import zohoSheet from "../../zoho-sheet.app.mjs";

export default {
key: "zoho-sheet-search-delete-row",
name: "Search and Delete Row",
description: "Searches for a row based on the provided criteria and deletes it. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
version: "0.0.{{ts}}",
type: "action",
props: {
zohoSheet,
worksheet: {
propDefinition: [
zohoSheet,
"worksheet",
],
},
criteria: {
propDefinition: [
zohoSheet,
"criteria",
],
},
},
async run({ $ }) {
const response = await this.zohoSheet.deleteRow({
worksheet: this.worksheet,
criteria: this.criteria,
});
$.export("$summary", "Successfully searched and deleted row(s) based on the provided criteria.");
return response;
},
};
41 changes: 41 additions & 0 deletions components/zoho-sheet/actions/update-row/update-row.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import zohoSheet from "../../zoho-sheet.app.mjs";
import { axios } from "@pipedream/platform";

Check failure on line 2 in components/zoho-sheet/actions/update-row/update-row.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used

export default {
key: "zoho-sheet-update-row",
name: "Update Row",
description: "Finds a specific row via its index and updates its content. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
version: "0.0.{{ts}}",
type: "action",
props: {
zohoSheet,
worksheet: {
propDefinition: [
zohoSheet,
"worksheet",
],
},
rowIndex: {
propDefinition: [
zohoSheet,
"rowIndex",
],
},
data: {
propDefinition: [
zohoSheet,
"data",
],
},
},
async run({ $ }) {
const response = await this.zohoSheet.updateRow({
worksheet: this.worksheet,
rowIndex: this.rowIndex,
data: this.data,
});

$.export("$summary", `Successfully updated row ${this.rowIndex} in worksheet ${this.worksheet}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import zohoSheet from "../../zoho-sheet.app.mjs";
import { axios } from "@pipedream/platform";

Check failure on line 2 in components/zoho-sheet/sources/new-or-updated-row-instant/new-or-updated-row-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used

export default {
key: "zoho-sheet-new-or-updated-row-instant",
name: "New or Updated Row Instant",
description: "Emit new event whenever a row is added or modified. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
version: "0.0.{{ts}}",
type: "source",
dedupe: "unique",
props: {
zohoSheet,
http: {
type: "$.interface.http",
customResponse: false,
},
db: "$.service.db",
worksheet: {
propDefinition: [
zohoSheet,
"worksheet",
],
},
},
methods: {
_getWebhookIds() {
return this.db.get("webhookIds");
},
_setWebhookIds(ids) {
this.db.set("webhookIds", ids);
},
},
hooks: {
async deploy() {
// Handle deployment logic here if required, e.g., fetching past events
},
async activate() {
const newRowWebhook = await this.zohoSheet.watchNewRow({
worksheet: this.worksheet,
});
const rowChangeWebhook = await this.zohoSheet.watchRowChange({
worksheet: this.worksheet,
});

this._setWebhookIds({
new_row: newRowWebhook,
row_change: rowChangeWebhook,
});
},
async deactivate() {
const {
new_row, row_change,
} = this._getWebhookIds();
if (new_row) {
await this.zohoSheet._makeRequest({
method: "POST",
path: "/webhook",
data: {
method: "webhook.unsubscribe",
webhook_id: new_row,
},
});
}
if (row_change) {
await this.zohoSheet._makeRequest({
method: "POST",
path: "/webhook",
data: {
method: "webhook.unsubscribe",
webhook_id: row_change,
},
});
}
},
},
async run(event) {
const { body } = event;
this.$emit(body, {
id: body.id || Date.now(),
summary: `New or updated row in worksheet: ${this.worksheet}`,
ts: Date.now(),
});
},
};
88 changes: 88 additions & 0 deletions components/zoho-sheet/sources/new-row-instant/new-row-instant.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import zohoSheet from "../../zoho-sheet.app.mjs";
import crypto from "crypto";
import { axios } from "@pipedream/platform";

Check failure on line 3 in components/zoho-sheet/sources/new-row-instant/new-row-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used

export default {
key: "zoho-sheet-new-row-instant",
name: "New Row Instant",
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/)",
version: "0.0.{{ts}}",
type: "source",
dedupe: "unique",
props: {
zohoSheet,
worksheet: {
propDefinition: [
zohoSheet,
"worksheet",
],
},
http: {
type: "$.interface.http",
customResponse: true,
},
db: "$.service.db",
},
methods: {
_getWebhookId() {
return this.db.get("webhookId");
},
_setWebhookId(id) {
this.db.set("webhookId", id);
},
},
hooks: {
async deploy() {
// Implement fetching and emitting historical events if applicable with Zoho Sheet API
},
async activate() {
const response = await this.zohoSheet.watchNewRow({
worksheet: this.worksheet,
});
this._setWebhookId(response.webhookId);
},
async deactivate() {
const webhookId = this._getWebhookId();
if (webhookId) {
await this.zohoSheet.deleteWebhook({
id: webhookId,
});
}
},
},
async run(event) {
if (!this.http.body) {
this.http.respond({
status: 400,
body: "Bad Request",
});
return;
}

const webhookSignature = event.headers["x-zoho-signature"];
const secretKey = this.zohoSheet.$auth.oauth_access_token;
const rawBody = event.rawBody;

const computedSignature = crypto.createHmac("sha256", secretKey).update(rawBody)
.digest("base64");
if (computedSignature !== webhookSignature) {
this.http.respond({
status: 401,
body: "Unauthorized",
});
return;
}

this.http.respond({
status: 200,
body: "OK",
});

const row = event.body;
this.$emit(row, {
id: row.id,
summary: `New row added to worksheet ${this.worksheet}`,
ts: Date.now(),
});
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import zohoSheet from "../../zoho-sheet.app.mjs";
import { axios } from "@pipedream/platform";

export default {
key: "zoho-sheet-new-workbook-instant",
name: "New Workbook Created",
description: "Emit new event when a new workbook is created. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
version: "0.0.{{ts}}",
type: "source",
dedupe: "unique",
props: {
zohoSheet: {
type: "app",
app: "zoho_sheet",
},
http: {
type: "$.interface.http",
customResponse: false,
},
db: "$.service.db",
location: {
propDefinition: [
zohoSheet,
"location",
],
},
},
hooks: {
async deploy() {
const workbooks = await this.zohoSheet._makeRequest({
method: "GET",
path: "/workbooks",
});
const recentWorkbooks = workbooks.slice(-50).reverse();
for (const workbook of recentWorkbooks) {
this.$emit(workbook, {
id: workbook.id,
summary: `New workbook created: ${workbook.name}`,
ts: Date.parse(workbook.created_time),
});
}
},
async activate() {
const webhookId = await this.zohoSheet.watchNewWorkbook({
location: this.location,
});
this.db.set("webhookId", webhookId.id);
},
async deactivate() {
const webhookId = this.db.get("webhookId");
if (webhookId) {
await axios(this, {
method: "DELETE",
url: `${this.zohoSheet._baseUrl()}/webhook/${webhookId}`,
headers: {
Authorization: `Bearer ${this.zohoSheet.$auth.oauth_access_token}`,
},
});
}
},
},
async run(event) {
const workbook = event.body;
this.$emit(workbook, {
id: workbook.id,
summary: `New workbook created: ${workbook.name}`,
ts: Date.parse(workbook.created_time),
});
},
};
Loading

0 comments on commit 733e7a8

Please sign in to comment.