@basis-theory/react-elements 1.11.2 → 1.11.4

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.
@@ -0,0 +1,682 @@
1
+ import { Properties } from "csstype";
2
+ import React, { PropsWithChildren, MutableRefObject } from "react";
3
+ type CardBrandId = 'american-express' | 'diners-club' | 'discover' | 'elo' | 'hiper' | 'hipercard' | 'jcb' | 'maestro' | 'mastercard' | 'mir' | 'unionpay' | 'visa';
4
+ type CardBrandNiceType = 'American Express' | 'Diners Club' | 'Discover' | 'Elo' | 'Hiper' | 'Hipercard' | 'JCB' | 'Maestro' | 'Mastercard' | 'Mir' | 'UnionPay' | 'Visa';
5
+ type SecurityCodeLabel = 'CVV' | 'CVC' | 'CID' | 'CVN' | 'CVE' | 'CVP2';
6
+ export type CreditCardType = {
7
+ code: {
8
+ size: number;
9
+ name: SecurityCodeLabel | string;
10
+ };
11
+ gaps: number[];
12
+ lengths: number[];
13
+ niceType: CardBrandNiceType | string;
14
+ patterns: (number | [number, number])[];
15
+ type: CardBrandId | string;
16
+ };
17
+ export const VISA: CreditCardType;
18
+ export const MASTERCARD: CreditCardType;
19
+ export const AMERICAN_EXPRESS: CreditCardType;
20
+ export const DINERS_CLUB: CreditCardType;
21
+ export const DISCOVER: CreditCardType;
22
+ export const JCB: CreditCardType;
23
+ export const UNION_PAY: CreditCardType;
24
+ export const MAESTRO: CreditCardType;
25
+ export const ELO: CreditCardType;
26
+ export const MIR: CreditCardType;
27
+ export const HIPER: CreditCardType;
28
+ export const HIPERCARD: CreditCardType;
29
+ export const DEFAULT_CARD_TYPES: CreditCardType[];
30
+ export interface RequestConfig {
31
+ headers?: Record<string, string>;
32
+ }
33
+ export interface HttpClient {
34
+ post(url: string, payload: unknown, config?: RequestConfig): Promise<unknown>;
35
+ put(url: string, payload: unknown, config?: RequestConfig): Promise<unknown>;
36
+ patch(url: string, payload: unknown, config?: RequestConfig): Promise<unknown>;
37
+ get(url: string, config?: RequestConfig): Promise<unknown>;
38
+ delete(url: string, config?: RequestConfig): Promise<unknown>;
39
+ }
40
+ export const CARD_BRANDS: readonly ["visa", "mastercard", "american-express", "discover", "diners-club", "jcb", "unionpay", "maestro", "elo", "hiper", "hipercard", "mir", "unknown"];
41
+ declare const CARD_ICON_POSITIONS: readonly ["left", "right", "none"];
42
+ declare 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"];
43
+ export type FieldErrorType = 'incomplete' | 'invalid';
44
+ export type ConfigErrorType = 'missing-configuration' | 'missing-permission' | 'invalid-configuration';
45
+ export interface ConfigError {
46
+ type: ConfigErrorType;
47
+ message: string;
48
+ }
49
+ export interface Targeted {
50
+ targetId: string;
51
+ }
52
+ export type ListenableKey = 'Escape' | 'Enter';
53
+ export interface FieldError {
54
+ targetId: string;
55
+ type: FieldErrorType;
56
+ }
57
+ export interface PropertyError {
58
+ type: FieldErrorType;
59
+ }
60
+ export interface ElementMetadata {
61
+ complete: boolean;
62
+ valid: boolean;
63
+ maskSatisfied?: boolean;
64
+ empty: boolean;
65
+ errors?: FieldError[] | Omit<FieldError, 'targetId'>[];
66
+ }
67
+ export interface CardMetadata {
68
+ cardBrand: Brand;
69
+ cardLast4?: string;
70
+ cardBin?: string;
71
+ }
72
+ /**
73
+ * Card brands type
74
+ */
75
+ export type Brand = (typeof CARD_BRANDS)[number];
76
+ /**
77
+ * Icon position for card number element
78
+ */
79
+ export type CardIconPosition = (typeof CARD_ICON_POSITIONS)[number];
80
+ /**
81
+ * Values for the element input autocomplete attribute
82
+ */
83
+ export type AutoCompleteValue = (typeof AUTOCOMPLETE_VALUES)[number];
84
+ /**
85
+ * Type used for detokenization responses stored on Data Elements
86
+ */
87
+ export type DataElementReference = {
88
+ correlationId: string;
89
+ elementId: string;
90
+ path: string;
91
+ };
92
+ export type EventType = 'ready' | 'change' | 'focus' | 'blur' | 'keydown';
93
+ export interface BaseEvent<T extends EventType> {
94
+ type: T;
95
+ }
96
+ export type ReadyEvent = BaseEvent<'ready'>;
97
+ export type ChangeEvent = BaseEvent<'change'> & {
98
+ empty: boolean;
99
+ complete: boolean;
100
+ valid?: boolean;
101
+ maskSatisfied?: boolean;
102
+ errors?: FieldError[];
103
+ };
104
+ export type CardChangeEvent = ChangeEvent & {
105
+ cardBrand: Brand;
106
+ cardLast4?: string;
107
+ cardBin?: string;
108
+ };
109
+ export type InputFocusEvent = BaseEvent<'focus'> & Targeted;
110
+ export type InputBlurEvent = BaseEvent<'blur'> & Targeted;
111
+ export type InputKeydownEvent = BaseEvent<'keydown'> & Targeted & {
112
+ key: ListenableKey;
113
+ } & Pick<KeyboardEvent, 'altKey' | 'ctrlKey' | 'shiftKey' | 'metaKey'>;
114
+ export type BaseElementEvents = ReadyEvent | InputFocusEvent | InputBlurEvent | InputKeydownEvent;
115
+ export type TextElementEvents = BaseElementEvents | ChangeEvent;
116
+ export type CardElementEvents = BaseElementEvents | CardChangeEvent;
117
+ export type CardNumberElementEvents = BaseElementEvents | CardChangeEvent;
118
+ export type CardExpirationDateElementEvents = BaseElementEvents | ChangeEvent;
119
+ export type CardVerificationCodeElementEvents = BaseElementEvents | ChangeEvent;
120
+ /**
121
+ * Utility type that helps find a Union type based on a `type` property
122
+ */
123
+ type FindByType<Union, Type> = Union extends {
124
+ type: Type;
125
+ } ? Union : never;
126
+ export type ElementEventListener<Events, Type> = (event: FindByType<Events, Type>) => void;
127
+ export interface Subscription {
128
+ unsubscribe(): void;
129
+ }
130
+ export const SAFE_CSS_PROPERTIES: readonly ["backgroundColor", "color", "fontFamily", "fontSize", "fontSmooth", "fontStyle", "fontVariant", "fontWeight", "lineHeight", "letterSpacing", "textAlign", "padding", "textDecoration", "textShadow", "textTransform"];
131
+ export type SafeCSSProperty = (typeof SAFE_CSS_PROPERTIES)[number];
132
+ export const SAFE_CSS_PROPERTIES_ALTERNATES: Partial<Record<SafeCSSProperty, string[]>>;
133
+ export const SAFE_CSS_PROPERTIES_WITH_ALTERNATES: string[];
134
+ export type SafeStyle = Pick<Properties, SafeCSSProperty>;
135
+ export const CARD_ELEMENT_STYLE_VARIANT_SELECTORS: readonly [":hover", ":focus", ":read-only", "::placeholder", "::selection", ":disabled"];
136
+ export type CardElementStyleVariantSelector = (typeof CARD_ELEMENT_STYLE_VARIANT_SELECTORS)[number];
137
+ export type CardElementStyleVariantStyle = SafeStyle & Partial<Record<CardElementStyleVariantSelector, SafeStyle>>;
138
+ export const CARD_ELEMENT_STYLE_VARIANTS: readonly ["base", "complete", "invalid", "empty"];
139
+ export const CARD_ELEMENT_STYLE_FONTS_ATTR: "fonts";
140
+ export type CardElementStyleVariant = (typeof CARD_ELEMENT_STYLE_VARIANTS)[number];
141
+ type CardElementStyleFontAttr = typeof CARD_ELEMENT_STYLE_FONTS_ATTR;
142
+ type FontSource = string;
143
+ export type FontSources = FontSource[];
144
+ export type Fonts = Record<CardElementStyleFontAttr, FontSources>;
145
+ export type CardElementStyle = Partial<Record<CardElementStyleVariant, CardElementStyleVariantStyle> & Fonts>;
146
+ export type ElementStyle = CardElementStyle;
147
+ export type CopyIconStyles = {
148
+ size?: string;
149
+ color?: string;
150
+ successColor?: string;
151
+ };
152
+ export const ELEMENTS_TYPES: readonly ["card", "cardExpirationDate", "cardNumber", "cardVerificationCode", "data", "text"];
153
+ export type ElementType = (typeof ELEMENTS_TYPES)[number];
154
+ export interface ElementInternalOptions {
155
+ apiKey: string | undefined;
156
+ baseUrl: string;
157
+ type: ElementType;
158
+ useNgApi: boolean | undefined;
159
+ useSameOriginApi: boolean | undefined;
160
+ }
161
+ export enum InputMode {
162
+ DECIMAL = "decimal",
163
+ EMAIL = "email",
164
+ NONE = "none",
165
+ NUMERIC = "numeric",
166
+ SEARCH = "search",
167
+ TEL = "tel",
168
+ TEXT = "text",
169
+ URL = "url"
170
+ }
171
+ export interface SanitizedElementOptions {
172
+ ariaDescription?: string;
173
+ ariaLabel?: string;
174
+ autoComplete?: AutoCompleteValue;
175
+ cardBrand?: string;
176
+ cardTypes?: CreditCardType[];
177
+ copyIconStyles?: CopyIconStyles;
178
+ disabled?: boolean;
179
+ enableCopy?: boolean;
180
+ iconPosition?: string;
181
+ inputMode?: `${InputMode}`;
182
+ mask?: (RegExp | string)[];
183
+ maxLength?: HTMLInputElement['maxLength'];
184
+ password?: boolean;
185
+ placeholder?: string;
186
+ readOnly?: boolean;
187
+ skipLuhnValidation?: boolean;
188
+ style?: ElementStyle;
189
+ targetId?: string;
190
+ transform?: [RegExp, string] | null;
191
+ validateOnChange?: boolean;
192
+ validation?: RegExp;
193
+ value?: CardElementValue<'static'> | CardExpirationDateValue<'static'> | string;
194
+ }
195
+ export type ElementOptions = ElementInternalOptions & SanitizedElementOptions;
196
+ export type Transform = RegExp | [RegExp, string?] | null;
197
+ interface TransformOption {
198
+ transform?: Transform;
199
+ }
200
+ interface AutoCompleteOption {
201
+ autoComplete?: AutoCompleteValue;
202
+ }
203
+ export type CustomizableElementOptions = Pick<ElementOptions, 'cardTypes' | 'copyIconStyles' | 'disabled' | 'enableCopy' | 'inputMode' | 'readOnly' | 'skipLuhnValidation' | 'style' | 'validateOnChange'> & AutoCompleteOption;
204
+ type ElementValueType = 'static' | 'reference';
205
+ export interface CardElementValue<T extends ElementValueType> {
206
+ cvc?: T extends 'reference' ? DataElementReference : string;
207
+ expiration_month?: T extends 'reference' ? DataElementReference : number;
208
+ expiration_year?: T extends 'reference' ? DataElementReference : number;
209
+ number?: T extends 'reference' ? DataElementReference : string;
210
+ }
211
+ export interface CardElementPlaceholder {
212
+ cardNumber?: string;
213
+ cardExpirationDate?: string;
214
+ cardSecurityCode?: string;
215
+ }
216
+ export interface CardExpirationDateValue<T extends ElementValueType> {
217
+ month: T extends 'reference' ? DataElementReference : number;
218
+ year: T extends 'reference' ? DataElementReference : number;
219
+ }
220
+ export type CreateCardElementOptions = CustomizableElementOptions & Pick<ElementOptions, 'cardTypes' | 'skipLuhnValidation'> & {
221
+ placeholder?: CardElementPlaceholder;
222
+ value?: CardElementValue<'static'>;
223
+ };
224
+ export type UpdateCardElementOptions = Omit<CreateCardElementOptions, 'validateOnChange' | 'enableCopy'>;
225
+ export type CreateTextElementOptions = CustomizableElementOptions & Pick<ElementOptions, 'placeholder' | 'mask' | 'maxLength' | 'password' | 'validation'> & TransformOption & Required<Pick<ElementOptions, 'targetId'>> & {
226
+ 'aria-label'?: string;
227
+ value?: string;
228
+ };
229
+ export type UpdateTextElementOptions = Omit<CreateTextElementOptions, 'targetId' | 'mask' | 'validateOnChange'>;
230
+ export type CreateCardNumberElementOptions = CustomizableElementOptions & Pick<ElementOptions, 'placeholder' | 'iconPosition' | 'cardTypes' | 'skipLuhnValidation'> & Required<Pick<ElementOptions, 'targetId'>> & {
231
+ 'aria-label'?: string;
232
+ value?: string;
233
+ };
234
+ export type UpdateCardNumberElementOptions = Omit<CreateCardNumberElementOptions, 'targetId' | 'validateOnChange' | 'enableCopy'>;
235
+ export type CreateCardExpirationDateElementOptions = CustomizableElementOptions & Pick<ElementOptions, 'placeholder'> & Required<Pick<ElementOptions, 'targetId'>> & {
236
+ 'aria-label'?: string;
237
+ value?: CardExpirationDateValue<'static'> | string;
238
+ };
239
+ export type UpdateCardExpirationDateElementOptions = Omit<CreateCardExpirationDateElementOptions, 'targetId' | 'validateOnChange' | 'enableCopy'>;
240
+ export type CreateCardVerificationCodeElementOptions = CustomizableElementOptions & Pick<ElementOptions, 'placeholder' | 'cardBrand'> & Required<Pick<ElementOptions, 'targetId'>> & {
241
+ 'aria-label'?: string;
242
+ value?: string;
243
+ };
244
+ export type UpdateCardVerificationCodeElementOptions = Omit<CreateCardVerificationCodeElementOptions, 'targetId' | 'validateOnChange' | 'enableCopy'>;
245
+ export interface BinDetails {
246
+ cardBrand?: string;
247
+ type?: string;
248
+ prepaid?: boolean;
249
+ cardSegmentType?: string;
250
+ reloadable?: boolean;
251
+ panOrToken?: string;
252
+ accountUpdater?: boolean;
253
+ alm?: boolean;
254
+ domesticOnly?: boolean;
255
+ gamblingBlocked?: boolean;
256
+ level2?: boolean;
257
+ level3?: boolean;
258
+ issuerCurrency?: string;
259
+ comboCard?: string;
260
+ binLength?: number;
261
+ authentication?: unknown;
262
+ cost?: unknown;
263
+ bank?: BinDetailsBank;
264
+ country?: BinDetailsCountry;
265
+ product?: BinDetailsProduct;
266
+ }
267
+ export interface BinDetailsBank {
268
+ name?: string;
269
+ phone?: string;
270
+ url?: string;
271
+ cleanName?: string;
272
+ }
273
+ export interface BinDetailsCountry {
274
+ alpha2?: string;
275
+ name?: string;
276
+ numeric?: string;
277
+ }
278
+ export interface BinDetailsProduct {
279
+ code?: string;
280
+ name?: string;
281
+ }
282
+ export type Primitive = string | number | boolean | null;
283
+ export type TokenType = 'token' | 'card' | 'bank' | 'card_number' | 'us_bank_routing_number' | 'us_bank_account_number' | 'social_security_number';
284
+ export interface Auditable {
285
+ createdBy?: string;
286
+ createdAt?: string;
287
+ modifiedBy?: string;
288
+ modifiedAt?: string;
289
+ }
290
+ export type DataObject<DataType = Primitive> = {
291
+ [member: string]: TokenData<DataType>;
292
+ };
293
+ type DataArray<DataType> = Array<TokenData<DataType>>;
294
+ type TokenData<DataType = Primitive> = Primitive | DataObject<DataType> | DataArray<DataType> | DataType;
295
+ export interface TokenBase<DataType = Primitive> extends Auditable {
296
+ data: TokenData<DataType>;
297
+ type: TokenType;
298
+ }
299
+ export interface ReactResponse {
300
+ tokens: DataObject;
301
+ raw: DataObject;
302
+ }
303
+ export const DATA_CLASSIFICATIONS: readonly ["general", "bank", "pci", "pii"];
304
+ export type DataClassification = (typeof DATA_CLASSIFICATIONS)[number];
305
+ export const DATA_IMPACT_LEVELS: readonly ["low", "moderate", "high"];
306
+ export type DataImpactLevel = (typeof DATA_IMPACT_LEVELS)[number];
307
+ export const DATA_RESTRICTION_POLICIES: readonly ["mask", "redact"];
308
+ export type DataRestrictionPolicy = (typeof DATA_RESTRICTION_POLICIES)[number];
309
+ type MaskObject = {
310
+ [member: string]: TokenMask;
311
+ };
312
+ type MaskArray = Array<TokenMask>;
313
+ type TokenMask = string | null | MaskObject | MaskArray;
314
+ interface TokenEncryptionKey {
315
+ key: string;
316
+ alg: string;
317
+ }
318
+ interface TokenEncryption {
319
+ cek: TokenEncryptionKey;
320
+ kek: TokenEncryptionKey;
321
+ }
322
+ interface TokenPrivacy {
323
+ classification?: DataClassification;
324
+ impactLevel?: DataImpactLevel;
325
+ restrictionPolicy?: DataRestrictionPolicy;
326
+ }
327
+ export interface TokenEnrichments {
328
+ binDetails?: BinDetails;
329
+ }
330
+ export type Token<DataType = Primitive> = TokenBase<DataType> & {
331
+ id: string;
332
+ privacy?: TokenPrivacy;
333
+ containers?: string[];
334
+ encryption?: TokenEncryption;
335
+ searchIndexes?: string[];
336
+ fingerprintExpression?: string;
337
+ mask?: TokenMask;
338
+ expiresAt?: string;
339
+ enrichments?: TokenEnrichments;
340
+ tenantId: string;
341
+ fingerprint?: string;
342
+ metadata?: Record<string, string>;
343
+ };
344
+ export type CreateTokenModel<DataType = Primitive> = Pick<Token<DataType>, 'type' | 'data' | 'privacy' | 'containers' | 'metadata' | 'encryption' | 'searchIndexes' | 'fingerprintExpression' | 'mask' | 'expiresAt'> & {
345
+ deduplicateToken?: boolean;
346
+ id?: string;
347
+ };
348
+ export type UpdateTokenModel<DataType = Primitive> = Partial<Pick<Token<DataType>, 'data' | 'containers' | 'metadata' | 'encryption' | 'searchIndexes' | 'fingerprintExpression' | 'mask' | 'expiresAt'> & {
349
+ privacy: Omit<TokenPrivacy, 'classification'>;
350
+ deduplicateToken: boolean;
351
+ }>;
352
+ export type TokenizeObject<DataType = Primitive> = {
353
+ [key: string]: Primitive | TokenizeObject<DataType> | TokenizeArray<DataType> | DataType;
354
+ };
355
+ export type TokenizeArray<DataType = Primitive> = Array<Primitive | TokenizeObject<DataType> | TokenizeArray<DataType> | DataType>;
356
+ export type TokenizeDataModel<DataType = Primitive> = TokenizeArray<DataType> | TokenizeObject<DataType>;
357
+ export interface Card {
358
+ number: string;
359
+ expirationMonth?: number;
360
+ expirationYear?: number;
361
+ cvc?: string;
362
+ }
363
+ export interface IssuerCountry {
364
+ alpha2: string;
365
+ name: string;
366
+ numeric: string;
367
+ }
368
+ /**
369
+ * Make all properties in T nullable
370
+ */
371
+ export type Nullable<T> = {
372
+ [P in keyof T]: T[P] | null;
373
+ };
374
+ /**
375
+ * Make selected properties in T nullable
376
+ */
377
+ export type NullableProps<T, K extends keyof T> = T | Nullable<Pick<T, K>>;
378
+ export interface TokenIntentCardDetails {
379
+ type: 'card';
380
+ card: {
381
+ bin: string;
382
+ last4: string;
383
+ brand: string;
384
+ funding: string;
385
+ expirationMonth: number;
386
+ expirationYear: number;
387
+ issuerCountry?: IssuerCountry;
388
+ };
389
+ }
390
+ interface TokenIntentBankDetails {
391
+ type: 'bank';
392
+ bank: {
393
+ routingNumber: string;
394
+ accountNumberLast4: string;
395
+ };
396
+ }
397
+ type TokenTypesForTokenIntents = Exclude<TokenType, 'token' | 'card' | 'bank'>;
398
+ type TokenTypeMap = {
399
+ [K in TokenTypesForTokenIntents]: {
400
+ type: K;
401
+ } & Record<K, Record<string, unknown>>;
402
+ };
403
+ export type TokenIntent<DataType = DataObject> = (TokenBase<DataType> & Omit<Auditable, 'modifiedAt' | 'modifiedBy'> & {
404
+ id: string;
405
+ tenantId: string;
406
+ expiresAt: string;
407
+ fingerprint?: string;
408
+ }) & (TokenTypeMap[TokenTypesForTokenIntents] | TokenIntentCardDetails | TokenIntentBankDetails | {
409
+ type: 'token';
410
+ });
411
+ export type CreateTokenIntentModel<DataType = DataObject> = Pick<TokenIntent<DataType>, 'type' | 'data'>;
412
+ interface RequestOptions {
413
+ apiKey?: string;
414
+ correlationId?: string;
415
+ idempotencyKey?: string;
416
+ }
417
+ type Create<T, C> = {
418
+ create(model: C, options?: RequestOptions): Promise<T>;
419
+ };
420
+ type Retrieve<T> = {
421
+ retrieve(id: string, options?: RequestOptions): Promise<T>;
422
+ };
423
+ type Update<T, U> = {
424
+ update(id: string, model: U, options?: RequestOptions): Promise<T>;
425
+ };
426
+ export type TokenizeData = TokenizeDataModel<ElementValue>;
427
+ export interface Tokenize {
428
+ tokenize(tokens: TokenizeData, options?: RequestOptions): Promise<TokenizeDataModel>;
429
+ }
430
+ export type CreateToken = CreateTokenModel<ElementValue>;
431
+ export type UpdateToken = UpdateTokenModel<ElementValue>;
432
+ export type Tokens = Create<Token, CreateToken> & Retrieve<Token<any>> & Update<Token, UpdateToken>;
433
+ type BasisTheoryProxyHeaders = {
434
+ [key: string]: string;
435
+ 'BT-PROXY-URL': string;
436
+ 'BT-PROXY-KEY': string;
437
+ };
438
+ type ProxyHeaders = Partial<BasisTheoryProxyHeaders>;
439
+ type BasisTheoryQueryParams = {
440
+ [key: string]: string;
441
+ 'bt-proxy-key': string;
442
+ };
443
+ type ProxyQuery = Partial<BasisTheoryQueryParams>;
444
+ export interface ProxyRequestOptions extends RequestOptions {
445
+ includeResponseHeaders?: boolean;
446
+ path?: string;
447
+ query?: ProxyQuery;
448
+ headers?: ProxyHeaders;
449
+ body?: unknown;
450
+ }
451
+ export interface Proxy {
452
+ get(options?: ProxyRequestOptions): Promise<unknown>;
453
+ post(options?: ProxyRequestOptions): Promise<unknown>;
454
+ patch(options?: ProxyRequestOptions): Promise<unknown>;
455
+ put(options?: ProxyRequestOptions): Promise<unknown>;
456
+ delete(options?: ProxyRequestOptions): Promise<unknown>;
457
+ }
458
+ export type CreateTokenIntent = CreateTokenIntentModel<ElementValue>;
459
+ export type TokenIntents = Create<TokenIntent, CreateTokenIntent>;
460
+ type CreateSessionResponse = {
461
+ sessionKey: string;
462
+ nonce: string;
463
+ expiresAt: string;
464
+ _debug?: Record<string, unknown>;
465
+ };
466
+ interface Sessions {
467
+ create(options?: RequestOptions): Promise<CreateSessionResponse>;
468
+ }
469
+ export interface BaseElement<UpdateOptions, ElementEvents> {
470
+ readonly mounted: boolean;
471
+ readonly metadata: ElementMetadata;
472
+ mount(selector: string): Promise<void>;
473
+ mount(element: Element): Promise<void>;
474
+ update(options: UpdateOptions): Promise<void>;
475
+ clear(): void;
476
+ focus(): void;
477
+ blur(): void;
478
+ unmount(): void;
479
+ on<T extends EventType>(eventType: T, listener: ElementEventListener<ElementEvents, T>): Subscription;
480
+ }
481
+ export type ICardElement = BaseElement<UpdateCardElementOptions, CardElementEvents> & {
482
+ readonly cardMetadata?: CardMetadata;
483
+ setValue(value: CardElementValue<'reference'>): void;
484
+ validate(): void;
485
+ };
486
+ export type ITextElement = BaseElement<UpdateTextElementOptions, TextElementEvents> & {
487
+ setValueRef(value: ITextElement): void;
488
+ setValue(value: DataElementReference): void;
489
+ };
490
+ export type ICardNumberElement = BaseElement<UpdateCardNumberElementOptions, CardNumberElementEvents> & {
491
+ readonly cardMetadata?: CardMetadata;
492
+ setValueRef(value: ICardNumberElement): void;
493
+ setValue(value: DataElementReference): void;
494
+ };
495
+ export type ICardExpirationDateElement = BaseElement<UpdateCardExpirationDateElementOptions, CardExpirationDateElementEvents> & {
496
+ setValueRef(value: ICardExpirationDateElement): void;
497
+ setValue(value: CardExpirationDateValue<'reference'>): void;
498
+ month(): ElementWrapper<ICardExpirationDateElement>;
499
+ year(): ElementWrapper<ICardExpirationDateElement>;
500
+ format(dateFormat: string): ElementWrapper<ICardExpirationDateElement>;
501
+ };
502
+ export type ICardVerificationCodeElement = BaseElement<UpdateCardVerificationCodeElementOptions, CardVerificationCodeElementEvents> & {
503
+ setValueRef(value: ICardVerificationCodeElement): void;
504
+ setValue(value: DataElementReference): void;
505
+ };
506
+ export type ElementWrapper<T extends BaseElement<any, any> = BaseElement<any, any>> = {
507
+ element: T;
508
+ method?: string;
509
+ formattingOptions?: {
510
+ format: string;
511
+ };
512
+ };
513
+ export type ElementValue = ITextElement | ICardElement | ICardNumberElement | ICardExpirationDateElement | ICardVerificationCodeElement | ElementWrapper;
514
+ export interface BasisTheoryElements {
515
+ tokens: Tokens;
516
+ proxy: Proxy;
517
+ sessions: Sessions;
518
+ tokenIntents: TokenIntents;
519
+ tokenize: Tokenize['tokenize'];
520
+ client: HttpClient;
521
+ createElement(type: 'card', options?: CreateCardElementOptions): ICardElement;
522
+ createElement(type: 'text', options: CreateTextElementOptions): ITextElement;
523
+ createElement(type: 'cardNumber', options: CreateCardNumberElementOptions): ICardNumberElement;
524
+ createElement(type: 'cardExpirationDate', options: CreateCardExpirationDateElementOptions): ICardExpirationDateElement;
525
+ createElement(type: 'cardVerificationCode', options: CreateCardVerificationCodeElementOptions): ICardVerificationCodeElement;
526
+ }
527
+ export interface BasisTheoryElementsInternal extends BasisTheoryElements {
528
+ init: (apiKey: string | undefined, elementsBaseUrl: string, elementsUseNgApi: boolean | undefined, elementsUseSameOriginApi: boolean | undefined, disableTelemetry: boolean | undefined, debug: boolean | undefined) => Promise<BasisTheoryElements>;
529
+ hasElement: (payload: unknown) => boolean;
530
+ }
531
+ declare global {
532
+ interface Window {
533
+ BasisTheoryElements?: BasisTheoryElementsInternal;
534
+ }
535
+ }
536
+ export interface BasisTheoryInitOptions {
537
+ _devMode?: boolean;
538
+ disableTelemetry?: boolean;
539
+ useSameOriginApi?: boolean;
540
+ debug?: boolean;
541
+ }
542
+ export const basistheory: (apiKey: string, options?: BasisTheoryInitOptions) => Promise<BasisTheoryElements | undefined>;
543
+ declare global {
544
+ interface Window {
545
+ basistheory?: typeof basistheory;
546
+ }
547
+ }
548
+ interface BasisTheoryProviderProps {
549
+ bt?: BasisTheoryElements;
550
+ }
551
+ export const BasisTheoryProvider: ({ bt, children, }: PropsWithChildren<BasisTheoryProviderProps>) => JSX.Element;
552
+ export const useBasisTheory: (apiKey?: string, options?: BasisTheoryInitOptions) => {
553
+ bt: BasisTheoryElements | undefined;
554
+ error: Error | undefined;
555
+ } | {
556
+ bt: BasisTheoryElements | undefined;
557
+ error?: undefined;
558
+ };
559
+ export interface CardElementProps {
560
+ autoComplete?: CreateCardElementOptions['autoComplete'];
561
+ bt?: BasisTheoryElements;
562
+ cardTypes?: CreditCardType[];
563
+ copyIconStyles?: CopyIconStyles;
564
+ disabled?: boolean;
565
+ enableCopy?: boolean;
566
+ id: string;
567
+ inputMode?: `${InputMode}`;
568
+ onBlur?: ElementEventListener<CardElementEvents, 'blur'>;
569
+ onChange?: ElementEventListener<CardElementEvents, 'change'>;
570
+ onFocus?: ElementEventListener<CardElementEvents, 'focus'>;
571
+ onKeyDown?: ElementEventListener<CardElementEvents, 'keydown'>;
572
+ onReady?: ElementEventListener<CardElementEvents, 'ready'>;
573
+ placeholder?: CardElementPlaceholder;
574
+ readOnly?: boolean;
575
+ skipLuhnValidation?: boolean;
576
+ style?: ElementStyle;
577
+ validateOnChange?: boolean;
578
+ value?: CardElementValue<'static'>;
579
+ }
580
+ export const CardElement: React.ForwardRefExoticComponent<CardElementProps & React.RefAttributes<ICardElement>>;
581
+ interface BaseTextElementProps {
582
+ 'aria-label'?: string;
583
+ autoComplete?: CreateTextElementOptions['autoComplete'];
584
+ bt?: BasisTheoryElements;
585
+ disabled?: boolean;
586
+ id: string;
587
+ inputMode?: `${InputMode}`;
588
+ maxLength?: HTMLInputElement['maxLength'];
589
+ onBlur?: ElementEventListener<TextElementEvents, 'blur'>;
590
+ onChange?: ElementEventListener<TextElementEvents, 'change'>;
591
+ onFocus?: ElementEventListener<TextElementEvents, 'focus'>;
592
+ onKeyDown?: ElementEventListener<TextElementEvents, 'keydown'>;
593
+ onReady?: ElementEventListener<TextElementEvents, 'ready'>;
594
+ placeholder?: string;
595
+ readOnly?: boolean;
596
+ style?: ElementStyle;
597
+ transform?: RegExp | [RegExp, string?];
598
+ validateOnChange?: boolean;
599
+ validation?: RegExp;
600
+ value?: string;
601
+ valueRef?: MutableRefObject<ITextElement | null>;
602
+ }
603
+ interface MaskedTextElementProps extends BaseTextElementProps {
604
+ mask?: (RegExp | string)[];
605
+ password?: false;
606
+ }
607
+ interface PasswordTextElementProps extends BaseTextElementProps {
608
+ mask?: never;
609
+ password: true;
610
+ }
611
+ export type TextElementProps = MaskedTextElementProps | PasswordTextElementProps;
612
+ export const TextElement: React.ForwardRefExoticComponent<TextElementProps & React.RefAttributes<ITextElement>>;
613
+ export interface CardNumberElementProps {
614
+ 'aria-label'?: string;
615
+ autoComplete?: CreateCardNumberElementOptions['autoComplete'];
616
+ bt?: BasisTheoryElements;
617
+ cardTypes?: CreditCardType[];
618
+ copyIconStyles?: CopyIconStyles;
619
+ disabled?: boolean;
620
+ enableCopy?: boolean;
621
+ iconPosition?: SanitizedElementOptions['iconPosition'];
622
+ id: string;
623
+ inputMode?: `${InputMode}`;
624
+ onBlur?: ElementEventListener<CardNumberElementEvents, 'blur'>;
625
+ onChange?: ElementEventListener<CardNumberElementEvents, 'change'>;
626
+ onFocus?: ElementEventListener<CardNumberElementEvents, 'focus'>;
627
+ onKeyDown?: ElementEventListener<CardNumberElementEvents, 'keydown'>;
628
+ onReady?: ElementEventListener<CardNumberElementEvents, 'ready'>;
629
+ placeholder?: string;
630
+ readOnly?: boolean;
631
+ skipLuhnValidation?: boolean;
632
+ style?: ElementStyle;
633
+ validateOnChange?: boolean;
634
+ value?: string;
635
+ valueRef?: MutableRefObject<ICardNumberElement | null>;
636
+ }
637
+ export const CardNumberElement: React.ForwardRefExoticComponent<CardNumberElementProps & React.RefAttributes<ICardNumberElement>>;
638
+ export interface CardExpirationDateElementProps {
639
+ 'aria-label'?: string;
640
+ autoComplete?: CreateCardExpirationDateElementOptions['autoComplete'];
641
+ bt?: BasisTheoryElements;
642
+ copyIconStyles?: CopyIconStyles;
643
+ disabled?: boolean;
644
+ enableCopy?: boolean;
645
+ id: string;
646
+ inputMode?: `${InputMode}`;
647
+ onBlur?: ElementEventListener<CardExpirationDateElementEvents, 'blur'>;
648
+ onChange?: ElementEventListener<CardExpirationDateElementEvents, 'change'>;
649
+ onFocus?: ElementEventListener<CardExpirationDateElementEvents, 'focus'>;
650
+ onKeyDown?: ElementEventListener<CardExpirationDateElementEvents, 'keydown'>;
651
+ onReady?: ElementEventListener<CardExpirationDateElementEvents, 'ready'>;
652
+ placeholder?: string;
653
+ readOnly?: boolean;
654
+ style?: ElementStyle;
655
+ validateOnChange?: boolean;
656
+ value?: CardExpirationDateValue<'static'> | string;
657
+ valueRef?: MutableRefObject<ICardExpirationDateElement | null>;
658
+ }
659
+ export const CardExpirationDateElement: React.ForwardRefExoticComponent<CardExpirationDateElementProps & React.RefAttributes<ICardExpirationDateElement>>;
660
+ export interface CardVerificationCodeElementProps {
661
+ 'aria-label'?: string;
662
+ autoComplete?: CreateCardVerificationCodeElementOptions['autoComplete'];
663
+ bt?: BasisTheoryElements;
664
+ cardBrand?: Brand | string;
665
+ copyIconStyles?: CopyIconStyles;
666
+ disabled?: boolean;
667
+ enableCopy?: boolean;
668
+ id: string;
669
+ inputMode?: `${InputMode}`;
670
+ onBlur?: ElementEventListener<CardVerificationCodeElementEvents, 'blur'>;
671
+ onChange?: ElementEventListener<CardVerificationCodeElementEvents, 'change'>;
672
+ onFocus?: ElementEventListener<CardVerificationCodeElementEvents, 'focus'>;
673
+ onKeyDown?: ElementEventListener<CardVerificationCodeElementEvents, 'keydown'>;
674
+ onReady?: ElementEventListener<CardVerificationCodeElementEvents, 'ready'>;
675
+ placeholder?: string;
676
+ readOnly?: boolean;
677
+ style?: ElementStyle;
678
+ validateOnChange?: boolean;
679
+ value?: string;
680
+ valueRef?: MutableRefObject<ICardVerificationCodeElement | null>;
681
+ }
682
+ export const CardVerificationCodeElement: React.ForwardRefExoticComponent<CardVerificationCodeElementProps & React.RefAttributes<ICardVerificationCodeElement>>;