@eduzz/miau-client 0.0.14 → 0.0.16

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.
@@ -6,6 +6,6 @@ export type Application = {
6
6
  slug: string;
7
7
  resources: Resource[];
8
8
  createdAt: Date;
9
- updatedAt: Date | null;
10
- deletedAt: Date | null;
9
+ updatedAt: Date;
10
+ deletedAt?: Date;
11
11
  };
@@ -3,6 +3,6 @@ export type Organization = {
3
3
  name: string;
4
4
  slug: string;
5
5
  createdAt: Date;
6
- updatedAt: Date | null;
7
- deletedAt: Date | null;
6
+ updatedAt: Date;
7
+ deletedAt?: Date;
8
8
  };
@@ -7,6 +7,6 @@ export type Permission = {
7
7
  metadata: Record<string, string>;
8
8
  resources: Resource[];
9
9
  createdAt: Date;
10
- updatedAt: Date | null;
11
- deletedAt: Date | null;
10
+ updatedAt: Date;
11
+ deletedAt?: Date;
12
12
  };
@@ -1,10 +1,10 @@
1
- export type ResourceType = 'http' | 'websocket' | 'grpc';
2
- export declare const ResourceTypes: ResourceType[];
1
+ export type ResourceProtocol = 'http' | 'websocket' | 'grpc';
2
+ export declare const ResourceProtocols: ResourceProtocol[];
3
3
  export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
4
4
  export declare const HttpMethods: HttpMethod[];
5
5
  export type Resource = {
6
6
  id?: string;
7
- type: ResourceType;
7
+ protocol: ResourceProtocol;
8
8
  method: HttpMethod;
9
9
  path: string;
10
10
  };
@@ -4,8 +4,8 @@ export type Secret = {
4
4
  name: string;
5
5
  value: string;
6
6
  environment: string;
7
- expiresAt?: Date | null;
7
+ expiresAt?: Date;
8
8
  createdAt: Date;
9
9
  updatedAt: Date;
10
- deletedAt?: Date | null;
10
+ deletedAt?: Date;
11
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eduzz/miau-client",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Eduzz Miau Client",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/MiauClient.ts CHANGED
@@ -33,7 +33,7 @@ export class MiauClient {
33
33
 
34
34
  constructor(props: MiauClientConfig) {
35
35
  this.apiUrl = props.apiUrl;
36
- const apiKey = props.appSecret.substring(7, 27);
36
+ const apiKey = props.appSecret.substring(7, 32);
37
37
  this.basicAuthToken = Buffer.from(`${apiKey}:${props.appSecret}`).toString('base64');
38
38
  }
39
39
 
package/src/middleware.ts CHANGED
@@ -36,26 +36,26 @@ export const miauMiddleware = <T>(
36
36
  const token = req.headers.authorization?.split(' ').pop();
37
37
 
38
38
  if (!token) {
39
- throw new HttpError(401, 'Invalid Token', 'Token not provided');
39
+ throw new HttpError(400, 'Invalid Token', 'Token not provided');
40
40
  }
41
41
 
42
42
  const decodedToken = jwt.decode(token, { complete: true }) as { header: { kid: string } };
43
43
 
44
44
  if (!decodedToken?.header?.kid) {
45
- throw new HttpError(401, 'Invalid Token', 'Missing kid in token header');
45
+ throw new HttpError(400, 'Invalid Token', 'Missing kid in token header');
46
46
  }
47
47
 
48
48
  const publicKey = await miauClient.getPublicKey(decodedToken.header.kid);
49
49
  const appToken = jwt.verify(token, publicKey, { algorithms: ['RS256'] }) as MiauApplication;
50
50
 
51
51
  if (!appToken || !appToken.id || !appToken.name) {
52
- throw new HttpError(401, 'Invalid Token', 'Token verification failed');
52
+ throw new HttpError(400, 'Invalid Token', 'Token verification failed');
53
53
  }
54
54
 
55
55
  const permission = await miauClient.getPermissions(appToken.id);
56
56
 
57
57
  if (!permission) {
58
- res.status(401).json({ error: 'Unauthorized', message: 'No permissions found for this application' });
58
+ throw new HttpError(401, 'Unauthorized', 'No permissions found for this application');
59
59
  }
60
60
 
61
61
  const resources = permission?.resources || [];
@@ -80,7 +80,8 @@ export const miauMiddleware = <T>(
80
80
 
81
81
  next();
82
82
  } catch (err: HttpError | any) {
83
- if (err instanceof HttpError && err.status == 401 && fallbackMidlleware) {
83
+ if (err instanceof HttpError && err.status == 400 && fallbackMidlleware) {
84
+ console.log('Using fallback middleware for 400 error');
84
85
  return fallbackMidlleware(req, res, next);
85
86
  }
86
87