@trycourier/courier 7.2.0 → 7.7.1
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/CHANGELOG.md +123 -0
- package/LICENSE +1 -1
- package/README.md +34 -345
- package/client.d.mts +50 -9
- package/client.d.mts.map +1 -1
- package/client.d.ts +50 -9
- package/client.d.ts.map +1 -1
- package/client.js +17 -4
- package/client.js.map +1 -1
- package/client.mjs +18 -5
- package/client.mjs.map +1 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +5 -0
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +5 -0
- package/internal/parse.mjs.map +1 -1
- package/internal/utils/query.d.mts +2 -0
- package/internal/utils/query.d.mts.map +1 -0
- package/internal/utils/query.d.ts +2 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +10 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +6 -0
- package/internal/utils/query.mjs.map +1 -0
- package/internal/utils.d.mts +1 -0
- package/internal/utils.d.ts +1 -0
- package/internal/utils.js +1 -0
- package/internal/utils.js.map +1 -1
- package/internal/utils.mjs +1 -0
- package/package.json +1 -1
- package/resources/audiences.d.mts +11 -33
- package/resources/audiences.d.mts.map +1 -1
- package/resources/audiences.d.ts +11 -33
- package/resources/audiences.d.ts.map +1 -1
- package/resources/automations/automations.d.mts +54 -1
- package/resources/automations/automations.d.mts.map +1 -1
- package/resources/automations/automations.d.ts +54 -1
- package/resources/automations/automations.d.ts.map +1 -1
- package/resources/automations/automations.js +12 -0
- package/resources/automations/automations.js.map +1 -1
- package/resources/automations/automations.mjs +12 -0
- package/resources/automations/automations.mjs.map +1 -1
- package/resources/automations/index.d.mts +1 -1
- package/resources/automations/index.d.mts.map +1 -1
- package/resources/automations/index.d.ts +1 -1
- package/resources/automations/index.d.ts.map +1 -1
- package/resources/automations/index.js.map +1 -1
- package/resources/automations/index.mjs +1 -1
- package/resources/automations/index.mjs.map +1 -1
- package/resources/bulk.d.mts +80 -39
- package/resources/bulk.d.mts.map +1 -1
- package/resources/bulk.d.ts +80 -39
- package/resources/bulk.d.ts.map +1 -1
- package/resources/bulk.js +12 -2
- package/resources/bulk.js.map +1 -1
- package/resources/bulk.mjs +12 -2
- package/resources/bulk.mjs.map +1 -1
- package/resources/inbound.d.mts +1 -1
- package/resources/inbound.d.ts +1 -1
- package/resources/index.d.mts +3 -3
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +3 -3
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/lists/subscriptions.d.mts +1 -1
- package/resources/lists/subscriptions.d.ts +1 -1
- package/resources/notifications/checks.d.mts +2 -2
- package/resources/notifications/checks.d.ts +2 -2
- package/resources/send.d.mts +8 -2
- package/resources/send.d.mts.map +1 -1
- package/resources/send.d.ts +8 -2
- package/resources/send.d.ts.map +1 -1
- package/resources/send.js +1 -1
- package/resources/send.mjs +1 -1
- package/resources/shared.d.mts +301 -49
- package/resources/shared.d.mts.map +1 -1
- package/resources/shared.d.ts +301 -49
- package/resources/shared.d.ts.map +1 -1
- package/resources/tenants/index.d.mts +2 -2
- package/resources/tenants/index.d.mts.map +1 -1
- package/resources/tenants/index.d.ts +2 -2
- package/resources/tenants/index.d.ts.map +1 -1
- package/resources/tenants/index.js +2 -2
- package/resources/tenants/index.js.map +1 -1
- package/resources/tenants/index.mjs +1 -1
- package/resources/tenants/index.mjs.map +1 -1
- package/resources/tenants/preferences/items.d.mts +2 -2
- package/resources/tenants/preferences/items.d.ts +2 -2
- package/resources/tenants/templates/index.d.mts +3 -0
- package/resources/tenants/templates/index.d.mts.map +1 -0
- package/resources/tenants/templates/index.d.ts +3 -0
- package/resources/tenants/templates/index.d.ts.map +1 -0
- package/resources/tenants/templates/index.js +9 -0
- package/resources/tenants/templates/index.js.map +1 -0
- package/resources/tenants/templates/index.mjs +4 -0
- package/resources/tenants/templates/index.mjs.map +1 -0
- package/resources/tenants/templates/templates.d.mts +159 -0
- package/resources/tenants/templates/templates.d.mts.map +1 -0
- package/resources/tenants/templates/templates.d.ts +159 -0
- package/resources/tenants/templates/templates.d.ts.map +1 -0
- package/resources/tenants/templates/templates.js +91 -0
- package/resources/tenants/templates/templates.js.map +1 -0
- package/resources/tenants/templates/templates.mjs +86 -0
- package/resources/tenants/templates/templates.mjs.map +1 -0
- package/resources/tenants/templates/versions.d.mts +39 -0
- package/resources/tenants/templates/versions.d.mts.map +1 -0
- package/resources/tenants/templates/versions.d.ts +39 -0
- package/resources/tenants/templates/versions.d.ts.map +1 -0
- package/resources/tenants/templates/versions.js +32 -0
- package/resources/tenants/templates/versions.js.map +1 -0
- package/resources/tenants/templates/versions.mjs +28 -0
- package/resources/tenants/templates/versions.mjs.map +1 -0
- package/resources/tenants/templates.d.mts +1 -90
- package/resources/tenants/templates.d.mts.map +1 -1
- package/resources/tenants/templates.d.ts +1 -90
- package/resources/tenants/templates.d.ts.map +1 -1
- package/resources/tenants/templates.js +2 -34
- package/resources/tenants/templates.js.map +1 -1
- package/resources/tenants/templates.mjs +1 -32
- package/resources/tenants/templates.mjs.map +1 -1
- package/resources/tenants/tenants.d.mts +147 -5
- package/resources/tenants/tenants.d.mts.map +1 -1
- package/resources/tenants/tenants.d.ts +147 -5
- package/resources/tenants/tenants.d.ts.map +1 -1
- package/resources/tenants/tenants.js +2 -2
- package/resources/tenants/tenants.js.map +1 -1
- package/resources/tenants/tenants.mjs +2 -2
- package/resources/tenants/tenants.mjs.map +1 -1
- package/resources/translations.d.mts +1 -1
- package/resources/translations.d.ts +1 -1
- package/resources/users/preferences.d.mts +1 -1
- package/resources/users/preferences.d.ts +1 -1
- package/resources/users/tenants.d.mts +1 -1
- package/resources/users/tenants.d.ts +1 -1
- package/resources/users/tokens.d.mts +7 -12
- package/resources/users/tokens.d.mts.map +1 -1
- package/resources/users/tokens.d.ts +7 -12
- package/resources/users/tokens.d.ts.map +1 -1
- package/resources/users/tokens.js +3 -6
- package/resources/users/tokens.js.map +1 -1
- package/resources/users/tokens.mjs +3 -6
- package/resources/users/tokens.mjs.map +1 -1
- package/src/client.ts +88 -15
- package/src/internal/parse.ts +6 -0
- package/src/internal/utils/query.ts +7 -0
- package/src/internal/utils.ts +1 -0
- package/src/resources/audiences.ts +11 -69
- package/src/resources/automations/automations.ts +74 -1
- package/src/resources/automations/index.ts +7 -1
- package/src/resources/bulk.ts +71 -32
- package/src/resources/inbound.ts +1 -1
- package/src/resources/index.ts +12 -3
- package/src/resources/lists/subscriptions.ts +1 -1
- package/src/resources/notifications/checks.ts +2 -2
- package/src/resources/send.ts +28 -2
- package/src/resources/shared.ts +402 -46
- package/src/resources/tenants/index.ts +8 -1
- package/src/resources/tenants/preferences/items.ts +2 -2
- package/src/resources/tenants/templates/index.ts +11 -0
- package/src/resources/tenants/templates/templates.ts +222 -0
- package/src/resources/tenants/templates/versions.ts +55 -0
- package/src/resources/tenants/templates.ts +1 -122
- package/src/resources/tenants/tenants.ts +179 -3
- package/src/resources/translations.ts +1 -1
- package/src/resources/users/preferences.ts +1 -1
- package/src/resources/users/tenants.ts +1 -1
- package/src/resources/users/tokens.ts +8 -14
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,128 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 7.7.1 (2026-03-03)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [v7.7.0...v7.7.1](https://github.com/trycourier/courier-node/compare/v7.7.0...v7.7.1)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* **api:** remove body_token parameter from tokens.addSingle method ([b8de6f7](https://github.com/trycourier/courier-node/commit/b8de6f7d6c936dce1b5e458b881635a4e0d920e4))
|
|
10
|
+
* **api:** remove brand field from ElementalContent ([2a3d25d](https://github.com/trycourier/courier-node/commit/2a3d25dac9b544179e928800dba0f53623cd3734))
|
|
11
|
+
* **docs/contributing:** correct pnpm link command ([d3b4a96](https://github.com/trycourier/courier-node/commit/d3b4a96b0d1112692832cff49bfd7897ec77df8c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Chores
|
|
15
|
+
|
|
16
|
+
* **internal/client:** fix form-urlencoded requests ([45deac0](https://github.com/trycourier/courier-node/commit/45deac06aa22be68b4ac57136d065dd85668901c))
|
|
17
|
+
* **internal:** avoid type checking errors with ts-reset ([88b8c18](https://github.com/trycourier/courier-node/commit/88b8c18a47ac0d71e5a58274eeb705b41dfb42c3))
|
|
18
|
+
* **internal:** codegen related update ([879dd2f](https://github.com/trycourier/courier-node/commit/879dd2f830081dd643bff1afafe1a4f3413f80c1))
|
|
19
|
+
* **internal:** remove mock server code ([cbd7d67](https://github.com/trycourier/courier-node/commit/cbd7d675567742542d481cf9275fa765524f2dae))
|
|
20
|
+
* update mock server docs ([f4a7c1f](https://github.com/trycourier/courier-node/commit/f4a7c1f3590b16463dd8edb1ef81a188ae276d06))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Documentation
|
|
24
|
+
|
|
25
|
+
* add AUTO-GENERATED-OVERVIEW markers for README sync ([#228](https://github.com/trycourier/courier-node/issues/228)) ([63dc300](https://github.com/trycourier/courier-node/commit/63dc300ce3d67d339942446c86edeaa0f4aa69ee))
|
|
26
|
+
* sync README from mintlify-docs (2026-02-20 18:11 UTC) ([#229](https://github.com/trycourier/courier-node/issues/229)) ([f35a2aa](https://github.com/trycourier/courier-node/commit/f35a2aa144409b12c125a564a003421a9b8a7a5b))
|
|
27
|
+
|
|
28
|
+
## 7.7.0 (2026-02-06)
|
|
29
|
+
|
|
30
|
+
Full Changelog: [v7.6.3...v7.7.0](https://github.com/trycourier/courier-node/compare/v7.6.3...v7.7.0)
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* **api:** add publish/replace methods to tenants.templates, versions sub-resource ([a479e13](https://github.com/trycourier/courier-node/commit/a479e1356e4c924dd93959faccc2f0bc5b220706))
|
|
35
|
+
* **api:** support array of recipients in send message to parameter ([e122396](https://github.com/trycourier/courier-node/commit/e1223964750961c6605fce9b5534b7f47c5912e4))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Bug Fixes
|
|
39
|
+
|
|
40
|
+
* **client:** avoid memory leak with abort signals ([456f32b](https://github.com/trycourier/courier-node/commit/456f32b5857119e3bce1b98d684452089f0dac25))
|
|
41
|
+
* **client:** avoid removing abort listener too early ([955a0ac](https://github.com/trycourier/courier-node/commit/955a0acd0c3562b8744f2d6ebcfc1a3afd3a81f0))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Chores
|
|
45
|
+
|
|
46
|
+
* **client:** do not parse responses with empty content-length ([f6a0da2](https://github.com/trycourier/courier-node/commit/f6a0da2fc5de72f899350b471e635a26ae5fe22b))
|
|
47
|
+
* **client:** restructure abort controller binding ([ebbf307](https://github.com/trycourier/courier-node/commit/ebbf30710e44dfe85ffd89a021c102381210f61c))
|
|
48
|
+
|
|
49
|
+
## 7.6.3 (2026-01-27)
|
|
50
|
+
|
|
51
|
+
Full Changelog: [v7.6.2...v7.6.3](https://github.com/trycourier/courier-node/compare/v7.6.2...v7.6.3)
|
|
52
|
+
|
|
53
|
+
### Chores
|
|
54
|
+
|
|
55
|
+
* **ci:** upgrade `actions/github-script` ([9be20f2](https://github.com/trycourier/courier-node/commit/9be20f262f8e308e07f27d7f577c029a24a5729c))
|
|
56
|
+
* **internal:** update `actions/checkout` version ([ff49d84](https://github.com/trycourier/courier-node/commit/ff49d84985ceb2f0abd1a1672d060f171fb4773e))
|
|
57
|
+
* **internal:** upgrade babel, qs, js-yaml ([69281b2](https://github.com/trycourier/courier-node/commit/69281b23561b6dc18cf5da460a3cfc4dc3563936))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Documentation
|
|
61
|
+
|
|
62
|
+
* **types:** clarify version field description in AutomationTemplate ([3b61dec](https://github.com/trycourier/courier-node/commit/3b61dec839fd7e97f8cb8877d045d2a53dcca809))
|
|
63
|
+
|
|
64
|
+
## 7.6.2 (2026-01-14)
|
|
65
|
+
|
|
66
|
+
Full Changelog: [v7.6.1...v7.6.2](https://github.com/trycourier/courier-node/compare/v7.6.1...v7.6.2)
|
|
67
|
+
|
|
68
|
+
### Chores
|
|
69
|
+
|
|
70
|
+
* fix typo in descriptions ([3e9304a](https://github.com/trycourier/courier-node/commit/3e9304abd0cb3ee2905a1c8ef2ca6add6de40d76))
|
|
71
|
+
* **internal:** regenerate SDK with no functional changes ([1eabb0d](https://github.com/trycourier/courier-node/commit/1eabb0d4747af6eb1077c56d0c701de3dfc4720d))
|
|
72
|
+
* **internal:** regenerate SDK with no functional changes ([fdf454c](https://github.com/trycourier/courier-node/commit/fdf454c4f56a9562eb4821d067a0dda22e8af4df))
|
|
73
|
+
* remove custom code ([68b45da](https://github.com/trycourier/courier-node/commit/68b45da055191f5b0a86995791dc5880dbed29e4))
|
|
74
|
+
|
|
75
|
+
## 7.6.1 (2026-01-12)
|
|
76
|
+
|
|
77
|
+
Full Changelog: [v7.6.0...v7.6.1](https://github.com/trycourier/courier-node/compare/v7.6.0...v7.6.1)
|
|
78
|
+
|
|
79
|
+
### Bug Fixes
|
|
80
|
+
|
|
81
|
+
* **types:** correct rules field type in NestedFilterConfig ([20636ec](https://github.com/trycourier/courier-node/commit/20636ecec7405c9c5370ac0842a8cf70a9cd16bc))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
### Chores
|
|
85
|
+
|
|
86
|
+
* **internal:** regenerate SDK with no functional changes ([2230886](https://github.com/trycourier/courier-node/commit/22308868766859b3e40cf9854bec627a4a3680b1))
|
|
87
|
+
|
|
88
|
+
## 7.6.0 (2026-01-08)
|
|
89
|
+
|
|
90
|
+
Full Changelog: [v7.5.0...v7.6.0](https://github.com/trycourier/courier-node/compare/v7.5.0...v7.6.0)
|
|
91
|
+
|
|
92
|
+
### Features
|
|
93
|
+
|
|
94
|
+
* **api:** remove methods across audit-events/brands/bulk/automations/translations/tenants ([459d7de](https://github.com/trycourier/courier-node/commit/459d7deb6ec73b2f06de57c590b46f26b157f15b))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
### Chores
|
|
98
|
+
|
|
99
|
+
* break long lines in snippets into multiline ([3c43d25](https://github.com/trycourier/courier-node/commit/3c43d2512f4bb4937fb40db54de74221d7d115ef))
|
|
100
|
+
|
|
101
|
+
## 7.5.0 (2025-12-29)
|
|
102
|
+
|
|
103
|
+
Full Changelog: [v7.4.0...v7.5.0](https://github.com/trycourier/courier-node/compare/v7.4.0...v7.5.0)
|
|
104
|
+
|
|
105
|
+
### Features
|
|
106
|
+
|
|
107
|
+
* **api:** add audience/slack/ms_teams/pagerduty/webhook recipient types to send.message ([236fa8b](https://github.com/trycourier/courier-node/commit/236fa8bfddfd5261c0058b78d7d44d0e060728e9))
|
|
108
|
+
|
|
109
|
+
## 7.4.0 (2025-12-16)
|
|
110
|
+
|
|
111
|
+
Full Changelog: [v7.3.0...v7.4.0](https://github.com/trycourier/courier-node/compare/v7.3.0...v7.4.0)
|
|
112
|
+
|
|
113
|
+
### Features
|
|
114
|
+
|
|
115
|
+
* Add timezone field to Delay schema ([30ff0dd](https://github.com/trycourier/courier-node/commit/30ff0dd269c78f2025c68c8ff161bb88027e381f))
|
|
116
|
+
* Update bulk API spec: make event required, document profile.email req… ([ec59104](https://github.com/trycourier/courier-node/commit/ec5910407ff2f6b5f7f11699ac4a275d0b6c9375))
|
|
117
|
+
|
|
118
|
+
## 7.3.0 (2025-12-08)
|
|
119
|
+
|
|
120
|
+
Full Changelog: [v7.2.0...v7.3.0](https://github.com/trycourier/courier-node/compare/v7.2.0...v7.3.0)
|
|
121
|
+
|
|
122
|
+
### Features
|
|
123
|
+
|
|
124
|
+
* Fix UsersGetAllTokensResponse to return object with tokens property i… ([18b27ab](https://github.com/trycourier/courier-node/commit/18b27abc52af02b8b50b8b87ea7edc51cd9f56c8))
|
|
125
|
+
|
|
3
126
|
## 7.2.0 (2025-12-08)
|
|
4
127
|
|
|
5
128
|
Full Changelog: [v7.1.1...v7.2.0](https://github.com/trycourier/courier-node/compare/v7.1.1...v7.2.0)
|
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2026 Courier
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -1,375 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- AUTO-GENERATED-OVERVIEW:START — Do not edit this section. It is synced from mintlify-docs. -->
|
|
2
|
+
# Courier Node.js SDK
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This library provides convenient access to the Courier REST API from server-side TypeScript or JavaScript.
|
|
6
|
-
|
|
7
|
-
The REST API documentation can be found on [www.courier.com](https://www.courier.com/docs). The full API of this library can be found in [api.md](api.md).
|
|
8
|
-
|
|
9
|
-
It is generated with [Stainless](https://www.stainless.com/).
|
|
4
|
+
The Courier Node.js SDK provides typed access to the Courier REST API from server-side TypeScript or JavaScript. Use it to send notifications, manage user profiles, check message status, issue JWT tokens for client-side SDKs, and more.
|
|
10
5
|
|
|
11
6
|
## Installation
|
|
12
7
|
|
|
13
|
-
```
|
|
8
|
+
```bash
|
|
14
9
|
npm install @trycourier/courier
|
|
15
10
|
```
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
The full API of this library can be found in [api.md](api.md).
|
|
20
|
-
|
|
21
|
-
<!-- prettier-ignore -->
|
|
22
|
-
```js
|
|
23
|
-
import Courier from '@trycourier/courier';
|
|
24
|
-
|
|
25
|
-
const client = new Courier({
|
|
26
|
-
apiKey: process.env['COURIER_API_KEY'], // This is the default and can be omitted
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const response = await client.send.message({
|
|
30
|
-
message: { to: { user_id: 'your_user_id' }, template: 'your_template_id', data: { foo: 'bar' } },
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
console.log(response.requestId);
|
|
34
|
-
```
|
|
12
|
+
Also available via `yarn add @trycourier/courier` and `pnpm add @trycourier/courier`.
|
|
35
13
|
|
|
36
|
-
|
|
14
|
+
Requires Node.js 20+ (LTS). Also works in Deno 1.28+, Bun 1.0+, Cloudflare Workers, and Vercel Edge Runtime.
|
|
37
15
|
|
|
38
|
-
|
|
16
|
+
## Quick Start
|
|
39
17
|
|
|
40
|
-
<!-- prettier-ignore -->
|
|
41
18
|
```ts
|
|
42
19
|
import Courier from '@trycourier/courier';
|
|
43
20
|
|
|
44
|
-
const client = new Courier({
|
|
45
|
-
apiKey: process.env['COURIER_API_KEY'], // This is the default and can be omitted
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const params: Courier.SendMessageParams = {
|
|
49
|
-
message: { to: { user_id: 'your_user_id' }, template: 'your_template_id', data: { foo: 'bar' } },
|
|
50
|
-
};
|
|
51
|
-
const response: Courier.SendMessageResponse = await client.send.message(params);
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
|
|
55
|
-
|
|
56
|
-
## Handling errors
|
|
57
|
-
|
|
58
|
-
When the library is unable to connect to the API,
|
|
59
|
-
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
|
|
60
|
-
a subclass of `APIError` will be thrown:
|
|
61
|
-
|
|
62
|
-
<!-- prettier-ignore -->
|
|
63
|
-
```ts
|
|
64
|
-
const response = await client.send
|
|
65
|
-
.message({
|
|
66
|
-
message: { to: { user_id: 'your_user_id' }, template: 'your_template_id', data: { foo: 'bar' } },
|
|
67
|
-
})
|
|
68
|
-
.catch(async (err) => {
|
|
69
|
-
if (err instanceof Courier.APIError) {
|
|
70
|
-
console.log(err.status); // 400
|
|
71
|
-
console.log(err.name); // BadRequestError
|
|
72
|
-
console.log(err.headers); // {server: 'nginx', ...}
|
|
73
|
-
} else {
|
|
74
|
-
throw err;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Error codes are as follows:
|
|
80
|
-
|
|
81
|
-
| Status Code | Error Type |
|
|
82
|
-
| ----------- | -------------------------- |
|
|
83
|
-
| 400 | `BadRequestError` |
|
|
84
|
-
| 401 | `AuthenticationError` |
|
|
85
|
-
| 403 | `PermissionDeniedError` |
|
|
86
|
-
| 404 | `NotFoundError` |
|
|
87
|
-
| 422 | `UnprocessableEntityError` |
|
|
88
|
-
| 429 | `RateLimitError` |
|
|
89
|
-
| >=500 | `InternalServerError` |
|
|
90
|
-
| N/A | `APIConnectionError` |
|
|
91
|
-
|
|
92
|
-
### Retries
|
|
93
|
-
|
|
94
|
-
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
|
|
95
|
-
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
|
|
96
|
-
429 Rate Limit, and >=500 Internal errors will all be retried by default.
|
|
97
|
-
|
|
98
|
-
You can use the `maxRetries` option to configure or disable this:
|
|
99
|
-
|
|
100
|
-
<!-- prettier-ignore -->
|
|
101
|
-
```js
|
|
102
|
-
// Configure the default for all requests:
|
|
103
|
-
const client = new Courier({
|
|
104
|
-
maxRetries: 0, // default is 2
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Or, configure per-request:
|
|
108
|
-
await client.send.message({ message: { to: { user_id: 'your_user_id' }, template: 'your_template_id', data: { foo: 'bar' } } }, {
|
|
109
|
-
maxRetries: 5,
|
|
110
|
-
});
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Timeouts
|
|
114
|
-
|
|
115
|
-
Requests time out after 1 minute by default. You can configure this with a `timeout` option:
|
|
116
|
-
|
|
117
|
-
<!-- prettier-ignore -->
|
|
118
|
-
```ts
|
|
119
|
-
// Configure the default for all requests:
|
|
120
|
-
const client = new Courier({
|
|
121
|
-
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Override per-request:
|
|
125
|
-
await client.send.message({ message: { to: { user_id: 'your_user_id' }, template: 'your_template_id', data: { foo: 'bar' } } }, {
|
|
126
|
-
timeout: 5 * 1000,
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
On timeout, an `APIConnectionTimeoutError` is thrown.
|
|
131
|
-
|
|
132
|
-
Note that requests which time out will be [retried twice by default](#retries).
|
|
133
|
-
|
|
134
|
-
## Advanced Usage
|
|
135
|
-
|
|
136
|
-
### Accessing raw Response data (e.g., headers)
|
|
137
|
-
|
|
138
|
-
The "raw" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.
|
|
139
|
-
This method returns as soon as the headers for a successful response are received and does not consume the response body, so you are free to write custom parsing or streaming logic.
|
|
140
|
-
|
|
141
|
-
You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.
|
|
142
|
-
Unlike `.asResponse()` this method consumes the body, returning once it is parsed.
|
|
143
|
-
|
|
144
|
-
<!-- prettier-ignore -->
|
|
145
|
-
```ts
|
|
146
21
|
const client = new Courier();
|
|
147
22
|
|
|
148
|
-
const response = await client.send
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const { data: response, response: raw } = await client.send
|
|
157
|
-
.message({
|
|
158
|
-
message: { to: { user_id: 'your_user_id' }, template: 'your_template_id', data: { foo: 'bar' } },
|
|
159
|
-
})
|
|
160
|
-
.withResponse();
|
|
161
|
-
console.log(raw.headers.get('X-My-Header'));
|
|
162
|
-
console.log(response.requestId);
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Logging
|
|
166
|
-
|
|
167
|
-
> [!IMPORTANT]
|
|
168
|
-
> All log messages are intended for debugging only. The format and content of log messages
|
|
169
|
-
> may change between releases.
|
|
170
|
-
|
|
171
|
-
#### Log levels
|
|
172
|
-
|
|
173
|
-
The log level can be configured in two ways:
|
|
174
|
-
|
|
175
|
-
1. Via the `COURIER_LOG` environment variable
|
|
176
|
-
2. Using the `logLevel` client option (overrides the environment variable if set)
|
|
177
|
-
|
|
178
|
-
```ts
|
|
179
|
-
import Courier from '@trycourier/courier';
|
|
180
|
-
|
|
181
|
-
const client = new Courier({
|
|
182
|
-
logLevel: 'debug', // Show all log messages
|
|
183
|
-
});
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
Available log levels, from most to least verbose:
|
|
187
|
-
|
|
188
|
-
- `'debug'` - Show debug messages, info, warnings, and errors
|
|
189
|
-
- `'info'` - Show info messages, warnings, and errors
|
|
190
|
-
- `'warn'` - Show warnings and errors (default)
|
|
191
|
-
- `'error'` - Show only errors
|
|
192
|
-
- `'off'` - Disable all logging
|
|
193
|
-
|
|
194
|
-
At the `'debug'` level, all HTTP requests and responses are logged, including headers and bodies.
|
|
195
|
-
Some authentication-related headers are redacted, but sensitive data in request and response bodies
|
|
196
|
-
may still be visible.
|
|
197
|
-
|
|
198
|
-
#### Custom logger
|
|
199
|
-
|
|
200
|
-
By default, this library logs to `globalThis.console`. You can also provide a custom logger.
|
|
201
|
-
Most logging libraries are supported, including [pino](https://www.npmjs.com/package/pino), [winston](https://www.npmjs.com/package/winston), [bunyan](https://www.npmjs.com/package/bunyan), [consola](https://www.npmjs.com/package/consola), [signale](https://www.npmjs.com/package/signale), and [@std/log](https://jsr.io/@std/log). If your logger doesn't work, please open an issue.
|
|
202
|
-
|
|
203
|
-
When providing a custom logger, the `logLevel` option still controls which messages are emitted, messages
|
|
204
|
-
below the configured level will not be sent to your logger.
|
|
205
|
-
|
|
206
|
-
```ts
|
|
207
|
-
import Courier from '@trycourier/courier';
|
|
208
|
-
import pino from 'pino';
|
|
209
|
-
|
|
210
|
-
const logger = pino();
|
|
211
|
-
|
|
212
|
-
const client = new Courier({
|
|
213
|
-
logger: logger.child({ name: 'Courier' }),
|
|
214
|
-
logLevel: 'debug', // Send all messages to pino, allowing it to filter
|
|
215
|
-
});
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
### Making custom/undocumented requests
|
|
219
|
-
|
|
220
|
-
This library is typed for convenient access to the documented API. If you need to access undocumented
|
|
221
|
-
endpoints, params, or response properties, the library can still be used.
|
|
222
|
-
|
|
223
|
-
#### Undocumented endpoints
|
|
224
|
-
|
|
225
|
-
To make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.
|
|
226
|
-
Options on the client, such as retries, will be respected when making these requests.
|
|
227
|
-
|
|
228
|
-
```ts
|
|
229
|
-
await client.post('/some/path', {
|
|
230
|
-
body: { some_prop: 'foo' },
|
|
231
|
-
query: { some_query_arg: 'bar' },
|
|
232
|
-
});
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
#### Undocumented request params
|
|
236
|
-
|
|
237
|
-
To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented
|
|
238
|
-
parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you
|
|
239
|
-
send will be sent as-is.
|
|
240
|
-
|
|
241
|
-
```ts
|
|
242
|
-
client.send.message({
|
|
243
|
-
// ...
|
|
244
|
-
// @ts-expect-error baz is not yet public
|
|
245
|
-
baz: 'undocumented option',
|
|
246
|
-
});
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
For requests with the `GET` verb, any extra params will be in the query, all other requests will send the
|
|
250
|
-
extra param in the body.
|
|
251
|
-
|
|
252
|
-
If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request
|
|
253
|
-
options.
|
|
254
|
-
|
|
255
|
-
#### Undocumented response properties
|
|
256
|
-
|
|
257
|
-
To access undocumented response properties, you may access the response object with `// @ts-expect-error` on
|
|
258
|
-
the response object, or cast the response object to the requisite type. Like the request params, we do not
|
|
259
|
-
validate or strip extra properties from the response from the API.
|
|
260
|
-
|
|
261
|
-
### Customizing the fetch client
|
|
262
|
-
|
|
263
|
-
By default, this library expects a global `fetch` function is defined.
|
|
264
|
-
|
|
265
|
-
If you want to use a different `fetch` function, you can either polyfill the global:
|
|
266
|
-
|
|
267
|
-
```ts
|
|
268
|
-
import fetch from 'my-fetch';
|
|
269
|
-
|
|
270
|
-
globalThis.fetch = fetch;
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
Or pass it to the client:
|
|
274
|
-
|
|
275
|
-
```ts
|
|
276
|
-
import Courier from '@trycourier/courier';
|
|
277
|
-
import fetch from 'my-fetch';
|
|
278
|
-
|
|
279
|
-
const client = new Courier({ fetch });
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
### Fetch options
|
|
283
|
-
|
|
284
|
-
If you want to set custom `fetch` options without overriding the `fetch` function, you can provide a `fetchOptions` object when instantiating the client or making a request. (Request-specific options override client options.)
|
|
285
|
-
|
|
286
|
-
```ts
|
|
287
|
-
import Courier from '@trycourier/courier';
|
|
288
|
-
|
|
289
|
-
const client = new Courier({
|
|
290
|
-
fetchOptions: {
|
|
291
|
-
// `RequestInit` options
|
|
23
|
+
const response = await client.send.message({
|
|
24
|
+
message: {
|
|
25
|
+
to: { email: 'you@example.com' },
|
|
26
|
+
content: {
|
|
27
|
+
title: 'Hello from Courier!',
|
|
28
|
+
body: 'Your first notification, sent with the Node.js SDK.',
|
|
29
|
+
},
|
|
292
30
|
},
|
|
293
31
|
});
|
|
294
|
-
```
|
|
295
32
|
|
|
296
|
-
|
|
33
|
+
console.log(response.requestId);
|
|
34
|
+
```
|
|
297
35
|
|
|
298
|
-
|
|
299
|
-
options to requests:
|
|
36
|
+
The client reads `COURIER_API_KEY` from your environment automatically. You can also pass it explicitly: `new Courier({ apiKey: 'your-key' })`.
|
|
300
37
|
|
|
301
|
-
|
|
38
|
+
## Common Operations
|
|
302
39
|
|
|
303
40
|
```ts
|
|
304
|
-
|
|
305
|
-
|
|
41
|
+
// Check message delivery status
|
|
42
|
+
const message = await client.messages.retrieve('message-id');
|
|
43
|
+
console.log(message.status);
|
|
306
44
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
dispatcher: proxyAgent,
|
|
311
|
-
},
|
|
45
|
+
// Create or update a user profile
|
|
46
|
+
await client.profiles.create('user_123', {
|
|
47
|
+
profile: { email: 'jane@example.com', name: 'Jane Doe' },
|
|
312
48
|
});
|
|
313
|
-
```
|
|
314
49
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const client = new Courier({
|
|
321
|
-
fetchOptions: {
|
|
322
|
-
proxy: 'http://localhost:8888',
|
|
323
|
-
},
|
|
50
|
+
// Issue a JWT for client-side SDK auth
|
|
51
|
+
const { token } = await client.auth.issueToken({
|
|
52
|
+
scope: 'user_id:user_123 inbox:read:messages inbox:write:events',
|
|
53
|
+
expires_in: '2 days',
|
|
324
54
|
});
|
|
325
55
|
```
|
|
326
56
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
```ts
|
|
330
|
-
import Courier from 'npm:@trycourier/courier';
|
|
331
|
-
|
|
332
|
-
const httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } });
|
|
333
|
-
const client = new Courier({
|
|
334
|
-
fetchOptions: {
|
|
335
|
-
client: httpClient,
|
|
336
|
-
},
|
|
337
|
-
});
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
## Frequently Asked Questions
|
|
341
|
-
|
|
342
|
-
## Semantic versioning
|
|
343
|
-
|
|
344
|
-
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
|
|
345
|
-
|
|
346
|
-
1. Changes that only affect static types, without breaking runtime behavior.
|
|
347
|
-
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
|
|
348
|
-
3. Changes that we do not expect to impact the vast majority of users in practice.
|
|
349
|
-
|
|
350
|
-
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
|
|
351
|
-
|
|
352
|
-
We are keen for your feedback; please open an [issue](https://www.github.com/trycourier/courier-node/issues) with questions, bugs, or suggestions.
|
|
353
|
-
|
|
354
|
-
## Requirements
|
|
355
|
-
|
|
356
|
-
TypeScript >= 4.9 is supported.
|
|
357
|
-
|
|
358
|
-
The following runtimes are supported:
|
|
359
|
-
|
|
360
|
-
- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
|
|
361
|
-
- Node.js 20 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
|
|
362
|
-
- Deno v1.28.0 or higher.
|
|
363
|
-
- Bun 1.0 or later.
|
|
364
|
-
- Cloudflare Workers.
|
|
365
|
-
- Vercel Edge Runtime.
|
|
366
|
-
- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
|
|
367
|
-
- Nitro v2.6 or greater.
|
|
368
|
-
|
|
369
|
-
Note that React Native is not supported at this time.
|
|
370
|
-
|
|
371
|
-
If you are interested in other runtime environments, please open or upvote an issue on GitHub.
|
|
57
|
+
## Documentation
|
|
372
58
|
|
|
373
|
-
|
|
59
|
+
Full documentation: **[courier.com/docs/sdk-libraries/node](https://www.courier.com/docs/sdk-libraries/node/)**
|
|
374
60
|
|
|
375
|
-
|
|
61
|
+
- [Quickstart](https://www.courier.com/docs/getting-started/quickstart/)
|
|
62
|
+
- [Send API](https://www.courier.com/docs/platform/sending/send-message/)
|
|
63
|
+
- [API Reference](https://www.courier.com/docs/reference/get-started/)
|
|
64
|
+
<!-- AUTO-GENERATED-OVERVIEW:END -->
|