@mercuryo-ai/magicpay-cli 0.1.1 → 0.1.4

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/README.md CHANGED
@@ -1,56 +1,76 @@
1
1
  # @mercuryo-ai/magicpay-cli
2
2
 
3
- Payment-only MagicPay CLI for session, secrets, and protected-form completion.
3
+ Protected-form CLI for MagicPay sessions, approvals, and one-time secret fills.
4
4
 
5
- `magicpay` is the payment-only MagicPay CLI surface for:
5
+ Choose this package when the browser is already at the correct login, identity,
6
+ or payment form and you want MagicPay to handle the protected part of the flow.
7
+ If you still need browser navigation and page interaction, pair it with
8
+ `@mercuryo-ai/agentbrowse-cli` or use `@mercuryo-ai/magicpay-agent-cli`.
6
9
 
7
- - gateway setup and health checks;
8
- - workflow session lifecycle;
9
- - secret catalog, request, poll, protected fill, and guarded submit/observe flow;
10
- - narrow browser attachment and protected-form completion on an already prepared page.
10
+ ## Before You Start
11
11
 
12
- ## Install
12
+ - Node.js 18 or newer
13
+ - A MagicPay account. Create it at `https://agents.mercuryo.io/signup`, then
14
+ create an API key in the dashboard.
15
+ - A browser page that is already at the protected step you want to complete
16
+
17
+ ## Install And Initialize
18
+
19
+ ```bash
20
+ npm i -g @mercuryo-ai/magicpay-cli@latest
21
+ magicpay init <magicpay-api-key>
22
+ magicpay --version
23
+ magicpay status
24
+ ```
25
+
26
+ ## Typical Flow
27
+
28
+ 1. Attach to the already running browser page.
29
+ 2. Start a workflow session.
30
+ 3. Find the protected form.
31
+ 4. Refresh the secrets catalog only if candidates are missing or stale.
32
+ 5. Request approval for one secret.
33
+ 6. Poll until the request is fulfilled or terminal.
34
+ 7. Run `fill-secret`.
35
+ 8. Use `submit-form` only as manual recovery if the normal flow still needs it.
36
+
37
+ Example:
38
+
39
+ ```bash
40
+ magicpay attach <cdp-url>
41
+ magicpay start-session "Checkout"
42
+ magicpay find-form
43
+ magicpay get-secrets-catalog
44
+ magicpay request-secret <fillRef> <storedSecretRef> --merchant-name "Example Store"
45
+ magicpay poll-secret <requestId>
46
+ magicpay fill-secret <fillRef> <requestId>
47
+ ```
48
+
49
+ ## Verify And Troubleshoot
50
+
51
+ Use these checks first:
13
52
 
14
53
  ```bash
15
- npm i -g @mercuryo-ai/magicpay-cli
16
- magicpay --help
54
+ magicpay --version
55
+ magicpay status
17
56
  ```
18
57
 
19
- ## Current surface
20
-
21
- - `init`
22
- - `status`
23
- - `attach`
24
- - `start-session`
25
- - `end-session`
26
- - `find-form`
27
- - `get-secrets-catalog`
28
- - `request-secret`
29
- - `mock-approve-secret`
30
- - `mock-deny-secret`
31
- - `poll-secret`
32
- - `fill-secret`
33
- - `submit-form`
34
-
35
- Browser attach happens over CDP:
36
-
37
- - `magicpay attach <cdp-url>`
38
-
39
- `magicpay fill-secret` now performs a post-fill refresh, auto-submits when it
40
- can resolve one live form-bound submit control, and returns a follow-up observe
41
- result when submission happens. `submit-form` remains available as a manual
42
- recovery surface.
43
-
44
- `magicpay status` stays quiet about CLI updates by default. When a newer npm
45
- release is available, it includes a short English notice and the suggested
46
- update command.
47
-
48
- ## Architecture boundary
49
-
50
- - `magicpay` is the operator CLI for workflow sessions, approvals, protected
51
- secret handling, and narrow form completion on the current page.
52
- - `@mercuryo-ai/agentbrowse` owns browser primitives and the reusable browser
53
- session store API.
54
- - `@mercuryo-ai/magicpay-sdk` owns reusable MagicPay API and flow helpers.
55
- - `@mercuryo-ai/magicpay-cli` owns branded payment CLI orchestration and the
56
- payment-safe command UX on top of the shared `~/.magicpay` home.
58
+ Use `magicpay doctor` only when `init` or `status` still fail and you need to
59
+ inspect the local MagicPay config. `mock-approve-secret` and
60
+ `mock-deny-secret` are development-only helpers, not production approval flows.
61
+
62
+ ## Command Groups
63
+
64
+ - Setup and diagnostics: `init`, `status`, `doctor`
65
+ - Session control: `attach`, `start-session`, `end-session`
66
+ - Protected form flow: `find-form`, `get-secrets-catalog`, `request-secret`,
67
+ `poll-secret`, `fill-secret`
68
+ - Development-only helpers: `mock-approve-secret`, `mock-deny-secret`
69
+ - Manual recovery: `submit-form`
70
+
71
+ ## Choose Another Package When
72
+
73
+ - You only need browser navigation, observation, or extraction:
74
+ use `@mercuryo-ai/agentbrowse-cli`
75
+ - You want one CLI for both browser work and protected fills:
76
+ use `@mercuryo-ai/magicpay-agent-cli`
@@ -1 +1 @@
1
- {"version":3,"file":"attach.d.ts","sourceRoot":"","sources":["../../src/commands/attach.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAQlC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AAE5C,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAO3F"}
1
+ {"version":3,"file":"attach.d.ts","sourceRoot":"","sources":["../../src/commands/attach.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAQlC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AAwB5C,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CA6B3F"}
@@ -1,7 +1,39 @@
1
1
  import { attach as attachBrowser, close as closeBrowser, } from '@mercuryo-ai/agentbrowse';
2
2
  import { loadMagicPayBrowserSession, loadMagicPaySession, saveMagicPaySession, } from '../workflow-state.js';
3
+ function currentPageMetadata(session) {
4
+ const runtime = session.runtime;
5
+ if (!runtime) {
6
+ return { url: '', title: '' };
7
+ }
8
+ const currentPageRef = runtime.currentPageRef;
9
+ const currentPage = (currentPageRef ? runtime.pages?.[currentPageRef] : undefined) ??
10
+ Object.values(runtime.pages ?? {})[0];
11
+ return {
12
+ url: currentPage?.url ?? '',
13
+ title: currentPage?.title ?? '',
14
+ };
15
+ }
3
16
  export async function attach(cdpUrl, options) {
4
- await closeBrowser(loadMagicPaySession() ?? loadMagicPayBrowserSession());
17
+ const existingSession = loadMagicPaySession() ?? loadMagicPayBrowserSession();
18
+ const normalizedCdpUrl = cdpUrl.trim();
19
+ if (existingSession?.cdpUrl?.trim() === normalizedCdpUrl) {
20
+ const session = existingSession;
21
+ const { url, title } = currentPageMetadata(session);
22
+ saveMagicPaySession(session);
23
+ return {
24
+ success: true,
25
+ runtime: 'attached',
26
+ session,
27
+ cdpUrl: session.cdpUrl,
28
+ url,
29
+ title,
30
+ ...(options?.provider ? { provider: options.provider } : {}),
31
+ captchaSolveCapable: options?.capabilities?.captchaSolve === true ||
32
+ (session.capabilities?.captchaSolve ===
33
+ true),
34
+ };
35
+ }
36
+ await closeBrowser(existingSession);
5
37
  const result = await attachBrowser(cdpUrl, options);
6
38
  if (result.success) {
7
39
  saveMagicPaySession(result.session);
@@ -0,0 +1,3 @@
1
+ import { type MagicPayConfigDoctorResult } from '@mercuryo-ai/magicpay-home';
2
+ export declare function doctor(): MagicPayConfigDoctorResult;
3
+ //# sourceMappingURL=doctor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAEnG,wBAAgB,MAAM,IAAI,0BAA0B,CAEnD"}
@@ -0,0 +1,4 @@
1
+ import { doctorMagicPayConfig } from '@mercuryo-ai/magicpay-home';
2
+ export function doctor() {
3
+ return doctorMagicPayConfig('magicpay');
4
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,IAAI,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QACP,gBAAgB,EAAE,IAAI,CAAC;QACvB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAMD,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAwBhE"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,IAAI,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QACP,gBAAgB,EAAE,IAAI,CAAC;QACvB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAwBhE"}
@@ -1,14 +1,9 @@
1
- import { getConfigPath, readConfig, writeConfig } from '../config.js';
1
+ import { getConfigPath, normalizeMagicPayApiUrl, readConfig, writeConfig } from '../config.js';
2
2
  import { DEFAULT_MAGICPAY_API_URL } from '../generated/build-config.js';
3
- function normalizeApiUrl(value) {
4
- return value.replace(/\/$/, '');
5
- }
6
3
  export function init(apiKey, apiUrl) {
7
4
  const config = readConfig();
8
5
  const normalizedApiKey = apiKey.trim();
9
- const normalizedApiUrl = apiUrl?.trim()
10
- ? normalizeApiUrl(apiUrl.trim())
11
- : DEFAULT_MAGICPAY_API_URL;
6
+ const normalizedApiUrl = normalizeMagicPayApiUrl(apiUrl?.trim() ? apiUrl.trim() : DEFAULT_MAGICPAY_API_URL);
12
7
  writeConfig({
13
8
  ...config,
14
9
  gateway: {
package/dist/config.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { getMagicPayConfigPath as getConfigPath, getMagicPayHomeDir as getStateDir, readMagicPayConfig as readConfig, writeMagicPayConfig as writeConfig, type MagicPaySharedConfig as MagicPayCliConfig, } from '@mercuryo-ai/magicpay-home';
1
+ export { getMagicPayConfigPath as getConfigPath, getMagicPayHomeDir as getStateDir, normalizeMagicPayApiUrl, readMagicPayConfig as readConfig, writeMagicPayConfig as writeConfig, type MagicPaySharedConfig as MagicPayCliConfig, } from '@mercuryo-ai/magicpay-home';
2
2
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,IAAI,aAAa,EACtC,kBAAkB,IAAI,WAAW,EACjC,kBAAkB,IAAI,UAAU,EAChC,mBAAmB,IAAI,WAAW,EAClC,KAAK,oBAAoB,IAAI,iBAAiB,GAC/C,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,IAAI,aAAa,EACtC,kBAAkB,IAAI,WAAW,EACjC,uBAAuB,EACvB,kBAAkB,IAAI,UAAU,EAChC,mBAAmB,IAAI,WAAW,EAClC,KAAK,oBAAoB,IAAI,iBAAiB,GAC/C,MAAM,4BAA4B,CAAC"}
package/dist/config.js CHANGED
@@ -1 +1 @@
1
- export { getMagicPayConfigPath as getConfigPath, getMagicPayHomeDir as getStateDir, readMagicPayConfig as readConfig, writeMagicPayConfig as writeConfig, } from '@mercuryo-ai/magicpay-home';
1
+ export { getMagicPayConfigPath as getConfigPath, getMagicPayHomeDir as getStateDir, normalizeMagicPayApiUrl, readMagicPayConfig as readConfig, writeMagicPayConfig as writeConfig, } from '@mercuryo-ai/magicpay-home';
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAE3B,MAAM,mCAAmC,CAAC;AA6B3C,wBAAgB,+BAA+B,IAAI,qBAAqB,GAAG,IAAI,CAiB9E;AAED,wBAAgB,4BAA4B,IAAI,qBAAqB,CAMpE;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,CAAC;AACzD,YAAY,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,CAAC;AAE3D,wBAAsB,qBAAqB,CACzC,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GACzC,OAAO,CAAC,mBAAmB,CAAC,CAE9B"}
1
+ {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAE3B,MAAM,mCAAmC,CAAC;AAyB3C,wBAAgB,+BAA+B,IAAI,qBAAqB,GAAG,IAAI,CAiB9E;AAED,wBAAgB,4BAA4B,IAAI,qBAAqB,CAMpE;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,CAAC;AACzD,YAAY,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,CAAC;AAE3D,wBAAsB,qBAAqB,CACzC,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GACzC,OAAO,CAAC,mBAAmB,CAAC,CAE9B"}
package/dist/gateway.js CHANGED
@@ -13,11 +13,8 @@ function trimOrUndefined(value) {
13
13
  }
14
14
  return trimmed;
15
15
  }
16
- function normalizeApiUrl(value) {
17
- return value.replace(/\/$/, '');
18
- }
19
16
  function appendApiPath(apiUrl, suffix) {
20
- return `${normalizeApiUrl(apiUrl)}${suffix.startsWith('/') ? suffix : `/${suffix}`}`;
17
+ return `${apiUrl}${suffix.startsWith('/') ? suffix : `/${suffix}`}`;
21
18
  }
22
19
  export function tryResolveMagicPayGatewayConfig() {
23
20
  const config = readConfig();
@@ -30,7 +27,7 @@ export function tryResolveMagicPayGatewayConfig() {
30
27
  }
31
28
  return {
32
29
  apiKey,
33
- apiUrl: normalizeApiUrl(apiUrl),
30
+ apiUrl,
34
31
  };
35
32
  }
36
33
  export function resolveMagicPayGatewayConfig() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AA0VA,wBAAsB,IAAI,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4HvE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAWzF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AA6VA,wBAAsB,IAAI,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiIvE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAWzF"}
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { config as loadEnv } from 'dotenv';
3
3
  import { realpathSync } from 'node:fs';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { attach } from './commands/attach.js';
6
+ import { doctor } from './commands/doctor.js';
6
7
  import { endSession } from './commands/end-session.js';
7
8
  import { fillSecret } from './commands/fill-secret.js';
8
9
  import { findForm } from './commands/find-form.js';
@@ -21,6 +22,7 @@ import { loadMagicPayBrowserSession, loadMagicPaySession, } from './workflow-sta
21
22
  loadEnv();
22
23
  const KNOWN_COMMANDS = new Set([
23
24
  'init',
25
+ 'doctor',
24
26
  'status',
25
27
  'attach',
26
28
  'start-session',
@@ -39,6 +41,7 @@ function usageText() {
39
41
 
40
42
  Commands:
41
43
  init <apiKey> [--api-url <url>] Configure MagicPay gateway access for the payment CLI
44
+ doctor Check persisted MagicPay config and gateway URL
42
45
  status Check gateway health and authenticated agent identity
43
46
  attach <cdp-url> [options] Attach the payment CLI to an already prepared browser over CDP
44
47
  start-session [name] [--merchant-name <name>]
@@ -294,6 +297,10 @@ export async function main(argv = process.argv) {
294
297
  outputJSON(init(initArgs.apiKey, initArgs.apiUrl));
295
298
  return;
296
299
  }
300
+ case 'doctor': {
301
+ outputJSON(doctor());
302
+ return;
303
+ }
297
304
  case 'status': {
298
305
  outputJSON(await status());
299
306
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercuryo-ai/magicpay-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "MagicPay CLI — payment/session/secrets shell with narrow protected-form completion",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -23,9 +23,31 @@
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/MercuryoAI/skills.git"
29
+ },
30
+ "homepage": "https://agents.mercuryo.io/docs/agents",
31
+ "bugs": {
32
+ "url": "https://github.com/MercuryoAI/skills/issues"
33
+ },
26
34
  "engines": {
27
35
  "node": ">=18.0.0"
28
36
  },
37
+ "dependencies": {
38
+ "@browserbasehq/stagehand": "^3.0.0",
39
+ "dotenv": "^16.4.0",
40
+ "@mercuryo-ai/magicpay-sdk": "0.1.0-test.5",
41
+ "@mercuryo-ai/magicpay-home": "0.1.6",
42
+ "@mercuryo-ai/agentbrowse": "0.2.53",
43
+ "@mercuryo-ai/captcha-solver": "0.1.1"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.0.0",
47
+ "tsx": "^4.19.0",
48
+ "typescript": "5.9.2",
49
+ "vitest": "^4.0.18"
50
+ },
29
51
  "scripts": {
30
52
  "build:config:dev": "node scripts/write-build-config.mjs https://durcottggsiesxxqzvbb.supabase.co/functions/v1/api",
31
53
  "build:config:prod": "node scripts/write-build-config.mjs https://agents-api.mercuryo.io/functions/v1/api",
@@ -40,19 +62,5 @@
40
62
  "test:unit:bare": "MAGICPAY_DISABLE_TELEMETRY=1 vitest run --exclude \"src/__tests__/*.e2e.test.ts\" --exclude \"dist/**\"",
41
63
  "test:e2e": "npm run test:deps && npm run test:e2e:bare",
42
64
  "test:e2e:bare": "MAGICPAY_DISABLE_TELEMETRY=1 vitest run --no-file-parallelism --maxWorkers=1 src/__tests__/protected-fill.e2e.test.ts"
43
- },
44
- "dependencies": {
45
- "@browserbasehq/stagehand": "^3.0.0",
46
- "@mercuryo-ai/captcha-solver": "workspace:*",
47
- "@mercuryo-ai/magicpay-sdk": "workspace:*",
48
- "@mercuryo-ai/magicpay-home": "workspace:*",
49
- "@mercuryo-ai/agentbrowse": "workspace:*",
50
- "dotenv": "^16.4.0"
51
- },
52
- "devDependencies": {
53
- "@types/node": "^22.0.0",
54
- "tsx": "^4.19.0",
55
- "typescript": "5.9.2",
56
- "vitest": "^4.0.18"
57
65
  }
58
- }
66
+ }