@whatalo/cli-kit 1.0.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/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/config/index.cjs +250 -0
- package/dist/config/index.d.cts +75 -0
- package/dist/config/index.d.ts +75 -0
- package/dist/config/index.mjs +205 -0
- package/dist/env-file-KvUHlLtI.d.cts +67 -0
- package/dist/env-file-KvUHlLtI.d.ts +67 -0
- package/dist/http/index.cjs +194 -0
- package/dist/http/index.d.cts +56 -0
- package/dist/http/index.d.ts +56 -0
- package/dist/http/index.mjs +166 -0
- package/dist/index.cjs +1055 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.mjs +978 -0
- package/dist/output/index.cjs +276 -0
- package/dist/output/index.d.cts +149 -0
- package/dist/output/index.d.ts +149 -0
- package/dist/output/index.mjs +221 -0
- package/dist/session/index.cjs +184 -0
- package/dist/session/index.d.cts +82 -0
- package/dist/session/index.d.ts +82 -0
- package/dist/session/index.mjs +139 -0
- package/dist/tunnel/index.cjs +252 -0
- package/dist/tunnel/index.d.cts +70 -0
- package/dist/tunnel/index.d.ts +70 -0
- package/dist/tunnel/index.mjs +214 -0
- package/dist/types-DunvRQ0f.d.cts +63 -0
- package/dist/types-DunvRQ0f.d.ts +63 -0
- package/dist/version/index.cjs +204 -0
- package/dist/version/index.d.cts +41 -0
- package/dist/version/index.d.ts +41 -0
- package/dist/version/index.mjs +164 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Whatalo Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @whatalo/cli-kit
|
|
2
|
+
|
|
3
|
+
Shared runtime utilities for the Whatalo CLI ecosystem.
|
|
4
|
+
|
|
5
|
+
This package powers `@whatalo/cli` and related developer tools with reusable modules for:
|
|
6
|
+
|
|
7
|
+
- session storage and device authentication flows
|
|
8
|
+
- authenticated HTTP requests
|
|
9
|
+
- CLI output formatting and error handling
|
|
10
|
+
- project configuration loading and validation
|
|
11
|
+
- local tunnel management
|
|
12
|
+
- version checks and upgrade messaging
|
|
13
|
+
|
|
14
|
+
## Intended usage
|
|
15
|
+
|
|
16
|
+
`@whatalo/cli-kit` is a support package for Whatalo developer tooling. Most developers should install and use `@whatalo/cli` instead of consuming this package directly.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @whatalo/cli-kit
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Module entry points
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { getSession } from "@whatalo/cli-kit/session";
|
|
28
|
+
import { WhataloApiClient } from "@whatalo/cli-kit/http";
|
|
29
|
+
import { success, withErrorHandler } from "@whatalo/cli-kit/output";
|
|
30
|
+
import { readConfig } from "@whatalo/cli-kit/config";
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Requirements
|
|
34
|
+
|
|
35
|
+
- Node.js 18 or newer
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
Developer documentation is available at `developers.whatalo.com`.
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/config/index.ts
|
|
31
|
+
var config_exports = {};
|
|
32
|
+
__export(config_exports, {
|
|
33
|
+
CONFIG_FILE_NAME: () => CONFIG_FILE_NAME,
|
|
34
|
+
REQUIRED_FIELDS: () => REQUIRED_FIELDS,
|
|
35
|
+
loadManifest: () => loadManifest,
|
|
36
|
+
parseEnvFile: () => parseEnvFile,
|
|
37
|
+
pluginConfigSchema: () => pluginConfigSchema,
|
|
38
|
+
readConfig: () => readConfig,
|
|
39
|
+
updateEnvFile: () => updateEnvFile,
|
|
40
|
+
validateConfig: () => validateConfig,
|
|
41
|
+
writeConfig: () => writeConfig
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(config_exports);
|
|
44
|
+
|
|
45
|
+
// src/config/toml.ts
|
|
46
|
+
var import_promises = require("fs/promises");
|
|
47
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
48
|
+
var import_toml = __toESM(require("@iarna/toml"), 1);
|
|
49
|
+
|
|
50
|
+
// src/config/types.ts
|
|
51
|
+
var REQUIRED_FIELDS = [
|
|
52
|
+
"plugin.name",
|
|
53
|
+
"plugin.plugin_id",
|
|
54
|
+
"plugin.slug",
|
|
55
|
+
"build.dev_command",
|
|
56
|
+
"build.build_command",
|
|
57
|
+
"build.output_dir",
|
|
58
|
+
"dev.port"
|
|
59
|
+
];
|
|
60
|
+
var CONFIG_FILE_NAME = "whatalo.app.toml";
|
|
61
|
+
|
|
62
|
+
// src/config/toml.ts
|
|
63
|
+
async function readConfig(dir) {
|
|
64
|
+
const filePath = import_node_path.default.join(dir, CONFIG_FILE_NAME);
|
|
65
|
+
let raw;
|
|
66
|
+
try {
|
|
67
|
+
raw = await (0, import_promises.readFile)(filePath, "utf-8");
|
|
68
|
+
} catch {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Could not find ${CONFIG_FILE_NAME} in "${dir}". Run \`whatalo init\` to set up your project.`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
let parsed;
|
|
74
|
+
try {
|
|
75
|
+
parsed = import_toml.default.parse(raw);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
78
|
+
throw new Error(
|
|
79
|
+
`Failed to parse ${CONFIG_FILE_NAME}: ${message}. Check for syntax errors.`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
validateRequiredFields(parsed);
|
|
83
|
+
return parsed;
|
|
84
|
+
}
|
|
85
|
+
async function writeConfig(dir, config) {
|
|
86
|
+
const filePath = import_node_path.default.join(dir, CONFIG_FILE_NAME);
|
|
87
|
+
const content = import_toml.default.stringify(config);
|
|
88
|
+
await (0, import_promises.writeFile)(filePath, content, "utf-8");
|
|
89
|
+
}
|
|
90
|
+
function validateRequiredFields(obj) {
|
|
91
|
+
for (const fieldPath of REQUIRED_FIELDS) {
|
|
92
|
+
const parts = fieldPath.split(".");
|
|
93
|
+
let current = obj;
|
|
94
|
+
for (const part of parts) {
|
|
95
|
+
if (current === null || current === void 0 || typeof current !== "object") {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`Missing \`${fieldPath}\` in ${CONFIG_FILE_NAME}. Run \`whatalo init\` to set up your project.`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
current = current[part];
|
|
101
|
+
}
|
|
102
|
+
if (current === null || current === void 0 || current === "") {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Missing \`${fieldPath}\` in ${CONFIG_FILE_NAME}. Run \`whatalo init\` to set up your project.`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/config/schema.ts
|
|
111
|
+
var import_zod = require("zod");
|
|
112
|
+
var pluginConfigSchema = import_zod.z.object({
|
|
113
|
+
plugin: import_zod.z.object({
|
|
114
|
+
name: import_zod.z.string().min(1, "Plugin name cannot be empty").max(100, "Plugin name must be 100 characters or fewer"),
|
|
115
|
+
plugin_id: import_zod.z.string().min(1, "plugin_id cannot be empty").regex(
|
|
116
|
+
/^[a-zA-Z0-9_-]+$/,
|
|
117
|
+
"Invalid plugin_id format. Must contain only alphanumeric characters, hyphens, or underscores."
|
|
118
|
+
),
|
|
119
|
+
slug: import_zod.z.string().regex(
|
|
120
|
+
/^[a-z0-9][a-z0-9-]*[a-z0-9]$/,
|
|
121
|
+
"Slug must be lowercase alphanumeric with hyphens, cannot start or end with a hyphen."
|
|
122
|
+
)
|
|
123
|
+
}),
|
|
124
|
+
build: import_zod.z.object({
|
|
125
|
+
dev_command: import_zod.z.string().min(1, "dev_command cannot be empty"),
|
|
126
|
+
build_command: import_zod.z.string().min(1, "build_command cannot be empty"),
|
|
127
|
+
output_dir: import_zod.z.string().min(1, "output_dir cannot be empty")
|
|
128
|
+
}).optional(),
|
|
129
|
+
webhooks: import_zod.z.object({
|
|
130
|
+
url: import_zod.z.string().url("Webhook URL must be a valid URL").refine((u) => u.startsWith("https://"), {
|
|
131
|
+
message: "Webhook URL must use HTTPS"
|
|
132
|
+
}).optional(),
|
|
133
|
+
events: import_zod.z.array(import_zod.z.string()).optional()
|
|
134
|
+
}).optional(),
|
|
135
|
+
dev: import_zod.z.object({
|
|
136
|
+
port: import_zod.z.number().int("Port must be an integer").min(1024, "Port must be >= 1024").max(65535, "Port must be <= 65535").default(5173),
|
|
137
|
+
store: import_zod.z.string().optional()
|
|
138
|
+
}).optional()
|
|
139
|
+
});
|
|
140
|
+
function validateConfig(raw) {
|
|
141
|
+
const result = pluginConfigSchema.safeParse(raw);
|
|
142
|
+
if (result.success) {
|
|
143
|
+
return { success: true, data: result.data };
|
|
144
|
+
}
|
|
145
|
+
const errors = result.error.issues.map((issue) => ({
|
|
146
|
+
path: issue.path.join("."),
|
|
147
|
+
message: issue.message
|
|
148
|
+
}));
|
|
149
|
+
return { success: false, errors };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/config/env-file.ts
|
|
153
|
+
var import_promises2 = require("fs/promises");
|
|
154
|
+
function parseEnvFile(content) {
|
|
155
|
+
const lines = content.split("\n");
|
|
156
|
+
return lines.map((raw) => {
|
|
157
|
+
const trimmed = raw.trim();
|
|
158
|
+
if (trimmed === "" || trimmed.startsWith("#")) {
|
|
159
|
+
return { raw };
|
|
160
|
+
}
|
|
161
|
+
const eqIndex = trimmed.indexOf("=");
|
|
162
|
+
if (eqIndex === -1) {
|
|
163
|
+
return { raw };
|
|
164
|
+
}
|
|
165
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
166
|
+
let value = trimmed.slice(eqIndex + 1).trim();
|
|
167
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
168
|
+
value = value.slice(1, -1);
|
|
169
|
+
}
|
|
170
|
+
return { raw, key, value };
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
async function updateEnvFile(filePath, vars) {
|
|
174
|
+
let existingContent = "";
|
|
175
|
+
try {
|
|
176
|
+
existingContent = await (0, import_promises2.readFile)(filePath, "utf-8");
|
|
177
|
+
} catch {
|
|
178
|
+
}
|
|
179
|
+
const entries = existingContent ? parseEnvFile(existingContent) : [];
|
|
180
|
+
const updatedKeys = /* @__PURE__ */ new Set();
|
|
181
|
+
const updatedLines = entries.map((entry) => {
|
|
182
|
+
if (entry.key && entry.key in vars) {
|
|
183
|
+
updatedKeys.add(entry.key);
|
|
184
|
+
return `${entry.key}=${vars[entry.key]}`;
|
|
185
|
+
}
|
|
186
|
+
return entry.raw;
|
|
187
|
+
});
|
|
188
|
+
const newVars = Object.entries(vars).filter(
|
|
189
|
+
([key]) => !updatedKeys.has(key)
|
|
190
|
+
);
|
|
191
|
+
if (newVars.length > 0) {
|
|
192
|
+
if (updatedLines.length > 0 && updatedLines[updatedLines.length - 1] !== "") {
|
|
193
|
+
updatedLines.push("");
|
|
194
|
+
}
|
|
195
|
+
updatedLines.push("# Whatalo Plugin Variables");
|
|
196
|
+
for (const [key, value] of newVars) {
|
|
197
|
+
updatedLines.push(`${key}=${value}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const output = updatedLines.join("\n");
|
|
201
|
+
await (0, import_promises2.writeFile)(filePath, output.endsWith("\n") ? output : output + "\n", "utf-8");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/config/manifest-loader.ts
|
|
205
|
+
var import_esbuild = require("esbuild");
|
|
206
|
+
var import_promises3 = require("fs/promises");
|
|
207
|
+
var import_node_os = require("os");
|
|
208
|
+
var import_node_url = require("url");
|
|
209
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
210
|
+
var MANIFEST_FILE_NAME = "whatalo.app.ts";
|
|
211
|
+
async function loadManifest(dir) {
|
|
212
|
+
const entryPoint = import_node_path2.default.join(dir, MANIFEST_FILE_NAME);
|
|
213
|
+
let tmpDir = null;
|
|
214
|
+
try {
|
|
215
|
+
tmpDir = await (0, import_promises3.mkdtemp)(import_node_path2.default.join((0, import_node_os.tmpdir)(), "whatalo-manifest-"));
|
|
216
|
+
const outfile = import_node_path2.default.join(tmpDir, "manifest.mjs");
|
|
217
|
+
await (0, import_esbuild.build)({
|
|
218
|
+
entryPoints: [entryPoint],
|
|
219
|
+
bundle: true,
|
|
220
|
+
format: "esm",
|
|
221
|
+
outfile,
|
|
222
|
+
platform: "node",
|
|
223
|
+
// Silence esbuild output — errors are caught below
|
|
224
|
+
logLevel: "silent"
|
|
225
|
+
});
|
|
226
|
+
const mod = await import((0, import_node_url.pathToFileURL)(outfile).href);
|
|
227
|
+
return mod.default ?? null;
|
|
228
|
+
} catch {
|
|
229
|
+
return null;
|
|
230
|
+
} finally {
|
|
231
|
+
if (tmpDir) {
|
|
232
|
+
try {
|
|
233
|
+
await (0, import_promises3.rm)(tmpDir, { recursive: true, force: true });
|
|
234
|
+
} catch {
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
240
|
+
0 && (module.exports = {
|
|
241
|
+
CONFIG_FILE_NAME,
|
|
242
|
+
REQUIRED_FIELDS,
|
|
243
|
+
loadManifest,
|
|
244
|
+
parseEnvFile,
|
|
245
|
+
pluginConfigSchema,
|
|
246
|
+
readConfig,
|
|
247
|
+
updateEnvFile,
|
|
248
|
+
validateConfig,
|
|
249
|
+
writeConfig
|
|
250
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export { C as CONFIG_FILE_NAME, E as EnvEntry, R as REQUIRED_FIELDS, W as WhataloAppConfig, p as parseEnvFile, r as readConfig, u as updateEnvFile, w as writeConfig } from '../env-file-KvUHlLtI.cjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Zod v4 schema for `whatalo.app.toml` validation.
|
|
6
|
+
* Provides typed, detailed error messages instead of manual field checks.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const pluginConfigSchema: z.ZodObject<{
|
|
10
|
+
plugin: z.ZodObject<{
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
plugin_id: z.ZodString;
|
|
13
|
+
slug: z.ZodString;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
build: z.ZodOptional<z.ZodObject<{
|
|
16
|
+
dev_command: z.ZodString;
|
|
17
|
+
build_command: z.ZodString;
|
|
18
|
+
output_dir: z.ZodString;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
webhooks: z.ZodOptional<z.ZodObject<{
|
|
21
|
+
url: z.ZodOptional<z.ZodString>;
|
|
22
|
+
events: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
+
}, z.core.$strip>>;
|
|
24
|
+
dev: z.ZodOptional<z.ZodObject<{
|
|
25
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
26
|
+
store: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
type PluginConfigSchema = z.infer<typeof pluginConfigSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* Validates a parsed TOML object against the plugin config schema.
|
|
32
|
+
* Returns a structured result with field-level errors.
|
|
33
|
+
*/
|
|
34
|
+
declare function validateConfig(raw: unknown): {
|
|
35
|
+
success: boolean;
|
|
36
|
+
data?: PluginConfigSchema;
|
|
37
|
+
errors?: Array<{
|
|
38
|
+
path: string;
|
|
39
|
+
message: string;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Subset of the AppManifest relevant for CLI operations */
|
|
44
|
+
interface ManifestData {
|
|
45
|
+
id?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
version?: string;
|
|
49
|
+
appUrl?: string;
|
|
50
|
+
webhookUrl?: string;
|
|
51
|
+
permissions?: string[];
|
|
52
|
+
adminUI?: {
|
|
53
|
+
pages?: Array<{
|
|
54
|
+
path: string;
|
|
55
|
+
title: string;
|
|
56
|
+
icon: string;
|
|
57
|
+
position: string;
|
|
58
|
+
navigationLabel?: string;
|
|
59
|
+
}>;
|
|
60
|
+
};
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Loads and evaluates the `whatalo.app.ts` manifest file from a plugin project.
|
|
65
|
+
*
|
|
66
|
+
* Uses esbuild to bundle the TypeScript file (including any imports like
|
|
67
|
+
* `@whatalo/app-sdk/manifest`) into a standalone ESM module, then dynamically
|
|
68
|
+
* imports it to extract the default export.
|
|
69
|
+
*
|
|
70
|
+
* Returns null if the file does not exist or fails to load — callers should
|
|
71
|
+
* treat this as a non-fatal condition and fall back gracefully.
|
|
72
|
+
*/
|
|
73
|
+
declare function loadManifest(dir: string): Promise<ManifestData | null>;
|
|
74
|
+
|
|
75
|
+
export { type ManifestData, type PluginConfigSchema, loadManifest, pluginConfigSchema, validateConfig };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export { C as CONFIG_FILE_NAME, E as EnvEntry, R as REQUIRED_FIELDS, W as WhataloAppConfig, p as parseEnvFile, r as readConfig, u as updateEnvFile, w as writeConfig } from '../env-file-KvUHlLtI.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Zod v4 schema for `whatalo.app.toml` validation.
|
|
6
|
+
* Provides typed, detailed error messages instead of manual field checks.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const pluginConfigSchema: z.ZodObject<{
|
|
10
|
+
plugin: z.ZodObject<{
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
plugin_id: z.ZodString;
|
|
13
|
+
slug: z.ZodString;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
build: z.ZodOptional<z.ZodObject<{
|
|
16
|
+
dev_command: z.ZodString;
|
|
17
|
+
build_command: z.ZodString;
|
|
18
|
+
output_dir: z.ZodString;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
webhooks: z.ZodOptional<z.ZodObject<{
|
|
21
|
+
url: z.ZodOptional<z.ZodString>;
|
|
22
|
+
events: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
+
}, z.core.$strip>>;
|
|
24
|
+
dev: z.ZodOptional<z.ZodObject<{
|
|
25
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
26
|
+
store: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
type PluginConfigSchema = z.infer<typeof pluginConfigSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* Validates a parsed TOML object against the plugin config schema.
|
|
32
|
+
* Returns a structured result with field-level errors.
|
|
33
|
+
*/
|
|
34
|
+
declare function validateConfig(raw: unknown): {
|
|
35
|
+
success: boolean;
|
|
36
|
+
data?: PluginConfigSchema;
|
|
37
|
+
errors?: Array<{
|
|
38
|
+
path: string;
|
|
39
|
+
message: string;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Subset of the AppManifest relevant for CLI operations */
|
|
44
|
+
interface ManifestData {
|
|
45
|
+
id?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
version?: string;
|
|
49
|
+
appUrl?: string;
|
|
50
|
+
webhookUrl?: string;
|
|
51
|
+
permissions?: string[];
|
|
52
|
+
adminUI?: {
|
|
53
|
+
pages?: Array<{
|
|
54
|
+
path: string;
|
|
55
|
+
title: string;
|
|
56
|
+
icon: string;
|
|
57
|
+
position: string;
|
|
58
|
+
navigationLabel?: string;
|
|
59
|
+
}>;
|
|
60
|
+
};
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Loads and evaluates the `whatalo.app.ts` manifest file from a plugin project.
|
|
65
|
+
*
|
|
66
|
+
* Uses esbuild to bundle the TypeScript file (including any imports like
|
|
67
|
+
* `@whatalo/app-sdk/manifest`) into a standalone ESM module, then dynamically
|
|
68
|
+
* imports it to extract the default export.
|
|
69
|
+
*
|
|
70
|
+
* Returns null if the file does not exist or fails to load — callers should
|
|
71
|
+
* treat this as a non-fatal condition and fall back gracefully.
|
|
72
|
+
*/
|
|
73
|
+
declare function loadManifest(dir: string): Promise<ManifestData | null>;
|
|
74
|
+
|
|
75
|
+
export { type ManifestData, type PluginConfigSchema, loadManifest, pluginConfigSchema, validateConfig };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// src/config/toml.ts
|
|
2
|
+
import { readFile, writeFile } from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import TOML from "@iarna/toml";
|
|
5
|
+
|
|
6
|
+
// src/config/types.ts
|
|
7
|
+
var REQUIRED_FIELDS = [
|
|
8
|
+
"plugin.name",
|
|
9
|
+
"plugin.plugin_id",
|
|
10
|
+
"plugin.slug",
|
|
11
|
+
"build.dev_command",
|
|
12
|
+
"build.build_command",
|
|
13
|
+
"build.output_dir",
|
|
14
|
+
"dev.port"
|
|
15
|
+
];
|
|
16
|
+
var CONFIG_FILE_NAME = "whatalo.app.toml";
|
|
17
|
+
|
|
18
|
+
// src/config/toml.ts
|
|
19
|
+
async function readConfig(dir) {
|
|
20
|
+
const filePath = path.join(dir, CONFIG_FILE_NAME);
|
|
21
|
+
let raw;
|
|
22
|
+
try {
|
|
23
|
+
raw = await readFile(filePath, "utf-8");
|
|
24
|
+
} catch {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Could not find ${CONFIG_FILE_NAME} in "${dir}". Run \`whatalo init\` to set up your project.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
let parsed;
|
|
30
|
+
try {
|
|
31
|
+
parsed = TOML.parse(raw);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Failed to parse ${CONFIG_FILE_NAME}: ${message}. Check for syntax errors.`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
validateRequiredFields(parsed);
|
|
39
|
+
return parsed;
|
|
40
|
+
}
|
|
41
|
+
async function writeConfig(dir, config) {
|
|
42
|
+
const filePath = path.join(dir, CONFIG_FILE_NAME);
|
|
43
|
+
const content = TOML.stringify(config);
|
|
44
|
+
await writeFile(filePath, content, "utf-8");
|
|
45
|
+
}
|
|
46
|
+
function validateRequiredFields(obj) {
|
|
47
|
+
for (const fieldPath of REQUIRED_FIELDS) {
|
|
48
|
+
const parts = fieldPath.split(".");
|
|
49
|
+
let current = obj;
|
|
50
|
+
for (const part of parts) {
|
|
51
|
+
if (current === null || current === void 0 || typeof current !== "object") {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Missing \`${fieldPath}\` in ${CONFIG_FILE_NAME}. Run \`whatalo init\` to set up your project.`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
current = current[part];
|
|
57
|
+
}
|
|
58
|
+
if (current === null || current === void 0 || current === "") {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Missing \`${fieldPath}\` in ${CONFIG_FILE_NAME}. Run \`whatalo init\` to set up your project.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/config/schema.ts
|
|
67
|
+
import { z } from "zod";
|
|
68
|
+
var pluginConfigSchema = z.object({
|
|
69
|
+
plugin: z.object({
|
|
70
|
+
name: z.string().min(1, "Plugin name cannot be empty").max(100, "Plugin name must be 100 characters or fewer"),
|
|
71
|
+
plugin_id: z.string().min(1, "plugin_id cannot be empty").regex(
|
|
72
|
+
/^[a-zA-Z0-9_-]+$/,
|
|
73
|
+
"Invalid plugin_id format. Must contain only alphanumeric characters, hyphens, or underscores."
|
|
74
|
+
),
|
|
75
|
+
slug: z.string().regex(
|
|
76
|
+
/^[a-z0-9][a-z0-9-]*[a-z0-9]$/,
|
|
77
|
+
"Slug must be lowercase alphanumeric with hyphens, cannot start or end with a hyphen."
|
|
78
|
+
)
|
|
79
|
+
}),
|
|
80
|
+
build: z.object({
|
|
81
|
+
dev_command: z.string().min(1, "dev_command cannot be empty"),
|
|
82
|
+
build_command: z.string().min(1, "build_command cannot be empty"),
|
|
83
|
+
output_dir: z.string().min(1, "output_dir cannot be empty")
|
|
84
|
+
}).optional(),
|
|
85
|
+
webhooks: z.object({
|
|
86
|
+
url: z.string().url("Webhook URL must be a valid URL").refine((u) => u.startsWith("https://"), {
|
|
87
|
+
message: "Webhook URL must use HTTPS"
|
|
88
|
+
}).optional(),
|
|
89
|
+
events: z.array(z.string()).optional()
|
|
90
|
+
}).optional(),
|
|
91
|
+
dev: z.object({
|
|
92
|
+
port: z.number().int("Port must be an integer").min(1024, "Port must be >= 1024").max(65535, "Port must be <= 65535").default(5173),
|
|
93
|
+
store: z.string().optional()
|
|
94
|
+
}).optional()
|
|
95
|
+
});
|
|
96
|
+
function validateConfig(raw) {
|
|
97
|
+
const result = pluginConfigSchema.safeParse(raw);
|
|
98
|
+
if (result.success) {
|
|
99
|
+
return { success: true, data: result.data };
|
|
100
|
+
}
|
|
101
|
+
const errors = result.error.issues.map((issue) => ({
|
|
102
|
+
path: issue.path.join("."),
|
|
103
|
+
message: issue.message
|
|
104
|
+
}));
|
|
105
|
+
return { success: false, errors };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/config/env-file.ts
|
|
109
|
+
import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
110
|
+
function parseEnvFile(content) {
|
|
111
|
+
const lines = content.split("\n");
|
|
112
|
+
return lines.map((raw) => {
|
|
113
|
+
const trimmed = raw.trim();
|
|
114
|
+
if (trimmed === "" || trimmed.startsWith("#")) {
|
|
115
|
+
return { raw };
|
|
116
|
+
}
|
|
117
|
+
const eqIndex = trimmed.indexOf("=");
|
|
118
|
+
if (eqIndex === -1) {
|
|
119
|
+
return { raw };
|
|
120
|
+
}
|
|
121
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
122
|
+
let value = trimmed.slice(eqIndex + 1).trim();
|
|
123
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
124
|
+
value = value.slice(1, -1);
|
|
125
|
+
}
|
|
126
|
+
return { raw, key, value };
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async function updateEnvFile(filePath, vars) {
|
|
130
|
+
let existingContent = "";
|
|
131
|
+
try {
|
|
132
|
+
existingContent = await readFile2(filePath, "utf-8");
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
const entries = existingContent ? parseEnvFile(existingContent) : [];
|
|
136
|
+
const updatedKeys = /* @__PURE__ */ new Set();
|
|
137
|
+
const updatedLines = entries.map((entry) => {
|
|
138
|
+
if (entry.key && entry.key in vars) {
|
|
139
|
+
updatedKeys.add(entry.key);
|
|
140
|
+
return `${entry.key}=${vars[entry.key]}`;
|
|
141
|
+
}
|
|
142
|
+
return entry.raw;
|
|
143
|
+
});
|
|
144
|
+
const newVars = Object.entries(vars).filter(
|
|
145
|
+
([key]) => !updatedKeys.has(key)
|
|
146
|
+
);
|
|
147
|
+
if (newVars.length > 0) {
|
|
148
|
+
if (updatedLines.length > 0 && updatedLines[updatedLines.length - 1] !== "") {
|
|
149
|
+
updatedLines.push("");
|
|
150
|
+
}
|
|
151
|
+
updatedLines.push("# Whatalo Plugin Variables");
|
|
152
|
+
for (const [key, value] of newVars) {
|
|
153
|
+
updatedLines.push(`${key}=${value}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const output = updatedLines.join("\n");
|
|
157
|
+
await writeFile2(filePath, output.endsWith("\n") ? output : output + "\n", "utf-8");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/config/manifest-loader.ts
|
|
161
|
+
import { build } from "esbuild";
|
|
162
|
+
import { mkdtemp, rm } from "fs/promises";
|
|
163
|
+
import { tmpdir } from "os";
|
|
164
|
+
import { pathToFileURL } from "url";
|
|
165
|
+
import path2 from "path";
|
|
166
|
+
var MANIFEST_FILE_NAME = "whatalo.app.ts";
|
|
167
|
+
async function loadManifest(dir) {
|
|
168
|
+
const entryPoint = path2.join(dir, MANIFEST_FILE_NAME);
|
|
169
|
+
let tmpDir = null;
|
|
170
|
+
try {
|
|
171
|
+
tmpDir = await mkdtemp(path2.join(tmpdir(), "whatalo-manifest-"));
|
|
172
|
+
const outfile = path2.join(tmpDir, "manifest.mjs");
|
|
173
|
+
await build({
|
|
174
|
+
entryPoints: [entryPoint],
|
|
175
|
+
bundle: true,
|
|
176
|
+
format: "esm",
|
|
177
|
+
outfile,
|
|
178
|
+
platform: "node",
|
|
179
|
+
// Silence esbuild output — errors are caught below
|
|
180
|
+
logLevel: "silent"
|
|
181
|
+
});
|
|
182
|
+
const mod = await import(pathToFileURL(outfile).href);
|
|
183
|
+
return mod.default ?? null;
|
|
184
|
+
} catch {
|
|
185
|
+
return null;
|
|
186
|
+
} finally {
|
|
187
|
+
if (tmpDir) {
|
|
188
|
+
try {
|
|
189
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
190
|
+
} catch {
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export {
|
|
196
|
+
CONFIG_FILE_NAME,
|
|
197
|
+
REQUIRED_FIELDS,
|
|
198
|
+
loadManifest,
|
|
199
|
+
parseEnvFile,
|
|
200
|
+
pluginConfigSchema,
|
|
201
|
+
readConfig,
|
|
202
|
+
updateEnvFile,
|
|
203
|
+
validateConfig,
|
|
204
|
+
writeConfig
|
|
205
|
+
};
|