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
47 lines (38 loc) • 1.19 kB
text/typescript
import { InitData, InitDataProvider } from "../../shared/types";
import parseInitResponse from "../parseInitResponse";
export default class VercelEdgeConfigInitDataProvider
implements InitDataProvider
{
private readonly edgeConfigClient: { get: (key: string) => Promise<any> };
private readonly itemKey: string;
constructor({
edgeConfigClient,
itemKey,
}: {
edgeConfigClient: { get: (key: string) => Promise<any> };
itemKey: string;
}) {
this.edgeConfigClient = edgeConfigClient;
this.itemKey = itemKey;
}
// eslint-disable-next-line class-methods-use-this
getName(): string {
return "Vercel Edge Config";
}
async getInitData(): Promise<InitData> {
const rawResponse = await this.edgeConfigClient.get(this.itemKey);
if (!rawResponse) {
throw new Error(`[initFromEdgeConfig] no value for key ${this.itemKey}`);
}
const response =
typeof rawResponse === "string"
? parseInitResponse(rawResponse)
: rawResponse;
if (!response.commitId) {
throw new Error(
`[initFromEdgeConfig] unexpected response: ${JSON.stringify(response)}`
);
}
return response;
}
}