@atlasauth/cli 0.2.0 → 0.4.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/dist/help.js CHANGED
@@ -17,10 +17,16 @@ Commands:
17
17
  users list|get|create|delete
18
18
  orgs list|get|members
19
19
  api-keys list|create|revoke
20
- webhooks list
20
+ webhooks list|create
21
21
  sessions revoke
22
22
  config export|import Config-as-code: round-trip the instance's config
23
23
  actions list|deploy|test|logs
24
+ init Create or complete an app's setup (idempotent); secrets to 0600 files
25
+ preflight Check an instance's setup; non-zero exit on errors (for CI)
26
+ env Print deploy variables: public values + secret file paths
27
+ client rotate Rotate an OAuth client secret straight into its file
28
+ referrals connect|backfill|status
29
+ Connect a referral platform, backfill, check the connection
24
30
 
25
31
  Global options:
26
32
  --profile <name> Use a named profile (default: active, else "default")
@@ -33,10 +39,47 @@ Global options:
33
39
  Environment overrides:
34
40
  ATLAS_SECRET_KEY Secret key to use instead of the stored one
35
41
  ATLAS_API_URL API URL to use instead of the stored one
42
+ ATLAS_PLATFORM_KEY Platform key (psk_) for atlas init
43
+ REFERALLY_BASE_URL Referally base URL for atlas referrals connect
44
+ REFERALLY_API_KEY Referally merchant key for atlas referrals connect (never stored)
45
+
46
+ Secrets: a command that receives a secret writes it to a 0600 file under
47
+ ~/.config/<product>/ and prints only the path. --print-secret prints it instead.
36
48
 
37
49
  Run 'atlas <command> --help' for command-specific help.`;
38
50
  /** Per-command help, keyed by the resource word. */
39
51
  exports.COMMAND_HELP = {
52
+ referrals: `atlas referrals — referral attribution
53
+
54
+ Usage:
55
+ atlas referrals connect --provider referally --program <prg_…> --base-url <url>
56
+ [--referally-key-file <path|-> | --referally-key <rk_…>]
57
+ [--auto-enroll] [--destination <url>] [--tracking-token <token>] [--enable]
58
+ atlas referrals connect --provider webhook --endpoint <https-url>
59
+ [--secret-file <path|->] [--program <id>] [--auto-enroll] [--enable]
60
+ atlas referrals backfill --since <YYYY-MM-DD> [--map <file.csv>]
61
+ [--metadata-path public_metadata.referral_code] [--wait]
62
+ atlas referrals status
63
+
64
+ connect --provider referally creates the Atlas connection on Referally with
65
+ your merchant key (bring your own key: used for this one call, never stored or
66
+ printed), saves the connection id and secret on the instance, and runs a ping.
67
+ --auto-enroll and --destination are passed to Referally. --enable turns
68
+ referrals on when the ping passes. Prefer --referally-key-file (or
69
+ REFERALLY_API_KEY) to --referally-key: a key on the command line can end up in
70
+ your shell history.
71
+
72
+ connect --provider webhook points the instance at a platform that speaks the
73
+ Atlas referral protocol. Without --secret-file, a signing secret is generated
74
+ and written to a 0600 file for you to configure on the platform.
75
+
76
+ backfill reports users who signed up since the date, with their real sign-up
77
+ time. --map reads customerRef,code lines; --metadata-path reads a stored code.
78
+
79
+ status prints the connection, its health and the referral preflight findings;
80
+ it exits 1 when one is an error.
81
+
82
+ All subcommands take --instance <id> or --product <name> like preflight.`,
40
83
  login: `atlas login — authenticate and store a profile credential
41
84
 
42
85
  Usage: atlas login [--profile <name>] [--url <api-url>] [--secret-key <sk_...>]
@@ -67,12 +110,69 @@ Usage:
67
110
 
68
111
  Usage:
69
112
  atlas api-keys list [--subject-type <user|organization>] [--subject-id <id>] [--json]
70
- atlas api-keys create --subject-type <user|organization> --subject-id <id> [--name <n>] [--json]
113
+ atlas api-keys create --subject-type <user|organization> --subject-id <id> [--name <n>]
114
+ [--product <name>] [--force] [--print-secret] [--json]
71
115
  atlas api-keys revoke <api-key-id> [--json]`,
72
- webhooks: `atlas webhooks — inspect webhook endpoints
116
+ webhooks: `atlas webhooks — manage webhook endpoints
117
+
118
+ Usage:
119
+ atlas webhooks list [--json]
120
+ atlas webhooks create --url <https-url> [--events a,b] [--product <name>] [--print-secret] [--json]
121
+
122
+ create writes the signing secret to a 0600 file and prints only its path.`,
123
+ init: `atlas init — create or complete an app's setup, idempotently
73
124
 
74
125
  Usage:
75
- atlas webhooks list [--json]`,
126
+ atlas init --product <name> [--domain <domain>] [--auth-host <host>]
127
+ [--instance-env development|production] [--name <app-name>]
128
+ [--strategies password,email_code,...]
129
+ [--email managed|development|none] [--email-from <address>]
130
+ [--email-provider resend|brevo --email-key-file <path|->]
131
+ [--client-redirect <url>]... [--webhook-url <url>]
132
+ [--yes] [--force] [--rotate-secret] [--json]
133
+
134
+ Needs a platform key (ATLAS_PLATFORM_KEY, or a psk_ profile from atlas login).
135
+ Finds the app by name and environment, or creates it, then sets strategies, the
136
+ email sender, the custom domain (auth.<domain> unless --auth-host; prints the
137
+ CNAME), a first-party OAuth client and a webhook. Re-running only fills what is
138
+ missing.
139
+
140
+ Email always goes through YOUR provider account (Atlas lends none):
141
+ managed Atlas sets your domain up on your Resend or Brevo account and
142
+ prints the DNS records.
143
+ development development instances only: your provider without a verified
144
+ domain (Resend's onboarding@resend.dev by default), capped.
145
+ The key is read from --email-key-file (a file holding the key or KEY=value; '-'
146
+ reads stdin). It is never taken from argv and never printed.
147
+
148
+ Every secret goes to ~/.config/<product>/<env>*.env (dir 0700, files 0600) and
149
+ is never printed. An existing file is never overwritten without --force.
150
+ --rotate-secret mints a new secret key when the app exists but its file is gone.
151
+ Public values and file paths are kept in ~/.config/<product>/atlas.json.`,
152
+ preflight: `atlas preflight — check an instance's setup (a CI / deploy gate)
153
+
154
+ Usage: atlas preflight [--instance <id> | --product <name> [--instance-env <env>]]
155
+ [--fail-on error|warning] [--json]
156
+
157
+ Prints every finding (severity, code, message, fix). Exits 1 when there is an
158
+ error, or with --fail-on warning also on a warning.`,
159
+ env: `atlas env — print deploy variables without secrets
160
+
161
+ Usage: atlas env --product <name> [--instance-env <env>] [--format dotenv|coolify|vercel] [--json]
162
+
163
+ Public values (publishable key, Frontend API, issuer, discovery and JWKS URLs,
164
+ OAuth client id) are printed as-is. Secrets are printed as references to their
165
+ 0600 files: *_FILE=<path> (dotenv), KEY=@<path> (coolify), or a vercel env add
166
+ command that pipes the value from the file (vercel).`,
167
+ client: `atlas client — OAuth clients
168
+
169
+ Usage: atlas client rotate <client-id> [--now | --overlap <seconds>]
170
+ [--instance <id> | --product <name> [--instance-env <env>]]
171
+ [--print-secret]
172
+
173
+ Rotates the client secret and writes the new one straight to its 0600 file.
174
+ --now revokes the old secret immediately; --overlap keeps it working for that
175
+ many seconds. Prints when the old secret stops working.`,
76
176
  sessions: `atlas sessions — manage sessions
77
177
 
78
178
  Usage:
package/dist/help.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEU,QAAA,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDA4BgC,CAAC;AAEzD,oDAAoD;AACvC,QAAA,YAAY,GAA2B;IAClD,KAAK,EAAE;;;;;;mCAM0B;IAEjC,MAAM,EAAE;;uCAE6B;IAErC,MAAM,EAAE;;gDAEsC;IAE9C,KAAK,EAAE;;;;;;wCAM+B;IAEtC,IAAI,EAAE;;;;;uCAK+B;IAErC,UAAU,EAAE;;;;;8CAKgC;IAE5C,QAAQ,EAAE;;;+BAGmB;IAE7B,QAAQ,EAAE;;;8CAGkC;IAE5C,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;8EAoBoE;IAC5E,OAAO,EAAE;;;;;;;;;;;gFAWqE;CAC/E,CAAC"}
1
+ {"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEU,QAAA,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDAwCgC,CAAC;AAEzD,oDAAoD;AACvC,QAAA,YAAY,GAA2B;IAClD,SAAS,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yEA8B4D;IAEvE,KAAK,EAAE;;;;;;mCAM0B;IAEjC,MAAM,EAAE;;uCAE6B;IAErC,MAAM,EAAE;;gDAEsC;IAE9C,KAAK,EAAE;;;;;;wCAM+B;IAEtC,IAAI,EAAE;;;;;uCAK+B;IAErC,UAAU,EAAE;;;;;;8CAMgC;IAE5C,QAAQ,EAAE;;;;;;0EAM8D;IAExE,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;yEA4BiE;IAEvE,SAAS,EAAE;;;;;;oDAMuC;IAElD,GAAG,EAAE;;;;;;;qDAO8C;IAEnD,MAAM,EAAE;;;;;;;;wDAQ8C;IAEtD,QAAQ,EAAE;;;8CAGkC;IAE5C,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;8EAoBoE;IAC5E,OAAO,EAAE;;;;;;;;;;;gFAWqE;CAC/E,CAAC"}
package/dist/index.d.ts CHANGED
@@ -20,3 +20,8 @@ export { webhooks } from './commands/webhooks';
20
20
  export { sessions } from './commands/sessions';
21
21
  export { config } from './commands/config';
22
22
  export { actions } from './commands/actions';
23
+ export { init } from './commands/init';
24
+ export { preflight, envCommand, client } from './commands/project-commands';
25
+ export { referrals } from './commands/referrals';
26
+ export { writeSecretFile, readEnvFile, parseDotenv, renderDotenv, productDir, deliverSecret, } from './secrets';
27
+ export { readManifest, writeManifest, manifestPath, type ProjectManifest, type ProjectInstance, type InstanceEnv, } from './project';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.actions = exports.config = exports.sessions = exports.webhooks = exports.apiKeys = exports.orgs = exports.users = exports.whoami = exports.logout = exports.login = exports.getVersion = exports.defaultPrompter = exports.defaultConfigPath = exports.MemoryConfigStore = exports.FileConfigStore = exports.captureIO = exports.defaultIO = exports.CliError = exports.isNotFound = exports.createConfigHttp = exports.defaultContext = exports.run = void 0;
3
+ exports.manifestPath = exports.writeManifest = exports.readManifest = exports.deliverSecret = exports.productDir = exports.renderDotenv = exports.parseDotenv = exports.readEnvFile = exports.writeSecretFile = exports.referrals = exports.client = exports.envCommand = exports.preflight = exports.init = exports.actions = exports.config = exports.sessions = exports.webhooks = exports.apiKeys = exports.orgs = exports.users = exports.whoami = exports.logout = exports.login = exports.getVersion = exports.defaultPrompter = exports.defaultConfigPath = exports.MemoryConfigStore = exports.FileConfigStore = exports.captureIO = exports.defaultIO = exports.CliError = exports.isNotFound = exports.createConfigHttp = exports.defaultContext = exports.run = void 0;
4
4
  /**
5
5
  * Library surface of `@atlasauth/cli`. The package ships a bin (`atlas`), but
6
6
  * exporting the pieces lets the handlers be unit-tested with injected deps and
@@ -46,4 +46,23 @@ var config_2 = require("./commands/config");
46
46
  Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_2.config; } });
47
47
  var actions_1 = require("./commands/actions");
48
48
  Object.defineProperty(exports, "actions", { enumerable: true, get: function () { return actions_1.actions; } });
49
+ var init_1 = require("./commands/init");
50
+ Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_1.init; } });
51
+ var project_commands_1 = require("./commands/project-commands");
52
+ Object.defineProperty(exports, "preflight", { enumerable: true, get: function () { return project_commands_1.preflight; } });
53
+ Object.defineProperty(exports, "envCommand", { enumerable: true, get: function () { return project_commands_1.envCommand; } });
54
+ Object.defineProperty(exports, "client", { enumerable: true, get: function () { return project_commands_1.client; } });
55
+ var referrals_1 = require("./commands/referrals");
56
+ Object.defineProperty(exports, "referrals", { enumerable: true, get: function () { return referrals_1.referrals; } });
57
+ var secrets_1 = require("./secrets");
58
+ Object.defineProperty(exports, "writeSecretFile", { enumerable: true, get: function () { return secrets_1.writeSecretFile; } });
59
+ Object.defineProperty(exports, "readEnvFile", { enumerable: true, get: function () { return secrets_1.readEnvFile; } });
60
+ Object.defineProperty(exports, "parseDotenv", { enumerable: true, get: function () { return secrets_1.parseDotenv; } });
61
+ Object.defineProperty(exports, "renderDotenv", { enumerable: true, get: function () { return secrets_1.renderDotenv; } });
62
+ Object.defineProperty(exports, "productDir", { enumerable: true, get: function () { return secrets_1.productDir; } });
63
+ Object.defineProperty(exports, "deliverSecret", { enumerable: true, get: function () { return secrets_1.deliverSecret; } });
64
+ var project_1 = require("./project");
65
+ Object.defineProperty(exports, "readManifest", { enumerable: true, get: function () { return project_1.readManifest; } });
66
+ Object.defineProperty(exports, "writeManifest", { enumerable: true, get: function () { return project_1.writeManifest; } });
67
+ Object.defineProperty(exports, "manifestPath", { enumerable: true, get: function () { return project_1.manifestPath; } });
49
68
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,6BAA0C;AAAjC,0FAAA,GAAG,OAAA;AACZ,qCAAmF;AAA1E,yGAAA,cAAc,OAAA;AACvB,6CAA8E;AAArE,+GAAA,gBAAgB,OAAA;AAAE,yGAAA,UAAU,OAAA;AACrC,mCAAoC;AAA3B,kGAAA,QAAQ,OAAA;AACjB,2BAAqE;AAA5D,+FAAA,SAAS,OAAA;AAAE,+FAAA,SAAS,OAAA;AAC7B,mCAOkB;AANhB,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,2GAAA,iBAAiB,OAAA;AAKnB,mCAA0D;AAAjD,yGAAA,eAAe,OAAA;AACxB,qCAAuC;AAA9B,qGAAA,UAAU,OAAA;AAEnB,0EAA0E;AAC1E,wCAAwD;AAA/C,6FAAA,KAAK,OAAA;AAAE,8FAAA,MAAM,OAAA;AAAE,8FAAA,MAAM,OAAA;AAC9B,0CAAyC;AAAhC,8FAAA,KAAK,OAAA;AACd,wCAAuC;AAA9B,4FAAA,IAAI,OAAA;AACb,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAChB,gDAA+C;AAAtC,oGAAA,QAAQ,OAAA;AACjB,gDAA+C;AAAtC,oGAAA,QAAQ,OAAA;AACjB,4CAA2C;AAAlC,gGAAA,MAAM,OAAA;AACf,8CAA6C;AAApC,kGAAA,OAAO,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,6BAA0C;AAAjC,0FAAA,GAAG,OAAA;AACZ,qCAA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igHttp } from './config-http';
2
+ import type { RunContext } from './context';
3
+ /**
4
+ * The project manifest `atlas init` keeps at `~/.config/<product>/atlas.json`:
5
+ * PUBLIC values only (ids, publishable key, hosts, redirect URIs) plus the path
6
+ * of each secret file. `atlas env`, `atlas preflight --instance` and
7
+ * `atlas client rotate` read it, so they know where a secret lives without
8
+ * ever holding it in the manifest.
9
+ */
10
+ export type InstanceEnv = 'development' | 'production';
11
+ export interface ProjectInstance {
12
+ instance_id: string;
13
+ environment: InstanceEnv;
14
+ publishable_key: string;
15
+ frontend_api_host: string | null;
16
+ issuer: string | null;
17
+ discovery_url: string | null;
18
+ jwks_uri: string | null;
19
+ /** The file holding ATLAS_SECRET_KEY. */
20
+ secret_file: string;
21
+ oauth_client?: {
22
+ id: string;
23
+ client_id: string;
24
+ redirect_uris: string[];
25
+ secret_file: string | null;
26
+ };
27
+ webhook?: {
28
+ id: string;
29
+ url: string;
30
+ secret_file: string | null;
31
+ };
32
+ custom_domain?: {
33
+ host: string;
34
+ cname_target: string | null;
35
+ status: string;
36
+ };
37
+ email?: {
38
+ mode: 'managed' | 'development' | 'none';
39
+ from_address?: string | null;
40
+ };
41
+ }
42
+ export interface ProjectManifest {
43
+ product: string;
44
+ api_url: string;
45
+ instances: Partial<Record<InstanceEnv, ProjectInstance>>;
46
+ }
47
+ export declare const MANIFEST_FILE = "atlas.json";
48
+ export declare function manifestPath(env: NodeJS.ProcessEnv, product: string): string;
49
+ export declare function readManifest(env: NodeJS.ProcessEnv, product: string): ProjectManifest | undefined;
50
+ export declare function writeManifest(env: NodeJS.ProcessEnv, manifest: ProjectManifest): string;
51
+ /** Find the project + instance an instance id belongs to, scanning every product directory. */
52
+ export declare function findInstance(env: NodeJS.ProcessEnv, instanceId: string, product?: string): {
53
+ manifest: ProjectManifest;
54
+ instance: ProjectInstance;
55
+ } | undefined;
56
+ export declare function parseInstanceEnv(raw: string | undefined, fallback: InstanceEnv): InstanceEnv;
57
+ /** The raw HTTP client for a credential (the context's, or the real one). */
58
+ export declare function httpFor(ctx: RunContext, opts: {
59
+ secretKey: string;
60
+ apiUrl: string;
61
+ }): ConfigHttp;
62
+ /** Read the instance secret key from the project's secret file. */
63
+ export declare function instanceSecretFromFile(instance: ProjectInstance): string;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MANIFEST_FILE = void 0;
4
+ exports.manifestPath = manifestPath;
5
+ exports.readManifest = readManifest;
6
+ exports.writeManifest = writeManifest;
7
+ exports.findInstance = findInstance;
8
+ exports.parseInstanceEnv = parseInstanceEnv;
9
+ exports.httpFor = httpFor;
10
+ exports.instanceSecretFromFile = instanceSecretFromFile;
11
+ const node_fs_1 = require("node:fs");
12
+ const node_os_1 = require("node:os");
13
+ const node_path_1 = require("node:path");
14
+ const config_http_1 = require("./config-http");
15
+ const errors_1 = require("./errors");
16
+ const secrets_1 = require("./secrets");
17
+ exports.MANIFEST_FILE = 'atlas.json';
18
+ function manifestPath(env, product) {
19
+ return (0, node_path_1.join)((0, secrets_1.productDir)(env, product), exports.MANIFEST_FILE);
20
+ }
21
+ function readManifest(env, product) {
22
+ try {
23
+ return JSON.parse((0, node_fs_1.readFileSync)(manifestPath(env, product), 'utf8'));
24
+ }
25
+ catch {
26
+ return undefined;
27
+ }
28
+ }
29
+ function writeManifest(env, manifest) {
30
+ const dir = (0, secrets_1.productDir)(env, manifest.product);
31
+ (0, node_fs_1.mkdirSync)(dir, { recursive: true, mode: 0o700 });
32
+ const path = (0, node_path_1.join)(dir, exports.MANIFEST_FILE);
33
+ (0, node_fs_1.writeFileSync)(path, JSON.stringify(manifest, null, 2) + '\n', { mode: 0o600 });
34
+ (0, node_fs_1.chmodSync)(path, 0o600);
35
+ return path;
36
+ }
37
+ /** Find the project + instance an instance id belongs to, scanning every product directory. */
38
+ function findInstance(env, instanceId, product) {
39
+ const products = product ? [product] : listProducts(env);
40
+ for (const p of products) {
41
+ const m = readManifest(env, p);
42
+ for (const inst of Object.values(m?.instances ?? {})) {
43
+ if (inst && inst.instance_id === instanceId)
44
+ return { manifest: m, instance: inst };
45
+ }
46
+ }
47
+ return undefined;
48
+ }
49
+ function listProducts(env) {
50
+ const base = env.XDG_CONFIG_HOME?.trim() || (0, node_path_1.join)(env.HOME?.trim() || (0, node_os_1.homedir)(), '.config');
51
+ try {
52
+ return (0, node_fs_1.readdirSync)(base).filter((d) => {
53
+ try {
54
+ (0, node_fs_1.readFileSync)((0, node_path_1.join)(base, d, exports.MANIFEST_FILE));
55
+ return true;
56
+ }
57
+ catch {
58
+ return false;
59
+ }
60
+ });
61
+ }
62
+ catch {
63
+ return [];
64
+ }
65
+ }
66
+ function parseInstanceEnv(raw, fallback) {
67
+ if (raw === undefined)
68
+ return fallback;
69
+ if (raw !== 'development' && raw !== 'production') {
70
+ throw new errors_1.CliError(`--instance-env must be development or production, got '${raw}'.`);
71
+ }
72
+ return raw;
73
+ }
74
+ /** The raw HTTP client for a credential (the context's, or the real one). */
75
+ function httpFor(ctx, opts) {
76
+ return (ctx.makeHttp ?? config_http_1.createConfigHttp)(opts);
77
+ }
78
+ /** Read the instance secret key from the project's secret file. */
79
+ function instanceSecretFromFile(instance) {
80
+ const key = (0, secrets_1.readEnvFile)(instance.secret_file)?.ATLAS_SECRET_KEY;
81
+ if (!key) {
82
+ throw new errors_1.CliError(`No ATLAS_SECRET_KEY in ${instance.secret_file}. Re-run 'atlas init' with --rotate-secret to mint a new one.`);
83
+ }
84
+ return key;
85
+ }
86
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":";;;AA0CA,oCAEC;AAED,oCAMC;AAED,sCAOC;AAGD,oCAaC;AAkBD,4CAMC;AAGD,0BAEC;AAGD,wDAQC;AArHD,qCAAyF;AACzF,qCAAkC;AAClC,yCAAiC;AACjC,+CAAkE;AAElE,qCAAoC;AACpC,uCAAoD;AAkCvC,QAAA,aAAa,GA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C;AACb,CAAC;AAED,6EAA6E;AAC7E,SAAgB,OAAO,CAAC,GAAe,EAAE,IAA2C;IAClF,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,8BAAgB,CAAC,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC;AAED,mEAAmE;AACnE,SAAgB,sBAAsB,CAAC,QAAyB;IAC9D,MAAM,GAAG,GAAG,IAAA,qBAAW,EAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAChE,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,iBAAQ,CAChB,0BAA0B,QAAQ,CAAC,WAAW,+DAA+D,CAC9G,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/dist/run.js CHANGED
@@ -7,7 +7,10 @@ const actions_1 = require("./commands/actions");
7
7
  const api_keys_1 = require("./commands/api-keys");
8
8
  const auth_1 = require("./commands/auth");
9
9
  const config_1 = require("./commands/config");
10
+ const init_1 = require("./commands/init");
11
+ const project_commands_1 = require("./commands/project-commands");
10
12
  const orgs_1 = require("./commands/orgs");
13
+ const referrals_1 = require("./commands/referrals");
11
14
  const sessions_1 = require("./commands/sessions");
12
15
  const users_1 = require("./commands/users");
13
16
  const webhooks_1 = require("./commands/webhooks");
@@ -26,6 +29,11 @@ const COMMANDS = {
26
29
  sessions: sessions_1.sessions,
27
30
  config: config_1.config,
28
31
  actions: actions_1.actions,
32
+ init: init_1.init,
33
+ preflight: project_commands_1.preflight,
34
+ env: project_commands_1.envCommand,
35
+ client: project_commands_1.client,
36
+ referrals: referrals_1.referrals,
29
37
  };
30
38
  /**
31
39
  * The CLI's whole control flow, as a pure function of (argv, context) → exit
package/dist/run.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;AAuCA,kBAwCC;AA/ED,gDAAmD;AACnD,iCAAgD;AAChD,gDAA6C;AAC7C,kDAA8C;AAC9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E,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,41 @@
1
+ import type { IO } from './io';
2
+ export declare function assertProductName(product: string): string;
3
+ /** `$XDG_CONFIG_HOME/<product>` (default `~/.config/<product>`). */
4
+ export declare function productDir(env: NodeJS.ProcessEnv, product: string): string;
5
+ export declare function renderDotenv(entries: Record<string, string>, comment?: string): string;
6
+ /** Parse a dotenv file this CLI wrote (KEY=value lines, `#` comments). */
7
+ export declare function parseDotenv(text: string): Record<string, string>;
8
+ /**
9
+ * Write a 0600 dotenv file inside a 0700 directory. Refuses an existing file
10
+ * unless `force` (the same content is not a conflict: a re-run is a no-op).
11
+ * Returns the path.
12
+ */
13
+ export declare function writeSecretFile(dir: string, fileName: string, entries: Record<string, string>, opts?: {
14
+ force?: boolean;
15
+ comment?: string;
16
+ }): {
17
+ path: string;
18
+ written: boolean;
19
+ };
20
+ /** Read one of the CLI's env files, or undefined when it does not exist. */
21
+ export declare function readEnvFile(path: string): Record<string, string> | undefined;
22
+ /** The env files in a product directory (for `atlas env`). */
23
+ export declare function listEnvFiles(dir: string): string[];
24
+ /**
25
+ * The common "a secret arrived" path for single-secret commands: write it to
26
+ * `<dir>/<fileName>` (0600) and print the path, or — only with
27
+ * `--print-secret` — print it after a warning on stderr.
28
+ */
29
+ export declare function deliverSecret(input: {
30
+ io: IO;
31
+ env: NodeJS.ProcessEnv;
32
+ product: string;
33
+ fileName: string;
34
+ entries: Record<string, string>;
35
+ label: string;
36
+ printSecret?: boolean;
37
+ force?: boolean;
38
+ comment?: string;
39
+ }): {
40
+ path?: string;
41
+ };
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertProductName = assertProductName;
4
+ exports.productDir = productDir;
5
+ exports.renderDotenv = renderDotenv;
6
+ exports.parseDotenv = parseDotenv;
7
+ exports.writeSecretFile = writeSecretFile;
8
+ exports.readEnvFile = readEnvFile;
9
+ exports.listEnvFiles = listEnvFiles;
10
+ exports.deliverSecret = deliverSecret;
11
+ const node_fs_1 = require("node:fs");
12
+ const node_os_1 = require("node:os");
13
+ const node_path_1 = require("node:path");
14
+ const errors_1 = require("./errors");
15
+ /**
16
+ * Secrets the CLI receives are written to disk, never printed.
17
+ *
18
+ * Every command that gets a secret back from the API (an instance secret key,
19
+ * an OAuth client secret, a webhook signing secret, an end-user API key) writes
20
+ * it to a dotenv file under `~/.config/<product>/` — directory 0700, file 0600 —
21
+ * and prints only the file path. `--print-secret` is the one explicit opt-out,
22
+ * and it prints a warning first. An existing file is never overwritten unless
23
+ * the command was given `--force`, so a re-run cannot silently destroy the only
24
+ * copy of a working secret.
25
+ *
26
+ * The product name doubles as the directory name, so it is restricted to a safe
27
+ * slug (no path separators, no dot-dot).
28
+ */
29
+ const PRODUCT_RE = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
30
+ function assertProductName(product) {
31
+ if (!PRODUCT_RE.test(product)) {
32
+ throw new errors_1.CliError(`--product must be letters, digits, '-' or '_' (up to 63 characters), got '${product}'.`);
33
+ }
34
+ return product;
35
+ }
36
+ /** `$XDG_CONFIG_HOME/<product>` (default `~/.config/<product>`). */
37
+ function productDir(env, product) {
38
+ const base = env.XDG_CONFIG_HOME?.trim() || (0, node_path_1.join)(env.HOME?.trim() || (0, node_os_1.homedir)(), '.config');
39
+ return (0, node_path_1.join)(base, assertProductName(product));
40
+ }
41
+ /** Quote a dotenv value when it needs it. Secrets are token-shaped, so this is rarely used. */
42
+ function dotenvValue(v) {
43
+ return /^[A-Za-z0-9_./:@+=,-]*$/.test(v) ? v : JSON.stringify(v);
44
+ }
45
+ function renderDotenv(entries, comment) {
46
+ const lines = comment ? comment.split('\n').map((l) => `# ${l}`) : [];
47
+ for (const [k, v] of Object.entries(entries))
48
+ lines.push(`${k}=${dotenvValue(v)}`);
49
+ return lines.join('\n') + '\n';
50
+ }
51
+ /** Parse a dotenv file this CLI wrote (KEY=value lines, `#` comments). */
52
+ function parseDotenv(text) {
53
+ const out = {};
54
+ for (const raw of text.split(/\r?\n/)) {
55
+ const line = raw.trim();
56
+ if (!line || line.startsWith('#'))
57
+ continue;
58
+ const i = line.indexOf('=');
59
+ if (i < 1)
60
+ continue;
61
+ const key = line.slice(0, i).trim();
62
+ let value = line.slice(i + 1).trim();
63
+ if (value.startsWith('"') && value.endsWith('"')) {
64
+ try {
65
+ value = JSON.parse(value);
66
+ }
67
+ catch {
68
+ /* keep raw */
69
+ }
70
+ }
71
+ out[key] = value;
72
+ }
73
+ return out;
74
+ }
75
+ /**
76
+ * Write a 0600 dotenv file inside a 0700 directory. Refuses an existing file
77
+ * unless `force` (the same content is not a conflict: a re-run is a no-op).
78
+ * Returns the path.
79
+ */
80
+ function writeSecretFile(dir, fileName, entries, opts = {}) {
81
+ if (fileName.includes('/') || fileName.includes('\\') || fileName.startsWith('.')) {
82
+ throw new errors_1.CliError(`Refusing to write a secret file named '${fileName}'.`);
83
+ }
84
+ const path = (0, node_path_1.join)(dir, fileName);
85
+ const content = renderDotenv(entries, opts.comment);
86
+ (0, node_fs_1.mkdirSync)(dir, { recursive: true, mode: 0o700 });
87
+ (0, node_fs_1.chmodSync)(dir, 0o700);
88
+ if ((0, node_fs_1.existsSync)(path)) {
89
+ const current = (0, node_fs_1.readFileSync)(path, 'utf8');
90
+ if (current === content) {
91
+ (0, node_fs_1.chmodSync)(path, 0o600);
92
+ return { path, written: false };
93
+ }
94
+ if (!opts.force) {
95
+ throw new errors_1.CliError(`${path} already exists and holds a different secret. Nothing was overwritten. Move it aside, or re-run with --force to replace it.`);
96
+ }
97
+ }
98
+ // Write THEN chmod: `mode` is masked by umask and ignored for an existing file.
99
+ (0, node_fs_1.writeFileSync)(path, content, { mode: 0o600 });
100
+ (0, node_fs_1.chmodSync)(path, 0o600);
101
+ return { path, written: true };
102
+ }
103
+ /** Read one of the CLI's env files, or undefined when it does not exist. */
104
+ function readEnvFile(path) {
105
+ try {
106
+ return parseDotenv((0, node_fs_1.readFileSync)(path, 'utf8'));
107
+ }
108
+ catch {
109
+ return undefined;
110
+ }
111
+ }
112
+ /** The env files in a product directory (for `atlas env`). */
113
+ function listEnvFiles(dir) {
114
+ try {
115
+ return (0, node_fs_1.readdirSync)(dir)
116
+ .filter((f) => f.endsWith('.env'))
117
+ .sort();
118
+ }
119
+ catch {
120
+ return [];
121
+ }
122
+ }
123
+ /**
124
+ * The common "a secret arrived" path for single-secret commands: write it to
125
+ * `<dir>/<fileName>` (0600) and print the path, or — only with
126
+ * `--print-secret` — print it after a warning on stderr.
127
+ */
128
+ function deliverSecret(input) {
129
+ if (input.printSecret) {
130
+ input.io.err(`atlas: warning: printing ${input.label} because --print-secret was given. It may end up in your shell history, terminal scrollback or CI logs.`);
131
+ for (const [k, v] of Object.entries(input.entries))
132
+ input.io.out(`${k}=${v}`);
133
+ return {};
134
+ }
135
+ const { path } = writeSecretFile(productDir(input.env, input.product), input.fileName, input.entries, {
136
+ force: input.force,
137
+ comment: input.comment,
138
+ });
139
+ input.io.out(`${input.label} written to ${path} (mode 0600).`);
140
+ return { path };
141
+ }
142
+ //# sourceMappingURL=secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":";;AAuBA,8CAOC;AAGD,gCAGC;AAOD,oCAIC;AAGD,kCAmBC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AAE,CAAC;AAClB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlasauth/cli",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "atlas — manage an Atlas instance from the terminal via the Backend API.",
5
5
  "bin": {
6
6
  "atlas": "dist/cli.js"
@@ -15,8 +15,8 @@
15
15
  "./package.json": "./package.json"
16
16
  },
17
17
  "dependencies": {
18
- "@atlasauth/backend": "0.3.0",
19
- "@atlasauth/actions": "0.1.0"
18
+ "@atlasauth/actions": "0.1.1",
19
+ "@atlasauth/backend": "0.12.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.9.0",
@@ -28,7 +28,8 @@
28
28
  },
29
29
  "files": [
30
30
  "dist",
31
- "README.md"
31
+ "README.md",
32
+ "CHANGELOG.md"
32
33
  ],
33
34
  "scripts": {
34
35
  "build": "tsc -p tsconfig.build.json",