@trycourier/react-provider 1.14.2 → 1.15.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.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +118 -0
  3. package/package.json +3 -3
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Courier
3
+ Copyright (c) 2022 Courier
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
2
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3
+
4
+ - [Props](#props)
5
+ - [Listening to Messsages](#listening-to-messsages)
6
+
7
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
8
+
9
+ <a name="0propsmd"></a>
10
+
11
+ ### [Props](#props)
12
+
13
+ ```
14
+ export interface ICourierProvider {
15
+ // Public Client Key used to identify your workspace
16
+ clientKey?: string;
17
+
18
+ // Matches the recipient/user id used in Courier
19
+ userId?: string;
20
+
21
+ // HMAC signature
22
+ userSignature?: string;
23
+
24
+ // Callback to listen for new messages
25
+ onMessage?: Interceptor;
26
+ }
27
+ ```
28
+
29
+ <a name="1listening-to-messagesmd"></a>
30
+
31
+ ### [Listening to Messsages](#listening)
32
+
33
+ There are a few ways to listen for messages and being able react.
34
+
35
+ 1. Via Props
36
+
37
+ ```
38
+ import { CourierProvider } from "@trycourier/react-provider";
39
+
40
+ const MyApp = ({ children }) => {
41
+ const handleOnMessage = (messsage: ICourierMessage) => {
42
+ console.log(message);
43
+ return message;
44
+ }
45
+
46
+ return (
47
+ <CourierProvider onMessage={handleOnMessage}>
48
+ {children}
49
+ </CourierProvider>
50
+ )
51
+ }
52
+ ```
53
+
54
+ 2. Via Transport
55
+
56
+ You can create a Transport and pass it into CourierProvider.
57
+
58
+ ```
59
+
60
+ import { useEffect } from 'react';
61
+ import { CourierProvider, CourierTransport } from "@trycourier/react-provider";
62
+
63
+ const courierTransport = new CourierTransport({
64
+ clientKey: CLIENT_KEY,
65
+ });
66
+
67
+ const MyApp = ({ children }) => {
68
+ useEffect(() => {
69
+ courierTransport.intercept((message) => {
70
+ console.log(message);
71
+ return message;
72
+ });
73
+ })
74
+
75
+ return (
76
+ <CourierProvider transport={courierTransport}>
77
+ {children}
78
+ </CourierProvider>
79
+ )
80
+ }
81
+ ```
82
+
83
+ 3. Via useCourier hook
84
+
85
+ If you don't pass in a transport, we will automatically create one. You can then access the transport via the CourierContext exposed through useCourier.
86
+
87
+ ```
88
+ import { useEffect } from 'react';
89
+ import { CourierProvider, useCourier } from "@trycourier/react-provider";
90
+
91
+ const courierTransport = new CourierTransport({
92
+ clientKey: CLIENT_KEY,
93
+ });
94
+
95
+ const MyComponent = () => {
96
+ const courier = useCourier();
97
+
98
+ useEffect(() => {
99
+ courier.transport.intercept((message) => {
100
+ console.log(message);
101
+ return message;
102
+ });
103
+ })
104
+
105
+ return (
106
+ <div>Hello World</div>
107
+ );
108
+ }
109
+
110
+
111
+ const MyApp = ({ children }) => {
112
+ return (
113
+ <CourierProvider>
114
+ <MyComponent />
115
+ </CourierProvider>
116
+ )
117
+ }
118
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/react-provider",
3
- "version": "1.14.2",
3
+ "version": "1.15.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "typings/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
- "@trycourier/client-graphql": "^1.14.2",
19
+ "@trycourier/client-graphql": "^1.15.0",
20
20
  "buffer": "^6.0.3",
21
21
  "graphql": "^15.5.0",
22
22
  "react-use": "^17.2.1",
@@ -32,5 +32,5 @@
32
32
  "dist/",
33
33
  "typings/"
34
34
  ],
35
- "gitHead": "c66337dc1a5adf809384b7d3cd032ed702e2ff6c"
35
+ "gitHead": "8f45c99f7b74d24afa6df3895e12f4bdc1bbfe90"
36
36
  }