TypeScript SDK
አንድ ጥቅል ከስድስት መግቢያ ነጥቦች ጋር። ከአሠራርዎ ጋር የሚስማማውን ያስመጡ፣ የዛፍ-መንቀጥቀጥ ግንባታውም ቀሪውን ከጥቅልዎ ውጭ ይተዋል።
የታተመበት
@prodantix/sdk on npm.
ጫን
bun add @prodantix/sdkየመግቢያ ነጥቦች
እያንዳንዱ ንዑስ መንገድ የራሱን የESM እና CommonJS ግንባታ ከራሱ ዓይነቶች ጋር ያቀርባል። ሥሩ ከአሠራር ነጻ ነው፣ ሌሎቹ ደግሞ አንድ አሠራር የሚፈልገውን ይጨምራሉ።
| Subpath | What it exports |
|---|---|
| @prodantix/sdk | ProdantixClient, createClient, evaluateFlag, FlagsClient, MessagesClient |
| @prodantix/sdk/web | createWebClient, installAutocapture, installSessionReplay, WebTransport |
| @prodantix/sdk/node | createNodeClient |
| @prodantix/sdk/csp | prodantixConnectSrc, prodantixScriptSrc |
| @prodantix/sdk/chat | mountChat, ChatClient, ChatPanel, resolveAppearance |
| @prodantix/sdk/messenger | fetchMessengerConfig, cachedMessengerConfig, MESSENGER_CACHE_KEY |
@prodantix/sdk
ደንበኛው፣ የባንዲራ ገማቹ፣ እና የማከማቻና የመጓጓዣ በይነገጾች። እዚህ ምንም ነገር DOMን አይነካም፣ ስለዚህ የራስዎን ማከማቻ፣ መጓጓዣ፣ ሰዓት ወይም መለያ ፋብሪካ አቅርበው በየትም ማሄድ ይችላሉ።
import { createClient, MemoryStorage } from '@prodantix/sdk';
const prodantix = createClient({
apiKey: PRODANTIX_PUBLIC_KEY,
host: 'https://eu.api.prodantix.com',
storage: new MemoryStorage(),
});
prodantix.capture('order.completed', { properties: { amount: 4200, currency: 'XAF' } });
await prodantix.flush();@prodantix/sdk/web
በዚያው ደንበኛ ላይ የአሳሽ ዝርጋታ፦ በአካባቢ ማከማቻ ውስጥ መቆየት፣ ገጹ ሲደበቅ በምልክት ማድረሻ ማድረስ፣ እና የገጽ እይታ እንዲሁም የጠቅታ ራስ-ቀረጻ። የክፍለ ጊዜ ድግግሞሽ የድግግሞሽ አስተናጋጅ እስኪሰጡት ድረስ ጠፍቶ ይቆያል።
import { createWebClient } from '@prodantix/sdk/web';
const prodantix = createWebClient({
apiKey: PRODANTIX_PUBLIC_KEY,
host: 'https://eu.api.prodantix.com',
flagsHost: 'https://api.prodantix.com',
autocaptureOptions: { clicks: true, pageviews: true },
});
prodantix.identify('user-42', { set: { plan: 'pro' } });
if (await prodantix.isFeatureEnabled('new-checkout')) {
// ...
}
// Every per-flag read records one $feature_flag_called exposure.
const variant = await prodantix.getVariant('new-checkout');
if (variant?.key === 'treatment') {
// ...
}
// A flag targeting a cohort reads this user's memberships from the store;
// pass them yourself to skip the lookup.
if (await prodantix.isFeatureEnabledLocal('members', { cohorts: ['<cohort id>'] })) {
// ...
}@prodantix/sdk/node
ተመሳሳዩ ደንበኛ በአገልጋይ ነባሪዎች። ክስተቶች ተከማችተው በጀርባ ይላካሉ፣ ስለዚህ ሂደቱ ከመውጣቱ በፊት shutdown ይጥሩ፣ አለበለዚያ የመጨረሻው ጥቅል ፈጽሞ አይወጣም።
import { createNodeClient } from '@prodantix/sdk/node';
// A node client streams flag changes over Socket.IO by default and refetches
// the snapshot on push; streamFlags: false leaves only the 30s poll.
const prodantix = createNodeClient({
apiKey: process.env.PRODANTIX_PUBLIC_KEY,
host: 'https://eu.api.prodantix.com',
streamFlags: true,
});
prodantix.capture('job.completed', { properties: { queue: 'emails' } });
await prodantix.shutdown();@prodantix/sdk/csp
አንድ መተግበሪያ Prodantixን ለመድረስ የሚያስፈልጉት የይዘት ደህንነት ፖሊሲ ምንጮች። ከReact ወይም ከአሳሽ ምንም አያስመጣም፣ ስለዚህ የግንባታ ውቅር ፋይል በቀጥታ ሊያነበው ይችላል።
import { prodantixConnectSrc, prodantixScriptSrc } from '@prodantix/sdk/csp';
const hosts = {
ingest: 'https://eu.api.prodantix.com',
edge: 'https://eu.edge.prodantix.com',
replay: 'https://eu.replay.prodantix.com',
};
const policy = [
`connect-src ${prodantixConnectSrc(hosts)}`,
`script-src ${prodantixScriptSrc(hosts)}`,
].join('; ');@prodantix/sdk/chat
የድጋፍ መግብር። ይጫኑት እና የሚከፍት፣ የሚዘጋ፣ የሚያጠፋ እና የሚለይ እጀታ ያገኛሉ። በተዘጋ የጥላ ሥር ውስጥ ስለሚሣል የአስተናጋጁ ገጽ ቅጦች ፈጽሞ አይደርሱበትም።
import { mountChat } from '@prodantix/sdk/chat';
const messenger = mountChat({
apiKey: PRODANTIX_PUBLIC_KEY,
host: 'https://eu.edge.prodantix.com',
distinctId: prodantix.distinctId,
});
document.querySelector('#help')?.addEventListener('click', () => messenger.open());@prodantix/sdk/messenger
ከመግብሩ ጀርባ ያለው የቅንብር አንባቢ፦ የአንድ ፕሮጀክት የመልእክተኛ ውቅር ያመጣል፣ ያከማቻል፣ እና ፕሮጀክቱ መልእክተኛውን አብርቶት እንደሆነ ይነግርዎታል። በራሱ የሚሠራው የቁራጭ ግንባታ ለብቻው ይገነባል፣ በዚህ ንዑስ መንገድም አይደረስም።
import { fetchMessengerConfig } from '@prodantix/sdk/messenger';
const config = await fetchMessengerConfig({
apiKey: PRODANTIX_PUBLIC_KEY,
host: 'https://eu.edge.prodantix.com',
});
if (config?.enabled) {
// the project has the messenger switched on
}