@constructor-io/constructorio-node 5.0.0 → 5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-node",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Constructor.io Node.js client",
5
5
  "main": "src/constructorio.js",
6
6
  "types": "src/types/constructorio.d.ts",
@@ -1,4 +1,4 @@
1
- /* eslint-disable object-curly-newline, no-param-reassign */
1
+ /* eslint-disable object-curly-newline, no-param-reassign, max-len */
2
2
  const qs = require('qs');
3
3
  const { AbortController } = require('node-abort-controller');
4
4
  const helpers = require('../utils/helpers');
@@ -41,6 +41,7 @@ function createRecommendationsUrl(podId, parameters, userParameters, options) {
41
41
  const {
42
42
  numResults,
43
43
  itemIds,
44
+ variationId,
44
45
  section,
45
46
  term,
46
47
  filters,
@@ -59,6 +60,18 @@ function createRecommendationsUrl(podId, parameters, userParameters, options) {
59
60
  queryParams.item_id = itemIds;
60
61
  }
61
62
 
63
+ if (variationId) {
64
+ if (!itemIds) {
65
+ throw new Error('itemIds is a required parameter for variationId');
66
+ }
67
+
68
+ if (Array.isArray(itemIds) && !itemIds.length) {
69
+ throw new Error('At least one itemId is a required parameter for variationId');
70
+ }
71
+
72
+ queryParams.variation_id = variationId;
73
+ }
74
+
62
75
  // Pull section from parameters
63
76
  if (section) {
64
77
  queryParams.section = section;
@@ -119,7 +132,8 @@ class Recommendations {
119
132
  * @function getRecommendations
120
133
  * @param {string} podId - Pod identifier
121
134
  * @param {object} [parameters] - Additional parameters to refine results
122
- * @param {string|array} [parameters.itemIds] - Item ID(s) to retrieve recommendations for (strategy specific)
135
+ * @param {string|array} [parameters.itemIds] - Item ID(s) to retrieve recommendations for (strategy specific). Required for variationId
136
+ * @param {string} [parameters.variationId] - Variation ID to retrieve recommendations for (strategy specific)
123
137
  * @param {number} [parameters.numResults] - The number of results to return
124
138
  * @param {string} [parameters.section] - The section to return results from
125
139
  * @param {string} [parameters.term] - The term to use to refine results (strategy specific)
@@ -1,9 +1,10 @@
1
- import { ConstructorClientOptions, NetworkParameters, UserParameters, VariationsMap } from '.';
1
+ import { ConstructorClientOptions, NetworkParameters, UserParameters, VariationsMap, FilterExpression } from '.';
2
2
 
3
3
  export default Recommendations;
4
4
 
5
5
  export interface RecommendationsParameters {
6
6
  itemIds?: string | string[];
7
+ variationId?: string;
7
8
  numResults?: number;
8
9
  section?: string;
9
10
  term?: string;
@@ -39,7 +40,8 @@ export interface RecommendationsResponse extends Record<string, any> {
39
40
 
40
41
  export interface RecommendationsRequestType extends Record<string, any> {
41
42
  num_results: number;
42
- item_id: string;
43
+ item_id: string | string[];
44
+ variation_id: string;
43
45
  filters: {
44
46
  group_id: string;
45
47
  [key: string]: any;