@constructor-io/constructorio-client-javascript 2.29.7 → 2.29.10

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/README.md CHANGED
@@ -8,6 +8,9 @@ A JavaScript client for [Constructor.io](http://constructor.io/). [Constructor.i
8
8
 
9
9
  > This client is intended for use in a browser environment but can also be used in React Native based mobile applications. Additional information about utilization in a React Native context can be found on the [Wiki](https://github.com/Constructor-io/constructorio-client-javascript/wiki/Utilization-in-a-DOM-less-environment). If you want a JavaScript client for server side integrations please use [@constructor-io/constructorio-node](https://github.com/Constructor-io/constructorio-node)
10
10
 
11
+ ## Documentation
12
+ Full API documentation is available on [Github Pages](https://constructor-io.github.io/constructorio-client-javascript/index.html)
13
+
11
14
  ## 1. Install
12
15
 
13
16
  This package can be installed via npm: `npm i @constructor-io/constructorio-client-javascript`. Once installed, simply import or require the package into your repository.
@@ -45,8 +48,6 @@ window.addEventListener('cio.client.search.getSearchResults.completed', (event)
45
48
  }, false);
46
49
  ```
47
50
 
48
- Full API documentation is available on [Github Pages](https://constructor-io.github.io/constructorio-client-javascript/index.html)
49
-
50
51
  ## Development / npm commands
51
52
 
52
53
  ```bash
@@ -12,9 +12,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
12
12
 
13
13
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
14
14
 
15
- /* eslint-disable max-len */
16
-
17
- /* eslint-disable object-curly-newline, no-underscore-dangle */
15
+ /* eslint-disable object-curly-newline, no-underscore-dangle, max-len, complexity */
18
16
  var qs = require('qs');
19
17
 
20
18
  var fetchPonyfill = require('fetch-ponyfill');
@@ -59,6 +57,7 @@ function createQueryParams(parameters, options) {
59
57
 
60
58
  if (parameters) {
61
59
  var page = parameters.page,
60
+ offset = parameters.offset,
62
61
  resultsPerPage = parameters.resultsPerPage,
63
62
  filters = parameters.filters,
64
63
  sortBy = parameters.sortBy,
@@ -67,10 +66,17 @@ function createQueryParams(parameters, options) {
67
66
  fmtOptions = parameters.fmtOptions,
68
67
  hiddenFields = parameters.hiddenFields,
69
68
  hiddenFacets = parameters.hiddenFacets,
70
- variationsMap = parameters.variationsMap; // Pull page from parameters
69
+ variationsMap = parameters.variationsMap,
70
+ qsParam = parameters.qsParam,
71
+ preFilterExpression = parameters.preFilterExpression; // Pull page from parameters
71
72
 
72
73
  if (!helpers.isNil(page)) {
73
74
  queryParams.page = page;
75
+ } // Pull offset from parameters
76
+
77
+
78
+ if (!helpers.isNil(offset)) {
79
+ queryParams.offset = offset;
74
80
  } // Pull results per page from parameters
75
81
 
76
82
 
@@ -127,6 +133,16 @@ function createQueryParams(parameters, options) {
127
133
 
128
134
  if (variationsMap) {
129
135
  queryParams.variations_map = JSON.stringify(variationsMap);
136
+ } // Pull pre_filter_expression from parameters
137
+
138
+
139
+ if (preFilterExpression) {
140
+ queryParams.pre_filter_expression = JSON.stringify(preFilterExpression);
141
+ } // pull qs param from parameters
142
+
143
+
144
+ if (qsParam) {
145
+ queryParams.qs = JSON.stringify(qsParam);
130
146
  }
131
147
  }
132
148
 
@@ -228,16 +244,19 @@ var Browse = /*#__PURE__*/function () {
228
244
  * @param {string} filterName - Filter name to display results from
229
245
  * @param {string} filterValue - Filter value to display results from
230
246
  * @param {object} [parameters] - Additional parameters to refine result set
231
- * @param {number} [parameters.page] - The page number of the results
247
+ * @param {number} [parameters.page] - The page number of the results (Can't be used together with offset)
248
+ * @param {number} [parameters.offset] - The number of results to skip from the beginning (Can't be used together with page)
232
249
  * @param {number} [parameters.resultsPerPage] - The number of results per page to return
233
250
  * @param {object} [parameters.filters] - Key / value mapping (dictionary) of filters used to refine results
234
251
  * @param {string} [parameters.sortBy='relevance'] - The sort method for results
235
252
  * @param {string} [parameters.sortOrder='descending'] - The sort order for results
236
253
  * @param {string} [parameters.section='Products'] - The section name for results
237
- * @param {object} [parameters.fmtOptions] - The format options used to refine result groups
254
+ * @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.io/rest_api/browse/queries/ for details
255
+ * @param {object} [parameters.preFilterExpression] - Faceting expression to scope browse results. Please refer to https://docs.constructor.io/rest_api/collections#add-items-dynamically
238
256
  * @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
239
257
  * @param {string[]} [parameters.hiddenFacets] - Hidden facets to return
240
258
  * @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.io/rest_api/variations_mapping for details
259
+ * @param {object} [parameters.qs] - Parameters listed above can be serialized into a JSON object and parsed through this parameter. Please refer to https://docs.constructor.io/rest_api/browse/queries/
241
260
  * @param {object} [networkParameters] - Parameters relevant to the network request
242
261
  * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
243
262
  * @returns {Promise}
@@ -309,13 +328,14 @@ var Browse = /*#__PURE__*/function () {
309
328
  * @function getBrowseResultsForItemIds
310
329
  * @param {string[]} itemIds - Item id's of results to fetch
311
330
  * @param {object} [parameters] - Additional parameters to refine result set
312
- * @param {number} [parameters.page] - The page number of the results
331
+ * @param {number} [parameters.page] - The page number of the results (Can't be used together with offset)
332
+ * @param {number} [parameters.offset] - The number of results to skip from the beginning (Can't be used together with page)
313
333
  * @param {number} [parameters.resultsPerPage] - The number of results per page to return
314
334
  * @param {object} [parameters.filters] - Filters used to refine results
315
335
  * @param {string} [parameters.sortBy='relevance'] - The sort method for results
316
336
  * @param {string} [parameters.sortOrder='descending'] - The sort order for results
317
337
  * @param {string} [parameters.section='Products'] - The section name for results
318
- * @param {object} [parameters.fmtOptions] - The format options used to refine result groups
338
+ * @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.io/rest_api/browse/queries/ for details
319
339
  * @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
320
340
  * @param {string[]} [parameters.hiddenFacets] - Hidden facets to return
321
341
  * @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.io/rest_api/variations_mapping for details
@@ -388,7 +408,7 @@ var Browse = /*#__PURE__*/function () {
388
408
  * @function getBrowseGroups
389
409
  * @param {object} [parameters.filters] - Filters used to refine results
390
410
  * @param {string} [parameters.section='Products'] - The section name for results
391
- * @param {object} [parameters.fmtOptions] - The format options used to refine result groups
411
+ * @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.io/rest_api/browse/groups/ for details
392
412
  * @param {object} [networkParameters] - Parameters relevant to the network request
393
413
  * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
394
414
  * @returns {Promise}
@@ -452,9 +472,10 @@ var Browse = /*#__PURE__*/function () {
452
472
  *
453
473
  * @function getBrowseFacets
454
474
  * @param {object} [parameters] - Additional parameters to refine result set
455
- * @param {number} [parameters.page] - The page number of the results
475
+ * @param {number} [parameters.page] - The page number of the results (Can't be used together with offset)
476
+ * @param {number} [parameters.offset] - The number of results to skip from the beginning (Can't be used together with page)
456
477
  * @param {string} [parameters.section='Products'] - The section name for results
457
- * @param {boolean} [parameters.fmtOptions.show_hidden_facets] - Include facets configured as hidden
478
+ * @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.io/rest_api/browse/facets/ for details
458
479
  * @param {number} [parameters.resultsPerPage] - The number of results per page to return
459
480
  * @param {object} [networkParameters] - Parameters relevant to the network request
460
481
  * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
@@ -518,8 +539,7 @@ var Browse = /*#__PURE__*/function () {
518
539
  * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
519
540
  * @param {object} [parameters] - Additional parameters to refine result set
520
541
  * @param {string} [parameters.section='Products'] - The section name for results
521
- * @param {object} [parameters.fmtOptions] - The format options used to refine result groups
522
- * @param {boolean} [parameters.fmtOptions.show_hidden_facets] - Include facets configured as hidden
542
+ * @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.io/rest_api/browse/facet_options/ for details
523
543
  * @param {}
524
544
  * @returns {Promise}
525
545
  * @see https://docs.constructor.io/rest_api/browse/facet_options/
@@ -6,6 +6,8 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
6
6
 
7
7
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
8
 
9
+ /* eslint-disable complexity */
10
+
9
11
  /* eslint-disable max-len */
10
12
 
11
13
  /* eslint-disable object-curly-newline, no-underscore-dangle */
@@ -58,7 +60,8 @@ function createSearchUrl(query, parameters, options) {
58
60
  }
59
61
 
60
62
  if (parameters) {
61
- var page = parameters.page,
63
+ var offset = parameters.offset,
64
+ page = parameters.page,
62
65
  resultsPerPage = parameters.resultsPerPage,
63
66
  filters = parameters.filters,
64
67
  sortBy = parameters.sortBy,
@@ -67,7 +70,14 @@ function createSearchUrl(query, parameters, options) {
67
70
  fmtOptions = parameters.fmtOptions,
68
71
  hiddenFields = parameters.hiddenFields,
69
72
  hiddenFacets = parameters.hiddenFacets,
70
- variationsMap = parameters.variationsMap; // Pull page from parameters
73
+ variationsMap = parameters.variationsMap,
74
+ qsParam = parameters.qsParam,
75
+ preFilterExpression = parameters.preFilterExpression; // Pull offset from parameters
76
+
77
+ if (!helpers.isNil(offset)) {
78
+ queryParams.offset = offset;
79
+ } // Pull page from parameters
80
+
71
81
 
72
82
  if (!helpers.isNil(page)) {
73
83
  queryParams.page = page;
@@ -128,6 +138,16 @@ function createSearchUrl(query, parameters, options) {
128
138
 
129
139
  if (variationsMap) {
130
140
  queryParams.variations_map = JSON.stringify(variationsMap);
141
+ } // Pull pre_filter_expression from parameters
142
+
143
+
144
+ if (preFilterExpression) {
145
+ queryParams.pre_filter_expression = JSON.stringify(preFilterExpression);
146
+ } // pull qs param from parameters
147
+
148
+
149
+ if (qsParam) {
150
+ queryParams.qs = JSON.stringify(qsParam);
131
151
  }
132
152
  }
133
153
 
@@ -160,16 +180,19 @@ var Search = /*#__PURE__*/function () {
160
180
  * @description Retrieve search results from Constructor.io API
161
181
  * @param {string} query - Term to use to perform a search
162
182
  * @param {object} [parameters] - Additional parameters to refine result set
163
- * @param {number} [parameters.page] - The page number of the results
183
+ * @param {number} [parameters.page] - The page number of the results(Can't be used together with offset)
184
+ * @param {number} [parameters.offset] - The number of results to skip from the beginning (Can't be used together with page)
164
185
  * @param {number} [parameters.resultsPerPage] - The number of results per page to return
165
186
  * @param {object} [parameters.filters] - Key / value mapping (dictionary) of filters used to refine results
166
187
  * @param {string} [parameters.sortBy='relevance'] - The sort method for results
167
188
  * @param {string} [parameters.sortOrder='descending'] - The sort order for results
168
189
  * @param {string} [parameters.section='Products'] - The section name for results
169
- * @param {object} [parameters.fmtOptions] - The format options used to refine result groups
190
+ * @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.io/rest_api/search/queries for details
191
+ * @param {object} [parameters.preFilterExpression] - Faceting expression to scope search results. Please refer to https://docs.constructor.io/rest_api/collections#add-items-dynamically
170
192
  * @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
171
193
  * @param {string[]} [parameters.hiddenFacets] - Hidden facets to return
172
194
  * @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.io/rest_api/variations_mapping for details
195
+ * @param {object} [parameters.qs] - Parameters listed above can be serialized into a JSON object and parsed through this parameter. Please refer to https://docs.constructor.io/rest_api/search/queries/
173
196
  * @param {object} [networkParameters] - Parameters relevant to the network request
174
197
  * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
175
198
  * @returns {Promise}
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
6
-
7
3
  /* eslint-disable no-param-reassign */
8
4
  var CRC32 = require('crc-32');
9
5
 
@@ -100,13 +96,13 @@ var utils = {
100
96
  },
101
97
  hasOrderIdRecord: function hasOrderIdRecord(orderId) {
102
98
  var orderIdHash = CRC32.str(orderId.toString());
103
- var purchaseEventStorage = store.session.get(purchaseEventStorageKey);
99
+ var purchaseEventStorage = store.local.get(purchaseEventStorageKey);
104
100
 
105
101
  if (typeof purchaseEventStorage === 'string') {
106
102
  purchaseEventStorage = JSON.parse(purchaseEventStorage);
107
103
  }
108
104
 
109
- if (purchaseEventStorage && purchaseEventStorage[orderIdHash]) {
105
+ if (purchaseEventStorage && purchaseEventStorage.includes(orderIdHash)) {
110
106
  return true;
111
107
  }
112
108
 
@@ -114,7 +110,7 @@ var utils = {
114
110
  },
115
111
  addOrderIdRecord: function addOrderIdRecord(orderId) {
116
112
  var orderIdHash = CRC32.str(orderId.toString());
117
- var purchaseEventStorage = store.session.get(purchaseEventStorageKey);
113
+ var purchaseEventStorage = store.local.get(purchaseEventStorageKey);
118
114
 
119
115
  if (typeof purchaseEventStorage === 'string') {
120
116
  purchaseEventStorage = JSON.parse(purchaseEventStorage);
@@ -122,18 +118,22 @@ var utils = {
122
118
 
123
119
  if (purchaseEventStorage) {
124
120
  // If the order already exists, do nothing
125
- if (purchaseEventStorage[orderIdHash]) {
121
+ if (purchaseEventStorage.includes(orderIdHash)) {
126
122
  return;
127
123
  }
128
124
 
129
- purchaseEventStorage[orderIdHash] = true;
125
+ if (purchaseEventStorage.length >= 10) {
126
+ purchaseEventStorage = purchaseEventStorage.slice(-9);
127
+ }
128
+
129
+ purchaseEventStorage.push(orderIdHash);
130
130
  } else {
131
131
  // Create a new object map for the order ids
132
- purchaseEventStorage = (0, _defineProperty2["default"])({}, orderIdHash, true);
133
- } // Push the order id map into session storage
132
+ purchaseEventStorage = [orderIdHash];
133
+ } // Push the order id map into local storage
134
134
 
135
135
 
136
- store.session.set(purchaseEventStorageKey, JSON.stringify(purchaseEventStorage));
136
+ store.local.set(purchaseEventStorageKey, JSON.stringify(purchaseEventStorage));
137
137
  },
138
138
  // Abort network request based on supplied timeout interval (in milliseconds)
139
139
  // - method call parameter takes precedence over global options parameter
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-client-javascript",
3
- "version": "2.29.7",
3
+ "version": "2.29.10",
4
4
  "description": "Constructor.io JavaScript client",
5
5
  "main": "lib/constructorio.js",
6
6
  "scripts": {