@budibase/backend-core 3.23.38 → 3.23.48

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,80 +1,155 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProxyDispatcher = getProxyDispatcher;
4
- exports.resetProxyDispatcherCache = resetProxyDispatcherCache;
3
+ exports.getDispatcher = getDispatcher;
5
4
  const undici_1 = require("undici");
6
5
  /**
7
- * Creates a fetch dispatcher (ProxyAgent) that respects global-agent environment variables.
8
- * This is necessary because Node.js's native fetch uses undici which doesn't respect
9
- * the global-agent proxy configuration.
6
+ * Check if a URL matches any pattern in the NO_PROXY list.
7
+ * Supports patterns like: *.foo.com, baz.com, .example.com
10
8
  *
11
- * @param options Optional configuration for the ProxyAgent
12
- * @returns ProxyAgent if proxy is configured, undefined otherwise
9
+ * @param url The URL to check
10
+ * @param noProxy Comma or space separated list of NO_PROXY patterns
11
+ * @returns true if the URL should bypass the proxy
13
12
  */
14
- function createProxyDispatcher(options) {
13
+ function isUrlMatchingNoProxy(url, noProxy) {
14
+ let hostname;
15
+ let port = null;
16
+ try {
17
+ const parsed = new URL(url);
18
+ hostname = parsed.hostname;
19
+ port = parsed.port || null;
20
+ }
21
+ catch (_a) {
22
+ return false;
23
+ }
24
+ const rules = noProxy.split(/[\s,]+/).filter(r => r.length > 0);
25
+ for (const rule of rules) {
26
+ // Handle leading dot (e.g., .foo.com) by converting to wildcard
27
+ const normalizedRule = rule.replace(/^\./, "*");
28
+ // Parse rule into hostname and optional port
29
+ // Match: hostname optionally followed by :port
30
+ const ruleMatch = normalizedRule.match(/^(.+?)(?::(\d+))?$/);
31
+ if (!ruleMatch || !ruleMatch[1]) {
32
+ continue;
33
+ }
34
+ const ruleHostname = ruleMatch[1].toLowerCase();
35
+ const rulePort = ruleMatch[2] || null;
36
+ // Check hostname match (supports wildcards like *.foo.com)
37
+ let hostnameMatches = false;
38
+ if (ruleHostname === "*") {
39
+ hostnameMatches = true;
40
+ }
41
+ else if (ruleHostname.startsWith("*")) {
42
+ // Wildcard pattern like *.foo.com
43
+ const suffix = ruleHostname.slice(1); // .foo.com
44
+ hostnameMatches =
45
+ hostname === suffix.slice(1) || hostname.endsWith(suffix);
46
+ }
47
+ else {
48
+ hostnameMatches = hostname === ruleHostname;
49
+ }
50
+ // Check port match (if rule specifies a port)
51
+ const portMatches = !rulePort || port === rulePort;
52
+ if (hostnameMatches && portMatches) {
53
+ return true;
54
+ }
55
+ }
56
+ return false;
57
+ }
58
+ /**
59
+ * Determines if the request should bypass the proxy.
60
+ *
61
+ * @param url The target URL
62
+ * @returns true if the request should go direct (no proxy)
63
+ */
64
+ function shouldBypassProxy(url) {
15
65
  const httpProxy = process.env.GLOBAL_AGENT_HTTP_PROXY || process.env.HTTP_PROXY;
16
66
  const httpsProxy = process.env.GLOBAL_AGENT_HTTPS_PROXY || process.env.HTTPS_PROXY;
17
67
  const proxyUrl = httpsProxy || httpProxy;
68
+ // No proxy configured
18
69
  if (!proxyUrl || !proxyUrl.trim()) {
19
- return false;
70
+ return true;
20
71
  }
21
- const trimmedProxyUrl = proxyUrl.trim();
22
- // Validate URL format
72
+ // Validate proxy URL format
23
73
  try {
24
- new URL(trimmedProxyUrl);
74
+ new URL(proxyUrl.trim());
25
75
  }
26
- catch (error) {
76
+ catch (_a) {
27
77
  console.log("[fetch] Invalid proxy URL format:", proxyUrl);
28
- return false;
78
+ return true;
79
+ }
80
+ // Check NO_PROXY patterns
81
+ if (url) {
82
+ const noProxy = process.env.GLOBAL_AGENT_NO_PROXY || process.env.NO_PROXY || "";
83
+ if (noProxy && isUrlMatchingNoProxy(url, noProxy)) {
84
+ console.log("[fetch] URL matches NO_PROXY pattern, bypassing proxy", {
85
+ url,
86
+ noProxy,
87
+ });
88
+ return true;
89
+ }
29
90
  }
30
- const rejectUnauthorized = (options === null || options === void 0 ? void 0 : options.rejectUnauthorized) !== undefined
31
- ? options === null || options === void 0 ? void 0 : options.rejectUnauthorized
32
- : true;
91
+ return false;
92
+ }
93
+ /**
94
+ * Creates a direct Agent (no proxy).
95
+ */
96
+ function createDirectAgent(rejectUnauthorized) {
97
+ return new undici_1.Agent({
98
+ connect: {
99
+ rejectUnauthorized,
100
+ },
101
+ });
102
+ }
103
+ /**
104
+ * Creates a ProxyAgent for proxied requests.
105
+ */
106
+ function createProxyAgent(rejectUnauthorized) {
107
+ const httpProxy = process.env.GLOBAL_AGENT_HTTP_PROXY || process.env.HTTP_PROXY;
108
+ const httpsProxy = process.env.GLOBAL_AGENT_HTTPS_PROXY || process.env.HTTPS_PROXY;
109
+ const proxyUrl = (httpsProxy || httpProxy).trim();
33
110
  console.log("[fetch] Creating ProxyAgent", {
34
- proxyUrl: trimmedProxyUrl,
111
+ proxyUrl,
35
112
  rejectUnauthorized,
36
113
  });
37
114
  const proxyConfig = {
38
- uri: trimmedProxyUrl,
115
+ uri: proxyUrl,
39
116
  requestTls: {
40
117
  rejectUnauthorized,
41
118
  },
42
119
  };
43
120
  // Only configure proxyTls if the proxy itself uses HTTPS
44
- if (trimmedProxyUrl.startsWith("https://")) {
121
+ if (proxyUrl.startsWith("https://")) {
45
122
  proxyConfig.proxyTls = {
46
123
  rejectUnauthorized,
47
124
  };
48
125
  }
49
- try {
50
- return new undici_1.ProxyAgent(proxyConfig);
51
- }
52
- catch (error) {
53
- console.log("[fetch] Failed to create ProxyAgent:", error);
54
- return false;
55
- }
126
+ return new undici_1.ProxyAgent(proxyConfig);
56
127
  }
57
- let cachedDispatcher = null;
58
128
  /**
59
- * Get or create a cached proxy dispatcher.
60
- * The dispatcher is cached to avoid creating a new ProxyAgent for every request.
129
+ * Creates a fetch dispatcher that respects global-agent environment variables.
130
+ * Always returns a usable Dispatcher - either a ProxyAgent or a direct Agent.
61
131
  *
62
- * @param options Optional configuration for the ProxyAgent
132
+ * @param options Configuration for the dispatcher
133
+ * @returns A Dispatcher (ProxyAgent for proxied requests, Agent for direct requests)
63
134
  */
64
- function getProxyDispatcher(options) {
65
- // Don't cache if custom options are provided
66
- if (options) {
67
- return createProxyDispatcher(options) || false;
68
- }
69
- if (cachedDispatcher === null) {
70
- cachedDispatcher = createProxyDispatcher();
135
+ function createDispatcher(options) {
136
+ var _a;
137
+ const rejectUnauthorized = (_a = options === null || options === void 0 ? void 0 : options.rejectUnauthorized) !== null && _a !== void 0 ? _a : true;
138
+ if (shouldBypassProxy(options === null || options === void 0 ? void 0 : options.url)) {
139
+ return createDirectAgent(rejectUnauthorized);
71
140
  }
72
- return cachedDispatcher || false;
141
+ return createProxyAgent(rejectUnauthorized);
73
142
  }
74
143
  /**
75
- * Reset the cached proxy dispatcher. Used for testing.
144
+ * Get a dispatcher for fetch requests.
145
+ * Always returns a usable Dispatcher - either a ProxyAgent or a direct Agent.
146
+ * The dispatcher respects GLOBAL_AGENT_HTTP_PROXY, GLOBAL_AGENT_HTTPS_PROXY,
147
+ * GLOBAL_AGENT_NO_PROXY, and their standard equivalents.
148
+ *
149
+ * @param options Configuration for the dispatcher
150
+ * @returns A Dispatcher ready to use with fetch
76
151
  */
77
- function resetProxyDispatcherCache() {
78
- cachedDispatcher = null;
152
+ function getDispatcher(options) {
153
+ return createDispatcher(options);
79
154
  }
80
155
  //# sourceMappingURL=fetch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/utils/fetch.ts"],"names":[],"mappings":";;AA8EA,gDAYC;AAKD,8DAEC;AAjGD,mCAAmC;AAEnC;;;;;;;GAOG;AACH,SAAS,qBAAqB,CAAC,OAE9B;IACC,MAAM,SAAS,GACb,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAA;IAC/D,MAAM,UAAU,GACd,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;IAEjE,MAAM,QAAQ,GAAG,UAAU,IAAI,SAAS,CAAA;IAExC,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AM,WAAW,GAIb;QACF,GAAG,EAAE,QAAQ;QACb,UAAU,EAAE;YACV,kBAAkB;SACnB;KACF,CAAA;IAED,yDAAyD;IACzD,IAAI,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACpC,WAAW,CAAC,QAAQ,GAAG;YACrB,kBAAkB;SACnB,CAAA;IACH,CAAC;IAED,OAAO,IAAI,mBAAU,CAAC,WAAW,CAAC,CAAA;AACpC,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,OAGzB;;IACC,MAAM,kBAAkB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB,mCAAI,IAAI,CAAA;IAE9D,IAAI,iBAAiB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,EAAE,CAAC;QACpC,OAAO,iBAAiB,CAAC,kBAAkB,CAAC,CAAA;IAC9C,CAAC;IAED,OAAO,gBAAgB,CAAC,kBAAkB,CAAC,CAAA;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,OAG7B;IACC,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAA;AAClC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/backend-core",
3
- "version": "3.23.38",
3
+ "version": "3.23.48",
4
4
  "description": "Budibase backend core libraries used in server and worker",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -39,6 +39,7 @@
39
39
  "@budibase/shared-core": "*",
40
40
  "@budibase/types": "*",
41
41
  "@koa/router": "13.1.0",
42
+ "@smithy/node-http-handler": "^4.1.1",
42
43
  "@techpass/passport-openidconnect": "0.3.3",
43
44
  "aws-cloudfront-sign": "3.0.2",
44
45
  "aws-sdk": "2.1692.0",
@@ -112,5 +113,5 @@
112
113
  }
113
114
  }
114
115
  },
115
- "gitHead": "83fecbd6e6b9e5f5d26369ce51d2173801925e3a"
116
+ "gitHead": "0a78faa2adbb8fb3b81de2b9b00352e60178f12f"
116
117
  }