@omnikit-ai/sdk 2.2.3 → 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 +31 -29
- package/dist/index.d.ts +31 -29
- package/dist/index.js +37 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -46
- 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
|
|
@@ -1383,19 +1382,20 @@ interface OmnikitClient {
|
|
|
1383
1382
|
/**
|
|
1384
1383
|
* Get a secret value at runtime (for backend functions).
|
|
1385
1384
|
*
|
|
1386
|
-
* This method securely fetches secrets from the Omnikit API
|
|
1387
|
-
*
|
|
1388
|
-
*
|
|
1385
|
+
* This method securely fetches secrets from the Omnikit API at runtime.
|
|
1386
|
+
* Secrets are NOT injected into function code - they are fetched via API
|
|
1387
|
+
* to ensure they cannot be leaked through source code, logs, or backups.
|
|
1389
1388
|
*
|
|
1390
1389
|
* @example
|
|
1391
1390
|
* ```typescript
|
|
1391
|
+
* const omnikit = createServerClient(req);
|
|
1392
1392
|
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
1393
1393
|
* const stripe = new Stripe(stripeKey);
|
|
1394
1394
|
* ```
|
|
1395
1395
|
*
|
|
1396
1396
|
* @param secretName - Name of the secret to retrieve
|
|
1397
1397
|
* @returns The decrypted secret value
|
|
1398
|
-
* @throws Error if the secret is not found or
|
|
1398
|
+
* @throws Error if the secret is not found or service token is invalid
|
|
1399
1399
|
*/
|
|
1400
1400
|
getSecret(secretName: string): Promise<string>;
|
|
1401
1401
|
}
|
|
@@ -1802,7 +1802,6 @@ declare class APIClient implements OmnikitClient {
|
|
|
1802
1802
|
appId: string;
|
|
1803
1803
|
baseUrl: string;
|
|
1804
1804
|
private userToken;
|
|
1805
|
-
private _serviceToken;
|
|
1806
1805
|
private _apiKey;
|
|
1807
1806
|
private initialized;
|
|
1808
1807
|
private initPromise;
|
|
@@ -1899,7 +1898,7 @@ declare class APIClient implements OmnikitClient {
|
|
|
1899
1898
|
get auth(): AuthModule;
|
|
1900
1899
|
/**
|
|
1901
1900
|
* Service-level operations (elevated privileges).
|
|
1902
|
-
* Only available when
|
|
1901
|
+
* Only available when apiKey is provided (e.g., via createServerClient).
|
|
1903
1902
|
*/
|
|
1904
1903
|
get service(): ServiceRoleClient;
|
|
1905
1904
|
/**
|
|
@@ -2158,21 +2157,24 @@ declare class APIClient implements OmnikitClient {
|
|
|
2158
2157
|
/**
|
|
2159
2158
|
* Get a secret value at runtime (for backend functions).
|
|
2160
2159
|
*
|
|
2161
|
-
* This method securely fetches secrets from the Omnikit API
|
|
2162
|
-
*
|
|
2163
|
-
*
|
|
2160
|
+
* This method securely fetches secrets from the Omnikit API at runtime.
|
|
2161
|
+
* Secrets are NOT injected into function code - they are fetched via API
|
|
2162
|
+
* to ensure they cannot be leaked through source code, logs, or backups.
|
|
2164
2163
|
*
|
|
2165
2164
|
* @example
|
|
2166
2165
|
* ```typescript
|
|
2167
2166
|
* // In a backend function (Deno Edge Function)
|
|
2168
|
-
*
|
|
2169
|
-
* appId: __OMNIKIT_APP_ID__,
|
|
2170
|
-
* serverUrl: __OMNIKIT_API_URL__,
|
|
2171
|
-
* apiKey: __OMNIKIT_API_KEY__,
|
|
2172
|
-
* });
|
|
2167
|
+
* import { createServerClient } from '@omnikit-ai/sdk';
|
|
2173
2168
|
*
|
|
2174
|
-
*
|
|
2175
|
-
*
|
|
2169
|
+
* Deno.serve(async (req) => {
|
|
2170
|
+
* const omnikit = createServerClient(req);
|
|
2171
|
+
*
|
|
2172
|
+
* // Fetch secret at runtime - secure, never in source code
|
|
2173
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
2174
|
+
* const stripe = new Stripe(stripeKey);
|
|
2175
|
+
*
|
|
2176
|
+
* // ... rest of function
|
|
2177
|
+
* });
|
|
2176
2178
|
* ```
|
|
2177
2179
|
*
|
|
2178
2180
|
* @param secretName - Name of the secret to retrieve
|
|
@@ -2231,7 +2233,7 @@ interface ServerRequest {
|
|
|
2231
2233
|
* // Access user data (user JWT auth)
|
|
2232
2234
|
* const currentUser = await omnikit.auth.me();
|
|
2233
2235
|
*
|
|
2234
|
-
* // Access connectors (requires
|
|
2236
|
+
* // Access connectors (requires API key)
|
|
2235
2237
|
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
2236
2238
|
*
|
|
2237
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
|
|
@@ -1383,19 +1382,20 @@ interface OmnikitClient {
|
|
|
1383
1382
|
/**
|
|
1384
1383
|
* Get a secret value at runtime (for backend functions).
|
|
1385
1384
|
*
|
|
1386
|
-
* This method securely fetches secrets from the Omnikit API
|
|
1387
|
-
*
|
|
1388
|
-
*
|
|
1385
|
+
* This method securely fetches secrets from the Omnikit API at runtime.
|
|
1386
|
+
* Secrets are NOT injected into function code - they are fetched via API
|
|
1387
|
+
* to ensure they cannot be leaked through source code, logs, or backups.
|
|
1389
1388
|
*
|
|
1390
1389
|
* @example
|
|
1391
1390
|
* ```typescript
|
|
1391
|
+
* const omnikit = createServerClient(req);
|
|
1392
1392
|
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
1393
1393
|
* const stripe = new Stripe(stripeKey);
|
|
1394
1394
|
* ```
|
|
1395
1395
|
*
|
|
1396
1396
|
* @param secretName - Name of the secret to retrieve
|
|
1397
1397
|
* @returns The decrypted secret value
|
|
1398
|
-
* @throws Error if the secret is not found or
|
|
1398
|
+
* @throws Error if the secret is not found or service token is invalid
|
|
1399
1399
|
*/
|
|
1400
1400
|
getSecret(secretName: string): Promise<string>;
|
|
1401
1401
|
}
|
|
@@ -1802,7 +1802,6 @@ declare class APIClient implements OmnikitClient {
|
|
|
1802
1802
|
appId: string;
|
|
1803
1803
|
baseUrl: string;
|
|
1804
1804
|
private userToken;
|
|
1805
|
-
private _serviceToken;
|
|
1806
1805
|
private _apiKey;
|
|
1807
1806
|
private initialized;
|
|
1808
1807
|
private initPromise;
|
|
@@ -1899,7 +1898,7 @@ declare class APIClient implements OmnikitClient {
|
|
|
1899
1898
|
get auth(): AuthModule;
|
|
1900
1899
|
/**
|
|
1901
1900
|
* Service-level operations (elevated privileges).
|
|
1902
|
-
* Only available when
|
|
1901
|
+
* Only available when apiKey is provided (e.g., via createServerClient).
|
|
1903
1902
|
*/
|
|
1904
1903
|
get service(): ServiceRoleClient;
|
|
1905
1904
|
/**
|
|
@@ -2158,21 +2157,24 @@ declare class APIClient implements OmnikitClient {
|
|
|
2158
2157
|
/**
|
|
2159
2158
|
* Get a secret value at runtime (for backend functions).
|
|
2160
2159
|
*
|
|
2161
|
-
* This method securely fetches secrets from the Omnikit API
|
|
2162
|
-
*
|
|
2163
|
-
*
|
|
2160
|
+
* This method securely fetches secrets from the Omnikit API at runtime.
|
|
2161
|
+
* Secrets are NOT injected into function code - they are fetched via API
|
|
2162
|
+
* to ensure they cannot be leaked through source code, logs, or backups.
|
|
2164
2163
|
*
|
|
2165
2164
|
* @example
|
|
2166
2165
|
* ```typescript
|
|
2167
2166
|
* // In a backend function (Deno Edge Function)
|
|
2168
|
-
*
|
|
2169
|
-
* appId: __OMNIKIT_APP_ID__,
|
|
2170
|
-
* serverUrl: __OMNIKIT_API_URL__,
|
|
2171
|
-
* apiKey: __OMNIKIT_API_KEY__,
|
|
2172
|
-
* });
|
|
2167
|
+
* import { createServerClient } from '@omnikit-ai/sdk';
|
|
2173
2168
|
*
|
|
2174
|
-
*
|
|
2175
|
-
*
|
|
2169
|
+
* Deno.serve(async (req) => {
|
|
2170
|
+
* const omnikit = createServerClient(req);
|
|
2171
|
+
*
|
|
2172
|
+
* // Fetch secret at runtime - secure, never in source code
|
|
2173
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
2174
|
+
* const stripe = new Stripe(stripeKey);
|
|
2175
|
+
*
|
|
2176
|
+
* // ... rest of function
|
|
2177
|
+
* });
|
|
2176
2178
|
* ```
|
|
2177
2179
|
*
|
|
2178
2180
|
* @param secretName - Name of the secret to retrieve
|
|
@@ -2231,7 +2233,7 @@ interface ServerRequest {
|
|
|
2231
2233
|
* // Access user data (user JWT auth)
|
|
2232
2234
|
* const currentUser = await omnikit.auth.me();
|
|
2233
2235
|
*
|
|
2234
|
-
* // Access connectors (requires
|
|
2236
|
+
* // Access connectors (requires API key)
|
|
2235
2237
|
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
2236
2238
|
*
|
|
2237
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
|
}
|
|
@@ -2689,21 +2676,24 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
2689
2676
|
/**
|
|
2690
2677
|
* Get a secret value at runtime (for backend functions).
|
|
2691
2678
|
*
|
|
2692
|
-
* This method securely fetches secrets from the Omnikit API
|
|
2693
|
-
*
|
|
2694
|
-
*
|
|
2679
|
+
* This method securely fetches secrets from the Omnikit API at runtime.
|
|
2680
|
+
* Secrets are NOT injected into function code - they are fetched via API
|
|
2681
|
+
* to ensure they cannot be leaked through source code, logs, or backups.
|
|
2695
2682
|
*
|
|
2696
2683
|
* @example
|
|
2697
2684
|
* ```typescript
|
|
2698
2685
|
* // In a backend function (Deno Edge Function)
|
|
2699
|
-
*
|
|
2700
|
-
* appId: __OMNIKIT_APP_ID__,
|
|
2701
|
-
* serverUrl: __OMNIKIT_API_URL__,
|
|
2702
|
-
* apiKey: __OMNIKIT_API_KEY__,
|
|
2703
|
-
* });
|
|
2686
|
+
* import { createServerClient } from '@omnikit-ai/sdk';
|
|
2704
2687
|
*
|
|
2705
|
-
*
|
|
2706
|
-
*
|
|
2688
|
+
* Deno.serve(async (req) => {
|
|
2689
|
+
* const omnikit = createServerClient(req);
|
|
2690
|
+
*
|
|
2691
|
+
* // Fetch secret at runtime - secure, never in source code
|
|
2692
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
2693
|
+
* const stripe = new Stripe(stripeKey);
|
|
2694
|
+
*
|
|
2695
|
+
* // ... rest of function
|
|
2696
|
+
* });
|
|
2707
2697
|
* ```
|
|
2708
2698
|
*
|
|
2709
2699
|
* @param secretName - Name of the secret to retrieve
|
|
@@ -2713,19 +2703,20 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
2713
2703
|
async getSecret(secretName) {
|
|
2714
2704
|
if (!this._apiKey) {
|
|
2715
2705
|
throw new OmnikitError(
|
|
2716
|
-
"API key
|
|
2706
|
+
"API key required. Use createServerClient(req) in backend functions.",
|
|
2717
2707
|
403,
|
|
2718
|
-
"
|
|
2708
|
+
"AUTH_REQUIRED"
|
|
2719
2709
|
);
|
|
2720
2710
|
}
|
|
2711
|
+
const headers = {
|
|
2712
|
+
"Content-Type": "application/json",
|
|
2713
|
+
"X-API-Key": this._apiKey
|
|
2714
|
+
};
|
|
2721
2715
|
const response = await fetch(
|
|
2722
2716
|
`${this.baseUrl}/apps/${this.appId}/secrets/${secretName}/value`,
|
|
2723
2717
|
{
|
|
2724
2718
|
method: "GET",
|
|
2725
|
-
headers
|
|
2726
|
-
"X-API-Key": this._apiKey,
|
|
2727
|
-
"Content-Type": "application/json"
|
|
2728
|
-
}
|
|
2719
|
+
headers
|
|
2729
2720
|
}
|
|
2730
2721
|
);
|
|
2731
2722
|
if (!response.ok) {
|
|
@@ -2752,12 +2743,12 @@ function createServerClient(request) {
|
|
|
2752
2743
|
};
|
|
2753
2744
|
const authHeader = getHeader("Authorization") || getHeader("authorization");
|
|
2754
2745
|
const userToken = authHeader?.startsWith("Bearer ") ? authHeader.slice(7) : null;
|
|
2755
|
-
const
|
|
2756
|
-
const appId = getHeader("X-Omnikit-App-Id") || getHeader("x-omnikit-app-id");
|
|
2757
|
-
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";
|
|
2758
2749
|
if (!appId) {
|
|
2759
2750
|
throw new OmnikitError(
|
|
2760
|
-
"
|
|
2751
|
+
"App ID not found. Ensure function is deployed through Omnikit platform (or X-Omnikit-App-Id header is set).",
|
|
2761
2752
|
400,
|
|
2762
2753
|
"MISSING_APP_ID"
|
|
2763
2754
|
);
|
|
@@ -2766,7 +2757,7 @@ function createServerClient(request) {
|
|
|
2766
2757
|
appId,
|
|
2767
2758
|
serverUrl,
|
|
2768
2759
|
token: userToken || void 0,
|
|
2769
|
-
|
|
2760
|
+
apiKey: apiKey || void 0,
|
|
2770
2761
|
autoInitAuth: false
|
|
2771
2762
|
// Don't auto-detect from localStorage in backend
|
|
2772
2763
|
});
|