@oxyhq/services 5.13.20 → 5.13.22

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 (51) hide show
  1. package/lib/commonjs/core/OxyServices.base.js +34 -21
  2. package/lib/commonjs/core/OxyServices.base.js.map +1 -1
  3. package/lib/commonjs/core/OxyServices.js.map +1 -1
  4. package/lib/commonjs/core/mixins/OxyServices.assets.js +33 -28
  5. package/lib/commonjs/core/mixins/OxyServices.assets.js.map +1 -1
  6. package/lib/commonjs/core/mixins/OxyServices.utility.js +3 -0
  7. package/lib/commonjs/core/mixins/OxyServices.utility.js.map +1 -1
  8. package/lib/module/core/OxyServices.base.js +34 -21
  9. package/lib/module/core/OxyServices.base.js.map +1 -1
  10. package/lib/module/core/OxyServices.js.map +1 -1
  11. package/lib/module/core/mixins/OxyServices.assets.js +33 -28
  12. package/lib/module/core/mixins/OxyServices.assets.js.map +1 -1
  13. package/lib/module/core/mixins/OxyServices.utility.js +3 -0
  14. package/lib/module/core/mixins/OxyServices.utility.js.map +1 -1
  15. package/lib/typescript/core/OxyServices.base.d.ts +16 -10
  16. package/lib/typescript/core/OxyServices.base.d.ts.map +1 -1
  17. package/lib/typescript/core/OxyServices.d.ts +3 -886
  18. package/lib/typescript/core/OxyServices.d.ts.map +1 -1
  19. package/lib/typescript/core/mixins/OxyServices.analytics.d.ts +0 -2
  20. package/lib/typescript/core/mixins/OxyServices.analytics.d.ts.map +1 -1
  21. package/lib/typescript/core/mixins/OxyServices.assets.d.ts +4 -2
  22. package/lib/typescript/core/mixins/OxyServices.assets.d.ts.map +1 -1
  23. package/lib/typescript/core/mixins/OxyServices.auth.d.ts +0 -2
  24. package/lib/typescript/core/mixins/OxyServices.auth.d.ts.map +1 -1
  25. package/lib/typescript/core/mixins/OxyServices.developer.d.ts +0 -2
  26. package/lib/typescript/core/mixins/OxyServices.developer.d.ts.map +1 -1
  27. package/lib/typescript/core/mixins/OxyServices.devices.d.ts +0 -2
  28. package/lib/typescript/core/mixins/OxyServices.devices.d.ts.map +1 -1
  29. package/lib/typescript/core/mixins/OxyServices.karma.d.ts +0 -2
  30. package/lib/typescript/core/mixins/OxyServices.karma.d.ts.map +1 -1
  31. package/lib/typescript/core/mixins/OxyServices.language.d.ts +0 -2
  32. package/lib/typescript/core/mixins/OxyServices.language.d.ts.map +1 -1
  33. package/lib/typescript/core/mixins/OxyServices.location.d.ts +0 -2
  34. package/lib/typescript/core/mixins/OxyServices.location.d.ts.map +1 -1
  35. package/lib/typescript/core/mixins/OxyServices.payment.d.ts +0 -2
  36. package/lib/typescript/core/mixins/OxyServices.payment.d.ts.map +1 -1
  37. package/lib/typescript/core/mixins/OxyServices.privacy.d.ts +0 -2
  38. package/lib/typescript/core/mixins/OxyServices.privacy.d.ts.map +1 -1
  39. package/lib/typescript/core/mixins/OxyServices.totp.d.ts +0 -2
  40. package/lib/typescript/core/mixins/OxyServices.totp.d.ts.map +1 -1
  41. package/lib/typescript/core/mixins/OxyServices.user.d.ts +0 -2
  42. package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -1
  43. package/lib/typescript/core/mixins/OxyServices.utility.d.ts +0 -2
  44. package/lib/typescript/core/mixins/OxyServices.utility.d.ts.map +1 -1
  45. package/lib/typescript/core/mixins/index.d.ts +4 -26
  46. package/lib/typescript/core/mixins/index.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/src/core/OxyServices.base.ts +37 -22
  49. package/src/core/OxyServices.ts +1 -1
  50. package/src/core/mixins/OxyServices.assets.ts +68 -27
  51. package/src/core/mixins/OxyServices.utility.ts +3 -0
@@ -52,16 +52,14 @@ export function OxyServicesAssetsMixin<T extends typeof OxyServicesBase>(Base: T
52
52
  */
53
53
  async getFileDownloadUrlAsync(fileId: string, variant?: string, expiresIn?: number): Promise<string> {
54
54
  try {
55
- const params: any = {};
56
- if (variant) params.variant = variant;
57
- if (expiresIn) params.expiresIn = expiresIn;
58
-
59
- const urlRes = await this.makeRequest<{ url: string }>('GET', `/api/assets/${encodeURIComponent(fileId)}/url`, params, {
60
- cache: true,
61
- cacheTTL: Math.min((expiresIn || 3600) * 1000, 10 * 60 * 1000), // Cache for up to 10 minutes or expiresIn, whichever is shorter
62
- });
63
-
64
- return urlRes?.url || this.getFileDownloadUrl(fileId, variant, expiresIn);
55
+ const url = await this.fetchAssetDownloadUrl(
56
+ fileId,
57
+ variant,
58
+ this.getAssetUrlCacheTTL(expiresIn),
59
+ expiresIn
60
+ );
61
+
62
+ return url || this.getFileDownloadUrl(fileId, variant, expiresIn);
65
63
  } catch (error) {
66
64
  // Fallback to synchronous method on error
67
65
  return this.getFileDownloadUrl(fileId, variant, expiresIn);
@@ -96,14 +94,17 @@ export function OxyServicesAssetsMixin<T extends typeof OxyServicesBase>(Base: T
96
94
  */
97
95
  async getFileContentAsText(fileId: string, variant?: string): Promise<string> {
98
96
  try {
99
- const params: any = variant ? { variant } : undefined;
100
- const urlRes = await this.makeRequest<{ url: string }>('GET', `/api/assets/${encodeURIComponent(fileId)}/url`, params, {
101
- cache: true,
102
- cacheTTL: 10 * 60 * 1000, // 10 minutes cache for URLs
103
- });
104
- const downloadUrl = urlRes?.url;
105
- const response = await fetch(downloadUrl);
106
- return await response.text();
97
+ const downloadUrl = await this.fetchAssetDownloadUrl(
98
+ fileId,
99
+ variant,
100
+ this.getAssetUrlCacheTTL()
101
+ );
102
+
103
+ if (!downloadUrl) {
104
+ throw new Error('No download URL returned for asset');
105
+ }
106
+
107
+ return await this.fetchAssetContent(downloadUrl, 'text');
107
108
  } catch (error) {
108
109
  throw this.handleError(error);
109
110
  }
@@ -114,14 +115,17 @@ export function OxyServicesAssetsMixin<T extends typeof OxyServicesBase>(Base: T
114
115
  */
115
116
  async getFileContentAsBlob(fileId: string, variant?: string): Promise<Blob> {
116
117
  try {
117
- const params: any = variant ? { variant } : undefined;
118
- const urlRes = await this.makeRequest<{ url: string }>('GET', `/api/assets/${encodeURIComponent(fileId)}/url`, params, {
119
- cache: true,
120
- cacheTTL: 10 * 60 * 1000, // 10 minutes cache for URLs
121
- });
122
- const downloadUrl = urlRes?.url;
123
- const response = await fetch(downloadUrl);
124
- return await response.blob();
118
+ const downloadUrl = await this.fetchAssetDownloadUrl(
119
+ fileId,
120
+ variant,
121
+ this.getAssetUrlCacheTTL()
122
+ );
123
+
124
+ if (!downloadUrl) {
125
+ throw new Error('No download URL returned for asset');
126
+ }
127
+
128
+ return await this.fetchAssetContent(downloadUrl, 'blob');
125
129
  } catch (error) {
126
130
  throw this.handleError(error);
127
131
  }
@@ -438,6 +442,43 @@ export function OxyServicesAssetsMixin<T extends typeof OxyServicesBase>(Base: T
438
442
  throw this.handleError(error);
439
443
  }
440
444
  }
445
+
446
+ public getAssetUrlCacheTTL(expiresIn?: number) {
447
+ const desiredTtlMs = (expiresIn ?? 3600) * 1000;
448
+ return Math.min(desiredTtlMs, 10 * 60 * 1000);
449
+ }
450
+
451
+ public async fetchAssetDownloadUrl(
452
+ fileId: string,
453
+ variant?: string,
454
+ cacheTTL?: number,
455
+ expiresIn?: number
456
+ ): Promise<string | null> {
457
+ const params: any = {};
458
+ if (variant) params.variant = variant;
459
+ if (expiresIn) params.expiresIn = expiresIn;
460
+
461
+ const urlRes = await this.makeRequest<{ url: string }>(
462
+ 'GET',
463
+ `/api/assets/${encodeURIComponent(fileId)}/url`,
464
+ Object.keys(params).length ? params : undefined,
465
+ {
466
+ cache: true,
467
+ cacheTTL: cacheTTL ?? 10 * 60 * 1000, // default 10 minutes cache for URLs
468
+ }
469
+ );
470
+
471
+ return urlRes?.url || null;
472
+ }
473
+
474
+ public async fetchAssetContent(url: string, type: 'text'): Promise<string>;
475
+ public async fetchAssetContent(url: string, type: 'blob'): Promise<Blob>;
476
+ public async fetchAssetContent(url: string, type: 'text' | 'blob') {
477
+ const response = await fetch(url);
478
+ if (!response?.ok) {
479
+ throw new Error(`Failed to fetch asset content (status ${response?.status})`);
480
+ }
481
+ return type === 'text' ? response.text() : response.blob();
482
+ }
441
483
  };
442
484
  }
443
-
@@ -165,6 +165,9 @@ export function OxyServicesUtilityMixin<T extends typeof OxyServicesBase>(Base:
165
165
  req.accessToken = token;
166
166
  req.user = { id: userId } as User;
167
167
 
168
+ // Automatically authenticate the OxyServices instance so all subsequent API calls are authenticated
169
+ this.setTokens(token);
170
+
168
171
  if (debug) {
169
172
  console.log(`✅ Auth: Authentication successful for user ${userId}`);
170
173
  }