@plasmicapp/loader-fetcher 1.0.13 → 1.0.15
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 +1 -0
- package/dist/fetcher.d.ts +1 -0
- package/dist/loader-fetcher.cjs.development.js +5 -24
- package/dist/loader-fetcher.cjs.development.js.map +1 -1
- package/dist/loader-fetcher.cjs.production.min.js +1 -1
- package/dist/loader-fetcher.cjs.production.min.js.map +1 -1
- package/dist/loader-fetcher.esm.js +5 -24
- package/dist/loader-fetcher.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/api.d.ts
CHANGED
|
@@ -116,6 +116,7 @@ export declare class Api {
|
|
|
116
116
|
platform?: 'react' | 'nextjs' | 'gatsby';
|
|
117
117
|
preview?: boolean;
|
|
118
118
|
browserOnly?: boolean;
|
|
119
|
+
i18nKeyScheme?: 'content' | 'hash';
|
|
119
120
|
}): Promise<LoaderBundleOutput>;
|
|
120
121
|
private parseJsonResponse;
|
|
121
122
|
fetchHtmlData(opts: {
|
package/dist/fetcher.d.ts
CHANGED
|
@@ -11,44 +11,36 @@ const isBrowser = typeof window !== 'undefined' && window != null && typeof wind
|
|
|
11
11
|
class Api {
|
|
12
12
|
constructor(opts) {
|
|
13
13
|
var _opts$host;
|
|
14
|
-
|
|
15
14
|
this.opts = opts;
|
|
16
15
|
this.host = (_opts$host = opts.host) != null ? _opts$host : 'https://codegen.plasmic.app';
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
async fetchLoaderData(projectIds, opts) {
|
|
20
18
|
const {
|
|
21
19
|
platform,
|
|
22
20
|
preview
|
|
23
21
|
} = opts;
|
|
24
|
-
const query = new URLSearchParams([['platform', platform != null ? platform : 'react'], ...projectIds.map(projectId => ['projectId', projectId]), ...(opts.browserOnly ? [['browserOnly', 'true']] : [])]).toString();
|
|
22
|
+
const query = new URLSearchParams([['platform', platform != null ? platform : 'react'], ...projectIds.map(projectId => ['projectId', projectId]), ...(opts.browserOnly ? [['browserOnly', 'true']] : []), ...(opts.i18nKeyScheme ? [['i18nKeyScheme', opts.i18nKeyScheme]] : [])]).toString();
|
|
25
23
|
const url = `${this.host}/api/v1/loader/code/${preview ? 'preview' : 'published'}?${query}`;
|
|
26
24
|
const resp = await fetch(url, {
|
|
27
25
|
method: 'GET',
|
|
28
26
|
headers: this.makeGetHeaders()
|
|
29
27
|
});
|
|
30
|
-
|
|
31
28
|
if (resp.status >= 400) {
|
|
32
29
|
var _error$error$message, _error$error;
|
|
33
|
-
|
|
34
30
|
const error = await this.parseJsonResponse(resp);
|
|
35
31
|
throw new Error(`Error fetching loader data: ${(_error$error$message = error == null ? void 0 : (_error$error = error.error) == null ? void 0 : _error$error.message) != null ? _error$error$message : resp.statusText}`);
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
const json = await this.parseJsonResponse(resp);
|
|
39
34
|
return json;
|
|
40
35
|
}
|
|
41
|
-
|
|
42
36
|
async parseJsonResponse(resp) {
|
|
43
37
|
const text = await resp.text();
|
|
44
|
-
|
|
45
38
|
try {
|
|
46
39
|
return JSON.parse(text);
|
|
47
40
|
} catch (err) {
|
|
48
41
|
throw new Error(`Error parsing JSON response: ${err}; response: ${text}`);
|
|
49
42
|
}
|
|
50
43
|
}
|
|
51
|
-
|
|
52
44
|
async fetchHtmlData(opts) {
|
|
53
45
|
const {
|
|
54
46
|
projectId,
|
|
@@ -64,15 +56,13 @@ class Api {
|
|
|
64
56
|
const json = await resp.json();
|
|
65
57
|
return json;
|
|
66
58
|
}
|
|
67
|
-
|
|
68
59
|
makeGetHeaders() {
|
|
69
60
|
return {
|
|
70
61
|
'x-plasmic-loader-version': VERSION,
|
|
71
62
|
...this.makeAuthHeaders()
|
|
72
63
|
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
}
|
|
65
|
+
// @ts-ignore
|
|
76
66
|
makePostHeaders() {
|
|
77
67
|
return {
|
|
78
68
|
'x-plasmic-loader-version': VERSION,
|
|
@@ -80,14 +70,12 @@ class Api {
|
|
|
80
70
|
...this.makeAuthHeaders()
|
|
81
71
|
};
|
|
82
72
|
}
|
|
83
|
-
|
|
84
73
|
makeAuthHeaders() {
|
|
85
74
|
const tokens = this.opts.projects.map(p => `${p.id}:${p.token}`).join(',');
|
|
86
75
|
return {
|
|
87
76
|
'x-plasmic-api-project-tokens': tokens
|
|
88
77
|
};
|
|
89
78
|
}
|
|
90
|
-
|
|
91
79
|
}
|
|
92
80
|
|
|
93
81
|
class PlasmicModulesFetcher {
|
|
@@ -99,42 +87,35 @@ class PlasmicModulesFetcher {
|
|
|
99
87
|
host: opts.host
|
|
100
88
|
});
|
|
101
89
|
}
|
|
102
|
-
|
|
103
90
|
async fetchAllData() {
|
|
104
91
|
if (this.opts.cache) {
|
|
105
92
|
const cachedData = await this.opts.cache.get();
|
|
106
|
-
|
|
107
93
|
if (cachedData) {
|
|
108
94
|
return cachedData;
|
|
109
95
|
}
|
|
110
96
|
}
|
|
111
|
-
|
|
112
97
|
if (this.curFetch) {
|
|
113
98
|
return await this.curFetch;
|
|
114
99
|
}
|
|
115
|
-
|
|
116
100
|
console.debug('Plasmic: doing a fresh fetch...');
|
|
117
101
|
this.curFetch = this.doFetch();
|
|
118
102
|
const data = await this.curFetch;
|
|
119
103
|
this.curFetch = undefined;
|
|
120
104
|
return data;
|
|
121
105
|
}
|
|
122
|
-
|
|
123
106
|
async doFetch() {
|
|
124
|
-
const data = await this.api.fetchLoaderData(this.opts.projects.map(p => p.version
|
|
107
|
+
const data = await this.api.fetchLoaderData(this.opts.projects.map(p => p.version ? `${p.id}@${p.version}` : p.id), {
|
|
125
108
|
platform: this.opts.platform,
|
|
126
109
|
preview: this.opts.preview,
|
|
110
|
+
i18nKeyScheme: this.opts.i18nKeyScheme,
|
|
127
111
|
browserOnly: isBrowser
|
|
128
112
|
});
|
|
129
|
-
|
|
130
113
|
if (this.opts.cache) {
|
|
131
114
|
await this.opts.cache.set(data);
|
|
132
115
|
}
|
|
133
|
-
|
|
134
116
|
console.debug(`Plasmic: fetched designs for ${data.projects.map(p => `"${p.name}" (${p.id}@${p.version})`).join(', ')}`);
|
|
135
117
|
return data;
|
|
136
118
|
}
|
|
137
|
-
|
|
138
119
|
}
|
|
139
120
|
|
|
140
121
|
exports.Api = Api;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-fetcher.cjs.development.js","sources":["../src/api.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\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 }\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 ]).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}\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 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 && !this.opts.preview ? `${p.id}@${p.version}` : p.id\n ),\n {\n platform: this.opts.platform,\n preview: this.opts.preview,\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"],"names":["VERSION","isBrowser","window","document","Api","constructor","opts","host","fetchLoaderData","projectIds","platform","preview","query","URLSearchParams","map","projectId","browserOnly","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","cache","cachedData","get","curFetch","console","debug","doFetch","data","version","set","name"],"mappings":";;;;;;;;AA0HA,MAAMA,OAAO,GAAG,GAAhB;AAEO,MAAMC,SAAS,GACpB,OAAOC,MAAP,KAAkB,WAAlB,IACAA,MAAM,IAAI,IADV,IAEA,OAAOA,MAAM,CAACC,QAAd,KAA2B,WAHtB;MAKMC;AAEXC,EAAAA,YACUC;;;AAAA,aAAA,GAAAA,IAAA;AAKR,SAAKC,IAAL,iBAAYD,IAAI,CAACC,IAAjB,yBAAyB,6BAAzB;AACD;;AAEoB,QAAfC,eAAe,CACnBC,UADmB,EAEnBH,IAFmB;AAQnB,UAAM;AAAEI,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,QAAwBL,IAA9B;AACA,UAAMM,KAAK,GAAG,IAAIC,eAAJ,CAAoB,CAChC,CAAC,UAAD,EAAaH,QAAb,WAAaA,QAAb,GAAyB,OAAzB,CADgC,EAEhC,GAAGD,UAAU,CAACK,GAAX,CAAgBC,SAAD,IAAe,CAAC,WAAD,EAAcA,SAAd,CAA9B,CAF6B,EAGhC,IAAIT,IAAI,CAACU,WAAL,GAAmB,CAAC,CAAC,aAAD,EAAgB,MAAhB,CAAD,CAAnB,GAA+C,EAAnD,CAHgC,CAApB,EAIXC,QAJW,EAAd;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B;AACjB,aAAO,MAAM,KAAKA,QAAlB;AACD;;AACDC,IAAAA,OAAO,CAACC,KAAR,CAAc,iCAAd;AACA,SAAKF,QAAL,GAAgB,KAAKG,OAAL,EAAhB;AACA,UAAMC,IAAI,GAAG,MAAM,KAAKJ,QAAxB;AACA,SAAKA,QAAL,GAAgBN,SAAhB;AACA,WAAOU,IAAP;AACD;;AAEoB,QAAPD,OAAO;AACnB,UAAMC,IAAI,GAAG,MAAM,KAAKT,GAAL,CAASzC,eAAT,CACjB,KAAKF,IAAL,CAAUoC,QAAV,CAAmB5B,GAAnB,CAAwB6B,CAAD,IACrBA,CAAC,CAACgB,OAAF,IAAa,CAAC,KAAKrD,IAAL,CAAUK,OAAxB,MAAqCgC,CAAC,CAACC,MAAMD,CAAC,CAACgB,SAA/C,GAA2DhB,CAAC,CAACC,EAD/D,CADiB,EAIjB;AACElC,MAAAA,QAAQ,EAAE,KAAKJ,IAAL,CAAUI,QADtB;AAEEC,MAAAA,OAAO,EAAE,KAAKL,IAAL,CAAUK,OAFrB;AAGEK,MAAAA,WAAW,EAAEf;AAHf,KAJiB,CAAnB;;AAUA,QAAI,KAAKK,IAAL,CAAU6C,KAAd,EAAqB;AACnB,YAAM,KAAK7C,IAAL,CAAU6C,KAAV,CAAgBS,GAAhB,CAAoBF,IAApB,CAAN;AACD;;AACDH,IAAAA,OAAO,CAACC,KAAR,iCACkCE,IAAI,CAAChB,QAAL,CAC7B5B,GAD6B,CACxB6B,CAAD,QAAWA,CAAC,CAACkB,UAAUlB,CAAC,CAACC,MAAMD,CAAC,CAACgB,UADR,EAE7Bb,IAF6B,CAExB,IAFwB,GADlC;AAKA,WAAOY,IAAP;AACD;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"loader-fetcher.cjs.development.js","sources":["../src/api.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\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 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"],"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","cache","cachedData","get","curFetch","console","debug","doFetch","data","version","set","name"],"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,KA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AI,GAAG,MAAM,IAAI,CAACT,GAAG,CAAC1C,eAAe,CACzC,IAAI,CAACF,IAAI,CAACqC,QAAQ,CAAC7B,GAAG,CAAE8B,CAAC,IACvBA,CAAC,CAACgB,OAAO,MAAMhB,CAAC,CAACC,MAAMD,CAAC,CAACgB,SAAS,GAAGhB,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,CAAC8C,KAAK,EAAE;MACnB,MAAM,IAAI,CAAC9C,IAAI,CAAC8C,KAAK,CAACS,GAAG,CAACF,IAAI,CAAC;;IAEjCH,OAAO,CAACC,KAAK,iCACqBE,IAAI,CAAChB,QAAQ,CAC1C7B,GAAG,CAAE8B,CAAC,QAASA,CAAC,CAACkB,UAAUlB,CAAC,CAACC,MAAMD,CAAC,CAACgB,UAAU,CAAC,CAChDb,IAAI,CAAC,IAAI,GAAG,CAChB;IACD,OAAOY,IAAI;;;;;;;"}
|
|
@@ -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"]]:[]]).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:s,component:r,embedHydrate:o,hydrate:a}=e,i=new URLSearchParams([["projectId",s],["component",r],["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(",")}}}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(){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
|
|
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}`,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:s,component:r,embedHydrate:o,hydrate:a}=e,i=new URLSearchParams([["projectId",s],["component",r],["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(",")}}}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(){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}};
|
|
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"],"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\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 }\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 ]).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}\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 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
|
|
1
|
+
{"version":3,"file":"loader-fetcher.cjs.production.min.js","sources":["../src/api.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\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 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"],"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","undefined","api","cache","cachedData","get","curFetch","console","debug","doFetch","data","fetchLoaderData","version","set","name"],"mappings":"6JA0HA,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,YAAAA,EAAOA,cAAPG,EAAcC,WAAWV,EAAKW,aAKpC,aADmBzB,KAAKqB,kBAAkBP,GAIpCZ,wBAAwBY,GAC9B,MAAMY,QAAaZ,EAAKY,OACxB,IACE,OAAOC,KAAKC,MAAMF,GAClB,MAAOG,GACP,MAAM,IAAIP,sCAAsCO,gBAAkBH,MAItExB,oBAAoBH,GAMlB,MAAMU,UAAEA,EAASqB,UAAEA,EAASC,aAAEA,EAAYC,QAAEA,GAAYjC,EAClDO,EAAQ,IAAIC,gBAAgB,CAChC,CAAC,YAAaE,GACd,CAAC,YAAaqB,GACd,CAAC,eAAgBC,EAAe,IAAM,KACtC,CAAC,UAAWC,EAAU,IAAM,OAC3BpB,WACGE,QAAaC,KAASf,KAAKC,2BAA2BK,IAAS,CACnEU,OAAQ,MACRC,QAASjB,KAAKkB,mBAGhB,aADmBJ,EAAKmB,OAIlBf,iBACN,MAAO,CACLgB,2BAtFU,OAuFPlC,KAAKmC,mBAKJC,kBACN,MAAO,CACLF,2BA9FU,IA+FVG,eAAgB,sBACbrC,KAAKmC,mBAIJA,kBAIN,MAAO,CACLG,+BAJatC,KAAKD,KAAKwC,SACtB/B,IAAKgC,MAASA,EAAEC,MAAMD,EAAEE,SACxBC,KAAK,yDC1MV7C,YAAoBC,GAAAC,UAAAD,EADZC,mBAAoD4C,EAE1D5C,KAAK6C,IAAM,IAAIhD,EAAI,CACjB0C,SAAUxC,EAAKwC,SACftC,KAAMF,EAAKE,OAIfC,qBACE,GAAIF,KAAKD,KAAK+C,MAAO,CACnB,MAAMC,QAAmB/C,KAAKD,KAAK+C,MAAME,MACzC,GAAID,EACF,OAAOA,EAGX,GAAI/C,KAAKiD,SACP,aAAajD,KAAKiD,SAEpBC,QAAQC,MAAM,mCACdnD,KAAKiD,SAAWjD,KAAKoD,UACrB,MAAMC,QAAarD,KAAKiD,SAExB,OADAjD,KAAKiD,cAAWL,EACTS,EAGDnD,gBACN,MAAMmD,QAAarD,KAAK6C,IAAIS,gBAC1BtD,KAAKD,KAAKwC,SAAS/B,IAAKgC,GACtBA,EAAEe,WAAaf,EAAEC,MAAMD,EAAEe,UAAYf,EAAEC,IAEzC,CACErC,SAAUJ,KAAKD,KAAKK,SACpBC,QAASL,KAAKD,KAAKM,QACnBM,cAAeX,KAAKD,KAAKY,cACzBD,YAAahB,IAWjB,OARIM,KAAKD,KAAK+C,aACN9C,KAAKD,KAAK+C,MAAMU,IAAIH,GAE5BH,QAAQC,sCAC0BE,EAAKd,SAClC/B,IAAKgC,OAAUA,EAAEiB,UAAUjB,EAAEC,MAAMD,EAAEe,YACrCZ,KAAK,OAEHU"}
|
|
@@ -5,44 +5,36 @@ const isBrowser = typeof window !== 'undefined' && window != null && typeof wind
|
|
|
5
5
|
class Api {
|
|
6
6
|
constructor(opts) {
|
|
7
7
|
var _opts$host;
|
|
8
|
-
|
|
9
8
|
this.opts = opts;
|
|
10
9
|
this.host = (_opts$host = opts.host) != null ? _opts$host : 'https://codegen.plasmic.app';
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
async fetchLoaderData(projectIds, opts) {
|
|
14
12
|
const {
|
|
15
13
|
platform,
|
|
16
14
|
preview
|
|
17
15
|
} = opts;
|
|
18
|
-
const query = new URLSearchParams([['platform', platform != null ? platform : 'react'], ...projectIds.map(projectId => ['projectId', projectId]), ...(opts.browserOnly ? [['browserOnly', 'true']] : [])]).toString();
|
|
16
|
+
const query = new URLSearchParams([['platform', platform != null ? platform : 'react'], ...projectIds.map(projectId => ['projectId', projectId]), ...(opts.browserOnly ? [['browserOnly', 'true']] : []), ...(opts.i18nKeyScheme ? [['i18nKeyScheme', opts.i18nKeyScheme]] : [])]).toString();
|
|
19
17
|
const url = `${this.host}/api/v1/loader/code/${preview ? 'preview' : 'published'}?${query}`;
|
|
20
18
|
const resp = await fetch(url, {
|
|
21
19
|
method: 'GET',
|
|
22
20
|
headers: this.makeGetHeaders()
|
|
23
21
|
});
|
|
24
|
-
|
|
25
22
|
if (resp.status >= 400) {
|
|
26
23
|
var _error$error$message, _error$error;
|
|
27
|
-
|
|
28
24
|
const error = await this.parseJsonResponse(resp);
|
|
29
25
|
throw new Error(`Error fetching loader data: ${(_error$error$message = error == null ? void 0 : (_error$error = error.error) == null ? void 0 : _error$error.message) != null ? _error$error$message : resp.statusText}`);
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
const json = await this.parseJsonResponse(resp);
|
|
33
28
|
return json;
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
async parseJsonResponse(resp) {
|
|
37
31
|
const text = await resp.text();
|
|
38
|
-
|
|
39
32
|
try {
|
|
40
33
|
return JSON.parse(text);
|
|
41
34
|
} catch (err) {
|
|
42
35
|
throw new Error(`Error parsing JSON response: ${err}; response: ${text}`);
|
|
43
36
|
}
|
|
44
37
|
}
|
|
45
|
-
|
|
46
38
|
async fetchHtmlData(opts) {
|
|
47
39
|
const {
|
|
48
40
|
projectId,
|
|
@@ -58,15 +50,13 @@ class Api {
|
|
|
58
50
|
const json = await resp.json();
|
|
59
51
|
return json;
|
|
60
52
|
}
|
|
61
|
-
|
|
62
53
|
makeGetHeaders() {
|
|
63
54
|
return {
|
|
64
55
|
'x-plasmic-loader-version': VERSION,
|
|
65
56
|
...this.makeAuthHeaders()
|
|
66
57
|
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
}
|
|
59
|
+
// @ts-ignore
|
|
70
60
|
makePostHeaders() {
|
|
71
61
|
return {
|
|
72
62
|
'x-plasmic-loader-version': VERSION,
|
|
@@ -74,14 +64,12 @@ class Api {
|
|
|
74
64
|
...this.makeAuthHeaders()
|
|
75
65
|
};
|
|
76
66
|
}
|
|
77
|
-
|
|
78
67
|
makeAuthHeaders() {
|
|
79
68
|
const tokens = this.opts.projects.map(p => `${p.id}:${p.token}`).join(',');
|
|
80
69
|
return {
|
|
81
70
|
'x-plasmic-api-project-tokens': tokens
|
|
82
71
|
};
|
|
83
72
|
}
|
|
84
|
-
|
|
85
73
|
}
|
|
86
74
|
|
|
87
75
|
class PlasmicModulesFetcher {
|
|
@@ -93,42 +81,35 @@ class PlasmicModulesFetcher {
|
|
|
93
81
|
host: opts.host
|
|
94
82
|
});
|
|
95
83
|
}
|
|
96
|
-
|
|
97
84
|
async fetchAllData() {
|
|
98
85
|
if (this.opts.cache) {
|
|
99
86
|
const cachedData = await this.opts.cache.get();
|
|
100
|
-
|
|
101
87
|
if (cachedData) {
|
|
102
88
|
return cachedData;
|
|
103
89
|
}
|
|
104
90
|
}
|
|
105
|
-
|
|
106
91
|
if (this.curFetch) {
|
|
107
92
|
return await this.curFetch;
|
|
108
93
|
}
|
|
109
|
-
|
|
110
94
|
console.debug('Plasmic: doing a fresh fetch...');
|
|
111
95
|
this.curFetch = this.doFetch();
|
|
112
96
|
const data = await this.curFetch;
|
|
113
97
|
this.curFetch = undefined;
|
|
114
98
|
return data;
|
|
115
99
|
}
|
|
116
|
-
|
|
117
100
|
async doFetch() {
|
|
118
|
-
const data = await this.api.fetchLoaderData(this.opts.projects.map(p => p.version
|
|
101
|
+
const data = await this.api.fetchLoaderData(this.opts.projects.map(p => p.version ? `${p.id}@${p.version}` : p.id), {
|
|
119
102
|
platform: this.opts.platform,
|
|
120
103
|
preview: this.opts.preview,
|
|
104
|
+
i18nKeyScheme: this.opts.i18nKeyScheme,
|
|
121
105
|
browserOnly: isBrowser
|
|
122
106
|
});
|
|
123
|
-
|
|
124
107
|
if (this.opts.cache) {
|
|
125
108
|
await this.opts.cache.set(data);
|
|
126
109
|
}
|
|
127
|
-
|
|
128
110
|
console.debug(`Plasmic: fetched designs for ${data.projects.map(p => `"${p.name}" (${p.id}@${p.version})`).join(', ')}`);
|
|
129
111
|
return data;
|
|
130
112
|
}
|
|
131
|
-
|
|
132
113
|
}
|
|
133
114
|
|
|
134
115
|
export { Api, PlasmicModulesFetcher };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-fetcher.esm.js","sources":["../src/api.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\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 }\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 ]).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}\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 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 && !this.opts.preview ? `${p.id}@${p.version}` : p.id\n ),\n {\n platform: this.opts.platform,\n preview: this.opts.preview,\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"],"names":["VERSION","isBrowser","window","document","Api","constructor","opts","host","fetchLoaderData","projectIds","platform","preview","query","URLSearchParams","map","projectId","browserOnly","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","cache","cachedData","get","curFetch","console","debug","doFetch","data","version","set","name"],"mappings":";;AA0HA,MAAMA,OAAO,GAAG,GAAhB;AAEO,MAAMC,SAAS,GACpB,OAAOC,MAAP,KAAkB,WAAlB,IACAA,MAAM,IAAI,IADV,IAEA,OAAOA,MAAM,CAACC,QAAd,KAA2B,WAHtB;MAKMC;AAEXC,EAAAA,YACUC;;;AAAA,aAAA,GAAAA,IAAA;AAKR,SAAKC,IAAL,iBAAYD,IAAI,CAACC,IAAjB,yBAAyB,6BAAzB;AACD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6C,KAAV,CAAgBS,GAAhB,CAAoBF,IAApB,CAAN;AACD;;AACDH,IAAAA,OAAO,CAACC,KAAR,iCACkCE,IAAI,CAAChB,QAAL,CAC7B5B,GAD6B,CACxB6B,CAAD,QAAWA,CAAC,CAACkB,UAAUlB,CAAC,CAACC,MAAMD,CAAC,CAACgB,UADR,EAE7Bb,IAF6B,CAExB,IAFwB,GADlC;AAKA,WAAOY,IAAP;AACD;;;;;;"}
|
|
1
|
+
{"version":3,"file":"loader-fetcher.esm.js","sources":["../src/api.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\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 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"],"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","cache","cachedData","get","curFetch","console","debug","doFetch","data","version","set","name"],"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,I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1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.15",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "e282c9cca3a168a822b34a1a5e6de3a6a072c00f"
|
|
62
62
|
}
|