@makeswift/runtime 0.10.10 → 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
@@ -669,12 +669,12 @@ const makeswiftSiteVersionSchema = z.enum(["Live", "Working"]);
669
669
  const MakeswiftSiteVersion = makeswiftSiteVersionSchema.Enum;
670
670
  const makeswiftPreviewDataSchema = z.object({
671
671
  makeswift: z.literal(true),
672
- unstable_siteVersion: makeswiftSiteVersionSchema
672
+ siteVersion: makeswiftSiteVersionSchema
673
673
  });
674
674
  function getMakeswiftSiteVersion(previewData) {
675
675
  const result = makeswiftPreviewDataSchema.safeParse(previewData);
676
676
  if (result.success)
677
- return result.data.unstable_siteVersion;
677
+ return result.data.siteVersion;
678
678
  return null;
679
679
  }
680
680
  function PreviewModeScript({
@@ -772,7 +772,7 @@ class Makeswift {
772
772
  constructor(apiKey, {
773
773
  apiOrigin = "https://api.makeswift.com",
774
774
  runtime = ReactRuntime,
775
- unstable_previewData
775
+ siteVersion
776
776
  } = {}) {
777
777
  __publicField(this, "apiKey");
778
778
  __publicField(this, "apiOrigin");
@@ -791,7 +791,11 @@ Received "${apiKey}" instead.`);
791
791
  }
792
792
  this.graphqlClient = new GraphQLClient(new URL("graphql", apiOrigin).href);
793
793
  this.runtime = runtime;
794
- 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;
795
799
  }
796
800
  async fetch(path, init) {
797
801
  var _a;
@@ -805,8 +809,7 @@ Received "${apiKey}" instead.`);
805
809
  return response;
806
810
  }
807
811
  async getPages() {
808
- const isUsingVersioning = this.siteVersion != null;
809
- const response = await this.fetch(`/${isUsingVersioning ? "v3" : "v2"}/pages`, {
812
+ const response = await this.fetch(`/${this.siteVersion == null ? "v2" : "v3"}/pages`, {
810
813
  headers: {
811
814
  "Makeswift-Site-Version": MakeswiftSiteVersion.Live
812
815
  }
@@ -820,8 +823,7 @@ Received "${apiKey}" instead.`);
820
823
  }
821
824
  async getTypographies(typographyIds, preview) {
822
825
  var _a;
823
- const isUsingVersioning = this.siteVersion != null;
824
- const url = new URL(`${isUsingVersioning ? "v2" : "v1"}/typographies/bulk`, this.apiOrigin);
826
+ const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/typographies/bulk`, this.apiOrigin);
825
827
  typographyIds.forEach((id) => {
826
828
  url.searchParams.append("ids", id);
827
829
  });
@@ -839,8 +841,7 @@ Received "${apiKey}" instead.`);
839
841
  }
840
842
  async getSwatches(ids, preview) {
841
843
  var _a;
842
- const isUsingVersioning = this.siteVersion != null;
843
- 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);
844
845
  ids.forEach((id) => {
845
846
  url.searchParams.append("ids", id);
846
847
  });
@@ -993,7 +994,6 @@ Received "${apiKey}" instead.`);
993
994
  unstable_locale
994
995
  } = {}) {
995
996
  var _a, _b, _c;
996
- const isUsingVersioning = this.siteVersion != null;
997
997
  const siteVersion = (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live;
998
998
  const defaultLocale = (_b = getDefaultLocale(this.runtime.store.getState())) == null ? void 0 : _b.toString();
999
999
  const locale = unstable_locale === defaultLocale ? null : unstable_locale;
@@ -1005,7 +1005,7 @@ Received "${apiKey}" instead.`);
1005
1005
  }
1006
1006
  searchParams.set("locale", locale);
1007
1007
  }
1008
- 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()}`, {
1009
1009
  headers: { "Makeswift-Site-Version": siteVersion }
1010
1010
  });
1011
1011
  if (!response.ok) {
@@ -1029,8 +1029,7 @@ Received "${apiKey}" instead.`);
1029
1029
  };
1030
1030
  }
1031
1031
  async getSwatch(swatchId) {
1032
- const isUsingVersioning = this.siteVersion != null;
1033
- const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/swatches/${swatchId}`);
1032
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/swatches/${swatchId}`);
1034
1033
  if (!response.ok) {
1035
1034
  if (response.status !== 404)
1036
1035
  console.error("Failed to get swatch", await response.json());
@@ -1044,8 +1043,7 @@ Received "${apiKey}" instead.`);
1044
1043
  return result.file;
1045
1044
  }
1046
1045
  async getTypography(typographyId) {
1047
- const isUsingVersioning = this.siteVersion != null;
1048
- const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/typographies/${typographyId}`);
1046
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/typographies/${typographyId}`);
1049
1047
  if (!response.ok) {
1050
1048
  if (response.status !== 404)
1051
1049
  console.error("Failed to get typography", await response.json());
@@ -1055,8 +1053,7 @@ Received "${apiKey}" instead.`);
1055
1053
  return typography;
1056
1054
  }
1057
1055
  async getGlobalElement(globalElementId) {
1058
- const isUsingVersioning = this.siteVersion != null;
1059
- const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/global-elements/${globalElementId}`);
1056
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/global-elements/${globalElementId}`);
1060
1057
  if (!response.ok) {
1061
1058
  if (response.status !== 404)
1062
1059
  console.error("Failed to get global element", await response.json());
@@ -1066,8 +1063,7 @@ Received "${apiKey}" instead.`);
1066
1063
  return globalElement;
1067
1064
  }
1068
1065
  async getLocalizedGlobalElement(globalElementId, locale) {
1069
- const isUsingVersioning = this.siteVersion != null;
1070
- const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/localized-global-elements/${globalElementId}?locale=${locale}`);
1066
+ const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/localized-global-elements/${globalElementId}?locale=${locale}`);
1071
1067
  if (!response.ok) {
1072
1068
  if (response.status !== 404)
1073
1069
  console.error("Failed to get localized global element", await response.json());
@@ -1159,8 +1155,8 @@ async function fonts(_req, res, { getFonts } = {}) {
1159
1155
  const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
1160
1156
  return res.json(fonts2);
1161
1157
  }
1162
- const version = "0.10.10";
1163
- async function handler(req, res, { apiKey, unstable_siteVersions }) {
1158
+ const version = "0.10.11";
1159
+ async function handler(req, res, { apiKey, siteVersions }) {
1164
1160
  if (req.query.secret !== apiKey) {
1165
1161
  return res.status(401).json({ message: "Unauthorized" });
1166
1162
  }
@@ -1171,7 +1167,8 @@ async function handler(req, res, { apiKey, unstable_siteVersions }) {
1171
1167
  clientSideNavigation: true,
1172
1168
  elementFromPoint: false,
1173
1169
  customBreakpoints: true,
1174
- unstable_siteVersions,
1170
+ siteVersions,
1171
+ unstable_siteVersions: siteVersions,
1175
1172
  localizedPageSSR: true
1176
1173
  });
1177
1174
  }
@@ -1216,7 +1213,7 @@ async function proxyPreviewMode(req, res, { apiKey }) {
1216
1213
  const secure = process.env["NODE_ENV"] === "production";
1217
1214
  const previewData = {
1218
1215
  makeswift: true,
1219
- unstable_siteVersion: MakeswiftSiteVersion.Working
1216
+ siteVersion: MakeswiftSiteVersion.Working
1220
1217
  };
1221
1218
  const setCookie = res.setPreviewData(previewData).getHeader("Set-Cookie");
1222
1219
  res.removeHeader("Set-Cookie");
@@ -1261,7 +1258,7 @@ function MakeswiftApiHandler(apiKey, {
1261
1258
  appOrigin = "https://app.makeswift.com",
1262
1259
  apiOrigin = "https://api.makeswift.com",
1263
1260
  getFonts,
1264
- unstable_siteVersions = false
1261
+ siteVersions = false
1265
1262
  } = {}) {
1266
1263
  const cors = Cors({ origin: appOrigin });
1267
1264
  if (typeof apiKey !== "string") {
@@ -1283,12 +1280,15 @@ Received "${apiKey}" instead.`);
1283
1280
  Received "${makeswift}" for the \`makeswift\` param instead.
1284
1281
  Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes`);
1285
1282
  }
1286
- 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
+ });
1287
1287
  const action = "/" + makeswift.join("/");
1288
1288
  const matches = (pattern) => match(pattern, { decode: decodeURIComponent })(action);
1289
1289
  let m;
1290
1290
  if (matches("/manifest"))
1291
- return handler(req, res, { apiKey, unstable_siteVersions });
1291
+ return handler(req, res, { apiKey, siteVersions });
1292
1292
  if (matches("/revalidate"))
1293
1293
  return revalidate(req, res, { apiKey });
1294
1294
  if (matches("/proxy-preview-mode"))
@@ -1397,8 +1397,7 @@ async function getStaticProps(ctx) {
1397
1397
  var _a, _b, _c;
1398
1398
  deprecationWarning("getStaticProps");
1399
1399
  const makeswift = new Makeswift(getApiKey(), {
1400
- apiOrigin: getApiOrigin(),
1401
- unstable_previewData: ctx.previewData
1400
+ apiOrigin: getApiOrigin()
1402
1401
  });
1403
1402
  const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
1404
1403
  const snapshot = await makeswift.getPageSnapshot(path, {
@@ -1420,8 +1419,7 @@ async function getServerSideProps(ctx) {
1420
1419
  var _a, _b;
1421
1420
  deprecationWarning("getServerSideProps");
1422
1421
  const makeswift = new Makeswift(getApiKey(), {
1423
- apiOrigin: getApiOrigin(),
1424
- unstable_previewData: ctx.previewData
1422
+ apiOrigin: getApiOrigin()
1425
1423
  });
1426
1424
  const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
1427
1425
  const snapshot = await makeswift.getPageSnapshot(path, {