@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.
- package/lib/commonjs/core/OxyServices.base.js +34 -21
- package/lib/commonjs/core/OxyServices.base.js.map +1 -1
- package/lib/commonjs/core/OxyServices.js.map +1 -1
- package/lib/commonjs/core/mixins/OxyServices.assets.js +33 -28
- package/lib/commonjs/core/mixins/OxyServices.assets.js.map +1 -1
- package/lib/commonjs/core/mixins/OxyServices.utility.js +3 -0
- package/lib/commonjs/core/mixins/OxyServices.utility.js.map +1 -1
- package/lib/module/core/OxyServices.base.js +34 -21
- package/lib/module/core/OxyServices.base.js.map +1 -1
- package/lib/module/core/OxyServices.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.assets.js +33 -28
- package/lib/module/core/mixins/OxyServices.assets.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.utility.js +3 -0
- package/lib/module/core/mixins/OxyServices.utility.js.map +1 -1
- package/lib/typescript/core/OxyServices.base.d.ts +16 -10
- package/lib/typescript/core/OxyServices.base.d.ts.map +1 -1
- package/lib/typescript/core/OxyServices.d.ts +3 -886
- package/lib/typescript/core/OxyServices.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.analytics.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.analytics.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.assets.d.ts +4 -2
- package/lib/typescript/core/mixins/OxyServices.assets.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.developer.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.developer.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.devices.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.devices.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.karma.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.karma.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.language.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.language.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.location.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.location.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.payment.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.payment.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.privacy.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.privacy.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.totp.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.totp.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.user.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.utility.d.ts +0 -2
- package/lib/typescript/core/mixins/OxyServices.utility.d.ts.map +1 -1
- package/lib/typescript/core/mixins/index.d.ts +4 -26
- package/lib/typescript/core/mixins/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/OxyServices.base.ts +37 -22
- package/src/core/OxyServices.ts +1 -1
- package/src/core/mixins/OxyServices.assets.ts +68 -27
- 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
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
}
|