@primer-io/primer-js 0.1.2 → 0.1.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.
@@ -88,6 +88,8 @@ This is used to control the CSS-only loader visibility */
88
88
  vaultManagerController?: VaultManagerController;
89
89
  /** */
90
90
  cardNetworkController?: CardNetworkController;
91
+ /** */
92
+ achPaymentEventsController?: AchPaymentEventsController;
91
93
  };
92
94
 
93
95
  export type ButtonComponentProps = {
@@ -136,6 +138,11 @@ export type CollapsableComponentProps = {
136
138
  "onexpanded-changed"?: (e: CustomEvent<CustomEvent>) => void;
137
139
  };
138
140
 
141
+ export type DialogComponentProps = {
142
+ /** */
143
+ "onprimer-dialog-close"?: (e: CustomEvent<CustomEvent>) => void;
144
+ };
145
+
139
146
  export type ErrorMessageComponentProps = {
140
147
  /** The error message text to display */
141
148
  message?: string;
@@ -226,6 +233,13 @@ export type InputWrapperComponentProps = {
226
233
  "onwrapper-click"?: (e: CustomEvent<CustomEvent>) => void;
227
234
  };
228
235
 
236
+ export type PortalComponentProps = {
237
+ /** */
238
+ id?: string;
239
+ /** */
240
+ oneventName?: (e: CustomEvent<CustomEvent>) => void;
241
+ };
242
+
229
243
  export type SpinnerComponentProps = {
230
244
  /** Color of the spinner
231
245
  Defaults to the design system loader color */
@@ -238,11 +252,45 @@ Useful when embedding in inputs */
238
252
  compact?: boolean;
239
253
  };
240
254
 
255
+ export type AchPaymentComponentProps = {
256
+ /** */
257
+ paymentMethod?: InitializedPaymentMethod | undefined;
258
+ /** */
259
+ paymentManagers?: InitializedManagersMap;
260
+ /** */
261
+ sdkState?: SdkStateContext | undefined;
262
+ /** */
263
+ clientOptions?: ClientOptionsContext | undefined;
264
+ /** */
265
+ screen?: "form" | "mandate";
266
+ /** */
267
+ "onprimer-ach-error"?: (e: CustomEvent<CustomEvent>) => void;
268
+ /** */
269
+ "onprimer-ach-bank-details-collected"?: (e: CustomEvent<CustomEvent>) => void;
270
+ /** */
271
+ "onprimer-ach-mandate-confirmed"?: (e: CustomEvent<CustomEvent>) => void;
272
+ /** */
273
+ "onprimer-ach-mandate-declined"?: (e: CustomEvent<CustomEvent>) => void;
274
+ };
275
+
241
276
  export type CardFormComponentProps = {
242
277
  /** Payment managers injected from context */
243
278
  paymentManagers?: InitializedManagersMap;
244
279
  };
245
280
 
281
+ export type DynamicPaymentComponentProps = {
282
+ /** */
283
+ paymentMethod?: InitializedPaymentMethod | undefined;
284
+ /** */
285
+ paymentManagers?: InitializedManagersMap;
286
+ /** */
287
+ sdkState?: SdkStateContext;
288
+ /** */
289
+ headlessUtils?: HeadlessUnitilsContext;
290
+ /** */
291
+ open?: boolean;
292
+ };
293
+
246
294
  export type ErrorMessageContainerComponentProps = {
247
295
  /** */
248
296
  "show-processing-errors"?: boolean;
@@ -592,6 +640,16 @@ export type CustomElements = {
592
640
  */
593
641
  "primer-collapsable": Partial<CollapsableComponentProps & BaseProps & BaseEvents>;
594
642
 
643
+ /**
644
+ *
645
+ * ---
646
+ *
647
+ *
648
+ * ### **Events:**
649
+ * - **primer-dialog-close**
650
+ */
651
+ "primer-dialog": Partial<DialogComponentProps & BaseProps & BaseEvents>;
652
+
595
653
  /**
596
654
  * A reusable atomic error message component that displays error information
597
655
  * with appropriate styling and accessibility attributes.
@@ -680,6 +738,16 @@ export type CustomElements = {
680
738
  */
681
739
  "primer-input-wrapper": Partial<InputWrapperComponentProps & BaseProps & BaseEvents>;
682
740
 
741
+ /**
742
+ *
743
+ * ---
744
+ *
745
+ *
746
+ * ### **Events:**
747
+ * - **eventName**
748
+ */
749
+ "primer-portal": Partial<PortalComponentProps & BaseProps & BaseEvents>;
750
+
683
751
  /**
684
752
  * Spinner component with configurable size and color
685
753
  * Adapted to work both standalone and within input components
@@ -688,6 +756,19 @@ export type CustomElements = {
688
756
  */
689
757
  "primer-spinner": Partial<SpinnerComponentProps & BaseProps & BaseEvents>;
690
758
 
759
+ /**
760
+ *
761
+ * ---
762
+ *
763
+ *
764
+ * ### **Events:**
765
+ * - **primer-ach-error**
766
+ * - **primer-ach-bank-details-collected**
767
+ * - **primer-ach-mandate-confirmed**
768
+ * - **primer-ach-mandate-declined**
769
+ */
770
+ "primer-ach-payment": Partial<AchPaymentComponentProps & BaseProps & BaseEvents>;
771
+
691
772
  /**
692
773
  * CardFormComponent serves as a container for card input components.
693
774
  * It handles form submission, validation, and provides context to child components.
@@ -696,6 +777,13 @@ export type CustomElements = {
696
777
  */
697
778
  "primer-card-form": Partial<CardFormComponentProps & BaseProps & BaseEvents>;
698
779
 
780
+ /**
781
+ *
782
+ * ---
783
+ *
784
+ */
785
+ "primer-dynamic-payment": Partial<DynamicPaymentComponentProps & BaseProps & BaseEvents>;
786
+
699
787
  /**
700
788
  * A container component that connects to the SDK state context
701
789
  * and displays appropriate error messages based on error state.
@@ -1727,6 +1727,7 @@ export type ResumeToken = {
1727
1727
  paymentId?: string;
1728
1728
  };
1729
1729
  export interface InputValidationError {
1730
+ field?: string;
1730
1731
  name: string;
1731
1732
  error: string;
1732
1733
  message: string;
@@ -2096,6 +2097,7 @@ export interface IKlarnaPaymentMethodManager {
2096
2097
  }
2097
2098
  export interface IAchPaymentMethodManager {
2098
2099
  start(paymentDetails: StripeAchCustomerDetails): Promise<Validation | void>;
2100
+ setAndValidate(paymentDetails: StripeAchCustomerDetails): Promise<Validation>;
2099
2101
  collectBankAccountDetails(): Promise<void>;
2100
2102
  confirmMandate(): Promise<void>;
2101
2103
  declineMandate(): Promise<void>;
@@ -2243,6 +2245,7 @@ export type PrimerCheckoutOptions = JSONSafe<HeadlessUniversalCheckoutOptions> &
2243
2245
  submitButton?: {
2244
2246
  amountVisible?: boolean;
2245
2247
  };
2248
+ stripe?: UniversalCheckoutOptions["stripe"];
2246
2249
  };
2247
2250
  declare global {
2248
2251
  interface Window {
@@ -2272,6 +2275,7 @@ export interface InitializedManagersMap extends Map<PaymentMethodType, Initializ
2272
2275
  get<T extends PaymentMethodType>(key: T): ManagerByType<T> | undefined;
2273
2276
  }
2274
2277
  export type RedirectPaymentMethodTypes = Exclude<PaymentMethodType, typeof PaymentMethodType.STRIPE_ACH | typeof PaymentMethodType.PAYMENT_CARD | typeof PaymentMethodType.KLARNA | typeof PaymentMethodType.PAYPAL | typeof PaymentMethodType.GOOGLE_PAY | typeof PaymentMethodType.APPLE_PAY>;
2278
+ export type DynamicPaymentMethodTypes = typeof PaymentMethodType.STRIPE_ACH;
2275
2279
  export type NativePaymentMethodTypes = typeof PaymentMethodType.PAYPAL | typeof PaymentMethodType.GOOGLE_PAY | typeof PaymentMethodType.APPLE_PAY;
2276
2280
  export type RedirectPaymentMethod = {
2277
2281
  type: RedirectPaymentMethodTypes;
@@ -2302,6 +2306,11 @@ export type PaymentMethodByType<T extends PaymentMethodType> = Extract<Initializ
2302
2306
  export interface InitializedPaymentMethodMap extends Map<PaymentMethodType, InitializedPaymentMethod> {
2303
2307
  get<T extends PaymentMethodType>(key: T): PaymentMethodByType<T> | undefined;
2304
2308
  }
2309
+ export interface AssetsConfig {
2310
+ backgroundColor: string;
2311
+ name: string;
2312
+ iconUrl: string;
2313
+ }
2305
2314
  export declare class InitializedPayments {
2306
2315
  private readonly _methods;
2307
2316
  constructor(map: InitializedPaymentMethodMap);
@@ -2316,6 +2325,9 @@ export interface CardSubmitSuccessPayload {
2316
2325
  export interface CardSubmitErrorsPayload {
2317
2326
  errors: unknown | InputValidationError[];
2318
2327
  }
2328
+ export interface PrimeAchErrorPayload {
2329
+ error: Error;
2330
+ }
2319
2331
  export interface PrimerEvents {
2320
2332
  "primer-state-changed": CustomEvent<SdkStateContext>;
2321
2333
  "primer-payment-methods-updated": CustomEvent<InitializedPayments>;
@@ -2323,6 +2335,10 @@ export interface PrimerEvents {
2323
2335
  "primer-card-network-change": CustomEvent<CardNetworksContext>;
2324
2336
  "primer-card-submit-success": CustomEvent<CardSubmitSuccessPayload>;
2325
2337
  "primer-card-submit-errors": CustomEvent<CardSubmitErrorsPayload>;
2338
+ "primer-ach-error": CustomEvent<PrimeAchErrorPayload>;
2339
+ "primer-ach-bank-details-collected": CustomEvent;
2340
+ "primer-ach-mandate-confirmed": CustomEvent;
2341
+ "primer-ach-mandate-declined": CustomEvent;
2326
2342
  }
2327
2343
  declare class PrimerEventsController implements ReactiveController {
2328
2344
  host: ReactiveControllerHost & LitElement;
@@ -2497,6 +2513,7 @@ declare class SdkStateController implements ReactiveController {
2497
2513
  setError(error: Error): void;
2498
2514
  setFailure(code: string, message: string, details?: Record<string, unknown>): void;
2499
2515
  reset(): void;
2516
+ forceCompleteLoading(): void;
2500
2517
  get state(): SdkState;
2501
2518
  }
2502
2519
  export interface PrimerCheckoutType extends ReactiveControllerHost, LitElement {
@@ -2636,6 +2653,15 @@ declare const targetLocales = [
2636
2653
  `zh-TW`,
2637
2654
  ] as const;
2638
2655
  export type LocaleCode = typeof sourceLocale | (typeof targetLocales)[number];
2656
+ declare class AchPaymentEventsController implements ReactiveController {
2657
+ host: PrimerCheckoutComponent;
2658
+ constructor(host: PrimerCheckoutComponent);
2659
+ private _error;
2660
+ private _mandateConfirmed;
2661
+ private _mandateDeclined;
2662
+ hostConnected(): void;
2663
+ hostDisconnected(): void;
2664
+ }
2639
2665
  /**
2640
2666
  * PrimerCheckoutComponent implements the main checkout experience.
2641
2667
  * This component includes a CSS-only loader that displays before the JavaScript
@@ -2661,6 +2687,7 @@ export declare class PrimerCheckoutComponent extends LitElement implements Prime
2661
2687
  defaultSlot: HTMLSlotElement;
2662
2688
  private previousLoadingState;
2663
2689
  private hasAssignedContent;
2690
+ private _loadingTimeoutId;
2664
2691
  locale?: LocaleCode;
2665
2692
  private onSlotChange;
2666
2693
  sdkContextController: SDKContextController;
@@ -2669,8 +2696,10 @@ export declare class PrimerCheckoutComponent extends LitElement implements Prime
2669
2696
  styleProcessingController: StyleProcessingController;
2670
2697
  vaultManagerController: VaultManagerController;
2671
2698
  cardNetworkController: CardNetworkController;
2699
+ achPaymentEventsController: AchPaymentEventsController;
2672
2700
  constructor();
2673
2701
  attributeChangedCallback(attrName: string, oldVal: string, newVal: string): void;
2702
+ disconnectedCallback(): void;
2674
2703
  willUpdate(changedProperties: PropertyValues): void;
2675
2704
  updated(): void;
2676
2705
  /**
@@ -2683,7 +2712,38 @@ export declare class PrimerCheckoutComponent extends LitElement implements Prime
2683
2712
  addEventListener<K extends keyof ShadowRootEventMap>(type: K, listener: (this: PrimerCheckoutComponent, ev: ShadowRootEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
2684
2713
  addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: PrimerCheckoutComponent, ev: DocumentEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
2685
2714
  addEventListener<K extends keyof PrimerEvents>(type: K, listener: (this: PrimerCheckoutComponent, ev: PrimerEvents[K]) => void, options?: boolean | AddEventListenerOptions): void;
2715
+ removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: PrimerCheckoutComponent, ev: HTMLElementEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
2716
+ removeEventListener<K extends keyof ShadowRootEventMap>(type: K, listener: (this: PrimerCheckoutComponent, ev: ShadowRootEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
2717
+ removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: PrimerCheckoutComponent, ev: DocumentEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
2718
+ removeEventListener<K extends keyof PrimerEvents>(type: K, listener: (this: PrimerCheckoutComponent, ev: PrimerEvents[K]) => void, options?: boolean | EventListenerOptions): void;
2686
2719
  }
2720
+ /**
2721
+ * Injects the CSS loader styles into the page
2722
+ * These styles display a loading indicator before JavaScript initializes
2723
+ *
2724
+ * Unlike theme styles, loader styles should take precedence over merchant styles
2725
+ * to ensure the loading indicator is visible. We append them to the end of the head.
2726
+ */
2727
+ export declare function injectLoaderStyles(): void;
2728
+ /**
2729
+ * Injects all required theme CSS variables into the page
2730
+ * This should be called before components are rendered to ensure
2731
+ * they have access to all design tokens
2732
+ *
2733
+ * Theme styles are prepended to the document head to allow merchant styles
2734
+ * to override our default variables.
2735
+ */
2736
+ export declare function injectThemeStyles(): void;
2737
+ /**
2738
+ * Utility function to inject only the light theme CSS variables
2739
+ * @returns {void}
2740
+ */
2741
+ export declare function injectLightTheme(): void;
2742
+ /**
2743
+ * Utility function to inject only the dark theme CSS variables
2744
+ * @returns {void}
2745
+ */
2746
+ export declare function injectDarkTheme(): void;
2687
2747
  /**
2688
2748
  * Size options for the spinner component
2689
2749
  */
@@ -3106,6 +3166,37 @@ declare global {
3106
3166
  "primer-error-message": ErrorMessageComponent;
3107
3167
  }
3108
3168
  }
3169
+ declare class PortalComponent extends LitElement {
3170
+ static styles: CSSResult[];
3171
+ id: string;
3172
+ getContainer(): HTMLDivElement;
3173
+ /**
3174
+ * Proxies the events sent from the portalled content and
3175
+ * re-dispatches them.
3176
+ *
3177
+ * TODO: find a better way to scale to new events instead
3178
+ * of hardcoding them one by one here.
3179
+ */
3180
+ private _setupEventListeners;
3181
+ disconnectedCallback(): void;
3182
+ private _handleSlotChange;
3183
+ render(): TemplateResult<1>;
3184
+ }
3185
+ declare global {
3186
+ interface HTMLElementTagNameMap {
3187
+ "primer-portal": PortalComponent;
3188
+ }
3189
+ }
3190
+ declare class DialogComponent extends LitElement {
3191
+ static styles: CSSResult[];
3192
+ private _handleCloseClick;
3193
+ render(): TemplateResult<1>;
3194
+ }
3195
+ declare global {
3196
+ interface HTMLElementTagNameMap {
3197
+ "primer-dialog": DialogComponent;
3198
+ }
3199
+ }
3109
3200
  /**
3110
3201
  * This component renders Klarna payment method in a card-like (accordion) container with
3111
3202
  * payment categories options to choose from.
@@ -3152,6 +3243,88 @@ declare global {
3152
3243
  "primer-payment-method": PaymentMethodComponent;
3153
3244
  }
3154
3245
  }
3246
+ export type ClientOptionsContext = PrimerCheckoutOptions | null;
3247
+ export type AchField = "firstName" | "lastName" | "emailAddress";
3248
+ export interface AchFormState {
3249
+ value: string;
3250
+ error: string;
3251
+ pristine: boolean;
3252
+ touched: boolean;
3253
+ dirty: boolean;
3254
+ valid: boolean;
3255
+ }
3256
+ export type AchFormStateMap = Record<AchField, AchFormState>;
3257
+ export type ValidationFunction = (data: StripeAchCustomerDetails) => Promise<Validation>;
3258
+ declare class AchPaymentFormControler implements ReactiveController {
3259
+ host: AchPaymentComponent;
3260
+ validate: ValidationFunction;
3261
+ formState: AchFormStateMap;
3262
+ get hasError(): {
3263
+ firstName: boolean;
3264
+ lastName: boolean;
3265
+ emailAddress: boolean;
3266
+ };
3267
+ get formData(): StripeAchCustomerDetails;
3268
+ constructor(host: AchPaymentComponent, validate: ValidationFunction);
3269
+ setFieldValue(field: AchField, value: string): Promise<void>;
3270
+ setValidation(validation: Validation, submit?: boolean): void;
3271
+ setFieldTouched(field: AchField): void;
3272
+ resetForm(): void;
3273
+ private isValidFieldName;
3274
+ hostConnected(): void;
3275
+ hostDisconnected(): void;
3276
+ }
3277
+ declare class AchPaymentComponent extends LitElement {
3278
+ static styles: CSSResult[];
3279
+ protected readonly formController: AchPaymentFormControler;
3280
+ paymentMethod: InitializedPaymentMethod | undefined;
3281
+ paymentManagers: InitializedManagersMap;
3282
+ sdkState: SdkStateContext | undefined;
3283
+ clientOptions: ClientOptionsContext | undefined;
3284
+ screen: "form" | "mandate";
3285
+ private isSubmitting;
3286
+ private _paymentMethodManagerTask;
3287
+ private _handleInput;
3288
+ private _handleBlur;
3289
+ private _handleError;
3290
+ private _handleSubmitButtonClick;
3291
+ private _handleCollectBankAccountDetails;
3292
+ private _handleConfirmMandate;
3293
+ private _handleDeclineMandate;
3294
+ private renderForm;
3295
+ private renderMandate;
3296
+ render(): TemplateResult | typeof nothing | undefined;
3297
+ }
3298
+ declare global {
3299
+ interface HTMLElementTagNameMap {
3300
+ "primer-ach-payment": AchPaymentComponent;
3301
+ }
3302
+ }
3303
+ declare class DynamicPaymentComponent extends LitElement {
3304
+ static styles: CSSResult[];
3305
+ paymentMethod: InitializedPaymentMethod | undefined;
3306
+ paymentManagers: InitializedManagersMap;
3307
+ sdkState: SdkStateContext;
3308
+ headlessUtils: HeadlessUnitilsContext;
3309
+ open: boolean;
3310
+ private _paymentMethodManagerTask;
3311
+ private _getAssetsTask;
3312
+ /**
3313
+ * Based on packages/primer-sdk-web/src/payment-methods/Button.tsx
3314
+ * Should be replaced once we align on a better solution across all platforms.
3315
+ * TODO: get label from payment config
3316
+ */
3317
+ private _legacyGetButtonLabel;
3318
+ private _setupTasks;
3319
+ start(): void;
3320
+ renderDialog(): typeof nothing | TemplateResult<1>;
3321
+ render(): symbol | TemplateResult<1> | undefined;
3322
+ }
3323
+ declare global {
3324
+ interface HTMLElementTagNameMap {
3325
+ "primer-dynamic-payment": DynamicPaymentComponent;
3326
+ }
3327
+ }
3155
3328
  declare class RedirectPaymentComponent extends LitElement {
3156
3329
  static styles: CSSResult[];
3157
3330
  paymentMethod: InitializedPaymentMethod | undefined;
@@ -3674,7 +3847,6 @@ declare global {
3674
3847
  "primer-input-card-holder-name": InputCardHolderNameComponent;
3675
3848
  }
3676
3849
  }
3677
- export type ClientOptionsContext = PrimerCheckoutOptions | null;
3678
3850
  /**
3679
3851
  * A form submit button component for card forms.
3680
3852
  * Provides a consistent submit button with translation support.
@@ -4249,33 +4421,6 @@ declare global {
4249
4421
  "primer-error-message-container": ErrorMessageContainerComponent;
4250
4422
  }
4251
4423
  }
4252
- /**
4253
- * Injects the CSS loader styles into the page
4254
- * These styles display a loading indicator before JavaScript initializes
4255
- *
4256
- * Unlike theme styles, loader styles should take precedence over merchant styles
4257
- * to ensure the loading indicator is visible. We append them to the end of the head.
4258
- */
4259
- export declare function injectLoaderStyles(): void;
4260
- /**
4261
- * Injects all required theme CSS variables into the page
4262
- * This should be called before components are rendered to ensure
4263
- * they have access to all design tokens
4264
- *
4265
- * Theme styles are prepended to the document head to allow merchant styles
4266
- * to override our default variables.
4267
- */
4268
- export declare function injectThemeStyles(): void;
4269
- /**
4270
- * Utility function to inject only the light theme CSS variables
4271
- * @returns {void}
4272
- */
4273
- export declare function injectLightTheme(): void;
4274
- /**
4275
- * Utility function to inject only the dark theme CSS variables
4276
- * @returns {void}
4277
- */
4278
- export declare function injectDarkTheme(): void;
4279
4424
  /**
4280
4425
  * Main function to load the Primer SDK with all required dependencies and styles
4281
4426
  * @returns {Promise<void>} A promise that resolves when loading is complete
@@ -4288,11 +4433,14 @@ declare global {
4288
4433
  }
4289
4434
 
4290
4435
  export {
4436
+ AchPaymentComponent as AchPayment,
4291
4437
  ButtonComponent as Button,
4292
4438
  CardFormComponent as CardForm,
4293
4439
  CardFormSubmitComponent as CardFormSubmit,
4294
4440
  CardNetworkSelectorComponent as CardFormCardNetworkSelector,
4295
4441
  CollapsableComponent as Collapsable,
4442
+ DialogComponent as Dialog,
4443
+ DynamicPaymentComponent as DynamicPayment,
4296
4444
  ErrorMessageComponent as ErrorMessage,
4297
4445
  ErrorMessageContainerComponent as ErrorMessageContainer,
4298
4446
  InputCardExpiryComponent as CardFormExpiry,
@@ -4305,6 +4453,7 @@ export {
4305
4453
  InputWrapperComponent as InputWrapper,
4306
4454
  NativePaymentComponent as NativePayment,
4307
4455
  PaymentMethodComponent as PaymentMethod,
4456
+ PortalComponent as Portal,
4308
4457
  PrimerCheckoutCompleteComponent as PrimerCheckoutComplete,
4309
4458
  PrimerCheckoutErrorComponent as PrimerCheckoutFailure,
4310
4459
  PrimerCheckoutStateComponent as PrimerCheckoutState,