@gem-sdk/pages 1.23.0-staging.358 → 1.23.0-staging.387

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.
@@ -6,7 +6,7 @@ var jsxRuntime = require('react/jsx-runtime');
6
6
  var react = require('react');
7
7
  var core = require('@gem-sdk/core');
8
8
 
9
- const ACTIONS_DATA = [
9
+ const BASE_DATA = [
10
10
  {
11
11
  title: 'Choose templates',
12
12
  content: 'inspired by CRO experts',
@@ -26,6 +26,14 @@ const ACTIONS_DATA = [
26
26
  id: 'gps-add-section-bottom-from-image'
27
27
  }
28
28
  ];
29
+ const POST_PURCHASE_PAGE_DATA = [
30
+ {
31
+ title: 'Blank section',
32
+ content: 'to start from scratch',
33
+ hasAILogo: false,
34
+ id: 'gps-add-section-blank'
35
+ }
36
+ ];
29
37
  const FOOTER_HEIGHT = 48;
30
38
  const defaultPadding = {
31
39
  desktop: 'var(--g-ct-p)',
@@ -37,6 +45,14 @@ const AddSectionImageToLayout = ({ editorImageToLayout })=>{
37
45
  const totalSection = core.useBuilderPreviewStore((state)=>state.state.ROOT.childrens?.length);
38
46
  const [link, setLink] = react.useState('');
39
47
  const [isInput, setIsInput] = react.useState(false);
48
+ const editingPageType = core.useShopStore((s)=>s.pageType);
49
+ let ACTIONS_DATA = BASE_DATA;
50
+ if (editingPageType === 'POST_PURCHASE') {
51
+ ACTIONS_DATA = [
52
+ ...POST_PURCHASE_PAGE_DATA,
53
+ ...BASE_DATA
54
+ ].filter((item)=>item.id !== 'gps-add-section-bottom-from-url' && item.id !== 'gps-add-section-bottom-from-image');
55
+ }
40
56
  react.useEffect(()=>{
41
57
  if (!isInput || totalSection === 0) {
42
58
  setLink('');
package/dist/cjs/index.js CHANGED
@@ -7,11 +7,13 @@ var getPreviewProps = require('./libs/api/get-preview-props.js');
7
7
  var getBuilderProps = require('./libs/api/get-builder-props.js');
8
8
  var getProductProps = require('./libs/api/get-product-props.js');
9
9
  var getStaticPagePropsV2 = require('./libs/api/get-static-page-props-v2.js');
10
+ var getPostPurchasePropsPreview = require('./libs/api/get-post-purchase-props-preview.js');
10
11
  var getStaticPagePropsPreview = require('./libs/api/get-static-page-props-preview.js');
11
12
  var fetcher = require('./libs/fetcher.js');
12
13
  var getLayout = require('./libs/get-layout.js');
13
14
  var genCss = require('./libs/helpers/gen-css.js');
14
15
  var useTrackingView = require('./libs/hooks/use-tracking-view.js');
16
+ var usePagePreview = require('./libs/hooks/usePagePreview.js');
15
17
  var userAgent = require('./libs/helpers/user-agent.js');
16
18
  var normalize = require('./libs/helpers/normalize.js');
17
19
  var getFallback = require('./libs/helpers/get-fallback.js');
@@ -43,12 +45,15 @@ exports.getPreviewProps = getPreviewProps.getPreviewProps;
43
45
  exports.getBuilderProps = getBuilderProps.getBuilderProps;
44
46
  exports.getProductProps = getProductProps.getProductProps;
45
47
  exports.getStaticPagePropsV2 = getStaticPagePropsV2.getStaticPagePropsV2;
48
+ exports.getPostPurchasePropsPreview = getPostPurchasePropsPreview.getPostPurchasePropsPreview;
46
49
  exports.getStaticPagePropsPreview = getStaticPagePropsPreview.getStaticPagePropsPreview;
50
+ exports.createAppAPIFetcher = fetcher.createAppAPIFetcher;
47
51
  exports.createFetcher = fetcher.createFetcher;
48
52
  exports.createShopifyFetcher = fetcher.createShopifyFetcher;
49
53
  exports.getLayout = getLayout.getLayout;
50
54
  exports.genCSS = genCss.genCSS;
51
55
  exports.useTrackingView = useTrackingView.useTrackingView;
56
+ exports.usePagePreview = usePagePreview.usePagePreview;
52
57
  exports.isBot = userAgent.isBot;
53
58
  exports.normalizePageSectionResponseV2 = normalize.normalizePageSectionResponseV2;
54
59
  exports.parseBuilderTemplateV2 = normalize.parseBuilderTemplateV2;
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ var core = require('@gem-sdk/core');
4
+ var adapterShopify = require('@gem-sdk/adapter-shopify');
5
+ var nextjs = require('@sentry/nextjs');
6
+ var googleFonts = require('../google-fonts.js');
7
+ var getFallback = require('../helpers/get-fallback.js');
8
+ var normalize = require('../helpers/normalize.js');
9
+ var usePagePreview = require('../hooks/usePagePreview.js');
10
+ var parseJson = require('../helpers/parse-json.js');
11
+
12
+ const fetchThemePageDataByID = async (themePageId, fetcher, shopifyFetcher)=>{
13
+ const variables = {
14
+ themePageId
15
+ };
16
+ const [theme, storeProperty, shopifyMeta] = await Promise.allSettled([
17
+ fetcher([
18
+ core.ThemePageDocument,
19
+ variables
20
+ ]),
21
+ fetcher([
22
+ core.StorePropertyDocument
23
+ ]),
24
+ shopifyFetcher([
25
+ adapterShopify.ShopMetaDocument
26
+ ])
27
+ ]);
28
+ if (theme.status === 'rejected') {
29
+ throw new Error(theme.reason?.[0]);
30
+ }
31
+ return {
32
+ dataBuilder: theme.value.themePage,
33
+ storeProperty,
34
+ shopifyMeta
35
+ };
36
+ };
37
+ const fetchThemePageDataByTemplateID = async (libraryTemplateId, fetcher, shopifyFetcher)=>{
38
+ const variables = {
39
+ libraryTemplateId
40
+ };
41
+ const [theme, storeProperty, shopifyMeta] = await Promise.allSettled([
42
+ fetcher([
43
+ core.LibraryTemplateDocument,
44
+ variables
45
+ ]),
46
+ fetcher([
47
+ core.StorePropertyDocument
48
+ ]),
49
+ shopifyFetcher([
50
+ adapterShopify.ShopMetaDocument
51
+ ])
52
+ ]);
53
+ if (theme.status === 'rejected') {
54
+ throw new Error(theme.reason?.[0]);
55
+ }
56
+ return {
57
+ dataBuilder: theme.value.libraryTemplate,
58
+ storeProperty,
59
+ shopifyMeta
60
+ };
61
+ };
62
+ const getPostPurchasePropsPreview = (fetcher, shopifyFetcher, isTemplate)=>async (id)=>{
63
+ try {
64
+ const { dataBuilder, storeProperty, shopifyMeta } = isTemplate ? await fetchThemePageDataByTemplateID(id, fetcher, shopifyFetcher) : await fetchThemePageDataByID(id, fetcher, shopifyFetcher);
65
+ if (!dataBuilder) {
66
+ throw new Error(`No data builder found for slug: /preview/${id}`);
67
+ }
68
+ const pageTemplate = normalize.parseBuilderTemplateV2(dataBuilder);
69
+ const [elementFontStyle, fallback] = await Promise.all([
70
+ googleFonts.getFontStyleFromPageTemplate(pageTemplate),
71
+ getFallback.getFallbackV2(fetcher, pageTemplate)
72
+ ]);
73
+ const { seo, pageConfig } = usePagePreview.usePagePreview(dataBuilder, storeProperty, shopifyMeta);
74
+ return parseJson.serializableJson({
75
+ seo,
76
+ ...pageConfig,
77
+ elementFontStyle,
78
+ builderData: pageTemplate,
79
+ pageType: 'POST_PURCHASE',
80
+ swr: {
81
+ fallback
82
+ }
83
+ });
84
+ } catch (err) {
85
+ nextjs.captureException(err);
86
+ throw err;
87
+ }
88
+ };
89
+
90
+ exports.fetchThemePageDataByID = fetchThemePageDataByID;
91
+ exports.fetchThemePageDataByTemplateID = fetchThemePageDataByTemplateID;
92
+ exports.getPostPurchasePropsPreview = getPostPurchasePropsPreview;
@@ -32,6 +32,38 @@ const createFetcher = (token)=>{
32
32
  });
33
33
  };
34
34
  };
35
+ const createAppAPIFetcher = (token, shopID)=>{
36
+ const shopToken = token;
37
+ const endPoint = process.env.NEXT_APP_API_URL;
38
+ return async (args)=>{
39
+ const [query, variables, operationName] = args;
40
+ if (!shopToken) {
41
+ throw new Error('shopToken is not defined');
42
+ }
43
+ if (!endPoint) {
44
+ throw new Error('NEXT_APP_API_URL is not defined');
45
+ }
46
+ const headers = {
47
+ 'Content-Type': 'application/json',
48
+ Authorization: `Token ${shopToken}`,
49
+ 'X-GemX-Shop-ID': shopID || ''
50
+ };
51
+ return fetch(endPoint, {
52
+ method: 'POST',
53
+ headers,
54
+ body: JSON.stringify({
55
+ query,
56
+ variables,
57
+ operationName
58
+ })
59
+ }).then((res)=>res.json()).then((res)=>{
60
+ if (res.errors) {
61
+ return Promise.reject(res.errors);
62
+ }
63
+ return res.data;
64
+ });
65
+ };
66
+ };
35
67
  const createShopifyFetcher = (storefrontToken, handle)=>{
36
68
  const token = storefrontToken ?? process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
37
69
  const storefrontHandle = handle ?? process.env.NEXT_PUBLIC_STOREFRONT_HANDLE;
@@ -63,5 +95,6 @@ const createShopifyFetcher = (storefrontToken, handle)=>{
63
95
  };
64
96
  };
65
97
 
98
+ exports.createAppAPIFetcher = createAppAPIFetcher;
66
99
  exports.createFetcher = createFetcher;
67
100
  exports.createShopifyFetcher = createShopifyFetcher;
@@ -2,20 +2,6 @@
2
2
 
3
3
  var genFonts = require('./helpers/gen-fonts.js');
4
4
 
5
- const CHROME_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36';
6
- const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
7
- async function getFontForUA(url, UA) {
8
- return fetch(url, {
9
- headers: {
10
- 'User-Agent': UA
11
- }
12
- }).then((res)=>{
13
- if (res.status === 200) {
14
- return res.text();
15
- }
16
- return '';
17
- });
18
- }
19
5
  const composeFonts = (fonts)=>{
20
6
  const uniqFonts = fonts.filter((font, index, arr)=>{
21
7
  return index === arr.findIndex((t)=>t.family === font.family);
@@ -56,31 +42,19 @@ const createFontUrl = (fonts, option)=>{
56
42
  }
57
43
  return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
58
44
  };
59
- async function getFonts(fonts, option, maxSize) {
45
+ async function getFonts(fonts, option) {
60
46
  /**
61
47
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
62
48
  * CSS cascading 🤷‍♂️.
63
49
  */ const url = createFontUrl(fonts, option);
64
50
  if (!url) return '';
65
51
  try {
66
- const [ie, chrome] = await Promise.all([
67
- getFontForUA(url, IE_UA),
68
- getFontForUA(url, CHROME_UA)
69
- ]);
70
- const value = ie + chrome;
71
- if (maxSize) {
72
- const textEncoder = new TextEncoder();
73
- const size = value ? textEncoder.encode(value).length : 0;
74
- if (Math.ceil(size / 1024) >= maxSize) {
75
- return `@import url('${url}');`;
76
- }
77
- }
78
- return value;
52
+ return `@import url('${url}');`;
79
53
  } catch (e) {
80
54
  return '';
81
55
  }
82
56
  }
83
- const getFontFromGlobalStyle = (data, maxSize)=>{
57
+ const getFontFromGlobalStyle = (data)=>{
84
58
  if (!data) return '';
85
59
  try {
86
60
  const globalStyle = JSON.parse(data);
@@ -88,7 +62,7 @@ const getFontFromGlobalStyle = (data, maxSize)=>{
88
62
  const fonts = Object.entries(fontData).map(([, value])=>{
89
63
  return value;
90
64
  });
91
- return getFonts(fonts, undefined, maxSize);
65
+ return getFonts(fonts);
92
66
  } catch {
93
67
  return '';
94
68
  }
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ var generateManifres = require('../helpers/generate-manifres.js');
4
+ var parseJson = require('../helpers/parse-json.js');
5
+
6
+ const usePagePreview = (dataBuilder, storeProperty, shopifyMeta)=>{
7
+ const mobileOnly = dataBuilder?.isMobile ?? false;
8
+ const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
9
+ const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
10
+ const favicon = shopData?.storeProperty?.favicon ?? '/favicon/favicon-32x32.png';
11
+ const languageIsoCode = shopMeta?.localization.language.isoCode ?? null;
12
+ const countryIsoCode = shopMeta?.localization.country.isoCode ?? null;
13
+ const moneyFormat = shopMeta?.shop.moneyFormat ?? null;
14
+ const currency = shopMeta?.localization.country.currency.isoCode ?? null;
15
+ const swatches = parseJson.parseJson(shopData?.storeProperty?.swatchesConfig);
16
+ const locale = !languageIsoCode || !countryIsoCode ? null : `${languageIsoCode}-${countryIsoCode}`;
17
+ const seo = {
18
+ defaultTitle: shopMeta?.shop.name,
19
+ title: dataBuilder?.name,
20
+ openGraph: {
21
+ site_name: shopMeta?.shop.name,
22
+ locale: shopMeta?.localization.country.isoCode,
23
+ title: dataBuilder?.name ?? shopMeta?.shop.name
24
+ },
25
+ nofollow: true,
26
+ noindex: true,
27
+ canonical: `/preview/${dataBuilder?.id}`,
28
+ additionalMetaTags: [
29
+ {
30
+ name: 'theme-color',
31
+ content: '#000000'
32
+ }
33
+ ],
34
+ additionalLinkTags: [
35
+ {
36
+ rel: 'icon',
37
+ sizes: '32x32',
38
+ href: `${favicon}-/crop/1:1/center/-/smart_resize/32x32/`
39
+ },
40
+ {
41
+ rel: 'icon',
42
+ sizes: '16x16',
43
+ href: `${favicon}-/crop/1:1/center/-/smart_resize/16x16/`
44
+ },
45
+ {
46
+ rel: 'apple-touch-icon',
47
+ sizes: '180x180',
48
+ href: `${favicon}-/crop/1:1/center/-/smart_resize/180x180/`
49
+ },
50
+ {
51
+ rel: 'manifest',
52
+ href: generateManifres.generateManifest({
53
+ theme_color: '#000000',
54
+ background_color: '#ffffff',
55
+ display: 'standalone',
56
+ scope: '/',
57
+ start_url: '/',
58
+ name: shopMeta?.shop.name,
59
+ short_name: shopMeta?.shop.name,
60
+ description: shopMeta?.shop.description,
61
+ icons: [
62
+ {
63
+ src: `${favicon}-/crop/1:1/center/-/smart_resize/192x192/`,
64
+ sizes: '192x192',
65
+ type: 'image/png',
66
+ purpose: 'any maskable'
67
+ },
68
+ {
69
+ src: `${favicon}-/crop/1:1/center/-/smart_resize/512x512/`,
70
+ sizes: '512x512',
71
+ type: 'image/png'
72
+ }
73
+ ]
74
+ })
75
+ }
76
+ ]
77
+ };
78
+ return {
79
+ seo,
80
+ pageConfig: {
81
+ mobileOnly,
82
+ locale,
83
+ languageIsoCode,
84
+ countryIsoCode,
85
+ moneyFormat,
86
+ currency,
87
+ swatches
88
+ }
89
+ };
90
+ };
91
+
92
+ exports.usePagePreview = usePagePreview;
@@ -16,6 +16,9 @@ var Toolbar = require('../components/builder/Toolbar.js');
16
16
 
17
17
  const BuilderPage = ({ components, seo, themeStyle, fontStyle, sectionData, pageType, editorImageToLayout, isThemeSectionEditor, hiddenToolbar })=>{
18
18
  const [loadSuccess, setLoadSuccess] = react.useState(false);
19
+ const isDisableHeaderFooter = ()=>{
20
+ return isThemeSectionEditor;
21
+ };
19
22
  const initState = react.useMemo(()=>({
20
23
  ROOT: {
21
24
  uid: 'ROOT',
@@ -65,12 +68,14 @@ const BuilderPage = ({ components, seo, themeStyle, fontStyle, sectionData, page
65
68
  loadSuccess && /*#__PURE__*/ jsxRuntime.jsxs("div", {
66
69
  className: "builder gp-z-1 gp-relative",
67
70
  children: [
68
- !hiddenToolbar && (isThemeSectionEditor ? /*#__PURE__*/ jsxRuntime.jsx("div", {
69
- className: "gp-h-[40px] gp-bg-[#f4f4f4]"
70
- }) : /*#__PURE__*/ jsxRuntime.jsx(Header.default, {})),
71
+ !hiddenToolbar && (isDisableHeaderFooter() ? /*#__PURE__*/ jsxRuntime.jsx("div", {
72
+ className: "h-[40px] bg-[#f4f4f4]"
73
+ }) : /*#__PURE__*/ jsxRuntime.jsx(Header.default, {
74
+ pageType: pageType
75
+ })),
71
76
  /*#__PURE__*/ jsxRuntime.jsx("div", {
72
77
  id: "storefront",
73
- className: isThemeSectionEditor ? 'theme-section-editor' : '',
78
+ className: `${isThemeSectionEditor ? 'theme-section-editor' : ''} ${pageType === 'POST_PURCHASE' ? 'post-purchase-page' : ''}`,
74
79
  children: pageType === 'GP_COLLECTION' ? /*#__PURE__*/ jsxRuntime.jsx(CollectionGlobalProvider.default, {
75
80
  children: /*#__PURE__*/ jsxRuntime.jsx(core.RenderPreview, {
76
81
  uid: "ROOT"
@@ -88,7 +93,9 @@ const BuilderPage = ({ components, seo, themeStyle, fontStyle, sectionData, page
88
93
  /*#__PURE__*/ jsxRuntime.jsx("div", {
89
94
  id: "visual-content"
90
95
  }),
91
- !isThemeSectionEditor && !hiddenToolbar && /*#__PURE__*/ jsxRuntime.jsx(Footer.default, {})
96
+ !isDisableHeaderFooter() && !hiddenToolbar && /*#__PURE__*/ jsxRuntime.jsx(Footer.default, {
97
+ pageType: pageType
98
+ })
92
99
  ]
93
100
  })
94
101
  ]
@@ -7,8 +7,10 @@ var Head = require('next/head');
7
7
  var router = require('next/router');
8
8
  var useTrackingView = require('../libs/hooks/use-tracking-view.js');
9
9
  var parseHtml = require('../libs/parse-html.js');
10
+ var Header = require('../components/Header.js');
11
+ var FooterForPostPurchase = require('../components/FooterForPostPurchase.js');
10
12
 
11
- const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, elementFontStyle, customCodeHeader, shopToken, pageHandle })=>{
13
+ const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, elementFontStyle, customCodeHeader, shopToken, pageHandle, isPostPurchase, shopName })=>{
12
14
  const router$1 = router.useRouter();
13
15
  useTrackingView.useTrackingView(shopToken, pageHandle, router$1.isFallback);
14
16
  if (router$1.isFallback) {
@@ -62,19 +64,28 @@ const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, f
62
64
  ]
63
65
  }),
64
66
  /*#__PURE__*/ jsxRuntime.jsx(core.PageProvider, {
65
- children: /*#__PURE__*/ jsxRuntime.jsx(core.BuilderComponentProvider, {
67
+ children: /*#__PURE__*/ jsxRuntime.jsxs(core.BuilderComponentProvider, {
66
68
  components: components,
67
- children: /*#__PURE__*/ jsxRuntime.jsx(core.SectionProvider, {
68
- data: sectionData,
69
- children: builderData?.map((builder)=>/*#__PURE__*/ jsxRuntime.jsx(core.BuilderProvider, {
70
- state: builder.data,
71
- lazy: builder.lazy,
72
- priority: builder.priority,
73
- children: /*#__PURE__*/ jsxRuntime.jsx(core.Render, {
74
- uid: builder.uid
75
- })
76
- }, builder.uid))
77
- })
69
+ children: [
70
+ isPostPurchase && /*#__PURE__*/ jsxRuntime.jsx(Header.default, {
71
+ pageType: "POST_PURCHASE"
72
+ }),
73
+ /*#__PURE__*/ jsxRuntime.jsx(core.SectionProvider, {
74
+ data: sectionData,
75
+ children: builderData?.map((builder)=>/*#__PURE__*/ jsxRuntime.jsx(core.BuilderProvider, {
76
+ state: builder.data,
77
+ lazy: builder.lazy,
78
+ priority: builder.priority,
79
+ isPostPurchase: isPostPurchase,
80
+ children: /*#__PURE__*/ jsxRuntime.jsx(core.Render, {
81
+ uid: builder.uid
82
+ })
83
+ }, builder.uid))
84
+ }),
85
+ isPostPurchase && /*#__PURE__*/ jsxRuntime.jsx(FooterForPostPurchase.default, {
86
+ shopName: shopName || ''
87
+ })
88
+ ]
78
89
  })
79
90
  })
80
91
  ]