@atlasauth/cli 0.0.0-stage → 0.1.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 (59) hide show
  1. package/README.md +57 -2
  2. package/dist/args.d.ts +69 -0
  3. package/dist/args.js +69 -0
  4. package/dist/args.js.map +1 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +19 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/commands/api-keys.d.ts +4 -0
  9. package/dist/commands/api-keys.js +81 -0
  10. package/dist/commands/api-keys.js.map +1 -0
  11. package/dist/commands/auth.d.ts +25 -0
  12. package/dist/commands/auth.js +94 -0
  13. package/dist/commands/auth.js.map +1 -0
  14. package/dist/commands/orgs.d.ts +4 -0
  15. package/dist/commands/orgs.js +72 -0
  16. package/dist/commands/orgs.js.map +1 -0
  17. package/dist/commands/sessions.d.ts +4 -0
  18. package/dist/commands/sessions.js +28 -0
  19. package/dist/commands/sessions.js.map +1 -0
  20. package/dist/commands/shared.d.ts +32 -0
  21. package/dist/commands/shared.js +60 -0
  22. package/dist/commands/shared.js.map +1 -0
  23. package/dist/commands/users.d.ts +4 -0
  24. package/dist/commands/users.js +87 -0
  25. package/dist/commands/users.js.map +1 -0
  26. package/dist/commands/webhooks.d.ts +4 -0
  27. package/dist/commands/webhooks.js +34 -0
  28. package/dist/commands/webhooks.js.map +1 -0
  29. package/dist/config.d.ts +48 -0
  30. package/dist/config.js +69 -0
  31. package/dist/config.js.map +1 -0
  32. package/dist/context.d.ts +35 -0
  33. package/dist/context.js +23 -0
  34. package/dist/context.js.map +1 -0
  35. package/dist/errors.d.ts +15 -0
  36. package/dist/errors.js +25 -0
  37. package/dist/errors.js.map +1 -0
  38. package/dist/help.d.ts +8 -0
  39. package/dist/help.js +79 -0
  40. package/dist/help.js.map +1 -0
  41. package/dist/index.d.ts +19 -0
  42. package/dist/index.js +42 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/io.d.ts +21 -0
  45. package/dist/io.js +28 -0
  46. package/dist/io.js.map +1 -0
  47. package/dist/output.d.ts +41 -0
  48. package/dist/output.js +72 -0
  49. package/dist/output.js.map +1 -0
  50. package/dist/prompt.d.ts +15 -0
  51. package/dist/prompt.js +46 -0
  52. package/dist/prompt.js.map +1 -0
  53. package/dist/run.d.ts +12 -0
  54. package/dist/run.js +90 -0
  55. package/dist/run.js.map +1 -0
  56. package/dist/version.d.ts +7 -0
  57. package/dist/version.js +21 -0
  58. package/dist/version.js.map +1 -0
  59. package/package.json +34 -3
package/dist/io.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultIO = defaultIO;
4
+ exports.captureIO = captureIO;
5
+ /** The real IO: a trailing newline is added so callers pass bare lines. */
6
+ function defaultIO(stdout = process.stdout, stderr = process.stderr) {
7
+ return {
8
+ out(text) {
9
+ stdout.write(text + '\n');
10
+ },
11
+ err(text) {
12
+ stderr.write(text + '\n');
13
+ },
14
+ };
15
+ }
16
+ function captureIO() {
17
+ const outLines = [];
18
+ const errLines = [];
19
+ return {
20
+ outLines,
21
+ errLines,
22
+ out: (text) => void outLines.push(text),
23
+ err: (text) => void errLines.push(text),
24
+ stdout: () => outLines.join('\n'),
25
+ stderr: () => errLines.join('\n'),
26
+ };
27
+ }
28
+ //# sourceMappingURL=io.js.map
package/dist/io.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"io.js","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":";;AAaA,8BAYC;AAUD,8BAWC;AAlCD,2EAA2E;AAC3E,SAAgB,SAAS,CACvB,SAA6B,OAAO,CAAC,MAAM,EAC3C,SAA6B,OAAO,CAAC,MAAM;IAE3C,OAAO;QACL,GAAG,CAAC,IAAI;YACN,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QAC5B,CAAC;QACD,GAAG,CAAC,IAAI;YACN,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC;AAUD,SAAgB,SAAS;IACvB,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,OAAO;QACL,QAAQ;QACR,QAAQ;QACR,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QACvC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QACvC,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QACjC,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;KAClC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { IO } from './io';
2
+ /**
3
+ * A single rendered column: a header plus a getter that pulls the raw value off
4
+ * a row. Getters (not keys) because a few columns are derived — a user's name
5
+ * joins first + last, a webhook's events join an array — and a getter keeps that
6
+ * shaping next to the column instead of forcing a pre-massaged row.
7
+ */
8
+ export interface Column<T> {
9
+ header: string;
10
+ get: (row: T) => unknown;
11
+ }
12
+ /**
13
+ * Epoch-millisecond timestamp → ISO-8601, the form every Atlas `*_at` field
14
+ * takes on the wire. Blank for null (e.g. a user who never signed in) so the
15
+ * column stays readable rather than printing `1970-...`.
16
+ */
17
+ export declare function fmtTime(value: unknown): string;
18
+ /**
19
+ * Hand-rolled fixed-width table — the only "formatting library" this CLI has.
20
+ * Columns are padded to the widest cell (header included); a dashed rule sits
21
+ * under the header; trailing padding on the last column is trimmed so lines
22
+ * don't carry invisible whitespace. Empty input prints a friendly placeholder
23
+ * rather than a bare header with no rows.
24
+ */
25
+ export declare function renderTable<T>(columns: Column<T>[], rows: T[]): string;
26
+ /** Pretty-print any value as the `--json` output on stdout. */
27
+ export declare function printJson(io: IO, value: unknown): void;
28
+ /**
29
+ * Print a cursor-paginated list as either raw JSON or a table, and — in table
30
+ * mode, when there is another page — a footer naming the exact flag to fetch
31
+ * it. Keeping the hint next to the data is what makes `--starting-after`
32
+ * discoverable without the user reading `--help`.
33
+ */
34
+ export declare function printList<T>(io: IO, opts: {
35
+ json: boolean;
36
+ columns: Column<T>[];
37
+ }, page: {
38
+ data: T[];
39
+ has_more?: boolean;
40
+ next_cursor?: string | null;
41
+ }, raw?: unknown): void;
package/dist/output.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fmtTime = fmtTime;
4
+ exports.renderTable = renderTable;
5
+ exports.printJson = printJson;
6
+ exports.printList = printList;
7
+ /** Render a value as a table cell: null/undefined blank, arrays joined, objects JSON. */
8
+ function cell(value) {
9
+ if (value === null || value === undefined)
10
+ return '';
11
+ if (Array.isArray(value))
12
+ return value.map((v) => cell(v)).join(', ');
13
+ if (typeof value === 'object')
14
+ return JSON.stringify(value);
15
+ return String(value);
16
+ }
17
+ /**
18
+ * Epoch-millisecond timestamp → ISO-8601, the form every Atlas `*_at` field
19
+ * takes on the wire. Blank for null (e.g. a user who never signed in) so the
20
+ * column stays readable rather than printing `1970-...`.
21
+ */
22
+ function fmtTime(value) {
23
+ if (value === null || value === undefined)
24
+ return '';
25
+ const n = Number(value);
26
+ if (!Number.isFinite(n))
27
+ return '';
28
+ return new Date(n).toISOString();
29
+ }
30
+ /**
31
+ * Hand-rolled fixed-width table — the only "formatting library" this CLI has.
32
+ * Columns are padded to the widest cell (header included); a dashed rule sits
33
+ * under the header; trailing padding on the last column is trimmed so lines
34
+ * don't carry invisible whitespace. Empty input prints a friendly placeholder
35
+ * rather than a bare header with no rows.
36
+ */
37
+ function renderTable(columns, rows) {
38
+ if (rows.length === 0)
39
+ return '(no results)';
40
+ const matrix = rows.map((row) => columns.map((col) => cell(col.get(row))));
41
+ const widths = columns.map((col, i) => Math.max(col.header.length, ...matrix.map((r) => r[i].length)));
42
+ const pad = (text, width) => text.padEnd(width);
43
+ const line = (fields) => fields.map((f, i) => pad(f, widths[i])).join(' ').replace(/\s+$/, '');
44
+ const lines = [
45
+ line(columns.map((c) => c.header)),
46
+ line(widths.map((w) => '-'.repeat(w))),
47
+ ...matrix.map((r) => line(r)),
48
+ ];
49
+ return lines.join('\n');
50
+ }
51
+ /** Pretty-print any value as the `--json` output on stdout. */
52
+ function printJson(io, value) {
53
+ io.out(JSON.stringify(value, null, 2));
54
+ }
55
+ /**
56
+ * Print a cursor-paginated list as either raw JSON or a table, and — in table
57
+ * mode, when there is another page — a footer naming the exact flag to fetch
58
+ * it. Keeping the hint next to the data is what makes `--starting-after`
59
+ * discoverable without the user reading `--help`.
60
+ */
61
+ function printList(io, opts, page, raw = page) {
62
+ if (opts.json) {
63
+ printJson(io, raw);
64
+ return;
65
+ }
66
+ io.out(renderTable(opts.columns, page.data));
67
+ if (page.has_more && page.next_cursor) {
68
+ io.out('');
69
+ io.out(`More results — fetch the next page with: --starting-after ${page.next_cursor}`);
70
+ }
71
+ }
72
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":";;AA0BA,0BAKC;AASD,kCAkBC;AAGD,8BAEC;AAQD,8BAeC;AAzED,yFAAyF;AACzF,SAAS,IAAI,CAAC,KAAc;IAC1B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,C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,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The interactive input seam for `atlas login`. An interface (not a direct
3
+ * `readline` call) so tests script answers without a TTY, and so `secret()`
4
+ * can hide the key no matter where it's wired.
5
+ */
6
+ export interface Prompter {
7
+ /** A visible line of input, with an optional default shown in brackets. */
8
+ text(query: string, opts?: {
9
+ default?: string;
10
+ }): Promise<string>;
11
+ /** A hidden line of input — the terminal never echoes what's typed. */
12
+ secret(query: string): Promise<string>;
13
+ }
14
+ /** The real prompter, reading the TTY. Not exercised by unit tests (they inject). */
15
+ export declare function defaultPrompter(input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream): Prompter;
package/dist/prompt.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultPrompter = defaultPrompter;
4
+ const node_readline_1 = require("node:readline");
5
+ function ask(input, output, query) {
6
+ const rl = (0, node_readline_1.createInterface)({ input, output });
7
+ return new Promise((resolve) => {
8
+ rl.question(query, (answer) => {
9
+ rl.close();
10
+ resolve(answer);
11
+ });
12
+ });
13
+ }
14
+ /** The real prompter, reading the TTY. Not exercised by unit tests (they inject). */
15
+ function defaultPrompter(input = process.stdin, output = process.stdout) {
16
+ return {
17
+ async text(query, opts) {
18
+ const suffix = opts?.default ? ` [${opts.default}]` : '';
19
+ const answer = (await ask(input, output, `${query}${suffix}: `)).trim();
20
+ return answer || opts?.default || '';
21
+ },
22
+ secret(query) {
23
+ // Echo the prompt, then mute readline's output so the secret never lands
24
+ // on screen or in scrollback. `_writeToOutput` is readline's own hook;
25
+ // overriding it is the standard way to hide typed input.
26
+ return new Promise((resolve) => {
27
+ const rl = (0, node_readline_1.createInterface)({ input, output, terminal: true });
28
+ let muted = false;
29
+ const rlInternal = rl;
30
+ rlInternal._writeToOutput = (s) => {
31
+ if (!muted)
32
+ output.write(s);
33
+ };
34
+ output.write(`${query}: `);
35
+ muted = true;
36
+ rl.question('', (answer) => {
37
+ muted = false;
38
+ output.write('\n');
39
+ rl.close();
40
+ resolve(answer.trim());
41
+ });
42
+ });
43
+ },
44
+ };
45
+ }
46
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":";;AAyBA,0CAiCC;AA1DD,iDAAgD;AAchD,SAAS,GAAG,CAAC,KAA4B,EAAE,MAA6B,EAAE,KAAa;IACrF,MAAM,EAAE,GAAG,IAAA,+BAAe,EAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;QACrC,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE;YAC5B,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,qFAAqF;AACrF,SAAgB,eAAe,CAC7B,QAA+B,OAAO,CAAC,KAAK,EAC5C,SAAgC,OAAO,CAAC,MAAM;IAE9C,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI;YACpB,MAAM,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACzD,MAAM,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,MAAM,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACxE,OAAO,MAAM,IAAI,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC;QACvC,CAAC;QAED,MAAM,CAAC,KAAK;YACV,yEAAyE;YACzE,uEAAuE;YACvE,yDAAyD;YACzD,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;gBACrC,MAAM,EAAE,GAAG,IAAA,+BAAe,EAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC9D,IAAI,KAAK,GAAG,KAAK,CAAC;gBAClB,MAAM,UAAU,GAAG,EAAyD,CAAC;gBAC7E,UAAU,CAAC,cAAc,GAAG,CAAC,CAAS,EAAE,EAAE;oBACxC,IAAI,CAAC,KAAK;wBAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC9B,CAAC,CAAC;gBACF,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC;gBAC3B,KAAK,GAAG,IAAI,CAAC;gBACb,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE;oBACzB,KAAK,GAAG,KAAK,CAAC;oBACd,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBACnB,EAAE,CAAC,KAAK,EAAE,CAAC;oBACX,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;gBACzB,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/run.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { type ParsedArgs } from './args';
2
+ import type { RunContext } from './context';
3
+ /** A command handler: given the context and parsed args, do the work; return an exit code. */
4
+ export type Handler = (ctx: RunContext, args: ParsedArgs) => Promise<number>;
5
+ /**
6
+ * The CLI's whole control flow, as a pure function of (argv, context) → exit
7
+ * code. It NEVER calls `process.exit` and NEVER throws: the bin calls it and
8
+ * exits with what it returns, and every test drives this same path with a
9
+ * captured IO. All error reporting funnels through the one try/catch so a user
10
+ * sees a clean message and a non-zero code — never a stack trace.
11
+ */
12
+ export declare function run(argv: string[], ctx: RunContext): Promise<number>;
package/dist/run.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.run = run;
4
+ const backend_1 = require("@atlasauth/backend");
5
+ const args_1 = require("./args");
6
+ const api_keys_1 = require("./commands/api-keys");
7
+ const auth_1 = require("./commands/auth");
8
+ const orgs_1 = require("./commands/orgs");
9
+ const sessions_1 = require("./commands/sessions");
10
+ const users_1 = require("./commands/users");
11
+ const webhooks_1 = require("./commands/webhooks");
12
+ const errors_1 = require("./errors");
13
+ const help_1 = require("./help");
14
+ const version_1 = require("./version");
15
+ /** The command table — the single place every top-level command is registered. */
16
+ const COMMANDS = {
17
+ login: auth_1.login,
18
+ logout: auth_1.logout,
19
+ whoami: auth_1.whoami,
20
+ users: users_1.users,
21
+ orgs: orgs_1.orgs,
22
+ 'api-keys': api_keys_1.apiKeys,
23
+ webhooks: webhooks_1.webhooks,
24
+ sessions: sessions_1.sessions,
25
+ };
26
+ /**
27
+ * The CLI's whole control flow, as a pure function of (argv, context) → exit
28
+ * code. It NEVER calls `process.exit` and NEVER throws: the bin calls it and
29
+ * exits with what it returns, and every test drives this same path with a
30
+ * captured IO. All error reporting funnels through the one try/catch so a user
31
+ * sees a clean message and a non-zero code — never a stack trace.
32
+ */
33
+ async function run(argv, ctx) {
34
+ let args;
35
+ try {
36
+ args = (0, args_1.parse)(argv);
37
+ }
38
+ catch (err) {
39
+ return report(ctx, err);
40
+ }
41
+ // --version wins over everything, like most CLIs.
42
+ if (args.values.version) {
43
+ ctx.io.out((0, version_1.getVersion)());
44
+ return 0;
45
+ }
46
+ const command = args.positionals[0];
47
+ // Bare `atlas` or `atlas --help`: top-level help on stdout, success.
48
+ if (!command) {
49
+ ctx.io.out(help_1.TOP_HELP);
50
+ return 0;
51
+ }
52
+ const handler = COMMANDS[command];
53
+ if (!handler) {
54
+ ctx.io.err(`Unknown command '${command}'.`);
55
+ ctx.io.err("Run 'atlas --help' to see available commands.");
56
+ return 1;
57
+ }
58
+ // `atlas <command> --help`: command-specific help on stdout, success.
59
+ if (args.values.help) {
60
+ ctx.io.out(help_1.COMMAND_HELP[command] ?? help_1.TOP_HELP);
61
+ return 0;
62
+ }
63
+ try {
64
+ return await handler(ctx, args);
65
+ }
66
+ catch (err) {
67
+ return report(ctx, err);
68
+ }
69
+ }
70
+ /**
71
+ * Turn any thrown error into a clean stderr message + exit code. An
72
+ * {@link AtlasApiError} keeps its HTTP status and stable `code` so the user can
73
+ * act on it; a {@link CliError} carries its own code; anything else is an
74
+ * unexpected bug reported as its message (still no stack).
75
+ */
76
+ function report(ctx, err) {
77
+ if (err instanceof backend_1.AtlasApiError) {
78
+ const code = err.code ? ` [${err.code}]` : '';
79
+ ctx.io.err(`atlas: API error (HTTP ${err.status})${code}: ${err.message}`);
80
+ return 1;
81
+ }
82
+ if (err instanceof errors_1.CliError) {
83
+ ctx.io.err(`atlas: ${err.message}`);
84
+ return err.exitCode;
85
+ }
86
+ const message = err instanceof Error ? err.message : String(err);
87
+ ctx.io.err(`atlas: ${message}`);
88
+ return 1;
89
+ }
90
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;AAmCA,kBAwCC;AA3ED,gDAAmD;AACnD,iCAAgD;AAChD,kDAA8C;AAC9C,0CAAwD;AACxD,0CAAuC;AACvC,kDAA+C;AAC/C,4CAAyC;AACzC,kDAA+C;AAE/C,qCAAoC;AACpC,iCAAgD;AAChD,uCAAuC;AAKvC,kFAAkF;AAClF,MAAM,QAAQ,GAA4B;IACxC,KAAK,EAAL,YAAK;IACL,MAAM,EAAN,aAAM;IACN,MAAM,EAAN,aAAM;IACN,KAAK,EAAL,aAAK;IACL,IAAI,EAAJ,WAAI;IACJ,UAAU,EAAE,kBAAO;IACnB,QAAQ,EAAR,mBAAQ;IACR,QAAQ,EAAR,mBAAQ;CACT,CAAC;AAEF;;;;;;GAMG;AACI,KAAK,UAAU,GAAG,CAAC,IAAc,EAAE,GAAe;IACvD,IAAI,IA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AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,GAAe,EAAE,GAAY;IAC3C,IAAI,GAAG,YAAY,uBAAa,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9C,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,0BAA0B,GAAG,CAAC,MAAM,IAAI,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,GAAG,YAAY,iBAAQ,EAAE,CAAC;QAC5B,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACpC,OAAO,GAAG,CAAC,QAAQ,CAAC;IACtB,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;IAChC,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Read the package version from the shipped package.json at runtime rather than
3
+ * importing it — `src/` is the tsc rootDir, so a static `import ../package.json`
4
+ * would both break rootDir and bake a stale number into the bundle. At runtime
5
+ * `__dirname` is `dist/`, so `../package.json` is the real manifest beside it.
6
+ */
7
+ export declare function getVersion(): string;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVersion = getVersion;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ /**
7
+ * Read the package version from the shipped package.json at runtime rather than
8
+ * importing it — `src/` is the tsc rootDir, so a static `import ../package.json`
9
+ * would both break rootDir and bake a stale number into the bundle. At runtime
10
+ * `__dirname` is `dist/`, so `../package.json` is the real manifest beside it.
11
+ */
12
+ function getVersion() {
13
+ try {
14
+ const manifest = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'package.json'), 'utf8'));
15
+ return manifest.version ?? '0.0.0';
16
+ }
17
+ catch {
18
+ return '0.0.0';
19
+ }
20
+ }
21
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AASA,gCASC;AAlBD,qCAAuC;AACvC,yCAAiC;AAEjC;;;;;GAKG;AACH,SAAgB,UAAU;IACxB,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAEtF,CAAC;QACF,OAAO,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@atlasauth/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "atlas — manage an Atlas instance from the terminal via the Backend API.",
5
+ "bin": {
6
+ "atlas": "dist/cli.js"
7
+ },
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "dependencies": {
18
+ "@atlasauth/backend": "0.1.7"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^22.9.0",
22
+ "typescript": "^5.6.3",
23
+ "vitest": "^2.1.4"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md"
31
+ ],
32
+ "scripts": {
33
+ "build": "tsc -p tsconfig.build.json",
34
+ "typecheck": "tsc -p tsconfig.json --noEmit",
35
+ "test": "vitest run"
36
+ }
6
37
  }