@sweepbright/api-client 0.29.6 → 0.29.8

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 (73) hide show
  1. package/dist/api-client.cjs.development.js +1322 -0
  2. package/dist/api-client.cjs.development.js.map +1 -0
  3. package/dist/api-client.cjs.production.min.js +2 -0
  4. package/dist/api-client.cjs.production.min.js.map +1 -0
  5. package/dist/api-client.esm.js +1318 -0
  6. package/dist/api-client.esm.js.map +1 -0
  7. package/dist/common/config.d.ts +2 -0
  8. package/dist/common/currencies.d.ts +50 -0
  9. package/dist/common/logger.d.ts +27 -0
  10. package/dist/common/types.d.ts +1 -0
  11. package/dist/entities/property.d.ts +523 -0
  12. package/dist/index.d.ts +142 -0
  13. package/dist/index.js +8 -0
  14. package/dist/mockServer.js +27 -0
  15. package/dist/mockServer.js.map +1 -0
  16. package/dist/resources/channel_accounts.d.ts +15 -0
  17. package/dist/resources/channels.d.ts +16 -0
  18. package/dist/resources/companies.d.ts +7 -0
  19. package/dist/resources/contact_preferences.d.ts +6 -0
  20. package/dist/resources/contacts.d.ts +14 -0
  21. package/dist/resources/estates.d.ts +43 -0
  22. package/dist/resources/leads.d.ts +39 -0
  23. package/dist/resources/negotiators.d.ts +10 -0
  24. package/dist/resources/offices.d.ts +6 -0
  25. package/dist/src/__tests__/auth.test.js +15 -0
  26. package/dist/src/__tests__/auth.test.js.map +1 -0
  27. package/dist/src/__tests__/channels.test.js +77 -0
  28. package/dist/src/__tests__/channels.test.js.map +1 -0
  29. package/dist/src/__tests__/contacts.test.js +61 -0
  30. package/dist/src/__tests__/contacts.test.js.map +1 -0
  31. package/dist/src/__tests__/estates.test.js +43 -0
  32. package/dist/src/__tests__/estates.test.js.map +1 -0
  33. package/dist/src/__tests__/leads.test.js +55 -0
  34. package/dist/src/__tests__/leads.test.js.map +1 -0
  35. package/dist/src/common/config.js +34 -0
  36. package/dist/src/common/config.js.map +1 -0
  37. package/dist/src/common/currencies.js +55 -0
  38. package/dist/src/common/currencies.js.map +1 -0
  39. package/dist/src/common/logger.js +50 -0
  40. package/dist/src/common/logger.js.map +1 -0
  41. package/dist/src/common/types.js +3 -0
  42. package/dist/src/common/types.js.map +1 -0
  43. package/dist/src/entities/office.js +9 -0
  44. package/dist/src/entities/office.js.map +1 -0
  45. package/dist/src/entities/property.js +220 -0
  46. package/dist/src/entities/property.js.map +1 -0
  47. package/dist/src/index.js +94 -0
  48. package/dist/src/index.js.map +1 -0
  49. package/dist/src/resources/channel_accounts.js +31 -0
  50. package/dist/src/resources/channel_accounts.js.map +1 -0
  51. package/dist/src/resources/channels.js +32 -0
  52. package/dist/src/resources/channels.js.map +1 -0
  53. package/dist/src/resources/companies.js +16 -0
  54. package/dist/src/resources/companies.js.map +1 -0
  55. package/dist/src/resources/contact_preferences.js +14 -0
  56. package/dist/src/resources/contact_preferences.js.map +1 -0
  57. package/dist/src/resources/contacts.js +29 -0
  58. package/dist/src/resources/contacts.js.map +1 -0
  59. package/dist/src/resources/estates.js +73 -0
  60. package/dist/src/resources/estates.js.map +1 -0
  61. package/dist/src/resources/leads.js +26 -0
  62. package/dist/src/resources/leads.js.map +1 -0
  63. package/dist/src/resources/negotiators.js +16 -0
  64. package/dist/src/resources/negotiators.js.map +1 -0
  65. package/dist/src/resources/offices.js +12 -0
  66. package/dist/src/resources/offices.js.map +1 -0
  67. package/dist/src/types.js +40 -0
  68. package/dist/src/types.js.map +1 -0
  69. package/dist/src/utils.js +28 -0
  70. package/dist/src/utils.js.map +1 -0
  71. package/dist/types.d.ts +75 -0
  72. package/dist/utils.d.ts +7 -0
  73. package/package.json +1 -1
@@ -0,0 +1,1322 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var axios = _interopDefault(require('axios'));
8
+ var invariant = _interopDefault(require('tiny-invariant'));
9
+
10
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
+ try {
12
+ var info = gen[key](arg);
13
+ var value = info.value;
14
+ } catch (error) {
15
+ reject(error);
16
+ return;
17
+ }
18
+
19
+ if (info.done) {
20
+ resolve(value);
21
+ } else {
22
+ Promise.resolve(value).then(_next, _throw);
23
+ }
24
+ }
25
+
26
+ function _asyncToGenerator(fn) {
27
+ return function () {
28
+ var self = this,
29
+ args = arguments;
30
+ return new Promise(function (resolve, reject) {
31
+ var gen = fn.apply(self, args);
32
+
33
+ function _next(value) {
34
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
35
+ }
36
+
37
+ function _throw(err) {
38
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
39
+ }
40
+
41
+ _next(undefined);
42
+ });
43
+ };
44
+ }
45
+
46
+ function createCommonjsModule(fn, module) {
47
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
48
+ }
49
+
50
+ var runtime_1 = createCommonjsModule(function (module) {
51
+ /**
52
+ * Copyright (c) 2014-present, Facebook, Inc.
53
+ *
54
+ * This source code is licensed under the MIT license found in the
55
+ * LICENSE file in the root directory of this source tree.
56
+ */
57
+
58
+ var runtime = (function (exports) {
59
+
60
+ var Op = Object.prototype;
61
+ var hasOwn = Op.hasOwnProperty;
62
+ var undefined$1; // More compressible than void 0.
63
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
64
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
65
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
66
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
67
+
68
+ function wrap(innerFn, outerFn, self, tryLocsList) {
69
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
70
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
71
+ var generator = Object.create(protoGenerator.prototype);
72
+ var context = new Context(tryLocsList || []);
73
+
74
+ // The ._invoke method unifies the implementations of the .next,
75
+ // .throw, and .return methods.
76
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
77
+
78
+ return generator;
79
+ }
80
+ exports.wrap = wrap;
81
+
82
+ // Try/catch helper to minimize deoptimizations. Returns a completion
83
+ // record like context.tryEntries[i].completion. This interface could
84
+ // have been (and was previously) designed to take a closure to be
85
+ // invoked without arguments, but in all the cases we care about we
86
+ // already have an existing method we want to call, so there's no need
87
+ // to create a new function object. We can even get away with assuming
88
+ // the method takes exactly one argument, since that happens to be true
89
+ // in every case, so we don't have to touch the arguments object. The
90
+ // only additional allocation required is the completion record, which
91
+ // has a stable shape and so hopefully should be cheap to allocate.
92
+ function tryCatch(fn, obj, arg) {
93
+ try {
94
+ return { type: "normal", arg: fn.call(obj, arg) };
95
+ } catch (err) {
96
+ return { type: "throw", arg: err };
97
+ }
98
+ }
99
+
100
+ var GenStateSuspendedStart = "suspendedStart";
101
+ var GenStateSuspendedYield = "suspendedYield";
102
+ var GenStateExecuting = "executing";
103
+ var GenStateCompleted = "completed";
104
+
105
+ // Returning this object from the innerFn has the same effect as
106
+ // breaking out of the dispatch switch statement.
107
+ var ContinueSentinel = {};
108
+
109
+ // Dummy constructor functions that we use as the .constructor and
110
+ // .constructor.prototype properties for functions that return Generator
111
+ // objects. For full spec compliance, you may wish to configure your
112
+ // minifier not to mangle the names of these two functions.
113
+ function Generator() {}
114
+ function GeneratorFunction() {}
115
+ function GeneratorFunctionPrototype() {}
116
+
117
+ // This is a polyfill for %IteratorPrototype% for environments that
118
+ // don't natively support it.
119
+ var IteratorPrototype = {};
120
+ IteratorPrototype[iteratorSymbol] = function () {
121
+ return this;
122
+ };
123
+
124
+ var getProto = Object.getPrototypeOf;
125
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
126
+ if (NativeIteratorPrototype &&
127
+ NativeIteratorPrototype !== Op &&
128
+ hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
129
+ // This environment has a native %IteratorPrototype%; use it instead
130
+ // of the polyfill.
131
+ IteratorPrototype = NativeIteratorPrototype;
132
+ }
133
+
134
+ var Gp = GeneratorFunctionPrototype.prototype =
135
+ Generator.prototype = Object.create(IteratorPrototype);
136
+ GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
137
+ GeneratorFunctionPrototype.constructor = GeneratorFunction;
138
+ GeneratorFunctionPrototype[toStringTagSymbol] =
139
+ GeneratorFunction.displayName = "GeneratorFunction";
140
+
141
+ // Helper for defining the .next, .throw, and .return methods of the
142
+ // Iterator interface in terms of a single ._invoke method.
143
+ function defineIteratorMethods(prototype) {
144
+ ["next", "throw", "return"].forEach(function(method) {
145
+ prototype[method] = function(arg) {
146
+ return this._invoke(method, arg);
147
+ };
148
+ });
149
+ }
150
+
151
+ exports.isGeneratorFunction = function(genFun) {
152
+ var ctor = typeof genFun === "function" && genFun.constructor;
153
+ return ctor
154
+ ? ctor === GeneratorFunction ||
155
+ // For the native GeneratorFunction constructor, the best we can
156
+ // do is to check its .name property.
157
+ (ctor.displayName || ctor.name) === "GeneratorFunction"
158
+ : false;
159
+ };
160
+
161
+ exports.mark = function(genFun) {
162
+ if (Object.setPrototypeOf) {
163
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
164
+ } else {
165
+ genFun.__proto__ = GeneratorFunctionPrototype;
166
+ if (!(toStringTagSymbol in genFun)) {
167
+ genFun[toStringTagSymbol] = "GeneratorFunction";
168
+ }
169
+ }
170
+ genFun.prototype = Object.create(Gp);
171
+ return genFun;
172
+ };
173
+
174
+ // Within the body of any async function, `await x` is transformed to
175
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
176
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
177
+ // meant to be awaited.
178
+ exports.awrap = function(arg) {
179
+ return { __await: arg };
180
+ };
181
+
182
+ function AsyncIterator(generator, PromiseImpl) {
183
+ function invoke(method, arg, resolve, reject) {
184
+ var record = tryCatch(generator[method], generator, arg);
185
+ if (record.type === "throw") {
186
+ reject(record.arg);
187
+ } else {
188
+ var result = record.arg;
189
+ var value = result.value;
190
+ if (value &&
191
+ typeof value === "object" &&
192
+ hasOwn.call(value, "__await")) {
193
+ return PromiseImpl.resolve(value.__await).then(function(value) {
194
+ invoke("next", value, resolve, reject);
195
+ }, function(err) {
196
+ invoke("throw", err, resolve, reject);
197
+ });
198
+ }
199
+
200
+ return PromiseImpl.resolve(value).then(function(unwrapped) {
201
+ // When a yielded Promise is resolved, its final value becomes
202
+ // the .value of the Promise<{value,done}> result for the
203
+ // current iteration.
204
+ result.value = unwrapped;
205
+ resolve(result);
206
+ }, function(error) {
207
+ // If a rejected Promise was yielded, throw the rejection back
208
+ // into the async generator function so it can be handled there.
209
+ return invoke("throw", error, resolve, reject);
210
+ });
211
+ }
212
+ }
213
+
214
+ var previousPromise;
215
+
216
+ function enqueue(method, arg) {
217
+ function callInvokeWithMethodAndArg() {
218
+ return new PromiseImpl(function(resolve, reject) {
219
+ invoke(method, arg, resolve, reject);
220
+ });
221
+ }
222
+
223
+ return previousPromise =
224
+ // If enqueue has been called before, then we want to wait until
225
+ // all previous Promises have been resolved before calling invoke,
226
+ // so that results are always delivered in the correct order. If
227
+ // enqueue has not been called before, then it is important to
228
+ // call invoke immediately, without waiting on a callback to fire,
229
+ // so that the async generator function has the opportunity to do
230
+ // any necessary setup in a predictable way. This predictability
231
+ // is why the Promise constructor synchronously invokes its
232
+ // executor callback, and why async functions synchronously
233
+ // execute code before the first await. Since we implement simple
234
+ // async functions in terms of async generators, it is especially
235
+ // important to get this right, even though it requires care.
236
+ previousPromise ? previousPromise.then(
237
+ callInvokeWithMethodAndArg,
238
+ // Avoid propagating failures to Promises returned by later
239
+ // invocations of the iterator.
240
+ callInvokeWithMethodAndArg
241
+ ) : callInvokeWithMethodAndArg();
242
+ }
243
+
244
+ // Define the unified helper method that is used to implement .next,
245
+ // .throw, and .return (see defineIteratorMethods).
246
+ this._invoke = enqueue;
247
+ }
248
+
249
+ defineIteratorMethods(AsyncIterator.prototype);
250
+ AsyncIterator.prototype[asyncIteratorSymbol] = function () {
251
+ return this;
252
+ };
253
+ exports.AsyncIterator = AsyncIterator;
254
+
255
+ // Note that simple async functions are implemented on top of
256
+ // AsyncIterator objects; they just return a Promise for the value of
257
+ // the final result produced by the iterator.
258
+ exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
259
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
260
+
261
+ var iter = new AsyncIterator(
262
+ wrap(innerFn, outerFn, self, tryLocsList),
263
+ PromiseImpl
264
+ );
265
+
266
+ return exports.isGeneratorFunction(outerFn)
267
+ ? iter // If outerFn is a generator, return the full iterator.
268
+ : iter.next().then(function(result) {
269
+ return result.done ? result.value : iter.next();
270
+ });
271
+ };
272
+
273
+ function makeInvokeMethod(innerFn, self, context) {
274
+ var state = GenStateSuspendedStart;
275
+
276
+ return function invoke(method, arg) {
277
+ if (state === GenStateExecuting) {
278
+ throw new Error("Generator is already running");
279
+ }
280
+
281
+ if (state === GenStateCompleted) {
282
+ if (method === "throw") {
283
+ throw arg;
284
+ }
285
+
286
+ // Be forgiving, per 25.3.3.3.3 of the spec:
287
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
288
+ return doneResult();
289
+ }
290
+
291
+ context.method = method;
292
+ context.arg = arg;
293
+
294
+ while (true) {
295
+ var delegate = context.delegate;
296
+ if (delegate) {
297
+ var delegateResult = maybeInvokeDelegate(delegate, context);
298
+ if (delegateResult) {
299
+ if (delegateResult === ContinueSentinel) continue;
300
+ return delegateResult;
301
+ }
302
+ }
303
+
304
+ if (context.method === "next") {
305
+ // Setting context._sent for legacy support of Babel's
306
+ // function.sent implementation.
307
+ context.sent = context._sent = context.arg;
308
+
309
+ } else if (context.method === "throw") {
310
+ if (state === GenStateSuspendedStart) {
311
+ state = GenStateCompleted;
312
+ throw context.arg;
313
+ }
314
+
315
+ context.dispatchException(context.arg);
316
+
317
+ } else if (context.method === "return") {
318
+ context.abrupt("return", context.arg);
319
+ }
320
+
321
+ state = GenStateExecuting;
322
+
323
+ var record = tryCatch(innerFn, self, context);
324
+ if (record.type === "normal") {
325
+ // If an exception is thrown from innerFn, we leave state ===
326
+ // GenStateExecuting and loop back for another invocation.
327
+ state = context.done
328
+ ? GenStateCompleted
329
+ : GenStateSuspendedYield;
330
+
331
+ if (record.arg === ContinueSentinel) {
332
+ continue;
333
+ }
334
+
335
+ return {
336
+ value: record.arg,
337
+ done: context.done
338
+ };
339
+
340
+ } else if (record.type === "throw") {
341
+ state = GenStateCompleted;
342
+ // Dispatch the exception by looping back around to the
343
+ // context.dispatchException(context.arg) call above.
344
+ context.method = "throw";
345
+ context.arg = record.arg;
346
+ }
347
+ }
348
+ };
349
+ }
350
+
351
+ // Call delegate.iterator[context.method](context.arg) and handle the
352
+ // result, either by returning a { value, done } result from the
353
+ // delegate iterator, or by modifying context.method and context.arg,
354
+ // setting context.delegate to null, and returning the ContinueSentinel.
355
+ function maybeInvokeDelegate(delegate, context) {
356
+ var method = delegate.iterator[context.method];
357
+ if (method === undefined$1) {
358
+ // A .throw or .return when the delegate iterator has no .throw
359
+ // method always terminates the yield* loop.
360
+ context.delegate = null;
361
+
362
+ if (context.method === "throw") {
363
+ // Note: ["return"] must be used for ES3 parsing compatibility.
364
+ if (delegate.iterator["return"]) {
365
+ // If the delegate iterator has a return method, give it a
366
+ // chance to clean up.
367
+ context.method = "return";
368
+ context.arg = undefined$1;
369
+ maybeInvokeDelegate(delegate, context);
370
+
371
+ if (context.method === "throw") {
372
+ // If maybeInvokeDelegate(context) changed context.method from
373
+ // "return" to "throw", let that override the TypeError below.
374
+ return ContinueSentinel;
375
+ }
376
+ }
377
+
378
+ context.method = "throw";
379
+ context.arg = new TypeError(
380
+ "The iterator does not provide a 'throw' method");
381
+ }
382
+
383
+ return ContinueSentinel;
384
+ }
385
+
386
+ var record = tryCatch(method, delegate.iterator, context.arg);
387
+
388
+ if (record.type === "throw") {
389
+ context.method = "throw";
390
+ context.arg = record.arg;
391
+ context.delegate = null;
392
+ return ContinueSentinel;
393
+ }
394
+
395
+ var info = record.arg;
396
+
397
+ if (! info) {
398
+ context.method = "throw";
399
+ context.arg = new TypeError("iterator result is not an object");
400
+ context.delegate = null;
401
+ return ContinueSentinel;
402
+ }
403
+
404
+ if (info.done) {
405
+ // Assign the result of the finished delegate to the temporary
406
+ // variable specified by delegate.resultName (see delegateYield).
407
+ context[delegate.resultName] = info.value;
408
+
409
+ // Resume execution at the desired location (see delegateYield).
410
+ context.next = delegate.nextLoc;
411
+
412
+ // If context.method was "throw" but the delegate handled the
413
+ // exception, let the outer generator proceed normally. If
414
+ // context.method was "next", forget context.arg since it has been
415
+ // "consumed" by the delegate iterator. If context.method was
416
+ // "return", allow the original .return call to continue in the
417
+ // outer generator.
418
+ if (context.method !== "return") {
419
+ context.method = "next";
420
+ context.arg = undefined$1;
421
+ }
422
+
423
+ } else {
424
+ // Re-yield the result returned by the delegate method.
425
+ return info;
426
+ }
427
+
428
+ // The delegate iterator is finished, so forget it and continue with
429
+ // the outer generator.
430
+ context.delegate = null;
431
+ return ContinueSentinel;
432
+ }
433
+
434
+ // Define Generator.prototype.{next,throw,return} in terms of the
435
+ // unified ._invoke helper method.
436
+ defineIteratorMethods(Gp);
437
+
438
+ Gp[toStringTagSymbol] = "Generator";
439
+
440
+ // A Generator should always return itself as the iterator object when the
441
+ // @@iterator function is called on it. Some browsers' implementations of the
442
+ // iterator prototype chain incorrectly implement this, causing the Generator
443
+ // object to not be returned from this call. This ensures that doesn't happen.
444
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
445
+ Gp[iteratorSymbol] = function() {
446
+ return this;
447
+ };
448
+
449
+ Gp.toString = function() {
450
+ return "[object Generator]";
451
+ };
452
+
453
+ function pushTryEntry(locs) {
454
+ var entry = { tryLoc: locs[0] };
455
+
456
+ if (1 in locs) {
457
+ entry.catchLoc = locs[1];
458
+ }
459
+
460
+ if (2 in locs) {
461
+ entry.finallyLoc = locs[2];
462
+ entry.afterLoc = locs[3];
463
+ }
464
+
465
+ this.tryEntries.push(entry);
466
+ }
467
+
468
+ function resetTryEntry(entry) {
469
+ var record = entry.completion || {};
470
+ record.type = "normal";
471
+ delete record.arg;
472
+ entry.completion = record;
473
+ }
474
+
475
+ function Context(tryLocsList) {
476
+ // The root entry object (effectively a try statement without a catch
477
+ // or a finally block) gives us a place to store values thrown from
478
+ // locations where there is no enclosing try statement.
479
+ this.tryEntries = [{ tryLoc: "root" }];
480
+ tryLocsList.forEach(pushTryEntry, this);
481
+ this.reset(true);
482
+ }
483
+
484
+ exports.keys = function(object) {
485
+ var keys = [];
486
+ for (var key in object) {
487
+ keys.push(key);
488
+ }
489
+ keys.reverse();
490
+
491
+ // Rather than returning an object with a next method, we keep
492
+ // things simple and return the next function itself.
493
+ return function next() {
494
+ while (keys.length) {
495
+ var key = keys.pop();
496
+ if (key in object) {
497
+ next.value = key;
498
+ next.done = false;
499
+ return next;
500
+ }
501
+ }
502
+
503
+ // To avoid creating an additional object, we just hang the .value
504
+ // and .done properties off the next function object itself. This
505
+ // also ensures that the minifier will not anonymize the function.
506
+ next.done = true;
507
+ return next;
508
+ };
509
+ };
510
+
511
+ function values(iterable) {
512
+ if (iterable) {
513
+ var iteratorMethod = iterable[iteratorSymbol];
514
+ if (iteratorMethod) {
515
+ return iteratorMethod.call(iterable);
516
+ }
517
+
518
+ if (typeof iterable.next === "function") {
519
+ return iterable;
520
+ }
521
+
522
+ if (!isNaN(iterable.length)) {
523
+ var i = -1, next = function next() {
524
+ while (++i < iterable.length) {
525
+ if (hasOwn.call(iterable, i)) {
526
+ next.value = iterable[i];
527
+ next.done = false;
528
+ return next;
529
+ }
530
+ }
531
+
532
+ next.value = undefined$1;
533
+ next.done = true;
534
+
535
+ return next;
536
+ };
537
+
538
+ return next.next = next;
539
+ }
540
+ }
541
+
542
+ // Return an iterator with no values.
543
+ return { next: doneResult };
544
+ }
545
+ exports.values = values;
546
+
547
+ function doneResult() {
548
+ return { value: undefined$1, done: true };
549
+ }
550
+
551
+ Context.prototype = {
552
+ constructor: Context,
553
+
554
+ reset: function(skipTempReset) {
555
+ this.prev = 0;
556
+ this.next = 0;
557
+ // Resetting context._sent for legacy support of Babel's
558
+ // function.sent implementation.
559
+ this.sent = this._sent = undefined$1;
560
+ this.done = false;
561
+ this.delegate = null;
562
+
563
+ this.method = "next";
564
+ this.arg = undefined$1;
565
+
566
+ this.tryEntries.forEach(resetTryEntry);
567
+
568
+ if (!skipTempReset) {
569
+ for (var name in this) {
570
+ // Not sure about the optimal order of these conditions:
571
+ if (name.charAt(0) === "t" &&
572
+ hasOwn.call(this, name) &&
573
+ !isNaN(+name.slice(1))) {
574
+ this[name] = undefined$1;
575
+ }
576
+ }
577
+ }
578
+ },
579
+
580
+ stop: function() {
581
+ this.done = true;
582
+
583
+ var rootEntry = this.tryEntries[0];
584
+ var rootRecord = rootEntry.completion;
585
+ if (rootRecord.type === "throw") {
586
+ throw rootRecord.arg;
587
+ }
588
+
589
+ return this.rval;
590
+ },
591
+
592
+ dispatchException: function(exception) {
593
+ if (this.done) {
594
+ throw exception;
595
+ }
596
+
597
+ var context = this;
598
+ function handle(loc, caught) {
599
+ record.type = "throw";
600
+ record.arg = exception;
601
+ context.next = loc;
602
+
603
+ if (caught) {
604
+ // If the dispatched exception was caught by a catch block,
605
+ // then let that catch block handle the exception normally.
606
+ context.method = "next";
607
+ context.arg = undefined$1;
608
+ }
609
+
610
+ return !! caught;
611
+ }
612
+
613
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
614
+ var entry = this.tryEntries[i];
615
+ var record = entry.completion;
616
+
617
+ if (entry.tryLoc === "root") {
618
+ // Exception thrown outside of any try block that could handle
619
+ // it, so set the completion value of the entire function to
620
+ // throw the exception.
621
+ return handle("end");
622
+ }
623
+
624
+ if (entry.tryLoc <= this.prev) {
625
+ var hasCatch = hasOwn.call(entry, "catchLoc");
626
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
627
+
628
+ if (hasCatch && hasFinally) {
629
+ if (this.prev < entry.catchLoc) {
630
+ return handle(entry.catchLoc, true);
631
+ } else if (this.prev < entry.finallyLoc) {
632
+ return handle(entry.finallyLoc);
633
+ }
634
+
635
+ } else if (hasCatch) {
636
+ if (this.prev < entry.catchLoc) {
637
+ return handle(entry.catchLoc, true);
638
+ }
639
+
640
+ } else if (hasFinally) {
641
+ if (this.prev < entry.finallyLoc) {
642
+ return handle(entry.finallyLoc);
643
+ }
644
+
645
+ } else {
646
+ throw new Error("try statement without catch or finally");
647
+ }
648
+ }
649
+ }
650
+ },
651
+
652
+ abrupt: function(type, arg) {
653
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
654
+ var entry = this.tryEntries[i];
655
+ if (entry.tryLoc <= this.prev &&
656
+ hasOwn.call(entry, "finallyLoc") &&
657
+ this.prev < entry.finallyLoc) {
658
+ var finallyEntry = entry;
659
+ break;
660
+ }
661
+ }
662
+
663
+ if (finallyEntry &&
664
+ (type === "break" ||
665
+ type === "continue") &&
666
+ finallyEntry.tryLoc <= arg &&
667
+ arg <= finallyEntry.finallyLoc) {
668
+ // Ignore the finally entry if control is not jumping to a
669
+ // location outside the try/catch block.
670
+ finallyEntry = null;
671
+ }
672
+
673
+ var record = finallyEntry ? finallyEntry.completion : {};
674
+ record.type = type;
675
+ record.arg = arg;
676
+
677
+ if (finallyEntry) {
678
+ this.method = "next";
679
+ this.next = finallyEntry.finallyLoc;
680
+ return ContinueSentinel;
681
+ }
682
+
683
+ return this.complete(record);
684
+ },
685
+
686
+ complete: function(record, afterLoc) {
687
+ if (record.type === "throw") {
688
+ throw record.arg;
689
+ }
690
+
691
+ if (record.type === "break" ||
692
+ record.type === "continue") {
693
+ this.next = record.arg;
694
+ } else if (record.type === "return") {
695
+ this.rval = this.arg = record.arg;
696
+ this.method = "return";
697
+ this.next = "end";
698
+ } else if (record.type === "normal" && afterLoc) {
699
+ this.next = afterLoc;
700
+ }
701
+
702
+ return ContinueSentinel;
703
+ },
704
+
705
+ finish: function(finallyLoc) {
706
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
707
+ var entry = this.tryEntries[i];
708
+ if (entry.finallyLoc === finallyLoc) {
709
+ this.complete(entry.completion, entry.afterLoc);
710
+ resetTryEntry(entry);
711
+ return ContinueSentinel;
712
+ }
713
+ }
714
+ },
715
+
716
+ "catch": function(tryLoc) {
717
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
718
+ var entry = this.tryEntries[i];
719
+ if (entry.tryLoc === tryLoc) {
720
+ var record = entry.completion;
721
+ if (record.type === "throw") {
722
+ var thrown = record.arg;
723
+ resetTryEntry(entry);
724
+ }
725
+ return thrown;
726
+ }
727
+ }
728
+
729
+ // The context.catch method must only be called with a location
730
+ // argument that corresponds to a known catch block.
731
+ throw new Error("illegal catch attempt");
732
+ },
733
+
734
+ delegateYield: function(iterable, resultName, nextLoc) {
735
+ this.delegate = {
736
+ iterator: values(iterable),
737
+ resultName: resultName,
738
+ nextLoc: nextLoc
739
+ };
740
+
741
+ if (this.method === "next") {
742
+ // Deliberately forget the last sent value so that we don't
743
+ // accidentally pass it on to the delegate.
744
+ this.arg = undefined$1;
745
+ }
746
+
747
+ return ContinueSentinel;
748
+ }
749
+ };
750
+
751
+ // Regardless of whether this script is executing as a CommonJS module
752
+ // or not, return the runtime object so that we can declare the variable
753
+ // regeneratorRuntime in the outer scope, which allows this module to be
754
+ // injected easily by `bin/regenerator --include-runtime script.js`.
755
+ return exports;
756
+
757
+ }(
758
+ // If this script is executing as a CommonJS module, use module.exports
759
+ // as the regeneratorRuntime namespace. Otherwise create a new empty
760
+ // object. Either way, the resulting object will be used to initialize
761
+ // the regeneratorRuntime variable at the top of this file.
762
+ module.exports
763
+ ));
764
+
765
+ try {
766
+ regeneratorRuntime = runtime;
767
+ } catch (accidentalStrictMode) {
768
+ // This module should not be running in strict mode, so the above
769
+ // assignment should always work unless something is misconfigured. Just
770
+ // in case runtime.js accidentally runs in strict mode, we can escape
771
+ // strict mode using a global Function call. This could conceivably fail
772
+ // if a Content Security Policy forbids using Function, but in that case
773
+ // the proper solution is to fix the accidental strict mode problem. If
774
+ // you've misconfigured your bundler to force strict mode and applied a
775
+ // CSP to forbid Function, and you're not willing to fix either of those
776
+ // problems, please detail your unique predicament in a GitHub issue.
777
+ Function("r", "regeneratorRuntime = r")(runtime);
778
+ }
779
+ });
780
+
781
+ var EstateInclude;
782
+
783
+ (function (EstateInclude) {
784
+ EstateInclude["settings"] = "settings";
785
+ EstateInclude["channels"] = "channels";
786
+ EstateInclude["negotiator"] = "negotiator";
787
+ EstateInclude["office.settings"] = "office.settings";
788
+ EstateInclude["project.settings"] = "project.settings";
789
+ EstateInclude["project.office.settings"] = "project.office.settings";
790
+ EstateInclude["project.properties.office.settings"] = "project.properties.office.settings";
791
+ EstateInclude["project.properties.settings"] = "project.properties.settings";
792
+ EstateInclude["properties.settings"] = "properties.settings";
793
+ EstateInclude["properties.office.settings"] = "properties.office.settings";
794
+ EstateInclude["properties.negotiator"] = "properties.negotiator";
795
+ EstateInclude["item.settings"] = "item.settings";
796
+ EstateInclude["item.office.settings"] = "item.office.settings";
797
+ EstateInclude["item.channels"] = "item.channels";
798
+ EstateInclude["item.project.settings"] = "item.project.settings";
799
+ EstateInclude["item.project.office.settings"] = "item.project.office.settings";
800
+ EstateInclude["item.project.properties.office.settings"] = "item.project.properties.office.settings";
801
+ EstateInclude["item.project.properties.settings"] = "item.project.properties.settings";
802
+ EstateInclude["item.properties.settings"] = "item.properties.settings";
803
+ EstateInclude["item.properties.office.settings"] = "item.properties.office.settings";
804
+ EstateInclude["item.negotiator"] = "item.negotiator";
805
+ EstateInclude["item.properties.negotiator"] = "item.properties.negotiator";
806
+ })(EstateInclude || (EstateInclude = {}));
807
+
808
+ var TokenType;
809
+
810
+ (function (TokenType) {
811
+ TokenType[TokenType["USER_TOKEN"] = 0] = "USER_TOKEN";
812
+ TokenType[TokenType["API_TOKEN"] = 1] = "API_TOKEN";
813
+ })(TokenType || (TokenType = {}));
814
+
815
+ (function (Env) {
816
+ Env["PRODUCTION"] = "production";
817
+ Env["STAGING"] = "staging";
818
+ Env["DEV"] = "dev";
819
+ })(exports.Env || (exports.Env = {}));
820
+
821
+ function getData(response) {
822
+ return response.data;
823
+ }
824
+ function handleRequestFailure(exception) {
825
+ if (exception.response) {
826
+ var _exception$response = exception.response,
827
+ status = _exception$response.status,
828
+ data = _exception$response.data;
829
+ var error = new Error(status + ": " + JSON.stringify(data)); // remove parts of the stack trace so the error message (codeframe) shows up
830
+ // at the code where the actual problem is.
831
+
832
+ error.stack = (error.stack || '').split('\n').filter(function (line) {
833
+ return !line.includes('at handleRequestFailure') && !line.includes('at processTicksAndRejections');
834
+ }).join('\n');
835
+ error.status = status;
836
+ error.data = data;
837
+ return Promise.reject(error);
838
+ } else {
839
+ return Promise.reject(exception);
840
+ }
841
+ }
842
+
843
+ function leads (ctx) {
844
+ function createLead(attributes) {
845
+ ctx.checkAuth(TokenType.API_TOKEN);
846
+ var firstName = attributes.firstName,
847
+ lastName = attributes.lastName,
848
+ propertyId = attributes.propertyId,
849
+ email = attributes.email,
850
+ phone = attributes.phone,
851
+ message = attributes.message,
852
+ portal = attributes.portal;
853
+ return ctx.httpClient.put("estates/" + propertyId + "/leads", {
854
+ first_name: firstName,
855
+ last_name: lastName,
856
+ message: message,
857
+ email: email,
858
+ phone: phone,
859
+ source_type: 'channel',
860
+ external_source: portal,
861
+ location_preference: attributes.location_preference
862
+ });
863
+ }
864
+
865
+ function createUnassignedLead(companyId, attributes) {
866
+ ctx.checkAuth(TokenType.API_TOKEN);
867
+ return ctx.httpClient.put("companies/" + companyId + "/leads", attributes);
868
+ }
869
+
870
+ return {
871
+ createLead: createLead,
872
+ createUnassignedLead: createUnassignedLead
873
+ };
874
+ }
875
+
876
+ function channels (ctx) {
877
+ /**
878
+ * @deprecated use channels.resolveReferences()
879
+ */
880
+ function getPropertyIdFromReference(_x, _x2) {
881
+ return _getPropertyIdFromReference.apply(this, arguments);
882
+ }
883
+ /**
884
+ * @param channel_id Channel ID, for example, `"immoweb"` or `"immovlan"` etc
885
+ * @param reference_code Reference
886
+ * @param company_id Company ID
887
+ */
888
+
889
+
890
+ function _getPropertyIdFromReference() {
891
+ _getPropertyIdFromReference = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(channel, referenceId) {
892
+ var endpoint;
893
+ return runtime_1.wrap(function _callee$(_context) {
894
+ while (1) {
895
+ switch (_context.prev = _context.next) {
896
+ case 0:
897
+ ctx.checkAuth(TokenType.API_TOKEN);
898
+ endpoint = "/channels/" + channel + "/channel-references/" + referenceId;
899
+ return _context.abrupt("return", ctx.httpClient.get(endpoint));
900
+
901
+ case 3:
902
+ case "end":
903
+ return _context.stop();
904
+ }
905
+ }
906
+ }, _callee);
907
+ }));
908
+ return _getPropertyIdFromReference.apply(this, arguments);
909
+ }
910
+
911
+ function resolveReferences(_x3, _x4, _x5) {
912
+ return _resolveReferences.apply(this, arguments);
913
+ }
914
+
915
+ function _resolveReferences() {
916
+ _resolveReferences = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(channel_id, reference_code, company_id) {
917
+ var endpoint;
918
+ return runtime_1.wrap(function _callee2$(_context2) {
919
+ while (1) {
920
+ switch (_context2.prev = _context2.next) {
921
+ case 0:
922
+ ctx.checkAuth(TokenType.API_TOKEN);
923
+ endpoint = "/services/channel-references";
924
+ return _context2.abrupt("return", ctx.httpClient.get(endpoint, {
925
+ params: {
926
+ channel_id: channel_id,
927
+ reference_code: reference_code,
928
+ company_id: company_id
929
+ }
930
+ }));
931
+
932
+ case 3:
933
+ case "end":
934
+ return _context2.stop();
935
+ }
936
+ }
937
+ }, _callee2);
938
+ }));
939
+ return _resolveReferences.apply(this, arguments);
940
+ }
941
+
942
+ return {
943
+ getPropertyIdFromReference: getPropertyIdFromReference,
944
+ resolveReferences: resolveReferences
945
+ };
946
+ }
947
+
948
+ function estates (ctx) {
949
+ function getOne(attributes) {
950
+ var _attributes$includes;
951
+
952
+ ctx.checkAuth(TokenType.API_TOKEN);
953
+ return ctx.httpClient.get("/services/estates/" + attributes.estateId, {
954
+ params: {
955
+ includes: (_attributes$includes = attributes.includes) != null ? _attributes$includes : []
956
+ }
957
+ }).then(function (res) {
958
+ return res.data;
959
+ });
960
+ }
961
+
962
+ function getAll(attributes) {
963
+ var _attributes$page, _attributes$limit;
964
+
965
+ ctx.checkAuth(TokenType.API_TOKEN);
966
+ return ctx.httpClient.get("/services/companies/" + attributes.companyId + "/estates", {
967
+ params: {
968
+ page: (_attributes$page = attributes.page) != null ? _attributes$page : 1,
969
+ limit: (_attributes$limit = attributes.limit) != null ? _attributes$limit : 10,
970
+ archived: attributes.archived
971
+ }
972
+ });
973
+ }
974
+
975
+ function getUnits(projectId, _temp) {
976
+ var _ref = _temp === void 0 ? {} : _temp,
977
+ page = _ref.page,
978
+ limit = _ref.limit,
979
+ includes = _ref.includes;
980
+
981
+ ctx.checkAuth(TokenType.API_TOKEN);
982
+ return ctx.httpClient.get("/services/projects/" + projectId + "/units", {
983
+ params: {
984
+ page: page,
985
+ limit: limit,
986
+ includes: includes
987
+ }
988
+ });
989
+ }
990
+
991
+ function createPublication(attributes) {
992
+ ctx.checkAuth(TokenType.USER_TOKEN);
993
+ return ctx.httpClient.post("/estates/" + attributes.estateId + "/channel-accounts/" + attributes.channelAccountId + "/ads", {
994
+ config: attributes.config
995
+ });
996
+ }
997
+
998
+ function updatePublication(attributes) {
999
+ ctx.checkAuth(TokenType.USER_TOKEN);
1000
+ return ctx.httpClient.put("/estates/" + attributes.estateId + "/channel-accounts/" + attributes.channelAccountId + "/ads", {
1001
+ config: attributes.config
1002
+ });
1003
+ }
1004
+
1005
+ function unpublishPublication(attributes) {
1006
+ ctx.checkAuth(TokenType.USER_TOKEN);
1007
+ return ctx.httpClient["delete"]("/estates/" + attributes.estateId + "/channel-accounts/" + attributes.channelAccountId + "/ads");
1008
+ }
1009
+
1010
+ function scheduleVisit(estateId, attributes) {
1011
+ ctx.checkAuth(TokenType.API_TOKEN);
1012
+ return ctx.httpClient.put("/properties/" + estateId + "/schedule-visit", attributes);
1013
+ }
1014
+
1015
+ function unstable_setPublicationUrl(_ref2) {
1016
+ var estateId = _ref2.estateId,
1017
+ url = _ref2.url;
1018
+ ctx.checkAuth(TokenType.API_TOKEN);
1019
+ return ctx.httpClient.put("/estates/" + estateId + "/website-url", {
1020
+ published_url: url
1021
+ });
1022
+ }
1023
+
1024
+ return {
1025
+ getOne: getOne,
1026
+ getAll: getAll,
1027
+ getUnits: getUnits,
1028
+ createPublication: createPublication,
1029
+ updatePublication: updatePublication,
1030
+ unpublishPublication: unpublishPublication,
1031
+ scheduleVisit: scheduleVisit,
1032
+ unstable_setPublicationUrl: unstable_setPublicationUrl
1033
+ };
1034
+ }
1035
+
1036
+ function channelAccounts (ctx) {
1037
+ function getAll(_x) {
1038
+ return _getAll.apply(this, arguments);
1039
+ }
1040
+
1041
+ function _getAll() {
1042
+ _getAll = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
1043
+ var companyId, endpoint;
1044
+ return runtime_1.wrap(function _callee$(_context) {
1045
+ while (1) {
1046
+ switch (_context.prev = _context.next) {
1047
+ case 0:
1048
+ companyId = _ref.companyId;
1049
+ ctx.checkAuth(TokenType.API_TOKEN);
1050
+ endpoint = "/services/companies/" + companyId + "/channel-accounts";
1051
+ return _context.abrupt("return", ctx.httpClient.get(endpoint, {
1052
+ params: {
1053
+ includes: 'channel'
1054
+ }
1055
+ }));
1056
+
1057
+ case 4:
1058
+ case "end":
1059
+ return _context.stop();
1060
+ }
1061
+ }
1062
+ }, _callee);
1063
+ }));
1064
+ return _getAll.apply(this, arguments);
1065
+ }
1066
+
1067
+ function get(_x2) {
1068
+ return _get.apply(this, arguments);
1069
+ }
1070
+
1071
+ function _get() {
1072
+ _get = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref2) {
1073
+ var channelAccountId, endpoint;
1074
+ return runtime_1.wrap(function _callee2$(_context2) {
1075
+ while (1) {
1076
+ switch (_context2.prev = _context2.next) {
1077
+ case 0:
1078
+ channelAccountId = _ref2.channelAccountId;
1079
+ ctx.checkAuth(TokenType.API_TOKEN);
1080
+ endpoint = "/services/channel-accounts/" + channelAccountId;
1081
+ return _context2.abrupt("return", ctx.httpClient.get(endpoint, {
1082
+ params: {
1083
+ includes: 'channel'
1084
+ }
1085
+ }));
1086
+
1087
+ case 4:
1088
+ case "end":
1089
+ return _context2.stop();
1090
+ }
1091
+ }
1092
+ }, _callee2);
1093
+ }));
1094
+ return _get.apply(this, arguments);
1095
+ }
1096
+
1097
+ function getEstateHash(_x3) {
1098
+ return _getEstateHash.apply(this, arguments);
1099
+ }
1100
+
1101
+ function _getEstateHash() {
1102
+ _getEstateHash = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_ref3) {
1103
+ var estateId, channelAccountId, endpoint, response;
1104
+ return runtime_1.wrap(function _callee3$(_context3) {
1105
+ while (1) {
1106
+ switch (_context3.prev = _context3.next) {
1107
+ case 0:
1108
+ estateId = _ref3.estateId, channelAccountId = _ref3.channelAccountId;
1109
+ endpoint = "services/estates/" + estateId + "/channel-accounts/" + channelAccountId + "/hash";
1110
+ _context3.next = 4;
1111
+ return ctx.httpClient.post(endpoint);
1112
+
1113
+ case 4:
1114
+ response = _context3.sent;
1115
+ return _context3.abrupt("return", response.data);
1116
+
1117
+ case 6:
1118
+ case "end":
1119
+ return _context3.stop();
1120
+ }
1121
+ }
1122
+ }, _callee3);
1123
+ }));
1124
+ return _getEstateHash.apply(this, arguments);
1125
+ }
1126
+
1127
+ return {
1128
+ getAll: getAll,
1129
+ get: get,
1130
+ getEstateHash: getEstateHash
1131
+ };
1132
+ }
1133
+
1134
+ function companies (ctx) {
1135
+ function get(attributes) {
1136
+ var _attributes$includes;
1137
+
1138
+ ctx.checkAuth(TokenType.API_TOKEN);
1139
+ return ctx.httpClient.get("/companies/" + attributes.companyId, {
1140
+ params: {
1141
+ includes: (_attributes$includes = attributes.includes) == null ? void 0 : _attributes$includes.join(',')
1142
+ }
1143
+ });
1144
+ }
1145
+
1146
+ return {
1147
+ get: get
1148
+ };
1149
+ }
1150
+
1151
+ function contacts (ctx) {
1152
+ function getOne(attributes) {
1153
+ ctx.checkAuth(TokenType.API_TOKEN);
1154
+ return ctx.httpClient.get("/services/contacts/" + attributes.contactId);
1155
+ }
1156
+
1157
+ function getOneWithNegotiators(attributes) {
1158
+ ctx.checkAuth(TokenType.API_TOKEN);
1159
+ return ctx.httpClient.get("/services/contacts/" + attributes.contactId + "?includes=negotiators");
1160
+ }
1161
+
1162
+ function getAll(attributes) {
1163
+ var _attributes$page, _attributes$limit;
1164
+
1165
+ ctx.checkAuth(TokenType.API_TOKEN);
1166
+ return ctx.httpClient.get("/services/companies/" + attributes.companyId + "/contacts", {
1167
+ params: {
1168
+ page: (_attributes$page = attributes.page) != null ? _attributes$page : 1,
1169
+ limit: (_attributes$limit = attributes.limit) != null ? _attributes$limit : 10
1170
+ }
1171
+ });
1172
+ }
1173
+
1174
+ return {
1175
+ getOne: getOne,
1176
+ getOneWithNegotiators: getOneWithNegotiators,
1177
+ getAll: getAll
1178
+ };
1179
+ }
1180
+
1181
+ function contact_preferences(ctx) {
1182
+ function getAll(attributes) {
1183
+ ctx.checkAuth(TokenType.API_TOKEN);
1184
+ return ctx.httpClient.get("/services/contacts/" + attributes.contactId + "/preferences");
1185
+ }
1186
+
1187
+ return {
1188
+ getAll: getAll
1189
+ };
1190
+ }
1191
+
1192
+ function negotiators (ctx) {
1193
+ function getNegotiatorsByIdCompanyId(attributes) {
1194
+ ctx.checkAuth(TokenType.API_TOKEN);
1195
+ return ctx.httpClient.get("/services/companies/" + attributes.companyId + "/negotiators", {
1196
+ params: {
1197
+ ids: attributes.ids
1198
+ }
1199
+ });
1200
+ }
1201
+
1202
+ return {
1203
+ getNegotiatorsByIdCompanyId: getNegotiatorsByIdCompanyId
1204
+ };
1205
+ }
1206
+
1207
+ function offices (ctx) {
1208
+ function getOffice(attributes) {
1209
+ ctx.checkAuth(TokenType.API_TOKEN);
1210
+ return ctx.httpClient.get("/service/offices/" + attributes.officeId);
1211
+ }
1212
+
1213
+ return {
1214
+ getOffice: getOffice
1215
+ };
1216
+ }
1217
+
1218
+ var _envHosts;
1219
+ var envHosts = (_envHosts = {}, _envHosts[exports.Env.PRODUCTION] = 'https://api.sweepbright.com', _envHosts[exports.Env.STAGING] = 'https://api.staging.sweepbright.com', _envHosts[exports.Env.DEV] = 'https://api.dev.sweepbright.com', _envHosts);
1220
+
1221
+ function createClient(conf) {
1222
+ var clientId = conf.clientId,
1223
+ clientSecret = conf.clientSecret,
1224
+ _conf$env = conf.env,
1225
+ env = _conf$env === void 0 ? exports.Env.PRODUCTION : _conf$env,
1226
+ version = conf.version;
1227
+ var _auth = null;
1228
+ var httpClient = axios.create({
1229
+ baseURL: envHosts[env]
1230
+ }); //TODO: getData here is an antipattern. Interceptor should not change a type of response
1231
+
1232
+ httpClient.interceptors.response.use(getData, handleRequestFailure);
1233
+
1234
+ if (version) {
1235
+ httpClient.defaults.headers.common['Accept'] = "application/vnd.sweepbright." + version + "+json";
1236
+ }
1237
+
1238
+ var ctx = {
1239
+ httpClient: httpClient,
1240
+ checkAuth: function checkAuth(tokenType) {
1241
+ if (!_auth) {
1242
+ throw new Error('client is not authenticated');
1243
+ }
1244
+
1245
+ if (_auth.type !== tokenType) {
1246
+ throw new Error('authenticated with invalid token type');
1247
+ }
1248
+ }
1249
+ };
1250
+ var client = {
1251
+ authorize: function authorize(config) {
1252
+ if (config === void 0) {
1253
+ config = {};
1254
+ }
1255
+
1256
+ var _config = config,
1257
+ _config$scopes = _config.scopes,
1258
+ scopes = _config$scopes === void 0 ? ['companies:read', 'properties:download', 'lead_info:write'] : _config$scopes;
1259
+ !clientId ? invariant(false, 'missing client id') : void 0;
1260
+ !clientSecret ? invariant(false, 'missing client secret') : void 0;
1261
+ return httpClient.post('/auth/access-token', {
1262
+ client_id: clientId,
1263
+ client_secret: clientSecret,
1264
+ grant_type: 'client_credentials',
1265
+ scope: scopes.join(',')
1266
+ }).then(function (_ref) {
1267
+ var access_token = _ref.access_token,
1268
+ expires_in = _ref.expires_in;
1269
+ !access_token ? invariant(false, 'access token should be defined') : void 0;
1270
+ !expires_in ? invariant(false, 'expires_in should be defined') : void 0;
1271
+ _auth = {
1272
+ token: access_token,
1273
+ expiresIn: expires_in,
1274
+ type: TokenType.API_TOKEN
1275
+ }; // https://github.com/axios/axios#custom-instance-defaults
1276
+
1277
+ httpClient.defaults.headers.common['Authorization'] = "Bearer " + _auth.token;
1278
+ return client;
1279
+ });
1280
+ },
1281
+ withUserToken: function () {
1282
+ var _withUserToken = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(accessToken) {
1283
+ return runtime_1.wrap(function _callee$(_context) {
1284
+ while (1) {
1285
+ switch (_context.prev = _context.next) {
1286
+ case 0:
1287
+ _auth = {
1288
+ token: accessToken,
1289
+ type: TokenType.USER_TOKEN
1290
+ };
1291
+ httpClient.defaults.headers.common['Authorization'] = "Bearer " + _auth.token;
1292
+ return _context.abrupt("return", client);
1293
+
1294
+ case 3:
1295
+ case "end":
1296
+ return _context.stop();
1297
+ }
1298
+ }
1299
+ }, _callee);
1300
+ }));
1301
+
1302
+ function withUserToken(_x) {
1303
+ return _withUserToken.apply(this, arguments);
1304
+ }
1305
+
1306
+ return withUserToken;
1307
+ }(),
1308
+ leads: leads(ctx),
1309
+ channels: channels(ctx),
1310
+ estates: estates(ctx),
1311
+ channelAccounts: channelAccounts(ctx),
1312
+ companies: companies(ctx),
1313
+ contacts: contacts(ctx),
1314
+ contactPreferences: contact_preferences(ctx),
1315
+ negotiators: negotiators(ctx),
1316
+ offices: offices(ctx)
1317
+ };
1318
+ return client;
1319
+ }
1320
+
1321
+ exports.createClient = createClient;
1322
+ //# sourceMappingURL=api-client.cjs.development.js.map