@sentecacommerce-theme/lib 0.12.96 → 0.12.97

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.
@@ -158,7 +158,8 @@ function _objectSpread(target) {
158
158
  mode: 'cors',
159
159
  cache: 'no-cache',
160
160
  headers: {
161
- 'Content-Type': 'application/json'
161
+ 'Content-Type': 'application/json',
162
+ 'senteca-locale': global.location.pathname.split('/')[1] || ''
162
163
  },
163
164
  body: JSON.stringify(payload)
164
165
  });
@@ -44,14 +44,16 @@ var getSDKConfig = function() {
44
44
  var defaultConfig = getOptions(options);
45
45
  var headers = ((ref = _sdk.HttpClient.defaultConfig) === null || ref === void 0 ? void 0 : ref.options.headers) || (defaultConfig === null || defaultConfig === void 0 ? void 0 : defaultConfig.headers) || {};
46
46
  var config = new _sdk.Configuration(_objectSpread({}, ((ref1 = _sdk.HttpClient.defaultConfig) === null || ref1 === void 0 ? void 0 : ref1.options) || defaultConfig, options, {
47
- headers: _objectSpread({}, headers, options.headers || {})
47
+ headers: _objectSpread({}, headers, options.headers || {}, {
48
+ 'senteca-locale': (0, _utils).getLocaleFromPath()
49
+ })
48
50
  }));
49
51
  return config;
50
52
  };
51
53
  exports.getSDKConfig = getSDKConfig;
52
54
  var getOptions = function() {
53
55
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
54
- if (typeof window === 'undefined') {
56
+ if (!(0, _utils).canUseDOM()) {
55
57
  // eslint-disable-next-line @typescript-eslint/no-var-requires
56
58
  var nodeFetch = require('node-fetch');
57
59
  var ref;
@@ -8,6 +8,7 @@ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
8
8
  var _getSDKConfig = require("../api/getSDKConfig");
9
9
  var _reactQuery = require("react-query");
10
10
  var _tokens = require("../utils/tokens");
11
+ var _utils = require("../utils");
11
12
  var _router = require("next/router");
12
13
  function _defineProperty(obj, key, value) {
13
14
  if (key in obj) {
@@ -51,7 +52,8 @@ function SentecaProvider(param) {
51
52
  if (localeData) {
52
53
  options.headers = _objectSpread({}, options.headers || {}, {
53
54
  InterfaceKey: localeData.interfaceKey,
54
- StoreKey: localeData.storeKey
55
+ StoreKey: localeData.storeKey,
56
+ 'senteca-locale': (0, _utils).getLocaleFromPath()
55
57
  });
56
58
  }
57
59
  _sdk.HttpClient.defaultConfig = new _sdk.Configuration(options);
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.getLocaleFromPath = void 0;
5
+ var _canUseDom = require("./canUseDom");
6
+ var getLocaleFromPath = function() {
7
+ if (!(0, _canUseDom).canUseDOM()) return '';
8
+ var locale = window.location.pathname.split('/')[1] || '';
9
+ // the allowed standards: bg bg-BG, en en-US/en-UK
10
+ if (locale.length !== 2 && locale.length !== 5) return '';
11
+ return locale;
12
+ };
13
+ exports.getLocaleFromPath = getLocaleFromPath;
@@ -170,6 +170,18 @@ Object.keys(_adjustColor).forEach(function(key) {
170
170
  }
171
171
  });
172
172
  });
173
+ var _getLocaleFromPath = _interopRequireWildcard(require("./getLocaleFromPath"));
174
+ Object.keys(_getLocaleFromPath).forEach(function(key) {
175
+ if (key === "default" || key === "__esModule") return;
176
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
177
+ if (key in exports && exports[key] === _getLocaleFromPath[key]) return;
178
+ Object.defineProperty(exports, key, {
179
+ enumerable: true,
180
+ get: function() {
181
+ return _getLocaleFromPath[key];
182
+ }
183
+ });
184
+ });
173
185
  var _calcDiscount = _interopRequireWildcard(require("./calcDiscount"));
174
186
  Object.keys(_calcDiscount).forEach(function(key) {
175
187
  if (key === "default" || key === "__esModule") return;
@@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", {
2
2
  value: true
3
3
  });
4
4
  exports.isTouchDevice = isTouchDevice;
5
+ var _canUseDom = require("./canUseDom");
5
6
  function isTouchDevice() {
6
- return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
7
+ return (0, _canUseDom).canUseDOM() && ('ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0);
7
8
  }
@@ -246,7 +246,8 @@ function _objectSpread(target) {
246
246
  mode: 'cors',
247
247
  cache: 'no-cache',
248
248
  headers: {
249
- 'Content-Type': 'application/json'
249
+ 'Content-Type': 'application/json',
250
+ 'senteca-locale': global.location.pathname.split('/')[1] || ''
250
251
  },
251
252
  body: JSON.stringify(payload)
252
253
  });
@@ -1,6 +1,6 @@
1
1
  import { Configuration, HttpClient } from '@sentecacommerce/sdk';
2
2
  import Cookies from 'js-cookie';
3
- import { ANONYMOUS_TOKEN_KEY, AUTH_TOKEN_KEY } from '../utils';
3
+ import { ANONYMOUS_TOKEN_KEY, AUTH_TOKEN_KEY, getLocaleFromPath, canUseDOM } from '../utils';
4
4
  function _defineProperty(obj, key, value) {
5
5
  if (key in obj) {
6
6
  Object.defineProperty(obj, key, {
@@ -35,13 +35,15 @@ export var getSDKConfig = function() {
35
35
  var defaultConfig = getOptions(options);
36
36
  var headers = ((ref = HttpClient.defaultConfig) === null || ref === void 0 ? void 0 : ref.options.headers) || (defaultConfig === null || defaultConfig === void 0 ? void 0 : defaultConfig.headers) || {};
37
37
  var config = new Configuration(_objectSpread({}, ((ref1 = HttpClient.defaultConfig) === null || ref1 === void 0 ? void 0 : ref1.options) || defaultConfig, options, {
38
- headers: _objectSpread({}, headers, options.headers || {})
38
+ headers: _objectSpread({}, headers, options.headers || {}, {
39
+ 'senteca-locale': getLocaleFromPath()
40
+ })
39
41
  }));
40
42
  return config;
41
43
  };
42
44
  export var getOptions = function() {
43
45
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
44
- if (typeof window === 'undefined') {
46
+ if (!canUseDOM()) {
45
47
  // eslint-disable-next-line @typescript-eslint/no-var-requires
46
48
  var nodeFetch = require('node-fetch');
47
49
  var ref;
@@ -4,6 +4,7 @@ import fetch from 'node-fetch';
4
4
  import { getOptions } from '../api/getSDKConfig';
5
5
  import { ReactQueryConfigProvider, useQueryCache } from 'react-query';
6
6
  import { removeAnonToken, removeAuthToken } from '../utils/tokens';
7
+ import { getLocaleFromPath } from '../utils';
7
8
  import { useRouter } from 'next/router';
8
9
  function _defineProperty(obj, key, value) {
9
10
  if (key in obj) {
@@ -42,7 +43,8 @@ export function SentecaProvider(param) {
42
43
  if (localeData) {
43
44
  options.headers = _objectSpread({}, options.headers || {}, {
44
45
  InterfaceKey: localeData.interfaceKey,
45
- StoreKey: localeData.storeKey
46
+ StoreKey: localeData.storeKey,
47
+ 'senteca-locale': getLocaleFromPath()
46
48
  });
47
49
  }
48
50
  HttpClient.defaultConfig = new Configuration(options);
@@ -0,0 +1,8 @@
1
+ import { canUseDOM } from './canUseDom';
2
+ export var getLocaleFromPath = function() {
3
+ if (!canUseDOM()) return '';
4
+ var locale = window.location.pathname.split('/')[1] || '';
5
+ // the allowed standards: bg bg-BG, en en-US/en-UK
6
+ if (locale.length !== 2 && locale.length !== 5) return '';
7
+ return locale;
8
+ };
@@ -13,6 +13,7 @@ export * from './getTranslatableField';
13
13
  export * from './formatAsCurrency';
14
14
  export * from './createCatalogBreadcrumb';
15
15
  export * from './adjustColor';
16
+ export * from './getLocaleFromPath';
16
17
  export * from './calcDiscount';
17
18
  export * from './canUseDom';
18
19
  export * from './getFirst';
@@ -1,3 +1,4 @@
1
+ import { canUseDOM } from "./canUseDom";
1
2
  export function isTouchDevice() {
2
- return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
3
+ return canUseDOM() && ('ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0);
3
4
  }
@@ -0,0 +1 @@
1
+ export declare const getLocaleFromPath: () => string;
@@ -13,6 +13,7 @@ export * from './getTranslatableField';
13
13
  export * from './formatAsCurrency';
14
14
  export * from './createCatalogBreadcrumb';
15
15
  export * from './adjustColor';
16
+ export * from './getLocaleFromPath';
16
17
  export * from './calcDiscount';
17
18
  export * from './canUseDom';
18
19
  export * from './getFirst';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentecacommerce-theme/lib",
3
3
  "sideEffects": false,
4
- "version": "0.12.96",
4
+ "version": "0.12.97",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -31,13 +31,13 @@
31
31
  "watch:cjs": "swc src --out-dir dist/cjs -w",
32
32
  "watch:esm": "swc src --out-dir dist/esm --no-swcrc -w"
33
33
  },
34
- "gitHead": "857da38c2eb402b3d8a51ad70ffbb5dc770febff",
34
+ "gitHead": "d71d565067baef7c428849d6ccd7280f74d9fcf3",
35
35
  "peerDependencies": {
36
36
  "react-query": "^2.26.2"
37
37
  },
38
38
  "dependencies": {
39
- "@sentecacommerce-theme/base": "^0.12.96",
40
- "@sentecacommerce-theme/cms": "^0.12.96",
39
+ "@sentecacommerce-theme/base": "^0.12.97",
40
+ "@sentecacommerce-theme/cms": "^0.12.97",
41
41
  "@sentecacommerce/sdk": "2.0.161",
42
42
  "body-scroll-lock": "^3.1.5",
43
43
  "copy-to-clipboard": "^3.3.1",