Skip to content

Commit 1b08b97

Browse files
committed
wip
1 parent 1149a32 commit 1b08b97

File tree

12 files changed

+147
-103
lines changed

12 files changed

+147
-103
lines changed

packages/api-workflows/src/domain/notifications/abstractions.ts

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,108 @@
11
import { createAbstraction } from "@webiny/feature/api";
22

3-
export interface INotificationTypeMessage {
4-
title: string;
5-
body: string;
6-
url: string;
3+
export interface INotificationMessageTitleParams {
4+
id: string;
5+
entryTitle: string;
76
}
87

9-
export const NotificationTypeMessageOnRequestReview = createAbstraction<INotificationTypeMessage>(
10-
"WorkflowNotificationTypeMessageOnRequestReview"
8+
export interface INotificationMessageBodyParams {
9+
id: string;
10+
entryTitle: string;
11+
}
12+
13+
export interface INotificationMessageUrlParams {
14+
id: string;
15+
entryTitle: string;
16+
}
17+
18+
export interface INotificationMessage {
19+
getTitle(params: INotificationMessageTitleParams): string;
20+
getBody(params: INotificationMessageBodyParams): string;
21+
getUrl(params: INotificationMessageUrlParams): string;
22+
}
23+
24+
export const NotificationReviewRequestMessage = createAbstraction<INotificationMessage>(
25+
"WorkflowNotificationReviewRequestMessage"
1126
);
1227

13-
export namespace NotificationTypeMessageOnRequestReview {
14-
export type Interface = INotificationTypeMessage;
28+
export namespace NotificationReviewRequestMessage {
29+
export type Interface = INotificationMessage;
1530
}
1631

17-
export const NotificationTypeMessageOnRequestReviewCancel =
18-
createAbstraction<INotificationTypeMessage>(
19-
"WorkflowNotificationTypeMessageOnRequestReviewCancel"
20-
);
32+
export const NotificationReviewCancelMessage = createAbstraction<INotificationMessage>(
33+
"WorkflowNotificationReviewCancelMessage"
34+
);
2135

22-
export namespace NotificationTypeMessageOnRequestReviewCancel {
23-
export type Interface = INotificationTypeMessage;
36+
export namespace NotificationReviewCancelMessage {
37+
export type Interface = INotificationMessage;
2438
}
2539

26-
export const NotificationTypeMessageOnReviewStepStart = createAbstraction<INotificationTypeMessage>(
27-
"WorkflowNotificationTypeMessageOnReviewStepStart"
40+
export const NotificationReviewStepStartMessage = createAbstraction<INotificationMessage>(
41+
"WorkflowNotificationReviewStepStartMessage"
2842
);
2943

30-
export namespace NotificationTypeMessageOnReviewStepStart {
31-
export type Interface = INotificationTypeMessage;
44+
export namespace NotificationReviewStepStartMessage {
45+
export type Interface = INotificationMessage;
3246
}
3347

34-
export const NotificationTypeMessageOnReviewStepApprove =
35-
createAbstraction<INotificationTypeMessage>(
36-
"WorkflowNotificationTypeMessageOnReviewStepApprove"
37-
);
48+
export const NotificationReviewStepApproveMessage = createAbstraction<INotificationMessage>(
49+
"WorkflowNotificationReviewStepApproveMessage"
50+
);
3851

39-
export namespace NotificationTypeMessageOnReviewStepApprove {
40-
export type Interface = INotificationTypeMessage;
52+
export namespace NotificationReviewStepApproveMessage {
53+
export type Interface = INotificationMessage;
4154
}
4255

43-
export const NotificationTypeMessageOnReviewReject = createAbstraction<INotificationTypeMessage>(
44-
"WorkflowNotificationTypeMessageOnReviewReject"
56+
export const NotificationReviewRejectMessage = createAbstraction<INotificationMessage>(
57+
"WorkflowNotificationReviewRejectMessage"
4558
);
4659

47-
export namespace NotificationTypeMessageOnReviewReject {
48-
export type Interface = INotificationTypeMessage;
60+
export namespace NotificationReviewRejectMessage {
61+
export type Interface = INotificationMessage;
4962
}
5063

51-
export const NotificationTypeMessageOnReviewApprove = createAbstraction<INotificationTypeMessage>(
52-
"WorkflowNotificationTypeMessageOnReviewApprove"
64+
export const NotificationReviewApproveMessage = createAbstraction<INotificationMessage>(
65+
"WorkflowNotificationReviewApproveMessage"
5366
);
5467

55-
export namespace NotificationTypeMessageOnReviewApprove {
56-
export type Interface = INotificationTypeMessage;
68+
export namespace NotificationReviewApproveMessage {
69+
export type Interface = INotificationMessage;
5770
}
5871

59-
export type INotificationTypes =
60-
| NotificationTypeMessageOnRequestReview.Interface
61-
| NotificationTypeMessageOnRequestReviewCancel.Interface
62-
| NotificationTypeMessageOnReviewStepStart.Interface
63-
| NotificationTypeMessageOnReviewStepApprove.Interface
64-
| NotificationTypeMessageOnReviewReject.Interface
65-
| NotificationTypeMessageOnReviewApprove.Interface;
72+
export type INotificationMessages =
73+
| NotificationReviewRequestMessage.Interface
74+
| NotificationReviewCancelMessage.Interface
75+
| NotificationReviewStepStartMessage.Interface
76+
| NotificationReviewStepApproveMessage.Interface
77+
| NotificationReviewRejectMessage.Interface
78+
| NotificationReviewApproveMessage.Interface;
79+
6680

6781
export interface INotificationTypeMessages {
6882
/**
6983
* User requests a review for a content.
7084
*/
71-
onRequestReview: NotificationTypeMessageOnRequestReview.Interface;
85+
reviewRequest: NotificationReviewRequestMessage.Interface;
7286
/**
7387
* User cancels a review for a content.
7488
*/
75-
onRequestReviewCancel: NotificationTypeMessageOnRequestReviewCancel.Interface;
89+
reviewCancel: NotificationReviewCancelMessage.Interface;
7690
/**
7791
* Reviewer starts a review step.
7892
*/
79-
onReviewStepStart: NotificationTypeMessageOnReviewStepStart.Interface;
93+
reviewStepStart: NotificationReviewStepStartMessage.Interface;
8094
/**
8195
* Reviewer approves a review step - there are more steps after this one.
8296
*/
83-
onReviewStepApprove: NotificationTypeMessageOnReviewStepApprove.Interface;
97+
reviewStepApprove: NotificationReviewStepApproveMessage.Interface;
8498
/**
8599
* Reviewer rejects a review - no step specific reject because as soon as step is rejected, whole review is rejected.
86100
*/
87-
onReviewReject: NotificationTypeMessageOnReviewReject.Interface;
101+
reviewReject: NotificationReviewRejectMessage.Interface;
88102
/**
89103
* Reviewer approves a final review step.
90104
*/
91-
onReviewApprove: NotificationTypeMessageOnReviewApprove.Interface;
105+
reviewApprove: NotificationReviewApproveMessage.Interface;
92106
}
93107

94108
export interface INotificationType {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
type INotificationMessageBodyParams,
3+
type INotificationMessageTitleParams,
4+
type INotificationMessageUrlParams,
5+
NotificationReviewRequestMessage as NotificationMessage
6+
} from "~/domain/notifications/abstractions.js";
7+
8+
class NotificationReviewRequestMessageImpl implements NotificationMessage.Interface {
9+
public getBody(params: INotificationMessageBodyParams): string {
10+
return "";
11+
}
12+
13+
public getTitle(params: INotificationMessageTitleParams): string {
14+
return "";
15+
}
16+
17+
public getUrl(params: INotificationMessageUrlParams): string {
18+
return "";
19+
}
20+
}
21+
22+
export const NotificationReviewRequestMessage = NotificationMessage.createImplementation({
23+
implementation: NotificationReviewRequestMessageImpl,
24+
dependencies: []
25+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./NotificationMessageOnRequestReview.js";

packages/api-workflows/src/features/notifications/ListNotificationTypes/ListNotificationTypesRepository.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Result } from "@webiny/feature/api";
22
import { ListNotificationTypesRepository as Repository } from "./abstractions.js";
3-
import { NotificationTransport } from "~/features/notifications/NotificationTransport/index.js";
3+
import { NotificationAdapter } from "../NotificationAdapter/index.js";
44

55
class ListNotificationTypesRepositoryImpl implements Repository.Interface {
66
private readonly types;
77

8-
public constructor(types: NotificationTransport.Interface[]) {
8+
public constructor(types: NotificationAdapter.Interface[]) {
99
this.types = types;
1010
}
1111

@@ -23,5 +23,5 @@ class ListNotificationTypesRepositoryImpl implements Repository.Interface {
2323

2424
export const ListNotificationTypesRepository = Repository.createImplementation({
2525
implementation: ListNotificationTypesRepositoryImpl,
26-
dependencies: [[NotificationTransport, { multiple: true }]]
26+
dependencies: [[NotificationAdapter, { multiple: true }]]
2727
});

packages/api-workflows/src/features/notifications/NotificationTransport/MailNotificationTransport.ts renamed to packages/api-workflows/src/features/notifications/NotificationAdapter/MailNotificationAdapter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { MailerService } from "@webiny/api-mailer";
2-
import { NotificationTransport } from "./abstractions.js";
2+
import { NotificationAdapter } from "./abstractions.js";
33

4-
class MailNotificationTransportImpl implements NotificationTransport.Interface {
4+
class MailNotificationAdapterImpl implements NotificationAdapter.Interface {
55
public readonly id = "e-mail";
66
public readonly title = "E-Mail";
77

@@ -11,7 +11,7 @@ class MailNotificationTransportImpl implements NotificationTransport.Interface {
1111
this.mailer = mailer;
1212
}
1313

14-
public async send(params: NotificationTransport.SendParams): Promise<void> {
14+
public async send(params: NotificationAdapter.SendParams): Promise<void> {
1515
const { users, message } = params;
1616

1717
const bcc = users
@@ -47,7 +47,7 @@ class MailNotificationTransportImpl implements NotificationTransport.Interface {
4747
}
4848
}
4949

50-
export const MailNotificationTransport = NotificationTransport.createImplementation({
51-
implementation: MailNotificationTransportImpl,
50+
export const MailNotificationAdapter = NotificationAdapter.createImplementation({
51+
implementation: MailNotificationAdapterImpl,
5252
dependencies: [MailerService]
5353
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { createAbstraction } from "@webiny/feature/api";
2+
import type { INotificationTypeMessages } from "~/domain/notifications/abstractions.js";
3+
import type { NonEmptyArray } from "@webiny/api/types.js";
4+
5+
export interface INotificationAdapterUser {
6+
id: string;
7+
email: string;
8+
displayName: string;
9+
}
10+
11+
export interface INotificationAdapterMessage {
12+
type: keyof INotificationTypeMessages;
13+
title: string;
14+
url: string;
15+
body: string;
16+
}
17+
18+
export interface INotificationAdapterSendParams {
19+
users: NonEmptyArray<INotificationAdapterUser>;
20+
message: INotificationAdapterMessage;
21+
}
22+
23+
export interface INotificationAdapter {
24+
id: string;
25+
title: string;
26+
send(params: INotificationAdapterSendParams): Promise<void>;
27+
}
28+
29+
export const NotificationAdapter = createAbstraction<INotificationAdapter>(
30+
"WorkflowNotificationAdapter"
31+
);
32+
33+
export namespace NotificationAdapter {
34+
export type Interface = INotificationAdapter;
35+
export type SendParams = INotificationAdapterSendParams;
36+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createFeature } from "@webiny/feature/api";
2+
import { MailNotificationAdapter } from "./MailNotificationAdapter.js";
3+
4+
export const NotificationAdapterFeature = createFeature({
5+
name: "WorkflowNotifications/NotificationAdapter",
6+
register(container) {
7+
container.register(MailNotificationAdapter);
8+
}
9+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export { NotificationAdapterFeature } from "./feature.js";
2+
export { NotificationAdapter } from "./abstractions.js";
3+
export type {
4+
INotificationAdapterSendParams,
5+
INotificationAdapter,
6+
INotificationAdapterUser
7+
} from "./abstractions.js";

packages/api-workflows/src/features/notifications/NotificationTransport/abstractions.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/api-workflows/src/features/notifications/NotificationTransport/feature.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)