@fayz-ai/sdk 0.10.1 → 0.12.0
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/README.md +1 -1
- package/dist/automations.d.ts +94 -0
- package/dist/automations.d.ts.map +1 -0
- package/dist/automations.js +61 -0
- package/dist/automations.js.map +1 -0
- package/dist/{chunk-7UXTYT6I.js → chunk-4YRHC5N7.js} +490 -31
- package/dist/chunk-4YRHC5N7.js.map +1 -0
- package/dist/chunk-7TTGX2SM.js +135 -0
- package/dist/chunk-7TTGX2SM.js.map +1 -0
- package/dist/events.d.ts +48 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +101 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +307 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/app-shell-pwa.d.ts +13 -0
- package/dist/lib/app-shell-pwa.d.ts.map +1 -0
- package/dist/lib/boot-skeleton.d.ts +33 -0
- package/dist/lib/boot-skeleton.d.ts.map +1 -0
- package/dist/lib/connector-oauth.d.ts +118 -0
- package/dist/lib/connector-oauth.d.ts.map +1 -0
- package/dist/lib/credentials.d.ts +98 -0
- package/dist/lib/credentials.d.ts.map +1 -0
- package/dist/lib/dedupe-fetch.d.ts +26 -0
- package/dist/lib/dedupe-fetch.d.ts.map +1 -0
- package/dist/lib/platform-url.d.ts +15 -0
- package/dist/lib/platform-url.d.ts.map +1 -0
- package/dist/lib/runtime-token.d.ts +104 -0
- package/dist/lib/runtime-token.d.ts.map +1 -0
- package/dist/release-channels.js +1 -1
- package/dist/release-channels.json +93 -93
- package/dist/shop.d.ts +381 -11
- package/dist/shop.d.ts.map +1 -1
- package/dist/shop.js +1 -1
- package/dist/vite.d.ts +19 -0
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +374 -47
- package/dist/vite.js.map +1 -1
- package/package.json +9 -1
- package/dist/chunk-7UXTYT6I.js.map +0 -1
- package/dist/chunk-KVMRRT3O.js +0 -135
- package/dist/chunk-KVMRRT3O.js.map +0 -1
package/dist/vite.js
CHANGED
|
@@ -1,64 +1,382 @@
|
|
|
1
|
-
import { existsSync } from 'fs';
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'fs';
|
|
2
2
|
import { resolve } from 'path';
|
|
3
|
+
import { createHash } from 'crypto';
|
|
3
4
|
|
|
4
5
|
// src/vite.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
6
|
+
var SW_FILE = "sw.js";
|
|
7
|
+
var MANIFEST_FILE = "manifest.webmanifest";
|
|
8
|
+
var ICON_FILE = "icon.svg";
|
|
9
|
+
var CACHE_PREFIX = "app-shell-";
|
|
10
|
+
var DEFAULT_THEME = "#131c26";
|
|
11
|
+
var DEFAULT_BACKGROUND = "#f1f1f1";
|
|
12
|
+
function lightnessOf(css) {
|
|
13
|
+
const hex = css.trim().replace("#", "");
|
|
14
|
+
const full = hex.length === 3 ? hex.replace(/./g, (c) => c + c) : hex;
|
|
15
|
+
if (!/^[0-9a-f]{6}$/i.test(full)) return 100;
|
|
16
|
+
const [r, g, b] = [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16) / 255);
|
|
17
|
+
return (Math.max(r, g, b) + Math.min(r, g, b)) / 2 * 100;
|
|
18
|
+
}
|
|
19
|
+
function readPackageName(root) {
|
|
20
|
+
const pkgPath = resolve(root, "package.json");
|
|
21
|
+
if (!existsSync(pkgPath)) return void 0;
|
|
22
|
+
try {
|
|
23
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
24
|
+
return pkg.name;
|
|
25
|
+
} catch {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function titleize(pkgName) {
|
|
30
|
+
const bare = pkgName.replace(/^@[^/]+\//, "");
|
|
31
|
+
return bare.split(/[-_.\s]+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ") || bare;
|
|
32
|
+
}
|
|
33
|
+
function identity(root, opts) {
|
|
34
|
+
const pkgName = readPackageName(root);
|
|
35
|
+
const name = opts.name ?? (pkgName ? titleize(pkgName) : "App");
|
|
36
|
+
const shortName = opts.shortName ?? (name.length <= 12 ? name : name.split(" ")[0].slice(0, 12));
|
|
37
|
+
return { name, shortName };
|
|
38
|
+
}
|
|
39
|
+
function iconSvg(identity2, themeColor) {
|
|
40
|
+
const initial = (identity2.name.match(/[a-z0-9]/i)?.[0] ?? "A").toUpperCase();
|
|
41
|
+
const ink = lightnessOf(themeColor) > 55 ? "#111111" : "#ffffff";
|
|
42
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512" role="img" aria-label="${escapeXml(identity2.name)}">
|
|
43
|
+
<rect width="512" height="512" rx="112" fill="${themeColor}"/>
|
|
44
|
+
<text x="256" y="256" fill="${ink}" font-family="system-ui,-apple-system,'Segoe UI',sans-serif" font-size="232" font-weight="600" text-anchor="middle" dominant-baseline="central">${escapeXml(initial)}</text>
|
|
45
|
+
</svg>
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
function escapeXml(value) {
|
|
49
|
+
return value.replace(/[<>&"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
50
|
+
}
|
|
51
|
+
function manifestJson(identity2, base, themeColor, backgroundColor) {
|
|
52
|
+
return `${JSON.stringify(
|
|
53
|
+
{
|
|
54
|
+
name: identity2.name,
|
|
55
|
+
short_name: identity2.shortName,
|
|
56
|
+
start_url: base,
|
|
57
|
+
scope: base,
|
|
58
|
+
display: "standalone",
|
|
59
|
+
theme_color: themeColor,
|
|
60
|
+
background_color: backgroundColor,
|
|
61
|
+
icons: [
|
|
62
|
+
{
|
|
63
|
+
src: `${base}${ICON_FILE}`,
|
|
64
|
+
sizes: "any",
|
|
65
|
+
type: "image/svg+xml",
|
|
66
|
+
purpose: "any maskable"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
null,
|
|
71
|
+
2
|
|
72
|
+
)}
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
function serviceWorkerSource(buildId, shell, precache) {
|
|
76
|
+
return `// Generated by @fayz-ai/sdk at build time. Do not edit.
|
|
77
|
+
const BUILD_ID = ${JSON.stringify(buildId)};
|
|
78
|
+
const CACHE = ${JSON.stringify(CACHE_PREFIX)} + BUILD_ID;
|
|
79
|
+
const SHELL = ${JSON.stringify(shell)};
|
|
80
|
+
const PRECACHE = ${JSON.stringify(precache, null, 2)};
|
|
81
|
+
const PRECACHED = new Set(PRECACHE);
|
|
82
|
+
|
|
83
|
+
self.addEventListener('install', function (event) {
|
|
84
|
+
event.waitUntil(
|
|
85
|
+
caches.open(CACHE).then(function (cache) {
|
|
86
|
+
// One request at a time and forgiving: a single 404 must not void the
|
|
87
|
+
// whole precache the way cache.addAll() would.
|
|
88
|
+
return Promise.all(
|
|
89
|
+
PRECACHE.map(function (url) {
|
|
90
|
+
return cache.add(new Request(url, { cache: 'reload' })).catch(function () {});
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
self.addEventListener('activate', function (event) {
|
|
98
|
+
event.waitUntil(
|
|
99
|
+
caches
|
|
100
|
+
.keys()
|
|
101
|
+
.then(function (keys) {
|
|
102
|
+
return Promise.all(
|
|
103
|
+
keys
|
|
104
|
+
.filter(function (key) {
|
|
105
|
+
return key.indexOf(${JSON.stringify(CACHE_PREFIX)}) === 0 && key !== CACHE;
|
|
106
|
+
})
|
|
107
|
+
.map(function (key) {
|
|
108
|
+
return caches.delete(key);
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
})
|
|
112
|
+
.then(function () {
|
|
113
|
+
return self.clients.claim();
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
self.addEventListener('fetch', function (event) {
|
|
119
|
+
var request = event.request;
|
|
120
|
+
if (request.method !== 'GET') return;
|
|
121
|
+
var url;
|
|
122
|
+
try {
|
|
123
|
+
url = new URL(request.url);
|
|
124
|
+
} catch (e) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (url.origin !== self.location.origin) return;
|
|
128
|
+
|
|
129
|
+
if (request.mode === 'navigate') {
|
|
130
|
+
event.respondWith(
|
|
131
|
+
fetch(request).catch(function () {
|
|
132
|
+
return caches.match(SHELL, { cacheName: CACHE }).then(function (hit) {
|
|
133
|
+
return hit || Response.error();
|
|
134
|
+
});
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Only the build's own hashed assets, which are immutable by construction.
|
|
141
|
+
// Everything else same-origin (API calls above all) is left to the network.
|
|
142
|
+
if (!PRECACHED.has(url.pathname)) return;
|
|
143
|
+
event.respondWith(
|
|
144
|
+
caches.match(request, { cacheName: CACHE }).then(function (hit) {
|
|
145
|
+
return hit || fetch(request);
|
|
146
|
+
})
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
`;
|
|
150
|
+
}
|
|
151
|
+
var HEAD_ANCHOR = /<head[^>]*>/i;
|
|
152
|
+
var BODY_END = /<\/body>/i;
|
|
153
|
+
function insertAfter(html, anchor, chunk) {
|
|
154
|
+
const match = anchor.exec(html);
|
|
155
|
+
if (!match) return null;
|
|
156
|
+
const at = match.index + match[0].length;
|
|
157
|
+
return `${html.slice(0, at)}
|
|
158
|
+
${chunk}${html.slice(at)}`;
|
|
159
|
+
}
|
|
160
|
+
function registrationScript(swUrl) {
|
|
161
|
+
return `<script>if('serviceWorker' in navigator){addEventListener('load',function(){navigator.serviceWorker.register('${swUrl}').catch(function(){})})}</script>`;
|
|
162
|
+
}
|
|
163
|
+
function isPrecacheable(fileName) {
|
|
164
|
+
if (fileName === SW_FILE || fileName === MANIFEST_FILE) return false;
|
|
165
|
+
return !fileName.endsWith(".map") && !fileName.endsWith(".html");
|
|
166
|
+
}
|
|
167
|
+
function appShellPwa(root, opts = {}) {
|
|
168
|
+
const app = identity(root, opts);
|
|
169
|
+
const themeColor = opts.themeColor ?? DEFAULT_THEME;
|
|
170
|
+
const backgroundColor = opts.backgroundColor ?? DEFAULT_BACKGROUND;
|
|
171
|
+
let base = "/";
|
|
172
|
+
return {
|
|
173
|
+
name: "fayz:app-shell-pwa",
|
|
174
|
+
apply: "build",
|
|
175
|
+
configResolved(config) {
|
|
176
|
+
base = config.base || "/";
|
|
177
|
+
if (!base.endsWith("/")) base += "/";
|
|
178
|
+
},
|
|
179
|
+
generateBundle: {
|
|
180
|
+
order: "post",
|
|
181
|
+
handler(_options, bundle) {
|
|
182
|
+
const precache = Object.keys(bundle).filter(isPrecacheable).sort().map((fileName) => `${base}${fileName}`);
|
|
183
|
+
const shell = `${base}index.html`;
|
|
184
|
+
precache.unshift(shell);
|
|
185
|
+
const indexAsset = bundle["index.html"];
|
|
186
|
+
const indexSource = indexAsset && indexAsset.type === "asset" ? String(indexAsset.source) : "";
|
|
187
|
+
const buildId = createHash("sha256").update(precache.join("\n")).update(indexSource).digest("hex").slice(0, 12);
|
|
188
|
+
this.emitFile({
|
|
189
|
+
type: "asset",
|
|
190
|
+
fileName: SW_FILE,
|
|
191
|
+
source: serviceWorkerSource(buildId, shell, precache)
|
|
192
|
+
});
|
|
193
|
+
this.emitFile({
|
|
194
|
+
type: "asset",
|
|
195
|
+
fileName: MANIFEST_FILE,
|
|
196
|
+
source: manifestJson(app, base, themeColor, backgroundColor)
|
|
197
|
+
});
|
|
198
|
+
this.emitFile({ type: "asset", fileName: ICON_FILE, source: iconSvg(app, themeColor) });
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
transformIndexHtml: {
|
|
202
|
+
order: "post",
|
|
203
|
+
handler(html) {
|
|
204
|
+
const manifestHref = `${base}${MANIFEST_FILE}`;
|
|
205
|
+
const link = /<link[^>]+rel=["']?manifest/i.test(html) ? "" : `<link rel="manifest" href="${manifestHref}" />`;
|
|
206
|
+
const script = html.includes("serviceWorker.register") ? "" : registrationScript(`${base}${SW_FILE}`);
|
|
207
|
+
if (!link && !script) return html;
|
|
208
|
+
const withLink = link ? insertAfter(html, HEAD_ANCHOR, link) ?? `${link}
|
|
209
|
+
${html}` : html;
|
|
210
|
+
if (!script) return withLink;
|
|
211
|
+
return BODY_END.test(withLink) ? withLink.replace(BODY_END, `${script}
|
|
212
|
+
</body>`) : `${withLink}
|
|
213
|
+
${script}`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
var BOOT_THEME_STORAGE_KEY = "fayz:boot-theme";
|
|
219
|
+
var THEME_MODE_STORAGE_KEY = "saas-core:theme-mode";
|
|
220
|
+
var UI_THEME_MODE_STORAGE_KEY = "fayz-ui:theme-mode";
|
|
221
|
+
var DEFAULT_PAGE = "#f1f1f1";
|
|
222
|
+
var DEFAULT_PAGE_DARK = "#1a1a1a";
|
|
223
|
+
var RING_ON_DARK = ["rgba(255,255,255,.18)", "rgba(255,255,255,.7)"];
|
|
224
|
+
var RING_ON_LIGHT = ["rgba(0,0,0,.15)", "rgba(0,0,0,.55)"];
|
|
225
|
+
function lightnessOf2(css) {
|
|
226
|
+
const hex = css.trim().replace("#", "");
|
|
227
|
+
const full = hex.length === 3 ? hex.replace(/./g, (c) => c + c) : hex;
|
|
228
|
+
if (!/^[0-9a-f]{6}$/i.test(full)) return 100;
|
|
229
|
+
const [r, g, b] = [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16) / 255);
|
|
230
|
+
return (Math.max(r, g, b) + Math.min(r, g, b)) / 2 * 100;
|
|
231
|
+
}
|
|
232
|
+
function ringTones(background) {
|
|
233
|
+
return lightnessOf2(background) > 55 ? RING_ON_LIGHT : RING_ON_DARK;
|
|
234
|
+
}
|
|
235
|
+
function markup() {
|
|
236
|
+
return `<div id="fayz-boot" role="status" aria-live="polite" aria-label="Carregando"><span class="fb-spin"></span></div>`;
|
|
237
|
+
}
|
|
238
|
+
function style(colors) {
|
|
239
|
+
const [ring, ringLit] = ringTones(colors.light);
|
|
240
|
+
const [darkRing, darkRingLit] = ringTones(colors.dark);
|
|
241
|
+
return `<style id="fayz-boot-style">
|
|
242
|
+
#fayz-boot{--fb-bg:${colors.light};--fb-ring:${ring};--fb-ring-lit:${ringLit};position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;background:var(--fb-bg);opacity:1;transition:opacity .2s ease}
|
|
243
|
+
.dark #fayz-boot{--fb-bg:${colors.dark};--fb-ring:${darkRing};--fb-ring-lit:${darkRingLit}}
|
|
244
|
+
#fayz-boot[data-leaving]{opacity:0;pointer-events:none}
|
|
245
|
+
#fayz-boot .fb-spin{display:block;width:1.75rem;height:1.75rem;border-radius:9999px;border:2px solid var(--fb-ring);border-top-color:var(--fb-ring-lit);animation:fb-spin .7s linear infinite}
|
|
246
|
+
@keyframes fb-spin{to{transform:rotate(360deg)}}
|
|
247
|
+
@media (prefers-reduced-motion:reduce){#fayz-boot .fb-spin{animation:none;border-top-color:var(--fb-ring)}}
|
|
248
|
+
</style>`;
|
|
249
|
+
}
|
|
250
|
+
function dismissScript(surface, colors) {
|
|
251
|
+
const paletteSeed = surface === "admin" ? `
|
|
252
|
+
try{
|
|
253
|
+
var t=JSON.parse(localStorage.getItem('${BOOT_THEME_STORAGE_KEY}')||'null');
|
|
254
|
+
if(t&&t.sidebar){
|
|
255
|
+
de.style.setProperty('--sidebar',t.sidebar);
|
|
256
|
+
if(t.sidebarForeground)de.style.setProperty('--sidebar-foreground',t.sidebarForeground);
|
|
257
|
+
}
|
|
258
|
+
}catch(e){}` : "";
|
|
259
|
+
return `<script>(function(){
|
|
260
|
+
var de=document.documentElement,dark=false;
|
|
261
|
+
try{
|
|
262
|
+
var m=localStorage.getItem('${THEME_MODE_STORAGE_KEY}')||localStorage.getItem('${UI_THEME_MODE_STORAGE_KEY}');
|
|
263
|
+
dark=m==='dark'||(m==='system'&&!!window.matchMedia&&window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
264
|
+
}catch(e){}
|
|
265
|
+
de.classList.toggle('dark',dark);
|
|
266
|
+
de.style.colorScheme=dark?'dark':'light';${paletteSeed}
|
|
267
|
+
var boot=document.getElementById('fayz-boot'),root=document.getElementById('root');
|
|
268
|
+
if(!boot)return;
|
|
269
|
+
var meta=document.querySelector('meta[name="theme-color"]');
|
|
270
|
+
if(meta)meta.setAttribute('content',dark?'${colors.dark}':'${colors.light}');
|
|
271
|
+
var gone=false,drop=function(){
|
|
272
|
+
if(gone)return;gone=true;boot.setAttribute('data-leaving','');
|
|
273
|
+
setTimeout(function(){boot.parentNode&&boot.parentNode.removeChild(boot)},250);
|
|
274
|
+
};
|
|
275
|
+
if(!root){drop();return}
|
|
276
|
+
if(root.childNodes.length){drop();return}
|
|
277
|
+
var mo=new MutationObserver(function(){
|
|
278
|
+
if(!root.childNodes.length)return;
|
|
279
|
+
mo.disconnect();
|
|
280
|
+
(window.requestAnimationFrame||setTimeout)(drop);
|
|
281
|
+
});
|
|
282
|
+
mo.observe(root,{childList:true});
|
|
283
|
+
setTimeout(function(){mo.disconnect();drop()},15000);
|
|
284
|
+
})();</script>`;
|
|
285
|
+
}
|
|
286
|
+
function looksLikeAdminApp(root) {
|
|
287
|
+
const pkgPath = resolve(root, "package.json");
|
|
288
|
+
if (!existsSync(pkgPath)) return false;
|
|
289
|
+
try {
|
|
290
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
291
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
292
|
+
if (deps["@fayz-ai/storefront"]) return false;
|
|
293
|
+
return Boolean(deps["@fayz-ai/admin"] || deps["@fayz-ai/saas"]);
|
|
294
|
+
} catch {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
var HEAD_ANCHOR2 = /<head[^>]*>(\s*<meta[^>]+charset[^>]*>)?/i;
|
|
299
|
+
var BODY_ANCHOR = /<body[^>]*>/i;
|
|
300
|
+
function insertAfter2(html, anchor, chunk) {
|
|
301
|
+
const match = anchor.exec(html);
|
|
302
|
+
if (!match) return null;
|
|
303
|
+
const at = match.index + match[0].length;
|
|
304
|
+
return `${html.slice(0, at)}
|
|
305
|
+
${chunk}${html.slice(at)}`;
|
|
306
|
+
}
|
|
307
|
+
function fayzBootSkeleton(root, opts = {}) {
|
|
308
|
+
const surface = opts.surface ?? (looksLikeAdminApp(root) ? "admin" : "page");
|
|
309
|
+
const colors = {
|
|
310
|
+
light: opts.background ?? DEFAULT_PAGE,
|
|
311
|
+
dark: opts.backgroundDark ?? DEFAULT_PAGE_DARK
|
|
312
|
+
};
|
|
313
|
+
return {
|
|
314
|
+
name: "fayz:boot-skeleton",
|
|
315
|
+
transformIndexHtml: {
|
|
316
|
+
order: "post",
|
|
317
|
+
handler(html) {
|
|
318
|
+
if (surface === "none") return html;
|
|
319
|
+
if (!html.includes('id="root"')) return html;
|
|
320
|
+
const hasThemeColor = /<meta[^>]+name=["']?theme-color/i.test(html);
|
|
321
|
+
const headChunk = hasThemeColor ? style(colors) : `<meta name="theme-color" content="${colors.light}" />
|
|
322
|
+
${style(colors)}`;
|
|
323
|
+
const bodyChunk = `${markup()}
|
|
324
|
+
${dismissScript(surface, colors)}`;
|
|
325
|
+
const withHead = insertAfter2(html, HEAD_ANCHOR2, headChunk);
|
|
326
|
+
const base = withHead ?? html;
|
|
327
|
+
const pending = withHead ? bodyChunk : `${headChunk}
|
|
328
|
+
${bodyChunk}`;
|
|
329
|
+
return insertAfter2(base, BODY_ANCHOR, pending) ?? `${base}
|
|
330
|
+
${pending}`;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// src/vite.ts
|
|
337
|
+
function sdkAliases(sdkDir) {
|
|
338
|
+
const out = {};
|
|
339
|
+
for (const group of ["packages", "plugins"]) {
|
|
340
|
+
const dir = resolve(sdkDir, group);
|
|
341
|
+
if (!existsSync(dir)) continue;
|
|
342
|
+
for (const name of readdirSync(dir)) {
|
|
343
|
+
const src = resolve(dir, name, "src");
|
|
344
|
+
if (existsSync(resolve(src, "index.ts"))) out[`@fayz-ai/${name}`] = src;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return out;
|
|
348
|
+
}
|
|
43
349
|
var FAYZ_SDK_DIR_ENV = "FAYZ_SDK_DIR";
|
|
44
350
|
function resolveSdkDir(root, sdkDir, env = process.env) {
|
|
45
351
|
const fromEnv = env[FAYZ_SDK_DIR_ENV]?.trim();
|
|
46
352
|
return resolve(root, fromEnv || sdkDir || "../../fayz-sdk");
|
|
47
353
|
}
|
|
354
|
+
var LAZY_ONLY_DEPS = ["recharts", "@dnd-kit/core", "@dnd-kit/sortable", "@dnd-kit/modifiers", "@dnd-kit/utilities"];
|
|
355
|
+
function installedDeps(root, names) {
|
|
356
|
+
const roots = [];
|
|
357
|
+
for (let dir = root, prev = ""; dir !== prev; prev = dir, dir = resolve(dir, "..")) {
|
|
358
|
+
roots.push(resolve(dir, "node_modules"));
|
|
359
|
+
}
|
|
360
|
+
return names.filter((name) => roots.some((nm) => existsSync(resolve(nm, name, "package.json"))));
|
|
361
|
+
}
|
|
48
362
|
function fayzVite(opts = {}) {
|
|
49
363
|
const root = opts.root ?? process.cwd();
|
|
50
364
|
const fayzSdk = resolveSdkDir(root, opts.sdkDir);
|
|
51
365
|
const wantLocal = process.env.FAYZ_SDK_SOURCE !== "published";
|
|
52
366
|
const localPresent = existsSync(resolve(fayzSdk, "packages/core/src/index.ts"));
|
|
53
367
|
const useLocal = wantLocal && localPresent;
|
|
54
|
-
const localAliases = {};
|
|
55
|
-
if (useLocal) {
|
|
56
|
-
for (const p of SDK_PACKAGES) localAliases[`@fayz-ai/${p}`] = resolve(fayzSdk, `packages/${p}/src`);
|
|
57
|
-
for (const p of SDK_PLUGINS) localAliases[`@fayz-ai/plugin-${p}`] = resolve(fayzSdk, `plugins/plugin-${p}/src`);
|
|
58
|
-
}
|
|
368
|
+
const localAliases = useLocal ? sdkAliases(fayzSdk) : {};
|
|
59
369
|
const { alias: userAlias, dedupe: userDedupe, conditions: _ignore, ...restResolve } = opts.resolve ?? {};
|
|
370
|
+
const pwa = opts.pwa ?? true;
|
|
371
|
+
const pwaPlugins = pwa === false ? [] : [
|
|
372
|
+
appShellPwa(root, {
|
|
373
|
+
themeColor: opts.bootSkeleton?.sidebar ?? opts.bootSkeleton?.background,
|
|
374
|
+
backgroundColor: opts.bootSkeleton?.background ?? opts.bootSkeleton?.sidebar,
|
|
375
|
+
...pwa === true ? {} : pwa
|
|
376
|
+
})
|
|
377
|
+
];
|
|
60
378
|
return {
|
|
61
|
-
plugins: [...opts.plugins ?? []],
|
|
379
|
+
plugins: [...opts.plugins ?? [], fayzBootSkeleton(root, opts.bootSkeleton), ...pwaPlugins],
|
|
62
380
|
envPrefix: ["VITE_", "PUBLIC_"],
|
|
63
381
|
resolve: {
|
|
64
382
|
...restResolve,
|
|
@@ -79,7 +397,16 @@ function fayzVite(opts = {}) {
|
|
|
79
397
|
dedupe: userDedupe ?? ["react", "react-dom", "zustand", "lucide-react", "react-router-dom", "@supabase/supabase-js", "sonner"],
|
|
80
398
|
conditions: useLocal ? ["source", "browser", "module", "jsnext:main", "jsnext"] : void 0
|
|
81
399
|
},
|
|
82
|
-
optimizeDeps: {
|
|
400
|
+
optimizeDeps: {
|
|
401
|
+
exclude: useLocal ? Object.keys(localAliases) : [],
|
|
402
|
+
// Excluding @fayz-ai/* also hides THEIR bare deps from Vite's initial
|
|
403
|
+
// scan. A dep that first appears behind a React.lazy() is then discovered
|
|
404
|
+
// at click time, and the re-optimize that follows kills the very imports
|
|
405
|
+
// that triggered it — the screen fails with "Failed to fetch dynamically
|
|
406
|
+
// imported module" (recharts: every chart at once; @dnd-kit: the forms
|
|
407
|
+
// builder). Naming them keeps the exclude that keeps SDK source hot.
|
|
408
|
+
include: useLocal ? installedDeps(root, LAZY_ONLY_DEPS) : void 0
|
|
409
|
+
},
|
|
83
410
|
// The preview-container runtime contract: Vite's host-check 403s any
|
|
84
411
|
// non-local Host (browser iframe via Caddy, health probe via
|
|
85
412
|
// host.docker.internal) unless allowedHosts is set. host/cors/headers keep
|
|
@@ -102,6 +429,6 @@ function fayzVite(opts = {}) {
|
|
|
102
429
|
};
|
|
103
430
|
}
|
|
104
431
|
|
|
105
|
-
export { FAYZ_SDK_DIR_ENV, fayzVite, resolveSdkDir };
|
|
432
|
+
export { BOOT_THEME_STORAGE_KEY, FAYZ_SDK_DIR_ENV, appShellPwa, fayzVite, resolveSdkDir };
|
|
106
433
|
//# sourceMappingURL=vite.js.map
|
|
107
434
|
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vite.ts"],"names":[],"mappings":";;;;AAOA,IAAM,YAAA,GAAe;AAAA;AAAA;AAAA,EAGnB,KAAA;AAAA,EAAO,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,IAAA;AAAA,EAAM,OAAA;AAAA,EAAS,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,YAAA;AAAA,EAAc,QAAA;AAAA,EAAU,SAAA;AAAA,EAA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I,EAAC,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOnE,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,IAAA;AAAA,MACN,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,YAAY,IAAA,CAAK,UAAA;AAAA,MACjB,IAAA,EAAM,IAAA;AAAA,MACN,YAAA,EAAc,IAAA;AAAA,MACd,OAAA,EAAS;AAAA,QACP,6BAAA,EAA+B,GAAA;AAAA,QAC/B,8BAAA,EAAgC;AAAA,OAClC;AAAA,MACA,IAAI,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAO,CAAA,EAAE;AAAA,MAC7B,GAAI,IAAA,CAAK,MAAA,IAAU;AAAC;AACtB,GACF;AACF","file":"vite.js","sourcesContent":["import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport type { UserConfig, PluginOption, AliasOptions } from 'vite'\n\n// All publishable @fayz-ai/* packages (root src). Subpaths (e.g.\n// @fayz-ai/admin/ui, @fayz-ai/storefront/catalog) resolve automatically via\n// Vite's prefix alias matching — the shim files mirror the subpath under src/.\nconst SDK_PACKAGES = [\n // 'saas' is the deprecated compat shim for 'admin' — kept so an app that has\n // not migrated its imports still resolves in source mode (removed in 0.12.0).\n 'sdk', 'core', 'auth', 'ui', 'admin', 'saas', 'shop', 'storefront', 'portal', 'courses', 'db',\n] as const\n\nconst SDK_PLUGINS = [\n 'agenda', 'auth', 'automations', 'blog', 'conversations', 'courses', 'crm', 'dashboard',\n 'financial', 'forms', 'inventory', 'marketing', 'menu', 'orders', 'payments', 'reports',\n 'reputation', 'shop', 'sites', 'tables', 'tasks',\n] as const\n\nexport interface FayzViteOptions {\n /** Dev server port. */\n port?: number\n /** Fail instead of incrementing if the port is taken. */\n strictPort?: boolean\n /** Extra app-specific aliases, merged after the SDK aliases. */\n aliases?: Record<string, string>\n /** Extra Vite plugins, appended after @vitejs/plugin-react. */\n plugins?: PluginOption[]\n /**\n * SDK source location, absolute or relative to the app root\n * (default `../../fayz-sdk`).\n *\n * The `FAYZ_SDK_DIR` environment variable OVERRIDES this — see\n * {@link resolveSdkDir}.\n */\n sdkDir?: string\n /** App root directory (default process.cwd()). */\n root?: string\n /**\n * Extra Vite `server` config, merged over the SDK server defaults. The\n * preview-container contract (host/cors/allowedHosts/headers) is applied\n * first, so an override can add e.g. `proxy` without dropping it.\n */\n server?: UserConfig['server']\n /**\n * Extra Vite `resolve` config, merged over the SDK resolve defaults. The SDK\n * alias map / dedupe / conditions win for `@fayz-ai/*` local-source\n * resolution; any other resolve keys (and extra aliases) are merged in.\n */\n resolve?: UserConfig['resolve']\n}\n\n/**\n * Shared Vite config for Fayz dogfood apps. Resolves `@fayz-ai/*` from the local\n * SDK source when it is checked out next to the app AND `FAYZ_SDK_SOURCE` is not\n * `published`; otherwise from node_modules (the Fayz editor sandbox / published\n * npm). Apps no longer hand-maintain alias maps or the local-vs-npm guard.\n *\n * import { defineConfig } from 'vite'\n * import react from '@vitejs/plugin-react'\n * import { fayzVite } from '@fayz-ai/sdk/vite'\n * export default defineConfig(fayzVite({ port: 5185, plugins: [react()] }))\n *\n * Where that local source is read from is {@link resolveSdkDir}: `FAYZ_SDK_DIR`\n * beats the `sdkDir` option beats `../../fayz-sdk`.\n *\n * The app passes its own `@vitejs/plugin-react` so `@fayz-ai/sdk` carries no\n * build-tool peer deps (which otherwise choke npm's peer resolution, since sdk\n * sits in every dependency path).\n */\n/** Env var that redirects local-source resolution to another SDK checkout. */\nexport const FAYZ_SDK_DIR_ENV = 'FAYZ_SDK_DIR'\n\n/**\n * Where the local SDK source is, as an absolute path. Resolution order:\n *\n * 1. `FAYZ_SDK_DIR` (env) — wins, absolute or root-relative\n * 2. `sdkDir` (option) — what the app's vite config declares\n * 3. `../../fayz-sdk` — the sibling-checkout convention\n *\n * Env wins deliberately. `sdkDir` lives in the app's COMMITTED vite config, so\n * without an override there was no way to build, dev or `fayz validate` a\n * store against a different SDK tree (a worktree, a release branch) short of\n * editing that committed file or dropping an untracked config shim next to it\n * — which is exactly what the fleet ended up doing. An env var is the one\n * knob a CLI flag and a container can both set without touching the repo.\n *\n * Exported so the CLI and the tests agree on the precedence by construction\n * rather than by comment.\n */\nexport function resolveSdkDir(\n root: string,\n sdkDir?: string,\n env: Record<string, string | undefined> = process.env,\n): string {\n const fromEnv = env[FAYZ_SDK_DIR_ENV]?.trim()\n return resolve(root, fromEnv || sdkDir || '../../fayz-sdk')\n}\n\nexport function fayzVite(opts: FayzViteOptions = {}): UserConfig {\n const root = opts.root ?? process.cwd()\n const fayzSdk = resolveSdkDir(root, opts.sdkDir)\n const wantLocal = process.env.FAYZ_SDK_SOURCE !== 'published'\n const localPresent = existsSync(resolve(fayzSdk, 'packages/core/src/index.ts'))\n const useLocal = wantLocal && localPresent\n\n const localAliases: Record<string, string> = {}\n if (useLocal) {\n for (const p of SDK_PACKAGES) localAliases[`@fayz-ai/${p}`] = resolve(fayzSdk, `packages/${p}/src`)\n for (const p of SDK_PLUGINS) localAliases[`@fayz-ai/plugin-${p}`] = resolve(fayzSdk, `plugins/plugin-${p}/src`)\n }\n\n // Pull SDK-owned resolve keys out of any caller override so they can't clobber\n // local-source @fayz-ai/* resolution; the rest of `resolve` is merged in.\n const { alias: userAlias, dedupe: userDedupe, conditions: _ignore, ...restResolve } =\n (opts.resolve ?? {}) as Exclude<UserConfig['resolve'], undefined>\n\n return {\n plugins: [...(opts.plugins ?? [])],\n envPrefix: ['VITE_', 'PUBLIC_'],\n resolve: {\n ...restResolve,\n alias: {\n '@': resolve(root, 'src'),\n ...localAliases,\n ...(opts.aliases ?? {}),\n ...((userAlias as Record<string, string> | undefined) ?? {}),\n } as AliasOptions,\n // lucide-react is a direct dep of both the app and every @fayz-ai/*\n // package; without dedupe a version skew installs two copies and esbuild\n // pre-bundles each barrel separately (~1,500 icon modules each).\n // Collapsing to one copy is the single biggest cut to the editor-container\n // optimize RAM/CPU spike. Only dedupe deps the *app* directly depends on\n // (so they're hoisted to its root node_modules) — deduping a transitive\n // like @tanstack/react-table makes Vite resolve it from the app root,\n // which fails in local-source mode and 500s the aliased UI source.\n dedupe: userDedupe ?? ['react', 'react-dom', 'zustand', 'lucide-react', 'react-router-dom', '@supabase/supabase-js', 'sonner'],\n conditions: useLocal ? ['source', 'browser', 'module', 'jsnext:main', 'jsnext'] : undefined,\n },\n optimizeDeps: { exclude: useLocal ? Object.keys(localAliases) : [] },\n // The preview-container runtime contract: Vite's host-check 403s any\n // non-local Host (browser iframe via Caddy, health probe via\n // host.docker.internal) unless allowedHosts is set. host/cors/headers keep\n // the proxied iframe + cross-origin asset fetches working. Owned here\n // because the app's vite.config has no literal `server: {` for the\n // container's text patchers to anchor on. Caller `server` merges last.\n server: {\n host: true,\n port: opts.port,\n strictPort: opts.strictPort,\n cors: true,\n allowedHosts: true,\n headers: {\n 'Access-Control-Allow-Origin': '*',\n 'Cross-Origin-Resource-Policy': 'cross-origin',\n },\n fs: { allow: [root, fayzSdk] },\n ...(opts.server ?? {}),\n },\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/app-shell-pwa.ts","../src/lib/boot-skeleton.ts","../src/vite.ts"],"names":["identity","lightnessOf","resolve","existsSync","readFileSync","HEAD_ANCHOR","insertAfter"],"mappings":";;;;;AAoCA,IAAM,OAAA,GAAU,OAAA;AAChB,IAAM,aAAA,GAAgB,sBAAA;AACtB,IAAM,SAAA,GAAY,UAAA;AAIlB,IAAM,YAAA,GAAe,YAAA;AAIrB,IAAM,aAAA,GAAgB,SAAA;AACtB,IAAM,kBAAA,GAAqB,SAAA;AAQ3B,SAAS,YAAY,GAAA,EAAqB;AACxC,EAAA,MAAM,MAAM,GAAA,CAAI,IAAA,EAAK,CAAE,OAAA,CAAQ,KAAK,EAAE,CAAA;AACtC,EAAA,MAAM,IAAA,GAAO,GAAA,CAAI,MAAA,KAAW,CAAA,GAAI,GAAA,CAAI,OAAA,CAAQ,IAAA,EAAM,CAAC,CAAA,KAAM,CAAA,GAAI,CAAC,CAAA,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B,GAAK,aAAoD;AAAC,OAC5D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MASA,MAAA,EAAQ,cAAc,CAAC,OAAA,EAAS,aAAa,SAAA,EAAW,cAAA,EAAgB,kBAAA,EAAoB,uBAAA,EAAyB,QAAQ,CAAA;AAAA,MAC7H,UAAA,EAAY,WAAW,CAAC,QAAA,EAAU,WAAW,QAAA,EAAU,aAAA,EAAe,QAAQ,CAAA,GAAI;AAAA,KACpF;AAAA,IACA,YAAA,EAAc;AAAA,MACZ,SAAS,QAAA,GAAW,MAAA,CAAO,IAAA,CAAK,YAAY,IAAI,EAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOjD,OAAA,EAAS,QAAA,GAAW,aAAA,CAAc,IAAA,EAAM,cAAc,CAAA,GAAI;AAAA,KAC5D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,IAAA;AAAA,MACN,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,YAAY,IAAA,CAAK,UAAA;AAAA,MACjB,IAAA,EAAM,IAAA;AAAA,MACN,YAAA,EAAc,IAAA;AAAA,MACd,OAAA,EAAS;AAAA,QACP,6BAAA,EAA+B,GAAA;AAAA,QAC/B,8BAAA,EAAgC;AAAA,OAClC;AAAA,MACA,IAAI,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAO,CAAA,EAAE;AAAA,MAC7B,GAAI,IAAA,CAAK,MAAA,IAAU;AAAC;AACtB,GACF;AACF","file":"vite.js","sourcesContent":["import { createHash } from 'node:crypto'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport type { Plugin } from 'vite'\n\n// ---------------------------------------------------------------------------\n// App shell, cached — the second load, and every load after it.\n//\n// The boot screen fixes the blank page; it does not fix the WAIT. A deployed\n// app still fetches its entry chunk over the network every single time, and on\n// a phone on café wifi that is the whole perceived cost of \"opening the app\".\n// A service worker that precaches the build turns the shell into something the\n// device already has: reload is instant, and a dropped connection still gets\n// the app (its own data is another story — see the fetch rules below).\n//\n// Hand-rolled on purpose. What we need is a precache list, a cache name and\n// three event listeners — about a page of JavaScript, against a build-time\n// dependency the preview container would have to cold-install on every start.\n//\n// Build only. A dev server that installs a service worker serves yesterday's\n// bundle to a developer who just saved a file, and the confusion costs more\n// than the caching saves.\n// ---------------------------------------------------------------------------\n\nexport interface AppShellPwaOptions {\n /** Install name. Default: the app's package.json name, de-scoped and titled. */\n name?: string\n /** Home-screen label, ideally ≤12 chars. Default: derived from `name`. */\n shortName?: string\n /** Browser chrome / icon color. Default: the boot screen's neutral rail. */\n themeColor?: string\n /** Splash background while the app boots. Default: the boot screen's page. */\n backgroundColor?: string\n}\n\n/** The emitted file names, at the bundle root (not under assets/). */\nconst SW_FILE = 'sw.js'\nconst MANIFEST_FILE = 'manifest.webmanifest'\nconst ICON_FILE = 'icon.svg'\n\n/** Every cache this SW owns is `<prefix><build id>`, so activate can tell its\n * own stale generations apart from caches belonging to anything else. */\nconst CACHE_PREFIX = 'app-shell-'\n\n// The same neutral defaults the boot screen paints with (see boot-skeleton.ts),\n// so the manifest, the theme-color meta and the first paint agree.\nconst DEFAULT_THEME = '#131c26'\nconst DEFAULT_BACKGROUND = '#f1f1f1'\n\ninterface AppIdentity {\n name: string\n shortName: string\n}\n\n/** Perceived lightness of a hex color, 0-100; non-hex is assumed light. */\nfunction lightnessOf(css: string): number {\n const hex = css.trim().replace('#', '')\n const full = hex.length === 3 ? hex.replace(/./g, (c) => c + c) : hex\n if (!/^[0-9a-f]{6}$/i.test(full)) return 100\n const [r, g, b] = [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16) / 255)\n return ((Math.max(r, g, b) + Math.min(r, g, b)) / 2) * 100\n}\n\nfunction readPackageName(root: string): string | undefined {\n const pkgPath = resolve(root, 'package.json')\n if (!existsSync(pkgPath)) return undefined\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { name?: string }\n return pkg.name\n } catch {\n return undefined\n }\n}\n\n/** `@acme/beauty-saas` → `Beauty Saas`. Good enough for a home-screen label,\n * and `name` overrides it whenever the app cares. */\nfunction titleize(pkgName: string): string {\n const bare = pkgName.replace(/^@[^/]+\\//, '')\n return (\n bare\n .split(/[-_.\\s]+/)\n .filter(Boolean)\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(' ') || bare\n )\n}\n\nfunction identity(root: string, opts: AppShellPwaOptions): AppIdentity {\n const pkgName = readPackageName(root)\n const name = opts.name ?? (pkgName ? titleize(pkgName) : 'App')\n const shortName = opts.shortName ?? (name.length <= 12 ? name : name.split(' ')[0].slice(0, 12))\n return { name, shortName }\n}\n\n/** A maskable mark: rounded square in the theme color, app initial on top.\n * The glyph stays well inside the 80% safe zone, so a circular mask on\n * Android does not clip it. PNG sizes are a follow-up. */\nfunction iconSvg(identity: AppIdentity, themeColor: string): string {\n const initial = (identity.name.match(/[a-z0-9]/i)?.[0] ?? 'A').toUpperCase()\n const ink = lightnessOf(themeColor) > 55 ? '#111111' : '#ffffff'\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 512 512\" width=\"512\" height=\"512\" role=\"img\" aria-label=\"${escapeXml(identity.name)}\">\n<rect width=\"512\" height=\"512\" rx=\"112\" fill=\"${themeColor}\"/>\n<text x=\"256\" y=\"256\" fill=\"${ink}\" font-family=\"system-ui,-apple-system,'Segoe UI',sans-serif\" font-size=\"232\" font-weight=\"600\" text-anchor=\"middle\" dominant-baseline=\"central\">${escapeXml(initial)}</text>\n</svg>\n`\n}\n\nfunction escapeXml(value: string): string {\n return value.replace(/[<>&\"']/g, (c) => `&#${c.charCodeAt(0)};`)\n}\n\nfunction manifestJson(\n identity: AppIdentity,\n base: string,\n themeColor: string,\n backgroundColor: string,\n): string {\n return `${JSON.stringify(\n {\n name: identity.name,\n short_name: identity.shortName,\n start_url: base,\n scope: base,\n display: 'standalone',\n theme_color: themeColor,\n background_color: backgroundColor,\n icons: [\n {\n src: `${base}${ICON_FILE}`,\n sizes: 'any',\n type: 'image/svg+xml',\n purpose: 'any maskable',\n },\n ],\n },\n null,\n 2,\n )}\\n`\n}\n\n/**\n * The worker itself, as plain JS with the build's precache list baked in.\n *\n * Caching rules, in the order the fetch handler applies them:\n * - non-GET, or cross-origin → untouched, the network answers\n * - navigation → network first, cached index.html offline\n * - a precached (hashed) asset → cache first, it can never go stale\n * - anything else same-origin → untouched (API reads/writes land here)\n *\n * The last rule is the important one: Supabase and every other API call goes\n * straight to the network, always. A service worker that answers a data\n * request from cache shows the user a number that is quietly wrong, which is\n * worse than an error.\n *\n * There is no `skipWaiting`. A new build installs in the background and takes\n * over on the NEXT load, so a tab in the middle of a form never has its code\n * swapped underneath it.\n */\nfunction serviceWorkerSource(buildId: string, shell: string, precache: string[]): string {\n return `// Generated by @fayz-ai/sdk at build time. Do not edit.\nconst BUILD_ID = ${JSON.stringify(buildId)};\nconst CACHE = ${JSON.stringify(CACHE_PREFIX)} + BUILD_ID;\nconst SHELL = ${JSON.stringify(shell)};\nconst PRECACHE = ${JSON.stringify(precache, null, 2)};\nconst PRECACHED = new Set(PRECACHE);\n\nself.addEventListener('install', function (event) {\n event.waitUntil(\n caches.open(CACHE).then(function (cache) {\n // One request at a time and forgiving: a single 404 must not void the\n // whole precache the way cache.addAll() would.\n return Promise.all(\n PRECACHE.map(function (url) {\n return cache.add(new Request(url, { cache: 'reload' })).catch(function () {});\n })\n );\n })\n );\n});\n\nself.addEventListener('activate', function (event) {\n event.waitUntil(\n caches\n .keys()\n .then(function (keys) {\n return Promise.all(\n keys\n .filter(function (key) {\n return key.indexOf(${JSON.stringify(CACHE_PREFIX)}) === 0 && key !== CACHE;\n })\n .map(function (key) {\n return caches.delete(key);\n })\n );\n })\n .then(function () {\n return self.clients.claim();\n })\n );\n});\n\nself.addEventListener('fetch', function (event) {\n var request = event.request;\n if (request.method !== 'GET') return;\n var url;\n try {\n url = new URL(request.url);\n } catch (e) {\n return;\n }\n if (url.origin !== self.location.origin) return;\n\n if (request.mode === 'navigate') {\n event.respondWith(\n fetch(request).catch(function () {\n return caches.match(SHELL, { cacheName: CACHE }).then(function (hit) {\n return hit || Response.error();\n });\n })\n );\n return;\n }\n\n // Only the build's own hashed assets, which are immutable by construction.\n // Everything else same-origin (API calls above all) is left to the network.\n if (!PRECACHED.has(url.pathname)) return;\n event.respondWith(\n caches.match(request, { cacheName: CACHE }).then(function (hit) {\n return hit || fetch(request);\n })\n );\n});\n`\n}\n\nconst HEAD_ANCHOR = /<head[^>]*>/i\nconst BODY_END = /<\\/body>/i\n\nfunction insertAfter(html: string, anchor: RegExp, chunk: string): string | null {\n const match = anchor.exec(html)\n if (!match) return null\n const at = match.index + match[0].length\n return `${html.slice(0, at)}\\n${chunk}${html.slice(at)}`\n}\n\nfunction registrationScript(swUrl: string): string {\n return `<script>if('serviceWorker' in navigator){addEventListener('load',function(){navigator.serviceWorker.register('${swUrl}').catch(function(){})})}</script>`\n}\n\n/** What goes in the precache list: the build's own output, minus the things a\n * cache has no use for (sourcemaps, the worker itself, other HTML). */\nfunction isPrecacheable(fileName: string): boolean {\n if (fileName === SW_FILE || fileName === MANIFEST_FILE) return false\n return !fileName.endsWith('.map') && !fileName.endsWith('.html')\n}\n\nexport function appShellPwa(root: string, opts: AppShellPwaOptions = {}): Plugin {\n const app = identity(root, opts)\n const themeColor = opts.themeColor ?? DEFAULT_THEME\n const backgroundColor = opts.backgroundColor ?? DEFAULT_BACKGROUND\n // Deployments under a subpath exist (preview containers, docs sites); every\n // emitted URL is base-relative so `/` is just the common case.\n let base = '/'\n\n return {\n name: 'fayz:app-shell-pwa',\n apply: 'build',\n\n configResolved(config) {\n base = config.base || '/'\n if (!base.endsWith('/')) base += '/'\n },\n\n generateBundle: {\n order: 'post',\n handler(_options, bundle) {\n const precache = Object.keys(bundle)\n .filter(isPrecacheable)\n .sort()\n .map((fileName) => `${base}${fileName}`)\n const shell = `${base}index.html`\n precache.unshift(shell)\n\n // The index.html source joins the hash: its asset names already change\n // per build, but its INLINE content (boot screen, meta) can change on\n // its own, and a shell served from an old cache would be that content.\n const indexAsset = bundle['index.html']\n const indexSource =\n indexAsset && indexAsset.type === 'asset' ? String(indexAsset.source) : ''\n const buildId = createHash('sha256')\n .update(precache.join('\\n'))\n .update(indexSource)\n .digest('hex')\n .slice(0, 12)\n\n this.emitFile({\n type: 'asset',\n fileName: SW_FILE,\n source: serviceWorkerSource(buildId, shell, precache),\n })\n this.emitFile({\n type: 'asset',\n fileName: MANIFEST_FILE,\n source: manifestJson(app, base, themeColor, backgroundColor),\n })\n this.emitFile({ type: 'asset', fileName: ICON_FILE, source: iconSvg(app, themeColor) })\n },\n },\n\n transformIndexHtml: {\n order: 'post',\n handler(html: string) {\n const manifestHref = `${base}${MANIFEST_FILE}`\n const link = /<link[^>]+rel=[\"']?manifest/i.test(html)\n ? ''\n : `<link rel=\"manifest\" href=\"${manifestHref}\" />`\n const script = html.includes('serviceWorker.register')\n ? ''\n : registrationScript(`${base}${SW_FILE}`)\n if (!link && !script) return html\n\n const withLink = link ? (insertAfter(html, HEAD_ANCHOR, link) ?? `${link}\\n${html}`) : html\n if (!script) return withLink\n return BODY_END.test(withLink)\n ? withLink.replace(BODY_END, `${script}\\n</body>`)\n : `${withLink}\\n${script}`\n },\n },\n }\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport type { Plugin } from 'vite'\n\n// ---------------------------------------------------------------------------\n// Boot screen — the first thing painted, from the HTML itself.\n//\n// The React boot screen only exists once React exists, and the wait BEFORE that\n// (fetch the entry chunk, parse it, run it) is the long part of a cold load:\n// the page sat blank for most of the wait. Anything that fills that window has\n// to be in the document the server already sent — markup and CSS the browser\n// can paint on its own, with no module graph behind it.\n//\n// What it paints is the THEME BACKGROUND and a spinner in the middle — light in\n// light mode, dark in dark mode. It used to paint the rail's color edge to\n// edge, but a dark splash in front of a light interface reads as a flash, not\n// a hand-off; the surface the app is about to paint is the only color that\n// disappears into it. It is deliberately the SAME image as AppShellSkeleton in\n// @fayz-ai/ui, so the handoff HTML → React → app never swaps anything the eye\n// can catch.\n//\n// The same inline script also resolves the theme mode before first paint, so a\n// dark-mode reload never flashes a light frame while React boots.\n//\n// It dismisses itself the moment React puts anything in #root.\n// ---------------------------------------------------------------------------\n\nexport interface BootSkeletonOptions {\n /**\n * 'admin' additionally seeds the app's stored palette tokens (sidebar) into\n * the document before React paints, so the console's rail mounts in its own\n * color; 'page' skips that; 'none' injects nothing. Both visible surfaces\n * paint the same background-colored screen. Default: 'admin' when the app\n * depends on @fayz-ai/admin or @fayz-ai/saas and not on @fayz-ai/storefront,\n * 'page' otherwise.\n */\n surface?: 'admin' | 'page' | 'none'\n /** @deprecated The boot screen paints the theme background, not the rail.\n * Accepted and ignored. */\n sidebar?: string\n /** Boot background, light mode. */\n background?: string\n /** Boot background, dark mode. */\n backgroundDark?: string\n}\n\n/** localStorage key the admin writes its resolved palette to, so the NEXT boot\n * paints in the app's own colors instead of the neutral default. */\nexport const BOOT_THEME_STORAGE_KEY = 'fayz:boot-theme'\n\n/** localStorage key the admin theme store writes the chosen mode to\n * ('light' | 'dark' | 'system', default 'light'). Duplicated as a literal on\n * both sides — see persistBootPalette in packages/admin/src/theme/utils.ts:\n * the app runtime must not depend on the build-tool package, and this file\n * must not depend on the admin package. */\nexport const THEME_MODE_STORAGE_KEY = 'saas-core:theme-mode'\n\n/** The same thing under @fayz-ai/ui's own theme store, which is what a\n * storefront or member app runs (packages/ui/src/stores/theme.store.ts). */\nexport const UI_THEME_MODE_STORAGE_KEY = 'fayz-ui:theme-mode'\n\n// The light/dark values of `--background` in @fayz-ai/ui — so React's first\n// real paint changes nothing.\nconst DEFAULT_PAGE = '#f1f1f1'\nconst DEFAULT_PAGE_DARK = '#1a1a1a'\n\nconst RING_ON_DARK = ['rgba(255,255,255,.18)', 'rgba(255,255,255,.7)'] as const\nconst RING_ON_LIGHT = ['rgba(0,0,0,.15)', 'rgba(0,0,0,.55)'] as const\n\n/** Perceived lightness of a hex color, 0-100. Non-hex CSS is assumed light —\n * a dark ring on an unknown surface is the safer miss on a white default. */\nfunction lightnessOf(css: string): number {\n const hex = css.trim().replace('#', '')\n const full = hex.length === 3 ? hex.replace(/./g, (c) => c + c) : hex\n if (!/^[0-9a-f]{6}$/i.test(full)) return 100\n const [r, g, b] = [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16) / 255)\n return ((Math.max(r, g, b) + Math.min(r, g, b)) / 2) * 100\n}\n\nfunction ringTones(background: string): readonly [string, string] {\n return lightnessOf(background) > 55 ? RING_ON_LIGHT : RING_ON_DARK\n}\n\nfunction markup(): string {\n return `<div id=\"fayz-boot\" role=\"status\" aria-live=\"polite\" aria-label=\"Carregando\"><span class=\"fb-spin\"></span></div>`\n}\n\n/** The overlay's own CSS. The `.dark` rule makes the screen correct at the\n * very first paint: the inline script sets the class synchronously before\n * the browser draws. The ring is drawn in rgba rather than a theme token,\n * which could land invisible. */\nfunction style(colors: { light: string; dark: string }): string {\n const [ring, ringLit] = ringTones(colors.light)\n const [darkRing, darkRingLit] = ringTones(colors.dark)\n return `<style id=\"fayz-boot-style\">\n#fayz-boot{--fb-bg:${colors.light};--fb-ring:${ring};--fb-ring-lit:${ringLit};position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;background:var(--fb-bg);opacity:1;transition:opacity .2s ease}\n.dark #fayz-boot{--fb-bg:${colors.dark};--fb-ring:${darkRing};--fb-ring-lit:${darkRingLit}}\n#fayz-boot[data-leaving]{opacity:0;pointer-events:none}\n#fayz-boot .fb-spin{display:block;width:1.75rem;height:1.75rem;border-radius:9999px;border:2px solid var(--fb-ring);border-top-color:var(--fb-ring-lit);animation:fb-spin .7s linear infinite}\n@keyframes fb-spin{to{transform:rotate(360deg)}}\n@media (prefers-reduced-motion:reduce){#fayz-boot .fb-spin{animation:none;border-top-color:var(--fb-ring)}}\n</style>`\n}\n\n/**\n * Resolves the theme mode, seeds the app's stored palette tokens, then removes\n * the whole thing as soon as React fills #root.\n *\n * The mode has to be resolved HERE and not in React: the class that makes the\n * page dark only exists once the theme store runs, which is a whole module\n * graph too late — the browser has already painted a light frame by then.\n *\n * The MutationObserver is the handoff: no import, no callback the app has to\n * remember to call, and it works for any scaffold. The timeout is the safety\n * net — a boot that never mounts must not leave a fixed overlay on top of\n * whatever error the page is trying to show.\n */\nfunction dismissScript(surface: 'admin' | 'page', colors: { light: string; dark: string }): string {\n // Seed the app's own sidebar tokens before the bundle paints: the console's\n // rail (and the React skeleton's spinner) mount BEFORE the theme effect\n // applies the palette, and the default tokens would flash the wrong colors\n // for one theme-effect's worth of frames. applyTheme overwrites these same\n // inline properties on every boot.\n const paletteSeed =\n surface === 'admin'\n ? `\n try{\n var t=JSON.parse(localStorage.getItem('${BOOT_THEME_STORAGE_KEY}')||'null');\n if(t&&t.sidebar){\n de.style.setProperty('--sidebar',t.sidebar);\n if(t.sidebarForeground)de.style.setProperty('--sidebar-foreground',t.sidebarForeground);\n }\n }catch(e){}`\n : ''\n return `<script>(function(){\n var de=document.documentElement,dark=false;\n try{\n var m=localStorage.getItem('${THEME_MODE_STORAGE_KEY}')||localStorage.getItem('${UI_THEME_MODE_STORAGE_KEY}');\n dark=m==='dark'||(m==='system'&&!!window.matchMedia&&window.matchMedia('(prefers-color-scheme: dark)').matches);\n }catch(e){}\n de.classList.toggle('dark',dark);\n de.style.colorScheme=dark?'dark':'light';${paletteSeed}\n var boot=document.getElementById('fayz-boot'),root=document.getElementById('root');\n if(!boot)return;\n var meta=document.querySelector('meta[name=\"theme-color\"]');\n if(meta)meta.setAttribute('content',dark?'${colors.dark}':'${colors.light}');\n var gone=false,drop=function(){\n if(gone)return;gone=true;boot.setAttribute('data-leaving','');\n setTimeout(function(){boot.parentNode&&boot.parentNode.removeChild(boot)},250);\n };\n if(!root){drop();return}\n if(root.childNodes.length){drop();return}\n var mo=new MutationObserver(function(){\n if(!root.childNodes.length)return;\n mo.disconnect();\n (window.requestAnimationFrame||setTimeout)(drop);\n });\n mo.observe(root,{childList:true});\n setTimeout(function(){mo.disconnect();drop()},15000);\n})();</script>`\n}\n\n/** True when the app on disk renders an admin console. */\nfunction looksLikeAdminApp(root: string): boolean {\n const pkgPath = resolve(root, 'package.json')\n if (!existsSync(pkgPath)) return false\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n }\n const deps = { ...pkg.dependencies, ...pkg.devDependencies }\n if (deps['@fayz-ai/storefront']) return false\n return Boolean(deps['@fayz-ai/admin'] || deps['@fayz-ai/saas'])\n } catch {\n return false\n }\n}\n\n// The head anchor swallows a leading charset meta if there is one: that\n// declaration has to stay inside the document's first 1024 bytes, and the boot\n// style is most of a kilobyte on its own.\nconst HEAD_ANCHOR = /<head[^>]*>(\\s*<meta[^>]+charset[^>]*>)?/i\nconst BODY_ANCHOR = /<body[^>]*>/i\n\n/** Inserts right after the opening tag, so the overlay paints before whatever\n * the template already had in there. */\nfunction insertAfter(html: string, anchor: RegExp, chunk: string): string | null {\n const match = anchor.exec(html)\n if (!match) return null\n const at = match.index + match[0].length\n return `${html.slice(0, at)}\\n${chunk}${html.slice(at)}`\n}\n\nexport function fayzBootSkeleton(root: string, opts: BootSkeletonOptions = {}): Plugin {\n const surface = opts.surface ?? (looksLikeAdminApp(root) ? 'admin' : 'page')\n // Neutral, not a guess at the brand: @fayz-ai/ui's own background values,\n // which is exactly what the app paints next.\n const colors = {\n light: opts.background ?? DEFAULT_PAGE,\n dark: opts.backgroundDark ?? DEFAULT_PAGE_DARK,\n }\n\n return {\n name: 'fayz:boot-skeleton',\n transformIndexHtml: {\n order: 'post',\n handler(html: string) {\n if (surface === 'none') return html\n if (!html.includes('id=\"root\"')) return html\n\n const hasThemeColor = /<meta[^>]+name=[\"']?theme-color/i.test(html)\n const headChunk = hasThemeColor\n ? style(colors)\n : `<meta name=\"theme-color\" content=\"${colors.light}\" />\\n${style(colors)}`\n const bodyChunk = `${markup()}\\n${dismissScript(surface, colors)}`\n\n const withHead = insertAfter(html, HEAD_ANCHOR, headChunk)\n // No <head> in the template: the style rides along at the top of the\n // body, still ahead of the markup it paints.\n const base = withHead ?? html\n const pending = withHead ? bodyChunk : `${headChunk}\\n${bodyChunk}`\n return insertAfter(base, BODY_ANCHOR, pending) ?? `${base}\\n${pending}`\n },\n },\n }\n}\n","import { existsSync, readdirSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport type { UserConfig, PluginOption, AliasOptions } from 'vite'\nimport { appShellPwa, type AppShellPwaOptions } from './lib/app-shell-pwa'\nimport { fayzBootSkeleton, type BootSkeletonOptions } from './lib/boot-skeleton'\n\nexport { BOOT_THEME_STORAGE_KEY, type BootSkeletonOptions } from './lib/boot-skeleton'\nexport { appShellPwa, type AppShellPwaOptions } from './lib/app-shell-pwa'\n\n/**\n * Every `@fayz-ai/*` package in the checkout, as a Vite alias map (root src).\n * Subpaths (e.g. `@fayz-ai/admin/ui`, `@fayz-ai/storefront/catalog`) resolve\n * automatically via Vite's prefix alias matching — the shim files mirror the\n * subpath under `src/`.\n *\n * Read from disk rather than listed, because a hardcoded list is only correct\n * for the version it shipped in and apps run the INSTALLED `fayzVite`, not this\n * one. That is how the `saas` → `admin` rename half-broke the fleet: `admin`\n * was not in 0.9.0's list, so every app resolved it through the workspace to\n * `packages/admin/dist` — a stale build in the middle of an otherwise\n * source-resolved app, which reads as a bug in the code rather than in the\n * setup. A directory listing cannot go stale.\n */\nfunction sdkAliases(sdkDir: string): Record<string, string> {\n const out: Record<string, string> = {}\n for (const group of ['packages', 'plugins']) {\n const dir = resolve(sdkDir, group)\n if (!existsSync(dir)) continue\n for (const name of readdirSync(dir)) {\n const src = resolve(dir, name, 'src')\n // The directory name is the package name minus the scope, for both groups\n // (packages/admin → @fayz-ai/admin, plugins/plugin-crm → …/plugin-crm).\n if (existsSync(resolve(src, 'index.ts'))) out[`@fayz-ai/${name}`] = src\n }\n }\n return out\n}\n\nexport interface FayzViteOptions {\n /** Dev server port. */\n port?: number\n /** Fail instead of incrementing if the port is taken. */\n strictPort?: boolean\n /** Extra app-specific aliases, merged after the SDK aliases. */\n aliases?: Record<string, string>\n /** Extra Vite plugins, appended after @vitejs/plugin-react. */\n plugins?: PluginOption[]\n /**\n * SDK source location, absolute or relative to the app root\n * (default `../../fayz-sdk`).\n *\n * The `FAYZ_SDK_DIR` environment variable OVERRIDES this — see\n * {@link resolveSdkDir}.\n */\n sdkDir?: string\n /** App root directory (default process.cwd()). */\n root?: string\n /**\n * Extra Vite `server` config, merged over the SDK server defaults. The\n * preview-container contract (host/cors/allowedHosts/headers) is applied\n * first, so an override can add e.g. `proxy` without dropping it.\n */\n server?: UserConfig['server']\n /**\n * Extra Vite `resolve` config, merged over the SDK resolve defaults. The SDK\n * alias map / dedupe / conditions win for `@fayz-ai/*` local-source\n * resolution; any other resolve keys (and extra aliases) are merged in.\n */\n resolve?: UserConfig['resolve']\n /**\n * The shell outline painted into index.html, so the wait for the entry chunk\n * is not a blank page. Auto-detected from the app's dependencies; pass\n * `{ surface: 'none' }` to opt out, or colors to match the app's palette on a\n * first-ever visit (later visits reuse the palette the app itself stored).\n */\n bootSkeleton?: BootSkeletonOptions\n /**\n * The built app precaches itself: a service worker + webmanifest emitted at\n * build time, so a deployed app reloads instantly and still opens with no\n * network. On by default, and build-only by construction — the dev server\n * never registers a worker. Pass `false` to opt out, or an object to name\n * the install / set its colors.\n */\n pwa?: boolean | AppShellPwaOptions\n}\n\n/**\n * Shared Vite config for Fayz dogfood apps. Resolves `@fayz-ai/*` from the local\n * SDK source when it is checked out next to the app AND `FAYZ_SDK_SOURCE` is not\n * `published`; otherwise from node_modules (the Fayz editor sandbox / published\n * npm). Apps no longer hand-maintain alias maps or the local-vs-npm guard.\n *\n * import { defineConfig } from 'vite'\n * import react from '@vitejs/plugin-react'\n * import { fayzVite } from '@fayz-ai/sdk/vite'\n * export default defineConfig(fayzVite({ port: 5185, plugins: [react()] }))\n *\n * Where that local source is read from is {@link resolveSdkDir}: `FAYZ_SDK_DIR`\n * beats the `sdkDir` option beats `../../fayz-sdk`.\n *\n * The app passes its own `@vitejs/plugin-react` so `@fayz-ai/sdk` carries no\n * build-tool peer deps (which otherwise choke npm's peer resolution, since sdk\n * sits in every dependency path).\n */\n/** Env var that redirects local-source resolution to another SDK checkout. */\nexport const FAYZ_SDK_DIR_ENV = 'FAYZ_SDK_DIR'\n\n/**\n * Where the local SDK source is, as an absolute path. Resolution order:\n *\n * 1. `FAYZ_SDK_DIR` (env) — wins, absolute or root-relative\n * 2. `sdkDir` (option) — what the app's vite config declares\n * 3. `../../fayz-sdk` — the sibling-checkout convention\n *\n * Env wins deliberately. `sdkDir` lives in the app's COMMITTED vite config, so\n * without an override there was no way to build, dev or `fayz validate` a\n * store against a different SDK tree (a worktree, a release branch) short of\n * editing that committed file or dropping an untracked config shim next to it\n * — which is exactly what the fleet ended up doing. An env var is the one\n * knob a CLI flag and a container can both set without touching the repo.\n *\n * Exported so the CLI and the tests agree on the precedence by construction\n * rather than by comment.\n */\nexport function resolveSdkDir(\n root: string,\n sdkDir?: string,\n env: Record<string, string | undefined> = process.env,\n): string {\n const fromEnv = env[FAYZ_SDK_DIR_ENV]?.trim()\n return resolve(root, fromEnv || sdkDir || '../../fayz-sdk')\n}\n\n/**\n * Bare deps that only ever appear behind a `React.lazy()` inside an @fayz-ai\n * package. See the `optimizeDeps.include` comment below for why they have to be\n * named. Filtered by what is actually installed, because a plugin the app does\n * not carry leaves its deps uninstalled and `include` hard-fails on those.\n */\nconst LAZY_ONLY_DEPS = ['recharts', '@dnd-kit/core', '@dnd-kit/sortable', '@dnd-kit/modifiers', '@dnd-kit/utilities']\n\nfunction installedDeps(root: string, names: string[]): string[] {\n const roots: string[] = []\n for (let dir = root, prev = ''; dir !== prev; prev = dir, dir = resolve(dir, '..')) {\n roots.push(resolve(dir, 'node_modules'))\n }\n return names.filter((name) => roots.some((nm) => existsSync(resolve(nm, name, 'package.json'))))\n}\n\nexport function fayzVite(opts: FayzViteOptions = {}): UserConfig {\n const root = opts.root ?? process.cwd()\n const fayzSdk = resolveSdkDir(root, opts.sdkDir)\n const wantLocal = process.env.FAYZ_SDK_SOURCE !== 'published'\n const localPresent = existsSync(resolve(fayzSdk, 'packages/core/src/index.ts'))\n const useLocal = wantLocal && localPresent\n\n const localAliases = useLocal ? sdkAliases(fayzSdk) : {}\n\n // Pull SDK-owned resolve keys out of any caller override so they can't clobber\n // local-source @fayz-ai/* resolution; the rest of `resolve` is merged in.\n const { alias: userAlias, dedupe: userDedupe, conditions: _ignore, ...restResolve } =\n (opts.resolve ?? {}) as Exclude<UserConfig['resolve'], undefined>\n\n const pwa = opts.pwa ?? true\n // The install colors follow the boot screen's, so the splash, the browser\n // chrome and the first paint are one surface rather than three guesses.\n const pwaPlugins =\n pwa === false\n ? []\n : [\n appShellPwa(root, {\n themeColor: opts.bootSkeleton?.sidebar ?? opts.bootSkeleton?.background,\n backgroundColor: opts.bootSkeleton?.background ?? opts.bootSkeleton?.sidebar,\n ...(pwa === true ? {} : pwa),\n }),\n ]\n\n return {\n plugins: [...(opts.plugins ?? []), fayzBootSkeleton(root, opts.bootSkeleton), ...pwaPlugins],\n envPrefix: ['VITE_', 'PUBLIC_'],\n resolve: {\n ...restResolve,\n alias: {\n '@': resolve(root, 'src'),\n ...localAliases,\n ...(opts.aliases ?? {}),\n ...((userAlias as Record<string, string> | undefined) ?? {}),\n } as AliasOptions,\n // lucide-react is a direct dep of both the app and every @fayz-ai/*\n // package; without dedupe a version skew installs two copies and esbuild\n // pre-bundles each barrel separately (~1,500 icon modules each).\n // Collapsing to one copy is the single biggest cut to the editor-container\n // optimize RAM/CPU spike. Only dedupe deps the *app* directly depends on\n // (so they're hoisted to its root node_modules) — deduping a transitive\n // like @tanstack/react-table makes Vite resolve it from the app root,\n // which fails in local-source mode and 500s the aliased UI source.\n dedupe: userDedupe ?? ['react', 'react-dom', 'zustand', 'lucide-react', 'react-router-dom', '@supabase/supabase-js', 'sonner'],\n conditions: useLocal ? ['source', 'browser', 'module', 'jsnext:main', 'jsnext'] : undefined,\n },\n optimizeDeps: {\n exclude: useLocal ? Object.keys(localAliases) : [],\n // Excluding @fayz-ai/* also hides THEIR bare deps from Vite's initial\n // scan. A dep that first appears behind a React.lazy() is then discovered\n // at click time, and the re-optimize that follows kills the very imports\n // that triggered it — the screen fails with \"Failed to fetch dynamically\n // imported module\" (recharts: every chart at once; @dnd-kit: the forms\n // builder). Naming them keeps the exclude that keeps SDK source hot.\n include: useLocal ? installedDeps(root, LAZY_ONLY_DEPS) : undefined,\n },\n // The preview-container runtime contract: Vite's host-check 403s any\n // non-local Host (browser iframe via Caddy, health probe via\n // host.docker.internal) unless allowedHosts is set. host/cors/headers keep\n // the proxied iframe + cross-origin asset fetches working. Owned here\n // because the app's vite.config has no literal `server: {` for the\n // container's text patchers to anchor on. Caller `server` merges last.\n server: {\n host: true,\n port: opts.port,\n strictPort: opts.strictPort,\n cors: true,\n allowedHosts: true,\n headers: {\n 'Access-Control-Allow-Origin': '*',\n 'Cross-Origin-Resource-Policy': 'cross-origin',\n },\n fs: { allow: [root, fayzSdk] },\n ...(opts.server ?? {}),\n },\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"fayz": {
|
|
4
4
|
"status": "beta"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.12.0",
|
|
7
7
|
"description": "Fayz SDK — API client, app params, runtime broker helpers, and shared types for generated Fayz projects",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"sideEffects": false,
|
|
@@ -27,6 +27,14 @@
|
|
|
27
27
|
"types": "./dist/agent.d.ts",
|
|
28
28
|
"import": "./dist/agent.js"
|
|
29
29
|
},
|
|
30
|
+
"./automations": {
|
|
31
|
+
"types": "./dist/automations.d.ts",
|
|
32
|
+
"import": "./dist/automations.js"
|
|
33
|
+
},
|
|
34
|
+
"./events": {
|
|
35
|
+
"types": "./dist/events.d.ts",
|
|
36
|
+
"import": "./dist/events.js"
|
|
37
|
+
},
|
|
30
38
|
"./shop": {
|
|
31
39
|
"types": "./dist/shop.d.ts",
|
|
32
40
|
"import": "./dist/shop.js"
|