upthing-sdk 1.0.2 → 1.0.3
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 +32 -1
- package/dist/index.d.ts +37 -0
- package/dist/index.js +43 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -87,6 +87,37 @@ await upthing.uploadBase64(base64String, "avatar.png");
|
|
|
87
87
|
| `projectUuid` | string | Target project (if key isn't pinned) |
|
|
88
88
|
| `ttlSeconds` | number | Auto-delete after N seconds |
|
|
89
89
|
|
|
90
|
+
### File management
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// List files (paginated)
|
|
94
|
+
const { data, pagination } = await upthing.listFiles({ limit: 20, offset: 0 });
|
|
95
|
+
console.log(`${pagination.total} files total`);
|
|
96
|
+
|
|
97
|
+
// Filter by project
|
|
98
|
+
const { data: projectFiles } = await upthing.listFiles({
|
|
99
|
+
projectUuid: "07595179-...",
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Get a single file
|
|
103
|
+
const file = await upthing.getFile("d98b6a92-...");
|
|
104
|
+
console.log(file.url, file.mime_type, file.size_bytes);
|
|
105
|
+
|
|
106
|
+
// Delete a file (removes S3 object + soft-deletes DB row)
|
|
107
|
+
await upthing.deleteFile("d98b6a92-...");
|
|
108
|
+
|
|
109
|
+
// Generate a signed URL (for files with url_mode: "signed")
|
|
110
|
+
const { url, expires_in } = await upthing.getSignedUrl("d98b6a92-...", 7200);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### List files options
|
|
114
|
+
|
|
115
|
+
| Option | Type | Default | Description |
|
|
116
|
+
| ------------- | ------ | ------- | ------------------------------------ |
|
|
117
|
+
| `projectUuid` | string | — | Filter by project |
|
|
118
|
+
| `limit` | number | 50 | Results per page (1–200) |
|
|
119
|
+
| `offset` | number | 0 | Pagination offset |
|
|
120
|
+
|
|
90
121
|
### Proxy
|
|
91
122
|
|
|
92
123
|
```typescript
|
|
@@ -125,7 +156,7 @@ try {
|
|
|
125
156
|
}
|
|
126
157
|
```
|
|
127
158
|
|
|
128
|
-
|
|
159
|
+
All methods except `proxyUrl()` and `permanentUrl()` require an API key and throw immediately with a helpful message if none was provided.
|
|
129
160
|
|
|
130
161
|
## Browser / React / Next.js usage
|
|
131
162
|
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,23 @@ export interface UploadOptions {
|
|
|
20
20
|
projectUuid?: string;
|
|
21
21
|
ttlSeconds?: number;
|
|
22
22
|
}
|
|
23
|
+
export interface ListFilesOptions {
|
|
24
|
+
projectUuid?: string;
|
|
25
|
+
limit?: number;
|
|
26
|
+
offset?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ListFilesResponse {
|
|
29
|
+
data: UpThingFile[];
|
|
30
|
+
pagination: {
|
|
31
|
+
limit: number;
|
|
32
|
+
offset: number;
|
|
33
|
+
total: number;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface SignedUrlResponse {
|
|
37
|
+
url: string;
|
|
38
|
+
expires_in: number;
|
|
39
|
+
}
|
|
23
40
|
export interface ProxyOptions {
|
|
24
41
|
projectUuid?: string;
|
|
25
42
|
ttlSeconds?: number;
|
|
@@ -53,6 +70,26 @@ export declare class UpThingClient {
|
|
|
53
70
|
* Upload base64-encoded data.
|
|
54
71
|
*/
|
|
55
72
|
uploadBase64(base64Data: string, filename: string, options?: UploadOptions): Promise<UpThingFile>;
|
|
73
|
+
/**
|
|
74
|
+
* List files owned by the authenticated user.
|
|
75
|
+
* Requires the `read` scope if the API key uses scoped permissions.
|
|
76
|
+
*/
|
|
77
|
+
listFiles(options?: ListFilesOptions): Promise<ListFilesResponse>;
|
|
78
|
+
/**
|
|
79
|
+
* Get a single file's metadata by UUID.
|
|
80
|
+
* Requires the `read` scope if the API key uses scoped permissions.
|
|
81
|
+
*/
|
|
82
|
+
getFile(uuid: string): Promise<UpThingFile>;
|
|
83
|
+
/**
|
|
84
|
+
* Delete a file by UUID. Removes the S3 object and soft-deletes the DB row.
|
|
85
|
+
* Requires the `delete` scope if the API key uses scoped permissions.
|
|
86
|
+
*/
|
|
87
|
+
deleteFile(uuid: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Generate a time-limited signed delivery URL for a file.
|
|
90
|
+
* Requires the `read` scope if the API key uses scoped permissions.
|
|
91
|
+
*/
|
|
92
|
+
getSignedUrl(uuid: string, ttlSeconds?: number): Promise<SignedUrlResponse>;
|
|
56
93
|
/**
|
|
57
94
|
* Build a proxy query-string URL (without auth). Useful when the
|
|
58
95
|
* project uses `domain` auth mode and no API key is needed in the
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,47 @@ export class UpThingClient {
|
|
|
46
46
|
ttl_seconds: options?.ttlSeconds,
|
|
47
47
|
}).then((r) => r.file);
|
|
48
48
|
}
|
|
49
|
+
// ── Files ───────────────────────────────────────────────────────────
|
|
50
|
+
/**
|
|
51
|
+
* List files owned by the authenticated user.
|
|
52
|
+
* Requires the `read` scope if the API key uses scoped permissions.
|
|
53
|
+
*/
|
|
54
|
+
async listFiles(options) {
|
|
55
|
+
const params = new URLSearchParams();
|
|
56
|
+
if (options?.projectUuid)
|
|
57
|
+
params.set("project_uuid", options.projectUuid);
|
|
58
|
+
if (options?.limit != null)
|
|
59
|
+
params.set("limit", String(options.limit));
|
|
60
|
+
if (options?.offset != null)
|
|
61
|
+
params.set("offset", String(options.offset));
|
|
62
|
+
const qs = params.toString();
|
|
63
|
+
return this.request("GET", `/api/files${qs ? `?${qs}` : ""}`);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get a single file's metadata by UUID.
|
|
67
|
+
* Requires the `read` scope if the API key uses scoped permissions.
|
|
68
|
+
*/
|
|
69
|
+
async getFile(uuid) {
|
|
70
|
+
return this.request("GET", `/api/files/${uuid}`).then((r) => r.file);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Delete a file by UUID. Removes the S3 object and soft-deletes the DB row.
|
|
74
|
+
* Requires the `delete` scope if the API key uses scoped permissions.
|
|
75
|
+
*/
|
|
76
|
+
async deleteFile(uuid) {
|
|
77
|
+
await this.request("DELETE", `/api/files/${uuid}`);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Generate a time-limited signed delivery URL for a file.
|
|
81
|
+
* Requires the `read` scope if the API key uses scoped permissions.
|
|
82
|
+
*/
|
|
83
|
+
async getSignedUrl(uuid, ttlSeconds) {
|
|
84
|
+
const params = new URLSearchParams();
|
|
85
|
+
if (ttlSeconds != null)
|
|
86
|
+
params.set("ttl_seconds", String(ttlSeconds));
|
|
87
|
+
const qs = params.toString();
|
|
88
|
+
return this.request("GET", `/api/files/${uuid}/signed-url${qs ? `?${qs}` : ""}`);
|
|
89
|
+
}
|
|
49
90
|
// ── Proxy ───────────────────────────────────────────────────────────
|
|
50
91
|
/**
|
|
51
92
|
* Build a proxy query-string URL (without auth). Useful when the
|
|
@@ -111,6 +152,8 @@ export class UpThingClient {
|
|
|
111
152
|
headers,
|
|
112
153
|
body: requestBody,
|
|
113
154
|
});
|
|
155
|
+
if (res.status === 204)
|
|
156
|
+
return undefined;
|
|
114
157
|
if (!res.ok) {
|
|
115
158
|
const err = await res.json().catch(() => ({ error: `HTTP ${res.status}`, code: 0 }));
|
|
116
159
|
throw new UpThingSDKError(res.status, err);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "upthing-sdk",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "TypeScript SDK for upthing.2klabs.xyz — upload
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "TypeScript SDK for upthing.2klabs.xyz — upload, manage, and proxy files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|