@remit/data-ports 0.0.86 → 0.0.88

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.
@@ -0,0 +1,11 @@
1
+ import type { AccountConfigItem, CreateAccountConfigInput } from "./types.js";
2
+ export interface AccountConfigCreator {
3
+ get: (accountConfigId: string) => Promise<AccountConfigItem>;
4
+ create: (input: CreateAccountConfigInput) => Promise<AccountConfigItem>;
5
+ }
6
+ /**
7
+ * The one way an AccountConfig row comes into being. Its id is derived from the
8
+ * caller's identity, so the row is its own owner: `userId` is the id itself,
9
+ * whichever path materializes it first.
10
+ */
11
+ export declare const ensureAccountConfig: (accountConfig: AccountConfigCreator, accountConfigId: string) => Promise<AccountConfigItem>;
@@ -0,0 +1,24 @@
1
+ import { ConflictError, NotFoundError } from "./errors.js";
2
+ /**
3
+ * The one way an AccountConfig row comes into being. Its id is derived from the
4
+ * caller's identity, so the row is its own owner: `userId` is the id itself,
5
+ * whichever path materializes it first.
6
+ */
7
+ export const ensureAccountConfig = async (accountConfig, accountConfigId) => {
8
+ const existing = await accountConfig
9
+ .get(accountConfigId)
10
+ .catch((err) => {
11
+ if (err instanceof NotFoundError)
12
+ return undefined;
13
+ throw err;
14
+ });
15
+ if (existing)
16
+ return existing;
17
+ return accountConfig
18
+ .create({ accountConfigId, userId: accountConfigId })
19
+ .catch((err) => {
20
+ if (err instanceof ConflictError)
21
+ return accountConfig.get(accountConfigId);
22
+ throw err;
23
+ });
24
+ };
package/dist/errors.d.ts CHANGED
@@ -108,6 +108,17 @@ export declare class UnrecoverableBodyError extends HTTPError {
108
108
  name: string;
109
109
  statusCode: number;
110
110
  }
111
+ /**
112
+ * The host refused the work because a quota or platform limit was reached. The
113
+ * host decides what counts: its port adapters translate their platform's limit
114
+ * errors into this one, so the shared mapping answers 429 without reading a
115
+ * message. The message is the host's, written for the person who hit the limit.
116
+ */
117
+ export declare class HostRefusedError extends HTTPError {
118
+ name: string;
119
+ statusCode: number;
120
+ constructor(message: string, cause: unknown);
121
+ }
111
122
  export declare class CreateFailedConflictError extends ConflictError {
112
123
  statusCode: number;
113
124
  name: string;
package/dist/errors.js CHANGED
@@ -124,6 +124,20 @@ export class UnrecoverableBodyError extends HTTPError {
124
124
  name = "UnrecoverableBodyError";
125
125
  statusCode = 422;
126
126
  }
127
+ /**
128
+ * The host refused the work because a quota or platform limit was reached. The
129
+ * host decides what counts: its port adapters translate their platform's limit
130
+ * errors into this one, so the shared mapping answers 429 without reading a
131
+ * message. The message is the host's, written for the person who hit the limit.
132
+ */
133
+ export class HostRefusedError extends HTTPError {
134
+ name = "HostRefusedError";
135
+ statusCode = 429;
136
+ constructor(message, cause) {
137
+ super(message, { cause });
138
+ this.publicApiError = { code: "request_refused" };
139
+ }
140
+ }
127
141
  export class CreateFailedConflictError extends ConflictError {
128
142
  statusCode = 409;
129
143
  name = "CreateFailedConflictError";
package/dist/index.d.ts CHANGED
@@ -29,7 +29,7 @@ export { holdsRoom } from "./interfaces/outbox-attachment.js";
29
29
  export type { IOutboxMessageRepository } from "./interfaces/outbox-message.js";
30
30
  export { APPENDED_UID_NONE, APPENDED_UID_UNREPORTED, isSentCopyFiled, } from "./interfaces/outbox-message.js";
31
31
  export type { IQuarantineRepository } from "./interfaces/quarantine.js";
32
- export { type FifoQueueMessage, type FifoQueueProducer, type GroupedQueueMessage, type GroupedQueueProducer, QUEUE_BATCH_LIMIT, type QueueBatchResult, type QueueMessage, type QueueProducer, } from "./interfaces/queue.js";
32
+ export { type FifoQueueMessage, type FifoQueueProducer, type GroupedQueueMessage, type GroupedQueueProducer, QUEUE_BATCH_LIMIT, type QueueBatchResult, type QueueKind, type QueueMessage, type QueueProducer, type QueueProducerOf, } from "./interfaces/queue.js";
33
33
  export type { ISenderSignerStandingRepository } from "./interfaces/sender-signer-standing.js";
34
34
  export type { ISyncWarningRepository, SurfacedSyncWarnings, } from "./interfaces/sync-warning.js";
35
35
  export type { IThreadMessageRepository } from "./interfaces/thread-message.js";
@@ -48,7 +48,7 @@ export interface IOutboxMessageRepository {
48
48
  updateIfStatus(accountConfigId: string, outboxMessageId: string, expected: OutboxMessageItem["status"], input: UpdateOutboxMessageInput): Promise<OutboxMessageItem | null>;
49
49
  markSent(accountConfigId: string, outboxMessageId: string, fields: {
50
50
  sentAt: number;
51
- smtpMessageId?: string;
51
+ smtpMessageId?: string | undefined;
52
52
  }): Promise<OutboxMessageItem>;
53
53
  delete(accountConfigId: string, outboxMessageId: string): Promise<void>;
54
54
  deleteMany(accountConfigId: string, outboxMessageIds: string[]): Promise<void>;
@@ -1,6 +1,5 @@
1
1
  export interface QueueMessage<T> {
2
2
  readonly body: T;
3
- readonly delaySeconds?: number;
4
3
  }
5
4
  export interface GroupedQueueMessage<T> extends QueueMessage<T> {
6
5
  readonly groupId: string;
@@ -12,9 +11,12 @@ export interface QueueBatchResult {
12
11
  readonly refused: ReadonlySet<number>;
13
12
  }
14
13
  export declare const QUEUE_BATCH_LIMIT = 10;
15
- export interface QueueProducer<T, M extends QueueMessage<T> = QueueMessage<T>> {
14
+ export type QueueKind = "Standard" | "Grouped" | "Fifo";
15
+ export interface QueueProducerOf<K extends QueueKind, M> {
16
+ readonly kind: K;
16
17
  readonly send: (message: M) => Promise<void>;
17
18
  readonly sendBatch: (messages: readonly M[]) => Promise<QueueBatchResult>;
18
19
  }
19
- export type FifoQueueProducer<T> = QueueProducer<T, FifoQueueMessage<T>>;
20
- export type GroupedQueueProducer<T> = QueueProducer<T, GroupedQueueMessage<T>>;
20
+ export type QueueProducer<T> = QueueProducerOf<"Standard", QueueMessage<T>>;
21
+ export type GroupedQueueProducer<T> = QueueProducerOf<"Grouped", GroupedQueueMessage<T>>;
22
+ export type FifoQueueProducer<T> = QueueProducerOf<"Fifo", FifoQueueMessage<T>>;
@@ -1,10 +1,12 @@
1
- import type { QueueProducer } from "./interfaces/queue.js";
1
+ import type { FifoQueueProducer, GroupedQueueProducer, QueueProducer } from "./interfaces/queue.js";
2
2
  export interface RecordedMessage {
3
3
  body: Record<string, unknown>;
4
4
  groupId: string | undefined;
5
5
  deduplicationId: string | undefined;
6
6
  }
7
7
  export interface RecordingQueue extends QueueProducer<unknown> {
8
+ readonly fifo: FifoQueueProducer<unknown>;
9
+ readonly grouped: GroupedQueueProducer<unknown>;
8
10
  readonly sent: RecordedMessage[];
9
11
  readonly answer: (next: () => Promise<unknown>) => void;
10
12
  readonly refuse: (positions: readonly number[]) => void;
@@ -17,7 +17,19 @@ export const recordingQueue = () => {
17
17
  const sent = [];
18
18
  let answer = async () => ({});
19
19
  let refused = new Set();
20
+ const send = async (message) => {
21
+ sent.push(recorded(message));
22
+ await answer();
23
+ };
24
+ const sendBatch = async (messages) => {
25
+ sent.push(...messages.map(recorded));
26
+ await answer();
27
+ return { refused };
28
+ };
20
29
  return {
30
+ kind: "Standard",
31
+ fifo: { kind: "Fifo", send, sendBatch },
32
+ grouped: { kind: "Grouped", send, sendBatch },
21
33
  sent,
22
34
  answer: (next) => {
23
35
  answer = next;
@@ -25,15 +37,8 @@ export const recordingQueue = () => {
25
37
  refuse: (positions) => {
26
38
  refused = new Set(positions);
27
39
  },
28
- send: async (message) => {
29
- sent.push(recorded(message));
30
- await answer();
31
- },
32
- sendBatch: async (messages) => {
33
- sent.push(...messages.map(recorded));
34
- await answer();
35
- return { refused };
36
- },
40
+ send,
41
+ sendBatch,
37
42
  };
38
43
  };
39
44
  export const failingQueue = (error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/data-ports",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",