@statezero/core 0.1.8 → 0.1.9

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/config.d.ts CHANGED
@@ -29,6 +29,10 @@ export function initializeAllEventReceivers(): Object;
29
29
  * @param {Function} getterFn - The getModelClass function imported from model-registry.js
30
30
  */
31
31
  export function registerModelGetter(getterFn: Function): void;
32
+ /**
33
+ * Helper function to build file URLs
34
+ */
35
+ export function buildFileUrl(fileUrl: any, backendKey?: string): any;
32
36
  /**
33
37
  * Get a model class by name using the registered getter.
34
38
  *
@@ -47,6 +51,7 @@ export namespace configInstance {
47
51
  export { initializeEventReceiver };
48
52
  export { registerModelGetter };
49
53
  export { getModelClass };
54
+ export { buildFileUrl };
50
55
  }
51
56
  export default configInstance;
52
57
  import { PusherEventReceiver } from './core/eventReceivers.js';
package/dist/config.js CHANGED
@@ -47,6 +47,7 @@ const backendSchema = z.object({
47
47
  API_URL: z.string().url('API_URL must be a valid URL'),
48
48
  GENERATED_TYPES_DIR: z.string({ required_error: 'GENERATED_TYPES_DIR is required' }),
49
49
  BACKEND_TZ: z.string().optional(),
50
+ fileRootURL: z.string().url('fileRootURL must be a valid URL').optional(),
50
51
  fileUploadMode: z.enum(['server', 's3']).default('server'),
51
52
  getAuthHeaders: z.function().optional()
52
53
  .refine((fn) => fn === undefined || typeof fn === 'function', 'getAuthHeaders must be a function if provided'),
@@ -212,6 +213,26 @@ export function registerModelGetter(getterFn) {
212
213
  }
213
214
  modelGetter = getterFn;
214
215
  }
216
+ /**
217
+ * Helper function to build file URLs
218
+ */
219
+ export function buildFileUrl(fileUrl, backendKey = 'default') {
220
+ // If URL is already absolute (cloud storage), use it as-is
221
+ if (fileUrl && fileUrl.startsWith('http')) {
222
+ return fileUrl;
223
+ }
224
+ const cfg = getConfig();
225
+ const backend = cfg.backendConfigs[backendKey];
226
+ if (!backend) {
227
+ throw new ConfigError(`Backend "${backendKey}" not found in configuration.`);
228
+ }
229
+ // If no fileRootURL provided, return relative URL as-is
230
+ if (!backend.fileRootURL) {
231
+ return fileUrl;
232
+ }
233
+ // Construct full URL
234
+ return backend.fileRootURL.replace(/\/$/, '') + fileUrl;
235
+ }
215
236
  /**
216
237
  * Get a model class by name using the registered getter.
217
238
  *
@@ -237,6 +258,7 @@ export const configInstance = {
237
258
  setBackendConfig,
238
259
  initializeEventReceiver,
239
260
  registerModelGetter,
240
- getModelClass
261
+ getModelClass,
262
+ buildFileUrl
241
263
  };
242
264
  export default configInstance;
@@ -77,7 +77,10 @@ export class FileObject {
77
77
  return this.uploadResult?.file_path;
78
78
  }
79
79
  get fileUrl() {
80
- return this.uploadResult?.file_url;
80
+ if (!this.uploadResult?.file_url) {
81
+ return null;
82
+ }
83
+ return configInstance.buildFileUrl(this.uploadResult.file_url, this.constructor.configKey);
81
84
  }
82
85
  async _initializeAndStartUpload(file, options) {
83
86
  const config = configInstance.getConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statezero/core",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "module": "ESNext",
6
6
  "description": "The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate",