@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,358 @@
1
+ /**
2
+ * Authentication Methods Mixin
3
+ *
4
+ * Supports password-based login (email/username) and public key challenge-response.
5
+ */
6
+ import type { User } from '../models/interfaces';
7
+ import type { SessionLoginResponse } from '../models/session';
8
+ import type { OxyServicesBase } from '../OxyServices.base';
9
+ import { OxyAuthenticationError } from '../OxyServices.errors';
10
+
11
+ export interface ChallengeResponse {
12
+ challenge: string;
13
+ expiresAt: string;
14
+ }
15
+
16
+ export interface RegistrationRequest {
17
+ publicKey: string;
18
+ username: string;
19
+ email?: string;
20
+ signature: string;
21
+ timestamp: number;
22
+ }
23
+
24
+ export interface ChallengeVerifyRequest {
25
+ publicKey: string;
26
+ challenge: string;
27
+ signature: string;
28
+ timestamp: number;
29
+ deviceName?: string;
30
+ deviceFingerprint?: string;
31
+ }
32
+
33
+ export interface PublicKeyCheckResponse {
34
+ registered: boolean;
35
+ message: string;
36
+ }
37
+
38
+ export function OxyServicesAuthMixin<T extends typeof OxyServicesBase>(Base: T) {
39
+ return class extends Base {
40
+ constructor(...args: any[]) {
41
+ super(...(args as [any]));
42
+ }
43
+
44
+ /**
45
+ * Register a new identity with public key authentication
46
+ * Identity is purely cryptographic - username and profile data are optional
47
+ *
48
+ * @param publicKey - The user's ECDSA public key (hex)
49
+ * @param signature - Signature of the registration request
50
+ * @param timestamp - Timestamp when the signature was created
51
+ */
52
+ async register(
53
+ publicKey: string,
54
+ signature: string,
55
+ timestamp: number
56
+ ): Promise<{ message: string; user: User }> {
57
+ try {
58
+ const res = await this.makeRequest<{ message: string; user: User }>('POST', '/api/auth/register', {
59
+ publicKey,
60
+ signature,
61
+ timestamp,
62
+ }, { cache: false });
63
+
64
+ if (!res || (typeof res === 'object' && Object.keys(res).length === 0)) {
65
+ throw new OxyAuthenticationError('Registration failed', 'REGISTER_FAILED', 400);
66
+ }
67
+
68
+ return res;
69
+ } catch (error) {
70
+ throw this.handleError(error);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Request an authentication challenge
76
+ * The client must sign this challenge with their private key
77
+ *
78
+ * @param publicKey - The user's public key
79
+ */
80
+ async requestChallenge(publicKey: string): Promise<ChallengeResponse> {
81
+ try {
82
+ return await this.makeRequest<ChallengeResponse>('POST', '/api/auth/challenge', {
83
+ publicKey,
84
+ }, { cache: false });
85
+ } catch (error) {
86
+ throw this.handleError(error);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Verify a signed challenge and create a session
92
+ *
93
+ * @param publicKey - The user's public key
94
+ * @param challenge - The challenge string from requestChallenge
95
+ * @param signature - Signature of the auth message
96
+ * @param timestamp - Timestamp when the signature was created
97
+ * @param deviceName - Optional device name
98
+ * @param deviceFingerprint - Optional device fingerprint
99
+ */
100
+ async verifyChallenge(
101
+ publicKey: string,
102
+ challenge: string,
103
+ signature: string,
104
+ timestamp: number,
105
+ deviceName?: string,
106
+ deviceFingerprint?: string
107
+ ): Promise<SessionLoginResponse> {
108
+ try {
109
+ return await this.makeRequest<SessionLoginResponse>('POST', '/api/auth/verify', {
110
+ publicKey,
111
+ challenge,
112
+ signature,
113
+ timestamp,
114
+ deviceName,
115
+ deviceFingerprint,
116
+ }, { cache: false });
117
+ } catch (error) {
118
+ throw this.handleError(error);
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Check if a public key is already registered
124
+ */
125
+ async checkPublicKeyRegistered(publicKey: string): Promise<PublicKeyCheckResponse> {
126
+ try {
127
+ return await this.makeRequest<PublicKeyCheckResponse>(
128
+ 'GET',
129
+ `/api/auth/check-publickey/${encodeURIComponent(publicKey)}`,
130
+ undefined,
131
+ { cache: false }
132
+ );
133
+ } catch (error) {
134
+ throw this.handleError(error);
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Get user by public key
140
+ */
141
+ async getUserByPublicKey(publicKey: string): Promise<User> {
142
+ try {
143
+ return await this.makeRequest<User>(
144
+ 'GET',
145
+ `/api/auth/user/${encodeURIComponent(publicKey)}`,
146
+ undefined,
147
+ { cache: true, cacheTTL: 2 * 60 * 1000 }
148
+ );
149
+ } catch (error) {
150
+ throw this.handleError(error);
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Get user by session ID
156
+ */
157
+ async getUserBySession(sessionId: string): Promise<User> {
158
+ try {
159
+ return await this.makeRequest<User>('GET', `/api/session/user/${sessionId}`, undefined, {
160
+ cache: true,
161
+ cacheTTL: 2 * 60 * 1000,
162
+ });
163
+ } catch (error) {
164
+ throw this.handleError(error);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Batch get multiple user profiles by session IDs
170
+ */
171
+ async getUsersBySessions(sessionIds: string[]): Promise<Array<{ sessionId: string; user: User | null }>> {
172
+ try {
173
+ if (!Array.isArray(sessionIds) || sessionIds.length === 0) {
174
+ return [];
175
+ }
176
+
177
+ const uniqueSessionIds = Array.from(new Set(sessionIds)).sort();
178
+
179
+ return await this.makeRequest<Array<{ sessionId: string; user: User | null }>>(
180
+ 'POST',
181
+ '/api/session/users/batch',
182
+ { sessionIds: uniqueSessionIds },
183
+ {
184
+ cache: true,
185
+ cacheTTL: 2 * 60 * 1000,
186
+ deduplicate: true,
187
+ }
188
+ );
189
+ } catch (error) {
190
+ throw this.handleError(error);
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Get access token by session ID
196
+ */
197
+ async getTokenBySession(sessionId: string): Promise<{ accessToken: string; expiresAt: string }> {
198
+ try {
199
+ const res = await this.makeRequest<{ accessToken: string; expiresAt: string }>(
200
+ 'GET',
201
+ `/api/session/token/${sessionId}`,
202
+ undefined,
203
+ { cache: false, retry: false }
204
+ );
205
+
206
+ this.setTokens(res.accessToken);
207
+
208
+ return res;
209
+ } catch (error) {
210
+ throw this.handleError(error);
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Get sessions by session ID
216
+ */
217
+ async getSessionsBySessionId(sessionId: string): Promise<any[]> {
218
+ try {
219
+ return await this.makeRequest('GET', `/api/session/sessions/${sessionId}`, undefined, {
220
+ cache: false,
221
+ });
222
+ } catch (error) {
223
+ throw this.handleError(error);
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Logout from a specific session
229
+ */
230
+ async logoutSession(sessionId: string, targetSessionId?: string): Promise<void> {
231
+ try {
232
+ const url = targetSessionId
233
+ ? `/api/session/logout/${sessionId}/${targetSessionId}`
234
+ : `/api/session/logout/${sessionId}`;
235
+
236
+ await this.makeRequest('POST', url, undefined, { cache: false });
237
+ } catch (error) {
238
+ throw this.handleError(error);
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Logout from all sessions
244
+ */
245
+ async logoutAllSessions(sessionId: string): Promise<void> {
246
+ try {
247
+ await this.makeRequest('POST', `/api/session/logout-all/${sessionId}`, undefined, { cache: false });
248
+ } catch (error) {
249
+ throw this.handleError(error);
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Validate session
255
+ */
256
+ async validateSession(
257
+ sessionId: string,
258
+ options: {
259
+ deviceFingerprint?: string;
260
+ useHeaderValidation?: boolean;
261
+ } = {}
262
+ ): Promise<{
263
+ valid: boolean;
264
+ expiresAt: string;
265
+ lastActivity: string;
266
+ user: User;
267
+ sessionId?: string;
268
+ source?: string;
269
+ }> {
270
+ try {
271
+ const urlParams: any = {};
272
+ if (options.deviceFingerprint) urlParams.deviceFingerprint = options.deviceFingerprint;
273
+ if (options.useHeaderValidation) urlParams.useHeaderValidation = 'true';
274
+ return await this.makeRequest('GET', `/api/session/validate/${sessionId}`, urlParams, { cache: false });
275
+ } catch (error) {
276
+ throw this.handleError(error);
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Check username availability
282
+ */
283
+ async checkUsernameAvailability(username: string): Promise<{ available: boolean; message: string }> {
284
+ try {
285
+ return await this.makeRequest('GET', `/api/auth/check-username/${username}`, undefined, { cache: false });
286
+ } catch (error) {
287
+ throw this.handleError(error);
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Check email availability
293
+ */
294
+ async checkEmailAvailability(email: string): Promise<{ available: boolean; message: string }> {
295
+ try {
296
+ return await this.makeRequest('GET', `/api/auth/check-email/${email}`, undefined, { cache: false });
297
+ } catch (error) {
298
+ throw this.handleError(error);
299
+ }
300
+ }
301
+
302
+ /**
303
+ * Register a new user with email/username and password
304
+ */
305
+ async signUp(
306
+ username: string,
307
+ email: string,
308
+ password: string,
309
+ deviceName?: string,
310
+ deviceFingerprint?: any
311
+ ): Promise<SessionLoginResponse> {
312
+ try {
313
+ return await this.makeRequest<SessionLoginResponse>('POST', '/api/auth/signup', {
314
+ username,
315
+ email,
316
+ password,
317
+ deviceName,
318
+ deviceFingerprint,
319
+ }, { cache: false });
320
+ } catch (error) {
321
+ throw this.handleError(error);
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Sign in with email or username and password
327
+ */
328
+ async signIn(
329
+ identifier: string,
330
+ password: string,
331
+ deviceName?: string,
332
+ deviceFingerprint?: any
333
+ ): Promise<SessionLoginResponse> {
334
+ try {
335
+ return await this.makeRequest<SessionLoginResponse>('POST', '/api/auth/login', {
336
+ identifier,
337
+ password,
338
+ deviceName,
339
+ deviceFingerprint,
340
+ }, { cache: false });
341
+ } catch (error) {
342
+ throw this.handleError(error);
343
+ }
344
+ }
345
+
346
+ /**
347
+ * Convenience helper for email sign-in
348
+ */
349
+ async signInWithEmail(
350
+ email: string,
351
+ password: string,
352
+ deviceName?: string,
353
+ deviceFingerprint?: any
354
+ ): Promise<SessionLoginResponse> {
355
+ return this.signIn(email, password, deviceName, deviceFingerprint);
356
+ }
357
+ };
358
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Developer API Methods Mixin
3
+ *
4
+ * Provides methods for managing developer applications and API keys
5
+ */
6
+ import type { OxyServicesBase } from '../OxyServices.base';
7
+ import { CACHE_TIMES } from './mixinHelpers';
8
+
9
+ export function OxyServicesDeveloperMixin<T extends typeof OxyServicesBase>(Base: T) {
10
+ return class extends Base {
11
+ constructor(...args: any[]) {
12
+ super(...(args as [any]));
13
+ }
14
+
15
+ /**
16
+ * Get developer apps for the current user
17
+ * @returns Array of developer apps
18
+ */
19
+ async getDeveloperApps(): Promise<any[]> {
20
+ try {
21
+ const res = await this.makeRequest<{ apps?: any[] }>('GET', '/api/developer/apps', undefined, {
22
+ cache: true,
23
+ cacheTTL: CACHE_TIMES.MEDIUM,
24
+ });
25
+ return res.apps || [];
26
+ } catch (error) {
27
+ throw this.handleError(error);
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Create a new developer app
33
+ * @param data - Developer app configuration
34
+ * @returns Created developer app
35
+ */
36
+ async createDeveloperApp(data: {
37
+ name: string;
38
+ description?: string;
39
+ webhookUrl: string;
40
+ devWebhookUrl?: string;
41
+ scopes?: string[];
42
+ }): Promise<any> {
43
+ try {
44
+ const res = await this.makeRequest<{ app: any }>('POST', '/api/developer/apps', data, { cache: false });
45
+ return res.app;
46
+ } catch (error) {
47
+ throw this.handleError(error);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Get a specific developer app
53
+ */
54
+ async getDeveloperApp(appId: string): Promise<any> {
55
+ try {
56
+ const res = await this.makeRequest<{ app: any }>('GET', `/api/developer/apps/${appId}`, undefined, {
57
+ cache: true,
58
+ cacheTTL: CACHE_TIMES.LONG,
59
+ });
60
+ return res.app;
61
+ } catch (error) {
62
+ throw this.handleError(error);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Update a developer app
68
+ * @param appId - The developer app ID
69
+ * @param data - Updated app configuration
70
+ * @returns Updated developer app
71
+ */
72
+ async updateDeveloperApp(appId: string, data: {
73
+ name?: string;
74
+ description?: string;
75
+ webhookUrl?: string;
76
+ devWebhookUrl?: string;
77
+ scopes?: string[];
78
+ }): Promise<any> {
79
+ try {
80
+ const res = await this.makeRequest<{ app: any }>('PATCH', `/api/developer/apps/${appId}`, data, { cache: false });
81
+ return res.app;
82
+ } catch (error) {
83
+ throw this.handleError(error);
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Regenerate API secret for a developer app
89
+ * @param appId - The developer app ID
90
+ * @returns App with new secret
91
+ */
92
+ async regenerateDeveloperAppSecret(appId: string): Promise<any> {
93
+ try {
94
+ return await this.makeRequest('POST', `/api/developer/apps/${appId}/regenerate-secret`, undefined, { cache: false });
95
+ } catch (error) {
96
+ throw this.handleError(error);
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Delete a developer app
102
+ * @param appId - The developer app ID
103
+ * @returns Deletion result
104
+ */
105
+ async deleteDeveloperApp(appId: string): Promise<any> {
106
+ try {
107
+ return await this.makeRequest('DELETE', `/api/developer/apps/${appId}`, undefined, { cache: false });
108
+ } catch (error) {
109
+ throw this.handleError(error);
110
+ }
111
+ }
112
+ };
113
+ }
114
+
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Device Methods Mixin
3
+ */
4
+ import type { OxyServicesBase } from '../OxyServices.base';
5
+
6
+ export function OxyServicesDevicesMixin<T extends typeof OxyServicesBase>(Base: T) {
7
+ return class extends Base {
8
+ constructor(...args: any[]) {
9
+ super(...(args as [any]));
10
+ }
11
+
12
+ /**
13
+ * Register a new device
14
+ * @param deviceData - Device information
15
+ * @returns Registered device object
16
+ */
17
+ async registerDevice(deviceData: any): Promise<any> {
18
+ try {
19
+ return await this.makeRequest('POST', '/api/devices', deviceData, { cache: false });
20
+ } catch (error) {
21
+ throw this.handleError(error);
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Get all devices for the current user
27
+ * @returns Array of user devices
28
+ */
29
+ async getUserDevices(): Promise<any[]> {
30
+ try {
31
+ return await this.makeRequest('GET', '/api/devices', undefined, {
32
+ cache: false, // Don't cache device list - always get fresh data
33
+ });
34
+ } catch (error) {
35
+ throw this.handleError(error);
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Remove a device
41
+ * @param deviceId - The device ID to remove
42
+ */
43
+ async removeDevice(deviceId: string): Promise<void> {
44
+ try {
45
+ await this.makeRequest('DELETE', `/api/devices/${deviceId}`, undefined, { cache: false });
46
+ } catch (error) {
47
+ throw this.handleError(error);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Get device sessions for a given session ID
53
+ * Note: Not cached by default to ensure fresh data
54
+ * @param sessionId - The session ID
55
+ * @returns Array of device sessions
56
+ */
57
+ async getDeviceSessions(sessionId: string): Promise<any[]> {
58
+ try {
59
+ // Use makeRequest for consistent error handling and optional caching
60
+ // Cache disabled by default to ensure fresh session data
61
+ return await this.makeRequest<any[]>('GET', `/api/session/device/sessions/${sessionId}`, undefined, {
62
+ cache: false, // Don't cache sessions - always get fresh data
63
+ deduplicate: true, // Deduplicate concurrent requests for same sessionId
64
+ });
65
+ } catch (error) {
66
+ throw this.handleError(error);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Logout all device sessions
72
+ * @param sessionId - The session ID
73
+ * @param deviceId - Optional device ID to target
74
+ * @param excludeCurrent - Whether to exclude the current session
75
+ * @returns Logout result
76
+ */
77
+ async logoutAllDeviceSessions(sessionId: string, deviceId?: string, excludeCurrent?: boolean): Promise<any> {
78
+ try {
79
+ const urlParams: any = {};
80
+ if (deviceId) urlParams.deviceId = deviceId;
81
+ if (excludeCurrent) urlParams.excludeCurrent = 'true';
82
+ return await this.makeRequest('POST', `/api/session/device/logout-all/${sessionId}`, urlParams, { cache: false });
83
+ } catch (error) {
84
+ throw this.handleError(error);
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Update device name
90
+ * @param sessionId - The session ID
91
+ * @param deviceName - New device name
92
+ * @returns Updated device object
93
+ */
94
+ async updateDeviceName(sessionId: string, deviceName: string): Promise<any> {
95
+ try {
96
+ return await this.makeRequest('PUT', `/api/session/device/name/${sessionId}`, { deviceName }, { cache: false });
97
+ } catch (error) {
98
+ throw this.handleError(error);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Get security information
104
+ * @returns Security information object
105
+ */
106
+ async getSecurityInfo(): Promise<{
107
+ recoveryEmail: string | null;
108
+ }> {
109
+ try {
110
+ return await this.makeRequest('GET', '/api/devices/security', undefined, {
111
+ cache: false,
112
+ });
113
+ } catch (error) {
114
+ throw this.handleError(error);
115
+ }
116
+ }
117
+ };
118
+ }
119
+