@seamless-auth/express 0.1.2 → 0.3.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 (51) hide show
  1. package/README.md +18 -0
  2. package/dist/createServer.d.ts +78 -0
  3. package/dist/createServer.d.ts.map +1 -0
  4. package/dist/getSeamlessUser.d.ts +4 -0
  5. package/dist/getSeamlessUser.d.ts.map +1 -0
  6. package/dist/handlers/admin.d.ts +14 -0
  7. package/dist/handlers/admin.d.ts.map +1 -0
  8. package/dist/handlers/bootstrapAdmininvite.d.ts +4 -0
  9. package/dist/handlers/bootstrapAdmininvite.d.ts.map +1 -0
  10. package/dist/handlers/finishLogin.d.ts +6 -0
  11. package/dist/handlers/finishLogin.d.ts.map +1 -0
  12. package/dist/handlers/finishRegister.d.ts +6 -0
  13. package/dist/handlers/finishRegister.d.ts.map +1 -0
  14. package/dist/handlers/internalMetrics.d.ts +9 -0
  15. package/dist/handlers/internalMetrics.d.ts.map +1 -0
  16. package/dist/handlers/login.d.ts +4 -0
  17. package/dist/handlers/login.d.ts.map +1 -0
  18. package/dist/handlers/logout.d.ts +4 -0
  19. package/dist/handlers/logout.d.ts.map +1 -0
  20. package/dist/handlers/me.d.ts +6 -0
  21. package/dist/handlers/me.d.ts.map +1 -0
  22. package/dist/handlers/pollMagicLinkConfirmation.d.ts +6 -0
  23. package/dist/handlers/pollMagicLinkConfirmation.d.ts.map +1 -0
  24. package/dist/handlers/register.d.ts +4 -0
  25. package/dist/handlers/register.d.ts.map +1 -0
  26. package/dist/handlers/requestMagicLink.d.ts +7 -0
  27. package/dist/handlers/requestMagicLink.d.ts.map +1 -0
  28. package/dist/handlers/requestOtp.d.ts +7 -0
  29. package/dist/handlers/requestOtp.d.ts.map +1 -0
  30. package/dist/handlers/sessions.d.ts +6 -0
  31. package/dist/handlers/sessions.d.ts.map +1 -0
  32. package/dist/handlers/systemConfig.d.ts +6 -0
  33. package/dist/handlers/systemConfig.d.ts.map +1 -0
  34. package/dist/index.d.ts +9 -197
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +621 -12
  37. package/dist/internal/buildAuthorization.d.ts +6 -0
  38. package/dist/internal/buildAuthorization.d.ts.map +1 -0
  39. package/dist/internal/cookie.d.ts +17 -0
  40. package/dist/internal/cookie.d.ts.map +1 -0
  41. package/dist/internal/deliverAuthMessage.d.ts +6 -0
  42. package/dist/internal/deliverAuthMessage.d.ts.map +1 -0
  43. package/dist/messaging.d.ts +98 -0
  44. package/dist/messaging.d.ts.map +1 -0
  45. package/dist/middleware/ensureCookies.d.ts +16 -0
  46. package/dist/middleware/ensureCookies.d.ts.map +1 -0
  47. package/dist/middleware/requireAuth.d.ts +69 -0
  48. package/dist/middleware/requireAuth.d.ts.map +1 -0
  49. package/dist/middleware/requireRole.d.ts +36 -0
  50. package/dist/middleware/requireRole.d.ts.map +1 -0
  51. package/package.json +7 -5
package/README.md CHANGED
@@ -14,6 +14,7 @@ This package:
14
14
  - Manages signed, HttpOnly session cookies
15
15
  - Enforces authentication and authorization in your API
16
16
  - Handles all API ↔ Auth Server communication via short-lived service tokens
17
+ - Establishes the initializer surface for adopter-supplied auth messaging
17
18
 
18
19
  > **npm:** https://www.npmjs.com/package/@seamless-auth/express
19
20
  > **Docs:** https://docs.seamlessauth.com
@@ -149,9 +150,26 @@ Routes include:
149
150
  registrationCookieName?: string;
150
151
  refreshCookieName?: string;
151
152
  preAuthCookieName?: string;
153
+ messaging?: {
154
+ email?: EmailTransport;
155
+ sms?: SmsTransport;
156
+ handlers?: Partial<AuthMessagingHandlers>;
157
+ overrides?: AuthMessageOverrides;
158
+ };
152
159
  }
153
160
  ```
154
161
 
162
+ `messaging` is the initializer-facing contract for adopter-supplied auth messaging capabilities.
163
+
164
+ When `messaging` is provided, `@seamless-auth/express` requests external-delivery payloads from the upstream auth server for auth-message flows and completes delivery locally through the configured transports or handlers.
165
+
166
+ This currently applies to:
167
+
168
+ - OTP email
169
+ - OTP SMS
170
+ - magic-link email
171
+ - bootstrap invite email
172
+
155
173
  ---
156
174
 
157
175
  ### `requireAuth(options?)`
@@ -0,0 +1,78 @@
1
+ import { Router } from "express";
2
+ import type { SeamlessAuthMessagingOptions } from "./messaging";
3
+ export type SeamlessAuthServerOptions = {
4
+ authServerUrl: string;
5
+ cookieSecret: string;
6
+ serviceSecret: string;
7
+ issuer: string;
8
+ audience: string;
9
+ jwksKid?: string;
10
+ cookieDomain?: string;
11
+ accessCookieName?: string;
12
+ registrationCookieName?: string;
13
+ refreshCookieName?: string;
14
+ preAuthCookieName?: string;
15
+ messaging?: SeamlessAuthMessagingOptions;
16
+ };
17
+ export interface SeamlessAuthUser {
18
+ id: string;
19
+ sub: string;
20
+ roles: string[];
21
+ email: string;
22
+ phone: string;
23
+ iat?: number;
24
+ exp?: number;
25
+ }
26
+ /**
27
+ * Creates an Express Router that proxies all authentication traffic to a Seamless Auth server.
28
+ *
29
+ * This helper wires your API backend to a Seamless Auth instance running in
30
+ * "server mode." It automatically forwards login, registration, WebAuthn,
31
+ * logout, token refresh, and session validation routes to the auth server
32
+ * and handles all cookie management required for a seamless login flow.
33
+ *
34
+ * ### Responsibilities
35
+ * - Proxies all `/auth/*` routes to the upstream Seamless Auth server
36
+ * - Manages `access`, `registration`, `pre-auth`, and `refresh` cookies
37
+ * - Normalizes cookie settings for cross-domain or same-domain deployments
38
+ * - Ensures authentication routes behave consistently across environments
39
+ * - Provides shared middleware for auth flows
40
+ *
41
+ * ### Cookie Types
42
+ * - **accessCookie** – long-lived session cookie for authenticated API requests
43
+ * - **registrationCookie** – ephemeral cookie used during registration and OTP/WebAuthn flows
44
+ * - **preAuthCookie** – short-lived cookie used during login initiation
45
+ * - **refreshCookie** – opaque refresh token cookie used to rotate session tokens
46
+ *
47
+ * All cookie names and their domains may be customized via the `opts` parameter.
48
+ *
49
+ * ### Example
50
+ * ```ts
51
+ * app.use("/auth", createSeamlessAuthServer({
52
+ * authServerUrl: "https://identifier.seamlessauth.com",
53
+ * cookieDomain: "mycompany.com",
54
+ * cookieSecret: "someLongRandomValue"
55
+ * serviceSecret: "someLongRandomValueToo"
56
+ * jwksKid: "dev-main"
57
+ * accessCookieName: "sa_access",
58
+ * registrationCookieName: "sa_registration",
59
+ * refreshCookieName: "sa_refresh",
60
+ * }));
61
+ * ```
62
+ *
63
+ * @param opts - Configuration options for the Seamless Auth proxy:
64
+ * - `authServerUrl` — Base URL of your Seamless Auth instance (required)
65
+ * - `cookieSecret` — The value to encode your cookies secrets with (required)
66
+ * - `serviceSecret` - An machine to machine shared secret that matches your auth servers (required)
67
+ * - `jwksKid` - The active jwks KID
68
+ * - `cookieDomain` — Domain attribute applied to all auth cookies
69
+ * - `accessCookieName` — Name of the session access cookie
70
+ * - `registrationCookieName` — Name of the ephemeral registration cookie
71
+ * - `refreshCookieName` — Name of the refresh token cookie
72
+ * - `preAuthCookieName` — Name of the cookie used during login initiation
73
+ * - `messaging` — Optional auth-messaging transports, handlers, and overrides
74
+ *
75
+ * @returns An Express `Router` preconfigured with all Seamless Auth routes.
76
+ */
77
+ export declare function createSeamlessAuthServer(opts: SeamlessAuthServerOptions): Router;
78
+ //# sourceMappingURL=createServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../src/createServer.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAI7D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAqDhE,MAAM,MAAM,yBAAyB,GAAG;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,4BAA4B,CAAC;CAC1C,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,yBAAyB,GAC9B,MAAM,CAkPR"}
@@ -0,0 +1,4 @@
1
+ import type { Request } from "express";
2
+ import { SeamlessAuthServerOptions } from "./createServer";
3
+ export declare function getSeamlessUser(req: Request, opts: SeamlessAuthServerOptions): Promise<any>;
4
+ //# sourceMappingURL=getSeamlessUser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSeamlessUser.d.ts","sourceRoot":"","sources":["../src/getSeamlessUser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAMvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,wBAAsB,eAAe,CACnC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,yBAAyB,gBAUhC"}
@@ -0,0 +1,14 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare const getUsers: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
4
+ export declare const createUser: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
5
+ export declare const deleteUser: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
6
+ export declare const updateUser: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
7
+ export declare const getUserDetail: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
8
+ export declare const getUserAnomalies: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
9
+ export declare const getAuthEvents: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
10
+ export declare const getCredentialCount: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
11
+ export declare const listAllSessions: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
12
+ export declare const listUserSessions: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
13
+ export declare const revokeAllUserSessions: (req: Request, res: Response, opts: SeamlessAuthServerOptions) => Promise<Response<any, Record<string, any>>>;
14
+ //# sourceMappingURL=admin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/handlers/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAgB5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAS5D,eAAO,MAAM,QAAQ,GACnB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAQ9B,CAAC;AAEJ,eAAO,MAAM,UAAU,GACrB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAS9B,CAAC;AAEJ,eAAO,MAAM,UAAU,GACrB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAQ9B,CAAC;AAEJ,eAAO,MAAM,UAAU,GACrB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAS9B,CAAC;AAEJ,eAAO,MAAM,aAAa,GACxB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAQ9B,CAAC;AAEJ,eAAO,MAAM,gBAAgB,GAC3B,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAQ9B,CAAC;AAEJ,eAAO,MAAM,aAAa,GACxB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAS9B,CAAC;AAEJ,eAAO,MAAM,kBAAkB,GAC7B,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAQ9B,CAAC;AAEJ,eAAO,MAAM,eAAe,GAC1B,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAS9B,CAAC;AAEJ,eAAO,MAAM,gBAAgB,GAC3B,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAQ9B,CAAC;AAEJ,eAAO,MAAM,qBAAqB,GAChC,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,yBAAyB,gDAQ9B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function bootstrapAdminInvite(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
4
+ //# sourceMappingURL=bootstrapAdmininvite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrapAdmininvite.d.ts","sourceRoot":"","sources":["../../src/handlers/bootstrapAdmininvite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DAsBhC"}
@@ -0,0 +1,6 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function finishLogin(req: Request & {
4
+ cookiePayload?: any;
5
+ }, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
6
+ //# sourceMappingURL=finishLogin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finishLogin.d.ts","sourceRoot":"","sources":["../../src/handlers/finishLogin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,WAAW,CAC/B,GAAG,EAAE,OAAO,GAAG;IAAE,aAAa,CAAC,EAAE,GAAG,CAAA;CAAE,EACtC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DA+ChC"}
@@ -0,0 +1,6 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function finishRegister(req: Request & {
4
+ cookiePayload?: any;
5
+ }, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
6
+ //# sourceMappingURL=finishRegister.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finishRegister.d.ts","sourceRoot":"","sources":["../../src/handlers/finishRegister.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAG5D,wBAAsB,cAAc,CAClC,GAAG,EAAE,OAAO,GAAG;IAAE,aAAa,CAAC,EAAE,GAAG,CAAA;CAAE,EACtC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DAkEhC"}
@@ -0,0 +1,9 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function getAuthEventSummary(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
4
+ export declare function getAuthEventTimeseries(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
5
+ export declare function getLoginStats(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
6
+ export declare function getSecurityAnomalies(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
7
+ export declare function getDashboardMetrics(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
8
+ export declare function getGroupedEventSummary(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
9
+ //# sourceMappingURL=internalMetrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internalMetrics.d.ts","sourceRoot":"","sources":["../../src/handlers/internalMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAW5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAS5D,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAWhC;AAED,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAWhC;AAED,wBAAsB,aAAa,CACjC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAUhC;AAED,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAUhC;AAED,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAUhC;AAED,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAUhC"}
@@ -0,0 +1,4 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function login(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
4
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/handlers/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,KAAK,CACzB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DA4ChC"}
@@ -0,0 +1,4 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function logout(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<void>;
4
+ //# sourceMappingURL=logout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../src/handlers/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,MAAM,CAC1B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,iBAYhC"}
@@ -0,0 +1,6 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function me(req: Request & {
4
+ cookiePayload?: any;
5
+ }, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
6
+ //# sourceMappingURL=me.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"me.d.ts","sourceRoot":"","sources":["../../src/handlers/me.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,EAAE,CACtB,GAAG,EAAE,OAAO,GAAG;IAAE,aAAa,CAAC,EAAE,GAAG,CAAA;CAAE,EACtC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DAoBhC"}
@@ -0,0 +1,6 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function pollMagicLinkConfirmation(req: Request & {
4
+ cookiePayload?: any;
5
+ }, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
6
+ //# sourceMappingURL=pollMagicLinkConfirmation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pollMagicLinkConfirmation.d.ts","sourceRoot":"","sources":["../../src/handlers/pollMagicLinkConfirmation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,OAAO,GAAG;IAAE,aAAa,CAAC,EAAE,GAAG,CAAA;CAAE,EACtC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DAgDhC"}
@@ -0,0 +1,4 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function register(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
4
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/handlers/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DAqDhC"}
@@ -0,0 +1,7 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function requestMagicLink(req: Request & {
4
+ cookiePayload?: any;
5
+ user?: any;
6
+ }, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
7
+ //# sourceMappingURL=requestMagicLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestMagicLink.d.ts","sourceRoot":"","sources":["../../src/handlers/requestMagicLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,OAAO,GAAG;IAAE,aAAa,CAAC,EAAE,GAAG,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAA;CAAE,EAClD,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAyBhC"}
@@ -0,0 +1,7 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function requestOtp(req: Request & {
4
+ cookiePayload?: any;
5
+ user?: any;
6
+ }, res: Response, opts: SeamlessAuthServerOptions, kind: "email" | "phone"): Promise<Response<any, Record<string, any>>>;
7
+ //# sourceMappingURL=requestOtp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestOtp.d.ts","sourceRoot":"","sources":["../../src/handlers/requestOtp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,UAAU,CAC9B,GAAG,EAAE,OAAO,GAAG;IAAE,aAAa,CAAC,EAAE,GAAG,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAA;CAAE,EAClD,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,EAC/B,IAAI,EAAE,OAAO,GAAG,OAAO,+CA0BxB"}
@@ -0,0 +1,6 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function listSessions(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
4
+ export declare function revokeSession(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
5
+ export declare function revokeAllSessions(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>>>;
6
+ //# sourceMappingURL=sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../src/handlers/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQ5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAS5D,wBAAsB,YAAY,CAChC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAUhC;AAED,wBAAsB,aAAa,CACjC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAUhC;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,+CAUhC"}
@@ -0,0 +1,6 @@
1
+ import { Request, Response } from "express";
2
+ import { SeamlessAuthServerOptions } from "../createServer";
3
+ export declare function getAvailableRoles(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
4
+ export declare function getSystemConfigAdmin(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
5
+ export declare function updateSystemConfig(req: Request, res: Response, opts: SeamlessAuthServerOptions): Promise<Response<any, Record<string, any>> | undefined>;
6
+ //# sourceMappingURL=systemConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"systemConfig.d.ts","sourceRoot":"","sources":["../../src/handlers/systemConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQ5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DAchC;AAED,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DAchC;AAED,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,yBAAyB,2DAehC"}
package/dist/index.d.ts CHANGED
@@ -1,197 +1,9 @@
1
- import { Router, Request, Response, NextFunction, RequestHandler } from 'express';
2
-
3
- type SeamlessAuthServerOptions = {
4
- authServerUrl: string;
5
- cookieSecret: string;
6
- serviceSecret: string;
7
- issuer: string;
8
- audience: string;
9
- jwksKid?: string;
10
- cookieDomain?: string;
11
- accessCookieName?: string;
12
- registrationCookieName?: string;
13
- refreshCookieName?: string;
14
- preAuthCookieName?: string;
15
- };
16
- interface SeamlessAuthUser {
17
- id: string;
18
- sub: string;
19
- roles: string[];
20
- email: string;
21
- phone: string;
22
- iat?: number;
23
- exp?: number;
24
- }
25
- /**
26
- * Creates an Express Router that proxies all authentication traffic to a Seamless Auth server.
27
- *
28
- * This helper wires your API backend to a Seamless Auth instance running in
29
- * "server mode." It automatically forwards login, registration, WebAuthn,
30
- * logout, token refresh, and session validation routes to the auth server
31
- * and handles all cookie management required for a seamless login flow.
32
- *
33
- * ### Responsibilities
34
- * - Proxies all `/auth/*` routes to the upstream Seamless Auth server
35
- * - Manages `access`, `registration`, `pre-auth`, and `refresh` cookies
36
- * - Normalizes cookie settings for cross-domain or same-domain deployments
37
- * - Ensures authentication routes behave consistently across environments
38
- * - Provides shared middleware for auth flows
39
- *
40
- * ### Cookie Types
41
- * - **accessCookie** – long-lived session cookie for authenticated API requests
42
- * - **registrationCookie** – ephemeral cookie used during registration and OTP/WebAuthn flows
43
- * - **preAuthCookie** – short-lived cookie used during login initiation
44
- * - **refreshCookie** – opaque refresh token cookie used to rotate session tokens
45
- *
46
- * All cookie names and their domains may be customized via the `opts` parameter.
47
- *
48
- * ### Example
49
- * ```ts
50
- * app.use("/auth", createSeamlessAuthServer({
51
- * authServerUrl: "https://identifier.seamlessauth.com",
52
- * cookieDomain: "mycompany.com",
53
- * cookieSecret: "someLongRandomValue"
54
- * serviceSecret: "someLongRandomValueToo"
55
- * jwksKid: "dev-main"
56
- * accessCookieName: "sa_access",
57
- * registrationCookieName: "sa_registration",
58
- * refreshCookieName: "sa_refresh",
59
- * }));
60
- * ```
61
- *
62
- * @param opts - Configuration options for the Seamless Auth proxy:
63
- * - `authServerUrl` — Base URL of your Seamless Auth instance (required)
64
- * - `cookieSecret` — The value to encode your cookies secrets with (required)
65
- * - `serviceSecret` - An machine to machine shared secret that matches your auth servers (required)
66
- * - `jwksKid` - The active jwks KID
67
- * - `cookieDomain` — Domain attribute applied to all auth cookies
68
- * - `accessCookieName` — Name of the session access cookie
69
- * - `registrationCookieName` — Name of the ephemeral registration cookie
70
- * - `refreshCookieName` — Name of the refresh token cookie
71
- * - `preAuthCookieName` — Name of the cookie used during login initiation
72
- *
73
- * @returns An Express `Router` preconfigured with all Seamless Auth routes.
74
- */
75
- declare function createSeamlessAuthServer(opts: SeamlessAuthServerOptions): Router;
76
-
77
- interface RequireAuthOptions {
78
- cookieName?: string;
79
- cookieSecret: string;
80
- }
81
- /**
82
- * Express middleware that enforces authentication using Seamless Auth cookies.
83
- *
84
- * This guard verifies the signed access cookie generated by the Seamless Auth
85
- * server. If the access cookie is valid and unexpired, the decoded session
86
- * payload is attached to `req.user` and the request proceeds.
87
- *
88
- * If the access cookie is expired or missing *but* a valid refresh cookie is
89
- * present, the middleware automatically attempts a silent token refresh using
90
- * the Seamless Auth server. When successful, new session cookies are issued and
91
- * the request continues with an updated `req.user`.
92
- *
93
- * If neither the access token nor refresh token can validate the session,
94
- * the middleware returns a 401 Unauthorized error and prevents further
95
- * route execution.
96
- *
97
- * ### Responsibilities
98
- * - Validates the Seamless Auth session access cookie
99
- * - Attempts refresh-token–based session renewal when necessary
100
- * - Populates `req.user` with the verified session payload
101
- * - Handles all cookie rewriting during refresh flows
102
- * - Acts as a request-level authentication guard for API routes
103
- *
104
- * ### Cookie Parameters
105
- * - **cookieName** — Name of the access cookie that holds the signed session JWT
106
- * - **refreshCookieName** — Name of the refresh cookie used for silent token refresh
107
- * - **cookieDomain** — Domain or path value applied to issued cookies
108
- *
109
- * ### Example
110
- * ```ts
111
- * // Protect a route
112
- * app.get("/api/me", requireAuth(), (req, res) => {
113
- * res.json({ user: req.user });
114
- * });
115
- *
116
- * // Custom cookie names (if your Seamless Auth server uses overrides)
117
- * app.use(
118
- * "/internal",
119
- * requireAuth("sa_access", "sa_refresh", "mycompany.com"),
120
- * internalRouter
121
- * );
122
- * ```
123
- *
124
- * @param cookieName - The access cookie name. Defaults to `"seamless-access"`.
125
- * @param refreshCookieName - The refresh cookie name used for session rotation. Defaults to `"seamless-refresh"`.
126
- * @param cookieDomain - Domain or path used when rewriting cookies. Defaults to `"/"`.
127
- *
128
- * @returns An Express middleware function that enforces Seamless Auth
129
- * authentication on incoming requests.
130
- */
131
- interface RequireAuthOptions {
132
- cookieName?: string;
133
- cookieSecret: string;
134
- }
135
- /**
136
- * Express middleware that enforces authentication
137
- * using an already-issued Seamless Auth access cookie.
138
- *
139
- * NOTE:
140
- * - This middleware does NOT attempt token refresh.
141
- * - Refresh is handled upstream by ensureCookies().
142
- */
143
- declare function requireAuth(opts: RequireAuthOptions): (req: Request, res: Response, next: NextFunction) => void;
144
-
145
- /**
146
- * Express middleware that enforces role-based authorization for Seamless Auth.
147
- *
148
- * This middleware assumes `requireAuth()` has already:
149
- * - authenticated the request
150
- * - populated `req.user` with the authenticated session payload
151
- *
152
- * `requireRole` performs **authorization only**. It does not inspect cookies,
153
- * verify tokens, or read environment variables.
154
- *
155
- * If any of the required roles are present on the user, access is granted.
156
- * Otherwise, a 403 Forbidden response is returned.
157
- *
158
- * * ### Example
159
- * ```ts
160
- * // Require a single role
161
- * app.get("/admin/users",
162
- * requireAuth(),
163
- * requireRole("admin"),
164
- * (req, res) => {
165
- * res.send("Welcome admin!");
166
- * }
167
- * );
168
- *
169
- * // Allow any of multiple roles
170
- * app.post("/settings",
171
- * requireAuth(),
172
- * requireRole(["admin", "supervisor"]),
173
- * updateSettingsHandler
174
- * );
175
- *
176
- * @param requiredRoles - A role or list of roles required to access the route
177
- */
178
- declare function requireRole(requiredRoles: string | string[]): RequestHandler;
179
-
180
- interface EnsureCookiesMiddlewareOptions {
181
- authServerUrl: string;
182
- cookieDomain?: string;
183
- accessCookieName: string;
184
- registrationCookieName: string;
185
- refreshCookieName: string;
186
- preAuthCookieName: string;
187
- cookieSecret: string;
188
- serviceSecret: string;
189
- issuer: string;
190
- audience: string;
191
- keyId: string;
192
- }
193
- declare function createEnsureCookiesMiddleware(opts: EnsureCookiesMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
194
-
195
- declare function getSeamlessUser(req: Request, opts: SeamlessAuthServerOptions): Promise<any>;
196
-
197
- export { type SeamlessAuthServerOptions, type SeamlessAuthUser, createEnsureCookiesMiddleware, createSeamlessAuthServer as default, getSeamlessUser, requireAuth, requireRole };
1
+ import { createSeamlessAuthServer, SeamlessAuthServerOptions, SeamlessAuthUser } from "./createServer";
2
+ export { SeamlessAuthServerOptions, SeamlessAuthUser };
3
+ export type { AuthMessageOverrides, AuthMessagingHandlers, DeliveryResult, EmailMessage, EmailTransport, SeamlessAuthMessagingOptions, SmsMessage, SmsTransport, } from "./messaging";
4
+ export { requireAuth } from "./middleware/requireAuth";
5
+ export { requireRole } from "./middleware/requireRole";
6
+ export { createEnsureCookiesMiddleware } from "./middleware/ensureCookies";
7
+ export { getSeamlessUser } from "./getSeamlessUser";
8
+ export default createSeamlessAuthServer;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,CAAC;AACvD,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,cAAc,EACd,4BAA4B,EAC5B,UAAU,EACV,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,eAAe,wBAAwB,CAAC"}