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