b23-lib 1.3.1 → 1.5.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/README.md CHANGED
Binary file
package/dist/index.d.mts CHANGED
@@ -249,11 +249,12 @@ interface AuthUtilityConfig {
249
249
  adminPublicKeys: StringifiedJSONArray;
250
250
  }
251
251
  declare const DefaultAuthUtilityConfig: Readonly<AuthUtilityConfig>;
252
- type AuthTokenType = 'Anon' | 'User' | 'System' | 'Admin';
252
+ type AuthTokenType = 'Anon' | 'User' | 'System' | 'Admin' | 'CDN';
253
253
  interface AuthMiddlewareConfig {
254
254
  allowAnonymous: boolean;
255
255
  allowSystem: boolean;
256
256
  allowUser: boolean;
257
+ allowCDN: boolean;
257
258
  }
258
259
  declare const DefaultAuthMiddlewareConfig: Readonly<AuthMiddlewareConfig>;
259
260
  /**
@@ -280,19 +281,84 @@ declare class AuthUtility {
280
281
  private logWarnings;
281
282
  private createSignedJWT;
282
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
+ */
283
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
+ */
284
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
+ */
285
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
+ */
286
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
+ */
287
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
+ */
288
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
+ */
289
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
+ */
290
353
  verifyAdminToken(token: string): Promise<jose.JWTPayload>;
291
354
  /**
292
- * Middleware for handling JWT authentication.
293
- * @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 {Function} Middleware function to handle authentication.
294
360
  */
295
- AuthMiddleware(config?: Partial<AuthMiddlewareConfig>): (req: any, res: any, next: any) => Promise<void>;
361
+ AuthMiddleware(config?: Partial<AuthMiddlewareConfig>): Function;
296
362
  }
297
363
 
298
364
  declare const Utils: {
@@ -330,14 +396,26 @@ type SuccessType = {
330
396
  statusText: string;
331
397
  data: any;
332
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
+ */
333
410
  declare const Fetch: (baseURL: string, endpoint: string, method?: "GET" | "POST" | "PATCH" | "DELETE", headers?: Record<string, string>, payload?: any) => Promise<SuccessType>;
334
411
 
335
412
  declare const Logger: {
336
413
  logException: (functionName: string, error: any) => void;
337
- logError: (functionName: string, errorMessage: string) => void;
414
+ logError: (functionName: string, error: any) => void;
338
415
  logWarning: (functionName: string, message: any) => void;
339
416
  logMessage: (functionName: string, message: any) => void;
340
417
  logInvalidPayload: (functionName: string, errorMessage: string) => void;
418
+ inspect: (context: any) => string;
341
419
  };
342
420
 
343
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
@@ -249,11 +249,12 @@ interface AuthUtilityConfig {
249
249
  adminPublicKeys: StringifiedJSONArray;
250
250
  }
251
251
  declare const DefaultAuthUtilityConfig: Readonly<AuthUtilityConfig>;
252
- type AuthTokenType = 'Anon' | 'User' | 'System' | 'Admin';
252
+ type AuthTokenType = 'Anon' | 'User' | 'System' | 'Admin' | 'CDN';
253
253
  interface AuthMiddlewareConfig {
254
254
  allowAnonymous: boolean;
255
255
  allowSystem: boolean;
256
256
  allowUser: boolean;
257
+ allowCDN: boolean;
257
258
  }
258
259
  declare const DefaultAuthMiddlewareConfig: Readonly<AuthMiddlewareConfig>;
259
260
  /**
@@ -280,19 +281,84 @@ declare class AuthUtility {
280
281
  private logWarnings;
281
282
  private createSignedJWT;
282
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
+ */
283
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
+ */
284
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
+ */
285
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
+ */
286
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
+ */
287
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
+ */
288
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
+ */
289
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
+ */
290
353
  verifyAdminToken(token: string): Promise<jose.JWTPayload>;
291
354
  /**
292
- * Middleware for handling JWT authentication.
293
- * @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 {Function} Middleware function to handle authentication.
294
360
  */
295
- AuthMiddleware(config?: Partial<AuthMiddlewareConfig>): (req: any, res: any, next: any) => Promise<void>;
361
+ AuthMiddleware(config?: Partial<AuthMiddlewareConfig>): Function;
296
362
  }
297
363
 
298
364
  declare const Utils: {
@@ -330,14 +396,26 @@ type SuccessType = {
330
396
  statusText: string;
331
397
  data: any;
332
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
+ */
333
410
  declare const Fetch: (baseURL: string, endpoint: string, method?: "GET" | "POST" | "PATCH" | "DELETE", headers?: Record<string, string>, payload?: any) => Promise<SuccessType>;
334
411
 
335
412
  declare const Logger: {
336
413
  logException: (functionName: string, error: any) => void;
337
- logError: (functionName: string, errorMessage: string) => void;
414
+ logError: (functionName: string, error: any) => void;
338
415
  logWarning: (functionName: string, message: any) => void;
339
416
  logMessage: (functionName: string, message: any) => void;
340
417
  logInvalidPayload: (functionName: string, errorMessage: string) => void;
418
+ inspect: (context: any) => string;
341
419
  };
342
420
 
343
421
  export { type AuthMiddlewareConfig, type AuthTokenType, AuthUtility, type AuthUtilityConfig, DefaultAuthMiddlewareConfig, DefaultAuthUtilityConfig, DynamoDBUtility as DynamoDB, type ErrorType, Fetch, Logger, ResponseUtility, Schema, type SuccessType, Utils };