@zcatalyst/transport 0.0.2 → 0.0.3

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 (39) hide show
  1. package/LICENCE +55 -1
  2. package/README.md +266 -0
  3. package/dist-cjs/fetch-handler.js +67 -64
  4. package/dist-cjs/http-handler.js +25 -23
  5. package/dist-cjs/index.browser.js +8 -3
  6. package/dist-cjs/index.js +9 -7
  7. package/dist-cjs/utils/clonable-stream.js +1 -1
  8. package/dist-cjs/utils/form-data.js +11 -5
  9. package/dist-cjs/utils/request-agent.js +1 -1
  10. package/dist-es/fetch-handler.js +64 -64
  11. package/dist-es/http-handler.js +25 -24
  12. package/dist-es/index.browser.js +3 -2
  13. package/dist-es/index.js +3 -5
  14. package/dist-es/utils/clonable-stream.js +0 -1
  15. package/dist-es/utils/form-data.js +10 -5
  16. package/dist-es/utils/request-agent.js +0 -1
  17. package/dist-types/fetch-handler.d.ts +115 -6
  18. package/dist-types/http-handler.d.ts +48 -8
  19. package/dist-types/index.browser.d.ts +17 -1
  20. package/dist-types/index.d.ts +22 -2
  21. package/dist-types/ts3.4/fetch-handler.d.ts +115 -6
  22. package/dist-types/ts3.4/http-handler.d.ts +48 -8
  23. package/dist-types/ts3.4/index.browser.d.ts +17 -1
  24. package/dist-types/ts3.4/index.d.ts +22 -2
  25. package/dist-types/ts3.4/utils/clonable-stream.d.ts +54 -0
  26. package/dist-types/ts3.4/utils/errors.d.ts +7 -0
  27. package/dist-types/ts3.4/utils/form-data.d.ts +242 -1
  28. package/dist-types/ts3.4/utils/helpers.d.ts +12 -0
  29. package/dist-types/ts3.4/utils/interfaces.d.ts +5 -1
  30. package/dist-types/ts3.4/utils/request-agent.d.ts +6 -0
  31. package/dist-types/ts3.4/utils/request-timeout.d.ts +12 -0
  32. package/dist-types/utils/clonable-stream.d.ts +54 -0
  33. package/dist-types/utils/errors.d.ts +7 -0
  34. package/dist-types/utils/form-data.d.ts +242 -1
  35. package/dist-types/utils/helpers.d.ts +12 -0
  36. package/dist-types/utils/interfaces.d.ts +5 -1
  37. package/dist-types/utils/request-agent.d.ts +6 -0
  38. package/dist-types/utils/request-timeout.d.ts +12 -0
  39. package/package.json +31 -6
package/LICENCE CHANGED
@@ -1 +1,55 @@
1
- ln -s ../../LICENSE packages/transport/LICENSE
1
+ Zoho Catalyst SDK
2
+
3
+ Copyright (c) 2025 Zoho Corporation Private Limited
4
+
5
+
6
+ Apache License Version 2.0
7
+ http://www.apache.org/licenses/
8
+
9
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
10
+
11
+ 1. Definitions.
12
+
13
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
14
+
15
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
18
+
19
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
20
+
21
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
22
+
23
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
24
+
25
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
26
+
27
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
28
+
29
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
30
+
31
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
32
+
33
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
34
+
35
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
36
+
37
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
38
+
39
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
40
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
41
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
43
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -0,0 +1,266 @@
1
+ # @zcatalyst/transport
2
+
3
+ HTTP Transport Layer for Catalyst SDK - Internal Communication Module
4
+
5
+ ## Overview
6
+
7
+ The `@zcatalyst/transport` package provides the `Handler` class and request/response types used by Catalyst SDK packages to send HTTP requests. It has Node.js and browser entry points.
8
+
9
+ ### Prerequisites
10
+
11
+ - Typically installed as a dependency of other Catalyst packages
12
+ - Not required to be installed separately unless building custom integrations
13
+
14
+ ## Installation
15
+
16
+ To install this package, simply type add or install @zcatalyst/transport
17
+ using your favorite package manager:
18
+
19
+ - `npm install @zcatalyst/transport`
20
+ - `yarn add @zcatalyst/transport`
21
+ - `pnpm add @zcatalyst/transport`
22
+
23
+ ## Getting Started
24
+
25
+ ### Import
26
+
27
+ To use the transport handler, import `Handler`:
28
+
29
+ ```js
30
+ // ES5 example
31
+ const { Handler } = require("@zcatalyst/transport");
32
+ ```
33
+
34
+ ```ts
35
+ // ES6+ example
36
+ import { Handler } from "@zcatalyst/transport";
37
+ ```
38
+
39
+ ### Usage
40
+
41
+ #### Node.js Environment
42
+
43
+ For server-side HTTP requests using Node.js built-in modules:
44
+
45
+ ```js
46
+ const handler = new Handler(app, component);
47
+
48
+ // Send HTTP request
49
+ const response = await handler.send({
50
+ method: 'GET',
51
+ url: '/api/data',
52
+ headers: {
53
+ 'Content-Type': 'application/json'
54
+ }
55
+ });
56
+ ```
57
+
58
+ #### Browser Environment
59
+
60
+ For client-side HTTP requests using Fetch API:
61
+
62
+ ```js
63
+ const handler = new Handler(app, component);
64
+
65
+ // Send HTTP request
66
+ const response = await handler.send({
67
+ method: 'POST',
68
+ url: '/api/data',
69
+ headers: {
70
+ 'Content-Type': 'application/json'
71
+ },
72
+ data: {
73
+ name: 'example',
74
+ value: 123
75
+ }
76
+ });
77
+ ```
78
+
79
+ ### Request Configuration
80
+
81
+ The `send` method accepts an `IRequestConfig` object:
82
+
83
+ ```js
84
+ const config = {
85
+ method: 'POST', // HTTP method: GET, POST, PUT, DELETE, etc.
86
+ url: '/api/endpoint', // API endpoint
87
+ headers: { // HTTP headers
88
+ 'Content-Type': 'application/json',
89
+ 'Authorization': 'Bearer token'
90
+ },
91
+ data: { // Request body (JSON)
92
+ key: 'value'
93
+ },
94
+ qs: { // URL query parameters
95
+ page: 1,
96
+ limit: 10
97
+ }
98
+ };
99
+ ```
100
+
101
+ ### Async/await
102
+
103
+ We recommend using [await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)
104
+ operator to wait for the promise returned by HTTP requests:
105
+
106
+ ```js
107
+ // async/await.
108
+ try {
109
+ const response = await handler.send(config);
110
+ // process response.
111
+ } catch (error) {
112
+ // error handling.
113
+ } finally {
114
+ // finally.
115
+ }
116
+ ```
117
+
118
+ ### Error Handling
119
+
120
+
121
+ ```js
122
+ try {
123
+ const response = await handler.send(config);
124
+ // process response.
125
+ } catch (error) {
126
+ const message = error.message;
127
+ const status = error.statusCode;
128
+ console.log({ message, status });
129
+ }
130
+ ```
131
+
132
+ ## Method Details
133
+
134
+ ### Transport Operations
135
+
136
+ <details>
137
+ <summary>
138
+ Create Handler Instance
139
+ </summary>
140
+
141
+ ```js
142
+ const handler = new Handler(app, component);
143
+ ```
144
+
145
+ - `app`: Catalyst app instance (optional)
146
+ - `component`: Component instance for request context (optional)
147
+
148
+ </details>
149
+
150
+ <details>
151
+ <summary>
152
+ Send GET Request
153
+ </summary>
154
+
155
+ ```js
156
+ const response = await handler.send({
157
+ method: 'GET',
158
+ url: '/api/users',
159
+ params: {
160
+ page: 1,
161
+ limit: 10
162
+ }
163
+ });
164
+ ```
165
+
166
+ </details>
167
+
168
+ <details>
169
+ <summary>
170
+ Send POST Request
171
+ </summary>
172
+
173
+ ```js
174
+ const response = await handler.send({
175
+ method: 'POST',
176
+ url: '/api/users',
177
+ headers: {
178
+ 'Content-Type': 'application/json'
179
+ },
180
+ data: {
181
+ name: 'John Doe',
182
+ email: 'john@example.com'
183
+ }
184
+ });
185
+ ```
186
+
187
+ </details>
188
+
189
+ <details>
190
+ <summary>
191
+ Send PUT Request
192
+ </summary>
193
+
194
+ ```js
195
+ const response = await handler.send({
196
+ method: 'PUT',
197
+ url: '/api/users/123',
198
+ headers: {
199
+ 'Content-Type': 'application/json'
200
+ },
201
+ data: {
202
+ name: 'Jane Doe',
203
+ email: 'jane@example.com'
204
+ }
205
+ });
206
+ ```
207
+
208
+ </details>
209
+
210
+ <details>
211
+ <summary>
212
+ Send DELETE Request
213
+ </summary>
214
+
215
+ ```js
216
+ const response = await handler.send({
217
+ method: 'DELETE',
218
+ url: '/api/users/123'
219
+ });
220
+ ```
221
+
222
+ </details>
223
+
224
+ <details>
225
+ <summary>
226
+ Handle File Upload
227
+ </summary>
228
+
229
+ ```js
230
+ const formData = new FormData();
231
+ formData.append('file', fileInput.files[0]);
232
+ formData.append('description', 'Profile picture');
233
+
234
+ const response = await handler.send({
235
+ method: 'POST',
236
+ url: '/api/upload',
237
+ headers: {
238
+ 'Content-Type': 'multipart/form-data'
239
+ },
240
+ data: formData
241
+ });
242
+ ```
243
+
244
+ </details>
245
+
246
+ ### Environment Support
247
+
248
+ This package has separate Node.js and browser entry points:
249
+
250
+ - **Node.js**: Uses built-in `http` and `https` modules
251
+ - **Browser**: Uses Fetch API
252
+
253
+ ## Resources
254
+
255
+ - [Catalyst SDK Documentation](https://docs.catalyst.zoho.com/en/sdk/)
256
+ - [Catalyst API Reference](https://docs.catalyst.zoho.com/en/sdk/)
257
+ - [Node.js HTTP Module](https://nodejs.org/api/http.html)
258
+ - [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
259
+
260
+ ## Contributing
261
+
262
+ See [CONTRIBUTING](../../CONTRIBUTING.md) for more information on how to get started.
263
+
264
+ ## License
265
+
266
+ This SDK is distributed under the Apache License 2.0. See [LICENSE](../../LICENCE) file for more information.
@@ -4,18 +4,20 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
5
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
6
  };
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
7
10
  var _a, _ResponseHandler_attachAppSpecificHeaders, _ResponseHandler_followZcrfTokenProtocol, _ResponseHandler_followJwtZCAuthProtocol, _ResponseHandler_sendRequest;
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.ResponseHandler = exports.DefaultHttpResponse = exports.keepAliveSupport = void 0;
12
+ exports.ResponseHandler = exports.DefaultHttpResponse = void 0;
10
13
  const auth_client_1 = require("@zcatalyst/auth-client");
11
14
  const utils_1 = require("@zcatalyst/utils");
15
+ const package_json_1 = __importDefault(require("../package.json"));
16
+ const { version } = package_json_1.default;
12
17
  const constants_1 = require("./utils/constants");
13
18
  const errors_1 = require("./utils/errors");
14
19
  const request_timeout_1 = require("./utils/request-timeout");
15
20
  const { REQ_METHOD } = utils_1.CONSTANTS;
16
- exports.keepAliveSupport = {
17
- supported: undefined
18
- };
19
21
  class DefaultHttpResponse {
20
22
  constructor(resp) {
21
23
  this.statusCode = resp.statusCode;
@@ -37,13 +39,16 @@ class ResponseHandler {
37
39
  static async fireGeneralRequest({ requestCore, url }, requestOptions = {}) {
38
40
  try {
39
41
  const headers = requestCore.headers || {};
42
+ const method = requestCore.method;
43
+ const methodAllowsBody = method !== REQ_METHOD.get && method !== REQ_METHOD.head;
40
44
  const options = {
41
- method: requestCore.method,
45
+ method,
42
46
  headers,
43
47
  credentials: requestOptions.auth ? 'include' : 'omit',
44
- body: requestCore.method !== REQ_METHOD.get ? requestCore.body : undefined
48
+ body: methodAllowsBody ? requestCore.body : undefined
45
49
  };
46
- if (requestOptions.auth) {
50
+ const isExternal = requestOptions.service === "external";
51
+ if (requestOptions.auth && !isExternal) {
47
52
  options.headers = await _a.attachZCAuthHeaders(headers);
48
53
  options.headers = __classPrivateFieldGet(this, _a, "m", _ResponseHandler_attachAppSpecificHeaders).call(this, headers);
49
54
  }
@@ -67,7 +72,7 @@ class ResponseHandler {
67
72
  request: requestCore
68
73
  });
69
74
  }
70
- catch (error) {
75
+ catch {
71
76
  requestOptions.retry--;
72
77
  return this.fireGeneralRequest({ requestCore, url }, requestOptions);
73
78
  }
@@ -92,22 +97,29 @@ class ResponseHandler {
92
97
  }
93
98
  static async wrapResponse(response, options) {
94
99
  try {
100
+ const method = options?.request?.method?.toUpperCase();
101
+ const hasNoBody = method === REQ_METHOD.head || response.status === 204 || response.status === 304;
95
102
  let data;
96
- switch (options?.expecting || "json") {
97
- case "buffer":
98
- data = await response.arrayBuffer();
99
- break;
100
- case "raw":
101
- data = await response.blob();
102
- break;
103
- case "json":
104
- data = await response.json();
105
- break;
106
- case "string":
107
- data = await response.text();
108
- break;
109
- default:
110
- throw new errors_1.CatalystAPIError('UNSUPPORTED_RESPONSE_TYPE', `Unsupported response type: ${options?.expecting}`);
103
+ if (hasNoBody) {
104
+ data = '';
105
+ }
106
+ else {
107
+ switch (options?.expecting || "json") {
108
+ case "buffer":
109
+ data = await response.arrayBuffer();
110
+ break;
111
+ case "raw":
112
+ data = await response.blob();
113
+ break;
114
+ case "json":
115
+ data = await response.json();
116
+ break;
117
+ case "string":
118
+ data = await response.text();
119
+ break;
120
+ default:
121
+ throw new errors_1.CatalystAPIError('UNSUPPORTED_RESPONSE_TYPE', `Unsupported response type: ${options?.expecting}`);
122
+ }
111
123
  }
112
124
  return new DefaultHttpResponse({
113
125
  headers: response.headers,
@@ -134,31 +146,30 @@ class ResponseHandler {
134
146
  };
135
147
  if (requestCore.method !== REQ_METHOD.get && requestCore.body !== null)
136
148
  options.body = requestCore.body;
137
- const url = this.configManager.APIDomain
138
- ? `${this.configManager.APIDomain}${requestCore.url}`
139
- : requestCore.url;
149
+ const url = this.apiDomain ? `${this.apiDomain}${requestCore.url}` : requestCore.url;
140
150
  return await this.wrapResponse(await fetch(url, options));
141
151
  }
142
- static attachZCAuthHeaders(headers) {
143
- switch (this.configManager.AuthProtocol) {
152
+ static async attachZCAuthHeaders(headers) {
153
+ const authProtocol = auth_client_1.ConfigStore.get('AUTH_PROTOCOL');
154
+ switch (authProtocol) {
144
155
  case auth_client_1.Auth_Protocol.ZcrfTokenProtocol:
145
- return __classPrivateFieldGet(_a, _a, "m", _ResponseHandler_followZcrfTokenProtocol).call(_a, headers);
156
+ return await __classPrivateFieldGet(_a, _a, "m", _ResponseHandler_followZcrfTokenProtocol).call(_a, headers);
146
157
  case auth_client_1.Auth_Protocol.JwtTokenProtocol:
147
- return __classPrivateFieldGet(_a, _a, "m", _ResponseHandler_followJwtZCAuthProtocol).call(_a, headers);
158
+ return await __classPrivateFieldGet(_a, _a, "m", _ResponseHandler_followJwtZCAuthProtocol).call(_a, headers);
148
159
  default:
149
160
  return Promise.resolve(headers);
150
161
  }
151
162
  }
152
163
  static getJWTZCAuthToken() {
153
- const conf = auth_client_1.ConfigManager.getInstance();
164
+ const jwtPrefix = auth_client_1.ConfigStore.get(auth_client_1.JWT_COOKIE_PREFIX);
154
165
  return new Promise((resolve, reject) => {
155
- const jwtZCAuthToken = (0, utils_1.getToken)();
166
+ const jwtZCAuthToken = (0, auth_client_1.getToken)();
156
167
  if (jwtZCAuthToken === '') {
157
168
  reject('Unable to get the JWT Access Token.');
158
169
  }
159
170
  else {
160
171
  resolve({
161
- access_token: `${conf.jwtAuthTokenPrefix} ${jwtZCAuthToken}`
172
+ access_token: `${jwtPrefix} ${jwtZCAuthToken}`
162
173
  });
163
174
  }
164
175
  });
@@ -175,8 +186,16 @@ class ResponseHandler {
175
186
  const existingParams = url.split('?')[1] || '';
176
187
  return `${baseUrl}?${existingParams ? `${existingParams}&` : ''}${searchParams.toString()}`;
177
188
  }
178
- static async send(options) {
189
+ static async send(options, componentName, componentVersion) {
179
190
  const headers = options.headers || {};
191
+ const isExternal = options.service === "external";
192
+ if (!isExternal) {
193
+ let userAgent = utils_1.CONSTANTS.USER_AGENT.PREFIX + version;
194
+ if (componentName) {
195
+ userAgent += ` ${componentName}/${componentVersion || 'unknown'}`;
196
+ }
197
+ headers['X-Catalyst-User-Agent'] = userAgent;
198
+ }
180
199
  let data = options.data;
181
200
  if (data !== undefined) {
182
201
  switch (options.type) {
@@ -193,25 +212,24 @@ class ResponseHandler {
193
212
  data = formData;
194
213
  break;
195
214
  case "raw":
196
- data = JSON.stringify(data);
197
215
  if (headers['Content-Type'] === undefined) {
198
216
  headers['Content-Type'] = 'application/octet-stream';
199
217
  }
218
+ data = new Blob([data], { type: headers['Content-Type'] });
200
219
  break;
201
220
  default:
202
221
  data = JSON.stringify(data);
203
222
  headers['Content-Type'] = 'application/x-www-form-urlencoded';
204
- headers['Content-Length'] = Buffer.byteLength(data) + '';
205
223
  }
206
224
  }
207
- if (this.configManager.APIDomain === null && !options.origin) {
225
+ if (this.apiDomain === null && !options.origin) {
208
226
  throw new errors_1.CatalystAPIError('API_REQUEST_ERROR', 'Unable to get the base url');
209
227
  }
210
- if (options.service !== "external" && options.path) {
211
- options.path = `${(0, utils_1.getServicePath)(options.service)}/project/${this.configManager.ProjectID}${options.path}`;
228
+ if (!isExternal && options.path) {
229
+ options.path = `${(0, utils_1.getServicePath)(options.service)}/project/${auth_client_1.ConfigStore.get(auth_client_1.PROJECT_ID)}${options.path}`;
212
230
  }
213
231
  const request = {
214
- url: options.url ?? `${options.origin ?? this.configManager.APIDomain}${options.path}`,
232
+ url: options.url ?? `${options.origin ?? this.apiDomain}${options.path}`,
215
233
  method: options.method,
216
234
  ...(data ? { body: data } : {}),
217
235
  headers
@@ -219,36 +237,21 @@ class ResponseHandler {
219
237
  request.url = this.appendQueryString(request.url, options.qs);
220
238
  return await __classPrivateFieldGet(this, _a, "m", _ResponseHandler_sendRequest).call(this, request, {
221
239
  expecting: options.expecting,
222
- auth: options.auth ?? true
240
+ auth: options.auth ?? true,
241
+ service: options.service
223
242
  });
224
243
  }
225
244
  }
226
245
  exports.ResponseHandler = ResponseHandler;
227
246
  _a = ResponseHandler, _ResponseHandler_attachAppSpecificHeaders = function _ResponseHandler_attachAppSpecificHeaders(headers) {
228
- const normalizedHeaders = headers;
229
- const currentAccept = normalizedHeaders['Accept'];
230
- if (!currentAccept) {
231
- normalizedHeaders['Accept'] = 'application/vnd.catalyst.v2+json';
232
- }
233
- else {
234
- normalizedHeaders['Accept'] = `application/vnd.catalyst.v2+json, ${currentAccept}`;
235
- }
236
- if (typeof this.configManager?.OrgId === 'string') {
237
- normalizedHeaders['CATALYST-ORG'] = this.configManager.OrgId;
238
- }
239
- normalizedHeaders['CATALYST-COMPONENT'] = 'true';
247
+ let normalizedHeaders = headers;
248
+ normalizedHeaders = (0, auth_client_1.addDefaultAppHeaders)(normalizedHeaders);
240
249
  return normalizedHeaders;
241
250
  }, _ResponseHandler_followZcrfTokenProtocol = async function _ResponseHandler_followZcrfTokenProtocol(headers) {
242
- return auth_client_1.zcAuth
243
- .collectZCRFToken()
244
- .then(() => {
245
- headers[constants_1.X_ZCSRF_TOKEN] =
246
- `${constants_1.ZD_CSRPARAM}=${this.configManager.CsrfToken}`;
247
- return headers;
248
- })
249
- .catch((err) => {
250
- throw new errors_1.CatalystAPIError('API_ERROR', err.message, err.status);
251
- });
251
+ await (0, auth_client_1.collectZCRFToken)();
252
+ const csrfToken = auth_client_1.ConfigStore.get('CSRF_TOKEN');
253
+ headers[constants_1.X_ZCSRF_TOKEN] = `${constants_1.ZD_CSRPARAM}=${csrfToken}`;
254
+ return headers;
252
255
  }, _ResponseHandler_followJwtZCAuthProtocol = async function _ResponseHandler_followJwtZCAuthProtocol(headers) {
253
256
  return this.getJWTZCAuthToken()
254
257
  .then((resp) => {
@@ -263,4 +266,4 @@ _a = ResponseHandler, _ResponseHandler_attachAppSpecificHeaders = function _Resp
263
266
  const { url, ...requestCore } = request;
264
267
  return _a.fireGeneralRequest({ url, requestCore }, options);
265
268
  };
266
- ResponseHandler.configManager = auth_client_1.ConfigManager.getInstance();
269
+ ResponseHandler.apiDomain = typeof document !== 'undefined' ? document.location.origin : '';