@starfish-codes/hellgate 2.0.0-beta.2 → 2.0.0-beta.3

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.
Files changed (37) hide show
  1. package/README.md +21 -7
  2. package/dist/{manifest.json → .vite/manifest.json} +2 -2
  3. package/dist/__tests__/index.d.ts +1 -0
  4. package/dist/__tests__/test-utils.d.ts +2 -0
  5. package/dist/card/card-handler.d.ts +8 -6
  6. package/dist/card/consts.d.ts +1 -1
  7. package/dist/card/index.d.ts +1 -0
  8. package/dist/card/typings.d.ts +9 -5
  9. package/dist/card/ui/constants.d.ts +8 -0
  10. package/dist/card/ui/elements/base-element.d.ts +21 -0
  11. package/dist/card/ui/elements/card-expiration-date.d.ts +14 -0
  12. package/dist/card/ui/elements/card-number.d.ts +9 -0
  13. package/dist/card/ui/elements/card-verification-code.d.ts +7 -0
  14. package/dist/card/ui/elements/card.d.ts +19 -0
  15. package/dist/card/ui/elements/index.d.ts +5 -0
  16. package/dist/card/ui/elements/text-element.d.ts +7 -0
  17. package/dist/card/ui/elements/utils.d.ts +15 -0
  18. package/dist/card/ui/iframe/__tests__/iframe-elements.spec.d.ts +1 -0
  19. package/dist/card/ui/iframe/elements/base-element.d.ts +34 -0
  20. package/dist/card/ui/iframe/elements/card-expiration-date.d.ts +10 -0
  21. package/dist/card/ui/iframe/elements/card-number.d.ts +12 -0
  22. package/dist/card/ui/iframe/elements/card-verification-code.d.ts +8 -0
  23. package/dist/card/ui/iframe/elements/card.d.ts +25 -0
  24. package/dist/card/ui/iframe/elements/text-element.d.ts +8 -0
  25. package/dist/card/ui/iframe/elements/typings.d.ts +16 -0
  26. package/dist/card/ui/iframe/iframe.d.ts +2 -0
  27. package/dist/card/ui/iframe/index.d.ts +1 -0
  28. package/dist/card/ui/iframe/typings.d.ts +10 -0
  29. package/dist/card/ui/iframe/utils.d.ts +24 -0
  30. package/dist/card/ui/index.d.ts +1 -0
  31. package/dist/card/ui/styles.d.ts +20 -0
  32. package/dist/card/ui/typings.d.ts +86 -0
  33. package/dist/hellgate-sdk.mjs +1473 -1179
  34. package/dist/hellgate-sdk.umd.js +5 -5
  35. package/dist/index.d.ts +2 -0
  36. package/package.json +47 -36
  37. /package/dist/{untils.d.ts → utils.d.ts} +0 -0
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  ## Documentation
7
7
 
8
- https://developer.hellgate.io/docs/head-less-web-sdk-overview
8
+ https://developer.hellgate.dev
9
9
 
10
10
  ## Development
11
11
 
@@ -15,19 +15,33 @@ https://developer.hellgate.io/docs/head-less-web-sdk-overview
15
15
  yarn
16
16
  ```
17
17
 
18
- ### Start Demo App in dev mode
18
+ ### Start Iframe App in dev mode
19
19
 
20
- Create `demo/.env.dev` by copying `demo/.env.dev.example` and replace its variables with a real secrets
20
+ ```
21
+ yarn iframe
22
+ ```
23
+
24
+ Should be available on http://localhost:4044
25
+
26
+ ### Start Demo App in dev mode (Iframe app running is required)
27
+
28
+ 1. Create `demo/.env.dev` by copying `demo/.env.dev.example` (VITE_API_KEY is optional)
29
+
30
+ ```
31
+ cp demo/.env.dev.example demo/.env.dev
32
+ ```
33
+
34
+ 2. Run demo app
21
35
 
22
36
  ```
23
- yarn start
37
+ yarn demo
24
38
  ```
25
39
 
26
- Open http://127.0.0.1:5173/
40
+ Open http://localhost:4040
27
41
 
28
- ### Run tests locally in dev mode
42
+ ### Run tests locally in dev mode (Iframe app running is required)
29
43
 
30
- 1. Create `.env.test` by copying `.env.test.example` and replace its variables with a real secrets
44
+ 1. Create `.env.test` by copying `.env.test.example`. (VITE_BT_API_KEY is required)
31
45
 
32
46
  ```
33
47
  cp .env.test.example .env.test
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "src/index.ts": {
3
3
  "file": "hellgate-sdk.umd.js",
4
- "isEntry": true,
5
- "src": "src/index.ts"
4
+ "src": "src/index.ts",
5
+ "isEntry": true
6
6
  }
7
7
  }
@@ -0,0 +1 @@
1
+ export * from './test-utils';
@@ -0,0 +1,2 @@
1
+ export declare function wait(milliseconds: number): Promise<unknown>;
2
+ export declare function fill(input: HTMLInputElement, value: string): void;
@@ -1,8 +1,9 @@
1
- import { BasisTheoryElements, CardElement, CardExpirationDateElement, CardNumberElement, CardVerificationCodeElement, ChangeEvent, CreateCardElementOptions } from '@basis-theory/basis-theory-js/types/elements';
2
1
  import { BasisTheory as IBasisTheory } from '@basis-theory/basis-theory-js/types/sdk';
3
2
  import { HellgateSession } from '../session';
4
- import { CreateCardFieldsOptions, PaymentAdditionalData, TokenizedData } from './typings';
5
- export type FormFieldState = Omit<ChangeEvent, 'type' | 'maskSatisfied'>;
3
+ import { CreateCardFieldsOptions, CreateCardFormOptions, PaymentAdditionalData, TokenizedData } from './typings';
4
+ import { CardElement, CardExpirationDateElement, CardNumberElement, CardVerificationCodeElement } from './ui/elements';
5
+ import { CardValue, ChangeEvent, ElementBaseOptions } from './ui/typings';
6
+ export type FormFieldState = Omit<ChangeEvent<CardValue>['data'], 'type'>;
6
7
  export declare class HellgateCardHandler {
7
8
  session: HellgateSession;
8
9
  private bt;
@@ -10,13 +11,14 @@ export declare class HellgateCardHandler {
10
11
  private cardElements;
11
12
  private stateChangeHandlers;
12
13
  static init(session: HellgateSession, bt_api_key: string): Promise<HellgateCardHandler>;
13
- constructor(session: HellgateSession, bt: IBasisTheory & BasisTheoryElements);
14
- createForm: (options?: CreateCardElementOptions) => CardElement;
14
+ constructor(session: HellgateSession, bt: IBasisTheory);
15
+ createForm: (options?: CreateCardFormOptions) => CardElement;
15
16
  createFormFields: (options?: CreateCardFieldsOptions) => {
16
17
  cardNumber: CardNumberElement;
17
18
  expiryDate: CardExpirationDateElement;
18
19
  securityCode: CardVerificationCodeElement;
19
20
  };
21
+ createTextField: (options?: ElementBaseOptions) => import("./ui/elements/text-element").TextElement;
20
22
  tokenize: () => Promise<TokenizedData>;
21
23
  onStateChange: (fn: (state: FormFieldState) => void) => void;
22
24
  clear: () => void;
@@ -27,6 +29,6 @@ export declare class HellgateCardHandler {
27
29
  private disableFormElements;
28
30
  private extractAdditionalData;
29
31
  private addElementStateListener;
30
- private updateFormState;
32
+ updateFormState(): void;
31
33
  private createFieldDefaultState;
32
34
  }
@@ -1,2 +1,2 @@
1
- import { ElementStyle } from '@basis-theory/basis-theory-js/types/elements';
1
+ import { ElementStyle } from './ui/styles';
2
2
  export declare const FORM_ELEMENT_STYLE_DEFAULT: ElementStyle;
@@ -1,2 +1,3 @@
1
1
  export * from './card-handler';
2
2
  export * from './typings';
3
+ export * from './ui';
@@ -1,8 +1,11 @@
1
- import { CreateCardExpirationDateElementOptions, CreateCardNumberElementOptions, CreateCardVerificationCodeElementOptions } from '@basis-theory/basis-theory-js/types/elements';
2
- export type CreateCardFieldsOptions = Pick<CreateCardExpirationDateElementOptions, 'style' | 'disabled' | 'autoComplete' | 'validateOnChange'> & {
3
- cardNumber?: Omit<CreateCardNumberElementOptions, 'targetId'>;
4
- expiryDate?: Omit<CreateCardExpirationDateElementOptions, 'targetId'>;
5
- securityCode?: Omit<CreateCardVerificationCodeElementOptions, 'targetId'>;
1
+ import { ElementBaseOptions } from './ui/typings';
2
+ export type CreateCardFormOptions = Pick<ElementBaseOptions, 'style' | 'disabled' | 'autocomplete' | 'placeholder' | 'ariaLabel'> & {
3
+ icon?: 'left' | 'right' | 'none';
4
+ };
5
+ export type CreateCardFieldsOptions = Pick<ElementBaseOptions, 'style' | 'disabled' | 'autocomplete'> & {
6
+ cardNumber?: ElementBaseOptions;
7
+ expiryDate?: ElementBaseOptions;
8
+ securityCode?: ElementBaseOptions;
6
9
  };
7
10
  export type PaymentAdditionalData = {
8
11
  cardholder_name?: string;
@@ -16,6 +19,7 @@ export type PaymentAdditionalData = {
16
19
  country?: string;
17
20
  };
18
21
  };
22
+ export type TokenizeData = Record<string, unknown>;
19
23
  export type TokenizedData = {
20
24
  id: string;
21
25
  };
@@ -0,0 +1,8 @@
1
+ export declare const ELEMENTS_SELECTOR_INVALID = "DOM Element was not found";
2
+ export declare const ELEMENTS_INIT_ERROR_MESSAGE = "WebSDK Elements was not properly initialized.";
3
+ export declare const ELEMENTS_NON_DOM_ERROR_MESSAGE = "Tried to load WebSDKElements in a non-DOM environment.";
4
+ export declare const ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE = "WebSDK Elements did not load properly.";
5
+ export declare const ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE = "There was an unknown error when loading WebSDK Elements. Check the console for details.";
6
+ export declare const CARD_BRANDS: readonly ["visa", "mastercard", "american-express", "discover", "diners-club", "jcb", "unionpay", "maestro", "elo", "hiper", "hipercard", "mir", "unknown"];
7
+ export declare const CARD_ICON_POSITIONS: readonly ["left", "right", "none"];
8
+ export declare const AUTOCOMPLETE_VALUES: readonly ["off", "on"];
@@ -0,0 +1,21 @@
1
+ import { Explicit } from '../iframe/utils';
2
+ import { CardElementEvents, ElementBaseOptions, ElementType, EventType, FindByType, Subscription } from '../typings';
3
+ export declare abstract class CardElementBase<Value, IframeValue = string> {
4
+ readonly options: ElementBaseOptions<Value>;
5
+ private iframe;
6
+ private subscriptions;
7
+ value: Value | null;
8
+ protected abstract type: ElementType;
9
+ protected abstract extractValue: (rawValue: IframeValue | null) => Value | null;
10
+ protected abstract putValue: (rawValue: Value | null) => IframeValue | null;
11
+ constructor(options: ElementBaseOptions<Value>);
12
+ mount(selector: string | Element): Promise<void>;
13
+ update: ({ ...data }: ElementBaseOptions<Value>) => Promise<void>;
14
+ clear: () => void;
15
+ focus: () => void;
16
+ blur: () => void;
17
+ unmount: () => void;
18
+ on<T extends EventType>(eventType: T, listener: (event: FindByType<Explicit<CardElementEvents<Value>>, T>['data']) => void): Subscription;
19
+ private emitEvent;
20
+ private iframePostMessage;
21
+ }
@@ -0,0 +1,14 @@
1
+ import { CardExpirationDateValue, ElementType } from '../typings';
2
+ import { CardElementBase } from './base-element';
3
+ export declare function extractExpiryDateValue(rawValue: string | null): {
4
+ month: number | null;
5
+ year: number | null;
6
+ };
7
+ export declare function putExpiryDateValue(rawValue: CardExpirationDateValue | null): string | null;
8
+ export declare class CardExpirationDateElement extends CardElementBase<CardExpirationDateValue> {
9
+ protected type: ElementType;
10
+ protected extractValue: typeof extractExpiryDateValue;
11
+ protected putValue: typeof putExpiryDateValue;
12
+ month: () => number | null;
13
+ year: () => number | null;
14
+ }
@@ -0,0 +1,9 @@
1
+ import { ElementType } from '../typings';
2
+ import { CardElementBase } from './base-element';
3
+ export declare function extractCardNumberValue(rawValue: string | null): string | null;
4
+ export declare function putCardNumberValue(rawValue: string | null): string | null;
5
+ export declare class CardNumberElement extends CardElementBase<string> {
6
+ protected type: ElementType;
7
+ protected extractValue: typeof extractCardNumberValue;
8
+ protected putValue: typeof putCardNumberValue;
9
+ }
@@ -0,0 +1,7 @@
1
+ import { ElementType } from '../typings';
2
+ import { CardElementBase } from './base-element';
3
+ export declare class CardVerificationCodeElement extends CardElementBase<string> {
4
+ protected type: ElementType;
5
+ protected extractValue: (rawValue: string | null) => string | null;
6
+ protected putValue: (rawValue: string | null) => string | null;
7
+ }
@@ -0,0 +1,19 @@
1
+ import { IframeCardValue } from '../iframe/typings';
2
+ import { CardValue, ElementType } from '../typings';
3
+ import { CardElementBase } from './base-element';
4
+ export declare class CardElement extends CardElementBase<CardValue, IframeCardValue> {
5
+ protected type: ElementType;
6
+ protected extractValue: (rawValue: IframeCardValue | null) => {
7
+ number: string | null;
8
+ expiry_date: {
9
+ month: number | null;
10
+ year: number | null;
11
+ } | null;
12
+ cvc: string | null;
13
+ } | null;
14
+ protected putValue: (rawValue: CardValue | null) => {
15
+ cardNumber: string | null;
16
+ cardExpirationDate: string | null;
17
+ cardVerificationCode: string | null;
18
+ } | null;
19
+ }
@@ -0,0 +1,5 @@
1
+ export * from './card';
2
+ export * from './card-expiration-date';
3
+ export * from './card-number';
4
+ export * from './card-verification-code';
5
+ export * from './utils';
@@ -0,0 +1,7 @@
1
+ import { ElementType } from '../typings';
2
+ import { CardElementBase } from './base-element';
3
+ export declare class TextElement extends CardElementBase<string> {
4
+ protected type: ElementType;
5
+ protected extractValue: (rawValue: string | null) => string | null;
6
+ protected putValue: (rawValue: string | null) => string | null;
7
+ }
@@ -0,0 +1,15 @@
1
+ import { ElementBaseOptions } from '../typings';
2
+ import { CardElement } from './card';
3
+ import { CardExpirationDateElement } from './card-expiration-date';
4
+ import { CardNumberElement } from './card-number';
5
+ import { CardVerificationCodeElement } from './card-verification-code';
6
+ import { TextElement } from './text-element';
7
+ type Elements = {
8
+ card: CardElement;
9
+ cardNumber: CardNumberElement;
10
+ cardExpirationDate: CardExpirationDateElement;
11
+ cardVerificationCode: CardVerificationCodeElement;
12
+ text: TextElement;
13
+ };
14
+ export declare function createElement<T extends keyof Elements>(type: T, options: ElementBaseOptions): Elements[T];
15
+ export {};
@@ -0,0 +1,34 @@
1
+ import { CreditCardType } from 'credit-card-type/dist/types';
2
+ import { FactoryArg, InputMask, Masked } from 'imask';
3
+ import { BaseElement, CardElementEvents, ElementBaseOptions, ElementEventListener, ElementMetadata, ElementType, EventType, Subscription } from '../../typings';
4
+ export type PostMessageOptions = {
5
+ postMessageOrigin: string;
6
+ postMessageRoot: Window;
7
+ };
8
+ export declare abstract class IframeCardElementBase implements BaseElement<ElementBaseOptions, CardElementEvents<string>, string> {
9
+ protected rootNode: Element;
10
+ protected postMessageOptions: PostMessageOptions;
11
+ protected inputNode?: HTMLInputElement;
12
+ protected subscriptions: {
13
+ [Key in EventType]: ElementEventListener<CardElementEvents<string>, Key>[];
14
+ };
15
+ abstract readonly type: ElementType;
16
+ protected abstract options: ElementBaseOptions;
17
+ protected abstract inputMaskOptions: FactoryArg;
18
+ protected inputMask?: InputMask<FactoryArg>;
19
+ private id;
20
+ cardType?: CreditCardType;
21
+ value: null;
22
+ constructor(rootNode: Element, postMessageOptions: PostMessageOptions);
23
+ mount(): Promise<void>;
24
+ unmount(): void;
25
+ focus(): void;
26
+ blur(): void;
27
+ clear(): void;
28
+ updateCardType(cardTypeName: string | undefined): void;
29
+ update(options: ElementBaseOptions): Promise<void>;
30
+ on<T extends EventType>(eventType: T, listener: ElementEventListener<CardElementEvents<string>, T>): Subscription;
31
+ private emitEvent;
32
+ protected validate(masked: Masked): ElementMetadata;
33
+ protected renderHTML(): string;
34
+ }
@@ -0,0 +1,10 @@
1
+ import { FactoryArg, Masked } from 'imask';
2
+ import { ElementBaseOptions, ElementMetadata, ElementType, ITextElement } from '../../typings';
3
+ import { IframeCardElementBase } from './base-element';
4
+ export declare class IframeCardExpirationDate extends IframeCardElementBase implements ITextElement {
5
+ readonly type: ElementType;
6
+ protected options: ElementBaseOptions;
7
+ compiledMask?: Masked;
8
+ protected inputMaskOptions: FactoryArg;
9
+ protected validate(masked: Masked): ElementMetadata;
10
+ }
@@ -0,0 +1,12 @@
1
+ import { FactoryArg, Masked } from 'imask';
2
+ import { CardNumberAdditionalData, ElementBaseOptions, ElementMetadata, ElementType, ITextElement } from '../../typings';
3
+ import { IframeCardElementBase } from './base-element';
4
+ export type IconPosition = 'left' | 'right' | 'none';
5
+ export declare class IframeCardNumber extends IframeCardElementBase implements ITextElement {
6
+ readonly type: ElementType;
7
+ protected options: ElementBaseOptions;
8
+ protected inputMaskOptions: FactoryArg;
9
+ update(options: ElementBaseOptions): Promise<void>;
10
+ protected validate(masked: Masked): ElementMetadata & CardNumberAdditionalData;
11
+ protected renderHTML(): string;
12
+ }
@@ -0,0 +1,8 @@
1
+ import { FactoryArg } from 'imask';
2
+ import { ElementBaseOptions, ElementType, ITextElement } from '../../typings';
3
+ import { IframeCardElementBase } from './base-element';
4
+ export declare class IframeCardVerificationCode extends IframeCardElementBase implements ITextElement {
5
+ readonly type: ElementType;
6
+ protected options: ElementBaseOptions;
7
+ protected inputMaskOptions: FactoryArg;
8
+ }
@@ -0,0 +1,25 @@
1
+ import { CardElementEvents, ElementBaseOptions, ElementEventListener, ElementType, EventType, ICardElement, Subscription } from '../../typings';
2
+ import { IframeCardValue } from '../typings';
3
+ import { PostMessageOptions } from './base-element';
4
+ export declare class IframeCard implements ICardElement<IframeCardValue> {
5
+ protected rootNode: Element;
6
+ protected postMessageOptions: PostMessageOptions;
7
+ protected type: ElementType;
8
+ private elements;
9
+ value: IframeCardValue;
10
+ private options;
11
+ protected subscriptions: {
12
+ [Key in EventType]: ElementEventListener<CardElementEvents<IframeCardValue>, Key>[];
13
+ };
14
+ private id;
15
+ constructor(rootNode: Element, postMessageOptions: PostMessageOptions);
16
+ mount(): Promise<void>;
17
+ unmount(): void;
18
+ clear(): void;
19
+ focus(): void;
20
+ blur(): void;
21
+ update({ style, ...options }: ElementBaseOptions<IframeCardValue>): Promise<void>;
22
+ on<T extends EventType>(eventType: T, listener: ElementEventListener<CardElementEvents<IframeCardValue>, T>): Subscription;
23
+ private onFieldChange;
24
+ private emitEvent;
25
+ }
@@ -0,0 +1,8 @@
1
+ import { FactoryArg } from 'imask';
2
+ import { ElementBaseOptions, ElementType, ITextElement } from '../../typings';
3
+ import { IframeCardElementBase } from './base-element';
4
+ export declare class IframeTextElement extends IframeCardElementBase implements ITextElement {
5
+ readonly type: ElementType;
6
+ protected options: ElementBaseOptions;
7
+ protected inputMaskOptions: FactoryArg;
8
+ }
@@ -0,0 +1,16 @@
1
+ import { ElementEventListener, ElementMetadata, EventType, Subscription } from '../../typings';
2
+ export type IframeBaseElement = {
3
+ mount(): void;
4
+ };
5
+ export interface BaseElement<UpdateOptions, ElementEvents> {
6
+ readonly mounted: boolean;
7
+ readonly metadata: ElementMetadata;
8
+ mount(selector: string): Promise<void>;
9
+ mount(element: Element | string): Promise<void>;
10
+ update(options: UpdateOptions): Promise<void>;
11
+ clear(): void;
12
+ focus(): void;
13
+ blur(): void;
14
+ unmount(): void;
15
+ on<T extends EventType>(eventType: T, listener: ElementEventListener<ElementEvents, T>): Subscription;
16
+ }
@@ -0,0 +1,2 @@
1
+ export declare function initElementsIframe(rootId: string): void;
2
+ export declare function mountElements(rootId: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export * from './iframe';
@@ -0,0 +1,10 @@
1
+ import { BaseElement, ElementBaseOptions, ElementType } from '../typings';
2
+ type IframeEventType = keyof Pick<BaseElement<ElementBaseOptions, unknown, string>, 'blur' | 'clear' | 'focus' | 'mount' | 'unmount' | 'update'>;
3
+ interface IframeBaseEvent<T extends IframeEventType> {
4
+ type: T;
5
+ }
6
+ export type IframeCardValue = Partial<Record<Exclude<ElementType, 'card'>, string | null>>;
7
+ export type IframeEvent<Value = unknown> = IframeBaseEvent<'blur'> | IframeBaseEvent<'clear'> | IframeBaseEvent<'focus'> | IframeBaseEvent<'mount'> | IframeBaseEvent<'unmount'> | (IframeBaseEvent<'update'> & {
8
+ data: ElementBaseOptions<Value>;
9
+ });
10
+ export {};
@@ -0,0 +1,24 @@
1
+ import { ElementStyle } from '../styles';
2
+ import { ElementBaseOptions, ElementType } from '../typings';
3
+ type IframeSearchParams = {
4
+ field: ElementType;
5
+ origin: string;
6
+ };
7
+ export declare function parseURLSearchParams(): IframeSearchParams;
8
+ export declare const isNonNullable: <T>(value: T) => value is NonNullable<T>;
9
+ type ObjectKeys = string | number | symbol;
10
+ type Keys<TUnion> = TUnion extends unknown ? keyof TUnion : never;
11
+ export type Explicit<T> = Keys<T> extends infer K ? T extends unknown ? T & {
12
+ [key in K extends ObjectKeys ? K extends keyof T ? never : K : never]?: undefined;
13
+ } extends infer X ? {
14
+ [k in keyof X]: X[k];
15
+ } : never : never : never;
16
+ export declare function camelCaseToDashCase(value: string): string;
17
+ export declare function findStyleElement(name: string): Element | null;
18
+ export declare function appendStyleElement(name: string): void;
19
+ export declare function appendFontElement(href: string): void;
20
+ export declare function generateElementId(type: ElementType): string;
21
+ export declare function mergeOptions(options1: ElementBaseOptions, options2: ElementBaseOptions): ElementBaseOptions;
22
+ export declare function mergeStyles(style1: ElementStyle, style2: ElementStyle): ElementStyle;
23
+ export declare function applyStyle(id: string, { fonts, ...styles }: ElementStyle): void;
24
+ export {};
@@ -0,0 +1 @@
1
+ export * from './elements';
@@ -0,0 +1,20 @@
1
+ import type { Properties as CSSProperties } from 'csstype';
2
+ declare const SAFE_CSS_PROPERTIES: readonly ["backgroundColor", "color", "fontFamily", "fontSize", "fontSmooth", "fontStyle", "fontVariant", "fontWeight", "lineHeight", "letterSpacing", "textAlign", "padding", "textDecoration", "textShadow", "textTransform"];
3
+ type SafeCSSProperty = (typeof SAFE_CSS_PROPERTIES)[number];
4
+ declare const SAFE_CSS_PROPERTIES_ALTERNATES: Partial<Record<SafeCSSProperty, string[]>>;
5
+ declare const SAFE_CSS_PROPERTIES_WITH_ALTERNATES: string[];
6
+ type SafeStyle = Pick<CSSProperties, SafeCSSProperty>;
7
+ declare const CARD_ELEMENT_STYLE_VARIANT_SELECTORS: readonly [":hover", ":focus", ":read-only", "::placeholder", "::selection", ":disabled"];
8
+ type CardElementStyleVariantSelector = (typeof CARD_ELEMENT_STYLE_VARIANT_SELECTORS)[number];
9
+ type CardElementStyleVariantStyle = SafeStyle & Partial<Record<CardElementStyleVariantSelector, SafeStyle>>;
10
+ declare const CARD_ELEMENT_STYLE_VARIANTS: readonly ["base", "complete", "invalid", "empty"];
11
+ declare const CARD_ELEMENT_STYLE_FONTS_ATTR: "fonts";
12
+ type CardElementStyleVariant = (typeof CARD_ELEMENT_STYLE_VARIANTS)[number];
13
+ type CardElementStyleFontAttr = typeof CARD_ELEMENT_STYLE_FONTS_ATTR;
14
+ type FontSource = string;
15
+ type FontSources = FontSource[];
16
+ type Fonts = Record<CardElementStyleFontAttr, FontSources>;
17
+ type CardElementStyle = Partial<Record<CardElementStyleVariant, CardElementStyleVariantStyle> & Fonts>;
18
+ type ElementStyle = CardElementStyle;
19
+ export { CARD_ELEMENT_STYLE_FONTS_ATTR, CARD_ELEMENT_STYLE_VARIANTS, CARD_ELEMENT_STYLE_VARIANT_SELECTORS, SAFE_CSS_PROPERTIES, SAFE_CSS_PROPERTIES_ALTERNATES, SAFE_CSS_PROPERTIES_WITH_ALTERNATES, };
20
+ export type { CardElementStyle, CardElementStyleVariant, CardElementStyleVariantSelector, CardElementStyleVariantStyle, ElementStyle, FontSources, Fonts, SafeCSSProperty, SafeStyle, };
@@ -0,0 +1,86 @@
1
+ import { IconPosition } from './iframe/elements/card-number';
2
+ import { ElementStyle } from './styles';
3
+ export type ListenableKey = 'Escape' | 'Enter';
4
+ export declare const LISTENABLE_KEYS: ListenableKey[];
5
+ type EventType = 'ready' | 'change' | 'focus' | 'blur' | 'keydown';
6
+ export declare const EVENT_TYPES: EventType[];
7
+ type BaseEvent<T extends EventType, TData = unknown> = {
8
+ type: T;
9
+ element: ElementType;
10
+ } & (TData extends object ? {
11
+ data: TData;
12
+ } : unknown);
13
+ type ReadyEvent = BaseEvent<'ready'>;
14
+ type ChangeEvent<Value> = BaseEvent<'change', {
15
+ empty: boolean;
16
+ complete: boolean;
17
+ valid?: boolean;
18
+ error?: string;
19
+ value: Value | null;
20
+ }>;
21
+ type InputFocusEvent = BaseEvent<'focus'>;
22
+ type InputBlurEvent = BaseEvent<'blur'>;
23
+ type InputKeydownEvent = BaseEvent<'keydown', {
24
+ key: ListenableKey;
25
+ } & Pick<KeyboardEvent, 'altKey' | 'ctrlKey' | 'shiftKey' | 'metaKey'>>;
26
+ type BaseElementEvents = ReadyEvent | InputFocusEvent | InputBlurEvent | InputKeydownEvent;
27
+ type CardElementEvents<Value> = BaseElementEvents | ChangeEvent<Value>;
28
+ /**
29
+ * Utility type that helps find a Union type based on a `type` property
30
+ */
31
+ type FindByType<Union, Type extends EventType> = Union extends {
32
+ type: Type;
33
+ } ? Union : never;
34
+ type ElementEventListener<Events, Type extends EventType> = (event: FindByType<Events, Type>) => void;
35
+ interface Subscription {
36
+ unsubscribe(): void;
37
+ }
38
+ export type { BaseElementEvents, BaseEvent, CardElementEvents, ChangeEvent, ElementEventListener, EventType, FindByType, InputBlurEvent, InputFocusEvent, InputKeydownEvent, ReadyEvent, Subscription, };
39
+ export type ElementType = 'card' | 'cardNumber' | 'cardExpirationDate' | 'cardVerificationCode' | 'text';
40
+ export declare const ELEMENT_TYPES: ElementType[];
41
+ export type ElementMetadata = {
42
+ complete: boolean;
43
+ valid: boolean;
44
+ empty: boolean;
45
+ error?: string;
46
+ };
47
+ export interface BaseElement<UpdateOptions, ElementEvents, Value> {
48
+ value: Value | null;
49
+ mount(selector: string): Promise<void>;
50
+ mount(element: Element | string): Promise<void>;
51
+ update(options: UpdateOptions): Promise<void>;
52
+ clear(): void;
53
+ focus(): void;
54
+ blur(): void;
55
+ unmount(): void;
56
+ on<T extends EventType>(eventType: T, listener: ElementEventListener<ElementEvents, T>): Subscription;
57
+ }
58
+ export type ElementBaseOptions<Value = unknown> = {
59
+ style?: ElementStyle;
60
+ disabled?: boolean;
61
+ autocomplete?: 'on' | 'off';
62
+ placeholder?: string;
63
+ ariaLabel?: string;
64
+ icon?: IconPosition;
65
+ value?: Value;
66
+ };
67
+ /**
68
+ * Card brands type
69
+ */
70
+ export type ICardNumberElement = BaseElement<ElementBaseOptions, CardElementEvents<string>, string>;
71
+ export type CardNumberAdditionalData = {
72
+ cardBrand?: string;
73
+ };
74
+ export type CardExpirationDateValue = {
75
+ month: number | null;
76
+ year: number | null;
77
+ };
78
+ export type ICardExpirationDateElement = BaseElement<ElementBaseOptions, CardElementEvents<CardExpirationDateValue>, CardExpirationDateValue>;
79
+ export type ICardVerificationCodeElement = BaseElement<ElementBaseOptions, CardElementEvents<string>, string>;
80
+ export type ITextElement = BaseElement<ElementBaseOptions, CardElementEvents<string>, string>;
81
+ export type CardValue = {
82
+ number: string | null;
83
+ expiry_date: CardExpirationDateValue | null;
84
+ cvc: string | null;
85
+ };
86
+ export type ICardElement<Value = CardValue> = BaseElement<ElementBaseOptions, CardElementEvents<Value>, Value>;