@basis-theory/basis-theory-js 1.76.0 → 1.77.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 +6 -0
- package/BasisTheory.js +22 -0
- package/common/BasisTheoryClient.d.ts +9 -0
- package/common/BasisTheoryClient.js +65 -0
- package/common/HttpClientError.d.ts +6 -0
- package/common/HttpClientError.js +45 -0
- package/common/index.d.ts +1 -0
- package/common/index.js +11 -2
- package/package.json +1 -1
- package/types/elements/elements.d.ts +9 -0
package/BasisTheory.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Config } from './common/BasisTheoryClient';
|
|
1
2
|
import type { BasisTheoryElements, CardElement, CardNumberElement, CardExpirationDateElement, CardVerificationCodeElement, CreateCardElementOptions, CreateCardNumberElementOptions, CreateCardExpirationDateElementOptions, CreateCardVerificationCodeElementOptions, CreateTextElementOptions, TextElement, TokenizeData as ElementsTokenizeData, Tokens as ElementsTokens } from './types/elements';
|
|
2
3
|
import type { TokenizeData } from './types/models';
|
|
3
4
|
import type { Applications, BasisTheory as IBasisTheory, BasisTheoryInit, Logs, Permissions, ReactorFormulas, Reactors, RequestOptions, Tenants, Tokens, BasisTheoryInitOptions, BasisTheoryInitOptionsWithElements, BasisTheoryInitOptionsWithoutElements, Proxies, Proxy, Sessions } from './types/sdk';
|
|
@@ -26,6 +27,11 @@ export declare class BasisTheory implements BasisTheoryInit, IBasisTheory, Basis
|
|
|
26
27
|
createElement(type: 'cardExpirationDate', options: CreateCardExpirationDateElementOptions): CardExpirationDateElement;
|
|
27
28
|
createElement(type: 'cardVerificationCode', options: CreateCardVerificationCodeElementOptions): CardVerificationCodeElement;
|
|
28
29
|
tokenize(tokens: TokenizeData & ElementsTokenizeData, options?: RequestOptions): Promise<TokenizeData>;
|
|
30
|
+
post(url: string, payload: unknown, config?: Config): Promise<unknown>;
|
|
31
|
+
put(url: string, payload: unknown, config?: Config): Promise<unknown>;
|
|
32
|
+
patch(url: string, payload: unknown, config?: Config): Promise<unknown>;
|
|
33
|
+
get(url: string, config?: Config): Promise<unknown>;
|
|
34
|
+
delete(url: string, config?: Config): Promise<unknown>;
|
|
29
35
|
private loadElements;
|
|
30
36
|
get initOptions(): Required<BasisTheoryInitOptions>;
|
|
31
37
|
get tokens(): Tokens & ElementsTokens;
|
package/BasisTheory.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.BasisTheory = void 0;
|
|
7
7
|
|
|
8
|
+
var _BasisTheoryClient = require("./common/BasisTheoryClient");
|
|
9
|
+
|
|
8
10
|
var _transactions = require("./transactions");
|
|
9
11
|
|
|
10
12
|
var _applications = require("./applications");
|
|
@@ -156,6 +158,26 @@ class BasisTheory {
|
|
|
156
158
|
return (0, _common.assertInit)(this._tokenize).tokenize(tokens, options);
|
|
157
159
|
}
|
|
158
160
|
|
|
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
|
+
|
|
159
181
|
async loadElements(apiKey) {
|
|
160
182
|
let elementsBaseUrl;
|
|
161
183
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BasisTheoryElementsInternal } from '../types/elements';
|
|
2
|
+
type Config = {
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
};
|
|
5
|
+
type MethodWithPayloads = 'post' | 'put' | 'patch';
|
|
6
|
+
type MethodWithoutPayloads = 'get' | 'delete';
|
|
7
|
+
declare const makeRequestWithElementsPayloadCheck: (elements: BasisTheoryElementsInternal | undefined, method: MethodWithPayloads, url: string, payload: unknown, config?: Config) => Promise<unknown>;
|
|
8
|
+
declare const makeRequestWithoutElementsPayloadCheck: (elements: BasisTheoryElementsInternal | undefined, method: MethodWithoutPayloads, url: string, config?: Config) => Promise<unknown>;
|
|
9
|
+
export { Config, makeRequestWithElementsPayloadCheck, makeRequestWithoutElementsPayloadCheck, };
|
|
@@ -0,0 +1,65 @@
|
|
|
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;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.HttpClientError = 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 HttpClientError extends _extendableBuiltin(Error) {
|
|
34
|
+
constructor(message, status, data, headers) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'HttpClientError';
|
|
37
|
+
this.status = status;
|
|
38
|
+
this.data = data;
|
|
39
|
+
this.headers = headers;
|
|
40
|
+
Object.setPrototypeOf(this, HttpClientError.prototype);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.HttpClientError = HttpClientError;
|
package/common/index.d.ts
CHANGED
package/common/index.js
CHANGED
|
@@ -5,7 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
BasisTheoryApiError: true,
|
|
8
|
-
BasisTheoryValidationError: true
|
|
8
|
+
BasisTheoryValidationError: true,
|
|
9
|
+
HttpClientError: true
|
|
9
10
|
};
|
|
10
11
|
Object.defineProperty(exports, "BasisTheoryApiError", {
|
|
11
12
|
enumerable: true,
|
|
@@ -19,6 +20,12 @@ Object.defineProperty(exports, "BasisTheoryValidationError", {
|
|
|
19
20
|
return _BasisTheoryValidationError.BasisTheoryValidationError;
|
|
20
21
|
}
|
|
21
22
|
});
|
|
23
|
+
Object.defineProperty(exports, "HttpClientError", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () {
|
|
26
|
+
return _HttpClientError.HttpClientError;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
22
29
|
|
|
23
30
|
var _constants = require("./constants");
|
|
24
31
|
|
|
@@ -50,4 +57,6 @@ Object.keys(_utils).forEach(function (key) {
|
|
|
50
57
|
|
|
51
58
|
var _BasisTheoryApiError = require("./BasisTheoryApiError");
|
|
52
59
|
|
|
53
|
-
var _BasisTheoryValidationError = require("./BasisTheoryValidationError");
|
|
60
|
+
var _BasisTheoryValidationError = require("./BasisTheoryValidationError");
|
|
61
|
+
|
|
62
|
+
var _HttpClientError = require("./HttpClientError");
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Config } from '../../common/BasisTheoryClient';
|
|
1
2
|
import type { ElementEventListener, EventType, Subscription, TextElementEvents, CardElementEvents, CardNumberElementEvents, CardExpirationDateElementEvents, CardVerificationCodeElementEvents } from './events';
|
|
2
3
|
import type { CreateCardElementOptions, CreateCardExpirationDateElementOptions, CreateCardVerificationCodeElementOptions, CreateTextElementOptions, UpdateCardElementOptions, CreateCardNumberElementOptions, UpdateCardNumberElementOptions, UpdateCardExpirationDateElementOptions, UpdateCardVerificationCodeElementOptions, UpdateTextElementOptions, CardElementValue, CardExpirationDateValue } from './options';
|
|
3
4
|
import type { Tokenize, Tokens, Proxy } from './services';
|
|
@@ -47,9 +48,17 @@ interface BasisTheoryElements extends Tokenize {
|
|
|
47
48
|
createElement(type: 'cardExpirationDate', options: CreateCardExpirationDateElementOptions): CardExpirationDateElement;
|
|
48
49
|
createElement(type: 'cardVerificationCode', options: CreateCardVerificationCodeElementOptions): CardVerificationCodeElement;
|
|
49
50
|
}
|
|
51
|
+
interface ElementClient {
|
|
52
|
+
post(url: string, payload: unknown, config?: Config): Promise<unknown>;
|
|
53
|
+
put(url: string, payload: unknown, config?: Config): Promise<unknown>;
|
|
54
|
+
patch(url: string, payload: unknown, config?: Config): Promise<unknown>;
|
|
55
|
+
get(url: string, config?: Config): Promise<unknown>;
|
|
56
|
+
delete(url: string, config?: Config): Promise<unknown>;
|
|
57
|
+
}
|
|
50
58
|
interface BasisTheoryElementsInternal extends BasisTheoryElements {
|
|
51
59
|
init: (apiKey: string | undefined, elementsBaseUrl: string) => Promise<BasisTheoryElements>;
|
|
52
60
|
hasElement: (payload: unknown) => boolean;
|
|
61
|
+
client: ElementClient;
|
|
53
62
|
}
|
|
54
63
|
declare global {
|
|
55
64
|
interface Window {
|