@oxyhq/core 10.2.0 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/boot/sessionColdBoot.js +3 -3
- package/dist/cjs/crypto/keyManager.js +68 -69
- package/dist/cjs/crypto/signatureService.js +2 -2
- package/dist/cjs/index.js +17 -20
- package/dist/cjs/logger/index.js +149 -0
- package/dist/cjs/mixins/OxyServices.assets.js +4 -4
- package/dist/cjs/mixins/OxyServices.auth.js +104 -2
- package/dist/cjs/mixins/OxyServices.language.js +3 -5
- package/dist/cjs/mixins/OxyServices.privacy.js +2 -4
- package/dist/cjs/mixins/OxyServices.security.js +7 -11
- package/dist/cjs/mixins/OxyServices.topics.js +25 -15
- package/dist/cjs/mixins/OxyServices.user.js +4 -4
- package/dist/cjs/mixins/OxyServices.utility.js +18 -18
- package/dist/cjs/session/SessionClient.js +17 -17
- package/dist/cjs/session/accountDialogController.js +12 -12
- package/dist/cjs/session/authStateStore.js +5 -5
- package/dist/cjs/session/refresh.js +4 -4
- package/dist/cjs/session/socketLoader.js +2 -2
- package/dist/cjs/utils/asyncUtils.js +2 -2
- package/dist/cjs/utils/avatarUtils.js +2 -1
- package/dist/cjs/utils/deviceManager.js +7 -5
- package/dist/cjs/utils/errorUtils.js +3 -3
- package/dist/cjs/utils/oauthPkce.js +3 -3
- package/dist/cjs/utils/requestUtils.js +1 -1
- package/dist/cjs/utils/webauthnOrigin.js +51 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/boot/sessionColdBoot.js +1 -1
- package/dist/esm/crypto/keyManager.js +1 -2
- package/dist/esm/crypto/signatureService.js +1 -1
- package/dist/esm/index.js +6 -3
- package/dist/esm/logger/index.js +140 -0
- package/dist/esm/mixins/OxyServices.assets.js +2 -2
- package/dist/esm/mixins/OxyServices.auth.js +103 -1
- package/dist/esm/mixins/OxyServices.language.js +3 -5
- package/dist/esm/mixins/OxyServices.privacy.js +2 -4
- package/dist/esm/mixins/OxyServices.security.js +7 -11
- package/dist/esm/mixins/OxyServices.topics.js +25 -15
- package/dist/esm/mixins/OxyServices.user.js +1 -1
- package/dist/esm/mixins/OxyServices.utility.js +1 -1
- package/dist/esm/session/SessionClient.js +1 -1
- package/dist/esm/session/accountDialogController.js +1 -1
- package/dist/esm/session/authStateStore.js +1 -1
- package/dist/esm/session/refresh.js +1 -1
- package/dist/esm/session/socketLoader.js +1 -1
- package/dist/esm/utils/asyncUtils.js +1 -1
- package/dist/esm/utils/avatarUtils.js +2 -1
- package/dist/esm/utils/deviceManager.js +7 -5
- package/dist/esm/utils/errorUtils.js +1 -1
- package/dist/esm/utils/oauthPkce.js +1 -1
- package/dist/esm/utils/requestUtils.js +1 -1
- package/dist/esm/utils/webauthnOrigin.js +48 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/logger/index.d.ts +104 -0
- package/dist/types/mixins/OxyServices.auth.d.ts +58 -0
- package/dist/types/mixins/OxyServices.topics.d.ts +3 -3
- package/dist/types/models/Topic.d.ts +10 -0
- package/dist/types/utils/requestUtils.d.ts +1 -1
- package/dist/types/utils/webauthnOrigin.d.ts +32 -0
- package/package.json +17 -2
- package/src/boot/sessionColdBoot.ts +1 -1
- package/src/crypto/keyManager.ts +1 -2
- package/src/crypto/signatureService.ts +1 -1
- package/src/index.ts +22 -19
- package/src/logger/__tests__/logger.test.ts +207 -0
- package/src/logger/index.ts +217 -0
- package/src/mixins/OxyServices.assets.ts +3 -3
- package/src/mixins/OxyServices.auth.ts +134 -1
- package/src/mixins/OxyServices.language.ts +3 -5
- package/src/mixins/OxyServices.privacy.ts +2 -4
- package/src/mixins/OxyServices.security.ts +7 -11
- package/src/mixins/OxyServices.topics.ts +47 -17
- package/src/mixins/OxyServices.user.ts +1 -1
- package/src/mixins/OxyServices.utility.ts +1 -1
- package/src/mixins/__tests__/discoveryErrorHandling.test.ts +1 -1
- package/src/mixins/__tests__/topics.test.ts +156 -0
- package/src/mixins/__tests__/webauthnAuth.test.ts +206 -0
- package/src/models/Topic.ts +11 -0
- package/src/session/SessionClient.ts +1 -1
- package/src/session/__tests__/SessionClient.diagnostics.test.ts +1 -1
- package/src/session/__tests__/accountDialogController.test.ts +1 -1
- package/src/session/accountDialogController.ts +1 -1
- package/src/session/authStateStore.ts +1 -1
- package/src/session/refresh.ts +1 -1
- package/src/session/socketLoader.ts +1 -1
- package/src/utils/__tests__/webauthnOrigin.test.ts +83 -0
- package/src/utils/asyncUtils.ts +1 -1
- package/src/utils/avatarUtils.ts +3 -1
- package/src/utils/deviceManager.ts +8 -5
- package/src/utils/errorUtils.ts +1 -1
- package/src/utils/oauthPkce.ts +1 -1
- package/src/utils/requestUtils.ts +1 -1
- package/src/utils/webauthnOrigin.ts +52 -0
- package/dist/cjs/shared/utils/debugUtils.js +0 -80
- package/dist/cjs/utils/loggerUtils.js +0 -126
- package/dist/esm/shared/utils/debugUtils.js +0 -72
- package/dist/esm/utils/loggerUtils.js +0 -115
- package/dist/types/shared/utils/debugUtils.d.ts +0 -48
- package/dist/types/utils/loggerUtils.d.ts +0 -48
- package/src/shared/utils/__tests__/debugUtils.test.ts +0 -55
- package/src/shared/utils/debugUtils.ts +0 -78
- package/src/utils/loggerUtils.ts +0 -153
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { runColdBoot } from '../utils/coldBoot.js';
|
|
24
24
|
import { isNative as detectNative } from '../utils/platform.js';
|
|
25
|
-
import { logger } from '../
|
|
25
|
+
import { logger } from '../logger/index.js';
|
|
26
26
|
import { TOKEN_REFRESH_LEAD_MS, refreshDeviceSecretArm } from '../session/refresh.js';
|
|
27
27
|
/**
|
|
28
28
|
* Run the device-first cold boot. Resolves to the `runColdBoot` outcome and, as
|
|
@@ -8,8 +8,7 @@ import _cjs_elliptic from 'elliptic';
|
|
|
8
8
|
const { ec: EC } = _cjs_elliptic;
|
|
9
9
|
import { isWeb, isIOS, isAndroid } from '../utils/platform.js';
|
|
10
10
|
import { isReactNative, isNodeJS, loadExpoCrypto, loadNodeCrypto, loadSecureStore, loadSharedIdentityBridge } from '@oxyhq/protocol';
|
|
11
|
-
import { logger } from '../
|
|
12
|
-
import { isDev } from '../shared/utils/debugUtils.js';
|
|
11
|
+
import { isDev, logger } from '../logger/index.js';
|
|
13
12
|
/**
|
|
14
13
|
* Thrown when an identity-mutating operation (createIdentity / importKeyPair)
|
|
15
14
|
* is invoked while a valid identity already exists on the device.
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { signEnvelope, signMessage, verifySignature, sha256, loadExpoCrypto, loadNodeCrypto, isReactNative, isNodeJS, } from '@oxyhq/protocol';
|
|
11
11
|
import { KeyManager } from './keyManager.js';
|
|
12
|
-
import { logger } from '../
|
|
12
|
+
import { logger } from '../logger/index.js';
|
|
13
13
|
export class SignatureService {
|
|
14
14
|
/**
|
|
15
15
|
* Generate a random challenge string (for offline use)
|
package/dist/esm/index.js
CHANGED
|
@@ -90,7 +90,6 @@ export { normalizeTheme, normalizeColorScheme, getOppositeTheme, systemPrefersDa
|
|
|
90
90
|
// ---------------------------------------------------------------------------
|
|
91
91
|
export { HttpStatus, getErrorStatus, getErrorMessage, isAlreadyRegisteredError, isUnauthorizedError, isForbiddenError, isNotFoundError, isRateLimitError, isServerError, isNetworkError, isRetryableError, } from './shared/utils/errorUtils.js';
|
|
92
92
|
export { DEFAULT_CIRCUIT_BREAKER_CONFIG, createCircuitBreakerState, calculateBackoffInterval, recordFailure, recordSuccess, shouldAllowRequest, delay, withRetry, } from './shared/utils/networkUtils.js';
|
|
93
|
-
export { isDev, debugLog, debugWarn, debugError, createDebugLogger, } from './shared/utils/debugUtils.js';
|
|
94
93
|
// ---------------------------------------------------------------------------
|
|
95
94
|
// i18n
|
|
96
95
|
// ---------------------------------------------------------------------------
|
|
@@ -110,9 +109,9 @@ export { EMAIL_REGEX, USERNAME_REGEX, PASSWORD_REGEX, isValidEmail, isValidUsern
|
|
|
110
109
|
// ---------------------------------------------------------------------------
|
|
111
110
|
export { normalizeInlineText, normalizeMultilineText, } from './utils/textNormalization.js';
|
|
112
111
|
// ---------------------------------------------------------------------------
|
|
113
|
-
// Logging
|
|
112
|
+
// Logging — the ecosystem-wide chokepoint (also at subpath `@oxyhq/core/logger`)
|
|
114
113
|
// ---------------------------------------------------------------------------
|
|
115
|
-
export { logger,
|
|
114
|
+
export { logger, createLogger, configureLogger, getLoggerConfig, resetLoggerConfig, consoleSink, isDev, } from './logger/index.js';
|
|
116
115
|
// ---------------------------------------------------------------------------
|
|
117
116
|
// Avatars
|
|
118
117
|
// ---------------------------------------------------------------------------
|
|
@@ -131,6 +130,10 @@ export { buildAccountsArray, createQuickAccount, getAccountDisplayName, getAccou
|
|
|
131
130
|
// ---------------------------------------------------------------------------
|
|
132
131
|
export { registrableApex } from './utils/registrableApex.js';
|
|
133
132
|
export { CENTRAL_IDP_APEX } from './utils/authWebUrl.js';
|
|
133
|
+
// WebAuthn relying-party origin guard (client side). Mirrors the server's
|
|
134
|
+
// `isOxyApexOrigin` so consumers can decide whether to offer passkey UI on the
|
|
135
|
+
// current page (first-party Oxy origin / loopback only).
|
|
136
|
+
export { isOxyRpOrigin } from './utils/webauthnOrigin.js';
|
|
134
137
|
export { runColdBoot } from './utils/coldBoot.js';
|
|
135
138
|
// ---------------------------------------------------------------------------
|
|
136
139
|
// OAuth 2.0 Authorization Code + PKCE helpers ("Sign in with Oxy" third party).
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oxyhq/core/logger — the ecosystem-wide logging chokepoint.
|
|
3
|
+
*
|
|
4
|
+
* A tiny, dependency-free, universal logger that works unchanged in React
|
|
5
|
+
* Native, browsers, Node, and Bun. Every Oxy app and package should log
|
|
6
|
+
* through here instead of calling `console.*` directly, so that level,
|
|
7
|
+
* formatting, and transport are controlled in ONE place.
|
|
8
|
+
*
|
|
9
|
+
* Design goals:
|
|
10
|
+
* - Zero dependencies. No Node-only imports, no `process.stdout` assumptions.
|
|
11
|
+
* - Four levels (`debug` | `info` | `warn` | `error`) plus `silent`.
|
|
12
|
+
* - Namespaced child loggers via `createLogger('mention:feed')` / `.child()`.
|
|
13
|
+
* - Structured context objects carried through to the sink.
|
|
14
|
+
* - A single pluggable sink so backends can pipe to pino / CloudWatch / etc.
|
|
15
|
+
* without touching any call site.
|
|
16
|
+
* - Debug is off in production by default (`__DEV__` on RN, `NODE_ENV`
|
|
17
|
+
* elsewhere); override globally with `configureLogger({ level })`.
|
|
18
|
+
*
|
|
19
|
+
* @module logger
|
|
20
|
+
*/
|
|
21
|
+
const LEVEL_WEIGHT = {
|
|
22
|
+
silent: 0,
|
|
23
|
+
error: 1,
|
|
24
|
+
warn: 2,
|
|
25
|
+
info: 3,
|
|
26
|
+
debug: 4,
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* True in development. Uses React Native's `__DEV__` when present, otherwise
|
|
30
|
+
* falls back to `process.env.NODE_ENV === 'development'`. Never throws.
|
|
31
|
+
*/
|
|
32
|
+
export function isDev() {
|
|
33
|
+
if (typeof __DEV__ !== 'undefined')
|
|
34
|
+
return __DEV__ === true;
|
|
35
|
+
try {
|
|
36
|
+
return typeof process !== 'undefined' && process.env?.NODE_ENV === 'development';
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function formatPrefix(entry) {
|
|
43
|
+
const parts = [entry.timestamp, entry.level.toUpperCase()];
|
|
44
|
+
if (entry.namespace)
|
|
45
|
+
parts.push(`[${entry.namespace}]`);
|
|
46
|
+
return parts.join(' ');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Default sink: routes each entry to the matching `console` method. `info` and
|
|
50
|
+
* `debug` go to `console.log` (RN/browser-safe — `console.debug`/`console.info`
|
|
51
|
+
* are inconsistently surfaced across runtimes).
|
|
52
|
+
*/
|
|
53
|
+
export const consoleSink = (entry) => {
|
|
54
|
+
const extras = [];
|
|
55
|
+
if (entry.context && Object.keys(entry.context).length > 0)
|
|
56
|
+
extras.push(entry.context);
|
|
57
|
+
if (entry.error !== undefined)
|
|
58
|
+
extras.push(entry.error);
|
|
59
|
+
if (entry.args.length > 0)
|
|
60
|
+
extras.push(...entry.args);
|
|
61
|
+
const line = `${formatPrefix(entry)} ${entry.message}`;
|
|
62
|
+
if (entry.level === 'error')
|
|
63
|
+
console.error(line, ...extras);
|
|
64
|
+
else if (entry.level === 'warn')
|
|
65
|
+
console.warn(line, ...extras);
|
|
66
|
+
else
|
|
67
|
+
console.log(line, ...extras);
|
|
68
|
+
};
|
|
69
|
+
function defaultLevel() {
|
|
70
|
+
return isDev() ? 'debug' : 'info';
|
|
71
|
+
}
|
|
72
|
+
const config = {
|
|
73
|
+
level: defaultLevel(),
|
|
74
|
+
sink: consoleSink,
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Update the global logger configuration. Affects every logger instance
|
|
78
|
+
* (root and children) immediately. Pass `{ level }` to gate output and/or
|
|
79
|
+
* `{ sink }` to redirect transport (pino, CloudWatch, a test capture, …).
|
|
80
|
+
*/
|
|
81
|
+
export function configureLogger(partial) {
|
|
82
|
+
if (partial.level !== undefined)
|
|
83
|
+
config.level = partial.level;
|
|
84
|
+
if (partial.sink !== undefined)
|
|
85
|
+
config.sink = partial.sink;
|
|
86
|
+
}
|
|
87
|
+
/** Read a snapshot of the current global configuration. */
|
|
88
|
+
export function getLoggerConfig() {
|
|
89
|
+
return { level: config.level, sink: config.sink };
|
|
90
|
+
}
|
|
91
|
+
/** Restore the default level (env-derived) and the console sink. */
|
|
92
|
+
export function resetLoggerConfig() {
|
|
93
|
+
config.level = defaultLevel();
|
|
94
|
+
config.sink = consoleSink;
|
|
95
|
+
}
|
|
96
|
+
function mergeContext(base, extra) {
|
|
97
|
+
if (!base)
|
|
98
|
+
return extra;
|
|
99
|
+
if (!extra)
|
|
100
|
+
return base;
|
|
101
|
+
return { ...base, ...extra };
|
|
102
|
+
}
|
|
103
|
+
function emit(level, namespace, baseContext, message, error, context, args) {
|
|
104
|
+
if (LEVEL_WEIGHT[level] > LEVEL_WEIGHT[config.level])
|
|
105
|
+
return;
|
|
106
|
+
config.sink({
|
|
107
|
+
level,
|
|
108
|
+
message,
|
|
109
|
+
namespace,
|
|
110
|
+
context: mergeContext(baseContext, context),
|
|
111
|
+
error,
|
|
112
|
+
args,
|
|
113
|
+
timestamp: new Date().toISOString(),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function makeLogger(namespace, baseContext) {
|
|
117
|
+
return {
|
|
118
|
+
namespace,
|
|
119
|
+
debug: (message, context, ...args) => emit('debug', namespace, baseContext, message, undefined, context, args),
|
|
120
|
+
info: (message, context, ...args) => emit('info', namespace, baseContext, message, undefined, context, args),
|
|
121
|
+
warn: (message, context, ...args) => emit('warn', namespace, baseContext, message, undefined, context, args),
|
|
122
|
+
error: (message, error, context, ...args) => emit('error', namespace, baseContext, message, error, context, args),
|
|
123
|
+
child: (childNamespace, childContext) => makeLogger(namespace ? `${namespace}:${childNamespace}` : childNamespace, mergeContext(baseContext, childContext)),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** The shared root logger. Prefer a namespaced `createLogger(...)` in modules. */
|
|
127
|
+
export const logger = makeLogger(undefined, undefined);
|
|
128
|
+
/**
|
|
129
|
+
* Create a namespaced logger.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* const log = createLogger('mention:feed');
|
|
134
|
+
* log.info('loaded', { count: 20 });
|
|
135
|
+
* const sub = log.child('prefetch'); // namespace → 'mention:feed:prefetch'
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export function createLogger(namespace, context) {
|
|
139
|
+
return makeLogger(namespace, context);
|
|
140
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isReactNative } from '@oxyhq/protocol';
|
|
2
|
-
import { logger } from '../
|
|
2
|
+
import { logger } from '../logger/index.js';
|
|
3
3
|
import { extractErrorStatus } from '../utils/errorUtils.js';
|
|
4
4
|
/**
|
|
5
5
|
* Maximum number of ids sent per `POST /assets/service/by-ids` request. Matches
|
|
@@ -359,7 +359,7 @@ export function OxyServicesAssetsMixin(Base) {
|
|
|
359
359
|
return response;
|
|
360
360
|
}
|
|
361
361
|
catch (error) {
|
|
362
|
-
|
|
362
|
+
logger.error('File upload error', error, { component: 'OxyServices.assets' });
|
|
363
363
|
let errorMessage = 'File upload failed';
|
|
364
364
|
if (error instanceof Error) {
|
|
365
365
|
errorMessage = error.message || errorMessage;
|
|
@@ -3,7 +3,7 @@ import { OxyAuthenticationError } from '../OxyServices.errors.js';
|
|
|
3
3
|
import { KeyManager } from '../crypto/keyManager.js';
|
|
4
4
|
import { SignatureService } from '../crypto/signatureService.js';
|
|
5
5
|
import { loadNodeCrypto } from '@oxyhq/protocol';
|
|
6
|
-
import { logger } from '../
|
|
6
|
+
import { logger } from '../logger/index.js';
|
|
7
7
|
import { normalizeUserIdentity, normalizeUserIdentityOrNull } from '../utils/userIdentity.js';
|
|
8
8
|
/**
|
|
9
9
|
* Default lifetime of a "Sign in with Oxy" device-flow session / authorize code.
|
|
@@ -847,6 +847,108 @@ export function OxyServicesAuthMixin(Base) {
|
|
|
847
847
|
throw this.handleError(error);
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
|
+
/**
|
|
851
|
+
* Begin a WebAuthn / passkey REGISTRATION ceremony. Requests the
|
|
852
|
+
* `PublicKeyCredentialCreationOptions` the browser's `navigator.credentials
|
|
853
|
+
* .create()` (or `@simplewebauthn/browser`'s `startRegistration`) needs.
|
|
854
|
+
*
|
|
855
|
+
* With a bearer token planted this links a passkey to the signed-in account
|
|
856
|
+
* (`username` ignored); without one it is a prospective signup and `username`
|
|
857
|
+
* is the desired handle. The returned options are OPAQUE — Oxy does not own
|
|
858
|
+
* their shape (the browser / `@simplewebauthn` does), so they pass through
|
|
859
|
+
* as `unknown` for the caller to hand straight to the ceremony.
|
|
860
|
+
*/
|
|
861
|
+
async webauthnRegisterOptions(username) {
|
|
862
|
+
try {
|
|
863
|
+
return await this.makeRequest('POST', '/auth/webauthn/register/options', { ...(username !== undefined ? { username } : {}) }, { cache: false });
|
|
864
|
+
}
|
|
865
|
+
catch (error) {
|
|
866
|
+
throw this.handleError(error);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Finish a WebAuthn / passkey REGISTRATION ceremony. Forwards the opaque
|
|
871
|
+
* browser `RegistrationResponseJSON` (`response`) alongside the Oxy envelope
|
|
872
|
+
* (desired `username` for signup + the device-session naming fields).
|
|
873
|
+
*
|
|
874
|
+
* Two server branches, disambiguated by the response shape:
|
|
875
|
+
* - **Signup** (no bearer): the account is created and a session minted —
|
|
876
|
+
* the response carries `sessionId`, is the SAME {@link LoginResult}
|
|
877
|
+
* contract as `POST /auth/verify`, and its access token is planted here.
|
|
878
|
+
* - **Link** (bearer present): the passkey is attached to the signed-in
|
|
879
|
+
* account and the server returns `{ success, message }` with no session,
|
|
880
|
+
* which is returned verbatim (no token planting).
|
|
881
|
+
*/
|
|
882
|
+
async webauthnRegisterVerify(response, envelope = {}) {
|
|
883
|
+
try {
|
|
884
|
+
const res = await this.makeRequest('POST', '/auth/webauthn/register/verify', { response, ...envelope }, { cache: false });
|
|
885
|
+
if (res && typeof res === 'object') {
|
|
886
|
+
const record = res;
|
|
887
|
+
// Signup branch: mints a session (LoginSessionResult, carries
|
|
888
|
+
// `sessionId`). Parse against the login contract and plant the token.
|
|
889
|
+
if ('sessionId' in record) {
|
|
890
|
+
const parsed = safeParseContract(loginResultSchema, record);
|
|
891
|
+
if (!parsed) {
|
|
892
|
+
throw new Error('auth/webauthn/register/verify returned an unexpected response shape');
|
|
893
|
+
}
|
|
894
|
+
if (!('twoFactorRequired' in parsed) && parsed.accessToken) {
|
|
895
|
+
this.setTokens(parsed.accessToken);
|
|
896
|
+
}
|
|
897
|
+
return parsed;
|
|
898
|
+
}
|
|
899
|
+
// Link branch: passkey attached to the signed-in account, no session.
|
|
900
|
+
if (record.success === true && typeof record.message === 'string') {
|
|
901
|
+
return { success: true, message: record.message };
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
throw new Error('auth/webauthn/register/verify returned an unexpected response shape');
|
|
905
|
+
}
|
|
906
|
+
catch (error) {
|
|
907
|
+
throw this.handleError(error);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Begin a WebAuthn / passkey AUTHENTICATION ceremony. Requests the
|
|
912
|
+
* `PublicKeyCredentialRequestOptions` the browser's `navigator.credentials
|
|
913
|
+
* .get()` (or `@simplewebauthn/browser`'s `startAuthentication`) needs.
|
|
914
|
+
*
|
|
915
|
+
* When `username` is present the server scopes `allowCredentials` to that
|
|
916
|
+
* user's passkeys (username-first); when omitted it returns an empty
|
|
917
|
+
* allow-list for the usernameless / discoverable-credential flow. The
|
|
918
|
+
* returned options are OPAQUE and pass through as `unknown`.
|
|
919
|
+
*/
|
|
920
|
+
async webauthnLoginOptions(username) {
|
|
921
|
+
try {
|
|
922
|
+
return await this.makeRequest('POST', '/auth/webauthn/login/options', { ...(username !== undefined ? { username } : {}) }, { cache: false });
|
|
923
|
+
}
|
|
924
|
+
catch (error) {
|
|
925
|
+
throw this.handleError(error);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Finish a WebAuthn / passkey AUTHENTICATION ceremony. Forwards the opaque
|
|
930
|
+
* browser `AuthenticationResponseJSON` (`response`) alongside the
|
|
931
|
+
* device-session envelope. Resolves to the SAME {@link LoginResult} contract
|
|
932
|
+
* as `POST /auth/verify`; on the session arm the access token is planted
|
|
933
|
+
* immediately (mirroring {@link passwordSignIn}), and the response's
|
|
934
|
+
* `deviceId` + `deviceSecret` are the zero-cookie restore credential.
|
|
935
|
+
*/
|
|
936
|
+
async webauthnLoginVerify(response, envelope = {}) {
|
|
937
|
+
try {
|
|
938
|
+
const res = await this.makeRequest('POST', '/auth/webauthn/login/verify', { response, ...envelope }, { cache: false });
|
|
939
|
+
const parsed = safeParseContract(loginResultSchema, res);
|
|
940
|
+
if (!parsed) {
|
|
941
|
+
throw new Error('auth/webauthn/login/verify returned an unexpected response shape');
|
|
942
|
+
}
|
|
943
|
+
if (!('twoFactorRequired' in parsed) && parsed.accessToken) {
|
|
944
|
+
this.setTokens(parsed.accessToken);
|
|
945
|
+
}
|
|
946
|
+
return parsed;
|
|
947
|
+
}
|
|
948
|
+
catch (error) {
|
|
949
|
+
throw this.handleError(error);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
850
952
|
/**
|
|
851
953
|
* Exchange an OAuth authorization code (returned to the RP redirect URI
|
|
852
954
|
* after password sign-in at auth.oxy.so) for a device-first session.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { normalizeLocale, getPrimaryLanguage, getLanguageMetadata, getLanguageName, getNativeLanguageName } from '../utils/languageUtils.js';
|
|
5
5
|
import { loadAsyncStorage } from '@oxyhq/protocol';
|
|
6
|
-
import {
|
|
6
|
+
import { logger } from '../logger/index.js';
|
|
7
7
|
export function OxyServicesLanguageMixin(Base) {
|
|
8
8
|
return class extends Base {
|
|
9
9
|
constructor(...args) {
|
|
@@ -28,7 +28,7 @@ export function OxyServicesLanguageMixin(Base) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
catch (error) {
|
|
31
|
-
|
|
31
|
+
logger.error('AsyncStorage not available in React Native', error, { component: 'OxyServices.language' });
|
|
32
32
|
throw new Error('AsyncStorage is required in React Native environment');
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -83,9 +83,7 @@ export function OxyServicesLanguageMixin(Base) {
|
|
|
83
83
|
return null;
|
|
84
84
|
}
|
|
85
85
|
catch (error) {
|
|
86
|
-
|
|
87
|
-
console.warn('Failed to get current language:', error);
|
|
88
|
-
}
|
|
86
|
+
logger.warn('Failed to get current language', { component: 'OxyServices.language' }, error);
|
|
89
87
|
return null;
|
|
90
88
|
}
|
|
91
89
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger } from '../logger/index.js';
|
|
2
2
|
export function OxyServicesPrivacyMixin(Base) {
|
|
3
3
|
return class extends Base {
|
|
4
4
|
constructor(...args) {
|
|
@@ -26,9 +26,7 @@ export function OxyServicesPrivacyMixin(Base) {
|
|
|
26
26
|
}
|
|
27
27
|
catch (error) {
|
|
28
28
|
// If there's an error, assume not in list to avoid breaking functionality
|
|
29
|
-
|
|
30
|
-
console.warn('Error checking user list:', error);
|
|
31
|
-
}
|
|
29
|
+
logger.warn('Error checking user list', { component: 'OxyServices.privacy' }, error);
|
|
32
30
|
return false;
|
|
33
31
|
}
|
|
34
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger } from '../logger/index.js';
|
|
2
2
|
export function OxyServicesSecurityMixin(Base) {
|
|
3
3
|
return class extends Base {
|
|
4
4
|
constructor(...args) {
|
|
@@ -62,11 +62,9 @@ export function OxyServicesSecurityMixin(Base) {
|
|
|
62
62
|
await this.makeRequest('POST', '/security/activity/private-key-exported', { deviceId }, { cache: false });
|
|
63
63
|
}
|
|
64
64
|
catch (error) {
|
|
65
|
-
// Don't throw - logging failures shouldn't break user flow
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
console.warn('[OxyServices] Failed to log private key exported event:', error);
|
|
69
|
-
}
|
|
65
|
+
// Don't throw - logging failures shouldn't break user flow, but surface
|
|
66
|
+
// for monitoring via the shared logger sink.
|
|
67
|
+
logger.warn('[OxyServices] Failed to log private key exported event', { component: 'OxyServices.security' }, error);
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
70
|
/**
|
|
@@ -79,11 +77,9 @@ export function OxyServicesSecurityMixin(Base) {
|
|
|
79
77
|
await this.makeRequest('POST', '/security/activity/backup-created', { deviceId }, { cache: false });
|
|
80
78
|
}
|
|
81
79
|
catch (error) {
|
|
82
|
-
// Don't throw - logging failures shouldn't break user flow
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
console.warn('[OxyServices] Failed to log backup created event:', error);
|
|
86
|
-
}
|
|
80
|
+
// Don't throw - logging failures shouldn't break user flow, but surface
|
|
81
|
+
// for monitoring via the shared logger sink.
|
|
82
|
+
logger.warn('[OxyServices] Failed to log backup created event', { component: 'OxyServices.security' }, error);
|
|
87
83
|
}
|
|
88
84
|
}
|
|
89
85
|
};
|
|
@@ -14,10 +14,10 @@ export function OxyServicesTopicsMixin(Base) {
|
|
|
14
14
|
const params = {};
|
|
15
15
|
if (locale)
|
|
16
16
|
params.locale = locale;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
// `GET /topics/categories` returns `{ categories: TopicData[] }` — the
|
|
18
|
+
// SDK's `unwrapResponse` only unwraps `{ data }`, so unwrap here.
|
|
19
|
+
const response = await this.makeRequest('GET', '/topics/categories', params, { cache: true, cacheTTL: CACHE_TIMES.EXTRA_LONG });
|
|
20
|
+
return response.categories ?? [];
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|
|
23
23
|
throw this.handleError(error);
|
|
@@ -34,9 +34,9 @@ export function OxyServicesTopicsMixin(Base) {
|
|
|
34
34
|
const params = { q: query };
|
|
35
35
|
if (limit)
|
|
36
36
|
params.limit = limit;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// `GET /topics/search` returns `{ topics: TopicData[] }` — unwrap it.
|
|
38
|
+
const response = await this.makeRequest('GET', '/topics/search', params, { cache: false });
|
|
39
|
+
return response.topics ?? [];
|
|
40
40
|
}
|
|
41
41
|
catch (error) {
|
|
42
42
|
throw this.handleError(error);
|
|
@@ -45,7 +45,7 @@ export function OxyServicesTopicsMixin(Base) {
|
|
|
45
45
|
/**
|
|
46
46
|
* List topics with optional filters
|
|
47
47
|
* @param options - Filter and pagination options
|
|
48
|
-
* @returns
|
|
48
|
+
* @returns Paginated topics envelope (`topics` plus `total`/`limit`/`offset`)
|
|
49
49
|
*/
|
|
50
50
|
async listTopics(options) {
|
|
51
51
|
try {
|
|
@@ -60,10 +60,18 @@ export function OxyServicesTopicsMixin(Base) {
|
|
|
60
60
|
params.offset = options.offset;
|
|
61
61
|
if (options?.locale)
|
|
62
62
|
params.locale = options.locale;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
63
|
+
// `GET /topics` returns `{ topics, total, limit, offset }`. The pagination
|
|
64
|
+
// fields matter to callers, so return the whole envelope (typed) rather
|
|
65
|
+
// than throwing them away.
|
|
66
|
+
const response = await this.makeRequest('GET', '/topics', params, { cache: true, cacheTTL: CACHE_TIMES.SHORT });
|
|
67
|
+
const requestedLimit = typeof params.limit === 'number' ? params.limit : 0;
|
|
68
|
+
const requestedOffset = typeof params.offset === 'number' ? params.offset : 0;
|
|
69
|
+
return {
|
|
70
|
+
topics: response.topics ?? [],
|
|
71
|
+
total: response.total ?? response.topics?.length ?? 0,
|
|
72
|
+
limit: response.limit ?? requestedLimit,
|
|
73
|
+
offset: response.offset ?? requestedOffset,
|
|
74
|
+
};
|
|
67
75
|
}
|
|
68
76
|
catch (error) {
|
|
69
77
|
throw this.handleError(error);
|
|
@@ -92,9 +100,11 @@ export function OxyServicesTopicsMixin(Base) {
|
|
|
92
100
|
*/
|
|
93
101
|
async resolveTopicNames(names) {
|
|
94
102
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
// `POST /topics/resolve` returns `{ topics: Record<name, TopicData> }`
|
|
104
|
+
// (a name-keyed map, not an array). Unwrap and flatten to the resolved
|
|
105
|
+
// topics; each TopicData carries its own `name` for re-keying.
|
|
106
|
+
const response = await this.makeRequest('POST', '/topics/resolve', { names }, { cache: false });
|
|
107
|
+
return Object.values(response.topics ?? {});
|
|
98
108
|
}
|
|
99
109
|
catch (error) {
|
|
100
110
|
throw this.handleError(error);
|
|
@@ -3,7 +3,7 @@ import { buildSearchParams, buildPaginationParams } from '../utils/apiUtils.js';
|
|
|
3
3
|
import { KeyManager } from '../crypto/keyManager.js';
|
|
4
4
|
import { SignatureService } from '../crypto/signatureService.js';
|
|
5
5
|
import { normalizeUserIdentity, normalizeUserIdentityOrNull } from '../utils/userIdentity.js';
|
|
6
|
-
import { logger } from '../
|
|
6
|
+
import { logger } from '../logger/index.js';
|
|
7
7
|
import { extractErrorStatus } from '../utils/errorUtils.js';
|
|
8
8
|
/**
|
|
9
9
|
* Maximum number of ids sent per `POST /users/by-ids` request. Matches the
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { jwtDecode } from 'jwt-decode';
|
|
8
8
|
import { loadNodeCrypto } from '@oxyhq/protocol';
|
|
9
9
|
import { buildUrl } from '../utils/apiUtils.js';
|
|
10
|
-
import { logger } from '../
|
|
10
|
+
import { logger } from '../logger/index.js';
|
|
11
11
|
/**
|
|
12
12
|
* Expected JWT audience for tokens issued by the Oxy auth service.
|
|
13
13
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deviceSessionStateSchema, deviceSessionSyncSchema, safeParseContract, SESSION_ACCOUNTS_CHANGED_EVENT, sessionAccountsChangedEventSchema, } from '@oxyhq/contracts';
|
|
2
|
-
import { logger } from '../
|
|
2
|
+
import { logger } from '../logger/index.js';
|
|
3
3
|
import { getSocketIO } from './socketLoader.js';
|
|
4
4
|
/**
|
|
5
5
|
* Same-origin `BroadcastChannel` name for instant, network-free session-state
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* (auth.oxy.so). {@link AccountDialogController.openPasswordAtOxyAuth} only
|
|
26
26
|
* builds the hand-off URL; device-first convergence syncs the session back.
|
|
27
27
|
*/
|
|
28
|
-
import { logger } from '../
|
|
28
|
+
import { logger } from '../logger/index.js';
|
|
29
29
|
import { extractErrorStatus } from '../utils/errorUtils.js';
|
|
30
30
|
import { CENTRAL_IDP_APEX } from '../utils/authWebUrl.js';
|
|
31
31
|
import { generateOAuthState, generatePkcePair, normalizeOAuthRedirectUri, persistOAuthHandshake, } from '../utils/oauthPkce.js';
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* ESM-safe (no `require()`).
|
|
18
18
|
*/
|
|
19
|
-
import { logger } from '../
|
|
19
|
+
import { logger } from '../logger/index.js';
|
|
20
20
|
/**
|
|
21
21
|
* Versioned DURABLE storage key. Holds ONLY the small, re-mint-critical fields
|
|
22
22
|
* (`sessionId`, `userId`, `deviceId`, `deviceSecret`) — never the large JWT
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isNative } from '../utils/platform.js';
|
|
2
2
|
import { extractErrorStatus } from '../utils/errorUtils.js';
|
|
3
|
-
import { logger } from '../
|
|
3
|
+
import { logger } from '../logger/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* Lead time (ms) before access-token expiry at which the proactive scheduler
|
|
6
6
|
* re-mints. Mirrors `HttpService`'s per-request `TOKEN_REFRESH_LEAD_SECONDS`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Async utilities for common asynchronous patterns and error handling
|
|
3
3
|
*/
|
|
4
|
-
import { logger } from '
|
|
4
|
+
import { logger } from '../logger/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* Wrapper for async operations with automatic error handling
|
|
7
7
|
* Returns null on error instead of throwing
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { logger } from '../logger/index.js';
|
|
1
2
|
/**
|
|
2
3
|
* Updates file visibility to public for avatar use.
|
|
3
4
|
* Logs non-404 errors to help debug upload issues.
|
|
@@ -19,7 +20,7 @@ export async function updateAvatarVisibility(fileId, oxyServices, contextName =
|
|
|
19
20
|
? visError.status
|
|
20
21
|
: undefined;
|
|
21
22
|
if (status !== 404) {
|
|
22
|
-
|
|
23
|
+
logger.error(`[${contextName}] Failed to update avatar visibility for ${fileId}`, visError, { component: contextName });
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { loadAsyncStorage } from '@oxyhq/protocol';
|
|
2
|
+
import { createLogger } from '../logger/index.js';
|
|
3
|
+
const log = createLogger('DeviceManager');
|
|
2
4
|
/**
|
|
3
5
|
* Client-side device management utility
|
|
4
6
|
* Handles persistent device identification across app sessions
|
|
@@ -28,7 +30,7 @@ export class DeviceManager {
|
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
catch (error) {
|
|
31
|
-
|
|
33
|
+
log.error('AsyncStorage not available in React Native', error);
|
|
32
34
|
throw new Error('AsyncStorage is required in React Native environment');
|
|
33
35
|
}
|
|
34
36
|
}
|
|
@@ -79,7 +81,7 @@ export class DeviceManager {
|
|
|
79
81
|
return await this.createNewDeviceInfo();
|
|
80
82
|
}
|
|
81
83
|
catch (error) {
|
|
82
|
-
|
|
84
|
+
log.error('Error getting device info', error);
|
|
83
85
|
return await this.createNewDeviceInfo();
|
|
84
86
|
}
|
|
85
87
|
}
|
|
@@ -105,7 +107,7 @@ export class DeviceManager {
|
|
|
105
107
|
await storage.setItem(this.DEVICE_KEY, JSON.stringify(deviceInfo));
|
|
106
108
|
}
|
|
107
109
|
catch (error) {
|
|
108
|
-
|
|
110
|
+
log.error('Error saving device info', error);
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
/**
|
|
@@ -118,7 +120,7 @@ export class DeviceManager {
|
|
|
118
120
|
await this.saveDeviceInfo(deviceInfo);
|
|
119
121
|
}
|
|
120
122
|
catch (error) {
|
|
121
|
-
|
|
123
|
+
log.error('Error updating device name', error);
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
/**
|
|
@@ -130,7 +132,7 @@ export class DeviceManager {
|
|
|
130
132
|
await storage.removeItem(this.DEVICE_KEY);
|
|
131
133
|
}
|
|
132
134
|
catch (error) {
|
|
133
|
-
|
|
135
|
+
log.error('Error clearing device info', error);
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
/**
|