@omnikit-ai/sdk 2.0.3 → 2.0.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 +45 -1
- package/dist/index.d.ts +45 -1
- package/dist/index.js +104 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -884,6 +884,24 @@ interface OmnikitClient {
|
|
|
884
884
|
* @returns Response from the function
|
|
885
885
|
*/
|
|
886
886
|
invokeFunction(functionName: string, body?: Record<string, any>): Promise<any>;
|
|
887
|
+
/**
|
|
888
|
+
* Get a secret value at runtime (for backend functions).
|
|
889
|
+
*
|
|
890
|
+
* This method securely fetches secrets from the Omnikit API using the app's API key.
|
|
891
|
+
* Use this in Supabase Edge Functions instead of storing secrets in Supabase's
|
|
892
|
+
* environment variables to ensure proper isolation between apps.
|
|
893
|
+
*
|
|
894
|
+
* @example
|
|
895
|
+
* ```typescript
|
|
896
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
897
|
+
* const stripe = new Stripe(stripeKey);
|
|
898
|
+
* ```
|
|
899
|
+
*
|
|
900
|
+
* @param secretName - Name of the secret to retrieve
|
|
901
|
+
* @returns The decrypted secret value
|
|
902
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
903
|
+
*/
|
|
904
|
+
getSecret(secretName: string): Promise<string>;
|
|
887
905
|
}
|
|
888
906
|
/**
|
|
889
907
|
* Request options for makeRequest
|
|
@@ -1244,7 +1262,8 @@ declare class APIClient implements OmnikitClient {
|
|
|
1244
1262
|
*/
|
|
1245
1263
|
ensureInitialized(): Promise<void>;
|
|
1246
1264
|
/**
|
|
1247
|
-
* Initialize SDK by fetching app schema and
|
|
1265
|
+
* Initialize SDK by fetching app schema (for collections and metadata)
|
|
1266
|
+
* Services use static mappings - no schema fetch needed
|
|
1248
1267
|
* This happens automatically on first use - no need to call explicitly
|
|
1249
1268
|
*/
|
|
1250
1269
|
private initialize;
|
|
@@ -1369,6 +1388,31 @@ declare class APIClient implements OmnikitClient {
|
|
|
1369
1388
|
* @throws Error if the function invocation fails
|
|
1370
1389
|
*/
|
|
1371
1390
|
invokeFunction(functionName: string, body?: Record<string, any>): Promise<any>;
|
|
1391
|
+
/**
|
|
1392
|
+
* Get a secret value at runtime (for backend functions).
|
|
1393
|
+
*
|
|
1394
|
+
* This method securely fetches secrets from the Omnikit API using the app's API key.
|
|
1395
|
+
* Use this in Supabase Edge Functions instead of storing secrets in Supabase's
|
|
1396
|
+
* environment variables to ensure proper isolation between apps.
|
|
1397
|
+
*
|
|
1398
|
+
* @example
|
|
1399
|
+
* ```typescript
|
|
1400
|
+
* // In a backend function (Deno Edge Function)
|
|
1401
|
+
* const omnikit = createClient({
|
|
1402
|
+
* appId: __OMNIKIT_APP_ID__,
|
|
1403
|
+
* serverUrl: __OMNIKIT_API_URL__,
|
|
1404
|
+
* apiKey: __OMNIKIT_API_KEY__,
|
|
1405
|
+
* });
|
|
1406
|
+
*
|
|
1407
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
1408
|
+
* const stripe = new Stripe(stripeKey);
|
|
1409
|
+
* ```
|
|
1410
|
+
*
|
|
1411
|
+
* @param secretName - Name of the secret to retrieve
|
|
1412
|
+
* @returns The decrypted secret value
|
|
1413
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
1414
|
+
*/
|
|
1415
|
+
getSecret(secretName: string): Promise<string>;
|
|
1372
1416
|
}
|
|
1373
1417
|
/**
|
|
1374
1418
|
* Factory function to create an Omnikit client
|
package/dist/index.d.ts
CHANGED
|
@@ -884,6 +884,24 @@ interface OmnikitClient {
|
|
|
884
884
|
* @returns Response from the function
|
|
885
885
|
*/
|
|
886
886
|
invokeFunction(functionName: string, body?: Record<string, any>): Promise<any>;
|
|
887
|
+
/**
|
|
888
|
+
* Get a secret value at runtime (for backend functions).
|
|
889
|
+
*
|
|
890
|
+
* This method securely fetches secrets from the Omnikit API using the app's API key.
|
|
891
|
+
* Use this in Supabase Edge Functions instead of storing secrets in Supabase's
|
|
892
|
+
* environment variables to ensure proper isolation between apps.
|
|
893
|
+
*
|
|
894
|
+
* @example
|
|
895
|
+
* ```typescript
|
|
896
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
897
|
+
* const stripe = new Stripe(stripeKey);
|
|
898
|
+
* ```
|
|
899
|
+
*
|
|
900
|
+
* @param secretName - Name of the secret to retrieve
|
|
901
|
+
* @returns The decrypted secret value
|
|
902
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
903
|
+
*/
|
|
904
|
+
getSecret(secretName: string): Promise<string>;
|
|
887
905
|
}
|
|
888
906
|
/**
|
|
889
907
|
* Request options for makeRequest
|
|
@@ -1244,7 +1262,8 @@ declare class APIClient implements OmnikitClient {
|
|
|
1244
1262
|
*/
|
|
1245
1263
|
ensureInitialized(): Promise<void>;
|
|
1246
1264
|
/**
|
|
1247
|
-
* Initialize SDK by fetching app schema and
|
|
1265
|
+
* Initialize SDK by fetching app schema (for collections and metadata)
|
|
1266
|
+
* Services use static mappings - no schema fetch needed
|
|
1248
1267
|
* This happens automatically on first use - no need to call explicitly
|
|
1249
1268
|
*/
|
|
1250
1269
|
private initialize;
|
|
@@ -1369,6 +1388,31 @@ declare class APIClient implements OmnikitClient {
|
|
|
1369
1388
|
* @throws Error if the function invocation fails
|
|
1370
1389
|
*/
|
|
1371
1390
|
invokeFunction(functionName: string, body?: Record<string, any>): Promise<any>;
|
|
1391
|
+
/**
|
|
1392
|
+
* Get a secret value at runtime (for backend functions).
|
|
1393
|
+
*
|
|
1394
|
+
* This method securely fetches secrets from the Omnikit API using the app's API key.
|
|
1395
|
+
* Use this in Supabase Edge Functions instead of storing secrets in Supabase's
|
|
1396
|
+
* environment variables to ensure proper isolation between apps.
|
|
1397
|
+
*
|
|
1398
|
+
* @example
|
|
1399
|
+
* ```typescript
|
|
1400
|
+
* // In a backend function (Deno Edge Function)
|
|
1401
|
+
* const omnikit = createClient({
|
|
1402
|
+
* appId: __OMNIKIT_APP_ID__,
|
|
1403
|
+
* serverUrl: __OMNIKIT_API_URL__,
|
|
1404
|
+
* apiKey: __OMNIKIT_API_KEY__,
|
|
1405
|
+
* });
|
|
1406
|
+
*
|
|
1407
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
1408
|
+
* const stripe = new Stripe(stripeKey);
|
|
1409
|
+
* ```
|
|
1410
|
+
*
|
|
1411
|
+
* @param secretName - Name of the secret to retrieve
|
|
1412
|
+
* @returns The decrypted secret value
|
|
1413
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
1414
|
+
*/
|
|
1415
|
+
getSecret(secretName: string): Promise<string>;
|
|
1372
1416
|
}
|
|
1373
1417
|
/**
|
|
1374
1418
|
* Factory function to create an Omnikit client
|
package/dist/index.js
CHANGED
|
@@ -1148,15 +1148,57 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1148
1148
|
return client.streamLLMResponse(params);
|
|
1149
1149
|
}
|
|
1150
1150
|
}
|
|
1151
|
+
let response;
|
|
1151
1152
|
const method = client._services[serviceName];
|
|
1152
|
-
if (
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
"
|
|
1153
|
+
if (method) {
|
|
1154
|
+
response = await method(params, useServiceToken);
|
|
1155
|
+
} else {
|
|
1156
|
+
const servicePathMap = {
|
|
1157
|
+
"SendEmail": "email/send",
|
|
1158
|
+
"InvokeLLM": "llm/invoke",
|
|
1159
|
+
"GenerateImage": "image/generate",
|
|
1160
|
+
"GenerateSpeech": "speech/generate",
|
|
1161
|
+
"GenerateVideo": "video/generate",
|
|
1162
|
+
"ExtractData": "extract/data",
|
|
1163
|
+
"SendSMS": "sms/send",
|
|
1164
|
+
"UploadFile": "storage/upload",
|
|
1165
|
+
"UploadPrivateFile": "storage/upload-private",
|
|
1166
|
+
"CreateFileSignedUrl": "storage/signed-url"
|
|
1167
|
+
};
|
|
1168
|
+
const servicePath = servicePathMap[serviceName];
|
|
1169
|
+
if (!servicePath) {
|
|
1170
|
+
throw new OmnikitError(
|
|
1171
|
+
`Service '${serviceName}' not found. Known services: ${Object.keys(servicePathMap).join(", ")}`,
|
|
1172
|
+
404,
|
|
1173
|
+
"SERVICE_NOT_FOUND"
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
const headers = {
|
|
1177
|
+
"Content-Type": "application/json"
|
|
1178
|
+
};
|
|
1179
|
+
if (client._apiKey) {
|
|
1180
|
+
headers["X-API-Key"] = client._apiKey;
|
|
1181
|
+
} else if (client.userToken) {
|
|
1182
|
+
headers["Authorization"] = `Bearer ${client.userToken}`;
|
|
1183
|
+
}
|
|
1184
|
+
const fetchResponse = await fetch(
|
|
1185
|
+
`${client.baseUrl}/apps/${client.appId}/integrations/${servicePath}`,
|
|
1186
|
+
{
|
|
1187
|
+
method: "POST",
|
|
1188
|
+
headers,
|
|
1189
|
+
body: JSON.stringify(params || {})
|
|
1190
|
+
}
|
|
1157
1191
|
);
|
|
1192
|
+
if (!fetchResponse.ok) {
|
|
1193
|
+
const error = await fetchResponse.json().catch(() => ({}));
|
|
1194
|
+
throw new OmnikitError(
|
|
1195
|
+
error.detail || `Service call failed: ${fetchResponse.statusText}`,
|
|
1196
|
+
fetchResponse.status,
|
|
1197
|
+
"SERVICE_CALL_FAILED"
|
|
1198
|
+
);
|
|
1199
|
+
}
|
|
1200
|
+
response = await fetchResponse.json();
|
|
1158
1201
|
}
|
|
1159
|
-
const response = await method(params, useServiceToken);
|
|
1160
1202
|
if (response && response.async && response.job_id) {
|
|
1161
1203
|
if (asyncOptions?.returnJobId) {
|
|
1162
1204
|
return response;
|
|
@@ -1253,16 +1295,14 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1253
1295
|
this.initPromise = null;
|
|
1254
1296
|
}
|
|
1255
1297
|
/**
|
|
1256
|
-
* Initialize SDK by fetching app schema and
|
|
1298
|
+
* Initialize SDK by fetching app schema (for collections and metadata)
|
|
1299
|
+
* Services use static mappings - no schema fetch needed
|
|
1257
1300
|
* This happens automatically on first use - no need to call explicitly
|
|
1258
1301
|
*/
|
|
1259
1302
|
async initialize() {
|
|
1260
1303
|
if (this.initialized) return;
|
|
1261
1304
|
try {
|
|
1262
|
-
const
|
|
1263
|
-
this.fetchAppSchema(),
|
|
1264
|
-
this.fetchIntegrationSchema()
|
|
1265
|
-
]);
|
|
1305
|
+
const appSchema = await this.fetchAppSchema();
|
|
1266
1306
|
if (appSchema.app) {
|
|
1267
1307
|
this.updateMetadataCache({
|
|
1268
1308
|
name: appSchema.app.name,
|
|
@@ -1275,11 +1315,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1275
1315
|
if (appSchema.entities) {
|
|
1276
1316
|
this.createCollections(appSchema.entities);
|
|
1277
1317
|
}
|
|
1278
|
-
if (integrationSchema && "services" in integrationSchema) {
|
|
1279
|
-
this.createServicesFromSchema(integrationSchema);
|
|
1280
|
-
} else if (integrationSchema && "installed_packages" in integrationSchema) {
|
|
1281
|
-
this.createIntegrationsFromSchema(integrationSchema);
|
|
1282
|
-
}
|
|
1283
1318
|
this.initialized = true;
|
|
1284
1319
|
} catch (error) {
|
|
1285
1320
|
console.error("Failed to initialize Omnikit SDK:", error);
|
|
@@ -2077,6 +2112,59 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
2077
2112
|
}
|
|
2078
2113
|
return response;
|
|
2079
2114
|
}
|
|
2115
|
+
/**
|
|
2116
|
+
* Get a secret value at runtime (for backend functions).
|
|
2117
|
+
*
|
|
2118
|
+
* This method securely fetches secrets from the Omnikit API using the app's API key.
|
|
2119
|
+
* Use this in Supabase Edge Functions instead of storing secrets in Supabase's
|
|
2120
|
+
* environment variables to ensure proper isolation between apps.
|
|
2121
|
+
*
|
|
2122
|
+
* @example
|
|
2123
|
+
* ```typescript
|
|
2124
|
+
* // In a backend function (Deno Edge Function)
|
|
2125
|
+
* const omnikit = createClient({
|
|
2126
|
+
* appId: __OMNIKIT_APP_ID__,
|
|
2127
|
+
* serverUrl: __OMNIKIT_API_URL__,
|
|
2128
|
+
* apiKey: __OMNIKIT_API_KEY__,
|
|
2129
|
+
* });
|
|
2130
|
+
*
|
|
2131
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
2132
|
+
* const stripe = new Stripe(stripeKey);
|
|
2133
|
+
* ```
|
|
2134
|
+
*
|
|
2135
|
+
* @param secretName - Name of the secret to retrieve
|
|
2136
|
+
* @returns The decrypted secret value
|
|
2137
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
2138
|
+
*/
|
|
2139
|
+
async getSecret(secretName) {
|
|
2140
|
+
if (!this._apiKey) {
|
|
2141
|
+
throw new OmnikitError(
|
|
2142
|
+
"API key is required to fetch secrets. Provide apiKey in config.",
|
|
2143
|
+
403,
|
|
2144
|
+
"API_KEY_REQUIRED"
|
|
2145
|
+
);
|
|
2146
|
+
}
|
|
2147
|
+
const response = await fetch(
|
|
2148
|
+
`${this.baseUrl}/apps/${this.appId}/secrets/${secretName}/value`,
|
|
2149
|
+
{
|
|
2150
|
+
method: "GET",
|
|
2151
|
+
headers: {
|
|
2152
|
+
"X-API-Key": this._apiKey,
|
|
2153
|
+
"Content-Type": "application/json"
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
);
|
|
2157
|
+
if (!response.ok) {
|
|
2158
|
+
const error = await response.json().catch(() => ({}));
|
|
2159
|
+
throw new OmnikitError(
|
|
2160
|
+
error.detail || `Failed to fetch secret: ${response.statusText}`,
|
|
2161
|
+
response.status,
|
|
2162
|
+
"SECRET_FETCH_FAILED"
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
const data = await response.json();
|
|
2166
|
+
return data.value;
|
|
2167
|
+
}
|
|
2080
2168
|
};
|
|
2081
2169
|
function createClient(config) {
|
|
2082
2170
|
return new APIClient(config);
|