@novu/nextjs 3.10.1 → 3.11.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 (2) hide show
  1. package/README.md +38 -6
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -88,11 +88,11 @@ function Novu() {
88
88
 
89
89
  ## HMAC Encryption
90
90
 
91
- When Novu's user adds the Inbox to their application they are required to pass a `subscriberId` which identifies the user's end-customer, and the application Identifier which is acted as a public key to communicate with the notification feed API.
91
+ When Novu's user adds the Inbox to their application they are required to pass a `subscriberId` which identifies the user's end-customer, and the application Identifier which is acted as a public key to communicate with the notification feed API.
92
92
 
93
- A malicious actor can access the user feed by accessing the API and passing another `subscriberId` using the public application identifier.
93
+ A malicious actor can access the user feed by accessing the API and passing another `subscriberId` using the public application identifier.
94
94
 
95
- HMAC encryption will make sure that a `subscriberId` is encrypted using the secret API key, and those will prevent malicious actors from impersonating users.
95
+ HMAC encryption will make sure that a `subscriberId` is encrypted using the secret API key, and those will prevent malicious actors from impersonating users.
96
96
 
97
97
  ### Enabling HMAC Encryption
98
98
 
@@ -102,15 +102,17 @@ In order to enable Hash-Based Message Authentication Codes, you need to visit th
102
102
  <img src="/images/notification-center/client/react/get-started/hmac-encryption-enable.png" />
103
103
  </Frame>
104
104
 
105
- 1. Next step would be to generate an HMAC encrypted subscriberId on your backend:
105
+ #### Subscriber HMAC
106
+
107
+ 1. Generate an HMAC encrypted subscriberId on your backend:
106
108
 
107
109
  ```jsx
108
110
  import { createHmac } from 'crypto';
109
111
 
110
- const hmacHash = createHmac('sha256', process.env.NOVU_API_KEY).update(subscriberId).digest('hex');
112
+ const subscriberHash = createHmac('sha256', process.env.NOVU_API_KEY).update(subscriberId).digest('hex');
111
113
  ```
112
114
 
113
- 2. Then pass the created HMAC to your client side application forward it to the component:
115
+ 2. Pass the created HMAC to your client side application:
114
116
 
115
117
  ```jsx
116
118
  <Inbox
@@ -123,6 +125,36 @@ const hmacHash = createHmac('sha256', process.env.NOVU_API_KEY).update(subscribe
123
125
  > Note: If HMAC encryption is active in In-App provider settings and `subscriberHash`
124
126
  > along with `subscriberId` is not provided, then Inbox will not load
125
127
 
128
+ #### Context HMAC (Optional)
129
+
130
+ If you're using the `context` prop to pass additional data (e.g., tenant information, environment, etc.), you should also generate a `contextHash` to prevent context tampering:
131
+
132
+ 1. Generate an HMAC for the context on your backend:
133
+
134
+ ```jsx
135
+ import { createHmac } from 'crypto';
136
+ import { canonicalize } from '@tufjs/canonical-json';
137
+
138
+ const context = { tenant: 'acme', app: 'dashboard' };
139
+ const contextHash = createHmac('sha256', process.env.NOVU_API_KEY)
140
+ .update(canonicalize(context))
141
+ .digest('hex');
142
+ ```
143
+
144
+ 2. Pass both the context and contextHash to the component:
145
+
146
+ ```jsx
147
+ <Inbox
148
+ subscriberId={'SUBSCRIBER_ID_PLAIN_VALUE'}
149
+ subscriberHash={'SUBSCRIBER_ID_HASH_VALUE'}
150
+ context={{ tenant: 'acme', app: 'dashboard' }}
151
+ contextHash={'CONTEXT_HASH_VALUE'}
152
+ applicationIdentifier={'APPLICATION_IDENTIFIER'}
153
+ />
154
+ ```
155
+
156
+ > Note: When HMAC encryption is enabled and `context` is provided, the `contextHash` is required. The hash is order-independent, so `{a:1, b:2}` produces the same hash as `{b:2, a:1}`.
157
+
126
158
  ## Use your own backend and socket URL
127
159
 
128
160
  By default, Novu's hosted services for API and socket are used. If you want, you can override them and configure your own.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novu/nextjs",
3
- "version": "3.10.1",
3
+ "version": "3.11.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/novuhq/novu",
@@ -93,7 +93,7 @@
93
93
  }
94
94
  },
95
95
  "dependencies": {
96
- "@novu/react": "3.10.1"
96
+ "@novu/react": "3.11.0"
97
97
  },
98
98
  "nx": {
99
99
  "tags": [