@fileverse-dev/ddoc 5.1.13 → 5.1.14-storage-agnostic.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -136,6 +136,15 @@ export interface DdocProps extends CommentAccountProps {
136
136
  };
137
137
  tabSectionContainer?: HTMLElement;
138
138
  isCollabDocumentPublished?: boolean;
139
+ /**
140
+ * Storage-agnostic image fetch function. Receives the stored location of an
141
+ * encrypted image (`url` + `contentRef`, e.g. an IPFS gateway URL + CID or a
142
+ * Swarm URL + reference) along with its decryption parameters, and returns
143
+ * the decrypted image. Preferred over the deprecated `ipfsImageFetchFn`;
144
+ * when both are provided, `imageFetchFn` wins.
145
+ */
146
+ imageFetchFn?: ImageFetchFn;
147
+ /** @deprecated Use the storage-agnostic `imageFetchFn` instead. */
139
148
  ipfsImageFetchFn?: (_data: IpfsImageFetchPayload) => Promise<{
140
149
  url: string;
141
150
  file: File;
@@ -174,6 +183,15 @@ export interface DdocProps extends CommentAccountProps {
174
183
  isPreviewMode: boolean;
175
184
  viewerMode?: 'suggest' | 'view-only';
176
185
  ensResolutionUrl?: string;
186
+ /**
187
+ * Storage-agnostic image upload function. Encrypts and stores the file on
188
+ * the host's storage backend (IPFS, Swarm, ...) and returns its location
189
+ * (`url` + `contentRef`) plus the decryption parameters. Preferred over the
190
+ * deprecated `ipfsImageUploadFn`; when both are provided, `imageUploadFn`
191
+ * wins.
192
+ */
193
+ imageUploadFn?: ImageUploadFn;
194
+ /** @deprecated Use the storage-agnostic `imageUploadFn` instead. */
177
195
  ipfsImageUploadFn?: (file: File) => Promise<IpfsImageUploadResponse>;
178
196
  enableIndexeddbSync?: boolean;
179
197
  ddocId?: string;
@@ -290,6 +308,39 @@ export interface IUser {
290
308
  isEns: boolean;
291
309
  }
292
310
  export { type IComment };
311
+ /**
312
+ * Storage-agnostic result of an image upload. The editor treats both fields
313
+ * as opaque: `url` is a fetchable location of the encrypted blob (e.g. an
314
+ * IPFS gateway URL or a Swarm `/bytes` URL) and `contentRef` is the backend's
315
+ * content address (IPFS CID, Swarm reference, ...). Both are stored in the
316
+ * document and handed back verbatim to `imageFetchFn`.
317
+ */
318
+ export interface StorageImageUploadResponse {
319
+ encryptionKey: string;
320
+ nonce: string;
321
+ authTag: string;
322
+ url: string;
323
+ contentRef: string;
324
+ }
325
+ /**
326
+ * Storage-agnostic payload handed to `imageFetchFn`: the `url`/`contentRef`
327
+ * returned by `imageUploadFn` at upload time, plus the parameters needed to
328
+ * decrypt the blob.
329
+ */
330
+ export interface StorageImageFetchPayload {
331
+ encryptionKey: string;
332
+ nonce: string;
333
+ authTag: string;
334
+ mimeType: string;
335
+ url: string;
336
+ contentRef: string;
337
+ }
338
+ export type ImageUploadFn = (file: File) => Promise<StorageImageUploadResponse>;
339
+ export type ImageFetchFn = (_data: StorageImageFetchPayload) => Promise<{
340
+ url: string;
341
+ file: File;
342
+ }>;
343
+ /** @deprecated Use the storage-agnostic {@link StorageImageUploadResponse} instead. */
293
344
  export interface IpfsImageUploadResponse {
294
345
  encryptionKey: string;
295
346
  nonce: string;
@@ -297,6 +348,7 @@ export interface IpfsImageUploadResponse {
297
348
  ipfsHash: string;
298
349
  authTag: string;
299
350
  }
351
+ /** @deprecated Use the storage-agnostic {@link StorageImageFetchPayload} instead. */
300
352
  export interface IpfsImageFetchPayload {
301
353
  encryptionKey: string;
302
354
  nonce: string;
@@ -0,0 +1,30 @@
1
+ import { ImageFetchFn, ImageUploadFn, IpfsImageFetchPayload, IpfsImageUploadResponse } from '../types';
2
+
3
+ /**
4
+ * Boundary adapters between the storage-agnostic public props
5
+ * (`imageUploadFn` / `imageFetchFn`) and the IPFS-shaped interface the editor
6
+ * internals still use. Internals are untouched: a storage-agnostic host
7
+ * function is wrapped here, at the prop boundary, so that downstream code
8
+ * keeps seeing the legacy `ipfsUrl` / `ipfsHash` field names regardless of
9
+ * which backend the host actually stores on.
10
+ */
11
+ type LegacyImageUploadFn = (file: File) => Promise<IpfsImageUploadResponse>;
12
+ type LegacyImageFetchFn = (_data: IpfsImageFetchPayload) => Promise<{
13
+ url: string;
14
+ file: File;
15
+ }>;
16
+ /**
17
+ * Resolve the upload function to use internally. The storage-agnostic
18
+ * `imageUploadFn` wins over the deprecated `ipfsImageUploadFn`; its response
19
+ * is mapped onto the legacy field names (`url` → `ipfsUrl`,
20
+ * `contentRef` → `ipfsHash`).
21
+ */
22
+ export declare const resolveImageUploadFn: (imageUploadFn?: ImageUploadFn, ipfsImageUploadFn?: LegacyImageUploadFn) => LegacyImageUploadFn | undefined;
23
+ /**
24
+ * Resolve the fetch function to use internally. The storage-agnostic
25
+ * `imageFetchFn` wins over the deprecated `ipfsImageFetchFn`; the legacy
26
+ * payload built by the internals is mapped onto the agnostic field names
27
+ * (`ipfsUrl` → `url`, `ipfsHash` → `contentRef`).
28
+ */
29
+ export declare const resolveImageFetchFn: (imageFetchFn?: ImageFetchFn, ipfsImageFetchFn?: LegacyImageFetchFn) => LegacyImageFetchFn | undefined;
30
+ export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@fileverse-dev/ddoc",
3
3
  "private": false,
4
4
  "description": "DDoc",
5
- "version": "5.1.13",
5
+ "version": "5.1.14-storage-agnostic.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/fileverse/fileverse-ddocs.git"