@gravito/signal 3.1.0 → 4.0.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.
Files changed (72) hide show
  1. package/dist/OrbitSignal.d.ts +6 -0
  2. package/dist/errors/codes.d.ts +19 -0
  3. package/dist/errors.d.ts +18 -11
  4. package/dist/index.cjs +55148 -81886
  5. package/dist/index.d.ts +514 -1
  6. package/dist/index.js +61553 -0
  7. package/dist/index.mjs +55158 -81907
  8. package/dist/transports/BaseTransport.d.ts +15 -23
  9. package/package.json +16 -4
  10. package/CHANGELOG.md +0 -74
  11. package/build.ts +0 -133
  12. package/dist/index.cjs.map +0 -712
  13. package/dist/index.mjs.map +0 -710
  14. package/doc/ADVANCED_RENDERING.md +0 -71
  15. package/doc/DISTRIBUTED_MESSAGING.md +0 -79
  16. package/doc/OPTIMIZATION_PLAN.md +0 -496
  17. package/package.json.bak +0 -75
  18. package/scripts/check-coverage.ts +0 -64
  19. package/src/Mailable.ts +0 -674
  20. package/src/OrbitSignal.ts +0 -451
  21. package/src/Queueable.ts +0 -9
  22. package/src/TypedMailable.ts +0 -96
  23. package/src/dev/DevMailbox.ts +0 -146
  24. package/src/dev/DevServer.ts +0 -192
  25. package/src/dev/storage/FileMailboxStorage.ts +0 -66
  26. package/src/dev/storage/MailboxStorage.ts +0 -15
  27. package/src/dev/storage/MemoryMailboxStorage.ts +0 -36
  28. package/src/dev/ui/mailbox.ts +0 -77
  29. package/src/dev/ui/preview.ts +0 -103
  30. package/src/dev/ui/shared.ts +0 -60
  31. package/src/errors.ts +0 -69
  32. package/src/events.ts +0 -72
  33. package/src/index.ts +0 -41
  34. package/src/renderers/HtmlRenderer.ts +0 -41
  35. package/src/renderers/MjmlRenderer.ts +0 -73
  36. package/src/renderers/ReactMjmlRenderer.ts +0 -94
  37. package/src/renderers/ReactRenderer.ts +0 -66
  38. package/src/renderers/Renderer.ts +0 -67
  39. package/src/renderers/TemplateRenderer.ts +0 -84
  40. package/src/renderers/VueMjmlRenderer.ts +0 -99
  41. package/src/renderers/VueRenderer.ts +0 -71
  42. package/src/renderers/mjml-templates.ts +0 -50
  43. package/src/transports/BaseTransport.ts +0 -148
  44. package/src/transports/LogTransport.ts +0 -55
  45. package/src/transports/MemoryTransport.ts +0 -55
  46. package/src/transports/SesTransport.ts +0 -129
  47. package/src/transports/SmtpTransport.ts +0 -184
  48. package/src/transports/Transport.ts +0 -45
  49. package/src/types.ts +0 -309
  50. package/src/utils/html.ts +0 -43
  51. package/src/webhooks/SendGridWebhookDriver.ts +0 -80
  52. package/src/webhooks/SesWebhookDriver.ts +0 -44
  53. package/tests/DevMailbox.test.ts +0 -54
  54. package/tests/FileMailboxStorage.test.ts +0 -56
  55. package/tests/MjmlLayout.test.ts +0 -28
  56. package/tests/MjmlRenderer.test.ts +0 -53
  57. package/tests/OrbitSignalWebhook.test.ts +0 -56
  58. package/tests/ReactMjmlRenderer.test.ts +0 -33
  59. package/tests/SendGridWebhookDriver.test.ts +0 -69
  60. package/tests/SesWebhookDriver.test.ts +0 -46
  61. package/tests/VueMjmlRenderer.test.ts +0 -35
  62. package/tests/dev-server.test.ts +0 -66
  63. package/tests/log-transport.test.ts +0 -21
  64. package/tests/mailable-extra.test.ts +0 -68
  65. package/tests/mailable.test.ts +0 -77
  66. package/tests/orbit-signal.test.ts +0 -43
  67. package/tests/renderers.test.ts +0 -58
  68. package/tests/template-renderer.test.ts +0 -24
  69. package/tests/transports.test.ts +0 -52
  70. package/tests/ui.test.ts +0 -37
  71. package/tsconfig.build.json +0 -24
  72. package/tsconfig.json +0 -9
@@ -5,6 +5,9 @@ import type { Message, Transport } from '../types';
5
5
  * Defines the behavior of the automatic retry mechanism, including the number of attempts
6
6
  * and the timing between them using exponential backoff.
7
7
  *
8
+ * @deprecated Configuration now handled internally by @gravito/resilience RetryOptions.
9
+ * Kept for backward compat of existing subclass constructors.
10
+ *
8
11
  * @example
9
12
  * ```typescript
10
13
  * const options: TransportOptions = {
@@ -29,21 +32,17 @@ export interface TransportOptions {
29
32
  /**
30
33
  * Multiplier applied to the delay after each failed attempt.
31
34
  * Used to implement exponential backoff to avoid overwhelming the service.
35
+ * @deprecated Backoff is now managed by @gravito/resilience (ExponentialBackoff).
32
36
  */
33
37
  backoffMultiplier?: number;
34
38
  }
35
39
  /**
36
- * Base transport class with automatic retry mechanism.
40
+ * Base transport class with automatic retry via @gravito/resilience.
37
41
  *
38
42
  * This abstract class provides a robust foundation for all transport implementations by
39
- * handling transient failures through an exponential backoff retry strategy. It ensures
40
- * that temporary network issues or service rate limits do not immediately fail the email delivery.
41
- *
42
- * The retry mechanism works as follows:
43
- * 1. Attempt to send the message via `doSend()`.
44
- * 2. If it fails, wait for `retryDelay` milliseconds.
45
- * 3. Increment the delay by `backoffMultiplier` for the next attempt.
46
- * 4. Repeat until success or `maxRetries` is reached.
43
+ * handling transient failures through the unified @gravito/resilience withRetry primitive.
44
+ * Only errors whose `retryable` flag is true (e.g., CONNECTION_FAILED, RATE_LIMIT) are
45
+ * retried automatically.
47
46
  *
48
47
  * @example
49
48
  * ```typescript
@@ -54,7 +53,7 @@ export interface TransportOptions {
54
53
  *
55
54
  * protected async doSend(message: Message): Promise<void> {
56
55
  * // Actual implementation of the sending logic
57
- * // If this throws, BaseTransport will catch and retry
56
+ * // If this throws, BaseTransport will retry via withRetry
58
57
  * }
59
58
  * }
60
59
  * ```
@@ -70,14 +69,14 @@ export declare abstract class BaseTransport implements Transport {
70
69
  */
71
70
  constructor(options?: TransportOptions);
72
71
  /**
73
- * Orchestrates the message delivery with retry logic.
72
+ * Orchestrates the message delivery with automatic retry via @gravito/resilience.
74
73
  *
75
- * This method wraps the concrete `doSend` implementation in a retry loop.
76
- * It tracks the last error encountered to provide context if all retries fail.
74
+ * Delegates to `doSend()` and retries on retryable InfrastructureException errors
75
+ * (CONNECTION_FAILED, RATE_LIMIT). Non-retryable errors surface immediately.
77
76
  *
78
77
  * @param message - The message to be delivered.
79
78
  * @returns A promise that resolves when the message is successfully sent.
80
- * @throws {MailTransportError} If the message cannot be sent after the maximum number of retries.
79
+ * @throws {MailTransportError} If the message cannot be sent after the maximum number of attempts.
81
80
  *
82
81
  * @example
83
82
  * ```typescript
@@ -94,18 +93,11 @@ export declare abstract class BaseTransport implements Transport {
94
93
  * Actual transport implementation to be provided by subclasses.
95
94
  *
96
95
  * This method should contain the protocol-specific logic for delivering the message.
97
- * It will be automatically retried by the `send` method if it throws an error.
96
+ * It will be automatically retried by `send()` if it throws a retryable error.
98
97
  *
99
98
  * @param message - The message to send.
100
99
  * @returns A promise that resolves when the delivery is successful.
101
- * @throws {Error} Any error encountered during delivery, which will trigger a retry.
100
+ * @throws {Error} Any error encountered during delivery, which may trigger a retry.
102
101
  */
103
102
  protected abstract doSend(message: Message): Promise<void>;
104
- /**
105
- * Utility method to pause execution for a given duration.
106
- *
107
- * @param ms - Milliseconds to sleep.
108
- * @returns A promise that resolves after the delay.
109
- */
110
- private sleep;
111
103
  }
package/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "@gravito/signal",
3
3
  "sideEffects": false,
4
- "version": "3.1.0",
4
+ "version": "4.0.0",
5
5
  "description": "Powerful email framework for Gravito applications with Dev UI and multi-renderer support.",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
8
8
  "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
9
16
  "scripts": {
10
17
  "build": "bun run build.ts",
11
18
  "build:dts": "bun run build.ts --dts-only",
@@ -16,6 +23,10 @@
16
23
  "test:unit": "bun test tests/ --timeout=10000",
17
24
  "test:integration": "test $(find tests -name '*.integration.test.ts' 2>/dev/null | wc -l) -gt 0 && find tests -name '*.integration.test.ts' -print0 | xargs -0 bun test --timeout=10000 || echo 'No integration tests found'"
18
25
  },
26
+ "files": [
27
+ "dist",
28
+ "README.md"
29
+ ],
19
30
  "keywords": [
20
31
  "gravito",
21
32
  "mail",
@@ -28,12 +39,13 @@
28
39
  "license": "MIT",
29
40
  "dependencies": {
30
41
  "@aws-sdk/client-ses": "^3.953.0",
42
+ "@gravito/resilience": "workspace:*",
31
43
  "nodemailer": "^7.0.11"
32
44
  },
33
45
  "peerDependencies": {
34
- "@gravito/core": "^2.0.0",
35
- "@gravito/stream": "^2.1.0",
36
- "@gravito/prism": "^3.1.1",
46
+ "@gravito/core": "^3.0.0",
47
+ "@gravito/stream": "^3.0.0",
48
+ "@gravito/prism": "^4.0.0",
37
49
  "react": "^19.0.0",
38
50
  "react-dom": "^19.0.0",
39
51
  "vue": "^3.0.0"
package/CHANGELOG.md DELETED
@@ -1,74 +0,0 @@
1
- # @gravito/signal
2
-
3
- ## 3.0.4
4
-
5
- ### Patch Changes
6
-
7
- - Convert all workspace:\* dependencies to version numbers for npm publishing
8
-
9
- - Fixed 144 workspace:\* dependencies across 58 packages
10
- - Ensures all packages work properly when installed from npm
11
- - Resolves issues with bunx and npm installation of CLI tools
12
- - All internal dependencies now use explicit version constraints
13
-
14
- - Updated dependencies
15
- - @gravito/core@1.6.1
16
- - @gravito/prism@3.1.1
17
- - @gravito/stream@2.0.2
18
-
19
- ## 3.0.3
20
-
21
- ### Patch Changes
22
-
23
- - Updated dependencies [6234dab]
24
- - @gravito/prism@3.0.2
25
-
26
- ## 3.0.2
27
-
28
- ### Patch Changes
29
-
30
- - Updated dependencies [905588f]
31
- - @gravito/stream@2.0.1
32
-
33
- ## 3.0.1
34
-
35
- ### Patch Changes
36
-
37
- - Updated dependencies
38
- - @gravito/core@1.2.1
39
- - @gravito/stream@1.0.3
40
- - @gravito/prism@3.0.1
41
-
42
- ## 3.0.0
43
-
44
- ### Patch Changes
45
-
46
- - Updated dependencies
47
- - @gravito/core@1.2.0
48
- - @gravito/prism@3.0.0
49
- - @gravito/stream@1.0.2
50
-
51
- ## 2.0.0
52
-
53
- ### Patch Changes
54
-
55
- - Updated dependencies
56
- - Updated dependencies
57
- - @gravito/core@1.1.0
58
- - @gravito/prism@2.0.0
59
- - @gravito/stream@1.0.1
60
-
61
- ## 1.0.1
62
-
63
- ### Patch Changes
64
-
65
- - Refactored all scaffold generators (Enterprise MVC, Clean Architecture, Action Domain, DDD) to adopt the Service Provider pattern and a modern 4-step bootstrap lifecycle. Fixed a missing mock in @gravito/signal tests.
66
-
67
- ## 1.0.0
68
-
69
- ### Patch Changes
70
-
71
- - Updated dependencies
72
- - @gravito/core@1.0.0
73
- - @gravito/stream@1.0.0
74
- - @gravito/prism@1.0.0
package/build.ts DELETED
@@ -1,133 +0,0 @@
1
- import { cp, type Dirent, mkdir, readdir, rm } from 'node:fs/promises'
2
- import { basename } from 'node:path'
3
- import { build } from 'bun'
4
-
5
- const isDtsOnly = process.argv.includes('--dts-only')
6
- const pkgName = basename(import.meta.dirname) // "signal"
7
-
8
- console.log(
9
- isDtsOnly ? 'Building @gravito/signal DTS...' : 'Building @gravito/signal in parallel...'
10
- )
11
-
12
- // Clean dist
13
- await rm('dist', { recursive: true, force: true })
14
-
15
- // External dependencies(peer deps + framework 包)
16
- const externalDeps = [
17
- '@gravito/core',
18
- '@gravito/stream',
19
- '@gravito/prism',
20
- 'react',
21
- 'react-dom',
22
- 'vue',
23
- '@vue/server-renderer',
24
- 'nodemailer',
25
- '@aws-sdk/client-ses',
26
- ]
27
-
28
- async function buildInParallel() {
29
- const tasks: Promise<number>[] = []
30
- const tempDir = isDtsOnly ? 'dist' : '.tsc-temp'
31
-
32
- if (!isDtsOnly) {
33
- await rm(tempDir, { recursive: true, force: true })
34
-
35
- // Task 1: bun build ESM
36
- const esmPromise = (async () => {
37
- const buildResult = await build({
38
- entrypoints: ['src/index.ts'],
39
- outdir: 'dist',
40
- format: 'esm',
41
- target: 'node',
42
- splitting: false,
43
- sourcemap: 'external',
44
- external: externalDeps,
45
- naming: '[dir]/[name].mjs',
46
- })
47
-
48
- if (!buildResult.success) {
49
- console.error('❌ ESM build failed:', buildResult.logs)
50
- return 1
51
- }
52
- return 0
53
- })()
54
- tasks.push(esmPromise)
55
-
56
- // Task 2: bun build CJS
57
- const cjsPromise = (async () => {
58
- const cjsResult = await build({
59
- entrypoints: ['src/index.ts'],
60
- outdir: 'dist',
61
- format: 'cjs',
62
- target: 'node',
63
- splitting: false,
64
- sourcemap: 'external',
65
- naming: '[dir]/[name].cjs',
66
- external: externalDeps,
67
- })
68
-
69
- if (!cjsResult.success) {
70
- console.error('❌ CJS build failed:', cjsResult.logs)
71
- return 1
72
- }
73
- return 0
74
- })()
75
- tasks.push(cjsPromise)
76
- }
77
-
78
- // Task 3: tsc 生成型別宣告(使用 tsconfig.build.json + noCheck)
79
- const tscPromise = (async () => {
80
- const tsc = Bun.spawn(['bunx', 'tsc', '-p', 'tsconfig.build.json', '--outDir', tempDir], {
81
- stdout: 'inherit',
82
- stderr: 'inherit',
83
- cwd: import.meta.dirname,
84
- })
85
- return await tsc.exited
86
- })()
87
- tasks.push(tscPromise)
88
-
89
- const results = await Promise.all(tasks)
90
- for (const result of results) {
91
- if (result !== 0) {
92
- process.exit(1)
93
- }
94
- }
95
- }
96
-
97
- // 遞迴複製 .d.ts 檔案
98
- async function copyDtsFiles(src: string, dest: string) {
99
- let entries: Dirent[]
100
- try {
101
- entries = await readdir(src, { withFileTypes: true })
102
- } catch (_e) {
103
- return
104
- }
105
-
106
- for (const entry of entries) {
107
- const srcPath = `${src}/${entry.name}`
108
- const destPath = `${dest}/${entry.name}`
109
-
110
- if (entry.isDirectory()) {
111
- await mkdir(destPath, { recursive: true }).catch(() => {})
112
- await copyDtsFiles(srcPath, destPath)
113
- } else if (entry.isFile() && entry.name.endsWith('.d.ts')) {
114
- await cp(srcPath, destPath)
115
- }
116
- }
117
- }
118
-
119
- await buildInParallel()
120
-
121
- // 後處理:tsc 輸出到 .tsc-temp/{pkgName}/src/,需要移到 dist/
122
- const tempDir = isDtsOnly ? 'dist' : '.tsc-temp'
123
- if (!isDtsOnly) {
124
- try {
125
- const dtsSourceDir = `${tempDir}/${pkgName}/src`
126
- await copyDtsFiles(dtsSourceDir, 'dist')
127
- await rm(tempDir, { recursive: true, force: true })
128
- } catch (e) {
129
- console.warn('⚠️ Warning: Failed to copy type declarations:', e)
130
- }
131
- }
132
-
133
- console.log('✅ @gravito/signal build completed')