/** * # Realtime API JavaScript client * * The public API of the client. Consumers configure the client with * {@link permutive}, then {@link Permutive.openSession} opens a session and * resolves the {@link Session} it runs: declare the * {@link Context}, run imperative commands ({@link Session.identify}, * {@link Session.track}), and * observe the replicated {@link SessionState}. Read cohorts out of that state * with {@link getCohorts} / {@link getActivation}. * * The {@link Transport} is an internal detail, but it is exported so a custom * one can be injected in place of the default {@link WebSocketTransport} — * e.g. {@link Http1Transport}, the serial-POST fallback for environments * that cannot hold a WebSocket. Only the transport you import is bundled. * * ## Getting Started * * Imperative calls resolve a {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise | PromiseLike}: * a modern client can `await` them; an ES5 client with no `Promise` runtime * drives the same value with `.then(onFulfilled, onRejected)`. * * ```ts * permutive({ apiKey: 'pk_…' }) * .openSession() * .then( * session => { * // An imperative command: each method resolves with its typed result. * session * .identify({ identities: [{ tag: 'email', id: 'a@b.c' }] }) * .then(result => console.log(result.output.user_id)) * * // Observe every applied fold of session-state. * session.onStateChange(change => { * console.log(getCohorts(change.current)) * }) * }, * error => console.error(error), * ) * ``` */ export { permutive } from './session.js'; export type { Permutive, Session, PermutiveConfig, OpenSessionOptions, } from './session.js'; export { getActivation, getCohorts } from './model.js'; export type { Context, SessionState, SessionStateChanged, CohortsAndActivations, Identity, Properties, Command, Result, DomainFailure, CommandOutput, CommandType, CommandRegistry, } from './model.js'; export type { Delta } from './merge.js'; export { webSocketTransport as WebSocketTransport } from './channel/websocket.js'; export { http1Transport as Http1Transport } from './channel/http1.js'; export type { Http1TransportOptions } from './channel/http1.js'; export type { Close, Transport, Connection } from './channel/transport.js';