@omnikit-ai/sdk 2.0.10 → 2.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/dist/index.d.mts +328 -6
- package/dist/index.d.ts +328 -6
- package/dist/index.js +377 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +374 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
export { cleanTokenFromUrl, getAccessToken, isTokenInUrl, removeAccessToken, saveAccessToken, setAccessToken } from './auth-utils.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Omnikit SDK - Connectors Module
|
|
5
|
+
*
|
|
6
|
+
* Provides access to connected external services (Slack, Google Calendar, Notion, etc.)
|
|
7
|
+
* Like Base44's connectors module - allows backend functions to get access tokens
|
|
8
|
+
* for making direct API calls to external services.
|
|
9
|
+
*
|
|
10
|
+
* SECURITY: getAccessToken requires service token authentication.
|
|
11
|
+
* Only available to backend functions, not frontend code.
|
|
12
|
+
*/
|
|
13
|
+
type ConnectorType = 'slack' | 'google_calendar' | 'notion' | 'salesforce';
|
|
14
|
+
interface ConnectorAccessTokenResponse {
|
|
15
|
+
success: boolean;
|
|
16
|
+
access_token: string;
|
|
17
|
+
connector_type: string;
|
|
18
|
+
external_workspace_id?: string;
|
|
19
|
+
external_workspace_name?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ConnectorStatusResponse {
|
|
22
|
+
success: boolean;
|
|
23
|
+
connector?: {
|
|
24
|
+
connector_type: string;
|
|
25
|
+
status: string;
|
|
26
|
+
external_workspace_id?: string;
|
|
27
|
+
external_workspace_name?: string;
|
|
28
|
+
external_user_email?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
interface ConnectorsModule$1 {
|
|
32
|
+
/**
|
|
33
|
+
* Get access token for a connector.
|
|
34
|
+
*
|
|
35
|
+
* SECURITY: Requires service token authentication.
|
|
36
|
+
* Only available in backend functions, not frontend code.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // In a backend function
|
|
41
|
+
* const { access_token } = await omnikit.connectors.getAccessToken('slack');
|
|
42
|
+
*
|
|
43
|
+
* // Make direct Slack API call
|
|
44
|
+
* const response = await fetch('https://slack.com/api/chat.postMessage', {
|
|
45
|
+
* method: 'POST',
|
|
46
|
+
* headers: {
|
|
47
|
+
* 'Authorization': `Bearer ${access_token}`,
|
|
48
|
+
* 'Content-Type': 'application/json',
|
|
49
|
+
* },
|
|
50
|
+
* body: JSON.stringify({
|
|
51
|
+
* channel: '#general',
|
|
52
|
+
* text: 'Hello from Omnikit!'
|
|
53
|
+
* })
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
getAccessToken(connectorType: ConnectorType): Promise<ConnectorAccessTokenResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Check if a connector is connected.
|
|
60
|
+
*/
|
|
61
|
+
isConnected(connectorType: ConnectorType): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Get connector status and info.
|
|
64
|
+
*/
|
|
65
|
+
getStatus(connectorType: ConnectorType): Promise<ConnectorStatusResponse>;
|
|
66
|
+
}
|
|
67
|
+
|
|
3
68
|
/**
|
|
4
69
|
* Omnikit SDK Type Definitions v2.0
|
|
5
70
|
*/
|
|
@@ -795,6 +860,48 @@ interface AuthModule {
|
|
|
795
860
|
*/
|
|
796
861
|
onUserChange(callback: (user: UserInfo | null) => void): () => void;
|
|
797
862
|
}
|
|
863
|
+
/**
|
|
864
|
+
* Connectors module interface for accessing external service tokens.
|
|
865
|
+
* SECURITY: Only available via client.service for backend functions.
|
|
866
|
+
*/
|
|
867
|
+
interface ConnectorsModule {
|
|
868
|
+
/**
|
|
869
|
+
* Get access token for a connector (e.g., Slack, Google Calendar).
|
|
870
|
+
* SECURITY: Only available in backend functions, not frontend code.
|
|
871
|
+
*
|
|
872
|
+
* @example
|
|
873
|
+
* ```typescript
|
|
874
|
+
* const omnikit = createServerClient(req);
|
|
875
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
876
|
+
*
|
|
877
|
+
* // Make direct Slack API call
|
|
878
|
+
* await fetch('https://slack.com/api/chat.postMessage', {
|
|
879
|
+
* headers: { Authorization: `Bearer ${access_token}` },
|
|
880
|
+
* body: JSON.stringify({ channel: '#general', text: 'Hello!' })
|
|
881
|
+
* });
|
|
882
|
+
* ```
|
|
883
|
+
*/
|
|
884
|
+
getAccessToken(connectorType: string): Promise<{
|
|
885
|
+
success: boolean;
|
|
886
|
+
access_token: string;
|
|
887
|
+
connector_type: string;
|
|
888
|
+
external_workspace_id?: string;
|
|
889
|
+
external_workspace_name?: string;
|
|
890
|
+
}>;
|
|
891
|
+
/** Check if a connector is connected */
|
|
892
|
+
isConnected(connectorType: string): Promise<boolean>;
|
|
893
|
+
/** Get connector status */
|
|
894
|
+
getStatus(connectorType: string): Promise<{
|
|
895
|
+
success: boolean;
|
|
896
|
+
connector?: {
|
|
897
|
+
connector_type: string;
|
|
898
|
+
status: string;
|
|
899
|
+
external_workspace_id?: string;
|
|
900
|
+
external_workspace_name?: string;
|
|
901
|
+
external_user_email?: string;
|
|
902
|
+
};
|
|
903
|
+
}>;
|
|
904
|
+
}
|
|
798
905
|
/**
|
|
799
906
|
* Service role client interface (elevated admin operations)
|
|
800
907
|
* Available when serviceToken is provided in config
|
|
@@ -808,6 +915,17 @@ interface ServiceRoleClient {
|
|
|
808
915
|
services: Record<string, IntegrationMethod>;
|
|
809
916
|
/** @deprecated Use services instead. Integration operations with service role privileges */
|
|
810
917
|
integrations: Record<string, Record<string, IntegrationMethod>>;
|
|
918
|
+
/**
|
|
919
|
+
* Connectors module for accessing external service tokens (Slack, Google Calendar, etc.)
|
|
920
|
+
* SECURITY: Only available via client.service for backend functions.
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* ```typescript
|
|
924
|
+
* const omnikit = createServerClient(req);
|
|
925
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
926
|
+
* ```
|
|
927
|
+
*/
|
|
928
|
+
connectors: ConnectorsModule;
|
|
811
929
|
}
|
|
812
930
|
/**
|
|
813
931
|
* Main Omnikit Client interface
|
|
@@ -867,11 +985,36 @@ interface OmnikitClient {
|
|
|
867
985
|
/** Authentication methods */
|
|
868
986
|
auth: AuthModule;
|
|
869
987
|
/**
|
|
870
|
-
* Service
|
|
871
|
-
* Only available when serviceToken is provided
|
|
872
|
-
* Throws error if accessed without serviceToken
|
|
988
|
+
* Service-level operations (elevated privileges).
|
|
989
|
+
* Only available when serviceToken is provided (e.g., via createServerClient).
|
|
990
|
+
* Throws error if accessed without serviceToken.
|
|
991
|
+
*
|
|
992
|
+
* @example
|
|
993
|
+
* ```typescript
|
|
994
|
+
* // In a backend function
|
|
995
|
+
* const omnikit = createServerClient(req);
|
|
996
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
997
|
+
* ```
|
|
998
|
+
*/
|
|
999
|
+
service?: ServiceRoleClient;
|
|
1000
|
+
/**
|
|
1001
|
+
* @deprecated Use service instead. Will be removed in next major version.
|
|
873
1002
|
*/
|
|
874
1003
|
asServiceRole?: ServiceRoleClient;
|
|
1004
|
+
/**
|
|
1005
|
+
* Connectors module for accessing external service tokens.
|
|
1006
|
+
*
|
|
1007
|
+
* SECURITY: getAccessToken requires service token authentication.
|
|
1008
|
+
* Prefer using omnikit.service.connectors in backend functions.
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* ```typescript
|
|
1012
|
+
* // In a backend function (using service role)
|
|
1013
|
+
* const omnikit = createServerClient(req);
|
|
1014
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
1015
|
+
* ```
|
|
1016
|
+
*/
|
|
1017
|
+
connectors: ConnectorsModule;
|
|
875
1018
|
/** @internal */
|
|
876
1019
|
getAppMetadata(): Promise<AppSchema>;
|
|
877
1020
|
/** @internal */
|
|
@@ -1183,6 +1326,7 @@ declare class APIClient implements OmnikitClient {
|
|
|
1183
1326
|
private _integrations;
|
|
1184
1327
|
private _auth;
|
|
1185
1328
|
private _asServiceRole?;
|
|
1329
|
+
private _connectors?;
|
|
1186
1330
|
private _metadata;
|
|
1187
1331
|
private _metadataListeners;
|
|
1188
1332
|
private _userListeners;
|
|
@@ -1269,10 +1413,35 @@ declare class APIClient implements OmnikitClient {
|
|
|
1269
1413
|
*/
|
|
1270
1414
|
get auth(): AuthModule;
|
|
1271
1415
|
/**
|
|
1272
|
-
*
|
|
1273
|
-
* Only available when serviceToken is provided
|
|
1416
|
+
* Service-level operations (elevated privileges).
|
|
1417
|
+
* Only available when serviceToken is provided (e.g., via createServerClient).
|
|
1418
|
+
*/
|
|
1419
|
+
get service(): ServiceRoleClient;
|
|
1420
|
+
/**
|
|
1421
|
+
* @deprecated Use service instead
|
|
1274
1422
|
*/
|
|
1275
1423
|
get asServiceRole(): ServiceRoleClient;
|
|
1424
|
+
/**
|
|
1425
|
+
* Lazy getter for connectors module
|
|
1426
|
+
* Like Base44's connectors - provides access to external service tokens
|
|
1427
|
+
*
|
|
1428
|
+
* SECURITY: getAccessToken requires service token authentication.
|
|
1429
|
+
* Only use in backend functions, not frontend code.
|
|
1430
|
+
*
|
|
1431
|
+
* @example
|
|
1432
|
+
* ```typescript
|
|
1433
|
+
* // In a backend function
|
|
1434
|
+
* const { access_token } = await omnikit.connectors.getAccessToken('slack');
|
|
1435
|
+
*
|
|
1436
|
+
* // Make direct Slack API call
|
|
1437
|
+
* const response = await fetch('https://slack.com/api/chat.postMessage', {
|
|
1438
|
+
* method: 'POST',
|
|
1439
|
+
* headers: { Authorization: `Bearer ${access_token}` },
|
|
1440
|
+
* body: JSON.stringify({ channel: '#general', text: 'Hello!' })
|
|
1441
|
+
* });
|
|
1442
|
+
* ```
|
|
1443
|
+
*/
|
|
1444
|
+
get connectors(): ConnectorsModule$1;
|
|
1276
1445
|
/**
|
|
1277
1446
|
* Create auth proxy that auto-initializes
|
|
1278
1447
|
*/
|
|
@@ -1480,6 +1649,60 @@ declare class APIClient implements OmnikitClient {
|
|
|
1480
1649
|
* ```
|
|
1481
1650
|
*/
|
|
1482
1651
|
declare function createClient(config: OmnikitConfig): OmnikitClient;
|
|
1652
|
+
/**
|
|
1653
|
+
* Request object interface for createServerClient.
|
|
1654
|
+
* Matches Deno/Node HTTP request interface.
|
|
1655
|
+
*/
|
|
1656
|
+
interface ServerRequest {
|
|
1657
|
+
headers: {
|
|
1658
|
+
get?(name: string): string | null;
|
|
1659
|
+
[key: string]: any;
|
|
1660
|
+
};
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* Create an Omnikit client for server-side (backend function) use.
|
|
1664
|
+
*
|
|
1665
|
+
* Extracts authentication tokens from HTTP headers injected by the Omnikit platform:
|
|
1666
|
+
* - Authorization: Bearer <user_jwt> (identifies the user making the request)
|
|
1667
|
+
* - X-Omnikit-Service-Authorization: <service_token> (for privileged operations)
|
|
1668
|
+
* - X-Omnikit-App-Id: <app_id> (identifies the app)
|
|
1669
|
+
* - X-Omnikit-Server-Url: <server_url> (API server URL)
|
|
1670
|
+
*
|
|
1671
|
+
* SECURITY: The service token is injected at runtime by the platform,
|
|
1672
|
+
* ensuring it cannot be leaked through source code.
|
|
1673
|
+
*
|
|
1674
|
+
* @example
|
|
1675
|
+
* ```typescript
|
|
1676
|
+
* // In a backend function (Deno Edge Function)
|
|
1677
|
+
* import { createServerClient } from '@omnikit-ai/sdk';
|
|
1678
|
+
*
|
|
1679
|
+
* Deno.serve(async (req) => {
|
|
1680
|
+
* const omnikit = createServerClient(req);
|
|
1681
|
+
*
|
|
1682
|
+
* // Access user data (user JWT auth)
|
|
1683
|
+
* const currentUser = await omnikit.auth.me();
|
|
1684
|
+
*
|
|
1685
|
+
* // Access connectors (requires service token)
|
|
1686
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
1687
|
+
*
|
|
1688
|
+
* // Make direct Slack API call
|
|
1689
|
+
* await fetch('https://slack.com/api/chat.postMessage', {
|
|
1690
|
+
* headers: { Authorization: `Bearer ${access_token}` },
|
|
1691
|
+
* body: JSON.stringify({ channel: '#general', text: `Hello from ${currentUser.email}!` })
|
|
1692
|
+
* });
|
|
1693
|
+
*
|
|
1694
|
+
* return new Response(JSON.stringify({ success: true }));
|
|
1695
|
+
* });
|
|
1696
|
+
* ```
|
|
1697
|
+
*
|
|
1698
|
+
* @param request - HTTP request object with headers
|
|
1699
|
+
* @returns Omnikit client configured with tokens from headers
|
|
1700
|
+
*/
|
|
1701
|
+
declare function createServerClient(request: ServerRequest): OmnikitClient;
|
|
1702
|
+
/**
|
|
1703
|
+
* @deprecated Use createServerClient instead
|
|
1704
|
+
*/
|
|
1705
|
+
declare const createClientFromRequest: typeof createServerClient;
|
|
1483
1706
|
|
|
1484
1707
|
/**
|
|
1485
1708
|
* Live Voice Session Implementation
|
|
@@ -1561,4 +1784,103 @@ declare class LiveVoiceSessionImpl implements LiveVoiceSession {
|
|
|
1561
1784
|
private cleanup;
|
|
1562
1785
|
}
|
|
1563
1786
|
|
|
1564
|
-
|
|
1787
|
+
/**
|
|
1788
|
+
* Omnikit Analytics Module
|
|
1789
|
+
*
|
|
1790
|
+
* Provides automatic event tracking for generated apps.
|
|
1791
|
+
* Supports page views, errors, auth events, and custom events.
|
|
1792
|
+
*
|
|
1793
|
+
* @example
|
|
1794
|
+
* ```typescript
|
|
1795
|
+
* import { Analytics } from '@omnikit/sdk';
|
|
1796
|
+
*
|
|
1797
|
+
* const analytics = new Analytics({
|
|
1798
|
+
* appId: 'your-app-id',
|
|
1799
|
+
* apiUrl: 'https://api.omnikit.ai'
|
|
1800
|
+
* });
|
|
1801
|
+
*
|
|
1802
|
+
* // Log events
|
|
1803
|
+
* analytics.logPageView('/dashboard');
|
|
1804
|
+
* analytics.logEvent('button_click', { action: 'submit' });
|
|
1805
|
+
* ```
|
|
1806
|
+
*/
|
|
1807
|
+
interface EventPayload {
|
|
1808
|
+
page_name?: string;
|
|
1809
|
+
action?: string;
|
|
1810
|
+
inputs?: Record<string, any>;
|
|
1811
|
+
metadata?: Record<string, any>;
|
|
1812
|
+
error_message?: string;
|
|
1813
|
+
error_stack?: string;
|
|
1814
|
+
}
|
|
1815
|
+
interface AnalyticsConfig {
|
|
1816
|
+
appId: string;
|
|
1817
|
+
apiUrl: string;
|
|
1818
|
+
sessionId?: string;
|
|
1819
|
+
userId?: string;
|
|
1820
|
+
enabled?: boolean;
|
|
1821
|
+
}
|
|
1822
|
+
declare class Analytics {
|
|
1823
|
+
private config;
|
|
1824
|
+
private sessionId;
|
|
1825
|
+
private userId?;
|
|
1826
|
+
private eventQueue;
|
|
1827
|
+
private flushTimer?;
|
|
1828
|
+
private enabled;
|
|
1829
|
+
constructor(config: AnalyticsConfig);
|
|
1830
|
+
private initSession;
|
|
1831
|
+
private generateId;
|
|
1832
|
+
private saveSession;
|
|
1833
|
+
/**
|
|
1834
|
+
* Get the current session ID
|
|
1835
|
+
*/
|
|
1836
|
+
getSessionId(): string;
|
|
1837
|
+
/**
|
|
1838
|
+
* Start a new session (e.g., after logout)
|
|
1839
|
+
*/
|
|
1840
|
+
startNewSession(): string;
|
|
1841
|
+
/**
|
|
1842
|
+
* Associate events with a user ID
|
|
1843
|
+
*/
|
|
1844
|
+
setUserId(userId: string): void;
|
|
1845
|
+
/**
|
|
1846
|
+
* Clear user association (e.g., on logout)
|
|
1847
|
+
*/
|
|
1848
|
+
clearUserId(): void;
|
|
1849
|
+
/**
|
|
1850
|
+
* Log a custom event
|
|
1851
|
+
*/
|
|
1852
|
+
logEvent(eventType: string, payload?: EventPayload): Promise<void>;
|
|
1853
|
+
/**
|
|
1854
|
+
* Log a page view event
|
|
1855
|
+
*/
|
|
1856
|
+
logPageView(pageName: string, metadata?: Record<string, any>): Promise<void>;
|
|
1857
|
+
/**
|
|
1858
|
+
* Log an error event
|
|
1859
|
+
*/
|
|
1860
|
+
logError(error: Error, componentStack?: string): Promise<void>;
|
|
1861
|
+
/**
|
|
1862
|
+
* Log an API error event
|
|
1863
|
+
*/
|
|
1864
|
+
logApiError(endpoint: string, statusCode: number, errorMessage: string, metadata?: Record<string, any>): Promise<void>;
|
|
1865
|
+
private startFlushTimer;
|
|
1866
|
+
/**
|
|
1867
|
+
* Flush all queued events to the server
|
|
1868
|
+
*/
|
|
1869
|
+
flush(): Promise<void>;
|
|
1870
|
+
private sendEvent;
|
|
1871
|
+
/**
|
|
1872
|
+
* Enable or disable analytics
|
|
1873
|
+
*/
|
|
1874
|
+
setEnabled(enabled: boolean): void;
|
|
1875
|
+
/**
|
|
1876
|
+
* Check if analytics is enabled
|
|
1877
|
+
*/
|
|
1878
|
+
isEnabled(): boolean;
|
|
1879
|
+
/**
|
|
1880
|
+
* Clean up resources
|
|
1881
|
+
*/
|
|
1882
|
+
destroy(): void;
|
|
1883
|
+
}
|
|
1884
|
+
declare function createAnalytics(config: AnalyticsConfig): Analytics;
|
|
1885
|
+
|
|
1886
|
+
export { APIClient, Analytics, type AnalyticsConfig, type AppMetadata, type AppSchema, type AsyncJobCreatedResponse, type AsyncJobStatus, type AsyncJobStatusResponse, type AsyncJobType, type AsyncOptions, type AuthModule, type AuthResponse, type BuiltInIntegration, type BulkResult, type CachedMetadata, type CheckJobStatusParams, type CollectionClass, type CollectionDefinition, type CollectionField, type CollectionRecord, type ConnectorAccessTokenResponse, type ConnectorStatusResponse, type ConnectorType, type ConnectorsModule, type EmailParams, type Entity, type EntityClass, type EntityDefinition, type EntityField, type EntityRecord, type EventPayload, type ExtractParams, type ImageParams, type ImportResult, type InitialMetadata, type IntegrationEndpoint, type IntegrationMethod, type IntegrationPackage, type IntegrationSchema, type LLMMessage, type LLMModel, type LLMParams, type LLMStreamEvent, type LLMStreamResult, type ListOptions, type LiveVoiceClientMessage, type LiveVoiceConfig, type LiveVoiceServerMessage, type LiveVoiceSession, LiveVoiceSessionImpl, type LiveVoiceStatus, type LiveVoiceVoice, type OAuthProvider, type OAuthProvidersResponse, type OmnikitClient, type OmnikitConfig, OmnikitError, type QueryOptions, type RequestOptions, type SMSParams, type ServiceDefinition, type ServiceResponse, type ServiceRoleClient, type ServicesSchema, type SpeechParams, type TemplateDefinition, type UserCollectionClass, type UserEntityClass, type UserInfo, type VideoParams, type VideoStatusParams, createAnalytics, createClient, createClientFromRequest, createServerClient };
|