@plasmicapp/loader-fetcher 2.0.12 → 2.0.13
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.esm.js +2 -1
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -177,7 +177,8 @@ var Api = class {
|
|
|
177
177
|
return __async(this, null, function* () {
|
|
178
178
|
let json = yield this.verifyAndParseJsonResponse(resp);
|
|
179
179
|
if (json.redirectUrl) {
|
|
180
|
-
const
|
|
180
|
+
const url = json.redirectUrl.startsWith("/") ? host + json.redirectUrl : json.redirectUrl;
|
|
181
|
+
const redirectResp = yield this.fetch(url, {
|
|
181
182
|
method: "GET",
|
|
182
183
|
headers: this.makeGetHeaders()
|
|
183
184
|
});
|
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\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,CAAC;AAAA,EACxE;AACF;AAEA,IAAM,mBAAmB;AAEzB,IAAM,oBAAoB,oBAAI,IAAI,CAAC,KAAK,KAAK,KAAK,GAAG,CAAC;AAEtD,IAAM,uBAAuB,uBAAO,sBAAsB;AAC1D,IAAM,kBAAkB,uBAAO,iBAAiB;AAEzC,IAAM,MAAN,MAAU;AAAA,EAcf,YACU,MASR;AATQ;AAdV,wBAAiB;AACjB,wBAAiB;AACjB,wBAAQ;AAER,wBAAQ,oBAAmB;AAE3B,wBAAQ;AA7JV;AA+KI,SAAK,WAAU,gBAAK,YAAL,YAAgB,KAAK,SAArB,YAA6B;AAC5C,SAAK,eAAc,gBAAK,YAAL,YAAgB,KAAK,SAArB,YAA6B,KAAK;AACrD,SAAK,QAAQ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,YACR;AAAA,UACF;AAAA,QACF;AAGA,cAAM,UAAU,IAAI,IAAI,UAAU,GAAG,EAAE,SAAS;AAChD,cAAI,UAAK,iBAAL,mBAAmB,SAAQ,SAAS;AACtC,iBAAO,KAAK,aAAa;AAAA,QAC3B;AAEA,cAAMC,QAAO,MAAM,KAAK,MAAM,SAAS;AAAA,UACrC,QAAQ;AAAA,UACR,SAAS,KAAK,eAAe;AAAA,QAC/B,CAAC;AAED,cAAM,OAAO;AAAA,UACX,MAAM,KAAK,2BAA2BA,KAAI;AAAA,QAC5C;AACA,aAAK,eAAe;AAAA,UAClB,QAAQ;AAAA,UACR,KAAK;AAAA,QACP;AAEA,eAAO;AAAA,MACT;AAEA,UAAI;AACJ,UAAI;AACF,eAAO,MAAM,KAAK,MAAM,KAAK;AAAA,UAC3B,QAAQ;AAAA,UACR,SAAS,KAAK,eAAe;AAAA,QAC/B,CAAC;AAAA,MACH,SAAS,OAAO;AAEd,YAAI,aAAa,sBAAsB,iBAAiB,WAAW;AACjE,iBAAO;AAAA,QACT;AACA,cAAM;AAAA,MACR;AAGA,UAAI,sBAAsB,KAAK,WAAW,OAAO,CAAC,KAAK,YAAY;AACjE,eAAO;AAAA,MACT;AAEA,aAAO,KAAK,qBAAqB,MAAM,IAAI;AAAA,IAC7C;AAAA;AAAA,EAEc,qBAAqB,MAAgB,MAAc;AAAA;AAC/D,UAAI,OAAO,MAAM,KAAK,2BAA2B,IAAI;AAIrD,UAAI,KAAK,aAAa;AACpB,cAAM,
|
|
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 url = json.redirectUrl.startsWith(\"/\")\n ? host + json.redirectUrl\n : json.redirectUrl;\n const redirectResp = await this.fetch(url, {\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,CAAC;AAAA,EACxE;AACF;AAEA,IAAM,mBAAmB;AAEzB,IAAM,oBAAoB,oBAAI,IAAI,CAAC,KAAK,KAAK,KAAK,GAAG,CAAC;AAEtD,IAAM,uBAAuB,uBAAO,sBAAsB;AAC1D,IAAM,kBAAkB,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EAAE,SAAS,IAAI,UAAU;AAAA,EACrD;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;AA7JlC;AA8JE,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;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmB;AAhLnB;AAiLE,SAAO,KAAK,UAAU;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAc,wDAAiB,WAAjB,mBAAyB;AAAA,IACvC,eAAe,6BAAM;AAAA,IACrB,eAAe,6BAAM;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAGO,SAAS,0BACd,WACA,aACA;AAnMF;AAoME,MAAI,aAAa,CAAC,OAAO,SAAS,WAAW,GAAG;AAC9C;AAAA,EACF;AACA,QAAM,SAAS;AACf,MAAI,OAAO,+BAA+B,QAAW;AACnD,WAAO,6BAA6B,CAAC;AAAA,EACvC;AACA,QAAM,QAAQ,OAAO;AACrB,QAAM,SAAS,IAAI,KAAK,KAAI,WAAM,SAAS,MAAf,YAAoB,aAAa,WAAW;AAC1E;",
|
|
6
6
|
"names": ["host", "resp"]
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -203,7 +203,8 @@ var Api = class {
|
|
|
203
203
|
return __async(this, null, function* () {
|
|
204
204
|
let json = yield this.verifyAndParseJsonResponse(resp);
|
|
205
205
|
if (json.redirectUrl) {
|
|
206
|
-
const
|
|
206
|
+
const url = json.redirectUrl.startsWith("/") ? host + json.redirectUrl : json.redirectUrl;
|
|
207
|
+
const redirectResp = yield this.fetch(url, {
|
|
207
208
|
method: "GET",
|
|
208
209
|
headers: this.makeGetHeaders()
|
|
209
210
|
});
|
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 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 __PLASMIC_PREVIEW_MIN_REVS?: { [projectId: string]: number };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;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;AAEA,IAAM,mBAAmB;AAEzB,IAAM,oBAAoB,oBAAI,IAAI,CAAC,KAAK,KAAK,KAAK,GAAG,CAAC;AAEtD,IAAM,uBAAuB,uBAAO,sBAAsB;AAC1D,IAAM,kBAAkB,uBAAO,iBAAiB;AAEzC,IAAM,MAAN,MAAU;AAAA,EAcf,YACU,MASR;AATQ;AAdV,wBAAiB;AACjB,wBAAiB;AACjB,wBAAQ;AAER,wBAAQ,oBAAmB;AAE3B,wBAAQ;AA7JV;AA+KI,SAAK,WAAU,gBAAK,YAAL,YAAgB,KAAK,SAArB,YAA6B;AAC5C,SAAK,eAAc,gBAAK,YAAL,YAAgB,KAAK,SAAr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AC,UAAU;AACb,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAGA,cAAM,UAAU,IAAI,IAAI,UAAU,GAAG,EAAE,SAAS;AAChD,cAAI,UAAK,iBAAL,mBAAmB,SAAQ,SAAS;AACtC,iBAAO,KAAK,aAAa;AAAA,QAC3B;AAEA,cAAMC,QAAO,MAAM,KAAK,MAAM,SAAS;AAAA,UACrC,QAAQ;AAAA,UACR,SAAS,KAAK,eAAe;AAAA,QAC/B,CAAC;AAED,cAAM,OAAO;AAAA,UACX,MAAM,KAAK,2BAA2BA,KAAI;AAAA,QAC5C;AACA,aAAK,eAAe;AAAA,UAClB,QAAQ;AAAA,UACR,KAAK;AAAA,QACP;AAEA,eAAO;AAAA,MACT;AAEA,UAAI;AACJ,UAAI;AACF,eAAO,MAAM,KAAK,MAAM,KAAK;AAAA,UAC3B,QAAQ;AAAA,UACR,SAAS,KAAK,eAAe;AAAA,QAC/B,CAAC;AAAA,MACH,SAAS,OAAO;AAEd,YAAI,aAAa,sBAAsB,iBAAiB,WAAW;AACjE,iBAAO;AAAA,QACT;AACA,cAAM;AAAA,MACR;AAGA,UAAI,sBAAsB,KAAK,WAAW,OAAO,CAAC,KAAK,YAAY;AACjE,eAAO;AAAA,MACT;AAEA,aAAO,KAAK,qBAAqB,MAAM,IAAI;AAAA,IAC7C;AAAA;AAAA,EAEc,qBAAqB,MAAgB,MAAc;AAAA;AAC/D,UAAI,OAAO,MAAM,KAAK,2BAA2B,IAAI;AAIrD,UAAI,KAAK,aAAa;AACpB,cAAM,
|
|
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 url = json.redirectUrl.startsWith(\"/\")\n ? host + json.redirectUrl\n : json.redirectUrl;\n const redirectResp = await this.fetch(url, {\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;A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