@duct-sdk/sdk 0.5.12 → 0.6.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +385 -336
  2. package/README.md +418 -264
  3. package/TOKEN_SPEC.md +243 -237
  4. package/dist/cli/add.d.ts +7 -0
  5. package/dist/cli/add.js +152 -0
  6. package/dist/cli/agent-prompt.d.ts +3 -0
  7. package/dist/cli/agent-prompt.js +39 -0
  8. package/dist/cli/api-sources.d.ts +26 -0
  9. package/dist/cli/api-sources.js +222 -0
  10. package/dist/cli/cloud.d.ts +133 -0
  11. package/dist/cli/cloud.js +298 -0
  12. package/dist/cli/config-loader.d.ts +14 -0
  13. package/dist/cli/config-loader.js +56 -7
  14. package/dist/cli/device-login.d.ts +17 -0
  15. package/dist/cli/device-login.js +75 -0
  16. package/dist/cli/drift.js +6 -6
  17. package/dist/cli/generators/any-stack.d.ts +3 -0
  18. package/dist/cli/generators/any-stack.js +97 -0
  19. package/dist/cli/generators/config.js +3 -2
  20. package/dist/cli/generators/receiver.js +7 -7
  21. package/dist/cli/generators/shell.js +12 -12
  22. package/dist/cli/generators/token-route.js +245 -245
  23. package/dist/cli/index.js +402 -611
  24. package/dist/cli/mcp-core.d.ts +42 -0
  25. package/dist/cli/mcp-core.js +161 -0
  26. package/dist/cli/mcp-setup.d.ts +4 -0
  27. package/dist/cli/mcp-setup.js +360 -0
  28. package/dist/cli/mcp.d.ts +2 -0
  29. package/dist/cli/mcp.js +457 -0
  30. package/dist/cli/migrate-intershell.js +5 -5
  31. package/dist/cli/policy-defaults.d.ts +37 -0
  32. package/dist/cli/policy-defaults.js +127 -0
  33. package/dist/cli/processors/integration-audit.js +2 -2
  34. package/dist/cli/processors/openapi-parser.d.ts +5 -0
  35. package/dist/cli/processors/openapi-parser.js +8 -3
  36. package/dist/cli/project-loader.d.ts +58 -0
  37. package/dist/cli/project-loader.js +198 -0
  38. package/dist/cli/project-writer.d.ts +23 -0
  39. package/dist/cli/project-writer.js +171 -0
  40. package/dist/cli/push.d.ts +43 -0
  41. package/dist/cli/push.js +276 -0
  42. package/dist/cli/safety-checks.d.ts +9 -0
  43. package/dist/cli/safety-checks.js +29 -0
  44. package/dist/cli/setup.d.ts +20 -0
  45. package/dist/cli/setup.js +349 -0
  46. package/dist/cli/shell-name.d.ts +8 -0
  47. package/dist/cli/shell-name.js +29 -0
  48. package/dist/cli/shells.d.ts +22 -0
  49. package/dist/cli/shells.js +122 -0
  50. package/dist/cli/split.d.ts +7 -0
  51. package/dist/cli/split.js +71 -0
  52. package/dist/cli/sync.d.ts +25 -0
  53. package/dist/cli/sync.js +120 -0
  54. package/dist/cli/test-runner.d.ts +21 -0
  55. package/dist/cli/test-runner.js +281 -0
  56. package/dist/core/compile.d.ts +43 -0
  57. package/dist/core/compile.js +510 -0
  58. package/dist/core/config.d.ts +533 -1
  59. package/dist/core/config.js +32 -12
  60. package/dist/core/hosted-upstream-check.d.ts +3 -0
  61. package/dist/core/hosted-upstream-check.js +35 -0
  62. package/dist/core/login-handoff.d.ts +1 -1
  63. package/dist/core/login-handoff.js +1 -1
  64. package/dist/core/project.d.ts +1798 -0
  65. package/dist/core/project.js +278 -0
  66. package/dist/core/readiness-checks.js +2 -2
  67. package/dist/core/types.d.ts +26 -1
  68. package/dist/index.d.ts +6 -0
  69. package/dist/index.js +16 -0
  70. package/dist/project.d.ts +4 -0
  71. package/dist/project.js +8 -0
  72. package/dist/server.d.ts +2 -0
  73. package/dist/server.js +1 -0
  74. package/fixtures/token-conformance-vectors.json +26 -0
  75. package/package.json +94 -94
  76. package/dist/adapters/react/page-context-guard.test.d.ts +0 -1
  77. package/dist/adapters/react/page-context-guard.test.js +0 -15
  78. package/dist/cli/agents/api-agent.d.ts +0 -22
  79. package/dist/cli/agents/api-agent.js +0 -761
  80. package/dist/cli/agents/auth-agent.d.ts +0 -7
  81. package/dist/cli/agents/auth-agent.js +0 -212
  82. package/dist/cli/agents/deeplink-agent.d.ts +0 -6
  83. package/dist/cli/agents/deeplink-agent.js +0 -285
  84. package/dist/cli/agents/llm.d.ts +0 -33
  85. package/dist/cli/agents/llm.js +0 -309
  86. package/dist/cli/agents/pipeline.d.ts +0 -72
  87. package/dist/cli/agents/pipeline.js +0 -421
  88. package/dist/cli/agents/reviewer-agent.d.ts +0 -13
  89. package/dist/cli/agents/reviewer-agent.js +0 -450
  90. package/dist/cli/agents/route-agent.d.ts +0 -17
  91. package/dist/cli/agents/route-agent.js +0 -383
  92. package/dist/cli/config-loader.test.d.ts +0 -1
  93. package/dist/cli/config-loader.test.js +0 -63
  94. package/dist/cli/detectors/topology.d.ts +0 -46
  95. package/dist/cli/detectors/topology.js +0 -417
  96. package/dist/cli/generators/config.test.d.ts +0 -1
  97. package/dist/cli/generators/config.test.js +0 -222
  98. package/dist/cli/generators/shell.test.d.ts +0 -1
  99. package/dist/cli/generators/shell.test.js +0 -73
  100. package/dist/cli/generators/token-route.test.d.ts +0 -1
  101. package/dist/cli/generators/token-route.test.js +0 -53
  102. package/dist/cli/generators/wiring-snippets.test.d.ts +0 -1
  103. package/dist/cli/generators/wiring-snippets.test.js +0 -80
  104. package/dist/cli/init.d.ts +0 -32
  105. package/dist/cli/init.js +0 -1336
  106. package/dist/cli/manifest-diff.test.d.ts +0 -1
  107. package/dist/cli/manifest-diff.test.js +0 -144
  108. package/dist/cli/processors/curl-parser.test.d.ts +0 -1
  109. package/dist/cli/processors/curl-parser.test.js +0 -24
  110. package/dist/cli/processors/integration-audit.test.d.ts +0 -1
  111. package/dist/cli/processors/integration-audit.test.js +0 -154
  112. package/dist/cli/processors/postprocess.d.ts +0 -22
  113. package/dist/cli/processors/postprocess.js +0 -107
  114. package/dist/cli/processors/prisma-parser.d.ts +0 -35
  115. package/dist/cli/processors/prisma-parser.js +0 -117
  116. package/dist/cli/processors/verify-discovery.d.ts +0 -33
  117. package/dist/cli/processors/verify-discovery.js +0 -193
  118. package/dist/cli/processors/verify-discovery.test.d.ts +0 -1
  119. package/dist/cli/processors/verify-discovery.test.js +0 -153
  120. package/dist/cli/processors/zod-extractor.d.ts +0 -27
  121. package/dist/cli/processors/zod-extractor.js +0 -153
  122. package/dist/cli/prompts/review.d.ts +0 -61
  123. package/dist/cli/prompts/review.js +0 -410
  124. package/dist/cli/selectors/express.d.ts +0 -12
  125. package/dist/cli/selectors/express.js +0 -117
  126. package/dist/cli/selectors/fastapi.d.ts +0 -12
  127. package/dist/cli/selectors/fastapi.js +0 -122
  128. package/dist/cli/selectors/generic.d.ts +0 -10
  129. package/dist/cli/selectors/generic.js +0 -74
  130. package/dist/cli/selectors/index.d.ts +0 -37
  131. package/dist/cli/selectors/index.js +0 -315
  132. package/dist/cli/selectors/next.d.ts +0 -12
  133. package/dist/cli/selectors/next.js +0 -130
  134. package/dist/core/config-policy.test.d.ts +0 -1
  135. package/dist/core/config-policy.test.js +0 -101
  136. package/dist/core/config-roundtrip.test.d.ts +0 -1
  137. package/dist/core/config-roundtrip.test.js +0 -180
  138. package/dist/core/endpoint-guard.test.d.ts +0 -1
  139. package/dist/core/endpoint-guard.test.js +0 -57
  140. package/dist/core/env-diagnostics.test.d.ts +0 -1
  141. package/dist/core/env-diagnostics.test.js +0 -31
  142. package/dist/core/evidence-bundle.conformance.test.d.ts +0 -1
  143. package/dist/core/evidence-bundle.conformance.test.js +0 -110
  144. package/dist/core/evidence-bundle.test.d.ts +0 -1
  145. package/dist/core/evidence-bundle.test.js +0 -58
  146. package/dist/core/invariants.test.d.ts +0 -1
  147. package/dist/core/invariants.test.js +0 -217
  148. package/dist/core/login-handoff.test.d.ts +0 -1
  149. package/dist/core/login-handoff.test.js +0 -31
  150. package/dist/core/profile.test.d.ts +0 -1
  151. package/dist/core/profile.test.js +0 -95
  152. package/dist/core/readiness-checks.test.d.ts +0 -1
  153. package/dist/core/readiness-checks.test.js +0 -106
  154. package/dist/core/receipt.test.d.ts +0 -1
  155. package/dist/core/receipt.test.js +0 -75
  156. package/dist/core/side-effects-review.test.d.ts +0 -1
  157. package/dist/core/side-effects-review.test.js +0 -28
  158. package/dist/core/token.test.d.ts +0 -1
  159. package/dist/core/token.test.js +0 -66
@@ -1,31 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { detectLoginRoutePath, enrichAuthLoginHandoff, resolveLoginHandoff, } from './login-handoff.js';
4
- describe('detectLoginRoutePath', () => {
5
- it('finds common login paths', () => {
6
- assert.equal(detectLoginRoutePath([
7
- { path: '/dashboard' },
8
- { path: '/auth/signin' },
9
- ]), '/auth/signin');
10
- });
11
- });
12
- describe('enrichAuthLoginHandoff', () => {
13
- it('adds loginRoutePath from routes', () => {
14
- const auth = enrichAuthLoginHandoff({
15
- strategy: 'nextauth',
16
- sessionFields: ['userId'],
17
- guestAllowed: false,
18
- tokenExpirySeconds: 300,
19
- }, [{ path: '/login' }]);
20
- assert.equal(auth.loginRoutePath, '/login');
21
- });
22
- });
23
- describe('resolveLoginHandoff', () => {
24
- it('prefers explicit loginRoutePath', () => {
25
- const target = resolveLoginHandoff({
26
- baseUrl: 'https://app.example.com',
27
- auth: { guestAllowed: false, loginRoutePath: '/sign-in' },
28
- });
29
- assert.equal(target?.url, '/sign-in');
30
- });
31
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,95 +0,0 @@
1
- import { describe, it, beforeEach, afterEach } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { mkdtempSync, rmSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import path from "node:path";
6
- import { applyActiveProfileEnvSync, applyProfileUrlsToEnv, listProfileNames, readProfileFileSync, resolveActiveProfileName, resolveProfileUrls, setActiveProfileSync, writeProfileFileSync, } from "./profile.js";
7
- const ORIGINAL_ENV = { ...process.env };
8
- function restoreEnv() {
9
- for (const key of Object.keys(process.env)) {
10
- if (!(key in ORIGINAL_ENV))
11
- delete process.env[key];
12
- }
13
- for (const [key, value] of Object.entries(ORIGINAL_ENV)) {
14
- if (value === undefined)
15
- delete process.env[key];
16
- else
17
- process.env[key] = value;
18
- }
19
- }
20
- describe("profile discovery", () => {
21
- let tempDir;
22
- let profilePath;
23
- beforeEach(() => {
24
- tempDir = mkdtempSync(path.join(tmpdir(), "duct-profile-"));
25
- profilePath = path.join(tempDir, "profile.json");
26
- delete process.env.DUCT_PROFILE;
27
- delete process.env.DUCT_URL;
28
- delete process.env.DUCT_API_URL;
29
- delete process.env.DUCT_AUTH_URL;
30
- delete process.env.DUCT_SHELL_URL;
31
- delete process.env.DUCT_DASHBOARD_URL;
32
- delete process.env.DUCT_REGISTRY_URL;
33
- delete process.env.DUCT_DOCS_URL;
34
- });
35
- afterEach(() => {
36
- restoreEnv();
37
- rmSync(tempDir, { recursive: true, force: true });
38
- });
39
- it("defaults to hosted when no file or env", () => {
40
- assert.equal(resolveActiveProfileName(null), "hosted");
41
- });
42
- it("reads active profile from file", () => {
43
- writeProfileFileSync({ active: "local" }, profilePath);
44
- const file = readProfileFileSync(profilePath);
45
- assert.equal(resolveActiveProfileName(file), "local");
46
- });
47
- it("prefers DUCT_PROFILE env over file", () => {
48
- process.env.DUCT_PROFILE = "staging";
49
- writeProfileFileSync({ active: "local" }, profilePath);
50
- const file = readProfileFileSync(profilePath);
51
- assert.equal(resolveActiveProfileName(file), "staging");
52
- });
53
- it("applies local builtin URLs when profile is local", () => {
54
- applyProfileUrlsToEnv("local");
55
- assert.equal(process.env.DUCT_API_URL, "http://localhost:3002");
56
- assert.equal(process.env.DUCT_AUTH_URL, "http://localhost:3001");
57
- assert.equal(process.env.DUCT_PROFILE, "local");
58
- });
59
- it("merges custom profile URLs from file", () => {
60
- writeProfileFileSync({
61
- active: "staging",
62
- profiles: {
63
- staging: { ductUrl: "https://staging.acme.dev" },
64
- },
65
- }, profilePath);
66
- const file = readProfileFileSync(profilePath);
67
- const urls = resolveProfileUrls("staging", file);
68
- assert.equal(urls.ductUrl, "https://staging.acme.dev");
69
- });
70
- it("does not override shell-protected env keys", () => {
71
- process.env.DUCT_API_URL = "https://api.custom.test";
72
- const protectedKeys = new Set(["DUCT_API_URL"]);
73
- applyProfileUrlsToEnv("local", { protectedKeys });
74
- assert.equal(process.env.DUCT_API_URL, "https://api.custom.test");
75
- assert.equal(process.env.DUCT_AUTH_URL, "http://localhost:3001");
76
- });
77
- it("applyActiveProfileEnvSync loads file and applies URLs", () => {
78
- writeProfileFileSync({ active: "local" }, profilePath);
79
- const name = applyActiveProfileEnvSync({ profilePath });
80
- assert.equal(name, "local");
81
- assert.equal(process.env.DUCT_SHELL_URL, "http://localhost:3000");
82
- });
83
- it("lists builtin and custom profile names", () => {
84
- writeProfileFileSync({ active: "local", profiles: { staging: { ductUrl: "https://x.test" } } }, profilePath);
85
- const names = listProfileNames(readProfileFileSync(profilePath));
86
- assert.ok(names.includes("local"));
87
- assert.ok(names.includes("hosted"));
88
- assert.ok(names.includes("staging"));
89
- });
90
- it("setActiveProfileSync updates active field", () => {
91
- setActiveProfileSync("local", { profilePath });
92
- const file = readProfileFileSync(profilePath);
93
- assert.equal(file?.active, "local");
94
- });
95
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,106 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { ReadinessReportSchema, buildCliReadinessReport, buildShellReadinessReport, probeProductBaseUrl, readinessReportOk, rewriteLoopbackForDocker, } from './readiness-checks.js';
4
- describe('readiness-checks', () => {
5
- it('buildCliReadinessReport emits schema-valid output', async () => {
6
- const report = await buildCliReadinessReport({
7
- env: {
8
- ductUrl: 'http://localhost:3005',
9
- shellId: 'shell_test',
10
- secretKey: 'sk_test1234',
11
- authEmail: 'dev@example.com',
12
- authSlug: 'acme',
13
- },
14
- endpoints: {
15
- authHealthUrl: 'http://localhost:3001/health',
16
- apiHealthUrl: 'http://localhost:3002/health',
17
- shellHealthUrl: 'http://localhost:3000/api/health',
18
- dashboardHealthUrl: 'http://localhost:3004/api/health',
19
- docsUrl: 'http://localhost:3005/docs',
20
- },
21
- probe: async (url) => ({ ok: url.includes('/health'), status: 200 }),
22
- });
23
- assert.equal(ReadinessReportSchema.safeParse(report).success, true);
24
- assert.equal(report.ok, true);
25
- assert.equal(report.docsUrl, 'http://localhost:3005/docs');
26
- assert.ok(report.checks.some((c) => c.id === 'api_reachable' && c.status === 'pass'));
27
- assert.ok(report.checks.some((c) => c.id === 'docs_url'));
28
- });
29
- it('marks report not ok when a required service probe fails', async () => {
30
- const report = await buildCliReadinessReport({
31
- env: {},
32
- endpoints: {
33
- authHealthUrl: 'http://localhost:3001/health',
34
- apiHealthUrl: 'http://localhost:3002/health',
35
- shellHealthUrl: 'http://localhost:3000/api/health',
36
- dashboardHealthUrl: 'http://localhost:3004/api/health',
37
- docsUrl: 'http://localhost:3005/docs',
38
- },
39
- probe: async (url) => ({
40
- ok: !url.includes(':3002'),
41
- status: url.includes(':3002') ? 503 : 200,
42
- }),
43
- });
44
- assert.equal(readinessReportOk(report.checks), false);
45
- assert.equal(report.ok, false);
46
- const api = report.checks.find((c) => c.id === 'api_reachable');
47
- assert.equal(api?.status, 'fail');
48
- });
49
- it('rewriteLoopbackForDocker rewrites localhost hosts', () => {
50
- assert.equal(rewriteLoopbackForDocker('http://localhost:5173'), 'http://host.docker.internal:5173/');
51
- assert.equal(rewriteLoopbackForDocker('https://app.example.com'), null);
52
- });
53
- it('probeProductBaseUrl retries via host.docker.internal', async () => {
54
- const attempted = [];
55
- const fetchFn = (async (input) => {
56
- const url = String(input);
57
- attempted.push(url);
58
- if (url.includes('host.docker.internal')) {
59
- return new Response('ok', { status: 200 });
60
- }
61
- throw new Error('fetch failed');
62
- });
63
- const result = await probeProductBaseUrl('http://localhost:5173', fetchFn);
64
- assert.equal(result.reachable, true);
65
- assert.deepEqual(attempted, [
66
- 'http://localhost:5173',
67
- 'http://host.docker.internal:5173/',
68
- ]);
69
- });
70
- it('buildShellReadinessReport is shell-only and probes product URL', async () => {
71
- const report = await buildShellReadinessReport({
72
- shellId: 'shell_test',
73
- manifestPushed: true,
74
- productBaseUrl: 'http://localhost:5173',
75
- actionCount: 2,
76
- recentMessages: 1,
77
- recentInvokeTurns: 0,
78
- statusUrl: 'http://localhost:3005/status',
79
- probeProduct: async () => ({ reachable: false, error: 'fetch failed' }),
80
- });
81
- assert.equal(ReadinessReportSchema.safeParse(report).success, true);
82
- assert.equal(report.ok, false);
83
- assert.equal(report.statusUrl, 'http://localhost:3005/status');
84
- assert.equal(report.checks.length, 4);
85
- assert.ok(!report.checks.some((c) => c.id === 'auth_reachable'));
86
- assert.ok(!report.checks.some((c) => c.id === 'api_reachable'));
87
- assert.ok(!report.checks.some((c) => c.id === 'docs_url'));
88
- const product = report.checks.find((c) => c.id === 'product_base_url');
89
- assert.equal(product?.status, 'fail');
90
- assert.match(product?.message ?? '', /fetch failed/);
91
- });
92
- it('buildShellReadinessReport passes when product URL is reachable', async () => {
93
- const report = await buildShellReadinessReport({
94
- shellId: 'shell_test',
95
- manifestPushed: true,
96
- productBaseUrl: 'http://localhost:5173',
97
- actionCount: 1,
98
- recentMessages: 0,
99
- recentInvokeTurns: 1,
100
- probeProduct: async () => ({ reachable: true, status: 200 }),
101
- });
102
- assert.equal(report.ok, true);
103
- const product = report.checks.find((c) => c.id === 'product_base_url');
104
- assert.equal(product?.status, 'pass');
105
- });
106
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,75 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { createHmac } from "crypto";
4
- import { canonicalizeJson } from "./jcs.js";
5
- import { computeReceiptId, verifyReceipt, } from "./receipt.js";
6
- const HMAC_SECRET = "01234567890123456789012345678901";
7
- function signTestReceipt(body) {
8
- const receipt_id = computeReceiptId(body);
9
- const canonical = canonicalizeJson(body);
10
- const signature = createHmac("sha256", HMAC_SECRET).update(canonical).digest("hex");
11
- return { ...body, receipt_id, signature, kid: "duct-gateway-hs256-v1" };
12
- }
13
- describe("verifyReceipt", () => {
14
- it("verifies HMAC-signed action receipts", () => {
15
- const body = {
16
- claim_type: "duct:action:v1",
17
- issued_at: "2026-07-01T00:00:00.000Z",
18
- shell_id: "shell_test",
19
- action_id: "search",
20
- caller_type: "agent",
21
- decision: "permit",
22
- reason: "allowed",
23
- permission_source: "manifest",
24
- capture_mode: "gateway_observed",
25
- scope_of_claim: {
26
- asserts: ["gate admitted action"],
27
- does_not_assert: ["upstream completed"],
28
- },
29
- };
30
- const signed = signTestReceipt(body);
31
- const result = verifyReceipt(signed, { hmacSecret: HMAC_SECRET });
32
- assert.equal(result.valid, true);
33
- });
34
- it("rejects tampered receipt_id", () => {
35
- const body = {
36
- claim_type: "duct:action:v1",
37
- issued_at: "2026-07-01T00:00:00.000Z",
38
- shell_id: "shell_test",
39
- action_id: "search",
40
- caller_type: "agent",
41
- decision: "permit",
42
- reason: "allowed",
43
- permission_source: "manifest",
44
- capture_mode: "gateway_observed",
45
- scope_of_claim: { asserts: [], does_not_assert: [] },
46
- };
47
- const signed = signTestReceipt(body);
48
- const tampered = { ...signed, receipt_id: "deadbeef".repeat(4) };
49
- const result = verifyReceipt(tampered, { hmacSecret: HMAC_SECRET });
50
- assert.equal(result.valid, false);
51
- if (!result.valid)
52
- assert.equal(result.reason, "RECEIPT_ID_MISMATCH");
53
- });
54
- it("rejects wrong claim type when expectedClaimType set", () => {
55
- const signed = signTestReceipt({
56
- claim_type: "duct:action:v1",
57
- issued_at: "2026-07-01T00:00:00.000Z",
58
- shell_id: "shell_test",
59
- action_id: "search",
60
- caller_type: "agent",
61
- decision: "permit",
62
- reason: "allowed",
63
- permission_source: "manifest",
64
- capture_mode: "gateway_observed",
65
- scope_of_claim: { asserts: [], does_not_assert: [] },
66
- });
67
- const result = verifyReceipt(signed, {
68
- hmacSecret: HMAC_SECRET,
69
- expectedClaimType: "duct:intent:v1",
70
- });
71
- assert.equal(result.valid, false);
72
- if (!result.valid)
73
- assert.equal(result.reason, "WRONG_CLAIM");
74
- });
75
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { collectSideEffectReviewMismatches, deriveExpectedSideEffects, } from '@duct-sdk/contracts';
4
- describe('side-effects-review', () => {
5
- it('derives sideEffects from HTTP method', () => {
6
- assert.equal(deriveExpectedSideEffects('GET'), false);
7
- assert.equal(deriveExpectedSideEffects('post'), true);
8
- assert.equal(deriveExpectedSideEffects(''), null);
9
- });
10
- it('flags mismatches without acknowledgment', () => {
11
- const mismatches = collectSideEffectReviewMismatches([
12
- { id: 'search', method: 'POST', sideEffects: false },
13
- ]);
14
- assert.equal(mismatches.length, 1);
15
- assert.equal(mismatches[0]?.actionId, 'search');
16
- });
17
- it('accepts acknowledged mismatches', () => {
18
- const mismatches = collectSideEffectReviewMismatches([
19
- {
20
- id: 'search',
21
- method: 'POST',
22
- sideEffects: false,
23
- sideEffectsReviewAck: 'Body-heavy search only; no mutations',
24
- },
25
- ]);
26
- assert.equal(mismatches.length, 0);
27
- });
28
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,66 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { generateDeeplinkToken, verifyDeeplinkToken, generateDuctToken, verifyDuctToken, createDevReplayStore, } from "./token.js";
4
- const SECRET = "test-secret-key-at-least-32-chars-long";
5
- const SHELL_ID = "shell_test_prod";
6
- describe("verifyDeeplinkToken replay protection", () => {
7
- it("mint → verify ok → replay rejected when store configured", async () => {
8
- const replayStore = createDevReplayStore();
9
- const { token } = await generateDeeplinkToken({
10
- secretKey: SECRET,
11
- shellId: SHELL_ID,
12
- deeplinkId: "view_order",
13
- state: { orderId: "42" },
14
- });
15
- const first = await verifyDeeplinkToken(token, {
16
- secretKey: SECRET,
17
- expectedShellId: SHELL_ID,
18
- replayStore,
19
- });
20
- assert.equal(first.valid, true);
21
- assert.ok(first.payload);
22
- assert.notEqual(first.payload.jti, "");
23
- const second = await verifyDeeplinkToken(token, {
24
- secretKey: SECRET,
25
- expectedShellId: SHELL_ID,
26
- replayStore,
27
- });
28
- assert.equal(second.valid, false);
29
- assert.equal(second.error, "Token already used");
30
- });
31
- it("populates jti on verified payload", async () => {
32
- const { token } = await generateDeeplinkToken({
33
- secretKey: SECRET,
34
- shellId: SHELL_ID,
35
- deeplinkId: "view_order",
36
- });
37
- const result = await verifyDeeplinkToken(token, {
38
- secretKey: SECRET,
39
- expectedShellId: SHELL_ID,
40
- });
41
- assert.equal(result.valid, true);
42
- assert.ok(result.payload);
43
- assert.notEqual(result.payload.jti, "");
44
- });
45
- });
46
- describe("generateDuctToken session allowlist", () => {
47
- it("copies only auth.sessionFields scalars into delegated JWT", async () => {
48
- const { token } = await generateDuctToken({
49
- secretKey: SECRET,
50
- shellId: SHELL_ID,
51
- userSession: {
52
- userId: "u_123",
53
- jwt: "eyJhbGciOiJIUzI1NiJ9.secret",
54
- ssn: "123-45-6789",
55
- email: "user@example.com",
56
- },
57
- sessionFields: ["userId"],
58
- });
59
- const verified = await verifyDuctToken(token, {
60
- secretKey: SECRET,
61
- expectedShellId: SHELL_ID,
62
- });
63
- assert.equal(verified.valid, true);
64
- assert.deepEqual(verified.payload?.session, { userId: "u_123" });
65
- });
66
- });