refactor(libs): share the origin env schema

`origin` (scheme and host only) lives in @lumina/libs/env, so the apps stop repeating it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amiram_se 2026-10-06 21:47:18 +04:00
parent 297f0b2cbd
commit 0e8347d6d3
2 changed files with 24 additions and 0 deletions

View File

@ -1,4 +1,5 @@
export { createClientEnv } from './env.client';
export { origin } from './schemas';
export type {
ClientEnvOptions,
EnvSchema,

23
packages/libs/src/env/schemas.ts vendored Normal file
View File

@ -0,0 +1,23 @@
import * as v from 'valibot';
/** `https://api.lumina.ir`, not `https://api.lumina.ir/` or `https://api.lumina.ir/v1`. */
function isOrigin(value: string): boolean {
try {
return new URL(value).origin === value;
} catch {
return false;
}
}
/**
* A scheme and host only, such as `http://gateway:3000`: paths are joined to it, so a trailing
* slash or a path would give `//v1` or `/v1/v1`.
*/
export const origin = v.pipe(
v.string(),
v.url(),
v.check(
isOrigin,
'Must be an origin such as https://api.example.com, with no path or trailing slash.',
),
);