@stakekit/widget 0.0.292 → 0.0.294
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.
- package/dist/bundle/{DateTime-BBRIKkPv.js → DateTime-CMMZj2i-.js} +54 -54
- package/dist/bundle/{assets-vw12jo1v.js → assets-Bc9gJ-IT.js} +6 -6
- package/dist/bundle/{cardano-connector-DCWdS4Lt.js → cardano-connector-4FH7sm5s.js} +2 -2
- package/dist/bundle/{configured-chains-Bc6_pgMo.js → configured-chains-DF5IpaPp.js} +1 -1
- package/dist/bundle/{cosmos-connector-meta-Br67nymZ.js → cosmos-connector-meta-BKRBGzAs.js} +1 -1
- package/dist/bundle/index.bundle.css +1 -1
- package/dist/bundle/index.bundle.js +15768 -15242
- package/dist/bundle/{ledger-connector-wZ-AWITi.js → ledger-connector-Em3Ex6Ns.js} +5 -5
- package/dist/bundle/{network-D8-Flo2u.js → network-D2ajkWp0.js} +1 -1
- package/dist/bundle/{reward-rate-chart-B41r4AU4.js → reward-rate-chart-6q6gJawR.js} +4 -4
- package/dist/bundle/{solana-connector-CXe_nU4I.js → solana-connector-DHrdMGZC.js} +3 -3
- package/dist/bundle/{stellar-connector-Cdl9Hnba.js → stellar-connector-DkR_jg41.js} +2 -2
- package/dist/bundle/{styles.css-BJ7-ORZP.js → styles.css-DQG3ba8V.js} +6 -6
- package/dist/bundle/{substrate-connector-DFeFqV_q.js → substrate-connector-CzewVoQ6.js} +1 -1
- package/dist/bundle/{ton-connector-CWmOukzn.js → ton-connector-CcahoFeW.js} +3 -3
- package/dist/bundle/{transaction-BwhgjU0e.js → transaction-BGiGADTK.js} +1 -1
- package/dist/bundle/{transaction-CUoDE6CU.js → transaction-BvpQWKqm.js} +1 -1
- package/dist/bundle/{transaction-B8S7Vgaq.js → transaction-CD_QhA6u.js} +2 -2
- package/dist/bundle/{transaction-DxrR2BHC.js → transaction-CiEShf7a.js} +1 -1
- package/dist/bundle/{tron-connector--M_0_Iy7.js → tron-connector-Dy_36o_J.js} +3 -3
- package/dist/bundle/{utils-CoW929-6.js → utils-BMTuLksW.js} +1 -1
- package/dist/bundle/{wallet-manager-C3rmOq7t.js → wallet-manager-BLaLHs2U.js} +11 -11
- package/dist/package/{DateTime-DJZXpaqx.js → DateTime-CGVpQQm9.js} +24 -2
- package/dist/package/{assets-BuIo5TOF.js → assets-CEn8BPdT.js} +1 -1
- package/dist/package/{cardano-connector-DIZuipB7.js → cardano-connector-BDWTBXaS.js} +2 -2
- package/dist/package/{configured-chains-B6PD9hvx.js → configured-chains-CRuy8tse.js} +1 -1
- package/dist/package/{cosmos-connector-meta-CgvZWkLV.js → cosmos-connector-meta-B-ke1Dvw.js} +1 -1
- package/dist/package/index.package.css +162 -162
- package/dist/package/index.package.js +4126 -3050
- package/dist/package/{ledger-connector-B3kEcKjM.js → ledger-connector-BQDRUjOJ.js} +5 -5
- package/dist/package/{network-B4Qs3uRl.js → network-K03Uj00V.js} +1 -1
- package/dist/package/{reward-rate-chart-B42ZCby7.js → reward-rate-chart-DBx39GdL.js} +2 -2
- package/dist/package/{solana-connector-VG2pC1EJ.js → solana-connector-fL70NOkD.js} +3 -3
- package/dist/package/{stellar-connector-DO9tJUOg.js → stellar-connector-C_33sqO5.js} +2 -2
- package/dist/package/{styles.css-DwJjrmLr.js → styles.css-BOghDWGq.js} +1 -1
- package/dist/package/{substrate-connector-P80MVt5T.js → substrate-connector-Cr7LEt2o.js} +1 -1
- package/dist/package/{ton-connector-3rqiqNZO.js → ton-connector-81-rUhzX.js} +3 -3
- package/dist/package/{transaction-DTbU7sxm.js → transaction-BHIZ9rKF.js} +1 -1
- package/dist/package/{transaction-CuMGfUeE.js → transaction-C5e_gCK6.js} +1 -1
- package/dist/package/{transaction-V39s0qKU.js → transaction-DMMfLvk1.js} +2 -2
- package/dist/package/{transaction-Do_oUKxl.js → transaction-DgdU5pHH.js} +1 -1
- package/dist/package/{tron-connector-CKUZFHDh.js → tron-connector-Cuez3U16.js} +3 -3
- package/dist/package/{wallet-manager-CioQJQ5H.js → wallet-manager-DWFwmdLb.js} +2 -2
- package/dist/types/domain/earn/contract.d.ts +1 -0
- package/dist/types/generated/yield-provider-ids.d.ts +86 -0
- package/dist/types/index.bundle.d.ts +2 -2
- package/dist/types/index.package.d.ts +2 -2
- package/dist/types/public-api/types.d.ts +21 -3
- package/dist/website/assets/AlertController-Dd3t1FDe.js +1 -0
- package/dist/website/assets/{CaipNetworkUtil-CIgzbD6k.js → CaipNetworkUtil-CyIDQhS0.js} +1 -1
- package/dist/website/assets/DateTime-ByC3zr_K.js +1 -0
- package/dist/website/assets/{HelpersUtil-BokHy7la.js → HelpersUtil-Bpil3MMz.js} +1 -1
- package/dist/website/assets/ModalController-BhWRBcfd.js +5 -0
- package/dist/website/assets/{albedo.module-Dn9vkw3f.js → albedo.module-DkOe0Unb.js} +1 -1
- package/dist/website/assets/assets-DXO6qW6R.js +2 -0
- package/dist/website/assets/{axios-Dl6BaS8Y.js → axios-rFNl7rAx.js} +2 -2
- package/dist/website/assets/{base-signer-b1ff2VPI-DF_m1Hx-.js → base-signer-b1ff2VPI-DEykpag5.js} +1 -1
- package/dist/website/assets/{basic-Bt_YnOIC.js → basic-By5_muQ4.js} +1 -1
- package/dist/website/assets/bignumber-FohbSRh0.js +1 -0
- package/dist/website/assets/blakejs-x6iaQxOd.js +3 -0
- package/dist/website/assets/bn-Ck4DeaX2.js +1 -0
- package/dist/website/assets/{browser-ponyfill-_v4sZCld.js → browser-ponyfill-lHyeX8iJ.js} +1 -1
- package/dist/website/assets/{bs58-CiFyCgrv.js → bs58-gzsgdke5.js} +1 -1
- package/dist/website/assets/{build-DM4Sawu1.js → build-ClRxYQRR.js} +1 -1
- package/dist/website/assets/{build-Butjcagw.js → build-TBrHU398.js} +1 -1
- package/dist/website/assets/{build-B5AnTSOq.js → build-Tl3I8dhV.js} +1 -1
- package/dist/website/assets/{cardano-connector-BC5bF4Y2.js → cardano-connector-8El4Ztf_.js} +9 -9
- package/dist/website/assets/{configured-chains-Bp7rWkOZ.js → configured-chains-DQ_M8-li.js} +1 -1
- package/dist/website/assets/core-BiDQVY37.js +2 -0
- package/dist/website/assets/{cosmos-connector-meta-CZFaunIB.js → cosmos-connector-meta-DRTieEt0.js} +1 -1
- package/dist/website/assets/dist-BVuLBvyS.js +7 -0
- package/dist/website/assets/{dist-BKdXTi2f.js → dist-Bo7ZdXT8.js} +3 -3
- package/dist/website/assets/{dist-7PipG_eL.js → dist-DlLKQSrv.js} +3 -3
- package/dist/website/assets/dist-ZKTSEBXW.js +1 -0
- package/dist/website/assets/{elliptic-j9CClrcl.js → elliptic-BdE4gFqn.js} +2 -2
- package/dist/website/assets/{esm-DVfwo40P.js → esm-BjyHrLEJ.js} +1 -1
- package/dist/website/assets/events-CMzhc0tf.js +1 -0
- package/dist/website/assets/{extrinsic-encoding-B3zynq2U.js → extrinsic-encoding-BIj1XBpl.js} +1 -1
- package/dist/website/assets/{features-LE43LGiF.js → features-Cy1CFK9a.js} +1 -1
- package/dist/website/assets/{fhevm-relayer-DXLb4mIw-bVmGMiQn.js → fhevm-relayer-DXLb4mIw-Bbrz0cha.js} +5 -3
- package/dist/website/assets/freighter.module-DsmrpiWT.js +1 -0
- package/dist/website/assets/index-7hHJ2eI5.js +558 -0
- package/dist/website/assets/index-zFAIWvcU.css +1 -0
- package/dist/website/assets/{index.es-D6B6PG3M.js → index.es-BGzDKZr_.js} +1 -1
- package/dist/website/assets/index.es-BHs2-Pa6.js +1 -0
- package/dist/website/assets/{index.es-wqX1ruQA.js → index.es-Bpga9r91.js} +5 -5
- package/dist/website/assets/{kms_lib-mPebVu09.js → kms_lib-BgnOy0xU.js} +1 -1
- package/dist/website/assets/{kms_lib-Bh_Z1nH6.js → kms_lib-w0jRi8cP.js} +1 -1
- package/dist/website/assets/{ledger-connector-BOOoTKx_.js → ledger-connector-CNNjVgC1.js} +3 -3
- package/dist/website/assets/{lib-es-5LFNYQ9J.js → lib-es-DmH9FYVZ.js} +1 -1
- package/dist/website/assets/lobstr.module-BUAItZUt.js +1 -0
- package/dist/website/assets/{nacl-fast-BI97gFtf.js → nacl-fast-B5R4wpqG.js} +1 -1
- package/dist/website/assets/{nacl-util-DCWJejqG.js → nacl-util-6167mj42.js} +1 -1
- package/dist/website/assets/{network-CEcIzsgc.js → network-BVzpe0Ii.js} +1 -1
- package/dist/website/assets/{polkadot-ledger-transaction-DaDP252u.js → polkadot-ledger-transaction-Dp6EFfyV.js} +1 -1
- package/dist/website/assets/registry-BgQw-qJW.js +1 -0
- package/dist/website/assets/{reward-rate-chart-COP_M115.js → reward-rate-chart-CO_yI4og.js} +4 -4
- package/dist/website/assets/{safe-buffer-Dz6e-rwu.js → safe-buffer-BUgQmBOp.js} +1 -1
- package/dist/website/assets/{safe-connector-DG2cXEO5.js → safe-connector-BObu9WgG.js} +2 -2
- package/dist/website/assets/{solana-connector-DSpWnxwA.js → solana-connector-CVuV_EKp.js} +1 -1
- package/dist/website/assets/{src-Zq1Jw-Sn.js → src-DbdC_Alu.js} +1 -1
- package/dist/website/assets/{src-hSPfFTzN.js → src-Dl7INWvU.js} +1 -1
- package/dist/website/assets/state-D5Nw1L4F.js +1 -0
- package/dist/website/assets/{stellar-connector-BAbbdkSK.js → stellar-connector-Ba7Jcrbg.js} +1 -1
- package/dist/website/assets/styles.css-NtRiu07M.js +1 -0
- package/dist/website/assets/substrate-connector-hQ3vc47X.js +2 -0
- package/dist/website/assets/tfhe-BACovsAk.js +1 -0
- package/dist/website/assets/{tfhe-DuWT_ao1.js → tfhe-BSAXrnM6.js} +1 -1
- package/dist/website/assets/ton-connector-CU1xiP2u.js +2264 -0
- package/dist/website/assets/tracking-variants-CtfEiKNR.js +93 -0
- package/dist/website/assets/{transaction-BH4ssPh3.js → transaction-B5hUD0AE.js} +1 -1
- package/dist/website/assets/{transaction-BVuftLt1.js → transaction-BWEzzOww.js} +1 -1
- package/dist/website/assets/transaction-BmFUkzQv.js +2 -0
- package/dist/website/assets/{transaction-1KdJeqcp.js → transaction-C_iyacpP.js} +1 -1
- package/dist/website/assets/{tron-connector-CJURHEQe.js → tron-connector-gXtlAAuG.js} +7 -7
- package/dist/website/assets/{tx-Bkou_ALe.js → tx-Cosvp39i.js} +1 -1
- package/dist/website/assets/{utils-CH0e59XB.js → utils-meUBO1X1.js} +1 -1
- package/dist/website/assets/{viem-BQ_7aeKB.js → viem-8-EtcU49.js} +1 -1
- package/dist/website/assets/{w3m-modal-BLY--NNS.js → w3m-modal-HS9RLkN8.js} +2 -2
- package/dist/website/assets/wallet-manager-BQrZx180.js +5 -0
- package/dist/website/assets/{web-4qAQ-Ymk.js → web-azgm2Psf.js} +1 -1
- package/dist/website/assets/{wui-list-item-1gzb5UQJ.js → wui-list-item-CfZ1WQql.js} +1 -1
- package/dist/website/assets/{xbull.module-B4N1LGQD.js → xbull.module-DQx6rh7x.js} +1 -1
- package/dist/website/index.html +19 -19
- package/package.json +3 -2
- package/dist/website/assets/AlertController-CH5fpr36.js +0 -1
- package/dist/website/assets/DateTime-DR7XeJxF.js +0 -1
- package/dist/website/assets/ModalController-CWwEAkfw.js +0 -5
- package/dist/website/assets/assets-Dk5ppLtc.js +0 -2
- package/dist/website/assets/bignumber-CziKLYjt.js +0 -1
- package/dist/website/assets/blakejs-Dx-Zt5zT.js +0 -3
- package/dist/website/assets/bn-CJG5j3KW.js +0 -1
- package/dist/website/assets/core-uatW2d6Y.js +0 -2
- package/dist/website/assets/dist-CELdgNh9.js +0 -1
- package/dist/website/assets/dist-omv2KNC4.js +0 -5
- package/dist/website/assets/events-D2w4OsQJ.js +0 -1
- package/dist/website/assets/freighter.module-CaBNS6Y-.js +0 -1
- package/dist/website/assets/index-3l3n0-cX.js +0 -540
- package/dist/website/assets/index-Dpi1HuAK.css +0 -1
- package/dist/website/assets/index.es-DCi2xZ1b.js +0 -1
- package/dist/website/assets/lobstr.module-GQjJAf8P.js +0 -1
- package/dist/website/assets/registry-DVfYVrCY.js +0 -1
- package/dist/website/assets/state-B8Vu3fYx.js +0 -1
- package/dist/website/assets/styles.css-BK5OO2Hh.js +0 -1
- package/dist/website/assets/substrate-connector-CwnGlD2K.js +0 -2
- package/dist/website/assets/tfhe-PDJAG8Bv.js +0 -1
- package/dist/website/assets/ton-connector-DMNOeieX.js +0 -2264
- package/dist/website/assets/tracking-variants-CuRpr0B_.js +0 -85
- package/dist/website/assets/transaction-CbxrIerN.js +0 -2
- package/dist/website/assets/wallet-manager-D8tOJ1jy.js +0 -5
- package/dist/website/mockServiceWorker.js +0 -460
|
@@ -1,460 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/* tslint:disable */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Mock Service Worker.
|
|
6
|
-
* @see https://github.com/mswjs/msw
|
|
7
|
-
* - Please do NOT modify this file.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const PACKAGE_VERSION = '3.0.2'
|
|
11
|
-
const INTEGRITY_CHECKSUM = '5cd5cf8b54c3a90f82960cedcd637772'
|
|
12
|
-
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
13
|
-
|
|
14
|
-
const activeClientIds = new Set()
|
|
15
|
-
/**
|
|
16
|
-
* @type {Map<string, Set<Promise<Response>>>}
|
|
17
|
-
*/
|
|
18
|
-
const pendingRequests = new Map()
|
|
19
|
-
|
|
20
|
-
addEventListener('install', function () {
|
|
21
|
-
self.skipWaiting()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
addEventListener('activate', function (event) {
|
|
25
|
-
event.waitUntil(self.clients.claim())
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
addEventListener('message', function (event) {
|
|
29
|
-
const clientId = Reflect.get(event.source || {}, 'id')
|
|
30
|
-
|
|
31
|
-
if (!clientId || !self.clients) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
event.waitUntil(
|
|
36
|
-
(async () => {
|
|
37
|
-
if (event.data === 'CLIENT_CLOSE') {
|
|
38
|
-
const allClients = await self.clients.matchAll({
|
|
39
|
-
type: 'window',
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
activeClientIds.delete(clientId)
|
|
43
|
-
|
|
44
|
-
// Await any pending requests from the closing client.
|
|
45
|
-
// This makes sure that those requests are handled and not passthrough.
|
|
46
|
-
const pending = pendingRequests.get(clientId)
|
|
47
|
-
if (pending != null && pending.size > 0) {
|
|
48
|
-
await Promise.allSettled(pending)
|
|
49
|
-
}
|
|
50
|
-
pendingRequests.delete(clientId)
|
|
51
|
-
|
|
52
|
-
const remainingClients = allClients.filter((client) => {
|
|
53
|
-
return client.id !== clientId
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
// Unregister itself when there are no more clients
|
|
57
|
-
if (remainingClients.length === 0) {
|
|
58
|
-
await self.registration.unregister()
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const client = await self.clients.get(clientId)
|
|
62
|
-
|
|
63
|
-
if (client != null) {
|
|
64
|
-
await sendToClient(client, {
|
|
65
|
-
type: 'CLIENT_CLOSED',
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @note Check for the client AFTER handling "CLIENT_CLOSE".
|
|
74
|
-
* This prevents early return on "!client" in case the page has reloaded
|
|
75
|
-
* and disassociated itself from the worker. This ensures self-unregistration
|
|
76
|
-
* still fires for those pages.
|
|
77
|
-
*/
|
|
78
|
-
const client = await self.clients.get(clientId)
|
|
79
|
-
|
|
80
|
-
if (!client) {
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
switch (event.data) {
|
|
85
|
-
case 'KEEPALIVE_REQUEST': {
|
|
86
|
-
await sendToClient(client, {
|
|
87
|
-
type: 'KEEPALIVE_RESPONSE',
|
|
88
|
-
})
|
|
89
|
-
break
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
case 'INTEGRITY_CHECK_REQUEST': {
|
|
93
|
-
await sendToClient(client, {
|
|
94
|
-
type: 'INTEGRITY_CHECK_RESPONSE',
|
|
95
|
-
payload: {
|
|
96
|
-
packageVersion: PACKAGE_VERSION,
|
|
97
|
-
checksum: INTEGRITY_CHECKSUM,
|
|
98
|
-
},
|
|
99
|
-
})
|
|
100
|
-
break
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
case 'MOCK_ACTIVATE': {
|
|
104
|
-
activeClientIds.add(clientId)
|
|
105
|
-
|
|
106
|
-
await sendToClient(client, {
|
|
107
|
-
type: 'MOCKING_ENABLED',
|
|
108
|
-
payload: {
|
|
109
|
-
client: {
|
|
110
|
-
id: client.id,
|
|
111
|
-
frameType: client.frameType,
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
})
|
|
115
|
-
break
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
})(),
|
|
119
|
-
)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
addEventListener('fetch', function (event) {
|
|
123
|
-
// Opening the DevTools triggers the "only-if-cached" request
|
|
124
|
-
// that cannot be handled by the worker. Bypass such requests.
|
|
125
|
-
if (
|
|
126
|
-
event.request.cache === 'only-if-cached' &&
|
|
127
|
-
event.request.mode !== 'same-origin'
|
|
128
|
-
) {
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Bypass all requests when there are no active clients.
|
|
133
|
-
// Prevents the self-unregistered worked from handling requests
|
|
134
|
-
// after it's been terminated (still remains active until the next reload).
|
|
135
|
-
if (activeClientIds.size === 0) {
|
|
136
|
-
return
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const requestId = crypto.randomUUID()
|
|
140
|
-
event.respondWith(handleRequest(event, requestId))
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* @param {FetchEvent} event
|
|
145
|
-
* @param {string} requestId
|
|
146
|
-
*/
|
|
147
|
-
async function handleRequest(event, requestId) {
|
|
148
|
-
const client = await resolveMainClient(event)
|
|
149
|
-
const requestCloneForEvents = event.request.clone()
|
|
150
|
-
|
|
151
|
-
const responsePromise = getResponse(event, client, requestId)
|
|
152
|
-
|
|
153
|
-
if (client != null) {
|
|
154
|
-
let pending = pendingRequests.get(client.id)
|
|
155
|
-
|
|
156
|
-
if (pending == null) {
|
|
157
|
-
pendingRequests.set(client.id, (pending = new Set()))
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
pending.add(responsePromise)
|
|
161
|
-
responsePromise
|
|
162
|
-
.finally(() => pending.delete(responsePromise))
|
|
163
|
-
.catch(() => {})
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
let response
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
response = await responsePromise
|
|
170
|
-
} catch (error) {
|
|
171
|
-
// The request has settled without a response (e.g. a passthrough
|
|
172
|
-
// request failed with a network error). Notify the client so it
|
|
173
|
-
// can release the resources associated with this request.
|
|
174
|
-
if (client && activeClientIds.has(client.id)) {
|
|
175
|
-
sendToClient(client, {
|
|
176
|
-
type: 'REQUEST_ERROR',
|
|
177
|
-
payload: {
|
|
178
|
-
request: {
|
|
179
|
-
id: requestId,
|
|
180
|
-
},
|
|
181
|
-
error: serializeError(error),
|
|
182
|
-
},
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
throw error
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Send back the response clone for the "response:*" life-cycle events.
|
|
190
|
-
// Ensure MSW is active and ready to handle the message, otherwise
|
|
191
|
-
// this message will pend indefinitely.
|
|
192
|
-
if (client && activeClientIds.has(client.id)) {
|
|
193
|
-
const serializedRequest = await serializeRequest(requestCloneForEvents)
|
|
194
|
-
|
|
195
|
-
// Omit the body of server-sent event stream responses.
|
|
196
|
-
// Cloning such responses would prevent client-side stream cancelations
|
|
197
|
-
// from reaching the original stream (a teed stream only cancels its
|
|
198
|
-
// source once both of its branches cancel) and would buffer the
|
|
199
|
-
// entire stream into the unconsumed clone indefinitely.
|
|
200
|
-
const isEventStreamResponse = response.headers
|
|
201
|
-
.get('content-type')
|
|
202
|
-
?.toLowerCase()
|
|
203
|
-
.startsWith('text/event-stream')
|
|
204
|
-
|
|
205
|
-
// Clone the response so both the client and the library could consume it.
|
|
206
|
-
const responseClone = isEventStreamResponse ? null : response.clone()
|
|
207
|
-
|
|
208
|
-
sendToClient(
|
|
209
|
-
client,
|
|
210
|
-
{
|
|
211
|
-
type: 'RESPONSE',
|
|
212
|
-
payload: {
|
|
213
|
-
isMockedResponse: IS_MOCKED_RESPONSE in response,
|
|
214
|
-
request: {
|
|
215
|
-
id: requestId,
|
|
216
|
-
...serializedRequest,
|
|
217
|
-
},
|
|
218
|
-
response: {
|
|
219
|
-
type: response.type,
|
|
220
|
-
status: response.status,
|
|
221
|
-
statusText: response.statusText,
|
|
222
|
-
headers: Object.fromEntries(response.headers.entries()),
|
|
223
|
-
body: responseClone ? responseClone.body : null,
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
responseClone && responseClone.body
|
|
228
|
-
? [serializedRequest.body, responseClone.body]
|
|
229
|
-
: [],
|
|
230
|
-
)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return response
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Resolve the main client for the given event.
|
|
238
|
-
* Client that issues a request doesn't necessarily equal the client
|
|
239
|
-
* that registered the worker. It's with the latter the worker should
|
|
240
|
-
* communicate with during the response resolving phase.
|
|
241
|
-
* @param {FetchEvent} event
|
|
242
|
-
* @returns {Promise<Client | undefined>}
|
|
243
|
-
*/
|
|
244
|
-
async function resolveMainClient(event) {
|
|
245
|
-
const client = await self.clients.get(event.clientId)
|
|
246
|
-
|
|
247
|
-
if (activeClientIds.has(event.clientId)) {
|
|
248
|
-
return client
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (client?.frameType === 'top-level') {
|
|
252
|
-
return client
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const allClients = await self.clients.matchAll({
|
|
256
|
-
type: 'window',
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
return allClients
|
|
260
|
-
.filter((client) => {
|
|
261
|
-
// Get only those clients that are currently visible.
|
|
262
|
-
return client.visibilityState === 'visible'
|
|
263
|
-
})
|
|
264
|
-
.find((client) => {
|
|
265
|
-
// Find the client ID that's recorded in the
|
|
266
|
-
// set of clients that have registered the worker.
|
|
267
|
-
return activeClientIds.has(client.id)
|
|
268
|
-
})
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* @param {FetchEvent} event
|
|
273
|
-
* @param {Client | undefined} client
|
|
274
|
-
* @param {string} requestId
|
|
275
|
-
* @returns {Promise<Response>}
|
|
276
|
-
*/
|
|
277
|
-
async function getResponse(event, client, requestId) {
|
|
278
|
-
// Clone the request because it might've been already used
|
|
279
|
-
// (i.e. its body has been read and sent to the client).
|
|
280
|
-
const requestClone = event.request.clone()
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* @param {{ request?: { headers?: Array<[string, string]> } }} [data]
|
|
284
|
-
*/
|
|
285
|
-
function passthrough(data) {
|
|
286
|
-
const headers = new Headers()
|
|
287
|
-
const requestHeaders = data?.request?.headers
|
|
288
|
-
|
|
289
|
-
if (Array.isArray(requestHeaders)) {
|
|
290
|
-
// Apply the request headers provided by the client.
|
|
291
|
-
// Those reflect any modifications made in the request handlers.
|
|
292
|
-
// Use ".append()" to support multiple headers with the same name.
|
|
293
|
-
for (const [name, value] of requestHeaders) {
|
|
294
|
-
headers.append(name, value)
|
|
295
|
-
}
|
|
296
|
-
} else {
|
|
297
|
-
for (const [name, value] of requestClone.headers) {
|
|
298
|
-
headers.append(name, value)
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Remove the "accept" header value that marked this request as passthrough.
|
|
303
|
-
// This prevents request alteration and also keeps it compliant with the
|
|
304
|
-
// user-defined CORS policies.
|
|
305
|
-
const acceptHeader = headers.get('accept')
|
|
306
|
-
if (acceptHeader) {
|
|
307
|
-
const values = acceptHeader.split(',').map((value) => value.trim())
|
|
308
|
-
const filteredValues = values.filter(
|
|
309
|
-
(value) => value !== 'msw/passthrough',
|
|
310
|
-
)
|
|
311
|
-
|
|
312
|
-
if (filteredValues.length > 0) {
|
|
313
|
-
headers.set('accept', filteredValues.join(', '))
|
|
314
|
-
} else {
|
|
315
|
-
headers.delete('accept')
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return fetch(requestClone, { headers })
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// Bypass mocking when the client is not active.
|
|
323
|
-
if (!client) {
|
|
324
|
-
return passthrough()
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Bypass initial page load requests (i.e. static assets).
|
|
328
|
-
// The absence of the immediate/parent client in the map of the active clients
|
|
329
|
-
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
|
|
330
|
-
// and is not ready to handle requests.
|
|
331
|
-
if (!activeClientIds.has(client.id)) {
|
|
332
|
-
return passthrough()
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// Notify the client that a request has been intercepted.
|
|
336
|
-
const serializedRequest = await serializeRequest(event.request)
|
|
337
|
-
const clientMessage = await sendToClient(
|
|
338
|
-
client,
|
|
339
|
-
{
|
|
340
|
-
type: 'REQUEST',
|
|
341
|
-
payload: {
|
|
342
|
-
id: requestId,
|
|
343
|
-
...serializedRequest,
|
|
344
|
-
},
|
|
345
|
-
},
|
|
346
|
-
[serializedRequest.body],
|
|
347
|
-
)
|
|
348
|
-
|
|
349
|
-
switch (clientMessage.type) {
|
|
350
|
-
case 'MOCK_RESPONSE': {
|
|
351
|
-
return respondWithMock(clientMessage.data, event)
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
case 'PASSTHROUGH': {
|
|
355
|
-
return passthrough(clientMessage.data)
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return passthrough()
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* @param {unknown} error
|
|
364
|
-
* @returns {{ name: string, message: string }}
|
|
365
|
-
*/
|
|
366
|
-
function serializeError(error) {
|
|
367
|
-
if (error instanceof Error) {
|
|
368
|
-
return {
|
|
369
|
-
name: error.name,
|
|
370
|
-
message: error.message,
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
return {
|
|
375
|
-
name: 'Error',
|
|
376
|
-
message: String(error),
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* @param {Client} client
|
|
382
|
-
* @param {any} message
|
|
383
|
-
* @param {Array<Transferable>} transferrables
|
|
384
|
-
* @returns {Promise<any>}
|
|
385
|
-
*/
|
|
386
|
-
function sendToClient(client, message, transferrables = []) {
|
|
387
|
-
return new Promise((resolve, reject) => {
|
|
388
|
-
const channel = new MessageChannel()
|
|
389
|
-
|
|
390
|
-
channel.port1.onmessage = (event) => {
|
|
391
|
-
if (event.data && event.data.error) {
|
|
392
|
-
return reject(event.data.error)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
resolve(event.data)
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
client.postMessage(message, [
|
|
399
|
-
channel.port2,
|
|
400
|
-
...transferrables.filter(Boolean),
|
|
401
|
-
])
|
|
402
|
-
})
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* @param {Response} response
|
|
407
|
-
* @param {FetchEvent} event
|
|
408
|
-
* @returns {Promise<Response>}
|
|
409
|
-
*/
|
|
410
|
-
async function respondWithMock(response, event) {
|
|
411
|
-
// Setting response status code to 0 is a no-op.
|
|
412
|
-
// However, when responding with a "Response.error()", the produced Response
|
|
413
|
-
// instance will have status code set to 0. Since it's not possible to create
|
|
414
|
-
// a Response instance with status code 0, handle that use-case separately.
|
|
415
|
-
if (response.status === 0) {
|
|
416
|
-
return Response.error()
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
let body = response.body
|
|
420
|
-
|
|
421
|
-
// Buffer the streamed mocked response body for navigation requests.
|
|
422
|
-
// The stream is transferred from the client that is being navigated
|
|
423
|
-
// away from. Once the navigation commits, that client gets destroyed
|
|
424
|
-
// and the stream will never complete, resulting in an empty document.
|
|
425
|
-
// Buffering here keeps "event.respondWith()" pending (the navigation
|
|
426
|
-
// cannot commit) until the entire body arrives from the client.
|
|
427
|
-
if (event.request.mode === 'navigate' && body instanceof ReadableStream) {
|
|
428
|
-
body = await new Response(body).arrayBuffer()
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const mockedResponse = new Response(body, response)
|
|
432
|
-
|
|
433
|
-
Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
|
|
434
|
-
value: true,
|
|
435
|
-
enumerable: true,
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
return mockedResponse
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* @param {Request} request
|
|
443
|
-
*/
|
|
444
|
-
async function serializeRequest(request) {
|
|
445
|
-
return {
|
|
446
|
-
url: request.url,
|
|
447
|
-
mode: request.mode,
|
|
448
|
-
method: request.method,
|
|
449
|
-
headers: Object.fromEntries(request.headers.entries()),
|
|
450
|
-
cache: request.cache,
|
|
451
|
-
credentials: request.credentials,
|
|
452
|
-
destination: request.destination,
|
|
453
|
-
integrity: request.integrity,
|
|
454
|
-
redirect: request.redirect,
|
|
455
|
-
referrer: request.referrer,
|
|
456
|
-
referrerPolicy: request.referrerPolicy,
|
|
457
|
-
body: await request.arrayBuffer(),
|
|
458
|
-
keepalive: request.keepalive,
|
|
459
|
-
}
|
|
460
|
-
}
|