some secret shit

This commit is contained in:
tresabhi committed 2026-06-24 21:30:07 -05:00
1 parent b285e9f1d0
commit 878ada0d10
6 files changed
+57 -4

No files matched your search

@@ -1,4 +0,0 @@
export function assertSecret<Type>(secret?: Type) {
if (secret === undefined) throw new Error("Missing secret");
return secret;
}
+1
View File
@@ -7,3 +7,4 @@ export * from "./protobuf";
export * from "./statistics";
export * from "./streams";
export * from "./types";
export * from "./secrets";
+5
View File
@@ -0,0 +1,5 @@
import { PassableSecretName } from "./secret";
export function hasSecret(name: PassableSecretName) {
return name in import.meta.env;
}
+3
View File
@@ -0,0 +1,3 @@
export * from "./secret";
export * from "./hasSecret";
export * from "./wellKnown";
+38
View File
@@ -0,0 +1,38 @@
import { hasSecret } from "./hasSecret";
import { WellKnownSecret } from "./wellKnown";
export enum SecretType {
String,
Number,
}
export type PassableSecretName = WellKnownSecret | (string & {});
export function secret(
name: PassableSecretName,
type?: SecretType.String,
): string;
export function secret(
name: PassableSecretName,
type: SecretType.Number,
): number;
export function secret(
name: WellKnownSecret | (string & {}),
type = SecretType.String,
) {
if (!hasSecret(name)) {
throw new Error(`Secret "${name}" not defined`);
}
const value = import.meta.env[name];
switch (type) {
case SecretType.String:
return value;
case SecretType.Number:
return Number(value);
}
}
+10
View File
@@ -0,0 +1,10 @@
export type WellKnownSecret =
| "BUILD_CHUNK"
| "TEXTURE_CHUNKS"
| "TEMP"
| "WOTB_SERVER"
| "WOTB_VERSION"
| "PUBLIC_WOTB_CLIENT"
| "WOTB_USMAP"
| "GOOGLE_APPLICATION_CREDENTIALS"
| "PUBLIC_GOOGLE_ANALYTICS_PROPERTY_ID";