@auth-craft/api-contract 0.1.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.
- package/dist/auth.contract.d.ts +391 -0
- package/dist/auth.contract.d.ts.map +1 -0
- package/dist/auth.contract.js +138 -0
- package/dist/auth.contract.js.map +1 -0
- package/dist/core.d.ts +51 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +29 -0
- package/dist/core.js.map +1 -0
- package/dist/groups/auth.d.ts +3 -0
- package/dist/groups/auth.d.ts.map +1 -0
- package/dist/groups/auth.js +3 -0
- package/dist/groups/auth.js.map +1 -0
- package/dist/groups/core.d.ts +15 -0
- package/dist/groups/core.d.ts.map +1 -0
- package/dist/groups/core.js +13 -0
- package/dist/groups/core.js.map +1 -0
- package/dist/groups/mfa.d.ts +3 -0
- package/dist/groups/mfa.d.ts.map +1 -0
- package/dist/groups/mfa.js +3 -0
- package/dist/groups/mfa.js.map +1 -0
- package/dist/groups/oauth.d.ts +3 -0
- package/dist/groups/oauth.d.ts.map +1 -0
- package/dist/groups/oauth.js +3 -0
- package/dist/groups/oauth.js.map +1 -0
- package/dist/groups/password.d.ts +3 -0
- package/dist/groups/password.d.ts.map +1 -0
- package/dist/groups/password.js +3 -0
- package/dist/groups/password.js.map +1 -0
- package/dist/groups/session.d.ts +3 -0
- package/dist/groups/session.d.ts.map +1 -0
- package/dist/groups/session.js +3 -0
- package/dist/groups/session.js.map +1 -0
- package/dist/groups/tenants.d.ts +3 -0
- package/dist/groups/tenants.d.ts.map +1 -0
- package/dist/groups/tenants.js +3 -0
- package/dist/groups/tenants.js.map +1 -0
- package/dist/groups/users.d.ts +3 -0
- package/dist/groups/users.d.ts.map +1 -0
- package/dist/groups/users.js +3 -0
- package/dist/groups/users.js.map +1 -0
- package/dist/groups/verification.d.ts +3 -0
- package/dist/groups/verification.d.ts.map +1 -0
- package/dist/groups/verification.js +3 -0
- package/dist/groups/verification.js.map +1 -0
- package/dist/index.d.ts +701 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/index.d.ts +952 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +339 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/internal/responses.d.ts +262 -0
- package/dist/internal/responses.d.ts.map +1 -0
- package/dist/internal/responses.js +145 -0
- package/dist/internal/responses.js.map +1 -0
- package/dist/login-result.d.ts +20 -0
- package/dist/login-result.d.ts.map +1 -0
- package/dist/login-result.js +13 -0
- package/dist/login-result.js.map +1 -0
- package/dist/mfa.contract.d.ts +155 -0
- package/dist/mfa.contract.d.ts.map +1 -0
- package/dist/mfa.contract.js +73 -0
- package/dist/mfa.contract.js.map +1 -0
- package/dist/oauth.contract.d.ts +163 -0
- package/dist/oauth.contract.d.ts.map +1 -0
- package/dist/oauth.contract.js +65 -0
- package/dist/oauth.contract.js.map +1 -0
- package/dist/password.contract.d.ts +83 -0
- package/dist/password.contract.d.ts.map +1 -0
- package/dist/password.contract.js +46 -0
- package/dist/password.contract.js.map +1 -0
- package/dist/responses/auth.d.ts +19 -0
- package/dist/responses/auth.d.ts.map +1 -0
- package/dist/responses/auth.js +19 -0
- package/dist/responses/auth.js.map +1 -0
- package/dist/responses/core.d.ts +86 -0
- package/dist/responses/core.d.ts.map +1 -0
- package/dist/responses/core.js +72 -0
- package/dist/responses/core.js.map +1 -0
- package/dist/responses/mfa.d.ts +31 -0
- package/dist/responses/mfa.d.ts.map +1 -0
- package/dist/responses/mfa.js +24 -0
- package/dist/responses/mfa.js.map +1 -0
- package/dist/responses/oauth.d.ts +18 -0
- package/dist/responses/oauth.d.ts.map +1 -0
- package/dist/responses/oauth.js +13 -0
- package/dist/responses/oauth.js.map +1 -0
- package/dist/responses/session.d.ts +32 -0
- package/dist/responses/session.d.ts.map +1 -0
- package/dist/responses/session.js +19 -0
- package/dist/responses/session.js.map +1 -0
- package/dist/responses/tenant.d.ts +92 -0
- package/dist/responses/tenant.d.ts.map +1 -0
- package/dist/responses/tenant.js +66 -0
- package/dist/responses/tenant.js.map +1 -0
- package/dist/responses/verification.d.ts +9 -0
- package/dist/responses/verification.d.ts.map +1 -0
- package/dist/responses/verification.js +9 -0
- package/dist/responses/verification.js.map +1 -0
- package/dist/responses.d.ts +17 -0
- package/dist/responses.d.ts.map +1 -0
- package/dist/responses.js +17 -0
- package/dist/responses.js.map +1 -0
- package/dist/schemas.d.ts +18 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +18 -0
- package/dist/schemas.js.map +1 -0
- package/dist/session.contract.d.ts +97 -0
- package/dist/session.contract.d.ts.map +1 -0
- package/dist/session.contract.js +44 -0
- package/dist/session.contract.js.map +1 -0
- package/dist/tenants.contract.d.ts +403 -0
- package/dist/tenants.contract.d.ts.map +1 -0
- package/dist/tenants.contract.js +146 -0
- package/dist/tenants.contract.js.map +1 -0
- package/dist/users.contract.d.ts +63 -0
- package/dist/users.contract.d.ts.map +1 -0
- package/dist/users.contract.js +25 -0
- package/dist/users.contract.js.map +1 -0
- package/dist/verification.contract.d.ts +67 -0
- package/dist/verification.contract.d.ts.map +1 -0
- package/dist/verification.contract.js +35 -0
- package/dist/verification.contract.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth + session-bootstrap endpoints (the "auth" route group).
|
|
3
|
+
*
|
|
4
|
+
* `kind` marks how the typed client dispatches each one:
|
|
5
|
+
* - login → establishes a session via the Worker (authenticate, register,
|
|
6
|
+
* complete-challenge, complete-mfa, oauth callback)
|
|
7
|
+
* - exchange → re-issues tokens for the same session (select-tenant)
|
|
8
|
+
* - logout → clears the session
|
|
9
|
+
* - data → plain authenticated call (me, issue-mfa-challenge)
|
|
10
|
+
*
|
|
11
|
+
* Bodies mirror the real route schemas in adapter-plugin-hono so the route and
|
|
12
|
+
* the client validate/infer from the same shapes.
|
|
13
|
+
*/
|
|
14
|
+
import * as v from 'valibot';
|
|
15
|
+
export declare const authenticate: {
|
|
16
|
+
readonly method: "POST";
|
|
17
|
+
readonly path: "/auth/authenticate";
|
|
18
|
+
readonly kind: "login";
|
|
19
|
+
readonly public: true;
|
|
20
|
+
readonly body: v.ObjectSchema<{
|
|
21
|
+
readonly identityType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
22
|
+
readonly identityValue: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 320, undefined>]>;
|
|
23
|
+
readonly credentialType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
24
|
+
readonly credentialValue: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>, undefined>;
|
|
25
|
+
readonly metadata: v.OptionalSchema<v.RecordSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, v.UnknownSchema, undefined>, undefined>;
|
|
26
|
+
readonly country: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
27
|
+
readonly city: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
28
|
+
}, undefined>;
|
|
29
|
+
readonly response: v.UnionSchema<[v.ObjectSchema<{
|
|
30
|
+
readonly requiresChallenge: v.LiteralSchema<true, undefined>;
|
|
31
|
+
readonly challenge: v.ObjectSchema<{
|
|
32
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
33
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
34
|
+
readonly expiresAt: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
|
|
35
|
+
readonly data: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
|
|
36
|
+
}, undefined>;
|
|
37
|
+
}, undefined>, v.ObjectSchema<{
|
|
38
|
+
readonly requiresMfa: v.LiteralSchema<true, undefined>;
|
|
39
|
+
readonly mfa: v.ObjectSchema<{
|
|
40
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
41
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
42
|
+
readonly methods: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
43
|
+
readonly method: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
44
|
+
readonly expiresAt: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>;
|
|
45
|
+
readonly userId: v.StringSchema<undefined>;
|
|
46
|
+
}, undefined>;
|
|
47
|
+
}, undefined>, v.ObjectSchema<{
|
|
48
|
+
readonly accessToken: v.StringSchema<undefined>;
|
|
49
|
+
readonly refreshToken: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
50
|
+
readonly expiresAt: v.NumberSchema<undefined>;
|
|
51
|
+
}, undefined>], undefined>;
|
|
52
|
+
};
|
|
53
|
+
export declare const register: {
|
|
54
|
+
readonly method: "POST";
|
|
55
|
+
readonly path: "/auth/register";
|
|
56
|
+
readonly kind: "data";
|
|
57
|
+
readonly public: true;
|
|
58
|
+
readonly body: v.ObjectSchema<{
|
|
59
|
+
readonly identityType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
60
|
+
readonly identityValue: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 320, undefined>]>;
|
|
61
|
+
readonly credentialType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
62
|
+
readonly credentialValue: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>;
|
|
63
|
+
readonly displayName: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
64
|
+
readonly givenName: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
65
|
+
readonly familyName: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
66
|
+
readonly avatarUrl: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
67
|
+
readonly locale: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
68
|
+
readonly metadata: v.OptionalSchema<v.RecordSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, v.UnknownSchema, undefined>, undefined>;
|
|
69
|
+
}, undefined>;
|
|
70
|
+
readonly response: v.ObjectSchema<{
|
|
71
|
+
readonly userId: v.StringSchema<undefined>;
|
|
72
|
+
readonly verification: v.OptionalSchema<v.ObjectSchema<{
|
|
73
|
+
readonly channel: v.StringSchema<undefined>;
|
|
74
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
75
|
+
readonly expiresAt: v.StringSchema<undefined>;
|
|
76
|
+
readonly identityType: v.StringSchema<undefined>;
|
|
77
|
+
readonly identityValue: v.StringSchema<undefined>;
|
|
78
|
+
}, undefined>, undefined>;
|
|
79
|
+
}, undefined>;
|
|
80
|
+
};
|
|
81
|
+
export declare const completeChallenge: {
|
|
82
|
+
readonly method: "POST";
|
|
83
|
+
readonly path: "/auth/complete-challenge";
|
|
84
|
+
readonly kind: "login";
|
|
85
|
+
readonly public: true;
|
|
86
|
+
readonly body: v.ObjectSchema<{
|
|
87
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
88
|
+
readonly code: v.StringSchema<undefined>;
|
|
89
|
+
}, undefined>;
|
|
90
|
+
readonly response: v.UnionSchema<[v.ObjectSchema<{
|
|
91
|
+
readonly requiresChallenge: v.LiteralSchema<true, undefined>;
|
|
92
|
+
readonly challenge: v.ObjectSchema<{
|
|
93
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
94
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
95
|
+
readonly expiresAt: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
|
|
96
|
+
readonly data: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
|
|
97
|
+
}, undefined>;
|
|
98
|
+
}, undefined>, v.ObjectSchema<{
|
|
99
|
+
readonly requiresMfa: v.LiteralSchema<true, undefined>;
|
|
100
|
+
readonly mfa: v.ObjectSchema<{
|
|
101
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
102
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
103
|
+
readonly methods: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
104
|
+
readonly method: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
105
|
+
readonly expiresAt: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>;
|
|
106
|
+
readonly userId: v.StringSchema<undefined>;
|
|
107
|
+
}, undefined>;
|
|
108
|
+
}, undefined>, v.ObjectSchema<{
|
|
109
|
+
readonly accessToken: v.StringSchema<undefined>;
|
|
110
|
+
readonly refreshToken: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
111
|
+
readonly expiresAt: v.NumberSchema<undefined>;
|
|
112
|
+
}, undefined>], undefined>;
|
|
113
|
+
};
|
|
114
|
+
export declare const completeMfaChallenge: {
|
|
115
|
+
readonly method: "POST";
|
|
116
|
+
readonly path: "/auth/complete-mfa-challenge";
|
|
117
|
+
readonly kind: "login";
|
|
118
|
+
readonly public: true;
|
|
119
|
+
readonly body: v.ObjectSchema<{
|
|
120
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
121
|
+
readonly method: v.StringSchema<undefined>;
|
|
122
|
+
readonly code: v.StringSchema<undefined>;
|
|
123
|
+
}, undefined>;
|
|
124
|
+
readonly response: v.UnionSchema<[v.ObjectSchema<{
|
|
125
|
+
readonly requiresChallenge: v.LiteralSchema<true, undefined>;
|
|
126
|
+
readonly challenge: v.ObjectSchema<{
|
|
127
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
128
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
129
|
+
readonly expiresAt: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
|
|
130
|
+
readonly data: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
|
|
131
|
+
}, undefined>;
|
|
132
|
+
}, undefined>, v.ObjectSchema<{
|
|
133
|
+
readonly requiresMfa: v.LiteralSchema<true, undefined>;
|
|
134
|
+
readonly mfa: v.ObjectSchema<{
|
|
135
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
136
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
137
|
+
readonly methods: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
138
|
+
readonly method: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
139
|
+
readonly expiresAt: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>;
|
|
140
|
+
readonly userId: v.StringSchema<undefined>;
|
|
141
|
+
}, undefined>;
|
|
142
|
+
}, undefined>, v.ObjectSchema<{
|
|
143
|
+
readonly accessToken: v.StringSchema<undefined>;
|
|
144
|
+
readonly refreshToken: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
145
|
+
readonly expiresAt: v.NumberSchema<undefined>;
|
|
146
|
+
}, undefined>], undefined>;
|
|
147
|
+
};
|
|
148
|
+
export declare const issueMfaChallenge: {
|
|
149
|
+
readonly method: "POST";
|
|
150
|
+
readonly path: "/auth/issue-mfa-challenge";
|
|
151
|
+
readonly kind: "data";
|
|
152
|
+
readonly public: true;
|
|
153
|
+
readonly body: v.ObjectSchema<{
|
|
154
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
155
|
+
readonly method: v.StringSchema<undefined>;
|
|
156
|
+
readonly userId: v.StringSchema<undefined>;
|
|
157
|
+
}, undefined>;
|
|
158
|
+
readonly response: v.ObjectSchema<{
|
|
159
|
+
readonly maskedRecipient: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
160
|
+
readonly expiresAt: v.StringSchema<undefined>;
|
|
161
|
+
}, undefined>;
|
|
162
|
+
};
|
|
163
|
+
export declare const refresh: {
|
|
164
|
+
readonly method: "POST";
|
|
165
|
+
readonly path: "/auth/refresh";
|
|
166
|
+
readonly kind: "exchange";
|
|
167
|
+
readonly public: true;
|
|
168
|
+
};
|
|
169
|
+
export declare const logout: {
|
|
170
|
+
readonly method: "POST";
|
|
171
|
+
readonly path: "/auth/logout";
|
|
172
|
+
readonly kind: "logout";
|
|
173
|
+
readonly public: true;
|
|
174
|
+
};
|
|
175
|
+
export declare const me: {
|
|
176
|
+
readonly method: "GET";
|
|
177
|
+
readonly path: "/auth/me";
|
|
178
|
+
readonly kind: "data";
|
|
179
|
+
readonly response: v.ObjectSchema<{
|
|
180
|
+
readonly id: v.StringSchema<undefined>;
|
|
181
|
+
readonly contactEmail: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
182
|
+
readonly contactPhone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
183
|
+
readonly username: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
184
|
+
readonly displayName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
185
|
+
readonly givenName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
186
|
+
readonly familyName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
187
|
+
readonly avatarUrl: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
188
|
+
readonly locale: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
189
|
+
readonly metadata: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
190
|
+
readonly createdAt: v.StringSchema<undefined>;
|
|
191
|
+
readonly updatedAt: v.StringSchema<undefined>;
|
|
192
|
+
}, undefined>;
|
|
193
|
+
};
|
|
194
|
+
export declare const selectTenant: {
|
|
195
|
+
readonly method: "POST";
|
|
196
|
+
readonly path: "/auth/select-tenant";
|
|
197
|
+
readonly kind: "exchange";
|
|
198
|
+
readonly body: v.ObjectSchema<{
|
|
199
|
+
readonly tenantId: v.StringSchema<undefined>;
|
|
200
|
+
}, undefined>;
|
|
201
|
+
};
|
|
202
|
+
export declare const authContract: {
|
|
203
|
+
readonly authenticate: {
|
|
204
|
+
readonly method: "POST";
|
|
205
|
+
readonly path: "/auth/authenticate";
|
|
206
|
+
readonly kind: "login";
|
|
207
|
+
readonly public: true;
|
|
208
|
+
readonly body: v.ObjectSchema<{
|
|
209
|
+
readonly identityType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
210
|
+
readonly identityValue: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 320, undefined>]>;
|
|
211
|
+
readonly credentialType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
212
|
+
readonly credentialValue: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>, undefined>;
|
|
213
|
+
readonly metadata: v.OptionalSchema<v.RecordSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, v.UnknownSchema, undefined>, undefined>;
|
|
214
|
+
readonly country: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
215
|
+
readonly city: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
216
|
+
}, undefined>;
|
|
217
|
+
readonly response: v.UnionSchema<[v.ObjectSchema<{
|
|
218
|
+
readonly requiresChallenge: v.LiteralSchema<true, undefined>;
|
|
219
|
+
readonly challenge: v.ObjectSchema<{
|
|
220
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
221
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
222
|
+
readonly expiresAt: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
|
|
223
|
+
readonly data: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
|
|
224
|
+
}, undefined>;
|
|
225
|
+
}, undefined>, v.ObjectSchema<{
|
|
226
|
+
readonly requiresMfa: v.LiteralSchema<true, undefined>;
|
|
227
|
+
readonly mfa: v.ObjectSchema<{
|
|
228
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
229
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
230
|
+
readonly methods: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
231
|
+
readonly method: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
232
|
+
readonly expiresAt: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>;
|
|
233
|
+
readonly userId: v.StringSchema<undefined>;
|
|
234
|
+
}, undefined>;
|
|
235
|
+
}, undefined>, v.ObjectSchema<{
|
|
236
|
+
readonly accessToken: v.StringSchema<undefined>;
|
|
237
|
+
readonly refreshToken: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
238
|
+
readonly expiresAt: v.NumberSchema<undefined>;
|
|
239
|
+
}, undefined>], undefined>;
|
|
240
|
+
};
|
|
241
|
+
readonly register: {
|
|
242
|
+
readonly method: "POST";
|
|
243
|
+
readonly path: "/auth/register";
|
|
244
|
+
readonly kind: "data";
|
|
245
|
+
readonly public: true;
|
|
246
|
+
readonly body: v.ObjectSchema<{
|
|
247
|
+
readonly identityType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
248
|
+
readonly identityValue: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 320, undefined>]>;
|
|
249
|
+
readonly credentialType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
250
|
+
readonly credentialValue: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>;
|
|
251
|
+
readonly displayName: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
252
|
+
readonly givenName: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
253
|
+
readonly familyName: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
254
|
+
readonly avatarUrl: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
255
|
+
readonly locale: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
256
|
+
readonly metadata: v.OptionalSchema<v.RecordSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, number, undefined>]>, v.UnknownSchema, undefined>, undefined>;
|
|
257
|
+
}, undefined>;
|
|
258
|
+
readonly response: v.ObjectSchema<{
|
|
259
|
+
readonly userId: v.StringSchema<undefined>;
|
|
260
|
+
readonly verification: v.OptionalSchema<v.ObjectSchema<{
|
|
261
|
+
readonly channel: v.StringSchema<undefined>;
|
|
262
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
263
|
+
readonly expiresAt: v.StringSchema<undefined>;
|
|
264
|
+
readonly identityType: v.StringSchema<undefined>;
|
|
265
|
+
readonly identityValue: v.StringSchema<undefined>;
|
|
266
|
+
}, undefined>, undefined>;
|
|
267
|
+
}, undefined>;
|
|
268
|
+
};
|
|
269
|
+
readonly completeChallenge: {
|
|
270
|
+
readonly method: "POST";
|
|
271
|
+
readonly path: "/auth/complete-challenge";
|
|
272
|
+
readonly kind: "login";
|
|
273
|
+
readonly public: true;
|
|
274
|
+
readonly body: v.ObjectSchema<{
|
|
275
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
276
|
+
readonly code: v.StringSchema<undefined>;
|
|
277
|
+
}, undefined>;
|
|
278
|
+
readonly response: v.UnionSchema<[v.ObjectSchema<{
|
|
279
|
+
readonly requiresChallenge: v.LiteralSchema<true, undefined>;
|
|
280
|
+
readonly challenge: v.ObjectSchema<{
|
|
281
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
282
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
283
|
+
readonly expiresAt: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
|
|
284
|
+
readonly data: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
|
|
285
|
+
}, undefined>;
|
|
286
|
+
}, undefined>, v.ObjectSchema<{
|
|
287
|
+
readonly requiresMfa: v.LiteralSchema<true, undefined>;
|
|
288
|
+
readonly mfa: v.ObjectSchema<{
|
|
289
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
290
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
291
|
+
readonly methods: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
292
|
+
readonly method: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
293
|
+
readonly expiresAt: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>;
|
|
294
|
+
readonly userId: v.StringSchema<undefined>;
|
|
295
|
+
}, undefined>;
|
|
296
|
+
}, undefined>, v.ObjectSchema<{
|
|
297
|
+
readonly accessToken: v.StringSchema<undefined>;
|
|
298
|
+
readonly refreshToken: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
299
|
+
readonly expiresAt: v.NumberSchema<undefined>;
|
|
300
|
+
}, undefined>], undefined>;
|
|
301
|
+
};
|
|
302
|
+
readonly completeMfaChallenge: {
|
|
303
|
+
readonly method: "POST";
|
|
304
|
+
readonly path: "/auth/complete-mfa-challenge";
|
|
305
|
+
readonly kind: "login";
|
|
306
|
+
readonly public: true;
|
|
307
|
+
readonly body: v.ObjectSchema<{
|
|
308
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
309
|
+
readonly method: v.StringSchema<undefined>;
|
|
310
|
+
readonly code: v.StringSchema<undefined>;
|
|
311
|
+
}, undefined>;
|
|
312
|
+
readonly response: v.UnionSchema<[v.ObjectSchema<{
|
|
313
|
+
readonly requiresChallenge: v.LiteralSchema<true, undefined>;
|
|
314
|
+
readonly challenge: v.ObjectSchema<{
|
|
315
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
316
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
317
|
+
readonly expiresAt: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
|
|
318
|
+
readonly data: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
|
|
319
|
+
}, undefined>;
|
|
320
|
+
}, undefined>, v.ObjectSchema<{
|
|
321
|
+
readonly requiresMfa: v.LiteralSchema<true, undefined>;
|
|
322
|
+
readonly mfa: v.ObjectSchema<{
|
|
323
|
+
readonly phase: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
324
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
325
|
+
readonly methods: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
326
|
+
readonly method: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
327
|
+
readonly expiresAt: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>;
|
|
328
|
+
readonly userId: v.StringSchema<undefined>;
|
|
329
|
+
}, undefined>;
|
|
330
|
+
}, undefined>, v.ObjectSchema<{
|
|
331
|
+
readonly accessToken: v.StringSchema<undefined>;
|
|
332
|
+
readonly refreshToken: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
333
|
+
readonly expiresAt: v.NumberSchema<undefined>;
|
|
334
|
+
}, undefined>], undefined>;
|
|
335
|
+
};
|
|
336
|
+
readonly issueMfaChallenge: {
|
|
337
|
+
readonly method: "POST";
|
|
338
|
+
readonly path: "/auth/issue-mfa-challenge";
|
|
339
|
+
readonly kind: "data";
|
|
340
|
+
readonly public: true;
|
|
341
|
+
readonly body: v.ObjectSchema<{
|
|
342
|
+
readonly challengeId: v.StringSchema<undefined>;
|
|
343
|
+
readonly method: v.StringSchema<undefined>;
|
|
344
|
+
readonly userId: v.StringSchema<undefined>;
|
|
345
|
+
}, undefined>;
|
|
346
|
+
readonly response: v.ObjectSchema<{
|
|
347
|
+
readonly maskedRecipient: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
348
|
+
readonly expiresAt: v.StringSchema<undefined>;
|
|
349
|
+
}, undefined>;
|
|
350
|
+
};
|
|
351
|
+
readonly refresh: {
|
|
352
|
+
readonly method: "POST";
|
|
353
|
+
readonly path: "/auth/refresh";
|
|
354
|
+
readonly kind: "exchange";
|
|
355
|
+
readonly public: true;
|
|
356
|
+
};
|
|
357
|
+
readonly logout: {
|
|
358
|
+
readonly method: "POST";
|
|
359
|
+
readonly path: "/auth/logout";
|
|
360
|
+
readonly kind: "logout";
|
|
361
|
+
readonly public: true;
|
|
362
|
+
};
|
|
363
|
+
readonly me: {
|
|
364
|
+
readonly method: "GET";
|
|
365
|
+
readonly path: "/auth/me";
|
|
366
|
+
readonly kind: "data";
|
|
367
|
+
readonly response: v.ObjectSchema<{
|
|
368
|
+
readonly id: v.StringSchema<undefined>;
|
|
369
|
+
readonly contactEmail: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
370
|
+
readonly contactPhone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
371
|
+
readonly username: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
372
|
+
readonly displayName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
373
|
+
readonly givenName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
374
|
+
readonly familyName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
375
|
+
readonly avatarUrl: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
376
|
+
readonly locale: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
377
|
+
readonly metadata: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
378
|
+
readonly createdAt: v.StringSchema<undefined>;
|
|
379
|
+
readonly updatedAt: v.StringSchema<undefined>;
|
|
380
|
+
}, undefined>;
|
|
381
|
+
};
|
|
382
|
+
readonly selectTenant: {
|
|
383
|
+
readonly method: "POST";
|
|
384
|
+
readonly path: "/auth/select-tenant";
|
|
385
|
+
readonly kind: "exchange";
|
|
386
|
+
readonly body: v.ObjectSchema<{
|
|
387
|
+
readonly tenantId: v.StringSchema<undefined>;
|
|
388
|
+
}, undefined>;
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
//# sourceMappingURL=auth.contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.contract.d.ts","sourceRoot":"","sources":["../src/auth.contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAO5B,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAevB,CAAA;AAKF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkBnB,CAAA;AAGF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAU5B,CAAA;AAGF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAW/B,CAAA;AAGF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;CAW5B,CAAA;AAIF,eAAO,MAAM,OAAO;;;;;CAKlB,CAAA;AAGF,eAAO,MAAM,MAAM;;;;;CAKjB,CAAA;AAGF,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;CAKb,CAAA;AAGF,eAAO,MAAM,YAAY;;;;;;;CAOvB,CAAA;AAEF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAUf,CAAA"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth + session-bootstrap endpoints (the "auth" route group).
|
|
3
|
+
*
|
|
4
|
+
* `kind` marks how the typed client dispatches each one:
|
|
5
|
+
* - login → establishes a session via the Worker (authenticate, register,
|
|
6
|
+
* complete-challenge, complete-mfa, oauth callback)
|
|
7
|
+
* - exchange → re-issues tokens for the same session (select-tenant)
|
|
8
|
+
* - logout → clears the session
|
|
9
|
+
* - data → plain authenticated call (me, issue-mfa-challenge)
|
|
10
|
+
*
|
|
11
|
+
* Bodies mirror the real route schemas in adapter-plugin-hono so the route and
|
|
12
|
+
* the client validate/infer from the same shapes.
|
|
13
|
+
*/
|
|
14
|
+
import * as v from 'valibot';
|
|
15
|
+
import { endpoint } from './core';
|
|
16
|
+
import { loginResultResponse, userProfileResponse } from './responses/core';
|
|
17
|
+
import { issueMfaResponse, registerResponse } from './responses/auth';
|
|
18
|
+
import { displayString, identityString, secretString, shortString, textString } from './schemas';
|
|
19
|
+
// ── /auth/authenticate (login) ────────────────────────────────────────────────
|
|
20
|
+
export const authenticate = endpoint({
|
|
21
|
+
method: 'POST',
|
|
22
|
+
path: '/auth/authenticate',
|
|
23
|
+
kind: 'login',
|
|
24
|
+
public: true,
|
|
25
|
+
body: v.object({
|
|
26
|
+
identityType: shortString(),
|
|
27
|
+
identityValue: identityString,
|
|
28
|
+
credentialType: shortString(),
|
|
29
|
+
credentialValue: v.optional(secretString),
|
|
30
|
+
metadata: v.optional(v.record(shortString(), v.unknown())),
|
|
31
|
+
country: v.optional(shortString()),
|
|
32
|
+
city: v.optional(shortString())
|
|
33
|
+
}),
|
|
34
|
+
response: loginResultResponse
|
|
35
|
+
});
|
|
36
|
+
// ── /auth/register (data) ─────────────────────────────────────────────────────
|
|
37
|
+
// Registration does NOT establish a session — it returns { userId, verification? }
|
|
38
|
+
// and the user verifies + logs in afterwards. So it's a plain data call, not login.
|
|
39
|
+
export const register = endpoint({
|
|
40
|
+
method: 'POST',
|
|
41
|
+
path: '/auth/register',
|
|
42
|
+
kind: 'data',
|
|
43
|
+
public: true,
|
|
44
|
+
body: v.object({
|
|
45
|
+
identityType: shortString(),
|
|
46
|
+
identityValue: identityString,
|
|
47
|
+
credentialType: shortString(),
|
|
48
|
+
credentialValue: secretString,
|
|
49
|
+
displayName: v.optional(displayString()),
|
|
50
|
+
givenName: v.optional(displayString()),
|
|
51
|
+
familyName: v.optional(displayString()),
|
|
52
|
+
avatarUrl: v.optional(textString(2048)),
|
|
53
|
+
locale: v.optional(shortString()),
|
|
54
|
+
metadata: v.optional(v.record(shortString(), v.unknown()))
|
|
55
|
+
}),
|
|
56
|
+
response: registerResponse
|
|
57
|
+
});
|
|
58
|
+
// ── /auth/complete-challenge (login) ──────────────────────────────────────────
|
|
59
|
+
export const completeChallenge = endpoint({
|
|
60
|
+
method: 'POST',
|
|
61
|
+
path: '/auth/complete-challenge',
|
|
62
|
+
kind: 'login',
|
|
63
|
+
public: true,
|
|
64
|
+
body: v.object({
|
|
65
|
+
challengeId: v.string(),
|
|
66
|
+
code: v.string()
|
|
67
|
+
}),
|
|
68
|
+
response: loginResultResponse
|
|
69
|
+
});
|
|
70
|
+
// ── /auth/complete-mfa-challenge (login) ──────────────────────────────────────
|
|
71
|
+
export const completeMfaChallenge = endpoint({
|
|
72
|
+
method: 'POST',
|
|
73
|
+
path: '/auth/complete-mfa-challenge',
|
|
74
|
+
kind: 'login',
|
|
75
|
+
public: true,
|
|
76
|
+
body: v.object({
|
|
77
|
+
challengeId: v.string(),
|
|
78
|
+
method: v.string(),
|
|
79
|
+
code: v.string()
|
|
80
|
+
}),
|
|
81
|
+
response: loginResultResponse
|
|
82
|
+
});
|
|
83
|
+
// ── /auth/issue-mfa-challenge (data — public, but plain HTTP) ──────────────────
|
|
84
|
+
export const issueMfaChallenge = endpoint({
|
|
85
|
+
method: 'POST',
|
|
86
|
+
path: '/auth/issue-mfa-challenge',
|
|
87
|
+
kind: 'data',
|
|
88
|
+
public: true,
|
|
89
|
+
body: v.object({
|
|
90
|
+
challengeId: v.string(),
|
|
91
|
+
method: v.string(),
|
|
92
|
+
userId: v.string()
|
|
93
|
+
}),
|
|
94
|
+
response: issueMfaResponse
|
|
95
|
+
});
|
|
96
|
+
// ── /auth/refresh — handled by the transport's refresh path, not the proxy.
|
|
97
|
+
// Declared for completeness/registry diffing.
|
|
98
|
+
export const refresh = endpoint({
|
|
99
|
+
method: 'POST',
|
|
100
|
+
path: '/auth/refresh',
|
|
101
|
+
kind: 'exchange',
|
|
102
|
+
public: true
|
|
103
|
+
});
|
|
104
|
+
// ── /auth/logout (logout) ─────────────────────────────────────────────────────
|
|
105
|
+
export const logout = endpoint({
|
|
106
|
+
method: 'POST',
|
|
107
|
+
path: '/auth/logout',
|
|
108
|
+
kind: 'logout',
|
|
109
|
+
public: true
|
|
110
|
+
});
|
|
111
|
+
// ── /auth/me (data) ───────────────────────────────────────────────────────────
|
|
112
|
+
export const me = endpoint({
|
|
113
|
+
method: 'GET',
|
|
114
|
+
path: '/auth/me',
|
|
115
|
+
kind: 'data',
|
|
116
|
+
response: userProfileResponse
|
|
117
|
+
});
|
|
118
|
+
// ── /auth/select-tenant (exchange) ────────────────────────────────────────────
|
|
119
|
+
export const selectTenant = endpoint({
|
|
120
|
+
method: 'POST',
|
|
121
|
+
path: '/auth/select-tenant',
|
|
122
|
+
kind: 'exchange',
|
|
123
|
+
body: v.object({
|
|
124
|
+
tenantId: v.string()
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
export const authContract = {
|
|
128
|
+
authenticate,
|
|
129
|
+
register,
|
|
130
|
+
completeChallenge,
|
|
131
|
+
completeMfaChallenge,
|
|
132
|
+
issueMfaChallenge,
|
|
133
|
+
refresh,
|
|
134
|
+
logout,
|
|
135
|
+
me,
|
|
136
|
+
selectTenant
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=auth.contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.contract.js","sourceRoot":"","sources":["../src/auth.contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;A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ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract core — the shape every endpoint declaration shares.
|
|
3
|
+
*
|
|
4
|
+
* One `Endpoint` is the single source of truth for a route: its method, path
|
|
5
|
+
* (with `:params`), how the typed client must invoke it (`kind`), and optional
|
|
6
|
+
* valibot schemas for the request body and response. The backend route imports
|
|
7
|
+
* the same object to validate; the frontend client imports it to infer types
|
|
8
|
+
* and build the URL. They cannot drift because they share this declaration.
|
|
9
|
+
*/
|
|
10
|
+
import type { GenericSchema } from 'valibot';
|
|
11
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
12
|
+
/**
|
|
13
|
+
* How the typed client must dispatch this endpoint.
|
|
14
|
+
*
|
|
15
|
+
* - `data` → plain authenticated HTTP via transport.callJson (most routes).
|
|
16
|
+
* - `login` → transport.login() — establishes a session (touches Worker token storage).
|
|
17
|
+
* - `exchange` → transport.exchangeToken() — re-issues tokens (select-tenant, etc.).
|
|
18
|
+
* - `logout` → transport.logout().
|
|
19
|
+
*
|
|
20
|
+
* Auth-lifecycle kinds exist because those flows must go through the Worker's
|
|
21
|
+
* refresh-token handling; they can't be plain `callJson`. The discriminator lets
|
|
22
|
+
* the proxy route them automatically instead of hand-writing each one.
|
|
23
|
+
*/
|
|
24
|
+
export type EndpointKind = 'data' | 'login' | 'exchange' | 'logout';
|
|
25
|
+
export interface Endpoint<Body = unknown, Resp = unknown, Params extends string = string, Query = unknown> {
|
|
26
|
+
method: HttpMethod;
|
|
27
|
+
/** Path with optional `:params`, e.g. '/tenants/:tenantId/invites'. */
|
|
28
|
+
path: string;
|
|
29
|
+
kind: EndpointKind;
|
|
30
|
+
/** Request body schema (also used by the backend route to validate). */
|
|
31
|
+
body?: GenericSchema<unknown, Body>;
|
|
32
|
+
/** Response data schema — when present, the client return type is inferred from it. */
|
|
33
|
+
response?: GenericSchema<unknown, Resp>;
|
|
34
|
+
/** Query schema (optional). */
|
|
35
|
+
query?: GenericSchema<unknown, Query>;
|
|
36
|
+
/** Public (no access token attached). Default: false. */
|
|
37
|
+
public?: boolean;
|
|
38
|
+
/** Phantom marker carrying the path-param union for type inference. */
|
|
39
|
+
readonly __params?: Params;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Helper to declare an endpoint with inference preserved. Using a function (vs a
|
|
43
|
+
* bare object literal) keeps the generic params inferred from the schemas while
|
|
44
|
+
* still returning a precisely-typed `Endpoint`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function endpoint<const E extends Endpoint<Body, Resp, Params, Query>, Body = unknown, Resp = unknown, Params extends string = string, Query = unknown>(e: E): E;
|
|
47
|
+
/** Extract `:param` names from a path as a string union (e.g. 'tenantId'). */
|
|
48
|
+
export type PathParams<P extends string> = P extends `${string}:${infer Param}/${infer Rest}` ? Param | PathParams<`/${Rest}`> : P extends `${string}:${infer Param}` ? Param : never;
|
|
49
|
+
/** Fill `:params` in a path with concrete values. */
|
|
50
|
+
export declare function fillPath(path: string, params?: Record<string, string | number>): string;
|
|
51
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEpE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAA;AAEnE,MAAM,WAAW,QAAQ,CACvB,IAAI,GAAG,OAAO,EACd,IAAI,GAAG,OAAO,EACd,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,KAAK,GAAG,OAAO;IAEf,MAAM,EAAE,UAAU,CAAA;IAClB,u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
|
3
|
+
*
|
|
4
|
+
* One `Endpoint` is the single source of truth for a route: its method, path
|
|
5
|
+
* (with `:params`), how the typed client must invoke it (`kind`), and optional
|
|
6
|
+
* valibot schemas for the request body and response. The backend route imports
|
|
7
|
+
* the same object to validate; the frontend client imports it to infer types
|
|
8
|
+
* and build the URL. They cannot drift because they share this declaration.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Helper to declare an endpoint with inference preserved. Using a function (vs a
|
|
12
|
+
* bare object literal) keeps the generic params inferred from the schemas while
|
|
13
|
+
* still returning a precisely-typed `Endpoint`.
|
|
14
|
+
*/
|
|
15
|
+
export function endpoint(e) {
|
|
16
|
+
return e;
|
|
17
|
+
}
|
|
18
|
+
/** Fill `:params` in a path with concrete values. */
|
|
19
|
+
export function fillPath(path, params) {
|
|
20
|
+
if (!params)
|
|
21
|
+
return path;
|
|
22
|
+
return path.replace(/:([A-Za-z0-9_]+)/g, (_m, key) => {
|
|
23
|
+
const v = params[key];
|
|
24
|
+
if (v === undefined)
|
|
25
|
+
throw new Error(`Missing path param ':${key}' for ${path}`);
|
|
26
|
+
return encodeURIComponent(String(v));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0CH;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAMtB,CAAI;IACJ,OAAO,CAAC,CAAA;AACV,CAAC;AASD,qDAAqD;AACrD,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,MAAwC;IAC7E,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxB,OAAO,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC,EAAE,EAAE,GAAW,EAAE,EAAE;QAC3D,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;QACrB,IAAI,CAAC,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,SAAS,IAAI,EAAE,CAAC,CAAA;QAChF,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/groups/auth.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/groups/auth.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA"}
|