Skip to content

Commit 1917e1b

Browse files
chore(providers): Modernize TS setup (#7699)
1 parent 78c02e9 commit 1917e1b

File tree

141 files changed

+1693
-2582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+1693
-2582
lines changed

packages/providers/babel.config.js

-6
This file was deleted.

packages/providers/package.json

+15-31
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,28 @@
22
"name": "@novu/providers",
33
"version": "2.6.5",
44
"description": "Novu Provider Wrappers",
5-
"main": "build/main/index.js",
6-
"typings": "build/main/index.d.ts",
7-
"module": "build/module/index.js",
8-
"private": false,
5+
"main": "dist/cjs/index.js",
6+
"module": "dist/esm/index.js",
7+
"types": "dist/cjs/index.d.ts",
8+
"files": [
9+
"dist/",
10+
"!**/*.spec.*",
11+
"!**/*.json",
12+
"CHANGELOG.md",
13+
"LICENSE",
14+
"README.md"
15+
],
916
"repository": "https://github.com/novuhq/novu",
1017
"license": "MIT",
1118
"keywords": [],
1219
"scripts": {
1320
"start": "npm run watch:build",
1421
"prebuild": "rimraf build",
15-
"build": "run-p build:*",
16-
"build:main": "tsc -p tsconfig.json",
17-
"build:module": "tsc -p tsconfig.module.json",
18-
"fix": "run-s fix:*",
19-
"fix:prettier": "prettier \"src/**/*.ts\" --write",
22+
"build": "npm run build:cjs && npm run build:esm",
23+
"build:esm": "tsc -p tsconfig.esm.json",
24+
"build:cjs": "tsc -p tsconfig.json",
2025
"lint:fix": "pnpm lint -- --fix",
21-
"lint": "eslint src",
26+
"lint": "eslint src --fix",
2227
"test": "vitest",
2328
"watch:build": "tsc -p tsconfig.json -w",
2429
"watch:test": "vitest",
@@ -74,7 +79,6 @@
7479
"devDependencies": {
7580
"@babel/preset-env": "^7.23.2",
7681
"@babel/preset-typescript": "^7.13.0",
77-
"@istanbuljs/nyc-config-typescript": "~1.0.1",
7882
"@types/node-mailjet": "^3.3.7",
7983
"@types/nodemailer": "^6.4.4",
8084
"@types/sparkpost": "^2.1.5",
@@ -83,34 +87,14 @@
8387
"cspell": "~6.19.2",
8488
"nock": "^13.1.3",
8589
"npm-run-all": "^4.1.5",
86-
"nyc": "~15.1.0",
8790
"open-cli": "^6.0.1",
88-
"prettier": "~2.8.0",
8991
"rimraf": "~3.0.2",
9092
"ts-node": "~10.9.1",
9193
"typedoc": "^0.24.0",
9294
"typescript": "5.6.2",
9395
"uuid": "^9.0.0",
9496
"vitest": "^2.0.5"
9597
},
96-
"files": [
97-
"build/main",
98-
"build/module",
99-
"!**/*.spec.*",
100-
"!**/*.json",
101-
"CHANGELOG.md",
102-
"LICENSE",
103-
"README.md"
104-
],
105-
"prettier": {
106-
"singleQuote": true
107-
},
108-
"nyc": {
109-
"extends": "@istanbuljs/nyc-config-typescript",
110-
"exclude": [
111-
"**/*.spec.js"
112-
]
113-
},
11498
"nx": {
11599
"tags": [
116100
"type:package"

packages/providers/src/base.provider.ts

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
camelCase,
3-
constantCase,
4-
kebabCase,
5-
pascalCase,
6-
snakeCase,
7-
} from './utils/change-case';
1+
import { camelCase, constantCase, kebabCase, pascalCase, snakeCase } from './utils/change-case';
82
import { deepMerge } from './utils/deepmerge.utils';
93
import { Passthrough, WithPassthrough } from './utils/types';
104

@@ -58,10 +52,7 @@ export abstract class BaseProvider {
5852
T_Output = Record<string, unknown>,
5953
T_Input = Record<string, unknown>,
6054
T_Data = Record<string, unknown>,
61-
>(
62-
bridgeProviderData: WithPassthrough<T_Input>,
63-
triggerProviderData: T_Data,
64-
): MergedPassthrough<T_Output> {
55+
>(bridgeProviderData: WithPassthrough<T_Input>, triggerProviderData: T_Data): MergedPassthrough<T_Output> {
6556
const { _passthrough = {}, ...bridgeData } = bridgeProviderData;
6657

6758
// Construct the trigger data passthrough object
@@ -114,9 +105,7 @@ export abstract class BaseProvider {
114105
* @param data The data to transform.
115106
* @returns The transformed data, with the keys transformed to the desired casing.
116107
*/
117-
private casingTransform(
118-
data: Record<string, unknown>,
119-
): Record<string, unknown> {
108+
private casingTransform(data: Record<string, unknown>): Record<string, unknown> {
120109
let casing = camelCase;
121110

122111
switch (this.casing) {

packages/providers/src/lib/chat/discord/discord.provider.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test('should trigger Discord provider correctly with _passthrough', async () =>
4444
content: 'passthrough content',
4545
},
4646
},
47-
},
47+
}
4848
);
4949

5050
expect(mockPost).toHaveBeenCalledWith('https://www.google.com/?wait=true', {

packages/providers/src/lib/chat/discord/discord.provider.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { ChatProviderIdEnum } from '@novu/shared';
2-
import {
3-
ChannelTypeEnum,
4-
IChatOptions,
5-
IChatProvider,
6-
ISendMessageSuccessResponse,
7-
} from '@novu/stateless';
2+
import { ChannelTypeEnum, IChatOptions, IChatProvider, ISendMessageSuccessResponse } from '@novu/stateless';
83
import axios from 'axios';
94
import { BaseProvider, CasingEnum } from '../../../base.provider';
105
import { WithPassthrough } from '../../../utils/types';
@@ -21,7 +16,7 @@ export class DiscordProvider extends BaseProvider implements IChatProvider {
2116

2217
async sendMessage(
2318
data: IChatOptions,
24-
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {},
19+
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {}
2520
): Promise<ISendMessageSuccessResponse> {
2621
// Setting the wait parameter with the URL API to respect user parameters
2722
const url = new URL(data.webhookUrl);
@@ -31,7 +26,7 @@ export class DiscordProvider extends BaseProvider implements IChatProvider {
3126
this.transform(bridgeProviderData, {
3227
content: data.content,
3328
...(data.customData || {}),
34-
}).body,
29+
}).body
3530
);
3631

3732
return {

packages/providers/src/lib/chat/getstream/getstream.provider.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test('should trigger getstream correctly with _passthrough', async () => {
5050
'X-API-KEY': 'test1',
5151
},
5252
},
53-
},
53+
}
5454
);
5555

5656
expect(mockPost).toHaveBeenCalledWith('https://www.google.com/', {

packages/providers/src/lib/chat/getstream/getstream.provider.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import { ChatProviderIdEnum } from '@novu/shared';
2-
import {
3-
ChannelTypeEnum,
4-
ISendMessageSuccessResponse,
5-
IChatOptions,
6-
IChatProvider,
7-
} from '@novu/stateless';
2+
import { ChannelTypeEnum, ISendMessageSuccessResponse, IChatOptions, IChatProvider } from '@novu/stateless';
83
import axios from 'axios';
94
import { BaseProvider, CasingEnum } from '../../../base.provider';
105
import { WithPassthrough } from '../../../utils/types';
116

12-
export class GetstreamChatProvider
13-
extends BaseProvider
14-
implements IChatProvider
15-
{
7+
export class GetstreamChatProvider extends BaseProvider implements IChatProvider {
168
id = ChatProviderIdEnum.GetStream;
179
channelType = ChannelTypeEnum.CHAT as ChannelTypeEnum.CHAT;
1810
protected casing = CasingEnum.SNAKE_CASE;
@@ -21,15 +13,15 @@ export class GetstreamChatProvider
2113
constructor(
2214
private config: {
2315
apiKey: string;
24-
},
16+
}
2517
) {
2618
super();
2719
this.config = config;
2820
}
2921

3022
async sendMessage(
3123
data: IChatOptions,
32-
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {},
24+
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {}
3325
): Promise<ISendMessageSuccessResponse> {
3426
const transformedData = this.transform(bridgeProviderData, {
3527
text: data.content,

packages/providers/src/lib/chat/grafana-on-call/grafana-on-call.provider.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('should trigger grafana-on-call library correctly', async () => {
3535
title: 'title',
3636
message: testContent,
3737
},
38-
undefined,
38+
undefined
3939
);
4040
expect(res).toEqual({ id: expect.any(String), date: date.toISOString() });
4141
});
@@ -71,7 +71,7 @@ test('should trigger grafana-on-call library correctly with _passthrough', async
7171
'Content-Type': 'application/json',
7272
},
7373
},
74-
},
74+
}
7575
);
7676

7777
expect(mockPost).toHaveBeenCalled();
@@ -89,7 +89,7 @@ test('should trigger grafana-on-call library correctly with _passthrough', async
8989
headers: {
9090
'Content-Type': 'application/json',
9191
},
92-
},
92+
}
9393
);
9494
expect(res).toEqual({ id: expect.any(String), date: date.toISOString() });
9595
});

packages/providers/src/lib/chat/grafana-on-call/grafana-on-call.provider.ts

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import { ChatProviderIdEnum } from '@novu/shared';
2-
import {
3-
ChannelTypeEnum,
4-
ISendMessageSuccessResponse,
5-
IChatOptions,
6-
IChatProvider,
7-
} from '@novu/stateless';
2+
import { ChannelTypeEnum, ISendMessageSuccessResponse, IChatOptions, IChatProvider } from '@novu/stateless';
83
import axios from 'axios';
94
import { v4 as uuid } from 'uuid';
105
import { BaseProvider, CasingEnum } from '../../../base.provider';
116
import { WithPassthrough } from '../../../utils/types';
127

13-
export class GrafanaOnCallChatProvider
14-
extends BaseProvider
15-
implements IChatProvider
16-
{
8+
export class GrafanaOnCallChatProvider extends BaseProvider implements IChatProvider {
179
id = ChatProviderIdEnum.GrafanaOnCall;
1810
channelType = ChannelTypeEnum.CHAT as ChannelTypeEnum.CHAT;
1911
protected casing = CasingEnum.SNAKE_CASE;
@@ -25,14 +17,14 @@ export class GrafanaOnCallChatProvider
2517
imageUrl?: string;
2618
state?: string;
2719
externalLink?: string;
28-
},
20+
}
2921
) {
3022
super();
3123
}
3224

3325
async sendMessage(
3426
options: IChatOptions,
35-
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {},
27+
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {}
3628
): Promise<ISendMessageSuccessResponse> {
3729
const url = new URL(options.webhookUrl);
3830
const data = this.transform(bridgeProviderData, {
@@ -54,7 +46,7 @@ export class GrafanaOnCallChatProvider
5446
? {
5547
headers: data.headers as Record<string, string>,
5648
}
57-
: undefined,
49+
: undefined
5850
);
5951

6052
return {

packages/providers/src/lib/chat/mattermost/mattermost.provider.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test('should trigger mattermost library correctly, default channel with _passthr
8585
text: '_passthrough content message',
8686
},
8787
},
88-
},
88+
}
8989
);
9090
expect(fakePostDefaultChannel).toHaveBeenCalled();
9191
expect(fakePostDefaultChannel).toHaveBeenCalledWith(testWebhookUrl, {

packages/providers/src/lib/chat/mattermost/mattermost.provider.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import axios from 'axios';
2-
import {
3-
ChannelTypeEnum,
4-
ISendMessageSuccessResponse,
5-
IChatOptions,
6-
IChatProvider,
7-
} from '@novu/stateless';
2+
import { ChannelTypeEnum, ISendMessageSuccessResponse, IChatOptions, IChatProvider } from '@novu/stateless';
83
import { ChatProviderIdEnum } from '@novu/shared';
94
import { BaseProvider, CasingEnum } from '../../../base.provider';
105
import { WithPassthrough } from '../../../utils/types';
@@ -22,17 +17,14 @@ export class MattermostProvider extends BaseProvider implements IChatProvider {
2217

2318
async sendMessage(
2419
data: IChatOptions,
25-
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {},
20+
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {}
2621
): Promise<ISendMessageSuccessResponse> {
2722
const payload: IMattermostPayload = { text: data.content };
2823

2924
if (data.channel) {
3025
payload.channel = data.channel;
3126
}
32-
const response = await this.axiosInstance.post(
33-
data.webhookUrl,
34-
this.transform(bridgeProviderData, payload).body,
35-
);
27+
const response = await this.axiosInstance.post(data.webhookUrl, this.transform(bridgeProviderData, payload).body);
3628

3729
return {
3830
id: response.headers['x-request-id'],

packages/providers/src/lib/chat/msTeams/msTeams.provider.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test('should trigger msTeams webhook correctly with _passthrough', async () => {
4343
title: '_passthrough test title',
4444
},
4545
},
46-
},
46+
}
4747
);
4848

4949
expect(fakePost).toHaveBeenCalled();

packages/providers/src/lib/chat/msTeams/msTeams.provider.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { ChatProviderIdEnum } from '@novu/shared';
2-
import {
3-
ChannelTypeEnum,
4-
ISendMessageSuccessResponse,
5-
IChatOptions,
6-
IChatProvider,
7-
} from '@novu/stateless';
2+
import { ChannelTypeEnum, ISendMessageSuccessResponse, IChatOptions, IChatProvider } from '@novu/stateless';
83
import axios from 'axios';
94
import { BaseProvider, CasingEnum } from '../../../base.provider';
105
import { WithPassthrough } from '../../../utils/types';
@@ -21,7 +16,7 @@ export class MsTeamsProvider extends BaseProvider implements IChatProvider {
2116

2217
async sendMessage(
2318
data: IChatOptions,
24-
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {},
19+
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {}
2520
): Promise<ISendMessageSuccessResponse> {
2621
let payload;
2722

packages/providers/src/lib/chat/rocket-chat/rocket-chat.provider.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test('should trigger rocket-chat library correctly', async () => {
3737
'x-auth-token': '<your-auth-token>',
3838
'x-user-id': '<your-user>',
3939
},
40-
},
40+
}
4141
);
4242
});
4343

@@ -73,7 +73,7 @@ test('should trigger rocket-chat library correctly with _passthrough', async ()
7373
'x-auth-token': '_passthrough',
7474
},
7575
},
76-
},
76+
}
7777
);
7878

7979
expect(mockPost).toHaveBeenCalledWith(
@@ -90,6 +90,6 @@ test('should trigger rocket-chat library correctly with _passthrough', async ()
9090
'x-auth-token': '_passthrough',
9191
'x-user-id': '<your-user>',
9292
},
93-
},
93+
}
9494
);
9595
});

0 commit comments

Comments
 (0)