@microsoft/rayfin-guide 1.34.0-alpha.1148 → 1.34.0-alpha.1201

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.
@@ -12,7 +12,9 @@ This guide explains how to configure Rayfin authentication in your application.
12
12
  - **Token management** - Access tokens never exposed to application code.
13
13
  - **Session Management** - Automatic state tracking with localStorage, sessionStorage, or custom storage.
14
14
  - **Event System** - React-friendly session change notifications.
15
- - **Server-side Compatible** - Works in Node.js with custom storage.
15
+ - **Isomorphic** - Works in Node.js, React Native, and Electron without crashing.
16
+ The constructor auto-detects the runtime and skips browser APIs when `window` is undefined.
17
+ - **Async Storage** - Storage adapters can return promises for async backends (e.g., React Native AsyncStorage).
16
18
 
17
19
  ## Auth client API surface
18
20
 
@@ -23,7 +25,9 @@ The auth client exposes the following methods for sign-up, sign-in, session mana
23
25
  | `signUp({ email, password })` | Register a new user. |
24
26
  | `signIn({ email, password })` | Authenticate an existing user. |
25
27
  | `signOut()` | End the current session. |
26
- | `getSession()` | Return the current session (opaque; check `isAuthenticated` or `user`). |
28
+ | `getSession()` | Return the current session (async; check `isAuthenticated` or `user`). |
29
+ | `startAutoRefresh()` | Resume automatic token refresh (for React Native / manual control). |
30
+ | `stopAutoRefresh()` | Pause automatic token refresh. |
27
31
  | `onSessionChange(callback)` | Subscribe to session state changes; returns an unsubscribe function. |
28
32
 
29
33
  > **Important**
@@ -114,11 +118,15 @@ That hook keeps React in sync with the Rayfin auth session.
114
118
  ```typescript
115
119
  import { useState, useEffect } from 'react';
116
120
  import { auth } from './lib/rayfin';
121
+ import type { OpaqueSession } from '@microsoft/rayfin-auth';
117
122
 
118
123
  export function useAuth() {
119
- const [session, setSession] = useState(auth.getSession());
124
+ const [session, setSession] = useState<OpaqueSession | null>(null);
120
125
 
121
- useEffect(() => auth.onSessionChange(setSession), []);
126
+ useEffect(() => {
127
+ setSession(auth.getSession());
128
+ return auth.onSessionChange(setSession);
129
+ }, []);
122
130
 
123
131
  return {
124
132
  ...session,
@@ -52,6 +52,7 @@ For the full walkthrough, see the [CLI Quickstart](./quickstart.md) or the [Buil
52
52
  | `npx rayfin up` | Deploy the project to Microsoft Fabric. If you are not signed in, the CLI launches an interactive login flow. Use `-t, --tenant <id>` when your account spans multiple tenants, `-w, --workspace <name>` for a Fabric workspace display name, `-n, --dry-run` to preview without API calls, and `-v, --verbose` for detailed output. Pass `--encryption-fallback-enabled` only when login fails with a keychain error to allow plaintext token storage on systems without OS credential storage, such as some Linux distros, dev containers, and Codespaces. Use `--exclude-services staticHosting` to skip static content build/package/deploy while leaving runtime settings untouched — useful during local development when Vite serves the frontend. Applies runtime settings, database configuration, and static content when enabled. |
53
53
  | `npx rayfin up status` | Display the status of the Fabric deployment (add `--json` for machine-readable output). |
54
54
  | `npx rayfin up db apply` | Generate and apply DAB configuration to the remote Rayfin item. Add `--force` to allow changes that may cause data loss. |
55
+ | `npx rayfin up secrets apply` | Read secrets from `rayfin/.env` file (prefixed with `RAYFIN_SECRET_`) and securely apply them to the remote Rayfin item workload. Validates that secrets are persisted. Use `--env-file <path>` to specify a custom .env file location. |
55
56
  | `npx rayfin up staticapp deploy` | Build, package, and deploy static content to the remote Rayfin item. Add `--skip-build` to deploy existing build output without rebuilding. |
56
57
 
57
58
  ## Update the CLI
@@ -0,0 +1,196 @@
1
+ ---
2
+ sidebar_position: 50
3
+ ---
4
+
5
+ # Managing Secrets
6
+
7
+ The Rayfin CLI provides secure secret management for your remote deployments.
8
+ Secrets are encrypted and stored securely in your Rayfin item workload.
9
+
10
+ ## Overview
11
+
12
+ Use the `rayfin up secrets apply` command to manage application secrets for your remote deployment.
13
+ Secrets are read from your `.env` file, securely transmitted to your workload, encrypted, and validated.
14
+
15
+ ## Setting up secrets
16
+
17
+ ### 1. Define secrets in `.env`
18
+
19
+ Create a `rayfin/.env` file with secrets prefixed using `RAYFIN_SECRET_`:
20
+
21
+ ```bash
22
+ # rayfin/.env
23
+ RAYFIN_SECRET_API_KEY=sk-prod-abc123xyz789
24
+ RAYFIN_SECRET_DATABASE_PASSWORD=secure-db-pass-123
25
+ RAYFIN_SECRET_AUTH_TOKEN=token-abcdefg-hijklmn
26
+ RAYFIN_SECRET_OPENAI_KEY=sk-openai-your-key-here
27
+ ```
28
+
29
+ > **Secret naming:** Secret names must follow the `RAYFIN_SECRET_` prefix convention.
30
+ > The part after the prefix becomes your secret name.
31
+ > For example, `RAYFIN_SECRET_API_KEY` creates a secret named `API_KEY`.
32
+
33
+ ### 2. Deploy your item
34
+
35
+ Before managing secrets, deploy your project to Microsoft Fabric:
36
+
37
+ ```bash
38
+ npx rayfin up
39
+ ```
40
+
41
+ This creates your Rayfin item and sets up the workload endpoint.
42
+
43
+ ### 3. Apply secrets
44
+
45
+ Apply your secrets to the remote workload:
46
+
47
+ ```bash
48
+ npx rayfin up secrets apply
49
+ ```
50
+
51
+ The CLI will:
52
+ 1. Read your `rayfin/.env` file
53
+ 2. Extract all `RAYFIN_SECRET_*` variables
54
+ 3. Securely send each secret to your workload
55
+ 4. Encrypt and persist the secrets
56
+ 5. Validate that all secrets were successfully saved
57
+
58
+ ### 4. Verify secrets
59
+
60
+ After running the apply command, you'll see output confirming each secret:
61
+
62
+ ```text
63
+ 🔐 Acquiring authentication token...
64
+ ✓ Token acquired
65
+ 📤 Sending 4 secret(s) to workload...
66
+ ✓ Secrets sent to workload (4 persisted)
67
+ ✅ Validating secrets persisted to workload...
68
+ ✓ All secrets validated
69
+
70
+ ✨ Secrets applied successfully (4/4)
71
+ ✓ API_KEY
72
+ ✓ DATABASE_PASSWORD
73
+ ✓ AUTH_TOKEN
74
+ ✓ OPENAI_KEY
75
+ ```
76
+
77
+ ## Advanced usage
78
+
79
+ ### Custom .env file location
80
+
81
+ If your secrets are in a non-standard location, use the `--env-file` option:
82
+
83
+ ```bash
84
+ npx rayfin up secrets apply --env-file ./config/secrets.env
85
+ ```
86
+
87
+ ### JSON output
88
+
89
+ For automation or scripting, use `--json` for machine-readable output:
90
+
91
+ ```bash
92
+ npx rayfin up secrets apply --json
93
+ ```
94
+
95
+ Output example:
96
+
97
+ ```json
98
+ {
99
+ "status": "success",
100
+ "message": "All secrets applied and validated",
101
+ "secretsCount": 4,
102
+ "persisted": 4,
103
+ "validated": true,
104
+ "secrets": [
105
+ {
106
+ "name": "API_KEY",
107
+ "id": "secret-123",
108
+ "createdAt": "2026-04-17T10:30:00Z"
109
+ }
110
+ ]
111
+ }
112
+ ```
113
+
114
+ ### Verbose logging
115
+
116
+ Enable detailed logging for debugging:
117
+
118
+ ```bash
119
+ npx rayfin up secrets apply --verbose
120
+ ```
121
+
122
+ ### Non-interactive mode
123
+
124
+ Use `-y` or `--yes` to skip confirmation prompts:
125
+
126
+ ```bash
127
+ npx rayfin up secrets apply -y
128
+ ```
129
+
130
+ ## Secret handling and security
131
+
132
+ ### Encryption
133
+
134
+ Secrets are transmitted over HTTPS with encrypted payloads.
135
+ The workload endpoint encrypts and persists secrets securely.
136
+ Secrets are never logged or displayed after being sent to the workload.
137
+
138
+ ### Best practices
139
+
140
+ 1. **Use `.env` files for local development only** – Never commit `.env` files to version control.
141
+ Add `.env` to your `.gitignore`:
142
+
143
+ ```bash
144
+ echo "rayfin/.env" >> .gitignore
145
+ ```
146
+
147
+ 2. **Use environment variables for CI/CD** – In automated environments, set `RAYFIN_SECRET_*` variables directly:
148
+
149
+ ```bash
150
+ export RAYFIN_SECRET_API_KEY=prod-key-from-vault
151
+ npx rayfin up secrets apply
152
+ ```
153
+
154
+ 3. **Rotate secrets regularly** – Re-run `rayfin up secrets apply` after updating secret values in your `.env` file.
155
+
156
+ 4. **Separate development and production secrets** – Use different `.env` files or environment variables for each environment.
157
+
158
+ ## Troubleshooting
159
+
160
+ ### No secrets found
161
+
162
+ If you see "No secrets found in .env file", verify:
163
+
164
+ - Your `.env` file exists at `rayfin/.env`
165
+ - Variables are prefixed with `RAYFIN_SECRET_`
166
+ - The file is readable by the CLI process
167
+
168
+ ### Authentication failed
169
+
170
+ If you see "Failed to acquire authentication token":
171
+
172
+ - Run `npx rayfin login` to sign in
173
+ - Check that you have valid Entra ID credentials
174
+ - On containers or restricted environments, use `--encryption-fallback-enabled` or set `RAYFIN_ENCRYPTION_FALLBACK_ENABLED=true`
175
+
176
+ ### Validation inconclusive
177
+
178
+ If some secrets fail validation:
179
+
180
+ - Check your network connection to Fabric
181
+ - Verify the workload endpoint is running and healthy
182
+ - Run `npx rayfin up status` to confirm deployment health
183
+ - Re-run `npx rayfin up secrets apply` to retry
184
+
185
+ ### Permission denied
186
+
187
+ If you see permission errors:
188
+
189
+ - Ensure you're authenticated with an account that has access to the Fabric workspace
190
+ - Verify you have the correct workspace selected
191
+ - Run `npx rayfin login --select` to choose a different account/tenant
192
+
193
+ ## See also
194
+
195
+ - [CLI quickstart](./quickstart.md)
196
+ - [Environment configuration](./env-interpolation.md)
@@ -34,6 +34,9 @@ Rayfin's fluent client produces DAB-compliant GraphQL and returns typed entities
34
34
  The GraphQL fluent client is available as `client.data.<Entity>`.
35
35
  Some older examples may show `client.data.gql.<Entity>`.
36
36
 
37
+ Required `@text()` fields return an empty string when the stored value is empty.
38
+ Optional `@text({ optional: true })` fields preserve `null` so apps can distinguish an intentionally missing value from empty text.
39
+
37
40
  ### Read multiple records
38
41
 
39
42
  Here is an example to read records and order by a column.
@@ -259,7 +262,7 @@ const env = loadEnv();
259
262
  const client = new RayfinClient<AppSchema>({
260
263
  baseUrl: env['VITE_RAYFIN_API_URL'],
261
264
  publishableKey: env['VITE_RAYFIN_PUBLISHABLE_KEY'],
262
- authStorage: false, // Required — Node.js has no localStorage
265
+ authStorage: false, // Optional — Node.js has no localStorage but Auth auto-detects
263
266
  });
264
267
 
265
268
  async function seed() {
@@ -295,7 +298,8 @@ Run with `npx tsx scripts/seed.ts`, or add `"seed": "npx tsx scripts/seed.ts"` t
295
298
 
296
299
  Key rules:
297
300
 
298
- - Set `authStorage: false` — Node.js has no `localStorage` and the client will crash without it.
301
+ - Set `authStorage: false` — disables session persistence in Node.js scripts.
302
+ This is optional since Auth now auto-detects Node.js and falls back to memory-only storage, but explicit `false` makes intent clear.
299
303
  - Read `baseUrl` and `publishableKey` from `.env`, not hardcoded values — the port and key vary per project.
300
304
  - Email/password auth works for **local development seeding only**.
301
305
  Deployed Fabric apps use Entra SSO exclusively.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/rayfin-guide",
3
- "version": "1.34.0-alpha.1148",
3
+ "version": "1.34.0-alpha.1201",
4
4
  "description": "Cross-cutting Builder guides for the Rayfin platform — discovered by `@microsoft/rayfin-docs` via the `rayfinDocs` package.json field convention.",
5
5
  "type": "module",
6
6
  "files": [