@portel/photon 1.8.4 → 1.10.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 +163 -210
- package/dist/async/dedup-map.d.ts +40 -0
- package/dist/async/dedup-map.d.ts.map +1 -0
- package/dist/async/dedup-map.js +80 -0
- package/dist/async/dedup-map.js.map +1 -0
- package/dist/async/index.d.ts +11 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/index.js +11 -0
- package/dist/async/index.js.map +1 -0
- package/dist/async/loading-gate.d.ts +27 -0
- package/dist/async/loading-gate.d.ts.map +1 -0
- package/dist/async/loading-gate.js +48 -0
- package/dist/async/loading-gate.js.map +1 -0
- package/dist/async/with-timeout.d.ts +6 -0
- package/dist/async/with-timeout.d.ts.map +1 -0
- package/dist/async/with-timeout.js +17 -0
- package/dist/async/with-timeout.js.map +1 -0
- package/dist/auto-ui/beam/class-metadata.d.ts +52 -0
- package/dist/auto-ui/beam/class-metadata.d.ts.map +1 -0
- package/dist/auto-ui/beam/class-metadata.js +133 -0
- package/dist/auto-ui/beam/class-metadata.js.map +1 -0
- package/dist/auto-ui/beam/config.d.ts +13 -0
- package/dist/auto-ui/beam/config.d.ts.map +1 -0
- package/dist/auto-ui/beam/config.js +52 -0
- package/dist/auto-ui/beam/config.js.map +1 -0
- package/dist/auto-ui/beam/external-mcp.d.ts +37 -0
- package/dist/auto-ui/beam/external-mcp.d.ts.map +1 -0
- package/dist/auto-ui/beam/external-mcp.js +311 -0
- package/dist/auto-ui/beam/external-mcp.js.map +1 -0
- package/dist/auto-ui/beam/photon-management.d.ts +51 -0
- package/dist/auto-ui/beam/photon-management.d.ts.map +1 -0
- package/dist/auto-ui/beam/photon-management.js +310 -0
- package/dist/auto-ui/beam/photon-management.js.map +1 -0
- package/dist/auto-ui/beam/routes/api-browse.d.ts +17 -0
- package/dist/auto-ui/beam/routes/api-browse.d.ts.map +1 -0
- package/dist/auto-ui/beam/routes/api-browse.js +531 -0
- package/dist/auto-ui/beam/routes/api-browse.js.map +1 -0
- package/dist/auto-ui/beam/routes/api-config.d.ts +9 -0
- package/dist/auto-ui/beam/routes/api-config.d.ts.map +1 -0
- package/dist/auto-ui/beam/routes/api-config.js +494 -0
- package/dist/auto-ui/beam/routes/api-config.js.map +1 -0
- package/dist/auto-ui/beam/routes/api-marketplace.d.ts +8 -0
- package/dist/auto-ui/beam/routes/api-marketplace.d.ts.map +1 -0
- package/dist/auto-ui/beam/routes/api-marketplace.js +490 -0
- package/dist/auto-ui/beam/routes/api-marketplace.js.map +1 -0
- package/dist/auto-ui/beam/startup.d.ts +41 -0
- package/dist/auto-ui/beam/startup.d.ts.map +1 -0
- package/dist/auto-ui/beam/startup.js +98 -0
- package/dist/auto-ui/beam/startup.js.map +1 -0
- package/dist/auto-ui/beam/subscription.d.ts +35 -0
- package/dist/auto-ui/beam/subscription.d.ts.map +1 -0
- package/dist/auto-ui/beam/subscription.js +151 -0
- package/dist/auto-ui/beam/subscription.js.map +1 -0
- package/dist/auto-ui/beam/types.d.ts +103 -0
- package/dist/auto-ui/beam/types.d.ts.map +1 -0
- package/dist/auto-ui/beam/types.js +8 -0
- package/dist/auto-ui/beam/types.js.map +1 -0
- package/dist/auto-ui/beam.d.ts +2 -0
- package/dist/auto-ui/beam.d.ts.map +1 -1
- package/dist/auto-ui/beam.js +731 -2519
- package/dist/auto-ui/beam.js.map +1 -1
- package/dist/auto-ui/bridge/index.d.ts.map +1 -1
- package/dist/auto-ui/bridge/index.js +10 -2
- package/dist/auto-ui/bridge/index.js.map +1 -1
- package/dist/auto-ui/components/card.d.ts.map +1 -1
- package/dist/auto-ui/components/card.js +3 -1
- package/dist/auto-ui/components/card.js.map +1 -1
- package/dist/auto-ui/components/progress.d.ts.map +1 -1
- package/dist/auto-ui/components/progress.js.map +1 -1
- package/dist/auto-ui/daemon-tools.d.ts +1 -1
- package/dist/auto-ui/daemon-tools.d.ts.map +1 -1
- package/dist/auto-ui/daemon-tools.js +4 -3
- package/dist/auto-ui/daemon-tools.js.map +1 -1
- package/dist/auto-ui/photon-bridge.d.ts +6 -2
- package/dist/auto-ui/photon-bridge.d.ts.map +1 -1
- package/dist/auto-ui/photon-bridge.js +20 -8
- package/dist/auto-ui/photon-bridge.js.map +1 -1
- package/dist/auto-ui/platform-compat.d.ts.map +1 -1
- package/dist/auto-ui/platform-compat.js +4 -0
- package/dist/auto-ui/platform-compat.js.map +1 -1
- package/dist/auto-ui/streamable-http-transport.d.ts +4 -2
- package/dist/auto-ui/streamable-http-transport.d.ts.map +1 -1
- package/dist/auto-ui/streamable-http-transport.js +120 -30
- package/dist/auto-ui/streamable-http-transport.js.map +1 -1
- package/dist/auto-ui/types.d.ts +4 -2
- package/dist/auto-ui/types.d.ts.map +1 -1
- package/dist/auto-ui/types.js +3 -0
- package/dist/auto-ui/types.js.map +1 -1
- package/dist/beam.bundle.js +9218 -4539
- package/dist/beam.bundle.js.map +4 -4
- package/dist/cli/commands/alias.d.ts +14 -0
- package/dist/cli/commands/alias.d.ts.map +1 -0
- package/dist/cli/commands/alias.js +41 -0
- package/dist/cli/commands/alias.js.map +1 -0
- package/dist/cli/commands/audit.d.ts +9 -0
- package/dist/cli/commands/audit.d.ts.map +1 -0
- package/dist/cli/commands/audit.js +377 -0
- package/dist/cli/commands/audit.js.map +1 -0
- package/dist/cli/commands/beam.d.ts +20 -0
- package/dist/cli/commands/beam.d.ts.map +1 -0
- package/dist/cli/commands/beam.js +256 -0
- package/dist/cli/commands/beam.js.map +1 -0
- package/dist/cli/commands/config.d.ts +14 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +165 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/daemon.d.ts +11 -0
- package/dist/cli/commands/daemon.d.ts.map +1 -0
- package/dist/cli/commands/daemon.js +108 -0
- package/dist/cli/commands/daemon.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +14 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +257 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/host.d.ts +11 -0
- package/dist/cli/commands/host.d.ts.map +1 -0
- package/dist/cli/commands/host.js +96 -0
- package/dist/cli/commands/host.js.map +1 -0
- package/dist/cli/commands/info.d.ts +1 -1
- package/dist/cli/commands/info.d.ts.map +1 -1
- package/dist/cli/commands/info.js +16 -15
- package/dist/cli/commands/info.js.map +1 -1
- package/dist/cli/commands/init.d.ts +20 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +774 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/maker.d.ts +12 -0
- package/dist/cli/commands/maker.d.ts.map +1 -0
- package/dist/cli/commands/maker.js +605 -0
- package/dist/cli/commands/maker.js.map +1 -0
- package/dist/cli/commands/mcp.d.ts +27 -0
- package/dist/cli/commands/mcp.d.ts.map +1 -0
- package/dist/cli/commands/mcp.js +390 -0
- package/dist/cli/commands/mcp.js.map +1 -0
- package/dist/cli/commands/package-app.d.ts +1 -1
- package/dist/cli/commands/package-app.d.ts.map +1 -1
- package/dist/cli/commands/package-app.js +5 -4
- package/dist/cli/commands/package-app.js.map +1 -1
- package/dist/cli/commands/package.d.ts +1 -1
- package/dist/cli/commands/package.d.ts.map +1 -1
- package/dist/cli/commands/package.js +134 -32
- package/dist/cli/commands/package.js.map +1 -1
- package/dist/cli/commands/run.d.ts +34 -0
- package/dist/cli/commands/run.d.ts.map +1 -0
- package/dist/cli/commands/run.js +334 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/commands/search.d.ts +11 -0
- package/dist/cli/commands/search.d.ts.map +1 -0
- package/dist/cli/commands/search.js +60 -0
- package/dist/cli/commands/search.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +11 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +138 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/test.d.ts +14 -0
- package/dist/cli/commands/test.d.ts.map +1 -0
- package/dist/cli/commands/test.js +51 -0
- package/dist/cli/commands/test.js.map +1 -0
- package/dist/cli/commands/update.d.ts +11 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +72 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/index.d.ts +14 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +139 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli-alias.js +2 -2
- package/dist/cli-alias.js.map +1 -1
- package/dist/cli.d.ts +3 -16
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +4 -2724
- package/dist/cli.js.map +1 -1
- package/dist/context-store.d.ts +13 -12
- package/dist/context-store.d.ts.map +1 -1
- package/dist/context-store.js +47 -23
- package/dist/context-store.js.map +1 -1
- package/dist/context.d.ts +35 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +38 -0
- package/dist/context.js.map +1 -0
- package/dist/daemon/client.d.ts +25 -13
- package/dist/daemon/client.d.ts.map +1 -1
- package/dist/daemon/client.js +183 -135
- package/dist/daemon/client.js.map +1 -1
- package/dist/daemon/manager.d.ts +58 -26
- package/dist/daemon/manager.d.ts.map +1 -1
- package/dist/daemon/manager.js +348 -157
- package/dist/daemon/manager.js.map +1 -1
- package/dist/daemon/protocol.d.ts +9 -3
- package/dist/daemon/protocol.d.ts.map +1 -1
- package/dist/daemon/protocol.js +2 -0
- package/dist/daemon/protocol.js.map +1 -1
- package/dist/daemon/server.js +850 -200
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/session-manager.d.ts +16 -2
- package/dist/daemon/session-manager.d.ts.map +1 -1
- package/dist/daemon/session-manager.js +65 -7
- package/dist/daemon/session-manager.js.map +1 -1
- package/dist/daemon/state-machine.d.ts +22 -0
- package/dist/daemon/state-machine.d.ts.map +1 -0
- package/dist/daemon/state-machine.js +48 -0
- package/dist/daemon/state-machine.js.map +1 -0
- package/dist/deploy/cloudflare.d.ts.map +1 -1
- package/dist/deploy/cloudflare.js +5 -5
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/loader.d.ts +65 -7
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +587 -63
- package/dist/loader.js.map +1 -1
- package/dist/marketplace-manager.d.ts +87 -13
- package/dist/marketplace-manager.d.ts.map +1 -1
- package/dist/marketplace-manager.js +476 -30
- package/dist/marketplace-manager.js.map +1 -1
- package/dist/path-resolver.d.ts +3 -1
- package/dist/path-resolver.d.ts.map +1 -1
- package/dist/path-resolver.js +4 -3
- package/dist/path-resolver.js.map +1 -1
- package/dist/photon-cli-runner.d.ts +1 -1
- package/dist/photon-cli-runner.d.ts.map +1 -1
- package/dist/photon-cli-runner.js +34 -44
- package/dist/photon-cli-runner.js.map +1 -1
- package/dist/photon-doc-extractor.d.ts +1 -0
- package/dist/photon-doc-extractor.d.ts.map +1 -1
- package/dist/photon-doc-extractor.js +62 -19
- package/dist/photon-doc-extractor.js.map +1 -1
- package/dist/photons/maker.photon.d.ts.map +1 -1
- package/dist/photons/maker.photon.js +4 -4
- package/dist/photons/maker.photon.js.map +1 -1
- package/dist/photons/maker.photon.ts +4 -3
- package/dist/photons/marketplace.photon.d.ts.map +1 -1
- package/dist/photons/marketplace.photon.js +10 -27
- package/dist/photons/marketplace.photon.js.map +1 -1
- package/dist/photons/marketplace.photon.ts +14 -33
- package/dist/photons/tunnel.photon.d.ts.map +1 -1
- package/dist/photons/tunnel.photon.js +4 -8
- package/dist/photons/tunnel.photon.js.map +1 -1
- package/dist/photons/tunnel.photon.ts +4 -7
- package/dist/serv/session/kv-store.d.ts +1 -1
- package/dist/serv/session/kv-store.d.ts.map +1 -1
- package/dist/serv/session/store.d.ts.map +1 -1
- package/dist/serv/session/store.js +16 -14
- package/dist/serv/session/store.js.map +1 -1
- package/dist/serv/vault/token-vault.js +1 -1
- package/dist/serv/vault/token-vault.js.map +1 -1
- package/dist/server.d.ts +34 -12
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +364 -313
- package/dist/server.js.map +1 -1
- package/dist/shared/audit.d.ts +30 -0
- package/dist/shared/audit.d.ts.map +1 -0
- package/dist/shared/audit.js +89 -0
- package/dist/shared/audit.js.map +1 -0
- package/dist/shared/cli-sections.d.ts +0 -4
- package/dist/shared/cli-sections.d.ts.map +1 -1
- package/dist/shared/cli-sections.js +0 -6
- package/dist/shared/cli-sections.js.map +1 -1
- package/dist/shared/cli-utils.d.ts +2 -56
- package/dist/shared/cli-utils.d.ts.map +1 -1
- package/dist/shared/cli-utils.js +1 -87
- package/dist/shared/cli-utils.js.map +1 -1
- package/dist/shared/error-handler.d.ts +6 -72
- package/dist/shared/error-handler.d.ts.map +1 -1
- package/dist/shared/error-handler.js +22 -213
- package/dist/shared/error-handler.js.map +1 -1
- package/dist/shared/security.d.ts +0 -9
- package/dist/shared/security.d.ts.map +1 -1
- package/dist/shared/security.js +0 -30
- package/dist/shared/security.js.map +1 -1
- package/dist/shared-utils.d.ts +0 -26
- package/dist/shared-utils.d.ts.map +1 -1
- package/dist/shared-utils.js +0 -44
- package/dist/shared-utils.js.map +1 -1
- package/dist/shell-completions.d.ts +1 -1
- package/dist/shell-completions.d.ts.map +1 -1
- package/dist/shell-completions.js +5 -5
- package/dist/shell-completions.js.map +1 -1
- package/dist/template-manager.d.ts.map +1 -1
- package/dist/template-manager.js +14 -1
- package/dist/template-manager.js.map +1 -1
- package/dist/test-runner.d.ts +0 -12
- package/dist/test-runner.d.ts.map +1 -1
- package/dist/test-runner.js +4 -39
- package/dist/test-runner.js.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +2 -2
- package/dist/testing.js.map +1 -1
- package/dist/version-checker.d.ts +4 -4
- package/dist/version-checker.d.ts.map +1 -1
- package/dist/version-checker.js +33 -4
- package/dist/version-checker.js.map +1 -1
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +14 -12
- package/dist/watcher.js.map +1 -1
- package/package.json +24 -17
package/dist/shared/cli-utils.js
CHANGED
|
@@ -1,61 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CLI Utilities
|
|
3
3
|
*
|
|
4
|
-
* Shared
|
|
4
|
+
* Shared readline helpers for CLI commands
|
|
5
5
|
*/
|
|
6
|
-
import { DEFAULT_PHOTON_DIR } from '@portel/photon-core';
|
|
7
|
-
/**
|
|
8
|
-
* Get global options from a command, handling parent chain
|
|
9
|
-
*
|
|
10
|
-
* Commander stores global options on the program root, so we need
|
|
11
|
-
* to traverse up the parent chain to find them.
|
|
12
|
-
*/
|
|
13
|
-
export function getGlobalOptions(command) {
|
|
14
|
-
// Traverse up to find the root program
|
|
15
|
-
let current = command;
|
|
16
|
-
while (current?.parent) {
|
|
17
|
-
current = current.parent;
|
|
18
|
-
}
|
|
19
|
-
const opts = current?.opts() || {};
|
|
20
|
-
return {
|
|
21
|
-
dir: opts.dir || DEFAULT_PHOTON_DIR,
|
|
22
|
-
logLevel: opts.logLevel,
|
|
23
|
-
jsonLogs: opts.jsonLogs,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get the working directory from command options
|
|
28
|
-
*/
|
|
29
|
-
export function getWorkingDir(command) {
|
|
30
|
-
return getGlobalOptions(command).dir;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Check if we're in JSON output mode
|
|
34
|
-
*/
|
|
35
|
-
export function isJsonMode(command) {
|
|
36
|
-
return getGlobalOptions(command).jsonLogs === true;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Check if stdout is a TTY (for formatting decisions)
|
|
40
|
-
*/
|
|
41
|
-
export function isTTY() {
|
|
42
|
-
return process.stdout.isTTY === true;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Format output based on mode (JSON vs human-readable)
|
|
46
|
-
*/
|
|
47
|
-
export function formatOutput(data, command) {
|
|
48
|
-
if (command && isJsonMode(command)) {
|
|
49
|
-
return JSON.stringify(data, null, 2);
|
|
50
|
-
}
|
|
51
|
-
if (typeof data === 'string') {
|
|
52
|
-
return data;
|
|
53
|
-
}
|
|
54
|
-
return JSON.stringify(data, null, 2);
|
|
55
|
-
}
|
|
56
|
-
// ══════════════════════════════════════════════════════════════════════════════
|
|
57
|
-
// READLINE UTILITIES
|
|
58
|
-
// ══════════════════════════════════════════════════════════════════════════════
|
|
59
6
|
import * as readline from 'readline';
|
|
60
7
|
/**
|
|
61
8
|
* Create a readline interface for CLI prompts
|
|
@@ -69,8 +16,6 @@ export function createReadline() {
|
|
|
69
16
|
}
|
|
70
17
|
/**
|
|
71
18
|
* Prompt user for text input
|
|
72
|
-
* @param prompt - The prompt to display
|
|
73
|
-
* @returns User's input
|
|
74
19
|
*/
|
|
75
20
|
export function promptText(prompt) {
|
|
76
21
|
const rl = createReadline();
|
|
@@ -83,9 +28,6 @@ export function promptText(prompt) {
|
|
|
83
28
|
}
|
|
84
29
|
/**
|
|
85
30
|
* Prompt user for confirmation (yes/no)
|
|
86
|
-
* @param message - The message to display
|
|
87
|
-
* @param defaultYes - Whether default is yes (true) or no (false)
|
|
88
|
-
* @returns true for yes, false for no
|
|
89
31
|
*/
|
|
90
32
|
export function promptConfirm(message, defaultYes = false) {
|
|
91
33
|
const rl = createReadline();
|
|
@@ -105,16 +47,9 @@ export function promptConfirm(message, defaultYes = false) {
|
|
|
105
47
|
}
|
|
106
48
|
/**
|
|
107
49
|
* Prompt user to select from numbered options
|
|
108
|
-
* @param prompt - The prompt to display
|
|
109
|
-
* @param optionCount - Number of options available
|
|
110
|
-
* @param options - Configuration options
|
|
111
|
-
* @param options.allowCancel - Whether empty input cancels (returns null). Default: true
|
|
112
|
-
* @param options.defaultChoice - Default choice (1-based) to use on empty input
|
|
113
|
-
* @returns Selected option number (1-based) or null if cancelled
|
|
114
50
|
*/
|
|
115
51
|
export function promptChoice(prompt, optionCount, options = true) {
|
|
116
52
|
const rl = createReadline();
|
|
117
|
-
// Handle legacy boolean parameter
|
|
118
53
|
const opts = typeof options === 'boolean' ? { allowCancel: options } : options;
|
|
119
54
|
const { allowCancel = true, defaultChoice } = opts;
|
|
120
55
|
return new Promise((resolve) => {
|
|
@@ -150,25 +85,4 @@ export function promptChoice(prompt, optionCount, options = true) {
|
|
|
150
85
|
ask();
|
|
151
86
|
});
|
|
152
87
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Prompt user to wait and press Enter
|
|
155
|
-
* @param message - Optional message (defaults to "Press Enter to continue")
|
|
156
|
-
* @param allowCancel - Whether typing "cancel" aborts
|
|
157
|
-
* @returns true to continue, false if cancelled
|
|
158
|
-
*/
|
|
159
|
-
export function promptWait(message = 'Press Enter to continue', allowCancel = true) {
|
|
160
|
-
const rl = createReadline();
|
|
161
|
-
const suffix = allowCancel ? ' (or type "cancel" to abort)' : '';
|
|
162
|
-
return new Promise((resolve) => {
|
|
163
|
-
rl.question(`${message}${suffix}: `, (answer) => {
|
|
164
|
-
rl.close();
|
|
165
|
-
if (allowCancel && answer.toLowerCase().trim() === 'cancel') {
|
|
166
|
-
resolve(false);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
resolve(true);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
88
|
//# sourceMappingURL=cli-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-utils.js","sourceRoot":"","sources":["../../src/shared/cli-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"cli-utils.js","sourceRoot":"","sources":["../../src/shared/cli-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,QAAQ,CAAC,eAAe,CAAC;QAC9B,KAAK,EAAE,OAAO,CAAC,KAAK;Q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,GAAG,EAAE,CAAC;gBACR,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QACF,GAAG,EAAE,CAAC;IACR,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Centralized error handling utilities
|
|
3
|
-
* Provides consistent error formatting, user-friendly messages, and structured error types
|
|
4
3
|
*/
|
|
5
4
|
import { Logger } from './logger.js';
|
|
6
5
|
import { PhotonError, ValidationError } from '@portel/photon-core';
|
|
@@ -29,68 +28,30 @@ export declare const ExitCode: {
|
|
|
29
28
|
/** Operation was cancelled by user */
|
|
30
29
|
readonly CANCELLED: 130;
|
|
31
30
|
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Get appropriate exit code for an error
|
|
35
|
-
*/
|
|
36
|
-
export declare function getExitCode(error: unknown): ExitCodeType;
|
|
37
|
-
export declare class FileSystemError extends PhotonError {
|
|
38
|
-
constructor(message: string, details?: Record<string, unknown>, suggestion?: string);
|
|
39
|
-
}
|
|
40
|
-
export declare class NetworkError extends PhotonError {
|
|
41
|
-
constructor(message: string, details?: Record<string, unknown>, suggestion?: string);
|
|
42
|
-
}
|
|
43
|
-
export declare class ConfigurationError extends PhotonError {
|
|
44
|
-
constructor(message: string, details?: Record<string, unknown>, suggestion?: string);
|
|
45
|
-
}
|
|
31
|
+
type ExitCodeType = (typeof ExitCode)[keyof typeof ExitCode];
|
|
46
32
|
/**
|
|
47
33
|
* Safe error message extraction
|
|
48
34
|
*/
|
|
49
35
|
export declare function getErrorMessage(error: unknown): string;
|
|
50
|
-
/**
|
|
51
|
-
* Safe error stack extraction
|
|
52
|
-
*/
|
|
53
|
-
export declare function getErrorStack(error: unknown): string | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* Check if error is a specific type
|
|
56
|
-
*/
|
|
57
|
-
export declare function isErrorCode(error: unknown, code: string): boolean;
|
|
58
36
|
/**
|
|
59
37
|
* Check if error is a Node.js file system error
|
|
60
38
|
*/
|
|
61
39
|
export declare function isNodeError(error: unknown, code?: string): error is NodeJS.ErrnoException;
|
|
62
|
-
/**
|
|
63
|
-
* Format error for user display
|
|
64
|
-
*/
|
|
65
|
-
export declare function formatErrorMessage(error: unknown, options?: {
|
|
66
|
-
includeStack?: boolean;
|
|
67
|
-
context?: string;
|
|
68
|
-
}): string;
|
|
69
|
-
/**
|
|
70
|
-
* Wrap Node.js ENOENT errors with helpful context
|
|
71
|
-
*/
|
|
72
|
-
export declare function handleFileNotFound(path: string, context?: string): FileSystemError;
|
|
73
|
-
/**
|
|
74
|
-
* Wrap Node.js EACCES errors with helpful context
|
|
75
|
-
*/
|
|
76
|
-
export declare function handlePermissionDenied(path: string, context?: string): FileSystemError;
|
|
77
40
|
/**
|
|
78
41
|
* Convert unknown error to PhotonError
|
|
79
42
|
*/
|
|
80
43
|
export declare function wrapError(error: unknown, context?: string, suggestion?: string): PhotonError;
|
|
81
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Centralized error handler for CLI commands
|
|
46
|
+
*/
|
|
47
|
+
export declare function handleError(error: unknown, options?: {
|
|
82
48
|
logger?: Logger;
|
|
83
49
|
exitOnError?: boolean;
|
|
84
50
|
exitCode?: ExitCodeType;
|
|
85
51
|
showStack?: boolean;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Centralized error handler
|
|
89
|
-
*/
|
|
90
|
-
export declare function handleError(error: unknown, options?: ErrorHandlerOptions): never | void;
|
|
52
|
+
}): never | void;
|
|
91
53
|
/**
|
|
92
54
|
* Print error to stderr and exit with appropriate code
|
|
93
|
-
* Use this for CLI commands to ensure consistent error handling
|
|
94
55
|
*/
|
|
95
56
|
export declare function exitWithError(message: string, options?: {
|
|
96
57
|
exitCode?: ExitCodeType;
|
|
@@ -98,31 +59,4 @@ export declare function exitWithError(message: string, options?: {
|
|
|
98
59
|
searchedIn?: string;
|
|
99
60
|
logger?: Logger;
|
|
100
61
|
}): never;
|
|
101
|
-
/**
|
|
102
|
-
* Exit successfully with optional message
|
|
103
|
-
*/
|
|
104
|
-
export declare function exitSuccess(message?: string, logger?: Logger): never;
|
|
105
|
-
/**
|
|
106
|
-
* Async error wrapper for cleaner try-catch
|
|
107
|
-
*/
|
|
108
|
-
export declare function tryAsync<T>(fn: () => Promise<T>, context?: string, suggestion?: string): Promise<T>;
|
|
109
|
-
/**
|
|
110
|
-
* Sync error wrapper for cleaner try-catch
|
|
111
|
-
*/
|
|
112
|
-
export declare function trySync<T>(fn: () => T, context?: string, suggestion?: string): T;
|
|
113
|
-
/**
|
|
114
|
-
* Retry an async operation with exponential backoff
|
|
115
|
-
*/
|
|
116
|
-
export declare function retry<T>(fn: () => Promise<T>, options?: {
|
|
117
|
-
maxAttempts?: number;
|
|
118
|
-
initialDelay?: number;
|
|
119
|
-
maxDelay?: number;
|
|
120
|
-
backoffFactor?: number;
|
|
121
|
-
context?: string;
|
|
122
|
-
retryIf?: (error: unknown) => boolean;
|
|
123
|
-
}): Promise<T>;
|
|
124
|
-
/**
|
|
125
|
-
* Check if an error is retryable (network/transient errors)
|
|
126
|
-
*/
|
|
127
|
-
export declare function isRetryableError(error: unknown): boolean;
|
|
128
62
|
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/shared/error-handler.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/shared/error-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;AAMxC;;;GAGG;AACH,eAAO,MAAM,QAAQ;IACnB,qCAAqC;;IAErC,gCAAgC;;IAEhC,6CAA6C;;IAE7C,sDAAsD;;IAEtD,iCAAiC;;IAEjC,kCAAkC;;IAElC,iDAAiD;;IAEjD,wBAAwB;;IAExB,sCAAsC;;CAE9B,CAAC;AAEX,KAAK,YAAY,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAM7D;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAWtD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAAC,cAAc,CAOzF;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,WAAW,CAkC5F;AAMD;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;CAChB,GACL,KAAK,GAAG,IAAI,CAsCd;AAMD;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GACA,KAAK,CAsBP"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Centralized error handling utilities
|
|
3
|
-
* Provides consistent error formatting, user-friendly messages, and structured error types
|
|
4
3
|
*/
|
|
5
4
|
import { PhotonError, ValidationError } from '@portel/photon-core';
|
|
6
5
|
// Re-export base error classes from photon-core
|
|
@@ -32,58 +31,6 @@ export const ExitCode = {
|
|
|
32
31
|
/** Operation was cancelled by user */
|
|
33
32
|
CANCELLED: 130,
|
|
34
33
|
};
|
|
35
|
-
/**
|
|
36
|
-
* Get appropriate exit code for an error
|
|
37
|
-
*/
|
|
38
|
-
export function getExitCode(error) {
|
|
39
|
-
if (error instanceof ValidationError) {
|
|
40
|
-
return ExitCode.VALIDATION_ERROR;
|
|
41
|
-
}
|
|
42
|
-
if (error instanceof ConfigurationError) {
|
|
43
|
-
return ExitCode.CONFIG_ERROR;
|
|
44
|
-
}
|
|
45
|
-
if (error instanceof NetworkError) {
|
|
46
|
-
return ExitCode.NETWORK_ERROR;
|
|
47
|
-
}
|
|
48
|
-
if (error instanceof FileSystemError) {
|
|
49
|
-
const details = error.details;
|
|
50
|
-
if (details?.code === 'ENOENT') {
|
|
51
|
-
return ExitCode.NOT_FOUND;
|
|
52
|
-
}
|
|
53
|
-
if (details?.code === 'EACCES' || details?.code === 'EPERM') {
|
|
54
|
-
return ExitCode.PERMISSION_DENIED;
|
|
55
|
-
}
|
|
56
|
-
return ExitCode.ERROR;
|
|
57
|
-
}
|
|
58
|
-
if (isNodeError(error)) {
|
|
59
|
-
if (error.code === 'ENOENT')
|
|
60
|
-
return ExitCode.NOT_FOUND;
|
|
61
|
-
if (error.code === 'EACCES' || error.code === 'EPERM')
|
|
62
|
-
return ExitCode.PERMISSION_DENIED;
|
|
63
|
-
}
|
|
64
|
-
return ExitCode.ERROR;
|
|
65
|
-
}
|
|
66
|
-
// ══════════════════════════════════════════════════════════════════════════════
|
|
67
|
-
// ERROR TYPES (extended, specific to photon CLI)
|
|
68
|
-
// ══════════════════════════════════════════════════════════════════════════════
|
|
69
|
-
export class FileSystemError extends PhotonError {
|
|
70
|
-
constructor(message, details, suggestion) {
|
|
71
|
-
super(message, 'FILE_SYSTEM_ERROR', details, suggestion);
|
|
72
|
-
this.name = 'FileSystemError';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export class NetworkError extends PhotonError {
|
|
76
|
-
constructor(message, details, suggestion) {
|
|
77
|
-
super(message, 'NETWORK_ERROR', details, suggestion);
|
|
78
|
-
this.name = 'NetworkError';
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
export class ConfigurationError extends PhotonError {
|
|
82
|
-
constructor(message, details, suggestion) {
|
|
83
|
-
super(message, 'CONFIGURATION_ERROR', details, suggestion);
|
|
84
|
-
this.name = 'ConfigurationError';
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
34
|
// ══════════════════════════════════════════════════════════════════════════════
|
|
88
35
|
// ERROR UTILITIES
|
|
89
36
|
// ══════════════════════════════════════════════════════════════════════════════
|
|
@@ -102,21 +49,6 @@ export function getErrorMessage(error) {
|
|
|
102
49
|
}
|
|
103
50
|
return 'Unknown error';
|
|
104
51
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Safe error stack extraction
|
|
107
|
-
*/
|
|
108
|
-
export function getErrorStack(error) {
|
|
109
|
-
if (error instanceof Error && error.stack) {
|
|
110
|
-
return error.stack;
|
|
111
|
-
}
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Check if error is a specific type
|
|
116
|
-
*/
|
|
117
|
-
export function isErrorCode(error, code) {
|
|
118
|
-
return error instanceof PhotonError && error.code === code;
|
|
119
|
-
}
|
|
120
52
|
/**
|
|
121
53
|
* Check if error is a Node.js file system error
|
|
122
54
|
*/
|
|
@@ -129,43 +61,6 @@ export function isNodeError(error, code) {
|
|
|
129
61
|
}
|
|
130
62
|
return nodeError.code !== undefined;
|
|
131
63
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Format error for user display
|
|
134
|
-
*/
|
|
135
|
-
export function formatErrorMessage(error, options) {
|
|
136
|
-
const message = getErrorMessage(error);
|
|
137
|
-
const parts = [];
|
|
138
|
-
if (options?.context) {
|
|
139
|
-
parts.push(`${options.context}:`);
|
|
140
|
-
}
|
|
141
|
-
parts.push(message);
|
|
142
|
-
if (error instanceof PhotonError && error.suggestion) {
|
|
143
|
-
parts.push(`\nSuggestion: ${error.suggestion}`);
|
|
144
|
-
}
|
|
145
|
-
if (options?.includeStack) {
|
|
146
|
-
const stack = getErrorStack(error);
|
|
147
|
-
if (stack) {
|
|
148
|
-
parts.push(`\nStack trace:\n${stack}`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return parts.join(' ');
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Wrap Node.js ENOENT errors with helpful context
|
|
155
|
-
*/
|
|
156
|
-
export function handleFileNotFound(path, context) {
|
|
157
|
-
const message = context ? `File not found: ${path} (${context})` : `File not found: ${path}`;
|
|
158
|
-
return new FileSystemError(message, { path }, 'Check that the file exists and you have read permissions');
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Wrap Node.js EACCES errors with helpful context
|
|
162
|
-
*/
|
|
163
|
-
export function handlePermissionDenied(path, context) {
|
|
164
|
-
const message = context
|
|
165
|
-
? `Permission denied: ${path} (${context})`
|
|
166
|
-
: `Permission denied: ${path}`;
|
|
167
|
-
return new FileSystemError(message, { path }, 'Check file permissions and ensure you have access rights');
|
|
168
|
-
}
|
|
169
64
|
/**
|
|
170
65
|
* Convert unknown error to PhotonError
|
|
171
66
|
*/
|
|
@@ -174,34 +69,43 @@ export function wrapError(error, context, suggestion) {
|
|
|
174
69
|
return error;
|
|
175
70
|
}
|
|
176
71
|
const message = context ? `${context}: ${getErrorMessage(error)}` : getErrorMessage(error);
|
|
177
|
-
// Handle Node.js errors
|
|
72
|
+
// Handle Node.js errors with helpful context
|
|
178
73
|
if (isNodeError(error)) {
|
|
179
74
|
if (error.code === 'ENOENT' && error.path) {
|
|
180
|
-
return
|
|
75
|
+
return new PhotonError(`File not found: ${error.path}${context ? ` (${context})` : ''}`, 'FILE_SYSTEM_ERROR', { path: error.path }, 'Check that the file exists and you have read permissions');
|
|
181
76
|
}
|
|
182
77
|
if (error.code === 'EACCES' && error.path) {
|
|
183
|
-
return
|
|
78
|
+
return new PhotonError(`Permission denied: ${error.path}${context ? ` (${context})` : ''}`, 'FILE_SYSTEM_ERROR', { path: error.path }, 'Check file permissions and ensure you have access rights');
|
|
184
79
|
}
|
|
185
|
-
return new
|
|
80
|
+
return new PhotonError(message, 'FILE_SYSTEM_ERROR', { code: error.code, path: error.path }, suggestion);
|
|
186
81
|
}
|
|
187
82
|
return new PhotonError(message, 'UNKNOWN_ERROR', undefined, suggestion);
|
|
188
83
|
}
|
|
84
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
85
|
+
// ERROR HANDLER
|
|
86
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
189
87
|
/**
|
|
190
|
-
* Centralized error handler
|
|
88
|
+
* Centralized error handler for CLI commands
|
|
191
89
|
*/
|
|
192
90
|
export function handleError(error, options = {}) {
|
|
193
91
|
const { logger, exitOnError = false, exitCode, showStack = process.env.DEBUG === 'true', } = options;
|
|
194
|
-
const message =
|
|
195
|
-
|
|
196
|
-
|
|
92
|
+
const message = getErrorMessage(error);
|
|
93
|
+
const suggestion = error instanceof PhotonError ? error.suggestion : undefined;
|
|
94
|
+
const stack = error instanceof Error ? error.stack : undefined;
|
|
95
|
+
const parts = [message];
|
|
96
|
+
if (suggestion)
|
|
97
|
+
parts.push(`\nSuggestion: ${suggestion}`);
|
|
98
|
+
if (showStack && stack)
|
|
99
|
+
parts.push(`\nStack trace:\n${stack}`);
|
|
100
|
+
const formatted = parts.join(' ');
|
|
197
101
|
if (logger) {
|
|
198
|
-
logger.error(
|
|
199
|
-
if (showStack &&
|
|
200
|
-
logger.debug(
|
|
102
|
+
logger.error(formatted);
|
|
103
|
+
if (showStack && stack) {
|
|
104
|
+
logger.debug(stack);
|
|
201
105
|
}
|
|
202
106
|
}
|
|
203
107
|
else {
|
|
204
|
-
console.error(`❌ ${
|
|
108
|
+
console.error(`❌ ${formatted}`);
|
|
205
109
|
}
|
|
206
110
|
if (error instanceof PhotonError && error.details) {
|
|
207
111
|
if (logger) {
|
|
@@ -212,8 +116,7 @@ export function handleError(error, options = {}) {
|
|
|
212
116
|
}
|
|
213
117
|
}
|
|
214
118
|
if (exitOnError) {
|
|
215
|
-
|
|
216
|
-
const code = exitCode ?? getExitCode(error);
|
|
119
|
+
const code = exitCode ?? ExitCode.ERROR;
|
|
217
120
|
process.exit(code);
|
|
218
121
|
}
|
|
219
122
|
}
|
|
@@ -222,7 +125,6 @@ export function handleError(error, options = {}) {
|
|
|
222
125
|
// ══════════════════════════════════════════════════════════════════════════════
|
|
223
126
|
/**
|
|
224
127
|
* Print error to stderr and exit with appropriate code
|
|
225
|
-
* Use this for CLI commands to ensure consistent error handling
|
|
226
128
|
*/
|
|
227
129
|
export function exitWithError(message, options) {
|
|
228
130
|
const { exitCode = ExitCode.ERROR, suggestion, searchedIn, logger } = options || {};
|
|
@@ -246,97 +148,4 @@ export function exitWithError(message, options) {
|
|
|
246
148
|
}
|
|
247
149
|
process.exit(exitCode);
|
|
248
150
|
}
|
|
249
|
-
/**
|
|
250
|
-
* Exit successfully with optional message
|
|
251
|
-
*/
|
|
252
|
-
export function exitSuccess(message, logger) {
|
|
253
|
-
if (message) {
|
|
254
|
-
if (logger) {
|
|
255
|
-
logger.info(message);
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
console.error(`✓ ${message}`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
process.exit(ExitCode.SUCCESS);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Async error wrapper for cleaner try-catch
|
|
265
|
-
*/
|
|
266
|
-
export async function tryAsync(fn, context, suggestion) {
|
|
267
|
-
try {
|
|
268
|
-
return await fn();
|
|
269
|
-
}
|
|
270
|
-
catch (error) {
|
|
271
|
-
throw wrapError(error, context, suggestion);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Sync error wrapper for cleaner try-catch
|
|
276
|
-
*/
|
|
277
|
-
export function trySync(fn, context, suggestion) {
|
|
278
|
-
try {
|
|
279
|
-
return fn();
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
throw wrapError(error, context, suggestion);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Retry an async operation with exponential backoff
|
|
287
|
-
*/
|
|
288
|
-
export async function retry(fn, options = {}) {
|
|
289
|
-
const { maxAttempts = 3, initialDelay = 1000, maxDelay = 10000, backoffFactor = 2, context, retryIf = () => true, } = options;
|
|
290
|
-
let lastError;
|
|
291
|
-
let delay = initialDelay;
|
|
292
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
293
|
-
try {
|
|
294
|
-
return await fn();
|
|
295
|
-
}
|
|
296
|
-
catch (error) {
|
|
297
|
-
lastError = error;
|
|
298
|
-
// Don't retry if condition not met
|
|
299
|
-
if (!retryIf(error)) {
|
|
300
|
-
throw wrapError(error, context, `Operation failed and is not retryable`);
|
|
301
|
-
}
|
|
302
|
-
// Don't retry on last attempt
|
|
303
|
-
if (attempt === maxAttempts) {
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
// Wait before retrying
|
|
307
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
308
|
-
// Exponential backoff
|
|
309
|
-
delay = Math.min(delay * backoffFactor, maxDelay);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
throw wrapError(lastError, context, `Operation failed after ${maxAttempts} attempts`);
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Check if an error is retryable (network/transient errors)
|
|
316
|
-
*/
|
|
317
|
-
export function isRetryableError(error) {
|
|
318
|
-
if (!(error instanceof Error))
|
|
319
|
-
return false;
|
|
320
|
-
const message = error.message.toLowerCase();
|
|
321
|
-
const name = error.name.toLowerCase();
|
|
322
|
-
// Network errors
|
|
323
|
-
if (message.includes('econnrefused') ||
|
|
324
|
-
message.includes('econnreset') ||
|
|
325
|
-
message.includes('etimedout') ||
|
|
326
|
-
message.includes('timeout') ||
|
|
327
|
-
message.includes('network') ||
|
|
328
|
-
name === 'timeouterror' ||
|
|
329
|
-
name === 'networkerror') {
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
332
|
-
// Rate limiting
|
|
333
|
-
if (message.includes('rate limit') || message.includes('too many requests')) {
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
|
-
// Service unavailable
|
|
337
|
-
if (message.includes('503') || message.includes('service unavailable')) {
|
|
338
|
-
return true;
|
|
339
|
-
}
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
151
|
//# sourceMappingURL=error-handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/shared/error-handler.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/shared/error-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEnE,gDAAgD;AAChD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;AAExC,iFAAiF;AACjF,0CAA0C;AAC1C,iFAAiF;AAEjF;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,qCAAqC;IACrC,OAAO,EAAE,CAAC;IACV,gCAAgC;IAChC,KAAK,EAAE,CAAC;IACR,6CAA6C;IAC7C,gBAAgB,EAAE,CAAC;IACnB,sDAAsD;IACtD,YAAY,EAAE,CAAC;IACf,iCAAiC;IACjC,SAAS,EAAE,CAAC;IACZ,kCAAkC;IAClC,aAAa,EAAE,CAAC;IAChB,iDAAiD;IACjD,gBAAgB,EAAE,CAAC;IACnB,wBAAwB;IACxB,iBAAiB,EAAE,EAAE;IACrB,sCAAsC;IACtC,SAAS,EAAE,GAAG;CACN,CAAC;AAIX,iFAAiF;AACjF,kBAAkB;AAClB,iFAAi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,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAEpF,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,gBAAgB,UAAU,EAAE,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,QAAQ,UAAU,EAAE,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC;QAC9B,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,kBAAkB,UAAU,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,UAAU,UAAU,EAAE,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -24,19 +24,10 @@ export declare function isLocalRequest(req: IncomingMessage): boolean;
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function timingSafeEqual(a: string, b: string): boolean;
|
|
26
26
|
export declare function validateNpmPackageName(input: string): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Validates a URL string. Returns the parsed URL or throws on invalid/dangerous input.
|
|
29
|
-
*/
|
|
30
|
-
export declare function validateUrl(input: string): URL;
|
|
31
27
|
/**
|
|
32
28
|
* Escapes HTML special characters to prevent XSS.
|
|
33
29
|
*/
|
|
34
30
|
export declare function escapeHtml(str: string): string;
|
|
35
|
-
/**
|
|
36
|
-
* Returns a shallow copy of `obj` with dangerous prototype-pollution keys removed.
|
|
37
|
-
* Works recursively on nested objects.
|
|
38
|
-
*/
|
|
39
|
-
export declare function sanitizeObject<T extends Record<string, any>>(obj: T): T;
|
|
40
31
|
/**
|
|
41
32
|
* Checks if a template expression contains forbidden identifiers
|
|
42
33
|
* that could be used for code injection. Returns the forbidden token or null.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/shared/security.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAI5D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAOrE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAW3D;AAID;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAI5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAQ7D;AAWD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D;
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/shared/security.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAI5D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAOrE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAW3D;AAID;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAI5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CA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