@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/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFile } from 'child_process';
|
|
3
3
|
import { promisify } from 'util';
|
|
4
|
-
import { readFile,
|
|
5
|
-
import path, {
|
|
4
|
+
import { readFile, mkdir, mkdtemp, writeFile, rename, rm, chmod, unlink, lstat } from 'fs/promises';
|
|
5
|
+
import path, { join, dirname, resolve, relative, isAbsolute } from 'path';
|
|
6
6
|
import { homedir } from 'os';
|
|
7
7
|
import { generateKeyPair, exportJWK, jwtVerify, importJWK } from 'jose';
|
|
8
8
|
import { createInterface } from 'readline/promises';
|
|
@@ -188,6 +188,71 @@ async function checkTrustRoot(apiOrigin, trustRootJson) {
|
|
|
188
188
|
await createVerifier({ trustRoot: trustRootJson, apiOrigin }).trust();
|
|
189
189
|
return JSON.stringify(JSON.parse(trustRootJson));
|
|
190
190
|
}
|
|
191
|
+
async function postAppLexDocument(apiOrigin, bearer, orgId, appId, url) {
|
|
192
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/apps/${encodeURIComponent(appId)}/lex-documents`, {
|
|
193
|
+
method: "POST",
|
|
194
|
+
bearer,
|
|
195
|
+
body: { url }
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async function postAppLexProfileStatement(apiOrigin, bearer, orgId, appId, profile) {
|
|
199
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/apps/${encodeURIComponent(appId)}/lex-profile/statement`, {
|
|
200
|
+
method: "POST",
|
|
201
|
+
bearer,
|
|
202
|
+
body: { profile }
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
async function putAppLexProfile(apiOrigin, bearer, orgId, appId, args) {
|
|
206
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/apps/${encodeURIComponent(appId)}/lex-profile`, {
|
|
207
|
+
method: "PUT",
|
|
208
|
+
bearer,
|
|
209
|
+
body: { profile: args.profile, receipt: args.receipt }
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async function postLexDecisionCounts(apiOrigin, bearer, orgId, query) {
|
|
213
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/decisions/counts`, { method: "POST", bearer, body: { query } });
|
|
214
|
+
}
|
|
215
|
+
async function postLexExportStatement(apiOrigin, bearer, orgId, request) {
|
|
216
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/exports/statement`, { method: "POST", bearer, body: { request } });
|
|
217
|
+
}
|
|
218
|
+
async function postLexExport(apiOrigin, bearer, orgId, args) {
|
|
219
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/exports`, {
|
|
220
|
+
method: "POST",
|
|
221
|
+
bearer,
|
|
222
|
+
body: { request: args.request, ...args.receipt !== void 0 ? { receipt: args.receipt } : {} }
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
async function getLexExports(apiOrigin, bearer, orgId) {
|
|
226
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/exports`, { bearer });
|
|
227
|
+
}
|
|
228
|
+
async function getLexExport(apiOrigin, bearer, orgId, jobId) {
|
|
229
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/exports/${encodeURIComponent(jobId)}`, { bearer });
|
|
230
|
+
}
|
|
231
|
+
async function getLexDecision(apiOrigin, bearer, orgId, decisionId) {
|
|
232
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/decisions/${encodeURIComponent(decisionId)}`, { bearer });
|
|
233
|
+
}
|
|
234
|
+
async function getLexSubjectDecisions(apiOrigin, bearer, orgId, subject) {
|
|
235
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/subjects/${encodeURIComponent(subject)}/decisions`, { bearer });
|
|
236
|
+
}
|
|
237
|
+
async function postLexSubjectErase(apiOrigin, bearer, orgId, subject, receipt) {
|
|
238
|
+
return apiJson(apiOrigin, `/orgs/${encodeURIComponent(orgId)}/lex/subjects/${encodeURIComponent(subject)}/erase`, {
|
|
239
|
+
method: "POST",
|
|
240
|
+
bearer,
|
|
241
|
+
body: { receipt }
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
async function getLexExportFile(apiOrigin, bearer, orgId, jobId, path2) {
|
|
245
|
+
const res = await fetch(
|
|
246
|
+
`${apiOrigin.replace(/\/+$/, "")}/orgs/${encodeURIComponent(orgId)}/lex/exports/${encodeURIComponent(jobId)}/files/${path2.split("/").map(encodeURIComponent).join("/")}`,
|
|
247
|
+
{ redirect: "error", headers: { Authorization: `Bearer ${bearer}` } }
|
|
248
|
+
);
|
|
249
|
+
if (!res.ok) {
|
|
250
|
+
const body = await res.json().catch(() => null);
|
|
251
|
+
const code = typeof body?.error === "string" ? body.error : `HTTP_${res.status}`;
|
|
252
|
+
throw new SetupApiError(res.status, code, typeof body?.message === "string" ? body.message : code);
|
|
253
|
+
}
|
|
254
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
255
|
+
}
|
|
191
256
|
var SetupApiError;
|
|
192
257
|
var init_org_api = __esm({
|
|
193
258
|
"src/org-api.ts"() {
|
|
@@ -611,6 +676,9 @@ function orgAppRegionsStatement(input2) {
|
|
|
611
676
|
regions: input2.regions === null ? null : [...new Set(input2.regions)].sort()
|
|
612
677
|
};
|
|
613
678
|
}
|
|
679
|
+
function orgLexSubjectEraseStatement(input2) {
|
|
680
|
+
return { type: "org.lex.subject_erase@1", org: input2.org.trim(), subject: input2.subject.trim() };
|
|
681
|
+
}
|
|
614
682
|
function orgCardIncorporationStatement(input2) {
|
|
615
683
|
return {
|
|
616
684
|
type: "org.card.incorporation_set@1",
|
|
@@ -1222,10 +1290,32 @@ var init_status = __esm({
|
|
|
1222
1290
|
init_org_api();
|
|
1223
1291
|
}
|
|
1224
1292
|
});
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1293
|
+
async function bytesDigest(bytes) {
|
|
1294
|
+
return `sha256:${bytesToBase64Url(new Uint8Array(await crypto.subtle.digest("SHA-256", new Uint8Array(bytes))))}`;
|
|
1295
|
+
}
|
|
1296
|
+
function lexRefusal(e) {
|
|
1297
|
+
if (!(e instanceof SetupApiError)) return null;
|
|
1298
|
+
switch (e.code) {
|
|
1299
|
+
case "PROFILE_INVALID":
|
|
1300
|
+
return { ok: false, error: "profile_invalid \u2014 the agreement profile is incomplete (version, service_name, purposes, destinations and terminal_categories are required)." };
|
|
1301
|
+
case "DOCUMENT_NOT_SNAPSHOTTED":
|
|
1302
|
+
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." };
|
|
1303
|
+
case "EXPORT_RUNNING":
|
|
1304
|
+
return { ok: false, error: "export_running \u2014 another export of this organisation is running. Wait for it, then start again." };
|
|
1305
|
+
case "EXPORT_TOO_LARGE":
|
|
1306
|
+
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." };
|
|
1307
|
+
case "FORBIDDEN":
|
|
1308
|
+
return { ok: false, error: "forbidden \u2014 only an owner or admin of the Org can do this." };
|
|
1309
|
+
case "NOT_FOUND":
|
|
1310
|
+
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." };
|
|
1311
|
+
case "ORG_HOLD":
|
|
1312
|
+
return { ok: false, error: "org_hold \u2014 these records are preserved under a hold, so erasure waits until the hold ends. Nothing was erased." };
|
|
1313
|
+
default:
|
|
1314
|
+
return null;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
async function requireSession(sessionPath) {
|
|
1318
|
+
const stored = await loadSession(sessionPath);
|
|
1229
1319
|
if (!stored?.session?.accessToken) {
|
|
1230
1320
|
return {
|
|
1231
1321
|
ok: false,
|
|
@@ -1236,7 +1326,7 @@ async function requireSession(client) {
|
|
|
1236
1326
|
}
|
|
1237
1327
|
};
|
|
1238
1328
|
}
|
|
1239
|
-
return { ok: true, data: { session: stored.session, origins: stored.origins
|
|
1329
|
+
return { ok: true, data: { session: stored.session, origins: stored.origins } };
|
|
1240
1330
|
}
|
|
1241
1331
|
async function runPasskeyCeremony(args) {
|
|
1242
1332
|
const returnTo = setupCeremonyReturnTo(args.origins.developersOrigin);
|
|
@@ -1314,7 +1404,7 @@ function createSetupClient(options = {}) {
|
|
|
1314
1404
|
const checked = checkOrgCreationTerms(terms);
|
|
1315
1405
|
if (!checked.ok) return checked;
|
|
1316
1406
|
const { incorporation } = checked;
|
|
1317
|
-
const auth = await requireSession(
|
|
1407
|
+
const auth = await requireSession(sessionPath);
|
|
1318
1408
|
if (!auth.ok) return auth;
|
|
1319
1409
|
const apiOrigin = auth.data.origins.apiOrigin;
|
|
1320
1410
|
const closed = await getClosedIncorporations(apiOrigin).catch(() => []);
|
|
@@ -1368,7 +1458,7 @@ function createSetupClient(options = {}) {
|
|
|
1368
1458
|
};
|
|
1369
1459
|
},
|
|
1370
1460
|
async orgAnchorFinish(args) {
|
|
1371
|
-
const auth = await requireSession(
|
|
1461
|
+
const auth = await requireSession(sessionPath);
|
|
1372
1462
|
if (!auth.ok) return auth;
|
|
1373
1463
|
const payload = await pollCeremonyResult({
|
|
1374
1464
|
apiOrigin: auth.data.origins.apiOrigin,
|
|
@@ -1406,7 +1496,7 @@ function createSetupClient(options = {}) {
|
|
|
1406
1496
|
const checked = checkOrgCreationTerms(args);
|
|
1407
1497
|
if (!checked.ok) return checked;
|
|
1408
1498
|
const { incorporation } = checked;
|
|
1409
|
-
const auth = await requireSession(
|
|
1499
|
+
const auth = await requireSession(sessionPath);
|
|
1410
1500
|
if (!auth.ok) return auth;
|
|
1411
1501
|
try {
|
|
1412
1502
|
const out = await postVerifyAnchor(auth.data.origins.apiOrigin, auth.data.session.accessToken, {
|
|
@@ -1431,7 +1521,7 @@ function createSetupClient(options = {}) {
|
|
|
1431
1521
|
}
|
|
1432
1522
|
},
|
|
1433
1523
|
async policyBootstrap(orgId) {
|
|
1434
|
-
const auth = await requireSession(
|
|
1524
|
+
const auth = await requireSession(sessionPath);
|
|
1435
1525
|
if (!auth.ok) return auth;
|
|
1436
1526
|
const detail = await getOrg(auth.data.origins.apiOrigin, auth.data.session.accessToken, orgId);
|
|
1437
1527
|
try {
|
|
@@ -1463,7 +1553,7 @@ function createSetupClient(options = {}) {
|
|
|
1463
1553
|
const checked = checkOrgCreationTerms(args, INCORPORATION_TERMS_HUMAN);
|
|
1464
1554
|
if (!checked.ok) return checked;
|
|
1465
1555
|
const code = checked.incorporation;
|
|
1466
|
-
const auth = await requireSession(
|
|
1556
|
+
const auth = await requireSession(sessionPath);
|
|
1467
1557
|
if (!auth.ok) return auth;
|
|
1468
1558
|
const sub = auth.data.session.sub;
|
|
1469
1559
|
if (!sub) return { ok: false, error: "session_missing_sub \u2014 re-login" };
|
|
@@ -1501,7 +1591,7 @@ function createSetupClient(options = {}) {
|
|
|
1501
1591
|
async cardCheckout(orgId, opts = {}) {
|
|
1502
1592
|
const offer = opts.offer === "bundle" ? "bundle" : "meter";
|
|
1503
1593
|
const lang = checkoutLang(opts.lang);
|
|
1504
|
-
const auth = await requireSession(
|
|
1594
|
+
const auth = await requireSession(sessionPath);
|
|
1505
1595
|
if (!auth.ok) return auth;
|
|
1506
1596
|
const sub = auth.data.session.sub;
|
|
1507
1597
|
if (!sub) return { ok: false, error: "session_missing_sub \u2014 re-login" };
|
|
@@ -1584,7 +1674,7 @@ function createSetupClient(options = {}) {
|
|
|
1584
1674
|
};
|
|
1585
1675
|
},
|
|
1586
1676
|
async appRegister(args) {
|
|
1587
|
-
const auth = await requireSession(
|
|
1677
|
+
const auth = await requireSession(sessionPath);
|
|
1588
1678
|
if (!auth.ok) return auth;
|
|
1589
1679
|
const sub = auth.data.session.sub;
|
|
1590
1680
|
if (!sub) return { ok: false, error: "session_missing_sub \u2014 re-login" };
|
|
@@ -1629,7 +1719,7 @@ function createSetupClient(options = {}) {
|
|
|
1629
1719
|
};
|
|
1630
1720
|
},
|
|
1631
1721
|
async appHostPlan(orgId, appId) {
|
|
1632
|
-
const auth = await requireSession(
|
|
1722
|
+
const auth = await requireSession(sessionPath);
|
|
1633
1723
|
if (!auth.ok) return auth;
|
|
1634
1724
|
const ch = await getHostChallenge(auth.data.origins.apiOrigin, auth.data.session.accessToken, orgId, appId);
|
|
1635
1725
|
return {
|
|
@@ -1646,7 +1736,7 @@ function createSetupClient(options = {}) {
|
|
|
1646
1736
|
};
|
|
1647
1737
|
},
|
|
1648
1738
|
async appVerifyHost(args) {
|
|
1649
|
-
const auth = await requireSession(
|
|
1739
|
+
const auth = await requireSession(sessionPath);
|
|
1650
1740
|
if (!auth.ok) return auth;
|
|
1651
1741
|
const ch = await getHostChallenge(
|
|
1652
1742
|
auth.data.origins.apiOrigin,
|
|
@@ -1687,7 +1777,7 @@ function createSetupClient(options = {}) {
|
|
|
1687
1777
|
}
|
|
1688
1778
|
},
|
|
1689
1779
|
async declarationSet(args) {
|
|
1690
|
-
const auth = await requireSession(
|
|
1780
|
+
const auth = await requireSession(sessionPath);
|
|
1691
1781
|
if (!auth.ok) return auth;
|
|
1692
1782
|
const declaration = { endUsers: args.endUsers, uses: args.uses };
|
|
1693
1783
|
const cer = await runPasskeyCeremony({
|
|
@@ -1711,7 +1801,7 @@ function createSetupClient(options = {}) {
|
|
|
1711
1801
|
const read = readAppRegionsInput(args.regions);
|
|
1712
1802
|
if (!read.ok) return read;
|
|
1713
1803
|
const regions = read.regions;
|
|
1714
|
-
const auth = await requireSession(
|
|
1804
|
+
const auth = await requireSession(sessionPath);
|
|
1715
1805
|
if (!auth.ok) return auth;
|
|
1716
1806
|
const sub = auth.data.session.sub;
|
|
1717
1807
|
if (!sub) return { ok: false, error: "session_missing_sub \u2014 re-login" };
|
|
@@ -1744,6 +1834,197 @@ function createSetupClient(options = {}) {
|
|
|
1744
1834
|
throw e;
|
|
1745
1835
|
}
|
|
1746
1836
|
},
|
|
1837
|
+
async appLexDocument(args) {
|
|
1838
|
+
const auth = await requireSession(sessionPath);
|
|
1839
|
+
if (!auth.ok) return auth;
|
|
1840
|
+
try {
|
|
1841
|
+
return { ok: true, data: await postAppLexDocument(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.appId, args.url) };
|
|
1842
|
+
} catch (e) {
|
|
1843
|
+
const refusal = lexRefusal(e);
|
|
1844
|
+
if (refusal) return refusal;
|
|
1845
|
+
throw e;
|
|
1846
|
+
}
|
|
1847
|
+
},
|
|
1848
|
+
async appLexProfileSet(args) {
|
|
1849
|
+
const auth = await requireSession(sessionPath);
|
|
1850
|
+
if (!auth.ok) return auth;
|
|
1851
|
+
const apiOrigin = auth.data.origins.apiOrigin;
|
|
1852
|
+
const bearer = auth.data.session.accessToken;
|
|
1853
|
+
try {
|
|
1854
|
+
const prepared = await postAppLexProfileStatement(apiOrigin, bearer, args.orgId, args.appId, args.profile);
|
|
1855
|
+
const cer = await runPasskeyCeremony({
|
|
1856
|
+
origins: auth.data.origins,
|
|
1857
|
+
bearer,
|
|
1858
|
+
statement: prepared.statement,
|
|
1859
|
+
displayHint: args.profile === null ? "Clear the App's agreement profile" : "Set the App's agreement profile",
|
|
1860
|
+
openBrowserFlag
|
|
1861
|
+
});
|
|
1862
|
+
const proof = await cer.wait();
|
|
1863
|
+
return { ok: true, data: await putAppLexProfile(apiOrigin, bearer, args.orgId, args.appId, { profile: args.profile, receipt: proof }) };
|
|
1864
|
+
} catch (e) {
|
|
1865
|
+
const refusal = lexRefusal(e);
|
|
1866
|
+
if (refusal) return refusal;
|
|
1867
|
+
throw e;
|
|
1868
|
+
}
|
|
1869
|
+
},
|
|
1870
|
+
async lexCounts(args) {
|
|
1871
|
+
const auth = await requireSession(sessionPath);
|
|
1872
|
+
if (!auth.ok) return auth;
|
|
1873
|
+
try {
|
|
1874
|
+
return { ok: true, data: await postLexDecisionCounts(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.query ?? {}) };
|
|
1875
|
+
} catch (e) {
|
|
1876
|
+
const refusal = lexRefusal(e);
|
|
1877
|
+
if (refusal) return refusal;
|
|
1878
|
+
throw e;
|
|
1879
|
+
}
|
|
1880
|
+
},
|
|
1881
|
+
async lexExport(args) {
|
|
1882
|
+
const auth = await requireSession(sessionPath);
|
|
1883
|
+
if (!auth.ok) return auth;
|
|
1884
|
+
const apiOrigin = auth.data.origins.apiOrigin;
|
|
1885
|
+
const bearer = auth.data.session.accessToken;
|
|
1886
|
+
try {
|
|
1887
|
+
const prepared = await postLexExportStatement(apiOrigin, bearer, args.orgId, args.request);
|
|
1888
|
+
let receipt;
|
|
1889
|
+
if (prepared.statement) {
|
|
1890
|
+
const cer = await runPasskeyCeremony({
|
|
1891
|
+
origins: auth.data.origins,
|
|
1892
|
+
bearer,
|
|
1893
|
+
statement: prepared.statement,
|
|
1894
|
+
displayHint: "Export the organisation's agreement records",
|
|
1895
|
+
openBrowserFlag
|
|
1896
|
+
});
|
|
1897
|
+
receipt = await cer.wait();
|
|
1898
|
+
}
|
|
1899
|
+
return { ok: true, data: await postLexExport(apiOrigin, bearer, args.orgId, { request: args.request, ...receipt ? { receipt } : {} }) };
|
|
1900
|
+
} catch (e) {
|
|
1901
|
+
const refusal = lexRefusal(e);
|
|
1902
|
+
if (refusal) return refusal;
|
|
1903
|
+
throw e;
|
|
1904
|
+
}
|
|
1905
|
+
},
|
|
1906
|
+
async lexExports(args) {
|
|
1907
|
+
const auth = await requireSession(sessionPath);
|
|
1908
|
+
if (!auth.ok) return auth;
|
|
1909
|
+
try {
|
|
1910
|
+
return { ok: true, data: await getLexExports(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId) };
|
|
1911
|
+
} catch (e) {
|
|
1912
|
+
const refusal = lexRefusal(e);
|
|
1913
|
+
if (refusal) return refusal;
|
|
1914
|
+
throw e;
|
|
1915
|
+
}
|
|
1916
|
+
},
|
|
1917
|
+
async lexExportStatus(args) {
|
|
1918
|
+
const auth = await requireSession(sessionPath);
|
|
1919
|
+
if (!auth.ok) return auth;
|
|
1920
|
+
try {
|
|
1921
|
+
return { ok: true, data: await getLexExport(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.jobId) };
|
|
1922
|
+
} catch (e) {
|
|
1923
|
+
const refusal = lexRefusal(e);
|
|
1924
|
+
if (refusal) return refusal;
|
|
1925
|
+
throw e;
|
|
1926
|
+
}
|
|
1927
|
+
},
|
|
1928
|
+
async lexExportDownload(args) {
|
|
1929
|
+
if (!/^[0-9a-f]{32}$/.test(args.jobId)) return { ok: false, error: "job_id_invalid" };
|
|
1930
|
+
const auth = await requireSession(sessionPath);
|
|
1931
|
+
if (!auth.ok) return auth;
|
|
1932
|
+
const apiOrigin = auth.data.origins.apiOrigin;
|
|
1933
|
+
const bearer = auth.data.session.accessToken;
|
|
1934
|
+
try {
|
|
1935
|
+
const { job } = await getLexExport(apiOrigin, bearer, args.orgId, args.jobId);
|
|
1936
|
+
if (job.state !== "done" || typeof job.manifest_digest !== "string") {
|
|
1937
|
+
return { ok: false, error: `export_not_done \u2014 the export is ${String(job.state)}. Check again with lex-export-status.` };
|
|
1938
|
+
}
|
|
1939
|
+
const manifestBytes = await getLexExportFile(apiOrigin, bearer, args.orgId, args.jobId, "manifest.json");
|
|
1940
|
+
if (await bytesDigest(manifestBytes) !== job.manifest_digest) {
|
|
1941
|
+
return { ok: false, error: "export_manifest_mismatch \u2014 the manifest does not hash to the digest Clavis anchored. Nothing was kept." };
|
|
1942
|
+
}
|
|
1943
|
+
const manifest = JSON.parse(new TextDecoder().decode(manifestBytes));
|
|
1944
|
+
if (manifest?.kind !== "lex.package@1" || manifest.job_id !== args.jobId || !Array.isArray(manifest.files)) {
|
|
1945
|
+
return { ok: false, error: "invalid_export_manifest" };
|
|
1946
|
+
}
|
|
1947
|
+
const files = [];
|
|
1948
|
+
const seen = /* @__PURE__ */ new Set(["manifest.json", "anchor.json"]);
|
|
1949
|
+
await mkdir(args.dir, { recursive: true, mode: 448 });
|
|
1950
|
+
const staging = await mkdtemp(join(args.dir, ".clavis-export-"));
|
|
1951
|
+
const store = async (path2, bytes) => {
|
|
1952
|
+
await mkdir(dirname(join(staging, path2)), { recursive: true, mode: 448 });
|
|
1953
|
+
await writeFile(join(staging, path2), bytes, { flag: "wx", mode: 384 });
|
|
1954
|
+
files.push({ path: path2, bytes: bytes.byteLength });
|
|
1955
|
+
};
|
|
1956
|
+
try {
|
|
1957
|
+
await store("manifest.json", manifestBytes);
|
|
1958
|
+
for (const entry of manifest.files) {
|
|
1959
|
+
if (typeof entry?.path !== "string" || !LEX_EXPORT_PATH.test(entry.path) || seen.has(entry.path)) {
|
|
1960
|
+
return { ok: false, error: "invalid_export_manifest" };
|
|
1961
|
+
}
|
|
1962
|
+
seen.add(entry.path);
|
|
1963
|
+
const bytes = await getLexExportFile(apiOrigin, bearer, args.orgId, args.jobId, entry.path);
|
|
1964
|
+
if (bytes.byteLength !== entry.bytes || await bytesDigest(bytes) !== entry.sha256) {
|
|
1965
|
+
return { ok: false, error: `export_file_mismatch \u2014 ${entry.path} differs from the manifest.` };
|
|
1966
|
+
}
|
|
1967
|
+
await store(entry.path, bytes);
|
|
1968
|
+
}
|
|
1969
|
+
await store("anchor.json", await getLexExportFile(apiOrigin, bearer, args.orgId, args.jobId, "anchor.json"));
|
|
1970
|
+
const root = join(args.dir, args.jobId);
|
|
1971
|
+
await rename(staging, root);
|
|
1972
|
+
return { ok: true, data: { dir: root, manifest_digest: job.manifest_digest, files } };
|
|
1973
|
+
} finally {
|
|
1974
|
+
await rm(staging, { recursive: true, force: true });
|
|
1975
|
+
}
|
|
1976
|
+
} catch (e) {
|
|
1977
|
+
const refusal = lexRefusal(e);
|
|
1978
|
+
if (refusal) return refusal;
|
|
1979
|
+
throw e;
|
|
1980
|
+
}
|
|
1981
|
+
},
|
|
1982
|
+
async lexDecision(args) {
|
|
1983
|
+
if (!LEX_DECISION_ID.test(args.decisionId)) return { ok: false, error: "decision_id_invalid \u2014 pass the decision_id Clavis returned for the agreement." };
|
|
1984
|
+
const auth = await requireSession(sessionPath);
|
|
1985
|
+
if (!auth.ok) return auth;
|
|
1986
|
+
try {
|
|
1987
|
+
return { ok: true, data: await getLexDecision(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.decisionId) };
|
|
1988
|
+
} catch (e) {
|
|
1989
|
+
const refusal = lexRefusal(e);
|
|
1990
|
+
if (refusal) return refusal;
|
|
1991
|
+
throw e;
|
|
1992
|
+
}
|
|
1993
|
+
},
|
|
1994
|
+
async lexSubjectDecisions(args) {
|
|
1995
|
+
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)." };
|
|
1996
|
+
const auth = await requireSession(sessionPath);
|
|
1997
|
+
if (!auth.ok) return auth;
|
|
1998
|
+
try {
|
|
1999
|
+
return { ok: true, data: await getLexSubjectDecisions(auth.data.origins.apiOrigin, auth.data.session.accessToken, args.orgId, args.subject) };
|
|
2000
|
+
} catch (e) {
|
|
2001
|
+
const refusal = lexRefusal(e);
|
|
2002
|
+
if (refusal) return refusal;
|
|
2003
|
+
throw e;
|
|
2004
|
+
}
|
|
2005
|
+
},
|
|
2006
|
+
async lexSubjectErase(args) {
|
|
2007
|
+
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)." };
|
|
2008
|
+
const auth = await requireSession(sessionPath);
|
|
2009
|
+
if (!auth.ok) return auth;
|
|
2010
|
+
const apiOrigin = auth.data.origins.apiOrigin;
|
|
2011
|
+
const bearer = auth.data.session.accessToken;
|
|
2012
|
+
try {
|
|
2013
|
+
const cer = await runPasskeyCeremony({
|
|
2014
|
+
origins: auth.data.origins,
|
|
2015
|
+
bearer,
|
|
2016
|
+
statement: orgLexSubjectEraseStatement({ org: args.orgId, subject: args.subject }),
|
|
2017
|
+
displayHint: "Erase one person's agreement records",
|
|
2018
|
+
openBrowserFlag
|
|
2019
|
+
});
|
|
2020
|
+
const proof = await cer.wait();
|
|
2021
|
+
return { ok: true, data: await postLexSubjectErase(apiOrigin, bearer, args.orgId, args.subject, proof) };
|
|
2022
|
+
} catch (e) {
|
|
2023
|
+
const refusal = lexRefusal(e);
|
|
2024
|
+
if (refusal) return refusal;
|
|
2025
|
+
throw e;
|
|
2026
|
+
}
|
|
2027
|
+
},
|
|
1747
2028
|
async emitEnv(args) {
|
|
1748
2029
|
const jwk = args.operatePrivateJwkJson?.trim() || await readOperatePrivateJwk(args.appId) || "";
|
|
1749
2030
|
if (!jwk) {
|
|
@@ -1766,6 +2047,7 @@ function createSetupClient(options = {}) {
|
|
|
1766
2047
|
};
|
|
1767
2048
|
return client;
|
|
1768
2049
|
}
|
|
2050
|
+
var LEX_SUBJECT, LEX_DECISION_ID, LEX_EXPORT_PATH;
|
|
1769
2051
|
var init_setup_client = __esm({
|
|
1770
2052
|
"src/setup-client.ts"() {
|
|
1771
2053
|
init_app_regions();
|
|
@@ -1775,6 +2057,7 @@ var init_setup_client = __esm({
|
|
|
1775
2057
|
init_statements();
|
|
1776
2058
|
init_ceremony();
|
|
1777
2059
|
init_emit_env();
|
|
2060
|
+
init_base64url();
|
|
1778
2061
|
init_operate_key_store();
|
|
1779
2062
|
init_keys();
|
|
1780
2063
|
init_login();
|
|
@@ -1782,6 +2065,9 @@ var init_setup_client = __esm({
|
|
|
1782
2065
|
init_org_creation();
|
|
1783
2066
|
init_session_store();
|
|
1784
2067
|
init_status();
|
|
2068
|
+
LEX_SUBJECT = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
2069
|
+
LEX_DECISION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
2070
|
+
LEX_EXPORT_PATH = /^(manifest\.json|anchor\.json|items\/\d{5}\.jsonl|decisions\/[A-Za-z0-9._:-]{1,128}\.json)$/;
|
|
1785
2071
|
}
|
|
1786
2072
|
});
|
|
1787
2073
|
|
|
@@ -1875,6 +2161,7 @@ async function dispatch(client, name, args) {
|
|
|
1875
2161
|
orgId: String(args.org_id),
|
|
1876
2162
|
host: String(args.host),
|
|
1877
2163
|
displayName: String(args.display_name),
|
|
2164
|
+
intentTypes: args.agreements === true ? ["generic_sign", "agreement"] : void 0,
|
|
1878
2165
|
redirectPaths: args.redirect_path ? [String(args.redirect_path)] : void 0
|
|
1879
2166
|
});
|
|
1880
2167
|
case "clavis_app_host_plan":
|
|
@@ -1896,6 +2183,26 @@ async function dispatch(client, name, args) {
|
|
|
1896
2183
|
endUsers: String(args.end_users),
|
|
1897
2184
|
uses: args.uses
|
|
1898
2185
|
});
|
|
2186
|
+
case "clavis_app_lex_document":
|
|
2187
|
+
return client.appLexDocument({ orgId: String(args.org_id), appId: String(args.app_id), url: String(args.url) });
|
|
2188
|
+
case "clavis_app_lex_profile_set":
|
|
2189
|
+
return client.appLexProfileSet({ orgId: String(args.org_id), appId: String(args.app_id), profile: args.profile ?? null });
|
|
2190
|
+
case "clavis_lex_counts":
|
|
2191
|
+
return client.lexCounts({ orgId: String(args.org_id), query: args.query ?? {} });
|
|
2192
|
+
case "clavis_lex_export":
|
|
2193
|
+
return client.lexExport({ orgId: String(args.org_id), request: args.request });
|
|
2194
|
+
case "clavis_lex_exports":
|
|
2195
|
+
return client.lexExports({ orgId: String(args.org_id) });
|
|
2196
|
+
case "clavis_lex_export_status":
|
|
2197
|
+
return client.lexExportStatus({ orgId: String(args.org_id), jobId: String(args.job_id) });
|
|
2198
|
+
case "clavis_lex_export_download":
|
|
2199
|
+
return client.lexExportDownload({ orgId: String(args.org_id), jobId: String(args.job_id), dir: String(args.dir) });
|
|
2200
|
+
case "clavis_lex_decision":
|
|
2201
|
+
return client.lexDecision({ orgId: String(args.org_id), decisionId: String(args.decision_id) });
|
|
2202
|
+
case "clavis_lex_subject_decisions":
|
|
2203
|
+
return client.lexSubjectDecisions({ orgId: String(args.org_id), subject: String(args.subject) });
|
|
2204
|
+
case "clavis_lex_subject_erase":
|
|
2205
|
+
return client.lexSubjectErase({ orgId: String(args.org_id), subject: String(args.subject) });
|
|
1899
2206
|
case "clavis_emit_app_env":
|
|
1900
2207
|
return client.emitEnv({
|
|
1901
2208
|
appId: String(args.app_id)
|
|
@@ -2076,7 +2383,8 @@ var init_mcp_server = __esm({
|
|
|
2076
2383
|
org_id: { type: "string" },
|
|
2077
2384
|
host: { type: "string" },
|
|
2078
2385
|
display_name: { type: "string" },
|
|
2079
|
-
redirect_path: { type: "string" }
|
|
2386
|
+
redirect_path: { type: "string" },
|
|
2387
|
+
agreements: { type: "boolean", description: "Allow this App to request agreements." }
|
|
2080
2388
|
},
|
|
2081
2389
|
required: ["org_id", "host", "display_name"],
|
|
2082
2390
|
additionalProperties: false
|
|
@@ -2150,6 +2458,101 @@ var init_mcp_server = __esm({
|
|
|
2150
2458
|
additionalProperties: false
|
|
2151
2459
|
}
|
|
2152
2460
|
},
|
|
2461
|
+
{
|
|
2462
|
+
name: "clavis_app_lex_document",
|
|
2463
|
+
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.",
|
|
2464
|
+
inputSchema: {
|
|
2465
|
+
type: "object",
|
|
2466
|
+
properties: { org_id: { type: "string" }, app_id: { type: "string" }, url: { type: "string" } },
|
|
2467
|
+
required: ["org_id", "app_id", "url"],
|
|
2468
|
+
additionalProperties: false
|
|
2469
|
+
}
|
|
2470
|
+
},
|
|
2471
|
+
{
|
|
2472
|
+
name: "clavis_app_lex_profile_set",
|
|
2473
|
+
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).",
|
|
2474
|
+
inputSchema: {
|
|
2475
|
+
type: "object",
|
|
2476
|
+
properties: { org_id: { type: "string" }, app_id: { type: "string" }, profile: { type: ["object", "null"] } },
|
|
2477
|
+
required: ["org_id", "app_id", "profile"],
|
|
2478
|
+
additionalProperties: false
|
|
2479
|
+
}
|
|
2480
|
+
},
|
|
2481
|
+
{
|
|
2482
|
+
name: "clavis_lex_counts",
|
|
2483
|
+
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.",
|
|
2484
|
+
inputSchema: {
|
|
2485
|
+
type: "object",
|
|
2486
|
+
properties: { org_id: { type: "string" }, query: { type: "object" } },
|
|
2487
|
+
required: ["org_id"],
|
|
2488
|
+
additionalProperties: false
|
|
2489
|
+
}
|
|
2490
|
+
},
|
|
2491
|
+
{
|
|
2492
|
+
name: "clavis_lex_export",
|
|
2493
|
+
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.",
|
|
2494
|
+
inputSchema: {
|
|
2495
|
+
type: "object",
|
|
2496
|
+
properties: { org_id: { type: "string" }, request: { type: "object" } },
|
|
2497
|
+
required: ["org_id", "request"],
|
|
2498
|
+
additionalProperties: false
|
|
2499
|
+
}
|
|
2500
|
+
},
|
|
2501
|
+
{
|
|
2502
|
+
name: "clavis_lex_exports",
|
|
2503
|
+
description: "List the org's exports of agreement records, newest first.",
|
|
2504
|
+
inputSchema: { type: "object", properties: { org_id: { type: "string" } }, required: ["org_id"], additionalProperties: false }
|
|
2505
|
+
},
|
|
2506
|
+
{
|
|
2507
|
+
name: "clavis_lex_export_status",
|
|
2508
|
+
description: "Read one export: its state, its files once done, and where its manifest stands on the org's ledger.",
|
|
2509
|
+
inputSchema: {
|
|
2510
|
+
type: "object",
|
|
2511
|
+
properties: { org_id: { type: "string" }, job_id: { type: "string" } },
|
|
2512
|
+
required: ["org_id", "job_id"],
|
|
2513
|
+
additionalProperties: false
|
|
2514
|
+
}
|
|
2515
|
+
},
|
|
2516
|
+
{
|
|
2517
|
+
name: "clavis_lex_export_download",
|
|
2518
|
+
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.",
|
|
2519
|
+
inputSchema: {
|
|
2520
|
+
type: "object",
|
|
2521
|
+
properties: { org_id: { type: "string" }, job_id: { type: "string" }, dir: { type: "string" } },
|
|
2522
|
+
required: ["org_id", "job_id", "dir"],
|
|
2523
|
+
additionalProperties: false
|
|
2524
|
+
}
|
|
2525
|
+
},
|
|
2526
|
+
{
|
|
2527
|
+
name: "clavis_lex_decision",
|
|
2528
|
+
description: "Read one agreement decision by the decision_id the App received: its record, its ledger proof and where it stands now.",
|
|
2529
|
+
inputSchema: {
|
|
2530
|
+
type: "object",
|
|
2531
|
+
properties: { org_id: { type: "string" }, decision_id: { type: "string" } },
|
|
2532
|
+
required: ["org_id", "decision_id"],
|
|
2533
|
+
additionalProperties: false
|
|
2534
|
+
}
|
|
2535
|
+
},
|
|
2536
|
+
{
|
|
2537
|
+
name: "clavis_lex_subject_decisions",
|
|
2538
|
+
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.",
|
|
2539
|
+
inputSchema: {
|
|
2540
|
+
type: "object",
|
|
2541
|
+
properties: { org_id: { type: "string" }, subject: { type: "string" } },
|
|
2542
|
+
required: ["org_id", "subject"],
|
|
2543
|
+
additionalProperties: false
|
|
2544
|
+
}
|
|
2545
|
+
},
|
|
2546
|
+
{
|
|
2547
|
+
name: "clavis_lex_subject_erase",
|
|
2548
|
+
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.",
|
|
2549
|
+
inputSchema: {
|
|
2550
|
+
type: "object",
|
|
2551
|
+
properties: { org_id: { type: "string" }, subject: { type: "string" } },
|
|
2552
|
+
required: ["org_id", "subject"],
|
|
2553
|
+
additionalProperties: false
|
|
2554
|
+
}
|
|
2555
|
+
},
|
|
2153
2556
|
{
|
|
2154
2557
|
name: "clavis_emit_app_env",
|
|
2155
2558
|
description: "Emit environment variables for @clavis.nexus/app after setup. Needs CLAVIS_TRUST_ROOT (the Clavis Master public JWK) in the environment.",
|
|
@@ -2240,11 +2643,21 @@ function usage() {
|
|
|
2240
2643
|
clavis policy-bootstrap <orgId>
|
|
2241
2644
|
clavis incorporation-set <orgId> --incorporation CODE --accept-customer-terms
|
|
2242
2645
|
clavis card-checkout <orgId> --consent-billing-data [--offer meter|bundle] [--lang en|ja]
|
|
2243
|
-
clavis app-register --org O --host H --name N [--redirect /done]
|
|
2646
|
+
clavis app-register --org O --host H --name N [--redirect /done] [--agreements]
|
|
2244
2647
|
clavis app-host-plan <orgId> <appId>
|
|
2245
2648
|
clavis app-verify-host <orgId> <appId>
|
|
2246
2649
|
clavis app-regions-set <orgId> <appId> (--regions JP,US | --all)
|
|
2247
2650
|
clavis declaration-set --org O --app A --end-users TEXT --use signature=OP
|
|
2651
|
+
clavis app-lex-document <orgId> <appId> --url U
|
|
2652
|
+
clavis app-lex-profile-set <orgId> <appId> (--file profile.json | --clear)
|
|
2653
|
+
clavis lex-counts <orgId> [--query-file query.json]
|
|
2654
|
+
clavis lex-export <orgId> --request-file request.json
|
|
2655
|
+
clavis lex-exports <orgId>
|
|
2656
|
+
clavis lex-export-status <orgId> <jobId>
|
|
2657
|
+
clavis lex-export-download <orgId> <jobId> --dir D
|
|
2658
|
+
clavis lex-decision <orgId> <decisionId>
|
|
2659
|
+
clavis lex-subject-decisions <orgId> <subject>
|
|
2660
|
+
clavis lex-subject-erase <orgId> <subject>
|
|
2248
2661
|
clavis emit-env --app A
|
|
2249
2662
|
|
|
2250
2663
|
login: opens developers /setup/login, then paste the JSON from the page (or pass --bridge-json-file).
|
|
@@ -2256,12 +2669,23 @@ incorporation-set declares the place again after the Customer Terms change (stat
|
|
|
2256
2669
|
card-checkout needs --consent-billing-data: the customer's consent to provide billing data to the payment provider. Run it once without the flag to get the statement to show them.
|
|
2257
2670
|
Secrets stay in ~/.config/clavis/apps/<appId>/ (mode 0600). Command output includes the file path. emit-env needs CLAVIS_TRUST_ROOT set to the Clavis Master public JWK (docs.clavis.nexus); it checks that the trust documents chain to it before writing CLAVIS_TRUST_ROOT for @clavis.nexus/app.
|
|
2258
2671
|
app-regions-set chooses where the App accepts new connections from: JP, US, GB, EEA (comma-separated). --all accepts every region Clavis accepts. People already connected keep using the App.
|
|
2672
|
+
app-lex-document has 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 profile's documents. app-lex-profile-set sets what Connect shows when the App asks for an agreement, with Passkey (--clear removes it).
|
|
2673
|
+
lex-export starts an export of agreement records: request.json is { "kind": "decisions" | "subject", "query": {...}, "expiring_within_days"?: N, "records"?: true }. Many people's records (decisions) need Passkey; one person's (subject, with query.subject_ref) does not. lex-export-download writes the files at mode 0600 under D/<jobId>/ after checking each against the manifest and the manifest against the digest anchored on the ledger.
|
|
2674
|
+
lex-decision reads one agreement decision by the decision_id your App received. lex-subject-decisions lists every decision for one person (subject is their ID in your App). lex-subject-erase erases that person's decisions now, with Passkey; it cannot be undone and is held while the records are under a hold.
|
|
2259
2675
|
declaration-set replaces the App's current declaration. Pass every use to keep. status reports the signature card and the place of incorporation. Ledger subscription is on developers.
|
|
2260
2676
|
|
|
2261
2677
|
Env: CLAVIS_API_ORIGIN CLAVIS_ID_ORIGIN CLAVIS_DEVELOPERS_ORIGIN CLAVIS_SESSION_PATH
|
|
2262
2678
|
`);
|
|
2263
2679
|
process.exit(2);
|
|
2264
2680
|
}
|
|
2681
|
+
async function readJsonFile(path2) {
|
|
2682
|
+
try {
|
|
2683
|
+
return JSON.parse(await readFile(path2, "utf8"));
|
|
2684
|
+
} catch (e) {
|
|
2685
|
+
console.error(`could not read JSON from ${path2}: ${e instanceof Error ? e.message : String(e)}`);
|
|
2686
|
+
process.exit(2);
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2265
2689
|
function requireFlag(args, name) {
|
|
2266
2690
|
const v = flag(args, name);
|
|
2267
2691
|
if (!v) {
|
|
@@ -2290,8 +2714,8 @@ async function main() {
|
|
|
2290
2714
|
const fromFile = flag(rest, "--bridge-json-file");
|
|
2291
2715
|
let bridgeJson;
|
|
2292
2716
|
if (fromFile) {
|
|
2293
|
-
const { readFile:
|
|
2294
|
-
bridgeJson = await
|
|
2717
|
+
const { readFile: readFile5 } = await import('fs/promises');
|
|
2718
|
+
bridgeJson = await readFile5(fromFile, "utf8");
|
|
2295
2719
|
}
|
|
2296
2720
|
printJson(await client.login(bridgeJson ? { bridgeJson } : void 0));
|
|
2297
2721
|
return;
|
|
@@ -2359,6 +2783,7 @@ async function main() {
|
|
|
2359
2783
|
orgId: requireFlag(rest, "--org"),
|
|
2360
2784
|
host: requireFlag(rest, "--host"),
|
|
2361
2785
|
displayName: requireFlag(rest, "--name"),
|
|
2786
|
+
intentTypes: rest.includes("--agreements") ? ["generic_sign", "agreement"] : void 0,
|
|
2362
2787
|
redirectPaths: flag(rest, "--redirect") ? [flag(rest, "--redirect")] : void 0
|
|
2363
2788
|
})
|
|
2364
2789
|
);
|
|
@@ -2401,6 +2826,73 @@ async function main() {
|
|
|
2401
2826
|
);
|
|
2402
2827
|
return;
|
|
2403
2828
|
}
|
|
2829
|
+
case "app-lex-document": {
|
|
2830
|
+
const [orgId, appId] = positionals(rest, ["--url"]);
|
|
2831
|
+
if (!orgId || !appId) usage();
|
|
2832
|
+
printJson(await client.appLexDocument({ orgId, appId, url: requireFlag(rest, "--url") }));
|
|
2833
|
+
return;
|
|
2834
|
+
}
|
|
2835
|
+
case "app-lex-profile-set": {
|
|
2836
|
+
const [orgId, appId] = positionals(rest, ["--file"]);
|
|
2837
|
+
if (!orgId || !appId) usage();
|
|
2838
|
+
const clear = rest.includes("--clear");
|
|
2839
|
+
const file = flag(rest, "--file");
|
|
2840
|
+
if (clear === Boolean(file)) {
|
|
2841
|
+
console.error("pass either --file or --clear");
|
|
2842
|
+
usage();
|
|
2843
|
+
}
|
|
2844
|
+
printJson(await client.appLexProfileSet({ orgId, appId, profile: clear ? null : await readJsonFile(file) }));
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
case "lex-counts": {
|
|
2848
|
+
const [orgId] = positionals(rest, ["--query-file"]);
|
|
2849
|
+
if (!orgId) usage();
|
|
2850
|
+
const file = flag(rest, "--query-file");
|
|
2851
|
+
printJson(await client.lexCounts({ orgId, query: file ? await readJsonFile(file) : {} }));
|
|
2852
|
+
return;
|
|
2853
|
+
}
|
|
2854
|
+
case "lex-export": {
|
|
2855
|
+
const [orgId] = positionals(rest, ["--request-file"]);
|
|
2856
|
+
if (!orgId) usage();
|
|
2857
|
+
printJson(await client.lexExport({ orgId, request: await readJsonFile(requireFlag(rest, "--request-file")) }));
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2860
|
+
case "lex-exports": {
|
|
2861
|
+
const [orgId] = rest;
|
|
2862
|
+
if (!orgId) usage();
|
|
2863
|
+
printJson(await client.lexExports({ orgId }));
|
|
2864
|
+
return;
|
|
2865
|
+
}
|
|
2866
|
+
case "lex-export-status": {
|
|
2867
|
+
const [orgId, jobId] = rest;
|
|
2868
|
+
if (!orgId || !jobId) usage();
|
|
2869
|
+
printJson(await client.lexExportStatus({ orgId, jobId }));
|
|
2870
|
+
return;
|
|
2871
|
+
}
|
|
2872
|
+
case "lex-export-download": {
|
|
2873
|
+
const [orgId, jobId] = positionals(rest, ["--dir"]);
|
|
2874
|
+
if (!orgId || !jobId) usage();
|
|
2875
|
+
printJson(await client.lexExportDownload({ orgId, jobId, dir: requireFlag(rest, "--dir") }));
|
|
2876
|
+
return;
|
|
2877
|
+
}
|
|
2878
|
+
case "lex-decision": {
|
|
2879
|
+
const [orgId, decisionId] = rest;
|
|
2880
|
+
if (!orgId || !decisionId) usage();
|
|
2881
|
+
printJson(await client.lexDecision({ orgId, decisionId }));
|
|
2882
|
+
return;
|
|
2883
|
+
}
|
|
2884
|
+
case "lex-subject-decisions": {
|
|
2885
|
+
const [orgId, subject] = rest;
|
|
2886
|
+
if (!orgId || !subject) usage();
|
|
2887
|
+
printJson(await client.lexSubjectDecisions({ orgId, subject }));
|
|
2888
|
+
return;
|
|
2889
|
+
}
|
|
2890
|
+
case "lex-subject-erase": {
|
|
2891
|
+
const [orgId, subject] = rest;
|
|
2892
|
+
if (!orgId || !subject) usage();
|
|
2893
|
+
printJson(await client.lexSubjectErase({ orgId, subject }));
|
|
2894
|
+
return;
|
|
2895
|
+
}
|
|
2404
2896
|
case "emit-env":
|
|
2405
2897
|
if (flag(rest, "--operate-jwk")) {
|
|
2406
2898
|
console.error(
|