@primer-io/primer-js 0.9.0 → 0.11.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.
@@ -66,8 +66,6 @@ export type PrimerCheckoutComponentProps = {
66
66
  /** */
67
67
  "client-token"?: string;
68
68
  /** */
69
- options?: PrimerCheckoutOptions;
70
- /** */
71
69
  "loader-disabled"?: boolean;
72
70
  /** Whether the component has completed initialization and loading
73
71
  This is used to control the CSS-only loader visibility */
@@ -77,6 +75,8 @@ This is used to control the CSS-only loader visibility */
77
75
  /** */
78
76
  primerJS?: PrimerJS | undefined;
79
77
  /** */
78
+ options?: PrimerCheckoutOptions;
79
+ /** */
80
80
  defaultSlot?: HTMLSlotElement;
81
81
  /** */
82
82
  locale?: LocaleCode | undefined;
@@ -657,6 +657,8 @@ export type VaultDeleteConfirmationComponentProps = {
657
657
  vaultManager?: VaultManagerContextType;
658
658
  };
659
659
 
660
+ export type VaultEmptyStateComponentProps = {};
661
+
660
662
  export type VaultErrorMessageComponentProps = {
661
663
  /** The error message to display */
662
664
  errorMessage?: string;
@@ -674,8 +676,6 @@ export type VaultErrorMessageComponentProps = {
674
676
  ) => void;
675
677
  };
676
678
 
677
- export type VaultEmptyStateComponentProps = {};
678
-
679
679
  export type VaultManagerHeaderComponentProps = {
680
680
  /** Whether we're in edit mode */
681
681
  isEditMode?: boolean;
@@ -1236,18 +1236,18 @@ export type CustomElements = {
1236
1236
  "primer-vault-delete-confirmation": Partial<VaultDeleteConfirmationComponentProps & BaseProps & BaseEvents>;
1237
1237
 
1238
1238
  /**
1239
- * VaultErrorMessageComponent - displays error messages with improved visuals
1239
+ * VaultEmptyStateComponent - displays when no payment methods are available
1240
1240
  * ---
1241
1241
  *
1242
1242
  */
1243
- "primer-vault-error-message": Partial<VaultErrorMessageComponentProps & BaseProps & BaseEvents>;
1243
+ "primer-vault-empty-state": Partial<VaultEmptyStateComponentProps & BaseProps & BaseEvents>;
1244
1244
 
1245
1245
  /**
1246
- * VaultEmptyStateComponent - displays when no payment methods are available
1246
+ * VaultErrorMessageComponent - displays error messages with improved visuals
1247
1247
  * ---
1248
1248
  *
1249
1249
  */
1250
- "primer-vault-empty-state": Partial<VaultEmptyStateComponentProps & BaseProps & BaseEvents>;
1250
+ "primer-vault-error-message": Partial<VaultErrorMessageComponentProps & BaseProps & BaseEvents>;
1251
1251
 
1252
1252
  /**
1253
1253
  * VaultManagerHeaderComponent - displays the header for the vault manager
@@ -376,36 +376,106 @@ export interface PaymentSummary {
376
376
  };
377
377
  }
378
378
  /**
379
- * Minimal vaulted payment method summary with reduced PII exposure.
380
- * Used for vault events and callbacks to expose vaulted payment methods safely.
379
+ * Base interface for common vaulted payment method fields.
380
+ * All payment-method-specific interfaces extend this base.
381
381
  */
382
- export interface VaultedPaymentMethodSummary {
382
+ export interface BaseVaultedPaymentMethodSummary {
383
383
  /** Payment instrument ID */
384
384
  id: string;
385
385
  /** Analytics tracking ID */
386
386
  analyticsId: string;
387
387
  /** Payment method type (e.g., "PAYMENT_CARD", "PAYPAL") */
388
388
  paymentMethodType: PaymentMethodType$1;
389
- /** Payment instrument type (e.g., "CARD", "PAYPAL_BILLING_AGREEMENT") */
390
- paymentInstrumentType: PaymentInstrumentType$1;
391
- /** Payment instrument data with whitelisted safe fields only */
389
+ /** Optional user-provided description for the payment method */
390
+ userDescription?: string;
391
+ }
392
+ /**
393
+ * Vaulted payment card summary with card-specific fields.
394
+ */
395
+ export interface CardVaultedPaymentMethodSummary extends BaseVaultedPaymentMethodSummary {
396
+ /** Discriminant for card payment instruments */
397
+ paymentInstrumentType: "PAYMENT_CARD";
398
+ /** Card-specific payment instrument data */
392
399
  paymentInstrumentData?: {
393
- /** Last 4 digits of card (cards only) */
400
+ /** Last 4 digits of card */
394
401
  last4Digits?: string;
395
- /** Card network (e.g., "VISA", "MASTERCARD") - cards only */
402
+ /** Card network (e.g., "VISA", "MASTERCARD") */
396
403
  network?: string;
397
- /** Last 4 digits of account number (ACH only) */
404
+ /** Cardholder name */
405
+ cardholderName?: string;
406
+ /** Expiration month (1-12) */
407
+ expirationMonth?: string;
408
+ /** Expiration year (e.g., "2025") */
409
+ expirationYear?: string;
410
+ };
411
+ }
412
+ /**
413
+ * Vaulted PayPal billing agreement summary with PayPal-specific fields.
414
+ */
415
+ export interface PayPalVaultedPaymentMethodSummary extends BaseVaultedPaymentMethodSummary {
416
+ /** Discriminant for PayPal billing agreement instruments */
417
+ paymentInstrumentType: "PAYPAL_BILLING_AGREEMENT";
418
+ /** PayPal-specific payment instrument data */
419
+ paymentInstrumentData?: {
420
+ /** External PayPal payer ID */
421
+ externalPayerId?: string;
422
+ /** PayPal account email */
423
+ email?: string;
424
+ /** First name */
425
+ firstName?: string;
426
+ /** Last name */
427
+ lastName?: string;
428
+ };
429
+ }
430
+ /**
431
+ * Vaulted Klarna customer token summary with Klarna-specific fields.
432
+ */
433
+ export interface KlarnaVaultedPaymentMethodSummary extends BaseVaultedPaymentMethodSummary {
434
+ /** Discriminant for Klarna customer token instruments */
435
+ paymentInstrumentType: "KLARNA_CUSTOMER_TOKEN";
436
+ /** Klarna-specific payment instrument data */
437
+ paymentInstrumentData?: {
438
+ /** Klarna account email */
439
+ email?: string;
440
+ /** First name */
441
+ firstName?: string;
442
+ /** Last name */
443
+ lastName?: string;
444
+ /** Phone number */
445
+ phoneNumber?: string;
446
+ };
447
+ }
448
+ /**
449
+ * Vaulted ACH (Automated Clearing House) summary with ACH-specific fields.
450
+ */
451
+ export interface ACHVaultedPaymentMethodSummary extends BaseVaultedPaymentMethodSummary {
452
+ /** Discriminant for ACH instruments */
453
+ paymentInstrumentType: "AUTOMATED_CLEARING_HOUSE";
454
+ /** ACH-specific payment instrument data */
455
+ paymentInstrumentData?: {
456
+ /** Last 4 digits of account number */
398
457
  accountNumberLastFourDigits?: string;
399
- /** Bank name (ACH only) */
458
+ /** Bank name */
400
459
  bankName?: string;
401
- /** Account type (ACH only) */
460
+ /** Account type (e.g., "CHECKING", "SAVINGS") */
402
461
  accountType?: string;
403
- /** Email for wallet payment methods */
404
- email?: string;
405
462
  };
406
- /** Optional user-provided description for the payment method */
407
- userDescription?: string;
408
463
  }
464
+ /**
465
+ * Generic vaulted payment method summary for payment instruments
466
+ * not explicitly modeled with their own interface.
467
+ */
468
+ export interface GenericVaultedPaymentMethodSummary extends BaseVaultedPaymentMethodSummary {
469
+ /** Discriminant for all other payment instrument types */
470
+ paymentInstrumentType: Exclude<PaymentInstrumentType$1, "PAYMENT_CARD" | "PAYPAL_BILLING_AGREEMENT" | "KLARNA_CUSTOMER_TOKEN" | "AUTOMATED_CLEARING_HOUSE">;
471
+ /** Generic payment instrument data for unknown/other payment methods */
472
+ paymentInstrumentData?: Record<string, unknown>;
473
+ }
474
+ /**
475
+ * Discriminated union of all vaulted payment method summaries.
476
+ * Use the paymentInstrumentType field to narrow to specific types.
477
+ */
478
+ export type VaultedPaymentMethodSummary = CardVaultedPaymentMethodSummary | PayPalVaultedPaymentMethodSummary | KlarnaVaultedPaymentMethodSummary | ACHVaultedPaymentMethodSummary | GenericVaultedPaymentMethodSummary;
409
479
  export type APIVersionOption = "legacy" | "2.4";
410
480
  declare enum HeadlessManagerType {
411
481
  CARD = "CARD",
@@ -1962,6 +2032,38 @@ export interface VaultedMethodsUpdateData {
1962
2032
  /** Unix timestamp in seconds */
1963
2033
  timestamp: number;
1964
2034
  }
2035
+ /**
2036
+ * VaultAPI provides programmatic access to vaulted payment method operations.
2037
+ * Enables merchants to build custom vault UIs and manage vaulted payment methods.
2038
+ */
2039
+ export interface VaultAPI {
2040
+ /**
2041
+ * Creates a CVV input for vaulted payment method CVV recapture.
2042
+ *
2043
+ * @param options - CVV input configuration options
2044
+ * @returns Promise resolving to CvvInput instance, or null if vault unavailable
2045
+ */
2046
+ createCvvInput(options: CardSecurityCodeInputOptions): Promise<CvvInput | null>;
2047
+ /**
2048
+ * Starts payment using a vaulted payment method.
2049
+ *
2050
+ * @param paymentMethodId - The unique identifier of the vaulted payment method
2051
+ * @param options - Optional payment configuration
2052
+ * @returns Promise that resolves when payment flow initiates
2053
+ * @throws Error if vault not initialized or payment method not found
2054
+ */
2055
+ startPayment(paymentMethodId: string, options?: {
2056
+ cvv?: string;
2057
+ }): Promise<void>;
2058
+ /**
2059
+ * Deletes a vaulted payment method from the vault.
2060
+ *
2061
+ * @param paymentMethodId - The unique identifier of the payment method to delete
2062
+ * @returns Promise that resolves when deletion completes
2063
+ * @throws Error if vault not initialized
2064
+ */
2065
+ delete(paymentMethodId: string): Promise<void>;
2066
+ }
1965
2067
  /**
1966
2068
  * PrimerJS is a wrapper class that provides a stable API for interfacing with the Primer SDK
1967
2069
  * while hiding direct access to the legacy headless instance.
@@ -1971,6 +2073,20 @@ export declare class PrimerJS {
1971
2073
  private paymentMethods;
1972
2074
  private paymentManagers;
1973
2075
  private vaultController;
2076
+ /**
2077
+ * Vault namespace providing programmatic access to vaulted payment method operations.
2078
+ * Use for building custom vault UIs with headless flows.
2079
+ *
2080
+ * @example
2081
+ * ```typescript
2082
+ * // Start payment with vaulted method
2083
+ * await primerJS.vault.startPayment(methodId);
2084
+ *
2085
+ * // Delete a vaulted method
2086
+ * await primerJS.vault.delete(methodId);
2087
+ * ```
2088
+ */
2089
+ readonly vault: VaultAPI;
1974
2090
  /**
1975
2091
  * Called when payment flow begins.
1976
2092
  * Use for analytics tracking or UI updates (e.g., disable form).
@@ -2107,88 +2223,41 @@ export declare class PrimerJS {
2107
2223
  * @internal
2108
2224
  */
2109
2225
  setVaultController(controller: VaultManagerController | null): void;
2226
+ /**
2227
+ * Internal implementation of createCvvInput.
2228
+ * @internal
2229
+ */
2230
+ private createCvvInputInternal;
2231
+ /**
2232
+ * Internal implementation of startVaultPayment.
2233
+ * @internal
2234
+ */
2235
+ private startVaultPaymentInternal;
2236
+ /**
2237
+ * Deletes a vaulted payment method.
2238
+ * @internal
2239
+ */
2240
+ private deleteVaultPaymentMethod;
2110
2241
  /**
2111
2242
  * Creates a CVV input for vaulted payment method CVV recapture.
2112
2243
  *
2113
- * ⚠️ Requires vault to be initialized. Check vault availability via
2114
- * the onVaultedMethodsUpdate callback before calling.
2244
+ * @deprecated Use primerJS.vault.createCvvInput() instead.
2245
+ * This method will be removed in a future major version.
2115
2246
  *
2116
2247
  * @param options - CVV input configuration
2117
2248
  * @returns Promise resolving to CvvInput or null if vault unavailable
2118
- *
2119
- * @example
2120
- * ```typescript
2121
- * const method = vaultedPayments.get(selectedId);
2122
- * const cvvInput = await primerJS.createCvvInput({
2123
- * cardNetwork: method.paymentInstrumentData.network,
2124
- * container: "#cvv-container",
2125
- * placeholder: "123"
2126
- * });
2127
- *
2128
- * if (cvvInput.metadata.error) {
2129
- * // Handle validation error
2130
- * }
2131
- * ```
2132
2249
  */
2133
2250
  createCvvInput(options: CardSecurityCodeInputOptions): Promise<CvvInput | null>;
2134
2251
  /**
2135
2252
  * Initiates payment using a vaulted payment method.
2136
2253
  *
2137
- * Enables headless vault flows where merchants build custom vault UIs.
2138
- * Mirrors the legacy SDK's vaultManager.startPaymentFlow().
2254
+ * @deprecated Use primerJS.vault.startPayment() instead.
2255
+ * This method will be removed in a future major version.
2139
2256
  *
2140
2257
  * @param paymentMethodId - The ID of the vaulted payment method
2141
2258
  * @param options - Optional payment options
2142
- * @param options.cvv - CVV value token (required if cvvRecapture is true)
2143
2259
  * @returns Promise that resolves when payment flow starts
2144
2260
  * @throws Error if vault not initialized or payment method not found
2145
- *
2146
- * @example
2147
- * ```typescript
2148
- * // Complete headless vault flow
2149
- * let vaultedMethods;
2150
- * let needsCvv = false;
2151
- *
2152
- * primerJS.onVaultedMethodsUpdate = ({ vaultedPayments, cvvRecapture }) => {
2153
- * vaultedMethods = vaultedPayments.toArray();
2154
- * needsCvv = cvvRecapture;
2155
- *
2156
- * // Build custom vault UI
2157
- * vaultedMethods.forEach(method => {
2158
- * displayVaultItem({
2159
- * id: method.id,
2160
- * last4: method.paymentInstrumentData?.last4Digits,
2161
- * network: method.paymentInstrumentData?.network
2162
- * });
2163
- * });
2164
- * };
2165
- *
2166
- * // When user submits payment
2167
- * async function handlePayment(selectedMethodId) {
2168
- * try {
2169
- * if (needsCvv) {
2170
- * const method = vaultedMethods.find(m => m.id === selectedMethodId);
2171
- * const cvvInput = await primerJS.createCvvInput({
2172
- * cardNetwork: method.paymentInstrumentData.network,
2173
- * container: "#cvv-container"
2174
- * });
2175
- *
2176
- * if (cvvInput.metadata.error) {
2177
- * showError("Invalid CVV");
2178
- * return;
2179
- * }
2180
- *
2181
- * await primerJS.startVaultPayment(selectedMethodId, {
2182
- * cvv: cvvInput.valueToken
2183
- * });
2184
- * } else {
2185
- * await primerJS.startVaultPayment(selectedMethodId);
2186
- * }
2187
- * } catch (error) {
2188
- * console.error("Payment failed:", error);
2189
- * }
2190
- * }
2191
- * ```
2192
2261
  */
2193
2262
  startVaultPayment(paymentMethodId: string, options?: {
2194
2263
  cvv?: string;