@equinor/fusion-framework-module-http 5.2.3 → 6.0.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/README.md +759 -36
  3. package/dist/esm/configurator.js +10 -1
  4. package/dist/esm/configurator.js.map +1 -1
  5. package/dist/esm/errors.js +18 -0
  6. package/dist/esm/errors.js.map +1 -1
  7. package/dist/esm/index.js +4 -0
  8. package/dist/esm/index.js.map +1 -1
  9. package/dist/esm/lib/client/client-msal.js +35 -0
  10. package/dist/esm/lib/client/client-msal.js.map +1 -1
  11. package/dist/esm/lib/client/client.js +153 -6
  12. package/dist/esm/lib/client/client.js.map +1 -1
  13. package/dist/esm/lib/operators/http-request-handler.js +16 -0
  14. package/dist/esm/lib/operators/http-request-handler.js.map +1 -1
  15. package/dist/esm/lib/operators/http-response-handler.js +6 -0
  16. package/dist/esm/lib/operators/http-response-handler.js.map +1 -1
  17. package/dist/esm/lib/operators/process-operators.js +49 -1
  18. package/dist/esm/lib/operators/process-operators.js.map +1 -1
  19. package/dist/esm/lib/operators/request-operator-header.js +7 -0
  20. package/dist/esm/lib/operators/request-operator-header.js.map +1 -1
  21. package/dist/esm/lib/selectors/blob-selector.js +28 -3
  22. package/dist/esm/lib/selectors/blob-selector.js.map +1 -1
  23. package/dist/esm/lib/selectors/json-selector.js +24 -0
  24. package/dist/esm/lib/selectors/json-selector.js.map +1 -1
  25. package/dist/esm/module.js +40 -0
  26. package/dist/esm/module.js.map +1 -1
  27. package/dist/esm/provider.js +65 -6
  28. package/dist/esm/provider.js.map +1 -1
  29. package/dist/esm/version.js +2 -1
  30. package/dist/esm/version.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/dist/types/configurator.d.ts +76 -0
  33. package/dist/types/errors.d.ts +18 -0
  34. package/dist/types/index.d.ts +4 -0
  35. package/dist/types/lib/client/client-msal.d.ts +43 -0
  36. package/dist/types/lib/client/client.d.ts +147 -3
  37. package/dist/types/lib/client/types.d.ts +156 -5
  38. package/dist/types/lib/operators/http-request-handler.d.ts +16 -0
  39. package/dist/types/lib/operators/http-response-handler.d.ts +6 -0
  40. package/dist/types/lib/operators/process-operators.d.ts +44 -0
  41. package/dist/types/lib/operators/request-operator-header.d.ts +7 -0
  42. package/dist/types/lib/operators/types.d.ts +57 -0
  43. package/dist/types/lib/selectors/blob-selector.d.ts +9 -1
  44. package/dist/types/lib/selectors/index.d.ts +1 -0
  45. package/dist/types/lib/selectors/json-selector.d.ts +16 -1
  46. package/dist/types/module.d.ts +35 -0
  47. package/dist/types/provider.d.ts +77 -0
  48. package/dist/types/version.d.ts +1 -1
  49. package/package.json +5 -5
  50. package/src/configurator.ts +38 -1
  51. package/src/errors.ts +11 -1
  52. package/src/lib/client/client-msal.ts +50 -5
  53. package/src/lib/client/client.ts +161 -12
  54. package/src/lib/client/types.ts +149 -71
  55. package/src/lib/operators/http-request-handler.ts +12 -4
  56. package/src/lib/operators/http-response-handler.ts +6 -0
  57. package/src/lib/operators/process-operators.ts +6 -1
  58. package/src/lib/operators/request-operator-header.ts +7 -0
  59. package/src/lib/operators/types.ts +22 -4
  60. package/src/lib/selectors/blob-selector.ts +26 -4
  61. package/src/lib/selectors/index.ts +2 -0
  62. package/src/lib/selectors/json-selector.ts +29 -9
  63. package/src/module.ts +55 -2
  64. package/src/provider.ts +76 -2
  65. package/src/version.ts +1 -1
@@ -1,18 +1,27 @@
1
1
  import { HttpRequestHandler } from './lib/operators';
2
+ /** @inheritdoc */
2
3
  export class HttpClientConfigurator {
4
+ /** Get a clone of all configured clients */
3
5
  get clients() {
4
6
  return Object.assign({}, this._clients);
5
7
  }
8
+ /**
9
+ * Create a instance of http configuration
10
+ * @param client defaultHttpRequestHandler
11
+ */
6
12
  constructor(client) {
7
13
  this._clients = {};
14
+ /** default request handler for http clients, applied on creation */
8
15
  this.defaultHttpRequestHandler = new HttpRequestHandler();
9
16
  this.defaultHttpClientCtor = client;
10
17
  }
18
+ /** @inheritdoc */
11
19
  hasClient(name) {
12
20
  return Object.keys(this._clients).includes(name);
13
21
  }
22
+ /** @inheritdoc */
14
23
  configureClient(name, args) {
15
- const argFn = typeof args === 'string' ? (x) => (x.uri = String(args)) : args;
24
+ const argFn = typeof args === 'string' ? { baseUri: args } : args;
16
25
  const options = typeof argFn === 'function' ? { onCreate: argFn } : argFn;
17
26
  this._clients[name] = Object.assign(Object.assign({}, this._clients[name]), options);
18
27
  return this;
@@ -1 +1 @@
1
- {"version":3,"file":"configurator.js","sourceRoot":"","sources":["../../src/configurator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAmFrD,MAAM,OAAO,sBAAsB;IAM/B,IAAW,OAAO;QACd,yBAAY,IAAI,CAAC,QAAQ,EAAG;IAChC,CAAC;IAcD,YAAY,MAAsC;QAnBxC,aAAQ,GAA+C,EAAE,CAAC;QAW3D,8BAAyB,GAAG,IAAI,kBAAkB,EAExD,CAAC;QAOA,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC;IACxC,CAAC;IAGD,SAAS,CAAC,IAAY;QAClB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAGD,eAAe,CACX,IAAY,EACZ,IAAsE;QAEtE,MAAM,KAAK,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACjF,MAAM,OAAO,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QAC1E,IAAI,CAAC,QAAQ,CAAC,IAAI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,7 @@
1
+ /**
2
+ * Represents an error that occurs when handling an HTTP response.
3
+ * @template TResponse The type of the HTTP response.
4
+ */
1
5
  export class HttpResponseError extends Error {
2
6
  constructor(message, response, options) {
3
7
  super(message, options);
@@ -5,7 +9,21 @@ export class HttpResponseError extends Error {
5
9
  }
6
10
  }
7
11
  HttpResponseError.Name = 'HttpResponseError';
12
+ /**
13
+ * Represents an error that occurs when handling a JSON response in an HTTP request.
14
+ * Extends the base `HttpResponseError` class.
15
+ *
16
+ * @template TType - The type of the data associated with the error.
17
+ * @template TResponse - The type of the HTTP response.
18
+ */
8
19
  export class HttpJsonResponseError extends HttpResponseError {
20
+ /**
21
+ * Creates a new instance of `HttpJsonResponseError`.
22
+ *
23
+ * @param message - The error message.
24
+ * @param response - The HTTP response associated with the error.
25
+ * @param options - Additional options for the error, including the associated data.
26
+ */
9
27
  constructor(message, response, options) {
10
28
  super(message, response, options);
11
29
  this.name = HttpJsonResponseError.Name;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,iBAAwC,SAAQ,KAAK;IAE9D,YACI,OAAe,EACC,QAAmB,EACnC,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAHR,aAAQ,GAAR,QAAQ,CAAW;IAIvC,CAAC;;AAPM,sBAAI,GAAG,mBAAmB,CAAC;AAetC,MAAM,OAAO,qBAGX,SAAQ,iBAA4B;IAGlC,YAAY,OAAe,EAAE,QAAmB,EAAE,OAAyC;QACvF,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC;IAC9B,CAAC;;AANM,0BAAI,GAAG,uBAAuB,CAAC"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,iBAAwC,SAAQ,KAAK;IAE9D,YACI,OAAe,EACC,QAAmB,EACnC,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAHR,aAAQ,GAAR,QAAQ,CAAW;IAIvC,CAAC;;AAPM,sBAAI,GAAG,mBAAmB,CAAC;AAUtC;;;;;;GAMG;AACH,MAAM,OAAO,qBAGX,SAAQ,iBAA4B;IAIlC;;;;;;OAMG;IACH,YAAY,OAAe,EAAE,QAAmB,EAAE,OAAyC;QACvF,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC;IAC9B,CAAC;;AAdM,0BAAI,GAAG,uBAAuB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * [[include:module-http/README.MD]]
3
+ * @module
4
+ */
1
5
  export * from './configurator';
2
6
  export * from './provider';
3
7
  export * from './module';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AAEzB,cAAc,UAAU,CAAC;AAIzB,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AAEzB,cAAc,UAAU,CAAC;AAIzB,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
@@ -1,10 +1,45 @@
1
1
  import { HttpClient } from './client';
2
+ /**
3
+ * Extends the `HttpClient` class to provide MSAL (Microsoft Authentication Library) authentication support.
4
+ *
5
+ * The `HttpClientMsal` class is responsible for handling requests that require authentication using the MSAL library.
6
+ * It extends the `HttpClient` class and adds the following functionality:
7
+ *
8
+ * - `defaultScopes`: An array of strings representing the default scopes to be used for all requests, unless overridden in the request object.
9
+ * - `fetch$`: Overrides the `fetch$` method of the `HttpClient` class to add MSAL authentication support. It takes an optional `MsalFetchRequestInit` object, which can include the `scopes` property to specify the scopes to be used for the request.
10
+ * - If `scopes` is provided in the `MsalFetchRequestInit` object, it will be used in addition to the `defaultScopes`.
11
+ * - If `scopes` is not provided, only the `defaultScopes` will be used.
12
+ *
13
+ * @template TRequest - The type of the request object. Defaults to `MsalFetchRequest`.
14
+ * @template TResponse - The type of the response object. Defaults to `FetchResponse`.
15
+ */
2
16
  export class HttpClientMsal extends HttpClient {
3
17
  constructor() {
4
18
  super(...arguments);
19
+ /**
20
+ * An array of default scopes to be used for all requests, unless overridden in the request object.
21
+ * This property is used by the `HttpClientMsal` class to add MSAL authentication support to requests.
22
+ */
5
23
  this.defaultScopes = [];
6
24
  }
25
+ /**
26
+ * Fetches a resource from the specified path, with optional MSAL authentication scopes.
27
+ *
28
+ * This method extends the `HttpClient.fetch$` method to add support for MSAL authentication.
29
+ * If `init.scopes` is provided, it will be used in addition to the `defaultScopes` defined in the `HttpClientMsal` class.
30
+ * If `init.scopes` is not provided, only the `defaultScopes` will be used for the request.
31
+ *
32
+ * @overrides HttpClient.fetch$
33
+ *
34
+ * @param path - The path to the resource to fetch.
35
+ * @param init - An optional `MsalFetchRequestInit` object that can include the `scopes` property.
36
+ * @returns An `Observable` that emits the fetched resource.
37
+ */
7
38
  fetch$(path, init) {
39
+ /**
40
+ * Merges the default scopes defined in the `HttpClientMsal` class with the scopes provided in the `init` parameter, if any.
41
+ * This ensures that the request includes the necessary scopes for MSAL authentication.
42
+ */
8
43
  const args = Object.assign(init || {}, {
9
44
  scopes: this.defaultScopes.concat((init === null || init === void 0 ? void 0 : init.scopes) || []),
10
45
  });
@@ -1 +1 @@
1
- {"version":3,"file":"client-msal.js","sourceRoot":"","sources":["../../../../src/lib/client/client-msal.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAWtC,MAAM,OAAO,cAGX,SAAQ,UAA+B;IAHzC;;QAKW,kBAAa,GAAa,EAAE,CAAC;IAYxC,CAAC;IATG,MAAM,CACF,IAAY,EACZ,IAAmD;QAEnD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE;YACnC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,KAAI,EAAE,CAAC;SACxD,CAA6C,CAAC;QAC/C,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;CACJ;AAED,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"client-msal.js","sourceRoot":"","sources":["../../../../src/lib/client/client-msal.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAsBtC;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,cAGX,SAAQ,UAA+B;IAHzC;;QAII;;;WAGG;QACI,kBAAa,GAAa,EAAE,CAAC;IA6BxC,CAAC;IA3BG;;;;;;;;;;;;OAYG;IACI,MAAM,CACT,IAAY,EACZ,IAAmD;QAEnD;;;WAGG;QACH,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE;YACnC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,KAAI,EAAE,CAAC;SACxD,CAA6C,CAAC;QAE/C,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;CACJ;AAED,eAAe,cAAc,CAAC"}
@@ -15,33 +15,84 @@ import { fromFetch } from 'rxjs/fetch';
15
15
  import { HttpRequestHandler, HttpResponseHandler } from '../operators';
16
16
  import { blobSelector, jsonSelector } from '../selectors';
17
17
  import { HttpResponseError } from '../../errors';
18
+ /** Base http client for executing requests */
18
19
  export class HttpClient {
20
+ /**
21
+ * A stream of requests that are about to be executed.
22
+ */
19
23
  get request$() {
20
24
  return this._request$.asObservable();
21
25
  }
26
+ /**
27
+ * A stream of responses that have been received.
28
+ */
22
29
  get response$() {
23
30
  return this._response$.asObservable();
24
31
  }
25
32
  constructor(uri, options) {
26
33
  this.uri = uri;
34
+ /**
35
+ * A stream of requests that are about to be executed.
36
+ * This property is used internally by the `HttpClient` class to manage the lifecycle of requests.
37
+ */
27
38
  this._request$ = new Subject();
39
+ /**
40
+ * A stream of responses that have been received.
41
+ * This property is used internally by the `HttpClient` class to manage the lifecycle of responses.
42
+ */
28
43
  this._response$ = new Subject();
44
+ /**
45
+ * A stream that is used to signal the abortion of requests.
46
+ * This property is used internally by the `HttpClient` class to manage the lifecycle of requests.
47
+ */
29
48
  this._abort$ = new Subject();
30
49
  this.requestHandler = new HttpRequestHandler(options === null || options === void 0 ? void 0 : options.requestHandler);
31
50
  this.responseHandler = new HttpResponseHandler(options === null || options === void 0 ? void 0 : options.responseHandler);
32
51
  this._init();
33
52
  }
53
+ /**
54
+ * Internal method called by child classes to perform initialization logic in the constructor.
55
+ * This method is intended to be overridden by child classes to add their own initialization logic.
56
+ * @protected
57
+ * @virtual
58
+ */
34
59
  _init() {
35
- }
60
+ // called by children for constructor setup
61
+ }
62
+ /**
63
+ * Fetches data from the specified path and returns a stream response.
64
+ *
65
+ * @param path - The path to fetch data from.
66
+ * @param args - Optional request initialization options, including a custom selector function.
67
+ * @returns A stream response containing the fetched data.
68
+ */
36
69
  fetch$(path, args) {
37
70
  return this._fetch$(path, args);
38
71
  }
72
+ /**
73
+ * Fetches data from the specified path and returns a Promise containing the fetched data.
74
+ *
75
+ * @param path - The path to fetch data from.
76
+ * @param args - Optional request initialization options, including a custom selector function.
77
+ * @returns A Promise containing the fetched data.
78
+ */
39
79
  fetch(path, args) {
40
80
  return firstValueFrom(this.fetch$(path, args));
41
81
  }
82
+ /** @deprecated */
42
83
  fetchAsync(path, args) {
43
84
  return this.fetch(path, args);
44
85
  }
86
+ /**
87
+ * Fetches data from the specified path and returns a stream response containing the data in JSON format.
88
+ *
89
+ * @param path - The path to fetch the data from.
90
+ * @param args - Optional request initialization options, including a custom selector function and request body.
91
+ * - `body`: The request body, which will be automatically serialized to JSON if it's an object.
92
+ * - `selector`: A custom selector function to transform the response data. If not provided, the `jsonSelector` function will be used.
93
+ * - `headers`: Additional headers to include in the request. The `Accept` and `Content-Type` headers will be automatically set to `application/json`.
94
+ * @returns A stream response containing the fetched data in JSON format.
95
+ */
45
96
  json$(path, args) {
46
97
  var _a;
47
98
  const body = typeof (args === null || args === void 0 ? void 0 : args.body) === 'object' ? JSON.stringify(args === null || args === void 0 ? void 0 : args.body) : args === null || args === void 0 ? void 0 : args.body;
@@ -53,32 +104,101 @@ export class HttpClient {
53
104
  selector,
54
105
  headers }));
55
106
  }
107
+ /**
108
+ * Fetches data from the specified path and returns a Promise containing the fetched data in JSON format.
109
+ *
110
+ * @param path - The path to fetch the data from.
111
+ * @param args - Optional request initialization options, including a custom selector function and request body.
112
+ * - `body`: The request body, which will be automatically serialized to JSON if it's an object.
113
+ * - `selector`: A custom selector function to transform the response data. If not provided, the `jsonSelector` function will be used.
114
+ * - `headers`: Additional headers to include in the request. The `Accept` and `Content-Type` headers will be automatically set to `application/json`.
115
+ * @returns A Promise containing the fetched data in JSON format.
116
+ */
56
117
  json(path, args) {
57
118
  return firstValueFrom(this.json$(path, args));
58
119
  }
120
+ /**
121
+ * Fetches a blob resource from the specified path and returns a stream response.
122
+ *
123
+ * @param path - The path to the blob resource.
124
+ * @param args - Optional request initialization options, including a custom selector function.
125
+ * @returns A stream response containing the fetched blob data.
126
+ */
59
127
  blob$(path, args) {
60
128
  var _a;
129
+ // Get the selector value from the provided args, or use the default blobSelector
61
130
  const selector = (_a = args === null || args === void 0 ? void 0 : args.selector) !== null && _a !== void 0 ? _a : blobSelector;
62
- return this.fetch$(path, Object.assign(Object.assign({}, args), { selector }));
63
- }
131
+ // Create the FetchRequestInit object with the provided args and the selector
132
+ const init = Object.assign(Object.assign({}, args), { selector });
133
+ // Call the fetch$ method with the provided path and the constructed init object
134
+ return this.fetch$(path, init);
135
+ }
136
+ /**
137
+ * Fetches a blob from the specified path and returns a Promise that resolves to the blob result.
138
+ *
139
+ * @param path - The path to fetch the blob from.
140
+ * @param args - Optional arguments for the fetch request, including request body, headers, and response type.
141
+ * @returns A Promise that resolves to the blob result.
142
+ */
64
143
  blob(path, args) {
65
144
  return firstValueFrom(this.blob$(path, args));
66
145
  }
146
+ /** @deprecated */
67
147
  jsonAsync(path, args) {
68
148
  return this.json(path, args);
69
149
  }
150
+ /**
151
+ * Executes an HTTP request using the specified method and path.
152
+ *
153
+ * @param method - The HTTP method to use for the request, such as 'fetch', 'json', or 'blob'.
154
+ * @param path - The path to the resource to fetch.
155
+ * @param init - Optional request initialization options, including request body, headers, and response type.
156
+ * @returns The result of the HTTP request, which will be of the same type as the return value of the specified method.
157
+ */
70
158
  execute(method, path, init) {
71
159
  return this[method](path, init);
72
160
  }
161
+ /**
162
+ * Aborts any ongoing HTTP requests made by this `IHttpClient` instance.
163
+ * This will trigger the `takeUntil` operator in the `_fetch$` method,
164
+ * causing any in-flight requests to be cancelled.
165
+ */
73
166
  abort() {
74
167
  this._abort$.next();
75
168
  }
169
+ /**
170
+ * Fetches data from the specified path and returns an Observable that emits the response.
171
+ *
172
+ * @param path - The path to fetch the data from.
173
+ * @param args - Optional arguments for the fetch request, including a response selector function, request body, headers, and response type.
174
+ * @returns {Observable<T>} An Observable that emits the response data.
175
+ *
176
+ * This method handles the following steps:
177
+ * 1. Resolves the full URL by combining the base URI and the provided path.
178
+ * 2. Prepares the request by passing it through the `requestHandler.process()` method.
179
+ * 3. Executes the fetch request using the prepared request.
180
+ * 4. Prepares the response by passing it through the `responseHandler.process()` method.
181
+ * 5. Applies the optional response selector function to transform the response data.
182
+ * 6. Cancels the request if the `_abort$` observable emits.
183
+ */
76
184
  _fetch$(path, args) {
77
185
  const _a = args || {}, { selector } = _a, options = __rest(_a, ["selector"]);
78
- const response$ = of(Object.assign(Object.assign({}, options), { uri: this._resolveUrl(path) })).pipe(switchMap((x) => this._prepareRequest(x)), tap((x) => this._request$.next(x)), switchMap((_a) => {
186
+ const response$ = of(Object.assign(Object.assign({}, options), { uri: this._resolveUrl(path) })).pipe(
187
+ /** prepare request, allow extensions to modify request */
188
+ switchMap((x) => this._prepareRequest(x)),
189
+ /** push request to event buss */
190
+ tap((x) => this._request$.next(x)),
191
+ /** execute request */
192
+ switchMap((_a) => {
79
193
  var { uri, path: _path } = _a, init = __rest(_a, ["uri", "path"]);
80
194
  return fromFetch(uri, init);
81
- }), switchMap((x) => this._prepareResponse(x)), tap((x) => this._response$.next(x)), switchMap((response) => {
195
+ }),
196
+ /** prepare response, allow extensions to modify response */
197
+ switchMap((x) => this._prepareResponse(x)),
198
+ /** push response to event buss */
199
+ tap((x) => this._response$.next(x)),
200
+ /** execute selector */
201
+ switchMap((response) => {
82
202
  if (selector) {
83
203
  try {
84
204
  return selector(response);
@@ -90,15 +210,42 @@ export class HttpClient {
90
210
  }
91
211
  }
92
212
  return of(response);
93
- }), takeUntil(this._abort$));
213
+ }),
214
+ /** cancel request on abort signal */
215
+ takeUntil(this._abort$));
94
216
  return response$;
95
217
  }
218
+ /**
219
+ * Prepares the request by passing it through the `requestHandler.process()` method.
220
+ * This method is an implementation detail of the `_fetch$()` method, and is not part of the public API.
221
+ * It takes a `TRequest` object as input, which represents the request data, and returns an `ObservableInput<TRequest>`,
222
+ * which can be used to further process the request before it is executed.
223
+ *
224
+ * @param init The request data to be processed.
225
+ * @returns An `ObservableInput<TRequest>` that represents the processed request.
226
+ */
96
227
  _prepareRequest(init) {
97
228
  return this.requestHandler.process(init);
98
229
  }
230
+ /**
231
+ * Prepares the response by passing it through the `responseHandler.process()` method.
232
+ * This method is an implementation detail of the `_fetch$()` method, and is not part of the public API.
233
+ * It takes a `TResponse` object as input, which represents the response data, and returns an `ObservableInput<TResponse>`,
234
+ * which can be used to further process the response before it is returned.
235
+ *
236
+ * @param response The response data to be processed.
237
+ * @returns An `ObservableInput<TResponse>` that represents the processed response.
238
+ */
99
239
  _prepareResponse(response) {
100
240
  return this.responseHandler.process(response);
101
241
  }
242
+ /**
243
+ * Resolves the full URL for a given path by combining it with the base URL.
244
+ * This is a protected method and is an implementation detail of the `HttpClient` class.
245
+ *
246
+ * @param path - The path to be resolved.
247
+ * @returns The full URL for the given path.
248
+ */
102
249
  _resolveUrl(path) {
103
250
  const baseUrl = this.uri || window.location.origin;
104
251
  return new URL(path, baseUrl).href;
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/lib/client/client.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAY1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAWjD,MAAM,OAAO,UAAU;IAiBnB,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;IAC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;QACvB,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;YACnB,IAAI,QAAQ,EAAE,CAAC;gBACX,IAAI,CAAC;oBACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBAC9B,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACX,MAAM,IAAI,iBAAiB,CACvB,qCAAqC,EACrC,QAAoB,EACpB;wBACI,KAAK,EAAE,GAAG;qBACb,CACJ,CAAC;gBACN,CAAC;YACL,CAAC;YACD,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAC;QACxB,CAAC,CAAC;QACF,qCAAqC;QACrC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAC1B,CAAC;QACF,OAAO,SAAqC,CAAC;IACjD,CAAC;IAED;;;;;;;;OAQG;IACO,eAAe,CAAC,IAAc;QACpC,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;OAQG;IACO,gBAAgB,CAAC,QAAmB;QAC1C,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACO,WAAW,CAAC,IAAY;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnD,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;IACvC,CAAC;CACJ"}
@@ -1,6 +1,22 @@
1
1
  import { ProcessOperators } from './process-operators';
2
2
  import { requestOperatorHeader } from './request-operator-header';
3
+ /**
4
+ * Extends the `ProcessOperators` class to handle HTTP requests.
5
+ *
6
+ * This class provides a method to set a header that will apply to all requests made by the `HttpClient`.
7
+ *
8
+ * @see {@link ProcessOperators}
9
+ *
10
+ * @template T - The type of the fetch request, which extends `FetchRequest`.
11
+ */
3
12
  export class HttpRequestHandler extends ProcessOperators {
13
+ /**
14
+ * Sets a header that will apply to all requests made by the `HttpClient`.
15
+ *
16
+ * @param key - The name of the header to set.
17
+ * @param value - The value of the header to set.
18
+ * @returns The current `HttpRequestHandler` instance, allowing for method chaining.
19
+ */
4
20
  setHeader(key, value) {
5
21
  const operator = requestOperatorHeader(key, value);
6
22
  return this.set('header-' + key, operator);
@@ -1 +1 @@
1
- {"version":3,"file":"http-request-handler.js","sourceRoot":"","sources":["../../../../src/lib/operators/http-request-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAOlE,MAAM,OAAO,kBAA0D,SAAQ,gBAAmB;IAM9F,SAAS,CAAC,GAAW,EAAE,KAAa;QAChC,MAAM,QAAQ,GAAG,qBAAqB,CAAI,GAAG,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,GAAG,EAAE,QAAQ,CAA0B,CAAC;IACxE,CAAC;CACJ;AAED,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"http-request-handler.js","sourceRoot":"","sources":["../../../../src/lib/operators/http-request-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAIlE;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAA0D,SAAQ,gBAAmB;IAC9F;;;;;;OAMG;IACH,SAAS,CAAC,GAAW,EAAE,KAAa;QAChC,MAAM,QAAQ,GAAG,qBAAqB,CAAI,GAAG,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,GAAG,EAAE,QAAQ,CAA0B,CAAC;IACxE,CAAC;CACJ;AAED,eAAe,kBAAkB,CAAC"}
@@ -1,4 +1,10 @@
1
1
  import { ProcessOperators } from './process-operators';
2
+ /**
3
+ * The `HttpResponseHandler` class extends the `ProcessOperators` class and is responsible for handling HTTP responses.
4
+ * It provides a common interface for processing HTTP responses, allowing for consistent error handling and response transformation.
5
+ *
6
+ * @template T - The type of the HTTP response. Defaults to `Response`.
7
+ */
2
8
  export class HttpResponseHandler extends ProcessOperators {
3
9
  }
4
10
  export default HttpResponseHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"http-response-handler.js","sourceRoot":"","sources":["../../../../src/lib/operators/http-response-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,OAAO,mBAAkC,SAAQ,gBAAmB;CAAG;AAE7E,eAAe,mBAAmB,CAAC"}
1
+ {"version":3,"file":"http-response-handler.js","sourceRoot":"","sources":["../../../../src/lib/operators/http-response-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,OAAO,mBAAkC,SAAQ,gBAAmB;CAAG;AAE7E,eAAe,mBAAmB,CAAC"}
@@ -1,9 +1,25 @@
1
1
  import { from, of } from 'rxjs';
2
2
  import { last, mergeScan } from 'rxjs/operators';
3
+ /**
4
+ * ProcessOperators class manages a collection of process operators
5
+ * and provides methods to add, set, get, and process these operators.
6
+ * It implements the IProcessOperators interface for type T.
7
+ *
8
+ * @template T The type of data that the process operators work with
9
+ */
3
10
  export class ProcessOperators {
11
+ /**
12
+ * Accessor for the collection of process operators.
13
+ * @returns The record of process operators.
14
+ */
4
15
  get operators() {
5
16
  return this._operators;
6
17
  }
18
+ /**
19
+ * Constructs a new instance of the ProcessOperators class.
20
+ * @param operators - An optional object containing process operators.
21
+ * It can be either an instance of IProcessOperators<T> or a record of string keys and ProcessOperator<T> values.
22
+ */
7
23
  constructor(operators) {
8
24
  if (operators && 'operators' in operators) {
9
25
  this._operators = Object.assign({}, operators.operators);
@@ -12,24 +28,56 @@ export class ProcessOperators {
12
28
  this._operators = operators !== null && operators !== void 0 ? operators : {};
13
29
  }
14
30
  }
31
+ /**
32
+ * Adds a new operator to the collection.
33
+ * @param key The key under which the operator is stored.
34
+ * @param operator The operator to be added.
35
+ * @returns The instance of ProcessOperators for chaining.
36
+ * @throws Error if an operator with the same key already exists.
37
+ */
15
38
  add(key, operator) {
16
39
  if (Object.keys(this._operators).includes(key))
17
40
  throw Error(`Operator [${key}] already defined`);
18
41
  return this.set(key, operator);
19
42
  }
43
+ /**
44
+ * Sets or updates an operator in the collection.
45
+ * @param key The key under which the operator is stored.
46
+ * @param operator The operator to be set.
47
+ * @returns The instance of ProcessOperators for chaining.
48
+ */
20
49
  set(key, operator) {
21
50
  this._operators[key] = operator;
22
51
  return this;
23
52
  }
53
+ /**
54
+ * Retrieves an operator from the collection by its key.
55
+ * @param key The key of the operator to retrieve.
56
+ * @returns The retrieved operator.
57
+ */
24
58
  get(key) {
25
59
  return this._operators[key];
26
60
  }
61
+ /**
62
+ * Processes an input request through the chain of operators.
63
+ * @param request The request to be processed.
64
+ * @returns An Observable of the processed request.
65
+ */
27
66
  process(request) {
28
67
  const operators = Object.values(this._operators);
68
+ /** if no operators registered, just return the observable value */
29
69
  if (!operators.length) {
30
70
  return of(request);
31
71
  }
32
- return from(Object.values(this._operators)).pipe(mergeScan((value, operator) => Promise.resolve(operator(value)).then((x) => x !== null && x !== void 0 ? x : value), request, 1), last());
72
+ return from(Object.values(this._operators)).pipe(mergeScan(
73
+ // resolve current operator and return result or previous if void
74
+ (value, operator) => Promise.resolve(operator(value)).then((x) => x !== null && x !== void 0 ? x : value),
75
+ // initial value
76
+ request,
77
+ // only allow concurrency of one operator
78
+ 1),
79
+ // output result of last operator
80
+ last());
33
81
  }
34
82
  }
35
83
  //# sourceMappingURL=process-operators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"process-operators.js","sourceRoot":"","sources":["../../../../src/lib/operators/process-operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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EAAE,QAA4B;QACzC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAW;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,OAAU;QACd,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,mEAAmE;QACnE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAC5C,SAAS;QACL,iEAAiE;QACjE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAD,CAAC,cAAD,CAAC,GAAI,KAAK,CAAC;QAC7E,gBAAgB;QAChB,OAAO;QACP,yCAAyC;QACzC,CAAC,CACJ;QACD,iCAAiC;QACjC,IAAI,EAAE,CACT,CAAC;IACN,CAAC;CACJ"}
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Creates a process operator that adds a header to the request.
3
+ *
4
+ * @param key - The header key to add.
5
+ * @param value - The header value to add.
6
+ * @returns A process operator that adds the specified header to the request.
7
+ */
1
8
  export const requestOperatorHeader = (key, value) => (request) => {
2
9
  const headers = new Headers(request.headers);
3
10
  headers.append(key, value);
@@ -1 +1 @@
1
- {"version":3,"file":"request-operator-header.js","sourceRoot":"","sources":["../../../../src/lib/operators/request-operator-header.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,qBAAqB,GAC9B,CAAwC,GAAW,EAAE,KAAa,EAAsB,EAAE,CAC1F,CAAC,OAAO,EAAE,EAAE;IACR,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC3B,uCAAY,OAAO,KAAE,OAAO,IAAG;AACnC,CAAC,CAAC;AAEN,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"request-operator-header.js","sourceRoot":"","sources":["../../../../src/lib/operators/request-operator-header.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAC9B,CAAwC,GAAW,EAAE,KAAa,EAAsB,EAAE,CAC1F,CAAC,OAAO,EAAE,EAAE;IACR,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC3B,uCAAY,OAAO,KAAE,OAAO,IAAG;AACnC,CAAC,CAAC;AAEN,eAAe,qBAAqB,CAAC"}
@@ -1,16 +1,41 @@
1
- export const blobSelector = (response) => {
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * Extracts a blob and filename from a successful HTTP response.
12
+ *
13
+ * @param response - The HTTP response to extract the blob and filename from.
14
+ * @returns A promise that resolves to an object containing the extracted blob and filename.
15
+ * @throws {Error} If the response is not successful or if there is an error parsing the response.
16
+ */
17
+ export const blobSelector = (response) => __awaiter(void 0, void 0, void 0, function* () {
18
+ var _a, _b, _c;
2
19
  if (!response.ok) {
20
+ // Throw an error if the network response is not successful
3
21
  throw new Error('network response was not OK');
4
22
  }
23
+ // Status code 204 indicates no content, so throw an error
5
24
  if (response.status === 204) {
6
25
  throw new Error('no content');
7
26
  }
27
+ // Extract the filename from the 'content-disposition' header
28
+ const filename = (_c = (_b = (_a = response.headers
29
+ .get('content-disposition')) === null || _a === void 0 ? void 0 : _a.split(';').find((n) => n.includes('filename='))) === null || _b === void 0 ? void 0 : _b.replace('filename=', '')) === null || _c === void 0 ? void 0 : _c.trim();
8
30
  try {
9
- return response.blob();
31
+ // Convert the response to a Blob and return the filename and Blob
32
+ const blob = yield response.blob();
33
+ return { filename, blob };
10
34
  }
11
35
  catch (err) {
36
+ // Throw an error if there's a problem parsing the response
12
37
  throw Error('failed to parse response');
13
38
  }
14
- };
39
+ });
15
40
  export default blobSelector;
16
41
  //# sourceMappingURL=blob-selector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"blob-selector.js","sourceRoot":"","sources":["../../../../src/lib/selectors/blob-selector.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,CACxB,QAAmB,EACN,EAAE;IACf,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC5C,CAAC;AACL,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"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