n8n-nodes-amazon-creator-api 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/LICENSE.md +21 -0
- package/README.md +120 -0
- package/dist/credentials/AmazonCreatorsApi.credentials.d.ts +7 -0
- package/dist/credentials/AmazonCreatorsApi.credentials.js +90 -0
- package/dist/credentials/AmazonCreatorsApi.credentials.js.map +1 -0
- package/dist/nodes/AmazonCreatorsApi/AmazonCreatorsApi.node.d.ts +13 -0
- package/dist/nodes/AmazonCreatorsApi/AmazonCreatorsApi.node.js +656 -0
- package/dist/nodes/AmazonCreatorsApi/AmazonCreatorsApi.node.js.map +1 -0
- package/dist/nodes/AmazonCreatorsApi/AmazonCreatorsPriceWatchTrigger.node.d.ts +5 -0
- package/dist/nodes/AmazonCreatorsApi/AmazonCreatorsPriceWatchTrigger.node.js +128 -0
- package/dist/nodes/AmazonCreatorsApi/AmazonCreatorsPriceWatchTrigger.node.js.map +1 -0
- package/dist/nodes/AmazonCreatorsApi/AmazonCreatorsSearchWatchTrigger.node.d.ts +5 -0
- package/dist/nodes/AmazonCreatorsApi/AmazonCreatorsSearchWatchTrigger.node.js +151 -0
- package/dist/nodes/AmazonCreatorsApi/AmazonCreatorsSearchWatchTrigger.node.js.map +1 -0
- package/dist/nodes/AmazonCreatorsApi/GenericFunctions.d.ts +19 -0
- package/dist/nodes/AmazonCreatorsApi/GenericFunctions.js +136 -0
- package/dist/nodes/AmazonCreatorsApi/GenericFunctions.js.map +1 -0
- package/dist/nodes/AmazonCreatorsApi/amazon.svg +1 -0
- package/dist/nodes/AmazonCreatorsApi/shared.d.ts +24 -0
- package/dist/nodes/AmazonCreatorsApi/shared.js +265 -0
- package/dist/nodes/AmazonCreatorsApi/shared.js.map +1 -0
- package/index.js +4 -0
- package/package.json +64 -0
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmazonCreatorsApi = void 0;
|
|
4
|
+
const GenericFunctions_1 = require("./GenericFunctions");
|
|
5
|
+
const shared_1 = require("./shared");
|
|
6
|
+
const ITEM_OPS = ['getItems', 'searchItems', 'getVariations'];
|
|
7
|
+
class AmazonCreatorsApi {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.description = {
|
|
10
|
+
displayName: 'Amazon Creators API',
|
|
11
|
+
name: 'amazonCreatorsApi',
|
|
12
|
+
icon: 'file:amazon.svg',
|
|
13
|
+
group: ['transform'],
|
|
14
|
+
version: 1,
|
|
15
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
16
|
+
description: 'Interact with the Amazon Creators API (successor to PA-API 5.0)',
|
|
17
|
+
defaults: {
|
|
18
|
+
name: 'Amazon Creators API',
|
|
19
|
+
color: '#FF9900',
|
|
20
|
+
},
|
|
21
|
+
usableAsTool: true,
|
|
22
|
+
inputs: ['main'],
|
|
23
|
+
outputs: '={{ $parameter["splitErrors"] ? [{ "type": "main", "displayName": "Data" }, { "type": "main", "displayName": "Errors" }] : [{ "type": "main", "displayName": "Data" }] }}',
|
|
24
|
+
credentials: [
|
|
25
|
+
{
|
|
26
|
+
name: 'amazonCreatorsApi',
|
|
27
|
+
required: true,
|
|
28
|
+
testedBy: 'creatorsApiCredentialTest',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
properties: [
|
|
32
|
+
{
|
|
33
|
+
displayName: 'Operation',
|
|
34
|
+
name: 'operation',
|
|
35
|
+
type: 'options',
|
|
36
|
+
noDataExpression: true,
|
|
37
|
+
options: [
|
|
38
|
+
{
|
|
39
|
+
name: 'Get Items',
|
|
40
|
+
value: 'getItems',
|
|
41
|
+
description: 'Get item attributes by ASIN',
|
|
42
|
+
action: 'Get items by ASIN',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'Search Items',
|
|
46
|
+
value: 'searchItems',
|
|
47
|
+
description: 'Search for items on Amazon',
|
|
48
|
+
action: 'Search for items',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'Get Variations',
|
|
52
|
+
value: 'getVariations',
|
|
53
|
+
description: 'Get variations (size, color, etc.) of an ASIN',
|
|
54
|
+
action: 'Get variations of an ASIN',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'Get Browse Nodes',
|
|
58
|
+
value: 'getBrowseNodes',
|
|
59
|
+
description: 'Get browse node information and traverse the category hierarchy',
|
|
60
|
+
action: 'Get browse nodes',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
default: 'getItems',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
displayName: 'Partner Tag',
|
|
67
|
+
name: 'partnerTag',
|
|
68
|
+
type: 'string',
|
|
69
|
+
default: '',
|
|
70
|
+
description: 'Associate/Partner Tag. Leave empty to use the credential default.',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
displayName: 'Marketplace',
|
|
74
|
+
name: 'marketplace',
|
|
75
|
+
type: 'options',
|
|
76
|
+
options: shared_1.MARKETPLACE_OPTIONS_WITH_DEFAULT,
|
|
77
|
+
default: '',
|
|
78
|
+
description: 'Target Amazon marketplace. Leave on default to use the credential value.',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
displayName: 'Item IDs',
|
|
82
|
+
name: 'itemIds',
|
|
83
|
+
type: 'string',
|
|
84
|
+
required: true,
|
|
85
|
+
displayOptions: { show: { operation: ['getItems'] } },
|
|
86
|
+
default: '',
|
|
87
|
+
placeholder: 'B0199980K4,B000HZD168',
|
|
88
|
+
description: 'Comma-separated list of item identifiers. More than 10 are automatically split into batched requests.',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
displayName: 'Item ID Type',
|
|
92
|
+
name: 'itemIdType',
|
|
93
|
+
type: 'options',
|
|
94
|
+
displayOptions: { show: { operation: ['getItems'] } },
|
|
95
|
+
options: [{ name: 'ASIN', value: 'ASIN' }],
|
|
96
|
+
default: 'ASIN',
|
|
97
|
+
description: 'The type of item identifier used in Item IDs',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
displayName: 'Condition',
|
|
101
|
+
name: 'condition',
|
|
102
|
+
type: 'options',
|
|
103
|
+
displayOptions: { show: { operation: ['getItems', 'getVariations'] } },
|
|
104
|
+
options: shared_1.CONDITION_OPTIONS,
|
|
105
|
+
default: 'Any',
|
|
106
|
+
description: 'Filter offers by condition',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
displayName: 'Keywords',
|
|
110
|
+
name: 'keywords',
|
|
111
|
+
type: 'string',
|
|
112
|
+
displayOptions: { show: { operation: ['searchItems'] } },
|
|
113
|
+
default: '',
|
|
114
|
+
description: 'Search query. At least one of Keywords, Actor, Artist, Author, Brand or Title is required.',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
displayName: 'Search Index (Category)',
|
|
118
|
+
name: 'searchIndex',
|
|
119
|
+
type: 'string',
|
|
120
|
+
displayOptions: { show: { operation: ['searchItems'] } },
|
|
121
|
+
default: 'All',
|
|
122
|
+
description: 'Product category to search in. Values differ by marketplace (e.g. Electronics, Books). Defaults to All.',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
displayName: 'Return All',
|
|
126
|
+
name: 'returnAll',
|
|
127
|
+
type: 'boolean',
|
|
128
|
+
displayOptions: { show: { operation: ['searchItems', 'getVariations'] } },
|
|
129
|
+
default: false,
|
|
130
|
+
description: 'Whether to return all results by paging through the API, up to a limit',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
displayName: 'Limit',
|
|
134
|
+
name: 'limit',
|
|
135
|
+
type: 'number',
|
|
136
|
+
typeOptions: { minValue: 1 },
|
|
137
|
+
displayOptions: { show: { operation: ['searchItems', 'getVariations'], returnAll: [true] } },
|
|
138
|
+
default: 50,
|
|
139
|
+
description: 'Max number of results to return',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
displayName: 'Item Count (Page Size)',
|
|
143
|
+
name: 'itemCount',
|
|
144
|
+
type: 'number',
|
|
145
|
+
typeOptions: { minValue: 1, maxValue: 10 },
|
|
146
|
+
displayOptions: { show: { operation: ['searchItems'] } },
|
|
147
|
+
default: 10,
|
|
148
|
+
description: 'Number of items per page (1-10)',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
displayName: 'Item Page',
|
|
152
|
+
name: 'itemPage',
|
|
153
|
+
type: 'number',
|
|
154
|
+
typeOptions: { minValue: 1, maxValue: 10 },
|
|
155
|
+
displayOptions: { show: { operation: ['searchItems'], returnAll: [false] } },
|
|
156
|
+
default: 1,
|
|
157
|
+
description: 'Page of results to return (1-10)',
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
displayName: 'Additional Fields',
|
|
161
|
+
name: 'searchAdditionalFields',
|
|
162
|
+
type: 'collection',
|
|
163
|
+
placeholder: 'Add Field',
|
|
164
|
+
default: {},
|
|
165
|
+
displayOptions: { show: { operation: ['searchItems'] } },
|
|
166
|
+
options: [
|
|
167
|
+
{ displayName: 'Actor', name: 'actor', type: 'string', default: '' },
|
|
168
|
+
{ displayName: 'Artist', name: 'artist', type: 'string', default: '' },
|
|
169
|
+
{ displayName: 'Author', name: 'author', type: 'string', default: '' },
|
|
170
|
+
{
|
|
171
|
+
displayName: 'Availability',
|
|
172
|
+
name: 'availability',
|
|
173
|
+
type: 'options',
|
|
174
|
+
options: shared_1.AVAILABILITY_OPTIONS,
|
|
175
|
+
default: 'Available',
|
|
176
|
+
},
|
|
177
|
+
{ displayName: 'Brand', name: 'brand', type: 'string', default: '' },
|
|
178
|
+
{
|
|
179
|
+
displayName: 'Browse Node ID',
|
|
180
|
+
name: 'browseNodeId',
|
|
181
|
+
type: 'string',
|
|
182
|
+
default: '',
|
|
183
|
+
description: 'Restrict the search to a specific browse node (category) ID',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
displayName: 'Condition',
|
|
187
|
+
name: 'condition',
|
|
188
|
+
type: 'options',
|
|
189
|
+
options: shared_1.CONDITION_OPTIONS,
|
|
190
|
+
default: 'Any',
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
displayName: 'Delivery Flags',
|
|
194
|
+
name: 'deliveryFlags',
|
|
195
|
+
type: 'multiOptions',
|
|
196
|
+
options: shared_1.DELIVERY_FLAGS_OPTIONS,
|
|
197
|
+
default: [],
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
displayName: 'Max Price',
|
|
201
|
+
name: 'maxPrice',
|
|
202
|
+
type: 'number',
|
|
203
|
+
typeOptions: { minValue: 0 },
|
|
204
|
+
default: 0,
|
|
205
|
+
description: 'Max offer price in the lowest currency denomination (e.g. 3241 = $32.41 in the US)',
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
displayName: 'Min Price',
|
|
209
|
+
name: 'minPrice',
|
|
210
|
+
type: 'number',
|
|
211
|
+
typeOptions: { minValue: 0 },
|
|
212
|
+
default: 0,
|
|
213
|
+
description: 'Min offer price in the lowest currency denomination (e.g. 3241 = $32.41 in the US)',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
displayName: 'Min Reviews Rating',
|
|
217
|
+
name: 'minReviewsRating',
|
|
218
|
+
type: 'number',
|
|
219
|
+
typeOptions: { minValue: 1, maxValue: 4 },
|
|
220
|
+
default: 0,
|
|
221
|
+
description: 'Filter to items with a customer review rating above this value (1-4)',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
displayName: 'Min Saving Percent',
|
|
225
|
+
name: 'minSavingPercent',
|
|
226
|
+
type: 'number',
|
|
227
|
+
typeOptions: { minValue: 1, maxValue: 99 },
|
|
228
|
+
default: 0,
|
|
229
|
+
description: 'Filter to items with an offer saving above this percentage (1-99)',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
displayName: 'Sort By',
|
|
233
|
+
name: 'sortBy',
|
|
234
|
+
type: 'options',
|
|
235
|
+
options: shared_1.SORT_BY_OPTIONS,
|
|
236
|
+
default: 'Relevance',
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
displayName: 'Title',
|
|
240
|
+
name: 'title',
|
|
241
|
+
type: 'string',
|
|
242
|
+
default: '',
|
|
243
|
+
description: 'Title associated with the item (a subset of a Keywords search)',
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
displayName: 'ASIN',
|
|
249
|
+
name: 'asin',
|
|
250
|
+
type: 'string',
|
|
251
|
+
required: true,
|
|
252
|
+
displayOptions: { show: { operation: ['getVariations'] } },
|
|
253
|
+
default: '',
|
|
254
|
+
description: 'Parent or child ASIN to get variations for',
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
displayName: 'Variation Count (Page Size)',
|
|
258
|
+
name: 'variationCount',
|
|
259
|
+
type: 'number',
|
|
260
|
+
typeOptions: { minValue: 1, maxValue: 10 },
|
|
261
|
+
displayOptions: { show: { operation: ['getVariations'] } },
|
|
262
|
+
default: 10,
|
|
263
|
+
description: 'Number of variations per page (1-10)',
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
displayName: 'Variation Page',
|
|
267
|
+
name: 'variationPage',
|
|
268
|
+
type: 'number',
|
|
269
|
+
typeOptions: { minValue: 1 },
|
|
270
|
+
displayOptions: { show: { operation: ['getVariations'], returnAll: [false] } },
|
|
271
|
+
default: 1,
|
|
272
|
+
description: 'Page of variations to return',
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
displayName: 'Browse Node IDs',
|
|
276
|
+
name: 'browseNodeIds',
|
|
277
|
+
type: 'string',
|
|
278
|
+
required: true,
|
|
279
|
+
displayOptions: { show: { operation: ['getBrowseNodes'] } },
|
|
280
|
+
default: '',
|
|
281
|
+
placeholder: '283155,3040',
|
|
282
|
+
description: 'Comma-separated list of Browse Node IDs. More than 10 are automatically split into batched requests.',
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
displayName: 'Resources',
|
|
286
|
+
name: 'browseNodeResources',
|
|
287
|
+
type: 'multiOptions',
|
|
288
|
+
displayOptions: { show: { operation: ['getBrowseNodes'] } },
|
|
289
|
+
options: shared_1.BROWSE_NODE_RESOURCES,
|
|
290
|
+
default: ['browseNodes.ancestor', 'browseNodes.children'],
|
|
291
|
+
description: 'Which data to return for each browse node',
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
displayName: 'Resource Preset',
|
|
295
|
+
name: 'resourcePreset',
|
|
296
|
+
type: 'options',
|
|
297
|
+
displayOptions: { show: { operation: ITEM_OPS } },
|
|
298
|
+
options: shared_1.RESOURCE_PRESET_OPTIONS,
|
|
299
|
+
default: 'custom',
|
|
300
|
+
description: 'Quick-select a set of resources, or choose Custom to pick individually',
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
displayName: 'Resources',
|
|
304
|
+
name: 'resourcesGetItems',
|
|
305
|
+
type: 'multiOptions',
|
|
306
|
+
displayOptions: { show: { operation: ['getItems'], resourcePreset: ['custom'] } },
|
|
307
|
+
options: shared_1.ITEM_RESOURCES,
|
|
308
|
+
default: ['itemInfo.title', 'images.primary.large', 'offersV2.listings.price'],
|
|
309
|
+
description: 'Which data to return for each item',
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
displayName: 'Resources',
|
|
313
|
+
name: 'resourcesSearchItems',
|
|
314
|
+
type: 'multiOptions',
|
|
315
|
+
displayOptions: { show: { operation: ['searchItems'], resourcePreset: ['custom'] } },
|
|
316
|
+
options: shared_1.SEARCH_RESOURCES,
|
|
317
|
+
default: ['itemInfo.title', 'images.primary.large', 'offersV2.listings.price'],
|
|
318
|
+
description: 'Which data to return for each item',
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
displayName: 'Resources',
|
|
322
|
+
name: 'resourcesGetVariations',
|
|
323
|
+
type: 'multiOptions',
|
|
324
|
+
displayOptions: { show: { operation: ['getVariations'], resourcePreset: ['custom'] } },
|
|
325
|
+
options: shared_1.VARIATION_RESOURCES,
|
|
326
|
+
default: [
|
|
327
|
+
'itemInfo.title',
|
|
328
|
+
'offersV2.listings.price',
|
|
329
|
+
'variationSummary.variationDimension',
|
|
330
|
+
],
|
|
331
|
+
description: 'Which data to return for each variation',
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
displayName: 'Languages of Preference',
|
|
335
|
+
name: 'languagesOfPreference',
|
|
336
|
+
type: 'multiOptions',
|
|
337
|
+
typeOptions: {
|
|
338
|
+
loadOptionsMethod: 'getLanguages',
|
|
339
|
+
loadOptionsDependsOn: ['marketplace'],
|
|
340
|
+
},
|
|
341
|
+
default: [],
|
|
342
|
+
description: 'Response language(s) valid for the selected marketplace. Amazon currently honours only a single language.',
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
displayName: 'Currency of Preference',
|
|
346
|
+
name: 'currencyOfPreference',
|
|
347
|
+
type: 'string',
|
|
348
|
+
displayOptions: { show: { operation: ITEM_OPS } },
|
|
349
|
+
default: '',
|
|
350
|
+
placeholder: 'USD',
|
|
351
|
+
description: 'ISO 4217 currency code for returned prices (e.g. USD, EUR). Defaults to the marketplace currency.',
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
displayName: 'Simplify',
|
|
355
|
+
name: 'simplify',
|
|
356
|
+
type: 'boolean',
|
|
357
|
+
default: false,
|
|
358
|
+
description: 'Whether to return a flattened item per result (asin, title, price, image, url…) instead of the raw API response',
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
displayName: 'Split Errors',
|
|
362
|
+
name: 'splitErrors',
|
|
363
|
+
type: 'boolean',
|
|
364
|
+
default: false,
|
|
365
|
+
description: 'Whether to route per-item API errors (e.g. inaccessible ASINs) to a separate "Errors" output',
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
};
|
|
369
|
+
this.methods = {
|
|
370
|
+
credentialTest: {
|
|
371
|
+
async creatorsApiCredentialTest(credential) {
|
|
372
|
+
try {
|
|
373
|
+
await (0, GenericFunctions_1.requestAccessToken)(async (options) => (await this.helpers.request(options)), credential.data);
|
|
374
|
+
return { status: 'OK', message: 'Authentication successful' };
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
return { status: 'Error', message: error.message };
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
loadOptions: {
|
|
382
|
+
async getLanguages() {
|
|
383
|
+
var _a;
|
|
384
|
+
let marketplace = '';
|
|
385
|
+
try {
|
|
386
|
+
marketplace = this.getCurrentNodeParameter('marketplace') || '';
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
}
|
|
390
|
+
if (!marketplace) {
|
|
391
|
+
try {
|
|
392
|
+
const creds = await this.getCredentials('amazonCreatorsApi');
|
|
393
|
+
marketplace = creds.marketplace || '';
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const info = (_a = shared_1.LOCALE_INFO[marketplace]) !== null && _a !== void 0 ? _a : shared_1.LOCALE_INFO['www.amazon.com'];
|
|
399
|
+
return info.languages.map((lang) => ({
|
|
400
|
+
name: lang === info.defaultLanguage ? `${lang} (default)` : lang,
|
|
401
|
+
value: lang,
|
|
402
|
+
}));
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
async execute() {
|
|
408
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
409
|
+
const items = this.getInputData();
|
|
410
|
+
const dataItems = [];
|
|
411
|
+
const errorItems = [];
|
|
412
|
+
const credentials = await this.getCredentials('amazonCreatorsApi');
|
|
413
|
+
const version = credentials.credentialVersion;
|
|
414
|
+
const accessToken = await GenericFunctions_1.getCreatorsAccessToken.call(this, credentials);
|
|
415
|
+
const splitErrors = this.getNodeParameter('splitErrors', 0, false);
|
|
416
|
+
for (let i = 0; i < items.length; i++) {
|
|
417
|
+
try {
|
|
418
|
+
const operation = this.getNodeParameter('operation', i);
|
|
419
|
+
const simplify = this.getNodeParameter('simplify', i, false);
|
|
420
|
+
const partnerTag = this.getNodeParameter('partnerTag', i, '') ||
|
|
421
|
+
credentials.partnerTag;
|
|
422
|
+
if (!partnerTag) {
|
|
423
|
+
throw (0, GenericFunctions_1.operationError)(this, 'Partner Tag is required (node or credential).', i);
|
|
424
|
+
}
|
|
425
|
+
const marketplace = this.getNodeParameter('marketplace', i, '') ||
|
|
426
|
+
credentials.marketplace;
|
|
427
|
+
const commonBody = { partnerTag, marketplace };
|
|
428
|
+
const languages = this.getNodeParameter('languagesOfPreference', i, []);
|
|
429
|
+
if (languages.length > 0)
|
|
430
|
+
commonBody.languagesOfPreference = languages;
|
|
431
|
+
if (ITEM_OPS.includes(operation)) {
|
|
432
|
+
const currency = this.getNodeParameter('currencyOfPreference', i, '');
|
|
433
|
+
if (currency)
|
|
434
|
+
commonBody.currencyOfPreference = currency;
|
|
435
|
+
}
|
|
436
|
+
const doRequest = (op, body) => GenericFunctions_1.creatorsApiRequest.call(this, op, body, marketplace, accessToken, version);
|
|
437
|
+
let responseData;
|
|
438
|
+
if (operation === 'getItems') {
|
|
439
|
+
const itemIds = (0, shared_1.csvToArray)(this.getNodeParameter('itemIds', i));
|
|
440
|
+
if (itemIds.length === 0)
|
|
441
|
+
throw (0, GenericFunctions_1.operationError)(this, 'At least one Item ID is required.', i);
|
|
442
|
+
const base = { ...commonBody };
|
|
443
|
+
base.itemIdType = this.getNodeParameter('itemIdType', i, 'ASIN');
|
|
444
|
+
const condition = this.getNodeParameter('condition', i, 'Any');
|
|
445
|
+
if (condition !== 'Any')
|
|
446
|
+
base.condition = condition;
|
|
447
|
+
const resources = getResources.call(this, i, operation);
|
|
448
|
+
if (resources.length > 0)
|
|
449
|
+
base.resources = resources;
|
|
450
|
+
const mergedItems = [];
|
|
451
|
+
const mergedErrors = [];
|
|
452
|
+
for (const group of (0, shared_1.chunk)(itemIds, 10)) {
|
|
453
|
+
const res = await doRequest('getItems', { ...base, itemIds: group });
|
|
454
|
+
mergedItems.push(...extractArray(res, 'itemResults.items'));
|
|
455
|
+
mergedErrors.push(...((_a = res.errors) !== null && _a !== void 0 ? _a : []));
|
|
456
|
+
}
|
|
457
|
+
responseData = { itemResults: { items: mergedItems }, errors: mergedErrors };
|
|
458
|
+
}
|
|
459
|
+
else if (operation === 'searchItems') {
|
|
460
|
+
const base = { ...commonBody };
|
|
461
|
+
const keywords = this.getNodeParameter('keywords', i, '');
|
|
462
|
+
if (keywords)
|
|
463
|
+
base.keywords = keywords;
|
|
464
|
+
const searchIndex = this.getNodeParameter('searchIndex', i, 'All');
|
|
465
|
+
if (searchIndex)
|
|
466
|
+
base.searchIndex = searchIndex;
|
|
467
|
+
const resources = getResources.call(this, i, operation);
|
|
468
|
+
if (resources.length > 0)
|
|
469
|
+
base.resources = resources;
|
|
470
|
+
applySearchExtras.call(this, i, base);
|
|
471
|
+
const pageSize = this.getNodeParameter('itemCount', i, 10);
|
|
472
|
+
const returnAll = this.getNodeParameter('returnAll', i, false);
|
|
473
|
+
const collected = [];
|
|
474
|
+
let lastResult = {};
|
|
475
|
+
if (returnAll) {
|
|
476
|
+
const limit = this.getNodeParameter('limit', i, 50);
|
|
477
|
+
for (let page = 1; page <= 10 && collected.length < limit; page++) {
|
|
478
|
+
const res = await doRequest('searchItems', { ...base, itemCount: pageSize, itemPage: page });
|
|
479
|
+
lastResult = (_b = res.searchResult) !== null && _b !== void 0 ? _b : {};
|
|
480
|
+
const pageItems = extractArray(res, 'searchResult.items');
|
|
481
|
+
collected.push(...pageItems);
|
|
482
|
+
if (pageItems.length < pageSize)
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
collected.splice(limit);
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
base.itemCount = pageSize;
|
|
489
|
+
base.itemPage = this.getNodeParameter('itemPage', i, 1);
|
|
490
|
+
const res = await doRequest('searchItems', base);
|
|
491
|
+
lastResult = (_c = res.searchResult) !== null && _c !== void 0 ? _c : {};
|
|
492
|
+
collected.push(...extractArray(res, 'searchResult.items'));
|
|
493
|
+
}
|
|
494
|
+
responseData = {
|
|
495
|
+
searchResult: { ...lastResult, items: collected },
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
else if (operation === 'getVariations') {
|
|
499
|
+
const asin = this.getNodeParameter('asin', i);
|
|
500
|
+
if (!asin)
|
|
501
|
+
throw (0, GenericFunctions_1.operationError)(this, 'ASIN is required for Get Variations.', i);
|
|
502
|
+
const base = { ...commonBody, asin: asin.trim() };
|
|
503
|
+
const condition = this.getNodeParameter('condition', i, 'Any');
|
|
504
|
+
if (condition !== 'Any')
|
|
505
|
+
base.condition = condition;
|
|
506
|
+
const resources = getResources.call(this, i, operation);
|
|
507
|
+
if (resources.length > 0)
|
|
508
|
+
base.resources = resources;
|
|
509
|
+
const pageSize = this.getNodeParameter('variationCount', i, 10);
|
|
510
|
+
const returnAll = this.getNodeParameter('returnAll', i, false);
|
|
511
|
+
const collected = [];
|
|
512
|
+
let summary;
|
|
513
|
+
if (returnAll) {
|
|
514
|
+
const limit = this.getNodeParameter('limit', i, 50);
|
|
515
|
+
for (let page = 1; collected.length < limit; page++) {
|
|
516
|
+
const res = await doRequest('getVariations', {
|
|
517
|
+
...base,
|
|
518
|
+
variationCount: pageSize,
|
|
519
|
+
variationPage: page,
|
|
520
|
+
});
|
|
521
|
+
const vr = (_d = res.variationsResult) !== null && _d !== void 0 ? _d : {};
|
|
522
|
+
if (!summary)
|
|
523
|
+
summary = vr.variationSummary;
|
|
524
|
+
const pageItems = extractArray(res, 'variationsResult.items');
|
|
525
|
+
collected.push(...pageItems);
|
|
526
|
+
const pageCount = (_e = summary === null || summary === void 0 ? void 0 : summary.pageCount) !== null && _e !== void 0 ? _e : page;
|
|
527
|
+
if (pageItems.length < pageSize || page >= pageCount)
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
collected.splice(limit);
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
base.variationCount = pageSize;
|
|
534
|
+
base.variationPage = this.getNodeParameter('variationPage', i, 1);
|
|
535
|
+
const res = await doRequest('getVariations', base);
|
|
536
|
+
const vr = (_f = res.variationsResult) !== null && _f !== void 0 ? _f : {};
|
|
537
|
+
summary = vr.variationSummary;
|
|
538
|
+
collected.push(...extractArray(res, 'variationsResult.items'));
|
|
539
|
+
}
|
|
540
|
+
responseData = {
|
|
541
|
+
variationsResult: { items: collected, variationSummary: summary !== null && summary !== void 0 ? summary : null },
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
else if (operation === 'getBrowseNodes') {
|
|
545
|
+
const browseNodeIds = (0, shared_1.csvToArray)(this.getNodeParameter('browseNodeIds', i));
|
|
546
|
+
if (browseNodeIds.length === 0)
|
|
547
|
+
throw (0, GenericFunctions_1.operationError)(this, 'At least one Browse Node ID is required.', i);
|
|
548
|
+
const base = { ...commonBody };
|
|
549
|
+
const resources = this.getNodeParameter('browseNodeResources', i, []);
|
|
550
|
+
if (resources.length > 0)
|
|
551
|
+
base.resources = resources;
|
|
552
|
+
const mergedNodes = [];
|
|
553
|
+
const mergedErrors = [];
|
|
554
|
+
for (const group of (0, shared_1.chunk)(browseNodeIds, 10)) {
|
|
555
|
+
const res = await doRequest('getBrowseNodes', { ...base, browseNodeIds: group });
|
|
556
|
+
mergedNodes.push(...extractArray(res, 'browseNodesResult.browseNodes'));
|
|
557
|
+
mergedErrors.push(...((_g = res.errors) !== null && _g !== void 0 ? _g : []));
|
|
558
|
+
}
|
|
559
|
+
responseData = { browseNodesResult: { browseNodes: mergedNodes }, errors: mergedErrors };
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
throw (0, GenericFunctions_1.operationError)(this, `Unknown operation: ${operation}`, i);
|
|
563
|
+
}
|
|
564
|
+
const apiErrors = (_h = responseData.errors) !== null && _h !== void 0 ? _h : [];
|
|
565
|
+
const productArray = operation === 'getBrowseNodes'
|
|
566
|
+
? extractArray(responseData, 'browseNodesResult.browseNodes')
|
|
567
|
+
: operation === 'getItems'
|
|
568
|
+
? extractArray(responseData, 'itemResults.items')
|
|
569
|
+
: operation === 'searchItems'
|
|
570
|
+
? extractArray(responseData, 'searchResult.items')
|
|
571
|
+
: extractArray(responseData, 'variationsResult.items');
|
|
572
|
+
if (simplify) {
|
|
573
|
+
for (const product of productArray) {
|
|
574
|
+
const flat = operation === 'getBrowseNodes' ? (0, shared_1.simplifyBrowseNode)(product) : (0, shared_1.simplifyItem)(product);
|
|
575
|
+
dataItems.push({ json: flat, pairedItem: { item: i } });
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
const main = { ...responseData };
|
|
580
|
+
if (splitErrors)
|
|
581
|
+
delete main.errors;
|
|
582
|
+
dataItems.push({ json: main, pairedItem: { item: i } });
|
|
583
|
+
}
|
|
584
|
+
for (const err of apiErrors) {
|
|
585
|
+
const target = splitErrors ? errorItems : dataItems;
|
|
586
|
+
target.push({ json: { ...err, __isError: true }, pairedItem: { item: i } });
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
catch (error) {
|
|
590
|
+
if (this.continueOnFail()) {
|
|
591
|
+
const target = splitErrors ? errorItems : dataItems;
|
|
592
|
+
target.push({ json: { error: error.message }, pairedItem: { item: i } });
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
throw error;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return splitErrors ? [dataItems, errorItems] : [dataItems];
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
exports.AmazonCreatorsApi = AmazonCreatorsApi;
|
|
602
|
+
function getResources(i, operation) {
|
|
603
|
+
const preset = this.getNodeParameter('resourcePreset', i, 'custom');
|
|
604
|
+
const paramName = operation === 'getItems'
|
|
605
|
+
? 'resourcesGetItems'
|
|
606
|
+
: operation === 'searchItems'
|
|
607
|
+
? 'resourcesSearchItems'
|
|
608
|
+
: 'resourcesGetVariations';
|
|
609
|
+
const custom = this.getNodeParameter(paramName, i, []);
|
|
610
|
+
const allResources = operation === 'getItems'
|
|
611
|
+
? shared_1.ITEM_RESOURCES
|
|
612
|
+
: operation === 'searchItems'
|
|
613
|
+
? shared_1.SEARCH_RESOURCES
|
|
614
|
+
: shared_1.VARIATION_RESOURCES;
|
|
615
|
+
return (0, shared_1.resolveResourcePreset)(preset, custom, allResources);
|
|
616
|
+
}
|
|
617
|
+
function applySearchExtras(i, body) {
|
|
618
|
+
const extra = this.getNodeParameter('searchAdditionalFields', i, {});
|
|
619
|
+
if (extra.actor)
|
|
620
|
+
body.actor = extra.actor;
|
|
621
|
+
if (extra.artist)
|
|
622
|
+
body.artist = extra.artist;
|
|
623
|
+
if (extra.author)
|
|
624
|
+
body.author = extra.author;
|
|
625
|
+
if (extra.brand)
|
|
626
|
+
body.brand = extra.brand;
|
|
627
|
+
if (extra.title)
|
|
628
|
+
body.title = extra.title;
|
|
629
|
+
if (extra.browseNodeId)
|
|
630
|
+
body.browseNodeId = extra.browseNodeId;
|
|
631
|
+
if (extra.availability && extra.availability !== 'Available')
|
|
632
|
+
body.availability = extra.availability;
|
|
633
|
+
if (extra.condition && extra.condition !== 'Any')
|
|
634
|
+
body.condition = extra.condition;
|
|
635
|
+
if (extra.sortBy)
|
|
636
|
+
body.sortBy = extra.sortBy;
|
|
637
|
+
if (Array.isArray(extra.deliveryFlags) && extra.deliveryFlags.length > 0)
|
|
638
|
+
body.deliveryFlags = extra.deliveryFlags;
|
|
639
|
+
if (typeof extra.minPrice === 'number' && extra.minPrice > 0)
|
|
640
|
+
body.minPrice = extra.minPrice;
|
|
641
|
+
if (typeof extra.maxPrice === 'number' && extra.maxPrice > 0)
|
|
642
|
+
body.maxPrice = extra.maxPrice;
|
|
643
|
+
if (typeof extra.minReviewsRating === 'number' && extra.minReviewsRating > 0)
|
|
644
|
+
body.minReviewsRating = extra.minReviewsRating;
|
|
645
|
+
if (typeof extra.minSavingPercent === 'number' && extra.minSavingPercent > 0)
|
|
646
|
+
body.minSavingPercent = extra.minSavingPercent;
|
|
647
|
+
}
|
|
648
|
+
function extractArray(obj, path) {
|
|
649
|
+
const value = path.split('.').reduce((acc, key) => {
|
|
650
|
+
if (acc && typeof acc === 'object')
|
|
651
|
+
return acc[key];
|
|
652
|
+
return undefined;
|
|
653
|
+
}, obj);
|
|
654
|
+
return Array.isArray(value) ? value : [];
|
|
655
|
+
}
|
|
656
|
+
//# sourceMappingURL=AmazonCreatorsApi.node.js.map
|