@pipedream/orca_scan 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/add-update-row/add-update-row.mjs +71 -0
- package/actions/find-row/find-row.mjs +36 -0
- package/orca_scan.app.mjs +107 -5
- package/package.json +4 -1
- package/sources/common/base.mjs +35 -0
- package/sources/new-row/new-row.mjs +50 -0
- package/sources/new-row/test-event.mjs +7 -0
- package/sources/new-sheet/new-sheet.mjs +42 -0
- package/sources/new-sheet/test-event.mjs +9 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import orca_scan from "../../orca_scan.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "orca_scan-add-update-row",
|
|
5
|
+
name: "Add or Update Row",
|
|
6
|
+
description: "Adds a new row or updates an existing row in a sheet. [See the documentation](https://orcascan.com/guides/add-barcode-tracking-to-your-system-using-a-rest-api-f09a21c3)",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
type: "action",
|
|
9
|
+
props: {
|
|
10
|
+
orca_scan,
|
|
11
|
+
sheetId: {
|
|
12
|
+
propDefinition: [
|
|
13
|
+
orca_scan,
|
|
14
|
+
"sheetId",
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
rowData: {
|
|
18
|
+
propDefinition: [
|
|
19
|
+
orca_scan,
|
|
20
|
+
"rowData",
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
barcode: {
|
|
24
|
+
propDefinition: [
|
|
25
|
+
orca_scan,
|
|
26
|
+
"barcode",
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
async run({ $ }) {
|
|
31
|
+
let rowId = null;
|
|
32
|
+
|
|
33
|
+
// Check if a row with the given barcode exists
|
|
34
|
+
if (this.barcode) {
|
|
35
|
+
const { data } = await this.orca_scan.listRows({
|
|
36
|
+
sheetId: this.sheetId,
|
|
37
|
+
params: {
|
|
38
|
+
barcode: this.barcode || null,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
if (data.length > 0) {
|
|
42
|
+
const row = data[0];
|
|
43
|
+
// Assume the first row is the one to update
|
|
44
|
+
rowId = row._id;
|
|
45
|
+
for (const [
|
|
46
|
+
key,
|
|
47
|
+
value,
|
|
48
|
+
] of Object.entries(this.rowData)) {
|
|
49
|
+
row[key] = value;
|
|
50
|
+
}
|
|
51
|
+
this.rowData = row;
|
|
52
|
+
} else {
|
|
53
|
+
this.rowData.barcode = this.barcode;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!this.rowData.date) this.rowData.date = new Date();
|
|
58
|
+
|
|
59
|
+
// Make the request to add or update the row
|
|
60
|
+
const response = await this.orca_scan.addOrUpdateRow({
|
|
61
|
+
sheetId: this.sheetId,
|
|
62
|
+
data: this.rowData,
|
|
63
|
+
rowId: rowId,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
$.export("$summary", `Successfully ${rowId
|
|
67
|
+
? "updated"
|
|
68
|
+
: "added"} row with ID: ${response.data?._id}`);
|
|
69
|
+
return response;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import orca_scan from "../../orca_scan.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "orca_scan-find-row",
|
|
5
|
+
name: "Find Row",
|
|
6
|
+
description: "Locates a row record based on a given barcode. If no barcode is provided, return all rows. [See the documentation](https://orcascan.com/guides/add-barcode-tracking-to-your-system-using-a-rest-api-f09a21c3#rows-1)",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
type: "action",
|
|
9
|
+
props: {
|
|
10
|
+
orca_scan,
|
|
11
|
+
sheetId: {
|
|
12
|
+
propDefinition: [
|
|
13
|
+
orca_scan,
|
|
14
|
+
"sheetId",
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
barcode: {
|
|
18
|
+
propDefinition: [
|
|
19
|
+
orca_scan,
|
|
20
|
+
"barcode",
|
|
21
|
+
],
|
|
22
|
+
optional: true,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
async run({ $ }) {
|
|
26
|
+
const rows = await this.orca_scan.listRows({
|
|
27
|
+
sheetId: this.sheetId,
|
|
28
|
+
params: {
|
|
29
|
+
barcode: this.barcode || null,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
$.export("$summary", `Successfully found ${rows.data?.length} row(s)`);
|
|
34
|
+
return rows;
|
|
35
|
+
},
|
|
36
|
+
};
|
package/orca_scan.app.mjs
CHANGED
|
@@ -1,11 +1,113 @@
|
|
|
1
|
+
import { axios } from "@pipedream/platform";
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
type: "app",
|
|
3
5
|
app: "orca_scan",
|
|
4
|
-
propDefinitions: {
|
|
6
|
+
propDefinitions: {
|
|
7
|
+
sheetId: {
|
|
8
|
+
type: "string",
|
|
9
|
+
label: "Sheet ID",
|
|
10
|
+
description: "The ID of the sheet where the row will be created or updated.",
|
|
11
|
+
async options({ page }) {
|
|
12
|
+
const { data } = await this.listSheets({
|
|
13
|
+
params: {
|
|
14
|
+
page,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return data.map(({
|
|
19
|
+
_id: value, name: label,
|
|
20
|
+
}) => ({
|
|
21
|
+
label,
|
|
22
|
+
value,
|
|
23
|
+
}));
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
rowData: {
|
|
27
|
+
type: "object",
|
|
28
|
+
label: "Row Data",
|
|
29
|
+
description: "The data for the new row to be added or updated. To get the fields, use the `Find Row` action to find a row and refer to the JSON output.",
|
|
30
|
+
},
|
|
31
|
+
barcode: {
|
|
32
|
+
type: "string",
|
|
33
|
+
label: "Barcode",
|
|
34
|
+
description: "The barcode value to locate a specific row record. If the barcode is not found, a new row will be created. If the barcode is found, the row will be updated with the data in `Row Data`.",
|
|
35
|
+
optional: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
5
38
|
methods: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
39
|
+
_baseUrl() {
|
|
40
|
+
return "https://api.orcascan.com/v1";
|
|
41
|
+
},
|
|
42
|
+
_getHeaders(headers) {
|
|
43
|
+
return {
|
|
44
|
+
...headers,
|
|
45
|
+
"Authorization": `Bearer ${this.$auth.api_key}`,
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
_makeRequest({
|
|
49
|
+
$ = this, path, ...opts
|
|
50
|
+
}) {
|
|
51
|
+
return axios($, {
|
|
52
|
+
url: this._baseUrl() + path,
|
|
53
|
+
headers: this._getHeaders(),
|
|
54
|
+
...opts,
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
listSheets() {
|
|
58
|
+
return this._makeRequest({
|
|
59
|
+
path: "/sheets",
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
getFields(sheetId) {
|
|
63
|
+
return this._makeRequest({
|
|
64
|
+
path: `/sheets/${sheetId}/fields`,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
getSettings(sheetId) {
|
|
68
|
+
return this._makeRequest({
|
|
69
|
+
path: `/sheets/${sheetId}/settings`,
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
clearSheet(sheetId) {
|
|
73
|
+
return this._makeRequest({
|
|
74
|
+
method: "PUT",
|
|
75
|
+
path: `/sheets/${sheetId}/clear`,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
listRows({
|
|
79
|
+
sheetId, ...opts
|
|
80
|
+
}) {
|
|
81
|
+
return this._makeRequest({
|
|
82
|
+
path: `/sheets/${sheetId}/rows`,
|
|
83
|
+
...opts,
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
getSingleRow(sheetId, rowId) {
|
|
87
|
+
return this._makeRequest({
|
|
88
|
+
path: `/sheets/${sheetId}/rows/${rowId}`,
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
addOrUpdateRow({
|
|
92
|
+
sheetId, rowId, ...opts
|
|
93
|
+
}) {
|
|
94
|
+
const method = rowId
|
|
95
|
+
? "PUT"
|
|
96
|
+
: "POST";
|
|
97
|
+
const path = `/sheets/${sheetId}/rows${rowId
|
|
98
|
+
? `/${rowId}`
|
|
99
|
+
: ""}`;
|
|
100
|
+
return this._makeRequest({
|
|
101
|
+
method,
|
|
102
|
+
path,
|
|
103
|
+
...opts,
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
deleteRow(sheetId, rowId) {
|
|
107
|
+
return this._makeRequest({
|
|
108
|
+
method: "DELETE",
|
|
109
|
+
path: `/sheets/${sheetId}/rows/${rowId}`,
|
|
110
|
+
});
|
|
9
111
|
},
|
|
10
112
|
},
|
|
11
|
-
};
|
|
113
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/orca_scan",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Pipedream Orca Scan Components",
|
|
5
5
|
"main": "orca_scan.app.mjs",
|
|
6
6
|
"keywords": [
|
|
@@ -11,5 +11,8 @@
|
|
|
11
11
|
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@pipedream/platform": "^1.5.1"
|
|
14
17
|
}
|
|
15
18
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
|
|
2
|
+
import orcaScan from "../../orca_scan.app.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
props: {
|
|
6
|
+
orcaScan,
|
|
7
|
+
db: "$.service.db",
|
|
8
|
+
timer: {
|
|
9
|
+
type: "$.interface.timer",
|
|
10
|
+
default: {
|
|
11
|
+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
methods: {
|
|
16
|
+
async startEvent(maxResults = false) {
|
|
17
|
+
const lastInfo = this._getLastInfo();
|
|
18
|
+
const data = await this.getData(maxResults, lastInfo);
|
|
19
|
+
|
|
20
|
+
if (data.length) this._setLastInfo(data[0]);
|
|
21
|
+
|
|
22
|
+
for (const item of data.reverse()) {
|
|
23
|
+
this.$emit(item, this.getEmit(item));
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
hooks: {
|
|
28
|
+
async deploy() {
|
|
29
|
+
await this.startEvent(25);
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
async run() {
|
|
33
|
+
await this.startEvent();
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import common from "../common/base.mjs";
|
|
2
|
+
import sampleEmit from "./test-event.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
...common,
|
|
6
|
+
key: "orca_scan-new-row",
|
|
7
|
+
name: "New Row in Orca Scan Sheet",
|
|
8
|
+
description: "Emit new event when a new row is created in an Orca Scan sheet. [See the documentation](https://orcascan.com/guides/add-barcode-tracking-to-your-system-using-a-rest-api-f09a21c3)",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
type: "source",
|
|
11
|
+
dedupe: "unique",
|
|
12
|
+
props: {
|
|
13
|
+
...common.props,
|
|
14
|
+
sheetId: {
|
|
15
|
+
propDefinition: [
|
|
16
|
+
common.props.orcaScan,
|
|
17
|
+
"sheetId",
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
methods: {
|
|
22
|
+
...common.methods,
|
|
23
|
+
_getLastInfo() {
|
|
24
|
+
return this.db.get("lastDate") || 0;
|
|
25
|
+
},
|
|
26
|
+
_setLastInfo(row) {
|
|
27
|
+
return this.db.set("lastDate", row.date);
|
|
28
|
+
},
|
|
29
|
+
async getData(maxResults = false, lastDate) {
|
|
30
|
+
const { data: rows } = await this.orcaScan.listRows({
|
|
31
|
+
sheetId: this.sheetId,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const sortedRows = rows
|
|
35
|
+
.filter((row) => new Date(row.date) > new Date(lastDate))
|
|
36
|
+
.sort((a, b) => new Date(b.date) - new Date(a.date));
|
|
37
|
+
|
|
38
|
+
if (maxResults && sortedRows.length >= maxResults) sortedRows.length = maxResults;
|
|
39
|
+
return sortedRows;
|
|
40
|
+
},
|
|
41
|
+
getEmit(row) {
|
|
42
|
+
return {
|
|
43
|
+
id: row._id,
|
|
44
|
+
summary: `New row with _id: ${row._id}`,
|
|
45
|
+
ts: row.date,
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
sampleEmit,
|
|
50
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import common from "../common/base.mjs";
|
|
2
|
+
import sampleEmit from "./test-event.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
...common,
|
|
6
|
+
key: "orca_scan-new-sheet",
|
|
7
|
+
name: "New Sheet Created",
|
|
8
|
+
description: "Emit new event when a new sheet is created in Orca Scan. [See the documentation](https://orcascan.com/guides/add-barcode-tracking-to-your-system-using-a-rest-api-f09a21c3)",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
type: "source",
|
|
11
|
+
dedupe: "unique",
|
|
12
|
+
methods: {
|
|
13
|
+
...common.methods,
|
|
14
|
+
_getLastInfo() {
|
|
15
|
+
return this.db.get("lastId") || 0;
|
|
16
|
+
},
|
|
17
|
+
_setLastInfo(row) {
|
|
18
|
+
return this.db.set("lastId", row._id);
|
|
19
|
+
},
|
|
20
|
+
async getData(maxResults = false, lastId) {
|
|
21
|
+
const { data: sheets } = await this.orcaScan.listSheets();
|
|
22
|
+
|
|
23
|
+
let pos = -1;
|
|
24
|
+
let sortedSheets = sheets;
|
|
25
|
+
if (lastId) {
|
|
26
|
+
pos = sheets.findIndex((sheet) => sheet._id == lastId);
|
|
27
|
+
if (pos != -1) sortedSheets = sheets.slice(pos + 1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (maxResults && sortedSheets.length >= maxResults) sortedSheets.length = maxResults;
|
|
31
|
+
return sortedSheets.reverse();
|
|
32
|
+
},
|
|
33
|
+
getEmit(sheet) {
|
|
34
|
+
return {
|
|
35
|
+
id: sheet._id,
|
|
36
|
+
summary: `New Sheet: ${sheet.name}`,
|
|
37
|
+
ts: Date.now(),
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
sampleEmit,
|
|
42
|
+
};
|