@parall/cli 1.75.0 → 1.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/commands/approvals.d.ts.map +1 -1
  2. package/dist/commands/approvals.js +42 -13
  3. package/dist/commands/apps-action-local.d.ts +6 -1
  4. package/dist/commands/apps-action-local.d.ts.map +1 -1
  5. package/dist/commands/apps-action-local.js +11 -2
  6. package/dist/commands/apps-actions-sdk.generated.d.ts +1 -1
  7. package/dist/commands/apps-actions-sdk.generated.d.ts.map +1 -1
  8. package/dist/commands/apps-actions-sdk.generated.js +1 -1
  9. package/dist/commands/apps-actions.d.ts.map +1 -1
  10. package/dist/commands/apps-actions.js +13 -15
  11. package/dist/commands/apps-add.js +2 -2
  12. package/dist/commands/apps-args.d.ts +22 -0
  13. package/dist/commands/apps-args.d.ts.map +1 -0
  14. package/dist/commands/apps-args.js +62 -0
  15. package/dist/commands/apps-check.d.ts.map +1 -1
  16. package/dist/commands/apps-check.js +8 -3
  17. package/dist/commands/apps-db.d.ts +3 -1
  18. package/dist/commands/apps-db.d.ts.map +1 -1
  19. package/dist/commands/apps-db.js +4 -7
  20. package/dist/commands/apps-dev-server.d.ts +3 -0
  21. package/dist/commands/apps-dev-server.d.ts.map +1 -1
  22. package/dist/commands/apps-dev-server.js +4 -0
  23. package/dist/commands/apps-dev-vars.d.ts +38 -0
  24. package/dist/commands/apps-dev-vars.d.ts.map +1 -0
  25. package/dist/commands/apps-dev-vars.js +107 -0
  26. package/dist/commands/apps-dev.d.ts.map +1 -1
  27. package/dist/commands/apps-dev.js +2 -1
  28. package/dist/commands/apps-local-runner.generated.d.ts +2 -1
  29. package/dist/commands/apps-local-runner.generated.d.ts.map +1 -1
  30. package/dist/commands/apps-local-runner.generated.js +2 -1
  31. package/dist/commands/apps-publish.d.ts +3 -1
  32. package/dist/commands/apps-publish.d.ts.map +1 -1
  33. package/dist/commands/apps-publish.js +36 -24
  34. package/dist/commands/apps-templates.gen.js +3 -3
  35. package/dist/commands/apps.d.ts.map +1 -1
  36. package/dist/commands/apps.js +35 -40
  37. package/dist/commands/browser.d.ts.map +1 -1
  38. package/dist/commands/browser.js +1 -0
  39. package/dist/commands/comments.d.ts.map +1 -1
  40. package/dist/commands/comments.js +3 -2
  41. package/dist/commands/db-plane.d.ts +5 -14
  42. package/dist/commands/db-plane.d.ts.map +1 -1
  43. package/dist/commands/db-plane.js +63 -32
  44. package/dist/commands/db-target.d.ts +22 -0
  45. package/dist/commands/db-target.d.ts.map +1 -0
  46. package/dist/commands/db-target.js +43 -0
  47. package/dist/commands/dbs.d.ts +3 -6
  48. package/dist/commands/dbs.d.ts.map +1 -1
  49. package/dist/commands/dbs.js +28 -34
  50. package/dist/commands/secrets.d.ts +3 -0
  51. package/dist/commands/secrets.d.ts.map +1 -0
  52. package/dist/commands/secrets.js +66 -0
  53. package/dist/index.js +18 -2
  54. package/dist/lib/approvers.d.ts +12 -0
  55. package/dist/lib/approvers.d.ts.map +1 -0
  56. package/dist/lib/approvers.js +48 -0
  57. package/dist/lib/browser-operation.d.ts.map +1 -1
  58. package/dist/lib/browser-operation.js +4 -1
  59. package/dist/lib/output.d.ts +19 -0
  60. package/dist/lib/output.d.ts.map +1 -1
  61. package/dist/lib/output.js +59 -2
  62. package/dist/lib/update-check.d.ts +4 -0
  63. package/dist/lib/update-check.d.ts.map +1 -1
  64. package/dist/lib/update-check.js +3 -1
  65. package/package.json +4 -4
@@ -2,6 +2,18 @@ import { promises as fs } from 'node:fs';
2
2
  import { resolveCredentials } from '../lib/client.js';
3
3
  import { printError, printJson } from '../lib/output.js';
4
4
  import { resolveApiToken } from '../lib/wiki-shared.js';
5
+ import { outputPath } from './apps-args.js';
6
+ import { resolveDataPlaneTarget } from './db-target.js';
7
+ /** The result of these commands is JSON on stdout, always: --output json
8
+ * (a form scripts reach for) is accepted, any other format refused. */
9
+ function jsonOutput(cmd) {
10
+ return cmd.option('--output <format>', 'Output format: json, the only one (the default)');
11
+ }
12
+ function checkJsonOutput(format) {
13
+ if (format !== undefined && format.trim().toLowerCase() !== 'json') {
14
+ throw new Error(`--output ${format}: the result is always JSON on stdout; to keep it in a file, redirect stdout (> result.json)`);
15
+ }
16
+ }
5
17
  /** The raw-SQL data plane (design §5, §7.2, §8) — a construction surface
6
18
  * for the authors of the apps attached to the Database and for org
7
19
  * owners/admins, not the member product surface (that will be app-defined
@@ -13,22 +25,31 @@ import { resolveApiToken } from '../lib/wiki-shared.js';
13
25
  * always refused with DB_DDL_APPROVAL_REQUIRED. */
14
26
  export function registerDataPlaneCommands(group, binding) {
15
27
  const withTarget = (cmd) => {
16
- cmd.requiredOption(binding.flag, binding.flagHelp);
28
+ cmd.argument('[target]', 'The app (app_…) or Database (adb_… or its name); or pass --app / --db');
29
+ const app = {
30
+ flag: '--app <appId>',
31
+ help: 'App ID (app_… or prll://app_…): its Database, with the app recorded on the SQL log',
32
+ };
33
+ const db = { flag: '--db <idOrName>', help: 'Database ID (adb_… or prll://adb_…) or its name' };
34
+ for (const target of binding.primary === 'app' ? [app, db] : [db, app]) {
35
+ cmd.option(target.flag, target.help);
36
+ }
17
37
  for (const extra of binding.extraOptions ?? []) {
18
38
  cmd.option(extra.flag, extra.help);
19
39
  }
20
40
  return cmd;
21
41
  };
22
- withTarget(group
42
+ jsonOutput(withTarget(group
23
43
  .command('query')
24
- .description('Run one read-only statement (attached-app author or org owner/admin)'))
44
+ .description('Run one read-only statement (attached-app author or org owner/admin)')))
25
45
  .option('--sql <sql>', 'SQL text')
26
46
  .option('--file <path>', 'Read the SQL from a file (- for stdin)')
27
47
  .option('--param <value...>', 'Positional parameters $1..$n; JSON values (42, "text", true, null) or bare text')
28
- .action(async (opts) => {
48
+ .action(async (name, opts) => {
29
49
  try {
50
+ checkJsonOutput(opts.output);
30
51
  const ctx = resolveCredentials();
31
- const target = await binding.resolve(ctx, opts);
52
+ const target = await resolveDataPlaneTarget(ctx, name, opts);
32
53
  const sql = await readSql(opts);
33
54
  printJson(await query(ctx, target, { sql, params: parseParams(opts.param) }));
34
55
  }
@@ -36,17 +57,18 @@ export function registerDataPlaneCommands(group, binding) {
36
57
  printError(err);
37
58
  }
38
59
  });
39
- withTarget(group
60
+ jsonOutput(withTarget(group
40
61
  .command('exec')
41
- .description('Run statements in one transaction: data writes or schema changes (snapshot first); attached-app author or org owner/admin'))
62
+ .description('Run statements in one transaction: data writes or schema changes (snapshot first); attached-app author or org owner/admin')))
42
63
  .option('--sql <sql>', 'SQL text (several statements separated by ;)')
43
64
  .option('--file <path>', 'Read the SQL from a file (- for stdin)')
44
65
  .option('--param <value...>', 'Positional parameters $1..$n (single statement only)')
45
66
  .option('--dry-run', 'Execute inside the transaction and roll back')
46
- .action(async (opts) => {
67
+ .action(async (name, opts) => {
47
68
  try {
69
+ checkJsonOutput(opts.output);
48
70
  const ctx = resolveCredentials();
49
- const target = await binding.resolve(ctx, opts);
71
+ const target = await resolveDataPlaneTarget(ctx, name, opts);
50
72
  const sql = await readSql(opts);
51
73
  printJson(await exec(ctx, target, {
52
74
  sql,
@@ -58,12 +80,14 @@ export function registerDataPlaneCommands(group, binding) {
58
80
  printError(err);
59
81
  }
60
82
  });
61
- withTarget(group
83
+ jsonOutput(withTarget(group
62
84
  .command('schema')
63
- .description('Describe the schema: tables, columns, primary keys, enums')).action(async (opts) => {
85
+ .alias('tables')
86
+ .description('Describe the schema: tables, columns, primary keys, enums'))).action(async (name, opts) => {
64
87
  try {
88
+ checkJsonOutput(opts.output);
65
89
  const ctx = resolveCredentials();
66
- printJson(await schema(ctx, await binding.resolve(ctx, opts)));
90
+ printJson(await schema(ctx, await resolveDataPlaneTarget(ctx, name, opts)));
67
91
  }
68
92
  catch (err) {
69
93
  printError(err);
@@ -71,13 +95,15 @@ export function registerDataPlaneCommands(group, binding) {
71
95
  });
72
96
  withTarget(group.command('types').description('Generate TypeScript types for the schema'))
73
97
  .option('--out <file>', 'Write the declarations to a file instead of stdout')
74
- .action(async (opts) => {
98
+ .option('--output <file>', 'Same as --out')
99
+ .action(async (name, opts) => {
75
100
  try {
101
+ const out = outputPath(opts);
76
102
  const ctx = resolveCredentials();
77
- const result = await types(ctx, await binding.resolve(ctx, opts));
78
- if (opts.out) {
79
- await fs.writeFile(opts.out, result.source, 'utf8');
80
- console.error(`Wrote ${opts.out}`);
103
+ const result = await types(ctx, await resolveDataPlaneTarget(ctx, name, opts));
104
+ if (out) {
105
+ await fs.writeFile(out, result.source, 'utf8');
106
+ console.error(`Wrote ${out}`);
81
107
  }
82
108
  else {
83
109
  process.stdout.write(result.source);
@@ -90,13 +116,15 @@ export function registerDataPlaneCommands(group, binding) {
90
116
  withTarget(group.command('dump').description('Plain-SQL pg_dump of the schema (or one table)'))
91
117
  .option('--table <name>', 'Only this table')
92
118
  .option('--out <file>', 'Write the dump to a file instead of stdout')
93
- .action(async (opts) => {
119
+ .option('--output <file>', 'Same as --out')
120
+ .action(async (name, opts) => {
94
121
  try {
122
+ const out = outputPath(opts);
95
123
  const ctx = resolveCredentials();
96
- const sql = await downloadDump(ctx, await binding.resolve(ctx, opts), opts.table);
97
- if (opts.out) {
98
- await fs.writeFile(opts.out, sql, 'utf8');
99
- console.error(`Wrote ${opts.out} (${sql.length} bytes)`);
124
+ const sql = await downloadDump(ctx, await resolveDataPlaneTarget(ctx, name, opts), opts.table);
125
+ if (out) {
126
+ await fs.writeFile(out, sql, 'utf8');
127
+ console.error(`Wrote ${out} (${sql.length} bytes)`);
100
128
  }
101
129
  else {
102
130
  process.stdout.write(sql);
@@ -106,16 +134,17 @@ export function registerDataPlaneCommands(group, binding) {
106
134
  printError(err);
107
135
  }
108
136
  });
109
- withTarget(group
137
+ jsonOutput(withTarget(group
110
138
  .command('log')
111
- .description('SQL log: execs with actor, app, role, rows, data_seq and errors'))
139
+ .description('SQL log: execs with actor, app, role, rows, data_seq and errors')))
112
140
  .option('--limit <n>', 'Entries to return (default 50, max 200)')
113
141
  .option('--before <rfc3339>', 'Entries created before this instant')
114
142
  .option('--invocation <aci_id>', "Only one action invocation's statements")
115
- .action(async (opts) => {
143
+ .action(async (name, opts) => {
116
144
  try {
145
+ checkJsonOutput(opts.output);
117
146
  const ctx = resolveCredentials();
118
- printJson(await log(ctx, await binding.resolve(ctx, opts), {
147
+ printJson(await log(ctx, await resolveDataPlaneTarget(ctx, name, opts), {
119
148
  limit: opts.limit ? Number(opts.limit) : undefined,
120
149
  before: opts.before,
121
150
  invocation_id: opts.invocation,
@@ -125,23 +154,25 @@ export function registerDataPlaneCommands(group, binding) {
125
154
  printError(err);
126
155
  }
127
156
  });
128
- withTarget(group.command('snapshots').description('Restore points taken before schema changes')).action(async (opts) => {
157
+ jsonOutput(withTarget(group.command('snapshots').description('Restore points taken before schema changes'))).action(async (name, opts) => {
129
158
  try {
159
+ checkJsonOutput(opts.output);
130
160
  const ctx = resolveCredentials();
131
- printJson(await snapshots(ctx, await binding.resolve(ctx, opts)));
161
+ printJson(await snapshots(ctx, await resolveDataPlaneTarget(ctx, name, opts)));
132
162
  }
133
163
  catch (err) {
134
164
  printError(err);
135
165
  }
136
166
  });
137
- withTarget(group
167
+ jsonOutput(withTarget(group
138
168
  .command('restore')
139
- .description('Replace the schema with a snapshot; the current state is snapshotted first'))
169
+ .description('Replace the schema with a snapshot; the current state is snapshotted first')))
140
170
  .requiredOption('--to <logId>', 'log_id of the snapshot (see `snapshots`)')
141
- .action(async (opts) => {
171
+ .action(async (name, opts) => {
142
172
  try {
173
+ checkJsonOutput(opts.output);
143
174
  const ctx = resolveCredentials();
144
- printJson(await restore(ctx, await binding.resolve(ctx, opts), opts.to));
175
+ printJson(await restore(ctx, await resolveDataPlaneTarget(ctx, name, opts), opts.to));
145
176
  }
146
177
  catch (err) {
147
178
  printError(err);
@@ -0,0 +1,22 @@
1
+ import type { resolveCredentials } from '../lib/client.js';
2
+ type Ctx = ReturnType<typeof resolveCredentials>;
3
+ /** What a data-plane command runs against: a Database directly, or an app
4
+ * (the alias: the app's Database, with the app recorded on the log row). */
5
+ export interface DataPlaneTarget {
6
+ kind: 'app' | 'db';
7
+ id: string;
8
+ }
9
+ type TargetOptions = {
10
+ app?: string;
11
+ db?: string;
12
+ };
13
+ /** The target a command names, by what it is: an app ID runs through the
14
+ * app, a Database ID or name on the Database. Given more than once, every
15
+ * form must name the same thing; --app takes IDs only (apps have no name
16
+ * lookup here). */
17
+ export declare function resolveDataPlaneTarget(ctx: Ctx, positional: string | undefined, opts: TargetOptions): Promise<DataPlaneTarget>;
18
+ /** A Database is addressed by id, or by its name — unique in the org,
19
+ * case-insensitively. */
20
+ export declare function resolveDatabaseId(ctx: Ctx, idOrName: string): Promise<string>;
21
+ export {};
22
+ //# sourceMappingURL=db-target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-target.d.ts","sourceRoot":"","sources":["../../src/commands/db-target.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3D,KAAK,GAAG,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEjD;4EAC4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,KAAK,aAAa,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAOnD;;;mBAGmB;AACnB,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,eAAe,CAAC,CAmB1B;AAED;yBACyB;AACzB,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAYnF"}
@@ -0,0 +1,43 @@
1
+ import { stripPrllScheme } from '../lib/output.js';
2
+ function clean(value) {
3
+ const v = value === undefined ? '' : stripPrllScheme(value.trim());
4
+ return v === '' ? undefined : v;
5
+ }
6
+ /** The target a command names, by what it is: an app ID runs through the
7
+ * app, a Database ID or name on the Database. Given more than once, every
8
+ * form must name the same thing; --app takes IDs only (apps have no name
9
+ * lookup here). */
10
+ export async function resolveDataPlaneTarget(ctx, positional, opts) {
11
+ const app = clean(opts.app);
12
+ if (app && !app.startsWith('app_') && !app.startsWith('adb_')) {
13
+ throw new Error(`--app takes an app ID (app_…); name a Database by its name with --db ${app}`);
14
+ }
15
+ const named = [
16
+ ...new Set([clean(positional), app, clean(opts.db)].filter((v) => v !== undefined)),
17
+ ];
18
+ if (named.length === 0) {
19
+ throw new Error('Name the target: an app (--app app_…) or a Database (--db adb_… or its name), or pass it as the first argument');
20
+ }
21
+ if (named.length > 1) {
22
+ throw new Error(`Name the target once: got ${named.join(' and ')}`);
23
+ }
24
+ const value = named[0];
25
+ if (value.startsWith('app_'))
26
+ return { kind: 'app', id: value };
27
+ return { kind: 'db', id: await resolveDatabaseId(ctx, value) };
28
+ }
29
+ /** A Database is addressed by id, or by its name — unique in the org,
30
+ * case-insensitively. */
31
+ export async function resolveDatabaseId(ctx, idOrName) {
32
+ const value = stripPrllScheme(idOrName.trim());
33
+ if (value === '')
34
+ throw new Error('Pass a Database ID or name');
35
+ if (value.startsWith('adb_'))
36
+ return value;
37
+ const all = await ctx.client.getMiniAppDatabases(ctx.orgId);
38
+ const match = all.find((d) => d.name.toLowerCase() === value.toLowerCase());
39
+ if (!match) {
40
+ throw new Error(`No database named ${JSON.stringify(value)}; pass its adb_ id or check \`parall db list\``);
41
+ }
42
+ return match.id;
43
+ }
@@ -1,16 +1,13 @@
1
1
  import type { Command } from 'commander';
2
- import { resolveCredentials } from '../lib/client.js';
3
2
  /** Database entity: a PostgreSQL schema of its own inside the org's
4
3
  * database on the apps instance (docs/engineering-design/mini-app-design.md
5
4
  * §4, §5). Databases belong to the organization; apps of the org attach to
6
5
  * one, and it may also stand alone. This file manages the entity (visible
7
6
  * to every org member); the raw-SQL data plane (query / exec / schema / …)
8
7
  * is db-plane.ts — a construction surface for attached-app authors and org
9
- * owners/admins — mounted here with `--db` and under `parall app db` with
10
- * `--app`. Every command answers 404 while the deployment has cap:mini-apps
8
+ * owners/admins — mounted here and under `parall app db`, both taking the
9
+ * target as an argument, --db or --app (db-target.ts). Every command
10
+ * answers 404 while the deployment has cap:mini-apps
11
11
  * off and 403 MINI_APPS_UNAVAILABLE for an org without the mini-apps flag. */
12
12
  export declare function registerDbCommands(program: Command): void;
13
- /** A Database is addressed by id, or by its name — unique in the org,
14
- * case-insensitively. */
15
- export declare function resolveDatabaseId(ctx: ReturnType<typeof resolveCredentials>, idOrName: string): Promise<string>;
16
13
  //# sourceMappingURL=dbs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dbs.d.ts","sourceRoot":"","sources":["../../src/commands/dbs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtD;;;;;;;;8EAQ8E;AAC9E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,QAgGlD;AASD;yBACyB;AACzB,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,EAC1C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAYjB"}
1
+ {"version":3,"file":"dbs.d.ts","sourceRoot":"","sources":["../../src/commands/dbs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASzC;;;;;;;;;8EAS8E;AAC9E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,QA0FlD"}
@@ -1,6 +1,7 @@
1
1
  import { resolveCredentials } from '../lib/client.js';
2
2
  import { printError, printJson, printRefHint, stripPrllScheme } from '../lib/output.js';
3
3
  import { registerDataPlaneCommands } from './db-plane.js';
4
+ import { resolveDatabaseId } from './db-target.js';
4
5
  const DEPRECATED_PROJECT = 'Deprecated and ignored: Databases belong to the organization and names are unique in it';
5
6
  /** Database entity: a PostgreSQL schema of its own inside the org's
6
7
  * database on the apps instance (docs/engineering-design/mini-app-design.md
@@ -8,18 +9,17 @@ const DEPRECATED_PROJECT = 'Deprecated and ignored: Databases belong to the orga
8
9
  * one, and it may also stand alone. This file manages the entity (visible
9
10
  * to every org member); the raw-SQL data plane (query / exec / schema / …)
10
11
  * is db-plane.ts — a construction surface for attached-app authors and org
11
- * owners/admins — mounted here with `--db` and under `parall app db` with
12
- * `--app`. Every command answers 404 while the deployment has cap:mini-apps
12
+ * owners/admins — mounted here and under `parall app db`, both taking the
13
+ * target as an argument, --db or --app (db-target.ts). Every command
14
+ * answers 404 while the deployment has cap:mini-apps
13
15
  * off and 403 MINI_APPS_UNAVAILABLE for an org without the mini-apps flag. */
14
16
  export function registerDbCommands(program) {
15
17
  const db = program
16
18
  .command('db')
17
19
  .description('Manage Databases (Mini App data); the SQL commands are the construction surface of app authors and org owners/admins');
18
20
  registerDataPlaneCommands(db, {
19
- flag: '--db <idOrName>',
20
- flagHelp: 'Database ID (adb_… or prll://adb_…) or its name',
21
+ primary: 'db',
21
22
  extraOptions: [{ flag: '--project <projectId>', help: DEPRECATED_PROJECT }],
22
- resolve: resolveDatabaseTarget,
23
23
  });
24
24
  db.command('list')
25
25
  .description("List the organization's Databases")
@@ -33,14 +33,12 @@ export function registerDbCommands(program) {
33
33
  printError(err);
34
34
  }
35
35
  });
36
- db.command('get')
37
- .description('Get a Database and the apps attached to it')
38
- .argument('<idOrName>', 'Database ID or its name')
36
+ withDb(db.command('get').description('Get a Database and the apps attached to it'))
39
37
  .option('--project <projectId>', DEPRECATED_PROJECT)
40
- .action(async (idOrName) => {
38
+ .action(async (idOrName, opts) => {
41
39
  try {
42
40
  const ctx = resolveCredentials();
43
- const id = await resolveDatabaseId(ctx, idOrName);
41
+ const id = await resolveDatabaseId(ctx, databaseFrom(idOrName, opts.db));
44
42
  printJson(await ctx.client.getMiniAppDatabase(ctx.orgId, id));
45
43
  }
46
44
  catch (err) {
@@ -66,9 +64,7 @@ export function registerDbCommands(program) {
66
64
  printError(err);
67
65
  }
68
66
  });
69
- db.command('update')
70
- .description('Update a Database (org owner/admin)')
71
- .argument('<idOrName>', 'Database ID or its name')
67
+ withDb(db.command('update').description('Update a Database (org owner/admin)'))
72
68
  .option('--project <projectId>', DEPRECATED_PROJECT)
73
69
  .option('--name <name>', 'New name')
74
70
  .option('--description <text>', 'New description (empty string clears)')
@@ -83,21 +79,19 @@ export function registerDbCommands(program) {
83
79
  if (Object.keys(data).length === 0) {
84
80
  throw new Error('Nothing to update: pass --name or --description');
85
81
  }
86
- const id = await resolveDatabaseId(ctx, idOrName);
82
+ const id = await resolveDatabaseId(ctx, databaseFrom(idOrName, opts.db));
87
83
  printJson(await ctx.client.updateMiniAppDatabase(ctx.orgId, id, data));
88
84
  }
89
85
  catch (err) {
90
86
  printError(err);
91
87
  }
92
88
  });
93
- db.command('delete')
94
- .description('Delete a Database nothing is attached to (org owner/admin)')
95
- .argument('<idOrName>', 'Database ID or its name')
89
+ withDb(db.command('delete').description('Delete a Database nothing is attached to (org owner/admin)'))
96
90
  .option('--project <projectId>', DEPRECATED_PROJECT)
97
- .action(async (idOrName) => {
91
+ .action(async (idOrName, opts) => {
98
92
  try {
99
93
  const ctx = resolveCredentials();
100
- const id = await resolveDatabaseId(ctx, idOrName);
94
+ const id = await resolveDatabaseId(ctx, databaseFrom(idOrName, opts.db));
101
95
  await ctx.client.deleteMiniAppDatabase(ctx.orgId, id);
102
96
  console.error(`Deleted ${id}`);
103
97
  }
@@ -106,21 +100,21 @@ export function registerDbCommands(program) {
106
100
  }
107
101
  });
108
102
  }
109
- async function resolveDatabaseTarget(ctx, opts) {
110
- return { kind: 'db', id: await resolveDatabaseId(ctx, opts.db ?? '') };
103
+ /** The Database an entity command names: as the argument or with --db,
104
+ * like the SQL commands (db-target.ts). */
105
+ function withDb(cmd) {
106
+ return cmd
107
+ .argument('[idOrName]', 'Database ID or its name; or pass --db')
108
+ .option('--db <idOrName>', 'Database ID or its name, in place of the argument');
111
109
  }
112
- /** A Database is addressed by id, or by its name — unique in the org,
113
- * case-insensitively. */
114
- export async function resolveDatabaseId(ctx, idOrName) {
115
- const value = stripPrllScheme(idOrName.trim());
116
- if (value === '')
117
- throw new Error('Pass a Database ID or name');
118
- if (value.startsWith('adb_'))
119
- return value;
120
- const all = await ctx.client.getMiniAppDatabases(ctx.orgId);
121
- const match = all.find((d) => d.name.toLowerCase() === value.toLowerCase());
122
- if (!match) {
123
- throw new Error(`No database named ${JSON.stringify(value)}; pass its adb_ id or check \`parall db list\``);
110
+ function databaseFrom(positional, flag) {
111
+ const arg = positional === undefined ? undefined : stripPrllScheme(positional.trim()) || undefined;
112
+ const opt = flag === undefined ? undefined : stripPrllScheme(flag.trim()) || undefined;
113
+ if (arg && opt && arg !== opt) {
114
+ throw new Error(`Name the Database once: the argument says ${arg}, --db says ${opt}`);
124
115
  }
125
- return match.id;
116
+ const value = arg ?? opt;
117
+ if (!value)
118
+ throw new Error('Name the Database: its ID (adb_…) or name, as the argument or with --db');
119
+ return value;
126
120
  }
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function registerSecretCommands(program: Command): void;
3
+ //# sourceMappingURL=secrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/commands/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,QA2EtD"}
@@ -0,0 +1,66 @@
1
+ import { printFiledApproval } from '../lib/approvers.js';
2
+ import { resolveCredentials } from '../lib/client.js';
3
+ import { printError, printJson, printProgress, stripPrllScheme } from '../lib/output.js';
4
+ // Secrets as an agent sees them (agent-secrets-design.md §12). An agent can
5
+ // list the names it has or may ask to use, and post a request card; it can
6
+ // never read or store a value — a person enters it on the card. `request` is
7
+ // shorthand for `approvals request` with the right action, target and payload.
8
+ export function registerSecretCommands(program) {
9
+ const secrets = program
10
+ .command('secrets')
11
+ .description('See the keys you have and ask a person for one');
12
+ secrets
13
+ .command('list')
14
+ .description("List the keys you have and the organization's shared keys you may ask to use (names and purposes, never values), plus your requests still waiting")
15
+ .action(async () => {
16
+ try {
17
+ const { client, orgId } = resolveCredentials();
18
+ printJson(await client.getMyAgentSecretCatalog(orgId));
19
+ }
20
+ catch (err) {
21
+ printError(err);
22
+ }
23
+ });
24
+ secrets
25
+ .command('request')
26
+ .description('Post a request card for a key. The person who manages you, or an org admin, enters the value on the card and approves; a key of yours with the same name gets the new value.')
27
+ .argument('<name>', 'The key name your commands will read, e.g. GITHUB_TOKEN')
28
+ .requiredOption('--purpose <text>', 'One line for a non-engineer on what the key is for')
29
+ .requiredOption('--chat <chatId>', 'Chat to post the card in — the one you are working in (e.g. prll://cht_456)')
30
+ .option('--where <text>', 'Where a person can get such a key, if you know')
31
+ .option('--shared', "Ask to use the organization's shared key of this name instead: an org admin approves and nobody enters a value")
32
+ .action(async (name, opts) => {
33
+ try {
34
+ if (opts.shared && opts.where !== undefined) {
35
+ throw new Error('--where does not apply with --shared: nobody enters a value for a shared key');
36
+ }
37
+ const { client, orgId } = resolveCredentials();
38
+ const result = await client.requestApproval(orgId, opts.shared
39
+ ? {
40
+ action_type: 'org.secret.agent.add',
41
+ resource_uri: `prll://${orgId}`,
42
+ action_payload: { name, purpose: opts.purpose },
43
+ chat_id: stripPrllScheme(opts.chat),
44
+ // The server writes the title; the endpoint still requires one.
45
+ title: name,
46
+ }
47
+ : {
48
+ action_type: 'agent.secret.request',
49
+ resource_uri: `prll://${(await client.getMe()).id}`,
50
+ action_payload: {
51
+ name,
52
+ purpose: opts.purpose,
53
+ ...(opts.where !== undefined ? { source: opts.where } : {}),
54
+ },
55
+ chat_id: stripPrllScheme(opts.chat),
56
+ title: name,
57
+ });
58
+ printJson(result);
59
+ printFiledApproval(result, result.deduplicated ? 'Already waiting' : 'Created');
60
+ printProgress('Now tell the people above, by name, what the key is for, then end your turn. You are woken when it is decided and the key is usable from that turn — do not wait with `parall approvals wait`.');
61
+ }
62
+ catch (err) {
63
+ printError(err);
64
+ }
65
+ });
66
+ }
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ import { registerProjectCommands } from './commands/projects.js';
20
20
  import { registerRefCommands } from './commands/refs.js';
21
21
  import { registerScheduleCommands } from './commands/schedules.js';
22
22
  import { registerSearchCommands } from './commands/search.js';
23
+ import { registerSecretCommands } from './commands/secrets.js';
23
24
  import { registerSlackCommands } from './commands/slack.js';
24
25
  import { registerTaskCommands } from './commands/tasks.js';
25
26
  import { registerTeamCommands } from './commands/teams.js';
@@ -29,7 +30,7 @@ import { registerWatchCommands } from './commands/watch.js';
29
30
  import { registerWechatCommands } from './commands/wechat.js';
30
31
  import { registerWikiCommands } from './commands/wiki.js';
31
32
  import { registerMiniAppCommands } from './lib/mini-app-discovery.js';
32
- import { printError } from './lib/output.js';
33
+ import { printError, stderrJoinsStdout } from './lib/output.js';
33
34
  import { createUpdateNotifier } from './lib/update-check.js';
34
35
  const version = typeof __PARALL_CLI_VERSION__ === 'string'
35
36
  ? __PARALL_CLI_VERSION__
@@ -39,6 +40,18 @@ program
39
40
  .name('parall')
40
41
  .description('CLI client for Parall — universal agent & human access to Parall API')
41
42
  .version(version);
43
+ // A command, option or argument this CLI does not know may simply be newer
44
+ // than it: instructions and skills describe the current release. Saying
45
+ // which version answered lets an agent tell a typo from an old install.
46
+ // Commander shares this output configuration with every subcommand.
47
+ program.configureOutput({
48
+ outputError: (str, write) => {
49
+ write(str);
50
+ if (/^error: (unknown command|unknown option|too many arguments)/.test(str)) {
51
+ write(`(this is parall ${version}; if your instructions name this command or option, update the CLI: npm install -g @parall/cli@latest)\n`);
52
+ }
53
+ },
54
+ });
42
55
  registerAgentCommands(program);
43
56
  registerApprovalCommands(program);
44
57
  registerChatCommands(program);
@@ -50,6 +63,7 @@ registerCommentCommands(program);
50
63
  registerLabelCommands(program);
51
64
  registerProjectCommands(program);
52
65
  registerProfileCommands(program);
66
+ registerSecretCommands(program);
53
67
  registerTeamCommands(program);
54
68
  registerScheduleCommands(program);
55
69
  registerTriggerCommands(program);
@@ -66,7 +80,9 @@ registerBrowserCommands(program);
66
80
  registerSlackCommands(program);
67
81
  registerMSTeamsCommands(program);
68
82
  registerWechatCommands(program);
69
- const updateNotifier = createUpdateNotifier(version);
83
+ const updateNotifier = createUpdateNotifier(version, {
84
+ canWriteHint: () => !stderrJoinsStdout(),
85
+ });
70
86
  program.hook('postAction', () => {
71
87
  if (process.exitCode === undefined || process.exitCode === 0) {
72
88
  updateNotifier.afterSuccessfulCommand();
@@ -0,0 +1,12 @@
1
+ import type { Approval, ApprovalApprovers, ApprovalWarning } from '@parall/sdk';
2
+ /** One line naming who can approve, with where each of them would see it. */
3
+ export declare function describeApprovers(set: ApprovalApprovers | null | undefined): string | undefined;
4
+ /** Prints who can approve and any advice, after the JSON result. */
5
+ export declare function printApprovers(set: ApprovalApprovers | null | undefined, warnings: ApprovalWarning[] | null | undefined, approvalId?: string): void;
6
+ /**
7
+ * Prints where a filed request is: the card's message link to point people
8
+ * at in chat (a request id is not a reference chat can show), and the
9
+ * request id for get, wait and cancel. Then who can approve it.
10
+ */
11
+ export declare function printFiledApproval(result: Approval, verb: string): void;
12
+ //# sourceMappingURL=approvers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approvers.d.ts","sourceRoot":"","sources":["../../src/lib/approvers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGhF,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAoB/F;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAC5B,GAAG,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,EACzC,QAAQ,EAAE,eAAe,EAAE,GAAG,IAAI,GAAG,SAAS,EAC9C,UAAU,CAAC,EAAE,MAAM,GAClB,IAAI,CAWN;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAIvE"}
@@ -0,0 +1,48 @@
1
+ import { printProgress } from './output.js';
2
+ /** One line naming who can approve, with where each of them would see it. */
3
+ export function describeApprovers(set) {
4
+ const users = set?.users;
5
+ if (!set || !users)
6
+ return undefined;
7
+ if (users.length === 0) {
8
+ return set.incomplete
9
+ ? 'Nobody found who can approve this, but some members could not be checked.'
10
+ : 'Nobody in this organization can approve this.';
11
+ }
12
+ const people = users.map((u) => {
13
+ const where = [];
14
+ if (u.in_chat !== undefined)
15
+ where.push(u.in_chat ? 'in this chat' : 'not in this chat');
16
+ if (u.in_inbox)
17
+ where.push('in their Inbox');
18
+ return where.length > 0 ? `${u.display_name} (${where.join(', ')})` : u.display_name;
19
+ });
20
+ const total = set.total ?? users.length;
21
+ const more = total > users.length ? `; ${total - users.length} more not listed` : '';
22
+ const partial = set.incomplete
23
+ ? ' Some members could not be checked; someone may be missing.'
24
+ : '';
25
+ return `Can approve (${total}): ${people.join(', ')}${more}.${partial}`;
26
+ }
27
+ /** Prints who can approve and any advice, after the JSON result. */
28
+ export function printApprovers(set, warnings, approvalId) {
29
+ const line = describeApprovers(set);
30
+ if (line)
31
+ printProgress(line);
32
+ for (const w of warnings ?? []) {
33
+ printProgress(`Warning (${w.code}): ${w.message}`);
34
+ if (w.code === 'NO_APPROVER_IN_CHAT' && approvalId) {
35
+ printProgress(`Withdraw this one before filing elsewhere: parall approvals cancel ${approvalId}`);
36
+ }
37
+ }
38
+ }
39
+ /**
40
+ * Prints where a filed request is: the card's message link to point people
41
+ * at in chat (a request id is not a reference chat can show), and the
42
+ * request id for get, wait and cancel. Then who can approve it.
43
+ */
44
+ export function printFiledApproval(result, verb) {
45
+ const card = result.message_id ? `card prll://${result.message_id} (link it in chat); ` : '';
46
+ printProgress(`${verb}: ${card}request ${result.id} (for parall approvals get/wait/cancel)`);
47
+ printApprovers(result.approvers, result.warnings, result.id);
48
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"browser-operation.d.ts","sourceRoot":"","sources":["../../src/lib/browser-operation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,0BAA0B,EAG1B,YAAY,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,KAAK,MAAM,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACnG,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IACpC,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAUF,wBAAgB,YAAY,CAC1B,GAAG,EAAE,OAAO,EACZ,MAAM,GAAE,MAAW,EACnB,iBAAiB,UAAQ,GACxB,cAAc,CA+ChB;AACD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,0BAA0B,EACnC,WAAW,UAAQ,GAClB,cAAc,CAsChB;AAED,oFAAoF;AACpF,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,EACtD,KAAK;;gBAAgC,MAAM;CAAkD,GAC5F,OAAO,CAAC,cAAc,CAAC,CAoFzB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CA8BjF"}
1
+ {"version":3,"file":"browser-operation.d.ts","sourceRoot":"","sources":["../../src/lib/browser-operation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,0BAA0B,EAG1B,YAAY,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,KAAK,MAAM,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACnG,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IACpC,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAYF,wBAAgB,YAAY,CAC1B,GAAG,EAAE,OAAO,EACZ,MAAM,GAAE,MAAW,EACnB,iBAAiB,UAAQ,GACxB,cAAc,CA+ChB;AACD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,0BAA0B,EACnC,WAAW,UAAQ,GAClB,cAAc,CAwChB;AAED,oFAAoF;AACpF,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,EACtD,KAAK;;gBAAgC,MAAM;CAAkD,GAC5F,OAAO,CAAC,cAAc,CAAC,CAoFzB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CA8BjF"}
@@ -1,6 +1,7 @@
1
1
  import { randomBytes, webcrypto } from 'node:crypto';
2
2
  import { ApiError, BrowserUseValidationError, validateBrowserUseReceipt } from '@parall/sdk';
3
3
  const recovery = (operationId, profileId) => `Do not retry the action. Check the original operation without running it again: parall browser operation get ${operationId} --profile ${profileId} --json`;
4
+ const dialogRecovery = (receipt) => `The page is paused on a JavaScript dialog; do not repeat the action. Read it: parall browser dialog --profile ${receipt.profile_id}${receipt.tab_id ? ` --tab ${receipt.tab_id} --browser-generation ${receipt.browser_generation}` : ' --tab <btab_id> --browser-generation <n>'} --json, then answer it with --accept true or --accept false. Nothing answers it for you.`;
4
5
  const publicText = (value) => value.length <= 1024 &&
5
6
  !/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/u.test(value) &&
6
7
  !/\b(?:agk_|pk_|sk_|edg_)|dispatch[_ -]?claim|grant[_ -]?proof/iu.test(value)
@@ -86,7 +87,9 @@ export function browserReceiptOutcome(receipt, waitExpired = false) {
86
87
  message: publicText(receipt.error.message ?? 'Browser Use did not succeed.'),
87
88
  hint: receipt.error.code === 'CANCELLED'
88
89
  ? 'Stop and report the cancellation to the user. Do not resume the task automatically.'
89
- : recovery(receipt.operation_id, receipt.profile_id),
90
+ : receipt.error.code === 'DIALOG_OPEN'
91
+ ? dialogRecovery(receipt)
92
+ : recovery(receipt.operation_id, receipt.profile_id),
90
93
  },
91
94
  };
92
95
  return { ok: true, ...base, ...(receipt.result_available ? { data: receipt.data } : {}) };