@activepieces/piece-google-bigquery 0.0.2 → 0.0.4

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 (61) hide show
  1. package/package.json +7 -58
  2. package/src/index.js +100 -60
  3. package/src/index.d.ts +0 -8
  4. package/src/index.d.ts.map +0 -1
  5. package/src/index.js.map +0 -1
  6. package/src/lib/actions/create-row.d.ts +0 -22
  7. package/src/lib/actions/create-row.d.ts.map +0 -1
  8. package/src/lib/actions/create-row.js +0 -75
  9. package/src/lib/actions/create-row.js.map +0 -1
  10. package/src/lib/actions/create-rows.d.ts +0 -21
  11. package/src/lib/actions/create-rows.d.ts.map +0 -1
  12. package/src/lib/actions/create-rows.js +0 -84
  13. package/src/lib/actions/create-rows.js.map +0 -1
  14. package/src/lib/actions/delete-rows.d.ts +0 -20
  15. package/src/lib/actions/delete-rows.d.ts.map +0 -1
  16. package/src/lib/actions/delete-rows.js +0 -43
  17. package/src/lib/actions/delete-rows.js.map +0 -1
  18. package/src/lib/actions/find-one-row.d.ts +0 -21
  19. package/src/lib/actions/find-one-row.d.ts.map +0 -1
  20. package/src/lib/actions/find-one-row.js +0 -60
  21. package/src/lib/actions/find-one-row.js.map +0 -1
  22. package/src/lib/actions/find-or-create-row.d.ts +0 -21
  23. package/src/lib/actions/find-or-create-row.d.ts.map +0 -1
  24. package/src/lib/actions/find-or-create-row.js +0 -79
  25. package/src/lib/actions/find-or-create-row.js.map +0 -1
  26. package/src/lib/actions/get-rows-for-job.d.ts +0 -13
  27. package/src/lib/actions/get-rows-for-job.d.ts.map +0 -1
  28. package/src/lib/actions/get-rows-for-job.js +0 -76
  29. package/src/lib/actions/get-rows-for-job.js.map +0 -1
  30. package/src/lib/actions/import-data.d.ts +0 -21
  31. package/src/lib/actions/import-data.d.ts.map +0 -1
  32. package/src/lib/actions/import-data.js +0 -111
  33. package/src/lib/actions/import-data.js.map +0 -1
  34. package/src/lib/actions/run-query.d.ts +0 -14
  35. package/src/lib/actions/run-query.d.ts.map +0 -1
  36. package/src/lib/actions/run-query.js +0 -86
  37. package/src/lib/actions/run-query.js.map +0 -1
  38. package/src/lib/actions/update-rows.d.ts +0 -21
  39. package/src/lib/actions/update-rows.d.ts.map +0 -1
  40. package/src/lib/actions/update-rows.js +0 -48
  41. package/src/lib/actions/update-rows.js.map +0 -1
  42. package/src/lib/common/index.d.ts +0 -73
  43. package/src/lib/common/index.d.ts.map +0 -1
  44. package/src/lib/common/index.js +0 -343
  45. package/src/lib/common/index.js.map +0 -1
  46. package/src/lib/triggers/new-job-completed.d.ts +0 -39
  47. package/src/lib/triggers/new-job-completed.d.ts.map +0 -1
  48. package/src/lib/triggers/new-job-completed.js +0 -118
  49. package/src/lib/triggers/new-job-completed.js.map +0 -1
  50. package/src/lib/triggers/new-row.d.ts +0 -75
  51. package/src/lib/triggers/new-row.d.ts.map +0 -1
  52. package/src/lib/triggers/new-row.js +0 -109
  53. package/src/lib/triggers/new-row.js.map +0 -1
  54. package/src/lib/triggers/query-job-completed.d.ts +0 -39
  55. package/src/lib/triggers/query-job-completed.d.ts.map +0 -1
  56. package/src/lib/triggers/query-job-completed.js +0 -127
  57. package/src/lib/triggers/query-job-completed.js.map +0 -1
  58. package/src/lib/triggers/updated-row.d.ts +0 -79
  59. package/src/lib/triggers/updated-row.d.ts.map +0 -1
  60. package/src/lib/triggers/updated-row.js +0 -118
  61. package/src/lib/triggers/updated-row.js.map +0 -1
@@ -1,109 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.newRowTrigger = void 0;
4
- const tslib_1 = require("tslib");
5
- const pieces_framework_1 = require("@activepieces/pieces-framework");
6
- const pieces_common_1 = require("@activepieces/pieces-common");
7
- const common_1 = require("../common");
8
- const props = {
9
- project_id: common_1.projectIdProp,
10
- dataset_id: common_1.datasetIdProp,
11
- table_id: common_1.tableIdProp,
12
- sort_column: pieces_framework_1.Property.ShortText({
13
- displayName: 'Sort Column',
14
- description: 'Name of the column used to detect new rows. The table is ordered by this column (DESC) and any row newer than the last check is returned. Use a TIMESTAMP or DATETIME column, e.g. `created_at`.',
15
- required: true,
16
- }),
17
- max_results: pieces_framework_1.Property.Number({
18
- displayName: 'Max Rows per Check',
19
- description: 'Maximum number of new rows to return per poll (default: 500).',
20
- required: false,
21
- defaultValue: 500,
22
- }),
23
- };
24
- const polling = {
25
- strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
26
- items: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue, lastFetchEpochMS }) {
27
- var _b, _c, _d, _e;
28
- const { project_id, dataset_id, table_id, sort_column, max_results } = propsValue;
29
- const limit = (_b = max_results) !== null && _b !== void 0 ? _b : 500;
30
- const token = yield (0, common_1.getAccessToken)(auth);
31
- // First run: look back 7 days; subsequent runs: since last check
32
- const threshold = lastFetchEpochMS !== null && lastFetchEpochMS !== void 0 ? lastFetchEpochMS : Date.now() - 7 * 24 * 60 * 60 * 1000;
33
- const fullTable = `\`${project_id}.${dataset_id}.${table_id}\``;
34
- const col = sort_column;
35
- const query = `SELECT * FROM ${fullTable} WHERE \`${col}\` > TIMESTAMP_MILLIS(${threshold}) ORDER BY \`${col}\` ASC LIMIT ${limit}`;
36
- const response = yield pieces_common_1.httpClient.sendRequest({
37
- method: pieces_common_1.HttpMethod.POST,
38
- url: `${common_1.BASE_URL}/projects/${project_id}/queries`,
39
- headers: { Authorization: `Bearer ${token}` },
40
- body: { query, useLegacySql: false, maxResults: limit, timeoutMs: 30000 },
41
- });
42
- let result = response.body;
43
- if (!result.jobComplete) {
44
- for (let i = 0; i < 30 && !result.jobComplete; i++) {
45
- const poll = yield pieces_common_1.httpClient.sendRequest({
46
- method: pieces_common_1.HttpMethod.GET,
47
- url: `${common_1.BASE_URL}/projects/${project_id}/queries/${result.jobReference.jobId}`,
48
- headers: { Authorization: `Bearer ${token}` },
49
- queryParams: { timeoutMs: '10000', maxResults: String(limit) },
50
- });
51
- result = poll.body;
52
- }
53
- }
54
- const schema = (_d = (_c = result.schema) === null || _c === void 0 ? void 0 : _c.fields) !== null && _d !== void 0 ? _d : [];
55
- const rows = (0, common_1.bigQueryRowsToFlat)(schema, (_e = result.rows) !== null && _e !== void 0 ? _e : []);
56
- return rows.map((row) => {
57
- const tsValue = row[col];
58
- let epochMs;
59
- if (typeof tsValue === 'string') {
60
- const parsed = parseFloat(tsValue);
61
- epochMs =
62
- !isNaN(parsed) && parsed > 1e9
63
- ? parsed * 1000
64
- : new Date(tsValue).getTime();
65
- }
66
- else if (typeof tsValue === 'number') {
67
- epochMs = tsValue > 1e12 ? tsValue : tsValue * 1000;
68
- }
69
- else {
70
- epochMs = Date.now();
71
- }
72
- return { epochMilliSeconds: epochMs, data: row };
73
- });
74
- }),
75
- };
76
- exports.newRowTrigger = (0, pieces_framework_1.createTrigger)({
77
- auth: common_1.bigQueryAuth,
78
- name: 'new_row',
79
- displayName: 'New Row',
80
- description: 'Triggers when a new row is added to a BigQuery table. Polls every 5 minutes by comparing the latest value in a sort column against the previous check.',
81
- props,
82
- sampleData: {
83
- id: '1',
84
- created_at: '2024-01-15T10:30:00Z',
85
- name: 'Example row',
86
- },
87
- type: pieces_framework_1.TriggerStrategy.POLLING,
88
- test(context) {
89
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
90
- return yield pieces_common_1.pollingHelper.test(polling, context);
91
- });
92
- },
93
- onEnable(context) {
94
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
95
- yield pieces_common_1.pollingHelper.onEnable(polling, context);
96
- });
97
- },
98
- onDisable(context) {
99
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
100
- yield pieces_common_1.pollingHelper.onDisable(polling, context);
101
- });
102
- },
103
- run(context) {
104
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
105
- return yield pieces_common_1.pollingHelper.poll(polling, context);
106
- });
107
- },
108
- });
109
- //# sourceMappingURL=new-row.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"new-row.js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,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;KAAA;IACK,SAAS,CAAC,OAAO;;YACrB,MAAM,6BAAa,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC;KAAA;IACK,GAAG,CAAC,OAAO;;YACf,OAAO,MAAM,6BAAa,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -1,39 +0,0 @@
1
- import { TriggerStrategy } from '@activepieces/pieces-framework';
2
- export declare const queryJobCompletedTrigger: import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
3
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
4
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
5
- }>)[], {
6
- project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
7
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
8
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
9
- }>)[]>;
10
- max_rows_per_job: import("@activepieces/pieces-framework").NumberProperty<false>;
11
- }> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.POLLING, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
12
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
13
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
14
- }>)[], {
15
- project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
16
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
17
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
18
- }>)[]>;
19
- max_rows_per_job: import("@activepieces/pieces-framework").NumberProperty<false>;
20
- }> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.MANUAL, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
21
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
22
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
23
- }>)[], {
24
- project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
25
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
26
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
27
- }>)[]>;
28
- max_rows_per_job: import("@activepieces/pieces-framework").NumberProperty<false>;
29
- }> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
30
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
31
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
32
- }>)[], {
33
- project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
34
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
35
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
36
- }>)[]>;
37
- max_rows_per_job: import("@activepieces/pieces-framework").NumberProperty<false>;
38
- }>;
39
- //# sourceMappingURL=query-job-completed.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-job-completed.d.ts","sourceRoot":"","sources":["../../../../src/lib/triggers/query-job-completed.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,eAAe,EAChB,MAAM,gCAAgC,CAAC;AA+IxC,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCnC,CAAC"}
@@ -1,127 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.queryJobCompletedTrigger = void 0;
4
- const tslib_1 = require("tslib");
5
- const pieces_framework_1 = require("@activepieces/pieces-framework");
6
- const pieces_common_1 = require("@activepieces/pieces-common");
7
- const common_1 = require("../common");
8
- const props = {
9
- project_id: common_1.projectIdProp,
10
- max_rows_per_job: pieces_framework_1.Property.Number({
11
- displayName: 'Max Rows per Job',
12
- description: 'Maximum number of result rows to fetch per completed job (default: 500).',
13
- required: false,
14
- defaultValue: 500,
15
- }),
16
- };
17
- const polling = {
18
- strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
19
- items: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue, lastFetchEpochMS }) {
20
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
21
- const { project_id, max_rows_per_job } = propsValue;
22
- const rowLimit = (_b = max_rows_per_job) !== null && _b !== void 0 ? _b : 500;
23
- const token = yield (0, common_1.getAccessToken)(auth);
24
- // Look back an hour before lastFetch to catch long-running jobs
25
- const minCreationTime = (lastFetchEpochMS !== null && lastFetchEpochMS !== void 0 ? lastFetchEpochMS : Date.now() - 24 * 60 * 60 * 1000) - 60 * 60 * 1000;
26
- const listResponse = yield pieces_common_1.httpClient.sendRequest({
27
- method: pieces_common_1.HttpMethod.GET,
28
- url: `${common_1.BASE_URL}/projects/${project_id}/jobs`,
29
- headers: { Authorization: `Bearer ${token}` },
30
- queryParams: {
31
- stateFilter: 'done',
32
- projection: 'full',
33
- minCreationTime: String(minCreationTime),
34
- maxResults: '50',
35
- },
36
- });
37
- const jobs = ((_c = listResponse.body.jobs) !== null && _c !== void 0 ? _c : []).filter((j) => {
38
- var _a;
39
- return j.configuration.jobType === 'QUERY' &&
40
- !j.status.errorResult &&
41
- parseInt((_a = j.statistics.endTime) !== null && _a !== void 0 ? _a : '0', 10) > (lastFetchEpochMS !== null && lastFetchEpochMS !== void 0 ? lastFetchEpochMS : 0);
42
- });
43
- const items = [];
44
- for (const job of jobs) {
45
- const jobId = job.jobReference.jobId;
46
- const location = job.jobReference.location;
47
- const endTime = parseInt((_d = job.statistics.endTime) !== null && _d !== void 0 ? _d : '0', 10);
48
- // Fetch result rows for this job
49
- const rows = [];
50
- let schema = [];
51
- let pageToken;
52
- do {
53
- const rowsResp = yield pieces_common_1.httpClient.sendRequest({
54
- method: pieces_common_1.HttpMethod.GET,
55
- url: `${common_1.BASE_URL}/projects/${project_id}/queries/${jobId}`,
56
- headers: { Authorization: `Bearer ${token}` },
57
- queryParams: Object.assign(Object.assign({ maxResults: String(Math.min(rowLimit - rows.length, 1000)), timeoutMs: '5000' }, (pageToken ? { pageToken } : {})), (location ? { location } : {})),
58
- });
59
- if ((_e = rowsResp.body.schema) === null || _e === void 0 ? void 0 : _e.fields)
60
- schema = rowsResp.body.schema.fields;
61
- rows.push(...((_f = rowsResp.body.rows) !== null && _f !== void 0 ? _f : []));
62
- pageToken = rowsResp.body.pageToken;
63
- } while (pageToken && rows.length < rowLimit);
64
- const flatRows = (0, common_1.bigQueryRowsToFlat)(schema, rows.slice(0, rowLimit));
65
- items.push({
66
- epochMilliSeconds: endTime,
67
- data: {
68
- job_id: jobId,
69
- project_id: job.jobReference.projectId,
70
- location: location !== null && location !== void 0 ? location : null,
71
- query: (_h = (_g = job.configuration.query) === null || _g === void 0 ? void 0 : _g.query) !== null && _h !== void 0 ? _h : null,
72
- completed_at: job.statistics.endTime
73
- ? new Date(endTime).toISOString()
74
- : null,
75
- bytes_processed: (_k = (_j = job.statistics.query) === null || _j === void 0 ? void 0 : _j.totalBytesProcessed) !== null && _k !== void 0 ? _k : null,
76
- cache_hit: (_m = (_l = job.statistics.query) === null || _l === void 0 ? void 0 : _l.cacheHit) !== null && _m !== void 0 ? _m : null,
77
- user_email: (_o = job.user_email) !== null && _o !== void 0 ? _o : null,
78
- row_count: flatRows.length,
79
- rows: flatRows,
80
- },
81
- });
82
- }
83
- return items;
84
- }),
85
- };
86
- exports.queryJobCompletedTrigger = (0, pieces_framework_1.createTrigger)({
87
- auth: common_1.bigQueryAuth,
88
- name: 'query_job_completed',
89
- displayName: 'Query Job Completed (With Row Data)',
90
- description: 'Triggers when a BigQuery query job finishes successfully. Each flow run receives the job metadata and the result rows from that query.',
91
- props,
92
- sampleData: {
93
- job_id: 'job_abc123',
94
- project_id: 'my-project',
95
- query: 'SELECT * FROM my_dataset.my_table LIMIT 10',
96
- completed_at: '2024-01-15T10:30:00Z',
97
- bytes_processed: '1024',
98
- cache_hit: false,
99
- row_count: 2,
100
- rows: [
101
- { id: '1', name: 'Alice' },
102
- { id: '2', name: 'Bob' },
103
- ],
104
- },
105
- type: pieces_framework_1.TriggerStrategy.POLLING,
106
- test(context) {
107
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
108
- return yield pieces_common_1.pollingHelper.test(polling, context);
109
- });
110
- },
111
- onEnable(context) {
112
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
113
- yield pieces_common_1.pollingHelper.onEnable(polling, context);
114
- });
115
- },
116
- onDisable(context) {
117
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
118
- yield pieces_common_1.pollingHelper.onDisable(polling, context);
119
- });
120
- },
121
- run(context) {
122
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
123
- return yield pieces_common_1.pollingHelper.poll(polling, context);
124
- });
125
- },
126
- });
127
- //# sourceMappingURL=query-job-completed.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-job-completed.js","sourceRoot":"","sources":["../../../../src/lib/triggers/query-job-completed.ts"],"names":[],"mappings":";;;;AAAA,qEAMwC;AACxC,+DAMqC;AACrC,sCASmB;AAEnB,MAAM,KAAK,GAAG;IACZ,UAAU,EAAE,sBAAa;IACzB,gBAAgB,EAAE,2BAAQ,CAAC,MAAM,CAAC;QAChC,WAAW,EAAE,kBAAkB;QAC/B,WAAW,EACT,0EAA0E;QAC5E,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,GAAG;KAClB,CAAC;CACH,CAAC;AAuBF,MAAM,OAAO,GAGT;IACF,QAAQ,EAAE,8BAAc,CAAC,SAAS;IAClC,KAAK,EAAE,KAA+C,EAAE,oDAA1C,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE;;QAClD,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,UAAU,CAAC;QACpD,MAAM,QAAQ,GAAG,MAAC,gBAA2B,mCAAI,GAAG,CAAC;QACrD,MAAM,KAAK,GAAG,MAAM,IAAA,uBAAc,EAAC,IAAyB,CAAC,CAAC;QAE9D,gEAAgE;QAChE,MAAM,eAAe,GACnB,CAAC,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAE1E,MAAM,YAAY,GAAG,MAAM,0BAAU,CAAC,WAAW,CAC/C;YACE,MAAM,EAAE,0BAAU,CAAC,GAAG;YACtB,GAAG,EAAE,GAAG,iBAAQ,aAAa,UAAoB,OAAO;YACxD,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE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OAAO;;YACrB,MAAM,6BAAa,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC;KAAA;IACK,GAAG,CAAC,OAAO;;YACf,OAAO,MAAM,6BAAa,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -1,79 +0,0 @@
1
- import { TriggerStrategy } from '@activepieces/pieces-framework';
2
- export declare const updatedRowTrigger: import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
3
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
4
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
5
- }>)[], {
6
- project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
7
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
8
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
9
- }>)[]>;
10
- dataset_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
11
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
12
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
13
- }>)[]>;
14
- table_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
15
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
16
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
17
- }>)[]>;
18
- updated_at_column: import("@activepieces/pieces-framework").ShortTextProperty<true>;
19
- created_at_column: import("@activepieces/pieces-framework").ShortTextProperty<false>;
20
- max_results: import("@activepieces/pieces-framework").NumberProperty<false>;
21
- }> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.POLLING, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
22
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
23
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
24
- }>)[], {
25
- project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
26
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
27
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
28
- }>)[]>;
29
- dataset_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
30
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
31
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
32
- }>)[]>;
33
- table_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
34
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
35
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
36
- }>)[]>;
37
- updated_at_column: import("@activepieces/pieces-framework").ShortTextProperty<true>;
38
- created_at_column: import("@activepieces/pieces-framework").ShortTextProperty<false>;
39
- max_results: import("@activepieces/pieces-framework").NumberProperty<false>;
40
- }> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.MANUAL, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
41
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
42
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
43
- }>)[], {
44
- project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
45
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
46
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
47
- }>)[]>;
48
- dataset_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
49
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
50
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
51
- }>)[]>;
52
- table_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
53
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
54
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
55
- }>)[]>;
56
- updated_at_column: import("@activepieces/pieces-framework").ShortTextProperty<true>;
57
- created_at_column: import("@activepieces/pieces-framework").ShortTextProperty<false>;
58
- max_results: import("@activepieces/pieces-framework").NumberProperty<false>;
59
- }> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
60
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
61
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
62
- }>)[], {
63
- project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
64
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
65
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
66
- }>)[]>;
67
- dataset_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
68
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
69
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
70
- }>)[]>;
71
- table_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
72
- instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
73
- serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
74
- }>)[]>;
75
- updated_at_column: import("@activepieces/pieces-framework").ShortTextProperty<true>;
76
- created_at_column: import("@activepieces/pieces-framework").ShortTextProperty<false>;
77
- max_results: import("@activepieces/pieces-framework").NumberProperty<false>;
78
- }>;
79
- //# sourceMappingURL=updated-row.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updated-row.d.ts","sourceRoot":"","sources":["../../../../src/lib/triggers/updated-row.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,eAAe,EAChB,MAAM,gCAAgC,CAAC;AAuIxC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqB5B,CAAC"}
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updatedRowTrigger = void 0;
4
- const tslib_1 = require("tslib");
5
- const pieces_framework_1 = require("@activepieces/pieces-framework");
6
- const pieces_common_1 = require("@activepieces/pieces-common");
7
- const common_1 = require("../common");
8
- const props = {
9
- project_id: common_1.projectIdProp,
10
- dataset_id: common_1.datasetIdProp,
11
- table_id: common_1.tableIdProp,
12
- updated_at_column: pieces_framework_1.Property.ShortText({
13
- displayName: 'Updated At Column',
14
- description: 'Name of the TIMESTAMP column that records when a row was last updated, e.g. `updated_at`. Rows where this column is newer than the last check are returned.',
15
- required: true,
16
- }),
17
- created_at_column: pieces_framework_1.Property.ShortText({
18
- displayName: 'Created At Column (optional)',
19
- description: 'If provided, only rows where the updated timestamp is newer than the created timestamp are returned, excluding brand-new rows from the results.',
20
- required: false,
21
- }),
22
- max_results: pieces_framework_1.Property.Number({
23
- displayName: 'Max Rows per Check',
24
- description: 'Maximum number of updated rows to return per poll (default: 500).',
25
- required: false,
26
- defaultValue: 500,
27
- }),
28
- };
29
- const polling = {
30
- strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
31
- items: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue, lastFetchEpochMS }) {
32
- var _b, _c, _d, _e;
33
- const { project_id, dataset_id, table_id, updated_at_column, created_at_column, max_results, } = propsValue;
34
- const limit = (_b = max_results) !== null && _b !== void 0 ? _b : 500;
35
- const token = yield (0, common_1.getAccessToken)(auth);
36
- const threshold = lastFetchEpochMS !== null && lastFetchEpochMS !== void 0 ? lastFetchEpochMS : Date.now() - 7 * 24 * 60 * 60 * 1000;
37
- const fullTable = `\`${project_id}.${dataset_id}.${table_id}\``;
38
- const updCol = updated_at_column;
39
- // Filter: updated after threshold; optionally exclude brand-new rows
40
- const createdFilter = created_at_column
41
- ? ` AND \`${created_at_column}\` < TIMESTAMP_MILLIS(${threshold})`
42
- : '';
43
- const query = [
44
- `SELECT * FROM ${fullTable}`,
45
- `WHERE \`${updCol}\` > TIMESTAMP_MILLIS(${threshold})${createdFilter}`,
46
- `ORDER BY \`${updCol}\` ASC`,
47
- `LIMIT ${limit}`,
48
- ].join(' ');
49
- const response = yield pieces_common_1.httpClient.sendRequest({
50
- method: pieces_common_1.HttpMethod.POST,
51
- url: `${common_1.BASE_URL}/projects/${project_id}/queries`,
52
- headers: { Authorization: `Bearer ${token}` },
53
- body: { query, useLegacySql: false, maxResults: limit, timeoutMs: 30000 },
54
- });
55
- let result = response.body;
56
- if (!result.jobComplete) {
57
- for (let i = 0; i < 30 && !result.jobComplete; i++) {
58
- const poll = yield pieces_common_1.httpClient.sendRequest({
59
- method: pieces_common_1.HttpMethod.GET,
60
- url: `${common_1.BASE_URL}/projects/${project_id}/queries/${result.jobReference.jobId}`,
61
- headers: { Authorization: `Bearer ${token}` },
62
- queryParams: { timeoutMs: '10000', maxResults: String(limit) },
63
- });
64
- result = poll.body;
65
- }
66
- }
67
- const schema = (_d = (_c = result.schema) === null || _c === void 0 ? void 0 : _c.fields) !== null && _d !== void 0 ? _d : [];
68
- const rows = (0, common_1.bigQueryRowsToFlat)(schema, (_e = result.rows) !== null && _e !== void 0 ? _e : []);
69
- return rows.map((row) => {
70
- const tsValue = row[updCol];
71
- let epochMs;
72
- if (typeof tsValue === 'string') {
73
- const parsed = parseFloat(tsValue);
74
- epochMs =
75
- !isNaN(parsed) && parsed > 1e9
76
- ? parsed * 1000
77
- : new Date(tsValue).getTime();
78
- }
79
- else if (typeof tsValue === 'number') {
80
- epochMs = tsValue > 1e12 ? tsValue : tsValue * 1000;
81
- }
82
- else {
83
- epochMs = Date.now();
84
- }
85
- return { epochMilliSeconds: epochMs, data: row };
86
- });
87
- }),
88
- };
89
- exports.updatedRowTrigger = (0, pieces_framework_1.createTrigger)({
90
- auth: common_1.bigQueryAuth,
91
- name: 'updated_row',
92
- displayName: 'Updated Row',
93
- description: 'Triggers when an existing row is updated in a BigQuery table. Requires an `updated_at` TIMESTAMP column that is set whenever a row changes.',
94
- props,
95
- sampleData: { id: '1', updated_at: '2024-01-15T10:30:00Z', status: 'active' },
96
- type: pieces_framework_1.TriggerStrategy.POLLING,
97
- test(context) {
98
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
99
- return yield pieces_common_1.pollingHelper.test(polling, context);
100
- });
101
- },
102
- onEnable(context) {
103
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
104
- yield pieces_common_1.pollingHelper.onEnable(polling, context);
105
- });
106
- },
107
- onDisable(context) {
108
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
109
- yield pieces_common_1.pollingHelper.onDisable(polling, context);
110
- });
111
- },
112
- run(context) {
113
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
114
- return yield pieces_common_1.pollingHelper.poll(polling, context);
115
- });
116
- },
117
- });
118
- //# sourceMappingURL=updated-row.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updated-row.js","sourceRoot":"","sources":["../../../../src/lib/triggers/updated-row.ts"],"names":[],"mappings":";;;;AAAA,qEAMwC;AACxC,+DAMqC;AACrC,sCAWmB;AAEnB,MAAM,KAAK,GAAG;IACZ,UAAU,EAAE,sBAAa;IACzB,UAAU,EAAE,sBAAa;IACzB,QAAQ,EAAE,oBAAW;IACrB,iBAAiB,EAAE,2BAAQ,CAAC,SAAS,CAAC;QACpC,WAAW,EAAE,mBAAmB;QAChC,WAAW,EACT,6JAA6J;QAC/J,QAAQ,EAAE,IA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