@fluid-app/fluid-cli 0.1.65 → 0.1.66

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-app/fluid-cli",
3
- "version": "0.1.65",
3
+ "version": "0.1.66",
4
4
  "description": "Core CLI for Fluid Commerce — auth, config, and plugin system",
5
5
  "bin": {
6
6
  "fluid": "./dist/bin/fluid.mjs"
@@ -23,6 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
+ "@napi-rs/keyring": "^2.1.0",
26
27
  "chalk": "^5.3.0",
27
28
  "commander": "^12.0.0",
28
29
  "ora": "^8.0.0",
@@ -30,6 +31,7 @@
30
31
  },
31
32
  "devDependencies": {
32
33
  "@fluid-app/api-client-core": "0.1.0",
34
+ "@fluid-app/auth": "0.1.0",
33
35
  "@fluid-app/typescript-config": "0.0.0",
34
36
  "@types/node": "24.10.12",
35
37
  "@types/prompts": "^2.4.9",
@@ -1,624 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
2
- import { randomBytes } from "node:crypto";
3
- import { dirname, join } from "node:path";
4
- import { homedir } from "node:os";
5
- //#region src/catalog/annotations.ts
6
- const ANNOTATION = Symbol.for("@fluid-app/fluid-cli.command-annotation");
7
- /**
8
- * Record the endpoints a command calls and whether it writes, so
9
- * `fluid commands --json` can list them. Returns the command for chaining.
10
- */
11
- function describeCommand(command, annotation) {
12
- const target = command;
13
- target[ANNOTATION] = {
14
- ...target[ANNOTATION],
15
- ...annotation
16
- };
17
- return command;
18
- }
19
- function readAnnotation(command) {
20
- return command[ANNOTATION] ?? null;
21
- }
22
- //#endregion
23
- //#region src/catalog/walk.ts
24
- function isHidden(command) {
25
- return command._hidden === true;
26
- }
27
- function isRunnable(command) {
28
- return command._actionHandler != null;
29
- }
30
- function visibleSubcommands(command) {
31
- return command.commands.filter((sub) => !isHidden(sub));
32
- }
33
- function visibleOptions(command) {
34
- return command.options.filter((option) => !option.hidden);
35
- }
36
- function describeOption(option) {
37
- return {
38
- flags: option.flags,
39
- long: option.long ?? null,
40
- short: option.short ?? null,
41
- description: option.description,
42
- takesValue: option.required,
43
- optionalValue: option.optional,
44
- required: option.mandatory,
45
- defaultValue: option.defaultValue
46
- };
47
- }
48
- function describeArgument(argument) {
49
- return {
50
- name: argument.name(),
51
- description: argument.description,
52
- required: argument.required,
53
- variadic: argument.variadic
54
- };
55
- }
56
- function inferWrites(command, declared) {
57
- if (declared !== void 0) return declared;
58
- return command.options.some((option) => option.long === "--yes") ? true : null;
59
- }
60
- function walkCommands(root) {
61
- const entries = [];
62
- function visit(command, path, ancestors) {
63
- const annotation = readAnnotation(command);
64
- const subcommands = visibleSubcommands(command);
65
- entries.push({
66
- command: path.join(" "),
67
- path,
68
- description: command.description(),
69
- aliases: command.aliases(),
70
- arguments: command.registeredArguments.map(describeArgument),
71
- options: visibleOptions(command).map(describeOption),
72
- inheritsOptionsFrom: ancestors.filter((ancestor) => visibleOptions(ancestor).some((option) => option.long !== "--version")).map((ancestor) => commandPath(ancestor).join(" ")),
73
- subcommands: subcommands.map((sub) => sub.name()),
74
- runnable: isRunnable(command),
75
- writes: inferWrites(command, annotation?.writes),
76
- endpoints: annotation?.endpoints ?? null
77
- });
78
- for (const sub of subcommands) visit(sub, [...path, sub.name()], [...ancestors, command]);
79
- }
80
- visit(root, [root.name()], []);
81
- return entries;
82
- }
83
- function rootCommand(command) {
84
- let root = command;
85
- while (root.parent) root = root.parent;
86
- return root;
87
- }
88
- function commandPath(command) {
89
- const path = [];
90
- for (let c = command; c; c = c.parent) path.unshift(c.name());
91
- return path;
92
- }
93
- /** Keep the entries at or under `prefix`, matching names or aliases. */
94
- function filterCatalog(entries, root, prefix) {
95
- let target = root;
96
- for (const word of prefix) {
97
- const next = visibleSubcommands(target).find((sub) => sub.name() === word || sub.aliases().includes(word));
98
- if (!next) return [];
99
- target = next;
100
- }
101
- const base = commandPath(target);
102
- return entries.filter((entry) => base.every((word, index) => entry.path[index] === word));
103
- }
104
- //#endregion
105
- //#region src/utils/result.ts
106
- function success(value) {
107
- return {
108
- success: true,
109
- value
110
- };
111
- }
112
- function failure(error) {
113
- return {
114
- success: false,
115
- error
116
- };
117
- }
118
- function isSuccess(result) {
119
- return result.success === true;
120
- }
121
- function isFailure(result) {
122
- return result.success === false;
123
- }
124
- function tryCatch(fn) {
125
- try {
126
- return success(fn());
127
- } catch (error) {
128
- return failure(error instanceof Error ? error : new Error(String(error)));
129
- }
130
- }
131
- async function tryCatchAsync(fn) {
132
- try {
133
- return success(await fn());
134
- } catch (error) {
135
- return failure(error instanceof Error ? error : new Error(String(error)));
136
- }
137
- }
138
- function unwrap(result) {
139
- if (isSuccess(result)) return result.value;
140
- if (result.error instanceof Error) throw result.error;
141
- throw new Error(typeof result.error === "object" && result.error !== null ? JSON.stringify(result.error) : String(result.error));
142
- }
143
- function unwrapOr(result, defaultValue) {
144
- if (isSuccess(result)) return result.value;
145
- return defaultValue;
146
- }
147
- function mapResult(result, fn) {
148
- if (isSuccess(result)) return success(fn(result.value));
149
- return result;
150
- }
151
- function mapError(result, fn) {
152
- if (isFailure(result)) return failure(fn(result.error));
153
- return result;
154
- }
155
- function isError(value) {
156
- return value instanceof Error;
157
- }
158
- function isNodeError(value) {
159
- return value instanceof Error && "code" in value;
160
- }
161
- function getErrorMessage(error) {
162
- if (error instanceof Error) return error.message;
163
- if (typeof error === "string") return error;
164
- return String(error);
165
- }
166
- //#endregion
167
- //#region src/auth/fluid-api.ts
168
- const API_TIMEOUT_MS = 1e4;
169
- function getFluidApiBase() {
170
- return process.env["FLUID_API_BASE"] ?? "https://api.fluid.app";
171
- }
172
- function makeSignal() {
173
- const controller = new AbortController();
174
- const timer = setTimeout(() => controller.abort(), API_TIMEOUT_MS);
175
- return {
176
- signal: controller.signal,
177
- cleanup: () => clearTimeout(timer)
178
- };
179
- }
180
- const FLUID_API_ERROR = {
181
- INVALID_TOKEN: {
182
- code: "INVALID_TOKEN",
183
- message: "Token is invalid or expired"
184
- },
185
- API_UNREACHABLE: {
186
- code: "API_UNREACHABLE",
187
- message: "Could not reach the Fluid API"
188
- },
189
- UUID_NOT_FOUND: {
190
- code: "UUID_NOT_FOUND",
191
- message: "Verification session not found"
192
- },
193
- CODE_EXPIRED: {
194
- code: "CODE_EXPIRED",
195
- message: "Verification code has expired, was already used, or is locked after too many attempts — please request a new one"
196
- },
197
- RATE_LIMITED: {
198
- code: "RATE_LIMITED",
199
- message: "Too many sign-in requests — wait a minute and try again"
200
- },
201
- INVALID_CODE: {
202
- code: "INVALID_CODE",
203
- message: "Invalid verification code"
204
- },
205
- COMPANY_NOT_FOUND: {
206
- code: "COMPANY_NOT_FOUND",
207
- message: "Company not found"
208
- },
209
- SWITCH_FAILED: {
210
- code: "SWITCH_FAILED",
211
- message: "Failed to switch company"
212
- }
213
- };
214
- function createApiError(template, details) {
215
- return {
216
- code: template.code,
217
- message: template.message,
218
- details
219
- };
220
- }
221
- /**
222
- * Validate a token against the Fluid API and return company info
223
- */
224
- async function validateToken(token) {
225
- const { signal, cleanup } = makeSignal();
226
- try {
227
- const response = await fetch(`${getFluidApiBase()}/api/company/v1/companies/me`, {
228
- method: "GET",
229
- headers: { Authorization: `Bearer ${token}` },
230
- signal
231
- });
232
- if (response.ok) {
233
- const name = (await response.json())?.data?.company?.name;
234
- if (!name) return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, "Unexpected response shape from /companies/me"));
235
- return success({ name });
236
- }
237
- if (response.status === 401 || response.status === 403) return failure(createApiError(FLUID_API_ERROR.INVALID_TOKEN, `HTTP ${response.status}: Check that your token is valid and non-expired.`));
238
- const body = await response.text();
239
- return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, `HTTP ${response.status}: ${body}`));
240
- } catch (err) {
241
- const message = err instanceof Error ? err.message : String(err);
242
- return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, message));
243
- } finally {
244
- cleanup();
245
- }
246
- }
247
- /**
248
- * Send a multi-factor authentication code to the given email address.
249
- * The API answers 201 whether or not the address can sign in
250
- * (anti-enumeration).
251
- *
252
- * With `fluidShop`, the server ties the code to the person's membership in
253
- * that company, so redeeming it signs in to that company alone and, for an
254
- * admin's emailed code, confirms a new signup.
255
- */
256
- async function sendMfa(email, options = {}) {
257
- const { signal, cleanup } = makeSignal();
258
- try {
259
- const response = await fetch(`${getFluidApiBase()}/api/authentication/send_mfa`, {
260
- method: "POST",
261
- headers: { "Content-Type": "application/json" },
262
- body: JSON.stringify(options.fluidShop ? {
263
- email,
264
- fluid_shop: options.fluidShop
265
- } : { email }),
266
- signal
267
- });
268
- if (response.status === 201) {
269
- const data = await response.json();
270
- const uuid = data.multi_factor_authentication?.uuid;
271
- const expiresAt = data.multi_factor_authentication?.verification_code_expires_at;
272
- if (!uuid || !expiresAt) return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, "Unexpected response shape from /send_mfa"));
273
- return success({
274
- uuid,
275
- expiresAt
276
- });
277
- }
278
- const body = await response.text();
279
- if (response.status === 429) return failure(createApiError(FLUID_API_ERROR.RATE_LIMITED, `HTTP 429: ${body}`));
280
- return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, `HTTP ${response.status}: ${body}`));
281
- } catch (err) {
282
- const message = err instanceof Error ? err.message : String(err);
283
- return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, message));
284
- } finally {
285
- cleanup();
286
- }
287
- }
288
- /**
289
- * Confirm a multi-factor authentication code and retrieve company JWTs.
290
- *
291
- * `baseUrl` is the API the code was sent from; a sign-in finished in a
292
- * later process passes the one it saved, not the current environment's.
293
- */
294
- async function confirmMfa(uuid, code, options = {}) {
295
- const { signal, cleanup } = makeSignal();
296
- const apiBase = options.baseUrl ?? getFluidApiBase();
297
- try {
298
- const response = await fetch(`${apiBase}/api/authentication/confirm_mfa`, {
299
- method: "POST",
300
- headers: { "Content-Type": "application/json" },
301
- body: JSON.stringify({
302
- uuid,
303
- multi_factor_authentication: { verification_code: code },
304
- ...options.fluidShop ? { fluid_shop: options.fluidShop } : {}
305
- }),
306
- signal
307
- });
308
- if (response.ok) {
309
- const data = await response.json();
310
- if (!data.authenticated) return failure(createApiError(FLUID_API_ERROR.INVALID_CODE, "Authentication was not confirmed by the server"));
311
- const companies = Array.isArray(data.companies) ? data.companies : [];
312
- return success({
313
- authType: data.auth_type ?? "",
314
- companies: companies.map((c) => ({
315
- id: c.id,
316
- name: c.name,
317
- shopName: c.shop_name,
318
- jwt: c.jwt,
319
- ...c.auth_type ? { authType: c.auth_type } : {}
320
- }))
321
- });
322
- }
323
- if (response.status === 404) return failure(createApiError(FLUID_API_ERROR.UUID_NOT_FOUND));
324
- if (response.status === 410) return failure(createApiError(FLUID_API_ERROR.CODE_EXPIRED));
325
- if (response.status === 422) return failure(createApiError(FLUID_API_ERROR.INVALID_CODE));
326
- const body = await response.text();
327
- if (response.status === 429) return failure(createApiError(FLUID_API_ERROR.RATE_LIMITED, `HTTP 429: ${body}`));
328
- return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, `HTTP ${response.status}: ${body}`));
329
- } catch (err) {
330
- const message = err instanceof Error ? err.message : String(err);
331
- return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, message));
332
- } finally {
333
- cleanup();
334
- }
335
- }
336
- /**
337
- * Fetch all companies the authenticated user has access to.
338
- */
339
- async function fetchUserCompanies(token, baseUrl) {
340
- const { signal, cleanup } = makeSignal();
341
- const apiBase = baseUrl ?? getFluidApiBase();
342
- try {
343
- const response = await fetch(`${apiBase}/api/me`, {
344
- method: "GET",
345
- headers: { Authorization: `Bearer ${token}` },
346
- signal
347
- });
348
- if (response.ok) {
349
- const data = await response.json();
350
- return success((Array.isArray(data.companies) ? data.companies : []).map((c) => ({
351
- id: c.id,
352
- name: c.name
353
- })));
354
- }
355
- if (response.status === 401 || response.status === 403) return failure(createApiError(FLUID_API_ERROR.INVALID_TOKEN, `HTTP ${response.status}`));
356
- const body = await response.text();
357
- return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, `HTTP ${response.status}: ${body}`));
358
- } catch (err) {
359
- const message = err instanceof Error ? err.message : String(err);
360
- return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, message));
361
- } finally {
362
- cleanup();
363
- }
364
- }
365
- /**
366
- * Switch to a different company and receive a new JWT.
367
- *
368
- * Response shape (from @fluid-app/auth SwitchCompanyResponse):
369
- * { company: { id, name, fluid_shop, jwt }, meta: { request_id, timestamp } }
370
- */
371
- async function switchCompany(token, companyId, baseUrl) {
372
- const { signal, cleanup } = makeSignal();
373
- const apiBase = baseUrl ?? getFluidApiBase();
374
- try {
375
- const response = await fetch(`${apiBase}/api/authentication/company/${companyId}/switch`, {
376
- method: "PUT",
377
- headers: {
378
- Authorization: `Bearer ${token}`,
379
- "Content-Type": "application/json"
380
- },
381
- signal
382
- });
383
- if (response.ok) {
384
- const company = (await response.json()).company;
385
- if (!company?.jwt) return failure(createApiError(FLUID_API_ERROR.SWITCH_FAILED, "Unexpected response shape from /switch"));
386
- return success({
387
- companyId: company.id,
388
- companyName: company.name,
389
- fluidShop: company.fluid_shop,
390
- jwt: company.jwt
391
- });
392
- }
393
- if (response.status === 404) return failure(createApiError(FLUID_API_ERROR.COMPANY_NOT_FOUND, `Company ${companyId} not found`));
394
- if (response.status === 401 || response.status === 403) return failure(createApiError(FLUID_API_ERROR.INVALID_TOKEN, `HTTP ${response.status}`));
395
- const body = await response.text();
396
- return failure(createApiError(FLUID_API_ERROR.SWITCH_FAILED, `HTTP ${response.status}: ${body}`));
397
- } catch (err) {
398
- const message = err instanceof Error ? err.message : String(err);
399
- return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, message));
400
- } finally {
401
- cleanup();
402
- }
403
- }
404
- //#endregion
405
- //#region src/config/paths.ts
406
- /**
407
- * XDG-compliant config directory resolution
408
- *
409
- * Priority:
410
- * 1. FLUID_CONFIG_DIR env var (explicit override)
411
- * 2. ~/.fluid/ on macOS (convention for CLI tools)
412
- * 3. %APPDATA%/fluid/ on Windows
413
- * 4. $XDG_CONFIG_HOME/fluid/ on Linux (XDG spec)
414
- * 5. ~/.config/fluid/ fallback on Linux
415
- */
416
- function getConfigDir() {
417
- const envOverride = process.env["FLUID_CONFIG_DIR"];
418
- if (envOverride) return envOverride;
419
- if (process.platform === "darwin") return join(homedir(), ".fluid");
420
- if (process.platform === "win32") return join(process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming"), "fluid");
421
- const xdgConfig = process.env["XDG_CONFIG_HOME"];
422
- if (xdgConfig) return join(xdgConfig, "fluid");
423
- return join(homedir(), ".config", "fluid");
424
- }
425
- function getConfigFilePath() {
426
- return join(getConfigDir(), "config.json");
427
- }
428
- //#endregion
429
- //#region src/config/types.ts
430
- function createDefaultConfig() {
431
- return {
432
- activeProfile: null,
433
- profiles: {},
434
- plugins: {},
435
- enabledPlugins: null
436
- };
437
- }
438
- //#endregion
439
- //#region src/config/config.ts
440
- /**
441
- * Read/write config.json with atomic writes and safe defaults
442
- */
443
- function readConfig() {
444
- const configPath = getConfigFilePath();
445
- if (!existsSync(configPath)) return createDefaultConfig();
446
- const raw = readFileSync(configPath, "utf8");
447
- let parsed;
448
- try {
449
- parsed = JSON.parse(raw);
450
- } catch {
451
- return createDefaultConfig();
452
- }
453
- return withDurableWorkspaceAliases({
454
- ...createDefaultConfig(),
455
- ...parsed
456
- });
457
- }
458
- function writeConfig(config) {
459
- const configPath = getConfigFilePath();
460
- const dir = dirname(configPath);
461
- mkdirSync(dir, {
462
- recursive: true,
463
- mode: 448
464
- });
465
- const tmpPath = join(dir, `.fluid-config-${randomBytes(6).toString("hex")}.tmp`);
466
- try {
467
- writeFileSync(tmpPath, JSON.stringify(withDurableWorkspaceAliases(config), null, 2) + "\n", {
468
- encoding: "utf8",
469
- mode: 384
470
- });
471
- renameSync(tmpPath, configPath);
472
- } catch (err) {
473
- try {
474
- unlinkSync(tmpPath);
475
- } catch {}
476
- throw err;
477
- }
478
- }
479
- function workspaceSlug(value) {
480
- return value.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
481
- }
482
- function storefrontSlug(value) {
483
- return workspaceSlug((value.trim().replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").split(/[/?#]/, 1)[0]?.replace(/:\d+$/, "") ?? "").replace(/\.fluid\.app$/i, ""));
484
- }
485
- /** Preserve rename history even when `fluid logout` clears the profiles that
486
- * originally carried it. Derivation on read migrates existing config files;
487
- * normalization on every write makes the migration durable before profiles
488
- * are removed. */
489
- function withDurableWorkspaceAliases(config) {
490
- const aliases = {};
491
- const add = (storefront, candidates) => {
492
- const key = storefrontSlug(storefront);
493
- if (!key) return;
494
- const values = new Set(aliases[key] ?? []);
495
- for (const candidate of candidates) {
496
- const slug = workspaceSlug(candidate);
497
- if (slug) values.add(slug);
498
- }
499
- if (values.size > 0) aliases[key] = [...values];
500
- };
501
- for (const [storefront, candidates] of Object.entries(config.workspaceAliasesByFluidShop ?? {})) {
502
- if (!Array.isArray(candidates)) continue;
503
- add(storefront, candidates.filter((candidate) => typeof candidate === "string"));
504
- }
505
- for (const profile of Object.values(config.profiles)) if (profile.fluidShop) add(profile.fluidShop, [profile.name, profile.companyName]);
506
- return Object.keys(aliases).length > 0 || config.workspaceAliasesByFluidShop !== void 0 ? {
507
- ...config,
508
- workspaceAliasesByFluidShop: aliases
509
- } : config;
510
- }
511
- function updateConfig(updater) {
512
- const updated = updater(readConfig());
513
- writeConfig(updated);
514
- return updated;
515
- }
516
- //#endregion
517
- //#region src/config/project-config.ts
518
- /**
519
- * Project-level config (.fluidrc) reader.
520
- *
521
- * Walks upward from a starting directory to find a `.fluidrc` file.
522
- * The file is JSON with a `profile` field that maps to a profile name
523
- * in `~/.fluid/config.json`.
524
- *
525
- * This allows portal repos to pin themselves to a specific CLI profile
526
- * so that `fluid portal pull` / `push` always use the correct company
527
- * credentials, regardless of which profile is globally active.
528
- */
529
- const RC_FILENAME = ".fluidrc";
530
- /** Cached result keyed by the starting directory. */
531
- let cachedResult;
532
- /**
533
- * Walk upward from `startDir` looking for a `.fluidrc` file.
534
- *
535
- * Returns the parsed config when found, or `null` if no valid `.fluidrc`
536
- * exists in any ancestor directory.
537
- *
538
- * The result is cached per starting directory for the lifetime of the
539
- * process — CLI commands are short-lived so stale-cache is not a concern.
540
- */
541
- function findProjectConfig(startDir) {
542
- if (cachedResult && cachedResult.dir === startDir) return cachedResult.config;
543
- let dir = startDir;
544
- while (true) {
545
- const rcPath = join(dir, RC_FILENAME);
546
- if (existsSync(rcPath)) {
547
- try {
548
- const raw = readFileSync(rcPath, "utf8");
549
- const parsed = JSON.parse(raw);
550
- if (typeof parsed.profile === "string" && parsed.profile.length > 0) {
551
- const config = { profile: parsed.profile };
552
- cachedResult = {
553
- dir: startDir,
554
- config
555
- };
556
- return config;
557
- }
558
- } catch {}
559
- cachedResult = {
560
- dir: startDir,
561
- config: null
562
- };
563
- return null;
564
- }
565
- const parent = dirname(dir);
566
- if (parent === dir) break;
567
- dir = parent;
568
- }
569
- cachedResult = {
570
- dir: startDir,
571
- config: null
572
- };
573
- return null;
574
- }
575
- //#endregion
576
- //#region src/auth/token.ts
577
- /**
578
- * Token storage and retrieval from config
579
- */
580
- /**
581
- * Get the auth token for a named profile, or the active profile when omitted.
582
- *
583
- * Resolution order (when `profileName` is omitted — mirrors `resolveToken`
584
- * in domain/context.ts):
585
- * 1. `FLUID_TOKEN` / `FLUID_API_TOKEN` environment variables
586
- * 2. Project-level `.fluidrc` profile (walks upward from cwd)
587
- * 3. Global active profile from `~/.fluid/config.json`
588
- *
589
- * When `profileName` is provided explicitly (e.g. via `--profile` flag),
590
- * it takes precedence over the environment variables, `.fluidrc`, and the
591
- * active profile.
592
- */
593
- function getAuthToken(profileName) {
594
- const config = readConfig();
595
- if (profileName) return config.profiles[profileName]?.token ?? null;
596
- const envToken = process.env["FLUID_TOKEN"] ?? process.env["FLUID_API_TOKEN"];
597
- if (envToken) return envToken;
598
- const projectConfig = findProjectConfig(process.cwd());
599
- if (projectConfig?.profile) {
600
- const profile = config.profiles[projectConfig.profile];
601
- if (profile) return profile.token;
602
- }
603
- if (!config.activeProfile) return null;
604
- return config.profiles[config.activeProfile]?.token ?? null;
605
- }
606
- /**
607
- * Get the active profile, or null if not logged in
608
- */
609
- function getActiveProfile() {
610
- const config = readConfig();
611
- if (!config.activeProfile) return null;
612
- return config.profiles[config.activeProfile] ?? null;
613
- }
614
- /**
615
- * List all stored profile names
616
- */
617
- function listProfileNames() {
618
- const config = readConfig();
619
- return Object.keys(config.profiles);
620
- }
621
- //#endregion
622
- export { unwrapOr as A, isSuccess as C, tryCatch as D, success as E, walkCommands as F, describeCommand as I, rootCommand as M, visibleOptions as N, tryCatchAsync as O, visibleSubcommands as P, isNodeError as S, mapResult as T, validateToken as _, readConfig as a, isError as b, createDefaultConfig as c, FLUID_API_ERROR as d, confirmMfa as f, switchCompany as g, sendMfa as h, findProjectConfig as i, filterCatalog as j, unwrap as k, getConfigDir as l, getFluidApiBase as m, getAuthToken as n, updateConfig as o, fetchUserCompanies as p, listProfileNames as r, writeConfig as s, getActiveProfile as t, getConfigFilePath as u, failure as v, mapError as w, isFailure as x, getErrorMessage as y };
623
-
624
- //# sourceMappingURL=token-DnFYT9pe.mjs.map