@finteqhub/sdk-js 0.15.0 → 0.16.0-beta.2
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/CHANGELOG.md +11 -0
- package/README.md +29 -9
- package/dist/src/processing.d.ts +1 -2
- package/dist/src/processing.js +2 -6
- package/dist/src/utils.d.ts +0 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Notable changes to `@finteqhub/sdk-js`. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
4
4
|
|
|
5
|
+
## 0.16.0
|
|
6
|
+
|
|
7
|
+
### Breaking changes
|
|
8
|
+
|
|
9
|
+
- The SDK no longer sends the `x-merchant-id` header (previously on every request) or the `x-project-id` header (previously on `submit-form` and `operations` requests, taken from the session response). This release requires a backend that no longer expects these headers; against older backends `submit-form` and `sessions` requests are rejected with 400.
|
|
10
|
+
- The `merchantId` constructor argument was removed together with the header. The constructor is now `new FinteqHubProcessing(apiUrl, fingerprintVisitorId, sessionId, isSecure?, retryOptions?)` — every argument after `fingerprintVisitorId` shifts one position to the left. Callers must drop the third argument; a call site that still passes it fails argument validation (`isSecure` receives the session id, which is not a boolean, and the constructor throws a `TypeError`).
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- README: `getSession` is documented as optional and the Usage section shows a submit-only flow next to the render-from-session one. `submitForm` never depended on the session response apart from `projectId`, which is no longer sent.
|
|
15
|
+
|
|
5
16
|
## 0.15.0
|
|
6
17
|
|
|
7
18
|
### Added
|
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# processing-sdk
|
|
2
2
|
|
|
3
|
-
Use `new FinteqHubProcessing(apiUrl: string, fingerprintVisitorId: string,
|
|
3
|
+
Use `new FinteqHubProcessing(apiUrl: string, fingerprintVisitorId: string, sessionId: string, isSecure?: boolean, retryOptions?: RetryOptions)` to create an instance of the FinteqHubProcessing object. The FinteqHubProcessing object is your entrypoint to FinteqHub processing SDK.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
|
-
const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', '
|
|
6
|
+
const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', 'session-id');
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
The constructor validates its arguments and throws a `TypeError` when `apiUrl`, `fingerprintVisitorId
|
|
9
|
+
The constructor validates its arguments and throws a `TypeError` when `apiUrl`, `fingerprintVisitorId` or `sessionId` is missing, empty or not a string, when `isSecure` is not a boolean, or when `retryOptions` is malformed (see [Retries and error diagnostics](#retries-and-error-diagnostics)).
|
|
10
10
|
|
|
11
11
|
## Retries and error diagnostics
|
|
12
12
|
|
|
13
|
-
Failed HTTP requests are retried automatically with exponential backoff (`100ms → 200ms → 500ms → 1000ms → 2000ms`; every retry after the fifth waits 2000ms). Retries can be configured via the optional `retryOptions` constructor argument (the
|
|
13
|
+
Failed HTTP requests are retried automatically with exponential backoff (`100ms → 200ms → 500ms → 1000ms → 2000ms`; every retry after the fifth waits 2000ms). Retries can be configured via the optional `retryOptions` constructor argument (the fifth one, after `isSecure`):
|
|
14
14
|
|
|
15
15
|
```
|
|
16
16
|
interface RetryOptions {
|
|
@@ -18,7 +18,7 @@ interface RetryOptions {
|
|
|
18
18
|
retryStatusCode?: (statusCode: number) => boolean; // default: statusCode < 200 || statusCode === 408 || statusCode >= 500
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', '
|
|
21
|
+
const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', 'session-id', false, {
|
|
22
22
|
retryCount: 3,
|
|
23
23
|
});
|
|
24
24
|
```
|
|
@@ -26,7 +26,7 @@ const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id',
|
|
|
26
26
|
To disable retries entirely, pass `retryCount: 0` — every request is then sent exactly once, as in 0.11.0. Error diagnostics (`RequestError`, the `console.error` dump) are still collected:
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', '
|
|
29
|
+
const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', 'session-id', false, {
|
|
30
30
|
retryCount: 0,
|
|
31
31
|
});
|
|
32
32
|
```
|
|
@@ -67,7 +67,7 @@ The header is added automatically to every request and cannot be disabled.
|
|
|
67
67
|
|
|
68
68
|
### processing.getSession()
|
|
69
69
|
|
|
70
|
-
Use `processing.getSession` to get session information.
|
|
70
|
+
Use `processing.getSession` to get session information (payment methods, credential fields, operation amount and currency, init credentials) for rendering the form. It is optional: `submitForm` does not depend on it and can be called right after constructing the instance.
|
|
71
71
|
|
|
72
72
|
```
|
|
73
73
|
processing
|
|
@@ -89,6 +89,10 @@ processing
|
|
|
89
89
|
|
|
90
90
|
## Usage
|
|
91
91
|
|
|
92
|
+
### Submit only
|
|
93
|
+
|
|
94
|
+
The minimal flow is to construct the instance and call `submitForm` — no other request is needed before it. Use it when your own UI already knows what to collect from the customer (for example, the payment method and its credential fields are fixed on your side):
|
|
95
|
+
|
|
92
96
|
```
|
|
93
97
|
import { FinteqHubProcessing } from "@finteqhub/sdk-js";
|
|
94
98
|
import FingerprintJS from "@fingerprintjs/fingerprintjs";
|
|
@@ -96,10 +100,26 @@ import FingerprintJS from "@fingerprintjs/fingerprintjs";
|
|
|
96
100
|
const fp = await FingerprintJS.load();
|
|
97
101
|
const result = await fp.get();
|
|
98
102
|
|
|
99
|
-
const processing = new FinteqHubProcessing(apiUrl, result.visitorId,
|
|
103
|
+
const processing = new FinteqHubProcessing(apiUrl, result.visitorId, sessionId);
|
|
104
|
+
|
|
105
|
+
const data = {/** collect data from form **/}
|
|
106
|
+
|
|
107
|
+
processing
|
|
108
|
+
.submitForm(data)
|
|
109
|
+
.then(result => console.log(result))
|
|
110
|
+
.catch(error => console.warn(error));
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Render the form from session data
|
|
114
|
+
|
|
115
|
+
Call `getSession` first when the form itself is built from the session: available payment methods, their credential fields, the operation amount and currency. `submitForm` does not use the result — it only drives your UI:
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
const processing = new FinteqHubProcessing(apiUrl, result.visitorId, sessionId);
|
|
119
|
+
|
|
100
120
|
const session = await processing.getSession();
|
|
101
121
|
|
|
102
|
-
const data = {/** collect data from form
|
|
122
|
+
const data = {/** collect data from form rendered from session **/}
|
|
103
123
|
|
|
104
124
|
processing
|
|
105
125
|
.submitForm(data)
|
package/dist/src/processing.d.ts
CHANGED
|
@@ -47,12 +47,11 @@ export declare class RequestError extends Error {
|
|
|
47
47
|
export declare class FinteqHubProcessing {
|
|
48
48
|
private apiUrl;
|
|
49
49
|
private fingerprintVisitorId;
|
|
50
|
-
private merchantId;
|
|
51
50
|
private sessionId;
|
|
52
51
|
private projectId;
|
|
53
52
|
private isSecure;
|
|
54
53
|
private retryOptions;
|
|
55
|
-
constructor(apiUrl: string, fingerprintVisitorId: string,
|
|
54
|
+
constructor(apiUrl: string, fingerprintVisitorId: string, sessionId: string, isSecure?: boolean, retryOptions?: RetryOptions);
|
|
56
55
|
getSession(): Promise<SessionResponse>;
|
|
57
56
|
submitForm(data: SubmitData): Promise<ProcessOperationRedirectResponse>;
|
|
58
57
|
private processOperation;
|
package/dist/src/processing.js
CHANGED
|
@@ -25,11 +25,10 @@ const sanitizeBody = (body) => body.slice(0, MAX_BODY_SNIPPET_LENGTH).replace(/\
|
|
|
25
25
|
// failures and for duplicate-submit rejections — retrying either only delays the error
|
|
26
26
|
const defaultRetryStatusCode = (statusCode) => statusCode < 200 || statusCode === 408 || statusCode >= 500;
|
|
27
27
|
export class FinteqHubProcessing {
|
|
28
|
-
constructor(apiUrl, fingerprintVisitorId,
|
|
29
|
-
validateArguments({ apiUrl, fingerprintVisitorId,
|
|
28
|
+
constructor(apiUrl, fingerprintVisitorId, sessionId, isSecure = false, retryOptions = {}) {
|
|
29
|
+
validateArguments({ apiUrl, fingerprintVisitorId, sessionId, isSecure, retryOptions });
|
|
30
30
|
this.apiUrl = apiUrl;
|
|
31
31
|
this.fingerprintVisitorId = fingerprintVisitorId;
|
|
32
|
-
this.merchantId = merchantId;
|
|
33
32
|
this.sessionId = sessionId;
|
|
34
33
|
this.isSecure = isSecure;
|
|
35
34
|
this.retryOptions = retryOptions;
|
|
@@ -43,7 +42,6 @@ export class FinteqHubProcessing {
|
|
|
43
42
|
method: "GET",
|
|
44
43
|
headers: {
|
|
45
44
|
"Content-Type": "application/json;charset=UTF-8",
|
|
46
|
-
"x-merchant-id": this.merchantId,
|
|
47
45
|
"x-request-id": uuid(),
|
|
48
46
|
[SDK_HEADER_NAME]: SDK_HEADER_VALUE,
|
|
49
47
|
},
|
|
@@ -108,11 +106,9 @@ export class FinteqHubProcessing {
|
|
|
108
106
|
method: "POST",
|
|
109
107
|
headers: {
|
|
110
108
|
"Content-Type": "application/json;charset=UTF-8",
|
|
111
|
-
"x-merchant-id": this.merchantId,
|
|
112
109
|
"x-request-id": uuid(),
|
|
113
110
|
"x-fingerprint": this.fingerprintVisitorId,
|
|
114
111
|
"x-session-id": this.sessionId,
|
|
115
|
-
"x-project-id": this.projectId,
|
|
116
112
|
[SDK_HEADER_NAME]: SDK_HEADER_VALUE,
|
|
117
113
|
},
|
|
118
114
|
body: JSON.stringify(data),
|
package/dist/src/utils.d.ts
CHANGED
package/dist/src/utils.js
CHANGED
|
@@ -49,7 +49,7 @@ export function getDeviceType() {
|
|
|
49
49
|
}
|
|
50
50
|
return DeviceType.Unknown;
|
|
51
51
|
}
|
|
52
|
-
const REQUIRED_STRINGS = ["apiUrl", "fingerprintVisitorId", "
|
|
52
|
+
const REQUIRED_STRINGS = ["apiUrl", "fingerprintVisitorId", "sessionId"];
|
|
53
53
|
export function validateArguments(args) {
|
|
54
54
|
for (const key of REQUIRED_STRINGS) {
|
|
55
55
|
if (typeof args[key] !== "string" || args[key] === "") {
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED