@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,40 @@
1
+ export function OxyServicesLocationMixin(Base) {
2
+ return class extends Base {
3
+ constructor(...args) {
4
+ super(...args);
5
+ }
6
+ /**
7
+ * Update user location
8
+ * @param latitude - Latitude coordinate
9
+ * @param longitude - Longitude coordinate
10
+ * @returns Location update result
11
+ */
12
+ async updateLocation(latitude, longitude) {
13
+ try {
14
+ return await this.makeRequest('POST', '/api/location', {
15
+ latitude,
16
+ longitude
17
+ }, { cache: false });
18
+ }
19
+ catch (error) {
20
+ throw this.handleError(error);
21
+ }
22
+ }
23
+ /**
24
+ * Get nearby users
25
+ * @param radius - Optional search radius in meters
26
+ * @returns Array of nearby users
27
+ */
28
+ async getNearbyUsers(radius) {
29
+ try {
30
+ const params = radius ? { radius } : undefined;
31
+ return await this.makeRequest('GET', '/api/location/nearby', params, {
32
+ cache: false, // Don't cache location data - always get fresh data
33
+ });
34
+ }
35
+ catch (error) {
36
+ throw this.handleError(error);
37
+ }
38
+ }
39
+ };
40
+ }
@@ -0,0 +1,155 @@
1
+ import { CACHE_TIMES } from './mixinHelpers';
2
+ export function OxyServicesPaymentMixin(Base) {
3
+ return class extends Base {
4
+ constructor(...args) {
5
+ super(...args);
6
+ }
7
+ /**
8
+ * Create a payment
9
+ * @param data - Payment data
10
+ * @returns Created payment object
11
+ */
12
+ async createPayment(data) {
13
+ try {
14
+ return await this.makeRequest('POST', '/api/payments', data, { cache: false });
15
+ }
16
+ catch (error) {
17
+ throw this.handleError(error);
18
+ }
19
+ }
20
+ /**
21
+ * Get payment by ID
22
+ * @param paymentId - The payment ID
23
+ * @returns Payment object
24
+ */
25
+ async getPayment(paymentId) {
26
+ try {
27
+ return await this.makeRequest('GET', `/api/payments/${paymentId}`, undefined, {
28
+ cache: true,
29
+ cacheTTL: CACHE_TIMES.LONG,
30
+ });
31
+ }
32
+ catch (error) {
33
+ throw this.handleError(error);
34
+ }
35
+ }
36
+ /**
37
+ * Get user payments
38
+ * @returns Array of user payments
39
+ */
40
+ async getUserPayments() {
41
+ try {
42
+ return await this.makeRequest('GET', '/api/payments/user', undefined, {
43
+ cache: false, // Don't cache user payments - always get fresh data
44
+ });
45
+ }
46
+ catch (error) {
47
+ throw this.handleError(error);
48
+ }
49
+ }
50
+ /**
51
+ * Get user subscription
52
+ * @param userId - The user ID
53
+ * @returns Subscription object
54
+ */
55
+ async getSubscription(userId) {
56
+ try {
57
+ return await this.makeRequest('GET', `/api/subscription/${userId}`, undefined, {
58
+ cache: true,
59
+ cacheTTL: CACHE_TIMES.MEDIUM,
60
+ });
61
+ }
62
+ catch (error) {
63
+ throw this.handleError(error);
64
+ }
65
+ }
66
+ /**
67
+ * Get current user's subscription
68
+ * @returns Subscription object
69
+ */
70
+ async getCurrentUserSubscription() {
71
+ try {
72
+ const userId = this.getCurrentUserId();
73
+ if (!userId) {
74
+ throw new Error('User not authenticated');
75
+ }
76
+ return await this.getSubscription(userId);
77
+ }
78
+ catch (error) {
79
+ throw this.handleError(error);
80
+ }
81
+ }
82
+ /**
83
+ * Get user wallet
84
+ * @param userId - The user ID
85
+ * @returns Wallet object with balance
86
+ */
87
+ async getWallet(userId) {
88
+ try {
89
+ return await this.makeRequest('GET', `/api/wallet/${userId}`, undefined, {
90
+ cache: true,
91
+ cacheTTL: CACHE_TIMES.SHORT, // Cache wallet for short time as balance changes frequently
92
+ });
93
+ }
94
+ catch (error) {
95
+ throw this.handleError(error);
96
+ }
97
+ }
98
+ /**
99
+ * Get current user's wallet
100
+ * @returns Wallet object with balance
101
+ */
102
+ async getCurrentUserWallet() {
103
+ try {
104
+ const userId = this.getCurrentUserId();
105
+ if (!userId) {
106
+ throw new Error('User not authenticated');
107
+ }
108
+ return await this.getWallet(userId);
109
+ }
110
+ catch (error) {
111
+ throw this.handleError(error);
112
+ }
113
+ }
114
+ /**
115
+ * Get wallet transaction history
116
+ * @param userId - The user ID
117
+ * @param options - Pagination options
118
+ * @returns Transaction history
119
+ */
120
+ async getWalletTransactions(userId, options) {
121
+ try {
122
+ const params = new URLSearchParams();
123
+ if (options?.limit)
124
+ params.append('limit', options.limit.toString());
125
+ if (options?.offset)
126
+ params.append('offset', options.offset.toString());
127
+ const queryString = params.toString();
128
+ const url = `/api/wallet/transactions/${userId}${queryString ? `?${queryString}` : ''}`;
129
+ return await this.makeRequest('GET', url, undefined, {
130
+ cache: false, // Don't cache transactions - always get fresh data
131
+ });
132
+ }
133
+ catch (error) {
134
+ throw this.handleError(error);
135
+ }
136
+ }
137
+ /**
138
+ * Get current user's wallet transaction history
139
+ * @param options - Pagination options
140
+ * @returns Transaction history
141
+ */
142
+ async getCurrentUserWalletTransactions(options) {
143
+ try {
144
+ const userId = this.getCurrentUserId();
145
+ if (!userId) {
146
+ throw new Error('User not authenticated');
147
+ }
148
+ return await this.getWalletTransactions(userId, options);
149
+ }
150
+ catch (error) {
151
+ throw this.handleError(error);
152
+ }
153
+ }
154
+ };
155
+ }
@@ -0,0 +1,369 @@
1
+ import { OxyAuthenticationError } from '../OxyServices.errors';
2
+ import { createDebugLogger } from '../shared/utils/debugUtils';
3
+ const debug = createDebugLogger('PopupAuth');
4
+ /**
5
+ * Popup-based Cross-Domain Authentication Mixin
6
+ *
7
+ * Implements OAuth2-style authentication using popup windows and postMessage.
8
+ * This is the primary authentication method for modern browsers, providing a
9
+ * Google-like experience without full page redirects.
10
+ *
11
+ * Flow:
12
+ * 1. Opens small popup window to auth.oxy.so
13
+ * 2. User signs in (auth.oxy.so sets its own first-party cookie)
14
+ * 3. auth.oxy.so sends token back via postMessage
15
+ * 4. Popup closes, parent app has the session
16
+ *
17
+ * Features:
18
+ * - No full page redirect (preserves app state)
19
+ * - Works across different domains (homiio.com, mention.earth, etc.)
20
+ * - Silent refresh using hidden iframe for seamless SSO
21
+ * - CSRF protection via state parameter
22
+ * - XSS protection via origin validation
23
+ *
24
+ * Browser Support: All modern browsers (IE11+)
25
+ */
26
+ export function OxyServicesPopupAuthMixin(Base) {
27
+ var _a;
28
+ return _a = class extends Base {
29
+ constructor(...args) {
30
+ super(...args);
31
+ }
32
+ /**
33
+ * Sign in using popup window
34
+ *
35
+ * Opens a centered popup window to auth.oxy.so where the user can sign in.
36
+ * The popup automatically closes after successful authentication and the
37
+ * session is returned to the parent window.
38
+ *
39
+ * @param options - Popup configuration options
40
+ * @returns Session with access token and user data
41
+ * @throws {OxyAuthenticationError} If popup is blocked or auth fails
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const handleSignIn = async () => {
46
+ * try {
47
+ * const session = await oxyServices.signInWithPopup();
48
+ * console.log('Signed in:', session.user);
49
+ * } catch (error) {
50
+ * if (error.message.includes('blocked')) {
51
+ * alert('Please allow popups for this site');
52
+ * }
53
+ * }
54
+ * };
55
+ * ```
56
+ */
57
+ async signInWithPopup(options = {}) {
58
+ if (typeof window === 'undefined') {
59
+ throw new OxyAuthenticationError('Popup authentication requires browser environment');
60
+ }
61
+ const state = this.generateState();
62
+ const nonce = this.generateNonce();
63
+ // Store state for CSRF protection
64
+ this.storeAuthState(state, nonce);
65
+ const width = options.width || this.constructor.POPUP_WIDTH;
66
+ const height = options.height || this.constructor.POPUP_HEIGHT;
67
+ const timeout = options.timeout || this.constructor.POPUP_TIMEOUT;
68
+ const mode = options.mode || 'login';
69
+ const authUrl = this.buildAuthUrl({
70
+ mode,
71
+ state,
72
+ nonce,
73
+ clientId: window.location.origin,
74
+ redirectUri: `${this.constructor.AUTH_URL}/auth/callback`,
75
+ });
76
+ const popup = this.openCenteredPopup(authUrl, 'Oxy Sign In', width, height);
77
+ if (!popup) {
78
+ throw new OxyAuthenticationError('Popup blocked. Please allow popups for this site and try again.');
79
+ }
80
+ try {
81
+ const session = await this.waitForPopupAuth(popup, state, timeout);
82
+ // Store access token if present
83
+ if (session && session.accessToken) {
84
+ this.httpService.setTokens(session.accessToken);
85
+ }
86
+ // Fetch user data using the session ID
87
+ // The callback page only sends sessionId/accessToken, not user data
88
+ if (session && session.sessionId && !session.user) {
89
+ try {
90
+ const userData = await this.makeRequest('GET', `/api/session/user/${session.sessionId}`, undefined, { cache: false });
91
+ if (userData) {
92
+ session.user = userData;
93
+ }
94
+ }
95
+ catch (userError) {
96
+ debug.warn('Failed to fetch user data:', userError);
97
+ // Continue without user data - caller can fetch separately
98
+ }
99
+ }
100
+ return session;
101
+ }
102
+ catch (error) {
103
+ throw error;
104
+ }
105
+ finally {
106
+ this.clearAuthState(state);
107
+ }
108
+ }
109
+ /**
110
+ * Sign up using popup window
111
+ *
112
+ * Same as signInWithPopup but opens the signup page by default.
113
+ *
114
+ * @param options - Popup configuration options
115
+ * @returns Session with access token and user data
116
+ */
117
+ async signUpWithPopup(options = {}) {
118
+ return this.signInWithPopup({ ...options, mode: 'signup' });
119
+ }
120
+ /**
121
+ * Silent sign-in using hidden iframe
122
+ *
123
+ * Attempts to automatically re-authenticate the user without any UI.
124
+ * This is what enables seamless SSO across all Oxy domains.
125
+ *
126
+ * How it works:
127
+ * 1. Creates hidden iframe pointing to auth.oxy.so/silent-auth
128
+ * 2. If user has valid session at auth.oxy.so, it sends token via postMessage
129
+ * 3. If not, iframe responds with null (no error thrown)
130
+ *
131
+ * This should be called on app startup to check for existing sessions.
132
+ *
133
+ * @param options - Silent auth options
134
+ * @returns Session if user is signed in, null otherwise
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * useEffect(() => {
139
+ * const checkAuth = async () => {
140
+ * const session = await oxyServices.silentSignIn();
141
+ * if (session) {
142
+ * setUser(session.user);
143
+ * }
144
+ * };
145
+ * checkAuth();
146
+ * }, []);
147
+ * ```
148
+ */
149
+ async silentSignIn(options = {}) {
150
+ if (typeof window === 'undefined') {
151
+ return null;
152
+ }
153
+ const timeout = options.timeout || this.constructor.SILENT_TIMEOUT;
154
+ const nonce = this.generateNonce();
155
+ const clientId = window.location.origin;
156
+ const iframe = document.createElement('iframe');
157
+ iframe.style.display = 'none';
158
+ iframe.style.position = 'absolute';
159
+ iframe.style.width = '0';
160
+ iframe.style.height = '0';
161
+ iframe.style.border = 'none';
162
+ const silentUrl = `${this.constructor.AUTH_URL}/auth/silent?` + `client_id=${encodeURIComponent(clientId)}&` + `nonce=${nonce}`;
163
+ iframe.src = silentUrl;
164
+ document.body.appendChild(iframe);
165
+ try {
166
+ const session = await this.waitForIframeAuth(iframe, timeout, clientId);
167
+ if (session && session.accessToken) {
168
+ this.httpService.setTokens(session.accessToken);
169
+ }
170
+ return session;
171
+ }
172
+ catch (error) {
173
+ return null;
174
+ }
175
+ finally {
176
+ document.body.removeChild(iframe);
177
+ }
178
+ }
179
+ /**
180
+ * Open a centered popup window
181
+ *
182
+ * @private
183
+ */
184
+ openCenteredPopup(url, title, width, height) {
185
+ const left = window.screenX + (window.outerWidth - width) / 2;
186
+ const top = window.screenY + (window.outerHeight - height) / 2;
187
+ const features = [
188
+ `width=${width}`,
189
+ `height=${height}`,
190
+ `left=${left}`,
191
+ `top=${top}`,
192
+ 'toolbar=no',
193
+ 'menubar=no',
194
+ 'scrollbars=yes',
195
+ 'resizable=yes',
196
+ 'status=no',
197
+ 'location=no',
198
+ ].join(',');
199
+ return window.open(url, title, features);
200
+ }
201
+ /**
202
+ * Wait for authentication response from popup
203
+ *
204
+ * @private
205
+ */
206
+ async waitForPopupAuth(popup, expectedState, timeout) {
207
+ return new Promise((resolve, reject) => {
208
+ const timeoutId = setTimeout(() => {
209
+ cleanup();
210
+ reject(new OxyAuthenticationError('Authentication timeout'));
211
+ }, timeout);
212
+ const messageHandler = (event) => {
213
+ const authUrl = this.constructor.AUTH_URL;
214
+ // Log all messages for debugging
215
+ if (event.data && typeof event.data === 'object' && event.data.type) {
216
+ debug.log('Message received:', {
217
+ origin: event.origin,
218
+ expectedOrigin: authUrl,
219
+ type: event.data.type,
220
+ hasSession: !!event.data.session,
221
+ hasError: !!event.data.error,
222
+ });
223
+ }
224
+ // CRITICAL: Verify origin to prevent XSS attacks
225
+ if (event.origin !== authUrl) {
226
+ return;
227
+ }
228
+ const { type, state, session, error } = event.data;
229
+ if (type !== 'oxy_auth_response') {
230
+ return;
231
+ }
232
+ debug.log('Valid auth response:', { state, expectedState, hasSession: !!session, error });
233
+ // Verify state parameter to prevent CSRF attacks
234
+ if (state !== expectedState) {
235
+ cleanup();
236
+ debug.error('State mismatch');
237
+ reject(new OxyAuthenticationError('Invalid state parameter. Possible CSRF attack.'));
238
+ return;
239
+ }
240
+ cleanup();
241
+ if (error) {
242
+ debug.error('Auth error:', error);
243
+ reject(new OxyAuthenticationError(error));
244
+ }
245
+ else if (session) {
246
+ debug.log('Session received successfully');
247
+ resolve(session);
248
+ }
249
+ else {
250
+ debug.error('No session in response');
251
+ reject(new OxyAuthenticationError('No session received from authentication server'));
252
+ }
253
+ };
254
+ // Poll to detect if user closed the popup
255
+ const pollInterval = setInterval(() => {
256
+ if (popup.closed) {
257
+ cleanup();
258
+ reject(new OxyAuthenticationError('Authentication cancelled by user'));
259
+ }
260
+ }, 500);
261
+ const cleanup = () => {
262
+ clearTimeout(timeoutId);
263
+ clearInterval(pollInterval);
264
+ window.removeEventListener('message', messageHandler);
265
+ if (!popup.closed) {
266
+ popup.close();
267
+ }
268
+ };
269
+ window.addEventListener('message', messageHandler);
270
+ });
271
+ }
272
+ /**
273
+ * Wait for authentication response from iframe
274
+ *
275
+ * @private
276
+ */
277
+ async waitForIframeAuth(iframe, timeout, expectedOrigin) {
278
+ return new Promise((resolve) => {
279
+ const timeoutId = setTimeout(() => {
280
+ cleanup();
281
+ resolve(null); // Silent failure - don't throw
282
+ }, timeout);
283
+ const messageHandler = (event) => {
284
+ // Verify origin
285
+ if (event.origin !== this.constructor.AUTH_URL) {
286
+ return;
287
+ }
288
+ const { type, session } = event.data;
289
+ if (type !== 'oxy_silent_auth') {
290
+ return;
291
+ }
292
+ cleanup();
293
+ resolve(session || null);
294
+ };
295
+ const cleanup = () => {
296
+ clearTimeout(timeoutId);
297
+ window.removeEventListener('message', messageHandler);
298
+ };
299
+ window.addEventListener('message', messageHandler);
300
+ });
301
+ }
302
+ /**
303
+ * Build authentication URL with query parameters
304
+ *
305
+ * @private
306
+ */
307
+ buildAuthUrl(params) {
308
+ const url = new URL(`${this.constructor.AUTH_URL}/${params.mode}`);
309
+ url.searchParams.set('response_type', 'token');
310
+ url.searchParams.set('client_id', params.clientId);
311
+ url.searchParams.set('redirect_uri', params.redirectUri);
312
+ url.searchParams.set('state', params.state);
313
+ url.searchParams.set('nonce', params.nonce);
314
+ return url.toString();
315
+ }
316
+ /**
317
+ * Generate cryptographically secure state for CSRF protection
318
+ *
319
+ * @private
320
+ */
321
+ generateState() {
322
+ if (typeof window !== 'undefined' && window.crypto && window.crypto.randomUUID) {
323
+ return window.crypto.randomUUID();
324
+ }
325
+ return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
326
+ }
327
+ /**
328
+ * Generate nonce for replay attack prevention
329
+ *
330
+ * @private
331
+ */
332
+ generateNonce() {
333
+ if (typeof window !== 'undefined' && window.crypto && window.crypto.randomUUID) {
334
+ return window.crypto.randomUUID();
335
+ }
336
+ return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
337
+ }
338
+ /**
339
+ * Store auth state in session storage
340
+ *
341
+ * @private
342
+ */
343
+ storeAuthState(state, nonce) {
344
+ if (typeof window !== 'undefined' && window.sessionStorage) {
345
+ sessionStorage.setItem(`oxy_auth_state_${state}`, JSON.stringify({ nonce, timestamp: Date.now() }));
346
+ }
347
+ }
348
+ /**
349
+ * Clear auth state from session storage
350
+ *
351
+ * @private
352
+ */
353
+ clearAuthState(state) {
354
+ if (typeof window !== 'undefined' && window.sessionStorage) {
355
+ sessionStorage.removeItem(`oxy_auth_state_${state}`);
356
+ }
357
+ }
358
+ },
359
+ _a.AUTH_URL = 'https://auth.oxy.so',
360
+ _a.POPUP_WIDTH = 500,
361
+ _a.POPUP_HEIGHT = 700,
362
+ _a.POPUP_TIMEOUT = 60000 // 1 minute
363
+ ,
364
+ _a.SILENT_TIMEOUT = 5000 // 5 seconds
365
+ ,
366
+ _a;
367
+ }
368
+ // Export the mixin function as both named and default
369
+ export { OxyServicesPopupAuthMixin as PopupAuthMixin };