@dloizides/auth-web 1.19.0 → 1.21.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.mjs CHANGED
@@ -660,6 +660,18 @@ function useSubmitOnEnter(submit) {
660
660
  [submit]
661
661
  );
662
662
  }
663
+
664
+ // src/components/usernameFieldProps.ts
665
+ var EMAIL_USERNAME_PROPS = {
666
+ autoComplete: "username",
667
+ inputMode: "email",
668
+ keyboardType: "email-address",
669
+ textContentType: "username"
670
+ };
671
+ var NO_EXTRA_PROPS = {};
672
+ function usernameFieldProps(emailUsername) {
673
+ return emailUsername ? EMAIL_USERNAME_PROPS : NO_EXTRA_PROPS;
674
+ }
663
675
  var BffAuthStatus = /* @__PURE__ */ ((BffAuthStatus2) => {
664
676
  BffAuthStatus2["Loading"] = "loading";
665
677
  BffAuthStatus2["Authenticated"] = "authenticated";
@@ -775,7 +787,8 @@ function LoginForm({
775
787
  initialUsername,
776
788
  initialPassword,
777
789
  prefillNonce,
778
- prefillIntent
790
+ prefillIntent,
791
+ emailUsername = false
779
792
  }) {
780
793
  const theme = useAuthTheme(themeProp);
781
794
  const styles3 = useAuthStyles(theme);
@@ -807,6 +820,7 @@ function LoginForm({
807
820
  /* @__PURE__ */ jsx(
808
821
  TextInput,
809
822
  {
823
+ ...usernameFieldProps(emailUsername),
810
824
  accessibilityHint: labels.usernamePlaceholder,
811
825
  accessibilityLabel: labels.usernameLabel,
812
826
  autoCapitalize: "none",
@@ -4192,6 +4206,9 @@ var RegisterErrorCode = /* @__PURE__ */ ((RegisterErrorCode2) => {
4192
4206
  RegisterErrorCode2["UsernameTaken"] = "usernameTaken";
4193
4207
  RegisterErrorCode2["EmailTaken"] = "emailTaken";
4194
4208
  RegisterErrorCode2["RealmInvalid"] = "realmInvalid";
4209
+ RegisterErrorCode2["TenantNameTaken"] = "tenantNameTaken";
4210
+ RegisterErrorCode2["RateLimited"] = "rateLimited";
4211
+ RegisterErrorCode2["AutoLoginFailed"] = "autoLoginFailed";
4195
4212
  RegisterErrorCode2["ValidationFailed"] = "validationFailed";
4196
4213
  RegisterErrorCode2["Failed"] = "failed";
4197
4214
  RegisterErrorCode2["InFlight"] = "inFlight";
@@ -4283,6 +4300,41 @@ function validateRegisterValues(values, passwordPolicy) {
4283
4300
  }
4284
4301
  return null;
4285
4302
  }
4303
+ var HTTP_TOO_MANY_REQUESTS = 429;
4304
+ var HTTP_SERVER_ERROR_MIN = 500;
4305
+ var BODY_ERROR_CODES = {
4306
+ USER_EXISTS: "emailTaken" /* EmailTaken */,
4307
+ USERNAME_TAKEN: "usernameTaken" /* UsernameTaken */,
4308
+ EMAIL_TAKEN: "emailTaken" /* EmailTaken */,
4309
+ TENANT_NAME_TAKEN: "tenantNameTaken" /* TenantNameTaken */,
4310
+ AUTO_LOGIN_FAILED: "autoLoginFailed" /* AutoLoginFailed */,
4311
+ INVALID_REQUEST: "validationFailed" /* ValidationFailed */,
4312
+ REALM_REQUIRED: "realmInvalid" /* RealmInvalid */,
4313
+ REALM_INVALID: "realmInvalid" /* RealmInvalid */
4314
+ };
4315
+ function typedFailureOf(error) {
4316
+ if (typeof error !== "object" || error === null) {
4317
+ return null;
4318
+ }
4319
+ const { status, errorCode } = error;
4320
+ const hasStatus = typeof status === "number";
4321
+ const hasCode = typeof errorCode === "string";
4322
+ if (!hasStatus && !hasCode) {
4323
+ return null;
4324
+ }
4325
+ return { status: hasStatus ? status : null, errorCode: hasCode ? errorCode : null };
4326
+ }
4327
+ function mapTypedFailure(failure) {
4328
+ const byCode = failure.errorCode === null ? void 0 : BODY_ERROR_CODES[failure.errorCode];
4329
+ if (byCode !== void 0) {
4330
+ return byCode;
4331
+ }
4332
+ if (failure.status === HTTP_TOO_MANY_REQUESTS) {
4333
+ return "rateLimited" /* RateLimited */;
4334
+ }
4335
+ const isServerError = failure.status !== null && failure.status >= HTTP_SERVER_ERROR_MIN;
4336
+ return isServerError ? "failed" /* Failed */ : null;
4337
+ }
4286
4338
  function messageOf(error) {
4287
4339
  if (error instanceof Error) {
4288
4340
  return error.message;
@@ -4290,6 +4342,11 @@ function messageOf(error) {
4290
4342
  return typeof error === "string" ? error : "";
4291
4343
  }
4292
4344
  function mapRegisterErrorCode(error) {
4345
+ const failure = typedFailureOf(error);
4346
+ const typed = failure === null ? null : mapTypedFailure(failure);
4347
+ if (typed !== null) {
4348
+ return typed;
4349
+ }
4293
4350
  const message = messageOf(error);
4294
4351
  if (message === "") {
4295
4352
  return "failed" /* Failed */;