@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.cjs.js +29 -31
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +29 -31
- package/dist/index.es.js.map +1 -1
- package/dist/types/src/next/api-handler/handlers/manifest.d.ts +3 -2
- package/dist/types/src/next/api-handler/handlers/manifest.d.ts.map +1 -1
- package/dist/types/src/next/api-handler/index.d.ts +2 -2
- package/dist/types/src/next/api-handler/index.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +4 -2
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/types/src/next/preview-mode.d.ts +3 -3
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -702,12 +702,12 @@ const makeswiftSiteVersionSchema = zod.z.enum(["Live", "Working"]);
|
|
|
702
702
|
const MakeswiftSiteVersion = makeswiftSiteVersionSchema.Enum;
|
|
703
703
|
const makeswiftPreviewDataSchema = zod.z.object({
|
|
704
704
|
makeswift: zod.z.literal(true),
|
|
705
|
-
|
|
705
|
+
siteVersion: makeswiftSiteVersionSchema
|
|
706
706
|
});
|
|
707
707
|
function getMakeswiftSiteVersion(previewData) {
|
|
708
708
|
const result = makeswiftPreviewDataSchema.safeParse(previewData);
|
|
709
709
|
if (result.success)
|
|
710
|
-
return result.data.
|
|
710
|
+
return result.data.siteVersion;
|
|
711
711
|
return null;
|
|
712
712
|
}
|
|
713
713
|
function PreviewModeScript({
|
|
@@ -805,7 +805,7 @@ class Makeswift {
|
|
|
805
805
|
constructor(apiKey, {
|
|
806
806
|
apiOrigin = "https://api.makeswift.com",
|
|
807
807
|
runtime = ReactRuntime,
|
|
808
|
-
|
|
808
|
+
siteVersion
|
|
809
809
|
} = {}) {
|
|
810
810
|
__publicField(this, "apiKey");
|
|
811
811
|
__publicField(this, "apiOrigin");
|
|
@@ -824,7 +824,11 @@ Received "${apiKey}" instead.`);
|
|
|
824
824
|
}
|
|
825
825
|
this.graphqlClient = new GraphQLClient(new URL("graphql", apiOrigin).href);
|
|
826
826
|
this.runtime = runtime;
|
|
827
|
-
this.siteVersion =
|
|
827
|
+
this.siteVersion = siteVersion != null ? siteVersion : null;
|
|
828
|
+
}
|
|
829
|
+
static getSiteVersion(previewData) {
|
|
830
|
+
var _a;
|
|
831
|
+
return (_a = getMakeswiftSiteVersion(previewData)) != null ? _a : MakeswiftSiteVersion.Live;
|
|
828
832
|
}
|
|
829
833
|
async fetch(path, init) {
|
|
830
834
|
var _a;
|
|
@@ -838,8 +842,7 @@ Received "${apiKey}" instead.`);
|
|
|
838
842
|
return response;
|
|
839
843
|
}
|
|
840
844
|
async getPages() {
|
|
841
|
-
const
|
|
842
|
-
const response = await this.fetch(`/${isUsingVersioning ? "v3" : "v2"}/pages`, {
|
|
845
|
+
const response = await this.fetch(`/${this.siteVersion == null ? "v2" : "v3"}/pages`, {
|
|
843
846
|
headers: {
|
|
844
847
|
"Makeswift-Site-Version": MakeswiftSiteVersion.Live
|
|
845
848
|
}
|
|
@@ -853,8 +856,7 @@ Received "${apiKey}" instead.`);
|
|
|
853
856
|
}
|
|
854
857
|
async getTypographies(typographyIds, preview) {
|
|
855
858
|
var _a;
|
|
856
|
-
const
|
|
857
|
-
const url = new URL(`${isUsingVersioning ? "v2" : "v1"}/typographies/bulk`, this.apiOrigin);
|
|
859
|
+
const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/typographies/bulk`, this.apiOrigin);
|
|
858
860
|
typographyIds.forEach((id) => {
|
|
859
861
|
url.searchParams.append("ids", id);
|
|
860
862
|
});
|
|
@@ -872,8 +874,7 @@ Received "${apiKey}" instead.`);
|
|
|
872
874
|
}
|
|
873
875
|
async getSwatches(ids, preview) {
|
|
874
876
|
var _a;
|
|
875
|
-
const
|
|
876
|
-
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);
|
|
877
878
|
ids.forEach((id) => {
|
|
878
879
|
url.searchParams.append("ids", id);
|
|
879
880
|
});
|
|
@@ -1026,7 +1027,6 @@ Received "${apiKey}" instead.`);
|
|
|
1026
1027
|
unstable_locale
|
|
1027
1028
|
} = {}) {
|
|
1028
1029
|
var _a, _b, _c;
|
|
1029
|
-
const isUsingVersioning = this.siteVersion != null;
|
|
1030
1030
|
const siteVersion = (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live;
|
|
1031
1031
|
const defaultLocale = (_b = reactPage.getDefaultLocale(this.runtime.store.getState())) == null ? void 0 : _b.toString();
|
|
1032
1032
|
const locale = unstable_locale === defaultLocale ? null : unstable_locale;
|
|
@@ -1038,7 +1038,7 @@ Received "${apiKey}" instead.`);
|
|
|
1038
1038
|
}
|
|
1039
1039
|
searchParams.set("locale", locale);
|
|
1040
1040
|
}
|
|
1041
|
-
const response = await this.fetch(`/${
|
|
1041
|
+
const response = await this.fetch(`/${this.siteVersion == null ? "v2" : "v3"}/pages/${encodeURIComponent(pathname)}/document?${searchParams.toString()}`, {
|
|
1042
1042
|
headers: { "Makeswift-Site-Version": siteVersion }
|
|
1043
1043
|
});
|
|
1044
1044
|
if (!response.ok) {
|
|
@@ -1062,8 +1062,7 @@ Received "${apiKey}" instead.`);
|
|
|
1062
1062
|
};
|
|
1063
1063
|
}
|
|
1064
1064
|
async getSwatch(swatchId) {
|
|
1065
|
-
const
|
|
1066
|
-
const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/swatches/${swatchId}`);
|
|
1065
|
+
const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/swatches/${swatchId}`);
|
|
1067
1066
|
if (!response.ok) {
|
|
1068
1067
|
if (response.status !== 404)
|
|
1069
1068
|
console.error("Failed to get swatch", await response.json());
|
|
@@ -1077,8 +1076,7 @@ Received "${apiKey}" instead.`);
|
|
|
1077
1076
|
return result.file;
|
|
1078
1077
|
}
|
|
1079
1078
|
async getTypography(typographyId) {
|
|
1080
|
-
const
|
|
1081
|
-
const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/typographies/${typographyId}`);
|
|
1079
|
+
const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/typographies/${typographyId}`);
|
|
1082
1080
|
if (!response.ok) {
|
|
1083
1081
|
if (response.status !== 404)
|
|
1084
1082
|
console.error("Failed to get typography", await response.json());
|
|
@@ -1088,8 +1086,7 @@ Received "${apiKey}" instead.`);
|
|
|
1088
1086
|
return typography;
|
|
1089
1087
|
}
|
|
1090
1088
|
async getGlobalElement(globalElementId) {
|
|
1091
|
-
const
|
|
1092
|
-
const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/global-elements/${globalElementId}`);
|
|
1089
|
+
const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/global-elements/${globalElementId}`);
|
|
1093
1090
|
if (!response.ok) {
|
|
1094
1091
|
if (response.status !== 404)
|
|
1095
1092
|
console.error("Failed to get global element", await response.json());
|
|
@@ -1099,8 +1096,7 @@ Received "${apiKey}" instead.`);
|
|
|
1099
1096
|
return globalElement;
|
|
1100
1097
|
}
|
|
1101
1098
|
async getLocalizedGlobalElement(globalElementId, locale) {
|
|
1102
|
-
const
|
|
1103
|
-
const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/localized-global-elements/${globalElementId}?locale=${locale}`);
|
|
1099
|
+
const response = await this.fetch(`${this.siteVersion == null ? "v1" : "v2"}/localized-global-elements/${globalElementId}?locale=${locale}`);
|
|
1104
1100
|
if (!response.ok) {
|
|
1105
1101
|
if (response.status !== 404)
|
|
1106
1102
|
console.error("Failed to get localized global element", await response.json());
|
|
@@ -1192,8 +1188,8 @@ async function fonts(_req, res, { getFonts } = {}) {
|
|
|
1192
1188
|
const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
|
|
1193
1189
|
return res.json(fonts2);
|
|
1194
1190
|
}
|
|
1195
|
-
const version = "0.10.
|
|
1196
|
-
async function handler(req, res, { apiKey,
|
|
1191
|
+
const version = "0.10.11";
|
|
1192
|
+
async function handler(req, res, { apiKey, siteVersions }) {
|
|
1197
1193
|
if (req.query.secret !== apiKey) {
|
|
1198
1194
|
return res.status(401).json({ message: "Unauthorized" });
|
|
1199
1195
|
}
|
|
@@ -1204,7 +1200,8 @@ async function handler(req, res, { apiKey, unstable_siteVersions }) {
|
|
|
1204
1200
|
clientSideNavigation: true,
|
|
1205
1201
|
elementFromPoint: false,
|
|
1206
1202
|
customBreakpoints: true,
|
|
1207
|
-
|
|
1203
|
+
siteVersions,
|
|
1204
|
+
unstable_siteVersions: siteVersions,
|
|
1208
1205
|
localizedPageSSR: true
|
|
1209
1206
|
});
|
|
1210
1207
|
}
|
|
@@ -1249,7 +1246,7 @@ async function proxyPreviewMode(req, res, { apiKey }) {
|
|
|
1249
1246
|
const secure = process.env["NODE_ENV"] === "production";
|
|
1250
1247
|
const previewData = {
|
|
1251
1248
|
makeswift: true,
|
|
1252
|
-
|
|
1249
|
+
siteVersion: MakeswiftSiteVersion.Working
|
|
1253
1250
|
};
|
|
1254
1251
|
const setCookie = res.setPreviewData(previewData).getHeader("Set-Cookie");
|
|
1255
1252
|
res.removeHeader("Set-Cookie");
|
|
@@ -1294,7 +1291,7 @@ function MakeswiftApiHandler(apiKey, {
|
|
|
1294
1291
|
appOrigin = "https://app.makeswift.com",
|
|
1295
1292
|
apiOrigin = "https://api.makeswift.com",
|
|
1296
1293
|
getFonts,
|
|
1297
|
-
|
|
1294
|
+
siteVersions = false
|
|
1298
1295
|
} = {}) {
|
|
1299
1296
|
const cors = Cors__default["default"]({ origin: appOrigin });
|
|
1300
1297
|
if (typeof apiKey !== "string") {
|
|
@@ -1316,12 +1313,15 @@ Received "${apiKey}" instead.`);
|
|
|
1316
1313
|
Received "${makeswift}" for the \`makeswift\` param instead.
|
|
1317
1314
|
Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes`);
|
|
1318
1315
|
}
|
|
1319
|
-
const client = new Makeswift(apiKey, {
|
|
1316
|
+
const client = new Makeswift(apiKey, {
|
|
1317
|
+
apiOrigin,
|
|
1318
|
+
siteVersion: siteVersions ? Makeswift.getSiteVersion(req.previewData) : void 0
|
|
1319
|
+
});
|
|
1320
1320
|
const action = "/" + makeswift.join("/");
|
|
1321
1321
|
const matches = (pattern) => pathToRegexp.match(pattern, { decode: decodeURIComponent })(action);
|
|
1322
1322
|
let m;
|
|
1323
1323
|
if (matches("/manifest"))
|
|
1324
|
-
return handler(req, res, { apiKey,
|
|
1324
|
+
return handler(req, res, { apiKey, siteVersions });
|
|
1325
1325
|
if (matches("/revalidate"))
|
|
1326
1326
|
return revalidate(req, res, { apiKey });
|
|
1327
1327
|
if (matches("/proxy-preview-mode"))
|
|
@@ -1430,8 +1430,7 @@ async function getStaticProps(ctx) {
|
|
|
1430
1430
|
var _a, _b, _c;
|
|
1431
1431
|
deprecationWarning("getStaticProps");
|
|
1432
1432
|
const makeswift = new Makeswift(getApiKey(), {
|
|
1433
|
-
apiOrigin: getApiOrigin()
|
|
1434
|
-
unstable_previewData: ctx.previewData
|
|
1433
|
+
apiOrigin: getApiOrigin()
|
|
1435
1434
|
});
|
|
1436
1435
|
const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
|
|
1437
1436
|
const snapshot = await makeswift.getPageSnapshot(path, {
|
|
@@ -1453,8 +1452,7 @@ async function getServerSideProps(ctx) {
|
|
|
1453
1452
|
var _a, _b;
|
|
1454
1453
|
deprecationWarning("getServerSideProps");
|
|
1455
1454
|
const makeswift = new Makeswift(getApiKey(), {
|
|
1456
|
-
apiOrigin: getApiOrigin()
|
|
1457
|
-
unstable_previewData: ctx.previewData
|
|
1455
|
+
apiOrigin: getApiOrigin()
|
|
1458
1456
|
});
|
|
1459
1457
|
const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
|
|
1460
1458
|
const snapshot = await makeswift.getPageSnapshot(path, {
|