| 9 | const edgeConfigClient = createClient(process.env.EDGE_CONFIG) |
| 10 | |
| 11 | export async function createSplitClient(userKey: string) { |
| 12 | const client = SplitFactory({ |
| 13 | core: { |
| 14 | authorizationKey: process.env.SPLIT_SDK_CLIENT_API_KEY!, |
| 15 | key: userKey, |
| 16 | }, |
| 17 | mode: 'consumer_partial', |
| 18 | storage: PluggableStorage({ |
| 19 | wrapper: EdgeConfigWrapper({ |
| 20 | // The Edge Config item where Split stores feature flag definitions, specified in the Split integration step |
| 21 | edgeConfigItemKey: process.env.EDGE_CONFIG_SPLIT_ITEM_KEY!, |
| 22 | edgeConfig: edgeConfigClient, |
| 23 | }), |
| 24 | }), |
| 25 | // Disable or keep only ERROR log level in production, to minimize performance impact |
| 26 | debug: ErrorLogger(), |
| 27 | }).client() |
| 28 | |
| 29 | // Wait to load feature flag definitions from the Edge Config |
| 30 | await client.ready() |
| 31 | |
| 32 | return client |
| 33 | } |