Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/google_sheets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/google_sheets",
"version": "0.9.0",
"version": "0.9.1",
"description": "Pipedream Google_sheets Components",
"main": "google_sheets.app.mjs",
"keywords": [
Expand All @@ -11,7 +11,7 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"dependencies": {
"@googleapis/sheets": "^0.3.0",
"@pipedream/google_drive": "^1.1.0",
"@pipedream/google_drive": "^1.1.1",
"@pipedream/platform": "^3.1.0",
"lodash": "^4.17.21",
"uuidv4": "^6.2.6",
Expand Down
5 changes: 4 additions & 1 deletion components/google_sheets/sources/common/http-based/base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export default {
props: {
googleSheets,
db: "$.service.db",
http: "$.interface.http",
http: {
type: "$.interface.http",
customResponse: true,
},
timer: {
label: "Push notification renewal schedule",
description:
Expand Down
4 changes: 4 additions & 0 deletions components/google_sheets/sources/common/http-based/drive.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ export default {
return;
}

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

const spreadsheet = await this.getSpreadsheetToProcess(event);

if (!spreadsheet) {
Expand Down
73 changes: 73 additions & 0 deletions components/google_sheets/sources/common/http-based/sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,39 @@
import { v4 as uuid } from "uuid";

import base from "./base.mjs";
import drive from "./drive.mjs";

/**
* This source watches for changes to a specific spreadsheet in the user's Google Drive.
*/
export default {
...base,
props: {
...base.props,
watchDrive: {
type: "boolean",
label: "Watch Drive",
description: "Set to `true` to watch the drive for changes. May reduce rate limiting.",
optional: true,
},
},
methods: {
...drive.methods,
...base.methods,
_getChangeToken() {
return this.db.get("changeToken");
},
_setChangeToken(changeToken) {
this.db.set("changeToken", changeToken);
},
async activateHook(channelID) {
if (this.watchDrive) {
return this.googleSheets.activateHook(
channelID,
this.http.endpoint,
this.googleSheets.getDriveId(this.watchedDrive),
);
}
return this.googleSheets.activateFileHook(
channelID,
this.http.endpoint,
Expand All @@ -27,6 +51,19 @@ export default {
.filter(({ sheetType }) => sheetType === "GRID")
.map(({ sheetId }) => (sheetId.toString()));
},
async isSheetRelevant() {
const pageToken = this._getChangeToken() || this._getPageToken();
const drive = this.googleSheets.drive();
const { data } = await drive.changes.list({
pageToken,
driveId: this.googleSheets.getDriveId(this.watchedDrive),
});
const {
changes, newStartPageToken,
} = data;
this._setChangeToken(newStartPageToken);
return changes.some((change) => change.file.id === this.getSheetId());
},
async renewSubscription() {
// Assume subscription & channelID may all be undefined at
// this point Handle their absence appropriately.
Expand All @@ -51,10 +88,37 @@ export default {
});
this._setChannelID(newChannelID);
},
async renewDriveSubscription() {
const subscription = this._getSubscription();
const channelID = this._getChannelID() || uuid();

const {
expiration,
resourceId,
newChannelID,
newPageToken,
} = await this.googleSheets.renewSubscription(
this.watchedDrive,
subscription,
this.http.endpoint,
channelID,
this._getPageToken(),
);

this._setSubscription({
expiration,
resourceId,
});
this._setChannelID(newChannelID);
this._setPageToken(newPageToken);
},
},
async run(event) {
if (event.timestamp) {
// Component was invoked by timer
if (this.watchDrive) {
return this.renewDriveSubscription();
}
return this.renewSubscription();
}

Expand All @@ -63,6 +127,15 @@ export default {
return;
}

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

if (this.watchDrive && !(await this.isSheetRelevant(event))) {
console.log("Change to unwatched file, exiting early");
return;
}

const spreadsheet = await this.googleSheets.getSpreadsheet(this.sheetID);

return this.processSpreadsheet(spreadsheet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "google_sheets-new-comment",
name: "New Comment (Instant)",
description: "Emit new event each time a comment is added to a spreadsheet.",
version: "0.1.1",
version: "0.1.2",
dedupe: "unique",
type: "source",
methods: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "google_sheets-new-row-added-polling",
name: "New Row Added",
description: "Emit new event each time a row or rows are added to the bottom of a spreadsheet.",
version: "0.1.1",
version: "0.1.2",
dedupe: "unique",
type: "source",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "google_sheets-new-row-added",
name: "New Row Added (Instant)",
description: "Emit new event each time a row or rows are added to the bottom of a spreadsheet.",
version: "0.2.1",
version: "0.2.2",
dedupe: "unique",
type: "source",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
type: "source",
name: "New Updates (Instant)",
description: "Emit new event each time a row or cell is updated in a spreadsheet.",
version: "0.3.1",
version: "0.3.2",
dedupe: "unique",
props: {
...httpBase.props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
type: "source",
name: "New Worksheet (Instant)",
description: "Emit new event each time a new worksheet is created in a spreadsheet.",
version: "0.2.1",
version: "0.2.2",
dedupe: "unique",
hooks: {
...httpBase.hooks,
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading