@vergelijkdirect/insurance-transmission-client 1.3.61 → 1.3.62

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
@@ -24,6 +24,10 @@ const config = {
24
24
  api: {
25
25
  baseUrl: 'https://api.vergelijkdirect.com/api',
26
26
  version: 'v2.1',
27
+ credentials: {
28
+ accessKey: 'your-partner-access-key',
29
+ secret: 'your-partner-secret',
30
+ },
27
31
  },
28
32
  };
29
33
  ```
@@ -40,6 +44,53 @@ With the recommended configuration, moped rates are called through:
40
44
  https://api.vergelijkdirect.com/api/v2.1/comparisons/moped
41
45
  ```
42
46
 
47
+ Existing `v2` integrations can keep using the client without partner credentials:
48
+
49
+ ```ts
50
+ await client.configure({
51
+ api: {
52
+ baseUrl: 'https://api.vergelijkdirect.com/api',
53
+ version: 'v2',
54
+ },
55
+ });
56
+ ```
57
+
58
+ ## Partner Credentials
59
+
60
+ Partner credentials are optional on the client. Use them for Partner API v2.1 integrations; omit them for existing v2 integrations that do not require partner authentication.
61
+
62
+ Partner API v2.1 uses the same credentials as the Vergelijkdirect Partner API documentation. Configure them once on the client and every service request will include the partner credential headers automatically:
63
+
64
+ ```ts
65
+ await client.configure({
66
+ api: {
67
+ baseUrl: 'https://api.vergelijkdirect.com/api',
68
+ version: 'v2.1',
69
+ credentials: {
70
+ accessKey: 'your-partner-access-key',
71
+ secret: 'your-partner-secret',
72
+ },
73
+ },
74
+ });
75
+ ```
76
+
77
+ By default the client sends:
78
+
79
+ ```text
80
+ X-Partner-Access-Key: your-partner-access-key
81
+ X-Partner-Secret: your-partner-secret
82
+ ```
83
+
84
+ If an integration needs HTTP Basic authentication instead, set `authType` to `basic`. Use `both` only when a gateway or migration flow requires both authentication formats.
85
+
86
+ ```ts
87
+ credentials: {
88
+ accessKey: 'your-partner-access-key',
89
+ secret: 'your-partner-secret',
90
+ authType: 'basic', // headers, basic, or both
91
+ }
92
+ ```
93
+
43
94
  Some helper resources still use fixed API paths in the client, for example `/v2/data`, `/v2/package`, `/v2/user`, `/v2/comparison`, `/v1` validation and legacy endpoints, `/partner`, and `/scripts/comparison-module`. If those backend endpoints are migrated to `v2.1`, update the related resource base URL before sharing a new client build.
44
95
 
45
96
  ## Installation
@@ -70,6 +121,10 @@ await client.configure({
70
121
  api: {
71
122
  baseUrl: 'https://api.vergelijkdirect.com/api',
72
123
  version: 'v2.1',
124
+ credentials: {
125
+ accessKey: 'your-partner-access-key',
126
+ secret: 'your-partner-secret',
127
+ },
73
128
  },
74
129
  });
75
130
 
@@ -120,6 +175,10 @@ await client.configure({
120
175
  api: {
121
176
  baseUrl: 'https://api.vergelijkdirect.com/api',
122
177
  version: 'v2.1',
178
+ credentials: {
179
+ accessKey: 'your-partner-access-key',
180
+ secret: 'your-partner-secret',
181
+ },
123
182
  },
124
183
  });
125
184
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vergelijkdirect/insurance-transmission-client",
3
- "version": "1.3.61",
3
+ "version": "1.3.62",
4
4
  "description": "",
5
5
  "main": "./src/js/index.js",
6
6
  "scripts": {
@@ -1,5 +1,6 @@
1
1
  import { Invokable } from "invokable";
2
2
  import 'isomorphic-fetch';
3
+ import { EnvironmentInterface } from "../interfaces";
3
4
  declare class HttpClient {
4
5
  interceptors: {
5
6
  request: InterceptorManager;
@@ -7,17 +8,18 @@ declare class HttpClient {
7
8
  };
8
9
  private readonly cache?;
9
10
  private readonly credentials?;
10
- private readonly headers?;
11
11
  private readonly keepalive?;
12
12
  private readonly mode?;
13
13
  private readonly redirect?;
14
14
  private readonly referrerPolicy?;
15
15
  private readonly baseUrl?;
16
+ private readonly environment?;
16
17
  private transformer;
17
- constructor(baseUrl: string);
18
+ constructor(baseUrl: string, environment?: EnvironmentInterface);
18
19
  setFetchRequestTransformer(transformer: (config: any) => RequestInit): void;
19
20
  private defaultTransformer;
20
21
  private getDefaultConfigurations;
22
+ private getDefaultHeaders;
21
23
  private getRequest;
22
24
  private buildUrl;
23
25
  private removeTrailingSlashes;
@@ -50,22 +50,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
50
50
  var invokable_1 = require("invokable");
51
51
  require("isomorphic-fetch");
52
52
  var HttpClient = /** @class */ (function () {
53
- function HttpClient(baseUrl) {
53
+ function HttpClient(baseUrl, environment) {
54
54
  this.interceptors = {
55
55
  request: new InterceptorManager,
56
56
  response: new InterceptorManager
57
57
  };
58
58
  this.cache = 'default';
59
59
  this.credentials = 'omit';
60
- this.headers = {
61
- 'Content-Type': 'application/json',
62
- 'ITC': 'true',
63
- };
64
60
  this.keepalive = false; // when true it have limit 65536 bytes
65
61
  this.mode = 'cors';
66
62
  this.redirect = 'follow';
67
63
  this.referrerPolicy = 'no-referrer-when-downgrade';
68
64
  this.baseUrl = baseUrl;
65
+ this.environment = environment;
69
66
  this.transformer = this.defaultTransformer;
70
67
  }
71
68
  HttpClient.prototype.setFetchRequestTransformer = function (transformer) {
@@ -81,13 +78,33 @@ var HttpClient = /** @class */ (function () {
81
78
  return {
82
79
  cache: this.cache,
83
80
  credentials: this.credentials,
84
- headers: this.headers,
81
+ headers: this.getDefaultHeaders(),
85
82
  keepalive: this.keepalive,
86
83
  mode: this.mode,
87
84
  redirect: this.redirect,
88
85
  referrerPolicy: this.referrerPolicy
89
86
  };
90
87
  };
88
+ HttpClient.prototype.getDefaultHeaders = function () {
89
+ var _a, _b;
90
+ var headers = {
91
+ 'Content-Type': 'application/json',
92
+ 'ITC': 'true',
93
+ };
94
+ var credentials = (_a = this.environment) === null || _a === void 0 ? void 0 : _a.api.credentials;
95
+ if (!credentials) {
96
+ return headers;
97
+ }
98
+ var authType = (_b = credentials.authType) !== null && _b !== void 0 ? _b : 'headers';
99
+ if (authType === 'headers' || authType === 'both') {
100
+ headers['X-Partner-Access-Key'] = credentials.accessKey;
101
+ headers['X-Partner-Secret'] = credentials.secret;
102
+ }
103
+ if (authType === 'basic' || authType === 'both') {
104
+ headers['Authorization'] = "Basic ".concat(btoa("".concat(credentials.accessKey, ":").concat(credentials.secret)));
105
+ }
106
+ return headers;
107
+ };
91
108
  HttpClient.prototype.getRequest = function (config) {
92
109
  var defaultConfigurations = this.getDefaultConfigurations();
93
110
  var request = this.transformer(config);
@@ -1,7 +1,14 @@
1
+ type PartnerCredentialsAuthType = 'headers' | 'basic' | 'both';
2
+ interface PartnerCredentialsInterface {
3
+ accessKey: string;
4
+ secret: string;
5
+ authType?: PartnerCredentialsAuthType;
6
+ }
1
7
  interface EnvironmentInterface {
2
8
  api: {
3
9
  baseUrl: string;
4
10
  version: string;
11
+ credentials?: PartnerCredentialsInterface;
5
12
  };
6
13
  }
7
14
  export default EnvironmentInterface;
@@ -5,7 +5,7 @@ var invokable_1 = require("invokable");
5
5
  var BaseResource = /** @class */ (function () {
6
6
  function BaseResource() {
7
7
  var env = core_1.Injector.instance.get('environment');
8
- this.http = invokable_1.Invokable.create(new core_1.HttpClient(this.getBaseUrl(env)));
8
+ this.http = invokable_1.Invokable.create(new core_1.HttpClient(this.getBaseUrl(env), env));
9
9
  }
10
10
  return BaseResource;
11
11
  }());