b23-lib 1.4.0 → 1.5.1

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/README.md CHANGED
Binary file
package/dist/index.d.mts CHANGED
@@ -281,17 +281,82 @@ declare class AuthUtility {
281
281
  private logWarnings;
282
282
  private createSignedJWT;
283
283
  private verifySignedJWT;
284
+ /**
285
+ * Creates an anonymous token with the given ID and additional data.
286
+ *
287
+ * @param id - The unique identifier for the token. Must be a valid UUID.
288
+ * @param additionalData - Optional additional data to include in the token payload.
289
+ * @returns A promise that resolves to the signed JWT as a string.
290
+ * @throws Will throw an error if no anonymous private keys are found or if the ID is not a valid UUID.
291
+ */
284
292
  createAnonymousToken(id: string, additionalData?: object): Promise<string>;
293
+ /**
294
+ * Verifies an anonymous token by checking its signature and payload type.
295
+ *
296
+ * @param token - The JWT token to be verified.
297
+ * @returns The payload of the verified token.
298
+ * @throws Will throw an error if no anonymous public keys are found or if the token type is invalid.
299
+ */
285
300
  verifyAnonymousToken(token: string): Promise<jose.JWTPayload>;
301
+ /**
302
+ * Creates a signed JWT token for a user.
303
+ *
304
+ * @param id - The UUID of the user.
305
+ * @param additionalData - Optional additional data to include in the token payload.
306
+ * @returns A promise that resolves to the signed JWT token as a string.
307
+ * @throws Will throw an error if no user private keys are found or if the provided id is not a valid UUID.
308
+ */
286
309
  createUserToken(id: string, additionalData?: object): Promise<string>;
310
+ /**
311
+ * Verifies the provided user token by checking its signature and payload.
312
+ *
313
+ * @param token - The JWT token to be verified.
314
+ * @returns The payload of the verified token if valid.
315
+ * @throws Will throw an error if no user public keys are found or if the token type is invalid.
316
+ */
287
317
  verifyUserToken(token: string): Promise<jose.JWTPayload>;
318
+ /**
319
+ * Creates a signed JWT (JSON Web Token) for a system with the given ID and optional additional data.
320
+ *
321
+ * @param id - The unique identifier for the system.
322
+ * @param additionalData - Optional additional data to include in the token payload.
323
+ * @returns A promise that resolves to the signed JWT as a string.
324
+ * @throws Will throw an error if no system private keys are found.
325
+ */
288
326
  createSystemToken(id: string, additionalData?: object): Promise<string>;
327
+ /**
328
+ * Verifies a system token by checking its signature and payload type.
329
+ *
330
+ * @param token - The JWT token to be verified.
331
+ * @returns The payload of the verified token.
332
+ * @throws Will throw an error if no system public keys are found or if the token type is not 'System'.
333
+ */
289
334
  verifySystemToken(token: string): Promise<jose.JWTPayload>;
335
+ /**
336
+ * Creates a signed JWT token for an admin user.
337
+ *
338
+ * @param id - The UUID of the admin user.
339
+ * @param additionalData - Optional additional data to include in the token payload.
340
+ * @returns A promise that resolves to the signed JWT token string.
341
+ * @throws Will throw an error if no admin private keys are found or if the provided id is not a valid UUID.
342
+ */
290
343
  createAdminToken(id: string, additionalData?: object): Promise<string>;
344
+ /**
345
+ * Verifies the provided admin token by checking its signature and payload.
346
+ * Ensures that the token is signed with one of the known admin public keys
347
+ * and that the payload type is 'Admin'.
348
+ *
349
+ * @param token - The JWT token to be verified.
350
+ * @returns The payload of the verified token.
351
+ * @throws Will throw an error if no admin public keys are found or if the token is invalid.
352
+ */
291
353
  verifyAdminToken(token: string): Promise<jose.JWTPayload>;
292
354
  /**
293
- * Middleware for handling JWT authentication.
294
- * @param config Configuration for middleware behavior.
355
+ * Middleware function to handle authentication based on different token types.
356
+ * It verifies the token and sets the authentication details in the response locals.
357
+ *
358
+ * @param {Partial<AuthMiddlewareConfig>} [config=DefaultAuthMiddlewareConfig] - Configuration object to customize the middleware behavior.
359
+ * @returns Middleware function to handle authentication.
295
360
  */
296
361
  AuthMiddleware(config?: Partial<AuthMiddlewareConfig>): (req: any, res: any, next: any) => Promise<void>;
297
362
  }
@@ -331,14 +396,26 @@ type SuccessType = {
331
396
  statusText: string;
332
397
  data: any;
333
398
  };
399
+ /**
400
+ * Makes an HTTP request to the specified endpoint using the provided parameters.
401
+ *
402
+ * @param {string} baseURL - The base URL of the API.
403
+ * @param {string} endpoint - The specific endpoint to call.
404
+ * @param {'GET' | 'POST' | 'PATCH' | 'DELETE'} [method='GET'] - The HTTP method to use for the request.
405
+ * @param {Record<string, string>} [headers={}] - Additional headers to include in the request.
406
+ * @param {any} [payload] - The payload to send with the request, if applicable.
407
+ * @returns {Promise<SuccessType>} - A promise that resolves to the response data if the request is successful.
408
+ * @throws {ErrorType} - Throws an error if the request fails.
409
+ */
334
410
  declare const Fetch: (baseURL: string, endpoint: string, method?: "GET" | "POST" | "PATCH" | "DELETE", headers?: Record<string, string>, payload?: any) => Promise<SuccessType>;
335
411
 
336
412
  declare const Logger: {
337
413
  logException: (functionName: string, error: any) => void;
338
- logError: (functionName: string, errorMessage: string) => void;
414
+ logError: (functionName: string, error: any) => void;
339
415
  logWarning: (functionName: string, message: any) => void;
340
416
  logMessage: (functionName: string, message: any) => void;
341
417
  logInvalidPayload: (functionName: string, errorMessage: string) => void;
418
+ inspect: (context: any) => string;
342
419
  };
343
420
 
344
421
  export { type AuthMiddlewareConfig, type AuthTokenType, AuthUtility, type AuthUtilityConfig, DefaultAuthMiddlewareConfig, DefaultAuthUtilityConfig, DynamoDBUtility as DynamoDB, type ErrorType, Fetch, Logger, ResponseUtility, Schema, type SuccessType, Utils };
package/dist/index.d.ts CHANGED
@@ -281,17 +281,82 @@ declare class AuthUtility {
281
281
  private logWarnings;
282
282
  private createSignedJWT;
283
283
  private verifySignedJWT;
284
+ /**
285
+ * Creates an anonymous token with the given ID and additional data.
286
+ *
287
+ * @param id - The unique identifier for the token. Must be a valid UUID.
288
+ * @param additionalData - Optional additional data to include in the token payload.
289
+ * @returns A promise that resolves to the signed JWT as a string.
290
+ * @throws Will throw an error if no anonymous private keys are found or if the ID is not a valid UUID.
291
+ */
284
292
  createAnonymousToken(id: string, additionalData?: object): Promise<string>;
293
+ /**
294
+ * Verifies an anonymous token by checking its signature and payload type.
295
+ *
296
+ * @param token - The JWT token to be verified.
297
+ * @returns The payload of the verified token.
298
+ * @throws Will throw an error if no anonymous public keys are found or if the token type is invalid.
299
+ */
285
300
  verifyAnonymousToken(token: string): Promise<jose.JWTPayload>;
301
+ /**
302
+ * Creates a signed JWT token for a user.
303
+ *
304
+ * @param id - The UUID of the user.
305
+ * @param additionalData - Optional additional data to include in the token payload.
306
+ * @returns A promise that resolves to the signed JWT token as a string.
307
+ * @throws Will throw an error if no user private keys are found or if the provided id is not a valid UUID.
308
+ */
286
309
  createUserToken(id: string, additionalData?: object): Promise<string>;
310
+ /**
311
+ * Verifies the provided user token by checking its signature and payload.
312
+ *
313
+ * @param token - The JWT token to be verified.
314
+ * @returns The payload of the verified token if valid.
315
+ * @throws Will throw an error if no user public keys are found or if the token type is invalid.
316
+ */
287
317
  verifyUserToken(token: string): Promise<jose.JWTPayload>;
318
+ /**
319
+ * Creates a signed JWT (JSON Web Token) for a system with the given ID and optional additional data.
320
+ *
321
+ * @param id - The unique identifier for the system.
322
+ * @param additionalData - Optional additional data to include in the token payload.
323
+ * @returns A promise that resolves to the signed JWT as a string.
324
+ * @throws Will throw an error if no system private keys are found.
325
+ */
288
326
  createSystemToken(id: string, additionalData?: object): Promise<string>;
327
+ /**
328
+ * Verifies a system token by checking its signature and payload type.
329
+ *
330
+ * @param token - The JWT token to be verified.
331
+ * @returns The payload of the verified token.
332
+ * @throws Will throw an error if no system public keys are found or if the token type is not 'System'.
333
+ */
289
334
  verifySystemToken(token: string): Promise<jose.JWTPayload>;
335
+ /**
336
+ * Creates a signed JWT token for an admin user.
337
+ *
338
+ * @param id - The UUID of the admin user.
339
+ * @param additionalData - Optional additional data to include in the token payload.
340
+ * @returns A promise that resolves to the signed JWT token string.
341
+ * @throws Will throw an error if no admin private keys are found or if the provided id is not a valid UUID.
342
+ */
290
343
  createAdminToken(id: string, additionalData?: object): Promise<string>;
344
+ /**
345
+ * Verifies the provided admin token by checking its signature and payload.
346
+ * Ensures that the token is signed with one of the known admin public keys
347
+ * and that the payload type is 'Admin'.
348
+ *
349
+ * @param token - The JWT token to be verified.
350
+ * @returns The payload of the verified token.
351
+ * @throws Will throw an error if no admin public keys are found or if the token is invalid.
352
+ */
291
353
  verifyAdminToken(token: string): Promise<jose.JWTPayload>;
292
354
  /**
293
- * Middleware for handling JWT authentication.
294
- * @param config Configuration for middleware behavior.
355
+ * Middleware function to handle authentication based on different token types.
356
+ * It verifies the token and sets the authentication details in the response locals.
357
+ *
358
+ * @param {Partial<AuthMiddlewareConfig>} [config=DefaultAuthMiddlewareConfig] - Configuration object to customize the middleware behavior.
359
+ * @returns Middleware function to handle authentication.
295
360
  */
296
361
  AuthMiddleware(config?: Partial<AuthMiddlewareConfig>): (req: any, res: any, next: any) => Promise<void>;
297
362
  }
@@ -331,14 +396,26 @@ type SuccessType = {
331
396
  statusText: string;
332
397
  data: any;
333
398
  };
399
+ /**
400
+ * Makes an HTTP request to the specified endpoint using the provided parameters.
401
+ *
402
+ * @param {string} baseURL - The base URL of the API.
403
+ * @param {string} endpoint - The specific endpoint to call.
404
+ * @param {'GET' | 'POST' | 'PATCH' | 'DELETE'} [method='GET'] - The HTTP method to use for the request.
405
+ * @param {Record<string, string>} [headers={}] - Additional headers to include in the request.
406
+ * @param {any} [payload] - The payload to send with the request, if applicable.
407
+ * @returns {Promise<SuccessType>} - A promise that resolves to the response data if the request is successful.
408
+ * @throws {ErrorType} - Throws an error if the request fails.
409
+ */
334
410
  declare const Fetch: (baseURL: string, endpoint: string, method?: "GET" | "POST" | "PATCH" | "DELETE", headers?: Record<string, string>, payload?: any) => Promise<SuccessType>;
335
411
 
336
412
  declare const Logger: {
337
413
  logException: (functionName: string, error: any) => void;
338
- logError: (functionName: string, errorMessage: string) => void;
414
+ logError: (functionName: string, error: any) => void;
339
415
  logWarning: (functionName: string, message: any) => void;
340
416
  logMessage: (functionName: string, message: any) => void;
341
417
  logInvalidPayload: (functionName: string, errorMessage: string) => void;
418
+ inspect: (context: any) => string;
342
419
  };
343
420
 
344
421
  export { type AuthMiddlewareConfig, type AuthTokenType, AuthUtility, type AuthUtilityConfig, DefaultAuthMiddlewareConfig, DefaultAuthUtilityConfig, DynamoDBUtility as DynamoDB, type ErrorType, Fetch, Logger, ResponseUtility, Schema, type SuccessType, Utils };