@ikonai/sdk 0.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.
@@ -0,0 +1,53 @@
1
+ import { AuthResponse } from '../../../platform-generated/src/index.ts';
2
+ import { ApiKeyConfig, BrowserConfig, LocalConfig } from '../client/ikon-client-config';
3
+ /**
4
+ * Result of authentication - contains the AuthResponse from the server.
5
+ */
6
+ export interface AuthResult {
7
+ authResponse: AuthResponse;
8
+ }
9
+ /**
10
+ * Derive backend API URL from window.location.hostname.
11
+ * - If hostname contains '.dev.' → https://api.dev.ikon.live
12
+ * - Otherwise → https://api.prod.ikon.live
13
+ */
14
+ export declare function deriveBackendUrl(): string;
15
+ /**
16
+ * Extract space domain from hostname.
17
+ * - First checks VITE_IKON_SPACE_DOMAIN env variable (via import.meta.env)
18
+ * - Otherwise extracts first subdomain: myapp.dev.ikon.live → myapp
19
+ */
20
+ export declare function deriveSpaceDomain(): string;
21
+ /**
22
+ * Authenticate with a local Ikon server in development mode.
23
+ *
24
+ * Flow:
25
+ * 1. POST /connect-token with ConnectToken data → get JWT token
26
+ * 2. GET /connect?token=jwt → get binary AuthResponse
27
+ */
28
+ export declare function authenticateLocal(config: LocalConfig, signal?: AbortSignal): Promise<AuthResult>;
29
+ /**
30
+ * Authenticate with the Ikon backend using browser session cookies.
31
+ *
32
+ * Flow:
33
+ * 1. Derive backend URL and space domain from hostname
34
+ * 2. Fetch space info by domain
35
+ * 3. Fetch channels for space
36
+ * 4. Select channel (by channelKey or first available)
37
+ * 5. POST /rooms/connect and poll until running
38
+ * 6. Connect to the returned Ikon server URL
39
+ */
40
+ export declare function authenticateBrowser(config: BrowserConfig, signal?: AbortSignal): Promise<AuthResult>;
41
+ /**
42
+ * Authenticate with the Ikon backend using an API key.
43
+ *
44
+ * Flow:
45
+ * 1. POST /auth/api-key with { space, apiKey, user } → get JWT token
46
+ * 2. Use token as Bearer auth for backend requests
47
+ * 3. GET /profiles/me?space={spaceId} to create user profile
48
+ * 4. Fetch channels for space
49
+ * 5. Select channel (by channelKey or first available)
50
+ * 6. POST /rooms/connect and poll until running
51
+ * 7. Connect to the returned Ikon server URL
52
+ */
53
+ export declare function authenticateApiKey(config: ApiKeyConfig, signal?: AbortSignal): Promise<AuthResult>;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Base class for all SDK connection-related errors.
3
+ */
4
+ export declare class ConnectionError extends Error {
5
+ readonly cause?: Error | undefined;
6
+ constructor(message: string, cause?: Error | undefined);
7
+ }
8
+ /**
9
+ * Error thrown when authentication fails.
10
+ * This includes /connect-token failures, /connect failures, or invalid responses.
11
+ */
12
+ export declare class AuthenticationError extends ConnectionError {
13
+ constructor(message: string, cause?: Error);
14
+ }
15
+ /**
16
+ * Error thrown when transport-level operations fail.
17
+ * This includes WebSocket connection failures and protocol errors.
18
+ */
19
+ export declare class TransportError extends ConnectionError {
20
+ constructor(message: string, cause?: Error);
21
+ }
22
+ /**
23
+ * Error thrown when no keepalive is received within the timeout period.
24
+ */
25
+ export declare class KeepaliveTimeoutError extends TransportError {
26
+ constructor(timeoutMs: number);
27
+ }
28
+ /**
29
+ * Error thrown when maximum reconnection attempts are exhausted.
30
+ */
31
+ export declare class MaxRetriesExceededError extends ConnectionError {
32
+ constructor(maxAttempts: number);
33
+ }
34
+ /**
35
+ * Error thrown when cloud channel provisioning times out.
36
+ */
37
+ export declare class ProvisioningTimeoutError extends AuthenticationError {
38
+ constructor(timeoutMs: number);
39
+ }
40
+ /**
41
+ * Error thrown when a channel with the specified key is not found.
42
+ */
43
+ export declare class ChannelNotFoundError extends AuthenticationError {
44
+ constructor(channelKey: string);
45
+ }
46
+ /**
47
+ * Error thrown when no space is found for the given domain.
48
+ */
49
+ export declare class SpaceNotFoundError extends AuthenticationError {
50
+ constructor(domain: string);
51
+ }
52
+ /**
53
+ * Error thrown when no channels are available in the space.
54
+ */
55
+ export declare class NoChannelsError extends AuthenticationError {
56
+ constructor();
57
+ }
package/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export { IkonClient, type ProtocolMessageHandler, type StateHandler } from './client/ikon-client';
2
+ export type { IkonClientConfig, LocalConfig, BrowserConfig, ApiKeyConfig, CloudConnectionConfig, CommonConnectionConfig, TimeoutConfig, BackendType } from './client/ikon-client-config';
3
+ export type { ConnectionState } from './client/connection-state';
4
+ export { isConnecting, isConnected, isOffline, isError } from './client/connection-state';
5
+ export { ChannelManager, type ChannelManagerConfig, type ChannelManagerState } from './channel/channel-manager';
6
+ export { Channel, type ChannelConfig, type ChannelState } from './channel/channel';
7
+ export { EndpointSelector } from './client/endpoint-selector';
8
+ export { ConnectionError, AuthenticationError, TransportError, KeepaliveTimeoutError, MaxRetriesExceededError, ProvisioningTimeoutError, ChannelNotFoundError, SpaceNotFoundError, NoChannelsError, } from './errors';
9
+ export { Opcode, EntrypointType, ClientReady, UserType, ClientType, ContextType } from '../../platform-generated/src/index.ts';
10
+ export type { ProtocolMessage, ProtocolMessageHeaders } from '../../platform-generated/src/index.ts';
11
+ export { teleportReadOpcode as readOpcode, teleportReadOpcodeGroup as readOpcodeGroup, asProtocolMessage, readProtocolMessageHeaders } from '../../platform-generated/src/index.ts';
12
+ export { isWebTransportSupported } from './transport/web-transport-transport';
13
+ export { setLogLevel, setLogSink, getLogLevel, getLogSink, createLogger, LogLevel } from './utils/logger';
14
+ export type { LogEntry, LogSink, Logger } from './utils/logger';
15
+ export { initializeLogSink, setSendLogsCallback, getBufferedLogs, takeBufferedLogs, flushLogs, clearLogBuffer, getLogBufferSize } from './utils/logSink';
16
+ export type { LogSinkConfig } from './utils/logSink';