clefbase 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/react/StorageImage.d.ts +7 -58
- package/dist/react/StorageImage.d.ts.map +1 -1
- package/dist/react/StorageImage.js +12 -69
- package/dist/react/StorageImage.js.map +1 -1
- package/dist/storage/index.d.ts +25 -40
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +68 -55
- package/dist/storage/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -34405,7 +34405,7 @@ async function runSitesList(cwd = process.cwd()) {
|
|
|
34405
34405
|
}
|
|
34406
34406
|
|
|
34407
34407
|
// package.json
|
|
34408
|
-
var version = "1.3.
|
|
34408
|
+
var version = "1.3.5";
|
|
34409
34409
|
|
|
34410
34410
|
// src/cli/index.ts
|
|
34411
34411
|
var program2 = new Command();
|
|
@@ -2,75 +2,24 @@ import React, { type ImgHTMLAttributes } from "react";
|
|
|
2
2
|
import type { ClefbaseStorage } from "../storage";
|
|
3
3
|
export type StorageImageStatus = "loading" | "loaded" | "error";
|
|
4
4
|
export interface StorageImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src"> {
|
|
5
|
-
/**
|
|
6
|
-
* The ClefbaseStorage instance returned by `getStorage(app)`.
|
|
7
|
-
*/
|
|
8
5
|
storage: ClefbaseStorage;
|
|
9
|
-
/**
|
|
10
|
-
* Path inside the default bucket, e.g. `"avatars/user-123.jpg"`.
|
|
11
|
-
* Mutually exclusive with `bucket` + `path`.
|
|
12
|
-
*/
|
|
6
|
+
/** Path inside the default bucket, e.g. "avatars/user-123.jpg". */
|
|
13
7
|
src?: string;
|
|
14
|
-
/**
|
|
15
|
-
* Named bucket to read from. Pair with `path`.
|
|
16
|
-
*/
|
|
8
|
+
/** Named bucket to read from. Pair with `path`. */
|
|
17
9
|
bucket?: string;
|
|
18
|
-
/**
|
|
19
|
-
* File path inside `bucket`.
|
|
20
|
-
*/
|
|
10
|
+
/** File path inside `bucket`. */
|
|
21
11
|
path?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Shown while the download URL is being resolved.
|
|
24
|
-
* Accepts a URL string or any React node.
|
|
25
|
-
*/
|
|
12
|
+
/** Shown while the download URL is being resolved. */
|
|
26
13
|
placeholder?: React.ReactNode | string;
|
|
27
|
-
/**
|
|
28
|
-
* Shown when the URL cannot be resolved or the image fails to load.
|
|
29
|
-
* Accepts a URL string or any React node.
|
|
30
|
-
*/
|
|
14
|
+
/** Shown when the URL cannot be resolved or the image fails to load. */
|
|
31
15
|
fallback?: React.ReactNode | string;
|
|
32
|
-
/**
|
|
33
|
-
* Called with the resolved download URL once ready.
|
|
34
|
-
*/
|
|
35
16
|
onResolve?: (url: string) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Called if URL resolution or image loading fails.
|
|
38
|
-
*/
|
|
39
17
|
onError?: (err: unknown) => void;
|
|
40
|
-
/**
|
|
41
|
-
* Called whenever the loading status changes.
|
|
42
|
-
*/
|
|
43
18
|
onStatusChange?: (status: StorageImageStatus) => void;
|
|
44
19
|
}
|
|
45
20
|
/**
|
|
46
|
-
*
|
|
47
|
-
* authenticated download URLs
|
|
48
|
-
*
|
|
49
|
-
* @example — default bucket
|
|
50
|
-
* ```tsx
|
|
51
|
-
* const storage = getStorage(app);
|
|
52
|
-
*
|
|
53
|
-
* <StorageImage
|
|
54
|
-
* storage={storage}
|
|
55
|
-
* src="avatars/user-123.jpg"
|
|
56
|
-
* alt="User avatar"
|
|
57
|
-
* width={64}
|
|
58
|
-
* height={64}
|
|
59
|
-
* style={{ borderRadius: "50%" }}
|
|
60
|
-
* />
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @example — named bucket
|
|
64
|
-
* ```tsx
|
|
65
|
-
* <StorageImage
|
|
66
|
-
* storage={storage}
|
|
67
|
-
* bucket="media"
|
|
68
|
-
* path="products/shoe.webp"
|
|
69
|
-
* alt="Product photo"
|
|
70
|
-
* placeholder={<Spinner />}
|
|
71
|
-
* fallback={<img src="/no-image.svg" alt="Not found" />}
|
|
72
|
-
* />
|
|
73
|
-
* ```
|
|
21
|
+
* Drop-in <img> replacement that resolves Clefbase storage paths to
|
|
22
|
+
* authenticated download URLs via /storage/resolve.
|
|
74
23
|
*/
|
|
75
24
|
export declare const StorageImage: React.ForwardRefExoticComponent<StorageImageProps & React.RefAttributes<HTMLImageElement>>;
|
|
76
25
|
export default StorageImage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageImage.d.ts","sourceRoot":"","sources":["../../src/react/StorageImage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAKZ,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIlD,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEhE,MAAM,WAAW,iBACf,SAAQ,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC;IACxD
|
|
1
|
+
{"version":3,"file":"StorageImage.d.ts","sourceRoot":"","sources":["../../src/react/StorageImage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAKZ,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIlD,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEhE,MAAM,WAAW,iBACf,SAAQ,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC;IACxD,OAAO,EAAE,eAAe,CAAC;IACzB,mEAAmE;IACnE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC;IACvC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC;IACpC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IACjC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACvD;AAID;;;GAGG;AACH,eAAO,MAAM,YAAY,4FAoIxB,CAAC;AAGF,eAAe,YAAY,CAAC"}
|
|
@@ -5,70 +5,20 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
// ─── StorageImage ─────────────────────────────────────────────────────────────
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* authenticated download URLs
|
|
10
|
-
*
|
|
11
|
-
* @example — default bucket
|
|
12
|
-
* ```tsx
|
|
13
|
-
* const storage = getStorage(app);
|
|
14
|
-
*
|
|
15
|
-
* <StorageImage
|
|
16
|
-
* storage={storage}
|
|
17
|
-
* src="avatars/user-123.jpg"
|
|
18
|
-
* alt="User avatar"
|
|
19
|
-
* width={64}
|
|
20
|
-
* height={64}
|
|
21
|
-
* style={{ borderRadius: "50%" }}
|
|
22
|
-
* />
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @example — named bucket
|
|
26
|
-
* ```tsx
|
|
27
|
-
* <StorageImage
|
|
28
|
-
* storage={storage}
|
|
29
|
-
* bucket="media"
|
|
30
|
-
* path="products/shoe.webp"
|
|
31
|
-
* alt="Product photo"
|
|
32
|
-
* placeholder={<Spinner />}
|
|
33
|
-
* fallback={<img src="/no-image.svg" alt="Not found" />}
|
|
34
|
-
* />
|
|
35
|
-
* ```
|
|
8
|
+
* Drop-in <img> replacement that resolves Clefbase storage paths to
|
|
9
|
+
* authenticated download URLs via /storage/resolve.
|
|
36
10
|
*/
|
|
37
11
|
exports.StorageImage = (0, react_1.forwardRef)(function StorageImage({ storage, src, bucket, path, placeholder, fallback, onResolve, onError, onStatusChange, alt = "", ...imgProps }, ref) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// connection pool (typically 6 connections) when many cards mount at once.
|
|
41
|
-
const getDirectUrl = () => {
|
|
42
|
-
try {
|
|
43
|
-
if (bucket && path)
|
|
44
|
-
return storage._directUrl(bucket, path);
|
|
45
|
-
if (src)
|
|
46
|
-
return storage._directUrl(storage["_defaultBucket"] ?? "default", src);
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const initialUrl = getDirectUrl();
|
|
54
|
-
const [resolvedUrl, setResolvedUrl] = (0, react_1.useState)(initialUrl);
|
|
55
|
-
const [status, setStatus] = (0, react_1.useState)(initialUrl ? "loaded" : "loading");
|
|
56
|
-
// Keep a ref to the latest callbacks so the effect closure stays stable.
|
|
12
|
+
const [resolvedUrl, setResolvedUrl] = (0, react_1.useState)(null);
|
|
13
|
+
const [status, setStatus] = (0, react_1.useState)("loading");
|
|
57
14
|
const onResolveRef = (0, react_1.useRef)(onResolve);
|
|
58
15
|
const onErrorRef = (0, react_1.useRef)(onError);
|
|
59
16
|
const onStatusRef = (0, react_1.useRef)(onStatusChange);
|
|
60
17
|
onResolveRef.current = onResolve;
|
|
61
18
|
onErrorRef.current = onError;
|
|
62
19
|
onStatusRef.current = onStatusChange;
|
|
63
|
-
// Determine the key that uniquely identifies the requested file.
|
|
64
20
|
const fileKey = bucket && path ? `${bucket}::${path}` : src ?? null;
|
|
65
21
|
(0, react_1.useEffect)(() => {
|
|
66
|
-
// If we already resolved synchronously, notify callers and skip the
|
|
67
|
-
// async effect entirely — no extra network round-trip needed.
|
|
68
|
-
if (initialUrl) {
|
|
69
|
-
onResolveRef.current?.(initialUrl);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
22
|
if (!fileKey)
|
|
73
23
|
return;
|
|
74
24
|
let cancelled = false;
|
|
@@ -78,9 +28,7 @@ exports.StorageImage = (0, react_1.forwardRef)(function StorageImage({ storage,
|
|
|
78
28
|
try {
|
|
79
29
|
let url;
|
|
80
30
|
if (bucket && path) {
|
|
81
|
-
url = storage.bucket(bucket).ref(path).getDownloadURL
|
|
82
|
-
? await storage.bucket(bucket).ref(path).getDownloadURL()
|
|
83
|
-
: storage._directUrl(bucket, path);
|
|
31
|
+
url = await storage.bucket(bucket).ref(path).getDownloadURL();
|
|
84
32
|
}
|
|
85
33
|
else if (src) {
|
|
86
34
|
url = await storage.ref(src).getDownloadURL();
|
|
@@ -90,9 +38,11 @@ exports.StorageImage = (0, react_1.forwardRef)(function StorageImage({ storage,
|
|
|
90
38
|
}
|
|
91
39
|
if (cancelled)
|
|
92
40
|
return;
|
|
41
|
+
if (!url)
|
|
42
|
+
throw new Error("StorageImage: empty download URL returned.");
|
|
93
43
|
setResolvedUrl(url);
|
|
94
44
|
onResolveRef.current?.(url);
|
|
95
|
-
// status
|
|
45
|
+
// status → "loaded" fires in the <img> onLoad handler
|
|
96
46
|
}
|
|
97
47
|
catch (err) {
|
|
98
48
|
if (cancelled)
|
|
@@ -103,9 +53,7 @@ exports.StorageImage = (0, react_1.forwardRef)(function StorageImage({ storage,
|
|
|
103
53
|
}
|
|
104
54
|
};
|
|
105
55
|
resolve();
|
|
106
|
-
return () => {
|
|
107
|
-
cancelled = true;
|
|
108
|
-
};
|
|
56
|
+
return () => { cancelled = true; };
|
|
109
57
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
58
|
}, [fileKey]);
|
|
111
59
|
// ── Render helpers ────────────────────────────────────────────────────────
|
|
@@ -118,18 +66,17 @@ exports.StorageImage = (0, react_1.forwardRef)(function StorageImage({ storage,
|
|
|
118
66
|
onStatusRef.current?.("error");
|
|
119
67
|
onErrorRef.current?.(e);
|
|
120
68
|
};
|
|
121
|
-
//
|
|
69
|
+
// Placeholder while resolving
|
|
122
70
|
if (status === "loading" && !resolvedUrl) {
|
|
123
71
|
if (placeholder === undefined) {
|
|
124
|
-
// Invisible img keeps layout stable
|
|
125
72
|
return ((0, jsx_runtime_1.jsx)("img", { ...imgProps, ref: ref, src: "", alt: alt, style: { ...imgProps.style, visibility: "hidden" } }));
|
|
126
73
|
}
|
|
127
74
|
if (typeof placeholder === "string") {
|
|
128
|
-
return (
|
|
75
|
+
return (0, jsx_runtime_1.jsx)("img", { ...imgProps, ref: ref, src: placeholder, alt: alt });
|
|
129
76
|
}
|
|
130
77
|
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: placeholder });
|
|
131
78
|
}
|
|
132
|
-
//
|
|
79
|
+
// Fallback on error
|
|
133
80
|
if (status === "error" || !resolvedUrl) {
|
|
134
81
|
if (fallback === undefined) {
|
|
135
82
|
return ((0, jsx_runtime_1.jsx)("img", { ...imgProps, ref: ref, src: "", alt: alt, style: { ...imgProps.style, visibility: "hidden" } }));
|
|
@@ -139,10 +86,6 @@ exports.StorageImage = (0, react_1.forwardRef)(function StorageImage({ storage,
|
|
|
139
86
|
}
|
|
140
87
|
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: fallback });
|
|
141
88
|
}
|
|
142
|
-
// Resolved — render the real image.
|
|
143
|
-
// `loading="lazy"` defers off-screen fetches so the browser never
|
|
144
|
-
// saturates its per-host connection pool (typically 6) when many
|
|
145
|
-
// cards render simultaneously. Callers may override with loading="eager".
|
|
146
89
|
return ((0, jsx_runtime_1.jsx)("img", { loading: "lazy", ...imgProps, ref: ref, src: resolvedUrl, alt: alt, onLoad: handleLoad, onError: handleImgError }));
|
|
147
90
|
});
|
|
148
91
|
exports.StorageImage.displayName = "StorageImage";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageImage.js","sourceRoot":"","sources":["../../src/react/StorageImage.tsx"],"names":[],"mappings":";;;;AAAA,iCAMe;
|
|
1
|
+
{"version":3,"file":"StorageImage.js","sourceRoot":"","sources":["../../src/react/StorageImage.tsx"],"names":[],"mappings":";;;;AAAA,iCAMe;AAyBf,iFAAiF;AAEjF;;;GAGG;AACU,QAAA,YAAY,GAAG,IAAA,kBAAU,EACpC,SAAS,YAAY,CACnB,EACE,OAAO,EACP,GAAG,EACH,MAAM,EACN,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,SAAS,EACT,OAAO,EACP,cAAc,EACd,GAAG,GAAG,EAAE,EACR,GAAG,QAAQ,EACZ,EACD,GAAG;IAEH,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAgB,IAAI,CAAC,CAAC;IACpE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAqB,SAAS,CAAC,CAAC;IAEpE,MAAM,YAAY,GAAG,IAAA,cAAM,EAAC,SAAS,CAAC,CAAC;IACvC,MAAM,UAAU,GAAK,IAAA,cAAM,EAAC,OAAO,CAAC,CAAC;IACrC,MAAM,WAAW,GAAI,IAAA,cAAM,EAAC,cAAc,CAAC,CAAC;IAC5C,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;IACjC,UAAU,CAAC,OAAO,GAAK,OAAO,CAAC;IAC/B,WAAW,CAAC,OAAO,GAAI,cAAc,CAAC;IAEtC,MAAM,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC;IAEpE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,SAAS,CAAC,SAAS,CAAC,CAAC;QACrB,WAAW,CAAC,OAAO,EAAE,CAAC,S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GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;QAClE,CAAC;QACD,OAAO,2DAAG,QAAQ,GAAI,CAAC;IACzB,CAAC;IAED,OAAO,CACL,gCACE,OAAO,EAAC,MAAM,KACV,QAAQ,EACZ,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,cAAc,GACvB,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,oBAAY,CAAC,WAAW,GAAG,cAAc,CAAC;AAC1C,kBAAe,oBAAY,CAAC"}
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -13,78 +13,63 @@ export interface StorageFile {
|
|
|
13
13
|
/** Present on /resolve responses */
|
|
14
14
|
downloadUrl?: string;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
* A reference to a file at a given path inside a bucket.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* const ref = storage.ref("avatars/user-123.jpg");
|
|
21
|
-
* const url = await ref.getDownloadURL();
|
|
22
|
-
* await ref.delete();
|
|
23
|
-
*/
|
|
24
16
|
export declare class StorageReference {
|
|
25
17
|
private readonly storage;
|
|
26
18
|
readonly bucket: string;
|
|
27
19
|
readonly filePath: string;
|
|
28
20
|
constructor(storage: ClefbaseStorage, bucket: string, filePath: string);
|
|
29
|
-
/**
|
|
30
|
-
* Upload a file. Accepts Buffer (Node) or File/Blob (browser).
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* // Node.js
|
|
34
|
-
* await ref.upload(fs.readFileSync("photo.jpg"), { contentType: "image/jpeg" });
|
|
35
|
-
* // Browser
|
|
36
|
-
* await ref.upload(fileInput.files[0]);
|
|
37
|
-
*/
|
|
38
21
|
upload(data: Buffer | Blob | File, opts?: {
|
|
39
22
|
contentType?: string;
|
|
40
23
|
metadata?: Record<string, unknown>;
|
|
41
24
|
}): Promise<StorageFile>;
|
|
42
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Returns the authenticated download URL for this file.
|
|
27
|
+
* Always resolves via /storage/resolve to get the real bucketId + fileId.
|
|
28
|
+
*/
|
|
43
29
|
getDownloadURL(): Promise<string>;
|
|
44
|
-
/** Fetch file metadata including downloadUrl. */
|
|
45
30
|
getMetadata(): Promise<StorageFile>;
|
|
46
|
-
/** Delete this file. */
|
|
47
31
|
delete(): Promise<void>;
|
|
48
|
-
/** List files under this path prefix. */
|
|
49
32
|
list(opts?: {
|
|
50
33
|
limit?: number;
|
|
51
34
|
offset?: number;
|
|
52
35
|
}): Promise<StorageFile[]>;
|
|
53
36
|
}
|
|
54
|
-
/**
|
|
55
|
-
* A scoped helper for a named bucket.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* const ref = storage.bucket("user-uploads").ref("doc.pdf");
|
|
59
|
-
*/
|
|
60
37
|
export declare class BucketReference {
|
|
61
38
|
private readonly storage;
|
|
62
39
|
readonly name: string;
|
|
63
40
|
constructor(storage: ClefbaseStorage, name: string);
|
|
64
41
|
ref(filePath: string): StorageReference;
|
|
65
42
|
}
|
|
66
|
-
/**
|
|
67
|
-
* File storage service. Obtain via `getStorage(app)`.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* const storage = getStorage(app);
|
|
71
|
-
* const url = await storage.ref("products/image.jpg").getDownloadURL();
|
|
72
|
-
* await storage.bucket("media").ref("photo.jpg").upload(buffer, { contentType: "image/jpeg" });
|
|
73
|
-
*/
|
|
74
43
|
export declare class ClefbaseStorage {
|
|
75
44
|
private readonly http;
|
|
76
45
|
private readonly projectId;
|
|
77
46
|
private readonly auth;
|
|
78
|
-
|
|
47
|
+
/** @internal used by StorageImage — kept for compat but now returns empty string (no /path route exists) */
|
|
48
|
+
_defaultBucket: string;
|
|
49
|
+
/** In-memory cache: bucket name → UUID */
|
|
50
|
+
private _bucketIdCache;
|
|
51
|
+
/** In-memory cache: "bucket::filePath" → download URL */
|
|
52
|
+
private _urlCache;
|
|
79
53
|
constructor(http: HttpClient, projectId: string, auth?: Auth | null);
|
|
80
54
|
private authHeaders;
|
|
81
|
-
/** Override the default bucket name (default: "default"). */
|
|
82
55
|
setDefaultBucket(name: string): this;
|
|
83
|
-
/** Return a reference scoped to a named bucket. */
|
|
84
56
|
bucket(name: string): BucketReference;
|
|
85
|
-
/** Return a StorageReference in the default bucket. */
|
|
86
57
|
ref(filePath: string): StorageReference;
|
|
87
|
-
|
|
58
|
+
_resolveBucketId(bucketName: string): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Resolves a storage path to an authenticated download URL via
|
|
61
|
+
* GET /storage/resolve?projectId=xxx&path=bucketName/folder/file.jpg
|
|
62
|
+
*
|
|
63
|
+
* The server returns { downloadUrl, id, bucketId, ... } — we use downloadUrl directly.
|
|
64
|
+
* Results are cached so repeated calls (e.g. many cards) only hit the server once per path.
|
|
65
|
+
*/
|
|
66
|
+
_getDownloadURL(bucket: string, filePath: string): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated No /path route exists on the server.
|
|
69
|
+
* Kept so StorageImage's synchronous fast-path gracefully returns ""
|
|
70
|
+
* (which makes StorageImage fall through to the async resolve path).
|
|
71
|
+
*/
|
|
72
|
+
_directUrl(_bucket: string, _filePath: string): string;
|
|
88
73
|
_resolve(bucket: string, filePath: string): Promise<StorageFile>;
|
|
89
74
|
_upload(bucket: string, filePath: string, data: Buffer | Blob | File, opts?: {
|
|
90
75
|
contentType?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAIpC,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,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,CAAC;IAexE;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;IAIhD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAShE,OAAO,CACX,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAC1B,IAAI,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAClE,OAAO,CAAC,WAAW,CAAC;IA0CjB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxD,KAAK,CACT,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACzC,OAAO,CAAC,WAAW,EAAE,CAAC;CAY1B"}
|
package/dist/storage/index.js
CHANGED
|
@@ -35,57 +35,34 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ClefbaseStorage = exports.BucketReference = exports.StorageReference = void 0;
|
|
37
37
|
// ─── StorageReference ─────────────────────────────────────────────────────────
|
|
38
|
-
/**
|
|
39
|
-
* A reference to a file at a given path inside a bucket.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* const ref = storage.ref("avatars/user-123.jpg");
|
|
43
|
-
* const url = await ref.getDownloadURL();
|
|
44
|
-
* await ref.delete();
|
|
45
|
-
*/
|
|
46
38
|
class StorageReference {
|
|
47
39
|
constructor(storage, bucket, filePath) {
|
|
48
40
|
this.storage = storage;
|
|
49
41
|
this.bucket = bucket;
|
|
50
42
|
this.filePath = filePath;
|
|
51
43
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Upload a file. Accepts Buffer (Node) or File/Blob (browser).
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* // Node.js
|
|
57
|
-
* await ref.upload(fs.readFileSync("photo.jpg"), { contentType: "image/jpeg" });
|
|
58
|
-
* // Browser
|
|
59
|
-
* await ref.upload(fileInput.files[0]);
|
|
60
|
-
*/
|
|
61
44
|
async upload(data, opts) {
|
|
62
45
|
return this.storage._upload(this.bucket, this.filePath, data, opts);
|
|
63
46
|
}
|
|
64
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Returns the authenticated download URL for this file.
|
|
49
|
+
* Always resolves via /storage/resolve to get the real bucketId + fileId.
|
|
50
|
+
*/
|
|
65
51
|
async getDownloadURL() {
|
|
66
|
-
return this.storage.
|
|
52
|
+
return this.storage._getDownloadURL(this.bucket, this.filePath);
|
|
67
53
|
}
|
|
68
|
-
/** Fetch file metadata including downloadUrl. */
|
|
69
54
|
async getMetadata() {
|
|
70
55
|
return this.storage._resolve(this.bucket, this.filePath);
|
|
71
56
|
}
|
|
72
|
-
/** Delete this file. */
|
|
73
57
|
async delete() {
|
|
74
58
|
return this.storage._delete(this.bucket, this.filePath);
|
|
75
59
|
}
|
|
76
|
-
/** List files under this path prefix. */
|
|
77
60
|
async list(opts) {
|
|
78
61
|
return this.storage._list(this.bucket, this.filePath, opts);
|
|
79
62
|
}
|
|
80
63
|
}
|
|
81
64
|
exports.StorageReference = StorageReference;
|
|
82
65
|
// ─── BucketReference ──────────────────────────────────────────────────────────
|
|
83
|
-
/**
|
|
84
|
-
* A scoped helper for a named bucket.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* const ref = storage.bucket("user-uploads").ref("doc.pdf");
|
|
88
|
-
*/
|
|
89
66
|
class BucketReference {
|
|
90
67
|
constructor(storage, name) {
|
|
91
68
|
this.storage = storage;
|
|
@@ -97,48 +74,83 @@ class BucketReference {
|
|
|
97
74
|
}
|
|
98
75
|
exports.BucketReference = BucketReference;
|
|
99
76
|
// ─── ClefbaseStorage ──────────────────────────────────────────────────────────
|
|
100
|
-
/**
|
|
101
|
-
* File storage service. Obtain via `getStorage(app)`.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* const storage = getStorage(app);
|
|
105
|
-
* const url = await storage.ref("products/image.jpg").getDownloadURL();
|
|
106
|
-
* await storage.bucket("media").ref("photo.jpg").upload(buffer, { contentType: "image/jpeg" });
|
|
107
|
-
*/
|
|
108
77
|
class ClefbaseStorage {
|
|
109
78
|
constructor(http, projectId, auth = null) {
|
|
110
79
|
this.http = http;
|
|
111
80
|
this.projectId = projectId;
|
|
112
81
|
this.auth = auth;
|
|
82
|
+
/** @internal used by StorageImage — kept for compat but now returns empty string (no /path route exists) */
|
|
113
83
|
this._defaultBucket = "default";
|
|
84
|
+
/** In-memory cache: bucket name → UUID */
|
|
85
|
+
this._bucketIdCache = new Map();
|
|
86
|
+
/** In-memory cache: "bucket::filePath" → download URL */
|
|
87
|
+
this._urlCache = new Map();
|
|
114
88
|
}
|
|
115
89
|
authHeaders() {
|
|
116
90
|
return this.auth?.getAuthHeaders() ?? {};
|
|
117
91
|
}
|
|
118
|
-
/** Override the default bucket name (default: "default"). */
|
|
119
92
|
setDefaultBucket(name) {
|
|
120
93
|
this._defaultBucket = name;
|
|
121
94
|
return this;
|
|
122
95
|
}
|
|
123
|
-
/** Return a reference scoped to a named bucket. */
|
|
124
96
|
bucket(name) {
|
|
125
97
|
return new BucketReference(this, name);
|
|
126
98
|
}
|
|
127
|
-
/** Return a StorageReference in the default bucket. */
|
|
128
99
|
ref(filePath) {
|
|
129
100
|
return new StorageReference(this, this._defaultBucket, filePath.replace(/^\/+/, ""));
|
|
130
101
|
}
|
|
131
|
-
// ───
|
|
132
|
-
|
|
102
|
+
// ─── Bucket UUID resolution ───────────────────────────────────────────────
|
|
103
|
+
async _resolveBucketId(bucketName) {
|
|
104
|
+
const cached = this._bucketIdCache.get(bucketName);
|
|
105
|
+
if (cached)
|
|
106
|
+
return cached;
|
|
107
|
+
const buckets = await this.http.get("/buckets");
|
|
108
|
+
for (const b of buckets) {
|
|
109
|
+
this._bucketIdCache.set(b.name, b.id);
|
|
110
|
+
}
|
|
111
|
+
const id = this._bucketIdCache.get(bucketName);
|
|
112
|
+
if (!id)
|
|
113
|
+
throw new Error(`Storage bucket "${bucketName}" not found`);
|
|
114
|
+
return id;
|
|
115
|
+
}
|
|
116
|
+
// ─── Download URL ─────────────────────────────────────────────────────────
|
|
117
|
+
/**
|
|
118
|
+
* Resolves a storage path to an authenticated download URL via
|
|
119
|
+
* GET /storage/resolve?projectId=xxx&path=bucketName/folder/file.jpg
|
|
120
|
+
*
|
|
121
|
+
* The server returns { downloadUrl, id, bucketId, ... } — we use downloadUrl directly.
|
|
122
|
+
* Results are cached so repeated calls (e.g. many cards) only hit the server once per path.
|
|
123
|
+
*/
|
|
124
|
+
async _getDownloadURL(bucket, filePath) {
|
|
133
125
|
const cleanFile = filePath.replace(/^\/+/, "");
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
// The resolve endpoint expects the full path including bucket name
|
|
127
|
+
const fullPath = `${bucket}/${cleanFile}`;
|
|
128
|
+
const cacheKey = fullPath;
|
|
129
|
+
const cached = this._urlCache.get(cacheKey);
|
|
130
|
+
if (cached)
|
|
131
|
+
return cached;
|
|
132
|
+
const meta = await this._resolve(bucket, cleanFile);
|
|
133
|
+
const url = meta.downloadUrl ?? "";
|
|
134
|
+
if (url)
|
|
135
|
+
this._urlCache.set(cacheKey, url);
|
|
136
|
+
return url;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated No /path route exists on the server.
|
|
140
|
+
* Kept so StorageImage's synchronous fast-path gracefully returns ""
|
|
141
|
+
* (which makes StorageImage fall through to the async resolve path).
|
|
142
|
+
*/
|
|
143
|
+
_directUrl(_bucket, _filePath) {
|
|
144
|
+
return "";
|
|
136
145
|
}
|
|
137
146
|
async _resolve(bucket, filePath) {
|
|
138
147
|
const cleanFile = filePath.replace(/^\/+/, "");
|
|
139
|
-
|
|
148
|
+
// The resolve endpoint matches by fullPath = "bucketName/folder/file.jpg"
|
|
149
|
+
const fullPath = `${bucket}/${cleanFile}`;
|
|
150
|
+
return this.http.get(`/resolve?projectId=${encodeURIComponent(this.projectId)}&path=${encodeURIComponent(fullPath)}`);
|
|
140
151
|
}
|
|
141
152
|
async _upload(bucket, filePath, data, opts) {
|
|
153
|
+
const bucketId = await this._resolveBucketId(bucket);
|
|
142
154
|
let FormDataImpl;
|
|
143
155
|
if (typeof FormData !== "undefined") {
|
|
144
156
|
FormDataImpl = FormData;
|
|
@@ -147,15 +159,11 @@ class ClefbaseStorage {
|
|
|
147
159
|
const mod = await Promise.resolve().then(() => __importStar(require("form-data")));
|
|
148
160
|
FormDataImpl = mod.default;
|
|
149
161
|
}
|
|
150
|
-
const form = new FormDataImpl();
|
|
151
162
|
const cleanPath = filePath.replace(/^\/+/, "");
|
|
152
163
|
const filename = cleanPath.split("/").pop() ?? "upload";
|
|
153
164
|
const parts = cleanPath.split("/");
|
|
154
165
|
const folder = parts.length > 1 ? parts.slice(0, -1).join("/") : undefined;
|
|
155
|
-
|
|
156
|
-
// resolve the correct project database and bucket UUID. ──────────
|
|
157
|
-
form.append("projectId", this.projectId);
|
|
158
|
-
form.append("bucketName", bucket);
|
|
166
|
+
const form = new FormDataImpl();
|
|
159
167
|
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
|
|
160
168
|
form.append("file", data, { filename, contentType: opts?.contentType ?? "application/octet-stream" });
|
|
161
169
|
}
|
|
@@ -166,9 +174,10 @@ class ClefbaseStorage {
|
|
|
166
174
|
form.append("folder", folder);
|
|
167
175
|
if (opts?.metadata)
|
|
168
176
|
form.append("metadata", JSON.stringify(opts.metadata));
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
177
|
+
// Bust the URL cache for this path so a fresh URL is fetched after upload
|
|
178
|
+
const cacheKey = `${bucket}/${cleanPath}`;
|
|
179
|
+
this._urlCache.delete(cacheKey);
|
|
180
|
+
return this.http.request(`/buckets/${bucketId}/files`, {
|
|
172
181
|
method: "POST",
|
|
173
182
|
body: form,
|
|
174
183
|
isFormData: true,
|
|
@@ -176,18 +185,22 @@ class ClefbaseStorage {
|
|
|
176
185
|
});
|
|
177
186
|
}
|
|
178
187
|
async _delete(bucket, filePath) {
|
|
188
|
+
const bucketId = await this._resolveBucketId(bucket);
|
|
179
189
|
const meta = await this._resolve(bucket, filePath);
|
|
180
|
-
|
|
190
|
+
this._urlCache.delete(`${bucket}/${filePath.replace(/^\/+/, "")}`);
|
|
191
|
+
await this.http.delete(`/buckets/${bucketId}/files/${meta.id}`, this.authHeaders());
|
|
181
192
|
}
|
|
182
193
|
async _list(bucket, prefix, opts) {
|
|
183
|
-
const
|
|
194
|
+
const bucketId = await this._resolveBucketId(bucket);
|
|
195
|
+
const qs = new URLSearchParams();
|
|
184
196
|
if (prefix)
|
|
185
197
|
qs.set("folder", prefix);
|
|
186
198
|
if (opts?.limit !== undefined)
|
|
187
199
|
qs.set("limit", String(opts.limit));
|
|
188
200
|
if (opts?.offset !== undefined)
|
|
189
201
|
qs.set("offset", String(opts.offset));
|
|
190
|
-
const
|
|
202
|
+
const query = qs.toString() ? `?${qs}` : "";
|
|
203
|
+
const result = await this.http.get(`/buckets/${bucketId}/files${query}`);
|
|
191
204
|
return Array.isArray(result) ? result : result.data;
|
|
192
205
|
}
|
|
193
206
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,iFAAiF;AAEjF
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":";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