@ikonai/sdk 1.3.10 → 1.3.11
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/client/endpoint-selector.d.ts +66 -7
- package/client/ikon-client-config.d.ts +4 -3
- package/client/ikon-client.d.ts +12 -0
- package/connection/authenticator.d.ts +7 -3
- package/connection/urls.d.ts +10 -0
- package/index.d.ts +2 -2
- package/index.js +1940 -1899
- package/package.json +1 -1
- package/utils/query-params.d.ts +11 -1
|
@@ -4,9 +4,43 @@ import { LocalConfig } from './ikon-client-config';
|
|
|
4
4
|
* Proxy connection mode.
|
|
5
5
|
* - `force-proxy`: only try proxy URLs/transports (e.g. `?ikon-proxy=true`)
|
|
6
6
|
* - `force-direct`: only try direct URLs/transports (e.g. `?ikon-proxy=false`)
|
|
7
|
-
* - `
|
|
7
|
+
* - `force-lb`: only try the same-origin stream tier (e.g. `?ikon-proxy=lb`)
|
|
8
|
+
* - `auto`: try all of them, ordered by preference, with persistent learning
|
|
8
9
|
*/
|
|
9
|
-
export type ProxyMode = 'force-proxy' | 'force-direct' | 'auto';
|
|
10
|
+
export type ProxyMode = 'force-proxy' | 'force-direct' | 'force-lb' | 'auto';
|
|
11
|
+
/**
|
|
12
|
+
* Which connect URL a session reaches its ikon server through, most permissive network first.
|
|
13
|
+
*
|
|
14
|
+
* - `direct` — the ikon server's own host and port
|
|
15
|
+
* - `proxy` — the on-host proxy, same host on 443
|
|
16
|
+
* - `lb` — the app's own origin on 443, through the fleet proxy gateway
|
|
17
|
+
*
|
|
18
|
+
* A separate axis from {@link EntrypointType}, and it has to be: the gateway advertises no
|
|
19
|
+
* WebTransport, so `proxy` and `lb` both come back as `WebSocketProxy` and the entrypoint type
|
|
20
|
+
* cannot tell them apart. Only the connect URL that answered knows which one it was.
|
|
21
|
+
*/
|
|
22
|
+
export type ConnectTier = 'direct' | 'proxy' | 'lb';
|
|
23
|
+
/** Most permissive first — a rung is only worth trying when the ones above it failed. */
|
|
24
|
+
export declare const CONNECT_TIER_LADDER: ConnectTier[];
|
|
25
|
+
/**
|
|
26
|
+
* The connect URLs to attempt, best first, given what the backend offered and what this client has
|
|
27
|
+
* learned.
|
|
28
|
+
*
|
|
29
|
+
* In `auto` mode it starts at the learned rung and walks *down* before wrapping back up: the reason
|
|
30
|
+
* a rung stopped working is almost always a network that tightened, and the rungs below it are the
|
|
31
|
+
* ones that survive that. A network that loosened is caught by the background probe instead, which
|
|
32
|
+
* costs nothing on the connect path.
|
|
33
|
+
*
|
|
34
|
+
* A learned rung the backend did not offer this session resumes at the first available rung no
|
|
35
|
+
* *shallower* than it — never above it, because the rungs above are the ones already known to fail
|
|
36
|
+
* on this network. An `lb` client meeting a backend with no stream tier falls back to the deepest
|
|
37
|
+
* rung on offer rather than starting again at the top, which is also what makes the two-rung case
|
|
38
|
+
* reduce exactly to the old behaviour.
|
|
39
|
+
*
|
|
40
|
+
* A free function rather than a method so the authenticator can order without holding a selector,
|
|
41
|
+
* and so the ordering is testable on its own.
|
|
42
|
+
*/
|
|
43
|
+
export declare function orderConnectTiers(availableTiers: ConnectTier[], learnedTier: ConnectTier, proxyMode: ProxyMode): ConnectTier[];
|
|
10
44
|
/**
|
|
11
45
|
* EndpointSelector handles ordering and selection of endpoint types.
|
|
12
46
|
*
|
|
@@ -24,7 +58,7 @@ export declare class EndpointSelector {
|
|
|
24
58
|
private readonly _proxyMode;
|
|
25
59
|
private readonly _websocket;
|
|
26
60
|
private readonly _webtransport;
|
|
27
|
-
private
|
|
61
|
+
private _connectTier;
|
|
28
62
|
private workingEndpointType;
|
|
29
63
|
constructor(config: {
|
|
30
64
|
local?: LocalConfig;
|
|
@@ -33,14 +67,29 @@ export declare class EndpointSelector {
|
|
|
33
67
|
webtransport?: boolean;
|
|
34
68
|
});
|
|
35
69
|
get proxyMode(): ProxyMode;
|
|
70
|
+
/** The connect tier last known to work. */
|
|
71
|
+
get connectTier(): ConnectTier;
|
|
72
|
+
/**
|
|
73
|
+
* Whether proxied entrypoint types should outrank direct ones.
|
|
74
|
+
*
|
|
75
|
+
* True for both proxied tiers: a session that reached its server through the gateway is on a
|
|
76
|
+
* network that refused the host's own ports, so the direct entrypoints will fail there too.
|
|
77
|
+
*/
|
|
36
78
|
get proxyPreferred(): boolean;
|
|
37
79
|
/** The endpoint type last known to work, or null when nothing has been learned yet. */
|
|
38
80
|
get rememberedType(): EntrypointType | null;
|
|
39
81
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
82
|
+
* The connect URL that just answered. Authoritative — it is the only thing that can distinguish
|
|
83
|
+
* the two proxied tiers.
|
|
42
84
|
*/
|
|
43
|
-
|
|
85
|
+
recordWorkingConnectTier(tier: ConnectTier): void;
|
|
86
|
+
/**
|
|
87
|
+
* A background probe reached a tier above the one in use. Adopt it for the next connection; the
|
|
88
|
+
* current one is left alone.
|
|
89
|
+
*/
|
|
90
|
+
recordReachableConnectTier(tier: ConnectTier): void;
|
|
91
|
+
/** The tiers worth probing from the one in use, best first. Empty when already at the top. */
|
|
92
|
+
getFasterConnectTiers(activeTier: ConnectTier): ConnectTier[];
|
|
44
93
|
/**
|
|
45
94
|
* Clear the proxy preference so the next connection tries direct first.
|
|
46
95
|
*/
|
|
@@ -74,6 +123,11 @@ export declare class EndpointSelector {
|
|
|
74
123
|
* A probe reached a tier faster than the remembered one — the network is no longer the one the
|
|
75
124
|
* preference was learned on. Drop the preference so the next connection starts from base
|
|
76
125
|
* priority; the current connection is left alone.
|
|
126
|
+
*
|
|
127
|
+
* Only a *direct* type says anything about the connect tier. A faster proxied type (WebTransport
|
|
128
|
+
* over the proxy, say) is still reached through a proxied connect URL, so throwing an `lb` client
|
|
129
|
+
* back to the top of the ladder on that evidence would cost it the full walk to end up where it
|
|
130
|
+
* already was.
|
|
77
131
|
*/
|
|
78
132
|
recordFasterTypeReachable(type: EntrypointType): void;
|
|
79
133
|
/**
|
|
@@ -84,5 +138,10 @@ export declare class EndpointSelector {
|
|
|
84
138
|
private filterByTransport;
|
|
85
139
|
private revalidationAgeMs;
|
|
86
140
|
private loadRememberedType;
|
|
87
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Reads nothing back into storage, deliberately: a page that loads and never connects must not
|
|
143
|
+
* create state it did not earn.
|
|
144
|
+
*/
|
|
145
|
+
private loadConnectTier;
|
|
146
|
+
private setConnectTier;
|
|
88
147
|
}
|
|
@@ -360,11 +360,12 @@ export interface IkonClientConfig {
|
|
|
360
360
|
*/
|
|
361
361
|
webtransport?: boolean;
|
|
362
362
|
/**
|
|
363
|
-
*
|
|
364
|
-
* When false, proxy types are excluded.
|
|
363
|
+
* Pin the connect tier. When true, only the on-host proxy on 443 is used, and only proxy endpoint
|
|
364
|
+
* types with it. When false, proxy types are excluded. `'lb'` pins the same-origin stream tier
|
|
365
|
+
* through the fleet proxy gateway, which auto mode reaches only after the other two fail.
|
|
365
366
|
* Can be overridden by the `?ikon-proxy=` query parameter.
|
|
366
367
|
*/
|
|
367
|
-
proxy?: boolean;
|
|
368
|
+
proxy?: boolean | 'lb';
|
|
368
369
|
/**
|
|
369
370
|
* Turn same-origin links into in-place route changes instead of document loads.
|
|
370
371
|
*
|
package/client/ikon-client.d.ts
CHANGED
|
@@ -443,6 +443,18 @@ export declare class IkonClient {
|
|
|
443
443
|
* Authenticate with the server.
|
|
444
444
|
*/
|
|
445
445
|
private authenticate;
|
|
446
|
+
/**
|
|
447
|
+
* Walk back up the ladder in the background after landing on anything but the top rung.
|
|
448
|
+
*
|
|
449
|
+
* Only in auto mode: the probe exists to retire a learned preference, and a force mode has none to
|
|
450
|
+
* retire — it was told which tier to use. Running it anyway spends a request on the direct high
|
|
451
|
+
* port that `force-proxy` exists to avoid, and lets a reachable direct server clear a preference
|
|
452
|
+
* `EndpointSelector` promises force modes never touch.
|
|
453
|
+
*
|
|
454
|
+
* Nothing ever probes *up to* `lb`, since it is the bottom rung — so the stream tier's `/health`
|
|
455
|
+
* having no load-balancer route of its own does not matter here.
|
|
456
|
+
*/
|
|
457
|
+
private probeFasterConnectTiers;
|
|
446
458
|
/**
|
|
447
459
|
* Handle incoming protocol message from channel manager.
|
|
448
460
|
*/
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { AuthResponse, ClientEnvironment } from '../../shared/protocol/src/index.ts';
|
|
2
2
|
import { ApiKeyConfig, LocalConfig, SessionTokenConfig } from '../client/ikon-client-config';
|
|
3
|
-
import { ProxyMode } from '../client/endpoint-selector';
|
|
3
|
+
import { ConnectTier, ProxyMode } from '../client/endpoint-selector';
|
|
4
4
|
/**
|
|
5
5
|
* Result of authentication - contains the AuthResponse from the server.
|
|
6
6
|
*/
|
|
7
7
|
export interface AuthResult {
|
|
8
8
|
authResponse: AuthResponse;
|
|
9
9
|
usedProxyUrl?: boolean;
|
|
10
|
+
/** Which connect-URL rung answered. */
|
|
11
|
+
connectTier?: ConnectTier;
|
|
12
|
+
/** Every rung offered this session, absolute, so the client can probe the ones above the winner. */
|
|
13
|
+
connectTierUrls?: Partial<Record<ConnectTier, string>>;
|
|
10
14
|
directUrl?: string;
|
|
11
15
|
backendUrl?: string;
|
|
12
16
|
authToken?: string;
|
|
@@ -43,7 +47,7 @@ export declare function authenticateLocal(config: LocalConfig, signal?: AbortSig
|
|
|
43
47
|
* 2. POST /init to create profile, resolve the app session, and wait for running
|
|
44
48
|
* 3. Connect to the returned Ikon server URL
|
|
45
49
|
*/
|
|
46
|
-
export declare function authenticateApiKey(config: ApiKeyConfig, signal?: AbortSignal, proxyMode?: ProxyMode,
|
|
50
|
+
export declare function authenticateApiKey(config: ApiKeyConfig, signal?: AbortSignal, proxyMode?: ProxyMode, learnedTier?: ConnectTier): Promise<AuthResult>;
|
|
47
51
|
/**
|
|
48
52
|
* Authenticate with the Ikon backend using a pre-obtained session token.
|
|
49
53
|
* Use this when the token was obtained from auth.ikonai.com (OAuth) or /auth/anonymous.
|
|
@@ -53,4 +57,4 @@ export declare function authenticateApiKey(config: ApiKeyConfig, signal?: AbortS
|
|
|
53
57
|
* 2. POST /init to create profile, resolve the app session, and wait for running
|
|
54
58
|
* 3. Connect to the returned Ikon server URL
|
|
55
59
|
*/
|
|
56
|
-
export declare function authenticateSessionToken(config: SessionTokenConfig, signal?: AbortSignal, proxyMode?: ProxyMode,
|
|
60
|
+
export declare function authenticateSessionToken(config: SessionTokenConfig, signal?: AbortSignal, proxyMode?: ProxyMode, learnedTier?: ConnectTier): Promise<AuthResult>;
|
package/connection/urls.d.ts
CHANGED
|
@@ -20,6 +20,16 @@ export declare const IKON_AUTH_BASE_URL = "https://auth.ikonai.com";
|
|
|
20
20
|
* cloud / non-browser. Requires the app LB to route `/ikon/auth/* → auth backend`.
|
|
21
21
|
*/
|
|
22
22
|
export declare function getSameOriginAuthUrl(): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the stream tier's connect path (`/ikon/stream/connect?…`) against the page origin.
|
|
25
|
+
*
|
|
26
|
+
* The backend hands this one over as a path rather than a URL because it cannot know the origin: an
|
|
27
|
+
* app may be served from a customer domain that appears nowhere in the Space document. That origin
|
|
28
|
+
* is the whole point of the tier — it is the one hostname a network that allowlists this app must
|
|
29
|
+
* already pass. Returns null off cloud / non-browser. Requires the app LB to route
|
|
30
|
+
* `/ikon/stream/* → proxy gateway`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getSameOriginStreamUrl(streamPath: string): string | null;
|
|
23
33
|
/**
|
|
24
34
|
* Get backend URL from BackendType.
|
|
25
35
|
* Defaults to same-origin /ikon/api on deployed apps; honors ?ikon-api=false to opt out.
|
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type { ConnectionState } from './client/connection-state';
|
|
|
5
5
|
export { isConnecting, isConnected, isOffline, isError } from './client/connection-state';
|
|
6
6
|
export { ChannelManager, type ChannelManagerConfig, type ChannelManagerState } from './channel/channel-manager';
|
|
7
7
|
export { Channel, type ChannelConfig, type ChannelState } from './channel/channel';
|
|
8
|
-
export { EndpointSelector, type ProxyMode } from './client/endpoint-selector';
|
|
8
|
+
export { EndpointSelector, orderConnectTiers, CONNECT_TIER_LADDER, type ConnectTier, type ProxyMode } from './client/endpoint-selector';
|
|
9
9
|
export { ConnectionError, AuthenticationError, TransportError, KeepaliveTimeoutError, AuthRejectedError, MaxRetriesExceededError, ProvisioningTimeoutError, AppStartupFailedError, SpaceNotFoundError, AccessDeniedError, ServerFullError, SessionNotFoundError, ServerUnavailableError, BrowserNotSupportedError } from './errors';
|
|
10
10
|
export { checkBrowserSupport, type BrowserSupportResult } from './utils/browser-support';
|
|
11
11
|
export { Opcode, EntrypointType, UserType, ClientType, ContextType } from '../shared/protocol/src/index.ts';
|
|
@@ -20,7 +20,7 @@ export { abortSignalTimeout, abortSignalAny } from './utils/abort-signal';
|
|
|
20
20
|
export { createPkceChallenge, takePkceVerifier, restorePkceVerifier, isPkceSupported } from './utils/pkce';
|
|
21
21
|
export { isEmbedded, startEmbeddedOAuthSignIn, adoptPkceVerifierFromUrl, onEmbeddedOAuthResult, PKCE_URL_PARAM, type EmbeddedOAuthResult } from './utils/embedded-oauth';
|
|
22
22
|
export { initializeInspectMode, isInspectModeEnabled, enableInspectMode, IKON_INSPECT_MODE_CHANGED_EVENT } from './utils/inspect-mode';
|
|
23
|
-
export { getLangParam, getProxyParam, getWebSocketParam, getWebTransportParam, getDebugParam, getServerUrlParam, getConnectParam, getAudioParam, getVideoParam, getWebRtcParam, getInspectParam, getDebugOverlayParam, getAuthSameOriginParam, getRetryParam, setSdkUrlParam, IKON_PARAM_PROXY, IKON_PARAM_WEBSOCKET, IKON_PARAM_WEBTRANSPORT, IKON_PARAM_DEBUG, IKON_PARAM_LANG, IKON_PARAM_SERVER_URL, IKON_PARAM_CONNECT, IKON_PARAM_AUDIO, IKON_PARAM_VIDEO, IKON_PARAM_WEBRTC, IKON_PARAM_INSPECT, IKON_PARAM_DEBUG_OVERLAY, IKON_PARAM_AUTH, IKON_PARAM_RETRY } from './utils/query-params';
|
|
23
|
+
export { getLangParam, getProxyParam, getProxyTierParam, getWebSocketParam, getWebTransportParam, getDebugParam, getServerUrlParam, getConnectParam, getAudioParam, getVideoParam, getWebRtcParam, getInspectParam, getDebugOverlayParam, getAuthSameOriginParam, getRetryParam, setSdkUrlParam, IKON_PARAM_PROXY, IKON_PARAM_WEBSOCKET, IKON_PARAM_WEBTRANSPORT, IKON_PARAM_DEBUG, IKON_PARAM_LANG, IKON_PARAM_SERVER_URL, IKON_PARAM_CONNECT, IKON_PARAM_AUDIO, IKON_PARAM_VIDEO, IKON_PARAM_WEBRTC, IKON_PARAM_INSPECT, IKON_PARAM_DEBUG_OVERLAY, IKON_PARAM_AUTH, IKON_PARAM_RETRY } from './utils/query-params';
|
|
24
24
|
export { getOpcodeName } from './utils/opcode-names';
|
|
25
25
|
export { initializeLogSink, setSendLogsCallback, getBufferedLogs, takeBufferedLogs, flushLogs, clearLogBuffer, getLogBufferSize } from './utils/log-sink';
|
|
26
26
|
export type { LogSinkConfig } from './utils/log-sink';
|