@didit-protocol/mcp-server 5.1.36 → 5.1.51
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 +201 -29
- package/dist/app-api-key.d.ts +5 -0
- package/dist/app-api-key.d.ts.map +1 -0
- package/dist/app-api-key.js +108 -0
- package/dist/app-api-key.js.map +1 -0
- package/dist/auth/cached-verifier.d.ts +38 -0
- package/dist/auth/cached-verifier.d.ts.map +1 -0
- package/dist/auth/cached-verifier.js +82 -0
- package/dist/auth/cached-verifier.js.map +1 -0
- package/dist/auth/introspection-verifier.d.ts +12 -0
- package/dist/auth/introspection-verifier.d.ts.map +1 -1
- package/dist/auth/introspection-verifier.js +40 -14
- package/dist/auth/introspection-verifier.js.map +1 -1
- package/dist/chatgpt-app.d.ts +1 -0
- package/dist/chatgpt-app.d.ts.map +1 -1
- package/dist/chatgpt-app.js +2 -0
- package/dist/chatgpt-app.js.map +1 -1
- package/dist/config.d.ts +12 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +55 -8
- package/dist/config.js.map +1 -1
- package/dist/device-login.d.ts +98 -0
- package/dist/device-login.d.ts.map +1 -0
- package/dist/device-login.js +455 -0
- package/dist/device-login.js.map +1 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +61 -5
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +595 -47
- package/dist/index.js.map +1 -1
- package/dist/investigator-agent.d.ts +4 -0
- package/dist/investigator-agent.d.ts.map +1 -0
- package/dist/investigator-agent.js +10 -0
- package/dist/investigator-agent.js.map +1 -0
- package/dist/login-cli.d.ts +6 -0
- package/dist/login-cli.d.ts.map +1 -0
- package/dist/login-cli.js +47 -0
- package/dist/login-cli.js.map +1 -0
- package/dist/mcp-modern.d.ts +1 -0
- package/dist/mcp-modern.d.ts.map +1 -1
- package/dist/mcp-modern.js +1 -1
- package/dist/mcp-modern.js.map +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +29 -4
- package/dist/permissions.js.map +1 -1
- package/dist/privileged-tools.d.ts +1 -0
- package/dist/privileged-tools.d.ts.map +1 -1
- package/dist/privileged-tools.js +2 -1
- package/dist/privileged-tools.js.map +1 -1
- package/dist/schema/feature-config-schema.json +941 -28
- package/dist/security.d.ts +9 -8
- package/dist/security.d.ts.map +1 -1
- package/dist/security.js +11 -3
- package/dist/security.js.map +1 -1
- package/dist/signature-download.d.ts +31 -0
- package/dist/signature-download.d.ts.map +1 -0
- package/dist/signature-download.js +122 -0
- package/dist/signature-download.js.map +1 -0
- package/dist/tools/auth.d.ts +2 -0
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +114 -14
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/billing.d.ts +33 -2
- package/dist/tools/billing.d.ts.map +1 -1
- package/dist/tools/billing.js +252 -12
- package/dist/tools/billing.js.map +1 -1
- package/dist/tools/compliance.d.ts.map +1 -1
- package/dist/tools/compliance.js +37 -0
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/investigator.d.ts +19 -0
- package/dist/tools/investigator.d.ts.map +1 -0
- package/dist/tools/investigator.js +449 -0
- package/dist/tools/investigator.js.map +1 -0
- package/dist/tools/members.d.ts +8 -0
- package/dist/tools/members.d.ts.map +1 -1
- package/dist/tools/members.js +73 -4
- package/dist/tools/members.js.map +1 -1
- package/dist/tools/observability.d.ts +6 -0
- package/dist/tools/observability.d.ts.map +1 -1
- package/dist/tools/observability.js +11 -3
- package/dist/tools/observability.js.map +1 -1
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +89 -5
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/session-explain-levers.d.ts +6 -0
- package/dist/tools/session-explain-levers.d.ts.map +1 -1
- package/dist/tools/session-explain-levers.js +40 -7
- package/dist/tools/session-explain-levers.js.map +1 -1
- package/dist/tools/sessions.d.ts +24 -0
- package/dist/tools/sessions.d.ts.map +1 -1
- package/dist/tools/sessions.js +196 -2
- package/dist/tools/sessions.js.map +1 -1
- package/dist/tools/settings.d.ts.map +1 -1
- package/dist/tools/settings.js +3 -1
- package/dist/tools/settings.js.map +1 -1
- package/dist/tools/standalone.d.ts +5 -0
- package/dist/tools/standalone.d.ts.map +1 -1
- package/dist/tools/standalone.js +18 -2
- package/dist/tools/standalone.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../src/tools/billing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../src/tools/billing.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,QAAS,CAAC;AAMrC;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAU7F;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,eAAe,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAc/G;AAWD,wBAAsB,UAAU,CAC9B,cAAc,CAAC,EAAE,MAAM,EACvB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACtD,OAAO,CAAC,GAAG,CAAC,CAgBd;AAED,eAAO,MAAM,sBAAsB,qCAAsC,CAAC;AAC1E,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzE,MAAM,WAAW,YAAY;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAiDD,wBAAsB,KAAK,CACzB,eAAe,EAAE,OAAO,EACxB,OAAO,CAAC,EAAE,OAAO,EACjB,cAAc,CAAC,EAAE,MAAM,EACvB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,GAAG,CAAC,CAgCd;AA6BD,wBAAsB,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAGnE;AAKD,wBAAsB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,eAAe,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CA+B/G;AAED,wBAAsB,kBAAkB,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAS9E;AAED,wBAAsB,YAAY,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAEzG;AAED,wBAAsB,iBAAiB,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAE7E;AAOD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAuClH"}
|
package/dist/tools/billing.js
CHANGED
|
@@ -1,17 +1,92 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TOP_UP_PAYMENT_METHODS = exports.TOP_UP_MAXIMUM = void 0;
|
|
4
|
+
exports.billingLinks = billingLinks;
|
|
5
|
+
exports.signedTopUpLink = signedTopUpLink;
|
|
3
6
|
exports.getBalance = getBalance;
|
|
4
7
|
exports.topUp = topUp;
|
|
8
|
+
exports.getPlan = getPlan;
|
|
9
|
+
exports.quotePlan = quotePlan;
|
|
10
|
+
exports.listPaymentMethods = listPaymentMethods;
|
|
11
|
+
exports.listReceipts = listReceipts;
|
|
12
|
+
exports.getBillingDetails = getBillingDetails;
|
|
13
|
+
exports.updateBillingDetails = updateBillingDetails;
|
|
5
14
|
const config_1 = require("../config");
|
|
6
15
|
const security_1 = require("../security");
|
|
7
16
|
// Billing is ORG-level on the console (no flat /billing/balance/). The org top-up endpoint
|
|
8
|
-
// (GET) returns balance + auto-refill config;
|
|
17
|
+
// (GET) returns balance + auto-refill config; checkout-session (GET) creates a Stripe Checkout.
|
|
9
18
|
const TOP_UP_MINIMUM = 50;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
// Self-serve ceiling: the API refuses a larger checkout (raised from $10,000 on 5 Nov 2026).
|
|
20
|
+
exports.TOP_UP_MAXIMUM = 20000;
|
|
21
|
+
// What a top-up link pre-fills when the caller names no amount: the smallest common preset.
|
|
22
|
+
const DEFAULT_TOP_UP_LINK_AMOUNT = 100;
|
|
23
|
+
const CONSOLE_ORIGIN = new URL(config_1.MCP_AUTHORIZATION_SERVER_ORIGIN).origin;
|
|
24
|
+
/**
|
|
25
|
+
* Console pages where the PERSON finishes a billing action an agent cannot take for them: paying
|
|
26
|
+
* a top-up, saving a card, turning on automatic top-up, changing the plan. The agent never moves
|
|
27
|
+
* money; it hands over the link. `top_up_amount` opens the console's top-up dialog with the
|
|
28
|
+
* amount filled in (fe-application-console `TopUpDialog`).
|
|
29
|
+
*/
|
|
30
|
+
function billingLinks(organizationId, amount) {
|
|
31
|
+
const org = (0, security_1.pathSegment)((0, config_1.resolveOrganizationId)(organizationId), "organization_id");
|
|
32
|
+
const billing = `${CONSOLE_ORIGIN}/console/${org}/settings/billing`;
|
|
33
|
+
const topUp = amount && Number.isInteger(amount) && amount > 0 ? amount : DEFAULT_TOP_UP_LINK_AMOUNT;
|
|
34
|
+
return {
|
|
35
|
+
top_up_url: `${billing}?top_up_amount=${topUp}`,
|
|
36
|
+
automatic_top_up_url: `${billing}/payment-methods`,
|
|
37
|
+
plans_url: `${billing}/plans`,
|
|
38
|
+
billing_details_url: billing,
|
|
39
|
+
};
|
|
13
40
|
}
|
|
14
|
-
|
|
41
|
+
/**
|
|
42
|
+
* A signed top-up request link for the person: the console's Top up dialog opens with the amount
|
|
43
|
+
* filled in and says "Requested by <agent> for <person>". Creates no payment and moves no money
|
|
44
|
+
* (the backend only signs the amount), so it is allowed on every endpoint. Best effort: returns
|
|
45
|
+
* null when no amount is known, no Bearer is present, or the call fails, and the caller keeps the
|
|
46
|
+
* unsigned `?top_up_amount=` link.
|
|
47
|
+
*/
|
|
48
|
+
async function signedTopUpLink(amountInDollars, organizationId) {
|
|
49
|
+
if (typeof amountInDollars !== "number" || !Number.isFinite(amountInDollars) || amountInDollars < TOP_UP_MINIMUM || amountInDollars > exports.TOP_UP_MAXIMUM) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
if (!(0, config_1.getHeaders)().Authorization)
|
|
54
|
+
return null;
|
|
55
|
+
const res = await (0, config_1.apiRequest)((0, config_1.orgPath)("/billing/top-up-requests/", { organizationId }), {
|
|
56
|
+
method: "POST",
|
|
57
|
+
json: { amount_in_dollars: amountInDollars },
|
|
58
|
+
});
|
|
59
|
+
return typeof res?.url === "string" && res.url.startsWith("https://") ? res.url : null;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const PERSON_ACTS = "Didit tools never charge a card. Give the person the link: they confirm and pay in the Didit console " +
|
|
66
|
+
"(or turn on automatic top-up there, so a saved card refills the balance when it runs low).";
|
|
67
|
+
// The monthly free credit is decided per organization, and only /credits/ knows the outcome.
|
|
68
|
+
// It enriches the balance, so its failure must never cost the balance itself.
|
|
69
|
+
// `agentTopUp` (the agent payments endpoint and stdio only) adds whether the organization's
|
|
70
|
+
// "Connected AI agents can top up with your saved card" switch is on, so an agent knows before it
|
|
71
|
+
// tries. Best effort like the credit.
|
|
72
|
+
async function getBalance(organizationId, options = {}) {
|
|
73
|
+
const [balance, credits, agentSpending] = await Promise.all([
|
|
74
|
+
(0, config_1.apiRequest)((0, config_1.orgPath)("/top-up/", { organizationId })),
|
|
75
|
+
(0, config_1.apiRequest)((0, config_1.orgPath)("/credits/", { organizationId })).catch(() => null),
|
|
76
|
+
options.agentTopUp
|
|
77
|
+
? (0, config_1.apiRequest)((0, config_1.orgPath)("/billing/agent-spending/", { organizationId })).catch(() => null)
|
|
78
|
+
: Promise.resolve(null),
|
|
79
|
+
]);
|
|
80
|
+
const withCredit = credits?.free_credit ? { free_credit: credits.free_credit, ...balance } : balance;
|
|
81
|
+
const result = options.agentTopUp && typeof agentSpending?.enabled === "boolean"
|
|
82
|
+
? { ...withCredit, agent_top_up: { enabled: agentSpending.enabled } }
|
|
83
|
+
: withCredit;
|
|
84
|
+
if (!options.links)
|
|
85
|
+
return result;
|
|
86
|
+
return { ...result, next_steps: { ...billingLinks(organizationId), note: PERSON_ACTS } };
|
|
87
|
+
}
|
|
88
|
+
exports.TOP_UP_PAYMENT_METHODS = ["checkout", "saved_card"];
|
|
89
|
+
function assertTopUpAmount(amountInDollars) {
|
|
15
90
|
if (typeof amountInDollars !== "number" || !Number.isFinite(amountInDollars)) {
|
|
16
91
|
throw new security_1.DiditError({
|
|
17
92
|
code: "bad_request",
|
|
@@ -23,26 +98,191 @@ async function topUp(amountInDollars, confirm, successUrl, cancelUrl) {
|
|
|
23
98
|
if (amountInDollars < TOP_UP_MINIMUM) {
|
|
24
99
|
throw new security_1.DiditError({ code: "unprocessable", message: `Minimum top-up is $${TOP_UP_MINIMUM}.`, field: "amount" });
|
|
25
100
|
}
|
|
26
|
-
if (amountInDollars > TOP_UP_MAXIMUM) {
|
|
101
|
+
if (amountInDollars > exports.TOP_UP_MAXIMUM) {
|
|
27
102
|
throw new security_1.DiditError({
|
|
28
103
|
code: "unprocessable",
|
|
29
|
-
message: `Top-up amount exceeds the maximum of $${TOP_UP_MAXIMUM}.`,
|
|
104
|
+
message: `Top-up amount exceeds the maximum of $${exports.TOP_UP_MAXIMUM}.`,
|
|
30
105
|
field: "amount",
|
|
31
106
|
});
|
|
32
107
|
}
|
|
108
|
+
}
|
|
109
|
+
function resolvePaymentMethod(value) {
|
|
110
|
+
if (value === undefined || value === null)
|
|
111
|
+
return "checkout";
|
|
112
|
+
if (typeof value !== "string" || !exports.TOP_UP_PAYMENT_METHODS.includes(value)) {
|
|
113
|
+
throw new security_1.DiditError({
|
|
114
|
+
code: "bad_request",
|
|
115
|
+
message: "payment_method must be checkout or saved_card.",
|
|
116
|
+
field: "payment_method",
|
|
117
|
+
allowed: [...exports.TOP_UP_PAYMENT_METHODS],
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function assertIdempotencyKey(value) {
|
|
123
|
+
if (typeof value !== "string" || value.length < 1 || value.length > 255 || !value.trim()) {
|
|
124
|
+
throw new security_1.DiditError({
|
|
125
|
+
code: "bad_request",
|
|
126
|
+
message: "idempotency_key is required for payment_method saved_card: a string of 1 to 255 characters.",
|
|
127
|
+
field: "idempotency_key",
|
|
128
|
+
hint: "Choose ONE unique key per intended top-up (for example a UUID) and reuse the same key on any retry of " +
|
|
129
|
+
"that same top-up, so a retry can never charge the card twice.",
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function topUp(amountInDollars, confirm, organizationId, options = {}) {
|
|
134
|
+
assertTopUpAmount(amountInDollars);
|
|
135
|
+
const paymentMethod = resolvePaymentMethod(options.payment_method);
|
|
136
|
+
if (paymentMethod === "saved_card")
|
|
137
|
+
assertIdempotencyKey(options.idempotency_key);
|
|
33
138
|
(0, security_1.assertBoolean)(confirm, "confirm");
|
|
34
139
|
if (confirm !== true) {
|
|
35
140
|
throw new security_1.DiditError({
|
|
36
141
|
code: "unsafe_operation",
|
|
37
142
|
message: `Top-up of $${amountInDollars} moves money and is not confirmed.`,
|
|
38
143
|
field: "confirm",
|
|
39
|
-
hint:
|
|
144
|
+
hint: paymentMethod === "saved_card"
|
|
145
|
+
? "Re-call with confirm:true once a human has approved. saved_card charges the organization's saved card now."
|
|
146
|
+
: "Re-call with confirm:true once a human has approved. This returns a checkout URL; it never auto-charges.",
|
|
40
147
|
});
|
|
41
148
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
149
|
+
if (paymentMethod === "saved_card")
|
|
150
|
+
return topUpWithSavedCard(amountInDollars, options.idempotency_key, organizationId);
|
|
151
|
+
// The console's Checkout route (GET with the amount). The organization's top-up route answers
|
|
152
|
+
// GET/PUT only, so the POST this tool used to send was refused with 405 on every call.
|
|
153
|
+
const res = await (0, config_1.apiRequest)((0, config_1.orgPath)("/checkout-session/", { organizationId }), {
|
|
154
|
+
params: { amount_in_dollars: amountInDollars },
|
|
45
155
|
});
|
|
46
|
-
|
|
156
|
+
const signedLink = await signedTopUpLink(amountInDollars, organizationId);
|
|
157
|
+
return {
|
|
158
|
+
...res,
|
|
159
|
+
requires_human_approval: true,
|
|
160
|
+
next_steps: {
|
|
161
|
+
checkout: "Give the person checkout_session_url; the balance updates within seconds of payment.",
|
|
162
|
+
console_top_up_url: signedLink ?? billingLinks(organizationId, Math.round(amountInDollars)).top_up_url,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Charge the organization's saved primary card now, when a person turned on "Connected AI agents can top up with your saved card" in the console (off by default),
|
|
168
|
+
* through the console's agent route (the caller's Bearer: an MCP connection, or the local server's
|
|
169
|
+
* own login). One POST, never retried here: the Idempotency-Key makes a retry by the caller safe
|
|
170
|
+
* (same key, same amount returns the same top-up), and a new key would be a second charge. The
|
|
171
|
+
* backend body is the result; a refusal keeps its code, detail and next_step.
|
|
172
|
+
*/
|
|
173
|
+
async function topUpWithSavedCard(amountInDollars, idempotencyKey, organizationId) {
|
|
174
|
+
try {
|
|
175
|
+
return await (0, config_1.apiRequest)((0, config_1.orgPath)("/billing/agent-top-ups/", { organizationId }), {
|
|
176
|
+
method: "POST",
|
|
177
|
+
json: { amount_in_dollars: amountInDollars },
|
|
178
|
+
headers: { ...(0, config_1.getHeaders)(), "Idempotency-Key": idempotencyKey },
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
// The backend's own code (agent_top_up_not_enabled, authentication_required, ...) replaces the
|
|
183
|
+
// generic status code so the model can act on it; its next_step rides along unchanged.
|
|
184
|
+
if (error instanceof security_1.DiditError && error.shape.backend_code) {
|
|
185
|
+
// The generic per-status hint ("may require a different role") would mislead: next_step says what to do.
|
|
186
|
+
throw new security_1.DiditError({ ...error.shape, code: error.shape.backend_code, hint: undefined });
|
|
187
|
+
}
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// ── Plans and billing details (read, quote, and the details printed on invoices) ──────────────
|
|
192
|
+
async function getPlan(organizationId) {
|
|
193
|
+
const plan = await (0, config_1.apiRequest)((0, config_1.orgPath)("/billing/plans/", { organizationId }));
|
|
194
|
+
return { ...plan, next_steps: { plans_url: billingLinks(organizationId).plans_url } };
|
|
195
|
+
}
|
|
196
|
+
const PLANS = ["free", "growth", "scale"];
|
|
197
|
+
const INTERVALS = ["monthly", "yearly"];
|
|
198
|
+
async function quotePlan(plan, billingInterval, organizationId) {
|
|
199
|
+
if (typeof plan !== "string" || !PLANS.includes(plan)) {
|
|
200
|
+
throw new security_1.DiditError({
|
|
201
|
+
code: "bad_request",
|
|
202
|
+
message: "plan must be one of free, growth, scale.",
|
|
203
|
+
field: "plan",
|
|
204
|
+
allowed: [...PLANS],
|
|
205
|
+
hint: "Enterprise is an annual contract: the person contacts Didit sales from the Plans page.",
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (billingInterval !== undefined && !INTERVALS.includes(billingInterval)) {
|
|
209
|
+
throw new security_1.DiditError({
|
|
210
|
+
code: "bad_request",
|
|
211
|
+
message: "billing_interval must be monthly or yearly.",
|
|
212
|
+
field: "billing_interval",
|
|
213
|
+
allowed: [...INTERVALS],
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const quote = await (0, config_1.apiRequest)((0, config_1.orgPath)("/billing/plans/quote/", { organizationId }), {
|
|
217
|
+
params: { plan, billing_interval: billingInterval },
|
|
218
|
+
});
|
|
219
|
+
const interval = billingInterval === "yearly" ? "?billing=yearly" : "";
|
|
220
|
+
return {
|
|
221
|
+
...quote,
|
|
222
|
+
next_steps: {
|
|
223
|
+
plans_url: `${billingLinks(organizationId).plans_url}${interval}`,
|
|
224
|
+
note: "A plan change charges the saved card, so the person confirms it on the Plans page (Didit tools never " +
|
|
225
|
+
"buy a plan). Show them amount_due and credit_added from this quote first.",
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
async function listPaymentMethods(organizationId) {
|
|
230
|
+
const methods = await (0, config_1.apiRequest)((0, config_1.orgPath)("/billing/payment-methods/", { organizationId }));
|
|
231
|
+
return {
|
|
232
|
+
...methods,
|
|
233
|
+
next_steps: {
|
|
234
|
+
add_card_url: billingLinks(organizationId).automatic_top_up_url,
|
|
235
|
+
note: "Cards are added and removed by the person in the console; the card number never reaches an agent.",
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
async function listReceipts(organizationId, limit, offset) {
|
|
240
|
+
return (0, config_1.apiRequest)((0, config_1.orgPath)("/billing/receipts/", { organizationId }), { params: { limit, offset } });
|
|
241
|
+
}
|
|
242
|
+
async function getBillingDetails(organizationId) {
|
|
243
|
+
return (0, config_1.apiRequest)((0, config_1.orgPath)("/billing/details/", { organizationId }));
|
|
244
|
+
}
|
|
245
|
+
// The fields the console's Billing details dialog saves. A PUT replaces every one of them, so an
|
|
246
|
+
// update reads the saved details first and changes only what the caller passed.
|
|
247
|
+
const DETAIL_FIELDS = ["legal_name", "tax_id_type", "tax_id", "address", "billing_emails", "po_number"];
|
|
248
|
+
const ADDRESS_FIELDS = ["line1", "line2", "city", "state", "postal_code", "country"];
|
|
249
|
+
async function updateBillingDetails(changes, organizationId) {
|
|
250
|
+
const unknownKeys = Object.keys(changes).filter((key) => !DETAIL_FIELDS.includes(key));
|
|
251
|
+
if (unknownKeys.length) {
|
|
252
|
+
throw new security_1.DiditError({
|
|
253
|
+
code: "bad_request",
|
|
254
|
+
message: `Unknown billing detail(s): ${unknownKeys.join(", ")}.`,
|
|
255
|
+
allowed: [...DETAIL_FIELDS],
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (!Object.keys(changes).length) {
|
|
259
|
+
throw new security_1.DiditError({ code: "bad_request", message: "Pass at least one billing detail to change.", allowed: [...DETAIL_FIELDS] });
|
|
260
|
+
}
|
|
261
|
+
const saved = await getBillingDetails(organizationId);
|
|
262
|
+
const savedAddress = (saved?.address ?? {});
|
|
263
|
+
const changedAddress = (changes.address ?? {});
|
|
264
|
+
const body = {
|
|
265
|
+
legal_name: saved?.legal_name ?? "",
|
|
266
|
+
tax_id_type: saved?.tax_id_type ?? "",
|
|
267
|
+
tax_id: saved?.tax_id ?? "",
|
|
268
|
+
billing_emails: saved?.billing_emails ?? [],
|
|
269
|
+
po_number: saved?.po_number ?? "",
|
|
270
|
+
...changes,
|
|
271
|
+
address: Object.fromEntries(ADDRESS_FIELDS.map((field) => [field, changedAddress[field] ?? savedAddress[field] ?? ""])),
|
|
272
|
+
};
|
|
273
|
+
try {
|
|
274
|
+
return await (0, config_1.apiRequest)((0, config_1.orgPath)("/billing/details/", { organizationId }), { method: "PUT", json: body });
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
// The organization asks members to confirm sensitive billing changes with their authenticator,
|
|
278
|
+
// which an agent must never collect: the person saves the change in the console instead.
|
|
279
|
+
if (error instanceof security_1.DiditError && /otp|two-factor|authenticator|confirm/i.test(error.shape.message ?? "")) {
|
|
280
|
+
throw new security_1.DiditError({
|
|
281
|
+
...error.shape,
|
|
282
|
+
hint: `This organization confirms billing changes with an authenticator code. Ask the person to save them at ${billingLinks(organizationId).billing_details_url}.`,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
47
287
|
}
|
|
48
288
|
//# sourceMappingURL=billing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/tools/billing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/tools/billing.ts"],"names":[],"mappings":";;;AAoBA,oCAUC;AASD,0CAcC;AAWD,gCAmBC;AAyDD,sBAqCC;AA6BD,0BAGC;AAKD,8BA+BC;AAED,gDASC;AAED,oCAEC;AAED,8CAEC;AAOD,oDAuCC;AAtTD,sCAAoH;AACpH,0CAAqE;AAErE,2FAA2F;AAC3F,gGAAgG;AAEhG,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,6FAA6F;AAChF,QAAA,cAAc,GAAG,KAAM,CAAC;AACrC,4FAA4F;AAC5F,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAEvC,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,wCAA+B,CAAC,CAAC,MAAM,CAAC;AAEvE;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,cAAuB,EAAE,MAAe;IACnE,MAAM,GAAG,GAAG,IAAA,sBAAW,EAAC,IAAA,8BAAqB,EAAC,cAAc,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAClF,MAAM,OAAO,GAAG,GAAG,cAAc,YAAY,GAAG,mBAAmB,CAAC;IACpE,MAAM,KAAK,GAAG,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,0BAA0B,CAAC;IACrG,OAAO;QACL,UAAU,EAAE,GAAG,OAAO,kBAAkB,KAAK,EAAE;QAC/C,oBAAoB,EAAE,GAAG,OAAO,kBAAkB;QAClD,SAA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IAAC,OAAO,KAAK,EAAE,CAAC;QACf,+FAA+F;QAC/F,yFAAyF;QACzF,IAAI,KAAK,YAAY,qBAAU,IAAI,uCAAuC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;YAC3G,MAAM,IAAI,qBAAU,CAAC;gBACnB,GAAG,KAAK,CAAC,KAAK;gBACd,IAAI,EAAE,yGAAyG,YAAY,CAAC,cAAc,CAAC,CAAC,mBAAmB,GAAG;aACnK,CAAC,CAAC;QACL,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compliance.d.ts","sourceRoot":"","sources":["../../src/tools/compliance.ts"],"names":[],"mappings":"AAUA,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAG5E;
|
|
1
|
+
{"version":3,"file":"compliance.d.ts","sourceRoot":"","sources":["../../src/tools/compliance.ts"],"names":[],"mappings":"AAUA,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAG5E;AAsGD;;;;2EAI2E;AAC3E,wBAAsB,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAqB5E"}
|
package/dist/tools/compliance.js
CHANGED
|
@@ -66,6 +66,42 @@ function refuseUnknownSpecKeys(spec) {
|
|
|
66
66
|
"do not resend the same spec, and do not invent keys the builder does not have.",
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Steps a country branch may repeat from the trunk, because the branch node does something the
|
|
71
|
+
* trunk's does not: a document step captures ANOTHER document, a Database Validation queries the
|
|
72
|
+
* branch countries' own registries. Mirrors service-didit-verification's
|
|
73
|
+
* `spec_builder.BRANCH_REPEATABLE_FEATURES`; keep the two in sync.
|
|
74
|
+
*/
|
|
75
|
+
const BRANCH_REPEATABLE_FEATURES = new Set(["OCR", "PROOF_OF_ADDRESS", "KYB_DOCUMENTS", "DOCUMENT_AI", "DATABASE_VALIDATION"]);
|
|
76
|
+
/**
|
|
77
|
+
* Staging, 2026-11-04 (customer demo): "ID verification first; if the ID is from the UAE, an
|
|
78
|
+
* additional active liveness with flashing and AML screening; otherwise finish" came in as
|
|
79
|
+
* `features: [OCR, LIVENESS, AML]` plus a UAE branch with `[LIVENESS, AML]`. Every session would
|
|
80
|
+
* run them and the UAE twice. The backend now answers that spec with a question for the user, but
|
|
81
|
+
* the user's words were never the problem: the spec is the model's, so it is refused here, before
|
|
82
|
+
* any request, with the fix, the same way an invented key is (refuseUnknownSpecKeys).
|
|
83
|
+
*/
|
|
84
|
+
function refuseRepeatedBranchSteps(spec) {
|
|
85
|
+
const trunk = new Set((Array.isArray(spec.features) ? spec.features : []).map(String));
|
|
86
|
+
const branches = Array.isArray(spec.branches) ? spec.branches : [];
|
|
87
|
+
const repeats = branches.flatMap((branch, index) => (Array.isArray(branch?.features) ? branch.features : [])
|
|
88
|
+
.map(String)
|
|
89
|
+
.filter((feature) => trunk.has(feature) && !BRANCH_REPEATABLE_FEATURES.has(feature))
|
|
90
|
+
.map((feature) => ({ feature, index })));
|
|
91
|
+
if (repeats.length === 0)
|
|
92
|
+
return;
|
|
93
|
+
const steps = [...new Set(repeats.map((repeat) => repeat.feature))];
|
|
94
|
+
const where = [...new Set(repeats.map((repeat) => `branches[${repeat.index}]`))].join(", ");
|
|
95
|
+
throw new security_1.DiditError({
|
|
96
|
+
code: "bad_request",
|
|
97
|
+
message: `${steps.join(", ")} ${steps.length === 1 ? "is" : "are"} in features (the trunk EVERY session runs) and ` +
|
|
98
|
+
`again in ${where}.features, so ${steps.length === 1 ? "it" : "they"} would run twice for those countries.`,
|
|
99
|
+
field: "features",
|
|
100
|
+
hint: "A step runs in ONE place. \"If the ID is from X, also do Y\" means Y goes in that branch ONLY: remove it from " +
|
|
101
|
+
"features. Keep a step in features only when every session takes it, and then not in a branch. Rewrite the " +
|
|
102
|
+
"spec and call didit_workflow_build_graph again - do not ask the user.",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
69
105
|
/** Slim by default: the graph itself stays OUT of the model's context (the
|
|
70
106
|
* document catalog alone is ~100KB and stalled the flash arm into reasoning-only
|
|
71
107
|
* steps, 2026-09-02). The model gets a summary + the accepted spec and applies by
|
|
@@ -74,6 +110,7 @@ function refuseUnknownSpecKeys(spec) {
|
|
|
74
110
|
async function buildWorkflow(data) {
|
|
75
111
|
const { include_graph, ...spec } = withoutScope(data) ?? {};
|
|
76
112
|
refuseUnknownSpecKeys(spec);
|
|
113
|
+
refuseRepeatedBranchSteps(spec);
|
|
77
114
|
const built = await (0, config_1.apiRequest)((0, config_1.orgAppPath)("/compliance/build-workflow/"), { method: "POST", json: spec });
|
|
78
115
|
if (!built?.graph || include_graph)
|
|
79
116
|
return { ...built, spec };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compliance.js","sourceRoot":"","sources":["../../src/tools/compliance.ts"],"names":[],"mappings":";;AAUA,oCAGC;
|
|
1
|
+
{"version":3,"file":"compliance.js","sourceRoot":"","sources":["../../src/tools/compliance.ts"],"names":[],"mappings":";;AAUA,oCAGC;AA2GD,sCAqBC;AA7ID,sCAAmD;AACnD,0CAAyC;AAEzC,8FAA8F;AAC9F,uFAAuF;AACvF,+FAA+F;AAC/F,qCAAqC;AAErC,8FAA8F;AAC9F,6FAA6F;AAC7F,SAAgB,YAAY,CAAC,IAA0B;IACrD,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;IAChE,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,M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AAU,EAAC,6BAA6B,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1G,IAAI,CAAC,KAAK,EAAE,KAAK,IAAI,aAAa;QAAE,OAAO,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAA+B,CAAC;IACnF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACzC,OAAO;QACL,GAAG,IAAI;QACP,KAAK,EAAE,IAAI;QACX,IAAI;QACJ,aAAa,EAAE;YACb,UAAU,EAAE,KAAK,CAAC,MAAM;YACxB,QAAQ,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YACxG,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,MAAM;SACrE;QACD,YAAY,EACV,kGAAkG;YAClG,qGAAqG;KACxG,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type ToolDef = {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
inputSchema: any;
|
|
5
|
+
};
|
|
6
|
+
export declare const INVESTIGATOR_TOOL_DEFS: ToolDef[];
|
|
7
|
+
export declare function isInvestigatorToolName(name: string): boolean;
|
|
8
|
+
/** The decisions, the policy answers and the re-review (it replaces the open report): annotated destructive,
|
|
9
|
+
* gated on confirm:true. */
|
|
10
|
+
export declare const INVESTIGATOR_DECISION_TOOLS: string[];
|
|
11
|
+
/** Read-like by name, but it stores a backtest. */
|
|
12
|
+
export declare const INVESTIGATOR_WRITE_TOOLS: string[];
|
|
13
|
+
export declare const INVESTIGATOR_TOOL_PERMISSIONS: Record<string, string | null>;
|
|
14
|
+
/** The allowlisted X-Didit-Actor-Via of an incoming MCP request: "copilot" from the console
|
|
15
|
+
* assistant, anything else (absent, unknown) is "mcp". */
|
|
16
|
+
export declare function actorViaFromHeaders(headers: Record<string, string | string[] | undefined> | undefined): "copilot" | "mcp";
|
|
17
|
+
export declare function dispatchInvestigatorTool(name: string, rawArgs: Record<string, any> | undefined): Promise<any>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=investigator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigator.d.ts","sourceRoot":"","sources":["../../src/tools/investigator.ts"],"names":[],"mappings":"AAkBA,KAAK,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,GAAG,CAAA;CAAE,CAAC;AAuCvE,eAAO,MAAM,sBAAsB,EAAE,OAAO,EA0P3C,CAAC;AAIF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;6BAC6B;AAC7B,eAAO,MAAM,2BAA2B,EAAE,MAAM,EAO/C,CAAC;AAEF,mDAAmD;AACnD,eAAO,MAAM,wBAAwB,EAAE,MAAM,EAA0C,CAAC;AAKxF,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAkBvE,CAAC;AAEF;2DAC2D;AAC3D,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,SAAS,GAAG,SAAS,GAAG,KAAK,CAIzH;AAiED,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,CAqEnH"}
|