@bunbase-ae/js 2.15.1-next.355.83a242f → 2.16.1-next.361.cc33a92
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/package.json +1 -1
- package/src/admin.ts +43 -1
package/package.json
CHANGED
package/src/admin.ts
CHANGED
|
@@ -182,6 +182,12 @@ export interface AdminStoredFile {
|
|
|
182
182
|
record_id: string | null;
|
|
183
183
|
owner_id: string | null;
|
|
184
184
|
owner_email?: string | null;
|
|
185
|
+
/**
|
|
186
|
+
* Tenant the file was uploaded under. `null` for admin uploads and
|
|
187
|
+
* pre-#536 rows; operators can attach a legacy null row to a tenant via
|
|
188
|
+
* `client.admin.storage.assignTenant(id, tenantId)`.
|
|
189
|
+
*/
|
|
190
|
+
tenant_id: string | null;
|
|
185
191
|
size: number;
|
|
186
192
|
mime_type: string;
|
|
187
193
|
is_public: boolean;
|
|
@@ -831,17 +837,53 @@ class AdminRelationsClient {
|
|
|
831
837
|
}
|
|
832
838
|
}
|
|
833
839
|
|
|
840
|
+
/**
|
|
841
|
+
* Sentinel querystring value for the `?tenant_id=` admin storage filter that
|
|
842
|
+
* matches `_files.tenant_id IS NULL` — the bucket of admin uploads and
|
|
843
|
+
* pre-#536 rows. Mirrors `_global` from the sequences admin routes (#537).
|
|
844
|
+
*/
|
|
845
|
+
const STORAGE_GLOBAL_TENANT_SENTINEL = "_global";
|
|
846
|
+
|
|
834
847
|
class AdminStorageClient {
|
|
835
848
|
constructor(private readonly http: HttpClient) {}
|
|
836
849
|
|
|
837
|
-
|
|
850
|
+
/**
|
|
851
|
+
* List admin-visible files, optionally scoped to a tenant.
|
|
852
|
+
*
|
|
853
|
+
* - omit `tenantId` → all files (no tenant filter, the legacy behavior).
|
|
854
|
+
* - pass a tenant id string → only that tenant's files.
|
|
855
|
+
* - pass `null` → only global / pre-#536 rows (the rows operators need to
|
|
856
|
+
* migrate when upgrading past v2.14.3).
|
|
857
|
+
*/
|
|
858
|
+
async listFiles(opts: { tenantId?: string | null } = {}): Promise<AdminStoredFile[]> {
|
|
859
|
+
const query: Record<string, string> = {};
|
|
860
|
+
if (opts.tenantId === null) {
|
|
861
|
+
query.tenant_id = STORAGE_GLOBAL_TENANT_SENTINEL;
|
|
862
|
+
} else if (typeof opts.tenantId === "string" && opts.tenantId !== "") {
|
|
863
|
+
query.tenant_id = opts.tenantId;
|
|
864
|
+
}
|
|
838
865
|
const res = await this.http.request<{ items: AdminStoredFile[] }>(
|
|
839
866
|
"GET",
|
|
840
867
|
"/api/v1/admin/storage",
|
|
868
|
+
Object.keys(query).length ? { query } : undefined,
|
|
841
869
|
);
|
|
842
870
|
return res.items;
|
|
843
871
|
}
|
|
844
872
|
|
|
873
|
+
/**
|
|
874
|
+
* Attach a file to a tenant (or unscope it). Used to migrate legacy
|
|
875
|
+
* admin uploads (pre-#536, `tenant_id IS NULL`) into a tenant context so
|
|
876
|
+
* tenant members can list/download/delete them under the post-#528 rules.
|
|
877
|
+
* Pass `null` to clear the assignment.
|
|
878
|
+
*/
|
|
879
|
+
async assignTenant(id: string, tenantId: string | null): Promise<AdminStoredFile> {
|
|
880
|
+
return this.http.request<AdminStoredFile>(
|
|
881
|
+
"PATCH",
|
|
882
|
+
`/api/v1/admin/storage/${encodeURIComponent(id)}/tenant`,
|
|
883
|
+
{ body: { tenant_id: tenantId } },
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
|
|
845
887
|
async uploadFile(params: {
|
|
846
888
|
file: File | Blob;
|
|
847
889
|
filename?: string;
|