SDK ya TypeScript
Kifurushi kimoja chenye vituo sita vya kuingilia. Ingiza kile kinacholingana na mazingira yako, na ujenzi wa kutikisa mti utaacha vingine nje ya kifurushi chako.
Ilipochapishwa
@prodantix/sdk on npm.
Sakinisha
bun add @prodantix/sdkVituo vya kuingilia
Kila njia ndogo huja na ujenzi wake wa ESM na CommonJS pamoja na aina zake. Kiini hakitegemei mazingira ya utekelezaji, na vingine huongeza kile ambacho mazingira mahususi yanahitaji.
| 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
Mteja, kipima bendera, na violesura vya hifadhi na usafirishaji. Hakuna kitu hapa kinachogusa DOM, hivyo unaweza kutoa hifadhi, usafirishaji, saa au kiwanda chako cha vitambulisho na kukiendesha popote.
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
Uunganishaji wa kivinjari juu ya mteja yule yule: kuhifadhi katika hifadhi ya ndani, kuwasilisha kwa kinara wakati ukurasa unapofichwa, na kunasa kiotomatiki mionekano ya kurasa na mibofyo. Urudiaji wa kipindi hubaki umezimwa hadi umpe mwenyeji wa urudiaji.
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
Mteja yule yule mwenye chaguo-msingi za seva. Matukio huhifadhiwa kwenye bafa na kutumwa chinichini, hivyo ita shutdown kabla mchakato haujaisha, la sivyo fungu la mwisho halitatoka kamwe.
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
Vyanzo vya sera ya usalama wa maudhui ambavyo programu inahitaji ili kufikia Prodantix. Haileti chochote kutoka React wala kivinjari, hivyo faili la usanidi wa ujenzi linaweza kuisoma moja kwa moja.
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
Kidirisha cha msaada. Kikiweke na utapata kishikizo kinachofungua, kinachofunga, kinachoharibu na kinachotambulisha mtumiaji. Huchorwa ndani ya kiini kivuli kilichofungwa, hivyo mitindo ya ukurasa mwenyeji haifiki kamwe.
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
Msomaji wa mipangilio nyuma ya kidirisha: huleta usanidi wa mjumbe wa mradi, huuhifadhi katika akiba, na hueleza kama mradi umewasha mjumbe. Kipande kinachojiendesha hujengwa kando na hakifikiki kupitia njia hii ndogo.
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
}