@haathie/pgmb 0.2.2 → 0.2.4
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/lib/types.d.ts +1 -1
- package/lib/webhook-handler.js +5 -2
- package/package.json +1 -1
- package/sql/pgmb.sql +1 -0
package/lib/types.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type PgmbWebhookOpts<T extends IEventData> = {
|
|
|
33
33
|
retryOpts?: IRetryHandlerOpts | null;
|
|
34
34
|
splitBy?: ISplitFn<T>;
|
|
35
35
|
jsonifier?: JSONifier;
|
|
36
|
-
serialiseEvent?(ev: IReadEvent): SerialisedEvent;
|
|
36
|
+
serialiseEvent?(ev: IReadEvent, logger: Logger): SerialisedEvent;
|
|
37
37
|
};
|
|
38
38
|
export interface IEventData {
|
|
39
39
|
topic: string;
|
package/lib/webhook-handler.js
CHANGED
|
@@ -22,12 +22,14 @@ function createWebhookHandler({ timeoutMs = 5_000, headers, retryOpts = {
|
|
|
22
22
|
&& (typeof extra.url === 'string'
|
|
23
23
|
|| extra.url instanceof URL), 'webhook handler requires extra.url parameter');
|
|
24
24
|
const { url } = extra;
|
|
25
|
-
const
|
|
25
|
+
const idempotencyKey = getIdempotencyKeyHeader(ev);
|
|
26
|
+
logger = logger.child({ idempotencyKey });
|
|
27
|
+
const { body, contentType } = serialiseEvent(ev, logger);
|
|
26
28
|
const { status, statusText, body: res } = await fetch(url, {
|
|
27
29
|
method: 'POST',
|
|
28
30
|
headers: {
|
|
29
31
|
'content-type': contentType,
|
|
30
|
-
'idempotency-key':
|
|
32
|
+
'idempotency-key': idempotencyKey,
|
|
31
33
|
...headers
|
|
32
34
|
},
|
|
33
35
|
body,
|
|
@@ -44,6 +46,7 @@ function createWebhookHandler({ timeoutMs = 5_000, headers, retryOpts = {
|
|
|
44
46
|
if (status < 200 || status >= 300) {
|
|
45
47
|
throw new Error(`Non-2xx response: ${status} (${statusText})`);
|
|
46
48
|
}
|
|
49
|
+
logger.info({ status }, 'webhook sent successfully');
|
|
47
50
|
};
|
|
48
51
|
if (!retryOpts) {
|
|
49
52
|
return handler;
|
package/package.json
CHANGED