@primer-io/primer-js 1.2.0 → 1.4.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.
@@ -238,11 +238,36 @@ export type InputWrapperComponentProps = {
238
238
  "has-error"?: boolean;
239
239
  };
240
240
 
241
+ export type PtPhoneNumberInputComponentProps = {
242
+ /** Fixed PT dial code. Exposed as a property only so tests can override. */
243
+ prefix?: string;
244
+ /** Externally-provided full phone number including the prefix. The component
245
+ displays only the local portion (everything after the prefix). */
246
+ value?: string;
247
+ /** */
248
+ placeholder?: string;
249
+ /** */
250
+ "input-id"?: string;
251
+ /** Maximum total length of the full phone number (including prefix). */
252
+ "max-length"?: number;
253
+ /** Minimum total length of the full phone number (including prefix). */
254
+ "min-length"?: number;
255
+ /** */
256
+ disabled?: boolean;
257
+ /** */
258
+ "has-errors"?: boolean;
259
+
260
+ /** */
261
+ oneventName?: (e: CustomEvent<CustomEvent>) => void;
262
+ /** CustomEvent<string> with full phone number on each keystroke */
263
+ oninput?: (e: CustomEvent<never>) => void;
264
+ /** CustomEvent<string> with full phone number on commit */
265
+ onchange?: (e: CustomEvent<never>) => void;
266
+ };
267
+
241
268
  export type SelectComponentProps = {
242
269
  /** The name attribute for the select element */
243
270
  name?: string;
244
- /** The id attribute for the select element */
245
- id?: string;
246
271
  /** The current value of the select */
247
272
  value?: string;
248
273
  /** Whether the select is disabled */
@@ -254,13 +279,13 @@ export type SelectComponentProps = {
254
279
  /** Array of options for the select */
255
280
  options?: SelectOption[];
256
281
  /** Fired when selection changes */
257
- onchange?: (e: CustomEvent<CustomEvent>) => void;
282
+ onchange?: (e: CustomEvent<never>) => void;
258
283
  /** Fired when input value changes */
259
- oninput?: (e: CustomEvent<CustomEvent>) => void;
284
+ oninput?: (e: CustomEvent<never>) => void;
260
285
  /** Fired when select receives focus */
261
- onfocus?: (e: CustomEvent<CustomEvent>) => void;
286
+ onfocus?: (e: CustomEvent<never>) => void;
262
287
  /** Fired when select loses focus */
263
- onblur?: (e: CustomEvent<CustomEvent>) => void;
288
+ onblur?: (e: CustomEvent<never>) => void;
264
289
  };
265
290
 
266
291
  export type SpinnerComponentProps = {
@@ -284,6 +309,13 @@ export type AdyenKlarnaComponentProps = {
284
309
  primerContext?: ContextType | undefined;
285
310
  };
286
311
 
312
+ export type AdyenMbwayComponentProps = {
313
+ /** */
314
+ paymentMethod?: MbwayPaymentMethod | undefined;
315
+ /** */
316
+ disabled?: boolean;
317
+ };
318
+
287
319
  export type BillingAddressComponentProps = {
288
320
  /** */
289
321
  primerContext?: ContextType | undefined;
@@ -437,13 +469,13 @@ export type VaultManagerComponentProps = {
437
469
  addEventListener?: <K extends keyof VaultManagerEventMap>(
438
470
  type: K,
439
471
  listener: (ev: VaultManagerEventMap[K]) => void,
440
- options?: boolean | AddEventListenerOptions,
472
+ options?: boolean | AddEventListenerOptions
441
473
  ) => void;
442
474
  /** */
443
475
  removeEventListener?: <K extends keyof VaultManagerEventMap>(
444
476
  type: K,
445
477
  listener: (ev: VaultManagerEventMap[K]) => void,
446
- options?: boolean | AddEventListenerOptions,
478
+ options?: boolean | AddEventListenerOptions
447
479
  ) => void;
448
480
  /** */
449
481
  primerContext?: ContextType | undefined;
@@ -600,13 +632,13 @@ export type VaultDeleteConfirmationComponentProps = {
600
632
  addEventListener?: <K extends keyof VaultManagerEventMap>(
601
633
  type: K,
602
634
  listener: (ev: VaultManagerEventMap[K]) => void,
603
- options?: boolean | AddEventListenerOptions,
635
+ options?: boolean | AddEventListenerOptions
604
636
  ) => void;
605
637
  /** */
606
638
  removeEventListener?: <K extends keyof VaultManagerEventMap>(
607
639
  type: K,
608
640
  listener: (ev: VaultManagerEventMap[K]) => void,
609
- options?: boolean | AddEventListenerOptions,
641
+ options?: boolean | AddEventListenerOptions
610
642
  ) => void;
611
643
  };
612
644
 
@@ -619,13 +651,13 @@ export type VaultErrorMessageComponentProps = {
619
651
  addEventListener?: <K extends keyof VaultManagerEventMap>(
620
652
  type: K,
621
653
  listener: (ev: VaultManagerEventMap[K]) => void,
622
- options?: boolean | AddEventListenerOptions,
654
+ options?: boolean | AddEventListenerOptions
623
655
  ) => void;
624
656
  /** */
625
657
  removeEventListener?: <K extends keyof VaultManagerEventMap>(
626
658
  type: K,
627
659
  listener: (ev: VaultManagerEventMap[K]) => void,
628
- options?: boolean | AddEventListenerOptions,
660
+ options?: boolean | AddEventListenerOptions
629
661
  ) => void;
630
662
  };
631
663
 
@@ -638,13 +670,13 @@ export type VaultManagerHeaderComponentProps = {
638
670
  addEventListener?: <K extends keyof VaultManagerEventMap>(
639
671
  type: K,
640
672
  listener: (ev: VaultManagerEventMap[K]) => void,
641
- options?: boolean | AddEventListenerOptions,
673
+ options?: boolean | AddEventListenerOptions
642
674
  ) => void;
643
675
  /** */
644
676
  removeEventListener?: <K extends keyof VaultManagerEventMap>(
645
677
  type: K,
646
678
  listener: (ev: VaultManagerEventMap[K]) => void,
647
- options?: boolean | AddEventListenerOptions,
679
+ options?: boolean | AddEventListenerOptions
648
680
  ) => void;
649
681
  };
650
682
 
@@ -655,13 +687,13 @@ export type VaultPaymentMethodItemComponentProps = {
655
687
  addEventListener?: <K extends keyof VaultManagerEventMap>(
656
688
  type: K,
657
689
  listener: (ev: VaultManagerEventMap[K]) => void,
658
- options?: boolean | AddEventListenerOptions,
690
+ options?: boolean | AddEventListenerOptions
659
691
  ) => void;
660
692
  /** */
661
693
  removeEventListener?: <K extends keyof VaultManagerEventMap>(
662
694
  type: K,
663
695
  listener: (ev: VaultManagerEventMap[K]) => void,
664
- options?: boolean | AddEventListenerOptions,
696
+ options?: boolean | AddEventListenerOptions
665
697
  ) => void;
666
698
  /** */
667
699
  primerContext?: ContextType | undefined;
@@ -825,6 +857,28 @@ export type CustomElements = {
825
857
  */
826
858
  "primer-input-wrapper": Partial<InputWrapperComponentProps & BaseProps & BaseEvents>;
827
859
 
860
+ /**
861
+ * Portuguese Phone Number Input
862
+ *
863
+ * Inline phone input dedicated to Portuguese (+351) numbers. Renders a PT
864
+ * flag, a fixed `+351` prefix, and a digit-only field; the user types only
865
+ * the local digits. Emits `input` / `change` events whose detail is the full
866
+ * E.164 number (`+351` + digits) or an empty string when no digits are
867
+ * entered.
868
+ *
869
+ * This is intentionally PT-only — MB WAY is the only consumer and only
870
+ * operates in Portugal. If we ever need other locales, fork into a
871
+ * country-aware component rather than generalising this one.
872
+ * ---
873
+ *
874
+ *
875
+ * ### **Events:**
876
+ * - **eventName**
877
+ * - **input** - CustomEvent<string> with full phone number on each keystroke
878
+ * - **change** - CustomEvent<string> with full phone number on commit
879
+ */
880
+ "primer-pt-phone-number-input": Partial<PtPhoneNumberInputComponentProps & BaseProps & BaseEvents>;
881
+
828
882
  /**
829
883
  * A native select dropdown component
830
884
  * ---
@@ -853,6 +907,15 @@ export type CustomElements = {
853
907
  */
854
908
  "primer-adyen-klarna": Partial<AdyenKlarnaComponentProps & BaseProps & BaseEvents>;
855
909
 
910
+ /**
911
+ * Adyen MB WAY Payment Component
912
+ *
913
+ * Inline phone-number entry → tokenize → poll MB WAY app → resume.
914
+ * ---
915
+ *
916
+ */
917
+ "primer-adyen-mbway": Partial<AdyenMbwayComponentProps & BaseProps & BaseEvents>;
918
+
856
919
  /**
857
920
  * BillingAddressComponent provides a form for collecting billing address information.
858
921
  *
@@ -572,7 +572,8 @@ declare enum HeadlessManagerType {
572
572
  KLARNA = "KLARNA",
573
573
  ADYEN_KLARNA = "ADYEN_KLARNA",
574
574
  ACH = "ACH",
575
- BLIK = "BLIK"
575
+ BLIK = "BLIK",
576
+ MBWAY = "MBWAY"
576
577
  }
577
578
  declare enum EventTypes {
578
579
  CHANGE = "change",
@@ -711,7 +712,7 @@ export interface PaymentMethodConfig<T = Record<string, unknown>> {
711
712
  id: string;
712
713
  type: PaymentMethodType;
713
714
  name: string;
714
- implementationType: "WEB_REDIRECT" | "NATIVE_SDK";
715
+ implementationType: "WEB_REDIRECT" | "NATIVE_SDK" | "BACKEND_DRIVEN";
715
716
  displayMetadata: {
716
717
  button: {
717
718
  backgroundColor: BackgroundColor;
@@ -1049,6 +1050,18 @@ export interface IBlikPaymentMethodManager {
1049
1050
  blikCode: string;
1050
1051
  }): Promise<void>;
1051
1052
  }
1053
+ /**
1054
+ * Adyen MB WAY Payment Method Manager
1055
+ *
1056
+ * Collects the user's phone number (with country prefix) inline, tokenizes
1057
+ * it, and polls the returned status URL until the user confirms the payment
1058
+ * in the MB WAY mobile app.
1059
+ */
1060
+ export interface IMbwayPaymentMethodManager {
1061
+ start(params: {
1062
+ phoneNumber: string;
1063
+ }): Promise<void>;
1064
+ }
1052
1065
  /**
1053
1066
  * Adyen Klarna payment option
1054
1067
  */
@@ -1467,12 +1480,39 @@ export interface PrimerCheckoutOptions {
1467
1480
  */
1468
1481
  redirect?: {
1469
1482
  /**
1470
- * URL the payment method redirects back to after the customer completes
1471
- * (or cancels) the flow on the external page.
1483
+ * URL the customer is redirected back to after completing (or
1484
+ * cancelling) the payment on the external page.
1485
+ *
1486
+ * Required when the configured payment methods include any that may
1487
+ * redirect the customer to an external page. The SDK throws at initialization
1488
+ * if a redirect-capable payment method is enabled and this is
1489
+ * missing.
1490
+ *
1491
+ * **Setting up the return page**
1492
+ *
1493
+ * The URL you provide must host a page that mounts the
1494
+ * `<primer-checkout>` component again so the payment can be
1495
+ * resumed. Primer redirects the customer back with a new client
1496
+ * token appended as a `clientToken` query parameter — read it
1497
+ * from the URL and pass it to the component:
1498
+ *
1499
+ * ```html
1500
+ * <primer-checkout client-token=""></primer-checkout>
1501
+ * <script>
1502
+ * const clientToken = new URLSearchParams(window.location.search)
1503
+ * .get('clientToken');
1504
+ * document
1505
+ * .querySelector('primer-checkout')
1506
+ * .setAttribute('client-token', clientToken);
1507
+ * </script>
1508
+ * ```
1509
+ *
1510
+ * The SDK reads the intent embedded in the token, detects that
1511
+ * this is a return-from-redirect, and resumes the payment
1512
+ * automatically — no separate method call is required.
1472
1513
  *
1473
- * If omitted, the SDK uses the current page URL.
1474
1514
  */
1475
- returnUrl?: string;
1515
+ returnUrl: string;
1476
1516
  /**
1477
1517
  * Whether to force a full-page redirect for payment methods that would
1478
1518
  * otherwise open in a popup.
@@ -1910,10 +1950,11 @@ export type NativePaymentMethodTypes = typeof PaymentMethodType.PAYPAL | typeof
1910
1950
  * - ADYEN_KLARNA: Uses ADYEN_KLARNA manager
1911
1951
  * - PAYPAL, GOOGLE_PAY, APPLE_PAY: Use NATIVE manager
1912
1952
  * - ADYEN_BLIK: Uses BLIK manager
1953
+ * - ADYEN_MBWAY: Uses MBWAY manager
1913
1954
  *
1914
1955
  * All other payment methods use the REDIRECT manager by default.
1915
1956
  */
1916
- export type RedirectPaymentMethodTypes = Exclude<PaymentMethodType, typeof PaymentMethodType.STRIPE_ACH | typeof PaymentMethodType.PAYMENT_CARD | typeof PaymentMethodType.KLARNA | typeof PaymentMethodType.ADYEN_KLARNA | typeof PaymentMethodType.PAYPAL | typeof PaymentMethodType.GOOGLE_PAY | typeof PaymentMethodType.APPLE_PAY | typeof PaymentMethodType.ADYEN_BLIK>;
1957
+ export type RedirectPaymentMethodTypes = Exclude<PaymentMethodType, typeof PaymentMethodType.STRIPE_ACH | typeof PaymentMethodType.PAYMENT_CARD | typeof PaymentMethodType.KLARNA | typeof PaymentMethodType.ADYEN_KLARNA | typeof PaymentMethodType.PAYPAL | typeof PaymentMethodType.GOOGLE_PAY | typeof PaymentMethodType.APPLE_PAY | typeof PaymentMethodType.ADYEN_BLIK | typeof PaymentMethodType.ADYEN_MBWAY>;
1917
1958
  /**
1918
1959
  * Represents a payment method that uses the REDIRECT manager.
1919
1960
  *
@@ -1937,6 +1978,11 @@ export interface BlikPaymentMethod {
1937
1978
  managerType: HeadlessManagerType.BLIK;
1938
1979
  manager: IBlikPaymentMethodManager;
1939
1980
  }
1981
+ export interface MbwayPaymentMethod {
1982
+ type: typeof PaymentMethodType.ADYEN_MBWAY;
1983
+ managerType: HeadlessManagerType.MBWAY;
1984
+ manager: IMbwayPaymentMethodManager;
1985
+ }
1940
1986
  export type InitializedPaymentMethod = {
1941
1987
  type: typeof PaymentMethodType.STRIPE_ACH;
1942
1988
  managerType: HeadlessManagerType.ACH;
@@ -1953,7 +1999,7 @@ export type InitializedPaymentMethod = {
1953
1999
  type: typeof PaymentMethodType.ADYEN_KLARNA;
1954
2000
  managerType: HeadlessManagerType.ADYEN_KLARNA;
1955
2001
  manager: IAdyenKlarnaPaymentMethodManager;
1956
- } | BlikPaymentMethod | RedirectPaymentMethod | NativePaymentMethod;
2002
+ } | BlikPaymentMethod | MbwayPaymentMethod | RedirectPaymentMethod | NativePaymentMethod;
1957
2003
  export interface AssetsConfig {
1958
2004
  backgroundColor: string;
1959
2005
  name: string;
@@ -3204,6 +3250,59 @@ declare global {
3204
3250
  "primer-input": InputComponent;
3205
3251
  }
3206
3252
  }
3253
+ /**
3254
+ * Portuguese Phone Number Input
3255
+ *
3256
+ * Inline phone input dedicated to Portuguese (+351) numbers. Renders a PT
3257
+ * flag, a fixed `+351` prefix, and a digit-only field; the user types only
3258
+ * the local digits. Emits `input` / `change` events whose detail is the full
3259
+ * E.164 number (`+351` + digits) or an empty string when no digits are
3260
+ * entered.
3261
+ *
3262
+ * This is intentionally PT-only — MB WAY is the only consumer and only
3263
+ * operates in Portugal. If we ever need other locales, fork into a
3264
+ * country-aware component rather than generalising this one.
3265
+ *
3266
+ * @element primer-pt-phone-number-input
3267
+ *
3268
+ * @fires input - CustomEvent<string> with full phone number on each keystroke
3269
+ * @fires change - CustomEvent<string> with full phone number on commit
3270
+ */
3271
+ declare class PtPhoneNumberInputComponent extends LitElement {
3272
+ static styles: import("lit").CSSResult[];
3273
+ /** Fixed PT dial code. Exposed as a property only so tests can override. */
3274
+ prefix: string;
3275
+ /**
3276
+ * Externally-provided full phone number including the prefix. The component
3277
+ * displays only the local portion (everything after the prefix).
3278
+ */
3279
+ value: string;
3280
+ placeholder: string;
3281
+ inputId: string;
3282
+ /** Maximum total length of the full phone number (including prefix). */
3283
+ maxLength: number;
3284
+ /** Minimum total length of the full phone number (including prefix). */
3285
+ minLength: number;
3286
+ disabled: boolean;
3287
+ hasErrors: boolean;
3288
+ private inputEl?;
3289
+ /** Strip the prefix to get the local digit portion. */
3290
+ private get localDigits();
3291
+ /** Allowed local digit count, derived from total length minus prefix. */
3292
+ private get maxLocalDigits();
3293
+ updated(changed: Map<string, unknown>): void;
3294
+ private dispatchValueEvent;
3295
+ private handleInput;
3296
+ private handleChange;
3297
+ private handleHostClick;
3298
+ focus(): void;
3299
+ render(): TemplateResult;
3300
+ }
3301
+ declare global {
3302
+ interface HTMLElementTagNameMap {
3303
+ "primer-pt-phone-number-input": PtPhoneNumberInputComponent;
3304
+ }
3305
+ }
3207
3306
  export interface SelectOption {
3208
3307
  value: string;
3209
3308
  label: string;
@@ -3224,10 +3323,6 @@ declare class SelectComponent extends LitElement {
3224
3323
  * The name attribute for the select element
3225
3324
  */
3226
3325
  name: string;
3227
- /**
3228
- * The id attribute for the select element
3229
- */
3230
- id: string;
3231
3326
  /**
3232
3327
  * The current value of the select
3233
3328
  */
@@ -3638,6 +3733,38 @@ declare global {
3638
3733
  "primer-adyen-klarna": AdyenKlarnaComponent;
3639
3734
  }
3640
3735
  }
3736
+ /**
3737
+ * Adyen MB WAY Payment Component
3738
+ *
3739
+ * Inline phone-number entry → tokenize → poll MB WAY app → resume.
3740
+ *
3741
+ * @element primer-adyen-mbway
3742
+ */
3743
+ declare class AdyenMbwayComponent extends LitElement {
3744
+ static styles: import("lit").CSSResult[];
3745
+ paymentMethod: MbwayPaymentMethod | undefined;
3746
+ disabled: boolean;
3747
+ private currentState;
3748
+ private phoneNumber;
3749
+ private errorMessage;
3750
+ private get isExpanded();
3751
+ private get isPhoneValid();
3752
+ private handleExpandedChange;
3753
+ private handleCollapse;
3754
+ private handleInput;
3755
+ private handleRetry;
3756
+ private submit;
3757
+ private renderExpandedInput;
3758
+ private renderLoading;
3759
+ private renderError;
3760
+ private renderExpandedState;
3761
+ render(): TemplateResult;
3762
+ }
3763
+ declare global {
3764
+ interface HTMLElementTagNameMap {
3765
+ "primer-adyen-mbway": AdyenMbwayComponent;
3766
+ }
3767
+ }
3641
3768
  declare class PaymentMethodComponent extends LitElement {
3642
3769
  static styles: import("lit").CSSResult[];
3643
3770
  type: PaymentMethodType | undefined;
@@ -3684,6 +3811,11 @@ declare class PaymentMethodButtonComponent extends LitElement {
3684
3811
  * Should be replaced once we align on a better solution across all platforms.
3685
3812
  */
3686
3813
  private _legacyGetButtonLabel;
3814
+ private _getBackgroundColor;
3815
+ private _getIconUrl;
3816
+ private _getIconPosition;
3817
+ private _getTextColor;
3818
+ private _getDisplayName;
3687
3819
  private _setupTask;
3688
3820
  private _handleClick;
3689
3821
  render(): symbol | import("lit-html").TemplateResult<1> | undefined;
@@ -5147,6 +5279,7 @@ declare global {
5147
5279
  export declare function loadPrimer(): void;
5148
5280
 
5149
5281
  export {
5282
+ AdyenMbwayComponent as AdyenMbway,
5150
5283
  ApplePayComponent as ApplePay,
5151
5284
  BillingAddressComponent as BillingAddress,
5152
5285
  BlikComponent as Blik,
@@ -5180,6 +5313,7 @@ export {
5180
5313
  PrimerIconComponent as PrimerIcon,
5181
5314
  PrimerKlarnaComponent as PrimerKlarna,
5182
5315
  PrimerMainComponent as PrimerMain,
5316
+ PtPhoneNumberInputComponent as PtPhoneNumberInput,
5183
5317
  RedirectPaymentComponent as RedirectPayment,
5184
5318
  SelectComponent as Select,
5185
5319
  ShowOtherPaymentsComponent as ShowOtherPayments,