@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.d.mts +14 -16
- package/dist/index.d.ts +14 -16
- package/dist/index.js +22 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
|
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)
|
|
109
|
-
*
|
|
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
|
|
@@ -1239,7 +1238,7 @@ interface ConnectorsModule {
|
|
|
1239
1238
|
}
|
|
1240
1239
|
/**
|
|
1241
1240
|
* Service role client interface (elevated admin operations)
|
|
1242
|
-
* Available when
|
|
1241
|
+
* Available when apiKey is provided in config
|
|
1243
1242
|
*/
|
|
1244
1243
|
interface ServiceRoleClient {
|
|
1245
1244
|
/** Collection operations with service role privileges */
|
|
@@ -1321,8 +1320,8 @@ interface OmnikitClient {
|
|
|
1321
1320
|
auth: AuthModule;
|
|
1322
1321
|
/**
|
|
1323
1322
|
* Service-level operations (elevated privileges).
|
|
1324
|
-
* Only available when
|
|
1325
|
-
* Throws error if accessed without
|
|
1323
|
+
* Only available when apiKey is provided (e.g., via createServerClient).
|
|
1324
|
+
* Throws error if accessed without apiKey.
|
|
1326
1325
|
*
|
|
1327
1326
|
* @example
|
|
1328
1327
|
* ```typescript
|
|
@@ -1803,7 +1802,6 @@ declare class APIClient implements OmnikitClient {
|
|
|
1803
1802
|
appId: string;
|
|
1804
1803
|
baseUrl: string;
|
|
1805
1804
|
private userToken;
|
|
1806
|
-
private _serviceToken;
|
|
1807
1805
|
private _apiKey;
|
|
1808
1806
|
private initialized;
|
|
1809
1807
|
private initPromise;
|
|
@@ -1900,7 +1898,7 @@ declare class APIClient implements OmnikitClient {
|
|
|
1900
1898
|
get auth(): AuthModule;
|
|
1901
1899
|
/**
|
|
1902
1900
|
* Service-level operations (elevated privileges).
|
|
1903
|
-
* Only available when
|
|
1901
|
+
* Only available when apiKey is provided (e.g., via createServerClient).
|
|
1904
1902
|
*/
|
|
1905
1903
|
get service(): ServiceRoleClient;
|
|
1906
1904
|
/**
|
|
@@ -2181,7 +2179,7 @@ declare class APIClient implements OmnikitClient {
|
|
|
2181
2179
|
*
|
|
2182
2180
|
* @param secretName - Name of the secret to retrieve
|
|
2183
2181
|
* @returns The decrypted secret value
|
|
2184
|
-
* @throws Error if the secret is not found or
|
|
2182
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
2185
2183
|
*/
|
|
2186
2184
|
getSecret(secretName: string): Promise<string>;
|
|
2187
2185
|
}
|
|
@@ -2235,7 +2233,7 @@ interface ServerRequest {
|
|
|
2235
2233
|
* // Access user data (user JWT auth)
|
|
2236
2234
|
* const currentUser = await omnikit.auth.me();
|
|
2237
2235
|
*
|
|
2238
|
-
* // Access connectors (requires
|
|
2236
|
+
* // Access connectors (requires API key)
|
|
2239
2237
|
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
2240
2238
|
*
|
|
2241
2239
|
* // 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
|
|
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
|
|
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)
|
|
109
|
-
*
|
|
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
|
|
@@ -1239,7 +1238,7 @@ interface ConnectorsModule {
|
|
|
1239
1238
|
}
|
|
1240
1239
|
/**
|
|
1241
1240
|
* Service role client interface (elevated admin operations)
|
|
1242
|
-
* Available when
|
|
1241
|
+
* Available when apiKey is provided in config
|
|
1243
1242
|
*/
|
|
1244
1243
|
interface ServiceRoleClient {
|
|
1245
1244
|
/** Collection operations with service role privileges */
|
|
@@ -1321,8 +1320,8 @@ interface OmnikitClient {
|
|
|
1321
1320
|
auth: AuthModule;
|
|
1322
1321
|
/**
|
|
1323
1322
|
* Service-level operations (elevated privileges).
|
|
1324
|
-
* Only available when
|
|
1325
|
-
* Throws error if accessed without
|
|
1323
|
+
* Only available when apiKey is provided (e.g., via createServerClient).
|
|
1324
|
+
* Throws error if accessed without apiKey.
|
|
1326
1325
|
*
|
|
1327
1326
|
* @example
|
|
1328
1327
|
* ```typescript
|
|
@@ -1803,7 +1802,6 @@ declare class APIClient implements OmnikitClient {
|
|
|
1803
1802
|
appId: string;
|
|
1804
1803
|
baseUrl: string;
|
|
1805
1804
|
private userToken;
|
|
1806
|
-
private _serviceToken;
|
|
1807
1805
|
private _apiKey;
|
|
1808
1806
|
private initialized;
|
|
1809
1807
|
private initPromise;
|
|
@@ -1900,7 +1898,7 @@ declare class APIClient implements OmnikitClient {
|
|
|
1900
1898
|
get auth(): AuthModule;
|
|
1901
1899
|
/**
|
|
1902
1900
|
* Service-level operations (elevated privileges).
|
|
1903
|
-
* Only available when
|
|
1901
|
+
* Only available when apiKey is provided (e.g., via createServerClient).
|
|
1904
1902
|
*/
|
|
1905
1903
|
get service(): ServiceRoleClient;
|
|
1906
1904
|
/**
|
|
@@ -2181,7 +2179,7 @@ declare class APIClient implements OmnikitClient {
|
|
|
2181
2179
|
*
|
|
2182
2180
|
* @param secretName - Name of the secret to retrieve
|
|
2183
2181
|
* @returns The decrypted secret value
|
|
2184
|
-
* @throws Error if the secret is not found or
|
|
2182
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
2185
2183
|
*/
|
|
2186
2184
|
getSecret(secretName: string): Promise<string>;
|
|
2187
2185
|
}
|
|
@@ -2235,7 +2233,7 @@ interface ServerRequest {
|
|
|
2235
2233
|
* // Access user data (user JWT auth)
|
|
2236
2234
|
* const currentUser = await omnikit.auth.me();
|
|
2237
2235
|
*
|
|
2238
|
-
* // Access connectors (requires
|
|
2236
|
+
* // Access connectors (requires API key)
|
|
2239
2237
|
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
2240
2238
|
*
|
|
2241
2239
|
* // 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,
|
|
439
|
+
function createConnectorsModule(makeRequest, appId, baseUrl, getApiKey) {
|
|
440
440
|
return {
|
|
441
441
|
async getAccessToken(connectorType) {
|
|
442
|
-
const
|
|
443
|
-
if (!
|
|
442
|
+
const apiKey = getApiKey();
|
|
443
|
+
if (!apiKey) {
|
|
444
444
|
throw new Error(
|
|
445
|
-
"
|
|
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.
|
|
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
|
|
822
|
+
* Only available when apiKey is provided (e.g., via createServerClient).
|
|
824
823
|
*/
|
|
825
824
|
get service() {
|
|
826
|
-
if (!this.
|
|
825
|
+
if (!this._apiKey) {
|
|
827
826
|
throw new OmnikitError(
|
|
828
|
-
"
|
|
827
|
+
"API key is required. Use createServerClient(req) in backend functions.",
|
|
829
828
|
403,
|
|
830
|
-
"
|
|
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.
|
|
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.
|
|
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
|
|
2701
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
2715
2702
|
*/
|
|
2716
2703
|
async getSecret(secretName) {
|
|
2717
|
-
|
|
2718
|
-
if (!authToken) {
|
|
2704
|
+
if (!this._apiKey) {
|
|
2719
2705
|
throw new OmnikitError(
|
|
2720
|
-
"
|
|
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
|
|
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
|
-
"
|
|
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
|
-
|
|
2760
|
+
apiKey: apiKey || void 0,
|
|
2779
2761
|
autoInitAuth: false
|
|
2780
2762
|
// Don't auto-detect from localStorage in backend
|
|
2781
2763
|
});
|