@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.cjs.js
CHANGED
|
@@ -246,7 +246,7 @@ function fetchAPIResource(resourceType, resourceId, locale) {
|
|
|
246
246
|
break;
|
|
247
247
|
}
|
|
248
248
|
case types.APIResourceType.PagePathnameSlice:
|
|
249
|
-
resource = await fetchJson(`/api/makeswift/page-pathname-slices/${resourceId}`);
|
|
249
|
+
resource = await fetchJson(`/api/makeswift/page-pathname-slices/${resourceId}?locale=${locale}`);
|
|
250
250
|
break;
|
|
251
251
|
case types.APIResourceType.Table:
|
|
252
252
|
resource = await fetchJson(`/api/makeswift/tables/${resourceId}`);
|
|
@@ -296,13 +296,6 @@ const FileFragment = `
|
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
`;
|
|
299
|
-
const PagePathnameSliceFragment = `
|
|
300
|
-
fragment PagePathnameSlice on PagePathnameSlice {
|
|
301
|
-
__typename
|
|
302
|
-
id
|
|
303
|
-
pathname
|
|
304
|
-
}
|
|
305
|
-
`;
|
|
306
299
|
const TableFragment = `
|
|
307
300
|
fragment Table on Table {
|
|
308
301
|
__typename
|
|
@@ -330,22 +323,17 @@ const TableFragment = `
|
|
|
330
323
|
}
|
|
331
324
|
`;
|
|
332
325
|
const IntrospectedResourcesQuery = `
|
|
333
|
-
query IntrospectedResources($fileIds: [ID!]!, $
|
|
326
|
+
query IntrospectedResources($fileIds: [ID!]!, $tableIds: [ID!]!) {
|
|
334
327
|
files(ids: $fileIds) {
|
|
335
328
|
...File
|
|
336
329
|
}
|
|
337
330
|
|
|
338
|
-
pagePathnamesById(ids: $pageIds) {
|
|
339
|
-
...PagePathnameSlice
|
|
340
|
-
}
|
|
341
|
-
|
|
342
331
|
tables(ids: $tableIds) {
|
|
343
332
|
...Table
|
|
344
333
|
}
|
|
345
334
|
}
|
|
346
335
|
|
|
347
336
|
${FileFragment}
|
|
348
|
-
${PagePathnameSliceFragment}
|
|
349
337
|
${TableFragment}
|
|
350
338
|
`;
|
|
351
339
|
const FileQuery = `
|
|
@@ -357,15 +345,6 @@ const FileQuery = `
|
|
|
357
345
|
|
|
358
346
|
${FileFragment}
|
|
359
347
|
`;
|
|
360
|
-
const PagePathnamesByIdQuery = `
|
|
361
|
-
query PagePathnamesById($pageIds: [ID!]!) {
|
|
362
|
-
pagePathnamesById(ids: $pageIds) {
|
|
363
|
-
...PagePathnameSlice
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
${PagePathnameSliceFragment}
|
|
368
|
-
`;
|
|
369
348
|
const TableQuery = `
|
|
370
349
|
query Table($tableId: ID!) {
|
|
371
350
|
table(id: $tableId) {
|
|
@@ -456,7 +435,7 @@ class MakeswiftClient {
|
|
|
456
435
|
return getAPIResource(this.makeswiftApiClient.getState(), types.APIResourceType.PagePathnameSlice, pageId);
|
|
457
436
|
}
|
|
458
437
|
async fetchPagePathnameSlice(pageId) {
|
|
459
|
-
return await this.makeswiftApiClient.dispatch(fetchAPIResource(types.APIResourceType.PagePathnameSlice, pageId));
|
|
438
|
+
return await this.makeswiftApiClient.dispatch(fetchAPIResource(types.APIResourceType.PagePathnameSlice, pageId, this.locale));
|
|
460
439
|
}
|
|
461
440
|
readTable(tableId) {
|
|
462
441
|
return getAPIResource(this.makeswiftApiClient.getState(), types.APIResourceType.Table, tableId);
|
|
@@ -571,7 +550,6 @@ function Page$1({
|
|
|
571
550
|
const socialImage = (_e = baseLocalizedPage == null ? void 0 : baseLocalizedPage.meta.socialImage) != null ? _e : page.meta.socialImage;
|
|
572
551
|
const canonicalUrl = (_f = baseLocalizedPage == null ? void 0 : baseLocalizedPage.seo.canonicalUrl) != null ? _f : page.seo.canonicalUrl;
|
|
573
552
|
const isIndexingBlocked = (_g = baseLocalizedPage == null ? void 0 : baseLocalizedPage.seo.isIndexingBlocked) != null ? _g : page.seo.isIndexingBlocked;
|
|
574
|
-
const hreflangs = page.hreflangs;
|
|
575
553
|
const fontFamilyParamValue = React.useMemo(() => {
|
|
576
554
|
if (site == null) {
|
|
577
555
|
return page.fonts.map(({
|
|
@@ -683,14 +661,7 @@ function Page$1({
|
|
|
683
661
|
rel: "stylesheet",
|
|
684
662
|
href: `https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`
|
|
685
663
|
})
|
|
686
|
-
}),
|
|
687
|
-
hreflang,
|
|
688
|
-
href
|
|
689
|
-
}) => /* @__PURE__ */ jsxRuntime.jsx("link", {
|
|
690
|
-
rel: "alternate",
|
|
691
|
-
hrefLang: hreflang,
|
|
692
|
-
href
|
|
693
|
-
}, hreflang)), headSnippets.map(snippetToElement).map((children) => React.Children.map(children, (child) => {
|
|
664
|
+
}), headSnippets.map(snippetToElement).map((children) => React.Children.map(children, (child) => {
|
|
694
665
|
if (typeof child === "string")
|
|
695
666
|
return child;
|
|
696
667
|
if (VALID_HEAD_ELEMENT_TYPES.includes(child.type))
|
|
@@ -820,6 +791,20 @@ if (window.parent !== window) {
|
|
|
820
791
|
})]
|
|
821
792
|
});
|
|
822
793
|
}
|
|
794
|
+
const pagePathnameSlicesAPISchema = zod.z.array(zod.z.object({
|
|
795
|
+
id: zod.z.string(),
|
|
796
|
+
basePageId: zod.z.string(),
|
|
797
|
+
pathname: zod.z.string(),
|
|
798
|
+
__typename: zod.z.literal("PagePathnameSlice")
|
|
799
|
+
}).nullable());
|
|
800
|
+
const getPageAPISchema = zod.z.object({
|
|
801
|
+
pathname: zod.z.string(),
|
|
802
|
+
locale: zod.z.string(),
|
|
803
|
+
alternate: zod.z.array(zod.z.object({
|
|
804
|
+
pathname: zod.z.string(),
|
|
805
|
+
locale: zod.z.string()
|
|
806
|
+
}))
|
|
807
|
+
});
|
|
823
808
|
class Makeswift {
|
|
824
809
|
constructor(apiKey, {
|
|
825
810
|
apiOrigin = "https://api.makeswift.com",
|
|
@@ -873,6 +858,25 @@ Received "${apiKey}" instead.`);
|
|
|
873
858
|
const json = await response.json();
|
|
874
859
|
return json;
|
|
875
860
|
}
|
|
861
|
+
async getPage(pathname, {
|
|
862
|
+
preview: previewOverride = false,
|
|
863
|
+
locale: localeInput
|
|
864
|
+
} = {}) {
|
|
865
|
+
var _a;
|
|
866
|
+
const siteVersion = (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live;
|
|
867
|
+
const searchParams = new URLSearchParams();
|
|
868
|
+
if (localeInput)
|
|
869
|
+
searchParams.set("locale", localeInput);
|
|
870
|
+
const response = await this.fetch(`v1/pages/${encodeURIComponent(pathname)}?${searchParams.toString()}`, { headers: { "Makeswift-Site-Version": siteVersion } });
|
|
871
|
+
if (!response.ok) {
|
|
872
|
+
if (response.status === 404)
|
|
873
|
+
return null;
|
|
874
|
+
console.error("Failed to get page snapshot", await response.json());
|
|
875
|
+
throw new Error(`Failed to get page snapshot with error: "${response.statusText}"`);
|
|
876
|
+
}
|
|
877
|
+
const json = await response.json();
|
|
878
|
+
return getPageAPISchema.parse(json);
|
|
879
|
+
}
|
|
876
880
|
async getTypographies(typographyIds, preview) {
|
|
877
881
|
var _a;
|
|
878
882
|
const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/typographies/bulk`, this.apiOrigin);
|
|
@@ -985,15 +989,12 @@ Received "${apiKey}" instead.`);
|
|
|
985
989
|
swatchIds.add(swatchId);
|
|
986
990
|
});
|
|
987
991
|
});
|
|
988
|
-
const
|
|
992
|
+
const pagePathnames = await this.getPagePathnameSlices([...pageIds], { preview, locale });
|
|
993
|
+
const { swatches, files, tables } = await this.getIntrospectedResources({
|
|
989
994
|
swatchIds: [...swatchIds],
|
|
990
995
|
fileIds: [...fileIds],
|
|
991
|
-
tableIds: [...tableIds]
|
|
992
|
-
pageIds: [...pageIds]
|
|
996
|
+
tableIds: [...tableIds]
|
|
993
997
|
}, preview);
|
|
994
|
-
const pagePathnameSlices = pagePathnamesById.map((pagePathnameSlice) => pagePathnameSlice && __spreadProps(__spreadValues({}, pagePathnameSlice), {
|
|
995
|
-
id: Buffer.from(`Page:${pagePathnameSlice.id}`).toString("base64")
|
|
996
|
-
}));
|
|
997
998
|
const cacheData = {
|
|
998
999
|
[types.APIResourceType.Swatch]: [...swatchIds].map((id) => {
|
|
999
1000
|
var _a2;
|
|
@@ -1027,7 +1028,7 @@ Received "${apiKey}" instead.`);
|
|
|
1027
1028
|
var _a2;
|
|
1028
1029
|
return {
|
|
1029
1030
|
id,
|
|
1030
|
-
value: (_a2 =
|
|
1031
|
+
value: (_a2 = pagePathnames.find((pagePathnameSlice) => (pagePathnameSlice == null ? void 0 : pagePathnameSlice.id) === id)) != null ? _a2 : null
|
|
1031
1032
|
};
|
|
1032
1033
|
}),
|
|
1033
1034
|
[types.APIResourceType.GlobalElement]: [...globalElements.entries()].map(([id, value]) => ({
|
|
@@ -1119,10 +1120,37 @@ Received "${apiKey}" instead.`);
|
|
|
1119
1120
|
const localizedGlobalElement = await response.json();
|
|
1120
1121
|
return localizedGlobalElement;
|
|
1121
1122
|
}
|
|
1122
|
-
async
|
|
1123
|
+
async getPagePathnameSlices(pageIds, { preview: previewOverride = false, locale } = {}) {
|
|
1124
|
+
var _a;
|
|
1125
|
+
const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/page-pathname-slices/bulk`, this.apiOrigin);
|
|
1126
|
+
pageIds.forEach((id) => url.searchParams.append("ids", id));
|
|
1127
|
+
if (locale != null)
|
|
1128
|
+
url.searchParams.set("locale", locale);
|
|
1129
|
+
const response = await this.fetch(url.pathname + url.search, {
|
|
1130
|
+
headers: {
|
|
1131
|
+
"Makeswift-Site-Version": (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
if (!response.ok) {
|
|
1135
|
+
console.error("Failed to get page pathname slices", await response.json());
|
|
1136
|
+
return [];
|
|
1137
|
+
}
|
|
1138
|
+
const json = await response.json();
|
|
1139
|
+
const pagePathnameSlices = pagePathnameSlicesAPISchema.parse(json);
|
|
1140
|
+
return pagePathnameSlices.map((pagePathnameSlice) => {
|
|
1141
|
+
if (pagePathnameSlice == null)
|
|
1142
|
+
return null;
|
|
1143
|
+
return {
|
|
1144
|
+
id: pagePathnameSlice.basePageId,
|
|
1145
|
+
pathname: pagePathnameSlice.pathname,
|
|
1146
|
+
__typename: pagePathnameSlice.__typename
|
|
1147
|
+
};
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
async getPagePathnameSlice(pageId, { preview = false, locale } = {}) {
|
|
1123
1151
|
var _a;
|
|
1124
|
-
const
|
|
1125
|
-
return (_a =
|
|
1152
|
+
const pagePathnameSlices = await this.getPagePathnameSlices([pageId], { preview, locale });
|
|
1153
|
+
return (_a = pagePathnameSlices.at(0)) != null ? _a : null;
|
|
1126
1154
|
}
|
|
1127
1155
|
async getTable(tableId) {
|
|
1128
1156
|
const result = await this.graphqlClient.request(TableQuery, { tableId });
|
|
@@ -1211,7 +1239,7 @@ async function fonts(_req, res, { getFonts } = {}) {
|
|
|
1211
1239
|
const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
|
|
1212
1240
|
return res.json(fonts2);
|
|
1213
1241
|
}
|
|
1214
|
-
const version = "0.11.
|
|
1242
|
+
const version = "0.11.8";
|
|
1215
1243
|
async function handler(req, res, { apiKey, siteVersions }) {
|
|
1216
1244
|
if (req.query.secret !== apiKey) {
|
|
1217
1245
|
return res.status(401).json({ message: "Unauthorized" });
|
|
@@ -1400,7 +1428,8 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
|
|
|
1400
1428
|
return client.getLocalizedGlobalElement(m.params.globalElementId, m.params.locale).then((resource) => resource === null ? res.json({ message: "Not Found" }) : res.json(resource));
|
|
1401
1429
|
}
|
|
1402
1430
|
if (m = matches("/page-pathname-slices/:id")) {
|
|
1403
|
-
|
|
1431
|
+
const locale = typeof req.query.locale === "string" ? req.query.locale : void 0;
|
|
1432
|
+
return client.getPagePathnameSlice(m.params.id, { locale }).then(handleResource);
|
|
1404
1433
|
}
|
|
1405
1434
|
if (m = matches("/tables/:id")) {
|
|
1406
1435
|
return client.getTable(m.params.id).then(handleResource);
|