旗子 SDK — 超调谐提供者
设置
Hypertune 提供者在 @flags-sdk/hypertune 模块。 你可以安装它
pnpm i @flags-sdk/hypertune
提供者实例
您必须使用由 : npx hypertune 创建适配器实例.
使用 createHypertuneAdapter 从 @flags-sdk/hypertune 如下所示:
import { createHypertuneAdapter } from "@flags-sdk/hypertune";
import { Identify } from "flags";
import { dedupe, flag } from "flags/next";
/** Generated with `npx hypertune` */
import {
createSource,
flagFallbacks,
vercelFlagDefinitions as flagDefinitions,
Context,
FlagValues,
} from "./generated/hypertune";
const identify: Identify<Context> = dedupe(async ({ headers, cookies }) => {
return {
environment: process.env.NODE_ENV,
user: {
id: "e23cc9a8-0287-40aa-8500-6802df91e56a",
name: "Example User",
email: "[email protected]",
},
};
});
const hypertuneAdapter = createHypertuneAdapter<FlagValues, Context>({
createSource,
flagFallbacks,
flagDefinitions,
identify,
});
/** Use the adapter to generate flag declarations for use in your app's framework */
export const showSummerBannerFlag = flag(
hypertuneAdapter.declarations.summerSale,
);
export const showFreeDeliveryBannerFlag = flag(
hypertuneAdapter.declarations.freeDelivery,
);
export const proceedToCheckoutColorFlag = flag(
hypertuneAdapter.declarations.proceedToCheckout,
);
/**
* NOTE: You can provide specific options for flag overrides.
*
* However, using enums in Hypertune will provide these automatically.
*/
export const delayFlag = flag({
...hypertuneAdapter.declarations.delay,
options: [
{ value: 0, label: "No delay" },
{ value: 1_000, label: "1 second" },
{ value: 2_000, label: "2 seconds" },
{ value: 3_000, label: "3 seconds" },
],
});
需要的环境变量
# Required
NEXT_PUBLIC_HYPERTUNE_TOKEN="123="
# For use with precompute, encrypted flag values, overrides, and the Flags Explorer
FLAGS_SECRET="ReplaceThisWith32RandomBytesBase64UrlString"
# Optional: automatically configure with a VercelGlobalConfigInitDataProvider
EXPERIMENTATION_CONFIG="ecfg_abc"
EXPERIMENTATION_CONFIG_ITEM_KEY="hypertune_xyz"
文档
请检查一下 超调解调器引用 更多信息.