@omnikit-ai/sdk 2.2.2 → 2.2.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
@@ -1719,7 +1719,7 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
1719
1719
  if (options.offset !== void 0) {
1720
1720
  queryParams.append("offset", String(options.offset));
1721
1721
  }
1722
- if (options.after !== void 0) {
1722
+ if (options.after) {
1723
1723
  queryParams.append("after", options.after);
1724
1724
  }
1725
1725
  }
@@ -2687,43 +2687,52 @@ Example: await ${collectionName}.list({ limit: 100, sort: '-created_at' })`,
2687
2687
  /**
2688
2688
  * Get a secret value at runtime (for backend functions).
2689
2689
  *
2690
- * This method securely fetches secrets from the Omnikit API using the app's API key.
2691
- * Use this in Supabase Edge Functions instead of storing secrets in Supabase's
2692
- * environment variables to ensure proper isolation between apps.
2690
+ * This method securely fetches secrets from the Omnikit API at runtime.
2691
+ * Secrets are NOT injected into function code - they are fetched via API
2692
+ * to ensure they cannot be leaked through source code, logs, or backups.
2693
2693
  *
2694
2694
  * @example
2695
2695
  * ```typescript
2696
2696
  * // In a backend function (Deno Edge Function)
2697
- * const omnikit = createClient({
2698
- * appId: __OMNIKIT_APP_ID__,
2699
- * serverUrl: __OMNIKIT_API_URL__,
2700
- * apiKey: __OMNIKIT_API_KEY__,
2701
- * });
2697
+ * import { createServerClient } from '@omnikit-ai/sdk';
2698
+ *
2699
+ * Deno.serve(async (req) => {
2700
+ * const omnikit = createServerClient(req);
2701
+ *
2702
+ * // Fetch secret at runtime - secure, never in source code
2703
+ * const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
2704
+ * const stripe = new Stripe(stripeKey);
2702
2705
  *
2703
- * const stripeKey = await omnikit.getSecret('STRIPE_SECRET_KEY');
2704
- * const stripe = new Stripe(stripeKey);
2706
+ * // ... rest of function
2707
+ * });
2705
2708
  * ```
2706
2709
  *
2707
2710
  * @param secretName - Name of the secret to retrieve
2708
2711
  * @returns The decrypted secret value
2709
- * @throws Error if the secret is not found or API key is invalid
2712
+ * @throws Error if the secret is not found or service token is invalid
2710
2713
  */
2711
2714
  async getSecret(secretName) {
2712
- if (!this._apiKey) {
2715
+ const authToken = this._serviceToken || this._apiKey;
2716
+ if (!authToken) {
2713
2717
  throw new OmnikitError(
2714
- "API key is required to fetch secrets. Provide apiKey in config.",
2718
+ "Service token required. Use createServerClient(req) in backend functions.",
2715
2719
  403,
2716
- "API_KEY_REQUIRED"
2720
+ "AUTH_REQUIRED"
2717
2721
  );
2718
2722
  }
2723
+ const headers = {
2724
+ "Content-Type": "application/json"
2725
+ };
2726
+ if (this._serviceToken) {
2727
+ headers["X-Service-Token"] = this._serviceToken;
2728
+ } else if (this._apiKey) {
2729
+ headers["X-API-Key"] = this._apiKey;
2730
+ }
2719
2731
  const response = await fetch(
2720
2732
  `${this.baseUrl}/apps/${this.appId}/secrets/${secretName}/value`,
2721
2733
  {
2722
2734
  method: "GET",
2723
- headers: {
2724
- "X-API-Key": this._apiKey,
2725
- "Content-Type": "application/json"
2726
- }
2735
+ headers
2727
2736
  }
2728
2737
  );
2729
2738
  if (!response.ok) {