@stacksjs/config 0.70.23 → 0.70.25

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,101 @@
1
+ import { defaults } from './defaults';
2
+ import { overrides, overridesReady } from './overrides';
3
+ import type { StacksOptions } from '@stacksjs/types';
4
+ /*.ts` file has loaded and the
5
+ * `overrides` instance has been mutated in place. Use this in code paths
6
+ * that *must* see the merged values — typically anything outside the
7
+ * normal request flow (e.g. CLI commands, top-level boot scripts) where
8
+ * the request hasn't yet hit a route handler that already awaited.
9
+ *
10
+ * Inside request handlers / routes you generally do *not* need to await
11
+ * this: the router's `serverResponse()` only fires after `importRoutes()`
12
+ * resolves, and `importRoutes()` indirectly awaits config (it reads
13
+ * `app/Routes.ts`, which imports config). So the proxy returns merged
14
+ * values for all "normal" request-time reads.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { config, awaitConfig } from '@stacksjs/config'
19
+ *
20
+ * // CLI / top-level script — config files may not be loaded yet
21
+ * await awaitConfig()
22
+ * console.log(config.ports.api) // guaranteed to be the user value
23
+ * ```
24
+ */
25
+ export declare function awaitConfig(): Promise<StacksOptions>;
26
+ /**
27
+ * Resolves once `database` config has been read by `@stacksjs/database`'s
28
+ * lazy initializer. Use it from boot scripts that need a live `db` handle
29
+ * before the request loop starts.
30
+ *
31
+ * Why a separate signal: `overridesReady` only signals that `~/config/database.ts`
32
+ * was *imported*, not that `@stacksjs/database` has actually wired up the
33
+ * connection. Calling `db.selectFrom(...)` immediately after `overridesReady`
34
+ * resolves can still race the connection setup. The database driver flips
35
+ * this signal to `true` once it has a working connection.
36
+ */
37
+ export declare function awaitDatabaseConfig(): Promise<StacksOptions>;
38
+ /**
39
+ * Called by `@stacksjs/database` once the connection is live. Internal —
40
+ * users shouldn't need to invoke this directly.
41
+ */
42
+ export declare function markDatabaseReady(): void;
43
+ export declare function getConfig(): StacksOptions;
44
+ export declare function determineAppEnv(): AppEnv;
45
+ export declare const config: StacksOptions;
46
+ // Per-section convenience exports.
47
+ //
48
+ // Caveat: these are *snapshots* taken at module-load time. ESM `export
49
+ // const x = expr` evaluates `expr` once and binds `x` to that result —
50
+ // there's no language-level way to make a named export re-evaluate
51
+ // per access. So `import { ports } from '@stacksjs/config'` returns
52
+ // whatever `config.ports` was when the config module first evaluated,
53
+ // which is *before* `overridesReady` resolves and the user's
54
+ // `config/*.ts` files land.
55
+ //
56
+ // These start as snapshots of the framework defaults (because the user's
57
+ // `config/*.ts` haven't loaded yet — see `overridesReady`). Once the
58
+ // async loader resolves we reassign each `let` binding so consumers of
59
+ // `import { ports } from '@stacksjs/config'` see the merged value.
60
+ //
61
+ // ESM live bindings make this work: when an exporting module reassigns
62
+ // a `let`-bound export, every importer immediately sees the new value
63
+ // (no re-import needed). The earlier `export const x = config.x` form
64
+ // captured the empty-default snapshot forever.
65
+ //
66
+ // Caveat: code that destructures (`const { ports } = config` or reads
67
+ // at the top of a function) before `overridesReady` resolves still
68
+ // gets the early snapshot. For correctness in that path, read off
69
+ // the `config` proxy: `config.ports.api` always pulls live.
70
+ export declare let ai: StacksOptions['ai'];
71
+ export declare let analytics: StacksOptions['analytics'];
72
+ export declare let app: StacksOptions['app'];
73
+ export declare let auth: StacksOptions['auth'];
74
+ export declare let realtime: StacksOptions['realtime'];
75
+ export declare let cache: StacksOptions['cache'];
76
+ export declare let cloud: StacksOptions['cloud'];
77
+ export declare let cli: StacksOptions['cli'];
78
+ export declare let dashboard: StacksOptions['dashboard'];
79
+ export declare let database: StacksOptions['database'];
80
+ export declare let dns: StacksOptions['dns'];
81
+ export declare let docs: StacksOptions['docs'];
82
+ export declare let email: StacksOptions['email'];
83
+ export declare let errors: StacksOptions['errors'];
84
+ export declare let git: StacksOptions['git'];
85
+ export declare let hashing: StacksOptions['hashing'];
86
+ export declare let library: StacksOptions['library'];
87
+ export declare let logging: StacksOptions['logging'];
88
+ export declare let notification: StacksOptions['notification'];
89
+ export declare let payment: StacksOptions['payment'];
90
+ export declare let ports: StacksOptions['ports'];
91
+ export declare let queue: StacksOptions['queue'];
92
+ export declare let security: StacksOptions['security'];
93
+ export declare let saas: StacksOptions['saas'];
94
+ export declare let searchEngine: StacksOptions['searchEngine'];
95
+ export declare let services: StacksOptions['services'];
96
+ export declare let filesystems: StacksOptions['filesystems'];
97
+ export declare let team: StacksOptions['team'];
98
+ export declare let ui: StacksOptions['ui'];
99
+ declare type AppEnv = 'dev' | 'stage' | 'prod' | string;
100
+ export * from './helpers';
101
+ export { defaults, overrides, overridesReady };
@@ -0,0 +1,20 @@
1
+ import type { StacksOptions } from '@stacksjs/types';
2
+ /**
3
+ * Framework-wide default scalars. Defining these as named constants
4
+ * (rather than re-spelling the literal in each config section) keeps
5
+ * "where do I change the default region?" answerable from a single
6
+ * line — the previous shape had `'us-east-1'` typed in 4+ places that
7
+ * could drift when a multi-region future lands.
8
+ */
9
+ export declare const FRAMEWORK_DEFAULTS: {
10
+ /** Default AWS region for SES, S3, DynamoDB, CloudFront origin shield. */
11
+ awsRegion: 'us-east-1';
12
+ /** Default scheduler / job timezone. UTC keeps cron predictable across hosts. */
13
+ timezone: 'UTC';
14
+ /** No-reply address for transactional email (override via config.email.from). */
15
+ noReplyEmail: 'no-reply@stacksjs.com';
16
+ /** Default project domain shape for new scaffolds. */
17
+ fallbackDomain: 'stacks.localhost'
18
+ };
19
+ export declare const defaults: StacksOptions;
20
+ export default defaults;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Truthy when the named feature is enabled in the current environment.
3
+ *
4
+ * Resolution order (first match wins):
5
+ * 1. Runtime override via `enableFeature` / `disableFeature`
6
+ * 2. Object form `{ enabled: true, env: ['production'] }` — env list
7
+ * gates the flag to specific deploy targets (matched against
8
+ * `config.app.env`)
9
+ * 3. Boolean form `true` / `false`
10
+ * 4. Missing → `false`
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * if (feature('experimental-streaming')) {
15
+ * return response.stream(producer)
16
+ * }
17
+ * ```
18
+ */
19
+ export declare function feature(name: string): boolean;
20
+ /**
21
+ * Force-enable a feature in the running process. Intended for tests and
22
+ * staged rollouts; production code should prefer config-file overrides.
23
+ */
24
+ export declare function enableFeature(name: string): void;
25
+ /**
26
+ * Force-disable a feature in the running process.
27
+ */
28
+ export declare function disableFeature(name: string): void;
29
+ /**
30
+ * Drop a runtime override and fall back to the config-driven value.
31
+ */
32
+ export declare function resetFeature(name: string): void;
33
+ /**
34
+ * Snapshot of the live flag set — useful for `/__features` debug
35
+ * endpoints and CLI commands that print the active configuration.
36
+ */
37
+ export declare function listFeatures(): Record<string, boolean>;
38
+ declare type FlagValue = boolean | { enabled?: boolean, env?: string[] }
@@ -0,0 +1,44 @@
1
+ import { config } from '.';
2
+ import type { AppConfig, CacheConfig, CdnConfig, ChatConfig, CliConfig, DatabaseConfig, DependenciesConfig, DnsConfig, EmailConfig, Events, FilesystemsConfig, GitConfig, HashingConfig, LibraryConfig, Model, NotificationConfig, PaymentConfig, QueueConfig, SearchEngineConfig, SecurityConfig, ServicesConfig, StacksConfig, StorageConfig, UiConfig } from '@stacksjs/types';
3
+ export declare function localUrl(options?: {
4
+ domain?: string
5
+ type?: LocalUrlType
6
+ network?: boolean
7
+ localhost?: boolean
8
+ https?: boolean
9
+ }): Promise<string>;
10
+ export declare function defineStacksConfig(config: StacksConfig): StacksConfig;
11
+ export declare function defineApp(config: AppConfig): AppConfig;
12
+ export declare function defineCache(config: CacheConfig): CacheConfig;
13
+ export declare function defineCdn(config: CdnConfig): CdnConfig;
14
+ export declare function defineChat(config: ChatConfig): ChatConfig;
15
+ export declare function defineCli(config: CliConfig): CliConfig;
16
+ export declare function defineDatabase(config: DatabaseConfig): DatabaseConfig;
17
+ export declare function defineDependencies(config: DependenciesConfig): DependenciesConfig;
18
+ export declare function defineDns(config: DnsConfig): DnsConfig;
19
+ export declare function defineEmailConfig(config: EmailConfig): EmailConfig;
20
+ export declare function defineEmail(config: EmailConfig): EmailConfig;
21
+ export declare function defineGit(config: GitConfig): GitConfig;
22
+ export declare function defineHashing(config: HashingConfig): HashingConfig;
23
+ export declare function defineLibrary(config: LibraryConfig): LibraryConfig;
24
+ export declare function defineNotification(config: NotificationConfig): NotificationConfig;
25
+ export declare function definePayment(config: PaymentConfig): PaymentConfig;
26
+ export declare function defineQueue(config: QueueConfig): QueueConfig;
27
+ export declare function defineSearchEngine(config: SearchEngineConfig): SearchEngineConfig;
28
+ export declare function defineSecurity(config: SecurityConfig): SecurityConfig;
29
+ export declare function defineServices(config: ServicesConfig): ServicesConfig;
30
+ export declare function defineSms(config: any): any;
31
+ export declare function defineStorage(config: StorageConfig): StorageConfig;
32
+ export declare function defineFilesystems(config: FilesystemsConfig): FilesystemsConfig;
33
+ export declare function defineUi(config: UiConfig): UiConfig;
34
+ export declare function defineModel(config: Model): Model;
35
+ export declare function defineEvents(config: Events): Events;
36
+ export type LocalUrlType = | 'frontend'
37
+ | 'backend'
38
+ | 'api'
39
+ | 'admin'
40
+ | 'library'
41
+ | 'email'
42
+ | 'docs'
43
+ | 'inspect'
44
+ | 'desktop';
@@ -0,0 +1,14 @@
1
+ // IMPORTANT: do NOT re-add `export * as config from './config'` here.
2
+ // That line creates a module-namespace object named `config` whose
3
+ // properties are non-configurable per the ESM spec (namespaces are sealed).
4
+ // Because `export *` is also exporting the real `config` proxy from
5
+ // `./config`, the namespace object would shadow the proxy under the
6
+ // `config` name — and consumers that did `import { config }` would get
7
+ // the sealed namespace, not the live proxy. The visible symptom: every
8
+ // `config.X` read returns whatever value the proxy's get trap produced
9
+ // the *first* time (typically defaults), and later mutations from
10
+ // `overridesReady` are silently ignored.
11
+ export * from './config';
12
+ export { FRAMEWORK_DEFAULTS } from './defaults';
13
+ export { validateConfig, reportConfigIssues, type ConfigValidationIssue } from './validators';
14
+ export { feature, enableFeature, disableFeature, resetFeature, listFeatures } from './features';
@@ -0,0 +1,19 @@
1
+ import type { StacksConfig } from '@stacksjs/types';
2
+ /**
3
+ * Validate a config snapshot. Returns the list of issues — caller decides
4
+ * whether to throw, log, or just print a summary. Returns an empty array
5
+ * when everything checks out.
6
+ */
7
+ export declare function validateConfig(config: Partial<StacksConfig>): ConfigValidationIssue[];
8
+ /**
9
+ * Convenience: validate and pretty-print to stderr. Returns true when
10
+ * the config is clean. Used by the boot path so users see issues
11
+ * immediately on startup rather than digging into a stack trace later.
12
+ */
13
+ export declare function reportConfigIssues(config: Partial<StacksConfig>): boolean;
14
+ export declare interface ConfigValidationIssue {
15
+ path: string
16
+ message: string
17
+ }
18
+ // eslint-disable-next-line pickier/no-unused-vars
19
+ declare type Check = (value: unknown, path: string) => ConfigValidationIssue[];
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@stacksjs/config",
3
3
  "type": "module",
4
- "version": "0.70.23",
4
+ "version": "0.70.25",
5
5
  "description": "The Stacks config helper methods.",
6
6
  "author": "Chris Breuer",
7
- "contributors": ["Chris Breuer <chris@stacksjs.org>"],
7
+ "contributors": [
8
+ "Chris Breuer <chris@stacksjs.com>"
9
+ ],
8
10
  "license": "MIT",
9
11
  "funding": "https://github.com/sponsors/chrisbbreuer",
10
12
  "homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/config#readme",
@@ -16,24 +18,38 @@
16
18
  "bugs": {
17
19
  "url": "https://github.com/stacksjs/stacks/issues"
18
20
  },
19
- "keywords": ["config", "utilities", "functions", "stacks"],
21
+ "keywords": [
22
+ "config",
23
+ "utilities",
24
+ "functions",
25
+ "stacks"
26
+ ],
20
27
  "exports": {
21
28
  ".": {
29
+ "bun": "./src/index.ts",
30
+ "types": "./dist/index.d.ts",
22
31
  "import": "./dist/index.js"
23
32
  },
24
33
  "./*": {
25
34
  "bun": "./*"
26
35
  }
27
36
  },
28
- "files": ["README.md", "dist"],
37
+ "files": [
38
+ "README.md",
39
+ "dist"
40
+ ],
29
41
  "scripts": {
30
42
  "build": "bun build.ts",
31
43
  "typecheck": "bun tsc --noEmit",
32
44
  "prepublishOnly": "bun run build"
33
45
  },
46
+ "dependencies": {
47
+ "ts-pantry": "^0.8.16"
48
+ },
34
49
  "devDependencies": {
35
- "@stacksjs/alias": "0.70.22",
36
- "@stacksjs/development": "0.70.22",
37
- "@stacksjs/types": "0.70.22"
50
+ "@stacksjs/alias": "0.70.23",
51
+ "better-dx": "^0.2.12",
52
+ "@stacksjs/types": "0.70.23",
53
+ "bunfig": "^0.15.11"
38
54
  }
39
55
  }
package/dist/config.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import type { StacksOptions } from '@stacksjs/types';
2
- import { defaults } from './defaults';
3
- import { overrides } from './overrides';
4
-
5
- export declare const config: StacksOptions;
6
- export declare function getConfig(): StacksOptions;
7
- export declare const ai: StacksOptions['ai'];
8
- export declare const app: StacksOptions['app'];
9
- export declare const cloud: StacksOptions['cloud'];
10
- export declare const database: StacksOptions['database'];
11
- export declare const docs: StacksOptions['docs'];
12
- export declare const errors: StacksOptions['errors'];
13
- export declare const hashing: StacksOptions['hashing'];
14
- export declare const logging: StacksOptions['logging'];
15
- export declare const payment: StacksOptions['payment'];
16
- export declare const queue: StacksOptions['queue'];
17
- export declare const saas: StacksOptions['saas'];
18
- export declare const services: StacksOptions['services'];
19
- export declare const team: StacksOptions['team'];
20
- export declare function determineAppEnv(): AppEnv;
21
-
22
- export { defaults, overrides }
23
-
24
- export * from './helpers'
25
-
26
- type AppEnv = 'dev' | 'stage' | 'prod' | string
@@ -1,5 +0,0 @@
1
- import type { StacksOptions } from '@stacksjs/types';
2
-
3
- export declare const defaults: StacksOptions;
4
-
5
- export default defaults;
package/dist/helpers.d.ts DELETED
@@ -1,116 +0,0 @@
1
- export declare type LocalUrlType =
2
- | 'frontend'
3
- | 'backend'
4
- | 'api'
5
- | 'admin'
6
- | 'library'
7
- | 'email'
8
- | 'docs'
9
- | 'inspect'
10
- | 'desktop'
11
-
12
- export async function localUrl({
13
- domain = config.app.url || 'stacks',
14
- type = 'frontend' as LocalUrlType,
15
- localhost = false,
16
- https = undefined as boolean | undefined,
17
- network = undefined as boolean | undefined,
18
- }: {
19
- domain?: string
20
- type?: LocalUrlType
21
- network?: boolean
22
- localhost?: boolean
23
- https?: boolean
24
- } = {}): Promise<string> {
25
- let url = domain.replace(/\.[^.]+$/, '.localhost')
26
-
27
- switch (type) {
28
- case 'frontend':
29
- if (network)
30
- return await createLocalTunnel(config.ports?.frontend || 3000)
31
- if (localhost)
32
- return `http:
33
- break
34
- case 'backend':
35
- if (network)
36
- return await createLocalTunnel(config.ports?.backend || 3001)
37
- if (localhost)
38
- return `http:
39
- url = `api.${url}`
40
- break
41
- case 'admin':
42
- if (network)
43
- return await createLocalTunnel(config.ports?.admin || 3002)
44
- if (localhost)
45
- return `http:
46
- url = `admin.${url}`
47
- break
48
- case 'library':
49
- if (network)
50
- return await createLocalTunnel(config.ports?.library || 3003)
51
- if (localhost)
52
- return `http:
53
- url = `libs.${url}`
54
- break
55
- case 'email':
56
- if (network)
57
- return await createLocalTunnel(config.ports?.email || 3005)
58
- if (localhost)
59
- return `http:
60
- url = `email.${url}`
61
- break
62
- case 'desktop':
63
- if (network)
64
- return await createLocalTunnel(config.ports?.desktop || 3004)
65
- if (localhost)
66
- return `http:
67
- url = `desktop.${url}`
68
- break
69
- case 'docs':
70
- if (network)
71
- return await createLocalTunnel(config.ports?.docs || 3006)
72
- if (localhost)
73
- return `http:
74
- url = `docs.${url}`
75
- break
76
- case 'inspect':
77
- if (network)
78
- return await createLocalTunnel(config.ports?.inspect || 3007)
79
- if (localhost)
80
- return `http:
81
- url = `inspect.${url}`
82
- break
83
- default:
84
- if (localhost)
85
- return `http:
86
- }
87
-
88
- if (https)
89
- return `https:
90
- return `http:
91
- }
92
- export declare function defineStacksConfig(config: StacksConfig): StacksConfig;
93
- export declare function defineApp(config: AppConfig): AppConfig;
94
- export declare function defineCache(config: CacheConfig): CacheConfig;
95
- export declare function defineCdn(config: CdnConfig): CdnConfig;
96
- export declare function defineChat(config: ChatConfig): ChatConfig;
97
- export declare function defineCli(config: CliConfig): CliConfig;
98
- export declare function defineDatabase(config: DatabaseConfig): DatabaseConfig;
99
- export declare function defineDependencies(config: DependenciesConfig): DependenciesConfig;
100
- export declare function defineDns(config: DnsConfig): DnsConfig;
101
- export declare function defineEmailConfig(config: EmailConfig): EmailConfig;
102
- export declare function defineEmail(config: EmailConfig): EmailConfig;
103
- export declare function defineGit(config: GitConfig): GitConfig;
104
- export declare function defineHashing(config: HashingConfig): HashingConfig;
105
- export declare function defineLibrary(config: LibraryConfig): LibraryConfig;
106
- export declare function defineNotification(config: NotificationConfig): NotificationConfig;
107
- export declare function definePayment(config: PaymentConfig): PaymentConfig;
108
- export declare function defineQueue(config: QueueConfig): QueueConfig;
109
- export declare function defineSearchEngine(config: SearchEngineConfig): SearchEngineConfig;
110
- export declare function defineSecurity(config: SecurityConfig): SecurityConfig;
111
- export declare function defineServices(config: ServicesConfig): ServicesConfig;
112
- export declare function defineSms(config: any): any;
113
- export declare function defineStorage(config: StorageConfig): StorageConfig;
114
- export declare function defineUi(config: UiConfig): UiConfig;
115
- export declare function defineModel(config: Model): Model;
116
- export declare function defineEvents(config: Events): Events;
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * as config from './config'
2
- export * from './config'
@@ -1,5 +0,0 @@
1
- import type { StacksConfig } from '@stacksjs/types';
2
-
3
- export declare const overrides: StacksConfig;
4
-
5
- export default overrides;