@crombolo/server 0.56.0 → 0.58.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/src/webhooks.ts CHANGED
@@ -213,6 +213,11 @@ export interface WebhookServiceOptions {
213
213
  /** Publishes the schema directory to a shared store, when there is one. */
214
214
  onFilesChanged?: () => Promise<void>
215
215
  now?: () => Date
216
+ /**
217
+ * The origins a bundle's event `fetch` may reach (story 308); undefined for a
218
+ * bundle written before schema 4, which the address rule alone holds.
219
+ */
220
+ bundleOrigins?(bundleId: string): readonly string[] | undefined
216
221
  /** Whether a bundle is turned on (story 222); its events are not delivered while it is off. */
217
222
  isBundleOn?(bundleId: string): boolean
218
223
  /** The site's own handlers (story 298): which events it handles, and how one is handed over. */
@@ -634,7 +639,17 @@ export function createWebhookService(options: WebhookServiceOptions): WebhookSer
634
639
  payload: delivery.payload as { Id: string },
635
640
  deliveryId: delivery.id,
636
641
  attempt: delivery.attempts,
637
- fetch: (input, init) => pinnedFetch(input, { signal, ...init }, outbound),
642
+ fetch: (input, init) => {
643
+ const origins = options.bundleOrigins?.(bundleId)
644
+ const url = new URL(input instanceof Request ? input.url : String(input))
645
+ if (origins && !origins.includes(url.origin))
646
+ return Promise.reject(
647
+ new OutboundRefused(
648
+ `${bundleId} may not reach ${url.origin}: its http.outbound names ${origins.join(', ') || 'nothing'}.`,
649
+ ),
650
+ )
651
+ return pinnedFetch(input, { signal, ...init }, outbound)
652
+ },
638
653
  log: {
639
654
  info: (message, properties) => named.info(message, properties),
640
655
  warn: (message, properties) => named.warn(message, properties),