@parix/cli 0.1.8 → 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 +4296 -35
  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 -36
  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 -131
  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 -128
  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 -180
  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 -177
  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,66 +0,0 @@
1
- export declare const tbOperationNames: readonly ["create_accounts", "create_transfers", "lookup_accounts", "lookup_transfers", "get_account_transfers", "get_account_balances", "query_accounts", "query_transfers"];
2
- export type TbOperationName = (typeof tbOperationNames)[number];
3
- export interface PayloadOverrideOptions {
4
- file?: string;
5
- payload?: string;
6
- }
7
- export declare function resolveTbPayload<T>(options: PayloadOverrideOptions, buildFromFlags: () => T): Promise<T>;
8
- export declare function buildCreateAccountsPayload(options: {
9
- code?: string;
10
- flags?: string[];
11
- id?: string;
12
- ledger?: string;
13
- timestamp?: string;
14
- userData128?: string;
15
- userData32?: string;
16
- userData64?: string;
17
- }): {
18
- [k: string]: string | undefined;
19
- }[];
20
- export declare function buildCreateTransfersPayload(options: {
21
- amount?: string;
22
- code?: string;
23
- creditAccountId?: string;
24
- debitAccountId?: string;
25
- flags?: string[];
26
- id?: string;
27
- ledger?: string;
28
- pendingId?: string;
29
- timestamp?: string;
30
- timeout?: string;
31
- userData128?: string;
32
- userData32?: string;
33
- userData64?: string;
34
- }): {
35
- [k: string]: string | undefined;
36
- }[];
37
- export declare function buildLookupPayload(options: {
38
- id?: string[];
39
- ids?: string;
40
- }): string[];
41
- export declare function buildAccountFilterPayload(options: {
42
- accountId?: string;
43
- code?: string;
44
- flags?: string[];
45
- limit?: string;
46
- timestampMax?: string;
47
- timestampMin?: string;
48
- userData128?: string;
49
- userData32?: string;
50
- userData64?: string;
51
- }): {
52
- [k: string]: string | undefined;
53
- };
54
- export declare function buildQueryPayload(options: {
55
- code?: string;
56
- flags?: string[];
57
- ledger?: string;
58
- limit?: string;
59
- timestampMax?: string;
60
- timestampMin?: string;
61
- userData128?: string;
62
- userData32?: string;
63
- userData64?: string;
64
- }): {
65
- [k: string]: string | undefined;
66
- };
@@ -1,249 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- const SPLIT_IDS_REGEX = /[\s,]+/;
3
- const DECIMAL_INTEGER_REGEX = /^\d+$/;
4
- const LINKED_FLAG = 1n;
5
- const ACCOUNT_IMPORTED_FLAG = 16n;
6
- const TRANSFER_PENDING_FLAG = 2n;
7
- const TRANSFER_POST_PENDING_FLAG = 4n;
8
- const TRANSFER_VOID_PENDING_FLAG = 8n;
9
- const TRANSFER_IMPORTED_FLAG = 256n;
10
- const TIGERBEETLE_TIMESTAMP_MAX_EXCLUSIVE = 1n << 63n;
11
- const IMPORTED_TIMESTAMP_ERROR = '--timestamp must be a decimal integer greater than 0 and less than 2^63 when --flag imported is used.';
12
- const ACCOUNT_FLAG_SET = {
13
- allowedMask: 63n,
14
- label: 'account',
15
- nameToBit: new Map([
16
- ['linked', LINKED_FLAG],
17
- ['debits_must_not_exceed_credits', 2n],
18
- ['credits_must_not_exceed_debits', 4n],
19
- ['history', 8n],
20
- ['imported', ACCOUNT_IMPORTED_FLAG],
21
- ['closed', 32n],
22
- ]),
23
- };
24
- const TRANSFER_FLAG_SET = {
25
- allowedMask: 511n,
26
- label: 'transfer',
27
- nameToBit: new Map([
28
- ['linked', LINKED_FLAG],
29
- ['pending', TRANSFER_PENDING_FLAG],
30
- ['post_pending_transfer', TRANSFER_POST_PENDING_FLAG],
31
- ['void_pending_transfer', TRANSFER_VOID_PENDING_FLAG],
32
- ['balancing_debit', 16n],
33
- ['balancing_credit', 32n],
34
- ['closing_debit', 64n],
35
- ['closing_credit', 128n],
36
- ['imported', TRANSFER_IMPORTED_FLAG],
37
- ]),
38
- };
39
- const ACCOUNT_FILTER_FLAG_SET = {
40
- allowedMask: 7n,
41
- label: 'account filter',
42
- nameToBit: new Map([
43
- ['debits', 1n],
44
- ['credits', 2n],
45
- ['reversed', 4n],
46
- ]),
47
- };
48
- const QUERY_FILTER_FLAG_SET = {
49
- allowedMask: 1n,
50
- label: 'query filter',
51
- nameToBit: new Map([['reversed', 1n]]),
52
- };
53
- export const tbOperationNames = [
54
- 'create_accounts',
55
- 'create_transfers',
56
- 'lookup_accounts',
57
- 'lookup_transfers',
58
- 'get_account_transfers',
59
- 'get_account_balances',
60
- 'query_accounts',
61
- 'query_transfers',
62
- ];
63
- export async function resolveTbPayload(options, buildFromFlags) {
64
- if (options.file) {
65
- return JSON.parse(await readFile(options.file, 'utf8'));
66
- }
67
- if (options.payload) {
68
- return JSON.parse(options.payload);
69
- }
70
- return buildFromFlags();
71
- }
72
- export function buildCreateAccountsPayload(options) {
73
- const flags = flagsBitfield(options.flags, ACCOUNT_FLAG_SET);
74
- rejectLinkedSingleEvent(flags);
75
- const isImported = flagIsSet(flags, ACCOUNT_IMPORTED_FLAG);
76
- if (!isImported && valueIsNonZero(options.timestamp)) {
77
- throw new Error('--timestamp requires --flag imported when nonzero.');
78
- }
79
- return [
80
- omitEmpty({
81
- code: requiredValue(options.code, '--code'),
82
- flags,
83
- id: options.id ?? randomTbId(),
84
- ledger: requiredValue(options.ledger, '--ledger'),
85
- timestamp: isImported ? requiredImportedTimestamp(options.timestamp) : options.timestamp,
86
- user_data_128: options.userData128,
87
- user_data_32: options.userData32,
88
- user_data_64: options.userData64,
89
- }),
90
- ];
91
- }
92
- export function buildCreateTransfersPayload(options) {
93
- const flags = flagsBitfield(options.flags, TRANSFER_FLAG_SET);
94
- rejectLinkedSingleEvent(flags);
95
- const isPending = flagIsSet(flags, TRANSFER_PENDING_FLAG);
96
- const isPostPending = flagIsSet(flags, TRANSFER_POST_PENDING_FLAG);
97
- const isVoidPending = flagIsSet(flags, TRANSFER_VOID_PENDING_FLAG);
98
- const isImported = flagIsSet(flags, TRANSFER_IMPORTED_FLAG);
99
- const lifecycleModeCount = Number(isPending) + Number(isPostPending) + Number(isVoidPending);
100
- if (lifecycleModeCount > 1) {
101
- throw new Error('The pending, post_pending_transfer, and void_pending_transfer flags cannot be combined.');
102
- }
103
- const resolvesPending = isPostPending || isVoidPending;
104
- if (!isImported && valueIsNonZero(options.timestamp)) {
105
- throw new Error('--timestamp requires --flag imported when nonzero.');
106
- }
107
- if (valueIsNonZero(options.timeout)) {
108
- if (isImported) {
109
- throw new Error('--timeout must be zero or omitted with --flag imported.');
110
- }
111
- if (!isPending) {
112
- throw new Error('--timeout requires --flag pending when nonzero.');
113
- }
114
- }
115
- if (!resolvesPending && valueIsNonZero(options.pendingId)) {
116
- throw new Error('--pending-id requires --flag post_pending_transfer or --flag void_pending_transfer when nonzero.');
117
- }
118
- return [
119
- omitEmpty({
120
- amount: isVoidPending ? valueOrZero(options.amount) : requiredValue(options.amount, '--amount'),
121
- code: resolvesPending ? valueOrZero(options.code) : requiredValue(options.code, '--code'),
122
- credit_account_id: resolvesPending
123
- ? valueOrZero(options.creditAccountId)
124
- : requiredValue(options.creditAccountId, '--to'),
125
- debit_account_id: resolvesPending
126
- ? valueOrZero(options.debitAccountId)
127
- : requiredValue(options.debitAccountId, '--from'),
128
- flags,
129
- id: options.id ?? randomTbId(),
130
- ledger: resolvesPending ? valueOrZero(options.ledger) : requiredValue(options.ledger, '--ledger'),
131
- pending_id: resolvesPending ? requiredValue(options.pendingId, '--pending-id') : options.pendingId,
132
- timestamp: isImported ? requiredImportedTimestamp(options.timestamp) : options.timestamp,
133
- timeout: options.timeout,
134
- user_data_128: options.userData128,
135
- user_data_32: options.userData32,
136
- user_data_64: options.userData64,
137
- }),
138
- ];
139
- }
140
- export function buildLookupPayload(options) {
141
- const ids = [...(options.id ?? []), ...splitIds(options.ids)];
142
- if (ids.length === 0) {
143
- throw new Error('Provide at least one `--id` or `--ids` value.');
144
- }
145
- return ids;
146
- }
147
- export function buildAccountFilterPayload(options) {
148
- return omitEmpty({
149
- account_id: requiredValue(options.accountId, '--account-id'),
150
- code: options.code,
151
- flags: flagsBitfield(options.flags, ACCOUNT_FILTER_FLAG_SET),
152
- limit: requiredValue(options.limit, '--limit'),
153
- timestamp_max: options.timestampMax,
154
- timestamp_min: options.timestampMin,
155
- user_data_128: options.userData128,
156
- user_data_32: options.userData32,
157
- user_data_64: options.userData64,
158
- });
159
- }
160
- export function buildQueryPayload(options) {
161
- return omitEmpty({
162
- code: options.code,
163
- flags: flagsBitfield(options.flags, QUERY_FILTER_FLAG_SET),
164
- ledger: options.ledger,
165
- limit: requiredValue(options.limit, '--limit'),
166
- timestamp_max: options.timestampMax,
167
- timestamp_min: options.timestampMin,
168
- user_data_128: options.userData128,
169
- user_data_32: options.userData32,
170
- user_data_64: options.userData64,
171
- });
172
- }
173
- function flagsBitfield(flags, flagSet) {
174
- if (!flags || flags.length === 0) {
175
- return '0';
176
- }
177
- let bitfield = 0n;
178
- for (const flag of flags) {
179
- const normalized = flag.trim();
180
- if (!normalized) {
181
- continue;
182
- }
183
- if (DECIMAL_INTEGER_REGEX.test(normalized)) {
184
- const direct = BigInt(normalized);
185
- if ((direct & ~flagSet.allowedMask) !== 0n) {
186
- throw new Error(`Unsupported ${flagSet.label} flag bitfield: ${flag}`);
187
- }
188
- bitfield |= direct;
189
- continue;
190
- }
191
- const bit = flagSet.nameToBit.get(normalized);
192
- if (bit === undefined) {
193
- throw new Error(`Unsupported ${flagSet.label} flag: ${flag}`);
194
- }
195
- bitfield |= bit;
196
- }
197
- return bitfield.toString();
198
- }
199
- function flagIsSet(flags, flag) {
200
- return (BigInt(flags) & flag) !== 0n;
201
- }
202
- function rejectLinkedSingleEvent(flags) {
203
- if (flagIsSet(flags, LINKED_FLAG)) {
204
- throw new Error('--flag linked requires --payload or --file with a batch of events.');
205
- }
206
- }
207
- function omitEmpty(input) {
208
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined && value.trim().length > 0));
209
- }
210
- function randomTbId() {
211
- return BigInt(`0x${crypto.getRandomValues(new Uint8Array(16)).reduce((value, byte) => value + byte.toString(16).padStart(2, '0'), '')}`).toString();
212
- }
213
- function requiredValue(value, flagName) {
214
- if (!value || value.trim().length === 0) {
215
- throw new Error(`${flagName} is required unless --payload or --file is used.`);
216
- }
217
- return value.trim();
218
- }
219
- function requiredImportedTimestamp(value) {
220
- const timestamp = requiredValue(value, '--timestamp');
221
- if (!DECIMAL_INTEGER_REGEX.test(timestamp)) {
222
- throw new Error(IMPORTED_TIMESTAMP_ERROR);
223
- }
224
- const parsed = BigInt(timestamp);
225
- if (parsed === 0n || parsed >= TIGERBEETLE_TIMESTAMP_MAX_EXCLUSIVE) {
226
- throw new Error(IMPORTED_TIMESTAMP_ERROR);
227
- }
228
- return timestamp;
229
- }
230
- function valueOrZero(value) {
231
- const trimmed = value?.trim();
232
- return trimmed || '0';
233
- }
234
- function valueIsNonZero(value) {
235
- const trimmed = value?.trim();
236
- if (!trimmed) {
237
- return false;
238
- }
239
- return !DECIMAL_INTEGER_REGEX.test(trimmed) || BigInt(trimmed) !== 0n;
240
- }
241
- function splitIds(value) {
242
- if (!value) {
243
- return [];
244
- }
245
- return value
246
- .split(SPLIT_IDS_REGEX)
247
- .map((item) => item.trim())
248
- .filter(Boolean);
249
- }