2025-02-15 21:30:12 +00:00
|
|
|
import { Result, ValueObject } from "@common/domain";
|
|
|
|
|
import { z } from "zod";
|
|
|
|
|
|
|
|
|
|
export class Token extends ValueObject<string> {
|
|
|
|
|
static create(token: string): Result<Token, Error> {
|
|
|
|
|
const result = Token.validate(token);
|
|
|
|
|
|
|
|
|
|
if (!result.success) {
|
|
|
|
|
return Result.fail(new Error(result.error.errors[0].message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result.ok(new Token(result.data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static validate(token: string) {
|
2025-02-16 19:30:20 +00:00
|
|
|
const schema = z.string().min(1, { message: "Invalid token string" });
|
2025-02-15 21:30:12 +00:00
|
|
|
return schema.safeParse(token);
|
|
|
|
|
}
|
|
|
|
|
}
|