Rayfin

Functions

Run server-side TypeScript in Rayfin with typed frontend calls, typed secrets, and app-identity connections to Azure and Fabric resources.

Changed in 1.36

Rayfin functions are server-side TypeScript user-defined functions (UDFs) authored with @microsoft/fabric-user-data-functions, run in the Fabric runtime, and invoked from your frontend through RayfinClient. Use them for trusted backend logic, secrets, and external resource calls that must not run in the browser.

Note

Functions are generally available in Rayfin 1.36 and no longer use a RAYFIN_FEATURE_FLAGS=functions gate. They are not available in every Fabric region or tenant; confirm deployment in the target workspace before you depend on them.

Use a function for trusted server work

Use a function when code needs a server boundary:

  • Secrets and API keys — read values with ctx.Secrets, never from client code.
  • Business logic users must not edit — enforce rules that a browser client could bypass.
  • Server-side validation — validate before writing data or calling external services.
  • Aggregation and transformation — combine data before returning it to the frontend.
  • External resources — call Fabric SQL, OneLake, Fabric REST, Azure AI Foundry, or Azure DevOps with server-side tokens.

For normal reads and writes against your Rayfin entities, call client.data.<Entity> from the frontend instead of adding a function hop.

Enable and scaffold functions

Run functions init from an existing Rayfin project:

npx rayfin functions init

The command creates the functions package, enables the service in rayfin/rayfin.yml, installs dependencies, builds, and generates the initial types.ts schema.

rayfin/rayfin.yml
services:
  functions:
    enabled: true
    path: rayfin/functions
    auth:
      type: application
    buildCommand: npm run build

auth.type: application is required when Functions are enabled. New 1.36 scaffolds write it automatically; existing apps must add it explicitly and run a full npx rayfin up to apply the remote setting. Standalone commands such as npx rayfin up functions deploy upload code but do not migrate the remote auth mode.

Understand the two identities

Deployed functions use two authentication paths:

Access pathAPIIdentity used
Rayfin datactx.getDataClient()The signed-in caller's Rayfin token and database permissions.
External resourcesctx.Tokens.<Audience>The Fabric app's application identity. For current Fabric apps, this is the owner of the Fabric app item.

Grant external resources to the app identity. Declaring an audience or deploying the function does not grant SQL, Storage, Fabric REST, Azure AI, or Azure DevOps permissions.

Project structure

rayfin/
  data/
  functions/
    src/
      function_app.ts
      types.ts
      secrets.generated.ts
    host.json
    local.settings.json
    package.json
    tsconfig.json
  • function_app.ts registers handlers with udf.func(...).
  • types.ts is generated for frontend calls; never hand-edit it.
  • secrets.generated.ts is generated from the top-level secrets: list in rayfin.yml; never hand-edit it.
  • local.settings.json is local-only and can contain local development secrets.

Development and deployment loop

Prefer npx rayfin dev during development. It provisions or reuses the Fabric backend, emits frontend environment files, starts the frontend, and starts the local Functions host when services.functions.enabled is true.

Use these focused commands when needed:

TaskCommand
Scaffold or refresh the functions packagenpx rayfin functions init
Run only the local Functions hostnpx rayfin dev functions apply
Deploy everything, including functionsnpx rayfin up
Deploy only function codenpx rayfin up functions deploy
Skip function deployment in a full deploynpx rayfin up --exclude-services functions

In this section

PromptAdd a Rayfin function for server-side logic
In my Rayfin project, add a server-side function for this task: <describe the trusted backend logic>. Use Rayfin 1.36 or later. If rayfin/functions/ does not exist, run `npx rayfin functions init`. Ensure rayfin/rayfin.yml has services.functions.enabled: true and services.functions.auth.type: application. Register the handler in rayfin/functions/src/function_app.ts with `udf.func(name, handler, [])`. Use `RayfinContext<AppSchema>` for typed data access, `ctx.Secrets.<NAME>` for declared secrets, and `RayfinContext<AppSchema, AudienceType.X>` plus `ctx.Tokens.X` for external resources. Do not expose secrets or tokens to the frontend. Run the smallest build or typegen command that validates the change, then tell me how to call the function from the frontend.
Something wrong on this page?Report an issueEdit this page

On this page