@basis-theory/react-elements 1.24.2 → 2.1.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/package.json +2 -2
- package/types/index.d.ts +103 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basis-theory/react-elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"repository": "https://github.com/basis-theory/react-elements",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"tag": "latest"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@basis-theory/web-elements": "1.
|
|
33
|
+
"@basis-theory/web-elements": "2.1.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
package/types/index.d.ts
CHANGED
|
@@ -40,9 +40,55 @@ export interface HttpClient {
|
|
|
40
40
|
get(url: string, config?: RequestConfig): Promise<unknown>;
|
|
41
41
|
delete(url: string, config?: RequestConfig): Promise<unknown>;
|
|
42
42
|
}
|
|
43
|
+
interface NetworkInformation {
|
|
44
|
+
downlink: number;
|
|
45
|
+
downlinkMax?: number;
|
|
46
|
+
effectiveType: 'slow-2g' | '2g' | '3g' | '4g';
|
|
47
|
+
rtt: number;
|
|
48
|
+
saveData: boolean;
|
|
49
|
+
type?: 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown';
|
|
50
|
+
}
|
|
51
|
+
type DeviceInfo = {
|
|
52
|
+
uaBrands?: Array<{
|
|
53
|
+
brand: string;
|
|
54
|
+
version: string;
|
|
55
|
+
}>;
|
|
56
|
+
uaMobile?: boolean;
|
|
57
|
+
uaPlatform?: string;
|
|
58
|
+
uaPlatformVersion?: string;
|
|
59
|
+
languages?: string[];
|
|
60
|
+
timeZone?: string;
|
|
61
|
+
cookiesEnabled?: boolean;
|
|
62
|
+
localStorageEnabled?: boolean;
|
|
63
|
+
sessionStorageEnabled?: boolean;
|
|
64
|
+
platform?: string;
|
|
65
|
+
hardwareConcurrency?: number;
|
|
66
|
+
deviceMemoryGb?: number | null;
|
|
67
|
+
screenWidth?: number;
|
|
68
|
+
screenHeight?: number;
|
|
69
|
+
screenAvailWidth?: number;
|
|
70
|
+
screenAvailHeight?: number;
|
|
71
|
+
innerWidth?: number;
|
|
72
|
+
innerHeight?: number;
|
|
73
|
+
devicePixelRatio?: number;
|
|
74
|
+
maxTouchPoints?: number;
|
|
75
|
+
plugins?: string[];
|
|
76
|
+
mimeTypes?: string[];
|
|
77
|
+
webdriver?: boolean;
|
|
78
|
+
suspectedHeadless?: boolean;
|
|
79
|
+
webglVendor?: string;
|
|
80
|
+
webglRenderer?: string;
|
|
81
|
+
canvasHash?: string;
|
|
82
|
+
network?: NetworkInformation;
|
|
83
|
+
};
|
|
84
|
+
interface Device {
|
|
85
|
+
getDeviceInfo(options?: {
|
|
86
|
+
includeCanvasHash?: boolean;
|
|
87
|
+
}): DeviceInfo;
|
|
88
|
+
}
|
|
43
89
|
export const CARD_BRANDS: readonly ["accel", "bancontact", "cartes-bancaires", "culiance", "dankort", "ebt", "eftpos-australia", "nyce", "private-label", "prop", "pulse", "rupay", "star", "uatp", "korean-local", "visa", "mastercard", "american-express", "discover", "diners-club", "jcb", "unionpay", "maestro", "elo", "hiper", "hipercard", "mir", "unknown"];
|
|
44
|
-
|
|
45
|
-
|
|
90
|
+
export const CARD_ICON_POSITIONS: readonly ["left", "right", "none"];
|
|
91
|
+
export const AUTOCOMPLETE_VALUES: readonly ["additional-name", "address-level1", "address-level2", "address-level3", "address-level4", "address-line1", "address-line2", "address-line3", "bday-day", "bday-month", "bday-year", "bday", "billing", "cc-additional-name", "cc-csc", "cc-exp-month", "cc-exp-year", "cc-exp", "cc-family-name", "cc-given-name", "cc-name", "cc-number", "cc-type", "country-name", "country", "current-password", "email", "family-name", "fax", "given-name", "home", "honorific-prefix", "honorific-suffix", "language", "mobile", "name", "new-password", "nickname", "off", "on", "one-time-code", "organization-title", "organization", "page", "postal-code", "sex", "shipping", "street-address", "tel-area-code", "tel-country-code", "tel-extension", "tel-local-prefix", "tel-local-suffix", "tel-local", "tel-national", "tel", "transaction-amount", "transaction-currency", "url", "username", "work"];
|
|
46
92
|
export type FieldErrorType = 'incomplete' | 'invalid';
|
|
47
93
|
export type ConfigErrorType = 'missing-configuration' | 'missing-permission' | 'invalid-configuration';
|
|
48
94
|
export interface ConfigError {
|
|
@@ -92,7 +138,7 @@ export type DataElementReference = {
|
|
|
92
138
|
elementId: string;
|
|
93
139
|
path: string;
|
|
94
140
|
};
|
|
95
|
-
export type EventType = 'ready' | 'change' | 'focus' | 'blur' | 'keydown';
|
|
141
|
+
export type EventType = 'ready' | 'change' | 'focus' | 'blur' | 'keydown' | 'click';
|
|
96
142
|
export interface BaseEvent<T extends EventType> {
|
|
97
143
|
type: T;
|
|
98
144
|
}
|
|
@@ -114,12 +160,14 @@ export type InputBlurEvent = BaseEvent<'blur'> & Targeted;
|
|
|
114
160
|
export type InputKeydownEvent = BaseEvent<'keydown'> & Targeted & {
|
|
115
161
|
key: ListenableKey;
|
|
116
162
|
} & Pick<KeyboardEvent, 'altKey' | 'ctrlKey' | 'shiftKey' | 'metaKey'>;
|
|
163
|
+
export type ClickEvent = BaseEvent<'click'> & Targeted;
|
|
117
164
|
export type BaseElementEvents = ReadyEvent | InputFocusEvent | InputBlurEvent | InputKeydownEvent;
|
|
118
165
|
export type TextElementEvents = BaseElementEvents | ChangeEvent;
|
|
119
166
|
export type CardElementEvents = BaseElementEvents | CardChangeEvent;
|
|
120
167
|
export type CardNumberElementEvents = BaseElementEvents | CardChangeEvent;
|
|
121
168
|
export type CardExpirationDateElementEvents = BaseElementEvents | ChangeEvent;
|
|
122
169
|
export type CardVerificationCodeElementEvents = BaseElementEvents | ChangeEvent;
|
|
170
|
+
export type CopyButtonElementEvents = BaseElementEvents | ClickEvent;
|
|
123
171
|
/**
|
|
124
172
|
* Utility type that helps find a Union type based on a `type` property
|
|
125
173
|
*/
|
|
@@ -130,15 +178,21 @@ export type ElementEventListener<Events, Type> = (event: FindByType<Events, Type
|
|
|
130
178
|
export interface Subscription {
|
|
131
179
|
unsubscribe(): void;
|
|
132
180
|
}
|
|
133
|
-
export const SAFE_CSS_PROPERTIES: readonly ["backgroundColor", "color", "fontFamily", "fontSize", "fontSmooth", "fontStyle", "fontVariant", "fontWeight", "
|
|
181
|
+
export const SAFE_CSS_PROPERTIES: readonly ["backgroundColor", "color", "fontFamily", "fontSize", "fontSmooth", "fontStyle", "fontVariant", "fontWeight", "letterSpacing", "lineHeight", "padding", "textAlign", "textDecoration", "textShadow", "textTransform"];
|
|
182
|
+
export const BUTTON_CSS_PROPERTIES: readonly ["alignItems", "backgroundColor", "border", "borderBottom", "borderColor", "borderLeft", "borderRadius", "borderRight", "borderStyle", "borderTop", "borderWidth", "boxShadow", "color", "cursor", "display", "fontFamily", "fontSize", "fontWeight", "gap", "height", "justifyContent", "letterSpacing", "lineHeight", "margin", "maxHeight", "maxWidth", "minHeight", "minWidth", "opacity", "outline", "padding", "textAlign", "textTransform", "transform", "transition", "width"];
|
|
134
183
|
export type SafeCSSProperty = (typeof SAFE_CSS_PROPERTIES)[number];
|
|
184
|
+
export type ButtonCSSProperty = (typeof BUTTON_CSS_PROPERTIES)[number];
|
|
135
185
|
export const SAFE_CSS_PROPERTIES_ALTERNATES: Partial<Record<SafeCSSProperty, string[]>>;
|
|
136
186
|
export const SAFE_CSS_PROPERTIES_WITH_ALTERNATES: string[];
|
|
137
187
|
export type SafeStyle = Pick<Properties, SafeCSSProperty>;
|
|
138
188
|
export const CARD_ELEMENT_STYLE_VARIANT_SELECTORS: readonly [":hover", ":focus", ":read-only", "::placeholder", "::selection", ":disabled"];
|
|
189
|
+
export const BUTTON_ELEMENT_STYLE_VARIANT_SELECTORS: readonly [":hover", ":focus", ":active"];
|
|
139
190
|
export type CardElementStyleVariantSelector = (typeof CARD_ELEMENT_STYLE_VARIANT_SELECTORS)[number];
|
|
191
|
+
export type ButtonElementStyleVariantSelector = (typeof BUTTON_ELEMENT_STYLE_VARIANT_SELECTORS)[number];
|
|
192
|
+
export type ButtonStyle = Pick<Properties, ButtonCSSProperty>;
|
|
140
193
|
export type CardElementStyleVariantStyle = SafeStyle & Partial<Record<CardElementStyleVariantSelector, SafeStyle>>;
|
|
141
|
-
export
|
|
194
|
+
export type ButtonElementStyleVariantStyle = ButtonStyle & Partial<Record<ButtonElementStyleVariantSelector, ButtonStyle>>;
|
|
195
|
+
export const CARD_ELEMENT_STYLE_VARIANTS: readonly ["base", "container", "complete", "invalid", "empty"];
|
|
142
196
|
export const CARD_ELEMENT_STYLE_FONTS_ATTR: "fonts";
|
|
143
197
|
export type CardElementStyleVariant = (typeof CARD_ELEMENT_STYLE_VARIANTS)[number];
|
|
144
198
|
type CardElementStyleFontAttr = typeof CARD_ELEMENT_STYLE_FONTS_ATTR;
|
|
@@ -146,16 +200,21 @@ type FontSource = string;
|
|
|
146
200
|
export type FontSources = FontSource[];
|
|
147
201
|
export type Fonts = Record<CardElementStyleFontAttr, FontSources>;
|
|
148
202
|
export type CardElementStyle = Partial<Record<CardElementStyleVariant, CardElementStyleVariantStyle> & Fonts>;
|
|
149
|
-
export
|
|
203
|
+
export const BUTTON_ELEMENT_STYLE_VARIANTS: readonly ["base", "container"];
|
|
204
|
+
export type ButtonElementStyleVariant = (typeof BUTTON_ELEMENT_STYLE_VARIANTS)[number];
|
|
205
|
+
export type ButtonElementStyle = Partial<Record<ButtonElementStyleVariant, ButtonElementStyleVariantStyle> & Fonts>;
|
|
206
|
+
export type CopyButtonElementStyle = ButtonElementStyle;
|
|
207
|
+
export type ElementStyle = CardElementStyle | CopyButtonElementStyle;
|
|
150
208
|
export type CopyIconStyles = {
|
|
151
209
|
size?: string;
|
|
152
210
|
color?: string;
|
|
153
211
|
successColor?: string;
|
|
154
212
|
};
|
|
155
|
-
export const ELEMENTS_TYPES: readonly ["card", "cardExpirationDate", "cardNumber", "cardVerificationCode", "data", "text"];
|
|
213
|
+
export const ELEMENTS_TYPES: readonly ["card", "cardExpirationDate", "cardNumber", "cardVerificationCode", "copyButton", "data", "text"];
|
|
156
214
|
export type ElementType = (typeof ELEMENTS_TYPES)[number];
|
|
157
215
|
export interface ElementInternalOptions {
|
|
158
216
|
apiKey: string | undefined;
|
|
217
|
+
customDomain: string | undefined;
|
|
159
218
|
baseUrl: string;
|
|
160
219
|
type: ElementType;
|
|
161
220
|
debug: boolean | undefined;
|
|
@@ -196,6 +255,7 @@ export interface SanitizedElementOptions {
|
|
|
196
255
|
skipLuhnValidation?: boolean;
|
|
197
256
|
style?: ElementStyle;
|
|
198
257
|
targetId?: string;
|
|
258
|
+
text?: string;
|
|
199
259
|
title?: string;
|
|
200
260
|
transform?: [RegExp, string] | null;
|
|
201
261
|
validateOnChange?: boolean;
|
|
@@ -262,6 +322,12 @@ export type CreateCardVerificationCodeElementOptions = CustomizableElementOption
|
|
|
262
322
|
value?: string;
|
|
263
323
|
};
|
|
264
324
|
export type UpdateCardVerificationCodeElementOptions = Omit<CreateCardVerificationCodeElementOptions, 'targetId' | 'validateOnChange' | 'enableCopy'>;
|
|
325
|
+
export type CreateCopyButtonElementOptions = Pick<ElementOptions, 'targetId' | 'title' | 'disabled'> & {
|
|
326
|
+
id?: string;
|
|
327
|
+
style?: CopyButtonElementStyle;
|
|
328
|
+
text?: string;
|
|
329
|
+
};
|
|
330
|
+
export type UpdateCopyButtonElementOptions = Omit<CreateCopyButtonElementOptions, 'targetId'>;
|
|
265
331
|
export interface BinDetails {
|
|
266
332
|
cardBrand?: string;
|
|
267
333
|
type?: string;
|
|
@@ -278,12 +344,20 @@ export interface BinDetails {
|
|
|
278
344
|
issuerCurrency?: string;
|
|
279
345
|
comboCard?: string;
|
|
280
346
|
binLength?: number;
|
|
281
|
-
authentication?:
|
|
282
|
-
cost?:
|
|
347
|
+
authentication?: Authentication;
|
|
348
|
+
cost?: Cost;
|
|
283
349
|
bank?: BinDetailsBank;
|
|
284
350
|
country?: BinDetailsCountry;
|
|
285
351
|
product?: BinDetailsProduct;
|
|
286
352
|
}
|
|
353
|
+
interface Cost {
|
|
354
|
+
capAdvaloremAmount: string;
|
|
355
|
+
capTypeName: string;
|
|
356
|
+
capFixedAmount: string;
|
|
357
|
+
}
|
|
358
|
+
interface Authentication {
|
|
359
|
+
authenticationName: string;
|
|
360
|
+
}
|
|
287
361
|
export interface BinDetailsBank {
|
|
288
362
|
name?: string;
|
|
289
363
|
phone?: string;
|
|
@@ -567,6 +641,9 @@ export type ICardVerificationCodeElement = BaseElement<UpdateCardVerificationCod
|
|
|
567
641
|
setValueRef(value: ICardVerificationCodeElement): void;
|
|
568
642
|
setValue(value: DataElementReference): void;
|
|
569
643
|
};
|
|
644
|
+
export type ICopyButtonElement = BaseElement<UpdateCopyButtonElementOptions, CopyButtonElementEvents> & {
|
|
645
|
+
setValueRef(value: ITextElement | ICardNumberElement | ICardExpirationDateElement | ICardVerificationCodeElement): void;
|
|
646
|
+
};
|
|
570
647
|
export type ElementWrapper<T extends BaseElement<any, any> = BaseElement<any, any>> = {
|
|
571
648
|
element: T;
|
|
572
649
|
method?: string;
|
|
@@ -574,7 +651,7 @@ export type ElementWrapper<T extends BaseElement<any, any> = BaseElement<any, an
|
|
|
574
651
|
format: string;
|
|
575
652
|
};
|
|
576
653
|
};
|
|
577
|
-
export type ElementValue = ITextElement | ICardElement | ICardNumberElement | ICardExpirationDateElement | ICardVerificationCodeElement | ElementWrapper;
|
|
654
|
+
export type ElementValue = ITextElement | ICardElement | ICardNumberElement | ICardExpirationDateElement | ICardVerificationCodeElement | ICopyButtonElement | ElementWrapper;
|
|
578
655
|
export interface BasisTheoryElements {
|
|
579
656
|
tokens: Tokens;
|
|
580
657
|
proxy: Proxy;
|
|
@@ -582,14 +659,16 @@ export interface BasisTheoryElements {
|
|
|
582
659
|
tokenIntents: TokenIntents;
|
|
583
660
|
tokenize: Tokenize['tokenize'];
|
|
584
661
|
client: HttpClient;
|
|
662
|
+
device: Device;
|
|
585
663
|
createElement(type: 'card', options?: CreateCardElementOptions): ICardElement;
|
|
586
664
|
createElement(type: 'text', options: CreateTextElementOptions): ITextElement;
|
|
587
665
|
createElement(type: 'cardNumber', options: CreateCardNumberElementOptions): ICardNumberElement;
|
|
588
666
|
createElement(type: 'cardExpirationDate', options: CreateCardExpirationDateElementOptions): ICardExpirationDateElement;
|
|
589
667
|
createElement(type: 'cardVerificationCode', options: CreateCardVerificationCodeElementOptions): ICardVerificationCodeElement;
|
|
668
|
+
createElement(type: 'copyButton', options: CreateCopyButtonElementOptions): ICopyButtonElement;
|
|
590
669
|
}
|
|
591
670
|
export interface BasisTheoryElementsInternal extends BasisTheoryElements {
|
|
592
|
-
init: (apiKey: string | undefined, elementsBaseUrl: string, elementsUseNgApi: boolean | undefined, elementsUseSameOriginApi: boolean | undefined, disableTelemetry: boolean | undefined, debug: boolean | undefined, useUat: boolean | undefined, useNetworkCheck: boolean | undefined) => Promise<BasisTheoryElements>;
|
|
671
|
+
init: (apiKey: string | undefined, elementsBaseUrl: string, elementsUseNgApi: boolean | undefined, elementsUseSameOriginApi: boolean | undefined, disableTelemetry: boolean | undefined, debug: boolean | undefined, useUat: boolean | undefined, useNetworkCheck: boolean | undefined, customDomain: string | undefined) => Promise<BasisTheoryElements>;
|
|
593
672
|
hasElement: (payload: unknown) => boolean;
|
|
594
673
|
}
|
|
595
674
|
declare global {
|
|
@@ -597,6 +676,18 @@ declare global {
|
|
|
597
676
|
BasisTheoryElements?: BasisTheoryElementsInternal;
|
|
598
677
|
}
|
|
599
678
|
}
|
|
679
|
+
export class BasisTheoryValidationError<Details = Record<string, unknown>> extends Error {
|
|
680
|
+
readonly details: Details;
|
|
681
|
+
/**
|
|
682
|
+
* @deprecated use {@link details}
|
|
683
|
+
*/
|
|
684
|
+
readonly validation?: FieldError[] | undefined;
|
|
685
|
+
constructor(message: string, details: Details,
|
|
686
|
+
/**
|
|
687
|
+
* @deprecated use {@link details}
|
|
688
|
+
*/
|
|
689
|
+
validation?: FieldError[] | undefined);
|
|
690
|
+
}
|
|
600
691
|
export interface BasisTheoryInitOptions {
|
|
601
692
|
_devMode?: boolean;
|
|
602
693
|
disableTelemetry?: boolean;
|
|
@@ -604,6 +695,7 @@ export interface BasisTheoryInitOptions {
|
|
|
604
695
|
useUat?: boolean;
|
|
605
696
|
debug?: boolean;
|
|
606
697
|
useNetworkCheck?: boolean;
|
|
698
|
+
customDomain?: string;
|
|
607
699
|
}
|
|
608
700
|
export const basistheory: (apiKey: string, options?: BasisTheoryInitOptions) => Promise<BasisTheoryElements | undefined>;
|
|
609
701
|
export class BasisTheoryApiError extends Error {
|
|
@@ -612,18 +704,6 @@ export class BasisTheoryApiError extends Error {
|
|
|
612
704
|
readonly _debug?: Record<string, unknown> | undefined;
|
|
613
705
|
constructor(message: string, status: number, data?: unknown | undefined, _debug?: Record<string, unknown> | undefined);
|
|
614
706
|
}
|
|
615
|
-
export class BasisTheoryValidationError<Details = Record<string, unknown>> extends Error {
|
|
616
|
-
readonly details: Details;
|
|
617
|
-
/**
|
|
618
|
-
* @deprecated use {@link details}
|
|
619
|
-
*/
|
|
620
|
-
readonly validation?: FieldError[] | undefined;
|
|
621
|
-
constructor(message: string, details: Details,
|
|
622
|
-
/**
|
|
623
|
-
* @deprecated use {@link details}
|
|
624
|
-
*/
|
|
625
|
-
validation?: FieldError[] | undefined);
|
|
626
|
-
}
|
|
627
707
|
export class HttpClientError extends Error {
|
|
628
708
|
readonly status: number;
|
|
629
709
|
readonly data?: unknown;
|