@pipedream/orca_scan 0.0.1 → 0.2.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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Overview
2
+
3
+ The Orca Scan API is a gateway to integrate barcode scanning and inventory management capabilities into various workflows. By leveraging the API, you can automate data collection, streamline inventory tracking, and sync your barcode scanning data with other systems. When used on Pipedream, you can merge Orca Scan functionalities with countless other apps, creating custom automation rules, processing data, and managing inventory in real-time. Ideal for inventory management, asset tracking, and data collection automation, the Orca Scan API is a tool that can adapt to a myriad of business needs.
4
+
5
+ # Example Use Cases
6
+
7
+ - **Automate Inventory Updates**: Use the Orca Scan API to update inventory counts in a Google Sheet every time a new item is scanned. This workflow ensures real-time inventory tracking without manual data entry.
8
+
9
+ - **Sync with CRM Systems**: After scanning items using Orca Scan, trigger a workflow on Pipedream to create or update records in a CRM like Salesforce or HubSpot. This keeps customer-related inventory data up-to-date.
10
+
11
+ - **Alerts for Low Stock**: Set up a workflow that monitors inventory levels using the Orca Scan API. When stock for certain items drops below a specified threshold, trigger an alert via email or a messaging app like Slack to prompt restocking.
@@ -0,0 +1,76 @@
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.2",
8
+ annotations: {
9
+ destructiveHint: true,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ orca_scan,
16
+ sheetId: {
17
+ propDefinition: [
18
+ orca_scan,
19
+ "sheetId",
20
+ ],
21
+ },
22
+ rowData: {
23
+ propDefinition: [
24
+ orca_scan,
25
+ "rowData",
26
+ ],
27
+ },
28
+ barcode: {
29
+ propDefinition: [
30
+ orca_scan,
31
+ "barcode",
32
+ ],
33
+ },
34
+ },
35
+ async run({ $ }) {
36
+ let rowId = null;
37
+
38
+ // Check if a row with the given barcode exists
39
+ if (this.barcode) {
40
+ const { data } = await this.orca_scan.listRows({
41
+ sheetId: this.sheetId,
42
+ params: {
43
+ barcode: this.barcode || null,
44
+ },
45
+ });
46
+ if (data.length > 0) {
47
+ const row = data[0];
48
+ // Assume the first row is the one to update
49
+ rowId = row._id;
50
+ for (const [
51
+ key,
52
+ value,
53
+ ] of Object.entries(this.rowData)) {
54
+ row[key] = value;
55
+ }
56
+ this.rowData = row;
57
+ } else {
58
+ this.rowData.barcode = this.barcode;
59
+ }
60
+ }
61
+
62
+ if (!this.rowData.date) this.rowData.date = new Date();
63
+
64
+ // Make the request to add or update the row
65
+ const response = await this.orca_scan.addOrUpdateRow({
66
+ sheetId: this.sheetId,
67
+ data: this.rowData,
68
+ rowId: rowId,
69
+ });
70
+
71
+ $.export("$summary", `Successfully ${rowId
72
+ ? "updated"
73
+ : "added"} row with ID: ${response.data?._id}`);
74
+ return response;
75
+ },
76
+ };
@@ -0,0 +1,41 @@
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.2",
8
+ annotations: {
9
+ destructiveHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ orca_scan,
16
+ sheetId: {
17
+ propDefinition: [
18
+ orca_scan,
19
+ "sheetId",
20
+ ],
21
+ },
22
+ barcode: {
23
+ propDefinition: [
24
+ orca_scan,
25
+ "barcode",
26
+ ],
27
+ optional: true,
28
+ },
29
+ },
30
+ async run({ $ }) {
31
+ const rows = await this.orca_scan.listRows({
32
+ sheetId: this.sheetId,
33
+ params: {
34
+ barcode: this.barcode || null,
35
+ },
36
+ });
37
+
38
+ $.export("$summary", `Successfully found ${rows.data?.length} row(s)`);
39
+ return rows;
40
+ },
41
+ };
@@ -0,0 +1,33 @@
1
+ import orca_scan from "../../orca_scan.app.mjs";
2
+
3
+ export default {
4
+ key: "orca_scan-list-sheet-id-options",
5
+ name: "List Sheet ID Options",
6
+ description: "Retrieves available options for the Sheet ID field.",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: true,
13
+ },
14
+ props: {
15
+ orca_scan,
16
+ page: {
17
+ type: "integer",
18
+ label: "Page",
19
+ description: "The page of results to retrieve.",
20
+ min: 0,
21
+ default: 0,
22
+ },
23
+ },
24
+ async run({ $ }) {
25
+ const options = await orca_scan.propDefinitions.sheetId.options.call(this.orca_scan, {
26
+ page: this.page,
27
+ });
28
+ $.export("$summary", `Successfully retrieved ${options.length} option${options.length === 1
29
+ ? ""
30
+ : "s"}`);
31
+ return options;
32
+ },
33
+ };
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
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
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.1",
3
+ "version": "0.2.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.6.8"
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,7 @@
1
+ export default {
2
+ "barcode": "WS2323",
3
+ "name": "Wooden Socks",
4
+ "location": "52.2019723, 0.1168256",
5
+ "date": "2020-03-16T16:02:45.000Z",
6
+ "_id": "6554e2a74c5cfa00b5e71b3c"
7
+ }
@@ -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
+ };
@@ -0,0 +1,9 @@
1
+ export default {
2
+ "_id": "62a3188f098a6343fe0d9c1b",
3
+ "name": "My sheet",
4
+ "isOwner": true,
5
+ "canAdmin": true,
6
+ "canUpdate": true,
7
+ "canDelete": true,
8
+ "canExport": true
9
+ }