@remit/mailbox-service 0.0.44 → 0.0.45

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/outbox-queue.ts +14 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/mailbox-service",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -5,6 +5,7 @@ import type {
5
5
  IOutboxMessageRepository,
6
6
  OutboxMessageItem,
7
7
  } from "@remit/data-ports";
8
+ import { ConflictError } from "@remit/data-ports/errors";
8
9
  import { OutboxMessageStatus } from "@remit/domain-enums";
9
10
  import { createQueueProducer } from "@remit/sqs-client/producer";
10
11
 
@@ -31,6 +32,7 @@ export interface OutboxQueueConfig {
31
32
  accountService: IAccountRepository;
32
33
  sqsSmtpQueueUrl: string;
33
34
  sqsEndpoint?: string;
35
+ sqsClient?: SQSClient;
34
36
  logger?: OutboxQueueLogger;
35
37
  }
36
38
 
@@ -91,10 +93,12 @@ export class OutboxQueueService {
91
93
  this.queueUrl = sqsSmtpQueueUrl;
92
94
  this.log = config.logger ?? noopLogger;
93
95
 
94
- this.sqs = createQueueProducer({
95
- queueUrl: sqsSmtpQueueUrl,
96
- endpoint: sqsEndpoint,
97
- });
96
+ this.sqs =
97
+ config.sqsClient ??
98
+ createQueueProducer({
99
+ queueUrl: sqsSmtpQueueUrl,
100
+ endpoint: sqsEndpoint,
101
+ });
98
102
  }
99
103
 
100
104
  createDraft = async (input: CreateDraftInput): Promise<OutboxMessageItem> => {
@@ -137,8 +141,8 @@ export class OutboxQueueService {
137
141
  "act",
138
142
  );
139
143
  if (existing.status !== OutboxMessageStatus.draft) {
140
- throw new Error(
141
- `Cannot update outbox message with status: ${existing.status}`,
144
+ throw new ConflictError(
145
+ `This message is already ${existing.status} and can no longer be edited as a draft. Start a new message to change it.`,
142
146
  );
143
147
  }
144
148
 
@@ -184,8 +188,8 @@ export class OutboxQueueService {
184
188
  existing.status !== OutboxMessageStatus.failed &&
185
189
  existing.status !== OutboxMessageStatus.blocked
186
190
  ) {
187
- throw new Error(
188
- `Cannot send outbox message with status: ${existing.status}`,
191
+ throw new ConflictError(
192
+ `This message is already ${existing.status} and cannot be sent again. Open the Outbox to see where it stands.`,
189
193
  );
190
194
  }
191
195
 
@@ -252,8 +256,8 @@ export class OutboxQueueService {
252
256
  existing.status !== OutboxMessageStatus.failed &&
253
257
  existing.status !== OutboxMessageStatus.blocked
254
258
  ) {
255
- throw new Error(
256
- `Cannot delete outbox message with status: ${existing.status}`,
259
+ throw new ConflictError(
260
+ `This message is already ${existing.status} and can no longer be discarded. Open the Outbox to see where it stands.`,
257
261
  );
258
262
  }
259
263