@plasmicapp/loader-fetcher 1.0.58 → 1.0.60
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 -3
- package/dist/index.esm.js +13 -20
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +13 -20
- package/dist/index.js.map +2 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare class Api {
|
|
2
2
|
private opts;
|
|
3
|
-
private
|
|
3
|
+
private readonly apiHost;
|
|
4
|
+
private readonly cdnHost;
|
|
4
5
|
private fetch;
|
|
5
6
|
private lastResponse;
|
|
6
7
|
constructor(opts: {
|
|
@@ -9,6 +10,8 @@ export declare class Api {
|
|
|
9
10
|
token: string;
|
|
10
11
|
}[];
|
|
11
12
|
host?: string;
|
|
13
|
+
apiHost?: string;
|
|
14
|
+
cdnHost?: string;
|
|
12
15
|
nativeFetch?: boolean;
|
|
13
16
|
manualRedirect?: boolean;
|
|
14
17
|
});
|
|
@@ -27,7 +30,8 @@ export declare class Api {
|
|
|
27
30
|
}): Promise<LoaderBundleOutput>;
|
|
28
31
|
private verifyAndParseJsonResponse;
|
|
29
32
|
private parseJsonResponse;
|
|
30
|
-
|
|
33
|
+
/** @deprecated */
|
|
34
|
+
fetchHtmlData(_opts: {
|
|
31
35
|
projectId: string;
|
|
32
36
|
component: string;
|
|
33
37
|
hydrate?: boolean;
|
|
@@ -91,7 +95,6 @@ export declare interface ComponentMeta {
|
|
|
91
95
|
pageMetadata?: PageMetadata;
|
|
92
96
|
metadata?: Record<string, string>;
|
|
93
97
|
serverQueriesExecFuncFileName?: string;
|
|
94
|
-
generateMetadataFuncFileName?: string;
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
export declare interface ExperimentSlice extends Slice {
|
|
@@ -117,7 +120,12 @@ export declare interface FetcherOptions {
|
|
|
117
120
|
};
|
|
118
121
|
};
|
|
119
122
|
preview?: boolean;
|
|
123
|
+
/** Fallback for apiHost and cdnHost. */
|
|
120
124
|
host?: string;
|
|
125
|
+
/** Used for fetching/previewing unpublished content. */
|
|
126
|
+
apiHost?: string;
|
|
127
|
+
/** Used for fetching published content. */
|
|
128
|
+
cdnHost?: string;
|
|
121
129
|
/**
|
|
122
130
|
* @deprecated use i18n.keyScheme instead
|
|
123
131
|
*/
|
package/dist/index.esm.js
CHANGED
|
@@ -51,8 +51,9 @@ var Api = class {
|
|
|
51
51
|
constructor(opts) {
|
|
52
52
|
this.opts = opts;
|
|
53
53
|
this.lastResponse = void 0;
|
|
54
|
-
var _a;
|
|
55
|
-
this.
|
|
54
|
+
var _a, _b, _c, _d;
|
|
55
|
+
this.apiHost = (_b = (_a = opts.apiHost) != null ? _a : opts.host) != null ? _b : "https://codegen-origin.plasmic.app";
|
|
56
|
+
this.cdnHost = (_d = (_c = opts.cdnHost) != null ? _c : opts.host) != null ? _d : "https://codegen.plasmic.app";
|
|
56
57
|
this.fetch = (opts.nativeFetch && globalThis.fetch ? globalThis.fetch : unfetch).bind(globalThis);
|
|
57
58
|
}
|
|
58
59
|
fetchLoaderData(projectIds, opts) {
|
|
@@ -68,7 +69,8 @@ var Api = class {
|
|
|
68
69
|
...opts.i18nTagPrefix ? [["i18nTagPrefix", opts.i18nTagPrefix]] : [],
|
|
69
70
|
...opts.skipHead ? [["skipHead", "true"]] : []
|
|
70
71
|
]).toString();
|
|
71
|
-
const
|
|
72
|
+
const host = preview ? this.apiHost : this.cdnHost;
|
|
73
|
+
const url = preview ? `${host}/api/v1/loader/code/preview?${query}` : `${host}/api/v1/loader/code/published?${query}`;
|
|
72
74
|
const useLastReponse = (
|
|
73
75
|
// We consider that manualRedirect is true by default, only by setting it to false
|
|
74
76
|
// we disable it.
|
|
@@ -95,7 +97,7 @@ var Api = class {
|
|
|
95
97
|
if (((_e = this.lastResponse) == null ? void 0 : _e.key) === nextLocation) {
|
|
96
98
|
return this.lastResponse.bundle;
|
|
97
99
|
}
|
|
98
|
-
const resp2 = yield this.fetch(`${
|
|
100
|
+
const resp2 = yield this.fetch(`${host}${nextLocation}`, {
|
|
99
101
|
method: "GET",
|
|
100
102
|
headers: this.makeGetHeaders()
|
|
101
103
|
});
|
|
@@ -114,7 +116,7 @@ var Api = class {
|
|
|
114
116
|
});
|
|
115
117
|
let json = yield this.verifyAndParseJsonResponse(resp);
|
|
116
118
|
if (json.redirectUrl) {
|
|
117
|
-
const redirectResp = yield this.fetch(`${
|
|
119
|
+
const redirectResp = yield this.fetch(`${host}${json.redirectUrl}`, {
|
|
118
120
|
method: "GET",
|
|
119
121
|
headers: this.makeGetHeaders()
|
|
120
122
|
});
|
|
@@ -147,21 +149,10 @@ var Api = class {
|
|
|
147
149
|
}
|
|
148
150
|
});
|
|
149
151
|
}
|
|
150
|
-
|
|
152
|
+
/** @deprecated */
|
|
153
|
+
fetchHtmlData(_opts) {
|
|
151
154
|
return __async(this, null, function* () {
|
|
152
|
-
|
|
153
|
-
const query = new URLSearchParams([
|
|
154
|
-
["projectId", projectId],
|
|
155
|
-
["component", component],
|
|
156
|
-
["embedHydrate", embedHydrate ? "1" : "0"],
|
|
157
|
-
["hydrate", hydrate ? "1" : "0"]
|
|
158
|
-
]).toString();
|
|
159
|
-
const resp = yield this.fetch(`${this.host}/api/v1/loader/html?${query}`, {
|
|
160
|
-
method: "GET",
|
|
161
|
-
headers: this.makeGetHeaders()
|
|
162
|
-
});
|
|
163
|
-
const json = yield resp.json();
|
|
164
|
-
return json;
|
|
155
|
+
throw new Error("deprecated");
|
|
165
156
|
});
|
|
166
157
|
}
|
|
167
158
|
makeGetHeaders() {
|
|
@@ -177,7 +168,7 @@ var Api = class {
|
|
|
177
168
|
}
|
|
178
169
|
getChunksUrl(bundle, modules) {
|
|
179
170
|
var _a;
|
|
180
|
-
return `${this.
|
|
171
|
+
return `${this.cdnHost}/api/v1/loader/chunks?bundleKey=${encodeURIComponent(
|
|
181
172
|
(_a = bundle.bundleKey) != null ? _a : "null"
|
|
182
173
|
)}&fileName=${encodeURIComponent(
|
|
183
174
|
modules.map((m) => m.fileName).sort().join(",")
|
|
@@ -193,6 +184,8 @@ var PlasmicModulesFetcher = class {
|
|
|
193
184
|
this.api = new Api({
|
|
194
185
|
projects: opts.projects,
|
|
195
186
|
host: opts.host,
|
|
187
|
+
apiHost: opts.apiHost,
|
|
188
|
+
cdnHost: opts.cdnHost,
|
|
196
189
|
nativeFetch: opts.nativeFetch,
|
|
197
190
|
manualRedirect: opts.manualRedirect
|
|
198
191
|
});
|
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 unfetch from \"@plasmicapp/isomorphic-unfetch\";\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 generateMetadataFuncFileName?: 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\nexport interface LoaderHtmlOutput {\n html: string;\n}\n\nexport interface CodeModule {\n fileName: string;\n code: string;\n imports: string[];\n type: \"code\";\n}\n\nexport interface AssetModule {\n fileName: string;\n source: string;\n type: \"asset\";\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 host: 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 nativeFetch?: boolean;\n manualRedirect?: boolean;\n }\n ) {\n this.host = opts.host ?? \"https://codegen.plasmic.app\";\n this.fetch = (\n opts.nativeFetch && globalThis.fetch ? globalThis.fetch : unfetch\n ).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 url = `${this.host}/api/v1/loader/code/${\n preview ? \"preview\" : \"published\"\n }?${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(`${this.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(`${this.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 async fetchHtmlData(opts: {\n projectId: string;\n component: string;\n hydrate?: boolean;\n embedHydrate?: boolean;\n }) {\n const { projectId, component, embedHydrate, hydrate } = opts;\n const query = new URLSearchParams([\n [\"projectId\", projectId],\n [\"component\", component],\n [\"embedHydrate\", embedHydrate ? \"1\" : \"0\"],\n [\"hydrate\", hydrate ? \"1\" : \"0\"],\n ]).toString();\n const resp = await this.fetch(`${this.host}/api/v1/loader/html?${query}`, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n const json = await resp.json();\n return json as LoaderHtmlOutput;\n }\n\n private makeGetHeaders() {\n return {\n \"x-plasmic-loader-version\": VERSION,\n ...this.makeAuthHeaders(),\n };\n }\n\n private makeAuthHeaders() {\n const tokens = this.opts.projects\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.host}/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 host?: string;\n /**\n * @deprecated use i18n.keyScheme instead\n */\n i18nKeyScheme?: \"content\" | \"hash\" | \"path\";\n i18n?: {\n keyScheme: \"content\" | \"hash\" | \"path\";\n tagPrefix?: string;\n };\n skipHead?: boolean;\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 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 ?? this.opts.i18nKeyScheme,\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 platform,\n i18nKeyScheme,\n preview,\n projects,\n skipHead,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n platform,\n i18nKeyScheme,\n preview,\n projects,\n skipHead,\n });\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [bundleKey: string]: LoaderBundleOutput };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,aAAa;
|
|
4
|
+
"sourcesContent": ["import unfetch from \"@plasmicapp/isomorphic-unfetch\";\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\nexport interface LoaderHtmlOutput {\n html: string;\n}\n\nexport interface CodeModule {\n fileName: string;\n code: string;\n imports: string[];\n type: \"code\";\n}\n\nexport interface AssetModule {\n fileName: string;\n source: string;\n type: \"asset\";\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 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 = (\n opts.nativeFetch && globalThis.fetch ? globalThis.fetch : unfetch\n ).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 /** @deprecated */\n async fetchHtmlData(_opts: {\n projectId: string;\n component: string;\n hydrate?: boolean;\n embedHydrate?: boolean;\n }): Promise<LoaderHtmlOutput> {\n throw new Error(\"deprecated\");\n }\n\n private makeGetHeaders() {\n return {\n \"x-plasmic-loader-version\": VERSION,\n ...this.makeAuthHeaders(),\n };\n }\n\n private makeAuthHeaders() {\n const tokens = this.opts.projects\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 /**\n * @deprecated use i18n.keyScheme instead\n */\n i18nKeyScheme?: \"content\" | \"hash\" | \"path\";\n i18n?: {\n keyScheme: \"content\" | \"hash\" | \"path\";\n tagPrefix?: string;\n };\n skipHead?: boolean;\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 ?? this.opts.i18nKeyScheme,\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 platform,\n i18nKeyScheme,\n preview,\n projects,\n skipHead,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n platform,\n i18nKeyScheme,\n preview,\n projects,\n skipHead,\n });\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [bundleKey: string]: LoaderBundleOutput };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,aAAa;AA8IpB,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;AAEO,IAAM,MAAN,MAAU;AAAA,EAYf,YACU,MAQR;AARQ;AARV,SAAQ,eAKQ;AAxKlB;AAoLI,SAAK,WACH,gBAAK,YAAL,YAAgB,KA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AK,KAAK,MAAM,IAAI,IAAI;AAAA,MAChC;AACA,UAAI,OAAO,YAAY,eAAe,GAAC,aAAQ,QAAR,mBAAa,gBAAe;AACjE,gBAAQ;AAAA,UACN,gCAAgC,KAAK,SAClC,IAAI,CAAC,MAAM,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAC/C,KAAK,IAAI;AAAA,QACd;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA;AAAA,EAEQ,wBAAwB,QAA4B;AAC1D,QAAI,WAAW;AACb;AAAA,IACF;AAEA,UAAM,SAAS;AACf,QAAI,OAAO,sBAAsB,QAAW;AAC1C,aAAO,oBAAoB,CAAC;AAAA,IAC9B;AACA,WAAO,kBAAkB,aAAa,KAAK,IAAI,CAAC,IAAI;AAAA,EACtD;AACF;AAEO,SAAS,qCACd,MACgC;AA9IlC;AA+IE,MAAI,WAAW;AACb,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,QAAM,SAAS;AACf,UAAO,YAAO,sBAAP,mBAA2B,aAAa,IAAI;AACrD;AAEA,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmB;AACjB,SAAO,KAAK,UAAU;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": ["resp", "json"]
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -86,8 +86,9 @@ var Api = class {
|
|
|
86
86
|
constructor(opts) {
|
|
87
87
|
this.opts = opts;
|
|
88
88
|
this.lastResponse = void 0;
|
|
89
|
-
var _a;
|
|
90
|
-
this.
|
|
89
|
+
var _a, _b, _c, _d;
|
|
90
|
+
this.apiHost = (_b = (_a = opts.apiHost) != null ? _a : opts.host) != null ? _b : "https://codegen-origin.plasmic.app";
|
|
91
|
+
this.cdnHost = (_d = (_c = opts.cdnHost) != null ? _c : opts.host) != null ? _d : "https://codegen.plasmic.app";
|
|
91
92
|
this.fetch = (opts.nativeFetch && globalThis.fetch ? globalThis.fetch : import_isomorphic_unfetch.default).bind(globalThis);
|
|
92
93
|
}
|
|
93
94
|
fetchLoaderData(projectIds, opts) {
|
|
@@ -103,7 +104,8 @@ var Api = class {
|
|
|
103
104
|
...opts.i18nTagPrefix ? [["i18nTagPrefix", opts.i18nTagPrefix]] : [],
|
|
104
105
|
...opts.skipHead ? [["skipHead", "true"]] : []
|
|
105
106
|
]).toString();
|
|
106
|
-
const
|
|
107
|
+
const host = preview ? this.apiHost : this.cdnHost;
|
|
108
|
+
const url = preview ? `${host}/api/v1/loader/code/preview?${query}` : `${host}/api/v1/loader/code/published?${query}`;
|
|
107
109
|
const useLastReponse = (
|
|
108
110
|
// We consider that manualRedirect is true by default, only by setting it to false
|
|
109
111
|
// we disable it.
|
|
@@ -130,7 +132,7 @@ var Api = class {
|
|
|
130
132
|
if (((_e = this.lastResponse) == null ? void 0 : _e.key) === nextLocation) {
|
|
131
133
|
return this.lastResponse.bundle;
|
|
132
134
|
}
|
|
133
|
-
const resp2 = yield this.fetch(`${
|
|
135
|
+
const resp2 = yield this.fetch(`${host}${nextLocation}`, {
|
|
134
136
|
method: "GET",
|
|
135
137
|
headers: this.makeGetHeaders()
|
|
136
138
|
});
|
|
@@ -149,7 +151,7 @@ var Api = class {
|
|
|
149
151
|
});
|
|
150
152
|
let json = yield this.verifyAndParseJsonResponse(resp);
|
|
151
153
|
if (json.redirectUrl) {
|
|
152
|
-
const redirectResp = yield this.fetch(`${
|
|
154
|
+
const redirectResp = yield this.fetch(`${host}${json.redirectUrl}`, {
|
|
153
155
|
method: "GET",
|
|
154
156
|
headers: this.makeGetHeaders()
|
|
155
157
|
});
|
|
@@ -182,21 +184,10 @@ var Api = class {
|
|
|
182
184
|
}
|
|
183
185
|
});
|
|
184
186
|
}
|
|
185
|
-
|
|
187
|
+
/** @deprecated */
|
|
188
|
+
fetchHtmlData(_opts) {
|
|
186
189
|
return __async(this, null, function* () {
|
|
187
|
-
|
|
188
|
-
const query = new URLSearchParams([
|
|
189
|
-
["projectId", projectId],
|
|
190
|
-
["component", component],
|
|
191
|
-
["embedHydrate", embedHydrate ? "1" : "0"],
|
|
192
|
-
["hydrate", hydrate ? "1" : "0"]
|
|
193
|
-
]).toString();
|
|
194
|
-
const resp = yield this.fetch(`${this.host}/api/v1/loader/html?${query}`, {
|
|
195
|
-
method: "GET",
|
|
196
|
-
headers: this.makeGetHeaders()
|
|
197
|
-
});
|
|
198
|
-
const json = yield resp.json();
|
|
199
|
-
return json;
|
|
190
|
+
throw new Error("deprecated");
|
|
200
191
|
});
|
|
201
192
|
}
|
|
202
193
|
makeGetHeaders() {
|
|
@@ -212,7 +203,7 @@ var Api = class {
|
|
|
212
203
|
}
|
|
213
204
|
getChunksUrl(bundle, modules) {
|
|
214
205
|
var _a;
|
|
215
|
-
return `${this.
|
|
206
|
+
return `${this.cdnHost}/api/v1/loader/chunks?bundleKey=${encodeURIComponent(
|
|
216
207
|
(_a = bundle.bundleKey) != null ? _a : "null"
|
|
217
208
|
)}&fileName=${encodeURIComponent(
|
|
218
209
|
modules.map((m) => m.fileName).sort().join(",")
|
|
@@ -228,6 +219,8 @@ var PlasmicModulesFetcher = class {
|
|
|
228
219
|
this.api = new Api({
|
|
229
220
|
projects: opts.projects,
|
|
230
221
|
host: opts.host,
|
|
222
|
+
apiHost: opts.apiHost,
|
|
223
|
+
cdnHost: opts.cdnHost,
|
|
231
224
|
nativeFetch: opts.nativeFetch,
|
|
232
225
|
manualRedirect: opts.manualRedirect
|
|
233
226
|
});
|
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 type {\n AssetModule,\n CodeModule,\n ComponentMeta,\n ExperimentSlice,\n FontMeta,\n GlobalGroupMeta,\n LoaderBundleOutput,\n LoaderHtmlOutput,\n PageMeta,\n PageMetadata,\n ProjectMeta,\n SegmentSlice,\n Split,\n} from \"./api\";\nexport { Api } from \"./api\";\nexport type { FetcherOptions, LoaderBundleCache } from \"./fetcher\";\nexport {\n internal_getCachedBundleInNodeServer,\n PlasmicModulesFetcher,\n} from \"./fetcher\";\n", "import unfetch from \"@plasmicapp/isomorphic-unfetch\";\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 generateMetadataFuncFileName?: 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\nexport interface LoaderHtmlOutput {\n html: string;\n}\n\nexport interface CodeModule {\n fileName: string;\n code: string;\n imports: string[];\n type: \"code\";\n}\n\nexport interface AssetModule {\n fileName: string;\n source: string;\n type: \"asset\";\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 host: 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 nativeFetch?: boolean;\n manualRedirect?: boolean;\n }\n ) {\n this.host = opts.host ?? \"https://codegen.plasmic.app\";\n this.fetch = (\n opts.nativeFetch && globalThis.fetch ? globalThis.fetch : unfetch\n ).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 url = `${this.host}/api/v1/loader/code/${\n preview ? \"preview\" : \"published\"\n }?${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(`${this.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(`${this.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 async fetchHtmlData(opts: {\n projectId: string;\n component: string;\n hydrate?: boolean;\n embedHydrate?: boolean;\n }) {\n const { projectId, component, embedHydrate, hydrate } = opts;\n const query = new URLSearchParams([\n [\"projectId\", projectId],\n [\"component\", component],\n [\"embedHydrate\", embedHydrate ? \"1\" : \"0\"],\n [\"hydrate\", hydrate ? \"1\" : \"0\"],\n ]).toString();\n const resp = await this.fetch(`${this.host}/api/v1/loader/html?${query}`, {\n method: \"GET\",\n headers: this.makeGetHeaders(),\n });\n const json = await resp.json();\n return json as LoaderHtmlOutput;\n }\n\n private makeGetHeaders() {\n return {\n \"x-plasmic-loader-version\": VERSION,\n ...this.makeAuthHeaders(),\n };\n }\n\n private makeAuthHeaders() {\n const tokens = this.opts.projects\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.host}/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 host?: string;\n /**\n * @deprecated use i18n.keyScheme instead\n */\n i18nKeyScheme?: \"content\" | \"hash\" | \"path\";\n i18n?: {\n keyScheme: \"content\" | \"hash\" | \"path\";\n tagPrefix?: string;\n };\n skipHead?: boolean;\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 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 ?? this.opts.i18nKeyScheme,\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 platform,\n i18nKeyScheme,\n preview,\n projects,\n skipHead,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n platform,\n i18nKeyScheme,\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;;;ACAA,gCAAoB;
|
|
4
|
+
"sourcesContent": ["export type {\n AssetModule,\n CodeModule,\n ComponentMeta,\n ExperimentSlice,\n FontMeta,\n GlobalGroupMeta,\n LoaderBundleOutput,\n LoaderHtmlOutput,\n PageMeta,\n PageMetadata,\n ProjectMeta,\n SegmentSlice,\n Split,\n} from \"./api\";\nexport { Api } from \"./api\";\nexport type { FetcherOptions, LoaderBundleCache } from \"./fetcher\";\nexport {\n internal_getCachedBundleInNodeServer,\n PlasmicModulesFetcher,\n} from \"./fetcher\";\n", "import unfetch from \"@plasmicapp/isomorphic-unfetch\";\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\nexport interface LoaderHtmlOutput {\n html: string;\n}\n\nexport interface CodeModule {\n fileName: string;\n code: string;\n imports: string[];\n type: \"code\";\n}\n\nexport interface AssetModule {\n fileName: string;\n source: string;\n type: \"asset\";\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 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 = (\n opts.nativeFetch && globalThis.fetch ? globalThis.fetch : unfetch\n ).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 /** @deprecated */\n async fetchHtmlData(_opts: {\n projectId: string;\n component: string;\n hydrate?: boolean;\n embedHydrate?: boolean;\n }): Promise<LoaderHtmlOutput> {\n throw new Error(\"deprecated\");\n }\n\n private makeGetHeaders() {\n return {\n \"x-plasmic-loader-version\": VERSION,\n ...this.makeAuthHeaders(),\n };\n }\n\n private makeAuthHeaders() {\n const tokens = this.opts.projects\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 /**\n * @deprecated use i18n.keyScheme instead\n */\n i18nKeyScheme?: \"content\" | \"hash\" | \"path\";\n i18n?: {\n keyScheme: \"content\" | \"hash\" | \"path\";\n tagPrefix?: string;\n };\n skipHead?: boolean;\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 ?? this.opts.i18nKeyScheme,\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 platform,\n i18nKeyScheme,\n preview,\n projects,\n skipHead,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n platform,\n i18nKeyScheme,\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;;;ACAA,gCAAoB;AA8IpB,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,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license": "MIT",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/index.js",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "39fee33309bd526e7347a21890fffe646aca074b"
|
|
51
51
|
}
|