@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,83 @@
1
+ import type { S3Api } from "@dimah-s3/core";
2
+ import type { UploadConfig, UploadHooks, UploadPhase, UploadProgress, UploadResult, UploadRequestOptions } from "../types";
3
+ /** Options for {@link useUpload}. */
4
+ export type UseUploadOptions = UploadConfig & UploadHooks & {
5
+ /** S3Api. Optional when an `<S3Provider>` is present in the tree. */
6
+ api?: S3Api;
7
+ };
8
+ export type UseUploadState = {
9
+ /** Current upload phase. */
10
+ phase: UploadPhase;
11
+ /** Byte transfer progress. */
12
+ progress: UploadProgress;
13
+ /** Error message, or `null`. */
14
+ error: string | null;
15
+ /** Result after success, or `null`. */
16
+ result: UploadResult | null;
17
+ /** Name of the file being uploaded. */
18
+ fileName: string | null;
19
+ /** Size of the file being uploaded in bytes. */
20
+ fileSize: number | null;
21
+ };
22
+ export type UseUploadReturn = UseUploadState & {
23
+ /**
24
+ * Start an upload.
25
+ *
26
+ * Safe to call again after `success`, `error`, or `cancel` — state is reset
27
+ * automatically before the new upload begins.
28
+ *
29
+ * If `uploadStore` is configured and a previous upload for the same
30
+ * `objectKey` was interrupted (e.g. via `detach()`), the engine will find
31
+ * the stored `uploadId`, call `listParts`, and resume from the last completed
32
+ * part rather than starting a new multipart upload.
33
+ */
34
+ upload: (file: File, objectKey: string, requestOptions?: UploadRequestOptions) => Promise<void>;
35
+ /**
36
+ * Abort the upload and fully clean up all resources.
37
+ *
38
+ * - Stops the in-flight network request immediately.
39
+ * - For multipart uploads: calls `AbortMultipartUpload` on S3 so incomplete
40
+ * parts are freed right away (instead of waiting for the bucket lifecycle
41
+ * policy to expire them).
42
+ * - Removes the `uploadStore` entry if one was provided.
43
+ * - Resets state to `idle`.
44
+ *
45
+ * Use this for a "Cancel" button that the user explicitly clicks to abandon
46
+ * the upload entirely.
47
+ */
48
+ cancel: () => void;
49
+ /**
50
+ * Stop the upload and — when multipart with `uploadStore` is active —
51
+ * preserve S3 parts and the store entry for a future resume.
52
+ *
53
+ * Compared to `cancel()`:
54
+ * - Does **not** call `AbortMultipartUpload` (parts stay on S3).
55
+ * - Does **not** remove the `uploadStore` entry.
56
+ * - Does **not** fire the `onCancel` callback.
57
+ *
58
+ * The next call to `upload(sameFile, sameKey)` will detect the stored
59
+ * `uploadId`, verify the existing parts via `listParts`, and continue
60
+ * uploading from where it stopped.
61
+ *
62
+ * For **simple uploads** or multipart **without** `uploadStore`, this is
63
+ * identical to `cancel()` — there is no S3 state worth preserving.
64
+ *
65
+ * Intended for custom UIs that want to offer a "save for later / resume"
66
+ * workflow.
67
+ */
68
+ detach: () => void;
69
+ /**
70
+ * Reset UI state to `idle` without touching any S3 or store resources.
71
+ *
72
+ * - Stops the in-flight network request if one is active.
73
+ * - Does **not** call `AbortMultipartUpload`.
74
+ * - Does **not** modify `uploadStore`.
75
+ * - Does **not** fire `onCancel`.
76
+ *
77
+ * Use this to clear an error or success state from the UI, or when you
78
+ * handle cleanup yourself outside this hook.
79
+ */
80
+ reset: () => void;
81
+ };
82
+ export declare function useUpload(options: UseUploadOptions): UseUploadReturn;
83
+ //# sourceMappingURL=use-upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAO5C,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,cAAc,EACd,YAAY,EACZ,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAGlB,qCAAqC;AACrC,MAAM,MAAM,gBAAgB,GAAG,YAAY,GACzC,WAAW,GAAG;IACZ,qEAAqE;IACrE,GAAG,CAAC,EAAE,KAAK,CAAC;CACb,CAAC;AAEJ,MAAM,MAAM,cAAc,GAAG;IAC3B,4BAA4B;IAC5B,KAAK,EAAE,WAAW,CAAC;IACnB,8BAA8B;IAC9B,QAAQ,EAAE,cAAc,CAAC;IACzB,gCAAgC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,uCAAuC;IACvC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,uCAAuC;IACvC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG;IAC7C;;;;;;;;;;OAUG;IACH,MAAM,EAAE,CACN,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EACjB,cAAc,CAAC,EAAE,oBAAoB,KAClC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB;;;;;;;;;;;;OAYG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;;;;;;;;;;OAUG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAuBF,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CA0KpE"}
@@ -0,0 +1,17 @@
1
+ export * from "./types";
2
+ export { defineApi } from "./api";
3
+ export { createS3Client, type CreateS3ClientOptions } from "./create-s3-client";
4
+ export { S3Provider, useApi, S3Context, type S3ProviderProps, } from "./s3-provider";
5
+ /** Generated key map — use with `satisfies Translations` / `Partial<Translations>`. */
6
+ export type { Translations } from "./translations";
7
+ export { createLocalStorageStore, createMemoryStore } from "./store";
8
+ export { uploadFile, uploadFiles, type UploadEngineCallbacks, type FileItem, type FileItemStatus, type MultiUploadCallbacks, } from "./upload";
9
+ export { formatAcceptLabels, formatUploadProgress, formatSpeed, formatEta, useFormatDimahError, useFormatValidateFileError, createSpeedTracker, type SpeedTracker, } from "./helpers";
10
+ export { useUpload, type UseUploadOptions, type UseUploadState, type UseUploadReturn, } from "./hooks/use-upload";
11
+ export { useMultiUpload, type UseMultiUploadOptions, type UseMultiUploadState, type UseMultiUploadReturn, } from "./hooks/use-multi-upload";
12
+ export { useUploadControls, type UseUploadControlsOptions, type UseUploadControlsReturn, } from "./hooks/use-upload-controls";
13
+ export { useMultiUploadControls, type UseMultiUploadControlsOptions, type UseMultiUploadControlsReturn, } from "./hooks/use-multi-upload-controls";
14
+ export { useDownload, type DownloadPhase, type DownloadHooks, type UseDownloadOptions, type UseDownloadState, type UseDownloadReturn, } from "./hooks/use-download";
15
+ export { useFetchDownload, type FetchDownloadPhase, type FetchDownloadProgress, type FetchDownloadHooks, type UseFetchDownloadOptions, type UseFetchDownloadState, type UseFetchDownloadReturn, } from "./hooks/use-fetch-download";
16
+ export { useDelete, type UseDeleteOptions, type UseDeleteState, type UseDeleteReturn, } from "./hooks/use-delete";
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAA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