@oneie/cli 5.7.0 → 5.7.2
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/package.json +1 -1
- package/dist/src/lib/invoked-as.js +8 -1
- package/dist/src/lib/journey.d.ts +13 -2
- package/dist/src/lib/journey.js +18 -5
- package/dist/src/start.js +10 -6
- package/dist/src/wallet.d.ts +11 -0
- package/dist/src/wallet.js +14 -6
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
* back to `npx oneie`, which still runs.
|
|
13
13
|
*/
|
|
14
14
|
import { basename } from 'node:path';
|
|
15
|
+
/** A runner's package cache (npx · bunx · pnpm dlx): the bin it started is not on PATH. */
|
|
16
|
+
const EPHEMERAL = /[\\/](_npx|bunx-[^\\/]*|dlx)[\\/]/;
|
|
15
17
|
export function cliPrefix(argv = process.argv) {
|
|
16
|
-
|
|
18
|
+
const bin = argv[1] ?? '';
|
|
19
|
+
// `npx oneie` starts `.bin/one` (measured 2026-11-03 with oneie@5.7.0 — two bins,
|
|
20
|
+
// npx picked `one`), so the bin name alone said `one` in the one case it is wrong.
|
|
21
|
+
if (EPHEMERAL.test(bin))
|
|
22
|
+
return 'npx oneie';
|
|
23
|
+
return basename(bin) === 'one' ? 'one' : 'npx oneie';
|
|
17
24
|
}
|
|
@@ -96,8 +96,12 @@ export interface JourneyOptions {
|
|
|
96
96
|
name: string;
|
|
97
97
|
email?: string;
|
|
98
98
|
products: ProductSpec[];
|
|
99
|
-
/**
|
|
100
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Seconds to keep reading back the sale before ending at `pending`. 0 = read once.
|
|
101
|
+
* Unset: a first run reads once (nobody has been sent to pay yet); a re-run waits
|
|
102
|
+
* RERUN_WAIT_S, because the person was sent to pay and the webhook takes seconds.
|
|
103
|
+
*/
|
|
104
|
+
waitSeconds?: number;
|
|
101
105
|
/** Between read-backs while waiting. */
|
|
102
106
|
pollMs?: number;
|
|
103
107
|
}
|
|
@@ -117,6 +121,13 @@ export interface JourneyReport {
|
|
|
117
121
|
next?: string;
|
|
118
122
|
}
|
|
119
123
|
export declare const TEST_CARD = "4242 4242 4242 4242 \u00B7 any future expiry \u00B7 any CVC \u00B7 any postcode";
|
|
124
|
+
/**
|
|
125
|
+
* Measured 2026-11-03 (text/agent-path.md § 6): Stripe's webhook counted a paid sale
|
|
126
|
+
* 3.2 s after the receipt. A re-run straight after paying read 0 and stopped. 20 s at
|
|
127
|
+
* 2 s a read covers that six times over without holding a run that will never sell.
|
|
128
|
+
*/
|
|
129
|
+
export declare const RERUN_WAIT_S = 20;
|
|
130
|
+
export declare const RERUN_POLL_MS = 2000;
|
|
120
131
|
export declare const DEFAULT_PRODUCT: ProductSpec;
|
|
121
132
|
/** `"Name=9.99"` → a product in minor units. A spec that is not that shape is refused by name. */
|
|
122
133
|
export declare function parseProductSpec(raw: string, currency?: string): {
|
package/dist/src/lib/journey.js
CHANGED
|
@@ -21,6 +21,13 @@
|
|
|
21
21
|
* step is done only when `storefront:stats` reads back a purchase.
|
|
22
22
|
*/
|
|
23
23
|
export const TEST_CARD = '4242 4242 4242 4242 · any future expiry · any CVC · any postcode';
|
|
24
|
+
/**
|
|
25
|
+
* Measured 2026-11-03 (text/agent-path.md § 6): Stripe's webhook counted a paid sale
|
|
26
|
+
* 3.2 s after the receipt. A re-run straight after paying read 0 and stopped. 20 s at
|
|
27
|
+
* 2 s a read covers that six times over without holding a run that will never sell.
|
|
28
|
+
*/
|
|
29
|
+
export const RERUN_WAIT_S = 20;
|
|
30
|
+
export const RERUN_POLL_MS = 2000;
|
|
24
31
|
export const DEFAULT_PRODUCT = { name: 'Test product', amount: 100, currency: 'usd' };
|
|
25
32
|
/** `"Name=9.99"` → a product in minor units. A spec that is not that shape is refused by name. */
|
|
26
33
|
export function parseProductSpec(raw, currency = 'usd') {
|
|
@@ -150,10 +157,15 @@ async function productsStep(deps, o, state, key) {
|
|
|
150
157
|
detail: { mode: 'test money', products: have.map((p) => `${p.name} ${(p.amount / 100).toFixed(2)} ${p.currency.toUpperCase()} ${p.url}`) },
|
|
151
158
|
};
|
|
152
159
|
}
|
|
153
|
-
async function saleStep(deps, o, state, key) {
|
|
160
|
+
async function saleStep(deps, o, state, key, rerun) {
|
|
154
161
|
if (state.sale)
|
|
155
162
|
return { step: 'sale', status: 'done', reused: true, detail: { purchases: state.sale.purchases } };
|
|
156
|
-
|
|
163
|
+
// An explicit --wait wins; unset, only a re-run waits (and never NaN — an unset wait
|
|
164
|
+
// once made the deadline NaN, and `now >= NaN` is never true).
|
|
165
|
+
const asked = Number(o.waitSeconds);
|
|
166
|
+
const waitS = o.waitSeconds !== undefined && Number.isFinite(asked) ? Math.max(0, asked) : rerun ? RERUN_WAIT_S : 0;
|
|
167
|
+
const pollMs = o.pollMs ?? (o.waitSeconds === undefined ? RERUN_POLL_MS : 5000);
|
|
168
|
+
const deadline = deps.now() + waitS * 1000;
|
|
157
169
|
for (;;) {
|
|
158
170
|
const r = readAnswer(await deps.ask(key, 'storefront:stats', { slug: state.workspace }), 'storefront:stats');
|
|
159
171
|
if (!r.ok)
|
|
@@ -176,7 +188,7 @@ async function saleStep(deps, o, state, key) {
|
|
|
176
188
|
}
|
|
177
189
|
if (deps.now() >= deadline)
|
|
178
190
|
break;
|
|
179
|
-
await deps.sleep(
|
|
191
|
+
await deps.sleep(pollMs);
|
|
180
192
|
}
|
|
181
193
|
const first = state.products?.[0];
|
|
182
194
|
return {
|
|
@@ -220,13 +232,14 @@ export async function runJourney(deps, o) {
|
|
|
220
232
|
if (products.status !== 'done') {
|
|
221
233
|
return { ok: false, workspace: state.workspace, steps, next: 'fix the products step and run `npx oneie` again' };
|
|
222
234
|
}
|
|
223
|
-
|
|
235
|
+
// A re-run: the shop already had its products before this run, so someone was sent to pay.
|
|
236
|
+
const sale = await saleStep(deps, o, state, k.key, products.reused === true);
|
|
224
237
|
steps.push(sale);
|
|
225
238
|
const handover = handoverStep(state, sale.status === 'done');
|
|
226
239
|
steps.push(handover);
|
|
227
240
|
const failed = steps.some((s) => s.status === 'failed');
|
|
228
241
|
const next = sale.status === 'pending'
|
|
229
|
-
? 'pay with the test card at the link above, then run `npx oneie` again (or `npx oneie --wait
|
|
242
|
+
? 'pay with the test card at the link above, then run `npx oneie` again — it waits for the sale to land (or `npx oneie --wait 30` to wait here now)'
|
|
230
243
|
: undefined;
|
|
231
244
|
return { ok: !failed, workspace: state.workspace, steps, ...(next ? { next } : {}) };
|
|
232
245
|
}
|
package/dist/src/start.js
CHANGED
|
@@ -23,11 +23,15 @@ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
|
23
23
|
export const START_FLAGS = new Set(['--name', '--email', '--product', '--currency', '--wait', '--api']);
|
|
24
24
|
/** Bare `oneie`, or `oneie` led by a journey flag, runs `start`. Everything else is untouched. */
|
|
25
25
|
export function startArgv(argv) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
26
|
+
// `--json` is the program's own flag, so it stays in front of the subcommand:
|
|
27
|
+
// `npx oneie --json` runs the journey in JSON instead of printing Usage.
|
|
28
|
+
const lead = argv[2] === '--json' ? 3 : 2;
|
|
29
|
+
const head = argv.slice(0, lead);
|
|
30
|
+
if (argv.length === lead)
|
|
31
|
+
return [...head, 'start'];
|
|
32
|
+
const first = argv[lead]?.split('=')[0] ?? '';
|
|
29
33
|
if (START_FLAGS.has(first))
|
|
30
|
-
return [
|
|
34
|
+
return [...head, 'start', ...argv.slice(lead)];
|
|
31
35
|
return argv;
|
|
32
36
|
}
|
|
33
37
|
const statePath = (dir) => join(dir, KEY_DIR_NAME, 'journey.json');
|
|
@@ -165,7 +169,7 @@ export function startCmd() {
|
|
|
165
169
|
.option('--email <email>', "The new owner's email — the handover link is sent there as well as printed")
|
|
166
170
|
.option('--product <name=price>', 'A product in major units, e.g. "Mug=12.50" (repeatable; default one Test product at 1.00)', (v, acc) => [...acc, v], [])
|
|
167
171
|
.option('--currency <iso>', 'ISO 4217 for --product prices', 'usd')
|
|
168
|
-
.option('--wait <seconds>', 'Keep reading back the test sale this long before stopping at pending
|
|
172
|
+
.option('--wait <seconds>', 'Keep reading back the test sale this long before stopping at pending (default: a re-run waits 20 s, a first run reads once)')
|
|
169
173
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
170
174
|
.action(async (opts, sub) => {
|
|
171
175
|
const products = [];
|
|
@@ -187,7 +191,7 @@ export function startCmd() {
|
|
|
187
191
|
name: opts.name,
|
|
188
192
|
...(opts.email ? { email: opts.email } : {}),
|
|
189
193
|
products,
|
|
190
|
-
waitSeconds: Math.max(0, Number(opts.wait) || 0),
|
|
194
|
+
...(opts.wait !== undefined ? { waitSeconds: Math.max(0, Number(opts.wait) || 0) } : {}),
|
|
191
195
|
});
|
|
192
196
|
if (jsonMode(sub))
|
|
193
197
|
process.stdout.write(JSON.stringify(report) + '\n');
|
package/dist/src/wallet.d.ts
CHANGED
|
@@ -3,6 +3,17 @@ import { type Derivation, type GeneratedWallet } from '@oneie/sdk/wallet';
|
|
|
3
3
|
import { type VaultBlob, type SealOpts } from '@oneie/sdk/vault-file';
|
|
4
4
|
import { askPath } from './lib/api-path.js';
|
|
5
5
|
export { askPath };
|
|
6
|
+
type AskEnvelope = {
|
|
7
|
+
outcome?: string;
|
|
8
|
+
result?: Record<string, unknown>;
|
|
9
|
+
error?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The refusal as the server said it. `wallet:send → failure` alone hid the reason —
|
|
13
|
+
* measured 2026-11-03 (text/agent-path.md § Stop 8): the server had answered
|
|
14
|
+
* `forbidden · requires manage_workspace · callerRole agent · "Requires the owner role"`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function refusalMessage(receiver: string, envelope: AskEnvelope): string;
|
|
6
17
|
/**
|
|
7
18
|
* A FRESH mint is born v2 — the same as one.ie (`NEW_MASTER_DERIVATION` in
|
|
8
19
|
* one.ie/web/src/lib/derive-multichain.ts). Before this the CLI minted v1 and the
|
package/dist/src/wallet.js
CHANGED
|
@@ -14,9 +14,18 @@ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'ht
|
|
|
14
14
|
// in ./lib/api-path.ts so trade.ts/client.ts/coordinate.ts/catalog.ts can share
|
|
15
15
|
// it instead of each hardcoding /api/ask/<receiver> against DEFAULT_API.
|
|
16
16
|
export { askPath };
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The refusal as the server said it. `wallet:send → failure` alone hid the reason —
|
|
19
|
+
* measured 2026-11-03 (text/agent-path.md § Stop 8): the server had answered
|
|
20
|
+
* `forbidden · requires manage_workspace · callerRole agent · "Requires the owner role"`.
|
|
21
|
+
*/
|
|
22
|
+
export function refusalMessage(receiver, envelope) {
|
|
23
|
+
const r = envelope.result ?? {};
|
|
24
|
+
const why = [r.error ?? envelope.error, r.required && `requires ${String(r.required)}`, r.callerRole && `you are ${String(r.callerRole)}`]
|
|
25
|
+
.filter(Boolean).map(String);
|
|
26
|
+
const hint = typeof r.hint === 'string' ? ` — ${r.hint}` : '';
|
|
27
|
+
return `${receiver} → ${envelope.outcome}${why.length ? `: ${why.join(' · ')}` : ''}${hint}`;
|
|
28
|
+
}
|
|
20
29
|
async function ask(base, key, receiver, data) {
|
|
21
30
|
const res = await fetch(askPath(base, receiver), {
|
|
22
31
|
method: 'POST',
|
|
@@ -28,9 +37,8 @@ async function ask(base, key, receiver, data) {
|
|
|
28
37
|
throw new Error(`${receiver} → ${res.status}\n${body}`);
|
|
29
38
|
}
|
|
30
39
|
const envelope = (await res.json());
|
|
31
|
-
if (envelope.outcome && envelope.outcome !== 'result')
|
|
32
|
-
throw new Error(
|
|
33
|
-
}
|
|
40
|
+
if (envelope.outcome && envelope.outcome !== 'result')
|
|
41
|
+
throw new Error(refusalMessage(receiver, envelope));
|
|
34
42
|
return envelope.result ?? envelope;
|
|
35
43
|
}
|
|
36
44
|
const DEFAULT_PAY = process.env.ONEIE_PAY_URL ?? 'https://pay.one.ie';
|