@makeswift/runtime 0.10.8 → 0.10.10

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 CHANGED
@@ -291,35 +291,6 @@ const FileFragment = `
291
291
  }
292
292
  }
293
293
  `;
294
- const TypographyFragment = `
295
- fragment Typography on Typography {
296
- __typename
297
- id
298
- name
299
- style {
300
- deviceId
301
- value {
302
- fontFamily
303
- fontSize {
304
- value
305
- unit
306
- }
307
- color {
308
- swatchId
309
- alpha
310
- }
311
- lineHeight
312
- letterSpacing
313
- fontWeight
314
- textAlign
315
- uppercase
316
- underline
317
- strikethrough
318
- italic
319
- }
320
- }
321
- }
322
- `;
323
294
  const PagePathnameSliceFragment = `
324
295
  fragment PagePathnameSlice on PagePathnameSlice {
325
296
  __typename
@@ -327,20 +298,6 @@ const PagePathnameSliceFragment = `
327
298
  pathname
328
299
  }
329
300
  `;
330
- const GlobalElementFragment = `
331
- fragment GlobalElement on GlobalElement {
332
- __typename
333
- id
334
- data
335
- }
336
- `;
337
- const LocalizedGlobalElementFragment = `
338
- fragment LocalizedGlobalElement on LocalizedGlobalElement {
339
- __typename
340
- id
341
- data
342
- }
343
- `;
344
301
  const TableFragment = `
345
302
  fragment Table on Table {
346
303
  __typename
@@ -395,15 +352,6 @@ const FileQuery = `
395
352
 
396
353
  ${FileFragment}
397
354
  `;
398
- const TypographyQuery = `
399
- query Typography($typographyId: ID!) {
400
- typography(id: $typographyId) {
401
- ...Typography
402
- }
403
- }
404
-
405
- ${TypographyFragment}
406
- `;
407
355
  const PagePathnamesByIdQuery = `
408
356
  query PagePathnamesById($pageIds: [ID!]!) {
409
357
  pagePathnamesById(ids: $pageIds) {
@@ -422,33 +370,6 @@ const TableQuery = `
422
370
 
423
371
  ${TableFragment}
424
372
  `;
425
- const TypographiesQuery = `
426
- query Typographies($typographyIds: [ID!]!) {
427
- typographies(ids: $typographyIds) {
428
- ...Typography
429
- }
430
- }
431
-
432
- ${TypographyFragment}
433
- `;
434
- const GlobalElementQuery = `
435
- query GlobalElement($globalElementId: ID!) {
436
- globalElement(id: $globalElementId) {
437
- ...GlobalElement
438
- }
439
- }
440
-
441
- ${GlobalElementFragment}
442
- `;
443
- const LocalizedGlobalElementQuery = `
444
- query LocalizedGlobalElement($globalElementId: ID!, $locale: Locale!) {
445
- localizedGlobalElement(globalElementId: $globalElementId, locale: $locale) {
446
- ...LocalizedGlobalElement
447
- }
448
- }
449
-
450
- ${LocalizedGlobalElementFragment}
451
- `;
452
373
  const CreateTableRecordMutation = `
453
374
  mutation CreateTableRecord($input: CreateTableRecordInput!) {
454
375
  createTableRecord(input: $input) {
@@ -930,9 +851,24 @@ Received "${apiKey}" instead.`);
930
851
  const json = await response.json();
931
852
  return json;
932
853
  }
933
- async getTypographies(typographyIds) {
934
- const result = await this.graphqlClient.request(TypographiesQuery, { typographyIds });
935
- return result.typographies;
854
+ async getTypographies(typographyIds, preview) {
855
+ var _a;
856
+ const isUsingVersioning = this.siteVersion != null;
857
+ const url = new URL(`${isUsingVersioning ? "v2" : "v1"}/typographies/bulk`, this.apiOrigin);
858
+ typographyIds.forEach((id) => {
859
+ url.searchParams.append("ids", id);
860
+ });
861
+ const response = await this.fetch(url.pathname + url.search, {
862
+ headers: {
863
+ "Makeswift-Site-Version": (_a = this.siteVersion) != null ? _a : preview ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live
864
+ }
865
+ });
866
+ if (!response.ok) {
867
+ console.error("Failed to get typographies", await response.json());
868
+ return [];
869
+ }
870
+ const body = await response.json();
871
+ return body;
936
872
  }
937
873
  async getSwatches(ids, preview) {
938
874
  var _a;
@@ -1020,7 +956,7 @@ Received "${apiKey}" instead.`);
1020
956
  continue;
1021
957
  getResourcesFromElementDescriptors(elementDescriptors, element2.props);
1022
958
  }
1023
- const typographies = await this.getTypographies([...typographyIds]);
959
+ const typographies = await this.getTypographies([...typographyIds], preview);
1024
960
  typographies.forEach((typography) => {
1025
961
  typography == null ? void 0 : typography.style.forEach((style) => {
1026
962
  var _a2;
@@ -1141,16 +1077,37 @@ Received "${apiKey}" instead.`);
1141
1077
  return result.file;
1142
1078
  }
1143
1079
  async getTypography(typographyId) {
1144
- const result = await this.graphqlClient.request(TypographyQuery, { typographyId });
1145
- return result.typography;
1080
+ const isUsingVersioning = this.siteVersion != null;
1081
+ const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/typographies/${typographyId}`);
1082
+ if (!response.ok) {
1083
+ if (response.status !== 404)
1084
+ console.error("Failed to get typography", await response.json());
1085
+ return null;
1086
+ }
1087
+ const typography = await response.json();
1088
+ return typography;
1146
1089
  }
1147
1090
  async getGlobalElement(globalElementId) {
1148
- const result = await this.graphqlClient.request(GlobalElementQuery, { globalElementId });
1149
- return result.globalElement;
1091
+ const isUsingVersioning = this.siteVersion != null;
1092
+ const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/global-elements/${globalElementId}`);
1093
+ if (!response.ok) {
1094
+ if (response.status !== 404)
1095
+ console.error("Failed to get global element", await response.json());
1096
+ return null;
1097
+ }
1098
+ const globalElement = await response.json();
1099
+ return globalElement;
1150
1100
  }
1151
1101
  async getLocalizedGlobalElement(globalElementId, locale) {
1152
- const result = await this.graphqlClient.request(LocalizedGlobalElementQuery, { globalElementId, locale });
1153
- return result.localizedGlobalElement;
1102
+ const isUsingVersioning = this.siteVersion != null;
1103
+ const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/localized-global-elements/${globalElementId}?locale=${locale}`);
1104
+ if (!response.ok) {
1105
+ if (response.status !== 404)
1106
+ console.error("Failed to get localized global element", await response.json());
1107
+ return null;
1108
+ }
1109
+ const localizedGlobalElement = await response.json();
1110
+ return localizedGlobalElement;
1154
1111
  }
1155
1112
  async getPagePathnameSlice(pageId) {
1156
1113
  var _a;
@@ -1235,7 +1192,7 @@ async function fonts(_req, res, { getFonts } = {}) {
1235
1192
  const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
1236
1193
  return res.json(fonts2);
1237
1194
  }
1238
- const version = "0.10.8";
1195
+ const version = "0.10.10";
1239
1196
  async function handler(req, res, { apiKey, unstable_siteVersions }) {
1240
1197
  if (req.query.secret !== apiKey) {
1241
1198
  return res.status(401).json({ message: "Unauthorized" });
@@ -1253,7 +1210,7 @@ async function handler(req, res, { apiKey, unstable_siteVersions }) {
1253
1210
  }
1254
1211
  async function proxyPreviewMode(req, res, { apiKey }) {
1255
1212
  const previewModeProxy = httpProxy.createProxyServer();
1256
- const NextRequestMetaSymbol = Reflect.ownKeys(req).find((key) => key.toString() === "Symbol(NextRequestMeta)");
1213
+ const NextRequestMetaSymbol = Reflect.ownKeys(req).find((key) => key.toString() === "Symbol(NextRequestMeta)" || key.toString() === "Symbol(NextInternalRequestMeta)");
1257
1214
  if (NextRequestMetaSymbol) {
1258
1215
  const nextRequestMeta = req[NextRequestMetaSymbol];
1259
1216
  const initUrl = nextRequestMeta == null ? void 0 : nextRequestMeta.__NEXT_INIT_URL;