@basis-theory/basis-theory-js 1.79.6 → 2.0.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,6 +1,6 @@
1
1
  import type { BasisTheoryElements, CardElement, CardExpirationDateElement, CardNumberElement, CardVerificationCodeElement, CreateCardElementOptions, CreateCardExpirationDateElementOptions, CreateCardNumberElementOptions, CreateCardVerificationCodeElementOptions, CreateTextElementOptions, TextElement, TokenizeData as ElementsTokenizeData, Tokens as ElementsTokens } from './types/elements';
2
2
  import type { TokenizeData } from './types/models';
3
- import type { Applications, BasisTheory as IBasisTheory, BasisTheoryInit, BasisTheoryInitOptions, BasisTheoryInitOptionsWithElements, BasisTheoryInitOptionsWithoutElements, Logs, Permissions, Proxies, Proxy, ReactorFormulas, Reactors, RequestConfig, RequestOptions, Sessions, Tenants, Tokens } from './types/sdk';
3
+ import type { Applications, BasisTheory as IBasisTheory, BasisTheoryInit, BasisTheoryInitOptions, BasisTheoryInitOptionsWithElements, BasisTheoryInitOptionsWithoutElements, HttpClient, Logs, Permissions, Proxies, Proxy, ReactorFormulas, Reactors, RequestOptions, Sessions, Tenants, Tokens } from './types/sdk';
4
4
  import { Transactions } from './types/sdk/services/transactions';
5
5
  export declare class BasisTheory implements BasisTheoryInit, IBasisTheory, BasisTheoryElements {
6
6
  private _initStatus;
@@ -26,15 +26,11 @@ export declare class BasisTheory implements BasisTheoryInit, IBasisTheory, Basis
26
26
  createElement(type: 'cardExpirationDate', options: CreateCardExpirationDateElementOptions): CardExpirationDateElement;
27
27
  createElement(type: 'cardVerificationCode', options: CreateCardVerificationCodeElementOptions): CardVerificationCodeElement;
28
28
  tokenize(tokens: TokenizeData & ElementsTokenizeData, options?: RequestOptions): Promise<TokenizeData>;
29
- post(url: string, payload: unknown, config?: RequestConfig): Promise<unknown>;
30
- put(url: string, payload: unknown, config?: RequestConfig): Promise<unknown>;
31
- patch(url: string, payload: unknown, config?: RequestConfig): Promise<unknown>;
32
- get(url: string, config?: RequestConfig): Promise<unknown>;
33
- delete(url: string, config?: RequestConfig): Promise<unknown>;
34
29
  private loadElements;
35
30
  get initOptions(): Required<BasisTheoryInitOptions>;
36
31
  get tokens(): Tokens & ElementsTokens;
37
32
  get applications(): Applications;
33
+ get client(): HttpClient | undefined;
38
34
  get tenants(): Tenants;
39
35
  get logs(): Logs;
40
36
  get reactorFormulas(): ReactorFormulas;
package/BasisTheory.js CHANGED
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.BasisTheory = void 0;
7
7
 
8
- var _BasisTheoryClient = require("./common/BasisTheoryClient");
9
-
10
8
  var _transactions = require("./transactions");
11
9
 
12
10
  var _applications = require("./applications");
@@ -158,26 +156,6 @@ class BasisTheory {
158
156
  return (0, _common.assertInit)(this._tokenize).tokenize(tokens, options);
159
157
  }
160
158
 
161
- post(url, payload, config) {
162
- return (0, _BasisTheoryClient.makeRequestWithElementsPayloadCheck)(this._elements, 'post', url, payload, config);
163
- }
164
-
165
- put(url, payload, config) {
166
- return (0, _BasisTheoryClient.makeRequestWithElementsPayloadCheck)(this._elements, 'put', url, payload, config);
167
- }
168
-
169
- patch(url, payload, config) {
170
- return (0, _BasisTheoryClient.makeRequestWithElementsPayloadCheck)(this._elements, 'patch', url, payload, config);
171
- }
172
-
173
- get(url, config) {
174
- return (0, _BasisTheoryClient.makeRequestWithoutElementsPayloadCheck)(this._elements, 'get', url, config);
175
- }
176
-
177
- delete(url, config) {
178
- return (0, _BasisTheoryClient.makeRequestWithoutElementsPayloadCheck)(this._elements, 'delete', url, config);
179
- }
180
-
181
159
  async loadElements(apiKey) {
182
160
  let elementsBaseUrl;
183
161
 
@@ -207,6 +185,18 @@ class BasisTheory {
207
185
  return (0, _common.assertInit)(this._applications);
208
186
  }
209
187
 
188
+ get client() {
189
+ if (this._elements) {
190
+ var _this$_elements;
191
+
192
+ return (_this$_elements = this._elements) === null || _this$_elements === void 0 ? void 0 : _this$_elements.client;
193
+ } // eslint-disable-next-line no-console
194
+
195
+
196
+ console.error('Elements are not initialized. Either initialize elements or use a regular HTTP client if no elements are needed.');
197
+ return undefined;
198
+ }
199
+
210
200
  get tenants() {
211
201
  return (0, _common.assertInit)(this._tenants);
212
202
  }
package/common/utils.js CHANGED
@@ -22,7 +22,6 @@ var _constants = require("./constants");
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
24
24
  const assertInit = prop => {
25
- // eslint-disable-next-line unicorn/no-null
26
25
  if (prop === null || prop === undefined) {
27
26
  throw new Error('BasisTheory has not yet been properly initialized.');
28
27
  }
@@ -313,7 +312,7 @@ const getQueryParams = (query = {}) => {
313
312
 
314
313
  const appendSafe = (key, value, isNested = false) => {
315
314
  const type = typeof value;
316
- const formattedKey = isNested ? key : (0, _snakeCase.snakeCase)(key); // eslint-disable-next-line unicorn/no-null
315
+ const formattedKey = isNested ? key : (0, _snakeCase.snakeCase)(key);
317
316
 
318
317
  if (value === null || ['boolean', 'number', 'string'].includes(type)) {
319
318
  params.append(formattedKey, value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basis-theory/basis-theory-js",
3
- "version": "1.79.6",
3
+ "version": "2.0.0",
4
4
  "repository": "https://github.com/Basis-Theory/basis-theory-js",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -43,7 +43,7 @@ type ElementWrapper<T extends BaseElement<any, any> = BaseElement<any, any>> = {
43
43
  };
44
44
  };
45
45
  type ElementValue = TextElement | CardElement | CardNumberElement | CardExpirationDateElement | CardVerificationCodeElement | ElementWrapper;
46
- interface BasisTheoryElements extends Tokenize, HttpClient {
46
+ interface BasisTheoryElements extends Tokenize {
47
47
  tokens: Tokens;
48
48
  proxy: Proxy;
49
49
  createElement(type: 'card', options?: CreateCardElementOptions): CardElement;
@@ -12,6 +12,7 @@ interface SanitizedElementOptions {
12
12
  enableCopy?: boolean;
13
13
  style?: ElementStyle;
14
14
  disabled?: boolean;
15
+ readOnly?: boolean;
15
16
  targetId?: string;
16
17
  mask?: (RegExp | string)[];
17
18
  password?: boolean;
@@ -33,7 +34,7 @@ interface TransformOption {
33
34
  interface AutoCompleteOption {
34
35
  autoComplete?: AutoCompleteValue;
35
36
  }
36
- type CustomizableElementOptions = Pick<ElementOptions, 'style' | 'disabled' | 'validateOnChange' | 'enableCopy'> & AutoCompleteOption;
37
+ type CustomizableElementOptions = Pick<ElementOptions, 'style' | 'disabled' | 'readOnly' | 'validateOnChange' | 'enableCopy'> & AutoCompleteOption;
37
38
  type ElementValueType = 'static' | 'reference';
38
39
  interface CardElementValue<T extends ElementValueType> {
39
40
  number?: T extends 'reference' ? DataElementReference : string;
@@ -4,7 +4,7 @@ type SafeCSSProperty = typeof SAFE_CSS_PROPERTIES[number];
4
4
  declare const SAFE_CSS_PROPERTIES_ALTERNATES: Partial<Record<SafeCSSProperty, string[]>>;
5
5
  declare const SAFE_CSS_PROPERTIES_WITH_ALTERNATES: string[];
6
6
  type SafeStyle = Pick<CSSProperties, SafeCSSProperty>;
7
- declare const CARD_ELEMENT_STYLE_VARIANT_SELECTORS: readonly [":hover", ":focus", "::placeholder", "::selection", ":disabled"];
7
+ declare const CARD_ELEMENT_STYLE_VARIANT_SELECTORS: readonly [":hover", ":focus", ":read-only", "::placeholder", "::selection", ":disabled"];
8
8
  type CardElementStyleVariantSelector = typeof CARD_ELEMENT_STYLE_VARIANT_SELECTORS[number];
9
9
  type CardElementStyleVariantStyle = SafeStyle & Partial<Record<CardElementStyleVariantSelector, SafeStyle>>;
10
10
  declare const CARD_ELEMENT_STYLE_VARIANTS: readonly ["base", "complete", "invalid", "empty"];
@@ -12,7 +12,7 @@ const SAFE_CSS_PROPERTIES_ALTERNATES = {
12
12
  exports.SAFE_CSS_PROPERTIES_ALTERNATES = SAFE_CSS_PROPERTIES_ALTERNATES;
13
13
  const SAFE_CSS_PROPERTIES_WITH_ALTERNATES = Object.keys(SAFE_CSS_PROPERTIES_ALTERNATES);
14
14
  exports.SAFE_CSS_PROPERTIES_WITH_ALTERNATES = SAFE_CSS_PROPERTIES_WITH_ALTERNATES;
15
- const CARD_ELEMENT_STYLE_VARIANT_SELECTORS = [':hover', ':focus', '::placeholder', '::selection', ':disabled'];
15
+ const CARD_ELEMENT_STYLE_VARIANT_SELECTORS = [':hover', ':focus', ':read-only', '::placeholder', '::selection', ':disabled'];
16
16
  exports.CARD_ELEMENT_STYLE_VARIANT_SELECTORS = CARD_ELEMENT_STYLE_VARIANT_SELECTORS;
17
17
  const CARD_ELEMENT_STYLE_VARIANTS = ['base', 'complete', 'invalid', 'empty'];
18
18
  exports.CARD_ELEMENT_STYLE_VARIANTS = CARD_ELEMENT_STYLE_VARIANTS;
@@ -1,6 +1,6 @@
1
1
  import type { BasisTheoryElements } from '../../types/elements';
2
2
  import { Transactions } from '../../types/sdk/services/transactions';
3
- import type { Tokens, Tokenize, Applications, Tenants, Logs, ReactorFormulas, Reactors, Permissions, Proxies, Proxy, Sessions, HttpClient } from './services';
3
+ import type { Applications, HttpClient, Logs, Permissions, Proxies, Proxy, ReactorFormulas, Reactors, Sessions, Tenants, Tokenize, Tokens } from './services';
4
4
  interface ApplicationInfo {
5
5
  name?: string;
6
6
  version?: string;
@@ -22,17 +22,23 @@ interface BasisTheoryInit {
22
22
  init(apiKey: string, options?: BasisTheoryInitOptionsWithoutElements): Promise<BasisTheory>;
23
23
  init(apiKey: string, options: BasisTheoryInitOptionsWithElements): Promise<BasisTheory & BasisTheoryElements>;
24
24
  }
25
- interface BasisTheory extends Tokenize, HttpClient {
26
- tokens: Tokens;
25
+ interface BasisTheory extends Tokenize {
27
26
  applications: Applications;
28
- tenants: Tenants;
27
+ /**
28
+ * @description Allows you to utilize element values in requests to a third-party API using our HTTP client service.
29
+ * @requires Before proceeding, ensure that the elements are properly initialized. Refer to the [Basis Theory Docs - Initialize elements]((https://developers.basistheory.com/docs/sdks/web/javascript/#initialization)) for more information.
30
+ * @see For details on how to use the HTTP client service, refer to [Basis Theory Docs - HTTP Client](https://developers.basistheory.com/docs/sdks/web/javascript/methods#http-client-service).
31
+ */
32
+ client?: HttpClient;
29
33
  logs: Logs;
30
- reactorFormulas: ReactorFormulas;
31
- reactors: Reactors;
32
34
  permissions: Permissions;
33
35
  proxies: Proxies;
34
36
  proxy: Proxy;
37
+ reactorFormulas: ReactorFormulas;
38
+ reactors: Reactors;
35
39
  sessions: Sessions;
40
+ tenants: Tenants;
41
+ tokens: Tokens;
36
42
  transactions: Transactions;
37
43
  }
38
44
  interface ClientUserAgent {
@@ -42,7 +48,7 @@ interface ClientUserAgent {
42
48
  runtimeVersion: string;
43
49
  application?: ApplicationInfo;
44
50
  }
45
- type BasisTheoryServices = keyof Omit<BasisTheory, keyof HttpClient>;
51
+ type BasisTheoryServices = keyof Omit<BasisTheory, 'client'>;
46
52
  type BasisTheoryServicesBasePathMap = {
47
53
  [key in BasisTheoryServices]: string;
48
54
  };
@@ -1,7 +0,0 @@
1
- import type { BasisTheoryElementsInternal } from '../types/elements';
2
- import type { RequestConfig } from '../types/sdk';
3
- type MethodWithPayloads = 'post' | 'put' | 'patch';
4
- type MethodWithoutPayloads = 'get' | 'delete';
5
- declare const makeRequestWithElementsPayloadCheck: (elements: BasisTheoryElementsInternal | undefined, method: MethodWithPayloads, url: string, payload: unknown, config?: RequestConfig) => Promise<unknown>;
6
- declare const makeRequestWithoutElementsPayloadCheck: (elements: BasisTheoryElementsInternal | undefined, method: MethodWithoutPayloads, url: string, config?: RequestConfig) => Promise<unknown>;
7
- export { makeRequestWithElementsPayloadCheck, makeRequestWithoutElementsPayloadCheck, };
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.makeRequestWithoutElementsPayloadCheck = exports.makeRequestWithElementsPayloadCheck = void 0;
7
-
8
- function _extendableBuiltin(cls) {
9
- function ExtendableBuiltin() {
10
- var instance = Reflect.construct(cls, Array.from(arguments));
11
- Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
12
- return instance;
13
- }
14
-
15
- ExtendableBuiltin.prototype = Object.create(cls.prototype, {
16
- constructor: {
17
- value: cls,
18
- enumerable: false,
19
- writable: true,
20
- configurable: true
21
- }
22
- });
23
-
24
- if (Object.setPrototypeOf) {
25
- Object.setPrototypeOf(ExtendableBuiltin, cls);
26
- } else {
27
- ExtendableBuiltin.__proto__ = cls;
28
- }
29
-
30
- return ExtendableBuiltin;
31
- }
32
-
33
- class NoElementsError extends _extendableBuiltin(Error) {
34
- constructor(message) {
35
- super(message);
36
- this.name = 'NoElementsError';
37
- }
38
-
39
- }
40
-
41
- const makeRequestWithElementsPayloadCheck = (elements, method, url, payload, config = {}) => {
42
- if (elements !== null && elements !== void 0 && elements.hasElement(payload)) {
43
- return elements.client[method](url, payload, config);
44
- }
45
-
46
- let errorMessageStart = 'Elements not initialized.';
47
-
48
- if (elements) {
49
- errorMessageStart = 'Element not found in payload.';
50
- }
51
-
52
- throw new NoElementsError(`${errorMessageStart} Use a regular HTTP client if no elements are needed.`);
53
- };
54
-
55
- exports.makeRequestWithElementsPayloadCheck = makeRequestWithElementsPayloadCheck;
56
-
57
- const makeRequestWithoutElementsPayloadCheck = (elements, method, url, config = {}) => {
58
- if (elements) {
59
- return elements.client[method](url, config);
60
- }
61
-
62
- throw new NoElementsError('Elements not initialized. Use a regular HTTP client if no elements are needed.');
63
- };
64
-
65
- exports.makeRequestWithoutElementsPayloadCheck = makeRequestWithoutElementsPayloadCheck;