@dudousxd/nestjs-notifications-webhook 0.2.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.
@@ -0,0 +1,5 @@
1
+ export { WebhookMessage, type WebhookMethod, type WebhookRequest, } from './webhook-message';
2
+ export { Webhook, WebhookChannel, type WebhookChannelOptions, type WebhookNotification, } from './webhook.channel';
3
+ export { WebhookChannelModule, type WebhookChannelModuleOptions, } from './webhook.module';
4
+ export { WEBHOOK_OPTIONS } from './tokens';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,cAAc,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,OAAO,EACP,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,KAAK,2BAA2B,GACjC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WEBHOOK_OPTIONS = exports.WebhookChannelModule = exports.WebhookChannel = exports.Webhook = exports.WebhookMessage = void 0;
4
+ var webhook_message_1 = require("./webhook-message");
5
+ Object.defineProperty(exports, "WebhookMessage", { enumerable: true, get: function () { return webhook_message_1.WebhookMessage; } });
6
+ var webhook_channel_1 = require("./webhook.channel");
7
+ Object.defineProperty(exports, "Webhook", { enumerable: true, get: function () { return webhook_channel_1.Webhook; } });
8
+ Object.defineProperty(exports, "WebhookChannel", { enumerable: true, get: function () { return webhook_channel_1.WebhookChannel; } });
9
+ var webhook_module_1 = require("./webhook.module");
10
+ Object.defineProperty(exports, "WebhookChannelModule", { enumerable: true, get: function () { return webhook_module_1.WebhookChannelModule; } });
11
+ var tokens_1 = require("./tokens");
12
+ Object.defineProperty(exports, "WEBHOOK_OPTIONS", { enumerable: true, get: function () { return tokens_1.WEBHOOK_OPTIONS; } });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAI2B;AAHzB,iHAAA,cAAc,OAAA;AAIhB,qDAK2B;AAJzB,0GAAA,OAAO,OAAA;AACP,iHAAA,cAAc,OAAA;AAIhB,mDAG0B;AAFxB,sHAAA,oBAAoB,OAAA;AAGtB,mCAA2C;AAAlC,yGAAA,eAAe,OAAA"}
@@ -0,0 +1,3 @@
1
+ /** DI token for the resolved {@link WebhookChannelOptions} (default url, headers). */
2
+ export declare const WEBHOOK_OPTIONS: unique symbol;
3
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,eAAO,MAAM,eAAe,eAA4B,CAAC"}
package/dist/tokens.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WEBHOOK_OPTIONS = void 0;
4
+ /** DI token for the resolved {@link WebhookChannelOptions} (default url, headers). */
5
+ exports.WEBHOOK_OPTIONS = Symbol('WEBHOOK_OPTIONS');
6
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":";;;AAAA,sFAAsF;AACzE,QAAA,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,44 @@
1
+ /** The HTTP method used for a webhook request. */
2
+ export type WebhookMethod = 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'GET';
3
+ /** The resolved request description produced by {@link WebhookMessage.toRequest}. */
4
+ export interface WebhookRequest {
5
+ /** Target URL, when set on the message; otherwise resolved by the channel. */
6
+ url?: string;
7
+ method: WebhookMethod;
8
+ headers: Record<string, string>;
9
+ /** The JSON body to send (a plain object). */
10
+ body: Record<string, unknown>;
11
+ }
12
+ /**
13
+ * A fluent builder for a webhook request.
14
+ *
15
+ * ```ts
16
+ * new WebhookMessage()
17
+ * .url('https://example.com/hooks/orders')
18
+ * .header('X-Signature', sign(payload))
19
+ * .payload({ event: 'order.paid', id: 42 });
20
+ * ```
21
+ */
22
+ export declare class WebhookMessage {
23
+ private _url?;
24
+ private _method;
25
+ private _headers;
26
+ private _payload;
27
+ /** Set the target URL (overrides the route and configured default). */
28
+ url(u: string): this;
29
+ /** Set the JSON body to send. */
30
+ payload(obj: Record<string, unknown>): this;
31
+ /** Set a single request header. */
32
+ header(key: string, value: string): this;
33
+ /** Merge multiple request headers. */
34
+ headers(obj: Record<string, string>): this;
35
+ /** Set the HTTP method (default `POST`). */
36
+ method(m: WebhookMethod): this;
37
+ get urlValue(): string | undefined;
38
+ get methodValue(): WebhookMethod;
39
+ get headerValues(): Record<string, string>;
40
+ get payloadValue(): Record<string, unknown>;
41
+ /** Serialize to a {@link WebhookRequest}. */
42
+ toRequest(): WebhookRequest;
43
+ }
44
+ //# sourceMappingURL=webhook-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-message.d.ts","sourceRoot":"","sources":["../src/webhook-message.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;AAExE,qFAAqF;AACrF,MAAM,WAAW,cAAc;IAC7B,8EAA8E;IAC9E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;;;;;;;;GASG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,IAAI,CAAC,CAAS;IACtB,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,QAAQ,CAA+B;IAE/C,uEAAuE;IACvE,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAKpB,iCAAiC;IACjC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAK3C,mCAAmC;IACnC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAKxC,sCAAsC;IACtC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAK1C,4CAA4C;IAC5C,MAAM,CAAC,CAAC,EAAE,aAAa,GAAG,IAAI;IAK9B,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAEjC;IAED,IAAI,WAAW,IAAI,aAAa,CAE/B;IAED,IAAI,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEzC;IAED,IAAI,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE1C;IAED,6CAA6C;IAC7C,SAAS,IAAI,cAAc;CAQ5B"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookMessage = void 0;
4
+ /**
5
+ * A fluent builder for a webhook request.
6
+ *
7
+ * ```ts
8
+ * new WebhookMessage()
9
+ * .url('https://example.com/hooks/orders')
10
+ * .header('X-Signature', sign(payload))
11
+ * .payload({ event: 'order.paid', id: 42 });
12
+ * ```
13
+ */
14
+ class WebhookMessage {
15
+ _url;
16
+ _method = 'POST';
17
+ _headers = {};
18
+ _payload = {};
19
+ /** Set the target URL (overrides the route and configured default). */
20
+ url(u) {
21
+ this._url = u;
22
+ return this;
23
+ }
24
+ /** Set the JSON body to send. */
25
+ payload(obj) {
26
+ this._payload = obj;
27
+ return this;
28
+ }
29
+ /** Set a single request header. */
30
+ header(key, value) {
31
+ this._headers[key] = value;
32
+ return this;
33
+ }
34
+ /** Merge multiple request headers. */
35
+ headers(obj) {
36
+ this._headers = { ...this._headers, ...obj };
37
+ return this;
38
+ }
39
+ /** Set the HTTP method (default `POST`). */
40
+ method(m) {
41
+ this._method = m;
42
+ return this;
43
+ }
44
+ get urlValue() {
45
+ return this._url;
46
+ }
47
+ get methodValue() {
48
+ return this._method;
49
+ }
50
+ get headerValues() {
51
+ return this._headers;
52
+ }
53
+ get payloadValue() {
54
+ return this._payload;
55
+ }
56
+ /** Serialize to a {@link WebhookRequest}. */
57
+ toRequest() {
58
+ return {
59
+ url: this._url,
60
+ method: this._method,
61
+ headers: { ...this._headers },
62
+ body: this._payload,
63
+ };
64
+ }
65
+ }
66
+ exports.WebhookMessage = WebhookMessage;
67
+ //# sourceMappingURL=webhook-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-message.js","sourceRoot":"","sources":["../src/webhook-message.ts"],"names":[],"mappings":";;;AAaA;;;;;;;;;GASG;AACH,MAAa,cAAc;IACjB,IAAI,CAAU;IACd,OAAO,GAAkB,MAAM,CAAC;IAChC,QAAQ,GAA2B,EAAE,CAAC;IACtC,QAAQ,GAA4B,EAAE,CAAC;IAE/C,uEAAuE;IACvE,GAAG,CAAC,CAAS;QACX,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iCAAiC;IACjC,OAAO,CAAC,GAA4B;QAClC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mCAAmC;IACnC,MAAM,CAAC,GAAW,EAAE,KAAa;QAC/B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sCAAsC;IACtC,OAAO,CAAC,GAA2B;QACjC,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,GAAG,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4CAA4C;IAC5C,MAAM,CAAC,CAAgB;QACrB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,6CAA6C;IAC7C,SAAS;QACP,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,IAAI;YACd,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE;YAC7B,IAAI,EAAE,IAAI,CAAC,QAAQ;SACpB,CAAC;IACJ,CAAC;CACF;AA7DD,wCA6DC"}
@@ -0,0 +1,32 @@
1
+ import { type ChannelDriver, type Notifiable, type Notification } from '@dudousxd/nestjs-notifications-core';
2
+ import { WebhookMessage } from './webhook-message';
3
+ /** Channel handle: use as `@Webhook()` on a payload method, or as a token in `via()`. */
4
+ export declare const Webhook: import("@dudousxd/nestjs-notifications-core").ChannelHandle;
5
+ /** Resolved runtime options for the webhook channel. */
6
+ export interface WebhookChannelOptions {
7
+ /** Default URL used when neither the message nor the route supplies one. */
8
+ url?: string;
9
+ /** Default headers merged into every request. */
10
+ headers?: Record<string, string>;
11
+ }
12
+ /**
13
+ * Implement this on a notification to define its webhook payload. Returning a plain
14
+ * object is treated as the JSON body to POST; return a {@link WebhookMessage} for full
15
+ * control over the url, method and headers.
16
+ */
17
+ export interface WebhookNotification extends Notification {
18
+ toWebhook(notifiable: Notifiable): WebhookMessage | Record<string, unknown>;
19
+ }
20
+ /**
21
+ * Delivers a notification by sending an HTTP request (JSON body) to a webhook endpoint.
22
+ * The target URL comes from the {@link WebhookMessage}, else from
23
+ * `routeNotificationFor('webhook')` (a URL string), else from the configured default.
24
+ */
25
+ export declare class WebhookChannel implements ChannelDriver {
26
+ private readonly options;
27
+ readonly channel = "webhook";
28
+ constructor(options: WebhookChannelOptions);
29
+ send(notifiable: Notifiable, notification: Notification): Promise<void>;
30
+ private post;
31
+ }
32
+ //# sourceMappingURL=webhook.channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.channel.d.ts","sourceRoot":"","sources":["../src/webhook.channel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,UAAU,EACf,KAAK,YAAY,EAGlB,MAAM,qCAAqC,CAAC;AAG7C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,yFAAyF;AACzF,eAAO,MAAM,OAAO,6DAA2B,CAAC;AAEhD,wDAAwD;AACxD,MAAM,WAAW,qBAAqB;IACpC,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7E;AAED;;;;GAIG;AACH,qBACa,cAAe,YAAW,aAAa;IAKhD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,QAAQ,CAAC,OAAO,aAAa;gBAIV,OAAO,EAAE,qBAAqB;IAG3C,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;YA2B/D,IAAI;CAsBnB"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.WebhookChannel = exports.Webhook = void 0;
16
+ const nestjs_notifications_core_1 = require("@dudousxd/nestjs-notifications-core");
17
+ const common_1 = require("@nestjs/common");
18
+ const tokens_1 = require("./tokens");
19
+ const webhook_message_1 = require("./webhook-message");
20
+ /** Channel handle: use as `@Webhook()` on a payload method, or as a token in `via()`. */
21
+ exports.Webhook = (0, nestjs_notifications_core_1.createChannel)('webhook');
22
+ /**
23
+ * Delivers a notification by sending an HTTP request (JSON body) to a webhook endpoint.
24
+ * The target URL comes from the {@link WebhookMessage}, else from
25
+ * `routeNotificationFor('webhook')` (a URL string), else from the configured default.
26
+ */
27
+ let WebhookChannel = class WebhookChannel {
28
+ options;
29
+ channel = 'webhook';
30
+ constructor(options) {
31
+ this.options = options;
32
+ }
33
+ async send(notifiable, notification) {
34
+ const handler = (0, nestjs_notifications_core_1.getHandler)(notification, 'webhook', 'toWebhook');
35
+ if (!handler) {
36
+ const name = notification.constructor.notificationName ??
37
+ notification.constructor.name;
38
+ throw new nestjs_notifications_core_1.MissingChannelMethodError('webhook', 'toWebhook()', name);
39
+ }
40
+ const result = handler(notifiable);
41
+ const message = result instanceof webhook_message_1.WebhookMessage ? result : new webhook_message_1.WebhookMessage().payload(result);
42
+ const request = message.toRequest();
43
+ const route = notifiable.routeNotificationFor('webhook', notification);
44
+ const url = request.url ?? (typeof route === 'string' ? route : undefined) ?? this.options.url;
45
+ if (!url) {
46
+ throw new Error('The webhook channel needs a target URL. Set one on the WebhookMessage via .url(), ' +
47
+ 'return one from routeNotificationFor("webhook"), or set url in forRoot().');
48
+ }
49
+ await this.post(url, request.method, request.body, request.headers);
50
+ }
51
+ async post(url, method, body, messageHeaders) {
52
+ const headers = {
53
+ ...this.options.headers,
54
+ ...messageHeaders,
55
+ 'Content-Type': 'application/json',
56
+ };
57
+ const response = await fetch(url, {
58
+ method,
59
+ headers,
60
+ body: JSON.stringify(body),
61
+ });
62
+ if (!response.ok) {
63
+ throw new Error(`Webhook request to ${url} failed with status ${response.status}.`);
64
+ }
65
+ }
66
+ };
67
+ exports.WebhookChannel = WebhookChannel;
68
+ exports.WebhookChannel = WebhookChannel = __decorate([
69
+ (0, common_1.Injectable)(),
70
+ __param(0, (0, common_1.Inject)(tokens_1.WEBHOOK_OPTIONS)),
71
+ __metadata("design:paramtypes", [Object])
72
+ ], WebhookChannel);
73
+ //# sourceMappingURL=webhook.channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.channel.js","sourceRoot":"","sources":["../src/webhook.channel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mFAO6C;AAC7C,2CAAoD;AACpD,qCAA2C;AAC3C,uDAAmD;AAGnD,yFAAyF;AAC5E,QAAA,OAAO,GAAG,IAAA,yCAAa,EAAC,SAAS,CAAC,CAAC;AAmBhD;;;;GAIG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IAKN;IAJV,OAAO,GAAG,SAAS,CAAC;IAE7B,YAEmB,OAA8B;QAA9B,YAAO,GAAP,OAAO,CAAuB;IAC9C,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,UAAsB,EAAE,YAA0B;QAC3D,MAAM,OAAO,GAAG,IAAA,sCAAU,EAAC,YAAY,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;QACjE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,GACP,YAAY,CAAC,WAA6C,CAAC,gBAAgB;gBAC5E,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC;YAChC,MAAM,IAAI,qDAAyB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;QACtE,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAA6C,CAAC;QAC/E,MAAM,OAAO,GACX,MAAM,YAAY,gCAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,gCAAc,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACnF,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;QAEpC,MAAM,KAAK,GAAG,UAAU,CAAC,oBAAoB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QACvE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;QAE/F,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CACb,oFAAoF;gBAClF,2EAA2E,CAC9E,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,CAAC;IAEO,KAAK,CAAC,IAAI,CAChB,GAAW,EACX,MAAqB,EACrB,IAA6B,EAC7B,cAAsC;QAEtC,MAAM,OAAO,GAA2B;YACtC,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO;YACvB,GAAG,cAAc;YACjB,cAAc,EAAE,kBAAkB;SACnC,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM;YACN,OAAO;YACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,uBAAuB,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;CACF,CAAA;AAzDY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,wBAAe,CAAC,CAAA;;GAJf,cAAc,CAyD1B"}
@@ -0,0 +1,20 @@
1
+ import { type DynamicModule } from '@nestjs/common';
2
+ export interface WebhookChannelModuleOptions {
3
+ /** Default URL used when neither the message nor the route supplies one. */
4
+ url?: string;
5
+ /** Default headers merged into every request. */
6
+ headers?: Record<string, string>;
7
+ /** Register globally so the channel is discoverable app-wide. Default true. */
8
+ global?: boolean;
9
+ }
10
+ /**
11
+ * Registers the webhook channel.
12
+ *
13
+ * ```ts
14
+ * WebhookChannelModule.forRoot({ url: 'https://example.com/hooks/notifications' });
15
+ * ```
16
+ */
17
+ export declare class WebhookChannelModule {
18
+ static forRoot(options?: WebhookChannelModuleOptions): DynamicModule;
19
+ }
20
+ //# sourceMappingURL=webhook.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.module.d.ts","sourceRoot":"","sources":["../src/webhook.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAyB,MAAM,gBAAgB,CAAC;AAI3E,MAAM,WAAW,2BAA2B;IAC1C,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,+EAA+E;IAC/E,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;GAMG;AACH,qBACa,oBAAoB;IAC/B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,2BAAgC,GAAG,aAAa;CAkBzE"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var WebhookChannelModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.WebhookChannelModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const tokens_1 = require("./tokens");
13
+ const webhook_channel_1 = require("./webhook.channel");
14
+ /**
15
+ * Registers the webhook channel.
16
+ *
17
+ * ```ts
18
+ * WebhookChannelModule.forRoot({ url: 'https://example.com/hooks/notifications' });
19
+ * ```
20
+ */
21
+ let WebhookChannelModule = WebhookChannelModule_1 = class WebhookChannelModule {
22
+ static forRoot(options = {}) {
23
+ const webhookOptions = {
24
+ url: options.url,
25
+ headers: options.headers,
26
+ };
27
+ const providers = [
28
+ { provide: tokens_1.WEBHOOK_OPTIONS, useValue: webhookOptions },
29
+ webhook_channel_1.WebhookChannel,
30
+ ];
31
+ return {
32
+ module: WebhookChannelModule_1,
33
+ global: options.global ?? true,
34
+ providers,
35
+ exports: [webhook_channel_1.WebhookChannel],
36
+ };
37
+ }
38
+ };
39
+ exports.WebhookChannelModule = WebhookChannelModule;
40
+ exports.WebhookChannelModule = WebhookChannelModule = WebhookChannelModule_1 = __decorate([
41
+ (0, common_1.Module)({})
42
+ ], WebhookChannelModule);
43
+ //# sourceMappingURL=webhook.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.module.js","sourceRoot":"","sources":["../src/webhook.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA2E;AAC3E,qCAA2C;AAC3C,uDAA+E;AAW/E;;;;;;GAMG;AAEI,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAC/B,MAAM,CAAC,OAAO,CAAC,UAAuC,EAAE;QACtD,MAAM,cAAc,GAA0B;YAC5C,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;QAEF,MAAM,SAAS,GAAe;YAC5B,EAAE,OAAO,EAAE,wBAAe,EAAE,QAAQ,EAAE,cAAc,EAAE;YACtD,gCAAc;SACf,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,sBAAoB;YAC5B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI;YAC9B,SAAS;YACT,OAAO,EAAE,CAAC,gCAAc,CAAC;SAC1B,CAAC;IACJ,CAAC;CACF,CAAA;AAnBY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,oBAAoB,CAmBhC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@dudousxd/nestjs-notifications-webhook",
3
+ "version": "0.2.0",
4
+ "description": "Webhook channel for nestjs-notifications — deliver notifications by POSTing JSON to an HTTP endpoint",
5
+ "license": "MIT",
6
+ "author": "Davide Carvalho",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/DavideCarvalho/nestjs-notifications.git",
10
+ "directory": "packages/webhook"
11
+ },
12
+ "type": "commonjs",
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "peerDependencies": {
19
+ "@dudousxd/nestjs-notifications-core": ">=0.1.0 <1.0.0",
20
+ "@nestjs/common": "^10.0.0 || ^11.0.0"
21
+ },
22
+ "devDependencies": {
23
+ "@nestjs/common": "^11.0.0",
24
+ "reflect-metadata": "^0.2.2",
25
+ "typescript": "^5.7.2",
26
+ "@dudousxd/nestjs-notifications-core": "^0.2.0"
27
+ },
28
+ "scripts": {
29
+ "build": "tsc -p tsconfig.json",
30
+ "typecheck": "tsc -p tsconfig.json --noEmit"
31
+ }
32
+ }