@constructor-io/constructorio-client-javascript 2.53.1 → 2.55.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.
@@ -58,7 +58,8 @@ function createAutocompleteUrl(query, parameters, options) {
58
58
  filtersPerSection = parameters.filtersPerSection,
59
59
  hiddenFields = parameters.hiddenFields,
60
60
  variationsMap = parameters.variationsMap,
61
- preFilterExpression = parameters.preFilterExpression;
61
+ preFilterExpression = parameters.preFilterExpression,
62
+ qsParam = parameters.qsParam;
62
63
 
63
64
  // Pull results number from parameters
64
65
  if (numResults) {
@@ -104,6 +105,11 @@ function createAutocompleteUrl(query, parameters, options) {
104
105
  if (variationsMap) {
105
106
  queryParams.variations_map = JSON.stringify(variationsMap);
106
107
  }
108
+
109
+ // pull qs param from parameters
110
+ if (qsParam) {
111
+ queryParams.qs = JSON.stringify(qsParam);
112
+ }
107
113
  }
108
114
  queryParams._dt = Date.now();
109
115
  queryParams = cleanParams(queryParams);
@@ -141,6 +147,7 @@ var Autocomplete = /*#__PURE__*/function () {
141
147
  * @param {object} [parameters.preFilterExpression] - Faceting expression to scope autocomplete results. Please refer to https://docs.constructor.io/rest_api/collections/#add-items-dynamically for details
142
148
  * @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
143
149
  * @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.io/rest_api/variations_mapping for details
150
+ * @param {object} [parameters.qsParam] - object of additional query parameters to be appended to requests for results
144
151
  * @param {object} [networkParameters] - Parameters relevant to the network request
145
152
  * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
146
153
  * @returns {Promise}
@@ -7,6 +7,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
7
7
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
8
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
9
9
  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; }
10
+ /* eslint-disable max-len */
10
11
  /* eslint-disable object-curly-newline, no-underscore-dangle, camelcase, no-unneeded-ternary */
11
12
  var EventEmitter = require('../utils/events');
12
13
  var helpers = require('../utils/helpers');
@@ -277,7 +278,7 @@ var Tracker = /*#__PURE__*/function () {
277
278
  * @param {string} [parameters.tr] - Trigger used to select the item (click, etc.)
278
279
  * @param {string} [parameters.itemId] - Item id of the selected item
279
280
  * @param {string} [parameters.variationId] - Variation id of the selected item
280
- * @param {string} [parameters.groupId] - Group identifier of selected item
281
+ * @param {string} [parameters.groupId] - Group identifier of the group to search within. Only required if searching within a group, i.e. "Pumpkin in Canned Goods"
281
282
  * @param {object} [networkParameters] - Parameters relevant to the network request
282
283
  * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
283
284
  * @returns {(true|Error)}
@@ -361,7 +362,7 @@ var Tracker = /*#__PURE__*/function () {
361
362
  * @param {string} parameters.originalQuery - The current autocomplete search query
362
363
  * @param {string} parameters.section - Section the selected item resides within
363
364
  * @param {string} [parameters.tr] - Trigger used to select the item (click, etc.)
364
- * @param {string} [parameters.groupId] - Group identifier of selected item
365
+ * @param {string} [parameters.groupId] - Group identifier of the group to search within. Only required if searching within a group, i.e. "Pumpkin in Canned Goods"
365
366
  * @param {string} [parameters.displayName] - Display name of group of selected item
366
367
  * @param {object} [networkParameters] - Parameters relevant to the network request
367
368
  * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
@@ -436,7 +437,7 @@ var Tracker = /*#__PURE__*/function () {
436
437
  * @param {string} searchTerm - Term of submitted autocomplete event
437
438
  * @param {object} parameters - Additional parameters to be sent with request
438
439
  * @param {string} parameters.userInput - The current autocomplete search query
439
- * @param {string} [parameters.groupId] - Group identifier of selected item
440
+ * @param {string} [parameters.groupId] - Group identifier of the group to search within. Only required if searching within a group, i.e. "Pumpkin in Canned Goods"
440
441
  * @param {string} [parameters.section] - The section name for the item Ex. "Products"
441
442
  * @param {object} [parameters.analyticsTags] - Pass additional analytics data
442
443
  * @param {object} [networkParameters] - Parameters relevant to the network request
@@ -513,7 +514,7 @@ var Tracker = /*#__PURE__*/function () {
513
514
  * @param {string} term - Term of submitted autocomplete event
514
515
  * @param {object} parameters - Additional parameters to be sent with request
515
516
  * @param {string} parameters.originalQuery - The current autocomplete search query
516
- * @param {string} [parameters.groupId] - Group identifier of selected item
517
+ * @param {string} [parameters.groupId] - Group identifier of the group to search within. Only required if searching within a group, i.e. "Pumpkin in Canned Goods"
517
518
  * @param {string} [parameters.displayName] - Display name of group of selected item
518
519
  * @param {object} [networkParameters] - Parameters relevant to the network request
519
520
  * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
@@ -19,6 +19,7 @@ export interface IAutocompleteParameters {
19
19
  hiddenFields?: string[];
20
20
  variationsMap?: VariationsMap;
21
21
  preFilterExpression?: FilterExpression;
22
+ qsParam?: Record<string, any>;
22
23
  }
23
24
 
24
25
  declare class Autocomplete {
@@ -1,5 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ function canUseStorage(type) {
4
+ var storage;
5
+ try {
6
+ storage = window[type];
7
+ var x = '__storage_test__';
8
+ storage.setItem(x, x);
9
+ storage.removeItem(x);
10
+ return true;
11
+ } catch (e) {
12
+ return e instanceof DOMException && e.name === 'QuotaExceededError'
13
+ // acknowledge QuotaExceededError only if there's something already stored
14
+ && storage && storage.length !== 0;
15
+ }
16
+ }
3
17
  var session = {
4
18
  overflow: {},
5
19
  get: function get(key) {
@@ -8,7 +22,7 @@ var session = {
8
22
  if (valueFromOverflow) {
9
23
  return valueFromOverflow;
10
24
  }
11
- if (typeof sessionStorage === 'undefined') {
25
+ if (!canUseStorage('sessionStorage') || typeof sessionStorage === 'undefined') {
12
26
  return null;
13
27
  }
14
28
  var valueFromSession = sessionStorage.getItem(key);
@@ -35,13 +49,13 @@ var session = {
35
49
  if ((_this$overflow = this.overflow) !== null && _this$overflow !== void 0 && _this$overflow[key]) {
36
50
  delete this.overflow[key];
37
51
  }
38
- if (typeof sessionStorage !== 'undefined') {
52
+ if (canUseStorage('sessionStorage') || typeof sessionStorage !== 'undefined') {
39
53
  sessionStorage.removeItem(key);
40
54
  }
41
55
  },
42
56
  key: function key(i) {
43
57
  var _sessionStorage, _sessionStorage2;
44
- if (typeof sessionStorage === 'undefined') {
58
+ if (!canUseStorage('sessionStorage') || typeof sessionStorage === 'undefined') {
45
59
  var _Object$keys;
46
60
  return (_Object$keys = Object.keys(this.overflow)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[i];
47
61
  }
@@ -56,14 +70,14 @@ var session = {
56
70
  },
57
71
  length: function length() {
58
72
  var overflowLength = Object.keys(this.overflow).length;
59
- if (typeof sessionStorage === 'undefined') {
73
+ if (!canUseStorage('sessionStorage') || typeof sessionStorage === 'undefined') {
60
74
  return overflowLength;
61
75
  }
62
76
  return sessionStorage.length + overflowLength;
63
77
  },
64
78
  clear: function clear() {
65
79
  this.overflow = {};
66
- if (typeof sessionStorage !== 'undefined') {
80
+ if (canUseStorage('sessionStorage') || typeof sessionStorage !== 'undefined') {
67
81
  sessionStorage.clear();
68
82
  }
69
83
  }
@@ -76,7 +90,7 @@ var local = {
76
90
  if (valueFromOverflow) {
77
91
  return valueFromOverflow;
78
92
  }
79
- if (typeof localStorage === 'undefined') {
93
+ if (!canUseStorage('localStorage') || typeof localStorage === 'undefined') {
80
94
  return null;
81
95
  }
82
96
  var valueFromLocal = localStorage.getItem(key);
@@ -103,13 +117,13 @@ var local = {
103
117
  if ((_this$overflow2 = this.overflow) !== null && _this$overflow2 !== void 0 && _this$overflow2[key]) {
104
118
  delete this.overflow[key];
105
119
  }
106
- if (typeof localStorage !== 'undefined') {
120
+ if (canUseStorage('localStorage') || typeof localStorage !== 'undefined') {
107
121
  localStorage.removeItem(key);
108
122
  }
109
123
  },
110
124
  key: function key(i) {
111
125
  var _localStorage, _localStorage2;
112
- if (typeof localStorage === 'undefined') {
126
+ if (!canUseStorage('localStorage') || typeof localStorage === 'undefined') {
113
127
  var _Object$keys3;
114
128
  return (_Object$keys3 = Object.keys(this.overflow)) === null || _Object$keys3 === void 0 ? void 0 : _Object$keys3[i];
115
129
  }
@@ -124,20 +138,21 @@ var local = {
124
138
  },
125
139
  length: function length() {
126
140
  var overflowLength = Object.keys(this.overflow).length;
127
- if (typeof localStorage === 'undefined') {
141
+ if (!canUseStorage('localStorage') || typeof localStorage === 'undefined') {
128
142
  return overflowLength;
129
143
  }
130
144
  return localStorage.length + overflowLength;
131
145
  },
132
146
  clear: function clear() {
133
147
  this.overflow = {};
134
- if (typeof localStorage !== 'undefined') {
148
+ if (canUseStorage('localStorage') || typeof localStorage !== 'undefined') {
135
149
  localStorage.clear();
136
150
  }
137
151
  }
138
152
  };
139
153
  var store = {
140
154
  local: local,
141
- session: session
155
+ session: session,
156
+ canUseStorage: canUseStorage
142
157
  };
143
158
  module.exports = store;
package/lib/version.js CHANGED
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _default = '2.53.1';
7
+ var _default = '2.55.0';
8
8
  exports["default"] = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-client-javascript",
3
- "version": "2.53.1",
3
+ "version": "2.55.0",
4
4
  "description": "Constructor.io JavaScript client",
5
5
  "main": "lib/constructorio.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -10,13 +10,14 @@
10
10
  "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause'",
11
11
  "verify-node-version": "chmod +x ./scripts/verify-node-version.sh && ./scripts/verify-node-version.sh",
12
12
  "lint": "eslint 'src/**/*.js' 'spec/**/*.js' 'src/**/*.d.ts'",
13
- "test": "npm run compile && mkdir -p test && cp -rf lib/* test && mocha --retries 3 ./spec/*",
13
+ "pretest": "npm run compile && npm run generate-test-folder",
14
+ "test": "mocha --retries 3 ./spec/*",
14
15
  "test:types": "tsd .",
15
- "test:parallel": "npm run compile && mkdir -p test && cp -rf lib/* test && mocha --parallel --retries 3 ./spec/*",
16
+ "test:parallel": "npm run pretest && mocha --parallel --retries 3 ./spec/*",
16
17
  "test:src": "mkdir -p test && cp -rf src/* test && mocha --retries 3 ./spec/*",
17
18
  "test:src:parallel": "mkdir -p test && cp -rf src/* test && mocha --parallel --retries 3 ./spec/*",
18
- "test:bundled": "npm run bundle && BUNDLED=true PACKAGE_VERSION=$(echo $npm_package_version) mocha --retries 3 ./spec/*",
19
- "test:bundled:parallel": "npm run bundle && BUNDLED=true PACKAGE_VERSION=$(echo $npm_package_version) mocha --parallel --retries 3 ./spec/*",
19
+ "test:bundled": "npm run bundle && npm run generate-test-folder && BUNDLED=true PACKAGE_VERSION=$(echo $npm_package_version) mocha --retries 3 ./spec/*",
20
+ "test:bundled:parallel": "npm run bundle && npm run generate-test-folder && BUNDLED=true PACKAGE_VERSION=$(echo $npm_package_version) mocha --parallel --retries 3 ./spec/*",
20
21
  "test:all": "npm run test && npm run test:bundled",
21
22
  "test:all:parallel": "npm run test:parallel && npm run test:bundled:parallel",
22
23
  "precoverage": "rm -rf ./coverage && rm -rf ./.nyc_output",
@@ -26,7 +27,8 @@
26
27
  "compile": "rm -rf ./lib/* && babel src/ -d lib/ --copy-files && rm -rf ./lib/types/tests",
27
28
  "prepublish": "npm run compile",
28
29
  "bundle": "rm -rf ./dist/* && npm run compile && node bundle.js",
29
- "prepare": "husky install"
30
+ "prepare": "husky install",
31
+ "generate-test-folder": "mkdir -p test && cp -rf lib/* test"
30
32
  },
31
33
  "repository": {
32
34
  "type": "git",
@@ -73,7 +75,7 @@
73
75
  "web-streams-polyfill": "^4.0.0"
74
76
  },
75
77
  "dependencies": {
76
- "@constructor-io/constructorio-id": "^2.4.17",
78
+ "@constructor-io/constructorio-id": "^2.6.0",
77
79
  "crc-32": "^1.2.2"
78
80
  },
79
81
  "peerDependencies": {