@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.
- package/README.md +77 -153
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,198 +1,122 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Upfiles Packages Plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A comprehensive package solution for managing projects and API keys in Upfiles applications.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
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
|
-
|
|
19
|
-
pnpm add @thetechfossil/upfiles
|
|
23
|
+
## API Routes
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
yarn add @thetechfossil/upfiles
|
|
23
|
-
```
|
|
25
|
+
### Projects
|
|
24
26
|
|
|
25
|
-
|
|
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
|
-
|
|
30
|
+
### API Keys
|
|
28
31
|
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
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
|
-
|
|
36
|
+
## Package Components
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
### 1. Dialog Component
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
The `ProjectKeyDialog` component provides a complete UI for managing projects and API keys:
|
|
39
41
|
|
|
40
42
|
```tsx
|
|
41
|
-
import
|
|
43
|
+
import ProjectKeyDialog from "@thetechfossil/upfiles/packages/dialog/ProjectKeyDialog";
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
function MyComponent() {
|
|
44
46
|
return (
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
onComplete={(files) => {
|
|
50
|
-
console.log('uploaded:', files);
|
|
47
|
+
<ProjectKeyDialog
|
|
48
|
+
userId="user-123"
|
|
49
|
+
onProjectSelected={(projectId) => {
|
|
50
|
+
// Handle project selection
|
|
51
51
|
}}
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
134
|
-
|
|
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
|
-
|
|
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 {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
98
|
+
## Usage Examples
|
|
155
99
|
|
|
156
|
-
|
|
100
|
+
See `packages/examples/usageExample.ts` for detailed usage examples.
|
|
157
101
|
|
|
158
|
-
|
|
159
|
-
import { ProjectFilesWidget } from '@thetechfossil/upfiles';
|
|
102
|
+
## Comprehensive Package Documentation
|
|
160
103
|
|
|
161
|
-
|
|
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
|
-
|
|
174
|
-
// { name, key, url, size, contentType }
|
|
175
|
-
console.log('Selected:', f.name, f.key);
|
|
176
|
-
}}
|
|
106
|
+
## Integration
|
|
177
107
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
-
|
|
190
|
-
-
|
|
191
|
-
-
|
|
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
|
-
|
|
120
|
+
## License
|
|
195
121
|
|
|
196
|
-
|
|
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.
|
|
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"
|