UNPKG

@devcycle/nextjs-sdk

Version:

The Next.js SDK for DevCycle!

55 lines 2.66 kB
import 'server-only'; import { initialize, validateSDKKey } from './initialize'; // allow return type inference // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export const setupDevCycle = ({ serverSDKKey, clientSDKKey, userGetter, options = {}, }) => { validateSDKKey(serverSDKKey, 'server'); validateSDKKey(clientSDKKey, 'client'); const _getVariableValue = async (key, defaultValue) => { const { client } = await initialize(serverSDKKey, clientSDKKey, userGetter, options); return client.variableValue(key, defaultValue); }; const _getAllVariables = async () => { const { client } = await initialize(serverSDKKey, clientSDKKey, userGetter, options); return client.allVariables(); }; const _getAllFeatures = async () => { const { client } = await initialize(serverSDKKey, clientSDKKey, userGetter, options); return client.allFeatures(); }; const _getClientContext = () => { var _a; const serverDataPromise = initialize(serverSDKKey, clientSDKKey, userGetter, options).then((result) => { const { client, ...serverData } = result; return serverData; }); const { enableStreaming, enableObfuscation, ...otherOptions } = options; const { disableAutomaticEventLogging, disableCustomEventLogging, disableRealtimeUpdates, apiProxyURL, eventFlushIntervalMS, flushEventQueueSize, } = otherOptions; const clientOptions = { disableAutomaticEventLogging, disableCustomEventLogging, disableRealtimeUpdates, apiProxyURL, eventFlushIntervalMS, flushEventQueueSize, enableObfuscation, }; return { serverDataPromise, options: clientOptions, clientSDKKey: clientSDKKey, enableStreaming: (_a = options === null || options === void 0 ? void 0 : options.enableStreaming) !== null && _a !== void 0 ? _a : false, // if a custom config source is set, add an artificial delay for realtime updates as a clumsy way to // allow for propagation time of the custom source, since we don't have a first-class way to ensure its // up to date realtimeDelay: (options === null || options === void 0 ? void 0 : options.configSource) ? 10000 : undefined, }; }; return { getVariableValue: _getVariableValue, getAllVariables: _getAllVariables, getAllFeatures: _getAllFeatures, getClientContext: _getClientContext, }; }; //# sourceMappingURL=setupDevCycle.js.map