@makeswift/runtime 0.11.7 → 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 +73 -36
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +73 -36
- 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/next/api-handler/index.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +42 -1
- 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);
|
|
@@ -779,6 +758,20 @@ if (window.parent !== window) {
|
|
|
779
758
|
})]
|
|
780
759
|
});
|
|
781
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
|
+
});
|
|
782
775
|
class Makeswift {
|
|
783
776
|
constructor(apiKey, {
|
|
784
777
|
apiOrigin = "https://api.makeswift.com",
|
|
@@ -832,6 +825,25 @@ Received "${apiKey}" instead.`);
|
|
|
832
825
|
const json = await response.json();
|
|
833
826
|
return json;
|
|
834
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
|
+
}
|
|
835
847
|
async getTypographies(typographyIds, preview) {
|
|
836
848
|
var _a;
|
|
837
849
|
const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/typographies/bulk`, this.apiOrigin);
|
|
@@ -944,15 +956,12 @@ Received "${apiKey}" instead.`);
|
|
|
944
956
|
swatchIds.add(swatchId);
|
|
945
957
|
});
|
|
946
958
|
});
|
|
947
|
-
const
|
|
959
|
+
const pagePathnames = await this.getPagePathnameSlices([...pageIds], { preview, locale });
|
|
960
|
+
const { swatches, files, tables } = await this.getIntrospectedResources({
|
|
948
961
|
swatchIds: [...swatchIds],
|
|
949
962
|
fileIds: [...fileIds],
|
|
950
|
-
tableIds: [...tableIds]
|
|
951
|
-
pageIds: [...pageIds]
|
|
963
|
+
tableIds: [...tableIds]
|
|
952
964
|
}, preview);
|
|
953
|
-
const pagePathnameSlices = pagePathnamesById.map((pagePathnameSlice) => pagePathnameSlice && __spreadProps(__spreadValues({}, pagePathnameSlice), {
|
|
954
|
-
id: Buffer.from(`Page:${pagePathnameSlice.id}`).toString("base64")
|
|
955
|
-
}));
|
|
956
965
|
const cacheData = {
|
|
957
966
|
[APIResourceType.Swatch]: [...swatchIds].map((id) => {
|
|
958
967
|
var _a2;
|
|
@@ -986,7 +995,7 @@ Received "${apiKey}" instead.`);
|
|
|
986
995
|
var _a2;
|
|
987
996
|
return {
|
|
988
997
|
id,
|
|
989
|
-
value: (_a2 =
|
|
998
|
+
value: (_a2 = pagePathnames.find((pagePathnameSlice) => (pagePathnameSlice == null ? void 0 : pagePathnameSlice.id) === id)) != null ? _a2 : null
|
|
990
999
|
};
|
|
991
1000
|
}),
|
|
992
1001
|
[APIResourceType.GlobalElement]: [...globalElements.entries()].map(([id, value]) => ({
|
|
@@ -1078,10 +1087,37 @@ Received "${apiKey}" instead.`);
|
|
|
1078
1087
|
const localizedGlobalElement = await response.json();
|
|
1079
1088
|
return localizedGlobalElement;
|
|
1080
1089
|
}
|
|
1081
|
-
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 } = {}) {
|
|
1082
1118
|
var _a;
|
|
1083
|
-
const
|
|
1084
|
-
return (_a =
|
|
1119
|
+
const pagePathnameSlices = await this.getPagePathnameSlices([pageId], { preview, locale });
|
|
1120
|
+
return (_a = pagePathnameSlices.at(0)) != null ? _a : null;
|
|
1085
1121
|
}
|
|
1086
1122
|
async getTable(tableId) {
|
|
1087
1123
|
const result = await this.graphqlClient.request(TableQuery, { tableId });
|
|
@@ -1170,7 +1206,7 @@ async function fonts(_req, res, { getFonts } = {}) {
|
|
|
1170
1206
|
const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
|
|
1171
1207
|
return res.json(fonts2);
|
|
1172
1208
|
}
|
|
1173
|
-
const version = "0.11.
|
|
1209
|
+
const version = "0.11.8";
|
|
1174
1210
|
async function handler(req, res, { apiKey, siteVersions }) {
|
|
1175
1211
|
if (req.query.secret !== apiKey) {
|
|
1176
1212
|
return res.status(401).json({ message: "Unauthorized" });
|
|
@@ -1359,7 +1395,8 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
|
|
|
1359
1395
|
return client.getLocalizedGlobalElement(m.params.globalElementId, m.params.locale).then((resource) => resource === null ? res.json({ message: "Not Found" }) : res.json(resource));
|
|
1360
1396
|
}
|
|
1361
1397
|
if (m = matches("/page-pathname-slices/:id")) {
|
|
1362
|
-
|
|
1398
|
+
const locale = typeof req.query.locale === "string" ? req.query.locale : void 0;
|
|
1399
|
+
return client.getPagePathnameSlice(m.params.id, { locale }).then(handleResource);
|
|
1363
1400
|
}
|
|
1364
1401
|
if (m = matches("/tables/:id")) {
|
|
1365
1402
|
return client.getTable(m.params.id).then(handleResource);
|