@trycourier/courier 7.3.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.
Files changed (175) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/LICENSE +1 -1
  3. package/README.md +34 -345
  4. package/client.d.mts +50 -8
  5. package/client.d.mts.map +1 -1
  6. package/client.d.ts +50 -8
  7. package/client.d.ts.map +1 -1
  8. package/client.js +17 -4
  9. package/client.js.map +1 -1
  10. package/client.mjs +18 -5
  11. package/client.mjs.map +1 -1
  12. package/internal/parse.d.mts.map +1 -1
  13. package/internal/parse.d.ts.map +1 -1
  14. package/internal/parse.js +5 -0
  15. package/internal/parse.js.map +1 -1
  16. package/internal/parse.mjs +5 -0
  17. package/internal/parse.mjs.map +1 -1
  18. package/internal/utils/query.d.mts +2 -0
  19. package/internal/utils/query.d.mts.map +1 -0
  20. package/internal/utils/query.d.ts +2 -0
  21. package/internal/utils/query.d.ts.map +1 -0
  22. package/internal/utils/query.js +10 -0
  23. package/internal/utils/query.js.map +1 -0
  24. package/internal/utils/query.mjs +6 -0
  25. package/internal/utils/query.mjs.map +1 -0
  26. package/internal/utils.d.mts +1 -0
  27. package/internal/utils.d.ts +1 -0
  28. package/internal/utils.js +1 -0
  29. package/internal/utils.js.map +1 -1
  30. package/internal/utils.mjs +1 -0
  31. package/package.json +1 -1
  32. package/resources/audiences.d.mts +11 -33
  33. package/resources/audiences.d.mts.map +1 -1
  34. package/resources/audiences.d.ts +11 -33
  35. package/resources/audiences.d.ts.map +1 -1
  36. package/resources/automations/automations.d.mts +54 -1
  37. package/resources/automations/automations.d.mts.map +1 -1
  38. package/resources/automations/automations.d.ts +54 -1
  39. package/resources/automations/automations.d.ts.map +1 -1
  40. package/resources/automations/automations.js +12 -0
  41. package/resources/automations/automations.js.map +1 -1
  42. package/resources/automations/automations.mjs +12 -0
  43. package/resources/automations/automations.mjs.map +1 -1
  44. package/resources/automations/index.d.mts +1 -1
  45. package/resources/automations/index.d.mts.map +1 -1
  46. package/resources/automations/index.d.ts +1 -1
  47. package/resources/automations/index.d.ts.map +1 -1
  48. package/resources/automations/index.js.map +1 -1
  49. package/resources/automations/index.mjs +1 -1
  50. package/resources/automations/index.mjs.map +1 -1
  51. package/resources/bulk.d.mts +80 -39
  52. package/resources/bulk.d.mts.map +1 -1
  53. package/resources/bulk.d.ts +80 -39
  54. package/resources/bulk.d.ts.map +1 -1
  55. package/resources/bulk.js +12 -2
  56. package/resources/bulk.js.map +1 -1
  57. package/resources/bulk.mjs +12 -2
  58. package/resources/bulk.mjs.map +1 -1
  59. package/resources/inbound.d.mts +1 -1
  60. package/resources/inbound.d.ts +1 -1
  61. package/resources/index.d.mts +3 -3
  62. package/resources/index.d.mts.map +1 -1
  63. package/resources/index.d.ts +3 -3
  64. package/resources/index.d.ts.map +1 -1
  65. package/resources/index.js.map +1 -1
  66. package/resources/index.mjs +1 -1
  67. package/resources/index.mjs.map +1 -1
  68. package/resources/lists/subscriptions.d.mts +1 -1
  69. package/resources/lists/subscriptions.d.ts +1 -1
  70. package/resources/notifications/checks.d.mts +2 -2
  71. package/resources/notifications/checks.d.ts +2 -2
  72. package/resources/send.d.mts +8 -2
  73. package/resources/send.d.mts.map +1 -1
  74. package/resources/send.d.ts +8 -2
  75. package/resources/send.d.ts.map +1 -1
  76. package/resources/send.js +1 -1
  77. package/resources/send.mjs +1 -1
  78. package/resources/shared.d.mts +290 -52
  79. package/resources/shared.d.mts.map +1 -1
  80. package/resources/shared.d.ts +290 -52
  81. package/resources/shared.d.ts.map +1 -1
  82. package/resources/tenants/index.d.mts +2 -2
  83. package/resources/tenants/index.d.mts.map +1 -1
  84. package/resources/tenants/index.d.ts +2 -2
  85. package/resources/tenants/index.d.ts.map +1 -1
  86. package/resources/tenants/index.js +2 -2
  87. package/resources/tenants/index.js.map +1 -1
  88. package/resources/tenants/index.mjs +1 -1
  89. package/resources/tenants/index.mjs.map +1 -1
  90. package/resources/tenants/preferences/items.d.mts +2 -2
  91. package/resources/tenants/preferences/items.d.ts +2 -2
  92. package/resources/tenants/templates/index.d.mts +3 -0
  93. package/resources/tenants/templates/index.d.mts.map +1 -0
  94. package/resources/tenants/templates/index.d.ts +3 -0
  95. package/resources/tenants/templates/index.d.ts.map +1 -0
  96. package/resources/tenants/templates/index.js +9 -0
  97. package/resources/tenants/templates/index.js.map +1 -0
  98. package/resources/tenants/templates/index.mjs +4 -0
  99. package/resources/tenants/templates/index.mjs.map +1 -0
  100. package/resources/tenants/templates/templates.d.mts +159 -0
  101. package/resources/tenants/templates/templates.d.mts.map +1 -0
  102. package/resources/tenants/templates/templates.d.ts +159 -0
  103. package/resources/tenants/templates/templates.d.ts.map +1 -0
  104. package/resources/tenants/templates/templates.js +91 -0
  105. package/resources/tenants/templates/templates.js.map +1 -0
  106. package/resources/tenants/templates/templates.mjs +86 -0
  107. package/resources/tenants/templates/templates.mjs.map +1 -0
  108. package/resources/tenants/templates/versions.d.mts +39 -0
  109. package/resources/tenants/templates/versions.d.mts.map +1 -0
  110. package/resources/tenants/templates/versions.d.ts +39 -0
  111. package/resources/tenants/templates/versions.d.ts.map +1 -0
  112. package/resources/tenants/templates/versions.js +32 -0
  113. package/resources/tenants/templates/versions.js.map +1 -0
  114. package/resources/tenants/templates/versions.mjs +28 -0
  115. package/resources/tenants/templates/versions.mjs.map +1 -0
  116. package/resources/tenants/templates.d.mts +1 -90
  117. package/resources/tenants/templates.d.mts.map +1 -1
  118. package/resources/tenants/templates.d.ts +1 -90
  119. package/resources/tenants/templates.d.ts.map +1 -1
  120. package/resources/tenants/templates.js +2 -34
  121. package/resources/tenants/templates.js.map +1 -1
  122. package/resources/tenants/templates.mjs +1 -32
  123. package/resources/tenants/templates.mjs.map +1 -1
  124. package/resources/tenants/tenants.d.mts +147 -5
  125. package/resources/tenants/tenants.d.mts.map +1 -1
  126. package/resources/tenants/tenants.d.ts +147 -5
  127. package/resources/tenants/tenants.d.ts.map +1 -1
  128. package/resources/tenants/tenants.js +2 -2
  129. package/resources/tenants/tenants.js.map +1 -1
  130. package/resources/tenants/tenants.mjs +2 -2
  131. package/resources/tenants/tenants.mjs.map +1 -1
  132. package/resources/translations.d.mts +1 -1
  133. package/resources/translations.d.ts +1 -1
  134. package/resources/users/preferences.d.mts +1 -1
  135. package/resources/users/preferences.d.ts +1 -1
  136. package/resources/users/tenants.d.mts +1 -1
  137. package/resources/users/tenants.d.ts +1 -1
  138. package/resources/users/tokens.d.mts +3 -8
  139. package/resources/users/tokens.d.mts.map +1 -1
  140. package/resources/users/tokens.d.ts +3 -8
  141. package/resources/users/tokens.d.ts.map +1 -1
  142. package/resources/users/tokens.js +2 -3
  143. package/resources/users/tokens.js.map +1 -1
  144. package/resources/users/tokens.mjs +2 -3
  145. package/resources/users/tokens.mjs.map +1 -1
  146. package/src/client.ts +88 -14
  147. package/src/internal/parse.ts +6 -0
  148. package/src/internal/utils/query.ts +7 -0
  149. package/src/internal/utils.ts +1 -0
  150. package/src/resources/audiences.ts +11 -69
  151. package/src/resources/automations/automations.ts +74 -1
  152. package/src/resources/automations/index.ts +7 -1
  153. package/src/resources/bulk.ts +71 -32
  154. package/src/resources/inbound.ts +1 -1
  155. package/src/resources/index.ts +12 -3
  156. package/src/resources/lists/subscriptions.ts +1 -1
  157. package/src/resources/notifications/checks.ts +2 -2
  158. package/src/resources/send.ts +28 -2
  159. package/src/resources/shared.ts +391 -49
  160. package/src/resources/tenants/index.ts +8 -1
  161. package/src/resources/tenants/preferences/items.ts +2 -2
  162. package/src/resources/tenants/templates/index.ts +11 -0
  163. package/src/resources/tenants/templates/templates.ts +222 -0
  164. package/src/resources/tenants/templates/versions.ts +55 -0
  165. package/src/resources/tenants/templates.ts +1 -122
  166. package/src/resources/tenants/tenants.ts +179 -3
  167. package/src/resources/translations.ts +1 -1
  168. package/src/resources/users/preferences.ts +1 -1
  169. package/src/resources/users/tenants.ts +1 -1
  170. package/src/resources/users/tokens.ts +4 -10
  171. package/src/version.ts +1 -1
  172. package/version.d.mts +1 -1
  173. package/version.d.ts +1 -1
  174. package/version.js +1 -1
  175. package/version.mjs +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,120 @@
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
+
3
118
  ## 7.3.0 (2025-12-08)
4
119
 
5
120
  Full Changelog: [v7.2.0...v7.3.0](https://github.com/trycourier/courier-node/compare/v7.2.0...v7.3.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 2025 Courier
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
- # Courier TypeScript API Library
1
+ <!-- AUTO-GENERATED-OVERVIEW:START Do not edit this section. It is synced from mintlify-docs. -->
2
+ # Courier Node.js SDK
2
3
 
3
- [![NPM version](<https://img.shields.io/npm/v/@trycourier/courier.svg?label=npm%20(stable)>)](https://npmjs.org/package/@trycourier/courier) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@trycourier/courier)
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
- ```sh
8
+ ```bash
14
9
  npm install @trycourier/courier
15
10
  ```
16
11
 
17
- ## Usage
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
- ### Request & Response types
14
+ Requires Node.js 20+ (LTS). Also works in Deno 1.28+, Bun 1.0+, Cloudflare Workers, and Vercel Edge Runtime.
37
15
 
38
- This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
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
- .message({
150
- message: { to: { user_id: 'your_user_id' }, template: 'your_template_id', data: { foo: 'bar' } },
151
- })
152
- .asResponse();
153
- console.log(response.headers.get('X-My-Header'));
154
- console.log(response.statusText); // access the underlying Response object
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
- #### Configuring proxies
33
+ console.log(response.requestId);
34
+ ```
297
35
 
298
- To modify proxy behavior, you can provide custom `fetchOptions` that add runtime-specific proxy
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
- <img src="https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/node.svg" align="top" width="18" height="21"> **Node** <sup>[[docs](https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md#example---proxyagent-with-fetch)]</sup>
38
+ ## Common Operations
302
39
 
303
40
  ```ts
304
- import Courier from '@trycourier/courier';
305
- import * as undici from 'undici';
41
+ // Check message delivery status
42
+ const message = await client.messages.retrieve('message-id');
43
+ console.log(message.status);
306
44
 
307
- const proxyAgent = new undici.ProxyAgent('http://localhost:8888');
308
- const client = new Courier({
309
- fetchOptions: {
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
- <img src="https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/bun.svg" align="top" width="18" height="21"> **Bun** <sup>[[docs](https://bun.sh/guides/http/proxy)]</sup>
316
-
317
- ```ts
318
- import Courier from '@trycourier/courier';
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
- <img src="https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/deno.svg" align="top" width="18" height="21"> **Deno** <sup>[[docs](https://docs.deno.com/api/deno/~/Deno.createHttpClient)]</sup>
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
- ## Contributing
59
+ Full documentation: **[courier.com/docs/sdk-libraries/node](https://www.courier.com/docs/sdk-libraries/node/)**
374
60
 
375
- See [the contributing documentation](./CONTRIBUTING.md).
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 -->