authtara-sdk 1.1.4 → 1.1.5

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.js CHANGED
@@ -234,14 +234,42 @@ var AuthModule = class {
234
234
  if (!redirectUri) {
235
235
  throw new ConfigurationError("Redirect URI is required");
236
236
  }
237
- const response = await this.httpClient.post("/api/oauth/token", {
237
+ const url = `${this.httpClient["baseUrl"]}/api/oauth/token`;
238
+ const body = {
238
239
  grant_type: "authorization_code",
239
240
  code,
240
241
  client_id: this.appId,
241
242
  client_secret: this.apiKey,
242
243
  redirect_uri: redirectUri
243
- });
244
- return response;
244
+ };
245
+ try {
246
+ const response = await fetch(url, {
247
+ method: "POST",
248
+ headers: {
249
+ "Content-Type": "application/json",
250
+ "Authorization": `Bearer ${this.apiKey}`
251
+ },
252
+ body: JSON.stringify(body)
253
+ });
254
+ if (!response.ok) {
255
+ const errorData = await response.json().catch(() => ({}));
256
+ throw new ApiError(
257
+ errorData.message || `HTTP ${response.status}`,
258
+ response.status,
259
+ errorData
260
+ );
261
+ }
262
+ const data = await response.json();
263
+ return data;
264
+ } catch (error) {
265
+ if (error instanceof ApiError) {
266
+ throw error;
267
+ }
268
+ throw new ApiError(
269
+ error instanceof Error ? error.message : "Token exchange failed",
270
+ 500
271
+ );
272
+ }
245
273
  }
246
274
  };
247
275
 
package/dist/index.mjs CHANGED
@@ -202,14 +202,42 @@ var AuthModule = class {
202
202
  if (!redirectUri) {
203
203
  throw new ConfigurationError("Redirect URI is required");
204
204
  }
205
- const response = await this.httpClient.post("/api/oauth/token", {
205
+ const url = `${this.httpClient["baseUrl"]}/api/oauth/token`;
206
+ const body = {
206
207
  grant_type: "authorization_code",
207
208
  code,
208
209
  client_id: this.appId,
209
210
  client_secret: this.apiKey,
210
211
  redirect_uri: redirectUri
211
- });
212
- return response;
212
+ };
213
+ try {
214
+ const response = await fetch(url, {
215
+ method: "POST",
216
+ headers: {
217
+ "Content-Type": "application/json",
218
+ "Authorization": `Bearer ${this.apiKey}`
219
+ },
220
+ body: JSON.stringify(body)
221
+ });
222
+ if (!response.ok) {
223
+ const errorData = await response.json().catch(() => ({}));
224
+ throw new ApiError(
225
+ errorData.message || `HTTP ${response.status}`,
226
+ response.status,
227
+ errorData
228
+ );
229
+ }
230
+ const data = await response.json();
231
+ return data;
232
+ } catch (error) {
233
+ if (error instanceof ApiError) {
234
+ throw error;
235
+ }
236
+ throw new ApiError(
237
+ error instanceof Error ? error.message : "Token exchange failed",
238
+ 500
239
+ );
240
+ }
213
241
  }
214
242
  };
215
243
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authtara-sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "SDK Client untuk integrasi dengan DigitalSolution Platform - SSO, Billing, dan Metering",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -88,4 +88,4 @@
88
88
  "access": "public",
89
89
  "registry": "https://registry.npmjs.org/"
90
90
  }
91
- }
91
+ }