@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.mjs CHANGED
@@ -2075,6 +2075,59 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2075
2075
  }
2076
2076
  return response;
2077
2077
  }
2078
+ /**
2079
+ * Get a secret value at runtime (for backend functions).
2080
+ *
2081
+ * This method securely fetches secrets from the Omnikit API using the app's API key.
2082
+ * Use this in Supabase Edge Functions instead of storing secrets in Supabase's
2083
+ * environment variables to ensure proper isolation between apps.
2084
+ *
2085
+ * @example
2086
+ * ```typescript
2087
+ * // In a backend function (Deno Edge Function)
2088
+ * const omnikit = createClient({
2089
+ * appId: __OMNIKIT_APP_ID__,
2090
+ * serverUrl: __OMNIKIT_API_URL__,
2091
+ * apiKey: __OMNIKIT_API_KEY__,
2092
+ * });
2093
+ *
2094
+ * const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
2095
+ * const stripe = new Stripe(stripeKey);
2096
+ * ```
2097
+ *
2098
+ * @param secretName - Name of the secret to retrieve
2099
+ * @returns The decrypted secret value
2100
+ * @throws Error if the secret is not found or API key is invalid
2101
+ */
2102
+ async getSecret(secretName) {
2103
+ if (!this._apiKey) {
2104
+ throw new OmnikitError(
2105
+ "API key is required to fetch secrets. Provide apiKey in config.",
2106
+ 403,
2107
+ "API_KEY_REQUIRED"
2108
+ );
2109
+ }
2110
+ const response = await fetch(
2111
+ `${this.baseUrl}/apps/${this.appId}/secrets/${secretName}/value`,
2112
+ {
2113
+ method: "GET",
2114
+ headers: {
2115
+ "X-API-Key": this._apiKey,
2116
+ "Content-Type": "application/json"
2117
+ }
2118
+ }
2119
+ );
2120
+ if (!response.ok) {
2121
+ const error = await response.json().catch(() => ({}));
2122
+ throw new OmnikitError(
2123
+ error.detail || `Failed to fetch secret: ${response.statusText}`,
2124
+ response.status,
2125
+ "SECRET_FETCH_FAILED"
2126
+ );
2127
+ }
2128
+ const data = await response.json();
2129
+ return data.value;
2130
+ }
2078
2131
  };
2079
2132
  function createClient(config) {
2080
2133
  return new APIClient(config);