@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.es.js CHANGED
@@ -258,35 +258,6 @@ const FileFragment = `
258
258
  }
259
259
  }
260
260
  `;
261
- const TypographyFragment = `
262
- fragment Typography on Typography {
263
- __typename
264
- id
265
- name
266
- style {
267
- deviceId
268
- value {
269
- fontFamily
270
- fontSize {
271
- value
272
- unit
273
- }
274
- color {
275
- swatchId
276
- alpha
277
- }
278
- lineHeight
279
- letterSpacing
280
- fontWeight
281
- textAlign
282
- uppercase
283
- underline
284
- strikethrough
285
- italic
286
- }
287
- }
288
- }
289
- `;
290
261
  const PagePathnameSliceFragment = `
291
262
  fragment PagePathnameSlice on PagePathnameSlice {
292
263
  __typename
@@ -294,20 +265,6 @@ const PagePathnameSliceFragment = `
294
265
  pathname
295
266
  }
296
267
  `;
297
- const GlobalElementFragment = `
298
- fragment GlobalElement on GlobalElement {
299
- __typename
300
- id
301
- data
302
- }
303
- `;
304
- const LocalizedGlobalElementFragment = `
305
- fragment LocalizedGlobalElement on LocalizedGlobalElement {
306
- __typename
307
- id
308
- data
309
- }
310
- `;
311
268
  const TableFragment = `
312
269
  fragment Table on Table {
313
270
  __typename
@@ -362,15 +319,6 @@ const FileQuery = `
362
319
 
363
320
  ${FileFragment}
364
321
  `;
365
- const TypographyQuery = `
366
- query Typography($typographyId: ID!) {
367
- typography(id: $typographyId) {
368
- ...Typography
369
- }
370
- }
371
-
372
- ${TypographyFragment}
373
- `;
374
322
  const PagePathnamesByIdQuery = `
375
323
  query PagePathnamesById($pageIds: [ID!]!) {
376
324
  pagePathnamesById(ids: $pageIds) {
@@ -389,33 +337,6 @@ const TableQuery = `
389
337
 
390
338
  ${TableFragment}
391
339
  `;
392
- const TypographiesQuery = `
393
- query Typographies($typographyIds: [ID!]!) {
394
- typographies(ids: $typographyIds) {
395
- ...Typography
396
- }
397
- }
398
-
399
- ${TypographyFragment}
400
- `;
401
- const GlobalElementQuery = `
402
- query GlobalElement($globalElementId: ID!) {
403
- globalElement(id: $globalElementId) {
404
- ...GlobalElement
405
- }
406
- }
407
-
408
- ${GlobalElementFragment}
409
- `;
410
- const LocalizedGlobalElementQuery = `
411
- query LocalizedGlobalElement($globalElementId: ID!, $locale: Locale!) {
412
- localizedGlobalElement(globalElementId: $globalElementId, locale: $locale) {
413
- ...LocalizedGlobalElement
414
- }
415
- }
416
-
417
- ${LocalizedGlobalElementFragment}
418
- `;
419
340
  const CreateTableRecordMutation = `
420
341
  mutation CreateTableRecord($input: CreateTableRecordInput!) {
421
342
  createTableRecord(input: $input) {
@@ -748,12 +669,12 @@ const makeswiftSiteVersionSchema = z.enum(["Live", "Working"]);
748
669
  const MakeswiftSiteVersion = makeswiftSiteVersionSchema.Enum;
749
670
  const makeswiftPreviewDataSchema = z.object({
750
671
  makeswift: z.literal(true),
751
- unstable_siteVersion: makeswiftSiteVersionSchema
672
+ siteVersion: makeswiftSiteVersionSchema
752
673
  });
753
674
  function getMakeswiftSiteVersion(previewData) {
754
675
  const result = makeswiftPreviewDataSchema.safeParse(previewData);
755
676
  if (result.success)
756
- return result.data.unstable_siteVersion;
677
+ return result.data.siteVersion;
757
678
  return null;
758
679
  }
759
680
  function PreviewModeScript({
@@ -851,7 +772,7 @@ class Makeswift {
851
772
  constructor(apiKey, {
852
773
  apiOrigin = "https://api.makeswift.com",
853
774
  runtime = ReactRuntime,
854
- unstable_previewData
775
+ siteVersion
855
776
  } = {}) {
856
777
  __publicField(this, "apiKey");
857
778
  __publicField(this, "apiOrigin");
@@ -870,7 +791,11 @@ Received "${apiKey}" instead.`);
870
791
  }
871
792
  this.graphqlClient = new GraphQLClient(new URL("graphql", apiOrigin).href);
872
793
  this.runtime = runtime;
873
- this.siteVersion = getMakeswiftSiteVersion(unstable_previewData);
794
+ this.siteVersion = siteVersion != null ? siteVersion : null;
795
+ }
796
+ static getSiteVersion(previewData) {
797
+ var _a;
798
+ return (_a = getMakeswiftSiteVersion(previewData)) != null ? _a : MakeswiftSiteVersion.Live;
874
799
  }
875
800
  async fetch(path, init) {
876
801
  var _a;
@@ -884,8 +809,7 @@ Received "${apiKey}" instead.`);
884
809
  return response;
885
810
  }
886
811
  async getPages() {
887
- const isUsingVersioning = this.siteVersion != null;
888
- const response = await this.fetch(`/${isUsingVersioning ? "v3" : "v2"}/pages`, {
812
+ const response = await this.fetch(`/${this.siteVersion == null ? "v2" : "v3"}/pages`, {
889
813
  headers: {
890
814
  "Makeswift-Site-Version": MakeswiftSiteVersion.Live
891
815
  }
@@ -897,14 +821,27 @@ Received "${apiKey}" instead.`);
897
821
  const json = await response.json();
898
822
  return json;
899
823
  }
900
- async getTypographies(typographyIds) {
901
- const result = await this.graphqlClient.request(TypographiesQuery, { typographyIds });
902
- return result.typographies;
824
+ async getTypographies(typographyIds, preview) {
825
+ var _a;
826
+ const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/typographies/bulk`, this.apiOrigin);
827
+ typographyIds.forEach((id) => {
828
+ url.searchParams.append("ids", id);
829
+ });
830
+ const response = await this.fetch(url.pathname + url.search, {
831
+ headers: {
832
+ "Makeswift-Site-Version": (_a = this.siteVersion) != null ? _a : preview ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live
833
+ }
834
+ });
835
+ if (!response.ok) {
836
+ console.error("Failed to get typographies", await response.json());
837
+ return [];
838
+ }
839
+ const body = await response.json();
840
+ return body;
903
841
  }
904
842
  async getSwatches(ids, preview) {
905
843
  var _a;
906
- const isUsingVersioning = this.siteVersion != null;
907
- const url = new URL(`${isUsingVersioning ? "v2" : "v1"}/swatches/bulk`, this.apiOrigin);
844
+ const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/swatches/bulk`, this.apiOrigin);
908
845
  ids.forEach((id) => {
909
846
  url.searchParams.append("ids", id);
910
847
  });
@@ -987,7 +924,7 @@ Received "${apiKey}" instead.`);
987
924
  continue;
988
925
  getResourcesFromElementDescriptors(elementDescriptors, element2.props);
989
926
  }
990
- const typographies = await this.getTypographies([...typographyIds]);
927
+ const typographies = await this.getTypographies([...typographyIds], preview);
991
928
  typographies.forEach((typography) => {
992
929
  typography == null ? void 0 : typography.style.forEach((style) => {
993
930
  var _a2;
@@ -1057,7 +994,6 @@ Received "${apiKey}" instead.`);
1057
994
  unstable_locale
1058
995
  } = {}) {
1059
996
  var _a, _b, _c;
1060
- const isUsingVersioning = this.siteVersion != null;
1061
997
  const siteVersion = (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live;
1062
998
  const defaultLocale = (_b = getDefaultLocale(this.runtime.store.getState())) == null ? void 0 : _b.toString();
1063
999
  const locale = unstable_locale === defaultLocale ? null : unstable_locale;
@@ -1069,7 +1005,7 @@ Received "${apiKey}" instead.`);
1069
1005
  }
1070
1006
  searchParams.set("locale", locale);
1071
1007
  }
1072
- const response = await this.fetch(`/${isUsingVersioning ? "v3" : "v2"}/pages/${encodeURIComponent(pathname)}/document?${searchParams.toString()}`, {
1008
+ const response = await this.fetch(`/${this.siteVersion == null ? "v2" : "v3"}/pages/${encodeURIComponent(pathname)}/document?${searchParams.toString()}`, {
1073
1009
  headers: { "Makeswift-Site-Version": siteVersion }
1074
1010
  });
1075
1011
  if (!response.ok) {
@@ -1093,8 +1029,7 @@ Received "${apiKey}" instead.`);
1093
1029
  };
1094
1030
  }
1095
1031
  async getSwatch(swatchId) {
1096
- const isUsingVersioning = this.siteVersion != null;
1097
- const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/swatches/${swatchId}`);
1032
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/swatches/${swatchId}`);
1098
1033
  if (!response.ok) {
1099
1034
  if (response.status !== 404)
1100
1035
  console.error("Failed to get swatch", await response.json());
@@ -1108,16 +1043,34 @@ Received "${apiKey}" instead.`);
1108
1043
  return result.file;
1109
1044
  }
1110
1045
  async getTypography(typographyId) {
1111
- const result = await this.graphqlClient.request(TypographyQuery, { typographyId });
1112
- return result.typography;
1046
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/typographies/${typographyId}`);
1047
+ if (!response.ok) {
1048
+ if (response.status !== 404)
1049
+ console.error("Failed to get typography", await response.json());
1050
+ return null;
1051
+ }
1052
+ const typography = await response.json();
1053
+ return typography;
1113
1054
  }
1114
1055
  async getGlobalElement(globalElementId) {
1115
- const result = await this.graphqlClient.request(GlobalElementQuery, { globalElementId });
1116
- return result.globalElement;
1056
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/global-elements/${globalElementId}`);
1057
+ if (!response.ok) {
1058
+ if (response.status !== 404)
1059
+ console.error("Failed to get global element", await response.json());
1060
+ return null;
1061
+ }
1062
+ const globalElement = await response.json();
1063
+ return globalElement;
1117
1064
  }
1118
1065
  async getLocalizedGlobalElement(globalElementId, locale) {
1119
- const result = await this.graphqlClient.request(LocalizedGlobalElementQuery, { globalElementId, locale });
1120
- return result.localizedGlobalElement;
1066
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/localized-global-elements/${globalElementId}?locale=${locale}`);
1067
+ if (!response.ok) {
1068
+ if (response.status !== 404)
1069
+ console.error("Failed to get localized global element", await response.json());
1070
+ return null;
1071
+ }
1072
+ const localizedGlobalElement = await response.json();
1073
+ return localizedGlobalElement;
1121
1074
  }
1122
1075
  async getPagePathnameSlice(pageId) {
1123
1076
  var _a;
@@ -1202,8 +1155,8 @@ async function fonts(_req, res, { getFonts } = {}) {
1202
1155
  const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
1203
1156
  return res.json(fonts2);
1204
1157
  }
1205
- const version = "0.10.9";
1206
- async function handler(req, res, { apiKey, unstable_siteVersions }) {
1158
+ const version = "0.10.11";
1159
+ async function handler(req, res, { apiKey, siteVersions }) {
1207
1160
  if (req.query.secret !== apiKey) {
1208
1161
  return res.status(401).json({ message: "Unauthorized" });
1209
1162
  }
@@ -1214,7 +1167,8 @@ async function handler(req, res, { apiKey, unstable_siteVersions }) {
1214
1167
  clientSideNavigation: true,
1215
1168
  elementFromPoint: false,
1216
1169
  customBreakpoints: true,
1217
- unstable_siteVersions,
1170
+ siteVersions,
1171
+ unstable_siteVersions: siteVersions,
1218
1172
  localizedPageSSR: true
1219
1173
  });
1220
1174
  }
@@ -1259,7 +1213,7 @@ async function proxyPreviewMode(req, res, { apiKey }) {
1259
1213
  const secure = process.env["NODE_ENV"] === "production";
1260
1214
  const previewData = {
1261
1215
  makeswift: true,
1262
- unstable_siteVersion: MakeswiftSiteVersion.Working
1216
+ siteVersion: MakeswiftSiteVersion.Working
1263
1217
  };
1264
1218
  const setCookie = res.setPreviewData(previewData).getHeader("Set-Cookie");
1265
1219
  res.removeHeader("Set-Cookie");
@@ -1304,7 +1258,7 @@ function MakeswiftApiHandler(apiKey, {
1304
1258
  appOrigin = "https://app.makeswift.com",
1305
1259
  apiOrigin = "https://api.makeswift.com",
1306
1260
  getFonts,
1307
- unstable_siteVersions = false
1261
+ siteVersions = false
1308
1262
  } = {}) {
1309
1263
  const cors = Cors({ origin: appOrigin });
1310
1264
  if (typeof apiKey !== "string") {
@@ -1326,12 +1280,15 @@ Received "${apiKey}" instead.`);
1326
1280
  Received "${makeswift}" for the \`makeswift\` param instead.
1327
1281
  Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes`);
1328
1282
  }
1329
- const client = new Makeswift(apiKey, { apiOrigin, unstable_previewData: req.previewData });
1283
+ const client = new Makeswift(apiKey, {
1284
+ apiOrigin,
1285
+ siteVersion: siteVersions ? Makeswift.getSiteVersion(req.previewData) : void 0
1286
+ });
1330
1287
  const action = "/" + makeswift.join("/");
1331
1288
  const matches = (pattern) => match(pattern, { decode: decodeURIComponent })(action);
1332
1289
  let m;
1333
1290
  if (matches("/manifest"))
1334
- return handler(req, res, { apiKey, unstable_siteVersions });
1291
+ return handler(req, res, { apiKey, siteVersions });
1335
1292
  if (matches("/revalidate"))
1336
1293
  return revalidate(req, res, { apiKey });
1337
1294
  if (matches("/proxy-preview-mode"))
@@ -1440,8 +1397,7 @@ async function getStaticProps(ctx) {
1440
1397
  var _a, _b, _c;
1441
1398
  deprecationWarning("getStaticProps");
1442
1399
  const makeswift = new Makeswift(getApiKey(), {
1443
- apiOrigin: getApiOrigin(),
1444
- unstable_previewData: ctx.previewData
1400
+ apiOrigin: getApiOrigin()
1445
1401
  });
1446
1402
  const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
1447
1403
  const snapshot = await makeswift.getPageSnapshot(path, {
@@ -1463,8 +1419,7 @@ async function getServerSideProps(ctx) {
1463
1419
  var _a, _b;
1464
1420
  deprecationWarning("getServerSideProps");
1465
1421
  const makeswift = new Makeswift(getApiKey(), {
1466
- apiOrigin: getApiOrigin(),
1467
- unstable_previewData: ctx.previewData
1422
+ apiOrigin: getApiOrigin()
1468
1423
  });
1469
1424
  const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
1470
1425
  const snapshot = await makeswift.getPageSnapshot(path, {