@replanejs/next 0.7.3 → 0.7.5
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 +160 -296
- package/dist/index.cjs +100 -174
- package/dist/index.d.cts +23 -183
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +24 -184
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -171
- package/dist/index.js.map +1 -1
- package/package.json +7 -15
- package/dist/chunk-CUT6urMc.cjs +0 -30
- package/dist/server.cjs +0 -95
- package/dist/server.d.cts +0 -114
- package/dist/server.d.cts.map +0 -1
- package/dist/server.d.ts +0 -114
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -94
- package/dist/server.js.map +0 -1
package/dist/server.cjs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const __replanejs_sdk = require_chunk.__toESM(require("@replanejs/sdk"));
|
|
3
|
-
|
|
4
|
-
//#region src/server.ts
|
|
5
|
-
/**
|
|
6
|
-
* Fetch configs from Replane and return a serializable snapshot.
|
|
7
|
-
*
|
|
8
|
-
* This is the primary server-side function for Next.js integration.
|
|
9
|
-
* It creates a Replane client, waits for initialization, captures a snapshot,
|
|
10
|
-
* and closes the client.
|
|
11
|
-
*
|
|
12
|
-
* The snapshot can be passed to `ReplaneNextProvider` for client-side hydration.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```tsx
|
|
16
|
-
* // In a Server Component
|
|
17
|
-
* const snapshot = await getReplaneSnapshot({
|
|
18
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
19
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
20
|
-
* context: { userId: user.id },
|
|
21
|
-
* });
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* // With Next.js caching
|
|
27
|
-
* const snapshot = await getReplaneSnapshot({
|
|
28
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
29
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
30
|
-
* fetchFn: (url, init) => fetch(url, {
|
|
31
|
-
* ...init,
|
|
32
|
-
* next: { revalidate: 60 }, // Revalidate every 60 seconds
|
|
33
|
-
* }),
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
async function getReplaneSnapshot(options) {
|
|
38
|
-
const client = await (0, __replanejs_sdk.createReplaneClient)({
|
|
39
|
-
baseUrl: options.baseUrl,
|
|
40
|
-
sdkKey: options.sdkKey,
|
|
41
|
-
fetchFn: options.fetchFn,
|
|
42
|
-
requestTimeoutMs: options.requestTimeoutMs,
|
|
43
|
-
initializationTimeoutMs: options.initializationTimeoutMs,
|
|
44
|
-
context: options.context,
|
|
45
|
-
required: options.required,
|
|
46
|
-
fallbacks: options.fallbacks
|
|
47
|
-
});
|
|
48
|
-
try {
|
|
49
|
-
return client.getSnapshot();
|
|
50
|
-
} finally {
|
|
51
|
-
client.close();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get a config value directly on the server.
|
|
56
|
-
*
|
|
57
|
-
* This is useful when you need a single config value in a Server Component
|
|
58
|
-
* or server-side code and don't need the full snapshot/hydration flow.
|
|
59
|
-
*
|
|
60
|
-
* Note: This creates a new client for each call, so prefer `getReplaneSnapshot`
|
|
61
|
-
* if you need multiple configs or client-side hydration.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```tsx
|
|
65
|
-
* // In a Server Component
|
|
66
|
-
* const maintenanceMode = await getConfig<boolean>({
|
|
67
|
-
* name: "maintenance-mode",
|
|
68
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
69
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
70
|
-
* });
|
|
71
|
-
*
|
|
72
|
-
* if (maintenanceMode) {
|
|
73
|
-
* return <MaintenancePage />;
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
async function getConfig(options) {
|
|
78
|
-
const client = await (0, __replanejs_sdk.createReplaneClient)({
|
|
79
|
-
baseUrl: options.baseUrl,
|
|
80
|
-
sdkKey: options.sdkKey,
|
|
81
|
-
fetchFn: options.fetchFn,
|
|
82
|
-
requestTimeoutMs: options.requestTimeoutMs,
|
|
83
|
-
initializationTimeoutMs: options.initializationTimeoutMs,
|
|
84
|
-
context: options.context
|
|
85
|
-
});
|
|
86
|
-
try {
|
|
87
|
-
return client.get(options.name, { context: options.context });
|
|
88
|
-
} finally {
|
|
89
|
-
client.close();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
//#endregion
|
|
94
|
-
exports.getConfig = getConfig;
|
|
95
|
-
exports.getReplaneSnapshot = getReplaneSnapshot;
|
package/dist/server.d.cts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { ReplaneClientOptions, ReplaneContext, ReplaneSnapshot } from "@replanejs/sdk";
|
|
2
|
-
|
|
3
|
-
//#region src/server.d.ts
|
|
4
|
-
|
|
5
|
-
interface GetReplaneSnapshotOptions<T extends object = Record<string, unknown>> {
|
|
6
|
-
/**
|
|
7
|
-
* Base URL of the Replane instance (no trailing slash).
|
|
8
|
-
*/
|
|
9
|
-
baseUrl: string;
|
|
10
|
-
/**
|
|
11
|
-
* Project SDK key for authorization.
|
|
12
|
-
*/
|
|
13
|
-
sdkKey: string;
|
|
14
|
-
/**
|
|
15
|
-
* Custom fetch implementation (useful for caching configuration).
|
|
16
|
-
* In Next.js, you can use the fetch options for caching:
|
|
17
|
-
* ```ts
|
|
18
|
-
* fetchFn: (url, init) => fetch(url, { ...init, next: { revalidate: 60 } })
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
fetchFn?: typeof fetch;
|
|
22
|
-
/**
|
|
23
|
-
* Optional timeout in ms for the request.
|
|
24
|
-
* @default 2000
|
|
25
|
-
*/
|
|
26
|
-
requestTimeoutMs?: number;
|
|
27
|
-
/**
|
|
28
|
-
* Optional timeout in ms for initialization.
|
|
29
|
-
* @default 5000
|
|
30
|
-
*/
|
|
31
|
-
initializationTimeoutMs?: number;
|
|
32
|
-
/**
|
|
33
|
-
* Default context used for override evaluation.
|
|
34
|
-
* This context will be included in the snapshot.
|
|
35
|
-
*/
|
|
36
|
-
context?: ReplaneContext;
|
|
37
|
-
/**
|
|
38
|
-
* Config names that must be present before the client is ready.
|
|
39
|
-
*/
|
|
40
|
-
required?: ReplaneClientOptions<T>["required"];
|
|
41
|
-
/**
|
|
42
|
-
* Fallback values to use if configs are not available.
|
|
43
|
-
*/
|
|
44
|
-
fallbacks?: ReplaneClientOptions<T>["fallbacks"];
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Fetch configs from Replane and return a serializable snapshot.
|
|
48
|
-
*
|
|
49
|
-
* This is the primary server-side function for Next.js integration.
|
|
50
|
-
* It creates a Replane client, waits for initialization, captures a snapshot,
|
|
51
|
-
* and closes the client.
|
|
52
|
-
*
|
|
53
|
-
* The snapshot can be passed to `ReplaneNextProvider` for client-side hydration.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```tsx
|
|
57
|
-
* // In a Server Component
|
|
58
|
-
* const snapshot = await getReplaneSnapshot({
|
|
59
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
60
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
61
|
-
* context: { userId: user.id },
|
|
62
|
-
* });
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```tsx
|
|
67
|
-
* // With Next.js caching
|
|
68
|
-
* const snapshot = await getReplaneSnapshot({
|
|
69
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
70
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
71
|
-
* fetchFn: (url, init) => fetch(url, {
|
|
72
|
-
* ...init,
|
|
73
|
-
* next: { revalidate: 60 }, // Revalidate every 60 seconds
|
|
74
|
-
* }),
|
|
75
|
-
* });
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
declare function getReplaneSnapshot<T extends object = Record<string, unknown>>(options: GetReplaneSnapshotOptions<T>): Promise<ReplaneSnapshot<T>>;
|
|
79
|
-
/**
|
|
80
|
-
* Get a config value directly on the server.
|
|
81
|
-
*
|
|
82
|
-
* This is useful when you need a single config value in a Server Component
|
|
83
|
-
* or server-side code and don't need the full snapshot/hydration flow.
|
|
84
|
-
*
|
|
85
|
-
* Note: This creates a new client for each call, so prefer `getReplaneSnapshot`
|
|
86
|
-
* if you need multiple configs or client-side hydration.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```tsx
|
|
90
|
-
* // In a Server Component
|
|
91
|
-
* const maintenanceMode = await getConfig<boolean>({
|
|
92
|
-
* name: "maintenance-mode",
|
|
93
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
94
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
95
|
-
* });
|
|
96
|
-
*
|
|
97
|
-
* if (maintenanceMode) {
|
|
98
|
-
* return <MaintenancePage />;
|
|
99
|
-
* }
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare function getConfig<T>(options: {
|
|
103
|
-
name: string;
|
|
104
|
-
baseUrl: string;
|
|
105
|
-
sdkKey: string;
|
|
106
|
-
fetchFn?: typeof fetch;
|
|
107
|
-
requestTimeoutMs?: number;
|
|
108
|
-
initializationTimeoutMs?: number;
|
|
109
|
-
context?: ReplaneContext;
|
|
110
|
-
}): Promise<T>;
|
|
111
|
-
//# sourceMappingURL=server.d.ts.map
|
|
112
|
-
//#endregion
|
|
113
|
-
export { GetReplaneSnapshotOptions, type ReplaneContext, type ReplaneSnapshot, getConfig, getReplaneSnapshot };
|
|
114
|
-
//# sourceMappingURL=server.d.cts.map
|
package/dist/server.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.cts","names":[],"sources":["../src/server.ts"],"sourcesContent":[],"mappings":";;;;UAiDiB,6CAA6C;;;;;;;;;;;;;;;;mBAkB3C;;;;;;;;;;;;;;;YAkBP;;;;aAKC,qBAAqB;;;;cAKpB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCb,sCAAsC,kCACjD,0BAA0B,KAClC,QAAQ,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;iBA0CL;;;;mBAIH;;;YAGP;IACR,QAAQ"}
|
package/dist/server.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { ReplaneClientOptions, ReplaneContext, ReplaneSnapshot } from "@replanejs/sdk";
|
|
2
|
-
|
|
3
|
-
//#region src/server.d.ts
|
|
4
|
-
|
|
5
|
-
interface GetReplaneSnapshotOptions<T extends object = Record<string, unknown>> {
|
|
6
|
-
/**
|
|
7
|
-
* Base URL of the Replane instance (no trailing slash).
|
|
8
|
-
*/
|
|
9
|
-
baseUrl: string;
|
|
10
|
-
/**
|
|
11
|
-
* Project SDK key for authorization.
|
|
12
|
-
*/
|
|
13
|
-
sdkKey: string;
|
|
14
|
-
/**
|
|
15
|
-
* Custom fetch implementation (useful for caching configuration).
|
|
16
|
-
* In Next.js, you can use the fetch options for caching:
|
|
17
|
-
* ```ts
|
|
18
|
-
* fetchFn: (url, init) => fetch(url, { ...init, next: { revalidate: 60 } })
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
fetchFn?: typeof fetch;
|
|
22
|
-
/**
|
|
23
|
-
* Optional timeout in ms for the request.
|
|
24
|
-
* @default 2000
|
|
25
|
-
*/
|
|
26
|
-
requestTimeoutMs?: number;
|
|
27
|
-
/**
|
|
28
|
-
* Optional timeout in ms for initialization.
|
|
29
|
-
* @default 5000
|
|
30
|
-
*/
|
|
31
|
-
initializationTimeoutMs?: number;
|
|
32
|
-
/**
|
|
33
|
-
* Default context used for override evaluation.
|
|
34
|
-
* This context will be included in the snapshot.
|
|
35
|
-
*/
|
|
36
|
-
context?: ReplaneContext;
|
|
37
|
-
/**
|
|
38
|
-
* Config names that must be present before the client is ready.
|
|
39
|
-
*/
|
|
40
|
-
required?: ReplaneClientOptions<T>["required"];
|
|
41
|
-
/**
|
|
42
|
-
* Fallback values to use if configs are not available.
|
|
43
|
-
*/
|
|
44
|
-
fallbacks?: ReplaneClientOptions<T>["fallbacks"];
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Fetch configs from Replane and return a serializable snapshot.
|
|
48
|
-
*
|
|
49
|
-
* This is the primary server-side function for Next.js integration.
|
|
50
|
-
* It creates a Replane client, waits for initialization, captures a snapshot,
|
|
51
|
-
* and closes the client.
|
|
52
|
-
*
|
|
53
|
-
* The snapshot can be passed to `ReplaneNextProvider` for client-side hydration.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```tsx
|
|
57
|
-
* // In a Server Component
|
|
58
|
-
* const snapshot = await getReplaneSnapshot({
|
|
59
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
60
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
61
|
-
* context: { userId: user.id },
|
|
62
|
-
* });
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```tsx
|
|
67
|
-
* // With Next.js caching
|
|
68
|
-
* const snapshot = await getReplaneSnapshot({
|
|
69
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
70
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
71
|
-
* fetchFn: (url, init) => fetch(url, {
|
|
72
|
-
* ...init,
|
|
73
|
-
* next: { revalidate: 60 }, // Revalidate every 60 seconds
|
|
74
|
-
* }),
|
|
75
|
-
* });
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
declare function getReplaneSnapshot<T extends object = Record<string, unknown>>(options: GetReplaneSnapshotOptions<T>): Promise<ReplaneSnapshot<T>>;
|
|
79
|
-
/**
|
|
80
|
-
* Get a config value directly on the server.
|
|
81
|
-
*
|
|
82
|
-
* This is useful when you need a single config value in a Server Component
|
|
83
|
-
* or server-side code and don't need the full snapshot/hydration flow.
|
|
84
|
-
*
|
|
85
|
-
* Note: This creates a new client for each call, so prefer `getReplaneSnapshot`
|
|
86
|
-
* if you need multiple configs or client-side hydration.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```tsx
|
|
90
|
-
* // In a Server Component
|
|
91
|
-
* const maintenanceMode = await getConfig<boolean>({
|
|
92
|
-
* name: "maintenance-mode",
|
|
93
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
94
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
95
|
-
* });
|
|
96
|
-
*
|
|
97
|
-
* if (maintenanceMode) {
|
|
98
|
-
* return <MaintenancePage />;
|
|
99
|
-
* }
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare function getConfig<T>(options: {
|
|
103
|
-
name: string;
|
|
104
|
-
baseUrl: string;
|
|
105
|
-
sdkKey: string;
|
|
106
|
-
fetchFn?: typeof fetch;
|
|
107
|
-
requestTimeoutMs?: number;
|
|
108
|
-
initializationTimeoutMs?: number;
|
|
109
|
-
context?: ReplaneContext;
|
|
110
|
-
}): Promise<T>;
|
|
111
|
-
//# sourceMappingURL=server.d.ts.map
|
|
112
|
-
//#endregion
|
|
113
|
-
export { GetReplaneSnapshotOptions, type ReplaneContext, type ReplaneSnapshot, getConfig, getReplaneSnapshot };
|
|
114
|
-
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","names":[],"sources":["../src/server.ts"],"sourcesContent":[],"mappings":";;;;UAiDiB,6CAA6C;;;;;;;;;;;;;;;;mBAkB3C;;;;;;;;;;;;;;;YAkBP;;;;aAKC,qBAAqB;;;;cAKpB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCb,sCAAsC,kCACjD,0BAA0B,KAClC,QAAQ,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;iBA0CL;;;;mBAIH;;;YAGP;IACR,QAAQ"}
|
package/dist/server.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { createReplaneClient } from "@replanejs/sdk";
|
|
2
|
-
|
|
3
|
-
//#region src/server.ts
|
|
4
|
-
/**
|
|
5
|
-
* Fetch configs from Replane and return a serializable snapshot.
|
|
6
|
-
*
|
|
7
|
-
* This is the primary server-side function for Next.js integration.
|
|
8
|
-
* It creates a Replane client, waits for initialization, captures a snapshot,
|
|
9
|
-
* and closes the client.
|
|
10
|
-
*
|
|
11
|
-
* The snapshot can be passed to `ReplaneNextProvider` for client-side hydration.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* // In a Server Component
|
|
16
|
-
* const snapshot = await getReplaneSnapshot({
|
|
17
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
18
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
19
|
-
* context: { userId: user.id },
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```tsx
|
|
25
|
-
* // With Next.js caching
|
|
26
|
-
* const snapshot = await getReplaneSnapshot({
|
|
27
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
28
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
29
|
-
* fetchFn: (url, init) => fetch(url, {
|
|
30
|
-
* ...init,
|
|
31
|
-
* next: { revalidate: 60 }, // Revalidate every 60 seconds
|
|
32
|
-
* }),
|
|
33
|
-
* });
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
async function getReplaneSnapshot(options) {
|
|
37
|
-
const client = await createReplaneClient({
|
|
38
|
-
baseUrl: options.baseUrl,
|
|
39
|
-
sdkKey: options.sdkKey,
|
|
40
|
-
fetchFn: options.fetchFn,
|
|
41
|
-
requestTimeoutMs: options.requestTimeoutMs,
|
|
42
|
-
initializationTimeoutMs: options.initializationTimeoutMs,
|
|
43
|
-
context: options.context,
|
|
44
|
-
required: options.required,
|
|
45
|
-
fallbacks: options.fallbacks
|
|
46
|
-
});
|
|
47
|
-
try {
|
|
48
|
-
return client.getSnapshot();
|
|
49
|
-
} finally {
|
|
50
|
-
client.close();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Get a config value directly on the server.
|
|
55
|
-
*
|
|
56
|
-
* This is useful when you need a single config value in a Server Component
|
|
57
|
-
* or server-side code and don't need the full snapshot/hydration flow.
|
|
58
|
-
*
|
|
59
|
-
* Note: This creates a new client for each call, so prefer `getReplaneSnapshot`
|
|
60
|
-
* if you need multiple configs or client-side hydration.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```tsx
|
|
64
|
-
* // In a Server Component
|
|
65
|
-
* const maintenanceMode = await getConfig<boolean>({
|
|
66
|
-
* name: "maintenance-mode",
|
|
67
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
68
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
69
|
-
* });
|
|
70
|
-
*
|
|
71
|
-
* if (maintenanceMode) {
|
|
72
|
-
* return <MaintenancePage />;
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
async function getConfig(options) {
|
|
77
|
-
const client = await createReplaneClient({
|
|
78
|
-
baseUrl: options.baseUrl,
|
|
79
|
-
sdkKey: options.sdkKey,
|
|
80
|
-
fetchFn: options.fetchFn,
|
|
81
|
-
requestTimeoutMs: options.requestTimeoutMs,
|
|
82
|
-
initializationTimeoutMs: options.initializationTimeoutMs,
|
|
83
|
-
context: options.context
|
|
84
|
-
});
|
|
85
|
-
try {
|
|
86
|
-
return client.get(options.name, { context: options.context });
|
|
87
|
-
} finally {
|
|
88
|
-
client.close();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
//#endregion
|
|
93
|
-
export { getConfig, getReplaneSnapshot };
|
|
94
|
-
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":["options: GetReplaneSnapshotOptions<T>","options: {\n name: string;\n baseUrl: string;\n sdkKey: string;\n fetchFn?: typeof fetch;\n requestTimeoutMs?: number;\n initializationTimeoutMs?: number;\n context?: ReplaneContext;\n}"],"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-side utilities for Replane in Next.js.\n *\n * These functions are designed to be used in:\n * - React Server Components (RSC)\n * - getServerSideProps\n * - API routes\n * - Server Actions\n *\n * @example\n * ```tsx\n * // app/layout.tsx (Server Component)\n * import { getReplaneSnapshot } from \"@replanejs/next/server\";\n * import { ReplaneNextProvider } from \"@replanejs/next\";\n *\n * export default async function RootLayout({ children }) {\n * const snapshot = await getReplaneSnapshot({\n * baseUrl: process.env.REPLANE_BASE_URL!,\n * sdkKey: process.env.REPLANE_SDK_KEY!,\n * });\n *\n * return (\n * <html>\n * <body>\n * <ReplaneNextProvider\n * snapshot={snapshot}\n * connection={{\n * baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,\n * sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,\n * }}\n * >\n * {children}\n * </ReplaneNextProvider>\n * </body>\n * </html>\n * );\n * }\n * ```\n */\n\nimport {\n createReplaneClient,\n type ReplaneClientOptions,\n type ReplaneSnapshot,\n type ReplaneContext,\n} from \"@replanejs/sdk\";\n\nexport type { ReplaneSnapshot, ReplaneContext };\n\nexport interface GetReplaneSnapshotOptions<T extends object = Record<string, unknown>> {\n /**\n * Base URL of the Replane instance (no trailing slash).\n */\n baseUrl: string;\n\n /**\n * Project SDK key for authorization.\n */\n sdkKey: string;\n\n /**\n * Custom fetch implementation (useful for caching configuration).\n * In Next.js, you can use the fetch options for caching:\n * ```ts\n * fetchFn: (url, init) => fetch(url, { ...init, next: { revalidate: 60 } })\n * ```\n */\n fetchFn?: typeof fetch;\n\n /**\n * Optional timeout in ms for the request.\n * @default 2000\n */\n requestTimeoutMs?: number;\n\n /**\n * Optional timeout in ms for initialization.\n * @default 5000\n */\n initializationTimeoutMs?: number;\n\n /**\n * Default context used for override evaluation.\n * This context will be included in the snapshot.\n */\n context?: ReplaneContext;\n\n /**\n * Config names that must be present before the client is ready.\n */\n required?: ReplaneClientOptions<T>[\"required\"];\n\n /**\n * Fallback values to use if configs are not available.\n */\n fallbacks?: ReplaneClientOptions<T>[\"fallbacks\"];\n}\n\n/**\n * Fetch configs from Replane and return a serializable snapshot.\n *\n * This is the primary server-side function for Next.js integration.\n * It creates a Replane client, waits for initialization, captures a snapshot,\n * and closes the client.\n *\n * The snapshot can be passed to `ReplaneNextProvider` for client-side hydration.\n *\n * @example\n * ```tsx\n * // In a Server Component\n * const snapshot = await getReplaneSnapshot({\n * baseUrl: process.env.REPLANE_BASE_URL!,\n * sdkKey: process.env.REPLANE_SDK_KEY!,\n * context: { userId: user.id },\n * });\n * ```\n *\n * @example\n * ```tsx\n * // With Next.js caching\n * const snapshot = await getReplaneSnapshot({\n * baseUrl: process.env.REPLANE_BASE_URL!,\n * sdkKey: process.env.REPLANE_SDK_KEY!,\n * fetchFn: (url, init) => fetch(url, {\n * ...init,\n * next: { revalidate: 60 }, // Revalidate every 60 seconds\n * }),\n * });\n * ```\n */\nexport async function getReplaneSnapshot<T extends object = Record<string, unknown>>(\n options: GetReplaneSnapshotOptions<T>\n): Promise<ReplaneSnapshot<T>> {\n const client = await createReplaneClient<T>({\n baseUrl: options.baseUrl,\n sdkKey: options.sdkKey,\n fetchFn: options.fetchFn,\n requestTimeoutMs: options.requestTimeoutMs,\n initializationTimeoutMs: options.initializationTimeoutMs,\n context: options.context,\n required: options.required,\n fallbacks: options.fallbacks,\n });\n\n try {\n return client.getSnapshot();\n } finally {\n client.close();\n }\n}\n\n/**\n * Get a config value directly on the server.\n *\n * This is useful when you need a single config value in a Server Component\n * or server-side code and don't need the full snapshot/hydration flow.\n *\n * Note: This creates a new client for each call, so prefer `getReplaneSnapshot`\n * if you need multiple configs or client-side hydration.\n *\n * @example\n * ```tsx\n * // In a Server Component\n * const maintenanceMode = await getConfig<boolean>({\n * name: \"maintenance-mode\",\n * baseUrl: process.env.REPLANE_BASE_URL!,\n * sdkKey: process.env.REPLANE_SDK_KEY!,\n * });\n *\n * if (maintenanceMode) {\n * return <MaintenancePage />;\n * }\n * ```\n */\nexport async function getConfig<T>(options: {\n name: string;\n baseUrl: string;\n sdkKey: string;\n fetchFn?: typeof fetch;\n requestTimeoutMs?: number;\n initializationTimeoutMs?: number;\n context?: ReplaneContext;\n}): Promise<T> {\n const client = await createReplaneClient({\n baseUrl: options.baseUrl,\n sdkKey: options.sdkKey,\n fetchFn: options.fetchFn,\n requestTimeoutMs: options.requestTimeoutMs,\n initializationTimeoutMs: options.initializationTimeoutMs,\n context: options.context,\n });\n\n try {\n return client.get(options.name, { context: options.context }) as T;\n } finally {\n client.close();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,eAAsB,mBACpBA,SAC6B;CAC7B,MAAM,SAAS,MAAM,oBAAuB;EAC1C,SAAS,QAAQ;EACjB,QAAQ,QAAQ;EAChB,SAAS,QAAQ;EACjB,kBAAkB,QAAQ;EAC1B,yBAAyB,QAAQ;EACjC,SAAS,QAAQ;EACjB,UAAU,QAAQ;EAClB,WAAW,QAAQ;CACpB,EAAC;AAEF,KAAI;AACF,SAAO,OAAO,aAAa;CAC5B,UAAS;AACR,SAAO,OAAO;CACf;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBD,eAAsB,UAAaC,SAQpB;CACb,MAAM,SAAS,MAAM,oBAAoB;EACvC,SAAS,QAAQ;EACjB,QAAQ,QAAQ;EAChB,SAAS,QAAQ;EACjB,kBAAkB,QAAQ;EAC1B,yBAAyB,QAAQ;EACjC,SAAS,QAAQ;CAClB,EAAC;AAEF,KAAI;AACF,SAAO,OAAO,IAAI,QAAQ,MAAM,EAAE,SAAS,QAAQ,QAAS,EAAC;CAC9D,UAAS;AACR,SAAO,OAAO;CACf;AACF"}
|