@sweepbright/api-client 0.31.6 → 0.31.8-pre-release.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/common/currencies.d.ts +50 -0
  2. package/dist/common/currencies.js +55 -0
  3. package/dist/common/currencies.js.map +1 -0
  4. package/dist/common/envHosts.d.ts +2 -0
  5. package/dist/common/envHosts.js +10 -0
  6. package/dist/common/envHosts.js.map +1 -0
  7. package/dist/common/types.d.ts +1 -0
  8. package/dist/common/types.js +3 -0
  9. package/dist/common/types.js.map +1 -0
  10. package/dist/entities/negotiator.d.ts +11 -0
  11. package/dist/entities/negotiator.js +3 -0
  12. package/dist/entities/negotiator.js.map +1 -0
  13. package/dist/entities/office.d.ts +16 -0
  14. package/dist/entities/office.js +9 -0
  15. package/dist/entities/office.js.map +1 -0
  16. package/dist/entities/property.d.ts +516 -0
  17. package/dist/entities/property.js +220 -0
  18. package/dist/entities/property.js.map +1 -0
  19. package/dist/index.d.ts +26 -0
  20. package/dist/index.js +124 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/oauth-manager/AuthenticationService_PrivateAPI.d.ts +20 -0
  23. package/dist/oauth-manager/AuthenticationService_PrivateAPI.js +54 -0
  24. package/dist/oauth-manager/AuthenticationService_PrivateAPI.js.map +1 -0
  25. package/dist/oauth-manager/OAuthManager_Impl.d.ts +10 -0
  26. package/dist/oauth-manager/OAuthManager_Impl.js +96 -0
  27. package/dist/oauth-manager/OAuthManager_Impl.js.map +1 -0
  28. package/dist/oauth-manager/SessionDataImpl.d.ts +18 -0
  29. package/dist/oauth-manager/SessionDataImpl.js +47 -0
  30. package/dist/oauth-manager/SessionDataImpl.js.map +1 -0
  31. package/dist/oauth-manager/TokensRepository_Memory.d.ts +8 -0
  32. package/dist/oauth-manager/TokensRepository_Memory.js +102 -0
  33. package/dist/oauth-manager/TokensRepository_Memory.js.map +1 -0
  34. package/dist/oauth-manager/TokensRepository_Redis.d.ts +13 -0
  35. package/dist/oauth-manager/TokensRepository_Redis.js +69 -0
  36. package/dist/oauth-manager/TokensRepository_Redis.js.map +1 -0
  37. package/dist/oauth-manager/factories/createOAuthManager.d.ts +16 -0
  38. package/dist/oauth-manager/factories/createOAuthManager.js +23 -0
  39. package/dist/oauth-manager/factories/createOAuthManager.js.map +1 -0
  40. package/dist/oauth-manager/interfaces.d.ts +56 -0
  41. package/dist/oauth-manager/interfaces.js +3 -0
  42. package/dist/oauth-manager/interfaces.js.map +1 -0
  43. package/dist/oauth-manager/playground/main.d.ts +1 -0
  44. package/dist/oauth-manager/playground/main.js +42 -0
  45. package/dist/oauth-manager/playground/main.js.map +1 -0
  46. package/dist/resources/channel_accounts.d.ts +15 -0
  47. package/dist/resources/channel_accounts.js +31 -0
  48. package/dist/resources/channel_accounts.js.map +1 -0
  49. package/dist/resources/channels.d.ts +16 -0
  50. package/dist/resources/channels.js +32 -0
  51. package/dist/resources/channels.js.map +1 -0
  52. package/dist/resources/companies.d.ts +7 -0
  53. package/dist/resources/companies.js +16 -0
  54. package/dist/resources/companies.js.map +1 -0
  55. package/dist/resources/contact_preferences.d.ts +6 -0
  56. package/dist/resources/contact_preferences.js +14 -0
  57. package/dist/resources/contact_preferences.js.map +1 -0
  58. package/dist/resources/contacts.d.ts +14 -0
  59. package/dist/resources/contacts.js +29 -0
  60. package/dist/resources/contacts.js.map +1 -0
  61. package/dist/resources/estates.d.ts +43 -0
  62. package/dist/resources/estates.js +73 -0
  63. package/dist/resources/estates.js.map +1 -0
  64. package/dist/resources/leads.d.ts +39 -0
  65. package/dist/resources/leads.js +26 -0
  66. package/dist/resources/leads.js.map +1 -0
  67. package/dist/resources/negotiators.d.ts +9 -0
  68. package/dist/resources/negotiators.js +16 -0
  69. package/dist/resources/negotiators.js.map +1 -0
  70. package/dist/resources/offices.d.ts +8 -0
  71. package/dist/resources/offices.js +19 -0
  72. package/dist/resources/offices.js.map +1 -0
  73. package/dist/schemas/currenciesSchema.d.ts +3 -0
  74. package/dist/schemas/currenciesSchema.js +8 -0
  75. package/dist/schemas/currenciesSchema.js.map +1 -0
  76. package/dist/schemas/officeSchema.d.ts +7459 -0
  77. package/dist/schemas/officeSchema.js +214 -0
  78. package/dist/schemas/officeSchema.js.map +1 -0
  79. package/dist/types.d.ts +76 -0
  80. package/dist/types.js +40 -0
  81. package/dist/types.js.map +1 -0
  82. package/dist/utils.d.ts +7 -0
  83. package/dist/utils.js +28 -0
  84. package/dist/utils.js.map +1 -0
  85. package/package.json +9 -2
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InternalType = exports.LandUseDesignation = exports.Shape = exports.FloodRisk = exports.EnergyReport = exports.EnergyCategoryExtended = exports.EnergyCategory = exports.Orientation = exports.Condition = exports.Negotiation = exports.PropertyType = exports.PropertySubType = exports.PropertyStatus = exports.AreaType = exports.MeasurementSystem = exports.UnitOfMeasurement = exports.Amenity = exports.ADScale = void 0;
4
+ var ADScale;
5
+ (function (ADScale) {
6
+ ADScale["A"] = "A";
7
+ ADScale["B"] = "B";
8
+ ADScale["C"] = "C";
9
+ ADScale["D"] = "D";
10
+ })(ADScale || (exports.ADScale = ADScale = {}));
11
+ var Amenity;
12
+ (function (Amenity) {
13
+ Amenity["Attic"] = "attic";
14
+ Amenity["Balcony"] = "balcony";
15
+ Amenity["Basement"] = "basement";
16
+ Amenity["ClimateControl"] = "climate_control";
17
+ Amenity["Code"] = "code";
18
+ Amenity["CoolingRoom"] = "cooling_room";
19
+ Amenity["DisplayWindow"] = "display_window";
20
+ Amenity["Drainage"] = "drainage";
21
+ Amenity["ElectricalGate"] = "electrical_gate";
22
+ Amenity["ExteriorParking"] = "exterior_parking";
23
+ Amenity["Fence"] = "fence";
24
+ Amenity["Fenced"] = "fenced";
25
+ Amenity["Garden"] = "garden";
26
+ Amenity["Guesthouse"] = "guesthouse";
27
+ Amenity["InteriorParking"] = "interior_parking";
28
+ Amenity["KeyCard"] = "key_card";
29
+ Amenity["Lift"] = "lift";
30
+ Amenity["ManualGate"] = "manual_gate";
31
+ Amenity["Parking"] = "parking";
32
+ Amenity["Pool"] = "pool";
33
+ Amenity["PrintAndCopyArea"] = "print_and_copy_area";
34
+ Amenity["ReceptionArea"] = "reception_area";
35
+ Amenity["RoadAccess"] = "road_access";
36
+ Amenity["ServerRoom"] = "server_room";
37
+ Amenity["SewerAccess"] = "sewer_access";
38
+ Amenity["StorageSpace"] = "storage_space";
39
+ Amenity["Terrace"] = "terrace";
40
+ Amenity["UtilitiesAccess"] = "utilities_access";
41
+ Amenity["WaitingArea"] = "waiting_area";
42
+ Amenity["WaterAccess"] = "water_access";
43
+ })(Amenity || (exports.Amenity = Amenity = {}));
44
+ var UnitOfMeasurement;
45
+ (function (UnitOfMeasurement) {
46
+ UnitOfMeasurement["cm"] = "cm";
47
+ UnitOfMeasurement["inch"] = "inch";
48
+ UnitOfMeasurement["sq_m"] = "sq_m";
49
+ UnitOfMeasurement["sq_ft"] = "sq_ft";
50
+ })(UnitOfMeasurement || (exports.UnitOfMeasurement = UnitOfMeasurement = {}));
51
+ var MeasurementSystem;
52
+ (function (MeasurementSystem) {
53
+ MeasurementSystem["Metric"] = "metric";
54
+ MeasurementSystem["Imperial"] = "imperial";
55
+ })(MeasurementSystem || (exports.MeasurementSystem = MeasurementSystem = {}));
56
+ var AreaType;
57
+ (function (AreaType) {
58
+ AreaType["Bathrooms"] = "bathrooms";
59
+ AreaType["Bedrooms"] = "bedrooms";
60
+ AreaType["ClosedOfficeSpaces"] = "closed_office_spaces";
61
+ AreaType["ConferenceRooms"] = "conference_rooms";
62
+ AreaType["Floors"] = "floors";
63
+ AreaType["Kitchens"] = "kitchens";
64
+ AreaType["LivingRoom"] = "living_room";
65
+ AreaType["ManufacturingAreas"] = "manufacturing_areas";
66
+ AreaType["MeetingRooms"] = "meeting_rooms";
67
+ AreaType["OpenOfficeSpaces"] = "open_office_spaces";
68
+ AreaType["ParkingSpaces"] = "parking_spaces";
69
+ AreaType["Showrooms"] = "showrooms";
70
+ AreaType["StorageRooms"] = "storage_rooms";
71
+ AreaType["Toilets"] = "toilets";
72
+ })(AreaType || (exports.AreaType = AreaType = {}));
73
+ var PropertyStatus;
74
+ (function (PropertyStatus) {
75
+ PropertyStatus["prospect"] = "prospect";
76
+ PropertyStatus["lost"] = "lost";
77
+ PropertyStatus["available"] = "available";
78
+ PropertyStatus["rented"] = "rented";
79
+ PropertyStatus["sold"] = "sold";
80
+ PropertyStatus["bid"] = "bid";
81
+ PropertyStatus["option"] = "option";
82
+ PropertyStatus["under_contract"] = "under_contract";
83
+ })(PropertyStatus || (exports.PropertyStatus = PropertyStatus = {}));
84
+ var PropertySubType;
85
+ (function (PropertySubType) {
86
+ PropertySubType["duplex"] = "duplex";
87
+ PropertySubType["agricultural"] = "agricultural";
88
+ PropertySubType["pasture_land"] = "pasture_land";
89
+ PropertySubType["private_garage"] = "private_garage";
90
+ PropertySubType["loft"] = "loft";
91
+ PropertySubType["recreational"] = "recreational";
92
+ PropertySubType["investment_property"] = "investment_property";
93
+ PropertySubType["mansion"] = "mansion";
94
+ PropertySubType["terraced"] = "terraced";
95
+ PropertySubType["townhouse"] = "townhouse";
96
+ PropertySubType["condo"] = "condo";
97
+ PropertySubType["penthouse"] = "penthouse";
98
+ PropertySubType["farm"] = "farm";
99
+ PropertySubType["cottage"] = "cottage";
100
+ PropertySubType["buildable"] = "buildable";
101
+ PropertySubType["villa"] = "villa";
102
+ PropertySubType["retail"] = "retail";
103
+ PropertySubType["covered_outdoor_space"] = "covered_outdoor_space";
104
+ PropertySubType["indoor_parking_space"] = "indoor_parking_space";
105
+ PropertySubType["flex_office"] = "flex_office";
106
+ PropertySubType["open_office"] = "open_office";
107
+ PropertySubType["industrial"] = "industrial";
108
+ PropertySubType["restaurant_and_cafe"] = "restaurant_and_cafe";
109
+ PropertySubType["student_accommodation"] = "student_accommodation";
110
+ PropertySubType["leisure_and_sports"] = "leasure_and_sports";
111
+ PropertySubType["outdoor_parking_space"] = "outdoor_parking_space";
112
+ PropertySubType["coworking"] = "coworking";
113
+ PropertySubType["warehouse"] = "warehouse";
114
+ PropertySubType["shop"] = "shop";
115
+ PropertySubType["semi_detached"] = "semi_detached";
116
+ PropertySubType["healthcare"] = "healthcare";
117
+ PropertySubType["detached"] = "detached";
118
+ PropertySubType["bungalow"] = "bungalow";
119
+ })(PropertySubType || (exports.PropertySubType = PropertySubType = {}));
120
+ var PropertyType;
121
+ (function (PropertyType) {
122
+ PropertyType["apartment"] = "apartment";
123
+ PropertyType["house"] = "house";
124
+ PropertyType["land"] = "land";
125
+ PropertyType["office"] = "office";
126
+ PropertyType["parking"] = "parking";
127
+ PropertyType["commercial"] = "commercial";
128
+ })(PropertyType || (exports.PropertyType = PropertyType = {}));
129
+ var Negotiation;
130
+ (function (Negotiation) {
131
+ Negotiation["sale"] = "sale";
132
+ Negotiation["let"] = "let";
133
+ })(Negotiation || (exports.Negotiation = Negotiation = {}));
134
+ var Condition;
135
+ (function (Condition) {
136
+ Condition["new"] = "new";
137
+ Condition["good"] = "good";
138
+ Condition["mint"] = "mint";
139
+ Condition["poor"] = "poor";
140
+ Condition["fair"] = "fair";
141
+ })(Condition || (exports.Condition = Condition = {}));
142
+ var Orientation;
143
+ (function (Orientation) {
144
+ Orientation["N"] = "N";
145
+ Orientation["S"] = "S";
146
+ Orientation["E"] = "E";
147
+ Orientation["W"] = "W";
148
+ Orientation["NE"] = "NE";
149
+ Orientation["NW"] = "NW";
150
+ Orientation["SE"] = "SE";
151
+ Orientation["SW"] = "SW";
152
+ })(Orientation || (exports.Orientation = Orientation = {}));
153
+ var EnergyCategory;
154
+ (function (EnergyCategory) {
155
+ EnergyCategory["A"] = "A";
156
+ EnergyCategory["B"] = "B";
157
+ EnergyCategory["C"] = "C";
158
+ EnergyCategory["D"] = "D";
159
+ EnergyCategory["E"] = "E";
160
+ EnergyCategory["F"] = "F";
161
+ EnergyCategory["G"] = "G";
162
+ })(EnergyCategory || (exports.EnergyCategory = EnergyCategory = {}));
163
+ var EnergyCategoryExtended;
164
+ (function (EnergyCategoryExtended) {
165
+ EnergyCategoryExtended["A_PLUS_PLUS"] = "A++";
166
+ EnergyCategoryExtended["A_PLUS"] = "A+";
167
+ EnergyCategoryExtended["A"] = "A";
168
+ EnergyCategoryExtended["B"] = "B";
169
+ EnergyCategoryExtended["C"] = "C";
170
+ EnergyCategoryExtended["D"] = "D";
171
+ EnergyCategoryExtended["E"] = "E";
172
+ EnergyCategoryExtended["F"] = "F";
173
+ EnergyCategoryExtended["G"] = "G";
174
+ })(EnergyCategoryExtended || (exports.EnergyCategoryExtended = EnergyCategoryExtended = {}));
175
+ var EnergyReport;
176
+ (function (EnergyReport) {
177
+ EnergyReport["conform"] = "conform";
178
+ EnergyReport["not_conform"] = "not_conform";
179
+ EnergyReport["no_report"] = "no_report";
180
+ EnergyReport["not_applicable"] = "not_applicable";
181
+ })(EnergyReport || (exports.EnergyReport = EnergyReport = {}));
182
+ var FloodRisk;
183
+ (function (FloodRisk) {
184
+ FloodRisk["no_flood_risk_area"] = "no_flood_risk_area";
185
+ FloodRisk["potential_flood_sensitive_area"] = "potential_flood_sensitive_area";
186
+ FloodRisk["effective_flood_sensitive_area"] = "effective_flood_sensitive_area";
187
+ })(FloodRisk || (exports.FloodRisk = FloodRisk = {}));
188
+ var Shape;
189
+ (function (Shape) {
190
+ Shape["flat"] = "flat";
191
+ Shape["sloped"] = "sloped";
192
+ Shape["wooded"] = "wooded";
193
+ Shape["has_rivers_lakes_or_ponds"] = "has_rivers_lakes_or_ponds";
194
+ Shape["single"] = "single";
195
+ Shape["double"] = "double";
196
+ })(Shape || (exports.Shape = Shape = {}));
197
+ var LandUseDesignation;
198
+ (function (LandUseDesignation) {
199
+ LandUseDesignation["residential"] = "residential";
200
+ LandUseDesignation["mixed_residential"] = "mixed_residential";
201
+ LandUseDesignation["industrial"] = "industrial";
202
+ LandUseDesignation["recreational"] = "recreational";
203
+ LandUseDesignation["park"] = "park";
204
+ LandUseDesignation["area_with_economical_activity"] = "area_with_economical_activity";
205
+ LandUseDesignation["forest_area"] = "forest_area";
206
+ LandUseDesignation["agricultural"] = "agricultural";
207
+ LandUseDesignation["nature_area"] = "nature_area";
208
+ LandUseDesignation["natural_reserve"] = "natural_reserve";
209
+ LandUseDesignation["residential_area_with_cultural_historical_value"] = "residential_area_with_cultural_historical_value";
210
+ LandUseDesignation["industrial_area_for_sme"] = "industrial_area_for_sme";
211
+ LandUseDesignation["day_recreation_area"] = "day_recreation_area";
212
+ LandUseDesignation["other"] = "other";
213
+ })(LandUseDesignation || (exports.LandUseDesignation = LandUseDesignation = {}));
214
+ var InternalType;
215
+ (function (InternalType) {
216
+ InternalType["project"] = "project";
217
+ InternalType["unit"] = "unit";
218
+ InternalType["standalone"] = "standalone";
219
+ })(InternalType || (exports.InternalType = InternalType = {}));
220
+ //# sourceMappingURL=property.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.js","sourceRoot":"","sources":["../../src/entities/property.ts"],"names":[],"mappings":";;;AAKA,IAAY,OAKX;AALD,WAAY,OAAO;IACjB,kBAAO,CAAA;IACP,kBAAO,CAAA;IACP,kBAAO,CAAA;IACP,kBAAO,CAAA;AACT,CAAC,EALW,OAAO,uBAAP,OAAO,QAKlB;AAED,IAAY,OA+BX;AA/BD,WAAY,OAAO;IACjB,0BAAe,CAAA;IACf,8BAAmB,CAAA;IACnB,gCAAqB,CAAA;IACrB,6CAAkC,CAAA;IAClC,wBAAa,CAAA;IACb,uCAA4B,CAAA;IAC5B,2CAAgC,CAAA;IAChC,gCAAqB,CAAA;IACrB,6CAAkC,CAAA;IAClC,+CAAoC,CAAA;IACpC,0BAAe,CAAA;IACf,4BAAiB,CAAA;IACjB,4BAAiB,CAAA;IACjB,oCAAyB,CAAA;IACzB,+CAAoC,CAAA;IACpC,+BAAoB,CAAA;IACpB,wBAAa,CAAA;IACb,qCAA0B,CAAA;IAC1B,8BAAmB,CAAA;IACnB,wBAAa,CAAA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AA;IAC7B,mCAAa,CAAA;IACb,qFAA+D,CAAA;IAC/D,iDAA2B,CAAA;IAC3B,mDAA6B,CAAA;IAC7B,iDAA2B,CAAA;IAC3B,yDAAmC,CAAA;IACnC,yHAAmG,CAAA;IACnG,yEAAmD,CAAA;IACnD,iEAA2C,CAAA;IAC3C,qCAAe,CAAA;AACjB,CAAC,EAfW,kBAAkB,kCAAlB,kBAAkB,QAe7B;AAkWD,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,mCAAmB,CAAA;IACnB,6BAAa,CAAA;IACb,yCAAyB,CAAA;AAC3B,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB"}
@@ -0,0 +1,26 @@
1
+ import { createOAuthManager } from './oauth-manager/factories/createOAuthManager';
2
+ import channelAccounts from './resources/channel_accounts';
3
+ import channels from './resources/channels';
4
+ import companies from './resources/companies';
5
+ import contact_preferences from './resources/contact_preferences';
6
+ import contacts from './resources/contacts';
7
+ import estates from './resources/estates';
8
+ import leads from './resources/leads';
9
+ import negotiators from './resources/negotiators';
10
+ import offices from './resources/offices';
11
+ import { ClientConf, Env, InitConf } from './types';
12
+ interface Client {
13
+ authorize(config?: InitConf): Promise<Client>;
14
+ withUserToken(accessToken: string): Promise<Client>;
15
+ leads: ReturnType<typeof leads>;
16
+ negotiators: ReturnType<typeof negotiators>;
17
+ offices: ReturnType<typeof offices>;
18
+ contacts: ReturnType<typeof contacts>;
19
+ channelAccounts: ReturnType<typeof channelAccounts>;
20
+ channels: ReturnType<typeof channels>;
21
+ companies: ReturnType<typeof companies>;
22
+ contactPreferences: ReturnType<typeof contact_preferences>;
23
+ estates: ReturnType<typeof estates>;
24
+ }
25
+ declare function createClient(conf: ClientConf): Client;
26
+ export { Client, Env, createClient, createOAuthManager };
package/dist/index.js ADDED
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createOAuthManager = exports.createClient = exports.Env = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
9
+ const envHosts_1 = require("./common/envHosts");
10
+ const SessionDataImpl_1 = require("./oauth-manager/SessionDataImpl");
11
+ const createOAuthManager_1 = require("./oauth-manager/factories/createOAuthManager");
12
+ Object.defineProperty(exports, "createOAuthManager", { enumerable: true, get: function () { return createOAuthManager_1.createOAuthManager; } });
13
+ const channel_accounts_1 = __importDefault(require("./resources/channel_accounts"));
14
+ const channels_1 = __importDefault(require("./resources/channels"));
15
+ const companies_1 = __importDefault(require("./resources/companies"));
16
+ const contact_preferences_1 = __importDefault(require("./resources/contact_preferences"));
17
+ const contacts_1 = __importDefault(require("./resources/contacts"));
18
+ const estates_1 = __importDefault(require("./resources/estates"));
19
+ const leads_1 = __importDefault(require("./resources/leads"));
20
+ const negotiators_1 = __importDefault(require("./resources/negotiators"));
21
+ const offices_1 = __importDefault(require("./resources/offices"));
22
+ const types_1 = require("./types");
23
+ Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return types_1.Env; } });
24
+ const utils_1 = require("./utils");
25
+ function createClient(conf) {
26
+ const { clientId, clientSecret, oauthManager, env = types_1.Env.PRODUCTION, version, } = conf;
27
+ let _auth = null;
28
+ let _oAuthManagerInvalidateInterceptor;
29
+ const httpClient = axios_1.default.create({
30
+ baseURL: envHosts_1.envHosts[env],
31
+ });
32
+ //TODO: getData here is an antipattern. Interceptor should not change a type of response
33
+ httpClient.interceptors.response.use(utils_1.getData, utils_1.handleRequestFailure);
34
+ httpClient.interceptors.response.use(undefined, (e) => {
35
+ if (_oAuthManagerInvalidateInterceptor) {
36
+ return _oAuthManagerInvalidateInterceptor(e);
37
+ }
38
+ return e;
39
+ });
40
+ if (version) {
41
+ httpClient.defaults.headers.common['Accept'] = `application/vnd.sweepbright.${version}+json`;
42
+ }
43
+ const ctx = {
44
+ httpClient,
45
+ checkAuth(tokenType) {
46
+ if (!_auth) {
47
+ throw new Error('client is not authenticated');
48
+ }
49
+ if (_auth.type !== tokenType) {
50
+ throw new Error('authenticated with invalid token type');
51
+ }
52
+ },
53
+ };
54
+ async function authorizeWithOAuthManager(oauthManager, clientId, clientSecret, scopes, options) {
55
+ const accessToken = await oauthManager.getAccessTokenBySessionData(new SessionDataImpl_1.SessionDataImpl({
56
+ clientId,
57
+ clientSecret,
58
+ scopes,
59
+ }), options);
60
+ if (!accessToken) {
61
+ throw new Error('Authentication failed');
62
+ }
63
+ _auth = {
64
+ token: accessToken,
65
+ type: types_1.TokenType.API_TOKEN,
66
+ };
67
+ httpClient.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
68
+ }
69
+ const client = {
70
+ async authorize(config = {}) {
71
+ const { scopes = ['companies:read', 'properties:download', 'lead_info:write'], } = config;
72
+ (0, tiny_invariant_1.default)(clientId, 'missing client id');
73
+ (0, tiny_invariant_1.default)(clientSecret, 'missing client secret');
74
+ if (oauthManager) {
75
+ await authorizeWithOAuthManager(oauthManager, clientId, clientSecret, scopes);
76
+ _oAuthManagerInvalidateInterceptor = async (e) => {
77
+ // If the token is invalid, try to re-authorize
78
+ if (e.status && e.status === 401) {
79
+ await authorizeWithOAuthManager(oauthManager, clientId, clientSecret, scopes, { forceInvalidate: true });
80
+ }
81
+ return e;
82
+ };
83
+ return client;
84
+ }
85
+ return httpClient
86
+ .post('/auth/access-token', {
87
+ client_id: clientId,
88
+ client_secret: clientSecret,
89
+ grant_type: 'client_credentials',
90
+ scope: scopes.join(','),
91
+ })
92
+ .then(({ access_token }) => {
93
+ (0, tiny_invariant_1.default)(access_token, 'access token should be defined');
94
+ _auth = {
95
+ token: access_token,
96
+ type: types_1.TokenType.API_TOKEN,
97
+ };
98
+ // https://github.com/axios/axios#custom-instance-defaults
99
+ httpClient.defaults.headers.common['Authorization'] = `Bearer ${_auth.token}`;
100
+ return client;
101
+ });
102
+ },
103
+ withUserToken: async (accessToken) => {
104
+ _auth = {
105
+ token: accessToken,
106
+ type: types_1.TokenType.USER_TOKEN,
107
+ };
108
+ httpClient.defaults.headers.common['Authorization'] = `Bearer ${_auth.token}`;
109
+ return client;
110
+ },
111
+ leads: (0, leads_1.default)(ctx),
112
+ channels: (0, channels_1.default)(ctx),
113
+ estates: (0, estates_1.default)(ctx),
114
+ channelAccounts: (0, channel_accounts_1.default)(ctx),
115
+ companies: (0, companies_1.default)(ctx),
116
+ contacts: (0, contacts_1.default)(ctx),
117
+ contactPreferences: (0, contact_preferences_1.default)(ctx),
118
+ negotiators: (0, negotiators_1.default)(ctx),
119
+ offices: (0, offices_1.default)(ctx),
120
+ };
121
+ return client;
122
+ }
123
+ exports.createClient = createClient;
124
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,oEAAuC;AACvC,gDAA6C;AAC7C,qEAAkE;AAClE,qFAAkF;AA8L9C,mGA9L3B,uCAAkB,OA8L2B;AAzLtD,oFAA2D;AAC3D,oEAA4C;AAC5C,sEAA8C;AAC9C,0FAAkE;AAClE,oEAA4C;AAC5C,kEAA0C;AAC1C,8DAAsC;AACtC,0EAAkD;AAClD,kEAA0C;AAC1C,mCAA4E;AAgL3D,oFAhLU,WAAG,OAgLV;AA/KpB,mCAAwD;AAgBxD,SAAS,YAAY,CAAC,IAAgB;IACpC,MAAM,EACJ,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,GAAG,GAAG,WAAG,CAAC,UAAU,EACpB,OAAO,GACR,GAAG,IAAI,CAAC;IACT,IAAI,KAAK,GAAgB,IAAI,CAAC;IAC9B,IAAI,kCAAuD,CAAC;IAE5D,MAAM,UAAU,GAAG,eAAK,CAAC,MAAM,CAAC;QAC9B,OAAO,EAAE,mBAAQ,CAAC,GAAG,CAAC;KACvB,CAAC,CAAC;IAEH,wFAAwF;IACxF,UAAU,CA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CAAC,KAAK,EAAE,CAAC;gBAC5B,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC,CAAC;QACP,CAAC;QACD,aAAa,EAAE,KAAK,EAAE,WAAmB,EAAmB,EAAE;YAC5D,KAAK,GAAG;gBACN,KAAK,EAAE,WAAW;gBAClB,IAAI,EAAE,iBAAS,CAAC,UAAU;aAC3B,CAAC;YAEF,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAChC,eAAe,CAChB,GAAG,UAAU,KAAK,CAAC,KAAK,EAAE,CAAC;YAE5B,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,KAAK,EAAE,IAAA,eAAK,EAAC,GAAG,CAAC;QACjB,QAAQ,EAAE,IAAA,kBAAQ,EAAC,GAAG,CAAC;QACvB,OAAO,EAAE,IAAA,iBAAO,EAAC,GAAG,CAAC;QACrB,eAAe,EAAE,IAAA,0BAAe,EAAC,GAAG,CAAC;QACrC,SAAS,EAAE,IAAA,mBAAS,EAAC,GAAG,CAAC;QACzB,QAAQ,EAAE,IAAA,kBAAQ,EAAC,GAAG,CAAC;QACvB,kBAAkB,EAAE,IAAA,6BAAmB,EAAC,GAAG,CAAC;QAC5C,WAAW,EAAE,IAAA,qBAAW,EAAC,GAAG,CAAC;QAC7B,OAAO,EAAE,IAAA,iBAAO,EAAC,GAAG,CAAC;KACtB,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AAEqB,oCAAY"}
@@ -0,0 +1,20 @@
1
+ import { AuthenticationService, SessionData, Tokens } from './interfaces';
2
+ interface AuthenticationServicePrivateAPIOptions {
3
+ baseUrl: string;
4
+ apiVersion: string;
5
+ }
6
+ /**
7
+ * AuthenticationService_PrivateAPI is used for authentication
8
+ * (exchanging the client credentials for an access token)
9
+ *
10
+ * This is the implementation of the {@link AuthenticationService} interface
11
+ * which uses Private API for authentication.
12
+ *
13
+ * Do not use this class directly.
14
+ */
15
+ export declare class AuthenticationService_PrivateAPI implements AuthenticationService {
16
+ private httpClient;
17
+ constructor(options: AuthenticationServicePrivateAPIOptions);
18
+ authenticate(sessionData: SessionData): Promise<Tokens | null>;
19
+ }
20
+ export {};
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AuthenticationService_PrivateAPI = void 0;
7
+ const assert_1 = require("assert");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ /**
10
+ * AuthenticationService_PrivateAPI is used for authentication
11
+ * (exchanging the client credentials for an access token)
12
+ *
13
+ * This is the implementation of the {@link AuthenticationService} interface
14
+ * which uses Private API for authentication.
15
+ *
16
+ * Do not use this class directly.
17
+ */
18
+ class AuthenticationService_PrivateAPI {
19
+ constructor(options) {
20
+ this.httpClient = axios_1.default.create({
21
+ baseURL: options.baseUrl,
22
+ headers: {
23
+ Accept: `application/vnd.sweepbright.${options.apiVersion}+json`,
24
+ },
25
+ });
26
+ }
27
+ async authenticate(sessionData) {
28
+ const request = {
29
+ client_id: sessionData.getCredentials().clientId,
30
+ client_secret: sessionData.getCredentials().clientSecret,
31
+ scope: sessionData.getScopes().join(','),
32
+ grant_type: 'client_credentials',
33
+ };
34
+ const response = await this.httpClient.post('/auth/access-token', request, {
35
+ validateStatus(status) {
36
+ return status === 200 || status === 401;
37
+ },
38
+ });
39
+ if (response.status === 401) {
40
+ return null;
41
+ }
42
+ const { data: { access_token, expires_in, token_type }, } = response;
43
+ (0, assert_1.ok)(access_token, 'access token should be defined');
44
+ (0, assert_1.ok)(expires_in, 'expires_in should be defined');
45
+ (0, assert_1.strictEqual)(token_type, 'Bearer', 'token_type should be Bearer');
46
+ const tokens = {
47
+ accessToken: access_token,
48
+ expiresIn: expires_in,
49
+ };
50
+ return tokens;
51
+ }
52
+ }
53
+ exports.AuthenticationService_PrivateAPI = AuthenticationService_PrivateAPI;
54
+ //# sourceMappingURL=AuthenticationService_PrivateAPI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthenticationService_PrivateAPI.js","sourceRoot":"","sources":["../../src/oauth-manager/AuthenticationService_PrivateAPI.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAyC;AACzC,kDAA6C;AAQ7C;;;;;;;;GAQG;AACH,MAAa,gCAAgC;IAG3C,YAAY,OAA+C;QACzD,IAAI,CAAC,UAAU,GAAG,eAAK,CAAC,MAAM,CAAC;YAC7B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE;gBACP,MAAM,EAAE,+BAA+B,OAAO,CAAC,UAAU,OAAO;aACjE;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,WAAwB;QACzC,MAAM,OAAO,GAAG;YACd,SAAS,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,QAAQ;YAChD,aAAa,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,YAAY;YACxD,KAAK,EAAE,WAAW,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;YACxC,UAAU,EAAE,oBAAoB;SACjC,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,oBAAoB,EAAE,OAAO,EAAE;YACzE,cAAc,CAAC,MAAM;gBACnB,OAAO,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC;YAC1C,CAAC;SACF,CAAC,CAAC;QACH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;YAC3B,OAAO,IAAI,CAAC;SACb;QACD,MAAM,EACJ,IAAI,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,GAC/C,GAAG,QAAQ,CAAC;QACb,IAAA,WAAE,EAAC,YAAY,EAAE,gCAAgC,CAAC,CAAC;QACnD,IAAA,WAAE,EAAC,UAAU,EAAE,8BAA8B,CAAC,CAAC;QAC/C,IAAA,oBAAW,EAAC,UAAU,EAAE,QAAQ,EAAE,6BAA6B,CAAC,CAAC;QAEjE,MAAM,MAAM,GAAW;YACrB,WAAW,EAAE,YAAY;YACzB,SAAS,EAAE,UAAU;SACtB,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1CD,4EA0CC"}
@@ -0,0 +1,10 @@
1
+ import { AuthenticationService, GetAccessTokenOptions, OAuthManager, SessionData, TokensRepository } from './interfaces';
2
+ export declare class OAuthManager_Impl implements OAuthManager {
3
+ private readonly tokensRepository;
4
+ private readonly authenticationService;
5
+ constructor(tokensRepository: TokensRepository, authenticationService: AuthenticationService);
6
+ private getLockTimeFromCurrentTime;
7
+ private sleep;
8
+ private expiresInToExpiresAt;
9
+ getAccessTokenBySessionData(sessionData: SessionData, options?: GetAccessTokenOptions): Promise<string | null>;
10
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuthManager_Impl = void 0;
4
+ const SECOND = 1000;
5
+ const LOCK_TTL = 10 * SECOND;
6
+ const MANAGER_POLLING_INTERVAL = 2 * SECOND;
7
+ const MANAGER_POLLING_TIMEOUT = 20 * SECOND;
8
+ class OAuthManager_Impl {
9
+ constructor(tokensRepository, authenticationService) {
10
+ this.tokensRepository = tokensRepository;
11
+ this.authenticationService = authenticationService;
12
+ }
13
+ getLockTimeFromCurrentTime(currentTime) {
14
+ return new Date(currentTime.getTime() + LOCK_TTL);
15
+ }
16
+ async sleep(ms) {
17
+ return new Promise((resolve) => setTimeout(resolve, ms));
18
+ }
19
+ expiresInToExpiresAt(expiresIn, issuedAt) {
20
+ return new Date(issuedAt.getTime() + expiresIn * SECOND);
21
+ }
22
+ async getAccessTokenBySessionData(sessionData, options = {}) {
23
+ const { forceInvalidate } = options;
24
+ const sessionKey = sessionData.getSessionKey();
25
+ if (!forceInvalidate) {
26
+ const accessToken = await this.tokensRepository.getAccessTokenIfValid(sessionKey, new Date());
27
+ if (accessToken) {
28
+ console.log('access token reused');
29
+ return accessToken;
30
+ }
31
+ }
32
+ const lockAcquiredAt = new Date();
33
+ const lockId = await this.tokensRepository.acquireLock({
34
+ currentTime: lockAcquiredAt,
35
+ sessionKey,
36
+ lockedUntil: this.getLockTimeFromCurrentTime(lockAcquiredAt),
37
+ });
38
+ if (lockId) {
39
+ let tokens = null;
40
+ const cleanUpLock = async () => {
41
+ await this.tokensRepository.releaseLock(lockId, {
42
+ shouldUpdateTokens: false,
43
+ sessionKey,
44
+ });
45
+ };
46
+ try {
47
+ if (forceInvalidate) {
48
+ // Remove ASAP the token to be invalidated
49
+ await this.tokensRepository.deleteAccessToken(lockId, sessionKey);
50
+ }
51
+ console.log('authentication');
52
+ tokens = await this.authenticationService.authenticate(sessionData);
53
+ }
54
+ catch (e) {
55
+ console.log('authentication failed, error', e);
56
+ await cleanUpLock();
57
+ throw new Error('Failed to authenticate');
58
+ }
59
+ const issuedAt = new Date();
60
+ if (!tokens) {
61
+ console.log('authentication failed, wrong credentials');
62
+ await cleanUpLock();
63
+ return null;
64
+ }
65
+ console.log('authentication succeeded');
66
+ await this.tokensRepository.releaseLock(lockId, {
67
+ shouldUpdateTokens: true,
68
+ sessionKey,
69
+ tokens,
70
+ expiresAt: this.expiresInToExpiresAt(tokens.expiresIn, issuedAt),
71
+ currentTime: issuedAt,
72
+ });
73
+ return tokens.accessToken;
74
+ }
75
+ else {
76
+ // Locked by another process. We need to wait for the token
77
+ // to become available (using polling).
78
+ // Or fail on timeout.
79
+ const startedAt = new Date();
80
+ for (;;) {
81
+ const accessToken = await this.tokensRepository.getAccessTokenIfValid(sessionKey, new Date());
82
+ if (accessToken) {
83
+ console.log('access token reused');
84
+ return accessToken;
85
+ }
86
+ if (new Date().getTime() >
87
+ startedAt.getTime() + MANAGER_POLLING_TIMEOUT) {
88
+ throw new Error('Timed out');
89
+ }
90
+ await this.sleep(MANAGER_POLLING_INTERVAL);
91
+ }
92
+ }
93
+ }
94
+ }
95
+ exports.OAuthManager_Impl = OAuthManager_Impl;
96
+ //# sourceMappingURL=OAuthManager_Impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OAuthManager_Impl.js","sourceRoot":"","sources":["../../src/oauth-manager/OAuthManager_Impl.ts"],"names":[],"mappings":";;;AASA,MAAM,MAAM,GAAG,IAAI,CAAC;AAEpB,MAAM,QAAQ,GAAG,EAAE,GAAG,MAAM,CAAC;AAC7B,MAAM,wBAAwB,GAAG,CAAC,GAAG,MAAM,CAAC;AAC5C,MAAM,uBAAuB,GAAG,EAAE,GAAG,MAAM,CAAC;AAE5C,MAAa,iBAAiB;IAC5B,YACmB,gBAAkC,EAClC,qBAA4C;QAD5C,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;IAC5D,CAAC;IAEI,0BAA0B,CAAC,WAAiB;QAClD,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC;IACpD,CAAC;IAEO,KAAK,CAAC,KAAK,CAAC,EAAU;QAC5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAEO,oBAAoB,CAAC,SAAiB,EAAE,QAAc;QAC5D,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,SAAS,GAAG,MAAM,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,2BAA2B,CAC/B,WAAwB,EACxB,UAAiC,EAAE;QAEnC,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QACpC,MAAM,UAAU,GAAG,WAAW,CAAC,aAAa,EAAE,CAAC;QAE/C,IAAI,CAAC,eAAe,EAAE;YACpB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CACnE,UAAU,EACV,IAAI,IAAI,EAAE,CACX,CAAC;YACF,IA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ED,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;YAExC,MAAM,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,MAAM,EAAE;gBAC9C,kBAAkB,EAAE,IAAI;gBACxB,UAAU;gBACV,MAAM;gBACN,SAAS,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC;gBAChE,WAAW,EAAE,QAAQ;aACtB,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC,WAAW,CAAC;SAC3B;aAAM;YACL,2DAA2D;YAC3D,uCAAuC;YACvC,sBAAsB;YACtB,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;YAC7B,SAAS;gBACP,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CACnE,UAAU,EACV,IAAI,IAAI,EAAE,CACX,CAAC;gBACF,IAAI,WAAW,EAAE;oBACf,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;oBACnC,OAAO,WAAW,CAAC;iBACpB;gBAED,IACE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;oBACpB,SAAS,CAAC,OAAO,EAAE,GAAG,uBAAuB,EAC7C;oBACA,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;iBAC9B;gBAED,MAAM,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;aAC5C;SACF;IACH,CAAC;CACF;AAhHD,8CAgHC"}
@@ -0,0 +1,18 @@
1
+ import { ClientCredentials, SessionData } from './interfaces';
2
+ interface SessionDataImplOptions {
3
+ readonly clientId: string;
4
+ readonly clientSecret: string;
5
+ readonly scopes: readonly string[];
6
+ }
7
+ export declare class SessionDataImpl implements SessionData {
8
+ private readonly credentials;
9
+ private readonly scopes;
10
+ private readonly sessionKey;
11
+ constructor(options: SessionDataImplOptions);
12
+ getCredentials(): ClientCredentials;
13
+ getSessionKey(): string;
14
+ getScopes(): readonly string[];
15
+ private normalizeScopes;
16
+ private createKey;
17
+ }
18
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionDataImpl = void 0;
4
+ const crypto_1 = require("crypto");
5
+ function shortHash(s) {
6
+ return (0, crypto_1.createHash)('sha256').update(s).digest('hex').substring(0, 8);
7
+ }
8
+ class SessionDataImpl {
9
+ constructor(options) {
10
+ this.credentials = {
11
+ clientId: options.clientId,
12
+ clientSecret: options.clientSecret,
13
+ };
14
+ this.scopes = options.scopes;
15
+ this.sessionKey = this.createKey(options);
16
+ }
17
+ getCredentials() {
18
+ return this.credentials;
19
+ }
20
+ getSessionKey() {
21
+ return this.sessionKey;
22
+ }
23
+ getScopes() {
24
+ return this.scopes;
25
+ }
26
+ normalizeScopes(scopes) {
27
+ const normalizedScopes = scopes.map((scope) => scope.toLowerCase());
28
+ normalizedScopes.sort();
29
+ return Array.from(new Set(normalizedScopes));
30
+ }
31
+ createKey(options) {
32
+ const clientId = options.clientId;
33
+ const normalizedScopes = this.normalizeScopes(options.scopes);
34
+ const secretHash = shortHash(this.credentials.clientSecret);
35
+ const scopesString = normalizedScopes.join(',');
36
+ // Session key uniquely identifies a session.
37
+ // Access token stored under the same session key can be reused globally by
38
+ // multiple processes, because it is guaranteed that the
39
+ // clientId, clientSecret and scopes are the same for the same key.
40
+ //
41
+ // Note: the clientSecret is hashed in order to avoid disclosure of sensitive data
42
+ // through logs or redis leaking.
43
+ return `${clientId}/${secretHash}/${scopesString}`;
44
+ }
45
+ }
46
+ exports.SessionDataImpl = SessionDataImpl;
47
+ //# sourceMappingURL=SessionDataImpl.js.map