@malible/distribution
Official library for the Malible distribution APIs, written inTypeScript.
All classes and APIs are one-to-one with Malibleofficial malible
Requirements
- Node.js v14+
Installation
npm
npm install @malible/distributionyarn
yarn add @malible/distributionUsage
import { MalibleDistribution } from '@malible/distribution';
const malibleDistribution = new MalibleDistribution({
apiKey: "YOUR_API_KEY", //Required
workspaceId: "YOUR_WORKSPACE_ID", //Required,
baseURL: "BASE_URL", //Optional,
timeout: "API_TIMEOUT", //Optional,
privateKeys: "PRIVATE_KEYS", //Optional,
debug: "DEBUG_LOGS?", //Optional,
});
// Get complete manifest for workspace
try {
const manifest = await malibleDistribution.getManifest();
console.log('manifest ', manifest);
} catch (error) {
console.error('Error while fetching manifest', error);
}
// Get all pages from workspace
try {
const pages = await malibleDistribution.getPages();
console.log('pages ', pages);
} catch (error) {
console.error('Error while fetching pages', error);
}
// Get page from workspace
try {
const page = await malibleDistribution.getPageById('PAGE_ID');
console.log('page ', page);
} catch (error) {
console.error('Error while fetching page', error);
}
// Get settings from workspace
try {
const settings = await malibleDistribution.getSettings();
console.log('settings ', settings);
} catch (error) {
console.error('Error while fetching settings', error);
}
// Get setting from workspace
try {
const setting = await malibleDistribution.getSettingId('SETTING_ID');
console.log('setting ', setting);
} catch (error) {
console.error('Error while fetching setting', error);
}
// Get secrets from workspace
try {
const secrets = await malibleDistribution.getSecrets();
console.log('secrets ', secrets);
} catch (error) {
console.error('Error while fetching secrets', error);
}
// Get secret from workspace
try {
const secret = await malibleDistribution.getSecret('SECRET_ID');
console.log('secret ', secret);
} catch (error) {
console.error('Error while fetching secret', error);
}
// Get client segments from workspace
try {
const segments = await malibleDistribution.getClientSegments('UNIQUE_CLIENT_ID');
console.log('segments ', segments);
} catch (error) {
console.error('Error while fetching segments', error);
}
// Post client attributes for workspace
try {
const isAttributedAdded = await malibleDistribution
.postClientAttribute('UNIQUE_CLIENT_ID', 'user', { gender: 'male' });
console.log('isAttributedAdded ', isAttributedAdded);
} catch (error) {
console.error('Error while posting attributes', error);
}
// Get client attributes from workspace
try {
const attributes = await malibleDistribution.getClientAttribute('UNIQUE_CLIENT_ID', 'user');
console.log('attributes ', attributes);
} catch (error) {
console.error('Error while fetching attributes', error);
}
// Post client daily active stat (DAU) for workspace
try {
const isDAUAdded = await malibleDistribution.putClientLastLogin('UNIQUE_CLIENT_ID');
console.log('isDAUAdded ', isDAUAdded);
} catch (error) {
console.error('Error while posting DAU', error);
}
Manifest based on client segments and A/B testing
// Get complete manifest for workspace based on clientId
try {
//SDK will handle different variants, A/B variants also will be managed by SDK
const manifest = await malibleDistribution.getManifest('CLIENT_ID');
console.log('manifest ', manifest);
} catch (error) {
console.error('Error while fetching segmented manifest', error);
}
Note
Internally, @malible/distribution uses a cache mechanism for API responses, which are cached for one minute, to bypass the cache value pass useCache=true
Sample code for useCache
import { MalibleDistribution } from '@malible/distribution';
const malibleDistribution = new MalibleDistribution({
apiKey: "YOUR_API_KEY",
workspaceId: "YOUR_WORKSPACE_ID",
});
// Get all pages from workspace, override cache response
try {
const pages = await malibleDistribution.getPages(false);
console.log('pages ', pages);
} catch (error) {
console.error('Error while fetching pages', error);
}
// Get page from workspace, override cache response
try {
const page = await malibleDistribution.getPageById('PAGE_ID', false);
console.log('page ', page);
} catch (error) {
console.error('Error while fetching page', error);
}
Set API Polling
Note:An active subscription is required for this feature.
Steps:
Navigate to the Malible portal:
link

