@basis-theory/basis-theory-js 1.15.0 → 1.19.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/BasisTheory.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { AtomicBanks as ElementsAtomicBanks, AtomicCards as ElementsAtomicCards, BasisTheoryElements, CardElement, CustomizableElementOptions, ElementType, TextElement, Tokenize as ElementsTokenize, Tokens as ElementsTokens } from '@basis-theory/basis-theory-elements-interfaces/elements';
2
- import type { Applications, AtomicBanks, AtomicCards, BasisTheory as IBasisTheory, BasisTheoryInit, Logs, Permissions, ReactorFormulas, Reactors, Tenants, Tokenize, Tokens } from '@basis-theory/basis-theory-elements-interfaces/sdk';
1
+ import type { AtomicBanks as ElementsAtomicBanks, AtomicCards as ElementsAtomicCards, BasisTheoryElements, CardElement, CustomizableElementOptions, ElementType, TextElement, TokenizeData as ElementsTokenizeData, Tokens as ElementsTokens } from '@basis-theory/basis-theory-elements-interfaces/elements';
2
+ import type { TokenizeData } from '@basis-theory/basis-theory-elements-interfaces/models';
3
+ import type { Applications, AtomicBanks, AtomicCards, BasisTheory as IBasisTheory, BasisTheoryInit, Logs, Permissions, ReactorFormulas, Reactors, RequestOptions, Tenants, Tokens } from '@basis-theory/basis-theory-elements-interfaces/sdk';
3
4
  import { BasisTheoryEncryptionAdapters } from './encryption/BasisTheoryEncryptionAdapters';
4
5
  import type { BasisTheoryInitOptions, BasisTheoryInitOptionsWithElements, BasisTheoryInitOptionsWithoutElements } from './types';
5
6
  export declare class BasisTheory implements BasisTheoryInit, IBasisTheory, BasisTheoryElements {
@@ -20,10 +21,10 @@ export declare class BasisTheory implements BasisTheoryInit, IBasisTheory, Basis
20
21
  init(apiKey: string, options?: BasisTheoryInitOptionsWithoutElements): Promise<IBasisTheory>;
21
22
  init(apiKey: string, options: BasisTheoryInitOptionsWithElements): Promise<IBasisTheory & BasisTheoryElements>;
22
23
  createElement(type: ElementType, options: CustomizableElementOptions): CardElement | TextElement;
24
+ tokenize(tokens: TokenizeData & ElementsTokenizeData, options?: RequestOptions): Promise<TokenizeData>;
23
25
  private loadElements;
24
26
  get initOptions(): Required<BasisTheoryInitOptions>;
25
27
  get tokens(): Tokens & ElementsTokens;
26
- get tokenize(): Tokenize & ElementsTokenize;
27
28
  /**
28
29
  * @deprecated
29
30
  */
package/BasisTheory.js CHANGED
@@ -131,6 +131,10 @@ class BasisTheory {
131
131
  return this._elements.createElement(type, options);
132
132
  }
133
133
 
134
+ tokenize(tokens, options) {
135
+ return (0, _common.assertInit)(this._tokenize).tokenize(tokens, options);
136
+ }
137
+
134
138
  async loadElements(apiKey) {
135
139
  let elementsBaseUrl;
136
140
 
@@ -155,10 +159,6 @@ class BasisTheory {
155
159
  get tokens() {
156
160
  return (0, _common.assertInit)(this._tokens);
157
161
  }
158
-
159
- get tokenize() {
160
- return (0, _common.assertInit)(this._tokenize);
161
- }
162
162
  /**
163
163
  * @deprecated
164
164
  */
package/README.md CHANGED
@@ -35,7 +35,7 @@ const bt = await new BasisTheory().init('key_N88mVGsp3sCXkykyN2EFED'); // replac
35
35
 
36
36
  ### Per-request configuration
37
37
 
38
- All of the service methods accept an optional `RequestOptions` object. This is used if you want to set a correlation ID or if you want to set a per-request X-API-KEY
38
+ All of the service methods accept an optional `RequestOptions` object. This is used if you want to set a correlation ID or if you want to set a per-request `BT-API-KEY`
39
39
 
40
40
  ```javascript
41
41
  import { v4 as uuid } from 'uuid';
@@ -1,5 +1,5 @@
1
1
  import type { ClientsBasePathMap } from '../types';
2
- declare const API_KEY_HEADER = "X-API-KEY";
2
+ declare const API_KEY_HEADER = "BT-API-KEY";
3
3
  declare const BT_TRACE_ID_HEADER = "bt-trace-id";
4
4
  declare const DEFAULT_BASE_URL: string;
5
5
  declare const DEFAULT_ELEMENTS_BASE_URL: string;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DEFAULT_ELEMENTS_BASE_URL = exports.DEFAULT_BASE_URL = exports.CLIENT_BASE_PATHS = exports.BT_TRACE_ID_HEADER = exports.API_KEY_HEADER = void 0;
7
- const API_KEY_HEADER = 'X-API-KEY';
7
+ const API_KEY_HEADER = 'BT-API-KEY';
8
8
  exports.API_KEY_HEADER = API_KEY_HEADER;
9
9
  const BT_TRACE_ID_HEADER = 'bt-trace-id';
10
10
  exports.BT_TRACE_ID_HEADER = BT_TRACE_ID_HEADER;
package/common/utils.js CHANGED
@@ -246,11 +246,12 @@ const getQueryParams = query => {
246
246
  if (keys.length) {
247
247
  const params = new URLSearchParams();
248
248
 
249
- const appendSafe = (key, value) => {
250
- const type = typeof value; // eslint-disable-next-line unicorn/no-null
249
+ const appendSafe = (key, value, isNested = false) => {
250
+ const type = typeof value;
251
+ const formattedKey = isNested ? key : (0, _snakeCase.snakeCase)(key); // eslint-disable-next-line unicorn/no-null
251
252
 
252
253
  if (value === null || ['boolean', 'number', 'string'].includes(type)) {
253
- params.append((0, _snakeCase.snakeCase)(key), value);
254
+ params.append(formattedKey, value);
254
255
  }
255
256
  };
256
257
 
@@ -261,6 +262,11 @@ const getQueryParams = query => {
261
262
  value.forEach(aValue => {
262
263
  appendSafe(String(key), aValue);
263
264
  });
265
+ } else if (value && typeof value === 'object') {
266
+ const objectKeys = Object.keys(value);
267
+ objectKeys.forEach(objectKey => {
268
+ appendSafe(`${key}.${objectKey}`, value[objectKey], true);
269
+ });
264
270
  } else {
265
271
  appendSafe(String(key), value);
266
272
  }
@@ -10,7 +10,7 @@ var _tokenize = require("../../tokenize");
10
10
  const delegateTokenize = elements => class BasisTheoryTokenizesElementsDelegate extends _tokenize.BasisTheoryTokenize {
11
11
  tokenize(payload, requestOptions) {
12
12
  if (elements !== null && elements !== void 0 && elements.hasElement(payload)) {
13
- return elements.tokenize.tokenize(payload, requestOptions);
13
+ return elements.tokenize(payload, requestOptions);
14
14
  }
15
15
 
16
16
  return super.tokenize(payload, requestOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basis-theory/basis-theory-js",
3
- "version": "1.15.0",
3
+ "version": "1.19.0",
4
4
  "repository": "https://github.com/Basis-Theory/basis-theory-js",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -15,7 +15,7 @@
15
15
  "!*.bundle.js"
16
16
  ],
17
17
  "dependencies": {
18
- "@basis-theory/basis-theory-elements-interfaces": "^2.1.1",
18
+ "@basis-theory/basis-theory-elements-interfaces": "^3.2.0",
19
19
  "axios": "^0.21.2",
20
20
  "camelcase-keys": "^6.2.2",
21
21
  "snake-case": "^3.0.4",
@@ -7,16 +7,14 @@ exports.BasisTheoryTokenize = void 0;
7
7
 
8
8
  var _common = require("../common");
9
9
 
10
- var _utils = require("../common/utils");
11
-
12
10
  var _service = require("../service");
13
11
 
14
12
  class BasisTheoryTokenize extends _service.BasisTheoryService {
15
13
  tokenize(tokens, options = {}) {
16
14
  return this.client.post('/', tokens, (0, _common.createRequestConfig)(options, {
17
- transformRequest: _utils.proxyRaw,
18
- transformResponse: _utils.proxyRaw
19
- })).then(_utils.dataExtractor);
15
+ transformRequest: _common.proxyRaw,
16
+ transformResponse: _common.proxyRaw
17
+ })).then(_common.dataExtractor);
20
18
  }
21
19
 
22
20
  }