@land-catalyst/batch-data-sdk 1.2.11 → 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.
- package/dist/builders/builders.d.ts +79 -22
- package/dist/builders/builders.js +83 -109
- package/dist/client/client.d.ts +113 -6
- package/dist/client/client.js +185 -38
- package/dist/core/types.d.ts +58 -16
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* .build();
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
import { StringFilter, NumericRangeFilter, DateRangeFilter, GeoLocationDistance, GeoLocationBoundingBox, GeoLocationPolygon, AddressSearchCriteria, AssessmentSearchCriteria, BuildingSearchCriteria, CompAddressSearchCriteria, DemographicsSearchCriteria, ForeclosureSearchCriteria, GeneralSearchCriteria, IdsSearchCriteria, IntelSearchCriteria, InvoluntaryLienSearchCriteria, LegalSearchCriteria, ListingSearchCriteria, LotSearchCriteria, OpenLienSearchCriteria, OwnerSearchCriteria, PermitSearchCriteria, PropertyOwnerProfileSearchCriteria, SaleSearchCriteria, TaxSearchCriteria, ValuationSearchCriteria, OrSearchCriteria, SearchCriteria, DeliveryConfig, EventHubConfig, PropertySubscriptionRequest, QuickListValueWithNot, PropertyLookupRequest, PropertyLookupRequestItem, PropertyLookupRequestAddress, PropertyLookupOptions, PropertyPermitRequest, PropertyCountRequest, PropertySearchRequest, PropertySearchAsyncRequest, PropertyLookupAsyncRequest, GeoPoint, AirConditioningSource, BasementType, BuildingClass, BuildingCondition, BuildingQuality, ConstructionType, Driveway, ExteriorWalls, FloorCover, Garage, HeatSource, HeatingFuelType, InteriorWalls, Patio, Pool, Porch, RoofCover, RoofType, Sewer, Style, WaterService, Features, HomeownerRenter, BusinessOwner, Gender, Investments, DemographicsValue, ReligiousAffiliation, ForeclosureStatus, PropertyTypeCategory, PropertyTypeDetail, LienType, LienTypeCode, LoanType, OwnerStatusType, LastSaleDocumentType, ZoningCode } from "../core/types";
|
|
19
|
+
import { StringFilter, NumericRangeFilter, DateRangeFilter, GeoLocationDistance, GeoLocationBoundingBox, GeoLocationPolygon, AddressSearchCriteria, AssessmentSearchCriteria, BuildingSearchCriteria, CompAddressSearchCriteria, DemographicsSearchCriteria, ForeclosureSearchCriteria, GeneralSearchCriteria, IdsSearchCriteria, IntelSearchCriteria, InvoluntaryLienSearchCriteria, LegalSearchCriteria, ListingSearchCriteria, LotSearchCriteria, OpenLienSearchCriteria, OwnerSearchCriteria, PermitSearchCriteria, PropertyOwnerProfileSearchCriteria, SaleSearchCriteria, TaxSearchCriteria, ValuationSearchCriteria, OrSearchCriteria, SearchCriteria, DeliveryConfig, EventHubConfig, PropertySubscriptionRequest, QuickListValueWithNot, PropertyLookupRequest, PropertyLookupRequestItem, PropertyLookupRequestAddress, PropertyLookupOptions, PropertyPermitRequest, PropertyCountRequest, PropertySearchRequest, PropertySearchAsyncRequest, PropertyLookupAsyncRequest, RequestWithLookupOptions, RequestWithSearchCriteria, GeoPoint, AirConditioningSource, BasementType, BuildingClass, BuildingCondition, BuildingQuality, ConstructionType, Driveway, ExteriorWalls, FloorCover, Garage, HeatSource, HeatingFuelType, InteriorWalls, Patio, Pool, Porch, RoofCover, RoofType, Sewer, Style, WaterService, Features, HomeownerRenter, BusinessOwner, Gender, Investments, DemographicsValue, ReligiousAffiliation, ForeclosureStatus, PropertyTypeCategory, PropertyTypeDetail, LienType, LienTypeCode, LoanType, OwnerStatusType, LastSaleDocumentType, ZoningCode } from "../core/types";
|
|
20
20
|
import type { PropertyFieldMetadata } from "../property-field/metadata";
|
|
21
21
|
/**
|
|
22
22
|
* Base interface for all builders
|
|
@@ -145,6 +145,79 @@ declare abstract class BaseBuilder<T> implements Builder<T> {
|
|
|
145
145
|
protected setPropertyWithBuilderClass<K extends keyof T, B extends Builder<T[K]>>(key: K, valueOrConfigurator: T[K] | ((builder: B) => void), BuilderClass: new () => B): this;
|
|
146
146
|
build(): T;
|
|
147
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Base class for builders that work with RequestWithLookupOptions types.
|
|
150
|
+
* Provides the common `options` method implementation.
|
|
151
|
+
*
|
|
152
|
+
* Builders that work with requests that have PropertyLookupOptions should extend
|
|
153
|
+
* this class instead of BaseBuilder directly.
|
|
154
|
+
*/
|
|
155
|
+
export declare abstract class RequestWithLookupOptionsBuilder<T extends RequestWithLookupOptions> extends BaseBuilder<T> {
|
|
156
|
+
/**
|
|
157
|
+
* Set PropertyLookupOptions either directly or via a builder configurator.
|
|
158
|
+
*
|
|
159
|
+
* @param optionsOrConfigurator - Either the direct options object or a configurator function
|
|
160
|
+
* @returns This builder instance for method chaining
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // Direct value
|
|
165
|
+
* builder.options({ take: 10, skip: 0 });
|
|
166
|
+
*
|
|
167
|
+
* // Builder configurator
|
|
168
|
+
* builder.options((opts) => {
|
|
169
|
+
* opts.take(10).skip(0).skipTrace(true);
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
options(options: PropertyLookupOptions): this;
|
|
174
|
+
options(configurator: (builder: PropertyLookupOptionsBuilder) => void): this;
|
|
175
|
+
/**
|
|
176
|
+
* Helper method to build options into a request object.
|
|
177
|
+
* This is used by subclasses in their build() methods.
|
|
178
|
+
*
|
|
179
|
+
* @param request - The request object being built
|
|
180
|
+
* @returns The request object with options applied (if any)
|
|
181
|
+
*/
|
|
182
|
+
protected buildOptionsIntoRequest<R extends RequestWithLookupOptions>(request: R): R;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Base class for builders that work with RequestWithSearchCriteria types.
|
|
186
|
+
* Provides the common `searchCriteria` and `options` method implementations.
|
|
187
|
+
*
|
|
188
|
+
* Builders that work with requests that have both searchCriteria and options
|
|
189
|
+
* should extend this class instead of RequestWithLookupOptionsBuilder directly.
|
|
190
|
+
*/
|
|
191
|
+
export declare abstract class RequestWithSearchCriteriaBuilder<T extends RequestWithSearchCriteria> extends RequestWithLookupOptionsBuilder<T> {
|
|
192
|
+
/**
|
|
193
|
+
* Set SearchCriteria either directly or via a builder configurator.
|
|
194
|
+
*
|
|
195
|
+
* @param criteriaOrConfigurator - Either the direct SearchCriteria object or a configurator function
|
|
196
|
+
* @returns This builder instance for method chaining
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* // Direct value
|
|
201
|
+
* builder.searchCriteria({ query: "123 Main St" });
|
|
202
|
+
*
|
|
203
|
+
* // Builder configurator
|
|
204
|
+
* builder.searchCriteria((sc) => {
|
|
205
|
+
* sc.address((addr) => {
|
|
206
|
+
* addr.street("Main St").city("Phoenix").state("AZ");
|
|
207
|
+
* });
|
|
208
|
+
* });
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
searchCriteria(criteria: SearchCriteria): this;
|
|
212
|
+
searchCriteria(configurator: (builder: SearchCriteriaBuilder) => void): this;
|
|
213
|
+
/**
|
|
214
|
+
* Helper method to validate that searchCriteria is present in build() methods.
|
|
215
|
+
* Throws an error if searchCriteria is missing.
|
|
216
|
+
*
|
|
217
|
+
* @throws Error if searchCriteria is not set
|
|
218
|
+
*/
|
|
219
|
+
protected validateSearchCriteria(): void;
|
|
220
|
+
}
|
|
148
221
|
/**
|
|
149
222
|
* Base builder for string filters
|
|
150
223
|
* @template T - Optional union type of allowed string values. Defaults to `string` for backward compatibility.
|
|
@@ -743,14 +816,10 @@ export declare class DeliveryConfigBuilder {
|
|
|
743
816
|
/**
|
|
744
817
|
* Main builder for property subscription requests
|
|
745
818
|
*/
|
|
746
|
-
export declare class PropertySubscriptionBuilder extends
|
|
819
|
+
export declare class PropertySubscriptionBuilder extends RequestWithSearchCriteriaBuilder<PropertySubscriptionRequest> {
|
|
747
820
|
static from(request: PropertySubscriptionRequest): PropertySubscriptionBuilder;
|
|
748
|
-
searchCriteria(criteria: SearchCriteria): this;
|
|
749
|
-
searchCriteria(configurator: (builder: SearchCriteriaBuilder) => void): this;
|
|
750
821
|
deliveryConfig(config: DeliveryConfig): this;
|
|
751
822
|
deliveryConfig(configurator: (builder: DeliveryConfigBuilder) => void): this;
|
|
752
|
-
options(options: PropertyLookupOptions): this;
|
|
753
|
-
options(configurator: (builder: PropertyLookupOptionsBuilder) => void): this;
|
|
754
823
|
build(): PropertySubscriptionRequest;
|
|
755
824
|
}
|
|
756
825
|
/**
|
|
@@ -807,14 +876,12 @@ export declare class AsyncPropertyLookupOptionsBuilder extends PropertyLookupOpt
|
|
|
807
876
|
/**
|
|
808
877
|
* Builder for property lookup requests
|
|
809
878
|
*/
|
|
810
|
-
export declare class PropertyLookupRequestBuilder extends
|
|
879
|
+
export declare class PropertyLookupRequestBuilder extends RequestWithLookupOptionsBuilder<PropertyLookupRequest> {
|
|
811
880
|
private requestItems;
|
|
812
881
|
static from(request: PropertyLookupRequest): PropertyLookupRequestBuilder;
|
|
813
882
|
items(items: PropertyLookupRequestItem[]): this;
|
|
814
883
|
addItem(item: PropertyLookupRequestItem): this;
|
|
815
884
|
addItemBuilder(builder: PropertyLookupRequestItemBuilder): this;
|
|
816
|
-
options(options: PropertyLookupOptions): this;
|
|
817
|
-
options(configurator: (builder: PropertyLookupOptionsBuilder) => void): this;
|
|
818
885
|
build(): PropertyLookupRequest;
|
|
819
886
|
}
|
|
820
887
|
/**
|
|
@@ -831,36 +898,26 @@ export declare class PropertyCountRequestBuilder extends BaseBuilder<PropertyCou
|
|
|
831
898
|
/**
|
|
832
899
|
* Builder for property search requests
|
|
833
900
|
*/
|
|
834
|
-
export declare class PropertySearchRequestBuilder extends
|
|
901
|
+
export declare class PropertySearchRequestBuilder extends RequestWithSearchCriteriaBuilder<PropertySearchRequest> {
|
|
835
902
|
static from(request: PropertySearchRequest): PropertySearchRequestBuilder;
|
|
836
|
-
searchCriteria(criteria: SearchCriteria): this;
|
|
837
|
-
searchCriteria(configurator: (builder: SearchCriteriaBuilder) => void): this;
|
|
838
|
-
options(options: PropertyLookupOptions): this;
|
|
839
|
-
options(configurator: (builder: PropertyLookupOptionsBuilder) => void): this;
|
|
840
903
|
build(): PropertySearchRequest;
|
|
841
904
|
}
|
|
842
905
|
/**
|
|
843
906
|
* Builder for property search async requests
|
|
844
907
|
*/
|
|
845
|
-
export declare class PropertySearchAsyncRequestBuilder extends
|
|
908
|
+
export declare class PropertySearchAsyncRequestBuilder extends RequestWithSearchCriteriaBuilder<PropertySearchAsyncRequest> {
|
|
846
909
|
static from(request: PropertySearchAsyncRequest): PropertySearchAsyncRequestBuilder;
|
|
847
|
-
searchCriteria(criteria: SearchCriteria): this;
|
|
848
|
-
searchCriteria(configurator: (builder: SearchCriteriaBuilder) => void): this;
|
|
849
|
-
options(options: PropertyLookupOptions): this;
|
|
850
|
-
options(configurator: (builder: PropertyLookupOptionsBuilder) => void): this;
|
|
851
910
|
build(): PropertySearchAsyncRequest;
|
|
852
911
|
}
|
|
853
912
|
/**
|
|
854
913
|
* Builder for property lookup async requests
|
|
855
914
|
*/
|
|
856
|
-
export declare class PropertyLookupAsyncRequestBuilder extends
|
|
915
|
+
export declare class PropertyLookupAsyncRequestBuilder extends RequestWithLookupOptionsBuilder<PropertyLookupAsyncRequest> {
|
|
857
916
|
private requestItems;
|
|
858
917
|
static from(request: PropertyLookupAsyncRequest): PropertyLookupAsyncRequestBuilder;
|
|
859
918
|
items(items: PropertyLookupRequestItem[]): this;
|
|
860
919
|
addItem(item: PropertyLookupRequestItem): this;
|
|
861
920
|
addItemBuilder(builder: PropertyLookupRequestItemBuilder): this;
|
|
862
|
-
options(options: PropertyLookupOptions): this;
|
|
863
|
-
options(configurator: (builder: PropertyLookupOptionsBuilder) => void): this;
|
|
864
921
|
build(): PropertyLookupAsyncRequest;
|
|
865
922
|
}
|
|
866
923
|
/**
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.PropertyPermitRequestBuilder = exports.PropertyLookupAsyncRequestBuilder = exports.PropertySearchAsyncRequestBuilder = exports.PropertySearchRequestBuilder = exports.PropertyCountRequestBuilder = exports.PropertyLookupRequestBuilder = exports.AsyncPropertyLookupOptionsBuilder = exports.PropertyLookupOptionsBuilder = exports.PropertyLookupRequestItemBuilder = exports.PropertySubscriptionBuilder = exports.DeliveryConfigBuilder = exports.SearchCriteriaBuilder = exports.OrSearchCriteriaBuilder = exports.ValuationSearchCriteriaBuilder = exports.TaxSearchCriteriaBuilder = exports.SaleSearchCriteriaBuilder = exports.PropertyOwnerProfileSearchCriteriaBuilder = exports.PermitSearchCriteriaBuilder = exports.OwnerSearchCriteriaBuilder = exports.OpenLienSearchCriteriaBuilder = exports.LotSearchCriteriaBuilder = exports.ListingSearchCriteriaBuilder = exports.LegalSearchCriteriaBuilder = exports.InvoluntaryLienSearchCriteriaBuilder = exports.IntelSearchCriteriaBuilder = exports.IdsSearchCriteriaBuilder = exports.GeneralSearchCriteriaBuilder = exports.ForeclosureSearchCriteriaBuilder = exports.DemographicsSearchCriteriaBuilder = exports.CompAddressSearchCriteriaBuilder = exports.BuildingSearchCriteriaBuilder = exports.AssessmentSearchCriteriaBuilder = exports.AddressSearchCriteriaBuilder = exports.GeoLocationFactory = exports.DateRangeFilterBuilder = exports.NumericRangeFilterBuilder = exports.StringFilterBuilder = void 0;
|
|
21
|
+
exports.PropertyPermitRequestBuilder = exports.PropertyLookupAsyncRequestBuilder = exports.PropertySearchAsyncRequestBuilder = exports.PropertySearchRequestBuilder = exports.PropertyCountRequestBuilder = exports.PropertyLookupRequestBuilder = exports.AsyncPropertyLookupOptionsBuilder = exports.PropertyLookupOptionsBuilder = exports.PropertyLookupRequestItemBuilder = exports.PropertySubscriptionBuilder = exports.DeliveryConfigBuilder = exports.SearchCriteriaBuilder = exports.OrSearchCriteriaBuilder = exports.ValuationSearchCriteriaBuilder = exports.TaxSearchCriteriaBuilder = exports.SaleSearchCriteriaBuilder = exports.PropertyOwnerProfileSearchCriteriaBuilder = exports.PermitSearchCriteriaBuilder = exports.OwnerSearchCriteriaBuilder = exports.OpenLienSearchCriteriaBuilder = exports.LotSearchCriteriaBuilder = exports.ListingSearchCriteriaBuilder = exports.LegalSearchCriteriaBuilder = exports.InvoluntaryLienSearchCriteriaBuilder = exports.IntelSearchCriteriaBuilder = exports.IdsSearchCriteriaBuilder = exports.GeneralSearchCriteriaBuilder = exports.ForeclosureSearchCriteriaBuilder = exports.DemographicsSearchCriteriaBuilder = exports.CompAddressSearchCriteriaBuilder = exports.BuildingSearchCriteriaBuilder = exports.AssessmentSearchCriteriaBuilder = exports.AddressSearchCriteriaBuilder = exports.GeoLocationFactory = exports.DateRangeFilterBuilder = exports.NumericRangeFilterBuilder = exports.StringFilterBuilder = exports.RequestWithSearchCriteriaBuilder = exports.RequestWithLookupOptionsBuilder = void 0;
|
|
22
22
|
const metadata_1 = require("../property-field/metadata");
|
|
23
23
|
const utils_1 = require("../property-field/utils");
|
|
24
24
|
/**
|
|
@@ -164,6 +164,69 @@ class BaseBuilder {
|
|
|
164
164
|
return result;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Base class for builders that work with RequestWithLookupOptions types.
|
|
169
|
+
* Provides the common `options` method implementation.
|
|
170
|
+
*
|
|
171
|
+
* Builders that work with requests that have PropertyLookupOptions should extend
|
|
172
|
+
* this class instead of BaseBuilder directly.
|
|
173
|
+
*/
|
|
174
|
+
class RequestWithLookupOptionsBuilder extends BaseBuilder {
|
|
175
|
+
options(optionsOrConfigurator) {
|
|
176
|
+
return this.setPropertyWithBuilderClass("options", optionsOrConfigurator, PropertyLookupOptionsBuilder);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Helper method to build options into a request object.
|
|
180
|
+
* This is used by subclasses in their build() methods.
|
|
181
|
+
*
|
|
182
|
+
* @param request - The request object being built
|
|
183
|
+
* @returns The request object with options applied (if any)
|
|
184
|
+
*/
|
|
185
|
+
buildOptionsIntoRequest(request) {
|
|
186
|
+
if (this.builders.options) {
|
|
187
|
+
request.options = this.builders.options.build();
|
|
188
|
+
}
|
|
189
|
+
else if (this.criteria.options) {
|
|
190
|
+
request.options = this.criteria.options;
|
|
191
|
+
}
|
|
192
|
+
return request;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.RequestWithLookupOptionsBuilder = RequestWithLookupOptionsBuilder;
|
|
196
|
+
/**
|
|
197
|
+
* Base class for builders that work with RequestWithSearchCriteria types.
|
|
198
|
+
* Provides the common `searchCriteria` and `options` method implementations.
|
|
199
|
+
*
|
|
200
|
+
* Builders that work with requests that have both searchCriteria and options
|
|
201
|
+
* should extend this class instead of RequestWithLookupOptionsBuilder directly.
|
|
202
|
+
*/
|
|
203
|
+
class RequestWithSearchCriteriaBuilder extends RequestWithLookupOptionsBuilder {
|
|
204
|
+
searchCriteria(criteriaOrConfigurator) {
|
|
205
|
+
if (typeof criteriaOrConfigurator === "function") {
|
|
206
|
+
const builder = new SearchCriteriaBuilder("");
|
|
207
|
+
criteriaOrConfigurator(builder);
|
|
208
|
+
this.criteria.searchCriteria = builder.build();
|
|
209
|
+
this.builders.searchCriteria = undefined;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
this.criteria.searchCriteria = criteriaOrConfigurator;
|
|
213
|
+
this.builders.searchCriteria = undefined;
|
|
214
|
+
}
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Helper method to validate that searchCriteria is present in build() methods.
|
|
219
|
+
* Throws an error if searchCriteria is missing.
|
|
220
|
+
*
|
|
221
|
+
* @throws Error if searchCriteria is not set
|
|
222
|
+
*/
|
|
223
|
+
validateSearchCriteria() {
|
|
224
|
+
if (!this.criteria.searchCriteria) {
|
|
225
|
+
throw new Error("Search criteria is required");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.RequestWithSearchCriteriaBuilder = RequestWithSearchCriteriaBuilder;
|
|
167
230
|
/**
|
|
168
231
|
* Base builder for string filters
|
|
169
232
|
* @template T - Optional union type of allowed string values. Defaults to `string` for backward compatibility.
|
|
@@ -2209,29 +2272,18 @@ exports.DeliveryConfigBuilder = DeliveryConfigBuilder;
|
|
|
2209
2272
|
/**
|
|
2210
2273
|
* Main builder for property subscription requests
|
|
2211
2274
|
*/
|
|
2212
|
-
class PropertySubscriptionBuilder extends
|
|
2275
|
+
class PropertySubscriptionBuilder extends RequestWithSearchCriteriaBuilder {
|
|
2213
2276
|
static from(request) {
|
|
2214
2277
|
const builder = new PropertySubscriptionBuilder();
|
|
2215
2278
|
builder.searchCriteria(request.searchCriteria);
|
|
2216
|
-
|
|
2279
|
+
if (request.deliveryConfig) {
|
|
2280
|
+
builder.deliveryConfig(request.deliveryConfig);
|
|
2281
|
+
}
|
|
2217
2282
|
if (request.options) {
|
|
2218
2283
|
builder.options(request.options);
|
|
2219
2284
|
}
|
|
2220
2285
|
return builder;
|
|
2221
2286
|
}
|
|
2222
|
-
searchCriteria(criteriaOrConfigurator) {
|
|
2223
|
-
if (typeof criteriaOrConfigurator === "function") {
|
|
2224
|
-
const builder = new SearchCriteriaBuilder("");
|
|
2225
|
-
criteriaOrConfigurator(builder);
|
|
2226
|
-
this.criteria.searchCriteria = builder.build();
|
|
2227
|
-
this.builders.searchCriteria = undefined;
|
|
2228
|
-
}
|
|
2229
|
-
else {
|
|
2230
|
-
this.criteria.searchCriteria = criteriaOrConfigurator;
|
|
2231
|
-
this.builders.searchCriteria = undefined;
|
|
2232
|
-
}
|
|
2233
|
-
return this;
|
|
2234
|
-
}
|
|
2235
2287
|
deliveryConfig(configOrConfigurator) {
|
|
2236
2288
|
if (typeof configOrConfigurator === "function") {
|
|
2237
2289
|
const builder = new DeliveryConfigBuilder();
|
|
@@ -2245,27 +2297,15 @@ class PropertySubscriptionBuilder extends BaseBuilder {
|
|
|
2245
2297
|
}
|
|
2246
2298
|
return this;
|
|
2247
2299
|
}
|
|
2248
|
-
options(optionsOrConfigurator) {
|
|
2249
|
-
return this.setPropertyWithBuilderClass("options", optionsOrConfigurator, PropertyLookupOptionsBuilder);
|
|
2250
|
-
}
|
|
2251
2300
|
build() {
|
|
2252
|
-
|
|
2253
|
-
throw new Error("Search criteria is required");
|
|
2254
|
-
}
|
|
2255
|
-
if (!this.criteria.deliveryConfig) {
|
|
2256
|
-
throw new Error("Delivery configuration is required");
|
|
2257
|
-
}
|
|
2301
|
+
this.validateSearchCriteria();
|
|
2258
2302
|
const request = {
|
|
2259
2303
|
searchCriteria: this.criteria.searchCriteria,
|
|
2260
|
-
|
|
2304
|
+
...(this.criteria.deliveryConfig && {
|
|
2305
|
+
deliveryConfig: this.criteria.deliveryConfig,
|
|
2306
|
+
}),
|
|
2261
2307
|
};
|
|
2262
|
-
|
|
2263
|
-
request.options = this.builders.options.build();
|
|
2264
|
-
}
|
|
2265
|
-
else if (this.criteria.options) {
|
|
2266
|
-
request.options = this.criteria.options;
|
|
2267
|
-
}
|
|
2268
|
-
return request;
|
|
2308
|
+
return this.buildOptionsIntoRequest(request);
|
|
2269
2309
|
}
|
|
2270
2310
|
}
|
|
2271
2311
|
exports.PropertySubscriptionBuilder = PropertySubscriptionBuilder;
|
|
@@ -2467,7 +2507,7 @@ exports.AsyncPropertyLookupOptionsBuilder = AsyncPropertyLookupOptionsBuilder;
|
|
|
2467
2507
|
/**
|
|
2468
2508
|
* Builder for property lookup requests
|
|
2469
2509
|
*/
|
|
2470
|
-
class PropertyLookupRequestBuilder extends
|
|
2510
|
+
class PropertyLookupRequestBuilder extends RequestWithLookupOptionsBuilder {
|
|
2471
2511
|
constructor() {
|
|
2472
2512
|
super(...arguments);
|
|
2473
2513
|
this.requestItems = [];
|
|
@@ -2492,20 +2532,11 @@ class PropertyLookupRequestBuilder extends BaseBuilder {
|
|
|
2492
2532
|
this.requestItems.push(builder.build());
|
|
2493
2533
|
return this;
|
|
2494
2534
|
}
|
|
2495
|
-
options(optionsOrConfigurator) {
|
|
2496
|
-
return this.setPropertyWithBuilderClass("options", optionsOrConfigurator, PropertyLookupOptionsBuilder);
|
|
2497
|
-
}
|
|
2498
2535
|
build() {
|
|
2499
2536
|
const request = {
|
|
2500
2537
|
requests: this.requestItems,
|
|
2501
2538
|
};
|
|
2502
|
-
|
|
2503
|
-
request.options = this.builders.options.build();
|
|
2504
|
-
}
|
|
2505
|
-
else if (this.criteria.options) {
|
|
2506
|
-
request.options = this.criteria.options;
|
|
2507
|
-
}
|
|
2508
|
-
return request;
|
|
2539
|
+
return this.buildOptionsIntoRequest(request);
|
|
2509
2540
|
}
|
|
2510
2541
|
}
|
|
2511
2542
|
exports.PropertyLookupRequestBuilder = PropertyLookupRequestBuilder;
|
|
@@ -2546,7 +2577,7 @@ exports.PropertyCountRequestBuilder = PropertyCountRequestBuilder;
|
|
|
2546
2577
|
/**
|
|
2547
2578
|
* Builder for property search requests
|
|
2548
2579
|
*/
|
|
2549
|
-
class PropertySearchRequestBuilder extends
|
|
2580
|
+
class PropertySearchRequestBuilder extends RequestWithSearchCriteriaBuilder {
|
|
2550
2581
|
static from(request) {
|
|
2551
2582
|
const builder = new PropertySearchRequestBuilder();
|
|
2552
2583
|
builder.searchCriteria(request.searchCriteria);
|
|
@@ -2555,43 +2586,19 @@ class PropertySearchRequestBuilder extends BaseBuilder {
|
|
|
2555
2586
|
}
|
|
2556
2587
|
return builder;
|
|
2557
2588
|
}
|
|
2558
|
-
searchCriteria(criteriaOrConfigurator) {
|
|
2559
|
-
if (typeof criteriaOrConfigurator === "function") {
|
|
2560
|
-
const builder = new SearchCriteriaBuilder("");
|
|
2561
|
-
criteriaOrConfigurator(builder);
|
|
2562
|
-
this.criteria.searchCriteria = builder.build();
|
|
2563
|
-
this.builders.searchCriteria = undefined;
|
|
2564
|
-
}
|
|
2565
|
-
else {
|
|
2566
|
-
this.criteria.searchCriteria = criteriaOrConfigurator;
|
|
2567
|
-
this.builders.searchCriteria = undefined;
|
|
2568
|
-
}
|
|
2569
|
-
return this;
|
|
2570
|
-
}
|
|
2571
|
-
options(optionsOrConfigurator) {
|
|
2572
|
-
return this.setPropertyWithBuilderClass("options", optionsOrConfigurator, PropertyLookupOptionsBuilder);
|
|
2573
|
-
}
|
|
2574
2589
|
build() {
|
|
2575
|
-
|
|
2576
|
-
throw new Error("Search criteria is required");
|
|
2577
|
-
}
|
|
2590
|
+
this.validateSearchCriteria();
|
|
2578
2591
|
const request = {
|
|
2579
2592
|
searchCriteria: this.criteria.searchCriteria,
|
|
2580
2593
|
};
|
|
2581
|
-
|
|
2582
|
-
request.options = this.builders.options.build();
|
|
2583
|
-
}
|
|
2584
|
-
else if (this.criteria.options) {
|
|
2585
|
-
request.options = this.criteria.options;
|
|
2586
|
-
}
|
|
2587
|
-
return request;
|
|
2594
|
+
return this.buildOptionsIntoRequest(request);
|
|
2588
2595
|
}
|
|
2589
2596
|
}
|
|
2590
2597
|
exports.PropertySearchRequestBuilder = PropertySearchRequestBuilder;
|
|
2591
2598
|
/**
|
|
2592
2599
|
* Builder for property search async requests
|
|
2593
2600
|
*/
|
|
2594
|
-
class PropertySearchAsyncRequestBuilder extends
|
|
2601
|
+
class PropertySearchAsyncRequestBuilder extends RequestWithSearchCriteriaBuilder {
|
|
2595
2602
|
static from(request) {
|
|
2596
2603
|
const builder = new PropertySearchAsyncRequestBuilder();
|
|
2597
2604
|
builder.searchCriteria(request.searchCriteria);
|
|
@@ -2600,43 +2607,19 @@ class PropertySearchAsyncRequestBuilder extends BaseBuilder {
|
|
|
2600
2607
|
}
|
|
2601
2608
|
return builder;
|
|
2602
2609
|
}
|
|
2603
|
-
searchCriteria(criteriaOrConfigurator) {
|
|
2604
|
-
if (typeof criteriaOrConfigurator === "function") {
|
|
2605
|
-
const builder = new SearchCriteriaBuilder("");
|
|
2606
|
-
criteriaOrConfigurator(builder);
|
|
2607
|
-
this.criteria.searchCriteria = builder.build();
|
|
2608
|
-
this.builders.searchCriteria = undefined;
|
|
2609
|
-
}
|
|
2610
|
-
else {
|
|
2611
|
-
this.criteria.searchCriteria = criteriaOrConfigurator;
|
|
2612
|
-
this.builders.searchCriteria = undefined;
|
|
2613
|
-
}
|
|
2614
|
-
return this;
|
|
2615
|
-
}
|
|
2616
|
-
options(optionsOrConfigurator) {
|
|
2617
|
-
return this.setPropertyWithBuilderClass("options", optionsOrConfigurator, PropertyLookupOptionsBuilder);
|
|
2618
|
-
}
|
|
2619
2610
|
build() {
|
|
2620
|
-
|
|
2621
|
-
throw new Error("Search criteria is required");
|
|
2622
|
-
}
|
|
2611
|
+
this.validateSearchCriteria();
|
|
2623
2612
|
const request = {
|
|
2624
2613
|
searchCriteria: this.criteria.searchCriteria,
|
|
2625
2614
|
};
|
|
2626
|
-
|
|
2627
|
-
request.options = this.builders.options.build();
|
|
2628
|
-
}
|
|
2629
|
-
else if (this.criteria.options) {
|
|
2630
|
-
request.options = this.criteria.options;
|
|
2631
|
-
}
|
|
2632
|
-
return request;
|
|
2615
|
+
return this.buildOptionsIntoRequest(request);
|
|
2633
2616
|
}
|
|
2634
2617
|
}
|
|
2635
2618
|
exports.PropertySearchAsyncRequestBuilder = PropertySearchAsyncRequestBuilder;
|
|
2636
2619
|
/**
|
|
2637
2620
|
* Builder for property lookup async requests
|
|
2638
2621
|
*/
|
|
2639
|
-
class PropertyLookupAsyncRequestBuilder extends
|
|
2622
|
+
class PropertyLookupAsyncRequestBuilder extends RequestWithLookupOptionsBuilder {
|
|
2640
2623
|
constructor() {
|
|
2641
2624
|
super(...arguments);
|
|
2642
2625
|
this.requestItems = [];
|
|
@@ -2661,20 +2644,11 @@ class PropertyLookupAsyncRequestBuilder extends BaseBuilder {
|
|
|
2661
2644
|
this.requestItems.push(builder.build());
|
|
2662
2645
|
return this;
|
|
2663
2646
|
}
|
|
2664
|
-
options(optionsOrConfigurator) {
|
|
2665
|
-
return this.setPropertyWithBuilderClass("options", optionsOrConfigurator, PropertyLookupOptionsBuilder);
|
|
2666
|
-
}
|
|
2667
2647
|
build() {
|
|
2668
2648
|
const request = {
|
|
2669
2649
|
requests: this.requestItems,
|
|
2670
2650
|
};
|
|
2671
|
-
|
|
2672
|
-
request.options = this.builders.options.build();
|
|
2673
|
-
}
|
|
2674
|
-
else if (this.criteria.options) {
|
|
2675
|
-
request.options = this.criteria.options;
|
|
2676
|
-
}
|
|
2677
|
-
return request;
|
|
2651
|
+
return this.buildOptionsIntoRequest(request);
|
|
2678
2652
|
}
|
|
2679
2653
|
}
|
|
2680
2654
|
exports.PropertyLookupAsyncRequestBuilder = PropertyLookupAsyncRequestBuilder;
|
package/dist/client/client.d.ts
CHANGED
|
@@ -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, 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,63 @@ 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;
|
|
168
|
+
/**
|
|
169
|
+
* Optional default PropertyLookupOptions to apply to all requests
|
|
170
|
+
* These defaults are merged with request-specific options, with request options taking precedence
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const client = new BatchDataClient({
|
|
175
|
+
* apiKey: "...",
|
|
176
|
+
* defaultOptions: {
|
|
177
|
+
* take: 100, // Default to 100 properties if not specified
|
|
178
|
+
* }
|
|
179
|
+
* });
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
defaultOptions?: PropertyLookupOptions;
|
|
183
|
+
/**
|
|
184
|
+
* Optional maximum `take` value to enforce on all requests
|
|
185
|
+
* If a request specifies a `take` value greater than this, it will be capped to this maximum
|
|
186
|
+
* This is useful for enforcing API limits or preventing accidental large requests
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const client = new BatchDataClient({
|
|
191
|
+
* apiKey: "...",
|
|
192
|
+
* maxTake: 100, // Cap all requests to max 100 properties
|
|
193
|
+
* });
|
|
194
|
+
*
|
|
195
|
+
* // Even if request specifies take: 500, it will be capped to 100
|
|
196
|
+
* await client.searchProperties({
|
|
197
|
+
* searchCriteria: { query: "AZ" },
|
|
198
|
+
* options: { take: 500 } // Will be capped to 100
|
|
199
|
+
* });
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
maxTake?: number;
|
|
132
203
|
}
|
|
133
204
|
/**
|
|
134
205
|
* BatchData API Client
|
|
@@ -143,6 +214,10 @@ export declare class BatchDataClient implements IBatchDataClient {
|
|
|
143
214
|
protected readonly axiosInstance: AxiosInstance;
|
|
144
215
|
protected readonly logger: ILogger;
|
|
145
216
|
private readonly webhooks?;
|
|
217
|
+
private readonly eventHubs?;
|
|
218
|
+
private readonly defaultDeliveryConfig?;
|
|
219
|
+
private readonly defaultOptions?;
|
|
220
|
+
private readonly maxTake?;
|
|
146
221
|
constructor(options: BatchDataClientOptions);
|
|
147
222
|
/**
|
|
148
223
|
* Obfuscate sensitive headers (like Authorization) for logging
|
|
@@ -170,14 +245,46 @@ export declare class BatchDataClient implements IBatchDataClient {
|
|
|
170
245
|
*/
|
|
171
246
|
private applyDefaultWebhookUrls;
|
|
172
247
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
248
|
+
* Get the maximum take value for a request, applying maxTake limit if configured.
|
|
249
|
+
*
|
|
250
|
+
* @param originalRequest The original request
|
|
251
|
+
* @returns The take value to use (capped if necessary)
|
|
252
|
+
*/
|
|
253
|
+
private getMaxPropertyTake;
|
|
254
|
+
/**
|
|
255
|
+
* Apply defaults and limits to a request with search criteria.
|
|
256
|
+
* Uses the shared RequestWithSearchCriteria interface.
|
|
257
|
+
* Currently caps the take value based on maxTake config.
|
|
258
|
+
*
|
|
259
|
+
* @param request The request with search criteria to apply defaults to
|
|
260
|
+
* @returns A new request with defaults applied
|
|
261
|
+
*/
|
|
262
|
+
private applySearchRequestDefaultsAndLimits;
|
|
263
|
+
/**
|
|
264
|
+
* Apply default options to a request that supports PropertyLookupOptions.
|
|
265
|
+
* Defaults are merged with request-specific options, with request options taking precedence.
|
|
266
|
+
*
|
|
267
|
+
* @param request The request to apply defaults to
|
|
268
|
+
* @returns The request with defaults applied (if defaults are configured)
|
|
269
|
+
*/
|
|
270
|
+
private applyDefaultOptions;
|
|
271
|
+
/**
|
|
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).
|
|
176
282
|
*
|
|
177
283
|
* @param request The property subscription request to modify
|
|
178
|
-
* @returns The request with
|
|
284
|
+
* @returns The request with delivery config applied (if needed)
|
|
285
|
+
* @throws Error if deliveryConfig type is explicitly set but required config is missing
|
|
179
286
|
*/
|
|
180
|
-
private
|
|
287
|
+
private applyDeliveryConfigDefaults;
|
|
181
288
|
/**
|
|
182
289
|
* Add a request middleware function that executes before requests are sent.
|
|
183
290
|
* Useful for adding headers, logging, metrics, etc.
|
package/dist/client/client.js
CHANGED
|
@@ -24,6 +24,10 @@ 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;
|
|
29
|
+
this.defaultOptions = options.defaultOptions;
|
|
30
|
+
this.maxTake = options.maxTake;
|
|
27
31
|
this.axiosInstance = axios_1.default.create({
|
|
28
32
|
timeout: options.timeout || 30000,
|
|
29
33
|
headers: {
|
|
@@ -212,14 +216,92 @@ class BatchDataClient {
|
|
|
212
216
|
};
|
|
213
217
|
}
|
|
214
218
|
/**
|
|
215
|
-
*
|
|
216
|
-
* This helper ensures that if webhook URLs are configured in the client,
|
|
217
|
-
* they will be used for property subscriptions that don't explicitly specify webhook URLs.
|
|
219
|
+
* Get the maximum take value for a request, applying maxTake limit if configured.
|
|
218
220
|
*
|
|
219
|
-
* @param
|
|
220
|
-
* @returns The
|
|
221
|
+
* @param originalRequest The original request
|
|
222
|
+
* @returns The take value to use (capped if necessary)
|
|
223
|
+
*/
|
|
224
|
+
getMaxPropertyTake(originalRequest) {
|
|
225
|
+
if (this.maxTake === undefined) {
|
|
226
|
+
return originalRequest.options?.take;
|
|
227
|
+
}
|
|
228
|
+
const { take: originalTake } = originalRequest.options ?? {};
|
|
229
|
+
if (!originalTake)
|
|
230
|
+
return this.maxTake;
|
|
231
|
+
if (originalTake > this.maxTake) {
|
|
232
|
+
this.logger.warn(`Property search take value capped from ${originalTake} to ${this.maxTake} (maxTake limit)`);
|
|
233
|
+
return this.maxTake;
|
|
234
|
+
}
|
|
235
|
+
return originalTake;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Apply defaults and limits to a request with search criteria.
|
|
239
|
+
* Uses the shared RequestWithSearchCriteria interface.
|
|
240
|
+
* Currently caps the take value based on maxTake config.
|
|
241
|
+
*
|
|
242
|
+
* @param request The request with search criteria to apply defaults to
|
|
243
|
+
* @returns A new request with defaults applied
|
|
244
|
+
*/
|
|
245
|
+
applySearchRequestDefaultsAndLimits(request) {
|
|
246
|
+
// First merge defaults if configured
|
|
247
|
+
let requestWithDefaults = request;
|
|
248
|
+
if (this.defaultOptions) {
|
|
249
|
+
requestWithDefaults = this.applyDefaultOptions(request);
|
|
250
|
+
}
|
|
251
|
+
// Then apply maxTake limit
|
|
252
|
+
const maxTake = this.getMaxPropertyTake(requestWithDefaults);
|
|
253
|
+
if (maxTake !== undefined) {
|
|
254
|
+
return {
|
|
255
|
+
...requestWithDefaults,
|
|
256
|
+
options: {
|
|
257
|
+
...requestWithDefaults.options,
|
|
258
|
+
take: maxTake,
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return requestWithDefaults;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Apply default options to a request that supports PropertyLookupOptions.
|
|
266
|
+
* Defaults are merged with request-specific options, with request options taking precedence.
|
|
267
|
+
*
|
|
268
|
+
* @param request The request to apply defaults to
|
|
269
|
+
* @returns The request with defaults applied (if defaults are configured)
|
|
221
270
|
*/
|
|
222
|
-
|
|
271
|
+
applyDefaultOptions(request) {
|
|
272
|
+
// If no defaults are configured, return original request
|
|
273
|
+
if (!this.defaultOptions) {
|
|
274
|
+
return request;
|
|
275
|
+
}
|
|
276
|
+
// Merge defaults with request options (request options take precedence)
|
|
277
|
+
const mergedOptions = {
|
|
278
|
+
...this.defaultOptions,
|
|
279
|
+
...request.options,
|
|
280
|
+
};
|
|
281
|
+
// If no options were actually merged (request had no options and defaults don't add anything),
|
|
282
|
+
// return original request
|
|
283
|
+
if (!request.options && Object.keys(mergedOptions).length === 0) {
|
|
284
|
+
return request;
|
|
285
|
+
}
|
|
286
|
+
// Return a new request object with merged options
|
|
287
|
+
return {
|
|
288
|
+
...request,
|
|
289
|
+
options: mergedOptions,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Get delivery config from fallbacks (defaultDeliveryConfig first, then Event Hub preferred over webhooks).
|
|
294
|
+
* Returns undefined if no fallback configs are available.
|
|
295
|
+
*
|
|
296
|
+
* @returns Delivery config from fallbacks, or undefined if none available
|
|
297
|
+
*/
|
|
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;
|
|
223
305
|
// Determine which webhook URLs to use
|
|
224
306
|
let webhookUrl;
|
|
225
307
|
let errorWebhookUrl;
|
|
@@ -233,32 +315,85 @@ class BatchDataClient {
|
|
|
233
315
|
webhookUrl = this.webhooks.default.url;
|
|
234
316
|
errorWebhookUrl = errorWebhookUrl || this.webhooks.default.errorUrl;
|
|
235
317
|
}
|
|
236
|
-
//
|
|
237
|
-
if (
|
|
238
|
-
return
|
|
318
|
+
// Event Hub takes precedence over webhooks
|
|
319
|
+
if (eventHubConfig) {
|
|
320
|
+
return {
|
|
321
|
+
type: "event-hub",
|
|
322
|
+
eventHub: eventHubConfig,
|
|
323
|
+
};
|
|
239
324
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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 };
|
|
249
349
|
}
|
|
250
|
-
//
|
|
251
|
-
|
|
252
|
-
deliveryConfig
|
|
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.");
|
|
364
|
+
}
|
|
365
|
+
if (!deliveryConfig.eventHub) {
|
|
366
|
+
return {
|
|
367
|
+
...request,
|
|
368
|
+
deliveryConfig: {
|
|
369
|
+
...deliveryConfig,
|
|
370
|
+
eventHub: eventHubConfig,
|
|
371
|
+
},
|
|
372
|
+
};
|
|
253
373
|
}
|
|
254
374
|
}
|
|
255
|
-
//
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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;
|
|
262
397
|
}
|
|
263
398
|
/**
|
|
264
399
|
* Add a request middleware function that executes before requests are sent.
|
|
@@ -373,8 +508,11 @@ class BatchDataClient {
|
|
|
373
508
|
*/
|
|
374
509
|
async createPropertySubscription(request) {
|
|
375
510
|
const url = `${this.v2BaseUrl}/property-subscription`;
|
|
376
|
-
// Apply default
|
|
377
|
-
|
|
511
|
+
// Apply default delivery config (Event Hub preferred over webhooks)
|
|
512
|
+
let requestWithDefaults = this.applyDeliveryConfigDefaults(request);
|
|
513
|
+
// Apply defaults and limits (including maxTake)
|
|
514
|
+
requestWithDefaults =
|
|
515
|
+
this.applySearchRequestDefaultsAndLimits(requestWithDefaults);
|
|
378
516
|
this.logger.debug(`Creating property subscription: POST ${url}`, {
|
|
379
517
|
query: requestWithDefaults.searchCriteria.query,
|
|
380
518
|
});
|
|
@@ -403,12 +541,14 @@ class BatchDataClient {
|
|
|
403
541
|
*/
|
|
404
542
|
async searchProperties(request) {
|
|
405
543
|
const url = `${this.v1BaseUrl}/property/search`;
|
|
544
|
+
// Apply defaults and limits (including maxTake)
|
|
545
|
+
const requestWithDefaults = this.applySearchRequestDefaultsAndLimits(request);
|
|
406
546
|
this.logger.debug(`Searching properties: POST ${url}`, {
|
|
407
|
-
query:
|
|
408
|
-
take:
|
|
409
|
-
skip:
|
|
547
|
+
query: requestWithDefaults.searchCriteria.query,
|
|
548
|
+
take: requestWithDefaults.options?.take,
|
|
549
|
+
skip: requestWithDefaults.options?.skip,
|
|
410
550
|
});
|
|
411
|
-
const { data, status } = await this.handleApiCall(() => this.axiosInstance.post(url,
|
|
551
|
+
const { data, status } = await this.handleApiCall(() => this.axiosInstance.post(url, requestWithDefaults), "Failed to search properties", url);
|
|
412
552
|
this.logger.debug(`Property search completed`, {
|
|
413
553
|
status,
|
|
414
554
|
hasData: !!data,
|
|
@@ -530,10 +670,12 @@ class BatchDataClient {
|
|
|
530
670
|
*/
|
|
531
671
|
async lookupProperty(request) {
|
|
532
672
|
const url = `${this.v1BaseUrl}/property/lookup/all-attributes`;
|
|
673
|
+
// Apply default options if configured
|
|
674
|
+
const requestWithDefaults = this.applyDefaultOptions(request);
|
|
533
675
|
this.logger.debug(`Looking up property: POST ${url}`, {
|
|
534
|
-
requestCount:
|
|
676
|
+
requestCount: requestWithDefaults.requests.length,
|
|
535
677
|
});
|
|
536
|
-
const { data, status } = await this.handleApiCall(() => this.axiosInstance.post(url,
|
|
678
|
+
const { data, status } = await this.handleApiCall(() => this.axiosInstance.post(url, requestWithDefaults), "Failed to lookup property", url);
|
|
537
679
|
this.logger.debug(`Property lookup completed`, {
|
|
538
680
|
status,
|
|
539
681
|
propertyCount: data.results?.properties?.length,
|
|
@@ -550,7 +692,9 @@ class BatchDataClient {
|
|
|
550
692
|
async lookupPropertyAsync(request) {
|
|
551
693
|
const url = `${this.v1BaseUrl}/property/lookup/async`;
|
|
552
694
|
// Apply default webhook URLs if configured
|
|
553
|
-
|
|
695
|
+
let requestWithDefaults = this.applyDefaultWebhookUrls(request, "propertyLookup");
|
|
696
|
+
// Apply default options if configured
|
|
697
|
+
requestWithDefaults = this.applyDefaultOptions(requestWithDefaults);
|
|
554
698
|
this.logger.debug(`Looking up property async: POST ${url}`, {
|
|
555
699
|
requestCount: requestWithDefaults.requests.length,
|
|
556
700
|
});
|
|
@@ -571,7 +715,10 @@ class BatchDataClient {
|
|
|
571
715
|
async searchPropertiesAsync(request) {
|
|
572
716
|
const url = `${this.v1BaseUrl}/property/search/async`;
|
|
573
717
|
// Apply default webhook URLs if configured
|
|
574
|
-
|
|
718
|
+
let requestWithDefaults = this.applyDefaultWebhookUrls(request, "propertySearch");
|
|
719
|
+
// Apply defaults and limits (including maxTake)
|
|
720
|
+
requestWithDefaults =
|
|
721
|
+
this.applySearchRequestDefaultsAndLimits(requestWithDefaults);
|
|
575
722
|
this.logger.debug(`Searching properties async: POST ${url}`, {
|
|
576
723
|
query: requestWithDefaults.searchCriteria.query,
|
|
577
724
|
});
|
package/dist/core/types.d.ts
CHANGED
|
@@ -478,10 +478,8 @@ export interface DeliveryConfig {
|
|
|
478
478
|
/**
|
|
479
479
|
* Property subscription request payload
|
|
480
480
|
*/
|
|
481
|
-
export interface PropertySubscriptionRequest {
|
|
482
|
-
|
|
483
|
-
deliveryConfig: DeliveryConfig;
|
|
484
|
-
options?: PropertyLookupOptions;
|
|
481
|
+
export interface PropertySubscriptionRequest extends RequestWithSearchCriteria {
|
|
482
|
+
deliveryConfig?: DeliveryConfig;
|
|
485
483
|
}
|
|
486
484
|
/**
|
|
487
485
|
* Property subscription response
|
|
@@ -1713,6 +1711,58 @@ export interface PropertyLookupRequestItem {
|
|
|
1713
1711
|
countyFipsCode?: string;
|
|
1714
1712
|
requestId?: string;
|
|
1715
1713
|
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Base interface for requests that support PropertyLookupOptions
|
|
1716
|
+
* This allows for type-safe application of defaults and limits across request types
|
|
1717
|
+
*
|
|
1718
|
+
* @example
|
|
1719
|
+
* ```typescript
|
|
1720
|
+
* // Apply defaults to any request with lookup options
|
|
1721
|
+
* function applyDefaults<T extends RequestWithLookupOptions>(
|
|
1722
|
+
* request: T,
|
|
1723
|
+
* defaults: PropertyLookupOptions
|
|
1724
|
+
* ): T {
|
|
1725
|
+
* return {
|
|
1726
|
+
* ...request,
|
|
1727
|
+
* options: { ...defaults, ...request.options },
|
|
1728
|
+
* };
|
|
1729
|
+
* }
|
|
1730
|
+
* ```
|
|
1731
|
+
*/
|
|
1732
|
+
export interface RequestWithLookupOptions {
|
|
1733
|
+
options?: PropertyLookupOptions;
|
|
1734
|
+
}
|
|
1735
|
+
/**
|
|
1736
|
+
* Base interface for requests that have both searchCriteria and PropertyLookupOptions
|
|
1737
|
+
* Most search-based requests extend this interface
|
|
1738
|
+
*
|
|
1739
|
+
* @example
|
|
1740
|
+
* ```typescript
|
|
1741
|
+
* // Apply defaults to any request with search criteria and options
|
|
1742
|
+
* function applySearchDefaults<T extends RequestWithSearchCriteria>(
|
|
1743
|
+
* request: T,
|
|
1744
|
+
* defaults: PropertyLookupOptions
|
|
1745
|
+
* ): T {
|
|
1746
|
+
* return {
|
|
1747
|
+
* ...request,
|
|
1748
|
+
* options: { ...defaults, ...request.options },
|
|
1749
|
+
* };
|
|
1750
|
+
* }
|
|
1751
|
+
* ```
|
|
1752
|
+
*/
|
|
1753
|
+
export interface RequestWithSearchCriteria extends RequestWithLookupOptions {
|
|
1754
|
+
searchCriteria: SearchCriteria;
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Type helper to extract request types that support PropertyLookupOptions
|
|
1758
|
+
* Useful for writing generic functions that work with any request type
|
|
1759
|
+
*/
|
|
1760
|
+
export type RequestWithLookupOptionsType = PropertySearchRequest | PropertySearchAsyncRequest | PropertyLookupRequest | PropertyLookupAsyncRequest | PropertySubscriptionRequest;
|
|
1761
|
+
/**
|
|
1762
|
+
* Type helper to extract request types that have both searchCriteria and options
|
|
1763
|
+
* Useful for writing generic functions that work with search-based requests
|
|
1764
|
+
*/
|
|
1765
|
+
export type RequestWithSearchCriteriaType = PropertySearchRequest | PropertySearchAsyncRequest | PropertySubscriptionRequest;
|
|
1716
1766
|
/**
|
|
1717
1767
|
* Property lookup options (shared with property search)
|
|
1718
1768
|
*/
|
|
@@ -1765,10 +1815,7 @@ export interface PropertyLookupOptions {
|
|
|
1765
1815
|
/**
|
|
1766
1816
|
* Property search request (synchronous)
|
|
1767
1817
|
*/
|
|
1768
|
-
export
|
|
1769
|
-
searchCriteria: SearchCriteria;
|
|
1770
|
-
options?: PropertyLookupOptions;
|
|
1771
|
-
}
|
|
1818
|
+
export type PropertySearchRequest = RequestWithSearchCriteria;
|
|
1772
1819
|
/**
|
|
1773
1820
|
* Property count request
|
|
1774
1821
|
*
|
|
@@ -1788,9 +1835,8 @@ export interface PropertyCountRequest {
|
|
|
1788
1835
|
/**
|
|
1789
1836
|
* Property lookup request
|
|
1790
1837
|
*/
|
|
1791
|
-
export interface PropertyLookupRequest {
|
|
1838
|
+
export interface PropertyLookupRequest extends RequestWithLookupOptions {
|
|
1792
1839
|
requests: PropertyLookupRequestItem[];
|
|
1793
|
-
options?: PropertyLookupOptions;
|
|
1794
1840
|
}
|
|
1795
1841
|
/**
|
|
1796
1842
|
* Property lookup API response (same structure as PropertySearchResponse)
|
|
@@ -1805,9 +1851,8 @@ export interface PropertyLookupResponse {
|
|
|
1805
1851
|
/**
|
|
1806
1852
|
* Property lookup async request
|
|
1807
1853
|
*/
|
|
1808
|
-
export interface PropertyLookupAsyncRequest {
|
|
1854
|
+
export interface PropertyLookupAsyncRequest extends RequestWithLookupOptions {
|
|
1809
1855
|
requests: PropertyLookupRequestItem[];
|
|
1810
|
-
options?: PropertyLookupOptions;
|
|
1811
1856
|
}
|
|
1812
1857
|
/**
|
|
1813
1858
|
* Property lookup async API response
|
|
@@ -1824,10 +1869,7 @@ export type PropertyLookupAsyncWebhookPayload = PropertyLookupResponse;
|
|
|
1824
1869
|
/**
|
|
1825
1870
|
* Property search async request
|
|
1826
1871
|
*/
|
|
1827
|
-
export
|
|
1828
|
-
searchCriteria: SearchCriteria;
|
|
1829
|
-
options?: PropertyLookupOptions;
|
|
1830
|
-
}
|
|
1872
|
+
export type PropertySearchAsyncRequest = RequestWithSearchCriteria;
|
|
1831
1873
|
/**
|
|
1832
1874
|
* Property search async API response
|
|
1833
1875
|
* Async endpoints return only a status object. Full results are delivered to the webhook URL.
|
package/package.json
CHANGED