phenoml 6.0.0 → 6.2.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.
Files changed (68) hide show
  1. package/dist/cjs/BaseClient.d.ts +4 -0
  2. package/dist/cjs/Client.js +2 -2
  3. package/dist/cjs/api/resources/agent/client/Client.js +24 -8
  4. package/dist/cjs/api/resources/agent/resources/prompts/client/Client.js +21 -7
  5. package/dist/cjs/api/resources/cohort/client/Client.js +3 -1
  6. package/dist/cjs/api/resources/construe/client/Client.js +30 -10
  7. package/dist/cjs/api/resources/fhir/client/Client.js +18 -6
  8. package/dist/cjs/api/resources/fhirProvider/client/Client.js +21 -7
  9. package/dist/cjs/api/resources/lang2Fhir/client/Client.js +15 -5
  10. package/dist/cjs/api/resources/summary/client/Client.js +18 -6
  11. package/dist/cjs/api/resources/tools/client/Client.js +12 -4
  12. package/dist/cjs/api/resources/tools/resources/mcpServer/client/Client.js +12 -4
  13. package/dist/cjs/api/resources/tools/resources/mcpServer/resources/tools/client/Client.js +12 -4
  14. package/dist/cjs/api/resources/workflows/client/Client.js +18 -6
  15. package/dist/cjs/core/exports.d.ts +1 -0
  16. package/dist/cjs/core/exports.js +17 -0
  17. package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -1
  18. package/dist/cjs/core/fetcher/Fetcher.js +181 -5
  19. package/dist/cjs/core/fetcher/getRequestBody.d.ts +1 -1
  20. package/dist/cjs/core/fetcher/getRequestBody.js +4 -0
  21. package/dist/cjs/core/headers.js +6 -4
  22. package/dist/cjs/core/index.d.ts +1 -0
  23. package/dist/cjs/core/index.js +2 -1
  24. package/dist/cjs/core/logging/exports.d.ts +18 -0
  25. package/dist/cjs/core/logging/exports.js +45 -0
  26. package/dist/cjs/core/logging/index.d.ts +1 -0
  27. package/dist/cjs/core/logging/index.js +17 -0
  28. package/dist/cjs/core/logging/logger.d.ts +126 -0
  29. package/dist/cjs/core/logging/logger.js +144 -0
  30. package/dist/cjs/exports.d.ts +1 -0
  31. package/dist/cjs/exports.js +17 -0
  32. package/dist/cjs/version.d.ts +1 -1
  33. package/dist/cjs/version.js +1 -1
  34. package/dist/esm/BaseClient.d.mts +4 -0
  35. package/dist/esm/Client.mjs +2 -2
  36. package/dist/esm/api/resources/agent/client/Client.mjs +24 -8
  37. package/dist/esm/api/resources/agent/resources/prompts/client/Client.mjs +21 -7
  38. package/dist/esm/api/resources/cohort/client/Client.mjs +3 -1
  39. package/dist/esm/api/resources/construe/client/Client.mjs +30 -10
  40. package/dist/esm/api/resources/fhir/client/Client.mjs +18 -6
  41. package/dist/esm/api/resources/fhirProvider/client/Client.mjs +21 -7
  42. package/dist/esm/api/resources/lang2Fhir/client/Client.mjs +15 -5
  43. package/dist/esm/api/resources/summary/client/Client.mjs +18 -6
  44. package/dist/esm/api/resources/tools/client/Client.mjs +12 -4
  45. package/dist/esm/api/resources/tools/resources/mcpServer/client/Client.mjs +12 -4
  46. package/dist/esm/api/resources/tools/resources/mcpServer/resources/tools/client/Client.mjs +12 -4
  47. package/dist/esm/api/resources/workflows/client/Client.mjs +18 -6
  48. package/dist/esm/core/exports.d.mts +1 -0
  49. package/dist/esm/core/exports.mjs +1 -0
  50. package/dist/esm/core/fetcher/Fetcher.d.mts +4 -1
  51. package/dist/esm/core/fetcher/Fetcher.mjs +181 -5
  52. package/dist/esm/core/fetcher/getRequestBody.d.mts +1 -1
  53. package/dist/esm/core/fetcher/getRequestBody.mjs +4 -0
  54. package/dist/esm/core/headers.mjs +6 -4
  55. package/dist/esm/core/index.d.mts +1 -0
  56. package/dist/esm/core/index.mjs +1 -0
  57. package/dist/esm/core/logging/exports.d.mts +18 -0
  58. package/dist/esm/core/logging/exports.mjs +9 -0
  59. package/dist/esm/core/logging/index.d.mts +1 -0
  60. package/dist/esm/core/logging/index.mjs +1 -0
  61. package/dist/esm/core/logging/logger.d.mts +126 -0
  62. package/dist/esm/core/logging/logger.mjs +138 -0
  63. package/dist/esm/exports.d.mts +1 -0
  64. package/dist/esm/exports.mjs +1 -0
  65. package/dist/esm/version.d.mts +1 -1
  66. package/dist/esm/version.mjs +1 -1
  67. package/package.json +3 -2
  68. package/reference.md +1 -1
@@ -84,7 +84,7 @@ class Workflows {
84
84
  }
85
85
  __list() {
86
86
  return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
87
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
87
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
88
88
  const { verbose } = request;
89
89
  const _queryParams = {};
90
90
  if (verbose != null) {
@@ -99,6 +99,8 @@ class Workflows {
99
99
  timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
100
100
  maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
101
101
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
102
+ fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
103
+ logging: this._options.logging,
102
104
  });
103
105
  if (_response.ok) {
104
106
  return {
@@ -168,7 +170,7 @@ class Workflows {
168
170
  }
169
171
  __create(request, requestOptions) {
170
172
  return __awaiter(this, void 0, void 0, function* () {
171
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
173
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
172
174
  const { verbose } = request, _body = __rest(request, ["verbose"]);
173
175
  const _queryParams = {};
174
176
  if (verbose != null) {
@@ -186,6 +188,8 @@ class Workflows {
186
188
  timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
187
189
  maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
188
190
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
191
+ fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
192
+ logging: this._options.logging,
189
193
  });
190
194
  if (_response.ok) {
191
195
  return {
@@ -250,7 +254,7 @@ class Workflows {
250
254
  }
251
255
  __get(id_1) {
252
256
  return __awaiter(this, arguments, void 0, function* (id, request = {}, requestOptions) {
253
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
257
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
254
258
  const { verbose } = request;
255
259
  const _queryParams = {};
256
260
  if (verbose != null) {
@@ -265,6 +269,8 @@ class Workflows {
265
269
  timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
266
270
  maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
267
271
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
272
+ fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
273
+ logging: this._options.logging,
268
274
  });
269
275
  if (_response.ok) {
270
276
  return {
@@ -338,7 +344,7 @@ class Workflows {
338
344
  }
339
345
  __update(id, request, requestOptions) {
340
346
  return __awaiter(this, void 0, void 0, function* () {
341
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
347
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
342
348
  const { verbose } = request, _body = __rest(request, ["verbose"]);
343
349
  const _queryParams = {};
344
350
  if (verbose != null) {
@@ -356,6 +362,8 @@ class Workflows {
356
362
  timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
357
363
  maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
358
364
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
365
+ fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
366
+ logging: this._options.logging,
359
367
  });
360
368
  if (_response.ok) {
361
369
  return {
@@ -419,7 +427,7 @@ class Workflows {
419
427
  }
420
428
  __delete(id, requestOptions) {
421
429
  return __awaiter(this, void 0, void 0, function* () {
422
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
430
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
423
431
  const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
424
432
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
425
433
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.phenomlEnvironment.Default, `workflows/${core.url.encodePathParam(id)}`),
@@ -429,6 +437,8 @@ class Workflows {
429
437
  timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
430
438
  maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
431
439
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
440
+ fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
441
+ logging: this._options.logging,
432
442
  });
433
443
  if (_response.ok) {
434
444
  return {
@@ -499,7 +509,7 @@ class Workflows {
499
509
  }
500
510
  __execute(id, request, requestOptions) {
501
511
  return __awaiter(this, void 0, void 0, function* () {
502
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
512
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
503
513
  const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
504
514
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
505
515
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.phenomlEnvironment.Default, `workflows/${core.url.encodePathParam(id)}/execute`),
@@ -512,6 +522,8 @@ class Workflows {
512
522
  timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
513
523
  maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
514
524
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
525
+ fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
526
+ logging: this._options.logging,
515
527
  });
516
528
  if (_response.ok) {
517
529
  return {
@@ -0,0 +1 @@
1
+ export * from "./logging/exports.js";
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./logging/exports.js"), exports);
@@ -1,3 +1,4 @@
1
+ import { type LogConfig, type Logger } from "../logging/logger.js";
1
2
  import type { APIResponse } from "./APIResponse.js";
2
3
  import type { EndpointMetadata } from "./EndpointMetadata.js";
3
4
  import { EndpointSupplier } from "./EndpointSupplier.js";
@@ -14,10 +15,12 @@ export declare namespace Fetcher {
14
15
  maxRetries?: number;
15
16
  withCredentials?: boolean;
16
17
  abortSignal?: AbortSignal;
17
- requestType?: "json" | "file" | "bytes";
18
+ requestType?: "json" | "file" | "bytes" | "form" | "other";
18
19
  responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
19
20
  duplex?: "half";
20
21
  endpointMetadata?: EndpointMetadata;
22
+ fetchFn?: typeof fetch;
23
+ logging?: LogConfig | Logger;
21
24
  }
22
25
  type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
23
26
  interface FailedStatusCodeError {
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.fetcher = void 0;
13
13
  exports.fetcherImpl = fetcherImpl;
14
14
  const json_js_1 = require("../json.js");
15
+ const logger_js_1 = require("../logging/logger.js");
15
16
  const createRequestUrl_js_1 = require("./createRequestUrl.js");
16
17
  const EndpointSupplier_js_1 = require("./EndpointSupplier.js");
17
18
  const getErrorResponseBody_js_1 = require("./getErrorResponseBody.js");
@@ -21,6 +22,122 @@ const getResponseBody_js_1 = require("./getResponseBody.js");
21
22
  const makeRequest_js_1 = require("./makeRequest.js");
22
23
  const RawResponse_js_1 = require("./RawResponse.js");
23
24
  const requestWithRetries_js_1 = require("./requestWithRetries.js");
25
+ const SENSITIVE_HEADERS = new Set([
26
+ "authorization",
27
+ "x-api-key",
28
+ "api-key",
29
+ "x-auth-token",
30
+ "cookie",
31
+ "set-cookie",
32
+ "proxy-authorization",
33
+ "x-csrf-token",
34
+ "x-xsrf-token",
35
+ ]);
36
+ function redactHeaders(headers) {
37
+ const filtered = {};
38
+ for (const [key, value] of Object.entries(headers)) {
39
+ if (SENSITIVE_HEADERS.has(key.toLowerCase())) {
40
+ filtered[key] = "[REDACTED]";
41
+ }
42
+ else {
43
+ filtered[key] = value;
44
+ }
45
+ }
46
+ return filtered;
47
+ }
48
+ const SENSITIVE_QUERY_PARAMS = new Set([
49
+ "api_key",
50
+ "api-key",
51
+ "apikey",
52
+ "token",
53
+ "access_token",
54
+ "access-token",
55
+ "auth_token",
56
+ "auth-token",
57
+ "password",
58
+ "passwd",
59
+ "secret",
60
+ "api_secret",
61
+ "api-secret",
62
+ "apisecret",
63
+ "key",
64
+ "session",
65
+ "session_id",
66
+ "session-id",
67
+ ]);
68
+ function redactQueryParameters(queryParameters) {
69
+ if (queryParameters == null) {
70
+ return queryParameters;
71
+ }
72
+ const redacted = {};
73
+ for (const [key, value] of Object.entries(queryParameters)) {
74
+ if (SENSITIVE_QUERY_PARAMS.has(key.toLowerCase())) {
75
+ redacted[key] = "[REDACTED]";
76
+ }
77
+ else {
78
+ redacted[key] = value;
79
+ }
80
+ }
81
+ return redacted;
82
+ }
83
+ function redactUrl(url) {
84
+ const protocolIndex = url.indexOf("://");
85
+ if (protocolIndex === -1)
86
+ return url;
87
+ const afterProtocol = protocolIndex + 3;
88
+ const atIndex = url.indexOf("@", afterProtocol);
89
+ if (atIndex !== -1) {
90
+ const pathStart = url.indexOf("/", afterProtocol);
91
+ const queryStart = url.indexOf("?", afterProtocol);
92
+ const fragmentStart = url.indexOf("#", afterProtocol);
93
+ const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
94
+ if (atIndex < firstDelimiter) {
95
+ url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
96
+ }
97
+ }
98
+ const queryStart = url.indexOf("?");
99
+ if (queryStart === -1)
100
+ return url;
101
+ const fragmentStart = url.indexOf("#", queryStart);
102
+ const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
103
+ const queryString = url.slice(queryStart + 1, queryEnd);
104
+ if (queryString.length === 0)
105
+ return url;
106
+ // FAST PATH: Quick check if any sensitive keywords present
107
+ // Using indexOf is faster than regex for simple substring matching
108
+ const lower = queryString.toLowerCase();
109
+ const hasSensitive = lower.includes("token") || // catches token, access_token, auth_token, etc.
110
+ lower.includes("key") || // catches key, api_key, apikey, api-key, etc.
111
+ lower.includes("password") || // catches password
112
+ lower.includes("passwd") || // catches passwd
113
+ lower.includes("secret") || // catches secret, api_secret, etc.
114
+ lower.includes("session") || // catches session, session_id, session-id
115
+ lower.includes("auth"); // catches auth_token, auth-token, etc.
116
+ if (!hasSensitive) {
117
+ return url; // Early exit - no sensitive params
118
+ }
119
+ // SLOW PATH: Parse and redact
120
+ const redactedParams = [];
121
+ const params = queryString.split("&");
122
+ for (const param of params) {
123
+ const equalIndex = param.indexOf("=");
124
+ if (equalIndex === -1) {
125
+ redactedParams.push(param);
126
+ continue;
127
+ }
128
+ const key = param.slice(0, equalIndex);
129
+ let shouldRedact = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
130
+ if (!shouldRedact && key.includes("%")) {
131
+ try {
132
+ const decodedKey = decodeURIComponent(key);
133
+ shouldRedact = SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
134
+ }
135
+ catch (_a) { }
136
+ }
137
+ redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
138
+ }
139
+ return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
140
+ }
24
141
  function getHeaders(args) {
25
142
  return __awaiter(this, void 0, void 0, function* () {
26
143
  var _a;
@@ -47,18 +164,38 @@ function getHeaders(args) {
47
164
  }
48
165
  function fetcherImpl(args) {
49
166
  return __awaiter(this, void 0, void 0, function* () {
50
- var _a;
167
+ var _a, _b, _c;
51
168
  const url = (0, createRequestUrl_js_1.createRequestUrl)(args.url, args.queryParameters);
52
169
  const requestBody = yield (0, getRequestBody_js_1.getRequestBody)({
53
170
  body: args.body,
54
- type: args.requestType === "json" ? "json" : "other",
171
+ type: (_a = args.requestType) !== null && _a !== void 0 ? _a : "other",
55
172
  });
56
- const fetchFn = yield (0, getFetchFn_js_1.getFetchFn)();
173
+ const fetchFn = (_b = args.fetchFn) !== null && _b !== void 0 ? _b : (yield (0, getFetchFn_js_1.getFetchFn)());
174
+ const headers = yield getHeaders(args);
175
+ const logger = (0, logger_js_1.createLogger)(args.logging);
176
+ if (logger.isDebug()) {
177
+ const metadata = {
178
+ method: args.method,
179
+ url: redactUrl(url),
180
+ headers: redactHeaders(headers),
181
+ queryParameters: redactQueryParameters(args.queryParameters),
182
+ hasBody: requestBody != null,
183
+ };
184
+ logger.debug("Making HTTP request", metadata);
185
+ }
57
186
  try {
58
187
  const response = yield (0, requestWithRetries_js_1.requestWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
59
- return (0, makeRequest_js_1.makeRequest)(fetchFn, url, args.method, yield getHeaders(args), requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
188
+ return (0, makeRequest_js_1.makeRequest)(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
60
189
  }), args.maxRetries);
61
190
  if (response.status >= 200 && response.status < 400) {
191
+ if (logger.isDebug()) {
192
+ const metadata = {
193
+ method: args.method,
194
+ url: redactUrl(url),
195
+ statusCode: response.status,
196
+ };
197
+ logger.debug("HTTP request succeeded", metadata);
198
+ }
62
199
  return {
63
200
  ok: true,
64
201
  body: (yield (0, getResponseBody_js_1.getResponseBody)(response, args.responseType)),
@@ -67,6 +204,14 @@ function fetcherImpl(args) {
67
204
  };
68
205
  }
69
206
  else {
207
+ if (logger.isError()) {
208
+ const metadata = {
209
+ method: args.method,
210
+ url: redactUrl(url),
211
+ statusCode: response.status,
212
+ };
213
+ logger.error("HTTP request failed with error status", metadata);
214
+ }
70
215
  return {
71
216
  ok: false,
72
217
  error: {
@@ -79,7 +224,14 @@ function fetcherImpl(args) {
79
224
  }
80
225
  }
81
226
  catch (error) {
82
- if ((_a = args.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
227
+ if ((_c = args.abortSignal) === null || _c === void 0 ? void 0 : _c.aborted) {
228
+ if (logger.isError()) {
229
+ const metadata = {
230
+ method: args.method,
231
+ url: redactUrl(url),
232
+ };
233
+ logger.error("HTTP request was aborted", metadata);
234
+ }
83
235
  return {
84
236
  ok: false,
85
237
  error: {
@@ -90,6 +242,14 @@ function fetcherImpl(args) {
90
242
  };
91
243
  }
92
244
  else if (error instanceof Error && error.name === "AbortError") {
245
+ if (logger.isError()) {
246
+ const metadata = {
247
+ method: args.method,
248
+ url: redactUrl(url),
249
+ timeoutMs: args.timeoutMs,
250
+ };
251
+ logger.error("HTTP request timed out", metadata);
252
+ }
93
253
  return {
94
254
  ok: false,
95
255
  error: {
@@ -99,6 +259,14 @@ function fetcherImpl(args) {
99
259
  };
100
260
  }
101
261
  else if (error instanceof Error) {
262
+ if (logger.isError()) {
263
+ const metadata = {
264
+ method: args.method,
265
+ url: redactUrl(url),
266
+ errorMessage: error.message,
267
+ };
268
+ logger.error("HTTP request failed with error", metadata);
269
+ }
102
270
  return {
103
271
  ok: false,
104
272
  error: {
@@ -108,6 +276,14 @@ function fetcherImpl(args) {
108
276
  rawResponse: RawResponse_js_1.unknownRawResponse,
109
277
  };
110
278
  }
279
+ if (logger.isError()) {
280
+ const metadata = {
281
+ method: args.method,
282
+ url: redactUrl(url),
283
+ error: (0, json_js_1.toJson)(error),
284
+ };
285
+ logger.error("HTTP request failed with unknown error", metadata);
286
+ }
111
287
  return {
112
288
  ok: false,
113
289
  error: {
@@ -1,7 +1,7 @@
1
1
  export declare namespace GetRequestBody {
2
2
  interface Args {
3
3
  body: unknown;
4
- type: "json" | "file" | "bytes" | "other";
4
+ type: "json" | "file" | "bytes" | "form" | "other";
5
5
  }
6
6
  }
7
7
  export declare function getRequestBody({ body, type }: GetRequestBody.Args): Promise<BodyInit | undefined>;
@@ -11,8 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getRequestBody = getRequestBody;
13
13
  const json_js_1 = require("../json.js");
14
+ const qs_js_1 = require("../url/qs.js");
14
15
  function getRequestBody(_a) {
15
16
  return __awaiter(this, arguments, void 0, function* ({ body, type }) {
17
+ if (type === "form") {
18
+ return (0, qs_js_1.toQueryString)(body, { arrayFormat: "repeat", encode: true });
19
+ }
16
20
  if (type.includes("json")) {
17
21
  return (0, json_js_1.toJson)(body);
18
22
  }
@@ -7,11 +7,12 @@ function mergeHeaders(...headersArray) {
7
7
  for (const [key, value] of headersArray
8
8
  .filter((headers) => headers != null)
9
9
  .flatMap((headers) => Object.entries(headers))) {
10
+ const insensitiveKey = key.toLowerCase();
10
11
  if (value != null) {
11
- result[key] = value;
12
+ result[insensitiveKey] = value;
12
13
  }
13
- else if (key in result) {
14
- delete result[key];
14
+ else if (insensitiveKey in result) {
15
+ delete result[insensitiveKey];
15
16
  }
16
17
  }
17
18
  return result;
@@ -21,8 +22,9 @@ function mergeOnlyDefinedHeaders(...headersArray) {
21
22
  for (const [key, value] of headersArray
22
23
  .filter((headers) => headers != null)
23
24
  .flatMap((headers) => Object.entries(headers))) {
25
+ const insensitiveKey = key.toLowerCase();
24
26
  if (value != null) {
25
- result[key] = value;
27
+ result[insensitiveKey] = value;
26
28
  }
27
29
  }
28
30
  return result;
@@ -1,5 +1,6 @@
1
1
  export * from "./auth/index.js";
2
2
  export * from "./base64.js";
3
3
  export * from "./fetcher/index.js";
4
+ export * as logging from "./logging/index.js";
4
5
  export * from "./runtime/index.js";
5
6
  export * as url from "./url/index.js";
@@ -36,9 +36,10 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  };
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.url = void 0;
39
+ exports.url = exports.logging = void 0;
40
40
  __exportStar(require("./auth/index.js"), exports);
41
41
  __exportStar(require("./base64.js"), exports);
42
42
  __exportStar(require("./fetcher/index.js"), exports);
43
+ exports.logging = __importStar(require("./logging/index.js"));
43
44
  __exportStar(require("./runtime/index.js"), exports);
44
45
  exports.url = __importStar(require("./url/index.js"));
@@ -0,0 +1,18 @@
1
+ import * as logger from "./logger.js";
2
+ export declare namespace logging {
3
+ /**
4
+ * Configuration for logger instances.
5
+ */
6
+ type LogConfig = logger.LogConfig;
7
+ type LogLevel = logger.LogLevel;
8
+ const LogLevel: typeof logger.LogLevel;
9
+ type ILogger = logger.ILogger;
10
+ /**
11
+ * Console logger implementation that outputs to the console.
12
+ */
13
+ type ConsoleLogger = logger.ConsoleLogger;
14
+ /**
15
+ * Console logger implementation that outputs to the console.
16
+ */
17
+ const ConsoleLogger: typeof logger.ConsoleLogger;
18
+ }
@@ -0,0 +1,45 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.logging = void 0;
37
+ const logger = __importStar(require("./logger.js"));
38
+ var logging;
39
+ (function (logging) {
40
+ logging.LogLevel = logger.LogLevel;
41
+ /**
42
+ * Console logger implementation that outputs to the console.
43
+ */
44
+ logging.ConsoleLogger = logger.ConsoleLogger;
45
+ })(logging || (exports.logging = logging = {}));
@@ -0,0 +1 @@
1
+ export * from "./logger.js";
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./logger.js"), exports);