@primer-io/primer-js 1.6.1 → 1.6.2

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.
@@ -614,14 +614,75 @@ 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(messageOrError: unknown, config?: {
664
+ metadata?: Record<string, unknown>;
665
+ status?: "error" | "warn" | "info";
666
+ }): void;
667
+ error(messageOrError: unknown, config?: {
668
+ metadata?: Record<string, unknown>;
669
+ status?: "error" | "warn" | "info";
670
+ }): void;
671
+ checkoutInitialized(initDurationMs?: number): void;
672
+ };
673
+ /**
674
+ * Console error + Datadog report for unexpected technical errors, exactly
675
+ * once per error. Do NOT use for expected operational errors (payment
676
+ * failures, validation errors, etc). `options.message` gives the report a
677
+ * call-site context message.
678
+ */
679
+ reportSdkError(error: unknown, options?: {
680
+ message?: string;
681
+ }): void;
682
+ setSdkInitStartTime(timestamp: number): void;
683
+ getSdkInitStartTime(): number | undefined;
684
+ dispose(): void;
685
+ }
625
686
  declare enum HeadlessManagerType {
626
687
  BLIK = "BLIK",
627
688
  CARD = "CARD",
@@ -1180,21 +1241,12 @@ export interface SDKUtilities {
1180
1241
  getPaymentMethodConfiguration: (paymentType: PaymentMethodType) => PaymentMethodConfig | undefined;
1181
1242
  setBillingAddress: (address: NullableAddress) => Promise<void>;
1182
1243
  }
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
1244
  export interface PrimerHeadlessCheckout {
1194
1245
  start: () => Promise<void>;
1195
1246
  createPaymentMethodManager: (type: string, managerOptions?: PaymentMethodManagerOptions) => Promise<PaymentMethodManager | null>;
1196
1247
  getSDKUtilities: () => SDKUtilities;
1197
- getAnalyticsUtils?: () => AnalyticsUtils;
1248
+ /** Session-bound telemetry, shared with all sdk-core internals via the checkout context */
1249
+ getTelemetry: () => TelemetryClient;
1198
1250
  createVaultManager: () => HeadlessVaultManager;
1199
1251
  getAssetsManager: () => unknown;
1200
1252
  refreshClientSession: () => Promise<boolean>;
@@ -1732,7 +1784,11 @@ export type SdkState = {
1732
1784
  } | null;
1733
1785
  };
1734
1786
  export type ContextType = {
1735
- analytics?: AnalyticsUtils;
1787
+ /**
1788
+ * Session-bound analytics and remote logging, published once the headless
1789
+ * SDK has initialized. Absent while loading and in legacy mode.
1790
+ */
1791
+ telemetry?: TelemetryClient;
1736
1792
  configuration?: ClientConfiguration;
1737
1793
  computedStyles?: CSSStyleDeclaration | null;
1738
1794
  klarnaCategories: KlarnaCategoriesContextType;
@@ -2494,6 +2550,12 @@ declare class HeadlessSdkController implements ReactiveController {
2494
2550
  private primerJS;
2495
2551
  private loadingTimeout;
2496
2552
  private isDisconnected;
2553
+ /**
2554
+ * Session-bound telemetry of the current SDK instance. Held here (in
2555
+ * addition to the Lit context) so teardown paths can still emit
2556
+ * PAYMENT_FLOW_EXITED before the instance is disposed.
2557
+ */
2558
+ private telemetry;
2497
2559
  constructor(host: PrimerCheckoutType);
2498
2560
  get primerJSInstance(): PrimerJS | null;
2499
2561
  hostConnected(): void;
@@ -2501,6 +2563,12 @@ declare class HeadlessSdkController implements ReactiveController {
2501
2563
  private setupLoadingTimeout;
2502
2564
  private clearLoadingTimeout;
2503
2565
  private cleanupResources;
2566
+ /**
2567
+ * Datadog error reporting that works across the whole lifecycle: uses the
2568
+ * session telemetry once it exists, and the pre-init error context while
2569
+ * initialization is still in flight (e.g. createCheckoutContext threw).
2570
+ */
2571
+ private reportError;
2504
2572
  /**
2505
2573
  * MANUAL approval flow: on a `:pay` 202, sdk-core invokes this. Keep the SDK
2506
2574
  * in the processing state (so the checkout shows its loading UI and stays