diff --git a/components/barcode_lookup/actions/batch-barcode-lookup/batch-barcode-lookup.mjs b/components/barcode_lookup/actions/batch-barcode-lookup/batch-barcode-lookup.mjs index 805b67cced699..169c98ad60192 100644 --- a/components/barcode_lookup/actions/batch-barcode-lookup/batch-barcode-lookup.mjs +++ b/components/barcode_lookup/actions/batch-barcode-lookup/batch-barcode-lookup.mjs @@ -5,7 +5,7 @@ export default { key: "barcode_lookup-batch-barcode-lookup", name: "Batch Barcode Lookup", description: "Get multiple products by barcode. [See the documentation](https://www.barcodelookup.com/api-documentation)", - version: "0.0.1", + version: "0.0.2", type: "action", annotations: { destructiveHint: false, @@ -21,7 +21,7 @@ export default { }, }, async run({ $ }) { - const response = await this.app.searchProducts({ + const response = await this.app.getProducts({ $, params: { barcode: parseObject(this.barcodes)?.join(","), diff --git a/components/barcode_lookup/actions/get-product-by-barcode/get-product-by-barcode.mjs b/components/barcode_lookup/actions/get-product-by-barcode/get-product-by-barcode.mjs index 111c87875faae..7e577562a565f 100644 --- a/components/barcode_lookup/actions/get-product-by-barcode/get-product-by-barcode.mjs +++ b/components/barcode_lookup/actions/get-product-by-barcode/get-product-by-barcode.mjs @@ -4,7 +4,7 @@ export default { key: "barcode_lookup-get-product-by-barcode", name: "Get Product by Barcode", description: "Get a product by barcode. [See the documentation](https://www.barcodelookup.com/api-documentation)", - version: "0.0.1", + version: "0.0.2", type: "action", annotations: { destructiveHint: false, @@ -20,7 +20,7 @@ export default { }, }, async run({ $ }) { - const response = await this.app.searchProducts({ + const response = await this.app.getProducts({ $, params: { barcode: this.barcode, diff --git a/components/barcode_lookup/actions/get-products/get-products.mjs b/components/barcode_lookup/actions/get-products/get-products.mjs new file mode 100644 index 0000000000000..9d33dbf0860cf --- /dev/null +++ b/components/barcode_lookup/actions/get-products/get-products.mjs @@ -0,0 +1,82 @@ +import app from "../../barcode_lookup.app.mjs"; + +export default { + key: "barcode_lookup-get-products", + name: "Get Products", + description: "Retrieve products details by barcode, MPN, ASIN, or search terms. [See the documentation](https://www.barcodelookup.com/api-documentation#endpoints)", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + type: "action", + props: { + app, + barcode: { + propDefinition: [ + app, + "barcode", + ], + }, + mpn: { + propDefinition: [ + app, + "mpn", + ], + }, + asin: { + propDefinition: [ + app, + "asin", + ], + }, + title: { + propDefinition: [ + app, + "title", + ], + }, + category: { + propDefinition: [ + app, + "category", + ], + }, + manufacturer: { + propDefinition: [ + app, + "manufacturer", + ], + }, + brand: { + propDefinition: [ + app, + "brand", + ], + }, + search: { + propDefinition: [ + app, + "search", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getProducts({ + $, + params: { + barcode: this.barcode, + mpn: this.mpn, + asin: this.asin, + title: this.title, + category: this.category, + manufacturer: this.manufacturer, + brand: this.brand, + search: this.search, + }, + }); + $.export("$summary", "Successfully retrieved " + response.products.length + " products"); + return response; + }, +}; diff --git a/components/barcode_lookup/actions/get-rate-limits/get-rate-limits.mjs b/components/barcode_lookup/actions/get-rate-limits/get-rate-limits.mjs new file mode 100644 index 0000000000000..f27ead99c23e4 --- /dev/null +++ b/components/barcode_lookup/actions/get-rate-limits/get-rate-limits.mjs @@ -0,0 +1,24 @@ +import app from "../../barcode_lookup.app.mjs"; + +export default { + key: "barcode_lookup-get-rate-limits", + name: "Get Rate Limits", + description: "Retrieve the current API rate limits for your account. [See the documentation](https://www.barcodelookup.com/api-documentation#endpoints)", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.getRateLimits({ + $, + }); + $.export("$summary", "Successfully retrieved the account rate limits"); + return response; + }, +}; diff --git a/components/barcode_lookup/actions/search-products-by-parameters/search-products-by-parameters.mjs b/components/barcode_lookup/actions/search-products-by-parameters/search-products-by-parameters.mjs index 3f44af0dca496..a0a47cc37138b 100644 --- a/components/barcode_lookup/actions/search-products-by-parameters/search-products-by-parameters.mjs +++ b/components/barcode_lookup/actions/search-products-by-parameters/search-products-by-parameters.mjs @@ -4,7 +4,7 @@ export default { key: "barcode_lookup-search-products-by-parameters", name: "Search Products by Parameters", description: "Search for products by parameters. [See the documentation](https://www.barcodelookup.com/api-documentation)", - version: "0.0.1", + version: "0.0.2", type: "action", annotations: { destructiveHint: false, @@ -78,7 +78,7 @@ export default { try { const response = await this.app.paginate({ $, - fn: this.app.searchProducts, + fn: this.app.getProducts, maxResults: this.maxResults, params: { mpn: this.mpn, diff --git a/components/barcode_lookup/barcode_lookup.app.mjs b/components/barcode_lookup/barcode_lookup.app.mjs index 24d686ad8386e..9083c248aae3c 100644 --- a/components/barcode_lookup/barcode_lookup.app.mjs +++ b/components/barcode_lookup/barcode_lookup.app.mjs @@ -3,56 +3,87 @@ import { axios } from "@pipedream/platform"; export default { type: "app", app: "barcode_lookup", - propDefinitions: {}, + propDefinitions: { + barcode: { + type: "string", + label: "Barcode", + description: "Barcode to search, must be 7, 8, 10, 11, 12, 13 or 14 digits long, e.g. `865694301167`", + optional: true, + }, + mpn: { + type: "string", + label: "MPN", + description: "Manufacturer Part Number of the product, i.e: `LXCF9407`", + optional: true, + }, + asin: { + type: "string", + label: "ASIN", + description: "Amazon Standard Identification Number of the product, e.g. `B079L4WR4T`", + optional: true, + }, + title: { + type: "string", + label: "Title", + description: "Product title or name, e.g. `Red Running Shoes`", + optional: true, + }, + category: { + type: "string", + label: "Category", + description: "Category or type of the product, e.g. `Home & Garden > Decor`", + optional: true, + }, + manufacturer: { + type: "string", + label: "Manufacturer", + description: "Name of the product manufacturer, e.g. `Samsung`", + optional: true, + }, + brand: { + type: "string", + label: "Brand", + description: "Brand associated with the product, e.g. `Calvin Klein`", + optional: true, + }, + search: { + type: "string", + label: "Search", + description: "General search term for products, e.g. `Air Jordan Red Shoes Size 40`", + optional: true, + }, + }, methods: { _baseUrl() { return "https://api.barcodelookup.com/v3"; }, - _params(params = {}) { - return { - ...params, - key: `${this.$auth.api_key}`, - }; - }, - _makeRequest({ - $ = this, params, path, ...opts - }) { + async _makeRequest(opts = {}) { + const { + $ = this, + path, + params, + ...otherOpts + } = opts; return axios($, { + ...otherOpts, url: this._baseUrl() + path, - params: this._params(params), - ...opts, + params: { + key: `${this.$auth.api_key}`, + ...params, + }, }); }, - searchProducts(opts = {}) { + async getProducts(args = {}) { return this._makeRequest({ path: "/products", - ...opts, + ...args, }); }, - async *paginate({ - fn, params = {}, maxResults = null, ...opts - }) { - let hasMore = false; - let count = 0; - let page = 0; - - do { - params.page = ++page; - const { products: data } = await fn({ - params, - ...opts, - }); - for (const d of data) { - yield d; - - if (maxResults && ++count === maxResults) { - return count; - } - } - - hasMore = data?.length; - - } while (hasMore); + async getRateLimits(args = {}) { + return this._makeRequest({ + path: "/rate-limits", + ...args, + }); }, }, }; diff --git a/components/barcode_lookup/package.json b/components/barcode_lookup/package.json index 7679b14de04b4..f6cd910ff7ef3 100644 --- a/components/barcode_lookup/package.json +++ b/components/barcode_lookup/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/barcode_lookup", - "version": "0.1.0", + "version": "0.2.0", "description": "Pipedream Barcode Lookup Components", "main": "barcode_lookup.app.mjs", "keywords": [