@factoringplus/pl-components-pack-v3 0.5.82-pre-01 → 0.5.82
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/mockServiceWorker.js +97 -100
- package/dist/pl-components-pack-v3.es.js +3244 -3432
- package/dist/pl-components-pack-v3.umd.js +18 -18
- package/dist/style.css +1 -1
- package/package.json +31 -3
|
@@ -8,111 +8,111 @@
|
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const INTEGRITY_CHECKSUM = 'c9450df6e4dc5e45740c3b0b640727a2'
|
|
12
|
-
const activeClientIds = new Set()
|
|
11
|
+
const INTEGRITY_CHECKSUM = 'c9450df6e4dc5e45740c3b0b640727a2';
|
|
12
|
+
const activeClientIds = new Set();
|
|
13
13
|
|
|
14
14
|
self.addEventListener('install', function () {
|
|
15
|
-
self.skipWaiting()
|
|
16
|
-
})
|
|
15
|
+
self.skipWaiting();
|
|
16
|
+
});
|
|
17
17
|
|
|
18
18
|
self.addEventListener('activate', function (event) {
|
|
19
|
-
event.waitUntil(self.clients.claim())
|
|
20
|
-
})
|
|
19
|
+
event.waitUntil(self.clients.claim());
|
|
20
|
+
});
|
|
21
21
|
|
|
22
22
|
self.addEventListener('message', async function (event) {
|
|
23
|
-
const clientId = event.source.id
|
|
23
|
+
const clientId = event.source.id;
|
|
24
24
|
|
|
25
25
|
if (!clientId || !self.clients) {
|
|
26
|
-
return
|
|
26
|
+
return;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const client = await self.clients.get(clientId)
|
|
29
|
+
const client = await self.clients.get(clientId);
|
|
30
30
|
|
|
31
31
|
if (!client) {
|
|
32
|
-
return
|
|
32
|
+
return;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const allClients = await self.clients.matchAll({
|
|
36
36
|
type: 'window',
|
|
37
|
-
})
|
|
37
|
+
});
|
|
38
38
|
|
|
39
39
|
switch (event.data) {
|
|
40
40
|
case 'KEEPALIVE_REQUEST': {
|
|
41
41
|
sendToClient(client, {
|
|
42
42
|
type: 'KEEPALIVE_RESPONSE',
|
|
43
|
-
})
|
|
44
|
-
break
|
|
43
|
+
});
|
|
44
|
+
break;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
case 'INTEGRITY_CHECK_REQUEST': {
|
|
48
48
|
sendToClient(client, {
|
|
49
49
|
type: 'INTEGRITY_CHECK_RESPONSE',
|
|
50
50
|
payload: INTEGRITY_CHECKSUM,
|
|
51
|
-
})
|
|
52
|
-
break
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
case 'MOCK_ACTIVATE': {
|
|
56
|
-
activeClientIds.add(clientId)
|
|
56
|
+
activeClientIds.add(clientId);
|
|
57
57
|
|
|
58
58
|
sendToClient(client, {
|
|
59
59
|
type: 'MOCKING_ENABLED',
|
|
60
60
|
payload: true,
|
|
61
|
-
})
|
|
62
|
-
break
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
case 'MOCK_DEACTIVATE': {
|
|
66
|
-
activeClientIds.delete(clientId)
|
|
67
|
-
break
|
|
66
|
+
activeClientIds.delete(clientId);
|
|
67
|
+
break;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
case 'CLIENT_CLOSED': {
|
|
71
|
-
activeClientIds.delete(clientId)
|
|
71
|
+
activeClientIds.delete(clientId);
|
|
72
72
|
|
|
73
73
|
const remainingClients = allClients.filter((client) => {
|
|
74
|
-
return client.id !== clientId
|
|
75
|
-
})
|
|
74
|
+
return client.id !== clientId;
|
|
75
|
+
});
|
|
76
76
|
|
|
77
77
|
// Unregister itself when there are no more clients
|
|
78
78
|
if (remainingClients.length === 0) {
|
|
79
|
-
self.registration.unregister()
|
|
79
|
+
self.registration.unregister();
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
break
|
|
82
|
+
break;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
})
|
|
85
|
+
});
|
|
86
86
|
|
|
87
87
|
self.addEventListener('fetch', function (event) {
|
|
88
|
-
const { request } = event
|
|
89
|
-
const accept = request.headers.get('accept') || ''
|
|
88
|
+
const { request } = event;
|
|
89
|
+
const accept = request.headers.get('accept') || '';
|
|
90
90
|
|
|
91
91
|
// Bypass server-sent events.
|
|
92
92
|
if (accept.includes('text/event-stream')) {
|
|
93
|
-
return
|
|
93
|
+
return;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// Bypass navigation requests.
|
|
97
97
|
if (request.mode === 'navigate') {
|
|
98
|
-
return
|
|
98
|
+
return;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
// Opening the DevTools triggers the "only-if-cached" request
|
|
102
102
|
// that cannot be handled by the worker. Bypass such requests.
|
|
103
103
|
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
|
|
104
|
-
return
|
|
104
|
+
return;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// Bypass all requests when there are no active clients.
|
|
108
108
|
// Prevents the self-unregistered worked from handling requests
|
|
109
109
|
// after it's been deleted (still remains active until the next reload).
|
|
110
110
|
if (activeClientIds.size === 0) {
|
|
111
|
-
return
|
|
111
|
+
return;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
// Generate unique request ID.
|
|
115
|
-
const requestId = Math.random().toString(16).slice(2)
|
|
115
|
+
const requestId = Math.random().toString(16).slice(2);
|
|
116
116
|
|
|
117
117
|
event.respondWith(
|
|
118
118
|
handleRequest(event, requestId).catch((error) => {
|
|
@@ -121,8 +121,8 @@ self.addEventListener('fetch', function (event) {
|
|
|
121
121
|
'[MSW] Successfully emulated a network error for the "%s %s" request.',
|
|
122
122
|
request.method,
|
|
123
123
|
request.url,
|
|
124
|
-
)
|
|
125
|
-
return
|
|
124
|
+
);
|
|
125
|
+
return;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
// At this point, any exception indicates an issue with the original request/response.
|
|
@@ -132,21 +132,21 @@ self.addEventListener('fetch', function (event) {
|
|
|
132
132
|
request.method,
|
|
133
133
|
request.url,
|
|
134
134
|
`${error.name}: ${error.message}`,
|
|
135
|
-
)
|
|
135
|
+
);
|
|
136
136
|
}),
|
|
137
|
-
)
|
|
138
|
-
})
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
139
|
|
|
140
140
|
async function handleRequest(event, requestId) {
|
|
141
|
-
const client = await resolveMainClient(event)
|
|
142
|
-
const response = await getResponse(event, client, requestId)
|
|
141
|
+
const client = await resolveMainClient(event);
|
|
142
|
+
const response = await getResponse(event, client, requestId);
|
|
143
143
|
|
|
144
144
|
// Send back the response clone for the "response:*" life-cycle events.
|
|
145
145
|
// Ensure MSW is active and ready to handle the message, otherwise
|
|
146
146
|
// this message will pend indefinitely.
|
|
147
147
|
if (client && activeClientIds.has(client.id)) {
|
|
148
|
-
|
|
149
|
-
const clonedResponse = response.clone()
|
|
148
|
+
(async function () {
|
|
149
|
+
const clonedResponse = response.clone();
|
|
150
150
|
sendToClient(client, {
|
|
151
151
|
type: 'RESPONSE',
|
|
152
152
|
payload: {
|
|
@@ -155,16 +155,15 @@ async function handleRequest(event, requestId) {
|
|
|
155
155
|
ok: clonedResponse.ok,
|
|
156
156
|
status: clonedResponse.status,
|
|
157
157
|
statusText: clonedResponse.statusText,
|
|
158
|
-
body:
|
|
159
|
-
clonedResponse.body === null ? null : await clonedResponse.text(),
|
|
158
|
+
body: clonedResponse.body === null ? null : await clonedResponse.text(),
|
|
160
159
|
headers: Object.fromEntries(clonedResponse.headers.entries()),
|
|
161
160
|
redirected: clonedResponse.redirected,
|
|
162
161
|
},
|
|
163
|
-
})
|
|
164
|
-
})()
|
|
162
|
+
});
|
|
163
|
+
})();
|
|
165
164
|
}
|
|
166
165
|
|
|
167
|
-
return response
|
|
166
|
+
return response;
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
// Resolve the main client for the given event.
|
|
@@ -172,49 +171,49 @@ async function handleRequest(event, requestId) {
|
|
|
172
171
|
// that registered the worker. It's with the latter the worker should
|
|
173
172
|
// communicate with during the response resolving phase.
|
|
174
173
|
async function resolveMainClient(event) {
|
|
175
|
-
const client = await self.clients.get(event.clientId)
|
|
174
|
+
const client = await self.clients.get(event.clientId);
|
|
176
175
|
|
|
177
176
|
if (client.frameType === 'top-level') {
|
|
178
|
-
return client
|
|
177
|
+
return client;
|
|
179
178
|
}
|
|
180
179
|
|
|
181
180
|
const allClients = await self.clients.matchAll({
|
|
182
181
|
type: 'window',
|
|
183
|
-
})
|
|
182
|
+
});
|
|
184
183
|
|
|
185
184
|
return allClients
|
|
186
185
|
.filter((client) => {
|
|
187
186
|
// Get only those clients that are currently visible.
|
|
188
|
-
return client.visibilityState === 'visible'
|
|
187
|
+
return client.visibilityState === 'visible';
|
|
189
188
|
})
|
|
190
189
|
.find((client) => {
|
|
191
190
|
// Find the client ID that's recorded in the
|
|
192
191
|
// set of clients that have registered the worker.
|
|
193
|
-
return activeClientIds.has(client.id)
|
|
194
|
-
})
|
|
192
|
+
return activeClientIds.has(client.id);
|
|
193
|
+
});
|
|
195
194
|
}
|
|
196
195
|
|
|
197
196
|
async function getResponse(event, client, requestId) {
|
|
198
|
-
const { request } = event
|
|
199
|
-
const clonedRequest = request.clone()
|
|
197
|
+
const { request } = event;
|
|
198
|
+
const clonedRequest = request.clone();
|
|
200
199
|
|
|
201
200
|
function passthrough() {
|
|
202
201
|
// Clone the request because it might've been already used
|
|
203
202
|
// (i.e. its body has been read and sent to the cilent).
|
|
204
|
-
const headers = Object.fromEntries(clonedRequest.headers.entries())
|
|
203
|
+
const headers = Object.fromEntries(clonedRequest.headers.entries());
|
|
205
204
|
|
|
206
205
|
// Remove MSW-specific request headers so the bypassed requests
|
|
207
206
|
// comply with the server's CORS preflight check.
|
|
208
207
|
// Operate with the headers as an object because request "Headers"
|
|
209
208
|
// are immutable.
|
|
210
|
-
delete headers['x-msw-bypass']
|
|
209
|
+
delete headers['x-msw-bypass'];
|
|
211
210
|
|
|
212
|
-
return fetch(clonedRequest, { headers })
|
|
211
|
+
return fetch(clonedRequest, { headers });
|
|
213
212
|
}
|
|
214
213
|
|
|
215
214
|
// Bypass mocking when the client is not active.
|
|
216
215
|
if (!client) {
|
|
217
|
-
return passthrough()
|
|
216
|
+
return passthrough();
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
// Bypass initial page load requests (i.e. static assets).
|
|
@@ -222,21 +221,19 @@ async function getResponse(event, client, requestId) {
|
|
|
222
221
|
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
|
|
223
222
|
// and is not ready to handle requests.
|
|
224
223
|
if (!activeClientIds.has(client.id)) {
|
|
225
|
-
return passthrough()
|
|
224
|
+
return passthrough();
|
|
226
225
|
}
|
|
227
226
|
|
|
228
227
|
// Bypass requests with the explicit bypass header.
|
|
229
228
|
// Such requests can be issued by "ctx.fetch()".
|
|
230
229
|
if (request.headers.get('x-msw-bypass') === 'true') {
|
|
231
|
-
return passthrough()
|
|
230
|
+
return passthrough();
|
|
232
231
|
}
|
|
233
232
|
|
|
234
233
|
// Create a communication channel scoped to the current request.
|
|
235
234
|
// This way events can be exchanged outside of the worker's global
|
|
236
235
|
// "message" event listener (i.e. abstracted into functions).
|
|
237
|
-
const operationChannel = new BroadcastChannel(
|
|
238
|
-
`msw-response-stream-${requestId}`,
|
|
239
|
-
)
|
|
236
|
+
const operationChannel = new BroadcastChannel(`msw-response-stream-${requestId}`);
|
|
240
237
|
|
|
241
238
|
// Notify the client that a request has been intercepted.
|
|
242
239
|
const clientMessage = await sendToClient(client, {
|
|
@@ -258,32 +255,32 @@ async function getResponse(event, client, requestId) {
|
|
|
258
255
|
bodyUsed: request.bodyUsed,
|
|
259
256
|
keepalive: request.keepalive,
|
|
260
257
|
},
|
|
261
|
-
})
|
|
258
|
+
});
|
|
262
259
|
|
|
263
260
|
switch (clientMessage.type) {
|
|
264
261
|
case 'MOCK_RESPONSE': {
|
|
265
|
-
return respondWithMock(clientMessage.payload)
|
|
262
|
+
return respondWithMock(clientMessage.payload);
|
|
266
263
|
}
|
|
267
264
|
|
|
268
265
|
case 'MOCK_RESPONSE_START': {
|
|
269
|
-
return respondWithMockStream(operationChannel, clientMessage.payload)
|
|
266
|
+
return respondWithMockStream(operationChannel, clientMessage.payload);
|
|
270
267
|
}
|
|
271
268
|
|
|
272
269
|
case 'MOCK_NOT_FOUND': {
|
|
273
|
-
return passthrough()
|
|
270
|
+
return passthrough();
|
|
274
271
|
}
|
|
275
272
|
|
|
276
273
|
case 'NETWORK_ERROR': {
|
|
277
|
-
const { name, message } = clientMessage.payload
|
|
278
|
-
const networkError = new Error(message)
|
|
279
|
-
networkError.name = name
|
|
274
|
+
const { name, message } = clientMessage.payload;
|
|
275
|
+
const networkError = new Error(message);
|
|
276
|
+
networkError.name = name;
|
|
280
277
|
|
|
281
278
|
// Rejecting a "respondWith" promise emulates a network error.
|
|
282
|
-
throw networkError
|
|
279
|
+
throw networkError;
|
|
283
280
|
}
|
|
284
281
|
|
|
285
282
|
case 'INTERNAL_ERROR': {
|
|
286
|
-
const parsedBody = JSON.parse(clientMessage.payload.body)
|
|
283
|
+
const parsedBody = JSON.parse(clientMessage.payload.body);
|
|
287
284
|
|
|
288
285
|
console.error(
|
|
289
286
|
`\
|
|
@@ -295,73 +292,73 @@ This exception has been gracefully handled as a 500 response, however, it's stro
|
|
|
295
292
|
`,
|
|
296
293
|
request.method,
|
|
297
294
|
request.url,
|
|
298
|
-
)
|
|
295
|
+
);
|
|
299
296
|
|
|
300
|
-
return respondWithMock(clientMessage.payload)
|
|
297
|
+
return respondWithMock(clientMessage.payload);
|
|
301
298
|
}
|
|
302
299
|
}
|
|
303
300
|
|
|
304
|
-
return passthrough()
|
|
301
|
+
return passthrough();
|
|
305
302
|
}
|
|
306
303
|
|
|
307
304
|
function sendToClient(client, message) {
|
|
308
305
|
return new Promise((resolve, reject) => {
|
|
309
|
-
const channel = new MessageChannel()
|
|
306
|
+
const channel = new MessageChannel();
|
|
310
307
|
|
|
311
308
|
channel.port1.onmessage = (event) => {
|
|
312
309
|
if (event.data && event.data.error) {
|
|
313
|
-
return reject(event.data.error)
|
|
310
|
+
return reject(event.data.error);
|
|
314
311
|
}
|
|
315
312
|
|
|
316
|
-
resolve(event.data)
|
|
317
|
-
}
|
|
313
|
+
resolve(event.data);
|
|
314
|
+
};
|
|
318
315
|
|
|
319
|
-
client.postMessage(JSON.stringify(message), [channel.port2])
|
|
320
|
-
})
|
|
316
|
+
client.postMessage(JSON.stringify(message), [channel.port2]);
|
|
317
|
+
});
|
|
321
318
|
}
|
|
322
319
|
|
|
323
320
|
function sleep(timeMs) {
|
|
324
321
|
return new Promise((resolve) => {
|
|
325
|
-
setTimeout(resolve, timeMs)
|
|
326
|
-
})
|
|
322
|
+
setTimeout(resolve, timeMs);
|
|
323
|
+
});
|
|
327
324
|
}
|
|
328
325
|
|
|
329
326
|
async function respondWithMock(response) {
|
|
330
|
-
await sleep(response.delay)
|
|
331
|
-
return new Response(response.body, response)
|
|
327
|
+
await sleep(response.delay);
|
|
328
|
+
return new Response(response.body, response);
|
|
332
329
|
}
|
|
333
330
|
|
|
334
331
|
function respondWithMockStream(operationChannel, mockResponse) {
|
|
335
|
-
let streamCtrl
|
|
332
|
+
let streamCtrl;
|
|
336
333
|
const stream = new ReadableStream({
|
|
337
334
|
start: (controller) => (streamCtrl = controller),
|
|
338
|
-
})
|
|
335
|
+
});
|
|
339
336
|
|
|
340
337
|
return new Promise(async (resolve, reject) => {
|
|
341
338
|
operationChannel.onmessageerror = (event) => {
|
|
342
|
-
operationChannel.close()
|
|
343
|
-
return reject(event.data.error)
|
|
344
|
-
}
|
|
339
|
+
operationChannel.close();
|
|
340
|
+
return reject(event.data.error);
|
|
341
|
+
};
|
|
345
342
|
|
|
346
343
|
operationChannel.onmessage = (event) => {
|
|
347
344
|
if (!event.data) {
|
|
348
|
-
return
|
|
345
|
+
return;
|
|
349
346
|
}
|
|
350
347
|
|
|
351
348
|
switch (event.data.type) {
|
|
352
349
|
case 'MOCK_RESPONSE_CHUNK': {
|
|
353
|
-
streamCtrl.enqueue(event.data.payload)
|
|
354
|
-
break
|
|
350
|
+
streamCtrl.enqueue(event.data.payload);
|
|
351
|
+
break;
|
|
355
352
|
}
|
|
356
353
|
|
|
357
354
|
case 'MOCK_RESPONSE_END': {
|
|
358
|
-
streamCtrl.close()
|
|
359
|
-
operationChannel.close()
|
|
355
|
+
streamCtrl.close();
|
|
356
|
+
operationChannel.close();
|
|
360
357
|
}
|
|
361
358
|
}
|
|
362
|
-
}
|
|
359
|
+
};
|
|
363
360
|
|
|
364
|
-
await sleep(mockResponse.delay)
|
|
365
|
-
return resolve(new Response(stream, mockResponse))
|
|
366
|
-
})
|
|
361
|
+
await sleep(mockResponse.delay);
|
|
362
|
+
return resolve(new Response(stream, mockResponse));
|
|
363
|
+
});
|
|
367
364
|
}
|