@volter/twin-postmark 0.1.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/LICENSE +202 -0
- package/README.md +144 -0
- package/client/postmark-mirror.css +79 -0
- package/client/postmark-mirror.tsx +221 -0
- package/dist/client/postmark-mirror.bundle.js +321 -0
- package/dist/client/postmark-mirror.css +79 -0
- package/dist/client/postmark-mirror.d.ts +18 -0
- package/dist/client/postmark-mirror.js +153 -0
- package/dist/client/postmark-mirror.tsx +221 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +31 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +54 -0
- package/dist/src/postmark-capabilities.d.ts +12 -0
- package/dist/src/postmark-capabilities.js +1502 -0
- package/dist/src/postmark-conformance.d.ts +33 -0
- package/dist/src/postmark-conformance.js +265 -0
- package/dist/src/postmark-connector.d.ts +167 -0
- package/dist/src/postmark-connector.js +251 -0
- package/dist/src/postmark-events.d.ts +85 -0
- package/dist/src/postmark-events.js +169 -0
- package/dist/src/postmark-mirror-ui.d.ts +58 -0
- package/dist/src/postmark-mirror-ui.js +207 -0
- package/dist/src/postmark-perform-harness.d.ts +9 -0
- package/dist/src/postmark-perform-harness.js +24 -0
- package/dist/src/postmark-server.d.ts +14 -0
- package/dist/src/postmark-server.js +29 -0
- package/dist/src/postmark-twin.d.ts +82 -0
- package/dist/src/postmark-twin.js +1575 -0
- package/dist/test-fixtures/postmark-swagger-operations.json +846 -0
- package/package.json +76 -0
- package/src/cli.ts +29 -0
- package/src/index.ts +89 -0
- package/src/postmark-capabilities.ts +1737 -0
- package/src/postmark-conformance.ts +282 -0
- package/src/postmark-connector.ts +312 -0
- package/src/postmark-events.ts +189 -0
- package/src/postmark-mirror-ui.ts +213 -0
- package/src/postmark-perform-harness.ts +21 -0
- package/src/postmark-server.ts +37 -0
- package/src/postmark-twin.ts +1520 -0
- package/test-fixtures/postmark-swagger-operations.json +846 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @volter/twin-postmark
|
|
2
|
+
|
|
3
|
+
A local **Postmark** twin — a faithful, stateful local Postmark transactional-email API your
|
|
4
|
+
real `postmark` SDK talks to **unmodified**. Send plain/templated/batch email; browse outbound
|
|
5
|
+
message activity with per-message delivery events; bounces + delivery stats; templates with
|
|
6
|
+
Mustachio rendering; message streams; suppressions; webhooks; servers, domains and sender
|
|
7
|
+
signatures. A **deterministic offline delivery lifecycle** writes real `MessageEvents`, mints
|
|
8
|
+
Bounce records and suppressions, and POSTs **Postmark's real (unsigned, Basic-auth/custom-header)
|
|
9
|
+
webhook payloads** to your registered endpoints. Ships a **React activity mirror UI** rendered
|
|
10
|
+
from real twin state. Built on the shared [`@volter/world-core`](../../world-core) kernel
|
|
11
|
+
(append-only event log + projection, local-action writes, egress ledger, connectors, pack
|
|
12
|
+
registry).
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { ServerClient, Models } from 'postmark';
|
|
16
|
+
import { createPostmarkTwinServer } from '@volter/twin-postmark';
|
|
17
|
+
|
|
18
|
+
const twin = createPostmarkTwinServer({ port: 0 }); // local, offline
|
|
19
|
+
// The SDK's OWN public option points it at the twin — nothing is monkey-patched.
|
|
20
|
+
const postmark = new ServerClient(
|
|
21
|
+
'11111111-2222-3333-4444-555555555555',
|
|
22
|
+
new Models.ClientOptions.Configuration(false, `127.0.0.1:${twin.port}`, 30),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const sent = await postmark.sendEmail({
|
|
26
|
+
From: 'Acme <notifications@acme.dev>',
|
|
27
|
+
To: 'ada@example.com',
|
|
28
|
+
Subject: 'Your login code',
|
|
29
|
+
TextBody: 'Your code is 123456',
|
|
30
|
+
}); // → { MessageID, SubmittedAt, ErrorCode: 0, Message: 'OK' }
|
|
31
|
+
|
|
32
|
+
const details = await postmark.getOutboundMessageDetails(sent.MessageID);
|
|
33
|
+
details.MessageEvents; // → [{ Type: 'Delivered', … }]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Zero-edit redirection also works: set `POSTMARK_TWIN_URL` and the control-plane injector
|
|
37
|
+
forwards `api.postmarkapp.com` to the twin, so an **unchanged** app finds it with no config.
|
|
38
|
+
|
|
39
|
+
## CLI
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
world-postmark serve [--port N] [--root DIR] [--read-only] # the Postmark API twin
|
|
43
|
+
world-postmark mirror [--port N] [--root DIR] # the activity mirror UI
|
|
44
|
+
world-postmark conformance [--root DIR] # spec-true validation
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## How it works
|
|
48
|
+
|
|
49
|
+
- **A repo, not a mock.** Every write is a local action appended to the kernel's log; every
|
|
50
|
+
read folds the projection. A sent message is **stored** in twin state — never put on the
|
|
51
|
+
wire — and `GET /messages/outbound` serves the same projection the mirror renders.
|
|
52
|
+
- **Auth is Postmark's, faked locally.** `X-Postmark-Server-Token` on server-scoped routes and
|
|
53
|
+
`X-Postmark-Account-Token` on account-scoped ones (**not** a Bearer token). A twin holds no
|
|
54
|
+
account, so any non-empty token is accepted; a missing or empty one fails like the vendor
|
|
55
|
+
with `401 {ErrorCode: 10}` and the vendor's endpoint-scoped message text. The documented
|
|
56
|
+
public test token `POSTMARK_API_TEST` is modeled with its real `/email`-only restriction.
|
|
57
|
+
- **A deterministic offline delivery lifecycle.** A send records `MessageEvents` on the stored
|
|
58
|
+
message: `Delivered`, plus `Opened`/`LinkClicked` **only when the message asked for that
|
|
59
|
+
tracking** (Postmark's tracking is opt-in). A recipient whose local part starts with
|
|
60
|
+
`bounce` hard-bounces; `spam`/`complaint` raises a spam complaint. Both mint a real Bounce
|
|
61
|
+
record **and a suppression**, so a later send to that address is refused with the vendor's
|
|
62
|
+
`422 {ErrorCode: 406}` — genuinely stateful behavior, not a fresh-root trick.
|
|
63
|
+
- **Webhooks are Postmark's, which means UNSIGNED.** There is no svix/HMAC scheme anywhere in
|
|
64
|
+
Postmark's design. Deliveries carry a `RecordType` discriminator
|
|
65
|
+
(`Delivery`/`Open`/`Click`/`Bounce`/`SpamComplaint`) and are authenticated the two ways the
|
|
66
|
+
Webhooks API actually models: `HttpAuth` → an HTTP Basic header, and `HttpHeaders` → your
|
|
67
|
+
own headers. A webhook only receives a record type whose trigger is enabled, on its own
|
|
68
|
+
message stream. `postmark.honesty.no_webhook_signature` is a deliberate negative assertion
|
|
69
|
+
that keeps a future contributor from copying a sibling pack's signature scheme in here.
|
|
70
|
+
- **The mirror is API passthrough (archetype A).** The browser client fetches **Postmark's own
|
|
71
|
+
real API paths**; there is exactly one handler serving both the screen and the SDK, so
|
|
72
|
+
API↔UI parity cannot drift.
|
|
73
|
+
|
|
74
|
+
## Coverage
|
|
75
|
+
|
|
76
|
+
**Partial and honest, and it is meant to read that way.** The capability manifest
|
|
77
|
+
(`src/postmark-capabilities.ts`) is the **real vendor surface as the denominator** — all 15
|
|
78
|
+
documented API groups and 86 endpoints from developer.postmarkapp.com's docs nav, enumerated
|
|
79
|
+
top-down whether or not this twin has reached them. Coverage grows by building, and the
|
|
80
|
+
percentage *drops* when the denominator honestly grows. See the generated table in the repo
|
|
81
|
+
[README](../../../docs/contributing/conformance.md) for the live numbers.
|
|
82
|
+
|
|
83
|
+
**Where the surface came from** (recorded in `spec-sources.json` as `kind: "none"` — Postmark
|
|
84
|
+
publishes no OpenAPI/SDL):
|
|
85
|
+
|
|
86
|
+
1. The **official `postmark` npm SDK v4.0.7**'s compiled route map and TypeScript models —
|
|
87
|
+
a first-party artifact naming every path, verb, field, casing and list envelope, plus its
|
|
88
|
+
`AuthHeaderNames` enum and `ApiInputError.ERROR_CODES`.
|
|
89
|
+
2. developer.postmarkapp.com's published **API-error-codes table** (163 rows) — the source of
|
|
90
|
+
every `ErrorCode`/HTTP-status pair in `POSTMARK_ERRORS`.
|
|
91
|
+
3. **Live read-only probes** of `api.postmarkapp.com` with the documented public test token,
|
|
92
|
+
made during this pack's build. These corrected three things the docs alone get wrong, each
|
|
93
|
+
annotated `[WIRE]` in `postmark-twin.ts`:
|
|
94
|
+
- **`Subject` is NOT required** on `POST /email` — a subject-less send succeeds;
|
|
95
|
+
- the **401 message text is endpoint-scoped** ("valid Server token" vs "valid Account
|
|
96
|
+
token"), not the merged string the docs table shows;
|
|
97
|
+
- **`POSTMARK_API_TEST` is `/email`-only**, answering `403` + `ErrorCode 10` anywhere else,
|
|
98
|
+
and `"Test job accepted"` rather than `"OK"` on a send.
|
|
99
|
+
|
|
100
|
+
Anything not grounded in those three is marked `⚠ doc-unverified` in the source and never
|
|
101
|
+
claimed beyond what a `verify()` proves.
|
|
102
|
+
|
|
103
|
+
### Fidelity quirks deliberately preserved
|
|
104
|
+
|
|
105
|
+
Postmark's API is inconsistent in ways a tidy-minded twin would silently "fix". These are
|
|
106
|
+
modeled as-is, because a consumer's parsing depends on them:
|
|
107
|
+
|
|
108
|
+
- `TotalCount` comes **first** on every list envelope **except** `/message-streams` (last) and
|
|
109
|
+
`/webhooks` (**absent entirely**).
|
|
110
|
+
- `/senders` returns a **`SenderSignatures`** array, not `Senders`.
|
|
111
|
+
- `/deliverystats`'s first bounce row is the `"All"` total and carries **no `Type` key**.
|
|
112
|
+
- Batch sends answer **HTTP 200 with per-message errors inside a bare array** — never a
|
|
113
|
+
top-level 422 (only the >500 cap is).
|
|
114
|
+
- Suppression deletion is a **POST to `…/suppressions/delete`**, not an HTTP `DELETE`.
|
|
115
|
+
- "Not found" for a known route is **422 + a per-domain `ErrorCode`**, not 404; 404 is
|
|
116
|
+
reserved for a route that does not exist at all.
|
|
117
|
+
- An outbound message **mixes two recipient shapes in one payload**: `To`/`Cc`/`Bcc` are
|
|
118
|
+
arrays of `{Email, Name}` **objects** while `Recipients`, right beside them, is an array of
|
|
119
|
+
**plain email strings** (all of To+Cc+Bcc flattened). This is the vendor's real shape, not a
|
|
120
|
+
twin bug — grounded in the outbound-search example on
|
|
121
|
+
postmarkapp.com/developer/api/messages-api (`"To":[{"Email":…,"Name":…}]` next to
|
|
122
|
+
`"Recipients":["…"]`) **and** the official `postmark` SDK's own types
|
|
123
|
+
(`OutboundMessage.To: Recipient[]` vs `Recipients: string[]`), and pinned by
|
|
124
|
+
`postmark.messages.outbound_recipient_shapes` so neither side is ever "fixed" into
|
|
125
|
+
consistency. (One sub-shape divergence, recorded honestly: for a bare address with no
|
|
126
|
+
display name the docs example shows `"Name": null` where this twin emits `""` — the string
|
|
127
|
+
the official SDK's non-nullable `Name: string` type declares.)
|
|
128
|
+
|
|
129
|
+
### No UI mirror? — it has one, and here is the rule it was decided by
|
|
130
|
+
|
|
131
|
+
Postmark's core job is done in **code** (an integrator calls `POST /email`), so `ui-scope.json`
|
|
132
|
+
records `needsUi: false`: it is **not an agent navigation target**. The mirror exists as a
|
|
133
|
+
**state visualization** — the local-dev outbox where a human inspects what the twin stored,
|
|
134
|
+
which is exactly what Postmark's Activity dashboard is for. Same classification and same
|
|
135
|
+
reasoning as the sibling `resend` pack. Every UI capability is **data-coupled** (seed through
|
|
136
|
+
the twin's write path → fetch the same API the screen reads → assert), never a marker grep.
|
|
137
|
+
|
|
138
|
+
### Known gaps (filed, not hidden)
|
|
139
|
+
|
|
140
|
+
Tracked as `todo` capabilities and in `pull-audit.json`: the Bulk API lifecycle, real inbound
|
|
141
|
+
ingestion, `PUT /templates/push`, webhook verify/statistics, full Mustachio blocks
|
|
142
|
+
(`{{#each}}`/`{{#if}}`) and layout composition, the rate-limit response headers and 429 path,
|
|
143
|
+
the `415` problem+json envelope, and connector pulls for account-token domains/sender
|
|
144
|
+
signatures, stream-scoped suppressions, inbound messages, and >500-row pagination.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bg: #09090b;
|
|
3
|
+
--panel: #131316;
|
|
4
|
+
--panel-2: #1b1b20;
|
|
5
|
+
--border: #2a2a30;
|
|
6
|
+
--text: #ededf0;
|
|
7
|
+
--muted: #9a9aa5;
|
|
8
|
+
--accent: #ffe01b; /* Postmark yellow */
|
|
9
|
+
--accent-2: #facc15;
|
|
10
|
+
--ok: #22c55e;
|
|
11
|
+
--warn: #f59e0b;
|
|
12
|
+
--bad: #ef4444;
|
|
13
|
+
--neutral: #6b6b7b;
|
|
14
|
+
}
|
|
15
|
+
* { box-sizing: border-box; }
|
|
16
|
+
html, body, #root { height: 100%; margin: 0; }
|
|
17
|
+
body {
|
|
18
|
+
background: var(--bg);
|
|
19
|
+
color: var(--text);
|
|
20
|
+
font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
21
|
+
}
|
|
22
|
+
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
23
|
+
.app { display: flex; flex-direction: column; height: 100%; }
|
|
24
|
+
.topbar {
|
|
25
|
+
display: flex; align-items: baseline; gap: 12px;
|
|
26
|
+
padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--panel);
|
|
27
|
+
}
|
|
28
|
+
.brand { font-weight: 700; color: var(--accent); font-size: 16px; }
|
|
29
|
+
.subtitle { color: var(--muted); font-size: 12px; }
|
|
30
|
+
/* The pane a reader OPENED gets the width. Three near-fixed tracks left the detail with
|
|
31
|
+
whatever was left over — 325px inside an 865px mirror embedded in a Room — and its own
|
|
32
|
+
label column then took 220px of that, so a MessageID rendered four characters per line.
|
|
33
|
+
Both tracks answer to the width they are actually given now. */
|
|
34
|
+
.body { display: grid; grid-template-columns: 200px minmax(220px, 0.8fr) minmax(0, 1.4fr); flex: 1; min-height: 0; }
|
|
35
|
+
.nav { border-right: 1px solid var(--border); background: var(--panel); padding: 8px; overflow: auto; }
|
|
36
|
+
.nav-item {
|
|
37
|
+
display: block; width: 100%; text-align: left; padding: 8px 10px; margin-bottom: 2px;
|
|
38
|
+
background: transparent; color: var(--text); border: 0; border-radius: 6px; cursor: pointer;
|
|
39
|
+
}
|
|
40
|
+
.nav-item:hover { background: var(--panel-2); }
|
|
41
|
+
.nav-item.active { background: var(--panel-2); color: #fff; border-left: 3px solid var(--accent); }
|
|
42
|
+
.list { border-right: 1px solid var(--border); overflow: auto; background: var(--bg); }
|
|
43
|
+
.list-head { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); }
|
|
44
|
+
.row {
|
|
45
|
+
display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0;
|
|
46
|
+
border-bottom: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer;
|
|
47
|
+
}
|
|
48
|
+
.row:hover { background: var(--panel-2); }
|
|
49
|
+
.row.selected { background: var(--panel-2); border-left: 3px solid var(--accent-2); }
|
|
50
|
+
.row-title { font-weight: 600; }
|
|
51
|
+
.row-sub { color: var(--muted); font-size: 12px; }
|
|
52
|
+
.detail { overflow: auto; padding: 16px 18px; }
|
|
53
|
+
.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
|
|
54
|
+
.message-view { margin-bottom: 16px; }
|
|
55
|
+
.message-meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; display: grid; gap: 2px; }
|
|
56
|
+
.timeline { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
|
|
57
|
+
.timeline .event {
|
|
58
|
+
padding: 2px 8px; border-radius: 4px; font-size: 11px; text-transform: capitalize;
|
|
59
|
+
border: 1px solid var(--border); color: var(--muted);
|
|
60
|
+
}
|
|
61
|
+
.timeline .event.ok { color: var(--ok); border-color: var(--ok); }
|
|
62
|
+
.timeline .event.warn { color: var(--warn); border-color: var(--warn); }
|
|
63
|
+
.timeline .event.bad { color: var(--bad); border-color: var(--bad); }
|
|
64
|
+
.message-html { width: 100%; height: 320px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
|
|
65
|
+
.message-text { white-space: pre-wrap; word-break: break-word; background: var(--panel); padding: 12px; border-radius: 6px; border: 1px solid var(--border); }
|
|
66
|
+
.detail-lines { margin: 12px 0 0; }
|
|
67
|
+
.detail-line { display: grid; grid-template-columns: minmax(88px, min(220px, 38%)) minmax(0, 1fr); gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--border); }
|
|
68
|
+
.detail-line dt { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
|
|
69
|
+
.detail-line dd { margin: 0; word-break: break-word; }
|
|
70
|
+
.empty { padding: 16px; color: var(--muted); }
|
|
71
|
+
.empty.error { color: var(--bad); }
|
|
72
|
+
.pill {
|
|
73
|
+
display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px;
|
|
74
|
+
text-transform: capitalize; border: 1px solid var(--border);
|
|
75
|
+
}
|
|
76
|
+
.pill.ok { color: var(--ok); border-color: var(--ok); }
|
|
77
|
+
.pill.warn { color: var(--warn); border-color: var(--warn); }
|
|
78
|
+
.pill.bad { color: var(--bad); border-color: var(--bad); }
|
|
79
|
+
.pill.neutral { color: var(--neutral); }
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// Postmark UI mirror — React/TSX client (Bun-bundled). A Postmark-dashboard-style console:
|
|
2
|
+
// top bar + left nav + list/detail split, with Activity (the outbound message stream) as the
|
|
3
|
+
// main screen, plus Bounces, Templates, Streams, Webhooks and Suppressions.
|
|
4
|
+
//
|
|
5
|
+
// It renders by consuming the twin's OWN REST API on the same origin, at POSTMARK'S REAL
|
|
6
|
+
// PATHS (/messages/outbound, /messages/outbound/:id/details, /bounces, /templates,
|
|
7
|
+
// /message-streams, /webhooks, /message-streams/outbound/suppressions/dump) — the exact
|
|
8
|
+
// endpoints a real integration calls. One code path serves both, so API↔UI parity holds by
|
|
9
|
+
// construction.
|
|
10
|
+
//
|
|
11
|
+
// The pure format helpers live in ../src/postmark-mirror-ui.ts so they can be unit-tested AND
|
|
12
|
+
// shared here (Bun tree-shakes the server-only exports out of this browser bundle).
|
|
13
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
14
|
+
import { createRoot } from 'react-dom/client';
|
|
15
|
+
import {
|
|
16
|
+
recipientsOf, messageSubject, messageStatus, messagePreview, deliveryTimeline,
|
|
17
|
+
formatPostmarkDate, statusTone, flattenPostmarkValue, POSTMARK_MIRROR_SECTIONS,
|
|
18
|
+
type PostmarkRow, type FlatLine, type MirrorSection,
|
|
19
|
+
} from '../src/postmark-mirror-ui.ts';
|
|
20
|
+
|
|
21
|
+
// WHERE THIS MIRROR LIVES. Served at a vendor root the base is '' (fetches are root-relative, as
|
|
22
|
+
// before); served under a path prefix with a <base> tag every read and write resolves inside that
|
|
23
|
+
// prefix instead of escaping it.
|
|
24
|
+
const WIRE_BASE = typeof document === 'undefined' || document.querySelector('base[href]') === null ? '' : new URL('.', document.baseURI).pathname.replace(/\/$/, '');
|
|
25
|
+
|
|
26
|
+
export function StatusPill({ value }: { value: any }) {
|
|
27
|
+
const v = String(value ?? '');
|
|
28
|
+
return <span className={`pill ${statusTone(v)}`}>{v || '—'}</span>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The rendered body preview — html in an isolated frame, text in a <pre>. */
|
|
32
|
+
export function MessageBody({ message }: { message: PostmarkRow }) {
|
|
33
|
+
const preview = messagePreview(message);
|
|
34
|
+
if (preview.kind === 'html') {
|
|
35
|
+
return <iframe className="message-html" title="message body" sandbox="" srcDoc={preview.value} />;
|
|
36
|
+
}
|
|
37
|
+
if (preview.kind === 'text') {
|
|
38
|
+
return <pre className="message-text">{preview.value}</pre>;
|
|
39
|
+
}
|
|
40
|
+
return <div className="empty">No body.</div>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The MessageEvents timeline the twin recorded for a sent message. */
|
|
44
|
+
export function DeliveryTimeline({ message }: { message: PostmarkRow }) {
|
|
45
|
+
const events = deliveryTimeline(message);
|
|
46
|
+
return (
|
|
47
|
+
<div className="timeline">
|
|
48
|
+
{events.map((ev, i) => (
|
|
49
|
+
<span key={`${ev}-${i}`} className={`event ${statusTone(ev)}`}>{ev}</span>
|
|
50
|
+
))}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Render the flattened nested-field lines for the detail panel. */
|
|
56
|
+
export function NestedLines({ lines }: { lines: FlatLine[] }) {
|
|
57
|
+
return (
|
|
58
|
+
<dl className="detail-lines">
|
|
59
|
+
{lines.map((ln, i) => (
|
|
60
|
+
<div className="detail-line" key={`${ln.key}-${i}`}>
|
|
61
|
+
<dt className="mono">{ln.key}</dt>
|
|
62
|
+
<dd className="mono">{ln.value}</dd>
|
|
63
|
+
</div>
|
|
64
|
+
))}
|
|
65
|
+
</dl>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The one-line summary each nav section shows for a row. */
|
|
70
|
+
function rowTitle(section: MirrorSection, r: PostmarkRow): string {
|
|
71
|
+
if (section.key === 'messages') return messageSubject(r);
|
|
72
|
+
if (section.key === 'bounces') return `${r.Type ?? 'Bounce'} · ${r.Email ?? ''}`;
|
|
73
|
+
if (section.key === 'templates') return String(r.Name ?? r.TemplateId ?? '');
|
|
74
|
+
if (section.key === 'streams') return String(r.Name ?? r.ID ?? '');
|
|
75
|
+
if (section.key === 'webhooks') return String(r.Url ?? r.ID ?? '');
|
|
76
|
+
if (section.key === 'suppressions') return String(r.EmailAddress ?? '');
|
|
77
|
+
return String(r[section.idKey] ?? '');
|
|
78
|
+
}
|
|
79
|
+
function rowSubtitle(section: MirrorSection, r: PostmarkRow): string {
|
|
80
|
+
if (section.key === 'messages') return `to ${recipientsOf(r)} · ${messageStatus(r)}`;
|
|
81
|
+
if (section.key === 'bounces') return `${r.Subject ?? ''} · ${r.Inactive ? 'inactive' : 'active'}`;
|
|
82
|
+
if (section.key === 'templates') return `${r.Alias ?? '(no alias)'} · ${r.TemplateType ?? ''}`;
|
|
83
|
+
if (section.key === 'streams') return `${r.MessageStreamType ?? ''} · ${r.ID ?? ''}`;
|
|
84
|
+
if (section.key === 'webhooks') return String(r.MessageStream ?? '');
|
|
85
|
+
if (section.key === 'suppressions') return `${r.SuppressionReason ?? ''} · ${r.Origin ?? ''}`;
|
|
86
|
+
return '';
|
|
87
|
+
}
|
|
88
|
+
/** The status value each section pins to its pill. */
|
|
89
|
+
function rowStatus(section: MirrorSection, r: PostmarkRow): string {
|
|
90
|
+
if (section.key === 'messages') return messageStatus(r);
|
|
91
|
+
if (section.key === 'bounces') return String(r.Type ?? '');
|
|
92
|
+
if (section.key === 'templates') return r.Active ? 'Active' : 'Inactive';
|
|
93
|
+
if (section.key === 'streams') return r.ArchivedAt ? 'Blocked' : 'Active';
|
|
94
|
+
if (section.key === 'suppressions') return String(r.SuppressionReason ?? '');
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function useCollection(section: MirrorSection): { rows: PostmarkRow[]; loading: boolean; error: string } {
|
|
99
|
+
const [rows, setRows] = useState<PostmarkRow[]>([]);
|
|
100
|
+
const [loading, setLoading] = useState(true);
|
|
101
|
+
const [error, setError] = useState('');
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
let live = true;
|
|
104
|
+
setLoading(true);
|
|
105
|
+
setError('');
|
|
106
|
+
fetch(`${WIRE_BASE}${section.path}`)
|
|
107
|
+
.then((r) => r.json())
|
|
108
|
+
.then((body) => {
|
|
109
|
+
if (!live) return;
|
|
110
|
+
const data = Array.isArray(body) ? body : Array.isArray(body?.[section.collection]) ? body[section.collection] : [];
|
|
111
|
+
setRows(data);
|
|
112
|
+
setLoading(false);
|
|
113
|
+
})
|
|
114
|
+
.catch((e) => { if (live) { setError(String(e)); setLoading(false); } });
|
|
115
|
+
return () => { live = false; };
|
|
116
|
+
}, [section.path, section.collection]);
|
|
117
|
+
return { rows, loading, error };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The Activity detail pane fetches the message's FULL record — Postmark's list endpoint
|
|
121
|
+
* deliberately omits bodies + MessageEvents, exactly as the real API does. */
|
|
122
|
+
function useMessageDetails(messageId: string | null): PostmarkRow | null {
|
|
123
|
+
const [detail, setDetail] = useState<PostmarkRow | null>(null);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
let live = true;
|
|
126
|
+
setDetail(null);
|
|
127
|
+
if (!messageId) return;
|
|
128
|
+
fetch(`${WIRE_BASE}/messages/outbound/${encodeURIComponent(messageId)}/details`)
|
|
129
|
+
.then((r) => r.json())
|
|
130
|
+
.then((body) => { if (live && body && !body.ErrorCode) setDetail(body); })
|
|
131
|
+
.catch(() => { /* the detail pane degrades to the list row */ });
|
|
132
|
+
return () => { live = false; };
|
|
133
|
+
}, [messageId]);
|
|
134
|
+
return detail;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function App() {
|
|
138
|
+
const [sectionKey, setSectionKey] = useState<string>(POSTMARK_MIRROR_SECTIONS[0]!.key);
|
|
139
|
+
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
140
|
+
const section = POSTMARK_MIRROR_SECTIONS.find((s) => s.key === sectionKey)!;
|
|
141
|
+
const { rows, loading, error } = useCollection(section);
|
|
142
|
+
const selected = useMemo(
|
|
143
|
+
() => rows.find((r) => String(r[section.idKey]) === selectedId) ?? rows[0] ?? null,
|
|
144
|
+
[rows, selectedId, section.idKey],
|
|
145
|
+
);
|
|
146
|
+
const isMessages = section.key === 'messages';
|
|
147
|
+
const details = useMessageDetails(isMessages && selected ? String(selected.MessageID) : null);
|
|
148
|
+
const shown = details ?? selected;
|
|
149
|
+
const lines = useMemo(() => (shown ? flattenPostmarkValue(shown) : []), [shown]);
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<div className="app">
|
|
153
|
+
<header className="topbar">
|
|
154
|
+
<span className="brand">Postmark twin</span>
|
|
155
|
+
<span className="subtitle">local transactional email mirror — activity · bounces · templates · streams</span>
|
|
156
|
+
</header>
|
|
157
|
+
<div className="body">
|
|
158
|
+
<nav className="nav">
|
|
159
|
+
{POSTMARK_MIRROR_SECTIONS.map((s) => (
|
|
160
|
+
<button
|
|
161
|
+
key={s.key}
|
|
162
|
+
className={`nav-item ${s.key === sectionKey ? 'active' : ''}`}
|
|
163
|
+
onClick={() => { setSectionKey(s.key); setSelectedId(null); }}
|
|
164
|
+
>
|
|
165
|
+
{s.label}
|
|
166
|
+
</button>
|
|
167
|
+
))}
|
|
168
|
+
</nav>
|
|
169
|
+
<section className="list">
|
|
170
|
+
<div className="list-head">{section.label}{!loading ? ` (${rows.length})` : ''}</div>
|
|
171
|
+
{loading && <div className="empty">Loading…</div>}
|
|
172
|
+
{error && <div className="empty error">{error}</div>}
|
|
173
|
+
{!loading && !error && rows.length === 0 && <div className="empty">No {section.label.toLowerCase()} yet.</div>}
|
|
174
|
+
{rows.map((r, i) => (
|
|
175
|
+
<button
|
|
176
|
+
key={`${String(r[section.idKey])}-${i}`}
|
|
177
|
+
className={`row ${selected && String(selected[section.idKey]) === String(r[section.idKey]) ? 'selected' : ''}`}
|
|
178
|
+
onClick={() => setSelectedId(String(r[section.idKey]))}
|
|
179
|
+
>
|
|
180
|
+
<div className="row-title">{rowTitle(section, r)}</div>
|
|
181
|
+
<div className="row-sub mono">{rowSubtitle(section, r)}</div>
|
|
182
|
+
</button>
|
|
183
|
+
))}
|
|
184
|
+
</section>
|
|
185
|
+
<aside className="detail">
|
|
186
|
+
{shown ? (
|
|
187
|
+
<>
|
|
188
|
+
<div className="detail-head">
|
|
189
|
+
<span className="mono">{String(shown[section.idKey] ?? '')}</span>
|
|
190
|
+
<StatusPill value={rowStatus(section, shown)} />
|
|
191
|
+
</div>
|
|
192
|
+
{isMessages && (
|
|
193
|
+
<div className="message-view">
|
|
194
|
+
<div className="message-meta mono">
|
|
195
|
+
<div>from {String(shown.From ?? '—')}</div>
|
|
196
|
+
<div>to {recipientsOf(shown)}</div>
|
|
197
|
+
<div>{formatPostmarkDate(shown.ReceivedAt)} · stream {String(shown.MessageStream ?? '—')}</div>
|
|
198
|
+
</div>
|
|
199
|
+
<DeliveryTimeline message={shown} />
|
|
200
|
+
<MessageBody message={shown} />
|
|
201
|
+
</div>
|
|
202
|
+
)}
|
|
203
|
+
<NestedLines lines={lines} />
|
|
204
|
+
</>
|
|
205
|
+
) : (
|
|
206
|
+
<div className="empty">Select a record.</div>
|
|
207
|
+
)}
|
|
208
|
+
</aside>
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Browser-only mount. Guarded so the exported presentational components (StatusPill,
|
|
215
|
+
// MessageBody, DeliveryTimeline, NestedLines) can be imported and renderToStaticMarkup'd in a
|
|
216
|
+
// DOM-less test/SSR environment (the data-coupled UI verifies) without this top-level
|
|
217
|
+
// `document` access throwing. The browser bundle still mounts exactly as before.
|
|
218
|
+
if (typeof document !== 'undefined') {
|
|
219
|
+
const rootEl = document.getElementById('root');
|
|
220
|
+
if (rootEl) createRoot(rootEl).render(<App />);
|
|
221
|
+
}
|