@controlium/utils 1.0.2-alpha.3 → 1.0.2-alpha.5

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,6 +1,6 @@
1
1
  import { Agent, Headers, ProxyAgent, fetch } from 'undici';
2
2
  import { Log, LogLevels, Utils } from '../index';
3
- export class EAAPIUtils {
3
+ export class APIUtils {
4
4
  /**
5
5
  * Verify if HTTP server listening
6
6
  * @param url
@@ -111,10 +111,12 @@ export class EAAPIUtils {
111
111
  dispatcher,
112
112
  });
113
113
  const responseBody = await fetchResponse.text();
114
- this.doResponseLogging(fetchResponse.status, fetchResponse.statusText, responseBody);
114
+ const responseHeaders = Object.fromEntries(fetchResponse.headers.entries());
115
+ this.doResponseLogging(fetchResponse.status, fetchResponse.statusText, responseHeaders, responseBody);
115
116
  return {
116
117
  status: fetchResponse.status,
117
118
  statusMessage: fetchResponse.statusText,
119
+ headers: responseHeaders,
118
120
  body: responseBody,
119
121
  };
120
122
  }
@@ -197,9 +199,21 @@ export class EAAPIUtils {
197
199
  }
198
200
  }
199
201
  }
200
- static doResponseLogging(status, statusText, body) {
202
+ static doResponseLogging(status, statusText, headers, body) {
201
203
  Log.writeLine(LogLevels.FrameworkInformation, 'HTTP Response:-');
202
204
  Log.writeLine(LogLevels.FrameworkInformation, ` Status [${status}] - [${statusText}]`);
205
+ Log.writeLine(LogLevels.FrameworkInformation, ' Headers;');
206
+ const headerEntries = Object.entries(headers);
207
+ if (headerEntries.length === 0) {
208
+ Log.writeLine(LogLevels.FrameworkInformation, ' <No headers!>');
209
+ }
210
+ else {
211
+ let headersStr = '';
212
+ headerEntries.forEach(([key, value]) => {
213
+ headersStr += `${headersStr === '' ? '' : '\n'} "${key}": "${value}"`;
214
+ });
215
+ Log.writeLine(LogLevels.FrameworkInformation, headersStr);
216
+ }
203
217
  Log.writeLine(LogLevels.FrameworkInformation, ' Body;');
204
218
  let indented = '';
205
219
  if (body) {
@@ -212,7 +226,7 @@ export class EAAPIUtils {
212
226
  }
213
227
  }
214
228
  // eslint-disable-next-line @typescript-eslint/no-namespace
215
- (function (EAAPIUtils) {
229
+ (function (APIUtils) {
216
230
  /**
217
231
  * Generic Http call methods
218
232
  */
@@ -221,6 +235,6 @@ export class EAAPIUtils {
221
235
  HttpMethods["POST"] = "POST";
222
236
  HttpMethods["GET"] = "GET";
223
237
  HttpMethods["PUT"] = "PUT";
224
- })(HttpMethods = EAAPIUtils.HttpMethods || (EAAPIUtils.HttpMethods = {}));
225
- EAAPIUtils.APPLICATION_JSON = 'application/json';
226
- })(EAAPIUtils || (EAAPIUtils = {}));
238
+ })(HttpMethods = APIUtils.HttpMethods || (APIUtils.HttpMethods = {}));
239
+ APIUtils.APPLICATION_JSON = 'application/json';
240
+ })(APIUtils || (APIUtils = {}));
package/dist/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Logger } from "./logger/logger";
2
2
  export { Logger, Logger as Log };
3
3
  export const LogLevels = Logger.Levels;
4
+ export { APIUtils } from "./apiUtils/APIUtils";
4
5
  export { JsonUtils } from "./jsonUtils/jsonUtils";
5
6
  export { StringUtils } from "./stringUtils/stringUtils";
6
7
  export { Utils, ExistingFileWriteActions } from "./utils/utils";
@@ -1,4 +1,4 @@
1
- export declare class EAAPIUtils {
1
+ export declare class APIUtils {
2
2
  /**
3
3
  * Verify if HTTP server listening
4
4
  * @param url
@@ -38,14 +38,14 @@ export declare class EAAPIUtils {
38
38
  * @throws Error if there is any fail that results in a Response not being received.
39
39
  * The caller-supplied timeout (or the default 10s) is enforced as a hard failsafe via AbortSignal.
40
40
  */
41
- static performHTTPOperation(httpRequest: EAAPIUtils.HTTPRequest): Promise<EAAPIUtils.HTTPResponse>;
41
+ static performHTTPOperation(httpRequest: APIUtils.HTTPRequest): Promise<APIUtils.HTTPResponse>;
42
42
  private static buildURL;
43
43
  private static buildDispatcher;
44
44
  private static buildHeaders;
45
45
  private static doRequestLogging;
46
46
  private static doResponseLogging;
47
47
  }
48
- export declare namespace EAAPIUtils {
48
+ export declare namespace APIUtils {
49
49
  /**
50
50
  * Generic HTTP call Header items
51
51
  */
@@ -81,6 +81,7 @@ export declare namespace EAAPIUtils {
81
81
  type HTTPResponse = {
82
82
  status: number;
83
83
  statusMessage: string;
84
+ headers: Record<string, string>;
84
85
  body: string;
85
86
  };
86
87
  type HTTPInteraction = {
@@ -12,6 +12,7 @@ export declare const LogLevels: {
12
12
  readonly NoOutput: 0;
13
13
  };
14
14
  export type { LogLevel, VideoOptions, WriteLineOptions, LogOutputCallbackSignature, } from "./logger/types";
15
+ export { APIUtils } from "./apiUtils/APIUtils";
15
16
  export { JsonUtils } from "./jsonUtils/jsonUtils";
16
17
  export { StringUtils } from "./stringUtils/stringUtils";
17
18
  export { Utils, ExistingFileWriteActions } from "./utils/utils";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@controlium/utils",
3
- "version": "1.0.2-alpha.3",
3
+ "version": "1.0.2-alpha.5",
4
4
  "description": "Shared utilities for Controlium-based projects",
5
5
  "type": "module",
6
6
  "author": "Team Controllium contributors",