@constatic/base 0.0.1-beta.3 → 0.0.1-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ export interface BootstrapOptions extends CustomClientOptions {
8
8
  beforeLoad?(client: Client<boolean>): Promise<void>;
9
9
  modules?: string[];
10
10
  loadLogs?: boolean;
11
+ env?: Record<string, string | undefined>;
11
12
  }
12
13
  export declare function bootstrap(options: BootstrapOptions): Promise<{
13
14
  client: Client<boolean>;
package/dist/bootstrap.js CHANGED
@@ -4,7 +4,7 @@ import { createClient } from "./client.js";
4
4
  import { ConstaticError } from "./error.js";
5
5
  import { loadModules } from "./modules.js";
6
6
  async function bootstrap(options) {
7
- const token = options.token ?? process.env.BOT_TOKEN;
7
+ const token = options.token ?? options.env?.BOT_TOKEN ?? process.env?.BOT_TOKEN;
8
8
  if (!token)
9
9
  throw new ConstaticError("The application token was not provided!");
10
10
  const app = ConstaticApp.getInstance();
package/dist/env.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
2
+ type Schema = StandardSchemaV1;
3
+ type Out<T extends Schema> = StandardSchemaV1.InferOutput<T>;
4
+ export declare function validateEnv<T extends Schema>(schema: T): Promise<Out<T>>;
5
+ export {};
package/dist/env.js ADDED
@@ -0,0 +1,18 @@
1
+ // src/env.ts
2
+ import { format, styleText } from "node:util";
3
+ async function validateEnv(schema) {
4
+ const result = await schema["~standard"].validate(process.env);
5
+ if (result.issues) {
6
+ const a = result.issues.map((issue) => {
7
+ return format(styleText("red", "✖︎ ENV VAR %s ➜ %s"), styleText("bold", issue.path?.join(".") ?? ""), styleText("gray", issue.message));
8
+ });
9
+ console.log(a.join(`
10
+ `));
11
+ process.exit(1);
12
+ }
13
+ console.log(styleText("dim", "☰ Environment variables validated ✓"));
14
+ return result.value;
15
+ }
16
+ export {
17
+ validateEnv
18
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./bootstrap.js";
2
2
  export * from "./creators/index.js";
3
+ export * from "./env.js";
3
4
  export * from "./version.js";
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/index.ts
2
2
  export * from "./bootstrap.js";
3
3
  export * from "./creators/index.js";
4
+ export * from "./env.js";
4
5
  export * from "./version.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constatic/base",
3
- "version": "0.0.1-beta.3",
3
+ "version": "0.0.1-beta.4",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@constatic/config": "*",
21
+ "@standard-schema/spec": "^1.0.0",
21
22
  "typescript": "^5.9.3"
22
23
  },
23
24
  "exports": {