@omnikit-ai/sdk 2.0.3 → 2.0.4
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 +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -0
- 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
|
|
@@ -1369,6 +1387,31 @@ declare class APIClient implements OmnikitClient {
|
|
|
1369
1387
|
* @throws Error if the function invocation fails
|
|
1370
1388
|
*/
|
|
1371
1389
|
invokeFunction(functionName: string, body?: Record<string, any>): Promise<any>;
|
|
1390
|
+
/**
|
|
1391
|
+
* Get a secret value at runtime (for backend functions).
|
|
1392
|
+
*
|
|
1393
|
+
* This method securely fetches secrets from the Omnikit API using the app's API key.
|
|
1394
|
+
* Use this in Supabase Edge Functions instead of storing secrets in Supabase's
|
|
1395
|
+
* environment variables to ensure proper isolation between apps.
|
|
1396
|
+
*
|
|
1397
|
+
* @example
|
|
1398
|
+
* ```typescript
|
|
1399
|
+
* // In a backend function (Deno Edge Function)
|
|
1400
|
+
* const omnikit = createClient({
|
|
1401
|
+
* appId: __OMNIKIT_APP_ID__,
|
|
1402
|
+
* serverUrl: __OMNIKIT_API_URL__,
|
|
1403
|
+
* apiKey: __OMNIKIT_API_KEY__,
|
|
1404
|
+
* });
|
|
1405
|
+
*
|
|
1406
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
1407
|
+
* const stripe = new Stripe(stripeKey);
|
|
1408
|
+
* ```
|
|
1409
|
+
*
|
|
1410
|
+
* @param secretName - Name of the secret to retrieve
|
|
1411
|
+
* @returns The decrypted secret value
|
|
1412
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
1413
|
+
*/
|
|
1414
|
+
getSecret(secretName: string): Promise<string>;
|
|
1372
1415
|
}
|
|
1373
1416
|
/**
|
|
1374
1417
|
* 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
|
|
@@ -1369,6 +1387,31 @@ declare class APIClient implements OmnikitClient {
|
|
|
1369
1387
|
* @throws Error if the function invocation fails
|
|
1370
1388
|
*/
|
|
1371
1389
|
invokeFunction(functionName: string, body?: Record<string, any>): Promise<any>;
|
|
1390
|
+
/**
|
|
1391
|
+
* Get a secret value at runtime (for backend functions).
|
|
1392
|
+
*
|
|
1393
|
+
* This method securely fetches secrets from the Omnikit API using the app's API key.
|
|
1394
|
+
* Use this in Supabase Edge Functions instead of storing secrets in Supabase's
|
|
1395
|
+
* environment variables to ensure proper isolation between apps.
|
|
1396
|
+
*
|
|
1397
|
+
* @example
|
|
1398
|
+
* ```typescript
|
|
1399
|
+
* // In a backend function (Deno Edge Function)
|
|
1400
|
+
* const omnikit = createClient({
|
|
1401
|
+
* appId: __OMNIKIT_APP_ID__,
|
|
1402
|
+
* serverUrl: __OMNIKIT_API_URL__,
|
|
1403
|
+
* apiKey: __OMNIKIT_API_KEY__,
|
|
1404
|
+
* });
|
|
1405
|
+
*
|
|
1406
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
1407
|
+
* const stripe = new Stripe(stripeKey);
|
|
1408
|
+
* ```
|
|
1409
|
+
*
|
|
1410
|
+
* @param secretName - Name of the secret to retrieve
|
|
1411
|
+
* @returns The decrypted secret value
|
|
1412
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
1413
|
+
*/
|
|
1414
|
+
getSecret(secretName: string): Promise<string>;
|
|
1372
1415
|
}
|
|
1373
1416
|
/**
|
|
1374
1417
|
* Factory function to create an Omnikit client
|
package/dist/index.js
CHANGED
|
@@ -2077,6 +2077,59 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
|
|
|
2077
2077
|
}
|
|
2078
2078
|
return response;
|
|
2079
2079
|
}
|
|
2080
|
+
/**
|
|
2081
|
+
* Get a secret value at runtime (for backend functions).
|
|
2082
|
+
*
|
|
2083
|
+
* This method securely fetches secrets from the Omnikit API using the app's API key.
|
|
2084
|
+
* Use this in Supabase Edge Functions instead of storing secrets in Supabase's
|
|
2085
|
+
* environment variables to ensure proper isolation between apps.
|
|
2086
|
+
*
|
|
2087
|
+
* @example
|
|
2088
|
+
* ```typescript
|
|
2089
|
+
* // In a backend function (Deno Edge Function)
|
|
2090
|
+
* const omnikit = createClient({
|
|
2091
|
+
* appId: __OMNIKIT_APP_ID__,
|
|
2092
|
+
* serverUrl: __OMNIKIT_API_URL__,
|
|
2093
|
+
* apiKey: __OMNIKIT_API_KEY__,
|
|
2094
|
+
* });
|
|
2095
|
+
*
|
|
2096
|
+
* const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
|
|
2097
|
+
* const stripe = new Stripe(stripeKey);
|
|
2098
|
+
* ```
|
|
2099
|
+
*
|
|
2100
|
+
* @param secretName - Name of the secret to retrieve
|
|
2101
|
+
* @returns The decrypted secret value
|
|
2102
|
+
* @throws Error if the secret is not found or API key is invalid
|
|
2103
|
+
*/
|
|
2104
|
+
async getSecret(secretName) {
|
|
2105
|
+
if (!this._apiKey) {
|
|
2106
|
+
throw new OmnikitError(
|
|
2107
|
+
"API key is required to fetch secrets. Provide apiKey in config.",
|
|
2108
|
+
403,
|
|
2109
|
+
"API_KEY_REQUIRED"
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
const response = await fetch(
|
|
2113
|
+
`${this.baseUrl}/apps/${this.appId}/secrets/${secretName}/value`,
|
|
2114
|
+
{
|
|
2115
|
+
method: "GET",
|
|
2116
|
+
headers: {
|
|
2117
|
+
"X-API-Key": this._apiKey,
|
|
2118
|
+
"Content-Type": "application/json"
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
);
|
|
2122
|
+
if (!response.ok) {
|
|
2123
|
+
const error = await response.json().catch(() => ({}));
|
|
2124
|
+
throw new OmnikitError(
|
|
2125
|
+
error.detail || `Failed to fetch secret: ${response.statusText}`,
|
|
2126
|
+
response.status,
|
|
2127
|
+
"SECRET_FETCH_FAILED"
|
|
2128
|
+
);
|
|
2129
|
+
}
|
|
2130
|
+
const data = await response.json();
|
|
2131
|
+
return data.value;
|
|
2132
|
+
}
|
|
2080
2133
|
};
|
|
2081
2134
|
function createClient(config) {
|
|
2082
2135
|
return new APIClient(config);
|