@serwist/strategies 8.4.4 → 9.0.0-preview.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.
@@ -0,0 +1,545 @@
1
+ /*
2
+ Copyright 2020 Google LLC
3
+
4
+ Use of this source code is governed by an MIT-style
5
+ license that can be found in the LICENSE file or at
6
+ https://opensource.org/licenses/MIT.
7
+ */
8
+
9
+ import type { HandlerCallbackOptions, MapLikeObject, SerwistPlugin, SerwistPluginCallbackParam } from "@serwist/core";
10
+ import {
11
+ assert,
12
+ Deferred,
13
+ SerwistError,
14
+ cacheMatchIgnoreParams,
15
+ executeQuotaErrorCallbacks,
16
+ getFriendlyURL,
17
+ logger,
18
+ timeout,
19
+ } from "@serwist/core/internal";
20
+
21
+ import type { Strategy } from "./Strategy.js";
22
+
23
+ function toRequest(input: RequestInfo) {
24
+ return typeof input === "string" ? new Request(input) : input;
25
+ }
26
+
27
+ /**
28
+ * A class created every time a Strategy instance instance calls `Strategy.handle` or
29
+ * `Strategy.handleAll` that wraps all fetch and cache actions around plugin callbacks
30
+ * and keeps track of when the strategy is "done" (i.e. all added `event.waitUntil()` promises
31
+ * have resolved).
32
+ */
33
+ class StrategyHandler {
34
+ /**
35
+ * The request the strategy is performing (passed to the strategy's
36
+ * `handle()` or `handleAll()` method).
37
+ */
38
+ public request!: Request;
39
+ /**
40
+ * A `URL` instance of `request.url` (if passed to the strategy's
41
+ * `handle()` or `handleAll()` method).
42
+ * Note: the `url` param will be present if the strategy was invoked
43
+ * from a `@serwist/routing.Route` object.
44
+ */
45
+ public url?: URL;
46
+ /**
47
+ * The event associated with this request.
48
+ */
49
+ public event: ExtendableEvent;
50
+ /**
51
+ * A `param` value (if passed to the strategy's
52
+ * `handle()` or `handleAll()` method).
53
+ * Note: the `param` param will be present if the strategy was invoked
54
+ * from a `@serwist/routing.Route` object and the `@serwist/strategies.matchCallback`
55
+ * returned a truthy value (it will be that value).
56
+ */
57
+ public params?: any;
58
+
59
+ private _cacheKeys: Record<string, Request> = {};
60
+
61
+ private readonly _strategy: Strategy;
62
+ private readonly _extendLifetimePromises: Promise<any>[];
63
+ private readonly _handlerDeferred: Deferred<any>;
64
+ private readonly _plugins: SerwistPlugin[];
65
+ private readonly _pluginStateMap: Map<SerwistPlugin, MapLikeObject>;
66
+
67
+ /**
68
+ * Creates a new instance associated with the passed strategy and event
69
+ * that's handling the request.
70
+ *
71
+ * The constructor also initializes the state that will be passed to each of
72
+ * the plugins handling this request.
73
+ *
74
+ * @param strategy
75
+ * @param options
76
+ */
77
+ constructor(strategy: Strategy, options: HandlerCallbackOptions) {
78
+ if (process.env.NODE_ENV !== "production") {
79
+ assert!.isInstance(options.event, ExtendableEvent, {
80
+ moduleName: "@serwist/strategies",
81
+ className: "StrategyHandler",
82
+ funcName: "constructor",
83
+ paramName: "options.event",
84
+ });
85
+ }
86
+
87
+ Object.assign(this, options);
88
+
89
+ this.event = options.event;
90
+ this._strategy = strategy;
91
+ this._handlerDeferred = new Deferred();
92
+ this._extendLifetimePromises = [];
93
+
94
+ // Copy the plugins list (since it's mutable on the strategy),
95
+ // so any mutations don't affect this handler instance.
96
+ this._plugins = [...strategy.plugins];
97
+ this._pluginStateMap = new Map();
98
+ for (const plugin of this._plugins) {
99
+ this._pluginStateMap.set(plugin, {});
100
+ }
101
+
102
+ this.event.waitUntil(this._handlerDeferred.promise);
103
+ }
104
+
105
+ /**
106
+ * Fetches a given request (and invokes any applicable plugin callback
107
+ * methods) using the `fetchOptions` (for non-navigation requests) and
108
+ * `plugins` defined on the `Strategy` object.
109
+ *
110
+ * The following plugin lifecycle methods are invoked when using this method:
111
+ * - `requestWillFetch()`
112
+ * - `fetchDidSucceed()`
113
+ * - `fetchDidFail()`
114
+ *
115
+ * @param input The URL or request to fetch.
116
+ * @returns
117
+ */
118
+ async fetch(input: RequestInfo): Promise<Response> {
119
+ const { event } = this;
120
+ let request: Request = toRequest(input);
121
+
122
+ if (request.mode === "navigate" && event instanceof FetchEvent && event.preloadResponse) {
123
+ const possiblePreloadResponse = (await event.preloadResponse) as Response | undefined;
124
+ if (possiblePreloadResponse) {
125
+ if (process.env.NODE_ENV !== "production") {
126
+ logger.log(`Using a preloaded navigation response for '${getFriendlyURL(request.url)}'`);
127
+ }
128
+ return possiblePreloadResponse;
129
+ }
130
+ }
131
+
132
+ // If there is a fetchDidFail plugin, we need to save a clone of the
133
+ // original request before it's either modified by a requestWillFetch
134
+ // plugin or before the original request's body is consumed via fetch().
135
+ const originalRequest = this.hasCallback("fetchDidFail") ? request.clone() : null;
136
+
137
+ try {
138
+ for (const cb of this.iterateCallbacks("requestWillFetch")) {
139
+ request = await cb({ request: request.clone(), event });
140
+ }
141
+ } catch (err) {
142
+ if (err instanceof Error) {
143
+ throw new SerwistError("plugin-error-request-will-fetch", {
144
+ thrownErrorMessage: err.message,
145
+ });
146
+ }
147
+ }
148
+
149
+ // The request can be altered by plugins with `requestWillFetch` making
150
+ // the original request (most likely from a `fetch` event) different
151
+ // from the Request we make. Pass both to `fetchDidFail` to aid debugging.
152
+ const pluginFilteredRequest: Request = request.clone();
153
+
154
+ try {
155
+ let fetchResponse: Response;
156
+
157
+ // See https://github.com/GoogleChrome/workbox/issues/1796
158
+ fetchResponse = await fetch(request, request.mode === "navigate" ? undefined : this._strategy.fetchOptions);
159
+
160
+ if (process.env.NODE_ENV !== "production") {
161
+ logger.debug(`Network request for '${getFriendlyURL(request.url)}' returned a response with status '${fetchResponse.status}'.`);
162
+ }
163
+
164
+ for (const callback of this.iterateCallbacks("fetchDidSucceed")) {
165
+ fetchResponse = await callback({
166
+ event,
167
+ request: pluginFilteredRequest,
168
+ response: fetchResponse,
169
+ });
170
+ }
171
+ return fetchResponse;
172
+ } catch (error) {
173
+ if (process.env.NODE_ENV !== "production") {
174
+ logger.log(`Network request for '${getFriendlyURL(request.url)}' threw an error.`, error);
175
+ }
176
+
177
+ // `originalRequest` will only exist if a `fetchDidFail` callback
178
+ // is being used (see above).
179
+ if (originalRequest) {
180
+ await this.runCallbacks("fetchDidFail", {
181
+ error: error as Error,
182
+ event,
183
+ originalRequest: originalRequest.clone(),
184
+ request: pluginFilteredRequest.clone(),
185
+ });
186
+ }
187
+ throw error;
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Calls `this.fetch()` and (in the background) runs `this.cachePut()` on
193
+ * the response generated by `this.fetch()`.
194
+ *
195
+ * The call to `this.cachePut()` automatically invokes `this.waitUntil()`,
196
+ * so you do not have to manually call `waitUntil()` on the event.
197
+ *
198
+ * @param input The request or URL to fetch and cache.
199
+ * @returns
200
+ */
201
+ async fetchAndCachePut(input: RequestInfo): Promise<Response> {
202
+ const response = await this.fetch(input);
203
+ const responseClone = response.clone();
204
+
205
+ void this.waitUntil(this.cachePut(input, responseClone));
206
+
207
+ return response;
208
+ }
209
+
210
+ /**
211
+ * Matches a request from the cache (and invokes any applicable plugin
212
+ * callback methods) using the `cacheName`, `matchOptions`, and `plugins`
213
+ * defined on the strategy object.
214
+ *
215
+ * The following plugin lifecycle methods are invoked when using this method:
216
+ * - cacheKeyWillByUsed()
217
+ * - cachedResponseWillByUsed()
218
+ *
219
+ * @param key The Request or URL to use as the cache key.
220
+ * @returns A matching response, if found.
221
+ */
222
+ async cacheMatch(key: RequestInfo): Promise<Response | undefined> {
223
+ const request: Request = toRequest(key);
224
+ let cachedResponse: Response | undefined;
225
+ const { cacheName, matchOptions } = this._strategy;
226
+
227
+ const effectiveRequest = await this.getCacheKey(request, "read");
228
+ const multiMatchOptions = { ...matchOptions, ...{ cacheName } };
229
+
230
+ cachedResponse = await caches.match(effectiveRequest, multiMatchOptions);
231
+
232
+ if (process.env.NODE_ENV !== "production") {
233
+ if (cachedResponse) {
234
+ logger.debug(`Found a cached response in '${cacheName}'.`);
235
+ } else {
236
+ logger.debug(`No cached response found in '${cacheName}'.`);
237
+ }
238
+ }
239
+
240
+ for (const callback of this.iterateCallbacks("cachedResponseWillBeUsed")) {
241
+ cachedResponse =
242
+ (await callback({
243
+ cacheName,
244
+ matchOptions,
245
+ cachedResponse,
246
+ request: effectiveRequest,
247
+ event: this.event,
248
+ })) || undefined;
249
+ }
250
+ return cachedResponse;
251
+ }
252
+
253
+ /**
254
+ * Puts a request/response pair in the cache (and invokes any applicable
255
+ * plugin callback methods) using the `cacheName` and `plugins` defined on
256
+ * the strategy object.
257
+ *
258
+ * The following plugin lifecycle methods are invoked when using this method:
259
+ * - cacheKeyWillByUsed()
260
+ * - cacheWillUpdate()
261
+ * - cacheDidUpdate()
262
+ *
263
+ * @param key The request or URL to use as the cache key.
264
+ * @param response The response to cache.
265
+ * @returns `false` if a cacheWillUpdate caused the response
266
+ * not be cached, and `true` otherwise.
267
+ */
268
+ async cachePut(key: RequestInfo, response: Response): Promise<boolean> {
269
+ const request: Request = toRequest(key);
270
+
271
+ // Run in the next task to avoid blocking other cache reads.
272
+ // https://github.com/w3c/ServiceWorker/issues/1397
273
+ await timeout(0);
274
+
275
+ const effectiveRequest = await this.getCacheKey(request, "write");
276
+
277
+ if (process.env.NODE_ENV !== "production") {
278
+ if (effectiveRequest.method && effectiveRequest.method !== "GET") {
279
+ throw new SerwistError("attempt-to-cache-non-get-request", {
280
+ url: getFriendlyURL(effectiveRequest.url),
281
+ method: effectiveRequest.method,
282
+ });
283
+ }
284
+
285
+ // See https://github.com/GoogleChrome/workbox/issues/2818
286
+ const vary = response.headers.get("Vary");
287
+ if (vary) {
288
+ logger.debug(
289
+ `The response for ${getFriendlyURL(
290
+ effectiveRequest.url,
291
+ )} has a 'Vary: ${vary}' header. Consider setting the {ignoreVary: true} option on your strategy to ensure cache matching and deletion works as expected.`,
292
+ );
293
+ }
294
+ }
295
+
296
+ if (!response) {
297
+ if (process.env.NODE_ENV !== "production") {
298
+ logger.error(`Cannot cache non-existent response for '${getFriendlyURL(effectiveRequest.url)}'.`);
299
+ }
300
+
301
+ throw new SerwistError("cache-put-with-no-response", {
302
+ url: getFriendlyURL(effectiveRequest.url),
303
+ });
304
+ }
305
+
306
+ const responseToCache = await this._ensureResponseSafeToCache(response);
307
+
308
+ if (!responseToCache) {
309
+ if (process.env.NODE_ENV !== "production") {
310
+ logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will not be cached.`, responseToCache);
311
+ }
312
+ return false;
313
+ }
314
+
315
+ const { cacheName, matchOptions } = this._strategy;
316
+ const cache = await self.caches.open(cacheName);
317
+
318
+ const hasCacheUpdateCallback = this.hasCallback("cacheDidUpdate");
319
+ const oldResponse = hasCacheUpdateCallback
320
+ ? await cacheMatchIgnoreParams(
321
+ // TODO(philipwalton): the `__WB_REVISION__` param is a precaching
322
+ // feature. Consider into ways to only add this behavior if using
323
+ // precaching.
324
+ cache,
325
+ effectiveRequest.clone(),
326
+ ["__WB_REVISION__"],
327
+ matchOptions,
328
+ )
329
+ : null;
330
+
331
+ if (process.env.NODE_ENV !== "production") {
332
+ logger.debug(`Updating the '${cacheName}' cache with a new Response ` + `for ${getFriendlyURL(effectiveRequest.url)}.`);
333
+ }
334
+
335
+ try {
336
+ await cache.put(effectiveRequest, hasCacheUpdateCallback ? responseToCache.clone() : responseToCache);
337
+ } catch (error) {
338
+ if (error instanceof Error) {
339
+ // See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError
340
+ if (error.name === "QuotaExceededError") {
341
+ await executeQuotaErrorCallbacks();
342
+ }
343
+ throw error;
344
+ }
345
+ }
346
+
347
+ for (const callback of this.iterateCallbacks("cacheDidUpdate")) {
348
+ await callback({
349
+ cacheName,
350
+ oldResponse,
351
+ newResponse: responseToCache.clone(),
352
+ request: effectiveRequest,
353
+ event: this.event,
354
+ });
355
+ }
356
+
357
+ return true;
358
+ }
359
+
360
+ /**
361
+ * Checks the list of plugins for the `cacheKeyWillBeUsed` callback, and
362
+ * executes any of those callbacks found in sequence. The final `Request`
363
+ * object returned by the last plugin is treated as the cache key for cache
364
+ * reads and/or writes. If no `cacheKeyWillBeUsed` plugin callbacks have
365
+ * been registered, the passed request is returned unmodified
366
+ *
367
+ * @param request
368
+ * @param mode
369
+ * @returns
370
+ */
371
+ async getCacheKey(request: Request, mode: "read" | "write"): Promise<Request> {
372
+ const key = `${request.url} | ${mode}`;
373
+ if (!this._cacheKeys[key]) {
374
+ let effectiveRequest = request;
375
+
376
+ for (const callback of this.iterateCallbacks("cacheKeyWillBeUsed")) {
377
+ effectiveRequest = toRequest(
378
+ await callback({
379
+ mode,
380
+ request: effectiveRequest,
381
+ event: this.event,
382
+ // params has a type any can't change right now.
383
+ params: this.params, // eslint-disable-line
384
+ }),
385
+ );
386
+ }
387
+
388
+ this._cacheKeys[key] = effectiveRequest;
389
+ }
390
+ return this._cacheKeys[key];
391
+ }
392
+
393
+ /**
394
+ * Returns true if the strategy has at least one plugin with the given
395
+ * callback.
396
+ *
397
+ * @param name The name of the callback to check for.
398
+ * @returns
399
+ */
400
+ hasCallback<C extends keyof SerwistPlugin>(name: C): boolean {
401
+ for (const plugin of this._strategy.plugins) {
402
+ if (name in plugin) {
403
+ return true;
404
+ }
405
+ }
406
+ return false;
407
+ }
408
+
409
+ /**
410
+ * Runs all plugin callbacks matching the given name, in order, passing the
411
+ * given param object (merged ith the current plugin state) as the only
412
+ * argument.
413
+ *
414
+ * Note: since this method runs all plugins, it's not suitable for cases
415
+ * where the return value of a callback needs to be applied prior to calling
416
+ * the next callback. See `@serwist/strategies.iterateCallbacks` for how to handle that case.
417
+ *
418
+ * @param name The name of the callback to run within each plugin.
419
+ * @param param The object to pass as the first (and only) param when executing each callback. This object will be merged with the
420
+ * current plugin state prior to callback execution.
421
+ */
422
+ async runCallbacks<C extends keyof NonNullable<SerwistPlugin>>(name: C, param: Omit<SerwistPluginCallbackParam[C], "state">): Promise<void> {
423
+ for (const callback of this.iterateCallbacks(name)) {
424
+ // TODO(philipwalton): not sure why `any` is needed. It seems like
425
+ // this should work with `as SerwistPluginCallbackParam[C]`.
426
+ await callback(param as any);
427
+ }
428
+ }
429
+
430
+ /**
431
+ * Accepts a callback and returns an iterable of matching plugin callbacks,
432
+ * where each callback is wrapped with the current handler state (i.e. when
433
+ * you call each callback, whatever object parameter you pass it will
434
+ * be merged with the plugin's current state).
435
+ *
436
+ * @param name The name fo the callback to run
437
+ * @returns
438
+ */
439
+ *iterateCallbacks<C extends keyof SerwistPlugin>(name: C): Generator<NonNullable<SerwistPlugin[C]>> {
440
+ for (const plugin of this._strategy.plugins) {
441
+ if (typeof plugin[name] === "function") {
442
+ const state = this._pluginStateMap.get(plugin);
443
+ const statefulCallback = (param: Omit<SerwistPluginCallbackParam[C], "state">) => {
444
+ const statefulParam = { ...param, state };
445
+
446
+ // TODO(philipwalton): not sure why `any` is needed. It seems like
447
+ // this should work with `as WorkboxPluginCallbackParam[C]`.
448
+ return plugin[name]!(statefulParam as any);
449
+ };
450
+ yield statefulCallback as NonNullable<SerwistPlugin[C]>;
451
+ }
452
+ }
453
+ }
454
+
455
+ /**
456
+ * Adds a promise to the
457
+ * [extend lifetime promises](https://w3c.github.io/ServiceWorker/#extendableevent-extend-lifetime-promises)
458
+ * of the event event associated with the request being handled (usually a `FetchEvent`).
459
+ *
460
+ * Note: you can await
461
+ * `@serwist/strategies.StrategyHandler.doneWaiting`
462
+ * to know when all added promises have settled.
463
+ *
464
+ * @param promise A promise to add to the extend lifetime promises of
465
+ * the event that triggered the request.
466
+ */
467
+ waitUntil<T>(promise: Promise<T>): Promise<T> {
468
+ this._extendLifetimePromises.push(promise);
469
+ return promise;
470
+ }
471
+
472
+ /**
473
+ * Returns a promise that resolves once all promises passed to
474
+ * `@serwist/strategies.StrategyHandler.waitUntil` have settled.
475
+ *
476
+ * Note: any work done after `doneWaiting()` settles should be manually
477
+ * passed to an event's `waitUntil()` method (not this handler's
478
+ * `waitUntil()` method), otherwise the service worker thread my be killed
479
+ * prior to your work completing.
480
+ */
481
+ async doneWaiting(): Promise<void> {
482
+ let promise: Promise<any> | undefined = undefined;
483
+ while ((promise = this._extendLifetimePromises.shift())) {
484
+ await promise;
485
+ }
486
+ }
487
+
488
+ /**
489
+ * Stops running the strategy and immediately resolves any pending
490
+ * `waitUntil()` promises.
491
+ */
492
+ destroy(): void {
493
+ this._handlerDeferred.resolve(null);
494
+ }
495
+
496
+ /**
497
+ * This method will call `cacheWillUpdate` on the available plugins (or use
498
+ * status === 200) to determine if the response is safe and valid to cache.
499
+ *
500
+ * @param response
501
+ * @returns
502
+ * @private
503
+ */
504
+ async _ensureResponseSafeToCache(response: Response): Promise<Response | undefined> {
505
+ let responseToCache: Response | undefined = response;
506
+ let pluginsUsed = false;
507
+
508
+ for (const callback of this.iterateCallbacks("cacheWillUpdate")) {
509
+ responseToCache =
510
+ (await callback({
511
+ request: this.request,
512
+ response: responseToCache,
513
+ event: this.event,
514
+ })) || undefined;
515
+ pluginsUsed = true;
516
+
517
+ if (!responseToCache) {
518
+ break;
519
+ }
520
+ }
521
+
522
+ if (!pluginsUsed) {
523
+ if (responseToCache && responseToCache.status !== 200) {
524
+ responseToCache = undefined;
525
+ }
526
+ if (process.env.NODE_ENV !== "production") {
527
+ if (responseToCache) {
528
+ if (responseToCache.status !== 200) {
529
+ if (responseToCache.status === 0) {
530
+ logger.warn(
531
+ `The response for '${this.request.url}' is an opaque response. The caching strategy that you're using will not cache opaque responses by default.`,
532
+ );
533
+ } else {
534
+ logger.debug(`The response for '${this.request.url}' returned a status code of '${response.status}' and won't be cached as a result.`);
535
+ }
536
+ }
537
+ }
538
+ }
539
+ }
540
+
541
+ return responseToCache;
542
+ }
543
+ }
544
+
545
+ export { StrategyHandler };
@@ -1,3 +1,11 @@
1
+ /*
2
+ Copyright 2018 Google LLC
3
+
4
+ Use of this source code is governed by an MIT-style
5
+ license that can be found in the LICENSE file or at
6
+ https://opensource.org/licenses/MIT.
7
+ */
8
+
1
9
  import { CacheFirst } from "./CacheFirst.js";
2
10
  import { CacheOnly } from "./CacheOnly.js";
3
11
  import type { NetworkFirstOptions } from "./NetworkFirst.js";
@@ -8,14 +16,19 @@ import { StaleWhileRevalidate } from "./StaleWhileRevalidate.js";
8
16
  import type { StrategyOptions } from "./Strategy.js";
9
17
  import { Strategy } from "./Strategy.js";
10
18
  import { StrategyHandler } from "./StrategyHandler.js";
19
+
20
+ // See https://github.com/GoogleChrome/workbox/issues/2946
11
21
  declare global {
12
- interface FetchEvent {
13
- readonly preloadResponse: Promise<any>;
14
- }
22
+ interface FetchEvent {
23
+ // See https://github.com/GoogleChrome/workbox/issues/2974
24
+ readonly preloadResponse: Promise<any>;
25
+ }
15
26
  }
27
+
16
28
  /**
17
29
  * There are common caching strategies that most service workers will need
18
30
  * and use. This module provides simple implementations of these strategies.
19
31
  */
20
32
  export { CacheFirst, CacheOnly, NetworkFirst, NetworkOnly, StaleWhileRevalidate, Strategy, StrategyHandler };
33
+
21
34
  export type { NetworkFirstOptions, NetworkOnlyOptions, StrategyOptions };
@@ -0,0 +1,26 @@
1
+ /*
2
+ Copyright 2018 Google LLC
3
+
4
+ Use of this source code is governed by an MIT-style
5
+ license that can be found in the LICENSE file or at
6
+ https://opensource.org/licenses/MIT.
7
+ */
8
+
9
+ import type { SerwistPlugin } from "@serwist/core";
10
+
11
+ export const cacheOkAndOpaquePlugin: SerwistPlugin = {
12
+ /**
13
+ * Returns a valid response (to allow caching) if the status is 200 (OK) or
14
+ * 0 (opaque).
15
+ *
16
+ * @param options
17
+ * @returns
18
+ * @private
19
+ */
20
+ cacheWillUpdate: async ({ response }) => {
21
+ if (response.status === 200 || response.status === 0) {
22
+ return response;
23
+ }
24
+ return null;
25
+ },
26
+ };
@@ -0,0 +1,20 @@
1
+ /*
2
+ Copyright 2018 Google LLC
3
+
4
+ Use of this source code is governed by an MIT-style
5
+ license that can be found in the LICENSE file or at
6
+ https://opensource.org/licenses/MIT.
7
+ */
8
+
9
+ import { getFriendlyURL, logger } from "@serwist/core/internal";
10
+
11
+ export const messages = {
12
+ strategyStart: (strategyName: string, request: Request): string => `Using ${strategyName} to respond to '${getFriendlyURL(request.url)}'`,
13
+ printFinalResponse: (response?: Response): void => {
14
+ if (response) {
15
+ logger.groupCollapsed("View the final response here.");
16
+ logger.log(response || "[No response returned]");
17
+ logger.groupEnd();
18
+ }
19
+ },
20
+ };