@microsoft/rayfin-client package

Classes

AuthError

Error specifically for issues related to authentication.

ClientCompositionError

A composition failure retaining its original cause and any cleanup failures. Configuration and tokens are never included in the error message.

NetworkError

Error for network-related issues (e.g., API unreachable, bad response).

RayfinClient

One application client, composed from independently typed capabilities.

Example

const client = RayfinClient.create({
  baseUrl: 'https://app.example/backend',
  publishableKey: 'pk-example',
  auth: suppliedToken({ accessToken: () => currentToken }),
  services: {
    reports: (http) => ({
      load: () => http.get('/reports'),
    }),
  },
});
await client.reports.load();
client.dispose();
RayfinConfigError

Error thrown when runtime configuration loading fails.

SdkError

Base custom error for the SDK. All other custom errors should extend this.

Interfaces

ApiClientConfig

Interface for API Client configuration. Includes an optional function to retrieve the access token dynamically.

ClientLifecycle

Resource ownership for a composed client. Register local, synchronous cleanup as soon as a resource is acquired.

RayfinClientConfig

Configuration for RayfinClient.create.

Select authentication explicitly and register services from their owning packages. Session options belong to the authentication adapter, not here.

RayfinRuntimeConfig

All rayfin.config.json values as a single optional-field bag — every field is optional because neither the remote config nor a caller-supplied set of defaults is guaranteed to provide it. Used both as the defaults shape (typically build-time VITE_* values) and as the resolved shape returned by resolveRayfinConfig.

ResolveRayfinConfigOptions

Options controlling how resolveRayfinConfig fetches remote runtime configuration. To skip remote loading entirely, don't call it — construct the client directly from your own values instead.

SuppliedTokenOptions

Options for externally supplied tokens, including per-request token rotation.

Type Aliases

ClientAuthFactory

Attaches an authentication mode to a composed client's HTTP transport. Return the session API to expose as client.auth, or undefined for supplied-token authentication without a session API.

ClientServiceApis

Readonly service APIs inferred from their registered factories.

ClientServiceFactory

Creates a service using the composed client's authenticated HTTP transport.

A factory must return synchronously; promise-like service types are excluded from its result. A plain (http) => service function is sufficient when the service owns no resources requiring cleanup.

ClientServices

Service factories keyed by the namespaces they expose on a client.

ComposedRayfinClient

A composed client with exactly its registered services and session API.

ReservedServiceName

Names owned by the client, object prototype, or JavaScript promise protocol.

ValidClientServices

Validates service names and excludes asynchronous factory results.

Functions

isDeprecationSilenced()

Whether deprecation warnings are currently silenced.

Precedence: an explicit setDeprecationsSilenced override wins; otherwise the RAYFIN_NO_DEPRECATION environment variable ('1' or 'true', case-insensitive) silences; otherwise warnings are emitted.

resolveRayfinConfig(Pick<RayfinRuntimeConfig, "publishableKey" | "apiUrl"> & Partial<RayfinRuntimeConfig>, ResolveRayfinConfigOptions)

Resolves the config a RayfinClient should be constructed with: loads the remote rayfin.config.json (unless the caller skips calling this function entirely), overlays it over the supplied defaults per-field, and returns the merged baseUrl / publishableKey / runtimeConfig. Construction itself is a plain, synchronous RayfinClient.create(...) call — this function only resolves values.

Example

import {
  RayfinClient,
  RayfinConfigError,
  resolveRayfinConfig,
} from '@microsoft/rayfin-client';
import { browserSession } from '@microsoft/rayfin-auth';

const resolved = await resolveRayfinConfig({
  apiUrl: 'https://your-backend.example.com',
  publishableKey: 'your-publishable-key',
});
const { baseUrl, publishableKey, runtimeConfig } = resolved;
if (typeof baseUrl !== 'string') {
  throw new RayfinConfigError('Configure a Rayfin backend URL.', 'CONFIG_INCOMPLETE');
}
if (typeof publishableKey !== 'string' || !publishableKey.trim()) {
  throw new RayfinConfigError('Configure a Rayfin publishable key.', 'CONFIG_INCOMPLETE');
}
const client = RayfinClient.create({
  baseUrl,
  publishableKey,
  runtimeConfig,
  auth: browserSession(),
});
setDeprecationsSilenced(boolean)

Programmatically silence or unsilence all deprecation warnings. This override takes precedence over the RAYFIN_NO_DEPRECATION environment variable and is the browser-safe way to quiet warnings.

suppliedToken(SuppliedTokenOptions)

Authenticate without creating a browser session or exposing client.auth. Token refresh and rotation remain the supplied provider's responsibility. Providers are called per request, not during synchronous client construction. Provider failures reject the request before it is sent.

Function Details

isDeprecationSilenced()

Whether deprecation warnings are currently silenced.

Precedence: an explicit setDeprecationsSilenced override wins; otherwise the RAYFIN_NO_DEPRECATION environment variable ('1' or 'true', case-insensitive) silences; otherwise warnings are emitted.

function isDeprecationSilenced(): boolean

Returns

boolean

resolveRayfinConfig(Pick<RayfinRuntimeConfig, "publishableKey" | "apiUrl"> & Partial<RayfinRuntimeConfig>, ResolveRayfinConfigOptions)

Resolves the config a RayfinClient should be constructed with: loads the remote rayfin.config.json (unless the caller skips calling this function entirely), overlays it over the supplied defaults per-field, and returns the merged baseUrl / publishableKey / runtimeConfig. Construction itself is a plain, synchronous RayfinClient.create(...) call — this function only resolves values.

Example

import {
  RayfinClient,
  RayfinConfigError,
  resolveRayfinConfig,
} from '@microsoft/rayfin-client';
import { browserSession } from '@microsoft/rayfin-auth';

const resolved = await resolveRayfinConfig({
  apiUrl: 'https://your-backend.example.com',
  publishableKey: 'your-publishable-key',
});
const { baseUrl, publishableKey, runtimeConfig } = resolved;
if (typeof baseUrl !== 'string') {
  throw new RayfinConfigError('Configure a Rayfin backend URL.', 'CONFIG_INCOMPLETE');
}
if (typeof publishableKey !== 'string' || !publishableKey.trim()) {
  throw new RayfinConfigError('Configure a Rayfin publishable key.', 'CONFIG_INCOMPLETE');
}
const client = RayfinClient.create({
  baseUrl,
  publishableKey,
  runtimeConfig,
  auth: browserSession(),
});
function resolveRayfinConfig(defaults: Pick<RayfinRuntimeConfig, "publishableKey" | "apiUrl"> & Partial<RayfinRuntimeConfig>, options?: ResolveRayfinConfigOptions): Promise<{ baseUrl?: string, publishableKey?: string, runtimeConfig: RayfinRuntimeConfig }>

Parameters

defaults

Pick<RayfinRuntimeConfig, "publishableKey" | "apiUrl"> & Partial<RayfinRuntimeConfig>

Returns

Promise<{ baseUrl?: string, publishableKey?: string, runtimeConfig: RayfinRuntimeConfig }>

setDeprecationsSilenced(boolean)

Programmatically silence or unsilence all deprecation warnings. This override takes precedence over the RAYFIN_NO_DEPRECATION environment variable and is the browser-safe way to quiet warnings.

function setDeprecationsSilenced(silenced: boolean)

Parameters

silenced

boolean

true to suppress all deprecation warnings, false to re-enable them.

suppliedToken(SuppliedTokenOptions)

Authenticate without creating a browser session or exposing client.auth. Token refresh and rotation remain the supplied provider's responsibility. Providers are called per request, not during synchronous client construction. Provider failures reject the request before it is sent.

function suppliedToken(options?: SuppliedTokenOptions): ClientAuthFactory<undefined>

Parameters

Returns

ClientAuthFactory<undefined>