-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b37fff
commit 733e7a8
Showing
7 changed files
with
471 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
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; | ||
}, | ||
}; |
32 changes: 32 additions & 0 deletions
32
components/zoho-sheet/actions/search-delete-row/search-delete-row.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
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; | ||
}, | ||
}; |
84 changes: 84 additions & 0 deletions
84
components/zoho-sheet/sources/new-or-updated-row-instant/new-or-updated-row-instant.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
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
88
components/zoho-sheet/sources/new-row-instant/new-row-instant.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
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(), | ||
}); | ||
}, | ||
}; |
70 changes: 70 additions & 0 deletions
70
components/zoho-sheet/sources/new-workbook-instant/new-workbook-instant.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}); | ||
}, | ||
}; |
Oops, something went wrong.