@shiftengineering/folio 0.1.18 → 0.1.20

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/README.md CHANGED
@@ -27,6 +27,7 @@ This package exports three main features:
27
27
  - `useAddFolioProject` - Create new projects
28
28
  - `useAddFolioFiles` - Add files to a project
29
29
  - `useAddFolioDirectoriesWithFiles` - Add directories with files to a project
30
+ - `useFolioUserMetadata` - Get and update user metadata
30
31
 
31
32
  ### Secure Token Handling
32
33
 
@@ -62,8 +63,19 @@ import App from "./App";
62
63
  // The token must be a valid JWT that the Folio backend is configured to accept
63
64
  const token = "your-jwt-auth-token";
64
65
 
66
+ // Optional user metadata to personalize AI responses
67
+ const userMetadata = {
68
+ role: "Sales Representative",
69
+ industry: "Healthcare",
70
+ };
71
+
65
72
  ReactDOM.render(
66
- <FolioProvider host="http://your-folio-server.com" port={5174} token={token}>
73
+ <FolioProvider
74
+ host="http://your-folio-server.com"
75
+ port={5174}
76
+ token={token}
77
+ userMetadata={userMetadata}
78
+ >
67
79
  <App />
68
80
  </FolioProvider>,
69
81
  document.getElementById("root"),
@@ -103,6 +115,7 @@ import {
103
115
  useAddFolioProject,
104
116
  useAddFolioFiles,
105
117
  useAddFolioDirectoriesWithFiles,
118
+ useFolioUserMetadata,
106
119
  type DirectoryEntry,
107
120
  type MetadataValue,
108
121
  } from "@shiftengineering/folio";
@@ -121,6 +134,13 @@ function FolioProjectManager() {
121
134
  // Get files for the selected project
122
135
  const { files, isLoading: isFilesLoading } = useFolioFiles(selectedProjectId);
123
136
 
137
+ // Get and update user metadata
138
+ const {
139
+ metadata: userMetadata,
140
+ updateMetadata,
141
+ isLoading: isMetadataLoading
142
+ } = useFolioUserMetadata();
143
+
124
144
  // Add a new project
125
145
  const { addProject, isAdding: isCreatingProject } = useAddFolioProject();
126
146
 
@@ -136,6 +156,14 @@ function FolioProjectManager() {
136
156
  addProject("My New Project");
137
157
  };
138
158
 
159
+ const handleUpdateUserMetadata = () => {
160
+ updateMetadata({
161
+ role: "Project Manager",
162
+ industry: "Finance",
163
+ interestedIn: "State contracts"
164
+ });
165
+ };
166
+
139
167
  const handleAddFile = () => {
140
168
  addFiles([{ blobUrl: "/path/to/file.pdf", name: "My Document.pdf" }]);
141
169
  };
@@ -384,13 +412,14 @@ Both approaches allow host applications to consume the same events regardless of
384
412
 
385
413
  Context provider that manages Folio application connection settings.
386
414
 
387
- | Prop | Type | Default | Description |
388
- | ----------------------- | ------------------------------- | -------------------- | ----------------------------------------------------------------------------------- |
389
- | `host` | string | `'http://localhost'` | Host for the Folio API and iframe |
390
- | `port` | number | `5174` | Port for the Folio API and iframe |
391
- | `token` | string | - | JWT authentication token that the Folio backend is configured to accept |
392
- | `onAnalyticsEvent` | (event: AnalyticsEvent) => void | - | Optional callback for handling analytics events from Folio |
393
- | `passTokenInQueryParam` | boolean | `false` | Whether to pass the token in URL (legacy, less secure) instead of using postMessage |
415
+ | Prop | Type | Default | Description |
416
+ | ----------------------- | ------------------------------- | -------------------- | ------------------------------------------------------------------------------------ |
417
+ | `host` | string | `'http://localhost'` | Host for the Folio API and iframe |
418
+ | `port` | number | `5174` | Port for the Folio API and iframe |
419
+ | `token` | string | - | JWT authentication token that the Folio backend is configured to accept |
420
+ | `userMetadata` | Record<string, MetadataValue> | - | Optional metadata for the current user that will be used to personalize AI responses |
421
+ | `onAnalyticsEvent` | (event: AnalyticsEvent) => void | - | Optional callback for handling analytics events from Folio |
422
+ | `passTokenInQueryParam` | boolean | `false` | Whether to pass the token in URL (legacy, less secure) instead of using postMessage |
394
423
 
395
424
  ### FolioEmbed
396
425
 
@@ -470,15 +499,30 @@ Hook for adding one or more directories with files to a project. Directory names
470
499
  | `error` | `Error \| null` | Error object if an error occurred |
471
500
  | `result` | `{ directory: FolioFile \| null; files: FolioFile[] } \| Array<{ directory: FolioFile \| null; files: FolioFile[] }> \| undefined` | The newly added directories and files. If a directory is null in a result, it means a directory with that name already existed |
472
501
 
502
+ #### `useFolioUserMetadata()`
503
+
504
+ Hook for retrieving and updating the current user's metadata.
505
+
506
+ | Return Property | Type | Description |
507
+ | --------------------- | ------------------------------------------------------------ | ---------------------------------------- |
508
+ | `metadata` | `string \| null` | The user's metadata as a string, or null |
509
+ | `isLoading` | `boolean` | Whether metadata is being loaded |
510
+ | `isError` | `boolean` | Whether an error occurred |
511
+ | `error` | `Error \| null` | Error object if an error occurred |
512
+ | `updateMetadata` | `(metadata: Record<string, MetadataValue>) => void` | Function to update user metadata |
513
+ | `updateMetadataAsync` | `(metadata: Record<string, MetadataValue>) => Promise<void>` | Async version returning a promise |
514
+ | `isUpdating` | `boolean` | Whether metadata is being updated |
515
+ | `refetch` | `() => Promise<...>` | Function to manually refetch metadata |
516
+
473
517
  ## Types
474
518
 
475
519
  The library exports these TypeScript types:
476
520
 
477
521
  | Type | Description |
478
522
  | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
479
- | `FolioFile` | Represents a file in Folio. Contains properties: `id`, `name`, `blobUrl`, `parentId` (null for root items), and `isDirectory` (boolean) |
480
- | `FolioProject` | Represents a project in Folio |
481
- | `MetadataValue` | Represents metadata values that can be nested. Can be a string, number, boolean, null, object, or array of these types |
523
+ | `FolioFile` | Represents a file in Folio. Contains properties: `id`, `name`, `blobUrl`, `parentId` (null for root items), `isDirectory` (boolean), `createdAt` (Date), and `updatedAt` (Date) |
524
+ | `FolioProject` | Represents a project in Folio. Contains properties: `id`, `name`, `createdAt` (Date), and `updatedAt` (Date) |
525
+ | `MetadataValue` | Represents metadata values that can be nested. Can be a string, number, boolean, null, object, or array of these types. Used for both directory metadata and user metadata. |
482
526
  | `DirectoryEntry` | Represents a directory with metadata and files to be added to Folio. Contains properties: `directoryName`, `directoryMetadata` (now supports nested objects), and `files` |
483
527
  | `AnalyticsEvent` | A union type for analytics events sent by Folio. Each event has a `name` property (like "page_view" or "file_view") and a `data` object with event-specific parameters. See the [Analytics Event Structure](#analytics-event-structure) section for details on all event types. |
484
528
  | `FolioEmbedProps` | Props for the FolioEmbed component |