@deliverd/sdk 0.39.0 → 0.40.0
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/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +1 -0
- package/dist/data-screen.d.ts +66 -0
- package/dist/data-screen.d.ts.map +1 -1
- package/dist/data-screen.js +138 -1
- package/dist/ledgers.d.ts +192 -0
- package/dist/ledgers.d.ts.map +1 -0
- package/dist/ledgers.js +672 -0
- package/dist/released.d.ts +1 -1
- package/dist/released.d.ts.map +1 -1
- package/dist/released.js +3118 -0
- package/package.json +1 -1
- package/src/adapters/index.ts +11 -0
- package/src/data-screen.ts +138 -1
- package/src/ledgers.ts +733 -0
- package/src/released.ts +3120 -0
package/package.json
CHANGED
package/src/adapters/index.ts
CHANGED
|
@@ -89,3 +89,14 @@ export { deliverdAllow, deliverdWebMcpAllow, describeStep, uiSdkApprovalRoute, U
|
|
|
89
89
|
export type { DeliverdAllowOptions, UiSdkApprovalAnswer, UiSdkApprovalRouteOptions, UiSdkAskContext, UiSdkStep } from "./ui-sdk.js";
|
|
90
90
|
export { defaultDescription, DEFAULT_TOOL_EXPIRY } from "./shared.js";
|
|
91
91
|
export type { Approver, CallDescription, CallOutcome, ToolApprovalOptions } from "./shared.js";
|
|
92
|
+
export {
|
|
93
|
+
FINANCE_ACTIONS,
|
|
94
|
+
FINANCE_ACTION_IDS,
|
|
95
|
+
LEDGERS,
|
|
96
|
+
LEDGER_LABEL,
|
|
97
|
+
classifyLedgerRequest,
|
|
98
|
+
classifyLedgerTool,
|
|
99
|
+
financeActionLabel,
|
|
100
|
+
maskAccount,
|
|
101
|
+
} from "../ledgers.js";
|
|
102
|
+
export type { FinanceActionId, Ledger, LedgerCall, LedgerInput } from "../ledgers.js";
|
package/src/data-screen.ts
CHANGED
|
@@ -58,6 +58,17 @@ export const DATA_KINDS = {
|
|
|
58
58
|
uk_national_insurance: { label: "UK National Insurance number", category: "personal", placeholder: "NINO", redactable: true },
|
|
59
59
|
ie_pps: { label: "Irish PPS number", category: "personal", placeholder: "PPS", redactable: true },
|
|
60
60
|
us_ssn: { label: "US Social Security number", category: "personal", placeholder: "SSN", redactable: true },
|
|
61
|
+
us_itin: { label: "US ITIN", category: "personal", placeholder: "ITIN", redactable: true },
|
|
62
|
+
ca_sin: { label: "Canadian Social Insurance number", category: "personal", placeholder: "SIN", redactable: true },
|
|
63
|
+
fr_nir: { label: "French social security number", category: "personal", placeholder: "NIR", redactable: true },
|
|
64
|
+
es_dni: { label: "Spanish DNI or NIE", category: "personal", placeholder: "DNI", redactable: true },
|
|
65
|
+
it_fiscal_code: { label: "Italian fiscal code", category: "personal", placeholder: "CF", redactable: true },
|
|
66
|
+
nl_bsn: { label: "Dutch BSN", category: "personal", placeholder: "BSN", redactable: true },
|
|
67
|
+
pl_pesel: { label: "Polish PESEL number", category: "personal", placeholder: "PESEL", redactable: true },
|
|
68
|
+
de_tax_id: { label: "German tax ID", category: "personal", placeholder: "STEUERID", redactable: true },
|
|
69
|
+
passport: { label: "Passport number", category: "personal", placeholder: "PASSPORT", redactable: true },
|
|
70
|
+
vat_number: { label: "VAT number", category: "financial", placeholder: "VAT", redactable: true },
|
|
71
|
+
bank_account: { label: "Bank account number", category: "financial", placeholder: "ACCOUNT", redactable: true },
|
|
61
72
|
ip_address: { label: "IP address", category: "personal", placeholder: "IP", redactable: true },
|
|
62
73
|
date_of_birth: { label: "Date of birth", category: "personal", placeholder: "DOB", redactable: true },
|
|
63
74
|
/** Never found by a pattern here: only by a model detector the caller plugs in (`spans`). */
|
|
@@ -175,6 +186,100 @@ function ipv6Valid(raw: string): boolean {
|
|
|
175
186
|
return compressed === 0 ? groups === 8 : compressed === 1 && groups >= 3 && groups <= 7;
|
|
176
187
|
}
|
|
177
188
|
|
|
189
|
+
/** An ITIN: 9XX-XX-XXXX with a middle group the IRS issues (50-65, 70-88, 90-92, 94-99). */
|
|
190
|
+
function itinValid(raw: string): boolean {
|
|
191
|
+
const g = Number(raw.slice(4, 6));
|
|
192
|
+
return (g >= 50 && g <= 65) || (g >= 70 && g <= 88) || (g >= 90 && g <= 92) || (g >= 94 && g <= 99);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** A Canadian SIN: nine digits, Luhn-checked; none is issued starting with 0 or 8. */
|
|
196
|
+
function sinValid(raw: string): boolean {
|
|
197
|
+
const d = digitsOf(raw);
|
|
198
|
+
return d.length === 9 && d[0] !== "0" && d[0] !== "8" && luhn(d);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** An ABA routing number: weights 3, 7, 1 repeating, a multiple of 10. */
|
|
202
|
+
function abaValid(raw: string): boolean {
|
|
203
|
+
const d = digitsOf(raw);
|
|
204
|
+
if (d.length !== 9 || /^0+$/.test(d)) return false;
|
|
205
|
+
let sum = 0;
|
|
206
|
+
for (let i = 0; i < 9; i++) sum += (d.charCodeAt(i) - 48) * [3, 7, 1][i % 3]!;
|
|
207
|
+
return sum % 10 === 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** A French NIR: thirteen digits (2A and 2B for Corsica) and a key, 97 minus the number mod 97. */
|
|
211
|
+
function nirValid(raw: string): boolean {
|
|
212
|
+
const s = raw.replace(/ /g, "").toUpperCase();
|
|
213
|
+
if (s.length !== 15) return false;
|
|
214
|
+
const body = s.slice(0, 13).replace("2A", "19").replace("2B", "18");
|
|
215
|
+
if (!/^\d{13}$/.test(body)) return false;
|
|
216
|
+
let mod = 0;
|
|
217
|
+
for (const ch of body) mod = (mod * 10 + (ch.charCodeAt(0) - 48)) % 97;
|
|
218
|
+
return 97 - mod === Number(s.slice(13));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** A Spanish DNI (eight digits) or NIE (X, Y or Z and seven), and its check letter. */
|
|
222
|
+
function dniValid(raw: string): boolean {
|
|
223
|
+
const s = raw.replace("-", "").toUpperCase();
|
|
224
|
+
const n = Number(s.slice(0, -1).replace(/^X/, "0").replace(/^Y/, "1").replace(/^Z/, "2"));
|
|
225
|
+
return "TRWAGMYFPDXBNJZSQVHLCKE"[n % 23] === s.at(-1);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const CF_ODD = [1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 2, 4, 18, 20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23];
|
|
229
|
+
|
|
230
|
+
/** An Italian codice fiscale and its check letter. */
|
|
231
|
+
function fiscalCodeValid(raw: string): boolean {
|
|
232
|
+
const s = raw.toUpperCase();
|
|
233
|
+
let sum = 0;
|
|
234
|
+
for (let i = 0; i < 15; i++) {
|
|
235
|
+
const c = s.charCodeAt(i);
|
|
236
|
+
const v = c >= 65 ? c - 65 : c - 48;
|
|
237
|
+
sum += i % 2 === 0 ? CF_ODD[v]! : v;
|
|
238
|
+
}
|
|
239
|
+
return String.fromCharCode(65 + (sum % 26)) === s[15];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** A Dutch BSN: the eleven test, weights 9 to 2 and -1 on the last digit. */
|
|
243
|
+
function bsnValid(raw: string): boolean {
|
|
244
|
+
const d = digitsOf(raw);
|
|
245
|
+
if (d.length !== 9 || /^0+$/.test(d)) return false;
|
|
246
|
+
let sum = 0;
|
|
247
|
+
for (let i = 0; i < 8; i++) sum += (d.charCodeAt(i) - 48) * (9 - i);
|
|
248
|
+
return (sum - (d.charCodeAt(8) - 48)) % 11 === 0;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** A Polish PESEL: weights 1, 3, 7, 9 repeating, and a check digit. */
|
|
252
|
+
function peselValid(raw: string): boolean {
|
|
253
|
+
if (!/^\d{11}$/.test(raw)) return false;
|
|
254
|
+
let sum = 0;
|
|
255
|
+
for (let i = 0; i < 10; i++) sum += (raw.charCodeAt(i) - 48) * [1, 3, 7, 9][i % 4]!;
|
|
256
|
+
return (10 - (sum % 10)) % 10 === raw.charCodeAt(10) - 48;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** A German Steuer-ID: eleven digits, not starting with 0, ISO 7064 MOD 11,10. */
|
|
260
|
+
function steuerIdValid(raw: string): boolean {
|
|
261
|
+
const d = digitsOf(raw);
|
|
262
|
+
if (d.length !== 11 || d[0] === "0") return false;
|
|
263
|
+
let product = 10;
|
|
264
|
+
for (let i = 0; i < 10; i++) {
|
|
265
|
+
let sum = (d.charCodeAt(i) - 48 + product) % 10;
|
|
266
|
+
if (sum === 0) sum = 10;
|
|
267
|
+
product = (2 * sum) % 11;
|
|
268
|
+
}
|
|
269
|
+
const check = 11 - product;
|
|
270
|
+
return (check === 10 ? 0 : check) === d.charCodeAt(10) - 48;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** A passport number after the word: some digits in it, so "passport holder" is not one. */
|
|
274
|
+
function passportValid(raw: string): boolean {
|
|
275
|
+
return digitsOf(raw).length >= 4;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** A VAT number after the word: written in capitals, as issued, with digits in it. */
|
|
279
|
+
function vatValid(raw: string): boolean {
|
|
280
|
+
return raw === raw.toUpperCase() && digitsOf(raw).length >= 6;
|
|
281
|
+
}
|
|
282
|
+
|
|
178
283
|
/** A value in a .env line that is a placeholder, not a credential. */
|
|
179
284
|
function envSecretValid(value: string): boolean {
|
|
180
285
|
return !/^[<{%(]/.test(value) && !/your|example|placeholder|changeme|xxxx/i.test(value);
|
|
@@ -234,6 +339,33 @@ const DETECTORS: Detector[] = [
|
|
|
234
339
|
pattern: /\b(?!BG|GB|NK|KN|TN|NT|ZZ)[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z] ?\d{2} ?\d{2} ?\d{2} ?[A-D]\b/g,
|
|
235
340
|
},
|
|
236
341
|
{ kind: "ie_pps", pattern: /\b\d{7}[A-W][A-IW]?\b/g, valid: ppsValid },
|
|
342
|
+
{ kind: "us_itin", pattern: /\b9\d{2}-\d{2}-\d{4}\b/g, valid: itinValid },
|
|
343
|
+
// Written in groups of three, or as nine digits after the words.
|
|
344
|
+
{ kind: "ca_sin", pattern: /\b\d{3}[ -]\d{3}[ -]\d{3}\b/g, valid: sinValid },
|
|
345
|
+
{ kind: "ca_sin", pattern: /\b(?:SIN|social insurance (?:number|no\.?))[ \t:#]*(\d{9})\b/gi, valid: sinValid, group: 1 },
|
|
346
|
+
{ kind: "fr_nir", pattern: /\b[12] ?\d{2} ?\d{2} ?(?:\d{2}|2[AB]) ?\d{3} ?\d{3} ?\d{2}\b/g, valid: nirValid },
|
|
347
|
+
{ kind: "es_dni", pattern: /\b(?:\d{8}|[XYZ]\d{7})-?[A-Z]\b/g, valid: dniValid },
|
|
348
|
+
{ kind: "it_fiscal_code", pattern: /\b[A-Z]{6}\d{2}[A-EHLMPRST]\d{2}[A-Z]\d{3}[A-Z]\b/g, valid: fiscalCodeValid },
|
|
349
|
+
// Nine or eleven bare digits are too often something else: these need the word before them.
|
|
350
|
+
{ kind: "nl_bsn", pattern: /\b(?:BSN|burgerservicenummer)(?:-?nummer)?[ \t:#.]*(\d{9}|\d{4}\.\d{2}\.\d{3}|\d{3}[ .]\d{3}[ .]\d{3})\b/gi, valid: bsnValid, group: 1 },
|
|
351
|
+
{ kind: "pl_pesel", pattern: /\bPESEL[ \t:#.]*(\d{11})\b/gi, valid: peselValid, group: 1 },
|
|
352
|
+
{
|
|
353
|
+
kind: "de_tax_id",
|
|
354
|
+
pattern: /\b(?:steuer-?id(?:entifikationsnummer)?|steuerliche identifikationsnummer|idnr\.?|tax id)[ \t:#.]*(\d{2} ?\d{3} ?\d{3} ?\d{3})\b/gi,
|
|
355
|
+
valid: steuerIdValid,
|
|
356
|
+
group: 1,
|
|
357
|
+
},
|
|
358
|
+
{ kind: "passport", pattern: /\bpassport(?: (?:no\.?|number|#))?[ \t:#]*([A-Z0-9]{6,9})\b/gi, valid: passportValid, group: 1 },
|
|
359
|
+
{
|
|
360
|
+
kind: "vat_number",
|
|
361
|
+
pattern: /\b(?:VAT|BTW|TVA|IVA|USt-?IdNr\.?)(?: (?:no\.?|number|reg(?:istration)?(?: no\.?| number)?|id))?[ \t:#.]*((?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK|XI) ?[0-9A-Z]{8,12})\b/gi,
|
|
362
|
+
valid: vatValid,
|
|
363
|
+
group: 1,
|
|
364
|
+
},
|
|
365
|
+
// Bank details after the words: a US routing number, a UK sort code, an account number.
|
|
366
|
+
{ kind: "bank_account", pattern: /\b(?:routing|ABA|RTN)(?: (?:no\.?|number|#))?[ \t:#]*(\d{9})\b/gi, valid: abaValid, group: 1 },
|
|
367
|
+
{ kind: "bank_account", pattern: /\bsort code[ \t:#]*(\d{2}[- ]?\d{2}[- ]?\d{2})\b/gi, group: 1 },
|
|
368
|
+
{ kind: "bank_account", pattern: /\b(?:account|acct|a\/c)(?: (?:no\.?|number|#))?[ \t:#]*(\d{8,17})\b/gi, group: 1 },
|
|
237
369
|
{ kind: "email", pattern: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}\b/g },
|
|
238
370
|
{
|
|
239
371
|
kind: "date_of_birth",
|
|
@@ -262,7 +394,7 @@ const DETECTORS: Detector[] = [
|
|
|
262
394
|
|
|
263
395
|
/** Earlier wins an overlap: a card number is not also a phone number. */
|
|
264
396
|
const PRIORITY: Record<DataKind, number> = Object.fromEntries(
|
|
265
|
-
["secret", "iban", "payment_card", "us_ssn", "uk_national_insurance", "ie_pps", "email", "date_of_birth", "phone", "ip_address", "term", "person_name", "special_category"].map(
|
|
397
|
+
["secret", "iban", "payment_card", "us_ssn", "uk_national_insurance", "ie_pps", "us_itin", "ca_sin", "fr_nir", "es_dni", "it_fiscal_code", "nl_bsn", "pl_pesel", "de_tax_id", "passport", "vat_number", "bank_account", "email", "date_of_birth", "phone", "ip_address", "term", "person_name", "special_category"].map(
|
|
266
398
|
(k, i) => [k, i]
|
|
267
399
|
)
|
|
268
400
|
) as Record<DataKind, number>;
|
|
@@ -466,6 +598,9 @@ export function readScreenPolicy(raw: unknown): ScreenPolicy {
|
|
|
466
598
|
};
|
|
467
599
|
}
|
|
468
600
|
|
|
601
|
+
/** Labels that start with a proper name, so they keep their capitals in a sentence. */
|
|
602
|
+
const KEEP_CASE: ReadonlySet<DataKind> = new Set(["ca_sin", "fr_nir", "it_fiscal_code", "nl_bsn", "pl_pesel", "de_tax_id"]);
|
|
603
|
+
|
|
469
604
|
const plural = (n: number, label: string) => `${n} ${label.toLowerCase()}${n === 1 ? "" : "s"}`;
|
|
470
605
|
|
|
471
606
|
/** "2 email addresses and 1 IBAN", for a reason or an approval's title. */
|
|
@@ -481,6 +616,8 @@ export function describeCounts(counts: ScreenCounts): string {
|
|
|
481
616
|
if (k === "ip_address") return `${n} IP address${n === 1 ? "" : "es"}`;
|
|
482
617
|
if (k === "date_of_birth") return `${n} date${n === 1 ? "" : "s"} of birth`;
|
|
483
618
|
if (k === "ie_pps") return `${n} Irish PPS number${n === 1 ? "" : "s"}`;
|
|
619
|
+
if (k === "es_dni") return `${n} Spanish ${n === 1 ? "DNI or NIE" : "DNIs or NIEs"}`;
|
|
620
|
+
if (KEEP_CASE.has(k)) return `${n} ${label}${n === 1 ? "" : "s"}`;
|
|
484
621
|
return /^[A-Z]{2,}/.test(label) ? `${n} ${label}${n === 1 ? "" : "s"}` : plural(n, label);
|
|
485
622
|
});
|
|
486
623
|
if (parts.length <= 1) return parts[0] ?? "nothing";
|