@land-catalyst/batch-data-sdk 1.3.0 → 1.3.1

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.
@@ -2276,7 +2276,9 @@ class PropertySubscriptionBuilder extends RequestWithSearchCriteriaBuilder {
2276
2276
  static from(request) {
2277
2277
  const builder = new PropertySubscriptionBuilder();
2278
2278
  builder.searchCriteria(request.searchCriteria);
2279
- builder.deliveryConfig(request.deliveryConfig);
2279
+ if (request.deliveryConfig) {
2280
+ builder.deliveryConfig(request.deliveryConfig);
2281
+ }
2280
2282
  if (request.options) {
2281
2283
  builder.options(request.options);
2282
2284
  }
@@ -2297,12 +2299,11 @@ class PropertySubscriptionBuilder extends RequestWithSearchCriteriaBuilder {
2297
2299
  }
2298
2300
  build() {
2299
2301
  this.validateSearchCriteria();
2300
- if (!this.criteria.deliveryConfig) {
2301
- throw new Error("Delivery configuration is required");
2302
- }
2303
2302
  const request = {
2304
2303
  searchCriteria: this.criteria.searchCriteria,
2305
- deliveryConfig: this.criteria.deliveryConfig,
2304
+ ...(this.criteria.deliveryConfig && {
2305
+ deliveryConfig: this.criteria.deliveryConfig,
2306
+ }),
2306
2307
  };
2307
2308
  return this.buildOptionsIntoRequest(request);
2308
2309
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosInstance, AxiosResponse, AxiosError, InternalAxiosRequestConfig } from "axios";
2
2
  import { IBatchDataClient } from "./client.interface";
3
3
  import { ILogger } from "../core/logger.interface";
4
- import { PropertySubscriptionRequest, PropertySubscriptionResponse, PropertyCountRequest, PropertySearchRequest, PropertySearchResponse, PropertyLookupOptions, AddressVerifyRequest, AddressVerifyResponse, AddressAutocompleteRequest, AddressAutocompleteResponse, AddressGeocodeRequest, AddressGeocodeResponse, AddressReverseGeocodeRequest, AddressReverseGeocodeResponse, PropertyLookupRequest, PropertyLookupResponse, PropertyLookupAsyncRequest, PropertyLookupAsyncResponse, PropertySearchAsyncRequest, PropertySearchAsyncResponse, PropertySkipTraceRequest, PropertySkipTraceResponse, PropertySkipTraceAsyncRequest, PropertySkipTraceAsyncResponse, PhoneVerificationRequest, PhoneVerificationResponse, PhoneVerificationAsyncRequest, PhoneVerificationAsyncResponse, PhoneDNCRequest, PhoneDNCResponse, PhoneDNCAsyncRequest, PhoneDNCAsyncResponse, PhoneTCPARequest, PhoneTCPAResponse, PhoneTCPAAsyncRequest, PhoneTCPAAsyncResponse, GetPropertySubscriptionsResponse, GetPropertySubscriptionDetailResponse, DeletePropertySubscriptionResponse, PropertyPermitRequest, PropertyPermitResponse, PropertySkipTraceV3Request, PropertySkipTraceV3Response, PropertySkipTraceV3AsyncRequest, PropertySkipTraceV3AsyncResponse } from "../core/types";
4
+ import { PropertySubscriptionRequest, PropertySubscriptionResponse, PropertyCountRequest, PropertySearchRequest, PropertySearchResponse, PropertyLookupOptions, AddressVerifyRequest, AddressVerifyResponse, AddressAutocompleteRequest, AddressAutocompleteResponse, AddressGeocodeRequest, AddressGeocodeResponse, AddressReverseGeocodeRequest, AddressReverseGeocodeResponse, PropertyLookupRequest, PropertyLookupResponse, PropertyLookupAsyncRequest, PropertyLookupAsyncResponse, PropertySearchAsyncRequest, PropertySearchAsyncResponse, PropertySkipTraceRequest, PropertySkipTraceResponse, PropertySkipTraceAsyncRequest, PropertySkipTraceAsyncResponse, PhoneVerificationRequest, PhoneVerificationResponse, PhoneVerificationAsyncRequest, PhoneVerificationAsyncResponse, PhoneDNCRequest, PhoneDNCResponse, PhoneDNCAsyncRequest, PhoneDNCAsyncResponse, PhoneTCPARequest, PhoneTCPAResponse, PhoneTCPAAsyncRequest, PhoneTCPAAsyncResponse, GetPropertySubscriptionsResponse, GetPropertySubscriptionDetailResponse, DeletePropertySubscriptionResponse, PropertyPermitRequest, PropertyPermitResponse, PropertySkipTraceV3Request, PropertySkipTraceV3Response, PropertySkipTraceV3AsyncRequest, PropertySkipTraceV3AsyncResponse, EventHubConfig, DeliveryConfig } from "../core/types";
5
5
  /**
6
6
  * Middleware function that executes before an HTTP request is sent.
7
7
  * Can modify the request config or perform side effects (logging, metrics, etc.).
@@ -98,6 +98,20 @@ export interface AsyncWebhookConfiguration {
98
98
  */
99
99
  propertySubscription?: AsyncWebhookUrls;
100
100
  }
101
+ /**
102
+ * Event Hub configuration for async API requests
103
+ * Allows specifying Event Hub config per endpoint type, with fallback to defaults
104
+ */
105
+ export interface AsyncEventHubConfiguration {
106
+ /**
107
+ * Default Event Hub config used as fallback for all async endpoints
108
+ */
109
+ default?: EventHubConfig;
110
+ /**
111
+ * Event Hub config for property subscription requests
112
+ */
113
+ propertySubscription?: EventHubConfig;
114
+ }
101
115
  /**
102
116
  * BatchData API Client Options
103
117
  */
@@ -129,6 +143,28 @@ export interface BatchDataClientOptions {
129
143
  * Allows specifying webhook URLs per endpoint type, with fallback to defaults
130
144
  */
131
145
  webhooks?: AsyncWebhookConfiguration;
146
+ /**
147
+ * Optional Event Hub configuration for async requests
148
+ * Allows specifying Event Hub config per endpoint type, with fallback to defaults
149
+ */
150
+ eventHubs?: AsyncEventHubConfiguration;
151
+ /**
152
+ * Optional default delivery configuration for property subscriptions
153
+ * If provided, this will be used when a subscription request doesn't specify deliveryConfig
154
+ * Takes precedence over webhooks and eventHubs configurations
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const client = new BatchDataClient({
159
+ * apiKey: "...",
160
+ * defaultDeliveryConfig: {
161
+ * type: "webhook",
162
+ * url: "https://example.com/webhook",
163
+ * }
164
+ * });
165
+ * ```
166
+ */
167
+ defaultDeliveryConfig?: DeliveryConfig;
132
168
  /**
133
169
  * Optional default PropertyLookupOptions to apply to all requests
134
170
  * These defaults are merged with request-specific options, with request options taking precedence
@@ -178,6 +214,8 @@ export declare class BatchDataClient implements IBatchDataClient {
178
214
  protected readonly axiosInstance: AxiosInstance;
179
215
  protected readonly logger: ILogger;
180
216
  private readonly webhooks?;
217
+ private readonly eventHubs?;
218
+ private readonly defaultDeliveryConfig?;
181
219
  private readonly defaultOptions?;
182
220
  private readonly maxTake?;
183
221
  constructor(options: BatchDataClientOptions);
@@ -231,14 +269,22 @@ export declare class BatchDataClient implements IBatchDataClient {
231
269
  */
232
270
  private applyDefaultOptions;
233
271
  /**
234
- * Apply default webhook URLs to a property subscription request if they're not already set.
235
- * This helper ensures that if webhook URLs are configured in the client,
236
- * they will be used for property subscriptions that don't explicitly specify webhook URLs.
272
+ * Get delivery config from fallbacks (defaultDeliveryConfig first, then Event Hub preferred over webhooks).
273
+ * Returns undefined if no fallback configs are available.
274
+ *
275
+ * @returns Delivery config from fallbacks, or undefined if none available
276
+ */
277
+ private createDeliveryConfigFromFallbacks;
278
+ /**
279
+ * Apply default delivery configuration (Event Hub or webhook) to a property subscription request.
280
+ * Event Hub takes precedence over webhooks if both are configured.
281
+ * If deliveryConfig is not set, it will be created based on available configs (Event Hub preferred).
237
282
  *
238
283
  * @param request The property subscription request to modify
239
- * @returns The request with webhook URLs applied (if needed)
284
+ * @returns The request with delivery config applied (if needed)
285
+ * @throws Error if deliveryConfig type is explicitly set but required config is missing
240
286
  */
241
- private applyPropertySubscriptionWebhooks;
287
+ private applyDeliveryConfigDefaults;
242
288
  /**
243
289
  * Add a request middleware function that executes before requests are sent.
244
290
  * Useful for adding headers, logging, metrics, etc.
@@ -24,6 +24,8 @@ class BatchDataClient {
24
24
  this.v3BaseUrl = options.v3BaseUrl || "https://api.batchdata.com/api/v3";
25
25
  this.logger = options.logger || new logger_interface_1.ConsoleLogger();
26
26
  this.webhooks = options.webhooks;
27
+ this.eventHubs = options.eventHubs;
28
+ this.defaultDeliveryConfig = options.defaultDeliveryConfig;
27
29
  this.defaultOptions = options.defaultOptions;
28
30
  this.maxTake = options.maxTake;
29
31
  this.axiosInstance = axios_1.default.create({
@@ -288,14 +290,18 @@ class BatchDataClient {
288
290
  };
289
291
  }
290
292
  /**
291
- * Apply default webhook URLs to a property subscription request if they're not already set.
292
- * This helper ensures that if webhook URLs are configured in the client,
293
- * they will be used for property subscriptions that don't explicitly specify webhook URLs.
293
+ * Get delivery config from fallbacks (defaultDeliveryConfig first, then Event Hub preferred over webhooks).
294
+ * Returns undefined if no fallback configs are available.
294
295
  *
295
- * @param request The property subscription request to modify
296
- * @returns The request with webhook URLs applied (if needed)
296
+ * @returns Delivery config from fallbacks, or undefined if none available
297
297
  */
298
- applyPropertySubscriptionWebhooks(request) {
298
+ createDeliveryConfigFromFallbacks() {
299
+ // Explicit defaultDeliveryConfig takes highest precedence
300
+ if (this.defaultDeliveryConfig) {
301
+ return this.defaultDeliveryConfig;
302
+ }
303
+ // Determine which Event Hub config to use (property subscription-specific first, then default)
304
+ const eventHubConfig = this.eventHubs?.propertySubscription ?? this.eventHubs?.default;
299
305
  // Determine which webhook URLs to use
300
306
  let webhookUrl;
301
307
  let errorWebhookUrl;
@@ -309,32 +315,85 @@ class BatchDataClient {
309
315
  webhookUrl = this.webhooks.default.url;
310
316
  errorWebhookUrl = errorWebhookUrl || this.webhooks.default.errorUrl;
311
317
  }
312
- // If no webhook URLs are configured, return original request
313
- if (!webhookUrl && !errorWebhookUrl) {
314
- return request;
318
+ // Event Hub takes precedence over webhooks
319
+ if (eventHubConfig) {
320
+ return {
321
+ type: "event-hub",
322
+ eventHub: eventHubConfig,
323
+ };
315
324
  }
316
- // If deliveryConfig is not set or is not a webhook type, create/update it
317
- const deliveryConfig = request.deliveryConfig || {
318
- type: "webhook",
319
- };
320
- // Only apply defaults if deliveryConfig is a webhook type
321
- if (deliveryConfig.type === "webhook") {
322
- // Apply webhook URL if not already set
323
- if (!deliveryConfig.url && webhookUrl) {
324
- deliveryConfig.url = webhookUrl;
325
+ if (webhookUrl || errorWebhookUrl) {
326
+ return {
327
+ type: "webhook",
328
+ ...(webhookUrl && { url: webhookUrl }),
329
+ ...(errorWebhookUrl && { errorUrl: errorWebhookUrl }),
330
+ };
331
+ }
332
+ return undefined;
333
+ }
334
+ /**
335
+ * Apply default delivery configuration (Event Hub or webhook) to a property subscription request.
336
+ * Event Hub takes precedence over webhooks if both are configured.
337
+ * If deliveryConfig is not set, it will be created based on available configs (Event Hub preferred).
338
+ *
339
+ * @param request The property subscription request to modify
340
+ * @returns The request with delivery config applied (if needed)
341
+ * @throws Error if deliveryConfig type is explicitly set but required config is missing
342
+ */
343
+ applyDeliveryConfigDefaults(request) {
344
+ const fallbackConfig = this.createDeliveryConfigFromFallbacks();
345
+ // If deliveryConfig is not set, create it from fallbacks
346
+ if (!request.deliveryConfig) {
347
+ if (fallbackConfig) {
348
+ return { ...request, deliveryConfig: fallbackConfig };
349
+ }
350
+ // If no fallback config is available, throw an error
351
+ throw new Error("Property subscription requires delivery configuration. " +
352
+ "Please provide deliveryConfig in the request, or configure webhooks or eventHubs in BatchDataClient options.");
353
+ }
354
+ const deliveryConfig = request.deliveryConfig;
355
+ // If type is event-hub, use request's eventHub or fallback's eventHub
356
+ if (deliveryConfig.type === "event-hub") {
357
+ const eventHubConfig = deliveryConfig.eventHub ??
358
+ (fallbackConfig?.type === "event-hub"
359
+ ? fallbackConfig.eventHub
360
+ : undefined);
361
+ if (!eventHubConfig) {
362
+ throw new Error("Property subscription requires Event Hub configuration, but none is available. " +
363
+ "Please provide eventHub in deliveryConfig, or configure eventHubs in BatchDataClient options.");
325
364
  }
326
- // Apply error webhook URL if not already set
327
- if (!deliveryConfig.errorUrl && errorWebhookUrl) {
328
- deliveryConfig.errorUrl = errorWebhookUrl;
365
+ if (!deliveryConfig.eventHub) {
366
+ return {
367
+ ...request,
368
+ deliveryConfig: {
369
+ ...deliveryConfig,
370
+ eventHub: eventHubConfig,
371
+ },
372
+ };
329
373
  }
330
374
  }
331
- // Return a new request object with updated deliveryConfig
332
- return {
333
- ...request,
334
- deliveryConfig: {
335
- ...deliveryConfig,
336
- },
337
- };
375
+ // If type is webhook, use request's URLs or fallback's URLs
376
+ if (deliveryConfig.type === "webhook") {
377
+ const webhookUrl = deliveryConfig.url ??
378
+ (fallbackConfig?.type === "webhook" ? fallbackConfig.url : undefined);
379
+ const errorWebhookUrl = deliveryConfig.errorUrl ??
380
+ (fallbackConfig?.type === "webhook"
381
+ ? fallbackConfig.errorUrl
382
+ : undefined);
383
+ if ((!deliveryConfig.url && webhookUrl) ||
384
+ (!deliveryConfig.errorUrl && errorWebhookUrl)) {
385
+ return {
386
+ ...request,
387
+ deliveryConfig: {
388
+ ...deliveryConfig,
389
+ ...(webhookUrl && !deliveryConfig.url && { url: webhookUrl }),
390
+ ...(errorWebhookUrl &&
391
+ !deliveryConfig.errorUrl && { errorUrl: errorWebhookUrl }),
392
+ },
393
+ };
394
+ }
395
+ }
396
+ return request;
338
397
  }
339
398
  /**
340
399
  * Add a request middleware function that executes before requests are sent.
@@ -449,8 +508,8 @@ class BatchDataClient {
449
508
  */
450
509
  async createPropertySubscription(request) {
451
510
  const url = `${this.v2BaseUrl}/property-subscription`;
452
- // Apply default webhook URLs if configured
453
- let requestWithDefaults = this.applyPropertySubscriptionWebhooks(request);
511
+ // Apply default delivery config (Event Hub preferred over webhooks)
512
+ let requestWithDefaults = this.applyDeliveryConfigDefaults(request);
454
513
  // Apply defaults and limits (including maxTake)
455
514
  requestWithDefaults =
456
515
  this.applySearchRequestDefaultsAndLimits(requestWithDefaults);
@@ -479,7 +479,7 @@ export interface DeliveryConfig {
479
479
  * Property subscription request payload
480
480
  */
481
481
  export interface PropertySubscriptionRequest extends RequestWithSearchCriteria {
482
- deliveryConfig: DeliveryConfig;
482
+ deliveryConfig?: DeliveryConfig;
483
483
  }
484
484
  /**
485
485
  * Property subscription response
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@land-catalyst/batch-data-sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "TypeScript SDK for BatchData.io Property API - Types, Builders, and Utilities",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",