@ikonai/sdk 0.0.7 → 0.0.9
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/ikon-client-config.d.ts +8 -0
- package/client/ikon-client.d.ts +13 -2
- package/connection/authenticator.d.ts +6 -8
- package/functions/browser-functions.d.ts +10 -0
- package/functions/function-registry.d.ts +75 -0
- package/functions/index.d.ts +3 -0
- package/functions/type-conversion.d.ts +7 -0
- package/functions/types.d.ts +61 -0
- package/index.d.ts +2 -0
- package/index.js +4171 -3431
- package/package.json +1 -1
- package/transport/web-transport-transport.d.ts +14 -0
|
@@ -217,6 +217,14 @@ export interface IkonClientConfig {
|
|
|
217
217
|
* Can be async (return a Promise).
|
|
218
218
|
*/
|
|
219
219
|
onReady?: () => void | Promise<void>;
|
|
220
|
+
/**
|
|
221
|
+
* Disable auto-registration of browser convenience functions.
|
|
222
|
+
* By default, functions like getTheme, setTheme, getLocation, etc. are
|
|
223
|
+
* automatically registered when running in a browser environment.
|
|
224
|
+
* Set to true to disable this behavior.
|
|
225
|
+
* Default: false
|
|
226
|
+
*/
|
|
227
|
+
disableBrowserFunctions?: boolean;
|
|
220
228
|
}
|
|
221
229
|
export declare const DEFAULT_SLOW_CONNECTION_THRESHOLD_MS = 5000;
|
|
222
230
|
export declare const DEFAULT_CONNECTION_TIMEOUT_MS = 30000;
|
package/client/ikon-client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GlobalState, ProtocolMessage } from '../../../../shared/generated/src/index.ts';
|
|
2
|
+
import { FunctionRegistry } from '../functions/function-registry';
|
|
2
3
|
import { ConnectionState } from './connection-state';
|
|
3
4
|
import { IkonClientConfig } from './ikon-client-config';
|
|
4
5
|
/**
|
|
@@ -54,6 +55,8 @@ export declare class IkonClient {
|
|
|
54
55
|
private boundVisibilityChange;
|
|
55
56
|
private _globalState;
|
|
56
57
|
private _initialGlobalStateReceived;
|
|
58
|
+
private readonly _functionRegistry;
|
|
59
|
+
private unregisterBrowserFunctions;
|
|
57
60
|
constructor(config: IkonClientConfig);
|
|
58
61
|
private _lastError;
|
|
59
62
|
/**
|
|
@@ -76,6 +79,10 @@ export declare class IkonClient {
|
|
|
76
79
|
* Get the current connection state.
|
|
77
80
|
*/
|
|
78
81
|
get connectionState(): ConnectionState;
|
|
82
|
+
/**
|
|
83
|
+
* Get the function registry for registering custom functions.
|
|
84
|
+
*/
|
|
85
|
+
get functionRegistry(): FunctionRegistry;
|
|
79
86
|
/**
|
|
80
87
|
* Connect to the Ikon server.
|
|
81
88
|
* Returns when connected or throws if connection fails.
|
|
@@ -110,6 +117,10 @@ export declare class IkonClient {
|
|
|
110
117
|
* Handle incoming protocol message from channel manager.
|
|
111
118
|
*/
|
|
112
119
|
private handleProtocolMessage;
|
|
120
|
+
/**
|
|
121
|
+
* Notify config callback and message subscribers.
|
|
122
|
+
*/
|
|
123
|
+
private notifyMessageSubscribers;
|
|
113
124
|
/**
|
|
114
125
|
* Handle channel manager state changes.
|
|
115
126
|
*/
|
|
@@ -151,12 +162,12 @@ export declare class IkonClient {
|
|
|
151
162
|
*/
|
|
152
163
|
private handleVisibilityChange;
|
|
153
164
|
/**
|
|
154
|
-
* Check if the connection is still healthy after
|
|
165
|
+
* Check if the connection is still healthy after page was backgrounded.
|
|
155
166
|
* If connection died while backgrounded, trigger reconnection.
|
|
156
167
|
*/
|
|
157
168
|
private checkConnectionHealth;
|
|
158
169
|
/**
|
|
159
|
-
* Handle connection ready - call user's onReady callback, then send ClientReady.
|
|
170
|
+
* Handle connection ready - attach function registry, call user's onReady callback, then send ClientReady.
|
|
160
171
|
* Called on every connect (including reconnects).
|
|
161
172
|
*/
|
|
162
173
|
private handleReady;
|
|
@@ -33,10 +33,9 @@ export declare function authenticateLocal(config: LocalConfig, signal?: AbortSig
|
|
|
33
33
|
* 1. Parse URL query parameters (id → sessionId, ck → channelKey, all → parameters)
|
|
34
34
|
* 2. Derive backend URL and space domain from hostname
|
|
35
35
|
* 3. Fetch space info by domain
|
|
36
|
-
* 4.
|
|
37
|
-
* 5.
|
|
38
|
-
* 6.
|
|
39
|
-
* 7. Connect to the returned Ikon server URL
|
|
36
|
+
* 4. Request channel
|
|
37
|
+
* 5. POST /rooms/connect and poll until running
|
|
38
|
+
* 6. Connect to the returned Ikon server URL
|
|
40
39
|
*/
|
|
41
40
|
export declare function authenticateBrowser(config: BrowserConfig, signal?: AbortSignal): Promise<AuthResult>;
|
|
42
41
|
/**
|
|
@@ -46,9 +45,8 @@ export declare function authenticateBrowser(config: BrowserConfig, signal?: Abor
|
|
|
46
45
|
* 1. POST /auth/api-key with { space, apiKey, user } → get JWT token
|
|
47
46
|
* 2. Use token as Bearer auth for backend requests
|
|
48
47
|
* 3. GET /profiles/me?space={spaceId} to create user profile
|
|
49
|
-
* 4.
|
|
50
|
-
* 5.
|
|
51
|
-
* 6.
|
|
52
|
-
* 7. Connect to the returned Ikon server URL
|
|
48
|
+
* 4. Request channel
|
|
49
|
+
* 5. POST /rooms/connect and poll until running
|
|
50
|
+
* 6. Connect to the returned Ikon server URL
|
|
53
51
|
*/
|
|
54
52
|
export declare function authenticateApiKey(config: ApiKeyConfig, signal?: AbortSignal): Promise<AuthResult>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FunctionRegistry } from './function-registry';
|
|
2
|
+
/**
|
|
3
|
+
* Register all browser convenience functions with a registry.
|
|
4
|
+
* Returns an unregister function that removes all browser functions.
|
|
5
|
+
*/
|
|
6
|
+
export declare function registerBrowserFunctions(registry: FunctionRegistry): () => void;
|
|
7
|
+
/**
|
|
8
|
+
* Check if browser environment is available.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isBrowserEnvironment(): boolean;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ProtocolMessage } from '../../../../shared/generated/src/index.ts';
|
|
2
|
+
import { FunctionDefinition, FunctionHandler, NormalizedFunction } from './types';
|
|
3
|
+
export interface FunctionRegistryConfig {
|
|
4
|
+
sendProtocolMessage: (message: ProtocolMessage) => void;
|
|
5
|
+
sessionId: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class FunctionRegistry {
|
|
8
|
+
private readonly functions;
|
|
9
|
+
private config;
|
|
10
|
+
private isConnected;
|
|
11
|
+
/**
|
|
12
|
+
* Attach the registry to a connected IkonClient.
|
|
13
|
+
* Called internally by IkonClient when connection is established.
|
|
14
|
+
*/
|
|
15
|
+
attach(config: FunctionRegistryConfig): void;
|
|
16
|
+
/**
|
|
17
|
+
* Detach from the client (on disconnect).
|
|
18
|
+
*/
|
|
19
|
+
detach(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Register a function with the registry.
|
|
22
|
+
* If already connected, sends registration to server immediately.
|
|
23
|
+
*/
|
|
24
|
+
register(definition: FunctionDefinition, handler: FunctionHandler): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Unregister a function by name.
|
|
27
|
+
*/
|
|
28
|
+
unregister(name: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a function is registered.
|
|
31
|
+
*/
|
|
32
|
+
has(name: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Get a registered function (for testing/inspection).
|
|
35
|
+
*/
|
|
36
|
+
get(name: string): NormalizedFunction | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Get the number of registered functions.
|
|
39
|
+
*/
|
|
40
|
+
get size(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Handle incoming protocol message.
|
|
43
|
+
* Returns true if the message was handled.
|
|
44
|
+
*/
|
|
45
|
+
handleProtocolMessage(message: ProtocolMessage, opcode: number): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Send registrations for all functions.
|
|
48
|
+
* Called when connection is established or re-established.
|
|
49
|
+
*/
|
|
50
|
+
private sendAllRegistrations;
|
|
51
|
+
/**
|
|
52
|
+
* Send a single function registration.
|
|
53
|
+
*/
|
|
54
|
+
private sendRegistration;
|
|
55
|
+
/**
|
|
56
|
+
* Handle an incoming function call.
|
|
57
|
+
*/
|
|
58
|
+
private handleFunctionCall;
|
|
59
|
+
/**
|
|
60
|
+
* Execute a function and send the result.
|
|
61
|
+
*/
|
|
62
|
+
private executeFunction;
|
|
63
|
+
/**
|
|
64
|
+
* Send ACK for a function call.
|
|
65
|
+
*/
|
|
66
|
+
private sendAck;
|
|
67
|
+
/**
|
|
68
|
+
* Send function result.
|
|
69
|
+
*/
|
|
70
|
+
private sendResult;
|
|
71
|
+
/**
|
|
72
|
+
* Send function error.
|
|
73
|
+
*/
|
|
74
|
+
private sendError;
|
|
75
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { ValueDescriptor, NormalizedValueDescriptor, PrimitiveValueKind, FunctionParameterDefinition, FunctionDefinition, FunctionHandler, } from './types';
|
|
2
|
+
export { FunctionRegistry, type FunctionRegistryConfig } from './function-registry';
|
|
3
|
+
export { registerBrowserFunctions, isBrowserEnvironment } from './browser-functions';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FunctionDefinition, FunctionHandler, NormalizedFunction, NormalizedValueDescriptor, ValueDescriptor } from './types';
|
|
2
|
+
export declare function normalizeDescriptor(descriptor: ValueDescriptor): NormalizedValueDescriptor;
|
|
3
|
+
export declare function descriptorToTypeName(descriptor: NormalizedValueDescriptor): string;
|
|
4
|
+
export declare function convertParameterFromJson(json: string | undefined, descriptor: NormalizedValueDescriptor): unknown;
|
|
5
|
+
export declare function convertValueToJson(value: unknown, descriptor: NormalizedValueDescriptor): string;
|
|
6
|
+
export declare function getDefaultValue(descriptor: NormalizedValueDescriptor): unknown;
|
|
7
|
+
export declare function normalizeFunction(definition: FunctionDefinition, handler: FunctionHandler): NormalizedFunction;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ActionFunctionRegister } from '../../../../shared/generated/src/index.ts';
|
|
2
|
+
export type PrimitiveValueKind = 'boolean' | 'number' | 'string';
|
|
3
|
+
type PrimitiveDescriptor = {
|
|
4
|
+
kind: PrimitiveValueKind;
|
|
5
|
+
nullable?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type ArrayDescriptor = {
|
|
8
|
+
kind: 'array';
|
|
9
|
+
element: ValueDescriptor;
|
|
10
|
+
nullable?: boolean;
|
|
11
|
+
};
|
|
12
|
+
type DictionaryDescriptor = {
|
|
13
|
+
kind: 'dictionary';
|
|
14
|
+
keyType?: 'string' | 'int';
|
|
15
|
+
value: ValueDescriptor;
|
|
16
|
+
nullable?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type ValueDescriptor = PrimitiveDescriptor | ArrayDescriptor | DictionaryDescriptor;
|
|
19
|
+
export type NormalizedValueDescriptor = {
|
|
20
|
+
kind: PrimitiveValueKind;
|
|
21
|
+
nullable: boolean;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'array';
|
|
24
|
+
element: NormalizedValueDescriptor;
|
|
25
|
+
nullable: boolean;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'dictionary';
|
|
28
|
+
keyType: 'string' | 'int';
|
|
29
|
+
value: NormalizedValueDescriptor;
|
|
30
|
+
nullable: boolean;
|
|
31
|
+
};
|
|
32
|
+
export interface FunctionParameterDefinition {
|
|
33
|
+
name: string;
|
|
34
|
+
type: ValueDescriptor;
|
|
35
|
+
defaultValue?: unknown;
|
|
36
|
+
description?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface FunctionDefinition {
|
|
39
|
+
name: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
inlineCall?: boolean;
|
|
42
|
+
callOnlyOnce?: boolean;
|
|
43
|
+
returnType: ValueDescriptor;
|
|
44
|
+
parameters?: FunctionParameterDefinition[];
|
|
45
|
+
}
|
|
46
|
+
export type FunctionHandler = (...parameters: unknown[]) => unknown | Promise<unknown>;
|
|
47
|
+
export interface NormalizedFunctionParameter {
|
|
48
|
+
name: string;
|
|
49
|
+
descriptor: NormalizedValueDescriptor;
|
|
50
|
+
hasDefaultValue: boolean;
|
|
51
|
+
defaultValueJson: string;
|
|
52
|
+
description?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface NormalizedFunction {
|
|
55
|
+
definition: FunctionDefinition;
|
|
56
|
+
handler: FunctionHandler;
|
|
57
|
+
registerPayload: ActionFunctionRegister;
|
|
58
|
+
parameters: NormalizedFunctionParameter[];
|
|
59
|
+
returnType: NormalizedValueDescriptor;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
package/index.d.ts
CHANGED
|
@@ -14,3 +14,5 @@ export { setLogLevel, setLogSink, getLogLevel, getLogSink, createLogger, LogLeve
|
|
|
14
14
|
export type { LogEntry, LogSink, Logger } from './utils/logger';
|
|
15
15
|
export { initializeLogSink, setSendLogsCallback, getBufferedLogs, takeBufferedLogs, flushLogs, clearLogBuffer, getLogBufferSize } from './utils/logSink';
|
|
16
16
|
export type { LogSinkConfig } from './utils/logSink';
|
|
17
|
+
export { FunctionRegistry, registerBrowserFunctions, isBrowserEnvironment, type FunctionRegistryConfig } from './functions';
|
|
18
|
+
export type { ValueDescriptor, NormalizedValueDescriptor, PrimitiveValueKind, FunctionParameterDefinition, FunctionDefinition, FunctionHandler } from './functions';
|