@reclaimprotocol/agent 0.1.10 → 0.1.12
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/lib/authoring/tools.js +67 -0
- package/lib/mcp/tools/agent/find.js +41 -16
- package/lib/mcp/tools/agent/propose.js +4 -4
- package/lib/old/client.d.ts +31 -5
- package/lib/old/client.js +33 -10
- package/lib/old/to-register.d.ts +2 -0
- package/lib/old/to-register.js +9 -5
- package/lib/old/tools/build.js +12 -2
- package/lib/old/tools/check-app-status.d.ts +8 -0
- package/lib/old/tools/check-app-status.js +27 -0
- package/lib/old/tools/get-provider-info.d.ts +10 -7
- package/lib/old/tools/get-provider-info.js +21 -15
- package/lib/old/tools/issue-app-credentials.d.ts +11 -0
- package/lib/old/tools/issue-app-credentials.js +35 -0
- package/lib/old/tools/js-sdk-integration-guide.d.ts +2 -0
- package/lib/old/tools/js-sdk-integration-guide.js +141 -0
- package/lib/old/tools/link-app.d.ts +10 -0
- package/lib/old/tools/link-app.js +72 -0
- package/lib/old/tools/publish.js +89 -126
- package/lib/old/tools/scaffold-demo-server.d.ts +2 -0
- package/lib/old/tools/scaffold-demo-server.js +242 -0
- package/lib/old/tools/verify-sdk-setup.d.ts +9 -0
- package/lib/old/tools/verify-sdk-setup.js +128 -0
- package/lib/provider/dom-xpath.js +178 -25
- package/lib/provider/draft.d.ts +6 -0
- package/lib/provider/draft.js +54 -5
- package/lib/provider/matcher.d.ts +4 -0
- package/lib/provider/matcher.js +6 -0
- package/lib/provider/to-version.d.ts +13 -0
- package/package.json +2 -1
- package/src/authoring/tools.ts +76 -0
- package/src/mcp/tools/agent/find.ts +44 -16
- package/src/mcp/tools/agent/propose.ts +4 -4
- package/src/old/client.ts +60 -18
- package/src/old/to-register.ts +11 -5
- package/src/old/tools/build.ts +12 -2
- package/src/old/tools/check-app-status.ts +33 -0
- package/src/old/tools/get-provider-info.ts +21 -15
- package/src/old/tools/issue-app-credentials.ts +42 -0
- package/src/old/tools/js-sdk-integration-guide.ts +147 -0
- package/src/old/tools/link-app.ts +88 -0
- package/src/old/tools/publish.ts +98 -158
- package/src/old/tools/scaffold-demo-server.ts +265 -0
- package/src/old/tools/verify-sdk-setup.ts +158 -0
- package/src/provider/dom-xpath.ts +227 -27
- package/src/provider/draft.ts +59 -5
- package/src/provider/matcher.ts +7 -0
- package/src/provider/to-version.ts +13 -0
- package/src/old/tools/get-version-config.ts +0 -56
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { defineTool } from "../../mcp/server.js";
|
|
2
|
+
/**
|
|
3
|
+
* Verified against `@reclaimprotocol/js-sdk` v5.8.1 source
|
|
4
|
+
* (`reclaim-js-sdk/src/Reclaim.ts`) — NOT copied unchecked from the archived
|
|
5
|
+
* `reclaim-mcp-server`'s guide, which predates several of these signatures.
|
|
6
|
+
* Corrections that matter most, all called out inline below:
|
|
7
|
+
* - `getRequestUrl()` and `ReclaimProofRequest.fromJsonString()` are ASYNC.
|
|
8
|
+
* - `setContext` is current; `addContext` is deprecated (calls setContext).
|
|
9
|
+
* - `verifyProof`'s second arg (`{ providerId, providerVersion? }`) is
|
|
10
|
+
* REQUIRED, not optional.
|
|
11
|
+
* - The verified result's flag is `isVerified` (camelCase), not
|
|
12
|
+
* `is_verified`.
|
|
13
|
+
* - A raw webhook body is TEXT — it must be JSON-parsed (and URL-decoded if
|
|
14
|
+
* form-encoded) into a `Proof`/`Proof[]` before calling `verifyProof`.
|
|
15
|
+
*/
|
|
16
|
+
const GUIDE = `# @reclaimprotocol/js-sdk — backend integration guide
|
|
17
|
+
|
|
18
|
+
Keep \`appSecret\` on your BACKEND only. Everything below runs server-side;
|
|
19
|
+
the browser only ever sees the \`requestUrl\`.
|
|
20
|
+
|
|
21
|
+
## Testing locally, without deploying anything
|
|
22
|
+
|
|
23
|
+
- **providerId \`"example"\`**: a canonical built-in smoke-test provider —
|
|
24
|
+
no need to author/publish your own provider just to confirm the SDK
|
|
25
|
+
plumbing works end-to-end. Swap in your real providerId once this passes.
|
|
26
|
+
- **ngrok for the callback URL**: \`setAppCallbackUrl\` needs a URL Reclaim's
|
|
27
|
+
servers can reach over the public internet — \`localhost\` will never
|
|
28
|
+
receive the callback. Run \`ngrok http 3000\` (or your port) alongside your
|
|
29
|
+
local server and set \`PUBLIC_URL\` to the \`https://<id>.ngrok-free.app\`
|
|
30
|
+
URL it prints. Without this, only the frontend-side flow (opening
|
|
31
|
+
\`requestUrl\` and polling/reading the result client-side) will work — the
|
|
32
|
+
async webhook never lands.
|
|
33
|
+
- \`scaffold_reclaim_demo_server\` defaults \`providerId\` to \`"example"\` and
|
|
34
|
+
its README calls out the ngrok step — use it to get a working local loop
|
|
35
|
+
before wiring in a real provider.
|
|
36
|
+
|
|
37
|
+
## 1. Install
|
|
38
|
+
|
|
39
|
+
\`\`\`bash
|
|
40
|
+
npm install @reclaimprotocol/js-sdk
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
## 2. Create a proof request (backend)
|
|
44
|
+
|
|
45
|
+
\`\`\`js
|
|
46
|
+
import { ReclaimProofRequest } from "@reclaimprotocol/js-sdk";
|
|
47
|
+
|
|
48
|
+
const reclaimProofRequest = await ReclaimProofRequest.init(
|
|
49
|
+
process.env.RECLAIM_APP_ID,
|
|
50
|
+
process.env.RECLAIM_APP_SECRET,
|
|
51
|
+
providerId,
|
|
52
|
+
{
|
|
53
|
+
// acceptAiProviders: true, // allow AI-verified providers
|
|
54
|
+
// useAppClip: true, // mobile app-clip flow instead of a browser popup
|
|
55
|
+
// providerVersion: "1.0.0", // pin a specific provider version
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// Deliver the verified proof back to your server asynchronously instead of
|
|
60
|
+
// (or in addition to) reading it from the frontend callback:
|
|
61
|
+
reclaimProofRequest.setAppCallbackUrl(
|
|
62
|
+
\`\${process.env.PUBLIC_URL}/webhooks/reclaim\`,
|
|
63
|
+
true, // jsonProofResponse: send the callback body as JSON, not form-encoded
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
// Optional: attach your own correlation id / metadata, retrievable later.
|
|
67
|
+
reclaimProofRequest.setContext(sessionId, JSON.stringify({ createdAt: Date.now() }));
|
|
68
|
+
|
|
69
|
+
// IMPORTANT: getRequestUrl() is ASYNC — await it.
|
|
70
|
+
const requestUrl = await reclaimProofRequest.getRequestUrl();
|
|
71
|
+
|
|
72
|
+
// Hand the requestUrl to the frontend to open in a new tab/window/webview.
|
|
73
|
+
// If you need to rehydrate this request object later (e.g. in the webhook
|
|
74
|
+
// handler, in a different process), persist reclaimProofRequest.toJsonString()
|
|
75
|
+
// (sync) and rehydrate with:
|
|
76
|
+
// const req = await ReclaimProofRequest.fromJsonString(json); // ASYNC
|
|
77
|
+
\`\`\`
|
|
78
|
+
|
|
79
|
+
## 3. Frontend: open the request URL
|
|
80
|
+
|
|
81
|
+
Fetch \`requestUrl\` from your backend, then open it (popup/new tab/QR code) —
|
|
82
|
+
never construct it in the browser, since that would require the appSecret
|
|
83
|
+
client-side. Trigger the fetch+open from a real user click (not a page-load
|
|
84
|
+
effect) or some browsers block the popup.
|
|
85
|
+
|
|
86
|
+
## 4. Verify the callback (backend webhook)
|
|
87
|
+
|
|
88
|
+
\`\`\`js
|
|
89
|
+
import { verifyProof } from "@reclaimprotocol/js-sdk";
|
|
90
|
+
|
|
91
|
+
app.post("/webhooks/reclaim", express.json(), async (req, res) => {
|
|
92
|
+
// req.body is already a parsed object here because jsonProofResponse was
|
|
93
|
+
// true above AND express.json() parsed it. If you did NOT set
|
|
94
|
+
// jsonProofResponse (or aren't using express.json()), the body arrives as
|
|
95
|
+
// form-encoded/raw text and must be JSON.parse()'d (and decodeURIComponent'd
|
|
96
|
+
// if form-encoded) into a Proof / Proof[] before calling verifyProof.
|
|
97
|
+
const proof = req.body;
|
|
98
|
+
|
|
99
|
+
// The second argument is REQUIRED — at minimum providerId.
|
|
100
|
+
const result = await verifyProof(proof, {
|
|
101
|
+
providerId,
|
|
102
|
+
// providerVersion, // optional, pin if you pinned it in init()
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
if (!result.isVerified) { // NOTE: isVerified, not is_verified
|
|
106
|
+
console.error("Proof verification failed:", result.error);
|
|
107
|
+
return res.status(400).json({ verified: false, error: result.error });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
console.log("Verified data:", result.data, result.publicData);
|
|
111
|
+
res.status(200).json({ verified: true });
|
|
112
|
+
});
|
|
113
|
+
\`\`\`
|
|
114
|
+
|
|
115
|
+
## Gotchas
|
|
116
|
+
|
|
117
|
+
- \`getRequestUrl()\` and \`ReclaimProofRequest.fromJsonString()\` are async —
|
|
118
|
+
a missing \`await\` silently hands you a Promise instead of a string/instance.
|
|
119
|
+
- \`verifyProof\`'s config arg is mandatory; omitting \`providerId\` throws.
|
|
120
|
+
- Prefer \`setContext\` over the deprecated \`addContext\` (same signature).
|
|
121
|
+
- \`ReclaimProofRequest.init\` needs network access to the Reclaim backend at
|
|
122
|
+
call time — don't call it at module load / cold-start if your platform pools
|
|
123
|
+
processes long-term; call it per-request instead.
|
|
124
|
+
- Use \`check_app_status\` (this MCP server) to confirm your app is linked
|
|
125
|
+
and not still sandbox-limited before debugging "verification never lands"
|
|
126
|
+
issues.
|
|
127
|
+
`;
|
|
128
|
+
export function getJsSdkIntegrationGuideTool() {
|
|
129
|
+
return defineTool({
|
|
130
|
+
name: 'get_js_sdk_integration_guide',
|
|
131
|
+
description: 'Return a verified, copy-pasteable guide for integrating ' +
|
|
132
|
+
'@reclaimprotocol/js-sdk (backend proof request + callback ' +
|
|
133
|
+
'verification), checked against the current SDK source rather than ' +
|
|
134
|
+
'assumed from older docs. Covers testing locally without deploying: ' +
|
|
135
|
+
'the built-in "example" providerId for a quick smoke test, and using ' +
|
|
136
|
+
'ngrok to get a callback URL Reclaim\'s servers can actually reach. ' +
|
|
137
|
+
'Use scaffold_reclaim_demo_server to generate a runnable local demo ' +
|
|
138
|
+
'instead of copy-pasting by hand.',
|
|
139
|
+
inputSchema: { type: 'object', properties: {} },
|
|
140
|
+
}, async () => ({ guide: GUIDE }));
|
|
141
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RegisteredTool } from '../../mcp/server.ts';
|
|
2
|
+
import type { ReclaimOldClient } from '../client.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Link an unassociated app (minted via `issue_app_credentials`, or any
|
|
5
|
+
* eth-keypair app you already hold the private key for) to the currently
|
|
6
|
+
* authenticated dashboard account. Proves ownership by signing a one-time
|
|
7
|
+
* challenge with the app's private key — the private key itself is only
|
|
8
|
+
* ever used locally to sign, never sent to the server.
|
|
9
|
+
*/
|
|
10
|
+
export declare function linkAppTool(client: ReclaimOldClient): RegisteredTool;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Wallet } from 'ethers';
|
|
2
|
+
import { defineTool } from "../../mcp/server.js";
|
|
3
|
+
/** Byte-for-byte the same format as the backend's `buildLinkMessage` in
|
|
4
|
+
* `application.controller.ts` — MUST stay in lockstep with it. */
|
|
5
|
+
function buildLinkMessage(appId, userId, nonce) {
|
|
6
|
+
return `Link ${appId} to account ${userId} | nonce: ${nonce}`;
|
|
7
|
+
}
|
|
8
|
+
/** The uid the backend binds into the signed message — `req.user.uid` there.
|
|
9
|
+
* For a bearer identity this comes back from `POST /users/login`; for an eth
|
|
10
|
+
* identity, `OldIdentity.uid` (already `eth:<address>`) IS that uid. */
|
|
11
|
+
async function resolveUserId(client) {
|
|
12
|
+
const identity = client.getIdentity();
|
|
13
|
+
if (!identity) {
|
|
14
|
+
throw new Error('Not authenticated against old devtools. Call reclaim_authenticate first.');
|
|
15
|
+
}
|
|
16
|
+
if (identity.kind === 'eth') {
|
|
17
|
+
return identity.uid;
|
|
18
|
+
}
|
|
19
|
+
const res = await client.loginWithToken();
|
|
20
|
+
const uid = res?.user?.uid;
|
|
21
|
+
if (!uid) {
|
|
22
|
+
throw new Error('Could not resolve your account uid from POST /users/login — ' +
|
|
23
|
+
'unexpected response shape.');
|
|
24
|
+
}
|
|
25
|
+
return uid;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Link an unassociated app (minted via `issue_app_credentials`, or any
|
|
29
|
+
* eth-keypair app you already hold the private key for) to the currently
|
|
30
|
+
* authenticated dashboard account. Proves ownership by signing a one-time
|
|
31
|
+
* challenge with the app's private key — the private key itself is only
|
|
32
|
+
* ever used locally to sign, never sent to the server.
|
|
33
|
+
*/
|
|
34
|
+
export function linkAppTool(client) {
|
|
35
|
+
return defineTool({
|
|
36
|
+
name: 'link_app_to_account',
|
|
37
|
+
description: 'Link an eth-keypair app to your authenticated dashboard account — ' +
|
|
38
|
+
'use this to keep using an appId/appSecret you already have ' +
|
|
39
|
+
'(instead of minting a fresh one via issue_app_credentials). ' +
|
|
40
|
+
'Requires reclaim_authenticate first. Fetches a one-time nonce, ' +
|
|
41
|
+
'signs `Link <appId> to account <userId> | nonce: <nonce>` locally ' +
|
|
42
|
+
'with `appSecret` (EIP-191, never transmitted), and submits the ' +
|
|
43
|
+
'signature. Fails with APP_ALREADY_LINKED if the app is already ' +
|
|
44
|
+
'linked to a (possibly different) account.',
|
|
45
|
+
inputSchema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
appId: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: 'The eth-address appId to link.',
|
|
51
|
+
},
|
|
52
|
+
appSecret: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
description: 'The app\'s raw eth private key — used only locally to sign ' +
|
|
55
|
+
'the link challenge, never sent to the server.',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ['appId', 'appSecret'],
|
|
59
|
+
},
|
|
60
|
+
}, async ({ appId, appSecret }) => {
|
|
61
|
+
const userId = await resolveUserId(client);
|
|
62
|
+
const { nonce } = await client.getLinkNonce();
|
|
63
|
+
const message = buildLinkMessage(appId, userId, nonce);
|
|
64
|
+
const signature = await new Wallet(appSecret).signMessage(message);
|
|
65
|
+
await client.linkAppToAccount(appId, signature, nonce);
|
|
66
|
+
return {
|
|
67
|
+
linked: true,
|
|
68
|
+
appId,
|
|
69
|
+
note: 'App linked to your account. Run check_app_status to confirm.',
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
package/lib/old/tools/publish.js
CHANGED
|
@@ -4,53 +4,6 @@ import { INJECTION_GUIDE } from "../../provider/injection-doc.js";
|
|
|
4
4
|
import { countsFor, matchRedactionWarnings, } from "../../provider/match-redaction-warning.js";
|
|
5
5
|
import { bumpPatchString, extractVersions, injectedRequestDataFrom, providerToConfigBody, providerToRegisterBody, } from "../to-register.js";
|
|
6
6
|
const DEFAULT_VERSION_INFO = 'Updated from MCP browser capture';
|
|
7
|
-
/** Fields with no partial-patch equivalent on this backend: a version always
|
|
8
|
-
* replaces the WHOLE `providerConfig`, so omitting one of these on
|
|
9
|
-
* add-version must carry forward the current value rather than publish it
|
|
10
|
-
* blank. `allowedInjectedRequestData` is handled alongside these (further
|
|
11
|
-
* down, inline) since it needs translation when freshly authored, unlike
|
|
12
|
-
* these — which pass through unchanged either way. */
|
|
13
|
-
const PRESERVABLE_KEYS = [
|
|
14
|
-
'customInjection',
|
|
15
|
-
'userAgent',
|
|
16
|
-
'pageTitle',
|
|
17
|
-
'stepsToFollow',
|
|
18
|
-
'useIncognitoWebview',
|
|
19
|
-
'extensionConfig',
|
|
20
|
-
];
|
|
21
|
-
/** Pull `providerConfig` out of a `get_provider_version_config` /
|
|
22
|
-
* `getProviderConfig` response, tolerant of a missing/malformed shape. */
|
|
23
|
-
function extractProviderConfig(resp) {
|
|
24
|
-
if (resp && typeof resp === 'object') {
|
|
25
|
-
const cfg = resp.providerConfig;
|
|
26
|
-
if (cfg && typeof cfg === 'object') {
|
|
27
|
-
return cfg;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
/** Prefer the caller's explicit value; otherwise fall back to `current`'s
|
|
33
|
-
* value (if any) and record `fieldName` as carried forward.
|
|
34
|
-
*
|
|
35
|
-
* `current === null` is treated the SAME as `undefined` (nothing to carry),
|
|
36
|
-
* not as a real value to preserve. These are all optional fields with no
|
|
37
|
-
* Prisma default — a version where one was never set reads back as
|
|
38
|
-
* `null`, not a missing key, because Prisma normalizes an absent optional
|
|
39
|
-
* field to `null` on read. Carrying that `null` "forward" would falsely
|
|
40
|
-
* claim the field was preserved when really nothing was ever there — it
|
|
41
|
-
* most likely means an EARLIER version already lost it (e.g. published
|
|
42
|
-
* before this field had carry-forward support at all), not that this call
|
|
43
|
-
* is doing anything wrong. */
|
|
44
|
-
function resolveField(explicit, current, fieldName, carried) {
|
|
45
|
-
if (explicit !== undefined) {
|
|
46
|
-
return explicit;
|
|
47
|
-
}
|
|
48
|
-
if (current !== undefined && current !== null) {
|
|
49
|
-
carried.push(fieldName);
|
|
50
|
-
return current;
|
|
51
|
-
}
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
7
|
/**
|
|
55
8
|
* The old backend lets you add a version only to a provider YOU own. A
|
|
56
9
|
* `providerId` for a public provider (or anyone else's) comes back as
|
|
@@ -111,23 +64,19 @@ export function createVersionFromCaptureTool(client) {
|
|
|
111
64
|
'For data gated behind login/navigation, pass `customInjection` — a ' +
|
|
112
65
|
'page-injection script (old-devtools\' name for the builder\'s ' +
|
|
113
66
|
'jsUserScripts) that drives the page to where the request fires. \n\n' +
|
|
114
|
-
'
|
|
115
|
-
'
|
|
116
|
-
'
|
|
117
|
-
'
|
|
118
|
-
'
|
|
119
|
-
'
|
|
120
|
-
'
|
|
121
|
-
'
|
|
122
|
-
'
|
|
123
|
-
'
|
|
124
|
-
'
|
|
125
|
-
'
|
|
126
|
-
'
|
|
127
|
-
'explicit value (`""`, `[]`, `false`, ...) to intentionally clear ' +
|
|
128
|
-
'one of them instead, or call get_provider_version_config FIRST ' +
|
|
129
|
-
'to see exactly what is live today, rather than assuming this ' +
|
|
130
|
-
'call recovered something that may already be gone. ' +
|
|
67
|
+
'BY DESIGN, this backend only ever CREATES A NEW VERSION (POST) — ' +
|
|
68
|
+
'there is no partial-patch/edit endpoint, and this tool does NOT ' +
|
|
69
|
+
'read or carry anything forward from the previous version. Every ' +
|
|
70
|
+
'new version replaces the WHOLE providerConfig with exactly what ' +
|
|
71
|
+
'you pass in THIS call. Therefore any field you want present in the ' +
|
|
72
|
+
'new version MUST be supplied here — `customInjection`, `userAgent`, ' +
|
|
73
|
+
'`pageTitle`, `allowedInjectedRequestData`, `stepsToFollow`, ' +
|
|
74
|
+
'`useIncognitoWebview`, `extensionConfig`, and `requestData` (via ' +
|
|
75
|
+
'`provider`/`providers`). Anything you OMIT is published blank/' +
|
|
76
|
+
'default in the new version, NOT preserved. To change one field ' +
|
|
77
|
+
'while keeping the rest, first read the current version with ' +
|
|
78
|
+
'get_provider_info, then pass the full desired config (the existing ' +
|
|
79
|
+
'values plus your change) back into this call. ' +
|
|
131
80
|
'`allowedInjectedRequestData`/`useIncognitoWebview`/' +
|
|
132
81
|
'`extensionConfig` only take effect on add-version — the register ' +
|
|
133
82
|
'endpoint (no `providerId`) ignores them. \n\n' +
|
|
@@ -156,8 +105,15 @@ export function createVersionFromCaptureTool(client) {
|
|
|
156
105
|
description: 'Multiple proven drafts → one multi-request version (each ' +
|
|
157
106
|
'becomes a parallel `requestData` entry, all verified ' +
|
|
158
107
|
'together). Each item has the same shape as `provider`. Pass ' +
|
|
159
|
-
'this OR `provider`, not both.'
|
|
160
|
-
|
|
108
|
+
'this OR `provider`, not both. May be omitted (or empty) ' +
|
|
109
|
+
'together with `provider` ONLY when adding a version to an ' +
|
|
110
|
+
'EXISTING provider (`providerId` set) — this publishes with ' +
|
|
111
|
+
'zero `requestData` entries, for a pure customInjection/' +
|
|
112
|
+
'HAWKEYE provider that relies entirely on ' +
|
|
113
|
+
'`allowedInjectedRequestData` for validation instead of a ' +
|
|
114
|
+
'static requestData stub. Registering a brand-new provider ' +
|
|
115
|
+
'always needs at least one draft (its name comes from the ' +
|
|
116
|
+
'first one).',
|
|
161
117
|
items: {
|
|
162
118
|
type: 'object',
|
|
163
119
|
properties: {
|
|
@@ -250,6 +206,26 @@ export function createVersionFromCaptureTool(client) {
|
|
|
250
206
|
type: 'boolean',
|
|
251
207
|
description: 'Fail validation if none match. Default true.',
|
|
252
208
|
},
|
|
209
|
+
templateParams: {
|
|
210
|
+
type: 'array',
|
|
211
|
+
items: { type: 'string' },
|
|
212
|
+
description: 'Names of `${var}` placeholders used in this ' +
|
|
213
|
+
'template\'s `responseMatches`/`responseRedactions` ' +
|
|
214
|
+
'that should be substituted at verify time from the ' +
|
|
215
|
+
'submitted proof\'s own witness params. Omit (or ' +
|
|
216
|
+
'leave empty) if the template has no such ' +
|
|
217
|
+
'placeholders.',
|
|
218
|
+
},
|
|
219
|
+
templateParamsMode: {
|
|
220
|
+
type: 'string',
|
|
221
|
+
enum: ['separate', 'merge'],
|
|
222
|
+
description: 'How multiple values for `templateParams` expand ' +
|
|
223
|
+
'into request specs. `separate` (default): one ' +
|
|
224
|
+
'independent spec per value, each matching its own ' +
|
|
225
|
+
'proof. `merge`: fold all values into ONE spec with ' +
|
|
226
|
+
'one match/redaction entry per value, matching a ' +
|
|
227
|
+
'single proof that bundles them all into one claim.',
|
|
228
|
+
},
|
|
253
229
|
},
|
|
254
230
|
required: ['url', 'method'],
|
|
255
231
|
},
|
|
@@ -274,29 +250,42 @@ export function createVersionFromCaptureTool(client) {
|
|
|
274
250
|
}, async (args) => {
|
|
275
251
|
// Exactly one of `provider` / `providers` — normalize to an array so a
|
|
276
252
|
// multi-request capture publishes every request, not just the first.
|
|
253
|
+
// Omitting both is allowed too, but ONLY when adding a version to an
|
|
254
|
+
// EXISTING provider (`providerId` set): that publishes with zero
|
|
255
|
+
// `requestData` entries, which only makes sense for a pure
|
|
256
|
+
// customInjection/HAWKEYE provider whose claims are validated entirely
|
|
257
|
+
// via `allowedInjectedRequestData` instead of a static requestData stub.
|
|
258
|
+
// Registering a brand-new provider (no `providerId`) still needs at
|
|
259
|
+
// least one draft — its name comes from the first one.
|
|
277
260
|
const hasMany = Array.isArray(args.providers) && args.providers.length > 0;
|
|
278
261
|
const hasOne = !!args.provider;
|
|
279
|
-
if (hasMany
|
|
280
|
-
throw new Boom('Pass
|
|
281
|
-
'(an array of 1+ drafts).', { statusCode: 400 });
|
|
282
|
-
}
|
|
283
|
-
const providers = hasMany ? args.providers : [args.provider];
|
|
284
|
-
const opts = { initialUrl: args.initialUrl };
|
|
285
|
-
if (args.description !== undefined) {
|
|
286
|
-
opts.description = args.description;
|
|
287
|
-
}
|
|
288
|
-
if (args.geoLocation !== undefined) {
|
|
289
|
-
opts.geoLocation = args.geoLocation;
|
|
262
|
+
if (hasMany && hasOne) {
|
|
263
|
+
throw new Boom('Pass at most one of `provider` (a single draft) or `providers` ' +
|
|
264
|
+
'(an array of 1+ drafts) — not both.', { statusCode: 400 });
|
|
290
265
|
}
|
|
291
|
-
if (args.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
if (args.customInjection !== undefined) {
|
|
298
|
-
opts.customInjection = args.customInjection;
|
|
266
|
+
if (!hasMany && !hasOne && !args.providerId) {
|
|
267
|
+
throw new Boom('Pass at least one of `provider`/`providers` when registering a ' +
|
|
268
|
+
'new provider (its name comes from the first draft). Omitting ' +
|
|
269
|
+
'both is only allowed when adding a version to an EXISTING ' +
|
|
270
|
+
'provider via `providerId`.', { statusCode: 400 });
|
|
299
271
|
}
|
|
272
|
+
const providers = hasMany ? args.providers : (hasOne ? [args.provider] : []);
|
|
273
|
+
const opts = {
|
|
274
|
+
initialUrl: args.initialUrl,
|
|
275
|
+
description: args.description,
|
|
276
|
+
geoLocation: args.geoLocation,
|
|
277
|
+
useProxy: args.useProxy,
|
|
278
|
+
providerType: args.providerType,
|
|
279
|
+
customInjection: args.customInjection,
|
|
280
|
+
userAgent: args.userAgent,
|
|
281
|
+
pageTitle: args.pageTitle,
|
|
282
|
+
stepsToFollow: args.stepsToFollow,
|
|
283
|
+
useIncognitoWebview: args.useIncognitoWebview,
|
|
284
|
+
extensionConfig: args.extensionConfig,
|
|
285
|
+
allowedInjectedRequestData: args.allowedInjectedRequestData
|
|
286
|
+
? injectedRequestDataFrom(args.allowedInjectedRequestData)
|
|
287
|
+
: undefined
|
|
288
|
+
};
|
|
300
289
|
// Non-blocking advisory per request — never alters or blocks the
|
|
301
290
|
// publish; the author keeps full control. Attaches under `_notes`.
|
|
302
291
|
const notes = matchRedactionWarnings(providers.map((p, i) => countsFor(`Request ${i + 1}`, p)));
|
|
@@ -325,20 +314,13 @@ export function createVersionFromCaptureTool(client) {
|
|
|
325
314
|
const ignoredOnRegister = REGISTER_IGNORED_KEYS
|
|
326
315
|
.filter((k) => args[k] !== undefined);
|
|
327
316
|
if (ignoredOnRegister.length) {
|
|
328
|
-
notes.push(`${ignoredOnRegister.join(', ')}
|
|
317
|
+
notes.push(`${ignoredOnRegister.join(', ')} ` +
|
|
318
|
+
`${ignoredOnRegister.length > 1 ? 'are' : 'is'} ` +
|
|
319
|
+
'ignored on register (no providerId) — the old backend only ' +
|
|
329
320
|
'reads them when adding a version. Publish once to create ' +
|
|
330
321
|
'the provider, then call this again WITH the returned ' +
|
|
331
322
|
'providerId to set them.');
|
|
332
323
|
}
|
|
333
|
-
if (args.userAgent !== undefined) {
|
|
334
|
-
opts.userAgent = args.userAgent;
|
|
335
|
-
}
|
|
336
|
-
if (args.pageTitle !== undefined) {
|
|
337
|
-
opts.pageTitle = args.pageTitle;
|
|
338
|
-
}
|
|
339
|
-
if (args.stepsToFollow !== undefined) {
|
|
340
|
-
opts.stepsToFollow = args.stepsToFollow;
|
|
341
|
-
}
|
|
342
324
|
const body = providerToRegisterBody(providers, opts);
|
|
343
325
|
return withNotes(await client.registerProvider(body));
|
|
344
326
|
}
|
|
@@ -348,42 +330,23 @@ export function createVersionFromCaptureTool(client) {
|
|
|
348
330
|
// workaround instead of a bare permission error.
|
|
349
331
|
const providerId = args.providerId;
|
|
350
332
|
try {
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
//
|
|
354
|
-
//
|
|
355
|
-
//
|
|
356
|
-
|
|
357
|
-
|| args.allowedInjectedRequestData === undefined;
|
|
358
|
-
const current = needsCurrent
|
|
359
|
-
? extractProviderConfig(await client.getProviderConfig(providerId))
|
|
360
|
-
: undefined;
|
|
361
|
-
const carried = [];
|
|
362
|
-
for (const key of PRESERVABLE_KEYS) {
|
|
363
|
-
const resolved = resolveField(args[key], current?.[key], key, carried);
|
|
364
|
-
if (resolved !== undefined) {
|
|
365
|
-
opts[key] = resolved;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
const freshInjected = args.allowedInjectedRequestData !== undefined
|
|
369
|
-
? injectedRequestDataFrom(args.allowedInjectedRequestData)
|
|
370
|
-
: undefined;
|
|
371
|
-
const resolvedInjected = resolveField(freshInjected, current?.allowedInjectedRequestData, 'allowedInjectedRequestData', carried);
|
|
372
|
-
if (resolvedInjected !== undefined) {
|
|
373
|
-
opts.allowedInjectedRequestData = resolvedInjected;
|
|
374
|
-
}
|
|
375
|
-
if (carried.length) {
|
|
376
|
-
notes.push('Not passed, carried forward unchanged from the current ' +
|
|
377
|
-
`published version: ${carried.join(', ')}. Pass an explicit ` +
|
|
378
|
-
'value ("", [], false, ...) to override any of them, or ' +
|
|
379
|
-
'call get_provider_version_config first to see what is ' +
|
|
380
|
-
'live today.');
|
|
381
|
-
}
|
|
333
|
+
// By design this always POSTs a brand-new version and publishes
|
|
334
|
+
// EXACTLY the config assembled above — nothing is read back or
|
|
335
|
+
// carried forward. Any field the caller omitted is already absent
|
|
336
|
+
// from `opts` and will be blank/default in the new version. To
|
|
337
|
+
// preserve existing fields, the caller must have read them via
|
|
338
|
+
// get_provider_info and passed them back in.
|
|
382
339
|
if (args.customInjection !== undefined && opts.customInjection?.trim()) {
|
|
383
340
|
notes.push('customInjection will run in the verification client before ' +
|
|
384
341
|
'every page load (before navigating to initialUrl), matching ' +
|
|
385
342
|
'the builder\'s jsUserScripts.');
|
|
386
343
|
}
|
|
344
|
+
notes.push('A NEW version was created with only the fields passed in this ' +
|
|
345
|
+
'call — nothing was carried forward from the previous version. ' +
|
|
346
|
+
'If you intended to keep other fields (customInjection, ' +
|
|
347
|
+
'userAgent, allowedInjectedRequestData, ...), read the prior ' +
|
|
348
|
+
'version with get_provider_info and re-publish with them ' +
|
|
349
|
+
'included.');
|
|
387
350
|
const versionsResp = await client.listVersions(providerId);
|
|
388
351
|
const version = bumpPatchString(extractVersions(versionsResp));
|
|
389
352
|
const versionInfo = args.notes && args.notes.trim().length >= 10
|