@dimah-s3/react 0.1.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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/dist/api.d.ts +29 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/create-s3-client.d.ts +34 -0
  6. package/dist/create-s3-client.d.ts.map +1 -0
  7. package/dist/helpers/format-accept-labels.d.ts +3 -0
  8. package/dist/helpers/format-accept-labels.d.ts.map +1 -0
  9. package/dist/helpers/format-dimah-error.d.ts +8 -0
  10. package/dist/helpers/format-dimah-error.d.ts.map +1 -0
  11. package/dist/helpers/format-dimah-error.test.d.ts +2 -0
  12. package/dist/helpers/format-dimah-error.test.d.ts.map +1 -0
  13. package/dist/helpers/format-eta.d.ts +13 -0
  14. package/dist/helpers/format-eta.d.ts.map +1 -0
  15. package/dist/helpers/format-speed.d.ts +9 -0
  16. package/dist/helpers/format-speed.d.ts.map +1 -0
  17. package/dist/helpers/format-upload-progress.d.ts +18 -0
  18. package/dist/helpers/format-upload-progress.d.ts.map +1 -0
  19. package/dist/helpers/format-validate-file-error.d.ts +9 -0
  20. package/dist/helpers/format-validate-file-error.d.ts.map +1 -0
  21. package/dist/helpers/helpers.test.d.ts +2 -0
  22. package/dist/helpers/helpers.test.d.ts.map +1 -0
  23. package/dist/helpers/index.d.ts +9 -0
  24. package/dist/helpers/index.d.ts.map +1 -0
  25. package/dist/helpers/speed-tracker.d.ts +18 -0
  26. package/dist/helpers/speed-tracker.d.ts.map +1 -0
  27. package/dist/helpers/throttled-speed.d.ts +8 -0
  28. package/dist/helpers/throttled-speed.d.ts.map +1 -0
  29. package/dist/hooks/index.d.ts +8 -0
  30. package/dist/hooks/index.d.ts.map +1 -0
  31. package/dist/hooks/use-delete.d.ts +29 -0
  32. package/dist/hooks/use-delete.d.ts.map +1 -0
  33. package/dist/hooks/use-download.d.ts +33 -0
  34. package/dist/hooks/use-download.d.ts.map +1 -0
  35. package/dist/hooks/use-fetch-download.d.ts +33 -0
  36. package/dist/hooks/use-fetch-download.d.ts.map +1 -0
  37. package/dist/hooks/use-multi-upload-controls.d.ts +45 -0
  38. package/dist/hooks/use-multi-upload-controls.d.ts.map +1 -0
  39. package/dist/hooks/use-multi-upload.d.ts +39 -0
  40. package/dist/hooks/use-multi-upload.d.ts.map +1 -0
  41. package/dist/hooks/use-upload-controls.d.ts +54 -0
  42. package/dist/hooks/use-upload-controls.d.ts.map +1 -0
  43. package/dist/hooks/use-upload.d.ts +83 -0
  44. package/dist/hooks/use-upload.d.ts.map +1 -0
  45. package/dist/index.d.ts +17 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +1558 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/internal-helpers.d.ts +10 -0
  50. package/dist/internal-helpers.d.ts.map +1 -0
  51. package/dist/s3-provider.d.ts +50 -0
  52. package/dist/s3-provider.d.ts.map +1 -0
  53. package/dist/store/index.d.ts +4 -0
  54. package/dist/store/index.d.ts.map +1 -0
  55. package/dist/store/local-storage-store.d.ts +10 -0
  56. package/dist/store/local-storage-store.d.ts.map +1 -0
  57. package/dist/store/memory-store.d.ts +15 -0
  58. package/dist/store/memory-store.d.ts.map +1 -0
  59. package/dist/translations/index.d.ts +2 -0
  60. package/dist/translations/index.d.ts.map +1 -0
  61. package/dist/translations/types.d.ts +61 -0
  62. package/dist/translations/types.d.ts.map +1 -0
  63. package/dist/types/delete.d.ts +11 -0
  64. package/dist/types/delete.d.ts.map +1 -0
  65. package/dist/types/download.d.ts +26 -0
  66. package/dist/types/download.d.ts.map +1 -0
  67. package/dist/types/error.d.ts +24 -0
  68. package/dist/types/error.d.ts.map +1 -0
  69. package/dist/types/index.d.ts +7 -0
  70. package/dist/types/index.d.ts.map +1 -0
  71. package/dist/types/multi-upload.d.ts +27 -0
  72. package/dist/types/multi-upload.d.ts.map +1 -0
  73. package/dist/types/upload-store.d.ts +55 -0
  74. package/dist/types/upload-store.d.ts.map +1 -0
  75. package/dist/types/upload.d.ts +102 -0
  76. package/dist/types/upload.d.ts.map +1 -0
  77. package/dist/upload/constants.d.ts +7 -0
  78. package/dist/upload/constants.d.ts.map +1 -0
  79. package/dist/upload/index.d.ts +3 -0
  80. package/dist/upload/index.d.ts.map +1 -0
  81. package/dist/upload/multipart.d.ts +5 -0
  82. package/dist/upload/multipart.d.ts.map +1 -0
  83. package/dist/upload/presigned-http.d.ts +17 -0
  84. package/dist/upload/presigned-http.d.ts.map +1 -0
  85. package/dist/upload/retry.d.ts +3 -0
  86. package/dist/upload/retry.d.ts.map +1 -0
  87. package/dist/upload/upload-file.d.ts +13 -0
  88. package/dist/upload/upload-file.d.ts.map +1 -0
  89. package/dist/upload/upload-files.d.ts +26 -0
  90. package/dist/upload/upload-files.d.ts.map +1 -0
  91. package/dist/upload/upload-part.d.ts +4 -0
  92. package/dist/upload/upload-part.d.ts.map +1 -0
  93. package/package.json +67 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { UploadProgress, UploadResult } from "./upload";
2
+ export type MultiUploadPhase = "idle" | "validating" | "uploading" | "success" | "error";
3
+ /** Per-file state in a multi-upload batch. */
4
+ export type MultiUploadFileState = {
5
+ /** Unique ID for this file in the batch. */
6
+ id: string;
7
+ /** Display file name. */
8
+ fileName: string;
9
+ /** File size in bytes. */
10
+ fileSize: number;
11
+ status: "pending" | "uploading" | "success" | "error";
12
+ progress: UploadProgress;
13
+ error: string | null;
14
+ };
15
+ /** Lifecycle hooks for multi-file upload. */
16
+ export type MultiUploadHooks = {
17
+ beforeUpload?: (files: File[]) => Promise<boolean> | boolean;
18
+ onUploadStart?: (files: File[]) => void;
19
+ onFileProgress?: (file: File, progress: UploadProgress) => void;
20
+ onFileSuccess?: (file: File, result: UploadResult) => void;
21
+ onFileError?: (file: File, error: string) => void;
22
+ onProgress?: (progress: UploadProgress) => void;
23
+ onSuccess?: (results: UploadResult[]) => Promise<void> | void;
24
+ onError?: (error: unknown) => void;
25
+ onCancel?: () => void;
26
+ };
27
+ //# sourceMappingURL=multi-upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-upload.d.ts","sourceRoot":"","sources":["../../src/types/multi-upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7D,MAAM,MAAM,gBAAgB,GAC1B,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE5D,8CAA8C;AAC9C,MAAM,MAAM,oBAAoB,GAAG;IACjC,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;IACtD,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,6CAA6C;AAC7C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAC7D,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACxC,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IAChE,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3D,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC9D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Minimal state that must be persisted to resume a multipart upload.
3
+ */
4
+ export type StoredUpload = {
5
+ /** S3 multipart `UploadId` returned by `CreateMultipartUpload`. */
6
+ uploadId: string;
7
+ /** S3 object key. */
8
+ key: string;
9
+ /** Total file size in bytes — used to verify the same file is being resumed. */
10
+ fileSize: number;
11
+ /** Bucket override, if any. */
12
+ bucket?: string;
13
+ };
14
+ /**
15
+ * Storage backend for resumable multipart uploads.
16
+ *
17
+ * Implement this interface to persist `uploadId` state in any storage system
18
+ * (database, Redis, IndexedDB, etc.). The default implementation uses
19
+ * `localStorage` via `createLocalStorageStore()`.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * // Custom database-backed store
24
+ * const dbStore: UploadStore = {
25
+ * async get(key, fileSize) {
26
+ * const row = await db.uploads.findFirst({ where: { key, fileSize } });
27
+ * return row ? { uploadId: row.uploadId, key, fileSize, bucket: row.bucket } : null;
28
+ * },
29
+ * async set(upload) {
30
+ * await db.uploads.upsert({ where: { key: upload.key }, data: upload });
31
+ * },
32
+ * async delete(key) {
33
+ * await db.uploads.deleteMany({ where: { key } });
34
+ * },
35
+ * };
36
+ * ```
37
+ */
38
+ export type UploadStore = {
39
+ /**
40
+ * Look up a pending upload by its S3 object key and file size.
41
+ * Returns `null` if no matching upload is found.
42
+ */
43
+ get: (key: string, fileSize: number) => StoredUpload | null | Promise<StoredUpload | null>;
44
+ /**
45
+ * Persist a new upload state after `CreateMultipartUpload` succeeds.
46
+ * Called once per upload, before any parts are sent.
47
+ */
48
+ set: (upload: StoredUpload) => void | Promise<void>;
49
+ /**
50
+ * Remove the upload state after the upload completes or is explicitly
51
+ * abandoned. Should be a no-op if the key is not found.
52
+ */
53
+ delete: (key: string) => void | Promise<void>;
54
+ };
55
+ //# sourceMappingURL=upload-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-store.d.ts","sourceRoot":"","sources":["../../src/types/upload-store.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,GAAG,EAAE,CACH,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,KACb,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAExD;;;OAGG;IACH,GAAG,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;;OAGG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C,CAAC"}
@@ -0,0 +1,102 @@
1
+ import type { UploadStore } from "./upload-store";
2
+ /** Result returned after a successful upload. */
3
+ export type UploadResult = {
4
+ /** S3 object key. */
5
+ key: string;
6
+ /** Object ETag from S3. */
7
+ eTag?: string;
8
+ };
9
+ /** Byte transfer progress for upload and fetch-download. */
10
+ export type UploadProgress = {
11
+ /** Bytes transferred so far. */
12
+ loaded: number;
13
+ /** Total bytes to transfer. */
14
+ total: number;
15
+ /** Progress percentage (0–100). */
16
+ percent: number;
17
+ /** Instantaneous transfer speed in bytes/second. `undefined` until measurable. */
18
+ speed?: number;
19
+ };
20
+ export type UploadPhase = "idle" | "validating" | "presigning" | "uploading" | "finalizing" | "success" | "error";
21
+ /** Per-upload options passed to the presign API. */
22
+ export type UploadRequestOptions = {
23
+ /** Custom S3 object metadata (`x-amz-meta-*`). */
24
+ metadata?: Record<string, string>;
25
+ /** Target bucket (overrides server default). */
26
+ bucket?: string;
27
+ /** Override auto-detected content type. */
28
+ contentType?: string;
29
+ /** Object ACL — defaults to `'private'`. */
30
+ acl?: "private" | "public-read";
31
+ /**
32
+ * Original file name stored as `Content-Disposition` on the S3 object.
33
+ * Defaults to the browser's `file.name` when not provided.
34
+ * Pass `null` to omit Content-Disposition entirely.
35
+ */
36
+ fileName?: string | null;
37
+ /**
38
+ * Per-upload multipart part size in bytes. Overrides `UploadConfig.partSize`.
39
+ * Minimum 5 MB; ignored for non-multipart uploads.
40
+ */
41
+ partSize?: number;
42
+ };
43
+ /** Lifecycle hooks for single-file upload. */
44
+ export type UploadHooks = {
45
+ /** Runs before the upload starts. Return `false` to block it. */
46
+ beforeUpload?: (file: File) => Promise<boolean> | boolean;
47
+ /** Fires after validation passes and the upload begins. */
48
+ onUploadStart?: (file: File, key: string) => void;
49
+ /** Fires continuously while bytes are transferred. */
50
+ onProgress?: (file: File, progress: UploadProgress) => void;
51
+ /** Fires after each part is successfully uploaded to S3 (multipart only). */
52
+ onPartUpload?: (file: File, partNumber: number, totalParts: number) => void;
53
+ /** Fires once after `CreateMultipartUpload` succeeds (multipart only). */
54
+ onMultipartInit?: (file: File, uploadId: string) => void;
55
+ /** Fires when the upload finishes successfully. */
56
+ onSuccess?: (file: File, result: UploadResult) => Promise<void> | void;
57
+ /** Fires when the upload fails with an unrecoverable error. */
58
+ onError?: (file: File | null, error: unknown, phase: UploadPhase) => void;
59
+ /** Fires when the upload is cancelled via `cancel()`. */
60
+ onCancel?: (file: File | null) => void;
61
+ };
62
+ /** Retry configuration for failed network requests. */
63
+ export type RetryConfig = {
64
+ /** Maximum number of retry attempts per request. @default 3 */
65
+ maxRetries?: number;
66
+ /** Base delay in ms for exponential backoff. @default 1000 */
67
+ baseDelay?: number;
68
+ };
69
+ /** Upload engine configuration for `useUpload` and `useMultiUpload`. */
70
+ export type UploadConfig = {
71
+ /** Enable multipart uploads for large files. */
72
+ multipart?: boolean;
73
+ /** Allowed file extensions or MIME types. */
74
+ accept?: string[];
75
+ /** Max file size in bytes. */
76
+ maxFileSize?: number;
77
+ /** Max number of files (multi-upload). */
78
+ maxFiles?: number;
79
+ /** File size threshold in bytes above which multipart is used. */
80
+ multipartThreshold?: number;
81
+ /**
82
+ * Multipart part size in bytes. Minimum 5 MB.
83
+ * Can be overridden per-upload via `UploadRequestOptions.partSize`.
84
+ * @default 5 MB
85
+ */
86
+ partSize?: number;
87
+ /** Number of parts uploaded concurrently (multipart). */
88
+ concurrentParts?: number;
89
+ /** Number of files uploaded concurrently (multi-upload). */
90
+ concurrentFiles?: number;
91
+ /** Retry configuration for failed network requests. */
92
+ retry?: RetryConfig;
93
+ /**
94
+ * Store for resumable multipart uploads.
95
+ *
96
+ * - Omit / `undefined` — abort immediately on cancel or error.
97
+ * - `false` — same as omitting.
98
+ * - Custom `UploadStore` — persist `uploadId` across sessions.
99
+ */
100
+ uploadStore?: UploadStore | false;
101
+ };
102
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/types/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,iDAAiD;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E,MAAM,CAAC;IACzB,4DAA4D;IAC5D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CACnC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const DEFAULT_MULTIPART_THRESHOLD: number;
2
+ export declare const DEFAULT_PART_SIZE: number;
3
+ export declare const MAX_RETRIES = 3;
4
+ export declare const RETRY_BASE_DELAY = 1000;
5
+ export declare const DEFAULT_CONCURRENT_PARTS = 2;
6
+ export declare const DEFAULT_CONCURRENT_FILES = 2;
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/upload/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,QAAmB,CAAC;AAC5D,eAAO,MAAM,iBAAiB,QAAkB,CAAC;AACjD,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,gBAAgB,OAAQ,CAAC;AACtC,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,wBAAwB,IAAI,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { uploadFile, type UploadEngineCallbacks } from "./upload-file";
2
+ export { uploadFiles, type FileItem, type FileItemStatus, type MultiUploadCallbacks, } from "./upload-files";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upload/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EACL,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { UploadProgress, UploadRequestOptions, RetryConfig } from "../types";
2
+ import type { S3Api } from "@dimah-s3/core";
3
+ import type { UploadStore } from "../types/upload-store";
4
+ export declare function uploadMultipart(api: S3Api, file: File, objectKey: string, partSize: number, concurrentParts: number, onProgress?: (progress: UploadProgress) => void, signal?: AbortSignal, requestOptions?: UploadRequestOptions, retryConfig?: RetryConfig, uploadStore?: UploadStore | false, onPartUpload?: (partNumber: number, totalParts: number) => void, onMultipartInit?: (uploadId: string, key: string) => void): Promise<string | undefined>;
5
+ //# sourceMappingURL=multipart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/upload/multipart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACZ,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAgBzD,wBAAsB,eAAe,CACnC,GAAG,EAAE,KAAK,EACV,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,EAC/C,MAAM,CAAC,EAAE,WAAW,EACpB,cAAc,CAAC,EAAE,oBAAoB,EACrC,WAAW,CAAC,EAAE,WAAW,EACzB,WAAW,CAAC,EAAE,WAAW,GAAG,KAAK,EACjC,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,EAC/D,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,GACxD,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAsL7B"}
@@ -0,0 +1,17 @@
1
+ import type { UploadProgress } from "../types";
2
+ /**
3
+ * Uploads a file directly to S3 using a presigned POST form.
4
+ *
5
+ * All policy fields (acl, Content-Type, content-length-range, signature, etc.)
6
+ * are embedded in `fields` and must be appended to the FormData **before** the
7
+ * file — this is an S3 requirement.
8
+ */
9
+ export declare function uploadSimple(file: File, url: string, fields: Record<string, string>, onProgress?: (progress: UploadProgress) => void, signal?: AbortSignal): Promise<void>;
10
+ /**
11
+ * Uploads a file directly to S3 using a presigned PUT URL.
12
+ *
13
+ * Use this when the server is configured with `upload.method = "PUT"` — for
14
+ * example with Cloudflare R2 which does not support presigned POST.
15
+ */
16
+ export declare function uploadPut(file: File, url: string, headers: Record<string, string>, onProgress?: (progress: UploadProgress) => void, signal?: AbortSignal): Promise<void>;
17
+ //# sourceMappingURL=presigned-http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presigned-http.d.ts","sourceRoot":"","sources":["../../src/upload/presigned-http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAyF/C;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,EAC/C,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAef;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,EAC/C,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAUf"}
@@ -0,0 +1,3 @@
1
+ import type { RetryConfig } from "../types";
2
+ export declare function withRetry<T>(fn: () => Promise<T>, retryConfig: RetryConfig | undefined, signal?: AbortSignal): Promise<T>;
3
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/upload/retry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,WAAW,EAAE,WAAW,GAAG,SAAS,EACpC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAoBZ"}
@@ -0,0 +1,13 @@
1
+ import type { UploadConfig, UploadProgress, UploadResult, UploadRequestOptions } from "../types";
2
+ import type { S3Api } from "@dimah-s3/core";
3
+ export type UploadEngineCallbacks = {
4
+ onProgress?: (progress: UploadProgress) => void;
5
+ /** Called when the upload transitions between internal phases. */
6
+ onPhaseChange?: (phase: "presigning" | "uploading" | "finalizing") => void;
7
+ /** Called after each individual multipart part is successfully uploaded. */
8
+ onPartUpload?: (partNumber: number, totalParts: number) => void;
9
+ /** Called once after `CreateMultipartUpload` succeeds with the S3-assigned `uploadId` and final object `key`. */
10
+ onMultipartInit?: (uploadId: string, key: string) => void;
11
+ };
12
+ export declare function uploadFile(api: S3Api, file: File, objectKey: string, config?: UploadConfig, callbacks?: UploadEngineCallbacks, signal?: AbortSignal, requestOptions?: UploadRequestOptions): Promise<UploadResult>;
13
+ //# sourceMappingURL=upload-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file.d.ts","sourceRoot":"","sources":["../../src/upload/upload-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAW5C,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD,kEAAkE;IAClE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,GAAG,YAAY,KAAK,IAAI,CAAC;IAC3E,4EAA4E;IAC5E,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAChE,iHAAiH;IACjH,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3D,CAAC;AAEF,wBAAsB,UAAU,CAC9B,GAAG,EAAE,KAAK,EACV,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EACjB,MAAM,GAAE,YAAiB,EACzB,SAAS,GAAE,qBAA0B,EACrC,MAAM,CAAC,EAAE,WAAW,EACpB,cAAc,CAAC,EAAE,oBAAoB,GACpC,OAAO,CAAC,YAAY,CAAC,CA8EvB"}
@@ -0,0 +1,26 @@
1
+ import type { UploadConfig, UploadProgress, UploadResult, UploadRequestOptions } from "../types";
2
+ import type { S3Api } from "@dimah-s3/core";
3
+ export type FileItemStatus = "pending" | "uploading" | "success" | "error";
4
+ export type FileItem = {
5
+ id: string;
6
+ file: File;
7
+ objectKey: string;
8
+ status: FileItemStatus;
9
+ progress: UploadProgress;
10
+ result: UploadResult | null;
11
+ error: string | null;
12
+ };
13
+ export type MultiUploadCallbacks = {
14
+ onFileProgress?: (id: string, progress: UploadProgress) => void;
15
+ onFileSuccess?: (id: string, result: UploadResult) => void;
16
+ onFileError?: (id: string, error: string) => void;
17
+ onTotalProgress?: (progress: UploadProgress) => void;
18
+ /** Called once after multipart init for a file (id → uploadId, server key). */
19
+ onMultipartInit?: (id: string, uploadId: string, key: string) => void;
20
+ };
21
+ export declare function uploadFiles(api: S3Api, items: Array<{
22
+ id: string;
23
+ file: File;
24
+ objectKey: string;
25
+ }>, config?: UploadConfig, callbacks?: MultiUploadCallbacks, signal?: AbortSignal, getRequestOptions?: (file: File) => UploadRequestOptions): Promise<FileItem[]>;
26
+ //# sourceMappingURL=upload-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-files.d.ts","sourceRoot":"","sources":["../../src/upload/upload-files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAI5C,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IAChE,aAAa,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3D,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,+EAA+E;IAC/E,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACvE,CAAC;AAEF,wBAAsB,WAAW,CAC/B,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,EAC3D,MAAM,GAAE,YAAiB,EACzB,SAAS,GAAE,oBAAyB,EACpC,MAAM,CAAC,EAAE,WAAW,EACpB,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,oBAAoB,GACvD,OAAO,CAAC,QAAQ,EAAE,CAAC,CAgFrB"}
@@ -0,0 +1,4 @@
1
+ export declare function uploadPart(blob: Blob, presignedUrl: string, partLoaded: {
2
+ bytes: number;
3
+ }, reportProgress: () => void, signal?: AbortSignal): Promise<void>;
4
+ //# sourceMappingURL=upload-part.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-part.d.ts","sourceRoot":"","sources":["../../src/upload/upload-part.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CACxB,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAC7B,cAAc,EAAE,MAAM,IAAI,EAC1B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAuDf"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@dimah-s3/react",
3
+ "version": "0.1.0",
4
+ "description": "React hooks for S3-compatible file uploads, downloads, and deletes",
5
+ "keywords": [
6
+ "s3",
7
+ "react",
8
+ "hooks",
9
+ "upload",
10
+ "download",
11
+ "file-upload"
12
+ ],
13
+ "author": "Hamidrezakz",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/dimah-kz/dimah-s3.git",
18
+ "directory": "packages/react"
19
+ },
20
+ "homepage": "https://github.com/dimah-kz/dimah-s3/tree/main/packages/react",
21
+ "bugs": {
22
+ "url": "https://github.com/dimah-kz/dimah-s3/issues"
23
+ },
24
+ "sideEffects": false,
25
+ "type": "module",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "dependencies": {
36
+ "@fuma-translate/react": "^1.0.2",
37
+ "@dimah-s3/core": "0.1.0"
38
+ },
39
+ "peerDependencies": {
40
+ "@fuma-translate/react": "^1.0.2",
41
+ "react": ">=18"
42
+ },
43
+ "devDependencies": {
44
+ "@types/react": "^19.2.18",
45
+ "@types/react-dom": "^19.2.4",
46
+ "eslint": "^10.8.0",
47
+ "fuma-translate": "^1.0.2",
48
+ "jsdom": "^30.0.1",
49
+ "react": "^19.2.8",
50
+ "react-dom": "^19.2.8",
51
+ "tsup": "^8.5.1",
52
+ "typescript": "7.0.2",
53
+ "vitest": "^4.1.10",
54
+ "@workspace/eslint-config": "0.0.1",
55
+ "@workspace/typescript-config": "0.0.1"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "scripts": {
61
+ "compile:translations": "node ./scripts/compile-translations.mjs",
62
+ "build": "pnpm compile:translations && tsup --config tsup.config.ts && tsc --emitDeclarationOnly",
63
+ "lint": "eslint",
64
+ "check-types": "pnpm compile:translations && tsc --noEmit",
65
+ "test": "vitest run"
66
+ }
67
+ }