mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
some secret shit
This commit is contained in:
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;
|
||||
}
|
||||
@@ -7,3 +7,4 @@ export * from "./protobuf";
|
||||
export * from "./statistics";
|
||||
export * from "./streams";
|
||||
export * from "./types";
|
||||
export * from "./secrets";
|
||||
@@ -0,0 +1,5 @@
|
||||
import { PassableSecretName } from "./secret";
|
||||
|
||||
export function hasSecret(name: PassableSecretName) {
|
||||
return name in import.meta.env;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from "./secret";
|
||||
export * from "./hasSecret";
|
||||
export * from "./wellKnown";
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
Reference in new issue
Block a user