@boltpay/tokenizer 2.0.56420 → 2.0.56503
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/build/bolt/tk/client/api.d.ts +1 -1
- package/build/bolt/tk/client/api.js +9 -5
- package/build/bolt/tk/client/client.d.ts +7 -7
- package/build/bolt/tk/client/client.js +24 -19
- package/build/bolt/tk/client/client.test.js +38 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/esm/bolt/tk/client/api.d.ts +1 -1
- package/esm/bolt/tk/client/api.js +9 -5
- package/esm/bolt/tk/client/client.d.ts +7 -7
- package/esm/bolt/tk/client/client.js +24 -19
- package/esm/bolt/tk/client/client.test.js +38 -2
- package/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -9,12 +9,16 @@ exports.tkBaseUrls = {
|
|
|
9
9
|
production: "https://production.bolttk.com",
|
|
10
10
|
test: "http://localhost",
|
|
11
11
|
};
|
|
12
|
+
// Ordered fallback hosts, tried after the primary tkBaseUrls host.
|
|
13
|
+
// bolt.com → boltapp.com zone migration (I307): during the cutover window both
|
|
14
|
+
// zones are served, so we prefer the new boltapp.com host and keep the legacy
|
|
15
|
+
// bolt.com host as a last-resort fallback. Once the window closes, drop bolt.com.
|
|
12
16
|
exports.tkBaseAlternativeUrls = {
|
|
13
|
-
dev: "http://localhost:3001",
|
|
14
|
-
staging: "https://tokenizer-staging.bolt.com",
|
|
15
|
-
sandbox: "https://tokenizer-sandbox.bolt.com",
|
|
16
|
-
production: "https://tokenizer.bolt.com",
|
|
17
|
-
test: "http://localhost",
|
|
17
|
+
dev: ["http://localhost:3001"],
|
|
18
|
+
staging: ["https://tokenizer-staging.boltapp.com", "https://tokenizer-staging.bolt.com"],
|
|
19
|
+
sandbox: ["https://tokenizer-sandbox.boltapp.com", "https://tokenizer-sandbox.bolt.com"],
|
|
20
|
+
production: ["https://tokenizer.boltapp.com", "https://tokenizer.bolt.com"],
|
|
21
|
+
test: ["http://localhost"],
|
|
18
22
|
};
|
|
19
23
|
exports.headerBoltForwardTo = "X-Bolt-Forward-To";
|
|
20
24
|
exports.headerBoltToken = "X-Bolt-Token";
|
|
@@ -4,19 +4,19 @@ export declare class TkClient implements ITkClient {
|
|
|
4
4
|
readonly env: TkEnvironment;
|
|
5
5
|
private readonly fetchFn;
|
|
6
6
|
private baseURL;
|
|
7
|
-
private
|
|
7
|
+
private fallbackBaseURLs;
|
|
8
8
|
private tokenURL;
|
|
9
|
-
private
|
|
9
|
+
private tokenFallbackURLs;
|
|
10
10
|
private cvvTokenURL;
|
|
11
|
-
private
|
|
11
|
+
private cvvTokenFallbackURLs;
|
|
12
12
|
private applePayTokenURL;
|
|
13
|
-
private
|
|
13
|
+
private applePayTokenFallbackURLs;
|
|
14
14
|
private googlePayTokenURL;
|
|
15
|
-
private
|
|
15
|
+
private googlePayTokenFallbackURLs;
|
|
16
16
|
private klarnaTokenURL;
|
|
17
|
-
private
|
|
17
|
+
private klarnaTokenFallbackURLs;
|
|
18
18
|
private publicKeyURL;
|
|
19
|
-
private
|
|
19
|
+
private publicKeyFallbackURLs;
|
|
20
20
|
private publicKey;
|
|
21
21
|
private keyPair;
|
|
22
22
|
constructor(env: TkEnvironment, fetchFn: FetchFn);
|
|
@@ -19,23 +19,23 @@ class TkClient {
|
|
|
19
19
|
this.env = env;
|
|
20
20
|
this.fetchFn = fetchFn;
|
|
21
21
|
this.baseURL = api_1.tkBaseUrls[this.env];
|
|
22
|
-
this.
|
|
22
|
+
this.fallbackBaseURLs = api_1.tkBaseAlternativeUrls[this.env];
|
|
23
23
|
this.tokenURL = `${this.baseURL}/token`;
|
|
24
|
-
this.
|
|
24
|
+
this.tokenFallbackURLs = this.fallbackBaseURLs.map(base => `${base}/token`);
|
|
25
25
|
this.cvvTokenURL = `${this.baseURL}/token/cvv`;
|
|
26
|
-
this.
|
|
26
|
+
this.cvvTokenFallbackURLs = this.fallbackBaseURLs.map(base => `${base}/token/cvv`);
|
|
27
27
|
this.applePayTokenURL = `${this.baseURL}/token/applepay`;
|
|
28
|
-
this.
|
|
28
|
+
this.applePayTokenFallbackURLs = this.fallbackBaseURLs.map(base => `${base}/token/applepay`);
|
|
29
29
|
this.googlePayTokenURL = `${this.baseURL}/token/googlepay`;
|
|
30
|
-
this.
|
|
30
|
+
this.googlePayTokenFallbackURLs = this.fallbackBaseURLs.map(base => `${base}/token/googlepay`);
|
|
31
31
|
this.klarnaTokenURL = `${this.baseURL}/token/klarna`;
|
|
32
|
-
this.
|
|
32
|
+
this.klarnaTokenFallbackURLs = this.fallbackBaseURLs.map(base => `${base}/token/klarna`);
|
|
33
33
|
this.publicKeyURL = `${this.baseURL}/public_key`;
|
|
34
|
-
this.
|
|
34
|
+
this.publicKeyFallbackURLs = this.fallbackBaseURLs.map(base => `${base}/public_key`);
|
|
35
35
|
this.publicKey = this.fetchPublicKey();
|
|
36
36
|
this.keyPair = (0, browserCrypto_1.generateKeyPair)();
|
|
37
37
|
}
|
|
38
|
-
makePostRequest(request, url,
|
|
38
|
+
makePostRequest(request, url, fallbackURLs, encryptRequest, decryptResponse) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
const publicKey = yield this.publicKey;
|
|
41
41
|
if (publicKey instanceof Error) {
|
|
@@ -48,7 +48,7 @@ class TkClient {
|
|
|
48
48
|
if (encryptedRequest instanceof Error) {
|
|
49
49
|
return encryptedRequest;
|
|
50
50
|
}
|
|
51
|
-
const httpResponse = yield this.fetchWithFallback(url,
|
|
51
|
+
const httpResponse = yield this.fetchWithFallback(url, fallbackURLs, {
|
|
52
52
|
body: JSON.stringify(encryptedRequest),
|
|
53
53
|
method: "POST",
|
|
54
54
|
headers: { "Content-Type": "application/json" },
|
|
@@ -65,15 +65,15 @@ class TkClient {
|
|
|
65
65
|
}
|
|
66
66
|
postToken(request) {
|
|
67
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
return this.makePostRequest(request, this.tokenURL, this.
|
|
68
|
+
return this.makePostRequest(request, this.tokenURL, this.tokenFallbackURLs, (request, publicKey, keyPair) => (0, browserCrypto_1.encryptRequest)(request, publicKey, keyPair), (response, publicKey, keyPair) => (0, browserCrypto_1.decryptResponse)(response, publicKey, keyPair));
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
postCVVToken(request) {
|
|
72
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
return this.makePostRequest(request, this.cvvTokenURL, this.
|
|
73
|
+
return this.makePostRequest(request, this.cvvTokenURL, this.cvvTokenFallbackURLs, (request, publicKey, keyPair) => (0, browserCrypto_1.encryptRequest)(request, publicKey, keyPair), (response, publicKey, keyPair) => (0, browserCrypto_1.decryptResponse)(response, publicKey, keyPair));
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
makePostRequestWithPublicKey(request, url,
|
|
76
|
+
makePostRequestWithPublicKey(request, url, fallbackURLs) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
78
|
const publicKey = yield this.publicKey;
|
|
79
79
|
if (publicKey instanceof Error) {
|
|
@@ -84,7 +84,7 @@ class TkClient {
|
|
|
84
84
|
}
|
|
85
85
|
// Add public_key to request for response encryption
|
|
86
86
|
const requestWithPublicKey = Object.assign(Object.assign({}, request), { public_key: (0, base64_1.toBase64)((0, arrayBuffers_1.fromUint8)(this.keyPair.publicKey)) });
|
|
87
|
-
const httpResponse = yield this.fetchWithFallback(url,
|
|
87
|
+
const httpResponse = yield this.fetchWithFallback(url, fallbackURLs, {
|
|
88
88
|
body: JSON.stringify(requestWithPublicKey),
|
|
89
89
|
method: "POST",
|
|
90
90
|
headers: { "Content-Type": "application/json" },
|
|
@@ -102,17 +102,17 @@ class TkClient {
|
|
|
102
102
|
}
|
|
103
103
|
postApplePayToken(request) {
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
return this.makePostRequestWithPublicKey(request, this.applePayTokenURL, this.
|
|
105
|
+
return this.makePostRequestWithPublicKey(request, this.applePayTokenURL, this.applePayTokenFallbackURLs);
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
postGooglePayToken(request) {
|
|
109
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
return this.makePostRequestWithPublicKey(request, this.googlePayTokenURL, this.
|
|
110
|
+
return this.makePostRequestWithPublicKey(request, this.googlePayTokenURL, this.googlePayTokenFallbackURLs);
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
postKlarnaToken(request) {
|
|
114
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
return this.makePostRequest(request, this.klarnaTokenURL, this.
|
|
115
|
+
return this.makePostRequest(request, this.klarnaTokenURL, this.klarnaTokenFallbackURLs, (request, _publicKey, _keyPair) => request, (response, _publicKey, _keyPair) => response);
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
overrideBaseUrl(baseUrl) {
|
|
@@ -134,7 +134,7 @@ class TkClient {
|
|
|
134
134
|
}
|
|
135
135
|
fetchPublicKey() {
|
|
136
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
const response = yield this.fetchWithFallback(this.publicKeyURL, this.
|
|
137
|
+
const response = yield this.fetchWithFallback(this.publicKeyURL, this.publicKeyFallbackURLs);
|
|
138
138
|
if (response instanceof Error) {
|
|
139
139
|
return response;
|
|
140
140
|
}
|
|
@@ -145,10 +145,15 @@ class TkClient {
|
|
|
145
145
|
return (0, arrayBuffers_1.toUint8)((0, base64_1.fromBase64)(publicKeyStr));
|
|
146
146
|
});
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
// Tries the primary url first, then each fallback url in order, stopping at the
|
|
149
|
+
// first 200 response. A non-200 (or thrown error) falls through to the next host.
|
|
150
|
+
fetchWithFallback(url, fallbackUrls, init) {
|
|
149
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
152
|
let response = yield this.fetch(url, init);
|
|
151
|
-
|
|
153
|
+
for (const fallbackUrl of fallbackUrls) {
|
|
154
|
+
if (!(response instanceof Error) && response.status === 200) {
|
|
155
|
+
return response;
|
|
156
|
+
}
|
|
152
157
|
response = yield this.fetch(fallbackUrl, init);
|
|
153
158
|
}
|
|
154
159
|
return response;
|
|
@@ -49,6 +49,11 @@ describe("TkClient", () => {
|
|
|
49
49
|
statusText: "Internal Server Error",
|
|
50
50
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return ""; }),
|
|
51
51
|
});
|
|
52
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/public_key", {
|
|
53
|
+
status: 500,
|
|
54
|
+
statusText: "Internal Server Error",
|
|
55
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return ""; }),
|
|
56
|
+
});
|
|
52
57
|
mockResponses.set("https://tokenizer-sandbox.bolt.com/public_key", {
|
|
53
58
|
status: 500,
|
|
54
59
|
statusText: "Internal Server Error",
|
|
@@ -80,6 +85,11 @@ describe("TkClient", () => {
|
|
|
80
85
|
statusText: "Bad Request",
|
|
81
86
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
82
87
|
});
|
|
88
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/token", {
|
|
89
|
+
status: 400,
|
|
90
|
+
statusText: "Bad Request",
|
|
91
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
92
|
+
});
|
|
83
93
|
mockResponses.set("https://tokenizer-sandbox.bolt.com/token", {
|
|
84
94
|
status: 400,
|
|
85
95
|
statusText: "Bad Request",
|
|
@@ -98,6 +108,7 @@ describe("TkClient", () => {
|
|
|
98
108
|
}));
|
|
99
109
|
it("handles network errors", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
110
|
mockResponses.set("https://sandbox.bolttk.com/public_key", new Error("Network error"));
|
|
111
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/public_key", new Error("Network error"));
|
|
101
112
|
mockResponses.set("https://tokenizer-sandbox.bolt.com/public_key", new Error("Network error"));
|
|
102
113
|
const client = new client_1.TkClient("sandbox", mockFetch);
|
|
103
114
|
const tokenRequest = {
|
|
@@ -118,6 +129,11 @@ describe("TkClient", () => {
|
|
|
118
129
|
statusText: "Internal Server Error",
|
|
119
130
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return ""; }),
|
|
120
131
|
});
|
|
132
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/public_key", {
|
|
133
|
+
status: 500,
|
|
134
|
+
statusText: "Internal Server Error",
|
|
135
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return ""; }),
|
|
136
|
+
});
|
|
121
137
|
mockResponses.set("https://tokenizer-sandbox.bolt.com/public_key", {
|
|
122
138
|
status: 500,
|
|
123
139
|
statusText: "Internal Server Error",
|
|
@@ -146,6 +162,11 @@ describe("TkClient", () => {
|
|
|
146
162
|
statusText: "Unprocessable Entity",
|
|
147
163
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
148
164
|
});
|
|
165
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/token/cvv", {
|
|
166
|
+
status: 422,
|
|
167
|
+
statusText: "Unprocessable Entity",
|
|
168
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
169
|
+
});
|
|
149
170
|
mockResponses.set("https://tokenizer-sandbox.bolt.com/token/cvv", {
|
|
150
171
|
status: 422,
|
|
151
172
|
statusText: "Unprocessable Entity",
|
|
@@ -226,7 +247,7 @@ describe("TkClient", () => {
|
|
|
226
247
|
statusText: "OK",
|
|
227
248
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return JSON.stringify(tempEncryptedResponse); }),
|
|
228
249
|
});
|
|
229
|
-
mockResponses.set("https://tokenizer-sandbox.
|
|
250
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/token/applepay", {
|
|
230
251
|
status: 200,
|
|
231
252
|
statusText: "OK",
|
|
232
253
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return JSON.stringify(tempEncryptedResponse); }),
|
|
@@ -247,7 +268,7 @@ describe("TkClient", () => {
|
|
|
247
268
|
statusText: "OK",
|
|
248
269
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return JSON.stringify(encryptedResponse); }),
|
|
249
270
|
});
|
|
250
|
-
mockResponses.set("https://tokenizer-sandbox.
|
|
271
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/token/applepay", {
|
|
251
272
|
status: 200,
|
|
252
273
|
statusText: "OK",
|
|
253
274
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return JSON.stringify(encryptedResponse); }),
|
|
@@ -285,6 +306,11 @@ describe("TkClient", () => {
|
|
|
285
306
|
statusText: "Internal Server Error",
|
|
286
307
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
287
308
|
});
|
|
309
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/token/applepay", {
|
|
310
|
+
status: 500,
|
|
311
|
+
statusText: "Internal Server Error",
|
|
312
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
313
|
+
});
|
|
288
314
|
mockResponses.set("https://tokenizer-sandbox.bolt.com/token/applepay", {
|
|
289
315
|
status: 500,
|
|
290
316
|
statusText: "Internal Server Error",
|
|
@@ -348,6 +374,11 @@ describe("TkClient", () => {
|
|
|
348
374
|
statusText: "Bad Request",
|
|
349
375
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
350
376
|
});
|
|
377
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/token/klarna", {
|
|
378
|
+
status: 400,
|
|
379
|
+
statusText: "Bad Request",
|
|
380
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
381
|
+
});
|
|
351
382
|
mockResponses.set("https://tokenizer-sandbox.bolt.com/token/klarna", {
|
|
352
383
|
status: 400,
|
|
353
384
|
statusText: "Bad Request",
|
|
@@ -379,6 +410,11 @@ describe("TkClient", () => {
|
|
|
379
410
|
statusText: "Internal Server Error",
|
|
380
411
|
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
381
412
|
});
|
|
413
|
+
mockResponses.set("https://tokenizer-sandbox.boltapp.com/token/klarna", {
|
|
414
|
+
status: 500,
|
|
415
|
+
statusText: "Internal Server Error",
|
|
416
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return "{}"; }),
|
|
417
|
+
});
|
|
382
418
|
mockResponses.set("https://tokenizer-sandbox.bolt.com/token/klarna", {
|
|
383
419
|
status: 500,
|
|
384
420
|
statusText: "Internal Server Error",
|