zooid 0.14.0 → 0.14.1

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/dist/bin.js CHANGED
@@ -871,9 +871,25 @@ var MAX_BODY2 = 1e6;
871
871
  var MAX_OUTPUT_CHARS = 6e4;
872
872
  var TRUNCATION_MARKER = "\n\n\u2026 (truncated)";
873
873
  var DELIVERY_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
874
- var EVENT_HEADER_BY_PROVIDER = {
875
- github: "x-github-event"
874
+ var EVENT_SOURCE_BY_PROVIDER = {
875
+ github: { header: "x-github-event" },
876
+ stripe: { path: ["type"] },
877
+ standard: { path: ["type"] },
878
+ slack: { path: ["event", "type"] }
876
879
  };
880
+ function stringAt(body, path) {
881
+ let cursor = body;
882
+ for (const key of path) {
883
+ if (typeof cursor !== "object" || cursor === null) return void 0;
884
+ cursor = cursor[key];
885
+ }
886
+ return typeof cursor === "string" ? cursor : void 0;
887
+ }
888
+ function eventNameFor(provider, headers, body) {
889
+ const source = EVENT_SOURCE_BY_PROVIDER[provider];
890
+ if (!source) return void 0;
891
+ return "header" in source ? headers[source.header] : stringAt(body, source.path);
892
+ }
877
893
  var DELIVERY_ID_HEADER_BY_PROVIDER = {
878
894
  github: "x-github-delivery",
879
895
  standard: "webhook-id"
@@ -924,14 +940,13 @@ async function handleDelivery(deps, name, trigger, raw, headers, cache, customDe
924
940
  const idHeader = DELIVERY_ID_HEADER_BY_PROVIDER[webhook.provider];
925
941
  const deliveryId = customDeliveryId ?? (idHeader ? headers[idHeader] : void 0);
926
942
  if (deliveryId !== void 0 && cache.seen(`${name}:${deliveryId}`)) return;
927
- const eventHeader = EVENT_HEADER_BY_PROVIDER[webhook.provider];
928
- const event = eventHeader ? headers[eventHeader] : void 0;
929
943
  let body;
930
944
  try {
931
945
  body = JSON.parse(raw);
932
946
  } catch {
933
947
  body = void 0;
934
948
  }
949
+ const event = eventNameFor(webhook.provider, headers, body);
935
950
  const ctx = {
936
951
  event,
937
952
  body,