@microsoft/rayfin-functions
SDK reference for functionsService, FunctionClient, FunctionsSchema, InvokeOptions, FunctionsError, and typed client.functions invocations.
@microsoft/rayfin-functions is the client-side SDK package behind client.functions.<name>.invoke(...). Server-side function authoring uses @microsoft/fabric-user-data-functions; see Writing a function.
Installation
Install the package in every app that calls functions, at the same version as @microsoft/rayfin-client. In 1.x the client pulled it in; the 2.0 client depends only on @microsoft/rayfin-lib.
npm install @microsoft/rayfin-functions@2.0.0Exports
| Export | Kind | Purpose |
|---|---|---|
functionsService<TSchema>() | Function | Registers typed client.functions on a client built with RayfinClient.create. New in 2.0 |
FunctionClient<TInput, TOutput> | Class | Client for one named function. |
FunctionsError | Class | Function invocation error extending SdkError. |
createFunctionsApi<TSchema>(apiClient) | Function | Creates the typed functions proxy for code that already owns an ApiClient. |
FunctionInvocationResponse<TOutput> | Type | Transport envelope returned by the backend before invoke() unwraps output. |
InvokeOptions | Type | Per-call headers and timeout. |
FunctionsSchema | Type | Map of function names to { input, output }. Import it from this package; @microsoft/rayfin-client no longer re-exports it. Changed in 2.0 |
TypedFunctionClients<TSchema> | Type | Map from schema keys to typed FunctionClient instances. |
functionsService
function functionsService<TSchema extends FunctionsSchema>(): ClientServiceFactory<
TypedFunctionClients<TSchema>
>;Register the factory under services when you create the client. The key you choose becomes the namespace on the client; use functions:
import { RayfinClient } from '@microsoft/rayfin-client';
import { browserSession } from '@microsoft/rayfin-auth';
import { dataService } from '@microsoft/rayfin-data';
import { functionsService } from '@microsoft/rayfin-functions';
import type { AppSchema } from '../../rayfin/data/schema';
import type { AppFunctionsSchema } from '../../rayfin/functions/src/types';
export const rayfinClient = RayfinClient.create({
baseUrl: import.meta.env.VITE_RAYFIN_API_URL,
publishableKey: import.meta.env.VITE_RAYFIN_PUBLISHABLE_KEY,
auth: browserSession({ storage: true }),
services: {
data: dataService<AppSchema>(),
functions: functionsService<AppFunctionsSchema>(),
},
});
export type AppClient = typeof rayfinClient;The service uses the client's shared, authenticated transport and delegates to createFunctionsApi. Set functionsBaseUrl on RayfinClient.create to change function routing only; data, connectors, and storage keep using baseUrl. It replaces 1.x's new RayfinClient<AppSchema, AppFunctionsSchema>(...); see Migrate from 1.x.
FunctionsSchema
type FunctionsSchema = Record<string, { input: any; output: any }>;Generated projects export an AppFunctionsSchema from rayfin/functions/src/types.ts:
export type AppFunctionsSchema = {
greet: {
input: { firstName: string; lastName: string };
output: string;
};
getEntries: {
input: Record<string, never>;
output: { id: string; message: string }[];
};
};Pass that schema as the type argument of functionsService<AppFunctionsSchema>(). Schemas provide compile-time types only; they do not validate inputs or outputs at run time.
FunctionClient
class FunctionClient<TInput = any, TOutput = any> {
constructor(apiClient: ApiClient, functionName: string);
invoke(
...args: TInput extends void | Record<string, never>
? [params?: undefined, options?: InvokeOptions]
: [params: TInput, options?: InvokeOptions]
): Promise<TOutput>;
}invoke() returns the function output directly as Promise<TOutput>. It does not return the transport envelope.
| Function shape | Call form |
|---|---|
| Input function | invoke(params) or invoke(params, options) |
| No-input function | invoke() or invoke(undefined, options) |
A lone argument is always treated as function input, never as options.
InvokeOptions
interface InvokeOptions {
headers?: Record<string, string>;
timeoutMs?: number;
}timeoutMs defaults to 250,000 ms and is capped at that same Fabric UDF host limit. Non-positive, non-finite, or missing values use the default.
Invocation route
When the client was created with functionsBaseUrl, FunctionClient posts to:
${functionsBaseUrl}/api/<functionName>Otherwise it posts to the deployed Fabric route:
${baseUrl}/functions/<functionName>/invokeErrors
FunctionClient.invoke() throws on failure. Catch FunctionsError before a generic error handler when you need function-specific messages or codes. Import NetworkError and SdkError by name from @microsoft/rayfin-client. Changed in 2.0
import { NetworkError } from '@microsoft/rayfin-client';
import { FunctionsError } from '@microsoft/rayfin-functions';
import { rayfinClient } from '../services/rayfinClient';
export async function logGreeting(): Promise<void> {
try {
const result = await rayfinClient.functions.greet.invoke({
firstName: 'Ada',
lastName: 'Lovelace',
});
console.log(result);
} catch (error) {
if (error instanceof FunctionsError) {
console.error(error.code, error.message);
} else if (error instanceof NetworkError) {
console.error('Network failure while invoking the function.');
} else {
throw error;
}
}
}| Failure | Error |
|---|---|
Backend response contains errors or non-success status | FunctionsError with code FUNCTION_EXECUTION_ERROR. |
| Unexpected invocation failure | FunctionsError with code UNKNOWN_FUNCTION_ERROR. |
| Network failure | NetworkError, propagated unchanged. |
| Other SDK failure | SdkError, propagated unchanged. |
The backend invocationId is logged with console.debug as [rayfin-functions] <name> invocationId=<id>.
Full exported surface
export { functionsService } from './functionsService.js';
export { FunctionsError, createFunctionsApi, FunctionClient } from './Functions.js';
export type {
FunctionInvocationResponse,
InvokeOptions,
TypedFunctionClients,
} from './Functions.js';
export type { FunctionsSchema } from './FunctionsSchema.js';FunctionInvocationResponse
interface FunctionInvocationResponse<TOutput = any> {
functionName: string;
invocationId: string;
status: string;
output: TOutput;
errors: Array<string | Record<string, any>>;
}This is the wire envelope. invoke() unwraps and returns output, auto-parsing JSON-encoded output strings and inner { output: <value> } envelopes when present.
In my Rayfin 2.0 app, make `client.functions` typed by the generated functions schema.
Add @microsoft/rayfin-functions to the frontend package.json at the same exact version as @microsoft/rayfin-client. In the existing `RayfinClient.create({...})` call, keep the auth adapter and every other service, and add `functions: functionsService<AppFunctionsSchema>()` to `services`, importing `functionsService` from @microsoft/rayfin-functions and `AppFunctionsSchema` from rayfin/functions/src/types. Replace any import of `FunctionsSchema` from @microsoft/rayfin-client with an import from @microsoft/rayfin-functions. Do not set `functionsBaseUrl` unless the app already uses the local `/.rayfin/api` route. Run the type check and fix what it reports.@microsoft/rayfin-embed-host
Parent-page SDK reference for brokering external Entra authentication into a Rayfin app embedded in an iframe.
@microsoft/rayfin-storage
SDK reference for Rayfin Storage — storageService and createStorageClient, path-based upload, download, list, and delete signatures, options, result shapes, and error codes.