@sweepbright/api-client 0.30.2 → 0.30.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/.circleci/config.yml +102 -0
- package/.devcontainer/Dockerfile +23 -0
- package/.devcontainer/devcontainer.json +59 -0
- package/.editorconfig +11 -0
- package/.eslintrc.json +6 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +40 -0
- package/.nvmrc +1 -0
- package/.prettierignore +1 -0
- package/jest.config.js +7 -0
- package/mockServer.ts +44 -0
- package/package.json +3 -6
- package/setupTests.ts +1 -0
- package/src/__tests__/auth.test.ts +14 -0
- package/src/__tests__/channels.test.ts +104 -0
- package/src/__tests__/contacts.test.ts +85 -0
- package/src/__tests__/estates.test.ts +50 -0
- package/src/__tests__/leads.test.ts +67 -0
- package/src/common/currencies.ts +50 -0
- package/src/common/types.ts +1 -0
- package/src/entities/office.ts +193 -0
- package/src/entities/property.ts +574 -0
- package/src/index.ts +128 -0
- package/src/resources/channel_accounts.ts +39 -0
- package/src/resources/channels.ts +52 -0
- package/src/resources/companies.ts +15 -0
- package/src/resources/contact_preferences.ts +14 -0
- package/src/resources/contacts.ts +38 -0
- package/src/resources/estates.ts +145 -0
- package/src/resources/leads.ts +65 -0
- package/src/resources/negotiators.ts +19 -0
- package/src/resources/offices.ts +12 -0
- package/src/types.ts +88 -0
- package/src/utils.ts +35 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import { Currency } from '../common/currencies';
|
|
3
|
+
import { Maybe } from '../common/types';
|
|
4
|
+
|
|
5
|
+
export enum ADScale {
|
|
6
|
+
A = 'A',
|
|
7
|
+
B = 'B',
|
|
8
|
+
C = 'C',
|
|
9
|
+
D = 'D',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export enum Amenity {
|
|
13
|
+
Attic = 'attic',
|
|
14
|
+
Balcony = 'balcony',
|
|
15
|
+
Basement = 'basement',
|
|
16
|
+
ClimateControl = 'climate_control',
|
|
17
|
+
Code = 'code',
|
|
18
|
+
CoolingRoom = 'cooling_room',
|
|
19
|
+
DisplayWindow = 'display_window',
|
|
20
|
+
Drainage = 'drainage',
|
|
21
|
+
ElectricalGate = 'electrical_gate',
|
|
22
|
+
ExteriorParking = 'exterior_parking',
|
|
23
|
+
Fence = 'fence',
|
|
24
|
+
Fenced = 'fenced',
|
|
25
|
+
Garden = 'garden',
|
|
26
|
+
Guesthouse = 'guesthouse',
|
|
27
|
+
InteriorParking = 'interior_parking',
|
|
28
|
+
KeyCard = 'key_card',
|
|
29
|
+
Lift = 'lift',
|
|
30
|
+
ManualGate = 'manual_gate',
|
|
31
|
+
Parking = 'parking',
|
|
32
|
+
Pool = 'pool',
|
|
33
|
+
PrintAndCopyArea = 'print_and_copy_area',
|
|
34
|
+
ReceptionArea = 'reception_area',
|
|
35
|
+
RoadAccess = 'road_access',
|
|
36
|
+
ServerRoom = 'server_room',
|
|
37
|
+
SewerAccess = 'sewer_access',
|
|
38
|
+
StorageSpace = 'storage_space',
|
|
39
|
+
Terrace = 'terrace',
|
|
40
|
+
UtilitiesAccess = 'utilities_access',
|
|
41
|
+
WaitingArea = 'waiting_area',
|
|
42
|
+
WaterAccess = 'water_access',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export enum UnitOfMeasurement {
|
|
46
|
+
cm = 'cm',
|
|
47
|
+
inch = 'inch',
|
|
48
|
+
sq_m = 'sq_m',
|
|
49
|
+
sq_ft = 'sq_ft',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export enum MeasurementSystem {
|
|
53
|
+
Metric = 'metric',
|
|
54
|
+
Imperial = 'imperial',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export enum AreaType {
|
|
58
|
+
Bathrooms = 'bathrooms',
|
|
59
|
+
Bedrooms = 'bedrooms',
|
|
60
|
+
ClosedOfficeSpaces = 'closed_office_spaces',
|
|
61
|
+
ConferenceRooms = 'conference_rooms',
|
|
62
|
+
Floors = 'floors',
|
|
63
|
+
Kitchens = 'kitchens',
|
|
64
|
+
LivingRoom = 'living_room',
|
|
65
|
+
ManufacturingAreas = 'manufacturing_areas',
|
|
66
|
+
MeetingRooms = 'meeting_rooms',
|
|
67
|
+
OpenOfficeSpaces = 'open_office_spaces',
|
|
68
|
+
ParkingSpaces = 'parking_spaces',
|
|
69
|
+
Showrooms = 'showrooms',
|
|
70
|
+
StorageRooms = 'storage_rooms',
|
|
71
|
+
Toilets = 'toilets',
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export enum PropertyStatus {
|
|
75
|
+
prospect = 'prospect',
|
|
76
|
+
lost = 'lost',
|
|
77
|
+
available = 'available',
|
|
78
|
+
rented = 'rented',
|
|
79
|
+
sold = 'sold',
|
|
80
|
+
bid = 'bid',
|
|
81
|
+
option = 'option',
|
|
82
|
+
under_contract = 'under_contract',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export enum PropertySubType {
|
|
86
|
+
duplex = 'duplex',
|
|
87
|
+
agricultural = 'agricultural',
|
|
88
|
+
pasture_land = 'pasture_land',
|
|
89
|
+
private_garage = 'private_garage',
|
|
90
|
+
loft = 'loft',
|
|
91
|
+
recreational = 'recreational',
|
|
92
|
+
investment_property = 'investment_property',
|
|
93
|
+
mansion = 'mansion',
|
|
94
|
+
terraced = 'terraced',
|
|
95
|
+
townhouse = 'townhouse',
|
|
96
|
+
condo = 'condo',
|
|
97
|
+
penthouse = 'penthouse',
|
|
98
|
+
farm = 'farm',
|
|
99
|
+
cottage = 'cottage',
|
|
100
|
+
buildable = 'buildable',
|
|
101
|
+
villa = 'villa',
|
|
102
|
+
retail = 'retail',
|
|
103
|
+
covered_outdoor_space = 'covered_outdoor_space',
|
|
104
|
+
indoor_parking_space = 'indoor_parking_space',
|
|
105
|
+
flex_office = 'flex_office',
|
|
106
|
+
open_office = 'open_office',
|
|
107
|
+
industrial = 'industrial',
|
|
108
|
+
restaurant_and_cafe = 'restaurant_and_cafe',
|
|
109
|
+
student_accommodation = 'student_accommodation',
|
|
110
|
+
leisure_and_sports = 'leasure_and_sports',
|
|
111
|
+
outdoor_parking_space = 'outdoor_parking_space',
|
|
112
|
+
coworking = 'coworking',
|
|
113
|
+
warehouse = 'warehouse',
|
|
114
|
+
shop = 'shop',
|
|
115
|
+
semi_detached = 'semi_detached',
|
|
116
|
+
healthcare = 'healthcare',
|
|
117
|
+
detached = 'detached',
|
|
118
|
+
bungalow = 'bungalow',
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export enum PropertyType {
|
|
122
|
+
apartment = 'apartment',
|
|
123
|
+
house = 'house',
|
|
124
|
+
land = 'land',
|
|
125
|
+
office = 'office',
|
|
126
|
+
parking = 'parking',
|
|
127
|
+
commercial = 'commercial',
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export enum Negotiation {
|
|
131
|
+
sale = 'sale',
|
|
132
|
+
let = 'let',
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export enum Condition {
|
|
136
|
+
new = 'new',
|
|
137
|
+
good = 'good',
|
|
138
|
+
mint = 'mint',
|
|
139
|
+
poor = 'poor',
|
|
140
|
+
fair = 'fair',
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export enum Orientation {
|
|
144
|
+
N = 'N',
|
|
145
|
+
S = 'S',
|
|
146
|
+
E = 'E',
|
|
147
|
+
W = 'W',
|
|
148
|
+
NE = 'NE',
|
|
149
|
+
NW = 'NW',
|
|
150
|
+
SE = 'SE',
|
|
151
|
+
SW = 'SW',
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export enum EnergyCategory {
|
|
155
|
+
A = 'A',
|
|
156
|
+
B = 'B',
|
|
157
|
+
C = 'C',
|
|
158
|
+
D = 'D',
|
|
159
|
+
E = 'E',
|
|
160
|
+
F = 'F',
|
|
161
|
+
G = 'G',
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export enum EnergyCategoryExtended {
|
|
165
|
+
A_PLUS_PLUS = 'A++',
|
|
166
|
+
A_PLUS = 'A+',
|
|
167
|
+
A = 'A',
|
|
168
|
+
B = 'B',
|
|
169
|
+
C = 'C',
|
|
170
|
+
D = 'D',
|
|
171
|
+
E = 'E',
|
|
172
|
+
F = 'F',
|
|
173
|
+
G = 'G',
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export enum EnergyReport {
|
|
177
|
+
conform = 'conform',
|
|
178
|
+
not_conform = 'not_conform',
|
|
179
|
+
no_report = 'no_report',
|
|
180
|
+
not_applicable = 'not_applicable',
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export enum FloodRisk {
|
|
184
|
+
no_flood_risk_area = 'no_flood_risk_area',
|
|
185
|
+
potential_flood_sensitive_area = 'potential_flood_sensitive_area',
|
|
186
|
+
effective_flood_sensitive_area = 'effective_flood_sensitive_area',
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export enum Shape {
|
|
190
|
+
flat = 'flat',
|
|
191
|
+
sloped = 'sloped',
|
|
192
|
+
wooded = 'wooded',
|
|
193
|
+
has_rivers_lakes_or_ponds = 'has_rivers_lakes_or_ponds',
|
|
194
|
+
single = 'single',
|
|
195
|
+
double = 'double',
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export enum LandUseDesignation {
|
|
199
|
+
residential = 'residential',
|
|
200
|
+
mixed_residential = 'mixed_residential',
|
|
201
|
+
industrial = 'industrial',
|
|
202
|
+
recreational = 'recreational',
|
|
203
|
+
park = 'park',
|
|
204
|
+
area_with_economical_activity = 'area_with_economical_activity',
|
|
205
|
+
forest_area = 'forest_area',
|
|
206
|
+
agricultural = 'agricultural',
|
|
207
|
+
nature_area = 'nature_area',
|
|
208
|
+
natural_reserve = 'natural_reserve',
|
|
209
|
+
residential_area_with_cultural_historical_value = 'residential_area_with_cultural_historical_value',
|
|
210
|
+
industrial_area_for_sme = 'industrial_area_for_sme',
|
|
211
|
+
day_recreation_area = 'day_recreation_area',
|
|
212
|
+
other = 'other',
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface Regulations {
|
|
216
|
+
heritage_list?: Maybe<boolean>;
|
|
217
|
+
as_build_report?: Maybe<boolean>;
|
|
218
|
+
building_permit?: Maybe<boolean>;
|
|
219
|
+
expropriation_plan?: Maybe<boolean>;
|
|
220
|
+
registered_building?: Maybe<boolean>;
|
|
221
|
+
urban_planning_breach?: Maybe<boolean>;
|
|
222
|
+
site_untapped_activity?: Maybe<boolean>;
|
|
223
|
+
priority_purchase_right?: Maybe<boolean>;
|
|
224
|
+
subdivision_authorisation?: Maybe<boolean>;
|
|
225
|
+
urban_planning_certificate?: Maybe<boolean>;
|
|
226
|
+
pending_legal_proceedings?: Maybe<boolean>;
|
|
227
|
+
asbestos_certificate?: Maybe<boolean>;
|
|
228
|
+
asbestos_certificate_reference?: Maybe<string>;
|
|
229
|
+
zone_subject_to_rent_control?: Maybe<boolean>;
|
|
230
|
+
ongoing_litigation?: Maybe<boolean>;
|
|
231
|
+
renovation_obligation?: Maybe<boolean>;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface PropertyAndLand {
|
|
235
|
+
flood_risk?: Maybe<FloodRisk>;
|
|
236
|
+
purchased_year?: Maybe<number | string>;
|
|
237
|
+
cadastral_income?: Maybe<number>;
|
|
238
|
+
land_use_designation?: Maybe<LandUseDesignation>;
|
|
239
|
+
flood_risk_plot_score?: Maybe<ADScale>;
|
|
240
|
+
flood_risk_building_score?: Maybe<ADScale>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export interface Energy {
|
|
244
|
+
epc_value?: Maybe<number>;
|
|
245
|
+
epc_category?: Maybe<EnergyCategoryExtended>;
|
|
246
|
+
epc_reference?: Maybe<string>;
|
|
247
|
+
co2_emissions?: Maybe<number>;
|
|
248
|
+
e_level?: Maybe<number>;
|
|
249
|
+
report_electricity_gas?: Maybe<EnergyReport>;
|
|
250
|
+
report_fuel_tank?: Maybe<EnergyReport>;
|
|
251
|
+
total_epc_value?: Maybe<number>;
|
|
252
|
+
dpe?: Maybe<EnergyCategory>;
|
|
253
|
+
greenhouse_emissions?: Maybe<EnergyCategory>;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface LegalAttributes {
|
|
257
|
+
energy?: Maybe<Energy>;
|
|
258
|
+
regulations?: Maybe<Regulations>;
|
|
259
|
+
legal_mentions?: Maybe<Record<string, string>>;
|
|
260
|
+
property_and_land?: Maybe<PropertyAndLand>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface Price {
|
|
264
|
+
amount: number;
|
|
265
|
+
currency: Currency;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export interface PropertyPrice {
|
|
269
|
+
costs?: Maybe<Record<string, string>>;
|
|
270
|
+
taxes?: Maybe<Record<string, string>>;
|
|
271
|
+
current_price?: Maybe<Price>;
|
|
272
|
+
published_price?: Maybe<Price>;
|
|
273
|
+
yearly_budgeted_building_costs?: Maybe<Price>;
|
|
274
|
+
recurring_costs?: Maybe<Price>;
|
|
275
|
+
property_tax?: Maybe<Price>;
|
|
276
|
+
vat_regime?: Maybe<number>;
|
|
277
|
+
guarantee?: Maybe<Price>;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export interface RenovationAttributes {
|
|
281
|
+
year?: Maybe<number | string>;
|
|
282
|
+
description?: Maybe<string>;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export interface ConstructionAttributes {
|
|
286
|
+
year?: Maybe<number | string>;
|
|
287
|
+
architect?: Maybe<string>;
|
|
288
|
+
residential_lots?: Maybe<number>;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface BuildingAttributes {
|
|
292
|
+
renovation?: Maybe<RenovationAttributes>;
|
|
293
|
+
construction?: Maybe<ConstructionAttributes>;
|
|
294
|
+
units_of_building?: Maybe<number>;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface EnergyFeatures {
|
|
298
|
+
gas?: Maybe<boolean>;
|
|
299
|
+
electricity?: Maybe<boolean>;
|
|
300
|
+
fuel?: Maybe<boolean>;
|
|
301
|
+
heat_pump?: Maybe<boolean>;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface ComfortFeatures {
|
|
305
|
+
sauna?: Maybe<boolean>;
|
|
306
|
+
fireplace?: Maybe<boolean>;
|
|
307
|
+
fitness_room?: Maybe<boolean>;
|
|
308
|
+
furnished?: Maybe<boolean>;
|
|
309
|
+
home_automation?: Maybe<boolean>;
|
|
310
|
+
home_cinema?: Maybe<boolean>;
|
|
311
|
+
wine_cellar?: Maybe<boolean>;
|
|
312
|
+
walk_in_closet?: Maybe<boolean>;
|
|
313
|
+
water_softener?: Maybe<boolean>;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface EcologyFeatures {
|
|
317
|
+
solar_boiler?: Maybe<boolean>;
|
|
318
|
+
solar_panels?: Maybe<boolean>;
|
|
319
|
+
double_glazing?: Maybe<boolean>;
|
|
320
|
+
rainwater_harvesting?: Maybe<boolean>;
|
|
321
|
+
insulated_roof?: Maybe<boolean>;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export interface SecurityFeatures {
|
|
325
|
+
alarm?: Maybe<boolean>;
|
|
326
|
+
concierge?: Maybe<boolean>;
|
|
327
|
+
video_surveillance?: Maybe<boolean>;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface HeatingCoolingFeatures {
|
|
331
|
+
air_conditioning?: Maybe<boolean>;
|
|
332
|
+
central_heating?: Maybe<boolean>;
|
|
333
|
+
floor_heating?: Maybe<boolean>;
|
|
334
|
+
individual_heating?: Maybe<boolean>;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export interface FeaturesAttributes {
|
|
338
|
+
energy?: Maybe<EnergyFeatures>;
|
|
339
|
+
comfort?: Maybe<ComfortFeatures>;
|
|
340
|
+
ecology?: Maybe<EcologyFeatures>;
|
|
341
|
+
security?: Maybe<SecurityFeatures>;
|
|
342
|
+
heating_cooling?: Maybe<HeatingCoolingFeatures>;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export interface GeoData {
|
|
346
|
+
latitude: number;
|
|
347
|
+
longitude: number;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface LocationAttributes {
|
|
351
|
+
country?: Maybe<string>;
|
|
352
|
+
box?: Maybe<string>;
|
|
353
|
+
geo?: Maybe<GeoData>;
|
|
354
|
+
city?: Maybe<string>;
|
|
355
|
+
floor?: Maybe<string>;
|
|
356
|
+
number?: Maybe<string>;
|
|
357
|
+
street?: Maybe<string>;
|
|
358
|
+
addition?: Maybe<string>;
|
|
359
|
+
street_2?: Maybe<string>;
|
|
360
|
+
postal_code?: Maybe<string | number>;
|
|
361
|
+
province_or_state?: Maybe<string>;
|
|
362
|
+
borough_or_district?: Maybe<string>;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export interface OfficeSettings {
|
|
366
|
+
reference?: Maybe<string>;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface MandateSettings {
|
|
370
|
+
end_date?: Maybe<string>;
|
|
371
|
+
start_date?: Maybe<string>;
|
|
372
|
+
number?: Maybe<string>;
|
|
373
|
+
exclusive?: Maybe<boolean>;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export interface AgencyCommission {
|
|
377
|
+
fixed_fee?: Maybe<number>;
|
|
378
|
+
percentage?: Maybe<number>;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export interface AgencyCommissions {
|
|
382
|
+
buyer?: Maybe<AgencyCommission>;
|
|
383
|
+
seller?: Maybe<AgencyCommission>;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface PropertySettings {
|
|
387
|
+
office?: Maybe<OfficeSettings>;
|
|
388
|
+
mandate?: Maybe<MandateSettings>;
|
|
389
|
+
current_rent?: Maybe<Price>;
|
|
390
|
+
internal_note?: Maybe<string>;
|
|
391
|
+
agency_commission?: Maybe<AgencyCommissions>;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export interface OccupancyAttributes {
|
|
395
|
+
vacant?: Maybe<boolean>;
|
|
396
|
+
occupied?: Maybe<boolean>;
|
|
397
|
+
contact_details?: Maybe<string>;
|
|
398
|
+
available_from?: Maybe<string>;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export interface PropertyRoomAttributes {
|
|
402
|
+
size: number | string;
|
|
403
|
+
type: string;
|
|
404
|
+
units: UnitOfMeasurement;
|
|
405
|
+
ordinal: Maybe<number>;
|
|
406
|
+
size_description: string;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export interface Area {
|
|
410
|
+
size: number;
|
|
411
|
+
units?: Maybe<UnitOfMeasurement>;
|
|
412
|
+
size_description: string;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export interface PropertyStructure {
|
|
416
|
+
rooms?: Maybe<Record<string, PropertyRoomAttributes>>;
|
|
417
|
+
toilets?: Maybe<number>;
|
|
418
|
+
bedrooms?: Maybe<number>;
|
|
419
|
+
bathrooms?: Maybe<number>;
|
|
420
|
+
kitchens?: Maybe<number>;
|
|
421
|
+
floors?: Maybe<number>;
|
|
422
|
+
living_room?: Maybe<number>;
|
|
423
|
+
showrooms?: Maybe<number>;
|
|
424
|
+
shower_rooms?: Maybe<number>;
|
|
425
|
+
manufacturing_areas?: Maybe<number>;
|
|
426
|
+
storage_rooms?: Maybe<number>;
|
|
427
|
+
parking_spaces?: Maybe<number>;
|
|
428
|
+
meeting_rooms?: Maybe<number>;
|
|
429
|
+
open_office_spaces?: Maybe<number>;
|
|
430
|
+
closed_office_spaces?: Maybe<number>;
|
|
431
|
+
conference_rooms?: Maybe<number>;
|
|
432
|
+
liveable_area?: Maybe<Area>;
|
|
433
|
+
gross_area?: Maybe<Area>;
|
|
434
|
+
net_area?: Maybe<Area>;
|
|
435
|
+
plot_area?: Maybe<Area>;
|
|
436
|
+
display_window_length?: Maybe<Area>;
|
|
437
|
+
ceiling_height?: Maybe<Area>;
|
|
438
|
+
loi_carrez_area?: Maybe<Area>;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export interface PropertyConditions {
|
|
442
|
+
kitchen?: Maybe<Condition>;
|
|
443
|
+
bathroom?: Maybe<Condition>;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export interface PropertyDescription {
|
|
447
|
+
title: Record<string, string>;
|
|
448
|
+
description: Record<string, string>;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export interface PropertyOrientation {
|
|
452
|
+
balcony?: Maybe<Orientation>;
|
|
453
|
+
garden?: Maybe<Orientation>;
|
|
454
|
+
terrace?: Maybe<Orientation>;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export interface PropertyAccessibility {
|
|
458
|
+
alarm?: Maybe<boolean>;
|
|
459
|
+
alarm_code?: Maybe<number | string>;
|
|
460
|
+
key_available?: Maybe<boolean>;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export interface PropertyDocument {
|
|
464
|
+
private: boolean;
|
|
465
|
+
filename: string;
|
|
466
|
+
extension: string;
|
|
467
|
+
description?: Maybe<string>;
|
|
468
|
+
uploaded_at: string;
|
|
469
|
+
'content-type': string;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export interface FloorPlan {
|
|
473
|
+
private: boolean;
|
|
474
|
+
filename: string;
|
|
475
|
+
extension: string;
|
|
476
|
+
description: Maybe<string>;
|
|
477
|
+
uploaded_at: string;
|
|
478
|
+
'content-type': string;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export interface Image {
|
|
482
|
+
ordinal: number;
|
|
483
|
+
private: boolean;
|
|
484
|
+
filename: string;
|
|
485
|
+
extension: string;
|
|
486
|
+
description?: Maybe<string>;
|
|
487
|
+
equirectangular?: Maybe<boolean>;
|
|
488
|
+
uploaded_at: string;
|
|
489
|
+
'content-type': string;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export interface PropertyPermissions {
|
|
493
|
+
construction?: Maybe<boolean>;
|
|
494
|
+
farming?: Maybe<boolean>;
|
|
495
|
+
fishing?: Maybe<boolean>;
|
|
496
|
+
planning?: Maybe<boolean>;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export interface TenantContract {
|
|
500
|
+
start_date?: Maybe<string>;
|
|
501
|
+
end_date?: Maybe<string>;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export interface PropertyAttributes {
|
|
505
|
+
legal?: Maybe<LegalAttributes>;
|
|
506
|
+
price?: Maybe<PropertyPrice>;
|
|
507
|
+
images?: Maybe<Record<string, Image>>;
|
|
508
|
+
status?: Maybe<PropertyStatus>;
|
|
509
|
+
building?: Maybe<BuildingAttributes>;
|
|
510
|
+
features?: Maybe<FeaturesAttributes>;
|
|
511
|
+
location?: Maybe<LocationAttributes>;
|
|
512
|
+
settings?: Maybe<PropertySettings>;
|
|
513
|
+
sub_type?: Maybe<PropertySubType[]>;
|
|
514
|
+
amenities?: Maybe<Amenity[]>;
|
|
515
|
+
documents?: Maybe<Record<string, PropertyDocument>>;
|
|
516
|
+
occupancy?: Maybe<OccupancyAttributes>;
|
|
517
|
+
structure?: Maybe<PropertyStructure>;
|
|
518
|
+
conditions?: Maybe<PropertyConditions>;
|
|
519
|
+
description?: Maybe<PropertyDescription>;
|
|
520
|
+
floor_plans?: Maybe<Record<string, FloorPlan>>;
|
|
521
|
+
orientation?: Maybe<PropertyOrientation>;
|
|
522
|
+
accessibility?: Maybe<PropertyAccessibility>;
|
|
523
|
+
tenant_contract?: Maybe<TenantContract>;
|
|
524
|
+
general_condition?: Maybe<Condition>;
|
|
525
|
+
permissions?: Maybe<PropertyPermissions>;
|
|
526
|
+
shape?: Maybe<Shape>;
|
|
527
|
+
video?: Maybe<string>;
|
|
528
|
+
virtual_tour?: Maybe<string>;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export interface Property {
|
|
532
|
+
id: string;
|
|
533
|
+
type: PropertyType;
|
|
534
|
+
negotiation: Negotiation;
|
|
535
|
+
is_project: boolean;
|
|
536
|
+
project_id?: Maybe<string>;
|
|
537
|
+
office_id: string;
|
|
538
|
+
negotiator_id: string;
|
|
539
|
+
attributes: PropertyAttributes;
|
|
540
|
+
archived_at?: Maybe<string>;
|
|
541
|
+
created_at?: Maybe<string>;
|
|
542
|
+
updated_at?: Maybe<string>;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export type Resource = FloorPlan | PropertyDocument | Image;
|
|
546
|
+
export type FileUploadStream = fs.ReadStream;
|
|
547
|
+
export interface LanguageWithDefaultValue {
|
|
548
|
+
language: string;
|
|
549
|
+
default_value: string;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export interface RoomData {
|
|
553
|
+
name: AreaType;
|
|
554
|
+
value: number;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export type LocalizedStringMap = { [key: string]: string };
|
|
558
|
+
|
|
559
|
+
export interface UserDefaults {
|
|
560
|
+
measurementSystem: MeasurementSystem;
|
|
561
|
+
currency: Currency;
|
|
562
|
+
defaultLanguage: string[];
|
|
563
|
+
country: string;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
export enum InternalType {
|
|
567
|
+
project = 'project',
|
|
568
|
+
unit = 'unit',
|
|
569
|
+
standalone = 'standalone',
|
|
570
|
+
}
|
|
571
|
+
export interface PropertyForSnsEvent extends Property {
|
|
572
|
+
is_archived: boolean;
|
|
573
|
+
internal_type: InternalType;
|
|
574
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import invariant from 'tiny-invariant';
|
|
3
|
+
import channelAccounts from './resources/channel_accounts';
|
|
4
|
+
import channels from './resources/channels';
|
|
5
|
+
import companies from './resources/companies';
|
|
6
|
+
import contact_preferences from './resources/contact_preferences';
|
|
7
|
+
import contacts from './resources/contacts';
|
|
8
|
+
import estates from './resources/estates';
|
|
9
|
+
import leads from './resources/leads';
|
|
10
|
+
import negotiators from './resources/negotiators';
|
|
11
|
+
import offices from './resources/offices';
|
|
12
|
+
import { Auth, ClientConf, Env, InitConf, Maybe, TokenType } from './types';
|
|
13
|
+
import { getData, handleRequestFailure } from './utils';
|
|
14
|
+
|
|
15
|
+
const envHosts: Record<Env, string> = {
|
|
16
|
+
[Env.PRODUCTION]: 'https://api.sweepbright.com',
|
|
17
|
+
[Env.STAGING]: 'https://api.staging.sweepbright.com',
|
|
18
|
+
[Env.DEV]: 'https://api.dev.sweepbright.com',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
interface Client {
|
|
22
|
+
authorize(config?: InitConf): Promise<Client>;
|
|
23
|
+
withUserToken(accessToken: string): Promise<Client>;
|
|
24
|
+
leads: ReturnType<typeof leads>;
|
|
25
|
+
negotiators: ReturnType<typeof negotiators>;
|
|
26
|
+
offices: ReturnType<typeof offices>;
|
|
27
|
+
contacts: ReturnType<typeof contacts>;
|
|
28
|
+
channelAccounts: ReturnType<typeof channelAccounts>;
|
|
29
|
+
channels: ReturnType<typeof channels>;
|
|
30
|
+
companies: ReturnType<typeof companies>;
|
|
31
|
+
contactPreferences: ReturnType<typeof contact_preferences>;
|
|
32
|
+
estates: ReturnType<typeof estates>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createClient(conf: ClientConf) {
|
|
36
|
+
const { clientId, clientSecret, env = Env.PRODUCTION, version } = conf;
|
|
37
|
+
let _auth: Maybe<Auth> = null;
|
|
38
|
+
|
|
39
|
+
const httpClient = axios.create({
|
|
40
|
+
baseURL: envHosts[env],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
//TODO: getData here is an antipattern. Interceptor should not change a type of response
|
|
44
|
+
httpClient.interceptors.response.use(getData, handleRequestFailure);
|
|
45
|
+
if (version) {
|
|
46
|
+
httpClient.defaults.headers.common[
|
|
47
|
+
'Accept'
|
|
48
|
+
] = `application/vnd.sweepbright.${version}+json`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const ctx = {
|
|
52
|
+
httpClient,
|
|
53
|
+
checkAuth(tokenType: TokenType) {
|
|
54
|
+
if (!_auth) {
|
|
55
|
+
throw new Error('client is not authenticated');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (_auth.type !== tokenType) {
|
|
59
|
+
throw new Error('authenticated with invalid token type');
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const client: Client = {
|
|
65
|
+
authorize(config: InitConf = {}): Promise<Client> {
|
|
66
|
+
const {
|
|
67
|
+
scopes = ['companies:read', 'properties:download', 'lead_info:write'],
|
|
68
|
+
} = config;
|
|
69
|
+
|
|
70
|
+
invariant(clientId, 'missing client id');
|
|
71
|
+
invariant(clientSecret, 'missing client secret');
|
|
72
|
+
|
|
73
|
+
return httpClient
|
|
74
|
+
.post<
|
|
75
|
+
any,
|
|
76
|
+
{
|
|
77
|
+
access_token: string;
|
|
78
|
+
expires_in: string;
|
|
79
|
+
}
|
|
80
|
+
>('/auth/access-token', {
|
|
81
|
+
client_id: clientId,
|
|
82
|
+
client_secret: clientSecret,
|
|
83
|
+
grant_type: 'client_credentials',
|
|
84
|
+
scope: scopes.join(','),
|
|
85
|
+
})
|
|
86
|
+
.then(({ access_token, expires_in }) => {
|
|
87
|
+
invariant(access_token, 'access token should be defined');
|
|
88
|
+
invariant(expires_in, 'expires_in should be defined');
|
|
89
|
+
_auth = {
|
|
90
|
+
token: access_token,
|
|
91
|
+
expiresIn: expires_in,
|
|
92
|
+
type: TokenType.API_TOKEN,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// https://github.com/axios/axios#custom-instance-defaults
|
|
96
|
+
httpClient.defaults.headers.common[
|
|
97
|
+
'Authorization'
|
|
98
|
+
] = `Bearer ${_auth.token}`;
|
|
99
|
+
return client;
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
withUserToken: async (accessToken: string): Promise<Client> => {
|
|
103
|
+
_auth = {
|
|
104
|
+
token: accessToken,
|
|
105
|
+
type: TokenType.USER_TOKEN,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
httpClient.defaults.headers.common[
|
|
109
|
+
'Authorization'
|
|
110
|
+
] = `Bearer ${_auth.token}`;
|
|
111
|
+
|
|
112
|
+
return client;
|
|
113
|
+
},
|
|
114
|
+
leads: leads(ctx),
|
|
115
|
+
channels: channels(ctx),
|
|
116
|
+
estates: estates(ctx),
|
|
117
|
+
channelAccounts: channelAccounts(ctx),
|
|
118
|
+
companies: companies(ctx),
|
|
119
|
+
contacts: contacts(ctx),
|
|
120
|
+
contactPreferences: contact_preferences(ctx),
|
|
121
|
+
negotiators: negotiators(ctx),
|
|
122
|
+
offices: offices(ctx),
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return client;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { createClient, Env, Client };
|