@stacksjs/env 0.75.15 → 0.75.16
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.
- package/README.md +34 -0
- package/dist/integrations.d.ts +22 -0
- package/dist/integrations.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -293,6 +293,40 @@ console.log(provider) // 'github' | 'gitlab' | 'vercel' | etc.
|
|
|
293
293
|
console.log(providerInfo) // { name: 'GitHub Actions', detected: true }
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
+
## Remote Integration Environments
|
|
297
|
+
|
|
298
|
+
Use `initializeIntegration()` before creating a remote telemetry client. The
|
|
299
|
+
initializer is not called when the current `APP_ENV` is excluded, so no client,
|
|
300
|
+
capture hook, upload timer, or network transport is created. Included adapters
|
|
301
|
+
receive the normalized environment for event metadata.
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
import { initializeIntegration } from '@stacksjs/env'
|
|
305
|
+
import { loghqTransport } from '@loghq/stacks'
|
|
306
|
+
|
|
307
|
+
const loghq = {
|
|
308
|
+
key: process.env.LOGHQ_KEY,
|
|
309
|
+
environments: ['production', 'staging'],
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const result = initializeIntegration(loghq, ({ environment }) =>
|
|
313
|
+
loghqTransport({ key: loghq.key, environment }))
|
|
314
|
+
|
|
315
|
+
export const transports = result.initialized ? [result.value] : []
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
The same helper is suitable for BugHQ, workers, web and API servers, dashboard
|
|
319
|
+
processes, and Buddy commands. Browser integrations should receive only the
|
|
320
|
+
resolved public enablement or metadata they need, never a server credential.
|
|
321
|
+
|
|
322
|
+
- `enabled: false` always disables initialization.
|
|
323
|
+
- `enabled: true` does not bypass the environment allowlist.
|
|
324
|
+
- An empty allowlist disables every environment.
|
|
325
|
+
- Unknown or malformed environment names fail closed.
|
|
326
|
+
- `local`, `development`, and `test` are distinct labels.
|
|
327
|
+
- `APP_ENV` is configuration, not deployment proof. A local process launched
|
|
328
|
+
with `APP_ENV=production` qualifies for a production allowlist.
|
|
329
|
+
|
|
296
330
|
### Supported CI/CD Providers
|
|
297
331
|
|
|
298
332
|
- GitHub Actions
|
package/dist/integrations.d.ts
CHANGED
|
@@ -33,6 +33,21 @@ export declare function integrationEnvironment(): string | undefined;
|
|
|
33
33
|
* @param defaultEnvironments the allowlist to use when the app did not set one
|
|
34
34
|
*/
|
|
35
35
|
export declare function integrationGate(options: EnvironmentGatedIntegration | undefined | null, defaultEnvironments?: readonly string[]): IntegrationGate;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize an integration only when its environment gate is open.
|
|
38
|
+
*
|
|
39
|
+
* The callback is never evaluated for an excluded environment, so constructing
|
|
40
|
+
* an SDK client, registering hooks, or starting a flush timer inside it is
|
|
41
|
+
* safe. Included adapters receive the normalized environment without exposing
|
|
42
|
+
* a second `environment` option to application configuration.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const result = initializeIntegration(config.bughq, ({ environment }) =>
|
|
47
|
+
* installBugHq({ key: config.bughq.key, environment }))
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function initializeIntegration<T>(options: EnvironmentGatedIntegration | undefined | null, initialize: (context: IntegrationContext) => T, defaultEnvironments?: readonly string[]): IntegrationInitialization<T>;
|
|
36
51
|
/**
|
|
37
52
|
* One environment gate, shared by every integration that talks to a remote
|
|
38
53
|
* service (stacksjs/stacks#2792).
|
|
@@ -87,9 +102,16 @@ export declare interface IntegrationGate {
|
|
|
87
102
|
environment: string | undefined
|
|
88
103
|
reason: IntegrationGateReason
|
|
89
104
|
}
|
|
105
|
+
/** Context Stacks resolves before an integration is allowed to initialize. */
|
|
106
|
+
export declare interface IntegrationContext {
|
|
107
|
+
environment: string
|
|
108
|
+
}
|
|
90
109
|
/** Why the gate answered as it did. Worth logging; worth asserting in tests. */
|
|
91
110
|
export type IntegrationGateReason = | 'disabled-explicitly'
|
|
92
111
|
| 'empty-allowlist'
|
|
93
112
|
| 'environment-unknown'
|
|
94
113
|
| 'environment-excluded'
|
|
95
114
|
| 'environment-allowed';
|
|
115
|
+
/** The observable result of an environment-gated initialization attempt. */
|
|
116
|
+
export type IntegrationInitialization<T> = | { initialized: false, gate: IntegrationGate }
|
|
117
|
+
| { initialized: true, gate: IntegrationGate, value: T }
|
package/dist/integrations.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const REMOTE_TELEMETRY_ENVIRONMENTS=["production","staging"];export function normalizeEnvironmentName(value){if(typeof value!=="string")return;const normalized=value.trim().toLowerCase();if(!/^[a-z0-9_-]+$/.test(normalized))return;if(normalized==="prod")return"production";if(normalized==="stage")return"staging";if(normalized==="dev")return"development";return normalized}export function integrationEnvironment(){return normalizeEnvironmentName(process.env.APP_ENV)??normalizeEnvironmentName("development")}export function integrationGate(options,defaultEnvironments=REMOTE_TELEMETRY_ENVIRONMENTS){const environment=integrationEnvironment();if(options?.enabled===!1)return{enabled:!1,environment,reason:"disabled-explicitly"};const allowlist=options?.environments??defaultEnvironments;if(allowlist.length===0)return{enabled:!1,environment,reason:"empty-allowlist"};if(environment===void 0)return{enabled:!1,environment,reason:"environment-unknown"};const permitted=new Set;for(const entry of allowlist){const name=normalizeEnvironmentName(entry);if(name!==void 0)permitted.add(name)}return permitted.has(environment)?{enabled:!0,environment,reason:"environment-allowed"}:{enabled:!1,environment,reason:"environment-excluded"}}
|
|
1
|
+
export const REMOTE_TELEMETRY_ENVIRONMENTS=["production","staging"];export function normalizeEnvironmentName(value){if(typeof value!=="string")return;const normalized=value.trim().toLowerCase();if(!/^[a-z0-9_-]+$/.test(normalized))return;if(normalized==="prod")return"production";if(normalized==="stage")return"staging";if(normalized==="dev")return"development";return normalized}export function integrationEnvironment(){return normalizeEnvironmentName(process.env.APP_ENV)??normalizeEnvironmentName("development")}export function integrationGate(options,defaultEnvironments=REMOTE_TELEMETRY_ENVIRONMENTS){const environment=integrationEnvironment();if(options?.enabled===!1)return{enabled:!1,environment,reason:"disabled-explicitly"};const allowlist=options?.environments??defaultEnvironments;if(allowlist.length===0)return{enabled:!1,environment,reason:"empty-allowlist"};if(environment===void 0)return{enabled:!1,environment,reason:"environment-unknown"};const permitted=new Set;for(const entry of allowlist){const name=normalizeEnvironmentName(entry);if(name!==void 0)permitted.add(name)}return permitted.has(environment)?{enabled:!0,environment,reason:"environment-allowed"}:{enabled:!1,environment,reason:"environment-excluded"}}export function initializeIntegration(options,initialize,defaultEnvironments=REMOTE_TELEMETRY_ENVIRONMENTS){const gate=integrationGate(options,defaultEnvironments);if(!gate.enabled||gate.environment===void 0)return{initialized:!1,gate};return{initialized:!0,gate,value:initialize({environment:gate.environment})}}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/env",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.16",
|
|
6
6
|
"description": "Stacks env helper methods.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"prepublishOnly": "bun run build"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@stacksjs/path": "0.75.
|
|
59
|
+
"@stacksjs/path": "0.75.16"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"better-dx": "^0.2.24",
|
|
63
|
-
"@stacksjs/validation": "0.75.
|
|
63
|
+
"@stacksjs/validation": "0.75.16"
|
|
64
64
|
}
|
|
65
65
|
}
|