@basis-theory/react-elements 2.0.0 → 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 +43 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basis-theory/react-elements",
|
|
3
|
-
"version": "2.
|
|
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": "2.
|
|
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
|
@@ -138,7 +138,7 @@ export type DataElementReference = {
|
|
|
138
138
|
elementId: string;
|
|
139
139
|
path: string;
|
|
140
140
|
};
|
|
141
|
-
export type EventType = 'ready' | 'change' | 'focus' | 'blur' | 'keydown';
|
|
141
|
+
export type EventType = 'ready' | 'change' | 'focus' | 'blur' | 'keydown' | 'click';
|
|
142
142
|
export interface BaseEvent<T extends EventType> {
|
|
143
143
|
type: T;
|
|
144
144
|
}
|
|
@@ -160,12 +160,14 @@ export type InputBlurEvent = BaseEvent<'blur'> & Targeted;
|
|
|
160
160
|
export type InputKeydownEvent = BaseEvent<'keydown'> & Targeted & {
|
|
161
161
|
key: ListenableKey;
|
|
162
162
|
} & Pick<KeyboardEvent, 'altKey' | 'ctrlKey' | 'shiftKey' | 'metaKey'>;
|
|
163
|
+
export type ClickEvent = BaseEvent<'click'> & Targeted;
|
|
163
164
|
export type BaseElementEvents = ReadyEvent | InputFocusEvent | InputBlurEvent | InputKeydownEvent;
|
|
164
165
|
export type TextElementEvents = BaseElementEvents | ChangeEvent;
|
|
165
166
|
export type CardElementEvents = BaseElementEvents | CardChangeEvent;
|
|
166
167
|
export type CardNumberElementEvents = BaseElementEvents | CardChangeEvent;
|
|
167
168
|
export type CardExpirationDateElementEvents = BaseElementEvents | ChangeEvent;
|
|
168
169
|
export type CardVerificationCodeElementEvents = BaseElementEvents | ChangeEvent;
|
|
170
|
+
export type CopyButtonElementEvents = BaseElementEvents | ClickEvent;
|
|
169
171
|
/**
|
|
170
172
|
* Utility type that helps find a Union type based on a `type` property
|
|
171
173
|
*/
|
|
@@ -176,14 +178,20 @@ export type ElementEventListener<Events, Type> = (event: FindByType<Events, Type
|
|
|
176
178
|
export interface Subscription {
|
|
177
179
|
unsubscribe(): void;
|
|
178
180
|
}
|
|
179
|
-
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"];
|
|
180
183
|
export type SafeCSSProperty = (typeof SAFE_CSS_PROPERTIES)[number];
|
|
184
|
+
export type ButtonCSSProperty = (typeof BUTTON_CSS_PROPERTIES)[number];
|
|
181
185
|
export const SAFE_CSS_PROPERTIES_ALTERNATES: Partial<Record<SafeCSSProperty, string[]>>;
|
|
182
186
|
export const SAFE_CSS_PROPERTIES_WITH_ALTERNATES: string[];
|
|
183
187
|
export type SafeStyle = Pick<Properties, SafeCSSProperty>;
|
|
184
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"];
|
|
185
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>;
|
|
186
193
|
export type CardElementStyleVariantStyle = SafeStyle & Partial<Record<CardElementStyleVariantSelector, SafeStyle>>;
|
|
194
|
+
export type ButtonElementStyleVariantStyle = ButtonStyle & Partial<Record<ButtonElementStyleVariantSelector, ButtonStyle>>;
|
|
187
195
|
export const CARD_ELEMENT_STYLE_VARIANTS: readonly ["base", "container", "complete", "invalid", "empty"];
|
|
188
196
|
export const CARD_ELEMENT_STYLE_FONTS_ATTR: "fonts";
|
|
189
197
|
export type CardElementStyleVariant = (typeof CARD_ELEMENT_STYLE_VARIANTS)[number];
|
|
@@ -192,16 +200,21 @@ type FontSource = string;
|
|
|
192
200
|
export type FontSources = FontSource[];
|
|
193
201
|
export type Fonts = Record<CardElementStyleFontAttr, FontSources>;
|
|
194
202
|
export type CardElementStyle = Partial<Record<CardElementStyleVariant, CardElementStyleVariantStyle> & Fonts>;
|
|
195
|
-
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;
|
|
196
208
|
export type CopyIconStyles = {
|
|
197
209
|
size?: string;
|
|
198
210
|
color?: string;
|
|
199
211
|
successColor?: string;
|
|
200
212
|
};
|
|
201
|
-
export const ELEMENTS_TYPES: readonly ["card", "cardExpirationDate", "cardNumber", "cardVerificationCode", "data", "text"];
|
|
213
|
+
export const ELEMENTS_TYPES: readonly ["card", "cardExpirationDate", "cardNumber", "cardVerificationCode", "copyButton", "data", "text"];
|
|
202
214
|
export type ElementType = (typeof ELEMENTS_TYPES)[number];
|
|
203
215
|
export interface ElementInternalOptions {
|
|
204
216
|
apiKey: string | undefined;
|
|
217
|
+
customDomain: string | undefined;
|
|
205
218
|
baseUrl: string;
|
|
206
219
|
type: ElementType;
|
|
207
220
|
debug: boolean | undefined;
|
|
@@ -242,6 +255,7 @@ export interface SanitizedElementOptions {
|
|
|
242
255
|
skipLuhnValidation?: boolean;
|
|
243
256
|
style?: ElementStyle;
|
|
244
257
|
targetId?: string;
|
|
258
|
+
text?: string;
|
|
245
259
|
title?: string;
|
|
246
260
|
transform?: [RegExp, string] | null;
|
|
247
261
|
validateOnChange?: boolean;
|
|
@@ -308,6 +322,12 @@ export type CreateCardVerificationCodeElementOptions = CustomizableElementOption
|
|
|
308
322
|
value?: string;
|
|
309
323
|
};
|
|
310
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'>;
|
|
311
331
|
export interface BinDetails {
|
|
312
332
|
cardBrand?: string;
|
|
313
333
|
type?: string;
|
|
@@ -621,6 +641,9 @@ export type ICardVerificationCodeElement = BaseElement<UpdateCardVerificationCod
|
|
|
621
641
|
setValueRef(value: ICardVerificationCodeElement): void;
|
|
622
642
|
setValue(value: DataElementReference): void;
|
|
623
643
|
};
|
|
644
|
+
export type ICopyButtonElement = BaseElement<UpdateCopyButtonElementOptions, CopyButtonElementEvents> & {
|
|
645
|
+
setValueRef(value: ITextElement | ICardNumberElement | ICardExpirationDateElement | ICardVerificationCodeElement): void;
|
|
646
|
+
};
|
|
624
647
|
export type ElementWrapper<T extends BaseElement<any, any> = BaseElement<any, any>> = {
|
|
625
648
|
element: T;
|
|
626
649
|
method?: string;
|
|
@@ -628,7 +651,7 @@ export type ElementWrapper<T extends BaseElement<any, any> = BaseElement<any, an
|
|
|
628
651
|
format: string;
|
|
629
652
|
};
|
|
630
653
|
};
|
|
631
|
-
export type ElementValue = ITextElement | ICardElement | ICardNumberElement | ICardExpirationDateElement | ICardVerificationCodeElement | ElementWrapper;
|
|
654
|
+
export type ElementValue = ITextElement | ICardElement | ICardNumberElement | ICardExpirationDateElement | ICardVerificationCodeElement | ICopyButtonElement | ElementWrapper;
|
|
632
655
|
export interface BasisTheoryElements {
|
|
633
656
|
tokens: Tokens;
|
|
634
657
|
proxy: Proxy;
|
|
@@ -642,9 +665,10 @@ export interface BasisTheoryElements {
|
|
|
642
665
|
createElement(type: 'cardNumber', options: CreateCardNumberElementOptions): ICardNumberElement;
|
|
643
666
|
createElement(type: 'cardExpirationDate', options: CreateCardExpirationDateElementOptions): ICardExpirationDateElement;
|
|
644
667
|
createElement(type: 'cardVerificationCode', options: CreateCardVerificationCodeElementOptions): ICardVerificationCodeElement;
|
|
668
|
+
createElement(type: 'copyButton', options: CreateCopyButtonElementOptions): ICopyButtonElement;
|
|
645
669
|
}
|
|
646
670
|
export interface BasisTheoryElementsInternal extends BasisTheoryElements {
|
|
647
|
-
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>;
|
|
648
672
|
hasElement: (payload: unknown) => boolean;
|
|
649
673
|
}
|
|
650
674
|
declare global {
|
|
@@ -652,6 +676,18 @@ declare global {
|
|
|
652
676
|
BasisTheoryElements?: BasisTheoryElementsInternal;
|
|
653
677
|
}
|
|
654
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
|
+
}
|
|
655
691
|
export interface BasisTheoryInitOptions {
|
|
656
692
|
_devMode?: boolean;
|
|
657
693
|
disableTelemetry?: boolean;
|
|
@@ -659,6 +695,7 @@ export interface BasisTheoryInitOptions {
|
|
|
659
695
|
useUat?: boolean;
|
|
660
696
|
debug?: boolean;
|
|
661
697
|
useNetworkCheck?: boolean;
|
|
698
|
+
customDomain?: string;
|
|
662
699
|
}
|
|
663
700
|
export const basistheory: (apiKey: string, options?: BasisTheoryInitOptions) => Promise<BasisTheoryElements | undefined>;
|
|
664
701
|
export class BasisTheoryApiError extends Error {
|
|
@@ -667,18 +704,6 @@ export class BasisTheoryApiError extends Error {
|
|
|
667
704
|
readonly _debug?: Record<string, unknown> | undefined;
|
|
668
705
|
constructor(message: string, status: number, data?: unknown | undefined, _debug?: Record<string, unknown> | undefined);
|
|
669
706
|
}
|
|
670
|
-
export class BasisTheoryValidationError<Details = Record<string, unknown>> extends Error {
|
|
671
|
-
readonly details: Details;
|
|
672
|
-
/**
|
|
673
|
-
* @deprecated use {@link details}
|
|
674
|
-
*/
|
|
675
|
-
readonly validation?: FieldError[] | undefined;
|
|
676
|
-
constructor(message: string, details: Details,
|
|
677
|
-
/**
|
|
678
|
-
* @deprecated use {@link details}
|
|
679
|
-
*/
|
|
680
|
-
validation?: FieldError[] | undefined);
|
|
681
|
-
}
|
|
682
707
|
export class HttpClientError extends Error {
|
|
683
708
|
readonly status: number;
|
|
684
709
|
readonly data?: unknown;
|