@nwire/auth 0.7.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.
@@ -0,0 +1,85 @@
1
+ /**
2
+ * `IdpAdapter` — the contract every authentication backend implements.
3
+ *
4
+ * Adapter packages (`@nwire/auth-better-auth`, `@nwire/auth-logto`,
5
+ * `@nwire/auth-passport`, …) provide an instance of this interface. The
6
+ * `identityPlugin` registers it on the container and wires the HTTP layer
7
+ * to call `verifyToken` on each request.
8
+ *
9
+ * Actions the adapter MUST support (everything else is optional):
10
+ * - `verifyToken(token)` — resolve a bearer/session token to a User
11
+ * - `signIn(credentials)` — credentialed login
12
+ * - `signOut(token)` — invalidate token / session
13
+ *
14
+ * Optional flows depend on the IdP's capabilities — gracefully degrade.
15
+ */
16
+ import type { PluginDefinition } from "@nwire/forge";
17
+ import type { User } from "./user.js";
18
+ /**
19
+ * Sub-shape: tokens the adapter mints on sign-in or refresh. Most adapters
20
+ * return a JWT + refresh token; OIDC adapters add an ID token; session
21
+ * adapters return a session ID. `expiresAt` is the access token's expiry.
22
+ */
23
+ export interface AuthTokens {
24
+ readonly accessToken: string;
25
+ readonly refreshToken?: string;
26
+ readonly idToken?: string;
27
+ readonly expiresAt?: number;
28
+ readonly tokenType?: "Bearer" | "Cookie";
29
+ }
30
+ export interface SignInInput {
31
+ readonly email?: string;
32
+ readonly password?: string;
33
+ /** Adapter-specific extras — magic links, social provider id, MFA codes, etc. */
34
+ readonly extras?: Record<string, any>;
35
+ }
36
+ export interface RegisterInput {
37
+ readonly email: string;
38
+ readonly password?: string;
39
+ readonly name?: string;
40
+ readonly extras?: Record<string, any>;
41
+ }
42
+ export interface IdpAdapter {
43
+ /**
44
+ * Verify a token (bearer / session ID) and return the User it identifies.
45
+ * Return `null` for "token doesn't resolve to a user" (expired, revoked,
46
+ * malformed). Throw only for adapter-level failures (IdP unreachable).
47
+ */
48
+ verifyToken(token: string): Promise<User | null>;
49
+ /** Credentialed sign-in. Returns User + token bundle. */
50
+ signIn(input: SignInInput): Promise<{
51
+ user: User;
52
+ tokens: AuthTokens;
53
+ }>;
54
+ /** Invalidate the session/token. */
55
+ signOut(token: string): Promise<void>;
56
+ /** Refresh an access token using a refresh token. Optional. */
57
+ refresh?(refreshToken: string): Promise<AuthTokens>;
58
+ /** Register a new user. Optional — IdP-backed apps usually don't expose this. */
59
+ register?(input: RegisterInput): Promise<{
60
+ user: User;
61
+ tokens?: AuthTokens;
62
+ }>;
63
+ /** Begin password reset flow (send email). Optional. */
64
+ requestPasswordReset?(email: string): Promise<void>;
65
+ /** Complete password reset flow (consume reset token + new password). Optional. */
66
+ resetPassword?(resetToken: string, newPassword: string): Promise<void>;
67
+ /** Verify an email-confirmation token. Optional. */
68
+ verifyEmail?(verificationToken: string): Promise<void>;
69
+ /** Adapter shutdown — close pools, flush caches, etc. */
70
+ shutdown?(): Promise<void>;
71
+ }
72
+ export interface IdentityPluginOptions {
73
+ /** The adapter implementing the IdP behaviors. */
74
+ readonly adapter: IdpAdapter;
75
+ /** Container token the adapter is registered under. Default: `"idp"`. */
76
+ readonly name?: string;
77
+ }
78
+ /**
79
+ * Identity plugin — registers the adapter on the container. HTTP-level
80
+ * token extraction (Authorization header, session cookie, etc.) lives in
81
+ * each adapter's wire integration (`adapter.applyToWire(koa)` is the
82
+ * usual hook).
83
+ */
84
+ export declare function identityPlugin(options: IdentityPluginOptions): PluginDefinition;
85
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ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,EAAE,IAAI,CAAC;QAAC,MAAM,CAAC,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IAE9E,wDAAwD;IACxD,oBAAoB,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD,mFAAmF;IACnF,aAAa,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvE,oDAAoD;IACpD,WAAW,CAAC,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvD,yDAAyD;IACzD,QAAQ,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,yEAAyE;IACzE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,gBAAgB,CAU/E"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * `IdpAdapter` — the contract every authentication backend implements.
3
+ *
4
+ * Adapter packages (`@nwire/auth-better-auth`, `@nwire/auth-logto`,
5
+ * `@nwire/auth-passport`, …) provide an instance of this interface. The
6
+ * `identityPlugin` registers it on the container and wires the HTTP layer
7
+ * to call `verifyToken` on each request.
8
+ *
9
+ * Actions the adapter MUST support (everything else is optional):
10
+ * - `verifyToken(token)` — resolve a bearer/session token to a User
11
+ * - `signIn(credentials)` — credentialed login
12
+ * - `signOut(token)` — invalidate token / session
13
+ *
14
+ * Optional flows depend on the IdP's capabilities — gracefully degrade.
15
+ */
16
+ import { definePlugin } from "@nwire/forge";
17
+ /**
18
+ * Identity plugin — registers the adapter on the container. HTTP-level
19
+ * token extraction (Authorization header, session cookie, etc.) lives in
20
+ * each adapter's wire integration (`adapter.applyToWire(koa)` is the
21
+ * usual hook).
22
+ */
23
+ export function identityPlugin(options) {
24
+ const name = options.name ?? "idp";
25
+ return definePlugin("identity", {
26
+ register: (container) => {
27
+ container.register(name, options.adapter);
28
+ },
29
+ shutdown: async () => {
30
+ if (options.adapter.shutdown)
31
+ await options.adapter.shutdown();
32
+ },
33
+ });
34
+ }
35
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAwE5C;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC;IACnC,OAAO,YAAY,CAAC,UAAU,EAAE;QAC9B,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE;YACtB,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE;YACnB,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ;gBAAE,MAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACjE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Canonical auth resolvers — every adapter inherits these. The resolver
3
+ * body looks up the IdpAdapter on the container and delegates; adapters
4
+ * never re-implement HTTP shape, only the business logic.
5
+ *
6
+ * Apps mount whichever subset they need:
7
+ *
8
+ * import { SignIn, SignOut, Register, Me } from "@nwire/auth";
9
+ * rest.mount([
10
+ * [SignIn, post("/auth/sign-in")],
11
+ * [SignOut, post("/auth/sign-out")],
12
+ * [Register, post("/auth/register")],
13
+ * [Me, get("/auth/me")],
14
+ * ]);
15
+ */
16
+ import { z } from "zod";
17
+ export declare const SignIn: import("@nwire/forge").ResolverDefinition<undefined, undefined, z.ZodObject<{
18
+ email: z.ZodEmail;
19
+ password: z.ZodString;
20
+ }, z.core.$strip>, {
21
+ email: string;
22
+ password: string;
23
+ }>;
24
+ export declare const SignOut: import("@nwire/forge").ResolverDefinition<undefined, undefined, z.ZodObject<{
25
+ token: z.ZodString;
26
+ }, z.core.$strip>, {
27
+ token: string;
28
+ }>;
29
+ export declare const Refresh: import("@nwire/forge").ResolverDefinition<undefined, undefined, z.ZodObject<{
30
+ refreshToken: z.ZodString;
31
+ }, z.core.$strip>, {
32
+ refreshToken: string;
33
+ }>;
34
+ export declare const Register: import("@nwire/forge").ResolverDefinition<undefined, undefined, z.ZodObject<{
35
+ email: z.ZodEmail;
36
+ password: z.ZodString;
37
+ name: z.ZodOptional<z.ZodString>;
38
+ }, z.core.$strip>, {
39
+ email: string;
40
+ password: string;
41
+ name?: string | undefined;
42
+ }>;
43
+ export declare const RequestPasswordReset: import("@nwire/forge").ResolverDefinition<undefined, undefined, z.ZodObject<{
44
+ email: z.ZodEmail;
45
+ }, z.core.$strip>, {
46
+ email: string;
47
+ }>;
48
+ export declare const ResetPassword: import("@nwire/forge").ResolverDefinition<undefined, undefined, z.ZodObject<{
49
+ resetToken: z.ZodString;
50
+ newPassword: z.ZodString;
51
+ }, z.core.$strip>, {
52
+ resetToken: string;
53
+ newPassword: string;
54
+ }>;
55
+ export declare const VerifyEmail: import("@nwire/forge").ResolverDefinition<undefined, undefined, z.ZodObject<{
56
+ verificationToken: z.ZodString;
57
+ }, z.core.$strip>, {
58
+ verificationToken: string;
59
+ }>;
60
+ export declare const Me: import("@nwire/forge").ResolverDefinition<undefined, undefined, z.ZodObject<{
61
+ token: z.ZodString;
62
+ }, z.core.$strip>, {
63
+ token: string;
64
+ }>;
65
+ //# sourceMappingURL=resolvers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../src/resolvers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoCxB,eAAO,MAAM,MAAM;;;;;;EAejB,CAAC;AAEH,eAAO,MAAM,OAAO;;;;EAYlB,CAAC;AAEH,eAAO,MAAM,OAAO;;;;EAalB,CAAC;AAEH,eAAO,MAAM,QAAQ;;;;;;;;EA0BnB,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;EAa/B,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;EAgBxB,CAAC;AAEH,eAAO,MAAM,WAAW;;;;EAatB,CAAC;AAEH,eAAO,MAAM,EAAE;;;;EAab,CAAC"}
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Canonical auth resolvers — every adapter inherits these. The resolver
3
+ * body looks up the IdpAdapter on the container and delegates; adapters
4
+ * never re-implement HTTP shape, only the business logic.
5
+ *
6
+ * Apps mount whichever subset they need:
7
+ *
8
+ * import { SignIn, SignOut, Register, Me } from "@nwire/auth";
9
+ * rest.mount([
10
+ * [SignIn, post("/auth/sign-in")],
11
+ * [SignOut, post("/auth/sign-out")],
12
+ * [Register, post("/auth/register")],
13
+ * [Me, get("/auth/me")],
14
+ * ]);
15
+ */
16
+ import { z } from "zod";
17
+ import { defineResource, defineResolver, response, NotFound } from "@nwire/forge";
18
+ const UserPublic = defineResource("User", {
19
+ schema: z.object({
20
+ id: z.string(),
21
+ email: z.string().optional(),
22
+ name: z.string().optional(),
23
+ roles: z.array(z.string()).readonly().optional(),
24
+ tenant: z.string().optional(),
25
+ }),
26
+ });
27
+ const TokensPublic = defineResource("AuthTokens", {
28
+ schema: z.object({
29
+ accessToken: z.string(),
30
+ refreshToken: z.string().optional(),
31
+ idToken: z.string().optional(),
32
+ expiresAt: z.number().optional(),
33
+ tokenType: z.enum(["Bearer", "Cookie"]).optional(),
34
+ }),
35
+ });
36
+ const SignInResult = defineResource("SignInResult", {
37
+ schema: z.object({
38
+ user: UserPublic.schema,
39
+ tokens: TokensPublic.schema,
40
+ }),
41
+ });
42
+ const ok202 = response(202);
43
+ const ok200User = response(200, UserPublic);
44
+ const ok200SignIn = response(200, SignInResult);
45
+ const ok200Tokens = response(200, TokensPublic);
46
+ export const SignIn = defineResolver({
47
+ operation: "auth.SignIn",
48
+ version: 1,
49
+ status: "active",
50
+ summary: "Authenticate with email + password",
51
+ body: z.object({
52
+ email: z.email(),
53
+ password: z.string().min(1),
54
+ }),
55
+ returns: [ok200SignIn],
56
+ errors: [],
57
+ }).use(async ({ input, resolve }) => {
58
+ const idp = resolve("idp");
59
+ const result = await idp.signIn({ email: input.email, password: input.password });
60
+ return ok200SignIn(result);
61
+ });
62
+ export const SignOut = defineResolver({
63
+ operation: "auth.SignOut",
64
+ version: 1,
65
+ status: "active",
66
+ summary: "Invalidate the current session/token",
67
+ body: z.object({ token: z.string() }),
68
+ returns: [ok202],
69
+ errors: [],
70
+ }).use(async ({ input, resolve }) => {
71
+ const idp = resolve("idp");
72
+ await idp.signOut(input.token);
73
+ return ok202();
74
+ });
75
+ export const Refresh = defineResolver({
76
+ operation: "auth.Refresh",
77
+ version: 1,
78
+ status: "active",
79
+ summary: "Exchange a refresh token for a new access token",
80
+ body: z.object({ refreshToken: z.string() }),
81
+ returns: [ok200Tokens],
82
+ errors: [],
83
+ }).use(async ({ input, resolve }) => {
84
+ const idp = resolve("idp");
85
+ if (!idp.refresh)
86
+ throw NotFound.with({ operation: "auth.Refresh", reason: "not supported by adapter" });
87
+ const tokens = await idp.refresh(input.refreshToken);
88
+ return ok200Tokens(tokens);
89
+ });
90
+ export const Register = defineResolver({
91
+ operation: "auth.Register",
92
+ version: 1,
93
+ status: "active",
94
+ summary: "Create a new account",
95
+ body: z.object({
96
+ email: z.email(),
97
+ password: z.string().min(8),
98
+ name: z.string().optional(),
99
+ }),
100
+ returns: [ok200SignIn],
101
+ errors: [],
102
+ }).use(async ({ input, resolve }) => {
103
+ const idp = resolve("idp");
104
+ if (!idp.register)
105
+ throw NotFound.with({ operation: "auth.Register", reason: "not supported by adapter" });
106
+ const result = await idp.register({
107
+ email: input.email,
108
+ password: input.password,
109
+ name: input.name,
110
+ });
111
+ // Some adapters don't mint tokens on register (e.g. email-verification first).
112
+ // Surface a minimal SignInResult so the shape stays consistent.
113
+ return ok200SignIn({
114
+ user: result.user,
115
+ tokens: result.tokens ?? { accessToken: "" },
116
+ });
117
+ });
118
+ export const RequestPasswordReset = defineResolver({
119
+ operation: "auth.RequestPasswordReset",
120
+ version: 1,
121
+ status: "active",
122
+ summary: "Send a password-reset email",
123
+ body: z.object({ email: z.email() }),
124
+ returns: [ok202],
125
+ errors: [],
126
+ }).use(async ({ input, resolve }) => {
127
+ const idp = resolve("idp");
128
+ if (!idp.requestPasswordReset)
129
+ throw NotFound.with({ operation: "auth.RequestPasswordReset" });
130
+ await idp.requestPasswordReset(input.email);
131
+ return ok202();
132
+ });
133
+ export const ResetPassword = defineResolver({
134
+ operation: "auth.ResetPassword",
135
+ version: 1,
136
+ status: "active",
137
+ summary: "Consume a reset token + set a new password",
138
+ body: z.object({
139
+ resetToken: z.string(),
140
+ newPassword: z.string().min(8),
141
+ }),
142
+ returns: [ok202],
143
+ errors: [],
144
+ }).use(async ({ input, resolve }) => {
145
+ const idp = resolve("idp");
146
+ if (!idp.resetPassword)
147
+ throw NotFound.with({ operation: "auth.ResetPassword" });
148
+ await idp.resetPassword(input.resetToken, input.newPassword);
149
+ return ok202();
150
+ });
151
+ export const VerifyEmail = defineResolver({
152
+ operation: "auth.VerifyEmail",
153
+ version: 1,
154
+ status: "active",
155
+ summary: "Confirm an email-verification token",
156
+ body: z.object({ verificationToken: z.string() }),
157
+ returns: [ok202],
158
+ errors: [],
159
+ }).use(async ({ input, resolve }) => {
160
+ const idp = resolve("idp");
161
+ if (!idp.verifyEmail)
162
+ throw NotFound.with({ operation: "auth.VerifyEmail" });
163
+ await idp.verifyEmail(input.verificationToken);
164
+ return ok202();
165
+ });
166
+ export const Me = defineResolver({
167
+ operation: "auth.Me",
168
+ version: 1,
169
+ status: "active",
170
+ summary: "Return the User identified by the current Authorization token",
171
+ body: z.object({ token: z.string() }),
172
+ returns: [ok200User],
173
+ errors: [],
174
+ }).use(async ({ input, resolve }) => {
175
+ const idp = resolve("idp");
176
+ const user = await idp.verifyToken(input.token);
177
+ if (!user)
178
+ throw NotFound.with({ operation: "auth.Me", reason: "token does not resolve to a user" });
179
+ return ok200User(user);
180
+ });
181
+ //# sourceMappingURL=resolvers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolvers.js","sourceRoot":"","sources":["../src/resolvers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGlF,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,EAAE;IACxC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,EAAE,EAAM,CAAC,CAAC,MAAM,EAAE;QAClB,KAAK,EAAG,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,IAAI,EAAI,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,KAAK,EAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;QACjD,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAC9B,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY,EAAE;IAChD,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,WAAW,EAAG,CAAC,CAAC,MAAM,EAAE;QACxB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QACnC,OAAO,EAAO,CAAC,CAAC,MAAM,EAAE,C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C,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACrC,OAAO,EAAE,CAAC,SAAS,CAAC;IACpB,MAAM,EAAG,EAAE;CACZ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;IAClC,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAe,CAAC;IACzC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAChD,IAAI,CAAC,IAAI;QAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,kCAAkC,EAAE,CAAC,CAAC;IACrG,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Auth routes — `{name}Route` + `{name}Handler` pairs for every canonical
3
+ * identity operation. Mount them on any `httpInterface` directly or via
4
+ * the `mountAuth(api)` helper:
5
+ *
6
+ * import { httpInterface } from "@nwire/http";
7
+ * import { mountAuth, identityPlugin } from "@nwire/auth";
8
+ *
9
+ * const api = mountAuth(httpInterface({ prefix: "/api/v1" }));
10
+ * // mounts: POST /auth/sign-in, /sign-out, /refresh, /register,
11
+ * // /request-password-reset, /reset-password, /verify-email,
12
+ * // GET /auth/me
13
+ *
14
+ * const app = createApp({
15
+ * plugins: [identityPlugin({ adapter })],
16
+ * ...
17
+ * });
18
+ *
19
+ * // app.runtime registers "idp" on the container; handlers resolve it
20
+ * await endpoint("api").serve(app).serve(api).run();
21
+ *
22
+ * Each handler reads `idp` from the container (registered by
23
+ * `identityPlugin`) and delegates the business logic to the adapter.
24
+ * Apps that want only a subset of operations import individual
25
+ * `{Route, Handler}` pairs and wire them by hand instead of using
26
+ * `mountAuth`.
27
+ */
28
+ import { z } from "zod";
29
+ import { type HttpHandler, type HttpInterface, type RouteBinding } from "@nwire/http";
30
+ declare const SignInBody: z.ZodObject<{
31
+ email: z.ZodEmail;
32
+ password: z.ZodString;
33
+ }, z.core.$strip>;
34
+ declare const SignOutBody: z.ZodObject<{
35
+ token: z.ZodString;
36
+ }, z.core.$strip>;
37
+ declare const RefreshBody: z.ZodObject<{
38
+ refreshToken: z.ZodString;
39
+ }, z.core.$strip>;
40
+ declare const RegisterBody: z.ZodObject<{
41
+ email: z.ZodEmail;
42
+ password: z.ZodString;
43
+ name: z.ZodOptional<z.ZodString>;
44
+ }, z.core.$strip>;
45
+ declare const RequestPwResetBody: z.ZodObject<{
46
+ email: z.ZodEmail;
47
+ }, z.core.$strip>;
48
+ declare const ResetPasswordBody: z.ZodObject<{
49
+ resetToken: z.ZodString;
50
+ newPassword: z.ZodString;
51
+ }, z.core.$strip>;
52
+ declare const VerifyEmailBody: z.ZodObject<{
53
+ verificationToken: z.ZodString;
54
+ }, z.core.$strip>;
55
+ declare const MeBody: z.ZodObject<{
56
+ token: z.ZodString;
57
+ }, z.core.$strip>;
58
+ type SignInInput = z.output<typeof SignInBody>;
59
+ type SignOutInput = z.output<typeof SignOutBody>;
60
+ type RefreshInput = z.output<typeof RefreshBody>;
61
+ type RegisterInput = z.output<typeof RegisterBody>;
62
+ type RequestPwResetInput = z.output<typeof RequestPwResetBody>;
63
+ type ResetPasswordInput = z.output<typeof ResetPasswordBody>;
64
+ type VerifyEmailInput = z.output<typeof VerifyEmailBody>;
65
+ type MeInput = z.output<typeof MeBody>;
66
+ export declare const signInRoute: RouteBinding<SignInInput>;
67
+ export declare const signInHandler: HttpHandler<SignInInput>;
68
+ export declare const signOutRoute: RouteBinding<SignOutInput>;
69
+ export declare const signOutHandler: HttpHandler<SignOutInput>;
70
+ export declare const refreshRoute: RouteBinding<RefreshInput>;
71
+ export declare const refreshHandler: HttpHandler<RefreshInput>;
72
+ export declare const registerRoute: RouteBinding<RegisterInput>;
73
+ export declare const registerHandler: HttpHandler<RegisterInput>;
74
+ export declare const requestPasswordResetRoute: RouteBinding<RequestPwResetInput>;
75
+ export declare const requestPasswordResetHandler: HttpHandler<RequestPwResetInput>;
76
+ export declare const resetPasswordRoute: RouteBinding<ResetPasswordInput>;
77
+ export declare const resetPasswordHandler: HttpHandler<ResetPasswordInput>;
78
+ export declare const verifyEmailRoute: RouteBinding<VerifyEmailInput>;
79
+ export declare const verifyEmailHandler: HttpHandler<VerifyEmailInput>;
80
+ export declare const meRoute: RouteBinding<MeInput>;
81
+ export declare const meHandler: HttpHandler<MeInput>;
82
+ export interface MountAuthOptions {
83
+ /** Pick which routes to mount. Default — all. */
84
+ readonly include?: ReadonlyArray<"signIn" | "signOut" | "refresh" | "register" | "requestPasswordReset" | "resetPassword" | "verifyEmail" | "me">;
85
+ }
86
+ /**
87
+ * Wire every canonical auth route onto the given httpInterface in one
88
+ * call. Returns the same interface for chaining. Pass `options.include`
89
+ * to mount only a subset (e.g. an app that doesn't expose registration).
90
+ *
91
+ * const api = mountAuth(httpInterface({ prefix: "/api/v1" }));
92
+ * // → 8 routes mounted: /auth/sign-in, /sign-out, /refresh, /register, ...
93
+ *
94
+ * // Subset:
95
+ * mountAuth(api, { include: ["signIn", "signOut", "me"] });
96
+ */
97
+ export declare function mountAuth(api: HttpInterface, options?: MountAuthOptions): HttpInterface;
98
+ export {};
99
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAwCjG,QAAA,MAAM,UAAU;;;iBAA8D,CAAC;AAC/E,QAAA,MAAM,WAAW;;iBAAkC,CAAC;AACpD,QAAA,MAAM,WAAW;;iBAAyC,CAAC;AAC3D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