حزمة TypeScript
حزمة واحدة بستة مداخل. استورد المدخل الذي يناسب بيئة التشغيل لديك، وسيترك بناء إزالة الشيفرة غير المستخدمة البقية خارج حزمتك.
مكان النشر
@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
}