@plasmicapp/loader-fetcher 1.0.17 → 1.0.19

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/api.d.ts CHANGED
@@ -86,12 +86,6 @@ export interface LoaderBundleOutput {
86
86
  globalGroups: GlobalGroupMeta[];
87
87
  projects: ProjectMeta[];
88
88
  activeSplits: Split[];
89
- /**
90
- * ID used to identify LoaderBundleOutputs locally within a process.
91
- *
92
- * This property may be unset or `undefined` to indicate an "empty" LoaderBundleOutput.
93
- */
94
- localId?: number | undefined;
95
89
  }
96
90
  export interface LoaderHtmlOutput {
97
91
  html: string;
package/dist/fetcher.d.ts CHANGED
@@ -23,5 +23,6 @@ export declare class PlasmicModulesFetcher {
23
23
  fetchAllData(): Promise<LoaderBundleOutput>;
24
24
  private getCachedOrFetch;
25
25
  private doFetch;
26
- private storeGlobally;
26
+ private cacheBundleInNodeServer;
27
27
  }
28
+ export declare function internal_getCachedBundleInNodeServer(opts: FetcherOptions): LoaderBundleOutput | undefined;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { Api, AssetModule, CodeModule, ComponentMeta, ExperimentSlice, FontMeta, GlobalGroupMeta, LoaderBundleOutput, LoaderHtmlOutput, PageMeta, PageMetadata, ProjectMeta, SegmentSlice, Split, } from './api';
2
- export { FetcherOptions, LoaderBundleCache, PlasmicModulesFetcher, } from './fetcher';
2
+ export { FetcherOptions, internal_getCachedBundleInNodeServer, LoaderBundleCache, PlasmicModulesFetcher, } from './fetcher';
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
- var fetch = _interopDefault(require('isomorphic-unfetch'));
7
+ var fetch = _interopDefault(require('@plasmicapp/isomorphic-unfetch'));
8
8
 
9
9
  const VERSION = '9';
10
10
  const isBrowser = typeof window !== 'undefined' && window != null && typeof window.document !== 'undefined';
@@ -78,19 +78,6 @@ class Api {
78
78
  }
79
79
  }
80
80
 
81
- /**
82
- * Returns an ID that is locally unique within a process.
83
- *
84
- * This function works even if this function's module is reloaded within the same process.
85
- * It depends on setting state in the environment's `globalThis` variable.
86
- */
87
- function uniqueLocalId() {
88
- const global = globalThis;
89
- const localId = global.__PLASMIC_NEXT_LOCAL_ID ? global.__PLASMIC_NEXT_LOCAL_ID : 1;
90
- global.__PLASMIC_NEXT_LOCAL_ID = localId + 1;
91
- return localId;
92
- }
93
-
94
81
  class PlasmicModulesFetcher {
95
82
  constructor(opts) {
96
83
  this.opts = opts;
@@ -101,10 +88,15 @@ class PlasmicModulesFetcher {
101
88
  });
102
89
  }
103
90
  async fetchAllData() {
91
+ // getCachedOrFetched uses a cache defined by the user.
104
92
  const bundle = await this.getCachedOrFetch();
105
- // Assign a local ID AFTER caching. If the local ID were cached, it may no longer be unique.
106
- bundle.localId = uniqueLocalId();
107
- this.storeGlobally(bundle);
93
+ // For React Server Components (Next.js 13+),
94
+ // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.
95
+ // We don't want to pass them via normal page props because that will be serialized to the browser.
96
+ // Instead, we pass the bundle (including the server modules) via the Node `global` variable.
97
+ //
98
+ // cacheBundleInNodeServer caches a bundle in the Node server process.
99
+ this.cacheBundleInNodeServer(bundle);
108
100
  return bundle;
109
101
  }
110
102
  async getCachedOrFetch() {
@@ -136,24 +128,41 @@ class PlasmicModulesFetcher {
136
128
  console.debug(`Plasmic: fetched designs for ${data.projects.map(p => `"${p.name}" (${p.id}@${p.version})`).join(', ')}`);
137
129
  return data;
138
130
  }
139
- // For React Server Components (Next.js 13+),
140
- // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.
141
- // We don't want to pass them via normal page props because that will be serialized to the browser.
142
- // Instead, we pass the bundle (including the server modules) via the Node `global` variable.
143
- //
144
- // This is the code that stores the bundle.
145
- storeGlobally(bundle) {
146
- if (bundle.localId === undefined) {
131
+ cacheBundleInNodeServer(bundle) {
132
+ if (isBrowser) {
147
133
  return;
148
134
  }
149
135
  if (global.__PLASMIC_BUNDLES === undefined) {
150
136
  global.__PLASMIC_BUNDLES = {};
151
137
  }
152
- global.__PLASMIC_BUNDLES[bundle.localId] = bundle;
138
+ global.__PLASMIC_BUNDLES[getBundleKey(this.opts)] = bundle;
153
139
  }
154
140
  }
141
+ function internal_getCachedBundleInNodeServer(opts) {
142
+ var _global$__PLASMIC_BUN;
143
+ if (isBrowser) {
144
+ throw new Error(`Should not be consulting Node server cache in browser`);
145
+ }
146
+ return (_global$__PLASMIC_BUN = global.__PLASMIC_BUNDLES) == null ? void 0 : _global$__PLASMIC_BUN[getBundleKey(opts)];
147
+ }
148
+ function getBundleKey({
149
+ host,
150
+ platform,
151
+ i18nKeyScheme,
152
+ preview,
153
+ projects
154
+ }) {
155
+ return JSON.stringify({
156
+ host,
157
+ platform,
158
+ i18nKeyScheme,
159
+ preview,
160
+ projects
161
+ });
162
+ }
155
163
  const global = globalThis;
156
164
 
157
165
  exports.Api = Api;
158
166
  exports.PlasmicModulesFetcher = PlasmicModulesFetcher;
167
+ exports.internal_getCachedBundleInNodeServer = internal_getCachedBundleInNodeServer;
159
168
  //# sourceMappingURL=loader-fetcher.cjs.development.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader-fetcher.cjs.development.js","sources":["../src/api.ts","../src/uniqueLocalId.ts","../src/fetcher.ts"],"sourcesContent":["import fetch from '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}\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 externalId?: string;\n type: 'experiment';\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit {\n id: 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 external: string[];\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\n\n // Note this property doesn't come from the API but is generated locally by this module.\n /**\n * ID used to identify LoaderBundleOutputs locally within a process.\n *\n * This property may be unset or `undefined` to indicate an \"empty\" LoaderBundleOutput.\n */\n localId?: number | undefined;\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 = '9';\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 constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n }\n ) {\n this.host = opts.host ?? 'https://codegen.plasmic.app';\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: 'react' | 'nextjs' | 'gatsby';\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: 'content' | 'hash';\n }\n ) {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n ['platform', platform ?? 'react'],\n ...projectIds.map((projectId) => ['projectId', projectId]),\n ...(opts.browserOnly ? [['browserOnly', 'true']] : []),\n ...(opts.i18nKeyScheme ? [['i18nKeyScheme', opts.i18nKeyScheme]] : []),\n ]).toString();\n\n const url = `${this.host}/api/v1/loader/code/${\n preview ? 'preview' : 'published'\n }?${query}`;\n const resp = await 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(`Error parsing JSON response: ${err}; response: ${text}`);\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 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 // @ts-ignore\n private makePostHeaders() {\n return {\n 'x-plasmic-loader-version': VERSION,\n 'Content-Type': 'application/json',\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","interface GlobalWithNextLocalId {\n __PLASMIC_NEXT_LOCAL_ID?: number;\n}\n\n/**\n * Returns an ID that is locally unique within a process.\n *\n * This function works even if this function's module is reloaded within the same process.\n * It depends on setting state in the environment's `globalThis` variable.\n */\nexport function uniqueLocalId(): number {\n const global = globalThis as GlobalWithNextLocalId;\n const localId = global.__PLASMIC_NEXT_LOCAL_ID\n ? global.__PLASMIC_NEXT_LOCAL_ID\n : 1;\n global.__PLASMIC_NEXT_LOCAL_ID = localId + 1;\n return localId;\n}\n","import { Api, isBrowser, LoaderBundleOutput } from './api';\nimport { uniqueLocalId } from './uniqueLocalId';\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 preview?: boolean;\n host?: string;\n i18nKeyScheme?: 'content' | 'hash';\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 });\n }\n\n async fetchAllData() {\n const bundle = await this.getCachedOrFetch();\n\n // Assign a local ID AFTER caching. If the local ID were cached, it may no longer be unique.\n bundle.localId = uniqueLocalId();\n this.storeGlobally(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 console.debug('Plasmic: doing a fresh fetch...');\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 preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18nKeyScheme,\n browserOnly: isBrowser,\n }\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(', ')}`\n );\n return data;\n }\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 // This is the code that stores the bundle.\n private storeGlobally(bundle: LoaderBundleOutput) {\n if (bundle.localId === undefined) {\n return;\n }\n\n if (global.__PLASMIC_BUNDLES === undefined) {\n global.__PLASMIC_BUNDLES = {};\n }\n global.__PLASMIC_BUNDLES[bundle.localId] = bundle;\n }\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [localId: number]: LoaderBundleOutput };\n}\nconst global = globalThis as GlobalWithBundles;\n"],"names":["VERSION","isBrowser","window","document","Api","constructor","opts","host","fetchLoaderData","projectIds","platform","preview","query","URLSearchParams","map","projectId","browserOnly","i18nKeyScheme","toString","url","resp","fetch","method","headers","makeGetHeaders","status","error","parseJsonResponse","Error","message","statusText","json","text","JSON","parse","err","fetchHtmlData","component","embedHydrate","hydrate","makeAuthHeaders","makePostHeaders","tokens","projects","p","id","token","join","uniqueLocalId","global","globalThis","localId","__PLASMIC_NEXT_LOCAL_ID","PlasmicModulesFetcher","undefined","api","fetchAllData","bundle","getCachedOrFetch","storeGlobally","cache","cachedData","get","curFetch","console","debug","doFetch","data","version","set","name","__PLASMIC_BUNDLES"],"mappings":";;;;;;;;AAkIA,MAAMA,OAAO,GAAG,GAAG;AAEZ,MAAMC,SAAS,GACpB,OAAOC,MAAM,KAAK,WAAW,I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AAI,CAACA,QAAQ,GAAGT,SAAS;IACzB,OAAOa,IAAI;;EAGL,MAAMD,OAAO;IACnB,MAAMC,IAAI,GAAG,MAAM,IAAI,CAACZ,GAAG,CAAC/C,eAAe,CACzC,IAAI,CAACF,IAAI,CAACqC,QAAQ,CAAC7B,GAAG,CAAE8B,CAAC,IACvBA,CAAC,CAACwB,OAAO,MAAMxB,CAAC,CAACC,MAAMD,CAAC,CAACwB,SAAS,GAAGxB,CAAC,CAACC,EAAE,CAC1C,EACD;MACEnC,QAAQ,EAAE,IAAI,CAACJ,IAAI,CAACI,QAAQ;MAC5BC,OAAO,EAAE,IAAI,CAACL,IAAI,CAACK,OAAO;MAC1BM,aAAa,EAAE,IAAI,CAACX,IAAI,CAACW,aAAa;MACtCD,WAAW,EAAEf;KACd,CACF;IACD,IAAI,IAAI,CAACK,IAAI,CAACsD,KAAK,EAAE;MACnB,MAAM,IAAI,CAACtD,IAAI,CAACsD,KAAK,CAACS,GAAG,CAACF,IAAI,CAAC;;IAEjCH,OAAO,CAACC,KAAK,iCACqBE,IAAI,CAACxB,QAAQ,CAC1C7B,GAAG,CAAE8B,CAAC,QAASA,CAAC,CAAC0B,UAAU1B,CAAC,CAACC,MAAMD,CAAC,CAACwB,UAAU,CAAC,CAChDrB,IAAI,CAAC,IAAI,GAAG,CAChB;IACD,OAAOoB,IAAI;;;;;;;;EASLR,aAAa,CAACF,MAA0B;IAC9C,IAAIA,MAAM,CAACN,OAAO,KAAKG,SAAS,EAAE;MAChC;;IAGF,IAAIL,MAAM,CAACsB,iBAAiB,KAAKjB,SAAS,EAAE;MAC1CL,MAAM,CAACsB,iBAAiB,GAAG,EAAE;;IAE/BtB,MAAM,CAACsB,iBAAiB,CAACd,MAAM,CAACN,OAAO,CAAC,GAAGM,MAAM;;;AAOrD,MAAMR,MAAM,GAAGC,UAA+B;;;;;"}
1
+ {"version":3,"file":"loader-fetcher.cjs.development.js","sources":["../src/api.ts","../src/fetcher.ts"],"sourcesContent":["import fetch 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}\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 externalId?: string;\n type: 'experiment';\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit {\n id: 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 external: string[];\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\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 = '9';\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 constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n }\n ) {\n this.host = opts.host ?? 'https://codegen.plasmic.app';\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: 'react' | 'nextjs' | 'gatsby';\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: 'content' | 'hash';\n }\n ) {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n ['platform', platform ?? 'react'],\n ...projectIds.map((projectId) => ['projectId', projectId]),\n ...(opts.browserOnly ? [['browserOnly', 'true']] : []),\n ...(opts.i18nKeyScheme ? [['i18nKeyScheme', opts.i18nKeyScheme]] : []),\n ]).toString();\n\n const url = `${this.host}/api/v1/loader/code/${\n preview ? 'preview' : 'published'\n }?${query}`;\n const resp = await 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(`Error parsing JSON response: ${err}; response: ${text}`);\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 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 // @ts-ignore\n private makePostHeaders() {\n return {\n 'x-plasmic-loader-version': VERSION,\n 'Content-Type': 'application/json',\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","import { Api, 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 preview?: boolean;\n host?: string;\n i18nKeyScheme?: 'content' | 'hash';\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 });\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 console.debug('Plasmic: doing a fresh fetch...');\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 preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18nKeyScheme,\n browserOnly: isBrowser,\n }\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(', ')}`\n );\n return data;\n }\n\n private cacheBundleInNodeServer(bundle: LoaderBundleOutput) {\n if (isBrowser) {\n return;\n }\n\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 return global.__PLASMIC_BUNDLES?.[getBundleKey(opts)];\n}\n\nfunction getBundleKey({\n host,\n platform,\n i18nKeyScheme,\n preview,\n projects,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n platform,\n i18nKeyScheme,\n preview,\n projects,\n });\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [bundleKey: string]: LoaderBundleOutput };\n}\nconst global = globalThis as GlobalWithBundles;\n"],"names":["VERSION","isBrowser","window","document","Api","constructor","opts","host","fetchLoaderData","projectIds","platform","preview","query","URLSearchParams","map","projectId","browserOnly","i18nKeyScheme","toString","url","resp","fetch","method","headers","makeGetHeaders","status","error","parseJsonResponse","Error","message","statusText","json","text","JSON","parse","err","fetchHtmlData","component","embedHydrate","hydrate","makeAuthHeaders","makePostHeaders","tokens","projects","p","id","token","join","PlasmicModulesFetcher","undefined","api","fetchAllData","bundle","getCachedOrFetch","cacheBundleInNodeServer","cache","cachedData","get","curFetch","console","debug","doFetch","data","version","set","name","global","__PLASMIC_BUNDLES","getBundleK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;EACbN,OAAO;EACPgC;CACe;EACf,OAAOV,IAAI,CAACqC,SAAS,CAAC;IACpB/D,IAAI;IACJG,QAAQ;IACRO,aAAa;IACbN,OAAO;IACPgC;GACD,CAAC;AACJ;AAKA,MAAMuB,MAAM,GAAGK,UAA+B;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("isomorphic-unfetch"))&&"object"==typeof e&&"default"in e?e.default:e;const s="undefined"!=typeof window&&null!=window&&void 0!==window.document;class r{constructor(e){var t;this.opts=e,this.host=null!=(t=e.host)?t:"https://codegen.plasmic.app"}async fetchLoaderData(e,s){const{platform:r,preview:o}=s,a=new URLSearchParams([["platform",null!=r?r:"react"],...e.map(e=>["projectId",e]),...s.browserOnly?[["browserOnly","true"]]:[],...s.i18nKeyScheme?[["i18nKeyScheme",s.i18nKeyScheme]]:[]]).toString(),i=`${this.host}/api/v1/loader/code/${o?"preview":"published"}?${a}`,c=await t(i,{method:"GET",headers:this.makeGetHeaders()});if(c.status>=400){var n,h;const e=await this.parseJsonResponse(c);throw new Error("Error fetching loader data: "+(null!=(n=null==e||null==(h=e.error)?void 0:h.message)?n:c.statusText))}return await this.parseJsonResponse(c)}async parseJsonResponse(e){const t=await e.text();try{return JSON.parse(t)}catch(e){throw new Error(`Error parsing JSON response: ${e}; response: ${t}`)}}async fetchHtmlData(e){const{projectId:s,component:r,embedHydrate:o,hydrate:a}=e,i=new URLSearchParams([["projectId",s],["component",r],["embedHydrate",o?"1":"0"],["hydrate",a?"1":"0"]]).toString(),c=await t(`${this.host}/api/v1/loader/html?${i}`,{method:"GET",headers:this.makeGetHeaders()});return await c.json()}makeGetHeaders(){return{"x-plasmic-loader-version":"9",...this.makeAuthHeaders()}}makePostHeaders(){return{"x-plasmic-loader-version":"9","Content-Type":"application/json",...this.makeAuthHeaders()}}makeAuthHeaders(){return{"x-plasmic-api-project-tokens":this.opts.projects.map(e=>`${e.id}:${e.token}`).join(",")}}}const o=globalThis;exports.Api=r,exports.PlasmicModulesFetcher=class{constructor(e){this.opts=e,this.curFetch=void 0,this.api=new r({projects:e.projects,host:e.host})}async fetchAllData(){const e=await this.getCachedOrFetch();return e.localId=function(){const e=globalThis,t=e.__PLASMIC_NEXT_LOCAL_ID?e.__PLASMIC_NEXT_LOCAL_ID:1;return e.__PLASMIC_NEXT_LOCAL_ID=t+1,t}(),this.storeGlobally(e),e}async getCachedOrFetch(){if(this.opts.cache){const e=await this.opts.cache.get();if(e)return e}if(this.curFetch)return await this.curFetch;console.debug("Plasmic: doing a fresh fetch..."),this.curFetch=this.doFetch();const e=await this.curFetch;return this.curFetch=void 0,e}async doFetch(){const e=await this.api.fetchLoaderData(this.opts.projects.map(e=>e.version?`${e.id}@${e.version}`:e.id),{platform:this.opts.platform,preview:this.opts.preview,i18nKeyScheme:this.opts.i18nKeyScheme,browserOnly:s});return this.opts.cache&&await this.opts.cache.set(e),console.debug("Plasmic: fetched designs for "+e.projects.map(e=>`"${e.name}" (${e.id}@${e.version})`).join(", ")),e}storeGlobally(e){void 0!==e.localId&&(void 0===o.__PLASMIC_BUNDLES&&(o.__PLASMIC_BUNDLES={}),o.__PLASMIC_BUNDLES[e.localId]=e)}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("@plasmicapp/isomorphic-unfetch"))&&"object"==typeof e&&"default"in e?e.default:e;const r="undefined"!=typeof window&&null!=window&&void 0!==window.document;class s{constructor(e){var t;this.opts=e,this.host=null!=(t=e.host)?t:"https://codegen.plasmic.app"}async fetchLoaderData(e,r){const{platform:s,preview:o}=r,a=new URLSearchParams([["platform",null!=s?s:"react"],...e.map(e=>["projectId",e]),...r.browserOnly?[["browserOnly","true"]]:[],...r.i18nKeyScheme?[["i18nKeyScheme",r.i18nKeyScheme]]:[]]).toString(),i=`${this.host}/api/v1/loader/code/${o?"preview":"published"}?${a}`,n=await t(i,{method:"GET",headers:this.makeGetHeaders()});if(n.status>=400){var c,h;const e=await this.parseJsonResponse(n);throw new Error("Error fetching loader data: "+(null!=(c=null==e||null==(h=e.error)?void 0:h.message)?c:n.statusText))}return await this.parseJsonResponse(n)}async parseJsonResponse(e){const t=await e.text();try{return JSON.parse(t)}catch(e){throw new Error(`Error parsing JSON response: ${e}; response: ${t}`)}}async fetchHtmlData(e){const{projectId:r,component:s,embedHydrate:o,hydrate:a}=e,i=new URLSearchParams([["projectId",r],["component",s],["embedHydrate",o?"1":"0"],["hydrate",a?"1":"0"]]).toString(),n=await t(`${this.host}/api/v1/loader/html?${i}`,{method:"GET",headers:this.makeGetHeaders()});return await n.json()}makeGetHeaders(){return{"x-plasmic-loader-version":"9",...this.makeAuthHeaders()}}makePostHeaders(){return{"x-plasmic-loader-version":"9","Content-Type":"application/json",...this.makeAuthHeaders()}}makeAuthHeaders(){return{"x-plasmic-api-project-tokens":this.opts.projects.map(e=>`${e.id}:${e.token}`).join(",")}}}function o({host:e,platform:t,i18nKeyScheme:r,preview:s,projects:o}){return JSON.stringify({host:e,platform:t,i18nKeyScheme:r,preview:s,projects:o})}const a=globalThis;exports.Api=s,exports.PlasmicModulesFetcher=class{constructor(e){this.opts=e,this.curFetch=void 0,this.api=new s({projects:e.projects,host:e.host})}async fetchAllData(){const e=await this.getCachedOrFetch();return this.cacheBundleInNodeServer(e),e}async getCachedOrFetch(){if(this.opts.cache){const e=await this.opts.cache.get();if(e)return e}if(this.curFetch)return await this.curFetch;console.debug("Plasmic: doing a fresh fetch..."),this.curFetch=this.doFetch();const e=await this.curFetch;return this.curFetch=void 0,e}async doFetch(){const e=await this.api.fetchLoaderData(this.opts.projects.map(e=>e.version?`${e.id}@${e.version}`:e.id),{platform:this.opts.platform,preview:this.opts.preview,i18nKeyScheme:this.opts.i18nKeyScheme,browserOnly:r});return this.opts.cache&&await this.opts.cache.set(e),console.debug("Plasmic: fetched designs for "+e.projects.map(e=>`"${e.name}" (${e.id}@${e.version})`).join(", ")),e}cacheBundleInNodeServer(e){r||(void 0===a.__PLASMIC_BUNDLES&&(a.__PLASMIC_BUNDLES={}),a.__PLASMIC_BUNDLES[o(this.opts)]=e)}},exports.internal_getCachedBundleInNodeServer=function(e){var t;if(r)throw new Error("Should not be consulting Node server cache in browser");return null==(t=a.__PLASMIC_BUNDLES)?void 0:t[o(e)]};
2
2
  //# sourceMappingURL=loader-fetcher.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader-fetcher.cjs.production.min.js","sources":["../src/api.ts","../src/fetcher.ts","../src/uniqueLocalId.ts"],"sourcesContent":["import fetch from '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}\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 externalId?: string;\n type: 'experiment';\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit {\n id: 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 external: string[];\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\n\n // Note this property doesn't come from the API but is generated locally by this module.\n /**\n * ID used to identify LoaderBundleOutputs locally within a process.\n *\n * This property may be unset or `undefined` to indicate an \"empty\" LoaderBundleOutput.\n */\n localId?: number | undefined;\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 = '9';\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 constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n }\n ) {\n this.host = opts.host ?? 'https://codegen.plasmic.app';\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: 'react' | 'nextjs' | 'gatsby';\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: 'content' | 'hash';\n }\n ) {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n ['platform', platform ?? 'react'],\n ...projectIds.map((projectId) => ['projectId', projectId]),\n ...(opts.browserOnly ? [['browserOnly', 'true']] : []),\n ...(opts.i18nKeyScheme ? [['i18nKeyScheme', opts.i18nKeyScheme]] : []),\n ]).toString();\n\n const url = `${this.host}/api/v1/loader/code/${\n preview ? 'preview' : 'published'\n }?${query}`;\n const resp = await 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(`Error parsing JSON response: ${err}; response: ${text}`);\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 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 // @ts-ignore\n private makePostHeaders() {\n return {\n 'x-plasmic-loader-version': VERSION,\n 'Content-Type': 'application/json',\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","import { Api, isBrowser, LoaderBundleOutput } from './api';\nimport { uniqueLocalId } from './uniqueLocalId';\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 preview?: boolean;\n host?: string;\n i18nKeyScheme?: 'content' | 'hash';\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 });\n }\n\n async fetchAllData() {\n const bundle = await this.getCachedOrFetch();\n\n // Assign a local ID AFTER caching. If the local ID were cached, it may no longer be unique.\n bundle.localId = uniqueLocalId();\n this.storeGlobally(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 console.debug('Plasmic: doing a fresh fetch...');\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 preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18nKeyScheme,\n browserOnly: isBrowser,\n }\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(', ')}`\n );\n return data;\n }\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 // This is the code that stores the bundle.\n private storeGlobally(bundle: LoaderBundleOutput) {\n if (bundle.localId === undefined) {\n return;\n }\n\n if (global.__PLASMIC_BUNDLES === undefined) {\n global.__PLASMIC_BUNDLES = {};\n }\n global.__PLASMIC_BUNDLES[bundle.localId] = bundle;\n }\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [localId: number]: LoaderBundleOutput };\n}\nconst global = globalThis as GlobalWithBundles;\n","interface GlobalWithNextLocalId {\n __PLASMIC_NEXT_LOCAL_ID?: number;\n}\n\n/**\n * Returns an ID that is locally unique within a process.\n *\n * This function works even if this function's module is reloaded within the same process.\n * It depends on setting state in the environment's `globalThis` variable.\n */\nexport function uniqueLocalId(): number {\n const global = globalThis as GlobalWithNextLocalId;\n const localId = global.__PLASMIC_NEXT_LOCAL_ID\n ? global.__PLASMIC_NEXT_LOCAL_ID\n : 1;\n global.__PLASMIC_NEXT_LOCAL_ID = localId + 1;\n return localId;\n}\n"],"names":["isBrowser","window","document","Api","constructor","opts","this","host","[object Object]","projectIds","platform","preview","query","URLSearchParams","map","projectId","browserOnly","i18nKeyScheme","toString","url","resp","fetch","method","headers","makeGetHeaders","status","error","parseJsonResponse","Error","_error$error","message","statusText","text","JSON","parse","err","component","embedHydrate","hydrate","json","x-plasmic-loader-version","makeAuthHeaders","makePostHeaders","Content-Type","x-plasmic-api-project-tokens","projects","p","id","token","join","global","globalThis","undefined","api","bundle","getCachedOrFetch","localId","__PLASMIC_NEXT_LOCAL_ID","uniqueLocalId","storeGlobally","cache","cachedData","get","curFetch","console","debug","doFetch","data","fetchLoaderData","version","set","name","__PLASMIC_BUNDLES"],"mappings":"6JAkIA,MAEaA,EACO,oBAAXC,QACG,MAAVA,aAC2B,IAApBA,OAAOC,eAEHC,EAEXC,YACUC,SAAAC,UAAAD,EAKRC,KAAKC,cAAOF,EAAKE,QAAQ,8BAG3BC,sBACEC,EACAJ,GAOA,MAAMK,SAAEA,EAAQC,QAAEA,GAAYN,EACxBO,EAAQ,IAAIC,gBAAgB,CAChC,CAAC,iBAAYH,EAAAA,EAAY,YACtBD,EAAWK,IAAKC,GAAc,CAAC,YAAaA,OAC3CV,EAAKW,YAAc,CAAC,CAAC,cAAe,SAAW,MAC/CX,EAAKY,cAAgB,CAAC,CAAC,gBAAiBZ,EAAKY,gBAAkB,KAClEC,WAEGC,KAASb,KAAKC,2BAClBI,EAAU,UAAY,eACpBC,IACEQ,QAAaC,EAAMF,EAAK,CAC5BG,OAAQ,MACRC,QAASjB,KAAKkB,mBAEhB,GAAIJ,EAAKK,QAAU,IAAK,CAAA,QACtB,MAAMC,QAAcpB,KAAKqB,kBAAkBP,GAC3C,MAAM,IAAIQ,qDAENF,YA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,GAAID,EACF,OAAOA,EAGX,GAAIvD,KAAKyD,SACP,aAAazD,KAAKyD,SAEpBC,QAAQC,MAAM,mCACd3D,KAAKyD,SAAWzD,KAAK4D,UACrB,MAAMC,QAAa7D,KAAKyD,SAExB,OADAzD,KAAKyD,cAAWX,EACTe,EAGD3D,gBACN,MAAM2D,QAAa7D,KAAK+C,IAAIe,gBAC1B9D,KAAKD,KAAKwC,SAAS/B,IAAKgC,GACtBA,EAAEuB,WAAavB,EAAEC,MAAMD,EAAEuB,UAAYvB,EAAEC,IAEzC,CACErC,SAAUJ,KAAKD,KAAKK,SACpBC,QAASL,KAAKD,KAAKM,QACnBM,cAAeX,KAAKD,KAAKY,cACzBD,YAAahB,IAWjB,OARIM,KAAKD,KAAKuD,aACNtD,KAAKD,KAAKuD,MAAMU,IAAIH,GAE5BH,QAAQC,sCAC0BE,EAAKtB,SAClC/B,IAAKgC,OAAUA,EAAEyB,UAAUzB,EAAEC,MAAMD,EAAEuB,YACrCpB,KAAK,OAEHkB,EASDR,cAAcL,QACGF,IAAnBE,EAAOE,eAIsBJ,IAA7BF,EAAOsB,oBACTtB,EAAOsB,kBAAoB,IAE7BtB,EAAOsB,kBAAkBlB,EAAOE,SAAWF"}
1
+ {"version":3,"file":"loader-fetcher.cjs.production.min.js","sources":["../src/api.ts","../src/fetcher.ts"],"sourcesContent":["import fetch 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}\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 externalId?: string;\n type: 'experiment';\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit {\n id: 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 external: string[];\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\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 = '9';\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 constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n }\n ) {\n this.host = opts.host ?? 'https://codegen.plasmic.app';\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: 'react' | 'nextjs' | 'gatsby';\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: 'content' | 'hash';\n }\n ) {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n ['platform', platform ?? 'react'],\n ...projectIds.map((projectId) => ['projectId', projectId]),\n ...(opts.browserOnly ? [['browserOnly', 'true']] : []),\n ...(opts.i18nKeyScheme ? [['i18nKeyScheme', opts.i18nKeyScheme]] : []),\n ]).toString();\n\n const url = `${this.host}/api/v1/loader/code/${\n preview ? 'preview' : 'published'\n }?${query}`;\n const resp = await 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(`Error parsing JSON response: ${err}; response: ${text}`);\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 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 // @ts-ignore\n private makePostHeaders() {\n return {\n 'x-plasmic-loader-version': VERSION,\n 'Content-Type': 'application/json',\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","import { Api, 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 preview?: boolean;\n host?: string;\n i18nKeyScheme?: 'content' | 'hash';\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 });\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 console.debug('Plasmic: doing a fresh fetch...');\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 preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18nKeyScheme,\n browserOnly: isBrowser,\n }\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(', ')}`\n );\n return data;\n }\n\n private cacheBundleInNodeServer(bundle: LoaderBundleOutput) {\n if (isBrowser) {\n return;\n }\n\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 return global.__PLASMIC_BUNDLES?.[getBundleKey(opts)];\n}\n\nfunction getBundleKey({\n host,\n platform,\n i18nKeyScheme,\n preview,\n projects,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n platform,\n i18nKeyScheme,\n preview,\n projects,\n });\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [bundleKey: string]: LoaderBundleOutput };\n}\nconst global = globalThis as GlobalWithBundles;\n"],"names":["isBrowser","window","document","Api","constructor","opts","this","host","[object Object]","projectIds","platform","preview","query","URLSearchParams","map","projectId","browserOnly","i18nKeyScheme","toString","url","resp","fetch","method","headers","makeGetHeaders","status","error","parseJsonResponse","Error","_error$error","message","statusText","text","JSON","parse","err","component","embedHydrate","hydrate","json","x-plasmic-loader-version","makeAuthHeaders","makePostHeaders","Content-Type","x-plasmic-api-project-tokens","projects","p","id","token","join","getBundleKey","stringify","global","globalThis","undefined","api","bundle","getCachedOrFetch","cacheBundleInNodeServer","cache","cachedData","get","curFetch","console","debug","doFetch","data","fetchLoaderData","version","set","name","__PLASMIC_BUNDLES","_global$__PLASMIC_BUN"],"mappings":"yKA0HA,MAEaA,EACO,oBAAXC,QACG,MAAVA,aAC2B,IAApBA,OAAOC,eAEHC,EAEXC,YACUC,SAAAC,UAAAD,EAKRC,KAAKC,cAAOF,EAAKE,QAAQ,8BAG3BC,sBACEC,EACAJ,GAOA,MAAMK,SAAEA,EAAQC,QAAEA,GAAYN,EACxBO,EAAQ,IAAIC,gBAAgB,CAChC,CAAC,iBAAYH,EAAAA,EAAY,YACtBD,EAAWK,IAAKC,GAAc,CAAC,YAAaA,OAC3CV,EAAKW,YAAc,CAAC,CAAC,c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
1
- import fetch from 'isomorphic-unfetch';
1
+ import fetch from '@plasmicapp/isomorphic-unfetch';
2
2
 
3
3
  const VERSION = '9';
4
4
  const isBrowser = typeof window !== 'undefined' && window != null && typeof window.document !== 'undefined';
@@ -72,19 +72,6 @@ class Api {
72
72
  }
73
73
  }
74
74
 
75
- /**
76
- * Returns an ID that is locally unique within a process.
77
- *
78
- * This function works even if this function's module is reloaded within the same process.
79
- * It depends on setting state in the environment's `globalThis` variable.
80
- */
81
- function uniqueLocalId() {
82
- const global = globalThis;
83
- const localId = global.__PLASMIC_NEXT_LOCAL_ID ? global.__PLASMIC_NEXT_LOCAL_ID : 1;
84
- global.__PLASMIC_NEXT_LOCAL_ID = localId + 1;
85
- return localId;
86
- }
87
-
88
75
  class PlasmicModulesFetcher {
89
76
  constructor(opts) {
90
77
  this.opts = opts;
@@ -95,10 +82,15 @@ class PlasmicModulesFetcher {
95
82
  });
96
83
  }
97
84
  async fetchAllData() {
85
+ // getCachedOrFetched uses a cache defined by the user.
98
86
  const bundle = await this.getCachedOrFetch();
99
- // Assign a local ID AFTER caching. If the local ID were cached, it may no longer be unique.
100
- bundle.localId = uniqueLocalId();
101
- this.storeGlobally(bundle);
87
+ // For React Server Components (Next.js 13+),
88
+ // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.
89
+ // We don't want to pass them via normal page props because that will be serialized to the browser.
90
+ // Instead, we pass the bundle (including the server modules) via the Node `global` variable.
91
+ //
92
+ // cacheBundleInNodeServer caches a bundle in the Node server process.
93
+ this.cacheBundleInNodeServer(bundle);
102
94
  return bundle;
103
95
  }
104
96
  async getCachedOrFetch() {
@@ -130,23 +122,39 @@ class PlasmicModulesFetcher {
130
122
  console.debug(`Plasmic: fetched designs for ${data.projects.map(p => `"${p.name}" (${p.id}@${p.version})`).join(', ')}`);
131
123
  return data;
132
124
  }
133
- // For React Server Components (Next.js 13+),
134
- // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.
135
- // We don't want to pass them via normal page props because that will be serialized to the browser.
136
- // Instead, we pass the bundle (including the server modules) via the Node `global` variable.
137
- //
138
- // This is the code that stores the bundle.
139
- storeGlobally(bundle) {
140
- if (bundle.localId === undefined) {
125
+ cacheBundleInNodeServer(bundle) {
126
+ if (isBrowser) {
141
127
  return;
142
128
  }
143
129
  if (global.__PLASMIC_BUNDLES === undefined) {
144
130
  global.__PLASMIC_BUNDLES = {};
145
131
  }
146
- global.__PLASMIC_BUNDLES[bundle.localId] = bundle;
132
+ global.__PLASMIC_BUNDLES[getBundleKey(this.opts)] = bundle;
147
133
  }
148
134
  }
135
+ function internal_getCachedBundleInNodeServer(opts) {
136
+ var _global$__PLASMIC_BUN;
137
+ if (isBrowser) {
138
+ throw new Error(`Should not be consulting Node server cache in browser`);
139
+ }
140
+ return (_global$__PLASMIC_BUN = global.__PLASMIC_BUNDLES) == null ? void 0 : _global$__PLASMIC_BUN[getBundleKey(opts)];
141
+ }
142
+ function getBundleKey({
143
+ host,
144
+ platform,
145
+ i18nKeyScheme,
146
+ preview,
147
+ projects
148
+ }) {
149
+ return JSON.stringify({
150
+ host,
151
+ platform,
152
+ i18nKeyScheme,
153
+ preview,
154
+ projects
155
+ });
156
+ }
149
157
  const global = globalThis;
150
158
 
151
- export { Api, PlasmicModulesFetcher };
159
+ export { Api, PlasmicModulesFetcher, internal_getCachedBundleInNodeServer };
152
160
  //# sourceMappingURL=loader-fetcher.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader-fetcher.esm.js","sources":["../src/api.ts","../src/uniqueLocalId.ts","../src/fetcher.ts"],"sourcesContent":["import fetch from '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}\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 externalId?: string;\n type: 'experiment';\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit {\n id: 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 external: string[];\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\n\n // Note this property doesn't come from the API but is generated locally by this module.\n /**\n * ID used to identify LoaderBundleOutputs locally within a process.\n *\n * This property may be unset or `undefined` to indicate an \"empty\" LoaderBundleOutput.\n */\n localId?: number | undefined;\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 = '9';\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 constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n }\n ) {\n this.host = opts.host ?? 'https://codegen.plasmic.app';\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: 'react' | 'nextjs' | 'gatsby';\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: 'content' | 'hash';\n }\n ) {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n ['platform', platform ?? 'react'],\n ...projectIds.map((projectId) => ['projectId', projectId]),\n ...(opts.browserOnly ? [['browserOnly', 'true']] : []),\n ...(opts.i18nKeyScheme ? [['i18nKeyScheme', opts.i18nKeyScheme]] : []),\n ]).toString();\n\n const url = `${this.host}/api/v1/loader/code/${\n preview ? 'preview' : 'published'\n }?${query}`;\n const resp = await 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(`Error parsing JSON response: ${err}; response: ${text}`);\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 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 // @ts-ignore\n private makePostHeaders() {\n return {\n 'x-plasmic-loader-version': VERSION,\n 'Content-Type': 'application/json',\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","interface GlobalWithNextLocalId {\n __PLASMIC_NEXT_LOCAL_ID?: number;\n}\n\n/**\n * Returns an ID that is locally unique within a process.\n *\n * This function works even if this function's module is reloaded within the same process.\n * It depends on setting state in the environment's `globalThis` variable.\n */\nexport function uniqueLocalId(): number {\n const global = globalThis as GlobalWithNextLocalId;\n const localId = global.__PLASMIC_NEXT_LOCAL_ID\n ? global.__PLASMIC_NEXT_LOCAL_ID\n : 1;\n global.__PLASMIC_NEXT_LOCAL_ID = localId + 1;\n return localId;\n}\n","import { Api, isBrowser, LoaderBundleOutput } from './api';\nimport { uniqueLocalId } from './uniqueLocalId';\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 preview?: boolean;\n host?: string;\n i18nKeyScheme?: 'content' | 'hash';\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 });\n }\n\n async fetchAllData() {\n const bundle = await this.getCachedOrFetch();\n\n // Assign a local ID AFTER caching. If the local ID were cached, it may no longer be unique.\n bundle.localId = uniqueLocalId();\n this.storeGlobally(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 console.debug('Plasmic: doing a fresh fetch...');\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 preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18nKeyScheme,\n browserOnly: isBrowser,\n }\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(', ')}`\n );\n return data;\n }\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 // This is the code that stores the bundle.\n private storeGlobally(bundle: LoaderBundleOutput) {\n if (bundle.localId === undefined) {\n return;\n }\n\n if (global.__PLASMIC_BUNDLES === undefined) {\n global.__PLASMIC_BUNDLES = {};\n }\n global.__PLASMIC_BUNDLES[bundle.localId] = bundle;\n }\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [localId: number]: LoaderBundleOutput };\n}\nconst global = globalThis as GlobalWithBundles;\n"],"names":["VERSION","isBrowser","window","document","Api","constructor","opts","host","fetchLoaderData","projectIds","platform","preview","query","URLSearchParams","map","projectId","browserOnly","i18nKeyScheme","toString","url","resp","fetch","method","headers","makeGetHeaders","status","error","parseJsonResponse","Error","message","statusText","json","text","JSON","parse","err","fetchHtmlData","component","embedHydrate","hydrate","makeAuthHeaders","makePostHeaders","tokens","projects","p","id","token","join","uniqueLocalId","global","globalThis","localId","__PLASMIC_NEXT_LOCAL_ID","PlasmicModulesFetcher","undefined","api","fetchAllData","bundle","getCachedOrFetch","storeGlobally","cache","cachedData","get","curFetch","console","debug","doFetch","data","version","set","name","__PLASMIC_BUNDLES"],"mappings":";;AAkIA,MAAMA,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,"file":"loader-fetcher.esm.js","sources":["../src/api.ts","../src/fetcher.ts"],"sourcesContent":["import fetch 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}\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 externalId?: string;\n type: 'experiment';\n slices: ExperimentSlice[];\n}\n\nexport interface SegmentSplit {\n id: 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 external: string[];\n components: ComponentMeta[];\n globalGroups: GlobalGroupMeta[];\n projects: ProjectMeta[];\n activeSplits: Split[];\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 = '9';\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 constructor(\n private opts: {\n projects: { id: string; token: string }[];\n host?: string;\n }\n ) {\n this.host = opts.host ?? 'https://codegen.plasmic.app';\n }\n\n async fetchLoaderData(\n projectIds: string[],\n opts: {\n platform?: 'react' | 'nextjs' | 'gatsby';\n preview?: boolean;\n browserOnly?: boolean;\n i18nKeyScheme?: 'content' | 'hash';\n }\n ) {\n const { platform, preview } = opts;\n const query = new URLSearchParams([\n ['platform', platform ?? 'react'],\n ...projectIds.map((projectId) => ['projectId', projectId]),\n ...(opts.browserOnly ? [['browserOnly', 'true']] : []),\n ...(opts.i18nKeyScheme ? [['i18nKeyScheme', opts.i18nKeyScheme]] : []),\n ]).toString();\n\n const url = `${this.host}/api/v1/loader/code/${\n preview ? 'preview' : 'published'\n }?${query}`;\n const resp = await 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(`Error parsing JSON response: ${err}; response: ${text}`);\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 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 // @ts-ignore\n private makePostHeaders() {\n return {\n 'x-plasmic-loader-version': VERSION,\n 'Content-Type': 'application/json',\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","import { Api, 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 preview?: boolean;\n host?: string;\n i18nKeyScheme?: 'content' | 'hash';\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 });\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 console.debug('Plasmic: doing a fresh fetch...');\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 preview: this.opts.preview,\n i18nKeyScheme: this.opts.i18nKeyScheme,\n browserOnly: isBrowser,\n }\n );\n if (this.opts.cache) {\n await this.opts.cache.set(data);\n }\n console.debug(\n `Plasmic: fetched designs for ${data.projects\n .map((p) => `\"${p.name}\" (${p.id}@${p.version})`)\n .join(', ')}`\n );\n return data;\n }\n\n private cacheBundleInNodeServer(bundle: LoaderBundleOutput) {\n if (isBrowser) {\n return;\n }\n\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 return global.__PLASMIC_BUNDLES?.[getBundleKey(opts)];\n}\n\nfunction getBundleKey({\n host,\n platform,\n i18nKeyScheme,\n preview,\n projects,\n}: FetcherOptions) {\n return JSON.stringify({\n host,\n platform,\n i18nKeyScheme,\n preview,\n projects,\n });\n}\n\ninterface GlobalWithBundles {\n __PLASMIC_BUNDLES?: { [bundleKey: string]: LoaderBundleOutput };\n}\nconst global = globalThis as GlobalWithBundles;\n"],"names":["VERSION","isBrowser","window","document","Api","constructor","opts","host","fetchLoaderData","projectIds","platform","preview","query","URLSearchParams","map","projectId","browserOnly","i18nKeyScheme","toString","url","resp","fetch","method","headers","makeGetHeaders","status","error","parseJsonResponse","Error","message","statusText","json","text","JSON","parse","err","fetchHtmlData","component","embedHydrate","hydrate","makeAuthHeaders","makePostHeaders","tokens","projects","p","id","token","join","PlasmicModulesFetcher","undefined","api","fetchAllData","bundle","getCachedOrFetch","cacheBundleInNodeServer","cache","cachedData","get","curFetch","console","debug","doFetch","data","version","set","name","global","__PLASMIC_BUNDLES","getBundleKey","internal_getCachedBundleInNodeServer","stringify","globalThis"],"mappings":";;AA0HA,MAAMA,OAAO,GAAG,GAAG;AAEZ,MAAMC,SAAS,GACpB,OAAOC,MAAM,KAAK,WAAW,IAC7BA,MAAM,IAAI,IAAI,IACd,OAAOA,MAAM,CAACC,QAAQ,KAAK,WAAW;MAE3BC,GAAG;EAEdC,YACUC,IAGP;;IAHO,SAAI,GAAJA,IAAI;IAKZ,IAAI,CAACC,IAAI,iBAAGD,IAAI,CAACC,IAAI,yBAAI,6BAA6B;;EAGxD,MAAMC,eAAe,CACnBC,UAAoB,EACpBH,IAKC;IAED,MAAM;MAAEI,QAAQ;MAAEC;KAAS,GAAGL,IAAI;IAClC,MAAMM,KAAK,GAAG,IAAIC,eAAe,CAAC,CAChC,CAAC,UAAU,EAAEH,QAAQ,WAARA,QAAQ,GAAI,OAAO,CAAC,EACjC,GAAGD,UAAU,CAACK,GAAG,CAAEC,SAAS,IAAK,CAAC,WAAW,EAAEA,SAAS,CAAC,CAAC,EAC1D,IAAIT,IAAI,CAACU,WAAW,GAAG,CAAC,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EACtD,IAAIV,IAAI,CAACW,aAAa,GAAG,CAAC,CAAC,eAAe,EAAEX,IAAI,CAACW,aAAa,CAAC,CAAC,GAAG,EAAE,CAAC,CACvE,CAAC,CAACC,QAAQ,EAAE;IAEb,MAAMC,GAAG,MAAM,IAAI,CAACZ,2BAClBI,OAAO,GAAG,SAAS,GAAG,eACpBC,OAAO;IACX,MAAMQ,IAAI,GAAG,MAAMC,KAAK,CAACF,GAAG,EAAE;MAC5BG,MAAM,EAAE,KAAK;MACbC,OAAO,EAAE,IAAI,CAACC,cAAc;KAC7B,CAAC;IACF,IAAIJ,IAAI,CAACK,MAAM,IAAI,GAAG,EAAE;MAAA;MACtB,MAAMC,KAAK,GAAG,MAAM,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SAAS8D,YAAY,CAAC;EACpB7D,IAAI;EACJG,QAAQ;EACRO,aAAa;EACbN,OAAO;EACPgC;CACe;EACf,OAAOV,IAAI,CAACqC,SAAS,CAAC;IACpB/D,IAAI;IACJG,QAAQ;IACRO,aAAa;IACbN,OAAO;IACPgC;GACD,CAAC;AACJ;AAKA,MAAMuB,MAAM,GAAGK,UAA+B;;;;"}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.17",
2
+ "version": "1.0.19",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -46,7 +46,6 @@
46
46
  ],
47
47
  "devDependencies": {
48
48
  "@size-limit/preset-small-lib": "^4.11.0",
49
- "@types/isomorphic-fetch": "^0.0.35",
50
49
  "husky": "^6.0.0",
51
50
  "size-limit": "^4.11.0",
52
51
  "tsdx": "^0.14.1",
@@ -54,10 +53,10 @@
54
53
  "typescript": "^4.3.2"
55
54
  },
56
55
  "dependencies": {
57
- "isomorphic-unfetch": "^3.1.0"
56
+ "@plasmicapp/isomorphic-unfetch": "^1.0.1"
58
57
  },
59
58
  "publishConfig": {
60
59
  "access": "public"
61
60
  },
62
- "gitHead": "1c887fa678139c20811ff9941a40eef8e7aaa50b"
61
+ "gitHead": "1a11e260711c67b16c0703de62e6d108a12fa2d9"
63
62
  }
@@ -1,7 +0,0 @@
1
- /**
2
- * Returns an ID that is locally unique within a process.
3
- *
4
- * This function works even if this function's module is reloaded within the same process.
5
- * It depends on setting state in the environment's `globalThis` variable.
6
- */
7
- export declare function uniqueLocalId(): number;