@dealcrawl/sdk 2.7.0 → 2.9.0

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
@@ -473,12 +473,17 @@ async function request(ctx, path, options = {}) {
473
473
  currentController = null;
474
474
  };
475
475
  try {
476
+ const headers = {
477
+ "Content-Type": "application/json"
478
+ };
479
+ if (ctx.apiKey) {
480
+ headers["Authorization"] = `Bearer ${ctx.apiKey}`;
481
+ } else if (ctx.clientId) {
482
+ headers["X-Client-ID"] = ctx.clientId;
483
+ }
476
484
  const response = await fetch(url, {
477
485
  method,
478
- headers: {
479
- "Content-Type": "application/json",
480
- Authorization: `Bearer ${ctx.apiKey}`
481
- },
486
+ headers,
482
487
  body: body ? JSON.stringify(body) : void 0,
483
488
  signal: controller.signal
484
489
  });
@@ -2893,9 +2898,12 @@ var DealCrawl = class {
2893
2898
  *
2894
2899
  * @example
2895
2900
  * ```ts
2896
- * // Minimal config
2901
+ * // With API key
2897
2902
  * const client = new DealCrawl({ apiKey: "sk_xxx" });
2898
2903
  *
2904
+ * // With Client ID (for internal calls)
2905
+ * const client = new DealCrawl({ clientId: "uuid-xxx" });
2906
+ *
2899
2907
  * // Full config
2900
2908
  * const client = new DealCrawl({
2901
2909
  * apiKey: "sk_xxx",
@@ -2908,11 +2916,17 @@ var DealCrawl = class {
2908
2916
  * ```
2909
2917
  */
2910
2918
  constructor(config) {
2911
- if (!config.apiKey || !config.apiKey.trim()) {
2912
- throw new Error("API key is required");
2919
+ const hasApiKey = config.apiKey && config.apiKey.trim();
2920
+ const hasClientId = config.clientId && config.clientId.trim();
2921
+ if (!hasApiKey && !hasClientId) {
2922
+ throw new Error("Either API key or Client ID is required");
2923
+ }
2924
+ if (hasApiKey && hasClientId) {
2925
+ throw new Error("Provide either API key OR Client ID, not both");
2913
2926
  }
2914
2927
  this.ctx = {
2915
2928
  apiKey: config.apiKey,
2929
+ clientId: config.clientId,
2916
2930
  baseUrl: config.baseUrl ?? DEFAULT_CONFIG.baseUrl,
2917
2931
  timeout: config.timeout ?? DEFAULT_CONFIG.timeout,
2918
2932
  maxRetries: config.maxRetries ?? DEFAULT_CONFIG.maxRetries,