docspring 4.1.0 → 4.2.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 (111) hide show
  1. package/AGENTS.md +3 -2
  2. package/README.md +4 -1
  3. package/dist/ApiClient.js +2 -2
  4. package/dist/RequestSchemas.js +75 -8
  5. package/dist/WebhookSignature.js +86 -0
  6. package/dist/api/Client.js +147 -15
  7. package/dist/index.js +42 -0
  8. package/dist/model/AddTemplateFieldsRequest.js +1 -1
  9. package/dist/model/AuthenticationCheck.js +1 -1
  10. package/dist/model/CombinedPdf.js +3 -3
  11. package/dist/model/CombinedPdfFiles.js +1 -1
  12. package/dist/model/CombinedPdfList.js +1 -1
  13. package/dist/model/CombinedPdfSource.js +1 -1
  14. package/dist/model/CombinedPdfSourceInput.js +1 -1
  15. package/dist/model/CombinedPdfSourcePdf.js +1 -1
  16. package/dist/model/CopyTemplateRequest.js +1 -1
  17. package/dist/model/CreateCombinedPdfRequest.js +2 -2
  18. package/dist/model/CreateCustomFileFromUploadRequest.js +1 -1
  19. package/dist/model/CreateFolderRequest.js +1 -1
  20. package/dist/model/CreateSignatureRequestEventRequest.js +1 -1
  21. package/dist/model/CreateSignatureRequestTokenRequest.js +1 -1
  22. package/dist/model/CreateSubmissionBatchRequest.js +1 -1
  23. package/dist/model/CreateSubmissionRequest.js +3 -3
  24. package/dist/model/CreateTemplatePreviewRequest.js +112 -0
  25. package/dist/model/CreateTemplateRequest.js +11 -2
  26. package/dist/model/CreateWebhookRequest.js +1 -1
  27. package/dist/model/CustomFile.js +1 -1
  28. package/dist/model/CustomFileList.js +1 -1
  29. package/dist/model/CustomFileSourcePdf.js +1 -1
  30. package/dist/model/ErrorCode.js +11 -1
  31. package/dist/model/ErrorDetail.js +2 -2
  32. package/dist/model/ErrorInfo.js +6 -6
  33. package/dist/model/ErrorResponse.js +1 -1
  34. package/dist/model/Field.js +1 -1
  35. package/dist/model/FieldComparisonCondition.js +1 -1
  36. package/dist/model/FieldDependency.js +1 -1
  37. package/dist/model/FieldDependencyInput.js +1 -1
  38. package/dist/model/FieldEqualsCondition.js +1 -1
  39. package/dist/model/FieldGroup.js +1 -1
  40. package/dist/model/FieldGroupInput.js +1 -1
  41. package/dist/model/FieldInCondition.js +1 -1
  42. package/dist/model/FieldInput.js +1 -1
  43. package/dist/model/FieldOverride.js +1 -1
  44. package/dist/model/FieldPresenceCondition.js +1 -1
  45. package/dist/model/FieldRangeCondition.js +1 -1
  46. package/dist/model/Folder.js +1 -1
  47. package/dist/model/FolderList.js +1 -1
  48. package/dist/model/GenerateSubmissionFilesRequest.js +1 -1
  49. package/dist/model/GeneratedFile.js +1 -1
  50. package/dist/model/HtmlEngineOptions.js +1 -1
  51. package/dist/model/HtmlEngineOptionsInput.js +1 -1
  52. package/dist/model/MoveFolderRequest.js +1 -1
  53. package/dist/model/MoveTemplateRequest.js +1 -1
  54. package/dist/model/PageImage.js +1 -1
  55. package/dist/model/PageImages.js +1 -1
  56. package/dist/model/PredefinedField.js +1 -1
  57. package/dist/model/PredefinedFieldInput.js +1 -1
  58. package/dist/model/PublishTemplateVersionRequest.js +1 -1
  59. package/dist/model/RemoveTemplateFieldsRequest.js +1 -1
  60. package/dist/model/RenameFolderRequest.js +1 -1
  61. package/dist/model/ReorderTemplateFieldsRequest.js +1 -1
  62. package/dist/model/RestoreTemplateVersionRequest.js +1 -1
  63. package/dist/model/SignatureRequest.js +1 -1
  64. package/dist/model/SignatureRequestEvent.js +1 -1
  65. package/dist/model/SignatureRequestInput.js +1 -1
  66. package/dist/model/SignatureRequestToken.js +1 -1
  67. package/dist/model/Submission.js +75 -75
  68. package/dist/model/SubmissionAction.js +1 -1
  69. package/dist/model/SubmissionBatch.js +1 -1
  70. package/dist/model/SubmissionFiles.js +1 -1
  71. package/dist/model/SubmissionInput.js +3 -3
  72. package/dist/model/SubmissionList.js +5 -5
  73. package/dist/model/SubmissionSourcePdf.js +1 -1
  74. package/dist/model/SubmissionSummary.js +343 -0
  75. package/dist/model/SubmissionValidation.js +1 -1
  76. package/dist/model/Template.js +68 -57
  77. package/dist/model/TemplateActor.js +3 -3
  78. package/dist/model/TemplateDefaults.js +1 -1
  79. package/dist/model/TemplateDefaultsInput.js +1 -1
  80. package/dist/model/TemplateDiff.js +1 -1
  81. package/dist/model/TemplateDiffSummary.js +1 -1
  82. package/dist/model/TemplateDocument.js +33 -33
  83. package/dist/model/TemplateDocumentSummary.js +152 -0
  84. package/dist/model/TemplateFieldChange.js +1 -1
  85. package/dist/model/TemplateFieldChanges.js +1 -1
  86. package/dist/model/TemplateFieldDependency.js +1 -1
  87. package/dist/model/TemplateFieldDependencyCondition.js +1 -1
  88. package/dist/model/TemplateFieldDependencyConditionInput.js +1 -1
  89. package/dist/model/TemplateFieldDependencyInput.js +1 -1
  90. package/dist/model/TemplateFieldMove.js +1 -1
  91. package/dist/model/TemplateFields.js +1 -1
  92. package/dist/model/TemplateModelCode.js +1 -1
  93. package/dist/model/TemplatePageImages.js +1 -1
  94. package/dist/model/TemplatePageProcessingStatus.js +1 -1
  95. package/dist/model/TemplatePreview.js +211 -0
  96. package/dist/model/TemplatePreviewState.js +64 -0
  97. package/dist/model/TemplateSourcePdf.js +1 -1
  98. package/dist/model/TemplateSummary.js +14 -288
  99. package/dist/model/TemplateSummaryList.js +1 -1
  100. package/dist/model/TemplateVersion.js +1 -1
  101. package/dist/model/UpdateSignatureRequestRequest.js +1 -1
  102. package/dist/model/UpdateTemplateDocumentRequest.js +1 -1
  103. package/dist/model/UpdateTemplateFieldsRequest.js +1 -1
  104. package/dist/model/UpdateTemplateRequest.js +11 -2
  105. package/dist/model/UpdateWebhookRequest.js +1 -1
  106. package/dist/model/UploadPresign.js +1 -1
  107. package/dist/model/UrlSourcePdf.js +1 -1
  108. package/dist/model/ValidateSubmissionRequest.js +3 -3
  109. package/dist/model/Webhook.js +1 -1
  110. package/dist/model/WebhookList.js +1 -1
  111. package/package.json +3 -2
package/AGENTS.md CHANGED
@@ -69,8 +69,9 @@ keeps it.
69
69
  (https://docspring.com/docs/webhooks/overview/). A webhook created with API v2 sends events in API v2's format
70
70
  (version 4).
71
71
  - Verify each request's `X-DocSpring-Signature` header before acting on it: an HMAC-SHA256 of `{t}.{raw body}` with the
72
- webhook's signing secret, computed over the raw body exactly as received
73
- (https://docspring.com/docs/webhooks/verifying-signatures/).
72
+ webhook's signing secret, where `t` must be within 5 minutes
73
+ (https://docspring.com/docs/webhooks/verifying-signatures/). Pass the raw body exactly as received, not parsed JSON,
74
+ to `verifyWebhookSignature(payload, signatureHeader, secret)` (exported by the package), which returns true or false.
74
75
  - No webhook is sent when a submission starts waiting for credits.
75
76
 
76
77
  ## Signature requests
package/README.md CHANGED
@@ -9,7 +9,7 @@ templates with your data, generates PDFs from HTML templates, combines PDFs and
9
9
  The code in this repository is generated from DocSpring's OpenAPI spec ([About this SDK](#about-this-sdk)). Issues and
10
10
  pull requests are welcome.
11
11
 
12
- Version 4.1.0.
12
+ Version 4.2.0.
13
13
 
14
14
  ## Install and configure
15
15
 
@@ -99,6 +99,7 @@ JavaScript code for every method.
99
99
  | [`createSubmission`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#createsubmission) | Generate a PDF |
100
100
  | [`createSubmissionBatch`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#createsubmissionbatch) | Generate PDFs in a batch |
101
101
  | [`createTemplate`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#createtemplate) | Create a template |
102
+ | [`createTemplatePreview`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#createtemplatepreview) | Preview a template with data |
102
103
  | [`createWebhook`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#createwebhook) | Create a webhook |
103
104
  | [`deleteCustomFile`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#deletecustomfile) | Delete a custom file |
104
105
  | [`deleteFolder`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#deletefolder) | Delete a folder |
@@ -119,6 +120,7 @@ JavaScript code for every method.
119
120
  | [`getTemplateDiff`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#gettemplatediff) | Compare a version of a template with the one before it |
120
121
  | [`getTemplateModelCode`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#gettemplatemodelcode) | Generate typed code for a template's submission data |
121
122
  | [`getTemplatePageImages`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#gettemplatepageimages) | Get images of a template's pages |
123
+ | [`getTemplatePreview`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#gettemplatepreview) | Get a template preview |
122
124
  | [`getTemplateSchema`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#gettemplateschema) | Get the JSON Schema of a template's submission data |
123
125
  | [`getWebhook`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#getwebhook) | Get a webhook |
124
126
  | [`listCombinedPdfs`](https://github.com/DocSpring/docspring-javascript/blob/main/docs/Client.md#listcombinedpdfs) | List combined PDFs |
@@ -179,6 +181,7 @@ On top of the generated code, we add:
179
181
  - A client constructor that reads your credentials, region and host from the environment.
180
182
  - A nested object that's null in a response is `null` (stock OpenAPI Generator makes it `undefined`).
181
183
  - A rejected call's `response` is an object with the response's status, headers and body. Stock OpenAPI Generator attaches superagent's response, which holds the request's `Authorization` header, so logging the error printed the API token.
184
+ - `verifyWebhookSignature(payload, signatureHeader, secret)` checks a webhook request's `X-DocSpring-Signature` header, with a `{ tolerance, now }` options object.
182
185
 
183
186
  Each release regenerates every file, so a change made only here would be lost in the next one. Issues and pull
184
187
  requests are welcome all the same: [open an issue](https://github.com/DocSpring/docspring-javascript/issues) or a pull request, or email
package/dist/ApiClient.js CHANGED
@@ -38,7 +38,7 @@ function responseInfo(response) {
38
38
 
39
39
  /**
40
40
  * @module ApiClient
41
- * @version 4.1.0
41
+ * @version 4.2.0
42
42
  */
43
43
 
44
44
  /**
@@ -88,7 +88,7 @@ var ApiClient = /*#__PURE__*/function () {
88
88
  * @default {}
89
89
  */
90
90
  this.defaultHeaders = {
91
- 'User-Agent': 'docspring-javascript-4.1.0'
91
+ 'User-Agent': 'docspring-javascript-4.2.0'
92
92
  };
93
93
 
94
94
  /**
@@ -392,7 +392,7 @@ var _default = exports["default"] = {
392
392
  "name": {
393
393
  "type": "string",
394
394
  "minLength": 1,
395
- "maxLength": 255
395
+ "maxLength": 512
396
396
  },
397
397
  "parent_folder_id": {
398
398
  "type": ["string", "null"],
@@ -629,7 +629,7 @@ var _default = exports["default"] = {
629
629
  },
630
630
  "email": {
631
631
  "type": ["string", "null"],
632
- "maxLength": 255
632
+ "maxLength": 254
633
633
  },
634
634
  "fields": {
635
635
  "type": "array",
@@ -814,7 +814,7 @@ var _default = exports["default"] = {
814
814
  "name": {
815
815
  "type": "string",
816
816
  "minLength": 1,
817
- "maxLength": 255
817
+ "maxLength": 512
818
818
  },
819
819
  "description": {
820
820
  "type": ["string", "null"]
@@ -1131,6 +1131,9 @@ var _default = exports["default"] = {
1131
1131
  },
1132
1132
  "additionalProperties": false
1133
1133
  },
1134
+ "html_escape_data": {
1135
+ "type": "boolean"
1136
+ },
1134
1137
  "cache_id": {
1135
1138
  "type": "string",
1136
1139
  "minLength": 1,
@@ -1173,6 +1176,32 @@ var _default = exports["default"] = {
1173
1176
  }
1174
1177
  }
1175
1178
  },
1179
+ "createTemplatePreview": {
1180
+ "query": {
1181
+ "version": {
1182
+ "required": false,
1183
+ "schema": {
1184
+ "type": "string",
1185
+ "pattern": "^(\\d+(\\.\\d+(\\.\\d+)?)?|latest|draft)$",
1186
+ "x-pattern-message": "must be a version like 1.2.3 or 1, or latest or draft"
1187
+ }
1188
+ }
1189
+ },
1190
+ "body": {
1191
+ "mediaType": "application/json",
1192
+ "required": true,
1193
+ "schema": {
1194
+ "type": "object",
1195
+ "required": ["data"],
1196
+ "properties": {
1197
+ "data": {
1198
+ "type": "object"
1199
+ }
1200
+ },
1201
+ "additionalProperties": false
1202
+ }
1203
+ }
1204
+ },
1176
1205
  "createWebhook": {
1177
1206
  "body": {
1178
1207
  "mediaType": "application/json",
@@ -1182,7 +1211,7 @@ var _default = exports["default"] = {
1182
1211
  "properties": {
1183
1212
  "name": {
1184
1213
  "type": ["string", "null"],
1185
- "maxLength": 255
1214
+ "maxLength": 512
1186
1215
  },
1187
1216
  "url": {
1188
1217
  "type": "string",
@@ -1350,6 +1379,12 @@ var _default = exports["default"] = {
1350
1379
  "type": "string",
1351
1380
  "enum": ["typescript", "javascript", "ruby", "python", "php", "java", "csharp", "elixir", "go"]
1352
1381
  }
1382
+ },
1383
+ "just_types": {
1384
+ "required": false,
1385
+ "schema": {
1386
+ "type": "boolean"
1387
+ }
1353
1388
  }
1354
1389
  }
1355
1390
  },
@@ -1365,6 +1400,7 @@ var _default = exports["default"] = {
1365
1400
  }
1366
1401
  }
1367
1402
  },
1403
+ "getTemplatePreview": {},
1368
1404
  "getTemplateSchema": {
1369
1405
  "query": {
1370
1406
  "version": {
@@ -1485,6 +1521,19 @@ var _default = exports["default"] = {
1485
1521
  "schema": {
1486
1522
  "type": "string"
1487
1523
  }
1524
+ },
1525
+ "state": {
1526
+ "required": false,
1527
+ "schema": {
1528
+ "type": "string",
1529
+ "enum": ["pending", "processed", "invalid_data", "error", "image_download_failed", "image_processing_failed", "waiting_for_signature_requests", "syntax_error", "insufficient_credits", "account_suspended", "license_revoked", "accidental", "declined"]
1530
+ }
1531
+ },
1532
+ "include_files": {
1533
+ "required": false,
1534
+ "schema": {
1535
+ "type": "boolean"
1536
+ }
1488
1537
  }
1489
1538
  }
1490
1539
  },
@@ -1541,6 +1590,19 @@ var _default = exports["default"] = {
1541
1590
  "schema": {
1542
1591
  "type": "string"
1543
1592
  }
1593
+ },
1594
+ "state": {
1595
+ "required": false,
1596
+ "schema": {
1597
+ "type": "string",
1598
+ "enum": ["pending", "processed", "invalid_data", "error", "image_download_failed", "image_processing_failed", "waiting_for_signature_requests", "syntax_error", "insufficient_credits", "account_suspended", "license_revoked", "accidental", "declined"]
1599
+ }
1600
+ },
1601
+ "include_files": {
1602
+ "required": false,
1603
+ "schema": {
1604
+ "type": "boolean"
1605
+ }
1544
1606
  }
1545
1607
  }
1546
1608
  },
@@ -1812,7 +1874,7 @@ var _default = exports["default"] = {
1812
1874
  "name": {
1813
1875
  "type": "string",
1814
1876
  "minLength": 1,
1815
- "maxLength": 255
1877
+ "maxLength": 512
1816
1878
  },
1817
1879
  "description": {
1818
1880
  "type": ["string", "null"]
@@ -2158,6 +2220,9 @@ var _default = exports["default"] = {
2158
2220
  }
2159
2221
  },
2160
2222
  "additionalProperties": false
2223
+ },
2224
+ "html_escape_data": {
2225
+ "type": "boolean"
2161
2226
  }
2162
2227
  },
2163
2228
  "additionalProperties": false
@@ -2592,7 +2657,7 @@ var _default = exports["default"] = {
2592
2657
  "properties": {
2593
2658
  "name": {
2594
2659
  "type": ["string", "null"],
2595
- "maxLength": 255
2660
+ "maxLength": 512
2596
2661
  },
2597
2662
  "url": {
2598
2663
  "type": "string",
@@ -2678,7 +2743,7 @@ var _default = exports["default"] = {
2678
2743
  "name": {
2679
2744
  "type": "string",
2680
2745
  "minLength": 1,
2681
- "maxLength": 255
2746
+ "maxLength": 512
2682
2747
  },
2683
2748
  "description": {
2684
2749
  "type": "string"
@@ -2810,7 +2875,7 @@ var _default = exports["default"] = {
2810
2875
  },
2811
2876
  "email": {
2812
2877
  "type": ["string", "null"],
2813
- "maxLength": 255
2878
+ "maxLength": 254
2814
2879
  },
2815
2880
  "fields": {
2816
2881
  "type": "array",
@@ -2897,6 +2962,7 @@ var _default = exports["default"] = {
2897
2962
  "GET /templates/{template_id}/fields": "listTemplateFields",
2898
2963
  "GET /templates/{template_id}/model_code": "getTemplateModelCode",
2899
2964
  "GET /templates/{template_id}/page_images": "getTemplatePageImages",
2965
+ "GET /templates/{template_id}/previews/{preview_id}": "getTemplatePreview",
2900
2966
  "GET /templates/{template_id}/schema": "getTemplateSchema",
2901
2967
  "GET /templates/{template_id}/submissions": "listTemplateSubmissions",
2902
2968
  "GET /uploads/presign": "getPresignUrl",
@@ -2919,6 +2985,7 @@ var _default = exports["default"] = {
2919
2985
  "POST /templates/{template_id}/fields/remove": "removeTemplateFields",
2920
2986
  "POST /templates/{template_id}/fields/reorder": "reorderTemplateFields",
2921
2987
  "POST /templates/{template_id}/move": "moveTemplate",
2988
+ "POST /templates/{template_id}/previews": "createTemplatePreview",
2922
2989
  "POST /templates/{template_id}/publish_version": "publishTemplateVersion",
2923
2990
  "POST /templates/{template_id}/restore_version": "restoreTemplateVersion",
2924
2991
  "POST /templates/{template_id}/submissions": "createSubmission",
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WEBHOOK_SIGNATURE_TOLERANCE = void 0;
7
+ exports.verifyWebhookSignature = verifyWebhookSignature;
8
+ var _crypto = _interopRequireDefault(require("crypto"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
11
+ 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."); }
12
+ 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; } }
13
+ 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; }
14
+ 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; } }
15
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
16
+ /**
17
+ * Checks webhook requests' X-DocSpring-Signature header (https://docspring.com/docs/webhooks/verifying-signatures/).
18
+ * @module WebhookSignature
19
+ */
20
+
21
+ /**
22
+ * The number of seconds a webhook request's signature stays valid (verifyWebhookSignature)
23
+ * @type {Number}
24
+ */
25
+ var WEBHOOK_SIGNATURE_TOLERANCE = exports.WEBHOOK_SIGNATURE_TOLERANCE = 300;
26
+
27
+ /**
28
+ * Checks a webhook request's X-DocSpring-Signature header. Returns true when one of its v1 signatures is the
29
+ * HMAC-SHA256 of "{t}.{payload}" with the webhook's secret, and its timestamp t is at most `tolerance` seconds from
30
+ * `now`. Returns false for anything else, including a missing or malformed header.
31
+ * @param {String|Buffer} payload The request body exactly as it was received (Express: express.raw()), not parsed JSON.
32
+ * @param {String} signatureHeader The X-DocSpring-Signature header.
33
+ * @param {String} secret The webhook's signing secret.
34
+ * @param {Object} [options]
35
+ * @param {Number} [options.tolerance=300] How many seconds old (or early) the timestamp can be. 5 minutes by default.
36
+ * @param {Number} [options.now] The current Unix time in seconds, for tests. The system clock by default.
37
+ * @returns {Boolean}
38
+ */
39
+ function verifyWebhookSignature(payload, signatureHeader, secret) {
40
+ var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
41
+ _ref$tolerance = _ref.tolerance,
42
+ tolerance = _ref$tolerance === void 0 ? WEBHOOK_SIGNATURE_TOLERANCE : _ref$tolerance,
43
+ now = _ref.now;
44
+ var body;
45
+ if (typeof payload === 'string') {
46
+ body = Buffer.from(payload, 'utf8');
47
+ } else if (payload instanceof Uint8Array) {
48
+ body = Buffer.from(payload);
49
+ } else {
50
+ return false;
51
+ }
52
+ if (typeof signatureHeader !== 'string' || typeof secret !== 'string' || secret === '') return false;
53
+ var parts = signatureHeader.split(',').map(function (part) {
54
+ var trimmed = part.trim();
55
+ var separator = trimmed.indexOf('=');
56
+ return separator === -1 ? [trimmed, ''] : [trimmed.slice(0, separator), trimmed.slice(separator + 1)];
57
+ });
58
+ var timestampPart = parts.find(function (_ref2) {
59
+ var _ref3 = _slicedToArray(_ref2, 1),
60
+ key = _ref3[0];
61
+ return key === 't';
62
+ });
63
+ var signatures = parts.filter(function (_ref4) {
64
+ var _ref5 = _slicedToArray(_ref4, 2),
65
+ key = _ref5[0],
66
+ value = _ref5[1];
67
+ return key === 'v1' && value !== '';
68
+ }).map(function (_ref6) {
69
+ var _ref7 = _slicedToArray(_ref6, 2),
70
+ value = _ref7[1];
71
+ return value;
72
+ });
73
+ if (!timestampPart || !/^[0-9]+$/.test(timestampPart[1]) || signatures.length === 0) return false;
74
+ var timestamp = timestampPart[1];
75
+ var current = now === undefined || now === null ? Math.floor(Date.now() / 1000) : Number(now);
76
+ if (Math.abs(current - Number(timestamp)) > tolerance) return false;
77
+ var hmac = _crypto["default"].createHmac('sha256', secret);
78
+ hmac.update("".concat(timestamp, "."), 'utf8');
79
+ hmac.update(body);
80
+ var expected = Buffer.from(hmac.digest('hex'), 'utf8');
81
+ // Constant time, so a timing attack can't find a valid signature byte by byte
82
+ return signatures.some(function (signature) {
83
+ var actual = Buffer.from(signature, 'utf8');
84
+ return actual.length === expected.length && _crypto["default"].timingSafeEqual(actual, expected);
85
+ });
86
+ }