@metamask/connect-multichain 0.9.0 → 0.10.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 (39) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/README.md +18 -6
  3. package/dist/browser/es/connect-multichain.d.mts +13 -3
  4. package/dist/browser/es/connect-multichain.mjs +33 -22
  5. package/dist/browser/es/connect-multichain.mjs.map +1 -1
  6. package/dist/browser/es/metafile-esm.json +1 -1
  7. package/dist/browser/iife/connect-multichain.d.ts +13 -3
  8. package/dist/browser/iife/connect-multichain.js +41 -22
  9. package/dist/browser/iife/connect-multichain.js.map +1 -1
  10. package/dist/browser/iife/metafile-iife.json +1 -1
  11. package/dist/browser/umd/connect-multichain.d.ts +13 -3
  12. package/dist/browser/umd/connect-multichain.js +33 -22
  13. package/dist/browser/umd/connect-multichain.js.map +1 -1
  14. package/dist/browser/umd/metafile-cjs.json +1 -1
  15. package/dist/node/cjs/connect-multichain.d.ts +13 -3
  16. package/dist/node/cjs/connect-multichain.js +33 -22
  17. package/dist/node/cjs/connect-multichain.js.map +1 -1
  18. package/dist/node/cjs/metafile-cjs.json +1 -1
  19. package/dist/node/es/connect-multichain.d.mts +13 -3
  20. package/dist/node/es/connect-multichain.mjs +33 -22
  21. package/dist/node/es/connect-multichain.mjs.map +1 -1
  22. package/dist/node/es/metafile-esm.json +1 -1
  23. package/dist/react-native/es/connect-multichain.d.mts +13 -3
  24. package/dist/react-native/es/connect-multichain.mjs +33 -22
  25. package/dist/react-native/es/connect-multichain.mjs.map +1 -1
  26. package/dist/react-native/es/metafile-esm.json +1 -1
  27. package/dist/src/domain/multichain/api/infura.d.ts +13 -1
  28. package/dist/src/domain/multichain/api/infura.d.ts.map +1 -1
  29. package/dist/src/domain/multichain/api/infura.js +17 -5
  30. package/dist/src/domain/multichain/api/infura.js.map +1 -1
  31. package/dist/src/multichain/index.d.ts.map +1 -1
  32. package/dist/src/multichain/index.js +19 -6
  33. package/dist/src/multichain/index.js.map +1 -1
  34. package/dist/src/multichain/utils/analytics.d.ts +1 -4
  35. package/dist/src/multichain/utils/analytics.d.ts.map +1 -1
  36. package/dist/src/multichain/utils/analytics.js +5 -9
  37. package/dist/src/multichain/utils/analytics.js.map +1 -1
  38. package/dist/types/connect-multichain.d.ts +13 -3
  39. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.10.0]
11
+
12
+ ### Changed
13
+
14
+ - **BREAKING** `getInfuraRpcUrls` now accepts a single options object `{ infuraApiKey, caipChainIds? }` instead of a positional `infuraApiKey` string. The optional `caipChainIds` parameter filters the output to only the specified CAIP-2 chain IDs ([#211](https://github.com/MetaMask/connect-monorepo/pull/211))
15
+ - use merged integration types in analytics ([#223](https://github.com/MetaMask/connect-monorepo/pull/223))
16
+
17
+ ### Fixed
18
+
19
+ - fix: Fix react-native-playground consumption of **PACKAGE_VERSION** build-time constant in connect packages ([#221](https://github.com/MetaMask/connect-monorepo/pull/221))
20
+
10
21
  ## [0.9.0]
11
22
 
12
23
  ### Added
@@ -199,7 +210,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
199
210
 
200
211
  - Initial release
201
212
 
202
- [Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.9.0...HEAD
213
+ [Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.10.0...HEAD
214
+ [0.10.0]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.9.0...@metamask/connect-multichain@0.10.0
203
215
  [0.9.0]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.8.0...@metamask/connect-multichain@0.9.0
204
216
  [0.8.0]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.7.0...@metamask/connect-multichain@0.8.0
205
217
  [0.7.0]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.6.0...@metamask/connect-multichain@0.7.0
package/README.md CHANGED
@@ -32,7 +32,7 @@ const client = await createMultichainClient({
32
32
  api: {
33
33
  supportedNetworks: {
34
34
  // use the `getInfuraRpcUrls` helper to generate a map of Infura RPC endpoints
35
- ...getInfuraRpcUrls(INFURA_API_KEY),
35
+ ...getInfuraRpcUrls({ infuraApiKey: INFURA_API_KEY }),
36
36
  // or specify your own CAIP Chain ID to rpc endpoint mapping
37
37
  'eip155:1': 'https://mainnet.example.io/rpc',
38
38
  'eip155:137': 'https://polygon-mainnet.example.io/rpc',
@@ -338,15 +338,16 @@ Emits an event to all registered handlers.
338
338
 
339
339
  ### Utilities
340
340
 
341
- #### `getInfuraRpcUrls(infuraApiKey)`
341
+ #### `getInfuraRpcUrls(options)`
342
342
 
343
343
  Generates Infura RPC URLs for common networks keyed by CAIP Chain ID.
344
344
 
345
345
  **Parameters**
346
346
 
347
- | Name | Type | Required | Description |
348
- | -------------- | -------- | -------- | ------------------- |
349
- | `infuraApiKey` | `string` | Yes | Your Infura API key |
347
+ | Name | Type | Required | Description |
348
+ | -------------- | --------------- | -------- | ------------------------------------- |
349
+ | `infuraApiKey` | `string` | Yes | Your Infura API key |
350
+ | `caipChainIds` | `CaipChainId[]` | No | CAIP-2 chain IDs to filter the output |
350
351
 
351
352
  **Returns**
352
353
 
@@ -355,13 +356,24 @@ A map of [CAIP-2 chain IDs](https://chainagnostic.org/CAIPs/caip-2) to Infura RP
355
356
  ```typescript
356
357
  import { getInfuraRpcUrls } from '@metamask/connect-multichain';
357
358
 
358
- const rpcUrls = getInfuraRpcUrls('YOUR_INFURA_KEY');
359
+ // Get all supported Infura RPC URLs
360
+ const rpcUrls = getInfuraRpcUrls({ infuraApiKey: 'YOUR_INFURA_KEY' });
359
361
  // {
360
362
  // 'eip155:1': 'https://mainnet.infura.io/v3/YOUR_KEY',
361
363
  // 'eip155:137': 'https://polygon-mainnet.infura.io/v3/YOUR_KEY',
362
364
  // 'eip155:11155111': 'https://sepolia.infura.io/v3/YOUR_KEY',
363
365
  // ...
364
366
  // }
367
+
368
+ // Filter to specific chains
369
+ const filtered = getInfuraRpcUrls({
370
+ infuraApiKey: 'YOUR_INFURA_KEY',
371
+ caipChainIds: ['eip155:1', 'eip155:137'],
372
+ });
373
+ // {
374
+ // 'eip155:1': 'https://mainnet.infura.io/v3/YOUR_KEY',
375
+ // 'eip155:137': 'https://polygon-mainnet.infura.io/v3/YOUR_KEY',
376
+ // }
365
377
  ```
366
378
 
367
379
  ---
@@ -1,7 +1,7 @@
1
1
  import debug from 'debug';
2
2
  import { SessionData, Transport, SessionProperties, TransportRequest, TransportResponse, MultichainApiClient } from '@metamask/multichain-api-client';
3
3
  export { SessionData } from '@metamask/multichain-api-client';
4
- import { CaipAccountId, Json } from '@metamask/utils';
4
+ import { CaipAccountId, CaipChainId, Json } from '@metamask/utils';
5
5
  import { SessionRequest, Session } from '@metamask/mobile-wallet-protocol-core';
6
6
  import { Components } from '@metamask/multichain-ui';
7
7
 
@@ -485,7 +485,18 @@ declare const infuraRpcUrls: RpcUrlsMap;
485
485
  declare const RPC_HANDLED_METHODS: Set<string>;
486
486
  declare const SDK_HANDLED_METHODS: Set<string>;
487
487
 
488
- declare function getInfuraRpcUrls(infuraAPIKey: string): RpcUrlsMap;
488
+ /**
489
+ * Generates Infura RPC URLs for common networks keyed by CAIP Chain ID.
490
+ *
491
+ * @param options - The options for generating Infura RPC URLs
492
+ * @param options.infuraApiKey - The Infura API key
493
+ * @param options.caipChainIds - Optional CAIP-2 chain IDs to filter the output
494
+ * @returns A map of CAIP-2 chain IDs to Infura RPC URLs
495
+ */
496
+ declare function getInfuraRpcUrls({ infuraApiKey, caipChainIds, }: {
497
+ infuraApiKey: string;
498
+ caipChainIds?: CaipChainId[];
499
+ }): RpcUrlsMap;
489
500
 
490
501
  type ConnectionStatus = 'pending' | 'loaded' | 'disconnected' | 'connected' | 'connecting';
491
502
  declare enum TransportType {
@@ -676,7 +687,6 @@ declare function getWalletActionAnalyticsProperties(options: MultichainOptions,
676
687
  mmconnect_versions: Record<string, string>;
677
688
  dapp_id: string;
678
689
  method: string;
679
- integration_type: string;
680
690
  caip_chain_id: string;
681
691
  anon_id: string;
682
692
  transport_type: TransportType;
@@ -356,10 +356,16 @@ var init_constants = __esm({
356
356
  });
357
357
 
358
358
  // src/domain/multichain/api/infura.ts
359
- function getInfuraRpcUrls(infuraAPIKey) {
360
- return Object.keys(infuraRpcUrls).reduce((acc, key) => {
361
- const typedKey = key;
362
- acc[typedKey] = `${infuraRpcUrls[typedKey]}${infuraAPIKey}`;
359
+ function getInfuraRpcUrls({
360
+ infuraApiKey,
361
+ caipChainIds
362
+ }) {
363
+ const keys = caipChainIds && caipChainIds.length > 0 ? caipChainIds : Object.keys(infuraRpcUrls);
364
+ return keys.reduce((acc, key) => {
365
+ const baseUrl = infuraRpcUrls[key];
366
+ if (baseUrl) {
367
+ acc[key] = `${baseUrl}${infuraApiKey}`;
368
+ }
363
369
  return acc;
364
370
  }, {});
365
371
  }
@@ -627,31 +633,27 @@ function isRejectionError(error) {
627
633
  }
628
634
  function getBaseAnalyticsProperties(options, storage) {
629
635
  return __async(this, null, function* () {
630
- var _a3, _b, _c;
636
+ var _a3;
631
637
  const dappId = getDappId(options.dapp);
632
638
  const platform = getPlatformType();
633
639
  const anonId = yield storage.getAnonId();
634
- const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
635
640
  return {
636
- mmconnect_versions: (_c = options.versions) != null ? _c : {},
641
+ mmconnect_versions: (_a3 = options.versions) != null ? _a3 : {},
637
642
  dapp_id: dappId,
638
643
  platform,
639
- integration_type: integrationType,
640
644
  anon_id: anonId
641
645
  };
642
646
  });
643
647
  }
644
648
  function getWalletActionAnalyticsProperties(options, storage, invokeOptions, transportType) {
645
649
  return __async(this, null, function* () {
646
- var _a3, _b, _c;
650
+ var _a3;
647
651
  const dappId = getDappId(options.dapp);
648
652
  const anonId = yield storage.getAnonId();
649
- const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown";
650
653
  return {
651
- mmconnect_versions: (_c = options.versions) != null ? _c : {},
654
+ mmconnect_versions: (_a3 = options.versions) != null ? _a3 : {},
652
655
  dapp_id: dappId,
653
656
  method: invokeOptions.request.method,
654
- integration_type: integrationType,
655
657
  caip_chain_id: invokeOptions.scope,
656
658
  anon_id: anonId,
657
659
  transport_type: transportType
@@ -2670,21 +2672,23 @@ var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
2670
2672
  var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn2, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn, getCaipSession_fn, openConnectDeeplinkIfNeeded_fn;
2671
2673
  var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
2672
2674
  constructor(options) {
2673
- var _a3, _b, _c, _d, _e, _f, _g;
2675
+ var _a3, _b, _c, _d, _e, _f;
2674
2676
  const withDappMetadata = setupDappMetadata(options);
2675
- const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "direct";
2677
+ const integrationType = ((_a3 = options.analytics) == null ? void 0 : _a3.integrationType) || "direct";
2676
2678
  const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
2677
2679
  ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
2678
- preferExtension: (_c = withDappMetadata.ui.preferExtension) != null ? _c : true,
2679
- showInstallModal: (_d = withDappMetadata.ui.showInstallModal) != null ? _d : false,
2680
- headless: (_e = withDappMetadata.ui.headless) != null ? _e : false
2680
+ preferExtension: (_b = withDappMetadata.ui.preferExtension) != null ? _b : true,
2681
+ showInstallModal: (_c = withDappMetadata.ui.showInstallModal) != null ? _c : false,
2682
+ headless: (_d = withDappMetadata.ui.headless) != null ? _d : false
2681
2683
  }),
2682
- analytics: __spreadProps(__spreadValues({}, (_f = options.analytics) != null ? _f : {}), {
2684
+ analytics: __spreadProps(__spreadValues({}, (_e = options.analytics) != null ? _e : {}), {
2683
2685
  integrationType
2684
2686
  }),
2685
2687
  versions: __spreadValues({
2686
- "connect-multichain": "0.9.0"
2687
- }, (_g = options.versions) != null ? _g : {})
2688
+ // typeof guard needed: Metro (React Native) bundles TS source directly,
2689
+ // bypassing the tsup build that substitutes __PACKAGE_VERSION__.
2690
+ "connect-multichain": false ? "unknown" : "0.10.0"
2691
+ }, (_f = options.versions) != null ? _f : {})
2688
2692
  });
2689
2693
  super(allOptions);
2690
2694
  __privateAdd(this, _MetaMaskConnectMultichain_instances);
@@ -2746,7 +2750,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2746
2750
  // subsequent calls to `createMultichainClient` to have a different `dapp` value.
2747
2751
  static create(options) {
2748
2752
  return __async(this, null, function* () {
2749
- var _a3;
2753
+ var _a3, _b;
2750
2754
  const globalObject = getGlobalObject();
2751
2755
  const existing = globalObject[SINGLETON_KEY];
2752
2756
  if (existing) {
@@ -2756,6 +2760,11 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2756
2760
  "mmconnect_versions",
2757
2761
  (_a3 = instance.options.versions) != null ? _a3 : {}
2758
2762
  );
2763
+ if ((_b = options.analytics) == null ? void 0 : _b.integrationType) {
2764
+ analytics2.setGlobalProperty("integration_types", [
2765
+ options.analytics.integrationType
2766
+ ]);
2767
+ }
2759
2768
  if (options.debug) {
2760
2769
  enableDebug("metamask-sdk:*");
2761
2770
  }
@@ -2976,7 +2985,9 @@ setupAnalytics_fn = function() {
2976
2985
  analytics2.setGlobalProperty("dapp_id", dappId);
2977
2986
  analytics2.setGlobalProperty("anon_id", anonId);
2978
2987
  analytics2.setGlobalProperty("platform", platform);
2979
- analytics2.setGlobalProperty("integration_type", integrationType);
2988
+ if (integrationType) {
2989
+ analytics2.setGlobalProperty("integration_types", [integrationType]);
2990
+ }
2980
2991
  analytics2.enable();
2981
2992
  });
2982
2993
  };