@finteqhub/sdk-js 0.12.0-beta.2 → 0.12.0-beta.4

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,36 +1,30 @@
1
1
  # processing-sdk
2
2
 
3
- Use `new FinteqHubProcessing(options: ProcessingOptions)` to create an instance of the FinteqHubProcessing object. The FinteqHubProcessing object is your entrypoint to FinteqHub processing SDK.
3
+ Use `new FinteqHubProcessing(apiUrl: string, fingerprintVisitorId: string, merchantId: 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
- interface ProcessingOptions {
7
- apiUrl: string;
8
- fingerprintVisitorId: string;
9
- merchantId: string;
10
- sessionId: string;
11
- isSecure?: boolean; // default false
12
- retryOptions?: RetryOptions;
13
- }
14
-
15
- const processing = new FinteqHubProcessing({
16
- apiUrl: 'api-url',
17
- fingerprintVisitorId: 'fingerprint-visitor-id',
18
- merchantId: 'merchant-id',
19
- sessionId: 'session-id',
20
- });
6
+ const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', 'merchant-id', 'session-id');
21
7
  ```
22
8
 
9
+ The constructor validates its arguments and throws a `TypeError` when `apiUrl`, `fingerprintVisitorId`, `merchantId` 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
+
23
11
  ## Retries and error diagnostics
24
12
 
25
- 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 `retryOptions` constructor option:
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 sixth one, after `isSecure`):
26
14
 
27
15
  ```
28
16
  interface RetryOptions {
29
17
  retryCount?: number; // number of retries after the initial attempt, default 5; 0 disables retries
30
18
  retryStatusCode?: (statusCode: number) => boolean; // default: statusCode < 200 || statusCode === 408 || statusCode >= 500
31
19
  }
20
+
21
+ const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', 'merchant-id', 'session-id', false, {
22
+ retryCount: 3,
23
+ });
32
24
  ```
33
25
 
26
+ The constructor throws a `TypeError` when `retryOptions` is not an object, `retryCount` is not a non-negative integer, or `retryStatusCode` is not a function.
27
+
34
28
  Network errors (the browser could not reach the server at all, e.g. `TypeError: Failed to fetch`, or the connection dropped while the response body was being read) are always retried too.
35
29
 
36
30
  Every retry attempt is reported with `console.warn`. When a request finally fails, the SDK logs `console.error` (`sdk-js: request failed: <message>`) with a full diagnostic dump and rejects with a `RequestError` whose `diagnostics` field carries the same payload — include it in your error reporting. `diagnostics.kind` tells the failure class apart:
@@ -94,7 +88,7 @@ import FingerprintJS from "@fingerprintjs/fingerprintjs";
94
88
  const fp = await FingerprintJS.load();
95
89
  const result = await fp.get();
96
90
 
97
- const processing = new FinteqHubProcessing({ apiUrl, fingerprintVisitorId: result.visitorId, merchantId, sessionId });
91
+ const processing = new FinteqHubProcessing(apiUrl, result.visitorId, merchantId, sessionId);
98
92
  const session = await processing.getSession();
99
93
 
100
94
  const data = {/** collect data from form and session **/}
@@ -3,14 +3,6 @@ export interface RetryOptions {
3
3
  retryCount?: number;
4
4
  retryStatusCode?: (statusCode: number) => boolean;
5
5
  }
6
- export interface ProcessingOptions {
7
- apiUrl: string;
8
- fingerprintVisitorId: string;
9
- merchantId: string;
10
- sessionId: string;
11
- isSecure?: boolean;
12
- retryOptions?: RetryOptions;
13
- }
14
6
  export declare type RequestAttempt = {
15
7
  durationMs: number;
16
8
  status?: number;
@@ -60,7 +52,7 @@ export declare class FinteqHubProcessing {
60
52
  private projectId;
61
53
  private isSecure;
62
54
  private retryOptions;
63
- constructor(options: ProcessingOptions);
55
+ constructor(apiUrl: string, fingerprintVisitorId: string, merchantId: string, sessionId: string, isSecure?: boolean, retryOptions?: RetryOptions);
64
56
  getSession(): Promise<SessionResponse>;
65
57
  submitForm(data: SubmitData): Promise<ProcessOperationRedirectResponse>;
66
58
  private processOperation;
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { getDeviceData, uuid, validateOptions } from "./utils";
10
+ import { getDeviceData, uuid, validateArguments } from "./utils";
11
11
  import { SDK_HEADER_NAME, SDK_HEADER_VALUE, SDK_VERSION } from "./version";
12
12
  export class RequestError extends Error {
13
13
  constructor(message, diagnostics) {
@@ -25,15 +25,14 @@ 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(options) {
29
- var _a, _b;
30
- validateOptions(options);
31
- this.apiUrl = options.apiUrl;
32
- this.fingerprintVisitorId = options.fingerprintVisitorId;
33
- this.merchantId = options.merchantId;
34
- this.sessionId = options.sessionId;
35
- this.isSecure = (_a = options.isSecure) !== null && _a !== void 0 ? _a : false;
36
- this.retryOptions = (_b = options.retryOptions) !== null && _b !== void 0 ? _b : {};
28
+ constructor(apiUrl, fingerprintVisitorId, merchantId, sessionId, isSecure = false, retryOptions = {}) {
29
+ validateArguments({ apiUrl, fingerprintVisitorId, merchantId, sessionId, isSecure, retryOptions });
30
+ this.apiUrl = apiUrl;
31
+ this.fingerprintVisitorId = fingerprintVisitorId;
32
+ this.merchantId = merchantId;
33
+ this.sessionId = sessionId;
34
+ this.isSecure = isSecure;
35
+ this.retryOptions = retryOptions;
37
36
  }
38
37
  getSession() {
39
38
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
@@ -1,4 +1,4 @@
1
- import type { ProcessingOptions } from "./processing";
1
+ import type { RetryOptions } from "./processing";
2
2
  export declare const DeviceType: {
3
3
  Unknown: string;
4
4
  Computer: string;
@@ -10,7 +10,15 @@ export declare const DeviceType: {
10
10
  };
11
11
  export declare function uuid(): string;
12
12
  export declare function getDeviceType(): string;
13
- export declare function validateOptions(options: ProcessingOptions): void;
13
+ declare type ConstructorArguments = {
14
+ apiUrl: string;
15
+ fingerprintVisitorId: string;
16
+ merchantId: string;
17
+ sessionId: string;
18
+ isSecure: boolean;
19
+ retryOptions: RetryOptions;
20
+ };
21
+ export declare function validateArguments(args: ConstructorArguments): void;
14
22
  export declare function getDeviceData(): {
15
23
  device: {
16
24
  type: string;
@@ -33,3 +41,4 @@ export declare function getDeviceData(): {
33
41
  };
34
42
  };
35
43
  };
44
+ export {};
package/dist/src/utils.js CHANGED
@@ -40,30 +40,26 @@ export function getDeviceType() {
40
40
  }
41
41
  return DeviceType.Unknown;
42
42
  }
43
- const REQUIRED_OPTIONS = ["apiUrl", "fingerprintVisitorId", "merchantId", "sessionId"];
44
- export function validateOptions(options) {
45
- if (typeof options !== "object" || options === null) {
46
- throw new TypeError("sdk-js: constructor expects an options object: { apiUrl, fingerprintVisitorId, merchantId, sessionId, isSecure?, retryOptions? }");
47
- }
48
- for (const key of REQUIRED_OPTIONS) {
49
- if (typeof options[key] !== "string" || options[key] === "") {
50
- throw new TypeError(`sdk-js: option "${key}" must be a non-empty string`);
43
+ const REQUIRED_STRINGS = ["apiUrl", "fingerprintVisitorId", "merchantId", "sessionId"];
44
+ export function validateArguments(args) {
45
+ for (const key of REQUIRED_STRINGS) {
46
+ if (typeof args[key] !== "string" || args[key] === "") {
47
+ throw new TypeError(`sdk-js: ${key} must be a non-empty string`);
51
48
  }
52
49
  }
53
- if (options.isSecure !== undefined && typeof options.isSecure !== "boolean") {
54
- throw new TypeError('sdk-js: option "isSecure" must be a boolean');
50
+ if (typeof args.isSecure !== "boolean") {
51
+ throw new TypeError("sdk-js: isSecure must be a boolean");
55
52
  }
56
- if (options.retryOptions !== undefined) {
57
- if (typeof options.retryOptions !== "object" || options.retryOptions === null) {
58
- throw new TypeError('sdk-js: option "retryOptions" must be an object');
59
- }
60
- const { retryCount, retryStatusCode } = options.retryOptions;
61
- if (retryCount !== undefined && (!Number.isInteger(retryCount) || retryCount < 0)) {
62
- throw new TypeError('sdk-js: option "retryOptions.retryCount" must be a non-negative integer');
63
- }
64
- if (retryStatusCode !== undefined && typeof retryStatusCode !== "function") {
65
- throw new TypeError('sdk-js: option "retryOptions.retryStatusCode" must be a function');
66
- }
53
+ const { retryOptions } = args;
54
+ if (typeof retryOptions !== "object" || retryOptions === null) {
55
+ throw new TypeError("sdk-js: retryOptions must be an object");
56
+ }
57
+ const { retryCount, retryStatusCode } = retryOptions;
58
+ if (retryCount !== undefined && (!Number.isInteger(retryCount) || retryCount < 0)) {
59
+ throw new TypeError("sdk-js: retryOptions.retryCount must be a non-negative integer");
60
+ }
61
+ if (retryStatusCode !== undefined && typeof retryStatusCode !== "function") {
62
+ throw new TypeError("sdk-js: retryOptions.retryStatusCode must be a function");
67
63
  }
68
64
  }
69
65
  export function getDeviceData() {
@@ -1,3 +1,3 @@
1
1
  export declare const SDK_HEADER_NAME = "X-Finteqhub-SDK";
2
- export declare const SDK_VERSION = "0.12.0-beta.2";
2
+ export declare const SDK_VERSION = "0.12.0-beta.4";
3
3
  export declare const SDK_HEADER_VALUE: string;
@@ -1,3 +1,3 @@
1
1
  export const SDK_HEADER_NAME = "X-Finteqhub-SDK";
2
- export const SDK_VERSION = "0.12.0-beta.2";
2
+ export const SDK_VERSION = "0.12.0-beta.4";
3
3
  export const SDK_HEADER_VALUE = `sdk-js/${SDK_VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finteqhub/sdk-js",
3
- "version": "0.12.0-beta.2",
3
+ "version": "0.12.0-beta.4",
4
4
  "description": "SDK for interacting with FinteqHub processing API",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",