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