@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.
Files changed (113) hide show
  1. package/README.md +34 -42
  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 -367
  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 -88
  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 -205
  76. package/dist/rules/audit-query.js +0 -89
  77. package/dist/rules/conflict-analyzer.js +0 -203
  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 -117
  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,354 +0,0 @@
1
- /**
2
- * `switchbot auth` command group (v2.9 preview, part of Phase 3A).
3
- *
4
- * Surfaces the credential store abstraction added in F1/F2 so users
5
- * can introspect, write to, delete from, and migrate into the OS
6
- * keychain without editing `~/.switchbot/config.json` by hand.
7
- *
8
- * All subcommands honour the active `--profile <name>` flag so a user
9
- * who runs multiple accounts keeps the keychain entries cleanly
10
- * partitioned.
11
- *
12
- * No credential material is ever printed in plain text. `get` emits
13
- * a masked summary only; `set` reads via a TTY prompt (echo-off) or a
14
- * file passed via `--stdin-file <path>`. `migrate` never touches the
15
- * keychain unless the backend reports `writable: true`.
16
- */
17
- import fs from 'node:fs';
18
- import path from 'node:path';
19
- import os from 'node:os';
20
- import readline from 'node:readline';
21
- import { exitWithError, isJsonMode, printJson } from '../utils/output.js';
22
- import { stringArg } from '../utils/arg-parsers.js';
23
- import { getActiveProfile } from '../lib/request-context.js';
24
- import { selectCredentialStore, } from '../credentials/keychain.js';
25
- function activeProfile() {
26
- return getActiveProfile() ?? 'default';
27
- }
28
- function maskValue(value) {
29
- if (value.length === 0)
30
- return '';
31
- if (value.length <= 4)
32
- return '*'.repeat(value.length);
33
- const head = value.slice(0, 2);
34
- const tail = value.slice(-2);
35
- return `${head}${'*'.repeat(Math.max(4, value.length - 4))}${tail}`;
36
- }
37
- async function promptSecret(question) {
38
- const rl = readline.createInterface({ input: process.stdin, output: process.stderr, terminal: true });
39
- return new Promise((resolve) => {
40
- process.stderr.write(question);
41
- const stdin = process.stdin;
42
- let answer = '';
43
- const onData = (chunk) => {
44
- const s = chunk.toString('utf-8');
45
- for (const ch of s) {
46
- if (ch === '\r' || ch === '\n') {
47
- stdin.removeListener('data', onData);
48
- if (stdin.setRawMode)
49
- stdin.setRawMode(false);
50
- stdin.pause();
51
- process.stderr.write('\n');
52
- rl.close();
53
- resolve(answer);
54
- return;
55
- }
56
- if (ch === '\u0003') {
57
- process.exit(130);
58
- }
59
- if (ch === '\u007f' || ch === '\b') {
60
- answer = answer.slice(0, -1);
61
- continue;
62
- }
63
- answer += ch;
64
- }
65
- };
66
- if (stdin.setRawMode)
67
- stdin.setRawMode(true);
68
- stdin.resume();
69
- stdin.on('data', onData);
70
- });
71
- }
72
- function readStdinFile(filePath) {
73
- if (!fs.existsSync(filePath)) {
74
- exitWithError({
75
- code: 2,
76
- kind: 'usage',
77
- message: `--stdin-file: file not found: ${filePath}`,
78
- });
79
- }
80
- let parsed;
81
- try {
82
- parsed = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
83
- }
84
- catch (err) {
85
- exitWithError({
86
- code: 2,
87
- kind: 'usage',
88
- message: `--stdin-file: invalid JSON: ${err instanceof Error ? err.message : String(err)}`,
89
- });
90
- }
91
- if (!parsed ||
92
- typeof parsed !== 'object' ||
93
- typeof parsed.token !== 'string' ||
94
- typeof parsed.secret !== 'string') {
95
- exitWithError({
96
- code: 2,
97
- kind: 'usage',
98
- message: '--stdin-file must contain a JSON object with "token" and "secret" strings.',
99
- });
100
- }
101
- const { token, secret } = parsed;
102
- if (!token || !secret) {
103
- exitWithError({
104
- code: 2,
105
- kind: 'usage',
106
- message: '--stdin-file: token and secret must be non-empty.',
107
- });
108
- }
109
- return { token, secret };
110
- }
111
- function cleanupMigratedSourceFile(sourceFile, parsed) {
112
- const next = { ...parsed };
113
- delete next.token;
114
- delete next.secret;
115
- if (Object.keys(next).length === 0) {
116
- fs.unlinkSync(sourceFile);
117
- return 'deleted';
118
- }
119
- fs.writeFileSync(sourceFile, JSON.stringify(next, null, 2), { mode: 0o600 });
120
- return 'scrubbed';
121
- }
122
- export function registerAuthCommand(program) {
123
- const auth = program
124
- .command('auth')
125
- .description('Manage SwitchBot credentials in the OS keychain (preview)');
126
- const keychain = auth
127
- .command('keychain')
128
- .description('OS keychain backend (describe/get/set/delete/migrate)');
129
- keychain
130
- .command('describe')
131
- .description('Show which credential backend is active on this machine')
132
- .action(async () => {
133
- const store = await selectCredentialStore();
134
- const desc = store.describe();
135
- if (isJsonMode()) {
136
- printJson(desc);
137
- return;
138
- }
139
- console.log(`backend : ${desc.backend}`);
140
- console.log(`tag : ${desc.tag}`);
141
- console.log(`writable: ${desc.writable ? 'yes' : 'no'}`);
142
- if (desc.notes)
143
- console.log(`notes : ${desc.notes}`);
144
- });
145
- keychain
146
- .command('get')
147
- .description('Check whether the active profile has credentials (masked output)')
148
- .action(async () => {
149
- const profile = activeProfile();
150
- const store = await selectCredentialStore();
151
- const creds = await store.get(profile);
152
- if (!creds) {
153
- if (isJsonMode()) {
154
- printJson({ profile, backend: store.name, present: false });
155
- return;
156
- }
157
- console.log(`No credentials found for profile "${profile}" in backend "${store.name}".`);
158
- process.exit(1);
159
- }
160
- if (isJsonMode()) {
161
- printJson({
162
- profile,
163
- backend: store.name,
164
- present: true,
165
- token: { length: creds.token.length, masked: maskValue(creds.token) },
166
- secret: { length: creds.secret.length, masked: maskValue(creds.secret) },
167
- });
168
- return;
169
- }
170
- console.log(`profile : ${profile}`);
171
- console.log(`backend : ${store.name}`);
172
- console.log(`token : ${maskValue(creds.token)} (${creds.token.length} chars)`);
173
- console.log(`secret : ${maskValue(creds.secret)} (${creds.secret.length} chars)`);
174
- });
175
- keychain
176
- .command('set')
177
- .description('Write token and secret to the keychain for the active profile')
178
- .option('--stdin-file <path>', 'Read {"token","secret"} JSON from file (for non-TTY environments)', stringArg('--stdin-file'))
179
- .action(async (options) => {
180
- const profile = activeProfile();
181
- const store = await selectCredentialStore();
182
- if (!store.describe().writable) {
183
- exitWithError({
184
- code: 1,
185
- kind: 'runtime',
186
- message: `backend "${store.name}" is not writable on this machine`,
187
- hint: 'Install the OS keychain helper or use ~/.switchbot/config.json directly.',
188
- });
189
- }
190
- let bundle;
191
- if (options.stdinFile) {
192
- bundle = readStdinFile(options.stdinFile);
193
- }
194
- else if (process.stdin.isTTY) {
195
- const token = (await promptSecret('Token : ')).trim();
196
- const secret = (await promptSecret('Secret: ')).trim();
197
- if (!token || !secret) {
198
- exitWithError({
199
- code: 2,
200
- kind: 'usage',
201
- message: 'Both token and secret are required.',
202
- });
203
- }
204
- bundle = { token, secret };
205
- }
206
- else {
207
- exitWithError({
208
- code: 2,
209
- kind: 'usage',
210
- message: 'Non-TTY input requires --stdin-file <path>.',
211
- });
212
- }
213
- try {
214
- await store.set(profile, bundle);
215
- }
216
- catch (err) {
217
- exitWithError({
218
- code: 1,
219
- kind: 'runtime',
220
- message: `keychain write failed: ${err instanceof Error ? err.message : String(err)}`,
221
- });
222
- }
223
- if (isJsonMode()) {
224
- printJson({ profile, backend: store.name, written: true });
225
- return;
226
- }
227
- console.log(`Stored credentials for profile "${profile}" in backend "${store.name}".`);
228
- });
229
- keychain
230
- .command('delete')
231
- .description('Remove credentials for the active profile from the keychain')
232
- .option('--yes', 'Skip the interactive confirmation prompt')
233
- .action(async (options) => {
234
- const profile = activeProfile();
235
- const store = await selectCredentialStore();
236
- if (!options.yes && process.stdin.isTTY) {
237
- const reply = (await promptSecret(`Delete credentials for profile "${profile}" from backend "${store.name}"? type DELETE to confirm: `)).trim();
238
- if (reply !== 'DELETE') {
239
- if (isJsonMode()) {
240
- printJson({ profile, backend: store.name, deleted: false, reason: 'cancelled' });
241
- return;
242
- }
243
- console.log('Aborted.');
244
- process.exit(0);
245
- }
246
- }
247
- try {
248
- await store.delete(profile);
249
- }
250
- catch (err) {
251
- exitWithError({
252
- code: 1,
253
- kind: 'runtime',
254
- message: `keychain delete failed: ${err instanceof Error ? err.message : String(err)}`,
255
- });
256
- }
257
- if (isJsonMode()) {
258
- printJson({ profile, backend: store.name, deleted: true });
259
- return;
260
- }
261
- console.log(`Deleted credentials for profile "${profile}" in backend "${store.name}".`);
262
- });
263
- keychain
264
- .command('migrate')
265
- .description('Copy credentials from ~/.switchbot/config.json (or --profile) into the keychain')
266
- .option('--delete-file', 'Remove the source credential file when possible; otherwise scrub token/secret and keep metadata')
267
- .action(async (options) => {
268
- const profile = activeProfile();
269
- const store = await selectCredentialStore();
270
- if (!store.describe().writable) {
271
- exitWithError({
272
- code: 1,
273
- kind: 'runtime',
274
- message: `backend "${store.name}" is not writable on this machine`,
275
- });
276
- }
277
- const sourceFile = profile === 'default'
278
- ? path.join(os.homedir(), '.switchbot', 'config.json')
279
- : path.join(os.homedir(), '.switchbot', 'profiles', `${profile}.json`);
280
- if (!fs.existsSync(sourceFile)) {
281
- exitWithError({
282
- code: 2,
283
- kind: 'usage',
284
- message: `source file not found: ${sourceFile}`,
285
- hint: 'Run "switchbot config set-token" first or use "switchbot auth keychain set" directly.',
286
- });
287
- }
288
- let parsed;
289
- try {
290
- const raw = JSON.parse(fs.readFileSync(sourceFile, 'utf-8'));
291
- if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
292
- throw new Error('expected a JSON object');
293
- }
294
- parsed = raw;
295
- }
296
- catch (err) {
297
- exitWithError({
298
- code: 1,
299
- kind: 'runtime',
300
- message: `failed to parse ${sourceFile}: ${err instanceof Error ? err.message : String(err)}`,
301
- });
302
- }
303
- const token = typeof parsed.token === 'string' ? parsed.token : '';
304
- const secret = typeof parsed.secret === 'string' ? parsed.secret : '';
305
- if (!token || !secret) {
306
- exitWithError({
307
- code: 1,
308
- kind: 'runtime',
309
- message: `source file missing token or secret: ${sourceFile}`,
310
- });
311
- }
312
- try {
313
- await store.set(profile, { token, secret });
314
- }
315
- catch (err) {
316
- exitWithError({
317
- code: 1,
318
- kind: 'runtime',
319
- message: `keychain write failed: ${err instanceof Error ? err.message : String(err)}`,
320
- });
321
- }
322
- let cleanup = 'kept';
323
- if (options.deleteFile) {
324
- try {
325
- cleanup = cleanupMigratedSourceFile(sourceFile, parsed);
326
- }
327
- catch (err) {
328
- // Non-fatal: migration succeeded, we just couldn't clean up.
329
- console.error(`warning: could not remove ${sourceFile}: ${err instanceof Error ? err.message : String(err)}`);
330
- }
331
- }
332
- if (isJsonMode()) {
333
- printJson({
334
- profile,
335
- backend: store.name,
336
- migrated: true,
337
- sourceFile,
338
- sourceDeleted: cleanup === 'deleted',
339
- sourceScrubbed: cleanup === 'scrubbed',
340
- });
341
- return;
342
- }
343
- console.log(`Migrated profile "${profile}" to backend "${store.name}".`);
344
- const cleanupNote = cleanup === 'deleted'
345
- ? ' (deleted)'
346
- : cleanup === 'scrubbed'
347
- ? ' (credentials removed; metadata kept)'
348
- : '';
349
- console.log(`source: ${sourceFile}${cleanupNote}`);
350
- if (!options.deleteFile) {
351
- console.log('Source file kept — pass --delete-file on the next run to remove it.');
352
- }
353
- });
354
- }