@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.mjs
CHANGED
|
@@ -1146,15 +1146,57 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1146
1146
|
return client.streamLLMResponse(params);
|
|
1147
1147
|
}
|
|
1148
1148
|
}
|
|
1149
|
+
let response;
|
|
1149
1150
|
const method = client._services[serviceName];
|
|
1150
|
-
if (
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
"
|
|
1151
|
+
if (method) {
|
|
1152
|
+
response = await method(params, useServiceToken);
|
|
1153
|
+
} else {
|
|
1154
|
+
const servicePathMap = {
|
|
1155
|
+
"SendEmail": "email/send",
|
|
1156
|
+
"InvokeLLM": "llm/invoke",
|
|
1157
|
+
"GenerateImage": "image/generate",
|
|
1158
|
+
"GenerateSpeech": "speech/generate",
|
|
1159
|
+
"GenerateVideo": "video/generate",
|
|
1160
|
+
"ExtractData": "extract/data",
|
|
1161
|
+
"SendSMS": "sms/send",
|
|
1162
|
+
"UploadFile": "storage/upload",
|
|
1163
|
+
"UploadPrivateFile": "storage/upload-private",
|
|
1164
|
+
"CreateFileSignedUrl": "storage/signed-url"
|
|
1165
|
+
};
|
|
1166
|
+
const servicePath = servicePathMap[serviceName];
|
|
1167
|
+
if (!servicePath) {
|
|
1168
|
+
throw new OmnikitError(
|
|
1169
|
+
`Service '${serviceName}' not found. Known services: ${Object.keys(servicePathMap).join(", ")}`,
|
|
1170
|
+
404,
|
|
1171
|
+
"SERVICE_NOT_FOUND"
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
const headers = {
|
|
1175
|
+
"Content-Type": "application/json"
|
|
1176
|
+
};
|
|
1177
|
+
if (client._apiKey) {
|
|
1178
|
+
headers["X-API-Key"] = client._apiKey;
|
|
1179
|
+
} else if (client.userToken) {
|
|
1180
|
+
headers["Authorization"] = `Bearer ${client.userToken}`;
|
|
1181
|
+
}
|
|
1182
|
+
const fetchResponse = await fetch(
|
|
1183
|
+
`${client.baseUrl}/apps/${client.appId}/integrations/${servicePath}`,
|
|
1184
|
+
{
|
|
1185
|
+
method: "POST",
|
|
1186
|
+
headers,
|
|
1187
|
+
body: JSON.stringify(params || {})
|
|
1188
|
+
}
|
|
1155
1189
|
);
|
|
1190
|
+
if (!fetchResponse.ok) {
|
|
1191
|
+
const error = await fetchResponse.json().catch(() => ({}));
|
|
1192
|
+
throw new OmnikitError(
|
|
1193
|
+
error.detail || `Service call failed: ${fetchResponse.statusText}`,
|
|
1194
|
+
fetchResponse.status,
|
|
1195
|
+
"SERVICE_CALL_FAILED"
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
response = await fetchResponse.json();
|
|
1156
1199
|
}
|
|
1157
|
-
const response = await method(params, useServiceToken);
|
|
1158
1200
|
if (response && response.async && response.job_id) {
|
|
1159
1201
|
if (asyncOptions?.returnJobId) {
|
|
1160
1202
|
return response;
|
|
@@ -1251,16 +1293,14 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1251
1293
|
this.initPromise = null;
|
|
1252
1294
|
}
|
|
1253
1295
|
/**
|
|
1254
|
-
* Initialize SDK by fetching app schema and
|
|
1296
|
+
* Initialize SDK by fetching app schema (for collections and metadata)
|
|
1297
|
+
* Services use static mappings - no schema fetch needed
|
|
1255
1298
|
* This happens automatically on first use - no need to call explicitly
|
|
1256
1299
|
*/
|
|
1257
1300
|
async initialize() {
|
|
1258
1301
|
if (this.initialized) return;
|
|
1259
1302
|
try {
|
|
1260
|
-
const
|
|
1261
|
-
this.fetchAppSchema(),
|
|
1262
|
-
this.fetchIntegrationSchema()
|
|
1263
|
-
]);
|
|
1303
|
+
const appSchema = await this.fetchAppSchema();
|
|
1264
1304
|
if (appSchema.app) {
|
|
1265
1305
|
this.updateMetadataCache({
|
|
1266
1306
|
name: appSchema.app.name,
|
|
@@ -1273,11 +1313,6 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
1273
1313
|
if (appSchema.entities) {
|
|
1274
1314
|
this.createCollections(appSchema.entities);
|
|
1275
1315
|
}
|
|
1276
|
-
if (integrationSchema && "services" in integrationSchema) {
|
|
1277
|
-
this.createServicesFromSchema(integrationSchema);
|
|
1278
|
-
} else if (integrationSchema && "installed_packages" in integrationSchema) {
|
|
1279
|
-
this.createIntegrationsFromSchema(integrationSchema);
|
|
1280
|
-
}
|
|
1281
1316
|
this.initialized = true;
|
|
1282
1317
|
} catch (error) {
|
|
1283
1318
|
console.error("Failed to initialize Omnikit SDK:", error);
|
|
@@ -2075,6 +2110,59 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
2075
2110
|
}
|
|
2076
2111
|
return response;
|
|
2077
2112
|
}
|
|
2113
|
+
/**
|
|
2114
|
+
* Get a secret value at runtime (for backend functions).
|
|
2115
|
+
*
|
|
2116
|
+
* This method securely fetches secrets from the Omnikit API using the app's API key.
|
|
2117
|
+
* Use this in Supabase Edge Functions instead of storing secrets in Supabase's
|
|
2118
|
+
* environment variables to ensure proper isolation between apps.
|
|
2119
|
+
*
|
|
2120
|
+
* @example
|
|
2121
|
+
* ```typescript
|
|
2122
|
+
* // In a backend function (Deno Edge Function)
|
|
2123
|
+
* const omnikit = createClient({
|
|
2124
|
+
* appId: __OMNIKIT_APP_ID__,
|
|
2125
|
+
* serverUrl: __OMNIKIT_API_URL__,
|
|
2126
|
+
* apiKey: __OMNIKIT_API_KEY__,
|
|
2127
|
+
* });
|
|
2128
|
+
*
|
|
2129
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
2130
|
+
* const stripe = new Stripe(stripeKey);
|
|
2131
|
+
* ```
|
|
2132
|
+
*
|
|
2133
|
+
* @param secretName - Name of the secret to retrieve
|
|
2134
|
+
* @returns The decrypted secret value
|
|
2135
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
2136
|
+
*/
|
|
2137
|
+
async getSecret(secretName) {
|
|
2138
|
+
if (!this._apiKey) {
|
|
2139
|
+
throw new OmnikitError(
|
|
2140
|
+
"API key is required to fetch secrets. Provide apiKey in config.",
|
|
2141
|
+
403,
|
|
2142
|
+
"API_KEY_REQUIRED"
|
|
2143
|
+
);
|
|
2144
|
+
}
|
|
2145
|
+
const response = await fetch(
|
|
2146
|
+
`${this.baseUrl}/apps/${this.appId}/secrets/${secretName}/value`,
|
|
2147
|
+
{
|
|
2148
|
+
method: "GET",
|
|
2149
|
+
headers: {
|
|
2150
|
+
"X-API-Key": this._apiKey,
|
|
2151
|
+
"Content-Type": "application/json"
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
);
|
|
2155
|
+
if (!response.ok) {
|
|
2156
|
+
const error = await response.json().catch(() => ({}));
|
|
2157
|
+
throw new OmnikitError(
|
|
2158
|
+
error.detail || `Failed to fetch secret: ${response.statusText}`,
|
|
2159
|
+
response.status,
|
|
2160
|
+
"SECRET_FETCH_FAILED"
|
|
2161
|
+
);
|
|
2162
|
+
}
|
|
2163
|
+
const data = await response.json();
|
|
2164
|
+
return data.value;
|
|
2165
|
+
}
|
|
2078
2166
|
};
|
|
2079
2167
|
function createClient(config) {
|
|
2080
2168
|
return new APIClient(config);
|