@microsoft/rayfin-guide 1.36.0-alpha.1756 → 1.36.0-alpha.1917
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/docs/app-backend/deploy.md +36 -1
- package/assets/docs/cli/connectors/add.md +18 -3
- package/assets/docs/cli/connectors/category-b-function-bridge.md +111 -11
- package/assets/docs/cli/connectors/index.md +8 -4
- package/assets/docs/cli/connectors/inspect.md +34 -1
- package/assets/docs/cli/connectors/invoke.md +4 -0
- package/assets/docs/cli/connectors/search.md +4 -0
- package/assets/docs/cli/environment-variables.md +2 -1
- package/assets/docs/cli/functions/deploy.md +13 -1
- package/assets/docs/cli/functions/dev-apply.md +8 -2
- package/assets/docs/cli/functions/index.md +4 -2
- package/assets/docs/cli/functions/init.md +7 -1
- package/assets/docs/cli/index.md +20 -7
- package/assets/docs/cli/secrets.md +18 -8
- package/assets/docs/functions/connections/add-ado.md +8 -4
- package/assets/docs/functions/connections/add-azure-resource.md +17 -131
- package/assets/docs/functions/connections/add-fabric-resource.md +31 -61
- package/assets/docs/functions/connections/add-foundry.md +11 -4
- package/assets/docs/functions/connections/get-fabric-info.md +7 -25
- package/assets/docs/functions/connections/index.md +127 -22
- package/assets/docs/functions/index.md +39 -1
- package/assets/docs/functions/secrets.md +39 -11
- package/assets/docs/functions/writing-functions.md +27 -23
- package/assets/docs/getting-started/project-structure.md +3 -1
- package/assets/docs/preview/local-dev-docker.md +2 -1
- package/package.json +1 -1
- package/assets/docs/functions/connections/add-work-iq.md +0 -39
|
@@ -4,7 +4,7 @@ sidebar_position: 50
|
|
|
4
4
|
|
|
5
5
|
# Managing Secrets
|
|
6
6
|
|
|
7
|
-
Secrets are encrypted values — API keys, connection strings, tokens — that your app needs at runtime but must never ship in client code. They are stored securely on your deployed Rayfin item and read on the server by [functions](./functions/index.md) via `ctx.
|
|
7
|
+
Secrets are encrypted values — API keys, connection strings, tokens — that your app needs at runtime but must never ship in client code. They are stored securely on your deployed Rayfin item and read on the server by [functions](./functions/index.md) via `ctx.Secrets`.
|
|
8
8
|
|
|
9
9
|
Manage secrets with the `npx rayfin secret` command group:
|
|
10
10
|
|
|
@@ -105,18 +105,28 @@ Deleting a secret that does not exist reports a not-found error — run `npx ray
|
|
|
105
105
|
|
|
106
106
|
## Reading secrets from functions
|
|
107
107
|
|
|
108
|
-
Server-side functions read secrets at runtime
|
|
108
|
+
Server-side functions read secrets at runtime as typed properties on `ctx.Secrets`, which resolve against the deployed item's secret bag and fall back to `process.env`. Set a secret with `npx rayfin secret set <name>`, then read it by the same name inside your handler:
|
|
109
109
|
|
|
110
110
|
```ts
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
import { type RayfinContext } from "@microsoft/fabric-user-data-functions";
|
|
112
|
+
|
|
113
|
+
udf.func(
|
|
114
|
+
"summarize",
|
|
115
|
+
async (ctx: RayfinContext<AppSchema>, input: { text: string }) => {
|
|
116
|
+
const apiKey = ctx.Secrets.OPENAI_KEY;
|
|
117
|
+
// ... call the API with apiKey
|
|
118
|
+
},
|
|
119
|
+
[],
|
|
120
|
+
);
|
|
115
121
|
```
|
|
116
122
|
|
|
123
|
+
The `RayfinContext<AppSchema>` annotation is what makes this type-safe. An unannotated `ctx` is contextually `any`, so `ctx.Secrets.OPENAI_KEY` compiles whether or not the secret is declared — and the annotation is also how typegen recognises the parameter as the injected context rather than a request-body argument.
|
|
124
|
+
|
|
125
|
+
Setting the secret is what types it: the CLI regenerates `rayfin/functions/src/secrets.generated.ts`, so `ctx.Secrets.OPENAI_KEY` is a `string` and an undeclared name is a compile error. See [Secrets](../functions/secrets.md) for the full model.
|
|
126
|
+
|
|
117
127
|
## Using secrets in local development
|
|
118
128
|
|
|
119
|
-
When you run functions locally with [`npx rayfin dev functions apply`](./functions/dev-apply.md), there is no deployed secret bag, so `ctx.
|
|
129
|
+
When you run functions locally with [`npx rayfin dev functions apply`](./functions/dev-apply.md), there is no deployed secret bag, so `ctx.Secrets.<NAME>` falls back to `process.env`. To make a secret available locally, add it under `Values` in `rayfin/functions/local.settings.json` — the Azure Functions host loads those entries into `process.env`:
|
|
120
130
|
|
|
121
131
|
```json
|
|
122
132
|
{
|
|
@@ -166,6 +176,6 @@ If `secret delete` reports the secret was not found:
|
|
|
166
176
|
|
|
167
177
|
## See also
|
|
168
178
|
|
|
169
|
-
- [Functions](./functions/index.md) — read secrets from server-side functions with `ctx.
|
|
179
|
+
- [Functions](./functions/index.md) — read secrets from server-side functions with `ctx.Secrets`.
|
|
170
180
|
- [CLI quickstart](./quickstart.md)
|
|
171
181
|
- [Environment configuration](./env-interpolation.md)
|
|
@@ -4,10 +4,14 @@ sidebar_position: 5
|
|
|
4
4
|
|
|
5
5
|
# Add Azure DevOps
|
|
6
6
|
|
|
7
|
-
Call the [Azure DevOps REST API](https://learn.microsoft.com/en-us/rest/api/azure/devops/) from a function
|
|
7
|
+
Call the [Azure DevOps REST API](https://learn.microsoft.com/en-us/rest/api/azure/devops/) from a deployed function using `AudienceType.ADO`.
|
|
8
|
+
|
|
9
|
+
Grant the [application identity](../index.md#application-authentication) access to your Azure DevOps organization and the permissions required by the project or resource you call.
|
|
8
10
|
|
|
9
11
|
Provide your Azure DevOps **organization** (and project, if the call needs one) — e.g. `https://dev.azure.com/<org>`. The token is a standard bearer token — send it with `fetch`:
|
|
10
12
|
|
|
13
|
+
`AppSchema` below is your app's data schema — the same type you pass to `RayfinClient<AppSchema>`. See [Writing functions](../writing-functions.md#accessing-data-and-request-context).
|
|
14
|
+
|
|
11
15
|
```ts
|
|
12
16
|
import {
|
|
13
17
|
UserDataFunctions,
|
|
@@ -22,8 +26,8 @@ const ORG = "https://dev.azure.com/<org>";
|
|
|
22
26
|
|
|
23
27
|
udf.func(
|
|
24
28
|
"listProjects",
|
|
25
|
-
async (ctx: RayfinContext): Promise<unknown> => {
|
|
26
|
-
const token = ctx.
|
|
29
|
+
async (ctx: RayfinContext<AppSchema, AudienceType.ADO>): Promise<unknown> => {
|
|
30
|
+
const token = ctx.Tokens.ADO;
|
|
27
31
|
const res = await fetch(`${ORG}/_apis/projects?api-version=7.1`, {
|
|
28
32
|
headers: { Authorization: `Bearer ${token}` },
|
|
29
33
|
});
|
|
@@ -32,7 +36,7 @@ udf.func(
|
|
|
32
36
|
}
|
|
33
37
|
return res.json();
|
|
34
38
|
},
|
|
35
|
-
[
|
|
39
|
+
[],
|
|
36
40
|
);
|
|
37
41
|
```
|
|
38
42
|
|
|
@@ -4,58 +4,24 @@ sidebar_position: 3
|
|
|
4
4
|
|
|
5
5
|
# Add an Azure resource
|
|
6
6
|
|
|
7
|
-
Connect a function to
|
|
7
|
+
Connect a deployed function to **Azure Blob Storage**.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Grant the [application identity](../index.md#application-authentication) the storage data permissions required by your operations.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
The storage account is an Azure resource, not a Fabric item, so its endpoint comes from the **Azure portal** (there is no Fabric lookup).
|
|
12
|
+
The pattern declares the audience in the `RayfinContext` annotation, reads the token from `ctx.Tokens`, and wraps it with the [`ContextTokenCredential`](./index.md#wrapping-the-token-for-azure-sdk-clients) helper for the Azure SDK.
|
|
13
|
+
See [Connecting to external resources](./index.md) for the shared model.
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
`AppSchema` below is your app's data schema — the same type you pass to `RayfinClient<AppSchema>`.
|
|
16
|
+
See [Writing functions](../writing-functions.md#accessing-data-and-request-context).
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
cd rayfin/functions
|
|
17
|
-
npm install @azure/keyvault-secrets @azure/identity
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
import {
|
|
22
|
-
UserDataFunctions,
|
|
23
|
-
AudienceType,
|
|
24
|
-
type RayfinContext,
|
|
25
|
-
} from "@microsoft/fabric-user-data-functions";
|
|
26
|
-
import { SecretClient } from "@azure/keyvault-secrets";
|
|
27
|
-
|
|
28
|
-
const udf = new UserDataFunctions();
|
|
29
|
-
|
|
30
|
-
udf.func(
|
|
31
|
-
"getVaultSecret",
|
|
32
|
-
async (
|
|
33
|
-
ctx: RayfinContext,
|
|
34
|
-
kvUrl: string,
|
|
35
|
-
secretName: string,
|
|
36
|
-
): Promise<string> => {
|
|
37
|
-
const credential = new ContextTokenCredential(
|
|
38
|
-
ctx.getToken(AudienceType.KeyVault),
|
|
39
|
-
);
|
|
40
|
-
const client = new SecretClient(kvUrl, credential);
|
|
41
|
-
const secret = await client.getSecret(secretName);
|
|
42
|
-
return secret.value ?? "";
|
|
43
|
-
},
|
|
44
|
-
[udf.connection({ audienceType: AudienceType.KeyVault })],
|
|
45
|
-
);
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
Provide the vault URL (e.g. `https://my-vault.vault.azure.net/`).
|
|
49
|
-
|
|
50
|
-
> To read secrets stored with Rayfin itself (rather than an external Key Vault), use [`ctx.getSecret()`](../secrets.md) instead — no connection required.
|
|
51
|
-
|
|
52
|
-
## Cosmos DB
|
|
18
|
+
## Blob Storage
|
|
53
19
|
|
|
54
|
-
Connect to Azure
|
|
20
|
+
Connect to Azure Blob / Table / Queue storage using `AudienceType.Storage`:
|
|
55
21
|
|
|
56
22
|
```bash
|
|
57
23
|
cd rayfin/functions
|
|
58
|
-
npm install @azure/
|
|
24
|
+
npm install @azure/storage-blob @azure/identity
|
|
59
25
|
```
|
|
60
26
|
|
|
61
27
|
```ts
|
|
@@ -64,53 +30,17 @@ import {
|
|
|
64
30
|
AudienceType,
|
|
65
31
|
type RayfinContext,
|
|
66
32
|
} from "@microsoft/fabric-user-data-functions";
|
|
67
|
-
import {
|
|
33
|
+
import { BlobServiceClient } from "@azure/storage-blob";
|
|
68
34
|
|
|
69
35
|
const udf = new UserDataFunctions();
|
|
70
36
|
|
|
71
|
-
udf.func(
|
|
72
|
-
"readItems",
|
|
73
|
-
async (
|
|
74
|
-
ctx: RayfinContext,
|
|
75
|
-
endpoint: string,
|
|
76
|
-
databaseId: string,
|
|
77
|
-
containerId: string,
|
|
78
|
-
): Promise<unknown[]> => {
|
|
79
|
-
const credential = new ContextTokenCredential(
|
|
80
|
-
ctx.getToken(AudienceType.CosmosDB),
|
|
81
|
-
);
|
|
82
|
-
const client = new CosmosClient({ endpoint, aadCredentials: credential });
|
|
83
|
-
const { resources } = await client
|
|
84
|
-
.database(databaseId)
|
|
85
|
-
.container(containerId)
|
|
86
|
-
.items.readAll()
|
|
87
|
-
.fetchAll();
|
|
88
|
-
return resources;
|
|
89
|
-
},
|
|
90
|
-
[udf.connection({ audienceType: AudienceType.CosmosDB })],
|
|
91
|
-
);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Provide the account endpoint and the database / container names.
|
|
95
|
-
|
|
96
|
-
## Blob Storage
|
|
97
|
-
|
|
98
|
-
Connect to Azure Blob / Table / Queue storage using `AudienceType.Storage`:
|
|
99
|
-
|
|
100
|
-
```bash
|
|
101
|
-
cd rayfin/functions
|
|
102
|
-
npm install @azure/storage-blob
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
```ts
|
|
106
|
-
import { BlobServiceClient } from "@azure/storage-blob";
|
|
107
|
-
|
|
108
37
|
udf.func(
|
|
109
38
|
"listBlobs",
|
|
110
|
-
async (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
39
|
+
async (
|
|
40
|
+
ctx: RayfinContext<AppSchema, AudienceType.Storage>,
|
|
41
|
+
accountUrl: string,
|
|
42
|
+
): Promise<string[]> => {
|
|
43
|
+
const credential = new ContextTokenCredential(ctx.Tokens.Storage);
|
|
114
44
|
const service = new BlobServiceClient(accountUrl, credential);
|
|
115
45
|
const names: string[] = [];
|
|
116
46
|
for await (const container of service.listContainers()) {
|
|
@@ -118,54 +48,10 @@ udf.func(
|
|
|
118
48
|
}
|
|
119
49
|
return names;
|
|
120
50
|
},
|
|
121
|
-
[
|
|
51
|
+
[],
|
|
122
52
|
);
|
|
123
53
|
```
|
|
124
54
|
|
|
125
55
|
Provide the storage account URL (e.g. `https://<account>.blob.core.windows.net`).
|
|
126
56
|
|
|
127
57
|
> `AudienceType.Storage` also covers **OneLake** files — that Fabric case is documented in [Add a Fabric resource → OneLake files](./add-fabric-resource.md#onelake-files).
|
|
128
|
-
|
|
129
|
-
## Event Grid
|
|
130
|
-
|
|
131
|
-
Publish events to an Azure Event Grid topic using `AudienceType.EventGrid`. The topic endpoint is in the Azure portal → your topic → **Overview** → _Topic Endpoint_.
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
cd rayfin/functions
|
|
135
|
-
npm install @azure/eventgrid
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
```ts
|
|
139
|
-
import {
|
|
140
|
-
UserDataFunctions,
|
|
141
|
-
AudienceType,
|
|
142
|
-
type RayfinContext,
|
|
143
|
-
} from "@microsoft/fabric-user-data-functions";
|
|
144
|
-
import { EventGridPublisherClient } from "@azure/eventgrid";
|
|
145
|
-
|
|
146
|
-
const udf = new UserDataFunctions();
|
|
147
|
-
|
|
148
|
-
const TOPIC_ENDPOINT =
|
|
149
|
-
"https://<topic>.<region>.eventgrid.azure.net/api/events";
|
|
150
|
-
|
|
151
|
-
udf.func(
|
|
152
|
-
"publishEvent",
|
|
153
|
-
async (ctx: RayfinContext, subject: string): Promise<string> => {
|
|
154
|
-
const client = new EventGridPublisherClient(
|
|
155
|
-
TOPIC_ENDPOINT,
|
|
156
|
-
"EventGrid",
|
|
157
|
-
new ContextTokenCredential(ctx.getToken(AudienceType.EventGrid)),
|
|
158
|
-
);
|
|
159
|
-
await client.send([
|
|
160
|
-
{
|
|
161
|
-
eventType: "Rayfin.Function.Event",
|
|
162
|
-
subject,
|
|
163
|
-
dataVersion: "1.0",
|
|
164
|
-
data: { source: "user-data-function" },
|
|
165
|
-
},
|
|
166
|
-
]);
|
|
167
|
-
return "published";
|
|
168
|
-
},
|
|
169
|
-
[udf.connection({ audienceType: AudienceType.EventGrid })],
|
|
170
|
-
);
|
|
171
|
-
```
|
|
@@ -4,11 +4,18 @@ sidebar_position: 2
|
|
|
4
4
|
|
|
5
5
|
# Add a Fabric resource
|
|
6
6
|
|
|
7
|
-
Connect a function to a **Microsoft Fabric item** — a Lakehouse, Warehouse, SQL Database, OneLake files
|
|
7
|
+
Connect a deployed function to a **Microsoft Fabric item** — a Lakehouse, Warehouse, SQL Database, or OneLake files.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
For the app's Rayfin DB, use [`ctx.getDataClient()`](../writing-functions.md#accessing-data-and-request-context) instead.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Grant the [application identity](../index.md#application-authentication) the required access to the workspace, item, or database for the operation you need.
|
|
12
|
+
|
|
13
|
+
**Before you start:** you need the item's coordinates (SQL endpoint or OneLake path).
|
|
14
|
+
See [Get Fabric info](./get-fabric-info.md) for how to pull them from the Fabric REST API.
|
|
15
|
+
|
|
16
|
+
All the patterns below follow the same model: declare the audience in the `RayfinContext` annotation, read the token from `ctx.Tokens`, use it. See [Connecting to external resources](./index.md) for the shared model and the [`ContextTokenCredential`](./index.md#wrapping-the-token-for-azure-sdk-clients) helper referenced here.
|
|
17
|
+
|
|
18
|
+
`AppSchema` below is your app's data schema — the same type you pass to `RayfinClient<AppSchema>`. See [Writing functions](../writing-functions.md#accessing-data-and-request-context).
|
|
12
19
|
|
|
13
20
|
## SQL databases
|
|
14
21
|
|
|
@@ -16,7 +23,7 @@ Covers Fabric **Lakehouse** (SQL analytics endpoint), **Warehouse**, **SQL Datab
|
|
|
16
23
|
|
|
17
24
|
- **Package:** `mssql@^12.6.0` (which pulls `tedious >= 19.2.2`). Older `tedious` (`<= 19.1.2`) has a LOGIN7 FeatureExt bug that causes "socket hang up" errors against Fabric endpoints.
|
|
18
25
|
- **Encryption:** `encrypt: true` (not `'strict'`). This matches ODBC `Encrypt=yes`.
|
|
19
|
-
- **Auth:** `azure-active-directory-access-token` with the token from `ctx.
|
|
26
|
+
- **Auth:** `azure-active-directory-access-token` with the token from `ctx.Tokens.Sql`.
|
|
20
27
|
|
|
21
28
|
Install the driver in the functions project:
|
|
22
29
|
|
|
@@ -52,10 +59,10 @@ const DATABASE = "<item-guid-or-db-name>";
|
|
|
52
59
|
udf.func(
|
|
53
60
|
"queryData",
|
|
54
61
|
async (
|
|
55
|
-
ctx: RayfinContext,
|
|
62
|
+
ctx: RayfinContext<AppSchema, AudienceType.Sql>,
|
|
56
63
|
query: string,
|
|
57
64
|
): Promise<Record<string, unknown>[]> => {
|
|
58
|
-
const token = ctx.
|
|
65
|
+
const token = ctx.Tokens.Sql;
|
|
59
66
|
const pool = await sql.connect({
|
|
60
67
|
server: SQL_SERVER,
|
|
61
68
|
database: DATABASE,
|
|
@@ -69,7 +76,7 @@ udf.func(
|
|
|
69
76
|
await pool.close();
|
|
70
77
|
return result.recordset;
|
|
71
78
|
},
|
|
72
|
-
[
|
|
79
|
+
[],
|
|
73
80
|
);
|
|
74
81
|
```
|
|
75
82
|
|
|
@@ -79,7 +86,7 @@ Read and write files in a Lakehouse's OneLake storage using `AudienceType.Storag
|
|
|
79
86
|
|
|
80
87
|
The OneLake DFS URL has the form `https://onelake.dfs.fabric.microsoft.com/<workspaceId>/<itemId>/Files/<path>` — get it from `oneLakeFilesPath` via [Get Fabric info](./get-fabric-info.md#lakehouse), or construct it from the workspace and item GUIDs.
|
|
81
88
|
|
|
82
|
-
Call the DFS endpoint directly with the
|
|
89
|
+
Call the DFS endpoint directly with the app-identity token — no SDK required:
|
|
83
90
|
|
|
84
91
|
```ts
|
|
85
92
|
import {
|
|
@@ -92,8 +99,11 @@ const udf = new UserDataFunctions();
|
|
|
92
99
|
|
|
93
100
|
udf.func(
|
|
94
101
|
"readFile",
|
|
95
|
-
async (
|
|
96
|
-
|
|
102
|
+
async (
|
|
103
|
+
ctx: RayfinContext<AppSchema, AudienceType.Storage>,
|
|
104
|
+
fileUrl: string,
|
|
105
|
+
): Promise<string> => {
|
|
106
|
+
const token = ctx.Tokens.Storage;
|
|
97
107
|
const res = await fetch(fileUrl, {
|
|
98
108
|
headers: { Authorization: `Bearer ${token}` },
|
|
99
109
|
});
|
|
@@ -102,59 +112,16 @@ udf.func(
|
|
|
102
112
|
}
|
|
103
113
|
return await res.text();
|
|
104
114
|
},
|
|
105
|
-
[
|
|
115
|
+
[],
|
|
106
116
|
);
|
|
107
117
|
```
|
|
108
118
|
|
|
109
|
-
## Eventhouse and KQL
|
|
110
|
-
|
|
111
|
-
Query a Fabric **Eventhouse** (KQL database) or a standalone Azure Data Explorer cluster using `AudienceType.Kusto`.
|
|
112
|
-
|
|
113
|
-
Get the cluster's **query URI** from the Eventhouse's `properties.queryServiceUri` — see [Get Fabric info → Eventhouse](./get-fabric-info.md#eventhouse).
|
|
114
|
-
|
|
115
|
-
`azure-kusto-data` accepts a token provider, so hand it a callback that returns `ctx.getToken`:
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
import {
|
|
119
|
-
UserDataFunctions,
|
|
120
|
-
AudienceType,
|
|
121
|
-
type RayfinContext,
|
|
122
|
-
} from "@microsoft/fabric-user-data-functions";
|
|
123
|
-
import { Client, KustoConnectionStringBuilder } from "azure-kusto-data";
|
|
124
|
-
|
|
125
|
-
const udf = new UserDataFunctions();
|
|
126
|
-
|
|
127
|
-
// Read these from the Eventhouse item — see "Get Fabric info".
|
|
128
|
-
const CLUSTER_URI = "https://<cluster>.z5.kusto.fabric.microsoft.com";
|
|
129
|
-
const DATABASE = "<kql-database-name>";
|
|
130
|
-
|
|
131
|
-
udf.func(
|
|
132
|
-
"queryKusto",
|
|
133
|
-
async (ctx: RayfinContext, query: string): Promise<unknown[]> => {
|
|
134
|
-
const kcsb = KustoConnectionStringBuilder.withTokenProvider(
|
|
135
|
-
CLUSTER_URI,
|
|
136
|
-
async () => ctx.getToken(AudienceType.Kusto),
|
|
137
|
-
);
|
|
138
|
-
const client = new Client(kcsb);
|
|
139
|
-
const response = await client.execute(DATABASE, query);
|
|
140
|
-
return response.primaryResults[0].toJSON().data;
|
|
141
|
-
},
|
|
142
|
-
[udf.connection({ audienceType: AudienceType.Kusto })],
|
|
143
|
-
);
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
Install the SDK in the functions project:
|
|
147
|
-
|
|
148
|
-
```bash
|
|
149
|
-
cd rayfin/functions
|
|
150
|
-
npm install azure-kusto-data
|
|
151
|
-
```
|
|
152
|
-
|
|
153
119
|
## Fabric REST API
|
|
154
120
|
|
|
155
|
-
Call the [Fabric REST API](https://learn.microsoft.com/en-us/rest/api/fabric/) as the
|
|
121
|
+
Call the [Fabric REST API](https://learn.microsoft.com/en-us/rest/api/fabric/) as the app identity — for example to list items or read item metadata from inside a function — using `AudienceType.Fabric`.
|
|
122
|
+
Check that the specific API supports application identities and that the app identity has the required access.
|
|
156
123
|
|
|
157
|
-
The API base is fixed at `https://api.fabric.microsoft.com/v1`; `ctx.
|
|
124
|
+
The API base is fixed at `https://api.fabric.microsoft.com/v1`; `ctx.Tokens.Fabric` returns a token scoped for it. Send it as a bearer token with `fetch`:
|
|
158
125
|
|
|
159
126
|
```ts
|
|
160
127
|
import {
|
|
@@ -169,8 +136,11 @@ const FABRIC_API = "https://api.fabric.microsoft.com/v1";
|
|
|
169
136
|
|
|
170
137
|
udf.func(
|
|
171
138
|
"listWorkspaceItems",
|
|
172
|
-
async (
|
|
173
|
-
|
|
139
|
+
async (
|
|
140
|
+
ctx: RayfinContext<AppSchema, AudienceType.Fabric>,
|
|
141
|
+
workspaceId: string,
|
|
142
|
+
): Promise<unknown> => {
|
|
143
|
+
const token = ctx.Tokens.Fabric;
|
|
174
144
|
const res = await fetch(`${FABRIC_API}/workspaces/${workspaceId}/items`, {
|
|
175
145
|
headers: { Authorization: `Bearer ${token}` },
|
|
176
146
|
});
|
|
@@ -179,8 +149,8 @@ udf.func(
|
|
|
179
149
|
}
|
|
180
150
|
return res.json();
|
|
181
151
|
},
|
|
182
|
-
[
|
|
152
|
+
[],
|
|
183
153
|
);
|
|
184
154
|
```
|
|
185
155
|
|
|
186
|
-
> This is the same API used in [Get Fabric info](./get-fabric-info.md) — the difference is that there you call it at **authoring time** (with an `az` token) to gather endpoints, whereas here the **function** calls it at runtime with the
|
|
156
|
+
> This is the same API used in [Get Fabric info](./get-fabric-info.md) — the difference is that there you call it at **authoring time** (with an `az` token) to gather endpoints, whereas here the **deployed function** calls it at runtime with the app identity's token and resource permissions.
|
|
@@ -4,10 +4,14 @@ sidebar_position: 4
|
|
|
4
4
|
|
|
5
5
|
# Add Azure AI Foundry
|
|
6
6
|
|
|
7
|
-
Call an **Azure AI Foundry** (Azure OpenAI / Azure AI) resource from a function
|
|
7
|
+
Call an **Azure AI Foundry** (Azure OpenAI / Azure AI) resource from a deployed function using `AudienceType.AzureAI`.
|
|
8
|
+
|
|
9
|
+
Grant the [application identity](../index.md#application-authentication) the permissions required by your Azure AI resource and API.
|
|
8
10
|
|
|
9
11
|
Provide the resource **endpoint** (Azure AI Foundry → your resource → _Endpoint_). The token is a standard bearer token — send it with `fetch`, or wrap it with the [`ContextTokenCredential`](./index.md#wrapping-the-token-for-azure-sdk-clients) helper for an Azure AI SDK client.
|
|
10
12
|
|
|
13
|
+
`AppSchema` below is your app's data schema — the same type you pass to `RayfinClient<AppSchema>`. See [Writing functions](../writing-functions.md#accessing-data-and-request-context).
|
|
14
|
+
|
|
11
15
|
```ts
|
|
12
16
|
import {
|
|
13
17
|
UserDataFunctions,
|
|
@@ -22,8 +26,11 @@ const AI_ENDPOINT = "https://<resource>.services.ai.azure.com";
|
|
|
22
26
|
|
|
23
27
|
udf.func(
|
|
24
28
|
"callAzureAi",
|
|
25
|
-
async (
|
|
26
|
-
|
|
29
|
+
async (
|
|
30
|
+
ctx: RayfinContext<AppSchema, AudienceType.AzureAI>,
|
|
31
|
+
prompt: string,
|
|
32
|
+
): Promise<unknown> => {
|
|
33
|
+
const token = ctx.Tokens.AzureAI;
|
|
27
34
|
const res = await fetch(`${AI_ENDPOINT}/...`, {
|
|
28
35
|
method: "POST",
|
|
29
36
|
headers: {
|
|
@@ -37,7 +44,7 @@ udf.func(
|
|
|
37
44
|
}
|
|
38
45
|
return res.json();
|
|
39
46
|
},
|
|
40
|
-
[
|
|
47
|
+
[],
|
|
41
48
|
);
|
|
42
49
|
```
|
|
43
50
|
|
|
@@ -4,12 +4,14 @@ sidebar_position: 1
|
|
|
4
4
|
|
|
5
5
|
# Finding resource coordinates
|
|
6
6
|
|
|
7
|
-
Every connection recipe needs a real endpoint
|
|
7
|
+
Every connection recipe needs a real endpoint, such as the SQL server or the OneLake path.
|
|
8
8
|
This page explains **how to obtain those values from a Fabric item** so you (or an agent authoring a function) can fill them in with real data instead of guessing.
|
|
9
9
|
|
|
10
|
-
**You only need the workspace and item _display names_ to start** — for example, "lakehouseA in workspaceB".
|
|
10
|
+
**You only need the workspace and item _display names_ to start** — for example, "lakehouseA in workspaceB".
|
|
11
|
+
Everything else (the workspace ID, item ID, SQL endpoint, OneLake path) is derivable from here.
|
|
12
|
+
Resolve those values rather than asking for anything you can look up.
|
|
11
13
|
|
|
12
|
-
> **Why this matters:** don't hardcode a guessed endpoint. `ctx.
|
|
14
|
+
> **Why this matters:** don't hardcode a guessed endpoint. `ctx.Tokens` gives you an access token, but you still have to point the SDK at the correct URL — and that URL comes from the Fabric item's metadata, not from `process.env`.
|
|
13
15
|
|
|
14
16
|
## Ways to get coordinates
|
|
15
17
|
|
|
@@ -36,7 +38,7 @@ az account get-access-token \
|
|
|
36
38
|
--query accessToken -o tsv
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
> This is an **authoring-time** lookup — you are gathering coordinates to write into the function. At **runtime** the function itself
|
|
41
|
+
> This is an **authoring-time** lookup — you are gathering coordinates to write into the function. At **runtime** the function itself declares the audience on its `RayfinContext` annotation and reads `ctx.Tokens.<Audience>` (for the Fabric API specifically, `ctx.Tokens.Fabric` — see [Add a Fabric resource → Fabric REST API](./add-fabric-resource.md#fabric-rest-api)).
|
|
40
42
|
|
|
41
43
|
## Step 1 — find the workspace and item ID
|
|
42
44
|
|
|
@@ -52,7 +54,7 @@ List items of a given type in a workspace (to resolve a display name to its ID):
|
|
|
52
54
|
GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/items?type=Lakehouse
|
|
53
55
|
```
|
|
54
56
|
|
|
55
|
-
`type` accepts any Fabric item type — `Lakehouse`, `Warehouse`, `SQLDatabase
|
|
57
|
+
`type` accepts any Fabric item type — for these recipes, use `Lakehouse`, `Warehouse`, or `SQLDatabase`.
|
|
56
58
|
Each entry returns `id`, `displayName`, and `type`. Take the `id` of the item you want.
|
|
57
59
|
|
|
58
60
|
## Step 2 — GET the item to read its coordinates
|
|
@@ -120,25 +122,6 @@ GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/sqlDatabases/{s
|
|
|
120
122
|
|
|
121
123
|
- **Server** → `properties.serverFqdn`, **database** → `properties.databaseName`. Both are also embedded in `properties.connectionString`.
|
|
122
124
|
|
|
123
|
-
### Eventhouse
|
|
124
|
-
|
|
125
|
-
```http
|
|
126
|
-
GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/eventhouses/{eventhouseId}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
```json
|
|
130
|
-
{
|
|
131
|
-
"type": "Eventhouse",
|
|
132
|
-
"properties": {
|
|
133
|
-
"queryServiceUri": "https://xxxxx.z5.kusto.fabric.microsoft.com",
|
|
134
|
-
"ingestionServiceUri": "https://ingest-xxxxx.z5.kusto.fabric.microsoft.com",
|
|
135
|
-
"databasesItemIds": ["<kql-database-item-id>"]
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
- **Cluster / query URI** → `properties.queryServiceUri`. Use with [Eventhouse and KQL](./add-fabric-resource.md#eventhouse-and-kql). Each KQL database inside the eventhouse is listed in `databasesItemIds`.
|
|
141
|
-
|
|
142
125
|
## Coordinate lookup table
|
|
143
126
|
|
|
144
127
|
| You need | Item type | Endpoint | Field |
|
|
@@ -147,7 +130,6 @@ GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/eventhouses/{ev
|
|
|
147
130
|
| SQL server (Warehouse) | Warehouse | `.../warehouses/{id}` | `properties.connectionString` |
|
|
148
131
|
| SQL server + database (SQL DB) | SQL Database | `.../sqlDatabases/{id}` | `properties.serverFqdn` / `properties.databaseName` |
|
|
149
132
|
| OneLake Files / Tables URL | Lakehouse | `.../lakehouses/{id}` | `properties.oneLakeFilesPath` / `oneLakeTablesPath` |
|
|
150
|
-
| Kusto query URI | Eventhouse | `.../eventhouses/{id}` | `properties.queryServiceUri` |
|
|
151
133
|
| Item GUID (any item) | any | `.../items?type={Type}` | `id` |
|
|
152
134
|
|
|
153
135
|
For item types not listed here, browse the [Fabric REST API item reference](https://learn.microsoft.com/en-us/rest/api/fabric/) — each item's **Get** operation returns its coordinates under `properties`.
|