@myapihq/cli 2.31.1 → 2.31.2
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/dist/flags.d.ts +1 -0
- package/dist/flags.js +24 -0
- package/dist/flags.test.js +27 -1
- package/dist/index.js +2 -3
- package/package.json +2 -2
package/dist/flags.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type FlagType = 'string' | 'boolean' | 'number' | 'list';
|
|
2
2
|
export type FlagSchema = Record<string, FlagType>;
|
|
3
3
|
export declare const GLOBAL_FLAGS: FlagSchema;
|
|
4
|
+
export declare const DISPATCH_FLAGS: ReadonlySet<string>;
|
|
4
5
|
export interface ParsedArgs {
|
|
5
6
|
args: string[];
|
|
6
7
|
flags: Record<string, string | boolean | number>;
|
package/dist/flags.js
CHANGED
|
@@ -5,13 +5,37 @@
|
|
|
5
5
|
// utils.ts — adding a new value flag without registering it would silently
|
|
6
6
|
// turn it into a boolean (e.g. `--html '<p>'` becoming `flags.html === true`).
|
|
7
7
|
// Flags every command understands.
|
|
8
|
+
//
|
|
9
|
+
// `org` belongs here rather than in each command's own schema. Ten commands
|
|
10
|
+
// declared it individually and the other nineteen did not, so the same flag
|
|
11
|
+
// refused a duplicate on `myapi pixel` and silently kept the last value on
|
|
12
|
+
// `myapi funnel push` — see the duplicate check in parseFlags for why last-wins
|
|
13
|
+
// is the one outcome you cannot recover from. For the tenant selector it picks
|
|
14
|
+
// the organisation your write lands in, which makes it the worst flag in the
|
|
15
|
+
// CLI to resolve silently.
|
|
8
16
|
export const GLOBAL_FLAGS = {
|
|
9
17
|
help: 'boolean',
|
|
10
18
|
json: 'boolean',
|
|
11
19
|
verbose: 'boolean',
|
|
12
20
|
yes: 'boolean',
|
|
13
21
|
y: 'boolean',
|
|
22
|
+
version: 'boolean',
|
|
23
|
+
org: 'string',
|
|
14
24
|
};
|
|
25
|
+
// Short aliases are consumed as `-h` / `-v` / `-V` before the `--flag` branch,
|
|
26
|
+
// so they never appear as keys in `merged` and need no type — but they do land
|
|
27
|
+
// in `flags` (as help/version), so the dispatcher must still tolerate them.
|
|
28
|
+
const SHORT_ALIASES = ['h', 'v', 'V'];
|
|
29
|
+
// What the dispatcher tolerates on any command, derived from the list above so
|
|
30
|
+
// the two cannot disagree. They previously drifted: `--org` was missing here
|
|
31
|
+
// while being honoured, so the CLI announced "unknown flag --org (took value
|
|
32
|
+
// …)" and then switched organisation anyway. A user who believed the warning
|
|
33
|
+
// and dropped the flag would have written to whatever org the config pointed
|
|
34
|
+
// at (ImmoPilot, 2026-08-22).
|
|
35
|
+
export const DISPATCH_FLAGS = new Set([
|
|
36
|
+
...Object.keys(GLOBAL_FLAGS),
|
|
37
|
+
...SHORT_ALIASES,
|
|
38
|
+
]);
|
|
15
39
|
// `quiet` suppresses the unknown-flag note. The dispatcher parses twice — once
|
|
16
40
|
// to learn the command, once under that command's own schema — and only the
|
|
17
41
|
// second pass knows which flags are genuinely foreign, so the first must stay
|
package/dist/flags.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { parseFlags } from './flags.js';
|
|
2
|
+
import { parseFlags, GLOBAL_FLAGS, DISPATCH_FLAGS } from './flags.js';
|
|
3
3
|
const SCHEMA = {
|
|
4
4
|
org: 'string',
|
|
5
5
|
name: 'string',
|
|
@@ -190,3 +190,29 @@ describe('parseFlags — repeated flags are never silently collapsed', () => {
|
|
|
190
190
|
expect(flags.name).toBe('prod');
|
|
191
191
|
});
|
|
192
192
|
});
|
|
193
|
+
// ImmoPilot, 2026-08-22: `--org` was honoured while being announced as an
|
|
194
|
+
// unknown flag, because the dispatcher's tolerated-flag list and the parser's
|
|
195
|
+
// typed-flag list were maintained separately and disagreed. DISPATCH_FLAGS is
|
|
196
|
+
// now derived from GLOBAL_FLAGS, so this asserts the derivation holds rather
|
|
197
|
+
// than re-checking a hand-written list.
|
|
198
|
+
describe('global flag lists cannot drift', () => {
|
|
199
|
+
it('every globally-typed flag is tolerated by the dispatcher', () => {
|
|
200
|
+
for (const key of Object.keys(GLOBAL_FLAGS)) {
|
|
201
|
+
expect(DISPATCH_FLAGS.has(key)).toBe(true);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
it('org is typed globally, so every command refuses a duplicate', () => {
|
|
205
|
+
// Ten commands declared `org` in their own schema and got this guard; the
|
|
206
|
+
// other nineteen silently kept the last value. Parse with an empty schema
|
|
207
|
+
// to stand in for a command that declares nothing of its own.
|
|
208
|
+
expect(() => parseFlags(['--org', 'ORG_A', '--org', 'ORG_B'], {}, true)).toThrow(/--org was given more than once/);
|
|
209
|
+
});
|
|
210
|
+
it('a single --org still parses to its value under an empty schema', () => {
|
|
211
|
+
const { flags } = parseFlags(['--org', 'ORG_A'], {}, true);
|
|
212
|
+
expect(flags.org).toBe('ORG_A');
|
|
213
|
+
});
|
|
214
|
+
it('--org is not reported as a foreign flag', () => {
|
|
215
|
+
const { unknownFlags } = parseFlags(['--org', 'ORG_A'], {}, true);
|
|
216
|
+
expect(unknownFlags ?? []).not.toContain('--org');
|
|
217
|
+
});
|
|
218
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { MyApiError, setUserAgent, hq } from '@myapihq/sdk';
|
|
|
5
5
|
import { friendlyError } from './errors.js';
|
|
6
6
|
import { currentOrg, adoptSoleOrg } from './helpers.js';
|
|
7
7
|
import * as fs from 'fs';
|
|
8
|
-
import { parseFlags } from './flags.js';
|
|
8
|
+
import { parseFlags, DISPATCH_FLAGS } from './flags.js';
|
|
9
9
|
const pkgPath = new URL('../package.json', import.meta.url);
|
|
10
10
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
11
11
|
// Identify the CLI (and its version) on every outbound request. Without this
|
|
@@ -100,8 +100,7 @@ const COMMAND_SCHEMAS = {
|
|
|
100
100
|
webhook: webhookCmd.SCHEMA,
|
|
101
101
|
workflow: workflowCmd.SCHEMA,
|
|
102
102
|
};
|
|
103
|
-
// Flags the dispatcher itself consumes
|
|
104
|
-
const DISPATCH_FLAGS = new Set(['help', 'h', 'json', 'verbose', 'yes', 'y', 'version', 'v', 'V', 'org']);
|
|
103
|
+
// Flags the dispatcher itself consumes are derived from GLOBAL_FLAGS in flags.ts.
|
|
105
104
|
function warnForeignFlags(command, flags) {
|
|
106
105
|
if (!command || process.env.MYAPI_QUIET_UNKNOWN_FLAGS)
|
|
107
106
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myapihq/cli",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.31.
|
|
4
|
+
"version": "2.31.2",
|
|
5
5
|
"description": "MyAPI command-line interface",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"lint:skills:strict": "node scripts/copy-skills.js && node scripts/lint-skills.js --strict"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@myapihq/sdk": "^2.31.
|
|
50
|
+
"@myapihq/sdk": "^2.31.2"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/node": "^25.6.0",
|