@searchspring/snap-toolbox 0.34.7 → 0.35.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.
@@ -1 +1 @@
1
- {"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../../src/getContext/getContext.ts"],"names":[],"mappings":"AAAA,aAAK,gBAAgB,GAAG;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,GAAE,MAAM,EAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,gBAAgB,CA0DzG"}
1
+ {"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../../src/getContext/getContext.ts"],"names":[],"mappings":"AAAA,aAAK,gBAAgB,GAAG;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,GAAE,MAAM,EAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,gBAAgB,CAsEzG"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getContext = void 0;
4
4
  function getContext(evaluate, script) {
5
- var _a, _b, _c;
5
+ var _a, _b, _c, _d;
6
6
  if (evaluate === void 0) { evaluate = []; }
7
7
  if (!script || typeof script === 'string') {
8
8
  var scripts = Array.from(document.querySelectorAll(script || 'script[id^=searchspring], script[src*="snapui.searchspring.io"]'));
@@ -26,6 +26,7 @@ function getContext(evaluate, script) {
26
26
  if ((evaluate && !Array.isArray(evaluate)) || (evaluate && !evaluate.reduce(function (accu, name) { return accu && typeof name === 'string'; }, true))) {
27
27
  throw new Error('getContext: first parameter must be an array of strings');
28
28
  }
29
+ var siteIdString = 'siteId';
29
30
  var variables = {};
30
31
  // evaluate text and put into variables
31
32
  evaluate === null || evaluate === void 0 ? void 0 : evaluate.forEach(function (name) {
@@ -44,6 +45,15 @@ function getContext(evaluate, script) {
44
45
  if (typeof variables[key] === 'undefined')
45
46
  delete variables[key];
46
47
  });
48
+ if (evaluate.includes(siteIdString)) {
49
+ // if we didnt find a siteId in the context, lets grab the id from the src url.
50
+ if (!variables[siteIdString]) {
51
+ var siteId = (_d = script.getAttribute('src')) === null || _d === void 0 ? void 0 : _d.match(/.*snapui.searchspring.io\/([a-zA-Z0-9]{6})\//);
52
+ if (siteId && siteId.length > 1) {
53
+ variables.siteId = siteId[1];
54
+ }
55
+ }
56
+ }
47
57
  return variables;
48
58
  }
49
59
  exports.getContext = getContext;
@@ -1 +1 @@
1
- {"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../../src/getContext/getContext.ts"],"names":[],"mappings":"AAAA,aAAK,gBAAgB,GAAG;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,GAAE,MAAM,EAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,gBAAgB,CA0DzG"}
1
+ {"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../../src/getContext/getContext.ts"],"names":[],"mappings":"AAAA,aAAK,gBAAgB,GAAG;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,GAAE,MAAM,EAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,gBAAgB,CAsEzG"}
@@ -21,6 +21,7 @@ export function getContext(evaluate = [], script) {
21
21
  if ((evaluate && !Array.isArray(evaluate)) || (evaluate && !evaluate.reduce((accu, name) => accu && typeof name === 'string', true))) {
22
22
  throw new Error('getContext: first parameter must be an array of strings');
23
23
  }
24
+ let siteIdString = 'siteId';
24
25
  const variables = {};
25
26
  // evaluate text and put into variables
26
27
  evaluate?.forEach((name) => {
@@ -43,5 +44,14 @@ export function getContext(evaluate = [], script) {
43
44
  if (typeof variables[key] === 'undefined')
44
45
  delete variables[key];
45
46
  });
47
+ if (evaluate.includes(siteIdString)) {
48
+ // if we didnt find a siteId in the context, lets grab the id from the src url.
49
+ if (!variables[siteIdString]) {
50
+ const siteId = script.getAttribute('src')?.match(/.*snapui.searchspring.io\/([a-zA-Z0-9]{6})\//);
51
+ if (siteId && siteId.length > 1) {
52
+ variables.siteId = siteId[1];
53
+ }
54
+ }
55
+ }
46
56
  return variables;
47
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searchspring/snap-toolbox",
3
- "version": "0.34.7",
3
+ "version": "0.35.0",
4
4
  "description": "Snap Toolbox",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -23,5 +23,5 @@
23
23
  "files": [
24
24
  "dist/**/*"
25
25
  ],
26
- "gitHead": "943f6a43f44b64e6ca91cdd095575a0cae21d94e"
26
+ "gitHead": "e6f8d7ef23662aed6042da5e49fc74454fa16e94"
27
27
  }