@cargo-ai/cli 1.0.13 → 1.0.15

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 (73) hide show
  1. package/README.md +23 -2
  2. package/build/api.d.ts +5 -1
  3. package/build/api.d.ts.map +1 -1
  4. package/build/api.js +6 -7
  5. package/build/commands/{auth.d.ts → auth/index.d.ts} +2 -2
  6. package/build/commands/auth/index.d.ts.map +1 -0
  7. package/build/commands/auth/index.js +131 -0
  8. package/build/commands/auth/oauth.d.ts +7 -0
  9. package/build/commands/auth/oauth.d.ts.map +1 -0
  10. package/build/commands/auth/oauth.js +140 -0
  11. package/build/commands/auth/workspace.d.ts +10 -0
  12. package/build/commands/auth/workspace.d.ts.map +1 -0
  13. package/build/commands/auth/workspace.js +120 -0
  14. package/build/commands/billing/subscription.d.ts.map +1 -1
  15. package/build/commands/billing/subscription.js +55 -17
  16. package/build/commands/orchestration/index.d.ts.map +1 -1
  17. package/build/commands/orchestration/index.js +2 -0
  18. package/build/commands/orchestration/query.d.ts +4 -0
  19. package/build/commands/orchestration/query.d.ts.map +1 -0
  20. package/build/commands/orchestration/query.js +23 -0
  21. package/build/commands/orchestration/run.d.ts.map +1 -1
  22. package/build/commands/orchestration/run.js +6 -1
  23. package/build/commands/runHandler.d.ts +32 -1
  24. package/build/commands/runHandler.d.ts.map +1 -1
  25. package/build/commands/runHandler.js +191 -24
  26. package/build/commands/storage/index.d.ts.map +1 -1
  27. package/build/commands/storage/index.js +2 -0
  28. package/build/commands/storage/query.d.ts +4 -0
  29. package/build/commands/storage/query.d.ts.map +1 -0
  30. package/build/commands/storage/query.js +46 -0
  31. package/build/commands/workspaceManagement/file.d.ts.map +1 -0
  32. package/build/commands/workspaceManagement/folder.d.ts.map +1 -0
  33. package/build/commands/workspaceManagement/index.d.ts +4 -0
  34. package/build/commands/workspaceManagement/index.d.ts.map +1 -0
  35. package/build/commands/workspaceManagement/index.js +19 -0
  36. package/build/commands/workspaceManagement/report.d.ts +4 -0
  37. package/build/commands/workspaceManagement/report.d.ts.map +1 -0
  38. package/build/commands/workspaceManagement/report.js +17 -0
  39. package/build/commands/workspaceManagement/role.d.ts.map +1 -0
  40. package/build/commands/workspaceManagement/token.d.ts.map +1 -0
  41. package/build/commands/{workspace → workspaceManagement}/token.js +3 -2
  42. package/build/commands/workspaceManagement/user.d.ts.map +1 -0
  43. package/build/commands/{workspace → workspaceManagement}/user.js +30 -22
  44. package/build/commands/workspaceManagement/workspaces.d.ts.map +1 -0
  45. package/build/commands/{workspace → workspaceManagement}/workspaces.js +36 -7
  46. package/build/config.d.ts +3 -1
  47. package/build/config.d.ts.map +1 -1
  48. package/build/config.js +19 -17
  49. package/build/index.js +24 -10
  50. package/build/oauthConfig.d.ts +13 -0
  51. package/build/oauthConfig.d.ts.map +1 -0
  52. package/build/oauthConfig.js +17 -0
  53. package/package.json +2 -2
  54. package/build/commands/auth.d.ts.map +0 -1
  55. package/build/commands/auth.js +0 -104
  56. package/build/commands/workspace/file.d.ts.map +0 -1
  57. package/build/commands/workspace/folder.d.ts.map +0 -1
  58. package/build/commands/workspace/index.d.ts +0 -4
  59. package/build/commands/workspace/index.d.ts.map +0 -1
  60. package/build/commands/workspace/index.js +0 -17
  61. package/build/commands/workspace/role.d.ts.map +0 -1
  62. package/build/commands/workspace/token.d.ts.map +0 -1
  63. package/build/commands/workspace/user.d.ts.map +0 -1
  64. package/build/commands/workspace/workspaces.d.ts.map +0 -1
  65. /package/build/commands/{workspace → workspaceManagement}/file.d.ts +0 -0
  66. /package/build/commands/{workspace → workspaceManagement}/file.js +0 -0
  67. /package/build/commands/{workspace → workspaceManagement}/folder.d.ts +0 -0
  68. /package/build/commands/{workspace → workspaceManagement}/folder.js +0 -0
  69. /package/build/commands/{workspace → workspaceManagement}/role.d.ts +0 -0
  70. /package/build/commands/{workspace → workspaceManagement}/role.js +0 -0
  71. /package/build/commands/{workspace → workspaceManagement}/token.d.ts +0 -0
  72. /package/build/commands/{workspace → workspaceManagement}/user.d.ts +0 -0
  73. /package/build/commands/{workspace → workspaceManagement}/workspaces.d.ts +0 -0
@@ -1,4 +1,3 @@
1
- import { getConfig } from "../../config.js";
2
1
  import { handleApiCall, outputJson } from "../runHandler.js";
3
2
  export function registerUserCommands(parent, getApi) {
4
3
  const user = parent
@@ -6,23 +5,23 @@ export function registerUserCommands(parent, getApi) {
6
5
  .description("Manage workspace users and permissions");
7
6
  user
8
7
  .command("list")
9
- .description("List workspace users")
10
- .option("--workspace-uuid <uuid>", "Workspace UUID (or set CARGO_WORKSPACE_UUID)")
11
- .action(async (opts) => {
12
- const config = getConfig();
13
- const workspaceUuid = opts.workspaceUuid !== undefined
14
- ? opts.workspaceUuid
15
- : config.workspaceUuid;
16
- if (workspaceUuid === undefined) {
17
- throw new Error("--workspace-uuid or CARGO_WORKSPACE_UUID required");
18
- }
8
+ .description("List users in the currently selected workspace")
9
+ .addHelpText("after", `
10
+ Examples:
11
+ $ cargo-ai workspaceManagement user list
12
+ $ cargo-ai workspaceManagement user list | jq -r '.users[] | "\\(.email) \\(.uuid)"'`)
13
+ .action(async () => {
19
14
  const api = getApi();
20
- const result = await handleApiCall(() => api.workspaceManagement.user.all({ workspaceUuid }));
15
+ const result = await handleApiCall(() => api.workspaceManagement.user.all());
21
16
  outputJson(result);
22
17
  });
23
18
  user
24
19
  .command("get-current")
25
- .description("Get current user")
20
+ .description("Get the user authenticated by the current credentials")
21
+ .addHelpText("after", `
22
+ Examples:
23
+ $ cargo-ai workspaceManagement user get-current
24
+ $ cargo-ai workspaceManagement user get-current | jq -r .user.email`)
26
25
  .action(async () => {
27
26
  const api = getApi();
28
27
  const result = await handleApiCall(() => api.workspaceManagement.user.getCurrent());
@@ -35,7 +34,7 @@ export function registerUserCommands(parent, getApi) {
35
34
  .requiredOption("--role-slug <slug>", "Role slug to assign (string, required)")
36
35
  .addHelpText("after", `
37
36
  Example:
38
- $ cargo-ai workspace user create --user-email alice@example.com --role-slug admin`)
37
+ $ cargo-ai workspaceManagement user create --user-email alice@example.com --role-slug admin`)
39
38
  .action(async (opts) => {
40
39
  const api = getApi();
41
40
  const result = await handleApiCall(() => api.workspaceManagement.user.create({
@@ -46,8 +45,11 @@ Example:
46
45
  });
47
46
  user
48
47
  .command("remove")
49
- .description("Remove a workspace user")
50
- .requiredOption("--user-uuid <uuid>", "User UUID")
48
+ .description("Remove a user from the currently selected workspace")
49
+ .requiredOption("--user-uuid <uuid>", "UUID of the user to remove")
50
+ .addHelpText("after", `
51
+ Example:
52
+ $ cargo-ai workspaceManagement user remove --user-uuid 550e8400-e29b-41d4-a716-446655440000`)
51
53
  .action(async (opts) => {
52
54
  const api = getApi();
53
55
  await handleApiCall(() => api.workspaceManagement.user.remove({ userUuid: opts.userUuid }));
@@ -55,9 +57,12 @@ Example:
55
57
  });
56
58
  user
57
59
  .command("update")
58
- .description("Update a workspace user")
59
- .requiredOption("--user-uuid <uuid>", "User UUID")
60
- .requiredOption("--role-slug <slug>", "Role slug")
60
+ .description("Change a user's role in the currently selected workspace")
61
+ .requiredOption("--user-uuid <uuid>", "UUID of the user to update")
62
+ .requiredOption("--role-slug <slug>", "New role slug (e.g. admin, member)")
63
+ .addHelpText("after", `
64
+ Example:
65
+ $ cargo-ai workspaceManagement user update --user-uuid 550e8400-... --role-slug admin`)
61
66
  .action(async (opts) => {
62
67
  const api = getApi();
63
68
  const result = await handleApiCall(() => api.workspaceManagement.user.update({
@@ -76,8 +81,8 @@ Example:
76
81
  .requiredOption("--effect <effect>", "Permission effect. Allowed values: allow, deny")
77
82
  .addHelpText("after", `
78
83
  Examples:
79
- $ cargo-ai workspace user upsert-permission --emails alice@example.com --action read --resource-uuid 550e8400-... --effect allow
80
- $ cargo-ai workspace user upsert-permission --user-uuids uuid1,uuid2 --action write --resource-uuid 550e8400-... --effect deny`)
84
+ $ cargo-ai workspaceManagement user upsert-permission --emails alice@example.com --action read --resource-uuid 550e8400-... --effect allow
85
+ $ cargo-ai workspaceManagement user upsert-permission --user-uuids uuid1,uuid2 --action write --resource-uuid 550e8400-... --effect deny`)
81
86
  .action(async (opts) => {
82
87
  if (opts.userUuids === undefined && opts.emails === undefined) {
83
88
  throw new Error("--user-uuids or --emails is required");
@@ -98,10 +103,13 @@ Examples:
98
103
  });
99
104
  user
100
105
  .command("remove-permission")
101
- .description("Remove a user permission")
106
+ .description("Remove a previously granted/denied user permission")
102
107
  .requiredOption("--user-uuid <uuid>", "User UUID (string, required)")
103
108
  .requiredOption("--resource-uuid <uuid>", "Resource UUID (string, required)")
104
109
  .requiredOption("--effect <effect>", "Permission effect to remove. Allowed values: allow, deny")
110
+ .addHelpText("after", `
111
+ Example:
112
+ $ cargo-ai workspaceManagement user remove-permission --user-uuid 550e8400-... --resource-uuid 660e8400-... --effect allow`)
105
113
  .action(async (opts) => {
106
114
  const api = getApi();
107
115
  await handleApiCall(() => api.workspaceManagement.user.removePermission({
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../../../src/commands/workspaceManagement/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CAiLN"}
@@ -5,8 +5,13 @@ export function registerWorkspacesCommands(parent, getApi) {
5
5
  .description("Workspace list and management");
6
6
  workspaces
7
7
  .command("list")
8
- .description("List all workspaces")
9
- .option("--refresh", "Refresh")
8
+ .description("List all workspaces accessible to the current user")
9
+ .option("--refresh", "Bypass any token cache and re-fetch from the server (useful after permission changes)")
10
+ .addHelpText("after", `
11
+ Examples:
12
+ $ cargo-ai workspaceManagement workspaces list
13
+ $ cargo-ai workspaceManagement workspaces list --refresh
14
+ $ cargo-ai workspaceManagement workspaces list | jq -r '.workspaces[].uuid'`)
10
15
  .action(async (opts) => {
11
16
  const api = getApi();
12
17
  const result = await handleApiCall(() => api.workspaceManagement.workspace.all({
@@ -14,12 +19,28 @@ export function registerWorkspacesCommands(parent, getApi) {
14
19
  }));
15
20
  outputJson(result);
16
21
  });
22
+ workspaces
23
+ .command("get-current")
24
+ .description("Get the workspace currently selected via credentials or CARGO_WORKSPACE_UUID")
25
+ .addHelpText("after", `
26
+ Examples:
27
+ $ cargo-ai workspaceManagement workspaces get-current
28
+ $ cargo-ai workspaceManagement workspaces get-current | jq -r .workspace.name`)
29
+ .action(async () => {
30
+ const api = getApi();
31
+ const result = await handleApiCall(() => api.workspaceManagement.workspace.getCurrent());
32
+ outputJson(result);
33
+ });
17
34
  workspaces
18
35
  .command("create")
19
- .description("Create a workspace")
20
- .requiredOption("--name <name>", "Workspace name")
21
- .option("--logo-base64 <data>", "Logo as base64 string")
22
- .option("--metadata <json>", 'Metadata (JSON object, e.g. {"key":"value"})')
36
+ .description("Create a new workspace")
37
+ .requiredOption("--name <name>", "Workspace display name")
38
+ .option("--logo-base64 <data>", "Logo image encoded as a base64 data string")
39
+ .option("--metadata <json>", 'Workspace metadata as a JSON object, e.g. {"mainGoal":["enrich"]}')
40
+ .addHelpText("after", `
41
+ Examples:
42
+ $ cargo-ai workspaceManagement workspaces create --name "Acme GTM"
43
+ $ cargo-ai workspaceManagement workspaces create --name "Acme GTM" --metadata '{"mainGoal":["enrich"]}'`)
23
44
  .action(async (opts) => {
24
45
  const api = getApi();
25
46
  const result = await handleApiCall(() => api.workspaceManagement.workspace.create({
@@ -33,7 +54,15 @@ export function registerWorkspacesCommands(parent, getApi) {
33
54
  });
34
55
  workspaces
35
56
  .command("update")
36
- .description("Update a workspace")
57
+ .description("Update properties of the currently selected workspace")
58
+ .addHelpText("after", `
59
+ Examples:
60
+ $ cargo-ai workspaceManagement workspaces update --name "New name"
61
+ $ cargo-ai workspaceManagement workspaces update --allowed-email-domains acme.com,example.org
62
+ $ cargo-ai workspaceManagement workspaces update --openai-api-key null # remove the key
63
+ $ cargo-ai workspaceManagement workspaces update --metadata '{"mainGoal":["enrich","prioritize"]}'
64
+
65
+ Pass the literal string "null" to remove a nullable value.`)
37
66
  .option("--name <name>", "Workspace name")
38
67
  .option("--allowed-email-domains <list>", "Allowed email domains (comma-separated)")
39
68
  .option("--logo-base64 <data>", "Logo as base64 string (use 'null' to remove)")
package/build/config.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ export type ConfigSource = "environment" | "credentials-file" | "none";
1
2
  export type Config = {
3
+ accessToken: string | undefined;
2
4
  baseUrl: string;
3
- accessToken: string;
4
5
  workspaceUuid: string | undefined;
6
+ source: ConfigSource;
5
7
  };
6
8
  export declare function getConfig(): Config;
7
9
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC,CAAC;AAIF,wBAAgB,SAAS,IAAI,MAAM,CAmBlC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,kBAAkB,GAAG,MAAM,CAAC;AAEvE,MAAM,MAAM,MAAM,GAAG;IACnB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAIF,wBAAgB,SAAS,IAAI,MAAM,CA4BlC"}
package/build/config.js CHANGED
@@ -2,27 +2,29 @@ import { loadCredentials } from "./credentials.js";
2
2
  const DEFAULT_BASE_URL = "https://api.getcargo.io";
3
3
  export function getConfig() {
4
4
  const credentials = loadCredentials();
5
- const accessToken = getAccessToken(credentials);
6
- if (accessToken === undefined) {
7
- console.error(JSON.stringify({
8
- error: 'Not authenticated. Run "cargo-ai login --token <token>" or set CARGO_API_TOKEN.',
9
- }));
10
- process.exit(1);
11
- }
12
- const baseUrl = getBaseUrl(credentials);
13
- const workspaceUuid = getWorkspaceUuid(credentials);
14
- return { baseUrl, accessToken, workspaceUuid };
15
- }
16
- const getAccessToken = (credentials) => {
17
5
  const envToken = process.env["CARGO_API_TOKEN"];
6
+ let accessToken;
7
+ let source;
18
8
  if (envToken !== undefined) {
19
- return envToken;
9
+ accessToken = envToken;
10
+ source = "environment";
20
11
  }
21
- if (credentials !== undefined) {
22
- return credentials.accessToken;
12
+ else if (credentials !== undefined &&
13
+ credentials.accessToken !== undefined) {
14
+ accessToken = credentials.accessToken;
15
+ source = "credentials-file";
23
16
  }
24
- return undefined;
25
- };
17
+ else {
18
+ accessToken = undefined;
19
+ source = "none";
20
+ }
21
+ return {
22
+ accessToken,
23
+ baseUrl: getBaseUrl(credentials),
24
+ workspaceUuid: getWorkspaceUuid(credentials),
25
+ source,
26
+ };
27
+ }
26
28
  const getBaseUrl = (credentials) => {
27
29
  const envUrl = process.env["CARGO_BASE_URL"];
28
30
  if (envUrl !== undefined) {
package/build/index.js CHANGED
@@ -3,7 +3,7 @@ import { createRequire } from "node:module";
3
3
  import { Command } from "commander";
4
4
  import { createApi } from "./api.js";
5
5
  import { registerAiCommands } from "./commands/ai/index.js";
6
- import { registerAuthCommands } from "./commands/auth.js";
6
+ import { registerAuthCommands } from "./commands/auth/index.js";
7
7
  import { registerBillingCommands } from "./commands/billing/index.js";
8
8
  import { registerConnectionCommands } from "./commands/connection/index.js";
9
9
  import { registerContextCommands } from "./commands/context/index.js";
@@ -11,11 +11,13 @@ import { registerExpressionCommands } from "./commands/expression/index.js";
11
11
  import { registerInitCommand } from "./commands/init.js";
12
12
  import { registerOrchestrationCommands } from "./commands/orchestration/index.js";
13
13
  import { registerRevenueOrganizationCommands } from "./commands/revenueOrganization/index.js";
14
+ import { ExitCodes, failWith } from "./commands/runHandler.js";
14
15
  import { registerSegmentationCommands } from "./commands/segmentation/index.js";
15
16
  import { registerStorageCommands } from "./commands/storage/index.js";
16
17
  import { registerSystemOfRecordIntegrationCommands } from "./commands/systemOfRecordIntegration/index.js";
17
18
  import { registerUserManagementCommands } from "./commands/userManagement/index.js";
18
- import { registerWorkspaceCommands } from "./commands/workspace/index.js";
19
+ import { registerWorkspaceManagementCommands } from "./commands/workspaceManagement/index.js";
20
+ import { getConfig } from "./config.js";
19
21
  const require = createRequire(import.meta.url);
20
22
  const { version } = require("../package.json");
21
23
  const program = new Command();
@@ -25,19 +27,34 @@ program
25
27
  .version(version)
26
28
  .addHelpText("after", `
27
29
  Authentication:
28
- Save credentials: cargo-ai login --token <your-token>
30
+ With API token: cargo-ai login --token <your-token>
31
+ Browser sign-in: cargo-ai login --oauth
29
32
  Use env variables: CARGO_API_TOKEN, CARGO_WORKSPACE_UUID, CARGO_BASE_URL
30
33
  Check status: cargo-ai whoami
31
34
 
32
- All commands output JSON to stdout. Errors exit with code 1.
35
+ All commands output JSON to stdout. Status messages, prompts, and errors go to stderr.
36
+
37
+ Exit codes:
38
+ 0 Success
39
+ 1 Generic error
40
+ 2 Invalid usage (missing/conflicting flags)
41
+ 3 Not authenticated (run \`cargo-ai login\`)
42
+ 4 Permission denied
43
+ 5 Not found
33
44
 
34
45
  Run "cargo-ai <command> --help" for details on a specific command group.
35
46
  Run "cargo-ai <command> <subcommand> --help" for details on a subcommand.`);
36
- const getApi = () => createApi();
47
+ const getApi = () => {
48
+ const { baseUrl, accessToken, workspaceUuid } = getConfig();
49
+ if (accessToken === undefined) {
50
+ failWith("Not authenticated. Run 'cargo-ai login --token <token>' or 'cargo-ai login --oauth'.", { code: ExitCodes.NotAuthenticated });
51
+ }
52
+ return createApi({ baseUrl, accessToken, workspaceUuid });
53
+ };
37
54
  registerAuthCommands(program, getApi);
38
55
  registerInitCommand(program, getApi);
39
56
  registerOrchestrationCommands(program, getApi);
40
- registerWorkspaceCommands(program, getApi);
57
+ registerWorkspaceManagementCommands(program, getApi);
41
58
  registerStorageCommands(program, getApi);
42
59
  registerConnectionCommands(program, getApi);
43
60
  registerContextCommands(program, getApi);
@@ -49,8 +66,5 @@ registerSystemOfRecordIntegrationCommands(program, getApi);
49
66
  registerUserManagementCommands(program, getApi);
50
67
  registerAiCommands(program, getApi);
51
68
  program.parseAsync().catch((err) => {
52
- console.error(JSON.stringify({
53
- error: err instanceof Error ? err.message : String(err),
54
- }));
55
- process.exit(1);
69
+ failWith(err instanceof Error ? err.message : String(err));
56
70
  });
@@ -0,0 +1,13 @@
1
+ export type OAuthConfig = {
2
+ domain: string;
3
+ clientId: string;
4
+ audience: string;
5
+ scope: string;
6
+ };
7
+ export type OAuthConfigOverrides = {
8
+ domain?: string;
9
+ clientId?: string;
10
+ audience?: string;
11
+ };
12
+ export declare function getOAuthConfig(overrides: OAuthConfigOverrides): OAuthConfig;
13
+ //# sourceMappingURL=oauthConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthConfig.d.ts","sourceRoot":"","sources":["../src/oauthConfig.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAOF,wBAAgB,cAAc,CAAC,SAAS,EAAE,oBAAoB,GAAG,WAAW,CAO3E"}
@@ -0,0 +1,17 @@
1
+ const DEFAULT_DOMAIN = "auth.getcargo.io";
2
+ const DEFAULT_AUDIENCE = "https://api.getcargo.io";
3
+ const DEFAULT_SCOPE = "openid profile email offline_access";
4
+ const DEFAULT_CLIENT_ID = "oUc99KlLSMAYUAPgxTUyqazef0sxR93b";
5
+ export function getOAuthConfig(overrides) {
6
+ return {
7
+ domain: pickString(overrides.domain, DEFAULT_DOMAIN),
8
+ audience: pickString(overrides.audience, DEFAULT_AUDIENCE),
9
+ clientId: pickString(overrides.clientId, DEFAULT_CLIENT_ID),
10
+ scope: DEFAULT_SCOPE,
11
+ };
12
+ }
13
+ const pickString = (override, fallback) => {
14
+ if (override !== undefined && override.length > 0)
15
+ return override;
16
+ return fallback;
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cargo-ai/cli",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "private": false,
5
5
  "description": "Command-line interface for the Cargo API",
6
6
  "engines": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "commander": "^12.1.0",
32
- "@cargo-ai/api": "^1.0.21"
32
+ "@cargo-ai/api": "^1.0.23"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@cargo-ai/eslint-config": "*",
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAWrC,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CAuIN"}
@@ -1,104 +0,0 @@
1
- import { clearCredentials, getCredentialsPath, loadCredentials, saveCredentials, } from "../credentials.js";
2
- import { handleApiCall, outputJson } from "./runHandler.js";
3
- const DEFAULT_BASE_URL = "https://api.getcargo.io";
4
- export function registerAuthCommands(program, getApi) {
5
- program
6
- .command("login")
7
- .description("Save API credentials for future use")
8
- .requiredOption("--token <token>", "Cargo API token (string)")
9
- .option("--workspace-uuid <uuid>", "Default workspace UUID (string, UUID v4)")
10
- .option("--base-url <url>", `API base URL (string, default: ${DEFAULT_BASE_URL})`)
11
- .addHelpText("after", `
12
- Examples:
13
- $ cargo-ai login --token sk_live_abc123
14
- $ cargo-ai login --token sk_live_abc123 --workspace-uuid 550e8400-e29b-41d4-a716-446655440000
15
- $ cargo-ai login --token sk_live_abc123 --base-url https://api.custom.io
16
-
17
- Credentials are stored in ~/.config/cargo-ai/credentials.json.
18
- Environment variables (CARGO_API_TOKEN, CARGO_WORKSPACE_UUID, CARGO_BASE_URL) take precedence over saved credentials.`)
19
- .action((opts) => {
20
- saveCredentials({
21
- accessToken: opts.token,
22
- workspaceUuid: opts.workspaceUuid,
23
- baseUrl: opts.baseUrl,
24
- });
25
- outputJson({
26
- ok: true,
27
- credentialsFile: getCredentialsPath(),
28
- baseUrl: opts.baseUrl !== undefined ? opts.baseUrl : DEFAULT_BASE_URL,
29
- workspaceUuid: opts.workspaceUuid !== undefined ? opts.workspaceUuid : null,
30
- });
31
- });
32
- program
33
- .command("logout")
34
- .description("Remove saved API credentials")
35
- .action(() => {
36
- const removed = clearCredentials();
37
- outputJson({
38
- ok: true,
39
- removed,
40
- credentialsFile: getCredentialsPath(),
41
- });
42
- });
43
- program
44
- .command("whoami")
45
- .description("Show current user and workspace")
46
- .addHelpText("after", `
47
- Returns JSON with: user (uuid, email, name), workspace (uuid, name),
48
- authentication source ("environment" or "credentials-file"), and base URL.`)
49
- .action(async () => {
50
- const envToken = process.env["CARGO_API_TOKEN"];
51
- const envBaseUrl = process.env["CARGO_BASE_URL"];
52
- const envWorkspace = process.env["CARGO_WORKSPACE_UUID"];
53
- const creds = loadCredentials();
54
- const hasToken = envToken !== undefined ||
55
- (creds !== undefined && creds.accessToken !== undefined);
56
- const baseUrl = envBaseUrl !== undefined
57
- ? envBaseUrl
58
- : creds !== undefined && creds.baseUrl !== undefined
59
- ? creds.baseUrl
60
- : DEFAULT_BASE_URL;
61
- const workspaceUuid = envWorkspace !== undefined
62
- ? envWorkspace
63
- : creds !== undefined
64
- ? creds.workspaceUuid
65
- : undefined;
66
- if (hasToken === false) {
67
- outputJson({
68
- user: null,
69
- workspace: null,
70
- source: "none",
71
- baseUrl,
72
- credentialsFile: getCredentialsPath(),
73
- warnings: [
74
- 'Not authenticated. Run "cargo-ai login --token <token>" or set CARGO_API_TOKEN.',
75
- ],
76
- });
77
- return;
78
- }
79
- const source = envToken !== undefined ? "environment" : "credentials-file";
80
- const api = getApi();
81
- const { user } = await handleApiCall(() => api.userManagement.user.getCurrent());
82
- const { workspaces } = await handleApiCall(() => api.workspaceManagement.workspace.all({ refresh: false }));
83
- const matchedWorkspace = workspaceUuid !== undefined
84
- ? workspaces.find((workspace) => {
85
- return workspace.uuid === workspaceUuid;
86
- })
87
- : workspaces[0];
88
- const workspace = matchedWorkspace !== undefined
89
- ? { uuid: matchedWorkspace.uuid, name: matchedWorkspace.name }
90
- : null;
91
- outputJson({
92
- user: {
93
- uuid: user.uuid,
94
- email: user.email,
95
- firstName: user.firstName,
96
- lastName: user.lastName,
97
- },
98
- workspace,
99
- source,
100
- baseUrl,
101
- credentialsFile: getCredentialsPath(),
102
- });
103
- });
104
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/file.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,IAAI,CA+C7E"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"folder.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/folder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CA6FN"}
@@ -1,4 +0,0 @@
1
- import type { Command } from "commander";
2
- import type { Api } from "../../api.js";
3
- export declare function registerWorkspaceCommands(parent: Command, getApi: () => Api): void;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAQxC,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CAWN"}
@@ -1,17 +0,0 @@
1
- import { registerFileCommands } from "./file.js";
2
- import { registerFolderCommands } from "./folder.js";
3
- import { registerRoleCommands } from "./role.js";
4
- import { registerTokenCommands } from "./token.js";
5
- import { registerUserCommands } from "./user.js";
6
- import { registerWorkspacesCommands } from "./workspaces.js";
7
- export function registerWorkspaceCommands(parent, getApi) {
8
- const workspace = parent
9
- .command("workspace")
10
- .description("Workspaces, users, tokens, roles, folders");
11
- registerWorkspacesCommands(workspace, getApi);
12
- registerUserCommands(workspace, getApi);
13
- registerTokenCommands(workspace, getApi);
14
- registerRoleCommands(workspace, getApi);
15
- registerFolderCommands(workspace, getApi);
16
- registerFileCommands(workspace, getApi);
17
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"role.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/role.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,IAAI,CAa7E"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CAoCN"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAIxC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,IAAI,CA0L7E"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CA0HN"}