@extk/expressive 0.5.3 → 0.5.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.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +24 -0
- package/dist/index.mjs +24 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -288,6 +288,7 @@ declare function bootstrap(container: Container): {
|
|
|
288
288
|
silently: (fn: () => Promise<void> | void) => Promise<void>;
|
|
289
289
|
notFoundMiddleware: (_req: express.Request, res: express.Response, _next: express.NextFunction) => void;
|
|
290
290
|
getErrorHandlerMiddleware: (errorMapper?: (err: Error & Record<string, unknown>) => ApiError | null | undefined) => (err: Error & Record<string, unknown>, req: express.Request, res: express.Response, _next: express.NextFunction) => Promise<void>;
|
|
291
|
+
getBasicAuthMiddleware: (basicAuthBase64: string, basicRealm?: string) => (req: express.Request, res: express.Response, next: express.NextFunction) => void;
|
|
291
292
|
expressiveServer: (configs?: {
|
|
292
293
|
app?: express.Express;
|
|
293
294
|
}) => ServerBuilder;
|
package/dist/index.d.ts
CHANGED
|
@@ -288,6 +288,7 @@ declare function bootstrap(container: Container): {
|
|
|
288
288
|
silently: (fn: () => Promise<void> | void) => Promise<void>;
|
|
289
289
|
notFoundMiddleware: (_req: express.Request, res: express.Response, _next: express.NextFunction) => void;
|
|
290
290
|
getErrorHandlerMiddleware: (errorMapper?: (err: Error & Record<string, unknown>) => ApiError | null | undefined) => (err: Error & Record<string, unknown>, req: express.Request, res: express.Response, _next: express.NextFunction) => Promise<void>;
|
|
291
|
+
getBasicAuthMiddleware: (basicAuthBase64: string, basicRealm?: string) => (req: express.Request, res: express.Response, next: express.NextFunction) => void;
|
|
291
292
|
expressiveServer: (configs?: {
|
|
292
293
|
app?: express.Express;
|
|
293
294
|
}) => ServerBuilder;
|
package/dist/index.js
CHANGED
|
@@ -432,6 +432,30 @@ var buildMiddleware = (container) => {
|
|
|
432
432
|
}
|
|
433
433
|
res.status(finalError.httpStatusCode).json(new ApiErrorResponse(finalError.message, finalError.code, finalError.data));
|
|
434
434
|
};
|
|
435
|
+
},
|
|
436
|
+
getBasicAuthMiddleware: (basicAuthBase64, basicRealm) => {
|
|
437
|
+
return (req, res, next) => {
|
|
438
|
+
try {
|
|
439
|
+
const token = req.header("authorization");
|
|
440
|
+
if (!token || token.indexOf("Basic ") === -1) {
|
|
441
|
+
throw new UserUnauthorizedError("Missing Authorization Header");
|
|
442
|
+
}
|
|
443
|
+
const credentials = token.split(" ")[1];
|
|
444
|
+
if (basicAuthBase64 !== credentials) {
|
|
445
|
+
throw new UserUnauthorizedError("Invalid Authentication Credentials");
|
|
446
|
+
}
|
|
447
|
+
next();
|
|
448
|
+
} catch (error) {
|
|
449
|
+
if (basicRealm) {
|
|
450
|
+
res.set("WWW-Authenticate", `Basic realm="${basicRealm}"`);
|
|
451
|
+
}
|
|
452
|
+
if (error instanceof ApiError) {
|
|
453
|
+
return next(error);
|
|
454
|
+
}
|
|
455
|
+
logger.error(error);
|
|
456
|
+
return next(new UserUnauthorizedError());
|
|
457
|
+
}
|
|
458
|
+
};
|
|
435
459
|
}
|
|
436
460
|
};
|
|
437
461
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -371,6 +371,30 @@ var buildMiddleware = (container) => {
|
|
|
371
371
|
}
|
|
372
372
|
res.status(finalError.httpStatusCode).json(new ApiErrorResponse(finalError.message, finalError.code, finalError.data));
|
|
373
373
|
};
|
|
374
|
+
},
|
|
375
|
+
getBasicAuthMiddleware: (basicAuthBase64, basicRealm) => {
|
|
376
|
+
return (req, res, next) => {
|
|
377
|
+
try {
|
|
378
|
+
const token = req.header("authorization");
|
|
379
|
+
if (!token || token.indexOf("Basic ") === -1) {
|
|
380
|
+
throw new UserUnauthorizedError("Missing Authorization Header");
|
|
381
|
+
}
|
|
382
|
+
const credentials = token.split(" ")[1];
|
|
383
|
+
if (basicAuthBase64 !== credentials) {
|
|
384
|
+
throw new UserUnauthorizedError("Invalid Authentication Credentials");
|
|
385
|
+
}
|
|
386
|
+
next();
|
|
387
|
+
} catch (error) {
|
|
388
|
+
if (basicRealm) {
|
|
389
|
+
res.set("WWW-Authenticate", `Basic realm="${basicRealm}"`);
|
|
390
|
+
}
|
|
391
|
+
if (error instanceof ApiError) {
|
|
392
|
+
return next(error);
|
|
393
|
+
}
|
|
394
|
+
logger.error(error);
|
|
395
|
+
return next(new UserUnauthorizedError());
|
|
396
|
+
}
|
|
397
|
+
};
|
|
374
398
|
}
|
|
375
399
|
};
|
|
376
400
|
};
|