@plasmicapp/loader-fetcher 1.0.49 → 1.0.51

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 CHANGED
@@ -37,12 +37,34 @@ export declare class Api {
37
37
  getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]): string;
38
38
  }
39
39
 
40
+ declare interface ApiLoaderBundleOutput {
41
+ modules: {
42
+ browser: (CodeModule | AssetModule)[];
43
+ server: (CodeModule | AssetModule)[];
44
+ };
45
+ components: ComponentMeta[];
46
+ globalGroups: GlobalGroupMeta[];
47
+ projects: ProjectMeta[];
48
+ activeSplits: Split[];
49
+ bundleKey: string | null;
50
+ deferChunksByDefault: boolean;
51
+ }
52
+
40
53
  export declare interface AssetModule {
41
54
  fileName: string;
42
55
  source: string;
43
56
  type: "asset";
44
57
  }
45
58
 
59
+ declare interface BareSplit {
60
+ id: string;
61
+ projectId: string;
62
+ name: string;
63
+ externalId?: string;
64
+ description?: string;
65
+ pagesPaths: string[];
66
+ }
67
+
46
68
  export declare interface CodeModule {
47
69
  fileName: string;
48
70
  code: string;
@@ -71,10 +93,7 @@ export declare interface ExperimentSlice extends Slice {
71
93
  prob: number;
72
94
  }
73
95
 
74
- declare interface ExperimentSplit {
75
- id: string;
76
- projectId: string;
77
- externalId?: string;
96
+ declare interface ExperimentSplit extends BareSplit {
78
97
  type: "experiment";
79
98
  slices: ExperimentSlice[];
80
99
  }
@@ -134,17 +153,8 @@ export declare interface LoaderBundleCache {
134
153
  get: () => Promise<LoaderBundleOutput>;
135
154
  }
136
155
 
137
- export declare interface LoaderBundleOutput {
138
- modules: {
139
- browser: (CodeModule | AssetModule)[];
140
- server: (CodeModule | AssetModule)[];
141
- };
142
- components: ComponentMeta[];
143
- globalGroups: GlobalGroupMeta[];
144
- projects: ProjectMeta[];
145
- activeSplits: Split[];
146
- bundleKey: string | null;
147
- deferChunksByDefault: boolean;
156
+ export declare interface LoaderBundleOutput extends ApiLoaderBundleOutput {
157
+ filteredIds: Record<string, string[]>;
148
158
  }
149
159
 
150
160
  export declare interface LoaderHtmlOutput {
@@ -192,10 +202,7 @@ export declare interface SegmentSlice extends Slice {
192
202
  cond: any;
193
203
  }
194
204
 
195
- declare interface SegmentSplit {
196
- id: string;
197
- projectId: string;
198
- externalId?: string;
205
+ declare interface SegmentSplit extends BareSplit {
199
206
  type: "segment";
200
207
  slices: SegmentSlice[];
201
208
  }
package/dist/index.esm.js CHANGED
@@ -1,4 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  var __async = (__this, __arguments, generator) => {
18
21
  return new Promise((resolve, reject) => {
19
22
  var fulfilled = (value) => {
@@ -39,6 +42,11 @@ var __async = (__this, __arguments, generator) => {
39
42
  import unfetch from "@plasmicapp/isomorphic-unfetch";
40
43
  var VERSION = "10";
41
44
  var isBrowser = typeof window !== "undefined" && window != null && typeof window.document !== "undefined";
45
+ function transformApiLoaderBundleOutput(bundle) {
46
+ return __spreadProps(__spreadValues({}, bundle), {
47
+ filteredIds: {}
48
+ });
49
+ }
42
50
  var Api = class {
43
51
  constructor(opts) {
44
52
  this.opts = opts;
@@ -97,7 +105,9 @@ var Api = class {
97
105
  `Error fetching loader data: ${(_g = (_f = error == null ? void 0 : error.error) == null ? void 0 : _f.message) != null ? _g : resp2.statusText}`
98
106
  );
99
107
  }
100
- const json2 = yield this.parseJsonResponse(resp2);
108
+ const json2 = transformApiLoaderBundleOutput(
109
+ yield this.parseJsonResponse(resp2)
110
+ );
101
111
  this.lastResponse = {
102
112
  bundle: json2,
103
113
  key: nextLocation
@@ -115,7 +125,7 @@ var Api = class {
115
125
  );
116
126
  }
117
127
  const json = yield this.parseJsonResponse(resp);
118
- return json;
128
+ return transformApiLoaderBundleOutput(json);
119
129
  });
120
130
  }
121
131
  parseJsonResponse(resp) {
@@ -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}\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\nexport interface ProjectMeta {\n id: string;\n teamId?: string;\n indirect?: boolean;\n name: string;\n version: string;\n remoteFonts: FontMeta[];\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\nexport interface ExperimentSplit {\n id: string;\n projectId: string;\n externalId?: string;\n type: \"experiment\";\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit {\n id: string;\n projectId: string;\n externalId?: string;\n type: \"segment\";\n slices: SegmentSlice[];\n}\n\nexport type Split = ExperimentSplit | SegmentSplit;\n\nexport interface LoaderBundleOutput {\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}\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 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 ) {\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 if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `Error fetching loader data: ${\n error?.error?.message ?? resp.statusText\n }`\n );\n }\n\n const json = (await this.parseJsonResponse(resp)) as LoaderBundleOutput;\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 if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `Error fetching loader data: ${\n error?.error?.message ?? resp.statusText\n }`\n );\n }\n const json = await this.parseJsonResponse(resp);\n return json as LoaderBundleOutput;\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 this.curFetch = this.doFetch();\n const data = await this.curFetch;\n this.curFetch = undefined;\n return data;\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;AA8HpB,IAAM,UAAU;AAET,IAAM,YACX,OAAO,WAAW,eAClB,UAAU,QACV,OAAO,OAAO,aAAa;AAEtB,IAAM,MAAN,MAAU;AAAA,EAWf,YACU,MAMR;AANQ;AARV,SAAQ,eAKQ;AA9IlB;AAwJI,SAAK,QAAO,UAAK,SAAL,YAAa;AACzB,SAAK,SACH,KAAK,eAAe,WAAW,QAAQ,WAAW,QAAQ,SAC1D,KAAK,UAAU;AAAA,EACnB;AAAA,EAEM,gBACJ,YACA,MAaA;AAAA;AA7KJ;AA8KI,YAAM,EAAE,UAAU,QAAQ,IAAI;AAC9B,YAAM,QA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K,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;AAhIlC;AAiIE,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;",
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}\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\nexport interface ProjectMeta {\n id: string;\n teamId?: string;\n indirect?: boolean;\n name: string;\n version: string;\n remoteFonts: FontMeta[];\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}\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\nfunction transformApiLoaderBundleOutput(\n bundle: ApiLoaderBundleOutput\n): LoaderBundleOutput {\n return {\n ...bundle,\n filteredIds: {},\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 if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `Error fetching loader data: ${\n error?.error?.message ?? resp.statusText\n }`\n );\n }\n\n const json = transformApiLoaderBundleOutput(\n (await this.parseJsonResponse(resp)) as ApiLoaderBundleOutput\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 if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `Error fetching loader data: ${\n error?.error?.message ?? resp.statusText\n }`\n );\n }\n const json = await this.parseJsonResponse(resp);\n return transformApiLoaderBundleOutput(json 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 this.curFetch = this.doFetch();\n const data = await this.curFetch;\n this.curFetch = undefined;\n return data;\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;AAwIpB,IAAM,UAAU;AAET,IAAM,YACX,OAAO,WAAW,eAClB,UAAU,QACV,OAAO,OAAO,aAAa;AAE7B,SAAS,+BACP,QACoB;AACpB,SAAO,iCACF,SADE;AAAA,IAEL,aAAa,CAAC;AAAA,EAChB;AACF;AAEO,IAAM,MAAN,MAAU;AAAA,EAWf,YACU,MAMR;AANQ;AARV,SAAQ,eAKQ;AAjKlB;AA2KI,SAAK,QAAO,UAAK,SAAL,YAAa;AACzB,SAAK,SACH,KAAK,eAAe,WAAW,QAAQ,WAAW,QAAQ,SAC1D,KAAK,UAAU;AAAA,EACnB;AAAA,EAEM,gBACJ,YACA,MAa6B;AAAA;AAhMjC;AAiMI,YAAM,EAAE,UAAU,QAAQ,IAAI;AAC9B,YAAM,QAAQ,IAAI,gBAAgB;AAAA,QAChC,CAAC,YAAY,8BAAY,OAAO;AAAA,QAChC,KAAI,gBAAK,oBAAL,mBAAsB,WAAtB,mBAA8B,UAC9B,CAAC,CAAC,gBAAgB,MAAM,CAAC,IACzB,CAAC;AAAA,QACL,GAAG,WAAW,IAAI,CAAC,cAAc,CAAC,aAAa,SAAS,CAAC;AAAA,QACzD,GAAI,KAAK,cAAc,CAAC,CAAC,eAAe,MAAM,CAAC,IAAI,CAAC;AAAA,QACpD,GAAI,KAAK,gBAAgB,CAAC,CAAC,iBAAiB,KAAK,aAAa,CAAC,IAAI,CAAC;AAAA,QACpE,GAAI,KAAK,gBAAgB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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
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
9
  var __getProtoOf = Object.getPrototypeOf;
@@ -19,6 +21,7 @@ var __spreadValues = (a, b) => {
19
21
  }
20
22
  return a;
21
23
  };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
25
  var __export = (target, all) => {
23
26
  for (var name in all)
24
27
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -74,6 +77,11 @@ module.exports = __toCommonJS(src_exports);
74
77
  var import_isomorphic_unfetch = __toESM(require("@plasmicapp/isomorphic-unfetch"));
75
78
  var VERSION = "10";
76
79
  var isBrowser = typeof window !== "undefined" && window != null && typeof window.document !== "undefined";
80
+ function transformApiLoaderBundleOutput(bundle) {
81
+ return __spreadProps(__spreadValues({}, bundle), {
82
+ filteredIds: {}
83
+ });
84
+ }
77
85
  var Api = class {
78
86
  constructor(opts) {
79
87
  this.opts = opts;
@@ -132,7 +140,9 @@ var Api = class {
132
140
  `Error fetching loader data: ${(_g = (_f = error == null ? void 0 : error.error) == null ? void 0 : _f.message) != null ? _g : resp2.statusText}`
133
141
  );
134
142
  }
135
- const json2 = yield this.parseJsonResponse(resp2);
143
+ const json2 = transformApiLoaderBundleOutput(
144
+ yield this.parseJsonResponse(resp2)
145
+ );
136
146
  this.lastResponse = {
137
147
  bundle: json2,
138
148
  key: nextLocation
@@ -150,7 +160,7 @@ var Api = class {
150
160
  );
151
161
  }
152
162
  const json = yield this.parseJsonResponse(resp);
153
- return json;
163
+ return transformApiLoaderBundleOutput(json);
154
164
  });
155
165
  }
156
166
  parseJsonResponse(resp) {
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}\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\nexport interface ProjectMeta {\n id: string;\n teamId?: string;\n indirect?: boolean;\n name: string;\n version: string;\n remoteFonts: FontMeta[];\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\nexport interface ExperimentSplit {\n id: string;\n projectId: string;\n externalId?: string;\n type: \"experiment\";\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit {\n id: string;\n projectId: string;\n externalId?: string;\n type: \"segment\";\n slices: SegmentSlice[];\n}\n\nexport type Split = ExperimentSplit | SegmentSplit;\n\nexport interface LoaderBundleOutput {\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}\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 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 ) {\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 if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `Error fetching loader data: ${\n error?.error?.message ?? resp.statusText\n }`\n );\n }\n\n const json = (await this.parseJsonResponse(resp)) as LoaderBundleOutput;\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 if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `Error fetching loader data: ${\n error?.error?.message ?? resp.statusText\n }`\n );\n }\n const json = await this.parseJsonResponse(resp);\n return json as LoaderBundleOutput;\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 this.curFetch = this.doFetch();\n const data = await this.curFetch;\n this.curFetch = undefined;\n return data;\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;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GroupMeta,\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}\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\nexport interface ProjectMeta {\n id: string;\n teamId?: string;\n indirect?: boolean;\n name: string;\n version: string;\n remoteFonts: FontMeta[];\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}\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\nfunction transformApiLoaderBundleOutput(\n bundle: ApiLoaderBundleOutput\n): LoaderBundleOutput {\n return {\n ...bundle,\n filteredIds: {},\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 if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `Error fetching loader data: ${\n error?.error?.message ?? resp.statusText\n }`\n );\n }\n\n const json = transformApiLoaderBundleOutput(\n (await this.parseJsonResponse(resp)) as ApiLoaderBundleOutput\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 if (resp.status >= 400) {\n const error = await this.parseJsonResponse(resp);\n throw new Error(\n `Error fetching loader data: ${\n error?.error?.message ?? resp.statusText\n }`\n );\n }\n const json = await this.parseJsonResponse(resp);\n return transformApiLoaderBundleOutput(json 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 this.curFetch = this.doFetch();\n const data = await this.curFetch;\n this.curFetch = undefined;\n return data;\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;AAwIpB,IAAM,UAAU;AAET,IA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"1.0.49",
2
+ "version": "1.0.51",
3
3
  "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": "3dba21994e2753f6bc28cb817c8dd2402ed154b0"
50
+ "gitHead": "933d82fb98100cf0d00ccb97d60bb31c0bd82bcb"
51
51
  }