Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

secretReference.ts

27 lines1.1 KB

1import * as Schema from "effect/Schema";
2​
3import { TrimmedNonEmptyString } from "./baseSchemas.ts";
4​
5// Separate module avoids an import cycle between settings and provider instance contracts.
6// Final once shipped: older builds drop entries whose key fails here, and erase them on their next save.
7// Unlike provider slugs it may start with a digit, so a provider named "1Password" fits.
8export const SecretProviderSlug = TrimmedNonEmptyString.check(
9 Schema.isMaxLength(64),
10 Schema.isPattern(/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/),
11);
12​
13export const SecretProviderId = SecretProviderSlug.pipe(Schema.brand("SecretProviderId"));
14export type SecretProviderId = typeof SecretProviderId.Type;
15​
16// Provider-specific syntax is the secret provider driver's to check.
17export const SecretReferencePath = TrimmedNonEmptyString.check(
18 Schema.isMaxLength(1024),
19 Schema.isPattern(/^[^\r\n]+$/),
20);
21​
22/** Points at a secret held by a configured secret provider; the secret itself is never stored. */
23export const SecretReference = Schema.Struct({
24 provider: SecretProviderId,
25 reference: SecretReferencePath,
26});
27export type SecretReference = typeof SecretReference.Type;