@open-mercato/shared 0.6.7-develop.6725.1.07a748cfc2 → 0.6.7-develop.6744.1.0483b18565
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/.turbo/turbo-build.log +1 -1
- package/dist/lib/version.js +1 -1
- package/dist/lib/version.js.map +1 -1
- package/dist/lib/webhooks/inbound-types.js +1 -0
- package/dist/lib/webhooks/inbound-types.js.map +7 -0
- package/dist/lib/webhooks/index.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/webhooks/inbound-types.ts +125 -0
- package/src/lib/webhooks/index.ts +12 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
[build:shared] found
|
|
1
|
+
[build:shared] found 247 entry points
|
|
2
2
|
[build:shared] built successfully
|
package/dist/lib/version.js
CHANGED
package/dist/lib/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/version.ts"],
|
|
4
|
-
"sourcesContent": ["// Build-time generated version\nexport const APP_VERSION = '0.6.7-develop.
|
|
4
|
+
"sourcesContent": ["// Build-time generated version\nexport const APP_VERSION = '0.6.7-develop.6744.1.0483b18565'\nexport const appVersion = APP_VERSION\n"],
|
|
5
5
|
"mappings": "AACO,MAAM,cAAc;AACpB,MAAM,aAAa;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=inbound-types.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/webhooks/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { signWebhookPayload, buildWebhookHeaders, generateMessageId } from './sign'\nexport { verifyWebhookSignature } from './verify'\nexport { generateWebhookSecret, parseWebhookSecret, isValidWebhookSecret } from './secrets'\nexport type { StandardWebhookHeaders, WebhookSigningKey, WebhookVerificationResult, StandardWebhookPayload } from './types'\n"],
|
|
4
|
+
"sourcesContent": ["export { signWebhookPayload, buildWebhookHeaders, generateMessageId } from './sign'\nexport { verifyWebhookSignature } from './verify'\nexport { generateWebhookSecret, parseWebhookSecret, isValidWebhookSecret } from './secrets'\nexport type { StandardWebhookHeaders, WebhookSigningKey, WebhookVerificationResult, StandardWebhookPayload } from './types'\nexport type {\n InboundWebhookRequest,\n WebhookSourceCredentialField,\n WebhookSourceConfig,\n WebhookHandlerMeta,\n WebhookHandlerPayload,\n WebhookHandlerContext,\n WebhookHandler,\n WebhookHandlerRegistryEntry,\n WebhookHandlerResult,\n WebhookIngestionStatus,\n} from './inbound-types'\n"],
|
|
5
5
|
"mappings": "AAAA,SAAS,oBAAoB,qBAAqB,yBAAyB;AAC3E,SAAS,8BAA8B;AACvC,SAAS,uBAAuB,oBAAoB,4BAA4B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/shared",
|
|
3
|
-
"version": "0.6.7-develop.
|
|
3
|
+
"version": "0.6.7-develop.6744.1.0483b18565",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"@mikro-orm/core": "^7.1.5",
|
|
102
102
|
"@mikro-orm/decorators": "^7.1.5",
|
|
103
103
|
"@mikro-orm/postgresql": "^7.1.5",
|
|
104
|
-
"@open-mercato/cache": "0.6.7-develop.
|
|
104
|
+
"@open-mercato/cache": "0.6.7-develop.6744.1.0483b18565",
|
|
105
105
|
"@types/sanitize-html": "^2.16.1",
|
|
106
106
|
"dotenv": "^17.4.2",
|
|
107
107
|
"pino": "^10.3.1",
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound webhook handler types (SPEC: 2026-03-23-inbound-webhook-handlers).
|
|
3
|
+
*
|
|
4
|
+
* These mirror the event-subscriber DX: a module exports `webhook-sources.ts`
|
|
5
|
+
* (one or more `WebhookSourceConfig`) and `webhook-handlers/*.ts` files that each
|
|
6
|
+
* export `metadata: WebhookHandlerMeta` plus a default handler function.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Raw inbound request passed to a source verifier. */
|
|
10
|
+
export interface InboundWebhookRequest {
|
|
11
|
+
/** Raw request body, required for signature verification. */
|
|
12
|
+
body: string
|
|
13
|
+
/** Lower-cased request headers. */
|
|
14
|
+
headers: Record<string, string>
|
|
15
|
+
/** Parsed request body (best-effort JSON). */
|
|
16
|
+
parsedBody: Record<string, unknown>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Optional descriptor of the credential fields a source needs (drives the admin UI). */
|
|
20
|
+
export interface WebhookSourceCredentialField {
|
|
21
|
+
key: string
|
|
22
|
+
label: string
|
|
23
|
+
secret?: boolean
|
|
24
|
+
required?: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for an external webhook source (e.g. `stripe`, `resend`).
|
|
29
|
+
* Declared in a module's `webhook-sources.ts` via the `webhookSources` export.
|
|
30
|
+
*/
|
|
31
|
+
export interface WebhookSourceConfig {
|
|
32
|
+
/** Unique source identifier, e.g. `stripe`. Also the inbound path segment. */
|
|
33
|
+
key: string
|
|
34
|
+
/** Human-readable label. */
|
|
35
|
+
label: string
|
|
36
|
+
/**
|
|
37
|
+
* Verify the authenticity of an inbound webhook.
|
|
38
|
+
* Return true if valid, false to reject with 401. Throwing rejects with 400/500.
|
|
39
|
+
*/
|
|
40
|
+
verifier: (
|
|
41
|
+
request: InboundWebhookRequest,
|
|
42
|
+
credentials: Record<string, string>,
|
|
43
|
+
) => Promise<boolean>
|
|
44
|
+
/** Extract the event type from the parsed body/headers. */
|
|
45
|
+
eventTypeExtractor: (
|
|
46
|
+
body: Record<string, unknown>,
|
|
47
|
+
headers: Record<string, string>,
|
|
48
|
+
) => string
|
|
49
|
+
/** Extract a unique message id for deduplication. Return undefined if unavailable. */
|
|
50
|
+
messageIdExtractor?: (
|
|
51
|
+
body: Record<string, unknown>,
|
|
52
|
+
headers: Record<string, string>,
|
|
53
|
+
) => string | undefined
|
|
54
|
+
/** Optionally derive tenant scope from the payload/headers. */
|
|
55
|
+
scopeExtractor?: (
|
|
56
|
+
body: Record<string, unknown>,
|
|
57
|
+
headers: Record<string, string>,
|
|
58
|
+
) => { tenantId?: string; organizationId?: string }
|
|
59
|
+
/** Credential fields this source needs; used by the source-credential admin UI. */
|
|
60
|
+
credentialFields?: WebhookSourceCredentialField[]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Metadata exported by every `webhook-handlers/*.ts` file. */
|
|
64
|
+
export interface WebhookHandlerMeta {
|
|
65
|
+
/** Source key this handler listens to, e.g. `stripe`. */
|
|
66
|
+
source: string
|
|
67
|
+
/** Event-type pattern (supports wildcards: `*`, `payment_intent.*`). */
|
|
68
|
+
event: string
|
|
69
|
+
/** Unique handler id, e.g. `payments:stripe-payment-succeeded`. */
|
|
70
|
+
id: string
|
|
71
|
+
/** If true (default), handler runs via the queue-backed dispatcher. */
|
|
72
|
+
persistent?: boolean
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Payload handed to a webhook handler. */
|
|
76
|
+
export interface WebhookHandlerPayload {
|
|
77
|
+
/** Parsed webhook body. */
|
|
78
|
+
data: Record<string, unknown>
|
|
79
|
+
/** Extracted event type. */
|
|
80
|
+
eventType: string
|
|
81
|
+
/** Source key. */
|
|
82
|
+
sourceKey: string
|
|
83
|
+
/** Selected request headers. */
|
|
84
|
+
headers: Record<string, string>
|
|
85
|
+
/** WebhookIngestion record id. */
|
|
86
|
+
ingestionId: string
|
|
87
|
+
/** Tenant scope. */
|
|
88
|
+
tenantId: string
|
|
89
|
+
organizationId: string
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** DI accessor handed to a webhook handler. */
|
|
93
|
+
export interface WebhookHandlerContext {
|
|
94
|
+
resolve: <T>(name: string) => T
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A webhook handler function (default export of a `webhook-handlers/*.ts` file). */
|
|
98
|
+
export type WebhookHandler = (
|
|
99
|
+
payload: WebhookHandlerPayload,
|
|
100
|
+
ctx: WebhookHandlerContext,
|
|
101
|
+
) => Promise<void>
|
|
102
|
+
|
|
103
|
+
/** A generated registry entry binding handler metadata to a lazy module loader. */
|
|
104
|
+
export interface WebhookHandlerRegistryEntry {
|
|
105
|
+
meta: WebhookHandlerMeta
|
|
106
|
+
handler: () => Promise<{ default: WebhookHandler }>
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Per-handler execution detail recorded on a WebhookIngestion. */
|
|
110
|
+
export interface WebhookHandlerResult {
|
|
111
|
+
handlerId: string
|
|
112
|
+
module: string
|
|
113
|
+
status: 'success' | 'failed'
|
|
114
|
+
errorMessage?: string
|
|
115
|
+
durationMs: number
|
|
116
|
+
startedAt: string
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Lifecycle status of an inbound webhook ingestion. */
|
|
120
|
+
export type WebhookIngestionStatus =
|
|
121
|
+
| 'received'
|
|
122
|
+
| 'processing'
|
|
123
|
+
| 'processed'
|
|
124
|
+
| 'failed'
|
|
125
|
+
| 'duplicate'
|
|
@@ -2,3 +2,15 @@ export { signWebhookPayload, buildWebhookHeaders, generateMessageId } from './si
|
|
|
2
2
|
export { verifyWebhookSignature } from './verify'
|
|
3
3
|
export { generateWebhookSecret, parseWebhookSecret, isValidWebhookSecret } from './secrets'
|
|
4
4
|
export type { StandardWebhookHeaders, WebhookSigningKey, WebhookVerificationResult, StandardWebhookPayload } from './types'
|
|
5
|
+
export type {
|
|
6
|
+
InboundWebhookRequest,
|
|
7
|
+
WebhookSourceCredentialField,
|
|
8
|
+
WebhookSourceConfig,
|
|
9
|
+
WebhookHandlerMeta,
|
|
10
|
+
WebhookHandlerPayload,
|
|
11
|
+
WebhookHandlerContext,
|
|
12
|
+
WebhookHandler,
|
|
13
|
+
WebhookHandlerRegistryEntry,
|
|
14
|
+
WebhookHandlerResult,
|
|
15
|
+
WebhookIngestionStatus,
|
|
16
|
+
} from './inbound-types'
|