@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,73 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { generateShell } from "./shell.js";
4
- import { generateReceiver } from "./receiver.js";
5
- import { runAgentSafetyChecks } from "../agents/reviewer-agent.js";
6
- const vueFramework = {
7
- name: "vue3",
8
- version: "3.4.0",
9
- hasAppRouter: false,
10
- hasPagesRouter: false,
11
- packageManager: "npm",
12
- srcDir: "src",
13
- };
14
- const minimalConfig = {
15
- shellId: "shell_test",
16
- product: {
17
- name: "Test",
18
- description: "Test product",
19
- baseUrl: "https://app.example.com",
20
- },
21
- };
22
- describe("generateShell vue3 origin guard", () => {
23
- it("includes origin guard and isAllowedDeeplinkUrl", () => {
24
- const code = generateShell(minimalConfig, vueFramework);
25
- assert.match(code, /event\.origin !== shellOrigin/);
26
- assert.match(code, /function isAllowedDeeplinkUrl/);
27
- assert.match(code, /isAllowedDeeplinkUrl\(url\)/);
28
- });
29
- });
30
- describe("generateReceiver replay store", () => {
31
- it("wires createDevReplayStore into remix receiver", () => {
32
- const remixFramework = {
33
- name: "remix",
34
- version: "2.0.0",
35
- hasAppRouter: false,
36
- hasPagesRouter: false,
37
- packageManager: "npm",
38
- srcDir: "app",
39
- };
40
- const code = generateReceiver(minimalConfig, remixFramework);
41
- assert.match(code, /createDevReplayStore/);
42
- assert.match(code, /replayStore/);
43
- });
44
- });
45
- describe("runAgentSafetyChecks", () => {
46
- it("errors on agentAccessible write with high sensitivity", () => {
47
- const issues = runAgentSafetyChecks({
48
- routes: [],
49
- deeplinks: [],
50
- auth: {
51
- strategy: "none",
52
- sessionFields: ["id"],
53
- guestAllowed: false,
54
- tokenExpirySeconds: 300,
55
- },
56
- actions: [
57
- {
58
- id: "delete_user",
59
- name: "Delete",
60
- description: "Deletes a user account permanently",
61
- method: "DELETE",
62
- path: "/api/users/:id",
63
- agentAccessible: true,
64
- sideEffects: true,
65
- sensitivityLevel: "critical",
66
- params: [],
67
- requiresAuth: true,
68
- },
69
- ],
70
- });
71
- assert.ok(issues.some((i) => i.code === "HIGH_SENSITIVITY_AGENT_ACCESSIBLE" && i.severity === "error"));
72
- });
73
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,53 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { generateStrategyTokenRoute } from "./token-route.js";
4
- function nextAppFramework() {
5
- return {
6
- name: "next-app",
7
- version: "14.0.0",
8
- hasAppRouter: true,
9
- hasPagesRouter: false,
10
- packageManager: "npm",
11
- srcDir: ".",
12
- };
13
- }
14
- describe("generateStrategyTokenRoute", () => {
15
- it("includes clerk session lookup for clerk strategy", () => {
16
- const code = generateStrategyTokenRoute(nextAppFramework(), {
17
- authStrategy: "clerk",
18
- guestAllowed: true,
19
- });
20
- assert.match(code, /@clerk\/nextjs\/server/);
21
- assert.match(code, /currentUser/);
22
- assert.match(code, /generateDuctToken/);
23
- assert.match(code, /@duct-sdk\/sdk\/server/);
24
- });
25
- it("returns 401 when guestAllowed is false and session is empty", () => {
26
- const code = generateStrategyTokenRoute(nextAppFramework(), {
27
- authStrategy: "nextauth",
28
- guestAllowed: false,
29
- });
30
- assert.match(code, /Object\.keys\(userSession\)\.length === 0/);
31
- assert.match(code, /status: 401/);
32
- });
33
- it("allows guest minting when guestAllowed is true", () => {
34
- const code = generateStrategyTokenRoute(nextAppFramework(), {
35
- authStrategy: "nextauth",
36
- guestAllowed: true,
37
- });
38
- assert.match(code, /Guest users allowed/);
39
- assert.doesNotMatch(code, /Object\.keys\(userSession\)\.length === 0/);
40
- });
41
- it("generates express route for vite-react", () => {
42
- const code = generateStrategyTokenRoute({
43
- name: "vite-react",
44
- version: "5.0.0",
45
- hasAppRouter: false,
46
- hasPagesRouter: false,
47
- packageManager: "npm",
48
- srcDir: "src",
49
- }, { authStrategy: "custom-jwt", guestAllowed: false });
50
- assert.match(code, /express/);
51
- assert.match(code, /\/api\/duct\/token/);
52
- });
53
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,80 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import * as path from "path";
4
- import { buildWiringPlan, generateVerifyDuctTokenMiddlewareSnippet, generateUctVerificationSnippet, sideEffectActionsApproved, } from "./wiring-snippets.js";
5
- const framework = {
6
- name: "next-app",
7
- version: "14.0.0",
8
- hasAppRouter: true,
9
- hasPagesRouter: false,
10
- packageManager: "npm",
11
- srcDir: ".",
12
- };
13
- const authDetection = {
14
- system: "nextauth",
15
- confidence: 0.9,
16
- sessionFields: ["id", "email"],
17
- guestAllowed: false,
18
- middlewarePath: "middleware.ts",
19
- configFiles: [],
20
- notes: [],
21
- };
22
- describe("wiring snippets", () => {
23
- it("buildWiringPlan lists core generated files", () => {
24
- const outputPaths = {
25
- configPath: path.join("/proj", "duct.config.ts"),
26
- tokenRoutePath: path.join("/proj", "app/api/duct/token/route.ts"),
27
- receiverPath: path.join("/proj", "app/api/duct/receive/route.ts"),
28
- shellComponentPath: path.join("/proj", "components", "DuctShell.tsx"),
29
- envTemplatePath: path.join("/proj", ".env.local.example"),
30
- };
31
- const plan = buildWiringPlan(outputPaths, framework, authDetection, "none");
32
- assert.ok(plan.items.some((item) => item.summary.includes("Mint duct_delegated")));
33
- assert.ok(plan.items.some((item) => item.summary.includes("verifyDuctToken")));
34
- assert.equal(plan.middlewareSnippetPath, ".duct/snippets/verify-duct-token.ts");
35
- assert.match(plan.middlewareSnippet, /verifyDuctToken/);
36
- });
37
- it("adds uct snippet when third-party agents use duct-consent", () => {
38
- const outputPaths = {
39
- configPath: "/proj/duct.config.ts",
40
- tokenRoutePath: "/proj/app/api/duct/token/route.ts",
41
- receiverPath: "/proj/app/api/duct/receive/route.ts",
42
- shellComponentPath: "/proj/components/DuctShell.tsx",
43
- envTemplatePath: "/proj/.env.local.example",
44
- };
45
- const plan = buildWiringPlan(outputPaths, framework, authDetection, "duct-consent");
46
- assert.equal(plan.uctSnippetPath, ".duct/snippets/uct-consent-auth.ts");
47
- assert.match(plan.uctSnippet ?? "", /uct_/);
48
- assert.ok(plan.items.some((item) => item.summary.includes("uct_")));
49
- });
50
- it("generateVerifyDuctTokenMiddlewareSnippet targets express for vite-react", () => {
51
- const snippet = generateVerifyDuctTokenMiddlewareSnippet({
52
- name: "vite-react",
53
- version: "5.0.0",
54
- hasAppRouter: false,
55
- hasPagesRouter: false,
56
- packageManager: "npm",
57
- srcDir: "src",
58
- }, "server/middleware/auth.ts");
59
- assert.match(snippet, /express/);
60
- assert.match(snippet, /ductDelegatedAuth/);
61
- assert.match(snippet, /expectedShellId/);
62
- });
63
- it("ductOrConsentAuth rejects unrecognized delegated tokens", () => {
64
- const snippet = generateUctVerificationSnippet({
65
- name: "vite-react",
66
- version: "5.0.0",
67
- hasAppRouter: false,
68
- hasPagesRouter: false,
69
- packageManager: "npm",
70
- srcDir: "src",
71
- });
72
- assert.match(snippet, /ductOrConsentAuth/);
73
- assert.match(snippet, /expectedShellId/);
74
- assert.doesNotMatch(snippet, /Fall through to ductDelegatedAuth[\s\S]*return next\(\)/);
75
- });
76
- it("sideEffectActionsApproved detects side-effect actions", () => {
77
- assert.equal(sideEffectActionsApproved({ actions: [{ sideEffects: true }] }), true);
78
- assert.equal(sideEffectActionsApproved({ actions: [{ sideEffects: false }] }), false);
79
- });
80
- });
@@ -1,32 +0,0 @@
1
- export interface InitOptions {
2
- /** Project root directory */
3
- cwd?: string;
4
- /** Skip the agent pipeline (open blank template) */
5
- noAgents?: boolean;
6
- /** Only print output, don't write files */
7
- dryRun?: boolean;
8
- /** Force framework detection result */
9
- framework?: string;
10
- /** Re-run agents on an existing duct.config.ts */
11
- update?: boolean;
12
- /** Auto-approve all review prompts — for CI / scripted use */
13
- yes?: boolean;
14
- /** Write unresolved review decisions to duct-review.json instead of prompting interactively */
15
- noInteractive?: boolean;
16
- /** Manual mode — topology + file selection only, no LLM. Generates a pre-filled template. */
17
- manual?: boolean;
18
- /** Path to an OpenAPI/Swagger spec file — skips Route + API agents */
19
- apiSpec?: string;
20
- /** Path to a cURL script or Postman collection — skips Route + API agents */
21
- curlCollection?: string;
22
- /** Separate API base URL (for APIs on a different domain from the frontend) */
23
- apiUrl?: string;
24
- /** Industry/category override (e.g., fintech, ecommerce, saas) */
25
- industry?: string;
26
- }
27
- export type { GeneratedOutputPaths as GeneratedFiles } from "./output-paths.js";
28
- /**
29
- * Run the Duct init command.
30
- * This is the main entry point for `npx duct init`.
31
- */
32
- export declare function runInit(opts?: InitOptions): Promise<void>;