@envarai/envarpay 0.2.0-alpha.5 → 0.2.0-alpha.6
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.
package/dist/commerce/cli.js
CHANGED
|
@@ -24,9 +24,9 @@ const { values, positionals } = parseArgs({ allowPositionals: true, options: {
|
|
|
24
24
|
config: { type: 'string' }, service: { type: 'string' }, offer: { type: 'string' }, origin: { type: 'string' },
|
|
25
25
|
version: { type: 'boolean' }, help: { type: 'boolean', short: 'h' }, state: { type: 'string' }, credentials: { type: 'string' }, host: { type: 'string' },
|
|
26
26
|
port: { type: 'string' }, directory: { type: 'string' }, 'envar-config': { type: 'string' }, 'envar-credentials': { type: 'string' },
|
|
27
|
-
after: { type: 'string' }, limit: { type: 'string' },
|
|
27
|
+
after: { type: 'string' }, limit: { type: 'string' }, 'refund-review': { type: 'boolean' },
|
|
28
28
|
} });
|
|
29
|
-
const usage = 'envarpay init --directory DIR | inspect --state DB [--after ROW --limit 100] | validate --config seller.json | card --config seller.json --service ID --offer ID --origin URL | serve/buyer-serve --config FILE --credentials FILE --state DB --origin URL';
|
|
29
|
+
const usage = 'envarpay init --directory DIR | inspect --state DB [--after ROW --limit 100 --refund-review] | validate --config seller.json | card --config seller.json --service ID --offer ID --origin URL | serve/buyer-serve --config FILE --credentials FILE --state DB --origin URL';
|
|
30
30
|
const closers = [];
|
|
31
31
|
function privateFile(path) {
|
|
32
32
|
const stat = lstatSync(path);
|
|
@@ -87,9 +87,11 @@ async function run() {
|
|
|
87
87
|
}
|
|
88
88
|
const command = positionals[0];
|
|
89
89
|
if (command === 'inspect' && values.state) {
|
|
90
|
-
console.log(JSON.stringify(inspectLedger(values.state, Number(values.after ?? 0), Number(values.limit ?? 100)), null, 2));
|
|
90
|
+
console.log(JSON.stringify(inspectLedger(values.state, Number(values.after ?? 0), Number(values.limit ?? 100), values['refund-review'] ? 'refund-review' : 'attention'), null, 2));
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
+
if (values['refund-review'])
|
|
94
|
+
throw new CommerceError('inspection_view', 'Refund review is available only for inspect');
|
|
93
95
|
if ((values['envar-config'] || values['envar-credentials']) && command !== 'serve')
|
|
94
96
|
throw new CommerceError('envar_role', 'Configuration synchronization is available on seller serve only');
|
|
95
97
|
if (Boolean(values['envar-config']) !== Boolean(values['envar-credentials']))
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
export type InspectionView = 'attention' | 'refund-review';
|
|
1
2
|
/** Local owner-only diagnostics: never opens a signer, vault, provider or network. */
|
|
2
|
-
export declare function inspectLedger(path: string, after?: number, limit?: number): {
|
|
3
|
+
export declare function inspectLedger(path: string, after?: number, limit?: number, view?: InspectionView): {
|
|
3
4
|
role: string;
|
|
5
|
+
view: InspectionView;
|
|
4
6
|
total: number;
|
|
5
7
|
attentionCount: number;
|
|
8
|
+
refundReviewCount: number;
|
|
6
9
|
items: {
|
|
10
|
+
reason?: "confirmed_payment_failed_execution" | undefined;
|
|
7
11
|
cursor: number;
|
|
8
12
|
id: string;
|
|
9
13
|
paymentState: string;
|
|
@@ -13,4 +17,5 @@ export declare function inspectLedger(path: string, after?: number, limit?: numb
|
|
|
13
17
|
nextCursor: number;
|
|
14
18
|
hasMore: boolean;
|
|
15
19
|
paymentPerformed: boolean;
|
|
20
|
+
refundPerformed: boolean;
|
|
16
21
|
};
|
|
@@ -2,12 +2,14 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
2
2
|
import { lstatSync } from 'node:fs';
|
|
3
3
|
import { CommerceError } from './types.js';
|
|
4
4
|
/** Local owner-only diagnostics: never opens a signer, vault, provider or network. */
|
|
5
|
-
export function inspectLedger(path, after = 0, limit = 100) {
|
|
5
|
+
export function inspectLedger(path, after = 0, limit = 100, view = 'attention') {
|
|
6
6
|
const stat = lstatSync(path);
|
|
7
7
|
if (!stat.isFile() || stat.isSymbolicLink() || (stat.mode & 0o077) !== 0 || (process.getuid && stat.uid !== process.getuid()))
|
|
8
8
|
throw new CommerceError('private_file', 'Inspect an existing ledger owned only by the current user');
|
|
9
9
|
if (!Number.isSafeInteger(after) || after < 0 || !Number.isSafeInteger(limit) || limit < 1 || limit > 100)
|
|
10
10
|
throw new CommerceError('inspection_cursor', 'Use a nonnegative row cursor and a limit from1 to100');
|
|
11
|
+
if (!['attention', 'refund-review'].includes(view))
|
|
12
|
+
throw new CommerceError('inspection_view', 'Use attention or refund-review inspection');
|
|
11
13
|
const db = new DatabaseSync(path, { readOnly: true });
|
|
12
14
|
try {
|
|
13
15
|
db.exec('PRAGMA query_only=ON; PRAGMA busy_timeout=1000');
|
|
@@ -20,12 +22,15 @@ export function inspectLedger(path, after = 0, limit = 100) {
|
|
|
20
22
|
throw new CommerceError('store_version', 'Unsupported commerce ledger version');
|
|
21
23
|
const table = role === 'buyer' ? 'buyer_purchases' : 'commerce_orders';
|
|
22
24
|
const total = Number(db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get().n);
|
|
23
|
-
const
|
|
25
|
+
const attention = role === 'buyer' ? "json_extract(record_json,'$.state') IN ('signing','submitted','unknown') OR json_extract(record_json,'$.paymentState') IN ('reserved','unknown') OR json_extract(record_json,'$.executionState')='unknown'" : "payment_state IN ('settling','unknown') OR execution_state IN ('dispatching','unknown')";
|
|
26
|
+
const refundReview = role === 'buyer' ? "json_extract(record_json,'$.paymentState')='confirmed' AND json_extract(record_json,'$.executionState')='failed'" : "payment_state='confirmed' AND execution_state='failed'";
|
|
27
|
+
const filter = view === 'refund-review' ? refundReview : attention;
|
|
24
28
|
const selected = role === 'buyer' ? "rowid AS cursor,id,json_extract(record_json,'$.paymentState') AS payment_state,json_extract(record_json,'$.executionState') AS execution_state,json_extract(record_json,'$.task.id') AS task_id" : "rowid AS cursor,id,payment_state,execution_state,task_id";
|
|
25
29
|
const rows = db.prepare(`SELECT ${selected} FROM ${table} WHERE rowid>? AND (${filter}) ORDER BY rowid LIMIT ?`).all(after, limit + 1);
|
|
26
|
-
const page = rows.slice(0, limit).map(row => ({ cursor: Number(row.cursor), id: String(row.id), paymentState: String(row.payment_state), executionState: String(row.execution_state), taskId: typeof row.task_id === 'string' ? row.task_id : null }));
|
|
27
|
-
const attentionCount = Number(db.prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE ${
|
|
28
|
-
|
|
30
|
+
const page = rows.slice(0, limit).map(row => ({ cursor: Number(row.cursor), id: String(row.id), paymentState: String(row.payment_state), executionState: String(row.execution_state), taskId: typeof row.task_id === 'string' ? row.task_id : null, ...(view === 'refund-review' ? { reason: 'confirmed_payment_failed_execution' } : {}) }));
|
|
31
|
+
const attentionCount = Number(db.prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE ${attention}`).get().n);
|
|
32
|
+
const refundReviewCount = Number(db.prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE ${refundReview}`).get().n);
|
|
33
|
+
return { role, view, total, attentionCount, refundReviewCount, items: page, nextCursor: page.at(-1)?.cursor ?? after, hasMore: rows.length > limit, paymentPerformed: false, refundPerformed: false };
|
|
29
34
|
}
|
|
30
35
|
finally {
|
|
31
36
|
db.close();
|