@gem-sdk/pages 1.5.7 → 1.5.23

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 (79) hide show
  1. package/dist/cjs/components/ErrorBoundary.js +32 -24
  2. package/dist/cjs/components/ErrorFallback.js +19 -2
  3. package/dist/cjs/components/FacebookPixel.js +25 -20
  4. package/dist/cjs/components/Footer.js +462 -0
  5. package/dist/cjs/components/GoogleAnalytic.js +49 -23
  6. package/dist/cjs/components/Header.js +211 -0
  7. package/dist/cjs/components/TikTokPixel.js +9 -6
  8. package/dist/cjs/components/builder/Toolbox.js +215 -188
  9. package/dist/cjs/layouts/main.js +19 -5
  10. package/dist/cjs/libs/api/get-builder-props.js +26 -24
  11. package/dist/cjs/libs/api/get-collection-props.js +59 -55
  12. package/dist/cjs/libs/api/get-home-page-props-v2.js +121 -114
  13. package/dist/cjs/libs/api/get-home-page-props.js +133 -123
  14. package/dist/cjs/libs/api/get-preview-props.js +10 -10
  15. package/dist/cjs/libs/api/get-product-props.js +64 -62
  16. package/dist/cjs/libs/api/get-static-page-props-preview.js +128 -121
  17. package/dist/cjs/libs/api/get-static-page-props-v2.js +126 -119
  18. package/dist/cjs/libs/api/get-static-page-props.js +130 -120
  19. package/dist/cjs/libs/fetcher.js +59 -63
  20. package/dist/cjs/libs/get-layout.js +5 -2
  21. package/dist/cjs/libs/get-storefront-api.js +7 -7
  22. package/dist/cjs/libs/getStaticPaths.js +5 -5
  23. package/dist/cjs/libs/google-fonts.js +54 -61
  24. package/dist/cjs/libs/helpers/gen-css.js +103 -94
  25. package/dist/cjs/libs/helpers/generate-manifres.js +1 -1
  26. package/dist/cjs/libs/helpers/get-fallback.js +24 -22
  27. package/dist/cjs/libs/helpers/normalize.js +82 -80
  28. package/dist/cjs/libs/helpers/parse-json.js +10 -12
  29. package/dist/cjs/libs/helpers/user-agent.js +2 -2
  30. package/dist/cjs/libs/hooks/use-tracking-view.js +36 -31
  31. package/dist/cjs/libs/parse-html.js +33 -26
  32. package/dist/cjs/pages/404.js +34 -2
  33. package/dist/cjs/pages/500.js +63 -8
  34. package/dist/cjs/pages/builder.js +69 -14
  35. package/dist/cjs/pages/collection-detail.js +48 -7
  36. package/dist/cjs/pages/preview.js +18 -12
  37. package/dist/cjs/pages/product-detail.js +53 -7
  38. package/dist/cjs/pages/static-v2.js +62 -7
  39. package/dist/cjs/pages/static.js +60 -6
  40. package/dist/esm/components/ErrorBoundary.js +32 -24
  41. package/dist/esm/components/ErrorFallback.js +19 -2
  42. package/dist/esm/components/FacebookPixel.js +25 -20
  43. package/dist/esm/components/Footer.js +458 -0
  44. package/dist/esm/components/GoogleAnalytic.js +49 -23
  45. package/dist/esm/components/Header.js +207 -0
  46. package/dist/esm/components/TikTokPixel.js +9 -6
  47. package/dist/esm/components/builder/Toolbox.js +217 -190
  48. package/dist/esm/layouts/main.js +19 -5
  49. package/dist/esm/libs/api/get-builder-props.js +26 -24
  50. package/dist/esm/libs/api/get-collection-props.js +59 -55
  51. package/dist/esm/libs/api/get-home-page-props-v2.js +121 -114
  52. package/dist/esm/libs/api/get-home-page-props.js +133 -123
  53. package/dist/esm/libs/api/get-preview-props.js +10 -10
  54. package/dist/esm/libs/api/get-product-props.js +64 -62
  55. package/dist/esm/libs/api/get-static-page-props-preview.js +128 -121
  56. package/dist/esm/libs/api/get-static-page-props-v2.js +126 -119
  57. package/dist/esm/libs/api/get-static-page-props.js +130 -120
  58. package/dist/esm/libs/fetcher.js +59 -63
  59. package/dist/esm/libs/get-layout.js +5 -2
  60. package/dist/esm/libs/get-storefront-api.js +7 -7
  61. package/dist/esm/libs/getStaticPaths.js +5 -5
  62. package/dist/esm/libs/google-fonts.js +54 -61
  63. package/dist/esm/libs/helpers/gen-css.js +103 -94
  64. package/dist/esm/libs/helpers/generate-manifres.js +1 -1
  65. package/dist/esm/libs/helpers/get-fallback.js +24 -22
  66. package/dist/esm/libs/helpers/normalize.js +82 -80
  67. package/dist/esm/libs/helpers/parse-json.js +10 -12
  68. package/dist/esm/libs/helpers/user-agent.js +2 -2
  69. package/dist/esm/libs/hooks/use-tracking-view.js +36 -31
  70. package/dist/esm/libs/parse-html.js +33 -26
  71. package/dist/esm/pages/404.js +34 -2
  72. package/dist/esm/pages/500.js +63 -8
  73. package/dist/esm/pages/builder.js +69 -14
  74. package/dist/esm/pages/collection-detail.js +48 -7
  75. package/dist/esm/pages/preview.js +18 -12
  76. package/dist/esm/pages/product-detail.js +53 -7
  77. package/dist/esm/pages/static-v2.js +62 -7
  78. package/dist/esm/pages/static.js +60 -6
  79. package/package.json +3 -3
@@ -2,69 +2,65 @@
2
2
 
3
3
  var getStorefrontApi = require('./get-storefront-api.js');
4
4
 
5
- const createFetcher = (token) => {
6
- const shopToken = token || process.env.NEXT_PUBLIC_SHOP_TOKEN;
7
- return async (args) => {
8
- const [query, variables, operationName] = args;
9
- if (!shopToken) {
10
- throw new Error('shopToken is not defined');
11
- }
12
- if (!process.env.NEXT_PUBLIC_API_URL) {
13
- throw new Error('NEXT_PUBLIC_API_URL is not defined');
14
- }
15
- const headers = {
16
- 'Content-Type': 'application/json',
17
- 'X-GemX-Shop-Token': shopToken,
18
- };
19
- return fetch(process.env.NEXT_PUBLIC_API_URL, {
20
- method: 'POST',
21
- headers,
22
- body: JSON.stringify({
23
- query,
24
- variables,
25
- operationName,
26
- }),
27
- })
28
- .then((res) => res.json())
29
- .then((res) => {
30
- if (res.errors) {
31
- return Promise.reject(res.errors);
32
- }
33
- return res.data;
34
- });
35
- };
36
- };
37
- const createShopifyFetcher = (storefrontToken, handle) => {
38
- const token = storefrontToken ?? process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
39
- const storefrontHandle = handle ?? process.env.NEXT_PUBLIC_STOREFRONT_HANDLE;
40
- return async (args) => {
41
- if (!token) {
42
- throw new Error('NEXT_PUBLIC_STOREFRONT_TOKEN is not defined');
43
- }
44
- if (!storefrontHandle) {
45
- throw new Error('NEXT_PUBLIC_STOREFRONT_HANDLE is not defined');
46
- }
47
- const headers = {
48
- 'Content-Type': 'application/json',
49
- 'X-Shopify-Storefront-Access-Token': token,
50
- };
51
- const [query, variables] = args;
52
- return fetch(getStorefrontApi.getStorefrontApi(storefrontHandle), {
53
- method: 'POST',
54
- headers,
55
- body: JSON.stringify({
56
- query,
57
- variables,
58
- }),
59
- })
60
- .then((res) => res.json())
61
- .then((res) => {
62
- if (res.errors) {
63
- return Promise.reject(res.errors);
64
- }
65
- return res.data;
66
- });
67
- };
5
+ const createFetcher = (token)=>{
6
+ const shopToken = token || process.env.NEXT_PUBLIC_SHOP_TOKEN;
7
+ return async (args)=>{
8
+ const [query, variables, operationName] = args;
9
+ if (!shopToken) {
10
+ throw new Error('shopToken is not defined');
11
+ }
12
+ if (!process.env.NEXT_PUBLIC_API_URL) {
13
+ throw new Error('NEXT_PUBLIC_API_URL is not defined');
14
+ }
15
+ const headers = {
16
+ 'Content-Type': 'application/json',
17
+ 'X-GemX-Shop-Token': shopToken
18
+ };
19
+ return fetch(process.env.NEXT_PUBLIC_API_URL, {
20
+ method: 'POST',
21
+ headers,
22
+ body: JSON.stringify({
23
+ query,
24
+ variables,
25
+ operationName
26
+ })
27
+ }).then((res)=>res.json()).then((res)=>{
28
+ if (res.errors) {
29
+ return Promise.reject(res.errors);
30
+ }
31
+ return res.data;
32
+ });
33
+ };
34
+ };
35
+ const createShopifyFetcher = (storefrontToken, handle)=>{
36
+ const token = storefrontToken ?? process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
37
+ const storefrontHandle = handle ?? process.env.NEXT_PUBLIC_STOREFRONT_HANDLE;
38
+ return async (args)=>{
39
+ if (!token) {
40
+ throw new Error('NEXT_PUBLIC_STOREFRONT_TOKEN is not defined');
41
+ }
42
+ if (!storefrontHandle) {
43
+ throw new Error('NEXT_PUBLIC_STOREFRONT_HANDLE is not defined');
44
+ }
45
+ const headers = {
46
+ 'Content-Type': 'application/json',
47
+ 'X-Shopify-Storefront-Access-Token': token
48
+ };
49
+ const [query, variables] = args;
50
+ return fetch(getStorefrontApi.getStorefrontApi(storefrontHandle), {
51
+ method: 'POST',
52
+ headers,
53
+ body: JSON.stringify({
54
+ query,
55
+ variables
56
+ })
57
+ }).then((res)=>res.json()).then((res)=>{
58
+ if (res.errors) {
59
+ return Promise.reject(res.errors);
60
+ }
61
+ return res.data;
62
+ });
63
+ };
68
64
  };
69
65
 
70
66
  exports.createFetcher = createFetcher;
@@ -3,8 +3,11 @@
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var main = require('../layouts/main.js');
5
5
 
6
- const getLayout = (page, pageProps) => {
7
- return jsxRuntime.jsx(main.default, { ...pageProps, children: page });
6
+ const getLayout = (page, pageProps)=>{
7
+ return /*#__PURE__*/ jsxRuntime.jsx(main.default, {
8
+ ...pageProps,
9
+ children: page
10
+ });
8
11
  };
9
12
 
10
13
  exports.getLayout = getLayout;
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const getStorefrontApi = (handle, provider) => {
4
- switch (provider) {
5
- case 'BIGCOMMERCE':
6
- return `https://${handle}.bigcommerce.com`;
7
- default:
8
- return `https://${handle}.myshopify.com/api/2022-07/graphql.json`;
9
- }
3
+ const getStorefrontApi = (handle, provider)=>{
4
+ switch(provider){
5
+ case 'BIGCOMMERCE':
6
+ return `https://${handle}.bigcommerce.com`;
7
+ default:
8
+ return `https://${handle}.myshopify.com/api/2022-07/graphql.json`;
9
+ }
10
10
  };
11
11
 
12
12
  exports.getStorefrontApi = getStorefrontApi;
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const getStaticPaths = async () => {
4
- return {
5
- paths: [],
6
- fallback: true,
7
- };
3
+ const getStaticPaths = async ()=>{
4
+ return {
5
+ paths: [],
6
+ fallback: true
7
+ };
8
8
  };
9
9
 
10
10
  exports.getStaticPaths = getStaticPaths;
@@ -1,66 +1,59 @@
1
1
  'use strict';
2
2
 
3
- 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';
4
- const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
5
- async function getFontForUA(url, UA) {
6
- return fetch(url, {
7
- headers: {
8
- 'User-Agent': UA,
9
- },
10
- }).then((res) => res.text());
11
- }
12
- const createFontUrl = (fonts, option) => {
13
- const params = new URLSearchParams();
14
- const display = option?.display || 'swap';
15
- const family = fonts
16
- .filter((font, index, arr) => {
17
- return index === arr.findIndex((t) => t.family === font.family);
18
- })
19
- .map((font) => {
20
- return `${font.family.replace(/ /g, '+')}:${font.variants.join(',')}`;
21
- })
22
- .join('|');
23
- params.append('family', family);
24
- params.append('display', display);
25
- if (option?.subset) {
26
- params.append('subset', option.subset);
27
- }
28
- if (option?.effect) {
29
- params.append('effect', option.effect);
30
- }
31
- return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
32
- };
33
- async function getFonts(fonts, option) {
34
- /**
35
- * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
36
- * CSS cascading 🤷‍♂️.
37
- */
38
- const url = createFontUrl(fonts, option);
39
- try {
40
- const [ie, chrome] = await Promise.all([
41
- getFontForUA(url, IE_UA),
42
- getFontForUA(url, CHROME_UA),
43
- ]);
44
- return ie + chrome;
45
- }
46
- catch (e) {
47
- return '';
48
- }
49
- }
50
- const getFontFromGlobalStyle = (data) => {
51
- if (!data)
52
- return '';
53
- try {
54
- const globalStyle = JSON.parse(data);
55
- const fonts = globalStyle?.font ?? {};
56
- const font = Object.entries(fonts).map(([, value]) => {
57
- return value;
58
- });
59
- return getFonts(font);
60
- }
61
- catch {
62
- return '';
63
- }
3
+ 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';
4
+ const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
5
+ async function getFontForUA(url, UA) {
6
+ return fetch(url, {
7
+ headers: {
8
+ 'User-Agent': UA
9
+ }
10
+ }).then((res)=>res.text());
11
+ }
12
+ const createFontUrl = (fonts, option)=>{
13
+ const params = new URLSearchParams();
14
+ const display = option?.display || 'swap';
15
+ const family = fonts.filter((font, index, arr)=>{
16
+ return index === arr.findIndex((t)=>t.family === font.family);
17
+ }).map((font)=>{
18
+ return `${font.family.replace(/ /g, '+')}:${font.variants.join(',')}`;
19
+ }).join('|');
20
+ params.append('family', family);
21
+ params.append('display', display);
22
+ if (option?.subset) {
23
+ params.append('subset', option.subset);
24
+ }
25
+ if (option?.effect) {
26
+ params.append('effect', option.effect);
27
+ }
28
+ return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
29
+ };
30
+ async function getFonts(fonts, option) {
31
+ /**
32
+ * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
33
+ * CSS cascading 🤷‍♂️.
34
+ */ const url = createFontUrl(fonts, option);
35
+ try {
36
+ const [ie, chrome] = await Promise.all([
37
+ getFontForUA(url, IE_UA),
38
+ getFontForUA(url, CHROME_UA)
39
+ ]);
40
+ return ie + chrome;
41
+ } catch (e) {
42
+ return '';
43
+ }
44
+ }
45
+ const getFontFromGlobalStyle = (data)=>{
46
+ if (!data) return '';
47
+ try {
48
+ const globalStyle = JSON.parse(data);
49
+ const fonts = globalStyle?.font ?? {};
50
+ const font = Object.entries(fonts).map(([, value])=>{
51
+ return value;
52
+ });
53
+ return getFonts(font);
54
+ } catch {
55
+ return '';
56
+ }
64
57
  };
65
58
 
66
59
  exports.createFontUrl = createFontUrl;
@@ -3,100 +3,109 @@
3
3
  var core = require('@gem-sdk/core');
4
4
  var merge = require('deepmerge');
5
5
 
6
- const baseDevices = {
7
- tablet: '1023px',
8
- mobile: '767px',
9
- };
10
- const flattenObject = (obj, prefix) => {
11
- return Object.keys(obj).reduce((acc, k) => {
12
- const pre = prefix ? `${prefix}-` : '';
13
- if (typeof obj[k] === 'object' && obj[k] !== null && Object.keys(obj[k]).length > 0)
14
- Object.assign(acc, flattenObject(obj[k], pre + k));
15
- else
16
- acc[pre + k] = obj[k];
17
- return acc;
18
- }, {});
19
- };
20
- const devicesOrder = ['desktop', 'tablet', 'mobile'];
21
- const mapObject = (obj) => {
22
- return Object.entries(obj ?? {}).reduce((acc, [k, v]) => {
23
- return {
24
- ...acc,
25
- [core.getShortName(k)]: typeof v === 'object' ? mapObject(v) : v,
26
- };
27
- }, {});
28
- };
29
- const getValueByDevice = (data, device) => {
30
- const deviceData = {
31
- typography: Object.fromEntries(Object.entries(data?.typography ?? {}).map(([key, value]) => {
32
- const typo = { ...value?.[device] };
33
- if (!typo)
34
- return [key, undefined];
35
- if (typo.fontFamily) {
36
- typo.fontFamily = `var(--g-font-${typo.fontFamily}, ${typo.fontFamily})`;
37
- }
38
- return [key, typo];
39
- })),
40
- spacing: Object.fromEntries(Object.entries(data?.spacing ?? {}).map(([key, value]) => {
41
- return [key, value?.[device]];
42
- })),
43
- container: Object.fromEntries(Object.entries(data?.container ?? {}).map(([key, value]) => {
44
- return [key, value?.[device]];
45
- })),
46
- font: Object.fromEntries(Object.entries(data?.font ?? {}).map(([key, value]) => {
47
- return [key, value?.family];
48
- })),
49
- };
50
- return deviceData;
51
- };
52
- const genCSSVariable = (deviceData) => {
53
- return Object.entries(mapObject(flattenObject(deviceData)))
54
- .map(([key, value]) => {
55
- if (value === undefined)
56
- return undefined;
57
- return `--g-${key}:${value}`;
58
- })
59
- .filter((v) => v !== undefined)
60
- .join(';');
61
- };
62
- const genCSS = (input, mobileOnly) => {
63
- if (!input)
64
- return '';
65
- let data = {};
66
- try {
67
- if (typeof input === 'string') {
68
- data = JSON.parse(input);
69
- }
70
- else {
71
- data = input;
72
- }
73
- if (mobileOnly) {
74
- const desktop = getValueByDevice(data, 'desktop');
75
- const mobile = getValueByDevice(data, 'mobile');
76
- const deviceData = merge(desktop, mobile);
77
- deviceData.color = data.color;
78
- deviceData.radius = data.radius;
79
- const cssData = genCSSVariable(deviceData);
80
- return `:root{${cssData}}`;
81
- }
82
- return devicesOrder
83
- .map((device) => {
84
- const deviceData = getValueByDevice(data, device);
85
- if (device === 'desktop') {
86
- deviceData.color = data.color;
87
- deviceData.radius = data.radius;
88
- }
89
- const cssData = genCSSVariable(deviceData);
90
- if (device === 'desktop') {
91
- return `:root{${cssData}}`;
92
- }
93
- return `@media (max-width: ${baseDevices[device]}) {:root{${cssData}}}`;
94
- })
95
- .join('\n');
96
- }
97
- catch {
98
- return '';
99
- }
6
+ const baseDevices = {
7
+ tablet: '1023px',
8
+ mobile: '767px'
9
+ };
10
+ const flattenObject = (obj, prefix)=>{
11
+ return Object.keys(obj).reduce((acc, k)=>{
12
+ const pre = prefix ? `${prefix}-` : '';
13
+ if (typeof obj[k] === 'object' && obj[k] !== null && Object.keys(obj[k]).length > 0) Object.assign(acc, flattenObject(obj[k], pre + k));
14
+ else acc[pre + k] = obj[k];
15
+ return acc;
16
+ }, {});
17
+ };
18
+ const devicesOrder = [
19
+ 'desktop',
20
+ 'tablet',
21
+ 'mobile'
22
+ ];
23
+ const mapObject = (obj)=>{
24
+ return Object.entries(obj ?? {}).reduce((acc, [k, v])=>{
25
+ return {
26
+ ...acc,
27
+ [core.getShortName(k)]: typeof v === 'object' ? mapObject(v) : v
28
+ };
29
+ }, {});
30
+ };
31
+ const getValueByDevice = (data, device)=>{
32
+ const deviceData = {
33
+ typography: Object.fromEntries(Object.entries(data?.typography ?? {}).map(([key, value])=>{
34
+ const typo = {
35
+ ...value?.[device]
36
+ };
37
+ if (!typo) return [
38
+ key,
39
+ undefined
40
+ ];
41
+ if (typo.fontFamily) {
42
+ typo.fontFamily = `var(--g-font-${typo.fontFamily}, ${typo.fontFamily})`;
43
+ }
44
+ return [
45
+ key,
46
+ typo
47
+ ];
48
+ })),
49
+ spacing: Object.fromEntries(Object.entries(data?.spacing ?? {}).map(([key, value])=>{
50
+ return [
51
+ key,
52
+ value?.[device]
53
+ ];
54
+ })),
55
+ container: Object.fromEntries(Object.entries(data?.container ?? {}).map(([key, value])=>{
56
+ return [
57
+ key,
58
+ value?.[device]
59
+ ];
60
+ })),
61
+ font: Object.fromEntries(Object.entries(data?.font ?? {}).map(([key, value])=>{
62
+ return [
63
+ key,
64
+ value?.family
65
+ ];
66
+ }))
67
+ };
68
+ return deviceData;
69
+ };
70
+ const genCSSVariable = (deviceData)=>{
71
+ return Object.entries(mapObject(flattenObject(deviceData))).map(([key, value])=>{
72
+ if (value === undefined) return undefined;
73
+ return `--g-${key}:${value}`;
74
+ }).filter((v)=>v !== undefined).join(';');
75
+ };
76
+ const genCSS = (input, mobileOnly)=>{
77
+ if (!input) return '';
78
+ let data = {};
79
+ try {
80
+ if (typeof input === 'string') {
81
+ data = JSON.parse(input);
82
+ } else {
83
+ data = input;
84
+ }
85
+ if (mobileOnly) {
86
+ const desktop = getValueByDevice(data, 'desktop');
87
+ const mobile = getValueByDevice(data, 'mobile');
88
+ const deviceData = merge(desktop, mobile);
89
+ deviceData.color = data.color;
90
+ deviceData.radius = data.radius;
91
+ const cssData = genCSSVariable(deviceData);
92
+ return `:root{${cssData}}`;
93
+ }
94
+ return devicesOrder.map((device)=>{
95
+ const deviceData = getValueByDevice(data, device);
96
+ if (device === 'desktop') {
97
+ deviceData.color = data.color;
98
+ deviceData.radius = data.radius;
99
+ }
100
+ const cssData = genCSSVariable(deviceData);
101
+ if (device === 'desktop') {
102
+ return `:root{${cssData}}`;
103
+ }
104
+ return `@media (max-width: ${baseDevices[device]}) {:root{${cssData}}}`;
105
+ }).join('\n');
106
+ } catch {
107
+ return '';
108
+ }
100
109
  };
101
110
 
102
111
  exports.genCSS = genCSS;
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const generateManifest = (data) => `data:application/manifest+json,${encodeURIComponent(JSON.stringify(data))}`;
3
+ const generateManifest = (data)=>`data:application/manifest+json,${encodeURIComponent(JSON.stringify(data))}`;
4
4
 
5
5
  exports.generateManifest = generateManifest;
@@ -2,28 +2,30 @@
2
2
 
3
3
  var core = require('@gem-sdk/core');
4
4
 
5
- const getFallbackV2 = async (fetcher, data) => {
6
- const isSample = !process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
7
- const queries = data.map((v) => core.prefetchQueries(v.data, isSample)).flat();
8
- const datas = await Promise.allSettled(queries.map(({ query, variables, func }) => {
9
- if (func) {
10
- return func(fetcher, variables);
11
- }
12
- if (query)
13
- return fetcher([query, variables]);
14
- return {};
15
- }));
16
- const fallback = queries.reduce((acc, { key }, index) => {
17
- const res = datas[index];
18
- if (res?.status === 'fulfilled') {
19
- return {
20
- ...acc,
21
- [key]: res.value,
22
- };
23
- }
24
- return acc;
25
- }, {});
26
- return fallback;
5
+ const getFallbackV2 = async (fetcher, data)=>{
6
+ const isSample = !process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
7
+ const queries = data.map((v)=>core.prefetchQueries(v.data, isSample)).flat();
8
+ const datas = await Promise.allSettled(queries.map(({ query , variables , func })=>{
9
+ if (func) {
10
+ return func(fetcher, variables);
11
+ }
12
+ if (query) return fetcher([
13
+ query,
14
+ variables
15
+ ]);
16
+ return {};
17
+ }));
18
+ const fallback = queries.reduce((acc, { key }, index)=>{
19
+ const res = datas[index];
20
+ if (res?.status === 'fulfilled') {
21
+ return {
22
+ ...acc,
23
+ [key]: res.value
24
+ };
25
+ }
26
+ return acc;
27
+ }, {});
28
+ return fallback;
27
29
  };
28
30
 
29
31
  exports.getFallbackV2 = getFallbackV2;