@meshconnect/web-link-sdk 3.2.15 → 3.2.16

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 (101) hide show
  1. package/Link.d.ts +2 -0
  2. package/Link.js +530 -0
  3. package/index.d.ts +3 -0
  4. package/index.js +3 -0
  5. package/package.json +8 -20
  6. package/utils/connectors/evm/chainConfigs.d.ts +2 -0
  7. package/utils/connectors/evm/chainConfigs.js +115 -0
  8. package/utils/connectors/evm/chainSwitching.d.ts +15 -0
  9. package/utils/connectors/evm/chainSwitching.js +242 -0
  10. package/utils/connectors/evm/index.d.ts +8 -0
  11. package/utils/connectors/evm/index.js +8 -0
  12. package/utils/connectors/evm/provider.d.ts +6 -0
  13. package/utils/connectors/evm/provider.js +13 -0
  14. package/utils/connectors/evm/signing.d.ts +1 -0
  15. package/utils/connectors/evm/signing.js +78 -0
  16. package/utils/connectors/evm/transactions.d.ts +28 -0
  17. package/utils/connectors/evm/transactions.js +381 -0
  18. package/utils/connectors/evm/types.d.ts +57 -0
  19. package/utils/connectors/evm/types.js +1 -0
  20. package/utils/connectors/evm/walletConnection.d.ts +20 -0
  21. package/utils/connectors/evm/walletConnection.js +160 -0
  22. package/utils/connectors/evm/walletDiscovery.d.ts +10 -0
  23. package/utils/connectors/evm/walletDiscovery.js +55 -0
  24. package/utils/connectors/solana/connection.d.ts +4 -0
  25. package/utils/connectors/solana/connection.js +108 -0
  26. package/utils/connectors/solana/index.d.ts +5 -0
  27. package/utils/connectors/solana/index.js +5 -0
  28. package/utils/connectors/solana/providerDiscovery.d.ts +3 -0
  29. package/utils/connectors/solana/providerDiscovery.js +127 -0
  30. package/utils/connectors/solana/signing.d.ts +1 -0
  31. package/utils/connectors/solana/signing.js +59 -0
  32. package/utils/connectors/solana/transaction.d.ts +17 -0
  33. package/utils/connectors/solana/transaction.js +362 -0
  34. package/utils/connectors/solana/types.d.ts +71 -0
  35. package/utils/connectors/solana/types.js +8 -0
  36. package/utils/event-types.d.ts +233 -0
  37. package/{src/utils/event-types.test.ts → utils/event-types.js} +5 -15
  38. package/utils/popup.d.ts +3 -0
  39. package/utils/popup.js +36 -0
  40. package/utils/sdk-specs.d.ts +5 -0
  41. package/utils/sdk-specs.js +6 -0
  42. package/utils/style.d.ts +3 -0
  43. package/utils/style.js +13 -0
  44. package/utils/types.d.ts +234 -0
  45. package/utils/types.js +1 -0
  46. package/utils/version.d.ts +1 -0
  47. package/utils/version.js +1 -0
  48. package/utils/wallet/EVMWalletStrategy.d.ts +31 -0
  49. package/utils/wallet/EVMWalletStrategy.js +265 -0
  50. package/utils/wallet/SolanaWalletStrategy.d.ts +33 -0
  51. package/utils/wallet/SolanaWalletStrategy.js +300 -0
  52. package/utils/wallet/WalletStrategy.d.ts +61 -0
  53. package/utils/wallet/WalletStrategy.js +25 -0
  54. package/utils/wallet/WalletStrategyFactory.d.ts +15 -0
  55. package/utils/wallet/WalletStrategyFactory.js +31 -0
  56. package/utils/wallet/index.d.ts +4 -0
  57. package/utils/wallet/index.js +4 -0
  58. package/utils/wallet-browser-event-types.d.ts +116 -0
  59. package/utils/wallet-browser-event-types.js +17 -0
  60. package/jest.setup.ts +0 -4
  61. package/src/Link.test.ts +0 -434
  62. package/src/Link.ts +0 -491
  63. package/src/index.ts +0 -3
  64. package/src/utils/__snapshots__/popup.test.ts.snap +0 -89
  65. package/src/utils/connectors/evm/chainConfigs.ts +0 -120
  66. package/src/utils/connectors/evm/chainSwitching.ts +0 -165
  67. package/src/utils/connectors/evm/index.ts +0 -8
  68. package/src/utils/connectors/evm/provider.ts +0 -22
  69. package/src/utils/connectors/evm/signing.ts +0 -39
  70. package/src/utils/connectors/evm/transactions.ts +0 -356
  71. package/src/utils/connectors/evm/types.ts +0 -63
  72. package/src/utils/connectors/evm/walletConnection.ts +0 -140
  73. package/src/utils/connectors/evm/walletDiscovery.ts +0 -67
  74. package/src/utils/connectors/solana/connection.ts +0 -69
  75. package/src/utils/connectors/solana/index.ts +0 -5
  76. package/src/utils/connectors/solana/providerDiscovery.ts +0 -153
  77. package/src/utils/connectors/solana/signing.ts +0 -18
  78. package/src/utils/connectors/solana/transaction.ts +0 -382
  79. package/src/utils/connectors/solana/types.ts +0 -66
  80. package/src/utils/event-types.ts +0 -350
  81. package/src/utils/popup.test.ts +0 -50
  82. package/src/utils/popup.ts +0 -123
  83. package/src/utils/sdk-specs.test.ts +0 -18
  84. package/src/utils/sdk-specs.ts +0 -7
  85. package/src/utils/style.test.ts +0 -33
  86. package/src/utils/style.ts +0 -15
  87. package/src/utils/types.ts +0 -270
  88. package/src/utils/version.ts +0 -1
  89. package/src/utils/wallet/EVMWalletStrategy.ts +0 -176
  90. package/src/utils/wallet/SolanaWalletStrategy.ts +0 -207
  91. package/src/utils/wallet/WalletStrategy.ts +0 -99
  92. package/src/utils/wallet/WalletStrategyFactory.ts +0 -46
  93. package/src/utils/wallet/__tests__/EVMWalletStrategy.test.ts +0 -233
  94. package/src/utils/wallet/__tests__/SolanaWalletStrategy.test.ts +0 -253
  95. package/src/utils/wallet/__tests__/WalletStrategy.test.ts +0 -77
  96. package/src/utils/wallet/__tests__/WalletStrategyFactory.test.ts +0 -65
  97. package/src/utils/wallet/index.ts +0 -4
  98. package/src/utils/wallet-browser-event-types.ts +0 -190
  99. package/tools/copy.js +0 -26
  100. package/tools/update-version.js +0 -10
  101. package/tsconfig.json +0 -14
package/src/Link.test.ts DELETED
@@ -1,434 +0,0 @@
1
- import { createLink } from './Link'
2
- import { DoneEvent, LinkEventType } from './utils/event-types'
3
- import {
4
- AccessTokenPayload,
5
- DelayedAuthPayload,
6
- EventType,
7
- LinkPayload,
8
- IntegrationAccessToken,
9
- TransferFinishedPayload
10
- } from './utils/types'
11
-
12
- type EventPayload = {
13
- type: EventType
14
- payload?: AccessTokenPayload | DelayedAuthPayload | TransferFinishedPayload
15
- message?: string
16
- link?: string
17
- }
18
-
19
- const BASE64_ENCODED_URL = Buffer.from('http://localhost/1').toString('base64')
20
-
21
- describe('createLink tests', () => {
22
- window.open = jest.fn()
23
-
24
- beforeEach(() => {
25
- document.getElementsByTagName('html')[0].innerHTML = ''
26
- })
27
-
28
- test('createLink when invalid link provided should not open popup', () => {
29
- const exitFunction = jest.fn<void, [string | undefined]>()
30
- const frontConnection = createLink({
31
- clientId: 'test',
32
- onIntegrationConnected: jest.fn(),
33
- onExit: exitFunction
34
- })
35
-
36
- frontConnection.openLink('')
37
-
38
- expect(exitFunction).toHaveBeenCalledWith('Invalid link token!')
39
- const iframeElement = document.getElementById('mesh-link-popup__iframe')
40
- expect(iframeElement).toBeFalsy()
41
- })
42
-
43
- test('createLink when valid link provided should open popup', () => {
44
- const frontConnection = createLink({
45
- clientId: 'test',
46
- onIntegrationConnected: jest.fn(),
47
- language: 'en'
48
- })
49
-
50
- frontConnection.openLink(BASE64_ENCODED_URL)
51
- const iframeElement = document.getElementById('mesh-link-popup__iframe')
52
- expect(iframeElement).toBeTruthy()
53
- expect(iframeElement?.attributes.getNamedItem('src')?.nodeValue).toBe(
54
- 'http://localhost/1?lng=en'
55
- )
56
- })
57
-
58
- test('createLink system language is requested then should open popup with correct language', () => {
59
- jest.spyOn(navigator, 'language', 'get').mockReturnValue('es-US')
60
-
61
- const frontConnection = createLink({
62
- clientId: 'test',
63
- onIntegrationConnected: jest.fn(),
64
- language: 'system'
65
- })
66
-
67
- frontConnection.openLink(BASE64_ENCODED_URL)
68
- const iframeElement = document.getElementById('mesh-link-popup__iframe')
69
- expect(iframeElement).toBeTruthy()
70
- expect(iframeElement?.attributes.getNamedItem('src')?.nodeValue).toBe(
71
- 'http://localhost/1?lng=es-US'
72
- )
73
- })
74
-
75
- test('createLink when valid link provided should open popup with custom iframe id', () => {
76
- const customIframeId = 'custom-iframe-id'
77
- const customIframeElement = document.createElement('iframe')
78
- customIframeElement.id = customIframeId
79
- document.body.appendChild(customIframeElement)
80
-
81
- const frontConnection = createLink({
82
- clientId: 'test',
83
- onIntegrationConnected: jest.fn(),
84
- language: 'en'
85
- })
86
-
87
- frontConnection.openLink(BASE64_ENCODED_URL, customIframeId)
88
- const iframeElement = document.getElementById('mesh-link-popup__iframe')
89
- expect(iframeElement).toBeFalsy()
90
-
91
- expect(customIframeElement.attributes.getNamedItem('src')?.nodeValue).toBe(
92
- 'http://localhost/1?lng=en'
93
- )
94
- })
95
-
96
- test('createLink closePopup should close popup', () => {
97
- const exitFunction = jest.fn<void, [string | undefined]>()
98
- const frontConnection = createLink({
99
- clientId: 'test',
100
- onIntegrationConnected: jest.fn(),
101
- onExit: exitFunction
102
- })
103
-
104
- frontConnection.openLink(BASE64_ENCODED_URL)
105
- frontConnection.closeLink()
106
-
107
- const iframeElement = document.getElementById('mesh-link-popup__iframe')
108
- expect(iframeElement).toBeFalsy()
109
-
110
- expect(exitFunction).toHaveBeenCalled()
111
- })
112
-
113
- test.each(['close', 'done'] as const)(
114
- 'createLink "%s" event should close popup',
115
- eventName => {
116
- const exitFunction = jest.fn<void, [string | undefined]>()
117
- const frontConnection = createLink({
118
- clientId: 'test',
119
- onIntegrationConnected: jest.fn(),
120
- onExit: exitFunction
121
- })
122
-
123
- const payload: DoneEvent['payload'] = {
124
- page: 'some page',
125
- errorMessage: 'some msg'
126
- }
127
- frontConnection.openLink(BASE64_ENCODED_URL)
128
- window.dispatchEvent(
129
- new MessageEvent<LinkEventType>('message', {
130
- data: {
131
- type: eventName,
132
- payload: payload
133
- },
134
- origin: 'http://localhost'
135
- })
136
- )
137
-
138
- const iframeElement = document.getElementById('mesh-link-popup__iframe')
139
- expect(iframeElement).toBeFalsy()
140
-
141
- expect(exitFunction).toHaveBeenCalledWith('some msg', payload)
142
- }
143
- )
144
-
145
- test('createLink "brokerageAccountAccessToken" event should send tokens', () => {
146
- const onEventHandler = jest.fn<void, [LinkEventType]>()
147
- const onBrokerConnectedHandler = jest.fn<void, [LinkPayload]>()
148
- const frontConnection = createLink({
149
- clientId: 'test',
150
- onIntegrationConnected: onBrokerConnectedHandler,
151
- onEvent: onEventHandler
152
- })
153
-
154
- frontConnection.openLink(BASE64_ENCODED_URL)
155
-
156
- const payload: AccessTokenPayload = {
157
- accountTokens: [],
158
- brokerBrandInfo: { brokerLogo: '' },
159
- brokerType: 'robinhood',
160
- brokerName: 'R'
161
- }
162
- window.dispatchEvent(
163
- new MessageEvent<EventPayload>('message', {
164
- data: {
165
- type: 'brokerageAccountAccessToken',
166
- payload: payload
167
- },
168
- origin: 'http://localhost'
169
- })
170
- )
171
-
172
- expect(onEventHandler).toHaveBeenCalledWith({
173
- type: 'integrationConnected',
174
- payload: { accessToken: payload }
175
- })
176
- expect(onBrokerConnectedHandler).toHaveBeenCalledWith({
177
- accessToken: payload
178
- })
179
- })
180
-
181
- test('createLink "delayedAuthentication" event should send dalayed tokens', () => {
182
- const onEventHandler = jest.fn<void, [LinkEventType]>()
183
- const onBrokerConnectedHandler = jest.fn<void, [LinkPayload]>()
184
- const frontConnection = createLink({
185
- clientId: 'test',
186
- onIntegrationConnected: onBrokerConnectedHandler,
187
- onEvent: onEventHandler
188
- })
189
-
190
- frontConnection.openLink(BASE64_ENCODED_URL)
191
-
192
- const payload: DelayedAuthPayload = {
193
- brokerBrandInfo: { brokerLogo: '' },
194
- brokerType: 'robinhood',
195
- brokerName: 'R',
196
- refreshToken: 'rt'
197
- }
198
- window.dispatchEvent(
199
- new MessageEvent<EventPayload>('message', {
200
- data: {
201
- type: 'delayedAuthentication',
202
- payload: payload
203
- },
204
- origin: 'http://localhost'
205
- })
206
- )
207
-
208
- expect(onEventHandler).toHaveBeenCalledWith({
209
- type: 'integrationConnected',
210
- payload: { delayedAuth: payload }
211
- })
212
- expect(onBrokerConnectedHandler).toHaveBeenCalledWith({
213
- delayedAuth: payload
214
- })
215
- })
216
-
217
- test('createLink "transferFinished" event should send transfer payload', () => {
218
- const onEventHandler = jest.fn<void, [LinkEventType]>()
219
- const onTransferFinishedHandler = jest.fn<void, [TransferFinishedPayload]>()
220
- const frontConnection = createLink({
221
- clientId: 'test',
222
- onIntegrationConnected: jest.fn(),
223
- onEvent: onEventHandler,
224
- onTransferFinished: onTransferFinishedHandler
225
- })
226
-
227
- frontConnection.openLink(BASE64_ENCODED_URL)
228
-
229
- const payload: TransferFinishedPayload = {
230
- status: 'success',
231
- txId: 'tid',
232
- fromAddress: 'fa',
233
- toAddress: 'ta',
234
- symbol: 'BTC',
235
- amount: 0.001,
236
- networkId: 'nid',
237
- amountInFiat: 9.77,
238
- totalAmountInFiat: 10.02,
239
- networkName: 'Bitcoin',
240
- txHash: 'txHash',
241
- transferId: 'trid'
242
- }
243
- window.dispatchEvent(
244
- new MessageEvent<EventPayload>('message', {
245
- data: {
246
- type: 'transferFinished',
247
- payload: payload
248
- },
249
- origin: 'http://localhost'
250
- })
251
- )
252
-
253
- expect(onEventHandler).toHaveBeenCalledWith({
254
- type: 'transferCompleted',
255
- payload: payload
256
- })
257
- expect(onTransferFinishedHandler).toHaveBeenCalledWith(payload)
258
- })
259
-
260
- test('createLink "loaded" event should trigger the passing for tokens', () => {
261
- const tokens: IntegrationAccessToken[] = [
262
- {
263
- accessToken: 'at',
264
- accountId: 'aid',
265
- accountName: 'an',
266
- brokerType: 'acorns',
267
- brokerName: 'A'
268
- }
269
- ]
270
- const destinationTokens: IntegrationAccessToken[] = [
271
- {
272
- accessToken: 'ttoken',
273
- accountId: 'tid',
274
- accountName: 'tname',
275
- brokerType: 'acorns',
276
- brokerName: 'tbrokername'
277
- }
278
- ]
279
- const frontConnection = createLink({
280
- clientId: 'test',
281
- onIntegrationConnected: jest.fn(),
282
- accessTokens: tokens,
283
- transferDestinationTokens: destinationTokens
284
- })
285
-
286
- frontConnection.openLink(BASE64_ENCODED_URL)
287
-
288
- const iframeElement = document.getElementById(
289
- 'mesh-link-popup__iframe'
290
- ) as HTMLIFrameElement | null
291
- expect(iframeElement?.contentWindow).toBeTruthy()
292
-
293
- const postMessageSpy = jest.spyOn(
294
- iframeElement?.contentWindow as Window,
295
- 'postMessage'
296
- )
297
-
298
- window.dispatchEvent(
299
- new MessageEvent<EventPayload>('message', {
300
- data: {
301
- type: 'loaded'
302
- },
303
- origin: 'http://localhost'
304
- })
305
- )
306
-
307
- const packageJSONContent = JSON.parse(
308
- // eslint-disable-next-line @typescript-eslint/no-var-requires
309
- require('fs').readFileSync('package.json', 'utf8')
310
- )
311
- expect(postMessageSpy).toHaveBeenCalledWith(
312
- {
313
- type: 'meshSDKSpecs',
314
- payload: {
315
- platform: 'web',
316
- version: packageJSONContent.version,
317
- origin: 'http://localhost'
318
- }
319
- },
320
- 'http://localhost'
321
- )
322
-
323
- expect(postMessageSpy).toHaveBeenCalledWith(
324
- { type: 'frontAccessTokens', payload: tokens },
325
- 'http://localhost'
326
- )
327
-
328
- expect(postMessageSpy).toHaveBeenCalledWith(
329
- { type: 'frontTransferDestinationTokens', payload: destinationTokens },
330
- 'http://localhost'
331
- )
332
- })
333
-
334
- test('createLink "integrationConnected" event should send event', () => {
335
- const onEventHandler = jest.fn<void, [LinkEventType]>()
336
- const frontConnection = createLink({
337
- clientId: 'test',
338
- onIntegrationConnected: jest.fn(),
339
- onEvent: onEventHandler
340
- })
341
-
342
- frontConnection.openLink(BASE64_ENCODED_URL)
343
-
344
- window.dispatchEvent(
345
- new MessageEvent('message', {
346
- data: {
347
- type: 'integrationConnected'
348
- },
349
- origin: 'http://localhost'
350
- })
351
- )
352
-
353
- expect(onEventHandler).toHaveBeenCalled()
354
- })
355
-
356
- test('createLink unknown event should not send any events', () => {
357
- const onEventHandler = jest.fn<void, [LinkEventType]>()
358
- const frontConnection = createLink({
359
- clientId: 'test',
360
- onIntegrationConnected: jest.fn(),
361
- onEvent: onEventHandler
362
- })
363
-
364
- frontConnection.openLink(BASE64_ENCODED_URL)
365
-
366
- window.dispatchEvent(
367
- new MessageEvent('message', {
368
- data: {
369
- type: 'unknown'
370
- },
371
- origin: 'http://localhost'
372
- })
373
- )
374
-
375
- expect(onEventHandler).not.toHaveBeenCalled()
376
- })
377
-
378
- test('createLink "brokerageAccountAccessToken" event should send tokens - used with openLink function', () => {
379
- const onEventHandler = jest.fn<void, [LinkEventType]>()
380
- const onBrokerConnectedHandler = jest.fn<void, [LinkPayload]>()
381
- const frontConnection = createLink({
382
- clientId: 'test',
383
- onIntegrationConnected: onBrokerConnectedHandler,
384
- onEvent: onEventHandler
385
- })
386
-
387
- frontConnection.openLink(
388
- Buffer.from('http://localhost/1').toString('base64')
389
- )
390
-
391
- const payload: AccessTokenPayload = {
392
- accountTokens: [],
393
- brokerBrandInfo: { brokerLogo: '' },
394
- brokerType: 'robinhood',
395
- brokerName: 'R'
396
- }
397
- window.dispatchEvent(
398
- new MessageEvent<EventPayload>('message', {
399
- data: {
400
- type: 'brokerageAccountAccessToken',
401
- payload: payload
402
- },
403
- origin: 'http://localhost'
404
- })
405
- )
406
-
407
- expect(onEventHandler).toHaveBeenCalledWith({
408
- type: 'integrationConnected',
409
- payload: { accessToken: payload }
410
- })
411
- expect(onBrokerConnectedHandler).toHaveBeenCalledWith({
412
- accessToken: payload
413
- })
414
- })
415
-
416
- test('createLink closeLink should close popup', () => {
417
- const exitFunction = jest.fn<void, [string | undefined]>()
418
- const frontConnection = createLink({
419
- clientId: 'test',
420
- onIntegrationConnected: jest.fn(),
421
- onExit: exitFunction
422
- })
423
-
424
- frontConnection.openLink(
425
- Buffer.from('http://localhost/1').toString('base64')
426
- )
427
- frontConnection.closeLink()
428
-
429
- const iframeElement = document.getElementById('mesh-link-popup__iframe')
430
- expect(iframeElement).toBeFalsy()
431
-
432
- expect(exitFunction).toHaveBeenCalled()
433
- })
434
- })