@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.20.0
|
|
4
|
+
|
|
5
|
+
`mapRegisterErrorCode` reads the typed `status` + body `errorCode` that `@dloizides/auth-client` 4.5.0
|
|
6
|
+
`BffRequestError` carries (duck-typed, so it needs no auth-client bump to compile). New codes:
|
|
7
|
+
`TenantNameTaken` (409 `TENANT_NAME_TAKEN`), `RateLimited` (429) and `AutoLoginFailed` (account created, sign-in
|
|
8
|
+
failed: tell the user to sign in, not to retry). `USER_EXISTS` maps to `EmailTaken`; 5xx to `Failed`. Consumers
|
|
9
|
+
with an exhaustive `Record<RegisterErrorCode, string>` must add the three new keys.
|
|
10
|
+
|
|
3
11
|
## 1.19.0
|
|
4
12
|
|
|
5
13
|
**`<RegisterForm compact>` (AUTH-REG-1 "Compact register form").** Opt-in; the default seven-field form is unchanged.
|
package/dist/index.d.mts
CHANGED
|
@@ -525,10 +525,19 @@ declare const enum RegisterErrorCode {
|
|
|
525
525
|
PasswordMismatch = "passwordMismatch",
|
|
526
526
|
/** The server reported `USERNAME_TAKEN`. */
|
|
527
527
|
UsernameTaken = "usernameTaken",
|
|
528
|
-
/** The server reported `EMAIL_TAKEN
|
|
528
|
+
/** The server reported `EMAIL_TAKEN` or `USER_EXISTS` (409). */
|
|
529
529
|
EmailTaken = "emailTaken",
|
|
530
530
|
/** The server reported `REALM_REQUIRED` or `REALM_INVALID`. */
|
|
531
531
|
RealmInvalid = "realmInvalid",
|
|
532
|
+
/** The server reported `TENANT_NAME_TAKEN` (409): the organisation / shop name is in use. */
|
|
533
|
+
TenantNameTaken = "tenantNameTaken",
|
|
534
|
+
/** The server rate-limited the request (HTTP 429). */
|
|
535
|
+
RateLimited = "rateLimited",
|
|
536
|
+
/**
|
|
537
|
+
* The account WAS created but the automatic sign-in failed (`AUTO_LOGIN_FAILED`).
|
|
538
|
+
* Tell the user to sign in; do not ask them to register again.
|
|
539
|
+
*/
|
|
540
|
+
AutoLoginFailed = "autoLoginFailed",
|
|
532
541
|
/** The server rejected the request with an unrecognised message. */
|
|
533
542
|
ValidationFailed = "validationFailed",
|
|
534
543
|
/** Generic failure: network error, empty message, or a filled honeypot (never revealed). */
|
package/dist/index.d.ts
CHANGED
|
@@ -525,10 +525,19 @@ declare const enum RegisterErrorCode {
|
|
|
525
525
|
PasswordMismatch = "passwordMismatch",
|
|
526
526
|
/** The server reported `USERNAME_TAKEN`. */
|
|
527
527
|
UsernameTaken = "usernameTaken",
|
|
528
|
-
/** The server reported `EMAIL_TAKEN
|
|
528
|
+
/** The server reported `EMAIL_TAKEN` or `USER_EXISTS` (409). */
|
|
529
529
|
EmailTaken = "emailTaken",
|
|
530
530
|
/** The server reported `REALM_REQUIRED` or `REALM_INVALID`. */
|
|
531
531
|
RealmInvalid = "realmInvalid",
|
|
532
|
+
/** The server reported `TENANT_NAME_TAKEN` (409): the organisation / shop name is in use. */
|
|
533
|
+
TenantNameTaken = "tenantNameTaken",
|
|
534
|
+
/** The server rate-limited the request (HTTP 429). */
|
|
535
|
+
RateLimited = "rateLimited",
|
|
536
|
+
/**
|
|
537
|
+
* The account WAS created but the automatic sign-in failed (`AUTO_LOGIN_FAILED`).
|
|
538
|
+
* Tell the user to sign in; do not ask them to register again.
|
|
539
|
+
*/
|
|
540
|
+
AutoLoginFailed = "autoLoginFailed",
|
|
532
541
|
/** The server rejected the request with an unrecognised message. */
|
|
533
542
|
ValidationFailed = "validationFailed",
|
|
534
543
|
/** Generic failure: network error, empty message, or a filled honeypot (never revealed). */
|
package/dist/index.js
CHANGED
|
@@ -4193,6 +4193,9 @@ var RegisterErrorCode = /* @__PURE__ */ ((RegisterErrorCode2) => {
|
|
|
4193
4193
|
RegisterErrorCode2["UsernameTaken"] = "usernameTaken";
|
|
4194
4194
|
RegisterErrorCode2["EmailTaken"] = "emailTaken";
|
|
4195
4195
|
RegisterErrorCode2["RealmInvalid"] = "realmInvalid";
|
|
4196
|
+
RegisterErrorCode2["TenantNameTaken"] = "tenantNameTaken";
|
|
4197
|
+
RegisterErrorCode2["RateLimited"] = "rateLimited";
|
|
4198
|
+
RegisterErrorCode2["AutoLoginFailed"] = "autoLoginFailed";
|
|
4196
4199
|
RegisterErrorCode2["ValidationFailed"] = "validationFailed";
|
|
4197
4200
|
RegisterErrorCode2["Failed"] = "failed";
|
|
4198
4201
|
RegisterErrorCode2["InFlight"] = "inFlight";
|
|
@@ -4284,6 +4287,41 @@ function validateRegisterValues(values, passwordPolicy) {
|
|
|
4284
4287
|
}
|
|
4285
4288
|
return null;
|
|
4286
4289
|
}
|
|
4290
|
+
var HTTP_TOO_MANY_REQUESTS = 429;
|
|
4291
|
+
var HTTP_SERVER_ERROR_MIN = 500;
|
|
4292
|
+
var BODY_ERROR_CODES = {
|
|
4293
|
+
USER_EXISTS: "emailTaken" /* EmailTaken */,
|
|
4294
|
+
USERNAME_TAKEN: "usernameTaken" /* UsernameTaken */,
|
|
4295
|
+
EMAIL_TAKEN: "emailTaken" /* EmailTaken */,
|
|
4296
|
+
TENANT_NAME_TAKEN: "tenantNameTaken" /* TenantNameTaken */,
|
|
4297
|
+
AUTO_LOGIN_FAILED: "autoLoginFailed" /* AutoLoginFailed */,
|
|
4298
|
+
INVALID_REQUEST: "validationFailed" /* ValidationFailed */,
|
|
4299
|
+
REALM_REQUIRED: "realmInvalid" /* RealmInvalid */,
|
|
4300
|
+
REALM_INVALID: "realmInvalid" /* RealmInvalid */
|
|
4301
|
+
};
|
|
4302
|
+
function typedFailureOf(error) {
|
|
4303
|
+
if (typeof error !== "object" || error === null) {
|
|
4304
|
+
return null;
|
|
4305
|
+
}
|
|
4306
|
+
const { status, errorCode } = error;
|
|
4307
|
+
const hasStatus = typeof status === "number";
|
|
4308
|
+
const hasCode = typeof errorCode === "string";
|
|
4309
|
+
if (!hasStatus && !hasCode) {
|
|
4310
|
+
return null;
|
|
4311
|
+
}
|
|
4312
|
+
return { status: hasStatus ? status : null, errorCode: hasCode ? errorCode : null };
|
|
4313
|
+
}
|
|
4314
|
+
function mapTypedFailure(failure) {
|
|
4315
|
+
const byCode = failure.errorCode === null ? void 0 : BODY_ERROR_CODES[failure.errorCode];
|
|
4316
|
+
if (byCode !== void 0) {
|
|
4317
|
+
return byCode;
|
|
4318
|
+
}
|
|
4319
|
+
if (failure.status === HTTP_TOO_MANY_REQUESTS) {
|
|
4320
|
+
return "rateLimited" /* RateLimited */;
|
|
4321
|
+
}
|
|
4322
|
+
const isServerError = failure.status !== null && failure.status >= HTTP_SERVER_ERROR_MIN;
|
|
4323
|
+
return isServerError ? "failed" /* Failed */ : null;
|
|
4324
|
+
}
|
|
4287
4325
|
function messageOf(error) {
|
|
4288
4326
|
if (error instanceof Error) {
|
|
4289
4327
|
return error.message;
|
|
@@ -4291,6 +4329,11 @@ function messageOf(error) {
|
|
|
4291
4329
|
return typeof error === "string" ? error : "";
|
|
4292
4330
|
}
|
|
4293
4331
|
function mapRegisterErrorCode(error) {
|
|
4332
|
+
const failure = typedFailureOf(error);
|
|
4333
|
+
const typed = failure === null ? null : mapTypedFailure(failure);
|
|
4334
|
+
if (typed !== null) {
|
|
4335
|
+
return typed;
|
|
4336
|
+
}
|
|
4294
4337
|
const message = messageOf(error);
|
|
4295
4338
|
if (message === "") {
|
|
4296
4339
|
return "failed" /* Failed */;
|