@centrali-io/centrali-sdk 2.9.2 → 2.9.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/README.md CHANGED
@@ -329,14 +329,26 @@ console.log('Job queued:', job.data);
329
329
  ### File Uploads
330
330
 
331
331
  ```typescript
332
- // Upload a file
333
- const uploadResult = await centrali.uploadFile(
334
- file,
335
- 'folder-name',
336
- true // make publicly accessible
337
- );
332
+ // Upload a file (defaults to /root/shared)
333
+ const result = await centrali.uploadFile(file);
334
+ const renderId = result.data; // e.g., "kvHJ4ipZ3Q6EAoguKrWmU7KYyDHcU03C"
335
+
336
+ // Upload to a specific folder (must exist, use full path)
337
+ const result = await centrali.uploadFile(file, '/root/shared/images');
338
+
339
+ // Upload as public file
340
+ const result = await centrali.uploadFile(file, '/root/shared/public', true);
338
341
 
339
- console.log('File URL:', uploadResult.data);
342
+ // Get URLs for the uploaded file
343
+ const renderUrl = centrali.getFileRenderUrl(renderId); // For inline display
344
+ const downloadUrl = centrali.getFileDownloadUrl(renderId); // For download
345
+
346
+ // Get URL with image transformations
347
+ const thumbnailUrl = centrali.getFileRenderUrl(renderId, {
348
+ width: 200,
349
+ quality: 80,
350
+ format: 'webp'
351
+ });
340
352
  ```
341
353
 
342
354
  ### Data Validation
package/dist/index.js CHANGED
@@ -1879,16 +1879,39 @@ class CentraliSDK {
1879
1879
  return this.request('POST', path, { field, value });
1880
1880
  }
1881
1881
  // ------------------ Storage API Methods ------------------
1882
- /** Upload a file to the storage service. */
1882
+ /**
1883
+ * Upload a file to the storage service.
1884
+ *
1885
+ * @param file - The file to upload
1886
+ * @param location - Target folder path (e.g., '/root/shared/images'). Defaults to '/root/shared' if not specified.
1887
+ * Must be an absolute path starting with '/root/'. The folder must exist before uploading.
1888
+ * @param isPublic - If true, the file will be publicly accessible without authentication. Defaults to false.
1889
+ * @returns The file URL or render ID
1890
+ *
1891
+ * @example
1892
+ * ```ts
1893
+ * // Upload to default location (/root/shared)
1894
+ * const result = await client.uploadFile(file);
1895
+ *
1896
+ * // Upload to specific folder
1897
+ * const result = await client.uploadFile(file, '/root/shared/images');
1898
+ *
1899
+ * // Upload as public file
1900
+ * const result = await client.uploadFile(file, '/root/shared/public', true);
1901
+ * ```
1902
+ */
1883
1903
  uploadFile(file_1, location_1) {
1884
1904
  return __awaiter(this, arguments, void 0, function* (file, location, isPublic = false) {
1885
1905
  const path = getFileUploadApiPath(this.options.workspaceId);
1886
1906
  const formData = new FormData();
1887
1907
  const fileName = this.options.workspaceId + Date.now() + file.name;
1888
1908
  formData.append('file', file);
1889
- formData.append('location', location);
1890
1909
  formData.append('fileName', fileName);
1891
1910
  formData.append('isPublic', isPublic ? 'true' : 'false');
1911
+ // Only append location if specified; backend defaults to /root/shared
1912
+ if (location) {
1913
+ formData.append('location', location);
1914
+ }
1892
1915
  return this.request('POST', path, formData, undefined, {
1893
1916
  headers: {
1894
1917
  'Content-Type': 'multipart/form-data',
@@ -1896,6 +1919,57 @@ class CentraliSDK {
1896
1919
  });
1897
1920
  });
1898
1921
  }
1922
+ /**
1923
+ * Get the render URL for a file. Use this URL to display files inline (e.g., images in img tags).
1924
+ * Supports optional image transformation parameters.
1925
+ *
1926
+ * @param renderId - The render ID returned from uploadFile()
1927
+ * @param options - Optional image transformation parameters
1928
+ * @returns The full render URL
1929
+ *
1930
+ * @example
1931
+ * ```ts
1932
+ * // Basic render URL
1933
+ * const url = client.getFileRenderUrl('abc123');
1934
+ * // => "https://api.centrali.io/storage/ws/my-workspace/api/v1/render/abc123"
1935
+ *
1936
+ * // With image transformations
1937
+ * const thumbUrl = client.getFileRenderUrl('abc123', { width: 200 });
1938
+ * const compressedUrl = client.getFileRenderUrl('abc123', { width: 800, quality: 60, format: 'webp' });
1939
+ * ```
1940
+ */
1941
+ getFileRenderUrl(renderId, options) {
1942
+ const baseUrl = `${this.options.baseUrl}/storage/ws/${this.options.workspaceId}/api/v1/render/${renderId}`;
1943
+ if (!options) {
1944
+ return baseUrl;
1945
+ }
1946
+ const params = new URLSearchParams();
1947
+ if (options.width)
1948
+ params.append('width', String(options.width));
1949
+ if (options.height)
1950
+ params.append('height', String(options.height));
1951
+ if (options.quality)
1952
+ params.append('quality', String(options.quality));
1953
+ if (options.format)
1954
+ params.append('format', options.format);
1955
+ const queryString = params.toString();
1956
+ return queryString ? `${baseUrl}?${queryString}` : baseUrl;
1957
+ }
1958
+ /**
1959
+ * Get the download URL for a file. Use this URL to download files as attachments.
1960
+ *
1961
+ * @param renderId - The render ID returned from uploadFile()
1962
+ * @returns The full download URL
1963
+ *
1964
+ * @example
1965
+ * ```ts
1966
+ * const downloadUrl = client.getFileDownloadUrl('abc123');
1967
+ * // => "https://api.centrali.io/storage/ws/my-workspace/api/v1/download/abc123"
1968
+ * ```
1969
+ */
1970
+ getFileDownloadUrl(renderId) {
1971
+ return `${this.options.baseUrl}/storage/ws/${this.options.workspaceId}/api/v1/download/${renderId}`;
1972
+ }
1899
1973
  // ------------------ Search API Methods ------------------
1900
1974
  /**
1901
1975
  * Search records across the workspace using full-text search.
package/index.ts CHANGED
@@ -3548,10 +3548,30 @@ export class CentraliSDK {
3548
3548
 
3549
3549
  // ------------------ Storage API Methods ------------------
3550
3550
 
3551
- /** Upload a file to the storage service. */
3551
+ /**
3552
+ * Upload a file to the storage service.
3553
+ *
3554
+ * @param file - The file to upload
3555
+ * @param location - Target folder path (e.g., '/root/shared/images'). Defaults to '/root/shared' if not specified.
3556
+ * Must be an absolute path starting with '/root/'. The folder must exist before uploading.
3557
+ * @param isPublic - If true, the file will be publicly accessible without authentication. Defaults to false.
3558
+ * @returns The file URL or render ID
3559
+ *
3560
+ * @example
3561
+ * ```ts
3562
+ * // Upload to default location (/root/shared)
3563
+ * const result = await client.uploadFile(file);
3564
+ *
3565
+ * // Upload to specific folder
3566
+ * const result = await client.uploadFile(file, '/root/shared/images');
3567
+ *
3568
+ * // Upload as public file
3569
+ * const result = await client.uploadFile(file, '/root/shared/public', true);
3570
+ * ```
3571
+ */
3552
3572
  public async uploadFile(
3553
3573
  file: File,
3554
- location: string,
3574
+ location?: string,
3555
3575
  isPublic: boolean = false
3556
3576
  ): Promise<ApiResponse<string>> {
3557
3577
  const path = getFileUploadApiPath(this.options.workspaceId);
@@ -3559,10 +3579,14 @@ export class CentraliSDK {
3559
3579
  const fileName = this.options.workspaceId + Date.now() + file.name;
3560
3580
 
3561
3581
  formData.append('file', file);
3562
- formData.append('location', location);
3563
3582
  formData.append('fileName', fileName);
3564
3583
  formData.append('isPublic', isPublic ? 'true' : 'false');
3565
3584
 
3585
+ // Only append location if specified; backend defaults to /root/shared
3586
+ if (location) {
3587
+ formData.append('location', location);
3588
+ }
3589
+
3566
3590
  return this.request<string>('POST', path, formData, undefined, {
3567
3591
  headers: {
3568
3592
  'Content-Type': 'multipart/form-data',
@@ -3570,6 +3594,66 @@ export class CentraliSDK {
3570
3594
  });
3571
3595
  }
3572
3596
 
3597
+ /**
3598
+ * Get the render URL for a file. Use this URL to display files inline (e.g., images in img tags).
3599
+ * Supports optional image transformation parameters.
3600
+ *
3601
+ * @param renderId - The render ID returned from uploadFile()
3602
+ * @param options - Optional image transformation parameters
3603
+ * @returns The full render URL
3604
+ *
3605
+ * @example
3606
+ * ```ts
3607
+ * // Basic render URL
3608
+ * const url = client.getFileRenderUrl('abc123');
3609
+ * // => "https://api.centrali.io/storage/ws/my-workspace/api/v1/render/abc123"
3610
+ *
3611
+ * // With image transformations
3612
+ * const thumbUrl = client.getFileRenderUrl('abc123', { width: 200 });
3613
+ * const compressedUrl = client.getFileRenderUrl('abc123', { width: 800, quality: 60, format: 'webp' });
3614
+ * ```
3615
+ */
3616
+ public getFileRenderUrl(
3617
+ renderId: string,
3618
+ options?: {
3619
+ width?: number;
3620
+ height?: number;
3621
+ quality?: number;
3622
+ format?: 'jpeg' | 'png' | 'webp';
3623
+ }
3624
+ ): string {
3625
+ const baseUrl = `${this.options.baseUrl}/storage/ws/${this.options.workspaceId}/api/v1/render/${renderId}`;
3626
+
3627
+ if (!options) {
3628
+ return baseUrl;
3629
+ }
3630
+
3631
+ const params = new URLSearchParams();
3632
+ if (options.width) params.append('width', String(options.width));
3633
+ if (options.height) params.append('height', String(options.height));
3634
+ if (options.quality) params.append('quality', String(options.quality));
3635
+ if (options.format) params.append('format', options.format);
3636
+
3637
+ const queryString = params.toString();
3638
+ return queryString ? `${baseUrl}?${queryString}` : baseUrl;
3639
+ }
3640
+
3641
+ /**
3642
+ * Get the download URL for a file. Use this URL to download files as attachments.
3643
+ *
3644
+ * @param renderId - The render ID returned from uploadFile()
3645
+ * @returns The full download URL
3646
+ *
3647
+ * @example
3648
+ * ```ts
3649
+ * const downloadUrl = client.getFileDownloadUrl('abc123');
3650
+ * // => "https://api.centrali.io/storage/ws/my-workspace/api/v1/download/abc123"
3651
+ * ```
3652
+ */
3653
+ public getFileDownloadUrl(renderId: string): string {
3654
+ return `${this.options.baseUrl}/storage/ws/${this.options.workspaceId}/api/v1/download/${renderId}`;
3655
+ }
3656
+
3573
3657
  // ------------------ Search API Methods ------------------
3574
3658
 
3575
3659
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centrali-io/centrali-sdk",
3
- "version": "2.9.2",
3
+ "version": "2.9.3",
4
4
  "description": "Centrali Node SDK",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",