@oxyhq/core 1.0.0

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 (277) hide show
  1. package/README.md +50 -0
  2. package/dist/cjs/AuthManager.js +361 -0
  3. package/dist/cjs/CrossDomainAuth.js +258 -0
  4. package/dist/cjs/HttpService.js +618 -0
  5. package/dist/cjs/OxyServices.base.js +263 -0
  6. package/dist/cjs/OxyServices.errors.js +22 -0
  7. package/dist/cjs/OxyServices.js +63 -0
  8. package/dist/cjs/constants/version.js +16 -0
  9. package/dist/cjs/crypto/index.js +20 -0
  10. package/dist/cjs/crypto/keyManager.js +887 -0
  11. package/dist/cjs/crypto/polyfill.js +64 -0
  12. package/dist/cjs/crypto/recoveryPhrase.js +169 -0
  13. package/dist/cjs/crypto/signatureService.js +296 -0
  14. package/dist/cjs/i18n/index.js +73 -0
  15. package/dist/cjs/i18n/locales/ar-SA.json +120 -0
  16. package/dist/cjs/i18n/locales/ca-ES.json +120 -0
  17. package/dist/cjs/i18n/locales/de-DE.json +120 -0
  18. package/dist/cjs/i18n/locales/en-US.json +956 -0
  19. package/dist/cjs/i18n/locales/es-ES.json +944 -0
  20. package/dist/cjs/i18n/locales/fr-FR.json +120 -0
  21. package/dist/cjs/i18n/locales/it-IT.json +120 -0
  22. package/dist/cjs/i18n/locales/ja-JP.json +119 -0
  23. package/dist/cjs/i18n/locales/ko-KR.json +120 -0
  24. package/dist/cjs/i18n/locales/locales/ar-SA.json +120 -0
  25. package/dist/cjs/i18n/locales/locales/ca-ES.json +120 -0
  26. package/dist/cjs/i18n/locales/locales/de-DE.json +120 -0
  27. package/dist/cjs/i18n/locales/locales/en-US.json +956 -0
  28. package/dist/cjs/i18n/locales/locales/es-ES.json +944 -0
  29. package/dist/cjs/i18n/locales/locales/fr-FR.json +120 -0
  30. package/dist/cjs/i18n/locales/locales/it-IT.json +120 -0
  31. package/dist/cjs/i18n/locales/locales/ja-JP.json +119 -0
  32. package/dist/cjs/i18n/locales/locales/ko-KR.json +120 -0
  33. package/dist/cjs/i18n/locales/locales/pt-PT.json +120 -0
  34. package/dist/cjs/i18n/locales/locales/zh-CN.json +120 -0
  35. package/dist/cjs/i18n/locales/pt-PT.json +120 -0
  36. package/dist/cjs/i18n/locales/zh-CN.json +120 -0
  37. package/dist/cjs/index.js +153 -0
  38. package/dist/cjs/mixins/OxyServices.analytics.js +49 -0
  39. package/dist/cjs/mixins/OxyServices.assets.js +380 -0
  40. package/dist/cjs/mixins/OxyServices.auth.js +259 -0
  41. package/dist/cjs/mixins/OxyServices.developer.js +97 -0
  42. package/dist/cjs/mixins/OxyServices.devices.js +116 -0
  43. package/dist/cjs/mixins/OxyServices.features.js +309 -0
  44. package/dist/cjs/mixins/OxyServices.fedcm.js +435 -0
  45. package/dist/cjs/mixins/OxyServices.karma.js +108 -0
  46. package/dist/cjs/mixins/OxyServices.language.js +154 -0
  47. package/dist/cjs/mixins/OxyServices.location.js +43 -0
  48. package/dist/cjs/mixins/OxyServices.payment.js +158 -0
  49. package/dist/cjs/mixins/OxyServices.popup.js +371 -0
  50. package/dist/cjs/mixins/OxyServices.privacy.js +162 -0
  51. package/dist/cjs/mixins/OxyServices.redirect.js +345 -0
  52. package/dist/cjs/mixins/OxyServices.security.js +81 -0
  53. package/dist/cjs/mixins/OxyServices.user.js +355 -0
  54. package/dist/cjs/mixins/OxyServices.utility.js +156 -0
  55. package/dist/cjs/mixins/index.js +79 -0
  56. package/dist/cjs/mixins/mixinHelpers.js +53 -0
  57. package/dist/cjs/models/interfaces.js +20 -0
  58. package/dist/cjs/models/session.js +2 -0
  59. package/dist/cjs/shared/index.js +70 -0
  60. package/dist/cjs/shared/utils/colorUtils.js +153 -0
  61. package/dist/cjs/shared/utils/debugUtils.js +73 -0
  62. package/dist/cjs/shared/utils/errorUtils.js +183 -0
  63. package/dist/cjs/shared/utils/index.js +49 -0
  64. package/dist/cjs/shared/utils/networkUtils.js +183 -0
  65. package/dist/cjs/shared/utils/themeUtils.js +106 -0
  66. package/dist/cjs/utils/apiUtils.js +61 -0
  67. package/dist/cjs/utils/asyncUtils.js +194 -0
  68. package/dist/cjs/utils/cache.js +226 -0
  69. package/dist/cjs/utils/deviceManager.js +205 -0
  70. package/dist/cjs/utils/errorUtils.js +154 -0
  71. package/dist/cjs/utils/index.js +26 -0
  72. package/dist/cjs/utils/languageUtils.js +165 -0
  73. package/dist/cjs/utils/loggerUtils.js +126 -0
  74. package/dist/cjs/utils/platform.js +144 -0
  75. package/dist/cjs/utils/requestUtils.js +209 -0
  76. package/dist/cjs/utils/sessionUtils.js +181 -0
  77. package/dist/cjs/utils/validationUtils.js +173 -0
  78. package/dist/esm/AuthManager.js +356 -0
  79. package/dist/esm/CrossDomainAuth.js +253 -0
  80. package/dist/esm/HttpService.js +614 -0
  81. package/dist/esm/OxyServices.base.js +259 -0
  82. package/dist/esm/OxyServices.errors.js +17 -0
  83. package/dist/esm/OxyServices.js +59 -0
  84. package/dist/esm/constants/version.js +13 -0
  85. package/dist/esm/crypto/index.js +13 -0
  86. package/dist/esm/crypto/keyManager.js +850 -0
  87. package/dist/esm/crypto/polyfill.js +61 -0
  88. package/dist/esm/crypto/recoveryPhrase.js +132 -0
  89. package/dist/esm/crypto/signatureService.js +259 -0
  90. package/dist/esm/i18n/index.js +69 -0
  91. package/dist/esm/i18n/locales/ar-SA.json +120 -0
  92. package/dist/esm/i18n/locales/ca-ES.json +120 -0
  93. package/dist/esm/i18n/locales/de-DE.json +120 -0
  94. package/dist/esm/i18n/locales/en-US.json +956 -0
  95. package/dist/esm/i18n/locales/es-ES.json +944 -0
  96. package/dist/esm/i18n/locales/fr-FR.json +120 -0
  97. package/dist/esm/i18n/locales/it-IT.json +120 -0
  98. package/dist/esm/i18n/locales/ja-JP.json +119 -0
  99. package/dist/esm/i18n/locales/ko-KR.json +120 -0
  100. package/dist/esm/i18n/locales/locales/ar-SA.json +120 -0
  101. package/dist/esm/i18n/locales/locales/ca-ES.json +120 -0
  102. package/dist/esm/i18n/locales/locales/de-DE.json +120 -0
  103. package/dist/esm/i18n/locales/locales/en-US.json +956 -0
  104. package/dist/esm/i18n/locales/locales/es-ES.json +944 -0
  105. package/dist/esm/i18n/locales/locales/fr-FR.json +120 -0
  106. package/dist/esm/i18n/locales/locales/it-IT.json +120 -0
  107. package/dist/esm/i18n/locales/locales/ja-JP.json +119 -0
  108. package/dist/esm/i18n/locales/locales/ko-KR.json +120 -0
  109. package/dist/esm/i18n/locales/locales/pt-PT.json +120 -0
  110. package/dist/esm/i18n/locales/locales/zh-CN.json +120 -0
  111. package/dist/esm/i18n/locales/pt-PT.json +120 -0
  112. package/dist/esm/i18n/locales/zh-CN.json +120 -0
  113. package/dist/esm/index.js +55 -0
  114. package/dist/esm/mixins/OxyServices.analytics.js +46 -0
  115. package/dist/esm/mixins/OxyServices.assets.js +377 -0
  116. package/dist/esm/mixins/OxyServices.auth.js +256 -0
  117. package/dist/esm/mixins/OxyServices.developer.js +94 -0
  118. package/dist/esm/mixins/OxyServices.devices.js +113 -0
  119. package/dist/esm/mixins/OxyServices.features.js +306 -0
  120. package/dist/esm/mixins/OxyServices.fedcm.js +433 -0
  121. package/dist/esm/mixins/OxyServices.karma.js +105 -0
  122. package/dist/esm/mixins/OxyServices.language.js +118 -0
  123. package/dist/esm/mixins/OxyServices.location.js +40 -0
  124. package/dist/esm/mixins/OxyServices.payment.js +155 -0
  125. package/dist/esm/mixins/OxyServices.popup.js +369 -0
  126. package/dist/esm/mixins/OxyServices.privacy.js +159 -0
  127. package/dist/esm/mixins/OxyServices.redirect.js +343 -0
  128. package/dist/esm/mixins/OxyServices.security.js +78 -0
  129. package/dist/esm/mixins/OxyServices.user.js +352 -0
  130. package/dist/esm/mixins/OxyServices.utility.js +153 -0
  131. package/dist/esm/mixins/index.js +76 -0
  132. package/dist/esm/mixins/mixinHelpers.js +48 -0
  133. package/dist/esm/models/interfaces.js +17 -0
  134. package/dist/esm/models/session.js +1 -0
  135. package/dist/esm/shared/index.js +31 -0
  136. package/dist/esm/shared/utils/colorUtils.js +143 -0
  137. package/dist/esm/shared/utils/debugUtils.js +65 -0
  138. package/dist/esm/shared/utils/errorUtils.js +170 -0
  139. package/dist/esm/shared/utils/index.js +15 -0
  140. package/dist/esm/shared/utils/networkUtils.js +173 -0
  141. package/dist/esm/shared/utils/themeUtils.js +98 -0
  142. package/dist/esm/utils/apiUtils.js +55 -0
  143. package/dist/esm/utils/asyncUtils.js +179 -0
  144. package/dist/esm/utils/cache.js +218 -0
  145. package/dist/esm/utils/deviceManager.js +168 -0
  146. package/dist/esm/utils/errorUtils.js +146 -0
  147. package/dist/esm/utils/index.js +7 -0
  148. package/dist/esm/utils/languageUtils.js +158 -0
  149. package/dist/esm/utils/loggerUtils.js +115 -0
  150. package/dist/esm/utils/platform.js +102 -0
  151. package/dist/esm/utils/requestUtils.js +203 -0
  152. package/dist/esm/utils/sessionUtils.js +171 -0
  153. package/dist/esm/utils/validationUtils.js +153 -0
  154. package/dist/types/AuthManager.d.ts +143 -0
  155. package/dist/types/CrossDomainAuth.d.ts +160 -0
  156. package/dist/types/HttpService.d.ts +163 -0
  157. package/dist/types/OxyServices.base.d.ts +126 -0
  158. package/dist/types/OxyServices.d.ts +81 -0
  159. package/dist/types/OxyServices.errors.d.ts +11 -0
  160. package/dist/types/constants/version.d.ts +13 -0
  161. package/dist/types/crypto/index.d.ts +11 -0
  162. package/dist/types/crypto/keyManager.d.ts +189 -0
  163. package/dist/types/crypto/polyfill.d.ts +11 -0
  164. package/dist/types/crypto/recoveryPhrase.d.ts +58 -0
  165. package/dist/types/crypto/signatureService.d.ts +86 -0
  166. package/dist/types/i18n/index.d.ts +3 -0
  167. package/dist/types/index.d.ts +50 -0
  168. package/dist/types/mixins/OxyServices.analytics.d.ts +66 -0
  169. package/dist/types/mixins/OxyServices.assets.d.ts +135 -0
  170. package/dist/types/mixins/OxyServices.auth.d.ts +186 -0
  171. package/dist/types/mixins/OxyServices.developer.d.ts +99 -0
  172. package/dist/types/mixins/OxyServices.devices.d.ts +96 -0
  173. package/dist/types/mixins/OxyServices.features.d.ts +228 -0
  174. package/dist/types/mixins/OxyServices.fedcm.d.ts +200 -0
  175. package/dist/types/mixins/OxyServices.karma.d.ts +85 -0
  176. package/dist/types/mixins/OxyServices.language.d.ts +81 -0
  177. package/dist/types/mixins/OxyServices.location.d.ts +64 -0
  178. package/dist/types/mixins/OxyServices.payment.d.ts +111 -0
  179. package/dist/types/mixins/OxyServices.popup.d.ts +205 -0
  180. package/dist/types/mixins/OxyServices.privacy.d.ts +122 -0
  181. package/dist/types/mixins/OxyServices.redirect.d.ts +245 -0
  182. package/dist/types/mixins/OxyServices.security.d.ts +78 -0
  183. package/dist/types/mixins/OxyServices.user.d.ts +182 -0
  184. package/dist/types/mixins/OxyServices.utility.d.ts +93 -0
  185. package/dist/types/mixins/index.d.ts +30 -0
  186. package/dist/types/mixins/mixinHelpers.d.ts +31 -0
  187. package/dist/types/models/interfaces.d.ts +415 -0
  188. package/dist/types/models/session.d.ts +27 -0
  189. package/dist/types/shared/index.d.ts +28 -0
  190. package/dist/types/shared/utils/colorUtils.d.ts +104 -0
  191. package/dist/types/shared/utils/debugUtils.d.ts +48 -0
  192. package/dist/types/shared/utils/errorUtils.d.ts +97 -0
  193. package/dist/types/shared/utils/index.d.ts +13 -0
  194. package/dist/types/shared/utils/networkUtils.d.ts +139 -0
  195. package/dist/types/shared/utils/themeUtils.d.ts +90 -0
  196. package/dist/types/utils/apiUtils.d.ts +53 -0
  197. package/dist/types/utils/asyncUtils.d.ts +58 -0
  198. package/dist/types/utils/cache.d.ts +127 -0
  199. package/dist/types/utils/deviceManager.d.ts +65 -0
  200. package/dist/types/utils/errorUtils.d.ts +46 -0
  201. package/dist/types/utils/index.d.ts +6 -0
  202. package/dist/types/utils/languageUtils.d.ts +37 -0
  203. package/dist/types/utils/loggerUtils.d.ts +48 -0
  204. package/dist/types/utils/platform.d.ts +40 -0
  205. package/dist/types/utils/requestUtils.d.ts +123 -0
  206. package/dist/types/utils/sessionUtils.d.ts +54 -0
  207. package/dist/types/utils/validationUtils.d.ts +85 -0
  208. package/package.json +84 -0
  209. package/src/AuthManager.ts +436 -0
  210. package/src/CrossDomainAuth.ts +307 -0
  211. package/src/HttpService.ts +752 -0
  212. package/src/OxyServices.base.ts +334 -0
  213. package/src/OxyServices.errors.ts +26 -0
  214. package/src/OxyServices.ts +129 -0
  215. package/src/constants/version.ts +15 -0
  216. package/src/crypto/index.ts +25 -0
  217. package/src/crypto/keyManager.ts +962 -0
  218. package/src/crypto/polyfill.ts +70 -0
  219. package/src/crypto/recoveryPhrase.ts +166 -0
  220. package/src/crypto/signatureService.ts +323 -0
  221. package/src/i18n/index.ts +75 -0
  222. package/src/i18n/locales/ar-SA.json +120 -0
  223. package/src/i18n/locales/ca-ES.json +120 -0
  224. package/src/i18n/locales/de-DE.json +120 -0
  225. package/src/i18n/locales/en-US.json +956 -0
  226. package/src/i18n/locales/es-ES.json +944 -0
  227. package/src/i18n/locales/fr-FR.json +120 -0
  228. package/src/i18n/locales/it-IT.json +120 -0
  229. package/src/i18n/locales/ja-JP.json +119 -0
  230. package/src/i18n/locales/ko-KR.json +120 -0
  231. package/src/i18n/locales/pt-PT.json +120 -0
  232. package/src/i18n/locales/zh-CN.json +120 -0
  233. package/src/index.ts +153 -0
  234. package/src/mixins/OxyServices.analytics.ts +53 -0
  235. package/src/mixins/OxyServices.assets.ts +412 -0
  236. package/src/mixins/OxyServices.auth.ts +358 -0
  237. package/src/mixins/OxyServices.developer.ts +114 -0
  238. package/src/mixins/OxyServices.devices.ts +119 -0
  239. package/src/mixins/OxyServices.features.ts +428 -0
  240. package/src/mixins/OxyServices.fedcm.ts +494 -0
  241. package/src/mixins/OxyServices.karma.ts +111 -0
  242. package/src/mixins/OxyServices.language.ts +127 -0
  243. package/src/mixins/OxyServices.location.ts +46 -0
  244. package/src/mixins/OxyServices.payment.ts +163 -0
  245. package/src/mixins/OxyServices.popup.ts +443 -0
  246. package/src/mixins/OxyServices.privacy.ts +182 -0
  247. package/src/mixins/OxyServices.redirect.ts +397 -0
  248. package/src/mixins/OxyServices.security.ts +103 -0
  249. package/src/mixins/OxyServices.user.ts +392 -0
  250. package/src/mixins/OxyServices.utility.ts +191 -0
  251. package/src/mixins/index.ts +91 -0
  252. package/src/mixins/mixinHelpers.ts +69 -0
  253. package/src/models/interfaces.ts +511 -0
  254. package/src/models/session.ts +30 -0
  255. package/src/shared/index.ts +82 -0
  256. package/src/shared/utils/colorUtils.ts +155 -0
  257. package/src/shared/utils/debugUtils.ts +73 -0
  258. package/src/shared/utils/errorUtils.ts +181 -0
  259. package/src/shared/utils/index.ts +59 -0
  260. package/src/shared/utils/networkUtils.ts +248 -0
  261. package/src/shared/utils/themeUtils.ts +115 -0
  262. package/src/types/bip39.d.ts +32 -0
  263. package/src/types/buffer.d.ts +97 -0
  264. package/src/types/color.d.ts +20 -0
  265. package/src/types/elliptic.d.ts +62 -0
  266. package/src/utils/apiUtils.ts +88 -0
  267. package/src/utils/asyncUtils.ts +252 -0
  268. package/src/utils/cache.ts +264 -0
  269. package/src/utils/deviceManager.ts +198 -0
  270. package/src/utils/errorUtils.ts +216 -0
  271. package/src/utils/index.ts +21 -0
  272. package/src/utils/languageUtils.ts +174 -0
  273. package/src/utils/loggerUtils.ts +153 -0
  274. package/src/utils/platform.ts +117 -0
  275. package/src/utils/requestUtils.ts +237 -0
  276. package/src/utils/sessionUtils.ts +206 -0
  277. package/src/utils/validationUtils.ts +174 -0
@@ -0,0 +1,380 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OxyServicesAssetsMixin = OxyServicesAssetsMixin;
4
+ function OxyServicesAssetsMixin(Base) {
5
+ return class extends Base {
6
+ constructor(...args) {
7
+ super(...args);
8
+ }
9
+ /**
10
+ * Delete file
11
+ */
12
+ async deleteFile(fileId) {
13
+ try {
14
+ return await this.makeRequest('DELETE', `/api/assets/${encodeURIComponent(fileId)}`, undefined, { cache: false });
15
+ }
16
+ catch (error) {
17
+ throw this.handleError(error);
18
+ }
19
+ }
20
+ /**
21
+ * Get file download URL (synchronous - uses stream endpoint for images to avoid ORB blocking)
22
+ */
23
+ getFileDownloadUrl(fileId, variant, expiresIn) {
24
+ const base = this.getBaseURL();
25
+ const params = new URLSearchParams();
26
+ if (variant)
27
+ params.set('variant', variant);
28
+ if (expiresIn)
29
+ params.set('expiresIn', String(expiresIn));
30
+ params.set('fallback', 'placeholderVisible');
31
+ const token = this.getClient().getAccessToken();
32
+ if (token)
33
+ params.set('token', token);
34
+ const qs = params.toString();
35
+ return `${base}/api/assets/${encodeURIComponent(fileId)}/stream${qs ? `?${qs}` : ''}`;
36
+ }
37
+ /**
38
+ * Get file download URL asynchronously (returns signed URL directly from CDN)
39
+ */
40
+ async getFileDownloadUrlAsync(fileId, variant, expiresIn) {
41
+ try {
42
+ const url = await this.fetchAssetDownloadUrl(fileId, variant, this.getAssetUrlCacheTTL(expiresIn), expiresIn);
43
+ return url || this.getFileDownloadUrl(fileId, variant, expiresIn);
44
+ }
45
+ catch (error) {
46
+ return this.getFileDownloadUrl(fileId, variant, expiresIn);
47
+ }
48
+ }
49
+ /**
50
+ * List user files
51
+ */
52
+ async listUserFiles(limit, offset) {
53
+ try {
54
+ const paramsObj = {};
55
+ if (limit)
56
+ paramsObj.limit = limit;
57
+ if (offset)
58
+ paramsObj.offset = offset;
59
+ return await this.makeRequest('GET', '/api/assets', paramsObj, {
60
+ cache: false,
61
+ });
62
+ }
63
+ catch (error) {
64
+ throw this.handleError(error);
65
+ }
66
+ }
67
+ /**
68
+ * Get account storage usage (server-side usage aggregated from assets)
69
+ */
70
+ async getAccountStorageUsage() {
71
+ try {
72
+ return await this.makeRequest('GET', '/api/storage/usage', undefined, {
73
+ cache: false,
74
+ });
75
+ }
76
+ catch (error) {
77
+ throw this.handleError(error);
78
+ }
79
+ }
80
+ /**
81
+ * Get file content as text
82
+ */
83
+ async getFileContentAsText(fileId, variant) {
84
+ try {
85
+ const downloadUrl = await this.fetchAssetDownloadUrl(fileId, variant, this.getAssetUrlCacheTTL());
86
+ if (!downloadUrl) {
87
+ throw new Error('No download URL returned for asset');
88
+ }
89
+ return await this.fetchAssetContent(downloadUrl, 'text');
90
+ }
91
+ catch (error) {
92
+ throw this.handleError(error);
93
+ }
94
+ }
95
+ /**
96
+ * Get file content as blob
97
+ */
98
+ async getFileContentAsBlob(fileId, variant) {
99
+ try {
100
+ const downloadUrl = await this.fetchAssetDownloadUrl(fileId, variant, this.getAssetUrlCacheTTL());
101
+ if (!downloadUrl) {
102
+ throw new Error('No download URL returned for asset');
103
+ }
104
+ return await this.fetchAssetContent(downloadUrl, 'blob');
105
+ }
106
+ catch (error) {
107
+ throw this.handleError(error);
108
+ }
109
+ }
110
+ /**
111
+ * Get batch access to multiple files
112
+ */
113
+ async getBatchFileAccess(fileIds, context) {
114
+ try {
115
+ return await this.makeRequest('POST', '/api/assets/batch-access', {
116
+ fileIds,
117
+ context
118
+ });
119
+ }
120
+ catch (error) {
121
+ throw this.handleError(error);
122
+ }
123
+ }
124
+ /**
125
+ * Get download URLs for multiple files efficiently
126
+ */
127
+ async getFileDownloadUrls(fileIds, context) {
128
+ const response = await this.getBatchFileAccess(fileIds, context);
129
+ const urls = {};
130
+ const results = response.results || {};
131
+ for (const [id, result] of Object.entries(results)) {
132
+ if (result.allowed && result.url) {
133
+ urls[id] = result.url;
134
+ }
135
+ }
136
+ return urls;
137
+ }
138
+ /**
139
+ * Upload raw file data
140
+ */
141
+ async uploadRawFile(file, visibility, metadata) {
142
+ return this.assetUpload(file, visibility, metadata);
143
+ }
144
+ /**
145
+ * Upload file using Central Asset Service
146
+ */
147
+ async assetUpload(file, visibility, metadata, onProgress) {
148
+ const fileName = file.name || 'unknown';
149
+ const fileSize = file.size;
150
+ try {
151
+ const formData = new FormData();
152
+ // Convert File to Blob to avoid read-only 'name' property error in Expo 54
153
+ // This is a known issue in Expo SDK 52+ where FormData tries to set the read-only 'name' property
154
+ let fileBlob;
155
+ if (file instanceof Blob) {
156
+ // Already a Blob, use directly
157
+ fileBlob = file;
158
+ }
159
+ else if (typeof file.blob === 'function') {
160
+ // Use async blob() method if available (Expo 54+ recommended approach)
161
+ fileBlob = await file.blob();
162
+ }
163
+ else {
164
+ // Fallback: create Blob from File (works in all environments)
165
+ fileBlob = new Blob([file], { type: file.type || 'application/octet-stream' });
166
+ }
167
+ formData.append('file', fileBlob, fileName);
168
+ if (visibility) {
169
+ formData.append('visibility', visibility);
170
+ }
171
+ if (metadata) {
172
+ formData.append('metadata', JSON.stringify(metadata));
173
+ }
174
+ const response = await this.getClient().request({
175
+ method: 'POST',
176
+ url: '/api/assets/upload',
177
+ data: formData,
178
+ cache: false,
179
+ });
180
+ if (onProgress && response) {
181
+ onProgress(100);
182
+ }
183
+ return response;
184
+ }
185
+ catch (error) {
186
+ console.error('File upload error:', error);
187
+ let errorMessage = 'File upload failed';
188
+ if (error instanceof Error) {
189
+ errorMessage = error.message || errorMessage;
190
+ }
191
+ else if (error && typeof error === 'object') {
192
+ if ('message' in error) {
193
+ errorMessage = String(error.message) || errorMessage;
194
+ }
195
+ else if ('error' in error && typeof error.error === 'string') {
196
+ errorMessage = error.error;
197
+ }
198
+ else if ('data' in error && error.data?.message) {
199
+ errorMessage = String(error.data.message);
200
+ }
201
+ }
202
+ else if (error) {
203
+ errorMessage = String(error) || errorMessage;
204
+ }
205
+ const contextError = error;
206
+ if (!contextError.fileContext) {
207
+ contextError.fileContext = {
208
+ fileName,
209
+ fileSize,
210
+ };
211
+ }
212
+ if (error instanceof Error && error.message) {
213
+ const handledError = this.handleError(contextError);
214
+ if (!handledError.message || handledError.message.trim() === 'An unexpected error occurred') {
215
+ handledError.message = errorMessage;
216
+ }
217
+ throw handledError;
218
+ }
219
+ const newError = new Error(errorMessage);
220
+ newError.fileContext = contextError.fileContext;
221
+ throw this.handleError(newError);
222
+ }
223
+ }
224
+ /**
225
+ * Link asset to an entity
226
+ */
227
+ async assetLink(fileId, app, entityType, entityId, visibility, webhookUrl) {
228
+ try {
229
+ const body = { app, entityType, entityId };
230
+ if (visibility)
231
+ body.visibility = visibility;
232
+ if (webhookUrl)
233
+ body.webhookUrl = webhookUrl;
234
+ return await this.makeRequest('POST', `/api/assets/${fileId}/links`, body, { cache: false });
235
+ }
236
+ catch (error) {
237
+ throw this.handleError(error);
238
+ }
239
+ }
240
+ /**
241
+ * Unlink asset from an entity
242
+ */
243
+ async assetUnlink(fileId, app, entityType, entityId) {
244
+ try {
245
+ return await this.makeRequest('DELETE', `/api/assets/${fileId}/links`, {
246
+ app,
247
+ entityType,
248
+ entityId
249
+ }, { cache: false });
250
+ }
251
+ catch (error) {
252
+ throw this.handleError(error);
253
+ }
254
+ }
255
+ /**
256
+ * Get asset metadata
257
+ */
258
+ async assetGet(fileId) {
259
+ try {
260
+ return await this.makeRequest('GET', `/api/assets/${fileId}`, undefined, {
261
+ cache: true,
262
+ cacheTTL: 5 * 60 * 1000,
263
+ });
264
+ }
265
+ catch (error) {
266
+ throw this.handleError(error);
267
+ }
268
+ }
269
+ /**
270
+ * Get asset URL (CDN or signed URL)
271
+ */
272
+ async assetGetUrl(fileId, variant, expiresIn) {
273
+ try {
274
+ const params = {};
275
+ if (variant)
276
+ params.variant = variant;
277
+ if (expiresIn)
278
+ params.expiresIn = expiresIn;
279
+ return await this.makeRequest('GET', `/api/assets/${fileId}/url`, params, {
280
+ cache: true,
281
+ cacheTTL: 10 * 60 * 1000,
282
+ });
283
+ }
284
+ catch (error) {
285
+ throw this.handleError(error);
286
+ }
287
+ }
288
+ /**
289
+ * Restore asset from trash
290
+ */
291
+ async assetRestore(fileId) {
292
+ try {
293
+ return await this.makeRequest('POST', `/api/assets/${fileId}/restore`, undefined, { cache: false });
294
+ }
295
+ catch (error) {
296
+ throw this.handleError(error);
297
+ }
298
+ }
299
+ /**
300
+ * Delete asset with optional force
301
+ */
302
+ async assetDelete(fileId, force = false) {
303
+ try {
304
+ const params = force ? { force: 'true' } : undefined;
305
+ return await this.makeRequest('DELETE', `/api/assets/${fileId}`, params, { cache: false });
306
+ }
307
+ catch (error) {
308
+ throw this.handleError(error);
309
+ }
310
+ }
311
+ /**
312
+ * Get list of available variants for an asset
313
+ */
314
+ async assetGetVariants(fileId) {
315
+ try {
316
+ const assetData = await this.assetGet(fileId);
317
+ return assetData.file?.variants || [];
318
+ }
319
+ catch (error) {
320
+ throw this.handleError(error);
321
+ }
322
+ }
323
+ /**
324
+ * Update asset visibility
325
+ */
326
+ async assetUpdateVisibility(fileId, visibility) {
327
+ try {
328
+ return await this.makeRequest('PATCH', `/api/assets/${fileId}/visibility`, {
329
+ visibility
330
+ }, { cache: false });
331
+ }
332
+ catch (error) {
333
+ throw this.handleError(error);
334
+ }
335
+ }
336
+ async uploadAvatar(file, userId, app = 'profiles') {
337
+ try {
338
+ const asset = await this.assetUpload(file, 'public');
339
+ await this.assetLink(asset.file.id, app, 'avatar', userId, 'public');
340
+ return asset;
341
+ }
342
+ catch (error) {
343
+ throw this.handleError(error);
344
+ }
345
+ }
346
+ async uploadProfileBanner(file, userId, app = 'profiles') {
347
+ try {
348
+ const asset = await this.assetUpload(file, 'public');
349
+ await this.assetLink(asset.file.id, app, 'profile-banner', userId, 'public');
350
+ return asset;
351
+ }
352
+ catch (error) {
353
+ throw this.handleError(error);
354
+ }
355
+ }
356
+ getAssetUrlCacheTTL(expiresIn) {
357
+ const desiredTtlMs = (expiresIn ?? 3600) * 1000;
358
+ return Math.min(desiredTtlMs, 10 * 60 * 1000);
359
+ }
360
+ async fetchAssetDownloadUrl(fileId, variant, cacheTTL, expiresIn) {
361
+ const params = {};
362
+ if (variant)
363
+ params.variant = variant;
364
+ if (expiresIn)
365
+ params.expiresIn = expiresIn;
366
+ const urlRes = await this.makeRequest('GET', `/api/assets/${encodeURIComponent(fileId)}/url`, Object.keys(params).length ? params : undefined, {
367
+ cache: true,
368
+ cacheTTL: cacheTTL ?? 10 * 60 * 1000,
369
+ });
370
+ return urlRes?.url || null;
371
+ }
372
+ async fetchAssetContent(url, type) {
373
+ const response = await fetch(url, { credentials: 'include' });
374
+ if (!response?.ok) {
375
+ throw new Error(`Failed to fetch asset content (status ${response?.status})`);
376
+ }
377
+ return type === 'text' ? response.text() : response.blob();
378
+ }
379
+ };
380
+ }
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OxyServicesAuthMixin = OxyServicesAuthMixin;
4
+ const OxyServices_errors_1 = require("../OxyServices.errors");
5
+ function OxyServicesAuthMixin(Base) {
6
+ return class extends Base {
7
+ constructor(...args) {
8
+ super(...args);
9
+ }
10
+ /**
11
+ * Register a new identity with public key authentication
12
+ * Identity is purely cryptographic - username and profile data are optional
13
+ *
14
+ * @param publicKey - The user's ECDSA public key (hex)
15
+ * @param signature - Signature of the registration request
16
+ * @param timestamp - Timestamp when the signature was created
17
+ */
18
+ async register(publicKey, signature, timestamp) {
19
+ try {
20
+ const res = await this.makeRequest('POST', '/api/auth/register', {
21
+ publicKey,
22
+ signature,
23
+ timestamp,
24
+ }, { cache: false });
25
+ if (!res || (typeof res === 'object' && Object.keys(res).length === 0)) {
26
+ throw new OxyServices_errors_1.OxyAuthenticationError('Registration failed', 'REGISTER_FAILED', 400);
27
+ }
28
+ return res;
29
+ }
30
+ catch (error) {
31
+ throw this.handleError(error);
32
+ }
33
+ }
34
+ /**
35
+ * Request an authentication challenge
36
+ * The client must sign this challenge with their private key
37
+ *
38
+ * @param publicKey - The user's public key
39
+ */
40
+ async requestChallenge(publicKey) {
41
+ try {
42
+ return await this.makeRequest('POST', '/api/auth/challenge', {
43
+ publicKey,
44
+ }, { cache: false });
45
+ }
46
+ catch (error) {
47
+ throw this.handleError(error);
48
+ }
49
+ }
50
+ /**
51
+ * Verify a signed challenge and create a session
52
+ *
53
+ * @param publicKey - The user's public key
54
+ * @param challenge - The challenge string from requestChallenge
55
+ * @param signature - Signature of the auth message
56
+ * @param timestamp - Timestamp when the signature was created
57
+ * @param deviceName - Optional device name
58
+ * @param deviceFingerprint - Optional device fingerprint
59
+ */
60
+ async verifyChallenge(publicKey, challenge, signature, timestamp, deviceName, deviceFingerprint) {
61
+ try {
62
+ return await this.makeRequest('POST', '/api/auth/verify', {
63
+ publicKey,
64
+ challenge,
65
+ signature,
66
+ timestamp,
67
+ deviceName,
68
+ deviceFingerprint,
69
+ }, { cache: false });
70
+ }
71
+ catch (error) {
72
+ throw this.handleError(error);
73
+ }
74
+ }
75
+ /**
76
+ * Check if a public key is already registered
77
+ */
78
+ async checkPublicKeyRegistered(publicKey) {
79
+ try {
80
+ return await this.makeRequest('GET', `/api/auth/check-publickey/${encodeURIComponent(publicKey)}`, undefined, { cache: false });
81
+ }
82
+ catch (error) {
83
+ throw this.handleError(error);
84
+ }
85
+ }
86
+ /**
87
+ * Get user by public key
88
+ */
89
+ async getUserByPublicKey(publicKey) {
90
+ try {
91
+ return await this.makeRequest('GET', `/api/auth/user/${encodeURIComponent(publicKey)}`, undefined, { cache: true, cacheTTL: 2 * 60 * 1000 });
92
+ }
93
+ catch (error) {
94
+ throw this.handleError(error);
95
+ }
96
+ }
97
+ /**
98
+ * Get user by session ID
99
+ */
100
+ async getUserBySession(sessionId) {
101
+ try {
102
+ return await this.makeRequest('GET', `/api/session/user/${sessionId}`, undefined, {
103
+ cache: true,
104
+ cacheTTL: 2 * 60 * 1000,
105
+ });
106
+ }
107
+ catch (error) {
108
+ throw this.handleError(error);
109
+ }
110
+ }
111
+ /**
112
+ * Batch get multiple user profiles by session IDs
113
+ */
114
+ async getUsersBySessions(sessionIds) {
115
+ try {
116
+ if (!Array.isArray(sessionIds) || sessionIds.length === 0) {
117
+ return [];
118
+ }
119
+ const uniqueSessionIds = Array.from(new Set(sessionIds)).sort();
120
+ return await this.makeRequest('POST', '/api/session/users/batch', { sessionIds: uniqueSessionIds }, {
121
+ cache: true,
122
+ cacheTTL: 2 * 60 * 1000,
123
+ deduplicate: true,
124
+ });
125
+ }
126
+ catch (error) {
127
+ throw this.handleError(error);
128
+ }
129
+ }
130
+ /**
131
+ * Get access token by session ID
132
+ */
133
+ async getTokenBySession(sessionId) {
134
+ try {
135
+ const res = await this.makeRequest('GET', `/api/session/token/${sessionId}`, undefined, { cache: false, retry: false });
136
+ this.setTokens(res.accessToken);
137
+ return res;
138
+ }
139
+ catch (error) {
140
+ throw this.handleError(error);
141
+ }
142
+ }
143
+ /**
144
+ * Get sessions by session ID
145
+ */
146
+ async getSessionsBySessionId(sessionId) {
147
+ try {
148
+ return await this.makeRequest('GET', `/api/session/sessions/${sessionId}`, undefined, {
149
+ cache: false,
150
+ });
151
+ }
152
+ catch (error) {
153
+ throw this.handleError(error);
154
+ }
155
+ }
156
+ /**
157
+ * Logout from a specific session
158
+ */
159
+ async logoutSession(sessionId, targetSessionId) {
160
+ try {
161
+ const url = targetSessionId
162
+ ? `/api/session/logout/${sessionId}/${targetSessionId}`
163
+ : `/api/session/logout/${sessionId}`;
164
+ await this.makeRequest('POST', url, undefined, { cache: false });
165
+ }
166
+ catch (error) {
167
+ throw this.handleError(error);
168
+ }
169
+ }
170
+ /**
171
+ * Logout from all sessions
172
+ */
173
+ async logoutAllSessions(sessionId) {
174
+ try {
175
+ await this.makeRequest('POST', `/api/session/logout-all/${sessionId}`, undefined, { cache: false });
176
+ }
177
+ catch (error) {
178
+ throw this.handleError(error);
179
+ }
180
+ }
181
+ /**
182
+ * Validate session
183
+ */
184
+ async validateSession(sessionId, options = {}) {
185
+ try {
186
+ const urlParams = {};
187
+ if (options.deviceFingerprint)
188
+ urlParams.deviceFingerprint = options.deviceFingerprint;
189
+ if (options.useHeaderValidation)
190
+ urlParams.useHeaderValidation = 'true';
191
+ return await this.makeRequest('GET', `/api/session/validate/${sessionId}`, urlParams, { cache: false });
192
+ }
193
+ catch (error) {
194
+ throw this.handleError(error);
195
+ }
196
+ }
197
+ /**
198
+ * Check username availability
199
+ */
200
+ async checkUsernameAvailability(username) {
201
+ try {
202
+ return await this.makeRequest('GET', `/api/auth/check-username/${username}`, undefined, { cache: false });
203
+ }
204
+ catch (error) {
205
+ throw this.handleError(error);
206
+ }
207
+ }
208
+ /**
209
+ * Check email availability
210
+ */
211
+ async checkEmailAvailability(email) {
212
+ try {
213
+ return await this.makeRequest('GET', `/api/auth/check-email/${email}`, undefined, { cache: false });
214
+ }
215
+ catch (error) {
216
+ throw this.handleError(error);
217
+ }
218
+ }
219
+ /**
220
+ * Register a new user with email/username and password
221
+ */
222
+ async signUp(username, email, password, deviceName, deviceFingerprint) {
223
+ try {
224
+ return await this.makeRequest('POST', '/api/auth/signup', {
225
+ username,
226
+ email,
227
+ password,
228
+ deviceName,
229
+ deviceFingerprint,
230
+ }, { cache: false });
231
+ }
232
+ catch (error) {
233
+ throw this.handleError(error);
234
+ }
235
+ }
236
+ /**
237
+ * Sign in with email or username and password
238
+ */
239
+ async signIn(identifier, password, deviceName, deviceFingerprint) {
240
+ try {
241
+ return await this.makeRequest('POST', '/api/auth/login', {
242
+ identifier,
243
+ password,
244
+ deviceName,
245
+ deviceFingerprint,
246
+ }, { cache: false });
247
+ }
248
+ catch (error) {
249
+ throw this.handleError(error);
250
+ }
251
+ }
252
+ /**
253
+ * Convenience helper for email sign-in
254
+ */
255
+ async signInWithEmail(email, password, deviceName, deviceFingerprint) {
256
+ return this.signIn(email, password, deviceName, deviceFingerprint);
257
+ }
258
+ };
259
+ }