@primer-io/primer-js 1.6.1 → 1.6.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.
@@ -476,6 +476,8 @@ export type RedirectPaymentComponentProps = {
476
476
  paymentMethod?: RedirectPaymentMethod | undefined;
477
477
  /** */
478
478
  disabled?: boolean;
479
+ /** */
480
+ primerContext?: ContextType | undefined;
479
481
  };
480
482
 
481
483
  export type ShowOtherPaymentsComponentProps = {
@@ -614,14 +614,71 @@ export type TranslateFunction = (key: string, fallback: string) => string;
614
614
  * Analytics environment type (mirrors @primer-io/sdk-utils/analytics)
615
615
  */
616
616
  export type AnalyticsEnvironment = "LOCAL" | "DEV" | "STAGING" | "SANDBOX" | "PRODUCTION";
617
+ /**
618
+ * Who should act on an SDK error (mirrors `SdkErrorOrigin` from
619
+ * @primer-io/sdk-utils/errors/types):
620
+ * - `integration`: the merchant's integration must be fixed — see `suggestion`
621
+ * - `primer`: unexpected Primer-side behaviour — report to Primer support
622
+ * - `user`: expected outcome of a shopper action (e.g. cancellation)
623
+ * - `network`: an API request failed at the transport/HTTP level
624
+ * - `payment`: the payment failed or was declined — check the Dashboard
625
+ */
626
+ export type SdkErrorOrigin = "integration" | "primer" | "user" | "network" | "payment";
617
627
  /**
618
628
  * SDK Error class interface (mirrors @primer-io/sdk-utils/errors/errors)
619
- * Base class for all SDK errors with error code and nested error.
629
+ * Class for all SDK errors with origin, error code and nested error.
620
630
  */
621
631
  export interface SdkError extends Error {
632
+ /** Who should act on this error — see {@link SdkErrorOrigin} */
633
+ readonly origin: SdkErrorOrigin;
622
634
  readonly code: string;
635
+ /** How to fix this error, present on `integration`-origin errors */
636
+ readonly suggestion?: string;
623
637
  readonly error?: unknown;
624
638
  }
639
+ /**
640
+ * Session-bound telemetry client (mirrors `Telemetry` from
641
+ * @primer-io/sdk-utils/telemetry). One instance per checkout session, created
642
+ * with the checkout context and disposed on teardown.
643
+ */
644
+ export interface TelemetryClient {
645
+ readonly session: {
646
+ environment: AnalyticsEnvironment;
647
+ checkoutSessionId: string;
648
+ clientSessionId: string;
649
+ primerAccountId: string;
650
+ sdkVersion: string;
651
+ clientSessionToken?: string;
652
+ userAgent: string;
653
+ /** Timestamp (ms) when the first backend call (/configuration) started */
654
+ sdkInitStartTime?: number;
655
+ };
656
+ readonly analytics: {
657
+ sendEvent(event: {
658
+ eventName: string;
659
+ [key: string]: unknown;
660
+ }): void;
661
+ };
662
+ readonly remoteLog: {
663
+ log(message: string, config?: {
664
+ metadata?: Record<string, unknown>;
665
+ status?: "error" | "warn" | "info";
666
+ }): void;
667
+ checkoutInitialized(initDurationMs?: number): void;
668
+ };
669
+ /**
670
+ * Console error + Datadog report for unexpected technical errors, exactly
671
+ * once per error. Do NOT use for expected operational errors (payment
672
+ * failures, validation errors, etc). `options.message` gives the report a
673
+ * call-site context message.
674
+ */
675
+ reportSdkError(error: unknown, options?: {
676
+ message?: string;
677
+ }): void;
678
+ setSdkInitStartTime(timestamp: number): void;
679
+ getSdkInitStartTime(): number | undefined;
680
+ dispose(): void;
681
+ }
625
682
  declare enum HeadlessManagerType {
626
683
  BLIK = "BLIK",
627
684
  CARD = "CARD",
@@ -1180,21 +1237,12 @@ export interface SDKUtilities {
1180
1237
  getPaymentMethodConfiguration: (paymentType: PaymentMethodType) => PaymentMethodConfig | undefined;
1181
1238
  setBillingAddress: (address: NullableAddress) => Promise<void>;
1182
1239
  }
1183
- export interface AnalyticsUtils {
1184
- environment: AnalyticsEnvironment;
1185
- primerAccountId?: string;
1186
- checkoutSessionId: string;
1187
- clientSessionId?: string;
1188
- clientSessionToken?: string;
1189
- sdkVersion?: string;
1190
- /** Timestamp (ms) when the first backend call (/configuration) started */
1191
- configurationFetchStartTime?: number;
1192
- }
1193
1240
  export interface PrimerHeadlessCheckout {
1194
1241
  start: () => Promise<void>;
1195
1242
  createPaymentMethodManager: (type: string, managerOptions?: PaymentMethodManagerOptions) => Promise<PaymentMethodManager | null>;
1196
1243
  getSDKUtilities: () => SDKUtilities;
1197
- getAnalyticsUtils?: () => AnalyticsUtils;
1244
+ /** Session-bound telemetry, shared with all sdk-core internals via the checkout context */
1245
+ getTelemetry: () => TelemetryClient;
1198
1246
  createVaultManager: () => HeadlessVaultManager;
1199
1247
  getAssetsManager: () => unknown;
1200
1248
  refreshClientSession: () => Promise<boolean>;
@@ -1732,7 +1780,11 @@ export type SdkState = {
1732
1780
  } | null;
1733
1781
  };
1734
1782
  export type ContextType = {
1735
- analytics?: AnalyticsUtils;
1783
+ /**
1784
+ * Session-bound analytics and remote logging, published once the headless
1785
+ * SDK has initialized. Absent while loading and in legacy mode.
1786
+ */
1787
+ telemetry?: TelemetryClient;
1736
1788
  configuration?: ClientConfiguration;
1737
1789
  computedStyles?: CSSStyleDeclaration | null;
1738
1790
  klarnaCategories: KlarnaCategoriesContextType;
@@ -1743,6 +1795,7 @@ export type ContextType = {
1743
1795
  paymentMethods: InitializedPaymentMethod[];
1744
1796
  headlessUtils?: SDKUtilities;
1745
1797
  sdkState: SdkState;
1798
+ setProcessing?: (isProcessing: boolean) => void;
1746
1799
  vaultManager?: VaultManagerState;
1747
1800
  vaultItem?: VaultManagerItemState;
1748
1801
  };
@@ -2494,6 +2547,12 @@ declare class HeadlessSdkController implements ReactiveController {
2494
2547
  private primerJS;
2495
2548
  private loadingTimeout;
2496
2549
  private isDisconnected;
2550
+ /**
2551
+ * Session-bound telemetry of the current SDK instance. Held here (in
2552
+ * addition to the Lit context) so teardown paths can still emit
2553
+ * PAYMENT_FLOW_EXITED before the instance is disposed.
2554
+ */
2555
+ private telemetry;
2497
2556
  constructor(host: PrimerCheckoutType);
2498
2557
  get primerJSInstance(): PrimerJS | null;
2499
2558
  hostConnected(): void;
@@ -2501,6 +2560,12 @@ declare class HeadlessSdkController implements ReactiveController {
2501
2560
  private setupLoadingTimeout;
2502
2561
  private clearLoadingTimeout;
2503
2562
  private cleanupResources;
2563
+ /**
2564
+ * Datadog error reporting that works across the whole lifecycle: uses the
2565
+ * session telemetry once it exists, and the pre-init error context while
2566
+ * initialization is still in flight (e.g. createCheckoutContext threw).
2567
+ */
2568
+ private reportError;
2504
2569
  /**
2505
2570
  * MANUAL approval flow: on a `:pay` 202, sdk-core invokes this. Keep the SDK
2506
2571
  * in the processing state (so the checkout shows its loading UI and stays
@@ -3466,6 +3531,7 @@ declare class RedirectPaymentComponent extends LitElement {
3466
3531
  static styles: import("lit").CSSResult;
3467
3532
  paymentMethod: RedirectPaymentMethod | undefined;
3468
3533
  disabled: boolean;
3534
+ primerContext?: ContextType;
3469
3535
  private _handleClick;
3470
3536
  render(): import("lit-html").TemplateResult<1>;
3471
3537
  }