-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(): create exception and change dependances requirement
- Loading branch information
1 parent
e07935f
commit c723335
Showing
11 changed files
with
245 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './webhook.channel'; | ||
export * from './webhook.interface'; | ||
export * from './webhook.message'; | ||
export * from './webhook-channel.message'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { WebhookChannelException } from '../exceptions'; | ||
|
||
/** | ||
* Webhook message | ||
* @class WebhookChannelMessage | ||
*/ | ||
export class WebhookChannelMessage { | ||
/** | ||
* @public | ||
* @property {string} channelId | ||
*/ | ||
private url: string; | ||
|
||
/** | ||
* @public | ||
* @property {any} header | ||
*/ | ||
private header: any; | ||
|
||
/** | ||
* @public | ||
* @property {any} body | ||
*/ | ||
private body: any; | ||
|
||
/** | ||
* @constructor | ||
* @param {string} body | ||
*/ | ||
constructor(body: any) { | ||
this.body = body; | ||
} | ||
|
||
/** | ||
* Get url. | ||
*/ | ||
get getUrl() { | ||
return this.url; | ||
} | ||
|
||
/** | ||
* Set the message url. | ||
* @param {string} url | ||
* @return this | ||
*/ | ||
setUrl(url: string): WebhookChannelMessage { | ||
if (!url) { | ||
throw new WebhookChannelException('URL is not empty'); | ||
} | ||
|
||
this.url = url; | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Get header | ||
*/ | ||
get getHeader() { | ||
return this.header; | ||
} | ||
|
||
/** | ||
* Set the message header. | ||
* @param {any} header | ||
* @return this | ||
*/ | ||
setHeader(header: any): WebhookChannelMessage { | ||
this.header = header; | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Get body | ||
*/ | ||
get getBody() { | ||
return this.body; | ||
} | ||
|
||
/** | ||
* Set the message body. | ||
* @param {any} body | ||
* @return this | ||
*/ | ||
setBody(body: any): WebhookChannelMessage { | ||
this.body = body; | ||
|
||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './webhook-channel.constant'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const WEBHOOK_CHANNEL_HTTP = 'WEBHOOK_CHANNEL_HTTP'; | ||
export const WEBHOOK_CHANNEL_OPTIONS = 'WEBHOOK_CHANNEL_OPTIONS'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './webhook-channel.exception'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @class WebhookChannelException | ||
* @extends Error | ||
*/ | ||
export class WebhookChannelException extends Error { | ||
/** | ||
* @constructor | ||
* @param message | ||
*/ | ||
constructor(message: string) { | ||
super(message); | ||
|
||
this.name = 'WebhookChannelException'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './bootstrap'; | ||
export * from './webhook-channel.service'; | ||
export * from './interfaces'; | ||
export * from './webhook-channel.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './webhook-channel.interface'; | ||
export * from './webhook-channel-module.interface'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ModuleMetadata, Provider, Type } from '@nestjs/common'; | ||
|
||
/** | ||
* @interface WebhookChannelModuleOptionsFactory | ||
* @property createWebhookChannelOptions() | ||
*/ | ||
export interface WebhookChannelModuleOptionsFactory { | ||
createWebhookChannelOptions(): | ||
| Promise<WebhookChannelModuleOptions> | ||
| WebhookChannelModuleOptions; | ||
} | ||
|
||
/** | ||
* @interface WebhookChannelModuleAsyncOptions | ||
* @extends {Pick<ModuleMetadata, 'imports'>} | ||
* @property useExisting | ||
* @property useClass | ||
* @property useFactory | ||
* @property inject | ||
* @property extraProviders | ||
*/ | ||
export interface WebhookChannelModuleAsyncOptions | ||
extends Pick<ModuleMetadata, 'imports'> { | ||
useExisting?: Type<WebhookChannelModuleOptionsFactory>; | ||
useClass?: Type<WebhookChannelModuleOptionsFactory>; | ||
useFactory?: ( | ||
...args: any[] | ||
) => Promise<WebhookChannelModuleOptions> | WebhookChannelModuleOptions; | ||
inject?: any[]; | ||
extraProviders?: Provider[]; | ||
} | ||
|
||
/** | ||
* HTTP client. | ||
* @interface WebhookHttpClient | ||
*/ | ||
export interface WebhookHttpClient { | ||
maxRedirects?: number; | ||
timeout?: number; | ||
} | ||
|
||
/** | ||
* @interface WebhookChannelConfig | ||
*/ | ||
export interface WebhookChannelConfig { | ||
url?: string; | ||
} | ||
|
||
/** | ||
* @interface WebhookChannelModuleOptions | ||
* @property {string} twilioAccountSid | ||
* @property {string} twilioAuthToken | ||
* @property {string} endpoint | ||
*/ | ||
export interface WebhookChannelModuleOptions | ||
extends WebhookHttpClient, | ||
WebhookChannelConfig {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NestJsNotification } from '@sinuos/nestjs-notification'; | ||
|
||
/** | ||
* Webhook channel model | ||
* @interface IWebhookChannel | ||
* @extends NestJsNotification | ||
*/ | ||
export interface IWebhookChannel extends NestJsNotification { | ||
/** | ||
* Get the Http representation of the notification. | ||
* @property | ||
* @returns {any} http payload data | ||
*/ | ||
toWebhook?(): any; | ||
} |