@switchbot/openapi-cli 3.1.1 → 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.
Files changed (113) hide show
  1. package/README.md +3 -3
  2. package/dist/index.js +56945 -169
  3. package/dist/policy/schema/v0.2.json +1 -1
  4. package/package.json +3 -2
  5. package/dist/api/client.js +0 -235
  6. package/dist/auth.js +0 -20
  7. package/dist/commands/agent-bootstrap.js +0 -182
  8. package/dist/commands/auth.js +0 -354
  9. package/dist/commands/batch.js +0 -413
  10. package/dist/commands/cache.js +0 -126
  11. package/dist/commands/capabilities.js +0 -385
  12. package/dist/commands/catalog.js +0 -359
  13. package/dist/commands/completion.js +0 -385
  14. package/dist/commands/config.js +0 -376
  15. package/dist/commands/daemon.js +0 -410
  16. package/dist/commands/device-meta.js +0 -159
  17. package/dist/commands/devices.js +0 -948
  18. package/dist/commands/doctor.js +0 -1015
  19. package/dist/commands/events.js +0 -563
  20. package/dist/commands/expand.js +0 -130
  21. package/dist/commands/explain.js +0 -139
  22. package/dist/commands/health.js +0 -113
  23. package/dist/commands/history.js +0 -320
  24. package/dist/commands/identity.js +0 -59
  25. package/dist/commands/install.js +0 -246
  26. package/dist/commands/mcp.js +0 -2017
  27. package/dist/commands/plan.js +0 -653
  28. package/dist/commands/policy.js +0 -586
  29. package/dist/commands/quota.js +0 -78
  30. package/dist/commands/rules.js +0 -875
  31. package/dist/commands/scenes.js +0 -264
  32. package/dist/commands/schema.js +0 -177
  33. package/dist/commands/status-sync.js +0 -131
  34. package/dist/commands/uninstall.js +0 -237
  35. package/dist/commands/upgrade-check.js +0 -107
  36. package/dist/commands/watch.js +0 -194
  37. package/dist/commands/webhook.js +0 -182
  38. package/dist/config.js +0 -258
  39. package/dist/credentials/backends/file.js +0 -101
  40. package/dist/credentials/backends/linux.js +0 -129
  41. package/dist/credentials/backends/macos.js +0 -129
  42. package/dist/credentials/backends/windows.js +0 -215
  43. package/dist/credentials/keychain.js +0 -88
  44. package/dist/credentials/prime.js +0 -52
  45. package/dist/devices/cache.js +0 -293
  46. package/dist/devices/catalog.js +0 -767
  47. package/dist/devices/device-meta.js +0 -56
  48. package/dist/devices/history-agg.js +0 -138
  49. package/dist/devices/history-query.js +0 -181
  50. package/dist/devices/param-validator.js +0 -433
  51. package/dist/devices/resources.js +0 -270
  52. package/dist/install/default-steps.js +0 -257
  53. package/dist/install/preflight.js +0 -212
  54. package/dist/install/steps.js +0 -67
  55. package/dist/lib/command-keywords.js +0 -17
  56. package/dist/lib/daemon-state.js +0 -46
  57. package/dist/lib/destructive-mode.js +0 -12
  58. package/dist/lib/devices.js +0 -382
  59. package/dist/lib/idempotency.js +0 -106
  60. package/dist/lib/plan-store.js +0 -68
  61. package/dist/lib/request-context.js +0 -12
  62. package/dist/lib/scenes.js +0 -10
  63. package/dist/logger.js +0 -16
  64. package/dist/mcp/device-history.js +0 -145
  65. package/dist/mcp/events-subscription.js +0 -213
  66. package/dist/mqtt/client.js +0 -180
  67. package/dist/mqtt/credential.js +0 -30
  68. package/dist/policy/add-rule.js +0 -124
  69. package/dist/policy/diff.js +0 -91
  70. package/dist/policy/format.js +0 -57
  71. package/dist/policy/load.js +0 -61
  72. package/dist/policy/migrate.js +0 -67
  73. package/dist/policy/schema.js +0 -18
  74. package/dist/policy/validate.js +0 -262
  75. package/dist/rules/action.js +0 -216
  76. package/dist/rules/audit-query.js +0 -89
  77. package/dist/rules/conflict-analyzer.js +0 -214
  78. package/dist/rules/cron-scheduler.js +0 -186
  79. package/dist/rules/destructive.js +0 -52
  80. package/dist/rules/engine.js +0 -757
  81. package/dist/rules/matcher.js +0 -230
  82. package/dist/rules/pid-file.js +0 -95
  83. package/dist/rules/quiet-hours.js +0 -45
  84. package/dist/rules/suggest.js +0 -95
  85. package/dist/rules/throttle.js +0 -116
  86. package/dist/rules/types.js +0 -34
  87. package/dist/rules/webhook-listener.js +0 -223
  88. package/dist/rules/webhook-token.js +0 -90
  89. package/dist/schema/field-aliases.js +0 -131
  90. package/dist/sinks/dispatcher.js +0 -12
  91. package/dist/sinks/file.js +0 -19
  92. package/dist/sinks/format.js +0 -56
  93. package/dist/sinks/homeassistant.js +0 -44
  94. package/dist/sinks/openclaw.js +0 -33
  95. package/dist/sinks/stdout.js +0 -5
  96. package/dist/sinks/telegram.js +0 -28
  97. package/dist/sinks/types.js +0 -1
  98. package/dist/sinks/webhook.js +0 -22
  99. package/dist/status-sync/manager.js +0 -268
  100. package/dist/utils/arg-parsers.js +0 -66
  101. package/dist/utils/audit.js +0 -121
  102. package/dist/utils/filter.js +0 -189
  103. package/dist/utils/flags.js +0 -186
  104. package/dist/utils/format.js +0 -117
  105. package/dist/utils/health.js +0 -101
  106. package/dist/utils/help-json.js +0 -54
  107. package/dist/utils/name-resolver.js +0 -137
  108. package/dist/utils/output.js +0 -404
  109. package/dist/utils/quota.js +0 -227
  110. package/dist/utils/redact.js +0 -68
  111. package/dist/utils/retry.js +0 -140
  112. package/dist/utils/string.js +0 -22
  113. package/dist/version.js +0 -4
@@ -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
- }
@@ -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
@@ -1,4 +0,0 @@
1
- import { createRequire } from 'module';
2
- const require = createRequire(import.meta.url);
3
- const { version: VERSION } = require('../package.json');
4
- export { VERSION };