@open-send/sdk 0.0.0-stage → 1.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.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OpenSend
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md CHANGED
@@ -1,3 +1,144 @@
1
- # Temporary Holding Version
1
+ # @open-send/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The TypeScript SDK of OpenSend, the open source email platform: send and receive email, and
4
+ manage broadcasts, contacts, templates, automations and webhooks from Node.js, Bun, Deno and
5
+ edge runtimes. It has no dependencies.
6
+
7
+ It runs on a server. In a web page it refuses to start, because anyone who opens the page could
8
+ read your API key: call your own server from the page, and the SDK from there.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @open-send/sdk
14
+ ```
15
+
16
+ `bun add @open-send/sdk`, `pnpm add @open-send/sdk` and
17
+ `deno add npm:@open-send/sdk` work the same way.
18
+
19
+ ## Send an email
20
+
21
+ ```ts
22
+ import { OpenSend } from '@open-send/sdk'
23
+
24
+ const opensend = new OpenSend('os_...')
25
+
26
+ const email = await opensend.emails.send(
27
+ {
28
+ from: 'Acme <hello@mail.example.com>',
29
+ to: 'ada@example.com',
30
+ subject: 'Your receipt for November',
31
+ html: '<p>Thanks for your order.</p>',
32
+ },
33
+ { idempotencyKey: 'order-1042' },
34
+ )
35
+
36
+ console.log(email.id, email.status)
37
+ ```
38
+
39
+ Every call returns what the API answered, and throws `OpenSendError` when the API refuses or
40
+ the call fails.
41
+
42
+ ## Settings
43
+
44
+ | Variable | Option | What it sets |
45
+ | --- | --- | --- |
46
+ | `OPENSEND_API_KEY` | `new OpenSend(key)` | The API key. Make one in the dashboard, under API keys |
47
+ | `OPENSEND_API_URL` | `baseUrl` | The address of the API: `https://api.opensend.sh` unless you name your own server |
48
+ | | `timeoutMs` | How long a call may take: 30 seconds unless you change it |
49
+ | | `fetch` | A fetch of your own, for tests or a proxy |
50
+
51
+ What you pass to `new OpenSend()` wins over the environment.
52
+
53
+ ## Your own server
54
+
55
+ When you host OpenSend yourself, point the SDK at your server: the address people open your
56
+ dashboard at. The SDK adds `/v1` itself.
57
+
58
+ ```ts
59
+ const opensend = new OpenSend('os_...', { baseUrl: 'https://mail.example.com' })
60
+ ```
61
+
62
+ Or keep it out of the code:
63
+
64
+ ```bash
65
+ OPENSEND_API_KEY=os_... OPENSEND_API_URL=https://mail.example.com node app.js
66
+ ```
67
+
68
+ Make the key in your server's dashboard: a key of our cloud does not work on your server, and
69
+ the other way round. The address must be `https`, or plain `http` on this computer
70
+ (`localhost`, `127.0.0.1` or `[::1]`). The command line takes the same address with
71
+ `opensend login --api-url https://mail.example.com`, and reads the same two variables.
72
+
73
+ ## Calls
74
+
75
+ - There is one call for each method of the API, written `opensend.<group>.<action>`, such as
76
+ `opensend.contacts.create(...)`. The inputs and the answers are typed from the API's own
77
+ schemas, and your editor shows the description of every field.
78
+ - A method whose address holds an id takes the id first: `opensend.emails.get('em_...')`, or
79
+ `opensend.runs.get('run_...', { automationId: 'aut_...' })` when it needs more.
80
+ - Every call takes `{ signal }` as its last argument, so an `AbortSignal` can give it up.
81
+ `emails.send`, `emails.batch` and `events.send` also take `{ idempotencyKey }`: a repeat
82
+ with the same key answers with the first result and sends nothing twice.
83
+
84
+ ## Errors
85
+
86
+ `OpenSendError` carries `status`, `code`, `type`, `requestId` and `cause`. The code is the
87
+ API's own when it answered, such as `validation_error` or `not_found`, and otherwise one of
88
+ these:
89
+
90
+ | Code | When |
91
+ | --- | --- |
92
+ | `missing_api_key` | No key was given, and none is in the environment |
93
+ | `browser_refused` | The client was made in a web page. It runs on a server only |
94
+ | `invalid_option` | An address that is not `https`, or a timeout that is not whole milliseconds |
95
+ | `missing_parameter` | A value the address needs, such as an id, is missing |
96
+ | `network_error` | The API could not be reached. `cause` holds what failed |
97
+ | `timeout` | The API did not answer in time |
98
+ | `aborted` | Your signal gave the call up |
99
+ | `unexpected_response` | The API answered with something that is not JSON |
100
+ | `invalid_signature` | A webhook's signature is missing, too old or wrong |
101
+
102
+ ## Webhooks
103
+
104
+ ```ts
105
+ import { OPENSEND_SIGNATURE_HEADER, verifyWebhook } from '@open-send/sdk'
106
+
107
+ const event = await verifyWebhook({
108
+ payload: rawBody,
109
+ signature: request.headers.get(OPENSEND_SIGNATURE_HEADER),
110
+ secret: process.env.OPENSEND_WEBHOOK_SECRET ?? '',
111
+ })
112
+ ```
113
+
114
+ It checks the raw body against the signing secret of your endpoint, refuses a delivery more
115
+ than five minutes old, and answers with the event.
116
+
117
+ ## Types
118
+
119
+ `OpenSendInputs` and `OpenSendOutputs` name the input and the answer of every call, such as
120
+ `OpenSendInputs['emails']['send']`, and `OpenSend` is the type of a client.
121
+
122
+ ## Versions
123
+
124
+ The SDK follows semantic versioning. A minor version adds methods, optional fields or error
125
+ codes, and a major version is the only one that removes or changes them. The hosted API keeps
126
+ every 1.x version working. It needs Node.js 20.3 or newer, and ships as ES modules and
127
+ CommonJS.
128
+
129
+ - Docs: https://opensend.sh/docs/sdk
130
+ - Changelog: https://opensend.sh/changelog/sdk
131
+
132
+ ## Security
133
+
134
+ Report a vulnerability privately to support@opensend.sh, not in a public issue.
135
+ https://opensend.sh/.well-known/security.txt says the same, and https://opensend.sh/security
136
+ describes how keys, sign-in and webhooks are protected.
137
+
138
+ ## Support
139
+
140
+ Questions and problems: https://opensend.sh/contact, or support@opensend.sh.
141
+
142
+ ## License
143
+
144
+ MIT