@visulima/storage 1.0.0-alpha.31 → 1.0.0-alpha.32

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 (173) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +2 -2
  3. package/dist/adapter/nuxt/module.d.ts +4 -4
  4. package/dist/adapter/nuxt/node_modules/.bin/nuxi +2 -2
  5. package/dist/adapter/nuxt/node_modules/.bin/nuxt +2 -2
  6. package/dist/ai/ai-sdk/index.d.ts +3 -3
  7. package/dist/ai/claude/index.d.ts +2 -2
  8. package/dist/ai/openai/index.d.ts +3 -3
  9. package/dist/ai/tanstack/index.d.ts +2 -2
  10. package/dist/handler/http/fetch/index.d.ts +7 -7
  11. package/dist/handler/http/fetch/index.js +1 -1
  12. package/dist/handler/http/hono/index.d.ts +4 -4
  13. package/dist/handler/http/hono/index.js +1 -1
  14. package/dist/handler/http/nextjs/index.d.ts +4 -4
  15. package/dist/handler/http/nextjs/index.js +1 -1
  16. package/dist/handler/http/node/index.d.ts +7 -7
  17. package/dist/handler/http/node/index.js +1 -1
  18. package/dist/handler/http/solid-start/index.d.ts +4 -4
  19. package/dist/handler/http/solid-start/index.js +1 -1
  20. package/dist/index.d.ts +6 -5
  21. package/dist/index.js +1 -1
  22. package/dist/packem_shared/{AwsLightStorage-DbQrK9m7.js → AwsLightStorage-B1jNF7sv.js} +1 -1
  23. package/dist/packem_shared/AzureStorage-B4E6VLn5.js +1 -0
  24. package/dist/packem_shared/{BoxMetaStorage-DLdXbZaV.js → BoxMetaStorage-nESVquA1.js} +1 -1
  25. package/dist/packem_shared/BoxStorage-CHYDrcxw.js +1 -0
  26. package/dist/packem_shared/{BunS3MetaStorage-Bv_CTTMz.js → BunS3MetaStorage-BkZx5q4w.js} +1 -1
  27. package/dist/packem_shared/BunS3Storage-BopE7kmX.js +1 -0
  28. package/dist/packem_shared/{BunnyMetaStorage-DNMTSeoN.js → BunnyMetaStorage-bB8NXGUI.js} +1 -1
  29. package/dist/packem_shared/BunnyStorage-C3IBxJqr.js +1 -0
  30. package/dist/packem_shared/{CloudinaryMetaStorage-DEBk5eQy.js → CloudinaryMetaStorage-BzibHydK.js} +1 -1
  31. package/dist/packem_shared/CloudinaryStorage-Cj00ZXWV.js +1 -0
  32. package/dist/packem_shared/DiskStorage-BrAb28Je.js +1 -0
  33. package/dist/packem_shared/DiskStorageWithChecksum-BX85CHJ6.js +1 -0
  34. package/dist/packem_shared/{DropboxMetaStorage-C6vj1QDA.js → DropboxMetaStorage-Bfm5bblb.js} +1 -1
  35. package/dist/packem_shared/DropboxStorage-Btz9h9Mj.js +1 -0
  36. package/dist/packem_shared/Files-tnc_buzM.js +1 -0
  37. package/dist/packem_shared/{FirebaseMetaStorage-CzyOim-J.js → FirebaseMetaStorage-CshnJMb0.js} +1 -1
  38. package/dist/packem_shared/FirebaseStorage-Y9P6Dx8I.js +2 -0
  39. package/dist/packem_shared/{FtpMetaStorage-1Njy0DpU.js → FtpMetaStorage-CoyWJafY.js} +1 -1
  40. package/dist/packem_shared/FtpStorage-DCKPMX0z.js +1 -0
  41. package/dist/packem_shared/{GCSMetaStorage-DFIjFmn-.js → GCSMetaStorage-CfZj52hQ.js} +1 -1
  42. package/dist/packem_shared/GCStorage-hfL1u2KQ.js +1 -0
  43. package/dist/packem_shared/{GoogleDriveMetaStorage-WGuUZPyx.js → GoogleDriveMetaStorage-CBSdEQr6.js} +1 -1
  44. package/dist/packem_shared/GoogleDriveStorage-C7iuV7qb.js +1 -0
  45. package/dist/packem_shared/{LocalMetaStorage-QMKL7McF.js → LocalMetaStorage-DSwsmdt7.js} +1 -1
  46. package/dist/packem_shared/MemoryMetaStorage-DEzfBNgL.js +1 -0
  47. package/dist/packem_shared/{Multipart-DkH4QwNs.js → Multipart-kQ5wJQaV.js} +1 -1
  48. package/dist/packem_shared/{Multipart-C6Mw7V9W.js → Multipart-qaEOWKz1.js} +1 -1
  49. package/dist/packem_shared/{NetlifyBlobMetaStorage-ClIFdTkT.js → NetlifyBlobMetaStorage-CqluIgV0.js} +1 -1
  50. package/dist/packem_shared/NetlifyBlobStorage-CkMw9Uyv.js +1 -0
  51. package/dist/packem_shared/{OneDriveMetaStorage-DS4f83X2.js → OneDriveMetaStorage-DPTNMpeq.js} +1 -1
  52. package/dist/packem_shared/OneDriveStorage-CEGYb6OC.js +1 -0
  53. package/dist/packem_shared/{PocketBaseMetaStorage-B6utPncj.js → PocketBaseMetaStorage-CemTT_01.js} +1 -1
  54. package/dist/packem_shared/PocketBaseStorage-BZNzWj09.js +1 -0
  55. package/dist/packem_shared/{Rest-DY1neM_3.js → Rest-BAcUFAgk.js} +1 -1
  56. package/dist/packem_shared/{Rest-DWrS4Z_j.js → Rest-DukkeDZe.js} +1 -1
  57. package/dist/packem_shared/S3Storage-7hG3izjU.js +1 -0
  58. package/dist/packem_shared/{SftpMetaStorage-DYqXwCdM.js → SftpMetaStorage-Cs8b7uBO.js} +1 -1
  59. package/dist/packem_shared/SftpStorage-DnigT9GT.js +1 -0
  60. package/dist/packem_shared/{SharePointMetaStorage-DVM5-X6g.js → SharePointMetaStorage-DTVKAx6f.js} +1 -1
  61. package/dist/packem_shared/{SharePointStorage-r934t5HX.js → SharePointStorage-D1cWu-14.js} +1 -1
  62. package/dist/packem_shared/{SupabaseMetaStorage-ivXoYVUu.js → SupabaseMetaStorage-D_fGv0d6.js} +1 -1
  63. package/dist/packem_shared/SupabaseStorage-DbIUa6NZ.js +1 -0
  64. package/dist/packem_shared/{Tus-d2hPK5nV.js → Tus-BYTcw17H.js} +1 -1
  65. package/dist/packem_shared/{Tus-BMd67Cnb.js → Tus-BrP4RFTg.js} +1 -1
  66. package/dist/packem_shared/{UploadThingMetaStorage-BvKNzgm7.js → UploadThingMetaStorage-CAQ1uTfv.js} +1 -1
  67. package/dist/packem_shared/UploadThingStorage-B1qw1GrM.js +1 -0
  68. package/dist/packem_shared/{VercelBlobMetaStorage-CwaqWucZ.js → VercelBlobMetaStorage-DY4zAB6M.js} +1 -1
  69. package/dist/packem_shared/VercelBlobStorage-u6xmp8ox.js +1 -0
  70. package/dist/packem_shared/{base-handler-core-Cwd9uq_E.js → base-handler-core-Ccvdhx-k.js} +1 -1
  71. package/dist/packem_shared/{base-handler-fetch-_BD4V1W2.js → base-handler-fetch-DzbThEWy.js} +1 -1
  72. package/dist/packem_shared/{base-handler-node-BDNRnVIc.js → base-handler-node-CmCpLlBt.js} +1 -1
  73. package/dist/packem_shared/default-BrhEhSqN.js +1 -0
  74. package/dist/packem_shared/{defaultCloudStorageFileNameValidation-hWLdEgOD.js → defaultCloudStorageFileNameValidation-DwDn0XB5.js} +1 -1
  75. package/dist/packem_shared/disk-storage-fWizVrge.js +1 -0
  76. package/dist/packem_shared/{disk-storage-with-checksum.d-Dm4agCey.d.ts → disk-storage-with-checksum.d-aYBmkg45.d.ts} +8 -2
  77. package/dist/packem_shared/{executors.d-Cut3Gstb.d.ts → executors.d-WGJGPSZs.d.ts} +1 -1
  78. package/dist/packem_shared/{gcs-meta-storage-Bwts-MUe.js → gcs-meta-storage-COq32th7.js} +1 -1
  79. package/dist/packem_shared/get-file-status-DLS18Zvd.js +1 -0
  80. package/dist/packem_shared/index.d-CYdFIB-w.d.ts +455 -0
  81. package/dist/packem_shared/isRetryableError-CBZ65V6T.js +1 -0
  82. package/dist/packem_shared/local-meta-storage-Dr891Iy7.js +1 -0
  83. package/dist/packem_shared/{local-meta-storage.d-qZQI1JUe.d.ts → local-meta-storage.d-CuvN-KQ3.d.ts} +1 -1
  84. package/dist/packem_shared/{media-transformer.d-lQ_RUjb5.d.ts → media-transformer.d-DfU7VbFl.d.ts} +2 -2
  85. package/dist/packem_shared/memory-storage.d-DRbE0WMO.d.ts +101 -0
  86. package/dist/packem_shared/part-match-D_NwyoF3.js +1 -0
  87. package/dist/packem_shared/{path-D7rMc9nq-B718mbm6.js → path-D7rMc9nq-CPbxyMDy.js} +1 -1
  88. package/dist/packem_shared/{rest-base-C-a7pXUc.js → rest-base-xrnOBxS9.js} +1 -1
  89. package/dist/packem_shared/s3-base-storage-CqAyWHR6.js +1 -0
  90. package/dist/packem_shared/{s3-base-storage.d-CDIOMTpp.d.ts → s3-base-storage.d-BrHiKWFw.d.ts} +9 -2
  91. package/dist/packem_shared/storage-uhIhcN-O.js +1 -0
  92. package/dist/packem_shared/{storage.d-BoJgdi1n.d.ts → storage.d-X6TimMHY.d.ts} +23 -1
  93. package/dist/packem_shared/{tus-base.d-C28C_AY9.d.ts → tus-base.d-Ds7xYAJC.d.ts} +3 -3
  94. package/dist/packem_shared/{types.d-CPxJpoPH.d.ts → types.d-B72PbsLY.d.ts} +2 -2
  95. package/dist/packem_shared/{types.d-DCPQvHDI.d.ts → types.d-C4QumoP1.d.ts} +2 -2
  96. package/dist/packem_shared/{types.d-C0MDnUYc.d.ts → types.d-a1grKnaX.d.ts} +1 -1
  97. package/dist/storage/aws/index.d.ts +9 -3
  98. package/dist/storage/aws/index.js +1 -1
  99. package/dist/storage/aws-light/index.d.ts +2 -2
  100. package/dist/storage/aws-light/index.js +1 -1
  101. package/dist/storage/azure/index.d.ts +1 -1
  102. package/dist/storage/azure/index.js +1 -1
  103. package/dist/storage/box/index.d.ts +2 -2
  104. package/dist/storage/box/index.js +1 -1
  105. package/dist/storage/bun-s3/index.d.ts +2 -2
  106. package/dist/storage/bun-s3/index.js +1 -1
  107. package/dist/storage/bunny/index.d.ts +2 -2
  108. package/dist/storage/bunny/index.js +1 -1
  109. package/dist/storage/cloudinary/index.d.ts +2 -2
  110. package/dist/storage/cloudinary/index.js +1 -1
  111. package/dist/storage/dropbox/index.d.ts +2 -2
  112. package/dist/storage/dropbox/index.js +1 -1
  113. package/dist/storage/firebase/index.d.ts +2 -2
  114. package/dist/storage/firebase/index.js +1 -1
  115. package/dist/storage/ftp/index.d.ts +2 -2
  116. package/dist/storage/ftp/index.js +1 -1
  117. package/dist/storage/gcs/index.d.ts +1 -1
  118. package/dist/storage/gcs/index.js +1 -1
  119. package/dist/storage/google-drive/index.d.ts +2 -2
  120. package/dist/storage/google-drive/index.js +1 -1
  121. package/dist/storage/local/index.d.ts +3 -3
  122. package/dist/storage/local/index.js +1 -1
  123. package/dist/storage/memory/index.d.ts +6 -0
  124. package/dist/storage/memory/index.js +1 -0
  125. package/dist/storage/netlify-blob/index.d.ts +2 -2
  126. package/dist/storage/netlify-blob/index.js +1 -1
  127. package/dist/storage/onedrive/index.d.ts +4 -4
  128. package/dist/storage/onedrive/index.js +1 -1
  129. package/dist/storage/pocketbase/index.d.ts +2 -2
  130. package/dist/storage/pocketbase/index.js +1 -1
  131. package/dist/storage/sftp/index.d.ts +2 -2
  132. package/dist/storage/sftp/index.js +1 -1
  133. package/dist/storage/sharepoint/index.d.ts +3 -3
  134. package/dist/storage/sharepoint/index.js +1 -1
  135. package/dist/storage/supabase/index.d.ts +2 -2
  136. package/dist/storage/supabase/index.js +1 -1
  137. package/dist/storage/uploadthing/index.d.ts +2 -2
  138. package/dist/storage/uploadthing/index.js +1 -1
  139. package/dist/storage/vercel-blob/index.d.ts +2 -2
  140. package/dist/storage/vercel-blob/index.js +1 -1
  141. package/dist/transformer/audio-transformer.d.ts +2 -2
  142. package/dist/transformer/image-transformer.d.ts +2 -2
  143. package/dist/transformer/index.d.ts +3 -3
  144. package/dist/transformer/video-transformer.d.ts +2 -2
  145. package/package.json +6 -2
  146. package/dist/packem_shared/AzureStorage-Cmr0nPDq.js +0 -1
  147. package/dist/packem_shared/BoxStorage-DYzAYPIr.js +0 -1
  148. package/dist/packem_shared/BunS3Storage-BvaFeKeu.js +0 -1
  149. package/dist/packem_shared/BunnyStorage-DsQndiy5.js +0 -1
  150. package/dist/packem_shared/CloudinaryStorage-DiK0T7N7.js +0 -1
  151. package/dist/packem_shared/DiskStorage-RvZNMWe7.js +0 -1
  152. package/dist/packem_shared/DiskStorageWithChecksum-eGOV3leX.js +0 -1
  153. package/dist/packem_shared/DropboxStorage-Dfd78aJL.js +0 -1
  154. package/dist/packem_shared/Files-CtggibJ-.js +0 -1
  155. package/dist/packem_shared/FirebaseStorage-C-FwZOYA.js +0 -2
  156. package/dist/packem_shared/FtpStorage-DzaP89bG.js +0 -1
  157. package/dist/packem_shared/GCStorage-1vA3xkFO.js +0 -1
  158. package/dist/packem_shared/GoogleDriveStorage-D_RaKV_j.js +0 -1
  159. package/dist/packem_shared/NetlifyBlobStorage-C-IkXF0_.js +0 -1
  160. package/dist/packem_shared/OneDriveStorage-C7rqK2Wp.js +0 -1
  161. package/dist/packem_shared/PocketBaseStorage-Cdgr5w88.js +0 -1
  162. package/dist/packem_shared/S3Storage-Dn3l4WkO.js +0 -1
  163. package/dist/packem_shared/SftpStorage-CBW6MBLV.js +0 -1
  164. package/dist/packem_shared/SupabaseStorage-DMRhLPNo.js +0 -1
  165. package/dist/packem_shared/UploadThingStorage-BjF_gRMY.js +0 -1
  166. package/dist/packem_shared/VercelBlobStorage-Dx2jywjl.js +0 -1
  167. package/dist/packem_shared/disk-storage-Bmvawf-b.js +0 -1
  168. package/dist/packem_shared/index.d-DSZjPbvW.d.ts +0 -230
  169. package/dist/packem_shared/isRetryableError-BhizNeAz.js +0 -1
  170. package/dist/packem_shared/local-meta-storage-Bi0mK6gD.js +0 -1
  171. package/dist/packem_shared/part-match-B5fLLmFw.js +0 -1
  172. package/dist/packem_shared/s3-base-storage-Ek1HinGR.js +0 -1
  173. package/dist/packem_shared/storage-B-NDsI-o.js +0 -1
@@ -1,6 +1,6 @@
1
- import { F as File, L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, R as RetryConfig, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-BoJgdi1n.js";
1
+ import { F as File, L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, R as RetryConfig, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-X6TimMHY.js";
2
2
  import 'node:stream';
3
- import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-qZQI1JUe.js";
3
+ import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CuvN-KQ3.js";
4
4
  import { getStore } from '@netlify/blobs';
5
5
  import 'node:crypto';
6
6
  import 'node:http';
@@ -1 +1 @@
1
- import{default as o}from"../../packem_shared/NetlifyBlobFile-PMZLJ8AC.js";import{default as a}from"../../packem_shared/NetlifyBlobMetaStorage-ClIFdTkT.js";import{default as r}from"../../packem_shared/NetlifyBlobStorage-C-IkXF0_.js";export{o as NetlifyBlobFile,a as NetlifyBlobMetaStorage,r as NetlifyBlobStorage};
1
+ import{default as o}from"../../packem_shared/NetlifyBlobFile-PMZLJ8AC.js";import{default as a}from"../../packem_shared/NetlifyBlobMetaStorage-CqluIgV0.js";import{default as r}from"../../packem_shared/NetlifyBlobStorage-CkMw9Uyv.js";export{o as NetlifyBlobFile,a as NetlifyBlobMetaStorage,r as NetlifyBlobStorage};
@@ -1,7 +1,7 @@
1
- import { O as OneDriveFile, a as OneDriveStorageOptions } from "../../packem_shared/types.d-C0MDnUYc.js";
2
- export { type b as OneDriveClientCredentialsAuth, type c as OneDriveOAuthRefreshAuth } from "../../packem_shared/types.d-C0MDnUYc.js";
3
- import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-qZQI1JUe.js";
4
- import { L as LocalMetaStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-BoJgdi1n.js";
1
+ import { O as OneDriveFile, a as OneDriveStorageOptions } from "../../packem_shared/types.d-a1grKnaX.js";
2
+ export { type b as OneDriveClientCredentialsAuth, type c as OneDriveOAuthRefreshAuth } from "../../packem_shared/types.d-a1grKnaX.js";
3
+ import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CuvN-KQ3.js";
4
+ import { L as LocalMetaStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-X6TimMHY.js";
5
5
  import { Client } from '@microsoft/microsoft-graph-client';
6
6
  import 'node:stream';
7
7
  import 'node:crypto';
@@ -1 +1 @@
1
- import{default as a}from"../../packem_shared/OneDriveFile-XbVVKIJh.js";import{default as o}from"../../packem_shared/OneDriveMetaStorage-DS4f83X2.js";import{default as i}from"../../packem_shared/OneDriveStorage-C7rqK2Wp.js";export{a as OneDriveFile,o as OneDriveMetaStorage,i as OneDriveStorage};
1
+ import{default as a}from"../../packem_shared/OneDriveFile-XbVVKIJh.js";import{default as o}from"../../packem_shared/OneDriveMetaStorage-DPTNMpeq.js";import{default as i}from"../../packem_shared/OneDriveStorage-CEGYb6OC.js";export{a as OneDriveFile,o as OneDriveMetaStorage,i as OneDriveStorage};
@@ -1,6 +1,6 @@
1
- import { F as File, L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-BoJgdi1n.js";
1
+ import { F as File, L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-X6TimMHY.js";
2
2
  import 'node:stream';
3
- import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-qZQI1JUe.js";
3
+ import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CuvN-KQ3.js";
4
4
  import 'node:crypto';
5
5
  import 'node:http';
6
6
  import 'lru-cache';
@@ -1 +1 @@
1
- import{default as t}from"../../packem_shared/PocketBaseFile-CkAiSBb0.js";import{default as r}from"../../packem_shared/PocketBaseMetaStorage-B6utPncj.js";import{default as s}from"../../packem_shared/PocketBaseStorage-Cdgr5w88.js";export{t as PocketBaseFile,r as PocketBaseMetaStorage,s as PocketBaseStorage};
1
+ import{default as t}from"../../packem_shared/PocketBaseFile-CkAiSBb0.js";import{default as r}from"../../packem_shared/PocketBaseMetaStorage-CemTT_01.js";import{default as s}from"../../packem_shared/PocketBaseStorage-BZNzWj09.js";export{t as PocketBaseFile,r as PocketBaseMetaStorage,s as PocketBaseStorage};
@@ -1,6 +1,6 @@
1
- import { F as File, L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-BoJgdi1n.js";
1
+ import { F as File, L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-X6TimMHY.js";
2
2
  import 'node:stream';
3
- import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-qZQI1JUe.js";
3
+ import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CuvN-KQ3.js";
4
4
  import { ConnectOptions } from 'ssh2-sftp-client';
5
5
  import 'node:crypto';
6
6
  import 'node:http';
@@ -1 +1 @@
1
- import{default as a}from"../../packem_shared/SftpFile-CQCxZNVq.js";import{default as o}from"../../packem_shared/SftpMetaStorage-DYqXwCdM.js";import{default as p}from"../../packem_shared/SftpStorage-CBW6MBLV.js";export{a as SftpFile,o as SftpMetaStorage,p as SftpStorage};
1
+ import{default as a}from"../../packem_shared/SftpFile-CQCxZNVq.js";import{default as o}from"../../packem_shared/SftpMetaStorage-Cs8b7uBO.js";import{default as p}from"../../packem_shared/SftpStorage-DnigT9GT.js";export{a as SftpFile,o as SftpMetaStorage,p as SftpStorage};
@@ -1,6 +1,6 @@
1
- import { O as OneDriveFile, a as OneDriveStorageOptions } from "../../packem_shared/types.d-C0MDnUYc.js";
2
- import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-qZQI1JUe.js";
3
- import { L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-BoJgdi1n.js";
1
+ import { O as OneDriveFile, a as OneDriveStorageOptions } from "../../packem_shared/types.d-a1grKnaX.js";
2
+ import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CuvN-KQ3.js";
3
+ import { L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-X6TimMHY.js";
4
4
  import { Readable } from 'node:stream';
5
5
  import { Client } from '@microsoft/microsoft-graph-client';
6
6
  import 'node:crypto';
@@ -1 +1 @@
1
- import{default as t}from"../../packem_shared/SharePointFile-BA6X9Sxr.js";import{default as r}from"../../packem_shared/SharePointMetaStorage-DVM5-X6g.js";import{default as S}from"../../packem_shared/SharePointStorage-r934t5HX.js";export{t as SharePointFile,r as SharePointMetaStorage,S as SharePointStorage};
1
+ import{default as t}from"../../packem_shared/SharePointFile-BA6X9Sxr.js";import{default as r}from"../../packem_shared/SharePointMetaStorage-DTVKAx6f.js";import{default as S}from"../../packem_shared/SharePointStorage-D1cWu-14.js";export{t as SharePointFile,r as SharePointMetaStorage,S as SharePointStorage};
@@ -1,6 +1,6 @@
1
- import { F as File, L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-BoJgdi1n.js";
1
+ import { F as File, L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-X6TimMHY.js";
2
2
  import 'node:stream';
3
- import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-qZQI1JUe.js";
3
+ import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CuvN-KQ3.js";
4
4
  import { StorageClient } from '@supabase/storage-js';
5
5
  import 'node:crypto';
6
6
  import 'node:http';
@@ -1 +1 @@
1
- import{default as t}from"../../packem_shared/SupabaseFile-DZ1iv9gM.js";import{default as r}from"../../packem_shared/SupabaseMetaStorage-ivXoYVUu.js";import{default as p}from"../../packem_shared/SupabaseStorage-DMRhLPNo.js";export{t as SupabaseFile,r as SupabaseMetaStorage,p as SupabaseStorage};
1
+ import{default as t}from"../../packem_shared/SupabaseFile-DZ1iv9gM.js";import{default as r}from"../../packem_shared/SupabaseMetaStorage-D_fGv0d6.js";import{default as p}from"../../packem_shared/SupabaseStorage-DbIUa6NZ.js";export{t as SupabaseFile,r as SupabaseMetaStorage,p as SupabaseStorage};
@@ -1,7 +1,7 @@
1
1
  import { UTApi } from 'uploadthing/server';
2
- import { L as LocalMetaStorageOptions, i as BaseStorageOptions, F as File, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-BoJgdi1n.js";
2
+ import { L as LocalMetaStorageOptions, i as BaseStorageOptions, F as File, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-X6TimMHY.js";
3
3
  import 'node:stream';
4
- import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-qZQI1JUe.js";
4
+ import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CuvN-KQ3.js";
5
5
  import 'node:crypto';
6
6
  import 'node:http';
7
7
  import 'lru-cache';
@@ -1 +1 @@
1
- import{default as e}from"../../packem_shared/UploadThingFile-BpG9mE8K.js";import{default as r}from"../../packem_shared/UploadThingMetaStorage-BvKNzgm7.js";import{default as d}from"../../packem_shared/UploadThingStorage-BjF_gRMY.js";export{e as UploadThingFile,r as UploadThingMetaStorage,d as UploadThingStorage};
1
+ import{default as e}from"../../packem_shared/UploadThingFile-BpG9mE8K.js";import{default as r}from"../../packem_shared/UploadThingMetaStorage-CAQ1uTfv.js";import{default as d}from"../../packem_shared/UploadThingStorage-B1qw1GrM.js";export{e as UploadThingFile,r as UploadThingMetaStorage,d as UploadThingStorage};
@@ -1,6 +1,6 @@
1
- import { L as LocalMetaStorageOptions, i as BaseStorageOptions, F as File, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-BoJgdi1n.js";
1
+ import { L as LocalMetaStorageOptions, i as BaseStorageOptions, F as File, M as MetaStorage, e as FileInit, O as OperationOptions, f as FilePart, g as FileQuery, a as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-X6TimMHY.js";
2
2
  import 'node:stream';
3
- import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-qZQI1JUe.js";
3
+ import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CuvN-KQ3.js";
4
4
  import { copy, del, list, put } from '@vercel/blob';
5
5
  import 'node:crypto';
6
6
  import 'node:http';
@@ -1 +1 @@
1
- import{default as r}from"../../packem_shared/VercelBlobFile-Cni_1qwD.js";import{default as a}from"../../packem_shared/VercelBlobMetaStorage-CwaqWucZ.js";import{default as f}from"../../packem_shared/VercelBlobStorage-Dx2jywjl.js";export{r as VercelBlobFile,a as VercelBlobMetaStorage,f as VercelBlobStorage};
1
+ import{default as r}from"../../packem_shared/VercelBlobFile-Cni_1qwD.js";import{default as a}from"../../packem_shared/VercelBlobMetaStorage-DY4zAB6M.js";import{default as f}from"../../packem_shared/VercelBlobStorage-u6xmp8ox.js";export{r as VercelBlobFile,a as VercelBlobMetaStorage,f as VercelBlobStorage};
@@ -1,5 +1,5 @@
1
- import { F as File, a as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-BoJgdi1n.js";
2
- import { s as AudioTransformerConfig, t as AudioTransformResult, u as AudioResampleOptions, v as AudioChannelMixOptions, w as AudioTransformOptions, x as AudioTransformationStep, r as BaseTransformer } from "../packem_shared/types.d-DCPQvHDI.js";
1
+ import { F as File, a as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-X6TimMHY.js";
2
+ import { A as AudioTransformerConfig, h as AudioTransformResult, i as AudioResampleOptions, j as AudioChannelMixOptions, k as AudioTransformOptions, l as AudioTransformationStep, B as BaseTransformer } from "../packem_shared/types.d-C4QumoP1.js";
3
3
  import 'node:stream';
4
4
  import 'node:crypto';
5
5
  import 'node:http';
@@ -1,6 +1,6 @@
1
1
  import { Readable } from 'node:stream';
2
- import { F as File, a as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-BoJgdi1n.js";
3
- import { I as ImageTransformerConfig, T as TransformResult, R as ResizeOptions, C as CropOptions, a as RotateOptions, b as ImageFormat, c as TransformOptions, S as SharpenOptions, B as BlurOptions, M as MedianOptions, d as CLAHEOptions, e as ConvolveOptions, f as ThresholdOptions, g as BooleanOptions, L as LinearOptions, h as RecombineOptions, i as ModulateOptions, j as TintOptions, G as GreyscaleOptions, k as ColourspaceOptions, E as ExtractChannelOptions, J as JoinChannelOptions, l as BandboolOptions, A as AffineOptions, D as DilateOptions, m as ErodeOptions, P as PipelineColourspaceOptions, n as ToColourspaceOptions, o as RemoveAlphaOptions, p as EnsureAlphaOptions, q as TransformationStep, r as BaseTransformer } from "../packem_shared/types.d-DCPQvHDI.js";
2
+ import { F as File, a as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-X6TimMHY.js";
3
+ import { I as ImageTransformerConfig, T as TransformResult, R as ResizeOptions, C as CropOptions, m as RotateOptions, n as ImageFormat, o as TransformOptions, S as SharpenOptions, p as BlurOptions, q as MedianOptions, r as CLAHEOptions, s as ConvolveOptions, t as ThresholdOptions, u as BooleanOptions, L as LinearOptions, v as RecombineOptions, w as ModulateOptions, x as TintOptions, G as GreyscaleOptions, y as ColourspaceOptions, E as ExtractChannelOptions, J as JoinChannelOptions, z as BandboolOptions, D as AffineOptions, F as DilateOptions, H as ErodeOptions, P as PipelineColourspaceOptions, K as ToColourspaceOptions, N as RemoveAlphaOptions, O as EnsureAlphaOptions, Q as TransformationStep, B as BaseTransformer } from "../packem_shared/types.d-C4QumoP1.js";
4
4
  import 'node:crypto';
5
5
  import 'node:http';
6
6
  import 'lru-cache';
@@ -1,6 +1,6 @@
1
- export { type v as AudioChannelMixOptions, type u as AudioResampleOptions, type w as AudioTransformOptions, type t as AudioTransformResult, type x as AudioTransformationStep, type s as AudioTransformerConfig, r as BaseTransformer, type C as CropOptions, type b as ImageFormat, type I as ImageTransformerConfig, type U as MediaTransformQuery, type Q as MediaTransformResult, type W as MediaTransformationStep, type O as MediaTransformerConfig, type R as ResizeOptions, type a as RotateOptions, type c as TransformOptions, type T as TransformResult, type q as TransformationStep, type F as VideoCropOptions, type z as VideoResizeOptions, type H as VideoRotateOptions, type K as VideoTransformOptions, type y as VideoTransformResult, type N as VideoTransformationStep, type V as VideoTransformerConfig } from "../packem_shared/types.d-DCPQvHDI.js";
2
- export { M as MediaTransformer } from "../packem_shared/media-transformer.d-lQ_RUjb5.js";
3
- import { a as FileReturn } from "../packem_shared/storage.d-BoJgdi1n.js";
1
+ export { type j as AudioChannelMixOptions, type i as AudioResampleOptions, type k as AudioTransformOptions, type h as AudioTransformResult, type l as AudioTransformationStep, type A as AudioTransformerConfig, B as BaseTransformer, type C as CropOptions, type n as ImageFormat, type I as ImageTransformerConfig, type U as MediaTransformQuery, type g as MediaTransformResult, type W as MediaTransformationStep, type M as MediaTransformerConfig, type R as ResizeOptions, type m as RotateOptions, type o as TransformOptions, type T as TransformResult, type Q as TransformationStep, type c as VideoCropOptions, type b as VideoResizeOptions, type d as VideoRotateOptions, type e as VideoTransformOptions, type a as VideoTransformResult, type f as VideoTransformationStep, type V as VideoTransformerConfig } from "../packem_shared/types.d-C4QumoP1.js";
2
+ export { M as MediaTransformer } from "../packem_shared/media-transformer.d-DfU7VbFl.js";
3
+ import { a as FileReturn } from "../packem_shared/storage.d-X6TimMHY.js";
4
4
  import 'node:stream';
5
5
  import 'node:crypto';
6
6
  import 'node:http';
@@ -1,5 +1,5 @@
1
- import { F as File, a as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-BoJgdi1n.js";
2
- import { V as VideoTransformerConfig, y as VideoTransformResult, z as VideoResizeOptions, F as VideoCropOptions, H as VideoRotateOptions, K as VideoTransformOptions, N as VideoTransformationStep, r as BaseTransformer } from "../packem_shared/types.d-DCPQvHDI.js";
1
+ import { F as File, a as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-X6TimMHY.js";
2
+ import { V as VideoTransformerConfig, a as VideoTransformResult, b as VideoResizeOptions, c as VideoCropOptions, d as VideoRotateOptions, e as VideoTransformOptions, f as VideoTransformationStep, B as BaseTransformer } from "../packem_shared/types.d-C4QumoP1.js";
3
3
  import 'node:stream';
4
4
  import 'node:crypto';
5
5
  import 'node:http';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/storage",
3
- "version": "1.0.0-alpha.31",
3
+ "version": "1.0.0-alpha.32",
4
4
  "description": "Visulima upload - Store files in a web-accessible location via a simplified API. Can automatically scale and rotate images. Includes S3, Azure, GCS and local filesystem-based backends with the most convenient features of each.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -120,6 +120,10 @@
120
120
  "types": "./dist/storage/local/index.d.ts",
121
121
  "import": "./dist/storage/local/index.js"
122
122
  },
123
+ "./provider/memory": {
124
+ "types": "./dist/storage/memory/index.d.ts",
125
+ "import": "./dist/storage/memory/index.js"
126
+ },
123
127
  "./provider/ftp": {
124
128
  "types": "./dist/storage/ftp/index.d.ts",
125
129
  "import": "./dist/storage/ftp/index.js"
@@ -263,7 +267,7 @@
263
267
  "dependencies": {
264
268
  "@remix-run/multipart-parser": "0.16.0",
265
269
  "@sindresorhus/fnv1a": "3.1.0",
266
- "@visulima/pagination": "5.0.0-alpha.11",
270
+ "@visulima/pagination": "5.0.0-alpha.12",
267
271
  "file-type": "22.0.1",
268
272
  "lru-cache": "11.4.0",
269
273
  "mime": "^4.1.0",
@@ -1 +0,0 @@
1
- var f=Object.defineProperty;var y=(d,t)=>f(d,"name",{value:t,configurable:!0});import{L as b}from"./path-D7rMc9nq-B718mbm6.js";import{d as C}from"./detect-file-type-5JhzC9RU.js";import{throwErrorCode as c,ERRORS as u}from"./ERRORS-CyOuSMLY.js";import{B as w,t as O}from"./storage-B-NDsI-o.js";import{v as T}from"./local-meta-storage-Bi0mK6gD.js";import{c as k,b as E,a as p,d as m}from"./azure-meta-storage-C4SrMtT2.js";import S from"./AzureFile-Dgj2Tef4.js";import{r as F,o as N}from"./part-match-B5fLLmFw.js";import{o as v}from"./has-content-Bx2p8Okx.js";var B=Object.defineProperty,R=y((d,t)=>B(d,"name",{value:t,configurable:!0}),"f");class q extends w{static name="azure";checksumTypes=["md5"];get raw(){return this.client}meta;client;containerClient;root;resolvedRetryConfig;signer;sasToken;anonymous;constructor(t){if(super(t),!t.containerName)throw new Error("Missing required parameter: Azure container name.");const{anonymous:r,client:e,sasToken:n,signer:s}=k(t);this.client=e,this.signer=s,this.sasToken=n,this.anonymous=r,this.containerClient=this.client.getContainerClient(t.containerName),this.root=t.root?b(t.root).replace(/^\//,""):"";const o={backoffMultiplier:2,initialDelay:1e3,maxDelay:3e4,maxRetries:3,retryableStatusCodes:[408,429,500,502,503,504],shouldRetry:R(a=>{const i=a;if(i.statusCode&&[408,429,500,502,503,504].includes(i.statusCode))return!0;if(a instanceof Error){const l=i.code;if(l==="ECONNRESET"||l==="ETIMEDOUT"||l==="ENOTFOUND"||l==="ECONNREFUSED")return!0}return!1},"shouldRetry"),...t.retryConfig};if(this.resolvedRetryConfig=o,t.metaStorage)this.meta=t.metaStorage;else{let a={...t,...t.metaStorageConfig,logger:this.logger};if("directory"in a)this.logger?.debug("Using local meta storage"),this.meta=new T(a);else{const i=t.metaStorageConfig;i&&["accountKey","accountName","connectionString","credential","endpoint","sasToken"].some(l=>l in i)||(a={...a,client:this.client}),this.meta=new E(a)}}this.isReady=!1,this.accessCheck().then(()=>{this.isReady=!0}).catch(a=>{this.logger?.error("Storage access check failed: %O",a)})}getRetryConfig(){return this.resolvedRetryConfig}async create(t,r){return this.instrumentOperation("create",async()=>{const e={...t};if(t.ttl){const i=typeof t.ttl=="string"?O(t.ttl):t.ttl;i!==void 0&&(e.expiredAt=Date.now()+i)}const n=new S(e);n.name=this.namingFunction(n),await this.validate(n);try{const i=await this.getMeta(n.id);if(i.bytesWritten>=0)return i}catch{}const s=this.containerClient.getBlockBlobClient(this.getFullPath(n.name)),o={};for(const[i,l]of Object.entries(n.metadata||{}))o[i]=JSON.stringify(l);const a=await this.runOperation(r,i=>s.uploadData(Buffer.from(""),{abortSignal:i,blobHTTPHeaders:{blobContentType:n.contentType},metadata:{name:n.name,originalName:n.originalName,...o}}));return a.requestId===void 0?c(u.FILE_ERROR,"azure create upload error"):(n.requestId=a.requestId,n.uri=a._response.headers.get("location"),n.bytesWritten=0,await this.saveMeta(n),n.status="created",await this.onCreate(n),n)})}async delete({id:t},r){return this.instrumentOperation("delete",async()=>{const e=await this.getMeta(t);e.status="deleted",await this.runOperation(r,s=>this.containerClient.getBlockBlobClient(this.getFullPath(e.name)).deleteIfExists({abortSignal:s})),await this.deleteMeta(e.id);const n={...e};return await this.onDelete(n),n})}async move(t,r,e){return this.instrumentOperation("move",async()=>{const n=await this.copy(t,r,e),s=this.getFullPath(t);return await this.runOperation(e,o=>this.containerClient.getBlockBlobClient(s).deleteIfExists({abortSignal:o})),n})}async write(t,r){return this.instrumentOperation("write",async()=>{let e;if("contentType"in t&&"metadata"in t&&!("body"in t)&&!("start"in t)?e=t:(e=await this.getMeta(t.id),await this.checkIfExpired(e)),e.status==="completed")return e;if(!F(t,e))return c(u.FILE_CONFLICT);const n=await this.lock(t.id);try{if(v(t)){if((e.bytesWritten===0||Number.isNaN(e.bytesWritten))&&(!e.contentType||e.contentType==="application/octet-stream"))try{const{fileType:i,stream:l}=await C(t.body);i?.mime&&(e.contentType=i.mime),t.body=l}catch{}const s=this.containerClient.getBlockBlobClient(this.getFullPath(e.name)),o=new AbortController;t.body.on("error",()=>{o.abort()});const a=await this.runOperation(r,i=>{const l=i?AbortSignal.any([o.signal,i]):o.signal;return s.uploadStream(t.body,void 0,void 0,{abortSignal:l,blobHTTPHeaders:{blobContentType:e.contentType??"application/octet-stream"},metadata:e.metadata})},{replayable:!1});if(a.requestId===void 0)return c(u.FILE_ERROR,"azure write upload error");e.requestId=a.requestId,e.bytesWritten+=t.contentLength||0,e.status=N(e),e.status==="completed"&&(e.uri=a._response.headers.get("location"),await this.deleteMeta(e.id))}}finally{await this.unlock(t.id,n)}return e})}async get({id:t},r){return this.instrumentOperation("get",async()=>{const e=this.containerClient.getBlockBlobClient(this.getFullPath(t));if(!await this.runOperation(r,h=>e.exists({abortSignal:h})))try{return await this.getMeta(t),c(u.GONE)}catch{return c(u.FILE_NOT_FOUND)}const n=await this.runOperation(r,h=>e.getProperties({abortSignal:h})),{contentLength:s,contentType:o,etag:a,expiresOn:i,lastModified:l,metadata:g}=n;return{content:await this.runOperation(r,h=>e.downloadToBuffer(0,void 0,{abortSignal:h})),contentType:o,ETag:a,expiredAt:i,id:t,metadata:g||{},modifiedAt:l,name:g?.name||t,originalName:g?.originalName||"",size:s}})}async exists({id:t},r){return this.instrumentOperation("exists",async()=>{try{await this.getMeta(t);const e=this.containerClient.getBlockBlobClient(this.getFullPath(t));return await this.runOperation(r,n=>e.exists({abortSignal:n}))}catch{return!1}})}async copy(t,r,e){return this.instrumentOperation("copy",async()=>{const n=this.containerClient.getBlockBlobClient(this.getFullPath(t));if(!await this.runOperation(e,i=>n.exists({abortSignal:i})))try{return await this.getMeta(t),c(u.GONE)}catch{return c(u.FILE_NOT_FOUND)}const s=this.containerClient.getBlockBlobClient(this.getFullPath(r));let o=n.url;this.signer?.kind==="userDelegation"?o=await p(this.containerClient.getBlobClient(this.getFullPath(t)),this.signer,{expiresIn:300,permissions:"r"}):this.sasToken&&(o=m(n.url,this.sasToken));const a=await this.runOperation(e,i=>s.beginCopyFromURL(o,{abortSignal:i}));return await this.runOperation(e,()=>a.pollUntilDone()),{...await this.getMeta(t),id:r,name:r}})}async list(t=1e3,r){return this.instrumentOperation("list",async()=>{const e=[];let n=!0,s;for(;n&&e.length<t;)try{const o=Math.min(t-e.length,1e3),a=(await this.runOperation(r,i=>this.containerClient.listBlobsFlat({abortSignal:i,includeMetadata:!0,prefix:this.root}).byPage({continuationToken:s,maxPageSize:o}).next())).value;if(a!==void 0&&"segment"in a){for(const i of a.segment.blobItems)if(!i.deleted&&(e.push({createdAt:i.properties.createdOn,id:i.name,modifiedAt:i.properties.lastModified}),e.length>=t))break}n=a?.continuationToken!==void 0,n&&(s=a.continuationToken)}catch(o){const a=this.normalizeError(o instanceof Error?o:new Error(String(o)));throw await this.onError(a),o}return e},{limit:t})}async getReadUrl(t,r){const e=this.containerClient.getBlobClient(this.getFullPath(t));return this.signer?p(e,this.signer,{expiresIn:r?.expiresIn??3600,permissions:"r",...r?.responseContentDisposition&&{contentDisposition:r.responseContentDisposition},...r?.responseContentType&&{contentType:r.responseContentType}}):this.sasToken?m(e.url,this.sasToken):this.anonymous?e.url:c(u.METHOD_NOT_ALLOWED,"azure: cannot produce a read URL without a shared key, Microsoft Entra credential, or SAS token. Construct the adapter with accountKey + accountName, a connectionString containing an account key, a credential + accountName, or a sasToken.")}async getUploadUrl(t,r){const e=this.containerClient.getBlobClient(this.getFullPath(t));return this.signer?p(e,this.signer,{expiresIn:r?.expiresIn??3600,permissions:"cw"}):this.sasToken?m(e.url,this.sasToken):c(u.METHOD_NOT_ALLOWED,"azure: cannot produce an upload URL without a shared key, Microsoft Entra credential, or SAS token. Anonymous (public-container) access is read-only.")}getFullPath(t){return this.assetFolder!==void 0?`${this.assetFolder}/${t}`:t}async accessCheck(){await this.runOperation(void 0,t=>this.containerClient.getProperties({abortSignal:t}))}}export{q as default};
@@ -1 +0,0 @@
1
- var x=Object.defineProperty;var C=(a,e)=>x(a,"name",{value:e,configurable:!0});import{Readable as b}from"node:stream";import{BoxDeveloperTokenAuth as F,BoxClient as p,OAuthConfig as T,BoxOAuth as S,CcgConfig as U,BoxCcgAuth as L,BoxJwtAuth as R,JwtConfig as v}from"box-typescript-sdk-gen";import{throwErrorCode as B,ERRORS as k}from"./ERRORS-CyOuSMLY.js";import{B as A}from"./storage-B-NDsI-o.js";import w from"./BoxFile-Be0S4N1L.js";import D from"./BoxMetaStorage-DLdXbZaV.js";import{o as E,r as H}from"./part-match-B5fLLmFw.js";import{u as _}from"./update-size-DANV7aa2.js";import{o as N}from"./has-content-Bx2p8Okx.js";var M=Object.defineProperty,c=C((a,e)=>M(a,"name",{value:e,configurable:!0}),"u");const j="0",$=50*1024*1024,m={ensureReady:c(()=>Promise.resolve(),"ensureReady")},z=c(a=>{let e=0,i=a.length;for(;e<i&&a[e]==="/";)e+=1;for(;i>e&&a[i-1]==="/";)i-=1;return e===0&&i===a.length?a:a.slice(e,i)},"trimSlashes"),y=c(a=>{const e=z(a);if(!e)throw new Error("Box: key must not be empty");const i=e.split("/").filter(r=>r.length>0),t=i.pop()??"";if(!t)throw new Error(`Box: key "${a}" has no file name segment`);return{leaf:t,parents:i}},"splitKey"),P=c(async a=>{const e=[];for await(const i of a)e.push(Buffer.from(i));return Buffer.concat(e)},"collectStream"),I=c(a=>b.from(a),"bufferToReadable"),J=c(a=>"configJsonString"in a?v.fromConfigJsonString(a.configJsonString):v.fromConfigFile(a.configFilePath),"buildJwtConfig"),K=c(a=>[a.developerToken,a.oauth,a.ccg,a.jwt].filter(e=>e!==void 0).length,"countAuthMethods"),q=c(a=>{if(a.client)return{authHandle:m,client:a.client};if(K(a)>1)throw new Error("Box storage: pass exactly one of `developerToken`, `oauth`, `ccg`, or `jwt`.");if(a.developerToken!==void 0){const i=new F({token:a.developerToken});return{authHandle:m,client:new p({auth:i})}}if(a.oauth){const{clientId:i,clientSecret:t,refreshToken:r}=a.oauth,s=new T({clientId:i,clientSecret:t}),n=new S({config:s});let l;const o=c(async()=>{await n.tokenStorage.store({accessToken:"",refreshToken:r})},"seed");return{authHandle:{ensureReady:c(()=>(l||(l=o()),l),"ensureReady")},client:new p({auth:n})}}if(a.ccg){const{clientId:i,clientSecret:t,enterpriseId:r,userId:s}=a.ccg;if(!r&&!s)throw new Error("Box storage: `ccg` auth requires either `enterpriseId` or `userId`.");const n=new U({clientId:i,clientSecret:t,...r!==void 0&&{enterpriseId:r},...s!==void 0&&{userId:s}}),l=new L({config:n});return{authHandle:m,client:new p({auth:l})}}if(a.jwt){const i=J(a.jwt),t=new R({config:i});return{authHandle:m,client:new p({auth:t})}}const e=process.env.BOX_DEVELOPER_TOKEN;if(e){const i=new F({token:e});return{authHandle:m,client:new p({auth:i})}}throw new Error("Box storage: missing auth. Pass `client`, `developerToken`, `oauth`, `ccg`, or `jwt`. Env fallback: BOX_DEVELOPER_TOKEN.")},"resolveAuth"),W=c(a=>{if(a&&typeof a=="object"){const e=a,i=e.responseInfo?.code??e.responseInfo?.body?.code;return e.responseInfo?.statusCode===404||i==="not_found"||i==="file_not_found"||i==="folder_not_found"||i==="trashed"}return!1},"isNotFoundError"),O=c(a=>{if(a&&typeof a=="object"){const e=a,i=e.responseInfo?.code??e.responseInfo?.body?.code;return e.responseInfo?.statusCode===409||i==="item_name_in_use"||i==="conflict"}return!1},"isConflictError");class ae extends A{static name="box";checksumTypes=[];meta;authHandle;client;fileIdCache;folderIdCache;publicByDefault;rootFolderId;constructor(e){super(e),this.rootFolderId=e.rootFolderId??j,this.publicByDefault=e.publicByDefault??!1;const i=q(e);this.client=i.client,this.authHandle=i.authHandle,this.folderIdCache=new Map,this.fileIdCache=new Map,this.meta=e.metaStorage??new D(e.metaStorageConfig),this.isReady=!0}get raw(){return this.client}async create(e,i){return this.instrumentOperation("create",async()=>{const t=new w(e);t.name=this.namingFunction(t),await this.validate(t);try{const r=await this.getMeta(t.id);if(r.bytesWritten>=0)return r}catch{}return t.bytesWritten=0,t.status=E(t),await this.saveMeta(t),await this.onCreate(t),t})}async write(e,i){return this.instrumentOperation("write",async()=>{let t;if("contentType"in e&&"metadata"in e&&!("body"in e)&&!("start"in e)?t=e:(t=await this.getMeta(e.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(e.size!==void 0&&_(t,e.size),!H(e,t))throw new Error("File part does not match");const r=await this.lock(e.id);try{if(N(e)){if(this.isUnsupportedChecksum(e.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");await this.authHandle.ensureReady();const s=await P(e.body),n=t.name||t.id,{leaf:l,parents:o}=y(n),d=await this.resolveFolderId(o,{create:!0},i),f=await this.resolveExistingFileForUpload(n,d,l,i),h=await this.performUpload(f,d,l,s,i);h.id&&(this.fileIdCache.set(n,h.id),this.publicByDefault&&await this.ensureSharedLink(h.id,i)),t.bytesWritten=s.length,t.size=s.length,t.boxFileId=h.id,t.eTag=h.etag??void 0,t.ETag=h.etag??void 0}return t.status=E(t),t.status==="completed"&&await this.internalOnComplete(t),await this.saveMeta(t),t}finally{await this.unlock(e.id,r)}})}async delete({id:e},i){return this.instrumentOperation("delete",async()=>{let t;try{t=await this.getMeta(e)}catch{}const r=t?.name??e;await this.authHandle.ensureReady();try{const s=t?.boxFileId??await this.resolveFileId(r,i);await this.runOperation(i,()=>this.client.files.deleteFileById(s)),this.fileIdCache.delete(r)}catch(s){if(!W(s))throw s}return t?(t.status="deleted",await this.deleteMeta(t.id),await this.onDelete(t),t):Object.assign(new w({contentType:"application/octet-stream",metadata:{},originalName:e}),{id:e,name:e,status:"deleted"})})}async get({id:e},i){return this.instrumentOperation("get",async()=>{let t,r=e;try{t=await this.checkIfExpired(await this.getMeta(e)),r=t.name??e}catch{}await this.authHandle.ensureReady();const s=t?.boxFileId??await this.resolveFileId(r,i),n=await this.runOperation(i,()=>this.client.files.getFileById(s)),l=await this.runOperation(i,()=>this.client.downloads.getDownloadFileUrl(s)),o=await this.runOperation(i,()=>fetch(l));if(!o.ok)throw new Error(`Box: download fetch failed (${o.status})`);const d=await this.runOperation(i,()=>o.arrayBuffer()),f=Buffer.from(d);return{content:f,contentType:t?.contentType??"application/octet-stream",ETag:t?.ETag??n.etag??void 0,expiredAt:t?.expiredAt,id:e,metadata:t?.metadata??{},modifiedAt:t?.modifiedAt??n.modifiedAt??n.contentModifiedAt??void 0,name:t?.name??n.name??r,originalName:t?.originalName??n.name??r,size:t?.size??n.size??f.length}})}async copy(e,i,t){return this.instrumentOperation("copy",async()=>{await this.authHandle.ensureReady();const r=await this.resolveFileId(e,t),{leaf:s,parents:n}=y(i),l=await this.resolveFolderId(n,{create:!0},t),o=await this.runOperation(t,()=>this.client.files.copyFile(r,{name:s,parent:{id:l}}));o.id&&this.fileIdCache.set(i,o.id);const d=new w({contentType:"application/octet-stream",metadata:{},originalName:i});return d.id=i,d.name=i,d.boxFileId=o.id,d.eTag=o.etag??void 0,d.ETag=o.etag??void 0,d})}async move(e,i,t){return this.instrumentOperation("move",async()=>{await this.authHandle.ensureReady();const r=await this.resolveFileId(e,t),{leaf:s,parents:n}=y(i),l=await this.resolveFolderId(n,{create:!0},t),o=await this.runOperation(t,()=>this.client.files.updateFileById(r,{requestBody:{name:s,parent:{id:l}}}));this.fileIdCache.delete(e),o.id&&this.fileIdCache.set(i,o.id);const d=new w({contentType:"application/octet-stream",metadata:{},originalName:i});d.id=i,d.name=i,d.boxFileId=o.id,d.eTag=o.etag??void 0,d.ETag=o.etag??void 0;try{await this.deleteMeta(e)}catch{}return d})}async list(e=1e3,i){return this.instrumentOperation("list",async()=>{await this.authHandle.ensureReady();const t=[];let r=0;const s=Math.min(e,1e3);for(;t.length<e;){const n=(await this.runOperation(i,()=>this.client.folders.getFolderItems(this.rootFolderId,{queryParams:{fields:["id","name","size","modified_at","etag","type"],limit:s,offset:r}}))).entries??[];for(const l of n){const o=l;if(o.type!=="file"||!o.id||!o.name)continue;this.fileIdCache.set(o.name,o.id);const d=new w({contentType:"application/octet-stream",metadata:{},originalName:o.name});if(d.id=o.name,d.name=o.name,d.boxFileId=o.id,d.eTag=o.etag??void 0,d.ETag=o.etag??void 0,d.size=o.size??0,d.modifiedAt=o.modifiedAt??o.contentModifiedAt??void 0,t.push(d),t.length>=e)break}if(n.length<s)break;r+=n.length}return t},{limit:e})}async getReadUrl(e,i){if(i?.responseContentDisposition||i?.responseContentType)return B(k.METHOD_NOT_ALLOWED,"Box: `responseContentDisposition` / `responseContentType` are not supported — Box download URLs and shared-link URLs have no overrides.");await this.authHandle.ensureReady();const t=await this.resolveFileId(e);return this.publicByDefault?this.ensureSharedLink(t):this.client.downloads.getDownloadFileUrl(t)}async getUploadUrl(e,i){return B(k.METHOD_NOT_ALLOWED,"Box: `getUploadUrl` is not supported. Box uploads require a multipart POST with an `attributes` JSON part and a file bytes part; this doesn't fit the PUT-style upload-url contract. Use `write()` server-side, or the Box UI Elements / Box Content Uploader for browser flows.")}async findChildByName(e,i,t){let r=0;const s=1e3;for(;;){const n=(await this.runOperation(t,()=>this.client.folders.getFolderItems(e,{queryParams:{fields:["id","name","type"],limit:s,offset:r}}))).entries??[];for(const l of n){const o=l;if(o.name===i&&o.id&&o.type)return{id:o.id,type:o.type}}if(n.length<s)return;r+=n.length}}folderCacheKey(e){return e.join("/")}async resolveFolderId(e,i,t){if(e.length===0)return this.rootFolderId;const r=this.folderCacheKey(e),s=this.folderIdCache.get(r);if(s)return s;let n=this.rootFolderId;const l=[];for(const o of e){l.push(o);const d=this.folderCacheKey(l),f=this.folderIdCache.get(d);if(f){n=f;continue}const h=await this.findChildByName(n,o,t);if(h&&h.type==="folder"){n=h.id,this.folderIdCache.set(d,n);continue}if(h&&h.type!=="folder")throw new Error(`Box: path segment "${o}" exists but is not a folder`);if(!i.create)throw new Error(`Box: folder "${l.join("/")}" not found`);try{const u=await this.runOperation(t,()=>this.client.folders.createFolder({name:o,parent:{id:n}}));if(!u.id)throw new Error(`Box: createFolder did not return an id for "${o}"`);n=u.id,this.folderIdCache.set(d,n)}catch(u){if(O(u)){const g=await this.findChildByName(n,o,t);if(g&&g.type==="folder"){n=g.id,this.folderIdCache.set(d,n);continue}}throw u}}return this.folderIdCache.set(r,n),n}async resolveFileId(e,i){const t=this.fileIdCache.get(e);if(t)return t;const{leaf:r,parents:s}=y(e),n=await this.resolveFolderId(s,{create:!1},i),l=await this.findChildByName(n,r,i);if(!l||l.type!=="file")throw new Error(`Box: file "${e}" not found`);return this.fileIdCache.set(e,l.id),l.id}async resolveExistingFileForUpload(e,i,t,r){const s=this.fileIdCache.get(e);if(s)return s;const n=await this.findChildByName(i,t,r);if(n){if(n.type==="file")return this.fileIdCache.set(e,n.id),n.id;throw new Error(`Box: "${e}" already exists as a non-file (${n.type})`)}}async performUpload(e,i,t,r,s){if(r.byteLength>$)return await this.runOperation(s,()=>this.client.chunkedUploads.uploadBigFile(I(r),t,r.byteLength,i));if(e){const l=((await this.runOperation(s,()=>this.client.uploads.uploadFileVersion(e,{attributes:{name:t},file:I(r)}))).entries??[])[0];if(!l)throw new Error("Box: uploadFileVersion returned no file");return l}const n=((await this.runOperation(s,()=>this.client.uploads.uploadFile({attributes:{name:t,parent:{id:i}},file:I(r)}))).entries??[])[0];if(!n)throw new Error("Box: uploadFile returned no file");return n}async ensureSharedLink(e,i){try{const t=(await this.runOperation(i,()=>this.client.sharedLinksFiles.addShareLinkToFile(e,{sharedLink:{access:"open"}},{fields:"shared_link"}))).sharedLink;return(t?.downloadUrl??t?.url)||this.fetchSharedLinkUrl(e,i)}catch(t){if(O(t))return this.fetchSharedLinkUrl(e,i);throw t}}async fetchSharedLinkUrl(e,i){const t=(await this.runOperation(i,()=>this.client.sharedLinksFiles.getSharedLinkForFile(e,{fields:"shared_link"}))).sharedLink,r=t?.downloadUrl??t?.url;if(!r)throw new Error("Box: file has no shared link. Call write() with publicByDefault: true, or addShareLinkToFile via storage.raw.");return r}internalOnComplete=c(e=>this.deleteMeta(e.id),"internalOnComplete")}export{ae as default};
@@ -1 +0,0 @@
1
- var T=Object.defineProperty;var g=(r,e)=>T(r,"name",{value:e,configurable:!0});import{Readable as b}from"node:stream";import{wrapStorageError as h}from"./ERRORS-CyOuSMLY.js";import{B as E}from"./storage-B-NDsI-o.js";import l from"./BunS3File-D-SRiyrm.js";import O from"./BunS3MetaStorage-Bv_CTTMz.js";import{o as f,r as I}from"./part-match-B5fLLmFw.js";import{u as v}from"./update-size-DANV7aa2.js";import{o as C}from"./has-content-Bx2p8Okx.js";var k=Object.defineProperty,p=g((r,e)=>k(r,"name",{value:e,configurable:!0}),"c");const c=p(r=>r.replace(/^\/+/u,""),"toKey"),z=p(async r=>{const e=[];for await(const i of r)e.push(Buffer.from(i));return Buffer.concat(e)},"collectStream"),B=p(r=>{const e=r?.code;return typeof e=="string"&&/nosuchkey|notfound/iu.test(e)},"isNotFoundError"),u=p((r,e)=>{const i=r?.code,t=typeof i=="string"?i:"";return/nosuchkey|notfound/iu.test(t)?h(r,{adapter:"Bun S3",operation:e,status:404}):/accessdenied|forbidden|ERR_S3_INVALID_SIGNATURE|ERR_S3_MISSING_CREDENTIALS/iu.test(t)?h(r,{adapter:"Bun S3",operation:e,status:403}):h(r,{adapter:"Bun S3",operation:e})},"wrapBunS3Error"),M=p(r=>{if(r.client)return r.client;const e=globalThis.Bun;if(!e?.S3Client)throw new Error("BunS3Storage requires the Bun runtime (Bun.S3Client). Run this under Bun, or pass a pre-built `client` instance. For Node/edge runtimes use the `aws` or `aws-light` provider instead.");return new e.S3Client({accessKeyId:r.accessKeyId,acl:r.acl,bucket:r.bucket,endpoint:r.endpoint,region:r.region,secretAccessKey:r.secretAccessKey,sessionToken:r.sessionToken,virtualHostedStyle:r.virtualHostedStyle})},"resolveClient");class L extends E{static name="bun-s3";meta;client;constructor(e){super(e),this.client=M(e),this.meta=e.metaStorage??new O(e.metaStorageConfig),this.isReady=!0}get raw(){return this.client}async create(e,i){return this.instrumentOperation("create",async()=>{const t=new l(e);t.name=this.namingFunction(t),t.bunS3Key=c(t.name),await this.validate(t);try{const n=await this.getMeta(t.id);if(n.bytesWritten>=0)return n}catch{}return t.bytesWritten=0,t.status=f(t),await this.saveMeta(t),await this.onCreate(t),t})}async write(e,i){return this.instrumentOperation("write",async()=>{let t;if("contentType"in e&&"metadata"in e&&!("body"in e)&&!("start"in e)?t=e:(t=await this.getMeta(e.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(e.size!==void 0&&v(t,e.size),!I(e,t))throw new Error("File part does not match");const n=await this.lock(e.id);try{if(C(e)){if(this.isUnsupportedChecksum(e.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const s=await z(e.body),a=c(t.name||t.id);try{await this.runOperation(i,()=>this.client.write(a,s,{type:t.contentType}))}catch(o){throw u(o,"upload")}t.bytesWritten=s.length,t.size=s.length,t.bunS3Key=a}return t.status=f(t),t.status==="completed"&&await this.internalOnComplete(t),await this.saveMeta(t),t}finally{await this.unlock(e.id,n)}})}async delete({id:e},i){return this.instrumentOperation("delete",async()=>{let t;try{t=await this.getMeta(e)}catch{}const n=t?.bunS3Key??c(t?.name??e);try{await this.runOperation(i,()=>this.client.delete(n))}catch(a){if(!B(a))throw u(a,"delete")}if(t)return t.status="deleted",await this.deleteMeta(t.id),await this.onDelete(t),t;const s=new l({contentType:"application/octet-stream",metadata:{},originalName:e});return s.id=e,s.name=e,s.bunS3Key=n,s.status="deleted",s})}async get({id:e},i){return this.instrumentOperation("get",async()=>{let t,n;try{t=await this.checkIfExpired(await this.getMeta(e)),n=t.bunS3Key??c(t.name??e)}catch{n=c(e)}const s=this.client.file(n);let a,o;try{t||(o=await this.runOperation(i,()=>s.stat())),a=Buffer.from(await this.runOperation(i,()=>s.arrayBuffer()))}catch(d){throw u(d,"get")}return{content:a,contentType:t?.contentType??o?.type??"application/octet-stream",ETag:t?.ETag??o?.etag??void 0,expiredAt:t?.expiredAt,id:e,metadata:t?.metadata??{},modifiedAt:t?.modifiedAt??o?.lastModified?.toISOString(),name:t?.name??n,originalName:t?.originalName??n,size:t?.size??o?.size??a.length}})}async getStream({id:e},i){return this.instrumentOperation("getStream",async()=>{let t,n;try{t=await this.checkIfExpired(await this.getMeta(e)),n=t.bunS3Key??c(t.name??e)}catch{n=c(e)}const s=this.client.file(n);let a,o;try{a=await this.runOperation(i,()=>s.stat()),o=s.stream()}catch(S){throw u(S,"getStream")}const d=t?.size??a.size,w=t?.contentType??a.type??"application/octet-stream",m=t?.ETag??a.etag,y=t?.modifiedAt??a.lastModified?.toISOString();return{headers:{"Content-Length":String(d??0),"Content-Type":w,...m&&{ETag:m},...y&&{"Last-Modified":String(y)}},size:typeof d=="number"?d:void 0,stream:b.fromWeb(o)}})}async copy(e,i,t){return this.instrumentOperation("copy",async()=>{const n=await this.get({id:e},t),s=c(i);try{await this.runOperation(t,()=>this.client.write(s,n.content,{type:n.contentType}))}catch(o){throw u(o,"copy")}const a=new l({contentType:n.contentType,metadata:{},originalName:i});return a.id=i,a.name=i,a.bunS3Key=s,a.size=typeof n.size=="string"?Number(n.size):n.size??n.content.length,a.ETag=n.ETag,a.bunS3ETag=n.ETag,a})}async move(e,i,t){return this.instrumentOperation("move",async()=>{const n=await this.copy(e,i,t);return await this.delete({id:e},t),n})}async list(e=1e3,i){return this.instrumentOperation("list",async()=>{let t;try{t=await this.runOperation(i,()=>this.client.list({maxKeys:e}))}catch(n){throw u(n,"list")}return(t.contents??[]).filter(n=>!!n.key).slice(0,e).map(n=>{const s=c(n.key),a=new l({contentType:"application/octet-stream",metadata:{},originalName:s});return a.id=s,a.name=s,a.bunS3Key=s,a.size=n.size,a.ETag=n.eTag??void 0,a.bunS3ETag=n.eTag??void 0,a.modifiedAt=n.lastModified?new Date(n.lastModified).toISOString():void 0,a})},{limit:e})}async getReadUrl(e,i){return this.client.file(c(e)).presign({...i?.responseContentDisposition&&{contentDisposition:i.responseContentDisposition},...i?.expiresIn!==void 0&&{expiresIn:i.expiresIn},method:"GET",...i?.responseContentType&&{type:i.responseContentType}})}async getUploadUrl(e,i){return this.client.presign(c(e),{...i?.expiresIn!==void 0&&{expiresIn:i.expiresIn},method:"PUT",...i?.contentType&&{type:i.contentType}})}internalOnComplete=p(e=>this.deleteMeta(e.id),"internalOnComplete")}export{L as default};
@@ -1 +0,0 @@
1
- var N=Object.defineProperty;var f=(n,t)=>N(n,"name",{value:t,configurable:!0});import*as u from"@bunny.net/storage-sdk";import{throwErrorCode as y,ERRORS as g,wrapStorageError as m}from"./ERRORS-CyOuSMLY.js";import{B}from"./storage-B-NDsI-o.js";import d from"./BunnyFile-Dotl-lO9.js";import b from"./BunnyMetaStorage-DNMTSeoN.js";import{o as E,r as A}from"./part-match-B5fLLmFw.js";import{u as _}from"./update-size-DANV7aa2.js";import{o as R}from"./has-content-Bx2p8Okx.js";var U=Object.defineProperty,c=f((n,t)=>U(n,"name",{value:t,configurable:!0}),"u");const O=new Set(Object.values(u.regions.StorageRegion)),h=c(n=>`/${n.replace(/^\/+/u,"")}`,"toBunnyPath"),w=c(n=>n.replace(/^\/+/u,""),"fromBunnyPath"),C=c((n,t)=>{const r=n.replace(/\/+$/u,""),e=t.replace(/^\/+/u,"");return`${r}/${e}`},"joinPublicUrl"),v=c(async n=>{const t=[];for await(const r of n)t.push(Buffer.from(r));return Buffer.concat(t)},"collectStream"),S=c(n=>new ReadableStream({start(t){t.enqueue(new Uint8Array(n)),t.close()}}),"streamFromBuffer"),z=c(n=>{if(n){if(!O.has(n))throw new Error(`Bunny Storage: unsupported region "${n}". Pass one of ${[...O].join(", ")}.`);return n}},"parseRegion"),P=c(n=>{if(n.client)return n.client;const t=n.zone??process.env.BUNNY_STORAGE_ZONE??process.env.STORAGE_ZONE,r=n.accessKey??process.env.BUNNY_STORAGE_ACCESS_KEY??process.env.BUNNY_ACCESS_KEY??process.env.STORAGE_ACCESS_KEY,e=z(n.region??process.env.BUNNY_STORAGE_REGION??process.env.STORAGE_REGION);if(!t||!r||!e)throw new Error("Bunny Storage: missing credentials. Pass `zone` + `accessKey` + `region`, or set BUNNY_STORAGE_ZONE / BUNNY_STORAGE_ACCESS_KEY / BUNNY_STORAGE_REGION (SDK aliases: STORAGE_ZONE / STORAGE_ACCESS_KEY / STORAGE_REGION).");return u.zone.connect_with_accesskey(e,t,r)},"resolveClient"),k=c(async n=>Buffer.from(await new Response(n).arrayBuffer()),"collectFromWebStream"),p=c((n,t)=>{const r=n?.message,e=typeof r=="string"?r:"";return/^file not found/iu.test(e)?m(n,{adapter:"Bunny Storage",operation:t,status:404}):/^unauthorized access/iu.test(e)?m(n,{adapter:"Bunny Storage",operation:t,status:401}):/^unable to upload file/iu.test(e)?m(n,{adapter:"Bunny Storage",operation:t,status:400}):m(n,{adapter:"Bunny Storage",operation:t})},"wrapBunnyError");class x extends B{static name="bunny";checksumTypes=["SHA256"];meta;client;publicBaseUrl;zoneName;constructor(t){super(t),this.client=P(t),this.zoneName=u.zone.name(this.client),this.publicBaseUrl=t.publicBaseUrl,this.meta=t.metaStorage??new b(t.metaStorageConfig),this.isReady=!0}get raw(){return this.client}get zone(){return this.zoneName}async create(t,r){return this.instrumentOperation("create",async()=>{const e=new d(t);e.name=this.namingFunction(e),e.bunnyPath=h(e.name),await this.validate(e);try{const a=await this.getMeta(e.id);if(a.bytesWritten>=0)return a}catch{}return e.bytesWritten=0,e.status=E(e),await this.saveMeta(e),await this.onCreate(e),e})}async write(t,r){return this.instrumentOperation("write",async()=>{let e;if("contentType"in t&&"metadata"in t&&!("body"in t)&&!("start"in t)?e=t:(e=await this.getMeta(t.id),await this.checkIfExpired(e)),e.status==="completed")return e;if(t.size!==void 0&&_(e,t.size),!A(t,e))throw new Error("File part does not match");const a=await this.lock(t.id);try{if(R(t)){if(this.isUnsupportedChecksum(t.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const i=await v(t.body),o=h(e.name||e.id);try{await this.runOperation(r,()=>u.file.upload(this.client,o,S(i),{contentType:e.contentType,...t.checksum&&t.checksumAlgorithm==="sha256"&&{sha256Checksum:t.checksum}}))}catch(s){throw p(s,"upload")}e.bytesWritten=i.length,e.size=i.length,e.bunnyPath=o}return e.status=E(e),e.status==="completed"&&await this.internalOnComplete(e),await this.saveMeta(e),e}finally{await this.unlock(t.id,a)}})}async delete({id:t},r){return this.instrumentOperation("delete",async()=>{let e;try{e=await this.getMeta(t)}catch{}const a=e?.bunnyPath??h(e?.name??t);try{await this.runOperation(r,()=>u.file.remove(this.client,a))}catch(o){throw p(o,"delete")}if(e)return e.status="deleted",await this.deleteMeta(e.id),await this.onDelete(e),e;const i=new d({contentType:"application/octet-stream",metadata:{},originalName:t});return i.id=t,i.name=t,i.bunnyPath=a,i.status="deleted",i})}async get({id:t},r){return this.instrumentOperation("get",async()=>{let e,a;try{e=await this.checkIfExpired(await this.getMeta(t)),a=e.bunnyPath??h(e.name??t)}catch{a=h(t)}let i;try{i=await this.runOperation(r,()=>u.file.get(this.client,a))}catch(s){throw p(s,"get")}let o;try{const s=await this.runOperation(r,()=>i.data());o=await k(s.stream)}catch(s){throw p(s,"download")}return{content:o,contentType:e?.contentType??i.contentType??"application/octet-stream",ETag:e?.ETag??i.checksum??void 0,expiredAt:e?.expiredAt,id:t,metadata:e?.metadata??{},modifiedAt:e?.modifiedAt??i.lastChanged?.toISOString(),name:e?.name??w(a),originalName:e?.originalName??w(a),size:e?.size??i.length??o.length}})}async copy(t,r,e){return this.instrumentOperation("copy",async()=>{const a=await this.get({id:t},e),i=h(r),o=a.content,s=typeof a.size=="string"?Number(a.size):a.size??o.length;try{await this.runOperation(e,()=>u.file.upload(this.client,i,S(o),{contentType:a.contentType}))}catch(T){throw p(T,"copy")}const l=new d({contentType:a.contentType,metadata:{},originalName:r});return l.id=r,l.name=r,l.bunnyPath=i,l.size=s,l.ETag=a.ETag,l.bunnyChecksum=a.ETag,l})}async move(t,r,e){return this.instrumentOperation("move",async()=>{const a=await this.copy(t,r,e);return await this.delete({id:t},e),a})}async list(t=1e3,r){return this.instrumentOperation("list",async()=>{let e;try{e=await this.runOperation(r,()=>u.file.list(this.client,"/"))}catch(a){throw p(a,"list")}return e.filter(a=>!a.isDirectory).slice(0,t).map(a=>{const i=a.path.endsWith(a.objectName)||!a.objectName?a.path:`${a.path.replace(/\/+$/u,"")}/${a.objectName}`,o=w(i),s=new d({contentType:a.contentType||"application/octet-stream",metadata:{},originalName:o});return s.id=o,s.name=o,s.bunnyPath=h(o),s.bunnyChecksum=a.checksum??void 0,s.ETag=a.checksum??void 0,s.size=a.length,s.modifiedAt=a.lastChanged?.toISOString(),s})},{limit:t})}async getReadUrl(t,r){return r?.responseContentDisposition?y(g.METHOD_NOT_ALLOWED,"Bunny Storage: `responseContentDisposition` is not supported — no override exists on Bunny Storage / Pull Zone URLs."):this.publicBaseUrl?C(this.publicBaseUrl,t):y(g.METHOD_NOT_ALLOWED,"Bunny Storage: `getReadUrl` requires `publicBaseUrl` (for example a Bunny Pull Zone or custom CDN hostname). The Storage API URL itself requires an AccessKey header and cannot be handed out as a public URL.")}async getUploadUrl(t,r){return y(g.METHOD_NOT_ALLOWED,"Bunny Storage: presigned PUT URLs are not supported — writes go through the Storage API with an AccessKey header. Upload server-side via the SDK or proxy through your application.")}internalOnComplete=c(t=>this.deleteMeta(t.id),"internalOnComplete")}export{x as default};
@@ -1 +0,0 @@
1
- var h=Object.defineProperty;var u=(n,e)=>h(n,"name",{value:e,configurable:!0});import{v2 as l}from"cloudinary";import{throwErrorCode as d,ERRORS as m}from"./ERRORS-CyOuSMLY.js";import{B as f}from"./storage-B-NDsI-o.js";import c from"./CloudinaryFile-B5-m33eS.js";import w from"./CloudinaryMetaStorage-DEBk5eQy.js";import{o as y,r as v}from"./part-match-B5fLLmFw.js";import{u as _}from"./update-size-DANV7aa2.js";import{o as g}from"./has-content-Bx2p8Okx.js";var T=Object.defineProperty,p=u((n,e)=>T(n,"name",{value:e,configurable:!0}),"c");const O=p(async n=>{const e=[];for await(const a of n)e.push(Buffer.from(a));return Buffer.concat(e)},"collectStream"),E=p(n=>{if(!n)return{};const e=n.match(/^cloudinary:\/\/([^:]+):([^@]+)@(.+)$/);return e?{apiKey:e[1],apiSecret:e[2],cloudName:e[3]}:{}},"parseCloudinaryUrl");class R extends f{static name="cloudinary";checksumTypes=[];meta;client;defaultUrlExpiresIn;deliveryType;resourceType;secure;constructor(e){if(super(e),this.resourceType=e.resourceType??"raw",this.deliveryType=e.type??"upload",this.secure=e.secure??!0,this.defaultUrlExpiresIn=e.defaultUrlExpiresIn??3600,e.client)this.client=e.client;else{const a=E(process.env.CLOUDINARY_URL),t=e.cloudName??process.env.CLOUDINARY_CLOUD_NAME??a.cloudName,r=e.apiKey??process.env.CLOUDINARY_API_KEY??a.apiKey,i=e.apiSecret??process.env.CLOUDINARY_API_SECRET??a.apiSecret;if(!t)throw new Error("Cloudinary storage: `cloudName` is required (or set CLOUDINARY_CLOUD_NAME / CLOUDINARY_URL).");l.config({api_key:r,api_secret:i,cloud_name:t,secure:this.secure}),this.client=l}this.meta=e.metaStorage??new w(e.metaStorageConfig),this.isReady=!0}get raw(){return this.client}async create(e,a){return this.instrumentOperation("create",async()=>{const t=new c(e);t.name=this.namingFunction(t),t.path=t.name,await this.validate(t);try{const r=await this.getMeta(t.id);if(r.bytesWritten>=0)return r}catch{}return t.bytesWritten=0,t.status=y(t),await this.saveMeta(t),await this.onCreate(t),t})}async write(e,a){return this.instrumentOperation("write",async()=>{let t;if("contentType"in e&&"metadata"in e&&!("body"in e)&&!("start"in e)?t=e:(t=await this.getMeta(e.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(e.size!==void 0&&_(t,e.size),!v(e,t))throw new Error("File part does not match");const r=await this.lock(e.id);try{if(g(e)){if(this.isUnsupportedChecksum(e.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const i=await O(e.body),s=t.path??t.name,o=await this.runOperation(a,()=>this.uploadBuffer(s,i));t.bytesWritten=i.length,t.size=i.length,t.path=o.public_id??s,t.publicUrl=o.secure_url??o.url,t.ETag=o.version===void 0?void 0:String(o.version)}return t.status=y(t),t.status==="completed"&&await this.internalOnComplete(t),await this.saveMeta(t),t}finally{await this.unlock(e.id,r)}})}async delete({id:e},a){return this.instrumentOperation("delete",async()=>{let t;try{t=await this.getMeta(e)}catch{}const r=t?.path??t?.name??e;return await this.runOperation(a,()=>this.client.uploader.destroy(r,{invalidate:!0,resource_type:this.resourceType,type:this.deliveryType})),t?(t.status="deleted",await this.deleteMeta(t.id),await this.onDelete(t),t):Object.assign(new c({contentType:"application/octet-stream",metadata:{},originalName:e}),{id:e,name:e,path:r,status:"deleted"})})}async exists({id:e},a){return this.instrumentOperation("exists",async()=>{let t=e;try{t=(await this.getMeta(e)).path??e}catch{}try{return await this.runOperation(a,()=>this.client.api.resource(t,{resource_type:this.resourceType,type:this.deliveryType})),!0}catch{return!1}})}async get({id:e},a){return this.instrumentOperation("get",async()=>{let t=e,r;try{r=await this.checkIfExpired(await this.getMeta(e)),t=r.path??r.name??e}catch{}const i=await this.runOperation(a,()=>this.client.api.resource(t,{resource_type:this.resourceType,type:this.deliveryType})),s=await this.runOperation(a,()=>fetch(this.client.url(t,{resource_type:this.resourceType,secure:this.secure,type:this.deliveryType})));if(!s.ok)throw new Error(`Cloudinary: object not found at "${t}"`);const o=Buffer.from(await s.arrayBuffer());return{content:o,contentType:r?.contentType??(i.resource_type&&i.format?`${i.resource_type}/${i.format}`:void 0)??"application/octet-stream",ETag:r?.ETag??(i.version===void 0?void 0:String(i.version)),expiredAt:r?.expiredAt,id:e,metadata:r?.metadata??{},modifiedAt:r?.modifiedAt,name:r?.name??t,originalName:r?.originalName??t,size:r?.size??(typeof i.bytes=="number"?i.bytes:o.length)}})}async copy(e,a,t){return this.instrumentOperation("copy",async()=>{const r=(await this.getMetaSafe(e))?.path??e,i=this.client.url(r,{resource_type:this.resourceType,secure:this.secure,type:this.deliveryType});await this.runOperation(t,()=>this.client.uploader.upload(i,{overwrite:!0,public_id:a,resource_type:this.resourceType,type:this.deliveryType}));const s=new c({contentType:"application/octet-stream",metadata:{},originalName:a});return s.id=a,s.name=a,s.path=a,s})}async move(e,a,t){return this.instrumentOperation("move",async()=>{const r=(await this.getMetaSafe(e))?.path??e;await this.runOperation(t,()=>this.client.uploader.rename(r,a,{resource_type:this.resourceType}));const i=new c({contentType:"application/octet-stream",metadata:{},originalName:a});i.id=a,i.name=a,i.path=a;try{await this.deleteMeta(e)}catch{}return i})}async list(e=1e3,a){return this.instrumentOperation("list",async()=>{const{resources:t}=await this.runOperation(a,()=>this.client.api.resources({max_results:e,resource_type:this.resourceType,type:this.deliveryType}));return(t??[]).map(r=>{const i=new c({contentType:r.resource_type&&r.format?`${r.resource_type}/${r.format}`:"application/octet-stream",metadata:{},originalName:r.public_id});return i.id=r.public_id,i.name=r.public_id,i.path=r.public_id,i.size=typeof r.bytes=="number"?r.bytes:void 0,i.createdAt=r.created_at??void 0,i.ETag=r.version===void 0?void 0:String(r.version),i})},{limit:e})}async getReadUrl(e,a){if(this.deliveryType==="upload")return this.client.url(e,{resource_type:this.resourceType,secure:this.secure,type:this.deliveryType});const t=a?.expiresIn??this.defaultUrlExpiresIn,r=e.lastIndexOf("."),i=r>0?e.slice(r+1):"";try{return this.client.utils.private_download_url(e,i,{expires_at:Math.floor(Date.now()/1e3)+t,resource_type:this.resourceType,type:this.deliveryType})}catch(s){return d(m.METHOD_NOT_ALLOWED,s instanceof Error?s.message:"Cloudinary: private_download_url failed")}}uploadBuffer(e,a){return new Promise((t,r)=>{this.client.uploader.upload_stream({overwrite:!0,public_id:e,resource_type:this.resourceType,type:this.deliveryType},(i,s)=>{if(i||!s){r(i instanceof Error?i:new Error(i?.message??"Cloudinary: upload failed"));return}t(s)}).end(a)})}async getMetaSafe(e){try{return await this.getMeta(e)}catch{return}}internalOnComplete=p(e=>this.deleteMeta(e.id),"internalOnComplete")}export{R as default};
@@ -1 +0,0 @@
1
- import"node:fs";import"node:fs/promises";import"node:stream";import"./local-meta-storage-Bi0mK6gD.js";import{f as c}from"./disk-storage-Bmvawf-b.js";import"./path-D7rMc9nq-B718mbm6.js";import"./index-B4ETk0Lu.js";import"./detect-file-type-5JhzC9RU.js";import"./ERRORS-CyOuSMLY.js";import"./storage-B-NDsI-o.js";import"./File-BhfUgJjs.js";import"./part-match-B5fLLmFw.js";import"./update-size-DANV7aa2.js";import"./has-content-Bx2p8Okx.js";export{c as default};
@@ -1 +0,0 @@
1
- var f=Object.defineProperty;var o=(i,t)=>f(i,"name",{value:t,configurable:!0});import{createReadStream as g,createWriteStream as b}from"node:fs";import{truncate as w}from"node:fs/promises";import{Transform as E,pipeline as F}from"node:stream";import{f as C,y as v,m as W,s as R}from"./disk-storage-Bmvawf-b.js";import{y as S}from"./local-meta-storage-Bi0mK6gD.js";import{d as T}from"./detect-file-type-5JhzC9RU.js";import{throwErrorCode as p,ERRORS as n}from"./ERRORS-CyOuSMLY.js";import{LRUCache as N}from"lru-cache";import{createHash as O}from"node:crypto";import{u as k}from"./update-size-DANV7aa2.js";import{r as P,o as x}from"./part-match-B5fLLmFw.js";import{o as M}from"./has-content-Bx2p8Okx.js";var _=Object.defineProperty,I=o((i,t)=>_(i,"name",{value:t,configurable:!0}),"a");class L extends E{static{o(this,"n")}constructor(t,e){super(),this.path=e,this.hashes=t,this.hash=this.hashes.get(e)||O(this.hashes.algorithm),this.hashCopy=this.hash.copy()}path;static{I(this,"RangeChecksum")}hash;hashCopy;hashes;reset(){this.hashes.set(this.path,this.hashCopy)}digest(t="hex"){return this.hash.copy().digest(t)}_transform(t,e,s){this.push(t),this.hash.update(t),s()}_flush(t){t()}}var z=Object.defineProperty,U=o((i,t)=>z(i,"name",{value:t,configurable:!0}),"h");class A extends N{static{o(this,"p")}constructor(t="sha1",e){super({ttl:1e3,ttlAutopurge:!0,...e}),this.algorithm=t}algorithm;static{U(this,"RangeHasher")}hex(t){return this.get(t)?.copy().digest("hex")||""}base64(t){return this.get(t)?.copy().digest("base64")||""}async init(t,e=0){return this.get(t)?.copy()||this.updateFromFs(t,e)}digester(t){return new L(this,t)}async updateFromFs(t,e=0,s){const r=await this.fromFs(t,e,s);return this.set(t,r),r}fromFs(t,e=0,s){return new Promise((r,a)=>{const h=this.digester(t);s!==void 0&&(h.hash=s),g(t,{start:e}).on("error",a).on("end",()=>{r(h.hash)}).pipe(h).resume()})}}var H=Object.defineProperty,l=o((i,t)=>H(i,"name",{value:t,configurable:!0}),"d");class tt extends C{static{o(this,"O")}static{l(this,"DiskStorageWithChecksum")}hashes;constructor(t){super(t),this.hashes=new A(t?.checksum==="sha1"?"sha1":"md5")}async delete({id:t}){try{const e=await this.getMeta(t),s=this.getFilePath(e.name);this.hashes.delete(s),await S(s),await this.deleteMeta(t);const r={...e,status:"deleted"};return await this.onDelete(r),r}catch(e){this.logger?.error("[error]: Could not delete file: %O",e);const s=this.normalizeError(e instanceof Error?e:new Error(String(e)));await this.onError(s)}return{id:t}}async write(t){let e;if("contentType"in t&&"metadata"in t&&!("body"in t)&&!("start"in t)?e=t:(e=await this.getMeta(t.id),await this.checkIfExpired(e)),e.status==="completed")return e;if(t.size!==void 0&&k(e,t.size),!P(t,e))return p(n.FILE_CONFLICT);const s=this.getFilePath(e.name);try{const r=t.start||0;if(await v(s),(e.bytesWritten===0||Number.isNaN(e.bytesWritten))&&(e.bytesWritten=r),await this.hashes.init(s),M(t)){if(this.isUnsupportedChecksum(t.checksumAlgorithm))return p(n.UNSUPPORTED_CHECKSUM_ALGORITHM);if((t.start===0||t.start===void 0)&&(e.bytesWritten===0||Number.isNaN(e.bytesWritten))&&(!e.contentType||e.contentType==="application/octet-stream"))try{const{fileType:m,stream:c}=await T(t.body);m?.mime&&(e.contentType=m.mime),t.body=c}catch{}const[a,h]=await this.lazyWrite({...t,...e});if(h)return await w(s,e.bytesWritten),p(h);typeof a!="number"&&await this.hashes.updateFromFs(s,e.bytesWritten),e.bytesWritten=a}return e.status=x(e),e.hash={algorithm:this.hashes.algorithm,value:this.hashes.hex(s)},e.status==="completed"&&this.hashes.delete(s),await this.saveMeta(e),e}catch(r){await this.hashes.updateFromFs(s,e.bytesWritten);const a=this.normalizeError(r instanceof Error?r:new Error(String(r)));return await this.onError(a),p(n.FILE_ERROR,(typeof a.message=="string"?a.message:String(r))||String(r))}}lazyWrite(t){return new Promise((e,s)=>{const r=this.getFilePath(t.name),a=b(r,{flags:"r+",start:t.start}),h=new W(t.contentLength||Number(t.size)-t.start),m=R(t.checksum,t.checksumAlgorithm),c=this.hashes.digester(r),y=!t.checksum,d=l(u=>{c.reset(),a.close(),e([Number.NaN,u])},"failWithCode");h.on("error",()=>{d(n.FILE_CONFLICT)}),m.on("error",()=>{d(n.CHECKSUM_MISMATCH)}),t.body.on("aborted",()=>{d(y?void 0:n.REQUEST_ABORTED)}),F(t.body,h,m,c,a,u=>{if(u){c.reset(),s(u);return}e([t.start+a.bytesWritten])})})}}export{tt as default};
@@ -1 +0,0 @@
1
- var E=Object.defineProperty;var O=(a,e)=>E(a,"name",{value:e,configurable:!0});import{DropboxResponseError as v,DropboxAuth as d,Dropbox as f}from"dropbox";import{throwErrorCode as y,ERRORS as w}from"./ERRORS-CyOuSMLY.js";import{c as D}from"./oauth-refresh-Dg2ybc6_.js";import{B as S}from"./storage-B-NDsI-o.js";import p from"./DropboxFile-BGVG2kXM.js";import x from"./DropboxMetaStorage-C6vj1QDA.js";import{o as b,r as B}from"./part-match-B5fLLmFw.js";import{u as R}from"./update-size-DANV7aa2.js";import{o as H}from"./has-content-Bx2p8Okx.js";var U=Object.defineProperty,c=O((a,e)=>U(a,"name",{value:e,configurable:!0}),"c");const T=14400,C=150*1024*1024,u=8*1024*1024,g=c((a,e)=>{a.auth.setAccessToken(e)},"setAccessToken"),L=c(a=>a.auth.getAccessToken(),"getAccessToken"),k=c(a=>{let e=0,s=a.length;for(;e<s&&a[e]==="/";)e+=1;for(;s>e&&a[s-1]==="/";)s-=1;return e===0&&s===a.length?a:a.slice(e,s)},"trimSlashes"),F=c(async a=>{const e=[];for await(const s of a)e.push(Buffer.from(s));return Buffer.concat(e)},"collectStream"),A=c(a=>a.includes("?dl=0")?a.replace("?dl=0","?dl=1"):a.includes("?dl=")?a:a+(a.includes("?")?"&dl=1":"?dl=1"),"rewriteSharedLinkForDirectDownload"),P=c((a,e)=>(g(a,e),{ensureAccessToken:c(()=>Promise.resolve(),"ensureAccessToken"),getAccessToken:c(()=>Promise.resolve(e),"getAccessToken")}),"createStaticAccessTokenAuth"),K=c((a,e)=>{const s=c(async()=>{const t=await e();return g(a,t),t},"ensure");return{async ensureAccessToken(){await s()},getAccessToken:s}},"createCallableAccessTokenAuth"),_=c((a,e)=>{const s=D({buildBody:c(()=>new URLSearchParams({client_id:e.appKey,grant_type:"refresh_token",refresh_token:e.refreshToken,...e.appSecret&&{client_secret:e.appSecret}}),"buildBody"),onRefresh:c(t=>{g(a,t)},"onRefresh"),provider:"Dropbox",tokenUrl:"https://api.dropboxapi.com/oauth2/token"});return{async ensureAccessToken(){await s.getAccessToken()},getAccessToken:c(()=>s.getAccessToken(),"getAccessToken")}},"createRefreshTokenAuth"),M=c(a=>{if(a.client){const i=a.client;return{authHandle:{ensureAccessToken:c(()=>Promise.resolve(),"ensureAccessToken"),getAccessToken:c(()=>Promise.resolve(L(i)),"getAccessToken")},client:i}}const e=a.accessToken,s=a.refreshToken!==void 0||a.appKey!==void 0||a.appSecret!==void 0;if(e!==void 0&&s)throw new Error("Dropbox storage: pass exactly one of `accessToken` or `refreshToken` (with `appKey`).");if(e!==void 0){const i=new d({accessToken:typeof e=="string"?e:void 0}),n=new f({auth:i});return{authHandle:typeof e=="function"?K(n,e):P(n,e),client:n}}if(s){if(!a.refreshToken||!a.appKey)throw new Error("Dropbox storage: refresh-token auth requires both `refreshToken` and `appKey`.");const i=new d({}),n=new f({auth:i});return{authHandle:_(n,{appKey:a.appKey,...a.appSecret&&{appSecret:a.appSecret},refreshToken:a.refreshToken}),client:n}}const t=process.env.DROPBOX_ACCESS_TOKEN;if(t){const i=new d({accessToken:t}),n=new f({auth:i});return{authHandle:P(n,t),client:n}}const o=process.env.DROPBOX_REFRESH_TOKEN,r=process.env.DROPBOX_APP_KEY;if(o&&r){const i=process.env.DROPBOX_APP_SECRET,n=new d({}),l=new f({auth:n});return{authHandle:_(l,{appKey:r,...i&&{appSecret:i},refreshToken:o}),client:l}}throw new Error("Dropbox storage: missing auth. Pass `client`, `accessToken`, or `refreshToken` + `appKey`. Env fallbacks: DROPBOX_ACCESS_TOKEN, or DROPBOX_REFRESH_TOKEN + DROPBOX_APP_KEY (+ DROPBOX_APP_SECRET).")},"resolveAuth");class J extends S{static name="dropbox";checksumTypes=[];meta;authHandle;client;defaultUrlExpiresIn;publicByDefault;rootFolderPath;constructor(e){super(e),this.rootFolderPath=k(e.rootFolderPath??""),this.publicByDefault=e.publicByDefault??!1,this.defaultUrlExpiresIn=Math.min(e.defaultUrlExpiresIn??3600,T);const s=M(e);this.client=s.client,this.authHandle=s.authHandle,this.meta=e.metaStorage??new x(e.metaStorageConfig),this.isReady=!0}get raw(){return this.client}async create(e,s){return this.instrumentOperation("create",async()=>{const t=new p(e);t.name=this.namingFunction(t),t.path=this.keyToPath(t.name),await this.validate(t);try{const o=await this.getMeta(t.id);if(o.bytesWritten>=0)return o}catch{}return t.bytesWritten=0,t.status=b(t),await this.saveMeta(t),await this.onCreate(t),t})}async write(e,s){return this.instrumentOperation("write",async()=>{let t;if("contentType"in e&&"metadata"in e&&!("body"in e)&&!("start"in e)?t=e:(t=await this.getMeta(e.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(e.size!==void 0&&R(t,e.size),!B(e,t))throw new Error("File part does not match");const o=await this.lock(e.id);try{if(H(e)){if(this.isUnsupportedChecksum(e.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const r=await F(e.body),i=t.path??this.keyToPath(t.name||t.id);await this.authHandle.ensureAccessToken();const n=r.byteLength<=C?await this.uploadSimple(i,r,s):await this.uploadSession(i,r,s);t.bytesWritten=r.length,t.size=r.length,t.path=n.path_display??i,t.rev=n.rev,t.ETag=n.rev}return t.status=b(t),t.status==="completed"&&await this.internalOnComplete(t),await this.saveMeta(t),t}finally{await this.unlock(e.id,o)}})}async delete({id:e},s){return this.instrumentOperation("delete",async()=>{let t;try{t=await this.getMeta(e)}catch{}const o=t?.path??this.keyToPath(t?.name??e);await this.authHandle.ensureAccessToken();try{await this.runOperation(s,()=>this.client.filesDeleteV2({path:o}))}catch(r){if(!N(r))throw r}return t?(t.status="deleted",await this.deleteMeta(t.id),await this.onDelete(t),t):Object.assign(new p({contentType:"application/octet-stream",metadata:{},originalName:e}),{id:e,name:e,path:o,status:"deleted"})})}async get({id:e},s){return this.instrumentOperation("get",async()=>{let t,o=this.keyToPath(e);try{t=await this.checkIfExpired(await this.getMeta(e)),o=t.path??this.keyToPath(t.name??e)}catch{}await this.authHandle.ensureAccessToken();const r=(await this.runOperation(s,()=>this.client.filesDownload({path:o}))).result;let i;if(r.fileBinary instanceof Uint8Array)i=Buffer.from(r.fileBinary.buffer,r.fileBinary.byteOffset,r.fileBinary.byteLength);else if(r.fileBlob instanceof Blob)i=Buffer.from(await r.fileBlob.arrayBuffer());else throw new TypeError("Dropbox: unexpected download response shape — neither fileBinary nor fileBlob present");return{content:i,contentType:t?.contentType??"application/octet-stream",ETag:t?.ETag??r.rev,expiredAt:t?.expiredAt,id:e,metadata:t?.metadata??{},modifiedAt:t?.modifiedAt??r.server_modified,name:t?.name??r.name,originalName:t?.originalName??r.name,size:t?.size??r.size??i.length}})}async copy(e,s,t){return this.instrumentOperation("copy",async()=>{const o=this.keyToPath(e),r=this.keyToPath(s);await this.authHandle.ensureAccessToken(),await this.runOperation(t,()=>this.client.filesCopyV2({from_path:o,to_path:r}));const i=new p({contentType:"application/octet-stream",metadata:{},originalName:s});return i.id=s,i.name=s,i.path=r,i})}async move(e,s,t){return this.instrumentOperation("move",async()=>{const o=this.keyToPath(e),r=this.keyToPath(s);await this.authHandle.ensureAccessToken(),await this.runOperation(t,()=>this.client.filesMoveV2({from_path:o,to_path:r}));const i=new p({contentType:"application/octet-stream",metadata:{},originalName:s});i.id=s,i.name=s,i.path=r;try{await this.deleteMeta(e)}catch{}return i})}async list(e=1e3,s){return this.instrumentOperation("list",async()=>{await this.authHandle.ensureAccessToken();const t=await this.runOperation(s,()=>this.client.filesListFolder({limit:e,path:this.rootFolderPath?`/${this.rootFolderPath}`:"",recursive:!0})),{result:o}=t,r=[];for(const i of o.entries){if(i[".tag"]!=="file")continue;const n=i,l=n.path_display??n.path_lower??`/${n.name}`,m=this.pathToKey(l);if(!m)continue;const h=new p({contentType:"application/octet-stream",metadata:{},originalName:n.name});h.id=m,h.name=m,h.path=l,h.size=n.size,h.rev=n.rev,h.ETag=n.rev,h.modifiedAt=n.server_modified,r.push(h)}return r},{limit:e})}async getReadUrl(e,s){if(s?.responseContentDisposition)return y(w.METHOD_NOT_ALLOWED,"Dropbox: `responseContentDisposition` is not supported — Dropbox temporary links have no Content-Disposition override.");const t=s?.expiresIn??this.defaultUrlExpiresIn;return t>T?y(w.METHOD_NOT_ALLOWED,`Dropbox: \`expiresIn\` of ${t}s exceeds the ${T}s (4h) maximum. Use \`publicByDefault: true\` for a permanent shared link.`):(await this.authHandle.ensureAccessToken(),this.publicByDefault?await this.createPublicSharedLink(e):(await this.client.filesGetTemporaryLink({path:this.keyToPath(e)})).result.link)}async getUploadUrl(e,s){return y(w.METHOD_NOT_ALLOWED,"Dropbox: presigned upload URLs use POST with a raw body, which doesn't fit the PUT-style upload-url contract. Use `write()` or `storage.raw.filesGetTemporaryUploadLink(...)` directly.")}keyToPath(e){const s=k(e),t=[];return this.rootFolderPath&&t.push(this.rootFolderPath),s&&t.push(s),t.length===0?"":`/${t.join("/")}`}pathToKey(e){const s=k(e);if(!this.rootFolderPath)return s;if(s===this.rootFolderPath)return"";const t=`${this.rootFolderPath}/`;return s.startsWith(t)?s.slice(t.length):s}async uploadSimple(e,s,t){return(await this.runOperation(t,()=>this.client.filesUpload({contents:s,mode:{".tag":"overwrite"},mute:!0,path:e}))).result}async uploadSession(e,s,t){const o=s.byteLength;let r=0;const i=(await this.runOperation(t,()=>this.client.filesUploadSessionStart({close:!1,contents:s.subarray(r,Math.min(r+u,o))}))).result.session_id;for(r=Math.min(r+u,o);o-r>u;){const l=s.subarray(r,r+u);await this.runOperation(t,()=>this.client.filesUploadSessionAppendV2({close:!1,contents:l,cursor:{offset:r,session_id:i}})),r+=u}const n=s.subarray(r,o);return(await this.runOperation(t,()=>this.client.filesUploadSessionFinish({commit:{mode:{".tag":"overwrite"},mute:!0,path:e},contents:n,cursor:{offset:r,session_id:i}}))).result}async createPublicSharedLink(e){try{const s=await this.client.sharingCreateSharedLinkWithSettings({path:this.keyToPath(e),settings:{requested_visibility:{".tag":"public"}}});return A(s.result.url)}catch(s){if(s instanceof v){const t=s.error?.shared_link_already_exists?.metadata?.url;if(typeof t=="string"&&t.length>0)return A(t)}throw s}}internalOnComplete=c(e=>this.deleteMeta(e.id),"internalOnComplete")}const N=c(a=>{if(!(a instanceof v))return!1;if(a.status===404)return!0;const e=[],s=c((t,o)=>{if(o>6||t===null||typeof t!="object")return;const r=t,i=r[".tag"];typeof i=="string"&&e.push(i);for(const n of Object.values(r))n&&typeof n=="object"&&s(n,o+1)},"walk");return s(a.error,0),e.includes("not_found")||e.includes("not_file")||e.includes("not_folder")},"isNotFoundError");export{J as default};
@@ -1 +0,0 @@
1
- var S=Object.defineProperty;var z=(s,e)=>S(s,"name",{value:e,configurable:!0});import{Readable as O}from"node:stream";import{B as h}from"./storage-B-NDsI-o.js";var T=Object.defineProperty,g=z((s,e)=>T(s,"name",{value:e,configurable:!0}),"g");const b=8,K=g(s=>typeof s=="object"&&s!==null&&typeof s.getReader=="function","isWebReadableStream"),I=g(s=>typeof s=="object"&&s!==null&&typeof s.pipe=="function"&&typeof s.read=="function","isNodeReadable"),U=g(async(s,e)=>{if(typeof s=="string"){const t=Buffer.from(s);return{size:t.byteLength,stream:O.from(t)}}if(Buffer.isBuffer(s))return{size:s.byteLength,stream:O.from(s)};if(s instanceof Uint8Array){const t=Buffer.from(s.buffer,s.byteOffset,s.byteLength);return{size:t.byteLength,stream:O.from(t)}}if(s instanceof ArrayBuffer){const t=Buffer.from(s);return{size:t.byteLength,stream:O.from(t)}}if(ArrayBuffer.isView(s)){const t=s,r=Buffer.from(t.buffer,t.byteOffset,t.byteLength);return{size:r.byteLength,stream:O.from(r)}}if(typeof Blob<"u"&&s instanceof Blob)return{size:s.size,stream:O.fromWeb(s.stream())};if(K(s))return{size:e,stream:O.fromWeb(s)};if(I(s))return{size:e,stream:s};throw new TypeError(`Unsupported body type: ${Object.prototype.toString.call(s)}`)},"normalizeBody"),k=g((s,e)=>({contentType:s.contentType??"application/octet-stream",etag:s.ETag,key:s.name||s.id||e||"",lastModified:s.modifiedAt??s.createdAt,metadata:s.metadata,size:typeof s.size=="number"?s.size:void 0}),"toFileObject"),L=g(s=>s?s.split("/").filter(e=>e.length>0).join("/"):"","normalizePrefix"),P=g((s,e)=>{if(!e&&!s.signal&&s.timeout===void 0&&s.retries===void 0)return;const t={...s};return e&&(e.signal!==void 0&&(t.signal=e.signal),e.timeout!==void 0&&(t.timeout=e.timeout),e.retries!==void 0&&(t.retries=e.retries)),s.signal&&e?.signal&&(t.signal=AbortSignal.any([s.signal,e.signal])),t},"mergeOperationOptions"),v=g(async(s,e,t)=>{const r=Array.from({length:s.length});let n=0,c=!1;const f=g(async()=>{for(;n<s.length;){if(c||t.signal?.aborted)return;const i=n;n+=1;try{const a=await e(s[i],i);r[i]={status:"fulfilled",value:a}}catch(a){r[i]={reason:a,status:"rejected"},t.stopOnError&&(c=!0)}}},"worker"),o=Math.max(1,Math.min(t.concurrency,s.length)),l=Array.from({length:o},()=>f());return await Promise.all(l),r},"runConcurrent"),u=g((s,e)=>e instanceof Error?{error:e,key:s}:{error:new Error(typeof e=="string"?e:"Unknown error",{cause:e}),key:s},"toBulkError");class C{static{z(this,"Files")}static{g(this,"Files")}adapter;defaults;prefix;constructor(e){this.adapter=e.adapter,this.defaults=e.defaults??{},this.prefix=L(e.prefix??"")}get raw(){return this.adapter.raw}resolveKey(e){return this.prefix?`${this.prefix}/${e}`:e}stripPrefix(e){const t=e.startsWith("/")?e.slice(1):e;if(!this.prefix)return t;const r=`${this.prefix}/`;return t.startsWith(r)?t.slice(r.length):null}mergeOptions(e){return P(this.defaults,e)}async upload(e,t,r){return Array.isArray(e)?this.uploadMany(e,t):this.uploadOne(e,t,r)}async uploadOne(e,t,r){const n=this.resolveKey(e);h.assertSafeId(n);const{size:c,stream:f}=await U(t,r?.size),o=r?.size??c,l={...r?.metadata??{},name:n,...r?.contentType?{type:r.contentType}:{},...o===void 0?{}:{size:o}},i=this.mergeOptions(r),a=await this.adapter.create({contentType:r?.contentType,id:n,metadata:l,originalName:n,size:o,storageClass:r?.storageClass},i),d={body:f,contentLength:o,id:a.id,start:0},p=await this.adapter.write(d,i),w=k(p,n),E=this.stripPrefix(w.key);return E!==null&&(w.key=E),w}async uploadMany(e,t){const{concurrency:r=b,stopOnError:n=!1,...c}=t??{},f=await v(e,async({body:i,key:a,...d})=>this.uploadOne(a,i,{...c,...d}),{concurrency:r,signal:c.signal,stopOnError:n}),o=[],l=[];for(const[i,a]of f.entries()){const d=e[i];if(!a){l.push(u(d.key,new Error("Operation skipped (stopOnError)")));continue}a.status==="fulfilled"?o.push(a.value):l.push(u(d.key,a.reason))}return l.length>0?{errors:l,uploaded:o}:{uploaded:o}}async download(e,t){return Array.isArray(e)?this.downloadMany(e,t):this.downloadOne(e,t)}async downloadOne(e,t){const r=this.resolveKey(e);h.assertSafeId(r);const n=await this.adapter.get({id:r},this.mergeOptions(t));return{body:n.content,contentType:n.contentType??"application/octet-stream",etag:n.ETag,key:e,lastModified:n.modifiedAt,metadata:n.metadata,size:typeof n.size=="number"?n.size:void 0}}async downloadMany(e,t){const{concurrency:r=b,stopOnError:n=!1,...c}=t??{},f=await v(e,async i=>this.downloadOne(i,c),{concurrency:r,signal:c.signal,stopOnError:n}),o=[],l=[];for(const[i,a]of f.entries()){const d=e[i];if(!a){l.push(u(d,new Error("Operation skipped (stopOnError)")));continue}a.status==="fulfilled"?o.push(a.value):l.push(u(d,a.reason))}return l.length>0?{downloaded:o,errors:l}:{downloaded:o}}async head(e,t){return Array.isArray(e)?this.headMany(e,t):this.headOne(e,t)}async headOne(e,t){const r=this.resolveKey(e);h.assertSafeId(r);const n=await this.adapter.getMeta(r,this.mergeOptions(t)),c=k(n,r);return c.key=e,c}async headMany(e,t){const{concurrency:r=b,stopOnError:n=!1,...c}=t??{},f=await v(e,async i=>this.headOne(i,c),{concurrency:r,signal:c.signal,stopOnError:n}),o=[],l=[];for(const[i,a]of f.entries()){const d=e[i];if(!a){l.push(u(d,new Error("Operation skipped (stopOnError)")));continue}a.status==="fulfilled"?o.push(a.value):l.push(u(d,a.reason))}return l.length>0?{errors:l,files:o}:{files:o}}async exists(e,t){return Array.isArray(e)?this.existsMany(e,t):this.existsOne(e,t)}async existsOne(e,t){const r=this.resolveKey(e);return h.assertSafeId(r),this.adapter.exists({id:r},this.mergeOptions(t))}async existsMany(e,t){const{concurrency:r=b,stopOnError:n=!1,...c}=t??{},f=await v(e,async a=>this.existsOne(a,c),{concurrency:r,signal:c.signal,stopOnError:n}),o=[],l=[],i=[];for(const[a,d]of f.entries()){const p=e[a];if(!d){i.push(u(p,new Error("Operation skipped (stopOnError)")));continue}d.status==="fulfilled"?d.value?o.push(p):l.push(p):i.push(u(p,d.reason))}return i.length>0?{errors:i,existing:o,missing:l}:{existing:o,missing:l}}async delete(e,t){if(Array.isArray(e))return this.deleteMany(e,t);await this.deleteOne(e,t)}async deleteOne(e,t){const r=this.resolveKey(e);h.assertSafeId(r),await this.adapter.delete({id:r},this.mergeOptions(t))}async deleteMany(e,t){const{concurrency:r=b,stopOnError:n=!1,...c}=t??{},f=this.mergeOptions(c);if(!n&&typeof this.adapter.deleteBatch=="function"){const a=[],d=[],p=[];for(const y of e){const m=this.resolveKey(y);try{h.assertSafeId(m),a.push(y),d.push(m)}catch(x){p.push(u(y,x))}}const w=d.length>0?await this.adapter.deleteBatch(d,f):{failed:[],successful:[]},E=new Map(d.map((y,m)=>[y,m])),A=w.successful.map(y=>this.stripPrefix(y.id)??y.id),B=[...p,...w.failed.map(({error:y,id:m})=>{const x=E.get(m),M=x===void 0?m:a[x];return u(M,new Error(y))})];return B.length>0?{deleted:A,errors:B}:{deleted:A}}const o=await v(e,async a=>this.deleteOne(a,c),{concurrency:r,signal:c.signal,stopOnError:n}),l=[],i=[];for(const[a,d]of o.entries()){const p=e[a];if(!d){i.push(u(p,new Error("Operation skipped (stopOnError)")));continue}d.status==="fulfilled"?l.push(p):i.push(u(p,d.reason))}return i.length>0?{deleted:l,errors:i}:{deleted:l}}async copy(e,t,r){const n=this.resolveKey(e),c=this.resolveKey(t);h.assertSafeId(n),h.assertSafeId(c);const f=await this.adapter.copy(n,c,{...this.mergeOptions(r),storageClass:r?.storageClass}),o=k(f,c);return o.key=t,o}async list(e={}){const{limit:t,prefix:r,...n}=e,c=await this.adapter.list(t??1e3,this.mergeOptions(n)),f=[];for(const o of c){const l=k(o),i=this.stripPrefix(l.key);i!==null&&(l.key=i,f.push(l))}return r?f.filter(o=>o.key.startsWith(r)):f}async url(e,t){const r=this.resolveKey(e);return h.assertSafeId(r),this.adapter.getReadUrl(r,{...this.mergeOptions(t),...t})}async signedUploadUrl(e,t){const r=this.resolveKey(e);return h.assertSafeId(r),this.adapter.getUploadUrl(r,{...this.mergeOptions(t),...t})}}export{C as Files,C as default};
@@ -1,2 +0,0 @@
1
- var g=Object.defineProperty;var h=(s,t)=>g(s,"name",{value:t,configurable:!0});import{readFileSync as w}from"node:fs";import{getApps as b,getApp as m,initializeApp as O,cert as k}from"firebase-admin/app";import{getStorage as A}from"firebase-admin/storage";import{throwErrorCode as d,ERRORS as f}from"./ERRORS-CyOuSMLY.js";import{B as T}from"./storage-B-NDsI-o.js";import o from"./FirebaseFile-JEu3plMP.js";import I from"./FirebaseMetaStorage-CzyOim-J.js";import{o as y,r as v}from"./part-match-B5fLLmFw.js";import{u as S}from"./update-size-DANV7aa2.js";import{o as _}from"./has-content-Bx2p8Okx.js";var N=Object.defineProperty,u=h((s,t)=>N(s,"name",{value:t,configurable:!0}),"l");const U=3600,R=u(async s=>{const t=[];for await(const i of s)t.push(Buffer.from(i));return Buffer.concat(t)},"collectStream"),B=u(s=>typeof s=="object"&&s!==null&&typeof s.file=="function"&&typeof s.getFiles=="function","isBucket");class E extends T{static name="firebase";checksumTypes=[];meta;bucket;bucketName;defaultUrlExpiresIn;publicBaseUrl;constructor(t){if(super(t),this.defaultUrlExpiresIn=t.defaultUrlExpiresIn??U,this.publicBaseUrl=t.publicBaseUrl?.replace(/\/+$/,""),t.app&&B(t.app))this.bucket=t.app,this.bucketName=t.app.name??"";else{const i=t.bucket??process.env.FIREBASE_STORAGE_BUCKET;if(!i)throw new Error("Firebase storage: `bucket` is required (or set FIREBASE_STORAGE_BUCKET).");this.bucketName=i;const e=t.app??E.resolveApp(t,i);this.bucket=A(e).bucket(i)}this.meta=t.metaStorage??new I(t.metaStorageConfig),this.isReady=!0}get raw(){return this.bucket}async create(t,i){return this.instrumentOperation("create",async()=>{const e=new o(t);e.name=this.namingFunction(e),e.bucket=this.bucketName,e.path=e.name,await this.validate(e);try{const a=await this.getMeta(e.id);if(a.bytesWritten>=0)return a}catch{}return e.bytesWritten=0,e.status=y(e),await this.saveMeta(e),await this.onCreate(e),e})}async write(t,i){return this.instrumentOperation("write",async()=>{let e;if("contentType"in t&&"metadata"in t&&!("body"in t)&&!("start"in t)?e=t:(e=await this.getMeta(t.id),await this.checkIfExpired(e)),e.status==="completed")return e;if(t.size!==void 0&&S(e,t.size),!v(t,e))throw new Error("File part does not match");const a=await this.lock(t.id);try{if(_(t)){if(this.isUnsupportedChecksum(t.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const r=await R(t.body),c=e.path??e.name;await this.runOperation(i,()=>this.bucket.file(c).save(r,{contentType:e.contentType,resumable:!1})),e.bytesWritten=r.length,e.size=r.length,e.path=c}return e.status=y(e),e.status==="completed"&&await this.internalOnComplete(e),await this.saveMeta(e),e}finally{await this.unlock(t.id,a)}})}async delete({id:t},i){return this.instrumentOperation("delete",async()=>{let e;try{e=await this.getMeta(t)}catch{}const a=e?.path??e?.name??t;return await this.runOperation(i,()=>this.bucket.file(a).delete({ignoreNotFound:!0})),e?(e.status="deleted",await this.deleteMeta(e.id),await this.onDelete(e),e):Object.assign(new o({contentType:"application/octet-stream",metadata:{},originalName:t}),{bucket:this.bucketName,id:t,name:t,path:a,status:"deleted"})})}async exists({id:t},i){return this.instrumentOperation("exists",async()=>{let e=t;try{e=(await this.getMeta(t)).path??t}catch{}try{const[a]=await this.runOperation(i,()=>this.bucket.file(e).exists());return a}catch{return!1}})}async get({id:t},i){return this.instrumentOperation("get",async()=>{let e=t,a;try{a=await this.checkIfExpired(await this.getMeta(t)),e=a.path??a.name??t}catch{}const r=this.bucket.file(e),[c]=await this.runOperation(i,()=>r.download());let n={};try{[n]=await this.runOperation(i,()=>r.getMetadata())}catch{}return{content:c,contentType:a?.contentType??n.contentType??"application/octet-stream",ETag:a?.ETag??n.etag,expiredAt:a?.expiredAt,id:t,metadata:a?.metadata??{},modifiedAt:a?.modifiedAt??n.updated,name:a?.name??e,originalName:a?.originalName??e,size:a?.size??(n.size===void 0?c.length:Number(n.size))}})}async copy(t,i,e){return this.instrumentOperation("copy",async()=>{const a=(await this.getMetaSafe(t))?.path??t;await this.runOperation(e,()=>this.bucket.file(a).copy(this.bucket.file(i)));const r=new o({contentType:"application/octet-stream",metadata:{},originalName:i});return r.id=i,r.name=i,r.path=i,r.bucket=this.bucketName,r})}async move(t,i,e){return this.instrumentOperation("move",async()=>{const a=(await this.getMetaSafe(t))?.path??t;await this.runOperation(e,()=>this.bucket.file(a).move(i));const r=new o({contentType:"application/octet-stream",metadata:{},originalName:i});r.id=i,r.name=i,r.path=i,r.bucket=this.bucketName;try{await this.deleteMeta(t)}catch{}return r})}async list(t=1e3,i){return this.instrumentOperation("list",async()=>{const[e]=await this.runOperation(i,()=>this.bucket.getFiles({maxResults:t}));return(e??[]).map(a=>{const r=new o({contentType:"application/octet-stream",metadata:{},originalName:a.name});return r.id=a.name,r.name=a.name,r.path=a.name,r.bucket=this.bucketName,r})},{limit:t})}async getReadUrl(t,i){if(this.publicBaseUrl)return`${this.publicBaseUrl}/${t}`;const e=i?.expiresIn??this.defaultUrlExpiresIn;try{const[a]=await this.bucket.file(t).getSignedUrl({action:"read",expires:Date.now()+e*1e3});return a}catch(a){return d(f.METHOD_NOT_ALLOWED,a instanceof Error?a.message:"Firebase: getSignedUrl failed")}}async getUploadUrl(t,i){const e=i?.expiresIn??this.defaultUrlExpiresIn;try{const[a]=await this.bucket.file(t).getSignedUrl({action:"write",contentType:i?.contentType,expires:Date.now()+e*1e3});return a}catch(a){return d(f.METHOD_NOT_ALLOWED,a instanceof Error?a.message:"Firebase: getSignedUrl failed")}}static resolveApp(t,i){const{appName:e}=t,a=b();if(e?a.find(p=>p.name===e):a[0])return e?m(e):m();const r=t.projectId??process.env.FIREBASE_PROJECT_ID??process.env.GOOGLE_CLOUD_PROJECT??process.env.GCLOUD_PROJECT;let c=t.credentials?.clientEmail??process.env.FIREBASE_CLIENT_EMAIL,n=t.credentials?.privateKey??process.env.FIREBASE_PRIVATE_KEY;const l=t.serviceAccountPath??process.env.GOOGLE_APPLICATION_CREDENTIALS;if((!c||!n)&&l){const p=JSON.parse(w(l,"utf8"));c??=p.client_email,n??=p.private_key}if(!c||!n)throw new Error("Firebase storage: service-account credentials are required. Provide `credentials` ({ clientEmail, privateKey }), `serviceAccountPath`, or set FIREBASE_CLIENT_EMAIL / FIREBASE_PRIVATE_KEY / GOOGLE_APPLICATION_CREDENTIALS.");return O({credential:k({clientEmail:c,privateKey:n.replaceAll(String.raw`\n`,`
2
- `),projectId:r}),projectId:r,storageBucket:i},e)}async getMetaSafe(t){try{return await this.getMeta(t)}catch{return}}internalOnComplete=u(t=>this.deleteMeta(t.id),"internalOnComplete")}export{E as default};
@@ -1 +0,0 @@
1
- var F=Object.defineProperty;var O=(o,a)=>F(o,"name",{value:a,configurable:!0});import{Readable as y,Writable as v}from"node:stream";import{Client as M}from"basic-ftp";import{S as k}from"./index-B4ETk0Lu.js";import{throwErrorCode as u,ERRORS as m}from"./ERRORS-CyOuSMLY.js";import{B as E}from"./storage-B-NDsI-o.js";import P from"./FtpFile-B8jaICTB.js";import A from"./FtpMetaStorage-1Njy0DpU.js";import{i as f,n as $,o as D}from"./posix-dirname-CiHXPPnw.js";import{o as b,r as R}from"./part-match-B5fLLmFw.js";import{u as L}from"./update-size-DANV7aa2.js";import{o as S}from"./has-content-Bx2p8Okx.js";var x=Object.defineProperty,l=O((o,a)=>x(o,"name",{value:a,configurable:!0}),"u");const d=l(o=>{const a=o?.code;if(a===550||a===450||a===553)return!0;const e=o instanceof Error?o.message:String(o);return/no such file|not exist|cannot find|file unavailable/i.test(e)},"isNotFoundError"),g=l(o=>{if(o instanceof Error&&o.name==="AbortError")return o;const a=new Error(o instanceof Error&&o.message?o.message:"The operation was aborted",{cause:o});return a.name="AbortError",a},"toAbortError"),T=l(async(o,a)=>{const e=[],t=new v({write(n,r,i){e.push(Buffer.from(n)),i()}});return await o.downloadTo(t,a),Buffer.concat(e)},"downloadToBuffer");class G extends E{static name="ftp";checksumTypes=[];meta;connection;rootFolderPath;constructor(a){super(a),this.connection=a.connection,this.rootFolderPath=f(a.rootFolderPath??""),this.meta=a.metaStorage??new A(a.metaStorageConfig),this.isReady=!0}async create(a,e){return this.instrumentOperation("create",async()=>{const t=new P(a);t.name=this.namingFunction(t),t.path=this.keyToPath(t.name),await this.validate(t);try{const n=await this.getMeta(t.id);if(n.status==="completed")return n}catch{}return t.bytesWritten=0,t.status=b(t),await this.saveMeta(t),await this.onCreate(t),t})}async write(a,e){return this.instrumentOperation("write",async()=>{let t;if("contentType"in a&&"metadata"in a&&!("body"in a)&&!("start"in a)?t=a:(t=await this.getMeta(a.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(a.size!==void 0&&L(t,a.size),!R(a,t))return u(m.FILE_CONFLICT);const n=await this.lock(a.id);try{if(S(a)){if(this.isUnsupportedChecksum(a.checksumAlgorithm))return u(m.UNSUPPORTED_CHECKSUM_ALGORITHM);if(a.start>0)return u(m.METHOD_NOT_ALLOWED,"FTP storage does not support chunked or resumable uploads; send the file in a single request.");const r=await $(a.body),i=t.path??this.keyToPath(t.name||t.id);await this.runOperation(e,c=>this.run(c,async s=>{await this.ensureRemoteDirectory(s,i),await s.uploadFrom(y.from(r),i)})),t.bytesWritten=r.length,t.size=r.length,t.path=i,t.ETag=k(r)}return t.status=b(t),await this.saveMeta(t),t}finally{await this.unlock(a.id,n)}})}async get({id:a},e){return this.instrumentOperation("get",async()=>{const t=await this.checkIfExpired(await this.getMeta(a)),n=t.path??this.keyToPath(t.name||a),r=await this.runOperation(e,i=>this.run(i,async c=>{try{return await T(c,n)}catch(s){if(d(s))return u(m.FILE_NOT_FOUND);throw s}}));return{content:r,contentType:t.contentType,ETag:t.ETag??k(r),expiredAt:t.expiredAt,id:a,metadata:t.metadata,modifiedAt:t.modifiedAt,name:t.name,originalName:t.originalName,size:t.size??r.length}})}async delete({id:a},e){return this.instrumentOperation("delete",async()=>{const t=await this.getMeta(a),n=t.path??this.keyToPath(t.name||a);await this.runOperation(e,i=>this.run(i,async c=>{try{await c.remove(n)}catch(s){if(!d(s))throw s}})),await this.deleteMeta(a);const r={...t,status:"deleted"};return await this.onDelete(r),r})}async copy(a,e,t){return this.instrumentOperation("copy",async()=>{const n=await this.getMeta(a),r=n.path??this.keyToPath(n.name||a),i=this.keyToPath(e);await this.runOperation(t,s=>this.run(s,async h=>{const p=await T(h,r);await this.ensureRemoteDirectory(h,i),await h.uploadFrom(y.from(p),i)}));const c={...n,id:e,name:e,path:i};return await this.saveMeta(c),c})}async move(a,e,t){return this.instrumentOperation("move",async()=>{const n=await this.getMeta(a),r=n.path??this.keyToPath(n.name||a),i=this.keyToPath(e);await this.runOperation(t,s=>this.run(s,async h=>{try{await this.ensureRemoteDirectory(h,i),await h.rename(r,i)}catch(p){try{const w=await T(h,r);await this.ensureRemoteDirectory(h,i),await h.uploadFrom(y.from(w),i),await h.remove(r)}catch(w){throw new AggregateError([p,w],`FTP move failed: rename and copy+delete fallback both failed for "${r}" → "${i}"`)}}}));const c={...n,id:e,name:e,path:i};await this.saveMeta(c);try{await this.deleteMeta(a)}catch{}return c})}async list(a=1e3,e){return this.instrumentOperation("list",async()=>{const t=this.keyToPath("");return this.runOperation(e,n=>this.run(n,async r=>{const i=[];return await this.walkList(r,t,i),i}))})}async exists({id:a},e){return this.instrumentOperation("exists",async()=>{let t;try{t=await this.getMeta(a)}catch{return!1}const n=t.path??this.keyToPath(t.name||a);return this.runOperation(e,r=>this.run(r,async i=>{try{return await i.size(n),!0}catch(c){if(d(c))return!1;throw c}}))})}async walkList(a,e,t){let n;try{n=await a.list(e||".")}catch(r){if(d(r))return;throw r}for(const r of n){const i=e?`${e}/${r.name}`:r.name;if(r.isDirectory){await this.walkList(a,i,t);continue}if(!r.isFile)continue;const c=this.pathToKey(i);if(!c)continue;const s=new P({contentType:"application/octet-stream",metadata:{},originalName:r.name});s.id=c,s.name=c,s.path=i,s.size=r.size,r.modifiedAt&&(s.modifiedAt=r.modifiedAt.toISOString()),t.push(s)}}async run(a,e){const t=new M;if(a?.aborted)throw g(a.reason);const n=l(()=>{t.close()},"onAbort");a?.addEventListener("abort",n,{once:!0});try{if(await t.access(this.connection),a?.aborted)throw g(a.reason);return await e(t)}catch(r){throw a?.aborted?g(r):r}finally{a?.removeEventListener("abort",n),t.close()}}async ensureRemoteDirectory(a,e){const t=D(e);t&&(await a.ensureDir(t),await a.cd("/"))}keyToPath(a){const e=f(a);e&&E.assertSafeId(e);const t=[];return this.rootFolderPath&&t.push(this.rootFolderPath),e&&t.push(e),t.length===0?"":`/${t.join("/")}`}pathToKey(a){const e=f(a);if(!this.rootFolderPath)return e;if(e===this.rootFolderPath)return"";const t=`${this.rootFolderPath}/`;return e.startsWith(t)?e.slice(t.length):e}}export{G as default};
@@ -1 +0,0 @@
1
- var y=Object.defineProperty;var h=(l,t)=>y(l,"name",{value:t,configurable:!0});import{randomUUID as w}from"node:crypto";import{request as b}from"gaxios";import{GoogleAuth as C}from"google-auth-library";import{r as R,E,b as U,g as k,d}from"./gcs-meta-storage-Bwts-MUe.js";import{d as $}from"./detect-file-type-5JhzC9RU.js";import{throwErrorCode as I,ERRORS as S}from"./ERRORS-CyOuSMLY.js";import{B as v,t as O}from"./storage-B-NDsI-o.js";import{v as T}from"./local-meta-storage-Bi0mK6gD.js";import m from"./GCSConfig-BQ0OpVhe.js";import B from"./GCSFile-CDQ6IWAz.js";import{r as A,o as j}from"./part-match-B5fLLmFw.js";import{o as x}from"./has-content-Bx2p8Okx.js";var P=Object.defineProperty,G=h((l,t)=>P(l,"name",{value:t,configurable:!0}),"e");class q extends Error{static{h(this,"o")}constructor(t,a,e){super(t),this.code=a,this.config=e}code;config;static{G(this,"FetchError")}name="FetchError"}var W=Object.defineProperty,g=h((l,t)=>W(l,"name",{value:t,configurable:!0}),"m");const M=g(l=>l>=200&&l<300||l===308||l===499,"validateStatus");class f extends v{static name="gcs";checksumTypes=["md5","crc32c"];get raw(){return this.authClient}meta;bucket;authClient;storageBaseURI;uploadBaseURI;isCustomEndpoint=!1;retryOptions={};useAuthWithCustomEndpoint;userProject;constructor(t){super(t);const a=t.bucket||process.env.GCS_BUCKET;if(!a)throw new Error("GCS bucket is not defined");if(!t.projectId)throw new Error("Sorry, we cannot connect to Cloud Services without a project ID.");this.bucket=a,this.storageBaseURI=`${t.storageAPI||m.storageAPI}/${this.bucket}/o`,this.uploadBaseURI=`${t.uploadAPI||m.uploadAPI}/${this.bucket}/o`,this.isCustomEndpoint=new URL(this.storageBaseURI).hostname!=="storage.googleapis.com";const{retryOptions:e,useAuthWithCustomEndpoint:r,userProject:i}=t;this.userProject=i,this.useAuthWithCustomEndpoint=r||!1,this.retryOptions={...R,...e},t.scopes||=m.authScopes,this.authClient=new C(t);const{bucket:o,metaStorage:c,metaStorageConfig:u,projectId:s}=t;if(c)this.meta=c;else{let n={...t,...u,logger:this.logger};"directory"in n?(this.logger?.debug("Using local meta storage"),this.meta=new T(n)):(o===n.bucket&&s===n.projectId&&(n={...n,authClient:this.authClient}),this.meta=new E(n))}this.isReady=!1,this.accessCheck().then(()=>{this.isReady=!0}).catch(n=>{this.logger?.error("Storage access check failed: %O",n)})}normalizeError(t){if(t.config){const a=+t.code||500;return{code:`GCS${a}`,message:t.message,name:t.name,retryable:a>=499,statusCode:a}}return{code:"GenericUploadError",message:`[${this.constructor.name}] ${t.message}`,name:t.name,statusCode:500}}async create(t,a){return this.instrumentOperation("create",async()=>{const e={...t};if(t.ttl){const s=typeof t.ttl=="string"?O(t.ttl):t.ttl;s!==void 0&&(e.expiredAt=Date.now()+s)}const r=new B(e);r.name=this.namingFunction(r),await this.validate(r);try{const s=await this.getMeta(r.id);return s.bytesWritten=await this.internalWrite(s,a),s}catch{}const i={"Content-Type":"application/json; charset=utf-8","X-Goog-Upload-Command":"start","X-Goog-Upload-Protocol":"resumable","X-Upload-Content-Length":r.size.toString(),"X-Upload-Content-Type":r.contentType},o={body:JSON.stringify({metadata:r.metadata}),headers:i,method:"POST",params:{name:r.name,size:r.size,uploadType:"resumable"},url:this.uploadBaseURI},c=await this.makeRequest(o,a);if(c.status!==200)throw new Error("Expected 200 response from GCS");const u=c.headers.get("X-Goog-Upload-Status")||c.headers.get("x-goog-upload-status");if(u!=="active")throw new Error(`X-Goog-Upload-Status response header expected 'active' got: ${u}`);return r.uri=c.headers.get("location"),this.config.clientDirectUpload?(r.GCSUploadURI=r.uri,this.logger?.debug("send uploadURI to client: %s",r.GCSUploadURI),r.status="created",r):(r.bytesWritten=0,await this.saveMeta(r),r.status="created",await this.onCreate(r),r)})}async write(t,a){return this.instrumentOperation("write",async()=>{let e;if("contentType"in t&&"metadata"in t&&!("body"in t)&&!("start"in t)?e=t:(e=await this.getMeta(t.id),await this.checkIfExpired(e)),e.status==="completed")return e;if(!A(t,e))return I(S.FILE_CONFLICT);const r=await this.lock(t.id);try{if(x(t)&&(e.bytesWritten===0||Number.isNaN(e.bytesWritten))&&(!e.contentType||e.contentType==="application/octet-stream"))try{const{fileType:i,stream:o}=await $(t.body);i?.mime&&(e.contentType=i.mime),t.body=o}catch{}e.bytesWritten=await this.internalWrite({...e,...t},a),e.status=j(e),e.status==="completed"&&(e.uri=`${this.storageBaseURI}/${e.name}`,await this.internalOnComplete(e))}finally{await this.unlock(t.id,r)}return e})}async delete({id:t},a){return this.instrumentOperation("delete",async()=>{const e=await this.getMeta(t);if(!e.uri)throw new Error(`File ${t} does not have a valid URI`);e.status="deleted",await this.makeRequest({method:"DELETE",url:e.uri,validateStatus:M},a),await this.deleteMeta(e.id);const r={...e};return await this.onDelete(r),r})}async copy(t,a,e){return this.instrumentOperation("copy",async()=>{const r=new URL(`/${this.bucket}/${t}`,"file://"),i=new URL(encodeURI(a),r).pathname,[,o,...c]=i.split("/"),u=c.join("/"),s=`${this.storageBaseURI}/${t}/rewriteTo/b/${o}/o/${u}`;let n={};const p={body:"",headers:{"Content-Type":"application/json"},method:"POST",url:s};do p.body=n.rewriteToken?JSON.stringify({rewriteToken:n.rewriteToken}):"",n=(await this.makeRequest(p,e)).data||{};while(n.rewriteToken);return await this.getMeta(a)})}async move(t,a,e){return this.instrumentOperation("move",async()=>{const r=await this.copy(t,a,e),i=`${this.storageBaseURI}/${t}`;return await this.makeRequest({method:"DELETE",url:i},e),r})}async get({id:t},a){return this.instrumentOperation("get",async()=>{const{data:e}=await this.makeRequest({params:{alt:"json"},url:`${this.storageBaseURI}/${t}`},a);if(await this.checkIfExpired({expiredAt:e.timeDeleted}),!e.uri)throw new Error("File URI not found");const r=(await this.makeRequest({params:{alt:"media"},url:e.uri},a)).data;let i;if(typeof r=="string")i=Buffer.from(r,"utf8");else if(r&&typeof r=="object"&&"data"in r){const o=r.data;i=Buffer.from(o)}else i=Buffer.from(r);return{...e,content:i}})}async exists({id:t},a){return this.instrumentOperation("exists",async()=>{try{return await this.getMeta(t),await this.makeRequest({method:"HEAD",url:`${this.storageBaseURI}/${t}`},a),!0}catch{return!1}})}async list(t=1e3,a){return this.instrumentOperation("list",async()=>{const e=[],r=Math.min(t,1e3);let i=!0,o={params:{maxResults:r},url:this.storageBaseURI};for(;i&&e.length<t;)try{const{data:c}=await this.makeRequest(o,a);for(const{name:u,timeCreated:s,updated:n}of c?.items||[]){if(e.length>=t)break;e.push({createdAt:s,id:u,modifiedAt:n})}i=c?.nextPageToken!==void 0,i&&e.length<t&&(o={...o,params:{...o.params,maxResults:Math.min(r,t-e.length),pageToken:c.nextPageToken}})}catch(c){const u=this.normalizeError(c instanceof Error?c:new Error(String(c)));throw await this.onError(u),c}return e},{limit:t})}async internalWrite(t,a){const{body:e,bytesWritten:r,size:i,uri:o=""}=t,c=U(t),u={method:"PUT"};if(e?.on){const s=new AbortController;e.on("aborted",()=>{s.abort()}),u.body=e,u.signal=s.signal,u.retry=!1}u.headers={Accept:"application/json","Content-Range":c,...i===r?{"X-Goog-Upload-Command":"upload, finalize"}:{}};try{const s=await this.makeRequest({url:o,...u},a);if(s.status===308){const n=s.headers.get("range");return n?k(n):0}if(s.status===200)return this.logger?.debug("uploaded %O",s.data),i;throw new q(String(s.data),`GCS${s.status}`,{uri:o})}catch(s){this.logger?.error(o,s);const n=this.normalizeError(s instanceof Error?s:new Error(String(s)));throw await this.onError(n),s}}internalOnComplete=g(t=>this.deleteMeta(t.id),"internalOnComplete");static buildCallSignal(t,a){const e=[];if(a&&e.push(a),t?.signal&&e.push(t.signal),e.length!==0)return e.length===1?e[0]:AbortSignal.any(e)}async makeRequest(t,a){typeof t.url=="string"&&(t.url=t.url.replaceAll("/:",":"));const e=f.buildCallSignal(a,t.signal);let r=this.retryOptions;if(a?.retries!==void 0){const o=typeof a.retries=="number"?a.retries:a.retries.maxRetries;typeof o=="number"&&(r={...this.retryOptions,retry:o})}const i=typeof a?.timeout=="number"&&a.timeout>0?a.timeout:6e4;return t={...t,headers:{"User-Agent":`${d.name}/${d.version}`,"x-goog-api-client":`gl-node/${process.versions.node} gccl/${d.version} gccl-invocation-id/${w()}`,...t.headers},params:{...this.userProject===void 0?{}:{userProject:this.userProject},...t.params},retry:t.retry===!1?!1:a?.retries!==0,retryConfig:r,timeout:i,...e?{signal:e}:{}},this.isCustomEndpoint&&!this.useAuthWithCustomEndpoint?b(t):this.authClient.request(t)}async accessCheck(){return this.makeRequest({url:this.storageBaseURI.replace("/o","")})}}export{f as default};
@@ -1 +0,0 @@
1
- var C=Object.defineProperty;var y=(r,e)=>C(r,"name",{value:e,configurable:!0});import{Readable as k}from"node:stream";import{drive as F}from"@googleapis/drive";import{JWT as T,GoogleAuth as E,OAuth2Client as _}from"google-auth-library";import{throwErrorCode as v,ERRORS as u,wrapStorageError as I}from"./ERRORS-CyOuSMLY.js";import{B as L}from"./storage-B-NDsI-o.js";import m from"./GoogleDriveFile-D0aGfGbL.js";import G from"./GoogleDriveMetaStorage-WGuUZPyx.js";import{o as O,r as A}from"./part-match-B5fLLmFw.js";import{u as R}from"./update-size-DANV7aa2.js";import{o as P}from"./has-content-Bx2p8Okx.js";var B=Object.defineProperty,c=y((r,e)=>B(r,"name",{value:e,configurable:!0}),"u");const f="https://www.googleapis.com/auth/drive",U=1024,p="fsdkKey",w="fsdkContentType",D="id, name, size, mimeType, md5Checksum, modifiedTime, appProperties",g=c(r=>{const e=r.lastIndexOf("/");return e===-1?r:r.slice(e+1)},"basename"),b=c(r=>r.replaceAll("\\","\\\\").replaceAll("'",String.raw`\'`),"escapeQueryValue");class z{static{y(this,"S")}static{c(this,"LRU")}#t;#e=new Map;constructor(e){this.#t=Math.max(1,e)}delete(e){this.#e.delete(e)}get(e){const i=this.#e.get(e);if(i!==void 0)return this.#e.delete(e),this.#e.set(e,i),i}set(e,i){if(this.#e.has(e)&&this.#e.delete(e),this.#e.set(e,i),this.#e.size>this.#t){const t=this.#e.keys().next().value;t!==void 0&&this.#e.delete(t)}}}const S=c(r=>{const e=r.subject??process.env.GOOGLE_DRIVE_SUBJECT;if(r.credentials)return new T({email:r.credentials.client_email,key:r.credentials.private_key,scopes:[f],...e&&{subject:e}});if(r.keyFilename)return new E({keyFile:r.keyFilename,scopes:[f],...e&&{clientOptions:{subject:e}}});if(r.oauth){const a=new _({clientId:r.oauth.clientId,clientSecret:r.oauth.clientSecret});return a.setCredentials({refresh_token:r.oauth.refreshToken}),a}const i=process.env.GOOGLE_DRIVE_CLIENT_EMAIL,t=process.env.GOOGLE_DRIVE_PRIVATE_KEY;if(i&&t)return new T({email:i,key:t,scopes:[f],...e&&{subject:e}});const o=process.env.GOOGLE_DRIVE_KEY_FILE;if(o)return new E({keyFile:o,scopes:[f],...e&&{clientOptions:{subject:e}}})},"buildAuth"),x=c(async r=>{const e=[];for await(const i of r)e.push(Buffer.from(i));return Buffer.concat(e)},"collectStream"),M=c(r=>{if(r instanceof Uint8Array)return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(Buffer.isBuffer(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);if(ArrayBuffer.isView(r)){const e=r;return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}if(typeof r=="string")return new TextEncoder().encode(r);throw new Error("Google Drive: unexpected response payload shape")},"toUint8");class Z extends L{static name="google-drive";checksumTypes=[];meta;authForTokens;driveClient;fileIdCache;publicByDefault;rootFolderId;sharedDriveParams;constructor(e){if(super(e),e.client)this.driveClient=e.client,this.authForTokens=void 0;else{const t=S(e);if(!t)throw new Error("Google Drive storage: missing auth. Pass `client`, `credentials`, `keyFilename`, or `oauth`. Env fallbacks: GOOGLE_DRIVE_CLIENT_EMAIL + GOOGLE_DRIVE_PRIVATE_KEY, or GOOGLE_DRIVE_KEY_FILE.");this.authForTokens=t,this.driveClient=F({auth:t,version:"v3"})}const i=e.driveId??process.env.GOOGLE_DRIVE_ID;this.rootFolderId=e.rootFolderId??process.env.GOOGLE_DRIVE_ROOT_FOLDER_ID??i??"root",this.publicByDefault=e.publicByDefault??!1,this.fileIdCache=new z(e.fileIdCacheSize??U),this.sharedDriveParams={includeItemsFromAllDrives:!0,supportsAllDrives:!0,...i&&{corpora:"drive",driveId:i}},this.meta=e.metaStorage??new G(e.metaStorageConfig),this.isReady=!0}get raw(){return this.driveClient}async create(e,i){return this.instrumentOperation("create",async()=>{const t=new m(e);t.name=this.namingFunction(t),await this.validate(t);try{const o=await this.getMeta(t.id);if(o.bytesWritten>=0)return o}catch{}return t.bytesWritten=0,t.status=O(t),await this.saveMeta(t),await this.onCreate(t),t})}async write(e,i){return this.instrumentOperation("write",async()=>{let t;if("contentType"in e&&"metadata"in e&&!("body"in e)&&!("start"in e)?t=e:(t=await this.getMeta(e.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(e.size!==void 0&&R(t,e.size),!A(e,t))throw new Error("File part does not match");const o=await this.lock(e.id);try{if(P(e)){if(this.isUnsupportedChecksum(e.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const a=await x(e.body),n=t.name||t.id,s={[w]:t.contentType,[p]:n},l=await this.runOperation(i,()=>this.driveClient.files.create({...this.sharedDriveParams,fields:"id, size, mimeType, md5Checksum, modifiedTime",media:{body:k.from(a),mimeType:t.contentType},requestBody:{appProperties:s,mimeType:t.contentType,name:g(n),parents:[this.rootFolderId]}})),{data:d}=l,h=d.id??void 0;h&&(this.fileIdCache.set(n,h),this.publicByDefault&&await this.runOperation(i,()=>this.driveClient.permissions.create({...this.sharedDriveParams,fileId:h,requestBody:{role:"reader",type:"anyone"}}))),t.bytesWritten=a.length,t.size=a.length,t.driveFileId=h,t.mimeType=d.mimeType??t.contentType,t.ETag=d.md5Checksum??void 0}return t.status=O(t),t.status==="completed"&&await this.internalOnComplete(t),await this.saveMeta(t),t}finally{await this.unlock(e.id,o)}})}async delete({id:e},i){return this.instrumentOperation("delete",async()=>{let t;const o=e;try{t=await this.getMeta(e)}catch{}try{const a=t?.driveFileId??await this.resolveFileId(o,i);await this.runOperation(i,()=>this.driveClient.files.delete({...this.sharedDriveParams,fileId:a})),this.fileIdCache.delete(o)}catch(a){if(!N(a))throw a;this.fileIdCache.delete(o)}return t?(t.status="deleted",await this.deleteMeta(t.id),await this.onDelete(t),t):Object.assign(new m({contentType:"application/octet-stream",metadata:{},originalName:e}),{id:e,name:e,status:"deleted"})})}async get({id:e},i){return this.instrumentOperation("get",async()=>{let t,o;try{t=await this.checkIfExpired(await this.getMeta(e)),o=t.driveFileId??await this.resolveFileId(t.name??e,i)}catch{o=await this.resolveFileId(e,i)}const[a,n]=await Promise.all([this.runOperation(i,()=>this.driveClient.files.get({...this.sharedDriveParams,fields:D,fileId:o})),this.runOperation(i,()=>this.driveClient.files.get({...this.sharedDriveParams,alt:"media",fileId:o},{responseType:"arraybuffer"}))]),{data:s}=a,l=M(n.data),d=Buffer.from(l.buffer,l.byteOffset,l.byteLength),h=s.appProperties??{};return{content:d,contentType:t?.contentType??h[w]??s.mimeType??"application/octet-stream",ETag:t?.ETag??s.md5Checksum??void 0,expiredAt:t?.expiredAt,id:e,metadata:t?.metadata??{},modifiedAt:t?.modifiedAt??s.modifiedTime??void 0,name:t?.name??s.name??e,originalName:t?.originalName??s.name??e,size:t?.size??Number(s.size??d.length)}})}async copy(e,i,t){return this.instrumentOperation("copy",async()=>{const o=await this.resolveFileId(e,t),a=await this.runOperation(t,()=>this.driveClient.files.copy({...this.sharedDriveParams,fields:"id, size, mimeType, md5Checksum",fileId:o,requestBody:{appProperties:{[p]:i},name:g(i),parents:[this.rootFolderId]}})),n=a.data.id??void 0;n&&this.fileIdCache.set(i,n);const s=new m({contentType:a.data.mimeType??"application/octet-stream",metadata:{},originalName:i});return s.id=i,s.name=i,s.driveFileId=n,s.mimeType=a.data.mimeType??void 0,s.ETag=a.data.md5Checksum??void 0,s.size=Number(a.data.size??0),s})}async move(e,i,t){return this.instrumentOperation("move",async()=>{const o=await this.copy(e,i,t);return await this.delete({id:e},t),o})}async list(e=1e3,i){return this.instrumentOperation("list",async()=>{const t=`'${b(this.rootFolderId)}' in parents and trashed=false`,o=(await this.runOperation(i,()=>this.driveClient.files.list({...this.sharedDriveParams,fields:`nextPageToken, files(${D})`,pageSize:e,q:t}))).data.files??[],a=[];for(const n of o){const s=n.appProperties??{},l=s[p];if(!l)continue;n.id&&this.fileIdCache.set(l,n.id);const d=new m({contentType:s[w]??n.mimeType??"application/octet-stream",metadata:{},originalName:n.name??l});d.id=l,d.name=l,d.driveFileId=n.id??void 0,d.mimeType=n.mimeType??void 0,d.size=Number(n.size??0),d.modifiedAt=n.modifiedTime??void 0,d.ETag=n.md5Checksum??void 0,a.push(d)}return a},{limit:e})}async getReadUrl(e,i){return i?.responseContentDisposition?v(u.METHOD_NOT_ALLOWED,"Google Drive: `responseContentDisposition` is not supported — Drive's webContentLink has no Content-Disposition override."):this.publicByDefault?`https://drive.google.com/uc?export=download&id=${await this.resolveFileId(e)}`:v(u.METHOD_NOT_ALLOWED,"Google Drive: getReadUrl() requires the adapter to be constructed with `publicByDefault: true`. Drive has no signed URL primitive — use get() for private files.")}async getUploadUrl(e,i){if(!this.authForTokens)return v(u.METHOD_NOT_ALLOWED,"Google Drive: getUploadUrl() requires `credentials`, `keyFilename`, or `oauth` — not the pre-built `client` escape hatch.");const t=await this.authForTokens.getAccessToken(),o=typeof t=="string"?t:t?.token;if(!o)throw new Error("Google Drive: failed to mint access token for resumable upload session");const a={Authorization:`Bearer ${o}`,"Content-Type":"application/json; charset=UTF-8"};i?.contentType&&(a["X-Upload-Content-Type"]=i.contentType),i?.contentLength!==void 0&&(a["X-Upload-Content-Length"]=String(i.contentLength));const n={appProperties:{[p]:e},name:g(e),parents:[this.rootFolderId]},s=await fetch("https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&supportsAllDrives=true",{body:JSON.stringify(n),headers:a,method:"POST"});if(!s.ok){const d=await s.text().catch(()=>"");throw I(new Error(`${s.statusText} ${d}`.trim()||s.statusText),{adapter:"Google Drive",operation:"resumable upload session",status:s.status})}const l=s.headers.get("location")??s.headers.get("Location");if(!l)throw I(new Error("response missing Location header"),{adapter:"Google Drive",code:u.STORAGE_ERROR,operation:"resumable upload session"});return l}async resolveFileId(e,i){const t=this.fileIdCache.get(e);if(t)return t;const o=`appProperties has { key='${p}' and value='${b(e)}' } and trashed=false`,a=(await this.runOperation(i,()=>this.driveClient.files.list({...this.sharedDriveParams,fields:"files(id)",pageSize:2,q:o}))).data.files??[];if(a.length===0)throw new Error(`Google Drive: not found: ${e}`);if(a.length>1)throw new Error(`Google Drive: multiple files share virtual key '${e}'. Resolve via storage.raw.`);const n=a[0]?.id;if(!n)throw new Error(`Google Drive: list returned no fileId for ${e}`);return this.fileIdCache.set(e,n),n}internalOnComplete=c(e=>this.deleteMeta(e.id),"internalOnComplete")}const N=c(r=>{if(r===null||typeof r!="object")return!1;const e=r;return typeof e.code=="number"&&e.code===404||typeof e.status=="number"&&e.status===404?!0:typeof e.response?.status=="number"&&e.response.status===404},"isNotFoundError");export{Z as default};
@@ -1 +0,0 @@
1
- var d=Object.defineProperty;var f=(l,e)=>d(l,"name",{value:e,configurable:!0});import{getStore as w}from"@netlify/blobs";import{a as g}from"./detect-file-type-5JhzC9RU.js";import{B as b,t as u,u as O}from"./storage-B-NDsI-o.js";import{v as E}from"./local-meta-storage-Bi0mK6gD.js";import m from"./NetlifyBlobFile-PMZLJ8AC.js";import{o as p,r as v}from"./part-match-B5fLLmFw.js";import{u as N}from"./update-size-DANV7aa2.js";import{o as T}from"./has-content-Bx2p8Okx.js";var k=Object.defineProperty,y=f((l,e)=>k(l,"name",{value:e,configurable:!0}),"u");class R extends b{static name="netlify-blob";checksumTypes=["md5"];get raw(){return this.store}meta;storeName;siteID;token;store;resolvedRetryConfig;constructor(e){super(e),this.storeName=e.storeName||"default",this.siteID=e.siteID||process.env.NETLIFY_SITE_ID,this.token=e.token||process.env.NETLIFY_TOKEN,this.store=w({name:this.storeName,...this.siteID&&{siteID:this.siteID},...this.token&&{token:this.token}});const n={backoffMultiplier:2,initialDelay:1e3,maxDelay:3e4,maxRetries:3,retryableStatusCodes:[408,429,500,502,503,504],shouldRetry:y(r=>{if(r instanceof Error){const i=r.code;if(i==="ECONNRESET"||i==="ETIMEDOUT"||i==="ENOTFOUND"||i==="ECONNREFUSED")return!0}const s=r;return!!(s.status&&[408,429,500,502,503,504].includes(s.status))},"shouldRetry"),...e.retryConfig};this.resolvedRetryConfig=n;const{metaStorage:t,metaStorageConfig:a}=e;this.meta=t||new E(a),this.isReady=!0}getRetryConfig(){return this.resolvedRetryConfig}async create(e,n){return this.instrumentOperation("create",async()=>{const t={...e};if(e.ttl){const r=typeof e.ttl=="string"?u(e.ttl):e.ttl;t.expiredAt=r===void 0?void 0:Date.now()+r}const a=new m(t);a.name=this.namingFunction(a),await this.validate(a);try{const r=await this.getMeta(a.id);if(r.bytesWritten>=0)return r}catch{}return a.bytesWritten=0,a.status=p(a),await this.saveMeta(a),await this.onCreate(a),a})}async write(e,n){return this.instrumentOperation("write",async()=>{let t;if("contentType"in e&&"metadata"in e&&!("body"in e)&&!("start"in e)?t=e:(t=await this.getMeta(e.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(e.size!==void 0&&N(t,e.size),!v(e,t))throw new Error("File part does not match");const a=await this.lock(e.id);try{if(T(e)){if(this.isUnsupportedChecksum(e.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const r=[],s=e.body;for await(const o of s)r.push(Buffer.from(o));const i=Buffer.concat(r);if((t.bytesWritten===0||Number.isNaN(t.bytesWritten))&&(!t.contentType||t.contentType==="application/octet-stream"))try{const o=await g(i);o?.mime&&(t.contentType=o.mime)}catch{}await this.runOperation(n,()=>this.store.set(t.name,i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),{metadata:{...t.metadata,contentType:t.contentType}})),t.pathname=t.name,t.url=this.getBlobUrl(t.name),t.bytesWritten=i.length}return t.status=p(t),t.status==="completed"&&await this.internalOnComplete(t),await this.saveMeta(t),t}finally{await this.unlock(e.id,a)}})}async delete({id:e},n){return this.instrumentOperation("delete",async()=>{const t=await this.getMeta(e);if(!t.pathname)throw new Error(`File ${e} does not have a valid pathname`);t.status="deleted";try{await this.runOperation(n,()=>this.store.delete(t.pathname))}catch(r){this.logger?.error("Failed to delete blob from Netlify Blob:",r);const s=this.normalizeError(r instanceof Error?r:new Error(String(r)));await this.onError(s)}await this.deleteMeta(t.id);const a={...t};return await this.onDelete(a),a})}async exists({id:e},n){return this.instrumentOperation("exists",async()=>{try{const t=await this.getMeta(e);return!t.pathname||t.pathname.length<=0?!1:await this.runOperation(n,()=>this.store.get(t.pathname,{type:"blob"}))!=null}catch{return!1}})}async get({id:e},n){return this.instrumentOperation("get",async()=>{const t=await this.checkIfExpired(await this.getMeta(e));if(!t.pathname||t.pathname.length<=0)throw new Error("File pathname not found");const a=await this.runOperation(n,()=>this.store.get(t.pathname,{type:"blob"}));if(!a)throw new Error("File not found in Netlify Blob");let r;if(typeof a=="string")r=Buffer.from(a,"utf8").buffer;else if(a&&typeof a=="object"&&"arrayBuffer"in a&&typeof a.arrayBuffer=="function")r=await this.runOperation(n,()=>a.arrayBuffer());else throw new Error("Invalid blob type returned from Netlify Blob");const s=Buffer.from(r);let i=null;try{i=await this.store.getMetadata?.(t.pathname)??null}catch{}return{content:s,contentType:i?.contentType||t.contentType,ETag:t.ETag,expiredAt:t.expiredAt,id:e,metadata:{...t.metadata,...i?.metadata},modifiedAt:t.modifiedAt,name:t.name,originalName:t.originalName,size:t.size||s.length}})}async copy(e,n,t){return this.instrumentOperation("copy",async()=>{const a=await this.getMeta(e);if(!a.pathname)throw new Error("Source file pathname not found");const r=await this.runOperation(t,()=>this.store.get(a.pathname,{type:"blob"}));if(!r)throw new Error("Source file not found in Netlify Blob");let s=null;try{const c=this.store;c.getMetadata&&a.pathname&&(s=await c.getMetadata(a.pathname))}catch{}let i;if(typeof r=="string")i=Buffer.from(r,"utf8").buffer;else if(r&&typeof r=="object"&&"arrayBuffer"in r){const c=r;i=await this.runOperation(t,()=>c.arrayBuffer())}else throw new Error("Invalid blob type returned from Netlify Blob");const o=Buffer.from(i);await this.runOperation(t,()=>this.store.set(n,o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength),{metadata:s||{contentType:a.contentType,...a.metadata}}));const h={...a,id:n,name:n,pathname:n,url:this.getBlobUrl(n)};return await this.saveMeta(h),h})}async move(e,n,t){return this.instrumentOperation("move",async()=>{const a=await this.copy(e,n,t);return await this.delete({id:e},t),a})}async update({id:e},n,t){return this.instrumentOperation("update",async()=>{const a=await this.getMeta(e),r={...n};if("ttl"in r&&r.ttl!==void 0){const i=r.ttl,o=typeof i=="string"?u(i):i;o!==void 0&&(r.expiredAt=Date.now()+o),delete r.ttl}O(a,r),await this.saveMeta(a);const s={...a,status:"updated"};return await this.onUpdate(s),s})}async list(e=1e3,n){return this.instrumentOperation("list",async()=>{const t=await this.runOperation(n,()=>this.store.list()),a=[];for await(const r of t.blobs){let s=null;try{s=await this.store.getMetadata?.(r.key)??null}catch{}const i=new m({contentType:s?.contentType||"application/octet-stream",metadata:s?.metadata||{},originalName:r.key}),o=r;if(i.createdAt=o.createdAt?.toISOString(),i.id=r.key,i.modifiedAt=o.updatedAt?.toISOString(),i.name=r.key,i.pathname=r.key,i.size=o.size,i.url=this.getBlobUrl(r.key),a.push(i),a.length>=e)break}return a},{limit:e})}internalOnComplete=y(e=>this.deleteMeta(e.id),"internalOnComplete");getBlobUrl(e){return`/api/blobs/${this.storeName}/${e}`}}export{R as default};
@@ -1 +0,0 @@
1
- var k=Object.defineProperty;var T=(o,t)=>k(o,"name",{value:t,configurable:!0});import{ResponseType as g,Client as A,GraphError as U}from"@microsoft/microsoft-graph-client";import{wrapStorageError as d,ERRORS as m,throwErrorCode as _}from"./ERRORS-CyOuSMLY.js";import{c as C}from"./oauth-refresh-Dg2ybc6_.js";import{B as N}from"./storage-B-NDsI-o.js";import f from"./OneDriveFile-XbVVKIJh.js";import S from"./OneDriveMetaStorage-DS4f83X2.js";import{o as E,r as $}from"./part-match-B5fLLmFw.js";import{u as L}from"./update-size-DANV7aa2.js";import{o as M}from"./has-content-Bx2p8Okx.js";var B=Object.defineProperty,h=T((o,t)=>B(o,"name",{value:t,configurable:!0}),"l");const P="https://graph.microsoft.com/.default",F=250*1024*1024,x=16*320*1024,V=1e3,u=h(o=>{let t=0,n=o.length;for(;t<n&&o[t]==="/";)t+=1;for(;n>t&&o[n-1]==="/";)n-=1;return t===0&&n===o.length?o:o.slice(t,n)},"trimSlashes"),y=h(o=>o.split("/").map(t=>encodeURIComponent(t)).join("/"),"encodePathSegments"),j=h(async o=>{const t=[];for await(const n of o)t.push(Buffer.from(n));return Buffer.concat(t)},"collectStream"),I=h(o=>({getAccessToken:h(()=>Promise.resolve(o),"getAccessToken")}),"createStaticAccessTokenAuth"),z=h(o=>({getAccessToken:h(async()=>o(),"ensure")}),"createCallableAccessTokenAuth"),O=h(o=>C({buildBody:h(()=>new URLSearchParams({client_id:o.clientId,client_secret:o.clientSecret,grant_type:"client_credentials",scope:P}),"buildBody"),provider:"OneDrive",tokenUrl:`https://login.microsoftonline.com/${encodeURIComponent(o.tenantId)}/oauth2/v2.0/token`}),"createClientCredentialsAuth"),v=h(o=>C({buildBody:h(()=>new URLSearchParams({client_id:o.clientId,grant_type:"refresh_token",refresh_token:o.refreshToken,scope:P,...o.clientSecret&&{client_secret:o.clientSecret}}),"buildBody"),provider:"OneDrive",tokenUrl:`https://login.microsoftonline.com/${encodeURIComponent(o.tenantId??"common")}/oauth2/v2.0/token`}),"createRefreshTokenAuth"),G=h(o=>({getAccessToken:h(()=>o.getAccessToken(),"getAccessToken")}),"makeAuthProvider"),D=h(o=>{if(o.client)return o.client;const t=o.accessToken!==void 0,n=o.clientCredentials!==void 0,e=o.oauth!==void 0;if([t,n,e].filter(Boolean).length>1)throw new Error("OneDrive storage: pass exactly one of `accessToken`, `clientCredentials`, or `oauth`.");let r;if(o.accessToken!==void 0?r=typeof o.accessToken=="function"?z(o.accessToken):I(o.accessToken):o.clientCredentials?r=O(o.clientCredentials):o.oauth&&(r=v({clientId:o.oauth.clientId,refreshToken:o.oauth.refreshToken,...o.oauth.clientSecret&&{clientSecret:o.oauth.clientSecret},...o.oauth.tenantId&&{tenantId:o.oauth.tenantId}})),!r){const a=process.env.ONEDRIVE_ACCESS_TOKEN;if(a)r=I(a);else{const i=process.env.ONEDRIVE_CLIENT_ID,s=process.env.ONEDRIVE_CLIENT_SECRET,c=process.env.ONEDRIVE_TENANT_ID,l=process.env.ONEDRIVE_REFRESH_TOKEN;l&&i?r=v({clientId:i,refreshToken:l,...s&&{clientSecret:s},...c&&{tenantId:c}}):i&&s&&c&&(r=O({clientId:i,clientSecret:s,tenantId:c}))}}if(!r)throw new Error("OneDrive storage: missing auth. Pass `client`, `accessToken`, `clientCredentials`, or `oauth`. Env fallbacks: ONEDRIVE_ACCESS_TOKEN; or ONEDRIVE_REFRESH_TOKEN + ONEDRIVE_CLIENT_ID (+ optional ONEDRIVE_CLIENT_SECRET, ONEDRIVE_TENANT_ID); or ONEDRIVE_CLIENT_ID + ONEDRIVE_CLIENT_SECRET + ONEDRIVE_TENANT_ID.");return A.initWithMiddleware({authProvider:G(r)})},"resolveAuth"),W=h(o=>{if(o instanceof U)return o.statusCode===404||o.code==="itemNotFound";if(o&&typeof o=="object"){const t=o;return t.statusCode===404||t.status===404||t.code==="itemNotFound"}return!1},"isNotFoundError");class nt extends N{static name="onedrive";checksumTypes=[];meta;basePath;client;copyTimeoutMs;publicByDefault;rootFolderPath;constructor(t){if(super(t),[t.driveId,t.siteId,t.userId].filter(n=>n!==void 0).length>1)throw new Error("OneDrive storage: pass at most one of `driveId`, `siteId`, or `userId`.");if(t.driveId)this.basePath=`/drives/${encodeURIComponent(t.driveId)}`;else if(t.siteId)this.basePath=`/sites/${encodeURIComponent(t.siteId)}/drive`;else if(t.userId)this.basePath=`/users/${encodeURIComponent(t.userId)}/drive`;else{if(t.clientCredentials)throw new Error("OneDrive storage: `clientCredentials` (app-only) auth requires `driveId`, `siteId`, or `userId`.");this.basePath="/me/drive"}this.rootFolderPath=u(t.rootFolderPath??""),this.publicByDefault=t.publicByDefault??!1,this.copyTimeoutMs=t.copyTimeoutMs??6e4,this.client=D(t),this.meta=t.metaStorage??new S(t.metaStorageConfig),this.isReady=!0}get raw(){return this.client}async create(t,n){return this.instrumentOperation("create",async()=>{const e=new f(t);e.name=this.namingFunction(e),await this.validate(e);try{const r=await this.getMeta(e.id);if(r.bytesWritten>=0)return r}catch{}return e.bytesWritten=0,e.status=E(e),await this.saveMeta(e),await this.onCreate(e),e})}async write(t,n){return this.instrumentOperation("write",async()=>{let e;if("contentType"in t&&"metadata"in t&&!("body"in t)&&!("start"in t)?e=t:(e=await this.getMeta(t.id),await this.checkIfExpired(e)),e.status==="completed")return e;if(t.size!==void 0&&L(e,t.size),!$(t,e))throw new Error("File part does not match");const r=await this.lock(t.id);try{if(M(t)){if(this.isUnsupportedChecksum(t.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const a=await j(t.body),i=e.name||e.id,s=a.byteLength<=F?await this.uploadSimple(i,a,e.contentType,n):await this.uploadSession(i,a,e.contentType,n);e.bytesWritten=a.length,e.size=a.length,e.driveItemId=s.id,e.webUrl=s.webUrl,e.eTag=s.eTag,e.ETag=s.eTag}return e.status=E(e),e.status==="completed"&&await this.internalOnComplete(e),await this.saveMeta(e),e}finally{await this.unlock(t.id,r)}})}async delete({id:t},n){return this.instrumentOperation("delete",async()=>{let e;try{e=await this.getMeta(t)}catch{}const r=e?.name??t;try{await this.runOperation(n,()=>this.client.api(this.itemApiPath(r)).delete())}catch(a){if(!W(a))throw a}return e?(e.status="deleted",await this.deleteMeta(e.id),await this.onDelete(e),e):Object.assign(new f({contentType:"application/octet-stream",metadata:{},originalName:t}),{id:t,name:t,status:"deleted"})})}async get({id:t},n){return this.instrumentOperation("get",async()=>{let e,r=t;try{e=await this.checkIfExpired(await this.getMeta(t)),r=e.name??t}catch{}const a=await this.runOperation(n,()=>this.client.api(this.itemApiPath(r)).get()),i=await this.runOperation(n,()=>this.client.api(this.itemActionPath(r,"content")).responseType(g.ARRAYBUFFER).get()),s=Buffer.from(i);return{content:s,contentType:e?.contentType??a.file?.mimeType??"application/octet-stream",ETag:e?.ETag??a.eTag,expiredAt:e?.expiredAt,id:t,metadata:e?.metadata??{},modifiedAt:e?.modifiedAt??a.lastModifiedDateTime,name:e?.name??a.name,originalName:e?.originalName??a.name,size:e?.size??a.size??s.length}})}async copy(t,n,e){return this.instrumentOperation("copy",async()=>{const r=this.parentReferencePath(n),a={name:R(n),parentReference:{path:r}},i=await this.runOperation(e,()=>this.client.api(this.itemActionPath(t,"copy")).responseType(g.RAW).post(a));if(i.status!==202){const w=await i.text().catch(()=>"");throw d(new Error(w||i.statusText),{adapter:"OneDrive",operation:"copy",status:i.status})}const s=i.headers.get("Location");if(!s)throw d(new Error("response missing Location monitor URL"),{adapter:"OneDrive",code:m.STORAGE_ERROR,operation:"copy"});const c=await this.pollCopyMonitor(s,e),l=new f({contentType:"application/octet-stream",metadata:{},originalName:n});return l.id=n,l.name=n,l.driveItemId=c,l})}async move(t,n,e){return this.instrumentOperation("move",async()=>{const r=this.parentReferencePath(n),a=R(n),i=await this.runOperation(e,()=>this.client.api(this.itemApiPath(t)).patch({name:a,parentReference:{path:r}})),s=new f({contentType:"application/octet-stream",metadata:{},originalName:n});s.id=n,s.name=n,s.driveItemId=i.id,s.webUrl=i.webUrl,s.eTag=i.eTag,s.ETag=i.eTag;try{await this.deleteMeta(t)}catch{}return s})}async list(t=1e3,n){return this.instrumentOperation("list",async()=>{const e=[];let r=`${this.folderListChildrenPath()}?$top=${Math.min(t,1e3)}`;for(;r&&e.length<t;){const a=await this.runOperation(n,()=>this.client.api(r).get());for(const i of a.value){if(!i.file)continue;const s=this.itemPathToKey(i);if(!s)continue;const c=new f({contentType:i.file.mimeType??"application/octet-stream",metadata:{},originalName:i.name});if(c.id=s,c.name=s,c.driveItemId=i.id,c.webUrl=i.webUrl,c.eTag=i.eTag,c.ETag=i.eTag,c.size=i.size??0,c.modifiedAt=i.lastModifiedDateTime,e.push(c),e.length>=t)break}r=a["@odata.nextLink"]??null}return e},{limit:t})}async getReadUrl(t,n){if(n?.responseContentDisposition||n?.responseContentType)return _(m.METHOD_NOT_ALLOWED,"OneDrive: `responseContentDisposition` / `responseContentType` are not supported — Graph download URLs have no overrides.");if(this.publicByDefault){const r=(await this.client.api(this.itemActionPath(t,"createLink")).post({scope:"anonymous",type:"view"})).link?.webUrl;if(!r)throw new Error("OneDrive: createLink response missing webUrl");return r}const e=(await this.client.api(this.itemApiPath(t)).select("@microsoft.graph.downloadUrl").get())["@microsoft.graph.downloadUrl"];if(!e)throw new Error("OneDrive: item has no `@microsoft.graph.downloadUrl` — it may be a folder or have no content.");return e}async getUploadUrl(t,n){const e=await this.client.api(this.itemActionPath(t,"createUploadSession")).post({item:{"@microsoft.graph.conflictBehavior":"replace",...n?.contentType&&{file:{mimeType:n.contentType}}}});if(!e.uploadUrl)throw d(new Error("createUploadSession response missing uploadUrl"),{adapter:"OneDrive",code:m.STORAGE_ERROR,operation:"getUploadUrl"});return e.uploadUrl}keyParts(t){const n=u(t),e=[];return this.rootFolderPath&&e.push(this.rootFolderPath),n&&e.push(n),e}itemApiPath(t){const n=this.keyParts(t);return n.length===0?`${this.basePath}/root`:`${this.basePath}/root:/${y(n.join("/"))}`}itemActionPath(t,n){const e=this.keyParts(t);return e.length===0?`${this.basePath}/root/${n}`:`${this.basePath}/root:/${y(e.join("/"))}:/${n}`}folderListChildrenPath(){return this.itemActionPath("","children")}parentReferencePath(t){const n=u(t),e=[];this.rootFolderPath&&e.push(this.rootFolderPath);const r=n.lastIndexOf("/");if(r!==-1){const a=n.slice(0,r);a&&e.push(a)}return e.length===0?"/drive/root:":`/drive/root:/${y(e.join("/"))}`}itemPathToKey(t){const n=t.parentReference?.path??"",e="/root:",r=n.indexOf(e);let a=r===-1?"":n.slice(r+e.length);a=u(decodeURIComponent(a));const i=this.rootFolderPath&&a.startsWith(this.rootFolderPath)?a.slice(this.rootFolderPath.length):a,s=u(i);return s?`${s}/${t.name}`:t.name}async uploadSimple(t,n,e,r){return await this.runOperation(r,()=>this.client.api(`${this.itemActionPath(t,"content")}?@microsoft.graph.conflictBehavior=replace`).header("Content-Type",e??"application/octet-stream").put(n))}async uploadSession(t,n,e,r){const a=await this.runOperation(r,()=>this.client.api(this.itemActionPath(t,"createUploadSession")).post({item:{"@microsoft.graph.conflictBehavior":"replace",...e&&{file:{mimeType:e}}}})),i=n.byteLength;let s=0,c;for(;s<i;){const l=Math.min(s+x,i),w=n.subarray(s,l),p=await this.runOperation(r,()=>fetch(a.uploadUrl,{body:new Uint8Array(w),headers:{"Content-Length":String(w.byteLength),"Content-Range":`bytes ${s}-${l-1}/${i}`},method:"PUT"}));if(p.status===200||p.status===201)c=await p.json();else if(p.status!==202){const b=await p.text().catch(()=>"");throw d(new Error(b||p.statusText),{adapter:"OneDrive",operation:"upload-session chunk",status:p.status})}s=l}if(!c)throw d(new Error("upload-session terminated without a final DriveItem response"),{adapter:"OneDrive",code:m.STORAGE_ERROR,operation:"write"});return c}async pollCopyMonitor(t,n){const e=Date.now()+this.copyTimeoutMs;for(;;){const r=await this.runOperation(n,()=>fetch(t));if(!r.ok)throw d(new Error(r.statusText),{adapter:"OneDrive",operation:"copy monitor",status:r.status});const a=await r.json();if(a.status==="completed")return a.resourceId;if(a.status==="failed")throw d(new Error(a.error?.message??"unknown error"),{adapter:"OneDrive",code:m.STORAGE_ERROR,operation:"copy"});if(Date.now()>=e)throw new Error(`OneDrive: copy timed out after ${this.copyTimeoutMs}ms (status: ${a.status??"unknown"})`);await new Promise(i=>{setTimeout(i,V)})}}internalOnComplete=h(t=>this.deleteMeta(t.id),"internalOnComplete")}const R=h(o=>{const t=u(o),n=t.lastIndexOf("/");return n===-1?t:t.slice(n+1)},"baseName"),ot=h(o=>D(o),"buildGraphClient");export{ot as buildGraphClient,nt as default};
@@ -1 +0,0 @@
1
- var k=Object.defineProperty;var g=(r,t)=>k(r,"name",{value:t,configurable:!0});import A,{ClientResponseError as E}from"pocketbase";import{throwErrorCode as f,ERRORS as w}from"./ERRORS-CyOuSMLY.js";import{B as N}from"./storage-B-NDsI-o.js";import u from"./PocketBaseFile-CkAiSBb0.js";import B from"./PocketBaseMetaStorage-B6utPncj.js";import{o as O,r as S}from"./part-match-B5fLLmFw.js";import{u as T}from"./update-size-DANV7aa2.js";import{o as F}from"./has-content-Bx2p8Okx.js";var R=Object.defineProperty,p=g((r,t)=>R(r,"name",{value:t,configurable:!0}),"h");const b=p(async r=>{const t=[];for await(const a of r)t.push(Buffer.from(a));return Buffer.concat(t)},"collectStream"),d=p(r=>(r instanceof E||!!r&&typeof r=="object")&&r.status===404,"isNotFound"),m=p((r,t,a,e)=>{const i=r.files.getURL??r.files.getUrl;return i?i(t,a,e):f(w.METHOD_NOT_ALLOWED,"PocketBase: client has no files.getURL()")},"fileUrl");class D extends N{static name="pocketbase";checksumTypes=[];meta;client;collectionName;defaultUrlExpiresIn;fileField;keyField;publicBaseUrl;ensureAuth;constructor(t){if(super(t),!t.collection)throw new Error("PocketBase storage: `collection` is required.");if(this.collectionName=t.collection,this.keyField=t.keyField??"key",this.fileField=t.fileField??"file",this.publicBaseUrl=t.publicBaseUrl,this.defaultUrlExpiresIn=t.defaultUrlExpiresIn??3600,t.client)this.client=t.client,this.ensureAuth=async()=>{};else{const a=t.url??process.env.POCKETBASE_URL;if(!a)throw new Error("PocketBase storage: `url` is required (or set POCKETBASE_URL).");const e=new A(a);this.client=e;const i=t.authToken??process.env.POCKETBASE_AUTH_TOKEN,n=t.adminEmail??process.env.POCKETBASE_ADMIN_EMAIL,s=t.adminPassword??process.env.POCKETBASE_ADMIN_PASSWORD;i?(e.authStore.save(i,null),this.ensureAuth=async()=>{}):n&&s?this.ensureAuth=async()=>{e.authStore.isValid||await e.collection("_superusers").authWithPassword(n,s)}:this.ensureAuth=async()=>{}}this.meta=t.metaStorage??new B(t.metaStorageConfig),this.isReady=!0}get raw(){return this.client}async create(t,a){return this.instrumentOperation("create",async()=>{const e=new u(t);e.name=this.namingFunction(e),e.bucket=this.collectionName,e.path=e.name,await this.validate(e);try{const i=await this.getMeta(e.id);if(i.bytesWritten>=0)return i}catch{}return e.bytesWritten=0,e.status=O(e),await this.saveMeta(e),await this.onCreate(e),e})}async write(t,a){return this.instrumentOperation("write",async()=>{let e;if("contentType"in t&&"metadata"in t&&!("body"in t)&&!("start"in t)?e=t:(e=await this.getMeta(t.id),await this.checkIfExpired(e)),e.status==="completed")return e;if(t.size!==void 0&&T(e,t.size),!S(t,e))throw new Error("File part does not match");const i=await this.lock(t.id);try{if(F(t)){if(this.isUnsupportedChecksum(t.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const n=await b(t.body),s=e.path??e.name;await this.putRecord(s,n,e.contentType,a),e.bytesWritten=n.length,e.size=n.length,e.path=s}return e.status=O(e),e.status==="completed"&&await this.internalOnComplete(e),await this.saveMeta(e),e}finally{await this.unlock(t.id,i)}})}async delete({id:t},a){return this.instrumentOperation("delete",async()=>{let e;try{e=await this.getMeta(t)}catch{}const i=e?.path??e?.name??t;await this.ensureAuth();try{const n=await this.findRecord(i,a);await this.runOperation(a,()=>this.client.collection(this.collectionName).delete(n.id))}catch(n){if(!d(n))throw n}return e?(e.status="deleted",await this.deleteMeta(e.id),await this.onDelete(e),e):Object.assign(new u({contentType:"application/octet-stream",metadata:{},originalName:t}),{bucket:this.collectionName,id:t,name:t,path:i,status:"deleted"})})}async exists({id:t},a){return this.instrumentOperation("exists",async()=>{let e=t;try{e=(await this.getMeta(t)).path??t}catch{}await this.ensureAuth();try{return await this.findRecord(e,a),!0}catch(i){if(d(i))return!1;throw i}})}async get({id:t},a){return this.instrumentOperation("get",async()=>{let e=t,i;try{i=await this.checkIfExpired(await this.getMeta(t)),e=i.path??i.name??t}catch{}await this.ensureAuth();const n=await this.findRecord(e,a),s=String(n[this.fileField]??""),o=m(this.client,n,s),c=await this.runOperation(a,()=>fetch(o));if(!c.ok)return f(w.FILE_NOT_FOUND,`PocketBase: object not found at "${e}"`);const h=Buffer.from(await c.arrayBuffer());return{content:h,contentType:i?.contentType??c.headers.get("content-type")??"application/octet-stream",ETag:i?.ETag,expiredAt:i?.expiredAt,id:t,metadata:i?.metadata??{},modifiedAt:i?.modifiedAt,name:i?.name??e,originalName:i?.originalName??e,size:i?.size??h.length}})}async copy(t,a,e){return this.instrumentOperation("copy",async()=>{const i=(await this.getMetaSafe(t))?.path??t;await this.ensureAuth();const n=await this.findRecord(i,e),s=String(n[this.fileField]??""),o=m(this.client,n,s),c=await this.runOperation(e,()=>fetch(o));if(!c.ok)return f(w.FILE_NOT_FOUND,`PocketBase: object not found at "${i}"`);const h=Buffer.from(await c.arrayBuffer()),y=c.headers.get("content-type")??"application/octet-stream";await this.putRecord(a,h,y,e);const l=new u({contentType:y,metadata:{},originalName:a});return l.id=a,l.name=a,l.path=a,l.bucket=this.collectionName,l.size=h.length,l})}async move(t,a,e){return this.instrumentOperation("move",async()=>{const i=await this.copy(t,a,e),n=(await this.getMetaSafe(t))?.path??t;await this.ensureAuth();try{const s=await this.findRecord(n,e);await this.runOperation(e,()=>this.client.collection(this.collectionName).delete(s.id))}catch(s){if(!d(s))throw s}try{await this.deleteMeta(t)}catch{}return i})}async list(t=1e3,a){return this.instrumentOperation("list",async()=>{await this.ensureAuth();const{items:e}=await this.runOperation(a,()=>this.client.collection(this.collectionName).getList(1,t));return(e??[]).map(i=>{const n=String(i[this.keyField]??i.id),s=String(i[this.fileField]??""),o=new u({contentType:"application/octet-stream",metadata:{},originalName:n});return o.id=n,o.name=n,o.path=n,o.bucket=this.collectionName,o.ETag=s||void 0,o.createdAt=typeof i.created=="string"?i.created:void 0,o.modifiedAt=typeof i.updated=="string"?i.updated:void 0,o})},{limit:t})}async getReadUrl(t,a){if(this.publicBaseUrl)return`${this.publicBaseUrl.replace(/\/+$/,"")}/${t}`;await this.ensureAuth();let e=t;const i=await this.getMetaSafe(t);i?.path&&(e=i.path);const n=await this.findRecord(e),s=String(n[this.fileField]??""),o=await this.client.files.getToken();return m(this.client,n,s,{token:o})}async findRecord(t,a){const e=this.client.filter(`${this.keyField} = {:k}`,{k:t});return this.runOperation(a,()=>this.client.collection(this.collectionName).getFirstListItem(e))}async putRecord(t,a,e,i){await this.ensureAuth();const n=new FormData;n.append(this.keyField,t),n.append(this.fileField,new Blob([new Uint8Array(a)],{type:e}),t);try{const s=await this.findRecord(t,i);await this.runOperation(i,()=>this.client.collection(this.collectionName).update(s.id,n))}catch(s){if(!d(s))throw s;await this.runOperation(i,()=>this.client.collection(this.collectionName).create(n))}}async getMetaSafe(t){try{return await this.getMeta(t)}catch{return}}internalOnComplete=p(t=>this.deleteMeta(t.id),"internalOnComplete")}export{D as default};