@sendmux/core 1.0.0 → 1.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 +21 -0
- package/README.md +49 -3
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +9 -3
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sendmux
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,13 +1,59 @@
|
|
|
1
1
|
# @sendmux/core
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@sendmux/core)
|
|
4
|
+
[](https://github.com/Sendmux/sendmux-sdk/actions/workflows/ci.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/@sendmux/core)
|
|
6
|
+
[](https://github.com/Sendmux/sendmux-sdk/blob/main/LICENSE)
|
|
7
|
+
|
|
3
8
|
Shared runtime helpers and public types for the Sendmux TypeScript SDK packages.
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
## Documentation
|
|
11
|
+
|
|
12
|
+
- Sendmux docs: [sendmux.ai/docs](https://sendmux.ai/docs)
|
|
13
|
+
- Source repository: [Sendmux/sendmux-sdk](https://github.com/Sendmux/sendmux-sdk)
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- A JavaScript runtime with the standard Fetch API.
|
|
18
|
+
- A surface package such as `@sendmux/sending`, `@sendmux/mailbox`, or `@sendmux/management` for API operations.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
6
21
|
|
|
7
22
|
```sh
|
|
8
23
|
npm install @sendmux/core
|
|
9
24
|
```
|
|
10
25
|
|
|
11
|
-
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Validate a key prefix and prepare request headers before calling a surface package.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import {
|
|
32
|
+
assertApiKeyKind,
|
|
33
|
+
conditionalHeaders,
|
|
34
|
+
idempotencyHeaders,
|
|
35
|
+
} from "@sendmux/core";
|
|
36
|
+
|
|
37
|
+
assertApiKeyKind(process.env.SENDMUX_MAILBOX_API_KEY!, "mailbox");
|
|
38
|
+
|
|
39
|
+
const headers = {
|
|
40
|
+
...idempotencyHeaders("idem_123"),
|
|
41
|
+
...conditionalHeaders({ ifNoneMatch: 'W/"etag"' }),
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Helpers
|
|
46
|
+
|
|
47
|
+
- `assertApiKeyKind` validates `smx_root_*` prefixes for root clients, send-capable `smx_mbx_*` prefixes or owner-approved Sending-resource `smx_agent_*` tokens for Sending clients, and mailbox-compatible `smx_mbx_*` or `smx_agent_*` prefixes for Mailbox clients.
|
|
48
|
+
- `paginate` iterates cursor-paginated Sendmux list responses.
|
|
49
|
+
- `idempotencyHeaders`, `conditionalHeaders`, and `responseEtag` cover idempotency and conditional requests.
|
|
50
|
+
- `createRetryingFetch` retries safe requests and idempotent `POST` requests with replayable bodies.
|
|
51
|
+
- `SendmuxApiError`, `mapApiError`, and `createErrorInterceptor` normalise API errors.
|
|
52
|
+
|
|
53
|
+
## Support
|
|
54
|
+
|
|
55
|
+
Open an issue in [Sendmux/sendmux-sdk](https://github.com/Sendmux/sendmux-sdk/issues) with the package name and version.
|
|
56
|
+
|
|
57
|
+
## Licence
|
|
12
58
|
|
|
13
|
-
|
|
59
|
+
MIT. See the [licence file](https://github.com/Sendmux/sendmux-sdk/blob/main/LICENSE).
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU,CAoBlF;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMrF"}
|
package/dist/auth.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export function assertApiKeyKind(apiKey, expected) {
|
|
2
|
-
const
|
|
2
|
+
const isMailboxKey = apiKey.startsWith("smx_mbx_");
|
|
3
|
+
const isAgentToken = apiKey.startsWith("smx_agent_");
|
|
4
|
+
const actual = isMailboxKey || isAgentToken ? "mailbox" : apiKey.startsWith("smx_root_") ? "root" : undefined;
|
|
3
5
|
if (!actual) {
|
|
4
|
-
throw new Error("Sendmux API keys must start with smx_root_ or
|
|
6
|
+
throw new Error("Sendmux API keys must start with smx_root_, smx_mbx_, or smx_agent_");
|
|
5
7
|
}
|
|
6
|
-
|
|
8
|
+
const isCompatible = !expected ||
|
|
9
|
+
actual === expected ||
|
|
10
|
+
(expected === "sending" && (isMailboxKey || isAgentToken)) ||
|
|
11
|
+
(expected === "mailbox" && actual === "mailbox");
|
|
12
|
+
if (!isCompatible) {
|
|
7
13
|
throw new Error(`Expected a ${expected} API key, received a ${actual} API key`);
|
|
8
14
|
}
|
|
9
15
|
return actual;
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAExD,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,GAAG,YAAY;IACpE,EA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