@eduzz/miau-client 1.0.0 → 1.0.2
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/.turbo/turbo-build$colon$types.log +1 -1
- package/dist/MiauClient.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +2 -2
- package/dist/middleware.d.ts +1 -1
- package/package.json +1 -1
- package/src/MiauClient.ts +2 -2
- package/src/middleware.ts +4 -4
package/dist/middleware.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export type RequestAugmentation<T> = (data: {
|
|
|
6
6
|
app: MiauApplication;
|
|
7
7
|
meta: T;
|
|
8
8
|
}) => void;
|
|
9
|
-
export declare const miauMiddleware: <T>(miauClient: MiauClient, requestAugmentation?: RequestAugmentation<T>,
|
|
9
|
+
export declare const miauMiddleware: <T>(miauClient: MiauClient, requestAugmentation?: RequestAugmentation<T>, fallbackMiddleware?: RequestHandler) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/package.json
CHANGED
package/src/MiauClient.ts
CHANGED
|
@@ -90,9 +90,9 @@ export class MiauClient {
|
|
|
90
90
|
|
|
91
91
|
public middleware<T = Record<string, string>>(config?: {
|
|
92
92
|
requestAugmentation?: RequestAugmentation<T>;
|
|
93
|
-
|
|
93
|
+
fallbackMiddleware?: RequestHandler;
|
|
94
94
|
}): RequestHandler {
|
|
95
|
-
return miauMiddleware<T>(this, config?.requestAugmentation, config?.
|
|
95
|
+
return miauMiddleware<T>(this, config?.requestAugmentation, config?.fallbackMiddleware);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
public async getPermissions(targetAppId: string) {
|
package/src/middleware.ts
CHANGED
|
@@ -29,7 +29,7 @@ const wildcardToRegex = (pattern: string) => {
|
|
|
29
29
|
export const miauMiddleware = <T>(
|
|
30
30
|
miauClient: MiauClient,
|
|
31
31
|
requestAugmentation?: RequestAugmentation<T>,
|
|
32
|
-
|
|
32
|
+
fallbackMiddleware?: RequestHandler
|
|
33
33
|
) => {
|
|
34
34
|
return async (req: Request, res: Response, next: NextFunction) => {
|
|
35
35
|
try {
|
|
@@ -80,7 +80,7 @@ export const miauMiddleware = <T>(
|
|
|
80
80
|
const isAllowed = resources.some((resource: Resource) => {
|
|
81
81
|
return (
|
|
82
82
|
resource.method.toLowerCase() === req.method.toLowerCase() &&
|
|
83
|
-
wildcardToRegex(resource.path).test(req.path.toLowerCase())
|
|
83
|
+
wildcardToRegex(resource.path.toLowerCase()).test(req.path.toLowerCase())
|
|
84
84
|
);
|
|
85
85
|
});
|
|
86
86
|
|
|
@@ -98,8 +98,8 @@ export const miauMiddleware = <T>(
|
|
|
98
98
|
|
|
99
99
|
next();
|
|
100
100
|
} catch (err: HttpError | any) {
|
|
101
|
-
if (err instanceof HttpError && err.status == 400 &&
|
|
102
|
-
return
|
|
101
|
+
if (err instanceof HttpError && err.status == 400 && fallbackMiddleware) {
|
|
102
|
+
return fallbackMiddleware(req, res, next);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
const errorStatus = err.status || 403;
|