@gem-sdk/pages 2.0.0-dev.168 → 2.0.0-dev.184

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.
Files changed (32) hide show
  1. package/dist/cjs/components/builder/Header.js +1 -1
  2. package/dist/cjs/constants/index.js +12 -0
  3. package/dist/cjs/layouts/main.js +1 -1
  4. package/dist/cjs/libs/api/get-home-page-props-v2.js +20 -8
  5. package/dist/cjs/libs/api/get-home-page-props.js +15 -3
  6. package/dist/cjs/libs/api/get-static-page-props-preview.js +6 -5
  7. package/dist/cjs/libs/api/get-static-page-props-v2.js +12 -8
  8. package/dist/cjs/libs/api/get-static-page-props.js +16 -3
  9. package/dist/cjs/libs/helpers/get-metafield.js +7 -0
  10. package/dist/cjs/libs/parse-html.js +15 -23
  11. package/dist/cjs/pages/builder.js +22 -13
  12. package/dist/cjs/pages/collection-detail.js +40 -30
  13. package/dist/cjs/pages/product-detail.js +29 -17
  14. package/dist/cjs/pages/static-v2.js +79 -39
  15. package/dist/cjs/pages/static.js +44 -33
  16. package/dist/esm/components/builder/Header.js +1 -1
  17. package/dist/esm/constants/index.js +12 -0
  18. package/dist/esm/layouts/main.js +1 -1
  19. package/dist/esm/libs/api/get-home-page-props-v2.js +21 -9
  20. package/dist/esm/libs/api/get-home-page-props.js +16 -4
  21. package/dist/esm/libs/api/get-static-page-props-preview.js +6 -5
  22. package/dist/esm/libs/api/get-static-page-props-v2.js +12 -8
  23. package/dist/esm/libs/api/get-static-page-props.js +17 -4
  24. package/dist/esm/libs/helpers/get-metafield.js +5 -0
  25. package/dist/esm/libs/parse-html.js +15 -23
  26. package/dist/esm/pages/builder.js +22 -13
  27. package/dist/esm/pages/collection-detail.js +41 -31
  28. package/dist/esm/pages/product-detail.js +30 -18
  29. package/dist/esm/pages/static-v2.js +80 -40
  30. package/dist/esm/pages/static.js +45 -34
  31. package/dist/types/index.d.ts +3 -3
  32. package/package.json +5 -5
@@ -3,53 +3,94 @@
3
3
 
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var core = require('@gem-sdk/core');
6
+ var nextSeo = require('next-seo');
7
+ var Head = require('next/head');
8
+ var router = require('next/router');
6
9
  var useTrackingView = require('../libs/hooks/use-tracking-view.js');
7
10
  var parseHtml = require('../libs/parse-html.js');
8
11
  var Header = require('../components/builder/Header.js');
9
12
  var FooterForPostPurchase = require('../components/FooterForPostPurchase.js');
10
13
  var Script = require('next/script');
14
+ var react = require('react');
11
15
 
12
- const StaticPageV2 = ({ components, builderData, sectionData, themeStyle, fontStyle, elementFontStyle, customCodeHeader, shopToken, pageHandle, customFonts, isPostPurchase, shopName, productOffers, publicStoreFrontData, isPreview, interaction, pageBackground })=>{
16
+ const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, elementFontStyle, customCodeHeader, shopToken, pageHandle, customFonts, isPostPurchase, shopName, productOffers, publicStoreFrontData, isPreview, interaction, pageBackground })=>{
17
+ const router$1 = router.useRouter();
13
18
  const baseAssetURL = process.env.NEXT_GP_BASE_ASSET_URL || 'https://d3kbi0je7pp4lw.cloudfront.net';
14
- useTrackingView.useTrackingView(shopToken, pageHandle);
19
+ useTrackingView.useTrackingView(shopToken, pageHandle, router$1.isFallback);
20
+ const customCodeHeaderID = 'custom-code-header';
21
+ react.useEffect(()=>{
22
+ const customCodeHeaderElement = document.querySelectorAll(`#${customCodeHeaderID}`);
23
+ if (customCodeHeaderElement.length > 1) {
24
+ customCodeHeaderElement.forEach((script, index)=>{
25
+ if (index !== 0) script.remove();
26
+ });
27
+ }
28
+ }, []);
29
+ if (router$1.isFallback) {
30
+ return /*#__PURE__*/ jsxRuntime.jsx("div", {
31
+ className: "gp-flex gp-h-[100vh] gp-items-center gp-justify-center",
32
+ children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
33
+ className: "gp-flex gp-gap-2",
34
+ children: [
35
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
36
+ className: "gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_alternate] gp-rounded-full gp-bg-slate-800"
37
+ }),
38
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
39
+ className: "gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_200ms_linear_alternate] gp-rounded-full gp-bg-slate-800"
40
+ }),
41
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
42
+ className: "gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_500ms_alternate] gp-rounded-full gp-bg-slate-800"
43
+ })
44
+ ]
45
+ })
46
+ });
47
+ }
48
+ const hasInteraction = (interaction?.value || []).length > 0;
15
49
  return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
16
50
  children: [
17
- parseHtml.parseHtml(customCodeHeader),
18
- themeStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
19
- "data-id": "global-style",
20
- type: "text/css",
21
- dangerouslySetInnerHTML: {
22
- __html: themeStyle
23
- }
51
+ /*#__PURE__*/ jsxRuntime.jsx(nextSeo.NextSeo, {
52
+ ...seo
24
53
  }),
25
- fontStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
26
- "data-id": "google-fonts",
27
- type: "text/css",
28
- dangerouslySetInnerHTML: {
29
- __html: fontStyle
30
- }
54
+ /*#__PURE__*/ jsxRuntime.jsxs(Head, {
55
+ children: [
56
+ parseHtml.parseHtml(customCodeHeaderID, customCodeHeader, true),
57
+ themeStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
58
+ "data-id": "global-style",
59
+ type: "text/css",
60
+ dangerouslySetInnerHTML: {
61
+ __html: themeStyle
62
+ }
63
+ }, "global-style"),
64
+ fontStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
65
+ "data-id": "google-fonts",
66
+ type: "text/css",
67
+ dangerouslySetInnerHTML: {
68
+ __html: fontStyle
69
+ }
70
+ }, "google-fonts"),
71
+ elementFontStyle && elementFontStyle.map((fontStyle)=>/*#__PURE__*/ jsxRuntime.jsx("style", {
72
+ "data-id": "google-element-fonts",
73
+ type: "text/css",
74
+ dangerouslySetInnerHTML: {
75
+ __html: fontStyle
76
+ }
77
+ }, fontStyle)),
78
+ customFonts && /*#__PURE__*/ jsxRuntime.jsx("style", {
79
+ "data-id": "custom-element-fonts",
80
+ type: "text/css",
81
+ dangerouslySetInnerHTML: {
82
+ __html: customFonts
83
+ }
84
+ }, fontStyle),
85
+ pageBackground?.isUsePageBackground && pageBackground?.background && /*#__PURE__*/ jsxRuntime.jsx("style", {
86
+ children: `
87
+ body {
88
+ background: ${pageBackground.background};
89
+ }
90
+ `
91
+ }, `page_background_${pageBackground?.background}`)
92
+ ]
31
93
  }),
32
- elementFontStyle && elementFontStyle.map((fontStyle)=>/*#__PURE__*/ jsxRuntime.jsx("style", {
33
- "data-id": "google-element-fonts",
34
- type: "text/css",
35
- dangerouslySetInnerHTML: {
36
- __html: fontStyle
37
- }
38
- }, fontStyle)),
39
- customFonts && /*#__PURE__*/ jsxRuntime.jsx("style", {
40
- "data-id": "custom-element-fonts",
41
- type: "text/css",
42
- dangerouslySetInnerHTML: {
43
- __html: customFonts
44
- }
45
- }, fontStyle),
46
- pageBackground?.isUsePageBackground && pageBackground?.background && /*#__PURE__*/ jsxRuntime.jsx("style", {
47
- children: `
48
- body {
49
- background: ${pageBackground.background};
50
- }
51
- `
52
- }, `page_background_${pageBackground?.background}`),
53
94
  /*#__PURE__*/ jsxRuntime.jsx(core.PageProvider, {
54
95
  productOffers: productOffers,
55
96
  publicStoreFrontData: publicStoreFrontData,
@@ -61,7 +102,7 @@ const StaticPageV2 = ({ components, builderData, sectionData, themeStyle, fontSt
61
102
  isPostPurchase && /*#__PURE__*/ jsxRuntime.jsx(Header.default, {
62
103
  pageType: "POST_PURCHASE"
63
104
  }),
64
- /*#__PURE__*/ jsxRuntime.jsx("div", {
105
+ hasInteraction && /*#__PURE__*/ jsxRuntime.jsx("div", {
65
106
  dangerouslySetInnerHTML: {
66
107
  __html: `<div id="gp-interaction" style="display: none;">${JSON.stringify(interaction?.value || [])}</div>`
67
108
  }
@@ -78,9 +119,8 @@ const StaticPageV2 = ({ components, builderData, sectionData, themeStyle, fontSt
78
119
  /*#__PURE__*/ jsxRuntime.jsx(core.Render, {
79
120
  uid: builder.uid
80
121
  }),
81
- /*#__PURE__*/ jsxRuntime.jsx(Script, {
122
+ hasInteraction && /*#__PURE__*/ jsxRuntime.jsx(Script, {
82
123
  defer: true,
83
- strategy: "lazyOnload",
84
124
  src: `${baseAssetURL}/assets-v2/gp-flow-action-lip.js`
85
125
  })
86
126
  ]
@@ -5,42 +5,53 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var core = require('@gem-sdk/core');
8
- var react = require('react');
8
+ var nextSeo = require('next-seo');
9
+ var Head = require('next/head');
10
+ var router = require('next/router');
9
11
 
10
- const StaticPage = ({ components, builderData, sectionData, themeStyle, fontStyle })=>{
11
- const fallbackContent = /*#__PURE__*/ jsxRuntime.jsx("div", {
12
- className: "gp-flex gp-h-[100vh] gp-items-center gp-justify-center",
13
- children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
14
- className: "gp-flex gp-gap-2",
15
- children: [
16
- /*#__PURE__*/ jsxRuntime.jsx("span", {
17
- className: "gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_alternate] gp-rounded-full gp-bg-slate-800"
18
- }),
19
- /*#__PURE__*/ jsxRuntime.jsx("span", {
20
- className: "gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_200ms_linear_alternate] gp-rounded-full gp-bg-slate-800"
21
- }),
22
- /*#__PURE__*/ jsxRuntime.jsx("span", {
23
- className: "gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_500ms_alternate] gp-rounded-full gp-bg-slate-800"
24
- })
25
- ]
26
- })
27
- });
28
- return /*#__PURE__*/ jsxRuntime.jsxs(react.Suspense, {
29
- fallback: fallbackContent,
12
+ const StaticPage = ({ components, builderData, sectionData, seo, themeStyle, fontStyle })=>{
13
+ const router$1 = router.useRouter();
14
+ if (router$1.isFallback) {
15
+ return /*#__PURE__*/ jsxRuntime.jsx("div", {
16
+ className: "gp-flex gp-h-[100vh] gp-items-center gp-justify-center",
17
+ children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
18
+ className: "gp-flex gp-gap-2",
19
+ children: [
20
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
21
+ className: "gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_alternate] gp-rounded-full gp-bg-slate-800"
22
+ }),
23
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
24
+ className: "gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_200ms_linear_alternate] gp-rounded-full gp-bg-slate-800"
25
+ }),
26
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
27
+ className: "gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_500ms_alternate] gp-rounded-full gp-bg-slate-800"
28
+ })
29
+ ]
30
+ })
31
+ });
32
+ }
33
+ return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
30
34
  children: [
31
- themeStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
32
- "data-id": "global-style",
33
- type: "text/css",
34
- dangerouslySetInnerHTML: {
35
- __html: themeStyle
36
- }
35
+ /*#__PURE__*/ jsxRuntime.jsx(nextSeo.NextSeo, {
36
+ ...seo
37
37
  }),
38
- fontStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
39
- "data-id": "google-fonts",
40
- type: "text/css",
41
- dangerouslySetInnerHTML: {
42
- __html: fontStyle
43
- }
38
+ /*#__PURE__*/ jsxRuntime.jsxs(Head, {
39
+ children: [
40
+ themeStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
41
+ "data-id": "global-style",
42
+ type: "text/css",
43
+ dangerouslySetInnerHTML: {
44
+ __html: themeStyle
45
+ }
46
+ }),
47
+ fontStyle && /*#__PURE__*/ jsxRuntime.jsx("style", {
48
+ "data-id": "google-fonts",
49
+ type: "text/css",
50
+ dangerouslySetInnerHTML: {
51
+ __html: fontStyle
52
+ }
53
+ })
54
+ ]
44
55
  }),
45
56
  /*#__PURE__*/ jsxRuntime.jsx(core.PageProvider, {
46
57
  children: /*#__PURE__*/ jsxRuntime.jsx(core.BuilderComponentProvider, {
@@ -118,7 +118,7 @@ const Header = (props)=>{
118
118
  })
119
119
  ]
120
120
  }),
121
- !isOriginTemplate && /*#__PURE__*/ jsx("button", {
121
+ !(isOriginTemplate || pageType === 'STATIC') && /*#__PURE__*/ jsx("button", {
122
122
  className: "gp-header gp-invisible gp-absolute gp-left-[8px] gp-flex gp-h-[24px] gp-cursor-pointer gp-items-center gp-justify-center gp-rounded gp-bg-[#EEEEEE] gp-p-[4px] hover:gp-bg-[#f4f4f4] group-hover:gp-visible",
123
123
  onClick: openPageSetting,
124
124
  children: /*#__PURE__*/ jsxs("div", {
@@ -0,0 +1,12 @@
1
+ var PublishedThemePageMetafields;
2
+ (function(PublishedThemePageMetafields) {
3
+ PublishedThemePageMetafields["CUSTOM_CODE_HEADER"] = 'custom_code_header';
4
+ PublishedThemePageMetafields["CUSTOM_CODE_BODY"] = 'custom_code_body';
5
+ PublishedThemePageMetafields["ANALYTICS_GA_TRACKING_ID"] = 'analytics_ga_tracking_id';
6
+ PublishedThemePageMetafields["ANALYTICS_FB_PIXEL_ID"] = 'analytics_fb_pixel_id';
7
+ PublishedThemePageMetafields["ANALYTICS_TIKTOK_PIXEL_ID"] = 'analytics_tiktok_pixel_id';
8
+ PublishedThemePageMetafields["GLOBAL_META_DESCRIPTION"] = 'global-meta-description';
9
+ PublishedThemePageMetafields["GLOBAL_META_THUMBNAIL"] = 'global-meta-thumbnail';
10
+ })(PublishedThemePageMetafields || (PublishedThemePageMetafields = {}));
11
+
12
+ export { PublishedThemePageMetafields };
@@ -7,7 +7,7 @@ const MainLayout = ({ children, ...props })=>{
7
7
  const mobileOnly = useShopStore((s)=>s.mobileOnly);
8
8
  return /*#__PURE__*/ jsxs(Fragment, {
9
9
  children: [
10
- parseHtml(props?.customCodeBody),
10
+ parseHtml('custom-code-body', props?.customCodeBody),
11
11
  /*#__PURE__*/ jsx("div", {
12
12
  className: cls({
13
13
  'gp-max-w-mobile gp-mx-auto gp-w-full': mobileOnly
@@ -1,4 +1,4 @@
1
- import { PublishedThemePagesDocument, StorePropertyDocument } from '@gem-sdk/core';
1
+ import { PublishedThemePagesDocument, StorePropertyDocument, PublishedShopMetasDocument } from '@gem-sdk/core';
2
2
  import { ShopMetaDocument } from '@gem-sdk/adapter-shopify';
3
3
  import { getFontStyleFromPageTemplate, getFontFromGlobalStyle } from '../google-fonts.js';
4
4
  import { genCSS } from '../helpers/gen-css.js';
@@ -7,13 +7,15 @@ import { getFallbackV2 } from '../helpers/get-fallback.js';
7
7
  import { parseBuilderTemplateV2 } from '../helpers/normalize.js';
8
8
  import { parseJson, serializableJson } from '../helpers/parse-json.js';
9
9
  import { captureException } from '@sentry/nextjs';
10
+ import { PublishedThemePageMetafields } from '../../constants/index.js';
11
+ import { getPublishedThemePageMetafieldByKey } from '../helpers/get-metafield.js';
10
12
 
11
13
  const getHomePagePropsV2 = (fetcher, shopifyFetcher)=>async ()=>{
12
14
  try {
13
15
  const variables = {
14
16
  slugType: 'STATIC'
15
17
  };
16
- const [theme, storeProperty, shopifyMeta] = await Promise.allSettled([
18
+ const [theme, storeProperty, shopifyMeta, publishedShopMetas] = await Promise.allSettled([
17
19
  fetcher([
18
20
  PublishedThemePagesDocument,
19
21
  variables
@@ -23,11 +25,21 @@ const getHomePagePropsV2 = (fetcher, shopifyFetcher)=>async ()=>{
23
25
  ]),
24
26
  shopifyFetcher([
25
27
  ShopMetaDocument
28
+ ]),
29
+ fetcher([
30
+ PublishedShopMetasDocument,
31
+ {
32
+ keys: [
33
+ PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION,
34
+ PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL
35
+ ]
36
+ }
26
37
  ])
27
38
  ]);
28
39
  if (theme.status === 'rejected') {
29
40
  throw new Error(theme.reason?.[0]);
30
41
  }
42
+ const publishedShopMetaValue = publishedShopMetas.status === 'fulfilled' ? publishedShopMetas.value : undefined;
31
43
  const dataBuilder = theme.value?.publishedThemePages?.[0];
32
44
  if (!dataBuilder) {
33
45
  throw new Error(`No data builder found for Home page`);
@@ -39,8 +51,8 @@ const getHomePagePropsV2 = (fetcher, shopifyFetcher)=>async ()=>{
39
51
  getFallbackV2(fetcher, homeTemplate)
40
52
  ]);
41
53
  const mobileOnly = dataBuilder.isMobile ?? false;
42
- const description = dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-description')?.value;
43
- const thumbnail = parseJson(dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-thumbnail')?.value);
54
+ const description = getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION, dataBuilder?.metafields) || publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION)?.value;
55
+ const thumbnail = parseJson(getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL, dataBuilder?.metafields) || publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL)?.value);
44
56
  const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
45
57
  const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
46
58
  const favicon = shopData?.storeProperty?.favicon ?? '/favicon/favicon-32x32.png';
@@ -127,11 +139,11 @@ const getHomePagePropsV2 = (fetcher, shopifyFetcher)=>async ()=>{
127
139
  swatches: parseJson(shopData?.storeProperty?.swatchesConfig),
128
140
  seo,
129
141
  mobileOnly,
130
- gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
131
- facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
132
- tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
133
- customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
134
- customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
142
+ gaTrackingId: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.ANALYTICS_GA_TRACKING_ID, dataBuilder?.metafields) ?? null,
143
+ facebookPixelId: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.ANALYTICS_FB_PIXEL_ID, dataBuilder?.metafields) ?? null,
144
+ tiktokPixelId: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.ANALYTICS_TIKTOK_PIXEL_ID, dataBuilder?.metafields) ?? null,
145
+ customCodeHeader: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.CUSTOM_CODE_HEADER, dataBuilder?.metafields) ?? null,
146
+ customCodeBody: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.CUSTOM_CODE_BODY, dataBuilder?.metafields) ?? null,
135
147
  pageHandle: dataBuilder.handle ?? null
136
148
  });
137
149
  } catch (err) {
@@ -1,10 +1,12 @@
1
- import { PublishedThemePagesDocument, StorePropertyDocument, prefetchQueries } from '@gem-sdk/core';
1
+ import { PublishedThemePagesDocument, StorePropertyDocument, PublishedShopMetasDocument, prefetchQueries } from '@gem-sdk/core';
2
2
  import { ShopMetaDocument } from '@gem-sdk/adapter-shopify';
3
3
  import { getFontFromGlobalStyle } from '../google-fonts.js';
4
4
  import { genCSS } from '../helpers/gen-css.js';
5
5
  import { generateManifest } from '../helpers/generate-manifres.js';
6
6
  import { parseBuilderTemplate } from '../helpers/normalize.js';
7
7
  import { parseJson, serializableJson } from '../helpers/parse-json.js';
8
+ import { PublishedThemePageMetafields } from '../../constants/index.js';
9
+ import { getPublishedThemePageMetafieldByKey } from '../helpers/get-metafield.js';
8
10
 
9
11
  const getHomePageProps = (fetcher, shopifyFetcher)=>async ()=>{
10
12
  const pageType = 'STATIC';
@@ -15,7 +17,7 @@ const getHomePageProps = (fetcher, shopifyFetcher)=>async ()=>{
15
17
  // PublishedThemePagesDocument,
16
18
  // variables,
17
19
  // ]);
18
- const [theme, storeProperty, shopifyMeta] = await Promise.allSettled([
20
+ const [theme, storeProperty, shopifyMeta, publishedShopMetas] = await Promise.allSettled([
19
21
  fetcher([
20
22
  PublishedThemePagesDocument,
21
23
  variables
@@ -25,6 +27,15 @@ const getHomePageProps = (fetcher, shopifyFetcher)=>async ()=>{
25
27
  ]),
26
28
  shopifyFetcher([
27
29
  ShopMetaDocument
30
+ ]),
31
+ fetcher([
32
+ PublishedShopMetasDocument,
33
+ {
34
+ keys: [
35
+ PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION,
36
+ PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL
37
+ ]
38
+ }
28
39
  ])
29
40
  ]);
30
41
  if (theme.status === 'rejected') {
@@ -32,6 +43,7 @@ const getHomePageProps = (fetcher, shopifyFetcher)=>async ()=>{
32
43
  pageType
33
44
  };
34
45
  }
46
+ const publishedShopMetaValue = publishedShopMetas.status === 'fulfilled' ? publishedShopMetas.value : undefined;
35
47
  const dataBuilder = theme.value.publishedThemePages?.[0];
36
48
  const homeTemplate = parseBuilderTemplate(dataBuilder);
37
49
  const fontStyle = await getFontFromGlobalStyle(dataBuilder?.pageStyle?.data);
@@ -56,8 +68,8 @@ const getHomePageProps = (fetcher, shopifyFetcher)=>async ()=>{
56
68
  }
57
69
  return acc;
58
70
  }, {});
59
- const description = dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-description')?.value;
60
- const thumbnail = parseJson(dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-thumbnail')?.value);
71
+ const description = getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION, dataBuilder?.metafields) || publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION)?.value;
72
+ const thumbnail = parseJson(getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL, dataBuilder?.metafields) || publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL)?.value);
61
73
  const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
62
74
  const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
63
75
  const favicon = shopData?.storeProperty?.favicon ?? '/favicon/favicon-32x32.png';
@@ -43,7 +43,7 @@ const getStaticPagePropsPreview = (fetcher, shopifyFetcher)=>async (slug)=>{
43
43
  getFallbackV2(fetcher, pageTemplate),
44
44
  getCustomFonts(themePageCustomFonts)
45
45
  ]);
46
- const mobileOnly = dataBuilder.isMobile ?? false;
46
+ const mobileOnly = !!dataBuilder.isMobile;
47
47
  const description = dataBuilder?.dataSEO?.find((item)=>item?.key === 'global-meta-description')?.value;
48
48
  const thumbnail = parseJson(dataBuilder?.dataSEO?.find((item)=>item?.key === 'global-meta-thumbnail')?.value);
49
49
  const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
@@ -117,15 +117,15 @@ const getStaticPagePropsPreview = (fetcher, shopifyFetcher)=>async (slug)=>{
117
117
  };
118
118
  const languageIsoCode = shopMeta?.localization.language.isoCode ?? null;
119
119
  const countryIsoCode = shopMeta?.localization.country.isoCode ?? null;
120
- const locale = !languageIsoCode || !countryIsoCode ? null : `${languageIsoCode}-${countryIsoCode}`;
120
+ const locale = languageIsoCode && countryIsoCode ? `${languageIsoCode}-${countryIsoCode}` : null;
121
121
  return serializableJson({
122
122
  themeStyle: genCSS(dataBuilder?.themeStyle?.data, mobileOnly),
123
123
  fontStyle,
124
124
  elementFontStyle,
125
125
  builderData: pageTemplate,
126
126
  pageType,
127
- moneyFormat: shopMeta?.shop.moneyFormat ?? null,
128
- currency: shopMeta?.localization.country.currency.isoCode ?? null,
127
+ moneyFormat: shopMeta?.shop?.moneyFormat ?? null,
128
+ currency: shopMeta?.localization?.country?.currency?.isoCode ?? null,
129
129
  languageIsoCode,
130
130
  countryIsoCode,
131
131
  locale,
@@ -141,7 +141,8 @@ const getStaticPagePropsPreview = (fetcher, shopifyFetcher)=>async (slug)=>{
141
141
  customCodeHeader: dataBuilder.customCode?.header ?? null,
142
142
  customCodeBody: dataBuilder.customCode?.body ?? null,
143
143
  customFonts,
144
- pageBackground: extractPageBackground(dataBuilder)
144
+ pageBackground: extractPageBackground(dataBuilder),
145
+ interaction: dataBuilder?.interaction
145
146
  });
146
147
  } catch (err) {
147
148
  captureException(err);
@@ -8,6 +8,8 @@ import { parseBuilderTemplateV2, extractPageBackground } from '../helpers/normal
8
8
  import { parseJson, serializableJson } from '../helpers/parse-json.js';
9
9
  import { captureException } from '@sentry/nextjs';
10
10
  import { getCustomFonts } from '../custom-fonts.js';
11
+ import { getPublishedThemePageMetafieldByKey } from '../helpers/get-metafield.js';
12
+ import { PublishedThemePageMetafields } from '../../constants/index.js';
11
13
 
12
14
  const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
13
15
  try {
@@ -31,7 +33,9 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
31
33
  PublishedShopMetasDocument,
32
34
  {
33
35
  keys: [
34
- 'source_font'
36
+ 'source_font',
37
+ PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION,
38
+ PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL
35
39
  ]
36
40
  }
37
41
  ])
@@ -54,8 +58,8 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
54
58
  getCustomFonts(themePageCustomFonts)
55
59
  ]);
56
60
  const mobileOnly = dataBuilder.isMobile ?? false;
57
- const description = dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-description')?.value;
58
- const thumbnail = parseJson(dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-thumbnail')?.value);
61
+ const description = getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION, dataBuilder?.metafields) || publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION)?.value;
62
+ const thumbnail = parseJson(getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL, dataBuilder?.metafields) || publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL)?.value);
59
63
  const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
60
64
  const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
61
65
  const favicon = shopData?.storeProperty?.favicon ?? '/favicon/favicon-32x32.png';
@@ -143,11 +147,11 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
143
147
  swatches: parseJson(shopData?.storeProperty?.swatchesConfig),
144
148
  seo,
145
149
  mobileOnly,
146
- gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
147
- facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
148
- tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
149
- customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
150
- customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
150
+ gaTrackingId: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.ANALYTICS_GA_TRACKING_ID, dataBuilder?.metafields) ?? null,
151
+ facebookPixelId: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.ANALYTICS_FB_PIXEL_ID, dataBuilder?.metafields) ?? null,
152
+ tiktokPixelId: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.ANALYTICS_TIKTOK_PIXEL_ID, dataBuilder?.metafields) ?? null,
153
+ customCodeHeader: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.CUSTOM_CODE_HEADER, dataBuilder?.metafields) ?? null,
154
+ customCodeBody: getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.CUSTOM_CODE_BODY, dataBuilder?.metafields) ?? null,
151
155
  pageHandle: dataBuilder.handle ?? null,
152
156
  customFonts,
153
157
  interaction: dataBuilder?.interaction,
@@ -1,10 +1,12 @@
1
- import { PublishedThemePagesDocument, StorePropertyDocument, prefetchQueries } from '@gem-sdk/core';
1
+ import { PublishedThemePagesDocument, StorePropertyDocument, PublishedShopMetasDocument, prefetchQueries } from '@gem-sdk/core';
2
2
  import { ShopMetaDocument } from '@gem-sdk/adapter-shopify';
3
3
  import { getFontFromGlobalStyle } from '../google-fonts.js';
4
4
  import { genCSS } from '../helpers/gen-css.js';
5
5
  import { generateManifest } from '../helpers/generate-manifres.js';
6
6
  import { parseBuilderTemplate } from '../helpers/normalize.js';
7
7
  import { parseJson, serializableJson } from '../helpers/parse-json.js';
8
+ import { PublishedThemePageMetafields } from '../../constants/index.js';
9
+ import { getPublishedThemePageMetafieldByKey } from '../helpers/get-metafield.js';
8
10
 
9
11
  const getStaticPageProps = (fetcher, shopifyFetcher)=>async (slug)=>{
10
12
  const pageType = 'STATIC';
@@ -12,7 +14,7 @@ const getStaticPageProps = (fetcher, shopifyFetcher)=>async (slug)=>{
12
14
  slug,
13
15
  slugType: pageType
14
16
  };
15
- const [theme, storeProperty, shopifyMeta] = await Promise.allSettled([
17
+ const [theme, storeProperty, shopifyMeta, publishedShopMetas] = await Promise.allSettled([
16
18
  fetcher([
17
19
  PublishedThemePagesDocument,
18
20
  variables
@@ -22,6 +24,16 @@ const getStaticPageProps = (fetcher, shopifyFetcher)=>async (slug)=>{
22
24
  ]),
23
25
  shopifyFetcher([
24
26
  ShopMetaDocument
27
+ ]),
28
+ fetcher([
29
+ PublishedShopMetasDocument,
30
+ {
31
+ keys: [
32
+ 'source_font',
33
+ PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION,
34
+ PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL
35
+ ]
36
+ }
25
37
  ])
26
38
  ]);
27
39
  if (theme.status === 'rejected') {
@@ -29,6 +41,7 @@ const getStaticPageProps = (fetcher, shopifyFetcher)=>async (slug)=>{
29
41
  pageType
30
42
  };
31
43
  }
44
+ const publishedShopMetaValue = publishedShopMetas.status === 'fulfilled' ? publishedShopMetas.value : undefined;
32
45
  const dataBuilder = theme.value.publishedThemePages?.[0];
33
46
  const pageTemplate = parseBuilderTemplate(dataBuilder);
34
47
  const fontStyle = await getFontFromGlobalStyle(dataBuilder?.pageStyle?.data);
@@ -53,8 +66,8 @@ const getStaticPageProps = (fetcher, shopifyFetcher)=>async (slug)=>{
53
66
  }
54
67
  return acc;
55
68
  }, {});
56
- const description = dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-description')?.value;
57
- const thumbnail = parseJson(dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-thumbnail')?.value);
69
+ const description = getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION, dataBuilder?.metafields) || publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === PublishedThemePageMetafields.GLOBAL_META_DESCRIPTION)?.value;
70
+ const thumbnail = parseJson(getPublishedThemePageMetafieldByKey(PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL, dataBuilder?.metafields) || publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === PublishedThemePageMetafields.GLOBAL_META_THUMBNAIL)?.value);
58
71
  const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
59
72
  const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
60
73
  const favicon = shopData?.storeProperty?.favicon ?? '/favicon/favicon-32x32.png';
@@ -0,0 +1,5 @@
1
+ const getPublishedThemePageMetafieldByKey = (key, metafields)=>{
2
+ return metafields?.find((item)=>item?.key === key)?.value;
3
+ };
4
+
5
+ export { getPublishedThemePageMetafieldByKey };
@@ -1,34 +1,26 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import parse, { Element, Text } from 'html-react-parser';
3
- import Script from 'next/script';
4
3
 
5
- const parseHtml = (html, isHead)=>{
4
+ const parseHtml = (key, html, isHead)=>{
6
5
  if (!html) return undefined;
7
6
  try {
8
7
  return parse(html, {
9
8
  replace: (node)=>{
10
- if (node.type === 'script' && node instanceof Element) {
11
- const child = node.children?.[0];
12
- if (child instanceof Text) {
13
- if (isHead) return /*#__PURE__*/ jsx("script", {
14
- ...node.attribs,
15
- dangerouslySetInnerHTML: {
16
- __html: child.data
17
- }
18
- });
19
- else return /*#__PURE__*/ jsx(Script, {
20
- ...node.attribs,
21
- dangerouslySetInnerHTML: {
22
- __html: child.data
23
- }
24
- });
25
- } else {
26
- if (!isHead) {
27
- return /*#__PURE__*/ jsx(Script, {
28
- ...node.attribs
29
- });
9
+ if (node.type !== 'script' || !(node instanceof Element)) return null;
10
+ const child = node.children?.[0];
11
+ if (!child) return null;
12
+ if (!(child instanceof Text) && !isHead) return /*#__PURE__*/ jsx("script", {
13
+ id: key,
14
+ ...node.attribs
15
+ }, key);
16
+ if (child instanceof Text && isHead) {
17
+ return /*#__PURE__*/ jsx("script", {
18
+ id: key,
19
+ ...node.attribs,
20
+ dangerouslySetInnerHTML: {
21
+ __html: child.data
30
22
  }
31
- }
23
+ }, key);
32
24
  }
33
25
  }
34
26
  });