@basis-theory/basis-theory-js 4.22.1 → 4.23.0
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 +2 -2
- package/common/constants.js +1 -1
- package/common/utils.js +3 -2
- package/elements/constants.d.ts +3 -2
- package/elements/constants.js +4 -2
- package/elements/load.js +122 -57
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Basis Theory JS SDK (aka BasisTheory.js)
|
|
2
2
|
|
|
3
3
|
> [!CAUTION]
|
|
4
|
-
> This SDK has been deprecated.
|
|
4
|
+
> This SDK has been deprecated for use in Node.js environments. It is still supported for use in web elements and reactor environments.
|
|
5
5
|
>
|
|
6
|
-
> Our new SDK can be found at https://github.com/Basis-Theory/node-sdk
|
|
6
|
+
> Our new Node.js SDK can be found at https://github.com/Basis-Theory/node-sdk
|
|
7
7
|
>
|
|
8
8
|
> See our documentation site for more information. https://developers.basistheory.com/docs/sdks/server-side/node
|
|
9
9
|
|
package/common/constants.js
CHANGED
|
@@ -28,7 +28,7 @@ const DEFAULT_ELEMENTS_BASE_URL = `https://${"js.basistheory.com/hosted-elements
|
|
|
28
28
|
exports.DEFAULT_ELEMENTS_BASE_URL = DEFAULT_ELEMENTS_BASE_URL;
|
|
29
29
|
const DD_TOKEN = "pub5f53501515584007899577554c4aeda6";
|
|
30
30
|
exports.DD_TOKEN = DD_TOKEN;
|
|
31
|
-
const DD_GIT_SHA = "
|
|
31
|
+
const DD_GIT_SHA = "f6e1c47d5deee3b136e999171243c4cad67757a2";
|
|
32
32
|
exports.DD_GIT_SHA = DD_GIT_SHA;
|
|
33
33
|
const CLIENT_BASE_PATHS = {
|
|
34
34
|
tokens: 'tokens',
|
package/common/utils.js
CHANGED
|
@@ -291,7 +291,7 @@ const createRequestConfig = (options, transformers) => {
|
|
|
291
291
|
exports.createRequestConfig = createRequestConfig;
|
|
292
292
|
|
|
293
293
|
const errorInterceptor = error => {
|
|
294
|
-
var _error$response$statu, _error$response, _error$response2, _error$config, _error$config$method, _error$config2, _error$config3, _error$config4, _error$config4$method, _error$config5, _error$config5$header, _error$response3, _error$response4, _error$response5;
|
|
294
|
+
var _error$response$statu, _error$response, _error$response2, _error$config, _error$config$method, _error$config2, _error$config3, _error$config4, _error$config4$method, _error$config5, _error$config5$header, _error$response3, _error$response4, _error$response5, _error$response6;
|
|
295
295
|
|
|
296
296
|
const status = (_error$response$statu = (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) !== null && _error$response$statu !== void 0 ? _error$response$statu : -1;
|
|
297
297
|
const data = (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data;
|
|
@@ -313,7 +313,8 @@ const errorInterceptor = error => {
|
|
|
313
313
|
headers: error === null || error === void 0 ? void 0 : (_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.headers,
|
|
314
314
|
message: error === null || error === void 0 ? void 0 : error.message,
|
|
315
315
|
status: error === null || error === void 0 ? void 0 : (_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : _error$response4.status,
|
|
316
|
-
statusText: error === null || error === void 0 ? void 0 : (_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : _error$response5.statusText
|
|
316
|
+
statusText: error === null || error === void 0 ? void 0 : (_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : _error$response5.statusText,
|
|
317
|
+
data: error === null || error === void 0 ? void 0 : (_error$response6 = error.response) === null || _error$response6 === void 0 ? void 0 : _error$response6.data
|
|
317
318
|
}
|
|
318
319
|
});
|
|
319
320
|
|
package/elements/constants.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
declare const ELEMENTS_INIT_ERROR_MESSAGE = "BasisTheory Elements was not properly initialized.";
|
|
2
2
|
declare const ELEMENTS_NOM_DOM_ERROR_MESSAGE = "Tried to load BasisTheoryElements in a non-DOM environment.";
|
|
3
3
|
declare const ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = "Basis Theory Elements did not load properly. Check network tab for more details.";
|
|
4
|
-
declare const ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = "
|
|
4
|
+
declare const ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = "Unable to load the Elements script. This may be due to network restrictions or browser extensions like ad blockers interfering with script loading. Check browser settings or network connection and try again.";
|
|
5
|
+
declare const ELEMENTS_SCRIPT_FAILED_TO_DELIVER = "Failed to deliver Elements script from Basis Theory. Check your network connection and try again or contact support@basistheory.com";
|
|
5
6
|
declare const CARD_BRANDS: readonly ["visa", "mastercard", "american-express", "discover", "diners-club", "jcb", "unionpay", "maestro", "elo", "hiper", "hipercard", "mir", "unknown"];
|
|
6
7
|
declare const CARD_ICON_POSITIONS: readonly ["left", "right", "none"];
|
|
7
8
|
declare const AUTOCOMPLETE_VALUES: readonly ["additional-name", "address-level1", "address-level2", "address-level3", "address-level4", "address-line1", "address-line2", "address-line3", "bday-day", "bday-month", "bday-year", "bday", "billing", "cc-additional-name", "cc-csc", "cc-exp-month", "cc-exp-year", "cc-exp", "cc-family-name", "cc-given-name", "cc-name", "cc-number", "cc-type", "country-name", "country", "current-password", "email", "family-name", "fax", "given-name", "home", "honorific-prefix", "honorific-suffix", "language", "mobile", "name", "new-password", "nickname", "off", "on", "one-time-code", "organization-title", "organization", "page", "postal-code", "sex", "shipping", "street-address", "tel-area-code", "tel-country-code", "tel-extension", "tel-local-prefix", "tel-local-suffix", "tel-local", "tel-national", "tel", "transaction-amount", "transaction-currency", "url", "username", "work"];
|
|
8
|
-
export { ELEMENTS_INIT_ERROR_MESSAGE, ELEMENTS_NOM_DOM_ERROR_MESSAGE, ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE, ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE, CARD_BRANDS, CARD_ICON_POSITIONS, AUTOCOMPLETE_VALUES, };
|
|
9
|
+
export { ELEMENTS_INIT_ERROR_MESSAGE, ELEMENTS_NOM_DOM_ERROR_MESSAGE, ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE, ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE, ELEMENTS_SCRIPT_FAILED_TO_DELIVER, CARD_BRANDS, CARD_ICON_POSITIONS, AUTOCOMPLETE_VALUES, };
|
package/elements/constants.js
CHANGED
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = exports.ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = exports.ELEMENTS_NOM_DOM_ERROR_MESSAGE = exports.ELEMENTS_INIT_ERROR_MESSAGE = exports.CARD_ICON_POSITIONS = exports.CARD_BRANDS = exports.AUTOCOMPLETE_VALUES = void 0;
|
|
6
|
+
exports.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = exports.ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = exports.ELEMENTS_SCRIPT_FAILED_TO_DELIVER = exports.ELEMENTS_NOM_DOM_ERROR_MESSAGE = exports.ELEMENTS_INIT_ERROR_MESSAGE = exports.CARD_ICON_POSITIONS = exports.CARD_BRANDS = exports.AUTOCOMPLETE_VALUES = void 0;
|
|
7
7
|
const ELEMENTS_INIT_ERROR_MESSAGE = 'BasisTheory Elements was not properly initialized.';
|
|
8
8
|
exports.ELEMENTS_INIT_ERROR_MESSAGE = ELEMENTS_INIT_ERROR_MESSAGE;
|
|
9
9
|
const ELEMENTS_NOM_DOM_ERROR_MESSAGE = 'Tried to load BasisTheoryElements in a non-DOM environment.';
|
|
10
10
|
exports.ELEMENTS_NOM_DOM_ERROR_MESSAGE = ELEMENTS_NOM_DOM_ERROR_MESSAGE;
|
|
11
11
|
const ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = 'Basis Theory Elements did not load properly. Check network tab for more details.';
|
|
12
12
|
exports.ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE;
|
|
13
|
-
const ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = '
|
|
13
|
+
const ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = 'Unable to load the Elements script. This may be due to network restrictions or browser extensions like ad blockers interfering with script loading. Check browser settings or network connection and try again.';
|
|
14
14
|
exports.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE;
|
|
15
|
+
const ELEMENTS_SCRIPT_FAILED_TO_DELIVER = 'Failed to deliver Elements script from Basis Theory. Check your network connection and try again or contact support@basistheory.com';
|
|
16
|
+
exports.ELEMENTS_SCRIPT_FAILED_TO_DELIVER = ELEMENTS_SCRIPT_FAILED_TO_DELIVER;
|
|
15
17
|
const CARD_BRANDS = ['visa', 'mastercard', 'american-express', 'discover', 'diners-club', 'jcb', 'unionpay', 'maestro', 'elo', 'hiper', 'hipercard', 'mir', 'unknown'];
|
|
16
18
|
exports.CARD_BRANDS = CARD_BRANDS;
|
|
17
19
|
const CARD_ICON_POSITIONS = ['left', 'right', 'none']; // https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
|
package/elements/load.js
CHANGED
|
@@ -9,10 +9,115 @@ var _logging = require("./../common/logging");
|
|
|
9
9
|
|
|
10
10
|
var _constants = require("./constants");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _script2 = require("./script");
|
|
13
13
|
|
|
14
14
|
let elementsPromise;
|
|
15
15
|
|
|
16
|
+
const loadScript = (url, retryCount) => new Promise((resolve, reject) => {
|
|
17
|
+
let script = (0, _script2.findScript)(url);
|
|
18
|
+
|
|
19
|
+
if (!script) {
|
|
20
|
+
script = (0, _script2.injectScript)(url);
|
|
21
|
+
} // flag to prevent double rejection (if somehow script was not removed)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
let isSettled = false; // script load success
|
|
25
|
+
|
|
26
|
+
script.addEventListener('load', () => {
|
|
27
|
+
if (window.BasisTheoryElements) {
|
|
28
|
+
resolve(window.BasisTheoryElements);
|
|
29
|
+
} else {
|
|
30
|
+
(async () => {
|
|
31
|
+
await _logging.logger.log.error('Elements not found on window on load', {
|
|
32
|
+
logType: 'elementsNotFoundOnWindow',
|
|
33
|
+
logOrigin: 'loadScript',
|
|
34
|
+
retryCount
|
|
35
|
+
});
|
|
36
|
+
})();
|
|
37
|
+
|
|
38
|
+
reject(new Error(_constants.ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE));
|
|
39
|
+
}
|
|
40
|
+
}); // script error event
|
|
41
|
+
|
|
42
|
+
script.addEventListener('error', async event => {
|
|
43
|
+
if (isSettled) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
isSettled = true;
|
|
48
|
+
await _logging.logger.log.error('Elements script onError event', {
|
|
49
|
+
logType: 'elementsScriptOnError',
|
|
50
|
+
logOrigin: 'loadScript',
|
|
51
|
+
retryCount,
|
|
52
|
+
event: {
|
|
53
|
+
message: event === null || event === void 0 ? void 0 : event.message,
|
|
54
|
+
source: event === null || event === void 0 ? void 0 : event.filename,
|
|
55
|
+
lineno: event === null || event === void 0 ? void 0 : event.lineno,
|
|
56
|
+
colno: event === null || event === void 0 ? void 0 : event.colno,
|
|
57
|
+
error: event === null || event === void 0 ? void 0 : event.error,
|
|
58
|
+
target: event === null || event === void 0 ? void 0 : event.target
|
|
59
|
+
}
|
|
60
|
+
}); // remove from dom to avoid duplicates
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
var _script;
|
|
64
|
+
|
|
65
|
+
(_script = script) === null || _script === void 0 ? void 0 : _script.remove();
|
|
66
|
+
} catch (error) {
|
|
67
|
+
await _logging.logger.log.error(`Error removing script from DOM on retry attempt ${retryCount}`, {
|
|
68
|
+
logType: 'scriptRemovalError',
|
|
69
|
+
logOrigin: 'loadScript',
|
|
70
|
+
retryCount,
|
|
71
|
+
removalError: error
|
|
72
|
+
});
|
|
73
|
+
} // retry 1x if first attempt
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if (retryCount === 0) {
|
|
77
|
+
loadScript(url, retryCount + 1).then(resolve).catch(reject);
|
|
78
|
+
return;
|
|
79
|
+
} // second attempt has failed: try fetching the script to inspect the response
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetch(url);
|
|
84
|
+
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
await _logging.logger.log.error(`Second attempt to load elements script failed, fetch failed with status: ${response.status}.`, {
|
|
87
|
+
logType: 'elementsScriptFetchFailure',
|
|
88
|
+
logOrigin: 'loadScript',
|
|
89
|
+
retryCount,
|
|
90
|
+
fetchResult: 'error',
|
|
91
|
+
fetchResponse: response
|
|
92
|
+
});
|
|
93
|
+
reject(new Error(_constants.ELEMENTS_SCRIPT_FAILED_TO_DELIVER));
|
|
94
|
+
} else {
|
|
95
|
+
await _logging.logger.log.error(`Second attempt to load elements script failed, fetch success`, {
|
|
96
|
+
logType: 'elementsScriptFetchFailure',
|
|
97
|
+
logOrigin: 'loadScript',
|
|
98
|
+
retryCount,
|
|
99
|
+
fetchResult: 'success',
|
|
100
|
+
fetchResponse: response
|
|
101
|
+
});
|
|
102
|
+
reject(new Error(_constants.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE));
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
// fetch also failed
|
|
106
|
+
await _logging.logger.log.error('Second attempt failed to load elements script failed, fetch network error.', {
|
|
107
|
+
logType: 'elementsScriptFetchError',
|
|
108
|
+
logOrigin: 'loadScript',
|
|
109
|
+
retryCount,
|
|
110
|
+
fetchResult: 'error',
|
|
111
|
+
fetchError: error
|
|
112
|
+
});
|
|
113
|
+
reject(new Error(_constants.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE));
|
|
114
|
+
} // ultimately reject with browser message
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
reject((event === null || event === void 0 ? void 0 : event.error) || (event === null || event === void 0 ? void 0 : event.message) || new Error(_constants.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE));
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
16
121
|
const loadElements = elementsClientUrl => {
|
|
17
122
|
if (!elementsPromise) {
|
|
18
123
|
elementsPromise = new Promise((resolve, reject) => {
|
|
@@ -33,67 +138,27 @@ const loadElements = elementsClientUrl => {
|
|
|
33
138
|
return;
|
|
34
139
|
}
|
|
35
140
|
|
|
36
|
-
|
|
37
|
-
let url = `https://${"js.basistheory.com"}/elements`;
|
|
38
|
-
|
|
39
|
-
if (typeof elementsClientUrl !== 'undefined') {
|
|
40
|
-
try {
|
|
41
|
-
const urlObject = new URL(elementsClientUrl);
|
|
42
|
-
url = urlObject.toString().replace(/\/$/u, '');
|
|
43
|
-
} catch {
|
|
44
|
-
(async () => {
|
|
45
|
-
await _logging.logger.log.warn('Invalid format for the given Elements client url.', {
|
|
46
|
-
logType: 'invalidClientUrlError',
|
|
47
|
-
logOrigin: 'loadElements'
|
|
48
|
-
});
|
|
49
|
-
})();
|
|
50
|
-
|
|
51
|
-
throw new Error('Invalid format for the given Elements client url.');
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let script = (0, _script.findScript)(url);
|
|
56
|
-
|
|
57
|
-
if (!script) {
|
|
58
|
-
script = (0, _script.injectScript)(url);
|
|
59
|
-
}
|
|
141
|
+
let url = `https://${"js.basistheory.com"}/elements`;
|
|
60
142
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
143
|
+
if (typeof elementsClientUrl !== 'undefined') {
|
|
144
|
+
try {
|
|
145
|
+
const urlObject = new URL(elementsClientUrl);
|
|
146
|
+
url = urlObject.toString().replace(/\/$/u, '');
|
|
147
|
+
} catch {
|
|
148
|
+
(async () => {
|
|
149
|
+
await _logging.logger.log.warn('Invalid format for the given Elements client url.', {
|
|
150
|
+
logType: 'invalidClientUrlError',
|
|
67
151
|
logOrigin: 'loadElements'
|
|
68
152
|
});
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
script.addEventListener('error', async event => {
|
|
73
|
-
await _logging.logger.log.error('Elements script onError event', {
|
|
74
|
-
logType: 'elementsScriptOnError',
|
|
75
|
-
logOrigin: 'loadElements',
|
|
76
|
-
event: {
|
|
77
|
-
message: event === null || event === void 0 ? void 0 : event.message,
|
|
78
|
-
source: event === null || event === void 0 ? void 0 : event.filename,
|
|
79
|
-
lineno: event === null || event === void 0 ? void 0 : event.lineno,
|
|
80
|
-
colno: event === null || event === void 0 ? void 0 : event.colno,
|
|
81
|
-
error: event === null || event === void 0 ? void 0 : event.error,
|
|
82
|
-
target: event === null || event === void 0 ? void 0 : event.target
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
reject((event === null || event === void 0 ? void 0 : event.error) || (event === null || event === void 0 ? void 0 : event.message) || new Error(_constants.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE));
|
|
86
|
-
});
|
|
87
|
-
} catch (error) {
|
|
88
|
-
_logging.logger.log.error('Unexpected error loading Elements script', {
|
|
89
|
-
logType: 'unexpectedError',
|
|
90
|
-
logOrigin: 'loadElements',
|
|
91
|
-
errorObject: error
|
|
92
|
-
});
|
|
153
|
+
})();
|
|
93
154
|
|
|
94
|
-
|
|
95
|
-
|
|
155
|
+
throw new Error('Invalid format for the given Elements client url.');
|
|
156
|
+
}
|
|
96
157
|
}
|
|
158
|
+
|
|
159
|
+
loadScript(url, 0).then(resolve).catch(error => {
|
|
160
|
+
reject(error);
|
|
161
|
+
});
|
|
97
162
|
});
|
|
98
163
|
}
|
|
99
164
|
|