@thetechfossil/upfiles 0.4.0 → 0.6.0

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.
Files changed (2) hide show
  1. package/README.md +77 -153
  2. package/package.json +5 -2
package/README.md CHANGED
@@ -1,198 +1,122 @@
1
- # @thetechfossil/upfiles
1
+ # Upfiles Packages Plugin
2
2
 
3
- Lightweight JavaScript client and React component to upload files via a presigned S3 flow. Similar to UploadThing-like DX.
3
+ A comprehensive package solution for managing projects and API keys in Upfiles applications.
4
4
 
5
- - Client: get presigned URLs and PUT to S3
6
- - React `<Uploader />`: drag/drop, progress, single/multiple, accepts/types, size limits
7
- - React `<ProjectFilesWidget />`: list all files for a project (Plugin API), pick one, and optionally auto-save to your app
5
+ ## Overview
6
+
7
+ This package provides both a user-friendly dialog interface and reusable functions for managing projects and API keys. It allows developers to either use the pre-built dialog component or integrate the underlying logic directly into their applications.
8
+
9
+ ## Features
10
+
11
+ - Multi-functional dialog for managing projects and API keys
12
+ - Reusable functions for programmatic integration
13
+ - Full CRUD operations for projects and API keys
14
+ - Authentication-aware API interactions
15
+ - TypeScript support with comprehensive type definitions
8
16
 
9
17
  ## Installation
10
18
 
11
19
  ```bash
12
- # Bun (recommended)
13
- bun add @thetechfossil/upfiles
14
-
15
- # npm
16
20
  npm install @thetechfossil/upfiles
21
+ ```
17
22
 
18
- # pnpm
19
- pnpm add @thetechfossil/upfiles
23
+ ## API Routes
20
24
 
21
- # yarn
22
- yarn add @thetechfossil/upfiles
23
- ```
25
+ ### Projects
24
26
 
25
- ## Server prerequisites
27
+ - `GET /api/packages/projects` - List all projects for the current user
28
+ - `POST /api/packages/projects` - Create a new project for the current user
26
29
 
27
- Your Upfiles app must expose the Plugin API presign endpoint:
30
+ ### API Keys
28
31
 
29
- - Method: `POST`
30
- - Path: `/api/plugin/upload/presigned-url` (default; configurable)
31
- - Body: `{ fileName, fileType, fileSize, folderPath?, projectId? }` (`fileSize` is required)
32
- - Response: `{ presignedUrl, fileKey, publicUrl, apiKeyId?, projectId? }`
32
+ - `GET /api/packages/projects/{projectId}/keys` - List API keys for a project
33
+ - `POST /api/packages/projects/{projectId}/keys` - Create a new API key for a project
34
+ - `DELETE /api/packages/projects/{projectId}/keys` - Revoke an API key
33
35
 
34
- This repository already provides a Next.js route at `src/app/api/plugin/upload/presigned-url/route.ts`.
36
+ ## Package Components
35
37
 
36
- For plugins/packages calling across origins, authenticate using an API key header as documented below. CORS must allow your plugin origin.
38
+ ### 1. Dialog Component
37
39
 
38
- ## Basic usage (React)
40
+ The `ProjectKeyDialog` component provides a complete UI for managing projects and API keys:
39
41
 
40
42
  ```tsx
41
- import { Uploader } from '@thetechfossil/upfiles';
43
+ import ProjectKeyDialog from "@thetechfossil/upfiles/packages/dialog/ProjectKeyDialog";
42
44
 
43
- export default function Page() {
45
+ function MyComponent() {
44
46
  return (
45
- <Uploader
46
- multiple
47
- accept={["image/*", "application/pdf"]}
48
- maxFileSize={100 * 1024 * 1024}
49
- onComplete={(files) => {
50
- console.log('uploaded:', files);
47
+ <ProjectKeyDialog
48
+ userId="user-123"
49
+ onProjectSelected={(projectId) => {
50
+ // Handle project selection
51
51
  }}
52
- onError={(err) => {
53
- console.error(err);
52
+ onApiKeySaved={(apiKey) => {
53
+ // Handle API key creation
54
54
  }}
55
- dropzoneClassName="border border-dashed rounded-md p-6 cursor-pointer"
56
- buttonClassName="px-3 py-2 rounded bg-blue-600 text-white"
57
- // Optional: pass clientOptions for cross-origin + API key auth
58
- // clientOptions={{
59
- // baseUrl: 'https://YOUR_APP_HOST',
60
- // // or presignUrl: 'https://YOUR_APP_HOST/api/plugin/upload/presigned-url',
61
- // apiKey: process.env.NEXT_PUBLIC_UPFILES_API_KEY!,
62
- // apiKeyHeader: 'authorization', // or 'x-api-key' | 'x-up-api-key'
63
- // }}
64
55
  />
65
56
  );
66
57
  }
67
58
  ```
68
59
 
69
- ## Basic usage (vanilla JS)
70
-
71
- ```ts
72
- import { UpfilesClient } from '@thetechfossil/upfiles';
73
-
74
- // Same-origin by default; only set these when needed:
75
- const client = new UpfilesClient({
76
- // presignUrl: 'https://YOUR_APP_HOST/api/plugin/upload/presigned-url', // full override
77
- // baseUrl: 'https://YOUR_APP_HOST', // used with presignPath
78
- // presignPath: '/api/plugin/upload/presigned-url', // default
79
- // withCredentials: true, // for session routes (not typical for Plugin API)
80
- // Provide API key for Plugin API auth:
81
- // apiKey: 'upk_...'
82
- // apiKeyHeader: 'authorization' // or 'x-api-key' | 'x-up-api-key'
83
- });
84
-
85
- async function upload(file) {
86
- const { presignedUrl, publicUrl } = await client.getPresignedUrl({
87
- fileName: file.name,
88
- fileType: file.type,
89
- fileSize: file.size, // required
90
- folderPath: 'my-plugin/uploads/',
91
- });
92
- const res = await client.uploadToS3(presignedUrl, file);
93
- if (!res.ok) throw new Error('Upload failed');
94
- return publicUrl;
95
- }
96
- ```
60
+ ### 2. Reusable Functions
97
61
 
98
- ## API
99
-
100
- - `new UpfilesClient(options)`
101
- - `presignUrl` (optional): full absolute URL to presign endpoint. Highest priority.
102
- - `baseUrl` (optional): API base origin. Used with `presignPath`.
103
- - `presignPath` (optional): relative path, default `/api/plugin/upload/presigned-url`.
104
- - `headers` (optional): extra headers to send.
105
- - `apiKey` (optional): API key value (e.g., `upk_...`).
106
- - `apiKeyHeader` (optional): one of `'authorization' | 'x-api-key' | 'x-up-api-key'` (default `'authorization'`). If `'authorization'`, `Bearer` prefix is auto-added for `upk_...`.
107
- - `withCredentials` (optional): `true` to send cookies.
108
- - Defaults: same-origin requests to `/api/plugin/upload/presigned-url`.
109
- - `client.getPresignedUrl({ fileName, fileType, fileSize, projectId?, folderPath? })`
110
- - `client.uploadToS3(presignedUrl, file)`
111
- - `client.upload(file, { projectId?, folderPath?, fetchThumbnails? })` → returns `{ publicUrl, fileKey, fileName, fileType, fileSize, projectId?, apiKeyId?, thumbnails? }`
112
- - `client.getThumbnails(fileKey)` → returns `Thumbnail[]`
113
- - `client.getProjectFiles({ folderPath? })` → returns `FileListItem[]`
114
-
115
- - `<Uploader />` props
116
- - `clientOptions` (optional): same as `UpfilesClient` options (only needed for cross-origin or auth customization)
117
- - `multiple` (default true)
118
- - `accept` (array of MIME patterns)
119
- - `maxFileSize` (bytes, default 100MB)
120
- - `maxFiles` (default 10)
121
- - `fetchThumbnails` (boolean): if true, fetch thumbnails after upload via Plugin API
122
- - `onComplete(files)` and `onError(error)`
123
- - `className`, `buttonClassName`, `dropzoneClassName`
124
- - `children`: custom dropzone inner content
125
-
126
- ### Thumbnails usage
127
-
128
- Your Upfiles app exposes `GET /api/plugin/thumbnails?fileKey=...` for plugins. Enable `fetchThumbnails` to auto-fetch after upload, or call `client.getThumbnails(fileKey)` yourself.
129
-
130
- Example with `client.upload`:
62
+ #### Project Management
131
63
 
132
64
  ```ts
133
- const result = await client.upload(file, { folderPath: 'my-plugin/', fetchThumbnails: true });
134
- console.log(result.thumbnails);
65
+ import {
66
+ listProjects,
67
+ createProject,
68
+ updateProject,
69
+ deleteProject,
70
+ } from "@thetechfossil/upfiles/packages/projectManager";
71
+
72
+ // List projects
73
+ const { projects } = await listProjects("user-123");
74
+
75
+ // Create project
76
+ const newProject = await createProject("user-123", { name: "My Project" });
135
77
  ```
136
78
 
137
- ### List project files (Plugin API)
138
-
139
- Your Upfiles app exposes `GET /api/plugin/files?folderPath=...` for plugins (API key auth + CORS). The client can call it via `getProjectFiles`:
79
+ #### API Key Management
140
80
 
141
81
  ```ts
142
- import { UpfilesClient } from '@thetechfossil/upfiles';
143
-
144
- const client = new UpfilesClient({
145
- baseUrl: 'https://YOUR_APP_HOST',
146
- apiKey: 'upk_...',
147
- thumbnailsPath: '/api/plugin/thumbnails', // used to derive /api/plugin/files
82
+ import {
83
+ listApiKeys,
84
+ createApiKey,
85
+ revokeApiKey,
86
+ } from "@thetechfossil/upfiles/packages/apiKeyManager";
87
+
88
+ // List API keys
89
+ const { keys } = await listApiKeys("project-456");
90
+
91
+ // Create API key
92
+ const { key } = await createApiKey({
93
+ projectId: "project-456",
94
+ name: "CI Pipeline Key",
148
95
  });
149
-
150
- const files = await client.getProjectFiles({ folderPath: 'optional/subfolder' });
151
- // [{ key, originalName, size, contentType, uploadedAt, url }, ...]
152
96
  ```
153
97
 
154
- ### `<ProjectFilesWidget />`
98
+ ## Usage Examples
155
99
 
156
- Simple UI to fetch and select a file for the project tied to the API key. Emits the selection, and can optionally POST it to your backend.
100
+ See `packages/examples/usageExample.ts` for detailed usage examples.
157
101
 
158
- ```tsx
159
- import { ProjectFilesWidget } from '@thetechfossil/upfiles';
102
+ ## Comprehensive Package Documentation
160
103
 
161
- export default function PickFile() {
162
- return (
163
- <ProjectFilesWidget
164
- clientOptions={{
165
- baseUrl: 'https://YOUR_APP_HOST',
166
- apiKey: process.env.NEXT_PUBLIC_UPFILES_API_KEY!,
167
- apiKeyHeader: 'authorization',
168
- thumbnailsPath: '/api/plugin/thumbnails',
169
- }}
170
- // Optional: filter within a folder
171
- // folderPath="my-plugin/"
104
+ For detailed package documentation including installation instructions, configuration options, usage examples, available methods and functions, parameter specifications, return value descriptions, troubleshooting guides, best practices, and detailed explanations of all package features and capabilities, see: [`docs/PACKAGE_DOCUMENTATION.md`](docs/PACKAGE_DOCUMENTATION.md)
172
105
 
173
- onSelect={(f) => {
174
- // { name, key, url, size, contentType }
175
- console.log('Selected:', f.name, f.key);
176
- }}
106
+ ## Integration
177
107
 
178
- // Optional: built-in save
179
- // saveUrl="/api/files/save" // Your app route to persist selection
180
- // onSave={async (f) => { await fetch('/api/files/save', { method: 'POST', body: JSON.stringify(f) }); }}
181
- // onSaved={(result) => console.log('Saved!', result)}
182
- />
183
- );
184
- }
185
- ```
108
+ The package can be integrated into existing applications by:
109
+
110
+ 1. Using the dialog component for user-facing interfaces
111
+ 2. Calling the reusable functions for programmatic operations
112
+ 3. Implementing custom UI components that use the same underlying logic
186
113
 
187
- ## Notes
114
+ ## Security Notes
188
115
 
189
- - Dev with Vite: configure a proxy so `/api/*` maps to your backend (e.g., `http://localhost:4000`), then `<Uploader />` works with no config.
190
- - Ensure CORS where applicable (S3 bucket CORS; and set `PLUGIN_ALLOWED_ORIGINS` on your Upfiles app for cross-origin Plugin API calls).
191
- - For cross-origin with cookies (NextAuth), set `withCredentials: true` and configure your server to allow credentials.
192
- Plugin API typically uses API keys instead of cookies.
116
+ - API keys are only returned once during creation (plaintext version)
117
+ - All operations are authenticated and scoped to the current user
118
+ - Revoked keys are marked as inactive but remain in the database
193
119
 
194
- ### Plugin endpoints provided by this repo
120
+ ## License
195
121
 
196
- - `POST /api/plugin/upload/presigned-url` – generate presigned S3 URL for upload
197
- - `GET /api/plugin/thumbnails?fileKey=...` – list thumbnails for a file
198
- - `GET /api/plugin/files?folderPath=...` – list project files (API key scoped), optional folder prefix
122
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thetechfossil/upfiles",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Lightweight client and React components for Upfiles Plugin API (presigned S3)",
5
5
  "license": "MIT",
6
6
  "author": "UpFiles",
@@ -28,7 +28,10 @@
28
28
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",
29
29
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
30
30
  "typecheck": "tsc -p tsconfig.json --noEmit",
31
- "prepublishOnly": "bun run build"
31
+ "prepublishOnly": "bun run build",
32
+ "todo:list": "node scripts/todo-manager.js list",
33
+ "todo:complete": "node scripts/todo-manager.js complete",
34
+ "todo:add": "node scripts/todo-manager.js add"
32
35
  },
33
36
  "peerDependencies": {
34
37
  "react": ">=18"