@basis-theory/basis-theory-js 1.27.0 → 1.30.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 +5 -2
- package/BasisTheory.js +1 -4
- package/elements/constants.d.ts +2 -1
- package/elements/constants.js +4 -2
- package/package.json +1 -1
- package/types/elements/elements.d.ts +19 -7
- package/types/elements/events.d.ts +11 -4
- package/types/elements/options.d.ts +11 -2
- package/types/elements/options.js +1 -1
- package/types/elements/services/tokenize.d.ts +2 -2
- package/types/elements/services/tokens.d.ts +2 -2
- package/types/elements/shared.d.ts +2 -1
package/BasisTheory.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AtomicBanks as ElementsAtomicBanks, AtomicCards as ElementsAtomicCards, BasisTheoryElements, CardElement,
|
|
1
|
+
import type { AtomicBanks as ElementsAtomicBanks, AtomicCards as ElementsAtomicCards, BasisTheoryElements, CardElement, CardExpirationDateElement, CardVerificationCodeElement, CreateCardElementOptions, CreateCardExpirationDateElementOptions, CreateCardVerificationCodeElementOptions, CreateTextElementOptions, TextElement, TokenizeData as ElementsTokenizeData, Tokens as ElementsTokens } from '@/types/elements';
|
|
2
2
|
import type { TokenizeData } from '@/types/models';
|
|
3
3
|
import type { Applications, AtomicBanks, AtomicCards, BasisTheory as IBasisTheory, BasisTheoryInit, Logs, Permissions, ReactorFormulas, Reactors, RequestOptions, Tenants, Tokens, BasisTheoryInitOptions, BasisTheoryInitOptionsWithElements, BasisTheoryInitOptionsWithoutElements } from '@/types/sdk';
|
|
4
4
|
export declare class BasisTheory implements BasisTheoryInit, IBasisTheory, BasisTheoryElements {
|
|
@@ -17,7 +17,10 @@ export declare class BasisTheory implements BasisTheoryInit, IBasisTheory, Basis
|
|
|
17
17
|
private _permissions?;
|
|
18
18
|
init(apiKey: string, options?: BasisTheoryInitOptionsWithoutElements): Promise<IBasisTheory>;
|
|
19
19
|
init(apiKey: string, options: BasisTheoryInitOptionsWithElements): Promise<IBasisTheory & BasisTheoryElements>;
|
|
20
|
-
createElement(type:
|
|
20
|
+
createElement(type: 'card', options?: CreateCardElementOptions): CardElement;
|
|
21
|
+
createElement(type: 'text', options: CreateTextElementOptions): TextElement;
|
|
22
|
+
createElement(type: 'cardExpirationDate', options: CreateCardExpirationDateElementOptions): CardExpirationDateElement;
|
|
23
|
+
createElement(type: 'cardVerificationCode', options: CreateCardVerificationCodeElementOptions): CardVerificationCodeElement;
|
|
21
24
|
tokenize(tokens: TokenizeData & ElementsTokenizeData, options?: RequestOptions): Promise<TokenizeData>;
|
|
22
25
|
private loadElements;
|
|
23
26
|
get initOptions(): Required<BasisTheoryInitOptions>;
|
package/BasisTheory.js
CHANGED
|
@@ -131,10 +131,7 @@ class BasisTheory {
|
|
|
131
131
|
createElement(type, options) {
|
|
132
132
|
if (!this._elements) {
|
|
133
133
|
throw new Error(_constants.ELEMENTS_INIT_ERROR_MESSAGE);
|
|
134
|
-
}
|
|
135
|
-
// the underlying elements function called will be the same, no matter the
|
|
136
|
-
// element type
|
|
137
|
-
|
|
134
|
+
}
|
|
138
135
|
|
|
139
136
|
return this._elements.createElement(type, options);
|
|
140
137
|
}
|
package/elements/constants.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ declare const ELEMENTS_INIT_ERROR_MESSAGE = "BasisTheory Elements was not proper
|
|
|
2
2
|
declare const ELEMENTS_NOM_DOM_ERROR_MESSAGE = "Tried to load BasisTheoryElements in a non-DOM environment.";
|
|
3
3
|
declare const ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = "BasisTheoryElements did not load properly.";
|
|
4
4
|
declare const ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = "There was an unknown error when loading BasisTheoryElements";
|
|
5
|
-
|
|
5
|
+
declare const CARD_BRANDS: readonly ["visa", "mastercard", "american-express", "discover", "diners-club", "jcb", "unionpay", "maestro", "elo", "hiper", "hipercard", "mir", "unknown"];
|
|
6
|
+
export { ELEMENTS_INIT_ERROR_MESSAGE, ELEMENTS_NOM_DOM_ERROR_MESSAGE, ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE, ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE, CARD_BRANDS, };
|
package/elements/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = exports.ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = exports.ELEMENTS_NOM_DOM_ERROR_MESSAGE = exports.ELEMENTS_INIT_ERROR_MESSAGE = void 0;
|
|
6
|
+
exports.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = exports.ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = exports.ELEMENTS_NOM_DOM_ERROR_MESSAGE = exports.ELEMENTS_INIT_ERROR_MESSAGE = exports.CARD_BRANDS = void 0;
|
|
7
7
|
const ELEMENTS_INIT_ERROR_MESSAGE = 'BasisTheory Elements was not properly initialized.';
|
|
8
8
|
exports.ELEMENTS_INIT_ERROR_MESSAGE = ELEMENTS_INIT_ERROR_MESSAGE;
|
|
9
9
|
const ELEMENTS_NOM_DOM_ERROR_MESSAGE = 'Tried to load BasisTheoryElements in a non-DOM environment.';
|
|
@@ -11,4 +11,6 @@ exports.ELEMENTS_NOM_DOM_ERROR_MESSAGE = ELEMENTS_NOM_DOM_ERROR_MESSAGE;
|
|
|
11
11
|
const ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = 'BasisTheoryElements did not load properly.';
|
|
12
12
|
exports.ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE;
|
|
13
13
|
const ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = 'There was an unknown error when loading BasisTheoryElements';
|
|
14
|
-
exports.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE;
|
|
14
|
+
exports.ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE;
|
|
15
|
+
const CARD_BRANDS = ['visa', 'mastercard', 'american-express', 'discover', 'diners-club', 'jcb', 'unionpay', 'maestro', 'elo', 'hiper', 'hipercard', 'mir', 'unknown'];
|
|
16
|
+
exports.CARD_BRANDS = CARD_BRANDS;
|
package/package.json
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import type { ElementEventListener, EventType, Subscription } from './events';
|
|
2
|
-
import type { CreateCardElementOptions, CreateTextElementOptions, UpdateCardElementOptions, UpdateTextElementOptions } from './options';
|
|
1
|
+
import type { ElementEventListener, EventType, Subscription, TextElementEvents, CardElementEvents, CardExpirationDateElementEvents, CardVerificationCodeElementEvents } from './events';
|
|
2
|
+
import type { CreateCardElementOptions, CreateCardExpirationDateElementOptions, CreateCardVerificationCodeElementOptions, CreateTextElementOptions, UpdateCardElementOptions, UpdateCardExpirationDateElementOptions, UpdateCardVerificationCodeElementOptions, UpdateTextElementOptions } from './options';
|
|
3
3
|
import type { AtomicBanks, AtomicCards, Tokenize, Tokens } from './services';
|
|
4
|
-
interface BaseElement<UpdateOptions> {
|
|
4
|
+
interface BaseElement<UpdateOptions, ElementEvents> {
|
|
5
5
|
readonly mounted: boolean;
|
|
6
6
|
mount(selector: string): Promise<void>;
|
|
7
7
|
update(options: UpdateOptions): Promise<void>;
|
|
8
8
|
clear(): void;
|
|
9
9
|
unmount(): void;
|
|
10
|
-
on<T extends EventType>(eventType: T, listener: ElementEventListener<T>): Subscription;
|
|
10
|
+
on<T extends EventType>(eventType: T, listener: ElementEventListener<ElementEvents, T>): Subscription;
|
|
11
11
|
}
|
|
12
|
-
declare type CardElement = BaseElement<UpdateCardElementOptions>;
|
|
13
|
-
declare type TextElement = BaseElement<UpdateTextElementOptions>;
|
|
12
|
+
declare type CardElement = BaseElement<UpdateCardElementOptions, CardElementEvents>;
|
|
13
|
+
declare type TextElement = BaseElement<UpdateTextElementOptions, TextElementEvents>;
|
|
14
|
+
declare type CardExpirationDateElement = BaseElement<UpdateCardExpirationDateElementOptions, CardExpirationDateElementEvents> & {
|
|
15
|
+
month(): ElementWrapper<CardExpirationDateElement>;
|
|
16
|
+
year(): ElementWrapper<CardExpirationDateElement>;
|
|
17
|
+
};
|
|
18
|
+
declare type CardVerificationCodeElement = BaseElement<UpdateCardVerificationCodeElementOptions, CardVerificationCodeElementEvents>;
|
|
19
|
+
declare type ElementWrapper<T extends BaseElement<any, any> = BaseElement<any, any>> = {
|
|
20
|
+
element: T;
|
|
21
|
+
method?: string;
|
|
22
|
+
};
|
|
23
|
+
declare type ElementValue = TextElement | CardElement | CardExpirationDateElement | CardVerificationCodeElement | ElementWrapper;
|
|
14
24
|
interface BasisTheoryElements extends Tokenize {
|
|
15
25
|
/**
|
|
16
26
|
* @deprecated use {@link tokens} or {@link tokenize}
|
|
@@ -23,6 +33,8 @@ interface BasisTheoryElements extends Tokenize {
|
|
|
23
33
|
tokens: Tokens;
|
|
24
34
|
createElement(type: 'card', options?: CreateCardElementOptions): CardElement;
|
|
25
35
|
createElement(type: 'text', options: CreateTextElementOptions): TextElement;
|
|
36
|
+
createElement(type: 'cardExpirationDate', options: CreateCardExpirationDateElementOptions): CardExpirationDateElement;
|
|
37
|
+
createElement(type: 'cardVerificationCode', options: CreateCardVerificationCodeElementOptions): CardVerificationCodeElement;
|
|
26
38
|
}
|
|
27
39
|
interface BasisTheoryElementsInternal extends BasisTheoryElements {
|
|
28
40
|
init: (apiKey: string, elementsBaseUrl: string) => Promise<BasisTheoryElements>;
|
|
@@ -33,4 +45,4 @@ declare global {
|
|
|
33
45
|
BasisTheoryElements?: BasisTheoryElementsInternal;
|
|
34
46
|
}
|
|
35
47
|
}
|
|
36
|
-
export type { BaseElement, CardElement, TextElement, BasisTheoryElements, BasisTheoryElementsInternal, };
|
|
48
|
+
export type { BaseElement, CardElement, TextElement, CardExpirationDateElement, CardVerificationCodeElement, ElementWrapper, ElementValue, BasisTheoryElements, BasisTheoryElementsInternal, };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FieldError, ListenableKey, Targeted } from './shared';
|
|
1
|
+
import type { Brand, FieldError, ListenableKey, Targeted } from './shared';
|
|
2
2
|
declare type EventType = 'ready' | 'change' | 'focus' | 'blur' | 'keydown';
|
|
3
3
|
interface BaseEvent<T extends EventType> {
|
|
4
4
|
type: T;
|
|
@@ -9,20 +9,27 @@ declare type ChangeEvent = BaseEvent<'change'> & {
|
|
|
9
9
|
complete: boolean;
|
|
10
10
|
errors?: FieldError[];
|
|
11
11
|
};
|
|
12
|
+
declare type CardChangeEvent = ChangeEvent & {
|
|
13
|
+
cardBrand: Brand;
|
|
14
|
+
};
|
|
12
15
|
declare type InputFocusEvent = BaseEvent<'focus'> & Targeted;
|
|
13
16
|
declare type InputBlurEvent = BaseEvent<'blur'> & Targeted;
|
|
14
17
|
declare type InputKeydownEvent = BaseEvent<'keydown'> & Targeted & {
|
|
15
18
|
key: ListenableKey;
|
|
16
19
|
} & Pick<KeyboardEvent, 'altKey' | 'ctrlKey' | 'shiftKey' | 'metaKey'>;
|
|
17
|
-
declare type
|
|
20
|
+
declare type BaseElementEvents = ReadyEvent | InputFocusEvent | InputBlurEvent | InputKeydownEvent;
|
|
21
|
+
declare type TextElementEvents = BaseElementEvents | ChangeEvent;
|
|
22
|
+
declare type CardElementEvents = BaseElementEvents | CardChangeEvent;
|
|
23
|
+
declare type CardExpirationDateElementEvents = BaseElementEvents | ChangeEvent;
|
|
24
|
+
declare type CardVerificationCodeElementEvents = BaseElementEvents | ChangeEvent;
|
|
18
25
|
/**
|
|
19
26
|
* Utility type that helps find a Union type based on a `type` property
|
|
20
27
|
*/
|
|
21
28
|
declare type FindByType<Union, Type> = Union extends {
|
|
22
29
|
type: Type;
|
|
23
30
|
} ? Union : never;
|
|
24
|
-
declare type ElementEventListener<
|
|
31
|
+
declare type ElementEventListener<Events, Type> = (event: FindByType<Events, Type>) => void;
|
|
25
32
|
interface Subscription {
|
|
26
33
|
unsubscribe(): void;
|
|
27
34
|
}
|
|
28
|
-
export type { EventType, BaseEvent, ReadyEvent, ChangeEvent, InputFocusEvent, InputBlurEvent, InputKeydownEvent,
|
|
35
|
+
export type { EventType, BaseEvent, ReadyEvent, ChangeEvent, CardChangeEvent, InputFocusEvent, InputBlurEvent, InputKeydownEvent, BaseElementEvents, TextElementEvents, CardElementEvents, CardExpirationDateElementEvents, CardVerificationCodeElementEvents, ElementEventListener, Subscription, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ElementStyle } from './styles';
|
|
2
|
-
declare const ELEMENTS_TYPES: readonly ["card", "text"];
|
|
2
|
+
declare const ELEMENTS_TYPES: readonly ["card", "text", "cardExpirationDate", "cardVerificationCode"];
|
|
3
3
|
declare type ElementType = typeof ELEMENTS_TYPES[number];
|
|
4
4
|
interface ElementInternalOptions {
|
|
5
5
|
apiKey: string;
|
|
@@ -16,6 +16,7 @@ interface SanitizedElementOptions {
|
|
|
16
16
|
transform?: [RegExp, string] | null;
|
|
17
17
|
ariaDescription?: string;
|
|
18
18
|
ariaLabel?: string;
|
|
19
|
+
cardBrand?: string;
|
|
19
20
|
}
|
|
20
21
|
declare type ElementOptions = ElementInternalOptions & SanitizedElementOptions;
|
|
21
22
|
declare type Transform = RegExp | [RegExp, string?] | null;
|
|
@@ -29,5 +30,13 @@ declare type CreateTextElementOptions = CustomizableElementOptions & Pick<Elemen
|
|
|
29
30
|
'aria-label'?: string;
|
|
30
31
|
};
|
|
31
32
|
declare type UpdateTextElementOptions = Omit<CreateTextElementOptions, 'targetId' | 'mask'>;
|
|
32
|
-
|
|
33
|
+
declare type CreateCardExpirationDateElementOptions = CustomizableElementOptions & Pick<ElementOptions, 'placeholder'> & Required<Pick<ElementOptions, 'targetId'>> & {
|
|
34
|
+
'aria-label'?: string;
|
|
35
|
+
};
|
|
36
|
+
declare type UpdateCardExpirationDateElementOptions = Omit<CreateCardExpirationDateElementOptions, 'targetId'>;
|
|
37
|
+
declare type CreateCardVerificationCodeElementOptions = CustomizableElementOptions & Pick<ElementOptions, 'placeholder' | 'cardBrand'> & Required<Pick<ElementOptions, 'targetId'>> & {
|
|
38
|
+
'aria-label'?: string;
|
|
39
|
+
};
|
|
40
|
+
declare type UpdateCardVerificationCodeElementOptions = Omit<CreateCardVerificationCodeElementOptions, 'targetId'>;
|
|
41
|
+
export type { ElementInternalOptions, ElementType, ElementOptions, SanitizedElementOptions, Transform, CustomizableElementOptions, CreateCardElementOptions, UpdateCardElementOptions, CreateTextElementOptions, UpdateTextElementOptions, CreateCardExpirationDateElementOptions, UpdateCardExpirationDateElementOptions, CreateCardVerificationCodeElementOptions, UpdateCardVerificationCodeElementOptions, };
|
|
33
42
|
export { ELEMENTS_TYPES };
|
|
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ELEMENTS_TYPES = void 0;
|
|
7
|
-
const ELEMENTS_TYPES = ['card', 'text'];
|
|
7
|
+
const ELEMENTS_TYPES = ['card', 'text', 'cardExpirationDate', 'cardVerificationCode'];
|
|
8
8
|
exports.ELEMENTS_TYPES = ELEMENTS_TYPES;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ElementValue } from '@/types/elements';
|
|
2
2
|
import type { TokenizeData as TokenizeDataModel } from '@/types/models';
|
|
3
3
|
import type { RequestOptions } from '@/types/sdk';
|
|
4
|
-
declare type TokenizeData = TokenizeDataModel<
|
|
4
|
+
declare type TokenizeData = TokenizeDataModel<ElementValue>;
|
|
5
5
|
interface Tokenize {
|
|
6
6
|
tokenize(tokens: TokenizeData, options?: RequestOptions): Promise<TokenizeDataModel>;
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ElementValue } from '@/types/elements';
|
|
2
2
|
import type { CreateToken as CreateTokenModel, Token } from '@/types/models';
|
|
3
3
|
import type { Create } from '@/types/sdk';
|
|
4
|
-
declare type CreateToken = CreateTokenModel<
|
|
4
|
+
declare type CreateToken = CreateTokenModel<ElementValue>;
|
|
5
5
|
declare type Tokens = Create<Token, CreateToken>;
|
|
6
6
|
export type { Tokens, CreateToken };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CARD_BRANDS } from '@/elements/constants';
|
|
1
2
|
declare type FieldErrorType = 'incomplete' | 'invalid';
|
|
2
3
|
declare type ConfigErrorType = 'missing-configuration' | 'missing-permission' | 'invalid-configuration';
|
|
3
4
|
interface ConfigError {
|
|
@@ -18,5 +19,5 @@ interface PropertyError {
|
|
|
18
19
|
/**
|
|
19
20
|
* Card brands type
|
|
20
21
|
*/
|
|
21
|
-
declare type Brand =
|
|
22
|
+
declare type Brand = typeof CARD_BRANDS[number];
|
|
22
23
|
export type { FieldErrorType, ConfigErrorType, ConfigError, Targeted, ListenableKey, FieldError, PropertyError, Brand, };
|