@openclaw/slack 2026.7.2-beta.2 → 2026.7.2-beta.4

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.
Files changed (161) hide show
  1. package/dist/{account-configured-DzC407uv.js → account-configured-BwfXBo_F.js} +1 -1
  2. package/dist/account-inspect-api.js +1 -1
  3. package/dist/{account-inspect-Di7ditqZ.js → account-inspect-jn1xLaVi.js} +9 -2
  4. package/dist/account-reply-mode-DrUXogvO.js +14 -0
  5. package/dist/{accounts-BOJJiHSr.js → accounts-BSr252c_.js} +13 -25
  6. package/dist/accounts.runtime-CjULMLTa.js +2 -0
  7. package/dist/{action-runtime-Cee2ih0s.js → action-runtime-CFU52n4W.js} +11 -17
  8. package/dist/action-runtime.runtime-9-17zvKH.js +2 -0
  9. package/dist/{actions-BZiuSTIq.js → actions-D51foiwR.js} +5 -5
  10. package/dist/{actions.runtime-DoD0-gxw.js → actions.runtime-BMJwtf5C.js} +1 -1
  11. package/dist/api.js +15 -15
  12. package/dist/{approval-handler.runtime-CUPtIM4k.js → approval-handler.runtime-3b4-wxMl.js} +2 -2
  13. package/dist/{channel-DaIiGUOp.js → channel-Ds8NKvfr.js} +75 -41
  14. package/dist/channel-config-api.js +1 -1
  15. package/dist/channel-plugin-api.js +1 -1
  16. package/dist/{channel-type-Cfm6_6n1.js → channel-type-DXkUajFP.js} +3 -3
  17. package/dist/{channel.setup-C-mLz50O.js → channel.setup-DOSTEDfA.js} +8 -5
  18. package/dist/{config-schema-xPSnK2VK.js → config-schema-B4j4tCOI.js} +236 -30
  19. package/dist/{directory-config-DRkFujwG.js → directory-config-B08pm5ZT.js} +1 -1
  20. package/dist/directory-contract-api.js +1 -1
  21. package/dist/{directory-live-D_yZhjgp.js → directory-live-DpPKzPrn.js} +2 -2
  22. package/dist/doctor-contract-U6oVntbM.js +173 -0
  23. package/dist/doctor-contract-api.js +1 -1
  24. package/dist/{group-policy-85UWiriS.js → group-policy-CdnQzQBI.js} +98 -125
  25. package/dist/{interactive-replies-BilWUdcI.js → interactive-replies-C3ffk6oN.js} +1 -1
  26. package/dist/interactive-replies-api.js +1 -1
  27. package/dist/{message-tool-api-CA9jZrCY.js → message-tool-api-ByVyIVOh.js} +3 -3
  28. package/dist/message-tool-api.js +1 -1
  29. package/dist/{monitor-CalGciTs.js → monitor-CnB_WKvF.js} +3 -3
  30. package/dist/{outbound-adapter-BiLKcnyH.js → outbound-adapter-DuPz2HHt.js} +49 -5
  31. package/dist/{pipeline.runtime-DofAvTtb.js → pipeline.runtime-5rRYZuX5.js} +490 -345
  32. package/dist/{policy-BVs4LiSa.js → policy-C31RYSuT.js} +1 -1
  33. package/dist/probe-CVRuArHA.js +340 -0
  34. package/dist/{provider-CmeoUiIM.js → provider-htuIJGFD.js} +791 -359
  35. package/dist/{relay-source-DMmgtvg4.js → relay-source-Df9EaiTF.js} +6 -11
  36. package/dist/{replies-CJJCp6qz.js → replies-Cgr2Gli4.js} +3 -3
  37. package/dist/{resolve-channels-Rfts6POK.js → resolve-channels-DodP2TFx.js} +1 -1
  38. package/dist/{resolve-users-y6wAxR8E.js → resolve-users-M9eF8891.js} +1 -1
  39. package/dist/{runtime-api-BGDyOt1D.js → runtime-api-D5XYMMsf.js} +3 -2
  40. package/dist/runtime-api.js +11 -11
  41. package/dist/{scopes-CuxNQZ6v.js → scopes-CJRpHkDC.js} +1 -2
  42. package/dist/{secret-contract-CMohXFWS.js → secret-contract-DxmvbxBF.js} +1 -0
  43. package/dist/secret-contract-api.js +1 -1
  44. package/dist/{security-audit-CikQhBUY.js → security-audit-Cz6erklv.js} +0 -10
  45. package/dist/security-contract-api.js +1 -1
  46. package/dist/{send-DYp8ca-l.js → send-BZ1tPv7-.js} +28 -11
  47. package/dist/send.runtime-a2pilFor.js +2 -0
  48. package/dist/setup-core-tPxMuFez.js +600 -0
  49. package/dist/setup-plugin-api.js +1 -1
  50. package/dist/{setup-surface-oSd3NX9J.js → setup-surface-wV-S1dE_.js} +58 -32
  51. package/dist/{shared-D9yz5Otg.js → shared-BfMskaMx.js} +57 -10
  52. package/dist/{slash-dispatch.runtime-CSja9VuD.js → slash-dispatch.runtime-lfeIsXTX.js} +1 -1
  53. package/node_modules/@types/node/README.md +1 -1
  54. package/node_modules/@types/node/fs/promises.d.ts +16 -6
  55. package/node_modules/@types/node/package.json +2 -2
  56. package/node_modules/agent-base/README.md +145 -0
  57. package/node_modules/agent-base/dist/src/index.d.ts +78 -0
  58. package/node_modules/agent-base/dist/src/index.js +203 -0
  59. package/node_modules/agent-base/dist/src/index.js.map +1 -0
  60. package/node_modules/agent-base/dist/src/promisify.d.ts +4 -0
  61. package/node_modules/agent-base/dist/src/promisify.js +18 -0
  62. package/node_modules/agent-base/dist/src/promisify.js.map +1 -0
  63. package/node_modules/agent-base/package.json +64 -0
  64. package/node_modules/agent-base/src/index.ts +345 -0
  65. package/node_modules/agent-base/src/promisify.ts +33 -0
  66. package/node_modules/axios/CHANGELOG.md +197 -1
  67. package/node_modules/axios/README.md +424 -256
  68. package/node_modules/axios/dist/axios.js +589 -204
  69. package/node_modules/axios/dist/axios.min.js +3 -3
  70. package/node_modules/axios/dist/axios.min.js.map +1 -1
  71. package/node_modules/axios/dist/browser/axios.cjs +630 -185
  72. package/node_modules/axios/dist/esm/axios.js +630 -185
  73. package/node_modules/axios/dist/esm/axios.min.js +2 -2
  74. package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
  75. package/node_modules/axios/dist/node/axios.cjs +949 -301
  76. package/node_modules/axios/index.d.cts +28 -5
  77. package/node_modules/axios/index.d.ts +24 -3
  78. package/node_modules/axios/lib/adapters/adapters.js +1 -1
  79. package/node_modules/axios/lib/adapters/fetch.js +223 -49
  80. package/node_modules/axios/lib/adapters/http.js +408 -193
  81. package/node_modules/axios/lib/adapters/xhr.js +3 -1
  82. package/node_modules/axios/lib/core/Axios.js +4 -2
  83. package/node_modules/axios/lib/core/AxiosError.js +13 -1
  84. package/node_modules/axios/lib/core/AxiosHeaders.js +13 -42
  85. package/node_modules/axios/lib/core/buildFullPath.js +29 -1
  86. package/node_modules/axios/lib/core/mergeConfig.js +35 -0
  87. package/node_modules/axios/lib/defaults/transitional.js +2 -0
  88. package/node_modules/axios/lib/env/data.js +1 -1
  89. package/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +1 -3
  90. package/node_modules/axios/lib/helpers/Http2Sessions.js +119 -0
  91. package/node_modules/axios/lib/helpers/buildURL.js +7 -4
  92. package/node_modules/axios/lib/helpers/composeSignals.js +48 -47
  93. package/node_modules/axios/lib/helpers/cookies.js +5 -1
  94. package/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +16 -11
  95. package/node_modules/axios/lib/helpers/formDataToJSON.js +26 -4
  96. package/node_modules/axios/lib/helpers/formDataToStream.js +2 -2
  97. package/node_modules/axios/lib/helpers/fromDataURI.js +20 -5
  98. package/node_modules/axios/lib/helpers/progressEventReducer.js +3 -0
  99. package/node_modules/axios/lib/helpers/resolveConfig.js +26 -13
  100. package/node_modules/axios/lib/helpers/sanitizeHeaderValue.js +60 -0
  101. package/node_modules/axios/lib/helpers/shouldBypassProxy.js +33 -1
  102. package/node_modules/axios/lib/helpers/toFormData.js +48 -12
  103. package/node_modules/axios/lib/helpers/validator.js +1 -1
  104. package/node_modules/axios/lib/utils.js +105 -19
  105. package/node_modules/axios/package.json +31 -13
  106. package/node_modules/https-proxy-agent/README.md +137 -0
  107. package/node_modules/https-proxy-agent/dist/agent.d.ts +30 -0
  108. package/node_modules/https-proxy-agent/dist/agent.js +177 -0
  109. package/node_modules/https-proxy-agent/dist/agent.js.map +1 -0
  110. package/node_modules/https-proxy-agent/dist/index.d.ts +23 -0
  111. package/node_modules/https-proxy-agent/dist/index.js +14 -0
  112. package/node_modules/https-proxy-agent/dist/index.js.map +1 -0
  113. package/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts +7 -0
  114. package/node_modules/https-proxy-agent/dist/parse-proxy-response.js +66 -0
  115. package/node_modules/https-proxy-agent/dist/parse-proxy-response.js.map +1 -0
  116. package/node_modules/https-proxy-agent/package.json +56 -0
  117. package/node_modules/iconv-lite/encodings/sbcs-data.js +2 -0
  118. package/node_modules/iconv-lite/encodings/utf32.js +10 -3
  119. package/node_modules/iconv-lite/package.json +2 -2
  120. package/node_modules/iconv-lite/types/encodings.d.ts +2 -0
  121. package/node_modules/path-to-regexp/Readme.md +3 -3
  122. package/node_modules/path-to-regexp/dist/index.js +135 -158
  123. package/node_modules/path-to-regexp/dist/index.js.map +1 -1
  124. package/node_modules/path-to-regexp/package.json +2 -2
  125. package/node_modules/qs/CHANGELOG.md +11 -0
  126. package/node_modules/qs/dist/qs.js +17 -17
  127. package/node_modules/qs/lib/parse.js +19 -8
  128. package/node_modules/qs/lib/utils.js +47 -8
  129. package/node_modules/qs/package.json +6 -5
  130. package/node_modules/qs/test/parse.js +230 -0
  131. package/node_modules/qs/test/utils.js +194 -0
  132. package/node_modules/typebox/build/compile/validator.d.mts +1 -4
  133. package/node_modules/typebox/build/guard/guard.d.mts +1 -1
  134. package/node_modules/typebox/build/guard/guard.mjs +5 -2
  135. package/node_modules/typebox/build/guard/string.mjs +16 -4
  136. package/node_modules/typebox/build/schema/engine/_functions.mjs +34 -15
  137. package/node_modules/typebox/build/type/action/readonly_object.d.mts +5 -0
  138. package/node_modules/typebox/build/type/action/readonly_object.mjs +8 -0
  139. package/node_modules/typebox/build/typebox.d.mts +1 -1
  140. package/node_modules/typebox/build/typebox.mjs +1 -1
  141. package/node_modules/typebox/package.json +1 -1
  142. package/node_modules/typebox/readme.md +29 -32
  143. package/node_modules/ws/lib/receiver.js +15 -32
  144. package/node_modules/ws/lib/websocket-server.js +4 -4
  145. package/node_modules/ws/lib/websocket.js +4 -4
  146. package/node_modules/ws/package.json +5 -1
  147. package/npm-shrinkwrap.json +54 -27
  148. package/openclaw.plugin.json +1331 -1424
  149. package/package.json +92 -14
  150. package/dist/accounts.runtime-KvftRRek.js +0 -2
  151. package/dist/action-runtime.runtime-DZfd7IFr.js +0 -2
  152. package/dist/client-WIPAS3Yr.js +0 -160
  153. package/dist/config-api-Df9a1B8C.js +0 -3
  154. package/dist/doctor-contract-DddfkMlF.js +0 -134
  155. package/dist/probe-CN0ssfLN.js +0 -48
  156. package/dist/send.runtime-CJLxAt26.js +0 -2
  157. package/dist/setup-core-CkwVLzFO.js +0 -337
  158. package/node_modules/axios/dist/axios.js.map +0 -1
  159. package/node_modules/axios/dist/browser/axios.cjs.map +0 -1
  160. package/node_modules/axios/dist/esm/axios.js.map +0 -1
  161. package/node_modules/axios/dist/node/axios.cjs.map +0 -1
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const events_1 = require("events");
6
+ const debug_1 = __importDefault(require("debug"));
7
+ const promisify_1 = __importDefault(require("./promisify"));
8
+ const debug = debug_1.default('agent-base');
9
+ function isAgent(v) {
10
+ return Boolean(v) && typeof v.addRequest === 'function';
11
+ }
12
+ function isSecureEndpoint() {
13
+ const { stack } = new Error();
14
+ if (typeof stack !== 'string')
15
+ return false;
16
+ return stack.split('\n').some(l => l.indexOf('(https.js:') !== -1 || l.indexOf('node:https:') !== -1);
17
+ }
18
+ function createAgent(callback, opts) {
19
+ return new createAgent.Agent(callback, opts);
20
+ }
21
+ (function (createAgent) {
22
+ /**
23
+ * Base `http.Agent` implementation.
24
+ * No pooling/keep-alive is implemented by default.
25
+ *
26
+ * @param {Function} callback
27
+ * @api public
28
+ */
29
+ class Agent extends events_1.EventEmitter {
30
+ constructor(callback, _opts) {
31
+ super();
32
+ let opts = _opts;
33
+ if (typeof callback === 'function') {
34
+ this.callback = callback;
35
+ }
36
+ else if (callback) {
37
+ opts = callback;
38
+ }
39
+ // Timeout for the socket to be returned from the callback
40
+ this.timeout = null;
41
+ if (opts && typeof opts.timeout === 'number') {
42
+ this.timeout = opts.timeout;
43
+ }
44
+ // These aren't actually used by `agent-base`, but are required
45
+ // for the TypeScript definition files in `@types/node` :/
46
+ this.maxFreeSockets = 1;
47
+ this.maxSockets = 1;
48
+ this.maxTotalSockets = Infinity;
49
+ this.sockets = {};
50
+ this.freeSockets = {};
51
+ this.requests = {};
52
+ this.options = {};
53
+ }
54
+ get defaultPort() {
55
+ if (typeof this.explicitDefaultPort === 'number') {
56
+ return this.explicitDefaultPort;
57
+ }
58
+ return isSecureEndpoint() ? 443 : 80;
59
+ }
60
+ set defaultPort(v) {
61
+ this.explicitDefaultPort = v;
62
+ }
63
+ get protocol() {
64
+ if (typeof this.explicitProtocol === 'string') {
65
+ return this.explicitProtocol;
66
+ }
67
+ return isSecureEndpoint() ? 'https:' : 'http:';
68
+ }
69
+ set protocol(v) {
70
+ this.explicitProtocol = v;
71
+ }
72
+ callback(req, opts, fn) {
73
+ throw new Error('"agent-base" has no default implementation, you must subclass and override `callback()`');
74
+ }
75
+ /**
76
+ * Called by node-core's "_http_client.js" module when creating
77
+ * a new HTTP request with this Agent instance.
78
+ *
79
+ * @api public
80
+ */
81
+ addRequest(req, _opts) {
82
+ const opts = Object.assign({}, _opts);
83
+ if (typeof opts.secureEndpoint !== 'boolean') {
84
+ opts.secureEndpoint = isSecureEndpoint();
85
+ }
86
+ if (opts.host == null) {
87
+ opts.host = 'localhost';
88
+ }
89
+ if (opts.port == null) {
90
+ opts.port = opts.secureEndpoint ? 443 : 80;
91
+ }
92
+ if (opts.protocol == null) {
93
+ opts.protocol = opts.secureEndpoint ? 'https:' : 'http:';
94
+ }
95
+ if (opts.host && opts.path) {
96
+ // If both a `host` and `path` are specified then it's most
97
+ // likely the result of a `url.parse()` call... we need to
98
+ // remove the `path` portion so that `net.connect()` doesn't
99
+ // attempt to open that as a unix socket file.
100
+ delete opts.path;
101
+ }
102
+ delete opts.agent;
103
+ delete opts.hostname;
104
+ delete opts._defaultAgent;
105
+ delete opts.defaultPort;
106
+ delete opts.createConnection;
107
+ // Hint to use "Connection: close"
108
+ // XXX: non-documented `http` module API :(
109
+ req._last = true;
110
+ req.shouldKeepAlive = false;
111
+ let timedOut = false;
112
+ let timeoutId = null;
113
+ const timeoutMs = opts.timeout || this.timeout;
114
+ const onerror = (err) => {
115
+ if (req._hadError)
116
+ return;
117
+ req.emit('error', err);
118
+ // For Safety. Some additional errors might fire later on
119
+ // and we need to make sure we don't double-fire the error event.
120
+ req._hadError = true;
121
+ };
122
+ const ontimeout = () => {
123
+ timeoutId = null;
124
+ timedOut = true;
125
+ const err = new Error(`A "socket" was not created for HTTP request before ${timeoutMs}ms`);
126
+ err.code = 'ETIMEOUT';
127
+ onerror(err);
128
+ };
129
+ const callbackError = (err) => {
130
+ if (timedOut)
131
+ return;
132
+ if (timeoutId !== null) {
133
+ clearTimeout(timeoutId);
134
+ timeoutId = null;
135
+ }
136
+ onerror(err);
137
+ };
138
+ const onsocket = (socket) => {
139
+ if (timedOut)
140
+ return;
141
+ if (timeoutId != null) {
142
+ clearTimeout(timeoutId);
143
+ timeoutId = null;
144
+ }
145
+ if (isAgent(socket)) {
146
+ // `socket` is actually an `http.Agent` instance, so
147
+ // relinquish responsibility for this `req` to the Agent
148
+ // from here on
149
+ debug('Callback returned another Agent instance %o', socket.constructor.name);
150
+ socket.addRequest(req, opts);
151
+ return;
152
+ }
153
+ if (socket) {
154
+ socket.once('free', () => {
155
+ this.freeSocket(socket, opts);
156
+ });
157
+ req.onSocket(socket);
158
+ return;
159
+ }
160
+ const err = new Error(`no Duplex stream was returned to agent-base for \`${req.method} ${req.path}\``);
161
+ onerror(err);
162
+ };
163
+ if (typeof this.callback !== 'function') {
164
+ onerror(new Error('`callback` is not defined'));
165
+ return;
166
+ }
167
+ if (!this.promisifiedCallback) {
168
+ if (this.callback.length >= 3) {
169
+ debug('Converting legacy callback function to promise');
170
+ this.promisifiedCallback = promisify_1.default(this.callback);
171
+ }
172
+ else {
173
+ this.promisifiedCallback = this.callback;
174
+ }
175
+ }
176
+ if (typeof timeoutMs === 'number' && timeoutMs > 0) {
177
+ timeoutId = setTimeout(ontimeout, timeoutMs);
178
+ }
179
+ if ('port' in opts && typeof opts.port !== 'number') {
180
+ opts.port = Number(opts.port);
181
+ }
182
+ try {
183
+ debug('Resolving socket for %o request: %o', opts.protocol, `${req.method} ${req.path}`);
184
+ Promise.resolve(this.promisifiedCallback(req, opts)).then(onsocket, callbackError);
185
+ }
186
+ catch (err) {
187
+ Promise.reject(err).catch(callbackError);
188
+ }
189
+ }
190
+ freeSocket(socket, opts) {
191
+ debug('Freeing socket %o %o', socket.constructor.name, opts);
192
+ socket.destroy();
193
+ }
194
+ destroy() {
195
+ debug('Destroying agent %o', this.constructor.name);
196
+ }
197
+ }
198
+ createAgent.Agent = Agent;
199
+ // So that `instanceof` works correctly
200
+ createAgent.prototype = createAgent.Agent.prototype;
201
+ })(createAgent || (createAgent = {}));
202
+ module.exports = createAgent;
203
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAIA,mCAAsC;AACtC,kDAAgC;AAChC,4DAAoC;AAEpC,MAAM,KAAK,GAAG,eAAW,CAAC,YAAY,CAAC,CAAC;AAExC,SAAS,OAAO,CAAC,CAAM;IACtB,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC;AACzD,CAAC;AAED,SAAS,gBAAgB;IACxB,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,KAAK,EAAE,CAAC;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,IAAK,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxG,CAAC;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 +1,4 @@
1
+ import { ClientRequest, RequestOptions, AgentCallbackCallback, AgentCallbackPromise } from './index';
2
+ declare type LegacyCallback = (req: ClientRequest, opts: RequestOptions, fn: AgentCallbackCallback) => void;
3
+ export default function promisify(fn: LegacyCallback): AgentCallbackPromise;
4
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function promisify(fn) {
4
+ return function (req, opts) {
5
+ return new Promise((resolve, reject) => {
6
+ fn.call(this, req, opts, (err, rtn) => {
7
+ if (err) {
8
+ reject(err);
9
+ }
10
+ else {
11
+ resolve(rtn);
12
+ }
13
+ });
14
+ });
15
+ };
16
+ }
17
+ exports.default = promisify;
18
+ //# sourceMappingURL=promisify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promisify.js","sourceRoot":"","sources":["../../src/promisify.ts"],"names":[],"mappings":";;AAeA,SAAwB,SAAS,CAAC,EAAkB;IACnD,OAAO,UAAsB,GAAkB,EAAE,IAAoB;QACpE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,EAAE,CAAC,IAAI,CACN,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,CAAC,GAA6B,EAAE,GAAyB,EAAE,EAAE;gBAC5D,IAAI,GAAG,EAAE;oBACR,MAAM,CAAC,GAAG,CAAC,CAAC;iBACZ;qBAAM;oBACN,OAAO,CAAC,GAAG,CAAC,CAAC;iBACb;YACF,CAAC,CACD,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAjBD,4BAiBC"}
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "agent-base",
3
+ "version": "6.0.2",
4
+ "description": "Turn a function into an `http.Agent` instance",
5
+ "main": "dist/src/index",
6
+ "typings": "dist/src/index",
7
+ "files": [
8
+ "dist/src",
9
+ "src"
10
+ ],
11
+ "scripts": {
12
+ "prebuild": "rimraf dist",
13
+ "build": "tsc",
14
+ "postbuild": "cpy --parents src test '!**/*.ts' dist",
15
+ "test": "mocha --reporter spec dist/test/*.js",
16
+ "test-lint": "eslint src --ext .js,.ts",
17
+ "prepublishOnly": "npm run build"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git://github.com/TooTallNate/node-agent-base.git"
22
+ },
23
+ "keywords": [
24
+ "http",
25
+ "agent",
26
+ "base",
27
+ "barebones",
28
+ "https"
29
+ ],
30
+ "author": "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)",
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/TooTallNate/node-agent-base/issues"
34
+ },
35
+ "dependencies": {
36
+ "debug": "4"
37
+ },
38
+ "devDependencies": {
39
+ "@types/debug": "4",
40
+ "@types/mocha": "^5.2.7",
41
+ "@types/node": "^14.0.20",
42
+ "@types/semver": "^7.1.0",
43
+ "@types/ws": "^6.0.3",
44
+ "@typescript-eslint/eslint-plugin": "1.6.0",
45
+ "@typescript-eslint/parser": "1.1.0",
46
+ "async-listen": "^1.2.0",
47
+ "cpy-cli": "^2.0.0",
48
+ "eslint": "5.16.0",
49
+ "eslint-config-airbnb": "17.1.0",
50
+ "eslint-config-prettier": "4.1.0",
51
+ "eslint-import-resolver-typescript": "1.1.1",
52
+ "eslint-plugin-import": "2.16.0",
53
+ "eslint-plugin-jsx-a11y": "6.2.1",
54
+ "eslint-plugin-react": "7.12.4",
55
+ "mocha": "^6.2.0",
56
+ "rimraf": "^3.0.0",
57
+ "semver": "^7.1.2",
58
+ "typescript": "^3.5.3",
59
+ "ws": "^3.0.0"
60
+ },
61
+ "engines": {
62
+ "node": ">= 6.0.0"
63
+ }
64
+ }
@@ -0,0 +1,345 @@
1
+ import net from 'net';
2
+ import http from 'http';
3
+ import https from 'https';
4
+ import { Duplex } from 'stream';
5
+ import { EventEmitter } from 'events';
6
+ import createDebug from 'debug';
7
+ import promisify from './promisify';
8
+
9
+ const debug = createDebug('agent-base');
10
+
11
+ function isAgent(v: any): v is createAgent.AgentLike {
12
+ return Boolean(v) && typeof v.addRequest === 'function';
13
+ }
14
+
15
+ function isSecureEndpoint(): boolean {
16
+ const { stack } = new Error();
17
+ if (typeof stack !== 'string') return false;
18
+ return stack.split('\n').some(l => l.indexOf('(https.js:') !== -1 || l.indexOf('node:https:') !== -1);
19
+ }
20
+
21
+ function createAgent(opts?: createAgent.AgentOptions): createAgent.Agent;
22
+ function createAgent(
23
+ callback: createAgent.AgentCallback,
24
+ opts?: createAgent.AgentOptions
25
+ ): createAgent.Agent;
26
+ function createAgent(
27
+ callback?: createAgent.AgentCallback | createAgent.AgentOptions,
28
+ opts?: createAgent.AgentOptions
29
+ ) {
30
+ return new createAgent.Agent(callback, opts);
31
+ }
32
+
33
+ namespace createAgent {
34
+ export interface ClientRequest extends http.ClientRequest {
35
+ _last?: boolean;
36
+ _hadError?: boolean;
37
+ method: string;
38
+ }
39
+
40
+ export interface AgentRequestOptions {
41
+ host?: string;
42
+ path?: string;
43
+ // `port` on `http.RequestOptions` can be a string or undefined,
44
+ // but `net.TcpNetConnectOpts` expects only a number
45
+ port: number;
46
+ }
47
+
48
+ export interface HttpRequestOptions
49
+ extends AgentRequestOptions,
50
+ Omit<http.RequestOptions, keyof AgentRequestOptions> {
51
+ secureEndpoint: false;
52
+ }
53
+
54
+ export interface HttpsRequestOptions
55
+ extends AgentRequestOptions,
56
+ Omit<https.RequestOptions, keyof AgentRequestOptions> {
57
+ secureEndpoint: true;
58
+ }
59
+
60
+ export type RequestOptions = HttpRequestOptions | HttpsRequestOptions;
61
+
62
+ export type AgentLike = Pick<createAgent.Agent, 'addRequest'> | http.Agent;
63
+
64
+ export type AgentCallbackReturn = Duplex | AgentLike;
65
+
66
+ export type AgentCallbackCallback = (
67
+ err?: Error | null,
68
+ socket?: createAgent.AgentCallbackReturn
69
+ ) => void;
70
+
71
+ export type AgentCallbackPromise = (
72
+ req: createAgent.ClientRequest,
73
+ opts: createAgent.RequestOptions
74
+ ) =>
75
+ | createAgent.AgentCallbackReturn
76
+ | Promise<createAgent.AgentCallbackReturn>;
77
+
78
+ export type AgentCallback = typeof Agent.prototype.callback;
79
+
80
+ export type AgentOptions = {
81
+ timeout?: number;
82
+ };
83
+
84
+ /**
85
+ * Base `http.Agent` implementation.
86
+ * No pooling/keep-alive is implemented by default.
87
+ *
88
+ * @param {Function} callback
89
+ * @api public
90
+ */
91
+ export class Agent extends EventEmitter {
92
+ public timeout: number | null;
93
+ public maxFreeSockets: number;
94
+ public maxTotalSockets: number;
95
+ public maxSockets: number;
96
+ public sockets: {
97
+ [key: string]: net.Socket[];
98
+ };
99
+ public freeSockets: {
100
+ [key: string]: net.Socket[];
101
+ };
102
+ public requests: {
103
+ [key: string]: http.IncomingMessage[];
104
+ };
105
+ public options: https.AgentOptions;
106
+ private promisifiedCallback?: createAgent.AgentCallbackPromise;
107
+ private explicitDefaultPort?: number;
108
+ private explicitProtocol?: string;
109
+
110
+ constructor(
111
+ callback?: createAgent.AgentCallback | createAgent.AgentOptions,
112
+ _opts?: createAgent.AgentOptions
113
+ ) {
114
+ super();
115
+
116
+ let opts = _opts;
117
+ if (typeof callback === 'function') {
118
+ this.callback = callback;
119
+ } else if (callback) {
120
+ opts = callback;
121
+ }
122
+
123
+ // Timeout for the socket to be returned from the callback
124
+ this.timeout = null;
125
+ if (opts && typeof opts.timeout === 'number') {
126
+ this.timeout = opts.timeout;
127
+ }
128
+
129
+ // These aren't actually used by `agent-base`, but are required
130
+ // for the TypeScript definition files in `@types/node` :/
131
+ this.maxFreeSockets = 1;
132
+ this.maxSockets = 1;
133
+ this.maxTotalSockets = Infinity;
134
+ this.sockets = {};
135
+ this.freeSockets = {};
136
+ this.requests = {};
137
+ this.options = {};
138
+ }
139
+
140
+ get defaultPort(): number {
141
+ if (typeof this.explicitDefaultPort === 'number') {
142
+ return this.explicitDefaultPort;
143
+ }
144
+ return isSecureEndpoint() ? 443 : 80;
145
+ }
146
+
147
+ set defaultPort(v: number) {
148
+ this.explicitDefaultPort = v;
149
+ }
150
+
151
+ get protocol(): string {
152
+ if (typeof this.explicitProtocol === 'string') {
153
+ return this.explicitProtocol;
154
+ }
155
+ return isSecureEndpoint() ? 'https:' : 'http:';
156
+ }
157
+
158
+ set protocol(v: string) {
159
+ this.explicitProtocol = v;
160
+ }
161
+
162
+ callback(
163
+ req: createAgent.ClientRequest,
164
+ opts: createAgent.RequestOptions,
165
+ fn: createAgent.AgentCallbackCallback
166
+ ): void;
167
+ callback(
168
+ req: createAgent.ClientRequest,
169
+ opts: createAgent.RequestOptions
170
+ ):
171
+ | createAgent.AgentCallbackReturn
172
+ | Promise<createAgent.AgentCallbackReturn>;
173
+ callback(
174
+ req: createAgent.ClientRequest,
175
+ opts: createAgent.AgentOptions,
176
+ fn?: createAgent.AgentCallbackCallback
177
+ ):
178
+ | createAgent.AgentCallbackReturn
179
+ | Promise<createAgent.AgentCallbackReturn>
180
+ | void {
181
+ throw new Error(
182
+ '"agent-base" has no default implementation, you must subclass and override `callback()`'
183
+ );
184
+ }
185
+
186
+ /**
187
+ * Called by node-core's "_http_client.js" module when creating
188
+ * a new HTTP request with this Agent instance.
189
+ *
190
+ * @api public
191
+ */
192
+ addRequest(req: ClientRequest, _opts: RequestOptions): void {
193
+ const opts: RequestOptions = { ..._opts };
194
+
195
+ if (typeof opts.secureEndpoint !== 'boolean') {
196
+ opts.secureEndpoint = isSecureEndpoint();
197
+ }
198
+
199
+ if (opts.host == null) {
200
+ opts.host = 'localhost';
201
+ }
202
+
203
+ if (opts.port == null) {
204
+ opts.port = opts.secureEndpoint ? 443 : 80;
205
+ }
206
+
207
+ if (opts.protocol == null) {
208
+ opts.protocol = opts.secureEndpoint ? 'https:' : 'http:';
209
+ }
210
+
211
+ if (opts.host && opts.path) {
212
+ // If both a `host` and `path` are specified then it's most
213
+ // likely the result of a `url.parse()` call... we need to
214
+ // remove the `path` portion so that `net.connect()` doesn't
215
+ // attempt to open that as a unix socket file.
216
+ delete opts.path;
217
+ }
218
+
219
+ delete opts.agent;
220
+ delete opts.hostname;
221
+ delete opts._defaultAgent;
222
+ delete opts.defaultPort;
223
+ delete opts.createConnection;
224
+
225
+ // Hint to use "Connection: close"
226
+ // XXX: non-documented `http` module API :(
227
+ req._last = true;
228
+ req.shouldKeepAlive = false;
229
+
230
+ let timedOut = false;
231
+ let timeoutId: ReturnType<typeof setTimeout> | null = null;
232
+ const timeoutMs = opts.timeout || this.timeout;
233
+
234
+ const onerror = (err: NodeJS.ErrnoException) => {
235
+ if (req._hadError) return;
236
+ req.emit('error', err);
237
+ // For Safety. Some additional errors might fire later on
238
+ // and we need to make sure we don't double-fire the error event.
239
+ req._hadError = true;
240
+ };
241
+
242
+ const ontimeout = () => {
243
+ timeoutId = null;
244
+ timedOut = true;
245
+ const err: NodeJS.ErrnoException = new Error(
246
+ `A "socket" was not created for HTTP request before ${timeoutMs}ms`
247
+ );
248
+ err.code = 'ETIMEOUT';
249
+ onerror(err);
250
+ };
251
+
252
+ const callbackError = (err: NodeJS.ErrnoException) => {
253
+ if (timedOut) return;
254
+ if (timeoutId !== null) {
255
+ clearTimeout(timeoutId);
256
+ timeoutId = null;
257
+ }
258
+ onerror(err);
259
+ };
260
+
261
+ const onsocket = (socket: AgentCallbackReturn) => {
262
+ if (timedOut) return;
263
+ if (timeoutId != null) {
264
+ clearTimeout(timeoutId);
265
+ timeoutId = null;
266
+ }
267
+
268
+ if (isAgent(socket)) {
269
+ // `socket` is actually an `http.Agent` instance, so
270
+ // relinquish responsibility for this `req` to the Agent
271
+ // from here on
272
+ debug(
273
+ 'Callback returned another Agent instance %o',
274
+ socket.constructor.name
275
+ );
276
+ (socket as createAgent.Agent).addRequest(req, opts);
277
+ return;
278
+ }
279
+
280
+ if (socket) {
281
+ socket.once('free', () => {
282
+ this.freeSocket(socket as net.Socket, opts);
283
+ });
284
+ req.onSocket(socket as net.Socket);
285
+ return;
286
+ }
287
+
288
+ const err = new Error(
289
+ `no Duplex stream was returned to agent-base for \`${req.method} ${req.path}\``
290
+ );
291
+ onerror(err);
292
+ };
293
+
294
+ if (typeof this.callback !== 'function') {
295
+ onerror(new Error('`callback` is not defined'));
296
+ return;
297
+ }
298
+
299
+ if (!this.promisifiedCallback) {
300
+ if (this.callback.length >= 3) {
301
+ debug('Converting legacy callback function to promise');
302
+ this.promisifiedCallback = promisify(this.callback);
303
+ } else {
304
+ this.promisifiedCallback = this.callback;
305
+ }
306
+ }
307
+
308
+ if (typeof timeoutMs === 'number' && timeoutMs > 0) {
309
+ timeoutId = setTimeout(ontimeout, timeoutMs);
310
+ }
311
+
312
+ if ('port' in opts && typeof opts.port !== 'number') {
313
+ opts.port = Number(opts.port);
314
+ }
315
+
316
+ try {
317
+ debug(
318
+ 'Resolving socket for %o request: %o',
319
+ opts.protocol,
320
+ `${req.method} ${req.path}`
321
+ );
322
+ Promise.resolve(this.promisifiedCallback(req, opts)).then(
323
+ onsocket,
324
+ callbackError
325
+ );
326
+ } catch (err) {
327
+ Promise.reject(err).catch(callbackError);
328
+ }
329
+ }
330
+
331
+ freeSocket(socket: net.Socket, opts: AgentOptions) {
332
+ debug('Freeing socket %o %o', socket.constructor.name, opts);
333
+ socket.destroy();
334
+ }
335
+
336
+ destroy() {
337
+ debug('Destroying agent %o', this.constructor.name);
338
+ }
339
+ }
340
+
341
+ // So that `instanceof` works correctly
342
+ createAgent.prototype = createAgent.Agent.prototype;
343
+ }
344
+
345
+ export = createAgent;
@@ -0,0 +1,33 @@
1
+ import {
2
+ Agent,
3
+ ClientRequest,
4
+ RequestOptions,
5
+ AgentCallbackCallback,
6
+ AgentCallbackPromise,
7
+ AgentCallbackReturn
8
+ } from './index';
9
+
10
+ type LegacyCallback = (
11
+ req: ClientRequest,
12
+ opts: RequestOptions,
13
+ fn: AgentCallbackCallback
14
+ ) => void;
15
+
16
+ export default function promisify(fn: LegacyCallback): AgentCallbackPromise {
17
+ return function(this: Agent, req: ClientRequest, opts: RequestOptions) {
18
+ return new Promise((resolve, reject) => {
19
+ fn.call(
20
+ this,
21
+ req,
22
+ opts,
23
+ (err: Error | null | undefined, rtn?: AgentCallbackReturn) => {
24
+ if (err) {
25
+ reject(err);
26
+ } else {
27
+ resolve(rtn);
28
+ }
29
+ }
30
+ );
31
+ });
32
+ };
33
+ }