@replanejs/next 0.7.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Dmitry Tilyupo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,30 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ Object.defineProperty(exports, '__toESM', {
26
+ enumerable: true,
27
+ get: function () {
28
+ return __toESM;
29
+ }
30
+ });
package/dist/index.cjs ADDED
@@ -0,0 +1,218 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const react = require_chunk.__toESM(require("react"));
3
+ const __replanejs_react = require_chunk.__toESM(require("@replanejs/react"));
4
+ const __replanejs_sdk = require_chunk.__toESM(require("@replanejs/sdk"));
5
+ const react_jsx_runtime = require_chunk.__toESM(require("react/jsx-runtime"));
6
+
7
+ //#region src/provider.tsx
8
+ /**
9
+ * Next.js-optimized Replane provider with SSR hydration support.
10
+ *
11
+ * This component:
12
+ * 1. Restores the Replane client from a server-side snapshot instantly (no loading state)
13
+ * 2. Optionally connects to Replane for real-time updates
14
+ * 3. Preserves the client across re-renders for minimal latency
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * // app/layout.tsx
19
+ * import { getReplaneSnapshot } from "@replanejs/next/server";
20
+ * import { ReplaneNextProvider } from "@replanejs/next";
21
+ *
22
+ * export default async function RootLayout({ children }) {
23
+ * const snapshot = await getReplaneSnapshot({
24
+ * baseUrl: process.env.REPLANE_BASE_URL!,
25
+ * sdkKey: process.env.REPLANE_SDK_KEY!,
26
+ * });
27
+ *
28
+ * return (
29
+ * <html>
30
+ * <body>
31
+ * <ReplaneNextProvider
32
+ * snapshot={snapshot}
33
+ * connection={{
34
+ * baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
35
+ * sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
36
+ * }}
37
+ * >
38
+ * {children}
39
+ * </ReplaneNextProvider>
40
+ * </body>
41
+ * </html>
42
+ * );
43
+ * }
44
+ * ```
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * // Without real-time updates (static snapshot only)
49
+ * <ReplaneNextProvider snapshot={snapshot}>
50
+ * {children}
51
+ * </ReplaneNextProvider>
52
+ * ```
53
+ */
54
+ function ReplaneNextProvider({ snapshot, connection, context, children }) {
55
+ const clientRef = (0, react.useRef)(null);
56
+ const clientKey = (0, react.useMemo)(() => {
57
+ const snapshotKey = JSON.stringify(snapshot.configs.map((c) => c.name).sort());
58
+ const connectionKey = connection ? `${connection.baseUrl}:${connection.sdkKey}` : "no-connection";
59
+ const contextKey = context ? JSON.stringify(context) : "no-context";
60
+ return `${snapshotKey}:${connectionKey}:${contextKey}`;
61
+ }, [
62
+ snapshot,
63
+ connection,
64
+ context
65
+ ]);
66
+ const client = (0, react.useMemo)(() => {
67
+ if (clientRef.current) {}
68
+ const newClient = (0, __replanejs_sdk.restoreReplaneClient)({
69
+ snapshot,
70
+ connection: connection ? {
71
+ baseUrl: connection.baseUrl,
72
+ sdkKey: connection.sdkKey,
73
+ requestTimeoutMs: connection.requestTimeoutMs,
74
+ retryDelayMs: connection.retryDelayMs,
75
+ inactivityTimeoutMs: connection.inactivityTimeoutMs
76
+ } : void 0,
77
+ context
78
+ });
79
+ clientRef.current = newClient;
80
+ return newClient;
81
+ }, [clientKey]);
82
+ (0, react.useEffect)(() => {
83
+ return () => {
84
+ if (clientRef.current) {
85
+ clientRef.current.close();
86
+ clientRef.current = null;
87
+ }
88
+ };
89
+ }, []);
90
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__replanejs_react.ReplaneProvider, {
91
+ client,
92
+ children
93
+ });
94
+ }
95
+
96
+ //#endregion
97
+ //#region src/script.tsx
98
+ const REPLANE_SNAPSHOT_KEY = "__REPLANE_SNAPSHOT__";
99
+ /**
100
+ * Generate the script content for embedding the snapshot.
101
+ *
102
+ * Use this in a Server Component to embed the snapshot in the page:
103
+ *
104
+ * @example
105
+ * ```tsx
106
+ * // app/layout.tsx
107
+ * import { getReplaneSnapshot } from "@replanejs/next/server";
108
+ * import { getReplaneSnapshotScript, ReplaneScriptProvider } from "@replanejs/next";
109
+ *
110
+ * export default async function RootLayout({ children }) {
111
+ * const snapshot = await getReplaneSnapshot({ ... });
112
+ *
113
+ * return (
114
+ * <html>
115
+ * <head>
116
+ * <script
117
+ * dangerouslySetInnerHTML={{
118
+ * __html: getReplaneSnapshotScript(snapshot),
119
+ * }}
120
+ * />
121
+ * </head>
122
+ * <body>
123
+ * <ReplaneScriptProvider connection={{ ... }}>
124
+ * {children}
125
+ * </ReplaneScriptProvider>
126
+ * </body>
127
+ * </html>
128
+ * );
129
+ * }
130
+ * ```
131
+ */
132
+ function getReplaneSnapshotScript(snapshot) {
133
+ const json = JSON.stringify(snapshot).replace(/<\/script>/gi, "<\\/script>");
134
+ return `window.${REPLANE_SNAPSHOT_KEY}=${json};`;
135
+ }
136
+ /**
137
+ * Provider that reads the snapshot from a script tag.
138
+ *
139
+ * Use this with `getReplaneSnapshotScript()` for an alternative hydration pattern
140
+ * where the snapshot is embedded in a script tag instead of passed as a prop.
141
+ *
142
+ * This pattern can be useful for:
143
+ * - Pages with heavy component trees where prop drilling is inconvenient
144
+ * - Partial hydration scenarios
145
+ * - When you want the snapshot to be available before React hydrates
146
+ *
147
+ * @example
148
+ * ```tsx
149
+ * // In app/layout.tsx (Server Component)
150
+ * <script dangerouslySetInnerHTML={{ __html: getReplaneSnapshotScript(snapshot) }} />
151
+ *
152
+ * // In a client component
153
+ * <ReplaneScriptProvider connection={{ baseUrl, sdkKey }}>
154
+ * <App />
155
+ * </ReplaneScriptProvider>
156
+ * ```
157
+ */
158
+ function ReplaneScriptProvider({ connection, fallback, children }) {
159
+ const [snapshot, setSnapshot] = (0, react.useState)(() => {
160
+ if (typeof window !== "undefined" && window[REPLANE_SNAPSHOT_KEY]) return window[REPLANE_SNAPSHOT_KEY];
161
+ return null;
162
+ });
163
+ const clientRef = (0, react.useRef)(null);
164
+ (0, react.useEffect)(() => {
165
+ if (!snapshot && typeof window !== "undefined" && window[REPLANE_SNAPSHOT_KEY]) setSnapshot(window[REPLANE_SNAPSHOT_KEY]);
166
+ }, [snapshot]);
167
+ const client = (0, react.useMemo)(() => {
168
+ if (!snapshot) return null;
169
+ const newClient = (0, __replanejs_sdk.restoreReplaneClient)({
170
+ snapshot,
171
+ connection: connection ? {
172
+ baseUrl: connection.baseUrl,
173
+ sdkKey: connection.sdkKey,
174
+ requestTimeoutMs: connection.requestTimeoutMs,
175
+ retryDelayMs: connection.retryDelayMs,
176
+ inactivityTimeoutMs: connection.inactivityTimeoutMs
177
+ } : void 0
178
+ });
179
+ clientRef.current = newClient;
180
+ return newClient;
181
+ }, [snapshot, connection]);
182
+ (0, react.useEffect)(() => {
183
+ return () => {
184
+ if (clientRef.current) {
185
+ clientRef.current.close();
186
+ clientRef.current = null;
187
+ }
188
+ };
189
+ }, []);
190
+ if (!client) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: fallback ?? null });
191
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__replanejs_react.ReplaneProvider, {
192
+ client,
193
+ children
194
+ });
195
+ }
196
+
197
+ //#endregion
198
+ exports.ReplaneNextProvider = ReplaneNextProvider;
199
+ exports.ReplaneScriptProvider = ReplaneScriptProvider;
200
+ exports.getReplaneSnapshotScript = getReplaneSnapshotScript;
201
+ Object.defineProperty(exports, 'restoreReplaneClient', {
202
+ enumerable: true,
203
+ get: function () {
204
+ return __replanejs_sdk.restoreReplaneClient;
205
+ }
206
+ });
207
+ Object.defineProperty(exports, 'useConfig', {
208
+ enumerable: true,
209
+ get: function () {
210
+ return __replanejs_react.useConfig;
211
+ }
212
+ });
213
+ Object.defineProperty(exports, 'useReplane', {
214
+ enumerable: true,
215
+ get: function () {
216
+ return __replanejs_react.useReplane;
217
+ }
218
+ });
@@ -0,0 +1,216 @@
1
+ import * as react_jsx_runtime0$1 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
3
+ import { ReactNode } from "react";
4
+ import { ReplaneClient, ReplaneContext, ReplaneContext as ReplaneContext$1, ReplaneError, ReplaneSnapshot, ReplaneSnapshot as ReplaneSnapshot$1, restoreReplaneClient } from "@replanejs/sdk";
5
+ import { ReplaneContextValue, useConfig, useReplane } from "@replanejs/react";
6
+
7
+ //#region src/types.d.ts
8
+ /**
9
+ * Connection options for real-time updates.
10
+ */
11
+ interface ReplaneConnectionOptions {
12
+ /**
13
+ * Base URL of the Replane instance (no trailing slash).
14
+ * Use a NEXT_PUBLIC_ prefixed env var for client-side access.
15
+ */
16
+ baseUrl: string;
17
+ /**
18
+ * Project SDK key for authorization.
19
+ * Use a NEXT_PUBLIC_ prefixed env var for client-side access.
20
+ */
21
+ sdkKey: string;
22
+ /**
23
+ * Optional timeout in ms for requests.
24
+ * @default 2000
25
+ */
26
+ requestTimeoutMs?: number;
27
+ /**
28
+ * Delay between retries in ms.
29
+ * @default 200
30
+ */
31
+ retryDelayMs?: number;
32
+ /**
33
+ * Timeout in ms for SSE connection inactivity.
34
+ * @default 30000
35
+ */
36
+ inactivityTimeoutMs?: number;
37
+ }
38
+ /**
39
+ * Props for ReplaneNextProvider.
40
+ */
41
+ interface ReplaneNextProviderProps<T extends object = any> {
42
+ /**
43
+ * Serializable snapshot from the server.
44
+ * Obtained from `getReplaneSnapshot()` in a Server Component or getServerSideProps.
45
+ */
46
+ snapshot: ReplaneSnapshot$1<T>;
47
+ /**
48
+ * Connection options for real-time updates.
49
+ * If not provided, the client will only use the snapshot data (no live updates).
50
+ *
51
+ * For SSR apps that need real-time updates, provide connection options:
52
+ * ```tsx
53
+ * <ReplaneNextProvider
54
+ * snapshot={snapshot}
55
+ * connection={{
56
+ * baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
57
+ * sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
58
+ * }}
59
+ * >
60
+ * {children}
61
+ * </ReplaneNextProvider>
62
+ * ```
63
+ */
64
+ connection?: ReplaneConnectionOptions;
65
+ /**
66
+ * Override the context from the snapshot on the client.
67
+ * Useful for client-specific context like browser info.
68
+ */
69
+ context?: ReplaneContext$1;
70
+ children: ReactNode;
71
+ }
72
+ //# sourceMappingURL=types.d.ts.map
73
+ //#endregion
74
+ //#region src/provider.d.ts
75
+ /**
76
+ * Next.js-optimized Replane provider with SSR hydration support.
77
+ *
78
+ * This component:
79
+ * 1. Restores the Replane client from a server-side snapshot instantly (no loading state)
80
+ * 2. Optionally connects to Replane for real-time updates
81
+ * 3. Preserves the client across re-renders for minimal latency
82
+ *
83
+ * @example
84
+ * ```tsx
85
+ * // app/layout.tsx
86
+ * import { getReplaneSnapshot } from "@replanejs/next/server";
87
+ * import { ReplaneNextProvider } from "@replanejs/next";
88
+ *
89
+ * export default async function RootLayout({ children }) {
90
+ * const snapshot = await getReplaneSnapshot({
91
+ * baseUrl: process.env.REPLANE_BASE_URL!,
92
+ * sdkKey: process.env.REPLANE_SDK_KEY!,
93
+ * });
94
+ *
95
+ * return (
96
+ * <html>
97
+ * <body>
98
+ * <ReplaneNextProvider
99
+ * snapshot={snapshot}
100
+ * connection={{
101
+ * baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
102
+ * sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
103
+ * }}
104
+ * >
105
+ * {children}
106
+ * </ReplaneNextProvider>
107
+ * </body>
108
+ * </html>
109
+ * );
110
+ * }
111
+ * ```
112
+ *
113
+ * @example
114
+ * ```tsx
115
+ * // Without real-time updates (static snapshot only)
116
+ * <ReplaneNextProvider snapshot={snapshot}>
117
+ * {children}
118
+ * </ReplaneNextProvider>
119
+ * ```
120
+ */
121
+ declare function ReplaneNextProvider<T extends object>({
122
+ snapshot,
123
+ connection,
124
+ context,
125
+ children
126
+ }: ReplaneNextProviderProps<T>): react_jsx_runtime0$1.JSX.Element;
127
+ //# sourceMappingURL=provider.d.ts.map
128
+ //#endregion
129
+ //#region src/script.d.ts
130
+ declare const REPLANE_SNAPSHOT_KEY = "__REPLANE_SNAPSHOT__";
131
+ type AnyConfig = Record<string, any>;
132
+ declare global {
133
+ interface Window {
134
+ [REPLANE_SNAPSHOT_KEY]?: ReplaneSnapshot$1<AnyConfig>;
135
+ }
136
+ }
137
+ /**
138
+ * Generate the script content for embedding the snapshot.
139
+ *
140
+ * Use this in a Server Component to embed the snapshot in the page:
141
+ *
142
+ * @example
143
+ * ```tsx
144
+ * // app/layout.tsx
145
+ * import { getReplaneSnapshot } from "@replanejs/next/server";
146
+ * import { getReplaneSnapshotScript, ReplaneScriptProvider } from "@replanejs/next";
147
+ *
148
+ * export default async function RootLayout({ children }) {
149
+ * const snapshot = await getReplaneSnapshot({ ... });
150
+ *
151
+ * return (
152
+ * <html>
153
+ * <head>
154
+ * <script
155
+ * dangerouslySetInnerHTML={{
156
+ * __html: getReplaneSnapshotScript(snapshot),
157
+ * }}
158
+ * />
159
+ * </head>
160
+ * <body>
161
+ * <ReplaneScriptProvider connection={{ ... }}>
162
+ * {children}
163
+ * </ReplaneScriptProvider>
164
+ * </body>
165
+ * </html>
166
+ * );
167
+ * }
168
+ * ```
169
+ */
170
+ declare function getReplaneSnapshotScript<T extends object>(snapshot: ReplaneSnapshot$1<T>): string;
171
+ /**
172
+ * Props for ReplaneScriptProvider.
173
+ */
174
+ interface ReplaneScriptProviderProps {
175
+ /**
176
+ * Connection options for real-time updates.
177
+ * If not provided, the client will only use the snapshot data (no live updates).
178
+ */
179
+ connection?: ReplaneConnectionOptions;
180
+ /**
181
+ * Fallback to render while waiting for the snapshot.
182
+ * This should rarely be needed since the script is in the head.
183
+ */
184
+ fallback?: ReactNode;
185
+ children: ReactNode;
186
+ }
187
+ /**
188
+ * Provider that reads the snapshot from a script tag.
189
+ *
190
+ * Use this with `getReplaneSnapshotScript()` for an alternative hydration pattern
191
+ * where the snapshot is embedded in a script tag instead of passed as a prop.
192
+ *
193
+ * This pattern can be useful for:
194
+ * - Pages with heavy component trees where prop drilling is inconvenient
195
+ * - Partial hydration scenarios
196
+ * - When you want the snapshot to be available before React hydrates
197
+ *
198
+ * @example
199
+ * ```tsx
200
+ * // In app/layout.tsx (Server Component)
201
+ * <script dangerouslySetInnerHTML={{ __html: getReplaneSnapshotScript(snapshot) }} />
202
+ *
203
+ * // In a client component
204
+ * <ReplaneScriptProvider connection={{ baseUrl, sdkKey }}>
205
+ * <App />
206
+ * </ReplaneScriptProvider>
207
+ * ```
208
+ */
209
+ declare function ReplaneScriptProvider({
210
+ connection,
211
+ fallback,
212
+ children
213
+ }: ReplaneScriptProviderProps): react_jsx_runtime0.JSX.Element;
214
+ //#endregion
215
+ export { type ReplaneClient, type ReplaneConnectionOptions, type ReplaneContext, type ReplaneContextValue, type ReplaneError, ReplaneNextProvider, type ReplaneNextProviderProps, ReplaneScriptProvider, type ReplaneScriptProviderProps, type ReplaneSnapshot, getReplaneSnapshotScript, restoreReplaneClient, useConfig, useReplane };
216
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/provider.tsx","../src/script.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;UAMiB,wBAAA;;AAAjB;AAoCA;;EAAyC,OAKb,EAAA,MAAA;EAAC;;;;EA2BR,MAAA,EAAA,MAAA;;;;ACrBrB;EAAmC,gBAAA,CAAA,EAAA,MAAA;EAAA;;;;EAIzB,YACkB,CAAA,EAAA,MAAA;EAAC;;AAAC;;;;ACrD0B;AAG9B;AAGH;AAAA,UF+BN,wBE/BM,CAAA,UAAA,MAAA,GAAA,GAAA,CAAA,CAAA;EAAA;;;;EAIE,QAAA,EFgCb,iBEhCa,CFgCG,CEhCH,CAAA;EAqCT;;;;AAAoE;AASpF;;;;;AAaqB;AAyBrB;;;;;;EAI6B,UAAA,CAAA,EFrCd,wBEqCc;EAAA;;;;YF/BjB;YAEA;;;;;;;;;;;AApEZ;AAoCA;;;;;;;AAgCqB;;;;ACrBrB;;;;;;;;;AAK8B;;;;ACrD0B;AAG9B;AAGH;;;;;;AAIE;AAqCzB;;;;AAAoF;AASpF;AAA2C,iBDR3B,mBCQ2B,CAAA,UAAA,MAAA,CAAA,CAAA;EAAA,QAAA;EAAA,UAAA;EAAA,OAAA;EAAA;AAAA,CAAA,EDHxC,wBCGwC,CDHf,CCGe,CAAA,CAAA,EDHb,oBAAA,CAAA,GAAA,CAAA,OCGa;;;;cArDrC,oBAAA;KAGD,SAAA,GAAY;;;IFLA,CESZ,oBAAA,EFToC,EESZ,iBFTY,CESI,SFTJ,CAAA;EAoCxB;;;;;;;AAgCI;;;;ACrBrB;;;;;;;;;AAK8B;;;;ACrD0B;AAG9B;AAGH;;;;;;AAIE;AAqCzB;;AAAqF,iBAArE,wBAAqE,CAAA,UAAA,MAAA,CAAA,CAAA,QAAA,EAAhB,iBAAgB,CAAA,CAAA,CAAA,CAAA,EAAA,MAAA;;AAAD;AASpF;AAA2C,UAA1B,0BAAA,CAA0B;EAAA;;;AAatB;EAyBL,UAAA,CAAA,EAjCD,wBAiCsB;EAAA;;;;EAG3B,QACP,CAAA,EA/BU,SA+BV;EAA0B,QAAA,EA7BjB,SA6BiB;AAAA;;;;;;;;;;;;;;;;;;;;;;;iBAJb,qBAAA;;;;GAIb,6BAA0B,kBAAA,CAAA,GAAA,CAAA"}
@@ -0,0 +1,216 @@
1
+ import { ReactNode } from "react";
2
+ import { ReplaneContextValue, useConfig, useReplane } from "@replanejs/react";
3
+ import { ReplaneClient, ReplaneContext, ReplaneContext as ReplaneContext$1, ReplaneError, ReplaneSnapshot, ReplaneSnapshot as ReplaneSnapshot$1, restoreReplaneClient } from "@replanejs/sdk";
4
+ import * as react_jsx_runtime0$1 from "react/jsx-runtime";
5
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
6
+
7
+ //#region src/types.d.ts
8
+ /**
9
+ * Connection options for real-time updates.
10
+ */
11
+ interface ReplaneConnectionOptions {
12
+ /**
13
+ * Base URL of the Replane instance (no trailing slash).
14
+ * Use a NEXT_PUBLIC_ prefixed env var for client-side access.
15
+ */
16
+ baseUrl: string;
17
+ /**
18
+ * Project SDK key for authorization.
19
+ * Use a NEXT_PUBLIC_ prefixed env var for client-side access.
20
+ */
21
+ sdkKey: string;
22
+ /**
23
+ * Optional timeout in ms for requests.
24
+ * @default 2000
25
+ */
26
+ requestTimeoutMs?: number;
27
+ /**
28
+ * Delay between retries in ms.
29
+ * @default 200
30
+ */
31
+ retryDelayMs?: number;
32
+ /**
33
+ * Timeout in ms for SSE connection inactivity.
34
+ * @default 30000
35
+ */
36
+ inactivityTimeoutMs?: number;
37
+ }
38
+ /**
39
+ * Props for ReplaneNextProvider.
40
+ */
41
+ interface ReplaneNextProviderProps<T extends object = any> {
42
+ /**
43
+ * Serializable snapshot from the server.
44
+ * Obtained from `getReplaneSnapshot()` in a Server Component or getServerSideProps.
45
+ */
46
+ snapshot: ReplaneSnapshot$1<T>;
47
+ /**
48
+ * Connection options for real-time updates.
49
+ * If not provided, the client will only use the snapshot data (no live updates).
50
+ *
51
+ * For SSR apps that need real-time updates, provide connection options:
52
+ * ```tsx
53
+ * <ReplaneNextProvider
54
+ * snapshot={snapshot}
55
+ * connection={{
56
+ * baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
57
+ * sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
58
+ * }}
59
+ * >
60
+ * {children}
61
+ * </ReplaneNextProvider>
62
+ * ```
63
+ */
64
+ connection?: ReplaneConnectionOptions;
65
+ /**
66
+ * Override the context from the snapshot on the client.
67
+ * Useful for client-specific context like browser info.
68
+ */
69
+ context?: ReplaneContext$1;
70
+ children: ReactNode;
71
+ }
72
+ //# sourceMappingURL=types.d.ts.map
73
+ //#endregion
74
+ //#region src/provider.d.ts
75
+ /**
76
+ * Next.js-optimized Replane provider with SSR hydration support.
77
+ *
78
+ * This component:
79
+ * 1. Restores the Replane client from a server-side snapshot instantly (no loading state)
80
+ * 2. Optionally connects to Replane for real-time updates
81
+ * 3. Preserves the client across re-renders for minimal latency
82
+ *
83
+ * @example
84
+ * ```tsx
85
+ * // app/layout.tsx
86
+ * import { getReplaneSnapshot } from "@replanejs/next/server";
87
+ * import { ReplaneNextProvider } from "@replanejs/next";
88
+ *
89
+ * export default async function RootLayout({ children }) {
90
+ * const snapshot = await getReplaneSnapshot({
91
+ * baseUrl: process.env.REPLANE_BASE_URL!,
92
+ * sdkKey: process.env.REPLANE_SDK_KEY!,
93
+ * });
94
+ *
95
+ * return (
96
+ * <html>
97
+ * <body>
98
+ * <ReplaneNextProvider
99
+ * snapshot={snapshot}
100
+ * connection={{
101
+ * baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
102
+ * sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
103
+ * }}
104
+ * >
105
+ * {children}
106
+ * </ReplaneNextProvider>
107
+ * </body>
108
+ * </html>
109
+ * );
110
+ * }
111
+ * ```
112
+ *
113
+ * @example
114
+ * ```tsx
115
+ * // Without real-time updates (static snapshot only)
116
+ * <ReplaneNextProvider snapshot={snapshot}>
117
+ * {children}
118
+ * </ReplaneNextProvider>
119
+ * ```
120
+ */
121
+ declare function ReplaneNextProvider<T extends object>({
122
+ snapshot,
123
+ connection,
124
+ context,
125
+ children
126
+ }: ReplaneNextProviderProps<T>): react_jsx_runtime0$1.JSX.Element;
127
+ //# sourceMappingURL=provider.d.ts.map
128
+ //#endregion
129
+ //#region src/script.d.ts
130
+ declare const REPLANE_SNAPSHOT_KEY = "__REPLANE_SNAPSHOT__";
131
+ type AnyConfig = Record<string, any>;
132
+ declare global {
133
+ interface Window {
134
+ [REPLANE_SNAPSHOT_KEY]?: ReplaneSnapshot$1<AnyConfig>;
135
+ }
136
+ }
137
+ /**
138
+ * Generate the script content for embedding the snapshot.
139
+ *
140
+ * Use this in a Server Component to embed the snapshot in the page:
141
+ *
142
+ * @example
143
+ * ```tsx
144
+ * // app/layout.tsx
145
+ * import { getReplaneSnapshot } from "@replanejs/next/server";
146
+ * import { getReplaneSnapshotScript, ReplaneScriptProvider } from "@replanejs/next";
147
+ *
148
+ * export default async function RootLayout({ children }) {
149
+ * const snapshot = await getReplaneSnapshot({ ... });
150
+ *
151
+ * return (
152
+ * <html>
153
+ * <head>
154
+ * <script
155
+ * dangerouslySetInnerHTML={{
156
+ * __html: getReplaneSnapshotScript(snapshot),
157
+ * }}
158
+ * />
159
+ * </head>
160
+ * <body>
161
+ * <ReplaneScriptProvider connection={{ ... }}>
162
+ * {children}
163
+ * </ReplaneScriptProvider>
164
+ * </body>
165
+ * </html>
166
+ * );
167
+ * }
168
+ * ```
169
+ */
170
+ declare function getReplaneSnapshotScript<T extends object>(snapshot: ReplaneSnapshot$1<T>): string;
171
+ /**
172
+ * Props for ReplaneScriptProvider.
173
+ */
174
+ interface ReplaneScriptProviderProps {
175
+ /**
176
+ * Connection options for real-time updates.
177
+ * If not provided, the client will only use the snapshot data (no live updates).
178
+ */
179
+ connection?: ReplaneConnectionOptions;
180
+ /**
181
+ * Fallback to render while waiting for the snapshot.
182
+ * This should rarely be needed since the script is in the head.
183
+ */
184
+ fallback?: ReactNode;
185
+ children: ReactNode;
186
+ }
187
+ /**
188
+ * Provider that reads the snapshot from a script tag.
189
+ *
190
+ * Use this with `getReplaneSnapshotScript()` for an alternative hydration pattern
191
+ * where the snapshot is embedded in a script tag instead of passed as a prop.
192
+ *
193
+ * This pattern can be useful for:
194
+ * - Pages with heavy component trees where prop drilling is inconvenient
195
+ * - Partial hydration scenarios
196
+ * - When you want the snapshot to be available before React hydrates
197
+ *
198
+ * @example
199
+ * ```tsx
200
+ * // In app/layout.tsx (Server Component)
201
+ * <script dangerouslySetInnerHTML={{ __html: getReplaneSnapshotScript(snapshot) }} />
202
+ *
203
+ * // In a client component
204
+ * <ReplaneScriptProvider connection={{ baseUrl, sdkKey }}>
205
+ * <App />
206
+ * </ReplaneScriptProvider>
207
+ * ```
208
+ */
209
+ declare function ReplaneScriptProvider({
210
+ connection,
211
+ fallback,
212
+ children
213
+ }: ReplaneScriptProviderProps): react_jsx_runtime0.JSX.Element;
214
+ //#endregion
215
+ export { type ReplaneClient, type ReplaneConnectionOptions, type ReplaneContext, type ReplaneContextValue, type ReplaneError, ReplaneNextProvider, type ReplaneNextProviderProps, ReplaneScriptProvider, type ReplaneScriptProviderProps, type ReplaneSnapshot, getReplaneSnapshotScript, restoreReplaneClient, useConfig, useReplane };
216
+ //# sourceMappingURL=index.d.ts.map