1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | exports.Client = void 0;
|
10 | var tslib_1 = require("tslib");
|
11 |
|
12 |
|
13 |
|
14 | var Constants_1 = require("./Constants");
|
15 | var CustomAuthenticationProvider_1 = require("./CustomAuthenticationProvider");
|
16 | var GraphRequest_1 = require("./GraphRequest");
|
17 | var HTTPClient_1 = require("./HTTPClient");
|
18 | var HTTPClientFactory_1 = require("./HTTPClientFactory");
|
19 | var ValidatePolyFilling_1 = require("./ValidatePolyFilling");
|
20 | var Client = (function () {
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function Client(clientOptions) {
|
28 | |
29 |
|
30 |
|
31 |
|
32 | this.config = {
|
33 | baseUrl: Constants_1.GRAPH_BASE_URL,
|
34 | debugLogging: false,
|
35 | defaultVersion: Constants_1.GRAPH_API_VERSION,
|
36 | };
|
37 | (0, ValidatePolyFilling_1.validatePolyFilling)();
|
38 | for (var key in clientOptions) {
|
39 | if (Object.prototype.hasOwnProperty.call(clientOptions, key)) {
|
40 | this.config[key] = clientOptions[key];
|
41 | }
|
42 | }
|
43 | var httpClient;
|
44 | if (clientOptions.authProvider !== undefined && clientOptions.middleware !== undefined) {
|
45 | var error = new Error();
|
46 | error.name = "AmbiguityInInitialization";
|
47 | error.message = "Unable to Create Client, Please provide either authentication provider for default middleware chain or custom middleware chain not both";
|
48 | throw error;
|
49 | }
|
50 | else if (clientOptions.authProvider !== undefined) {
|
51 | httpClient = HTTPClientFactory_1.HTTPClientFactory.createWithAuthenticationProvider(clientOptions.authProvider);
|
52 | }
|
53 | else if (clientOptions.middleware !== undefined) {
|
54 | httpClient = new (HTTPClient_1.HTTPClient.bind.apply(HTTPClient_1.HTTPClient, tslib_1.__spreadArray([void 0], [].concat(clientOptions.middleware), false)))();
|
55 | }
|
56 | else {
|
57 | var error = new Error();
|
58 | error.name = "InvalidMiddlewareChain";
|
59 | error.message = "Unable to Create Client, Please provide either authentication provider for default middleware chain or custom middleware chain";
|
60 | throw error;
|
61 | }
|
62 | this.httpClient = httpClient;
|
63 | }
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | Client.init = function (options) {
|
72 | var clientOptions = {};
|
73 | for (var i in options) {
|
74 | if (Object.prototype.hasOwnProperty.call(options, i)) {
|
75 | clientOptions[i] = i === "authProvider" ? new CustomAuthenticationProvider_1.CustomAuthenticationProvider(options[i]) : options[i];
|
76 | }
|
77 | }
|
78 | return Client.initWithMiddleware(clientOptions);
|
79 | };
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | Client.initWithMiddleware = function (clientOptions) {
|
88 | return new Client(clientOptions);
|
89 | };
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | Client.prototype.api = function (path) {
|
97 | return new GraphRequest_1.GraphRequest(this.httpClient, this.config, path);
|
98 | };
|
99 | return Client;
|
100 | }());
|
101 | exports.Client = Client;
|
102 |
|
\ | No newline at end of file |