@asgardeo/javascript 0.20.0 → 0.20.1

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.
@@ -2021,20 +2021,37 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
2021
2021
  __publicField(_AsgardeoAuthClient, "authHelperInstance");
2022
2022
  var AsgardeoAuthClient = _AsgardeoAuthClient;
2023
2023
 
2024
+ // src/utils/parseApiErrorMessage.ts
2025
+ var parseApiErrorMessage = (errorText) => {
2026
+ try {
2027
+ const parsed = JSON.parse(errorText);
2028
+ const description = parsed["description"];
2029
+ const message = parsed["message"];
2030
+ if (description?.defaultValue) return description.defaultValue;
2031
+ if (message?.defaultValue) return message.defaultValue;
2032
+ } catch {
2033
+ }
2034
+ return errorText;
2035
+ };
2036
+ var parseApiErrorMessage_default = parseApiErrorMessage;
2037
+
2024
2038
  // src/errors/AsgardeoAPIError.ts
2025
2039
  var AsgardeoAPIError = class extends AsgardeoError {
2026
2040
  /**
2027
2041
  * Creates an instance of AsgardeoAPIError.
2028
2042
  *
2029
- * @param message - Human-readable description of the error
2043
+ * @param message - Human-readable description or raw API error response body
2030
2044
  * @param code - A unique error code that identifies the error type
2045
+ * @param origin - The SDK origin (e.g. 'react', 'vue')
2031
2046
  * @param statusCode - HTTP status code of the failed request
2032
2047
  * @param statusText - HTTP status text of the failed request
2033
- * @param origin - Optional. The SDK origin (e.g. 'react', 'vue'). Defaults to generic 'Asgardeo'
2048
+ * @param prefix - Optional prefix prepended to the resolved message
2034
2049
  * @constructor
2035
2050
  */
2036
- constructor(message, code, origin, statusCode, statusText) {
2037
- super(message, code, origin);
2051
+ constructor(message, code, origin, statusCode, statusText, prefix) {
2052
+ const parsed = parseApiErrorMessage_default(message);
2053
+ const resolvedMessage = prefix ? `${prefix}: ${parsed}` : parsed;
2054
+ super(resolvedMessage, code, origin);
2038
2055
  this.statusCode = statusCode;
2039
2056
  this.statusText = statusText;
2040
2057
  Object.defineProperty(this, "name", {
@@ -2101,11 +2118,12 @@ var initializeEmbeddedSignInFlow = async ({
2101
2118
  if (!response.ok) {
2102
2119
  const errorText = await response.text();
2103
2120
  throw new AsgardeoAPIError(
2104
- `Authorization request failed: ${errorText}`,
2121
+ errorText,
2105
2122
  "initializeEmbeddedSignInFlow-ResponseError-001",
2106
2123
  "javascript",
2107
2124
  response.status,
2108
- response.statusText
2125
+ response.statusText,
2126
+ "Authorization request failed"
2109
2127
  );
2110
2128
  }
2111
2129
  return await response.json();
@@ -2165,11 +2183,12 @@ var executeEmbeddedSignInFlow = async ({
2165
2183
  if (!response.ok) {
2166
2184
  const errorText = await response.text();
2167
2185
  throw new AsgardeoAPIError(
2168
- `Authorization request failed: ${errorText}`,
2186
+ errorText,
2169
2187
  "initializeEmbeddedSignInFlow-ResponseError-001",
2170
2188
  "javascript",
2171
2189
  response.status,
2172
- response.statusText
2190
+ response.statusText,
2191
+ "Authorization request failed"
2173
2192
  );
2174
2193
  }
2175
2194
  return await response.json();
@@ -2263,11 +2282,12 @@ var executeEmbeddedSignUpFlow = async ({
2263
2282
  if (!response.ok) {
2264
2283
  const errorText = await response.text();
2265
2284
  throw new AsgardeoAPIError(
2266
- `Embedded SignUp flow execution failed: ${errorText}`,
2285
+ errorText,
2267
2286
  "javascript-executeEmbeddedSignUpFlow-ResponseError-100",
2268
2287
  "javascript",
2269
2288
  response.status,
2270
- response.statusText
2289
+ response.statusText,
2290
+ "Embedded SignUp flow execution failed"
2271
2291
  );
2272
2292
  }
2273
2293
  return await response.json();
@@ -2312,11 +2332,12 @@ var getUserInfo = async ({ url, ...requestConfig }) => {
2312
2332
  if (!response.ok) {
2313
2333
  const errorText = await response.text();
2314
2334
  throw new AsgardeoAPIError(
2315
- `Failed to fetch user info: ${errorText}`,
2335
+ errorText,
2316
2336
  "getUserInfo-ResponseError-001",
2317
2337
  "javascript",
2318
2338
  response.status,
2319
- response.statusText
2339
+ response.statusText,
2340
+ "Failed to fetch user info"
2320
2341
  );
2321
2342
  }
2322
2343
  return await response.json();
@@ -2390,11 +2411,12 @@ var getScim2Me = async ({ url, baseUrl, fetcher, ...requestConfig }) => {
2390
2411
  if (!response?.ok) {
2391
2412
  const errorText = await response.text();
2392
2413
  throw new AsgardeoAPIError(
2393
- `Failed to fetch user profile: ${errorText}`,
2414
+ errorText,
2394
2415
  "getScim2Me-ResponseError-001",
2395
2416
  "javascript",
2396
2417
  response.status,
2397
- response.statusText
2418
+ response.statusText,
2419
+ "Failed to fetch user profile"
2398
2420
  );
2399
2421
  }
2400
2422
  const user = await response.json();
@@ -2443,11 +2465,12 @@ var getSchemas = async ({ url, baseUrl, fetcher, ...requestConfig }) => {
2443
2465
  if (!response?.ok) {
2444
2466
  const errorText = await response.text();
2445
2467
  throw new AsgardeoAPIError(
2446
- `Failed to fetch SCIM2 schemas: ${errorText}`,
2468
+ errorText,
2447
2469
  "getSchemas-ResponseError-001",
2448
2470
  "javascript",
2449
2471
  response.status,
2450
- response.statusText
2472
+ response.statusText,
2473
+ "Failed to fetch SCIM2 schemas"
2451
2474
  );
2452
2475
  }
2453
2476
  return await response.json();
@@ -2511,11 +2534,12 @@ var getAllOrganizations = async ({
2511
2534
  if (!response?.ok) {
2512
2535
  const errorText = await response.text();
2513
2536
  throw new AsgardeoAPIError(
2514
- `Failed to get organizations: ${errorText}`,
2537
+ errorText,
2515
2538
  "getAllOrganizations-ResponseError-001",
2516
2539
  "javascript",
2517
2540
  response.status,
2518
- response.statusText
2541
+ response.statusText,
2542
+ "Failed to get organizations"
2519
2543
  );
2520
2544
  }
2521
2545
  const data = await response.json();
@@ -2588,11 +2612,12 @@ var createOrganization = async ({
2588
2612
  if (!response?.ok) {
2589
2613
  const errorText = await response.text();
2590
2614
  throw new AsgardeoAPIError(
2591
- `Failed to create organization: ${errorText}`,
2615
+ errorText,
2592
2616
  "createOrganization-ResponseError-001",
2593
2617
  "javascript",
2594
2618
  response.status,
2595
- response.statusText
2619
+ response.statusText,
2620
+ "Failed to create organization"
2596
2621
  );
2597
2622
  }
2598
2623
  return await response.json();
@@ -2662,11 +2687,12 @@ var getMeOrganizations = async ({
2662
2687
  if (!response?.ok) {
2663
2688
  const errorText = await response.text();
2664
2689
  throw new AsgardeoAPIError(
2665
- `Failed to fetch associated organizations of the user: ${errorText}`,
2690
+ errorText,
2666
2691
  "getMeOrganizations-ResponseError-001",
2667
2692
  "javascript",
2668
2693
  response.status,
2669
- response.statusText
2694
+ response.statusText,
2695
+ "Failed to fetch associated organizations of the user"
2670
2696
  );
2671
2697
  }
2672
2698
  const data = await response.json();
@@ -2729,11 +2755,12 @@ var getOrganization = async ({
2729
2755
  if (!response?.ok) {
2730
2756
  const errorText = await response.text();
2731
2757
  throw new AsgardeoAPIError(
2732
- `Failed to fetch organization details: ${errorText}`,
2758
+ errorText,
2733
2759
  "getOrganization-ResponseError-001",
2734
2760
  "javascript",
2735
2761
  response.status,
2736
- response.statusText
2762
+ response.statusText,
2763
+ "Failed to fetch organization details"
2737
2764
  );
2738
2765
  }
2739
2766
  return await response.json();
@@ -2824,11 +2851,12 @@ var updateOrganization = async ({
2824
2851
  if (!response?.ok) {
2825
2852
  const errorText = await response.text();
2826
2853
  throw new AsgardeoAPIError(
2827
- `Failed to update organization: ${errorText}`,
2854
+ errorText,
2828
2855
  "updateOrganization-ResponseError-001",
2829
2856
  "javascript",
2830
2857
  response.status,
2831
- response.statusText
2858
+ response.statusText,
2859
+ "Failed to update organization"
2832
2860
  );
2833
2861
  }
2834
2862
  return await response.json();
@@ -2905,11 +2933,12 @@ var updateMeProfile = async ({
2905
2933
  if (!response?.ok) {
2906
2934
  const errorText = await response.text();
2907
2935
  throw new AsgardeoAPIError(
2908
- `Failed to update user profile: ${errorText}`,
2936
+ errorText,
2909
2937
  "updateMeProfile-ResponseError-001",
2910
2938
  "javascript",
2911
2939
  response.status,
2912
- response.statusText
2940
+ response.statusText,
2941
+ "Failed to update user profile"
2913
2942
  );
2914
2943
  }
2915
2944
  return processUsername_default(await response.json());
@@ -2973,11 +3002,12 @@ var getBrandingPreference = async ({
2973
3002
  if (!response?.ok) {
2974
3003
  const errorText = await response.text();
2975
3004
  throw new AsgardeoAPIError(
2976
- `Failed to get branding preference: ${errorText}`,
3005
+ errorText,
2977
3006
  "getBrandingPreference-ResponseError-001",
2978
3007
  "javascript",
2979
3008
  response.status,
2980
- response.statusText
3009
+ response.statusText,
3010
+ "Failed to get branding preference"
2981
3011
  );
2982
3012
  }
2983
3013
  const data = await response.json();
@@ -3045,11 +3075,12 @@ var executeEmbeddedSignInFlowV2 = async ({
3045
3075
  if (!response.ok) {
3046
3076
  const errorText = await response.text();
3047
3077
  throw new AsgardeoAPIError(
3048
- `Authorization request failed: ${errorText}`,
3078
+ errorText,
3049
3079
  "executeEmbeddedSignInFlow-ResponseError-001",
3050
3080
  "javascript",
3051
3081
  response.status,
3052
- response.statusText
3082
+ response.statusText,
3083
+ "Authorization request failed"
3053
3084
  );
3054
3085
  }
3055
3086
  const flowResponse = await response.json();
@@ -3145,11 +3176,12 @@ var executeEmbeddedSignUpFlowV2 = async ({
3145
3176
  if (!response.ok) {
3146
3177
  const errorText = await response.text();
3147
3178
  throw new AsgardeoAPIError(
3148
- `Registration request failed: ${errorText}`,
3179
+ errorText,
3149
3180
  "executeEmbeddedSignUpFlow-ResponseError-001",
3150
3181
  "javascript",
3151
3182
  response.status,
3152
- response.statusText
3183
+ response.statusText,
3184
+ "Registration request failed"
3153
3185
  );
3154
3186
  }
3155
3187
  const flowResponse = await response.json();
@@ -3284,11 +3316,12 @@ var executeEmbeddedUserOnboardingFlowV2 = async ({
3284
3316
  if (!response.ok) {
3285
3317
  const errorText = await response.text();
3286
3318
  throw new AsgardeoAPIError(
3287
- `User onboarding request failed: ${errorText}`,
3319
+ errorText,
3288
3320
  "executeEmbeddedUserOnboardingFlow-ResponseError-001",
3289
3321
  "javascript",
3290
3322
  response.status,
3291
- response.statusText
3323
+ response.statusText,
3324
+ "User onboarding request failed"
3292
3325
  );
3293
3326
  }
3294
3327
  const flowResponse = await response.json();
@@ -3325,11 +3358,12 @@ var getFlowMetaV2 = async ({
3325
3358
  if (!response.ok) {
3326
3359
  const errorText = await response.text();
3327
3360
  throw new AsgardeoAPIError(
3328
- `Flow metadata request failed: ${errorText}`,
3361
+ errorText,
3329
3362
  "getFlowMetaV2-ResponseError-001",
3330
3363
  "javascript",
3331
3364
  response.status,
3332
- response.statusText
3365
+ response.statusText,
3366
+ "Flow metadata request failed"
3333
3367
  );
3334
3368
  }
3335
3369
  const flowMetadata = await response.json();
@@ -3371,11 +3405,12 @@ var getOrganizationUnitChildren = async ({
3371
3405
  if (!response.ok) {
3372
3406
  const errorText = await response.text();
3373
3407
  throw new AsgardeoAPIError(
3374
- `Failed to fetch organization unit children: ${errorText}`,
3408
+ errorText,
3375
3409
  "getOrganizationUnitChildren-ResponseError-001",
3376
3410
  "javascript",
3377
3411
  response.status,
3378
- response.statusText
3412
+ response.statusText,
3413
+ "Failed to fetch organization unit children"
3379
3414
  );
3380
3415
  }
3381
3416
  const listResponse = await response.json();