@constructor-io/constructorio-client-javascript 2.29.8 → 2.29.11

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
@@ -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, 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.8",
3
+ "version": "2.29.11",
4
4
  "description": "Constructor.io JavaScript client",
5
5
  "main": "lib/constructorio.js",
6
6
  "scripts": {