@eduzz/miau-client 1.4.0-rc.155 → 1.4.0-rc.157
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/MiauClient.d.ts +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/src/MiauClient.ts +24 -3
package/package.json
CHANGED
package/src/MiauClient.ts
CHANGED
|
@@ -18,6 +18,20 @@ import { miauHook, miauMiddleware, type RequestAugmentation } from './middleware
|
|
|
18
18
|
|
|
19
19
|
type MiauClientConfig = { apiUrl: string; appSecret: string };
|
|
20
20
|
|
|
21
|
+
type OAuthTokenSuccessResponse = {
|
|
22
|
+
access_token: string;
|
|
23
|
+
token_type: 'Bearer';
|
|
24
|
+
expires_in: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type OAuthTokenErrorResponse = {
|
|
28
|
+
error: string;
|
|
29
|
+
error_description: string;
|
|
30
|
+
message?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type OAuthTokenResponse = OAuthTokenSuccessResponse | OAuthTokenErrorResponse;
|
|
34
|
+
|
|
21
35
|
export class MiauClient {
|
|
22
36
|
private config: MiauClientConfig;
|
|
23
37
|
private jwtToken: string | undefined;
|
|
@@ -72,13 +86,20 @@ export class MiauClient {
|
|
|
72
86
|
}
|
|
73
87
|
});
|
|
74
88
|
|
|
75
|
-
const data = await response.json();
|
|
89
|
+
const data = (await response.json()) as OAuthTokenResponse;
|
|
76
90
|
|
|
77
91
|
if (response.status !== 200) {
|
|
78
|
-
|
|
92
|
+
const errorData = data as OAuthTokenErrorResponse;
|
|
93
|
+
const errorMessage =
|
|
94
|
+
errorData.message ||
|
|
95
|
+
errorData.error_description ||
|
|
96
|
+
`OAuth error: ${errorData.error}` ||
|
|
97
|
+
'Failed to fetch JWT token';
|
|
98
|
+
throw new Error(errorMessage);
|
|
79
99
|
}
|
|
80
100
|
|
|
81
|
-
|
|
101
|
+
const successData = data as OAuthTokenSuccessResponse;
|
|
102
|
+
this.jwtToken = successData.access_token;
|
|
82
103
|
return this.jwtToken;
|
|
83
104
|
}
|
|
84
105
|
|