@plasmicapp/loader-fetcher 2.0.11 → 2.0.12
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.d.ts +11 -2
- package/dist/index.esm.js +116 -28
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +116 -28
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare class Api {
|
|
2
2
|
private opts;
|
|
3
|
-
private readonly
|
|
3
|
+
private readonly previewHost;
|
|
4
4
|
private readonly cdnHost;
|
|
5
5
|
private fetch;
|
|
6
|
+
private useLegacyPreview;
|
|
6
7
|
private lastResponse;
|
|
7
8
|
constructor(opts: {
|
|
8
9
|
projects: {
|
|
@@ -28,7 +29,11 @@ export declare class Api {
|
|
|
28
29
|
i18nKeyScheme?: "content" | "hash" | "path";
|
|
29
30
|
i18nTagPrefix?: string;
|
|
30
31
|
skipHead?: boolean;
|
|
32
|
+
/** Watcher revisions bypass cached redirects to older previews. */
|
|
33
|
+
minRevs?: Record<string, number>;
|
|
31
34
|
}): Promise<LoaderBundleOutput>;
|
|
35
|
+
private fetchFromRoute;
|
|
36
|
+
private handleBundleResponse;
|
|
32
37
|
private verifyAndParseJsonResponse;
|
|
33
38
|
private parseJsonResponse;
|
|
34
39
|
private makeGetHeaders;
|
|
@@ -116,7 +121,7 @@ export declare interface FetcherOptions {
|
|
|
116
121
|
preview?: boolean;
|
|
117
122
|
/** Fallback for apiHost and cdnHost. */
|
|
118
123
|
host?: string;
|
|
119
|
-
/**
|
|
124
|
+
/** Preview host. Defaults to `host`, then `cdnHost`. */
|
|
120
125
|
apiHost?: string;
|
|
121
126
|
/** Used for fetching published content. */
|
|
122
127
|
cdnHost?: string;
|
|
@@ -152,6 +157,9 @@ declare interface GlobalVariantSplitContent {
|
|
|
152
157
|
|
|
153
158
|
export declare function internal_getCachedBundleInNodeServer(opts: FetcherOptions): LoaderBundleOutput | undefined;
|
|
154
159
|
|
|
160
|
+
/** Share watcher revisions across Next.js server and RSC bundles in the same process. */
|
|
161
|
+
export declare function internal_setPreviewMinRev(projectId: string, revisionNum: number): void;
|
|
162
|
+
|
|
155
163
|
export declare interface LoaderBundleCache {
|
|
156
164
|
set: (data: LoaderBundleOutput) => Promise<void>;
|
|
157
165
|
get: () => Promise<LoaderBundleOutput>;
|
|
@@ -185,6 +193,7 @@ export declare class PlasmicModulesFetcher {
|
|
|
185
193
|
fetchAllData(): Promise<LoaderBundleOutput>;
|
|
186
194
|
private getCachedOrFetch;
|
|
187
195
|
private doFetch;
|
|
196
|
+
private getPreviewMinRevs;
|
|
188
197
|
private cacheBundleInNodeServer;
|
|
189
198
|
}
|
|
190
199
|
|
package/dist/index.esm.js
CHANGED
|
@@ -47,21 +47,26 @@ function transformApiLoaderBundleOutput(bundle) {
|
|
|
47
47
|
filteredIds: Object.fromEntries(bundle.projects.map((p) => [p.id, []]))
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
+
var DEFAULT_CDN_HOST = "https://codegen.plasmic.app";
|
|
51
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 307, 308]);
|
|
52
|
+
var BROWSER_FETCH_FAILED = /* @__PURE__ */ Symbol("BROWSER_FETCH_FAILED");
|
|
53
|
+
var ROUTE_NOT_FOUND = /* @__PURE__ */ Symbol("ROUTE_NOT_FOUND");
|
|
50
54
|
var Api = class {
|
|
51
55
|
constructor(opts) {
|
|
52
56
|
__publicField(this, "opts", opts);
|
|
53
|
-
__publicField(this, "
|
|
57
|
+
__publicField(this, "previewHost");
|
|
54
58
|
__publicField(this, "cdnHost");
|
|
55
59
|
__publicField(this, "fetch");
|
|
60
|
+
__publicField(this, "useLegacyPreview", false);
|
|
56
61
|
__publicField(this, "lastResponse");
|
|
57
62
|
var _a, _b, _c, _d;
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
63
|
+
this.cdnHost = (_b = (_a = opts.cdnHost) != null ? _a : opts.host) != null ? _b : DEFAULT_CDN_HOST;
|
|
64
|
+
this.previewHost = (_d = (_c = opts.apiHost) != null ? _c : opts.host) != null ? _d : this.cdnHost;
|
|
60
65
|
this.fetch = globalThis.fetch.bind(globalThis);
|
|
61
66
|
}
|
|
62
67
|
fetchLoaderData(projectIds, opts) {
|
|
63
68
|
return __async(this, null, function* () {
|
|
64
|
-
var _a, _b
|
|
69
|
+
var _a, _b;
|
|
65
70
|
const { platform, preview } = opts;
|
|
66
71
|
const query = new URLSearchParams([
|
|
67
72
|
["platform", platform != null ? platform : "react"],
|
|
@@ -70,53 +75,106 @@ var Api = class {
|
|
|
70
75
|
...opts.browserOnly ? [["browserOnly", "true"]] : [],
|
|
71
76
|
...opts.i18nKeyScheme ? [["i18nKeyScheme", opts.i18nKeyScheme]] : [],
|
|
72
77
|
...opts.i18nTagPrefix ? [["i18nTagPrefix", opts.i18nTagPrefix]] : [],
|
|
73
|
-
...opts.skipHead ? [["skipHead", "true"]] : []
|
|
78
|
+
...opts.skipHead ? [["skipHead", "true"]] : [],
|
|
79
|
+
...preview ? [["loaderVersion", VERSION]] : [],
|
|
80
|
+
...preview && opts.minRevs ? Object.entries(opts.minRevs).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([projectId, rev]) => ["minRev", `${projectId}:${rev}`]) : []
|
|
74
81
|
]).toString();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
if (!preview) {
|
|
83
|
+
const host2 = this.cdnHost;
|
|
84
|
+
return this.fetchFromRoute(
|
|
85
|
+
host2,
|
|
86
|
+
`${host2}/api/v1/loader/code/published?${query}`,
|
|
87
|
+
{ preview: false }
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const host = this.previewHost;
|
|
91
|
+
const legacyUrl = `${host}/api/v1/loader/code/preview?${query}`;
|
|
92
|
+
if (this.useLegacyPreview) {
|
|
93
|
+
return this.fetchFromRoute(host, legacyUrl, { preview: true });
|
|
94
|
+
}
|
|
95
|
+
const result = yield this.fetchFromRoute(
|
|
96
|
+
host,
|
|
97
|
+
`${host}/api/v1/loader/code/revision/latest?${query}`,
|
|
98
|
+
{ preview: true, allowRouteNotFound: true }
|
|
81
99
|
);
|
|
82
|
-
if (
|
|
100
|
+
if (result !== ROUTE_NOT_FOUND && result !== BROWSER_FETCH_FAILED) {
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
const bundle = yield this.fetchFromRoute(host, legacyUrl, {
|
|
104
|
+
preview: true
|
|
105
|
+
});
|
|
106
|
+
if (result === ROUTE_NOT_FOUND) {
|
|
107
|
+
this.useLegacyPreview = true;
|
|
108
|
+
}
|
|
109
|
+
return bundle;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
fetchFromRoute(host, url, opts) {
|
|
113
|
+
return __async(this, null, function* () {
|
|
114
|
+
var _a, _b, _c;
|
|
115
|
+
const { preview, allowRouteNotFound } = opts;
|
|
116
|
+
const useManualRedirect = this.opts.manualRedirect !== false && !isBrowser;
|
|
117
|
+
if (useManualRedirect) {
|
|
83
118
|
const redirectResp = yield this.fetch(url, {
|
|
84
119
|
method: "GET",
|
|
85
120
|
headers: this.makeGetHeaders(),
|
|
86
121
|
redirect: "manual"
|
|
87
122
|
});
|
|
88
|
-
if (
|
|
123
|
+
if (allowRouteNotFound && redirectResp.status === 404) {
|
|
124
|
+
return ROUTE_NOT_FOUND;
|
|
125
|
+
}
|
|
126
|
+
if (!REDIRECT_STATUSES.has(redirectResp.status)) {
|
|
127
|
+
if (preview) {
|
|
128
|
+
return this.handleBundleResponse(redirectResp, host);
|
|
129
|
+
}
|
|
89
130
|
const error = yield this.parseJsonResponse(redirectResp);
|
|
90
131
|
throw new Error(
|
|
91
|
-
`Error fetching loader data, a redirect was expected: ${(
|
|
132
|
+
`Error fetching loader data, a redirect was expected: ${(_b = (_a = error == null ? void 0 : error.error) == null ? void 0 : _a.message) != null ? _b : redirectResp.statusText}`
|
|
92
133
|
);
|
|
93
134
|
}
|
|
94
|
-
const
|
|
95
|
-
if (!
|
|
135
|
+
const location = redirectResp.headers.get("location");
|
|
136
|
+
if (!location) {
|
|
96
137
|
throw new Error(
|
|
97
138
|
`Error fetching loader data, a redirect was expected but no location header was found`
|
|
98
139
|
);
|
|
99
140
|
}
|
|
100
|
-
|
|
141
|
+
const nextUrl = new URL(location, url).toString();
|
|
142
|
+
if (((_c = this.lastResponse) == null ? void 0 : _c.key) === nextUrl) {
|
|
101
143
|
return this.lastResponse.bundle;
|
|
102
144
|
}
|
|
103
|
-
const resp2 = yield this.fetch(
|
|
145
|
+
const resp2 = yield this.fetch(nextUrl, {
|
|
104
146
|
method: "GET",
|
|
105
147
|
headers: this.makeGetHeaders()
|
|
106
148
|
});
|
|
107
|
-
const
|
|
149
|
+
const json = transformApiLoaderBundleOutput(
|
|
108
150
|
yield this.verifyAndParseJsonResponse(resp2)
|
|
109
151
|
);
|
|
110
152
|
this.lastResponse = {
|
|
111
|
-
bundle:
|
|
112
|
-
key:
|
|
153
|
+
bundle: json,
|
|
154
|
+
key: nextUrl
|
|
113
155
|
};
|
|
114
|
-
return
|
|
156
|
+
return json;
|
|
115
157
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
158
|
+
let resp;
|
|
159
|
+
try {
|
|
160
|
+
resp = yield this.fetch(url, {
|
|
161
|
+
method: "GET",
|
|
162
|
+
headers: this.makeGetHeaders()
|
|
163
|
+
});
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (isBrowser && allowRouteNotFound && error instanceof TypeError) {
|
|
166
|
+
return BROWSER_FETCH_FAILED;
|
|
167
|
+
}
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
if (allowRouteNotFound && resp.status === 404 && !resp.redirected) {
|
|
171
|
+
return ROUTE_NOT_FOUND;
|
|
172
|
+
}
|
|
173
|
+
return this.handleBundleResponse(resp, host);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
handleBundleResponse(resp, host) {
|
|
177
|
+
return __async(this, null, function* () {
|
|
120
178
|
let json = yield this.verifyAndParseJsonResponse(resp);
|
|
121
179
|
if (json.redirectUrl) {
|
|
122
180
|
const redirectResp = yield this.fetch(`${host}${json.redirectUrl}`, {
|
|
@@ -239,7 +297,8 @@ var PlasmicModulesFetcher = class {
|
|
|
239
297
|
i18nKeyScheme: (_a = this.opts.i18n) == null ? void 0 : _a.keyScheme,
|
|
240
298
|
i18nTagPrefix: (_b = this.opts.i18n) == null ? void 0 : _b.tagPrefix,
|
|
241
299
|
browserOnly: isBrowser,
|
|
242
|
-
skipHead: this.opts.skipHead
|
|
300
|
+
skipHead: this.opts.skipHead,
|
|
301
|
+
minRevs: this.opts.preview ? this.getPreviewMinRevs() : void 0
|
|
243
302
|
}
|
|
244
303
|
);
|
|
245
304
|
if (this.opts.cache) {
|
|
@@ -253,6 +312,22 @@ var PlasmicModulesFetcher = class {
|
|
|
253
312
|
return data;
|
|
254
313
|
});
|
|
255
314
|
}
|
|
315
|
+
getPreviewMinRevs() {
|
|
316
|
+
if (isBrowser) {
|
|
317
|
+
return void 0;
|
|
318
|
+
}
|
|
319
|
+
const known = globalThis.__PLASMIC_PREVIEW_MIN_REVS;
|
|
320
|
+
if (!known) {
|
|
321
|
+
return void 0;
|
|
322
|
+
}
|
|
323
|
+
const minRevs = {};
|
|
324
|
+
for (const { id } of this.opts.projects) {
|
|
325
|
+
if (known[id] !== void 0) {
|
|
326
|
+
minRevs[id] = known[id];
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return Object.keys(minRevs).length > 0 ? minRevs : void 0;
|
|
330
|
+
}
|
|
256
331
|
cacheBundleInNodeServer(bundle) {
|
|
257
332
|
if (isBrowser) {
|
|
258
333
|
return;
|
|
@@ -297,9 +372,22 @@ function getBundleKey({
|
|
|
297
372
|
skipHead
|
|
298
373
|
});
|
|
299
374
|
}
|
|
375
|
+
function internal_setPreviewMinRev(projectId, revisionNum) {
|
|
376
|
+
var _a;
|
|
377
|
+
if (isBrowser || !Number.isFinite(revisionNum)) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const global = globalThis;
|
|
381
|
+
if (global.__PLASMIC_PREVIEW_MIN_REVS === void 0) {
|
|
382
|
+
global.__PLASMIC_PREVIEW_MIN_REVS = {};
|
|
383
|
+
}
|
|
384
|
+
const known = global.__PLASMIC_PREVIEW_MIN_REVS;
|
|
385
|
+
known[projectId] = Math.max((_a = known[projectId]) != null ? _a : revisionNum, revisionNum);
|
|
386
|
+
}
|
|
300
387
|
export {
|
|
301
388
|
Api,
|
|
302
389
|
PlasmicModulesFetcher,
|
|
303
|
-
internal_getCachedBundleInNodeServer
|
|
390
|
+
internal_getCachedBundleInNodeServer,
|
|
391
|
+
internal_setPreviewMinRev
|
|
304
392
|
};
|
|
305
393
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/api.ts", "../src/fetcher.ts"],
|
|
4
|
-
"sourcesContent": ["import type { AssetModule, CodeModule } from \"./runtime-types\";\n\nexport type { AssetModule, CodeModule };\n\nexport interface ComponentMeta {\n id: string;\n usedComponents: string[];\n projectId: string;\n name: string;\n displayName: string;\n cssFile: string;\n path: string | undefined;\n isPage: boolean;\n plumeType?: string;\n entry: string;\n isCode: boolean;\n isGlobalContextProvider: boolean;\n pageMetadata?: PageMetadata;\n metadata?: Record<string, string>;\n serverQueriesExecFuncFileName?: string;\n}\n\nexport interface PageMeta extends ComponentMeta {\n isPage: true;\n path: string;\n plumeType: never;\n pageMetadata: PageMetadata;\n}\n\nexport interface PageMetadata {\n path: string;\n title?: string | null;\n description?: string | null;\n openGraphImageUrl?: string | null;\n canonical?: string | null;\n}\n\nexport interface GlobalGroupMeta {\n id: string;\n projectId: string;\n name: string;\n type: string;\n contextFile: string;\n useName: string;\n}\n\n// Keep in sync with platform/wab ProjectMeta\nexport interface ProjectMeta {\n id: string;\n teamId?: string;\n indirect: boolean;\n name: string;\n version: string;\n remoteFonts: FontMeta[];\n hasStyleTokenOverrides: boolean;\n styleTokensProviderFileName: string;\n globalContextsProviderFileName: string;\n}\n\nexport interface FontMeta {\n url: string;\n}\n\ninterface GlobalVariantSplitContent {\n type: \"global-variant\";\n projectId: string;\n group: string;\n variant: string;\n}\n\ninterface Slice {\n id: string;\n contents: GlobalVariantSplitContent[];\n externalId?: string;\n}\n\nexport interface ExperimentSlice extends Slice {\n prob: number;\n}\n\nexport interface SegmentSlice extends Slice {\n cond: any;\n}\n\ninterface BareSplit {\n id: string;\n projectId: string;\n name: string;\n externalId?: string;\n description?: string;\n pagesPaths: string[];\n}\n\nexport interface ExperimentSplit extends BareSplit {\n type: \"experiment\";\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit extends BareSplit {\n type: \"segment\";\n slices: SegmentSlice[];\n}\n\nexport type Split = ExperimentSplit | SegmentSplit;\n\ninterface ApiLoaderBundleOutput {\n modules: {\n browser: (CodeModule | AssetModule)[];\n server: (CodeModule | AssetModule)[];\n };\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\n bundleKey: string | null;\n deferChunksByDefault: boolean;\n disableRootLoadingBoundaryByDefault: boolean;\n redirectUrl?: string;\n}\n\nexport interface LoaderBundleOutput extends ApiLoaderBundleOutput {\n // A map from project ID to the list of component IDs that are not included in the bundle\n // this is used to know which components exist in the project, which allow us to properly\n // handle bundle merging being aware of the deleted components.\n filteredIds: Record<string, string[]>;\n}\n\nconst VERSION = \"10\";\n\nexport const isBrowser =\n typeof window !== \"undefined\" &&\n window != null &&\n typeof window.document !== \"undefined\";\n\nexport function transformApiLoaderBundleOutput(\n bundle: ApiLoaderBundleOutput,\n): LoaderBundleOutput {\n return {\n ...bundle,\n filteredIds: Object.fromEntries(bundle.projects.map((p) => [p.id, []])),\n };\n}\n\nexport class Api {\n private readonly apiHost: string;\n private readonly cdnHost: string;\n private fetch: typeof globalThis.fetch;\n\n private lastResponse:\n | {\n bundle: LoaderBundleOutput;\n key: string;\n }\n | undefined = undefined;\n\n constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n apiHost?: string;\n cdnHost?: string;\n /** @deprecated No-op. Native fetch is always used now. */\n nativeFetch?: boolean;\n manualRedirect?: boolean;\n },\n ) {\n this.apiHost =\n opts.apiHost ?? opts.host ?? \"https://codegen-origin.plasmic.app\";\n this.cdnHost = opts.cdnHost ?? opts.host ?? \"https://codegen.plasmic.app\";\n this.fetch = globalThis.fetch.bind(globalThis);\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: \"react\" | \"nextjs\" | \"gatsby\";\n platformOptions?: {\n nextjs?: {\n appDir: boolean;\n };\n };\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: \"content\" | \"hash\" | \"path\";\n i18nTagPrefix?: string;\n skipHead?: boolean;\n },\n ): Promise<LoaderBundleOutput> {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n [\"platform\", platform ?? \"react\"],\n ...(opts.platformOptions?.nextjs?.appDir\n ? [[\"nextjsAppDir\", \"true\"]]\n : []),\n ...projectIds.map((projectId) => [\"projectId\", projectId]),\n ...(opts.browserOnly ? [[\"browserOnly\", \"true\"]] : []),\n ...(opts.i18nKeyScheme ? [[\"i18nKeyScheme\", opts.i18nKeyScheme]] : []),\n ...(opts.i18nTagPrefix ? [[\"i18nTagPrefix\", opts.i18nTagPrefix]] : []),\n ...(opts.skipHead ? [[\"skipHead\", \"true\"]] : []),\n ]).toString();\n\n const host = preview ? this.apiHost : this.cdnHost;\n const url = preview\n ? `${host}/api/v1/loader/code/preview?${query}`\n : `${host}/api/v1/loader/code/published?${query}`;\n\n // We only expect a redirect when we're dealing with published mode, as there should be\n // a stable set of versions to be used. As in browser, we could receive a opaque response\n // with a redirect, we don't try to use last response in browser.\n const useLastReponse =\n // We consider that manualRedirect is true by default, only by setting it to false\n // we disable it.\n !(this.opts.manualRedirect === false) && !preview && !isBrowser;\n\n if (useLastReponse) {\n const redirectResp = await this.fetch(url, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n redirect: \"manual\",\n });\n\n if (redirectResp.status !== 301 && redirectResp.status !== 302) {\n const error = await this.parseJsonResponse(redirectResp);\n throw new Error(\n `Error fetching loader data, a redirect was expected: ${\n error?.error?.message ?? redirectResp.statusText\n }`,\n );\n }\n\n const nextLocation = redirectResp.headers.get(\"location\");\n if (!nextLocation) {\n throw new Error(\n `Error fetching loader data, a redirect was expected but no location header was found`,\n );\n }\n\n if (this.lastResponse?.key === nextLocation) {\n return this.lastResponse.bundle;\n }\n\n const resp = await this.fetch(`${host}${nextLocation}`, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n\n const json = transformApiLoaderBundleOutput(\n await this.verifyAndParseJsonResponse(resp),\n );\n this.lastResponse = {\n bundle: json,\n key: nextLocation,\n };\n\n return json;\n }\n\n const resp = await this.fetch(url, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n\n let json = await this.verifyAndParseJsonResponse(resp);\n\n // An Angular polyfill can cause 302 redirects to fail in Safari, due to missing headers.\n // This 200 response with `redirectUrl` is a workaround for specific projects that need it.\n if (json.redirectUrl) {\n const redirectResp = await this.fetch(`${host}${json.redirectUrl}`, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n json = await this.verifyAndParseJsonResponse(redirectResp);\n }\n\n return transformApiLoaderBundleOutput(json);\n }\n\n private async verifyAndParseJsonResponse(\n resp: Response,\n errorText = \"Error fetching loader data\",\n ) {\n if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `${errorText}: ${error?.error?.message ?? resp.statusText}`,\n );\n }\n return (await this.parseJsonResponse(resp)) as ApiLoaderBundleOutput;\n }\n\n private async parseJsonResponse(resp: Response) {\n const text = await resp.text();\n try {\n return JSON.parse(text);\n } catch (err) {\n throw new Error(\n `Error parsing JSON response: ${err}; status: ${resp.status}; response: ${text}`,\n );\n }\n }\n\n private makeGetHeaders() {\n return {\n \"x-plasmic-loader-version\": VERSION,\n ...this.makeAuthHeaders(),\n };\n }\n\n private makeAuthHeaders() {\n // CDN caches key loader responses on this header, so serialize projects in\n // a canonical order: callers listing the same projects in a different\n // order then share cache entries. The sort is stable, so duplicate IDs keep\n // their relative order.\n const tokens = [...this.opts.projects]\n .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))\n .map((p) => `${p.id}:${p.token}`)\n .join(\",\");\n return {\n \"x-plasmic-api-project-tokens\": tokens,\n };\n }\n\n getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]) {\n return `${this.cdnHost}/api/v1/loader/chunks?bundleKey=${encodeURIComponent(\n bundle.bundleKey ?? \"null\",\n )}&fileName=${encodeURIComponent(\n modules\n .map((m) => m.fileName)\n .sort()\n .join(\",\"),\n )}`;\n }\n}\n", "import { Api, CodeModule, isBrowser, LoaderBundleOutput } from \"./api\";\n\nexport interface FetcherOptions {\n projects: {\n id: string;\n version?: string;\n token: string;\n }[];\n cache?: LoaderBundleCache;\n platform?: \"react\" | \"nextjs\" | \"gatsby\";\n platformOptions?: {\n nextjs?: {\n appDir: boolean;\n };\n };\n preview?: boolean;\n /** Fallback for apiHost and cdnHost. */\n host?: string;\n /** Used for fetching/previewing unpublished content. */\n apiHost?: string;\n /** Used for fetching published content. */\n cdnHost?: string;\n i18n?: {\n keyScheme: \"content\" | \"hash\" | \"path\";\n tagPrefix?: string;\n };\n skipHead?: boolean;\n /** @deprecated No-op. Native fetch is always used now. */\n nativeFetch?: boolean;\n manualRedirect?: boolean;\n}\n\nexport interface LoaderBundleCache {\n set: (data: LoaderBundleOutput) => Promise<void>;\n get: () => Promise<LoaderBundleOutput>;\n}\n\nexport class PlasmicModulesFetcher {\n private api: Api;\n private curFetch: Promise<LoaderBundleOutput> | undefined = undefined;\n constructor(private opts: FetcherOptions) {\n this.api = new Api({\n projects: opts.projects,\n host: opts.host,\n apiHost: opts.apiHost,\n cdnHost: opts.cdnHost,\n nativeFetch: opts.nativeFetch,\n manualRedirect: opts.manualRedirect,\n });\n }\n\n getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]) {\n return this.api.getChunksUrl(bundle, modules);\n }\n\n async fetchAllData() {\n // getCachedOrFetched uses a cache defined by the user.\n const bundle = await this.getCachedOrFetch();\n\n // For React Server Components (Next.js 13+),\n // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.\n // We don't want to pass them via normal page props because that will be serialized to the browser.\n // Instead, we pass the bundle (including the server modules) via the Node `global` variable.\n //\n // cacheBundleInNodeServer caches a bundle in the Node server process.\n this.cacheBundleInNodeServer(bundle);\n\n return bundle;\n }\n\n private async getCachedOrFetch() {\n if (this.opts.cache) {\n const cachedData = await this.opts.cache.get();\n if (cachedData) {\n return cachedData;\n }\n }\n if (this.curFetch) {\n return await this.curFetch;\n }\n if (typeof process === \"undefined\" || !process.env?.PLASMIC_QUIET) {\n console.debug(\"Plasmic: doing a fresh fetch...\");\n }\n const fetchPromise = this.doFetch();\n this.curFetch = fetchPromise;\n try {\n const data = await fetchPromise;\n return data;\n } finally {\n // Reset this.curFetch only if it still holds the original fetch promise\n if (this.curFetch === fetchPromise) {\n this.curFetch = undefined;\n }\n }\n }\n\n private async doFetch() {\n const data = await this.api.fetchLoaderData(\n this.opts.projects.map((p) =>\n p.version ? `${p.id}@${p.version}` : p.id\n ),\n {\n platform: this.opts.platform,\n platformOptions: this.opts.platformOptions,\n preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18n?.keyScheme,\n i18nTagPrefix: this.opts.i18n?.tagPrefix,\n browserOnly: isBrowser,\n skipHead: this.opts.skipHead,\n }\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n if (typeof process === \"undefined\" || !process.env?.PLASMIC_QUIET) {\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(\", \")}`\n );\n }\n return data;\n }\n\n private cacheBundleInNodeServer(bundle: LoaderBundleOutput) {\n if (isBrowser) {\n return;\n }\n\n const global = globalThis as GlobalWithBundles;\n if (global.__PLASMIC_BUNDLES === undefined) {\n global.__PLASMIC_BUNDLES = {};\n }\n global.__PLASMIC_BUNDLES[getBundleKey(this.opts)] = bundle;\n }\n}\n\nexport function internal_getCachedBundleInNodeServer(\n opts: FetcherOptions\n): LoaderBundleOutput | undefined {\n if (isBrowser) {\n throw new Error(`Should not be consulting Node server cache in browser`);\n }\n\n const global = globalThis as GlobalWithBundles;\n return global.__PLASMIC_BUNDLES?.[getBundleKey(opts)];\n}\n\nfunction getBundleKey({\n host,\n apiHost,\n cdnHost,\n platform,\n platformOptions,\n i18n,\n preview,\n projects,\n skipHead,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n apiHost,\n cdnHost,\n platform,\n nextjsAppDir: platformOptions?.nextjs?.appDir,\n i18nKeyScheme: i18n?.keyScheme,\n i18nTagPrefix: i18n?.tagPrefix,\n preview,\n projects,\n skipHead,\n });\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [bundleKey: string]: LoaderBundleOutput };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+HA,IAAM,UAAU;AAET,IAAM,YACX,OAAO,WAAW,eAClB,UAAU,QACV,OAAO,OAAO,aAAa;AAEtB,SAAS,+BACd,QACoB;AACpB,SAAO,iCACF,SADE;AAAA,IAEL,aAAa,OAAO,YAAY,OAAO,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAAA,EACxE;AACF;
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import type { AssetModule, CodeModule } from \"./runtime-types\";\n\nexport type { AssetModule, CodeModule };\n\nexport interface ComponentMeta {\n id: string;\n usedComponents: string[];\n projectId: string;\n name: string;\n displayName: string;\n cssFile: string;\n path: string | undefined;\n isPage: boolean;\n plumeType?: string;\n entry: string;\n isCode: boolean;\n isGlobalContextProvider: boolean;\n pageMetadata?: PageMetadata;\n metadata?: Record<string, string>;\n serverQueriesExecFuncFileName?: string;\n}\n\nexport interface PageMeta extends ComponentMeta {\n isPage: true;\n path: string;\n plumeType: never;\n pageMetadata: PageMetadata;\n}\n\nexport interface PageMetadata {\n path: string;\n title?: string | null;\n description?: string | null;\n openGraphImageUrl?: string | null;\n canonical?: string | null;\n}\n\nexport interface GlobalGroupMeta {\n id: string;\n projectId: string;\n name: string;\n type: string;\n contextFile: string;\n useName: string;\n}\n\n// Keep in sync with platform/wab ProjectMeta\nexport interface ProjectMeta {\n id: string;\n teamId?: string;\n indirect: boolean;\n name: string;\n version: string;\n remoteFonts: FontMeta[];\n hasStyleTokenOverrides: boolean;\n styleTokensProviderFileName: string;\n globalContextsProviderFileName: string;\n}\n\nexport interface FontMeta {\n url: string;\n}\n\ninterface GlobalVariantSplitContent {\n type: \"global-variant\";\n projectId: string;\n group: string;\n variant: string;\n}\n\ninterface Slice {\n id: string;\n contents: GlobalVariantSplitContent[];\n externalId?: string;\n}\n\nexport interface ExperimentSlice extends Slice {\n prob: number;\n}\n\nexport interface SegmentSlice extends Slice {\n cond: any;\n}\n\ninterface BareSplit {\n id: string;\n projectId: string;\n name: string;\n externalId?: string;\n description?: string;\n pagesPaths: string[];\n}\n\nexport interface ExperimentSplit extends BareSplit {\n type: \"experiment\";\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit extends BareSplit {\n type: \"segment\";\n slices: SegmentSlice[];\n}\n\nexport type Split = ExperimentSplit | SegmentSplit;\n\ninterface ApiLoaderBundleOutput {\n modules: {\n browser: (CodeModule | AssetModule)[];\n server: (CodeModule | AssetModule)[];\n };\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\n bundleKey: string | null;\n deferChunksByDefault: boolean;\n disableRootLoadingBoundaryByDefault: boolean;\n redirectUrl?: string;\n}\n\nexport interface LoaderBundleOutput extends ApiLoaderBundleOutput {\n // A map from project ID to the list of component IDs that are not included in the bundle\n // this is used to know which components exist in the project, which allow us to properly\n // handle bundle merging being aware of the deleted components.\n filteredIds: Record<string, string[]>;\n}\n\nconst VERSION = \"10\";\n\nexport const isBrowser =\n typeof window !== \"undefined\" &&\n window != null &&\n typeof window.document !== \"undefined\";\n\nexport function transformApiLoaderBundleOutput(\n bundle: ApiLoaderBundleOutput,\n): LoaderBundleOutput {\n return {\n ...bundle,\n filteredIds: Object.fromEntries(bundle.projects.map((p) => [p.id, []])),\n };\n}\n\nconst DEFAULT_CDN_HOST = \"https://codegen.plasmic.app\";\n\nconst REDIRECT_STATUSES = new Set([301, 302, 307, 308]);\n\nconst BROWSER_FETCH_FAILED = Symbol(\"BROWSER_FETCH_FAILED\");\nconst ROUTE_NOT_FOUND = Symbol(\"ROUTE_NOT_FOUND\");\n\nexport class Api {\n private readonly previewHost: string;\n private readonly cdnHost: string;\n private fetch: typeof globalThis.fetch;\n\n private useLegacyPreview = false;\n\n private lastResponse:\n | {\n bundle: LoaderBundleOutput;\n key: string;\n }\n | undefined = undefined;\n\n constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n apiHost?: string;\n cdnHost?: string;\n /** @deprecated No-op. Native fetch is always used now. */\n nativeFetch?: boolean;\n manualRedirect?: boolean;\n },\n ) {\n this.cdnHost = opts.cdnHost ?? opts.host ?? DEFAULT_CDN_HOST;\n this.previewHost = opts.apiHost ?? opts.host ?? this.cdnHost;\n this.fetch = globalThis.fetch.bind(globalThis);\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: \"react\" | \"nextjs\" | \"gatsby\";\n platformOptions?: {\n nextjs?: {\n appDir: boolean;\n };\n };\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: \"content\" | \"hash\" | \"path\";\n i18nTagPrefix?: string;\n skipHead?: boolean;\n /** Watcher revisions bypass cached redirects to older previews. */\n minRevs?: Record<string, number>;\n },\n ): Promise<LoaderBundleOutput> {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n [\"platform\", platform ?? \"react\"],\n ...(opts.platformOptions?.nextjs?.appDir\n ? [[\"nextjsAppDir\", \"true\"]]\n : []),\n ...projectIds.map((projectId) => [\"projectId\", projectId]),\n ...(opts.browserOnly ? [[\"browserOnly\", \"true\"]] : []),\n ...(opts.i18nKeyScheme ? [[\"i18nKeyScheme\", opts.i18nKeyScheme]] : []),\n ...(opts.i18nTagPrefix ? [[\"i18nTagPrefix\", opts.i18nTagPrefix]] : []),\n ...(opts.skipHead ? [[\"skipHead\", \"true\"]] : []),\n ...(preview ? [[\"loaderVersion\", VERSION]] : []),\n ...(preview && opts.minRevs\n ? Object.entries(opts.minRevs)\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n .map(([projectId, rev]) => [\"minRev\", `${projectId}:${rev}`])\n : []),\n ]).toString();\n\n if (!preview) {\n const host = this.cdnHost;\n return this.fetchFromRoute(\n host,\n `${host}/api/v1/loader/code/published?${query}`,\n { preview: false },\n );\n }\n\n const host = this.previewHost;\n const legacyUrl = `${host}/api/v1/loader/code/preview?${query}`;\n if (this.useLegacyPreview) {\n return this.fetchFromRoute(host, legacyUrl, { preview: true });\n }\n const result = await this.fetchFromRoute(\n host,\n `${host}/api/v1/loader/code/revision/latest?${query}`,\n { preview: true, allowRouteNotFound: true },\n );\n if (result !== ROUTE_NOT_FOUND && result !== BROWSER_FETCH_FAILED) {\n return result;\n }\n const bundle = await this.fetchFromRoute(host, legacyUrl, {\n preview: true,\n });\n // A browser network error can be temporary. Only remember a confirmed 404.\n if (result === ROUTE_NOT_FOUND) {\n this.useLegacyPreview = true;\n }\n return bundle;\n }\n\n private async fetchFromRoute(\n host: string,\n url: string,\n opts: { preview: boolean; allowRouteNotFound?: false },\n ): Promise<LoaderBundleOutput>;\n private async fetchFromRoute(\n host: string,\n url: string,\n opts: { preview: boolean; allowRouteNotFound: true },\n ): Promise<\n LoaderBundleOutput | typeof ROUTE_NOT_FOUND | typeof BROWSER_FETCH_FAILED\n >;\n private async fetchFromRoute(\n host: string,\n url: string,\n opts: { preview: boolean; allowRouteNotFound?: boolean },\n ): Promise<\n LoaderBundleOutput | typeof ROUTE_NOT_FOUND | typeof BROWSER_FETCH_FAILED\n > {\n const { preview, allowRouteNotFound } = opts;\n\n // Browsers hide manual redirect targets. Node can reuse the last bundle by URL.\n const useManualRedirect = this.opts.manualRedirect !== false && !isBrowser;\n\n if (useManualRedirect) {\n const redirectResp = await this.fetch(url, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n redirect: \"manual\",\n });\n\n if (allowRouteNotFound && redirectResp.status === 404) {\n return ROUTE_NOT_FOUND;\n }\n\n if (!REDIRECT_STATUSES.has(redirectResp.status)) {\n if (preview) {\n return this.handleBundleResponse(redirectResp, host);\n }\n const error = await this.parseJsonResponse(redirectResp);\n throw new Error(\n `Error fetching loader data, a redirect was expected: ${\n error?.error?.message ?? redirectResp.statusText\n }`,\n );\n }\n\n const location = redirectResp.headers.get(\"location\");\n if (!location) {\n throw new Error(\n `Error fetching loader data, a redirect was expected but no location header was found`,\n );\n }\n\n // Resolve before caching so relative locations are scoped to their host.\n const nextUrl = new URL(location, url).toString();\n if (this.lastResponse?.key === nextUrl) {\n return this.lastResponse.bundle;\n }\n\n const resp = await this.fetch(nextUrl, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n\n const json = transformApiLoaderBundleOutput(\n await this.verifyAndParseJsonResponse(resp),\n );\n this.lastResponse = {\n bundle: json,\n key: nextUrl,\n };\n\n return json;\n }\n\n let resp: Response;\n try {\n resp = await this.fetch(url, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n } catch (error) {\n // Browsers reject fetch with TypeError when an older host omits CORS on its 404.\n if (isBrowser && allowRouteNotFound && error instanceof TypeError) {\n return BROWSER_FETCH_FAILED;\n }\n throw error;\n }\n\n // A followed redirect can return 404 for a missing revision.\n if (allowRouteNotFound && resp.status === 404 && !resp.redirected) {\n return ROUTE_NOT_FOUND;\n }\n\n return this.handleBundleResponse(resp, host);\n }\n\n private async handleBundleResponse(resp: Response, host: string) {\n let json = await this.verifyAndParseJsonResponse(resp);\n\n // An Angular polyfill can cause 302 redirects to fail in Safari, due to missing headers.\n // This 200 response with `redirectUrl` is a workaround for specific projects that need it.\n if (json.redirectUrl) {\n const redirectResp = await this.fetch(`${host}${json.redirectUrl}`, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n json = await this.verifyAndParseJsonResponse(redirectResp);\n }\n\n return transformApiLoaderBundleOutput(json);\n }\n\n private async verifyAndParseJsonResponse(\n resp: Response,\n errorText = \"Error fetching loader data\",\n ) {\n if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `${errorText}: ${error?.error?.message ?? resp.statusText}`,\n );\n }\n return (await this.parseJsonResponse(resp)) as ApiLoaderBundleOutput;\n }\n\n private async parseJsonResponse(resp: Response) {\n const text = await resp.text();\n try {\n return JSON.parse(text);\n } catch (err) {\n throw new Error(\n `Error parsing JSON response: ${err}; status: ${resp.status}; response: ${text}`,\n );\n }\n }\n\n private makeGetHeaders() {\n return {\n \"x-plasmic-loader-version\": VERSION,\n ...this.makeAuthHeaders(),\n };\n }\n\n private makeAuthHeaders() {\n // CDN caches key loader responses on this header, so serialize projects in\n // a canonical order: callers listing the same projects in a different\n // order then share cache entries. The sort is stable, so duplicate IDs keep\n // their relative order.\n const tokens = [...this.opts.projects]\n .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))\n .map((p) => `${p.id}:${p.token}`)\n .join(\",\");\n return {\n \"x-plasmic-api-project-tokens\": tokens,\n };\n }\n\n getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]) {\n return `${this.cdnHost}/api/v1/loader/chunks?bundleKey=${encodeURIComponent(\n bundle.bundleKey ?? \"null\",\n )}&fileName=${encodeURIComponent(\n modules\n .map((m) => m.fileName)\n .sort()\n .join(\",\"),\n )}`;\n }\n}\n", "import { Api, CodeModule, isBrowser, LoaderBundleOutput } from \"./api\";\n\nexport interface FetcherOptions {\n projects: {\n id: string;\n version?: string;\n token: string;\n }[];\n cache?: LoaderBundleCache;\n platform?: \"react\" | \"nextjs\" | \"gatsby\";\n platformOptions?: {\n nextjs?: {\n appDir: boolean;\n };\n };\n preview?: boolean;\n /** Fallback for apiHost and cdnHost. */\n host?: string;\n /** Preview host. Defaults to `host`, then `cdnHost`. */\n apiHost?: string;\n /** Used for fetching published content. */\n cdnHost?: string;\n i18n?: {\n keyScheme: \"content\" | \"hash\" | \"path\";\n tagPrefix?: string;\n };\n skipHead?: boolean;\n /** @deprecated No-op. Native fetch is always used now. */\n nativeFetch?: boolean;\n manualRedirect?: boolean;\n}\n\nexport interface LoaderBundleCache {\n set: (data: LoaderBundleOutput) => Promise<void>;\n get: () => Promise<LoaderBundleOutput>;\n}\n\nexport class PlasmicModulesFetcher {\n private api: Api;\n private curFetch: Promise<LoaderBundleOutput> | undefined = undefined;\n constructor(private opts: FetcherOptions) {\n this.api = new Api({\n projects: opts.projects,\n host: opts.host,\n apiHost: opts.apiHost,\n cdnHost: opts.cdnHost,\n nativeFetch: opts.nativeFetch,\n manualRedirect: opts.manualRedirect,\n });\n }\n\n getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]) {\n return this.api.getChunksUrl(bundle, modules);\n }\n\n async fetchAllData() {\n // getCachedOrFetched uses a cache defined by the user.\n const bundle = await this.getCachedOrFetch();\n\n // For React Server Components (Next.js 13+),\n // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.\n // We don't want to pass them via normal page props because that will be serialized to the browser.\n // Instead, we pass the bundle (including the server modules) via the Node `global` variable.\n //\n // cacheBundleInNodeServer caches a bundle in the Node server process.\n this.cacheBundleInNodeServer(bundle);\n\n return bundle;\n }\n\n private async getCachedOrFetch() {\n if (this.opts.cache) {\n const cachedData = await this.opts.cache.get();\n if (cachedData) {\n return cachedData;\n }\n }\n if (this.curFetch) {\n return await this.curFetch;\n }\n if (typeof process === \"undefined\" || !process.env?.PLASMIC_QUIET) {\n console.debug(\"Plasmic: doing a fresh fetch...\");\n }\n const fetchPromise = this.doFetch();\n this.curFetch = fetchPromise;\n try {\n const data = await fetchPromise;\n return data;\n } finally {\n // Reset this.curFetch only if it still holds the original fetch promise\n if (this.curFetch === fetchPromise) {\n this.curFetch = undefined;\n }\n }\n }\n\n private async doFetch() {\n const data = await this.api.fetchLoaderData(\n this.opts.projects.map((p) =>\n p.version ? `${p.id}@${p.version}` : p.id,\n ),\n {\n platform: this.opts.platform,\n platformOptions: this.opts.platformOptions,\n preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18n?.keyScheme,\n i18nTagPrefix: this.opts.i18n?.tagPrefix,\n browserOnly: isBrowser,\n skipHead: this.opts.skipHead,\n minRevs: this.opts.preview ? this.getPreviewMinRevs() : undefined,\n },\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n if (typeof process === \"undefined\" || !process.env?.PLASMIC_QUIET) {\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(\", \")}`,\n );\n }\n return data;\n }\n\n private getPreviewMinRevs() {\n if (isBrowser) {\n return undefined;\n }\n const known = (globalThis as GlobalWithBundles).__PLASMIC_PREVIEW_MIN_REVS;\n if (!known) {\n return undefined;\n }\n const minRevs: Record<string, number> = {};\n for (const { id } of this.opts.projects) {\n if (known[id] !== undefined) {\n minRevs[id] = known[id];\n }\n }\n return Object.keys(minRevs).length > 0 ? minRevs : undefined;\n }\n\n private cacheBundleInNodeServer(bundle: LoaderBundleOutput) {\n if (isBrowser) {\n return;\n }\n\n const global = globalThis as GlobalWithBundles;\n if (global.__PLASMIC_BUNDLES === undefined) {\n global.__PLASMIC_BUNDLES = {};\n }\n global.__PLASMIC_BUNDLES[getBundleKey(this.opts)] = bundle;\n }\n}\n\nexport function internal_getCachedBundleInNodeServer(\n opts: FetcherOptions,\n): LoaderBundleOutput | undefined {\n if (isBrowser) {\n throw new Error(`Should not be consulting Node server cache in browser`);\n }\n\n const global = globalThis as GlobalWithBundles;\n return global.__PLASMIC_BUNDLES?.[getBundleKey(opts)];\n}\n\nfunction getBundleKey({\n host,\n apiHost,\n cdnHost,\n platform,\n platformOptions,\n i18n,\n preview,\n projects,\n skipHead,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n apiHost,\n cdnHost,\n platform,\n nextjsAppDir: platformOptions?.nextjs?.appDir,\n i18nKeyScheme: i18n?.keyScheme,\n i18nTagPrefix: i18n?.tagPrefix,\n preview,\n projects,\n skipHead,\n });\n}\n\n/** Share watcher revisions across Next.js server and RSC bundles in the same process. */\nexport function internal_setPreviewMinRev(\n projectId: string,\n revisionNum: number,\n) {\n if (isBrowser || !Number.isFinite(revisionNum)) {\n return;\n }\n const global = globalThis as GlobalWithBundles;\n if (global.__PLASMIC_PREVIEW_MIN_REVS === undefined) {\n global.__PLASMIC_PREVIEW_MIN_REVS = {};\n }\n const known = global.__PLASMIC_PREVIEW_MIN_REVS;\n known[projectId] = Math.max(known[projectId] ?? revisionNum, revisionNum);\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [bundleKey: string]: LoaderBundleOutput };\n __PLASMIC_PREVIEW_MIN_REVS?: { [projectId: string]: number };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+HA,IAAM,UAAU;AAET,IAAM,YACX,OAAO,WAAW,eAClB,UAAU,QACV,OAAO,OAAO,aAAa;AAEtB,SAAS,+BACd,QACoB;AACpB,SAAO,iCACF,SADE;AAAA,IAEL,aAAa,OAAO,YAAY,OAAO,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CA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7
|
}
|
package/dist/index.js
CHANGED
|
@@ -60,7 +60,8 @@ var index_exports = {};
|
|
|
60
60
|
__export(index_exports, {
|
|
61
61
|
Api: () => Api,
|
|
62
62
|
PlasmicModulesFetcher: () => PlasmicModulesFetcher,
|
|
63
|
-
internal_getCachedBundleInNodeServer: () => internal_getCachedBundleInNodeServer
|
|
63
|
+
internal_getCachedBundleInNodeServer: () => internal_getCachedBundleInNodeServer,
|
|
64
|
+
internal_setPreviewMinRev: () => internal_setPreviewMinRev
|
|
64
65
|
});
|
|
65
66
|
module.exports = __toCommonJS(index_exports);
|
|
66
67
|
|
|
@@ -72,21 +73,26 @@ function transformApiLoaderBundleOutput(bundle) {
|
|
|
72
73
|
filteredIds: Object.fromEntries(bundle.projects.map((p) => [p.id, []]))
|
|
73
74
|
});
|
|
74
75
|
}
|
|
76
|
+
var DEFAULT_CDN_HOST = "https://codegen.plasmic.app";
|
|
77
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 307, 308]);
|
|
78
|
+
var BROWSER_FETCH_FAILED = /* @__PURE__ */ Symbol("BROWSER_FETCH_FAILED");
|
|
79
|
+
var ROUTE_NOT_FOUND = /* @__PURE__ */ Symbol("ROUTE_NOT_FOUND");
|
|
75
80
|
var Api = class {
|
|
76
81
|
constructor(opts) {
|
|
77
82
|
__publicField(this, "opts", opts);
|
|
78
|
-
__publicField(this, "
|
|
83
|
+
__publicField(this, "previewHost");
|
|
79
84
|
__publicField(this, "cdnHost");
|
|
80
85
|
__publicField(this, "fetch");
|
|
86
|
+
__publicField(this, "useLegacyPreview", false);
|
|
81
87
|
__publicField(this, "lastResponse");
|
|
82
88
|
var _a, _b, _c, _d;
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
89
|
+
this.cdnHost = (_b = (_a = opts.cdnHost) != null ? _a : opts.host) != null ? _b : DEFAULT_CDN_HOST;
|
|
90
|
+
this.previewHost = (_d = (_c = opts.apiHost) != null ? _c : opts.host) != null ? _d : this.cdnHost;
|
|
85
91
|
this.fetch = globalThis.fetch.bind(globalThis);
|
|
86
92
|
}
|
|
87
93
|
fetchLoaderData(projectIds, opts) {
|
|
88
94
|
return __async(this, null, function* () {
|
|
89
|
-
var _a, _b
|
|
95
|
+
var _a, _b;
|
|
90
96
|
const { platform, preview } = opts;
|
|
91
97
|
const query = new URLSearchParams([
|
|
92
98
|
["platform", platform != null ? platform : "react"],
|
|
@@ -95,53 +101,106 @@ var Api = class {
|
|
|
95
101
|
...opts.browserOnly ? [["browserOnly", "true"]] : [],
|
|
96
102
|
...opts.i18nKeyScheme ? [["i18nKeyScheme", opts.i18nKeyScheme]] : [],
|
|
97
103
|
...opts.i18nTagPrefix ? [["i18nTagPrefix", opts.i18nTagPrefix]] : [],
|
|
98
|
-
...opts.skipHead ? [["skipHead", "true"]] : []
|
|
104
|
+
...opts.skipHead ? [["skipHead", "true"]] : [],
|
|
105
|
+
...preview ? [["loaderVersion", VERSION]] : [],
|
|
106
|
+
...preview && opts.minRevs ? Object.entries(opts.minRevs).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([projectId, rev]) => ["minRev", `${projectId}:${rev}`]) : []
|
|
99
107
|
]).toString();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
if (!preview) {
|
|
109
|
+
const host2 = this.cdnHost;
|
|
110
|
+
return this.fetchFromRoute(
|
|
111
|
+
host2,
|
|
112
|
+
`${host2}/api/v1/loader/code/published?${query}`,
|
|
113
|
+
{ preview: false }
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
const host = this.previewHost;
|
|
117
|
+
const legacyUrl = `${host}/api/v1/loader/code/preview?${query}`;
|
|
118
|
+
if (this.useLegacyPreview) {
|
|
119
|
+
return this.fetchFromRoute(host, legacyUrl, { preview: true });
|
|
120
|
+
}
|
|
121
|
+
const result = yield this.fetchFromRoute(
|
|
122
|
+
host,
|
|
123
|
+
`${host}/api/v1/loader/code/revision/latest?${query}`,
|
|
124
|
+
{ preview: true, allowRouteNotFound: true }
|
|
106
125
|
);
|
|
107
|
-
if (
|
|
126
|
+
if (result !== ROUTE_NOT_FOUND && result !== BROWSER_FETCH_FAILED) {
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
const bundle = yield this.fetchFromRoute(host, legacyUrl, {
|
|
130
|
+
preview: true
|
|
131
|
+
});
|
|
132
|
+
if (result === ROUTE_NOT_FOUND) {
|
|
133
|
+
this.useLegacyPreview = true;
|
|
134
|
+
}
|
|
135
|
+
return bundle;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
fetchFromRoute(host, url, opts) {
|
|
139
|
+
return __async(this, null, function* () {
|
|
140
|
+
var _a, _b, _c;
|
|
141
|
+
const { preview, allowRouteNotFound } = opts;
|
|
142
|
+
const useManualRedirect = this.opts.manualRedirect !== false && !isBrowser;
|
|
143
|
+
if (useManualRedirect) {
|
|
108
144
|
const redirectResp = yield this.fetch(url, {
|
|
109
145
|
method: "GET",
|
|
110
146
|
headers: this.makeGetHeaders(),
|
|
111
147
|
redirect: "manual"
|
|
112
148
|
});
|
|
113
|
-
if (
|
|
149
|
+
if (allowRouteNotFound && redirectResp.status === 404) {
|
|
150
|
+
return ROUTE_NOT_FOUND;
|
|
151
|
+
}
|
|
152
|
+
if (!REDIRECT_STATUSES.has(redirectResp.status)) {
|
|
153
|
+
if (preview) {
|
|
154
|
+
return this.handleBundleResponse(redirectResp, host);
|
|
155
|
+
}
|
|
114
156
|
const error = yield this.parseJsonResponse(redirectResp);
|
|
115
157
|
throw new Error(
|
|
116
|
-
`Error fetching loader data, a redirect was expected: ${(
|
|
158
|
+
`Error fetching loader data, a redirect was expected: ${(_b = (_a = error == null ? void 0 : error.error) == null ? void 0 : _a.message) != null ? _b : redirectResp.statusText}`
|
|
117
159
|
);
|
|
118
160
|
}
|
|
119
|
-
const
|
|
120
|
-
if (!
|
|
161
|
+
const location = redirectResp.headers.get("location");
|
|
162
|
+
if (!location) {
|
|
121
163
|
throw new Error(
|
|
122
164
|
`Error fetching loader data, a redirect was expected but no location header was found`
|
|
123
165
|
);
|
|
124
166
|
}
|
|
125
|
-
|
|
167
|
+
const nextUrl = new URL(location, url).toString();
|
|
168
|
+
if (((_c = this.lastResponse) == null ? void 0 : _c.key) === nextUrl) {
|
|
126
169
|
return this.lastResponse.bundle;
|
|
127
170
|
}
|
|
128
|
-
const resp2 = yield this.fetch(
|
|
171
|
+
const resp2 = yield this.fetch(nextUrl, {
|
|
129
172
|
method: "GET",
|
|
130
173
|
headers: this.makeGetHeaders()
|
|
131
174
|
});
|
|
132
|
-
const
|
|
175
|
+
const json = transformApiLoaderBundleOutput(
|
|
133
176
|
yield this.verifyAndParseJsonResponse(resp2)
|
|
134
177
|
);
|
|
135
178
|
this.lastResponse = {
|
|
136
|
-
bundle:
|
|
137
|
-
key:
|
|
179
|
+
bundle: json,
|
|
180
|
+
key: nextUrl
|
|
138
181
|
};
|
|
139
|
-
return
|
|
182
|
+
return json;
|
|
140
183
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
184
|
+
let resp;
|
|
185
|
+
try {
|
|
186
|
+
resp = yield this.fetch(url, {
|
|
187
|
+
method: "GET",
|
|
188
|
+
headers: this.makeGetHeaders()
|
|
189
|
+
});
|
|
190
|
+
} catch (error) {
|
|
191
|
+
if (isBrowser && allowRouteNotFound && error instanceof TypeError) {
|
|
192
|
+
return BROWSER_FETCH_FAILED;
|
|
193
|
+
}
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
if (allowRouteNotFound && resp.status === 404 && !resp.redirected) {
|
|
197
|
+
return ROUTE_NOT_FOUND;
|
|
198
|
+
}
|
|
199
|
+
return this.handleBundleResponse(resp, host);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
handleBundleResponse(resp, host) {
|
|
203
|
+
return __async(this, null, function* () {
|
|
145
204
|
let json = yield this.verifyAndParseJsonResponse(resp);
|
|
146
205
|
if (json.redirectUrl) {
|
|
147
206
|
const redirectResp = yield this.fetch(`${host}${json.redirectUrl}`, {
|
|
@@ -264,7 +323,8 @@ var PlasmicModulesFetcher = class {
|
|
|
264
323
|
i18nKeyScheme: (_a = this.opts.i18n) == null ? void 0 : _a.keyScheme,
|
|
265
324
|
i18nTagPrefix: (_b = this.opts.i18n) == null ? void 0 : _b.tagPrefix,
|
|
266
325
|
browserOnly: isBrowser,
|
|
267
|
-
skipHead: this.opts.skipHead
|
|
326
|
+
skipHead: this.opts.skipHead,
|
|
327
|
+
minRevs: this.opts.preview ? this.getPreviewMinRevs() : void 0
|
|
268
328
|
}
|
|
269
329
|
);
|
|
270
330
|
if (this.opts.cache) {
|
|
@@ -278,6 +338,22 @@ var PlasmicModulesFetcher = class {
|
|
|
278
338
|
return data;
|
|
279
339
|
});
|
|
280
340
|
}
|
|
341
|
+
getPreviewMinRevs() {
|
|
342
|
+
if (isBrowser) {
|
|
343
|
+
return void 0;
|
|
344
|
+
}
|
|
345
|
+
const known = globalThis.__PLASMIC_PREVIEW_MIN_REVS;
|
|
346
|
+
if (!known) {
|
|
347
|
+
return void 0;
|
|
348
|
+
}
|
|
349
|
+
const minRevs = {};
|
|
350
|
+
for (const { id } of this.opts.projects) {
|
|
351
|
+
if (known[id] !== void 0) {
|
|
352
|
+
minRevs[id] = known[id];
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return Object.keys(minRevs).length > 0 ? minRevs : void 0;
|
|
356
|
+
}
|
|
281
357
|
cacheBundleInNodeServer(bundle) {
|
|
282
358
|
if (isBrowser) {
|
|
283
359
|
return;
|
|
@@ -322,4 +398,16 @@ function getBundleKey({
|
|
|
322
398
|
skipHead
|
|
323
399
|
});
|
|
324
400
|
}
|
|
401
|
+
function internal_setPreviewMinRev(projectId, revisionNum) {
|
|
402
|
+
var _a;
|
|
403
|
+
if (isBrowser || !Number.isFinite(revisionNum)) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const global = globalThis;
|
|
407
|
+
if (global.__PLASMIC_PREVIEW_MIN_REVS === void 0) {
|
|
408
|
+
global.__PLASMIC_PREVIEW_MIN_REVS = {};
|
|
409
|
+
}
|
|
410
|
+
const known = global.__PLASMIC_PREVIEW_MIN_REVS;
|
|
411
|
+
known[projectId] = Math.max((_a = known[projectId]) != null ? _a : revisionNum, revisionNum);
|
|
412
|
+
}
|
|
325
413
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/api.ts", "../src/fetcher.ts"],
|
|
4
|
-
"sourcesContent": ["export { Api } from \"./api\";\nexport type {\n AssetModule,\n CodeModule,\n ComponentMeta,\n ExperimentSlice,\n FontMeta,\n GlobalGroupMeta,\n LoaderBundleOutput,\n PageMeta,\n PageMetadata,\n ProjectMeta,\n SegmentSlice,\n Split,\n} from \"./api\";\nexport {\n PlasmicModulesFetcher,\n internal_getCachedBundleInNodeServer,\n} from \"./fetcher\";\nexport type { FetcherOptions, LoaderBundleCache } from \"./fetcher\";\n", "import type { AssetModule, CodeModule } from \"./runtime-types\";\n\nexport type { AssetModule, CodeModule };\n\nexport interface ComponentMeta {\n id: string;\n usedComponents: string[];\n projectId: string;\n name: string;\n displayName: string;\n cssFile: string;\n path: string | undefined;\n isPage: boolean;\n plumeType?: string;\n entry: string;\n isCode: boolean;\n isGlobalContextProvider: boolean;\n pageMetadata?: PageMetadata;\n metadata?: Record<string, string>;\n serverQueriesExecFuncFileName?: string;\n}\n\nexport interface PageMeta extends ComponentMeta {\n isPage: true;\n path: string;\n plumeType: never;\n pageMetadata: PageMetadata;\n}\n\nexport interface PageMetadata {\n path: string;\n title?: string | null;\n description?: string | null;\n openGraphImageUrl?: string | null;\n canonical?: string | null;\n}\n\nexport interface GlobalGroupMeta {\n id: string;\n projectId: string;\n name: string;\n type: string;\n contextFile: string;\n useName: string;\n}\n\n// Keep in sync with platform/wab ProjectMeta\nexport interface ProjectMeta {\n id: string;\n teamId?: string;\n indirect: boolean;\n name: string;\n version: string;\n remoteFonts: FontMeta[];\n hasStyleTokenOverrides: boolean;\n styleTokensProviderFileName: string;\n globalContextsProviderFileName: string;\n}\n\nexport interface FontMeta {\n url: string;\n}\n\ninterface GlobalVariantSplitContent {\n type: \"global-variant\";\n projectId: string;\n group: string;\n variant: string;\n}\n\ninterface Slice {\n id: string;\n contents: GlobalVariantSplitContent[];\n externalId?: string;\n}\n\nexport interface ExperimentSlice extends Slice {\n prob: number;\n}\n\nexport interface SegmentSlice extends Slice {\n cond: any;\n}\n\ninterface BareSplit {\n id: string;\n projectId: string;\n name: string;\n externalId?: string;\n description?: string;\n pagesPaths: string[];\n}\n\nexport interface ExperimentSplit extends BareSplit {\n type: \"experiment\";\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit extends BareSplit {\n type: \"segment\";\n slices: SegmentSlice[];\n}\n\nexport type Split = ExperimentSplit | SegmentSplit;\n\ninterface ApiLoaderBundleOutput {\n modules: {\n browser: (CodeModule | AssetModule)[];\n server: (CodeModule | AssetModule)[];\n };\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\n bundleKey: string | null;\n deferChunksByDefault: boolean;\n disableRootLoadingBoundaryByDefault: boolean;\n redirectUrl?: string;\n}\n\nexport interface LoaderBundleOutput extends ApiLoaderBundleOutput {\n // A map from project ID to the list of component IDs that are not included in the bundle\n // this is used to know which components exist in the project, which allow us to properly\n // handle bundle merging being aware of the deleted components.\n filteredIds: Record<string, string[]>;\n}\n\nconst VERSION = \"10\";\n\nexport const isBrowser =\n typeof window !== \"undefined\" &&\n window != null &&\n typeof window.document !== \"undefined\";\n\nexport function transformApiLoaderBundleOutput(\n bundle: ApiLoaderBundleOutput,\n): LoaderBundleOutput {\n return {\n ...bundle,\n filteredIds: Object.fromEntries(bundle.projects.map((p) => [p.id, []])),\n };\n}\n\nexport class Api {\n private readonly apiHost: string;\n private readonly cdnHost: string;\n private fetch: typeof globalThis.fetch;\n\n private lastResponse:\n | {\n bundle: LoaderBundleOutput;\n key: string;\n }\n | undefined = undefined;\n\n constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n apiHost?: string;\n cdnHost?: string;\n /** @deprecated No-op. Native fetch is always used now. */\n nativeFetch?: boolean;\n manualRedirect?: boolean;\n },\n ) {\n this.apiHost =\n opts.apiHost ?? opts.host ?? \"https://codegen-origin.plasmic.app\";\n this.cdnHost = opts.cdnHost ?? opts.host ?? \"https://codegen.plasmic.app\";\n this.fetch = globalThis.fetch.bind(globalThis);\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: \"react\" | \"nextjs\" | \"gatsby\";\n platformOptions?: {\n nextjs?: {\n appDir: boolean;\n };\n };\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: \"content\" | \"hash\" | \"path\";\n i18nTagPrefix?: string;\n skipHead?: boolean;\n },\n ): Promise<LoaderBundleOutput> {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n [\"platform\", platform ?? \"react\"],\n ...(opts.platformOptions?.nextjs?.appDir\n ? [[\"nextjsAppDir\", \"true\"]]\n : []),\n ...projectIds.map((projectId) => [\"projectId\", projectId]),\n ...(opts.browserOnly ? [[\"browserOnly\", \"true\"]] : []),\n ...(opts.i18nKeyScheme ? [[\"i18nKeyScheme\", opts.i18nKeyScheme]] : []),\n ...(opts.i18nTagPrefix ? [[\"i18nTagPrefix\", opts.i18nTagPrefix]] : []),\n ...(opts.skipHead ? [[\"skipHead\", \"true\"]] : []),\n ]).toString();\n\n const host = preview ? this.apiHost : this.cdnHost;\n const url = preview\n ? `${host}/api/v1/loader/code/preview?${query}`\n : `${host}/api/v1/loader/code/published?${query}`;\n\n // We only expect a redirect when we're dealing with published mode, as there should be\n // a stable set of versions to be used. As in browser, we could receive a opaque response\n // with a redirect, we don't try to use last response in browser.\n const useLastReponse =\n // We consider that manualRedirect is true by default, only by setting it to false\n // we disable it.\n !(this.opts.manualRedirect === false) && !preview && !isBrowser;\n\n if (useLastReponse) {\n const redirectResp = await this.fetch(url, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n redirect: \"manual\",\n });\n\n if (redirectResp.status !== 301 && redirectResp.status !== 302) {\n const error = await this.parseJsonResponse(redirectResp);\n throw new Error(\n `Error fetching loader data, a redirect was expected: ${\n error?.error?.message ?? redirectResp.statusText\n }`,\n );\n }\n\n const nextLocation = redirectResp.headers.get(\"location\");\n if (!nextLocation) {\n throw new Error(\n `Error fetching loader data, a redirect was expected but no location header was found`,\n );\n }\n\n if (this.lastResponse?.key === nextLocation) {\n return this.lastResponse.bundle;\n }\n\n const resp = await this.fetch(`${host}${nextLocation}`, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n\n const json = transformApiLoaderBundleOutput(\n await this.verifyAndParseJsonResponse(resp),\n );\n this.lastResponse = {\n bundle: json,\n key: nextLocation,\n };\n\n return json;\n }\n\n const resp = await this.fetch(url, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n\n let json = await this.verifyAndParseJsonResponse(resp);\n\n // An Angular polyfill can cause 302 redirects to fail in Safari, due to missing headers.\n // This 200 response with `redirectUrl` is a workaround for specific projects that need it.\n if (json.redirectUrl) {\n const redirectResp = await this.fetch(`${host}${json.redirectUrl}`, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n json = await this.verifyAndParseJsonResponse(redirectResp);\n }\n\n return transformApiLoaderBundleOutput(json);\n }\n\n private async verifyAndParseJsonResponse(\n resp: Response,\n errorText = \"Error fetching loader data\",\n ) {\n if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `${errorText}: ${error?.error?.message ?? resp.statusText}`,\n );\n }\n return (await this.parseJsonResponse(resp)) as ApiLoaderBundleOutput;\n }\n\n private async parseJsonResponse(resp: Response) {\n const text = await resp.text();\n try {\n return JSON.parse(text);\n } catch (err) {\n throw new Error(\n `Error parsing JSON response: ${err}; status: ${resp.status}; response: ${text}`,\n );\n }\n }\n\n private makeGetHeaders() {\n return {\n \"x-plasmic-loader-version\": VERSION,\n ...this.makeAuthHeaders(),\n };\n }\n\n private makeAuthHeaders() {\n // CDN caches key loader responses on this header, so serialize projects in\n // a canonical order: callers listing the same projects in a different\n // order then share cache entries. The sort is stable, so duplicate IDs keep\n // their relative order.\n const tokens = [...this.opts.projects]\n .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))\n .map((p) => `${p.id}:${p.token}`)\n .join(\",\");\n return {\n \"x-plasmic-api-project-tokens\": tokens,\n };\n }\n\n getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]) {\n return `${this.cdnHost}/api/v1/loader/chunks?bundleKey=${encodeURIComponent(\n bundle.bundleKey ?? \"null\",\n )}&fileName=${encodeURIComponent(\n modules\n .map((m) => m.fileName)\n .sort()\n .join(\",\"),\n )}`;\n }\n}\n", "import { Api, CodeModule, isBrowser, LoaderBundleOutput } from \"./api\";\n\nexport interface FetcherOptions {\n projects: {\n id: string;\n version?: string;\n token: string;\n }[];\n cache?: LoaderBundleCache;\n platform?: \"react\" | \"nextjs\" | \"gatsby\";\n platformOptions?: {\n nextjs?: {\n appDir: boolean;\n };\n };\n preview?: boolean;\n /** Fallback for apiHost and cdnHost. */\n host?: string;\n /** Used for fetching/previewing unpublished content. */\n apiHost?: string;\n /** Used for fetching published content. */\n cdnHost?: string;\n i18n?: {\n keyScheme: \"content\" | \"hash\" | \"path\";\n tagPrefix?: string;\n };\n skipHead?: boolean;\n /** @deprecated No-op. Native fetch is always used now. */\n nativeFetch?: boolean;\n manualRedirect?: boolean;\n}\n\nexport interface LoaderBundleCache {\n set: (data: LoaderBundleOutput) => Promise<void>;\n get: () => Promise<LoaderBundleOutput>;\n}\n\nexport class PlasmicModulesFetcher {\n private api: Api;\n private curFetch: Promise<LoaderBundleOutput> | undefined = undefined;\n constructor(private opts: FetcherOptions) {\n this.api = new Api({\n projects: opts.projects,\n host: opts.host,\n apiHost: opts.apiHost,\n cdnHost: opts.cdnHost,\n nativeFetch: opts.nativeFetch,\n manualRedirect: opts.manualRedirect,\n });\n }\n\n getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]) {\n return this.api.getChunksUrl(bundle, modules);\n }\n\n async fetchAllData() {\n // getCachedOrFetched uses a cache defined by the user.\n const bundle = await this.getCachedOrFetch();\n\n // For React Server Components (Next.js 13+),\n // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.\n // We don't want to pass them via normal page props because that will be serialized to the browser.\n // Instead, we pass the bundle (including the server modules) via the Node `global` variable.\n //\n // cacheBundleInNodeServer caches a bundle in the Node server process.\n this.cacheBundleInNodeServer(bundle);\n\n return bundle;\n }\n\n private async getCachedOrFetch() {\n if (this.opts.cache) {\n const cachedData = await this.opts.cache.get();\n if (cachedData) {\n return cachedData;\n }\n }\n if (this.curFetch) {\n return await this.curFetch;\n }\n if (typeof process === \"undefined\" || !process.env?.PLASMIC_QUIET) {\n console.debug(\"Plasmic: doing a fresh fetch...\");\n }\n const fetchPromise = this.doFetch();\n this.curFetch = fetchPromise;\n try {\n const data = await fetchPromise;\n return data;\n } finally {\n // Reset this.curFetch only if it still holds the original fetch promise\n if (this.curFetch === fetchPromise) {\n this.curFetch = undefined;\n }\n }\n }\n\n private async doFetch() {\n const data = await this.api.fetchLoaderData(\n this.opts.projects.map((p) =>\n p.version ? `${p.id}@${p.version}` : p.id\n ),\n {\n platform: this.opts.platform,\n platformOptions: this.opts.platformOptions,\n preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18n?.keyScheme,\n i18nTagPrefix: this.opts.i18n?.tagPrefix,\n browserOnly: isBrowser,\n skipHead: this.opts.skipHead,\n }\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n if (typeof process === \"undefined\" || !process.env?.PLASMIC_QUIET) {\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(\", \")}`\n );\n }\n return data;\n }\n\n private cacheBundleInNodeServer(bundle: LoaderBundleOutput) {\n if (isBrowser) {\n return;\n }\n\n const global = globalThis as GlobalWithBundles;\n if (global.__PLASMIC_BUNDLES === undefined) {\n global.__PLASMIC_BUNDLES = {};\n }\n global.__PLASMIC_BUNDLES[getBundleKey(this.opts)] = bundle;\n }\n}\n\nexport function internal_getCachedBundleInNodeServer(\n opts: FetcherOptions\n): LoaderBundleOutput | undefined {\n if (isBrowser) {\n throw new Error(`Should not be consulting Node server cache in browser`);\n }\n\n const global = globalThis as GlobalWithBundles;\n return global.__PLASMIC_BUNDLES?.[getBundleKey(opts)];\n}\n\nfunction getBundleKey({\n host,\n apiHost,\n cdnHost,\n platform,\n platformOptions,\n i18n,\n preview,\n projects,\n skipHead,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n apiHost,\n cdnHost,\n platform,\n nextjsAppDir: platformOptions?.nextjs?.appDir,\n i18nKeyScheme: i18n?.keyScheme,\n i18nTagPrefix: i18n?.tagPrefix,\n preview,\n projects,\n skipHead,\n });\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [bundleKey: string]: LoaderBundleOutput };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC+HA,IAAM,UAAU;AAET,IAAM,YACX,OAAO,WAAW,eAClB,UAAU,QACV,OAAO,OAAO,aAAa;AAEtB,SAAS,+BACd,QACoB;AACpB,SAAO,iCACF,SADE;AAAA,IAEL,aAAa,OAAO,YAAY,OAAO,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAAA,EACxE;AACF;
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["export { Api } from \"./api\";\nexport type {\n AssetModule,\n CodeModule,\n ComponentMeta,\n ExperimentSlice,\n FontMeta,\n GlobalGroupMeta,\n LoaderBundleOutput,\n PageMeta,\n PageMetadata,\n ProjectMeta,\n SegmentSlice,\n Split,\n} from \"./api\";\nexport {\n PlasmicModulesFetcher,\n internal_getCachedBundleInNodeServer,\n internal_setPreviewMinRev,\n} from \"./fetcher\";\nexport type { FetcherOptions, LoaderBundleCache } from \"./fetcher\";\n", "import type { AssetModule, CodeModule } from \"./runtime-types\";\n\nexport type { AssetModule, CodeModule };\n\nexport interface ComponentMeta {\n id: string;\n usedComponents: string[];\n projectId: string;\n name: string;\n displayName: string;\n cssFile: string;\n path: string | undefined;\n isPage: boolean;\n plumeType?: string;\n entry: string;\n isCode: boolean;\n isGlobalContextProvider: boolean;\n pageMetadata?: PageMetadata;\n metadata?: Record<string, string>;\n serverQueriesExecFuncFileName?: string;\n}\n\nexport interface PageMeta extends ComponentMeta {\n isPage: true;\n path: string;\n plumeType: never;\n pageMetadata: PageMetadata;\n}\n\nexport interface PageMetadata {\n path: string;\n title?: string | null;\n description?: string | null;\n openGraphImageUrl?: string | null;\n canonical?: string | null;\n}\n\nexport interface GlobalGroupMeta {\n id: string;\n projectId: string;\n name: string;\n type: string;\n contextFile: string;\n useName: string;\n}\n\n// Keep in sync with platform/wab ProjectMeta\nexport interface ProjectMeta {\n id: string;\n teamId?: string;\n indirect: boolean;\n name: string;\n version: string;\n remoteFonts: FontMeta[];\n hasStyleTokenOverrides: boolean;\n styleTokensProviderFileName: string;\n globalContextsProviderFileName: string;\n}\n\nexport interface FontMeta {\n url: string;\n}\n\ninterface GlobalVariantSplitContent {\n type: \"global-variant\";\n projectId: string;\n group: string;\n variant: string;\n}\n\ninterface Slice {\n id: string;\n contents: GlobalVariantSplitContent[];\n externalId?: string;\n}\n\nexport interface ExperimentSlice extends Slice {\n prob: number;\n}\n\nexport interface SegmentSlice extends Slice {\n cond: any;\n}\n\ninterface BareSplit {\n id: string;\n projectId: string;\n name: string;\n externalId?: string;\n description?: string;\n pagesPaths: string[];\n}\n\nexport interface ExperimentSplit extends BareSplit {\n type: \"experiment\";\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit extends BareSplit {\n type: \"segment\";\n slices: SegmentSlice[];\n}\n\nexport type Split = ExperimentSplit | SegmentSplit;\n\ninterface ApiLoaderBundleOutput {\n modules: {\n browser: (CodeModule | AssetModule)[];\n server: (CodeModule | AssetModule)[];\n };\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\n bundleKey: string | null;\n deferChunksByDefault: boolean;\n disableRootLoadingBoundaryByDefault: boolean;\n redirectUrl?: string;\n}\n\nexport interface LoaderBundleOutput extends ApiLoaderBundleOutput {\n // A map from project ID to the list of component IDs that are not included in the bundle\n // this is used to know which components exist in the project, which allow us to properly\n // handle bundle merging being aware of the deleted components.\n filteredIds: Record<string, string[]>;\n}\n\nconst VERSION = \"10\";\n\nexport const isBrowser =\n typeof window !== \"undefined\" &&\n window != null &&\n typeof window.document !== \"undefined\";\n\nexport function transformApiLoaderBundleOutput(\n bundle: ApiLoaderBundleOutput,\n): LoaderBundleOutput {\n return {\n ...bundle,\n filteredIds: Object.fromEntries(bundle.projects.map((p) => [p.id, []])),\n };\n}\n\nconst DEFAULT_CDN_HOST = \"https://codegen.plasmic.app\";\n\nconst REDIRECT_STATUSES = new Set([301, 302, 307, 308]);\n\nconst BROWSER_FETCH_FAILED = Symbol(\"BROWSER_FETCH_FAILED\");\nconst ROUTE_NOT_FOUND = Symbol(\"ROUTE_NOT_FOUND\");\n\nexport class Api {\n private readonly previewHost: string;\n private readonly cdnHost: string;\n private fetch: typeof globalThis.fetch;\n\n private useLegacyPreview = false;\n\n private lastResponse:\n | {\n bundle: LoaderBundleOutput;\n key: string;\n }\n | undefined = undefined;\n\n constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n apiHost?: string;\n cdnHost?: string;\n /** @deprecated No-op. Native fetch is always used now. */\n nativeFetch?: boolean;\n manualRedirect?: boolean;\n },\n ) {\n this.cdnHost = opts.cdnHost ?? opts.host ?? DEFAULT_CDN_HOST;\n this.previewHost = opts.apiHost ?? opts.host ?? this.cdnHost;\n this.fetch = globalThis.fetch.bind(globalThis);\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: \"react\" | \"nextjs\" | \"gatsby\";\n platformOptions?: {\n nextjs?: {\n appDir: boolean;\n };\n };\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: \"content\" | \"hash\" | \"path\";\n i18nTagPrefix?: string;\n skipHead?: boolean;\n /** Watcher revisions bypass cached redirects to older previews. */\n minRevs?: Record<string, number>;\n },\n ): Promise<LoaderBundleOutput> {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n [\"platform\", platform ?? \"react\"],\n ...(opts.platformOptions?.nextjs?.appDir\n ? [[\"nextjsAppDir\", \"true\"]]\n : []),\n ...projectIds.map((projectId) => [\"projectId\", projectId]),\n ...(opts.browserOnly ? [[\"browserOnly\", \"true\"]] : []),\n ...(opts.i18nKeyScheme ? [[\"i18nKeyScheme\", opts.i18nKeyScheme]] : []),\n ...(opts.i18nTagPrefix ? [[\"i18nTagPrefix\", opts.i18nTagPrefix]] : []),\n ...(opts.skipHead ? [[\"skipHead\", \"true\"]] : []),\n ...(preview ? [[\"loaderVersion\", VERSION]] : []),\n ...(preview && opts.minRevs\n ? Object.entries(opts.minRevs)\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n .map(([projectId, rev]) => [\"minRev\", `${projectId}:${rev}`])\n : []),\n ]).toString();\n\n if (!preview) {\n const host = this.cdnHost;\n return this.fetchFromRoute(\n host,\n `${host}/api/v1/loader/code/published?${query}`,\n { preview: false },\n );\n }\n\n const host = this.previewHost;\n const legacyUrl = `${host}/api/v1/loader/code/preview?${query}`;\n if (this.useLegacyPreview) {\n return this.fetchFromRoute(host, legacyUrl, { preview: true });\n }\n const result = await this.fetchFromRoute(\n host,\n `${host}/api/v1/loader/code/revision/latest?${query}`,\n { preview: true, allowRouteNotFound: true },\n );\n if (result !== ROUTE_NOT_FOUND && result !== BROWSER_FETCH_FAILED) {\n return result;\n }\n const bundle = await this.fetchFromRoute(host, legacyUrl, {\n preview: true,\n });\n // A browser network error can be temporary. Only remember a confirmed 404.\n if (result === ROUTE_NOT_FOUND) {\n this.useLegacyPreview = true;\n }\n return bundle;\n }\n\n private async fetchFromRoute(\n host: string,\n url: string,\n opts: { preview: boolean; allowRouteNotFound?: false },\n ): Promise<LoaderBundleOutput>;\n private async fetchFromRoute(\n host: string,\n url: string,\n opts: { preview: boolean; allowRouteNotFound: true },\n ): Promise<\n LoaderBundleOutput | typeof ROUTE_NOT_FOUND | typeof BROWSER_FETCH_FAILED\n >;\n private async fetchFromRoute(\n host: string,\n url: string,\n opts: { preview: boolean; allowRouteNotFound?: boolean },\n ): Promise<\n LoaderBundleOutput | typeof ROUTE_NOT_FOUND | typeof BROWSER_FETCH_FAILED\n > {\n const { preview, allowRouteNotFound } = opts;\n\n // Browsers hide manual redirect targets. Node can reuse the last bundle by URL.\n const useManualRedirect = this.opts.manualRedirect !== false && !isBrowser;\n\n if (useManualRedirect) {\n const redirectResp = await this.fetch(url, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n redirect: \"manual\",\n });\n\n if (allowRouteNotFound && redirectResp.status === 404) {\n return ROUTE_NOT_FOUND;\n }\n\n if (!REDIRECT_STATUSES.has(redirectResp.status)) {\n if (preview) {\n return this.handleBundleResponse(redirectResp, host);\n }\n const error = await this.parseJsonResponse(redirectResp);\n throw new Error(\n `Error fetching loader data, a redirect was expected: ${\n error?.error?.message ?? redirectResp.statusText\n }`,\n );\n }\n\n const location = redirectResp.headers.get(\"location\");\n if (!location) {\n throw new Error(\n `Error fetching loader data, a redirect was expected but no location header was found`,\n );\n }\n\n // Resolve before caching so relative locations are scoped to their host.\n const nextUrl = new URL(location, url).toString();\n if (this.lastResponse?.key === nextUrl) {\n return this.lastResponse.bundle;\n }\n\n const resp = await this.fetch(nextUrl, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n\n const json = transformApiLoaderBundleOutput(\n await this.verifyAndParseJsonResponse(resp),\n );\n this.lastResponse = {\n bundle: json,\n key: nextUrl,\n };\n\n return json;\n }\n\n let resp: Response;\n try {\n resp = await this.fetch(url, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n } catch (error) {\n // Browsers reject fetch with TypeError when an older host omits CORS on its 404.\n if (isBrowser && allowRouteNotFound && error instanceof TypeError) {\n return BROWSER_FETCH_FAILED;\n }\n throw error;\n }\n\n // A followed redirect can return 404 for a missing revision.\n if (allowRouteNotFound && resp.status === 404 && !resp.redirected) {\n return ROUTE_NOT_FOUND;\n }\n\n return this.handleBundleResponse(resp, host);\n }\n\n private async handleBundleResponse(resp: Response, host: string) {\n let json = await this.verifyAndParseJsonResponse(resp);\n\n // An Angular polyfill can cause 302 redirects to fail in Safari, due to missing headers.\n // This 200 response with `redirectUrl` is a workaround for specific projects that need it.\n if (json.redirectUrl) {\n const redirectResp = await this.fetch(`${host}${json.redirectUrl}`, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n json = await this.verifyAndParseJsonResponse(redirectResp);\n }\n\n return transformApiLoaderBundleOutput(json);\n }\n\n private async verifyAndParseJsonResponse(\n resp: Response,\n errorText = \"Error fetching loader data\",\n ) {\n if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `${errorText}: ${error?.error?.message ?? resp.statusText}`,\n );\n }\n return (await this.parseJsonResponse(resp)) as ApiLoaderBundleOutput;\n }\n\n private async parseJsonResponse(resp: Response) {\n const text = await resp.text();\n try {\n return JSON.parse(text);\n } catch (err) {\n throw new Error(\n `Error parsing JSON response: ${err}; status: ${resp.status}; response: ${text}`,\n );\n }\n }\n\n private makeGetHeaders() {\n return {\n \"x-plasmic-loader-version\": VERSION,\n ...this.makeAuthHeaders(),\n };\n }\n\n private makeAuthHeaders() {\n // CDN caches key loader responses on this header, so serialize projects in\n // a canonical order: callers listing the same projects in a different\n // order then share cache entries. The sort is stable, so duplicate IDs keep\n // their relative order.\n const tokens = [...this.opts.projects]\n .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))\n .map((p) => `${p.id}:${p.token}`)\n .join(\",\");\n return {\n \"x-plasmic-api-project-tokens\": tokens,\n };\n }\n\n getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]) {\n return `${this.cdnHost}/api/v1/loader/chunks?bundleKey=${encodeURIComponent(\n bundle.bundleKey ?? \"null\",\n )}&fileName=${encodeURIComponent(\n modules\n .map((m) => m.fileName)\n .sort()\n .join(\",\"),\n )}`;\n }\n}\n", "import { Api, CodeModule, isBrowser, LoaderBundleOutput } from \"./api\";\n\nexport interface FetcherOptions {\n projects: {\n id: string;\n version?: string;\n token: string;\n }[];\n cache?: LoaderBundleCache;\n platform?: \"react\" | \"nextjs\" | \"gatsby\";\n platformOptions?: {\n nextjs?: {\n appDir: boolean;\n };\n };\n preview?: boolean;\n /** Fallback for apiHost and cdnHost. */\n host?: string;\n /** Preview host. Defaults to `host`, then `cdnHost`. */\n apiHost?: string;\n /** Used for fetching published content. */\n cdnHost?: string;\n i18n?: {\n keyScheme: \"content\" | \"hash\" | \"path\";\n tagPrefix?: string;\n };\n skipHead?: boolean;\n /** @deprecated No-op. Native fetch is always used now. */\n nativeFetch?: boolean;\n manualRedirect?: boolean;\n}\n\nexport interface LoaderBundleCache {\n set: (data: LoaderBundleOutput) => Promise<void>;\n get: () => Promise<LoaderBundleOutput>;\n}\n\nexport class PlasmicModulesFetcher {\n private api: Api;\n private curFetch: Promise<LoaderBundleOutput> | undefined = undefined;\n constructor(private opts: FetcherOptions) {\n this.api = new Api({\n projects: opts.projects,\n host: opts.host,\n apiHost: opts.apiHost,\n cdnHost: opts.cdnHost,\n nativeFetch: opts.nativeFetch,\n manualRedirect: opts.manualRedirect,\n });\n }\n\n getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]) {\n return this.api.getChunksUrl(bundle, modules);\n }\n\n async fetchAllData() {\n // getCachedOrFetched uses a cache defined by the user.\n const bundle = await this.getCachedOrFetch();\n\n // For React Server Components (Next.js 13+),\n // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.\n // We don't want to pass them via normal page props because that will be serialized to the browser.\n // Instead, we pass the bundle (including the server modules) via the Node `global` variable.\n //\n // cacheBundleInNodeServer caches a bundle in the Node server process.\n this.cacheBundleInNodeServer(bundle);\n\n return bundle;\n }\n\n private async getCachedOrFetch() {\n if (this.opts.cache) {\n const cachedData = await this.opts.cache.get();\n if (cachedData) {\n return cachedData;\n }\n }\n if (this.curFetch) {\n return await this.curFetch;\n }\n if (typeof process === \"undefined\" || !process.env?.PLASMIC_QUIET) {\n console.debug(\"Plasmic: doing a fresh fetch...\");\n }\n const fetchPromise = this.doFetch();\n this.curFetch = fetchPromise;\n try {\n const data = await fetchPromise;\n return data;\n } finally {\n // Reset this.curFetch only if it still holds the original fetch promise\n if (this.curFetch === fetchPromise) {\n this.curFetch = undefined;\n }\n }\n }\n\n private async doFetch() {\n const data = await this.api.fetchLoaderData(\n this.opts.projects.map((p) =>\n p.version ? `${p.id}@${p.version}` : p.id,\n ),\n {\n platform: this.opts.platform,\n platformOptions: this.opts.platformOptions,\n preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18n?.keyScheme,\n i18nTagPrefix: this.opts.i18n?.tagPrefix,\n browserOnly: isBrowser,\n skipHead: this.opts.skipHead,\n minRevs: this.opts.preview ? this.getPreviewMinRevs() : undefined,\n },\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n if (typeof process === \"undefined\" || !process.env?.PLASMIC_QUIET) {\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(\", \")}`,\n );\n }\n return data;\n }\n\n private getPreviewMinRevs() {\n if (isBrowser) {\n return undefined;\n }\n const known = (globalThis as GlobalWithBundles).__PLASMIC_PREVIEW_MIN_REVS;\n if (!known) {\n return undefined;\n }\n const minRevs: Record<string, number> = {};\n for (const { id } of this.opts.projects) {\n if (known[id] !== undefined) {\n minRevs[id] = known[id];\n }\n }\n return Object.keys(minRevs).length > 0 ? minRevs : undefined;\n }\n\n private cacheBundleInNodeServer(bundle: LoaderBundleOutput) {\n if (isBrowser) {\n return;\n }\n\n const global = globalThis as GlobalWithBundles;\n if (global.__PLASMIC_BUNDLES === undefined) {\n global.__PLASMIC_BUNDLES = {};\n }\n global.__PLASMIC_BUNDLES[getBundleKey(this.opts)] = bundle;\n }\n}\n\nexport function internal_getCachedBundleInNodeServer(\n opts: FetcherOptions,\n): LoaderBundleOutput | undefined {\n if (isBrowser) {\n throw new Error(`Should not be consulting Node server cache in browser`);\n }\n\n const global = globalThis as GlobalWithBundles;\n return global.__PLASMIC_BUNDLES?.[getBundleKey(opts)];\n}\n\nfunction getBundleKey({\n host,\n apiHost,\n cdnHost,\n platform,\n platformOptions,\n i18n,\n preview,\n projects,\n skipHead,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n apiHost,\n cdnHost,\n platform,\n nextjsAppDir: platformOptions?.nextjs?.appDir,\n i18nKeyScheme: i18n?.keyScheme,\n i18nTagPrefix: i18n?.tagPrefix,\n preview,\n projects,\n skipHead,\n });\n}\n\n/** Share watcher revisions across Next.js server and RSC bundles in the same process. */\nexport function internal_setPreviewMinRev(\n projectId: string,\n revisionNum: number,\n) {\n if (isBrowser || !Number.isFinite(revisionNum)) {\n return;\n }\n const global = globalThis as GlobalWithBundles;\n if (global.__PLASMIC_PREVIEW_MIN_REVS === undefined) {\n global.__PLASMIC_PREVIEW_MIN_REVS = {};\n }\n const known = global.__PLASMIC_PREVIEW_MIN_REVS;\n known[projectId] = Math.max(known[projectId] ?? revisionNum, revisionNum);\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [bundleKey: string]: LoaderBundleOutput };\n __PLAS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