@oxyhq/core 3.2.0 → 3.4.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/AuthManager.js +3 -1
- package/dist/cjs/HttpService.js +89 -0
- package/dist/cjs/OxyServices.js +1 -1
- package/dist/cjs/constants/version.js +1 -1
- package/dist/cjs/i18n/locales/en-US.json +44 -44
- package/dist/cjs/i18n/locales/es-ES.json +44 -44
- package/dist/cjs/i18n/locales/locales/en-US.json +44 -44
- package/dist/cjs/i18n/locales/locales/es-ES.json +44 -44
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/mixins/OxyServices.applications.js +3 -1
- package/dist/cjs/mixins/OxyServices.reputation.js +244 -0
- package/dist/cjs/mixins/OxyServices.workspaces.js +3 -1
- package/dist/cjs/mixins/index.js +2 -2
- package/dist/cjs/utils/accountUtils.js +12 -5
- package/dist/cjs/utils/ssoReturn.js +80 -33
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/AuthManager.js +3 -1
- package/dist/esm/HttpService.js +89 -0
- package/dist/esm/OxyServices.js +1 -1
- package/dist/esm/constants/version.js +1 -1
- package/dist/esm/i18n/locales/en-US.json +44 -44
- package/dist/esm/i18n/locales/es-ES.json +44 -44
- package/dist/esm/i18n/locales/locales/en-US.json +44 -44
- package/dist/esm/i18n/locales/locales/es-ES.json +44 -44
- package/dist/esm/index.js +4 -0
- package/dist/esm/mixins/OxyServices.applications.js +3 -1
- package/dist/esm/mixins/OxyServices.reputation.js +241 -0
- package/dist/esm/mixins/OxyServices.workspaces.js +3 -1
- package/dist/esm/mixins/index.js +2 -2
- package/dist/esm/utils/accountUtils.js +12 -5
- package/dist/esm/utils/ssoReturn.js +80 -33
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/HttpService.d.ts +57 -0
- package/dist/types/OxyServices.d.ts +1 -1
- package/dist/types/constants/version.d.ts +2 -2
- package/dist/types/index.d.ts +2 -1
- package/dist/types/mixins/OxyServices.applications.d.ts +8 -2
- package/dist/types/mixins/OxyServices.features.d.ts +0 -1
- package/dist/types/mixins/OxyServices.reputation.d.ts +436 -0
- package/dist/types/mixins/OxyServices.workspaces.d.ts +8 -2
- package/dist/types/mixins/index.d.ts +2 -2
- package/dist/types/models/interfaces.d.ts +15 -26
- package/dist/types/utils/accountUtils.d.ts +17 -4
- package/dist/types/utils/ssoReturn.d.ts +30 -9
- package/package.json +2 -1
- package/src/AuthManager.ts +3 -1
- package/src/HttpService.ts +91 -0
- package/src/OxyServices.ts +1 -1
- package/src/__tests__/httpServiceCache.test.ts +198 -0
- package/src/constants/version.ts +1 -1
- package/src/i18n/locales/en-US.json +44 -44
- package/src/i18n/locales/es-ES.json +44 -44
- package/src/index.ts +32 -4
- package/src/mixins/OxyServices.applications.ts +8 -2
- package/src/mixins/OxyServices.auth.ts +2 -1
- package/src/mixins/OxyServices.features.ts +0 -1
- package/src/mixins/OxyServices.reputation.ts +674 -0
- package/src/mixins/OxyServices.workspaces.ts +8 -2
- package/src/mixins/__tests__/reputation.test.ts +408 -0
- package/src/mixins/index.ts +3 -3
- package/src/models/interfaces.ts +16 -32
- package/src/utils/__tests__/accountUtils.test.ts +142 -0
- package/src/utils/__tests__/consumeSsoReturn.test.ts +229 -37
- package/src/utils/accountUtils.ts +20 -5
- package/src/utils/ssoReturn.ts +98 -37
- package/dist/cjs/mixins/OxyServices.developer.js +0 -97
- package/dist/cjs/mixins/OxyServices.karma.js +0 -108
- package/dist/esm/mixins/OxyServices.developer.js +0 -94
- package/dist/esm/mixins/OxyServices.karma.js +0 -105
- package/dist/types/mixins/OxyServices.developer.d.ts +0 -106
- package/dist/types/mixins/OxyServices.karma.d.ts +0 -92
- package/src/mixins/OxyServices.karma.ts +0 -111
|
@@ -87,7 +87,9 @@ function OxyServicesWorkspacesMixin(Base) {
|
|
|
87
87
|
/**
|
|
88
88
|
* Add a member to a workspace.
|
|
89
89
|
* @param workspaceId - The workspace's Mongo `_id`.
|
|
90
|
-
* @param data - Target user
|
|
90
|
+
* @param data - Target user's username or email and role (never `owner`).
|
|
91
|
+
* The server resolves `usernameOrEmail` to a user; an unknown value yields
|
|
92
|
+
* a 404 "User not found".
|
|
91
93
|
*/
|
|
92
94
|
async inviteWorkspaceMember(workspaceId, data) {
|
|
93
95
|
try {
|
package/dist/cjs/mixins/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const OxyServices_user_1 = require("./OxyServices.user");
|
|
|
18
18
|
const OxyServices_privacy_1 = require("./OxyServices.privacy");
|
|
19
19
|
const OxyServices_language_1 = require("./OxyServices.language");
|
|
20
20
|
const OxyServices_payment_1 = require("./OxyServices.payment");
|
|
21
|
-
const
|
|
21
|
+
const OxyServices_reputation_1 = require("./OxyServices.reputation");
|
|
22
22
|
const OxyServices_assets_1 = require("./OxyServices.assets");
|
|
23
23
|
const OxyServices_applications_1 = require("./OxyServices.applications");
|
|
24
24
|
const OxyServices_workspaces_1 = require("./OxyServices.workspaces");
|
|
@@ -63,7 +63,7 @@ const MIXIN_PIPELINE = [
|
|
|
63
63
|
// Feature mixins
|
|
64
64
|
OxyServices_language_1.OxyServicesLanguageMixin,
|
|
65
65
|
OxyServices_payment_1.OxyServicesPaymentMixin,
|
|
66
|
-
|
|
66
|
+
OxyServices_reputation_1.OxyServicesReputationMixin,
|
|
67
67
|
OxyServices_assets_1.OxyServicesAssetsMixin,
|
|
68
68
|
OxyServices_applications_1.OxyServicesApplicationsMixin,
|
|
69
69
|
OxyServices_workspaces_1.OxyServicesWorkspacesMixin,
|
|
@@ -21,11 +21,16 @@ exports.formatPublicKeyHandle = formatPublicKeyHandle;
|
|
|
21
21
|
* Resolve a friendly display name for a user.
|
|
22
22
|
*
|
|
23
23
|
* Order of preference:
|
|
24
|
-
* 1. `name.full`, or composed `name.first name.last`
|
|
24
|
+
* 1. `name.full`, or composed `name.first name.last` (FIRST-NAME-ONLY SAFE —
|
|
25
|
+
* a user with only a first name resolves to that first name, never to the
|
|
26
|
+
* lowercase username; this is the exact drift bug the auth app hit).
|
|
25
27
|
* 2. `name` (when stored as a plain string)
|
|
26
|
-
* 3. `username`
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* 3. `displayName` (server `displayName` virtual — `username || truncatedKey`).
|
|
29
|
+
* Placed AFTER the structured name on purpose: the server virtual ignores
|
|
30
|
+
* `name`, so preferring it first would re-introduce the first-only bug.
|
|
31
|
+
* 4. `username`
|
|
32
|
+
* 5. `Account 0x12345678…` (derived from publicKey, when present)
|
|
33
|
+
* 6. Translated fallback (e.g. "Unnamed")
|
|
29
34
|
*
|
|
30
35
|
* The translation key `common.unnamed` is used for the final fallback. If the
|
|
31
36
|
* caller does not pass a locale, the default English translation is used.
|
|
@@ -33,7 +38,7 @@ exports.formatPublicKeyHandle = formatPublicKeyHandle;
|
|
|
33
38
|
const getAccountDisplayName = (user, locale) => {
|
|
34
39
|
if (!user)
|
|
35
40
|
return (0, i18n_1.translate)(locale, 'common.unnamed');
|
|
36
|
-
const { name, username, publicKey } = user;
|
|
41
|
+
const { name, displayName, username, publicKey } = user;
|
|
37
42
|
if (name && typeof name === 'object') {
|
|
38
43
|
if (typeof name.full === 'string' && name.full.trim())
|
|
39
44
|
return name.full.trim();
|
|
@@ -46,6 +51,8 @@ const getAccountDisplayName = (user, locale) => {
|
|
|
46
51
|
else if (typeof name === 'string' && name.trim()) {
|
|
47
52
|
return name.trim();
|
|
48
53
|
}
|
|
54
|
+
if (typeof displayName === 'string' && displayName.trim())
|
|
55
|
+
return displayName.trim();
|
|
49
56
|
if (typeof username === 'string' && username.trim())
|
|
50
57
|
return username.trim();
|
|
51
58
|
if (typeof publicKey === 'string' && publicKey.length > 0) {
|
|
@@ -96,14 +96,22 @@ function parseSsoReturnFragment(hash) {
|
|
|
96
96
|
* treated exactly like "no session" (never loops, never rethrows).
|
|
97
97
|
* - On EVERY consumed outcome (ok, none, error, state-mismatch, no-code,
|
|
98
98
|
* failed-exchange, no-sessionId) — not just ok — if the page landed on
|
|
99
|
-
* {@link SSO_CALLBACK_PATH}, the
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
99
|
+
* {@link SSO_CALLBACK_PATH}, the user is taken to a same-origin TARGET so
|
|
100
|
+
* they are never stranded on the internal callback path (which is an
|
|
101
|
+
* unregistered route in every consumer router → a hard 404). The target is
|
|
102
|
+
* the stored DEST when it parses as same-origin (an attacker-planted
|
|
103
|
+
* cross-origin / protocol-relative dest is rejected), ELSE the app root
|
|
104
|
+
* (`origin + '/'`). The DEST key is removed unconditionally.
|
|
105
|
+
* - For the `ok` outcome the target is applied via a SOFT
|
|
106
|
+
* `history.replaceState` + synthetic `popstate` so the freshly exchanged
|
|
107
|
+
* in-memory session the provider is about to commit is preserved (no
|
|
108
|
+
* reload). `popstate` is dispatched only on the `ok` same-origin restore.
|
|
109
|
+
* - For every NON-`ok` outcome there is no in-memory session to preserve, and
|
|
110
|
+
* the consumer router has ALREADY synchronously rendered its 404 for the
|
|
111
|
+
* unregistered callback route — a soft replaceState+popstate does not
|
|
112
|
+
* reliably make it re-resolve. So these outcomes perform a HARD
|
|
113
|
+
* full-document navigation to the target (`hardRedirect`), which is both
|
|
114
|
+
* safe (nothing to lose) and guaranteed to clear the 404 in every router.
|
|
107
115
|
*
|
|
108
116
|
* Total: this function NEVER throws. Off-web it is a no-op returning `null`.
|
|
109
117
|
*
|
|
@@ -137,6 +145,17 @@ async function consumeSsoReturn(oxy, deps = {}) {
|
|
|
137
145
|
window.dispatchEvent(new Event('popstate'));
|
|
138
146
|
}
|
|
139
147
|
});
|
|
148
|
+
// Default: a hard, full-document navigation used to leave the callback path
|
|
149
|
+
// on non-`ok` outcomes. Feature-detected end to end so it never throws in any
|
|
150
|
+
// environment (SSR / native / a stubbed location without `replace`).
|
|
151
|
+
const hardRedirect = deps.hardRedirect ??
|
|
152
|
+
((url) => {
|
|
153
|
+
if (typeof window !== 'undefined' &&
|
|
154
|
+
window.location &&
|
|
155
|
+
typeof window.location.replace === 'function') {
|
|
156
|
+
window.location.replace(url);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
140
159
|
const ret = parseSsoReturnFragment(location.hash);
|
|
141
160
|
if (!ret) {
|
|
142
161
|
// Not an oxy_sso fragment — nothing to do (do NOT touch any flags).
|
|
@@ -159,42 +178,62 @@ async function consumeSsoReturn(oxy, deps = {}) {
|
|
|
159
178
|
// even if some consumer path skipped setting it pre-bounce.
|
|
160
179
|
storage.setItem((0, ssoBounce_1.ssoAttemptedKey)(origin), '1');
|
|
161
180
|
};
|
|
162
|
-
//
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
// Compute the same-origin TARGET to leave the callback path for. Returns the
|
|
182
|
+
// stored DEST when present AND it parses as same-origin (never honour a
|
|
183
|
+
// cross-origin / protocol-relative dest that could have been planted to
|
|
184
|
+
// redirect the user), ELSE the app root (`origin + '/'`) so the user is never
|
|
185
|
+
// stranded on the internal callback path even when no dest was stored. The
|
|
186
|
+
// DEST key is removed unconditionally. Returns the relative path+search+hash
|
|
187
|
+
// (so it can be fed to either `history.replaceState` or a `hardRedirect`),
|
|
188
|
+
// or `null` when the page is not on the callback path (nothing to leave).
|
|
189
|
+
const consumeCallbackTarget = () => {
|
|
190
|
+
if (location.pathname !== ssoBounce_1.SSO_CALLBACK_PATH) {
|
|
191
|
+
// Not on the callback path — still drop the dest key (consumed) but there
|
|
192
|
+
// is nothing to navigate away from.
|
|
193
|
+
storage.removeItem((0, ssoBounce_1.ssoDestKey)(origin));
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const dest = storage.getItem((0, ssoBounce_1.ssoDestKey)(origin));
|
|
197
|
+
storage.removeItem((0, ssoBounce_1.ssoDestKey)(origin));
|
|
198
|
+
if (dest) {
|
|
199
|
+
try {
|
|
200
|
+
const destUrl = new URL(dest, origin);
|
|
201
|
+
if (destUrl.origin === origin) {
|
|
202
|
+
return destUrl.pathname + destUrl.search + destUrl.hash;
|
|
181
203
|
}
|
|
182
204
|
}
|
|
205
|
+
catch {
|
|
206
|
+
// Malformed stored destination — fall through to the app-root fallback.
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// No dest, a cross-origin/protocol-relative dest, or an unparseable dest:
|
|
210
|
+
// fall back to the app root so the router always leaves the 404.
|
|
211
|
+
return '/';
|
|
212
|
+
};
|
|
213
|
+
// Non-`ok` outcomes: there is no in-memory session to preserve, and the
|
|
214
|
+
// consumer router has already rendered its 404 for the unregistered callback
|
|
215
|
+
// route — a soft replaceState+popstate does not reliably make it re-resolve.
|
|
216
|
+
// Perform a HARD full-document navigation to the target (safe: nothing to
|
|
217
|
+
// lose; guaranteed: every router leaves the 404). Off the callback path this
|
|
218
|
+
// is a no-op (target is null).
|
|
219
|
+
const leaveCallbackHard = () => {
|
|
220
|
+
const target = consumeCallbackTarget();
|
|
221
|
+
if (target !== null) {
|
|
222
|
+
hardRedirect(origin + target);
|
|
183
223
|
}
|
|
184
|
-
storage.removeItem((0, ssoBounce_1.ssoDestKey)(origin));
|
|
185
224
|
};
|
|
186
225
|
if (ret.kind === 'none' || ret.kind === 'error') {
|
|
187
226
|
// The central IdP had no session (or the bounce failed). Record it so we do
|
|
188
227
|
// not bounce again this tab — the definitive loop breaker.
|
|
189
228
|
markNoSession();
|
|
190
|
-
|
|
229
|
+
leaveCallbackHard();
|
|
191
230
|
return null;
|
|
192
231
|
}
|
|
193
232
|
if (!stateOk || !ret.code) {
|
|
194
233
|
// Forged / replayed / stale fragment, or a malformed ok with no code. Treat
|
|
195
234
|
// exactly like "no session": never exchange, never loop.
|
|
196
235
|
markNoSession();
|
|
197
|
-
|
|
236
|
+
leaveCallbackHard();
|
|
198
237
|
return null;
|
|
199
238
|
}
|
|
200
239
|
let session;
|
|
@@ -204,14 +243,22 @@ async function consumeSsoReturn(oxy, deps = {}) {
|
|
|
204
243
|
catch (error) {
|
|
205
244
|
onExchangeError?.(error);
|
|
206
245
|
markNoSession();
|
|
207
|
-
|
|
246
|
+
leaveCallbackHard();
|
|
208
247
|
return null;
|
|
209
248
|
}
|
|
210
249
|
if (!session?.sessionId) {
|
|
211
250
|
markNoSession();
|
|
212
|
-
|
|
251
|
+
leaveCallbackHard();
|
|
213
252
|
return null;
|
|
214
253
|
}
|
|
215
|
-
|
|
254
|
+
// `ok`: the provider is about to commit the freshly exchanged in-memory
|
|
255
|
+
// session — do NOT hard-redirect (a full navigation would discard it). Use a
|
|
256
|
+
// SOFT `history.replaceState` to the target + a synthetic `popstate` so
|
|
257
|
+
// URL-driven routers re-sync to the restored route without a reload.
|
|
258
|
+
const target = consumeCallbackTarget();
|
|
259
|
+
if (target !== null) {
|
|
260
|
+
history.replaceState(null, '', target);
|
|
261
|
+
dispatchPopState();
|
|
262
|
+
}
|
|
216
263
|
return session;
|
|
217
264
|
}
|