@shiftengineering/folio 0.1.5 → 0.1.6

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
@@ -26,7 +26,7 @@ This package exports three main features:
26
26
  - `useFolioFiles` - Get files for a project
27
27
  - `useAddFolioProject` - Create new projects
28
28
  - `useAddFolioFiles` - Add files to a project
29
- - `useAddFolioDirectoryWithFiles` - Add directories with files to a project
29
+ - `useAddFolioDirectoriesWithFiles` - Add directories with files to a project
30
30
 
31
31
  ### Basic Setup
32
32
 
@@ -79,8 +79,9 @@ import {
79
79
  useFolioFiles,
80
80
  useAddFolioProject,
81
81
  useAddFolioFiles,
82
- useAddFolioDirectoryWithFiles,
82
+ useAddFolioDirectoriesWithFiles,
83
83
  type DirectoryEntry,
84
+ type MetadataValue,
84
85
  } from "@shiftengineering/folio";
85
86
  import { useState } from "react";
86
87
 
@@ -105,8 +106,8 @@ function FolioProjectManager() {
105
106
  useAddFolioFiles(selectedProjectId);
106
107
 
107
108
  // Add directories with files to a project
108
- const { addDirectoryWithFiles, isAdding: isAddingDirectory } =
109
- useAddFolioDirectoryWithFiles(selectedProjectId);
109
+ const { addDirectoriesWithFiles, isAdding: isAddingDirectory } =
110
+ useAddFolioDirectoriesWithFiles(selectedProjectId);
110
111
 
111
112
  const handleCreateProject = () => {
112
113
  addProject("My New Project");
@@ -117,10 +118,18 @@ function FolioProjectManager() {
117
118
  };
118
119
 
119
120
  const handleAddSingleDirectory = () => {
120
- // Create metadata as a simple object
121
+ // Create metadata with nested structure
121
122
  const metadata = {
122
123
  category: "reports",
123
- owner: "John Doe"
124
+ details: {
125
+ owner: "John Doe",
126
+ department: "Finance",
127
+ tags: ["important", "quarterly"],
128
+ },
129
+ status: {
130
+ reviewed: true,
131
+ approvalDate: "2023-10-15"
132
+ }
124
133
  };
125
134
 
126
135
  const directoryEntry: DirectoryEntry = {
@@ -132,17 +141,31 @@ function FolioProjectManager() {
132
141
  ],
133
142
  };
134
143
 
135
- addDirectoryWithFiles(directoryEntry);
144
+ addDirectoriesWithFiles(directoryEntry);
136
145
  };
137
146
 
138
147
  const handleAddMultipleDirectories = () => {
139
- // Create metadata for each directory as simple objects
148
+ // Create metadata for each directory with nested structures
140
149
  const metadata1 = {
141
- category: "reports"
150
+ category: "reports",
151
+ details: {
152
+ owner: "Jane Smith",
153
+ department: "Accounting",
154
+ tags: ["quarterly", "financial"]
155
+ }
142
156
  };
143
157
 
144
158
  const metadata2 = {
145
- category: "contracts"
159
+ category: "contracts",
160
+ details: {
161
+ owner: "Legal Team",
162
+ priority: "high",
163
+ clients: ["Acme Inc", "Globex Corp"]
164
+ },
165
+ approvalChain: {
166
+ legalApproved: true,
167
+ executiveApproved: false
168
+ }
146
169
  };
147
170
 
148
171
  const directories: DirectoryEntry[] = [
@@ -164,7 +187,7 @@ function FolioProjectManager() {
164
187
  },
165
188
  ];
166
189
 
167
- addDirectoryWithFiles(directories);
190
+ addDirectoriesWithFiles(directories);
168
191
  };
169
192
 
170
193
  if (isProjectsLoading) return <div>Loading projects...</div>;
@@ -297,30 +320,31 @@ Hook for adding files to a project. Files are always created at the root level (
297
320
  | `error` | `Error \| null` | Error object if an error occurred |
298
321
  | `newFiles` | `FolioFile[] \| undefined` | The newly added files if available |
299
322
 
300
- #### `useAddFolioDirectoryWithFiles(projectId?: number)`
323
+ #### `useAddFolioDirectoriesWithFiles(projectId?: number)`
301
324
 
302
325
  Hook for adding one or more directories with files to a project. Directory names must be unique at the root level (duplicates will be silently skipped with a console warning).
303
326
 
304
- | Return Property | Type | Description |
305
- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
306
- | `addDirectoryWithFiles` | `(params: DirectoryEntry \| DirectoryEntry[]) => void` | Function to add one or more directories with files |
307
- | `addDirectoryWithFilesAsync` | `(params: DirectoryEntry \| DirectoryEntry[]) => Promise<{ directory: FolioFile \| null; files: FolioFile[] } \| Array<{ directory: FolioFile \| null; files: FolioFile[] }>>` | Async version returning a promise. Returns a single result when given a single directory, or an array of results when given multiple directories |
308
- | `isAdding` | `boolean` | Whether the directories and files are being added |
309
- | `isError` | `boolean` | Whether an error occurred |
310
- | `error` | `Error \| null` | Error object if an error occurred |
311
- | `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 |
327
+ | Return Property | Type | Description |
328
+ | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
329
+ | `addDirectoriesWithFiles` | `(params: DirectoryEntry \| DirectoryEntry[]) => void` | Function to add one or more directories with files |
330
+ | `addDirectoriesWithFilesAsync` | `(params: DirectoryEntry \| DirectoryEntry[]) => Promise<{ directory: FolioFile \| null; files: FolioFile[] } \| Array<{ directory: FolioFile \| null; files: FolioFile[] }>>` | Async version returning a promise. Returns a single result when given a single directory, or an array of results when given multiple directories |
331
+ | `isAdding` | `boolean` | Whether the directories and files are being added |
332
+ | `isError` | `boolean` | Whether an error occurred |
333
+ | `error` | `Error \| null` | Error object if an error occurred |
334
+ | `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 |
312
335
 
313
336
  ## Types
314
337
 
315
338
  The library exports these TypeScript types:
316
339
 
317
- | Type | Description |
318
- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
319
- | `FolioFile` | Represents a file in Folio. Contains properties: `id`, `name`, `blobUrl`, `parentId` (null for root items), and `isDirectory` (boolean) |
320
- | `FolioProject` | Represents a project in Folio |
321
- | `DirectoryEntry` | Represents a directory with metadata and files to be added to Folio. Contains properties: `directoryName`, `directoryMetadata` (Record<string, string>), and `files` |
322
- | `FolioEmbedProps` | Props for the FolioEmbed component |
323
- | `FolioProviderProps` | Props for the FolioProvider component |
340
+ | Type | Description |
341
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
342
+ | `FolioFile` | Represents a file in Folio. Contains properties: `id`, `name`, `blobUrl`, `parentId` (null for root items), and `isDirectory` (boolean) |
343
+ | `FolioProject` | Represents a project in Folio |
344
+ | `MetadataValue` | Represents metadata values that can be nested. Can be a string, number, boolean, null, object, or array of these types |
345
+ | `DirectoryEntry` | Represents a directory with metadata and files to be added to Folio. Contains properties: `directoryName`, `directoryMetadata` (now supports nested objects), and `files` |
346
+ | `FolioEmbedProps` | Props for the FolioEmbed component |
347
+ | `FolioProviderProps` | Props for the FolioProvider component |
324
348
 
325
349
  ## License
326
350
 
@@ -11,7 +11,12 @@ import { UseMutateFunction } from '@tanstack/react-query';
11
11
  */
12
12
  export declare type DirectoryEntry = {
13
13
  directoryName: string;
14
- directoryMetadata: Record<string, string>;
14
+ /**
15
+ * Metadata for the directory. Can be a nested structure of objects, arrays, and primitive values.
16
+ * Will be automatically converted to a JSON string before sending to the API.
17
+ * Example: { category: "reports", details: { owner: "John", tags: ["important", "tax"] } }
18
+ */
19
+ directoryMetadata: Record<string, MetadataValue>;
15
20
  files: Omit<FolioFile, "id" | "parentId" | "isDirectory">[];
16
21
  };
17
22
 
@@ -91,6 +96,13 @@ export declare interface FolioProviderProps {
91
96
  token: string;
92
97
  }
93
98
 
99
+ /**
100
+ * Type definition for metadata values that can be nested
101
+ */
102
+ declare type MetadataValue = string | number | boolean | null | {
103
+ [key: string]: MetadataValue;
104
+ } | MetadataValue[];
105
+
94
106
  /**
95
107
  * Hook for adding one or more directories with files to a project
96
108
  * @param projectId The ID of the project to add the directories and files to
@@ -102,7 +114,7 @@ export declare interface FolioProviderProps {
102
114
  * - Files are checked for duplicates based on their path and parent directory.
103
115
  * Files with the same path but in different directories are considered unique.
104
116
  * - Only PDF files are accepted and will be filtered automatically.
105
- * - Metadata is provided as a Record<string, string> and will be automatically
117
+ * - Metadata can be a nested structure of objects, arrays, and primitive values, and will be automatically
106
118
  * converted to a JSON string before sending to the API.
107
119
  * - Can add a single directory or multiple directories in one call.
108
120
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shiftengineering/folio",
3
3
  "private": false,
4
- "version": "0.1.5",
4
+ "version": "0.1.6",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ShiftEngineering/folio.git"
@@ -100,7 +100,7 @@
100
100
  "concurrently": "^9.1.2",
101
101
  "date-fns": "^4.1.0",
102
102
  "embla-carousel-react": "^8.5.2",
103
- "esbuild": "^0.24.2",
103
+ "esbuild": "^0.25.0",
104
104
  "eslint": "^9.19.0",
105
105
  "eslint-plugin-react-hooks": "^5.1.0",
106
106
  "eslint-plugin-react-refresh": "^0.4.18",