growthbook
Version:
The GrowthBook command-line interface (CLI) for working with the GrowthBook A/B testing, feature flagging, and experimentation platform
49 lines (48 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchAllPaginatedFeatures = exports.getFeatureValueTypeToTypeScriptMapping = void 0;
const features_repository_1 = require("../repositories/features.repository");
/**
* Maps a GrowthBook value type to a TypeScript type
* @param valueType GrowthBook value type
* @return {string} TypeScript type
*/
const getFeatureValueTypeToTypeScriptMapping = (valueType) => {
switch (valueType) {
case 'boolean':
case 'number':
case 'string':
return valueType;
case 'json':
return 'Record<string, unknown>';
default:
return 'unknown';
}
};
exports.getFeatureValueTypeToTypeScriptMapping = getFeatureValueTypeToTypeScriptMapping;
/**
* Fetches all the features from the GrowthBook REST API for the provided API base URL.
* @param apiBaseUrl The API base URL for the target GrowthBook instance
* @param token Secret token
* @param projectId Optional project ID filter
* @return {Promise<SimplifiedFeature[]>} A list of features
*/
const fetchAllPaginatedFeatures = async (apiBaseUrl, token, projectId) => {
const limit = 100;
let offset = 0;
let allFeatures = [];
let shouldFetch = true;
const featuresRepo = new features_repository_1.FeaturesRepository({
apiKey: token,
apiBaseUrl,
});
while (shouldFetch) {
const response = await featuresRepo.listFeatures(limit, offset, projectId);
const { nextOffset, hasMore, features } = response;
allFeatures = [...allFeatures, ...features];
offset = nextOffset;
shouldFetch = hasMore;
}
return allFeatures;
};
exports.fetchAllPaginatedFeatures = fetchAllPaginatedFeatures;