@upyo/mock 0.5.0-dev.86 → 0.5.0

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.
package/dist/index.cjs CHANGED
@@ -1,3 +1,27 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const __upyo_core = __toESM(require("@upyo/core"));
1
25
 
2
26
  //#region src/config.ts
3
27
  /**
@@ -24,7 +48,8 @@ function createMockConfig(config = {}) {
24
48
  return {
25
49
  defaultResponse: config.defaultResponse ?? {
26
50
  successful: true,
27
- messageId: "mock-message-id"
51
+ messageId: "mock-message-id",
52
+ provider: "mock"
28
53
  },
29
54
  delay: config.delay ?? 0,
30
55
  randomDelayRange: config.randomDelayRange ?? {
@@ -47,6 +72,7 @@ function createMockConfig(config = {}) {
47
72
  * behavior simulation, and async utilities.
48
73
  */
49
74
  var MockTransport = class {
75
+ id = "mock";
50
76
  /**
51
77
  * The resolved configuration used by this mock transport.
52
78
  */
@@ -315,19 +341,28 @@ var MockTransport = class {
315
341
  if (delayMs > 0) await new Promise((resolve) => setTimeout(resolve, delayMs));
316
342
  }
317
343
  getResponse() {
318
- if (this.config.failureRate > 0 && Math.random() < this.config.failureRate) return {
319
- successful: false,
320
- errorMessages: ["Simulated random failure"]
321
- };
344
+ if (this.config.failureRate > 0 && Math.random() < this.config.failureRate) return (0, __upyo_core.createFailedReceipt)("Simulated random failure", {
345
+ provider: "mock",
346
+ category: "unknown",
347
+ code: "mock.random_failure",
348
+ retryable: true,
349
+ attempts: 1
350
+ });
322
351
  if (this.nextResponse) {
323
352
  const response = this.nextResponse;
324
353
  this.nextResponse = null;
325
354
  return response;
326
355
  }
327
- if (this.config.defaultResponse.successful && this.config.generateUniqueMessageIds) return {
328
- successful: true,
329
- messageId: `mock-message-${this.messageIdCounter++}`
330
- };
356
+ if (this.config.defaultResponse.successful && this.config.generateUniqueMessageIds) {
357
+ const { attempts, timestamp } = this.config.defaultResponse;
358
+ return {
359
+ successful: true,
360
+ messageId: `mock-message-${this.messageIdCounter++}`,
361
+ provider: "mock",
362
+ ...attempts == null ? {} : { attempts },
363
+ ...timestamp == null ? {} : { timestamp }
364
+ };
365
+ }
331
366
  return this.config.defaultResponse;
332
367
  }
333
368
  };
package/dist/index.d.cts CHANGED
@@ -23,13 +23,7 @@ interface MockConfig {
23
23
  *
24
24
  * @default { successful: true, messageId: "mock-message-id" }
25
25
  */
26
- readonly defaultResponse?: {
27
- readonly successful: true;
28
- readonly messageId: string;
29
- } | {
30
- readonly successful: false;
31
- readonly errorMessages: readonly string[];
32
- };
26
+ readonly defaultResponse?: Receipt<"mock">;
33
27
  /**
34
28
  * Fixed delay in milliseconds for all send operations.
35
29
  *
@@ -95,7 +89,8 @@ type ResolvedMockConfig = Required<MockConfig>;
95
89
  * comprehensive testing capabilities including message verification,
96
90
  * behavior simulation, and async utilities.
97
91
  */
98
- declare class MockTransport implements Transport {
92
+ declare class MockTransport implements Transport<"mock"> {
93
+ readonly id = "mock";
99
94
  /**
100
95
  * The resolved configuration used by this mock transport.
101
96
  */
@@ -120,7 +115,7 @@ declare class MockTransport implements Transport {
120
115
  * @returns A promise that resolves to a receipt indicating success or failure.
121
116
  * @throws {DOMException} When the operation is aborted via `AbortSignal`.
122
117
  */
123
- send(message: Message, options?: TransportOptions): Promise<Receipt>;
118
+ send(message: Message, options?: TransportOptions): Promise<Receipt<"mock">>;
124
119
  /**
125
120
  * Sends multiple email messages through the mock transport.
126
121
  *
@@ -132,7 +127,7 @@ declare class MockTransport implements Transport {
132
127
  * @returns An async iterable of receipts, one for each message.
133
128
  * @throws {DOMException} When the operation is aborted via `AbortSignal`.
134
129
  */
135
- sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
130
+ sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt<"mock">>;
136
131
  /**
137
132
  * Get all messages that have been "sent" through this transport.
138
133
  *
@@ -166,7 +161,7 @@ declare class MockTransport implements Transport {
166
161
  *
167
162
  * @param receipt The receipt to return for the next send operation.
168
163
  */
169
- setNextResponse(receipt: Receipt): void;
164
+ setNextResponse(receipt: Receipt<"mock">): void;
170
165
  /**
171
166
  * Set the default response that will be returned for send operations.
172
167
  *
@@ -175,7 +170,7 @@ declare class MockTransport implements Transport {
175
170
  *
176
171
  * @param receipt The default receipt to return for send operations.
177
172
  */
178
- setDefaultResponse(receipt: Receipt): void;
173
+ setDefaultResponse(receipt: Receipt<"mock">): void;
179
174
  /**
180
175
  * Set the failure rate (0.0 to 1.0). When set, sends will randomly fail
181
176
  * at the specified rate instead of using the configured responses.
package/dist/index.d.ts CHANGED
@@ -23,13 +23,7 @@ interface MockConfig {
23
23
  *
24
24
  * @default { successful: true, messageId: "mock-message-id" }
25
25
  */
26
- readonly defaultResponse?: {
27
- readonly successful: true;
28
- readonly messageId: string;
29
- } | {
30
- readonly successful: false;
31
- readonly errorMessages: readonly string[];
32
- };
26
+ readonly defaultResponse?: Receipt<"mock">;
33
27
  /**
34
28
  * Fixed delay in milliseconds for all send operations.
35
29
  *
@@ -95,7 +89,8 @@ type ResolvedMockConfig = Required<MockConfig>;
95
89
  * comprehensive testing capabilities including message verification,
96
90
  * behavior simulation, and async utilities.
97
91
  */
98
- declare class MockTransport implements Transport {
92
+ declare class MockTransport implements Transport<"mock"> {
93
+ readonly id = "mock";
99
94
  /**
100
95
  * The resolved configuration used by this mock transport.
101
96
  */
@@ -120,7 +115,7 @@ declare class MockTransport implements Transport {
120
115
  * @returns A promise that resolves to a receipt indicating success or failure.
121
116
  * @throws {DOMException} When the operation is aborted via `AbortSignal`.
122
117
  */
123
- send(message: Message, options?: TransportOptions): Promise<Receipt>;
118
+ send(message: Message, options?: TransportOptions): Promise<Receipt<"mock">>;
124
119
  /**
125
120
  * Sends multiple email messages through the mock transport.
126
121
  *
@@ -132,7 +127,7 @@ declare class MockTransport implements Transport {
132
127
  * @returns An async iterable of receipts, one for each message.
133
128
  * @throws {DOMException} When the operation is aborted via `AbortSignal`.
134
129
  */
135
- sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
130
+ sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt<"mock">>;
136
131
  /**
137
132
  * Get all messages that have been "sent" through this transport.
138
133
  *
@@ -166,7 +161,7 @@ declare class MockTransport implements Transport {
166
161
  *
167
162
  * @param receipt The receipt to return for the next send operation.
168
163
  */
169
- setNextResponse(receipt: Receipt): void;
164
+ setNextResponse(receipt: Receipt<"mock">): void;
170
165
  /**
171
166
  * Set the default response that will be returned for send operations.
172
167
  *
@@ -175,7 +170,7 @@ declare class MockTransport implements Transport {
175
170
  *
176
171
  * @param receipt The default receipt to return for send operations.
177
172
  */
178
- setDefaultResponse(receipt: Receipt): void;
173
+ setDefaultResponse(receipt: Receipt<"mock">): void;
179
174
  /**
180
175
  * Set the failure rate (0.0 to 1.0). When set, sends will randomly fail
181
176
  * at the specified rate instead of using the configured responses.
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { createFailedReceipt } from "@upyo/core";
2
+
1
3
  //#region src/config.ts
2
4
  /**
3
5
  * Creates a resolved mock configuration by applying default values to optional fields.
@@ -23,7 +25,8 @@ function createMockConfig(config = {}) {
23
25
  return {
24
26
  defaultResponse: config.defaultResponse ?? {
25
27
  successful: true,
26
- messageId: "mock-message-id"
28
+ messageId: "mock-message-id",
29
+ provider: "mock"
27
30
  },
28
31
  delay: config.delay ?? 0,
29
32
  randomDelayRange: config.randomDelayRange ?? {
@@ -46,6 +49,7 @@ function createMockConfig(config = {}) {
46
49
  * behavior simulation, and async utilities.
47
50
  */
48
51
  var MockTransport = class {
52
+ id = "mock";
49
53
  /**
50
54
  * The resolved configuration used by this mock transport.
51
55
  */
@@ -314,19 +318,28 @@ var MockTransport = class {
314
318
  if (delayMs > 0) await new Promise((resolve) => setTimeout(resolve, delayMs));
315
319
  }
316
320
  getResponse() {
317
- if (this.config.failureRate > 0 && Math.random() < this.config.failureRate) return {
318
- successful: false,
319
- errorMessages: ["Simulated random failure"]
320
- };
321
+ if (this.config.failureRate > 0 && Math.random() < this.config.failureRate) return createFailedReceipt("Simulated random failure", {
322
+ provider: "mock",
323
+ category: "unknown",
324
+ code: "mock.random_failure",
325
+ retryable: true,
326
+ attempts: 1
327
+ });
321
328
  if (this.nextResponse) {
322
329
  const response = this.nextResponse;
323
330
  this.nextResponse = null;
324
331
  return response;
325
332
  }
326
- if (this.config.defaultResponse.successful && this.config.generateUniqueMessageIds) return {
327
- successful: true,
328
- messageId: `mock-message-${this.messageIdCounter++}`
329
- };
333
+ if (this.config.defaultResponse.successful && this.config.generateUniqueMessageIds) {
334
+ const { attempts, timestamp } = this.config.defaultResponse;
335
+ return {
336
+ successful: true,
337
+ messageId: `mock-message-${this.messageIdCounter++}`,
338
+ provider: "mock",
339
+ ...attempts == null ? {} : { attempts },
340
+ ...timestamp == null ? {} : { timestamp }
341
+ };
342
+ }
330
343
  return this.config.defaultResponse;
331
344
  }
332
345
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upyo/mock",
3
- "version": "0.5.0-dev.86",
3
+ "version": "0.5.0",
4
4
  "description": "Mock transport for Upyo email library—useful for testing",
5
5
  "keywords": [
6
6
  "email",
@@ -54,18 +54,13 @@
54
54
  },
55
55
  "sideEffects": false,
56
56
  "peerDependencies": {
57
- "@upyo/core": "0.5.0-dev.86+2a12a704"
57
+ "@upyo/core": "0.5.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@dotenvx/dotenvx": "^1.47.3",
61
60
  "tsdown": "^0.12.7",
62
61
  "typescript": "5.8.3"
63
62
  },
64
63
  "scripts": {
65
- "build": "tsdown",
66
- "prepublish": "tsdown",
67
- "test": "tsdown && dotenvx run --ignore=MISSING_ENV_FILE -- node --experimental-transform-types --test",
68
- "test:bun": "tsdown && bun test --timeout=30000",
69
- "test:deno": "deno test --allow-env"
64
+ "prepublish": "mise run --no-deps :build"
70
65
  }
71
66
  }