alepha
Version:
Easy-to-use modern TypeScript framework for building many kind of applications.
48 lines (47 loc) • 2.82 kB
JavaScript
import { $module, z } from "alepha";
import { $entity, db } from "alepha/orm";
//#region ../../src/api/verifications/schemas/verificationTypeEnumSchema.ts
const verificationTypeEnumSchema = z.enum(["code", "link"]);
//#endregion
//#region ../../src/api/verifications/entities/verifications.ts
const verifications = $entity({
name: "verification",
schema: z.object({
id: db.primaryKey(z.bigint()),
createdAt: db.createdAt(),
updatedAt: db.updatedAt(),
version: db.version(),
type: verificationTypeEnumSchema,
target: z.text({ description: "Can be a phone (E.164 format) or email address" }),
purpose: db.default(z.text({ description: "Logical purpose bucket (e.g. 'default', 'password-reset'). Scopes the cooldown and daily-limit checks so unrelated flows that share the same (type, target) — most notably email verification and password reset — don't collide." }), "default"),
code: z.text({ description: "Hashed verification token (n-digit code or UUID)" }),
verifiedAt: z.datetime().describe("When it was successfully verified").optional(),
attempts: db.default(z.integer().describe("Number of failed attempts (to prevent brute-force)"), 0)
}),
indexes: ["createdAt", { columns: ["target", "code"] }]
});
const verificationEntitySchema = verifications.schema;
const verificationEntityInsertSchema = verifications.insertSchema;
//#endregion
//#region ../../src/api/verifications/schemas/requestVerificationCodeResponseSchema.ts
const requestVerificationCodeResponseSchema = z.object({
token: z.string().describe("The verification token (6-digit code for phone, UUID for email). The caller should send this to the user via their preferred notification method."),
codeExpiration: z.integer().describe("Time in seconds before your verification token expires."),
verificationCooldown: z.integer().describe("Cooldown period in seconds before you can request another verification."),
maxVerificationAttempts: z.integer().describe("Maximum number of verification attempts allowed before the token is locked.")
});
//#endregion
//#region ../../src/api/verifications/schemas/validateVerificationCodeResponseSchema.ts
const validateVerificationCodeResponseSchema = z.object({
ok: z.boolean().describe("Indicates whether the verification was successful."),
alreadyVerified: z.boolean().describe("Indicates whether the target was already verified.").optional()
});
//#endregion
//#region ../../src/api/verifications/index.browser.ts
const AlephaApiVerification = $module({
name: "alepha.api.verifications",
services: []
});
//#endregion
export { AlephaApiVerification, requestVerificationCodeResponseSchema, validateVerificationCodeResponseSchema, verificationEntityInsertSchema, verificationEntitySchema, verificationTypeEnumSchema, verifications };
//# sourceMappingURL=index.browser.js.map