@basis-theory/basis-theory-js 1.0.0 → 1.2.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.
Files changed (54) hide show
  1. package/BasisTheory.d.ts +10 -11
  2. package/BasisTheory.js +66 -35
  3. package/LICENSE +1 -1
  4. package/README.md +18 -1
  5. package/applications/BasisTheoryApplications.d.ts +2 -2
  6. package/applications/BasisTheoryApplications.js +1 -1
  7. package/applications/types.d.ts +7 -6
  8. package/atomic/BasisTheoryAtomic.js +4 -4
  9. package/atomic/banks/BasisTheoryAtomicBanks.d.ts +2 -2
  10. package/atomic/banks/BasisTheoryAtomicBanks.js +16 -16
  11. package/atomic/banks/types.d.ts +4 -3
  12. package/atomic/cards/BasisTheoryAtomicCards.d.ts +2 -2
  13. package/atomic/cards/BasisTheoryAtomicCards.js +18 -18
  14. package/atomic/cards/types.d.ts +6 -5
  15. package/atomic/types.d.ts +4 -2
  16. package/common/constants.d.ts +7 -4
  17. package/common/constants.js +19 -55
  18. package/common/elements.js +0 -1
  19. package/common/script.d.ts +3 -2
  20. package/common/script.js +2 -4
  21. package/common/utils.d.ts +17 -14
  22. package/common/utils.js +51 -22
  23. package/elements/index.d.ts +4 -4
  24. package/encryption/BasisTheoryEncryption.d.ts +1 -2
  25. package/encryption/BasisTheoryEncryption.js +5 -4
  26. package/encryption/BasisTheoryEncryptionAdapters.js +6 -4
  27. package/encryption/providers/browser.js +23 -32
  28. package/encryption/providers/node.js +11 -13
  29. package/encryption/providers/utils.d.ts +3 -2
  30. package/encryption/providers/utils.js +8 -7
  31. package/encryption/types.d.ts +3 -2
  32. package/index.d.ts +5 -3
  33. package/index.js +10 -7
  34. package/logs/BasisTheoryLogs.d.ts +1 -1
  35. package/logs/types.d.ts +3 -2
  36. package/package.json +6 -13
  37. package/permissions/BasisTheoryPermissions.js +1 -1
  38. package/permissions/types.d.ts +5 -3
  39. package/reactor-formulas/BasisTheoryReactorFormulas.d.ts +1 -1
  40. package/reactor-formulas/types.d.ts +8 -7
  41. package/reactors/BasisTheoryReactors.js +9 -7
  42. package/reactors/types.d.ts +6 -5
  43. package/service/BasisTheoryService.js +9 -3
  44. package/service/CrudBuilder.d.ts +10 -10
  45. package/service/CrudBuilder.js +15 -4
  46. package/service/types.d.ts +6 -5
  47. package/tenants/BasisTheoryTenants.d.ts +2 -2
  48. package/tenants/BasisTheoryTenants.js +2 -2
  49. package/tenants/types.d.ts +3 -2
  50. package/tokens/BasisTheoryTokens.d.ts +5 -5
  51. package/tokens/BasisTheoryTokens.js +16 -15
  52. package/tokens/types.d.ts +14 -12
  53. package/types.d.ts +14 -15
  54. package/basis-theory-js.bundle.js +0 -1
package/BasisTheory.d.ts CHANGED
@@ -1,17 +1,16 @@
1
- import { BasisTheoryAtomic } from './atomic';
2
- import type { BasisTheoryInitOptions } from './types';
3
1
  import { BasisTheoryApplications } from './applications';
4
- import { BasisTheoryTokens } from './tokens';
5
- import { BasisTheoryEncryptionAdapters } from './encryption/BasisTheoryEncryptionAdapters';
2
+ import { BasisTheoryAtomic } from './atomic';
3
+ import { BasisTheoryAtomicBanks } from './atomic/banks';
4
+ import { BasisTheoryAtomicCards } from './atomic/cards';
6
5
  import type { BasisTheoryElements } from './elements';
7
- import { BasisTheoryTenants } from './tenants';
6
+ import { BasisTheoryEncryptionAdapters } from './encryption/BasisTheoryEncryptionAdapters';
8
7
  import { BasisTheoryLogs } from './logs';
8
+ import { BasisTheoryPermissions } from './permissions';
9
9
  import { BasisTheoryReactorFormulas } from './reactor-formulas';
10
10
  import { BasisTheoryReactors } from './reactors';
11
- import { BasisTheoryAtomicBanks } from './atomic/banks';
12
- import { BasisTheoryAtomicCards } from './atomic/cards';
13
- import { BasisTheoryPermissions } from './permissions';
14
- export declare const defaultInitOptions: Required<BasisTheoryInitOptions>;
11
+ import { BasisTheoryTenants } from './tenants';
12
+ import { BasisTheoryTokens } from './tokens';
13
+ import type { BasisTheoryInitOptions } from './types';
15
14
  export declare class BasisTheory {
16
15
  private _initStatus;
17
16
  private _initOptions?;
@@ -33,8 +32,6 @@ export declare class BasisTheory {
33
32
  get tokens(): BasisTheoryTokens;
34
33
  get atomic(): BasisTheoryAtomic;
35
34
  get encryption(): BasisTheoryEncryptionAdapters;
36
- set elements(elements: BasisTheoryElements);
37
- get elements(): BasisTheoryElements;
38
35
  get applications(): BasisTheoryApplications;
39
36
  get tenants(): BasisTheoryTenants;
40
37
  get logs(): BasisTheoryLogs;
@@ -43,4 +40,6 @@ export declare class BasisTheory {
43
40
  get atomicBanks(): BasisTheoryAtomicBanks;
44
41
  get atomicCards(): BasisTheoryAtomicCards;
45
42
  get permissions(): BasisTheoryPermissions;
43
+ get elements(): BasisTheoryElements;
44
+ set elements(elements: BasisTheoryElements);
46
45
  }
package/BasisTheory.js CHANGED
@@ -3,39 +3,41 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.BasisTheory = exports.defaultInitOptions = void 0;
6
+ exports.BasisTheory = void 0;
7
7
 
8
- var _common = require("./common");
8
+ var _applications = require("./applications");
9
9
 
10
10
  var _atomic = require("./atomic");
11
11
 
12
- var _applications = require("./applications");
12
+ var _banks = require("./atomic/banks");
13
13
 
14
- var _tokens = require("./tokens");
14
+ var _cards = require("./atomic/cards");
15
15
 
16
- var _BasisTheoryEncryptionAdapters = require("./encryption/BasisTheoryEncryptionAdapters");
16
+ var _common = require("./common");
17
17
 
18
- var _tenants = require("./tenants");
18
+ var _constants = require("./common/constants");
19
+
20
+ var _BasisTheoryEncryptionAdapters = require("./encryption/BasisTheoryEncryptionAdapters");
19
21
 
20
22
  var _logs = require("./logs");
21
23
 
24
+ var _permissions = require("./permissions");
25
+
22
26
  var _reactorFormulas = require("./reactor-formulas");
23
27
 
24
28
  var _reactors = require("./reactors");
25
29
 
26
- var _banks = require("./atomic/banks");
27
-
28
- var _cards = require("./atomic/cards");
30
+ var _tenants = require("./tenants");
29
31
 
30
- var _permissions = require("./permissions");
32
+ var _tokens = require("./tokens");
31
33
 
32
34
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
33
35
 
34
36
  const defaultInitOptions = {
35
- environment: 'production',
36
- elements: false
37
+ apiBaseUrl: _constants.DEFAULT_BASE_URL,
38
+ elements: false,
39
+ elementsBaseUrl: _constants.DEFAULT_ELEMENTS_BASE_URL
37
40
  };
38
- exports.defaultInitOptions = defaultInitOptions;
39
41
 
40
42
  class BasisTheory {
41
43
  constructor() {
@@ -79,45 +81,61 @@ class BasisTheory {
79
81
  this._initOptions = Object.freeze({ ...defaultInitOptions,
80
82
  ...options
81
83
  });
84
+ let baseUrl = this._initOptions.apiBaseUrl;
85
+
86
+ try {
87
+ const baseUrlObject = new URL(this.initOptions.apiBaseUrl);
88
+
89
+ if (baseUrlObject.hostname === 'localhost') {
90
+ baseUrlObject.protocol = 'http';
91
+ } else {
92
+ baseUrlObject.protocol = 'https';
93
+ }
94
+
95
+ baseUrl = baseUrlObject.toString().replace(/\/$/u, '');
96
+ } catch {
97
+ throw new Error('Invalid format for the given API base url.');
98
+ }
99
+
82
100
  this._tokens = new _tokens.BasisTheoryTokens({
83
101
  apiKey,
84
- baseURL: _common.SERVICES.tokens[this._initOptions.environment]
102
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.tokens, baseUrl).toString()
85
103
  });
86
104
  this._atomic = new _atomic.BasisTheoryAtomic({
87
105
  apiKey,
88
- baseURL: _common.SERVICES.atomic[this._initOptions.environment]
106
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.atomic, baseUrl).toString()
89
107
  });
90
108
  this._applications = new _applications.BasisTheoryApplications({
91
109
  apiKey,
92
- baseURL: _common.SERVICES.applications[this._initOptions.environment]
110
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.applications, baseUrl).toString()
93
111
  });
94
112
  this._tenants = new _tenants.BasisTheoryTenants({
95
113
  apiKey,
96
- baseURL: _common.SERVICES.tenants[this._initOptions.environment]
114
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.tenants, baseUrl).toString()
97
115
  });
98
116
  this._logs = new _logs.BasisTheoryLogs({
99
117
  apiKey,
100
- baseURL: _common.SERVICES.logs[this._initOptions.environment]
118
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.logs, baseUrl).toString()
101
119
  });
102
120
  this._reactorFormulas = new _reactorFormulas.BasisTheoryReactorFormulas({
103
121
  apiKey,
104
- baseURL: _common.SERVICES.reactorFormulas[this._initOptions.environment]
122
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.reactorFormulas, baseUrl).toString()
105
123
  });
106
124
  this._reactors = new _reactors.BasisTheoryReactors({
107
125
  apiKey,
108
- baseURL: _common.SERVICES.reactors[this._initOptions.environment]
126
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.reactors, baseUrl).toString()
109
127
  });
110
128
  this._atomicBanks = new _banks.BasisTheoryAtomicBanks({
111
129
  apiKey,
112
- baseURL: _common.SERVICES.atomicBanks[this._initOptions.environment]
130
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.atomicBanks, baseUrl).toString()
113
131
  });
114
132
  this._atomicCards = new _cards.BasisTheoryAtomicCards({
115
133
  apiKey,
116
- baseURL: _common.SERVICES.atomicCards[this._initOptions.environment]
134
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.atomicCards, baseUrl).toString()
117
135
  });
118
136
  this._permissions = new _permissions.BasisTheoryPermissions({
119
137
  apiKey,
120
- baseURL: _common.SERVICES.permissions[this._initOptions.environment]
138
+ baseURL: new URL(_constants.CLIENT_BASE_PATHS.permissions, baseUrl).toString()
121
139
  });
122
140
  this._encryption = new _BasisTheoryEncryptionAdapters.BasisTheoryEncryptionAdapters();
123
141
 
@@ -126,19 +144,30 @@ class BasisTheory {
126
144
  }
127
145
 
128
146
  this._initStatus = 'done';
129
- } catch (e) {
147
+ } catch (error) {
130
148
  this._initStatus = 'error';
131
- throw e;
149
+ throw error;
132
150
  }
133
151
 
134
152
  return this;
135
153
  }
136
154
 
137
155
  async loadElements(apiKey) {
156
+ let elementsBaseUrl;
157
+
158
+ try {
159
+ elementsBaseUrl = new URL(this.initOptions.elementsBaseUrl);
160
+ } catch {
161
+ throw new Error('Invalid format for the given Elements base url.');
162
+ }
163
+
138
164
  const elements = await (0, _common.loadElements)();
139
- await elements.init(apiKey, this.initOptions.environment);
165
+ await elements.init(apiKey, elementsBaseUrl.toString().replace(/\/$/u, ''));
140
166
  this.elements = elements;
141
- }
167
+ } // these should be set by the init call only.
168
+
169
+ /* eslint-disable accessor-pairs */
170
+
142
171
 
143
172
  get initOptions() {
144
173
  return (0, _common.assertInit)(this._initOptions);
@@ -156,14 +185,6 @@ class BasisTheory {
156
185
  return (0, _common.assertInit)(this._encryption);
157
186
  }
158
187
 
159
- set elements(elements) {
160
- this._elements = elements;
161
- }
162
-
163
- get elements() {
164
- return (0, _common.assertInit)(this._elements);
165
- }
166
-
167
188
  get applications() {
168
189
  return (0, _common.assertInit)(this._applications);
169
190
  }
@@ -195,6 +216,16 @@ class BasisTheory {
195
216
  get permissions() {
196
217
  return (0, _common.assertInit)(this._permissions);
197
218
  }
219
+ /* eslint-enable accessor-pairs */
220
+
221
+
222
+ get elements() {
223
+ return (0, _common.assertInit)(this._elements);
224
+ }
225
+
226
+ set elements(elements) {
227
+ this._elements = elements;
228
+ }
198
229
 
199
230
  }
200
231
 
package/LICENSE CHANGED
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright 2011 Jayme Davis
190
+ Copyright 2021 Basis Theory
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -1,4 +1,9 @@
1
- # BasisTheory JS SDK (aka BasisTheory.js)
1
+ # Basis Theory JS SDK (aka BasisTheory.js)
2
+
3
+ [![Version](https://img.shields.io/npm/v/@basis-theory/basis-theory-js.svg)](https://www.npmjs.org/package/@basis-theory/basis-theory-js)
4
+ [![Verify](https://github.com/Basis-Theory/basis-theory-js/actions/workflows/release.yml/badge.svg)](https://github.com/Basis-Theory/basis-theory-js/actions/workflows/release.yml)
5
+
6
+ The [Basis Theory](https://basistheory.com/) JS SDK
2
7
 
3
8
  ## Installation
4
9
 
@@ -44,6 +49,18 @@ await bt.applications.list(
44
49
  );
45
50
  ```
46
51
 
52
+ ### Setting a custom API Url
53
+
54
+ You can set a custom API Url to be used across all clients when creating a new SDK instance.
55
+
56
+ ```javascript
57
+ import { BasisTheory } from '@basis-theory/basis-theory-js';
58
+
59
+ const bt = await new BasisTheory().init('key_N88mVGsp3sCXkykyN2EFED', {
60
+ apiBaseUrl: 'https://api.somedomain.com',
61
+ }); // replace with your application key and api base URL.
62
+ ```
63
+
47
64
  ## Development
48
65
 
49
66
  The provided scripts with the SDK will check for all dependencies, start docker, build the solution, and run all tests.
@@ -1,7 +1,7 @@
1
- import type { Application, ApplicationQuery, CreateApplicationModel } from './types';
2
1
  import { RequestOptions } from '../service';
2
+ import type { Application, ApplicationQuery, CreateApplicationModel } from './types';
3
3
  export declare const BasisTheoryApplications: {
4
- new (options: import("../service").BasisTheoryServiceOptions): {
4
+ new (options: import("../service/types").BasisTheoryServiceOptions): {
5
5
  /**
6
6
  * @deprecated use {@link retrieveByKey} instead
7
7
  */
@@ -15,7 +15,7 @@ const BasisTheoryApplications = new _CrudBuilder.CrudBuilder(class BasisTheoryAp
15
15
  /**
16
16
  * @deprecated use {@link retrieveByKey} instead
17
17
  */
18
- async getApplicationByKey() {
18
+ getApplicationByKey() {
19
19
  return this.retrieveByKey();
20
20
  }
21
21
 
@@ -1,7 +1,7 @@
1
1
  import type { PaginatedQuery } from '../service';
2
- export declare const APPLICATION_TYPES: readonly ["server_to_server", "public", "elements", "management"];
3
- export declare type ApplicationType = typeof APPLICATION_TYPES[number];
4
- export interface Application {
2
+ declare const APPLICATION_TYPES: readonly ["server_to_server", "public", "elements", "management"];
3
+ declare type ApplicationType = typeof APPLICATION_TYPES[number];
4
+ interface Application {
5
5
  id: string;
6
6
  tenantId: string;
7
7
  name: string;
@@ -11,8 +11,9 @@ export interface Application {
11
11
  createdAt: string;
12
12
  modifiedAt: string;
13
13
  }
14
- export declare type CreateApplicationModel = Pick<Application, 'name' | 'type'> & Partial<Pick<Application, 'permissions'>>;
15
- export declare type UpdateApplicationModel = Partial<Pick<Application, 'name' | 'permissions'>>;
16
- export interface ApplicationQuery extends PaginatedQuery {
14
+ declare type CreateApplicationModel = Pick<Application, 'name' | 'type'> & Partial<Pick<Application, 'permissions'>>;
15
+ declare type UpdateApplicationModel = Partial<Pick<Application, 'name' | 'permissions'>>;
16
+ interface ApplicationQuery extends PaginatedQuery {
17
17
  id?: string | string[];
18
18
  }
19
+ export { APPLICATION_TYPES, ApplicationType, Application, CreateApplicationModel, UpdateApplicationModel, ApplicationQuery, };
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.BasisTheoryAtomic = void 0;
7
7
 
8
- var _service = require("../service");
9
-
10
8
  var _common = require("../common");
11
9
 
10
+ var _service = require("../service");
11
+
12
12
  /**
13
13
  * @deprecated use {@link BasisTheoryAtomicBanks} and {@link BasisTheoryAtomicCards} instead
14
14
  */
@@ -16,7 +16,7 @@ class BasisTheoryAtomic extends _service.BasisTheoryService {
16
16
  /**
17
17
  * @deprecated use {@link BasisTheoryAtomicCards.create} instead
18
18
  */
19
- async storeCreditCard(model) {
19
+ storeCreditCard(model) {
20
20
  return this.client.post('/cards', model).then(_common.dataExtractor);
21
21
  }
22
22
  /**
@@ -24,7 +24,7 @@ class BasisTheoryAtomic extends _service.BasisTheoryService {
24
24
  */
25
25
 
26
26
 
27
- async storeBank(model) {
27
+ storeBank(model) {
28
28
  return this.client.post('/banks', model).then(_common.dataExtractor);
29
29
  }
30
30
 
@@ -1,7 +1,7 @@
1
- import type { AtomicBank } from './types';
2
1
  import type { BasisTheoryServiceOptions, PaginatedQuery, RequestOptions } from '../../service';
3
- import type { ReactRequest } from '../types';
4
2
  import type { Token } from '../../tokens';
3
+ import type { ReactRequest } from '../types';
4
+ import type { AtomicBank } from './types';
5
5
  export declare const BasisTheoryAtomicBanks: {
6
6
  new (options: BasisTheoryServiceOptions): {
7
7
  retrieveDecrypted(id: string, options?: RequestOptions | undefined): Promise<AtomicBank>;
@@ -13,30 +13,30 @@ var _CrudBuilder = require("../../service/CrudBuilder");
13
13
 
14
14
  const BasisTheoryAtomicBanks = new _CrudBuilder.CrudBuilder(class BasisTheoryAtomicBanks extends _service.BasisTheoryService {
15
15
  constructor(options) {
16
- super({
17
- transformRequest: _common.transformAtomicRequestSnakeCase,
18
- transformResponse: _common.transformAtomicResponseCamelCase,
19
- ...options
20
- });
16
+ const _options = { ...options
17
+ }; // eslint-disable-next-line unicorn/prefer-spread
18
+
19
+ _options.transformRequest = [].concat(_common.transformAtomicRequestSnakeCase, options.transformRequest || []); // eslint-disable-next-line unicorn/prefer-spread
20
+
21
+ _options.transformResponse = [].concat(_common.transformAtomicResponseCamelCase, options.transformResponse || []);
22
+ super(_options);
21
23
  }
22
24
 
23
- async retrieveDecrypted(id, options) {
25
+ retrieveDecrypted(id, options) {
24
26
  return this.client.get(`/${id}/decrypt`, (0, _common.createRequestConfig)(options)).then(_common.dataExtractor);
25
27
  }
26
28
 
27
- async react(id, request, options) {
28
- return this.client.post(`/${id}/react`, request, {
29
+ react(id, request, options) {
30
+ return this.client.post(`/${id}/react`, request, (0, _common.createRequestConfig)(options, {
29
31
  transformRequest: _common.transformAtomicReactionRequestSnakeCase,
30
- transformResponse: _common.transformTokenResponseCamelCase,
31
- ...(0, _common.createRequestConfig)(options)
32
- }).then(_common.dataExtractor);
32
+ transformResponse: _common.transformTokenResponseCamelCase
33
+ })).then(_common.dataExtractor);
33
34
  }
34
35
 
35
- async retrieveReaction(atomicBankId, reactionTokenId, options) {
36
- return this.client.get(`/${atomicBankId}/reaction/${reactionTokenId}`, {
37
- transformResponse: _common.transformTokenResponseCamelCase,
38
- ...(0, _common.createRequestConfig)(options)
39
- }).then(_common.dataExtractor);
36
+ retrieveReaction(atomicBankId, reactionTokenId, options) {
37
+ return this.client.get(`/${atomicBankId}/reaction/${reactionTokenId}`, (0, _common.createRequestConfig)(options, {
38
+ transformResponse: _common.transformTokenResponseCamelCase
39
+ })).then(_common.dataExtractor);
40
40
  }
41
41
 
42
42
  }).create().retrieve().delete().list().build();
@@ -1,9 +1,10 @@
1
1
  import type { Atomic } from '../types';
2
- export interface Bank {
2
+ interface Bank {
3
3
  routingNumber: string;
4
4
  accountNumber: string;
5
5
  }
6
- export interface AtomicBank extends Atomic {
6
+ interface AtomicBank extends Atomic {
7
7
  bank: Bank;
8
8
  }
9
- export declare type CreateAtomicBankModel = Pick<AtomicBank, 'bank' | 'metadata'>;
9
+ declare type CreateAtomicBankModel = Pick<AtomicBank, 'bank' | 'metadata'>;
10
+ export type { Bank, AtomicBank, CreateAtomicBankModel };
@@ -1,7 +1,7 @@
1
- import type { AtomicCard } from './types';
2
1
  import type { BasisTheoryServiceOptions, PaginatedQuery, RequestOptions } from '../../service';
3
- import type { ReactRequest } from '../types';
4
2
  import type { Token } from '../../tokens';
3
+ import type { ReactRequest } from '../types';
4
+ import type { AtomicCard } from './types';
5
5
  export declare const BasisTheoryAtomicCards: {
6
6
  new (options: BasisTheoryServiceOptions): {
7
7
  retrieveDecrypted(id: string, options?: RequestOptions | undefined): Promise<AtomicCard>;
@@ -5,40 +5,40 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.BasisTheoryAtomicCards = void 0;
7
7
 
8
- var _utils = require("./../../common/utils");
9
-
10
8
  var _common = require("../../common");
11
9
 
10
+ var _utils = require("../../common/utils");
11
+
12
12
  var _service = require("../../service");
13
13
 
14
14
  var _CrudBuilder = require("../../service/CrudBuilder");
15
15
 
16
16
  const BasisTheoryAtomicCards = new _CrudBuilder.CrudBuilder(class BasisTheoryAtomicCards extends _service.BasisTheoryService {
17
17
  constructor(options) {
18
- super({
19
- transformRequest: _utils.transformAtomicRequestSnakeCase,
20
- transformResponse: _utils.transformAtomicResponseCamelCase,
21
- ...options
22
- });
18
+ const _options = { ...options
19
+ }; // eslint-disable-next-line unicorn/prefer-spread
20
+
21
+ _options.transformRequest = [].concat(_utils.transformAtomicRequestSnakeCase, options.transformRequest || []); // eslint-disable-next-line unicorn/prefer-spread
22
+
23
+ _options.transformResponse = [].concat(_utils.transformAtomicResponseCamelCase, options.transformResponse || []);
24
+ super(_options);
23
25
  }
24
26
 
25
- async retrieveDecrypted(id, options) {
27
+ retrieveDecrypted(id, options) {
26
28
  return this.client.get(`/${id}/decrypt`, (0, _common.createRequestConfig)(options)).then(_common.dataExtractor);
27
29
  }
28
30
 
29
- async react(id, request, options) {
30
- return this.client.post(`/${id}/react`, request, {
31
+ react(id, request, options) {
32
+ return this.client.post(`/${id}/react`, request, (0, _common.createRequestConfig)(options, {
31
33
  transformRequest: _common.transformAtomicReactionRequestSnakeCase,
32
- transformResponse: _common.transformTokenResponseCamelCase,
33
- ...(0, _common.createRequestConfig)(options)
34
- }).then(_common.dataExtractor);
34
+ transformResponse: _common.transformTokenResponseCamelCase
35
+ })).then(_common.dataExtractor);
35
36
  }
36
37
 
37
- async retrieveReaction(atomicCardId, reactionTokenId, options) {
38
- return this.client.get(`/${atomicCardId}/reaction/${reactionTokenId}`, {
39
- transformResponse: _common.transformTokenResponseCamelCase,
40
- ...(0, _common.createRequestConfig)(options)
41
- }).then(_common.dataExtractor);
38
+ retrieveReaction(atomicCardId, reactionTokenId, options) {
39
+ return this.client.get(`/${atomicCardId}/reaction/${reactionTokenId}`, (0, _common.createRequestConfig)(options, {
40
+ transformResponse: _common.transformTokenResponseCamelCase
41
+ })).then(_common.dataExtractor);
42
42
  }
43
43
 
44
44
  }).create().retrieve().delete().list().build();
@@ -1,21 +1,21 @@
1
1
  import type { Atomic } from '../types';
2
- export interface AtomicCard extends Atomic {
2
+ interface AtomicCard extends Atomic {
3
3
  card: Card;
4
4
  billingDetails?: BillingDetails;
5
5
  }
6
- export interface Card {
6
+ interface Card {
7
7
  number: string;
8
8
  expirationMonth: number;
9
9
  expirationYear: number;
10
10
  cvc?: string;
11
11
  }
12
- export interface BillingDetails {
12
+ interface BillingDetails {
13
13
  name?: string;
14
14
  email?: string;
15
15
  phone?: string;
16
16
  address?: Address;
17
17
  }
18
- export interface Address {
18
+ interface Address {
19
19
  line1?: string;
20
20
  line2?: string;
21
21
  city?: string;
@@ -23,4 +23,5 @@ export interface Address {
23
23
  postalCode?: string;
24
24
  country?: string;
25
25
  }
26
- export declare type CreateAtomicCardModel = Pick<AtomicCard, 'card' | 'billingDetails' | 'metadata'>;
26
+ declare type CreateAtomicCardModel = Pick<AtomicCard, 'card' | 'billingDetails' | 'metadata'>;
27
+ export type { AtomicCard, Card, BillingDetails, Address, CreateAtomicCardModel, };
package/atomic/types.d.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  import type { TokenType } from '../tokens';
2
- export interface Atomic {
2
+ interface Atomic {
3
3
  id: string;
4
4
  tenantId: string;
5
5
  type: TokenType;
6
+ fingerprint: string;
6
7
  metadata?: Record<string, string>;
7
8
  createdBy: string;
8
9
  createdAt: string;
9
10
  }
10
- export interface ReactRequest {
11
+ interface ReactRequest {
11
12
  reactorId: string;
12
13
  requestParameters?: Record<string, unknown>;
13
14
  metadata?: Record<string, string>;
14
15
  }
16
+ export type { Atomic, ReactRequest };
@@ -1,4 +1,7 @@
1
- import { ServicesMap } from '../types';
2
- export declare const SERVICES: ServicesMap;
3
- export declare const API_KEY_HEADER = "X-API-KEY";
4
- export declare const BT_TRACE_ID_HEADER = "bt-trace-id";
1
+ import type { ClientsBasePathMap } from '../types';
2
+ declare const API_KEY_HEADER = "X-API-KEY";
3
+ declare const BT_TRACE_ID_HEADER = "bt-trace-id";
4
+ declare const DEFAULT_BASE_URL: string;
5
+ declare const DEFAULT_ELEMENTS_BASE_URL: string;
6
+ declare const CLIENT_BASE_PATHS: ClientsBasePathMap;
7
+ export { API_KEY_HEADER, BT_TRACE_ID_HEADER, DEFAULT_BASE_URL, DEFAULT_ELEMENTS_BASE_URL, CLIENT_BASE_PATHS, };
@@ -3,61 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.BT_TRACE_ID_HEADER = exports.API_KEY_HEADER = exports.SERVICES = void 0;
7
- const SERVICES = {
8
- tokens: {
9
- production: `https://${"api.basistheory.com"}/tokens`,
10
- sandbox: `https://${"api-dev.basistheory.com"}/tokens`,
11
- local: `http://${"localhost:3333"}/tokens`
12
- },
13
- atomic: {
14
- production: `https://${"api.basistheory.com"}/atomic`,
15
- sandbox: `https://${"api-dev.basistheory.com"}/atomic`,
16
- local: `http://${"localhost:3333"}/atomic`
17
- },
18
- applications: {
19
- production: `https://${"api.basistheory.com"}/applications`,
20
- sandbox: `https://${"api-dev.basistheory.com"}/applications`,
21
- local: `http://${"localhost:3333"}/applications`
22
- },
23
- tenants: {
24
- production: `https://${"api.basistheory.com"}/tenants/self`,
25
- sandbox: `https://${"api-dev.basistheory.com"}/tenants/self`,
26
- local: `http://${"localhost:3333"}/tenants/self`
27
- },
28
- logs: {
29
- production: `https://${"api.basistheory.com"}/logs`,
30
- sandbox: `https://${"api-dev.basistheory.com"}/logs`,
31
- local: `http://${"localhost:3333"}/logs`
32
- },
33
- reactorFormulas: {
34
- production: `https://${"api.basistheory.com"}/reactor-formulas`,
35
- sandbox: `https://${"api-dev.basistheory.com"}/reactor-formulas`,
36
- local: `http://${"localhost:3333"}/reactor-formulas`
37
- },
38
- reactors: {
39
- production: `https://${"api.basistheory.com"}/reactors`,
40
- sandbox: `https://${"api-dev.basistheory.com"}/reactors`,
41
- local: `http://${"localhost:3333"}/reactors`
42
- },
43
- atomicBanks: {
44
- production: `https://${"api.basistheory.com"}/atomic/banks`,
45
- sandbox: `https://${"api-dev.basistheory.com"}/atomic/banks`,
46
- local: `http://${"localhost:3333"}/atomic/banks`
47
- },
48
- atomicCards: {
49
- production: `https://${"api.basistheory.com"}/atomic/cards`,
50
- sandbox: `https://${"api-dev.basistheory.com"}/atomic/cards`,
51
- local: `http://${"localhost:3333"}/atomic/cards`
52
- },
53
- permissions: {
54
- production: `https://${"api.basistheory.com"}/permissions`,
55
- sandbox: `https://${"api-dev.basistheory.com"}/permissions`,
56
- local: `http://${"localhost:3333"}/permissions`
57
- }
58
- };
59
- exports.SERVICES = SERVICES;
6
+ exports.CLIENT_BASE_PATHS = exports.DEFAULT_ELEMENTS_BASE_URL = exports.DEFAULT_BASE_URL = exports.BT_TRACE_ID_HEADER = exports.API_KEY_HEADER = void 0;
60
7
  const API_KEY_HEADER = 'X-API-KEY';
61
8
  exports.API_KEY_HEADER = API_KEY_HEADER;
62
9
  const BT_TRACE_ID_HEADER = 'bt-trace-id';
63
- exports.BT_TRACE_ID_HEADER = BT_TRACE_ID_HEADER;
10
+ exports.BT_TRACE_ID_HEADER = BT_TRACE_ID_HEADER;
11
+ const DEFAULT_BASE_URL = `https://${"api.basistheory.com"}`;
12
+ exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
13
+ const DEFAULT_ELEMENTS_BASE_URL = `https://${"elements.basistheory.com"}`;
14
+ exports.DEFAULT_ELEMENTS_BASE_URL = DEFAULT_ELEMENTS_BASE_URL;
15
+ const CLIENT_BASE_PATHS = {
16
+ tokens: 'tokens',
17
+ atomic: 'atomic',
18
+ applications: 'applications',
19
+ tenants: 'tenants/self',
20
+ logs: 'logs',
21
+ reactorFormulas: 'reactor-formulas',
22
+ reactors: 'reactors',
23
+ atomicBanks: 'atomic/banks',
24
+ atomicCards: 'atomic/cards',
25
+ permissions: 'permissions'
26
+ };
27
+ exports.CLIENT_BASE_PATHS = CLIENT_BASE_PATHS;
@@ -18,7 +18,6 @@ const loadElements = () => {
18
18
  }
19
19
 
20
20
  if (window.BasisTheoryElements) {
21
- // TODO print console message
22
21
  resolve(window.BasisTheoryElements);
23
22
  return;
24
23
  }
@@ -1,2 +1,3 @@
1
- export declare const findScript: (url: string) => HTMLScriptElement | null;
2
- export declare const injectScript: (url: string) => HTMLScriptElement;
1
+ declare const findScript: (url: string) => HTMLScriptElement | null;
2
+ declare const injectScript: (url: string) => HTMLScriptElement;
3
+ export { findScript, injectScript };