@oxyhq/core 9.1.0 → 9.2.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.
- package/README.md +1 -1
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/boot/{coldBootV2.js → sessionColdBoot.js} +2 -2
- package/dist/cjs/index.js +23 -4
- package/dist/cjs/mixins/OxyServices.auth.js +61 -0
- package/dist/cjs/mixins/OxyServices.deviceBoot.js +29 -1
- package/dist/cjs/server/index.js +8 -1
- package/dist/cjs/session/SessionClient.js +57 -25
- package/dist/cjs/session/accountDialogController.js +20 -9
- package/dist/cjs/session/authStateStore.js +13 -7
- package/dist/cjs/session/hubSync.js +55 -0
- package/dist/cjs/session/sessionClientHost.js +5 -0
- package/dist/cjs/utils/coldBoot.js +1 -1
- package/dist/cjs/utils/oauthPkce.js +65 -1
- package/dist/cjs/utils/officialOrigins.js +128 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/boot/{coldBootV2.js → sessionColdBoot.js} +2 -2
- package/dist/esm/index.js +4 -2
- package/dist/esm/mixins/OxyServices.auth.js +61 -0
- package/dist/esm/mixins/OxyServices.deviceBoot.js +30 -2
- package/dist/esm/server/index.js +1 -0
- package/dist/esm/session/SessionClient.js +57 -25
- package/dist/esm/session/accountDialogController.js +20 -9
- package/dist/esm/session/authStateStore.js +13 -7
- package/dist/esm/session/hubSync.js +51 -0
- package/dist/esm/session/sessionClientHost.js +5 -0
- package/dist/esm/utils/coldBoot.js +1 -1
- package/dist/esm/utils/oauthPkce.js +60 -0
- package/dist/esm/utils/officialOrigins.js +119 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/boot/{coldBootV2.d.ts → sessionColdBoot.d.ts} +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/mixins/OxyServices.auth.d.ts +14 -0
- package/dist/types/mixins/OxyServices.deviceBoot.d.ts +6 -2
- package/dist/types/server/index.d.ts +1 -0
- package/dist/types/session/SessionClient.d.ts +6 -0
- package/dist/types/session/accountDialogController.d.ts +9 -1
- package/dist/types/session/authStateStore.d.ts +1 -1
- package/dist/types/session/hubSync.d.ts +20 -0
- package/dist/types/session/sessionClientHost.d.ts +2 -1
- package/dist/types/utils/coldBoot.d.ts +2 -2
- package/dist/types/utils/oauthPkce.d.ts +27 -0
- package/dist/types/utils/officialOrigins.d.ts +17 -0
- package/package.json +2 -2
- package/src/boot/__tests__/{coldBootV2.test.ts → sessionColdBoot.test.ts} +1 -1
- package/src/boot/{coldBootV2.ts → sessionColdBoot.ts} +2 -2
- package/src/index.ts +27 -3
- package/src/mixins/OxyServices.auth.ts +70 -1
- package/src/mixins/OxyServices.deviceBoot.ts +46 -1
- package/src/server/index.ts +8 -0
- package/src/session/SessionClient.ts +68 -26
- package/src/session/__tests__/SessionClient.additive.test.ts +1 -0
- package/src/session/__tests__/SessionClient.broadcastChannel.test.ts +1 -0
- package/src/session/__tests__/SessionClient.diagnostics.test.ts +1 -0
- package/src/session/__tests__/SessionClient.rest.test.ts +1 -0
- package/src/session/__tests__/SessionClient.socket.test.ts +1 -0
- package/src/session/__tests__/SessionClient.socketFactory.test.ts +1 -0
- package/src/session/__tests__/SessionClient.state.test.ts +1 -0
- package/src/session/__tests__/accountDialogController.test.ts +38 -6
- package/src/session/__tests__/sessionIntegration.test.ts +7 -0
- package/src/session/accountDialogController.ts +36 -10
- package/src/session/authStateStore.ts +18 -9
- package/src/session/hubSync.ts +79 -0
- package/src/session/sessionClientHost.ts +10 -2
- package/src/utils/__tests__/officialOrigins.test.ts +74 -0
- package/src/utils/coldBoot.ts +2 -2
- package/src/utils/oauthPkce.ts +71 -0
- package/src/utils/officialOrigins.ts +124 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official first-party web origin allowlist — shared by hub-ticket issuance,
|
|
3
|
+
* OAuth redirect validation, and cross-origin session restore.
|
|
4
|
+
*/
|
|
5
|
+
import { CENTRAL_IDP_APEX } from './authWebUrl.js';
|
|
6
|
+
import { registrableApex } from './registrableApex.js';
|
|
7
|
+
/** Official first-party registrable apexes (mirrors API trusted origins). */
|
|
8
|
+
const OFFICIAL_APEXES = new Set([
|
|
9
|
+
'oxy.so',
|
|
10
|
+
'fairco.in',
|
|
11
|
+
'mention.earth',
|
|
12
|
+
'homiio.com',
|
|
13
|
+
'alia.onl',
|
|
14
|
+
'syra.fm',
|
|
15
|
+
'allo.you',
|
|
16
|
+
'tnp.network',
|
|
17
|
+
'moovo.now',
|
|
18
|
+
'mercaria.co',
|
|
19
|
+
]);
|
|
20
|
+
export function buildIdpHubOrigin() {
|
|
21
|
+
return `https://auth.${CENTRAL_IDP_APEX}`;
|
|
22
|
+
}
|
|
23
|
+
/** Whether the current web origin is the central IdP hub (`auth.oxy.so`). */
|
|
24
|
+
export function isIdpHubOrigin() {
|
|
25
|
+
if (typeof globalThis === 'undefined') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const location = globalThis.location;
|
|
29
|
+
if (!location) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const { hostname } = new URL(location.href);
|
|
34
|
+
return hostname === `auth.${CENTRAL_IDP_APEX}`;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function isLoopbackOrigin(origin) {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = new URL(origin);
|
|
43
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const host = parsed.hostname.toLowerCase();
|
|
47
|
+
return host === 'localhost' || host === '127.0.0.1' || host === '[::1]';
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Whether an origin belongs to the official Oxy web ecosystem. */
|
|
54
|
+
export function isOfficialWebOrigin(origin) {
|
|
55
|
+
if (isLoopbackOrigin(origin)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const parsed = new URL(origin);
|
|
60
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const host = parsed.hostname.toLowerCase();
|
|
64
|
+
if (host === CENTRAL_IDP_APEX || host.endsWith(`.${CENTRAL_IDP_APEX}`)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
const apex = registrableApex(host);
|
|
68
|
+
return apex != null && OFFICIAL_APEXES.has(apex);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Normalize and validate a return URL against official origins. Returns origin only. */
|
|
75
|
+
export function normalizeOfficialReturnOrigin(raw) {
|
|
76
|
+
try {
|
|
77
|
+
const parsed = new URL(raw);
|
|
78
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (!isOfficialWebOrigin(parsed.origin)) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return parsed.origin;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Validate a hub-sync return URL; returns the full normalized URL string. */
|
|
91
|
+
export function parseHubSyncReturnUrl(raw) {
|
|
92
|
+
if (!raw) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const parsed = new URL(raw);
|
|
97
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
if (!isOfficialWebOrigin(parsed.origin)) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return parsed.toString();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Build auth.oxy.so/sync redirect URL with a one-time hub ticket. */
|
|
110
|
+
export function buildHubSyncUrl(ticket, returnUrl) {
|
|
111
|
+
const url = new URL('/sync', buildIdpHubOrigin());
|
|
112
|
+
url.searchParams.set('ticket', ticket);
|
|
113
|
+
if (returnUrl) {
|
|
114
|
+
url.searchParams.set('return', returnUrl);
|
|
115
|
+
}
|
|
116
|
+
return url.toString();
|
|
117
|
+
}
|
|
118
|
+
/** @deprecated Use {@link isOfficialWebOrigin}. */
|
|
119
|
+
export const isAllowedDeviceJoinOrigin = isOfficialWebOrigin;
|