@cauth/core 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.
Files changed (2) hide show
  1. package/dist/index.d.ts +23 -17
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -194,33 +194,37 @@ type AuthGuardDeps = {
194
194
  tokens: _CAuth<any>['Tokens'];
195
195
  roles?: Array<string>;
196
196
  };
197
- interface RoutesContract {
197
+ /**
198
+ * Generic RoutesContract
199
+ * THandler is generic, defaults to any function
200
+ */
201
+ interface RoutesContract<THandler extends (...args: any[]) => any = (...args: any[]) => any> {
198
202
  Login({
199
203
  ...config
200
- }: RouteDeps): any;
204
+ }: RouteDeps): THandler;
201
205
  Register({
202
206
  ...config
203
- }: RouteDeps): any;
207
+ }: RouteDeps): THandler;
204
208
  Logout({
205
209
  ...config
206
- }: RouteDeps): any;
210
+ }: RouteDeps): THandler;
207
211
  Guard({
208
212
  ...config
209
- }: AuthGuardDeps): any;
213
+ }: AuthGuardDeps): THandler;
210
214
  Refresh({
211
215
  ...config
212
- }: AuthGuardDeps): any;
216
+ }: AuthGuardDeps): THandler;
213
217
  ChangePassword({
214
218
  ...config
215
219
  }: RouteDeps & {
216
220
  userId: string;
217
- }): any;
221
+ }): THandler;
218
222
  }
219
223
  //#endregion
220
224
  //#region src/types/config.t.d.ts
221
225
  declare const CAuthOptionsSchema: z$1.ZodObject<{
222
226
  dbContractor: z$1.ZodCustom<DatabaseContract, DatabaseContract>;
223
- routeContractor: z$1.ZodCustom<RoutesContract, RoutesContract>;
227
+ routeContractor: z$1.ZodCustom<RoutesContract<(...args: any[]) => any>, RoutesContract<(...args: any[]) => any>>;
224
228
  roles: z$1.ZodArray<z$1.ZodString>;
225
229
  jwtConfig: z$1.ZodObject<{
226
230
  refreshTokenSecret: z$1.ZodString;
@@ -269,10 +273,11 @@ declare const ChangePasswordSchema: z.ZodObject<{
269
273
  type ChangePasswordSchemaType = z.infer<typeof ChangePasswordSchema>;
270
274
  //#endregion
271
275
  //#region src/cauth.d.ts
272
- declare class _CAuth<T extends string[]> {
276
+ declare class _CAuth<T extends string[], TContractor extends RoutesContract<any> = RoutesContract<any>> {
273
277
  #private;
274
278
  constructor(config: Omit<CAuthOptions, 'roles'> & {
275
279
  roles: T;
280
+ routeContractor: TContractor;
276
281
  });
277
282
  get RoleType(): T[number];
278
283
  /**
@@ -282,13 +287,13 @@ declare class _CAuth<T extends string[]> {
282
287
  *
283
288
  * @default undefined
284
289
  */
285
- Guard: (roles?: Array<T[number]>) => any;
290
+ Guard: (roles?: Array<T[number]>) => (...args: any[]) => any;
286
291
  Routes: {
287
- Register: () => any;
288
- Login: () => any;
289
- Logout: () => any;
290
- Refresh: () => any;
291
- ChangePassword: (userId: string) => any;
292
+ Register: () => (...args: any[]) => any;
293
+ Login: () => (...args: any[]) => any;
294
+ Logout: () => (...args: any[]) => any;
295
+ Refresh: () => (...args: any[]) => any;
296
+ ChangePassword: (userId: string) => (...args: any[]) => any;
292
297
  };
293
298
  FN: {
294
299
  Login: ({
@@ -354,8 +359,9 @@ declare class _CAuth<T extends string[]> {
354
359
  VerifyAccessToken: <T_1>(token: any) => Promise<T_1 | null>;
355
360
  };
356
361
  }
357
- declare function CAuth<const T extends string[]>(options: Omit<CAuthOptions, 'roles'> & {
362
+ declare function CAuth<const T extends string[], const TContractor extends RoutesContract<any>>(options: Omit<CAuthOptions, 'roles'> & {
358
363
  roles: T;
359
- }): _CAuth<T>;
364
+ routeContractor: TContractor;
365
+ }): _CAuth<T, RoutesContract<(...args: any[]) => any> & TContractor>;
360
366
  //#endregion
361
367
  export { AccountNotFoundError, CAuth, type CAuthOptions, CredentialMismatchError, type DatabaseContract, DuplicateAccountError, InvalidDataError, InvalidOTPCode, InvalidRefreshTokenError, InvalidRoleError, type RoutesContract };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cauth/core",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",