UNPKG

@flags-sdk/openfeature

Version:

OpenFeature provider for the Flags SDK

92 lines 2.11 kB
// src/index.ts function createOpenFeatureAdapter(init) { let client = typeof init === "function" ? null : init; let clientPromise; async function initialize() { if (client) return client; if (clientPromise) return clientPromise; clientPromise = typeof init === "function" ? init() : Promise.resolve(init); client = await clientPromise; return clientPromise; } function booleanValue(options) { return { async decide({ key, entities, defaultValue }) { await initialize(); if (!client) return defaultValue; return client.getBooleanValue( key, defaultValue, entities, options ); } }; } function stringValue(options) { return { async decide({ key, entities, defaultValue }) { await initialize(); if (!client) return defaultValue; return client.getStringValue( key, defaultValue, entities, options ); } }; } function numberValue(options) { return { async decide({ key, entities, defaultValue }) { await initialize(); if (!client) return defaultValue; return client.getNumberValue( key, defaultValue, entities, options ); } }; } function objectValue(options) { return { async decide({ key, entities, defaultValue }) { await initialize(); if (!client) return defaultValue; return client.getObjectValue( key, defaultValue, entities, options ); } }; } return { booleanValue, stringValue, numberValue, objectValue, client: typeof init === "function" ? async () => { await initialize(); if (!client) throw new Error( "@flags-sdk/openfeature: OpenFeature client failed to initialize" ); return client; } : init }; } export { createOpenFeatureAdapter }; //# sourceMappingURL=index.js.map