@guayaba/workflow-piece-google-sheets 0.14.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/.babelrc +3 -0
  2. package/.eslintrc.json +18 -0
  3. package/README.md +5 -0
  4. package/assets/logo.png +0 -0
  5. package/package.json +28 -0
  6. package/src/i18n/ar.json +124 -0
  7. package/src/i18n/bg.json +124 -0
  8. package/src/i18n/ca.json +132 -0
  9. package/src/i18n/de.json +165 -0
  10. package/src/i18n/es.json +165 -0
  11. package/src/i18n/fr.json +165 -0
  12. package/src/i18n/hi.json +132 -0
  13. package/src/i18n/hu.json +124 -0
  14. package/src/i18n/hy.json +124 -0
  15. package/src/i18n/id.json +132 -0
  16. package/src/i18n/it.json +124 -0
  17. package/src/i18n/ja.json +165 -0
  18. package/src/i18n/ko.json +124 -0
  19. package/src/i18n/nl.json +165 -0
  20. package/src/i18n/pl.json +124 -0
  21. package/src/i18n/pt.json +165 -0
  22. package/src/i18n/ru.json +132 -0
  23. package/src/i18n/sv.json +124 -0
  24. package/src/i18n/translation.json +165 -0
  25. package/src/i18n/uk.json +124 -0
  26. package/src/i18n/vi.json +132 -0
  27. package/src/i18n/zh.json +165 -0
  28. package/src/index.ts +93 -0
  29. package/src/lib/actions/clear-sheet.ts +60 -0
  30. package/src/lib/actions/copy-worksheet.ts +32 -0
  31. package/src/lib/actions/create-column.ts +109 -0
  32. package/src/lib/actions/create-spreadsheet.ts +122 -0
  33. package/src/lib/actions/create-worksheet.ts +62 -0
  34. package/src/lib/actions/delete-row.action.ts +40 -0
  35. package/src/lib/actions/delete-worksheet.ts +36 -0
  36. package/src/lib/actions/export-sheet.ts +86 -0
  37. package/src/lib/actions/find-row-by-num.ts +42 -0
  38. package/src/lib/actions/find-rows.ts +135 -0
  39. package/src/lib/actions/find-spreadsheets.ts +83 -0
  40. package/src/lib/actions/find-worksheet.ts +52 -0
  41. package/src/lib/actions/format-spreadsheet-row.ts +112 -0
  42. package/src/lib/actions/get-many-rows.ts +42 -0
  43. package/src/lib/actions/get-rows.ts +207 -0
  44. package/src/lib/actions/insert-multiple-rows.action.ts +542 -0
  45. package/src/lib/actions/insert-row.action.ts +111 -0
  46. package/src/lib/actions/rename-worksheet.ts +44 -0
  47. package/src/lib/actions/update-multiple-rows.ts +177 -0
  48. package/src/lib/actions/update-row.ts +93 -0
  49. package/src/lib/common/common.ts +383 -0
  50. package/src/lib/common/props.ts +274 -0
  51. package/src/lib/triggers/helpers.ts +155 -0
  52. package/src/lib/triggers/new-or-updated-row.trigger.ts +299 -0
  53. package/src/lib/triggers/new-row-added-webhook.ts +182 -0
  54. package/src/lib/triggers/new-spreadsheet.ts +88 -0
  55. package/src/lib/triggers/new-worksheet.ts +96 -0
  56. package/tsconfig.json +16 -0
  57. package/tsconfig.lib.json +15 -0
package/src/index.ts ADDED
@@ -0,0 +1,93 @@
1
+ import { createCustomApiCallAction } from '@guayaba/workflows-common';
2
+ import { createPiece } from '@guayaba/workflows-framework';
3
+ import { PieceCategory } from '@guayaba/workflows-shared';
4
+ import { clearSheetAction } from './lib/actions/clear-sheet';
5
+ import { deleteRowAction } from './lib/actions/delete-row.action';
6
+ import { findRowByNumAction } from './lib/actions/find-row-by-num';
7
+ import { findRowsAction } from './lib/actions/find-rows';
8
+ import { getRowsAction } from './lib/actions/get-rows';
9
+ import { insertRowAction } from './lib/actions/insert-row.action';
10
+ import { updateRowAction } from './lib/actions/update-row';
11
+ import {
12
+ getAccessToken,
13
+ googleSheetsAuth,
14
+ GoogleSheetsAuthValue,
15
+ googleSheetsCommon,
16
+ } from './lib/common/common';
17
+ import { newRowAddedTrigger } from './lib/triggers/new-row-added-webhook';
18
+ import { newOrUpdatedRowTrigger } from './lib/triggers/new-or-updated-row.trigger';
19
+ import { insertMultipleRowsAction } from './lib/actions/insert-multiple-rows.action';
20
+ import { createWorksheetAction } from './lib/actions/create-worksheet';
21
+ import { createSpreadsheetAction } from './lib/actions/create-spreadsheet';
22
+ import { findSpreadsheets } from './lib/actions/find-spreadsheets';
23
+ import { newSpreadsheetTrigger } from './lib/triggers/new-spreadsheet';
24
+ import { newWorksheetTrigger } from './lib/triggers/new-worksheet';
25
+ import { findWorksheetAction } from './lib/actions/find-worksheet';
26
+ import { copyWorksheetAction } from './lib/actions/copy-worksheet';
27
+ import { updateMultipleRowsAction } from './lib/actions/update-multiple-rows';
28
+ import { createColumnAction } from './lib/actions/create-column';
29
+ import { exportSheetAction } from './lib/actions/export-sheet';
30
+ import { getManyRowsAction } from './lib/actions/get-many-rows';
31
+ import { renameWorksheetAction } from './lib/actions/rename-worksheet';
32
+ import { deleteWorksheetAction } from './lib/actions/delete-worksheet';
33
+ import { formatRowAction } from './lib/actions/format-spreadsheet-row';
34
+
35
+ export const googleSheets = createPiece({
36
+ minimumSupportedRelease: '0.71.4',
37
+ logoUrl: 'https://cdn.activepieces.com/pieces/google-sheets.png',
38
+ categories: [PieceCategory.PRODUCTIVITY],
39
+ authors: [
40
+ 'ShayPunter',
41
+ 'Ozak93',
42
+ 'Abdallah-Alwarawreh',
43
+ 'Salem-Alaa',
44
+ 'kishanprmr',
45
+ 'MoShizzle',
46
+ 'AbdulTheActivePiecer',
47
+ 'khaledmashaly',
48
+ 'abuaboud',
49
+ 'geekyme',
50
+ ],
51
+ actions: [
52
+ insertRowAction,
53
+ insertMultipleRowsAction,
54
+ updateRowAction,
55
+ updateMultipleRowsAction,
56
+ deleteRowAction,
57
+ findRowsAction,
58
+ createSpreadsheetAction,
59
+ createWorksheetAction,
60
+ clearSheetAction,
61
+ deleteWorksheetAction,
62
+ renameWorksheetAction,
63
+ formatRowAction,
64
+ findRowByNumAction,
65
+ getRowsAction,
66
+ getManyRowsAction,
67
+ findSpreadsheets,
68
+ findWorksheetAction,
69
+ copyWorksheetAction,
70
+ createColumnAction,
71
+ exportSheetAction,
72
+ createCustomApiCallAction({
73
+ auth: googleSheetsAuth,
74
+ baseUrl: () => {
75
+ return googleSheetsCommon.baseUrl;
76
+ },
77
+ authMapping: async (auth) => {
78
+ return {
79
+ Authorization: `Bearer ${await getAccessToken(auth as GoogleSheetsAuthValue)}`,
80
+ };
81
+ },
82
+ }),
83
+ ],
84
+ displayName: 'Google Sheets',
85
+ description: 'Create, edit, and collaborate on spreadsheets online',
86
+ triggers: [
87
+ newOrUpdatedRowTrigger,
88
+ newRowAddedTrigger,
89
+ newSpreadsheetTrigger,
90
+ newWorksheetTrigger,
91
+ ],
92
+ auth: googleSheetsAuth,
93
+ });
@@ -0,0 +1,60 @@
1
+ import { createAction, Property } from '@guayaba/workflows-framework';
2
+ import { areSheetIdsValid, googleSheetsCommon } from '../common/common';
3
+ import { googleSheetsAuth } from '../common/common';
4
+ import { commonProps, isFirstRowHeaderProp } from '../common/props';
5
+
6
+ export const clearSheetAction = createAction({
7
+ auth: googleSheetsAuth,
8
+ name: 'clear_sheet',
9
+ description: 'Clears all rows on an existing sheet.',
10
+ displayName: 'Clear Sheet',
11
+ props: {
12
+ ...commonProps,
13
+ is_first_row_headers: isFirstRowHeaderProp(),
14
+ headerRow: Property.Number({
15
+ displayName: 'Header Row Number',
16
+ description: 'Enter the row number where your column headers are located (usually row 1).',
17
+ required: true,
18
+ defaultValue: 1,
19
+ }),
20
+ },
21
+ async run({ propsValue, auth }) {
22
+ const {
23
+ spreadsheetId,
24
+ sheetId,
25
+ is_first_row_headers: isFirstRowHeaders,
26
+ headerRow,
27
+ } = propsValue;
28
+
29
+ if (!areSheetIdsValid(spreadsheetId, sheetId)) {
30
+ throw new Error('Please select a spreadsheet and sheet first.');
31
+ }
32
+ await googleSheetsCommon.findSheetName(auth, spreadsheetId as string, sheetId as number);
33
+
34
+ const rowsToDelete: number[] = [];
35
+ const values = await googleSheetsCommon.getGoogleSheetRows({
36
+ spreadsheetId: spreadsheetId as string,
37
+ auth: auth,
38
+ sheetId: sheetId as number,
39
+ rowIndex_s: 1,
40
+ rowIndex_e: undefined,
41
+ headerRow: headerRow,
42
+ });
43
+ for (const key in values) {
44
+ if (key === '0' && isFirstRowHeaders) {
45
+ continue;
46
+ }
47
+ rowsToDelete.push(parseInt(key) + 1);
48
+ }
49
+
50
+ const response = await googleSheetsCommon.clearSheet(
51
+ spreadsheetId as string,
52
+ sheetId as number,
53
+ auth,
54
+ isFirstRowHeaders ? 1 : 0,
55
+ rowsToDelete.length,
56
+ );
57
+
58
+ return response.body;
59
+ },
60
+ });
@@ -0,0 +1,32 @@
1
+ import { googleSheetsAuth } from '../common/common';
2
+ import { createAction } from '@guayaba/workflows-framework';
3
+ import { includeTeamDrivesProp, sheetIdProp, spreadsheetIdProp } from '../common/props';
4
+ import { google } from 'googleapis';
5
+ import { createGoogleClient } from '../common/common';
6
+
7
+ export const copyWorksheetAction = createAction({
8
+ auth: googleSheetsAuth,
9
+ name: 'copy-worksheet',
10
+ displayName: 'Copy Worksheet',
11
+ description: 'Creates a new worksheet by copying an existing one.',
12
+ props: {
13
+ includeTeamDrives: includeTeamDrivesProp(),
14
+ spreadsheetId: spreadsheetIdProp('Spreadsheet Containing the Worksheet to Copy', ''),
15
+ sheetId: sheetIdProp('Worksheet to Copy', ''),
16
+ desinationSpeadsheetId: spreadsheetIdProp('Spreadsheet to paste in', ''),
17
+ },
18
+ async run(context) {
19
+ const authClient = await createGoogleClient(context.auth);
20
+ const sheets = google.sheets({ version: 'v4', auth: authClient });
21
+
22
+ const response = await sheets.spreadsheets.sheets.copyTo({
23
+ spreadsheetId: context.propsValue.spreadsheetId,
24
+ sheetId: context.propsValue.sheetId,
25
+ requestBody: {
26
+ destinationSpreadsheetId: context.propsValue.desinationSpeadsheetId,
27
+ },
28
+ });
29
+
30
+ return response.data;
31
+ },
32
+ });
@@ -0,0 +1,109 @@
1
+ import { googleSheetsAuth } from '../common/common';
2
+ import { createAction, Property } from '@guayaba/workflows-framework';
3
+ import {
4
+ areSheetIdsValid,
5
+ columnToLabel,
6
+ createGoogleClient,
7
+ getHeaderRow,
8
+ ValueInputOption,
9
+ } from '../common/common';
10
+ import { google } from 'googleapis';
11
+ import { getWorkSheetName } from '../triggers/helpers';
12
+ import { commonProps } from '../common/props';
13
+
14
+ export const createColumnAction = createAction({
15
+ auth: googleSheetsAuth,
16
+ name: 'create-column',
17
+ displayName: 'Create Spreadsheet Column',
18
+ description: 'Creates a new column in a specific spreadsheet.',
19
+ props: {
20
+ ...commonProps,
21
+ columnName: Property.ShortText({
22
+ displayName: 'Column Name',
23
+ required: true,
24
+ }),
25
+ columnIndex: Property.Number({
26
+ displayName: 'Column Index',
27
+ description:
28
+ 'The column index starts from 1.For example, if you want to add a column to the third column, enter 3.Ff the input is less than 1 the column will be added after the last current column.',
29
+ required: false,
30
+ }),
31
+ },
32
+ async run(context) {
33
+ const { spreadsheetId, sheetId, columnName, columnIndex } = context.propsValue;
34
+
35
+ if (!areSheetIdsValid(spreadsheetId, sheetId)) {
36
+ throw new Error('Please select a spreadsheet and sheet first.');
37
+ }
38
+
39
+ const authClient = await createGoogleClient(context.auth);
40
+ const sheets = google.sheets({ version: 'v4', auth: authClient });
41
+
42
+ let columnLabel;
43
+
44
+ if (columnIndex && columnIndex > 0) {
45
+ await sheets.spreadsheets.batchUpdate({
46
+ spreadsheetId,
47
+ requestBody: {
48
+ requests: [
49
+ {
50
+ insertDimension: {
51
+ range: {
52
+ sheetId,
53
+ dimension: 'COLUMNS',
54
+ startIndex: columnIndex - 1,
55
+ endIndex: columnIndex,
56
+ },
57
+ },
58
+ },
59
+ ],
60
+ },
61
+ });
62
+ columnLabel = columnToLabel(columnIndex - 1);
63
+ } else {
64
+ const headers = await getHeaderRow({
65
+ spreadsheetId: spreadsheetId as string,
66
+ sheetId: sheetId as number,
67
+ auth: context.auth,
68
+ });
69
+
70
+ const newColumnIndex = headers === undefined ? 0 : headers.length;
71
+
72
+ await sheets.spreadsheets.batchUpdate({
73
+ spreadsheetId,
74
+ requestBody: {
75
+ requests: [
76
+ {
77
+ insertDimension: {
78
+ range: {
79
+ sheetId,
80
+ dimension: 'COLUMNS',
81
+ startIndex: newColumnIndex,
82
+ endIndex: newColumnIndex + 1,
83
+ },
84
+ },
85
+ },
86
+ ],
87
+ },
88
+ });
89
+ columnLabel = columnToLabel(newColumnIndex);
90
+ }
91
+
92
+ const sheetName = await getWorkSheetName(
93
+ context.auth,
94
+ spreadsheetId as string,
95
+ sheetId as number,
96
+ );
97
+
98
+ const response = await sheets.spreadsheets.values.update({
99
+ range: `${sheetName}!${columnLabel}1`,
100
+ spreadsheetId,
101
+ valueInputOption: ValueInputOption.USER_ENTERED,
102
+ requestBody: {
103
+ values: [[columnName]],
104
+ },
105
+ });
106
+
107
+ return response.data;
108
+ },
109
+ });
@@ -0,0 +1,122 @@
1
+ import {
2
+ AppConnectionValueForAuthProperty,
3
+ createAction,
4
+ PiecePropValueSchema,
5
+ Property,
6
+ } from '@guayaba/workflows-framework';
7
+ import {
8
+ AuthenticationType,
9
+ httpClient,
10
+ HttpMethod,
11
+ HttpRequest,
12
+ } from '@guayaba/workflows-common';
13
+ import { google } from 'googleapis';
14
+ import { includeTeamDrivesProp } from '../common/props';
15
+ import { createGoogleClient, getAccessToken, googleSheetsAuth } from '../common/common';
16
+ import { AppConnectionType, isNil } from '@guayaba/workflows-shared';
17
+
18
+ export const createSpreadsheetAction = createAction({
19
+ auth: googleSheetsAuth,
20
+ name: 'create-spreadsheet',
21
+ displayName: 'Create Spreadsheet',
22
+ description: 'Creates a blank spreadsheet.',
23
+ props: {
24
+ title: Property.ShortText({
25
+ displayName: 'Title',
26
+ description: 'The title of the new spreadsheet.',
27
+ required: true,
28
+ }),
29
+ includeTeamDrives: includeTeamDrivesProp(),
30
+ folder: Property.Dropdown({
31
+ auth: googleSheetsAuth,
32
+ displayName: 'Parent Folder',
33
+ description:
34
+ 'The folder to create the worksheet in.By default, the new worksheet is created in the root folder of drive.',
35
+ required: false,
36
+ refreshers: ['auth', 'includeTeamDrives'],
37
+ options: async ({ auth, includeTeamDrives }) => {
38
+ if (!auth) {
39
+ return {
40
+ disabled: true,
41
+ options: [],
42
+ placeholder: 'Please authenticate first',
43
+ };
44
+ }
45
+ const authProp = auth;
46
+ let folders: { id: string; name: string }[] = [];
47
+ const isServiceAccountWithoutImpersonation = authProp.type === AppConnectionType.CUSTOM_AUTH && authProp.props.userEmail?.length === 0;
48
+ let pageToken = null;
49
+ do {
50
+ const request: HttpRequest = {
51
+ method: HttpMethod.GET,
52
+ url: `https://www.googleapis.com/drive/v3/files`,
53
+ queryParams: {
54
+ q: "mimeType='application/vnd.google-apps.folder' and trashed = false",
55
+ includeItemsFromAllDrives: includeTeamDrives || isServiceAccountWithoutImpersonation ? 'true' : 'false',
56
+ supportsAllDrives: 'true',
57
+ },
58
+ authentication: {
59
+ type: AuthenticationType.BEARER_TOKEN,
60
+ token: await getAccessToken(authProp),
61
+ },
62
+ };
63
+ if (pageToken) {
64
+ if (request.queryParams !== undefined) {
65
+ request.queryParams['pageToken'] = pageToken;
66
+ }
67
+ }
68
+ try {
69
+ const response = await httpClient.sendRequest<{
70
+ files: { id: string; name: string,teamDriveId?: string }[];
71
+ nextPageToken: string;
72
+ }>(request);
73
+ folders = folders.concat(response.body.files.filter(file => !isNil(file.teamDriveId) || !isServiceAccountWithoutImpersonation));
74
+ pageToken = response.body.nextPageToken;
75
+ } catch (e) {
76
+ throw new Error(`Failed to get folders\nError:${e}`);
77
+ }
78
+ } while (pageToken);
79
+
80
+ return {
81
+ disabled: false,
82
+ options: folders.map((folder: { id: string; name: string }) => {
83
+ return {
84
+ label: folder.name,
85
+ value: folder.id,
86
+ };
87
+ }),
88
+ };
89
+ },
90
+ }),
91
+ },
92
+ async run(context) {
93
+ const { title, folder } = context.propsValue;
94
+ const response = await createSpreadsheet(context.auth, title, folder);
95
+ const newSpreadsheetId = response.id;
96
+
97
+
98
+
99
+ return {
100
+ id: newSpreadsheetId,
101
+ };
102
+ },
103
+ });
104
+
105
+ async function createSpreadsheet(
106
+ auth: AppConnectionValueForAuthProperty<typeof googleSheetsAuth>,
107
+ title: string,
108
+ folderId?: string,
109
+ ) {
110
+ const googleClient = await createGoogleClient(auth);
111
+ const driveApi = google.drive({ version: 'v3', auth: googleClient });
112
+ const response = await driveApi.files.create({
113
+ requestBody: {
114
+ name: title,
115
+ mimeType: 'application/vnd.google-apps.spreadsheet',
116
+ parents: folderId ? [folderId] : undefined,
117
+ },
118
+ supportsAllDrives: true,
119
+ });
120
+ return response.data;
121
+ }
122
+
@@ -0,0 +1,62 @@
1
+ import { createAction, Property } from '@guayaba/workflows-framework';
2
+ import { createGoogleClient } from '../common/common';
3
+ import { googleSheetsAuth } from '../common/common';
4
+ import { includeTeamDrivesProp, spreadsheetIdProp } from '../common/props';
5
+ import { google } from 'googleapis';
6
+
7
+ export const createWorksheetAction = createAction({
8
+ auth: googleSheetsAuth,
9
+ name: 'create-worksheet',
10
+ displayName: 'Create Worksheet',
11
+ description:'Create a new blank worksheet with a title.',
12
+ props: {
13
+ includeTeamDrives: includeTeamDrivesProp(),
14
+ spreadsheetId: spreadsheetIdProp('Spreadsheet',''),
15
+ title:Property.ShortText({
16
+ displayName:'Title',
17
+ description:'The title of the new worksheet.',
18
+ required:true
19
+ }),
20
+ headers:Property.Array({
21
+ displayName:'Headers',
22
+ required:false
23
+ })
24
+
25
+ },
26
+ async run(context){
27
+ const {spreadsheetId,title} = context.propsValue;
28
+ const headers = context.propsValue.headers as string[] ?? [];
29
+ const client = await createGoogleClient(context.auth);
30
+ const sheetsApi = google.sheets({ version: 'v4', auth: client });
31
+ const sheet = await sheetsApi.spreadsheets.batchUpdate({
32
+ spreadsheetId:spreadsheetId,
33
+ requestBody:{
34
+ requests:[
35
+ {
36
+ addSheet:{
37
+ properties:{
38
+ title:title
39
+ },
40
+ },
41
+
42
+ }
43
+ ]
44
+ }
45
+ });
46
+ const addHeadersResponse = await sheetsApi.spreadsheets.values.append({
47
+ spreadsheetId,
48
+ range:`${context.propsValue.title}!A1`,
49
+ valueInputOption:'RAW',
50
+ requestBody:{
51
+ majorDimension:'ROWS',
52
+ values:[headers]
53
+ }
54
+ });
55
+
56
+ return {
57
+ id: sheet.data?.replies?.[0]?.addSheet?.properties?.sheetId,
58
+ ...addHeadersResponse.data
59
+ }
60
+
61
+
62
+ }})
@@ -0,0 +1,40 @@
1
+ import { createAction, Property } from '@guayaba/workflows-framework';
2
+ import { areSheetIdsValid, googleSheetsCommon } from '../common/common';
3
+ import { googleSheetsAuth } from '../common/common';
4
+ import { commonProps } from '../common/props';
5
+
6
+ export const deleteRowAction = createAction({
7
+ auth: googleSheetsAuth,
8
+ name: 'delete_row',
9
+ description: 'Delete a specific row from the selected sheet.',
10
+ displayName: 'Delete Row',
11
+ props: {
12
+ ...commonProps,
13
+ rowId: Property.Number({
14
+ displayName: 'Row Number',
15
+ description: 'The number of the row you want to delete.',
16
+ required: true,
17
+ }),
18
+ },
19
+ async run(context) {
20
+ const { spreadsheetId, sheetId, rowId } = context.propsValue;
21
+
22
+ if (!areSheetIdsValid(spreadsheetId,sheetId)) {
23
+ throw new Error('Please select a spreadsheet and sheet first.');
24
+ }
25
+
26
+ // Subtract 1 from the row_id to convert it to 0-indexed
27
+ const adjustedRowIndex = rowId - 1;
28
+ const response = await googleSheetsCommon.deleteRow(
29
+ spreadsheetId as string,
30
+ sheetId as number,
31
+ adjustedRowIndex,
32
+ context.auth,
33
+ );
34
+
35
+ return {
36
+ success: true,
37
+ body: response,
38
+ };
39
+ },
40
+ });
@@ -0,0 +1,36 @@
1
+ import { googleSheetsAuth } from '../common/common';
2
+ import { createAction } from '@guayaba/workflows-framework';
3
+ import { includeTeamDrivesProp, sheetIdProp, spreadsheetIdProp } from '../common/props';
4
+ import { google } from 'googleapis';
5
+ import { createGoogleClient } from '../common/common';
6
+
7
+ export const deleteWorksheetAction = createAction({
8
+ auth: googleSheetsAuth,
9
+ name: 'delete-worksheet',
10
+ displayName: 'Delete Worksheet',
11
+ description: 'Permanently delete a specific worksheet.',
12
+ props: {
13
+ includeTeamDrives: includeTeamDrivesProp(),
14
+ spreadsheetId: spreadsheetIdProp('Spreadsheet', 'The ID of the spreadsheet to use.'),
15
+ sheetId: sheetIdProp('Worksheet', 'The ID of the worksheet to delete.'),
16
+ },
17
+ async run(context) {
18
+ const authClient = await createGoogleClient(context.auth);
19
+ const sheets = google.sheets({ version: 'v4', auth: authClient });
20
+
21
+ const response = await sheets.spreadsheets.batchUpdate({
22
+ spreadsheetId: context.propsValue.spreadsheetId,
23
+ requestBody: {
24
+ requests:[
25
+ {
26
+ deleteSheet:{
27
+ sheetId:context.propsValue.sheetId
28
+ }
29
+ }
30
+ ]
31
+ },
32
+ });
33
+
34
+ return response.data;
35
+ },
36
+ });
@@ -0,0 +1,86 @@
1
+ import { createAction, Property } from '@guayaba/workflows-framework';
2
+ import {
3
+ httpClient,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ } from '@guayaba/workflows-common';
7
+ import { googleSheetsAuth } from '../common/common';
8
+ import { commonProps } from '../common/props';
9
+ import { areSheetIdsValid, getAccessToken } from '../common/common';
10
+
11
+ export const exportSheetAction = createAction({
12
+ name: 'export_sheet',
13
+ displayName: 'Export Worksheet',
14
+ description: 'Download a worksheet as a CSV or TSV file.',
15
+ auth: googleSheetsAuth,
16
+ props: {
17
+ ...commonProps,
18
+ format: Property.StaticDropdown({
19
+ displayName: 'Export Format',
20
+ description: 'Select the file type to export the sheet as.',
21
+ required: true,
22
+ defaultValue: 'csv',
23
+ options: {
24
+ disabled: false,
25
+ options: [
26
+ { label: 'Comma Separated Values (.csv)', value: 'csv' },
27
+ { label: 'Tab Separated Values (.tsv)', value: 'tsv' },
28
+ ],
29
+ },
30
+ }),
31
+ returnAsText: Property.Checkbox({
32
+ displayName: 'Return as Text',
33
+ description: 'Return the exported data as text instead of a file.',
34
+ required: false,
35
+ defaultValue: false,
36
+ }),
37
+ },
38
+ async run({ propsValue, auth, files }) {
39
+ const { spreadsheetId, sheetId, format, returnAsText } = propsValue;
40
+
41
+ if (!areSheetIdsValid(spreadsheetId, sheetId)) {
42
+ throw new Error('Please select a spreadsheet and sheet first.');
43
+ }
44
+
45
+ const spreadsheet_id = spreadsheetId as string;
46
+ const sheet_id = sheetId as number;
47
+
48
+ const exportUrl = `https://docs.google.com/spreadsheets/d/${spreadsheet_id}/export?format=${format}&id=${spreadsheet_id}&gid=${sheet_id}`;
49
+
50
+ try {
51
+ const response = await httpClient.sendRequest({
52
+ method: HttpMethod.GET,
53
+ url: exportUrl,
54
+ authentication: {
55
+ type: AuthenticationType.BEARER_TOKEN,
56
+ token: await getAccessToken(auth),
57
+ },
58
+ responseType: 'arraybuffer',
59
+ followRedirects: true,
60
+ });
61
+
62
+ if (returnAsText) {
63
+ const textData = Buffer.from(response.body).toString('utf-8');
64
+ return {
65
+ text: textData,
66
+ format,
67
+ };
68
+ } else {
69
+ const filename = `exported_sheet.${format}`;
70
+
71
+ const file = await files.write({
72
+ fileName: filename,
73
+ data: Buffer.from(response.body),
74
+ });
75
+
76
+ return {
77
+ file,
78
+ filename,
79
+ format,
80
+ };
81
+ }
82
+ } catch (error) {
83
+ throw new Error(`Failed to export sheet: ${error}`);
84
+ }
85
+ },
86
+ });
@@ -0,0 +1,42 @@
1
+ import { Property, createAction } from '@guayaba/workflows-framework';
2
+ import { areSheetIdsValid, googleSheetsCommon } from '../common/common';
3
+ import { googleSheetsAuth } from '../common/common';
4
+ import { commonProps } from '../common/props';
5
+
6
+ export const findRowByNumAction = createAction({
7
+ auth: googleSheetsAuth,
8
+ name: 'find_row_by_num',
9
+ displayName: 'Get Single Row by ID',
10
+ description: 'Retrieve a specific row using its unique ID.',
11
+ props: {
12
+ ...commonProps,
13
+ rowNumber: Property.Number({
14
+ displayName: 'Row Number',
15
+ description: 'Enter the row number you want to retrieve',
16
+ required: true,
17
+ }),
18
+ headerRow: Property.Number({
19
+ displayName: 'Header Row Number',
20
+ description: 'Enter the row number where your column headers are located (usually row 1).',
21
+ required: true,
22
+ defaultValue: 1,
23
+ }),
24
+ },
25
+ async run(context) {
26
+ const { spreadsheetId, sheetId, rowNumber, headerRow } = context.propsValue;
27
+
28
+ if (!areSheetIdsValid(spreadsheetId, sheetId)) {
29
+ throw new Error('Please select a spreadsheet and sheet first.');
30
+ }
31
+
32
+ const row = await googleSheetsCommon.getGoogleSheetRows({
33
+ auth: context.auth,
34
+ sheetId: sheetId as number,
35
+ spreadsheetId: spreadsheetId as string,
36
+ rowIndex_s: rowNumber,
37
+ rowIndex_e: rowNumber,
38
+ headerRow: headerRow,
39
+ });
40
+ return row[0];
41
+ },
42
+ });