Chuyển đến nội dung chính

Bộ điều hợp framework

SDK TypeScript

Một gói với sáu điểm vào. Hãy nhập điểm phù hợp với môi trường chạy của bạn, và bản dựng rung cây sẽ để phần còn lại ngoài bundle.

Nơi phát hành

@prodantix/sdk on npm.

Cài đặt

Bash
bun add @prodantix/sdk

Các điểm vào

Mỗi đường dẫn con đi kèm bản dựng ESM và CommonJS riêng cùng kiểu dữ liệu riêng. Gốc không phụ thuộc môi trường chạy, các phần còn lại bổ sung thứ mà một môi trường cụ thể cần.

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

Client, bộ đánh giá cờ, cùng các giao diện lưu trữ và truyền tải. Không phần nào ở đây chạm vào DOM, nên bạn có thể cung cấp lưu trữ, truyền tải, đồng hồ hay bộ sinh id của riêng mình và chạy ở bất cứ đâu.

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

Phần đấu nối trình duyệt đặt trên cùng client đó: lưu trong local storage, gửi bằng beacon khi trang bị ẩn, cùng việc tự động thu pageview và cú nhấp. Phát lại phiên vẫn tắt cho tới khi bạn cung cấp máy chủ phát lại.

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

Vẫn client đó nhưng với mặc định phía máy chủ. Sự kiện được đệm lại và gửi đi ở nền, nên hãy gọi shutdown trước khi tiến trình thoát, nếu không lô cuối cùng sẽ không bao giờ rời đi.

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

Các nguồn của chính sách bảo mật nội dung mà một ứng dụng cần để tới được Prodantix. Nó không nhập gì từ React hay trình duyệt, nên tệp cấu hình bản dựng có thể đọc trực tiếp.

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

Tiện ích hỗ trợ. Gắn nó vào và bạn nhận một handle để mở, đóng, huỷ và định danh người dùng. Nó dựng bên trong một shadow root đóng, nên kiểu dáng của trang chủ nhà không bao giờ chạm tới.

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

Bộ đọc cấu hình phía sau tiện ích: nó lấy cấu hình trình nhắn tin của một dự án, lưu đệm, và cho biết dự án đã bật trình nhắn tin hay chưa. Đoạn mã tự chạy được dựng riêng và không thể lấy qua đường dẫn con này.

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
}