From f0e54cf66692b1c8150c823412965e2e3864a2cf Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Fri, 10 Apr 2026 16:09:54 +0600 Subject: [PATCH] [FSSDK-12453] server bundle addition --- package.json | 5 +++++ rollup.config.mjs | 29 ++++++++++++++++++++++------- src/server.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 src/server.ts diff --git a/package.json b/package.json index 662f2c5..4d593ea 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,11 @@ "types": "./dist/index.d.ts", "exports": { ".": { + "react-server": { + "types": "./dist/server.d.ts", + "import": "./dist/server.es.min.mjs", + "default": "./dist/server.es.min.mjs" + }, "types": "./dist/index.d.ts", "import": "./dist/react-sdk.es.min.mjs", "default": "./dist/react-sdk.es.min.mjs" diff --git a/rollup.config.mjs b/rollup.config.mjs index b4d6cd5..b3a2437 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -22,13 +22,28 @@ const { dependencies, peerDependencies } = pkg; const externalDeps = [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {}), 'crypto']; const external = (id) => externalDeps.some((dep) => id === dep || id.startsWith(dep + '/')); -export default { - input: '.build/index.js', +const shared = { external, plugins: [resolve({ browser: true }), terser()], - output: { - file: 'dist/react-sdk.es.min.mjs', - format: 'es', - sourcemap: true, - }, }; + +export default [ + { + ...shared, + input: '.build/index.js', + output: { + file: 'dist/react-sdk.es.min.mjs', + format: 'es', + sourcemap: true, + }, + }, + { + ...shared, + input: '.build/server.js', + output: { + file: 'dist/server.es.min.mjs', + format: 'es', + sourcemap: true, + }, + }, +]; diff --git a/src/server.ts b/src/server.ts new file mode 100644 index 0000000..534d903 --- /dev/null +++ b/src/server.ts @@ -0,0 +1,46 @@ +/** + * Copyright 2026 Optimizely + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Server-safe entry point for @optimizely/react-sdk. + * + * This module can be safely imported in React Server Components (RSC) + * as it does not use any client-only React APIs (createContext, hooks, etc.). + */ + +// Client creation +export { + createInstance, + createPollingProjectConfigManager, + createStaticProjectConfigManager, + createBatchEventProcessor, + createForwardingEventProcessor, + createOdpManager, + createVuidManager, + createErrorNotifier, +} from './client/index'; + +// Logger +export { createLogger, DEBUG, ERROR, WARN, INFO } from './logger/index'; + +// Helpers +export { getQualifiedSegments, type QualifiedSegmentsResult } from './utils/helpers'; + +// Types from JS SDK +export type * from '@optimizely/optimizely-sdk'; + +// UserInfo type (type-only, safe for server) +export type { UserInfo } from './provider/types';