@bergetai/odoo-cli 0.9.2 → 0.12.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.
@@ -1,5 +1,5 @@
1
1
  import { OdooClient } from "../client.js";
2
- import { missingValueHint, missingValues, resolveConfig, writeConfigFile, } from "../config.js";
2
+ import { missingValueHint, missingValues, profileSelectionHint, resolveConfig, resolveProfileName, effectiveProfiles, readConfigFile, writeConfigFile, } from "../config.js";
3
3
  import { parseDurationMs } from "../duration.js";
4
4
  import { usageError } from "../errors.js";
5
5
  import { printJson } from "../output.js";
@@ -12,6 +12,7 @@ async function readStdinKey() {
12
12
  }
13
13
  function authFlags(globals) {
14
14
  return {
15
+ profile: globals.profile,
15
16
  url: globals.url,
16
17
  db: globals.db,
17
18
  username: globals.username,
@@ -34,9 +35,9 @@ export async function authLoginCommand(globals) {
34
35
  else if (!process.env.ODOO_API_KEY && !globals.apiKeyFile) {
35
36
  throw usageError("no API key provided", "pipe the key via stdin, set ODOO_API_KEY, or pass --api-key-file — login never prompts");
36
37
  }
37
- const resolved = await resolveConfig(authFlags(globals), {
38
- apiKey: stdinKey,
39
- });
38
+ const resolved = await resolveConfig(authFlags(globals), { apiKey: stdinKey },
39
+ // Bootstrap: the profile may not exist yet — login creates it.
40
+ { allowUnknownProfile: true });
40
41
  const missing = missingValues(resolved);
41
42
  if (missing.length > 0) {
42
43
  const details = missing
@@ -61,9 +62,10 @@ export async function authLoginCommand(globals) {
61
62
  username: resolved.username,
62
63
  api_key: resolved.apiKey,
63
64
  server_version: version.server_version,
64
- });
65
+ }, resolved.profile);
65
66
  if (globals.json) {
66
67
  printJson({
68
+ profile: resolved.profile,
67
69
  url: resolved.url,
68
70
  db: resolved.db,
69
71
  username: resolved.username,
@@ -73,7 +75,7 @@ export async function authLoginCommand(globals) {
73
75
  });
74
76
  }
75
77
  else {
76
- process.stdout.write(`Logged in as '${resolved.username}' (uid ${uid}) on ${resolved.url} (Odoo ${version.server_version})\n`);
78
+ process.stdout.write(`Logged in as '${resolved.username}' (uid ${uid}) on ${resolved.url} (Odoo ${version.server_version}) [profile: ${resolved.profile}]\n`);
77
79
  }
78
80
  }
79
81
  /**
@@ -82,17 +84,50 @@ export async function authLoginCommand(globals) {
82
84
  * stdout, even when exiting non-zero (SPEC §7.3 exception).
83
85
  */
84
86
  export async function authStatusCommand(globals) {
85
- const resolved = await resolveConfig(authFlags(globals));
86
- const missing = missingValues(resolved);
87
+ // Profile resolution is handled softly so the §7.3 envelope (with the
88
+ // missing "profile" key) still reaches stdout under --json, both for a
89
+ // missing selection and for a selected profile with no stored credentials.
90
+ const profileName = resolveProfileName(globals);
87
91
  const envelope = {
88
- url: resolved.url ?? null,
89
- db: resolved.db ?? null,
90
- username: resolved.username ?? null,
92
+ profile: profileName ?? null,
93
+ url: null,
94
+ db: null,
95
+ username: null,
91
96
  server_version: null,
92
97
  uid: null,
93
98
  authenticated: false,
94
- config_source: resolved.sources,
99
+ config_source: null,
95
100
  };
101
+ if (!profileName) {
102
+ const hint = await profileSelectionHint();
103
+ if (globals.json) {
104
+ envelope.missing = ["profile"];
105
+ printJson(envelope);
106
+ }
107
+ else {
108
+ process.stderr.write(`Error: no profile selected — ${hint}\n`);
109
+ }
110
+ process.exitCode = 2;
111
+ return;
112
+ }
113
+ const knownProfiles = effectiveProfiles(await readConfigFile());
114
+ if (!knownProfiles.has(profileName)) {
115
+ if (globals.json) {
116
+ envelope.missing = ["profile"];
117
+ printJson(envelope);
118
+ }
119
+ else {
120
+ process.stderr.write(`Error: no stored credentials for profile ${JSON.stringify(profileName)} — run \`odoo auth login --profile ${profileName} ...\`\n`);
121
+ }
122
+ process.exitCode = 2;
123
+ return;
124
+ }
125
+ const resolved = await resolveConfig(authFlags(globals));
126
+ envelope.url = resolved.url ?? null;
127
+ envelope.db = resolved.db ?? null;
128
+ envelope.username = resolved.username ?? null;
129
+ envelope.config_source = resolved.sources;
130
+ const missing = missingValues(resolved);
96
131
  if (missing.length > 0) {
97
132
  envelope.missing = missing;
98
133
  if (globals.json) {
@@ -123,6 +158,7 @@ export async function authStatusCommand(globals) {
123
158
  printJson(envelope);
124
159
  }
125
160
  else {
161
+ process.stdout.write(`Profile: ${profileName}\n`);
126
162
  process.stdout.write(`URL: ${envelope.url} (${resolved.sources.url})\n`);
127
163
  process.stdout.write(`Database: ${envelope.db} (${resolved.sources.db})\n`);
128
164
  process.stdout.write(`Username: ${envelope.username} (${resolved.sources.username})\n`);