@axinom/mosaic-user-auth 0.4.4 → 0.5.0-rc.0

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
@@ -59,7 +59,7 @@ function commonjsRequire () {
59
59
 
60
60
  var enums = createCommonjsModule(function (module, exports) {
61
61
  Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.DecryptNativeCookieResponseCode = exports.IdpProtocol = exports.CheckOtpResponseCode = exports.CompleteUserSignUpResponseCode = exports.UserSignUpResponseCode = exports.ROPCPasswordResponseCode = exports.ROPCSignInResponseCode = exports.IdpConfigurationResponseCode = exports.SignOutResponseCode = exports.TokenResponseCode = void 0;
62
+ exports.DecryptNativeCookieResponseCode = exports.IdpProtocol = exports.CheckOtpResponseCode = exports.CompleteUserSignUpResponseCode = exports.UserSignUpResponseCode = exports.ResetPasswordResponseCode = exports.SignInResponseCode = exports.IdpConfigurationResponseCode = exports.SignOutResponseCode = exports.TokenResponseCode = void 0;
63
63
  /**
64
64
  * Token response code from User Service Auth API
65
65
  */
@@ -94,27 +94,27 @@ var IdpConfigurationResponseCode;
94
94
  IdpConfigurationResponseCode["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
95
95
  })(IdpConfigurationResponseCode = exports.IdpConfigurationResponseCode || (exports.IdpConfigurationResponseCode = {}));
96
96
  /**
97
- * ROPC Sign In Response Code from User Service Auth API
97
+ * Sign In With Credentials Response Code from User Service Auth API
98
98
  */
99
- var ROPCSignInResponseCode;
100
- (function (ROPCSignInResponseCode) {
101
- ROPCSignInResponseCode["SUCCESS"] = "SUCCESS";
102
- ROPCSignInResponseCode["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
103
- ROPCSignInResponseCode["BAD_REQUEST"] = "BAD_REQUEST";
104
- ROPCSignInResponseCode["AUTH_FLOW_ERROR"] = "AUTH_FLOW_ERROR";
105
- ROPCSignInResponseCode["SERVICE_CONFIGURATION_ERROR"] = "SERVICE_CONFIGURATION_ERROR";
106
- })(ROPCSignInResponseCode = exports.ROPCSignInResponseCode || (exports.ROPCSignInResponseCode = {}));
99
+ var SignInResponseCode;
100
+ (function (SignInResponseCode) {
101
+ SignInResponseCode["SUCCESS"] = "SUCCESS";
102
+ SignInResponseCode["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
103
+ SignInResponseCode["BAD_REQUEST"] = "BAD_REQUEST";
104
+ SignInResponseCode["AUTH_FLOW_ERROR"] = "AUTH_FLOW_ERROR";
105
+ SignInResponseCode["SERVICE_CONFIGURATION_ERROR"] = "SERVICE_CONFIGURATION_ERROR";
106
+ })(SignInResponseCode = exports.SignInResponseCode || (exports.SignInResponseCode = {}));
107
107
  /**
108
- * ROPC Password Reset/Complete Password Reset Code from User Service Auth API
108
+ * Sign In With Credentials Password Reset/Complete Password Reset Code from User Service Auth API
109
109
  */
110
- var ROPCPasswordResponseCode;
111
- (function (ROPCPasswordResponseCode) {
112
- ROPCPasswordResponseCode["SUCCESS"] = "SUCCESS";
113
- ROPCPasswordResponseCode["ERROR"] = "ERROR";
114
- ROPCPasswordResponseCode["SERVICE_CONFIGURATION_ERROR"] = "SERVICE_CONFIGURATION_ERROR";
115
- })(ROPCPasswordResponseCode = exports.ROPCPasswordResponseCode || (exports.ROPCPasswordResponseCode = {}));
110
+ var ResetPasswordResponseCode;
111
+ (function (ResetPasswordResponseCode) {
112
+ ResetPasswordResponseCode["SUCCESS"] = "SUCCESS";
113
+ ResetPasswordResponseCode["ERROR"] = "ERROR";
114
+ ResetPasswordResponseCode["SERVICE_CONFIGURATION_ERROR"] = "SERVICE_CONFIGURATION_ERROR";
115
+ })(ResetPasswordResponseCode = exports.ResetPasswordResponseCode || (exports.ResetPasswordResponseCode = {}));
116
116
  /**
117
- * ROPC Sign Up Response Code from User Service Auth API
117
+ * Sign Up With Credential Response Code from User Service Auth API
118
118
  */
119
119
  var UserSignUpResponseCode;
120
120
  (function (UserSignUpResponseCode) {
@@ -123,7 +123,7 @@ var UserSignUpResponseCode;
123
123
  UserSignUpResponseCode["SERVICE_CONFIGURATION_ERROR"] = "SERVICE_CONFIGURATION_ERROR";
124
124
  })(UserSignUpResponseCode = exports.UserSignUpResponseCode || (exports.UserSignUpResponseCode = {}));
125
125
  /**
126
- * Verify ROPC Sign Up Response Code from User Service Auth API
126
+ * Verify Sign Up With Credential Response Code from User Service Auth API
127
127
  */
128
128
  var CompleteUserSignUpResponseCode;
129
129
  (function (CompleteUserSignUpResponseCode) {
@@ -1660,15 +1660,15 @@ const getWellKnownEndpoints = (userAuthConfig) => __awaiter(void 0, void 0, void
1660
1660
  return userServiceEndpoints;
1661
1661
  });
1662
1662
  /**
1663
- * Perform a user sign in process according to the ROPC flow.
1663
+ * Perform a user sign in process according to the SignInWithCredentials flow.
1664
1664
  *
1665
1665
  * @param userAuthConfig An object containing user authentication info.
1666
1666
  * @param axAuthConnectionId The IDP Connection ID for AX_AUTH as configured for the application.
1667
- * @param ropcSignInRequest Sign info (email, password).
1667
+ * @param signInRequest Sign info (email, password).
1668
1668
  * @returns
1669
1669
  */
1670
- const performROPCSignIn = (userAuthConfig, axAuthConnectionId, ropcSignInRequest) => __awaiter(void 0, void 0, void 0, function* () {
1671
- const signInURL = new URL(`${userAuthConfig.tenantId}/${userAuthConfig.environmentId}/${userAuthConfig.applicationId}/ropc-sign-in`, userAuthConfig.userAuthBaseUrl);
1670
+ const performSignInWithCredentials = (userAuthConfig, axAuthConnectionId, signInRequest) => __awaiter(void 0, void 0, void 0, function* () {
1671
+ const signInURL = new URL(`${userAuthConfig.tenantId}/${userAuthConfig.environmentId}/${userAuthConfig.applicationId}/sign-in-with-credentials`, userAuthConfig.userAuthBaseUrl);
1672
1672
  const signInResponse = yield (yield fetch(signInURL.href, {
1673
1673
  method: 'POST',
1674
1674
  cache: 'no-cache',
@@ -1678,7 +1678,7 @@ const performROPCSignIn = (userAuthConfig, axAuthConnectionId, ropcSignInRequest
1678
1678
  headers: {
1679
1679
  'Content-Type': 'application/json',
1680
1680
  },
1681
- body: JSON.stringify(Object.assign(Object.assign({}, ropcSignInRequest), { connectionId: axAuthConnectionId })),
1681
+ body: JSON.stringify(Object.assign(Object.assign({}, signInRequest), { connectionId: axAuthConnectionId })),
1682
1682
  })).json();
1683
1683
  return signInResponse;
1684
1684
  });
@@ -1806,12 +1806,12 @@ const initiatePasswordReset = (email, axAuthClientId, axAuthManagementEndpoint)
1806
1806
  })).json();
1807
1807
  if (initiateResetPasswordResponse.errors !== undefined) {
1808
1808
  return {
1809
- code: dist.ROPCPasswordResponseCode.ERROR,
1809
+ code: dist.ResetPasswordResponseCode.ERROR,
1810
1810
  message: initiateResetPasswordResponse.errors[0].message,
1811
1811
  };
1812
1812
  }
1813
1813
  return {
1814
- code: dist.ROPCPasswordResponseCode.SUCCESS,
1814
+ code: dist.ResetPasswordResponseCode.SUCCESS,
1815
1815
  };
1816
1816
  });
1817
1817
  /**
@@ -1872,12 +1872,12 @@ const completePasswordReset = (completePasswordResetRequest, axAuthManagementEnd
1872
1872
  })).json();
1873
1873
  if (completePasswordResetResponse.errors !== undefined) {
1874
1874
  return {
1875
- code: dist.ROPCPasswordResponseCode.ERROR,
1875
+ code: dist.ResetPasswordResponseCode.ERROR,
1876
1876
  message: completePasswordResetResponse.errors[0].message,
1877
1877
  };
1878
1878
  }
1879
1879
  return {
1880
- code: dist.ROPCPasswordResponseCode.SUCCESS,
1880
+ code: dist.ResetPasswordResponseCode.SUCCESS,
1881
1881
  };
1882
1882
  });
1883
1883
  const getIdpConfigurations = (userAuthConfig) => __awaiter(void 0, void 0, void 0, function* () {
@@ -2267,7 +2267,7 @@ class UserServiceClient {
2267
2267
  this.tokenRenewalMethod = tokenRenewalMethod;
2268
2268
  this._tokenChangedHandlers = [];
2269
2269
  this._tokenResponse = null;
2270
- this._ropcEndpointResponse = null;
2270
+ this._signInWithCredentialsEndpointResponse = null;
2271
2271
  this.emitTokenChanged = (token) => {
2272
2272
  this._tokenChangedHandlers.forEach((handler) => handler(token));
2273
2273
  };
@@ -2298,19 +2298,19 @@ class UserServiceClient {
2298
2298
  });
2299
2299
  /**
2300
2300
  * Call the well-known endpoint of ax-user-service and retrieves endpoints related to AxAuth.
2301
- * @returns ROPCEndpointResponse
2301
+ * @returns SignInWithCredentialsEndpointResponse
2302
2302
  */
2303
- this.getROPCEndpoints = () => __awaiter(this, void 0, void 0, function* () {
2303
+ this.getSignInWithCredentialsEndpoints = () => __awaiter(this, void 0, void 0, function* () {
2304
2304
  try {
2305
- if (this._ropcEndpointResponse === null) {
2305
+ if (this._signInWithCredentialsEndpointResponse === null) {
2306
2306
  const endpoints = yield getWellKnownEndpoints(this.userAuthConfig);
2307
- this._ropcEndpointResponse = {
2307
+ this._signInWithCredentialsEndpointResponse = {
2308
2308
  code: 'SUCCESS',
2309
2309
  managementEndpoint: endpoints.axAuthManagementGQL,
2310
2310
  authEndpoint: endpoints.axAuthEndpoint,
2311
2311
  };
2312
2312
  }
2313
- return this._ropcEndpointResponse;
2313
+ return this._signInWithCredentialsEndpointResponse;
2314
2314
  }
2315
2315
  catch (error) {
2316
2316
  assertError(error);
@@ -2343,7 +2343,7 @@ class UserServiceClient {
2343
2343
  * Based on the outcome of this function, an end-user application can conditionally offer the option to Sign-In directly
2344
2344
  * via email & password.
2345
2345
  *
2346
- * @see {@link ropcSignIn}
2346
+ * @see {@link signInWithCredentials}
2347
2347
  *
2348
2348
  * @returns a boolean indicating if the Mosaic application has an AxAuth IDP provider configured and it is enabled.
2349
2349
  */
@@ -2353,21 +2353,21 @@ class UserServiceClient {
2353
2353
  return this._axAuthIdpConfig !== undefined;
2354
2354
  });
2355
2355
  /**
2356
- * Starts a ROPC Sign-In flow using the AX_AUTH IDP configured for the application.
2356
+ * Starts a SignInWithCredentials flow using the AX_AUTH IDP configured for the application.
2357
2357
  *
2358
- * @param ropcSignInRequest
2359
- * @returns `ROPCSignInResponse`
2358
+ * @param signInRequest
2359
+ * @returns `SignInResponse`
2360
2360
  */
2361
- this.ropcSignIn = (ropcSignInRequest) => __awaiter(this, void 0, void 0, function* () {
2361
+ this.signInWithCredentials = (signInRequest) => __awaiter(this, void 0, void 0, function* () {
2362
2362
  var _b, _c;
2363
2363
  if (((_b = this._axAuthIdpConfig) === null || _b === void 0 ? void 0 : _b.idpConnectionId) !== undefined) {
2364
- const result = yield performROPCSignIn(this.userAuthConfig, (_c = this._axAuthIdpConfig) === null || _c === void 0 ? void 0 : _c.idpConnectionId, ropcSignInRequest);
2364
+ const result = yield performSignInWithCredentials(this.userAuthConfig, (_c = this._axAuthIdpConfig) === null || _c === void 0 ? void 0 : _c.idpConnectionId, signInRequest);
2365
2365
  return result;
2366
2366
  }
2367
2367
  else {
2368
2368
  return {
2369
- code: dist.ROPCSignInResponseCode.SERVICE_CONFIGURATION_ERROR,
2370
- message: 'No IDP has configured for ROPC sign-in.',
2369
+ code: dist.SignInResponseCode.SERVICE_CONFIGURATION_ERROR,
2370
+ message: 'No IDP has configured for sign in with credentials.',
2371
2371
  };
2372
2372
  }
2373
2373
  });
@@ -2385,9 +2385,10 @@ class UserServiceClient {
2385
2385
  }
2386
2386
  if (this._axAuthIdpConfig !== undefined &&
2387
2387
  this._axAuthIdpConfig.clientId !== null &&
2388
- ((_d = this._ropcEndpointResponse) === null || _d === void 0 ? void 0 : _d.managementEndpoint) !== undefined) {
2388
+ ((_d = this._signInWithCredentialsEndpointResponse) === null || _d === void 0 ? void 0 : _d.managementEndpoint) !==
2389
+ undefined) {
2389
2390
  const signUpRequest = Object.assign(Object.assign({}, userSignUpRequest), { oAuthClientId: this._axAuthIdpConfig.clientId });
2390
- const result = yield initiateUserSignUp(signUpRequest, this._ropcEndpointResponse.managementEndpoint);
2391
+ const result = yield initiateUserSignUp(signUpRequest, this._signInWithCredentialsEndpointResponse.managementEndpoint);
2391
2392
  return result;
2392
2393
  }
2393
2394
  else {
@@ -2411,8 +2412,9 @@ class UserServiceClient {
2411
2412
  }
2412
2413
  if (this._axAuthIdpConfig !== undefined &&
2413
2414
  this._axAuthIdpConfig.clientId !== null &&
2414
- ((_e = this._ropcEndpointResponse) === null || _e === void 0 ? void 0 : _e.managementEndpoint) !== undefined) {
2415
- const result = yield checkUserSignUpOtp(checkUserSignUpOtpRequest, this._ropcEndpointResponse.managementEndpoint);
2415
+ ((_e = this._signInWithCredentialsEndpointResponse) === null || _e === void 0 ? void 0 : _e.managementEndpoint) !==
2416
+ undefined) {
2417
+ const result = yield checkUserSignUpOtp(checkUserSignUpOtpRequest, this._signInWithCredentialsEndpointResponse.managementEndpoint);
2416
2418
  return result;
2417
2419
  }
2418
2420
  else {
@@ -2432,8 +2434,9 @@ class UserServiceClient {
2432
2434
  */
2433
2435
  this.completeUserSignUp = (completeUserSignUpRequest) => __awaiter(this, void 0, void 0, function* () {
2434
2436
  var _f;
2435
- if (((_f = this._ropcEndpointResponse) === null || _f === void 0 ? void 0 : _f.managementEndpoint) !== undefined) {
2436
- const result = yield completeUserSignUp(completeUserSignUpRequest, this._ropcEndpointResponse.managementEndpoint);
2437
+ if (((_f = this._signInWithCredentialsEndpointResponse) === null || _f === void 0 ? void 0 : _f.managementEndpoint) !==
2438
+ undefined) {
2439
+ const result = yield completeUserSignUp(completeUserSignUpRequest, this._signInWithCredentialsEndpointResponse.managementEndpoint);
2437
2440
  return result;
2438
2441
  }
2439
2442
  else {
@@ -2459,13 +2462,14 @@ class UserServiceClient {
2459
2462
  }
2460
2463
  if (this._axAuthIdpConfig !== undefined &&
2461
2464
  this._axAuthIdpConfig.clientId !== null &&
2462
- ((_g = this._ropcEndpointResponse) === null || _g === void 0 ? void 0 : _g.managementEndpoint) !== undefined) {
2463
- const result = yield initiatePasswordReset(email, this._axAuthIdpConfig.clientId, this._ropcEndpointResponse.managementEndpoint);
2465
+ ((_g = this._signInWithCredentialsEndpointResponse) === null || _g === void 0 ? void 0 : _g.managementEndpoint) !==
2466
+ undefined) {
2467
+ const result = yield initiatePasswordReset(email, this._axAuthIdpConfig.clientId, this._signInWithCredentialsEndpointResponse.managementEndpoint);
2464
2468
  return result;
2465
2469
  }
2466
2470
  else {
2467
2471
  return {
2468
- code: dist.ROPCPasswordResponseCode.SERVICE_CONFIGURATION_ERROR,
2472
+ code: dist.ResetPasswordResponseCode.SERVICE_CONFIGURATION_ERROR,
2469
2473
  message: 'No IDP has been configured to handle password reset.',
2470
2474
  };
2471
2475
  }
@@ -2484,8 +2488,9 @@ class UserServiceClient {
2484
2488
  }
2485
2489
  if (this._axAuthIdpConfig !== undefined &&
2486
2490
  this._axAuthIdpConfig.clientId !== null &&
2487
- ((_h = this._ropcEndpointResponse) === null || _h === void 0 ? void 0 : _h.managementEndpoint) !== undefined) {
2488
- const result = yield checkPasswordResetOtp(checkPasswordResetOtpRequest, this._ropcEndpointResponse.managementEndpoint);
2491
+ ((_h = this._signInWithCredentialsEndpointResponse) === null || _h === void 0 ? void 0 : _h.managementEndpoint) !==
2492
+ undefined) {
2493
+ const result = yield checkPasswordResetOtp(checkPasswordResetOtpRequest, this._signInWithCredentialsEndpointResponse.managementEndpoint);
2489
2494
  return result;
2490
2495
  }
2491
2496
  else {
@@ -2504,13 +2509,14 @@ class UserServiceClient {
2504
2509
  */
2505
2510
  this.completeResetPassword = (completePasswordResetRequest) => __awaiter(this, void 0, void 0, function* () {
2506
2511
  var _j;
2507
- if (((_j = this._ropcEndpointResponse) === null || _j === void 0 ? void 0 : _j.managementEndpoint) !== undefined) {
2508
- const result = yield completePasswordReset(completePasswordResetRequest, this._ropcEndpointResponse.managementEndpoint);
2512
+ if (((_j = this._signInWithCredentialsEndpointResponse) === null || _j === void 0 ? void 0 : _j.managementEndpoint) !==
2513
+ undefined) {
2514
+ const result = yield completePasswordReset(completePasswordResetRequest, this._signInWithCredentialsEndpointResponse.managementEndpoint);
2509
2515
  return result;
2510
2516
  }
2511
2517
  else {
2512
2518
  return {
2513
- code: dist.ROPCPasswordResponseCode.SERVICE_CONFIGURATION_ERROR,
2519
+ code: dist.ResetPasswordResponseCode.SERVICE_CONFIGURATION_ERROR,
2514
2520
  message: 'No IDP has been configured to handle password reset.',
2515
2521
  };
2516
2522
  }
@@ -2557,7 +2563,7 @@ class UserServiceClient {
2557
2563
  };
2558
2564
  /**
2559
2565
  * Returns an array of IDP Configurations that are configured for the application
2560
- * This list will exclude connections for provider id AX_AUTH as it is used for a user sign-up and ROPC flows.
2566
+ * This list will exclude connections for provider id AX_AUTH as it is used for a user sign-up and SignInWithCredentials flows.
2561
2567
  *
2562
2568
  */
2563
2569
  this.getIdpConfigurations = () => __awaiter(this, void 0, void 0, function* () {
@@ -2696,8 +2702,8 @@ class UserServiceClient {
2696
2702
  const authUrl = getNativeAuthUrl(this.userAuthConfig, idpConnectionId, returnUrl, encryptionKey);
2697
2703
  return authUrl;
2698
2704
  };
2699
- // asynchronously get the ROPC endpoints at client initialization
2700
- this.getROPCEndpoints();
2705
+ // asynchronously get the SignInWithCredentials endpoints at client initialization
2706
+ this.getSignInWithCredentialsEndpoints();
2701
2707
  }
2702
2708
  get tokenResponse() {
2703
2709
  return this._tokenResponse;