@metamask/connect-multichain 0.12.1 → 0.14.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/dist/browser/es/connect-multichain.d.mts +46 -2
  3. package/dist/browser/es/connect-multichain.mjs +1733 -1566
  4. package/dist/browser/es/connect-multichain.mjs.map +1 -1
  5. package/dist/browser/es/metafile-esm.json +1 -1
  6. package/dist/browser/iife/connect-multichain.d.ts +46 -2
  7. package/dist/browser/iife/connect-multichain.js +6279 -5413
  8. package/dist/browser/iife/connect-multichain.js.map +1 -1
  9. package/dist/browser/iife/metafile-iife.json +1 -1
  10. package/dist/browser/umd/connect-multichain.d.ts +46 -2
  11. package/dist/browser/umd/connect-multichain.js +1761 -1589
  12. package/dist/browser/umd/connect-multichain.js.map +1 -1
  13. package/dist/browser/umd/metafile-cjs.json +1 -1
  14. package/dist/node/cjs/connect-multichain.d.ts +46 -2
  15. package/dist/node/cjs/connect-multichain.js +892 -719
  16. package/dist/node/cjs/connect-multichain.js.map +1 -1
  17. package/dist/node/cjs/metafile-cjs.json +1 -1
  18. package/dist/node/es/connect-multichain.d.mts +46 -2
  19. package/dist/node/es/connect-multichain.mjs +890 -723
  20. package/dist/node/es/connect-multichain.mjs.map +1 -1
  21. package/dist/node/es/metafile-esm.json +1 -1
  22. package/dist/react-native/es/connect-multichain.d.mts +46 -2
  23. package/dist/react-native/es/connect-multichain.mjs +890 -723
  24. package/dist/react-native/es/connect-multichain.mjs.map +1 -1
  25. package/dist/react-native/es/metafile-esm.json +1 -1
  26. package/dist/src/domain/multichain/index.d.ts +1 -1
  27. package/dist/src/domain/multichain/index.d.ts.map +1 -1
  28. package/dist/src/domain/utils/index.d.ts +2 -1
  29. package/dist/src/domain/utils/index.d.ts.map +1 -1
  30. package/dist/src/domain/utils/index.js +1 -1
  31. package/dist/src/domain/utils/index.js.map +1 -1
  32. package/dist/src/multichain/index.d.ts +2 -2
  33. package/dist/src/multichain/index.d.ts.map +1 -1
  34. package/dist/src/multichain/index.js +39 -25
  35. package/dist/src/multichain/index.js.map +1 -1
  36. package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
  37. package/dist/src/multichain/rpc/requestRouter.js +4 -4
  38. package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
  39. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +1 -0
  40. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
  41. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +10 -10
  42. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
  43. package/dist/src/multichain/transports/mwp/KeyManager.d.ts +12 -9
  44. package/dist/src/multichain/transports/mwp/KeyManager.d.ts.map +1 -1
  45. package/dist/src/multichain/transports/mwp/KeyManager.js +38 -25
  46. package/dist/src/multichain/transports/mwp/KeyManager.js.map +1 -1
  47. package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
  48. package/dist/src/multichain/transports/mwp/index.js +18 -6
  49. package/dist/src/multichain/transports/mwp/index.js.map +1 -1
  50. package/dist/src/multichain/utils/analytics.d.ts +82 -1
  51. package/dist/src/multichain/utils/analytics.d.ts.map +1 -1
  52. package/dist/src/multichain/utils/analytics.js +252 -17
  53. package/dist/src/multichain/utils/analytics.js.map +1 -1
  54. package/dist/types/connect-multichain.d.ts +46 -2
  55. package/package.json +2 -2
@@ -679,13 +679,42 @@ declare abstract class Modal<Options, Data extends DataType = DataType> {
679
679
  set data(data: Data);
680
680
  }
681
681
 
682
+ /**
683
+ * Tag describing the cause of a failed wallet action / connection. Surfaced
684
+ * as the `failure_reason` property on `mmconnect_wallet_action_failed` and
685
+ * `mmconnect_connection_failed` events so we can distinguish e.g. a transport
686
+ * timeout from a wallet-side internal error in Mixpanel.
687
+ *
688
+ * Intentionally a string union (not a const enum) so callers stay free to
689
+ * pass through a new bucket; the schema-side property is an open string for
690
+ * the same reason.
691
+ */
692
+ type FailureReason = 'transport_timeout' | 'transport_disconnect' | 'wallet_method_unsupported' | 'wallet_invalid_params' | 'wallet_internal_error' | 'wallet_unauthorized' | 'unrecognized_chain' | 'unknown';
682
693
  /**
683
694
  * Checks if an error represents a user rejection.
684
695
  *
696
+ * Unwraps `RPCInvokeMethodErr` so the wallet's `code: 4001` survives the
697
+ * SDK's transport-boundary wrapping (the outer error otherwise reports
698
+ * `code: 53`, which would never match the heuristics here).
699
+ *
685
700
  * @param error - The error object to check
686
701
  * @returns True if the error indicates a user rejection, false otherwise
687
702
  */
688
703
  declare function isRejectionError(error: unknown): boolean;
704
+ /**
705
+ * Classifies a failed wallet action / connection error into a short tag for
706
+ * the `failure_reason` analytics property. Caller is expected to have already
707
+ * established that the error is *not* a user rejection (use `isRejectionError`
708
+ * for that branching).
709
+ *
710
+ * The taxonomy is deliberately producer-side-only — the schema accepts any
711
+ * string — so we can add buckets here without an API migration. Once the
712
+ * distribution stabilises we may convert the schema field to a closed enum.
713
+ *
714
+ * @param error - The error to classify
715
+ * @returns A short, snake_case tag describing why the operation failed
716
+ */
717
+ declare function classifyFailureReason(error: unknown): FailureReason;
689
718
  /**
690
719
  * Gets analytics properties specific to wallet action events.
691
720
  *
@@ -693,15 +722,30 @@ declare function isRejectionError(error: unknown): boolean;
693
722
  * @param storage - Storage client for getting anonymous ID
694
723
  * @param invokeOptions - The invoke method options containing method and scope
695
724
  * @param transportType - The transport type to use for the analytics event
725
+ * @param extra - Optional event-specific diagnostic properties. Used by
726
+ * `mmconnect_wallet_action_failed` to attach the {@link ErrorDiagnostics}
727
+ * bundle (`failure_reason`, `error_code`, `error_message_sample`).
728
+ * @param extra.failure_reason - A short tag describing why the operation
729
+ * failed; see `classifyFailureReason` and the `FailureReason` union.
730
+ * @param extra.error_code - The raw wallet-side error code, if present.
731
+ * @param extra.error_message_sample - A sanitised, truncated sample of the
732
+ * original error message.
696
733
  * @returns Wallet action analytics properties
697
734
  */
698
- declare function getWalletActionAnalyticsProperties(options: MultichainOptions, storage: StoreClient, invokeOptions: InvokeMethodOptions, transportType: TransportType): Promise<{
735
+ declare function getWalletActionAnalyticsProperties(options: MultichainOptions, storage: StoreClient, invokeOptions: InvokeMethodOptions, transportType: TransportType, extra?: {
736
+ failure_reason?: FailureReason;
737
+ error_code?: number;
738
+ error_message_sample?: string;
739
+ }): Promise<{
699
740
  mmconnect_versions: Record<string, string>;
700
741
  dapp_id: string;
701
742
  method: string;
702
743
  caip_chain_id: string;
703
744
  anon_id: string;
704
745
  transport_type: TransportType;
746
+ failure_reason?: FailureReason;
747
+ error_code?: number;
748
+ error_message_sample?: string;
705
749
  }>;
706
750
 
707
751
  /**
@@ -713,4 +757,4 @@ declare function getVersion(): string;
713
757
 
714
758
  declare const createMultichainClient: CreateMultichainFN;
715
759
 
716
- export { type ConnectVersions, type ConnectionRequest, type ConnectionStatus, type CreateMultichainFN, type DappSettings, type DataType, type DomainErrorCodes, type Enumerate, type ErrorCodeRange, type ErrorCodes, EventEmitter, type EventTypes, type ExtendedTransport, type InstallWidgetProps, type InvokeMethodOptions, type LoggerNameSpaces, type MergeableMultichainOptions, Modal, type ModalFactoryConnectOptions, type ModalFactoryOptions, MultichainCore, type MultichainOptions, type NotificationCallback, type OTPCode, type OTPCodeWidgetProps, PlatformType, type QRLink, type RPCAPI, type RPCErrorCodes, RPCHttpErr, RPCInvokeMethodErr, RPCReadonlyRequestErr, RPCReadonlyResponseErr, type RPCResponse, RPC_HANDLED_METHODS, type RpcMethod, type RpcUrlsMap, type SDKEvents, SDK_HANDLED_METHODS, type Scope, type StorageErrorCodes, StoreAdapter, StoreClient, type StoreOptions, TransportType, createLogger, createMultichainClient, enableDebug, getInfuraRpcUrls, getPlatformType, getTransportType, getVersion, getWalletActionAnalyticsProperties, hasExtension, infuraRpcUrls, isEnabled, isMetamaskExtensionInstalled, isRejectionError, isSecure };
760
+ export { type ConnectVersions, type ConnectionRequest, type ConnectionStatus, type CreateMultichainFN, type DappSettings, type DataType, type DomainErrorCodes, type Enumerate, type ErrorCodeRange, type ErrorCodes, EventEmitter, type EventTypes, type ExtendedTransport, type FailureReason, type InstallWidgetProps, type InvokeMethodOptions, type LoggerNameSpaces, type MergeableMultichainOptions, Modal, type ModalFactoryConnectOptions, type ModalFactoryOptions, MultichainCore, type MultichainOptions, type NotificationCallback, type OTPCode, type OTPCodeWidgetProps, PlatformType, type QRLink, type RPCAPI, type RPCErrorCodes, RPCHttpErr, RPCInvokeMethodErr, RPCReadonlyRequestErr, RPCReadonlyResponseErr, type RPCResponse, RPC_HANDLED_METHODS, type RpcMethod, type RpcUrlsMap, type SDKEvents, SDK_HANDLED_METHODS, type Scope, type StorageErrorCodes, StoreAdapter, StoreClient, type StoreOptions, TransportType, classifyFailureReason, createLogger, createMultichainClient, enableDebug, getInfuraRpcUrls, getPlatformType, getTransportType, getVersion, getWalletActionAnalyticsProperties, hasExtension, infuraRpcUrls, isEnabled, isMetamaskExtensionInstalled, isRejectionError, isSecure };