asposeslidescloud 22.2.0 → 22.6.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.
@@ -1,33 +1,33 @@
1
- import request = require("request");
2
- import { Configuration } from "./configuration";
3
- export declare function checkMultipartContent(options: request.Options, files: any): void;
4
- /**
5
- * Invoke api method
6
- * @param requestOptions request parameters
7
- * @param confguration api configuration
8
- * @param notApplyAuthToRequest if setted to true, auth is not applied to request
9
- */
10
- export declare function invokeApiMethod(requestOptions: request.Options, confguration: Configuration, notApplyAuthToRequest?: boolean): Promise<request.RequestResponse>;
11
- /**
12
- * Add parameter to query
13
- * @param url url
14
- * @param queryParameters queryParameters
15
- * @param parameterName parameterName
16
- * @param parameterValue parameterValue
17
- */
18
- export declare function addQueryParameterToUrl(url: string, queryParameters: Array<string>, parameterName: string, parameterValue: any): string;
19
- /**
20
- * Add parameter to query
21
- * @param url url
22
- * @param queryParameters queryParameters
23
- * @param parameterName parameterName
24
- * @param parameterValue parameterValue
25
- */
26
- export declare function addPathParameterToUrl(url: string, parameterName: string, parameterValue: string): string;
27
- /**
28
- * Add parameter to headers
29
- * @param headers headers
30
- * @param parameterName parameterName
31
- * @param parameterValue parameterValue
32
- */
33
- export declare function addHeaderParameter(headers: any, parameterName: string, parameterValue: any): void;
1
+ import request = require("request");
2
+ import { Configuration } from "./configuration";
3
+ export declare function checkMultipartContent(options: request.Options, files: any): void;
4
+ /**
5
+ * Invoke api method
6
+ * @param requestOptions request parameters
7
+ * @param confguration api configuration
8
+ * @param notApplyAuthToRequest if setted to true, auth is not applied to request
9
+ */
10
+ export declare function invokeApiMethod(requestOptions: request.Options, confguration: Configuration, notApplyAuthToRequest?: boolean): Promise<request.RequestResponse>;
11
+ /**
12
+ * Add parameter to query
13
+ * @param url url
14
+ * @param queryParameters queryParameters
15
+ * @param parameterName parameterName
16
+ * @param parameterValue parameterValue
17
+ */
18
+ export declare function addQueryParameterToUrl(url: string, queryParameters: Array<string>, parameterName: string, parameterValue: any): string;
19
+ /**
20
+ * Add parameter to query
21
+ * @param url url
22
+ * @param queryParameters queryParameters
23
+ * @param parameterName parameterName
24
+ * @param parameterValue parameterValue
25
+ */
26
+ export declare function addPathParameterToUrl(url: string, parameterName: string, parameterValue: string): string;
27
+ /**
28
+ * Add parameter to headers
29
+ * @param headers headers
30
+ * @param parameterName parameterName
31
+ * @param parameterValue parameterValue
32
+ */
33
+ export declare function addHeaderParameter(headers: any, parameterName: string, parameterValue: any): void;
@@ -1,247 +1,249 @@
1
- "use strict";
2
- /*
3
- * MIT License
4
-
5
- * Copyright (c) 2018 Aspose Pty Ltd
6
-
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
-
14
- * The above copyright notice and this permission notice shall be included in all
15
- * copies or substantial portions of the Software.
16
-
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- */
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- const request = require("request");
35
- const requestDebug = require("request-debug");
36
- const objectSerializer_1 = require("./objectSerializer");
37
- function checkMultipartContent(options, files) {
38
- if (files && files.length) {
39
- const data = {
40
- pipeline: null,
41
- attachments: []
42
- };
43
- if (options.json !== true && options.json) {
44
- data.pipeline = JSON.stringify(options.json);
45
- }
46
- else {
47
- delete data.pipeline;
48
- }
49
- for (var i = 0; i < files.length; i++) {
50
- data.attachments.push(files[i]);
51
- }
52
- options.formData = data;
53
- options.json = null;
54
- }
55
- }
56
- exports.checkMultipartContent = checkMultipartContent;
57
- /**
58
- * Invoke api method
59
- * @param requestOptions request parameters
60
- * @param confguration api configuration
61
- * @param notApplyAuthToRequest if setted to true, auth is not applied to request
62
- */
63
- function invokeApiMethod(requestOptions, confguration, notApplyAuthToRequest) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- try {
66
- return yield invokeApiMethodInternal(requestOptions, confguration, notApplyAuthToRequest);
67
- }
68
- catch (e) {
69
- if (e instanceof NeedRepeatException) {
70
- return yield invokeApiMethodInternal(requestOptions, confguration, notApplyAuthToRequest);
71
- }
72
- throw e;
73
- }
74
- });
75
- }
76
- exports.invokeApiMethod = invokeApiMethod;
77
- /**
78
- * Add parameter to query
79
- * @param url url
80
- * @param queryParameters queryParameters
81
- * @param parameterName parameterName
82
- * @param parameterValue parameterValue
83
- */
84
- function addQueryParameterToUrl(url, queryParameters, parameterName, parameterValue) {
85
- if (parameterValue !== undefined && parameterValue != null) {
86
- if (Array.isArray(parameterValue)) {
87
- parameterValue = parameterValue.join(",");
88
- }
89
- if (url.indexOf("{" + parameterName + "}") >= 0) {
90
- url = url.replace("{" + parameterName + "}", String(parameterValue));
91
- }
92
- else {
93
- queryParameters[parameterName] = String(parameterValue);
94
- }
95
- }
96
- else {
97
- url = url.replace("/{" + parameterName + "}", "");
98
- }
99
- return url;
100
- }
101
- exports.addQueryParameterToUrl = addQueryParameterToUrl;
102
- /**
103
- * Add parameter to query
104
- * @param url url
105
- * @param queryParameters queryParameters
106
- * @param parameterName parameterName
107
- * @param parameterValue parameterValue
108
- */
109
- function addPathParameterToUrl(url, parameterName, parameterValue) {
110
- if (!parameterValue) {
111
- return url.replace("/{" + parameterName + "}", "");
112
- }
113
- return url.replace("{" + parameterName + "}", parameterValue);
114
- }
115
- exports.addPathParameterToUrl = addPathParameterToUrl;
116
- /**
117
- * Add parameter to headers
118
- * @param headers headers
119
- * @param parameterName parameterName
120
- * @param parameterValue parameterValue
121
- */
122
- function addHeaderParameter(headers, parameterName, parameterValue) {
123
- if (parameterValue) {
124
- headers[parameterName] = String(parameterValue);
125
- }
126
- }
127
- exports.addHeaderParameter = addHeaderParameter;
128
- /**
129
- * Invoke api method
130
- * @param requestOptions request parameters
131
- * @param confguration api configuration
132
- * @param notApplyAuthToRequest if setted to true, auth is not applied to request
133
- */
134
- function invokeApiMethodInternal(requestOptions, confguration, notApplyAuthToRequest) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- requestDebug(request, (type, data, r) => {
137
- if (r.writeDebugToConsole) {
138
- const toLog = {};
139
- toLog[type] = data;
140
- // tslint:disable-next-line:no-console
141
- console.log(JSON.stringify(toLog, undefined, 2));
142
- }
143
- });
144
- if (!requestOptions.headers) {
145
- requestOptions.headers = {};
146
- }
147
- requestOptions.headers["x-aspose-client"] = "nodejs sdk v22.2.0";
148
- if (confguration.timeout) {
149
- requestOptions.headers["x-aspose-timeout"] = confguration.timeout;
150
- }
151
- for (var key in confguration.customHeaders) {
152
- requestOptions.headers[key] = confguration.customHeaders[key];
153
- }
154
- if (!notApplyAuthToRequest) {
155
- yield addAuthHeader(requestOptions, confguration);
156
- }
157
- return new Promise((resolve, reject) => {
158
- const r = request(requestOptions, (error, response) => __awaiter(this, void 0, void 0, function* () {
159
- if (error) {
160
- reject(error);
161
- }
162
- else {
163
- if (response.statusCode >= 200 && response.statusCode <= 299) {
164
- resolve(response);
165
- }
166
- else if (!notApplyAuthToRequest && response.statusCode === 401) {
167
- yield requestToken(confguration);
168
- reject(new NeedRepeatException());
169
- }
170
- else {
171
- try {
172
- if (response.statusCode == 400 && response.body && response.body.error && typeof response.body.error == "string") {
173
- reject({ message: response.body.error, code: 401 });
174
- }
175
- else if (response.body && (response.body.length === undefined || response.body.length)) {
176
- let bodyContent = response.body;
177
- let bodyString = bodyContent;
178
- if (bodyContent instanceof Buffer) {
179
- bodyString = bodyContent.toString("utf8");
180
- bodyContent = JSON.parse(bodyString);
181
- }
182
- let result = objectSerializer_1.ObjectSerializer.deserialize(bodyContent, "SlidesApiErrorResponse");
183
- try {
184
- result = JSON.parse(result);
185
- }
186
- catch (_a) {
187
- //Error means the object is already deserialized
188
- reject({ message: result.error ? result.error.message : bodyString, code: response.statusCode });
189
- }
190
- }
191
- else {
192
- reject({ message: response.statusMessage, code: response.statusCode });
193
- }
194
- }
195
- catch (error) {
196
- reject({ message: "Error while parse server error: " + error });
197
- }
198
- }
199
- }
200
- }));
201
- r.writeDebugToConsole = confguration.debugMode;
202
- });
203
- });
204
- }
205
- function addAuthHeader(requestOptions, configuration) {
206
- return __awaiter(this, void 0, void 0, function* () {
207
- if (configuration.appSid || configuration.appKey) {
208
- if (isRequestTokenPending) {
209
- yield requestingToken;
210
- }
211
- if (!configuration.accessToken) {
212
- isRequestTokenPending = true;
213
- requestingToken = requestToken(configuration).catch((err) => { isRequestTokenPending = false; throw (err); });
214
- yield requestingToken;
215
- }
216
- isRequestTokenPending = false;
217
- if (requestOptions && requestOptions.headers) {
218
- requestOptions.headers.Authorization = "Bearer " + configuration.accessToken;
219
- }
220
- }
221
- return Promise.resolve();
222
- });
223
- }
224
- function requestToken(configuration) {
225
- return __awaiter(this, void 0, void 0, function* () {
226
- const requestOptions = {
227
- method: "POST",
228
- json: true,
229
- uri: configuration.authBaseUrl + "/connect/token",
230
- form: {
231
- grant_type: "client_credentials",
232
- client_id: configuration.appSid,
233
- client_secret: configuration.appKey,
234
- },
235
- };
236
- const response = yield invokeApiMethod(requestOptions, configuration, true);
237
- configuration.accessToken = response.body.access_token;
238
- return Promise.resolve();
239
- });
240
- }
241
- var requestingToken = null;
242
- var isRequestTokenPending = false;
243
- /**
244
- * Exception, indicating necessity of request repeat
245
- */
246
- class NeedRepeatException extends Error {
247
- }
1
+ "use strict";
2
+ /*
3
+ * MIT License
4
+
5
+ * Copyright (c) 2018 Aspose Pty Ltd
6
+
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.addHeaderParameter = exports.addPathParameterToUrl = exports.addQueryParameterToUrl = exports.invokeApiMethod = exports.checkMultipartContent = void 0;
36
+ const request = require("request");
37
+ const requestDebug = require("request-debug");
38
+ const objectSerializer_1 = require("./objectSerializer");
39
+ function checkMultipartContent(options, files) {
40
+ if (files && files.length) {
41
+ const data = {
42
+ pipeline: null,
43
+ attachments: []
44
+ };
45
+ if (options.json !== true && options.json) {
46
+ data.pipeline = JSON.stringify(options.json);
47
+ }
48
+ else {
49
+ delete data.pipeline;
50
+ }
51
+ for (var i = 0; i < files.length; i++) {
52
+ data.attachments.push(files[i]);
53
+ }
54
+ options.formData = data;
55
+ options.json = null;
56
+ }
57
+ }
58
+ exports.checkMultipartContent = checkMultipartContent;
59
+ /**
60
+ * Invoke api method
61
+ * @param requestOptions request parameters
62
+ * @param confguration api configuration
63
+ * @param notApplyAuthToRequest if setted to true, auth is not applied to request
64
+ */
65
+ function invokeApiMethod(requestOptions, confguration, notApplyAuthToRequest) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ try {
68
+ return yield invokeApiMethodInternal(requestOptions, confguration, notApplyAuthToRequest);
69
+ }
70
+ catch (e) {
71
+ if (e instanceof NeedRepeatException) {
72
+ return yield invokeApiMethodInternal(requestOptions, confguration, notApplyAuthToRequest);
73
+ }
74
+ throw e;
75
+ }
76
+ });
77
+ }
78
+ exports.invokeApiMethod = invokeApiMethod;
79
+ /**
80
+ * Add parameter to query
81
+ * @param url url
82
+ * @param queryParameters queryParameters
83
+ * @param parameterName parameterName
84
+ * @param parameterValue parameterValue
85
+ */
86
+ function addQueryParameterToUrl(url, queryParameters, parameterName, parameterValue) {
87
+ if (parameterValue !== undefined && parameterValue != null) {
88
+ if (Array.isArray(parameterValue)) {
89
+ parameterValue = parameterValue.join(",");
90
+ }
91
+ if (url.indexOf("{" + parameterName + "}") >= 0) {
92
+ url = url.replace("{" + parameterName + "}", String(parameterValue));
93
+ }
94
+ else {
95
+ queryParameters[parameterName] = String(parameterValue);
96
+ }
97
+ }
98
+ else {
99
+ url = url.replace("/{" + parameterName + "}", "");
100
+ }
101
+ return url;
102
+ }
103
+ exports.addQueryParameterToUrl = addQueryParameterToUrl;
104
+ /**
105
+ * Add parameter to query
106
+ * @param url url
107
+ * @param queryParameters queryParameters
108
+ * @param parameterName parameterName
109
+ * @param parameterValue parameterValue
110
+ */
111
+ function addPathParameterToUrl(url, parameterName, parameterValue) {
112
+ if (!parameterValue) {
113
+ return url.replace("/{" + parameterName + "}", "");
114
+ }
115
+ return url.replace("{" + parameterName + "}", parameterValue);
116
+ }
117
+ exports.addPathParameterToUrl = addPathParameterToUrl;
118
+ /**
119
+ * Add parameter to headers
120
+ * @param headers headers
121
+ * @param parameterName parameterName
122
+ * @param parameterValue parameterValue
123
+ */
124
+ function addHeaderParameter(headers, parameterName, parameterValue) {
125
+ if (parameterValue) {
126
+ headers[parameterName] = String(parameterValue);
127
+ }
128
+ }
129
+ exports.addHeaderParameter = addHeaderParameter;
130
+ /**
131
+ * Invoke api method
132
+ * @param requestOptions request parameters
133
+ * @param confguration api configuration
134
+ * @param notApplyAuthToRequest if setted to true, auth is not applied to request
135
+ */
136
+ function invokeApiMethodInternal(requestOptions, confguration, notApplyAuthToRequest) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ requestDebug(request, (type, data, r) => {
139
+ if (r.writeDebugToConsole) {
140
+ const toLog = {};
141
+ toLog[type] = data;
142
+ // tslint:disable-next-line:no-console
143
+ console.log(JSON.stringify(toLog, undefined, 2));
144
+ }
145
+ });
146
+ if (!requestOptions.headers) {
147
+ requestOptions.headers = {};
148
+ }
149
+ requestOptions.headers["x-aspose-client"] = "nodejs sdk v22.6.0";
150
+ if (confguration.timeout) {
151
+ requestOptions.headers["x-aspose-timeout"] = confguration.timeout;
152
+ }
153
+ for (var key in confguration.customHeaders) {
154
+ requestOptions.headers[key] = confguration.customHeaders[key];
155
+ }
156
+ if (!notApplyAuthToRequest) {
157
+ yield addAuthHeader(requestOptions, confguration);
158
+ }
159
+ return new Promise((resolve, reject) => {
160
+ const r = request(requestOptions, (error, response) => __awaiter(this, void 0, void 0, function* () {
161
+ if (error) {
162
+ reject(error);
163
+ }
164
+ else {
165
+ if (response.statusCode >= 200 && response.statusCode <= 299) {
166
+ resolve(response);
167
+ }
168
+ else if (!notApplyAuthToRequest && response.statusCode === 401) {
169
+ yield requestToken(confguration);
170
+ reject(new NeedRepeatException());
171
+ }
172
+ else {
173
+ try {
174
+ if (response.statusCode == 400 && response.body && response.body.error && typeof response.body.error == "string") {
175
+ reject({ message: response.body.error, code: 401 });
176
+ }
177
+ else if (response.body && (response.body.length === undefined || response.body.length)) {
178
+ let bodyContent = response.body;
179
+ let bodyString = bodyContent;
180
+ if (bodyContent instanceof Buffer) {
181
+ bodyString = bodyContent.toString("utf8");
182
+ bodyContent = JSON.parse(bodyString);
183
+ }
184
+ let result = objectSerializer_1.ObjectSerializer.deserialize(bodyContent, "SlidesApiErrorResponse");
185
+ try {
186
+ result = JSON.parse(result);
187
+ }
188
+ catch (_a) {
189
+ //Error means the object is already deserialized
190
+ reject({ message: result.error ? result.error.message : bodyString, code: response.statusCode });
191
+ }
192
+ }
193
+ else {
194
+ reject({ message: response.statusMessage, code: response.statusCode });
195
+ }
196
+ }
197
+ catch (error) {
198
+ reject({ message: "Error while parse server error: " + error });
199
+ }
200
+ }
201
+ }
202
+ }));
203
+ r.writeDebugToConsole = confguration.debugMode;
204
+ });
205
+ });
206
+ }
207
+ function addAuthHeader(requestOptions, configuration) {
208
+ return __awaiter(this, void 0, void 0, function* () {
209
+ if (configuration.appSid || configuration.appKey) {
210
+ if (isRequestTokenPending) {
211
+ yield requestingToken;
212
+ }
213
+ if (!configuration.accessToken) {
214
+ isRequestTokenPending = true;
215
+ requestingToken = requestToken(configuration).catch((err) => { isRequestTokenPending = false; throw (err); });
216
+ yield requestingToken;
217
+ }
218
+ isRequestTokenPending = false;
219
+ if (requestOptions && requestOptions.headers) {
220
+ requestOptions.headers.Authorization = "Bearer " + configuration.accessToken;
221
+ }
222
+ }
223
+ return Promise.resolve();
224
+ });
225
+ }
226
+ function requestToken(configuration) {
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ const requestOptions = {
229
+ method: "POST",
230
+ json: true,
231
+ uri: configuration.authBaseUrl + "/connect/token",
232
+ form: {
233
+ grant_type: "client_credentials",
234
+ client_id: configuration.appSid,
235
+ client_secret: configuration.appKey,
236
+ },
237
+ };
238
+ const response = yield invokeApiMethod(requestOptions, configuration, true);
239
+ configuration.accessToken = response.body.access_token;
240
+ return Promise.resolve();
241
+ });
242
+ }
243
+ var requestingToken = null;
244
+ var isRequestTokenPending = false;
245
+ /**
246
+ * Exception, indicating necessity of request repeat
247
+ */
248
+ class NeedRepeatException extends Error {
249
+ }