@gem-sdk/pages 1.36.20 → 2.0.0-dev.832
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.
- package/dist/cjs/components/ErrorBoundary.js +1 -40
- package/dist/cjs/components/ErrorFallback.js +1 -26
- package/dist/cjs/components/FacebookPixel.js +3 -36
- package/dist/cjs/components/Footer.js +1 -125
- package/dist/cjs/components/FooterForPostPurchase.js +1 -0
- package/dist/cjs/components/GoogleAnalytic.js +5 -67
- package/dist/cjs/components/Header.js +1 -96
- package/dist/cjs/components/TikTokPixel.js +3 -19
- package/dist/cjs/components/builder/PopupManager.js +1 -62
- package/dist/cjs/components/builder/Toolbar.js +1 -883
- package/dist/cjs/components/builder/Toolbox.js +1 -384
- package/dist/cjs/components/builder/toolbar/Onboarding.js +1 -110
- package/dist/cjs/components/image-to-layout/AddSectionImageToLayout.js +1 -263
- package/dist/cjs/components/image-to-layout/DropElement.js +1 -164
- package/dist/cjs/components/image-to-layout/ImageToLayout.js +1 -41
- package/dist/cjs/index.js +1 -75
- package/dist/cjs/layouts/main.js +1 -30
- package/dist/cjs/libs/api/get-builder-props.js +1 -41
- package/dist/cjs/libs/api/get-collection-props.js +1 -68
- package/dist/cjs/libs/api/get-home-page-props-v2.js +1 -145
- package/dist/cjs/libs/api/get-home-page-props.js +1 -151
- package/dist/cjs/libs/api/get-post-purchase-props-preview.js +1 -0
- package/dist/cjs/libs/api/get-preview-props.js +1 -18
- package/dist/cjs/libs/api/get-product-props.js +1 -73
- package/dist/cjs/libs/api/get-static-page-props-preview.js +1 -150
- package/dist/cjs/libs/api/get-static-page-props-v2.js +1 -152
- package/dist/cjs/libs/api/get-static-page-props.js +1 -148
- package/dist/cjs/libs/custom-fonts.js +6 -60
- package/dist/cjs/libs/fetcher.js +1 -67
- package/dist/cjs/libs/get-layout.js +1 -13
- package/dist/cjs/libs/get-storefront-api.js +1 -12
- package/dist/cjs/libs/getStaticPaths.js +1 -10
- package/dist/cjs/libs/google-fonts.js +1 -81
- package/dist/cjs/libs/helpers/common.js +1 -27
- package/dist/cjs/libs/helpers/gen-css.js +1 -117
- package/dist/cjs/libs/helpers/gen-fonts.js +1 -68
- package/dist/cjs/libs/helpers/generate-manifres.js +1 -5
- package/dist/cjs/libs/helpers/get-fallback.js +1 -35
- package/dist/cjs/libs/helpers/normalize.js +1 -90
- package/dist/cjs/libs/helpers/parse-json.js +1 -16
- package/dist/cjs/libs/helpers/user-agent.js +1 -7
- package/dist/cjs/libs/hooks/use-tracking-view.js +1 -45
- package/dist/cjs/libs/hooks/usePagePreview.js +1 -0
- package/dist/cjs/libs/parse-html.js +1 -42
- package/dist/cjs/libs/shopify-cdn-with-google-fonts.js +1 -1845
- package/dist/cjs/pages/404.js +1 -43
- package/dist/cjs/pages/500.js +1 -74
- package/dist/cjs/pages/CollectionGlobalProvider.js +1 -59
- package/dist/cjs/pages/builder.js +1 -103
- package/dist/cjs/pages/collection-detail.js +1 -64
- package/dist/cjs/pages/preview.js +1 -26
- package/dist/cjs/pages/product-detail.js +1 -69
- package/dist/cjs/pages/static-v2.js +1 -91
- package/dist/cjs/pages/static.js +1 -75
- package/dist/esm/components/ErrorBoundary.js +1 -38
- package/dist/esm/components/ErrorFallback.js +1 -24
- package/dist/esm/components/FacebookPixel.js +3 -34
- package/dist/esm/components/Footer.js +1 -121
- package/dist/esm/components/FooterForPostPurchase.js +1 -0
- package/dist/esm/components/GoogleAnalytic.js +5 -65
- package/dist/esm/components/Header.js +1 -92
- package/dist/esm/components/TikTokPixel.js +3 -17
- package/dist/esm/components/builder/PopupManager.js +1 -58
- package/dist/esm/components/builder/Toolbar.js +1 -879
- package/dist/esm/components/builder/Toolbox.js +1 -380
- package/dist/esm/components/builder/toolbar/Onboarding.js +1 -106
- package/dist/esm/components/image-to-layout/AddSectionImageToLayout.js +1 -259
- package/dist/esm/components/image-to-layout/DropElement.js +1 -162
- package/dist/esm/components/image-to-layout/ImageToLayout.js +1 -37
- package/dist/esm/index.js +1 -33
- package/dist/esm/layouts/main.js +1 -26
- package/dist/esm/libs/api/get-builder-props.js +1 -39
- package/dist/esm/libs/api/get-collection-props.js +1 -66
- package/dist/esm/libs/api/get-home-page-props-v2.js +1 -143
- package/dist/esm/libs/api/get-home-page-props.js +1 -149
- package/dist/esm/libs/api/get-post-purchase-props-preview.js +1 -0
- package/dist/esm/libs/api/get-preview-props.js +1 -16
- package/dist/esm/libs/api/get-product-props.js +1 -71
- package/dist/esm/libs/api/get-static-page-props-preview.js +1 -148
- package/dist/esm/libs/api/get-static-page-props-v2.js +1 -150
- package/dist/esm/libs/api/get-static-page-props.js +1 -146
- package/dist/esm/libs/custom-fonts.js +6 -55
- package/dist/esm/libs/fetcher.js +1 -64
- package/dist/esm/libs/get-layout.js +1 -11
- package/dist/esm/libs/get-storefront-api.js +1 -10
- package/dist/esm/libs/getStaticPaths.js +1 -8
- package/dist/esm/libs/google-fonts.js +1 -75
- package/dist/esm/libs/helpers/common.js +1 -24
- package/dist/esm/libs/helpers/gen-css.js +1 -115
- package/dist/esm/libs/helpers/gen-fonts.js +1 -65
- package/dist/esm/libs/helpers/generate-manifres.js +1 -3
- package/dist/esm/libs/helpers/get-fallback.js +1 -33
- package/dist/esm/libs/helpers/normalize.js +1 -85
- package/dist/esm/libs/helpers/parse-json.js +1 -13
- package/dist/esm/libs/helpers/user-agent.js +1 -5
- package/dist/esm/libs/hooks/use-tracking-view.js +1 -43
- package/dist/esm/libs/hooks/usePagePreview.js +1 -0
- package/dist/esm/libs/parse-html.js +1 -40
- package/dist/esm/libs/shopify-cdn-with-google-fonts.js +1 -1843
- package/dist/esm/pages/404.js +1 -41
- package/dist/esm/pages/500.js +1 -72
- package/dist/esm/pages/CollectionGlobalProvider.js +1 -55
- package/dist/esm/pages/builder.js +1 -101
- package/dist/esm/pages/collection-detail.js +1 -60
- package/dist/esm/pages/preview.js +1 -24
- package/dist/esm/pages/product-detail.js +1 -65
- package/dist/esm/pages/static-v2.js +1 -89
- package/dist/esm/pages/static.js +1 -71
- package/dist/types/index.d.ts +28 -6
- package/package.json +5 -5
|
@@ -1,150 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ShopMetaDocument } from '@gem-sdk/adapter-shopify';
|
|
3
|
-
import { getFontStyleFromPageTemplate, getFontFromGlobalStyle } from '../google-fonts.js';
|
|
4
|
-
import { genCSS } from '../helpers/gen-css.js';
|
|
5
|
-
import { generateManifest } from '../helpers/generate-manifres.js';
|
|
6
|
-
import { getFallbackV2 } from '../helpers/get-fallback.js';
|
|
7
|
-
import { parseBuilderTemplateV2 } from '../helpers/normalize.js';
|
|
8
|
-
import { parseJson, serializableJson } from '../helpers/parse-json.js';
|
|
9
|
-
import { captureException } from '@sentry/nextjs';
|
|
10
|
-
import { getCustomFonts } from '../custom-fonts.js';
|
|
11
|
-
|
|
12
|
-
const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
|
|
13
|
-
try {
|
|
14
|
-
const pageType = 'STATIC';
|
|
15
|
-
const variables = {
|
|
16
|
-
slug,
|
|
17
|
-
slugType: pageType
|
|
18
|
-
};
|
|
19
|
-
const [theme, storeProperty, shopifyMeta] = await Promise.allSettled([
|
|
20
|
-
fetcher([
|
|
21
|
-
PublishedThemePagesDocument,
|
|
22
|
-
variables
|
|
23
|
-
]),
|
|
24
|
-
fetcher([
|
|
25
|
-
StorePropertyDocument
|
|
26
|
-
]),
|
|
27
|
-
shopifyFetcher([
|
|
28
|
-
ShopMetaDocument
|
|
29
|
-
])
|
|
30
|
-
]);
|
|
31
|
-
if (theme.status === 'rejected') {
|
|
32
|
-
throw new Error(theme.reason?.[0]);
|
|
33
|
-
}
|
|
34
|
-
const dataBuilder = theme.value.publishedThemePages?.[0];
|
|
35
|
-
const themePageCustomFonts = theme.value?.publishedThemePages?.[0]?.themePageCustomFonts;
|
|
36
|
-
if (!dataBuilder) {
|
|
37
|
-
throw new Error(`No data builder found for slug: /${slug}`);
|
|
38
|
-
}
|
|
39
|
-
const pageTemplate = parseBuilderTemplateV2(dataBuilder);
|
|
40
|
-
const [elementFontStyle, fontStyle, fallback, customFonts] = await Promise.all([
|
|
41
|
-
getFontStyleFromPageTemplate(pageTemplate),
|
|
42
|
-
getFontFromGlobalStyle(dataBuilder?.pageStyle?.data),
|
|
43
|
-
getFallbackV2(fetcher, pageTemplate),
|
|
44
|
-
getCustomFonts(themePageCustomFonts)
|
|
45
|
-
]);
|
|
46
|
-
const mobileOnly = dataBuilder.isMobile ?? false;
|
|
47
|
-
const description = dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-description')?.value;
|
|
48
|
-
const thumbnail = parseJson(dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-thumbnail')?.value);
|
|
49
|
-
const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
|
|
50
|
-
const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
|
|
51
|
-
const favicon = shopData?.storeProperty?.favicon ?? '/favicon/favicon-32x32.png';
|
|
52
|
-
const seo = {
|
|
53
|
-
defaultTitle: shopMeta?.shop.name,
|
|
54
|
-
title: dataBuilder?.name,
|
|
55
|
-
description: description ?? shopMeta?.shop.description,
|
|
56
|
-
openGraph: {
|
|
57
|
-
site_name: shopMeta?.shop.name,
|
|
58
|
-
locale: shopMeta?.localization.country.isoCode,
|
|
59
|
-
title: dataBuilder?.name ?? shopMeta?.shop.name,
|
|
60
|
-
description: description ?? shopMeta?.shop.description,
|
|
61
|
-
images: thumbnail ? [
|
|
62
|
-
thumbnail
|
|
63
|
-
] : []
|
|
64
|
-
},
|
|
65
|
-
canonical: `https://${shopData?.storeProperty?.primaryDomain}/${slug}`,
|
|
66
|
-
additionalMetaTags: [
|
|
67
|
-
{
|
|
68
|
-
name: 'theme-color',
|
|
69
|
-
content: '#000000'
|
|
70
|
-
}
|
|
71
|
-
],
|
|
72
|
-
additionalLinkTags: [
|
|
73
|
-
{
|
|
74
|
-
rel: 'icon',
|
|
75
|
-
sizes: '32x32',
|
|
76
|
-
href: `${favicon}-/crop/1:1/center/-/smart_resize/32x32/`
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
rel: 'icon',
|
|
80
|
-
sizes: '16x16',
|
|
81
|
-
href: `${favicon}-/crop/1:1/center/-/smart_resize/16x16/`
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
rel: 'apple-touch-icon',
|
|
85
|
-
sizes: '180x180',
|
|
86
|
-
href: `${favicon}-/crop/1:1/center/-/smart_resize/180x180/`
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
rel: 'manifest',
|
|
90
|
-
href: generateManifest({
|
|
91
|
-
theme_color: '#000000',
|
|
92
|
-
background_color: '#ffffff',
|
|
93
|
-
display: 'standalone',
|
|
94
|
-
scope: '/',
|
|
95
|
-
start_url: '/',
|
|
96
|
-
name: shopMeta?.shop.name,
|
|
97
|
-
short_name: shopMeta?.shop.name,
|
|
98
|
-
description: shopMeta?.shop.description,
|
|
99
|
-
icons: [
|
|
100
|
-
{
|
|
101
|
-
src: `${favicon}-/crop/1:1/center/-/smart_resize/192x192/`,
|
|
102
|
-
sizes: '192x192',
|
|
103
|
-
type: 'image/png',
|
|
104
|
-
purpose: 'any maskable'
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
src: `${favicon}-/crop/1:1/center/-/smart_resize/512x512/`,
|
|
108
|
-
sizes: '512x512',
|
|
109
|
-
type: 'image/png'
|
|
110
|
-
}
|
|
111
|
-
]
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
]
|
|
115
|
-
};
|
|
116
|
-
const languageIsoCode = shopMeta?.localization.language.isoCode ?? null;
|
|
117
|
-
const countryIsoCode = shopMeta?.localization.country.isoCode ?? null;
|
|
118
|
-
const locale = !languageIsoCode || !countryIsoCode ? null : `${languageIsoCode}-${countryIsoCode}`;
|
|
119
|
-
return serializableJson({
|
|
120
|
-
themeStyle: genCSS(dataBuilder?.pageStyle?.data, mobileOnly),
|
|
121
|
-
fontStyle,
|
|
122
|
-
elementFontStyle,
|
|
123
|
-
builderData: pageTemplate,
|
|
124
|
-
pageType,
|
|
125
|
-
moneyFormat: shopMeta?.shop.moneyFormat ?? null,
|
|
126
|
-
currency: shopMeta?.localization.country.currency.isoCode ?? null,
|
|
127
|
-
languageIsoCode,
|
|
128
|
-
countryIsoCode,
|
|
129
|
-
locale,
|
|
130
|
-
swr: {
|
|
131
|
-
fallback
|
|
132
|
-
},
|
|
133
|
-
swatches: parseJson(shopData?.storeProperty?.swatchesConfig),
|
|
134
|
-
seo,
|
|
135
|
-
mobileOnly,
|
|
136
|
-
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
137
|
-
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
138
|
-
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
139
|
-
customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
|
|
140
|
-
customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
|
|
141
|
-
pageHandle: dataBuilder.handle ?? null,
|
|
142
|
-
customFonts
|
|
143
|
-
});
|
|
144
|
-
} catch (err) {
|
|
145
|
-
captureException(err);
|
|
146
|
-
throw err;
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export { getStaticPagePropsV2 };
|
|
1
|
+
import{PublishedThemePagesDocument as e,StorePropertyDocument as o}from"@gem-sdk/core";import{ShopMetaDocument as t}from"@gem-sdk/adapter-shopify";import{getFontStyleFromPageTemplate as a,getFontFromGlobalStyle as r}from"../google-fonts.js";import{genCSS as s}from"../helpers/gen-css.js";import{generateManifest as i}from"../helpers/generate-manifres.js";import{getFallbackV2 as l}from"../helpers/get-fallback.js";import{parseBuilderTemplateV2 as n}from"../helpers/normalize.js";import{parseJson as m,serializableJson as c}from"../helpers/parse-json.js";import{captureException as p}from"@sentry/nextjs";import{getCustomFonts as d}from"../custom-fonts.js";let getStaticPagePropsV2=(u,h)=>async g=>{try{let p="STATIC",f={slug:g,slugType:p},[y,P,x]=await Promise.allSettled([u([e,f]),u([o]),h([t])]);if("rejected"===y.status)throw Error(y.reason?.[0]);let k=y.value.publishedThemePages?.[0],z=y.value?.publishedThemePages?.[0]?.themePageCustomFonts;if(!k)throw Error(`No data builder found for slug: /${g}`);let b=n(k),[C,v,j,T]=await Promise.all([a(b),r(k?.pageStyle?.data),l(u,b),d(z)]),$=k.isMobile??!1,_=k?.themePageDataSEO?.find(e=>e?.key==="global-meta-description")?.value,S=m(k?.themePageDataSEO?.find(e=>e?.key==="global-meta-thumbnail")?.value),w="fulfilled"===x.status?x.value:void 0,D="fulfilled"===P.status?P.value:void 0,I=D?.storeProperty?.favicon??"/favicon/favicon-32x32.png",A={defaultTitle:w?.shop.name,title:k?.name,description:_??w?.shop.description,openGraph:{site_name:w?.shop.name,locale:w?.localization.country.isoCode,title:k?.name??w?.shop.name,description:_??w?.shop.description,images:S?[S]:[]},canonical:`https://${D?.storeProperty?.primaryDomain}/${g}`,additionalMetaTags:[{name:"theme-color",content:"#000000"}],additionalLinkTags:[{rel:"icon",sizes:"32x32",href:`${I}-/crop/1:1/center/-/smart_resize/32x32/`},{rel:"icon",sizes:"16x16",href:`${I}-/crop/1:1/center/-/smart_resize/16x16/`},{rel:"apple-touch-icon",sizes:"180x180",href:`${I}-/crop/1:1/center/-/smart_resize/180x180/`},{rel:"manifest",href:i({theme_color:"#000000",background_color:"#ffffff",display:"standalone",scope:"/",start_url:"/",name:w?.shop.name,short_name:w?.shop.name,description:w?.shop.description,icons:[{src:`${I}-/crop/1:1/center/-/smart_resize/192x192/`,sizes:"192x192",type:"image/png",purpose:"any maskable"},{src:`${I}-/crop/1:1/center/-/smart_resize/512x512/`,sizes:"512x512",type:"image/png"}]})}]},E=w?.localization.language.isoCode??null,F=w?.localization.country.isoCode??null,H=E&&F?`${E}-${F}`:null;return c({themeStyle:s(k?.pageStyle?.data,$),fontStyle:v,elementFontStyle:C,builderData:b,pageType:p,moneyFormat:w?.shop.moneyFormat??null,currency:w?.localization.country.currency.isoCode??null,languageIsoCode:E,countryIsoCode:F,locale:H,swr:{fallback:j},swatches:m(D?.storeProperty?.swatchesConfig),seo:A,mobileOnly:$,gaTrackingId:k.themePageAnalytic?.gaTrackingID??null,facebookPixelId:k.themePageAnalytic?.fbPixelID??null,tiktokPixelId:k.themePageAnalytic?.tiktokPixelID??null,customCodeHeader:k.themePageCustomCode?.header??null,customCodeBody:k.themePageCustomCode?.body??null,pageHandle:k.handle??null,customFonts:T})}catch(e){throw p(e),e}};export{getStaticPagePropsV2};
|
|
@@ -1,146 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ShopMetaDocument } from '@gem-sdk/adapter-shopify';
|
|
3
|
-
import { getFontFromGlobalStyle } from '../google-fonts.js';
|
|
4
|
-
import { genCSS } from '../helpers/gen-css.js';
|
|
5
|
-
import { generateManifest } from '../helpers/generate-manifres.js';
|
|
6
|
-
import { parseBuilderTemplate } from '../helpers/normalize.js';
|
|
7
|
-
import { parseJson, serializableJson } from '../helpers/parse-json.js';
|
|
8
|
-
|
|
9
|
-
const getStaticPageProps = (fetcher, shopifyFetcher)=>async (slug)=>{
|
|
10
|
-
const pageType = 'STATIC';
|
|
11
|
-
const variables = {
|
|
12
|
-
slug,
|
|
13
|
-
slugType: pageType
|
|
14
|
-
};
|
|
15
|
-
const [theme, storeProperty, shopifyMeta] = await Promise.allSettled([
|
|
16
|
-
fetcher([
|
|
17
|
-
PublishedThemePagesDocument,
|
|
18
|
-
variables
|
|
19
|
-
]),
|
|
20
|
-
fetcher([
|
|
21
|
-
StorePropertyDocument
|
|
22
|
-
]),
|
|
23
|
-
shopifyFetcher([
|
|
24
|
-
ShopMetaDocument
|
|
25
|
-
])
|
|
26
|
-
]);
|
|
27
|
-
if (theme.status === 'rejected') {
|
|
28
|
-
return {
|
|
29
|
-
pageType
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const dataBuilder = theme.value.publishedThemePages?.[0];
|
|
33
|
-
const pageTemplate = parseBuilderTemplate(dataBuilder);
|
|
34
|
-
const fontStyle = await getFontFromGlobalStyle(dataBuilder?.pageStyle?.data);
|
|
35
|
-
const queries = prefetchQueries(pageTemplate);
|
|
36
|
-
const datas = await Promise.allSettled(queries.map(({ query, variables, func })=>{
|
|
37
|
-
if (func) {
|
|
38
|
-
return func(fetcher, variables);
|
|
39
|
-
}
|
|
40
|
-
if (query) return fetcher([
|
|
41
|
-
query,
|
|
42
|
-
variables
|
|
43
|
-
]);
|
|
44
|
-
return {};
|
|
45
|
-
}));
|
|
46
|
-
const fallback = queries.reduce((acc, { key }, index)=>{
|
|
47
|
-
const res = datas[index];
|
|
48
|
-
if (res?.status === 'fulfilled') {
|
|
49
|
-
return {
|
|
50
|
-
...acc,
|
|
51
|
-
[key]: res.value
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return acc;
|
|
55
|
-
}, {});
|
|
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);
|
|
58
|
-
const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
|
|
59
|
-
const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
|
|
60
|
-
const favicon = shopData?.storeProperty?.favicon ?? '/favicon/favicon-32x32.png';
|
|
61
|
-
const seo = {
|
|
62
|
-
defaultTitle: shopMeta?.shop.name ?? '',
|
|
63
|
-
title: dataBuilder?.name ?? '',
|
|
64
|
-
description: description ?? shopMeta?.shop.description ?? '',
|
|
65
|
-
openGraph: {
|
|
66
|
-
site_name: shopMeta?.shop.name ?? '',
|
|
67
|
-
locale: shopMeta?.localization.country.isoCode ?? '',
|
|
68
|
-
title: dataBuilder?.name ?? shopMeta?.shop.name ?? '',
|
|
69
|
-
description: description ?? shopMeta?.shop.description ?? '',
|
|
70
|
-
images: thumbnail ? [
|
|
71
|
-
thumbnail
|
|
72
|
-
] : []
|
|
73
|
-
},
|
|
74
|
-
additionalMetaTags: [
|
|
75
|
-
{
|
|
76
|
-
name: 'theme-color',
|
|
77
|
-
content: '#000000'
|
|
78
|
-
}
|
|
79
|
-
],
|
|
80
|
-
canonical: `/${slug}`,
|
|
81
|
-
additionalLinkTags: [
|
|
82
|
-
{
|
|
83
|
-
rel: 'icon',
|
|
84
|
-
sizes: '32x32',
|
|
85
|
-
href: `${favicon}-/crop/1:1/center/-/smart_resize/32x32/`
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
rel: 'icon',
|
|
89
|
-
sizes: '16x16',
|
|
90
|
-
href: `${favicon}-/crop/1:1/center/-/smart_resize/16x16/`
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
rel: 'apple-touch-icon',
|
|
94
|
-
sizes: '180x180',
|
|
95
|
-
href: `${favicon}-/crop/1:1/center/-/smart_resize/180x180/`
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
rel: 'manifest',
|
|
99
|
-
href: generateManifest({
|
|
100
|
-
theme_color: '#000000',
|
|
101
|
-
background_color: '#ffffff',
|
|
102
|
-
display: 'standalone',
|
|
103
|
-
scope: '/',
|
|
104
|
-
start_url: '/',
|
|
105
|
-
name: shopMeta?.shop.name,
|
|
106
|
-
short_name: shopMeta?.shop.name,
|
|
107
|
-
description: shopMeta?.shop.description,
|
|
108
|
-
icons: [
|
|
109
|
-
{
|
|
110
|
-
src: `${favicon}-/crop/1:1/center/-/smart_resize/192x192/`,
|
|
111
|
-
sizes: '192x192',
|
|
112
|
-
type: 'image/png',
|
|
113
|
-
purpose: 'any maskable'
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
src: `${favicon}-/crop/1:1/center/-/smart_resize/512x512/`,
|
|
117
|
-
sizes: '512x512',
|
|
118
|
-
type: 'image/png'
|
|
119
|
-
}
|
|
120
|
-
]
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
]
|
|
124
|
-
};
|
|
125
|
-
const languageIsoCode = shopMeta?.localization.language.isoCode ?? null;
|
|
126
|
-
const countryIsoCode = shopMeta?.localization.country.isoCode ?? null;
|
|
127
|
-
const locale = !languageIsoCode || !countryIsoCode ? null : `${languageIsoCode}-${countryIsoCode}`;
|
|
128
|
-
return serializableJson({
|
|
129
|
-
themeStyle: genCSS(dataBuilder?.pageStyle?.data),
|
|
130
|
-
fontStyle,
|
|
131
|
-
builderData: pageTemplate,
|
|
132
|
-
pageType,
|
|
133
|
-
moneyFormat: shopMeta?.shop.moneyFormat ?? null,
|
|
134
|
-
currency: shopMeta?.localization.country.currency.isoCode ?? null,
|
|
135
|
-
languageIsoCode,
|
|
136
|
-
countryIsoCode,
|
|
137
|
-
locale,
|
|
138
|
-
swr: {
|
|
139
|
-
fallback
|
|
140
|
-
},
|
|
141
|
-
swatches: parseJson(shopData?.storeProperty?.swatchesConfig),
|
|
142
|
-
seo
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export { getStaticPageProps };
|
|
1
|
+
import{PublishedThemePagesDocument as e,StorePropertyDocument as a,prefetchQueries as t}from"@gem-sdk/core";import{ShopMetaDocument as o}from"@gem-sdk/adapter-shopify";import{getFontFromGlobalStyle as r}from"../google-fonts.js";import{genCSS as s}from"../helpers/gen-css.js";import{generateManifest as i}from"../helpers/generate-manifres.js";import{parseBuilderTemplate as l}from"../helpers/normalize.js";import{parseJson as n,serializableJson as p}from"../helpers/parse-json.js";let getStaticPageProps=(c,m)=>async d=>{let u="STATIC",f={slug:d,slugType:u},[h,g,y]=await Promise.allSettled([c([e,f]),c([a]),m([o])]);if("rejected"===h.status)return{pageType:u};let z=h.value.publishedThemePages?.[0],x=l(z),v=await r(z?.pageStyle?.data),P=t(x),S=await Promise.allSettled(P.map(({query:e,variables:a,func:t})=>t?t(c,a):e?c([e,a]):{})),_=P.reduce((e,{key:a},t)=>{let o=S[t];return o?.status==="fulfilled"?{...e,[a]:o.value}:e},{}),$=z?.themePageDataSEO?.find(e=>e?.key==="global-meta-description")?.value,b=n(z?.themePageDataSEO?.find(e=>e?.key==="global-meta-thumbnail")?.value),j="fulfilled"===y.status?y.value:void 0,k="fulfilled"===g.status?g.value:void 0,T=k?.storeProperty?.favicon??"/favicon/favicon-32x32.png",w={defaultTitle:j?.shop.name??"",title:z?.name??"",description:$??j?.shop.description??"",openGraph:{site_name:j?.shop.name??"",locale:j?.localization.country.isoCode??"",title:z?.name??j?.shop.name??"",description:$??j?.shop.description??"",images:b?[b]:[]},additionalMetaTags:[{name:"theme-color",content:"#000000"}],canonical:`/${d}`,additionalLinkTags:[{rel:"icon",sizes:"32x32",href:`${T}-/crop/1:1/center/-/smart_resize/32x32/`},{rel:"icon",sizes:"16x16",href:`${T}-/crop/1:1/center/-/smart_resize/16x16/`},{rel:"apple-touch-icon",sizes:"180x180",href:`${T}-/crop/1:1/center/-/smart_resize/180x180/`},{rel:"manifest",href:i({theme_color:"#000000",background_color:"#ffffff",display:"standalone",scope:"/",start_url:"/",name:j?.shop.name,short_name:j?.shop.name,description:j?.shop.description,icons:[{src:`${T}-/crop/1:1/center/-/smart_resize/192x192/`,sizes:"192x192",type:"image/png",purpose:"any maskable"},{src:`${T}-/crop/1:1/center/-/smart_resize/512x512/`,sizes:"512x512",type:"image/png"}]})}]},C=j?.localization.language.isoCode??null,D=j?.localization.country.isoCode??null,E=C&&D?`${C}-${D}`:null;return p({themeStyle:s(z?.pageStyle?.data),fontStyle:v,builderData:x,pageType:u,moneyFormat:j?.shop.moneyFormat??null,currency:j?.localization.country.currency.isoCode??null,languageIsoCode:C,countryIsoCode:D,locale:E,swr:{fallback:_},swatches:n(k?.storeProperty?.swatchesConfig),seo:w})};export{getStaticPageProps};
|
|
@@ -1,57 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const result = {};
|
|
3
|
-
fonts?.forEach((font)=>{
|
|
4
|
-
if (!font) return;
|
|
5
|
-
const fontKey = `${font.fontFamily}_${font.fontStyle}_${font.fontWeight}`;
|
|
6
|
-
const fontData = {
|
|
7
|
-
font: {
|
|
8
|
-
fontFamily: font.fontFamily,
|
|
9
|
-
fontStyle: font.fontStyle,
|
|
10
|
-
fontWeight: font.fontWeight
|
|
11
|
-
},
|
|
12
|
-
urls: [
|
|
13
|
-
{
|
|
14
|
-
url: font.backupFilePath || font.filePath,
|
|
15
|
-
mimeType: font.mimeType
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
};
|
|
19
|
-
if (!result[fontKey]) {
|
|
20
|
-
result[fontKey] = fontData;
|
|
21
|
-
} else {
|
|
22
|
-
result[fontKey]?.urls.push(fontData?.urls?.[0]);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
// Currently support only ttf, otf, woff, woff2
|
|
28
|
-
const formatName = (mimeType)=>{
|
|
29
|
-
const fontMimeTypes = {
|
|
30
|
-
'font/ttf': 'truetype',
|
|
31
|
-
'application/x-font-opentype': 'opentype',
|
|
32
|
-
'application/font-woff': 'woff',
|
|
33
|
-
'application/font-woff2': 'woff2'
|
|
34
|
-
};
|
|
35
|
-
return fontMimeTypes[mimeType];
|
|
36
|
-
};
|
|
37
|
-
const composeFontFaces = (fontsMimeType)=>{
|
|
38
|
-
const fontFaces = [];
|
|
39
|
-
for (const [, value] of Object.entries(fontsMimeType)){
|
|
40
|
-
fontFaces.push(`
|
|
1
|
+
let composeFontMimeType=t=>{let o={};return t?.forEach(t=>{if(!t)return;let e=`${t.fontFamily}_${t.fontStyle}_${t.fontWeight}`,n={font:{fontFamily:t.fontFamily,fontStyle:t.fontStyle,fontWeight:t.fontWeight},urls:[{url:t.backupFilePath||t.filePath,mimeType:t.mimeType}]};o[e]?o[e]?.urls.push(n?.urls?.[0]):o[e]=n}),o},formatName=t=>({"font/ttf":"truetype","application/x-font-opentype":"opentype","application/font-woff":"woff","application/font-woff2":"woff2"})[t],composeFontFaces=t=>{let o=[];for(let[,e]of Object.entries(t))o.push(`
|
|
41
2
|
@font-face {
|
|
42
|
-
font-family: '${
|
|
43
|
-
src: ${
|
|
44
|
-
font-style: ${
|
|
45
|
-
font-weight: ${
|
|
3
|
+
font-family: '${e.font.fontFamily}';
|
|
4
|
+
src: ${e.urls.map(t=>`url('${t.url}') format('${formatName(t.mimeType)}')`).join("\n")};
|
|
5
|
+
font-style: ${e?.font?.fontStyle??"normal"};
|
|
6
|
+
font-weight: ${e?.font?.fontWeight??"normal"};
|
|
46
7
|
}
|
|
47
|
-
`);
|
|
48
|
-
}
|
|
49
|
-
return fontFaces.map((fontFace)=>fontFace).join('\n');
|
|
50
|
-
};
|
|
51
|
-
const getCustomFonts = (fonts)=>{
|
|
52
|
-
if (!fonts) return null;
|
|
53
|
-
const fontsMimeType = composeFontMimeType(fonts);
|
|
54
|
-
return composeFontFaces(fontsMimeType);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export { composeFontFaces, composeFontMimeType, formatName, getCustomFonts };
|
|
8
|
+
`);return o.map(t=>t).join("\n")},getCustomFonts=t=>{if(!t)return null;let o=composeFontMimeType(t);return composeFontFaces(o)};export{composeFontFaces,composeFontMimeType,formatName,getCustomFonts};
|
package/dist/esm/libs/fetcher.js
CHANGED
|
@@ -1,64 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const createFetcher = (token)=>{
|
|
4
|
-
const shopToken = token || process.env.NEXT_PUBLIC_SHOP_TOKEN;
|
|
5
|
-
return async (args)=>{
|
|
6
|
-
const [query, variables, operationName] = args;
|
|
7
|
-
if (!shopToken) {
|
|
8
|
-
throw new Error('shopToken is not defined');
|
|
9
|
-
}
|
|
10
|
-
if (!process.env.NEXT_PUBLIC_API_URL) {
|
|
11
|
-
throw new Error('NEXT_PUBLIC_API_URL is not defined');
|
|
12
|
-
}
|
|
13
|
-
const headers = {
|
|
14
|
-
'Content-Type': 'application/json',
|
|
15
|
-
'X-GemX-Shop-Token': shopToken
|
|
16
|
-
};
|
|
17
|
-
return fetch(process.env.NEXT_PUBLIC_API_URL, {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
headers,
|
|
20
|
-
body: JSON.stringify({
|
|
21
|
-
query,
|
|
22
|
-
variables,
|
|
23
|
-
operationName
|
|
24
|
-
})
|
|
25
|
-
}).then((res)=>res.json()).then((res)=>{
|
|
26
|
-
if (res.errors) {
|
|
27
|
-
return Promise.reject(res.errors);
|
|
28
|
-
}
|
|
29
|
-
return res.data;
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const createShopifyFetcher = (storefrontToken, handle)=>{
|
|
34
|
-
const token = storefrontToken ?? process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
|
|
35
|
-
const storefrontHandle = handle ?? process.env.NEXT_PUBLIC_STOREFRONT_HANDLE;
|
|
36
|
-
return async (args)=>{
|
|
37
|
-
if (!token) {
|
|
38
|
-
throw new Error('NEXT_PUBLIC_STOREFRONT_TOKEN is not defined');
|
|
39
|
-
}
|
|
40
|
-
if (!storefrontHandle) {
|
|
41
|
-
throw new Error('NEXT_PUBLIC_STOREFRONT_HANDLE is not defined');
|
|
42
|
-
}
|
|
43
|
-
const headers = {
|
|
44
|
-
'Content-Type': 'application/json',
|
|
45
|
-
'X-Shopify-Storefront-Access-Token': token
|
|
46
|
-
};
|
|
47
|
-
const [query, variables] = args;
|
|
48
|
-
return fetch(getStorefrontApi(storefrontHandle), {
|
|
49
|
-
method: 'POST',
|
|
50
|
-
headers,
|
|
51
|
-
body: JSON.stringify({
|
|
52
|
-
query,
|
|
53
|
-
variables
|
|
54
|
-
})
|
|
55
|
-
}).then((res)=>res.json()).then((res)=>{
|
|
56
|
-
if (res.errors) {
|
|
57
|
-
return Promise.reject(res.errors);
|
|
58
|
-
}
|
|
59
|
-
return res.data;
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export { createFetcher, createShopifyFetcher };
|
|
1
|
+
import{getStorefrontApi as e}from"./get-storefront-api.js";let createFetcher=e=>{let r=e||process.env.NEXT_PUBLIC_SHOP_TOKEN;return async e=>{let[t,o,n]=e;if(!r)throw Error("shopToken is not defined");if(!process.env.NEXT_PUBLIC_API_URL)throw Error("NEXT_PUBLIC_API_URL is not defined");let s={"Content-Type":"application/json","X-GemX-Shop-Token":r};return fetch(process.env.NEXT_PUBLIC_API_URL,{method:"POST",headers:s,body:JSON.stringify({query:t,variables:o,operationName:n})}).then(e=>e.json()).then(e=>e.errors?Promise.reject(e.errors):e.data)}},createAppAPIFetcher=(e,r)=>{let t=process.env.NEXT_APP_API_URL;return async o=>{let[n,s,i]=o;if(!e)throw Error("shopToken is not defined");if(!t)throw Error("NEXT_APP_API_URL is not defined");let c={"Content-Type":"application/json",Authorization:`Token ${e}`,"X-GemX-Shop-ID":r||""};return fetch(t,{method:"POST",headers:c,body:JSON.stringify({query:n,variables:s,operationName:i})}).then(e=>e.json()).then(e=>e.errors?Promise.reject(e.errors):e.data)}},createShopifyFetcher=(r,t)=>{let o=r??process.env.NEXT_PUBLIC_STOREFRONT_TOKEN,n=t??process.env.NEXT_PUBLIC_STOREFRONT_HANDLE;return async r=>{if(!o)throw Error("NEXT_PUBLIC_STOREFRONT_TOKEN is not defined");if(!n)throw Error("NEXT_PUBLIC_STOREFRONT_HANDLE is not defined");let t={"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":o},[s,i]=r;return fetch(e(n),{method:"POST",headers:t,body:JSON.stringify({query:s,variables:i})}).then(e=>e.json()).then(e=>e.errors?Promise.reject(e.errors):e.data)}};export{createAppAPIFetcher,createFetcher,createShopifyFetcher};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import MainLayout from '../layouts/main.js';
|
|
3
|
-
|
|
4
|
-
const getLayout = (page, pageProps)=>{
|
|
5
|
-
return /*#__PURE__*/ jsx(MainLayout, {
|
|
6
|
-
...pageProps,
|
|
7
|
-
children: page
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { getLayout };
|
|
1
|
+
import{jsx as t}from"react/jsx-runtime";import o from"../layouts/main.js";let getLayout=(r,e)=>t(o,{...e,children:r});export{getLayout};
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
switch(provider){
|
|
3
|
-
case 'BIGCOMMERCE':
|
|
4
|
-
return `https://${handle}.bigcommerce.com`;
|
|
5
|
-
default:
|
|
6
|
-
return `https://${handle}.myshopify.com/api/2022-07/graphql.json`;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export { getStorefrontApi };
|
|
1
|
+
let getStorefrontApi=(t,o)=>"BIGCOMMERCE"===o?`https://${t}.bigcommerce.com`:`https://${t}.myshopify.com/api/2022-07/graphql.json`;export{getStorefrontApi};
|
|
@@ -1,75 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const composeFonts = (fonts)=>{
|
|
4
|
-
const uniqFonts = fonts.filter((font, index, arr)=>{
|
|
5
|
-
return index === arr.findIndex((t)=>t.family === font.family);
|
|
6
|
-
});
|
|
7
|
-
return uniqFonts.map((font)=>{
|
|
8
|
-
const variants = fonts.filter((t)=>t.family === font.family).reduce((acc, t)=>{
|
|
9
|
-
return [
|
|
10
|
-
...acc,
|
|
11
|
-
...t.variants
|
|
12
|
-
];
|
|
13
|
-
}, []).filter((t, index, arr)=>{
|
|
14
|
-
return index === arr.findIndex((v)=>v === t);
|
|
15
|
-
});
|
|
16
|
-
return {
|
|
17
|
-
...font,
|
|
18
|
-
variants
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
const createFontUrl = (fonts, option)=>{
|
|
23
|
-
const googleFonts = fonts.filter((font)=>font.type === 'google' || !font.type);
|
|
24
|
-
if (!googleFonts.length) return;
|
|
25
|
-
const params = new URLSearchParams();
|
|
26
|
-
const display = option?.display || 'swap';
|
|
27
|
-
const uniqFonts = googleFonts.filter((font, index, arr)=>{
|
|
28
|
-
return index === arr.findIndex((t)=>t.family === font.family);
|
|
29
|
-
});
|
|
30
|
-
const family = composeFonts(uniqFonts).map((font)=>{
|
|
31
|
-
return `${font.family.replace(/ /g, '+')}:${font.variants.join(',')}`;
|
|
32
|
-
}).join('|');
|
|
33
|
-
params.append('family', family);
|
|
34
|
-
params.append('display', display);
|
|
35
|
-
if (option?.subset) {
|
|
36
|
-
params.append('subset', option.subset);
|
|
37
|
-
}
|
|
38
|
-
if (option?.effect) {
|
|
39
|
-
params.append('effect', option.effect);
|
|
40
|
-
}
|
|
41
|
-
return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
|
|
42
|
-
};
|
|
43
|
-
async function getFonts(fonts, option) {
|
|
44
|
-
/**
|
|
45
|
-
* The order of IE -> Chrome is important, other wise chrome starts loading woff1.
|
|
46
|
-
* CSS cascading 🤷♂️.
|
|
47
|
-
*/ const url = createFontUrl(fonts, option);
|
|
48
|
-
if (!url) return '';
|
|
49
|
-
try {
|
|
50
|
-
return `@import url('${url}');`;
|
|
51
|
-
} catch (e) {
|
|
52
|
-
return '';
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const getFontFromGlobalStyle = (data)=>{
|
|
56
|
-
if (!data) return '';
|
|
57
|
-
try {
|
|
58
|
-
const globalStyle = JSON.parse(data);
|
|
59
|
-
const fontData = globalStyle?.font ?? {};
|
|
60
|
-
const fonts = Object.entries(fontData).map(([, value])=>{
|
|
61
|
-
return value;
|
|
62
|
-
});
|
|
63
|
-
return getFonts(fonts);
|
|
64
|
-
} catch {
|
|
65
|
-
return '';
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
async function getFontStyleFromPageTemplate(pageTemplate) {
|
|
69
|
-
const fontStyle = pageTemplate.map((sectionData)=>{
|
|
70
|
-
return getFonts(getFontsFromDataBuilder(sectionData.data));
|
|
71
|
-
});
|
|
72
|
-
return await Promise.all(fontStyle);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { composeFonts, createFontUrl, getFontFromGlobalStyle, getFontStyleFromPageTemplate, getFonts };
|
|
1
|
+
import{getFontsFromDataBuilder as e}from"./helpers/gen-fonts.js";let 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",IE_UA="Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko";async function getFontForUA(e,t){return fetch(e,{headers:{"User-Agent":t}}).then(e=>200===e.status?e.text():"")}let composeFonts=e=>{let t=e.filter((e,t,n)=>t===n.findIndex(t=>t.family===e.family));return t.map(t=>{let n=e.filter(e=>e.family===t.family).reduce((e,t)=>[...e,...t.variants],[]).filter((e,t,n)=>t===n.findIndex(t=>t===e));return{...t,variants:n}})},createFontUrl=(e,t)=>{let n=e.filter(e=>"google"===e.type||!e.type);if(!n.length)return;let r=new URLSearchParams,o=t?.display||"swap",a=n.filter((e,t,n)=>t===n.findIndex(t=>t.family===e.family)),l=composeFonts(a).map(e=>`${e.family.replace(/ /g,"+")}:${e.variants.join(",")}`).join("|");return r.append("family",l),r.append("display",o),t?.subset&&r.append("subset",t.subset),t?.effect&&r.append("effect",t.effect),`https://fonts.googleapis.com/css?${decodeURIComponent(r.toString())}`};async function getFonts(e,t,n=!0){let r=createFontUrl(e,t);if(!r)return"";try{if(n)return`@import url('${r}');`;let[e,t]=await Promise.all([getFontForUA(r,"Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"),getFontForUA(r,"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")]);return e+t}catch(e){return""}}let getFontFromGlobalStyle=e=>{if(!e)return"";try{let t=JSON.parse(e),n=t?.font??{},r=Object.entries(n).map(([,e])=>e);return getFonts(r)}catch{return""}};async function getFontStyleFromPageTemplate(t){let n=t.map(t=>getFonts(e(t.data)));return await Promise.all(n)}export{composeFonts,createFontUrl,getFontFromGlobalStyle,getFontStyleFromPageTemplate,getFonts};
|
|
@@ -1,24 +1 @@
|
|
|
1
|
-
async function wait(
|
|
2
|
-
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
3
|
-
}
|
|
4
|
-
const retryWithDelay = async (fn, config)=>{
|
|
5
|
-
const retries = config?.retries ?? 3;
|
|
6
|
-
const delay = config?.delay ?? 1000;
|
|
7
|
-
try {
|
|
8
|
-
return await fn();
|
|
9
|
-
} catch (err) {
|
|
10
|
-
if (retries <= 0 || config?.retryIf && !config.retryIf(err)) {
|
|
11
|
-
return Promise.reject(err);
|
|
12
|
-
}
|
|
13
|
-
//delay the next call
|
|
14
|
-
await wait(delay);
|
|
15
|
-
//recursively call the same func
|
|
16
|
-
return retryWithDelay(fn, {
|
|
17
|
-
...config,
|
|
18
|
-
retries: retries - 1,
|
|
19
|
-
delay
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export { retryWithDelay, wait };
|
|
1
|
+
async function wait(e){return new Promise(t=>setTimeout(t,e))}let retryWithDelay=async(e,t)=>{let r=t?.retries??3,i=t?.delay??1e3;try{return await e()}catch(a){if(r<=0||t?.retryIf&&!t.retryIf(a))return Promise.reject(a);return await wait(i),retryWithDelay(e,{...t,retries:r-1,delay:i})}};export{retryWithDelay,wait};
|