@iota-uz/sdk 0.3.1 → 0.3.2
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 +2 -0
- package/dist/applet/vite.cjs +231 -0
- package/dist/applet/vite.cjs.map +1 -0
- package/dist/applet/vite.d.cts +115 -0
- package/dist/applet/vite.d.ts +115 -0
- package/dist/applet/vite.mjs +214 -0
- package/dist/applet/vite.mjs.map +1 -0
- package/dist/bichat/index.cjs +11 -2
- package/dist/bichat/index.cjs.map +1 -1
- package/dist/bichat/index.d.cts +12 -3
- package/dist/bichat/index.d.ts +12 -3
- package/dist/bichat/index.mjs +11 -3
- package/dist/bichat/index.mjs.map +1 -1
- package/dist/bichat/tailwind.cjs +93 -0
- package/dist/bichat/tailwind.cjs.map +1 -0
- package/dist/bichat/tailwind.d.cts +21 -0
- package/dist/bichat/tailwind.d.ts +21 -0
- package/dist/bichat/tailwind.mjs +85 -0
- package/dist/bichat/tailwind.mjs.map +1 -0
- package/package.json +12 -1
package/README.MD
CHANGED
|
@@ -122,6 +122,8 @@ The script automatically detects your OS (macOS/Linux) and architecture, downloa
|
|
|
122
122
|
|
|
123
123
|
**Prerequisites:** Go and Homebrew (macOS only) must be installed first.
|
|
124
124
|
|
|
125
|
+
**Node/pnpm:** The repo pins `pnpm@9.15.0` via the `packageManager` field in `package.json`. Ensure [Corepack](https://nodejs.org/api/corepack.html) is enabled (`corepack enable`) in CI and contributor environments so the correct pnpm version is used; otherwise `npm` or `yarn` may run without warning.
|
|
126
|
+
|
|
125
127
|
For full setup instructions, see the [Installation Guide](https://iota-uz.github.io/iota-sdk/getting-started/installation.html).
|
|
126
128
|
|
|
127
129
|
## 🔐 Super Admin
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs2 = require('fs');
|
|
4
|
+
var path2 = require('path');
|
|
5
|
+
var child_process = require('child_process');
|
|
6
|
+
var crypto = require('crypto');
|
|
7
|
+
var module$1 = require('module');
|
|
8
|
+
var os = require('os');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
13
|
+
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
14
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
15
|
+
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
16
|
+
|
|
17
|
+
// ui/src/applet-vite/vite.ts
|
|
18
|
+
var APPLET_DEV_MANIFEST = "applet-dev.json";
|
|
19
|
+
function readAppletDevManifest(viteDir) {
|
|
20
|
+
const dir = viteDir ?? process.cwd();
|
|
21
|
+
const filePath = path2__default.default.join(dir, APPLET_DEV_MANIFEST);
|
|
22
|
+
try {
|
|
23
|
+
const raw = fs2__default.default.readFileSync(filePath, "utf-8");
|
|
24
|
+
const data = JSON.parse(raw);
|
|
25
|
+
if (typeof data.basePath === "string" && typeof data.assetsBase === "string" && typeof data.vitePort === "number" && typeof data.backendUrl === "string") {
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
var DEFAULT_DEDUPE = ["react", "react-dom", "react-router-dom", "react-is"];
|
|
33
|
+
function getAppletAssetsBase(viteDir, manifest) {
|
|
34
|
+
const resolved = manifest ?? readAppletDevManifest(viteDir);
|
|
35
|
+
if (resolved) {
|
|
36
|
+
const base2 = resolved.assetsBase;
|
|
37
|
+
return base2.endsWith("/") ? base2 : base2 + "/";
|
|
38
|
+
}
|
|
39
|
+
const base = process.env.APPLET_ASSETS_BASE ?? "";
|
|
40
|
+
return base.endsWith("/") ? base : base ? base + "/" : "/";
|
|
41
|
+
}
|
|
42
|
+
function getAppletVitePort(defaultPort = 5173, viteDir, manifest) {
|
|
43
|
+
const resolved = manifest ?? readAppletDevManifest(viteDir);
|
|
44
|
+
if (resolved) return resolved.vitePort;
|
|
45
|
+
const p = process.env.APPLET_VITE_PORT;
|
|
46
|
+
if (p === void 0 || p === "") return defaultPort;
|
|
47
|
+
const n = Number(p);
|
|
48
|
+
return Number.isFinite(n) ? n : defaultPort;
|
|
49
|
+
}
|
|
50
|
+
function createAppletViteConfig(opts) {
|
|
51
|
+
const manifest = readAppletDevManifest(opts.viteConfigDir);
|
|
52
|
+
const base = getAppletAssetsBase(opts.viteConfigDir, manifest);
|
|
53
|
+
const port = getAppletVitePort(5173, opts.viteConfigDir, manifest);
|
|
54
|
+
const basePath = manifest?.basePath ?? opts.basePath;
|
|
55
|
+
const backendUrl = manifest?.backendUrl ?? opts.backendUrl;
|
|
56
|
+
const config = {
|
|
57
|
+
base,
|
|
58
|
+
resolve: {
|
|
59
|
+
dedupe: DEFAULT_DEDUPE,
|
|
60
|
+
alias: createLocalSdkAliases({
|
|
61
|
+
enabled: opts.enableLocalSdkAliases ?? Boolean(process.env.IOTA_SDK_DIST),
|
|
62
|
+
sdkDistDir: opts.sdkDistDir ?? process.env.IOTA_SDK_DIST
|
|
63
|
+
})
|
|
64
|
+
},
|
|
65
|
+
server: {
|
|
66
|
+
port,
|
|
67
|
+
strictPort: true,
|
|
68
|
+
proxy: createAppletBackendProxy({
|
|
69
|
+
basePath,
|
|
70
|
+
backendUrl
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
if (opts.extend) {
|
|
75
|
+
return mergeConfig(config, opts.extend);
|
|
76
|
+
}
|
|
77
|
+
return config;
|
|
78
|
+
}
|
|
79
|
+
function createAppletBackendProxy(opts) {
|
|
80
|
+
const base = opts.basePath.replace(/\/+$/, "");
|
|
81
|
+
const target = opts.backendUrl.replace(/\/+$/, "");
|
|
82
|
+
return {
|
|
83
|
+
[base + "/rpc"]: target,
|
|
84
|
+
[base + "/stream"]: target
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function createLocalSdkAliases(opts) {
|
|
88
|
+
const enabled = opts?.enabled ?? Boolean(opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST);
|
|
89
|
+
const dir = opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST;
|
|
90
|
+
if (!enabled || !dir) return [];
|
|
91
|
+
const sdkDist = path2__default.default.resolve(dir);
|
|
92
|
+
return [
|
|
93
|
+
{ find: /^@iota-uz\/sdk\/bichat$/, replacement: path2__default.default.join(sdkDist, "bichat/index.mjs") },
|
|
94
|
+
{ find: /^@iota-uz\/sdk$/, replacement: path2__default.default.join(sdkDist, "index.mjs") }
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
function mergeConfig(a, b) {
|
|
98
|
+
const aResolve = a.resolve;
|
|
99
|
+
const bResolve = b.resolve;
|
|
100
|
+
const aServer = a.server;
|
|
101
|
+
const bServer = b.server;
|
|
102
|
+
const aPlugins = a.plugins;
|
|
103
|
+
const bPlugins = b.plugins;
|
|
104
|
+
const merged = { ...a, ...b };
|
|
105
|
+
if (bResolve) {
|
|
106
|
+
const aAlias = aResolve?.alias;
|
|
107
|
+
const bAlias = bResolve.alias;
|
|
108
|
+
const aIsArray = Array.isArray(aAlias);
|
|
109
|
+
const bIsArray = Array.isArray(bAlias);
|
|
110
|
+
const alias = aIsArray && bIsArray ? [...aAlias, ...bAlias] : bAlias !== void 0 ? bAlias : aResolve?.alias;
|
|
111
|
+
merged.resolve = {
|
|
112
|
+
...aResolve,
|
|
113
|
+
...bResolve,
|
|
114
|
+
alias,
|
|
115
|
+
dedupe: bResolve.dedupe ?? merged.resolve?.dedupe ?? aResolve?.dedupe
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (bServer) {
|
|
119
|
+
merged.server = { ...aServer, ...bServer };
|
|
120
|
+
}
|
|
121
|
+
if (bPlugins) {
|
|
122
|
+
merged.plugins = [...aPlugins ?? [], ...bPlugins];
|
|
123
|
+
}
|
|
124
|
+
return merged;
|
|
125
|
+
}
|
|
126
|
+
var VIRTUAL_APPLET_STYLES_ID = "virtual:applet-styles";
|
|
127
|
+
var RESOLVED_ID = "\0" + VIRTUAL_APPLET_STYLES_ID;
|
|
128
|
+
function resolvePrependPath(specifierOrPath, root) {
|
|
129
|
+
if (path2__default.default.isAbsolute(specifierOrPath)) {
|
|
130
|
+
return specifierOrPath;
|
|
131
|
+
}
|
|
132
|
+
if (!specifierOrPath.startsWith(".") && !specifierOrPath.startsWith("/")) {
|
|
133
|
+
try {
|
|
134
|
+
const req = module$1.createRequire(path2__default.default.join(root, "package.json"));
|
|
135
|
+
return req.resolve(specifierOrPath);
|
|
136
|
+
} catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return path2__default.default.join(root, specifierOrPath);
|
|
141
|
+
}
|
|
142
|
+
function createAppletStylesVirtualModulePlugin(options = {}) {
|
|
143
|
+
const inputCss = options.inputCss ?? "src/index.css";
|
|
144
|
+
const outputCssPath = options.outputCssPath ?? "dist/style.css";
|
|
145
|
+
const tailwindConfigPath = options.tailwindConfigPath;
|
|
146
|
+
const prependCss = options.prependCss ?? [];
|
|
147
|
+
let root = process.cwd();
|
|
148
|
+
return {
|
|
149
|
+
name: "applet-styles-virtual-module",
|
|
150
|
+
configResolved(config) {
|
|
151
|
+
root = config.root;
|
|
152
|
+
},
|
|
153
|
+
resolveId(id) {
|
|
154
|
+
if (id === VIRTUAL_APPLET_STYLES_ID) return RESOLVED_ID;
|
|
155
|
+
return null;
|
|
156
|
+
},
|
|
157
|
+
load(id) {
|
|
158
|
+
if (id !== RESOLVED_ID) return null;
|
|
159
|
+
const parts = [];
|
|
160
|
+
for (const p of prependCss) {
|
|
161
|
+
const full = resolvePrependPath(p, root);
|
|
162
|
+
if (full) {
|
|
163
|
+
try {
|
|
164
|
+
parts.push(fs2__default.default.readFileSync(full, "utf-8"));
|
|
165
|
+
} catch {
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const inputPath = path2__default.default.join(root, inputCss);
|
|
170
|
+
let mainCss = null;
|
|
171
|
+
if (fs2__default.default.existsSync(inputPath)) {
|
|
172
|
+
const tmpFile = path2__default.default.join(os__default.default.tmpdir(), `applet-styles-${Date.now()}-${crypto__default.default.randomUUID()}.css`);
|
|
173
|
+
const args = ["-i", inputPath, "-o", tmpFile];
|
|
174
|
+
if (tailwindConfigPath) {
|
|
175
|
+
const configPath = path2__default.default.join(root, tailwindConfigPath);
|
|
176
|
+
if (fs2__default.default.existsSync(configPath)) {
|
|
177
|
+
args.push("-c", configPath);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const pnpmCmd = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
|
|
181
|
+
const result = child_process.spawnSync(pnpmCmd, ["exec", "tailwindcss", ...args], {
|
|
182
|
+
cwd: root,
|
|
183
|
+
stdio: "pipe"
|
|
184
|
+
});
|
|
185
|
+
if (result.status === 0 && fs2__default.default.existsSync(tmpFile)) {
|
|
186
|
+
mainCss = fs2__default.default.readFileSync(tmpFile, "utf-8");
|
|
187
|
+
try {
|
|
188
|
+
fs2__default.default.unlinkSync(tmpFile);
|
|
189
|
+
} catch {
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (mainCss === null) {
|
|
194
|
+
const fallbackPath = path2__default.default.isAbsolute(outputCssPath) ? outputCssPath : path2__default.default.join(root, outputCssPath);
|
|
195
|
+
try {
|
|
196
|
+
mainCss = fs2__default.default.readFileSync(fallbackPath, "utf-8");
|
|
197
|
+
} catch {
|
|
198
|
+
if (process.env.NODE_ENV !== "production") {
|
|
199
|
+
console.warn(
|
|
200
|
+
`[applet-styles] Could not compile via Tailwind CLI and ${fallbackPath} not found; export empty string. Install tailwindcss in the project or build CSS first.`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
mainCss = "";
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
parts.push(mainCss);
|
|
207
|
+
const css = parts.join("\n");
|
|
208
|
+
return `export default ${JSON.stringify(css)}`;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function createBichatStylesPlugin(options = {}) {
|
|
213
|
+
return createAppletStylesVirtualModulePlugin({
|
|
214
|
+
...options,
|
|
215
|
+
inputCss: options.inputCss ?? "src/index.css",
|
|
216
|
+
outputCssPath: options.outputCssPath ?? "dist/style.css",
|
|
217
|
+
prependCss: ["@iota-uz/sdk/bichat/styles.css"]
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
exports.VIRTUAL_APPLET_STYLES_ID = VIRTUAL_APPLET_STYLES_ID;
|
|
222
|
+
exports.createAppletBackendProxy = createAppletBackendProxy;
|
|
223
|
+
exports.createAppletStylesVirtualModulePlugin = createAppletStylesVirtualModulePlugin;
|
|
224
|
+
exports.createAppletViteConfig = createAppletViteConfig;
|
|
225
|
+
exports.createBichatStylesPlugin = createBichatStylesPlugin;
|
|
226
|
+
exports.createLocalSdkAliases = createLocalSdkAliases;
|
|
227
|
+
exports.getAppletAssetsBase = getAppletAssetsBase;
|
|
228
|
+
exports.getAppletVitePort = getAppletVitePort;
|
|
229
|
+
exports.readAppletDevManifest = readAppletDevManifest;
|
|
230
|
+
//# sourceMappingURL=vite.cjs.map
|
|
231
|
+
//# sourceMappingURL=vite.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../ui/src/applet-vite/vite.ts","../../ui/src/applet-vite/styles-plugin.ts"],"names":["path","fs","base","createRequire","os","crypto","spawnSync"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,IAAM,mBAAA,GAAsB,iBAAA;AAMrB,SAAS,sBAAsB,OAAA,EAA4C;AAChF,EAAA,MAAM,GAAA,GAAM,OAAA,IAAW,OAAA,CAAQ,GAAA,EAAI;AACnC,EAAA,MAAM,QAAA,GAAWA,sBAAA,CAAK,IAAA,CAAK,GAAA,EAAK,mBAAmB,CAAA;AACnD,EAAA,IAAI;AACF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base path\n * with dev proxy and optional local SDK aliasing.\n */\nimport type { UserConfig } from 'vite'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nexport type AppletViteOptions = {\n /** Applet base path (e.g. \"/admin/ali/chat\" or \"/bi-chat\"); overridden by applet-dev.json when present. */\n basePath: string\n /** Backend URL for proxy (e.g. \"http://localhost:3200\"); overridden by applet-dev.json when present. */\n backendUrl: string\n /** Directory containing applet-dev.json (default: process.cwd()). When set, base/port/proxy use manifest if present. */\n viteConfigDir?: string\n /** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */\n enableLocalSdkAliases?: boolean\n /** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */\n sdkDistDir?: string\n /** Merge additional Vite config */\n extend?: UserConfig\n}\n\n/** Shape of applet-dev.json written by the Go dev runner (single source of truth when using `just dev <name>`). */\nexport type AppletDevManifest = {\n basePath: string\n assetsBase: string\n vitePort: number\n backendUrl: string\n}\n\nconst APPLET_DEV_MANIFEST = 'applet-dev.json'\n\n/**\n * Reads applet-dev.json from viteDir (default process.cwd()). When using `just dev <name>`, the Go runner writes this file.\n * Returns null if file is missing or invalid (env vars remain the fallback).\n */\nexport function readAppletDevManifest(viteDir?: string): AppletDevManifest | null {\n const dir = viteDir ?? process.cwd()\n const filePath = path.join(dir, APPLET_DEV_MANIFEST)\n try {\n const raw = fs.readFileSync(filePath, 'utf-8')\n const data = JSON.parse(raw) as AppletDevManifest\n if (typeof data.basePath === 'string' && typeof data.assetsBase === 'string' && typeof data.vitePort === 'number' && typeof data.backendUrl === 'string') {\n return data\n }\n } catch {\n // file missing or invalid\n }\n return null\n}\n\nconst DEFAULT_DEDUPE = ['react', 'react-dom', 'react-router-dom', 'react-is']\n\nexport type AppletDevManifestOrNull = AppletDevManifest | null\n\n/**\n * Returns base URL for assets (with trailing slash). Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_ASSETS_BASE env.\n */\nexport function getAppletAssetsBase(viteDir?: string, manifest?: AppletDevManifestOrNull): string {\n const resolved = manifest ?? readAppletDevManifest(viteDir)\n if (resolved) {\n const base = resolved.assetsBase\n return base.endsWith('/') ? base : base + '/'\n }\n const base = process.env.APPLET_ASSETS_BASE ?? ''\n return base.endsWith('/') ? base : base ? base + '/' : '/'\n}\n\n/**\n * Returns dev server port. Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_VITE_PORT env.\n */\nexport function getAppletVitePort(defaultPort = 5173, viteDir?: string, manifest?: AppletDevManifestOrNull): number {\n const resolved = manifest ?? readAppletDevManifest(viteDir)\n if (resolved) return resolved.vitePort\n const p = process.env.APPLET_VITE_PORT\n if (p === undefined || p === '') return defaultPort\n const n = Number(p)\n return Number.isFinite(n) ? n : defaultPort\n}\n\n/**\n * Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.\n * When applet-dev.json is present (e.g. when using `just dev <name>`), base, port, basePath, and backendUrl come from it.\n *\n * **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:\n * - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).\n * - **plugins**: arrays are concatenated (base plugins first, then extend plugins).\n * - **server**, **base**, **resolve.dedupe** and other scalar/object fields: extend overrides base (Object.assign-style).\n * To fully override the base config, spread first: `defineConfig({ ...createAppletViteConfig(opts), ...yourOverrides })`.\n */\nexport function createAppletViteConfig(opts: AppletViteOptions): UserConfig {\n const manifest = readAppletDevManifest(opts.viteConfigDir)\n const base = getAppletAssetsBase(opts.viteConfigDir, manifest)\n const port = getAppletVitePort(5173, opts.viteConfigDir, manifest)\n const basePath = manifest?.basePath ?? opts.basePath\n const backendUrl = manifest?.backendUrl ?? opts.backendUrl\n const config: UserConfig = {\n base,\n resolve: {\n dedupe: DEFAULT_DEDUPE,\n alias: createLocalSdkAliases({\n enabled: opts.enableLocalSdkAliases ?? Boolean(process.env.IOTA_SDK_DIST),\n sdkDistDir: opts.sdkDistDir ?? process.env.IOTA_SDK_DIST,\n }),\n },\n server: {\n port,\n strictPort: true,\n proxy: createAppletBackendProxy({\n basePath,\n backendUrl,\n }),\n },\n }\n if (opts.extend) {\n return mergeConfig(config, opts.extend)\n }\n return config\n}\n\n/**\n * Returns proxy entries for applet RPC and stream under basePath.\n * Use as server.proxy in Vite config.\n * Note: /stream is SSE; plain string targets do not set ws or changeOrigin. If WebSocket upgrade or SSE proxying issues arise, configure proxy with ws: true or a custom configure.\n */\nexport function createAppletBackendProxy(opts: {\n basePath: string\n backendUrl: string\n}): Record<string, string> {\n const base = opts.basePath.replace(/\\/+$/, '')\n const target = opts.backendUrl.replace(/\\/+$/, '')\n return {\n [base + '/rpc']: target,\n [base + '/stream']: target,\n }\n}\n\n/**\n * Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.\n * Use when IOTA_SDK_DIST is set or sdkDistDir is passed, so the app uses the local SDK build with HMR.\n */\nexport function createLocalSdkAliases(opts?: {\n enabled?: boolean\n sdkDistDir?: string\n}): Array<{ find: string | RegExp; replacement: string }> {\n const enabled = opts?.enabled ?? Boolean(opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST)\n const dir = opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST\n if (!enabled || !dir) return []\n const sdkDist = path.resolve(dir)\n return [\n { find: /^@iota-uz\\/sdk\\/bichat$/, replacement: path.join(sdkDist, 'bichat/index.mjs') },\n { find: /^@iota-uz\\/sdk$/, replacement: path.join(sdkDist, 'index.mjs') },\n ]\n}\n\n/**\n * Merges base config with extend. Start with merged = { ...a, ...b } so no Vite fields from b are dropped.\n * We capture a.resolve, b.resolve, a.server, b.server, a.plugins, b.plugins before the spread so we never\n * read b's values as \"original\" a when merging. resolve.alias: only coerce to array when both sides are\n * actually arrays (concat); otherwise leave Record/object as-is and prefer b's value then a's.\n */\nfunction mergeConfig(a: UserConfig, b: UserConfig): UserConfig {\n const aResolve = a.resolve\n const bResolve = b.resolve\n const aServer = a.server\n const bServer = b.server\n const aPlugins = a.plugins\n const bPlugins = b.plugins\n\n const merged: UserConfig = { ...a, ...b }\n\n if (bResolve) {\n const aAlias = aResolve?.alias\n const bAlias = bResolve.alias\n const aIsArray = Array.isArray(aAlias)\n const bIsArray = Array.isArray(bAlias)\n const alias =\n aIsArray && bIsArray\n ? [...(aAlias as Array<{ find: string | RegExp; replacement: string }>), ...(bAlias as Array<{ find: string | RegExp; replacement: string }>)]\n : (bAlias !== undefined ? bAlias : aResolve?.alias)\n merged.resolve = {\n ...aResolve,\n ...bResolve,\n alias,\n dedupe: bResolve.dedupe ?? merged.resolve?.dedupe ?? aResolve?.dedupe,\n }\n }\n if (bServer) {\n merged.server = { ...aServer, ...bServer }\n }\n if (bPlugins) {\n merged.plugins = [...(aPlugins ?? []), ...bPlugins]\n }\n return merged\n}\n","/**\n * Vite plugin that provides a virtual module exporting the compiled applet CSS string\n * for Shadow DOM injection (defineReactAppletElement({ styles })).\n * Can compile CSS via Tailwind CLI in the plugin or fall back to reading a prebuilt file.\n */\nimport type { Plugin } from 'vite'\nimport { spawnSync } from 'node:child_process'\nimport crypto from 'node:crypto'\nimport fs from 'node:fs'\nimport { createRequire } from 'node:module'\nimport os from 'node:os'\nimport path from 'node:path'\n\nexport const VIRTUAL_APPLET_STYLES_ID = 'virtual:applet-styles'\nconst RESOLVED_ID = '\\0' + VIRTUAL_APPLET_STYLES_ID\n\nexport type AppletStylesVirtualModuleOptions = {\n /**\n * Input CSS for Tailwind (e.g. src/index.css). When set, the plugin tries to run Tailwind CLI to compile.\n * Default: \"src/index.css\"\n */\n inputCss?: string\n /**\n * Path to Tailwind config (optional). If not set, CLI uses its default lookup.\n */\n tailwindConfigPath?: string\n /**\n * Path to the compiled CSS file when not using Tailwind CLI (fallback), or when Tailwind is not available.\n * Default: \"dist/style.css\"\n */\n outputCssPath?: string\n /**\n * CSS to prepend: package specifiers (e.g. \"@iota-uz/sdk/bichat/styles.css\") or paths relative to project root.\n * Specifiers are resolved via Node resolution from the project root.\n * Default: []\n */\n prependCss?: string[]\n}\n\n/**\n * Resolves a prepend CSS entry: absolute paths returned as-is; non-relative, non-absolute\n * specifiers (e.g. @iota-uz/sdk/bichat/styles.css or some-lib/styles.css) are resolved via\n * Node module resolution first; relative paths are joined to root.\n */\nfunction resolvePrependPath(specifierOrPath: string, root: string): string | null {\n if (path.isAbsolute(specifierOrPath)) {\n return specifierOrPath\n }\n if (!specifierOrPath.startsWith('.') && !specifierOrPath.startsWith('/')) {\n try {\n const req = createRequire(path.join(root, 'package.json'))\n return req.resolve(specifierOrPath)\n } catch {\n return null\n }\n }\n return path.join(root, specifierOrPath)\n}\n\n/**\n * Creates a Vite plugin that registers virtual:applet-styles and exports the compiled CSS string.\n * When inputCss is set, tries to run Tailwind CLI to compile; if Tailwind is not available, falls back to reading outputCssPath.\n */\nexport function createAppletStylesVirtualModulePlugin(\n options: AppletStylesVirtualModuleOptions = {}\n): Plugin {\n const inputCss = options.inputCss ?? 'src/index.css'\n const outputCssPath = options.outputCssPath ?? 'dist/style.css'\n const tailwindConfigPath = options.tailwindConfigPath\n const prependCss = options.prependCss ?? []\n let root = process.cwd()\n\n return {\n name: 'applet-styles-virtual-module',\n configResolved(config) {\n root = config.root\n },\n resolveId(id: string) {\n if (id === VIRTUAL_APPLET_STYLES_ID) return RESOLVED_ID\n return null\n },\n load(id: string) {\n if (id !== RESOLVED_ID) return null\n\n const parts: string[] = []\n\n for (const p of prependCss) {\n const full = resolvePrependPath(p, root)\n if (full) {\n try {\n parts.push(fs.readFileSync(full, 'utf-8'))\n } catch {\n // Prepend file missing (e.g. optional SDK styles); skip\n }\n }\n }\n\n const inputPath = path.join(root, inputCss)\n let mainCss: string | null = null\n\n // Try Tailwind CLI if input file exists. spawnSync blocks the event loop; for parallel builds consider a random suffix (e.g. crypto.randomUUID()).\n if (fs.existsSync(inputPath)) {\n const tmpFile = path.join(os.tmpdir(), `applet-styles-${Date.now()}-${crypto.randomUUID()}.css`)\n const args = ['-i', inputPath, '-o', tmpFile]\n if (tailwindConfigPath) {\n const configPath = path.join(root, tailwindConfigPath)\n if (fs.existsSync(configPath)) {\n args.push('-c', configPath)\n }\n }\n // Use platform-specific executable and no shell so args (paths with spaces) are passed safely on Windows.\n const pnpmCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'\n const result = spawnSync(pnpmCmd, ['exec', 'tailwindcss', ...args], {\n cwd: root,\n stdio: 'pipe',\n })\n if (result.status === 0 && fs.existsSync(tmpFile)) {\n mainCss = fs.readFileSync(tmpFile, 'utf-8')\n try {\n fs.unlinkSync(tmpFile)\n } catch {\n /* ignore */\n }\n }\n }\n\n if (mainCss === null) {\n const fallbackPath = path.isAbsolute(outputCssPath) ? outputCssPath : path.join(root, outputCssPath)\n try {\n mainCss = fs.readFileSync(fallbackPath, 'utf-8')\n } catch {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[applet-styles] Could not compile via Tailwind CLI and ${fallbackPath} not found; export empty string. Install tailwindcss in the project or build CSS first.`\n )\n }\n mainCss = ''\n }\n }\n\n parts.push(mainCss)\n const css = parts.join('\\n')\n return `export default ${JSON.stringify(css)}`\n },\n }\n}\n\n/**\n * Convenience plugin for BiChat applets: compiles app CSS and prepends SDK BiChat styles.\n * Uses default input src/index.css and package specifier @iota-uz/sdk/bichat/styles.css.\n */\nexport function createBichatStylesPlugin(\n options: Omit<AppletStylesVirtualModuleOptions, 'prependCss'> = {}\n): Plugin {\n return createAppletStylesVirtualModulePlugin({\n ...options,\n inputCss: options.inputCss ?? 'src/index.css',\n outputCssPath: options.outputCssPath ?? 'dist/style.css',\n prependCss: ['@iota-uz/sdk/bichat/styles.css'],\n })\n}\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { UserConfig, Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Applet Frontend Kit: Vite config helpers for applets running behind a base path
|
|
5
|
+
* with dev proxy and optional local SDK aliasing.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type AppletViteOptions = {
|
|
9
|
+
/** Applet base path (e.g. "/admin/ali/chat" or "/bi-chat"); overridden by applet-dev.json when present. */
|
|
10
|
+
basePath: string;
|
|
11
|
+
/** Backend URL for proxy (e.g. "http://localhost:3200"); overridden by applet-dev.json when present. */
|
|
12
|
+
backendUrl: string;
|
|
13
|
+
/** Directory containing applet-dev.json (default: process.cwd()). When set, base/port/proxy use manifest if present. */
|
|
14
|
+
viteConfigDir?: string;
|
|
15
|
+
/** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */
|
|
16
|
+
enableLocalSdkAliases?: boolean;
|
|
17
|
+
/** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */
|
|
18
|
+
sdkDistDir?: string;
|
|
19
|
+
/** Merge additional Vite config */
|
|
20
|
+
extend?: UserConfig;
|
|
21
|
+
};
|
|
22
|
+
/** Shape of applet-dev.json written by the Go dev runner (single source of truth when using `just dev <name>`). */
|
|
23
|
+
type AppletDevManifest = {
|
|
24
|
+
basePath: string;
|
|
25
|
+
assetsBase: string;
|
|
26
|
+
vitePort: number;
|
|
27
|
+
backendUrl: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Reads applet-dev.json from viteDir (default process.cwd()). When using `just dev <name>`, the Go runner writes this file.
|
|
31
|
+
* Returns null if file is missing or invalid (env vars remain the fallback).
|
|
32
|
+
*/
|
|
33
|
+
declare function readAppletDevManifest(viteDir?: string): AppletDevManifest | null;
|
|
34
|
+
type AppletDevManifestOrNull = AppletDevManifest | null;
|
|
35
|
+
/**
|
|
36
|
+
* Returns base URL for assets (with trailing slash). Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_ASSETS_BASE env.
|
|
37
|
+
*/
|
|
38
|
+
declare function getAppletAssetsBase(viteDir?: string, manifest?: AppletDevManifestOrNull): string;
|
|
39
|
+
/**
|
|
40
|
+
* Returns dev server port. Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_VITE_PORT env.
|
|
41
|
+
*/
|
|
42
|
+
declare function getAppletVitePort(defaultPort?: number, viteDir?: string, manifest?: AppletDevManifestOrNull): number;
|
|
43
|
+
/**
|
|
44
|
+
* Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.
|
|
45
|
+
* When applet-dev.json is present (e.g. when using `just dev <name>`), base, port, basePath, and backendUrl come from it.
|
|
46
|
+
*
|
|
47
|
+
* **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:
|
|
48
|
+
* - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).
|
|
49
|
+
* - **plugins**: arrays are concatenated (base plugins first, then extend plugins).
|
|
50
|
+
* - **server**, **base**, **resolve.dedupe** and other scalar/object fields: extend overrides base (Object.assign-style).
|
|
51
|
+
* To fully override the base config, spread first: `defineConfig({ ...createAppletViteConfig(opts), ...yourOverrides })`.
|
|
52
|
+
*/
|
|
53
|
+
declare function createAppletViteConfig(opts: AppletViteOptions): UserConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Returns proxy entries for applet RPC and stream under basePath.
|
|
56
|
+
* Use as server.proxy in Vite config.
|
|
57
|
+
* Note: /stream is SSE; plain string targets do not set ws or changeOrigin. If WebSocket upgrade or SSE proxying issues arise, configure proxy with ws: true or a custom configure.
|
|
58
|
+
*/
|
|
59
|
+
declare function createAppletBackendProxy(opts: {
|
|
60
|
+
basePath: string;
|
|
61
|
+
backendUrl: string;
|
|
62
|
+
}): Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.
|
|
65
|
+
* Use when IOTA_SDK_DIST is set or sdkDistDir is passed, so the app uses the local SDK build with HMR.
|
|
66
|
+
*/
|
|
67
|
+
declare function createLocalSdkAliases(opts?: {
|
|
68
|
+
enabled?: boolean;
|
|
69
|
+
sdkDistDir?: string;
|
|
70
|
+
}): Array<{
|
|
71
|
+
find: string | RegExp;
|
|
72
|
+
replacement: string;
|
|
73
|
+
}>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Vite plugin that provides a virtual module exporting the compiled applet CSS string
|
|
77
|
+
* for Shadow DOM injection (defineReactAppletElement({ styles })).
|
|
78
|
+
* Can compile CSS via Tailwind CLI in the plugin or fall back to reading a prebuilt file.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
declare const VIRTUAL_APPLET_STYLES_ID = "virtual:applet-styles";
|
|
82
|
+
type AppletStylesVirtualModuleOptions = {
|
|
83
|
+
/**
|
|
84
|
+
* Input CSS for Tailwind (e.g. src/index.css). When set, the plugin tries to run Tailwind CLI to compile.
|
|
85
|
+
* Default: "src/index.css"
|
|
86
|
+
*/
|
|
87
|
+
inputCss?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Path to Tailwind config (optional). If not set, CLI uses its default lookup.
|
|
90
|
+
*/
|
|
91
|
+
tailwindConfigPath?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Path to the compiled CSS file when not using Tailwind CLI (fallback), or when Tailwind is not available.
|
|
94
|
+
* Default: "dist/style.css"
|
|
95
|
+
*/
|
|
96
|
+
outputCssPath?: string;
|
|
97
|
+
/**
|
|
98
|
+
* CSS to prepend: package specifiers (e.g. "@iota-uz/sdk/bichat/styles.css") or paths relative to project root.
|
|
99
|
+
* Specifiers are resolved via Node resolution from the project root.
|
|
100
|
+
* Default: []
|
|
101
|
+
*/
|
|
102
|
+
prependCss?: string[];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Creates a Vite plugin that registers virtual:applet-styles and exports the compiled CSS string.
|
|
106
|
+
* When inputCss is set, tries to run Tailwind CLI to compile; if Tailwind is not available, falls back to reading outputCssPath.
|
|
107
|
+
*/
|
|
108
|
+
declare function createAppletStylesVirtualModulePlugin(options?: AppletStylesVirtualModuleOptions): Plugin;
|
|
109
|
+
/**
|
|
110
|
+
* Convenience plugin for BiChat applets: compiles app CSS and prepends SDK BiChat styles.
|
|
111
|
+
* Uses default input src/index.css and package specifier @iota-uz/sdk/bichat/styles.css.
|
|
112
|
+
*/
|
|
113
|
+
declare function createBichatStylesPlugin(options?: Omit<AppletStylesVirtualModuleOptions, 'prependCss'>): Plugin;
|
|
114
|
+
|
|
115
|
+
export { type AppletDevManifest, type AppletStylesVirtualModuleOptions, type AppletViteOptions, VIRTUAL_APPLET_STYLES_ID, createAppletBackendProxy, createAppletStylesVirtualModulePlugin, createAppletViteConfig, createBichatStylesPlugin, createLocalSdkAliases, getAppletAssetsBase, getAppletVitePort, readAppletDevManifest };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { UserConfig, Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Applet Frontend Kit: Vite config helpers for applets running behind a base path
|
|
5
|
+
* with dev proxy and optional local SDK aliasing.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type AppletViteOptions = {
|
|
9
|
+
/** Applet base path (e.g. "/admin/ali/chat" or "/bi-chat"); overridden by applet-dev.json when present. */
|
|
10
|
+
basePath: string;
|
|
11
|
+
/** Backend URL for proxy (e.g. "http://localhost:3200"); overridden by applet-dev.json when present. */
|
|
12
|
+
backendUrl: string;
|
|
13
|
+
/** Directory containing applet-dev.json (default: process.cwd()). When set, base/port/proxy use manifest if present. */
|
|
14
|
+
viteConfigDir?: string;
|
|
15
|
+
/** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */
|
|
16
|
+
enableLocalSdkAliases?: boolean;
|
|
17
|
+
/** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */
|
|
18
|
+
sdkDistDir?: string;
|
|
19
|
+
/** Merge additional Vite config */
|
|
20
|
+
extend?: UserConfig;
|
|
21
|
+
};
|
|
22
|
+
/** Shape of applet-dev.json written by the Go dev runner (single source of truth when using `just dev <name>`). */
|
|
23
|
+
type AppletDevManifest = {
|
|
24
|
+
basePath: string;
|
|
25
|
+
assetsBase: string;
|
|
26
|
+
vitePort: number;
|
|
27
|
+
backendUrl: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Reads applet-dev.json from viteDir (default process.cwd()). When using `just dev <name>`, the Go runner writes this file.
|
|
31
|
+
* Returns null if file is missing or invalid (env vars remain the fallback).
|
|
32
|
+
*/
|
|
33
|
+
declare function readAppletDevManifest(viteDir?: string): AppletDevManifest | null;
|
|
34
|
+
type AppletDevManifestOrNull = AppletDevManifest | null;
|
|
35
|
+
/**
|
|
36
|
+
* Returns base URL for assets (with trailing slash). Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_ASSETS_BASE env.
|
|
37
|
+
*/
|
|
38
|
+
declare function getAppletAssetsBase(viteDir?: string, manifest?: AppletDevManifestOrNull): string;
|
|
39
|
+
/**
|
|
40
|
+
* Returns dev server port. Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_VITE_PORT env.
|
|
41
|
+
*/
|
|
42
|
+
declare function getAppletVitePort(defaultPort?: number, viteDir?: string, manifest?: AppletDevManifestOrNull): number;
|
|
43
|
+
/**
|
|
44
|
+
* Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.
|
|
45
|
+
* When applet-dev.json is present (e.g. when using `just dev <name>`), base, port, basePath, and backendUrl come from it.
|
|
46
|
+
*
|
|
47
|
+
* **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:
|
|
48
|
+
* - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).
|
|
49
|
+
* - **plugins**: arrays are concatenated (base plugins first, then extend plugins).
|
|
50
|
+
* - **server**, **base**, **resolve.dedupe** and other scalar/object fields: extend overrides base (Object.assign-style).
|
|
51
|
+
* To fully override the base config, spread first: `defineConfig({ ...createAppletViteConfig(opts), ...yourOverrides })`.
|
|
52
|
+
*/
|
|
53
|
+
declare function createAppletViteConfig(opts: AppletViteOptions): UserConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Returns proxy entries for applet RPC and stream under basePath.
|
|
56
|
+
* Use as server.proxy in Vite config.
|
|
57
|
+
* Note: /stream is SSE; plain string targets do not set ws or changeOrigin. If WebSocket upgrade or SSE proxying issues arise, configure proxy with ws: true or a custom configure.
|
|
58
|
+
*/
|
|
59
|
+
declare function createAppletBackendProxy(opts: {
|
|
60
|
+
basePath: string;
|
|
61
|
+
backendUrl: string;
|
|
62
|
+
}): Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.
|
|
65
|
+
* Use when IOTA_SDK_DIST is set or sdkDistDir is passed, so the app uses the local SDK build with HMR.
|
|
66
|
+
*/
|
|
67
|
+
declare function createLocalSdkAliases(opts?: {
|
|
68
|
+
enabled?: boolean;
|
|
69
|
+
sdkDistDir?: string;
|
|
70
|
+
}): Array<{
|
|
71
|
+
find: string | RegExp;
|
|
72
|
+
replacement: string;
|
|
73
|
+
}>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Vite plugin that provides a virtual module exporting the compiled applet CSS string
|
|
77
|
+
* for Shadow DOM injection (defineReactAppletElement({ styles })).
|
|
78
|
+
* Can compile CSS via Tailwind CLI in the plugin or fall back to reading a prebuilt file.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
declare const VIRTUAL_APPLET_STYLES_ID = "virtual:applet-styles";
|
|
82
|
+
type AppletStylesVirtualModuleOptions = {
|
|
83
|
+
/**
|
|
84
|
+
* Input CSS for Tailwind (e.g. src/index.css). When set, the plugin tries to run Tailwind CLI to compile.
|
|
85
|
+
* Default: "src/index.css"
|
|
86
|
+
*/
|
|
87
|
+
inputCss?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Path to Tailwind config (optional). If not set, CLI uses its default lookup.
|
|
90
|
+
*/
|
|
91
|
+
tailwindConfigPath?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Path to the compiled CSS file when not using Tailwind CLI (fallback), or when Tailwind is not available.
|
|
94
|
+
* Default: "dist/style.css"
|
|
95
|
+
*/
|
|
96
|
+
outputCssPath?: string;
|
|
97
|
+
/**
|
|
98
|
+
* CSS to prepend: package specifiers (e.g. "@iota-uz/sdk/bichat/styles.css") or paths relative to project root.
|
|
99
|
+
* Specifiers are resolved via Node resolution from the project root.
|
|
100
|
+
* Default: []
|
|
101
|
+
*/
|
|
102
|
+
prependCss?: string[];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Creates a Vite plugin that registers virtual:applet-styles and exports the compiled CSS string.
|
|
106
|
+
* When inputCss is set, tries to run Tailwind CLI to compile; if Tailwind is not available, falls back to reading outputCssPath.
|
|
107
|
+
*/
|
|
108
|
+
declare function createAppletStylesVirtualModulePlugin(options?: AppletStylesVirtualModuleOptions): Plugin;
|
|
109
|
+
/**
|
|
110
|
+
* Convenience plugin for BiChat applets: compiles app CSS and prepends SDK BiChat styles.
|
|
111
|
+
* Uses default input src/index.css and package specifier @iota-uz/sdk/bichat/styles.css.
|
|
112
|
+
*/
|
|
113
|
+
declare function createBichatStylesPlugin(options?: Omit<AppletStylesVirtualModuleOptions, 'prependCss'>): Plugin;
|
|
114
|
+
|
|
115
|
+
export { type AppletDevManifest, type AppletStylesVirtualModuleOptions, type AppletViteOptions, VIRTUAL_APPLET_STYLES_ID, createAppletBackendProxy, createAppletStylesVirtualModulePlugin, createAppletViteConfig, createBichatStylesPlugin, createLocalSdkAliases, getAppletAssetsBase, getAppletVitePort, readAppletDevManifest };
|