@strav/herald 1.0.0-alpha.42

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 (52) hide show
  1. package/README.md +48 -0
  2. package/package.json +43 -0
  3. package/src/drivers/gbp/gbp_client.ts +155 -0
  4. package/src/drivers/gbp/gbp_config.ts +48 -0
  5. package/src/drivers/gbp/gbp_driver.ts +246 -0
  6. package/src/drivers/gbp/gbp_provider.ts +35 -0
  7. package/src/drivers/gbp/index.ts +23 -0
  8. package/src/drivers/meta/index.ts +21 -0
  9. package/src/drivers/meta/meta_client.ts +103 -0
  10. package/src/drivers/meta/meta_config.ts +45 -0
  11. package/src/drivers/meta/meta_driver.ts +313 -0
  12. package/src/drivers/meta/meta_provider.ts +45 -0
  13. package/src/drivers/meta/meta_webhook_ops.ts +227 -0
  14. package/src/drivers/wordpress/index.ts +24 -0
  15. package/src/drivers/wordpress/wordpress_client.ts +185 -0
  16. package/src/drivers/wordpress/wordpress_config.ts +51 -0
  17. package/src/drivers/wordpress/wordpress_driver.ts +277 -0
  18. package/src/drivers/wordpress/wordpress_provider.ts +37 -0
  19. package/src/drivers/wordpress/wordpress_validate.ts +122 -0
  20. package/src/dto/post_status.ts +14 -0
  21. package/src/dto/publish_input.ts +38 -0
  22. package/src/dto/publish_result.ts +23 -0
  23. package/src/dto/publish_target.ts +15 -0
  24. package/src/errors.ts +122 -0
  25. package/src/herald_capabilities.ts +37 -0
  26. package/src/herald_config.ts +32 -0
  27. package/src/herald_driver.ts +86 -0
  28. package/src/herald_manager.ts +169 -0
  29. package/src/herald_provider.ts +44 -0
  30. package/src/index.ts +65 -0
  31. package/src/ledger/apply_publication_migration.ts +53 -0
  32. package/src/ledger/index.ts +11 -0
  33. package/src/ledger/publication.ts +30 -0
  34. package/src/ledger/publication_repository.ts +172 -0
  35. package/src/ledger/publication_schema.ts +70 -0
  36. package/src/onboarding/complete_channel_connect.ts +154 -0
  37. package/src/onboarding/connect_channel_callback.ts +138 -0
  38. package/src/onboarding/index.ts +26 -0
  39. package/src/onboarding/types.ts +67 -0
  40. package/src/tenanted/apply_tenanted_publication_migration.ts +46 -0
  41. package/src/tenanted/index.ts +18 -0
  42. package/src/tenanted/tenanted_publication.ts +28 -0
  43. package/src/tenanted/tenanted_publication_repository.ts +145 -0
  44. package/src/tenanted/tenanted_publication_schema.ts +35 -0
  45. package/src/webhook/apply_herald_webhook_event_migration.ts +42 -0
  46. package/src/webhook/herald_event.ts +139 -0
  47. package/src/webhook/herald_webhook.ts +149 -0
  48. package/src/webhook/herald_webhook_event.ts +25 -0
  49. package/src/webhook/herald_webhook_event_repository.ts +65 -0
  50. package/src/webhook/herald_webhook_event_schema.ts +37 -0
  51. package/src/webhook/herald_webhook_registry.ts +65 -0
  52. package/src/webhook/index.ts +24 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Handler registry for normalized Herald webhook events.
3
+ *
4
+ * Apps register handlers at boot:
5
+ *
6
+ * herald.onWebhookEvent('post.published', (ctx) => { ... })
7
+ * herald.onWebhookEvent('engagement.review', { provider: 'gbp' }, (ctx) => { ... })
8
+ *
9
+ * Handlers fire in registration order. A thrown handler aborts the
10
+ * rest and surfaces a 500 (the provider retries). Multiple handlers
11
+ * per `(eventType, provider?)` are fine.
12
+ *
13
+ * Filter semantics: when `filter.provider` is set, the handler only
14
+ * fires for that provider-instance name; when omitted, the handler
15
+ * fires for any instance that emits the type.
16
+ */
17
+
18
+ import type {
19
+ HeraldEventType,
20
+ WebhookHandler,
21
+ WebhookHandlerFilter,
22
+ } from './herald_event.ts'
23
+
24
+ interface RegisteredHandler {
25
+ filter: WebhookHandlerFilter
26
+ handler: WebhookHandler
27
+ }
28
+
29
+ export class HeraldWebhookRegistry {
30
+ private readonly handlers = new Map<HeraldEventType, RegisteredHandler[]>()
31
+
32
+ on(eventType: HeraldEventType, handler: WebhookHandler): void
33
+ on(
34
+ eventType: HeraldEventType,
35
+ filter: WebhookHandlerFilter,
36
+ handler: WebhookHandler,
37
+ ): void
38
+ on(
39
+ eventType: HeraldEventType,
40
+ filterOrHandler: WebhookHandlerFilter | WebhookHandler,
41
+ maybeHandler?: WebhookHandler,
42
+ ): void {
43
+ const { filter, handler } =
44
+ typeof filterOrHandler === 'function'
45
+ ? { filter: {}, handler: filterOrHandler }
46
+ : { filter: filterOrHandler, handler: maybeHandler! }
47
+ const existing = this.handlers.get(eventType) ?? []
48
+ existing.push({ filter, handler })
49
+ this.handlers.set(eventType, existing)
50
+ }
51
+
52
+ /** Remove every registered handler. Tests use this to keep cases isolated. */
53
+ clear(): void {
54
+ this.handlers.clear()
55
+ }
56
+
57
+ /** Resolve the handlers that match a given `(type, provider)` pair. */
58
+ resolve(eventType: HeraldEventType, provider: string): readonly WebhookHandler[] {
59
+ const matches = this.handlers.get(eventType)
60
+ if (!matches) return []
61
+ return matches
62
+ .filter((m) => !m.filter.provider || m.filter.provider === provider)
63
+ .map((m) => m.handler)
64
+ }
65
+ }
@@ -0,0 +1,24 @@
1
+ export {
2
+ applyHeraldWebhookEventMigration,
3
+ type ApplyHeraldWebhookEventMigrationOptions,
4
+ } from './apply_herald_webhook_event_migration.ts'
5
+ export type {
6
+ CommentEvent,
7
+ HeraldEventType,
8
+ HeraldWebhookEvent,
9
+ HeraldWebhookEventBase,
10
+ PostDeletedEvent,
11
+ PostFailedEvent,
12
+ PostPublishedEvent,
13
+ ReactionEvent,
14
+ ReviewEvent,
15
+ UnknownEvent,
16
+ WebhookHandler,
17
+ WebhookHandlerContext,
18
+ WebhookHandlerFilter,
19
+ } from './herald_event.ts'
20
+ export { HeraldWebhookEventRecord } from './herald_webhook_event.ts'
21
+ export { HeraldWebhookEventRepository } from './herald_webhook_event_repository.ts'
22
+ export { heraldWebhookEventSchema } from './herald_webhook_event_schema.ts'
23
+ export { heraldWebhook, type HeraldWebhookOptions } from './herald_webhook.ts'
24
+ export { HeraldWebhookRegistry } from './herald_webhook_registry.ts'