@makeswift/runtime 0.10.9 → 0.10.11

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) {
@@ -781,12 +702,12 @@ const makeswiftSiteVersionSchema = zod.z.enum(["Live", "Working"]);
781
702
  const MakeswiftSiteVersion = makeswiftSiteVersionSchema.Enum;
782
703
  const makeswiftPreviewDataSchema = zod.z.object({
783
704
  makeswift: zod.z.literal(true),
784
- unstable_siteVersion: makeswiftSiteVersionSchema
705
+ siteVersion: makeswiftSiteVersionSchema
785
706
  });
786
707
  function getMakeswiftSiteVersion(previewData) {
787
708
  const result = makeswiftPreviewDataSchema.safeParse(previewData);
788
709
  if (result.success)
789
- return result.data.unstable_siteVersion;
710
+ return result.data.siteVersion;
790
711
  return null;
791
712
  }
792
713
  function PreviewModeScript({
@@ -884,7 +805,7 @@ class Makeswift {
884
805
  constructor(apiKey, {
885
806
  apiOrigin = "https://api.makeswift.com",
886
807
  runtime = ReactRuntime,
887
- unstable_previewData
808
+ siteVersion
888
809
  } = {}) {
889
810
  __publicField(this, "apiKey");
890
811
  __publicField(this, "apiOrigin");
@@ -903,7 +824,11 @@ Received "${apiKey}" instead.`);
903
824
  }
904
825
  this.graphqlClient = new GraphQLClient(new URL("graphql", apiOrigin).href);
905
826
  this.runtime = runtime;
906
- this.siteVersion = getMakeswiftSiteVersion(unstable_previewData);
827
+ this.siteVersion = siteVersion != null ? siteVersion : null;
828
+ }
829
+ static getSiteVersion(previewData) {
830
+ var _a;
831
+ return (_a = getMakeswiftSiteVersion(previewData)) != null ? _a : MakeswiftSiteVersion.Live;
907
832
  }
908
833
  async fetch(path, init) {
909
834
  var _a;
@@ -917,8 +842,7 @@ Received "${apiKey}" instead.`);
917
842
  return response;
918
843
  }
919
844
  async getPages() {
920
- const isUsingVersioning = this.siteVersion != null;
921
- const response = await this.fetch(`/${isUsingVersioning ? "v3" : "v2"}/pages`, {
845
+ const response = await this.fetch(`/${this.siteVersion == null ? "v2" : "v3"}/pages`, {
922
846
  headers: {
923
847
  "Makeswift-Site-Version": MakeswiftSiteVersion.Live
924
848
  }
@@ -930,14 +854,27 @@ Received "${apiKey}" instead.`);
930
854
  const json = await response.json();
931
855
  return json;
932
856
  }
933
- async getTypographies(typographyIds) {
934
- const result = await this.graphqlClient.request(TypographiesQuery, { typographyIds });
935
- return result.typographies;
857
+ async getTypographies(typographyIds, preview) {
858
+ var _a;
859
+ const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/typographies/bulk`, this.apiOrigin);
860
+ typographyIds.forEach((id) => {
861
+ url.searchParams.append("ids", id);
862
+ });
863
+ const response = await this.fetch(url.pathname + url.search, {
864
+ headers: {
865
+ "Makeswift-Site-Version": (_a = this.siteVersion) != null ? _a : preview ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live
866
+ }
867
+ });
868
+ if (!response.ok) {
869
+ console.error("Failed to get typographies", await response.json());
870
+ return [];
871
+ }
872
+ const body = await response.json();
873
+ return body;
936
874
  }
937
875
  async getSwatches(ids, preview) {
938
876
  var _a;
939
- const isUsingVersioning = this.siteVersion != null;
940
- const url = new URL(`${isUsingVersioning ? "v2" : "v1"}/swatches/bulk`, this.apiOrigin);
877
+ const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/swatches/bulk`, this.apiOrigin);
941
878
  ids.forEach((id) => {
942
879
  url.searchParams.append("ids", id);
943
880
  });
@@ -1020,7 +957,7 @@ Received "${apiKey}" instead.`);
1020
957
  continue;
1021
958
  getResourcesFromElementDescriptors(elementDescriptors, element2.props);
1022
959
  }
1023
- const typographies = await this.getTypographies([...typographyIds]);
960
+ const typographies = await this.getTypographies([...typographyIds], preview);
1024
961
  typographies.forEach((typography) => {
1025
962
  typography == null ? void 0 : typography.style.forEach((style) => {
1026
963
  var _a2;
@@ -1090,7 +1027,6 @@ Received "${apiKey}" instead.`);
1090
1027
  unstable_locale
1091
1028
  } = {}) {
1092
1029
  var _a, _b, _c;
1093
- const isUsingVersioning = this.siteVersion != null;
1094
1030
  const siteVersion = (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live;
1095
1031
  const defaultLocale = (_b = reactPage.getDefaultLocale(this.runtime.store.getState())) == null ? void 0 : _b.toString();
1096
1032
  const locale = unstable_locale === defaultLocale ? null : unstable_locale;
@@ -1102,7 +1038,7 @@ Received "${apiKey}" instead.`);
1102
1038
  }
1103
1039
  searchParams.set("locale", locale);
1104
1040
  }
1105
- const response = await this.fetch(`/${isUsingVersioning ? "v3" : "v2"}/pages/${encodeURIComponent(pathname)}/document?${searchParams.toString()}`, {
1041
+ const response = await this.fetch(`/${this.siteVersion == null ? "v2" : "v3"}/pages/${encodeURIComponent(pathname)}/document?${searchParams.toString()}`, {
1106
1042
  headers: { "Makeswift-Site-Version": siteVersion }
1107
1043
  });
1108
1044
  if (!response.ok) {
@@ -1126,8 +1062,7 @@ Received "${apiKey}" instead.`);
1126
1062
  };
1127
1063
  }
1128
1064
  async getSwatch(swatchId) {
1129
- const isUsingVersioning = this.siteVersion != null;
1130
- const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/swatches/${swatchId}`);
1065
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/swatches/${swatchId}`);
1131
1066
  if (!response.ok) {
1132
1067
  if (response.status !== 404)
1133
1068
  console.error("Failed to get swatch", await response.json());
@@ -1141,16 +1076,34 @@ Received "${apiKey}" instead.`);
1141
1076
  return result.file;
1142
1077
  }
1143
1078
  async getTypography(typographyId) {
1144
- const result = await this.graphqlClient.request(TypographyQuery, { typographyId });
1145
- return result.typography;
1079
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/typographies/${typographyId}`);
1080
+ if (!response.ok) {
1081
+ if (response.status !== 404)
1082
+ console.error("Failed to get typography", await response.json());
1083
+ return null;
1084
+ }
1085
+ const typography = await response.json();
1086
+ return typography;
1146
1087
  }
1147
1088
  async getGlobalElement(globalElementId) {
1148
- const result = await this.graphqlClient.request(GlobalElementQuery, { globalElementId });
1149
- return result.globalElement;
1089
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/global-elements/${globalElementId}`);
1090
+ if (!response.ok) {
1091
+ if (response.status !== 404)
1092
+ console.error("Failed to get global element", await response.json());
1093
+ return null;
1094
+ }
1095
+ const globalElement = await response.json();
1096
+ return globalElement;
1150
1097
  }
1151
1098
  async getLocalizedGlobalElement(globalElementId, locale) {
1152
- const result = await this.graphqlClient.request(LocalizedGlobalElementQuery, { globalElementId, locale });
1153
- return result.localizedGlobalElement;
1099
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/localized-global-elements/${globalElementId}?locale=${locale}`);
1100
+ if (!response.ok) {
1101
+ if (response.status !== 404)
1102
+ console.error("Failed to get localized global element", await response.json());
1103
+ return null;
1104
+ }
1105
+ const localizedGlobalElement = await response.json();
1106
+ return localizedGlobalElement;
1154
1107
  }
1155
1108
  async getPagePathnameSlice(pageId) {
1156
1109
  var _a;
@@ -1235,8 +1188,8 @@ async function fonts(_req, res, { getFonts } = {}) {
1235
1188
  const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
1236
1189
  return res.json(fonts2);
1237
1190
  }
1238
- const version = "0.10.9";
1239
- async function handler(req, res, { apiKey, unstable_siteVersions }) {
1191
+ const version = "0.10.11";
1192
+ async function handler(req, res, { apiKey, siteVersions }) {
1240
1193
  if (req.query.secret !== apiKey) {
1241
1194
  return res.status(401).json({ message: "Unauthorized" });
1242
1195
  }
@@ -1247,7 +1200,8 @@ async function handler(req, res, { apiKey, unstable_siteVersions }) {
1247
1200
  clientSideNavigation: true,
1248
1201
  elementFromPoint: false,
1249
1202
  customBreakpoints: true,
1250
- unstable_siteVersions,
1203
+ siteVersions,
1204
+ unstable_siteVersions: siteVersions,
1251
1205
  localizedPageSSR: true
1252
1206
  });
1253
1207
  }
@@ -1292,7 +1246,7 @@ async function proxyPreviewMode(req, res, { apiKey }) {
1292
1246
  const secure = process.env["NODE_ENV"] === "production";
1293
1247
  const previewData = {
1294
1248
  makeswift: true,
1295
- unstable_siteVersion: MakeswiftSiteVersion.Working
1249
+ siteVersion: MakeswiftSiteVersion.Working
1296
1250
  };
1297
1251
  const setCookie = res.setPreviewData(previewData).getHeader("Set-Cookie");
1298
1252
  res.removeHeader("Set-Cookie");
@@ -1337,7 +1291,7 @@ function MakeswiftApiHandler(apiKey, {
1337
1291
  appOrigin = "https://app.makeswift.com",
1338
1292
  apiOrigin = "https://api.makeswift.com",
1339
1293
  getFonts,
1340
- unstable_siteVersions = false
1294
+ siteVersions = false
1341
1295
  } = {}) {
1342
1296
  const cors = Cors__default["default"]({ origin: appOrigin });
1343
1297
  if (typeof apiKey !== "string") {
@@ -1359,12 +1313,15 @@ Received "${apiKey}" instead.`);
1359
1313
  Received "${makeswift}" for the \`makeswift\` param instead.
1360
1314
  Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes`);
1361
1315
  }
1362
- const client = new Makeswift(apiKey, { apiOrigin, unstable_previewData: req.previewData });
1316
+ const client = new Makeswift(apiKey, {
1317
+ apiOrigin,
1318
+ siteVersion: siteVersions ? Makeswift.getSiteVersion(req.previewData) : void 0
1319
+ });
1363
1320
  const action = "/" + makeswift.join("/");
1364
1321
  const matches = (pattern) => pathToRegexp.match(pattern, { decode: decodeURIComponent })(action);
1365
1322
  let m;
1366
1323
  if (matches("/manifest"))
1367
- return handler(req, res, { apiKey, unstable_siteVersions });
1324
+ return handler(req, res, { apiKey, siteVersions });
1368
1325
  if (matches("/revalidate"))
1369
1326
  return revalidate(req, res, { apiKey });
1370
1327
  if (matches("/proxy-preview-mode"))
@@ -1473,8 +1430,7 @@ async function getStaticProps(ctx) {
1473
1430
  var _a, _b, _c;
1474
1431
  deprecationWarning("getStaticProps");
1475
1432
  const makeswift = new Makeswift(getApiKey(), {
1476
- apiOrigin: getApiOrigin(),
1477
- unstable_previewData: ctx.previewData
1433
+ apiOrigin: getApiOrigin()
1478
1434
  });
1479
1435
  const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
1480
1436
  const snapshot = await makeswift.getPageSnapshot(path, {
@@ -1496,8 +1452,7 @@ async function getServerSideProps(ctx) {
1496
1452
  var _a, _b;
1497
1453
  deprecationWarning("getServerSideProps");
1498
1454
  const makeswift = new Makeswift(getApiKey(), {
1499
- apiOrigin: getApiOrigin(),
1500
- unstable_previewData: ctx.previewData
1455
+ apiOrigin: getApiOrigin()
1501
1456
  });
1502
1457
  const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
1503
1458
  const snapshot = await makeswift.getPageSnapshot(path, {