moc-oauth-client 1.0.6 → 1.0.7

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.ts CHANGED
@@ -1,8 +1,8 @@
1
- interface OAuthResult<T> {
1
+ interface ApiResponse<T> {
2
2
  data: T | null;
3
- error: OAuthError["error"] | null;
3
+ error: ApiErrorResponse["error"] | null;
4
4
  }
5
- interface OAuthError {
5
+ interface ApiErrorResponse {
6
6
  status: number;
7
7
  success: false;
8
8
  error: {
@@ -10,25 +10,32 @@ interface OAuthError {
10
10
  message: string;
11
11
  };
12
12
  }
13
- interface AuthorizeResponse {
13
+ interface LoginTokenResponse {
14
14
  redirectUri: string;
15
15
  }
16
- interface ValidateTokenResponse {
16
+ interface ValidateJwtResponse {
17
17
  isValid: boolean;
18
+ payload: {
19
+ accessToken: string;
20
+ refreshToken: string;
21
+ };
22
+ }
23
+ interface RefreshTokenResponse {
18
24
  accessToken: string;
19
25
  refreshToken: string;
20
26
  }
21
- interface CurrentUser {
27
+ interface LookupUserProfileResponse {
28
+ id: number;
22
29
  email: string;
23
- firstName: string;
24
- lastName: string;
30
+ username?: string;
31
+ isActive: boolean;
25
32
  }
26
33
 
27
34
  interface MOCOAuthClientBase {
28
- authorizeClient(): Promise<OAuthResult<AuthorizeResponse>>;
29
- validateToken(accessToken: string): Promise<OAuthResult<ValidateTokenResponse>>;
30
- getCurrentUser(accessToken: string): Promise<OAuthResult<CurrentUser>>;
31
- refreshToken(refreshToken: string): Promise<OAuthResult<ValidateTokenResponse>>;
35
+ getLoginToken(): Promise<ApiResponse<LoginTokenResponse>>;
36
+ validateJwtToken(accessToken: string): Promise<ApiResponse<ValidateJwtResponse>>;
37
+ lookupUserProfile(accessToken: string): Promise<ApiResponse<LookupUserProfileResponse>>;
38
+ refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
32
39
  }
33
40
  /**
34
41
  * MOCOAuthClient is a client library for interacting with the MOC OAuth API.
@@ -42,7 +49,7 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
42
49
  * The response data will contain the authorization URL for the client.
43
50
  * @throws An error if the request to authorize the client fails.
44
51
  */
45
- authorizeClient(): Promise<OAuthResult<AuthorizeResponse>>;
52
+ getLoginToken(): Promise<ApiResponse<LoginTokenResponse>>;
46
53
  /**
47
54
  * Validates a JWT token using the MOC OAuth API.
48
55
  * @param accessToken The JWT token to validate.
@@ -51,7 +58,7 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
51
58
  * an access token, and a refresh token.
52
59
  * @throws An error if the request to validate the token fails.
53
60
  */
54
- validateToken(accessToken: string): Promise<OAuthResult<ValidateTokenResponse>>;
61
+ validateJwtToken(accessToken: string): Promise<ApiResponse<ValidateJwtResponse>>;
55
62
  /**
56
63
  * Retrieves the current user's information using the MOC OAuth API.
57
64
  * @param accessToken The JWT token to use for authentication.
@@ -59,7 +66,7 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
59
66
  * The response data will contain the current user's email, first name, and last name.
60
67
  * @throws An error if the request to retrieve the user's information fails.
61
68
  */
62
- getCurrentUser(accessToken: string): Promise<OAuthResult<CurrentUser>>;
69
+ lookupUserProfile(accessToken: string): Promise<ApiResponse<LookupUserProfileResponse>>;
63
70
  /**
64
71
  * Refreshes an access token using the MOC OAuth API.
65
72
  * @param refreshToken The JWT token to use for authentication.
@@ -67,7 +74,7 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
67
74
  * The response data will contain the new access token and refresh token.
68
75
  * @throws An error if the request to refresh the access token fails.
69
76
  */
70
- refreshToken(refreshToken: string): Promise<OAuthResult<ValidateTokenResponse>>;
77
+ refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
71
78
  }
72
79
 
73
- export { type AuthorizeResponse, type CurrentUser, MOCOAuthClient, type OAuthError, type OAuthResult, type ValidateTokenResponse };
80
+ export { type ApiErrorResponse, type ApiResponse, type LoginTokenResponse, type LookupUserProfileResponse, MOCOAuthClient, type RefreshTokenResponse, type ValidateJwtResponse };
package/dist/index.js CHANGED
@@ -78,10 +78,10 @@ function handleError(error) {
78
78
 
79
79
  // src/api-endpoint.ts
80
80
  var API_ENDPOINTS = {
81
- LOGIN_TOKEN: "/api/v1/service-account/login-token",
82
- USER: "/api/v1/service-account/profile-user",
81
+ GET_LOGIN_TOKEN: "/api/v1/service-account/login-token",
82
+ LOOKUP_USER_PROFILE: "/api/v1/service-account/lookup-user-profile",
83
83
  REFRESH_TOKEN: "/api/v1/service-account/refresh-token",
84
- VALIDATE_TOKEN: "/api/v1/service-account/validate-jwt-token"
84
+ VALIDATE_JWT_TOKEN: "/api/v1/service-account/validate-jwt-token"
85
85
  };
86
86
 
87
87
  // src/client.ts
@@ -92,9 +92,9 @@ var MOCOAuthClient = class {
92
92
  * The response data will contain the authorization URL for the client.
93
93
  * @throws An error if the request to authorize the client fails.
94
94
  */
95
- async authorizeClient() {
95
+ async getLoginToken() {
96
96
  try {
97
- const res = await http.post(API_ENDPOINTS.LOGIN_TOKEN, {
97
+ const res = await http.post(API_ENDPOINTS.GET_LOGIN_TOKEN, {
98
98
  clientId: config.clientId,
99
99
  clientSecret: config.clientSecret,
100
100
  redirectUri: config.redirectUri
@@ -118,9 +118,9 @@ var MOCOAuthClient = class {
118
118
  * an access token, and a refresh token.
119
119
  * @throws An error if the request to validate the token fails.
120
120
  */
121
- async validateToken(accessToken) {
121
+ async validateJwtToken(accessToken) {
122
122
  try {
123
- const res = await http.post(API_ENDPOINTS.VALIDATE_TOKEN, {
123
+ const res = await http.post(API_ENDPOINTS.VALIDATE_JWT_TOKEN, {
124
124
  accessToken
125
125
  });
126
126
  return {
@@ -141,9 +141,9 @@ var MOCOAuthClient = class {
141
141
  * The response data will contain the current user's email, first name, and last name.
142
142
  * @throws An error if the request to retrieve the user's information fails.
143
143
  */
144
- async getCurrentUser(accessToken) {
144
+ async lookupUserProfile(accessToken) {
145
145
  try {
146
- const res = await http.get(API_ENDPOINTS.USER, {
146
+ const res = await http.get(API_ENDPOINTS.LOOKUP_USER_PROFILE, {
147
147
  headers: {
148
148
  Authorization: `Bearer ${accessToken}`
149
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moc-oauth-client",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "OAuth client for Ministry of Commerce, Cambodia",
5
5
  "author": "Ministry of Commerce, Cambodia",
6
6
  "license": "MIT",