@tspvivek/baasix-sdk 0.1.0-alpha.1

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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +942 -0
  3. package/dist/client-CzF9B60b.d.ts +614 -0
  4. package/dist/client-aXK_gEyr.d.cts +614 -0
  5. package/dist/index.cjs +4159 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +1498 -0
  8. package/dist/index.d.ts +1498 -0
  9. package/dist/index.js +4135 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/modules/auth.cjs +651 -0
  12. package/dist/modules/auth.cjs.map +1 -0
  13. package/dist/modules/auth.d.cts +384 -0
  14. package/dist/modules/auth.d.ts +384 -0
  15. package/dist/modules/auth.js +649 -0
  16. package/dist/modules/auth.js.map +1 -0
  17. package/dist/modules/files.cjs +266 -0
  18. package/dist/modules/files.cjs.map +1 -0
  19. package/dist/modules/files.d.cts +187 -0
  20. package/dist/modules/files.d.ts +187 -0
  21. package/dist/modules/files.js +264 -0
  22. package/dist/modules/files.js.map +1 -0
  23. package/dist/modules/items.cjs +654 -0
  24. package/dist/modules/items.cjs.map +1 -0
  25. package/dist/modules/items.d.cts +472 -0
  26. package/dist/modules/items.d.ts +472 -0
  27. package/dist/modules/items.js +651 -0
  28. package/dist/modules/items.js.map +1 -0
  29. package/dist/modules/schemas.cjs +269 -0
  30. package/dist/modules/schemas.cjs.map +1 -0
  31. package/dist/modules/schemas.d.cts +239 -0
  32. package/dist/modules/schemas.d.ts +239 -0
  33. package/dist/modules/schemas.js +267 -0
  34. package/dist/modules/schemas.js.map +1 -0
  35. package/dist/storage/index.cjs +162 -0
  36. package/dist/storage/index.cjs.map +1 -0
  37. package/dist/storage/index.d.cts +96 -0
  38. package/dist/storage/index.d.ts +96 -0
  39. package/dist/storage/index.js +157 -0
  40. package/dist/storage/index.js.map +1 -0
  41. package/dist/types-BdjsGANq.d.cts +40 -0
  42. package/dist/types-BdjsGANq.d.ts +40 -0
  43. package/package.json +107 -0
@@ -0,0 +1,187 @@
1
+ import { H as HttpClient, i as UploadOptions, j as FileMetadata, Q as QueryParams, e as PaginatedResponse, k as AssetTransformOptions } from '../client-CzF9B60b.js';
2
+ import '../types-BdjsGANq.js';
3
+
4
+ interface FilesModuleConfig {
5
+ client: HttpClient;
6
+ }
7
+ /**
8
+ * Files module for file upload, management, and asset transformations.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Upload a file
13
+ * const file = await baasix.files.upload(fileInput.files[0], {
14
+ * title: 'My Image',
15
+ * isPublic: true
16
+ * });
17
+ *
18
+ * // Get asset URL with transformations
19
+ * const url = baasix.files.getAssetUrl(file.id, {
20
+ * width: 200,
21
+ * height: 200,
22
+ * fit: 'cover'
23
+ * });
24
+ * ```
25
+ */
26
+ declare class FilesModule {
27
+ private client;
28
+ constructor(config: FilesModuleConfig);
29
+ /**
30
+ * Upload a file
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Browser File API
35
+ * const metadata = await baasix.files.upload(fileInput.files[0], {
36
+ * title: 'Product Image',
37
+ * folder: 'products',
38
+ * isPublic: true,
39
+ * onProgress: (progress) => console.log(`${progress}% uploaded`)
40
+ * });
41
+ *
42
+ * // React Native with expo-image-picker
43
+ * const metadata = await baasix.files.upload({
44
+ * uri: result.uri,
45
+ * name: 'photo.jpg',
46
+ * type: 'image/jpeg'
47
+ * });
48
+ * ```
49
+ */
50
+ upload(file: File | Blob | {
51
+ uri: string;
52
+ name: string;
53
+ type: string;
54
+ }, options?: UploadOptions): Promise<FileMetadata>;
55
+ /**
56
+ * Upload multiple files
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const files = await baasix.files.uploadMany(fileInput.files, {
61
+ * folder: 'gallery',
62
+ * isPublic: true
63
+ * });
64
+ * ```
65
+ */
66
+ uploadMany(files: FileList | File[] | Array<{
67
+ uri: string;
68
+ name: string;
69
+ type: string;
70
+ }>, options?: Omit<UploadOptions, "onProgress">): Promise<FileMetadata[]>;
71
+ /**
72
+ * List files with optional filtering
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const { data, totalCount } = await baasix.files.find({
77
+ * filter: { mimeType: { startsWith: 'image/' } },
78
+ * limit: 20
79
+ * });
80
+ * ```
81
+ */
82
+ find(params?: QueryParams): Promise<PaginatedResponse<FileMetadata>>;
83
+ /**
84
+ * Get file metadata by ID
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const file = await baasix.files.findOne('file-uuid');
89
+ * console.log(file.filename, file.size);
90
+ * ```
91
+ */
92
+ findOne(id: string): Promise<FileMetadata>;
93
+ /**
94
+ * Update file metadata
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * await baasix.files.update('file-uuid', {
99
+ * title: 'Updated Title',
100
+ * description: 'New description'
101
+ * });
102
+ * ```
103
+ */
104
+ update(id: string, data: Partial<Pick<FileMetadata, "title" | "description" | "isPublic">>): Promise<FileMetadata>;
105
+ /**
106
+ * Delete a file
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * await baasix.files.delete('file-uuid');
111
+ * ```
112
+ */
113
+ delete(id: string): Promise<void>;
114
+ /**
115
+ * Delete multiple files
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * await baasix.files.deleteMany(['id1', 'id2', 'id3']);
120
+ * ```
121
+ */
122
+ deleteMany(ids: string[]): Promise<void>;
123
+ /**
124
+ * Get the URL for an asset with optional transformations
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Original file
129
+ * const url = baasix.files.getAssetUrl('file-uuid');
130
+ *
131
+ * // Resized thumbnail
132
+ * const thumbUrl = baasix.files.getAssetUrl('file-uuid', {
133
+ * width: 200,
134
+ * height: 200,
135
+ * fit: 'cover',
136
+ * quality: 80
137
+ * });
138
+ *
139
+ * // Convert to WebP
140
+ * const webpUrl = baasix.files.getAssetUrl('file-uuid', {
141
+ * format: 'webp',
142
+ * quality: 85
143
+ * });
144
+ * ```
145
+ */
146
+ getAssetUrl(id: string, options?: AssetTransformOptions): string;
147
+ /**
148
+ * Download a file as a Blob
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const blob = await baasix.files.download('file-uuid');
153
+ *
154
+ * // Create download link
155
+ * const url = URL.createObjectURL(blob);
156
+ * const a = document.createElement('a');
157
+ * a.href = url;
158
+ * a.download = 'filename.pdf';
159
+ * a.click();
160
+ * ```
161
+ */
162
+ download(id: string, options?: AssetTransformOptions): Promise<Blob>;
163
+ /**
164
+ * Get file as base64 string (useful for React Native)
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * const base64 = await baasix.files.toBase64('file-uuid');
169
+ * // Use in Image component: <Image source={{ uri: `data:image/jpeg;base64,${base64}` }} />
170
+ * ```
171
+ */
172
+ toBase64(id: string, options?: AssetTransformOptions): Promise<string>;
173
+ /**
174
+ * Import file from URL
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * const file = await baasix.files.importFromUrl(
179
+ * 'https://example.com/image.jpg',
180
+ * { title: 'Imported Image' }
181
+ * );
182
+ * ```
183
+ */
184
+ importFromUrl(url: string, options?: UploadOptions): Promise<FileMetadata>;
185
+ }
186
+
187
+ export { AssetTransformOptions, FileMetadata, FilesModule, type FilesModuleConfig, UploadOptions };
@@ -0,0 +1,264 @@
1
+ // src/modules/files.ts
2
+ var FilesModule = class {
3
+ client;
4
+ constructor(config) {
5
+ this.client = config.client;
6
+ }
7
+ /**
8
+ * Upload a file
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Browser File API
13
+ * const metadata = await baasix.files.upload(fileInput.files[0], {
14
+ * title: 'Product Image',
15
+ * folder: 'products',
16
+ * isPublic: true,
17
+ * onProgress: (progress) => console.log(`${progress}% uploaded`)
18
+ * });
19
+ *
20
+ * // React Native with expo-image-picker
21
+ * const metadata = await baasix.files.upload({
22
+ * uri: result.uri,
23
+ * name: 'photo.jpg',
24
+ * type: 'image/jpeg'
25
+ * });
26
+ * ```
27
+ */
28
+ async upload(file, options) {
29
+ const formData = new FormData();
30
+ if (file instanceof File || file instanceof Blob) {
31
+ formData.append("file", file);
32
+ } else {
33
+ formData.append("file", file);
34
+ }
35
+ if (options?.title) {
36
+ formData.append("title", options.title);
37
+ }
38
+ if (options?.description) {
39
+ formData.append("description", options.description);
40
+ }
41
+ if (options?.folder) {
42
+ formData.append("folder", options.folder);
43
+ }
44
+ if (options?.storage) {
45
+ formData.append("storage", options.storage);
46
+ }
47
+ if (options?.isPublic !== void 0) {
48
+ formData.append("isPublic", String(options.isPublic));
49
+ }
50
+ if (options?.metadata) {
51
+ formData.append("metadata", JSON.stringify(options.metadata));
52
+ }
53
+ const response = await this.client.upload(
54
+ "/files",
55
+ formData,
56
+ { onProgress: options?.onProgress }
57
+ );
58
+ return response.data;
59
+ }
60
+ /**
61
+ * Upload multiple files
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const files = await baasix.files.uploadMany(fileInput.files, {
66
+ * folder: 'gallery',
67
+ * isPublic: true
68
+ * });
69
+ * ```
70
+ */
71
+ async uploadMany(files, options) {
72
+ const results = [];
73
+ const fileArray = files instanceof FileList ? Array.from(files) : files;
74
+ for (const file of fileArray) {
75
+ const metadata = await this.upload(file, options);
76
+ results.push(metadata);
77
+ }
78
+ return results;
79
+ }
80
+ /**
81
+ * List files with optional filtering
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const { data, totalCount } = await baasix.files.find({
86
+ * filter: { mimeType: { startsWith: 'image/' } },
87
+ * limit: 20
88
+ * });
89
+ * ```
90
+ */
91
+ async find(params) {
92
+ return this.client.get("/files", {
93
+ params
94
+ });
95
+ }
96
+ /**
97
+ * Get file metadata by ID
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const file = await baasix.files.findOne('file-uuid');
102
+ * console.log(file.filename, file.size);
103
+ * ```
104
+ */
105
+ async findOne(id) {
106
+ const response = await this.client.get(`/files/${id}`);
107
+ return response.data;
108
+ }
109
+ /**
110
+ * Update file metadata
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * await baasix.files.update('file-uuid', {
115
+ * title: 'Updated Title',
116
+ * description: 'New description'
117
+ * });
118
+ * ```
119
+ */
120
+ async update(id, data) {
121
+ const response = await this.client.patch(
122
+ `/files/${id}`,
123
+ data
124
+ );
125
+ return response.data;
126
+ }
127
+ /**
128
+ * Delete a file
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * await baasix.files.delete('file-uuid');
133
+ * ```
134
+ */
135
+ async delete(id) {
136
+ await this.client.delete(`/files/${id}`);
137
+ }
138
+ /**
139
+ * Delete multiple files
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * await baasix.files.deleteMany(['id1', 'id2', 'id3']);
144
+ * ```
145
+ */
146
+ async deleteMany(ids) {
147
+ await Promise.all(ids.map((id) => this.delete(id)));
148
+ }
149
+ /**
150
+ * Get the URL for an asset with optional transformations
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // Original file
155
+ * const url = baasix.files.getAssetUrl('file-uuid');
156
+ *
157
+ * // Resized thumbnail
158
+ * const thumbUrl = baasix.files.getAssetUrl('file-uuid', {
159
+ * width: 200,
160
+ * height: 200,
161
+ * fit: 'cover',
162
+ * quality: 80
163
+ * });
164
+ *
165
+ * // Convert to WebP
166
+ * const webpUrl = baasix.files.getAssetUrl('file-uuid', {
167
+ * format: 'webp',
168
+ * quality: 85
169
+ * });
170
+ * ```
171
+ */
172
+ getAssetUrl(id, options) {
173
+ const baseUrl = this.client.getBaseUrl();
174
+ const url = new URL(`/assets/${id}`, baseUrl);
175
+ if (options) {
176
+ if (options.width) {
177
+ url.searchParams.set("width", String(options.width));
178
+ }
179
+ if (options.height) {
180
+ url.searchParams.set("height", String(options.height));
181
+ }
182
+ if (options.fit) {
183
+ url.searchParams.set("fit", options.fit);
184
+ }
185
+ if (options.quality) {
186
+ url.searchParams.set("quality", String(options.quality));
187
+ }
188
+ if (options.format) {
189
+ url.searchParams.set("format", options.format);
190
+ }
191
+ }
192
+ return url.toString();
193
+ }
194
+ /**
195
+ * Download a file as a Blob
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * const blob = await baasix.files.download('file-uuid');
200
+ *
201
+ * // Create download link
202
+ * const url = URL.createObjectURL(blob);
203
+ * const a = document.createElement('a');
204
+ * a.href = url;
205
+ * a.download = 'filename.pdf';
206
+ * a.click();
207
+ * ```
208
+ */
209
+ async download(id, options) {
210
+ const url = this.getAssetUrl(id, options);
211
+ const response = await fetch(url);
212
+ if (!response.ok) {
213
+ throw new Error(`Failed to download file: ${response.statusText}`);
214
+ }
215
+ return response.blob();
216
+ }
217
+ /**
218
+ * Get file as base64 string (useful for React Native)
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * const base64 = await baasix.files.toBase64('file-uuid');
223
+ * // Use in Image component: <Image source={{ uri: `data:image/jpeg;base64,${base64}` }} />
224
+ * ```
225
+ */
226
+ async toBase64(id, options) {
227
+ const blob = await this.download(id, options);
228
+ return new Promise((resolve, reject) => {
229
+ const reader = new FileReader();
230
+ reader.onloadend = () => {
231
+ const result = reader.result;
232
+ const base64 = result.split(",")[1];
233
+ resolve(base64);
234
+ };
235
+ reader.onerror = reject;
236
+ reader.readAsDataURL(blob);
237
+ });
238
+ }
239
+ /**
240
+ * Import file from URL
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const file = await baasix.files.importFromUrl(
245
+ * 'https://example.com/image.jpg',
246
+ * { title: 'Imported Image' }
247
+ * );
248
+ * ```
249
+ */
250
+ async importFromUrl(url, options) {
251
+ const response = await this.client.post(
252
+ "/files/import",
253
+ {
254
+ url,
255
+ ...options
256
+ }
257
+ );
258
+ return response.data;
259
+ }
260
+ };
261
+
262
+ export { FilesModule };
263
+ //# sourceMappingURL=files.js.map
264
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/modules/files.ts"],"names":[],"mappings":";AAgCO,IAAM,cAAN,MAAkB;AAAA,EACf,MAAA;AAAA,EAER,YAAY,MAAA,EAA2B;AACrC,IAAA,IAAA,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AO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACtC,MAAA,MAAM,MAAA,GAAS,IAAI,UAAA,EAAW;AAC9B,MAAA,MAAA,CAAO,YAAY,MAAM;AACvB,QAAA,MAAM,SAAS,MAAA,CAAO,MAAA;AAEtB,QAAA,MAAM,MAAA,GAAS,MAAA,CAAO,KAAA,CAAM,GAAG,EAAE,CAAC,CAAA;AAClC,QAAA,OAAA,CAAQ,MAAM,CAAA;AAAA,MAChB,CAAA;AACA,MAAA,MAAA,CAAO,OAAA,GAAU,MAAA;AACjB,MAAA,MAAA,CAAO,cAAc,IAAI,CAAA;AAAA,IAC3B,CAAC,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,aAAA,CACJ,GAAA,EACA,OAAA,EACuB;AACvB,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,MAAA,CAAO,IAAA;AAAA,MACjC,eAAA;AAAA,MACA;AAAA,QACE,GAAA;AAAA,QACA,GAAG;AAAA;AACL,KACF;AACA,IAAA,OAAO,QAAA,CAAS,IAAA;AAAA,EAClB;AACF","file":"files.js","sourcesContent":["import type { HttpClient } from \"../client\";\nimport type {\n AssetTransformOptions,\n FileMetadata,\n PaginatedResponse,\n QueryParams,\n UploadOptions,\n} from \"../types\";\n\nexport interface FilesModuleConfig {\n client: HttpClient;\n}\n\n/**\n * Files module for file upload, management, and asset transformations.\n *\n * @example\n * ```typescript\n * // Upload a file\n * const file = await baasix.files.upload(fileInput.files[0], {\n * title: 'My Image',\n * isPublic: true\n * });\n *\n * // Get asset URL with transformations\n * const url = baasix.files.getAssetUrl(file.id, {\n * width: 200,\n * height: 200,\n * fit: 'cover'\n * });\n * ```\n */\nexport class FilesModule {\n private client: HttpClient;\n\n constructor(config: FilesModuleConfig) {\n this.client = config.client;\n }\n\n /**\n * Upload a file\n *\n * @example\n * ```typescript\n * // Browser File API\n * const metadata = await baasix.files.upload(fileInput.files[0], {\n * title: 'Product Image',\n * folder: 'products',\n * isPublic: true,\n * onProgress: (progress) => console.log(`${progress}% uploaded`)\n * });\n *\n * // React Native with expo-image-picker\n * const metadata = await baasix.files.upload({\n * uri: result.uri,\n * name: 'photo.jpg',\n * type: 'image/jpeg'\n * });\n * ```\n */\n async upload(\n file: File | Blob | { uri: string; name: string; type: string },\n options?: UploadOptions\n ): Promise<FileMetadata> {\n const formData = new FormData();\n\n // Handle different file types (Browser File, Blob, React Native)\n if (file instanceof File || file instanceof Blob) {\n formData.append(\"file\", file);\n } else {\n // React Native style object with uri\n formData.append(\"file\", file as unknown as Blob);\n }\n\n // Add metadata options\n if (options?.title) {\n formData.append(\"title\", options.title);\n }\n if (options?.description) {\n formData.append(\"description\", options.description);\n }\n if (options?.folder) {\n formData.append(\"folder\", options.folder);\n }\n if (options?.storage) {\n formData.append(\"storage\", options.storage);\n }\n if (options?.isPublic !== undefined) {\n formData.append(\"isPublic\", String(options.isPublic));\n }\n if (options?.metadata) {\n formData.append(\"metadata\", JSON.stringify(options.metadata));\n }\n\n const response = await this.client.upload<{ data: FileMetadata }>(\n \"/files\",\n formData,\n { onProgress: options?.onProgress }\n );\n\n return response.data;\n }\n\n /**\n * Upload multiple files\n *\n * @example\n * ```typescript\n * const files = await baasix.files.uploadMany(fileInput.files, {\n * folder: 'gallery',\n * isPublic: true\n * });\n * ```\n */\n async uploadMany(\n files: FileList | File[] | Array<{ uri: string; name: string; type: string }>,\n options?: Omit<UploadOptions, \"onProgress\">\n ): Promise<FileMetadata[]> {\n const results: FileMetadata[] = [];\n \n // Handle different input types\n const fileArray: Array<File | { uri: string; name: string; type: string }> = \n files instanceof FileList \n ? Array.from(files) \n : files;\n\n for (const file of fileArray) {\n const metadata = await this.upload(file, options);\n results.push(metadata);\n }\n\n return results;\n }\n\n /**\n * List files with optional filtering\n *\n * @example\n * ```typescript\n * const { data, totalCount } = await baasix.files.find({\n * filter: { mimeType: { startsWith: 'image/' } },\n * limit: 20\n * });\n * ```\n */\n async find(params?: QueryParams): Promise<PaginatedResponse<FileMetadata>> {\n return this.client.get<PaginatedResponse<FileMetadata>>(\"/files\", {\n params: params as Record<string, unknown>,\n });\n }\n\n /**\n * Get file metadata by ID\n *\n * @example\n * ```typescript\n * const file = await baasix.files.findOne('file-uuid');\n * console.log(file.filename, file.size);\n * ```\n */\n async findOne(id: string): Promise<FileMetadata> {\n const response = await this.client.get<{ data: FileMetadata }>(`/files/${id}`);\n return response.data;\n }\n\n /**\n * Update file metadata\n *\n * @example\n * ```typescript\n * await baasix.files.update('file-uuid', {\n * title: 'Updated Title',\n * description: 'New description'\n * });\n * ```\n */\n async update(\n id: string,\n data: Partial<Pick<FileMetadata, \"title\" | \"description\" | \"isPublic\">>\n ): Promise<FileMetadata> {\n const response = await this.client.patch<{ data: FileMetadata }>(\n `/files/${id}`,\n data\n );\n return response.data;\n }\n\n /**\n * Delete a file\n *\n * @example\n * ```typescript\n * await baasix.files.delete('file-uuid');\n * ```\n */\n async delete(id: string): Promise<void> {\n await this.client.delete(`/files/${id}`);\n }\n\n /**\n * Delete multiple files\n *\n * @example\n * ```typescript\n * await baasix.files.deleteMany(['id1', 'id2', 'id3']);\n * ```\n */\n async deleteMany(ids: string[]): Promise<void> {\n await Promise.all(ids.map((id) => this.delete(id)));\n }\n\n /**\n * Get the URL for an asset with optional transformations\n *\n * @example\n * ```typescript\n * // Original file\n * const url = baasix.files.getAssetUrl('file-uuid');\n *\n * // Resized thumbnail\n * const thumbUrl = baasix.files.getAssetUrl('file-uuid', {\n * width: 200,\n * height: 200,\n * fit: 'cover',\n * quality: 80\n * });\n *\n * // Convert to WebP\n * const webpUrl = baasix.files.getAssetUrl('file-uuid', {\n * format: 'webp',\n * quality: 85\n * });\n * ```\n */\n getAssetUrl(id: string, options?: AssetTransformOptions): string {\n const baseUrl = this.client.getBaseUrl();\n const url = new URL(`/assets/${id}`, baseUrl);\n\n if (options) {\n if (options.width) {\n url.searchParams.set(\"width\", String(options.width));\n }\n if (options.height) {\n url.searchParams.set(\"height\", String(options.height));\n }\n if (options.fit) {\n url.searchParams.set(\"fit\", options.fit);\n }\n if (options.quality) {\n url.searchParams.set(\"quality\", String(options.quality));\n }\n if (options.format) {\n url.searchParams.set(\"format\", options.format);\n }\n }\n\n return url.toString();\n }\n\n /**\n * Download a file as a Blob\n *\n * @example\n * ```typescript\n * const blob = await baasix.files.download('file-uuid');\n *\n * // Create download link\n * const url = URL.createObjectURL(blob);\n * const a = document.createElement('a');\n * a.href = url;\n * a.download = 'filename.pdf';\n * a.click();\n * ```\n */\n async download(id: string, options?: AssetTransformOptions): Promise<Blob> {\n const url = this.getAssetUrl(id, options);\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`Failed to download file: ${response.statusText}`);\n }\n return response.blob();\n }\n\n /**\n * Get file as base64 string (useful for React Native)\n *\n * @example\n * ```typescript\n * const base64 = await baasix.files.toBase64('file-uuid');\n * // Use in Image component: <Image source={{ uri: `data:image/jpeg;base64,${base64}` }} />\n * ```\n */\n async toBase64(id: string, options?: AssetTransformOptions): Promise<string> {\n const blob = await this.download(id, options);\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => {\n const result = reader.result as string;\n // Remove data URL prefix\n const base64 = result.split(\",\")[1];\n resolve(base64);\n };\n reader.onerror = reject;\n reader.readAsDataURL(blob);\n });\n }\n\n /**\n * Import file from URL\n *\n * @example\n * ```typescript\n * const file = await baasix.files.importFromUrl(\n * 'https://example.com/image.jpg',\n * { title: 'Imported Image' }\n * );\n * ```\n */\n async importFromUrl(\n url: string,\n options?: UploadOptions\n ): Promise<FileMetadata> {\n const response = await this.client.post<{ data: FileMetadata }>(\n \"/files/import\",\n {\n url,\n ...options,\n }\n );\n return response.data;\n }\n}\n\n// Re-export types\nexport type { AssetTransformOptions, FileMetadata, UploadOptions };\n"]}