@duct-sdk/sdk 0.3.12 → 0.4.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 (58) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/adapters/next/receiver.d.ts +2 -6
  3. package/dist/adapters/next/receiver.js +20 -66
  4. package/dist/adapters/remix/receiver.d.ts +2 -6
  5. package/dist/adapters/remix/receiver.js +16 -33
  6. package/dist/adapters/sveltekit/receiver.d.ts +2 -6
  7. package/dist/adapters/sveltekit/receiver.js +13 -40
  8. package/dist/adapters/vite/receiver.d.ts +2 -4
  9. package/dist/adapters/vite/receiver.js +13 -30
  10. package/dist/cli/agents/api-agent.d.ts +3 -1
  11. package/dist/cli/agents/api-agent.js +22 -11
  12. package/dist/cli/agents/auth-agent.js +4 -4
  13. package/dist/cli/agents/pipeline.js +63 -7
  14. package/dist/cli/agents/route-agent.d.ts +3 -1
  15. package/dist/cli/agents/route-agent.js +17 -6
  16. package/dist/cli/detectors/topology.d.ts +1 -1
  17. package/dist/cli/detectors/topology.js +1 -1
  18. package/dist/cli/generators/config.js +71 -44
  19. package/dist/cli/generators/config.test.d.ts +1 -0
  20. package/dist/cli/generators/config.test.js +219 -0
  21. package/dist/cli/generators/normalize.d.ts +10 -0
  22. package/dist/cli/generators/normalize.js +49 -0
  23. package/dist/cli/generators/receiver.d.ts +2 -1
  24. package/dist/cli/generators/receiver.js +20 -201
  25. package/dist/cli/generators/token-route.d.ts +8 -0
  26. package/dist/cli/generators/token-route.js +235 -0
  27. package/dist/cli/generators/token-route.test.d.ts +1 -0
  28. package/dist/cli/generators/token-route.test.js +53 -0
  29. package/dist/cli/generators/wiring-snippets.d.ts +23 -0
  30. package/dist/cli/generators/wiring-snippets.js +233 -0
  31. package/dist/cli/generators/wiring-snippets.test.d.ts +1 -0
  32. package/dist/cli/generators/wiring-snippets.test.js +66 -0
  33. package/dist/cli/index.js +41 -1
  34. package/dist/cli/init.d.ts +1 -7
  35. package/dist/cli/init.js +100 -53
  36. package/dist/cli/output-paths.d.ts +10 -0
  37. package/dist/cli/output-paths.js +60 -0
  38. package/dist/cli/processors/curl-parser.test.d.ts +1 -0
  39. package/dist/cli/processors/curl-parser.test.js +24 -0
  40. package/dist/cli/processors/integration-audit.d.ts +23 -0
  41. package/dist/cli/processors/integration-audit.js +208 -0
  42. package/dist/cli/processors/integration-audit.test.d.ts +1 -0
  43. package/dist/cli/processors/integration-audit.test.js +154 -0
  44. package/dist/cli/processors/prisma-parser.js +1 -1
  45. package/dist/cli/processors/verify-discovery.d.ts +33 -0
  46. package/dist/cli/processors/verify-discovery.js +193 -0
  47. package/dist/cli/processors/verify-discovery.test.d.ts +1 -0
  48. package/dist/cli/processors/verify-discovery.test.js +153 -0
  49. package/dist/cli/processors/zod-extractor.js +1 -1
  50. package/dist/core/config.d.ts +16 -0
  51. package/dist/core/config.js +59 -28
  52. package/dist/core/endpoints.d.ts +2 -0
  53. package/dist/core/endpoints.js +10 -0
  54. package/dist/core/receiver.d.ts +33 -0
  55. package/dist/core/receiver.js +77 -0
  56. package/dist/server.d.ts +2 -0
  57. package/dist/server.js +2 -0
  58. package/package.json +2 -1
@@ -9,6 +9,8 @@ export declare function getManifestApiBase(profile?: EndpointProfile | null): st
9
9
  export declare function getShellRuntimeUrl(): string;
10
10
  export declare function getRegistryUrl(): string;
11
11
  export declare function getConfiguredDashboard(profile?: EndpointProfile | null): string;
12
+ /** Public docs base URL for generated file headers and CLI hints. */
13
+ export declare function getDocsUrl(): string;
12
14
  export declare function getManifestApiBases(profile?: EndpointProfile | null): string[];
13
15
  export declare function getCandidateApiBases(profile?: EndpointProfile | null): string[];
14
16
  export declare function getCandidateAuthBases(profile?: EndpointProfile | null): string[];
@@ -100,6 +100,16 @@ export function getConfiguredDashboard(profile) {
100
100
  stripTrailingSlash(profile?.dashboardUrl ?? "") ||
101
101
  deriveSubdomain(getDuctBaseUrl(), "dash", 3004));
102
102
  }
103
+ /** Public docs base URL for generated file headers and CLI hints. */
104
+ export function getDocsUrl() {
105
+ const explicit = env("DUCT_DOCS_URL");
106
+ if (explicit)
107
+ return explicit;
108
+ const website = env("DUCT_WEBSITE_URL");
109
+ if (website)
110
+ return `${website}/docs`;
111
+ return "http://localhost:3005/docs";
112
+ }
103
113
  // ── Backward-compat helpers (used internally) ────────────────────
104
114
  export function getManifestApiBases(profile) {
105
115
  const configured = [
@@ -0,0 +1,33 @@
1
+ import type { DeeplinkTokenPayload, SessionContext } from "./types.js";
2
+ /** Unified onReceive result shape across all framework adapters. */
3
+ export interface DeeplinkReceiverResult {
4
+ /** Override the redirect URL (default: derived from config) */
5
+ redirectUrl?: string;
6
+ /** Additional data to include in JSON responses (Next adapter) */
7
+ data?: Record<string, unknown>;
8
+ /** Additional headers to set on the response */
9
+ headers?: Record<string, string>;
10
+ }
11
+ /**
12
+ * Build a redirect URL from a deeplink target route and token state.
13
+ * Replaces `[param]` segments and appends remaining state as query params.
14
+ */
15
+ export declare function buildDeeplinkRedirectUrl(targetRoute: string, state: Record<string, unknown>, baseUrl: string): string;
16
+ /** Build a minimal session context for a deeplink handoff. */
17
+ export declare function buildDeeplinkSession(sub: string, shellId: string): SessionContext;
18
+ /**
19
+ * Validate required JWT claims after verifyDeeplinkToken succeeds.
20
+ * Returns an error message when a required claim is missing, else null.
21
+ */
22
+ export declare function validateDeeplinkClaims(payload: DeeplinkTokenPayload): string | null;
23
+ /**
24
+ * Fire-and-forget callback to Duct confirming deeplink receipt.
25
+ * No-op when DUCT_API_KEY is unset.
26
+ */
27
+ export declare function confirmDeeplinkReceipt(options: {
28
+ deeplinkId: string;
29
+ shellId: string;
30
+ userId: string;
31
+ redirectUrl: string;
32
+ apiKey?: string;
33
+ }): void;
@@ -0,0 +1,77 @@
1
+ // ============================================================
2
+ // @duct/sdk — Shared deeplink receiver helpers
3
+ // Used by Next, Remix, Vite, and SvelteKit adapters.
4
+ // ============================================================
5
+ import { getActiveApiBase } from "./endpoints.js";
6
+ /**
7
+ * Build a redirect URL from a deeplink target route and token state.
8
+ * Replaces `[param]` segments and appends remaining state as query params.
9
+ */
10
+ export function buildDeeplinkRedirectUrl(targetRoute, state, baseUrl) {
11
+ let path = targetRoute;
12
+ const usedKeys = new Set();
13
+ for (const match of [...targetRoute.matchAll(/\[([^\]]+)\]/g)]) {
14
+ const paramName = match[1];
15
+ const value = state[paramName] ??
16
+ state[`${paramName}Id`] ??
17
+ state[`${paramName}_id`];
18
+ if (value !== undefined) {
19
+ path = path.replace(match[0], String(value));
20
+ usedKeys.add(paramName);
21
+ }
22
+ }
23
+ const queryEntries = Object.entries(state).filter(([key]) => !usedKeys.has(key) && state[key] !== undefined && state[key] !== null);
24
+ if (queryEntries.length > 0) {
25
+ const qs = new URLSearchParams(queryEntries.map(([k, v]) => [k, String(v)])).toString();
26
+ path += `?${qs}`;
27
+ }
28
+ const base = baseUrl.replace(/\/$/, "");
29
+ return `${base}${path}`;
30
+ }
31
+ /** Build a minimal session context for a deeplink handoff. */
32
+ export function buildDeeplinkSession(sub, shellId) {
33
+ return {
34
+ sessionId: `dl_${Date.now()}_${Math.random().toString(36).slice(2)}`,
35
+ shellId,
36
+ user: { id: sub },
37
+ isAgent: false,
38
+ messages: [],
39
+ createdAt: new Date().toISOString(),
40
+ updatedAt: new Date().toISOString(),
41
+ };
42
+ }
43
+ /**
44
+ * Validate required JWT claims after verifyDeeplinkToken succeeds.
45
+ * Returns an error message when a required claim is missing, else null.
46
+ */
47
+ export function validateDeeplinkClaims(payload) {
48
+ if (!payload.iss)
49
+ return "Token missing iss claim";
50
+ if (!payload.sub)
51
+ return "Token missing sub claim";
52
+ return null;
53
+ }
54
+ /**
55
+ * Fire-and-forget callback to Duct confirming deeplink receipt.
56
+ * No-op when DUCT_API_KEY is unset.
57
+ */
58
+ export function confirmDeeplinkReceipt(options) {
59
+ const ductApiKey = options.apiKey ?? process.env["DUCT_API_KEY"];
60
+ if (!ductApiKey)
61
+ return;
62
+ const ductApiBase = getActiveApiBase();
63
+ fetch(`${ductApiBase}/v1/deeplinks/${options.deeplinkId}/confirm`, {
64
+ method: "POST",
65
+ headers: {
66
+ "Content-Type": "application/json",
67
+ Authorization: `Bearer ${ductApiKey}`,
68
+ },
69
+ body: JSON.stringify({
70
+ shellId: options.shellId,
71
+ userId: options.userId,
72
+ redirectUrl: options.redirectUrl,
73
+ }),
74
+ }).catch((err) => {
75
+ console.warn("[Duct] Could not confirm receipt:", err.message);
76
+ });
77
+ }
package/dist/server.d.ts CHANGED
@@ -12,6 +12,8 @@ export { sendIntershellAction, sendIntershellQuery } from "./core/intershell.js"
12
12
  export type { IntershellClientOptions, IntershellMessage, IntershellActionResult, } from "./core/intershell.js";
13
13
  export { checkShellStatus } from "./core/status.js";
14
14
  export type { ShellStatus, ShellStatusWidget, CheckShellStatusOptions } from "./core/status.js";
15
+ export { buildDeeplinkRedirectUrl, buildDeeplinkSession, validateDeeplinkClaims, confirmDeeplinkReceipt, } from "./core/receiver.js";
16
+ export type { DeeplinkReceiverResult } from "./core/receiver.js";
15
17
  export { SHELL_PRESET_DIMENSIONS, DEFAULT_SHELL_PRESET, SHELL_PANEL_VIEWPORT_INSETS, resolveShellDimensions, fitShellPanelDimensions, } from "./core/types.js";
16
18
  export type { ShellPreset, ShellPanelViewportInsets } from "./core/types.js";
17
19
  export type { DuctConfig, DuctTokenPayload, DeeplinkTokenPayload, ActionManifest, ActionParam, RouteManifest, RouteParam, QueryParam, AuthSchema, AuthStrategy, DeeplinkDefinition, StateField, ShellManifest, ProductConfig, AgentPermissions, AgentPermissionLevel, WidgetConfig, SensitivityLevel, SessionContext, DuctAdapter, ReceiverOptions, } from "./core/types.js";
package/dist/server.js CHANGED
@@ -23,5 +23,7 @@ export { buildAction, checkActionPermission, buildActionSearchIndex, shouldDefer
23
23
  export { sendIntershellAction, sendIntershellQuery } from "./core/intershell.js";
24
24
  // Shell status check (server-side polling)
25
25
  export { checkShellStatus } from "./core/status.js";
26
+ // Shared deeplink receiver helpers (used by framework adapters)
27
+ export { buildDeeplinkRedirectUrl, buildDeeplinkSession, validateDeeplinkClaims, confirmDeeplinkReceipt, } from "./core/receiver.js";
26
28
  // Shell embed layout (presets + viewport fitting)
27
29
  export { SHELL_PRESET_DIMENSIONS, DEFAULT_SHELL_PRESET, SHELL_PANEL_VIEWPORT_INSETS, resolveShellDimensions, fitShellPanelDimensions, } from "./core/types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duct-sdk/sdk",
3
- "version": "0.3.12",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Duct SDK — A shell (like terminal) that knows when to talk, when to show, and when to hand off.",
6
6
  "main": "dist/index.js",
@@ -20,6 +20,7 @@
20
20
  "scripts": {
21
21
  "build": "tsc",
22
22
  "dev": "tsc --watch",
23
+ "test": "npm run build && node --test dist/cli/generators/config.test.js dist/cli/generators/token-route.test.js dist/cli/generators/wiring-snippets.test.js dist/cli/processors/curl-parser.test.js dist/cli/processors/integration-audit.test.js dist/cli/processors/verify-discovery.test.js",
23
24
  "verify:publish": "node scripts/verify-publish.mjs",
24
25
  "prepublishOnly": "npm run build && npm run verify:publish"
25
26
  },