@sentecacommerce-theme/lib 0.13.21-alpha.0 → 0.13.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,18 +53,18 @@ var getSDKConfig = function() {
53
53
  exports.getSDKConfig = getSDKConfig;
54
54
  var getOptions = function() {
55
55
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
56
- var ref;
57
- var basePath = process.env.NEXT_PUBLIC_PROXY_URL + ((ref = options === null || options === void 0 ? void 0 : options.basePath) !== null && ref !== void 0 ? ref : '/platform');
58
56
  if (!(0, _utils).canUseDOM()) {
59
57
  // eslint-disable-next-line @typescript-eslint/no-var-requires
60
58
  var nodeFetch = require('node-fetch');
59
+ var ref;
61
60
  return _objectSpread({}, options, {
62
- basePath: basePath,
61
+ basePath: process.env.PLATFORM_HOST + ((ref = options === null || options === void 0 ? void 0 : options.basePath) !== null && ref !== void 0 ? ref : '/api'),
63
62
  fetchApi: nodeFetch
64
63
  }, process.env.sdkConfig || {});
65
64
  } else {
65
+ var ref2;
66
66
  return _objectSpread({}, options, {
67
- basePath: basePath,
67
+ basePath: (ref2 = options === null || options === void 0 ? void 0 : options.basePath) !== null && ref2 !== void 0 ? ref2 : '/api',
68
68
  token: _jsCookie.default.get(_utils.AUTH_TOKEN_KEY) || _jsCookie.default.get(_utils.ANONYMOUS_TOKEN_KEY) || process.env.API_KEY || process.env.apiKey,
69
69
  fetchApi: window.fetch.bind(window)
70
70
  }, process.env.sdkConfig || {});
@@ -19,7 +19,7 @@ function _interopRequireDefault(obj) {
19
19
  var ProductStateContext = /*#__PURE__*/ _react.default.createContext(undefined);
20
20
  var CountDispatchContext = /*#__PURE__*/ _react.default.createContext(undefined);
21
21
  function ProductProvider(param) {
22
- var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName;
22
+ var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName, _withShortTitle = param.withShortTitle, withShortTitle = _withShortTitle === void 0 ? false : _withShortTitle;
23
23
  var ref38 = (0, _useProductVariants).useProductVariants({
24
24
  product: product,
25
25
  defaultVariantId: defaultVariantId
@@ -30,7 +30,7 @@ function ProductProvider(param) {
30
30
  var rootCategoryId = rootCategory === null || rootCategory === void 0 ? void 0 : rootCategory.resourceId;
31
31
  var metaObj = {
32
32
  _id: product === null || product === void 0 ? void 0 : product._id,
33
- name: includeBrandInName && (product === null || product === void 0 ? void 0 : (ref1 = product.brands) === null || ref1 === void 0 ? void 0 : (ref2 = ref1[0]) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.resource) === null || ref3 === void 0 ? void 0 : ref3.name) ? "".concat((0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref4 = product.brands) === null || ref4 === void 0 ? void 0 : (ref5 = ref4[0]) === null || ref5 === void 0 ? void 0 : (ref6 = ref5.resource) === null || ref6 === void 0 ? void 0 : ref6.name), " ").concat((0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name)) : (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
33
+ name: includeBrandInName && !withShortTitle && (product === null || product === void 0 ? void 0 : (ref1 = product.brands) === null || ref1 === void 0 ? void 0 : (ref2 = ref1[0]) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.resource) === null || ref3 === void 0 ? void 0 : ref3.name) ? "".concat((0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref4 = product.brands) === null || ref4 === void 0 ? void 0 : (ref5 = ref4[0]) === null || ref5 === void 0 ? void 0 : (ref6 = ref5.resource) === null || ref6 === void 0 ? void 0 : ref6.name), " ").concat((0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name)) : (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
34
34
  slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.slug),
35
35
  description: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.description) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.description),
36
36
  shortDescription: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.metaDescription) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.metaDescription),
@@ -28,17 +28,17 @@ function _interopRequireDefault(obj) {
28
28
  *
29
29
  */ var truncateToCharLength = function(text, maxLenChars) {
30
30
  var separator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ' ';
31
- var cut = text.indexOf(separator, maxLenChars);
31
+ var cut = text === null || text === void 0 ? void 0 : text.indexOf(separator, maxLenChars);
32
32
  if (cut === -1) return text;
33
- return text.substring(0, cut);
33
+ return text === null || text === void 0 ? void 0 : text.substring(0, cut);
34
34
  };
35
35
  function ProductSEO() {
36
- var ref16 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _favorTitleTemplateOverMeta = ref16.favorTitleTemplateOverMeta, favorTitleTemplateOverMeta = _favorTitleTemplateOverMeta === void 0 ? false : _favorTitleTemplateOverMeta, _favorDescriptionTemplateOverMeta = ref16.favorDescriptionTemplateOverMeta, favorDescriptionTemplateOverMeta = _favorDescriptionTemplateOverMeta === void 0 ? false : _favorDescriptionTemplateOverMeta, _titleTemplate = ref16.titleTemplate, titleTemplate = _titleTemplate === void 0 ? ':title:' : _titleTemplate, _descriptionTemplate = ref16.descriptionTemplate, descriptionTemplate = _descriptionTemplate === void 0 ? ':description:' : _descriptionTemplate;
36
+ var ref16 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _favorTitleTemplateOverMeta = ref16.favorTitleTemplateOverMeta, favorTitleTemplateOverMeta = _favorTitleTemplateOverMeta === void 0 ? false : _favorTitleTemplateOverMeta, _favorDescriptionTemplateOverMeta = ref16.favorDescriptionTemplateOverMeta, favorDescriptionTemplateOverMeta = _favorDescriptionTemplateOverMeta === void 0 ? false : _favorDescriptionTemplateOverMeta, _titleTemplate = ref16.titleTemplate, titleTemplate = _titleTemplate === void 0 ? ':title:' : _titleTemplate, _descriptionTemplate = ref16.descriptionTemplate, descriptionTemplate = _descriptionTemplate === void 0 ? ':description:' : _descriptionTemplate, _withShortTitle = ref16.withShortTitle, withShortTitle = _withShortTitle === void 0 ? false : _withShortTitle;
37
37
  var ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13, ref14;
38
38
  var ref15 = (0, _useProduct).useProductState(), selectedVariant = ref15.selectedVariant, metaData = ref15.metaData, seoData = ref15.seoData;
39
39
  var domain = (0, _useConfig).useConfigState().domain;
40
40
  var description = (0, _utils).escape(seoData.description || metaData.shortDescription || truncateToCharLength(metaData === null || metaData === void 0 ? void 0 : metaData.description, 200) || '');
41
- var title = seoData.title || metaData.name || '';
41
+ var title = withShortTitle ? metaData.name || '' : seoData.title || metaData.name || '';
42
42
  var price = (0, _usePrice).usePrice({
43
43
  price: selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref1 = selectedVariant.offer) === null || ref1 === void 0 ? void 0 : ref1.originalPrice
44
44
  }).price;
@@ -63,7 +63,7 @@ function ProductSEO() {
63
63
  type: "application/ld+json",
64
64
  dangerouslySetInnerHTML: (0, _utils).createDangerousMarkup(productJSONLd)
65
65
  })), /*#__PURE__*/ _react.default.createElement(_basicSEO.BasicSEO, {
66
- title: formattedTitle,
66
+ title: withShortTitle ? title : formattedTitle,
67
67
  description: formattedDescription,
68
68
  keywords: seoData.keywords
69
69
  }), /*#__PURE__*/ _react.default.createElement(_openGraph.OpenGraph, {
@@ -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, canUseDOM, getLocaleFromPath } 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, {
@@ -43,18 +43,18 @@ export var getSDKConfig = function() {
43
43
  };
44
44
  export var getOptions = function() {
45
45
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
46
- var ref;
47
- var basePath = process.env.NEXT_PUBLIC_PROXY_URL + ((ref = options === null || options === void 0 ? void 0 : options.basePath) !== null && ref !== void 0 ? ref : '/platform');
48
46
  if (!canUseDOM()) {
49
47
  // eslint-disable-next-line @typescript-eslint/no-var-requires
50
48
  var nodeFetch = require('node-fetch');
49
+ var ref;
51
50
  return _objectSpread({}, options, {
52
- basePath: basePath,
51
+ basePath: process.env.PLATFORM_HOST + ((ref = options === null || options === void 0 ? void 0 : options.basePath) !== null && ref !== void 0 ? ref : '/api'),
53
52
  fetchApi: nodeFetch
54
53
  }, process.env.sdkConfig || {});
55
54
  } else {
55
+ var ref2;
56
56
  return _objectSpread({}, options, {
57
- basePath: basePath,
57
+ basePath: (ref2 = options === null || options === void 0 ? void 0 : options.basePath) !== null && ref2 !== void 0 ? ref2 : '/api',
58
58
  token: Cookies.get(AUTH_TOKEN_KEY) || Cookies.get(ANONYMOUS_TOKEN_KEY) || process.env.API_KEY || process.env.apiKey,
59
59
  fetchApi: window.fetch.bind(window)
60
60
  }, process.env.sdkConfig || {});
@@ -7,7 +7,7 @@ import { useProductVariants } from '../useProductVariants';
7
7
  var ProductStateContext = /*#__PURE__*/ React.createContext(undefined);
8
8
  var CountDispatchContext = /*#__PURE__*/ React.createContext(undefined);
9
9
  export function ProductProvider(param) {
10
- var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName;
10
+ var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName, _withShortTitle = param.withShortTitle, withShortTitle = _withShortTitle === void 0 ? false : _withShortTitle;
11
11
  var ref38 = useProductVariants({
12
12
  product: product,
13
13
  defaultVariantId: defaultVariantId
@@ -18,7 +18,7 @@ export function ProductProvider(param) {
18
18
  var rootCategoryId = rootCategory === null || rootCategory === void 0 ? void 0 : rootCategory.resourceId;
19
19
  var metaObj = {
20
20
  _id: product === null || product === void 0 ? void 0 : product._id,
21
- name: includeBrandInName && (product === null || product === void 0 ? void 0 : (ref1 = product.brands) === null || ref1 === void 0 ? void 0 : (ref2 = ref1[0]) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.resource) === null || ref3 === void 0 ? void 0 : ref3.name) ? "".concat(getTranslatableField(product === null || product === void 0 ? void 0 : (ref4 = product.brands) === null || ref4 === void 0 ? void 0 : (ref5 = ref4[0]) === null || ref5 === void 0 ? void 0 : (ref6 = ref5.resource) === null || ref6 === void 0 ? void 0 : ref6.name), " ").concat(getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name)) : getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
21
+ name: includeBrandInName && !withShortTitle && (product === null || product === void 0 ? void 0 : (ref1 = product.brands) === null || ref1 === void 0 ? void 0 : (ref2 = ref1[0]) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.resource) === null || ref3 === void 0 ? void 0 : ref3.name) ? "".concat(getTranslatableField(product === null || product === void 0 ? void 0 : (ref4 = product.brands) === null || ref4 === void 0 ? void 0 : (ref5 = ref4[0]) === null || ref5 === void 0 ? void 0 : (ref6 = ref5.resource) === null || ref6 === void 0 ? void 0 : ref6.name), " ").concat(getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name)) : getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
22
22
  slug: getTranslatableField(product === null || product === void 0 ? void 0 : product.slug),
23
23
  description: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.description) || getTranslatableField(product === null || product === void 0 ? void 0 : product.description),
24
24
  shortDescription: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.metaDescription) || getTranslatableField(product === null || product === void 0 ? void 0 : product.metaDescription),
@@ -18,17 +18,17 @@ import { useConfigState } from '../../../hooks/useConfig';
18
18
  *
19
19
  */ var truncateToCharLength = function(text, maxLenChars) {
20
20
  var separator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ' ';
21
- var cut = text.indexOf(separator, maxLenChars);
21
+ var cut = text === null || text === void 0 ? void 0 : text.indexOf(separator, maxLenChars);
22
22
  if (cut === -1) return text;
23
- return text.substring(0, cut);
23
+ return text === null || text === void 0 ? void 0 : text.substring(0, cut);
24
24
  };
25
25
  export function ProductSEO() {
26
- var ref16 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _favorTitleTemplateOverMeta = ref16.favorTitleTemplateOverMeta, favorTitleTemplateOverMeta = _favorTitleTemplateOverMeta === void 0 ? false : _favorTitleTemplateOverMeta, _favorDescriptionTemplateOverMeta = ref16.favorDescriptionTemplateOverMeta, favorDescriptionTemplateOverMeta = _favorDescriptionTemplateOverMeta === void 0 ? false : _favorDescriptionTemplateOverMeta, _titleTemplate = ref16.titleTemplate, titleTemplate = _titleTemplate === void 0 ? ':title:' : _titleTemplate, _descriptionTemplate = ref16.descriptionTemplate, descriptionTemplate = _descriptionTemplate === void 0 ? ':description:' : _descriptionTemplate;
26
+ var ref16 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _favorTitleTemplateOverMeta = ref16.favorTitleTemplateOverMeta, favorTitleTemplateOverMeta = _favorTitleTemplateOverMeta === void 0 ? false : _favorTitleTemplateOverMeta, _favorDescriptionTemplateOverMeta = ref16.favorDescriptionTemplateOverMeta, favorDescriptionTemplateOverMeta = _favorDescriptionTemplateOverMeta === void 0 ? false : _favorDescriptionTemplateOverMeta, _titleTemplate = ref16.titleTemplate, titleTemplate = _titleTemplate === void 0 ? ':title:' : _titleTemplate, _descriptionTemplate = ref16.descriptionTemplate, descriptionTemplate = _descriptionTemplate === void 0 ? ':description:' : _descriptionTemplate, _withShortTitle = ref16.withShortTitle, withShortTitle = _withShortTitle === void 0 ? false : _withShortTitle;
27
27
  var ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13, ref14;
28
28
  var ref15 = useProductState(), selectedVariant = ref15.selectedVariant, metaData = ref15.metaData, seoData = ref15.seoData;
29
29
  var domain = useConfigState().domain;
30
30
  var description = escape(seoData.description || metaData.shortDescription || truncateToCharLength(metaData === null || metaData === void 0 ? void 0 : metaData.description, 200) || '');
31
- var title = seoData.title || metaData.name || '';
31
+ var title = withShortTitle ? metaData.name || '' : seoData.title || metaData.name || '';
32
32
  var price = usePrice({
33
33
  price: selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref1 = selectedVariant.offer) === null || ref1 === void 0 ? void 0 : ref1.originalPrice
34
34
  }).price;
@@ -53,7 +53,7 @@ export function ProductSEO() {
53
53
  type: "application/ld+json",
54
54
  dangerouslySetInnerHTML: createDangerousMarkup(productJSONLd)
55
55
  })), /*#__PURE__*/ React.createElement(BasicSEO, {
56
- title: formattedTitle,
56
+ title: withShortTitle ? title : formattedTitle,
57
57
  description: formattedDescription,
58
58
  keywords: seoData.keywords
59
59
  }), /*#__PURE__*/ React.createElement(OpenGraph, {
@@ -55,6 +55,7 @@ declare type ProductProviderProps = {
55
55
  project?: string;
56
56
  };
57
57
  includeBrandInName?: boolean;
58
+ withShortTitle?: boolean;
58
59
  };
59
60
  declare type ProductStateContextType = {
60
61
  attributeRules: AttributeRulesMap;
@@ -91,7 +92,7 @@ declare type CountFunctionsContextType = {
91
92
  };
92
93
  getProductVideos: () => VideoType[];
93
94
  };
94
- export declare function ProductProvider({ product, children, defaultVariantId, includeBrandInName, }: ProductProviderProps): JSX.Element;
95
+ export declare function ProductProvider({ product, children, defaultVariantId, includeBrandInName, withShortTitle, }: ProductProviderProps): JSX.Element;
95
96
  export declare function useProductState(): ProductStateContextType;
96
97
  export declare function useProductFunctions(): CountFunctionsContextType;
97
98
  export declare function useProduct(slug: string, config?: getProductBySlugConfig): import("react-query").QueryResult<ProductDTO, unknown>;
@@ -1,6 +1,7 @@
1
- export declare function ProductSEO({ favorTitleTemplateOverMeta, favorDescriptionTemplateOverMeta, titleTemplate, descriptionTemplate, }?: {
1
+ export declare function ProductSEO({ favorTitleTemplateOverMeta, favorDescriptionTemplateOverMeta, titleTemplate, descriptionTemplate, withShortTitle, }?: {
2
2
  favorTitleTemplateOverMeta?: boolean;
3
3
  favorDescriptionTemplateOverMeta?: boolean;
4
4
  titleTemplate?: string;
5
5
  descriptionTemplate?: string;
6
+ withShortTitle?: boolean;
6
7
  }): JSX.Element;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentecacommerce-theme/lib",
3
3
  "sideEffects": false,
4
- "version": "0.13.21-alpha.0+1eaf982",
4
+ "version": "0.13.21",
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": "1eaf9822c6a7e00f5e893efbe7b4d74adac6ead9",
34
+ "gitHead": "b2055eb08ee6b288207b4745eeb2d632bb2bc872",
35
35
  "peerDependencies": {
36
36
  "react-query": "^2.26.2"
37
37
  },
38
38
  "dependencies": {
39
- "@sentecacommerce-theme/base": "^0.13.21-alpha.0+1eaf982",
40
- "@sentecacommerce-theme/cms": "^0.13.21-alpha.0+1eaf982",
39
+ "@sentecacommerce-theme/base": "^0.13.21",
40
+ "@sentecacommerce-theme/cms": "^0.13.21",
41
41
  "@sentecacommerce/sdk": "2.0.175",
42
42
  "body-scroll-lock": "^3.1.5",
43
43
  "copy-to-clipboard": "^3.3.1",