@duct-sdk/sdk 0.5.11 → 0.5.13

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog — @duct-sdk/sdk
2
2
 
3
+ ## [0.5.13] — 2026-07-26
4
+
5
+ ### Added
6
+ - **Manifest `approval.stepUp` and `operatorNotifications`** schema defaults.
7
+ - **Token conformance vectors** (`fixtures/token-conformance-vectors.json`) and drift test.
8
+ - **`duct checkup` hosted-private upstream** detection for local `apiBaseUrl` against hosted profiles.
9
+ - **Root export guard** — `DuctSdkWrongEntrypointError` when React is not installed.
10
+
11
+ ## [0.5.12] — 2026-07-25
12
+
13
+ ### Added
14
+ - **`sideEffectsReviewAck`** — manifest action field (reason string) when declared `sideEffects` intentionally disagrees with HTTP-method-derived expectation. `duct push` blocks CI/non-TTY pushes until set; interactive push prompts and writes acks into `duct.config.ts`. No `--force` skip.
15
+
3
16
  ## [0.5.11] — 2026-07-22
4
17
 
5
18
  ### Added
package/TOKEN_SPEC.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Language-agnostic contract for verifying Duct tokens in any backend. This document is the source of truth for integrators who do not use the TypeScript SDK.
4
4
 
5
+ **Conformance:** [`fixtures/token-conformance-vectors.json`](./fixtures/token-conformance-vectors.json) plus `token.conformance.test.ts` in the SDK package.
6
+
7
+ **Clock skew:** allow ±60s on `exp`/`iat` unless your deployment documents otherwise.
8
+
9
+ **Rejection rules (HS256 delegated/deeplink):** reject `alg: none`, wrong `iss`/`aud`, expired `exp`, and missing required claims.
10
+
5
11
  > **Production recommendation:** use **Ed25519 / JWKS** for delegated tokens, deeplinks, and outcome receipts where offline verification matters. **HS256 with a shared `DUCT_SECRET_KEY`** remains supported for local development and migration — never ship the symmetric secret to third-party verifiers.
6
12
 
7
13
  ---
package/dist/cli/index.js CHANGED
@@ -23,6 +23,8 @@ import { fileURLToPath } from "node:url";
23
23
  import { readFileSync, existsSync } from "fs";
24
24
  import { DuctConfigSchema, crossValidateDuctConfig } from "../core/config.js";
25
25
  import { runAgentSafetyChecks } from "./agents/reviewer-agent.js";
26
+ import { formatSideEffectMismatchLines, findSideEffectReviewMismatches, resolveSideEffectReviewAcks, } from "./side-effects-review-push.js";
27
+ import { generateConfigFile } from "./generators/config.js";
26
28
  import { ConfigRuntimeReferenceError, loadDuctConfig, } from "./config-loader.js";
27
29
  import { computeManifestPrivilegeDiff, fetchLiveManifestConfig, formatManifestPrivilegeDiff, detectDashboardNetworkReverts, } from "./manifest-diff.js";
28
30
  import { applyActiveProfileEnvSync, ensureProfileExists, getDuctProfileFilePath, listProfileNames, readProfileFileSync, resolveActiveProfileName, resolveProfileUrls, setActiveProfileSync, } from "../core/profile.js";
@@ -333,7 +335,7 @@ program
333
335
  process.exit(1);
334
336
  }
335
337
  config = validation.data;
336
- const validated = validation.data;
338
+ let validated = validation.data;
337
339
  const crossIssues = crossValidateDuctConfig(validated);
338
340
  const crossErrors = crossIssues.filter((i) => i.severity === "error");
339
341
  if (crossErrors.length > 0) {
@@ -378,6 +380,33 @@ program
378
380
  }
379
381
  console.log(chalk.gray("\n Continuing with --yes.\n"));
380
382
  }
383
+ const interactiveReview = Boolean(process.stdin.isTTY) && process.env.CI !== "true";
384
+ const reviewMismatchesBefore = findSideEffectReviewMismatches(validated.actions);
385
+ if (reviewMismatchesBefore.length > 0) {
386
+ try {
387
+ const reviewedActions = await resolveSideEffectReviewAcks(validated.actions, {
388
+ interactive: interactiveReview,
389
+ });
390
+ if (reviewedActions !== validated.actions) {
391
+ validated = { ...validated, actions: reviewedActions };
392
+ config = { ...config, actions: reviewedActions };
393
+ const configPath = path.resolve(cwd, opts.config ?? "duct.config.ts");
394
+ await fs.writeFile(configPath, generateConfigFile(validated), "utf-8");
395
+ console.log(chalk.green("\n ✓ Wrote sideEffectsReviewAck reasons to duct.config.ts\n"));
396
+ }
397
+ }
398
+ catch (err) {
399
+ if (err instanceof Error && err.message === "side_effects_review_required") {
400
+ console.log(chalk.red("\n Push blocked — side-effect classification review required.\n"));
401
+ for (const line of formatSideEffectMismatchLines(reviewMismatchesBefore)) {
402
+ console.log(chalk.red(line));
403
+ }
404
+ console.log(chalk.gray("\n Add sideEffectsReviewAck with a reason on each listed action in duct.config.ts (no --force skip).\n"));
405
+ process.exit(1);
406
+ }
407
+ throw err;
408
+ }
409
+ }
381
410
  // Warn on weak DUCT_SECRET_KEY — must be ≥ 32 chars for adequate HMAC entropy
382
411
  const secretKey = process.env["DUCT_SECRET_KEY"];
383
412
  if (secretKey && secretKey.length < 32) {
@@ -774,6 +803,12 @@ program
774
803
  outputPaths,
775
804
  authDetection,
776
805
  });
806
+ const apiUrl = config.product?.apiBaseUrl ?? config.product?.baseUrl ?? '';
807
+ const { shouldWarnHostedPrivateUpstream, hostedPrivateUpstreamMessage } = await import('../core/hosted-upstream-check.js');
808
+ if (apiUrl && shouldWarnHostedPrivateUpstream(apiUrl)) {
809
+ console.log(chalk.red(` ✗ ${hostedPrivateUpstreamMessage(apiUrl)}\n`));
810
+ process.exit(1);
811
+ }
777
812
  printIntegrationAuditIssues(auditIssues);
778
813
  if (integrationAuditFailed(auditIssues)) {
779
814
  console.log(chalk.red(" ✗ Integration audit found blocking issues\n"));
@@ -0,0 +1,11 @@
1
+ import { type SideEffectReviewMismatch } from '@duct-sdk/contracts';
2
+ import type { ActionManifest } from '../core/types.js';
3
+ export declare function findSideEffectReviewMismatches(actions: ActionManifest[]): SideEffectReviewMismatch[];
4
+ export declare function formatSideEffectMismatchLines(mismatches: SideEffectReviewMismatch[]): string[];
5
+ /**
6
+ * Interactive: prompt for acknowledgment reasons and merge into actions.
7
+ * Non-interactive: throws with mismatch list (no --force escape hatch).
8
+ */
9
+ export declare function resolveSideEffectReviewAcks(actions: ActionManifest[], opts: {
10
+ interactive: boolean;
11
+ }): Promise<ActionManifest[]>;
@@ -0,0 +1,48 @@
1
+ import inquirer from 'inquirer';
2
+ import chalk from 'chalk';
3
+ import { collectSideEffectReviewMismatches, } from '@duct-sdk/contracts';
4
+ export function findSideEffectReviewMismatches(actions) {
5
+ return collectSideEffectReviewMismatches(actions.map((a) => ({
6
+ id: a.id,
7
+ method: a.method,
8
+ sideEffects: a.sideEffects,
9
+ sideEffectsReviewAck: a.sideEffectsReviewAck,
10
+ })));
11
+ }
12
+ export function formatSideEffectMismatchLines(mismatches) {
13
+ return mismatches.map((m) => ` • ${m.actionId} (${m.method}): declared sideEffects=${m.declared}, derived=${m.derived}`);
14
+ }
15
+ /**
16
+ * Interactive: prompt for acknowledgment reasons and merge into actions.
17
+ * Non-interactive: throws with mismatch list (no --force escape hatch).
18
+ */
19
+ export async function resolveSideEffectReviewAcks(actions, opts) {
20
+ let working = actions.map((a) => ({ ...a }));
21
+ let mismatches = findSideEffectReviewMismatches(working);
22
+ if (mismatches.length === 0)
23
+ return working;
24
+ console.log(chalk.yellow('\n Side-effect classification review:\n'));
25
+ for (const line of formatSideEffectMismatchLines(mismatches)) {
26
+ console.log(chalk.yellow(line));
27
+ }
28
+ console.log(chalk.gray('\n Declared sideEffects disagrees with the HTTP method expectation. Add sideEffectsReviewAck with a reason in duct.config.ts (reviewed in git).\n'));
29
+ if (!opts.interactive) {
30
+ throw new Error('side_effects_review_required');
31
+ }
32
+ for (const mismatch of mismatches) {
33
+ const { reason } = await inquirer.prompt([
34
+ {
35
+ type: 'input',
36
+ name: 'reason',
37
+ message: `Acknowledge ${mismatch.actionId} (declared=${mismatch.declared}, derived=${mismatch.derived}) — reason:`,
38
+ validate: (v) => (v?.trim().length >= 8 ? true : 'Enter at least 8 characters'),
39
+ },
40
+ ]);
41
+ working = working.map((a) => a.id === mismatch.actionId ? { ...a, sideEffectsReviewAck: reason.trim() } : a);
42
+ }
43
+ mismatches = findSideEffectReviewMismatches(working);
44
+ if (mismatches.length > 0) {
45
+ throw new Error('side_effects_review_incomplete');
46
+ }
47
+ return working;
48
+ }
@@ -184,6 +184,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
184
184
  path: z.ZodString;
185
185
  agentAccessible: z.ZodBoolean;
186
186
  sideEffects: z.ZodBoolean;
187
+ sideEffectsReviewAck: z.ZodOptional<z.ZodString>;
187
188
  sensitivityLevel: z.ZodEnum<["none", "low", "medium", "high", "critical"]>;
188
189
  params: z.ZodDefault<z.ZodArray<z.ZodObject<{
189
190
  name: z.ZodString;
@@ -270,6 +271,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
270
271
  sideEffects: boolean;
271
272
  sensitivityLevel: "none" | "low" | "medium" | "high" | "critical";
272
273
  requiresAuth: boolean;
274
+ sideEffectsReviewAck?: string | undefined;
273
275
  responseSchema?: Record<string, unknown> | undefined;
274
276
  inputSchema?: Record<string, unknown> | undefined;
275
277
  rateLimit?: number | undefined;
@@ -315,6 +317,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
315
317
  description?: string | undefined;
316
318
  schema?: Record<string, unknown> | undefined;
317
319
  }[] | undefined;
320
+ sideEffectsReviewAck?: string | undefined;
318
321
  responseSchema?: Record<string, unknown> | undefined;
319
322
  inputSchema?: Record<string, unknown> | undefined;
320
323
  rateLimit?: number | undefined;
@@ -570,14 +573,57 @@ export declare const DuctConfigSchema: z.ZodObject<{
570
573
  consentCallback: z.ZodOptional<z.ZodString>;
571
574
  identityUrl: z.ZodOptional<z.ZodString>;
572
575
  secret: z.ZodOptional<z.ZodString>;
576
+ deeplinkCallback: z.ZodOptional<z.ZodString>;
577
+ eventStream: z.ZodOptional<z.ZodString>;
573
578
  }, "strip", z.ZodTypeAny, {
574
579
  consentCallback?: string | undefined;
575
580
  identityUrl?: string | undefined;
576
581
  secret?: string | undefined;
582
+ deeplinkCallback?: string | undefined;
583
+ eventStream?: string | undefined;
577
584
  }, {
578
585
  consentCallback?: string | undefined;
579
586
  identityUrl?: string | undefined;
580
587
  secret?: string | undefined;
588
+ deeplinkCallback?: string | undefined;
589
+ eventStream?: string | undefined;
590
+ }>>;
591
+ approval: z.ZodOptional<z.ZodObject<{
592
+ stepUp: z.ZodDefault<z.ZodOptional<z.ZodObject<{
593
+ minSensitivity: z.ZodDefault<z.ZodOptional<z.ZodEnum<["none", "low", "medium", "high", "critical"]>>>;
594
+ requireForSideEffects: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
595
+ sideEffectsMinSensitivity: z.ZodDefault<z.ZodOptional<z.ZodEnum<["none", "low", "medium", "high", "critical"]>>>;
596
+ }, "strip", z.ZodTypeAny, {
597
+ minSensitivity: "none" | "low" | "medium" | "high" | "critical";
598
+ requireForSideEffects: boolean;
599
+ sideEffectsMinSensitivity: "none" | "low" | "medium" | "high" | "critical";
600
+ }, {
601
+ minSensitivity?: "none" | "low" | "medium" | "high" | "critical" | undefined;
602
+ requireForSideEffects?: boolean | undefined;
603
+ sideEffectsMinSensitivity?: "none" | "low" | "medium" | "high" | "critical" | undefined;
604
+ }>>>;
605
+ }, "strip", z.ZodTypeAny, {
606
+ stepUp: {
607
+ minSensitivity: "none" | "low" | "medium" | "high" | "critical";
608
+ requireForSideEffects: boolean;
609
+ sideEffectsMinSensitivity: "none" | "low" | "medium" | "high" | "critical";
610
+ };
611
+ }, {
612
+ stepUp?: {
613
+ minSensitivity?: "none" | "low" | "medium" | "high" | "critical" | undefined;
614
+ requireForSideEffects?: boolean | undefined;
615
+ sideEffectsMinSensitivity?: "none" | "low" | "medium" | "high" | "critical" | undefined;
616
+ } | undefined;
617
+ }>>;
618
+ operatorNotifications: z.ZodOptional<z.ZodObject<{
619
+ approverEmails: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
620
+ confirmationReminderLeadMinutes: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
621
+ }, "strip", z.ZodTypeAny, {
622
+ approverEmails: string[];
623
+ confirmationReminderLeadMinutes?: number | null | undefined;
624
+ }, {
625
+ approverEmails?: string[] | undefined;
626
+ confirmationReminderLeadMinutes?: number | null | undefined;
581
627
  }>>;
582
628
  }, "strip", z.ZodTypeAny, {
583
629
  auth: {
@@ -648,6 +694,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
648
694
  sideEffects: boolean;
649
695
  sensitivityLevel: "none" | "low" | "medium" | "high" | "critical";
650
696
  requiresAuth: boolean;
697
+ sideEffectsReviewAck?: string | undefined;
651
698
  responseSchema?: Record<string, unknown> | undefined;
652
699
  inputSchema?: Record<string, unknown> | undefined;
653
700
  rateLimit?: number | undefined;
@@ -747,6 +794,19 @@ export declare const DuctConfigSchema: z.ZodObject<{
747
794
  consentCallback?: string | undefined;
748
795
  identityUrl?: string | undefined;
749
796
  secret?: string | undefined;
797
+ deeplinkCallback?: string | undefined;
798
+ eventStream?: string | undefined;
799
+ } | undefined;
800
+ approval?: {
801
+ stepUp: {
802
+ minSensitivity: "none" | "low" | "medium" | "high" | "critical";
803
+ requireForSideEffects: boolean;
804
+ sideEffectsMinSensitivity: "none" | "low" | "medium" | "high" | "critical";
805
+ };
806
+ } | undefined;
807
+ operatorNotifications?: {
808
+ approverEmails: string[];
809
+ confirmationReminderLeadMinutes?: number | null | undefined;
750
810
  } | undefined;
751
811
  }, {
752
812
  auth: {
@@ -828,6 +888,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
828
888
  description?: string | undefined;
829
889
  schema?: Record<string, unknown> | undefined;
830
890
  }[] | undefined;
891
+ sideEffectsReviewAck?: string | undefined;
831
892
  responseSchema?: Record<string, unknown> | undefined;
832
893
  inputSchema?: Record<string, unknown> | undefined;
833
894
  rateLimit?: number | undefined;
@@ -916,6 +977,19 @@ export declare const DuctConfigSchema: z.ZodObject<{
916
977
  consentCallback?: string | undefined;
917
978
  identityUrl?: string | undefined;
918
979
  secret?: string | undefined;
980
+ deeplinkCallback?: string | undefined;
981
+ eventStream?: string | undefined;
982
+ } | undefined;
983
+ approval?: {
984
+ stepUp?: {
985
+ minSensitivity?: "none" | "low" | "medium" | "high" | "critical" | undefined;
986
+ requireForSideEffects?: boolean | undefined;
987
+ sideEffectsMinSensitivity?: "none" | "low" | "medium" | "high" | "critical" | undefined;
988
+ } | undefined;
989
+ } | undefined;
990
+ operatorNotifications?: {
991
+ approverEmails?: string[] | undefined;
992
+ confirmationReminderLeadMinutes?: number | null | undefined;
919
993
  } | undefined;
920
994
  }>;
921
995
  export type ValidatedDuctConfig = z.infer<typeof DuctConfigSchema>;
@@ -2,7 +2,7 @@
2
2
  // @duct/sdk — Config Definition and Validation
3
3
  // ============================================================
4
4
  import { z } from "zod";
5
- import { ActionManifestSchema, iso8601Schema, } from "@duct-sdk/contracts";
5
+ import { ActionManifestSchema, iso8601Schema, SensitivityLevelSchema, } from "@duct-sdk/contracts";
6
6
  export { ActionManifestSchema, ManifestActionSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "@duct-sdk/contracts";
7
7
  // ----------------------------------------------------------------
8
8
  // Zod Schemas
@@ -132,6 +132,24 @@ const WebhooksConfigSchema = z.object({
132
132
  consentCallback: z.string().url().optional(),
133
133
  identityUrl: z.string().url().optional(),
134
134
  secret: z.string().optional(),
135
+ deeplinkCallback: z.string().url().optional(),
136
+ eventStream: z.string().url().optional(),
137
+ });
138
+ const ApprovalStepUpConfigSchema = z.object({
139
+ minSensitivity: SensitivityLevelSchema.optional().default('high'),
140
+ requireForSideEffects: z.boolean().optional().default(true),
141
+ sideEffectsMinSensitivity: SensitivityLevelSchema.optional().default('medium'),
142
+ });
143
+ const ApprovalConfigSchema = z.object({
144
+ stepUp: ApprovalStepUpConfigSchema.optional().default({
145
+ minSensitivity: 'high',
146
+ requireForSideEffects: true,
147
+ sideEffectsMinSensitivity: 'medium',
148
+ }),
149
+ });
150
+ const OperatorNotificationsConfigSchema = z.object({
151
+ approverEmails: z.array(z.string().email()).optional().default([]),
152
+ confirmationReminderLeadMinutes: z.number().int().positive().nullable().optional(),
135
153
  });
136
154
  const WidgetConfigSchema = z.object({
137
155
  primaryColor: z.string().optional(),
@@ -189,6 +207,8 @@ export const DuctConfigSchema = z.object({
189
207
  registry_visibility: z.enum(['public', 'private']).optional().default('private'),
190
208
  intershell_enabled: z.boolean().optional().default(false),
191
209
  webhooks: WebhooksConfigSchema.optional(),
210
+ approval: ApprovalConfigSchema.optional(),
211
+ operatorNotifications: OperatorNotificationsConfigSchema.optional(),
192
212
  });
193
213
  function zodIssuesToValidationIssues(errors) {
194
214
  return errors.map((e) => ({
@@ -0,0 +1,3 @@
1
+ export declare function isPrivateOrLocalProductUrl(url: string): boolean;
2
+ export declare function hostedPrivateUpstreamMessage(apiUrl: string): string;
3
+ export declare function shouldWarnHostedPrivateUpstream(apiUrl: string): boolean;
@@ -0,0 +1,35 @@
1
+ import { isLocalDuctProfile, isLocalhostUrl } from './endpoint-guard.js';
2
+ const PRIVATE_HOST_PATTERNS = [
3
+ /^10\./,
4
+ /^192\.168\./,
5
+ /^172\.(1[6-9]|2\d|3[0-1])\./,
6
+ /^127\./,
7
+ /^0\./,
8
+ /^169\.254\./,
9
+ ];
10
+ export function isPrivateOrLocalProductUrl(url) {
11
+ if (!url.trim())
12
+ return false;
13
+ if (isLocalhostUrl(url))
14
+ return true;
15
+ try {
16
+ const host = new URL(url).hostname.toLowerCase();
17
+ return PRIVATE_HOST_PATTERNS.some((re) => re.test(host));
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ }
23
+ export function hostedPrivateUpstreamMessage(apiUrl) {
24
+ return (`Product API URL ${apiUrl} points at a private or local address while using hosted Duct. ` +
25
+ 'Hosted Duct cannot reach your machine directly. Expose your dev API with an HTTP tunnel, ' +
26
+ 'set product.apiBaseUrl to the public tunnel URL, and run checkup again. ' +
27
+ 'See /docs/local-development-hosted');
28
+ }
29
+ export function shouldWarnHostedPrivateUpstream(apiUrl) {
30
+ if (isLocalDuctProfile())
31
+ return false;
32
+ if ((process.env.DUCT_ALLOW_LOCALHOST ?? '').trim().toLowerCase() === 'true')
33
+ return false;
34
+ return isPrivateOrLocalProductUrl(apiUrl);
35
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ describe('sdk entrypoints', () => {
4
+ it('server entry loads without requiring the root React bundle', async () => {
5
+ const mod = await import('../server.js');
6
+ assert.equal(typeof mod.verifyDuctToken, 'function');
7
+ });
8
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { readFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, } from "./token.js";
7
+ const fixturePath = path.join(path.dirname(fileURLToPath(import.meta.url)), "../../fixtures/token-conformance-vectors.json");
8
+ describe("token conformance vectors", () => {
9
+ it("matches fixture mint + verify for delegated and deeplink", async () => {
10
+ const raw = JSON.parse(await readFile(fixturePath, "utf8"));
11
+ const { token } = await generateDuctToken({
12
+ secretKey: raw.secret,
13
+ shellId: raw.shellId,
14
+ userSession: { id: "user_42", email: "user@example.com" },
15
+ expirySeconds: 300,
16
+ allowedActions: ["get_orders"],
17
+ });
18
+ const delegated = await verifyDuctToken(token, {
19
+ secretKey: raw.secret,
20
+ expectedShellId: raw.shellId,
21
+ });
22
+ assert.equal(delegated.valid, true);
23
+ const deeplink = await generateDeeplinkToken({
24
+ secretKey: raw.secret,
25
+ shellId: raw.shellId,
26
+ deeplinkId: "view_order",
27
+ state: { orderId: "99" },
28
+ expirySeconds: 300,
29
+ });
30
+ const dl = await verifyDeeplinkToken(deeplink.token, {
31
+ secretKey: raw.secret,
32
+ expectedShellId: raw.shellId,
33
+ });
34
+ assert.equal(dl.valid, true);
35
+ for (const bad of raw.reject) {
36
+ const result = await verifyDuctToken(bad.token, {
37
+ secretKey: raw.secret,
38
+ expectedShellId: raw.shellId,
39
+ });
40
+ assert.equal(result.valid, false, `expected reject for ${bad.id}`);
41
+ }
42
+ });
43
+ });
@@ -101,6 +101,11 @@ export interface ActionManifest {
101
101
  agentAccessible: boolean;
102
102
  /** Whether this action mutates state (POST/PUT/PATCH/DELETE) */
103
103
  sideEffects: boolean;
104
+ /**
105
+ * Free-text reason when `sideEffects` intentionally disagrees with the HTTP-method-derived expectation.
106
+ * Required for push when declared ≠ derived (stored in git / manifest hash).
107
+ */
108
+ sideEffectsReviewAck?: string;
104
109
  /** Data sensitivity classification */
105
110
  sensitivityLevel: SensitivityLevel;
106
111
  /** Input parameters */
@@ -471,6 +476,25 @@ export interface DataModelEntity {
471
476
  export interface DataModel {
472
477
  entities: DataModelEntity[];
473
478
  }
479
+ /** Human approval policy — step-up password re-entry before operator approves. */
480
+ export interface ApprovalStepUpConfig {
481
+ /** Minimum sensitivity that always requires step-up (default high → high + critical). */
482
+ minSensitivity?: SensitivityLevel;
483
+ /** When true, side-effect actions can require step-up per sideEffectsMinSensitivity. */
484
+ requireForSideEffects?: boolean;
485
+ /** Side-effect actions at or above this level require step-up (default medium). */
486
+ sideEffectsMinSensitivity?: SensitivityLevel;
487
+ }
488
+ export interface ApprovalConfig {
489
+ stepUp?: ApprovalStepUpConfig;
490
+ }
491
+ /** Operator notifications for pending confirmations (dashboard-configured). */
492
+ export interface OperatorNotificationsConfig {
493
+ /** Email addresses to notify when a confirmation is created. */
494
+ approverEmails?: string[];
495
+ /** Minutes before expiry to send one reminder; omit or null = off. */
496
+ confirmationReminderLeadMinutes?: number | null;
497
+ }
474
498
  export interface DuctConfig {
475
499
  /** Shell ID assigned by Duct cloud */
476
500
  shellId: string;
@@ -500,6 +524,10 @@ export interface DuctConfig {
500
524
  intershell_enabled?: boolean;
501
525
  /** Identity/consent webhook wiring — required for cross-shell protected actions. */
502
526
  webhooks?: WebhooksConfig;
527
+ /** Gateway approval policy (step-up thresholds). */
528
+ approval?: ApprovalConfig;
529
+ /** Pending-confirmation operator notifications. */
530
+ operatorNotifications?: OperatorNotificationsConfig;
503
531
  }
504
532
  /**
505
533
  * Identity/consent webhook wiring for this shell. Read dynamically from manifest JSON
@@ -514,6 +542,8 @@ export interface WebhooksConfig {
514
542
  identityUrl?: string;
515
543
  /** Shared webhook signing secret (whsec_…) used to verify identity vouches + signed callbacks. */
516
544
  secret?: string;
545
+ deeplinkCallback?: string;
546
+ eventStream?: string;
517
547
  }
518
548
  export interface ShellManifest {
519
549
  shellId: string;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ export declare class DuctSdkWrongEntrypointError extends Error {
2
+ readonly name = "DuctSdkWrongEntrypointError";
3
+ constructor();
4
+ }
1
5
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
2
6
  export type { ValidatedDuctConfig, ManifestAction, ErrorEnvelope, ConfirmationState } from "./core/config.js";
3
7
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
package/dist/index.js CHANGED
@@ -5,6 +5,21 @@
5
5
  // instead. The root export includes React adapters which crash
6
6
  // runtimes where React is not installed (e.g. plain Express).
7
7
  // ============================================================
8
+ import { createRequire } from 'node:module';
9
+ const require = createRequire(import.meta.url);
10
+ export class DuctSdkWrongEntrypointError extends Error {
11
+ name = 'DuctSdkWrongEntrypointError';
12
+ constructor() {
13
+ super('Import @duct-sdk/sdk/server in Node.js backends (Express, Fastify, etc.). ' +
14
+ 'The package root export includes React adapters and requires react/react-dom.');
15
+ }
16
+ }
17
+ try {
18
+ require.resolve('react');
19
+ }
20
+ catch {
21
+ throw new DuctSdkWrongEntrypointError();
22
+ }
8
23
  // Core config
9
24
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
10
25
  // Token utilities
@@ -0,0 +1,26 @@
1
+ {
2
+ "version": 1,
3
+ "secret": "conformance-test-secret-32chars!!",
4
+ "shellId": "shell_conformance_test",
5
+ "delegated": {
6
+ "mint": {
7
+ "userSession": { "id": "user_42", "email": "user@example.com" },
8
+ "expirySeconds": 300,
9
+ "allowedActions": ["get_orders"]
10
+ },
11
+ "verify": {
12
+ "expectedShellId": "shell_conformance_test"
13
+ }
14
+ },
15
+ "deeplink": {
16
+ "mint": {
17
+ "deeplinkId": "view_order",
18
+ "state": { "orderId": "99" },
19
+ "expirySeconds": 300
20
+ }
21
+ },
22
+ "reject": [
23
+ { "id": "wrong_iss", "description": "issuer does not match shell", "token": "eyJhbGciOiJIUzI1NiJ9.eyJ0eXBlIjoiZHVjdF9kZWxlZ2F0ZWQiLCJpc3MiOiJzaGVsbF93cm9uZyIsInN1YiI6InVzZXJfNDIiLCJzZXNzaW9uIjp7fSwiaWF0IjoxNzAwMDAwMDAwLCJleHAiOjQxMDI0NDQ4MDB9.invalid" },
24
+ { "id": "alg_none", "description": "alg none must be rejected", "token": "eyJhbGciOiJub25lIn0.eyJ0eXBlIjoiZHVjdF9kZWxlZ2F0ZWQifQ." }
25
+ ]
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duct-sdk/sdk",
3
- "version": "0.5.11",
3
+ "version": "0.5.13",
4
4
  "type": "module",
5
5
  "description": "Duct SDK — manifest, CLI, and embed components for permissioned human and agent access to your product APIs.",
6
6
  "main": "dist/index.js",
@@ -67,6 +67,7 @@
67
67
  "files": [
68
68
  "dist",
69
69
  "assets",
70
+ "fixtures",
70
71
  "README.md",
71
72
  "CHANGELOG.md",
72
73
  "TOKEN_SPEC.md"