@pipedream/spreadsheet_com 0.0.1 → 0.1.0
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.
- package/actions/create-rows/create-rows.mjs +61 -0
- package/actions/update-rows/update-rows.mjs +53 -0
- package/common/utils.mjs +13 -0
- package/package.json +6 -5
- package/sources/row-updated/row-updated.mjs +125 -0
- package/sources/row-updated/test-event.mjs +19 -0
- package/spreadsheet_com.app.mjs +170 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { parseArray } from "../../common/utils.mjs";
|
|
2
|
+
import spreadsheetCom from "../../spreadsheet_com.app.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "spreadsheet_com-create-rows",
|
|
6
|
+
name: "Create Rows",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
description: "Adds new row(s) after last row that has data. Empty data sets are ignored. Provide data for at least 1 column. [See the documentation](https://developer.spreadsheet.com/#tag/Rows/operation/createRows)",
|
|
9
|
+
type: "action",
|
|
10
|
+
props: {
|
|
11
|
+
spreadsheetCom,
|
|
12
|
+
workbookId: {
|
|
13
|
+
propDefinition: [
|
|
14
|
+
spreadsheetCom,
|
|
15
|
+
"workbookId",
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
worksheetId: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
spreadsheetCom,
|
|
21
|
+
"worksheetId",
|
|
22
|
+
({ workbookId }) => ({
|
|
23
|
+
workbookId,
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
position: {
|
|
28
|
+
type: "string",
|
|
29
|
+
label: "Position",
|
|
30
|
+
description: "Position at which the row is to be added in the worksheet. If not specified, row is added after the last non-empty row in the worksheet. E.g. `S3vBb3FZRQuFtW1mrj0U2g:before`. [Where to find row Ids](https://developer.spreadsheet.com/#section/Using-the-API/Extract-Resource-IDs)",
|
|
31
|
+
optional: true,
|
|
32
|
+
},
|
|
33
|
+
rowsData: {
|
|
34
|
+
type: "string[]",
|
|
35
|
+
label: "Rows Data",
|
|
36
|
+
description: "Data row(s) to add. Each entry have the following sample format: `{ \"cellData\": [ { \"field\": \"A\", \"data\": \"Person\" }, { \"field\": \"B\", \"data\": \"Region\" } ] }`. Rows without any column data will be ignored. Maximum of 100 entries can be provided. [See the documentation](https://developer.spreadsheet.com/#tag/Rows/operation/createRows).",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
async run({ $ }) {
|
|
40
|
+
const {
|
|
41
|
+
spreadsheetCom,
|
|
42
|
+
worksheetId,
|
|
43
|
+
position,
|
|
44
|
+
rowsData,
|
|
45
|
+
} = this;
|
|
46
|
+
|
|
47
|
+
const response = await spreadsheetCom.createRows({
|
|
48
|
+
$,
|
|
49
|
+
worksheetId,
|
|
50
|
+
params: {
|
|
51
|
+
position,
|
|
52
|
+
},
|
|
53
|
+
data: parseArray(rowsData),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
$.export("$summary", `New row(s) with Id(s): ${(response.ids).toString()} ${response.ids.length > 1
|
|
57
|
+
? "were"
|
|
58
|
+
: "was"} successfully created!`);
|
|
59
|
+
return response;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { parseArray } from "../../common/utils.mjs";
|
|
2
|
+
import spreadsheetCom from "../../spreadsheet_com.app.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "spreadsheet_com-update-rows",
|
|
6
|
+
name: "Update Rows",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
description: "Update existing row(s). [See the documentation](https://developer.spreadsheet.com/#tag/Rows/operation/updateRows)",
|
|
9
|
+
type: "action",
|
|
10
|
+
props: {
|
|
11
|
+
spreadsheetCom,
|
|
12
|
+
workbookId: {
|
|
13
|
+
propDefinition: [
|
|
14
|
+
spreadsheetCom,
|
|
15
|
+
"workbookId",
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
worksheetId: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
spreadsheetCom,
|
|
21
|
+
"worksheetId",
|
|
22
|
+
({ workbookId }) => ({
|
|
23
|
+
workbookId,
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
rowsData: {
|
|
28
|
+
type: "string[]",
|
|
29
|
+
label: "Rows Data",
|
|
30
|
+
description: "Data row(s) to update. Each entry have the following sample format: `{ \"_id\": \"WTwPho0VQp-goWf_xtSMgQ\", \"cellData\": [ { \"field\": \"A\", \"data\": \"Person\" }, { \"field\": \"B\", \"data\": \"Region\" } ] }`. Response will contain list of row ids for which the operation was successful. Maximum of 100 entries can be provided. [Where to find row Ids](https://developer.spreadsheet.com/#section/Using-the-API/Extract-Resource-IDs)",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
async run({ $ }) {
|
|
34
|
+
const {
|
|
35
|
+
spreadsheetCom,
|
|
36
|
+
worksheetId,
|
|
37
|
+
rowsData,
|
|
38
|
+
} = this;
|
|
39
|
+
|
|
40
|
+
const parsedData = parseArray(rowsData);
|
|
41
|
+
|
|
42
|
+
const response = await spreadsheetCom.updateRows({
|
|
43
|
+
$,
|
|
44
|
+
worksheetId,
|
|
45
|
+
data: parsedData,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
$.export("$summary", `The row${parsedData.length > 1
|
|
49
|
+
? "s were"
|
|
50
|
+
: " was"} successfully updated!`);
|
|
51
|
+
return response;
|
|
52
|
+
},
|
|
53
|
+
};
|
package/common/utils.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const LIMIT = 100;
|
|
2
|
+
|
|
3
|
+
export const parseArray = (array) => {
|
|
4
|
+
if (Array.isArray(array)) {
|
|
5
|
+
return array.map((item) => {
|
|
6
|
+
if (typeof item != "object") {
|
|
7
|
+
return JSON.parse(item);
|
|
8
|
+
}
|
|
9
|
+
return item;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return JSON.parse(array);
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/spreadsheet_com",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Pipedream Spreadsheet.com Components",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "spreadsheet_com.app.mjs",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"pipedream",
|
|
8
8
|
"spreadsheet_com"
|
|
9
9
|
],
|
|
10
|
-
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
],
|
|
13
10
|
"homepage": "https://pipedream.com/apps/spreadsheet_com",
|
|
14
11
|
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
|
|
15
12
|
"publishConfig": {
|
|
16
13
|
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"moment": "^2.29.4",
|
|
17
|
+
"@pipedream/platform": "^1.5.1"
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigurationError, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
|
|
3
|
+
} from "@pipedream/platform";
|
|
4
|
+
import moment from "moment";
|
|
5
|
+
import spreadsheetCom from "../../spreadsheet_com.app.mjs";
|
|
6
|
+
import sampleEmit from "./test-event.mjs";
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
key: "spreadsheet_com-row-updated",
|
|
10
|
+
name: "New Row Updated",
|
|
11
|
+
version: "0.0.1",
|
|
12
|
+
description: "Emit new event when a row is updated.",
|
|
13
|
+
type: "source",
|
|
14
|
+
dedupe: "unique",
|
|
15
|
+
props: {
|
|
16
|
+
spreadsheetCom,
|
|
17
|
+
db: "$.service.db",
|
|
18
|
+
timer: {
|
|
19
|
+
label: "Polling interval",
|
|
20
|
+
description: "Pipedream will poll the Spreadsheet.com on this schedule",
|
|
21
|
+
type: "$.interface.timer",
|
|
22
|
+
default: {
|
|
23
|
+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
workbookId: {
|
|
27
|
+
propDefinition: [
|
|
28
|
+
spreadsheetCom,
|
|
29
|
+
"workbookId",
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
worksheetId: {
|
|
33
|
+
propDefinition: [
|
|
34
|
+
spreadsheetCom,
|
|
35
|
+
"worksheetId",
|
|
36
|
+
({ workbookId }) => ({
|
|
37
|
+
workbookId,
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
methods: {
|
|
43
|
+
_getLastDate() {
|
|
44
|
+
return this.db.get("lastDate") || 0;
|
|
45
|
+
},
|
|
46
|
+
_setLastDate(lastDate) {
|
|
47
|
+
this.db.set("lastDate", lastDate);
|
|
48
|
+
},
|
|
49
|
+
_getSortColumn() {
|
|
50
|
+
return this.db.get("sortColumn");
|
|
51
|
+
},
|
|
52
|
+
_setSortColumn(sortColumn) {
|
|
53
|
+
this.db.set("sortColumn", sortColumn);
|
|
54
|
+
},
|
|
55
|
+
async startEvent(maxResults = 0) {
|
|
56
|
+
const {
|
|
57
|
+
spreadsheetCom,
|
|
58
|
+
worksheetId,
|
|
59
|
+
} = this;
|
|
60
|
+
|
|
61
|
+
const lastDate = this._getLastDate();
|
|
62
|
+
const items = spreadsheetCom.paginate({
|
|
63
|
+
fn: spreadsheetCom.listRows,
|
|
64
|
+
maxResults,
|
|
65
|
+
worksheetId,
|
|
66
|
+
params: {
|
|
67
|
+
sort: {
|
|
68
|
+
"options": [
|
|
69
|
+
{
|
|
70
|
+
"column": this._getSortColumn(),
|
|
71
|
+
"sortType": "desc",
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
let responseArray = [];
|
|
79
|
+
|
|
80
|
+
for await (const item of items) {
|
|
81
|
+
if (moment(item.updatedAt).isSameOrBefore(lastDate)) break;
|
|
82
|
+
responseArray.push(item);
|
|
83
|
+
}
|
|
84
|
+
if (responseArray.length) this._setLastDate(responseArray[0].updatedAt);
|
|
85
|
+
|
|
86
|
+
for (const item of responseArray.reverse()) {
|
|
87
|
+
this.$emit(
|
|
88
|
+
item,
|
|
89
|
+
{
|
|
90
|
+
id: item._id + item.updatedAt,
|
|
91
|
+
summary: `The row with id: "${item._id}" was updated!`,
|
|
92
|
+
ts: item.updatedAt,
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
async getUpdatedAtColumn() {
|
|
98
|
+
const { spreadsheetCom } = this;
|
|
99
|
+
const columns = spreadsheetCom.paginate({
|
|
100
|
+
fn: spreadsheetCom.listColumns,
|
|
101
|
+
worksheetId: this.worksheetId,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
let sortColumn;
|
|
105
|
+
for await (const column of columns) {
|
|
106
|
+
if (column.dataType === "UPDATED_AT") {
|
|
107
|
+
sortColumn = column.field;
|
|
108
|
+
this._setSortColumn(column.field);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!sortColumn) throw new ConfigurationError("This worksheet doesn't have a column of type UPDATED_AT.");
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
hooks: {
|
|
116
|
+
async deploy() {
|
|
117
|
+
await this.getUpdatedAtColumn();
|
|
118
|
+
await this.startEvent(25);
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
async run() {
|
|
122
|
+
await this.startEvent();
|
|
123
|
+
},
|
|
124
|
+
sampleEmit,
|
|
125
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
"_id": "S3vBb3FZRQuFtW1mrj0U2g",
|
|
3
|
+
"createdAt": "2022-08-03T19:00:54.620Z",
|
|
4
|
+
"updatedAt": "2022-08-03T19:00:54.620Z",
|
|
5
|
+
"createdBy": "ocxAVW3oRSajt9yOKg7B-Q",
|
|
6
|
+
"updatedBy": "ocxAVW3oRSajt9yOKg7B-Q",
|
|
7
|
+
"cellData": [
|
|
8
|
+
{
|
|
9
|
+
"field": "col_1",
|
|
10
|
+
"data": "Person",
|
|
11
|
+
"dataType": "AUTOMATIC"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"field": "col_2",
|
|
15
|
+
"data": "Region",
|
|
16
|
+
"dataType": "AUTOMATIC"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { axios } from "@pipedream/platform";
|
|
2
|
+
import { LIMIT } from "./common/utils.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
type: "app",
|
|
6
|
+
app: "spreadsheet_com",
|
|
7
|
+
propDefinitions: {
|
|
8
|
+
columnId: {
|
|
9
|
+
type: "string",
|
|
10
|
+
label: "Column Id",
|
|
11
|
+
description: "Unique column identifier in the worksheet.",
|
|
12
|
+
async options({
|
|
13
|
+
page, worksheetId,
|
|
14
|
+
}) {
|
|
15
|
+
const { items } = await this.listColumns({
|
|
16
|
+
worksheetId,
|
|
17
|
+
params: {
|
|
18
|
+
limit: LIMIT,
|
|
19
|
+
offset: LIMIT * page,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return items.map(({ field }) => field);
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
workbookId: {
|
|
27
|
+
type: "string",
|
|
28
|
+
label: "Workbook Id",
|
|
29
|
+
description: "ID of the workbook.",
|
|
30
|
+
async options({ page }) {
|
|
31
|
+
const { items } = await this.listWorkbooks({
|
|
32
|
+
params: {
|
|
33
|
+
limit: LIMIT,
|
|
34
|
+
offset: LIMIT * page,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return items.map(({
|
|
39
|
+
_id: value, name: label,
|
|
40
|
+
}) => ({
|
|
41
|
+
label,
|
|
42
|
+
value,
|
|
43
|
+
}));
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
worksheetId: {
|
|
47
|
+
type: "string",
|
|
48
|
+
label: "Worksheet Id",
|
|
49
|
+
description: "ID of the worksheet.",
|
|
50
|
+
async options({
|
|
51
|
+
page, workbookId,
|
|
52
|
+
}) {
|
|
53
|
+
const { items } = await this.listWorksheets({
|
|
54
|
+
workbookId,
|
|
55
|
+
params: {
|
|
56
|
+
limit: LIMIT,
|
|
57
|
+
offset: LIMIT * page,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return items.map(({
|
|
62
|
+
_id: value, name: label,
|
|
63
|
+
}) => ({
|
|
64
|
+
label,
|
|
65
|
+
value,
|
|
66
|
+
}));
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
methods: {
|
|
71
|
+
_apiUrl() {
|
|
72
|
+
return "https://api.spreadsheet.com/v1";
|
|
73
|
+
},
|
|
74
|
+
_getHeaders() {
|
|
75
|
+
return {
|
|
76
|
+
"Authorization": `Bearer ${this.$auth.api_key}`,
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
_makeRequest({
|
|
81
|
+
$ = this, path, ...opts
|
|
82
|
+
}) {
|
|
83
|
+
const config = {
|
|
84
|
+
url: `${this._apiUrl()}/${path}`,
|
|
85
|
+
headers: this._getHeaders(),
|
|
86
|
+
...opts,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return axios($, config);
|
|
90
|
+
},
|
|
91
|
+
createRows({
|
|
92
|
+
worksheetId, ...args
|
|
93
|
+
}) {
|
|
94
|
+
return this._makeRequest({
|
|
95
|
+
method: "POST",
|
|
96
|
+
path: `worksheets/${worksheetId}/rows`,
|
|
97
|
+
...args,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
updateRows({
|
|
101
|
+
worksheetId, ...args
|
|
102
|
+
}) {
|
|
103
|
+
return this._makeRequest({
|
|
104
|
+
method: "PUT",
|
|
105
|
+
path: `worksheets/${worksheetId}/rows`,
|
|
106
|
+
...args,
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
listColumns({
|
|
110
|
+
worksheetId, ...args
|
|
111
|
+
}) {
|
|
112
|
+
return this._makeRequest({
|
|
113
|
+
path: `worksheets/${worksheetId}/columns`,
|
|
114
|
+
...args,
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
listRows({
|
|
118
|
+
worksheetId, ...args
|
|
119
|
+
}) {
|
|
120
|
+
return this._makeRequest({
|
|
121
|
+
path: `worksheets/${worksheetId}/rows`,
|
|
122
|
+
...args,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
listWorkbooks(args = {}) {
|
|
126
|
+
return this._makeRequest({
|
|
127
|
+
path: "workbooks",
|
|
128
|
+
...args,
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
listWorksheets({
|
|
132
|
+
workbookId, ...args
|
|
133
|
+
}) {
|
|
134
|
+
return this._makeRequest({
|
|
135
|
+
path: `workbooks/${workbookId}/worksheets`,
|
|
136
|
+
...args,
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
async *paginate({
|
|
140
|
+
fn, params = {}, maxResults = null, ...args
|
|
141
|
+
}) {
|
|
142
|
+
let hasMore = false;
|
|
143
|
+
let count = 0;
|
|
144
|
+
let page = 0;
|
|
145
|
+
|
|
146
|
+
do {
|
|
147
|
+
params.limit = LIMIT;
|
|
148
|
+
params.offset = LIMIT * page;
|
|
149
|
+
page++;
|
|
150
|
+
const {
|
|
151
|
+
items,
|
|
152
|
+
hasMore: hasMoreItems,
|
|
153
|
+
} = await fn({
|
|
154
|
+
params,
|
|
155
|
+
...args,
|
|
156
|
+
});
|
|
157
|
+
for (const d of items) {
|
|
158
|
+
yield d;
|
|
159
|
+
|
|
160
|
+
if (maxResults && ++count === maxResults) {
|
|
161
|
+
return count;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
hasMore = hasMoreItems;
|
|
166
|
+
|
|
167
|
+
} while (hasMore);
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
};
|