@ai-matrx/data 0.18.1 → 0.18.3
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/CHANGELOG.md +14 -0
- package/dist/db.cjs +3 -3
- package/dist/db.cjs.map +1 -1
- package/dist/db.js +3 -3
- package/dist/db.js.map +1 -1
- package/dist/files.cjs +23 -15
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.cts +28 -8
- package/dist/files.d.ts +28 -8
- package/dist/files.js +23 -15
- package/dist/files.js.map +1 -1
- package/package.json +2 -1
package/dist/files.d.ts
CHANGED
|
@@ -74,11 +74,23 @@ interface FilesBlobHandle {
|
|
|
74
74
|
/** Release the handle. Cache-backed handles no-op (the cache owns the URL). */
|
|
75
75
|
release(): void;
|
|
76
76
|
}
|
|
77
|
+
/** `platform.shown_to`: a list filter, never row security (access ladder T-13). */
|
|
78
|
+
type FileShownTo = "only_me" | "my_team" | "everyone" | "everyone_on_ai_matrx";
|
|
77
79
|
interface MediaUploadOptions {
|
|
78
80
|
onProgress?: ((loaded: number, total: number) => void) | undefined;
|
|
79
81
|
fileName?: string | undefined;
|
|
80
82
|
mimeType?: string | undefined;
|
|
81
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Publish the upload to the web (the only anonymous lane; access ladder T-13).
|
|
85
|
+
* Omitted = not published.
|
|
86
|
+
*/
|
|
87
|
+
publishedToWeb?: boolean | undefined;
|
|
88
|
+
/** The "Shown to" list filter; omitted = only me (the upload default). */
|
|
89
|
+
shownTo?: FileShownTo | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* The retiring level word (`personal` | `internal` | `link` | `public`), read only when
|
|
92
|
+
* neither word above is given; hosts move to the two words.
|
|
93
|
+
*/
|
|
82
94
|
visibility?: string | undefined;
|
|
83
95
|
/**
|
|
84
96
|
* Host-side folder identity. The wire contract addresses folders by PATH
|
|
@@ -135,7 +147,8 @@ interface FileUploadResponseWire {
|
|
|
135
147
|
url?: string | null;
|
|
136
148
|
cdn_url?: string | null;
|
|
137
149
|
download_url?: string | null;
|
|
138
|
-
|
|
150
|
+
published_to_web?: boolean;
|
|
151
|
+
shown_to?: string | null;
|
|
139
152
|
}
|
|
140
153
|
/**
|
|
141
154
|
* `GET /files/{id}` response (`FileRecord`) — the subset this lane reads.
|
|
@@ -145,7 +158,8 @@ interface FileRecordWire {
|
|
|
145
158
|
id: string;
|
|
146
159
|
file_name?: string | null;
|
|
147
160
|
mime_type?: string | null;
|
|
148
|
-
|
|
161
|
+
published_to_web?: boolean | null;
|
|
162
|
+
shown_to?: string | null;
|
|
149
163
|
deleted_at?: string | null;
|
|
150
164
|
public_url?: string | null;
|
|
151
165
|
thumbnail_url?: string | null;
|
|
@@ -171,7 +185,8 @@ interface ShareLinkRecordWire {
|
|
|
171
185
|
/** The per-file metadata this lane renders transport decisions from. */
|
|
172
186
|
interface FileMetadata {
|
|
173
187
|
mimeType?: string | null;
|
|
174
|
-
|
|
188
|
+
/** True only when the file is published to the web (its CDN URL is anonymous). */
|
|
189
|
+
publishedToWeb?: boolean | null;
|
|
175
190
|
cdnUrl?: string | null;
|
|
176
191
|
publicUrl?: string | null;
|
|
177
192
|
thumbnailUrl?: string | null;
|
|
@@ -179,7 +194,7 @@ interface FileMetadata {
|
|
|
179
194
|
fileName?: string | null;
|
|
180
195
|
}
|
|
181
196
|
/**
|
|
182
|
-
* Where `resolve()` reads per-file metadata (
|
|
197
|
+
* Where `resolve()` reads per-file metadata (published to the web → CDN vs blob lane,
|
|
183
198
|
* mime, thumbnail). `peek` is synchronous and render-safe; `hydrate` may hit
|
|
184
199
|
* the network/store. DEFAULT: an in-client cache over `GET /files/{id}`.
|
|
185
200
|
* A host with its own file store (Redux, Supabase reads) overrides this port
|
|
@@ -353,8 +368,6 @@ declare function mimeFromUrl(url: string): string | null;
|
|
|
353
368
|
* shown as one.
|
|
354
369
|
*/
|
|
355
370
|
declare function fileNameFromUrl(url: string): string | null;
|
|
356
|
-
/** True when the string is a bare cld_files UUID (a fileId, not a URL). */
|
|
357
|
-
declare function isFileIdString(value: string): boolean;
|
|
358
371
|
interface FileUrls {
|
|
359
372
|
/** Authenticated direct-download endpoint (`Content-Disposition: attachment`). */
|
|
360
373
|
download: string;
|
|
@@ -524,6 +537,13 @@ interface MatrxFilesClient<TSrc extends string = DurableSrc> {
|
|
|
524
537
|
* Persistent tiers (IndexedDB, the service worker) stay host-injected.
|
|
525
538
|
*/
|
|
526
539
|
declare function createMemoryBlobCache(budgetBytes?: number): BlobCachePort;
|
|
540
|
+
/**
|
|
541
|
+
* The upload's row-access form fields (access ladder T-13). The two words are written
|
|
542
|
+
* explicitly on every upload — never left to a server default: not published, shown to
|
|
543
|
+
* only me, unless the caller says otherwise. A caller still on the retiring level word
|
|
544
|
+
* is translated here, once.
|
|
545
|
+
*/
|
|
546
|
+
declare function uploadAccessFields(opts: MediaUploadOptions): Record<string, string>;
|
|
527
547
|
declare function createMatrxFilesClient<TSrc extends string = DurableSrc>(config: MatrxFilesClientConfig): MatrxFilesClient<TSrc>;
|
|
528
548
|
|
|
529
549
|
/**
|
|
@@ -663,4 +683,4 @@ interface FilesSession {
|
|
|
663
683
|
}
|
|
664
684
|
declare function createFilesSession(options: FilesSessionOptions): FilesSession;
|
|
665
685
|
|
|
666
|
-
export { type BlobCacheEntry, type BlobCachePort, type DurableSrc, ExternalFetchError, FileAccessDeniedError, FileDeletedError, FileError, type FileErrorCode, type FileMetadata, type FileMetadataPort, FileNotFoundError, type FileOrigins, type FileRecordWire, type FileSessionResponseWire, FileUploadError, type FileUploadResponseWire, type FileUrlRecognizer, type FileUrls, type FilesBlobHandle, type FilesDiagnosticsEvent, type FilesDiagnosticsSink, type FilesRecoveryReport, type FilesRecoveryVerdict, type FilesResolution, type FilesSession, type FilesSessionOptions, type FilesSessionSnapshot, type MatrxFilesClient, type MatrxFilesClientConfig, type MediaKind, type MediaMultiUploadResult, type MediaRef, type MediaRefLike, type MediaUnavailableReason, type MediaUploadOptions, type MediaUploadResult, type MediaUrlKind, SIGNED_URL_RE, ShareLinkInvalidError, type ShareLinkRecordWire, TUS_TRANSPORT_THRESHOLD_BYTES, type UploadTransport, classifyMediaUrl, classifyUnavailable, createFileUrlRecognizer, createFilesSession, createMatrxFilesClient, createMemoryBlobCache, fileErrorFromStatus, fileNameFromUrl, fileUrls, isDurableMediaUrl,
|
|
686
|
+
export { type BlobCacheEntry, type BlobCachePort, type DurableSrc, ExternalFetchError, FileAccessDeniedError, FileDeletedError, FileError, type FileErrorCode, type FileMetadata, type FileMetadataPort, FileNotFoundError, type FileOrigins, type FileRecordWire, type FileSessionResponseWire, type FileShownTo, FileUploadError, type FileUploadResponseWire, type FileUrlRecognizer, type FileUrls, type FilesBlobHandle, type FilesDiagnosticsEvent, type FilesDiagnosticsSink, type FilesRecoveryReport, type FilesRecoveryVerdict, type FilesResolution, type FilesSession, type FilesSessionOptions, type FilesSessionSnapshot, type MatrxFilesClient, type MatrxFilesClientConfig, type MediaKind, type MediaMultiUploadResult, type MediaRef, type MediaRefLike, type MediaUnavailableReason, type MediaUploadOptions, type MediaUploadResult, type MediaUrlKind, SIGNED_URL_RE, ShareLinkInvalidError, type ShareLinkRecordWire, TUS_TRANSPORT_THRESHOLD_BYTES, type UploadTransport, classifyMediaUrl, classifyUnavailable, createFileUrlRecognizer, createFilesSession, createMatrxFilesClient, createMemoryBlobCache, fileErrorFromStatus, fileNameFromUrl, fileUrls, isDurableMediaUrl, isSignedUrl, mimeFromUrl, resolveUploadTransport, shareUrl, shareableMediaUrl, uploadAccessFields };
|
package/dist/files.js
CHANGED
|
@@ -92,7 +92,7 @@ function classifyUnavailable(err) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// src/files/recognize.ts
|
|
95
|
-
|
|
95
|
+
import { isUuidShape } from "@ai-matrx/kit/uuid";
|
|
96
96
|
var SIGNED_URL_RE = /[?&](x-amz-signature|x-amz-credential|x-amz-date|x-amz-expires|awsaccesskeyid|signature|expires)=/i;
|
|
97
97
|
function isSignedUrl(url) {
|
|
98
98
|
if (!url) return false;
|
|
@@ -131,14 +131,14 @@ function createFileUrlRecognizer(origins = {}) {
|
|
|
131
131
|
if (!u || !endpointHosts.test(u.hostname)) return null;
|
|
132
132
|
const m = u.pathname.match(FILE_ENDPOINT_PATH_RE);
|
|
133
133
|
const candidate = m ? m[1] ?? m[2] : null;
|
|
134
|
-
return candidate &&
|
|
134
|
+
return candidate && isUuidShape(candidate) ? candidate : null;
|
|
135
135
|
}
|
|
136
136
|
function fileIdFromUserFilesUrl(url) {
|
|
137
137
|
const u = parse(url);
|
|
138
138
|
if (!u || !userFilesHosts.test(u.hostname)) return null;
|
|
139
139
|
const segs = u.pathname.split("/").filter(Boolean);
|
|
140
140
|
const candidate = segs[1] ?? segs[segs.length - 1];
|
|
141
|
-
return candidate &&
|
|
141
|
+
return candidate && isUuidShape(candidate) ? candidate : null;
|
|
142
142
|
}
|
|
143
143
|
function looksLikeCdnUrl(url) {
|
|
144
144
|
const u = parse(url);
|
|
@@ -197,9 +197,6 @@ function fileNameFromUrl(url) {
|
|
|
197
197
|
if (!last || !/\.[a-z0-9]{1,5}$/i.test(last)) return null;
|
|
198
198
|
return decodeURIComponent(last);
|
|
199
199
|
}
|
|
200
|
-
function isFileIdString(value) {
|
|
201
|
-
return UUID_RE.test(value);
|
|
202
|
-
}
|
|
203
200
|
function fileUrls(filesBaseUrl, fileId) {
|
|
204
201
|
const id = encodeURIComponent(fileId);
|
|
205
202
|
const base = `${filesBaseUrl.replace(/\/$/, "")}/files/${id}/download`;
|
|
@@ -209,6 +206,9 @@ function shareUrl(filesBaseUrl, token) {
|
|
|
209
206
|
return `${filesBaseUrl.replace(/\/$/, "")}/share/${encodeURIComponent(token)}`;
|
|
210
207
|
}
|
|
211
208
|
|
|
209
|
+
// src/files/client.ts
|
|
210
|
+
import { isUuidShape as isUuidShape2 } from "@ai-matrx/kit/uuid";
|
|
211
|
+
|
|
212
212
|
// src/files/session.ts
|
|
213
213
|
var REFRESH_SAFETY_MARGIN_MS = 60 * 60 * 1e3;
|
|
214
214
|
function createFilesSession(options) {
|
|
@@ -529,10 +529,18 @@ function createMemoryBlobCache(budgetBytes = DEFAULT_BLOB_BUDGET_BYTES) {
|
|
|
529
529
|
}
|
|
530
530
|
};
|
|
531
531
|
}
|
|
532
|
+
function uploadAccessFields(opts) {
|
|
533
|
+
const legacy = opts.visibility;
|
|
534
|
+
const published = opts.publishedToWeb ?? (legacy === void 0 ? false : legacy === "public");
|
|
535
|
+
const shownTo = opts.shownTo ?? (opts.publishedToWeb !== void 0 || legacy === void 0 || legacy === "personal" ? "only_me" : null);
|
|
536
|
+
const fields = { published_to_web: String(published) };
|
|
537
|
+
if (shownTo) fields.shown_to = shownTo;
|
|
538
|
+
return fields;
|
|
539
|
+
}
|
|
532
540
|
function recordToMetadata(record) {
|
|
533
541
|
return {
|
|
534
542
|
mimeType: record.mime_type ?? null,
|
|
535
|
-
|
|
543
|
+
publishedToWeb: record.published_to_web ?? null,
|
|
536
544
|
cdnUrl: record.cdn_url ?? null,
|
|
537
545
|
publicUrl: record.public_url ?? null,
|
|
538
546
|
thumbnailUrl: record.thumbnail_url ?? null,
|
|
@@ -656,7 +664,7 @@ function createMatrxFilesClient(config) {
|
|
|
656
664
|
function normalizeRef(ref) {
|
|
657
665
|
if (!ref) return null;
|
|
658
666
|
if (typeof ref === "string") {
|
|
659
|
-
if (
|
|
667
|
+
if (isUuidShape2(ref)) return { kind: "file_id", fileId: ref, mime: null };
|
|
660
668
|
if (!ref.trim()) return null;
|
|
661
669
|
return normalizeUrl(ref, null);
|
|
662
670
|
}
|
|
@@ -706,7 +714,7 @@ function createMatrxFilesClient(config) {
|
|
|
706
714
|
return response.blob();
|
|
707
715
|
}
|
|
708
716
|
async function fileIdBlob(fileId) {
|
|
709
|
-
if (!
|
|
717
|
+
if (!isUuidShape2(fileId)) {
|
|
710
718
|
throw new FileError(
|
|
711
719
|
"internal",
|
|
712
720
|
`getBlob: "${fileId}" is not a cld_files id \u2014 host-namespaced/virtual ids are resolved by the host before this client.`,
|
|
@@ -832,7 +840,7 @@ function createMatrxFilesClient(config) {
|
|
|
832
840
|
const form = new FormData();
|
|
833
841
|
form.append("file", asFile);
|
|
834
842
|
form.append("file_path", `${folder}/${asFile.name}`);
|
|
835
|
-
form.append(
|
|
843
|
+
for (const [key, value] of Object.entries(uploadAccessFields(opts))) form.append(key, value);
|
|
836
844
|
if (opts.metadata) form.append("metadata_json", JSON.stringify(opts.metadata));
|
|
837
845
|
const response = await postMultipart(form, opts, newRequestId());
|
|
838
846
|
if (!response.file_id) {
|
|
@@ -862,7 +870,7 @@ function createMatrxFilesClient(config) {
|
|
|
862
870
|
return { uploaded, failed, cancelled: false };
|
|
863
871
|
}
|
|
864
872
|
function permanentPublicUrl(meta) {
|
|
865
|
-
if (meta?.
|
|
873
|
+
if (meta?.publishedToWeb !== true) return null;
|
|
866
874
|
const candidate = shareableMediaUrl(meta.cdnUrl ?? meta.publicUrl ?? null);
|
|
867
875
|
if (!candidate) return null;
|
|
868
876
|
return recognizer.fileIdFromFileEndpointUrl(candidate) ? null : candidate;
|
|
@@ -933,7 +941,7 @@ function createMatrxFilesClient(config) {
|
|
|
933
941
|
}
|
|
934
942
|
const { fileId } = norm;
|
|
935
943
|
const meta = metadata.peek(fileId);
|
|
936
|
-
if (
|
|
944
|
+
if (isUuidShape2(fileId)) scheduleHydration(fileId);
|
|
937
945
|
const mime = norm.mime ?? meta?.mimeType ?? null;
|
|
938
946
|
const kind = mimeToKind(mime);
|
|
939
947
|
const thumbRaw = meta?.thumbnailUrl ?? null;
|
|
@@ -1046,7 +1054,7 @@ function createMatrxFilesClient(config) {
|
|
|
1046
1054
|
if (!norm) return null;
|
|
1047
1055
|
if (norm.kind === "url") return shareableMediaUrl(norm.url);
|
|
1048
1056
|
const { fileId } = norm;
|
|
1049
|
-
if (!
|
|
1057
|
+
if (!isUuidShape2(fileId)) return null;
|
|
1050
1058
|
const meta = await metadata.hydrate(fileId);
|
|
1051
1059
|
const permanent = permanentPublicUrl(meta);
|
|
1052
1060
|
if (permanent) return permanent;
|
|
@@ -1091,11 +1099,11 @@ export {
|
|
|
1091
1099
|
fileNameFromUrl,
|
|
1092
1100
|
fileUrls,
|
|
1093
1101
|
isDurableMediaUrl,
|
|
1094
|
-
isFileIdString,
|
|
1095
1102
|
isSignedUrl,
|
|
1096
1103
|
mimeFromUrl,
|
|
1097
1104
|
resolveUploadTransport,
|
|
1098
1105
|
shareUrl,
|
|
1099
|
-
shareableMediaUrl
|
|
1106
|
+
shareableMediaUrl,
|
|
1107
|
+
uploadAccessFields
|
|
1100
1108
|
};
|
|
1101
1109
|
//# sourceMappingURL=files.js.map
|