UNPKG

hypertune

Version:

[Hypertune](https://www.hypertune.com/) is the most flexible platform for feature flags, A/B testing, analytics and app configuration. Built with full end-to-end type-safety, Git-style version control and local, synchronous, in-memory flag evaluation. Opt

444 lines (287 loc) 13.1 kB
# Changelog ## 2.7.2 - Updated dependencies. ## 2.7.1 - Remote logging improvements. ## 2.7.0 - Added support for compressed initialization responses. ## 2.6.0 - Added a `shouldSkipInitDataUpdateOnRefresh` create option that skips updating init data when an update is detected, but still triggers an update notification so you can trigger rehydration from your own server in an update listener. This is the default behaviour in the generated React provider components for SSR frameworks like Next.js. - Optimization to skip init requests in the unlikely case that the retrieved hash data is for a commit older than the current one. - Renamed the `getInitDataHash` function in the `InitDataProvider` interface to `getHashData`. - Added `getInitResponse` and `getHashResponse` SDK methods so you can implement endpoints for SDK initialization and updates on your own server. ## 2.5.7 - Improvements to update handling. ## 2.5.6 - Added codegen support for `reactNative`. - Users on paid plans can now generate the Hypertune toolbar React component by setting the `includeToolbar` option to `true`. ## 2.5.5 - Improvements to update notifications. - Less verbose logging and improved error messages. ## 2.5.4 - Improvements to the local logs handler. ## 2.5.3 - You can now use the `getOverrideFromOverridesList` helper function to convert a flat object with dot separated flag paths as keys to an override object that can be used by the SDK. - Added support for encoding and decoding flag values for static pages using `Node.getEncodedFlagValues` and `decodeFlagValues` respectively. ## 2.5.2 - Improvements to readiness notifications. ## 2.5.1 - Deprecated the `localLogger` option in `CreateOptions`, replacing it with a new `logsHandler` option which lets you handle logs yourself, e.g. to forward to other analytics or observability systems. - Improvements to initialization data payload size. ## 2.4.1 - Improvements to readiness notifications. ## 2.4.0 - Initialization and standalone usage improvements. - Efficiency improvements when using query fragments. ## 2.3.10 - Bundle size, initialization and standalone usage improvements. ## 2.3.9 - Code generation improvements. ## 2.3.8 - Added `mjs` and `cjs` as `language` options for code generation. ## 2.3.7 - Vercel Edge Config init data provider improvements. ## 2.3.6 - Add README.md. ## 2.3.3 - Improvements to listening for updates. ## 2.3.1 - Traceability and shutdown behavior improvements. ## 2.2.5 - Remote logging improvements. ## 2.2.4 - Added the `isReady` function that checks whether the SDK is ready to log analytics events. - Deprecated the `initIntervalMs` option in `CreateOptions`. It is replaced by: - `initDataRefreshIntervalMs`: Specifies the interval at which the SDK checks for flag updates with a default value of 2000ms. - `shouldCheckForUpdates`: Specifies whether the SDK automatically checks for flag updates in the background. - You can now generate Vercel feature flag functions, defined via the `@vercel/flags/next` package, for the top-level boolean and enum flags in your Hypertune project. To enable this, set the `framework` option to `nextApp`, the `platform` option to `vercel` and specify the `getHypertuneImportPath` option with the relative path to your `getHypertune` function. - Bumped SDK request timeouts from 5s to 10s. - Disabled retries when using the `initIfNeeded` method. ## 2.1.2 - You can now use the `merge` helper function to recursively merge objects. ## 2.1.1 - You can now set a `HYPERTUNE_BRANCH_NAME` environment variable option to generate a client for a specific branch in your project. - You can now specify a `branchName` when creating the Hypertune SDK instance to initialize from a specific branch in your project. - You can now set a `HYPERTUNE_FRAMEWORK` environment variable to generate React context providers and hooks for your framework in an additional file. The options are `nextApp`, `nextPages`, `react`, `remix` and `gatsby`. ## 2.0.2 - Vercel Edge Config initialization improvements. ## 2.0.1 - Less verbose logging. ## 2.0.0 - You can now control how often the SDK should check for updates and flush logs. - You can now pass a custom `InitDataProvider` to initialize the SDK from your own data source. - You can now partially reduce your logic during dehydration on the server to hydrate the SDK on the client with a smaller logic payload. - You can now forward SDK messages, expression evaluations, split exposures and events to your own server. - Improved serverless logging. ## Migration guide - Install this SDK version with `npm i hypertune@2`. - Regenerate your client with `npx hypertune`. - Fix the TypeScript errors in your project with reference to the breaking changes listed below. ### Breaking changes #### Initialization - Renamed `initializeHypertune` to `initHypertune`. - `initHypertune` now only takes one options object and token is now a required option unless you've included it in your generated file. - Removed the `vercelEdgeConfigClient` and `vercelEdgeConfigItemKey` options. Instead you can set `initDataProvider` to an instance of `VercelEdgeConfigInitDataProvider` as shown below: ```typescript new VercelEdgeConfigInitDataProvider({ edgeConfigClient: createClient(process.env.EDGE_CONFIG), itemKey: process.env.EDGE_CONFIG_HYPERTUNE_ITEM_KEY, }); ``` `edgeConfigClient` and `itemKey` should have the same value as the old `vercelEdgeConfigClient` and `vercelEdgeConfigItemKey` options. - Removed the `shouldInitializeFromServer` option. Instead you can set the `initDataProvider` option to `null`. - Removed the `shouldStartIntervals` option. Instead you can set `initIntervalMs` and `remoteLogging.flushIntervalMs` to `0` to disable all background intervals or control each individually with a custom millisecond value. - Removed the `shouldListenForUpdates` option. Instead you can set `initIntervalMs` to `0` to disable listening for updates or control the interval in milliseconds directly. The default value is `1000`, i.e. 1 second. - Renamed the `loggingMode` option to `remoteLogging.mode`. - Renamed the `logger` option to `localLogger` and renamed its type from `CustomLogger` to `LocalLogger`. - The `DehydratedState` type was made generic. Instead you can use the concrete `DehydratedState` type in your generated file. #### Generated client - All methods on the generated client now take one options object argument instead of positional arguments. So when getting the Root node you will need to change: ```typescript hypertune.root({ context: { ... } }) ``` to ```typescript hypertune.root({ args: { context: { ... } } }) ``` - You no longer need to call the `get()` method for primitive and enum fields. For example, you will need to change: ```typescript rootNode.exampleFlag().get(/* fallback */ false); ``` to ```typescript rootNode.exampleFlag({ fallback: false }); ``` - This is also the case for primitive and enum arrays. Previously you had to map over the array calling the `get()` method for all the items. Now you just need to provide the `itemFallback` option and you will get a list of values directly. For example, you will need to change: ```typescript rootNode.stringListFlag().map((node) => node.get("item fallback")); ``` to ```typescript rootNode.stringListFlag({ itemFallback: "item fallback" }); ``` - Object, unions and lists of objects and unions are still returned as nodes or lists of nodes as before. - The default value for the `outputFilePath` codegen option has changed from `generated/generated.ts` to `generated/hypertune.ts`. - The codegen option `includeFallback` has been renamed to `includeInitData`. #### Other - Renamed `initFromServerIfNeeded()` to `initIfNeeded()`. - Removed `hasInitializedFromServer()`. Instead you can call `!!hypertune.getLastDataProviderInitTime()`. - Removed the `InitResponseBody` type. - Renamed the `LoggingMode` type to `RemoteLoggingMode`. - Renamed `initialize()` to `init()` and the `InitializeOptions` type to `InitOptions`. - Removed deprecated Node methods: - Removed `getCommitHash()`. Instead you can use `getStateHash()`. - Removed `waitForInitialization()`. Instead you can use `initFromServerIfNeeded()`. - Removed `getInitData()`. Instead you can use `dehydrate()`. - Removed `initFromData()`. Instead you can use `hydrate()`. ## 1.13.4 - Serverless improvements. ## 1.13.3 - Improved observability. ## 1.13.1 - Improved logging. ## 1.13.0 - Improved bundle size, reduced dependencies and improved analytics logging. ## 1.12.0 - Improved analytics event logging. ## 1.11.1 ### Breaking changes - The SDK now initializes from `edge.hypertune.com` (instead of `edge.prod.hypertune.com`) with significantly lower latency. If you have a Content Security Policy, add `https://edge.hypertune.com` to your `connect-src` directive. ## 1.10.0 - Added a `setOverride()` method you can use to set a local override that the SDK should use when evaluating your flags. - Added `dehydrate()` and `hydrate()` methods you can use to pass the state of the SDK from the server to the client during server-side rendering. These replace the `getInitData()` and `initFromData()` methods which are now deprecated. - Added a `getStateHash()` method which replaces the `getCommitHash()` method which is now deprecated. ## 1.9.0 - Analytics logging improvements. ## 1.8.0 - Performance improvements. ## 1.7.23 - Reduction improvements. ## 1.7.22 - Improved Cloudflare workers support. ## 1.7.21 - Analytics logging improvements. ## 1.7.20 - Reduction improvements. ## 1.7.17 - Plain JavaScript code generation option. ## 1.7.16 - Node.js improvements. ## 1.7.15 - Optimized package size. ## 1.7.12 - Code generation improvements. ## 1.7.9 - Code generation arguments can now be supplied as environment variables. ## 1.7.8 - React Native improvements. ## 1.7.5 - Added `hasInitializedFromServer()` method on SDK nodes. ## 1.7.4 - Made the SDK initialization query optional for code generation. ## 1.7.3 ### Breaking changes - Removed the `isInitialized()` SDK node method. Use the `getCommitHash()` method instead. - Renamed `stopListeners()` to `close()`. - Removed `initFromVercelEdgeConfig()` SDK node method. Use `initFromServerIfNeeded()` instead. - Replaced the `outputDirectoryPath` codegen argument with `outputFilePath`. ### Features - Improved Next.js and Vercel Edge Config integration. ## 1.6.12 - Optimized initialization. ## 1.6.7 - Added `addUpdateListener(listener)` and `removeUpdateListener(listener)` methods on SDK nodes so you can be notified when the SDK fetches an update. ## 1.6.5 - Added `getInitData()` and `initFromData(initData)` methods on SDK nodes so you can pass SDK init data across the server / client boundary in Next.js apps to instantly initialize the SDK on the client as part of the page load. - Added `shouldInitializeFromServer` initialize option so you can disable server initialization, e.g. for unit tests or when initializing the SDK from the server response in a Next.js app. - Added `initFromVercelEdgeConfig()` method on SDK nodes to explicitly `await` reinitialization from Vercel Edge Config. - Added `flushLogs()` method on SDK nodes to explicitly `await` flushing logs to Hypertune. ## 1.5.1 ### Breaking changes - You no longer need the `projectId` field in your `hypertune.json`. - The `token` field should now be your project token rather than your business token. You can find this in your project settings. - If you're setting your token via an environment variable, this needs to be your project token too. - When you run `npx hypertune`, the generated file has a different name so you should delete the old file and change any imports of it to point to the new one. - The generated file no longer contains the token so you should pass this yourself in the options object when you call `initializeHypertune` or ensure you have it in an environment variable with a name ending with `HYPERTUNE_TOKEN`. - The `businessToken` field in the options object passed to `initializeHypertune` has been replaced with a `token` field. - If you're using Vercel Edge Config, you need to pass a `vercelEdgeConfigItemKey` in the initialize options too. ### Features - Added `includeToken` codegen option so you can opt out of including your token in the generated code. - Added `includeFallback` codegen option so you can opt out of embedding the build time snapshot in the generated code. ## 1.4.12 - React native improvements. ## 1.4.7 - Improved retry behaviour. ## 1.4.5 - Bug fixes and improvements. ## 1.4.0 ### Breaking changes - Removed `enableConsoleDebugLogging` SDK initialization option. ### Features - Added support for initializing from Vercel Edge Config. ## 1.3.0 No breaking changes from 1.2.30. ### Features - Added support for personalization splits.