@theokit/gateway 0.16.1 → 0.17.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6329554: `rawBodyCapture` now refuses a body over 1 MiB with 413 when `maxBytes` is not given. The default is exported as `DEFAULT_WEBHOOK_MAX_BYTES`; pass `maxBytes: Number.POSITIVE_INFINITY` for no limit.
8
+
3
9
  ## 0.16.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -325,6 +325,9 @@ for (const { platform, reason } of failed) console.error(`${platform} did not co
325
325
  - `start()` waits for every connect under both `connectFailure` modes, so a connect that never
326
326
  settles blocks it. Under `"rollback"` that holds after a failure too: a failing start rejects
327
327
  only once its slowest connect settles.
328
+ - `rawBodyCapture(tag, { maxBytes })` (Express webhook routes) answers 413 with
329
+ `{ "error": "request body too large" }` to a body over `maxBytes`. The default is
330
+ `DEFAULT_WEBHOOK_MAX_BYTES`, 1 MiB; pass `Number.POSITIVE_INFINITY` for no limit.
328
331
  - A webhook channel's request reaches your HTTP route; route it by platform to the descriptor's
329
332
  `webhook.verify(adapter, { rawBody, headers })`, then parse the body and pass it to
330
333
  `webhook.ingest(adapter, payload)`, which answers `"delivered"`, `"malformed"` or
package/dist/index.cjs CHANGED
@@ -1524,10 +1524,10 @@ async function loadPeer(load, onMissing) {
1524
1524
  }
1525
1525
  }
1526
1526
  function rawBodyCapture(tag, options = {}) {
1527
- const { maxBytes } = options;
1528
- if (maxBytes !== void 0 && !(Number.isFinite(maxBytes) && maxBytes >= 0)) {
1527
+ const maxBytes = options.maxBytes ?? DEFAULT_WEBHOOK_MAX_BYTES;
1528
+ if (!(maxBytes >= 0)) {
1529
1529
  throw new RangeError(
1530
- `[${tag}] rawBodyCapture: maxBytes must be a finite number of zero or more, got ${maxBytes}`
1530
+ `[${tag}] rawBodyCapture: maxBytes must be a number of zero or more (Infinity allowed), got ${maxBytes}`
1531
1531
  );
1532
1532
  }
1533
1533
  return (rawReq, rawRes, next) => {
@@ -1543,13 +1543,13 @@ function rawBodyCapture(tag, options = {}) {
1543
1543
  }
1544
1544
  let buf = "";
1545
1545
  let bytes = 0;
1546
- let refused2 = maxBytes !== void 0 && declaredLength(req) > maxBytes;
1546
+ let refused2 = declaredLength(req) > maxBytes;
1547
1547
  let settled = false;
1548
1548
  req.setEncoding("utf8");
1549
1549
  req.on("data", (chunk) => {
1550
1550
  if (refused2 || settled) return;
1551
1551
  bytes += Buffer.byteLength(chunk);
1552
- if (maxBytes !== void 0 && bytes > maxBytes) {
1552
+ if (bytes > maxBytes) {
1553
1553
  refused2 = true;
1554
1554
  buf = "";
1555
1555
  return;
@@ -1560,7 +1560,7 @@ function rawBodyCapture(tag, options = {}) {
1560
1560
  if (settled) return;
1561
1561
  settled = true;
1562
1562
  if (refused2) {
1563
- answerTooLarge(rawRes, tag, maxBytes ?? 0);
1563
+ answerTooLarge(rawRes, tag, maxBytes);
1564
1564
  return;
1565
1565
  }
1566
1566
  req.rawBody = buf;
@@ -1574,6 +1574,7 @@ function rawBodyCapture(tag, options = {}) {
1574
1574
  });
1575
1575
  };
1576
1576
  }
1577
+ var DEFAULT_WEBHOOK_MAX_BYTES = 1024 * 1024;
1577
1578
  function declaredLength(req) {
1578
1579
  const value = req.headers?.["content-length"];
1579
1580
  const declared = Number(Array.isArray(value) ? value[0] : value);
@@ -1625,6 +1626,7 @@ function listenerLifecycle(opts) {
1625
1626
 
1626
1627
  exports.BasePlatformAdapter = BasePlatformAdapter;
1627
1628
  exports.CREDENTIAL_SHAPES = CREDENTIAL_SHAPES;
1629
+ exports.DEFAULT_WEBHOOK_MAX_BYTES = DEFAULT_WEBHOOK_MAX_BYTES;
1628
1630
  exports.DeliveryRouter = DeliveryRouter;
1629
1631
  exports.GatewayConfigurationError = GatewayConfigurationError;
1630
1632
  exports.GatewayLifecycleError = GatewayLifecycleError;