@asgardeo/javascript 0.19.2 → 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.
Files changed (43) hide show
  1. package/dist/AsgardeoJavaScriptClient.d.ts +2 -1
  2. package/dist/AsgardeoJavaScriptClient.d.ts.map +1 -1
  3. package/dist/api/createOrganization.d.ts.map +1 -1
  4. package/dist/api/executeEmbeddedSignInFlow.d.ts.map +1 -1
  5. package/dist/api/executeEmbeddedSignUpFlow.d.ts.map +1 -1
  6. package/dist/api/getAllOrganizations.d.ts.map +1 -1
  7. package/dist/api/getBrandingPreference.d.ts.map +1 -1
  8. package/dist/api/getMeOrganizations.d.ts.map +1 -1
  9. package/dist/api/getOrganization.d.ts.map +1 -1
  10. package/dist/api/getSchemas.d.ts.map +1 -1
  11. package/dist/api/getScim2Me.d.ts.map +1 -1
  12. package/dist/api/getUserInfo.d.ts.map +1 -1
  13. package/dist/api/initializeEmbeddedSignInFlow.d.ts.map +1 -1
  14. package/dist/api/updateMeProfile.d.ts.map +1 -1
  15. package/dist/api/updateOrganization.d.ts.map +1 -1
  16. package/dist/api/v2/executeEmbeddedRecoveryFlowV2.d.ts +57 -0
  17. package/dist/api/v2/executeEmbeddedRecoveryFlowV2.d.ts.map +1 -0
  18. package/dist/api/v2/executeEmbeddedSignInFlowV2.d.ts.map +1 -1
  19. package/dist/api/v2/executeEmbeddedSignUpFlowV2.d.ts.map +1 -1
  20. package/dist/api/v2/executeEmbeddedUserOnboardingFlowV2.d.ts.map +1 -1
  21. package/dist/api/v2/getFlowMetaV2.d.ts.map +1 -1
  22. package/dist/api/v2/getOrganizationUnitChildren.d.ts.map +1 -1
  23. package/dist/cjs/index.js +147 -40
  24. package/dist/cjs/index.js.map +4 -4
  25. package/dist/edge/index.js +144 -40
  26. package/dist/edge/index.js.map +4 -4
  27. package/dist/errors/AsgardeoAPIError.d.ts +9 -3
  28. package/dist/errors/AsgardeoAPIError.d.ts.map +1 -1
  29. package/dist/index.d.ts +3 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +144 -40
  32. package/dist/index.js.map +4 -4
  33. package/dist/models/client.d.ts +8 -1
  34. package/dist/models/client.d.ts.map +1 -1
  35. package/dist/models/config.d.ts +1 -1
  36. package/dist/models/config.d.ts.map +1 -1
  37. package/dist/models/embedded-flow.d.ts +3 -2
  38. package/dist/models/embedded-flow.d.ts.map +1 -1
  39. package/dist/models/v2/embedded-recovery-flow-v2.d.ts +143 -0
  40. package/dist/models/v2/embedded-recovery-flow-v2.d.ts.map +1 -0
  41. package/dist/utils/parseApiErrorMessage.d.ts +29 -0
  42. package/dist/utils/parseApiErrorMessage.d.ts.map +1 -0
  43. package/package.json +1 -1
@@ -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();
@@ -2191,6 +2210,7 @@ var executeEmbeddedSignInFlow_default = executeEmbeddedSignInFlow;
2191
2210
  // src/models/embedded-flow.ts
2192
2211
  var EmbeddedFlowType = /* @__PURE__ */ ((EmbeddedFlowType2) => {
2193
2212
  EmbeddedFlowType2["Authentication"] = "AUTHENTICATION";
2213
+ EmbeddedFlowType2["Recovery"] = "RECOVERY";
2194
2214
  EmbeddedFlowType2["Registration"] = "REGISTRATION";
2195
2215
  EmbeddedFlowType2["UserOnboarding"] = "USER_ONBOARDING";
2196
2216
  return EmbeddedFlowType2;
@@ -2262,11 +2282,12 @@ var executeEmbeddedSignUpFlow = async ({
2262
2282
  if (!response.ok) {
2263
2283
  const errorText = await response.text();
2264
2284
  throw new AsgardeoAPIError(
2265
- `Embedded SignUp flow execution failed: ${errorText}`,
2285
+ errorText,
2266
2286
  "javascript-executeEmbeddedSignUpFlow-ResponseError-100",
2267
2287
  "javascript",
2268
2288
  response.status,
2269
- response.statusText
2289
+ response.statusText,
2290
+ "Embedded SignUp flow execution failed"
2270
2291
  );
2271
2292
  }
2272
2293
  return await response.json();
@@ -2311,11 +2332,12 @@ var getUserInfo = async ({ url, ...requestConfig }) => {
2311
2332
  if (!response.ok) {
2312
2333
  const errorText = await response.text();
2313
2334
  throw new AsgardeoAPIError(
2314
- `Failed to fetch user info: ${errorText}`,
2335
+ errorText,
2315
2336
  "getUserInfo-ResponseError-001",
2316
2337
  "javascript",
2317
2338
  response.status,
2318
- response.statusText
2339
+ response.statusText,
2340
+ "Failed to fetch user info"
2319
2341
  );
2320
2342
  }
2321
2343
  return await response.json();
@@ -2389,11 +2411,12 @@ var getScim2Me = async ({ url, baseUrl, fetcher, ...requestConfig }) => {
2389
2411
  if (!response?.ok) {
2390
2412
  const errorText = await response.text();
2391
2413
  throw new AsgardeoAPIError(
2392
- `Failed to fetch user profile: ${errorText}`,
2414
+ errorText,
2393
2415
  "getScim2Me-ResponseError-001",
2394
2416
  "javascript",
2395
2417
  response.status,
2396
- response.statusText
2418
+ response.statusText,
2419
+ "Failed to fetch user profile"
2397
2420
  );
2398
2421
  }
2399
2422
  const user = await response.json();
@@ -2442,11 +2465,12 @@ var getSchemas = async ({ url, baseUrl, fetcher, ...requestConfig }) => {
2442
2465
  if (!response?.ok) {
2443
2466
  const errorText = await response.text();
2444
2467
  throw new AsgardeoAPIError(
2445
- `Failed to fetch SCIM2 schemas: ${errorText}`,
2468
+ errorText,
2446
2469
  "getSchemas-ResponseError-001",
2447
2470
  "javascript",
2448
2471
  response.status,
2449
- response.statusText
2472
+ response.statusText,
2473
+ "Failed to fetch SCIM2 schemas"
2450
2474
  );
2451
2475
  }
2452
2476
  return await response.json();
@@ -2510,11 +2534,12 @@ var getAllOrganizations = async ({
2510
2534
  if (!response?.ok) {
2511
2535
  const errorText = await response.text();
2512
2536
  throw new AsgardeoAPIError(
2513
- `Failed to get organizations: ${errorText}`,
2537
+ errorText,
2514
2538
  "getAllOrganizations-ResponseError-001",
2515
2539
  "javascript",
2516
2540
  response.status,
2517
- response.statusText
2541
+ response.statusText,
2542
+ "Failed to get organizations"
2518
2543
  );
2519
2544
  }
2520
2545
  const data = await response.json();
@@ -2587,11 +2612,12 @@ var createOrganization = async ({
2587
2612
  if (!response?.ok) {
2588
2613
  const errorText = await response.text();
2589
2614
  throw new AsgardeoAPIError(
2590
- `Failed to create organization: ${errorText}`,
2615
+ errorText,
2591
2616
  "createOrganization-ResponseError-001",
2592
2617
  "javascript",
2593
2618
  response.status,
2594
- response.statusText
2619
+ response.statusText,
2620
+ "Failed to create organization"
2595
2621
  );
2596
2622
  }
2597
2623
  return await response.json();
@@ -2661,11 +2687,12 @@ var getMeOrganizations = async ({
2661
2687
  if (!response?.ok) {
2662
2688
  const errorText = await response.text();
2663
2689
  throw new AsgardeoAPIError(
2664
- `Failed to fetch associated organizations of the user: ${errorText}`,
2690
+ errorText,
2665
2691
  "getMeOrganizations-ResponseError-001",
2666
2692
  "javascript",
2667
2693
  response.status,
2668
- response.statusText
2694
+ response.statusText,
2695
+ "Failed to fetch associated organizations of the user"
2669
2696
  );
2670
2697
  }
2671
2698
  const data = await response.json();
@@ -2728,11 +2755,12 @@ var getOrganization = async ({
2728
2755
  if (!response?.ok) {
2729
2756
  const errorText = await response.text();
2730
2757
  throw new AsgardeoAPIError(
2731
- `Failed to fetch organization details: ${errorText}`,
2758
+ errorText,
2732
2759
  "getOrganization-ResponseError-001",
2733
2760
  "javascript",
2734
2761
  response.status,
2735
- response.statusText
2762
+ response.statusText,
2763
+ "Failed to fetch organization details"
2736
2764
  );
2737
2765
  }
2738
2766
  return await response.json();
@@ -2823,11 +2851,12 @@ var updateOrganization = async ({
2823
2851
  if (!response?.ok) {
2824
2852
  const errorText = await response.text();
2825
2853
  throw new AsgardeoAPIError(
2826
- `Failed to update organization: ${errorText}`,
2854
+ errorText,
2827
2855
  "updateOrganization-ResponseError-001",
2828
2856
  "javascript",
2829
2857
  response.status,
2830
- response.statusText
2858
+ response.statusText,
2859
+ "Failed to update organization"
2831
2860
  );
2832
2861
  }
2833
2862
  return await response.json();
@@ -2904,11 +2933,12 @@ var updateMeProfile = async ({
2904
2933
  if (!response?.ok) {
2905
2934
  const errorText = await response.text();
2906
2935
  throw new AsgardeoAPIError(
2907
- `Failed to update user profile: ${errorText}`,
2936
+ errorText,
2908
2937
  "updateMeProfile-ResponseError-001",
2909
2938
  "javascript",
2910
2939
  response.status,
2911
- response.statusText
2940
+ response.statusText,
2941
+ "Failed to update user profile"
2912
2942
  );
2913
2943
  }
2914
2944
  return processUsername_default(await response.json());
@@ -2972,11 +3002,12 @@ var getBrandingPreference = async ({
2972
3002
  if (!response?.ok) {
2973
3003
  const errorText = await response.text();
2974
3004
  throw new AsgardeoAPIError(
2975
- `Failed to get branding preference: ${errorText}`,
3005
+ errorText,
2976
3006
  "getBrandingPreference-ResponseError-001",
2977
3007
  "javascript",
2978
3008
  response.status,
2979
- response.statusText
3009
+ response.statusText,
3010
+ "Failed to get branding preference"
2980
3011
  );
2981
3012
  }
2982
3013
  const data = await response.json();
@@ -3044,11 +3075,12 @@ var executeEmbeddedSignInFlowV2 = async ({
3044
3075
  if (!response.ok) {
3045
3076
  const errorText = await response.text();
3046
3077
  throw new AsgardeoAPIError(
3047
- `Authorization request failed: ${errorText}`,
3078
+ errorText,
3048
3079
  "executeEmbeddedSignInFlow-ResponseError-001",
3049
3080
  "javascript",
3050
3081
  response.status,
3051
- response.statusText
3082
+ response.statusText,
3083
+ "Authorization request failed"
3052
3084
  );
3053
3085
  }
3054
3086
  const flowResponse = await response.json();
@@ -3144,11 +3176,12 @@ var executeEmbeddedSignUpFlowV2 = async ({
3144
3176
  if (!response.ok) {
3145
3177
  const errorText = await response.text();
3146
3178
  throw new AsgardeoAPIError(
3147
- `Registration request failed: ${errorText}`,
3179
+ errorText,
3148
3180
  "executeEmbeddedSignUpFlow-ResponseError-001",
3149
3181
  "javascript",
3150
3182
  response.status,
3151
- response.statusText
3183
+ response.statusText,
3184
+ "Registration request failed"
3152
3185
  );
3153
3186
  }
3154
3187
  const flowResponse = await response.json();
@@ -3196,6 +3229,55 @@ var executeEmbeddedSignUpFlowV2 = async ({
3196
3229
  };
3197
3230
  var executeEmbeddedSignUpFlowV2_default = executeEmbeddedSignUpFlowV2;
3198
3231
 
3232
+ // src/api/v2/executeEmbeddedRecoveryFlowV2.ts
3233
+ var executeEmbeddedRecoveryFlowV2 = async ({
3234
+ url,
3235
+ baseUrl,
3236
+ payload,
3237
+ ...requestConfig
3238
+ }) => {
3239
+ if (!payload) {
3240
+ throw new AsgardeoAPIError(
3241
+ "Recovery payload is required",
3242
+ "executeEmbeddedRecoveryFlow-ValidationError-002",
3243
+ "javascript",
3244
+ 400,
3245
+ "If a recovery payload is not provided, the request cannot be constructed correctly."
3246
+ );
3247
+ }
3248
+ const endpoint = url ?? `${baseUrl}/flow/execute`;
3249
+ const cleanPayload = typeof payload === "object" && payload !== null ? Object.fromEntries(Object.entries(payload).filter(([key]) => key !== "verbose")) : payload;
3250
+ const hasOnlyAppIdAndFlowType = typeof cleanPayload === "object" && cleanPayload !== null && "applicationId" in cleanPayload && "flowType" in cleanPayload && Object.keys(cleanPayload).length === 2;
3251
+ const hasOnlyFlowId = typeof cleanPayload === "object" && cleanPayload !== null && "executionId" in cleanPayload && Object.keys(cleanPayload).length === 1;
3252
+ const requestPayload = hasOnlyAppIdAndFlowType || hasOnlyFlowId ? {
3253
+ ...cleanPayload,
3254
+ verbose: true
3255
+ } : cleanPayload;
3256
+ const response = await fetch(endpoint, {
3257
+ ...requestConfig,
3258
+ body: JSON.stringify(requestPayload),
3259
+ headers: {
3260
+ Accept: "application/json",
3261
+ "Content-Type": "application/json",
3262
+ ...requestConfig.headers
3263
+ },
3264
+ method: requestConfig.method || "POST"
3265
+ });
3266
+ if (!response.ok) {
3267
+ const errorText = await response.text();
3268
+ throw new AsgardeoAPIError(
3269
+ `Recovery request failed: ${errorText}`,
3270
+ "executeEmbeddedRecoveryFlow-ResponseError-001",
3271
+ "javascript",
3272
+ response.status,
3273
+ response.statusText
3274
+ );
3275
+ }
3276
+ const flowResponse = await response.json();
3277
+ return flowResponse;
3278
+ };
3279
+ var executeEmbeddedRecoveryFlowV2_default = executeEmbeddedRecoveryFlowV2;
3280
+
3199
3281
  // src/api/v2/executeEmbeddedUserOnboardingFlowV2.ts
3200
3282
  var executeEmbeddedUserOnboardingFlowV2 = async ({
3201
3283
  url,
@@ -3234,11 +3316,12 @@ var executeEmbeddedUserOnboardingFlowV2 = async ({
3234
3316
  if (!response.ok) {
3235
3317
  const errorText = await response.text();
3236
3318
  throw new AsgardeoAPIError(
3237
- `User onboarding request failed: ${errorText}`,
3319
+ errorText,
3238
3320
  "executeEmbeddedUserOnboardingFlow-ResponseError-001",
3239
3321
  "javascript",
3240
3322
  response.status,
3241
- response.statusText
3323
+ response.statusText,
3324
+ "User onboarding request failed"
3242
3325
  );
3243
3326
  }
3244
3327
  const flowResponse = await response.json();
@@ -3275,11 +3358,12 @@ var getFlowMetaV2 = async ({
3275
3358
  if (!response.ok) {
3276
3359
  const errorText = await response.text();
3277
3360
  throw new AsgardeoAPIError(
3278
- `Flow metadata request failed: ${errorText}`,
3361
+ errorText,
3279
3362
  "getFlowMetaV2-ResponseError-001",
3280
3363
  "javascript",
3281
3364
  response.status,
3282
- response.statusText
3365
+ response.statusText,
3366
+ "Flow metadata request failed"
3283
3367
  );
3284
3368
  }
3285
3369
  const flowMetadata = await response.json();
@@ -3321,11 +3405,12 @@ var getOrganizationUnitChildren = async ({
3321
3405
  if (!response.ok) {
3322
3406
  const errorText = await response.text();
3323
3407
  throw new AsgardeoAPIError(
3324
- `Failed to fetch organization unit children: ${errorText}`,
3408
+ errorText,
3325
3409
  "getOrganizationUnitChildren-ResponseError-001",
3326
3410
  "javascript",
3327
3411
  response.status,
3328
- response.statusText
3412
+ response.statusText,
3413
+ "Failed to fetch organization unit children"
3329
3414
  );
3330
3415
  }
3331
3416
  const listResponse = await response.json();
@@ -3457,6 +3542,19 @@ var EmbeddedFlowEventType = /* @__PURE__ */ ((EmbeddedFlowEventType2) => {
3457
3542
  return EmbeddedFlowEventType2;
3458
3543
  })(EmbeddedFlowEventType || {});
3459
3544
 
3545
+ // src/models/v2/embedded-recovery-flow-v2.ts
3546
+ var EmbeddedRecoveryFlowStatus = /* @__PURE__ */ ((EmbeddedRecoveryFlowStatus2) => {
3547
+ EmbeddedRecoveryFlowStatus2["Complete"] = "COMPLETE";
3548
+ EmbeddedRecoveryFlowStatus2["Error"] = "ERROR";
3549
+ EmbeddedRecoveryFlowStatus2["Incomplete"] = "INCOMPLETE";
3550
+ return EmbeddedRecoveryFlowStatus2;
3551
+ })(EmbeddedRecoveryFlowStatus || {});
3552
+ var EmbeddedRecoveryFlowType = /* @__PURE__ */ ((EmbeddedRecoveryFlowType2) => {
3553
+ EmbeddedRecoveryFlowType2["Redirection"] = "REDIRECTION";
3554
+ EmbeddedRecoveryFlowType2["View"] = "VIEW";
3555
+ return EmbeddedRecoveryFlowType2;
3556
+ })(EmbeddedRecoveryFlowType || {});
3557
+
3460
3558
  // src/models/v2/flow-meta-v2.ts
3461
3559
  var FlowMetaType = /* @__PURE__ */ ((FlowMetaType2) => {
3462
3560
  FlowMetaType2["App"] = "APP";
@@ -3661,6 +3759,9 @@ var AsgardeoJavaScriptClient = class {
3661
3759
  signOut(_options, _sessionIdOrAfterSignOut, _afterSignOut) {
3662
3760
  throw new Error("Method not implemented.");
3663
3761
  }
3762
+ recover(_payload) {
3763
+ throw new Error("Method not implemented.");
3764
+ }
3664
3765
  signUp(_optionsOrPayload) {
3665
3766
  throw new Error("Method not implemented.");
3666
3767
  }
@@ -5423,6 +5524,8 @@ export {
5423
5524
  EmbeddedFlowStatus,
5424
5525
  EmbeddedFlowTextVariant as EmbeddedFlowTextVariantV2,
5425
5526
  EmbeddedFlowType,
5527
+ EmbeddedRecoveryFlowStatus as EmbeddedRecoveryFlowStatusV2,
5528
+ EmbeddedRecoveryFlowType as EmbeddedRecoveryFlowTypeV2,
5426
5529
  EmbeddedSignInFlowAuthenticatorKnownIdPType,
5427
5530
  EmbeddedSignInFlowAuthenticatorParamType,
5428
5531
  EmbeddedSignInFlowAuthenticatorPromptType,
@@ -5460,6 +5563,7 @@ export {
5460
5563
  deepMerge_default as deepMerge,
5461
5564
  deriveOrganizationHandleFromBaseUrl_default as deriveOrganizationHandleFromBaseUrl,
5462
5565
  error,
5566
+ executeEmbeddedRecoveryFlowV2_default as executeEmbeddedRecoveryFlowV2,
5463
5567
  executeEmbeddedSignInFlow_default as executeEmbeddedSignInFlow,
5464
5568
  executeEmbeddedSignInFlowV2_default as executeEmbeddedSignInFlowV2,
5465
5569
  executeEmbeddedSignUpFlow_default as executeEmbeddedSignUpFlow,