@naturalcycles/js-lib 14.123.1 → 14.123.3

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.
@@ -24,6 +24,9 @@ const defRetryOptions = {
24
24
  */
25
25
  class Fetcher {
26
26
  constructor(cfg = {}) {
27
+ if (typeof globalThis.fetch !== 'function') {
28
+ throw new TypeError(`globalThis.fetch is not available`);
29
+ }
27
30
  this.cfg = this.normalizeCfg(cfg);
28
31
  // Dynamically create all helper methods
29
32
  http_model_1.HTTP_METHODS.forEach(method => {
@@ -112,7 +115,7 @@ class Fetcher {
112
115
  const started = Date.now();
113
116
  if (this.cfg.logRequest) {
114
117
  const { retryAttempt } = res.retryStatus;
115
- logger.log([' >>', signature, retryAttempt && `try#${retryAttempt + 1}/${req.retry.count}`]
118
+ logger.log([' >>', signature, retryAttempt && `try#${retryAttempt + 1}/${req.retry.count + 1}`]
116
119
  .filter(Boolean)
117
120
  .join(' '));
118
121
  if (this.cfg.logRequestBody && req.init.body) {
@@ -144,7 +147,7 @@ class Fetcher {
144
147
  ' <<',
145
148
  res.fetchResponse.status,
146
149
  signature,
147
- retryAttempt && `try#${retryAttempt + 1}/${req.retry.count}`,
150
+ retryAttempt && `try#${retryAttempt + 1}/${req.retry.count + 1}`,
148
151
  (0, time_util_1._since)(started),
149
152
  ]
150
153
  .filter(Boolean)
@@ -22,6 +22,9 @@ const defRetryOptions = {
22
22
  */
23
23
  export class Fetcher {
24
24
  constructor(cfg = {}) {
25
+ if (typeof globalThis.fetch !== 'function') {
26
+ throw new TypeError(`globalThis.fetch is not available`);
27
+ }
25
28
  this.cfg = this.normalizeCfg(cfg);
26
29
  // Dynamically create all helper methods
27
30
  HTTP_METHODS.forEach(method => {
@@ -121,7 +124,7 @@ export class Fetcher {
121
124
  const started = Date.now();
122
125
  if (this.cfg.logRequest) {
123
126
  const { retryAttempt } = res.retryStatus;
124
- logger.log([' >>', signature, retryAttempt && `try#${retryAttempt + 1}/${req.retry.count}`]
127
+ logger.log([' >>', signature, retryAttempt && `try#${retryAttempt + 1}/${req.retry.count + 1}`]
125
128
  .filter(Boolean)
126
129
  .join(' '));
127
130
  if (this.cfg.logRequestBody && req.init.body) {
@@ -153,7 +156,7 @@ export class Fetcher {
153
156
  ' <<',
154
157
  res.fetchResponse.status,
155
158
  signature,
156
- retryAttempt && `try#${retryAttempt + 1}/${req.retry.count}`,
159
+ retryAttempt && `try#${retryAttempt + 1}/${req.retry.count + 1}`,
157
160
  _since(started),
158
161
  ]
159
162
  .filter(Boolean)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.123.1",
3
+ "version": "14.123.3",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -187,6 +187,10 @@ const defRetryOptions: FetcherRetryOptions = {
187
187
  */
188
188
  export class Fetcher {
189
189
  private constructor(cfg: FetcherCfg & FetcherOptions = {}) {
190
+ if (typeof globalThis.fetch !== 'function') {
191
+ throw new TypeError(`globalThis.fetch is not available`)
192
+ }
193
+
190
194
  this.cfg = this.normalizeCfg(cfg)
191
195
 
192
196
  // Dynamically create all helper methods
@@ -325,7 +329,7 @@ export class Fetcher {
325
329
  if (this.cfg.logRequest) {
326
330
  const { retryAttempt } = res.retryStatus
327
331
  logger.log(
328
- [' >>', signature, retryAttempt && `try#${retryAttempt + 1}/${req.retry.count}`]
332
+ [' >>', signature, retryAttempt && `try#${retryAttempt + 1}/${req.retry.count + 1}`]
329
333
  .filter(Boolean)
330
334
  .join(' '),
331
335
  )
@@ -361,7 +365,7 @@ export class Fetcher {
361
365
  ' <<',
362
366
  res.fetchResponse.status,
363
367
  signature,
364
- retryAttempt && `try#${retryAttempt + 1}/${req.retry.count}`,
368
+ retryAttempt && `try#${retryAttempt + 1}/${req.retry.count + 1}`,
365
369
  _since(started),
366
370
  ]
367
371
  .filter(Boolean)