@timum/booking 1.5.0 → 1.5.2

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.
@@ -1,338 +1,303 @@
1
- /* eslint-disable */
2
- /* tslint:disable */
3
-
4
- /**
5
- * Mock Service Worker (0.39.2).
6
- * @see https://github.com/mswjs/msw
7
- * - Please do NOT modify this file.
8
- * - Please do NOT serve this file on production.
9
- */
10
-
11
- const INTEGRITY_CHECKSUM = '02f4ad4a2797f85668baf196e553d929'
12
- const bypassHeaderName = 'x-msw-bypass'
13
- const activeClientIds = new Set()
14
-
15
- self.addEventListener('install', function () {
16
- return self.skipWaiting()
17
- })
18
-
19
- self.addEventListener('activate', async function (event) {
20
- return self.clients.claim()
21
- })
22
-
23
- self.addEventListener('message', async function (event) {
24
- const clientId = event.source.id
25
-
26
- if (!clientId || !self.clients) {
27
- return
28
- }
29
-
30
- const client = await self.clients.get(clientId)
31
-
32
- if (!client) {
33
- return
34
- }
35
-
36
- const allClients = await self.clients.matchAll()
37
-
38
- switch (event.data) {
39
- case 'KEEPALIVE_REQUEST': {
40
- sendToClient(client, {
41
- type: 'KEEPALIVE_RESPONSE',
42
- })
43
- break
44
- }
45
-
46
- case 'INTEGRITY_CHECK_REQUEST': {
47
- sendToClient(client, {
48
- type: 'INTEGRITY_CHECK_RESPONSE',
49
- payload: INTEGRITY_CHECKSUM,
50
- })
51
- break
52
- }
53
-
54
- case 'MOCK_ACTIVATE': {
55
- activeClientIds.add(clientId)
56
-
57
- sendToClient(client, {
58
- type: 'MOCKING_ENABLED',
59
- payload: true,
60
- })
61
- break
62
- }
63
-
64
- case 'MOCK_DEACTIVATE': {
65
- activeClientIds.delete(clientId)
66
- break
67
- }
68
-
69
- case 'CLIENT_CLOSED': {
70
- activeClientIds.delete(clientId)
71
-
72
- const remainingClients = allClients.filter((client) => {
73
- return client.id !== clientId
74
- })
75
-
76
- // Unregister itself when there are no more clients
77
- if (remainingClients.length === 0) {
78
- self.registration.unregister()
79
- }
80
-
81
- break
82
- }
83
- }
84
- })
85
-
86
- // Resolve the "main" client for the given event.
87
- // Client that issues a request doesn't necessarily equal the client
88
- // that registered the worker. It's with the latter the worker should
89
- // communicate with during the response resolving phase.
90
- async function resolveMainClient(event) {
91
- const client = await self.clients.get(event.clientId)
92
-
93
- if (client.frameType === 'top-level') {
94
- return client
95
- }
96
-
97
- const allClients = await self.clients.matchAll()
98
-
99
- return allClients
100
- .filter((client) => {
101
- // Get only those clients that are currently visible.
102
- return client.visibilityState === 'visible'
103
- })
104
- .find((client) => {
105
- // Find the client ID that's recorded in the
106
- // set of clients that have registered the worker.
107
- return activeClientIds.has(client.id)
108
- })
109
- }
110
-
111
- async function handleRequest(event, requestId) {
112
- const client = await resolveMainClient(event)
113
- const response = await getResponse(event, client, requestId)
114
-
115
- // Send back the response clone for the "response:*" life-cycle events.
116
- // Ensure MSW is active and ready to handle the message, otherwise
117
- // this message will pend indefinitely.
118
- if (client && activeClientIds.has(client.id)) {
119
- ;(async function () {
120
- const clonedResponse = response.clone()
121
- sendToClient(client, {
122
- type: 'RESPONSE',
123
- payload: {
124
- requestId,
125
- type: clonedResponse.type,
126
- ok: clonedResponse.ok,
127
- status: clonedResponse.status,
128
- statusText: clonedResponse.statusText,
129
- body:
130
- clonedResponse.body === null ? null : await clonedResponse.text(),
131
- headers: serializeHeaders(clonedResponse.headers),
132
- redirected: clonedResponse.redirected,
133
- },
134
- })
135
- })()
136
- }
137
-
138
- return response
139
- }
140
-
141
- async function getResponse(event, client, requestId) {
142
- const { request } = event
143
- const requestClone = request.clone()
144
- const getOriginalResponse = () => fetch(requestClone)
145
-
146
- // Bypass mocking when the request client is not active.
147
- if (!client) {
148
- return getOriginalResponse()
149
- }
150
-
151
- // Bypass initial page load requests (i.e. static assets).
152
- // The absence of the immediate/parent client in the map of the active clients
153
- // means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
154
- // and is not ready to handle requests.
155
- if (!activeClientIds.has(client.id)) {
156
- return await getOriginalResponse()
157
- }
158
-
159
- // Bypass requests with the explicit bypass header
160
- if (requestClone.headers.get(bypassHeaderName) === 'true') {
161
- const cleanRequestHeaders = serializeHeaders(requestClone.headers)
162
-
163
- // Remove the bypass header to comply with the CORS preflight check.
164
- delete cleanRequestHeaders[bypassHeaderName]
165
-
166
- const originalRequest = new Request(requestClone, {
167
- headers: new Headers(cleanRequestHeaders),
168
- })
169
-
170
- return fetch(originalRequest)
171
- }
172
-
173
- // Send the request to the client-side MSW.
174
- const reqHeaders = serializeHeaders(request.headers)
175
- const body = await request.text()
176
-
177
- const clientMessage = await sendToClient(client, {
178
- type: 'REQUEST',
179
- payload: {
180
- id: requestId,
181
- url: request.url,
182
- method: request.method,
183
- headers: reqHeaders,
184
- cache: request.cache,
185
- mode: request.mode,
186
- credentials: request.credentials,
187
- destination: request.destination,
188
- integrity: request.integrity,
189
- redirect: request.redirect,
190
- referrer: request.referrer,
191
- referrerPolicy: request.referrerPolicy,
192
- body,
193
- bodyUsed: request.bodyUsed,
194
- keepalive: request.keepalive,
195
- },
196
- })
197
-
198
- switch (clientMessage.type) {
199
- case 'MOCK_SUCCESS': {
200
- return delayPromise(
201
- () => respondWithMock(clientMessage),
202
- clientMessage.payload.delay,
203
- )
204
- }
205
-
206
- case 'MOCK_NOT_FOUND': {
207
- return getOriginalResponse()
208
- }
209
-
210
- case 'NETWORK_ERROR': {
211
- const { name, message } = clientMessage.payload
212
- const networkError = new Error(message)
213
- networkError.name = name
214
-
215
- // Rejecting a request Promise emulates a network error.
216
- throw networkError
217
- }
218
-
219
- case 'INTERNAL_ERROR': {
220
- const parsedBody = JSON.parse(clientMessage.payload.body)
221
-
222
- console.error(
223
- `\
224
- [MSW] Uncaught exception in the request handler for "%s %s":
225
-
226
- ${parsedBody.location}
227
-
228
- This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
229
- `,
230
- request.method,
231
- request.url,
232
- )
233
-
234
- return respondWithMock(clientMessage)
235
- }
236
- }
237
-
238
- return getOriginalResponse()
239
- }
240
-
241
- self.addEventListener('fetch', function (event) {
242
- const { request } = event
243
- const accept = request.headers.get('accept') || ''
244
-
245
- // Bypass server-sent events.
246
- if (accept.includes('text/event-stream')) {
247
- return
248
- }
249
-
250
- // Bypass navigation requests.
251
- if (request.mode === 'navigate') {
252
- return
253
- }
254
-
255
- // Opening the DevTools triggers the "only-if-cached" request
256
- // that cannot be handled by the worker. Bypass such requests.
257
- if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
258
- return
259
- }
260
-
261
- // Bypass all requests when there are no active clients.
262
- // Prevents the self-unregistered worked from handling requests
263
- // after it's been deleted (still remains active until the next reload).
264
- if (activeClientIds.size === 0) {
265
- return
266
- }
267
-
268
- const requestId = uuidv4()
269
-
270
- return event.respondWith(
271
- handleRequest(event, requestId).catch((error) => {
272
- if (error.name === 'NetworkError') {
273
- console.warn(
274
- '[MSW] Successfully emulated a network error for the "%s %s" request.',
275
- request.method,
276
- request.url,
277
- )
278
- return
279
- }
280
-
281
- // At this point, any exception indicates an issue with the original request/response.
282
- console.error(
283
- `\
284
- [MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`,
285
- request.method,
286
- request.url,
287
- `${error.name}: ${error.message}`,
288
- )
289
- }),
290
- )
291
- })
292
-
293
- function serializeHeaders(headers) {
294
- const reqHeaders = {}
295
- headers.forEach((value, name) => {
296
- reqHeaders[name] = reqHeaders[name]
297
- ? [].concat(reqHeaders[name]).concat(value)
298
- : value
299
- })
300
- return reqHeaders
301
- }
302
-
303
- function sendToClient(client, message) {
304
- return new Promise((resolve, reject) => {
305
- const channel = new MessageChannel()
306
-
307
- channel.port1.onmessage = (event) => {
308
- if (event.data && event.data.error) {
309
- return reject(event.data.error)
310
- }
311
-
312
- resolve(event.data)
313
- }
314
-
315
- client.postMessage(JSON.stringify(message), [channel.port2])
316
- })
317
- }
318
-
319
- function delayPromise(cb, duration) {
320
- return new Promise((resolve) => {
321
- setTimeout(() => resolve(cb()), duration)
322
- })
323
- }
324
-
325
- function respondWithMock(clientMessage) {
326
- return new Response(clientMessage.payload.body, {
327
- ...clientMessage.payload,
328
- headers: clientMessage.payload.headers,
329
- })
330
- }
331
-
332
- function uuidv4() {
333
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
334
- const r = (Math.random() * 16) | 0
335
- const v = c == 'x' ? r : (r & 0x3) | 0x8
336
- return v.toString(16)
337
- })
338
- }
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+
4
+ /**
5
+ * Mock Service Worker (1.3.2).
6
+ * @see https://github.com/mswjs/msw
7
+ * - Please do NOT modify this file.
8
+ * - Please do NOT serve this file on production.
9
+ */
10
+
11
+ const INTEGRITY_CHECKSUM = '3d6b9f06410d179a7f7404d4bf4c3c70'
12
+ const activeClientIds = new Set()
13
+
14
+ self.addEventListener('install', function () {
15
+ self.skipWaiting()
16
+ })
17
+
18
+ self.addEventListener('activate', function (event) {
19
+ event.waitUntil(self.clients.claim())
20
+ })
21
+
22
+ self.addEventListener('message', async function (event) {
23
+ const clientId = event.source.id
24
+
25
+ if (!clientId || !self.clients) {
26
+ return
27
+ }
28
+
29
+ const client = await self.clients.get(clientId)
30
+
31
+ if (!client) {
32
+ return
33
+ }
34
+
35
+ const allClients = await self.clients.matchAll({
36
+ type: 'window',
37
+ })
38
+
39
+ switch (event.data) {
40
+ case 'KEEPALIVE_REQUEST': {
41
+ sendToClient(client, {
42
+ type: 'KEEPALIVE_RESPONSE',
43
+ })
44
+ break
45
+ }
46
+
47
+ case 'INTEGRITY_CHECK_REQUEST': {
48
+ sendToClient(client, {
49
+ type: 'INTEGRITY_CHECK_RESPONSE',
50
+ payload: INTEGRITY_CHECKSUM,
51
+ })
52
+ break
53
+ }
54
+
55
+ case 'MOCK_ACTIVATE': {
56
+ activeClientIds.add(clientId)
57
+
58
+ sendToClient(client, {
59
+ type: 'MOCKING_ENABLED',
60
+ payload: true,
61
+ })
62
+ break
63
+ }
64
+
65
+ case 'MOCK_DEACTIVATE': {
66
+ activeClientIds.delete(clientId)
67
+ break
68
+ }
69
+
70
+ case 'CLIENT_CLOSED': {
71
+ activeClientIds.delete(clientId)
72
+
73
+ const remainingClients = allClients.filter((client) => {
74
+ return client.id !== clientId
75
+ })
76
+
77
+ // Unregister itself when there are no more clients
78
+ if (remainingClients.length === 0) {
79
+ self.registration.unregister()
80
+ }
81
+
82
+ break
83
+ }
84
+ }
85
+ })
86
+
87
+ self.addEventListener('fetch', function (event) {
88
+ const { request } = event
89
+ const accept = request.headers.get('accept') || ''
90
+
91
+ // Bypass server-sent events.
92
+ if (accept.includes('text/event-stream')) {
93
+ return
94
+ }
95
+
96
+ // Bypass navigation requests.
97
+ if (request.mode === 'navigate') {
98
+ return
99
+ }
100
+
101
+ // Opening the DevTools triggers the "only-if-cached" request
102
+ // that cannot be handled by the worker. Bypass such requests.
103
+ if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
104
+ return
105
+ }
106
+
107
+ // Bypass all requests when there are no active clients.
108
+ // Prevents the self-unregistered worked from handling requests
109
+ // after it's been deleted (still remains active until the next reload).
110
+ if (activeClientIds.size === 0) {
111
+ return
112
+ }
113
+
114
+ // Generate unique request ID.
115
+ const requestId = Math.random().toString(16).slice(2)
116
+
117
+ event.respondWith(
118
+ handleRequest(event, requestId).catch((error) => {
119
+ if (error.name === 'NetworkError') {
120
+ console.warn(
121
+ '[MSW] Successfully emulated a network error for the "%s %s" request.',
122
+ request.method,
123
+ request.url,
124
+ )
125
+ return
126
+ }
127
+
128
+ // At this point, any exception indicates an issue with the original request/response.
129
+ console.error(
130
+ `\
131
+ [MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`,
132
+ request.method,
133
+ request.url,
134
+ `${error.name}: ${error.message}`,
135
+ )
136
+ }),
137
+ )
138
+ })
139
+
140
+ async function handleRequest(event, requestId) {
141
+ const client = await resolveMainClient(event)
142
+ const response = await getResponse(event, client, requestId)
143
+
144
+ // Send back the response clone for the "response:*" life-cycle events.
145
+ // Ensure MSW is active and ready to handle the message, otherwise
146
+ // this message will pend indefinitely.
147
+ if (client && activeClientIds.has(client.id)) {
148
+ ;(async function () {
149
+ const clonedResponse = response.clone()
150
+ sendToClient(client, {
151
+ type: 'RESPONSE',
152
+ payload: {
153
+ requestId,
154
+ type: clonedResponse.type,
155
+ ok: clonedResponse.ok,
156
+ status: clonedResponse.status,
157
+ statusText: clonedResponse.statusText,
158
+ body:
159
+ clonedResponse.body === null ? null : await clonedResponse.text(),
160
+ headers: Object.fromEntries(clonedResponse.headers.entries()),
161
+ redirected: clonedResponse.redirected,
162
+ },
163
+ })
164
+ })()
165
+ }
166
+
167
+ return response
168
+ }
169
+
170
+ // Resolve the main client for the given event.
171
+ // Client that issues a request doesn't necessarily equal the client
172
+ // that registered the worker. It's with the latter the worker should
173
+ // communicate with during the response resolving phase.
174
+ async function resolveMainClient(event) {
175
+ const client = await self.clients.get(event.clientId)
176
+
177
+ if (client?.frameType === 'top-level') {
178
+ return client
179
+ }
180
+
181
+ const allClients = await self.clients.matchAll({
182
+ type: 'window',
183
+ })
184
+
185
+ return allClients
186
+ .filter((client) => {
187
+ // Get only those clients that are currently visible.
188
+ return client.visibilityState === 'visible'
189
+ })
190
+ .find((client) => {
191
+ // Find the client ID that's recorded in the
192
+ // set of clients that have registered the worker.
193
+ return activeClientIds.has(client.id)
194
+ })
195
+ }
196
+
197
+ async function getResponse(event, client, requestId) {
198
+ const { request } = event
199
+ const clonedRequest = request.clone()
200
+
201
+ function passthrough() {
202
+ // Clone the request because it might've been already used
203
+ // (i.e. its body has been read and sent to the client).
204
+ const headers = Object.fromEntries(clonedRequest.headers.entries())
205
+
206
+ // Remove MSW-specific request headers so the bypassed requests
207
+ // comply with the server's CORS preflight check.
208
+ // Operate with the headers as an object because request "Headers"
209
+ // are immutable.
210
+ delete headers['x-msw-bypass']
211
+
212
+ return fetch(clonedRequest, { headers })
213
+ }
214
+
215
+ // Bypass mocking when the client is not active.
216
+ if (!client) {
217
+ return passthrough()
218
+ }
219
+
220
+ // Bypass initial page load requests (i.e. static assets).
221
+ // The absence of the immediate/parent client in the map of the active clients
222
+ // means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
223
+ // and is not ready to handle requests.
224
+ if (!activeClientIds.has(client.id)) {
225
+ return passthrough()
226
+ }
227
+
228
+ // Bypass requests with the explicit bypass header.
229
+ // Such requests can be issued by "ctx.fetch()".
230
+ if (request.headers.get('x-msw-bypass') === 'true') {
231
+ return passthrough()
232
+ }
233
+
234
+ // Notify the client that a request has been intercepted.
235
+ const clientMessage = await sendToClient(client, {
236
+ type: 'REQUEST',
237
+ payload: {
238
+ id: requestId,
239
+ url: request.url,
240
+ method: request.method,
241
+ headers: Object.fromEntries(request.headers.entries()),
242
+ cache: request.cache,
243
+ mode: request.mode,
244
+ credentials: request.credentials,
245
+ destination: request.destination,
246
+ integrity: request.integrity,
247
+ redirect: request.redirect,
248
+ referrer: request.referrer,
249
+ referrerPolicy: request.referrerPolicy,
250
+ body: await request.text(),
251
+ bodyUsed: request.bodyUsed,
252
+ keepalive: request.keepalive,
253
+ },
254
+ })
255
+
256
+ switch (clientMessage.type) {
257
+ case 'MOCK_RESPONSE': {
258
+ return respondWithMock(clientMessage.data)
259
+ }
260
+
261
+ case 'MOCK_NOT_FOUND': {
262
+ return passthrough()
263
+ }
264
+
265
+ case 'NETWORK_ERROR': {
266
+ const { name, message } = clientMessage.data
267
+ const networkError = new Error(message)
268
+ networkError.name = name
269
+
270
+ // Rejecting a "respondWith" promise emulates a network error.
271
+ throw networkError
272
+ }
273
+ }
274
+
275
+ return passthrough()
276
+ }
277
+
278
+ function sendToClient(client, message) {
279
+ return new Promise((resolve, reject) => {
280
+ const channel = new MessageChannel()
281
+
282
+ channel.port1.onmessage = (event) => {
283
+ if (event.data && event.data.error) {
284
+ return reject(event.data.error)
285
+ }
286
+
287
+ resolve(event.data)
288
+ }
289
+
290
+ client.postMessage(message, [channel.port2])
291
+ })
292
+ }
293
+
294
+ function sleep(timeMs) {
295
+ return new Promise((resolve) => {
296
+ setTimeout(resolve, timeMs)
297
+ })
298
+ }
299
+
300
+ async function respondWithMock(response) {
301
+ await sleep(response.delay)
302
+ return new Response(response.body, response)
303
+ }