@eduzz/miau-client 0.0.12 → 0.0.13
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/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-prepublish.log +1 -1
- package/dist/MiauClient.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +2 -2
- package/dist/middleware.d.ts +6 -2
- package/package.json +1 -1
- package/src/MiauClient.ts +4 -4
- package/src/middleware.ts +5 -9
package/dist/middleware.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type RequestHandler, type NextFunction, type Request, type Response } from 'express';
|
|
2
2
|
import type { MiauApplication } from '@eduzz/miau-types';
|
|
3
3
|
import type { MiauClient } from './MiauClient';
|
|
4
|
-
export type RequestAugmentation = (
|
|
5
|
-
|
|
4
|
+
export type RequestAugmentation<T> = (data: {
|
|
5
|
+
req: Request;
|
|
6
|
+
app: MiauApplication;
|
|
7
|
+
meta: T;
|
|
8
|
+
}) => void;
|
|
9
|
+
export declare const miauMiddleware: <T>(miauClient: MiauClient, requestAugmentation?: RequestAugmentation<T>, fallbackMidlleware?: RequestHandler) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/package.json
CHANGED
package/src/MiauClient.ts
CHANGED
|
@@ -71,11 +71,11 @@ export class MiauClient {
|
|
|
71
71
|
return this.jwtToken;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
public middleware(
|
|
75
|
-
requestAugmentation
|
|
76
|
-
fallbackMidlleware
|
|
74
|
+
public middleware<T = Record<string, string>>(
|
|
75
|
+
requestAugmentation?: RequestAugmentation<T>,
|
|
76
|
+
fallbackMidlleware?: RequestHandler
|
|
77
77
|
): RequestHandler {
|
|
78
|
-
return miauMiddleware(this, requestAugmentation, fallbackMidlleware);
|
|
78
|
+
return miauMiddleware<T>(this, requestAugmentation, fallbackMidlleware);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
public async getPermissions(targetAppId: string) {
|
package/src/middleware.ts
CHANGED
|
@@ -17,11 +17,7 @@ class HttpError extends Error {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export type RequestAugmentation = (
|
|
21
|
-
request: Request,
|
|
22
|
-
miauApplication: MiauApplication,
|
|
23
|
-
miauMetadata: Record<string, string>
|
|
24
|
-
) => void;
|
|
20
|
+
export type RequestAugmentation<T> = (data: { req: Request; app: MiauApplication; meta: T }) => void;
|
|
25
21
|
|
|
26
22
|
const wildcardToRegex = (pattern: string) => {
|
|
27
23
|
const escaped = pattern.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&');
|
|
@@ -30,10 +26,10 @@ const wildcardToRegex = (pattern: string) => {
|
|
|
30
26
|
return new RegExp(regexStr);
|
|
31
27
|
};
|
|
32
28
|
|
|
33
|
-
export const miauMiddleware = (
|
|
29
|
+
export const miauMiddleware = <T>(
|
|
34
30
|
miauClient: MiauClient,
|
|
35
|
-
requestAugmentation
|
|
36
|
-
fallbackMidlleware
|
|
31
|
+
requestAugmentation?: RequestAugmentation<T>,
|
|
32
|
+
fallbackMidlleware?: RequestHandler
|
|
37
33
|
) => {
|
|
38
34
|
return async (req: Request, res: Response, next: NextFunction) => {
|
|
39
35
|
try {
|
|
@@ -79,7 +75,7 @@ export const miauMiddleware = (
|
|
|
79
75
|
|
|
80
76
|
if (requestAugmentation) {
|
|
81
77
|
console.log('Request augmentation is being applied');
|
|
82
|
-
requestAugmentation(req, req.miauApplication, req.miauMetadata);
|
|
78
|
+
requestAugmentation({ req, app: req.miauApplication, meta: req.miauMetadata as T });
|
|
83
79
|
}
|
|
84
80
|
|
|
85
81
|
next();
|