@dloizides/auth-web 1.19.0 → 1.20.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/CHANGELOG.md +8 -0
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4192,6 +4192,9 @@ var RegisterErrorCode = /* @__PURE__ */ ((RegisterErrorCode2) => {
|
|
|
4192
4192
|
RegisterErrorCode2["UsernameTaken"] = "usernameTaken";
|
|
4193
4193
|
RegisterErrorCode2["EmailTaken"] = "emailTaken";
|
|
4194
4194
|
RegisterErrorCode2["RealmInvalid"] = "realmInvalid";
|
|
4195
|
+
RegisterErrorCode2["TenantNameTaken"] = "tenantNameTaken";
|
|
4196
|
+
RegisterErrorCode2["RateLimited"] = "rateLimited";
|
|
4197
|
+
RegisterErrorCode2["AutoLoginFailed"] = "autoLoginFailed";
|
|
4195
4198
|
RegisterErrorCode2["ValidationFailed"] = "validationFailed";
|
|
4196
4199
|
RegisterErrorCode2["Failed"] = "failed";
|
|
4197
4200
|
RegisterErrorCode2["InFlight"] = "inFlight";
|
|
@@ -4283,6 +4286,41 @@ function validateRegisterValues(values, passwordPolicy) {
|
|
|
4283
4286
|
}
|
|
4284
4287
|
return null;
|
|
4285
4288
|
}
|
|
4289
|
+
var HTTP_TOO_MANY_REQUESTS = 429;
|
|
4290
|
+
var HTTP_SERVER_ERROR_MIN = 500;
|
|
4291
|
+
var BODY_ERROR_CODES = {
|
|
4292
|
+
USER_EXISTS: "emailTaken" /* EmailTaken */,
|
|
4293
|
+
USERNAME_TAKEN: "usernameTaken" /* UsernameTaken */,
|
|
4294
|
+
EMAIL_TAKEN: "emailTaken" /* EmailTaken */,
|
|
4295
|
+
TENANT_NAME_TAKEN: "tenantNameTaken" /* TenantNameTaken */,
|
|
4296
|
+
AUTO_LOGIN_FAILED: "autoLoginFailed" /* AutoLoginFailed */,
|
|
4297
|
+
INVALID_REQUEST: "validationFailed" /* ValidationFailed */,
|
|
4298
|
+
REALM_REQUIRED: "realmInvalid" /* RealmInvalid */,
|
|
4299
|
+
REALM_INVALID: "realmInvalid" /* RealmInvalid */
|
|
4300
|
+
};
|
|
4301
|
+
function typedFailureOf(error) {
|
|
4302
|
+
if (typeof error !== "object" || error === null) {
|
|
4303
|
+
return null;
|
|
4304
|
+
}
|
|
4305
|
+
const { status, errorCode } = error;
|
|
4306
|
+
const hasStatus = typeof status === "number";
|
|
4307
|
+
const hasCode = typeof errorCode === "string";
|
|
4308
|
+
if (!hasStatus && !hasCode) {
|
|
4309
|
+
return null;
|
|
4310
|
+
}
|
|
4311
|
+
return { status: hasStatus ? status : null, errorCode: hasCode ? errorCode : null };
|
|
4312
|
+
}
|
|
4313
|
+
function mapTypedFailure(failure) {
|
|
4314
|
+
const byCode = failure.errorCode === null ? void 0 : BODY_ERROR_CODES[failure.errorCode];
|
|
4315
|
+
if (byCode !== void 0) {
|
|
4316
|
+
return byCode;
|
|
4317
|
+
}
|
|
4318
|
+
if (failure.status === HTTP_TOO_MANY_REQUESTS) {
|
|
4319
|
+
return "rateLimited" /* RateLimited */;
|
|
4320
|
+
}
|
|
4321
|
+
const isServerError = failure.status !== null && failure.status >= HTTP_SERVER_ERROR_MIN;
|
|
4322
|
+
return isServerError ? "failed" /* Failed */ : null;
|
|
4323
|
+
}
|
|
4286
4324
|
function messageOf(error) {
|
|
4287
4325
|
if (error instanceof Error) {
|
|
4288
4326
|
return error.message;
|
|
@@ -4290,6 +4328,11 @@ function messageOf(error) {
|
|
|
4290
4328
|
return typeof error === "string" ? error : "";
|
|
4291
4329
|
}
|
|
4292
4330
|
function mapRegisterErrorCode(error) {
|
|
4331
|
+
const failure = typedFailureOf(error);
|
|
4332
|
+
const typed = failure === null ? null : mapTypedFailure(failure);
|
|
4333
|
+
if (typed !== null) {
|
|
4334
|
+
return typed;
|
|
4335
|
+
}
|
|
4293
4336
|
const message = messageOf(error);
|
|
4294
4337
|
if (message === "") {
|
|
4295
4338
|
return "failed" /* Failed */;
|