@basis-theory/web-elements 1.0.0-beta

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.
Files changed (44) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +3 -0
  3. package/dist/LICENSE +202 -0
  4. package/dist/README.md +3 -0
  5. package/dist/bundle/index.js +1 -0
  6. package/dist/main/index.js +325 -0
  7. package/dist/module/module.js +308 -0
  8. package/dist/package.json +33 -0
  9. package/dist/types/BasisTheory.d.ts +8 -0
  10. package/dist/types/common/BasisTheoryApiError.d.ts +5 -0
  11. package/dist/types/common/BasisTheoryValidationError.d.ts +13 -0
  12. package/dist/types/common/HttpClientError.d.ts +6 -0
  13. package/dist/types/common/index.d.ts +3 -0
  14. package/dist/types/common/logging.d.ts +8 -0
  15. package/dist/types/elements/constants.d.ts +9 -0
  16. package/dist/types/elements/getOrCreateScriptElement.d.ts +1 -0
  17. package/dist/types/elements/index.d.ts +2 -0
  18. package/dist/types/elements/loadElements.d.ts +3 -0
  19. package/dist/types/index.d.ts +470 -0
  20. package/dist/types/types/elements/cardTypes.d.ts +29 -0
  21. package/dist/types/types/elements/elements.d.ts +72 -0
  22. package/dist/types/types/elements/events.d.ts +40 -0
  23. package/dist/types/types/elements/index.d.ts +7 -0
  24. package/dist/types/types/elements/options.d.ts +98 -0
  25. package/dist/types/types/elements/services/index.d.ts +4 -0
  26. package/dist/types/types/elements/services/proxy.d.ts +27 -0
  27. package/dist/types/types/elements/services/shared.d.ts +21 -0
  28. package/dist/types/types/elements/services/token-intents.d.ts +6 -0
  29. package/dist/types/types/elements/services/tokenize.d.ts +8 -0
  30. package/dist/types/types/elements/services/tokens.d.ts +7 -0
  31. package/dist/types/types/elements/shared.d.ts +51 -0
  32. package/dist/types/types/elements/styles.d.ts +25 -0
  33. package/dist/types/types/models/bin-details.d.ts +38 -0
  34. package/dist/types/types/models/cards.d.ts +7 -0
  35. package/dist/types/types/models/index.d.ts +7 -0
  36. package/dist/types/types/models/shared.d.ts +22 -0
  37. package/dist/types/types/models/token-intents.d.ts +28 -0
  38. package/dist/types/types/models/tokenize.d.ts +7 -0
  39. package/dist/types/types/models/tokens.d.ts +53 -0
  40. package/dist/types/types/models/util.d.ts +11 -0
  41. package/dist/types/types/sdk/index.d.ts +1 -0
  42. package/dist/types/types/sdk/services/http.d.ts +11 -0
  43. package/dist/types/types/sdk/services/index.d.ts +1 -0
  44. package/package.json +81 -0
@@ -0,0 +1,325 @@
1
+
2
+ function $parcel$exportWildcard(dest, source) {
3
+ Object.keys(source).forEach(function(key) {
4
+ if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
5
+ return;
6
+ }
7
+
8
+ Object.defineProperty(dest, key, {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return source[key];
12
+ }
13
+ });
14
+ });
15
+
16
+ return dest;
17
+ }
18
+
19
+ function $parcel$export(e, n, v, s) {
20
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
21
+ }
22
+ var $316c9c8f85cead13$exports = {};
23
+
24
+ $parcel$export($316c9c8f85cead13$exports, "basistheory", () => $316c9c8f85cead13$export$cbe2892587230861);
25
+ const $426651baf7085210$export$74dcf80d122cf64e = (url)=>{
26
+ const existingScript = document.querySelector(`script[src^="${url}"]`);
27
+ if (existingScript) return existingScript;
28
+ const parent = document.head || document.body;
29
+ if (!parent) throw new Error('No <head> or <body> elements found in the document.');
30
+ const script = Object.assign(document.createElement('script'), {
31
+ src: url
32
+ });
33
+ parent.append(script);
34
+ return script;
35
+ };
36
+
37
+
38
+ const $ef6e1b024b683770$export$ab49734bd00442f0 = 'BasisTheory Elements was not properly initialized.';
39
+ const $ef6e1b024b683770$export$6b1a35ff3caa965f = 'Tried to load BasisTheoryElements in a non-DOM environment.';
40
+ const $ef6e1b024b683770$export$e3797f3a93015b7b = 'Basis Theory Elements did not load properly. Check network tab for more details.';
41
+ const $ef6e1b024b683770$export$56e79dc97980170 = '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.';
42
+ const $ef6e1b024b683770$export$9fe15478e8fc6bac = 'Failed to deliver Elements script from Basis Theory. Check your network connection and try again or contact support@basistheory.com';
43
+ const $ef6e1b024b683770$export$51be6d94c4fcf45 = [
44
+ 'visa',
45
+ 'mastercard',
46
+ 'american-express',
47
+ 'discover',
48
+ 'diners-club',
49
+ 'jcb',
50
+ 'unionpay',
51
+ 'maestro',
52
+ 'elo',
53
+ 'hiper',
54
+ 'hipercard',
55
+ 'mir',
56
+ 'unknown'
57
+ ];
58
+ const $ef6e1b024b683770$export$829c91d8f039f695 = [
59
+ 'left',
60
+ 'right',
61
+ 'none'
62
+ ];
63
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
64
+ const $ef6e1b024b683770$export$dea6ebbc92df4fa3 = [
65
+ 'additional-name',
66
+ 'address-level1',
67
+ 'address-level2',
68
+ 'address-level3',
69
+ 'address-level4',
70
+ 'address-line1',
71
+ 'address-line2',
72
+ 'address-line3',
73
+ 'bday-day',
74
+ 'bday-month',
75
+ 'bday-year',
76
+ 'bday',
77
+ 'billing',
78
+ 'cc-additional-name',
79
+ 'cc-csc',
80
+ 'cc-exp-month',
81
+ 'cc-exp-year',
82
+ 'cc-exp',
83
+ 'cc-family-name',
84
+ 'cc-given-name',
85
+ 'cc-name',
86
+ 'cc-number',
87
+ 'cc-type',
88
+ 'country-name',
89
+ 'country',
90
+ 'current-password',
91
+ 'email',
92
+ 'family-name',
93
+ 'fax',
94
+ 'given-name',
95
+ 'home',
96
+ 'honorific-prefix',
97
+ 'honorific-suffix',
98
+ 'language',
99
+ 'mobile',
100
+ 'name',
101
+ 'new-password',
102
+ 'nickname',
103
+ 'off',
104
+ 'on',
105
+ 'one-time-code',
106
+ 'organization-title',
107
+ 'organization',
108
+ 'page',
109
+ 'postal-code',
110
+ 'sex',
111
+ 'shipping',
112
+ 'street-address',
113
+ 'tel-area-code',
114
+ 'tel-country-code',
115
+ 'tel-extension',
116
+ 'tel-local-prefix',
117
+ 'tel-local-suffix',
118
+ 'tel-local',
119
+ 'tel-national',
120
+ 'tel',
121
+ 'transaction-amount',
122
+ 'transaction-currency',
123
+ 'url',
124
+ 'username',
125
+ 'work'
126
+ ];
127
+
128
+
129
+
130
+ const $fe2ec396f58502a3$var$DEFAULT_BASE_URL = `https://${undefined}`;
131
+ const $fe2ec396f58502a3$export$af88d00dbe7f521 = (()=>{
132
+ const ddTok = 'pubb96b84a13912504f4354f2d794ea4fab';
133
+ let isTelemetryEnabled = true;
134
+ const _log = async (message, level, attributes = {})=>{
135
+ if (!isTelemetryEnabled) return;
136
+ let env;
137
+ if ($fe2ec396f58502a3$var$DEFAULT_BASE_URL.includes('localhost')) env = 'local';
138
+ else if ($fe2ec396f58502a3$var$DEFAULT_BASE_URL.includes('dev')) env = 'dev';
139
+ else env = 'prod';
140
+ const payload = {
141
+ level: // dd info
142
+ level,
143
+ message: message,
144
+ // for basis theory tracking
145
+ service: 'web-elements-loader',
146
+ env: env,
147
+ // browser information
148
+ referrer: document?.referrer,
149
+ origin: window?.location.origin,
150
+ url: window?.location.href,
151
+ userAgent: navigator?.userAgent,
152
+ // custom values
153
+ ...attributes
154
+ };
155
+ try {
156
+ await fetch(`https://http-intake.logs.datadoghq.com/v1/input/${ddTok}`, {
157
+ method: 'POST',
158
+ body: JSON.stringify(payload),
159
+ headers: {
160
+ 'Content-Type': 'application/json'
161
+ }
162
+ });
163
+ } catch {
164
+ // eslint-disable-next-line no-console
165
+ console.warn('There was an error sending telemetry.');
166
+ }
167
+ };
168
+ const setTelemetryEnabled = (enabled)=>{
169
+ isTelemetryEnabled = enabled;
170
+ };
171
+ return {
172
+ setTelemetryEnabled: setTelemetryEnabled,
173
+ log: {
174
+ error: (message, attributes = {})=>_log(message, 'error', attributes),
175
+ info: (message, attributes = {})=>_log(message, 'info', attributes),
176
+ warn: (message, attributes = {})=>_log(message, 'warn', attributes)
177
+ }
178
+ };
179
+ })();
180
+
181
+
182
+ let $6477b722f43d24f2$var$elementsPromise;
183
+ const $6477b722f43d24f2$var$loadScript = (url, retryCount)=>new Promise((resolve, reject)=>{
184
+ let script = (0, $426651baf7085210$export$74dcf80d122cf64e)(url);
185
+ // flag to prevent double rejection (if somehow script was not removed)
186
+ let isSettled = false;
187
+ // script load success
188
+ script.addEventListener('load', ()=>{
189
+ if (window.BasisTheoryElements) resolve(window.BasisTheoryElements);
190
+ else {
191
+ (async ()=>{
192
+ await (0, $fe2ec396f58502a3$export$af88d00dbe7f521).log.error('Elements not found on window on load', {
193
+ logType: 'elementsNotFoundOnWindow',
194
+ logOrigin: 'loadScript',
195
+ retryCount: retryCount
196
+ });
197
+ })();
198
+ reject(new Error((0, $ef6e1b024b683770$export$e3797f3a93015b7b)));
199
+ }
200
+ });
201
+ // script error event
202
+ script.addEventListener('error', async (event)=>{
203
+ if (isSettled) return;
204
+ isSettled = true;
205
+ await (0, $fe2ec396f58502a3$export$af88d00dbe7f521).log.error('Elements script onError event', {
206
+ logType: 'elementsScriptOnError',
207
+ logOrigin: 'loadScript',
208
+ retryCount: retryCount,
209
+ event: {
210
+ message: event?.message,
211
+ source: event?.filename,
212
+ lineno: event?.lineno,
213
+ colno: event?.colno,
214
+ error: event?.error,
215
+ target: event?.target
216
+ }
217
+ });
218
+ // remove from dom to avoid duplicates
219
+ try {
220
+ script?.remove();
221
+ } catch (error) {
222
+ await (0, $fe2ec396f58502a3$export$af88d00dbe7f521).log.error(`Error removing script from DOM on retry attempt ${retryCount}`, {
223
+ logType: 'scriptRemovalError',
224
+ logOrigin: 'loadScript',
225
+ retryCount: retryCount,
226
+ removalError: error
227
+ });
228
+ }
229
+ // retry 1x if first attempt
230
+ if (retryCount === 0) {
231
+ $6477b722f43d24f2$var$loadScript(url, retryCount + 1).then(resolve).catch(reject);
232
+ return;
233
+ }
234
+ // second attempt has failed: try fetching the script to inspect the response
235
+ try {
236
+ const response = await fetch(url);
237
+ if (!response.ok) {
238
+ await (0, $fe2ec396f58502a3$export$af88d00dbe7f521).log.error(`Second attempt to load elements script failed, fetch failed with status: ${response.status}.`, {
239
+ logType: 'elementsScriptFetchFailure',
240
+ logOrigin: 'loadScript',
241
+ retryCount: retryCount,
242
+ fetchResult: 'error',
243
+ fetchResponse: response
244
+ });
245
+ reject(new Error((0, $ef6e1b024b683770$export$6b1a35ff3caa965f)));
246
+ } else {
247
+ await (0, $fe2ec396f58502a3$export$af88d00dbe7f521).log.error(`Second attempt to load elements script failed, fetch success`, {
248
+ logType: 'elementsScriptFetchFailure',
249
+ logOrigin: 'loadScript',
250
+ retryCount: retryCount,
251
+ fetchResult: 'success',
252
+ fetchResponse: response
253
+ });
254
+ reject(new Error((0, $ef6e1b024b683770$export$56e79dc97980170)));
255
+ }
256
+ } catch (error) {
257
+ // fetch also failed
258
+ await (0, $fe2ec396f58502a3$export$af88d00dbe7f521).log.error('Second attempt failed to load elements script failed, fetch network error.', {
259
+ logType: 'elementsScriptFetchError',
260
+ logOrigin: 'loadScript',
261
+ retryCount: retryCount,
262
+ fetchResult: 'error',
263
+ fetchError: error
264
+ });
265
+ reject(new Error((0, $ef6e1b024b683770$export$56e79dc97980170)));
266
+ }
267
+ // ultimately reject with browser message
268
+ reject(event?.error || event?.message || new Error((0, $ef6e1b024b683770$export$56e79dc97980170)));
269
+ });
270
+ });
271
+ const $6477b722f43d24f2$export$2b0a6e5a1c78018f = (elementsClientUrl)=>{
272
+ if (!$6477b722f43d24f2$var$elementsPromise) $6477b722f43d24f2$var$elementsPromise = new Promise((resolve, reject)=>{
273
+ if (typeof window !== 'object') {
274
+ (async ()=>{
275
+ await (0, $fe2ec396f58502a3$export$af88d00dbe7f521).log.warn((0, $ef6e1b024b683770$export$6b1a35ff3caa965f), {
276
+ logType: 'elementsNonDomError',
277
+ logOrigin: 'loadElements'
278
+ });
279
+ reject(new Error((0, $ef6e1b024b683770$export$6b1a35ff3caa965f)));
280
+ })();
281
+ return;
282
+ }
283
+ if (window.BasisTheoryElements) {
284
+ resolve(window.BasisTheoryElements);
285
+ return;
286
+ }
287
+ let url = `https://${undefined}/elements`;
288
+ if (typeof elementsClientUrl !== 'undefined') try {
289
+ const urlObject = new URL(elementsClientUrl);
290
+ url = urlObject.toString().replace(/\/$/u, '');
291
+ } catch {
292
+ (async ()=>{
293
+ await (0, $fe2ec396f58502a3$export$af88d00dbe7f521).log.warn('Invalid format for the given Elements client url.', {
294
+ logType: 'invalidClientUrlError',
295
+ logOrigin: 'loadElements'
296
+ });
297
+ })();
298
+ throw new Error('Invalid format for the given Elements client url.');
299
+ }
300
+ $6477b722f43d24f2$var$loadScript(url, 0).then(resolve).catch((error)=>{
301
+ reject(error);
302
+ });
303
+ });
304
+ return $6477b722f43d24f2$var$elementsPromise;
305
+ };
306
+
307
+
308
+
309
+
310
+ const $316c9c8f85cead13$var$TEST_ENV = 'js.flock-dev.com';
311
+ const $316c9c8f85cead13$var$DEFAULT_ENV = 'js.basistheory.com';
312
+ const $316c9c8f85cead13$export$cbe2892587230861 = async (apiKey, options)=>{
313
+ if (!apiKey) throw new Error('API key is required');
314
+ const env = options?._devMode ? $316c9c8f85cead13$var$TEST_ENV : $316c9c8f85cead13$var$DEFAULT_ENV;
315
+ const elements = await (0, $6477b722f43d24f2$export$2b0a6e5a1c78018f)(`https://${env}/elements`);
316
+ return elements.init(apiKey, `https://${env}/hosted-elements`, false, options?.useSameOriginApi ?? false, options?.disableTelemetry ?? false);
317
+ };
318
+
319
+
320
+ /**
321
+ * Attaches to window when importing via `<script>` tags.
322
+ */ if (typeof window !== 'undefined' && document.currentScript && !window.basistheory) window.basistheory = (0, $316c9c8f85cead13$export$cbe2892587230861);
323
+ $parcel$exportWildcard(module.exports, $316c9c8f85cead13$exports);
324
+
325
+
@@ -0,0 +1,308 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+ var $65168f0452925da7$exports = {};
6
+
7
+ $parcel$export($65168f0452925da7$exports, "basistheory", () => $65168f0452925da7$export$cbe2892587230861);
8
+ const $0da125a57a8274fc$export$74dcf80d122cf64e = (url)=>{
9
+ const existingScript = document.querySelector(`script[src^="${url}"]`);
10
+ if (existingScript) return existingScript;
11
+ const parent = document.head || document.body;
12
+ if (!parent) throw new Error('No <head> or <body> elements found in the document.');
13
+ const script = Object.assign(document.createElement('script'), {
14
+ src: url
15
+ });
16
+ parent.append(script);
17
+ return script;
18
+ };
19
+
20
+
21
+ const $2e9038c0999bba06$export$ab49734bd00442f0 = 'BasisTheory Elements was not properly initialized.';
22
+ const $2e9038c0999bba06$export$6b1a35ff3caa965f = 'Tried to load BasisTheoryElements in a non-DOM environment.';
23
+ const $2e9038c0999bba06$export$e3797f3a93015b7b = 'Basis Theory Elements did not load properly. Check network tab for more details.';
24
+ const $2e9038c0999bba06$export$56e79dc97980170 = '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.';
25
+ const $2e9038c0999bba06$export$9fe15478e8fc6bac = 'Failed to deliver Elements script from Basis Theory. Check your network connection and try again or contact support@basistheory.com';
26
+ const $2e9038c0999bba06$export$51be6d94c4fcf45 = [
27
+ 'visa',
28
+ 'mastercard',
29
+ 'american-express',
30
+ 'discover',
31
+ 'diners-club',
32
+ 'jcb',
33
+ 'unionpay',
34
+ 'maestro',
35
+ 'elo',
36
+ 'hiper',
37
+ 'hipercard',
38
+ 'mir',
39
+ 'unknown'
40
+ ];
41
+ const $2e9038c0999bba06$export$829c91d8f039f695 = [
42
+ 'left',
43
+ 'right',
44
+ 'none'
45
+ ];
46
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
47
+ const $2e9038c0999bba06$export$dea6ebbc92df4fa3 = [
48
+ 'additional-name',
49
+ 'address-level1',
50
+ 'address-level2',
51
+ 'address-level3',
52
+ 'address-level4',
53
+ 'address-line1',
54
+ 'address-line2',
55
+ 'address-line3',
56
+ 'bday-day',
57
+ 'bday-month',
58
+ 'bday-year',
59
+ 'bday',
60
+ 'billing',
61
+ 'cc-additional-name',
62
+ 'cc-csc',
63
+ 'cc-exp-month',
64
+ 'cc-exp-year',
65
+ 'cc-exp',
66
+ 'cc-family-name',
67
+ 'cc-given-name',
68
+ 'cc-name',
69
+ 'cc-number',
70
+ 'cc-type',
71
+ 'country-name',
72
+ 'country',
73
+ 'current-password',
74
+ 'email',
75
+ 'family-name',
76
+ 'fax',
77
+ 'given-name',
78
+ 'home',
79
+ 'honorific-prefix',
80
+ 'honorific-suffix',
81
+ 'language',
82
+ 'mobile',
83
+ 'name',
84
+ 'new-password',
85
+ 'nickname',
86
+ 'off',
87
+ 'on',
88
+ 'one-time-code',
89
+ 'organization-title',
90
+ 'organization',
91
+ 'page',
92
+ 'postal-code',
93
+ 'sex',
94
+ 'shipping',
95
+ 'street-address',
96
+ 'tel-area-code',
97
+ 'tel-country-code',
98
+ 'tel-extension',
99
+ 'tel-local-prefix',
100
+ 'tel-local-suffix',
101
+ 'tel-local',
102
+ 'tel-national',
103
+ 'tel',
104
+ 'transaction-amount',
105
+ 'transaction-currency',
106
+ 'url',
107
+ 'username',
108
+ 'work'
109
+ ];
110
+
111
+
112
+
113
+ const $367e4a81566d966b$var$DEFAULT_BASE_URL = `https://${undefined}`;
114
+ const $367e4a81566d966b$export$af88d00dbe7f521 = (()=>{
115
+ const ddTok = 'pubb96b84a13912504f4354f2d794ea4fab';
116
+ let isTelemetryEnabled = true;
117
+ const _log = async (message, level, attributes = {})=>{
118
+ if (!isTelemetryEnabled) return;
119
+ let env;
120
+ if ($367e4a81566d966b$var$DEFAULT_BASE_URL.includes('localhost')) env = 'local';
121
+ else if ($367e4a81566d966b$var$DEFAULT_BASE_URL.includes('dev')) env = 'dev';
122
+ else env = 'prod';
123
+ const payload = {
124
+ level: // dd info
125
+ level,
126
+ message: message,
127
+ // for basis theory tracking
128
+ service: 'web-elements-loader',
129
+ env: env,
130
+ // browser information
131
+ referrer: document?.referrer,
132
+ origin: window?.location.origin,
133
+ url: window?.location.href,
134
+ userAgent: navigator?.userAgent,
135
+ // custom values
136
+ ...attributes
137
+ };
138
+ try {
139
+ await fetch(`https://http-intake.logs.datadoghq.com/v1/input/${ddTok}`, {
140
+ method: 'POST',
141
+ body: JSON.stringify(payload),
142
+ headers: {
143
+ 'Content-Type': 'application/json'
144
+ }
145
+ });
146
+ } catch {
147
+ // eslint-disable-next-line no-console
148
+ console.warn('There was an error sending telemetry.');
149
+ }
150
+ };
151
+ const setTelemetryEnabled = (enabled)=>{
152
+ isTelemetryEnabled = enabled;
153
+ };
154
+ return {
155
+ setTelemetryEnabled: setTelemetryEnabled,
156
+ log: {
157
+ error: (message, attributes = {})=>_log(message, 'error', attributes),
158
+ info: (message, attributes = {})=>_log(message, 'info', attributes),
159
+ warn: (message, attributes = {})=>_log(message, 'warn', attributes)
160
+ }
161
+ };
162
+ })();
163
+
164
+
165
+ let $2cc07a9862fd14af$var$elementsPromise;
166
+ const $2cc07a9862fd14af$var$loadScript = (url, retryCount)=>new Promise((resolve, reject)=>{
167
+ let script = (0, $0da125a57a8274fc$export$74dcf80d122cf64e)(url);
168
+ // flag to prevent double rejection (if somehow script was not removed)
169
+ let isSettled = false;
170
+ // script load success
171
+ script.addEventListener('load', ()=>{
172
+ if (window.BasisTheoryElements) resolve(window.BasisTheoryElements);
173
+ else {
174
+ (async ()=>{
175
+ await (0, $367e4a81566d966b$export$af88d00dbe7f521).log.error('Elements not found on window on load', {
176
+ logType: 'elementsNotFoundOnWindow',
177
+ logOrigin: 'loadScript',
178
+ retryCount: retryCount
179
+ });
180
+ })();
181
+ reject(new Error((0, $2e9038c0999bba06$export$e3797f3a93015b7b)));
182
+ }
183
+ });
184
+ // script error event
185
+ script.addEventListener('error', async (event)=>{
186
+ if (isSettled) return;
187
+ isSettled = true;
188
+ await (0, $367e4a81566d966b$export$af88d00dbe7f521).log.error('Elements script onError event', {
189
+ logType: 'elementsScriptOnError',
190
+ logOrigin: 'loadScript',
191
+ retryCount: retryCount,
192
+ event: {
193
+ message: event?.message,
194
+ source: event?.filename,
195
+ lineno: event?.lineno,
196
+ colno: event?.colno,
197
+ error: event?.error,
198
+ target: event?.target
199
+ }
200
+ });
201
+ // remove from dom to avoid duplicates
202
+ try {
203
+ script?.remove();
204
+ } catch (error) {
205
+ await (0, $367e4a81566d966b$export$af88d00dbe7f521).log.error(`Error removing script from DOM on retry attempt ${retryCount}`, {
206
+ logType: 'scriptRemovalError',
207
+ logOrigin: 'loadScript',
208
+ retryCount: retryCount,
209
+ removalError: error
210
+ });
211
+ }
212
+ // retry 1x if first attempt
213
+ if (retryCount === 0) {
214
+ $2cc07a9862fd14af$var$loadScript(url, retryCount + 1).then(resolve).catch(reject);
215
+ return;
216
+ }
217
+ // second attempt has failed: try fetching the script to inspect the response
218
+ try {
219
+ const response = await fetch(url);
220
+ if (!response.ok) {
221
+ await (0, $367e4a81566d966b$export$af88d00dbe7f521).log.error(`Second attempt to load elements script failed, fetch failed with status: ${response.status}.`, {
222
+ logType: 'elementsScriptFetchFailure',
223
+ logOrigin: 'loadScript',
224
+ retryCount: retryCount,
225
+ fetchResult: 'error',
226
+ fetchResponse: response
227
+ });
228
+ reject(new Error((0, $2e9038c0999bba06$export$6b1a35ff3caa965f)));
229
+ } else {
230
+ await (0, $367e4a81566d966b$export$af88d00dbe7f521).log.error(`Second attempt to load elements script failed, fetch success`, {
231
+ logType: 'elementsScriptFetchFailure',
232
+ logOrigin: 'loadScript',
233
+ retryCount: retryCount,
234
+ fetchResult: 'success',
235
+ fetchResponse: response
236
+ });
237
+ reject(new Error((0, $2e9038c0999bba06$export$56e79dc97980170)));
238
+ }
239
+ } catch (error) {
240
+ // fetch also failed
241
+ await (0, $367e4a81566d966b$export$af88d00dbe7f521).log.error('Second attempt failed to load elements script failed, fetch network error.', {
242
+ logType: 'elementsScriptFetchError',
243
+ logOrigin: 'loadScript',
244
+ retryCount: retryCount,
245
+ fetchResult: 'error',
246
+ fetchError: error
247
+ });
248
+ reject(new Error((0, $2e9038c0999bba06$export$56e79dc97980170)));
249
+ }
250
+ // ultimately reject with browser message
251
+ reject(event?.error || event?.message || new Error((0, $2e9038c0999bba06$export$56e79dc97980170)));
252
+ });
253
+ });
254
+ const $2cc07a9862fd14af$export$2b0a6e5a1c78018f = (elementsClientUrl)=>{
255
+ if (!$2cc07a9862fd14af$var$elementsPromise) $2cc07a9862fd14af$var$elementsPromise = new Promise((resolve, reject)=>{
256
+ if (typeof window !== 'object') {
257
+ (async ()=>{
258
+ await (0, $367e4a81566d966b$export$af88d00dbe7f521).log.warn((0, $2e9038c0999bba06$export$6b1a35ff3caa965f), {
259
+ logType: 'elementsNonDomError',
260
+ logOrigin: 'loadElements'
261
+ });
262
+ reject(new Error((0, $2e9038c0999bba06$export$6b1a35ff3caa965f)));
263
+ })();
264
+ return;
265
+ }
266
+ if (window.BasisTheoryElements) {
267
+ resolve(window.BasisTheoryElements);
268
+ return;
269
+ }
270
+ let url = `https://${undefined}/elements`;
271
+ if (typeof elementsClientUrl !== 'undefined') try {
272
+ const urlObject = new URL(elementsClientUrl);
273
+ url = urlObject.toString().replace(/\/$/u, '');
274
+ } catch {
275
+ (async ()=>{
276
+ await (0, $367e4a81566d966b$export$af88d00dbe7f521).log.warn('Invalid format for the given Elements client url.', {
277
+ logType: 'invalidClientUrlError',
278
+ logOrigin: 'loadElements'
279
+ });
280
+ })();
281
+ throw new Error('Invalid format for the given Elements client url.');
282
+ }
283
+ $2cc07a9862fd14af$var$loadScript(url, 0).then(resolve).catch((error)=>{
284
+ reject(error);
285
+ });
286
+ });
287
+ return $2cc07a9862fd14af$var$elementsPromise;
288
+ };
289
+
290
+
291
+
292
+
293
+ const $65168f0452925da7$var$TEST_ENV = 'js.flock-dev.com';
294
+ const $65168f0452925da7$var$DEFAULT_ENV = 'js.basistheory.com';
295
+ const $65168f0452925da7$export$cbe2892587230861 = async (apiKey, options)=>{
296
+ if (!apiKey) throw new Error('API key is required');
297
+ const env = options?._devMode ? $65168f0452925da7$var$TEST_ENV : $65168f0452925da7$var$DEFAULT_ENV;
298
+ const elements = await (0, $2cc07a9862fd14af$export$2b0a6e5a1c78018f)(`https://${env}/elements`);
299
+ return elements.init(apiKey, `https://${env}/hosted-elements`, false, options?.useSameOriginApi ?? false, options?.disableTelemetry ?? false);
300
+ };
301
+
302
+
303
+ /**
304
+ * Attaches to window when importing via `<script>` tags.
305
+ */ if (typeof window !== 'undefined' && document.currentScript && !window.basistheory) window.basistheory = (0, $65168f0452925da7$export$cbe2892587230861);
306
+
307
+
308
+ export {$65168f0452925da7$export$cbe2892587230861 as basistheory};
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@basis-theory/web-elements",
3
+ "version": "1.0.0-beta",
4
+ "repository": "https://github.com/basis-theory/web-elements",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "Basis Theory",
8
+ "email": "support@basistheory.com"
9
+ },
10
+ "module": "module/module.js",
11
+ "main": "main/index.js",
12
+ "types": "types/index.d.ts",
13
+ "files": [
14
+ "*",
15
+ "!/bundle"
16
+ ],
17
+ "scripts": {
18
+ "build:dev": "yarn clean && yarn generateTypes && parcel build && npx size-limit",
19
+ "build": "node ../scripts/web-elements/prepare.js && yarn generateTypes && parcel build --no-cache",
20
+ "clean": "rimraf dist .parcel-cache",
21
+ "generateTypes": "tsc --emitDeclarationOnly",
22
+ "lint-staged": "lint-staged",
23
+ "lint:fix": "eslint --fix",
24
+ "lint": "eslint",
25
+ "size": "size-limit",
26
+ "test": "jest",
27
+ "watch": "parcel watch"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "tag": "latest"
32
+ }
33
+ }
@@ -0,0 +1,8 @@
1
+ import { BasisTheoryElements } from './types/elements';
2
+ interface BasisTheoryInitOptions {
3
+ _devMode?: boolean;
4
+ disableTelemetry?: boolean;
5
+ useSameOriginApi?: boolean;
6
+ }
7
+ declare const basistheory: (apiKey: string, options?: BasisTheoryInitOptions) => Promise<BasisTheoryElements | undefined>;
8
+ export { basistheory, BasisTheoryInitOptions };
@@ -0,0 +1,5 @@
1
+ export declare class BasisTheoryApiError extends Error {
2
+ readonly status: number;
3
+ readonly data?: unknown | undefined;
4
+ constructor(message: string, status: number, data?: unknown | undefined);
5
+ }