Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions packages/api-workflows/src/domain/notification/abstractions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import { createAbstraction } from "@webiny/feature/api";
import type { NonEmptyArray } from "@webiny/api/types.js";

/**
* Notification Message
*/
export interface INotificationMessageTitleParams {
id: string;
entryTitle: string;
}

export interface INotificationMessageBodyParams {
id: string;
entryTitle: string;
}

export interface INotificationMessageUrlParams {
id: string;
entryTitle: string;
}

export interface INotificationMessage {
getTitle(params: INotificationMessageTitleParams): string;
getBody(params: INotificationMessageBodyParams): string;
getUrl(params: INotificationMessageUrlParams): string;
}

export const NotificationReviewRequestMessage = createAbstraction<INotificationMessage>(
"WorkflowNotificationReviewRequestMessage"
);

export namespace NotificationReviewRequestMessage {
export type Interface = INotificationMessage;
}

export const NotificationReviewCancelMessage = createAbstraction<INotificationMessage>(
"WorkflowNotificationReviewCancelMessage"
);

export namespace NotificationReviewCancelMessage {
export type Interface = INotificationMessage;
}

export const NotificationReviewStepStartMessage = createAbstraction<INotificationMessage>(
"WorkflowNotificationReviewStepStartMessage"
);

export namespace NotificationReviewStepStartMessage {
export type Interface = INotificationMessage;
}

export const NotificationReviewStepApproveMessage = createAbstraction<INotificationMessage>(
"WorkflowNotificationReviewStepApproveMessage"
);

export namespace NotificationReviewStepApproveMessage {
export type Interface = INotificationMessage;
}

export const NotificationReviewRejectMessage = createAbstraction<INotificationMessage>(
"WorkflowNotificationReviewRejectMessage"
);

export namespace NotificationReviewRejectMessage {
export type Interface = INotificationMessage;
}

export const NotificationReviewApproveMessage = createAbstraction<INotificationMessage>(
"WorkflowNotificationReviewApproveMessage"
);

export namespace NotificationReviewApproveMessage {
export type Interface = INotificationMessage;
}

export type INotificationMessages =
| NotificationReviewRequestMessage.Interface
| NotificationReviewCancelMessage.Interface
| NotificationReviewStepStartMessage.Interface
| NotificationReviewStepApproveMessage.Interface
| NotificationReviewRejectMessage.Interface
| NotificationReviewApproveMessage.Interface;

export interface INotificationTypeMessages {
/**
* User requests a review for a content.
*/
reviewRequest: NotificationReviewRequestMessage.Interface;
/**
* User cancels a review for a content.
*/
reviewCancel: NotificationReviewCancelMessage.Interface;
/**
* Reviewer starts a review step.
*/
reviewStepStart: NotificationReviewStepStartMessage.Interface;
/**
* Reviewer approves a review step - there are more steps after this one.
*/
reviewStepApprove: NotificationReviewStepApproveMessage.Interface;
/**
* Reviewer rejects a review - no step specific reject because as soon as step is rejected, whole review is rejected.
*/
reviewReject: NotificationReviewRejectMessage.Interface;
/**
* Reviewer approves a final review step.
*/
reviewApprove: NotificationReviewApproveMessage.Interface;
}

/**
* Notification Type
*/
export interface INotificationType {
id: string;
title: string;
}

export const NotificationType = createAbstraction<INotificationType>("WorkflowNotificationType");

export namespace NotificationType {
export type Interface = INotificationType;
}

/**
* Notification Message Body Converter
*/
export interface INotificationMessageBodyConverter {
convert(body: string): string;
}

export const NotificationMessageBodyConverter =
createAbstraction<INotificationMessageBodyConverter>("NotificationMessageBodyConverter");

export namespace NotificationMessageBodyConverter {
export type Interface = INotificationMessageBodyConverter;
}

/**
* Notification Adapter
*/
export interface INotificationAdapterUser {
id: string;
email: string;
displayName: string;
}

export interface INotificationAdapterMessage {
type: keyof INotificationTypeMessages;
title: string;
url: string;
body: string;
}

export interface INotificationAdapterSendParams {
users: NonEmptyArray<INotificationAdapterUser>;
message: INotificationAdapterMessage;
}

export interface INotificationAdapter {
id: string;
title: string;
getMessageBodyConverter(): NotificationMessageBodyConverter.Interface | null;
send(params: INotificationAdapterSendParams): Promise<void>;
}

export const NotificationAdapter = createAbstraction<INotificationAdapter>(
"WorkflowNotificationAdapter"
);

export namespace NotificationAdapter {
export type Interface = INotificationAdapter;
export type Params = INotificationAdapterSendParams;
export type User = INotificationAdapterUser;
}

export namespace Notification {
export type Type = INotificationType;
export type Adapter = INotificationAdapter;
export type MessageBodyConverter = INotificationMessageBodyConverter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
type INotificationMessageBodyParams,
type INotificationMessageTitleParams,
type INotificationMessageUrlParams,
NotificationReviewRequestMessage as NotificationMessage
} from "../abstractions.js";

class NotificationReviewRequestMessageImpl implements NotificationMessage.Interface {
public getBody(params: INotificationMessageBodyParams): string {
return "";
}

public getTitle(params: INotificationMessageTitleParams): string {
return "";
}

public getUrl(params: INotificationMessageUrlParams): string {
return "";
}
}

export const NotificationReviewRequestMessage = NotificationMessage.createImplementation({
implementation: NotificationReviewRequestMessageImpl,
dependencies: []
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./NotificationMessageOnRequestReview.js";
103 changes: 0 additions & 103 deletions packages/api-workflows/src/domain/notifications/abstractions.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Result } from "@webiny/feature/api";
import { ListNotificationTypesRepository as Repository } from "./abstractions.js";
import { NotificationTransport } from "~/features/notifications/NotificationTransport/index.js";
import { NotificationAdapter } from "~/domain/notification/abstractions.js";

class ListNotificationTypesRepositoryImpl implements Repository.Interface {
private readonly types;

public constructor(types: NotificationTransport.Interface[]) {
public constructor(types: NotificationAdapter.Interface[]) {
this.types = types;
}

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

export const ListNotificationTypesRepository = Repository.createImplementation({
implementation: ListNotificationTypesRepositoryImpl,
dependencies: [[NotificationTransport, { multiple: true }]]
dependencies: [[NotificationAdapter, { multiple: true }]]
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { WORKFLOWS_PERMISSION } from "~/constants.js";
import type { IWorkflowsSecurityPermission } from "~/types.js";
import { WorkflowsSecurityPermissionAccessLevel } from "~/types.js";
import { NotificationAuthorizedError } from "~/domain/notifications/errors.js";
import { NotificationAuthorizedError } from "~/domain/notification/errors.js";

class ListNotificationTypesUseCaseImpl implements UseCase.Interface {
public constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Result } from "@webiny/feature/api";
import { createAbstraction } from "@webiny/feature/api";
import type { INotificationType } from "~/domain/notifications/abstractions.js";
import { NotificationAuthorizedError } from "~/domain/notifications/errors.js";
import type { INotificationType } from "~/domain/notification/abstractions.js";
import { NotificationAuthorizedError } from "~/domain/notification/errors.js";

/**
* ListNotificationTypes use case interface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MailerService } from "@webiny/api-mailer";
import { NotificationTransport } from "./abstractions.js";
import type { NotificationMessageBodyConverter } from "~/domain/notification/abstractions.js";
import { NotificationAdapter } from "~/domain/notification/abstractions.js";

class MailNotificationTransportImpl implements NotificationTransport.Interface {
class NotificationMailAdapterImpl implements NotificationAdapter.Interface {
public readonly id = "e-mail";
public readonly title = "E-Mail";

Expand All @@ -11,7 +12,11 @@ class MailNotificationTransportImpl implements NotificationTransport.Interface {
this.mailer = mailer;
}

public async send(params: NotificationTransport.SendParams): Promise<void> {
public getMessageBodyConverter(): NotificationMessageBodyConverter.Interface | null {
return null;
}

public async send(params: NotificationAdapter.Params): Promise<void> {
const { users, message } = params;

const bcc = users
Expand Down Expand Up @@ -47,7 +52,7 @@ class MailNotificationTransportImpl implements NotificationTransport.Interface {
}
}

export const MailNotificationTransport = NotificationTransport.createImplementation({
implementation: MailNotificationTransportImpl,
export const NotificationMailAdapter = NotificationAdapter.createImplementation({
implementation: NotificationMailAdapterImpl,
dependencies: [MailerService]
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createFeature } from "@webiny/feature/api";
import { NotificationMailAdapter } from "./NotificationMailAdapter.js";

export const NotificationMailAdapterFeature = createFeature({
name: "WorkflowNotifications/NotificationMailAdapter",
register(container) {
container.register(NotificationMailAdapter);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotificationMailAdapterFeature } from "./feature.js";
Loading
Loading