@cauth/express 0.0.3 → 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 +25 -39
- 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
|
|
|
@@ -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
|
-
* If 'roles' is empty it allows all authenticated users, without respecting specific role
|
|
189
|
-
*
|
|
190
|
-
* @default undefined
|
|
187
|
+
* @description Auth guard middleware — roles optional.
|
|
188
|
+
* Automatically typed as the handler type from the contractor (e.g. Express.RequestHandler).
|
|
191
189
|
*/
|
|
192
190
|
Guard: (roles?: Array<T[number]>) => (...args: any[]) => any;
|
|
191
|
+
/**
|
|
192
|
+
* Route Handlers — typed from the contractor automatically.
|
|
193
|
+
*/
|
|
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
|
|
@@ -300,7 +285,8 @@ interface RoutesContract<THandler extends (...args: any[]) => any = (...args: an
|
|
|
300
285
|
}
|
|
301
286
|
//#endregion
|
|
302
287
|
//#region src/express.contractor.d.ts
|
|
303
|
-
|
|
288
|
+
type OptionalNextHandler = (req: Request, res: Response, next?: NextFunction) => any;
|
|
289
|
+
declare class ExpressContractor<THandler extends (...args: any[]) => any = OptionalNextHandler> implements RoutesContract<THandler> {
|
|
304
290
|
Register: ({
|
|
305
291
|
config,
|
|
306
292
|
tokens
|