@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.
- package/README.md +48 -0
- package/package.json +43 -0
- package/src/drivers/gbp/gbp_client.ts +155 -0
- package/src/drivers/gbp/gbp_config.ts +48 -0
- package/src/drivers/gbp/gbp_driver.ts +246 -0
- package/src/drivers/gbp/gbp_provider.ts +35 -0
- package/src/drivers/gbp/index.ts +23 -0
- package/src/drivers/meta/index.ts +21 -0
- package/src/drivers/meta/meta_client.ts +103 -0
- package/src/drivers/meta/meta_config.ts +45 -0
- package/src/drivers/meta/meta_driver.ts +313 -0
- package/src/drivers/meta/meta_provider.ts +45 -0
- package/src/drivers/meta/meta_webhook_ops.ts +227 -0
- package/src/drivers/wordpress/index.ts +24 -0
- package/src/drivers/wordpress/wordpress_client.ts +185 -0
- package/src/drivers/wordpress/wordpress_config.ts +51 -0
- package/src/drivers/wordpress/wordpress_driver.ts +277 -0
- package/src/drivers/wordpress/wordpress_provider.ts +37 -0
- package/src/drivers/wordpress/wordpress_validate.ts +122 -0
- package/src/dto/post_status.ts +14 -0
- package/src/dto/publish_input.ts +38 -0
- package/src/dto/publish_result.ts +23 -0
- package/src/dto/publish_target.ts +15 -0
- package/src/errors.ts +122 -0
- package/src/herald_capabilities.ts +37 -0
- package/src/herald_config.ts +32 -0
- package/src/herald_driver.ts +86 -0
- package/src/herald_manager.ts +169 -0
- package/src/herald_provider.ts +44 -0
- package/src/index.ts +65 -0
- package/src/ledger/apply_publication_migration.ts +53 -0
- package/src/ledger/index.ts +11 -0
- package/src/ledger/publication.ts +30 -0
- package/src/ledger/publication_repository.ts +172 -0
- package/src/ledger/publication_schema.ts +70 -0
- package/src/onboarding/complete_channel_connect.ts +154 -0
- package/src/onboarding/connect_channel_callback.ts +138 -0
- package/src/onboarding/index.ts +26 -0
- package/src/onboarding/types.ts +67 -0
- package/src/tenanted/apply_tenanted_publication_migration.ts +46 -0
- package/src/tenanted/index.ts +18 -0
- package/src/tenanted/tenanted_publication.ts +28 -0
- package/src/tenanted/tenanted_publication_repository.ts +145 -0
- package/src/tenanted/tenanted_publication_schema.ts +35 -0
- package/src/webhook/apply_herald_webhook_event_migration.ts +42 -0
- package/src/webhook/herald_event.ts +139 -0
- package/src/webhook/herald_webhook.ts +149 -0
- package/src/webhook/herald_webhook_event.ts +25 -0
- package/src/webhook/herald_webhook_event_repository.ts +65 -0
- package/src/webhook/herald_webhook_event_schema.ts +37 -0
- package/src/webhook/herald_webhook_registry.ts +65 -0
- 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'
|