@nuvei-connect/nc-websdk 1.12.0 → 1.12.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 (2) hide show
  1. package/README.md +108 -213
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -3,6 +3,15 @@
3
3
 
4
4
  A practical guide for integrating **Nuvei WebSDK** into a React application using the `@nuvei-connect/nc-websdk` package.
5
5
 
6
+ ---
7
+ ## Prerequisites
8
+
9
+ | Item | Description | Example |
10
+ |---|---|---|
11
+ | **Backend Access Token** | A valid access token required by the backend to authenticate with Nuvei services. | `634f59fa0917b38886a2a781d24362c405:79ac4c2087d6053430e6abc2734f4c42fd` |
12
+ | **Authentication Endpoint** | Backend endpoint used by the WebSDK to create the MFE session. | `POST https://api.example.com/api/auth/session` |
13
+ | **Module Name** | The Nuvei module to be loaded by the WebSDK. | `ONBOARDING`,`DOC_UTILITY` |
14
+ | **Merchant / Partner Distinguishers** | Values used to identify whether the current request is for a Merchant or Partner. | `isGuest: true`, `emailAddress: "user@example.com"`, `partnerId: "partner_123"` |
6
15
  ---
7
16
 
8
17
  # Step 1 - Installation
@@ -52,7 +61,7 @@ useEffect(() => {
52
61
  container: containerRef.current.id,
53
62
  componentName: ModulesNameEnum.ONBOARDING_MERCHANT,
54
63
  fetchClientSession : async() => {
55
- const response = await fetch(`${backendApiUrl}/api/nuvei/auth/session`, { method: "POST"});
64
+ const response = await fetch(`${backendApiUrl}/api/auth/session`, { method: "POST"});
56
65
  if (!response.ok) { throw new Error(`Session error: ${response.status}`);}
57
66
  return await response.json();
58
67
  };,
@@ -73,9 +82,9 @@ return (
73
82
  The backend then calls the Nuvei token/session endpoint : in nodejs backend
74
83
 
75
84
  ```ts
76
- app.post("/api/nuvei/auth/session", async (_req: Request, res: Response) => {
85
+ app.post("/api/auth/session", async (_req: Request, res: Response) => {
77
86
  try {
78
- const response = await fetch('https://nonprodmanagement-us-e.azure-api.net/dev2/v1/auth/micro-frontend/tokens', {
87
+ const response = await fetch('https://nuvei_backend_url/dev2/v1/auth/micro-frontend/tokens', {
79
88
  method: "POST",
80
89
  headers: {
81
90
  "Content-Type": "application/json",
@@ -102,7 +111,9 @@ app.post("/api/nuvei/auth/session", async (_req: Request, res: Response) => {
102
111
  });
103
112
 
104
113
  ```
114
+ These are the **minimum requirements** needed to integrate the Nuvei Web SDK.
105
115
 
116
+ If additional configuration or advanced options are required, please refer to the **sections below in this documentation** for detailed configuration references and usage examples.
106
117
 
107
118
  ---
108
119
 
@@ -133,7 +144,7 @@ const App: React.FC = () => {
133
144
  container: containerRef.current.id,
134
145
  componentName: ModulesNameEnum.ONBOARDING_MERCHANT,
135
146
  fetchClientSession : async() => {
136
- const response = await fetch(`${backendApiUrl}/api/nuvei/auth/session`, { method: "POST"});
147
+ const response = await fetch(`${backendApiUrl}/api/auth/session`, { method: "POST"});
137
148
  if (!response.ok) { throw new Error(`Session error: ${response.status}`);}
138
149
  return await response.json();
139
150
  },
@@ -145,29 +156,7 @@ const App: React.FC = () => {
145
156
  }, []);
146
157
 
147
158
 
148
- return (
149
- <div className="app-container">
150
- <header className="app-header">
151
- <h1>Nuvei WebSDK React Demo</h1>
152
-
153
- <p>
154
- Minimal implementation using <code>@nuvei-connect/nc-websdk</code>.
155
- </p>
156
- </header>
157
-
158
- <main className="app-main">
159
- <div
160
- id="nuvei-websdk-container"
161
- ref={containerRef}
162
- style={{
163
- width: "100%",
164
- minHeight: "calc(100vh - 100px)",
165
- border: "none",
166
- }}
167
- />
168
- </main>
169
- </div>
170
- );
159
+ return (<div id="nuvei-websdk-container" ref={containerRef} style={{width: "100%",height: "100%" }}/>);
171
160
  };
172
161
 
173
162
  export default App;
@@ -177,104 +166,119 @@ export default App;
177
166
 
178
167
  # 5. Loading Different Modules
179
168
 
180
- The module is selected through `componentName`.
169
+ The Nuvei WebSDK supports separate modules for different use cases:
181
170
 
182
- ## Partner Onboarding
171
+ | Module | Purpose | Component |
172
+ | --------------- | ------------------------------- | -------------------------------------------- |
173
+ | **ONBOARDING** | Merchant and Partner onboarding | `ONBOARDING_MERCHANT` / `ONBOARDING_PARTNER` |
174
+ | **DOC_UTILITY** | Document utility operations | `DOC_UTILITY` |
183
175
 
184
- Use:
176
+ For **Onboarding**, the backend authentication request and the SDK `componentName` determine whether the flow is for a **Merchant** or **Partner**.
185
177
 
186
- ```tsx
187
- componentName: ModulesNameEnum.ONBOARDING_PARTNER;
178
+ ---
179
+
180
+ ## 5.1 Partner Onboarding
181
+
182
+ For Partner onboarding, provide the following values when authenticating with the Nuvei backend:
183
+
184
+ * **Module:** `ONBOARDING`
185
+ * **isGuest:** `false`
186
+ * **emailAddress(optional):** Partner email address
187
+ * **partnerId(optional):** Partner ID
188
+
189
+ Backend Authentication Request:
190
+
191
+ ```ts
192
+ body: JSON.stringify({
193
+ modules: [
194
+ {
195
+ name: "ONBOARDING",
196
+ },
197
+ ],
198
+ isGuest: false,
199
+ emailAddress: "your_partner_email_address",
200
+ partnerId: "your_partner_id",
201
+ }),
188
202
  ```
189
203
 
190
- Example:
204
+ Then, load the Partner onboarding component using:
191
205
 
192
206
  ```tsx
193
207
  NuveiSDK.mount({
194
- container: containerRef.current.id,
195
208
  componentName: ModulesNameEnum.ONBOARDING_PARTNER,
196
-
197
- fetchClientSession,
198
-
199
- onError: (error: any) => {
200
- console.error("NuveiWebSDK Error:", error);
201
- },
202
-
203
- config: {
204
- environment: "dev2",
205
- },
206
209
  });
207
210
  ```
208
211
 
212
+
209
213
  ---
210
214
 
211
- ## Merchant Onboarding
215
+ ## 5.2 Merchant Onboarding
212
216
 
213
- Use:
217
+ For Merchant onboarding, provide the following values when authenticating with the Nuvei backend:
214
218
 
215
- ```tsx
216
- componentName: ModulesNameEnum.ONBOARDING_MERCHANT;
219
+ * **Module:** `ONBOARDING`
220
+ * **isGuest:** `true`
221
+ * **emailAddress:** Merchant email address
222
+ * **partnerId(optional):** Partner ID
223
+
224
+ Backend Authentication Request:
225
+
226
+ ```ts
227
+ body: JSON.stringify({
228
+ modules: [
229
+ {
230
+ name: "ONBOARDING",
231
+ },
232
+ ],
233
+ isGuest: true,
234
+ emailAddress: "your_merchant_email_address",
235
+ partnerId: "your_partner_id",
236
+ }),
217
237
  ```
218
238
 
219
- Example:
239
+ Then, load the Merchant onboarding component using:
220
240
 
221
241
  ```tsx
222
242
  NuveiSDK.mount({
223
- container: containerRef.current.id,
224
243
  componentName: ModulesNameEnum.ONBOARDING_MERCHANT,
225
-
226
- fetchClientSession,
227
-
228
- onError: (error: any) => {
229
- console.error("NuveiWebSDK Error:", error);
230
- },
231
-
232
- config: {
233
- environment: "dev2",
234
- },
235
244
  });
236
245
  ```
237
246
 
238
247
  ---
239
248
 
240
- ## Document Utility
249
+ ## 5.3 Document Utility
250
+
251
+ Document Utility is a separate module from Onboarding.
241
252
 
242
- Use the document utility module exposed by your SDK.
253
+ When using Document Utility:
243
254
 
244
- Example structure:
255
+ * **Module:** `DOC_UTILITY`
256
+ * **Component:** `ModulesNameEnum.DOC_UTILITY`
257
+
258
+ Example:
245
259
 
246
260
  ```tsx
247
261
  NuveiSDK.mount({
248
262
  container: containerRef.current.id,
249
- componentName: ModulesNameEnum.ONBOARDING_MERCHANT,
250
-
251
- fetchClientSession,
252
-
253
- onError: (error: any) => {
254
- console.error("NuveiWebSDK Error:", error);
255
- },
256
-
257
- config: {
258
- environment: "dev2",
259
- },
263
+ componentName: ModulesNameEnum.DOC_UTILITY,
260
264
  });
261
265
  ```
262
266
 
263
- > **Note:** Verify the exact `ModulesNameEnum` value for Document Utility in the installed SDK version before using it. The original implementation should not be changed here unless that enum is confirmed.
267
+ The authentication/session request should include the module required by the Document Utility flow.
264
268
 
265
269
  ---
266
270
 
271
+
272
+
267
273
  # 6. Session Lifecycle Callbacks
268
274
 
269
275
  For applications that need full session lifecycle management, the SDK can receive:
270
276
 
271
- - `fetchClientSession`
272
- - `refreshClientSession`
273
- - `destroySession`
274
-
277
+ 1.`fetchClientSession`
278
+ Creates or retrieves the each session required by the SDK to communicate with the Nuvei backend.
275
279
  ```tsx
276
280
  const fetchClientSession = async () => {
277
- const response = await fetch(`${apiBaseUrl}/api/nuvei/auth/session`, {
281
+ const response = await fetch(`${apiBaseUrl}/api/auth/session`, {
278
282
  method: "POST",
279
283
  });
280
284
 
@@ -286,9 +290,11 @@ const fetchClientSession = async () => {
286
290
  };
287
291
  ```
288
292
 
293
+ 2.`refreshClientSession`
294
+ Refreshes the current session using the refresh token. The SDK can use this callback when the existing session is expired or approaching expiration
289
295
  ```tsx
290
296
  const refreshClientSession = async (refreshToken: string) => {
291
- const response = await fetch(`${apiBaseUrl}/api/nuvei/auth/session/refresh`, {
297
+ const response = await fetch(`${apiBaseUrl}/api/auth/session/refresh`, {
292
298
  method: "POST",
293
299
 
294
300
  headers: {
@@ -308,9 +314,11 @@ const refreshClientSession = async (refreshToken: string) => {
308
314
  };
309
315
  ```
310
316
 
317
+ 3.`destroySession`
318
+ Terminates the current session on the backend. This is typically used when the user logs out or when the SDK session needs to be explicitly invalidated.
311
319
  ```tsx
312
320
  const destroySession = async () => {
313
- const response = await fetch(`${apiBaseUrl}/api/nuvei/auth/session/destroy`, {
321
+ const response = await fetch(`${apiBaseUrl}/api/auth/session/destroy`, {
314
322
  method: "POST",
315
323
  });
316
324
 
@@ -324,136 +332,23 @@ const destroySession = async () => {
324
332
 
325
333
  ---
326
334
 
327
- # 7. Mount With Full Session Lifecycle
328
-
329
- When all callbacks are available, pass them to `NuveiSDK.mount()`:
330
-
331
- ```tsx
332
- NuveiSDK.mount({
333
- container: containerRef.current.id,
334
-
335
- componentName: ModulesNameEnum.ONBOARDING_MERCHANT,
336
-
337
- fetchClientSession,
338
- refreshClientSession,
339
- destroySession,
340
-
341
- onError: (error: any) => {
342
- console.error("NuveiWebSDK Error:", error);
343
- },
344
-
345
- config: {
346
- environment: "dev2",
347
- },
348
- }).catch((error: any) => {
349
- console.error("NuveiWebSDK Mount Error:", error);
350
- });
351
- ```
352
-
353
- ---
354
-
355
- # 8. Backend Session Refresh
335
+ ## 13. Configuration References
356
336
 
357
- The frontend refresh callback should call your backend.
337
+ | Property | Type | Default | Description |
338
+ | ----------------------- | --------------------------- | ----------------------- | ---------------------------------------------------------- |
339
+ | **`moduleName`** | `ModulesNameEnum \| string` | `ONBOARDING_MERCHANT` | Nuvei module to render |
340
+ | **`requestId`** | `string` | `undefined` | Onboarding application/request ID |
341
+ | **`documentRequestId`** | `string` | `undefined` | Document Utility request ID |
342
+ | **`environment`** | `string` | — | Target environment |
343
+ | **`apiBaseUrl`** | `string` | `http://localhost:3005` | Base URL for your backend API
344
+ | **`nuveiBackendUrl`** | `string` | `https://nuvei_backend_url/dev2/v1/auth/micro-frontend/tokens` | Base URL for the Nuvei backend API |
345
+ | **`isGuest`** | `boolean` | `false` | Indicates whether the current user is a guest |
346
+ | **`emailAddress`** | `string` | `undefined` | Email address used to identify the current user |
347
+ | **`partnerId`** | `string` | `undefined` | Partner ID used when accessing the Partner onboarding flow |
348
+ | **`onCompleted`** | `(data) => void` | `undefined` | Callback invoked when the flow is completed |
349
+ | **`onError`** | `(error) => void` | `undefined` | Callback invoked when an error occurs |
350
+ | **`style`** | `React.CSSProperties` | `undefined` | Optional container styling |
358
351
 
359
- Example:
360
-
361
- ```ts
362
- app.post("/api/nuvei/auth/refresh", async (req: Request, res: Response) => {
363
- try {
364
- const { refreshToken } = req.body as {
365
- refreshToken?: string;
366
- };
367
-
368
- if (!refreshToken) {
369
- return res.status(400).json({
370
- isSuccess: false,
371
- message: "refreshToken is required",
372
- });
373
- }
374
-
375
- console.log("Refreshing Nuvei session...");
376
-
377
- // Replace this URL with your actual
378
- // Nuvei refresh-token endpoint.
379
- const refreshUrl = "YOUR_NUVEI_REFRESH_ENDPOINT";
380
-
381
- const response = await fetch(refreshUrl, {
382
- method: "POST",
383
-
384
- headers: {
385
- "Content-Type": "application/json",
386
- Authorization: NUVEI_AUTHORIZATION,
387
- },
388
-
389
- body: JSON.stringify({
390
- refreshToken,
391
- }),
392
- });
393
-
394
- const data: unknown = await response.json();
395
-
396
- if (!response.ok) {
397
- console.error("Nuvei refresh failed:", data);
398
-
399
- return res.status(response.status).json(data);
400
- }
401
-
402
- console.log("Nuvei session refreshed");
403
-
404
- return res.json(data);
405
- } catch (error) {
406
- console.error("Session refresh error:", error);
407
-
408
- return res.status(500).json({
409
- isSuccess: false,
410
- message: "Internal server error while refreshing session",
411
- });
412
- }
413
- });
414
- ```
415
-
416
- ---
417
-
418
- # 9. Backend Logout / Destroy Session
419
-
420
- ```ts
421
- app.post("/api/nuvei/auth/logout", async (_req: Request, res: Response) => {
422
- try {
423
- console.log("Destroying Nuvei session...");
424
-
425
- return res.json({
426
- isSuccess: true,
427
- });
428
- } catch (error) {
429
- console.error("Logout error:", error);
430
-
431
- return res.status(500).json({
432
- isSuccess: false,
433
- message: "Failed to destroy session",
434
- });
435
- }
436
- });
437
- ```
438
-
439
- > The exact Nuvei destroy/logout behavior should follow the session API supported by the environment you are integrating with.
440
-
441
- ---
442
-
443
- # 13. Configuration Reference
444
-
445
- | Property | Type | Default | Description |
446
- | ------------------- | --------------------------- | ----------------------- | --------------------------------- |
447
- | `componentName` | `ModulesNameEnum \| string` | `ONBOARDING_MERCHANT` | Nuvei module to render |
448
- | `requestId` | `string` | `undefined` | Onboarding application ID |
449
- | `documentRequestId` | `string` | `undefined` | Document Utility request ID |
450
- | `environment` | `string` | — | Target environment |
451
- | `backendApiUrl` | `string` | `http://localhost:3005` | Backend API base URL |
452
- | `onCompleted` | `(data) => void` | `undefined` | Called when the flow is completed |
453
- | `onError` | `(error) => void` | `undefined` | Called when an error occurs |
454
- | `style` | `React.CSSProperties` | `undefined` | Optional container styling |
455
-
456
- ---
457
352
 
458
353
  # 15. Production Checklist
459
354
 
@@ -472,7 +367,7 @@ Before deploying the integration, verify:
472
367
 
473
368
  - [ ] Nuvei authorization is stored securely.
474
369
  - [ ] Nuvei credentials are never exposed to the browser.
475
- - [ ] `/api/nuvei/auth/session` is implemented.
370
+ - [ ] `/api/auth/session` is implemented.
476
371
  - [ ] Refresh endpoint is implemented when required.
477
372
  - [ ] Destroy/logout endpoint is implemented when required.
478
373
  - [ ] `emailAddress`, `partnerId`, and `isGuest` are populated from the appropriate application context.
@@ -512,7 +407,7 @@ and confirm that the container exists:
512
407
  Check the browser network request:
513
408
 
514
409
  ```text
515
- POST /api/nuvei/auth/session
410
+ POST /api/auth/session
516
411
  ```
517
412
 
518
413
  Then verify:
@@ -555,7 +450,7 @@ If you only need the simplest integration, the essential flow is:
555
450
 
556
451
  ```tsx
557
452
  const fetchClientSession = async () => {
558
- const response = await fetch(`${backendApiUrl}/api/nuvei/auth/session`, {
453
+ const response = await fetch(`${backendApiUrl}/api/auth/session`, {
559
454
  method: "POST",
560
455
  });
561
456
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuvei-connect/nc-websdk",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",