@bella-baxter/next 0.1.1-preview.100

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 ADDED
@@ -0,0 +1,92 @@
1
+ # @bella-baxter/next
2
+
3
+ [![npm](https://img.shields.io/npm/v/@bella-baxter/next)](https://www.npmjs.com/package/@bella-baxter/next)
4
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+
6
+ [Bella Baxter](https://github.com/Cosmic-Chimps/bella-baxter) integration for Next.js (App Router) — load secrets once in `instrumentation.ts` and access them in any server component or API route.
7
+
8
+ > ⚠️ **Node.js runtime only.** Not compatible with the Edge runtime. For Edge routes, export secrets at deploy time with `bella secrets get -o .env.production` and read from `process.env`.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @bella-baxter/next
14
+ # or
15
+ pnpm add @bella-baxter/next
16
+ ```
17
+
18
+ ## Setup
19
+
20
+ ### 1. Enable instrumentation (Next.js 14+)
21
+
22
+ ```js
23
+ // next.config.js / next.config.ts
24
+ /** @type {import('next').NextConfig} */
25
+ const nextConfig = {
26
+ experimental: {
27
+ instrumentationHook: true,
28
+ },
29
+ };
30
+
31
+ export default nextConfig;
32
+ ```
33
+
34
+ ### 2. Initialize in `instrumentation.ts`
35
+
36
+ ```ts
37
+ // instrumentation.ts
38
+ import { initBella } from '@bella-baxter/next';
39
+
40
+ export async function register() {
41
+ if (process.env.NEXT_RUNTIME === 'nodejs') {
42
+ await initBella({
43
+ baxterUrl: process.env.BELLA_BAXTER_URL!,
44
+ apiKey: process.env.BELLA_BAXTER_API_KEY!,
45
+ projectSlug: 'my-app', // or BELLA_BAXTER_PROJECT env var
46
+ environmentSlug: 'production', // or BELLA_BAXTER_ENV env var
47
+ });
48
+ }
49
+ }
50
+ ```
51
+
52
+ ### 3. Use anywhere server-side
53
+
54
+ ```ts
55
+ // app/api/route.ts
56
+ import { getBella, bella } from '@bella-baxter/next';
57
+
58
+ export async function GET() {
59
+ // Option A: full config object
60
+ const config = getBella();
61
+ const dbUrl = config.getOrThrow('DATABASE_URL');
62
+
63
+ // Option B: direct shorthand
64
+ const redisUrl = bella('REDIS_URL');
65
+
66
+ return Response.json({ ok: true });
67
+ }
68
+ ```
69
+
70
+ ## Typed secrets
71
+
72
+ Run `bella secrets generate typescript --declaration` to generate `bella-secrets.d.ts`. `getBella()` returns `BellaConfig & BellaSecrets` — typed property access works automatically:
73
+
74
+ ```ts
75
+ getBella().DATABASE_URL // string — typed!
76
+ ```
77
+
78
+ ## Environment variables
79
+
80
+ | Variable | Description |
81
+ |----------|-------------|
82
+ | `BELLA_BAXTER_URL` | Base URL of the Bella Baxter API |
83
+ | `BELLA_BAXTER_API_KEY` | API key (`bax-...`) |
84
+ | `BELLA_BAXTER_PROJECT` | Project slug |
85
+ | `BELLA_BAXTER_ENV` | Environment slug |
86
+ | `BELLA_BAXTER_PRIVATE_KEY` | Private key for ZKE (optional) |
87
+
88
+ ## Links
89
+
90
+ - [GitHub](https://github.com/Cosmic-Chimps/bella-baxter)
91
+ - [Issues](https://github.com/Cosmic-Chimps/bella-baxter/issues)
92
+ - [Core SDK](https://www.npmjs.com/package/@bella-baxter/sdk)
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @bella-baxter/next
3
+ *
4
+ * Next.js integration — load secrets once in instrumentation.ts and
5
+ * access them anywhere in server components / API routes.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // instrumentation.ts (Next.js 14+ / App Router)
10
+ * import { initBella } from '@bella-baxter/next';
11
+ *
12
+ * export async function register() {
13
+ * await initBella({
14
+ * baxterUrl: process.env.BELLA_BAXTER_URL!,
15
+ * apiKey: process.env.BELLA_BAXTER_API_KEY!,
16
+ * });
17
+ * }
18
+ *
19
+ * // app/api/route.ts (any server component or route handler)
20
+ * import { getBella } from '@bella-baxter/next';
21
+ *
22
+ * export async function GET() {
23
+ * const bella = getBella();
24
+ * return Response.json({ db: bella.DATABASE_URL });
25
+ * }
26
+ * ```
27
+ *
28
+ * ⚠️ Only works in the Node.js runtime (not Edge runtime).
29
+ * For Edge routes, fetch secrets at deploy time:
30
+ * bella secrets get -o .env.production
31
+ * then read from process.env in your edge functions.
32
+ */
33
+ import type { BellaConfig, BellaSecrets, BellaConfigOptions } from '@bella-baxter/sdk';
34
+ /**
35
+ * Initialize Bella secrets. Call this once from `instrumentation.ts`.
36
+ * Starts the polling timer in the background.
37
+ */
38
+ export declare function initBella(options: BellaConfigOptions): Promise<BellaConfig & BellaSecrets>;
39
+ /**
40
+ * Get the initialized BellaConfig instance.
41
+ * Throws if initBella() has not been called yet.
42
+ */
43
+ export declare function getBella(): BellaConfig & BellaSecrets;
44
+ /** Direct shorthand: bella('DATABASE_URL') */
45
+ export declare function bella(key: string): string | undefined;
46
+ export type { BellaConfig, BellaSecrets, BellaConfigOptions };
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAWH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAkBvF;;;GAGG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,GAAG,YAAY,CAAC,CAWhG;AAED;;;GAGG;AACH,wBAAgB,QAAQ,IAAI,WAAW,GAAG,YAAY,CAKrD;AAED,8CAA8C;AAC9C,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAErD;AAED,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @bella-baxter/next
3
+ *
4
+ * Next.js integration — load secrets once in instrumentation.ts and
5
+ * access them anywhere in server components / API routes.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // instrumentation.ts (Next.js 14+ / App Router)
10
+ * import { initBella } from '@bella-baxter/next';
11
+ *
12
+ * export async function register() {
13
+ * await initBella({
14
+ * baxterUrl: process.env.BELLA_BAXTER_URL!,
15
+ * apiKey: process.env.BELLA_BAXTER_API_KEY!,
16
+ * });
17
+ * }
18
+ *
19
+ * // app/api/route.ts (any server component or route handler)
20
+ * import { getBella } from '@bella-baxter/next';
21
+ *
22
+ * export async function GET() {
23
+ * const bella = getBella();
24
+ * return Response.json({ db: bella.DATABASE_URL });
25
+ * }
26
+ * ```
27
+ *
28
+ * ⚠️ Only works in the Node.js runtime (not Edge runtime).
29
+ * For Edge routes, fetch secrets at deploy time:
30
+ * bella secrets get -o .env.production
31
+ * then read from process.env in your edge functions.
32
+ */
33
+ // Store singleton on `process` (NOT `globalThis`).
34
+ //
35
+ // Next.js RSC bundles run through webpack which replaces `globalThis` with its own
36
+ // polyfill object — a value set on `globalThis` in instrumentation.ts is NOT visible
37
+ // in the RSC route bundle. `process` is the real Node.js process object and is never
38
+ // polyfilled by webpack for server-side bundles, making it a reliable cross-bundle carrier.
39
+ const PROCESS_KEY = '__bella_baxter_instance__';
40
+ function getInstance() {
41
+ return process[PROCESS_KEY] ?? null;
42
+ }
43
+ function setInstance(val) {
44
+ process[PROCESS_KEY] = val;
45
+ }
46
+ /**
47
+ * Initialize Bella secrets. Call this once from `instrumentation.ts`.
48
+ * Starts the polling timer in the background.
49
+ */
50
+ export async function initBella(options) {
51
+ if (getInstance()) {
52
+ console.warn('[Bella] initBella() called more than once — reusing existing instance.');
53
+ return getInstance();
54
+ }
55
+ // Dynamic import keeps Node.js-only modules (fs, path, crypto) out of the
56
+ // edge bundler's static analysis path, preventing spurious edge-runtime warnings.
57
+ const { createBellaConfig } = await import('@bella-baxter/sdk');
58
+ const instance = await createBellaConfig(options);
59
+ setInstance(instance);
60
+ return instance;
61
+ }
62
+ /**
63
+ * Get the initialized BellaConfig instance.
64
+ * Throws if initBella() has not been called yet.
65
+ */
66
+ export function getBella() {
67
+ const instance = getInstance();
68
+ if (!instance)
69
+ throw new Error('[Bella] getBella() called before initBella(). Check instrumentation.ts.');
70
+ return instance;
71
+ }
72
+ /** Direct shorthand: bella('DATABASE_URL') */
73
+ export function bella(key) {
74
+ return getBella().get(key);
75
+ }
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAaH,mDAAmD;AACnD,EAAE;AACF,mFAAmF;AACnF,qFAAqF;AACrF,qFAAqF;AACrF,4FAA4F;AAC5F,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAEhD,SAAS,WAAW;IAClB,OAAQ,OAA8C,CAAC,WAAW,CAAwC,IAAI,IAAI,CAAC;AACrH,CAAC;AAED,SAAS,WAAW,CAAC,GAA+B;IACjD,OAA8C,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC;AACrE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAA2B;IACzD,IAAI,WAAW,EAAE,EAAE,CAAC;QAClB,OAAO,CAAC,IAAI,CAAC,wEAAwE,CAAC,CAAC;QACvF,OAAO,WAAW,EAAG,CAAC;IACxB,CAAC;IACD,0EAA0E;IAC1E,kFAAkF;IAClF,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAClD,WAAW,CAAC,QAAQ,CAAC,CAAC;IACtB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ;IACtB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,IAAI,CAAC,QAAQ;QACX,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC7F,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,OAAO,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@bella-baxter/next",
3
+ "version": "0.1.1-preview.100",
4
+ "description": "Bella Baxter Next.js integration — load secrets in instrumentation.ts and access anywhere server-side",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "README.md",
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@bella-baxter/sdk": "0.1.1-preview.100"
20
+ },
21
+ "peerDependencies": {
22
+ "next": ">=14"
23
+ },
24
+ "devDependencies": {
25
+ "typescript": "^6.0.2",
26
+ "@types/node": "^25.5.0"
27
+ },
28
+ "keywords": [
29
+ "bella-baxter",
30
+ "secrets",
31
+ "nextjs",
32
+ "next"
33
+ ],
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/Cosmic-Chimps/bella-baxter-js.git",
38
+ "directory": "apps/sdk/js/packages/next"
39
+ },
40
+ "homepage": "https://github.com/Cosmic-Chimps/bella-baxter-js/tree/main/packages/next#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/Cosmic-Chimps/bella-baxter-js/issues"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "typecheck": "tsc --noEmit"
47
+ }
48
+ }