@switchbot/openapi-cli 3.1.0 → 3.2.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 +34 -42
- package/dist/index.js +56945 -169
- package/dist/policy/schema/v0.2.json +1 -1
- package/package.json +3 -2
- package/dist/api/client.js +0 -235
- package/dist/auth.js +0 -20
- package/dist/commands/agent-bootstrap.js +0 -182
- package/dist/commands/auth.js +0 -354
- package/dist/commands/batch.js +0 -413
- package/dist/commands/cache.js +0 -126
- package/dist/commands/capabilities.js +0 -385
- package/dist/commands/catalog.js +0 -359
- package/dist/commands/completion.js +0 -385
- package/dist/commands/config.js +0 -376
- package/dist/commands/daemon.js +0 -367
- package/dist/commands/device-meta.js +0 -159
- package/dist/commands/devices.js +0 -948
- package/dist/commands/doctor.js +0 -1015
- package/dist/commands/events.js +0 -563
- package/dist/commands/expand.js +0 -130
- package/dist/commands/explain.js +0 -139
- package/dist/commands/health.js +0 -113
- package/dist/commands/history.js +0 -320
- package/dist/commands/identity.js +0 -59
- package/dist/commands/install.js +0 -246
- package/dist/commands/mcp.js +0 -2017
- package/dist/commands/plan.js +0 -653
- package/dist/commands/policy.js +0 -586
- package/dist/commands/quota.js +0 -78
- package/dist/commands/rules.js +0 -875
- package/dist/commands/scenes.js +0 -264
- package/dist/commands/schema.js +0 -177
- package/dist/commands/status-sync.js +0 -131
- package/dist/commands/uninstall.js +0 -237
- package/dist/commands/upgrade-check.js +0 -88
- package/dist/commands/watch.js +0 -194
- package/dist/commands/webhook.js +0 -182
- package/dist/config.js +0 -258
- package/dist/credentials/backends/file.js +0 -101
- package/dist/credentials/backends/linux.js +0 -129
- package/dist/credentials/backends/macos.js +0 -129
- package/dist/credentials/backends/windows.js +0 -215
- package/dist/credentials/keychain.js +0 -88
- package/dist/credentials/prime.js +0 -52
- package/dist/devices/cache.js +0 -293
- package/dist/devices/catalog.js +0 -767
- package/dist/devices/device-meta.js +0 -56
- package/dist/devices/history-agg.js +0 -138
- package/dist/devices/history-query.js +0 -181
- package/dist/devices/param-validator.js +0 -433
- package/dist/devices/resources.js +0 -270
- package/dist/install/default-steps.js +0 -257
- package/dist/install/preflight.js +0 -212
- package/dist/install/steps.js +0 -67
- package/dist/lib/command-keywords.js +0 -17
- package/dist/lib/daemon-state.js +0 -46
- package/dist/lib/destructive-mode.js +0 -12
- package/dist/lib/devices.js +0 -382
- package/dist/lib/idempotency.js +0 -106
- package/dist/lib/plan-store.js +0 -68
- package/dist/lib/request-context.js +0 -12
- package/dist/lib/scenes.js +0 -10
- package/dist/logger.js +0 -16
- package/dist/mcp/device-history.js +0 -145
- package/dist/mcp/events-subscription.js +0 -213
- package/dist/mqtt/client.js +0 -180
- package/dist/mqtt/credential.js +0 -30
- package/dist/policy/add-rule.js +0 -124
- package/dist/policy/diff.js +0 -91
- package/dist/policy/format.js +0 -57
- package/dist/policy/load.js +0 -61
- package/dist/policy/migrate.js +0 -67
- package/dist/policy/schema.js +0 -18
- package/dist/policy/validate.js +0 -262
- package/dist/rules/action.js +0 -205
- package/dist/rules/audit-query.js +0 -89
- package/dist/rules/conflict-analyzer.js +0 -203
- package/dist/rules/cron-scheduler.js +0 -186
- package/dist/rules/destructive.js +0 -52
- package/dist/rules/engine.js +0 -757
- package/dist/rules/matcher.js +0 -230
- package/dist/rules/pid-file.js +0 -95
- package/dist/rules/quiet-hours.js +0 -45
- package/dist/rules/suggest.js +0 -95
- package/dist/rules/throttle.js +0 -116
- package/dist/rules/types.js +0 -34
- package/dist/rules/webhook-listener.js +0 -223
- package/dist/rules/webhook-token.js +0 -90
- package/dist/schema/field-aliases.js +0 -131
- package/dist/sinks/dispatcher.js +0 -12
- package/dist/sinks/file.js +0 -19
- package/dist/sinks/format.js +0 -56
- package/dist/sinks/homeassistant.js +0 -44
- package/dist/sinks/openclaw.js +0 -33
- package/dist/sinks/stdout.js +0 -5
- package/dist/sinks/telegram.js +0 -28
- package/dist/sinks/types.js +0 -1
- package/dist/sinks/webhook.js +0 -22
- package/dist/status-sync/manager.js +0 -268
- package/dist/utils/arg-parsers.js +0 -66
- package/dist/utils/audit.js +0 -117
- package/dist/utils/filter.js +0 -189
- package/dist/utils/flags.js +0 -186
- package/dist/utils/format.js +0 -117
- package/dist/utils/health.js +0 -101
- package/dist/utils/help-json.js +0 -54
- package/dist/utils/name-resolver.js +0 -137
- package/dist/utils/output.js +0 -404
- package/dist/utils/quota.js +0 -227
- package/dist/utils/redact.js +0 -68
- package/dist/utils/retry.js +0 -140
- package/dist/utils/string.js +0 -22
- package/dist/version.js +0 -4
package/dist/utils/retry.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retry/backoff helpers for the axios client. Kept as pure functions so
|
|
3
|
-
* tests can pin attempt → delay without wall-clock sleeping.
|
|
4
|
-
*
|
|
5
|
-
* Backoff strategies:
|
|
6
|
-
* linear → 1s, 2s, 3s, ... (cap 30s)
|
|
7
|
-
* exponential → 1s, 2s, 4s, 8s, 16s (cap 30s) [default]
|
|
8
|
-
*
|
|
9
|
-
* If the server returns a `Retry-After` header we always prefer it over our
|
|
10
|
-
* own backoff — the API explicitly told us when to come back.
|
|
11
|
-
*
|
|
12
|
-
* Circuit breaker:
|
|
13
|
-
* Prevents hammering a consistently-failing endpoint. Tracks consecutive
|
|
14
|
-
* failures; when `failureThreshold` is exceeded the circuit opens and
|
|
15
|
-
* subsequent calls fail immediately (with CircuitOpenError). After
|
|
16
|
-
* `resetTimeoutMs` the circuit enters half-open state: the next call is
|
|
17
|
-
* allowed as a probe — success closes it, failure re-opens it.
|
|
18
|
-
*/
|
|
19
|
-
const BASE_MS = 1_000;
|
|
20
|
-
const MAX_MS = 30_000;
|
|
21
|
-
/**
|
|
22
|
-
* Parse an HTTP `Retry-After` header. Supports both the seconds form
|
|
23
|
-
* ("Retry-After: 42") and the HTTP-date form ("Retry-After: Wed, 21 Oct
|
|
24
|
-
* 2015 07:28:00 GMT"). Returns the delay in ms, or undefined on garbage.
|
|
25
|
-
*/
|
|
26
|
-
export function parseRetryAfter(header, now = Date.now()) {
|
|
27
|
-
if (typeof header !== 'string')
|
|
28
|
-
return undefined;
|
|
29
|
-
const trimmed = header.trim();
|
|
30
|
-
if (!trimmed)
|
|
31
|
-
return undefined;
|
|
32
|
-
// All-digits → seconds.
|
|
33
|
-
if (/^\d+$/.test(trimmed)) {
|
|
34
|
-
const seconds = Number(trimmed);
|
|
35
|
-
if (!Number.isFinite(seconds) || seconds < 0)
|
|
36
|
-
return undefined;
|
|
37
|
-
return Math.min(seconds * 1000, MAX_MS);
|
|
38
|
-
}
|
|
39
|
-
// HTTP-date.
|
|
40
|
-
const ts = Date.parse(trimmed);
|
|
41
|
-
if (!Number.isFinite(ts))
|
|
42
|
-
return undefined;
|
|
43
|
-
const delta = ts - now;
|
|
44
|
-
if (delta <= 0)
|
|
45
|
-
return 0;
|
|
46
|
-
return Math.min(delta, MAX_MS);
|
|
47
|
-
}
|
|
48
|
-
/** Compute the next backoff delay (ms) for a given attempt index (0-based). */
|
|
49
|
-
export function computeBackoff(attempt, strategy) {
|
|
50
|
-
const safe = Math.max(0, attempt);
|
|
51
|
-
if (strategy === 'linear') {
|
|
52
|
-
return Math.min((safe + 1) * BASE_MS, MAX_MS);
|
|
53
|
-
}
|
|
54
|
-
// exponential
|
|
55
|
-
return Math.min(BASE_MS * Math.pow(2, safe), MAX_MS);
|
|
56
|
-
}
|
|
57
|
-
/** Resolve the delay to use before the next retry, preferring Retry-After. */
|
|
58
|
-
export function nextRetryDelayMs(attempt, strategy, retryAfterHeader, now = Date.now()) {
|
|
59
|
-
const fromHeader = parseRetryAfter(retryAfterHeader, now);
|
|
60
|
-
if (fromHeader !== undefined)
|
|
61
|
-
return fromHeader;
|
|
62
|
-
return computeBackoff(attempt, strategy);
|
|
63
|
-
}
|
|
64
|
-
export function sleep(ms) {
|
|
65
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Thrown when a call is blocked because the circuit is open.
|
|
69
|
-
*/
|
|
70
|
-
export class CircuitOpenError extends Error {
|
|
71
|
-
circuitName;
|
|
72
|
-
nextAttemptMs;
|
|
73
|
-
constructor(circuitName, nextAttemptMs) {
|
|
74
|
-
super(`Circuit "${circuitName}" is open — too many recent failures. Next probe allowed in ${Math.ceil((nextAttemptMs - Date.now()) / 1000)}s.`);
|
|
75
|
-
this.circuitName = circuitName;
|
|
76
|
-
this.nextAttemptMs = nextAttemptMs;
|
|
77
|
-
this.name = 'CircuitOpenError';
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export class CircuitBreaker {
|
|
81
|
-
name;
|
|
82
|
-
state = 'closed';
|
|
83
|
-
failures = 0;
|
|
84
|
-
lastOpenedAt = 0;
|
|
85
|
-
failureThreshold;
|
|
86
|
-
resetTimeoutMs;
|
|
87
|
-
constructor(name, opts = {}) {
|
|
88
|
-
this.name = name;
|
|
89
|
-
this.failureThreshold = opts.failureThreshold ?? 5;
|
|
90
|
-
this.resetTimeoutMs = opts.resetTimeoutMs ?? 60_000;
|
|
91
|
-
}
|
|
92
|
-
getState() {
|
|
93
|
-
this._maybeHalfOpen();
|
|
94
|
-
return this.state;
|
|
95
|
-
}
|
|
96
|
-
getStats() {
|
|
97
|
-
this._maybeHalfOpen();
|
|
98
|
-
return {
|
|
99
|
-
state: this.state,
|
|
100
|
-
failures: this.failures,
|
|
101
|
-
lastOpenedAt: this.lastOpenedAt,
|
|
102
|
-
nextProbeMs: this.state === 'open' ? this.lastOpenedAt + this.resetTimeoutMs : 0,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Check if a call is allowed. Throws `CircuitOpenError` when the circuit
|
|
107
|
-
* is open and the reset timeout hasn't elapsed. Call `recordSuccess()` or
|
|
108
|
-
* `recordFailure()` after the operation completes.
|
|
109
|
-
*/
|
|
110
|
-
checkAndAllow() {
|
|
111
|
-
this._maybeHalfOpen();
|
|
112
|
-
if (this.state === 'open') {
|
|
113
|
-
throw new CircuitOpenError(this.name, this.lastOpenedAt + this.resetTimeoutMs);
|
|
114
|
-
}
|
|
115
|
-
// closed or half-open: allow the call
|
|
116
|
-
}
|
|
117
|
-
recordSuccess() {
|
|
118
|
-
this.failures = 0;
|
|
119
|
-
this.state = 'closed';
|
|
120
|
-
}
|
|
121
|
-
recordFailure() {
|
|
122
|
-
this.failures++;
|
|
123
|
-
if (this.state === 'half-open' || this.failures >= this.failureThreshold) {
|
|
124
|
-
this.state = 'open';
|
|
125
|
-
this.lastOpenedAt = Date.now();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/** Reset to closed — useful for testing or manual recovery. */
|
|
129
|
-
reset() {
|
|
130
|
-
this.state = 'closed';
|
|
131
|
-
this.failures = 0;
|
|
132
|
-
this.lastOpenedAt = 0;
|
|
133
|
-
}
|
|
134
|
-
_maybeHalfOpen() {
|
|
135
|
-
if (this.state === 'open' &&
|
|
136
|
-
Date.now() >= this.lastOpenedAt + this.resetTimeoutMs) {
|
|
137
|
-
this.state = 'half-open';
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
package/dist/utils/string.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export function levenshtein(a, b) {
|
|
2
|
-
if (a === b)
|
|
3
|
-
return 0;
|
|
4
|
-
if (a.length === 0)
|
|
5
|
-
return b.length;
|
|
6
|
-
if (b.length === 0)
|
|
7
|
-
return a.length;
|
|
8
|
-
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
9
|
-
for (let i = 1; i <= a.length; i++) {
|
|
10
|
-
let prev = i;
|
|
11
|
-
for (let j = 1; j <= b.length; j++) {
|
|
12
|
-
const val = a[i - 1] === b[j - 1] ? row[j - 1] : Math.min(row[j - 1], row[j], prev) + 1;
|
|
13
|
-
row[j - 1] = prev;
|
|
14
|
-
prev = val;
|
|
15
|
-
}
|
|
16
|
-
row[b.length] = prev;
|
|
17
|
-
}
|
|
18
|
-
return row[b.length];
|
|
19
|
-
}
|
|
20
|
-
export function normalizeDeviceName(s) {
|
|
21
|
-
return s.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff ]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
22
|
-
}
|
package/dist/version.js
DELETED