docspring 1.4.0 → 2.0.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 (221) hide show
  1. package/README.md +58 -52
  2. package/dist/ApiClient.js +701 -0
  3. package/dist/api/PDFApi.js +1509 -0
  4. package/dist/index.js +356 -0
  5. package/dist/model/AddFieldsData.js +112 -0
  6. package/dist/model/BatchGeneratePdfs201Response.js +184 -0
  7. package/dist/model/CombinePdfsData.js +156 -0
  8. package/dist/model/CombinedSubmission.js +323 -0
  9. package/dist/model/CombinedSubmissionAction.js +252 -0
  10. package/dist/model/CombinedSubmissionData.js +148 -0
  11. package/dist/model/CopyTemplateOptions.js +124 -0
  12. package/dist/model/CreateCombinedSubmissionResponse.js +158 -0
  13. package/dist/model/CreateCustomFileData.js +112 -0
  14. package/dist/model/CreateCustomFileResponse.js +158 -0
  15. package/dist/model/CreateFolderData.js +108 -0
  16. package/dist/model/CreateHtmlSubmissionData.js +161 -0
  17. package/dist/model/CreateHtmlTemplate.js +108 -0
  18. package/dist/model/CreatePdfSubmissionData.js +190 -0
  19. package/dist/model/CreatePdfTemplate.js +108 -0
  20. package/dist/model/CreateSubmissionDataRequestData.js +210 -0
  21. package/dist/model/CreateSubmissionDataRequestEventRequest.js +215 -0
  22. package/dist/model/CreateSubmissionDataRequestEventResponse.js +158 -0
  23. package/dist/model/CreateSubmissionDataRequestResponse.js +158 -0
  24. package/dist/model/CreateSubmissionDataRequestTokenResponse.js +158 -0
  25. package/dist/model/CreateSubmissionResponse.js +158 -0
  26. package/dist/model/CustomFile.js +126 -0
  27. package/dist/model/ErrorResponse.js +139 -0
  28. package/dist/model/Folder.js +154 -0
  29. package/dist/model/JsonSchema.js +173 -0
  30. package/dist/model/ListSubmissionsResponse.js +154 -0
  31. package/dist/model/MoveFolderData.js +89 -0
  32. package/dist/model/MoveTemplateData.js +112 -0
  33. package/dist/model/MultipleErrorsResponse.js +139 -0
  34. package/dist/model/RenameFolderData.js +112 -0
  35. package/dist/model/Submission.js +537 -0
  36. package/dist/model/SubmissionAction.js +252 -0
  37. package/dist/model/SubmissionBatch.js +213 -0
  38. package/dist/model/SubmissionBatchData.js +128 -0
  39. package/dist/model/SubmissionBatchWithSubmissions.js +243 -0
  40. package/dist/model/SubmissionDataRequest.js +475 -0
  41. package/dist/model/SubmissionDataRequestEvent.js +287 -0
  42. package/dist/model/SubmissionDataRequestShow.js +489 -0
  43. package/dist/model/SubmissionDataRequestToken.js +154 -0
  44. package/dist/model/SubmissionPreview.js +471 -0
  45. package/dist/model/SuccessErrorResponse.js +142 -0
  46. package/dist/model/SuccessMultipleErrorsResponse.js +142 -0
  47. package/dist/model/Template.js +717 -0
  48. package/dist/model/TemplateAddFieldsResponse.js +154 -0
  49. package/dist/model/TemplatePreview.js +593 -0
  50. package/dist/model/UpdateHtmlTemplate.js +108 -0
  51. package/dist/model/UpdateSubmissionDataRequestData.js +160 -0
  52. package/dist/model/UploadPresignResponse.js +157 -0
  53. package/package.json +33 -8
  54. package/.openapi-generator/VERSION +0 -1
  55. package/.openapi-generator-ignore +0 -23
  56. package/.travis.yml +0 -7
  57. package/CHANGELOG.md +0 -33
  58. package/docs/AddFieldsData.md +0 -8
  59. package/docs/AddFieldsTemplateResponse.md +0 -21
  60. package/docs/AuthenticationError.md +0 -18
  61. package/docs/AuthenticationSuccessResponse.md +0 -17
  62. package/docs/CombinePdfsData.md +0 -13
  63. package/docs/CombinedSubmission.md +0 -31
  64. package/docs/CombinedSubmissionAction.md +0 -54
  65. package/docs/CombinedSubmissionData.md +0 -12
  66. package/docs/CopyTemplateData.md +0 -9
  67. package/docs/CreateCombinedSubmissionResponse.md +0 -21
  68. package/docs/CreateCustomFileData.md +0 -8
  69. package/docs/CreateCustomFileResponse.md +0 -21
  70. package/docs/CreateFolderData.md +0 -8
  71. package/docs/CreateHtmlTemplateData.md +0 -8
  72. package/docs/CreateSubmissionBatchResponse.md +0 -23
  73. package/docs/CreateSubmissionBatchSubmissionsResponse.md +0 -23
  74. package/docs/CreateSubmissionDataRequestData.md +0 -60
  75. package/docs/CreateSubmissionDataRequestTokenResponse.md +0 -21
  76. package/docs/CreateSubmissionDataRequestTokenResponseToken.md +0 -11
  77. package/docs/CreateSubmissionResponse.md +0 -21
  78. package/docs/CreateTemplateFromUploadData.md +0 -8
  79. package/docs/CustomFile.md +0 -9
  80. package/docs/Error.md +0 -18
  81. package/docs/Folder.md +0 -11
  82. package/docs/FoldersFolder.md +0 -9
  83. package/docs/FullTemplate.md +0 -59
  84. package/docs/FullTemplateDefaults.md +0 -10
  85. package/docs/HtmlTemplateData.md +0 -48
  86. package/docs/InvalidRequest.md +0 -18
  87. package/docs/ListSubmissionsResponse.md +0 -10
  88. package/docs/MoveFolderData.md +0 -8
  89. package/docs/MoveTemplateData.md +0 -8
  90. package/docs/PDFApi.md +0 -1700
  91. package/docs/PendingTemplate.md +0 -37
  92. package/docs/RenameFolderData.md +0 -8
  93. package/docs/Submission.md +0 -55
  94. package/docs/SubmissionAction.md +0 -54
  95. package/docs/SubmissionBatch.md +0 -29
  96. package/docs/SubmissionBatchData.md +0 -11
  97. package/docs/SubmissionData.md +0 -15
  98. package/docs/SubmissionDataBatchRequest.md +0 -13
  99. package/docs/SubmissionDataRequest.md +0 -78
  100. package/docs/Template.md +0 -40
  101. package/docs/TemplateData.md +0 -36
  102. package/docs/TemplatestemplateIdaddFieldsFields.md +0 -286
  103. package/docs/UpdateDataRequestResponse.md +0 -21
  104. package/docs/UpdateSubmissionDataRequestData.md +0 -60
  105. package/docs/UpdateTemplateData.md +0 -8
  106. package/docs/UpdateTemplateResponse.md +0 -20
  107. package/docs/UploadTemplateData.md +0 -49
  108. package/docs/UploadTemplateDataDocument.md +0 -19
  109. package/docs/UploadTemplateDataDocumentMetadata.md +0 -19
  110. package/git_push.sh +0 -52
  111. package/mocha.opts +0 -1
  112. package/src/ApiClient.js +0 -605
  113. package/src/api/Client.js +0 -395
  114. package/src/api/PDFApi.js +0 -1722
  115. package/src/index.js +0 -334
  116. package/src/model/AddFieldsData.js +0 -82
  117. package/src/model/AddFieldsTemplateResponse.js +0 -114
  118. package/src/model/AuthenticationError.js +0 -102
  119. package/src/model/AuthenticationSuccessResponse.js +0 -93
  120. package/src/model/CombinePdfsData.js +0 -122
  121. package/src/model/CombinedSubmission.js +0 -183
  122. package/src/model/CombinedSubmissionAction.js +0 -198
  123. package/src/model/CombinedSubmissionData.js +0 -114
  124. package/src/model/CopyTemplateData.js +0 -90
  125. package/src/model/CreateCombinedSubmissionResponse.js +0 -114
  126. package/src/model/CreateCustomFileData.js +0 -82
  127. package/src/model/CreateCustomFileResponse.js +0 -114
  128. package/src/model/CreateFolderData.js +0 -82
  129. package/src/model/CreateHtmlTemplateData.js +0 -82
  130. package/src/model/CreateSubmissionBatchResponse.js +0 -130
  131. package/src/model/CreateSubmissionBatchSubmissionsResponse.js +0 -119
  132. package/src/model/CreateSubmissionDataRequestData.js +0 -256
  133. package/src/model/CreateSubmissionDataRequestTokenResponse.js +0 -114
  134. package/src/model/CreateSubmissionDataRequestTokenResponseToken.js +0 -105
  135. package/src/model/CreateSubmissionResponse.js +0 -114
  136. package/src/model/CreateTemplateFromUploadData.js +0 -82
  137. package/src/model/CustomFile.js +0 -89
  138. package/src/model/Error.js +0 -103
  139. package/src/model/Folder.js +0 -105
  140. package/src/model/FoldersFolder.js +0 -89
  141. package/src/model/FullTemplate.js +0 -407
  142. package/src/model/FullTemplateDefaults.js +0 -97
  143. package/src/model/HtmlTemplateData.js +0 -248
  144. package/src/model/InvalidRequest.js +0 -103
  145. package/src/model/ListSubmissionsResponse.js +0 -97
  146. package/src/model/MoveFolderData.js +0 -81
  147. package/src/model/MoveTemplateData.js +0 -82
  148. package/src/model/PendingTemplate.js +0 -231
  149. package/src/model/RenameFolderData.js +0 -82
  150. package/src/model/Submission.js +0 -291
  151. package/src/model/SubmissionAction.js +0 -198
  152. package/src/model/SubmissionBatch.js +0 -167
  153. package/src/model/SubmissionBatchData.js +0 -106
  154. package/src/model/SubmissionData.js +0 -138
  155. package/src/model/SubmissionDataBatchRequest.js +0 -121
  156. package/src/model/SubmissionDataRequest.js +0 -337
  157. package/src/model/Template.js +0 -255
  158. package/src/model/TemplateData.js +0 -223
  159. package/src/model/TemplatestemplateIdaddFieldsFields.js +0 -1128
  160. package/src/model/UpdateDataRequestResponse.js +0 -114
  161. package/src/model/UpdateSubmissionDataRequestData.js +0 -256
  162. package/src/model/UpdateTemplateData.js +0 -82
  163. package/src/model/UpdateTemplateResponse.js +0 -106
  164. package/src/model/UploadTemplateData.js +0 -256
  165. package/src/model/UploadTemplateDataDocument.js +0 -109
  166. package/src/model/UploadTemplateDataDocumentMetadata.js +0 -109
  167. package/test/api/ClientIntegration.spec.js +0 -275
  168. package/test/api/PDFApi.spec.js.original +0 -395
  169. package/test/api/PDFApiIntegration.spec.js +0 -301
  170. package/test/model/AddFieldsData.spec.js +0 -67
  171. package/test/model/AddFieldsTemplateResponse.spec.js +0 -79
  172. package/test/model/AuthenticationError.spec.js +0 -73
  173. package/test/model/AuthenticationSuccessResponse.spec.js +0 -67
  174. package/test/model/CombinePdfsData.spec.js +0 -97
  175. package/test/model/CombinedSubmission.spec.js +0 -127
  176. package/test/model/CombinedSubmissionAction.spec.js +0 -97
  177. package/test/model/CombinedSubmissionData.spec.js +0 -91
  178. package/test/model/CopyTemplateData.spec.js +0 -73
  179. package/test/model/CreateCombinedSubmissionResponse.spec.js +0 -79
  180. package/test/model/CreateCustomFileData.spec.js +0 -67
  181. package/test/model/CreateCustomFileResponse.spec.js +0 -79
  182. package/test/model/CreateFolderData.spec.js +0 -67
  183. package/test/model/CreateHtmlTemplateData.spec.js +0 -67
  184. package/test/model/CreateSubmissionBatchResponse.spec.js +0 -91
  185. package/test/model/CreateSubmissionBatchSubmissionsResponse.spec.js +0 -79
  186. package/test/model/CreateSubmissionDataRequestData.spec.js +0 -139
  187. package/test/model/CreateSubmissionDataRequestTokenResponse.spec.js +0 -79
  188. package/test/model/CreateSubmissionDataRequestTokenResponseToken.spec.js +0 -85
  189. package/test/model/CreateSubmissionResponse.spec.js +0 -79
  190. package/test/model/CreateTemplateFromUploadData.spec.js +0 -67
  191. package/test/model/CustomFile.spec.js +0 -73
  192. package/test/model/Error.spec.js +0 -73
  193. package/test/model/Folder.spec.js +0 -85
  194. package/test/model/FoldersFolder.spec.js +0 -73
  195. package/test/model/FullTemplate.spec.js +0 -295
  196. package/test/model/FullTemplateDefaults.spec.js +0 -79
  197. package/test/model/HtmlTemplateData.spec.js +0 -163
  198. package/test/model/InvalidRequest.spec.js +0 -73
  199. package/test/model/ListSubmissionsResponse.spec.js +0 -79
  200. package/test/model/MoveFolderData.spec.js +0 -67
  201. package/test/model/MoveTemplateData.spec.js +0 -67
  202. package/test/model/PendingTemplate.spec.js +0 -163
  203. package/test/model/RenameFolderData.spec.js +0 -67
  204. package/test/model/Submission.spec.js +0 -175
  205. package/test/model/SubmissionAction.spec.js +0 -97
  206. package/test/model/SubmissionBatch.spec.js +0 -115
  207. package/test/model/SubmissionBatchData.spec.js +0 -85
  208. package/test/model/SubmissionData.spec.js +0 -109
  209. package/test/model/SubmissionDataBatchRequest.spec.js +0 -97
  210. package/test/model/SubmissionDataRequest.spec.js +0 -181
  211. package/test/model/Template.spec.js +0 -181
  212. package/test/model/TemplateData.spec.js +0 -157
  213. package/test/model/TemplatestemplateIdaddFieldsFields.spec.js +0 -577
  214. package/test/model/UpdateDataRequestResponse.spec.js +0 -79
  215. package/test/model/UpdateSubmissionDataRequestData.spec.js +0 -139
  216. package/test/model/UpdateTemplateData.spec.js +0 -67
  217. package/test/model/UpdateTemplateResponse.spec.js +0 -73
  218. package/test/model/UploadTemplateData.spec.js +0 -169
  219. package/test/model/UploadTemplateDataDocument.spec.js +0 -79
  220. package/test/model/UploadTemplateDataDocumentMetadata.spec.js +0 -79
  221. package/yarn.lock +0 -263
package/src/ApiClient.js DELETED
@@ -1,605 +0,0 @@
1
- /**
2
- * API v1
3
- * DocSpring is a service that helps you fill out and sign PDF templates.
4
- *
5
- * OpenAPI spec version: v1
6
- *
7
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
8
- * https://openapi-generator.tech
9
- *
10
- * OpenAPI Generator version: 3.3.0
11
- *
12
- * Do not edit the class manually.
13
- *
14
- */
15
-
16
- (function(root, factory) {
17
- if (typeof define === 'function' && define.amd) {
18
- // AMD. Register as an anonymous module.
19
- define(['superagent', 'querystring'], factory);
20
- } else if (typeof module === 'object' && module.exports) {
21
- // CommonJS-like environments that support module.exports, like Node.
22
- module.exports = factory(require('superagent'), require('querystring'));
23
- } else {
24
- // Browser globals (root is window)
25
- if (!root.DocSpring) {
26
- root.DocSpring = {};
27
- }
28
- root.DocSpring.ApiClient = factory(root.superagent, root.querystring);
29
- }
30
- }(this, function(superagent, querystring) {
31
- 'use strict';
32
-
33
- /**
34
- * @module ApiClient
35
- * @version 1.4.0
36
- */
37
-
38
- /**
39
- * Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
40
- * application to use this class directly - the *Api and model classes provide the public API for the service. The
41
- * contents of this file should be regarded as internal but are documented for completeness.
42
- * @alias module:ApiClient
43
- * @class
44
- */
45
- var exports = function() {
46
- /**
47
- * The base URL against which to resolve every API call's (relative) path.
48
- * @type {String}
49
- * @default https://api.docspring.com/api/v1
50
- */
51
- this.basePath = 'https://api.docspring.com/api/v1'.replace(/\/+$/, '');
52
-
53
- /**
54
- * The authentication methods to be included for all API calls.
55
- * Skip this - just use a username and password. We only support basic auth.
56
- * @type {Array.<String>}
57
- */
58
- this.apiTokenId = null;
59
- this.apiTokenSecret = null;
60
- this.authentications = {
61
- 'api_token_basic': {type: 'basic'}
62
- };
63
- /**
64
- * The default HTTP headers to be included for all API calls.
65
- * @type {Array.<String>}
66
- * @default {}
67
- */
68
- this.defaultHeaders = {};
69
-
70
- /**
71
- * The default HTTP timeout for all API calls.
72
- * @type {Number}
73
- * @default 60000
74
- */
75
- this.timeout = 60000;
76
-
77
- /**
78
- * If set to false an additional timestamp parameter is added to all API GET calls to
79
- * prevent browser caching
80
- * @type {Boolean}
81
- * @default true
82
- */
83
- this.cache = true;
84
-
85
- /**
86
- * If set to true, the client will save the cookies from each server
87
- * response, and return them in the next request.
88
- * @default false
89
- */
90
- this.enableCookies = false;
91
-
92
- /*
93
- * Used to save and return cookies in a node.js (non-browser) setting,
94
- * if this.enableCookies is set to true.
95
- */
96
- if (typeof window === 'undefined') {
97
- this.agent = new superagent.agent();
98
- }
99
-
100
- /*
101
- * Allow user to override superagent agent
102
- */
103
- this.requestAgent = null;
104
- };
105
-
106
- /**
107
- * Returns a string representation for an actual parameter.
108
- * @param param The actual parameter.
109
- * @returns {String} The string representation of <code>param</code>.
110
- */
111
- exports.prototype.paramToString = function(param) {
112
- if (param == undefined || param == null) {
113
- return '';
114
- }
115
- if (param instanceof Date) {
116
- return param.toJSON();
117
- }
118
- return param.toString();
119
- };
120
-
121
- /**
122
- * Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
123
- * NOTE: query parameters are not handled here.
124
- * @param {String} path The path to append to the base URL.
125
- * @param {Object} pathParams The parameter values to append.
126
- * @returns {String} The encoded path with parameter values substituted.
127
- */
128
- exports.prototype.buildUrl = function(path, pathParams) {
129
- if (!path.match(/^\//)) {
130
- path = '/' + path;
131
- }
132
- var url = this.basePath + path;
133
- var _this = this;
134
- url = url.replace(/\{([\w-]+)\}/g, function(fullMatch, key) {
135
- var value;
136
- if (pathParams.hasOwnProperty(key)) {
137
- value = _this.paramToString(pathParams[key]);
138
- } else {
139
- value = fullMatch;
140
- }
141
- return encodeURIComponent(value);
142
- });
143
- return url;
144
- };
145
-
146
- /**
147
- * Checks whether the given content type represents JSON.<br>
148
- * JSON content type examples:<br>
149
- * <ul>
150
- * <li>application/json</li>
151
- * <li>application/json; charset=UTF8</li>
152
- * <li>APPLICATION/JSON</li>
153
- * </ul>
154
- * @param {String} contentType The MIME content type to check.
155
- * @returns {Boolean} <code>true</code> if <code>contentType</code> represents JSON, otherwise <code>false</code>.
156
- */
157
- exports.prototype.isJsonMime = function(contentType) {
158
- return Boolean(contentType != null && contentType.match(/^application\/json(;.*)?$/i));
159
- };
160
-
161
- /**
162
- * Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.
163
- * @param {Array.<String>} contentTypes
164
- * @returns {String} The chosen content type, preferring JSON.
165
- */
166
- exports.prototype.jsonPreferredMime = function(contentTypes) {
167
- for (var i = 0; i < contentTypes.length; i++) {
168
- if (this.isJsonMime(contentTypes[i])) {
169
- return contentTypes[i];
170
- }
171
- }
172
- return contentTypes[0];
173
- };
174
-
175
- /**
176
- * Checks whether the given parameter value represents file-like content.
177
- * @param param The parameter to check.
178
- * @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
179
- */
180
- exports.prototype.isFileParam = function(param) {
181
- // fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
182
- if (typeof require === 'function') {
183
- var fs;
184
- try {
185
- fs = require('fs');
186
- } catch (err) {}
187
- if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
188
- return true;
189
- }
190
- }
191
- // Buffer in Node.js
192
- if (typeof Buffer === 'function' && param instanceof Buffer) {
193
- return true;
194
- }
195
- // Blob in browser
196
- if (typeof Blob === 'function' && param instanceof Blob) {
197
- return true;
198
- }
199
- // File in browser (it seems File object is also instance of Blob, but keep this for safe)
200
- if (typeof File === 'function' && param instanceof File) {
201
- return true;
202
- }
203
- return false;
204
- };
205
-
206
- /**
207
- * Normalizes parameter values:
208
- * <ul>
209
- * <li>remove nils</li>
210
- * <li>keep files and arrays</li>
211
- * <li>format to string with `paramToString` for other cases</li>
212
- * </ul>
213
- * @param {Object.<String, Object>} params The parameters as object properties.
214
- * @returns {Object.<String, Object>} normalized parameters.
215
- */
216
- exports.prototype.normalizeParams = function(params) {
217
- var newParams = {};
218
- for (var key in params) {
219
- if (params.hasOwnProperty(key) && params[key] != undefined && params[key] != null) {
220
- var value = params[key];
221
- if (this.isFileParam(value) || Array.isArray(value)) {
222
- newParams[key] = value;
223
- } else {
224
- newParams[key] = this.paramToString(value);
225
- }
226
- }
227
- }
228
- return newParams;
229
- };
230
-
231
- /**
232
- * Enumeration of collection format separator strategies.
233
- * @enum {String}
234
- * @readonly
235
- */
236
- exports.CollectionFormatEnum = {
237
- /**
238
- * Comma-separated values. Value: <code>csv</code>
239
- * @const
240
- */
241
- CSV: ',',
242
- /**
243
- * Space-separated values. Value: <code>ssv</code>
244
- * @const
245
- */
246
- SSV: ' ',
247
- /**
248
- * Tab-separated values. Value: <code>tsv</code>
249
- * @const
250
- */
251
- TSV: '\t',
252
- /**
253
- * Pipe(|)-separated values. Value: <code>pipes</code>
254
- * @const
255
- */
256
- PIPES: '|',
257
- /**
258
- * Native array. Value: <code>multi</code>
259
- * @const
260
- */
261
- MULTI: 'multi'
262
- };
263
-
264
- /**
265
- * Builds a string representation of an array-type actual parameter, according to the given collection format.
266
- * @param {Array} param An array parameter.
267
- * @param {module:ApiClient.CollectionFormatEnum} collectionFormat The array element separator strategy.
268
- * @returns {String|Array} A string representation of the supplied collection, using the specified delimiter. Returns
269
- * <code>param</code> as is if <code>collectionFormat</code> is <code>multi</code>.
270
- */
271
- exports.prototype.buildCollectionParam = function buildCollectionParam(param, collectionFormat) {
272
- if (param == null) {
273
- return null;
274
- }
275
- switch (collectionFormat) {
276
- case 'csv':
277
- return param.map(this.paramToString).join(',');
278
- case 'ssv':
279
- return param.map(this.paramToString).join(' ');
280
- case 'tsv':
281
- return param.map(this.paramToString).join('\t');
282
- case 'pipes':
283
- return param.map(this.paramToString).join('|');
284
- case 'multi':
285
- // return the array directly as SuperAgent will handle it as expected
286
- return param.map(this.paramToString);
287
- default:
288
- throw new Error('Unknown collection format: ' + collectionFormat);
289
- }
290
- };
291
-
292
- /**
293
- * Applies authentication headers to the request.
294
- * @param {Object} request The request object created by a <code>superagent()</code> call.
295
- * @param {Array.<String>} authNames An array of authentication method names.
296
- */
297
- exports.prototype.applyAuthToRequest = function(request, authNames) {
298
- if (!this.apiTokenId || !this.apiTokenSecret) {
299
- throw new Error('apiTokenId and apiTokenSecret are required!');
300
- }
301
- request.auth(this.apiTokenId || '', this.apiTokenSecret || '');
302
-
303
- // var _this = this;
304
- // authNames.forEach(function(authName) {
305
- // var auth = _this.authentications[authName];
306
- // switch (auth.type) {
307
- // case 'basic':
308
- // if (auth.username || auth.password) {
309
- // request.auth(auth.username || '', auth.password || '');
310
- // }
311
- // break;
312
- // case 'apiKey':
313
- // if (auth.apiKey) {
314
- // var data = {};
315
- // if (auth.apiKeyPrefix) {
316
- // data[auth.name] = auth.apiKeyPrefix + ' ' + auth.apiKey;
317
- // } else {
318
- // data[auth.name] = auth.apiKey;
319
- // }
320
- // if (auth['in'] === 'header') {
321
- // request.set(data);
322
- // } else {
323
- // request.query(data);
324
- // }
325
- // }
326
- // break;
327
- // case 'oauth2':
328
- // if (auth.accessToken) {
329
- // request.set({'Authorization': 'Bearer ' + auth.accessToken});
330
- // }
331
- // break;
332
- // default:
333
- // throw new Error('Unknown authentication type: ' + auth.type);
334
- // }
335
- // });
336
- };
337
-
338
- /**
339
- * Deserializes an HTTP response body into a value of the specified type.
340
- * @param {Object} response A SuperAgent response object.
341
- * @param {(String|Array.<String>|Object.<String, Object>|Function)} returnType The type to return. Pass a string for simple types
342
- * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
343
- * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
344
- * all properties on <code>data<code> will be converted to this type.
345
- * @returns A value of the specified type.
346
- */
347
- exports.prototype.deserialize = function deserialize(response, returnType) {
348
- if (response == null || returnType == null || response.status == 204) {
349
- return null;
350
- }
351
- // Rely on SuperAgent for parsing response body.
352
- // See http://visionmedia.github.io/superagent/#parsing-response-bodies
353
- var data = response.body;
354
- if (data == null || (typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length)) {
355
- // SuperAgent does not always produce a body; use the unparsed response as a fallback
356
- data = response.text;
357
- }
358
- return exports.convertToType(data, returnType);
359
- };
360
-
361
- /**
362
- * Callback function to receive the result of the operation.
363
- * @callback module:ApiClient~callApiCallback
364
- * @param {String} error Error message, if any.
365
- * @param data The data returned by the service call.
366
- * @param {String} response The complete HTTP response.
367
- */
368
-
369
- /**
370
- * Invokes the REST service using the supplied settings and parameters.
371
- * @param {String} path The base URL to invoke.
372
- * @param {String} httpMethod The HTTP method to use.
373
- * @param {Object.<String, String>} pathParams A map of path parameters and their values.
374
- * @param {Object.<String, Object>} queryParams A map of query parameters and their values.
375
- * @param {Object.<String, Object>} collectionQueryParams A map of collection query parameters and their values.
376
- * @param {Object.<String, Object>} headerParams A map of header parameters and their values.
377
- * @param {Object.<String, Object>} formParams A map of form parameters and their values.
378
- * @param {Object} bodyParam The value to pass as the request body.
379
- * @param {Array.<String>} authNames An array of authentication type names.
380
- * @param {Array.<String>} contentTypes An array of request MIME types.
381
- * @param {Array.<String>} accepts An array of acceptable response MIME types.
382
- * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
383
- * constructor for a complex type.
384
- * @param {module:ApiClient~callApiCallback} callback The callback function.
385
- * @returns {Object} The SuperAgent request object.
386
- */
387
- exports.prototype.callApi = function callApi(path, httpMethod, pathParams,
388
- queryParams, collectionQueryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts,
389
- returnType, callback) {
390
-
391
- var _this = this;
392
- var url = this.buildUrl(path, pathParams);
393
- var request = superagent(httpMethod, url);
394
-
395
- // apply authentications
396
- this.applyAuthToRequest(request, authNames);
397
-
398
- // set collection query parameters
399
- for (var key in collectionQueryParams) {
400
- if (collectionQueryParams.hasOwnProperty(key)) {
401
- var param = collectionQueryParams[key];
402
- if (param.collectionFormat === 'csv') {
403
- // SuperAgent normally percent-encodes all reserved characters in a query parameter. However,
404
- // commas are used as delimiters for the 'csv' collectionFormat so they must not be encoded. We
405
- // must therefore construct and encode 'csv' collection query parameters manually.
406
- if (param.value != null) {
407
- var value = param.value.map(this.paramToString).map(encodeURIComponent).join(',');
408
- request.query(encodeURIComponent(key) + "=" + value);
409
- }
410
- } else {
411
- // All other collection query parameters should be treated as ordinary query parameters.
412
- queryParams[key] = this.buildCollectionParam(param.value, param.collectionFormat);
413
- }
414
- }
415
- }
416
-
417
- // set query parameters
418
- if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
419
- queryParams['_'] = new Date().getTime();
420
- }
421
- request.query(this.normalizeParams(queryParams));
422
-
423
- // set header parameters
424
- request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
425
-
426
-
427
- // set requestAgent if it is set by user
428
- if (this.requestAgent) {
429
- request.agent(this.requestAgent);
430
- }
431
-
432
- // set request timeout
433
- request.timeout(this.timeout);
434
-
435
- var contentType = this.jsonPreferredMime(contentTypes);
436
- if (contentType) {
437
- // Issue with superagent and multipart/form-data (https://github.com/visionmedia/superagent/issues/746)
438
- if(contentType != 'multipart/form-data') {
439
- request.type(contentType);
440
- }
441
- } else if (!request.header['Content-Type']) {
442
- request.type('application/json');
443
- }
444
-
445
- if (contentType === 'application/x-www-form-urlencoded') {
446
- request.send(querystring.stringify(this.normalizeParams(formParams)));
447
- } else if (contentType == 'multipart/form-data') {
448
- var _formParams = this.normalizeParams(formParams);
449
- for (var key in _formParams) {
450
- if (_formParams.hasOwnProperty(key)) {
451
- if (this.isFileParam(_formParams[key])) {
452
- // file field
453
- request.attach(key, _formParams[key]);
454
- } else {
455
- request.field(key, _formParams[key]);
456
- }
457
- }
458
- }
459
- } else if (bodyParam) {
460
- request.send(bodyParam);
461
- }
462
-
463
- var accept = this.jsonPreferredMime(accepts);
464
- if (accept) {
465
- request.accept(accept);
466
- }
467
-
468
- if (returnType === 'Blob') {
469
- request.responseType('blob');
470
- } else if (returnType === 'String') {
471
- request.responseType('string');
472
- }
473
-
474
- // Attach previously saved cookies, if enabled
475
- if (this.enableCookies){
476
- if (typeof window === 'undefined') {
477
- this.agent._attachCookies(request);
478
- }
479
- else {
480
- request.withCredentials();
481
- }
482
- }
483
-
484
-
485
- request.end(function(error, response) {
486
- if (callback) {
487
- var data = null;
488
- if (!error) {
489
- try {
490
- data = _this.deserialize(response, returnType);
491
- if (_this.enableCookies && typeof window === 'undefined'){
492
- _this.agent._saveCookies(response);
493
- }
494
- } catch (err) {
495
- error = err;
496
- }
497
- }
498
- callback(error, data, response);
499
- }
500
- });
501
-
502
- return request;
503
- };
504
-
505
- /**
506
- * Parses an ISO-8601 string representation of a date value.
507
- * @param {String} str The date value as a string.
508
- * @returns {Date} The parsed date object.
509
- */
510
- exports.parseDate = function(str) {
511
- return new Date(str.replace(/T/i, ' '));
512
- };
513
-
514
- /**
515
- * Converts a value to the specified type.
516
- * @param {(String|Object)} data The data to convert, as a string or object.
517
- * @param {(String|Array.<String>|Object.<String, Object>|Function)} type The type to return. Pass a string for simple types
518
- * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
519
- * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
520
- * all properties on <code>data<code> will be converted to this type.
521
- * @returns An instance of the specified type or null or undefined if data is null or undefined.
522
- */
523
- exports.convertToType = function(data, type) {
524
- if (data === null || data === undefined)
525
- return data
526
-
527
- switch (type) {
528
- case 'Boolean':
529
- return Boolean(data);
530
- case 'Integer':
531
- return parseInt(data, 10);
532
- case 'Number':
533
- return parseFloat(data);
534
- case 'String':
535
- return String(data);
536
- case 'Date':
537
- return this.parseDate(String(data));
538
- case 'Blob':
539
- return data;
540
- default:
541
- if (type === Object) {
542
- // generic object, return directly
543
- return data;
544
- } else if (typeof type === 'function') {
545
- // for model type like: User
546
- return type.constructFromObject(data);
547
- } else if (Array.isArray(type)) {
548
- // for array type like: ['String']
549
- var itemType = type[0];
550
- return data.map(function(item) {
551
- return exports.convertToType(item, itemType);
552
- });
553
- } else if (typeof type === 'object') {
554
- // for plain object type like: {'String': 'Integer'}
555
- var keyType, valueType;
556
- for (var k in type) {
557
- if (type.hasOwnProperty(k)) {
558
- keyType = k;
559
- valueType = type[k];
560
- break;
561
- }
562
- }
563
- var result = {};
564
- for (var k in data) {
565
- if (data.hasOwnProperty(k)) {
566
- var key = exports.convertToType(k, keyType);
567
- var value = exports.convertToType(data[k], valueType);
568
- result[key] = value;
569
- }
570
- }
571
- return result;
572
- } else {
573
- // for unknown type, return the data directly
574
- return data;
575
- }
576
- }
577
- };
578
-
579
- /**
580
- * Constructs a new map or array model from REST data.
581
- * @param data {Object|Array} The REST data.
582
- * @param obj {Object|Array} The target object or array.
583
- */
584
- exports.constructFromObject = function(data, obj, itemType) {
585
- if (Array.isArray(data)) {
586
- for (var i = 0; i < data.length; i++) {
587
- if (data.hasOwnProperty(i))
588
- obj[i] = exports.convertToType(data[i], itemType);
589
- }
590
- } else {
591
- for (var k in data) {
592
- if (data.hasOwnProperty(k))
593
- obj[k] = exports.convertToType(data[k], itemType);
594
- }
595
- }
596
- };
597
-
598
- /**
599
- * The default API client implementation.
600
- * @type {module:ApiClient}
601
- */
602
- exports.instance = new exports();
603
-
604
- return exports;
605
- }));