@omnikit-ai/sdk 2.2.4 → 2.2.6

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 CHANGED
@@ -7,7 +7,7 @@ export { cleanTokenFromUrl, getAccessToken, isTokenInUrl, removeAccessToken, sav
7
7
  * Like Base44's connectors module - allows backend functions to get access tokens
8
8
  * for making direct API calls to external services.
9
9
  *
10
- * SECURITY: getAccessToken requires service token authentication.
10
+ * SECURITY: getAccessToken requires API key (X-API-Key) authentication.
11
11
  * Only available to backend functions, not frontend code.
12
12
  */
13
13
  type ConnectorType = 'slack' | 'google_calendar' | 'gmail' | 'google_sheets' | 'notion' | 'salesforce';
@@ -32,7 +32,7 @@ interface ConnectorsModule$1 {
32
32
  /**
33
33
  * Get access token for a connector.
34
34
  *
35
- * SECURITY: Requires service token authentication.
35
+ * SECURITY: Requires API key (X-API-Key) authentication.
36
36
  * Only available in backend functions, not frontend code.
37
37
  *
38
38
  * @example
@@ -98,17 +98,16 @@ interface OmnikitConfig {
98
98
  * If not provided, will auto-detect from URL or localStorage
99
99
  */
100
100
  token?: string;
101
- /**
102
- * Service role token for elevated admin operations (optional)
103
- * When provided, enables asServiceRole operations
104
- */
105
- serviceToken?: string;
106
101
  /**
107
102
  * API key for server-to-server authentication (optional)
108
- * Used in backend functions (Deno Edge Functions) where user auth isn't needed.
109
- * Takes precedence over serviceToken if both are provided.
103
+ * Used in backend functions (Deno Edge Functions) for privileged operations.
104
+ * When provided, enables service role operations via omnikit.service
110
105
  */
111
106
  apiKey?: string;
107
+ /**
108
+ * @deprecated Use apiKey instead. serviceToken is an alias for backwards compatibility.
109
+ */
110
+ serviceToken?: string;
112
111
  /**
113
112
  * Auto-detect and load token from URL params or localStorage
114
113
  * @default true
@@ -1013,9 +1012,44 @@ type UserEntityClass<T = UserInfo> = UserCollectionClass<T>;
1013
1012
  */
1014
1013
  type IntegrationMethod = (params?: Record<string, any>, useServiceToken?: boolean) => Promise<any>;
1015
1014
  /**
1016
- * BuiltIn integration methods
1015
+ * BuiltIn integration methods.
1016
+ * Supports both camelCase (industry standard) and PascalCase (legacy).
1017
+ * camelCase is recommended for new code.
1017
1018
  */
1018
1019
  interface BuiltInIntegration {
1020
+ sendEmail(params: EmailParams): Promise<ServiceResponse>;
1021
+ sendSMS(params: SMSParams): Promise<ServiceResponse>;
1022
+ invokeLLM(params: LLMParams, options?: AsyncOptions): Promise<LLMResponse | AsyncJobCreatedResponse>;
1023
+ uploadFile(params: {
1024
+ file: File;
1025
+ metadata?: Record<string, any>;
1026
+ }): Promise<ServiceResponse>;
1027
+ uploadPrivateFile(params: {
1028
+ file: File;
1029
+ }): Promise<{
1030
+ file_uri: string;
1031
+ file_id: string;
1032
+ filename: string;
1033
+ size: number;
1034
+ content_type: string;
1035
+ }>;
1036
+ createFileSignedUrl(params: {
1037
+ file_uri: string;
1038
+ expires_in?: number;
1039
+ }): Promise<{
1040
+ signed_url: string;
1041
+ expires_in: number;
1042
+ }>;
1043
+ downloadPrivateFile(params: {
1044
+ file_uri: string;
1045
+ filename?: string;
1046
+ }): Promise<void>;
1047
+ generateImage(params: ImageParams): Promise<ServiceResponse>;
1048
+ generateSpeech(params: SpeechParams): Promise<ServiceResponse>;
1049
+ generateVideo(params: VideoParams): Promise<ServiceResponse>;
1050
+ checkVideoStatus(params: VideoStatusParams): Promise<ServiceResponse>;
1051
+ extractData(params: ExtractParams): Promise<ServiceResponse>;
1052
+ checkJobStatus(params: CheckJobStatusParams): Promise<AsyncJobStatusResponse>;
1019
1053
  SendEmail(params: EmailParams): Promise<ServiceResponse>;
1020
1054
  SendSMS(params: SMSParams): Promise<ServiceResponse>;
1021
1055
  /**
@@ -1239,7 +1273,7 @@ interface ConnectorsModule {
1239
1273
  }
1240
1274
  /**
1241
1275
  * Service role client interface (elevated admin operations)
1242
- * Available when serviceToken is provided in config
1276
+ * Available when apiKey is provided in config
1243
1277
  */
1244
1278
  interface ServiceRoleClient {
1245
1279
  /** Collection operations with service role privileges */
@@ -1321,8 +1355,8 @@ interface OmnikitClient {
1321
1355
  auth: AuthModule;
1322
1356
  /**
1323
1357
  * Service-level operations (elevated privileges).
1324
- * Only available when serviceToken is provided (e.g., via createServerClient).
1325
- * Throws error if accessed without serviceToken.
1358
+ * Only available when apiKey is provided (e.g., via createServerClient).
1359
+ * Throws error if accessed without apiKey.
1326
1360
  *
1327
1361
  * @example
1328
1362
  * ```typescript
@@ -1803,7 +1837,6 @@ declare class APIClient implements OmnikitClient {
1803
1837
  appId: string;
1804
1838
  baseUrl: string;
1805
1839
  private userToken;
1806
- private _serviceToken;
1807
1840
  private _apiKey;
1808
1841
  private initialized;
1809
1842
  private initPromise;
@@ -1900,7 +1933,7 @@ declare class APIClient implements OmnikitClient {
1900
1933
  get auth(): AuthModule;
1901
1934
  /**
1902
1935
  * Service-level operations (elevated privileges).
1903
- * Only available when serviceToken is provided (e.g., via createServerClient).
1936
+ * Only available when apiKey is provided (e.g., via createServerClient).
1904
1937
  */
1905
1938
  get service(): ServiceRoleClient;
1906
1939
  /**
@@ -2181,7 +2214,7 @@ declare class APIClient implements OmnikitClient {
2181
2214
  *
2182
2215
  * @param secretName - Name of the secret to retrieve
2183
2216
  * @returns The decrypted secret value
2184
- * @throws Error if the secret is not found or service token is invalid
2217
+ * @throws Error if the secret is not found or API key is invalid
2185
2218
  */
2186
2219
  getSecret(secretName: string): Promise<string>;
2187
2220
  }
@@ -2235,7 +2268,7 @@ interface ServerRequest {
2235
2268
  * // Access user data (user JWT auth)
2236
2269
  * const currentUser = await omnikit.auth.me();
2237
2270
  *
2238
- * // Access connectors (requires service token)
2271
+ * // Access connectors (requires API key)
2239
2272
  * const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
2240
2273
  *
2241
2274
  * // Make direct Slack API call
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { cleanTokenFromUrl, getAccessToken, isTokenInUrl, removeAccessToken, sav
7
7
  * Like Base44's connectors module - allows backend functions to get access tokens
8
8
  * for making direct API calls to external services.
9
9
  *
10
- * SECURITY: getAccessToken requires service token authentication.
10
+ * SECURITY: getAccessToken requires API key (X-API-Key) authentication.
11
11
  * Only available to backend functions, not frontend code.
12
12
  */
13
13
  type ConnectorType = 'slack' | 'google_calendar' | 'gmail' | 'google_sheets' | 'notion' | 'salesforce';
@@ -32,7 +32,7 @@ interface ConnectorsModule$1 {
32
32
  /**
33
33
  * Get access token for a connector.
34
34
  *
35
- * SECURITY: Requires service token authentication.
35
+ * SECURITY: Requires API key (X-API-Key) authentication.
36
36
  * Only available in backend functions, not frontend code.
37
37
  *
38
38
  * @example
@@ -98,17 +98,16 @@ interface OmnikitConfig {
98
98
  * If not provided, will auto-detect from URL or localStorage
99
99
  */
100
100
  token?: string;
101
- /**
102
- * Service role token for elevated admin operations (optional)
103
- * When provided, enables asServiceRole operations
104
- */
105
- serviceToken?: string;
106
101
  /**
107
102
  * API key for server-to-server authentication (optional)
108
- * Used in backend functions (Deno Edge Functions) where user auth isn't needed.
109
- * Takes precedence over serviceToken if both are provided.
103
+ * Used in backend functions (Deno Edge Functions) for privileged operations.
104
+ * When provided, enables service role operations via omnikit.service
110
105
  */
111
106
  apiKey?: string;
107
+ /**
108
+ * @deprecated Use apiKey instead. serviceToken is an alias for backwards compatibility.
109
+ */
110
+ serviceToken?: string;
112
111
  /**
113
112
  * Auto-detect and load token from URL params or localStorage
114
113
  * @default true
@@ -1013,9 +1012,44 @@ type UserEntityClass<T = UserInfo> = UserCollectionClass<T>;
1013
1012
  */
1014
1013
  type IntegrationMethod = (params?: Record<string, any>, useServiceToken?: boolean) => Promise<any>;
1015
1014
  /**
1016
- * BuiltIn integration methods
1015
+ * BuiltIn integration methods.
1016
+ * Supports both camelCase (industry standard) and PascalCase (legacy).
1017
+ * camelCase is recommended for new code.
1017
1018
  */
1018
1019
  interface BuiltInIntegration {
1020
+ sendEmail(params: EmailParams): Promise<ServiceResponse>;
1021
+ sendSMS(params: SMSParams): Promise<ServiceResponse>;
1022
+ invokeLLM(params: LLMParams, options?: AsyncOptions): Promise<LLMResponse | AsyncJobCreatedResponse>;
1023
+ uploadFile(params: {
1024
+ file: File;
1025
+ metadata?: Record<string, any>;
1026
+ }): Promise<ServiceResponse>;
1027
+ uploadPrivateFile(params: {
1028
+ file: File;
1029
+ }): Promise<{
1030
+ file_uri: string;
1031
+ file_id: string;
1032
+ filename: string;
1033
+ size: number;
1034
+ content_type: string;
1035
+ }>;
1036
+ createFileSignedUrl(params: {
1037
+ file_uri: string;
1038
+ expires_in?: number;
1039
+ }): Promise<{
1040
+ signed_url: string;
1041
+ expires_in: number;
1042
+ }>;
1043
+ downloadPrivateFile(params: {
1044
+ file_uri: string;
1045
+ filename?: string;
1046
+ }): Promise<void>;
1047
+ generateImage(params: ImageParams): Promise<ServiceResponse>;
1048
+ generateSpeech(params: SpeechParams): Promise<ServiceResponse>;
1049
+ generateVideo(params: VideoParams): Promise<ServiceResponse>;
1050
+ checkVideoStatus(params: VideoStatusParams): Promise<ServiceResponse>;
1051
+ extractData(params: ExtractParams): Promise<ServiceResponse>;
1052
+ checkJobStatus(params: CheckJobStatusParams): Promise<AsyncJobStatusResponse>;
1019
1053
  SendEmail(params: EmailParams): Promise<ServiceResponse>;
1020
1054
  SendSMS(params: SMSParams): Promise<ServiceResponse>;
1021
1055
  /**
@@ -1239,7 +1273,7 @@ interface ConnectorsModule {
1239
1273
  }
1240
1274
  /**
1241
1275
  * Service role client interface (elevated admin operations)
1242
- * Available when serviceToken is provided in config
1276
+ * Available when apiKey is provided in config
1243
1277
  */
1244
1278
  interface ServiceRoleClient {
1245
1279
  /** Collection operations with service role privileges */
@@ -1321,8 +1355,8 @@ interface OmnikitClient {
1321
1355
  auth: AuthModule;
1322
1356
  /**
1323
1357
  * Service-level operations (elevated privileges).
1324
- * Only available when serviceToken is provided (e.g., via createServerClient).
1325
- * Throws error if accessed without serviceToken.
1358
+ * Only available when apiKey is provided (e.g., via createServerClient).
1359
+ * Throws error if accessed without apiKey.
1326
1360
  *
1327
1361
  * @example
1328
1362
  * ```typescript
@@ -1803,7 +1837,6 @@ declare class APIClient implements OmnikitClient {
1803
1837
  appId: string;
1804
1838
  baseUrl: string;
1805
1839
  private userToken;
1806
- private _serviceToken;
1807
1840
  private _apiKey;
1808
1841
  private initialized;
1809
1842
  private initPromise;
@@ -1900,7 +1933,7 @@ declare class APIClient implements OmnikitClient {
1900
1933
  get auth(): AuthModule;
1901
1934
  /**
1902
1935
  * Service-level operations (elevated privileges).
1903
- * Only available when serviceToken is provided (e.g., via createServerClient).
1936
+ * Only available when apiKey is provided (e.g., via createServerClient).
1904
1937
  */
1905
1938
  get service(): ServiceRoleClient;
1906
1939
  /**
@@ -2181,7 +2214,7 @@ declare class APIClient implements OmnikitClient {
2181
2214
  *
2182
2215
  * @param secretName - Name of the secret to retrieve
2183
2216
  * @returns The decrypted secret value
2184
- * @throws Error if the secret is not found or service token is invalid
2217
+ * @throws Error if the secret is not found or API key is invalid
2185
2218
  */
2186
2219
  getSecret(secretName: string): Promise<string>;
2187
2220
  }
@@ -2235,7 +2268,7 @@ interface ServerRequest {
2235
2268
  * // Access user data (user JWT auth)
2236
2269
  * const currentUser = await omnikit.auth.me();
2237
2270
  *
2238
- * // Access connectors (requires service token)
2271
+ * // Access connectors (requires API key)
2239
2272
  * const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
2240
2273
  *
2241
2274
  * // Make direct Slack API call
package/dist/index.js CHANGED
@@ -436,13 +436,13 @@ var LiveVoiceSessionImpl = class {
436
436
  };
437
437
 
438
438
  // src/connectors.ts
439
- function createConnectorsModule(makeRequest, appId, baseUrl, getServiceToken) {
439
+ function createConnectorsModule(makeRequest, appId, baseUrl, getApiKey) {
440
440
  return {
441
441
  async getAccessToken(connectorType) {
442
- const serviceToken = getServiceToken();
443
- if (!serviceToken) {
442
+ const apiKey = getApiKey();
443
+ if (!apiKey) {
444
444
  throw new Error(
445
- "Service token is required to get connector access token. This method is only available in backend functions. Make sure you created the client with a serviceToken."
445
+ "API key is required to get connector access token. This method is only available in backend functions. Use createServerClient(req) to get an authenticated client."
446
446
  );
447
447
  }
448
448
  return makeRequest(
@@ -450,6 +450,7 @@ function createConnectorsModule(makeRequest, appId, baseUrl, getServiceToken) {
450
450
  "GET",
451
451
  null,
452
452
  { useServiceToken: true }
453
+ // Still uses this flag internally to trigger API key usage
453
454
  );
454
455
  },
455
456
  async isConnected(connectorType) {
@@ -543,7 +544,6 @@ var getMetadataCacheKey = (appId) => `omnikit_metadata_${appId}`;
543
544
  var APIClient = class {
544
545
  constructor(config) {
545
546
  this.userToken = null;
546
- this._serviceToken = null;
547
547
  this._apiKey = null;
548
548
  this.initialized = false;
549
549
  this.initPromise = null;
@@ -557,8 +557,7 @@ var APIClient = class {
557
557
  this._userListeners = /* @__PURE__ */ new Set();
558
558
  this.appId = config.appId;
559
559
  this.baseUrl = config.serverUrl || config.baseUrl || "http://localhost:8001/api";
560
- this._serviceToken = config.serviceToken || null;
561
- this._apiKey = config.apiKey || null;
560
+ this._apiKey = config.apiKey || config.serviceToken || null;
562
561
  const isBrowser2 = typeof window !== "undefined" && typeof localStorage !== "undefined";
563
562
  this._metadata = this.loadCachedMetadata(config.initialMetadata);
564
563
  if (isBrowser2) {
@@ -820,14 +819,14 @@ var APIClient = class {
820
819
  }
821
820
  /**
822
821
  * Service-level operations (elevated privileges).
823
- * Only available when serviceToken is provided (e.g., via createServerClient).
822
+ * Only available when apiKey is provided (e.g., via createServerClient).
824
823
  */
825
824
  get service() {
826
- if (!this._serviceToken) {
825
+ if (!this._apiKey) {
827
826
  throw new OmnikitError(
828
- "Service token is required. Use createServerClient(req) in backend functions.",
827
+ "API key is required. Use createServerClient(req) in backend functions.",
829
828
  403,
830
- "SERVICE_TOKEN_REQUIRED"
829
+ "API_KEY_REQUIRED"
831
830
  );
832
831
  }
833
832
  if (this._asServiceRole) {
@@ -878,7 +877,7 @@ var APIClient = class {
878
877
  this.makeRequest.bind(this),
879
878
  this.appId,
880
879
  this.baseUrl,
881
- () => this._serviceToken
880
+ () => this._apiKey
882
881
  );
883
882
  }
884
883
  return this._connectors;
@@ -1162,7 +1161,7 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
1162
1161
  }
1163
1162
  if (useServiceToken) {
1164
1163
  const originalGetToken = client.getAuthToken.bind(client);
1165
- client.getAuthToken = () => client._serviceToken;
1164
+ client.getAuthToken = () => client._apiKey;
1166
1165
  try {
1167
1166
  const result = await collection[method](...args);
1168
1167
  client.getAuthToken = originalGetToken;
@@ -1246,9 +1245,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
1246
1245
  if (token) {
1247
1246
  headers["Authorization"] = `Bearer ${token}`;
1248
1247
  }
1249
- if (this._serviceToken) {
1250
- headers["X-Service-Token"] = this._serviceToken;
1251
- }
1252
1248
  if (this._apiKey) {
1253
1249
  headers["X-API-Key"] = this._apiKey;
1254
1250
  }
@@ -2252,9 +2248,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2252
2248
  if (userToken) {
2253
2249
  fetchOptions.headers.Authorization = `Bearer ${userToken}`;
2254
2250
  }
2255
- if (this._serviceToken) {
2256
- fetchOptions.headers["X-Service-Token"] = this._serviceToken;
2257
- }
2258
2251
  if (this._apiKey) {
2259
2252
  fetchOptions.headers["X-API-Key"] = this._apiKey;
2260
2253
  }
@@ -2301,9 +2294,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2301
2294
  if (userToken) {
2302
2295
  fetchOptions.headers.Authorization = `Bearer ${userToken}`;
2303
2296
  }
2304
- if (this._serviceToken) {
2305
- fetchOptions.headers["X-Service-Token"] = this._serviceToken;
2306
- }
2307
2297
  if (this._apiKey) {
2308
2298
  fetchOptions.headers["X-API-Key"] = this._apiKey;
2309
2299
  }
@@ -2424,9 +2414,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2424
2414
  if (token) {
2425
2415
  headers["Authorization"] = `Bearer ${token}`;
2426
2416
  }
2427
- if (this._serviceToken) {
2428
- headers["X-Service-Token"] = this._serviceToken;
2429
- }
2430
2417
  if (this._apiKey) {
2431
2418
  headers["X-API-Key"] = this._apiKey;
2432
2419
  }
@@ -2711,25 +2698,20 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2711
2698
  *
2712
2699
  * @param secretName - Name of the secret to retrieve
2713
2700
  * @returns The decrypted secret value
2714
- * @throws Error if the secret is not found or service token is invalid
2701
+ * @throws Error if the secret is not found or API key is invalid
2715
2702
  */
2716
2703
  async getSecret(secretName) {
2717
- const authToken = this._serviceToken || this._apiKey;
2718
- if (!authToken) {
2704
+ if (!this._apiKey) {
2719
2705
  throw new OmnikitError(
2720
- "Service token required. Use createServerClient(req) in backend functions.",
2706
+ "API key required. Use createServerClient(req) in backend functions.",
2721
2707
  403,
2722
2708
  "AUTH_REQUIRED"
2723
2709
  );
2724
2710
  }
2725
2711
  const headers = {
2726
- "Content-Type": "application/json"
2712
+ "Content-Type": "application/json",
2713
+ "X-API-Key": this._apiKey
2727
2714
  };
2728
- if (this._serviceToken) {
2729
- headers["X-Service-Token"] = this._serviceToken;
2730
- } else if (this._apiKey) {
2731
- headers["X-API-Key"] = this._apiKey;
2732
- }
2733
2715
  const response = await fetch(
2734
2716
  `${this.baseUrl}/apps/${this.appId}/secrets/${secretName}/value`,
2735
2717
  {
@@ -2761,12 +2743,12 @@ function createServerClient(request) {
2761
2743
  };
2762
2744
  const authHeader = getHeader("Authorization") || getHeader("authorization");
2763
2745
  const userToken = authHeader?.startsWith("Bearer ") ? authHeader.slice(7) : null;
2764
- const serviceToken = getHeader("X-Omnikit-Service-Authorization") || getHeader("x-omnikit-service-authorization");
2765
- const appId = getHeader("X-Omnikit-App-Id") || getHeader("x-omnikit-app-id");
2766
- const serverUrl = getHeader("X-Omnikit-Server-Url") || getHeader("x-omnikit-server-url") || "https://omnikit.ai/api";
2746
+ const apiKey = getHeader("X-API-Key") || getHeader("x-api-key");
2747
+ const appId = (typeof __OMNIKIT_APP_ID__ !== "undefined" ? __OMNIKIT_APP_ID__ : null) || getHeader("X-Omnikit-App-Id") || getHeader("x-omnikit-app-id");
2748
+ const serverUrl = (typeof __OMNIKIT_API_URL__ !== "undefined" ? __OMNIKIT_API_URL__ : null) || getHeader("X-Omnikit-Server-Url") || getHeader("x-omnikit-server-url") || "https://omnikit.ai/api";
2767
2749
  if (!appId) {
2768
2750
  throw new OmnikitError(
2769
- "X-Omnikit-App-Id header is required. This function should be invoked through the Omnikit platform.",
2751
+ "App ID not found. Ensure function is deployed through Omnikit platform (or X-Omnikit-App-Id header is set).",
2770
2752
  400,
2771
2753
  "MISSING_APP_ID"
2772
2754
  );
@@ -2775,7 +2757,7 @@ function createServerClient(request) {
2775
2757
  appId,
2776
2758
  serverUrl,
2777
2759
  token: userToken || void 0,
2778
- serviceToken: serviceToken || void 0,
2760
+ apiKey: apiKey || void 0,
2779
2761
  autoInitAuth: false
2780
2762
  // Don't auto-detect from localStorage in backend
2781
2763
  });