@clavis.nexus/setup 3.0.1 → 3.0.3
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 +44 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +514 -22
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +87 -1
- package/dist/index.js +301 -15
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +420 -17
- package/dist/mcp.js.map +1 -1
- package/package.json +9 -9
package/dist/mcp.js
CHANGED
|
@@ -7,8 +7,8 @@ import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprot
|
|
|
7
7
|
import { createRequire } from 'module';
|
|
8
8
|
import { execFile } from 'child_process';
|
|
9
9
|
import { promisify } from 'util';
|
|
10
|
-
import {
|
|
11
|
-
import path, {
|
|
10
|
+
import { mkdir, mkdtemp, writeFile, rename, rm, readFile, chmod, unlink, lstat } from 'fs/promises';
|
|
11
|
+
import path, { join, dirname, resolve, relative, isAbsolute } from 'path';
|
|
12
12
|
import { homedir } from 'os';
|
|
13
13
|
import { generateKeyPair, exportJWK, jwtVerify, importJWK } from 'jose';
|
|
14
14
|
import { createInterface } from 'readline/promises';
|
|
@@ -185,6 +185,71 @@ async function checkTrustRoot(apiOrigin, trustRootJson) {
|
|
|
185
185
|
await createVerifier({ trustRoot: trustRootJson, apiOrigin }).trust();
|
|
186
186
|
return JSON.stringify(JSON.parse(trustRootJson));
|
|
187
187
|
}
|
|
188
|
+
async function postAppLexDocument(apiOrigin, bearer, orgId, appId, url) {
|
|
189
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/apps/${encodeURIComponent(appId)}/lex-documents`, {
|
|
190
|
+
method: "POST",
|
|
191
|
+
bearer,
|
|
192
|
+
body: { url }
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
async function postAppLexProfileStatement(apiOrigin, bearer, orgId, appId, profile) {
|
|
196
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/apps/${encodeURIComponent(appId)}/lex-profile/statement`, {
|
|
197
|
+
method: "POST",
|
|
198
|
+
bearer,
|
|
199
|
+
body: { profile }
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
async function putAppLexProfile(apiOrigin, bearer, orgId, appId, args) {
|
|
203
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/apps/${encodeURIComponent(appId)}/lex-profile`, {
|
|
204
|
+
method: "PUT",
|
|
205
|
+
bearer,
|
|
206
|
+
body: { profile: args.profile, receipt: args.receipt }
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
async function postLexDecisionCounts(apiOrigin, bearer, orgId, query) {
|
|
210
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/decisions/counts`, { method: "POST", bearer, body: { query } });
|
|
211
|
+
}
|
|
212
|
+
async function postLexExportStatement(apiOrigin, bearer, orgId, request) {
|
|
213
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/exports/statement`, { method: "POST", bearer, body: { request } });
|
|
214
|
+
}
|
|
215
|
+
async function postLexExport(apiOrigin, bearer, orgId, args) {
|
|
216
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/exports`, {
|
|
217
|
+
method: "POST",
|
|
218
|
+
bearer,
|
|
219
|
+
body: { request: args.request, ...args.receipt !== void 0 ? { receipt: args.receipt } : {} }
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
async function getLexExports(apiOrigin, bearer, orgId) {
|
|
223
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/exports`, { bearer });
|
|
224
|
+
}
|
|
225
|
+
async function getLexExport(apiOrigin, bearer, orgId, jobId) {
|
|
226
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/exports/${encodeURIComponent(jobId)}`, { bearer });
|
|
227
|
+
}
|
|
228
|
+
async function getLexDecision(apiOrigin, bearer, orgId, decisionId) {
|
|
229
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/decisions/${encodeURIComponent(decisionId)}`, { bearer });
|
|
230
|
+
}
|
|
231
|
+
async function getLexSubjectDecisions(apiOrigin, bearer, orgId, subject) {
|
|
232
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/subjects/${encodeURIComponent(subject)}/decisions`, { bearer });
|
|
233
|
+
}
|
|
234
|
+
async function postLexSubjectErase(apiOrigin, bearer, orgId, subject, receipt) {
|
|
235
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/subjects/${encodeURIComponent(subject)}/erase`, {
|
|
236
|
+
method: "POST",
|
|
237
|
+
bearer,
|
|
238
|
+
body: { receipt }
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
async function getLexExportFile(apiOrigin, bearer, orgId, jobId, path2) {
|
|
242
|
+
const res = await fetch(
|
|
243
|
+
`${apiOrigin.replace(/\/+$/, "")}/orgs/${encodeURIComponent(orgId)}/lex/exports/${encodeURIComponent(jobId)}/files/${path2.split("/").map(encodeURIComponent).join("/")}`,
|
|
244
|
+
{ redirect: "error", headers: { Authorization: `Bearer ${bearer}` } }
|
|
245
|
+
);
|
|
246
|
+
if (!res.ok) {
|
|
247
|
+
const body = await res.json().catch(() => null);
|
|
248
|
+
const code = typeof body?.error === "string" ? body.error : `HTTP_${res.status}`;
|
|
249
|
+
throw new SetupApiError(res.status, code, typeof body?.message === "string" ? body.message : code);
|
|
250
|
+
}
|
|
251
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
252
|
+
}
|
|
188
253
|
|
|
189
254
|
// src/app-regions.ts
|
|
190
255
|
var APP_REGIONS = ["JP", "US", "GB", "EEA"];
|
|
@@ -550,6 +615,9 @@ function orgAppRegionsStatement(input2) {
|
|
|
550
615
|
regions: input2.regions === null ? null : [...new Set(input2.regions)].sort()
|
|
551
616
|
};
|
|
552
617
|
}
|
|
618
|
+
function orgLexSubjectEraseStatement(input2) {
|
|
619
|
+
return { type: "org.lex.subject_erase@1", org: input2.org.trim(), subject: input2.subject.trim() };
|
|
620
|
+
}
|
|
553
621
|
function orgCardIncorporationStatement(input2) {
|
|
554
622
|
return {
|
|
555
623
|
type: "org.card.incorporation_set@1",
|
|
@@ -1112,8 +1180,35 @@ async function buildSetupStatus(args) {
|
|
|
1112
1180
|
}
|
|
1113
1181
|
|
|
1114
1182
|
// src/setup-client.ts
|
|
1115
|
-
|
|
1116
|
-
|
|
1183
|
+
var LEX_SUBJECT = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
1184
|
+
var LEX_DECISION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
1185
|
+
var LEX_EXPORT_PATH = /^(manifest\.json|anchor\.json|items\/\d{5}\.jsonl|decisions\/[A-Za-z0-9._:-]{1,128}\.json)$/;
|
|
1186
|
+
async function bytesDigest(bytes) {
|
|
1187
|
+
return `sha256:${bytesToBase64Url(new Uint8Array(await crypto.subtle.digest("SHA-256", new Uint8Array(bytes))))}`;
|
|
1188
|
+
}
|
|
1189
|
+
function lexRefusal(e) {
|
|
1190
|
+
if (!(e instanceof SetupApiError)) return null;
|
|
1191
|
+
switch (e.code) {
|
|
1192
|
+
case "PROFILE_INVALID":
|
|
1193
|
+
return { ok: false, error: "profile_invalid \u2014 the agreement profile is incomplete (version, service_name, purposes, destinations and terminal_categories are required)." };
|
|
1194
|
+
case "DOCUMENT_NOT_SNAPSHOTTED":
|
|
1195
|
+
return { ok: false, error: "document_not_snapshotted \u2014 run app-lex-document for each document in the profile first, and use the sha256 it returns." };
|
|
1196
|
+
case "EXPORT_RUNNING":
|
|
1197
|
+
return { ok: false, error: "export_running \u2014 another export of this organisation is running. Wait for it, then start again." };
|
|
1198
|
+
case "EXPORT_TOO_LARGE":
|
|
1199
|
+
return { ok: false, error: "export_too_large \u2014 more decisions match than one export holds. Narrow the period (query.from, query.to) and start again." };
|
|
1200
|
+
case "FORBIDDEN":
|
|
1201
|
+
return { ok: false, error: "forbidden \u2014 only an owner or admin of the Org can do this." };
|
|
1202
|
+
case "NOT_FOUND":
|
|
1203
|
+
return { ok: false, error: "not_found \u2014 the Org, the App, the export or the decision was not found, or this is not open to the Org yet." };
|
|
1204
|
+
case "ORG_HOLD":
|
|
1205
|
+
return { ok: false, error: "org_hold \u2014 these records are preserved under a hold, so erasure waits until the hold ends. Nothing was erased." };
|
|
1206
|
+
default:
|
|
1207
|
+
return null;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
async function requireSession(sessionPath) {
|
|
1211
|
+
const stored = await loadSession(sessionPath);
|
|
1117
1212
|
if (!stored?.session?.accessToken) {
|
|
1118
1213
|
return {
|
|
1119
1214
|
ok: false,
|
|
@@ -1124,7 +1219,7 @@ async function requireSession(client) {
|
|
|
1124
1219
|
}
|
|
1125
1220
|
};
|
|
1126
1221
|
}
|
|
1127
|
-
return { ok: true, data: { session: stored.session, origins: stored.origins
|
|
1222
|
+
return { ok: true, data: { session: stored.session, origins: stored.origins } };
|
|
1128
1223
|
}
|
|
1129
1224
|
async function runPasskeyCeremony(args) {
|
|
1130
1225
|
const returnTo = setupCeremonyReturnTo(args.origins.developersOrigin);
|
|
@@ -1202,7 +1297,7 @@ function createSetupClient(options = {}) {
|
|
|
1202
1297
|
const checked = checkOrgCreationTerms(terms);
|
|
1203
1298
|
if (!checked.ok) return checked;
|
|
1204
1299
|
const { incorporation } = checked;
|
|
1205
|
-
const auth = await requireSession(
|
|
1300
|
+
const auth = await requireSession(sessionPath);
|
|
1206
1301
|
if (!auth.ok) return auth;
|
|
1207
1302
|
const apiOrigin = auth.data.origins.apiOrigin;
|
|
1208
1303
|
const closed = await getClosedIncorporations(apiOrigin).catch(() => []);
|
|
@@ -1256,7 +1351,7 @@ function createSetupClient(options = {}) {
|
|
|
1256
1351
|
};
|
|
1257
1352
|
},
|
|
1258
1353
|
async orgAnchorFinish(args) {
|
|
1259
|
-
const auth = await requireSession(
|
|
1354
|
+
const auth = await requireSession(sessionPath);
|
|
1260
1355
|
if (!auth.ok) return auth;
|
|
1261
1356
|
const payload = await pollCeremonyResult({
|
|
1262
1357
|
apiOrigin: auth.data.origins.apiOrigin,
|
|
@@ -1294,7 +1389,7 @@ function createSetupClient(options = {}) {
|
|
|
1294
1389
|
const checked = checkOrgCreationTerms(args);
|
|
1295
1390
|
if (!checked.ok) return checked;
|
|
1296
1391
|
const { incorporation } = checked;
|
|
1297
|
-
const auth = await requireSession(
|
|
1392
|
+
const auth = await requireSession(sessionPath);
|
|
1298
1393
|
if (!auth.ok) return auth;
|
|
1299
1394
|
try {
|
|
1300
1395
|
const out = await postVerifyAnchor(auth.data.origins.apiOrigin, auth.data.session.accessToken, {
|
|
@@ -1319,7 +1414,7 @@ function createSetupClient(options = {}) {
|
|
|
1319
1414
|
}
|
|
1320
1415
|
},
|
|
1321
1416
|
async policyBootstrap(orgId) {
|
|
1322
|
-
const auth = await requireSession(
|
|
1417
|
+
const auth = await requireSession(sessionPath);
|
|
1323
1418
|
if (!auth.ok) return auth;
|
|
1324
1419
|
const detail = await getOrg(auth.data.origins.apiOrigin, auth.data.session.accessToken, orgId);
|
|
1325
1420
|
try {
|
|
@@ -1351,7 +1446,7 @@ function createSetupClient(options = {}) {
|
|
|
1351
1446
|
const checked = checkOrgCreationTerms(args, INCORPORATION_TERMS_HUMAN);
|
|
1352
1447
|
if (!checked.ok) return checked;
|
|
1353
1448
|
const code = checked.incorporation;
|
|
1354
|
-
const auth = await requireSession(
|
|
1449
|
+
const auth = await requireSession(sessionPath);
|
|
1355
1450
|
if (!auth.ok) return auth;
|
|
1356
1451
|
const sub = auth.data.session.sub;
|
|
1357
1452
|
if (!sub) return { ok: false, error: "session_missing_sub \u2014 re-login" };
|
|
@@ -1389,7 +1484,7 @@ function createSetupClient(options = {}) {
|
|
|
1389
1484
|
async cardCheckout(orgId, opts = {}) {
|
|
1390
1485
|
const offer = opts.offer === "bundle" ? "bundle" : "meter";
|
|
1391
1486
|
const lang = checkoutLang(opts.lang);
|
|
1392
|
-
const auth = await requireSession(
|
|
1487
|
+
const auth = await requireSession(sessionPath);
|
|
1393
1488
|
if (!auth.ok) return auth;
|
|
1394
1489
|
const sub = auth.data.session.sub;
|
|
1395
1490
|
if (!sub) return { ok: false, error: "session_missing_sub \u2014 re-login" };
|
|
@@ -1472,7 +1567,7 @@ function createSetupClient(options = {}) {
|
|
|
1472
1567
|
};
|
|
1473
1568
|
},
|
|
1474
1569
|
async appRegister(args) {
|
|
1475
|
-
const auth = await requireSession(
|
|
1570
|
+
const auth = await requireSession(sessionPath);
|
|
1476
1571
|
if (!auth.ok) return auth;
|
|
1477
1572
|
const sub = auth.data.session.sub;
|
|
1478
1573
|
if (!sub) return { ok: false, error: "session_missing_sub \u2014 re-login" };
|
|
@@ -1517,7 +1612,7 @@ function createSetupClient(options = {}) {
|
|
|
1517
1612
|
};
|
|
1518
1613
|
},
|
|
1519
1614
|
async appHostPlan(orgId, appId) {
|
|
1520
|
-
const auth = await requireSession(
|
|
1615
|
+
const auth = await requireSession(sessionPath);
|
|
1521
1616
|
if (!auth.ok) return auth;
|
|
1522
1617
|
const ch = await getHostChallenge(auth.data.origins.apiOrigin, auth.data.session.accessToken, orgId, appId);
|
|
1523
1618
|
return {
|
|
@@ -1534,7 +1629,7 @@ function createSetupClient(options = {}) {
|
|
|
1534
1629
|
};
|
|
1535
1630
|
},
|
|
1536
1631
|
async appVerifyHost(args) {
|
|
1537
|
-
const auth = await requireSession(
|
|
1632
|
+
const auth = await requireSession(sessionPath);
|
|
1538
1633
|
if (!auth.ok) return auth;
|
|
1539
1634
|
const ch = await getHostChallenge(
|
|
1540
1635
|
auth.data.origins.apiOrigin,
|
|
@@ -1575,7 +1670,7 @@ function createSetupClient(options = {}) {
|
|
|
1575
1670
|
}
|
|
1576
1671
|
},
|
|
1577
1672
|
async declarationSet(args) {
|
|
1578
|
-
const auth = await requireSession(
|
|
1673
|
+
const auth = await requireSession(sessionPath);
|
|
1579
1674
|
if (!auth.ok) return auth;
|
|
1580
1675
|
const declaration = { endUsers: args.endUsers, uses: args.uses };
|
|
1581
1676
|
const cer = await runPasskeyCeremony({
|
|
@@ -1599,7 +1694,7 @@ function createSetupClient(options = {}) {
|
|
|
1599
1694
|
const read = readAppRegionsInput(args.regions);
|
|
1600
1695
|
if (!read.ok) return read;
|
|
1601
1696
|
const regions = read.regions;
|
|
1602
|
-
const auth = await requireSession(
|
|
1697
|
+
const auth = await requireSession(sessionPath);
|
|
1603
1698
|
if (!auth.ok) return auth;
|
|
1604
1699
|
const sub = auth.data.session.sub;
|
|
1605
1700
|
if (!sub) return { ok: false, error: "session_missing_sub \u2014 re-login" };
|
|
@@ -1632,6 +1727,197 @@ function createSetupClient(options = {}) {
|
|
|
1632
1727
|
throw e;
|
|
1633
1728
|
}
|
|
1634
1729
|
},
|
|
1730
|
+
async appLexDocument(args) {
|
|
1731
|
+
const auth = await requireSession(sessionPath);
|
|
1732
|
+
if (!auth.ok) return auth;
|
|
1733
|
+
try {
|
|
1734
|
+
return { ok: true, data: await postAppLexDocument(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.appId, args.url) };
|
|
1735
|
+
} catch (e) {
|
|
1736
|
+
const refusal = lexRefusal(e);
|
|
1737
|
+
if (refusal) return refusal;
|
|
1738
|
+
throw e;
|
|
1739
|
+
}
|
|
1740
|
+
},
|
|
1741
|
+
async appLexProfileSet(args) {
|
|
1742
|
+
const auth = await requireSession(sessionPath);
|
|
1743
|
+
if (!auth.ok) return auth;
|
|
1744
|
+
const apiOrigin = auth.data.origins.apiOrigin;
|
|
1745
|
+
const bearer = auth.data.session.accessToken;
|
|
1746
|
+
try {
|
|
1747
|
+
const prepared = await postAppLexProfileStatement(apiOrigin, bearer, args.orgId, args.appId, args.profile);
|
|
1748
|
+
const cer = await runPasskeyCeremony({
|
|
1749
|
+
origins: auth.data.origins,
|
|
1750
|
+
bearer,
|
|
1751
|
+
statement: prepared.statement,
|
|
1752
|
+
displayHint: args.profile === null ? "Clear the App's agreement profile" : "Set the App's agreement profile",
|
|
1753
|
+
openBrowserFlag
|
|
1754
|
+
});
|
|
1755
|
+
const proof = await cer.wait();
|
|
1756
|
+
return { ok: true, data: await putAppLexProfile(apiOrigin, bearer, args.orgId, args.appId, { profile: args.profile, receipt: proof }) };
|
|
1757
|
+
} catch (e) {
|
|
1758
|
+
const refusal = lexRefusal(e);
|
|
1759
|
+
if (refusal) return refusal;
|
|
1760
|
+
throw e;
|
|
1761
|
+
}
|
|
1762
|
+
},
|
|
1763
|
+
async lexCounts(args) {
|
|
1764
|
+
const auth = await requireSession(sessionPath);
|
|
1765
|
+
if (!auth.ok) return auth;
|
|
1766
|
+
try {
|
|
1767
|
+
return { ok: true, data: await postLexDecisionCounts(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.query ?? {}) };
|
|
1768
|
+
} catch (e) {
|
|
1769
|
+
const refusal = lexRefusal(e);
|
|
1770
|
+
if (refusal) return refusal;
|
|
1771
|
+
throw e;
|
|
1772
|
+
}
|
|
1773
|
+
},
|
|
1774
|
+
async lexExport(args) {
|
|
1775
|
+
const auth = await requireSession(sessionPath);
|
|
1776
|
+
if (!auth.ok) return auth;
|
|
1777
|
+
const apiOrigin = auth.data.origins.apiOrigin;
|
|
1778
|
+
const bearer = auth.data.session.accessToken;
|
|
1779
|
+
try {
|
|
1780
|
+
const prepared = await postLexExportStatement(apiOrigin, bearer, args.orgId, args.request);
|
|
1781
|
+
let receipt;
|
|
1782
|
+
if (prepared.statement) {
|
|
1783
|
+
const cer = await runPasskeyCeremony({
|
|
1784
|
+
origins: auth.data.origins,
|
|
1785
|
+
bearer,
|
|
1786
|
+
statement: prepared.statement,
|
|
1787
|
+
displayHint: "Export the organisation's agreement records",
|
|
1788
|
+
openBrowserFlag
|
|
1789
|
+
});
|
|
1790
|
+
receipt = await cer.wait();
|
|
1791
|
+
}
|
|
1792
|
+
return { ok: true, data: await postLexExport(apiOrigin, bearer, args.orgId, { request: args.request, ...receipt ? { receipt } : {} }) };
|
|
1793
|
+
} catch (e) {
|
|
1794
|
+
const refusal = lexRefusal(e);
|
|
1795
|
+
if (refusal) return refusal;
|
|
1796
|
+
throw e;
|
|
1797
|
+
}
|
|
1798
|
+
},
|
|
1799
|
+
async lexExports(args) {
|
|
1800
|
+
const auth = await requireSession(sessionPath);
|
|
1801
|
+
if (!auth.ok) return auth;
|
|
1802
|
+
try {
|
|
1803
|
+
return { ok: true, data: await getLexExports(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId) };
|
|
1804
|
+
} catch (e) {
|
|
1805
|
+
const refusal = lexRefusal(e);
|
|
1806
|
+
if (refusal) return refusal;
|
|
1807
|
+
throw e;
|
|
1808
|
+
}
|
|
1809
|
+
},
|
|
1810
|
+
async lexExportStatus(args) {
|
|
1811
|
+
const auth = await requireSession(sessionPath);
|
|
1812
|
+
if (!auth.ok) return auth;
|
|
1813
|
+
try {
|
|
1814
|
+
return { ok: true, data: await getLexExport(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.jobId) };
|
|
1815
|
+
} catch (e) {
|
|
1816
|
+
const refusal = lexRefusal(e);
|
|
1817
|
+
if (refusal) return refusal;
|
|
1818
|
+
throw e;
|
|
1819
|
+
}
|
|
1820
|
+
},
|
|
1821
|
+
async lexExportDownload(args) {
|
|
1822
|
+
if (!/^[0-9a-f]{32}$/.test(args.jobId)) return { ok: false, error: "job_id_invalid" };
|
|
1823
|
+
const auth = await requireSession(sessionPath);
|
|
1824
|
+
if (!auth.ok) return auth;
|
|
1825
|
+
const apiOrigin = auth.data.origins.apiOrigin;
|
|
1826
|
+
const bearer = auth.data.session.accessToken;
|
|
1827
|
+
try {
|
|
1828
|
+
const { job } = await getLexExport(apiOrigin, bearer, args.orgId, args.jobId);
|
|
1829
|
+
if (job.state !== "done" || typeof job.manifest_digest !== "string") {
|
|
1830
|
+
return { ok: false, error: `export_not_done \u2014 the export is ${String(job.state)}. Check again with lex-export-status.` };
|
|
1831
|
+
}
|
|
1832
|
+
const manifestBytes = await getLexExportFile(apiOrigin, bearer, args.orgId, args.jobId, "manifest.json");
|
|
1833
|
+
if (await bytesDigest(manifestBytes) !== job.manifest_digest) {
|
|
1834
|
+
return { ok: false, error: "export_manifest_mismatch \u2014 the manifest does not hash to the digest Clavis anchored. Nothing was kept." };
|
|
1835
|
+
}
|
|
1836
|
+
const manifest = JSON.parse(new TextDecoder().decode(manifestBytes));
|
|
1837
|
+
if (manifest?.kind !== "lex.package@1" || manifest.job_id !== args.jobId || !Array.isArray(manifest.files)) {
|
|
1838
|
+
return { ok: false, error: "invalid_export_manifest" };
|
|
1839
|
+
}
|
|
1840
|
+
const files = [];
|
|
1841
|
+
const seen = /* @__PURE__ */ new Set(["manifest.json", "anchor.json"]);
|
|
1842
|
+
await mkdir(args.dir, { recursive: true, mode: 448 });
|
|
1843
|
+
const staging = await mkdtemp(join(args.dir, ".clavis-export-"));
|
|
1844
|
+
const store = async (path2, bytes) => {
|
|
1845
|
+
await mkdir(dirname(join(staging, path2)), { recursive: true, mode: 448 });
|
|
1846
|
+
await writeFile(join(staging, path2), bytes, { flag: "wx", mode: 384 });
|
|
1847
|
+
files.push({ path: path2, bytes: bytes.byteLength });
|
|
1848
|
+
};
|
|
1849
|
+
try {
|
|
1850
|
+
await store("manifest.json", manifestBytes);
|
|
1851
|
+
for (const entry of manifest.files) {
|
|
1852
|
+
if (typeof entry?.path !== "string" || !LEX_EXPORT_PATH.test(entry.path) || seen.has(entry.path)) {
|
|
1853
|
+
return { ok: false, error: "invalid_export_manifest" };
|
|
1854
|
+
}
|
|
1855
|
+
seen.add(entry.path);
|
|
1856
|
+
const bytes = await getLexExportFile(apiOrigin, bearer, args.orgId, args.jobId, entry.path);
|
|
1857
|
+
if (bytes.byteLength !== entry.bytes || await bytesDigest(bytes) !== entry.sha256) {
|
|
1858
|
+
return { ok: false, error: `export_file_mismatch \u2014 ${entry.path} differs from the manifest.` };
|
|
1859
|
+
}
|
|
1860
|
+
await store(entry.path, bytes);
|
|
1861
|
+
}
|
|
1862
|
+
await store("anchor.json", await getLexExportFile(apiOrigin, bearer, args.orgId, args.jobId, "anchor.json"));
|
|
1863
|
+
const root = join(args.dir, args.jobId);
|
|
1864
|
+
await rename(staging, root);
|
|
1865
|
+
return { ok: true, data: { dir: root, manifest_digest: job.manifest_digest, files } };
|
|
1866
|
+
} finally {
|
|
1867
|
+
await rm(staging, { recursive: true, force: true });
|
|
1868
|
+
}
|
|
1869
|
+
} catch (e) {
|
|
1870
|
+
const refusal = lexRefusal(e);
|
|
1871
|
+
if (refusal) return refusal;
|
|
1872
|
+
throw e;
|
|
1873
|
+
}
|
|
1874
|
+
},
|
|
1875
|
+
async lexDecision(args) {
|
|
1876
|
+
if (!LEX_DECISION_ID.test(args.decisionId)) return { ok: false, error: "decision_id_invalid \u2014 pass the decision_id Clavis returned for the agreement." };
|
|
1877
|
+
const auth = await requireSession(sessionPath);
|
|
1878
|
+
if (!auth.ok) return auth;
|
|
1879
|
+
try {
|
|
1880
|
+
return { ok: true, data: await getLexDecision(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.decisionId) };
|
|
1881
|
+
} catch (e) {
|
|
1882
|
+
const refusal = lexRefusal(e);
|
|
1883
|
+
if (refusal) return refusal;
|
|
1884
|
+
throw e;
|
|
1885
|
+
}
|
|
1886
|
+
},
|
|
1887
|
+
async lexSubjectDecisions(args) {
|
|
1888
|
+
if (!LEX_SUBJECT.test(args.subject)) return { ok: false, error: "subject_invalid \u2014 pass the person's ID in your App (the sub you passed as allowedSub)." };
|
|
1889
|
+
const auth = await requireSession(sessionPath);
|
|
1890
|
+
if (!auth.ok) return auth;
|
|
1891
|
+
try {
|
|
1892
|
+
return { ok: true, data: await getLexSubjectDecisions(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.subject) };
|
|
1893
|
+
} catch (e) {
|
|
1894
|
+
const refusal = lexRefusal(e);
|
|
1895
|
+
if (refusal) return refusal;
|
|
1896
|
+
throw e;
|
|
1897
|
+
}
|
|
1898
|
+
},
|
|
1899
|
+
async lexSubjectErase(args) {
|
|
1900
|
+
if (!LEX_SUBJECT.test(args.subject)) return { ok: false, error: "subject_invalid \u2014 pass the person's ID in your App (the sub you passed as allowedSub)." };
|
|
1901
|
+
const auth = await requireSession(sessionPath);
|
|
1902
|
+
if (!auth.ok) return auth;
|
|
1903
|
+
const apiOrigin = auth.data.origins.apiOrigin;
|
|
1904
|
+
const bearer = auth.data.session.accessToken;
|
|
1905
|
+
try {
|
|
1906
|
+
const cer = await runPasskeyCeremony({
|
|
1907
|
+
origins: auth.data.origins,
|
|
1908
|
+
bearer,
|
|
1909
|
+
statement: orgLexSubjectEraseStatement({ org: args.orgId, subject: args.subject }),
|
|
1910
|
+
displayHint: "Erase one person's agreement records",
|
|
1911
|
+
openBrowserFlag
|
|
1912
|
+
});
|
|
1913
|
+
const proof = await cer.wait();
|
|
1914
|
+
return { ok: true, data: await postLexSubjectErase(apiOrigin, bearer, args.orgId, args.subject, proof) };
|
|
1915
|
+
} catch (e) {
|
|
1916
|
+
const refusal = lexRefusal(e);
|
|
1917
|
+
if (refusal) return refusal;
|
|
1918
|
+
throw e;
|
|
1919
|
+
}
|
|
1920
|
+
},
|
|
1635
1921
|
async emitEnv(args) {
|
|
1636
1922
|
const jwk = args.operatePrivateJwkJson?.trim() || await readOperatePrivateJwk(args.appId) || "";
|
|
1637
1923
|
if (!jwk) {
|
|
@@ -1821,7 +2107,8 @@ var TOOLS = [
|
|
|
1821
2107
|
org_id: { type: "string" },
|
|
1822
2108
|
host: { type: "string" },
|
|
1823
2109
|
display_name: { type: "string" },
|
|
1824
|
-
redirect_path: { type: "string" }
|
|
2110
|
+
redirect_path: { type: "string" },
|
|
2111
|
+
agreements: { type: "boolean", description: "Allow this App to request agreements." }
|
|
1825
2112
|
},
|
|
1826
2113
|
required: ["org_id", "host", "display_name"],
|
|
1827
2114
|
additionalProperties: false
|
|
@@ -1895,6 +2182,101 @@ var TOOLS = [
|
|
|
1895
2182
|
additionalProperties: false
|
|
1896
2183
|
}
|
|
1897
2184
|
},
|
|
2185
|
+
{
|
|
2186
|
+
name: "clavis_app_lex_document",
|
|
2187
|
+
description: "Have Clavis take a snapshot of the org's terms or privacy notice from the App's confirmed host or the org's domain. Put the sha256 it returns in the agreement profile's documents.",
|
|
2188
|
+
inputSchema: {
|
|
2189
|
+
type: "object",
|
|
2190
|
+
properties: { org_id: { type: "string" }, app_id: { type: "string" }, url: { type: "string" } },
|
|
2191
|
+
required: ["org_id", "app_id", "url"],
|
|
2192
|
+
additionalProperties: false
|
|
2193
|
+
}
|
|
2194
|
+
},
|
|
2195
|
+
{
|
|
2196
|
+
name: "clavis_app_lex_profile_set",
|
|
2197
|
+
description: "Set what Connect shows when the App asks a user for an agreement (version, service_name, documents, purposes, destinations, terminal_categories), or clear it with profile null. Needs the human's Passkey (returns needs_human: passkey while waiting).",
|
|
2198
|
+
inputSchema: {
|
|
2199
|
+
type: "object",
|
|
2200
|
+
properties: { org_id: { type: "string" }, app_id: { type: "string" }, profile: { type: ["object", "null"] } },
|
|
2201
|
+
required: ["org_id", "app_id", "profile"],
|
|
2202
|
+
additionalProperties: false
|
|
2203
|
+
}
|
|
2204
|
+
},
|
|
2205
|
+
{
|
|
2206
|
+
name: "clavis_lex_counts",
|
|
2207
|
+
description: "Count the org's agreement decisions a query matches (period from/to, app_id, use_case, outcome, pack_id, template, requirement, versions), by outcome, stop reason and pack.",
|
|
2208
|
+
inputSchema: {
|
|
2209
|
+
type: "object",
|
|
2210
|
+
properties: { org_id: { type: "string" }, query: { type: "object" } },
|
|
2211
|
+
required: ["org_id"],
|
|
2212
|
+
additionalProperties: false
|
|
2213
|
+
}
|
|
2214
|
+
},
|
|
2215
|
+
{
|
|
2216
|
+
name: "clavis_lex_export",
|
|
2217
|
+
description: "Start an export of the org's agreement records. request: { kind: decisions | subject, query, expiring_within_days?, records? }. Many people's records (decisions) need the human's Passkey; one person's (subject, with query.subject_ref) does not. One export runs at a time.",
|
|
2218
|
+
inputSchema: {
|
|
2219
|
+
type: "object",
|
|
2220
|
+
properties: { org_id: { type: "string" }, request: { type: "object" } },
|
|
2221
|
+
required: ["org_id", "request"],
|
|
2222
|
+
additionalProperties: false
|
|
2223
|
+
}
|
|
2224
|
+
},
|
|
2225
|
+
{
|
|
2226
|
+
name: "clavis_lex_exports",
|
|
2227
|
+
description: "List the org's exports of agreement records, newest first.",
|
|
2228
|
+
inputSchema: { type: "object", properties: { org_id: { type: "string" } }, required: ["org_id"], additionalProperties: false }
|
|
2229
|
+
},
|
|
2230
|
+
{
|
|
2231
|
+
name: "clavis_lex_export_status",
|
|
2232
|
+
description: "Read one export: its state, its files once done, and where its manifest stands on the org's ledger.",
|
|
2233
|
+
inputSchema: {
|
|
2234
|
+
type: "object",
|
|
2235
|
+
properties: { org_id: { type: "string" }, job_id: { type: "string" } },
|
|
2236
|
+
required: ["org_id", "job_id"],
|
|
2237
|
+
additionalProperties: false
|
|
2238
|
+
}
|
|
2239
|
+
},
|
|
2240
|
+
{
|
|
2241
|
+
name: "clavis_lex_export_download",
|
|
2242
|
+
description: "Fetch a finished export into dir/<job_id>/ (files at mode 0600: they hold people's records), checking each file against the manifest and the manifest against the digest anchored on the ledger.",
|
|
2243
|
+
inputSchema: {
|
|
2244
|
+
type: "object",
|
|
2245
|
+
properties: { org_id: { type: "string" }, job_id: { type: "string" }, dir: { type: "string" } },
|
|
2246
|
+
required: ["org_id", "job_id", "dir"],
|
|
2247
|
+
additionalProperties: false
|
|
2248
|
+
}
|
|
2249
|
+
},
|
|
2250
|
+
{
|
|
2251
|
+
name: "clavis_lex_decision",
|
|
2252
|
+
description: "Read one agreement decision by the decision_id the App received: its record, its ledger proof and where it stands now.",
|
|
2253
|
+
inputSchema: {
|
|
2254
|
+
type: "object",
|
|
2255
|
+
properties: { org_id: { type: "string" }, decision_id: { type: "string" } },
|
|
2256
|
+
required: ["org_id", "decision_id"],
|
|
2257
|
+
additionalProperties: false
|
|
2258
|
+
}
|
|
2259
|
+
},
|
|
2260
|
+
{
|
|
2261
|
+
name: "clavis_lex_subject_decisions",
|
|
2262
|
+
description: "List every agreement decision the Org holds for one person (subject is their ID in the Org's App), to answer that person's request.",
|
|
2263
|
+
inputSchema: {
|
|
2264
|
+
type: "object",
|
|
2265
|
+
properties: { org_id: { type: "string" }, subject: { type: "string" } },
|
|
2266
|
+
required: ["org_id", "subject"],
|
|
2267
|
+
additionalProperties: false
|
|
2268
|
+
}
|
|
2269
|
+
},
|
|
2270
|
+
{
|
|
2271
|
+
name: "clavis_lex_subject_erase",
|
|
2272
|
+
description: "Erase one person's agreement decisions now, as the Org's instruction for that person's erasure request. Needs the owner's or admin's Passkey, cannot be undone, and is refused while the records are under a hold. Run it only when the Org has decided to erase.",
|
|
2273
|
+
inputSchema: {
|
|
2274
|
+
type: "object",
|
|
2275
|
+
properties: { org_id: { type: "string" }, subject: { type: "string" } },
|
|
2276
|
+
required: ["org_id", "subject"],
|
|
2277
|
+
additionalProperties: false
|
|
2278
|
+
}
|
|
2279
|
+
},
|
|
1898
2280
|
{
|
|
1899
2281
|
name: "clavis_emit_app_env",
|
|
1900
2282
|
description: "Emit environment variables for @clavis.nexus/app after setup. Needs CLAVIS_TRUST_ROOT (the Clavis Master public JWK) in the environment.",
|
|
@@ -1959,6 +2341,7 @@ async function dispatch(client, name, args) {
|
|
|
1959
2341
|
orgId: String(args.org_id),
|
|
1960
2342
|
host: String(args.host),
|
|
1961
2343
|
displayName: String(args.display_name),
|
|
2344
|
+
intentTypes: args.agreements === true ? ["generic_sign", "agreement"] : void 0,
|
|
1962
2345
|
redirectPaths: args.redirect_path ? [String(args.redirect_path)] : void 0
|
|
1963
2346
|
});
|
|
1964
2347
|
case "clavis_app_host_plan":
|
|
@@ -1980,6 +2363,26 @@ async function dispatch(client, name, args) {
|
|
|
1980
2363
|
endUsers: String(args.end_users),
|
|
1981
2364
|
uses: args.uses
|
|
1982
2365
|
});
|
|
2366
|
+
case "clavis_app_lex_document":
|
|
2367
|
+
return client.appLexDocument({ orgId: String(args.org_id), appId: String(args.app_id), url: String(args.url) });
|
|
2368
|
+
case "clavis_app_lex_profile_set":
|
|
2369
|
+
return client.appLexProfileSet({ orgId: String(args.org_id), appId: String(args.app_id), profile: args.profile ?? null });
|
|
2370
|
+
case "clavis_lex_counts":
|
|
2371
|
+
return client.lexCounts({ orgId: String(args.org_id), query: args.query ?? {} });
|
|
2372
|
+
case "clavis_lex_export":
|
|
2373
|
+
return client.lexExport({ orgId: String(args.org_id), request: args.request });
|
|
2374
|
+
case "clavis_lex_exports":
|
|
2375
|
+
return client.lexExports({ orgId: String(args.org_id) });
|
|
2376
|
+
case "clavis_lex_export_status":
|
|
2377
|
+
return client.lexExportStatus({ orgId: String(args.org_id), jobId: String(args.job_id) });
|
|
2378
|
+
case "clavis_lex_export_download":
|
|
2379
|
+
return client.lexExportDownload({ orgId: String(args.org_id), jobId: String(args.job_id), dir: String(args.dir) });
|
|
2380
|
+
case "clavis_lex_decision":
|
|
2381
|
+
return client.lexDecision({ orgId: String(args.org_id), decisionId: String(args.decision_id) });
|
|
2382
|
+
case "clavis_lex_subject_decisions":
|
|
2383
|
+
return client.lexSubjectDecisions({ orgId: String(args.org_id), subject: String(args.subject) });
|
|
2384
|
+
case "clavis_lex_subject_erase":
|
|
2385
|
+
return client.lexSubjectErase({ orgId: String(args.org_id), subject: String(args.subject) });
|
|
1983
2386
|
case "clavis_emit_app_env":
|
|
1984
2387
|
return client.emitEnv({
|
|
1985
2388
|
appId: String(args.app_id)
|