@h3ravel/core 0.1.0 → 0.1.1

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.
@@ -0,0 +1,90 @@
1
+ import {
2
+ ServiceProvider,
3
+ __name,
4
+ safeDot,
5
+ setNested
6
+ } from "./chunk-22XJG4AW.js";
7
+
8
+ // ../config/src/ConfigRepository.ts
9
+ import path from "path";
10
+ import { readdir } from "fs/promises";
11
+ var ConfigRepository = class {
12
+ static {
13
+ __name(this, "ConfigRepository");
14
+ }
15
+ app;
16
+ loaded = false;
17
+ configs = {};
18
+ constructor(app) {
19
+ this.app = app;
20
+ }
21
+ get(key, def) {
22
+ return safeDot(this.configs, key) ?? def;
23
+ }
24
+ /**
25
+ * Modify the defined configurations
26
+ */
27
+ set(key, value) {
28
+ setNested(this.configs, key, value);
29
+ }
30
+ async load() {
31
+ if (!this.loaded) {
32
+ const configPath = this.app.getPath("config");
33
+ const files = await readdir(configPath);
34
+ for (let i = 0; i < files.length; i++) {
35
+ const configModule = await import(path.join(configPath, files[i]));
36
+ const name = files[i].replaceAll(/.ts|js/g, "");
37
+ if (typeof configModule.default === "function") {
38
+ this.configs[name] = configModule.default(this.app);
39
+ }
40
+ }
41
+ this.loaded = true;
42
+ }
43
+ return this;
44
+ }
45
+ };
46
+
47
+ // ../config/src/EnvLoader.ts
48
+ var EnvLoader = class {
49
+ static {
50
+ __name(this, "EnvLoader");
51
+ }
52
+ _app;
53
+ constructor(_app) {
54
+ this._app = _app;
55
+ }
56
+ get(key, def) {
57
+ return safeDot(process.env, key) ?? def;
58
+ }
59
+ };
60
+
61
+ // ../config/src/Providers/ConfigServiceProvider.ts
62
+ import { config as loadEnv } from "dotenv";
63
+ var ConfigServiceProvider = class extends ServiceProvider {
64
+ static {
65
+ __name(this, "ConfigServiceProvider");
66
+ }
67
+ async register() {
68
+ loadEnv();
69
+ this.app.singleton("env", () => {
70
+ return new EnvLoader(this.app).get;
71
+ });
72
+ const repo = new ConfigRepository(this.app);
73
+ await repo.load();
74
+ this.app.singleton("config", () => {
75
+ return {
76
+ get: /* @__PURE__ */ __name((key, def) => repo.get(key, def), "get"),
77
+ set: repo.set
78
+ };
79
+ });
80
+ this.app.make("http.app").use((e) => {
81
+ repo.set("app.url", e.url.origin);
82
+ });
83
+ }
84
+ };
85
+ export {
86
+ ConfigRepository,
87
+ ConfigServiceProvider,
88
+ EnvLoader
89
+ };
90
+ //# sourceMappingURL=src-UIEMS3XE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../config/src/ConfigRepository.ts","../../config/src/EnvLoader.ts","../../config/src/Providers/ConfigServiceProvider.ts"],"sourcesContent":["import { DotNestedKeys, DotNestedValue, safeDot, setNested } from '@h3ravel/support'\n\nimport { Application } from \"@h3ravel/core\";\nimport path from 'node:path'\nimport { readdir } from 'node:fs/promises'\n\nexport class ConfigRepository {\n private loaded: boolean = false\n private configs: Record<string, Record<string, any>> = {}\n\n constructor(private app: Application) { }\n\n // get<X extends Record<string, any>> (): X\n // get<X extends Record<string, any>, T extends Extract<keyof X, string>> (key: T): X[T]\n\n /**\n * Get the defined configurations\n */\n get<X extends Record<string, any>> (): X\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(this.configs, key) ?? def\n }\n\n /**\n * Modify the defined configurations\n */\n set<T extends string> (key: T, value: any): void {\n setNested(this.configs, key, value)\n }\n\n async load () {\n if (!this.loaded) {\n const configPath = this.app.getPath('config')\n\n const files = await readdir(configPath);\n\n for (let i = 0; i < files.length; i++) {\n const configModule = await import(path.join(configPath, files[i]))\n const name = files[i].replaceAll(/.ts|js/g, '')\n if (typeof configModule.default === 'function') {\n this.configs[name] = configModule.default(this.app)\n }\n }\n\n this.loaded = true\n }\n\n return this\n }\n}\n","import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\n\nimport { Application } from \"@h3ravel/core\";\n\nexport class EnvLoader {\n constructor(private _app: Application) { }\n\n /**\n * Get the defined environment vars\n */\n get<X extends NodeJS.ProcessEnv> (): X\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(process.env, key) ?? def\n }\n}\n","import { Bindings, ServiceProvider } from '@h3ravel/core'\nimport { ConfigRepository, EnvLoader } from '..'\n\nimport { config as loadEnv } from 'dotenv'\n\n/**\n * Loads configuration and environment files.\n * \n * Load .env and merge with config files.\n * Bind ConfigRepository to the container.\n * \n * Auto-Registered\n */\nexport class ConfigServiceProvider extends ServiceProvider {\n async register () {\n\n loadEnv()\n\n /**\n * Create singleton to load env\n */\n this.app.singleton('env', () => {\n return new EnvLoader(this.app).get\n })\n\n /**\n * Initialize the configuration through the repository\n */\n const repo = new ConfigRepository(this.app)\n await repo.load()\n\n /**\n * Create singleton to load configurations\n */\n this.app.singleton('config', () => {\n return {\n get: (key, def) => repo.get(key as any, def),\n set: repo.set\n } as Bindings['config']\n })\n\n this.app.make('http.app').use(e => {\n repo.set('app.url', e.url.origin)\n })\n }\n}\n"],"mappings":";;;;;;;;AAGA,OAAOA,UAAU;AACjB,SAASC,eAAe;AAEjB,IAAMC,mBAAN,MAAMA;EANb,OAMaA;;;;EACDC,SAAkB;EAClBC,UAA+C,CAAC;EAExD,YAAoBC,KAAkB;SAAlBA,MAAAA;EAAoB;EAUxCC,IAAgEC,KAASC,KAAgB;AACrF,WAAOC,QAAQ,KAAKL,SAASG,GAAAA,KAAQC;EACzC;;;;EAKAE,IAAuBH,KAAQI,OAAkB;AAC7CC,cAAU,KAAKR,SAASG,KAAKI,KAAAA;EACjC;EAEA,MAAME,OAAQ;AACV,QAAI,CAAC,KAAKV,QAAQ;AACd,YAAMW,aAAa,KAAKT,IAAIU,QAAQ,QAAA;AAEpC,YAAMC,QAAQ,MAAMC,QAAQH,UAAAA;AAE5B,eAASI,IAAI,GAAGA,IAAIF,MAAMG,QAAQD,KAAK;AACnC,cAAME,eAAe,MAAM,OAAOC,KAAKC,KAAKR,YAAYE,MAAME,CAAAA,CAAE;AAChE,cAAMK,OAAOP,MAAME,CAAAA,EAAGM,WAAW,WAAW,EAAA;AAC5C,YAAI,OAAOJ,aAAaK,YAAY,YAAY;AAC5C,eAAKrB,QAAQmB,IAAAA,IAAQH,aAAaK,QAAQ,KAAKpB,GAAG;QACtD;MACJ;AAEA,WAAKF,SAAS;IAClB;AAEA,WAAO;EACX;AACJ;;;AC9CO,IAAMuB,YAAN,MAAMA;EAJb,OAIaA;;;;EACT,YAAoBC,MAAmB;SAAnBA,OAAAA;EAAqB;EAOzCC,IAA8DC,KAASC,KAAgB;AACnF,WAAOC,QAAQC,QAAQC,KAAKJ,GAAAA,KAAQC;EACxC;AACJ;;;ACZA,SAASI,UAAUC,eAAe;AAU3B,IAAMC,wBAAN,cAAoCC,gBAAAA;EAb3C,OAa2CA;;;EACvC,MAAMC,WAAY;AAEdC,YAAAA;AAKA,SAAKC,IAAIC,UAAU,OAAO,MAAA;AACtB,aAAO,IAAIC,UAAU,KAAKF,GAAG,EAAEG;IACnC,CAAA;AAKA,UAAMC,OAAO,IAAIC,iBAAiB,KAAKL,GAAG;AAC1C,UAAMI,KAAKE,KAAI;AAKf,SAAKN,IAAIC,UAAU,UAAU,MAAA;AACzB,aAAO;QACHE,KAAK,wBAACI,KAAKC,QAAQJ,KAAKD,IAAII,KAAYC,GAAAA,GAAnC;QACLC,KAAKL,KAAKK;MACd;IACJ,CAAA;AAEA,SAAKT,IAAIU,KAAK,UAAA,EAAYC,IAAIC,CAAAA,MAAAA;AAC1BR,WAAKK,IAAI,WAAWG,EAAEC,IAAIC,MAAM;IACpC,CAAA;EACJ;AACJ;","names":["path","readdir","ConfigRepository","loaded","configs","app","get","key","def","safeDot","set","value","setNested","load","configPath","getPath","files","readdir","i","length","configModule","path","join","name","replaceAll","default","EnvLoader","_app","get","key","def","safeDot","process","env","config","loadEnv","ConfigServiceProvider","ServiceProvider","register","loadEnv","app","singleton","EnvLoader","get","repo","ConfigRepository","load","key","def","set","make","use","e","url","origin"]}
@@ -5,7 +5,7 @@ import {
5
5
  __name,
6
6
  afterLast,
7
7
  before
8
- } from "./chunk-UZGBH6AC.js";
8
+ } from "./chunk-22XJG4AW.js";
9
9
 
10
10
  // ../router/src/Router.ts
11
11
  var Router = class {
@@ -220,4 +220,4 @@ export {
220
220
  RouteServiceProvider,
221
221
  Router
222
222
  };
223
- //# sourceMappingURL=src-E5IZSMT7.js.map
223
+ //# sourceMappingURL=src-ZLODNLLQ.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Core application container, lifecycle management and service providers for H3ravel.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,528 +0,0 @@
1
- import {
2
- ServiceProvider,
3
- __commonJS,
4
- __name,
5
- __require,
6
- __toESM,
7
- safeDot,
8
- setNested
9
- } from "./chunk-UZGBH6AC.js";
10
-
11
- // ../../node_modules/.pnpm/dotenv@17.2.1/node_modules/dotenv/package.json
12
- var require_package = __commonJS({
13
- "../../node_modules/.pnpm/dotenv@17.2.1/node_modules/dotenv/package.json"(exports, module) {
14
- module.exports = {
15
- name: "dotenv",
16
- version: "17.2.1",
17
- description: "Loads environment variables from .env file",
18
- main: "lib/main.js",
19
- types: "lib/main.d.ts",
20
- exports: {
21
- ".": {
22
- types: "./lib/main.d.ts",
23
- require: "./lib/main.js",
24
- default: "./lib/main.js"
25
- },
26
- "./config": "./config.js",
27
- "./config.js": "./config.js",
28
- "./lib/env-options": "./lib/env-options.js",
29
- "./lib/env-options.js": "./lib/env-options.js",
30
- "./lib/cli-options": "./lib/cli-options.js",
31
- "./lib/cli-options.js": "./lib/cli-options.js",
32
- "./package.json": "./package.json"
33
- },
34
- scripts: {
35
- "dts-check": "tsc --project tests/types/tsconfig.json",
36
- lint: "standard",
37
- pretest: "npm run lint && npm run dts-check",
38
- test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
39
- "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
40
- prerelease: "npm test",
41
- release: "standard-version"
42
- },
43
- repository: {
44
- type: "git",
45
- url: "git://github.com/motdotla/dotenv.git"
46
- },
47
- homepage: "https://github.com/motdotla/dotenv#readme",
48
- funding: "https://dotenvx.com",
49
- keywords: [
50
- "dotenv",
51
- "env",
52
- ".env",
53
- "environment",
54
- "variables",
55
- "config",
56
- "settings"
57
- ],
58
- readmeFilename: "README.md",
59
- license: "BSD-2-Clause",
60
- devDependencies: {
61
- "@types/node": "^18.11.3",
62
- decache: "^4.6.2",
63
- sinon: "^14.0.1",
64
- standard: "^17.0.0",
65
- "standard-version": "^9.5.0",
66
- tap: "^19.2.0",
67
- typescript: "^4.8.4"
68
- },
69
- engines: {
70
- node: ">=12"
71
- },
72
- browser: {
73
- fs: false
74
- }
75
- };
76
- }
77
- });
78
-
79
- // ../../node_modules/.pnpm/dotenv@17.2.1/node_modules/dotenv/lib/main.js
80
- var require_main = __commonJS({
81
- "../../node_modules/.pnpm/dotenv@17.2.1/node_modules/dotenv/lib/main.js"(exports, module) {
82
- "use strict";
83
- var fs = __require("fs");
84
- var path2 = __require("path");
85
- var os = __require("os");
86
- var crypto = __require("crypto");
87
- var packageJson = require_package();
88
- var version = packageJson.version;
89
- var TIPS = [
90
- "\u{1F510} encrypt with Dotenvx: https://dotenvx.com",
91
- "\u{1F510} prevent committing .env to code: https://dotenvx.com/precommit",
92
- "\u{1F510} prevent building .env in docker: https://dotenvx.com/prebuild",
93
- "\u{1F4E1} observe env with Radar: https://dotenvx.com/radar",
94
- "\u{1F4E1} auto-backup env with Radar: https://dotenvx.com/radar",
95
- "\u{1F4E1} version env with Radar: https://dotenvx.com/radar",
96
- "\u{1F6E0}\uFE0F run anywhere with `dotenvx run -- yourcommand`",
97
- "\u2699\uFE0F specify custom .env file path with { path: '/custom/path/.env' }",
98
- "\u2699\uFE0F enable debug logging with { debug: true }",
99
- "\u2699\uFE0F override existing env vars with { override: true }",
100
- "\u2699\uFE0F suppress all logs with { quiet: true }",
101
- "\u2699\uFE0F write to custom object with { processEnv: myObject }",
102
- "\u2699\uFE0F load multiple .env files with { path: ['.env.local', '.env'] }"
103
- ];
104
- function _getRandomTip() {
105
- return TIPS[Math.floor(Math.random() * TIPS.length)];
106
- }
107
- __name(_getRandomTip, "_getRandomTip");
108
- function parseBoolean(value) {
109
- if (typeof value === "string") {
110
- return ![
111
- "false",
112
- "0",
113
- "no",
114
- "off",
115
- ""
116
- ].includes(value.toLowerCase());
117
- }
118
- return Boolean(value);
119
- }
120
- __name(parseBoolean, "parseBoolean");
121
- function supportsAnsi() {
122
- return process.stdout.isTTY;
123
- }
124
- __name(supportsAnsi, "supportsAnsi");
125
- function dim(text) {
126
- return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
127
- }
128
- __name(dim, "dim");
129
- var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
130
- function parse(src) {
131
- const obj = {};
132
- let lines = src.toString();
133
- lines = lines.replace(/\r\n?/mg, "\n");
134
- let match;
135
- while ((match = LINE.exec(lines)) != null) {
136
- const key = match[1];
137
- let value = match[2] || "";
138
- value = value.trim();
139
- const maybeQuote = value[0];
140
- value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
141
- if (maybeQuote === '"') {
142
- value = value.replace(/\\n/g, "\n");
143
- value = value.replace(/\\r/g, "\r");
144
- }
145
- obj[key] = value;
146
- }
147
- return obj;
148
- }
149
- __name(parse, "parse");
150
- function _parseVault(options) {
151
- options = options || {};
152
- const vaultPath = _vaultPath(options);
153
- options.path = vaultPath;
154
- const result = DotenvModule.configDotenv(options);
155
- if (!result.parsed) {
156
- const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
157
- err.code = "MISSING_DATA";
158
- throw err;
159
- }
160
- const keys = _dotenvKey(options).split(",");
161
- const length = keys.length;
162
- let decrypted;
163
- for (let i = 0; i < length; i++) {
164
- try {
165
- const key = keys[i].trim();
166
- const attrs = _instructions(result, key);
167
- decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
168
- break;
169
- } catch (error) {
170
- if (i + 1 >= length) {
171
- throw error;
172
- }
173
- }
174
- }
175
- return DotenvModule.parse(decrypted);
176
- }
177
- __name(_parseVault, "_parseVault");
178
- function _warn(message) {
179
- console.error(`[dotenv@${version}][WARN] ${message}`);
180
- }
181
- __name(_warn, "_warn");
182
- function _debug(message) {
183
- console.log(`[dotenv@${version}][DEBUG] ${message}`);
184
- }
185
- __name(_debug, "_debug");
186
- function _log(message) {
187
- console.log(`[dotenv@${version}] ${message}`);
188
- }
189
- __name(_log, "_log");
190
- function _dotenvKey(options) {
191
- if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
192
- return options.DOTENV_KEY;
193
- }
194
- if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
195
- return process.env.DOTENV_KEY;
196
- }
197
- return "";
198
- }
199
- __name(_dotenvKey, "_dotenvKey");
200
- function _instructions(result, dotenvKey) {
201
- let uri;
202
- try {
203
- uri = new URL(dotenvKey);
204
- } catch (error) {
205
- if (error.code === "ERR_INVALID_URL") {
206
- const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
207
- err.code = "INVALID_DOTENV_KEY";
208
- throw err;
209
- }
210
- throw error;
211
- }
212
- const key = uri.password;
213
- if (!key) {
214
- const err = new Error("INVALID_DOTENV_KEY: Missing key part");
215
- err.code = "INVALID_DOTENV_KEY";
216
- throw err;
217
- }
218
- const environment = uri.searchParams.get("environment");
219
- if (!environment) {
220
- const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
221
- err.code = "INVALID_DOTENV_KEY";
222
- throw err;
223
- }
224
- const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
225
- const ciphertext = result.parsed[environmentKey];
226
- if (!ciphertext) {
227
- const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
228
- err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
229
- throw err;
230
- }
231
- return {
232
- ciphertext,
233
- key
234
- };
235
- }
236
- __name(_instructions, "_instructions");
237
- function _vaultPath(options) {
238
- let possibleVaultPath = null;
239
- if (options && options.path && options.path.length > 0) {
240
- if (Array.isArray(options.path)) {
241
- for (const filepath of options.path) {
242
- if (fs.existsSync(filepath)) {
243
- possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
244
- }
245
- }
246
- } else {
247
- possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
248
- }
249
- } else {
250
- possibleVaultPath = path2.resolve(process.cwd(), ".env.vault");
251
- }
252
- if (fs.existsSync(possibleVaultPath)) {
253
- return possibleVaultPath;
254
- }
255
- return null;
256
- }
257
- __name(_vaultPath, "_vaultPath");
258
- function _resolveHome(envPath) {
259
- return envPath[0] === "~" ? path2.join(os.homedir(), envPath.slice(1)) : envPath;
260
- }
261
- __name(_resolveHome, "_resolveHome");
262
- function _configVault(options) {
263
- const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
264
- const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
265
- if (debug || !quiet) {
266
- _log("Loading env from encrypted .env.vault");
267
- }
268
- const parsed = DotenvModule._parseVault(options);
269
- let processEnv = process.env;
270
- if (options && options.processEnv != null) {
271
- processEnv = options.processEnv;
272
- }
273
- DotenvModule.populate(processEnv, parsed, options);
274
- return {
275
- parsed
276
- };
277
- }
278
- __name(_configVault, "_configVault");
279
- function configDotenv(options) {
280
- const dotenvPath = path2.resolve(process.cwd(), ".env");
281
- let encoding = "utf8";
282
- let processEnv = process.env;
283
- if (options && options.processEnv != null) {
284
- processEnv = options.processEnv;
285
- }
286
- let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
287
- let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
288
- if (options && options.encoding) {
289
- encoding = options.encoding;
290
- } else {
291
- if (debug) {
292
- _debug("No encoding is specified. UTF-8 is used by default");
293
- }
294
- }
295
- let optionPaths = [
296
- dotenvPath
297
- ];
298
- if (options && options.path) {
299
- if (!Array.isArray(options.path)) {
300
- optionPaths = [
301
- _resolveHome(options.path)
302
- ];
303
- } else {
304
- optionPaths = [];
305
- for (const filepath of options.path) {
306
- optionPaths.push(_resolveHome(filepath));
307
- }
308
- }
309
- }
310
- let lastError;
311
- const parsedAll = {};
312
- for (const path3 of optionPaths) {
313
- try {
314
- const parsed = DotenvModule.parse(fs.readFileSync(path3, {
315
- encoding
316
- }));
317
- DotenvModule.populate(parsedAll, parsed, options);
318
- } catch (e) {
319
- if (debug) {
320
- _debug(`Failed to load ${path3} ${e.message}`);
321
- }
322
- lastError = e;
323
- }
324
- }
325
- const populated = DotenvModule.populate(processEnv, parsedAll, options);
326
- debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
327
- quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
328
- if (debug || !quiet) {
329
- const keysCount = Object.keys(populated).length;
330
- const shortPaths = [];
331
- for (const filePath of optionPaths) {
332
- try {
333
- const relative = path2.relative(process.cwd(), filePath);
334
- shortPaths.push(relative);
335
- } catch (e) {
336
- if (debug) {
337
- _debug(`Failed to load ${filePath} ${e.message}`);
338
- }
339
- lastError = e;
340
- }
341
- }
342
- _log(`injecting env (${keysCount}) from ${shortPaths.join(",")} ${dim(`-- tip: ${_getRandomTip()}`)}`);
343
- }
344
- if (lastError) {
345
- return {
346
- parsed: parsedAll,
347
- error: lastError
348
- };
349
- } else {
350
- return {
351
- parsed: parsedAll
352
- };
353
- }
354
- }
355
- __name(configDotenv, "configDotenv");
356
- function config(options) {
357
- if (_dotenvKey(options).length === 0) {
358
- return DotenvModule.configDotenv(options);
359
- }
360
- const vaultPath = _vaultPath(options);
361
- if (!vaultPath) {
362
- _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
363
- return DotenvModule.configDotenv(options);
364
- }
365
- return DotenvModule._configVault(options);
366
- }
367
- __name(config, "config");
368
- function decrypt(encrypted, keyStr) {
369
- const key = Buffer.from(keyStr.slice(-64), "hex");
370
- let ciphertext = Buffer.from(encrypted, "base64");
371
- const nonce = ciphertext.subarray(0, 12);
372
- const authTag = ciphertext.subarray(-16);
373
- ciphertext = ciphertext.subarray(12, -16);
374
- try {
375
- const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
376
- aesgcm.setAuthTag(authTag);
377
- return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
378
- } catch (error) {
379
- const isRange = error instanceof RangeError;
380
- const invalidKeyLength = error.message === "Invalid key length";
381
- const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
382
- if (isRange || invalidKeyLength) {
383
- const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
384
- err.code = "INVALID_DOTENV_KEY";
385
- throw err;
386
- } else if (decryptionFailed) {
387
- const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
388
- err.code = "DECRYPTION_FAILED";
389
- throw err;
390
- } else {
391
- throw error;
392
- }
393
- }
394
- }
395
- __name(decrypt, "decrypt");
396
- function populate(processEnv, parsed, options = {}) {
397
- const debug = Boolean(options && options.debug);
398
- const override = Boolean(options && options.override);
399
- const populated = {};
400
- if (typeof parsed !== "object") {
401
- const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
402
- err.code = "OBJECT_REQUIRED";
403
- throw err;
404
- }
405
- for (const key of Object.keys(parsed)) {
406
- if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
407
- if (override === true) {
408
- processEnv[key] = parsed[key];
409
- populated[key] = parsed[key];
410
- }
411
- if (debug) {
412
- if (override === true) {
413
- _debug(`"${key}" is already defined and WAS overwritten`);
414
- } else {
415
- _debug(`"${key}" is already defined and was NOT overwritten`);
416
- }
417
- }
418
- } else {
419
- processEnv[key] = parsed[key];
420
- populated[key] = parsed[key];
421
- }
422
- }
423
- return populated;
424
- }
425
- __name(populate, "populate");
426
- var DotenvModule = {
427
- configDotenv,
428
- _configVault,
429
- _parseVault,
430
- config,
431
- decrypt,
432
- parse,
433
- populate
434
- };
435
- module.exports.configDotenv = DotenvModule.configDotenv;
436
- module.exports._configVault = DotenvModule._configVault;
437
- module.exports._parseVault = DotenvModule._parseVault;
438
- module.exports.config = DotenvModule.config;
439
- module.exports.decrypt = DotenvModule.decrypt;
440
- module.exports.parse = DotenvModule.parse;
441
- module.exports.populate = DotenvModule.populate;
442
- module.exports = DotenvModule;
443
- }
444
- });
445
-
446
- // ../config/src/ConfigRepository.ts
447
- import path from "path";
448
- import { readdir } from "fs/promises";
449
- var ConfigRepository = class {
450
- static {
451
- __name(this, "ConfigRepository");
452
- }
453
- app;
454
- loaded = false;
455
- configs = {};
456
- constructor(app) {
457
- this.app = app;
458
- }
459
- get(key, def) {
460
- return safeDot(this.configs, key) ?? def;
461
- }
462
- /**
463
- * Modify the defined configurations
464
- */
465
- set(key, value) {
466
- setNested(this.configs, key, value);
467
- }
468
- async load() {
469
- if (!this.loaded) {
470
- const configPath = this.app.getPath("config");
471
- const files = await readdir(configPath);
472
- for (let i = 0; i < files.length; i++) {
473
- const configModule = await import(path.join(configPath, files[i]));
474
- const name = files[i].replaceAll(/.ts|js/g, "");
475
- if (typeof configModule.default === "function") {
476
- this.configs[name] = configModule.default(this.app);
477
- }
478
- }
479
- this.loaded = true;
480
- }
481
- return this;
482
- }
483
- };
484
-
485
- // ../config/src/EnvLoader.ts
486
- var EnvLoader = class {
487
- static {
488
- __name(this, "EnvLoader");
489
- }
490
- _app;
491
- constructor(_app) {
492
- this._app = _app;
493
- }
494
- get(key, def) {
495
- return safeDot(process.env, key) ?? def;
496
- }
497
- };
498
-
499
- // ../config/src/Providers/ConfigServiceProvider.ts
500
- var import_dotenv = __toESM(require_main(), 1);
501
- var ConfigServiceProvider = class extends ServiceProvider {
502
- static {
503
- __name(this, "ConfigServiceProvider");
504
- }
505
- async register() {
506
- (0, import_dotenv.config)();
507
- this.app.singleton("env", () => {
508
- return new EnvLoader(this.app).get;
509
- });
510
- const repo = new ConfigRepository(this.app);
511
- await repo.load();
512
- this.app.singleton("config", () => {
513
- return {
514
- get: /* @__PURE__ */ __name((key, def) => repo.get(key, def), "get"),
515
- set: repo.set
516
- };
517
- });
518
- this.app.make("http.app").use((e) => {
519
- repo.set("app.url", e.url.origin);
520
- });
521
- }
522
- };
523
- export {
524
- ConfigRepository,
525
- ConfigServiceProvider,
526
- EnvLoader
527
- };
528
- //# sourceMappingURL=src-KWAEFHNO.js.map