@omnikit-ai/sdk 2.2.4 → 2.2.5

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.mjs CHANGED
@@ -434,13 +434,13 @@ var LiveVoiceSessionImpl = class {
434
434
  };
435
435
 
436
436
  // src/connectors.ts
437
- function createConnectorsModule(makeRequest, appId, baseUrl, getServiceToken) {
437
+ function createConnectorsModule(makeRequest, appId, baseUrl, getApiKey) {
438
438
  return {
439
439
  async getAccessToken(connectorType) {
440
- const serviceToken = getServiceToken();
441
- if (!serviceToken) {
440
+ const apiKey = getApiKey();
441
+ if (!apiKey) {
442
442
  throw new Error(
443
- "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."
443
+ "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."
444
444
  );
445
445
  }
446
446
  return makeRequest(
@@ -448,6 +448,7 @@ function createConnectorsModule(makeRequest, appId, baseUrl, getServiceToken) {
448
448
  "GET",
449
449
  null,
450
450
  { useServiceToken: true }
451
+ // Still uses this flag internally to trigger API key usage
451
452
  );
452
453
  },
453
454
  async isConnected(connectorType) {
@@ -541,7 +542,6 @@ var getMetadataCacheKey = (appId) => `omnikit_metadata_${appId}`;
541
542
  var APIClient = class {
542
543
  constructor(config) {
543
544
  this.userToken = null;
544
- this._serviceToken = null;
545
545
  this._apiKey = null;
546
546
  this.initialized = false;
547
547
  this.initPromise = null;
@@ -555,8 +555,7 @@ var APIClient = class {
555
555
  this._userListeners = /* @__PURE__ */ new Set();
556
556
  this.appId = config.appId;
557
557
  this.baseUrl = config.serverUrl || config.baseUrl || "http://localhost:8001/api";
558
- this._serviceToken = config.serviceToken || null;
559
- this._apiKey = config.apiKey || null;
558
+ this._apiKey = config.apiKey || config.serviceToken || null;
560
559
  const isBrowser2 = typeof window !== "undefined" && typeof localStorage !== "undefined";
561
560
  this._metadata = this.loadCachedMetadata(config.initialMetadata);
562
561
  if (isBrowser2) {
@@ -818,14 +817,14 @@ var APIClient = class {
818
817
  }
819
818
  /**
820
819
  * Service-level operations (elevated privileges).
821
- * Only available when serviceToken is provided (e.g., via createServerClient).
820
+ * Only available when apiKey is provided (e.g., via createServerClient).
822
821
  */
823
822
  get service() {
824
- if (!this._serviceToken) {
823
+ if (!this._apiKey) {
825
824
  throw new OmnikitError(
826
- "Service token is required. Use createServerClient(req) in backend functions.",
825
+ "API key is required. Use createServerClient(req) in backend functions.",
827
826
  403,
828
- "SERVICE_TOKEN_REQUIRED"
827
+ "API_KEY_REQUIRED"
829
828
  );
830
829
  }
831
830
  if (this._asServiceRole) {
@@ -876,7 +875,7 @@ var APIClient = class {
876
875
  this.makeRequest.bind(this),
877
876
  this.appId,
878
877
  this.baseUrl,
879
- () => this._serviceToken
878
+ () => this._apiKey
880
879
  );
881
880
  }
882
881
  return this._connectors;
@@ -1160,7 +1159,7 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
1160
1159
  }
1161
1160
  if (useServiceToken) {
1162
1161
  const originalGetToken = client.getAuthToken.bind(client);
1163
- client.getAuthToken = () => client._serviceToken;
1162
+ client.getAuthToken = () => client._apiKey;
1164
1163
  try {
1165
1164
  const result = await collection[method](...args);
1166
1165
  client.getAuthToken = originalGetToken;
@@ -1244,9 +1243,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
1244
1243
  if (token) {
1245
1244
  headers["Authorization"] = `Bearer ${token}`;
1246
1245
  }
1247
- if (this._serviceToken) {
1248
- headers["X-Service-Token"] = this._serviceToken;
1249
- }
1250
1246
  if (this._apiKey) {
1251
1247
  headers["X-API-Key"] = this._apiKey;
1252
1248
  }
@@ -2250,9 +2246,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2250
2246
  if (userToken) {
2251
2247
  fetchOptions.headers.Authorization = `Bearer ${userToken}`;
2252
2248
  }
2253
- if (this._serviceToken) {
2254
- fetchOptions.headers["X-Service-Token"] = this._serviceToken;
2255
- }
2256
2249
  if (this._apiKey) {
2257
2250
  fetchOptions.headers["X-API-Key"] = this._apiKey;
2258
2251
  }
@@ -2299,9 +2292,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2299
2292
  if (userToken) {
2300
2293
  fetchOptions.headers.Authorization = `Bearer ${userToken}`;
2301
2294
  }
2302
- if (this._serviceToken) {
2303
- fetchOptions.headers["X-Service-Token"] = this._serviceToken;
2304
- }
2305
2295
  if (this._apiKey) {
2306
2296
  fetchOptions.headers["X-API-Key"] = this._apiKey;
2307
2297
  }
@@ -2422,9 +2412,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2422
2412
  if (token) {
2423
2413
  headers["Authorization"] = `Bearer ${token}`;
2424
2414
  }
2425
- if (this._serviceToken) {
2426
- headers["X-Service-Token"] = this._serviceToken;
2427
- }
2428
2415
  if (this._apiKey) {
2429
2416
  headers["X-API-Key"] = this._apiKey;
2430
2417
  }
@@ -2709,25 +2696,20 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2709
2696
  *
2710
2697
  * @param secretName - Name of the secret to retrieve
2711
2698
  * @returns The decrypted secret value
2712
- * @throws Error if the secret is not found or service token is invalid
2699
+ * @throws Error if the secret is not found or API key is invalid
2713
2700
  */
2714
2701
  async getSecret(secretName) {
2715
- const authToken = this._serviceToken || this._apiKey;
2716
- if (!authToken) {
2702
+ if (!this._apiKey) {
2717
2703
  throw new OmnikitError(
2718
- "Service token required. Use createServerClient(req) in backend functions.",
2704
+ "API key required. Use createServerClient(req) in backend functions.",
2719
2705
  403,
2720
2706
  "AUTH_REQUIRED"
2721
2707
  );
2722
2708
  }
2723
2709
  const headers = {
2724
- "Content-Type": "application/json"
2710
+ "Content-Type": "application/json",
2711
+ "X-API-Key": this._apiKey
2725
2712
  };
2726
- if (this._serviceToken) {
2727
- headers["X-Service-Token"] = this._serviceToken;
2728
- } else if (this._apiKey) {
2729
- headers["X-API-Key"] = this._apiKey;
2730
- }
2731
2713
  const response = await fetch(
2732
2714
  `${this.baseUrl}/apps/${this.appId}/secrets/${secretName}/value`,
2733
2715
  {
@@ -2759,12 +2741,12 @@ function createServerClient(request) {
2759
2741
  };
2760
2742
  const authHeader = getHeader("Authorization") || getHeader("authorization");
2761
2743
  const userToken = authHeader?.startsWith("Bearer ") ? authHeader.slice(7) : null;
2762
- const serviceToken = getHeader("X-Omnikit-Service-Authorization") || getHeader("x-omnikit-service-authorization");
2763
- const appId = getHeader("X-Omnikit-App-Id") || getHeader("x-omnikit-app-id");
2764
- const serverUrl = getHeader("X-Omnikit-Server-Url") || getHeader("x-omnikit-server-url") || "https://omnikit.ai/api";
2744
+ const apiKey = getHeader("X-API-Key") || getHeader("x-api-key");
2745
+ const appId = (typeof __OMNIKIT_APP_ID__ !== "undefined" ? __OMNIKIT_APP_ID__ : null) || getHeader("X-Omnikit-App-Id") || getHeader("x-omnikit-app-id");
2746
+ 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";
2765
2747
  if (!appId) {
2766
2748
  throw new OmnikitError(
2767
- "X-Omnikit-App-Id header is required. This function should be invoked through the Omnikit platform.",
2749
+ "App ID not found. Ensure function is deployed through Omnikit platform (or X-Omnikit-App-Id header is set).",
2768
2750
  400,
2769
2751
  "MISSING_APP_ID"
2770
2752
  );
@@ -2773,7 +2755,7 @@ function createServerClient(request) {
2773
2755
  appId,
2774
2756
  serverUrl,
2775
2757
  token: userToken || void 0,
2776
- serviceToken: serviceToken || void 0,
2758
+ apiKey: apiKey || void 0,
2777
2759
  autoInitAuth: false
2778
2760
  // Don't auto-detect from localStorage in backend
2779
2761
  });