@trycourier/courier-react 8.0.29 → 8.2.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/README.md CHANGED
@@ -1,42 +1,27 @@
1
1
  <img width="1040" alt="courier-react" src="https://github.com/user-attachments/assets/e886b445-d106-4dab-afca-82183e0fcbe7" />
2
2
 
3
- ## 1. Install
3
+ **Using React 17?** Use the [@trycourier/courier-react-17](../courier-react-17/) package.
4
+
5
+ **Not using React?** Use the [@trycourier/courier-ui-inbox](../courier-ui-inbox/) package.
6
+
7
+ ## Installation
4
8
 
5
9
  ```sh
6
10
  npm install @trycourier/courier-react
7
11
  ```
8
12
 
9
- > **Not using React?** We suggest you use [@trycourier/courier-ui-inbox](../courier-ui-inbox/README.md) package instead.
10
-
11
- ## 2. Authenticate
12
-
13
- To use the SDK, you need to generate a JWT (JSON Web Token) for your user. **This JWT should always be generated by your backend server, never in client-side code.**
14
-
15
- **How it works:**
13
+ ## Usage
16
14
 
17
- 1. **Your frontend calls your backend:**
18
- - When your app needs to authenticate a user, your frontend should make a request to your own backend (e.g., `/api/generate-courier-jwt`).
15
+ Check out the [Courier documentation](https://www.courier.com/docs/sdk-libraries/courier-react-web) for a full guide to Courier React.
19
16
 
20
- 2. **Your backend calls Courier to issue a JWT:**
21
- - In your backend endpoint, use your [Courier API Key](https://app.courier.com/settings/api-keys) to call the [Courier JWT Token Endpoint](https://www.courier.com/docs/reference/auth/issue-token) and generate a JWT for the user.
22
- - Your backend then returns the JWT to your frontend.
17
+ If you’re coming from an earlier version of the Courier React SDK,
18
+ check out [the v8 migration guide](https://www.courier.com/docs/sdk-libraries/courier-react-v8-migration-guide)
19
+ for what’s changed, how to upgrade your app,
20
+ and links to documentation for past versions of the React SDK.
23
21
 
24
- To quickly test JWT generation (for development only), you can use the following cURL command to call Courier's API directly. **Do not use this in production or from client-side code.**
22
+ ## Examples
25
23
 
26
- ```sh
27
- curl --request POST \
28
- --url https://api.courier.com/auth/issue-token \
29
- --header 'Accept: application/json' \
30
- --header 'Authorization: Bearer $YOUR_API_KEY' \
31
- --header 'Content-Type: application/json' \
32
- --data \
33
- '{
34
- "scope": "user_id:$YOUR_USER_ID write:user-tokens inbox:read:messages inbox:write:events read:preferences write:preferences read:brands",
35
- "expires_in": "$YOUR_NUMBER days"
36
- }'
37
- ```
38
-
39
- ## 3. Add Inbox Component
24
+ Below are a few examples of the Courier Inbox. Visit the [Courier documentation](https://www.courier.com/docs/sdk-libraries/courier-react-web) for more examples.
40
25
 
41
26
  ### `CourierInbox`
42
27
 
@@ -98,383 +83,8 @@ export default function App() {
98
83
  }
99
84
  ```
100
85
 
101
- ## NextJS & Server Side Rendering Frameworks
102
-
103
- `courier-react` only supports client side rendering. You will need to add `'use client'` to the top of any file that will use `CourierInbox` or `CourierInboxPopupMenu`.
104
-
105
- ```ts
106
- 'use client'
107
-
108
- ...
109
- import { ..., CourierInboxPopupMenu } from '@trycourier/courier-react';
110
-
111
- export default function Page() {
112
-
113
- ...
114
-
115
- return <CourierInboxPopupMenu />;
116
-
117
- }
118
- ```
119
-
120
- ## Handle Clicks and Presses
121
-
122
- ```ts
123
- import { useEffect } from 'react';
124
- import { CourierInbox, useCourier, type CourierInboxListItemFactoryProps, type CourierInboxListItemActionFactoryProps } from '@trycourier/courier-react';
125
-
126
- export default function App() {
127
-
128
- const courier = useCourier();
129
-
130
- useEffect(() => {
131
- // Generate a JWT for your user (do this on your backend server)
132
- const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT
133
-
134
- // Authenticate the user with the inbox
135
- courier.shared.signIn({
136
- userId: $YOUR_USER_ID,
137
- jwt: jwt,
138
- });
139
- }, []);
140
-
141
- return (
142
- <CourierInbox
143
- onMessageClick={({ message, index }: CourierInboxListItemFactoryProps) => {
144
- alert("Message clicked at index " + index + ":\n" + JSON.stringify(message, null, 2));
145
- }}
146
- onMessageActionClick={({ message, action, index }: CourierInboxListItemActionFactoryProps) => {
147
- alert(
148
- "Message action clicked at index " + index + ":\n" +
149
- "Action: " + JSON.stringify(action, null, 2) + "\n" +
150
- "Message: " + JSON.stringify(message, null, 2)
151
- );
152
- }}
153
- onMessageLongPress={({ message, index }: CourierInboxListItemFactoryProps) => {
154
- // Handle message long presses. **Only works on devices that support javascript's touch events. This will not work with a mouse cursor.**
155
- alert("Message long pressed at index " + index + ":\n" + JSON.stringify(message, null, 2));
156
- }}
157
- />
158
- );
159
-
160
- }
161
- ```
162
-
163
- ## Styles and Theming
164
-
165
- ### Light & Dark Themes
166
-
167
- The fastest way to style the Inbox to match your app. This example shows unread indicator styling, but you can customize fonts, icons, text, and more.
168
-
169
- > **🎨 Theme Reference:** [All available theme values](../courier-ui-inbox/docs/theme.md)
170
-
171
- <img width="688" alt="Screenshot 2025-06-25 at 5 38 07 PM" src="https://github.com/user-attachments/assets/d1440494-ee66-4ff6-850b-c1a13691cf2f" />
172
-
173
- ```ts
174
- import { CourierInbox, ..., type CourierInboxTheme } from '@trycourier/courier-react';
175
-
176
- export default function App() {
177
- ...
178
-
179
- const theme: CourierInboxTheme = {
180
- inbox: {
181
- header: {
182
- filters: {
183
- unreadIndicator: {
184
- backgroundColor: '#8B5CF6',
185
- },
186
- },
187
- },
188
- list: {
189
- item: {
190
- unreadIndicatorColor: '#8B5CF6',
191
- },
192
- },
193
- },
194
- };
195
-
196
- return <CourierInbox lightTheme={theme} darkTheme={theme} mode="light" />;
197
- }
198
- ```
199
-
200
- ### Popup Alignment, Positioning, and Dimensions
201
-
202
- ```ts
203
- export default function App() {
204
-
205
- ...
206
-
207
- return (
208
- <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', padding: '100px' }}>
209
- <CourierInboxPopupMenu
210
- popupAlignment="top-right" // 'top-right' | 'top-left' | 'top-center' | 'bottom-right' | 'bottom-left' | 'bottom-center' | 'center-right' | 'center-left' | 'center-center'
211
- popupWidth="340px"
212
- popupHeight="400px"
213
- top="44px"
214
- right="44px"
215
- />
216
- </div>
217
- );
218
-
219
- }
220
- ```
221
-
222
- ### Custom height `CourierInbox`
223
-
224
- > **Important:** The default `CourierInbox` height is auto. It will set it's height based on it's children.
225
-
226
- ```ts
227
- <CourierInbox height='50vh' />
228
- ```
229
-
230
- ## Custom Elements
231
-
232
- Customize the inbox UI with any element you want.
233
-
234
- ### List Items
235
-
236
- <img width="688" alt="Screenshot 2025-06-25 at 6 25 17 PM" src="https://github.com/user-attachments/assets/075a568b-5538-4116-bb3d-752ecc5dea2c" />
237
-
238
- ```ts
239
- import { CourierInbox, ..., type CourierInboxListItemFactoryProps } from '@trycourier/courier-react'
240
-
241
- const CustomListItem = ({ message, index }: CourierInboxListItemFactoryProps) => (
242
- <pre style={{
243
- padding: '24px',
244
- borderBottom: '1px solid #e0e0e0',
245
- margin: '0'
246
- }}>
247
- {JSON.stringify({ message, index }, null, 2)}
248
- </pre>
249
- );
250
-
251
- export default function App() {
252
-
253
- ...
254
-
255
- return (
256
- <CourierInbox
257
- renderListItem={(props: CourierInboxListItemFactoryProps) => {
258
- return <CustomListItem {...props} />
259
- }}
260
- />
261
- );
262
-
263
- }
264
- ```
265
-
266
- ### Header
267
-
268
- <img width="688" alt="Screenshot 2025-06-25 at 6 35 59 PM" src="https://github.com/user-attachments/assets/25d45ac1-32e6-4e98-baf1-d0df34cef72a" />
269
-
270
- ```ts
271
- import { CourierInbox, ..., type CourierInboxHeaderFactoryProps } from '@trycourier/courier-react'
272
-
273
- const CustomHeader = (props: CourierInboxHeaderFactoryProps) => (
274
- <div style={{
275
- background: 'red',
276
- fontSize: '24px',
277
- padding: '24px',
278
- width: '100%'
279
- }}>
280
- {props.feedType}
281
- </div>
282
- );
283
-
284
- export default function App() {
285
-
286
- ...
287
-
288
- return (
289
- <CourierInbox
290
- renderHeader={(props: CourierInboxHeaderFactoryProps) => {
291
- return <CustomHeader {...props} />
292
- }}
293
- />
294
- );
295
-
296
- }
297
- ```
298
-
299
- ### Popup Menu Button
300
-
301
- <img width="606" alt="Screenshot 2025-06-25 at 6 40 38 PM" src="https://github.com/user-attachments/assets/dfb0daca-f11d-420f-9dc7-0c14b49ab7db" />
302
-
303
- ```ts
304
- import { CourierInboxPopupMenu, ..., type CourierInboxMenuButtonFactoryProps } from '@trycourier/courier-react'
305
-
306
- const CustomMenuButton = ({ unreadCount }: CourierInboxMenuButtonFactoryProps) => (
307
- <button>
308
- Open the Inbox Popup. Unread message count: {unreadCount}
309
- </button>
310
- );
311
-
312
- export default function App() {
313
-
314
- ...
315
-
316
- return (
317
- <div style={{ padding: '24px' }}>
318
- <CourierInboxPopupMenu
319
- renderMenuButton={(props: CourierInboxMenuButtonFactoryProps) => {
320
- return <CustomMenuButton {...props} />
321
- }}
322
- />
323
- </div>
324
- );
325
-
326
- }
327
- ```
328
-
329
- ### Loading, Empty, Error & Pagination
330
-
331
- ```ts
332
- import {
333
- CourierInbox,
334
- ...,
335
- type CourierInboxStateEmptyFactoryProps,
336
- type CourierInboxStateLoadingFactoryProps,
337
- type CourierInboxStateErrorFactoryProps,
338
- type CourierInboxPaginationItemFactoryProps
339
- } from '@trycourier/courier-react'
340
-
341
- const CustomLoadingState = ({ feedType }: CourierInboxStateLoadingFactoryProps) => (
342
- <div style={{
343
- padding: '24px',
344
- background: 'red',
345
- textAlign: 'center'
346
- }}>
347
- Custom Loading State
348
- </div>
349
- );
350
-
351
- const CustomEmptyState = ({ feedType }: CourierInboxStateEmptyFactoryProps) => (
352
- <div style={{
353
- padding: '24px',
354
- background: 'green',
355
- textAlign: 'center'
356
- }}>
357
- Custom Empty State
358
- </div>
359
- );
360
-
361
- const CustomErrorState = ({ feedType, error }: CourierInboxStateErrorFactoryProps) => (
362
- <div style={{
363
- padding: '24px',
364
- background: 'blue',
365
- textAlign: 'center'
366
- }}>
367
- Custom Error State: {error.message}
368
- </div>
369
- );
370
-
371
- const CustomPaginationItem = ({ feedType }: CourierInboxPaginationItemFactoryProps) => (
372
- <div style={{
373
- padding: '24px',
374
- background: 'yellow',
375
- textAlign: 'center'
376
- }}>
377
- Custom Pagination Item
378
- </div>
379
- );
380
-
381
- export default function App() {
382
-
383
- ...
384
-
385
- return (
386
- <CourierInbox
387
- renderLoadingState={(props: CourierInboxStateLoadingFactoryProps) => {
388
- return <CustomLoadingState {...props} />
389
- }}
390
- renderEmptyState={(props: CourierInboxStateEmptyFactoryProps) => {
391
- return <CustomEmptyState {...props} />
392
- }}
393
- renderErrorState={(props: CourierInboxStateErrorFactoryProps) => {
394
- return <CustomErrorState {...props} />
395
- }}
396
- renderPaginationItem={(props: CourierInboxPaginationItemFactoryProps) => {
397
- return <CustomPaginationItem {...props} />
398
- }}
399
- />
400
- );
401
-
402
- }
403
- ```
404
-
405
- ### Available Hooks
406
-
407
- ```ts
408
- import { useCourier } from '@trycourier/courier-react';
409
-
410
- const { auth, inbox } = useCourier();
411
-
412
- // Sign in & Sign out
413
- useEffect(() => {
414
- auth.signIn({
415
- userId: '$YOUR_USER_ID',
416
- jwt: jwt,
417
- });
418
-
419
- // To sign out, call:
420
- auth.signOut();
421
- }, [auth]);
422
-
423
- // Log the signed-in user
424
- useEffect(() => {
425
- console.log('Current Courier User: ', auth.userId);
426
- }, [auth.userId]);
427
-
428
- // Inbox Hooks
429
- useEffect(() => {
430
-
431
- // Set how many messages get fetched when getting another page
432
- inbox.setPaginationLimit(20);
433
-
434
- // Reload a specific dataset in the inbox
435
- inbox.load({ feedType: 'inbox', canUseCache: true });
436
-
437
- // Fetch the next page of messages
438
- inbox.fetchNextPageOfMessages({ feedType: 'inbox' }).then((data) => {
439
- if (data) {
440
- console.log('Next page of messages:', data);
441
- }
442
- });
443
-
444
- // Mark all messages as read
445
- inbox.readAllMessages();
446
-
447
- // Log unread count and errors
448
- if (inbox.unreadCount !== undefined) {
449
- console.log('Unread messages:', inbox.unreadCount);
450
- }
451
-
452
- if (inbox.error) {
453
- console.error('Inbox error:', inbox.error);
454
- }
455
-
456
- // Log inbox and archive datasets
457
- if (inbox.inbox) {
458
- console.log('Inbox dataset:', inbox.inbox);
459
- }
460
-
461
- if (inbox.archive) {
462
- console.log('Archive dataset:', inbox.archive);
463
- }
464
-
465
- }, [
466
- inbox,
467
- inbox.inbox,
468
- inbox.archive,
469
- inbox.unreadCount,
470
- inbox.error,
471
- ]);
472
- ```
473
-
474
- > **Not using React?** We suggest you use [@trycourier/courier-ui-inbox](../courier-ui-inbox/README.md) package instead.
475
-
476
- ## **Share feedback with Courier**
86
+ ## Share feedback with Courier
477
87
 
478
- We want to make this the best SDK for managing notifications! Have an idea or feedback about our SDKs? Let us know!
88
+ Have an idea or feedback about our SDKs? Let us know!
479
89
 
480
- [Courier Web Issues](https://github.com/trycourier/courier-web/issues)
90
+ Open an issue: [Courier Web Issues](https://github.com/trycourier/courier-web/issues)
@@ -0,0 +1,24 @@
1
+ import { CourierToast as CourierToastElement } from '@trycourier/courier-ui-toast';
2
+ import { CourierToastProps } from '@trycourier/courier-react-components';
3
+ /**
4
+ * CourierToast React component.
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * const courier = useCourier();
9
+ *
10
+ * useEffect(() => {
11
+ * // Generate a JWT for your user (do this on your backend server)
12
+ * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT
13
+ *
14
+ * // Authenticate the user with the inbox
15
+ * courier.shared.signIn({
16
+ * userId: $YOUR_USER_ID,
17
+ * jwt: jwt,
18
+ * });
19
+ * }, []);
20
+ *
21
+ * return <CourierToast />;
22
+ * ```
23
+ */
24
+ export declare const CourierToast: import('react').ForwardRefExoticComponent<CourierToastProps & import('react').RefAttributes<CourierToastElement>>;
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),t=require("@trycourier/courier-react-components"),o=require("react-dom"),n=require("react-dom/client"),i=require("@trycourier/courier-ui-inbox");function u(e){const r=document.createElement("div"),t=n.createRoot(r);o.flushSync((()=>{t.render(e)}));const i=r.firstElementChild;if(!(i instanceof HTMLElement))throw new Error("renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)");return i}const a=r.forwardRef(((r,o)=>e.jsx(t.CourierRenderContext.Provider,{value:u,children:e.jsx(t.CourierInboxComponent,{...r,ref:o})})));a.displayName="CourierInbox";const s=r.forwardRef(((r,o)=>e.jsx(t.CourierRenderContext.Provider,{value:u,children:e.jsx(t.CourierInboxPopupMenuComponent,{...r,ref:o})})));s.displayName="CourierInboxPopupMenu",Object.defineProperty(exports,"useCourier",{enumerable:!0,get:()=>t.useCourier}),Object.defineProperty(exports,"archiveMessage",{enumerable:!0,get:()=>i.archiveMessage}),Object.defineProperty(exports,"clickMessage",{enumerable:!0,get:()=>i.clickMessage}),Object.defineProperty(exports,"defaultDarkTheme",{enumerable:!0,get:()=>i.defaultDarkTheme}),Object.defineProperty(exports,"defaultLightTheme",{enumerable:!0,get:()=>i.defaultLightTheme}),Object.defineProperty(exports,"markAsRead",{enumerable:!0,get:()=>i.markAsRead}),Object.defineProperty(exports,"markAsUnread",{enumerable:!0,get:()=>i.markAsUnread}),Object.defineProperty(exports,"mergeTheme",{enumerable:!0,get:()=>i.mergeTheme}),Object.defineProperty(exports,"openMessage",{enumerable:!0,get:()=>i.openMessage}),exports.CourierInbox=a,exports.CourierInboxPopupMenu=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@trycourier/courier-js"),r=require("react/jsx-runtime"),t=require("react"),o=require("@trycourier/courier-react-components"),u=require("react-dom"),i=require("react-dom/client"),n=require("@trycourier/courier-ui-inbox"),a=require("@trycourier/courier-ui-toast");function s(e){const r=document.createElement("div"),t=i.createRoot(r);return u.flushSync((()=>{t.render(e)})),r}const c=t.forwardRef(((e,t)=>r.jsx(o.CourierRenderContext.Provider,{value:s,children:r.jsx(o.CourierInboxComponent,{...e,ref:t})})));c.displayName="CourierInbox";const d=t.forwardRef(((e,t)=>r.jsx(o.CourierRenderContext.Provider,{value:s,children:r.jsx(o.CourierInboxPopupMenuComponent,{...e,ref:t})})));d.displayName="CourierInboxPopupMenu";const m=t.forwardRef(((e,t)=>r.jsx(o.CourierRenderContext.Provider,{value:s,children:r.jsx(o.CourierToastComponent,{...e,ref:t})})));m.displayName="CourierToast",e.Courier.shared.courierUserAgentName="courier-react",e.Courier.shared.courierUserAgentVersion="8.2.0",Object.defineProperty(exports,"useCourier",{enumerable:!0,get:()=>o.useCourier}),Object.defineProperty(exports,"archiveMessage",{enumerable:!0,get:()=>n.archiveMessage}),Object.defineProperty(exports,"clickMessage",{enumerable:!0,get:()=>n.clickMessage}),Object.defineProperty(exports,"defaultDarkTheme",{enumerable:!0,get:()=>n.defaultDarkTheme}),Object.defineProperty(exports,"defaultLightTheme",{enumerable:!0,get:()=>n.defaultLightTheme}),Object.defineProperty(exports,"markAsRead",{enumerable:!0,get:()=>n.markAsRead}),Object.defineProperty(exports,"markAsUnread",{enumerable:!0,get:()=>n.markAsUnread}),Object.defineProperty(exports,"mergeTheme",{enumerable:!0,get:()=>n.mergeTheme}),Object.defineProperty(exports,"openMessage",{enumerable:!0,get:()=>n.openMessage}),Object.defineProperty(exports,"defaultToastDarkTheme",{enumerable:!0,get:()=>a.defaultDarkTheme}),Object.defineProperty(exports,"defaultToastLightTheme",{enumerable:!0,get:()=>a.defaultLightTheme}),Object.defineProperty(exports,"mergeToastTheme",{enumerable:!0,get:()=>a.mergeTheme}),exports.CourierInbox=c,exports.CourierInboxPopupMenu=d,exports.CourierToast=m;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/utils/render.tsx","../src/components/courier-inbox.tsx","../src/components/courier-inbox-popup-menu.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { createRoot } from \"react-dom/client\";\n\n/**\n * Converts a React node to an HTMLElement.\n * This function uses flushSync to ensure the DOM is updated synchronously.\n * @param node - The React node to convert.\n * @returns The converted HTMLElement.\n */\nexport function reactNodeToHTMLElement(node: ReactNode): HTMLElement {\n const container = document.createElement('div');\n\n // Use React 18 root\n const root = createRoot(container);\n flushSync(() => {\n root.render(node);\n });\n\n // Wait until React mounts the content synchronously\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)'\n );\n }\n\n return element;\n}\n","import { forwardRef } from \"react\";\nimport { CourierInbox as CourierInboxElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxComponent, CourierInboxProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInbox React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInbox />;\n * ```\n */\nexport const CourierInbox = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInbox.displayName = 'CourierInbox';\n","import { forwardRef } from \"react\";\nimport { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxPopupMenuComponent, CourierInboxPopupMenuProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInboxPopupMenu React component.\n *\n * This component is used to display a popup menu for a message in the inbox.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInboxPopupMenu />;\n * ```\n */\nexport const CourierInboxPopupMenu = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxPopupMenuComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInboxPopupMenu.displayName = 'CourierInboxPopupMenu';\n"],"names":["reactNodeToHTMLElement","node","container","document","createElement","root","createRoot","flushSync","render","element","firstElementChild","HTMLElement","Error","CourierInbox","forwardRef","props","ref","jsx","CourierRenderContext","Provider","value","children","CourierInboxComponent","displayName","CourierInboxPopupMenu","CourierInboxPopupMenuComponent"],"mappings":"yRAUO,SAASA,EAAuBC,GACrC,MAAMC,EAAYC,SAASC,cAAc,OAGnCC,EAAOC,EAAAA,WAAWJ,GACxBK,EAAAA,WAAU,KACRF,EAAKG,OAAOP,EAAI,IAIlB,MAAMQ,EAAUP,EAAUQ,kBAC1B,KAAMD,aAAmBE,aACvB,MAAM,IAAIC,MACR,gGAIJ,OAAOH,CACT,CCFO,MAAMI,EAAeC,EAAAA,YAAmD,CAACC,EAAOC,MAEnFC,IAACC,EAAAA,qBAAqBC,SAArB,CAA8BC,MAAOpB,EACpCqB,WAAAJ,IAACK,EAAAA,sBAAA,IAA0BP,EAAOC,YAKxCH,EAAaU,YAAc,eCNpB,MAAMC,EAAwBV,EAAAA,YAAqE,CAACC,EAAOC,MAE9GC,IAACC,EAAAA,qBAAqBC,SAArB,CAA8BC,MAAOpB,EACpCqB,WAAAJ,IAACQ,EAAAA,+BAAA,IAAmCV,EAAOC,YAKjDQ,EAAsBD,YAAc"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils/render.tsx","../src/components/courier-inbox.tsx","../src/components/courier-inbox-popup-menu.tsx","../src/components/courier-toast.tsx","../src/index.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { createRoot } from \"react-dom/client\";\n\n/**\n * Converts a React node to an HTMLElement.\n * This function uses flushSync to ensure the DOM is updated synchronously.\n * @param node - The React node to convert.\n * @returns The converted HTMLElement.\n */\nexport function reactNodeToHTMLElement(node: ReactNode): HTMLElement {\n const container = document.createElement('div');\n\n // Use React 18 root\n const root = createRoot(container);\n flushSync(() => {\n root.render(node);\n });\n\n // Return the container to preserve React's event handling\n // The container maintains the React root and event delegation\n return container;\n}\n","import { forwardRef } from \"react\";\nimport { CourierInbox as CourierInboxElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxComponent, CourierInboxProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInbox React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInbox />;\n * ```\n */\nexport const CourierInbox = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInbox.displayName = 'CourierInbox';\n","import { forwardRef } from \"react\";\nimport { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxPopupMenuComponent, CourierInboxPopupMenuProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInboxPopupMenu React component.\n *\n * This component is used to display a popup menu for a message in the inbox.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInboxPopupMenu />;\n * ```\n */\nexport const CourierInboxPopupMenu = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxPopupMenuComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInboxPopupMenu.displayName = 'CourierInboxPopupMenu';\n","import { forwardRef } from \"react\";\nimport { CourierToast as CourierToastElement } from \"@trycourier/courier-ui-toast\";\nimport { CourierToastComponent, CourierToastProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierToast React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierToast />;\n * ```\n */\nexport const CourierToast = forwardRef<CourierToastElement, CourierToastProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierToastComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierToast.displayName = 'CourierToast';\n","import { Courier } from '@trycourier/courier-js';\n\nCourier.shared.courierUserAgentName = \"courier-react\";\nCourier.shared.courierUserAgentVersion = __PACKAGE_VERSION__;\n\nexport { CourierInbox } from './components/courier-inbox';\nexport { CourierInboxPopupMenu } from './components/courier-inbox-popup-menu';\nexport { CourierToast } from './components/courier-toast';\n\nexport { useCourier } from '@trycourier/courier-react-components';\n\nexport type {\n CourierInboxProps,\n CourierInboxPopupMenuProps,\n CourierToastProps,\n} from '@trycourier/courier-react-components';\n\n// Re-export types from courier-js\nexport type {\n CourierProps,\n CourierClientOptions,\n CourierBrand,\n CourierApiUrls,\n CourierUserPreferences,\n CourierUserPreferencesStatus,\n CourierUserPreferencesChannel,\n CourierUserPreferencesPaging,\n CourierUserPreferencesTopic,\n CourierUserPreferencesTopicResponse,\n CourierDevice,\n CourierToken,\n CourierGetInboxMessageResponse,\n CourierGetInboxMessagesResponse,\n InboxMessage,\n InboxAction,\n InboxMessageEventEnvelope,\n} from '@trycourier/courier-js';\n\n// Re-export utility functions from courier-ui-inbox\nexport {\n markAsRead,\n markAsUnread,\n clickMessage,\n archiveMessage,\n openMessage\n} from '@trycourier/courier-ui-inbox';\n\n// Re-export factory prop types from courier-ui-inbox\nexport type {\n CourierInboxHeaderFactoryProps,\n CourierInboxStateLoadingFactoryProps,\n CourierInboxStateEmptyFactoryProps,\n CourierInboxStateErrorFactoryProps,\n CourierInboxListItemFactoryProps,\n CourierInboxListItemActionFactoryProps,\n CourierInboxPaginationItemFactoryProps,\n CourierInboxMenuButtonFactoryProps,\n CourierInboxFeedType\n} from '@trycourier/courier-ui-inbox';\n\n// Re-export theme types from courier-ui-inbox\nexport type {\n CourierInboxTheme,\n CourierInboxFontTheme,\n CourierInboxIconTheme,\n CourierInboxFilterItemTheme,\n CourierInboxUnreadCountIndicatorTheme,\n CourierInboxUnreadDotIndicatorTheme,\n CourierInboxIconButtonTheme,\n CourierInboxButtonTheme,\n CourierInboxMenuButtonTheme,\n CourierInboxPopupTheme,\n CourierInboxListItemTheme,\n CourierInboxSkeletonLoadingStateTheme,\n CourierInboxInfoStateTheme,\n CourierMenuItemTheme,\n CourierFilterMenuTheme,\n CourierActionMenuTheme\n} from '@trycourier/courier-ui-inbox';\n\n// Re-export theme utilities from courier-ui-inbox\nexport {\n defaultLightTheme,\n defaultDarkTheme,\n mergeTheme\n} from '@trycourier/courier-ui-inbox';\n\n// Re-export element types from courier-ui-inbox\nexport type { CourierInbox as CourierInboxElement } from '@trycourier/courier-ui-inbox';\nexport type { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from '@trycourier/courier-ui-inbox';\n\n// Re-export element types from courier-ui-toast\nexport type { CourierToast as CourierToastElement } from '@trycourier/courier-ui-toast';\n\n// Re-export toast types from courier-ui-toast\nexport type {\n CourierToastTheme,\n CourierToastFontTheme,\n CourierToastIconTheme,\n CourierToastItemTheme,\n CourierToastItemFactoryProps,\n CourierToastItemClickEvent,\n CourierToastDismissButtonOption\n} from '@trycourier/courier-ui-toast';\n\n// Re-export toast theme utilities from courier-ui-toast\nexport {\n defaultLightTheme as defaultToastLightTheme,\n defaultDarkTheme as defaultToastDarkTheme,\n mergeTheme as mergeToastTheme\n} from '@trycourier/courier-ui-toast';\n\n// Re-export types from courier-ui-core\nexport type {\n CourierComponentThemeMode\n} from '@trycourier/courier-ui-core'\n"],"names":["reactNodeToHTMLElement","node","container","document","createElement","root","createRoot","flushSync","render","CourierInbox","forwardRef","props","ref","jsx","CourierRenderContext","Provider","value","children","CourierInboxComponent","displayName","CourierInboxPopupMenu","CourierInboxPopupMenuComponent","CourierToast","CourierToastComponent","Courier","shared","courierUserAgentName","courierUserAgentVersion"],"mappings":"uWAUO,SAASA,EAAuBC,GACrC,MAAMC,EAAYC,SAASC,cAAc,OAGnCC,EAAOC,EAAAA,WAAWJ,GAOxB,OANAK,EAAAA,WAAU,KACRF,EAAKG,OAAOP,EAAI,IAKXC,CACT,CCIO,MAAMO,EAAeC,EAAAA,YAAmD,CAACC,EAAOC,MAEnFC,IAACC,EAAAA,qBAAqBC,SAArB,CAA8BC,MAAOhB,EACpCiB,WAAAJ,IAACK,EAAAA,sBAAA,IAA0BP,EAAOC,YAKxCH,EAAaU,YAAc,eCNpB,MAAMC,EAAwBV,EAAAA,YAAqE,CAACC,EAAOC,MAE9GC,IAACC,EAAAA,qBAAqBC,SAArB,CAA8BC,MAAOhB,EACpCiB,WAAAJ,IAACQ,EAAAA,+BAAA,IAAmCV,EAAOC,YAKjDQ,EAAsBD,YAAc,wBCV7B,MAAMG,EAAeZ,EAAAA,YAAmD,CAACC,EAAOC,MAEnFC,IAACC,EAAAA,qBAAqBC,SAArB,CAA8BC,MAAOhB,EACpCiB,WAAAJ,IAACU,EAAAA,sBAAA,IAA0BZ,EAAOC,YAKxCU,EAAaH,YAAc,eChC3BK,EAAAA,QAAQC,OAAOC,qBAAuB,gBACtCF,EAAAA,QAAQC,OAAOE,wBAA0B"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { CourierInbox } from './components/courier-inbox';
2
2
  export { CourierInboxPopupMenu } from './components/courier-inbox-popup-menu';
3
+ export { CourierToast } from './components/courier-toast';
3
4
  export { useCourier } from '@trycourier/courier-react-components';
4
- export type { CourierInboxProps, CourierInboxPopupMenuProps, } from '@trycourier/courier-react-components';
5
+ export type { CourierInboxProps, CourierInboxPopupMenuProps, CourierToastProps, } from '@trycourier/courier-react-components';
5
6
  export type { CourierProps, CourierClientOptions, CourierBrand, CourierApiUrls, CourierUserPreferences, CourierUserPreferencesStatus, CourierUserPreferencesChannel, CourierUserPreferencesPaging, CourierUserPreferencesTopic, CourierUserPreferencesTopicResponse, CourierDevice, CourierToken, CourierGetInboxMessageResponse, CourierGetInboxMessagesResponse, InboxMessage, InboxAction, InboxMessageEventEnvelope, } from '@trycourier/courier-js';
6
7
  export { markAsRead, markAsUnread, clickMessage, archiveMessage, openMessage } from '@trycourier/courier-ui-inbox';
7
8
  export type { CourierInboxHeaderFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxStateEmptyFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxListItemFactoryProps, CourierInboxListItemActionFactoryProps, CourierInboxPaginationItemFactoryProps, CourierInboxMenuButtonFactoryProps, CourierInboxFeedType } from '@trycourier/courier-ui-inbox';
@@ -9,4 +10,7 @@ export type { CourierInboxTheme, CourierInboxFontTheme, CourierInboxIconTheme, C
9
10
  export { defaultLightTheme, defaultDarkTheme, mergeTheme } from '@trycourier/courier-ui-inbox';
10
11
  export type { CourierInbox as CourierInboxElement } from '@trycourier/courier-ui-inbox';
11
12
  export type { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from '@trycourier/courier-ui-inbox';
13
+ export type { CourierToast as CourierToastElement } from '@trycourier/courier-ui-toast';
14
+ export type { CourierToastTheme, CourierToastFontTheme, CourierToastIconTheme, CourierToastItemTheme, CourierToastItemFactoryProps, CourierToastItemClickEvent, CourierToastDismissButtonOption } from '@trycourier/courier-ui-toast';
15
+ export { defaultLightTheme as defaultToastLightTheme, defaultDarkTheme as defaultToastDarkTheme, mergeTheme as mergeToastTheme } from '@trycourier/courier-ui-toast';
12
16
  export type { CourierComponentThemeMode } from '@trycourier/courier-ui-core';
package/dist/index.mjs CHANGED
@@ -1,23 +1,19 @@
1
+ import { Courier } from "@trycourier/courier-js";
1
2
  import { jsx } from "react/jsx-runtime";
2
3
  import { forwardRef } from "react";
3
- import { CourierRenderContext, CourierInboxComponent, CourierInboxPopupMenuComponent } from "@trycourier/courier-react-components";
4
+ import { CourierRenderContext, CourierInboxComponent, CourierInboxPopupMenuComponent, CourierToastComponent } from "@trycourier/courier-react-components";
4
5
  import { useCourier } from "@trycourier/courier-react-components";
5
6
  import { flushSync } from "react-dom";
6
7
  import { createRoot } from "react-dom/client";
7
8
  import { archiveMessage, clickMessage, defaultDarkTheme, defaultLightTheme, markAsRead, markAsUnread, mergeTheme, openMessage } from "@trycourier/courier-ui-inbox";
9
+ import { defaultDarkTheme as defaultDarkTheme2, defaultLightTheme as defaultLightTheme2, mergeTheme as mergeTheme2 } from "@trycourier/courier-ui-toast";
8
10
  function reactNodeToHTMLElement(node) {
9
11
  const container = document.createElement("div");
10
12
  const root = createRoot(container);
11
13
  flushSync(() => {
12
14
  root.render(node);
13
15
  });
14
- const element = container.firstElementChild;
15
- if (!(element instanceof HTMLElement)) {
16
- throw new Error(
17
- "renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)"
18
- );
19
- }
20
- return element;
16
+ return container;
21
17
  }
22
18
  const CourierInbox = forwardRef((props, ref) => {
23
19
  return /* @__PURE__ */ jsx(CourierRenderContext.Provider, { value: reactNodeToHTMLElement, children: /* @__PURE__ */ jsx(CourierInboxComponent, { ...props, ref }) });
@@ -27,16 +23,26 @@ const CourierInboxPopupMenu = forwardRef((props, ref) => {
27
23
  return /* @__PURE__ */ jsx(CourierRenderContext.Provider, { value: reactNodeToHTMLElement, children: /* @__PURE__ */ jsx(CourierInboxPopupMenuComponent, { ...props, ref }) });
28
24
  });
29
25
  CourierInboxPopupMenu.displayName = "CourierInboxPopupMenu";
26
+ const CourierToast = forwardRef((props, ref) => {
27
+ return /* @__PURE__ */ jsx(CourierRenderContext.Provider, { value: reactNodeToHTMLElement, children: /* @__PURE__ */ jsx(CourierToastComponent, { ...props, ref }) });
28
+ });
29
+ CourierToast.displayName = "CourierToast";
30
+ Courier.shared.courierUserAgentName = "courier-react";
31
+ Courier.shared.courierUserAgentVersion = "8.2.0";
30
32
  export {
31
33
  CourierInbox,
32
34
  CourierInboxPopupMenu,
35
+ CourierToast,
33
36
  archiveMessage,
34
37
  clickMessage,
35
38
  defaultDarkTheme,
36
39
  defaultLightTheme,
40
+ defaultDarkTheme2 as defaultToastDarkTheme,
41
+ defaultLightTheme2 as defaultToastLightTheme,
37
42
  markAsRead,
38
43
  markAsUnread,
39
44
  mergeTheme,
45
+ mergeTheme2 as mergeToastTheme,
40
46
  openMessage,
41
47
  useCourier
42
48
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/utils/render.tsx","../src/components/courier-inbox.tsx","../src/components/courier-inbox-popup-menu.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { createRoot } from \"react-dom/client\";\n\n/**\n * Converts a React node to an HTMLElement.\n * This function uses flushSync to ensure the DOM is updated synchronously.\n * @param node - The React node to convert.\n * @returns The converted HTMLElement.\n */\nexport function reactNodeToHTMLElement(node: ReactNode): HTMLElement {\n const container = document.createElement('div');\n\n // Use React 18 root\n const root = createRoot(container);\n flushSync(() => {\n root.render(node);\n });\n\n // Wait until React mounts the content synchronously\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)'\n );\n }\n\n return element;\n}\n","import { forwardRef } from \"react\";\nimport { CourierInbox as CourierInboxElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxComponent, CourierInboxProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInbox React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInbox />;\n * ```\n */\nexport const CourierInbox = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInbox.displayName = 'CourierInbox';\n","import { forwardRef } from \"react\";\nimport { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxPopupMenuComponent, CourierInboxPopupMenuProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInboxPopupMenu React component.\n *\n * This component is used to display a popup menu for a message in the inbox.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInboxPopupMenu />;\n * ```\n */\nexport const CourierInboxPopupMenu = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxPopupMenuComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInboxPopupMenu.displayName = 'CourierInboxPopupMenu';\n"],"names":[],"mappings":";;;;;;;AAUO,SAAS,uBAAuB,MAA8B;AACnE,QAAM,YAAY,SAAS,cAAc,KAAK;AAG9C,QAAM,OAAO,WAAW,SAAS;AACjC,YAAU,MAAM;AACd,SAAK,OAAO,IAAI;AAAA,EAClB,CAAC;AAGD,QAAM,UAAU,UAAU;AAC1B,MAAI,EAAE,mBAAmB,cAAc;AACrC,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AACT;ACFO,MAAM,eAAe,WAAmD,CAAC,OAAO,QAAQ;AAC7F,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,wBACpC,UAAA,oBAAC,uBAAA,EAAuB,GAAG,OAAO,IAAA,CAAU,EAAA,CAC9C;AAEJ,CAAC;AAED,aAAa,cAAc;ACNpB,MAAM,wBAAwB,WAAqE,CAAC,OAAO,QAAQ;AACxH,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,wBACpC,UAAA,oBAAC,gCAAA,EAAgC,GAAG,OAAO,IAAA,CAAU,EAAA,CACvD;AAEJ,CAAC;AAED,sBAAsB,cAAc;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/utils/render.tsx","../src/components/courier-inbox.tsx","../src/components/courier-inbox-popup-menu.tsx","../src/components/courier-toast.tsx","../src/index.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { createRoot } from \"react-dom/client\";\n\n/**\n * Converts a React node to an HTMLElement.\n * This function uses flushSync to ensure the DOM is updated synchronously.\n * @param node - The React node to convert.\n * @returns The converted HTMLElement.\n */\nexport function reactNodeToHTMLElement(node: ReactNode): HTMLElement {\n const container = document.createElement('div');\n\n // Use React 18 root\n const root = createRoot(container);\n flushSync(() => {\n root.render(node);\n });\n\n // Return the container to preserve React's event handling\n // The container maintains the React root and event delegation\n return container;\n}\n","import { forwardRef } from \"react\";\nimport { CourierInbox as CourierInboxElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxComponent, CourierInboxProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInbox React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInbox />;\n * ```\n */\nexport const CourierInbox = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInbox.displayName = 'CourierInbox';\n","import { forwardRef } from \"react\";\nimport { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxPopupMenuComponent, CourierInboxPopupMenuProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInboxPopupMenu React component.\n *\n * This component is used to display a popup menu for a message in the inbox.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInboxPopupMenu />;\n * ```\n */\nexport const CourierInboxPopupMenu = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxPopupMenuComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInboxPopupMenu.displayName = 'CourierInboxPopupMenu';\n","import { forwardRef } from \"react\";\nimport { CourierToast as CourierToastElement } from \"@trycourier/courier-ui-toast\";\nimport { CourierToastComponent, CourierToastProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierToast React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierToast />;\n * ```\n */\nexport const CourierToast = forwardRef<CourierToastElement, CourierToastProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierToastComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierToast.displayName = 'CourierToast';\n","import { Courier } from '@trycourier/courier-js';\n\nCourier.shared.courierUserAgentName = \"courier-react\";\nCourier.shared.courierUserAgentVersion = __PACKAGE_VERSION__;\n\nexport { CourierInbox } from './components/courier-inbox';\nexport { CourierInboxPopupMenu } from './components/courier-inbox-popup-menu';\nexport { CourierToast } from './components/courier-toast';\n\nexport { useCourier } from '@trycourier/courier-react-components';\n\nexport type {\n CourierInboxProps,\n CourierInboxPopupMenuProps,\n CourierToastProps,\n} from '@trycourier/courier-react-components';\n\n// Re-export types from courier-js\nexport type {\n CourierProps,\n CourierClientOptions,\n CourierBrand,\n CourierApiUrls,\n CourierUserPreferences,\n CourierUserPreferencesStatus,\n CourierUserPreferencesChannel,\n CourierUserPreferencesPaging,\n CourierUserPreferencesTopic,\n CourierUserPreferencesTopicResponse,\n CourierDevice,\n CourierToken,\n CourierGetInboxMessageResponse,\n CourierGetInboxMessagesResponse,\n InboxMessage,\n InboxAction,\n InboxMessageEventEnvelope,\n} from '@trycourier/courier-js';\n\n// Re-export utility functions from courier-ui-inbox\nexport {\n markAsRead,\n markAsUnread,\n clickMessage,\n archiveMessage,\n openMessage\n} from '@trycourier/courier-ui-inbox';\n\n// Re-export factory prop types from courier-ui-inbox\nexport type {\n CourierInboxHeaderFactoryProps,\n CourierInboxStateLoadingFactoryProps,\n CourierInboxStateEmptyFactoryProps,\n CourierInboxStateErrorFactoryProps,\n CourierInboxListItemFactoryProps,\n CourierInboxListItemActionFactoryProps,\n CourierInboxPaginationItemFactoryProps,\n CourierInboxMenuButtonFactoryProps,\n CourierInboxFeedType\n} from '@trycourier/courier-ui-inbox';\n\n// Re-export theme types from courier-ui-inbox\nexport type {\n CourierInboxTheme,\n CourierInboxFontTheme,\n CourierInboxIconTheme,\n CourierInboxFilterItemTheme,\n CourierInboxUnreadCountIndicatorTheme,\n CourierInboxUnreadDotIndicatorTheme,\n CourierInboxIconButtonTheme,\n CourierInboxButtonTheme,\n CourierInboxMenuButtonTheme,\n CourierInboxPopupTheme,\n CourierInboxListItemTheme,\n CourierInboxSkeletonLoadingStateTheme,\n CourierInboxInfoStateTheme,\n CourierMenuItemTheme,\n CourierFilterMenuTheme,\n CourierActionMenuTheme\n} from '@trycourier/courier-ui-inbox';\n\n// Re-export theme utilities from courier-ui-inbox\nexport {\n defaultLightTheme,\n defaultDarkTheme,\n mergeTheme\n} from '@trycourier/courier-ui-inbox';\n\n// Re-export element types from courier-ui-inbox\nexport type { CourierInbox as CourierInboxElement } from '@trycourier/courier-ui-inbox';\nexport type { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from '@trycourier/courier-ui-inbox';\n\n// Re-export element types from courier-ui-toast\nexport type { CourierToast as CourierToastElement } from '@trycourier/courier-ui-toast';\n\n// Re-export toast types from courier-ui-toast\nexport type {\n CourierToastTheme,\n CourierToastFontTheme,\n CourierToastIconTheme,\n CourierToastItemTheme,\n CourierToastItemFactoryProps,\n CourierToastItemClickEvent,\n CourierToastDismissButtonOption\n} from '@trycourier/courier-ui-toast';\n\n// Re-export toast theme utilities from courier-ui-toast\nexport {\n defaultLightTheme as defaultToastLightTheme,\n defaultDarkTheme as defaultToastDarkTheme,\n mergeTheme as mergeToastTheme\n} from '@trycourier/courier-ui-toast';\n\n// Re-export types from courier-ui-core\nexport type {\n CourierComponentThemeMode\n} from '@trycourier/courier-ui-core'\n"],"names":[],"mappings":";;;;;;;;;AAUO,SAAS,uBAAuB,MAA8B;AACnE,QAAM,YAAY,SAAS,cAAc,KAAK;AAG9C,QAAM,OAAO,WAAW,SAAS;AACjC,YAAU,MAAM;AACd,SAAK,OAAO,IAAI;AAAA,EAClB,CAAC;AAID,SAAO;AACT;ACIO,MAAM,eAAe,WAAmD,CAAC,OAAO,QAAQ;AAC7F,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,wBACpC,UAAA,oBAAC,uBAAA,EAAuB,GAAG,OAAO,IAAA,CAAU,EAAA,CAC9C;AAEJ,CAAC;AAED,aAAa,cAAc;ACNpB,MAAM,wBAAwB,WAAqE,CAAC,OAAO,QAAQ;AACxH,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,wBACpC,UAAA,oBAAC,gCAAA,EAAgC,GAAG,OAAO,IAAA,CAAU,EAAA,CACvD;AAEJ,CAAC;AAED,sBAAsB,cAAc;ACV7B,MAAM,eAAe,WAAmD,CAAC,OAAO,QAAQ;AAC7F,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,wBACpC,UAAA,oBAAC,uBAAA,EAAuB,GAAG,OAAO,IAAA,CAAU,EAAA,CAC9C;AAEJ,CAAC;AAED,aAAa,cAAc;AChC3B,QAAQ,OAAO,uBAAuB;AACtC,QAAQ,OAAO,0BAA0B;"}
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react",
3
- "version": "8.0.29",
3
+ "version": "8.2.0",
4
4
  "description": "The React components for the Courier web UI",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -8,11 +8,13 @@
8
8
  "scripts": {
9
9
  "dev": "vite",
10
10
  "build": "cross-env NODE_ENV=production tsc && vite build --mode production",
11
+ "build:ci": "yarn build && yarn generate-api-doc",
11
12
  "watch": "vite build --watch",
12
13
  "preview": "vite preview",
13
14
  "prepare": "npm run build",
14
15
  "test": "jest",
15
- "test:watch": "jest --watch"
16
+ "test:watch": "jest --watch",
17
+ "generate-api-doc": "api-extractor run"
16
18
  },
17
19
  "files": [
18
20
  "dist"
@@ -27,10 +29,11 @@
27
29
  "author": "Courier",
28
30
  "license": "MIT",
29
31
  "dependencies": {
30
- "@trycourier/courier-js": "2.0.12",
31
- "@trycourier/courier-react-components": "1.0.4",
32
- "@trycourier/courier-ui-core": "1.0.13",
33
- "@trycourier/courier-ui-inbox": "1.0.18"
32
+ "@trycourier/courier-js": "2.1.0",
33
+ "@trycourier/courier-react-components": "1.2.0",
34
+ "@trycourier/courier-ui-core": "1.0.14",
35
+ "@trycourier/courier-ui-inbox": "1.2.0",
36
+ "@trycourier/courier-ui-toast": "1.0.0"
34
37
  },
35
38
  "peerDependencies": {
36
39
  "react": ">=18.0.0",