@duct-sdk/sdk 0.4.0 → 0.4.1
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 +7 -0
- package/dist/cli/agents/pipeline.js +2 -0
- package/dist/cli/generators/config.js +6 -0
- package/dist/core/config.d.ts +10 -0
- package/dist/core/config.js +6 -0
- package/dist/core/login-handoff.d.ts +41 -0
- package/dist/core/login-handoff.js +133 -0
- package/dist/core/login-handoff.test.d.ts +1 -0
- package/dist/core/login-handoff.test.js +31 -0
- package/dist/core/types.d.ts +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Public release notes for the Duct SDK. Versioning follows [semver](https://semver.org).
|
|
4
4
|
|
|
5
|
+
## [0.4.1] — 2026-07-03
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **`auth.loginRoutePath` and `auth.loginDeeplinkId`** — optional manifest fields that tell the shell where to send unauthenticated users before invoking `requiresAuth` actions.
|
|
9
|
+
- **`core/login-handoff.ts`** — `detectLoginRoutePath()`, `enrichAuthLoginHandoff()`, and `resolveLoginHandoff()` helpers shared with codegen.
|
|
10
|
+
- **`duct init` auto-wiring** — pipeline sets `loginRoutePath` (and `loginDeeplinkId` when a matching deeplink exists) from discovered routes.
|
|
11
|
+
|
|
5
12
|
## [0.4.0] — 2026-07-02
|
|
6
13
|
|
|
7
14
|
### Added
|
|
@@ -12,6 +12,7 @@ import { applyDeterministicRules } from "../processors/postprocess.js";
|
|
|
12
12
|
import { verifyDiscoveryAgainstFilesystem } from "../processors/verify-discovery.js";
|
|
13
13
|
import { parseOpenApiSpec } from "../processors/openapi-parser.js";
|
|
14
14
|
import { parseCurlCollection } from "../processors/curl-parser.js";
|
|
15
|
+
import { enrichAuthLoginHandoff } from "../../core/login-handoff.js";
|
|
15
16
|
// ----------------------------------------------------------------
|
|
16
17
|
// Default emitter (uses Node EventEmitter)
|
|
17
18
|
// ----------------------------------------------------------------
|
|
@@ -400,6 +401,7 @@ export async function runAgentPipeline(sandboxFs, opts = {}) {
|
|
|
400
401
|
}
|
|
401
402
|
}
|
|
402
403
|
const durationMs = Date.now() - startTime;
|
|
404
|
+
auth = enrichAuthLoginHandoff(auth, routes, deeplinks);
|
|
403
405
|
const pipelineResult = {
|
|
404
406
|
routes,
|
|
405
407
|
actions,
|
|
@@ -146,6 +146,12 @@ function generateAuth(auth, indentSpaces) {
|
|
|
146
146
|
if (auth.customClaims && Object.keys(auth.customClaims).length > 0) {
|
|
147
147
|
lines.push(`${pad} customClaims: ${jsonValue(auth.customClaims, indentSpaces + 2)},`);
|
|
148
148
|
}
|
|
149
|
+
if (auth.loginDeeplinkId) {
|
|
150
|
+
lines.push(`${pad} loginDeeplinkId: ${JSON.stringify(auth.loginDeeplinkId)},`);
|
|
151
|
+
}
|
|
152
|
+
if (auth.loginRoutePath) {
|
|
153
|
+
lines.push(`${pad} loginRoutePath: ${JSON.stringify(auth.loginRoutePath)},`);
|
|
154
|
+
}
|
|
149
155
|
return `auth: {\n${lines.join("\n")}\n${pad}},`;
|
|
150
156
|
}
|
|
151
157
|
function generateDeeplinks(deeplinks, indentSpaces) {
|
package/dist/core/config.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
31
31
|
tokenExpirySeconds: z.ZodDefault<z.ZodNumber>;
|
|
32
32
|
tokenEndpoint: z.ZodOptional<z.ZodString>;
|
|
33
33
|
customClaims: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
34
|
+
loginDeeplinkId: z.ZodOptional<z.ZodString>;
|
|
35
|
+
loginRoutePath: z.ZodOptional<z.ZodString>;
|
|
34
36
|
}, "strip", z.ZodTypeAny, {
|
|
35
37
|
strategy: "none" | "nextauth" | "clerk" | "auth0" | "custom-jwt" | "session-cookie" | "unknown";
|
|
36
38
|
sessionFields: string[];
|
|
@@ -38,6 +40,8 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
38
40
|
tokenExpirySeconds: number;
|
|
39
41
|
tokenEndpoint?: string | undefined;
|
|
40
42
|
customClaims?: Record<string, string> | undefined;
|
|
43
|
+
loginDeeplinkId?: string | undefined;
|
|
44
|
+
loginRoutePath?: string | undefined;
|
|
41
45
|
}, {
|
|
42
46
|
strategy: "none" | "nextauth" | "clerk" | "auth0" | "custom-jwt" | "session-cookie" | "unknown";
|
|
43
47
|
guestAllowed: boolean;
|
|
@@ -45,6 +49,8 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
45
49
|
tokenExpirySeconds?: number | undefined;
|
|
46
50
|
tokenEndpoint?: string | undefined;
|
|
47
51
|
customClaims?: Record<string, string> | undefined;
|
|
52
|
+
loginDeeplinkId?: string | undefined;
|
|
53
|
+
loginRoutePath?: string | undefined;
|
|
48
54
|
}>;
|
|
49
55
|
routes: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
50
56
|
path: z.ZodString;
|
|
@@ -361,6 +367,8 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
361
367
|
tokenExpirySeconds: number;
|
|
362
368
|
tokenEndpoint?: string | undefined;
|
|
363
369
|
customClaims?: Record<string, string> | undefined;
|
|
370
|
+
loginDeeplinkId?: string | undefined;
|
|
371
|
+
loginRoutePath?: string | undefined;
|
|
364
372
|
};
|
|
365
373
|
shellId: string;
|
|
366
374
|
product: {
|
|
@@ -468,6 +476,8 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
468
476
|
tokenExpirySeconds?: number | undefined;
|
|
469
477
|
tokenEndpoint?: string | undefined;
|
|
470
478
|
customClaims?: Record<string, string> | undefined;
|
|
479
|
+
loginDeeplinkId?: string | undefined;
|
|
480
|
+
loginRoutePath?: string | undefined;
|
|
471
481
|
};
|
|
472
482
|
shellId: string;
|
|
473
483
|
product: {
|
package/dist/core/config.js
CHANGED
|
@@ -91,6 +91,12 @@ const AuthSchemaSchema = z.object({
|
|
|
91
91
|
tokenExpirySeconds: z.number().positive().default(60),
|
|
92
92
|
tokenEndpoint: z.string().url().optional(),
|
|
93
93
|
customClaims: z.record(z.string()).optional(),
|
|
94
|
+
loginDeeplinkId: z
|
|
95
|
+
.string()
|
|
96
|
+
.min(1)
|
|
97
|
+
.regex(/^[a-z_][a-z0-9_]*$/, "loginDeeplinkId must be snake_case")
|
|
98
|
+
.optional(),
|
|
99
|
+
loginRoutePath: z.string().min(1).startsWith("/").optional(),
|
|
94
100
|
});
|
|
95
101
|
const StateFieldSchema = z.object({
|
|
96
102
|
key: z.string().min(1),
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface LoginRouteLike {
|
|
2
|
+
path: string;
|
|
3
|
+
}
|
|
4
|
+
export interface LoginDeeplinkLike {
|
|
5
|
+
id: string;
|
|
6
|
+
pathTemplate?: string;
|
|
7
|
+
targetRoute?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LoginAuthConfig {
|
|
10
|
+
guestAllowed?: boolean;
|
|
11
|
+
loginDeeplinkId?: string;
|
|
12
|
+
loginRoutePath?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface LoginHandoffManifest {
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
auth?: LoginAuthConfig;
|
|
17
|
+
deeplinks?: LoginDeeplinkLike[];
|
|
18
|
+
routes?: LoginRouteLike[];
|
|
19
|
+
}
|
|
20
|
+
export interface LoginHandoffTarget {
|
|
21
|
+
deeplinkId: string;
|
|
22
|
+
url: string;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const DEFAULT_LOGIN_HANDOFF_MESSAGE = "You'll need to sign in first \u2014 I'll take you there now.";
|
|
26
|
+
/** Normalize dynamic route patterns to a static path prefix for navigation. */
|
|
27
|
+
export declare function normalizeRoutePathForLogin(path: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Pick the best login route path from a manifest route inventory.
|
|
30
|
+
* Used by `duct init` to populate `auth.loginRoutePath`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function detectLoginRoutePath(routes: LoginRouteLike[]): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve where the shell should send an unauthenticated user to sign in.
|
|
35
|
+
* Priority: explicit deeplink id → explicit route path → deeplink heuristic → route heuristic.
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveLoginHandoff(manifest: LoginHandoffManifest | null | undefined): LoginHandoffTarget | null;
|
|
38
|
+
/** True when the shell should treat the caller as unauthenticated. */
|
|
39
|
+
export declare function shellNeedsUserToken(manifest: LoginHandoffManifest | null | undefined, userToken?: string | null): boolean;
|
|
40
|
+
/** Attach login handoff fields discovered from routes/deeplinks during init. */
|
|
41
|
+
export declare function enrichAuthLoginHandoff<T extends LoginAuthConfig>(auth: T, routes: LoginRouteLike[], deeplinks?: LoginDeeplinkLike[]): T;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// Login handoff — resolve where unauthenticated shell users sign in
|
|
3
|
+
// ============================================================
|
|
4
|
+
/** Route path segments that commonly represent a sign-in page. */
|
|
5
|
+
const LOGIN_ROUTE_RE = /^\/(login|signin|sign-in|auth\/signin|auth\/login|account\/login)(\/|$)/i;
|
|
6
|
+
const LOGIN_ID_RE = /login|sign[_-]?in/i;
|
|
7
|
+
export const DEFAULT_LOGIN_HANDOFF_MESSAGE = "You'll need to sign in first — I'll take you there now.";
|
|
8
|
+
/** Normalize dynamic route patterns to a static path prefix for navigation. */
|
|
9
|
+
export function normalizeRoutePathForLogin(path) {
|
|
10
|
+
const withoutQuery = path.split("?")[0] ?? path;
|
|
11
|
+
const staticPrefix = withoutQuery.split("[")[0].split(":")[0];
|
|
12
|
+
const trimmed = staticPrefix.replace(/\/+$/, "");
|
|
13
|
+
if (!trimmed)
|
|
14
|
+
return "/";
|
|
15
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
16
|
+
}
|
|
17
|
+
function isLoginPath(path) {
|
|
18
|
+
return LOGIN_ROUTE_RE.test(normalizeRoutePathForLogin(path));
|
|
19
|
+
}
|
|
20
|
+
function buildHandoffUrl(baseUrl, path) {
|
|
21
|
+
const trimmed = path.trim();
|
|
22
|
+
if (!trimmed)
|
|
23
|
+
return null;
|
|
24
|
+
if (/^https?:\/\//i.test(trimmed))
|
|
25
|
+
return trimmed;
|
|
26
|
+
if (trimmed.startsWith("/"))
|
|
27
|
+
return trimmed;
|
|
28
|
+
if (baseUrl) {
|
|
29
|
+
try {
|
|
30
|
+
return new URL(trimmed, baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`).pathname;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Pick the best login route path from a manifest route inventory.
|
|
40
|
+
* Used by `duct init` to populate `auth.loginRoutePath`.
|
|
41
|
+
*/
|
|
42
|
+
export function detectLoginRoutePath(routes) {
|
|
43
|
+
for (const route of routes) {
|
|
44
|
+
if (!route.path)
|
|
45
|
+
continue;
|
|
46
|
+
const normalized = normalizeRoutePathForLogin(route.path);
|
|
47
|
+
if (isLoginPath(normalized))
|
|
48
|
+
return normalized;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve where the shell should send an unauthenticated user to sign in.
|
|
54
|
+
* Priority: explicit deeplink id → explicit route path → deeplink heuristic → route heuristic.
|
|
55
|
+
*/
|
|
56
|
+
export function resolveLoginHandoff(manifest) {
|
|
57
|
+
if (!manifest)
|
|
58
|
+
return null;
|
|
59
|
+
const baseUrl = manifest.baseUrl;
|
|
60
|
+
const auth = manifest.auth;
|
|
61
|
+
const explicitDlId = auth?.loginDeeplinkId?.trim();
|
|
62
|
+
if (explicitDlId) {
|
|
63
|
+
const dl = manifest.deeplinks?.find((d) => d.id === explicitDlId);
|
|
64
|
+
const path = dl?.pathTemplate ?? dl?.targetRoute;
|
|
65
|
+
const url = path ? buildHandoffUrl(baseUrl, path) : null;
|
|
66
|
+
if (url) {
|
|
67
|
+
return {
|
|
68
|
+
deeplinkId: explicitDlId,
|
|
69
|
+
url,
|
|
70
|
+
message: DEFAULT_LOGIN_HANDOFF_MESSAGE,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const explicitRoute = auth?.loginRoutePath?.trim();
|
|
75
|
+
if (explicitRoute) {
|
|
76
|
+
const url = buildHandoffUrl(baseUrl, normalizeRoutePathForLogin(explicitRoute));
|
|
77
|
+
if (url) {
|
|
78
|
+
return {
|
|
79
|
+
deeplinkId: explicitDlId ?? "login_page",
|
|
80
|
+
url,
|
|
81
|
+
message: DEFAULT_LOGIN_HANDOFF_MESSAGE,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const dl of manifest.deeplinks ?? []) {
|
|
86
|
+
const path = dl.pathTemplate ?? dl.targetRoute ?? "";
|
|
87
|
+
if (LOGIN_ID_RE.test(dl.id) || isLoginPath(path)) {
|
|
88
|
+
const url = buildHandoffUrl(baseUrl, path);
|
|
89
|
+
if (url) {
|
|
90
|
+
return {
|
|
91
|
+
deeplinkId: dl.id,
|
|
92
|
+
url,
|
|
93
|
+
message: DEFAULT_LOGIN_HANDOFF_MESSAGE,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const route of manifest.routes ?? []) {
|
|
99
|
+
if (!route.path || !isLoginPath(route.path))
|
|
100
|
+
continue;
|
|
101
|
+
const url = buildHandoffUrl(baseUrl, normalizeRoutePathForLogin(route.path));
|
|
102
|
+
if (url) {
|
|
103
|
+
return {
|
|
104
|
+
deeplinkId: "login_page",
|
|
105
|
+
url,
|
|
106
|
+
message: DEFAULT_LOGIN_HANDOFF_MESSAGE,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
/** True when the shell should treat the caller as unauthenticated. */
|
|
113
|
+
export function shellNeedsUserToken(manifest, userToken) {
|
|
114
|
+
if (manifest?.auth?.guestAllowed === true)
|
|
115
|
+
return false;
|
|
116
|
+
return !userToken?.trim();
|
|
117
|
+
}
|
|
118
|
+
/** Attach login handoff fields discovered from routes/deeplinks during init. */
|
|
119
|
+
export function enrichAuthLoginHandoff(auth, routes, deeplinks = []) {
|
|
120
|
+
const enriched = { ...auth };
|
|
121
|
+
if (!enriched.loginRoutePath) {
|
|
122
|
+
const detected = detectLoginRoutePath(routes);
|
|
123
|
+
if (detected)
|
|
124
|
+
enriched.loginRoutePath = detected;
|
|
125
|
+
}
|
|
126
|
+
if (!enriched.loginDeeplinkId) {
|
|
127
|
+
const dl = deeplinks.find((d) => LOGIN_ID_RE.test(d.id) ||
|
|
128
|
+
isLoginPath(d.pathTemplate ?? d.targetRoute ?? ""));
|
|
129
|
+
if (dl)
|
|
130
|
+
enriched.loginDeeplinkId = dl.id;
|
|
131
|
+
}
|
|
132
|
+
return enriched;
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
});
|
package/dist/core/types.d.ts
CHANGED
|
@@ -124,6 +124,16 @@ export interface AuthSchema {
|
|
|
124
124
|
tokenEndpoint?: string;
|
|
125
125
|
/** Custom claims added to tokens */
|
|
126
126
|
customClaims?: Record<string, string>;
|
|
127
|
+
/**
|
|
128
|
+
* Deeplink id for the sign-in page. When an unauthenticated user hits a
|
|
129
|
+
* requiresAuth action, the shell navigates here instead of showing an error.
|
|
130
|
+
*/
|
|
131
|
+
loginDeeplinkId?: string;
|
|
132
|
+
/**
|
|
133
|
+
* App route path for sign-in (e.g. `/login`). Used when no login deeplink is
|
|
134
|
+
* declared — auto-detected from routes during `duct init` when possible.
|
|
135
|
+
*/
|
|
136
|
+
loginRoutePath?: string;
|
|
127
137
|
/** Agent detection confidence (0.0–1.0). */
|
|
128
138
|
confidence?: number;
|
|
129
139
|
/** Files and signals that led to this auth strategy being detected. */
|