@makeswift/runtime 0.11.6 → 0.11.8
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/index.cjs.js +74 -45
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +74 -45
- package/dist/index.es.js.map +1 -1
- package/dist/types/src/api/graphql/documents/queries.d.ts +0 -2
- package/dist/types/src/api/graphql/documents/queries.d.ts.map +1 -1
- package/dist/types/src/api/graphql/generated/types.d.ts +0 -27
- package/dist/types/src/api/graphql/generated/types.d.ts.map +1 -1
- package/dist/types/src/components/page/Page.d.ts.map +1 -1
- package/dist/types/src/next/api-handler/index.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +42 -6
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -213,7 +213,7 @@ function fetchAPIResource(resourceType, resourceId, locale) {
|
|
|
213
213
|
break;
|
|
214
214
|
}
|
|
215
215
|
case APIResourceType.PagePathnameSlice:
|
|
216
|
-
resource = await fetchJson(`/api/makeswift/page-pathname-slices/${resourceId}`);
|
|
216
|
+
resource = await fetchJson(`/api/makeswift/page-pathname-slices/${resourceId}?locale=${locale}`);
|
|
217
217
|
break;
|
|
218
218
|
case APIResourceType.Table:
|
|
219
219
|
resource = await fetchJson(`/api/makeswift/tables/${resourceId}`);
|
|
@@ -263,13 +263,6 @@ const FileFragment = `
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
`;
|
|
266
|
-
const PagePathnameSliceFragment = `
|
|
267
|
-
fragment PagePathnameSlice on PagePathnameSlice {
|
|
268
|
-
__typename
|
|
269
|
-
id
|
|
270
|
-
pathname
|
|
271
|
-
}
|
|
272
|
-
`;
|
|
273
266
|
const TableFragment = `
|
|
274
267
|
fragment Table on Table {
|
|
275
268
|
__typename
|
|
@@ -297,22 +290,17 @@ const TableFragment = `
|
|
|
297
290
|
}
|
|
298
291
|
`;
|
|
299
292
|
const IntrospectedResourcesQuery = `
|
|
300
|
-
query IntrospectedResources($fileIds: [ID!]!, $
|
|
293
|
+
query IntrospectedResources($fileIds: [ID!]!, $tableIds: [ID!]!) {
|
|
301
294
|
files(ids: $fileIds) {
|
|
302
295
|
...File
|
|
303
296
|
}
|
|
304
297
|
|
|
305
|
-
pagePathnamesById(ids: $pageIds) {
|
|
306
|
-
...PagePathnameSlice
|
|
307
|
-
}
|
|
308
|
-
|
|
309
298
|
tables(ids: $tableIds) {
|
|
310
299
|
...Table
|
|
311
300
|
}
|
|
312
301
|
}
|
|
313
302
|
|
|
314
303
|
${FileFragment}
|
|
315
|
-
${PagePathnameSliceFragment}
|
|
316
304
|
${TableFragment}
|
|
317
305
|
`;
|
|
318
306
|
const FileQuery = `
|
|
@@ -324,15 +312,6 @@ const FileQuery = `
|
|
|
324
312
|
|
|
325
313
|
${FileFragment}
|
|
326
314
|
`;
|
|
327
|
-
const PagePathnamesByIdQuery = `
|
|
328
|
-
query PagePathnamesById($pageIds: [ID!]!) {
|
|
329
|
-
pagePathnamesById(ids: $pageIds) {
|
|
330
|
-
...PagePathnameSlice
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
${PagePathnameSliceFragment}
|
|
335
|
-
`;
|
|
336
315
|
const TableQuery = `
|
|
337
316
|
query Table($tableId: ID!) {
|
|
338
317
|
table(id: $tableId) {
|
|
@@ -423,7 +402,7 @@ class MakeswiftClient {
|
|
|
423
402
|
return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.PagePathnameSlice, pageId);
|
|
424
403
|
}
|
|
425
404
|
async fetchPagePathnameSlice(pageId) {
|
|
426
|
-
return await this.makeswiftApiClient.dispatch(fetchAPIResource(APIResourceType.PagePathnameSlice, pageId));
|
|
405
|
+
return await this.makeswiftApiClient.dispatch(fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, this.locale));
|
|
427
406
|
}
|
|
428
407
|
readTable(tableId) {
|
|
429
408
|
return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.Table, tableId);
|
|
@@ -538,7 +517,6 @@ function Page$1({
|
|
|
538
517
|
const socialImage = (_e = baseLocalizedPage == null ? void 0 : baseLocalizedPage.meta.socialImage) != null ? _e : page.meta.socialImage;
|
|
539
518
|
const canonicalUrl = (_f = baseLocalizedPage == null ? void 0 : baseLocalizedPage.seo.canonicalUrl) != null ? _f : page.seo.canonicalUrl;
|
|
540
519
|
const isIndexingBlocked = (_g = baseLocalizedPage == null ? void 0 : baseLocalizedPage.seo.isIndexingBlocked) != null ? _g : page.seo.isIndexingBlocked;
|
|
541
|
-
const hreflangs = page.hreflangs;
|
|
542
520
|
const fontFamilyParamValue = useMemo(() => {
|
|
543
521
|
if (site == null) {
|
|
544
522
|
return page.fonts.map(({
|
|
@@ -650,14 +628,7 @@ function Page$1({
|
|
|
650
628
|
rel: "stylesheet",
|
|
651
629
|
href: `https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`
|
|
652
630
|
})
|
|
653
|
-
}),
|
|
654
|
-
hreflang,
|
|
655
|
-
href
|
|
656
|
-
}) => /* @__PURE__ */ jsx("link", {
|
|
657
|
-
rel: "alternate",
|
|
658
|
-
hrefLang: hreflang,
|
|
659
|
-
href
|
|
660
|
-
}, hreflang)), headSnippets.map(snippetToElement).map((children) => Children.map(children, (child) => {
|
|
631
|
+
}), headSnippets.map(snippetToElement).map((children) => Children.map(children, (child) => {
|
|
661
632
|
if (typeof child === "string")
|
|
662
633
|
return child;
|
|
663
634
|
if (VALID_HEAD_ELEMENT_TYPES.includes(child.type))
|
|
@@ -787,6 +758,20 @@ if (window.parent !== window) {
|
|
|
787
758
|
})]
|
|
788
759
|
});
|
|
789
760
|
}
|
|
761
|
+
const pagePathnameSlicesAPISchema = z.array(z.object({
|
|
762
|
+
id: z.string(),
|
|
763
|
+
basePageId: z.string(),
|
|
764
|
+
pathname: z.string(),
|
|
765
|
+
__typename: z.literal("PagePathnameSlice")
|
|
766
|
+
}).nullable());
|
|
767
|
+
const getPageAPISchema = z.object({
|
|
768
|
+
pathname: z.string(),
|
|
769
|
+
locale: z.string(),
|
|
770
|
+
alternate: z.array(z.object({
|
|
771
|
+
pathname: z.string(),
|
|
772
|
+
locale: z.string()
|
|
773
|
+
}))
|
|
774
|
+
});
|
|
790
775
|
class Makeswift {
|
|
791
776
|
constructor(apiKey, {
|
|
792
777
|
apiOrigin = "https://api.makeswift.com",
|
|
@@ -840,6 +825,25 @@ Received "${apiKey}" instead.`);
|
|
|
840
825
|
const json = await response.json();
|
|
841
826
|
return json;
|
|
842
827
|
}
|
|
828
|
+
async getPage(pathname, {
|
|
829
|
+
preview: previewOverride = false,
|
|
830
|
+
locale: localeInput
|
|
831
|
+
} = {}) {
|
|
832
|
+
var _a;
|
|
833
|
+
const siteVersion = (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live;
|
|
834
|
+
const searchParams = new URLSearchParams();
|
|
835
|
+
if (localeInput)
|
|
836
|
+
searchParams.set("locale", localeInput);
|
|
837
|
+
const response = await this.fetch(`v1/pages/${encodeURIComponent(pathname)}?${searchParams.toString()}`, { headers: { "Makeswift-Site-Version": siteVersion } });
|
|
838
|
+
if (!response.ok) {
|
|
839
|
+
if (response.status === 404)
|
|
840
|
+
return null;
|
|
841
|
+
console.error("Failed to get page snapshot", await response.json());
|
|
842
|
+
throw new Error(`Failed to get page snapshot with error: "${response.statusText}"`);
|
|
843
|
+
}
|
|
844
|
+
const json = await response.json();
|
|
845
|
+
return getPageAPISchema.parse(json);
|
|
846
|
+
}
|
|
843
847
|
async getTypographies(typographyIds, preview) {
|
|
844
848
|
var _a;
|
|
845
849
|
const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/typographies/bulk`, this.apiOrigin);
|
|
@@ -952,15 +956,12 @@ Received "${apiKey}" instead.`);
|
|
|
952
956
|
swatchIds.add(swatchId);
|
|
953
957
|
});
|
|
954
958
|
});
|
|
955
|
-
const
|
|
959
|
+
const pagePathnames = await this.getPagePathnameSlices([...pageIds], { preview, locale });
|
|
960
|
+
const { swatches, files, tables } = await this.getIntrospectedResources({
|
|
956
961
|
swatchIds: [...swatchIds],
|
|
957
962
|
fileIds: [...fileIds],
|
|
958
|
-
tableIds: [...tableIds]
|
|
959
|
-
pageIds: [...pageIds]
|
|
963
|
+
tableIds: [...tableIds]
|
|
960
964
|
}, preview);
|
|
961
|
-
const pagePathnameSlices = pagePathnamesById.map((pagePathnameSlice) => pagePathnameSlice && __spreadProps(__spreadValues({}, pagePathnameSlice), {
|
|
962
|
-
id: Buffer.from(`Page:${pagePathnameSlice.id}`).toString("base64")
|
|
963
|
-
}));
|
|
964
965
|
const cacheData = {
|
|
965
966
|
[APIResourceType.Swatch]: [...swatchIds].map((id) => {
|
|
966
967
|
var _a2;
|
|
@@ -994,7 +995,7 @@ Received "${apiKey}" instead.`);
|
|
|
994
995
|
var _a2;
|
|
995
996
|
return {
|
|
996
997
|
id,
|
|
997
|
-
value: (_a2 =
|
|
998
|
+
value: (_a2 = pagePathnames.find((pagePathnameSlice) => (pagePathnameSlice == null ? void 0 : pagePathnameSlice.id) === id)) != null ? _a2 : null
|
|
998
999
|
};
|
|
999
1000
|
}),
|
|
1000
1001
|
[APIResourceType.GlobalElement]: [...globalElements.entries()].map(([id, value]) => ({
|
|
@@ -1086,10 +1087,37 @@ Received "${apiKey}" instead.`);
|
|
|
1086
1087
|
const localizedGlobalElement = await response.json();
|
|
1087
1088
|
return localizedGlobalElement;
|
|
1088
1089
|
}
|
|
1089
|
-
async
|
|
1090
|
+
async getPagePathnameSlices(pageIds, { preview: previewOverride = false, locale } = {}) {
|
|
1091
|
+
var _a;
|
|
1092
|
+
const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/page-pathname-slices/bulk`, this.apiOrigin);
|
|
1093
|
+
pageIds.forEach((id) => url.searchParams.append("ids", id));
|
|
1094
|
+
if (locale != null)
|
|
1095
|
+
url.searchParams.set("locale", locale);
|
|
1096
|
+
const response = await this.fetch(url.pathname + url.search, {
|
|
1097
|
+
headers: {
|
|
1098
|
+
"Makeswift-Site-Version": (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
if (!response.ok) {
|
|
1102
|
+
console.error("Failed to get page pathname slices", await response.json());
|
|
1103
|
+
return [];
|
|
1104
|
+
}
|
|
1105
|
+
const json = await response.json();
|
|
1106
|
+
const pagePathnameSlices = pagePathnameSlicesAPISchema.parse(json);
|
|
1107
|
+
return pagePathnameSlices.map((pagePathnameSlice) => {
|
|
1108
|
+
if (pagePathnameSlice == null)
|
|
1109
|
+
return null;
|
|
1110
|
+
return {
|
|
1111
|
+
id: pagePathnameSlice.basePageId,
|
|
1112
|
+
pathname: pagePathnameSlice.pathname,
|
|
1113
|
+
__typename: pagePathnameSlice.__typename
|
|
1114
|
+
};
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
async getPagePathnameSlice(pageId, { preview = false, locale } = {}) {
|
|
1090
1118
|
var _a;
|
|
1091
|
-
const
|
|
1092
|
-
return (_a =
|
|
1119
|
+
const pagePathnameSlices = await this.getPagePathnameSlices([pageId], { preview, locale });
|
|
1120
|
+
return (_a = pagePathnameSlices.at(0)) != null ? _a : null;
|
|
1093
1121
|
}
|
|
1094
1122
|
async getTable(tableId) {
|
|
1095
1123
|
const result = await this.graphqlClient.request(TableQuery, { tableId });
|
|
@@ -1178,7 +1206,7 @@ async function fonts(_req, res, { getFonts } = {}) {
|
|
|
1178
1206
|
const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
|
|
1179
1207
|
return res.json(fonts2);
|
|
1180
1208
|
}
|
|
1181
|
-
const version = "0.11.
|
|
1209
|
+
const version = "0.11.8";
|
|
1182
1210
|
async function handler(req, res, { apiKey, siteVersions }) {
|
|
1183
1211
|
if (req.query.secret !== apiKey) {
|
|
1184
1212
|
return res.status(401).json({ message: "Unauthorized" });
|
|
@@ -1367,7 +1395,8 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
|
|
|
1367
1395
|
return client.getLocalizedGlobalElement(m.params.globalElementId, m.params.locale).then((resource) => resource === null ? res.json({ message: "Not Found" }) : res.json(resource));
|
|
1368
1396
|
}
|
|
1369
1397
|
if (m = matches("/page-pathname-slices/:id")) {
|
|
1370
|
-
|
|
1398
|
+
const locale = typeof req.query.locale === "string" ? req.query.locale : void 0;
|
|
1399
|
+
return client.getPagePathnameSlice(m.params.id, { locale }).then(handleResource);
|
|
1371
1400
|
}
|
|
1372
1401
|
if (m = matches("/tables/:id")) {
|
|
1373
1402
|
return client.getTable(m.params.id).then(handleResource);
|