@doist/todoist-api-typescript 6.2.0 → 6.2.1

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,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __rest = (this && this.__rest) || function (s, e) {
3
36
  var t = {};
4
37
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -12,7 +45,6 @@ var __rest = (this && this.__rest) || function (s, e) {
12
45
  };
13
46
  Object.defineProperty(exports, "__esModule", { value: true });
14
47
  exports.fetchWithRetry = fetchWithRetry;
15
- const undici_1 = require("undici");
16
48
  const http_1 = require("../types/http");
17
49
  /**
18
50
  * Default retry configuration matching the original axios-retry behavior
@@ -27,13 +59,32 @@ const DEFAULT_RETRY_CONFIG = {
27
59
  },
28
60
  };
29
61
  /**
30
- * HTTP agent with keepAlive disabled to prevent hanging connections
31
- * This ensures the process exits immediately after requests complete
62
+ * Cached HTTP agent to prevent creating multiple agents
63
+ * null = not initialized, undefined = browser env, UndiciAgent = Node.js env
32
64
  */
33
- const httpAgent = new undici_1.Agent({
34
- keepAliveTimeout: 1, // Close connections after 1ms of idle time
35
- keepAliveMaxTimeout: 1, // Maximum time to keep connections alive
36
- });
65
+ let httpAgent = null;
66
+ /**
67
+ * Gets the HTTP agent for Node.js environments or undefined for browser environments.
68
+ * Uses dynamic import to avoid loading undici in browser environments.
69
+ */
70
+ async function getHttpAgent() {
71
+ var _a;
72
+ if (httpAgent === null) {
73
+ if (typeof process !== 'undefined' && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
74
+ // We're in Node.js - dynamically import undici
75
+ const { Agent } = await Promise.resolve().then(() => __importStar(require('undici')));
76
+ httpAgent = new Agent({
77
+ keepAliveTimeout: 1, // Close connections after 1ms of idle time
78
+ keepAliveMaxTimeout: 1, // Maximum time to keep connections alive
79
+ });
80
+ }
81
+ else {
82
+ // We're in browser - no agent needed
83
+ httpAgent = undefined;
84
+ }
85
+ }
86
+ return httpAgent;
87
+ }
37
88
  /**
38
89
  * Converts Headers object to a plain object
39
90
  */
@@ -118,7 +169,7 @@ async function fetchWithRetry(args) {
118
169
  else {
119
170
  const nativeResponse = await fetch(url, Object.assign(Object.assign({}, fetchOptions), { signal: requestSignal,
120
171
  // @ts-expect-error - dispatcher is a valid option for Node.js fetch but not in the TS types
121
- dispatcher: httpAgent }));
172
+ dispatcher: await getHttpAgent() }));
122
173
  fetchResponse = convertResponseToCustomFetch(nativeResponse);
123
174
  }
124
175
  // Check if the response is successful
@@ -9,7 +9,6 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { Agent } from 'undici';
13
12
  import { isNetworkError } from '../types/http.js';
14
13
  /**
15
14
  * Default retry configuration matching the original axios-retry behavior
@@ -24,13 +23,32 @@ const DEFAULT_RETRY_CONFIG = {
24
23
  },
25
24
  };
26
25
  /**
27
- * HTTP agent with keepAlive disabled to prevent hanging connections
28
- * This ensures the process exits immediately after requests complete
26
+ * Cached HTTP agent to prevent creating multiple agents
27
+ * null = not initialized, undefined = browser env, UndiciAgent = Node.js env
29
28
  */
30
- const httpAgent = new Agent({
31
- keepAliveTimeout: 1, // Close connections after 1ms of idle time
32
- keepAliveMaxTimeout: 1, // Maximum time to keep connections alive
33
- });
29
+ let httpAgent = null;
30
+ /**
31
+ * Gets the HTTP agent for Node.js environments or undefined for browser environments.
32
+ * Uses dynamic import to avoid loading undici in browser environments.
33
+ */
34
+ async function getHttpAgent() {
35
+ var _a;
36
+ if (httpAgent === null) {
37
+ if (typeof process !== 'undefined' && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
38
+ // We're in Node.js - dynamically import undici
39
+ const { Agent } = await import('undici');
40
+ httpAgent = new Agent({
41
+ keepAliveTimeout: 1, // Close connections after 1ms of idle time
42
+ keepAliveMaxTimeout: 1, // Maximum time to keep connections alive
43
+ });
44
+ }
45
+ else {
46
+ // We're in browser - no agent needed
47
+ httpAgent = undefined;
48
+ }
49
+ }
50
+ return httpAgent;
51
+ }
34
52
  /**
35
53
  * Converts Headers object to a plain object
36
54
  */
@@ -115,7 +133,7 @@ export async function fetchWithRetry(args) {
115
133
  else {
116
134
  const nativeResponse = await fetch(url, Object.assign(Object.assign({}, fetchOptions), { signal: requestSignal,
117
135
  // @ts-expect-error - dispatcher is a valid option for Node.js fetch but not in the TS types
118
- dispatcher: httpAgent }));
136
+ dispatcher: await getHttpAgent() }));
119
137
  fetchResponse = convertResponseToCustomFetch(nativeResponse);
120
138
  }
121
139
  // Check if the response is successful
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/todoist-api-typescript",
3
- "version": "6.2.0",
3
+ "version": "6.2.1",
4
4
  "description": "A typescript wrapper for the Todoist REST API.",
5
5
  "author": "Doist developers",
6
6
  "repository": "https://github.com/Doist/todoist-api-typescript",