@cauth/express 0.0.2 → 0.0.4
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/index.d.ts +44 -54
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./express-BgF1jv36.js";
|
|
2
|
-
import
|
|
2
|
+
import { NextFunction, Request, Response } from "express";
|
|
3
3
|
import z$1, { z } from "zod";
|
|
4
4
|
import ms from "ms";
|
|
5
5
|
|
|
@@ -127,7 +127,7 @@ interface DatabaseContract {
|
|
|
127
127
|
//#region ../core/src/types/config.t.d.ts
|
|
128
128
|
declare const CAuthOptionsSchema: z$1.ZodObject<{
|
|
129
129
|
dbContractor: z$1.ZodCustom<DatabaseContract, DatabaseContract>;
|
|
130
|
-
routeContractor: z$1.ZodCustom<RoutesContract
|
|
130
|
+
routeContractor: z$1.ZodCustom<RoutesContract<(...args: any[]) => any>, RoutesContract<(...args: any[]) => any>>;
|
|
131
131
|
roles: z$1.ZodArray<z$1.ZodString>;
|
|
132
132
|
jwtConfig: z$1.ZodObject<{
|
|
133
133
|
refreshTokenSecret: z$1.ZodString;
|
|
@@ -176,55 +176,44 @@ declare const ChangePasswordSchema: z.ZodObject<{
|
|
|
176
176
|
type ChangePasswordSchemaType = z.infer<typeof ChangePasswordSchema>;
|
|
177
177
|
//#endregion
|
|
178
178
|
//#region ../core/src/cauth.d.ts
|
|
179
|
-
declare class _CAuth<T extends string[]> {
|
|
179
|
+
declare class _CAuth<T extends string[], TContractor extends RoutesContract<any> = RoutesContract<any>> {
|
|
180
180
|
#private;
|
|
181
181
|
constructor(config: Omit<CAuthOptions, 'roles'> & {
|
|
182
182
|
roles: T;
|
|
183
|
+
routeContractor: TContractor;
|
|
183
184
|
});
|
|
184
185
|
get RoleType(): T[number];
|
|
185
186
|
/**
|
|
186
|
-
* @description
|
|
187
|
-
*
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
* @description Auth guard middleware — roles optional.
|
|
188
|
+
* Automatically typed as the handler type from the contractor (e.g. Express.RequestHandler).
|
|
189
|
+
*/
|
|
190
|
+
Guard: (roles?: Array<T[number]>) => (...args: any[]) => any;
|
|
191
|
+
/**
|
|
192
|
+
* Route Handlers — typed from the contractor automatically.
|
|
191
193
|
*/
|
|
192
|
-
Guard: (roles?: Array<T[number]>) => any;
|
|
193
194
|
Routes: {
|
|
194
|
-
Register: () =>
|
|
195
|
-
Login: () =>
|
|
196
|
-
Logout: () =>
|
|
197
|
-
Refresh: () =>
|
|
198
|
-
ChangePassword: (userId: string) =>
|
|
195
|
+
Register: () => ReturnType<TContractor["Register"]>;
|
|
196
|
+
Login: () => ReturnType<TContractor["Login"]>;
|
|
197
|
+
Logout: () => ReturnType<TContractor["Logout"]>;
|
|
198
|
+
Refresh: () => ReturnType<TContractor["Refresh"]>;
|
|
199
|
+
ChangePassword: (userId: string) => ReturnType<TContractor["ChangePassword"]>;
|
|
199
200
|
};
|
|
200
201
|
FN: {
|
|
201
|
-
Login: ({
|
|
202
|
-
...args
|
|
203
|
-
}: LoginSchemaType) => Promise<Result$1<{
|
|
202
|
+
Login: (args: LoginSchemaType) => Promise<Result$1<{
|
|
204
203
|
account: Account;
|
|
205
204
|
tokens: Tokens;
|
|
206
205
|
}>>;
|
|
207
|
-
Register: ({
|
|
208
|
-
...args
|
|
209
|
-
}: RegisterSchemaType) => Promise<Result<{
|
|
206
|
+
Register: (args: RegisterSchemaType) => Promise<Result<{
|
|
210
207
|
account: Account;
|
|
211
208
|
tokens: Tokens;
|
|
212
209
|
}>>;
|
|
213
|
-
Logout: (
|
|
214
|
-
|
|
215
|
-
}: LogoutSchemaType) => Promise<Result<any>>;
|
|
216
|
-
Refresh: ({
|
|
217
|
-
...args
|
|
218
|
-
}: RefreshTokenSchemaType) => Promise<Result$1<{
|
|
210
|
+
Logout: (args: LogoutSchemaType) => Promise<Result<any>>;
|
|
211
|
+
Refresh: (args: RefreshTokenSchemaType) => Promise<Result$1<{
|
|
219
212
|
account: Account;
|
|
220
213
|
tokens: Tokens;
|
|
221
214
|
}>>;
|
|
222
|
-
ChangePassword: (
|
|
223
|
-
|
|
224
|
-
}: ChangePasswordSchemaType) => Promise<Result<unknown>>;
|
|
225
|
-
RequestOTPCode: ({
|
|
226
|
-
...args
|
|
227
|
-
}: Omit<LoginSchemaType, "password"> & {
|
|
215
|
+
ChangePassword: (args: ChangePasswordSchemaType) => Promise<Result<unknown>>;
|
|
216
|
+
RequestOTPCode: (args: Omit<LoginSchemaType, "password"> & {
|
|
228
217
|
password?: string;
|
|
229
218
|
usePassword?: boolean;
|
|
230
219
|
otpPurpose: OtpPurpose;
|
|
@@ -232,17 +221,13 @@ declare class _CAuth<T extends string[]> {
|
|
|
232
221
|
id: string;
|
|
233
222
|
code: string;
|
|
234
223
|
}>>;
|
|
235
|
-
LoginWithOTP: ({
|
|
236
|
-
...args
|
|
237
|
-
}: Omit<LoginSchemaType, "password"> & {
|
|
224
|
+
LoginWithOTP: (args: Omit<LoginSchemaType, "password"> & {
|
|
238
225
|
code: string;
|
|
239
226
|
}) => Promise<Result<{
|
|
240
227
|
account: Account;
|
|
241
228
|
tokens: Tokens;
|
|
242
229
|
}>>;
|
|
243
|
-
VerifyOTP: ({
|
|
244
|
-
...args
|
|
245
|
-
}: {
|
|
230
|
+
VerifyOTP: (args: {
|
|
246
231
|
id: string;
|
|
247
232
|
code: string;
|
|
248
233
|
otpPurpose: OtpPurpose;
|
|
@@ -257,8 +242,8 @@ declare class _CAuth<T extends string[]> {
|
|
|
257
242
|
accessToken: string;
|
|
258
243
|
refreshToken: string;
|
|
259
244
|
}>;
|
|
260
|
-
VerifyRefreshToken: <
|
|
261
|
-
VerifyAccessToken: <
|
|
245
|
+
VerifyRefreshToken: <R>(token: any) => Promise<R | null>;
|
|
246
|
+
VerifyAccessToken: <R>(token: any) => Promise<R | null>;
|
|
262
247
|
};
|
|
263
248
|
}
|
|
264
249
|
//#endregion
|
|
@@ -272,59 +257,64 @@ type AuthGuardDeps = {
|
|
|
272
257
|
tokens: _CAuth<any>['Tokens'];
|
|
273
258
|
roles?: Array<string>;
|
|
274
259
|
};
|
|
275
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Generic RoutesContract
|
|
262
|
+
* THandler is generic, defaults to any function
|
|
263
|
+
*/
|
|
264
|
+
interface RoutesContract<THandler extends (...args: any[]) => any = (...args: any[]) => any> {
|
|
276
265
|
Login({
|
|
277
266
|
...config
|
|
278
|
-
}: RouteDeps):
|
|
267
|
+
}: RouteDeps): THandler;
|
|
279
268
|
Register({
|
|
280
269
|
...config
|
|
281
|
-
}: RouteDeps):
|
|
270
|
+
}: RouteDeps): THandler;
|
|
282
271
|
Logout({
|
|
283
272
|
...config
|
|
284
|
-
}: RouteDeps):
|
|
273
|
+
}: RouteDeps): THandler;
|
|
285
274
|
Guard({
|
|
286
275
|
...config
|
|
287
|
-
}: AuthGuardDeps):
|
|
276
|
+
}: AuthGuardDeps): THandler;
|
|
288
277
|
Refresh({
|
|
289
278
|
...config
|
|
290
|
-
}: AuthGuardDeps):
|
|
279
|
+
}: AuthGuardDeps): THandler;
|
|
291
280
|
ChangePassword({
|
|
292
281
|
...config
|
|
293
282
|
}: RouteDeps & {
|
|
294
283
|
userId: string;
|
|
295
|
-
}):
|
|
284
|
+
}): THandler;
|
|
296
285
|
}
|
|
297
286
|
//#endregion
|
|
298
287
|
//#region src/express.contractor.d.ts
|
|
299
|
-
|
|
288
|
+
type OptionalNextHandler = (req: Request, res: Response, next?: NextFunction) => any;
|
|
289
|
+
declare class ExpressContractor<THandler extends (...args: any[]) => any = OptionalNextHandler> implements RoutesContract<THandler> {
|
|
300
290
|
Register: ({
|
|
301
291
|
config,
|
|
302
292
|
tokens
|
|
303
|
-
}: RouteDeps) =>
|
|
293
|
+
}: RouteDeps) => THandler;
|
|
304
294
|
Login: ({
|
|
305
295
|
config,
|
|
306
296
|
tokens
|
|
307
|
-
}: RouteDeps) =>
|
|
297
|
+
}: RouteDeps) => THandler;
|
|
308
298
|
Logout: ({
|
|
309
299
|
config,
|
|
310
300
|
tokens
|
|
311
|
-
}: RouteDeps) =>
|
|
301
|
+
}: RouteDeps) => THandler;
|
|
312
302
|
Refresh: ({
|
|
313
303
|
config,
|
|
314
304
|
tokens
|
|
315
|
-
}: RouteDeps) =>
|
|
305
|
+
}: RouteDeps) => THandler;
|
|
316
306
|
ChangePassword: ({
|
|
317
307
|
config,
|
|
318
308
|
tokens,
|
|
319
309
|
userId
|
|
320
310
|
}: RouteDeps & {
|
|
321
311
|
userId: string;
|
|
322
|
-
}) =>
|
|
312
|
+
}) => THandler;
|
|
323
313
|
Guard: ({
|
|
324
314
|
config,
|
|
325
315
|
tokens,
|
|
326
316
|
roles
|
|
327
|
-
}: AuthGuardDeps) =>
|
|
317
|
+
}: AuthGuardDeps) => THandler;
|
|
328
318
|
}
|
|
329
319
|
//#endregion
|
|
330
320
|
export { ExpressContractor };
|