تخطَّ إلى المحتوى الرئيسي

محوّلات أطر العمل

حزمة TypeScript

حزمة واحدة بستة مداخل. استورد المدخل الذي يناسب بيئة التشغيل لديك، وسيترك بناء إزالة الشيفرة غير المستخدمة البقية خارج حزمتك.

مكان النشر

@prodantix/sdk on npm.

التثبيت

Bash
bun add @prodantix/sdk

مداخل الحزمة

كل مسار فرعي يقدّم بناءه الخاص بصيغتي ESM وCommonJS مع أنواعه الخاصة. الجذر مستقل عن بيئة التشغيل، والبقية تضيف ما تحتاجه بيئة بعينها.

SubpathWhat it exports
@prodantix/sdkProdantixClient, createClient, evaluateFlag, FlagsClient, MessagesClient
@prodantix/sdk/webcreateWebClient, installAutocapture, installSessionReplay, WebTransport
@prodantix/sdk/nodecreateNodeClient
@prodantix/sdk/cspprodantixConnectSrc, prodantixScriptSrc
@prodantix/sdk/chatmountChat, ChatClient, ChatPanel, resolveAppearance
@prodantix/sdk/messengerfetchMessengerConfig, cachedMessengerConfig, MESSENGER_CACHE_KEY

@prodantix/sdk

العميل، ومقيّم الرايات، وواجهتا التخزين والنقل. لا شيء هنا يلمس DOM، فيمكنك تمرير تخزينك أو نقلك أو ساعتك أو مولّد المعرّفات الخاص بك وتشغيله في أي مكان.

TypeScript
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

تجهيزات المتصفح فوق العميل نفسه: الحفظ في التخزين المحلي، والإرسال عبر منارة حين تُخفى الصفحة، والالتقاط التلقائي لمشاهدات الصفحات والنقرات. ويبقى تسجيل الجلسة معطلًا حتى تمنحه مضيف التسجيل.

TypeScript
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 قبل خروج العملية وإلا فلن تغادر الدفعة الأخيرة أبدًا.

TypeScript
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 ولا من المتصفح، فيستطيع ملف إعداد البناء قراءته مباشرة.

TypeScript
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

أداة الدعم. ركّبها فتحصل على مقبض يفتحها ويغلقها ويتلفها ويعرّف المستخدم. تُرسم داخل جذر ظل مغلق، فلا تصل إليها أنماط الصفحة المضيفة أبدًا.

TypeScript
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

قارئ الإعدادات خلف الأداة: يجلب إعدادات المراسل لمشروع، ويخزّنها مؤقتًا، ويخبرك إن كان المشروع قد فعّل المراسل. أما قصاصة التشغيل الذاتي فتُبنى على حدة ولا يمكن الوصول إليها عبر هذا المسار الفرعي.

TypeScript
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
}