@parix/cli 0.1.7 → 0.1.9

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/dist/cli.cjs +4295 -28
  2. package/package.json +2 -2
  3. package/dist/cli.d.cts +0 -2
  4. package/dist/cli.d.ts +0 -2
  5. package/dist/cli.js +0 -30
  6. package/dist/commands/api.cjs +0 -81
  7. package/dist/commands/api.d.cts +0 -2
  8. package/dist/commands/api.d.ts +0 -2
  9. package/dist/commands/api.js +0 -78
  10. package/dist/commands/auth.cjs +0 -128
  11. package/dist/commands/auth.d.cts +0 -2
  12. package/dist/commands/auth.d.ts +0 -2
  13. package/dist/commands/auth.js +0 -125
  14. package/dist/commands/database.cjs +0 -259
  15. package/dist/commands/database.d.cts +0 -2
  16. package/dist/commands/database.d.ts +0 -2
  17. package/dist/commands/database.js +0 -256
  18. package/dist/commands/skill-content.cjs +0 -77
  19. package/dist/commands/skill-content.d.cts +0 -1
  20. package/dist/commands/skill-content.d.ts +0 -1
  21. package/dist/commands/skill-content.js +0 -74
  22. package/dist/commands/skill.cjs +0 -10
  23. package/dist/commands/skill.d.cts +0 -2
  24. package/dist/commands/skill.d.ts +0 -2
  25. package/dist/commands/skill.js +0 -7
  26. package/dist/commands/tb.cjs +0 -254
  27. package/dist/commands/tb.d.cts +0 -2
  28. package/dist/commands/tb.d.ts +0 -2
  29. package/dist/commands/tb.js +0 -251
  30. package/dist/lib/api-client.cjs +0 -44
  31. package/dist/lib/api-client.d.cts +0 -10
  32. package/dist/lib/api-client.d.ts +0 -10
  33. package/dist/lib/api-client.js +0 -40
  34. package/dist/lib/config.cjs +0 -24
  35. package/dist/lib/config.d.cts +0 -10
  36. package/dist/lib/config.d.ts +0 -10
  37. package/dist/lib/config.js +0 -18
  38. package/dist/lib/loopback-server.cjs +0 -158
  39. package/dist/lib/loopback-server.d.cts +0 -20
  40. package/dist/lib/loopback-server.d.ts +0 -20
  41. package/dist/lib/loopback-server.js +0 -155
  42. package/dist/lib/oauth-api.cjs +0 -73
  43. package/dist/lib/oauth-api.d.cts +0 -31
  44. package/dist/lib/oauth-api.d.ts +0 -31
  45. package/dist/lib/oauth-api.js +0 -68
  46. package/dist/lib/oauth-session.cjs +0 -108
  47. package/dist/lib/oauth-session.d.cts +0 -32
  48. package/dist/lib/oauth-session.d.ts +0 -32
  49. package/dist/lib/oauth-session.js +0 -103
  50. package/dist/lib/oauth.cjs +0 -58
  51. package/dist/lib/oauth.d.cts +0 -19
  52. package/dist/lib/oauth.d.ts +0 -19
  53. package/dist/lib/oauth.js +0 -49
  54. package/dist/lib/open-url.cjs +0 -38
  55. package/dist/lib/open-url.d.cts +0 -1
  56. package/dist/lib/open-url.d.ts +0 -1
  57. package/dist/lib/open-url.js +0 -32
  58. package/dist/lib/output.cjs +0 -20
  59. package/dist/lib/output.d.cts +0 -6
  60. package/dist/lib/output.d.ts +0 -6
  61. package/dist/lib/output.js +0 -15
  62. package/dist/lib/parix-api.cjs +0 -59
  63. package/dist/lib/parix-api.d.cts +0 -12
  64. package/dist/lib/parix-api.d.ts +0 -12
  65. package/dist/lib/parix-api.js +0 -55
  66. package/dist/lib/session.cjs +0 -80
  67. package/dist/lib/session.d.cts +0 -28
  68. package/dist/lib/session.d.ts +0 -28
  69. package/dist/lib/session.js +0 -74
  70. package/dist/lib/tb-payloads.cjs +0 -258
  71. package/dist/lib/tb-payloads.d.cts +0 -66
  72. package/dist/lib/tb-payloads.d.ts +0 -66
  73. package/dist/lib/tb-payloads.js +0 -249
@@ -1,74 +0,0 @@
1
- export const PARIX_AGENT_SKILL = [
2
- '---',
3
- 'name: parix',
4
- 'description: "Operate Parix through the `parix` CLI: inspect authentication and active organization context, manage database lifecycle, call authenticated Parix API endpoints, and run TigerBeetle queries or mutations. Use for Parix CLI setup, sessions, database catalog/list/info/create/remove work, Parix API requests, and TigerBeetle account or transfer operations."',
5
- '---',
6
- '',
7
- '# Parix CLI',
8
- '',
9
- 'Use the installed `parix` binary. Prefer scoped `--help` over guessing flags.',
10
- '',
11
- '## Start safely',
12
- '',
13
- '1. Run `command -v parix`. If it is absent, ask the user to install it with `npm install -g @parix/cli`.',
14
- '2. Run `parix auth status` before authenticated work. Confirm the base URL and active organization before any mutation. Status may refresh and persist tokens or organization context, so it is not strictly read-only. If no usable session exists, ask the user to complete `parix auth login`; login opens a browser OAuth flow.',
15
- '3. Treat `https://parix.io` as production. Login resolves its target as explicit `--base-url`, then `PARIX_BASE_URL`, then production; it ignores any URL in the stored session. Later commands resolve explicit URL, then stored URL, then environment, then production. Pass `--base-url <url>` explicitly when the environment matters.',
16
- '4. Use `parix database`, not `parix db`; no `db` alias exists.',
17
- '',
18
- 'Never read or print `~/.config/parix/session.json`; it contains access and refresh tokens.',
19
- '',
20
- '`parix auth logout` deletes the local session without confirmation; run it only when explicitly requested.',
21
- '',
22
- '## Discover before changing state',
23
- '',
24
- '```bash',
25
- 'parix database catalog',
26
- 'parix database list',
27
- 'parix database info <database-id>',
28
- 'parix database <command> --help',
29
- 'parix tb <command> --help',
30
- '```',
31
- '',
32
- 'Database and TigerBeetle commands operate in the active organization from the current session. Stop if that organization or target environment is not the intended one.',
33
- '',
34
- 'Use `--json` when a database or TigerBeetle command needs the complete response, but do not assume it is directly pipeable to `jq`: current output is wrapped by Clack formatting.',
35
- '',
36
- '## Manage databases',
37
- '',
38
- '- Run `parix database catalog` before creation and use provider, region, cluster, size, and storage identifiers returned by it.',
39
- '- Treat `parix database create` as potentially billable. Run it only when the user explicitly requests the exact resource. `--storage-gb` must be a positive integer.',
40
- '- Inspect the create response, including `success`, billing, and provisioning fields; exit code 0 alone does not prove provisioning started. Only when `success` is true and a database ID is returned, follow with `parix database info <database-id>`.',
41
- '- Treat `parix database remove <database-id>` as destructive. Resolve the exact ID, obtain explicit confirmation, and only then use `--yes` for a non-interactive run. Removal is queued; verify the returned workflow/status rather than claiming immediate deletion.',
42
- '',
43
- '## Run TigerBeetle operations',
44
- '',
45
- 'Read operations are `lookup-accounts`, `lookup-transfers`, `get-account-transfers`, `get-account-balances`, `query-accounts`, and `query-transfers`. `create-accounts` and `create-transfers` mutate data; run them only when explicitly requested.',
46
- '',
47
- 'Choose exactly one payload style:',
48
- '',
49
- '- flags for a single/common operation;',
50
- "- `--payload '<json>'` for raw JSON; or",
51
- '- `--file <path>` for a JSON file.',
52
- '',
53
- '`--file` takes precedence over `--payload`, and either raw form bypasses flag-built payloads, defaults, and validation. Flag-built account creation requires `--ledger` and `--code`. Ordinary transfer creation requires `--from`, `--to`, `--amount`, `--ledger`, and `--code`. Post-pending transfer creation requires `--flag post_pending_transfer`, `--pending-id`, and `--amount`; debit/credit IDs, ledger, and code may be omitted to inherit them. Void-pending transfer creation requires `--flag void_pending_transfer` and `--pending-id`; amount and the same inherited fields may be omitted. Imported accounts and transfers also require `--timestamp` in nanoseconds, greater than 0 and less than 2^63; nonzero `--timeout` values are in seconds and limited to non-imported pending transfers. Linked batches require `--payload` or `--file`.',
54
- '',
55
- 'Supply stable explicit `--id` values for retryable mutations; omitted IDs are newly generated on each run. Flag-built queries and account filters default to `--limit 100`.',
56
- '',
57
- 'Newly provisioned databases may not be ready immediately. Check `parix database info` and retry read-only readiness checks before TigerBeetle mutations.',
58
- '',
59
- '## Call the authenticated API',
60
- '',
61
- '```bash',
62
- 'parix api /api/v1/session',
63
- 'parix api /api/v1/example -X POST -d \'{"key":"value"}\'',
64
- '```',
65
- '',
66
- "Prefer relative `/api/...` paths. An absolute HTTP(S) URL also receives the stored bearer token, so use one only when the user explicitly trusts that host. Repeat `-H 'name:value'` for headers; a body defaults to `content-type: application/json` unless overridden.",
67
- '',
68
- 'Always inspect the printed HTTP status: `parix api` can exit successfully for an HTTP error response.',
69
- '',
70
- '## Verify outcomes',
71
- '',
72
- 'Report the target base URL and organization, the exact command class used, the response status/body, and any asynchronous provisioning or deletion state. Do not infer success from process exit alone.',
73
- '',
74
- ].join('\n');
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSkillCommand = createSkillCommand;
4
- const commander_1 = require("commander");
5
- const skill_content_1 = require("./skill-content.cjs");
6
- function createSkillCommand() {
7
- return new commander_1.Command('skill').description('Print the agent skill file to stdout').action(() => {
8
- process.stdout.write(skill_content_1.PARIX_AGENT_SKILL);
9
- });
10
- }
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function createSkillCommand(): Command;
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function createSkillCommand(): Command;
@@ -1,7 +0,0 @@
1
- import { Command } from 'commander';
2
- import { PARIX_AGENT_SKILL } from "./skill-content.js";
3
- export function createSkillCommand() {
4
- return new Command('skill').description('Print the agent skill file to stdout').action(() => {
5
- process.stdout.write(PARIX_AGENT_SKILL);
6
- });
7
- }
@@ -1,254 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTbCommand = createTbCommand;
4
- const prompts_1 = require("@clack/prompts");
5
- const commander_1 = require("commander");
6
- const output_1 = require("../lib/output.cjs");
7
- const parix_api_1 = require("../lib/parix-api.cjs");
8
- const tb_payloads_1 = require("../lib/tb-payloads.cjs");
9
- function createTbCommand() {
10
- const tb = new commander_1.Command('tb')
11
- .description('Run TigerBeetle operations against a database')
12
- .addHelpText('after', [
13
- '',
14
- 'Examples:',
15
- ' parix tb create-accounts db_123 --id 1000 --ledger 1 --code 1',
16
- ' parix tb create-transfers db_123 --id 2000 --from 1000 --to 1001 --amount 1 --ledger 1 --code 1',
17
- ' parix tb lookup-accounts db_123 --id 1000 --id 1001',
18
- ' parix tb query-transfers db_123 --limit 10 --json',
19
- ' parix tb create-transfers db_123 --file ./transfer.json',
20
- ].join('\n'));
21
- addCreateAccountsCommand(tb);
22
- addCreateTransfersCommand(tb);
23
- addLookupCommand(tb, 'lookup-accounts', 'lookup_accounts', 'Lookup accounts');
24
- addLookupCommand(tb, 'lookup-transfers', 'lookup_transfers', 'Lookup transfers');
25
- addAccountFilterCommand(tb, 'get-account-transfers', 'get_account_transfers', 'Get account transfers');
26
- addAccountFilterCommand(tb, 'get-account-balances', 'get_account_balances', 'Get account balances');
27
- addQueryCommand(tb, 'query-accounts', 'query_accounts', 'Query accounts');
28
- addQueryCommand(tb, 'query-transfers', 'query_transfers', 'Query transfers');
29
- return tb;
30
- }
31
- function addCreateAccountsCommand(parent) {
32
- parent
33
- .command('create-accounts')
34
- .description('Create TigerBeetle accounts')
35
- .argument('<database-id>', 'Database id')
36
- .option('-b, --base-url <url>', 'Parix base URL')
37
- .option('--json', 'Print raw JSON')
38
- .option('--payload <json>', 'Raw JSON payload override')
39
- .option('--file <path>', 'Read JSON payload from file')
40
- .option('--id <id>', 'Account id (defaults to generated id)')
41
- .option('--ledger <ledger>', 'Ledger id')
42
- .option('--code <code>', 'Account code')
43
- .option('--flag <flag>', 'Account flag name or bitfield value', collectValues, [])
44
- .option('--timestamp <nanoseconds>', 'Imported timestamp, greater than 0 and less than 2^63')
45
- .option('--user-data-128 <value>', 'user_data_128')
46
- .option('--user-data-64 <value>', 'user_data_64')
47
- .option('--user-data-32 <value>', 'user_data_32')
48
- .addHelpText('after', [
49
- '',
50
- 'Examples:',
51
- ' parix tb create-accounts db_123 --id 1000 --ledger 1 --code 1',
52
- ' parix tb create-accounts db_123 --payload "[{\"id\":\"1000\",\"ledger\":\"1\",\"code\":\"1\",\"flags\":\"0\"}]"',
53
- ].join('\n'))
54
- .action(async (databaseId, options) => {
55
- const payload = await (0, tb_payloads_1.resolveTbPayload)(options, () => (0, tb_payloads_1.buildCreateAccountsPayload)({
56
- code: options.code,
57
- flags: options.flag,
58
- id: options.id,
59
- ledger: options.ledger,
60
- timestamp: options.timestamp,
61
- userData128: options.userData128,
62
- userData32: options.userData32,
63
- userData64: options.userData64,
64
- }));
65
- await executeTbOperation(databaseId, 'create_accounts', payload, options);
66
- });
67
- }
68
- function addCreateTransfersCommand(parent) {
69
- parent
70
- .command('create-transfers')
71
- .description('Create TigerBeetle transfers')
72
- .argument('<database-id>', 'Database id')
73
- .option('-b, --base-url <url>', 'Parix base URL')
74
- .option('--json', 'Print raw JSON')
75
- .option('--payload <json>', 'Raw JSON payload override')
76
- .option('--file <path>', 'Read JSON payload from file')
77
- .option('--id <id>', 'Transfer id (defaults to generated id)')
78
- .option('--from <id>', 'Debit account id')
79
- .option('--to <id>', 'Credit account id')
80
- .option('--amount <amount>', 'Transfer amount')
81
- .option('--ledger <ledger>', 'Ledger id')
82
- .option('--code <code>', 'Transfer code')
83
- .option('--flag <flag>', 'Transfer flag name or bitfield value', collectValues, [])
84
- .option('--pending-id <id>', 'Pending transfer id')
85
- .option('--timeout <seconds>', 'Pending transfer timeout in seconds')
86
- .option('--timestamp <nanoseconds>', 'Imported timestamp, greater than 0 and less than 2^63')
87
- .option('--user-data-128 <value>', 'user_data_128')
88
- .option('--user-data-64 <value>', 'user_data_64')
89
- .option('--user-data-32 <value>', 'user_data_32')
90
- .addHelpText('after', [
91
- '',
92
- 'Examples:',
93
- ' parix tb create-transfers db_123 --id 2000 --from 1000 --to 1001 --amount 1 --ledger 1 --code 1',
94
- ' parix tb create-transfers db_123 --id 2001 --pending-id 2000 --amount 25 --flag post_pending_transfer',
95
- ' parix tb create-transfers db_123 --id 2001 --pending-id 2000 --flag void_pending_transfer',
96
- ' parix tb create-transfers db_123 --file ./transfer.json',
97
- ].join('\n'))
98
- .action(async (databaseId, options) => {
99
- const payload = await (0, tb_payloads_1.resolveTbPayload)(options, () => (0, tb_payloads_1.buildCreateTransfersPayload)({
100
- amount: options.amount,
101
- code: options.code,
102
- creditAccountId: options.to,
103
- debitAccountId: options.from,
104
- flags: options.flag,
105
- id: options.id,
106
- ledger: options.ledger,
107
- pendingId: options.pendingId,
108
- timestamp: options.timestamp,
109
- timeout: options.timeout,
110
- userData128: options.userData128,
111
- userData32: options.userData32,
112
- userData64: options.userData64,
113
- }));
114
- await executeTbOperation(databaseId, 'create_transfers', payload, options);
115
- });
116
- }
117
- function addLookupCommand(parent, name, operation, description) {
118
- parent
119
- .command(name)
120
- .description(description)
121
- .argument('<database-id>', 'Database id')
122
- .option('-b, --base-url <url>', 'Parix base URL')
123
- .option('--json', 'Print raw JSON')
124
- .option('--payload <json>', 'Raw JSON payload override')
125
- .option('--file <path>', 'Read JSON payload from file')
126
- .option('--id <id>', 'ID to lookup', collectValues, [])
127
- .option('--ids <ids>', 'Comma-separated IDs to lookup')
128
- .addHelpText('after', [
129
- '',
130
- 'Examples:',
131
- ` parix tb ${name} db_123 --id 1000 --id 1001`,
132
- ` parix tb ${name} db_123 --ids 1000,1001`,
133
- ].join('\n'))
134
- .action(async (databaseId, options) => {
135
- const payload = await (0, tb_payloads_1.resolveTbPayload)(options, () => (0, tb_payloads_1.buildLookupPayload)({
136
- id: options.id,
137
- ids: options.ids,
138
- }));
139
- await executeTbOperation(databaseId, operation, payload, options);
140
- });
141
- }
142
- function addAccountFilterCommand(parent, name, operation, description) {
143
- parent
144
- .command(name)
145
- .description(description)
146
- .argument('<database-id>', 'Database id')
147
- .option('-b, --base-url <url>', 'Parix base URL')
148
- .option('--json', 'Print raw JSON')
149
- .option('--payload <json>', 'Raw JSON payload override')
150
- .option('--file <path>', 'Read JSON payload from file')
151
- .option('--account-id <id>', 'Account id')
152
- .option('--limit <limit>', 'Maximum row count', '100')
153
- .option('--flag <flag>', 'Filter flag name or bitfield value', collectValues, [])
154
- .option('--timestamp-min <value>', 'Minimum timestamp')
155
- .option('--timestamp-max <value>', 'Maximum timestamp')
156
- .option('--user-data-128 <value>', 'user_data_128')
157
- .option('--user-data-64 <value>', 'user_data_64')
158
- .option('--user-data-32 <value>', 'user_data_32')
159
- .option('--code <code>', 'Filter code')
160
- .addHelpText('after', [
161
- '',
162
- 'Examples:',
163
- ` parix tb ${name} db_123 --account-id 1000 --limit 10 --flag debits`,
164
- ` parix tb ${name} db_123 --file ./filter.json`,
165
- ].join('\n'))
166
- .action(async (databaseId, options) => {
167
- const payload = await (0, tb_payloads_1.resolveTbPayload)(options, () => (0, tb_payloads_1.buildAccountFilterPayload)({
168
- accountId: options.accountId,
169
- code: options.code,
170
- flags: options.flag,
171
- limit: options.limit,
172
- timestampMax: options.timestampMax,
173
- timestampMin: options.timestampMin,
174
- userData128: options.userData128,
175
- userData32: options.userData32,
176
- userData64: options.userData64,
177
- }));
178
- await executeTbOperation(databaseId, operation, payload, options);
179
- });
180
- }
181
- function addQueryCommand(parent, name, operation, description) {
182
- parent
183
- .command(name)
184
- .description(description)
185
- .argument('<database-id>', 'Database id')
186
- .option('-b, --base-url <url>', 'Parix base URL')
187
- .option('--json', 'Print raw JSON')
188
- .option('--payload <json>', 'Raw JSON payload override')
189
- .option('--file <path>', 'Read JSON payload from file')
190
- .option('--limit <limit>', 'Maximum row count', '100')
191
- .option('--flag <flag>', 'Query flag name or bitfield value', collectValues, [])
192
- .option('--ledger <ledger>', 'Filter ledger')
193
- .option('--code <code>', 'Filter code')
194
- .option('--timestamp-min <value>', 'Minimum timestamp')
195
- .option('--timestamp-max <value>', 'Maximum timestamp')
196
- .option('--user-data-128 <value>', 'user_data_128')
197
- .option('--user-data-64 <value>', 'user_data_64')
198
- .option('--user-data-32 <value>', 'user_data_32')
199
- .addHelpText('after', [
200
- '',
201
- 'Examples:',
202
- ` parix tb ${name} db_123 --limit 10`,
203
- ` parix tb ${name} db_123 --ledger 1 --limit 10 --json`,
204
- ].join('\n'))
205
- .action(async (databaseId, options) => {
206
- const payload = await (0, tb_payloads_1.resolveTbPayload)(options, () => (0, tb_payloads_1.buildQueryPayload)({
207
- code: options.code,
208
- flags: options.flag,
209
- ledger: options.ledger,
210
- limit: options.limit,
211
- timestampMax: options.timestampMax,
212
- timestampMin: options.timestampMin,
213
- userData128: options.userData128,
214
- userData32: options.userData32,
215
- userData64: options.userData64,
216
- }));
217
- await executeTbOperation(databaseId, operation, payload, options);
218
- });
219
- }
220
- async function executeTbOperation(databaseId, operation, payload, options) {
221
- const response = await (0, parix_api_1.requestApiJson)({
222
- baseUrl: options.baseUrl,
223
- body: JSON.stringify(payload),
224
- headers: {
225
- 'content-type': 'application/json',
226
- },
227
- method: 'POST',
228
- path: `/api/v1/databases/${encodeURIComponent(databaseId)}/tb/${operation}`,
229
- });
230
- if (options.json) {
231
- (0, output_1.printJson)(response);
232
- return;
233
- }
234
- (0, prompts_1.note)(response.docsUrl, 'TigerBeetle docs');
235
- (0, prompts_1.note)([
236
- `Operation: ${response.operationLabel}`,
237
- `Database: ${response.databaseName}`,
238
- `Provider: ${response.provider}`,
239
- `Cluster ID: ${response.clusterId}`,
240
- `Target host: ${response.targetHost}`,
241
- `Replicas: ${String(response.replicaCount)}`,
242
- `Mode: ${response.mode}`,
243
- `Persisted: ${String(response.persisted)}`,
244
- ].join('\n'), 'Execution');
245
- if (Array.isArray(response.responsePayload)) {
246
- (0, prompts_1.note)(String(response.responsePayload.length), 'Rows returned');
247
- }
248
- (0, output_1.printJson)(response.responsePayload);
249
- (0, prompts_1.outro)(response.message);
250
- }
251
- function collectValues(value, previous) {
252
- previous.push(value);
253
- return previous;
254
- }
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function createTbCommand(): Command;
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function createTbCommand(): Command;
@@ -1,251 +0,0 @@
1
- import { note, outro } from '@clack/prompts';
2
- import { Command } from 'commander';
3
- import { printJson } from "../lib/output.js";
4
- import { requestApiJson } from "../lib/parix-api.js";
5
- import { buildAccountFilterPayload, buildCreateAccountsPayload, buildCreateTransfersPayload, buildLookupPayload, buildQueryPayload, resolveTbPayload, } from "../lib/tb-payloads.js";
6
- export function createTbCommand() {
7
- const tb = new Command('tb')
8
- .description('Run TigerBeetle operations against a database')
9
- .addHelpText('after', [
10
- '',
11
- 'Examples:',
12
- ' parix tb create-accounts db_123 --id 1000 --ledger 1 --code 1',
13
- ' parix tb create-transfers db_123 --id 2000 --from 1000 --to 1001 --amount 1 --ledger 1 --code 1',
14
- ' parix tb lookup-accounts db_123 --id 1000 --id 1001',
15
- ' parix tb query-transfers db_123 --limit 10 --json',
16
- ' parix tb create-transfers db_123 --file ./transfer.json',
17
- ].join('\n'));
18
- addCreateAccountsCommand(tb);
19
- addCreateTransfersCommand(tb);
20
- addLookupCommand(tb, 'lookup-accounts', 'lookup_accounts', 'Lookup accounts');
21
- addLookupCommand(tb, 'lookup-transfers', 'lookup_transfers', 'Lookup transfers');
22
- addAccountFilterCommand(tb, 'get-account-transfers', 'get_account_transfers', 'Get account transfers');
23
- addAccountFilterCommand(tb, 'get-account-balances', 'get_account_balances', 'Get account balances');
24
- addQueryCommand(tb, 'query-accounts', 'query_accounts', 'Query accounts');
25
- addQueryCommand(tb, 'query-transfers', 'query_transfers', 'Query transfers');
26
- return tb;
27
- }
28
- function addCreateAccountsCommand(parent) {
29
- parent
30
- .command('create-accounts')
31
- .description('Create TigerBeetle accounts')
32
- .argument('<database-id>', 'Database id')
33
- .option('-b, --base-url <url>', 'Parix base URL')
34
- .option('--json', 'Print raw JSON')
35
- .option('--payload <json>', 'Raw JSON payload override')
36
- .option('--file <path>', 'Read JSON payload from file')
37
- .option('--id <id>', 'Account id (defaults to generated id)')
38
- .option('--ledger <ledger>', 'Ledger id')
39
- .option('--code <code>', 'Account code')
40
- .option('--flag <flag>', 'Account flag name or bitfield value', collectValues, [])
41
- .option('--timestamp <nanoseconds>', 'Imported timestamp, greater than 0 and less than 2^63')
42
- .option('--user-data-128 <value>', 'user_data_128')
43
- .option('--user-data-64 <value>', 'user_data_64')
44
- .option('--user-data-32 <value>', 'user_data_32')
45
- .addHelpText('after', [
46
- '',
47
- 'Examples:',
48
- ' parix tb create-accounts db_123 --id 1000 --ledger 1 --code 1',
49
- ' parix tb create-accounts db_123 --payload "[{\"id\":\"1000\",\"ledger\":\"1\",\"code\":\"1\",\"flags\":\"0\"}]"',
50
- ].join('\n'))
51
- .action(async (databaseId, options) => {
52
- const payload = await resolveTbPayload(options, () => buildCreateAccountsPayload({
53
- code: options.code,
54
- flags: options.flag,
55
- id: options.id,
56
- ledger: options.ledger,
57
- timestamp: options.timestamp,
58
- userData128: options.userData128,
59
- userData32: options.userData32,
60
- userData64: options.userData64,
61
- }));
62
- await executeTbOperation(databaseId, 'create_accounts', payload, options);
63
- });
64
- }
65
- function addCreateTransfersCommand(parent) {
66
- parent
67
- .command('create-transfers')
68
- .description('Create TigerBeetle transfers')
69
- .argument('<database-id>', 'Database id')
70
- .option('-b, --base-url <url>', 'Parix base URL')
71
- .option('--json', 'Print raw JSON')
72
- .option('--payload <json>', 'Raw JSON payload override')
73
- .option('--file <path>', 'Read JSON payload from file')
74
- .option('--id <id>', 'Transfer id (defaults to generated id)')
75
- .option('--from <id>', 'Debit account id')
76
- .option('--to <id>', 'Credit account id')
77
- .option('--amount <amount>', 'Transfer amount')
78
- .option('--ledger <ledger>', 'Ledger id')
79
- .option('--code <code>', 'Transfer code')
80
- .option('--flag <flag>', 'Transfer flag name or bitfield value', collectValues, [])
81
- .option('--pending-id <id>', 'Pending transfer id')
82
- .option('--timeout <seconds>', 'Pending transfer timeout in seconds')
83
- .option('--timestamp <nanoseconds>', 'Imported timestamp, greater than 0 and less than 2^63')
84
- .option('--user-data-128 <value>', 'user_data_128')
85
- .option('--user-data-64 <value>', 'user_data_64')
86
- .option('--user-data-32 <value>', 'user_data_32')
87
- .addHelpText('after', [
88
- '',
89
- 'Examples:',
90
- ' parix tb create-transfers db_123 --id 2000 --from 1000 --to 1001 --amount 1 --ledger 1 --code 1',
91
- ' parix tb create-transfers db_123 --id 2001 --pending-id 2000 --amount 25 --flag post_pending_transfer',
92
- ' parix tb create-transfers db_123 --id 2001 --pending-id 2000 --flag void_pending_transfer',
93
- ' parix tb create-transfers db_123 --file ./transfer.json',
94
- ].join('\n'))
95
- .action(async (databaseId, options) => {
96
- const payload = await resolveTbPayload(options, () => buildCreateTransfersPayload({
97
- amount: options.amount,
98
- code: options.code,
99
- creditAccountId: options.to,
100
- debitAccountId: options.from,
101
- flags: options.flag,
102
- id: options.id,
103
- ledger: options.ledger,
104
- pendingId: options.pendingId,
105
- timestamp: options.timestamp,
106
- timeout: options.timeout,
107
- userData128: options.userData128,
108
- userData32: options.userData32,
109
- userData64: options.userData64,
110
- }));
111
- await executeTbOperation(databaseId, 'create_transfers', payload, options);
112
- });
113
- }
114
- function addLookupCommand(parent, name, operation, description) {
115
- parent
116
- .command(name)
117
- .description(description)
118
- .argument('<database-id>', 'Database id')
119
- .option('-b, --base-url <url>', 'Parix base URL')
120
- .option('--json', 'Print raw JSON')
121
- .option('--payload <json>', 'Raw JSON payload override')
122
- .option('--file <path>', 'Read JSON payload from file')
123
- .option('--id <id>', 'ID to lookup', collectValues, [])
124
- .option('--ids <ids>', 'Comma-separated IDs to lookup')
125
- .addHelpText('after', [
126
- '',
127
- 'Examples:',
128
- ` parix tb ${name} db_123 --id 1000 --id 1001`,
129
- ` parix tb ${name} db_123 --ids 1000,1001`,
130
- ].join('\n'))
131
- .action(async (databaseId, options) => {
132
- const payload = await resolveTbPayload(options, () => buildLookupPayload({
133
- id: options.id,
134
- ids: options.ids,
135
- }));
136
- await executeTbOperation(databaseId, operation, payload, options);
137
- });
138
- }
139
- function addAccountFilterCommand(parent, name, operation, description) {
140
- parent
141
- .command(name)
142
- .description(description)
143
- .argument('<database-id>', 'Database id')
144
- .option('-b, --base-url <url>', 'Parix base URL')
145
- .option('--json', 'Print raw JSON')
146
- .option('--payload <json>', 'Raw JSON payload override')
147
- .option('--file <path>', 'Read JSON payload from file')
148
- .option('--account-id <id>', 'Account id')
149
- .option('--limit <limit>', 'Maximum row count', '100')
150
- .option('--flag <flag>', 'Filter flag name or bitfield value', collectValues, [])
151
- .option('--timestamp-min <value>', 'Minimum timestamp')
152
- .option('--timestamp-max <value>', 'Maximum timestamp')
153
- .option('--user-data-128 <value>', 'user_data_128')
154
- .option('--user-data-64 <value>', 'user_data_64')
155
- .option('--user-data-32 <value>', 'user_data_32')
156
- .option('--code <code>', 'Filter code')
157
- .addHelpText('after', [
158
- '',
159
- 'Examples:',
160
- ` parix tb ${name} db_123 --account-id 1000 --limit 10 --flag debits`,
161
- ` parix tb ${name} db_123 --file ./filter.json`,
162
- ].join('\n'))
163
- .action(async (databaseId, options) => {
164
- const payload = await resolveTbPayload(options, () => buildAccountFilterPayload({
165
- accountId: options.accountId,
166
- code: options.code,
167
- flags: options.flag,
168
- limit: options.limit,
169
- timestampMax: options.timestampMax,
170
- timestampMin: options.timestampMin,
171
- userData128: options.userData128,
172
- userData32: options.userData32,
173
- userData64: options.userData64,
174
- }));
175
- await executeTbOperation(databaseId, operation, payload, options);
176
- });
177
- }
178
- function addQueryCommand(parent, name, operation, description) {
179
- parent
180
- .command(name)
181
- .description(description)
182
- .argument('<database-id>', 'Database id')
183
- .option('-b, --base-url <url>', 'Parix base URL')
184
- .option('--json', 'Print raw JSON')
185
- .option('--payload <json>', 'Raw JSON payload override')
186
- .option('--file <path>', 'Read JSON payload from file')
187
- .option('--limit <limit>', 'Maximum row count', '100')
188
- .option('--flag <flag>', 'Query flag name or bitfield value', collectValues, [])
189
- .option('--ledger <ledger>', 'Filter ledger')
190
- .option('--code <code>', 'Filter code')
191
- .option('--timestamp-min <value>', 'Minimum timestamp')
192
- .option('--timestamp-max <value>', 'Maximum timestamp')
193
- .option('--user-data-128 <value>', 'user_data_128')
194
- .option('--user-data-64 <value>', 'user_data_64')
195
- .option('--user-data-32 <value>', 'user_data_32')
196
- .addHelpText('after', [
197
- '',
198
- 'Examples:',
199
- ` parix tb ${name} db_123 --limit 10`,
200
- ` parix tb ${name} db_123 --ledger 1 --limit 10 --json`,
201
- ].join('\n'))
202
- .action(async (databaseId, options) => {
203
- const payload = await resolveTbPayload(options, () => buildQueryPayload({
204
- code: options.code,
205
- flags: options.flag,
206
- ledger: options.ledger,
207
- limit: options.limit,
208
- timestampMax: options.timestampMax,
209
- timestampMin: options.timestampMin,
210
- userData128: options.userData128,
211
- userData32: options.userData32,
212
- userData64: options.userData64,
213
- }));
214
- await executeTbOperation(databaseId, operation, payload, options);
215
- });
216
- }
217
- async function executeTbOperation(databaseId, operation, payload, options) {
218
- const response = await requestApiJson({
219
- baseUrl: options.baseUrl,
220
- body: JSON.stringify(payload),
221
- headers: {
222
- 'content-type': 'application/json',
223
- },
224
- method: 'POST',
225
- path: `/api/v1/databases/${encodeURIComponent(databaseId)}/tb/${operation}`,
226
- });
227
- if (options.json) {
228
- printJson(response);
229
- return;
230
- }
231
- note(response.docsUrl, 'TigerBeetle docs');
232
- note([
233
- `Operation: ${response.operationLabel}`,
234
- `Database: ${response.databaseName}`,
235
- `Provider: ${response.provider}`,
236
- `Cluster ID: ${response.clusterId}`,
237
- `Target host: ${response.targetHost}`,
238
- `Replicas: ${String(response.replicaCount)}`,
239
- `Mode: ${response.mode}`,
240
- `Persisted: ${String(response.persisted)}`,
241
- ].join('\n'), 'Execution');
242
- if (Array.isArray(response.responsePayload)) {
243
- note(String(response.responsePayload.length), 'Rows returned');
244
- }
245
- printJson(response.responsePayload);
246
- outro(response.message);
247
- }
248
- function collectValues(value, previous) {
249
- previous.push(value);
250
- return previous;
251
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiClient = void 0;
4
- const oauth_session_1 = require("./oauth-session.cjs");
5
- const TRAILING_SLASHES_REGEX = /\/+$/;
6
- class ApiClient {
7
- session;
8
- constructor(options) {
9
- this.session = options.session;
10
- }
11
- async request(pathname, init = {}) {
12
- this.session = await (0, oauth_session_1.ensureFreshSession)(this.session);
13
- const url = toRequestUrl(pathname, this.session.baseUrl);
14
- const headers = new Headers(init.headers);
15
- headers.set('authorization', `Bearer ${this.session.accessToken}`);
16
- const response = await fetch(url, {
17
- ...init,
18
- headers,
19
- });
20
- if (response.status !== 401) {
21
- return response;
22
- }
23
- this.session = await (0, oauth_session_1.ensureFreshSession)({
24
- ...this.session,
25
- accessTokenExpiresAt: new Date(0).toISOString(),
26
- });
27
- const retryHeaders = new Headers(init.headers);
28
- retryHeaders.set('authorization', `Bearer ${this.session.accessToken}`);
29
- return fetch(url, {
30
- ...init,
31
- headers: retryHeaders,
32
- });
33
- }
34
- }
35
- exports.ApiClient = ApiClient;
36
- function toRequestUrl(pathname, baseUrl) {
37
- if (pathname.startsWith('http://') || pathname.startsWith('https://')) {
38
- return pathname;
39
- }
40
- return new URL(pathname, `${trimTrailingSlash(baseUrl)}/`).toString();
41
- }
42
- function trimTrailingSlash(value) {
43
- return value.replace(TRAILING_SLASHES_REGEX, '');
44
- }