@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,355 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OxyServicesUserMixin = OxyServicesUserMixin;
4
+ const apiUtils_1 = require("../utils/apiUtils");
5
+ function OxyServicesUserMixin(Base) {
6
+ return class extends Base {
7
+ constructor(...args) {
8
+ super(...args);
9
+ }
10
+ /**
11
+ * Get profile by username
12
+ */
13
+ async getProfileByUsername(username) {
14
+ try {
15
+ return await this.makeRequest('GET', `/api/profiles/username/${username}`, undefined, {
16
+ cache: true,
17
+ cacheTTL: 5 * 60 * 1000, // 5 minutes cache for profiles
18
+ });
19
+ }
20
+ catch (error) {
21
+ throw this.handleError(error);
22
+ }
23
+ }
24
+ /**
25
+ * Search user profiles
26
+ */
27
+ async searchProfiles(query, pagination) {
28
+ try {
29
+ const params = { query, ...pagination };
30
+ const searchParams = (0, apiUtils_1.buildSearchParams)(params);
31
+ const paramsObj = Object.fromEntries(searchParams.entries());
32
+ const response = await this.makeRequest('GET', '/api/profiles/search', paramsObj, {
33
+ cache: true,
34
+ cacheTTL: 2 * 60 * 1000, // 2 minutes cache
35
+ });
36
+ // New API shape: { data: User[], pagination: {...} }
37
+ const isSearchProfilesResponse = (payload) => typeof payload === 'object' &&
38
+ payload !== null &&
39
+ Array.isArray(payload.data);
40
+ if (isSearchProfilesResponse(response)) {
41
+ const typedResponse = response;
42
+ const paginationInfo = typedResponse.pagination ?? {
43
+ total: typedResponse.data.length,
44
+ limit: pagination?.limit ?? typedResponse.data.length,
45
+ offset: pagination?.offset ?? 0,
46
+ hasMore: typedResponse.data.length === (pagination?.limit ?? typedResponse.data.length) &&
47
+ (pagination?.limit ?? typedResponse.data.length) > 0,
48
+ };
49
+ return {
50
+ data: typedResponse.data,
51
+ pagination: paginationInfo,
52
+ };
53
+ }
54
+ // Legacy API shape: returns raw User[]
55
+ if (Array.isArray(response)) {
56
+ const fallbackLimit = pagination?.limit ?? response.length;
57
+ const fallbackPagination = {
58
+ total: response.length,
59
+ limit: fallbackLimit,
60
+ offset: pagination?.offset ?? 0,
61
+ hasMore: fallbackLimit > 0 && response.length === fallbackLimit,
62
+ };
63
+ return { data: response, pagination: fallbackPagination };
64
+ }
65
+ // If response is unexpected, throw an error
66
+ throw new Error('Unexpected search response format');
67
+ }
68
+ catch (error) {
69
+ throw this.handleError(error);
70
+ }
71
+ }
72
+ /**
73
+ * Get profile recommendations
74
+ */
75
+ async getProfileRecommendations() {
76
+ return this.withAuthRetry(async () => {
77
+ return await this.makeRequest('GET', '/api/profiles/recommendations', undefined, { cache: true });
78
+ }, 'getProfileRecommendations');
79
+ }
80
+ /**
81
+ * Get user by ID
82
+ */
83
+ async getUserById(userId) {
84
+ try {
85
+ return await this.makeRequest('GET', `/api/users/${userId}`, undefined, {
86
+ cache: true,
87
+ cacheTTL: 5 * 60 * 1000, // 5 minutes cache
88
+ });
89
+ }
90
+ catch (error) {
91
+ throw this.handleError(error);
92
+ }
93
+ }
94
+ /**
95
+ * Get current user
96
+ */
97
+ async getCurrentUser() {
98
+ return this.withAuthRetry(async () => {
99
+ return await this.makeRequest('GET', '/api/users/me', undefined, {
100
+ cache: true,
101
+ cacheTTL: 1 * 60 * 1000, // 1 minute cache for current user
102
+ });
103
+ }, 'getCurrentUser');
104
+ }
105
+ /**
106
+ * Update user profile
107
+ * TanStack Query handles offline queuing automatically
108
+ */
109
+ async updateProfile(updates) {
110
+ try {
111
+ return await this.makeRequest('PUT', '/api/users/me', updates, { cache: false });
112
+ }
113
+ catch (error) {
114
+ const errorAny = error;
115
+ const errorMessage = error instanceof Error ? error.message : String(error);
116
+ const status = errorAny?.status || errorAny?.response?.status;
117
+ // Check if it's an authentication error (401)
118
+ const isAuthError = status === 401 ||
119
+ errorMessage.includes('Authentication required') ||
120
+ errorMessage.includes('Invalid or missing authorization header');
121
+ // If authentication error and we don't have a token, this might be an offline session
122
+ // The caller should handle syncing the session before retrying
123
+ if (isAuthError && !this.hasValidToken()) {
124
+ // Re-throw with a specific message so the caller knows to sync
125
+ throw new Error('AUTH_REQUIRED_OFFLINE_SESSION: Session needs to be synced to get a token');
126
+ }
127
+ throw this.handleError(error);
128
+ }
129
+ }
130
+ /**
131
+ * Get privacy settings for a user
132
+ * @param userId - The user ID (defaults to current user)
133
+ */
134
+ async getPrivacySettings(userId) {
135
+ try {
136
+ const id = userId || (await this.getCurrentUser()).id;
137
+ return await this.makeRequest('GET', `/api/privacy/${id}/privacy`, undefined, {
138
+ cache: true,
139
+ cacheTTL: 2 * 60 * 1000, // 2 minutes cache
140
+ });
141
+ }
142
+ catch (error) {
143
+ throw this.handleError(error);
144
+ }
145
+ }
146
+ /**
147
+ * Update privacy settings
148
+ * @param settings - Partial privacy settings object
149
+ * @param userId - The user ID (defaults to current user)
150
+ */
151
+ async updatePrivacySettings(settings, userId) {
152
+ try {
153
+ const id = userId || (await this.getCurrentUser()).id;
154
+ return await this.makeRequest('PATCH', `/api/privacy/${id}/privacy`, settings, {
155
+ cache: false,
156
+ });
157
+ }
158
+ catch (error) {
159
+ throw this.handleError(error);
160
+ }
161
+ }
162
+ /**
163
+ * Request account verification
164
+ */
165
+ async requestAccountVerification(reason, evidence) {
166
+ try {
167
+ return await this.makeRequest('POST', '/api/users/verify/request', {
168
+ reason,
169
+ evidence,
170
+ }, { cache: false });
171
+ }
172
+ catch (error) {
173
+ throw this.handleError(error);
174
+ }
175
+ }
176
+ /**
177
+ * Download account data export
178
+ */
179
+ async downloadAccountData(format = 'json') {
180
+ try {
181
+ // Use httpService for blob responses (it handles blob responses automatically)
182
+ const result = await this.getClient().request({
183
+ method: 'GET',
184
+ url: `/api/users/me/data`,
185
+ params: { format },
186
+ cache: false,
187
+ });
188
+ return result;
189
+ }
190
+ catch (error) {
191
+ throw this.handleError(error);
192
+ }
193
+ }
194
+ /**
195
+ * Delete account permanently
196
+ * @param password - User password for confirmation
197
+ * @param confirmText - Confirmation text (usually username)
198
+ */
199
+ async deleteAccount(password, confirmText) {
200
+ try {
201
+ return await this.makeRequest('DELETE', '/api/users/me', {
202
+ password,
203
+ confirmText,
204
+ }, { cache: false });
205
+ }
206
+ catch (error) {
207
+ throw this.handleError(error);
208
+ }
209
+ }
210
+ /**
211
+ * Follow a user
212
+ */
213
+ async followUser(userId) {
214
+ try {
215
+ return await this.makeRequest('POST', `/api/users/${userId}/follow`, undefined, { cache: false });
216
+ }
217
+ catch (error) {
218
+ throw this.handleError(error);
219
+ }
220
+ }
221
+ /**
222
+ * Unfollow a user
223
+ */
224
+ async unfollowUser(userId) {
225
+ try {
226
+ return await this.makeRequest('DELETE', `/api/users/${userId}/follow`, undefined, { cache: false });
227
+ }
228
+ catch (error) {
229
+ throw this.handleError(error);
230
+ }
231
+ }
232
+ /**
233
+ * Get follow status
234
+ */
235
+ async getFollowStatus(userId) {
236
+ try {
237
+ return await this.makeRequest('GET', `/api/users/${userId}/follow-status`, undefined, {
238
+ cache: true,
239
+ cacheTTL: 1 * 60 * 1000, // 1 minute cache
240
+ });
241
+ }
242
+ catch (error) {
243
+ throw this.handleError(error);
244
+ }
245
+ }
246
+ /**
247
+ * Get user followers
248
+ */
249
+ async getUserFollowers(userId, pagination) {
250
+ try {
251
+ const params = (0, apiUtils_1.buildPaginationParams)(pagination || {});
252
+ const response = await this.makeRequest('GET', `/api/users/${userId}/followers`, params, {
253
+ cache: true,
254
+ cacheTTL: 2 * 60 * 1000, // 2 minutes cache
255
+ });
256
+ return {
257
+ followers: response.data || [],
258
+ total: response.pagination.total,
259
+ hasMore: response.pagination.hasMore,
260
+ };
261
+ }
262
+ catch (error) {
263
+ throw this.handleError(error);
264
+ }
265
+ }
266
+ /**
267
+ * Get user following
268
+ */
269
+ async getUserFollowing(userId, pagination) {
270
+ try {
271
+ const params = (0, apiUtils_1.buildPaginationParams)(pagination || {});
272
+ const response = await this.makeRequest('GET', `/api/users/${userId}/following`, params, {
273
+ cache: true,
274
+ cacheTTL: 2 * 60 * 1000, // 2 minutes cache
275
+ });
276
+ return {
277
+ following: response.data || [],
278
+ total: response.pagination.total,
279
+ hasMore: response.pagination.hasMore,
280
+ };
281
+ }
282
+ catch (error) {
283
+ throw this.handleError(error);
284
+ }
285
+ }
286
+ /**
287
+ * Get notifications
288
+ */
289
+ async getNotifications() {
290
+ return this.withAuthRetry(async () => {
291
+ return await this.makeRequest('GET', '/api/notifications', undefined, {
292
+ cache: false, // Don't cache notifications - always get fresh data
293
+ });
294
+ }, 'getNotifications');
295
+ }
296
+ /**
297
+ * Get unread notification count
298
+ */
299
+ async getUnreadCount() {
300
+ try {
301
+ const res = await this.makeRequest('GET', '/api/notifications/unread-count', undefined, {
302
+ cache: false, // Don't cache unread count - always get fresh data
303
+ });
304
+ return res.count;
305
+ }
306
+ catch (error) {
307
+ throw this.handleError(error);
308
+ }
309
+ }
310
+ /**
311
+ * Create notification
312
+ */
313
+ async createNotification(data) {
314
+ try {
315
+ return await this.makeRequest('POST', '/api/notifications', data, { cache: false });
316
+ }
317
+ catch (error) {
318
+ throw this.handleError(error);
319
+ }
320
+ }
321
+ /**
322
+ * Mark notification as read
323
+ */
324
+ async markNotificationAsRead(notificationId) {
325
+ try {
326
+ await this.makeRequest('PUT', `/api/notifications/${notificationId}/read`, undefined, { cache: false });
327
+ }
328
+ catch (error) {
329
+ throw this.handleError(error);
330
+ }
331
+ }
332
+ /**
333
+ * Mark all notifications as read
334
+ */
335
+ async markAllNotificationsAsRead() {
336
+ try {
337
+ await this.makeRequest('PUT', '/api/notifications/read-all', undefined, { cache: false });
338
+ }
339
+ catch (error) {
340
+ throw this.handleError(error);
341
+ }
342
+ }
343
+ /**
344
+ * Delete notification
345
+ */
346
+ async deleteNotification(notificationId) {
347
+ try {
348
+ await this.makeRequest('DELETE', `/api/notifications/${notificationId}`, undefined, { cache: false });
349
+ }
350
+ catch (error) {
351
+ throw this.handleError(error);
352
+ }
353
+ }
354
+ };
355
+ }
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OxyServicesUtilityMixin = OxyServicesUtilityMixin;
4
+ /**
5
+ * Utility Methods Mixin
6
+ *
7
+ * Provides utility methods including link metadata fetching
8
+ * and Express.js authentication middleware
9
+ */
10
+ const jwt_decode_1 = require("jwt-decode");
11
+ const mixinHelpers_1 = require("./mixinHelpers");
12
+ function OxyServicesUtilityMixin(Base) {
13
+ return class extends Base {
14
+ constructor(...args) {
15
+ super(...args);
16
+ }
17
+ /**
18
+ * Fetch link metadata
19
+ */
20
+ async fetchLinkMetadata(url) {
21
+ try {
22
+ return await this.makeRequest('GET', '/api/link-metadata', { url }, {
23
+ cache: true,
24
+ cacheTTL: mixinHelpers_1.CACHE_TIMES.EXTRA_LONG,
25
+ });
26
+ }
27
+ catch (error) {
28
+ throw this.handleError(error);
29
+ }
30
+ }
31
+ /**
32
+ * Simple Express.js authentication middleware
33
+ *
34
+ * Built-in authentication middleware that validates JWT tokens and adds user data to requests.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Basic usage - just add it to your routes
39
+ * app.use('/api/protected', oxyServices.auth());
40
+ *
41
+ * // With debug logging
42
+ * app.use('/api/protected', oxyServices.auth({ debug: true }));
43
+ *
44
+ * // With custom error handling
45
+ * app.use('/api/protected', oxyServices.auth({
46
+ * onError: (error) => console.error('Auth failed:', error)
47
+ * }));
48
+ *
49
+ * // Load full user data
50
+ * app.use('/api/protected', oxyServices.auth({ loadUser: true }));
51
+ * ```
52
+ *
53
+ * @param options Optional configuration
54
+ * @param options.debug Enable debug logging (default: false)
55
+ * @param options.onError Custom error handler
56
+ * @param options.loadUser Load full user data (default: false for performance)
57
+ * @param options.session Use session-based validation (default: false)
58
+ * @returns Express middleware function
59
+ */
60
+ auth(options = {}) {
61
+ const { debug = false, onError, loadUser = false, session = false } = options;
62
+ // Return a synchronous middleware function
63
+ return (req, res, next) => {
64
+ try {
65
+ // Extract token from Authorization header
66
+ const authHeader = req.headers['authorization'];
67
+ const token = authHeader?.startsWith('Bearer ') ? authHeader.substring(7) : null;
68
+ if (debug) {
69
+ console.log(`🔐 Auth: Processing ${req.method} ${req.path}`);
70
+ console.log(`🔐 Auth: Token present: ${!!token}`);
71
+ }
72
+ if (!token) {
73
+ const error = {
74
+ message: 'Access token required',
75
+ code: 'MISSING_TOKEN',
76
+ status: 401
77
+ };
78
+ if (debug)
79
+ console.log(`❌ Auth: Missing token`);
80
+ if (onError)
81
+ return onError(error);
82
+ return res.status(401).json(error);
83
+ }
84
+ // Decode and validate token
85
+ let decoded;
86
+ try {
87
+ decoded = (0, jwt_decode_1.jwtDecode)(token);
88
+ if (debug) {
89
+ console.log(`🔐 Auth: Token decoded, User ID: ${decoded.userId || decoded.id}`);
90
+ }
91
+ }
92
+ catch (decodeError) {
93
+ const error = {
94
+ message: 'Invalid token format',
95
+ code: 'INVALID_TOKEN_FORMAT',
96
+ status: 403
97
+ };
98
+ if (debug)
99
+ console.log(`❌ Auth: Token decode failed`);
100
+ if (onError)
101
+ return onError(error);
102
+ return res.status(403).json(error);
103
+ }
104
+ const userId = decoded.userId || decoded.id;
105
+ if (!userId) {
106
+ const error = {
107
+ message: 'Token missing user ID',
108
+ code: 'INVALID_TOKEN_PAYLOAD',
109
+ status: 403
110
+ };
111
+ if (debug)
112
+ console.log(`❌ Auth: Token missing user ID`);
113
+ if (onError)
114
+ return onError(error);
115
+ return res.status(403).json(error);
116
+ }
117
+ // Check token expiration
118
+ if (decoded.exp && decoded.exp < Math.floor(Date.now() / 1000)) {
119
+ const error = {
120
+ message: 'Token expired',
121
+ code: 'TOKEN_EXPIRED',
122
+ status: 403
123
+ };
124
+ if (debug)
125
+ console.log(`❌ Auth: Token expired`);
126
+ if (onError)
127
+ return onError(error);
128
+ return res.status(403).json(error);
129
+ }
130
+ // For now, skip session validation to keep it simple
131
+ // Session validation can be added later if needed
132
+ // Set request properties immediately
133
+ req.userId = userId;
134
+ req.accessToken = token;
135
+ req.user = { id: userId };
136
+ // Automatically authenticate the OxyServices instance so all subsequent API calls are authenticated
137
+ this.setTokens(token);
138
+ if (debug) {
139
+ console.log(`✅ Auth: Authentication successful for user ${userId}`);
140
+ }
141
+ next();
142
+ }
143
+ catch (error) {
144
+ const apiError = this.handleError(error);
145
+ if (debug) {
146
+ // Debug logging - using console.log is acceptable here for development
147
+ console.log(`❌ Auth: Unexpected error:`, apiError);
148
+ }
149
+ if (onError)
150
+ return onError(apiError);
151
+ return res.status((apiError && apiError.status) || 500).json(apiError);
152
+ }
153
+ };
154
+ }
155
+ };
156
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * Centralized mixin exports and composition helper
4
+ *
5
+ * This module provides a clean way to compose all mixins
6
+ * and ensures consistent ordering for better maintainability
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MIXIN_PIPELINE = void 0;
10
+ exports.composeOxyServices = composeOxyServices;
11
+ const OxyServices_base_1 = require("../OxyServices.base");
12
+ const OxyServices_auth_1 = require("./OxyServices.auth");
13
+ const OxyServices_fedcm_1 = require("./OxyServices.fedcm");
14
+ const OxyServices_popup_1 = require("./OxyServices.popup");
15
+ const OxyServices_redirect_1 = require("./OxyServices.redirect");
16
+ const OxyServices_user_1 = require("./OxyServices.user");
17
+ const OxyServices_privacy_1 = require("./OxyServices.privacy");
18
+ const OxyServices_language_1 = require("./OxyServices.language");
19
+ const OxyServices_payment_1 = require("./OxyServices.payment");
20
+ const OxyServices_karma_1 = require("./OxyServices.karma");
21
+ const OxyServices_assets_1 = require("./OxyServices.assets");
22
+ const OxyServices_developer_1 = require("./OxyServices.developer");
23
+ const OxyServices_location_1 = require("./OxyServices.location");
24
+ const OxyServices_analytics_1 = require("./OxyServices.analytics");
25
+ const OxyServices_devices_1 = require("./OxyServices.devices");
26
+ const OxyServices_security_1 = require("./OxyServices.security");
27
+ const OxyServices_utility_1 = require("./OxyServices.utility");
28
+ const OxyServices_features_1 = require("./OxyServices.features");
29
+ /**
30
+ * Mixin pipeline - applied in order from first to last.
31
+ *
32
+ * Order matters for dependencies:
33
+ * 1. Base auth mixin first (required by all others)
34
+ * 2. Cross-domain auth mixins (FedCM, Popup, Redirect)
35
+ * 3. User mixin (requires auth)
36
+ * 4. Feature mixins (can depend on user)
37
+ * 5. Utility mixin last (augments all)
38
+ *
39
+ * To add a new mixin: insert it at the appropriate position in this array.
40
+ */
41
+ const MIXIN_PIPELINE = [
42
+ // Base authentication
43
+ OxyServices_auth_1.OxyServicesAuthMixin,
44
+ // Cross-domain authentication (web-only)
45
+ // - FedCM: Modern browser-native identity federation (Google-style)
46
+ // - Popup: OAuth2-style popup authentication
47
+ // - Redirect: Traditional redirect-based authentication
48
+ OxyServices_fedcm_1.OxyServicesFedCMMixin,
49
+ OxyServices_popup_1.OxyServicesPopupAuthMixin,
50
+ OxyServices_redirect_1.OxyServicesRedirectAuthMixin,
51
+ // User management (requires auth)
52
+ OxyServices_user_1.OxyServicesUserMixin,
53
+ OxyServices_privacy_1.OxyServicesPrivacyMixin,
54
+ // Feature mixins
55
+ OxyServices_language_1.OxyServicesLanguageMixin,
56
+ OxyServices_payment_1.OxyServicesPaymentMixin,
57
+ OxyServices_karma_1.OxyServicesKarmaMixin,
58
+ OxyServices_assets_1.OxyServicesAssetsMixin,
59
+ OxyServices_developer_1.OxyServicesDeveloperMixin,
60
+ OxyServices_location_1.OxyServicesLocationMixin,
61
+ OxyServices_analytics_1.OxyServicesAnalyticsMixin,
62
+ OxyServices_devices_1.OxyServicesDevicesMixin,
63
+ OxyServices_security_1.OxyServicesSecurityMixin,
64
+ OxyServices_features_1.OxyServicesFeaturesMixin,
65
+ // Utility (last, can use all above)
66
+ OxyServices_utility_1.OxyServicesUtilityMixin,
67
+ ];
68
+ exports.MIXIN_PIPELINE = MIXIN_PIPELINE;
69
+ /**
70
+ * Composes all OxyServices mixins using a pipeline pattern.
71
+ *
72
+ * This is equivalent to the nested calls but more readable and maintainable.
73
+ * Adding a new mixin: just add it to MIXIN_PIPELINE at the appropriate position.
74
+ *
75
+ * @returns The fully composed OxyServices class with all mixins applied
76
+ */
77
+ function composeOxyServices() {
78
+ return MIXIN_PIPELINE.reduce((Base, mixin) => mixin(Base), OxyServices_base_1.OxyServicesBase);
79
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * Helper utilities for mixin classes
4
+ * Provides common patterns to reduce code duplication
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.CACHE_TIMES = void 0;
8
+ exports.withErrorHandling = withErrorHandling;
9
+ exports.createApiMethod = createApiMethod;
10
+ /**
11
+ * Wraps an async method with standard error handling
12
+ * Reduces boilerplate in mixin methods
13
+ */
14
+ async function withErrorHandling(operation, handleError) {
15
+ try {
16
+ return await operation();
17
+ }
18
+ catch (error) {
19
+ throw handleError(error);
20
+ }
21
+ }
22
+ /**
23
+ * Creates a standard API request method with error handling
24
+ * Reduces duplication across mixin methods
25
+ */
26
+ function createApiMethod(makeRequest, handleError, method, url, options = {}) {
27
+ return async (...args) => {
28
+ const urlString = typeof url === 'function' ? url(...args) : url;
29
+ const requestData = options.transformData ? options.transformData(args) : args[0];
30
+ const requestOptions = {
31
+ cache: options.cache ?? true,
32
+ cacheTTL: options.cacheTTL,
33
+ retry: options.retry ?? true,
34
+ };
35
+ try {
36
+ const response = await makeRequest(method, urlString, requestData, requestOptions);
37
+ return options.transformResponse ? options.transformResponse(response) : response;
38
+ }
39
+ catch (error) {
40
+ throw handleError(error);
41
+ }
42
+ };
43
+ }
44
+ /**
45
+ * Cache time constants (in milliseconds)
46
+ */
47
+ exports.CACHE_TIMES = {
48
+ SHORT: 1 * 60 * 1000, // 1 minute
49
+ MEDIUM: 2 * 60 * 1000, // 2 minutes
50
+ LONG: 5 * 60 * 1000, // 5 minutes
51
+ VERY_LONG: 10 * 60 * 1000, // 10 minutes
52
+ EXTRA_LONG: 30 * 60 * 1000, // 30 minutes
53
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SECURITY_EVENT_SEVERITY_MAP = void 0;
4
+ /**
5
+ * Security event severity mapping (single source of truth)
6
+ * Maps each event type to its default severity level
7
+ */
8
+ exports.SECURITY_EVENT_SEVERITY_MAP = {
9
+ 'sign_in': 'low',
10
+ 'sign_out': 'low',
11
+ 'profile_updated': 'low',
12
+ 'email_changed': 'medium',
13
+ 'device_added': 'medium',
14
+ 'device_removed': 'medium',
15
+ 'security_settings_changed': 'medium',
16
+ 'account_recovery': 'high',
17
+ 'private_key_exported': 'high',
18
+ 'backup_created': 'high',
19
+ 'suspicious_activity': 'critical',
20
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });