@thewhateverapp/platform 0.7.22 → 0.7.24
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/dist/ai/index.d.ts +7 -2
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +13 -23
- package/dist/ai/index.js.map +1 -1
- package/dist/database/index.d.ts +8 -3
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +14 -30
- package/dist/database/index.js.map +1 -1
- package/dist/env.d.ts +68 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +66 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/kv/index.d.ts +8 -3
- package/dist/kv/index.d.ts.map +1 -1
- package/dist/kv/index.js +14 -30
- package/dist/kv/index.js.map +1 -1
- package/dist/kv/providers/cloudflare-kv.d.ts +1 -1
- package/dist/kv/providers/cloudflare-kv.js +2 -2
- package/dist/kv/types.d.ts +3 -3
- package/dist/r2/index.d.ts +8 -3
- package/dist/r2/index.d.ts.map +1 -1
- package/dist/r2/index.js +14 -30
- package/dist/r2/index.js.map +1 -1
- package/package.json +8 -2
package/dist/ai/index.d.ts
CHANGED
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
9
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
10
|
+
* import { configurePlatformEnv, getAI } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* export async function POST(req: NextRequest) {
|
|
13
|
+
* // Configure env once per request
|
|
14
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
+
*
|
|
12
16
|
* const ai = await getAI();
|
|
13
17
|
*
|
|
14
18
|
* // Simple text generation
|
|
@@ -38,7 +42,8 @@ export type * from './types';
|
|
|
38
42
|
*
|
|
39
43
|
* Automatically retrieves configuration from the environment.
|
|
40
44
|
*
|
|
41
|
-
* @param req - NextRequest, object with env property, or env object directly
|
|
45
|
+
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
46
|
+
* If not provided, uses the env configured via configurePlatformEnv().
|
|
42
47
|
* @returns AI service provider instance
|
|
43
48
|
*/
|
|
44
49
|
export declare function getAI(req?: AIRequest | {
|
package/dist/ai/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,SAAS,EACT,KAAK,EAIN,MAAM,SAAS,CAAC;AAIjB,mBAAmB,SAAS,CAAC;AAK7B;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CACzB,GAAG,CAAC,EAAE,SAAS,GAAG;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GAAG,KAAK,GACvC,OAAO,CAAC,iBAAiB,CAAC,CAmC5B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,iBAAiB,CAGvF"}
|
package/dist/ai/index.js
CHANGED
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
9
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
10
|
+
* import { configurePlatformEnv, getAI } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* export async function POST(req: NextRequest) {
|
|
13
|
+
* // Configure env once per request
|
|
14
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
+
*
|
|
12
16
|
* const ai = await getAI();
|
|
13
17
|
*
|
|
14
18
|
* // Simple text generation
|
|
@@ -31,6 +35,7 @@
|
|
|
31
35
|
* }
|
|
32
36
|
* ```
|
|
33
37
|
*/
|
|
38
|
+
import { getPlatformEnv, isPlatformEnvConfigured } from '../env';
|
|
34
39
|
// Default platform API URL
|
|
35
40
|
const DEFAULT_PLATFORM_API = 'https://api.thewhatever.app';
|
|
36
41
|
/**
|
|
@@ -38,34 +43,19 @@ const DEFAULT_PLATFORM_API = 'https://api.thewhatever.app';
|
|
|
38
43
|
*
|
|
39
44
|
* Automatically retrieves configuration from the environment.
|
|
40
45
|
*
|
|
41
|
-
* @param req - NextRequest, object with env property, or env object directly
|
|
46
|
+
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
47
|
+
* If not provided, uses the env configured via configurePlatformEnv().
|
|
42
48
|
* @returns AI service provider instance
|
|
43
49
|
*/
|
|
44
50
|
export async function getAI(req) {
|
|
45
51
|
let env;
|
|
46
|
-
// If no argument provided,
|
|
52
|
+
// If no argument provided, use the configured env provider
|
|
47
53
|
if (!req) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// @ts-ignore - dynamic import, only available at runtime in OpenNext apps
|
|
52
|
-
const { getCloudflareContext } = await import('@opennextjs/cloudflare');
|
|
53
|
-
// Try sync first (works in production worker context)
|
|
54
|
-
let context;
|
|
55
|
-
try {
|
|
56
|
-
context = getCloudflareContext();
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// Fall back to async if sync fails (e.g., during SSG or Node.js context)
|
|
60
|
-
context = await getCloudflareContext({ async: true });
|
|
61
|
-
}
|
|
62
|
-
env = context.env;
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
66
|
-
throw new Error(`getAI() failed: ${errMsg}. ` +
|
|
67
|
-
'In API routes, you can pass env directly: getAI({ env: getCloudflareContext().env })');
|
|
54
|
+
if (!isPlatformEnvConfigured()) {
|
|
55
|
+
throw new Error('getAI() called without env and configurePlatformEnv() was not called. ' +
|
|
56
|
+
'Either pass env directly: getAI({ env }) or call configurePlatformEnv(() => getCloudflareContext().env) first.');
|
|
68
57
|
}
|
|
58
|
+
env = getPlatformEnv();
|
|
69
59
|
}
|
|
70
60
|
else if ('env' in req) {
|
|
71
61
|
env = req.env;
|
package/dist/ai/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAUH,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AAKjE,2BAA2B;AAC3B,MAAM,oBAAoB,GAAG,6BAA6B,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,GAAwC;IAExC,IAAI,GAAsB,CAAC;IAE3B,2DAA2D;IAC3D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,IAAI,CAAC,uBAAuB,EAAE,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,wEAAwE;gBACtE,gHAAgH,CACnH,CAAC;QACJ,CAAC;QACD,GAAG,GAAG,cAAc,EAAW,CAAC;IAClC,CAAC;SAAM,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;QACxB,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAChB,CAAC;SAAM,IAAI,SAAS,IAAI,GAAG,IAAI,kBAAkB,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,EAAE,CAAC;QAC5E,oBAAoB;QACpB,GAAG,GAAG,GAAY,CAAC;IAC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K,IAAI,qBAAqB,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,OAAO;QACL,KAAK,CAAC,GAAG,CAAC,MAAc,EAAE,OAAoB;YAC5C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAiB,SAAS,EAAE;gBACtD,MAAM;gBACN,QAAQ,EAAE,OAAO,EAAE,QAAQ;gBAC3B,YAAY,EAAE,OAAO,EAAE,YAAY;gBACnC,SAAS,EAAE,OAAO,EAAE,SAAS;gBAC7B,WAAW,EAAE,OAAO,EAAE,WAAW;aAClC,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC,IAAI,CAAC;QACrB,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,GAAkB;YAC7B,OAAO,OAAO,CAAiB,SAAS,EAAE,GAAG,CAAC,CAAC;QACjD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/database/index.d.ts
CHANGED
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
9
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
10
|
+
* import { configurePlatformEnv, getDatabase } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* export async function GET(req: NextRequest) {
|
|
12
|
-
*
|
|
13
|
+
* // Configure env once per request
|
|
14
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
+
*
|
|
16
|
+
* const db = await getDatabase();
|
|
13
17
|
* const todos = db.collection('todos');
|
|
14
18
|
* const result = await todos.find({ completed: false });
|
|
15
19
|
* return NextResponse.json(result);
|
|
@@ -27,7 +31,8 @@ export type * from './types';
|
|
|
27
31
|
* - 'mongo-atlas': MongoDB Atlas for complex queries
|
|
28
32
|
* - 'planetscale': PlanetScale for relational needs
|
|
29
33
|
*
|
|
30
|
-
* @param req - NextRequest, object with env property, or env object directly
|
|
34
|
+
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
35
|
+
* If not provided, uses the env configured via configurePlatformEnv().
|
|
31
36
|
* @returns Database provider instance
|
|
32
37
|
*/
|
|
33
38
|
export declare function getDatabase(req?: DatabaseRequest | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAKhF,mBAAmB,SAAS,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAC/B,GAAG,CAAC,EAAE,eAAe,GAAG;IAAE,GAAG,EAAE,aAAa,CAAA;CAAE,GAAG,aAAa,GAC7D,OAAO,CAAC,gBAAgB,CAAC,CA6D3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,gBAAgB,CAenE"}
|
package/dist/database/index.js
CHANGED
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
9
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
10
|
+
* import { configurePlatformEnv, getDatabase } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* export async function GET(req: NextRequest) {
|
|
12
|
-
*
|
|
13
|
+
* // Configure env once per request
|
|
14
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
+
*
|
|
16
|
+
* const db = await getDatabase();
|
|
13
17
|
* const todos = db.collection('todos');
|
|
14
18
|
* const result = await todos.find({ completed: false });
|
|
15
19
|
* return NextResponse.json(result);
|
|
@@ -17,6 +21,7 @@
|
|
|
17
21
|
* ```
|
|
18
22
|
*/
|
|
19
23
|
import { FlexDB } from './providers';
|
|
24
|
+
import { getPlatformEnv, isPlatformEnvConfigured } from '../env';
|
|
20
25
|
/**
|
|
21
26
|
* Get a database instance for the current request
|
|
22
27
|
*
|
|
@@ -26,40 +31,19 @@ import { FlexDB } from './providers';
|
|
|
26
31
|
* - 'mongo-atlas': MongoDB Atlas for complex queries
|
|
27
32
|
* - 'planetscale': PlanetScale for relational needs
|
|
28
33
|
*
|
|
29
|
-
* @param req - NextRequest, object with env property, or env object directly
|
|
34
|
+
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
35
|
+
* If not provided, uses the env configured via configurePlatformEnv().
|
|
30
36
|
* @returns Database provider instance
|
|
31
37
|
*/
|
|
32
38
|
export async function getDatabase(req) {
|
|
33
39
|
let env;
|
|
34
|
-
// If no argument provided,
|
|
40
|
+
// If no argument provided, use the configured env provider
|
|
35
41
|
if (!req) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// @ts-ignore - dynamic import, only available at runtime in OpenNext apps
|
|
40
|
-
const { getCloudflareContext } = await import('@opennextjs/cloudflare');
|
|
41
|
-
// Try sync first (works in production worker context)
|
|
42
|
-
let context;
|
|
43
|
-
try {
|
|
44
|
-
context = getCloudflareContext();
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
// Fall back to async if sync fails (e.g., during SSG or Node.js context)
|
|
48
|
-
context = await getCloudflareContext({ async: true });
|
|
49
|
-
}
|
|
50
|
-
env = context.env;
|
|
51
|
-
// Validate that DB is actually a D1Database with expected methods
|
|
52
|
-
if (env.DB && typeof env.DB.exec !== 'function') {
|
|
53
|
-
console.error('[Platform SDK] env.DB exists but is not a valid D1Database:', typeof env.DB);
|
|
54
|
-
throw new Error(`DB binding exists but is not a valid D1Database. Got type: ${typeof env.DB}. ` +
|
|
55
|
-
'This may be a configuration issue with OpenNext or wrangler.json bindings.');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
60
|
-
throw new Error(`getDatabase() failed: ${errMsg}. ` +
|
|
61
|
-
'In API routes, you can pass env directly: getDatabase({ env: getCloudflareContext().env })');
|
|
42
|
+
if (!isPlatformEnvConfigured()) {
|
|
43
|
+
throw new Error('getDatabase() called without env and configurePlatformEnv() was not called. ' +
|
|
44
|
+
'Either pass env directly: getDatabase({ env }) or call configurePlatformEnv(() => getCloudflareContext().env) first.');
|
|
62
45
|
}
|
|
46
|
+
env = getPlatformEnv();
|
|
63
47
|
}
|
|
64
48
|
else if ('env' in req) {
|
|
65
49
|
env = req.env;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AAKjE;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAA8D;IAE9D,IAAI,GAA8B,CAAC;IAEnC,2DAA2D;IAC3D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,IAAI,CAAC,uBAAuB,EAAE,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,8EAA8E;gBAC5E,sHAAsH,CACzH,CAAC;QACJ,CAAC;QACD,GAAG,GAAG,cAAc,EAAmB,CAAC;IAC1C,CAAC;SAAM,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;QACxB,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAChB,CAAC;SAAM,IAAI,IAAI,IAAI,GAAG,EAA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AO,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAE5B;YACE,OAAO,CAAC,IAAI,CAAC,wBAAwB,QAAQ,2BAA2B,CAAC,CAAC;YAC1E,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC"}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment Provider for Platform SDK
|
|
3
|
+
*
|
|
4
|
+
* This module provides a dependency injection mechanism for accessing
|
|
5
|
+
* Cloudflare bindings (KV, R2, D1, etc.) without the SDK needing to
|
|
6
|
+
* import @opennextjs/cloudflare directly.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // In your OpenNext app (e.g., layout.tsx or API route)
|
|
11
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
12
|
+
* import { configurePlatformEnv } from '@thewhateverapp/platform';
|
|
13
|
+
*
|
|
14
|
+
* // Configure once per request
|
|
15
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
16
|
+
*
|
|
17
|
+
* // Then use SDK functions normally
|
|
18
|
+
* const kv = await getKV();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export interface PlatformEnv {
|
|
22
|
+
KV?: KVNamespace;
|
|
23
|
+
DB?: D1Database;
|
|
24
|
+
STORAGE?: R2Bucket;
|
|
25
|
+
STORAGE_PUBLIC_URL?: string;
|
|
26
|
+
DB_PROVIDER?: string;
|
|
27
|
+
KV_PROVIDER?: string;
|
|
28
|
+
STORAGE_PROVIDER?: string;
|
|
29
|
+
API_KEY?: string;
|
|
30
|
+
APP_ID?: string;
|
|
31
|
+
PLATFORM_API_URL?: string;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
type EnvProvider = () => PlatformEnv;
|
|
35
|
+
/**
|
|
36
|
+
* Configure the SDK's environment provider.
|
|
37
|
+
*
|
|
38
|
+
* Call this at the start of each request handler to wire in the
|
|
39
|
+
* Cloudflare context from OpenNext.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
44
|
+
* import { configurePlatformEnv } from '@thewhateverapp/platform';
|
|
45
|
+
*
|
|
46
|
+
* export async function POST(req: Request) {
|
|
47
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
48
|
+
* // ... rest of handler
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function configurePlatformEnv(provider: EnvProvider): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get the current environment.
|
|
55
|
+
*
|
|
56
|
+
* @throws Error if configurePlatformEnv() hasn't been called
|
|
57
|
+
*/
|
|
58
|
+
export declare function getPlatformEnv(): PlatformEnv;
|
|
59
|
+
/**
|
|
60
|
+
* Check if the environment provider has been configured.
|
|
61
|
+
*/
|
|
62
|
+
export declare function isPlatformEnvConfigured(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Reset the environment provider (mainly for testing).
|
|
65
|
+
*/
|
|
66
|
+
export declare function resetPlatformEnv(): void;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,WAAW,CAAC;IACjB,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,KAAK,WAAW,GAAG,MAAM,WAAW,CAAC;AAIrC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAQ5C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment Provider for Platform SDK
|
|
3
|
+
*
|
|
4
|
+
* This module provides a dependency injection mechanism for accessing
|
|
5
|
+
* Cloudflare bindings (KV, R2, D1, etc.) without the SDK needing to
|
|
6
|
+
* import @opennextjs/cloudflare directly.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // In your OpenNext app (e.g., layout.tsx or API route)
|
|
11
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
12
|
+
* import { configurePlatformEnv } from '@thewhateverapp/platform';
|
|
13
|
+
*
|
|
14
|
+
* // Configure once per request
|
|
15
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
16
|
+
*
|
|
17
|
+
* // Then use SDK functions normally
|
|
18
|
+
* const kv = await getKV();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
let envProvider = null;
|
|
22
|
+
/**
|
|
23
|
+
* Configure the SDK's environment provider.
|
|
24
|
+
*
|
|
25
|
+
* Call this at the start of each request handler to wire in the
|
|
26
|
+
* Cloudflare context from OpenNext.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
31
|
+
* import { configurePlatformEnv } from '@thewhateverapp/platform';
|
|
32
|
+
*
|
|
33
|
+
* export async function POST(req: Request) {
|
|
34
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
35
|
+
* // ... rest of handler
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function configurePlatformEnv(provider) {
|
|
40
|
+
envProvider = provider;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get the current environment.
|
|
44
|
+
*
|
|
45
|
+
* @throws Error if configurePlatformEnv() hasn't been called
|
|
46
|
+
*/
|
|
47
|
+
export function getPlatformEnv() {
|
|
48
|
+
if (!envProvider) {
|
|
49
|
+
throw new Error('Platform SDK env not configured. ' +
|
|
50
|
+
'Call configurePlatformEnv(() => getCloudflareContext().env) at the start of your request handler.');
|
|
51
|
+
}
|
|
52
|
+
return envProvider();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if the environment provider has been configured.
|
|
56
|
+
*/
|
|
57
|
+
export function isPlatformEnvConfigured() {
|
|
58
|
+
return envProvider !== null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Reset the environment provider (mainly for testing).
|
|
62
|
+
*/
|
|
63
|
+
export function resetPlatformEnv() {
|
|
64
|
+
envProvider = null;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAkBH,IAAI,WAAW,GAAuB,IAAI,CAAC;AAE3C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAqB;IACxD,WAAW,GAAG,QAAQ,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,mCAAmC;YACjC,mGAAmG,CACtG,CAAC;IACJ,CAAC;IACD,OAAO,WAAW,EAAE,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,WAAW,KAAK,IAAI,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
* ## Quick Start (for tiles/apps)
|
|
7
7
|
*
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
9
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
10
|
+
* import { configurePlatformEnv, getDatabase, getKV, getAI } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* // In your API route
|
|
12
13
|
* export async function POST(req: NextRequest) {
|
|
14
|
+
* // Configure env once at the start of each request
|
|
15
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
16
|
+
*
|
|
13
17
|
* const db = await getDatabase();
|
|
14
18
|
* const ai = await getAI();
|
|
15
19
|
*
|
|
@@ -20,6 +24,8 @@
|
|
|
20
24
|
* }
|
|
21
25
|
* ```
|
|
22
26
|
*/
|
|
27
|
+
export { configurePlatformEnv, getPlatformEnv, isPlatformEnvConfigured, resetPlatformEnv, } from './env';
|
|
28
|
+
export type { PlatformEnv } from './env';
|
|
23
29
|
export { createPlatform, WhateverPlatform } from './platform';
|
|
24
30
|
export type * from './types';
|
|
25
31
|
export { getDatabase, createDatabase } from './database';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],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
|
+
* import { configurePlatformEnv, getDatabase, getKV, getAI } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* // In your API route
|
|
12
13
|
* export async function POST(req: NextRequest) {
|
|
14
|
+
* // Configure env once at the start of each request
|
|
15
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
16
|
+
*
|
|
13
17
|
* const db = await getDatabase();
|
|
14
18
|
* const ai = await getAI();
|
|
15
19
|
*
|
|
@@ -20,6 +24,8 @@
|
|
|
20
24
|
* }
|
|
21
25
|
* ```
|
|
22
26
|
*/
|
|
27
|
+
// Environment configuration (must be called before using SDK in OpenNext)
|
|
28
|
+
export { configurePlatformEnv, getPlatformEnv, isPlatformEnvConfigured, resetPlatformEnv, } from './env';
|
|
23
29
|
// Main exports
|
|
24
30
|
export { createPlatform, WhateverPlatform } from './platform';
|
|
25
31
|
// =============================================================================
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,0EAA0E;AAC1E,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,OAAO,CAAC;AAGf,eAAe;AACf,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAK9D,gFAAgF;AAChF,mEAAmE;AACnE,gFAAgF;AAEhF,mDAAmD;AACnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAazD,yCAAyC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAWvC,gCAAgC;AAChC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAYjD,6DA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
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
9
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
10
|
+
* import { configurePlatformEnv, getKV } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* export async function GET(req: NextRequest) {
|
|
12
|
-
*
|
|
13
|
+
* // Configure env once per request
|
|
14
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
+
*
|
|
16
|
+
* const kv = await getKV();
|
|
13
17
|
*
|
|
14
18
|
* // Store data
|
|
15
19
|
* await kv.set('user:123', { name: 'Alice', score: 100 });
|
|
@@ -31,7 +35,8 @@ export type * from './types';
|
|
|
31
35
|
* - 'upstash': Upstash Redis
|
|
32
36
|
* - 'vercel': Vercel KV
|
|
33
37
|
*
|
|
34
|
-
* @param req - NextRequest, object with env property, or env object directly
|
|
38
|
+
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
39
|
+
* If not provided, uses the env configured via configurePlatformEnv().
|
|
35
40
|
* @returns KV provider instance
|
|
36
41
|
*/
|
|
37
42
|
export declare function getKV(req?: KVRequest | {
|
package/dist/kv/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKtE,mBAAmB,SAAS,CAAC;AAE7B;;;;;;;;;;;GAWG;AACH,wBAAsB,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG;IAAE,GAAG,EAAE,eAAe,CAAA;CAAE,GAAG,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAuD7G;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,UAAU,CAezD"}
|
package/dist/kv/index.js
CHANGED
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
9
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
10
|
+
* import { configurePlatformEnv, getKV } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* export async function GET(req: NextRequest) {
|
|
12
|
-
*
|
|
13
|
+
* // Configure env once per request
|
|
14
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
+
*
|
|
16
|
+
* const kv = await getKV();
|
|
13
17
|
*
|
|
14
18
|
* // Store data
|
|
15
19
|
* await kv.set('user:123', { name: 'Alice', score: 100 });
|
|
@@ -22,6 +26,7 @@
|
|
|
22
26
|
* ```
|
|
23
27
|
*/
|
|
24
28
|
import { CloudflareKV } from './providers';
|
|
29
|
+
import { getPlatformEnv, isPlatformEnvConfigured } from '../env';
|
|
25
30
|
/**
|
|
26
31
|
* Get a KV instance for the current request
|
|
27
32
|
*
|
|
@@ -30,40 +35,19 @@ import { CloudflareKV } from './providers';
|
|
|
30
35
|
* - 'upstash': Upstash Redis
|
|
31
36
|
* - 'vercel': Vercel KV
|
|
32
37
|
*
|
|
33
|
-
* @param req - NextRequest, object with env property, or env object directly
|
|
38
|
+
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
39
|
+
* If not provided, uses the env configured via configurePlatformEnv().
|
|
34
40
|
* @returns KV provider instance
|
|
35
41
|
*/
|
|
36
42
|
export async function getKV(req) {
|
|
37
43
|
let env;
|
|
38
|
-
// If no argument provided,
|
|
44
|
+
// If no argument provided, use the configured env provider
|
|
39
45
|
if (!req) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// @ts-ignore - dynamic import, only available at runtime in OpenNext apps
|
|
44
|
-
const { getCloudflareContext } = await import('@opennextjs/cloudflare');
|
|
45
|
-
// Try sync first (works in production worker context)
|
|
46
|
-
let context;
|
|
47
|
-
try {
|
|
48
|
-
context = getCloudflareContext();
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
// Fall back to async if sync fails (e.g., during SSG or Node.js context)
|
|
52
|
-
context = await getCloudflareContext({ async: true });
|
|
53
|
-
}
|
|
54
|
-
env = context.env;
|
|
55
|
-
// Validate that KV is actually a KVNamespace with expected methods
|
|
56
|
-
if (env.KV && typeof env.KV.put !== 'function') {
|
|
57
|
-
console.error('[Platform SDK] env.KV exists but is not a valid KVNamespace:', typeof env.KV, env.KV);
|
|
58
|
-
throw new Error(`KV binding exists but is not a valid KVNamespace. Got type: ${typeof env.KV}. ` +
|
|
59
|
-
'This may be a configuration issue with OpenNext or wrangler.json bindings.');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
64
|
-
throw new Error(`getKV() failed: ${errMsg}. ` +
|
|
65
|
-
'In API routes, you can pass env directly: getKV({ env: getCloudflareContext().env })');
|
|
46
|
+
if (!isPlatformEnvConfigured()) {
|
|
47
|
+
throw new Error('getKV() called without env and configurePlatformEnv() was not called. ' +
|
|
48
|
+
'Either pass env directly: getKV({ env }) or call configurePlatformEnv(() => getCloudflareContext().env) first.');
|
|
66
49
|
}
|
|
50
|
+
env = getPlatformEnv();
|
|
67
51
|
}
|
|
68
52
|
else if ('env' in req) {
|
|
69
53
|
env = req.env;
|
package/dist/kv/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EAAE,YAAY,EA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CAC5F,CAAC;QAEJ;YACE,OAAO,CAAC,IAAI,CAAC,wBAAwB,QAAQ,kCAAkC,CAAC,CAAC;YACjF,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAoB;IAC3C,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,IAAI,YAAY,CAAC;IAEjD,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,YAAY;YACf,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAElC;YACE,OAAO,CAAC,IAAI,CAAC,wBAAwB,QAAQ,kCAAkC,CAAC,CAAC;YACjF,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;AACH,CAAC"}
|
|
@@ -11,7 +11,7 @@ export declare class CloudflareKV implements KVProvider {
|
|
|
11
11
|
private kv;
|
|
12
12
|
constructor(kv: KVNamespace);
|
|
13
13
|
get<T = string>(key: string, type?: KVValueType): Promise<T | null>;
|
|
14
|
-
|
|
14
|
+
put(key: string, value: KVValue, options?: KVSetOptions): Promise<void>;
|
|
15
15
|
delete(key: string): Promise<void>;
|
|
16
16
|
deleteMany(keys: string[]): Promise<void>;
|
|
17
17
|
has(key: string): Promise<boolean>;
|
|
@@ -25,7 +25,7 @@ export class CloudflareKV {
|
|
|
25
25
|
return (await this.kv.get(key, 'text'));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
async
|
|
28
|
+
async put(key, value, options) {
|
|
29
29
|
const kvOptions = {};
|
|
30
30
|
if (options?.ttl) {
|
|
31
31
|
kvOptions.expirationTtl = options.ttl;
|
|
@@ -101,7 +101,7 @@ export class CloudflareKV {
|
|
|
101
101
|
const current = await this.get(key, 'text');
|
|
102
102
|
const currentValue = current ? parseInt(current, 10) : 0;
|
|
103
103
|
const newValue = currentValue + amount;
|
|
104
|
-
await this.
|
|
104
|
+
await this.put(key, String(newValue));
|
|
105
105
|
return newValue;
|
|
106
106
|
}
|
|
107
107
|
/**
|
package/dist/kv/types.d.ts
CHANGED
|
@@ -15,12 +15,12 @@ export interface KVProvider {
|
|
|
15
15
|
*/
|
|
16
16
|
get<T = string>(key: string, type?: KVValueType): Promise<T | null>;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param key - The key to
|
|
18
|
+
* Store a value by key (matches Cloudflare's native KV API)
|
|
19
|
+
* @param key - The key to store
|
|
20
20
|
* @param value - The value to store
|
|
21
21
|
* @param options - Optional storage options (TTL, metadata)
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
put(key: string, value: KVValue, options?: KVSetOptions): Promise<void>;
|
|
24
24
|
/**
|
|
25
25
|
* Delete a value by key
|
|
26
26
|
* @param key - The key to delete
|
package/dist/r2/index.d.ts
CHANGED
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
9
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
10
|
+
* import { configurePlatformEnv, getStorage } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* export async function POST(req: NextRequest) {
|
|
12
|
-
*
|
|
13
|
+
* // Configure env once per request
|
|
14
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
+
*
|
|
16
|
+
* const storage = await getStorage();
|
|
13
17
|
*
|
|
14
18
|
* // Upload a file
|
|
15
19
|
* const file = await req.formData().get('file') as File;
|
|
@@ -31,7 +35,8 @@ export type * from './types';
|
|
|
31
35
|
* - 's3': AWS S3
|
|
32
36
|
* - 'backblaze': Backblaze B2
|
|
33
37
|
*
|
|
34
|
-
* @param req - NextRequest, object with env property, or env object directly
|
|
38
|
+
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
39
|
+
* If not provided, uses the env configured via configurePlatformEnv().
|
|
35
40
|
* @returns Storage provider instance
|
|
36
41
|
*/
|
|
37
42
|
export declare function getStorage(req?: StorageRequest | {
|
package/dist/r2/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/r2/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/r2/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAKrF,mBAAmB,SAAS,CAAC;AAE7B;;;;;;;;;;;GAWG;AACH,wBAAsB,UAAU,CAC9B,GAAG,CAAC,EAAE,cAAc,GAAG;IAAE,GAAG,EAAE,oBAAoB,CAAA;CAAE,GAAG,oBAAoB,GAC1E,OAAO,CAAC,eAAe,CAAC,CAuD1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,oBAAoB,GAAG,eAAe,CAexE"}
|
package/dist/r2/index.js
CHANGED
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
9
|
+
* import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
10
|
+
* import { configurePlatformEnv, getStorage } from '@thewhateverapp/platform';
|
|
10
11
|
*
|
|
11
12
|
* export async function POST(req: NextRequest) {
|
|
12
|
-
*
|
|
13
|
+
* // Configure env once per request
|
|
14
|
+
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
+
*
|
|
16
|
+
* const storage = await getStorage();
|
|
13
17
|
*
|
|
14
18
|
* // Upload a file
|
|
15
19
|
* const file = await req.formData().get('file') as File;
|
|
@@ -22,6 +26,7 @@
|
|
|
22
26
|
* ```
|
|
23
27
|
*/
|
|
24
28
|
import { CloudflareR2 } from './providers';
|
|
29
|
+
import { getPlatformEnv, isPlatformEnvConfigured } from '../env';
|
|
25
30
|
/**
|
|
26
31
|
* Get a storage instance for the current request
|
|
27
32
|
*
|
|
@@ -30,40 +35,19 @@ import { CloudflareR2 } from './providers';
|
|
|
30
35
|
* - 's3': AWS S3
|
|
31
36
|
* - 'backblaze': Backblaze B2
|
|
32
37
|
*
|
|
33
|
-
* @param req - NextRequest, object with env property, or env object directly
|
|
38
|
+
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
39
|
+
* If not provided, uses the env configured via configurePlatformEnv().
|
|
34
40
|
* @returns Storage provider instance
|
|
35
41
|
*/
|
|
36
42
|
export async function getStorage(req) {
|
|
37
43
|
let env;
|
|
38
|
-
// If no argument provided,
|
|
44
|
+
// If no argument provided, use the configured env provider
|
|
39
45
|
if (!req) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// @ts-ignore - dynamic import, only available at runtime in OpenNext apps
|
|
44
|
-
const { getCloudflareContext } = await import('@opennextjs/cloudflare');
|
|
45
|
-
// Try sync first (works in production worker context)
|
|
46
|
-
let context;
|
|
47
|
-
try {
|
|
48
|
-
context = getCloudflareContext();
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
// Fall back to async if sync fails (e.g., during SSG or Node.js context)
|
|
52
|
-
context = await getCloudflareContext({ async: true });
|
|
53
|
-
}
|
|
54
|
-
env = context.env;
|
|
55
|
-
// Validate that STORAGE is actually an R2Bucket with expected methods
|
|
56
|
-
if (env.STORAGE && typeof env.STORAGE.put !== 'function') {
|
|
57
|
-
console.error('[Platform SDK] env.STORAGE exists but is not a valid R2Bucket:', typeof env.STORAGE);
|
|
58
|
-
throw new Error(`STORAGE binding exists but is not a valid R2Bucket. Got type: ${typeof env.STORAGE}. ` +
|
|
59
|
-
'This may be a configuration issue with OpenNext or wrangler.json bindings.');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
64
|
-
throw new Error(`getStorage() failed: ${errMsg}. ` +
|
|
65
|
-
'In API routes, you can pass env directly: getStorage({ env: getCloudflareContext().env })');
|
|
46
|
+
if (!isPlatformEnvConfigured()) {
|
|
47
|
+
throw new Error('getStorage() called without env and configurePlatformEnv() was not called. ' +
|
|
48
|
+
'Either pass env directly: getStorage({ env }) or call configurePlatformEnv(() => getCloudflareContext().env) first.');
|
|
66
49
|
}
|
|
50
|
+
env = getPlatformEnv();
|
|
67
51
|
}
|
|
68
52
|
else if ('env' in req) {
|
|
69
53
|
env = req.env;
|
package/dist/r2/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/r2/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/r2/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AAKjE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAA2E;IAE3E,IAAI,GAAqC,CAAC;IAE1C,2DAA2D;IAC3D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,IAAI,CAAC,uBAAuB,EAAE,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,6EAA6E;gBAC3E,qHAAqH,CACxH,CAAC;QACJ,CAAC;QACD,GAAG,GAAG,cAAc,EAA0B,CAAC;IACjD,CAAC;SAAM,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;QACxB,GAAG,GAAG,GA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EAAE,CAAC;QACjB,KAAK,IAAI;YACP,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAE/D;YACE,OAAO,CAAC,IAAI,CAAC,6BAA6B,QAAQ,kCAAkC,CAAC,CAAC;YACtF,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACjE,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thewhateverapp/platform",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.24",
|
|
4
4
|
"description": "Universal SDK for The Whatever App platform services",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,6 +53,12 @@
|
|
|
53
53
|
"typescript": "^5.7.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@cloudflare/workers-types": "^4.0.0"
|
|
56
|
+
"@cloudflare/workers-types": "^4.0.0",
|
|
57
|
+
"@opennextjs/cloudflare": "^1.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"@opennextjs/cloudflare": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
57
63
|
}
|
|
58
64
|
}
|