docspring 3.2.0 → 4.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 (157) hide show
  1. package/AGENTS.md +79 -19
  2. package/README.md +65 -63
  3. package/dist/ApiClient.js +62 -27
  4. package/dist/RequestSchemas.js +2297 -0
  5. package/dist/RequestValidator.js +494 -0
  6. package/dist/api/Client.js +1345 -946
  7. package/dist/index.js +655 -151
  8. package/dist/model/AiFieldNamingLanguage.js +64 -0
  9. package/dist/model/{AddFieldsData.js → AuthenticationCheck.js} +31 -31
  10. package/dist/model/BarcodeSymbology.js +89 -0
  11. package/dist/model/CheckCharacter.js +74 -0
  12. package/dist/model/CombinedFieldType.js +59 -0
  13. package/dist/model/CombinedPdf.js +294 -0
  14. package/dist/model/{MoveFolderData.js → CombinedPdfFiles.js} +26 -26
  15. package/dist/model/CombinedPdfList.js +132 -0
  16. package/dist/model/{SubmissionDataRequestToken.js → CombinedPdfSource.js} +55 -52
  17. package/dist/model/CombinedPdfSourceInput.js +270 -0
  18. package/dist/model/{SuccessErrorResponse.js → CombinedPdfSourcePdf.js} +41 -55
  19. package/dist/model/CombinedPdfSourceType.js +74 -0
  20. package/dist/model/CombinedPdfState.js +74 -0
  21. package/dist/model/{CopyTemplateOptions.js → CopyTemplateRequest.js} +25 -21
  22. package/dist/model/{CombinePdfsData.js → CreateCombinedPdfRequest.js} +68 -52
  23. package/dist/model/{CreateCustomFileData.js → CreateCustomFileFromUploadRequest.js} +24 -22
  24. package/dist/model/{CreateFolderData.js → CreateFolderRequest.js} +46 -27
  25. package/dist/model/{CreateSubmissionDataRequestEventRequest.js → CreateSignatureRequestEventRequest.js} +41 -137
  26. package/dist/model/CreateSignatureRequestTokenRequest.js +88 -0
  27. package/dist/model/{CreatePdfSubmissionData.js → CreateSubmissionBatchRequest.js} +63 -87
  28. package/dist/model/CreateSubmissionRequest.js +212 -0
  29. package/dist/model/CreateTemplateRequest.js +545 -0
  30. package/dist/model/CreateWebhookRequest.js +234 -0
  31. package/dist/model/CustomFile.js +66 -15
  32. package/dist/model/CustomFileList.js +132 -0
  33. package/dist/model/CustomFileSourcePdf.js +130 -0
  34. package/dist/model/ErrorCode.js +154 -0
  35. package/dist/model/{BatchGeneratePdfs201Response.js → ErrorDetail.js} +65 -76
  36. package/dist/model/ErrorInfo.js +211 -0
  37. package/dist/model/ErrorResponse.js +11 -40
  38. package/dist/model/ExpirationInterval.js +64 -0
  39. package/dist/model/{CreateSubmissionResponse.js → FieldComparisonCondition.js} +46 -64
  40. package/dist/model/FieldComparisonOperator.js +69 -0
  41. package/dist/model/FieldDisplayType.js +79 -0
  42. package/dist/model/FieldEqualsCondition.js +137 -0
  43. package/dist/model/FieldEqualsOperator.js +59 -0
  44. package/dist/model/FieldInCondition.js +145 -0
  45. package/dist/model/FieldOverride.js +722 -0
  46. package/dist/model/{MultipleErrorsResponse.js → FieldPresenceCondition.js} +39 -54
  47. package/dist/model/FieldPresenceOperator.js +59 -0
  48. package/dist/model/FieldRangeCondition.js +148 -0
  49. package/dist/model/FieldReimportState.js +69 -0
  50. package/dist/model/FieldSetupLogic.js +59 -0
  51. package/dist/model/FieldSetupNaming.js +59 -0
  52. package/dist/model/FieldSetupSource.js +64 -0
  53. package/dist/model/Folder.js +37 -10
  54. package/dist/model/FolderList.js +132 -0
  55. package/dist/model/GeneratedFile.js +214 -0
  56. package/dist/model/GeneratedFileState.js +64 -0
  57. package/dist/model/HtmlEngineOptions.js +230 -0
  58. package/dist/model/HtmlEngineOptionsInput.js +193 -0
  59. package/dist/model/ImageGravity.js +94 -0
  60. package/dist/model/ImageScaleType.js +64 -0
  61. package/dist/model/ModelCodeLanguage.js +94 -0
  62. package/dist/model/{UpdatePdfTemplate.js → MoveFolderRequest.js} +33 -27
  63. package/dist/model/{MoveTemplateData.js → MoveTemplateRequest.js} +24 -34
  64. package/dist/model/NumberConditionType.js +79 -0
  65. package/dist/model/PageFormat.js +114 -0
  66. package/dist/model/{PublishVersionData.js → PublishTemplateVersionRequest.js} +32 -32
  67. package/dist/model/{RenameFolderData.js → RenameFolderRequest.js} +24 -22
  68. package/dist/model/{RestoreVersionData.js → RestoreTemplateVersionRequest.js} +24 -22
  69. package/dist/model/ShapeType.js +79 -0
  70. package/dist/model/{SubmissionDataRequestShow.js → SignatureRequest.js} +164 -239
  71. package/dist/model/SignatureRequestAuthSecondFactorType.js +79 -0
  72. package/dist/model/SignatureRequestAuthType.js +84 -0
  73. package/dist/model/{SubmissionDataRequestEvent.js → SignatureRequestEvent.js} +66 -148
  74. package/dist/model/SignatureRequestEventType.js +79 -0
  75. package/dist/model/SignatureRequestInput.js +278 -0
  76. package/dist/model/SignatureRequestMessageType.js +94 -0
  77. package/dist/model/SignatureRequestState.js +64 -0
  78. package/dist/model/SignatureRequestToken.js +195 -0
  79. package/dist/model/SignatureRequestTokenType.js +59 -0
  80. package/dist/model/StringConditionType.js +74 -0
  81. package/dist/model/Submission.js +185 -339
  82. package/dist/model/SubmissionAction.js +29 -114
  83. package/dist/model/SubmissionActionState.js +69 -0
  84. package/dist/model/SubmissionActionType.js +84 -0
  85. package/dist/model/SubmissionBatch.js +73 -54
  86. package/dist/model/SubmissionBatchState.js +64 -0
  87. package/dist/model/SubmissionFiles.js +108 -0
  88. package/dist/model/SubmissionInput.js +204 -0
  89. package/dist/model/{ListSubmissionsResponse.js → SubmissionList.js} +34 -41
  90. package/dist/model/SubmissionSource.js +69 -0
  91. package/dist/model/SubmissionSourcePdf.js +130 -0
  92. package/dist/model/SubmissionState.js +114 -0
  93. package/dist/model/Template.js +309 -572
  94. package/dist/model/TemplateActor.js +171 -0
  95. package/dist/model/TemplateActorType.js +64 -0
  96. package/dist/model/TemplateDefaults.js +307 -0
  97. package/dist/model/TemplateDefaultsInput.js +305 -0
  98. package/dist/model/TemplateDocument.js +280 -0
  99. package/dist/model/TemplateDocumentState.js +74 -0
  100. package/dist/model/TemplateFieldDependency.js +184 -0
  101. package/dist/model/TemplateFieldDependencyAction.js +64 -0
  102. package/dist/model/{CreateCombinedSubmissionResponse.js → TemplateFieldDependencyCondition.js} +50 -61
  103. package/dist/model/TemplateFieldDependencyConditionInput.js +304 -0
  104. package/dist/model/TemplateFieldDependencyInput.js +182 -0
  105. package/dist/model/TemplateFieldDependencyMatch.js +59 -0
  106. package/dist/model/TemplateFieldDependencyOperator.js +99 -0
  107. package/dist/model/TemplateFieldLogicStatus.js +74 -0
  108. package/dist/model/TemplateFormMode.js +64 -0
  109. package/dist/model/{TemplateModelCodeResponse.js → TemplateModelCode.js} +33 -85
  110. package/dist/model/TemplatePageAiError.js +69 -0
  111. package/dist/model/TemplatePageAiNamingStatus.js +59 -0
  112. package/dist/model/TemplatePageFieldsStatus.js +74 -0
  113. package/dist/model/TemplatePageImageStatus.js +59 -0
  114. package/dist/model/TemplatePageProcessingStatus.js +162 -0
  115. package/dist/model/{SubmissionBatchData.js → TemplateSourcePdf.js} +49 -49
  116. package/dist/model/TemplateSummary.js +560 -0
  117. package/dist/model/{SuccessMultipleErrorsResponse.js → TemplateSummaryList.js} +43 -55
  118. package/dist/model/TemplateType.js +59 -0
  119. package/dist/model/{Submission422Response.js → TemplateVersion.js} +59 -62
  120. package/dist/model/TemplateVersionType.js +64 -0
  121. package/dist/model/TextAlignment.js +69 -0
  122. package/dist/model/TextOverflow.js +59 -0
  123. package/dist/model/TextVerticalAlignment.js +64 -0
  124. package/dist/model/Typeface.js +134 -0
  125. package/dist/model/UpdateSignatureRequestRequest.js +183 -0
  126. package/dist/model/{ErrorOrMultipleErrorsResponse.js → UpdateTemplateDocumentRequest.js} +43 -60
  127. package/dist/model/UpdateTemplateRequest.js +450 -0
  128. package/dist/model/UpdateWebhookRequest.js +209 -0
  129. package/dist/model/UploadMethod.js +54 -0
  130. package/dist/model/{UploadPresignResponse.js → UploadPresign.js} +52 -57
  131. package/dist/model/UrlSourcePdf.js +130 -0
  132. package/dist/model/Webhook.js +57 -72
  133. package/dist/model/WebhookEventType.js +174 -0
  134. package/dist/model/WebhookList.js +132 -0
  135. package/dist/model/WebhookMode.js +59 -0
  136. package/package.json +1 -1
  137. package/dist/model/CombinedSubmission.js +0 -308
  138. package/dist/model/CombinedSubmissionAction.js +0 -268
  139. package/dist/model/CreateCustomFileResponse.js +0 -155
  140. package/dist/model/CreateHtmlTemplate.js +0 -108
  141. package/dist/model/CreatePdfTemplate.js +0 -108
  142. package/dist/model/CreateSubmissionDataRequestData.js +0 -314
  143. package/dist/model/CreateSubmissionDataRequestEventResponse.js +0 -155
  144. package/dist/model/CreateSubmissionDataRequestResponse.js +0 -155
  145. package/dist/model/CreateSubmissionDataRequestTokenResponse.js +0 -155
  146. package/dist/model/CreateWebhookData.js +0 -108
  147. package/dist/model/JsonSchema.js +0 -205
  148. package/dist/model/SubmissionBatchWithSubmissions.js +0 -228
  149. package/dist/model/SubmissionDataRequest.js +0 -496
  150. package/dist/model/SubmissionPreview.js +0 -504
  151. package/dist/model/TemplateAddFieldsResponse.js +0 -156
  152. package/dist/model/TemplateDeleteResponse.js +0 -168
  153. package/dist/model/TemplatePreview.js +0 -796
  154. package/dist/model/TemplatePublishVersionResponse.js +0 -154
  155. package/dist/model/UpdateHtmlTemplate.js +0 -108
  156. package/dist/model/UpdateSubmissionDataRequestData.js +0 -311
  157. package/dist/model/UpdateWebhookData.js +0 -108
@@ -0,0 +1,494 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ValidationError = void 0;
7
+ exports.errors = errors;
8
+ exports.requestError = requestError;
9
+ exports.validate = validate;
10
+ var _RequestSchemas = _interopRequireDefault(require("./RequestSchemas"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
13
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
14
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
17
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
18
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
19
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
20
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
21
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
22
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
23
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
24
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
25
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
26
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
27
+ function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
28
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
29
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
30
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
31
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
32
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
33
+ function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
34
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
35
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
36
+ function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
37
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
38
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } /**
39
+ * Checks a request against API v2's request schemas (RequestSchemas.js, the schemas the API validates requests with)
40
+ * before it's sent, and says what the API would say about it. api_clients/validator_conformance checks that it agrees
41
+ * with the API.
42
+ */
43
+ /**
44
+ * Rejects a request before it's sent when the API would reject it with a 422. `details` are the API's error details:
45
+ * objects with `code`, `message` and a `pointer` into the body (or a `parameter` for a query parameter).
46
+ */
47
+ var ValidationError = exports.ValidationError = /*#__PURE__*/function (_Error) {
48
+ function ValidationError(details) {
49
+ var _this;
50
+ _classCallCheck(this, ValidationError);
51
+ var shown = details.slice(0, 3).map(function (detail) {
52
+ var subject = detail.pointer === '' ? 'the request body' : detail.pointer || detail.parameter;
53
+ return "".concat(subject, " ").concat(detail.message);
54
+ });
55
+ var message = "Invalid request: ".concat(shown.join('; '));
56
+ if (details.length > 3) message += " (and ".concat(details.length - 3, " more)");
57
+ _this = _callSuper(this, ValidationError, [message]);
58
+ _this.name = 'ValidationError';
59
+ _this.details = details;
60
+ return _this;
61
+ }
62
+ _inherits(ValidationError, _Error);
63
+ return _createClass(ValidationError);
64
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
65
+ var TYPE_NAMES = {
66
+ string: 'a string',
67
+ integer: 'an integer',
68
+ number: 'a number',
69
+ "boolean": 'true or false',
70
+ object: 'an object',
71
+ array: 'an array',
72
+ "null": 'null'
73
+ };
74
+ // What a multipart body's file field holds when the API checks it
75
+ var FILE_PLACEHOLDER = '(file)';
76
+ // A date and time as the API reads it (Ruby's DateTime.rfc3339, then json_schemer's checks)
77
+ var DATE_TIME = /^[ \t\n\v\f\r]*(-?\d{4})-(\d{2})-(\d{2})[Tt \t\n\v\f\r](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|([+-])(\d{2}):(\d{2}))$/;
78
+ // An absolute URI as the API reads it (RFC 3986, as Ruby's URI parser has it), a little looser for IP addresses
79
+ // Lookaheads check the escapes, so only character classes repeat: Java and PHP recurse on each repetition of a group
80
+ var SEGMENT = '[%!$&-.0-9:;=@A-Z_a-z~/]';
81
+ var URI = new RegExp('^(?![^?#]*%(?![0-9A-Fa-f]{2}))[A-Za-z][+\\-.0-9A-Za-z]*:' + '(?://(?:[%!$&-.0-9:;=A-Z_a-z~]*@)?' + '(?:\\[(?:[0-9A-Fa-f:.]+|[vV][0-9A-Fa-f]+\\.[!$&-.0-9:;=A-Z_a-z~]+)\\]|[%!$&-.0-9;=A-Z_a-z~]*)' + "(?::[0-9]*)?(?:/".concat(SEGMENT, "*)?") + "|/(?:(?!/)".concat(SEGMENT, "+)?") + "|(?!/)".concat(SEGMENT, "+") + '|)' + '(?:\\?[^#]*)?' + '(?:#(?![^#]*%(?![0-9A-Fa-f]{2}))[%!$&-.0-9:;=@A-Z_a-z~/?]*)?$');
82
+ var WHITESPACE = /[ \t\n\v\f\r]/;
83
+ var patterns = {};
84
+
85
+ /**
86
+ * The ValidationError for a request the API would reject, or null. `path` is the operation's path template
87
+ * (/templates/{template_id}); `body` is the JSON the SDK sends, or a multipart body's params (files as file objects).
88
+ */
89
+ function requestError(method, path, query, body, isFile) {
90
+ var operationId = _RequestSchemas["default"].routes["".concat(method.toUpperCase(), " ").concat(path)];
91
+ if (!operationId) return null;
92
+ var entry = _RequestSchemas["default"].operations[operationId];
93
+ var requestBody = body;
94
+ if (entry.body && entry.body.mediaType === 'multipart/form-data' && body) {
95
+ requestBody = {};
96
+ Object.keys(body).forEach(function (key) {
97
+ if (body[key] !== undefined) requestBody[key] = isFile(body[key]) ? FILE_PLACEHOLDER : body[key];
98
+ });
99
+ } else if (body !== null && body !== undefined) {
100
+ // The JSON the request sends
101
+ requestBody = JSON.parse(JSON.stringify(body));
102
+ }
103
+ var details = errors(operationId, query || {}, requestBody);
104
+ return details.length ? new ValidationError(details) : null;
105
+ }
106
+
107
+ /** The details for a request to an operation (createSubmission) */
108
+ function errors(operationId, query, body) {
109
+ var entry = _RequestSchemas["default"].operations[operationId];
110
+ var details = [];
111
+ var queryValues = {};
112
+ Object.keys(query || {}).forEach(function (key) {
113
+ if (query[key] !== undefined && query[key] !== null) queryValues[key] = query[key];
114
+ });
115
+ if (entry.query && Object.keys(queryValues).length) {
116
+ var params = entry.query;
117
+ var properties = {};
118
+ var required = [];
119
+ Object.keys(params).forEach(function (name) {
120
+ properties[name] = params[name].schema;
121
+ if (params[name].required) required.push(name);
122
+ });
123
+ var schema = {
124
+ type: 'object',
125
+ properties: properties,
126
+ required: required,
127
+ additionalProperties: false
128
+ };
129
+ details.push.apply(details, _toConsumableArray(validateParams(schema, queryValues, 'query')));
130
+ }
131
+ if (entry.body && body !== null && body !== undefined) {
132
+ if (entry.body.mediaType === 'multipart/form-data') {
133
+ details.push.apply(details, _toConsumableArray(validateParams(entry.body.schema, body, 'body')));
134
+ } else {
135
+ details.push.apply(details, _toConsumableArray(validate(entry.body.schema, typeof body === 'string' ? JSON.parse(body) : body, 'body')));
136
+ }
137
+ }
138
+ return details;
139
+ }
140
+
141
+ /** The details for `data` checked against `schema` at `location` (body or query) */
142
+ function validate(schema, data, location) {
143
+ var details = [];
144
+ check(schema, data, '', location, details);
145
+ return details;
146
+ }
147
+
148
+ // Query and multipart params arrive as strings, which the API converts where the schema types them
149
+ function validateParams(schema, data, location) {
150
+ var properties = schema.properties || {};
151
+ var converted = {};
152
+ Object.keys(data).forEach(function (key) {
153
+ converted[key] = convertParam(data[key], properties[key]);
154
+ });
155
+ return validate(schema, converted, location);
156
+ }
157
+ function convertParam(value, schema) {
158
+ if (!isObject(schema)) return value;
159
+ var types = typesOf(schema);
160
+ if (Array.isArray(value) && types.includes('array')) return value.map(function (item) {
161
+ return convertParam(item, schema.items);
162
+ });
163
+ if (value instanceof Date) return value.toISOString();
164
+ if (typeof value !== 'string') return value;
165
+ if (types.includes('integer') && /^-?[0-9]+$/.test(value)) return parseInt(value, 10);
166
+ if (types.includes('number') && /^-?[0-9]+(?:\.[0-9]+)?$/.test(value)) return Number(value);
167
+ if (types.includes('boolean') && (value === 'true' || value === 'false')) return value === 'true';
168
+ return value;
169
+ }
170
+ function typesOf(schema) {
171
+ if (schema.type === undefined) return [];
172
+ return Array.isArray(schema.type) ? schema.type : [schema.type];
173
+ }
174
+ function isObject(value) {
175
+ return value !== null && _typeof(value) === 'object' && !Array.isArray(value);
176
+ }
177
+ function resolve(schema) {
178
+ var resolved = schema;
179
+ while (isObject(resolved) && resolved.$ref) {
180
+ resolved = _RequestSchemas["default"].components.schemas[resolved.$ref.replace('#/components/schemas/', '')];
181
+ }
182
+ return resolved;
183
+ }
184
+ function check(rawSchema, data, pointer, location, details) {
185
+ var schema = resolve(rawSchema);
186
+ if (!isObject(schema)) return;
187
+ if (schema.discriminator) {
188
+ checkUnion(schema, data, pointer, location, details);
189
+ return;
190
+ }
191
+ if (schema.type !== undefined && !typesOf(schema).some(function (type) {
192
+ return isType(data, type);
193
+ })) {
194
+ var message = pointer === '' && location === 'body' ? 'must be a JSON object' : typeMessage(typesOf(schema));
195
+ details.push(detail(location, pointer, 'type', message));
196
+ }
197
+ if (schema["enum"] && !schema["enum"].some(function (value) {
198
+ return jsonEqual(value, data);
199
+ })) {
200
+ details.push(detail(location, pointer, 'enum', "must be one of: ".concat(schema["enum"].map(toJson).join(', '))));
201
+ }
202
+ if ('const' in schema && !jsonEqual(schema["const"], data)) {
203
+ details.push(detail(location, pointer, 'const', "must be ".concat(toJson(schema["const"]))));
204
+ }
205
+ if (typeof data === 'string') checkString(schema, data, pointer, location, details);else if (typeof data === 'number') checkNumber(schema, data, pointer, location, details);else if (Array.isArray(data)) checkArray(schema, data, pointer, location, details);else if (isObject(data)) checkObject(schema, data, pointer, location, details);
206
+ }
207
+
208
+ // A union (oneOf with a discriminator): the discriminator property's value picks the variant, and only that one is
209
+ // checked, as the API does
210
+ function checkUnion(schema, data, pointer, location, details) {
211
+ if (!isObject(data)) {
212
+ details.push(detail(location, pointer, 'type', "must be ".concat(TYPE_NAMES.object)));
213
+ return;
214
+ }
215
+ var name = schema.discriminator.propertyName;
216
+ var child = "".concat(pointer, "/").concat(escape(name));
217
+ if (!Object.prototype.hasOwnProperty.call(data, name)) {
218
+ details.push(detail(location, child, 'required', 'is required'));
219
+ return;
220
+ }
221
+
222
+ // [value, $ref] pairs, in the order the API lists them
223
+ var mapping = schema.discriminator.mapping;
224
+ var value = data[name];
225
+ var variant = typeof value === 'string' ? mapping.find(function (_ref) {
226
+ var _ref2 = _slicedToArray(_ref, 1),
227
+ candidate = _ref2[0];
228
+ return candidate === value;
229
+ }) : undefined;
230
+ if (variant) {
231
+ check({
232
+ $ref: variant[1]
233
+ }, data, pointer, location, details);
234
+ return;
235
+ }
236
+ details.push(detail(location, child, 'enum', "must be one of: ".concat(mapping.map(function (_ref3) {
237
+ var _ref4 = _slicedToArray(_ref3, 1),
238
+ candidate = _ref4[0];
239
+ return toJson(candidate);
240
+ }).join(', '))));
241
+ }
242
+ function checkString(schema, data, pointer, location, details) {
243
+ var length = Array.from(data).length;
244
+ if (schema.minLength !== undefined && length < schema.minLength) {
245
+ var message = atLeast(schema.minLength, "must be at least ".concat(count(schema.minLength, 'character')));
246
+ details.push(detail(location, pointer, 'minLength', message));
247
+ }
248
+ if (schema.maxLength !== undefined && length > schema.maxLength) {
249
+ details.push(detail(location, pointer, 'maxLength', "must be at most ".concat(count(schema.maxLength, 'character'))));
250
+ }
251
+ if (schema.pattern !== undefined && !pattern(schema.pattern).test(data)) {
252
+ var _message = schema['x-pattern-message'] || "must match the pattern ".concat(schema.pattern);
253
+ details.push(detail(location, pointer, 'pattern', _message));
254
+ }
255
+ if (schema.format !== undefined && !format(schema.format, data)) {
256
+ var _message2 = _RequestSchemas["default"].formatMessages[schema.format] || "must be a valid ".concat(schema.format);
257
+ details.push(detail(location, pointer, 'format', _message2));
258
+ }
259
+ }
260
+ function checkNumber(schema, data, pointer, location, details) {
261
+ if (schema.minimum !== undefined && data < schema.minimum) {
262
+ details.push(detail(location, pointer, 'minimum', "must be at least ".concat(schema.minimum)));
263
+ }
264
+ if (schema.maximum !== undefined && data > schema.maximum) {
265
+ details.push(detail(location, pointer, 'maximum', "must be at most ".concat(schema.maximum)));
266
+ }
267
+ if (schema.exclusiveMinimum !== undefined && data <= schema.exclusiveMinimum) {
268
+ details.push(detail(location, pointer, 'exclusiveMinimum', "must be greater than ".concat(schema.exclusiveMinimum)));
269
+ }
270
+ if (schema.exclusiveMaximum !== undefined && data >= schema.exclusiveMaximum) {
271
+ details.push(detail(location, pointer, 'exclusiveMaximum', "must be less than ".concat(schema.exclusiveMaximum)));
272
+ }
273
+ }
274
+ function checkArray(schema, data, pointer, location, details) {
275
+ if (schema.minItems !== undefined && data.length < schema.minItems) {
276
+ var message = atLeast(schema.minItems, "must have at least ".concat(count(schema.minItems, 'item')));
277
+ details.push(detail(location, pointer, 'minItems', message));
278
+ }
279
+ if (schema.maxItems !== undefined && data.length > schema.maxItems) {
280
+ details.push(detail(location, pointer, 'maxItems', "must have at most ".concat(count(schema.maxItems, 'item'))));
281
+ }
282
+ if (schema.uniqueItems && !unique(data)) {
283
+ var duplicate = firstDuplicate(data);
284
+ var _message3 = duplicate ? "has ".concat(toJson(duplicate.value), " more than once") : "can't contain the same item twice";
285
+ details.push(detail(location, pointer, 'uniqueItems', _message3));
286
+ }
287
+ if (schema.items !== undefined) {
288
+ data.forEach(function (item, index) {
289
+ return check(schema.items, item, "".concat(pointer, "/").concat(index), location, details);
290
+ });
291
+ }
292
+ }
293
+ function checkObject(schema, data, pointer, location, details) {
294
+ (schema.required || []).forEach(function (name) {
295
+ if (!Object.prototype.hasOwnProperty.call(data, name)) {
296
+ details.push(detail(location, "".concat(pointer, "/").concat(escape(name)), 'required', 'is required'));
297
+ }
298
+ });
299
+ var properties = schema.properties || {};
300
+ Object.keys(data).forEach(function (name) {
301
+ var child = "".concat(pointer, "/").concat(escape(name));
302
+ if (Object.prototype.hasOwnProperty.call(properties, name)) {
303
+ check(properties[name], data[name], child, location, details);
304
+ } else if (schema.additionalProperties === false) {
305
+ details.push(unknownProperty(schema, name, child, location));
306
+ } else if (isObject(schema.additionalProperties)) {
307
+ check(schema.additionalProperties, data[name], child, location, details);
308
+ }
309
+ });
310
+ }
311
+ function unknownProperty(schema, name, pointer, location) {
312
+ var notAllowed = (schema['x-not-allowed-properties'] || {})[name];
313
+ if (notAllowed) return detail(location, pointer, 'not_allowed', notAllowed);
314
+ var noun = location === 'query' ? 'query parameter' : 'property';
315
+ var custom = schema['x-unknown-property-message'];
316
+ var message = custom || "isn't a documented ".concat(noun);
317
+ var snake = underscore(name);
318
+ if (snake !== name && Object.prototype.hasOwnProperty.call(schema.properties || {}, snake)) {
319
+ var plural = custom ? 'settings' : noun === 'property' ? 'properties' : 'query parameters';
320
+ message += ". API v2 names ".concat(plural, " in snake_case: '").concat(snake, "'");
321
+ }
322
+ return detail(location, pointer, 'unknown_property', message);
323
+ }
324
+ function detail(location, pointer, code, message) {
325
+ if (location !== 'query') return {
326
+ code: code,
327
+ message: message,
328
+ pointer: pointer
329
+ };
330
+ var parameter = pointer.slice(1).split('/')[0].replace(/~1/g, '/').replace(/~0/g, '~');
331
+ return {
332
+ code: code,
333
+ message: message,
334
+ parameter: parameter
335
+ };
336
+ }
337
+ function isType(data, type) {
338
+ switch (type) {
339
+ case 'string':
340
+ return typeof data === 'string';
341
+ case 'integer':
342
+ return typeof data === 'number' && Number.isInteger(data);
343
+ case 'number':
344
+ return typeof data === 'number' && Number.isFinite(data);
345
+ case 'boolean':
346
+ return typeof data === 'boolean';
347
+ case 'object':
348
+ return isObject(data);
349
+ case 'array':
350
+ return Array.isArray(data);
351
+ case 'null':
352
+ return data === null;
353
+ default:
354
+ return false;
355
+ }
356
+ }
357
+
358
+ // Patterns are ECMA-262 regexps, as OpenAPI says: ^ and $ are the start and end of the value, not of a line. The
359
+ // API's patterns only use ^ as the first character and $ as the last (api_clients/scripts/extract_request_schemas).
360
+ // JavaScript reads them that way. The u flag counts characters as the API does (an emoji is one), but rejects some
361
+ // escapes that are fine without it (\-).
362
+ function pattern(source) {
363
+ if (!patterns[source]) {
364
+ try {
365
+ patterns[source] = new RegExp(source, 'u');
366
+ } catch (error) {
367
+ patterns[source] = new RegExp(source);
368
+ }
369
+ }
370
+ return patterns[source];
371
+ }
372
+ function format(name, data) {
373
+ if (name === 'uri') return /^[\x00-\x7f]*$/.test(data) && !WHITESPACE.test(data) && URI.test(data);
374
+ if (name === 'date-time') return dateTime(data);
375
+ return true;
376
+ }
377
+ function dateTime(data) {
378
+ var match = DATE_TIME.exec(data);
379
+ if (!match) return false;
380
+ var _match$slice$map = match.slice(1, 7).map(function (value) {
381
+ return parseInt(value, 10);
382
+ }),
383
+ _match$slice$map2 = _slicedToArray(_match$slice$map, 6),
384
+ year = _match$slice$map2[0],
385
+ month = _match$slice$map2[1],
386
+ day = _match$slice$map2[2],
387
+ hour = _match$slice$map2[3],
388
+ minute = _match$slice$map2[4],
389
+ second = _match$slice$map2[5];
390
+ if (month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month)) return false;
391
+ if (hour > 23 || minute > 59 || second > 60) return false;
392
+ var offset = 0;
393
+ if (match[7]) {
394
+ var offsetHours = parseInt(match[8], 10);
395
+ var offsetMinutes = parseInt(match[9], 10);
396
+ if (offsetHours > 23 || offsetMinutes > 59) return false;
397
+ offset = (match[7] === '-' ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
398
+ }
399
+ // A leap second is only at the end of a UTC day
400
+ return second < 60 || ((hour * 60 + minute - offset) % 1440 + 1440) % 1440 === 1439;
401
+ }
402
+
403
+ // Before the Gregorian calendar (1582), the API's dates are Julian: every fourth year is a leap year
404
+ function daysInMonth(year, month) {
405
+ var leap = year % 4 === 0 && (year < 1583 || year % 100 !== 0 || year % 400 === 0);
406
+ if (month === 2 && leap) return 29;
407
+ return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
408
+ }
409
+ function unique(data) {
410
+ return !data.some(function (item, index) {
411
+ return data.slice(index + 1).some(function (other) {
412
+ return jsonEqual(item, other);
413
+ });
414
+ });
415
+ }
416
+
417
+ // The first value that's in the list twice, as the API names it
418
+ function firstDuplicate(data) {
419
+ var counts = new Map();
420
+ var firsts = new Map();
421
+ data.forEach(function (item) {
422
+ var key = tallyKey(item);
423
+ counts.set(key, (counts.get(key) || 0) + 1);
424
+ if (!firsts.has(key)) firsts.set(key, item);
425
+ });
426
+ var _iterator = _createForOfIteratorHelper(counts),
427
+ _step;
428
+ try {
429
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
430
+ var _step$value = _slicedToArray(_step.value, 2),
431
+ key = _step$value[0],
432
+ times = _step$value[1];
433
+ if (times > 1) return {
434
+ value: firsts.get(key)
435
+ };
436
+ }
437
+ } catch (err) {
438
+ _iterator.e(err);
439
+ } finally {
440
+ _iterator.f();
441
+ }
442
+ return null;
443
+ }
444
+ function tallyKey(value) {
445
+ if (Array.isArray(value)) return "[".concat(value.map(tallyKey).join(','), "]");
446
+ if (isObject(value)) {
447
+ return "{".concat(Object.keys(value).sort().map(function (key) {
448
+ return "".concat(JSON.stringify(key), ":").concat(tallyKey(value[key]));
449
+ }).join(','), "}");
450
+ }
451
+ return JSON.stringify(value);
452
+ }
453
+
454
+ // JSON equality: numbers by value, objects regardless of key order
455
+ function jsonEqual(left, right) {
456
+ if (Array.isArray(left) && Array.isArray(right)) {
457
+ return left.length === right.length && left.every(function (item, index) {
458
+ return jsonEqual(item, right[index]);
459
+ });
460
+ }
461
+ if (isObject(left) && isObject(right)) {
462
+ var keys = Object.keys(left);
463
+ return keys.length === Object.keys(right).length && keys.every(function (key) {
464
+ return Object.prototype.hasOwnProperty.call(right, key) && jsonEqual(left[key], right[key]);
465
+ });
466
+ }
467
+ return left === right;
468
+ }
469
+ function typeMessage(types) {
470
+ var names = types.map(function (type) {
471
+ return TYPE_NAMES[type] || type;
472
+ });
473
+ var connector = names.length > 1 && names.some(function (name) {
474
+ return name.includes(' or ');
475
+ }) ? ', or ' : ' or ';
476
+ if (names.length === 1) return "must be ".concat(names[0]);
477
+ if (names.length === 2) return "must be ".concat(names.join(connector));
478
+ return "must be ".concat(names.slice(0, -1).join(', ')).concat(connector).concat(names[names.length - 1]);
479
+ }
480
+ function atLeast(limit, message) {
481
+ return limit === 1 ? "can't be empty" : message;
482
+ }
483
+ function count(number, noun) {
484
+ return "".concat(number, " ").concat(number === 1 ? noun : "".concat(noun, "s"));
485
+ }
486
+ function toJson(value) {
487
+ return JSON.stringify(value);
488
+ }
489
+ function escape(token) {
490
+ return String(token).replace(/~/g, '~0').replace(/\//g, '~1');
491
+ }
492
+ function underscore(name) {
493
+ return name.replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').replace(/-/g, '_').toLowerCase();
494
+ }