feat: implement TASK-WP1-01 registration transaction
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
export type RegistrationErrorReason =
|
||||
| "invite_not_found"
|
||||
| "invite_expired"
|
||||
| "invite_disabled"
|
||||
| "invite_exhausted"
|
||||
| "stage_limit_reached"
|
||||
| "email_already_registered"
|
||||
| "challenge_invalid"
|
||||
| "challenge_expired"
|
||||
| "privacy_consent_required"
|
||||
| "privacy_notice_version_invalid"
|
||||
| "profile_invalid"
|
||||
| "idempotency_conflict";
|
||||
|
||||
export type RegistrationErrorCode =
|
||||
| "REGISTRATION_REJECTED"
|
||||
| "REGISTRATION_REQUEST_INVALID"
|
||||
| "IDEMPOTENCY_KEY_CONFLICT";
|
||||
|
||||
export class RegistrationError extends Error {
|
||||
readonly code: RegistrationErrorCode;
|
||||
readonly httpStatus: 400 | 409;
|
||||
readonly reason: RegistrationErrorReason;
|
||||
|
||||
constructor(code: RegistrationErrorCode, reason: RegistrationErrorReason) {
|
||||
super(code);
|
||||
this.code = code;
|
||||
this.httpStatus = code === "REGISTRATION_REQUEST_INVALID" ? 400 : 409;
|
||||
this.reason = reason;
|
||||
}
|
||||
}
|
||||
|
||||
export function registrationFieldError(reason: RegistrationErrorReason) {
|
||||
const entries: Record<RegistrationErrorReason, { field: string; message_key: string }> = {
|
||||
challenge_expired: { field: "verification_code", message_key: "auth.challenge.expired" },
|
||||
challenge_invalid: { field: "verification_code", message_key: "auth.challenge.invalid" },
|
||||
email_already_registered: { field: "email", message_key: "auth.email.already_registered" },
|
||||
idempotency_conflict: { field: "idempotency_key", message_key: "request.idempotency_conflict" },
|
||||
invite_disabled: { field: "invite_code", message_key: "auth.invite.disabled" },
|
||||
invite_exhausted: { field: "invite_code", message_key: "auth.invite.exhausted" },
|
||||
invite_expired: { field: "invite_code", message_key: "auth.invite.expired" },
|
||||
invite_not_found: { field: "invite_code", message_key: "auth.invite.not_found" },
|
||||
privacy_consent_required: { field: "privacy_consent_accepted", message_key: "auth.privacy.consent_required" },
|
||||
privacy_notice_version_invalid: { field: "privacy_notice_version", message_key: "auth.privacy.notice_version_invalid" },
|
||||
profile_invalid: { field: "profile", message_key: "auth.profile.invalid" },
|
||||
stage_limit_reached: { field: "invite_code", message_key: "auth.registration.stage_limit_reached" },
|
||||
};
|
||||
return entries[reason];
|
||||
}
|
||||
Reference in New Issue
Block a user