Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import app from "../../barcode_lookup.app.mjs";
import { parseObject } from "../../common/utils.mjs";

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",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
app,
barcodes: {
type: "string[]",
label: "Barcodes",
description: "The barcodes to search for. You can also use a partial barcode followed by an asterisk (*).",
},
},
async run({ $ }) {
const response = await this.app.searchProducts({
$,
params: {
barcode: parseObject(this.barcodes)?.join(","),
},
});
$.export("$summary", "Successfully retrieved products by barcodes");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import app from "../../barcode_lookup.app.mjs";

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",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
app,
barcode: {
type: "string",
label: "Barcode",
description: "The barcode to search for. You can also use a partial barcode (6 digits minimum) followed by an asterisk (*).",
},
},
async run({ $ }) {
const response = await this.app.searchProducts({
$,
params: {
barcode: this.barcode,
},
});
$.export("$summary", "Successfully retrieved product by barcode");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import app from "../../barcode_lookup.app.mjs";

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",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
app,
mpn: {
type: "string",
label: "MPN",
description: "MPN parameter is the manufacturer part number. `E.g. **LXCF9407**`",
optional: true,
},
asin: {
type: "string",
label: "ASIN",
description: "ASIN parameter is the Amazon Standard Identification Number. `E.g. **B079L4WR4T**`",
optional: true,
},
title: {
type: "string",
label: "Title",
description: "Search by product name (title) for any item. `E.g. **Red Running Shoes**`",
optional: true,
},
category: {
type: "string",
label: "Category",
description: "Search by category - based on [Google's product taxonomy](https://www.google.com/basepages/producttype/taxonomy.en-US.txt). `E.g. **Home & Garden > Decor**`",
optional: true,
},
manufacturer: {
type: "string",
label: "Manufacturer",
description: "search by manufacturer - use double quotes (\"\") around value for an exact match. `E.g. **\"Samsung\"**`",
optional: true,
},
brand: {
type: "string",
label: "Brand",
description: "Search by brand - use double quotes (\"\") around value for an exact match. `E.g. **\"Calvin Klein\"**`",
optional: true,
},
search: {
type: "string",
label: "Search",
description: "Query all the search fields including title, category, brand and MPN. `E.g. **\"Air Jordan Red Shoes Size 40\"**`",
optional: true,
},
geo: {
type: "string",
label: "Geo",
description: "Filter online store results by geographical location",
options: [
"us",
"gb",
"ca",
"eu",
],
optional: true,
},
maxResults: {
type: "integer",
label: "Max Results",
description: "The maximum number of results to return",
optional: true,
},
},
async run({ $ }) {
try {
const response = await this.app.paginate({
$,
fn: this.app.searchProducts,
maxResults: this.maxResults,
params: {
mpn: this.mpn,
asin: this.asin,
title: this.title,
category: this.category,
manufacturer: this.manufacturer,
brand: this.brand,
search: this.search,
metadata: "y",
geo: this.geo,
formatted: "y",
},
});

const responseArray = [];
for await (const item of response) {
responseArray.push(item);
}

$.export("$summary", `Successfully retrieved ${responseArray.length} products`);
return responseArray;
} catch (error) {
$.export("$summary", "Successfully retrieved 0 products");
return [];
}
},
};
53 changes: 50 additions & 3 deletions components/barcode_lookup/barcode_lookup.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,58 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "barcode_lookup",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.barcodelookup.com/v3";
},
_params(params = {}) {
return {
...params,
key: `${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, params, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
params: this._params(params),
...opts,
});
},
searchProducts(opts = {}) {
return this._makeRequest({
path: "/products",
...opts,
});
},
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);
},
},
};
24 changes: 24 additions & 0 deletions components/barcode_lookup/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
5 changes: 4 additions & 1 deletion components/barcode_lookup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/barcode_lookup",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Barcode Lookup Components",
"main": "barcode_lookup.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
17 changes: 10 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading