@makeswift/runtime 0.23.7 → 0.23.8-canary.1
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/cjs/api/react.js +28 -7
- package/dist/cjs/api/react.js.map +1 -1
- package/dist/cjs/api/site-version.js +36 -0
- package/dist/cjs/api/site-version.js.map +1 -0
- package/dist/cjs/next/api-handler/handlers/draft-mode.js +78 -0
- package/dist/cjs/next/api-handler/handlers/draft-mode.js.map +1 -0
- package/dist/cjs/next/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/next/api-handler/handlers/preview-mode.js +71 -0
- package/dist/cjs/next/api-handler/handlers/preview-mode.js.map +1 -0
- package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js +2 -2
- package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js +2 -2
- package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js.map +1 -1
- package/dist/cjs/next/api-handler/index.js +20 -2
- package/dist/cjs/next/api-handler/index.js.map +1 -1
- package/dist/cjs/next/client.js +7 -6
- package/dist/cjs/next/client.js.map +1 -1
- package/dist/cjs/next/draft-mode/index.js +3 -3
- package/dist/cjs/next/draft-mode/index.js.map +1 -1
- package/dist/cjs/next/middleware/exceptions.js +59 -0
- package/dist/cjs/next/middleware/exceptions.js.map +1 -0
- package/dist/cjs/next/middleware/index.js +37 -0
- package/dist/cjs/next/middleware/index.js.map +1 -0
- package/dist/cjs/next/middleware/request-utils.js +167 -0
- package/dist/cjs/next/middleware/request-utils.js.map +1 -0
- package/dist/cjs/next/preview-mode.js +4 -9
- package/dist/cjs/next/preview-mode.js.map +1 -1
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js +4 -2
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/host-api-client.js +5 -1
- package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
- package/dist/cjs/state/makeswift-api-client.js +21 -10
- package/dist/cjs/state/makeswift-api-client.js.map +1 -1
- package/dist/esm/api/react.js +28 -7
- package/dist/esm/api/react.js.map +1 -1
- package/dist/esm/api/site-version.js +10 -0
- package/dist/esm/api/site-version.js.map +1 -0
- package/dist/esm/next/api-handler/handlers/draft-mode.js +58 -0
- package/dist/esm/next/api-handler/handlers/draft-mode.js.map +1 -0
- package/dist/esm/next/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/next/api-handler/handlers/preview-mode.js +51 -0
- package/dist/esm/next/api-handler/handlers/preview-mode.js.map +1 -0
- package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js +1 -1
- package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js +1 -1
- package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js.map +1 -1
- package/dist/esm/next/api-handler/index.js +24 -2
- package/dist/esm/next/api-handler/index.js.map +1 -1
- package/dist/esm/next/client.js +2 -1
- package/dist/esm/next/client.js.map +1 -1
- package/dist/esm/next/draft-mode/index.js +1 -1
- package/dist/esm/next/draft-mode/index.js.map +1 -1
- package/dist/esm/next/middleware/exceptions.js +29 -0
- package/dist/esm/next/middleware/exceptions.js.map +1 -0
- package/dist/esm/next/middleware/index.js +15 -0
- package/dist/esm/next/middleware/index.js.map +1 -0
- package/dist/esm/next/middleware/request-utils.js +146 -0
- package/dist/esm/next/middleware/request-utils.js.map +1 -0
- package/dist/esm/next/preview-mode.js +2 -5
- package/dist/esm/next/preview-mode.js.map +1 -1
- package/dist/esm/runtimes/react/components/RuntimeProvider.js +4 -2
- package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/esm/runtimes/react/host-api-client.js +5 -1
- package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
- package/dist/esm/state/makeswift-api-client.js +21 -10
- package/dist/esm/state/makeswift-api-client.js.map +1 -1
- package/dist/types/api/react.d.ts +4 -1
- package/dist/types/api/react.d.ts.map +1 -1
- package/dist/types/api/site-version.d.ts +6 -0
- package/dist/types/api/site-version.d.ts.map +1 -0
- package/dist/types/next/api-handler/handlers/draft-mode.d.ts +20 -0
- package/dist/types/next/api-handler/handlers/draft-mode.d.ts.map +1 -0
- package/dist/types/next/api-handler/handlers/preview-mode.d.ts +20 -0
- package/dist/types/next/api-handler/handlers/preview-mode.d.ts.map +1 -0
- package/dist/types/next/api-handler/handlers/proxy-preview-mode.d.ts.map +1 -1
- package/dist/types/next/api-handler/index.d.ts +3 -1
- package/dist/types/next/api-handler/index.d.ts.map +1 -1
- package/dist/types/next/client.d.ts +1 -1
- package/dist/types/next/client.d.ts.map +1 -1
- package/dist/types/next/draft-mode/index.d.ts +2 -2
- package/dist/types/next/middleware/exceptions.d.ts +16 -0
- package/dist/types/next/middleware/exceptions.d.ts.map +1 -0
- package/dist/types/next/middleware/index.d.ts +2 -0
- package/dist/types/next/middleware/index.d.ts.map +1 -0
- package/dist/types/next/middleware/request-utils.d.ts +16 -0
- package/dist/types/next/middleware/request-utils.d.ts.map +1 -0
- package/dist/types/next/middleware/request-utils.test.d.ts +2 -0
- package/dist/types/next/middleware/request-utils.test.d.ts.map +1 -0
- package/dist/types/next/preview-mode.d.ts +3 -5
- package/dist/types/next/preview-mode.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/host-api-client.d.ts.map +1 -1
- package/dist/types/state/makeswift-api-client.d.ts +2 -1
- package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
- package/package.json +10 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { cookies, draftMode } from "next/headers";
|
|
3
|
-
import {
|
|
3
|
+
import { MakeswiftSiteVersion, makeswiftSiteVersionSchema } from "../../api/site-version";
|
|
4
4
|
const MAKESWIFT_DRAFT_MODE_DATA_COOKIE = "x-makeswift-draft-data";
|
|
5
5
|
const makeswiftDraftDataSchema = z.object({
|
|
6
6
|
makeswift: z.literal(true),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/next/draft-mode/index.tsx"],"sourcesContent":["import { z } from 'zod'\nimport { cookies, draftMode } from 'next/headers'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/next/draft-mode/index.tsx"],"sourcesContent":["import { z } from 'zod'\nimport { cookies, draftMode } from 'next/headers'\nimport { MakeswiftSiteVersion, makeswiftSiteVersionSchema } from '../../api/site-version'\n\nexport const MAKESWIFT_DRAFT_MODE_DATA_COOKIE = 'x-makeswift-draft-data'\n\nexport const makeswiftDraftDataSchema = z.object({\n makeswift: z.literal(true),\n siteVersion: makeswiftSiteVersionSchema,\n})\n\nexport type MakeswiftDraftData = z.infer<typeof makeswiftDraftDataSchema>\n\nasync function getDraftData(): Promise<MakeswiftDraftData | null> {\n const { isEnabled: isDraftModeEnabled } = await draftMode()\n if (!isDraftModeEnabled) return null\n\n const cookie = (await cookies()).get(MAKESWIFT_DRAFT_MODE_DATA_COOKIE)\n if (cookie == null) return null\n\n const draftData = JSON.parse(cookie.value)\n const result = makeswiftDraftDataSchema.safeParse(draftData)\n\n if (result.success) return result.data\n return null\n}\n\nexport async function getSiteVersion() {\n return (await getDraftData())?.siteVersion ?? MakeswiftSiteVersion.Live\n}\n"],"mappings":"AAAA,SAAS,SAAS;AAClB,SAAS,SAAS,iBAAiB;AACnC,SAAS,sBAAsB,kCAAkC;AAE1D,MAAM,mCAAmC;AAEzC,MAAM,2BAA2B,EAAE,OAAO;AAAA,EAC/C,WAAW,EAAE,QAAQ,IAAI;AAAA,EACzB,aAAa;AACf,CAAC;AAID,eAAe,eAAmD;AAChE,QAAM,EAAE,WAAW,mBAAmB,IAAI,MAAM,UAAU;AAC1D,MAAI,CAAC;AAAoB,WAAO;AAEhC,QAAM,UAAU,MAAM,QAAQ,GAAG,IAAI,gCAAgC;AACrE,MAAI,UAAU;AAAM,WAAO;AAE3B,QAAM,YAAY,KAAK,MAAM,OAAO,KAAK;AACzC,QAAM,SAAS,yBAAyB,UAAU,SAAS;AAE3D,MAAI,OAAO;AAAS,WAAO,OAAO;AAClC,SAAO;AACT;AAEA,eAAsB,iBAAiB;AACrC,UAAQ,MAAM,aAAa,IAAI,eAAe,qBAAqB;AACrE;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class MiddlewareError extends Error {
|
|
2
|
+
constructor(message, options) {
|
|
3
|
+
super(message, options);
|
|
4
|
+
this.name = this.constructor.name;
|
|
5
|
+
Error.captureStackTrace(this, this.constructor);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
class InvariantDraftRequestError extends MiddlewareError {
|
|
9
|
+
}
|
|
10
|
+
class UnauthorizedDraftRequestError extends MiddlewareError {
|
|
11
|
+
}
|
|
12
|
+
class UnparseableDraftCookieResponseError extends MiddlewareError {
|
|
13
|
+
}
|
|
14
|
+
class MissingDraftEndpointError extends MiddlewareError {
|
|
15
|
+
}
|
|
16
|
+
class UnknownDraftFetchRequestError extends MiddlewareError {
|
|
17
|
+
}
|
|
18
|
+
class InvalidProxyRequestInputError extends MiddlewareError {
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
InvalidProxyRequestInputError,
|
|
22
|
+
InvariantDraftRequestError,
|
|
23
|
+
MiddlewareError,
|
|
24
|
+
MissingDraftEndpointError,
|
|
25
|
+
UnauthorizedDraftRequestError,
|
|
26
|
+
UnknownDraftFetchRequestError,
|
|
27
|
+
UnparseableDraftCookieResponseError
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/next/middleware/exceptions.ts"],"sourcesContent":["export class MiddlewareError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options)\n this.name = this.constructor.name\n\n Error.captureStackTrace(this, this.constructor)\n }\n}\n\nexport class InvariantDraftRequestError extends MiddlewareError {}\n\nexport class UnauthorizedDraftRequestError extends MiddlewareError {}\n\nexport class UnparseableDraftCookieResponseError extends MiddlewareError {}\n\nexport class MissingDraftEndpointError extends MiddlewareError {}\n\nexport class UnknownDraftFetchRequestError extends MiddlewareError {}\n\nexport class InvalidProxyRequestInputError extends MiddlewareError {}\n"],"mappings":"AAAO,MAAM,wBAAwB,MAAM;AAAA,EACzC,YAAY,SAAiB,SAAwB;AACnD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO,KAAK,YAAY;AAE7B,UAAM,kBAAkB,MAAM,KAAK,WAAW;AAAA,EAChD;AACF;AAEO,MAAM,mCAAmC,gBAAgB;AAAC;AAE1D,MAAM,sCAAsC,gBAAgB;AAAC;AAE7D,MAAM,4CAA4C,gBAAgB;AAAC;AAEnE,MAAM,kCAAkC,gBAAgB;AAAC;AAEzD,MAAM,sCAAsC,gBAAgB;AAAC;AAE7D,MAAM,sCAAsC,gBAAgB;AAAC;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isDraftModeRequest,
|
|
3
|
+
isPreviewModeRequest,
|
|
4
|
+
getDraftSecret,
|
|
5
|
+
createDraftRequest,
|
|
6
|
+
fetchDraftProxyResponse
|
|
7
|
+
} from "./request-utils";
|
|
8
|
+
export {
|
|
9
|
+
createDraftRequest as unstable_createMakeswiftDraftRequest,
|
|
10
|
+
fetchDraftProxyResponse as unstable_fetchMakeswiftDraftProxyResponse,
|
|
11
|
+
getDraftSecret as unstable_getMakeswiftDraftSecret,
|
|
12
|
+
isDraftModeRequest as unstable_isDraftModeRequest,
|
|
13
|
+
isPreviewModeRequest as unstable_isPreviewModeRequest
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/next/middleware/index.ts"],"sourcesContent":["export {\n isDraftModeRequest as unstable_isDraftModeRequest,\n isPreviewModeRequest as unstable_isPreviewModeRequest,\n getDraftSecret as unstable_getMakeswiftDraftSecret,\n createDraftRequest as unstable_createMakeswiftDraftRequest,\n fetchDraftProxyResponse as unstable_fetchMakeswiftDraftProxyResponse,\n} from './request-utils'\n"],"mappings":"AAAA;AAAA,EACwB;AAAA,EACE;AAAA,EACN;AAAA,EACI;AAAA,EACK;AAAA,OACtB;","names":[]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import {
|
|
3
|
+
InvalidProxyRequestInputError,
|
|
4
|
+
InvariantDraftRequestError,
|
|
5
|
+
MiddlewareError,
|
|
6
|
+
MissingDraftEndpointError,
|
|
7
|
+
UnauthorizedDraftRequestError,
|
|
8
|
+
UnknownDraftFetchRequestError,
|
|
9
|
+
UnparseableDraftCookieResponseError
|
|
10
|
+
} from "./exceptions";
|
|
11
|
+
import { parse as parseSetCookie } from "set-cookie-parser";
|
|
12
|
+
const HeaderNames = {
|
|
13
|
+
DraftMode: "X-Makeswift-Draft-Mode",
|
|
14
|
+
PreviewMode: "X-Makeswift-Preview-Mode"
|
|
15
|
+
};
|
|
16
|
+
const SearchParams = {
|
|
17
|
+
DraftMode: "x-makeswift-draft-mode",
|
|
18
|
+
PreviewMode: "x-makeswift-preview-mode"
|
|
19
|
+
};
|
|
20
|
+
const CookieRequestEndpoints = {
|
|
21
|
+
DraftMode: "/api/makeswift/draft-mode",
|
|
22
|
+
PreviewMode: "/api/makeswift/preview-mode"
|
|
23
|
+
};
|
|
24
|
+
function getDraftModeSecret(request) {
|
|
25
|
+
return request.nextUrl.searchParams.get(SearchParams.DraftMode) ?? request.headers.get(HeaderNames.DraftMode) ?? null;
|
|
26
|
+
}
|
|
27
|
+
function getPreviewModeSecret(request) {
|
|
28
|
+
return request.nextUrl.searchParams.get(SearchParams.PreviewMode) ?? request.headers.get(HeaderNames.PreviewMode) ?? null;
|
|
29
|
+
}
|
|
30
|
+
function isDraftModeRequest(request) {
|
|
31
|
+
return getDraftModeSecret(request) != null;
|
|
32
|
+
}
|
|
33
|
+
function isPreviewModeRequest(request) {
|
|
34
|
+
return getPreviewModeSecret(request) != null;
|
|
35
|
+
}
|
|
36
|
+
function isDraftRequest(request) {
|
|
37
|
+
return isDraftModeRequest(request) || isPreviewModeRequest(request);
|
|
38
|
+
}
|
|
39
|
+
function getDraftSecret(request) {
|
|
40
|
+
const draftSecret = getDraftModeSecret(request);
|
|
41
|
+
const previewSecret = getPreviewModeSecret(request);
|
|
42
|
+
if (draftSecret != null && previewSecret != null) {
|
|
43
|
+
throw new InvariantDraftRequestError(
|
|
44
|
+
"Request can't include draft mode and preview mode secrets"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return draftSecret ?? previewSecret;
|
|
48
|
+
}
|
|
49
|
+
async function fetchCookies(url, draftSecret) {
|
|
50
|
+
const requestUrl = new URL(url);
|
|
51
|
+
requestUrl.searchParams.set("secret", draftSecret);
|
|
52
|
+
const response = await fetch(requestUrl).then((res) => {
|
|
53
|
+
if (res.ok)
|
|
54
|
+
return res;
|
|
55
|
+
if (res.status === 401) {
|
|
56
|
+
throw new UnauthorizedDraftRequestError(`Unauthorized draft request to ${url}`);
|
|
57
|
+
}
|
|
58
|
+
if (res.status === 404) {
|
|
59
|
+
throw new MissingDraftEndpointError(
|
|
60
|
+
`Could not find draft endpoint at ${url}. Please make sure you properly registered a \`MakeswiftApiHandler\``
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
throw new UnknownDraftFetchRequestError(
|
|
64
|
+
"Encountered unknown error while fetching draft cookies"
|
|
65
|
+
);
|
|
66
|
+
}).catch((err) => {
|
|
67
|
+
if (err instanceof MiddlewareError)
|
|
68
|
+
throw err;
|
|
69
|
+
throw new UnknownDraftFetchRequestError(
|
|
70
|
+
"Encountered unknown error while fetching draft cookies",
|
|
71
|
+
{ cause: err }
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
const setCookieHeader = response.headers.getSetCookie();
|
|
75
|
+
if (setCookieHeader.length <= 0) {
|
|
76
|
+
throw new UnparseableDraftCookieResponseError(
|
|
77
|
+
"Received empty draft cookies. If you're seeing this error, please report a bug to https://github.com/makeswift/makeswift"
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return parseSetCookie(setCookieHeader);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
throw new UnparseableDraftCookieResponseError(
|
|
84
|
+
"Could not parse draft cookies. If you're seeing this error, please report a bug to https://github.com/makeswift/makeswift",
|
|
85
|
+
{ cause: err }
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function fetchDraftModeCookies(origin, draftSecret) {
|
|
90
|
+
return await fetchCookies(new URL(CookieRequestEndpoints.DraftMode, origin), draftSecret);
|
|
91
|
+
}
|
|
92
|
+
async function fetchPreviewModeCookies(origin, draftSecret) {
|
|
93
|
+
return await fetchCookies(new URL(CookieRequestEndpoints.PreviewMode, origin), draftSecret);
|
|
94
|
+
}
|
|
95
|
+
async function fetchDraftCookies(request, draftSecret) {
|
|
96
|
+
if (isDraftModeRequest(request)) {
|
|
97
|
+
return await fetchDraftModeCookies(request.nextUrl.origin, draftSecret);
|
|
98
|
+
} else if (isPreviewModeRequest(request)) {
|
|
99
|
+
return await fetchPreviewModeCookies(request.nextUrl.origin, draftSecret);
|
|
100
|
+
}
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
class MakeswiftDraftRequest extends NextRequest {
|
|
104
|
+
}
|
|
105
|
+
async function createDraftRequest(requestInit, apiKey) {
|
|
106
|
+
const requestSecret = getDraftSecret(requestInit);
|
|
107
|
+
if (requestSecret == null || requestSecret !== apiKey)
|
|
108
|
+
return null;
|
|
109
|
+
const draftCookies = await fetchDraftCookies(requestInit, requestSecret);
|
|
110
|
+
const draftRequest = new MakeswiftDraftRequest(requestInit, requestInit);
|
|
111
|
+
draftCookies.forEach(({ name, value }) => {
|
|
112
|
+
draftRequest.cookies.set(name, value);
|
|
113
|
+
});
|
|
114
|
+
draftRequest.nextUrl.searchParams.delete(SearchParams.DraftMode);
|
|
115
|
+
draftRequest.nextUrl.searchParams.delete(SearchParams.PreviewMode);
|
|
116
|
+
draftRequest.headers.delete(HeaderNames.DraftMode);
|
|
117
|
+
draftRequest.headers.delete(HeaderNames.PreviewMode);
|
|
118
|
+
return draftRequest;
|
|
119
|
+
}
|
|
120
|
+
async function fetchDraftProxyResponse(draftRequest) {
|
|
121
|
+
if (!(draftRequest instanceof MakeswiftDraftRequest)) {
|
|
122
|
+
throw new InvalidProxyRequestInputError(
|
|
123
|
+
"Draft request must be instance of `MakeswiftDraftRequest`"
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
const proxyUrl = new URL(draftRequest.nextUrl, draftRequest.nextUrl.origin);
|
|
127
|
+
const proxyResponse = await fetch(proxyUrl, { headers: draftRequest.headers });
|
|
128
|
+
const response = new NextResponse(proxyResponse.body, {
|
|
129
|
+
headers: proxyResponse.headers,
|
|
130
|
+
status: proxyResponse.status
|
|
131
|
+
});
|
|
132
|
+
if (response.headers.has("content-encoding")) {
|
|
133
|
+
response.headers.delete("content-encoding");
|
|
134
|
+
response.headers.delete("content-length");
|
|
135
|
+
}
|
|
136
|
+
return response;
|
|
137
|
+
}
|
|
138
|
+
export {
|
|
139
|
+
createDraftRequest,
|
|
140
|
+
fetchDraftProxyResponse,
|
|
141
|
+
getDraftSecret,
|
|
142
|
+
isDraftModeRequest,
|
|
143
|
+
isDraftRequest,
|
|
144
|
+
isPreviewModeRequest
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=request-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/next/middleware/request-utils.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server'\nimport {\n InvalidProxyRequestInputError,\n InvariantDraftRequestError,\n MiddlewareError,\n MissingDraftEndpointError,\n UnauthorizedDraftRequestError,\n UnknownDraftFetchRequestError,\n UnparseableDraftCookieResponseError,\n} from './exceptions'\n\nimport { type Cookie, parse as parseSetCookie } from 'set-cookie-parser'\n\nconst HeaderNames = {\n DraftMode: 'X-Makeswift-Draft-Mode',\n PreviewMode: 'X-Makeswift-Preview-Mode',\n} as const\n\nconst SearchParams = {\n DraftMode: 'x-makeswift-draft-mode',\n PreviewMode: 'x-makeswift-preview-mode',\n} as const\n\nconst CookieRequestEndpoints = {\n DraftMode: '/api/makeswift/draft-mode',\n PreviewMode: '/api/makeswift/preview-mode',\n} as const\n\nfunction getDraftModeSecret(request: NextRequest): string | null {\n return (\n request.nextUrl.searchParams.get(SearchParams.DraftMode) ??\n request.headers.get(HeaderNames.DraftMode) ??\n null\n )\n}\n\nfunction getPreviewModeSecret(request: NextRequest): string | null {\n return (\n request.nextUrl.searchParams.get(SearchParams.PreviewMode) ??\n request.headers.get(HeaderNames.PreviewMode) ??\n null\n )\n}\n\nexport function isDraftModeRequest(request: NextRequest): boolean {\n return getDraftModeSecret(request) != null\n}\n\nexport function isPreviewModeRequest(request: NextRequest): boolean {\n return getPreviewModeSecret(request) != null\n}\n\nexport function isDraftRequest(request: NextRequest): boolean {\n return isDraftModeRequest(request) || isPreviewModeRequest(request)\n}\n\nexport function getDraftSecret(request: NextRequest): string | null {\n const draftSecret = getDraftModeSecret(request)\n const previewSecret = getPreviewModeSecret(request)\n if (draftSecret != null && previewSecret != null) {\n throw new InvariantDraftRequestError(\n \"Request can't include draft mode and preview mode secrets\",\n )\n }\n return draftSecret ?? previewSecret\n}\n\nasync function fetchCookies(url: URL, draftSecret: string): Promise<Cookie[]> {\n const requestUrl = new URL(url)\n requestUrl.searchParams.set('secret', draftSecret)\n\n const response = await fetch(requestUrl)\n .then(res => {\n if (res.ok) return res\n if (res.status === 401) {\n throw new UnauthorizedDraftRequestError(`Unauthorized draft request to ${url}`)\n }\n if (res.status === 404) {\n throw new MissingDraftEndpointError(\n `Could not find draft endpoint at ${url}. Please make sure you properly registered a \\`MakeswiftApiHandler\\``,\n )\n }\n throw new UnknownDraftFetchRequestError(\n 'Encountered unknown error while fetching draft cookies',\n )\n })\n .catch((err: unknown) => {\n if (err instanceof MiddlewareError) throw err\n throw new UnknownDraftFetchRequestError(\n 'Encountered unknown error while fetching draft cookies',\n { cause: err },\n )\n })\n\n const setCookieHeader = response.headers.getSetCookie()\n\n if (setCookieHeader.length <= 0) {\n throw new UnparseableDraftCookieResponseError(\n \"Received empty draft cookies. If you're seeing this error, please report a bug to https://github.com/makeswift/makeswift\",\n )\n }\n\n try {\n return parseSetCookie(setCookieHeader)\n } catch (err) {\n throw new UnparseableDraftCookieResponseError(\n \"Could not parse draft cookies. If you're seeing this error, please report a bug to https://github.com/makeswift/makeswift\",\n { cause: err },\n )\n }\n}\n\nasync function fetchDraftModeCookies(origin: string, draftSecret: string): Promise<Cookie[]> {\n return await fetchCookies(new URL(CookieRequestEndpoints.DraftMode, origin), draftSecret)\n}\n\nasync function fetchPreviewModeCookies(origin: string, draftSecret: string): Promise<Cookie[]> {\n return await fetchCookies(new URL(CookieRequestEndpoints.PreviewMode, origin), draftSecret)\n}\n\nasync function fetchDraftCookies(request: NextRequest, draftSecret: string): Promise<Cookie[]> {\n if (isDraftModeRequest(request)) {\n return await fetchDraftModeCookies(request.nextUrl.origin, draftSecret)\n } else if (isPreviewModeRequest(request)) {\n return await fetchPreviewModeCookies(request.nextUrl.origin, draftSecret)\n }\n\n return []\n}\n\nclass MakeswiftDraftRequest extends NextRequest {}\n\n/**\n * Creates a new `NextRequest` that can be used for fetching a working version\n * of the page (that will also bypass the Vercel cache). Returns `null` if the\n * given request does not have a draft secret that matches the `apiKey`.\n */\nexport async function createDraftRequest(\n requestInit: NextRequest,\n apiKey: string,\n): Promise<MakeswiftDraftRequest | null> {\n const requestSecret = getDraftSecret(requestInit)\n\n if (requestSecret == null || requestSecret !== apiKey) return null\n\n const draftCookies = await fetchDraftCookies(requestInit, requestSecret)\n\n // https://github.com/vercel/next.js/issues/52967#issuecomment-1644675602\n // if we don't pass request twice, headers are stripped\n const draftRequest = new MakeswiftDraftRequest(requestInit, requestInit)\n\n draftCookies.forEach(({ name, value }) => {\n draftRequest.cookies.set(name, value)\n })\n\n draftRequest.nextUrl.searchParams.delete(SearchParams.DraftMode)\n draftRequest.nextUrl.searchParams.delete(SearchParams.PreviewMode)\n draftRequest.headers.delete(HeaderNames.DraftMode)\n draftRequest.headers.delete(HeaderNames.PreviewMode)\n\n return draftRequest\n}\n\nexport async function fetchDraftProxyResponse(\n draftRequest: MakeswiftDraftRequest,\n): Promise<NextResponse> {\n if (!(draftRequest instanceof MakeswiftDraftRequest)) {\n throw new InvalidProxyRequestInputError(\n 'Draft request must be instance of `MakeswiftDraftRequest`',\n )\n }\n // Passing `draftRequest.nextUrl` to fetch directly won't work when deployed\n // on Vercel - it results in a `TypeError: Invalid URL` error. Constructing\n // the URL works.\n const proxyUrl = new URL(draftRequest.nextUrl, draftRequest.nextUrl.origin)\n const proxyResponse = await fetch(proxyUrl, { headers: draftRequest.headers })\n\n const response = new NextResponse(proxyResponse.body, {\n headers: proxyResponse.headers,\n status: proxyResponse.status,\n })\n\n // `fetch` automatically decompresses the response, but the response headers\n // will keep the `content-encoding` and `content-length` headers. This will\n // cause decoding issues if the client attempts to decompress the response\n // again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (response.headers.has('content-encoding')) {\n response.headers.delete('content-encoding')\n response.headers.delete('content-length')\n }\n\n return response\n}\n"],"mappings":"AAAA,SAAS,aAAa,oBAAoB;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAsB,SAAS,sBAAsB;AAErD,MAAM,cAAc;AAAA,EAClB,WAAW;AAAA,EACX,aAAa;AACf;AAEA,MAAM,eAAe;AAAA,EACnB,WAAW;AAAA,EACX,aAAa;AACf;AAEA,MAAM,yBAAyB;AAAA,EAC7B,WAAW;AAAA,EACX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O,YAAY,SAAS;AACjD,eAAa,QAAQ,OAAO,YAAY,WAAW;AAEnD,SAAO;AACT;AAEA,eAAsB,wBACpB,cACuB;AACvB,MAAI,EAAE,wBAAwB,wBAAwB;AACpD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAIA,QAAM,WAAW,IAAI,IAAI,aAAa,SAAS,aAAa,QAAQ,MAAM;AAC1E,QAAM,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,aAAa,QAAQ,CAAC;AAE7E,QAAM,WAAW,IAAI,aAAa,cAAc,MAAM;AAAA,IACpD,SAAS,cAAc;AAAA,IACvB,QAAQ,cAAc;AAAA,EACxB,CAAC;AAQD,MAAI,SAAS,QAAQ,IAAI,kBAAkB,GAAG;AAC5C,aAAS,QAAQ,OAAO,kBAAkB;AAC1C,aAAS,QAAQ,OAAO,gBAAgB;AAAA,EAC1C;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { ActionTypes } from "../react";
|
|
4
|
-
|
|
5
|
-
const MakeswiftSiteVersion = makeswiftSiteVersionSchema.Enum;
|
|
4
|
+
import { makeswiftSiteVersionSchema } from "../api/site-version";
|
|
6
5
|
const makeswiftPreviewDataSchema = z.object({
|
|
7
6
|
makeswift: z.literal(true),
|
|
8
7
|
siteVersion: makeswiftSiteVersionSchema
|
|
@@ -111,9 +110,7 @@ if (window.parent !== window) {
|
|
|
111
110
|
] });
|
|
112
111
|
}
|
|
113
112
|
export {
|
|
114
|
-
MakeswiftSiteVersion,
|
|
115
113
|
PreviewModeScript,
|
|
116
|
-
getMakeswiftSiteVersion
|
|
117
|
-
makeswiftSiteVersionSchema
|
|
114
|
+
getMakeswiftSiteVersion
|
|
118
115
|
};
|
|
119
116
|
//# sourceMappingURL=preview-mode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/next/preview-mode.tsx"],"sourcesContent":["import { PreviewData } from 'next'\nimport { z } from 'zod'\nimport { ActionTypes } from '../react'\
|
|
1
|
+
{"version":3,"sources":["../../../src/next/preview-mode.tsx"],"sourcesContent":["import { PreviewData } from 'next'\nimport { z } from 'zod'\nimport { ActionTypes } from '../react'\nimport { type MakeswiftSiteVersion, makeswiftSiteVersionSchema } from '../api/site-version'\n\nconst makeswiftPreviewDataSchema = z.object({\n makeswift: z.literal(true),\n siteVersion: makeswiftSiteVersionSchema,\n})\nexport type MakeswiftPreviewData = z.infer<typeof makeswiftPreviewDataSchema>\n\nexport function getMakeswiftSiteVersion(previewData: PreviewData): MakeswiftSiteVersion | null {\n const result = makeswiftPreviewDataSchema.safeParse(previewData)\n\n if (result.success) return result.data.siteVersion\n\n return null\n}\n\ntype Props = {\n isPreview?: boolean\n appOrigin?: string\n}\n\nexport function PreviewModeScript({\n isPreview = false,\n appOrigin = 'https://app.makeswift.com',\n}: Props) {\n const previewModeScript = `\nconst isPreview = ${isPreview}\nconst appOrigin = '${appOrigin.replace(\"'\", \"\\\\'\")}'\nconst searchParamName = 'x-makeswift-preview-mode'\nconst headerName = 'X-Makeswift-Preview-Mode'\nconst originalUrl = new URL(window.location.href)\n\nif (window.parent !== window) {\n window.addEventListener('message', event => {\n if (event.origin === appOrigin && event.data.type === 'makeswift_preview_mode') {\n const { secret } = event.data\n\n if (!isPreview && !originalUrl.searchParams.has(searchParamName)) {\n const url = new URL(originalUrl)\n\n url.searchParams.set(searchParamName, secret)\n\n window.location.replace(url)\n } else {\n const originalFetch = window.fetch\n\n window.fetch = function patchedFetch(resource, options) {\n const request = new Request(resource, options)\n\n if (new URL(request.url).origin !== window.location.origin) {\n return originalFetch.call(this, resource, options)\n }\n \n const newHeaders = new Headers(request.headers)\n newHeaders.set(headerName, secret)\n\n return originalFetch.call(\n this,\n new Request(request, { headers: newHeaders })\n )\n }\n }\n }\n })\n\n window.parent.postMessage({ type: 'makeswift_preview_mode' }, appOrigin)\n}\n\nif (originalUrl.searchParams.has(searchParamName)) {\n const url = new URL(originalUrl)\n\n url.searchParams.delete(searchParamName)\n\n window.history.replaceState(null, '', url)\n}\n`\n\n const makeswiftConnectionCheckScript = `\nconst appOrigin = '${appOrigin.replace(\"'\", \"\\\\'\")}'\n\nif (window.parent !== window) {\n window.addEventListener('message', event => {\n if (\n event.origin === appOrigin && \n event.data.type === '${ActionTypes.MAKESWIFT_CONNECTION_INIT}'\n ) {\n setInterval(() => {\n window.parent.postMessage({ \n type: '${ActionTypes.MAKESWIFT_CONNECTION_CHECK}',\n payload: { \n currentUrl: window.location.href \n }\n }, appOrigin)\n }, 20)\n }\n })\n\n window.parent.postMessage({ type: '${ActionTypes.MAKESWIFT_CONNECTION_INIT}' }, appOrigin)\n}\n`\n\n return (\n <>\n <script\n id=\"makeswift-preview-mode\"\n type=\"module\"\n dangerouslySetInnerHTML={{ __html: previewModeScript }}\n />\n <script\n id=\"makeswift-connection-check\"\n type=\"module\"\n dangerouslySetInnerHTML={{ __html: makeswiftConnectionCheckScript }}\n />\n </>\n )\n}\n"],"mappings":"AAyGI,mBACE,KADF;AAxGJ,SAAS,SAAS;AAClB,SAAS,mBAAmB;AAC5B,SAAoC,kCAAkC;AAEtE,MAAM,6BAA6B,EAAE,OAAO;AAAA,EAC1C,WAAW,EAAE,QAAQ,IAAI;AAAA,EACzB,aAAa;AACf,CAAC;AAGM,SAAS,wBAAwB,aAAuD;AAC7F,QAAM,SAAS,2BAA2B,UAAU,WAAW;AAE/D,MAAI,OAAO;AAAS,WAAO,OAAO,KAAK;AAEvC,SAAO;AACT;AAOO,SAAS,kBAAkB;AAAA,EAChC,YAAY;AAAA,EACZ,YAAY;AACd,GAAU;AACR,QAAM,oBAAoB;AAAA,oBACR,SAAS;AAAA,qBACR,UAAU,QAAQ,KAAK,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkDhD,QAAM,iCAAiC;AAAA,qBACpB,UAAU,QAAQ,KAAK,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAMrB,YAAY,yBAAyB;AAAA;AAAA;AAAA;AAAA,mBAI/C,YAAY,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uCASlB,YAAY,yBAAyB;AAAA;AAAA;AAI1E,SACE,iCACE;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,IAAG;AAAA,QACH,MAAK;AAAA,QACL,yBAAyB,EAAE,QAAQ,kBAAkB;AAAA;AAAA,IACvD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACC,IAAG;AAAA,QACH,MAAK;AAAA,QACL,yBAAyB,EAAE,QAAQ,+BAA+B;AAAA;AAAA,IACpE;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -4,6 +4,7 @@ import { useMemo, lazy } from "react";
|
|
|
4
4
|
import { MakeswiftHostApiClient } from "../../../api/react";
|
|
5
5
|
import { ReactRuntimeContext } from "../hooks/use-react-runtime";
|
|
6
6
|
import { MakeswiftHostApiClientProvider } from "../host-api-client";
|
|
7
|
+
import { MakeswiftSiteVersion } from "../../../api/site-version";
|
|
7
8
|
const LiveProvider = lazy(() => import("./LiveProvider"));
|
|
8
9
|
const PreviewProvider = lazy(() => import("./PreviewProvider"));
|
|
9
10
|
function ReactRuntimeProvider({
|
|
@@ -16,9 +17,10 @@ function ReactRuntimeProvider({
|
|
|
16
17
|
const client = useMemo(
|
|
17
18
|
() => new MakeswiftHostApiClient({
|
|
18
19
|
uri: new URL("graphql", apiOrigin).href,
|
|
19
|
-
locale
|
|
20
|
+
locale,
|
|
21
|
+
siteVersion: previewMode ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live
|
|
20
22
|
}),
|
|
21
|
-
[apiOrigin, locale]
|
|
23
|
+
[apiOrigin, locale, previewMode]
|
|
22
24
|
);
|
|
23
25
|
const StoreProvider = previewMode ? PreviewProvider : LiveProvider;
|
|
24
26
|
return /* @__PURE__ */ jsx(ReactRuntimeContext.Provider, { value: runtime, children: /* @__PURE__ */ jsx(MakeswiftHostApiClientProvider, { client, children: /* @__PURE__ */ jsx(StoreProvider, { children }) }) });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useMemo, lazy } from 'react'\n\nimport { MakeswiftHostApiClient } from '../../../api/react'\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { ReactRuntime } from '../react-runtime'\nimport { MakeswiftHostApiClientProvider } from '../host-api-client'\n\nconst LiveProvider = lazy(() => import('./LiveProvider'))\nconst PreviewProvider = lazy(() => import('./PreviewProvider'))\n\nexport function ReactRuntimeProvider({\n children,\n runtime,\n previewMode,\n apiOrigin = 'https://api.makeswift.com',\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntime\n previewMode: boolean\n apiOrigin?: string\n locale?: string\n}) {\n const client = useMemo(\n () =>\n new MakeswiftHostApiClient({\n uri: new URL('graphql', apiOrigin).href,\n locale,\n }),\n [apiOrigin, locale],\n )\n\n const StoreProvider = previewMode ? PreviewProvider : LiveProvider\n\n return (\n <ReactRuntimeContext.Provider value={runtime}>\n <MakeswiftHostApiClientProvider client={client}>\n <StoreProvider>{children}</StoreProvider>\n </MakeswiftHostApiClientProvider>\n </ReactRuntimeContext.Provider>\n )\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useMemo, lazy } from 'react'\n\nimport { MakeswiftHostApiClient } from '../../../api/react'\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { ReactRuntime } from '../react-runtime'\nimport { MakeswiftHostApiClientProvider } from '../host-api-client'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\n\nconst LiveProvider = lazy(() => import('./LiveProvider'))\nconst PreviewProvider = lazy(() => import('./PreviewProvider'))\n\nexport function ReactRuntimeProvider({\n children,\n runtime,\n previewMode,\n apiOrigin = 'https://api.makeswift.com',\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntime\n previewMode: boolean\n apiOrigin?: string\n locale?: string\n}) {\n const client = useMemo(\n () =>\n new MakeswiftHostApiClient({\n uri: new URL('graphql', apiOrigin).href,\n locale,\n siteVersion: previewMode ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live,\n }),\n [apiOrigin, locale, previewMode],\n )\n\n const StoreProvider = previewMode ? PreviewProvider : LiveProvider\n\n return (\n <ReactRuntimeContext.Provider value={runtime}>\n <MakeswiftHostApiClientProvider client={client}>\n <StoreProvider>{children}</StoreProvider>\n </MakeswiftHostApiClientProvider>\n </ReactRuntimeContext.Provider>\n )\n}\n"],"mappings":";AAyCQ;AAvCR,SAAoB,SAAS,YAAY;AAEzC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AAEpC,SAAS,sCAAsC;AAC/C,SAAS,4BAA4B;AAErC,MAAM,eAAe,KAAK,MAAM,OAAO,gBAAgB,CAAC;AACxD,MAAM,kBAAkB,KAAK,MAAM,OAAO,mBAAmB,CAAC;AAEvD,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,SAAS;AACX,GAMG;AACD,QAAM,SAAS;AAAA,IACb,MACE,IAAI,uBAAuB;AAAA,MACzB,KAAK,IAAI,IAAI,WAAW,SAAS,EAAE;AAAA,MACnC;AAAA,MACA,aAAa,cAAc,qBAAqB,UAAU,qBAAqB;AAAA,IACjF,CAAC;AAAA,IACH,CAAC,WAAW,QAAQ,WAAW;AAAA,EACjC;AAEA,QAAM,gBAAgB,cAAc,kBAAkB;AAEtD,SACE,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,SACnC,8BAAC,kCAA+B,QAC9B,8BAAC,iBAAe,UAAS,GAC3B,GACF;AAEJ;","names":[]}
|
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext } from "react";
|
|
4
4
|
import { MakeswiftHostApiClient } from "../../api/react";
|
|
5
|
+
import { MakeswiftSiteVersion } from "../../api/site-version";
|
|
5
6
|
const Context = createContext(
|
|
6
|
-
new MakeswiftHostApiClient({
|
|
7
|
+
new MakeswiftHostApiClient({
|
|
8
|
+
uri: "https://api.makeswift.com/graphql",
|
|
9
|
+
siteVersion: MakeswiftSiteVersion.Live
|
|
10
|
+
})
|
|
7
11
|
);
|
|
8
12
|
function useMakeswiftHostApiClient() {
|
|
9
13
|
return useContext(Context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\n\nconst Context = createContext(\n new MakeswiftHostApiClient({
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\nimport { MakeswiftSiteVersion } from '../../api/site-version'\n\nconst Context = createContext(\n new MakeswiftHostApiClient({\n uri: 'https://api.makeswift.com/graphql',\n siteVersion: MakeswiftSiteVersion.Live,\n }),\n)\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useContext(Context)\n}\n\nexport function MakeswiftHostApiClientProvider({\n client,\n children,\n}: {\n client: MakeswiftHostApiClient\n children: ReactNode\n}) {\n return <Context.Provider value={client}>{children}</Context.Provider>\n}\n"],"mappings":";AAwBS;AAtBT,SAAoB,eAAe,kBAAkB;AACrD,SAAS,8BAA8B;AACvC,SAAS,4BAA4B;AAErC,MAAM,UAAU;AAAA,EACd,IAAI,uBAAuB;AAAA,IACzB,KAAK;AAAA,IACL,aAAa,qBAAqB;AAAA,EACpC,CAAC;AACH;AAEO,SAAS,4BAAoD;AAClE,SAAO,WAAW,OAAO;AAC3B;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGG;AACD,SAAO,oBAAC,QAAQ,UAAR,EAAiB,OAAO,QAAS,UAAS;AACpD;","names":[]}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
APIResourceType
|
|
14
14
|
} from "../api";
|
|
15
15
|
import { MAKESWIFT_CACHE_TAG } from "../next/api-handler/handlers/webhook/site-published";
|
|
16
|
+
import { API_HANDLER_SITE_VERSION_HEADER } from "../api/site-version";
|
|
16
17
|
const reducer = combineReducers({
|
|
17
18
|
apiResources: APIResources.reducer,
|
|
18
19
|
localizedResourcesMap: LocalizedResourcesMap.reducer
|
|
@@ -50,9 +51,12 @@ function getAPIResource(state, resourceType, resourceId, locale) {
|
|
|
50
51
|
return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
async function fetchJson(url) {
|
|
54
|
+
async function fetchJson(url, siteVersion) {
|
|
54
55
|
const response = await fetch(url, {
|
|
55
|
-
headers: {
|
|
56
|
+
headers: {
|
|
57
|
+
"Content-Type": "application/json",
|
|
58
|
+
[API_HANDLER_SITE_VERSION_HEADER]: siteVersion
|
|
59
|
+
},
|
|
56
60
|
next: { tags: [MAKESWIFT_CACHE_TAG] }
|
|
57
61
|
});
|
|
58
62
|
if (response.status === 404)
|
|
@@ -66,7 +70,7 @@ async function fetchJson(url) {
|
|
|
66
70
|
}
|
|
67
71
|
return response.json();
|
|
68
72
|
}
|
|
69
|
-
function fetchAPIResource(resourceType, resourceId, locale) {
|
|
73
|
+
function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
70
74
|
return async (dispatch, getState) => {
|
|
71
75
|
const state = getState();
|
|
72
76
|
if (getHasAPIResource(state, resourceType, resourceId, locale)) {
|
|
@@ -75,16 +79,22 @@ function fetchAPIResource(resourceType, resourceId, locale) {
|
|
|
75
79
|
let resource;
|
|
76
80
|
switch (resourceType) {
|
|
77
81
|
case APIResourceType.Swatch:
|
|
78
|
-
resource = await fetchJson(`/api/makeswift/swatches/${resourceId}
|
|
82
|
+
resource = await fetchJson(`/api/makeswift/swatches/${resourceId}`, siteVersion);
|
|
79
83
|
break;
|
|
80
84
|
case APIResourceType.File:
|
|
81
|
-
resource = await fetchJson(`/api/makeswift/files/${resourceId}
|
|
85
|
+
resource = await fetchJson(`/api/makeswift/files/${resourceId}`, siteVersion);
|
|
82
86
|
break;
|
|
83
87
|
case APIResourceType.Typography:
|
|
84
|
-
resource = await fetchJson(
|
|
88
|
+
resource = await fetchJson(
|
|
89
|
+
`/api/makeswift/typographies/${resourceId}`,
|
|
90
|
+
siteVersion
|
|
91
|
+
);
|
|
85
92
|
break;
|
|
86
93
|
case APIResourceType.GlobalElement:
|
|
87
|
-
resource = await fetchJson(
|
|
94
|
+
resource = await fetchJson(
|
|
95
|
+
`/api/makeswift/global-elements/${resourceId}`,
|
|
96
|
+
siteVersion
|
|
97
|
+
);
|
|
88
98
|
break;
|
|
89
99
|
case APIResourceType.LocalizedGlobalElement: {
|
|
90
100
|
if (locale == null)
|
|
@@ -93,7 +103,8 @@ function fetchAPIResource(resourceType, resourceId, locale) {
|
|
|
93
103
|
return null;
|
|
94
104
|
}
|
|
95
105
|
resource = await fetchJson(
|
|
96
|
-
`/api/makeswift/localized-global-elements/${resourceId}/${locale}
|
|
106
|
+
`/api/makeswift/localized-global-elements/${resourceId}/${locale}`,
|
|
107
|
+
siteVersion
|
|
97
108
|
);
|
|
98
109
|
dispatch(
|
|
99
110
|
setLocalizedResourceId({
|
|
@@ -108,11 +119,11 @@ function fetchAPIResource(resourceType, resourceId, locale) {
|
|
|
108
119
|
const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
|
|
109
120
|
if (locale != null)
|
|
110
121
|
url.searchParams.set("locale", locale);
|
|
111
|
-
resource = await fetchJson(url.pathname + url.search);
|
|
122
|
+
resource = await fetchJson(url.pathname + url.search, siteVersion);
|
|
112
123
|
break;
|
|
113
124
|
}
|
|
114
125
|
case APIResourceType.Table:
|
|
115
|
-
resource = await fetchJson(`/api/makeswift/tables/${resourceId}
|
|
126
|
+
resource = await fetchJson(`/api/makeswift/tables/${resourceId}`, siteVersion);
|
|
116
127
|
break;
|
|
117
128
|
default:
|
|
118
129
|
resource = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n applyMiddleware,\n createStore,\n combineReducers,\n type Dispatch as ReduxDispatch,\n type Store as ReduxStore,\n type Middleware,\n} from 'redux'\nimport thunk, { type ThunkAction, type ThunkDispatch } from 'redux-thunk'\n\nimport { composeWithDevToolsDevelopmentOnly } from '@redux-devtools/extension'\n\nimport { serializeState } from '../utils/serializeState'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes, apiResourceFulfilled, setLocalizedResourceId } from './actions'\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\nimport { MAKESWIFT_CACHE_TAG } from '../next/api-handler/handlers/webhook/site-published'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nasync function fetchJson<T>(url: string): Promise<T | null> {\n const response = await fetch(url, {\n headers: { 'Content-Type': 'application/json' },\n next: { tags: [MAKESWIFT_CACHE_TAG] },\n })\n\n if (response.status === 404) return null\n\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n}\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n return async (dispatch, getState) => {\n const state = getState()\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchJson<Swatch>(`/api/makeswift/swatches/${resourceId}`)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(`/api/makeswift/typographies/${resourceId}`)\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(`/api/makeswift/global-elements/${resourceId}`)\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchJson<PagePathnameSlice>(url.pathname + url.search)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nexport type Store = ReduxStore<State, Action> & { dispatch: Dispatch }\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(\n defaultLocale: string | undefined,\n): Middleware<Dispatch, State, Dispatch> {\n return () => (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: { ...action.payload, locale: locale ?? defaultLocale },\n } as Action)\n }\n }\n\n return next(action)\n }\n }\n}\n\nexport function configureStore({\n defaultLocale,\n serializedState,\n}: {\n defaultLocale: string | undefined\n serializedState?: SerializedState\n}): Store {\n const composeEnhancers = composeWithDevToolsDevelopmentOnly({\n name: `API client store (${new Date().toISOString()})`,\n serialize: true,\n stateSanitizer: (state: any) => serializeState(state),\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n })\n\n return createStore(\n reducer,\n {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n composeEnhancers(applyMiddleware(thunk, defaultLocaleMiddleware(defaultLocale))),\n )\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,OAAO,WAAqD;AAE5D,SAAS,0CAA0C;AAEnD,SAAS,sBAAsB;AAE/B,YAAY,kBAAkB;AAC9B,YAAY,2BAA2B;AACvC,SAAsB,aAAa,sBAAsB,8BAA8B;AACvF;AAAA,EACE;AAAA,OAUK;AACP,SAAS,2BAA2B;AAEpC,MAAM,UAAU,gBAAgB;AAAA,EAC9B,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;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vE;AAAA,MACF;AAAA,MAEA,KAAK,gBAAgB;AACnB,mBAAW,MAAM,UAAiB,yBAAyB,UAAU,EAAE;AACvE;AAAA,MAEF;AACE,mBAAW;AAAA,IACf;AAEA,aAAS,qBAAqB,cAAc,YAAY,UAAU,MAAM,CAAC;AAEzE,WAAO;AAAA,EACT;AACF;AAQA,SAAS,wBACP,eACuC;AACvC,SAAO,MAAM,CAAC,SAAgC;AAC5C,WAAO,CAAC,WAA2B;AACjC,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY,2BAA2B;AAC1C,gBAAM,EAAE,OAAO,IAAI,OAAO;AAC1B,iBAAO,KAAK;AAAA,YACV,GAAG;AAAA,YACH,SAAS,EAAE,GAAG,OAAO,SAAS,QAAQ,UAAU,cAAc;AAAA,UAChE,CAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF;AACF;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAGU;AACR,QAAM,mBAAmB,mCAAmC;AAAA,IAC1D,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,IACnD,WAAW;AAAA,IACX,gBAAgB,CAAC,UAAe,eAAe,KAAK;AAAA,IACpD,iBAAiB;AAAA,MACf,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,YAAY;AAAA,IACd;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IACA,iBAAiB,gBAAgB,OAAO,wBAAwB,aAAa,CAAC,CAAC;AAAA,EACjF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n applyMiddleware,\n createStore,\n combineReducers,\n type Dispatch as ReduxDispatch,\n type Store as ReduxStore,\n type Middleware,\n} from 'redux'\nimport thunk, { type ThunkAction, type ThunkDispatch } from 'redux-thunk'\n\nimport { composeWithDevToolsDevelopmentOnly } from '@redux-devtools/extension'\n\nimport { serializeState } from '../utils/serializeState'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes, apiResourceFulfilled, setLocalizedResourceId } from './actions'\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\nimport { MAKESWIFT_CACHE_TAG } from '../next/api-handler/handlers/webhook/site-published'\nimport { API_HANDLER_SITE_VERSION_HEADER, MakeswiftSiteVersion } from '../api/site-version'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nasync function fetchJson<T>(url: string, siteVersion: MakeswiftSiteVersion): Promise<T | null> {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n [API_HANDLER_SITE_VERSION_HEADER]: siteVersion,\n },\n next: { tags: [MAKESWIFT_CACHE_TAG] },\n })\n\n if (response.status === 404) return null\n\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n}\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n siteVersion: MakeswiftSiteVersion,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n return async (dispatch, getState) => {\n const state = getState()\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchJson<Swatch>(`/api/makeswift/swatches/${resourceId}`, siteVersion)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`, siteVersion)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n siteVersion,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n siteVersion,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n siteVersion,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchJson<PagePathnameSlice>(url.pathname + url.search, siteVersion)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`, siteVersion)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nexport type Store = ReduxStore<State, Action> & { dispatch: Dispatch }\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(\n defaultLocale: string | undefined,\n): Middleware<Dispatch, State, Dispatch> {\n return () => (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: { ...action.payload, locale: locale ?? defaultLocale },\n } as Action)\n }\n }\n\n return next(action)\n }\n }\n}\n\nexport function configureStore({\n defaultLocale,\n serializedState,\n}: {\n defaultLocale: string | undefined\n serializedState?: SerializedState\n}): Store {\n const composeEnhancers = composeWithDevToolsDevelopmentOnly({\n name: `API client store (${new Date().toISOString()})`,\n serialize: true,\n stateSanitizer: (state: any) => serializeState(state),\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n })\n\n return createStore(\n reducer,\n {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n composeEnhancers(applyMiddleware(thunk, defaultLocaleMiddleware(defaultLocale))),\n )\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,OAAO,WAAqD;AAE5D,SAAS,0CAA0C;AAEnD,SAAS,sBAAsB;AAE/B,YAAY,kBAAkB;AAC9B,YAAY,2BAA2B;AACvC,SAAsB,aAAa,sBAAsB,8BAA8B;AACvF;AAAA,EACE;AAAA,OAUK;AACP,SAAS,2BAA2B;AACpC,SAAS,uCAA6D;AAEtE,MAAM,UAAU,gBAAgB;AAAA,EAC9B,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AASD,SAAS,uBACP,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,kBACd,OACA,cACA,YACA,QACS;AACT,UAAQ,cAAc;AAAA,IACpB,KAAK,gBAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO,QAAQ,UAAU;AACpE,aACE,eAA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AACvC,SAAO,MAAM,CAAC,SAAgC;AAC5C,WAAO,CAAC,WAA2B;AACjC,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY,2BAA2B;AAC1C,gBAAM,EAAE,OAAO,IAAI,OAAO;AAC1B,iBAAO,KAAK;AAAA,YACV,GAAG;AAAA,YACH,SAAS,EAAE,GAAG,OAAO,SAAS,QAAQ,UAAU,cAAc;AAAA,UAChE,CAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF;AACF;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAGU;AACR,QAAM,mBAAmB,mCAAmC;AAAA,IAC1D,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,IACnD,WAAW;AAAA,IACX,gBAAgB,CAAC,UAAe,eAAe,KAAK;AAAA,IACpD,iBAAiB;AAAA,MACf,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,YAAY;AAAA,IACd;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IACA,iBAAiB,gBAAgB,OAAO,wBAAwB,aAAa,CAAC,CAAC;AAAA,EACjF;AACF;","names":[]}
|
|
@@ -2,6 +2,7 @@ import { type FetchableValue } from '@makeswift/controls';
|
|
|
2
2
|
import * as MakeswiftApiClient from '../state/makeswift-api-client';
|
|
3
3
|
import { APIResourceType, File, GlobalElement, LocalizedGlobalElement, Page, PagePathnameSlice, Site, Snippet, Swatch, Table, Typography } from './types';
|
|
4
4
|
import { GraphQLClient } from './graphql/client';
|
|
5
|
+
import { MakeswiftSiteVersion } from './site-version';
|
|
5
6
|
export type CacheData = MakeswiftApiClient.SerializedState;
|
|
6
7
|
export declare const CacheData: {
|
|
7
8
|
empty(): CacheData;
|
|
@@ -26,11 +27,13 @@ export declare const CacheData: {
|
|
|
26
27
|
* snapshot for use in the builder, not the lives pages.
|
|
27
28
|
*/
|
|
28
29
|
export declare class MakeswiftHostApiClient {
|
|
30
|
+
siteVersion: MakeswiftSiteVersion;
|
|
29
31
|
graphqlClient: GraphQLClient;
|
|
30
32
|
makeswiftApiClient: MakeswiftApiClient.Store;
|
|
31
33
|
subscribe: MakeswiftApiClient.Store['subscribe'];
|
|
32
|
-
constructor({ uri, cacheData, locale }: {
|
|
34
|
+
constructor({ uri, siteVersion, cacheData, locale, }: {
|
|
33
35
|
uri: string;
|
|
36
|
+
siteVersion: MakeswiftSiteVersion;
|
|
34
37
|
cacheData?: CacheData;
|
|
35
38
|
locale?: string;
|
|
36
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/api/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,kBAAkB,MAAM,+BAA+B,CAAA;AACnE,OAAO,EACL,eAAe,EACf,IAAI,EACJ,aAAa,EACb,sBAAsB,EACtB,IAAI,EACJ,iBAAiB,EACjB,IAAI,EACJ,OAAO,EACP,MAAM,EACN,KAAK,EACL,UAAU,EACX,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/api/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,kBAAkB,MAAM,+BAA+B,CAAA;AACnE,OAAO,EACL,eAAe,EACf,IAAI,EACJ,aAAa,EACb,sBAAsB,EACtB,IAAI,EACJ,iBAAiB,EACjB,IAAI,EACJ,O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,KAAK,GACN,EAAE;QACD,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;QACtB,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,GAAG,IAAI,CAAA;QAC9B,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;KACzC,GACA,cAAc,CAAC,CAAC,GAAG,IAAI,CAAC;IAc3B,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAQlC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAMlD,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAQrC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAQrC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;CAO/C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const makeswiftSiteVersionSchema: z.ZodEnum<["Live", "Working"]>;
|
|
3
|
+
export declare const MakeswiftSiteVersion: z.Values<["Live", "Working"]>;
|
|
4
|
+
export type MakeswiftSiteVersion = z.infer<typeof makeswiftSiteVersionSchema>;
|
|
5
|
+
export declare const API_HANDLER_SITE_VERSION_HEADER = "X-Makeswift-Site-Version";
|
|
6
|
+
//# sourceMappingURL=site-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-version.d.ts","sourceRoot":"","sources":["../../../src/api/site-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,0BAA0B,gCAA8B,CAAA;AACrE,eAAO,MAAM,oBAAoB,+BAAkC,CAAA;AACnE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAE7E,eAAO,MAAM,+BAA+B,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
type Context = {
|
|
4
|
+
params: {
|
|
5
|
+
[key: string]: string | string[];
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
type DraftModeError = string;
|
|
9
|
+
type Response = {
|
|
10
|
+
__brand: 'DraftModeResponse';
|
|
11
|
+
};
|
|
12
|
+
export type DraftModeResponse = DraftModeError | Response;
|
|
13
|
+
export default function draftModeHandler(request: NextRequest, context: Context, { apiKey }: {
|
|
14
|
+
apiKey: string;
|
|
15
|
+
}): Promise<NextResponse<DraftModeResponse>>;
|
|
16
|
+
export default function draftModeHandler(req: NextApiRequest, res: NextApiResponse<DraftModeResponse>, { apiKey }: {
|
|
17
|
+
apiKey: string;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=draft-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft-mode.d.ts","sourceRoot":"","sources":["../../../../../src/next/api-handler/handlers/draft-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAQvD,KAAK,OAAO,GAAG;IAAE,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,CAAA;AAE/D,KAAK,cAAc,GAAG,MAAM,CAAA;AAE5B,KAAK,QAAQ,GAAG;IAAE,OAAO,EAAE,mBAAmB,CAAA;CAAE,CAAA;AAEhD,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG,QAAQ,CAAA;AASzD,wBAA8B,gBAAgB,CAC5C,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,OAAO,EAChB,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7B,OAAO,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAA;AAC3C,wBAA8B,gBAAgB,CAC5C,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,eAAe,CAAC,iBAAiB,CAAC,EACvC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7B,OAAO,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
type Context = {
|
|
4
|
+
params: {
|
|
5
|
+
[key: string]: string | string[];
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
type PreviewModeError = string;
|
|
9
|
+
type Response = {
|
|
10
|
+
__brand: 'PreviewModeResponse';
|
|
11
|
+
};
|
|
12
|
+
export type PreviewModeResponse = PreviewModeError | Response;
|
|
13
|
+
export default function previewModeHandler(request: NextRequest, context: Context, { apiKey }: {
|
|
14
|
+
apiKey: string;
|
|
15
|
+
}): Promise<NextResponse<PreviewModeResponse>>;
|
|
16
|
+
export default function previewModeHandler(req: NextApiRequest, res: NextApiResponse<PreviewModeResponse>, { apiKey }: {
|
|
17
|
+
apiKey: string;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=preview-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-mode.d.ts","sourceRoot":"","sources":["../../../../../src/next/api-handler/handlers/preview-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAUvD,KAAK,OAAO,GAAG;IAAE,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,CAAA;AAE/D,KAAK,gBAAgB,GAAG,MAAM,CAAA;AAE9B,KAAK,QAAQ,GAAG;IAAE,OAAO,EAAE,qBAAqB,CAAA;CAAE,CAAA;AAElD,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,QAAQ,CAAA;AAS7D,wBAA8B,kBAAkB,CAC9C,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,OAAO,EAChB,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7B,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAA;AAC7C,wBAA8B,kBAAkB,CAC9C,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,eAAe,CAAC,mBAAmB,CAAC,EACzC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7B,OAAO,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-preview-mode.d.ts","sourceRoot":"","sources":["../../../../../src/next/api-handler/handlers/proxy-preview-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAEtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"proxy-preview-mode.d.ts","sourceRoot":"","sources":["../../../../../src/next/api-handler/handlers/proxy-preview-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAEtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAIvD,KAAK,OAAO,GAAG;IAAE,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,CAAA;AAE/D,KAAK,qBAAqB,GAAG,MAAM,CAAA;AAEnC,KAAK,aAAa,GAAG;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,CAAA;AAEjD,MAAM,MAAM,wBAAwB,GAAG,qBAAqB,GAAG,aAAa,CAAA;AAyC5E,wBAA8B,gBAAgB,CAC5C,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,OAAO,EAChB,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7B,OAAO,CAAC,YAAY,CAAC,wBAAwB,CAAC,CAAC,CAAA;AAClD,wBAA8B,gBAAgB,CAC5C,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,eAAe,CAAC,wBAAwB,CAAC,EAC9C,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7B,OAAO,CAAC,IAAI,CAAC,CAAA"}
|