@suphark/files-client 0.0.0-stage → 0.3.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 +97 -2
- package/dist/chunk-5VLU7KXC.js +169 -0
- package/dist/chunk-YZSJOMM6.js +225 -0
- package/dist/index.d.ts +1297 -0
- package/dist/index.js +16 -0
- package/dist/next/index.d.ts +746 -0
- package/dist/next/index.js +186 -0
- package/dist/react/index.d.ts +140 -0
- package/dist/react/index.js +357 -0
- package/dist/upload-D79TA4qU.d.ts +76 -0
- package/package.json +75 -4
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Problem, FileAssetDto, UploadTicket } from '@pi/files-contracts';
|
|
2
|
+
|
|
3
|
+
/** error จาก Pi Files API (problem+json) หรือจาก storage/network ระหว่างอัปโหลด */
|
|
4
|
+
declare class PiFilesError extends Error {
|
|
5
|
+
readonly status: number;
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly problem?: Problem | undefined;
|
|
8
|
+
constructor(status: number, code: string, message: string, problem?: Problem | undefined);
|
|
9
|
+
}
|
|
10
|
+
interface HttpOptions {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
/** API key ของแอป (server เท่านั้น) */
|
|
13
|
+
appKey?: string;
|
|
14
|
+
/** access token ของผู้ใช้ (Pi Auth JWT) — ใช้แทน appKey เมื่อต้องการ user-context */
|
|
15
|
+
getUserToken?: () => Promise<string | null> | string | null;
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
/** ส่ง cookie ของ Pi Files เอง (browser ภายใน files.suphark.com) */
|
|
18
|
+
credentials?: RequestCredentials;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* ตัวอัปโหลด bytes ตาม ticket — ใช้ได้ทั้ง browser (XHR เพื่อ progress) และ node (fetch)
|
|
23
|
+
* ผู้เรียกต้องมี `api` ที่คุยกับ Pi Files (parts/complete) — SDK core หรือ endpoint proxy ของ consumer
|
|
24
|
+
*/
|
|
25
|
+
interface UploadApi {
|
|
26
|
+
partUrls(uploadId: string, partNumbers: number[]): Promise<{
|
|
27
|
+
parts: {
|
|
28
|
+
partNumber: number;
|
|
29
|
+
url: string;
|
|
30
|
+
method?: "PUT" | "POST";
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
}[];
|
|
33
|
+
}>;
|
|
34
|
+
complete(uploadId: string, parts?: {
|
|
35
|
+
partNumber: number;
|
|
36
|
+
etag: string;
|
|
37
|
+
}[]): Promise<FileAssetDto>;
|
|
38
|
+
abort(uploadId: string): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
interface UploadProgress {
|
|
41
|
+
loaded: number;
|
|
42
|
+
total: number;
|
|
43
|
+
fraction: number;
|
|
44
|
+
}
|
|
45
|
+
interface PerformUploadOptions {
|
|
46
|
+
onProgress?: (p: UploadProgress) => void;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
concurrency?: number;
|
|
49
|
+
/** part ที่อัปโหลดเสร็จแล้ว (resume) */
|
|
50
|
+
completedParts?: {
|
|
51
|
+
partNumber: number;
|
|
52
|
+
etag: string;
|
|
53
|
+
}[];
|
|
54
|
+
onPartDone?: (part: {
|
|
55
|
+
partNumber: number;
|
|
56
|
+
etag: string;
|
|
57
|
+
}) => void;
|
|
58
|
+
}
|
|
59
|
+
type UploadSource = Blob | Uint8Array | ArrayBuffer;
|
|
60
|
+
/**
|
|
61
|
+
* ส่ง bytes ไป storage ด้วย XHR (progress) เมื่ออยู่ใน browser, fetch เมื่อไม่มี XHR
|
|
62
|
+
* etag: header ETag (S3/R2) หรือ JSON body { etag } (part ของ Vercel Blob ที่ส่งด้วย POST)
|
|
63
|
+
*/
|
|
64
|
+
declare function putBytes(url: string, body: Blob, headers: Record<string, string>, onProgress: (loaded: number) => void, signal?: AbortSignal, method?: "PUT" | "POST"): Promise<{
|
|
65
|
+
etag: string | null;
|
|
66
|
+
}>;
|
|
67
|
+
declare function performUpload(api: UploadApi, ticket: UploadTicket, source: UploadSource, mimeType: string, options?: PerformUploadOptions): Promise<FileAssetDto>;
|
|
68
|
+
/** fingerprint ของไฟล์สำหรับ resume (ชื่อ+ขนาด+lastModified) */
|
|
69
|
+
declare function fileFingerprint(file: {
|
|
70
|
+
name: string;
|
|
71
|
+
size: number;
|
|
72
|
+
lastModified?: number;
|
|
73
|
+
}): string;
|
|
74
|
+
|
|
75
|
+
export { PiFilesError as P, putBytes as d, fileFingerprint as f, performUpload as p };
|
|
76
|
+
export type { HttpOptions as H, UploadProgress as U, UploadApi as a, UploadSource as b, PerformUploadOptions as c };
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suphark/files-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Pi Files SDK: presigned/multipart upload, content proxy for Next.js route handlers, React upload hook, file references",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./next": {
|
|
14
|
+
"types": "./dist/next/index.d.ts",
|
|
15
|
+
"import": "./dist/next/index.js",
|
|
16
|
+
"default": "./dist/next/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./react": {
|
|
19
|
+
"types": "./dist/react/index.d.ts",
|
|
20
|
+
"import": "./dist/react/index.js",
|
|
21
|
+
"default": "./dist/react/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"test": "vitest run --passWithNoTests",
|
|
28
|
+
"prepack": "pnpm run build"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"next": ">=15",
|
|
32
|
+
"react": ">=19"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"next": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"react": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@pi/config": "workspace:*",
|
|
44
|
+
"@pi/files-contracts": "workspace:*",
|
|
45
|
+
"@types/node": "^26.6.5",
|
|
46
|
+
"@types/react": "^19.2.18",
|
|
47
|
+
"next": "^16.4.2",
|
|
48
|
+
"react": "^19.3.1",
|
|
49
|
+
"tsup": "^9.0.0",
|
|
50
|
+
"typescript": "^6.0.3",
|
|
51
|
+
"vitest": "^5.0.5",
|
|
52
|
+
"zod": "^4.6.7"
|
|
53
|
+
},
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/suphark/files",
|
|
58
|
+
"directory": "packages/files-client"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"files",
|
|
62
|
+
"upload",
|
|
63
|
+
"r2",
|
|
64
|
+
"nextjs",
|
|
65
|
+
"pi-files"
|
|
66
|
+
],
|
|
67
|
+
"sideEffects": false,
|
|
68
|
+
"files": [
|
|
69
|
+
"dist",
|
|
70
|
+
"README.md"
|
|
71
|
+
],
|
|
72
|
+
"main": "./dist/index.js",
|
|
73
|
+
"types": "./dist/index.d.ts",
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public"
|
|
76
|
+
}
|
|
77
|
+
}
|