Skip to content

Commit 7e0a32b

Browse files
authored
New Components - axesso_data_service (#15598)
* axesso_data_service init * new components * pnpm-lock.yaml * fix base url
1 parent 5d96e67 commit 7e0a32b

File tree

7 files changed

+320
-7
lines changed

7 files changed

+320
-7
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import axesso from "../../axesso_data_service.app.mjs";
2+
3+
export default {
4+
key: "axesso_data_service-get-product-details",
5+
name: "Get Product Details",
6+
description: "Requests product detail information using Axesso Data Service. [See the documentation](https://axesso.developer.azure-api.net/api-details#api=axesso-amazon-data-service&operation=product-details)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
axesso,
11+
url: {
12+
propDefinition: [
13+
axesso,
14+
"url",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.axesso.getProductDetails({
20+
$,
21+
params: {
22+
url: this.url,
23+
psc: 1,
24+
},
25+
});
26+
$.export("$summary", `Retrieved product details for URL: ${this.url}`);
27+
return response;
28+
},
29+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import axesso from "../../axesso_data_service.app.mjs";
2+
3+
export default {
4+
key: "axesso_data_service-list-reviews",
5+
name: "List Reviews",
6+
description: "Lists reviews for an Amazon product using Axesso Data Service. [See the documentation](https://axesso.developer.azure-api.net/api-details#api=axesso-amazon-data-service&operation=reviews)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
axesso,
11+
url: {
12+
propDefinition: [
13+
axesso,
14+
"url",
15+
],
16+
},
17+
domainCode: {
18+
propDefinition: [
19+
axesso,
20+
"domainCode",
21+
],
22+
},
23+
sortBy: {
24+
propDefinition: [
25+
axesso,
26+
"sortBy",
27+
],
28+
},
29+
maxResults: {
30+
propDefinition: [
31+
axesso,
32+
"maxResults",
33+
],
34+
},
35+
},
36+
async run({ $ }) {
37+
const { asin } = await this.axesso.getProductDetails({
38+
$,
39+
params: {
40+
url: this.url,
41+
psc: 1,
42+
},
43+
});
44+
45+
const results = await this.axesso.paginate({
46+
fn: this.axesso.lookupReviews,
47+
args: {
48+
$,
49+
params: {
50+
asin,
51+
domainCode: this.domainCode,
52+
sortBy: this.sortBy,
53+
},
54+
},
55+
resourceKey: "reviews",
56+
max: this.maxResults,
57+
});
58+
59+
const reviews = [];
60+
for await (const review of results) {
61+
reviews.push(review);
62+
}
63+
64+
$.export("$summary", `Fetched reviews for product with ASIN: ${asin}`);
65+
return reviews;
66+
},
67+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import axesso from "../../axesso_data_service.app.mjs";
2+
3+
export default {
4+
key: "axesso_data_service-search-products",
5+
name: "Search Products",
6+
description: "Search Amazon products by keyword using Axesso Data Service. [See the documentation](https://axesso.developer.azure-api.net/api-details#api=axesso-amazon-data-service&operation=search-products)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
axesso,
11+
keyword: {
12+
type: "string",
13+
label: "Keyword",
14+
description: "The keyword to search for products",
15+
},
16+
domainCode: {
17+
propDefinition: [
18+
axesso,
19+
"domainCode",
20+
],
21+
},
22+
sortBy: {
23+
propDefinition: [
24+
axesso,
25+
"sortBy",
26+
],
27+
},
28+
category: {
29+
type: "string",
30+
label: "Category",
31+
description: "Valid category list can found on the amazon website on the search selection box. Important: If the passed category is not a valid amazon category, the response will be empty",
32+
optional: true,
33+
},
34+
maxResults: {
35+
propDefinition: [
36+
axesso,
37+
"maxResults",
38+
],
39+
},
40+
},
41+
async run({ $ }) {
42+
const results = this.axesso.paginate({
43+
fn: this.axesso.searchProducts,
44+
args: {
45+
$,
46+
params: {
47+
keyword: this.keyword,
48+
domainCode: this.domainCode,
49+
sortBy: this.sortBy,
50+
category: this.category,
51+
},
52+
},
53+
resourceKey: "searchProductDetails",
54+
max: this.maxResults,
55+
});
56+
57+
const products = [];
58+
for await (const product of results) {
59+
products.push(product);
60+
}
61+
62+
$.export("$summary", `Found ${products.length} product${products.length === 1
63+
? ""
64+
: "s"} for keyword '${this.keyword}'`);
65+
return products;
66+
},
67+
};
Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,103 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
import Bottleneck from "bottleneck";
4+
const limiter = new Bottleneck({
5+
minTime: 6000, // 10 requests per minute (1 request every 6000ms)
6+
maxConcurrent: 1,
7+
});
8+
const axiosRateLimiter = limiter.wrap(axios);
9+
110
export default {
211
type: "app",
312
app: "axesso_data_service",
4-
propDefinitions: {},
13+
propDefinitions: {
14+
url: {
15+
type: "string",
16+
label: "Product URL",
17+
description: "The URL of the Amazon product to lookup",
18+
},
19+
domainCode: {
20+
type: "string",
21+
label: "Domain Code",
22+
description: "The amazon marketplace domain code",
23+
options: constants.DOMAIN_CODES,
24+
},
25+
sortBy: {
26+
type: "string",
27+
label: "Sort By",
28+
description: "The sort option for the search or reviews",
29+
options: constants.SORT_OPTIONS,
30+
optional: true,
31+
},
32+
maxResults: {
33+
type: "integer",
34+
label: "Max Results",
35+
description: "The maximum number of results to return. Defaults to `25`",
36+
default: 25,
37+
optional: true,
38+
},
39+
},
540
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
41+
_baseUrl() {
42+
return "https://api.axesso.de/amz";
43+
},
44+
_makeRequest({
45+
$ = this,
46+
path,
47+
...opts
48+
}) {
49+
return axiosRateLimiter($, {
50+
url: `${this._baseUrl()}${path}`,
51+
headers: {
52+
"axesso-api-key": this.$auth.api_key,
53+
},
54+
...opts,
55+
});
56+
},
57+
getProductDetails(opts = {}) {
58+
return this._makeRequest({
59+
path: "/amazon-lookup-product",
60+
...opts,
61+
});
62+
},
63+
searchProducts(opts = {}) {
64+
return this._makeRequest({
65+
path: "/amazon-search-by-keyword-asin",
66+
...opts,
67+
});
68+
},
69+
lookupReviews(opts = {}) {
70+
return this._makeRequest({
71+
path: "/amazon-lookup-reviews",
72+
...opts,
73+
});
74+
},
75+
async *paginate({
76+
fn, args, resourceKey, max,
77+
}) {
78+
args = {
79+
...args,
80+
params: {
81+
...args?.params,
82+
page: 1,
83+
},
84+
};
85+
let hasMore = true;
86+
let count = 0;
87+
while (hasMore) {
88+
const response = await fn(args);
89+
const items = response[resourceKey];
90+
for (const item of items) {
91+
yield item;
92+
if (max && ++count >= max) {
93+
return;
94+
}
95+
}
96+
if (!items?.length) {
97+
hasMore = false;
98+
}
99+
args.params.page++;
100+
}
9101
},
10102
},
11103
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const DOMAIN_CODES = [
2+
{
3+
label: "US",
4+
value: "com",
5+
},
6+
{
7+
label: "Canada",
8+
value: "ca",
9+
},
10+
{
11+
label: "Mexico",
12+
value: "com.mx",
13+
},
14+
{
15+
label: "UK",
16+
value: "co.uk",
17+
},
18+
{
19+
label: "France",
20+
value: "fr",
21+
},
22+
{
23+
label: "Germany",
24+
value: "de",
25+
},
26+
{
27+
label: "Italy",
28+
value: "it",
29+
},
30+
{
31+
label: "Spain",
32+
value: "es",
33+
},
34+
];
35+
36+
const SORT_OPTIONS = [
37+
"relevanceblender",
38+
"price-asc-rank",
39+
"price-desc-rank",
40+
"review-rank",
41+
"date-desc-rank",
42+
];
43+
44+
export default {
45+
DOMAIN_CODES,
46+
SORT_OPTIONS,
47+
};

components/axesso_data_service/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/axesso_data_service",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Axesso Data Service - Amazon Components",
55
"main": "axesso_data_service.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3",
17+
"bottleneck": "^2.19.5"
1418
}
15-
}
19+
}

pnpm-lock.yaml

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)