@vigneshreddy/cms-sdk 1.0.13 → 1.0.15

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.
@@ -23,12 +23,19 @@ Object.defineProperty(exports, "createSpecificError", { enumerable: true, get: f
23
23
  /**
24
24
  * Parses fetch/network errors into a clean CMSAPIError (or specific subclass)
25
25
  * Uses specific error types when possible for better type safety
26
+ * Sanitizes sensitive information before storing
26
27
  */
27
28
  function handleApiError(error, request, response) {
28
29
  var _a, _b, _c, _d, _e, _f;
29
30
  if (error instanceof base_1.CMSAPIError) {
30
31
  throw error; // preserve original error metadata/type
31
32
  }
33
+ const isHtmlResponse = (data) => {
34
+ if (typeof data !== "string")
35
+ return false;
36
+ const trimmed = data.trim().toLowerCase();
37
+ return trimmed.startsWith("<!doctype") || trimmed.startsWith("<html") || trimmed.startsWith("<!-");
38
+ };
32
39
  const getBackendErrorMessage = (data) => {
33
40
  var _a;
34
41
  const directMessage = typeof (data === null || data === void 0 ? void 0 : data.message) === "string" ? data.message.trim() : "";
@@ -55,7 +62,8 @@ function handleApiError(error, request, response) {
55
62
  return firstObjectErrorText.errorMessage.trim();
56
63
  }
57
64
  }
58
- if (typeof data === "string" && data.trim()) {
65
+ // Ignore HTML responses (e.g., 404 pages)
66
+ if (typeof data === "string" && data.trim() && !isHtmlResponse(data)) {
59
67
  return data.trim();
60
68
  }
61
69
  return undefined;
@@ -64,30 +72,48 @@ function handleApiError(error, request, response) {
64
72
  if (!req || typeof req !== "object")
65
73
  return undefined;
66
74
  const r = req;
67
- return {
75
+ const sanitized = {
68
76
  url: typeof r.url === "string" ? r.url : undefined,
69
77
  method: typeof r.method === "string" ? r.method : undefined,
70
78
  timeout: typeof r.timeout === "number" ? r.timeout : undefined,
71
- headers: typeof r.headers === "object" && r.headers !== null
72
- ? r.headers
73
- : undefined,
74
79
  };
80
+ // Only include headers if they don't contain sensitive data
81
+ if (typeof r.headers === "object" && r.headers !== null) {
82
+ const headersObj = r.headers;
83
+ const safeHeaders = {};
84
+ for (const [key, value] of Object.entries(headersObj)) {
85
+ const lowerKey = key.toLowerCase();
86
+ // Exclude authorization and api-key headers
87
+ if (!lowerKey.includes("authorization") &&
88
+ !lowerKey.includes("api-key") &&
89
+ !lowerKey.includes("token")) {
90
+ safeHeaders[key] = value;
91
+ }
92
+ }
93
+ if (Object.keys(safeHeaders).length > 0) {
94
+ sanitized.headers = safeHeaders;
95
+ }
96
+ }
97
+ return sanitized;
75
98
  };
76
99
  // Error with response from server
77
100
  const errorWithResponse = (_a = error === null || error === void 0 ? void 0 : error.response) !== null && _a !== void 0 ? _a : response;
78
101
  if (errorWithResponse) {
79
102
  const res = errorWithResponse;
80
103
  const statusCode = (_c = (_b = res.status) !== null && _b !== void 0 ? _b : res.statusCode) !== null && _c !== void 0 ? _c : 500;
81
- const backendMessage = getBackendErrorMessage(res.data);
104
+ const isHtml = isHtmlResponse(res.data);
105
+ const backendMessage = isHtml ? undefined : getBackendErrorMessage(res.data);
82
106
  const fallbackMessage = `CMS API Error: ${statusCode} - ${(_d = res.statusText) !== null && _d !== void 0 ? _d : "Unknown API Error"}`;
83
107
  const message = backendMessage !== null && backendMessage !== void 0 ? backendMessage : fallbackMessage;
108
+ // Don't pass HTML blobs as rawError
109
+ const rawError = isHtml ? undefined : ((_e = res.data) !== null && _e !== void 0 ? _e : error);
84
110
  // Prefer typed error subclasses when possible
85
- const typedError = (0, specific_1.createSpecificError)(statusCode, message, (_e = res.data) !== null && _e !== void 0 ? _e : error);
111
+ const typedError = (0, specific_1.createSpecificError)(statusCode, message, rawError);
86
112
  typedError.request = sanitizeRequest(request !== null && request !== void 0 ? request : error === null || error === void 0 ? void 0 : error.request);
87
113
  typedError.response = {
88
114
  status: statusCode,
89
115
  statusText: res.statusText || "",
90
- data: res.data,
116
+ data: isHtml ? undefined : res.data,
91
117
  headers: res.headers,
92
118
  };
93
119
  throw typedError;
@@ -0,0 +1,192 @@
1
+ import type { Configuration } from './configuration';
2
+ import type { RequestArgs, RequestOptions } from './base';
3
+ import { BaseAPI } from './base';
4
+ export type TrackLeadRequest = {
5
+ /**
6
+ * The `cms_id` from the cookie.
7
+ */
8
+ 'clickId': string;
9
+ 'eventName': string;
10
+ /**
11
+ * Unique User ID. Used for deduplication (user cannot signup twice).
12
+ */
13
+ 'customerExternalId': string;
14
+ /**
15
+ * When set to `"deferred"`, the API may associate `clickId` to `customerId`
16
+ * for later attribution.
17
+ */
18
+ 'mode'?: 'deferred';
19
+ /**
20
+ * Optional event timestamp in ISO 8601 format.
21
+ */
22
+ 'timestamp'?: string;
23
+ /**
24
+ * Optional customer display name.
25
+ */
26
+ 'customerName'?: string;
27
+ /**
28
+ * Optional customer email address.
29
+ */
30
+ 'customerEmail'?: string;
31
+ /**
32
+ * Optional URL to a customer avatar image.
33
+ */
34
+ 'customerAvatar'?: string;
35
+ } | {
36
+ /**
37
+ * In deferred mode, a follow-up call can omit `clickId` and only provide
38
+ * `customerId` (and `eventName`) to attribute using the stored association.
39
+ */
40
+ 'clickId'?: never;
41
+ 'eventName': string;
42
+ /**
43
+ * Unique User ID. Used for deduplication (user cannot signup twice).
44
+ */
45
+ 'mode': 'deferred';
46
+ /**
47
+ * Optional event timestamp in ISO 8601 format.
48
+ */
49
+ 'timestamp'?: string;
50
+ /**
51
+ * Optional external customer identifier used in your system.
52
+ */
53
+ 'customerExternalId': string;
54
+ /**
55
+ * Optional customer display name.
56
+ */
57
+ 'customerName'?: string;
58
+ /**
59
+ * Optional customer email address.
60
+ */
61
+ 'customerEmail'?: string;
62
+ /**
63
+ * Optional URL to a customer avatar image.
64
+ */
65
+ 'customerAvatar'?: string;
66
+ };
67
+ export interface TrackResponse {
68
+ 'status'?: string;
69
+ }
70
+ export interface TrackSaleRequest {
71
+ /**
72
+ * The `dub_id` from the cookie.
73
+ */
74
+ 'clickId': string;
75
+ 'eventName': string;
76
+ /**
77
+ * Optional event timestamp in ISO 8601 format.
78
+ */
79
+ 'timestamp'?: string;
80
+ /**
81
+ * Optional external customer identifier used in your system.
82
+ */
83
+ 'customerExternalId': string;
84
+ /**
85
+ * Optional customer display name.
86
+ */
87
+ 'customerName'?: string;
88
+ /**
89
+ * Optional customer email address.
90
+ */
91
+ 'customerEmail'?: string;
92
+ /**
93
+ * Optional URL to a customer avatar image.
94
+ */
95
+ 'customerAvatar'?: string;
96
+ /**
97
+ * Unique Transaction ID. Used for deduplication (charge cannot happen twice).
98
+ */
99
+ 'invoiceId': string;
100
+ /**
101
+ * The value of the sale in cents.
102
+ */
103
+ 'amount': number;
104
+ /**
105
+ * Three-letter currency code.
106
+ */
107
+ 'currency': string;
108
+ }
109
+ /**
110
+ * EventsApi - axios parameter creator
111
+ */
112
+ export declare const EventsApiAxiosParamCreator: (configuration?: Configuration) => {
113
+ /**
114
+ *
115
+ * @summary Track a Lead
116
+ * @param {TrackLeadRequest} trackLeadRequest
117
+ * @param {*} [options] Override http request option.
118
+ * @throws {RequiredError}
119
+ */
120
+ trackLead: (trackLeadRequest: TrackLeadRequest, options?: RequestOptions) => Promise<RequestArgs>;
121
+ /**
122
+ *
123
+ * @summary Track a Sale
124
+ * @param {TrackSaleRequest} trackSaleRequest
125
+ * @param {*} [options] Override http request option.
126
+ * @throws {RequiredError}
127
+ */
128
+ trackSale: (trackSaleRequest: TrackSaleRequest, options?: RequestOptions) => Promise<RequestArgs>;
129
+ };
130
+ /**
131
+ * EventsApi - functional programming interface
132
+ */
133
+ export declare const EventsApiFp: (configuration?: Configuration) => {
134
+ /**
135
+ *
136
+ * @summary Track a Lead
137
+ * @param {TrackLeadRequest} trackLeadRequest
138
+ * @param {*} [options] Override http request option.
139
+ * @throws {RequiredError}
140
+ */
141
+ trackLead(trackLeadRequest: TrackLeadRequest, options?: RequestOptions, basePathOverride?: string): Promise<TrackResponse>;
142
+ /**
143
+ *
144
+ * @summary Track a Sale
145
+ * @param {TrackSaleRequest} trackSaleRequest
146
+ * @param {*} [options] Override http request option.
147
+ * @throws {RequiredError}
148
+ */
149
+ trackSale(trackSaleRequest: TrackSaleRequest, options?: RequestOptions, basePathOverride?: string): Promise<TrackResponse>;
150
+ };
151
+ /**
152
+ * EventsApi - factory interface
153
+ */
154
+ export declare const EventsApiFactory: (configuration?: Configuration, basePath?: string) => {
155
+ /**
156
+ *
157
+ * @summary Track a Lead
158
+ * @param {TrackLeadRequest} trackLeadRequest
159
+ * @param {*} [options] Override http request option.
160
+ * @throws {RequiredError}
161
+ */
162
+ trackLead(trackLeadRequest: TrackLeadRequest, options?: RequestOptions): Promise<TrackResponse>;
163
+ /**
164
+ *
165
+ * @summary Track a Sale
166
+ * @param {TrackSaleRequest} trackSaleRequest
167
+ * @param {*} [options] Override http request option.
168
+ * @throws {RequiredError}
169
+ */
170
+ trackSale(trackSaleRequest: TrackSaleRequest, options?: RequestOptions): Promise<TrackResponse>;
171
+ };
172
+ /**
173
+ * EventsApi - object-oriented interface
174
+ */
175
+ export declare class EventsApi extends BaseAPI {
176
+ /**
177
+ *
178
+ * @summary Track a Lead
179
+ * @param {TrackLeadRequest} trackLeadRequest
180
+ * @param {*} [options] Override http request option.
181
+ * @throws {RequiredError}
182
+ */
183
+ trackLead(trackLeadRequest: TrackLeadRequest, options?: RequestOptions): Promise<TrackResponse>;
184
+ /**
185
+ *
186
+ * @summary Track a Sale
187
+ * @param {TrackSaleRequest} trackSaleRequest
188
+ * @param {*} [options] Override http request option.
189
+ * @throws {RequiredError}
190
+ */
191
+ trackSale(trackSaleRequest: TrackSaleRequest, options?: RequestOptions): Promise<TrackResponse>;
192
+ }
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventsApi = exports.EventsApiFactory = exports.EventsApiFp = exports.EventsApiAxiosParamCreator = void 0;
4
+ const common_1 = require("./common");
5
+ // @ts-ignore
6
+ const base_1 = require("./base");
7
+ /**
8
+ * EventsApi - axios parameter creator
9
+ */
10
+ const EventsApiAxiosParamCreator = function (configuration) {
11
+ return {
12
+ /**
13
+ *
14
+ * @summary Track a Lead
15
+ * @param {TrackLeadRequest} trackLeadRequest
16
+ * @param {*} [options] Override http request option.
17
+ * @throws {RequiredError}
18
+ */
19
+ trackLead: async (trackLeadRequest, options = {}) => {
20
+ // verify required parameter 'trackLeadRequest' is not null or undefined
21
+ (0, common_1.assertParamExists)('trackLead', 'trackLeadRequest', trackLeadRequest);
22
+ const localVarPath = `/track/lead`;
23
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
24
+ const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
25
+ let baseOptions;
26
+ if (configuration) {
27
+ baseOptions = configuration.baseOptions;
28
+ }
29
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
30
+ const localVarHeaderParameter = {};
31
+ const localVarQueryParameter = {};
32
+ // authentication bearerAuth required
33
+ // http bearer authentication required
34
+ await (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration);
35
+ localVarHeaderParameter['Content-Type'] = 'application/json';
36
+ localVarHeaderParameter['Accept'] = 'application/json';
37
+ (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
38
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
39
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
40
+ localVarRequestOptions.data = (0, common_1.serializeDataIfNeeded)(trackLeadRequest, localVarRequestOptions, configuration);
41
+ return {
42
+ url: (0, common_1.toPathString)(localVarUrlObj),
43
+ options: localVarRequestOptions,
44
+ };
45
+ },
46
+ /**
47
+ *
48
+ * @summary Track a Sale
49
+ * @param {TrackSaleRequest} trackSaleRequest
50
+ * @param {*} [options] Override http request option.
51
+ * @throws {RequiredError}
52
+ */
53
+ trackSale: async (trackSaleRequest, options = {}) => {
54
+ // verify required parameter 'trackSaleRequest' is not null or undefined
55
+ (0, common_1.assertParamExists)('trackSale', 'trackSaleRequest', trackSaleRequest);
56
+ const localVarPath = `/track/sale`;
57
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
58
+ const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
59
+ let baseOptions;
60
+ if (configuration) {
61
+ baseOptions = configuration.baseOptions;
62
+ }
63
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
64
+ const localVarHeaderParameter = {};
65
+ const localVarQueryParameter = {};
66
+ // authentication bearerAuth required
67
+ // http bearer authentication required
68
+ await (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration);
69
+ localVarHeaderParameter['Content-Type'] = 'application/json';
70
+ localVarHeaderParameter['Accept'] = 'application/json';
71
+ (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
72
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
73
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
74
+ localVarRequestOptions.data = (0, common_1.serializeDataIfNeeded)(trackSaleRequest, localVarRequestOptions, configuration);
75
+ return {
76
+ url: (0, common_1.toPathString)(localVarUrlObj),
77
+ options: localVarRequestOptions,
78
+ };
79
+ },
80
+ };
81
+ };
82
+ exports.EventsApiAxiosParamCreator = EventsApiAxiosParamCreator;
83
+ /**
84
+ * EventsApi - functional programming interface
85
+ */
86
+ const EventsApiFp = function (configuration) {
87
+ const localVarAxiosParamCreator = (0, exports.EventsApiAxiosParamCreator)(configuration);
88
+ return {
89
+ /**
90
+ *
91
+ * @summary Track a Lead
92
+ * @param {TrackLeadRequest} trackLeadRequest
93
+ * @param {*} [options] Override http request option.
94
+ * @throws {RequiredError}
95
+ */
96
+ async trackLead(trackLeadRequest, options, basePathOverride) {
97
+ var _a, _b, _c, _d, _e;
98
+ const localVarAxiosArgs = await localVarAxiosParamCreator.trackLead(trackLeadRequest, options !== null && options !== void 0 ? options : {});
99
+ const localVarOperationServerIndex = (_a = configuration === null || configuration === void 0 ? void 0 : configuration.serverIndex) !== null && _a !== void 0 ? _a : 0;
100
+ const localVarOperationServerBasePath = (_c = (_b = base_1.operationServerMap['EventsApi.trackLead']) === null || _b === void 0 ? void 0 : _b[localVarOperationServerIndex]) === null || _c === void 0 ? void 0 : _c.url;
101
+ const basePath = (_e = (_d = basePathOverride !== null && basePathOverride !== void 0 ? basePathOverride : localVarOperationServerBasePath) !== null && _d !== void 0 ? _d : configuration === null || configuration === void 0 ? void 0 : configuration.basePath) !== null && _e !== void 0 ? _e : base_1.BASE_PATH;
102
+ return performFetchRequest(localVarAxiosArgs, basePath);
103
+ },
104
+ /**
105
+ *
106
+ * @summary Track a Sale
107
+ * @param {TrackSaleRequest} trackSaleRequest
108
+ * @param {*} [options] Override http request option.
109
+ * @throws {RequiredError}
110
+ */
111
+ async trackSale(trackSaleRequest, options, basePathOverride) {
112
+ var _a, _b, _c, _d, _e;
113
+ const localVarAxiosArgs = await localVarAxiosParamCreator.trackSale(trackSaleRequest, options !== null && options !== void 0 ? options : {});
114
+ const localVarOperationServerIndex = (_a = configuration === null || configuration === void 0 ? void 0 : configuration.serverIndex) !== null && _a !== void 0 ? _a : 0;
115
+ const localVarOperationServerBasePath = (_c = (_b = base_1.operationServerMap['EventsApi.trackSale']) === null || _b === void 0 ? void 0 : _b[localVarOperationServerIndex]) === null || _c === void 0 ? void 0 : _c.url;
116
+ const basePath = (_e = (_d = basePathOverride !== null && basePathOverride !== void 0 ? basePathOverride : localVarOperationServerBasePath) !== null && _d !== void 0 ? _d : configuration === null || configuration === void 0 ? void 0 : configuration.basePath) !== null && _e !== void 0 ? _e : base_1.BASE_PATH;
117
+ return performFetchRequest(localVarAxiosArgs, basePath);
118
+ },
119
+ };
120
+ };
121
+ exports.EventsApiFp = EventsApiFp;
122
+ /**
123
+ * EventsApi - factory interface
124
+ */
125
+ const EventsApiFactory = function (configuration, basePath) {
126
+ const localVarFp = (0, exports.EventsApiFp)(configuration);
127
+ return {
128
+ /**
129
+ *
130
+ * @summary Track a Lead
131
+ * @param {TrackLeadRequest} trackLeadRequest
132
+ * @param {*} [options] Override http request option.
133
+ * @throws {RequiredError}
134
+ */
135
+ trackLead(trackLeadRequest, options) {
136
+ return localVarFp.trackLead(trackLeadRequest, options, basePath);
137
+ },
138
+ /**
139
+ *
140
+ * @summary Track a Sale
141
+ * @param {TrackSaleRequest} trackSaleRequest
142
+ * @param {*} [options] Override http request option.
143
+ * @throws {RequiredError}
144
+ */
145
+ trackSale(trackSaleRequest, options) {
146
+ return localVarFp.trackSale(trackSaleRequest, options, basePath);
147
+ },
148
+ };
149
+ };
150
+ exports.EventsApiFactory = EventsApiFactory;
151
+ /**
152
+ * EventsApi - object-oriented interface
153
+ */
154
+ class EventsApi extends base_1.BaseAPI {
155
+ /**
156
+ *
157
+ * @summary Track a Lead
158
+ * @param {TrackLeadRequest} trackLeadRequest
159
+ * @param {*} [options] Override http request option.
160
+ * @throws {RequiredError}
161
+ */
162
+ trackLead(trackLeadRequest, options) {
163
+ return (0, exports.EventsApiFp)(this.configuration).trackLead(trackLeadRequest, options, this.basePath);
164
+ }
165
+ /**
166
+ *
167
+ * @summary Track a Sale
168
+ * @param {TrackSaleRequest} trackSaleRequest
169
+ * @param {*} [options] Override http request option.
170
+ * @throws {RequiredError}
171
+ */
172
+ trackSale(trackSaleRequest, options) {
173
+ return (0, exports.EventsApiFp)(this.configuration).trackSale(trackSaleRequest, options, this.basePath);
174
+ }
175
+ }
176
+ exports.EventsApi = EventsApi;
177
+ /**
178
+ * Internal helper that performs a fetch request based on the generated
179
+ * `RequestArgs` and normalizes errors into an Axios-like shape so the
180
+ * existing error handling and retry logic in the SDK can continue to
181
+ * operate without changes.
182
+ */
183
+ async function performFetchRequest(requestArgs, basePath) {
184
+ const url = (basePath !== null && basePath !== void 0 ? basePath : base_1.BASE_PATH).replace(/\/+$/, "") + requestArgs.url;
185
+ const { timeout, data, ...restOptions } = requestArgs.options;
186
+ if (typeof fetch !== "function") {
187
+ throw new Error("Global fetch API is not available. Please provide a fetch polyfill in this environment.");
188
+ }
189
+ const controller = typeof AbortController !== "undefined" ? new AbortController() : undefined;
190
+ const signal = controller === null || controller === void 0 ? void 0 : controller.signal;
191
+ let timeoutId;
192
+ if (controller && typeof timeout === "number" && timeout > 0) {
193
+ timeoutId = setTimeout(() => controller.abort(), timeout);
194
+ }
195
+ try {
196
+ const fetchOptions = { ...restOptions, signal };
197
+ // The generated client stores the request payload on `data` (Axios-style),
198
+ // but the fetch API expects it on `body`. Translate between the two.
199
+ if (typeof data !== "undefined") {
200
+ const rawHeaders = fetchOptions.headers;
201
+ let headers = {};
202
+ if (rawHeaders instanceof Headers) {
203
+ rawHeaders.forEach((value, key) => {
204
+ headers[key] = value;
205
+ });
206
+ }
207
+ else if (Array.isArray(rawHeaders)) {
208
+ headers = Object.fromEntries(rawHeaders.map(([key, value]) => [String(key), String(value)]));
209
+ }
210
+ else if (rawHeaders && typeof rawHeaders === "object") {
211
+ headers = Object.fromEntries(Object.entries(rawHeaders).map(([key, value]) => [key, String(value)]));
212
+ }
213
+ const requestContentTypeHeader = Object.keys(headers).find((h) => h.toLowerCase() === "content-type");
214
+ const requestContentType = requestContentTypeHeader
215
+ ? headers[requestContentTypeHeader]
216
+ : undefined;
217
+ // If Content-Type is JSON (our default), ensure the body is a JSON string.
218
+ if (requestContentType === null || requestContentType === void 0 ? void 0 : requestContentType.toLowerCase().includes("application/json")) {
219
+ fetchOptions.body =
220
+ typeof data === "string" ? data : JSON.stringify(data);
221
+ }
222
+ else {
223
+ fetchOptions.body = data;
224
+ }
225
+ }
226
+ const response = await fetch(url, fetchOptions);
227
+ const responseContentType = response.headers.get("content-type") || "";
228
+ const isJson = responseContentType.toLowerCase().includes("application/json");
229
+ let dataResult = null;
230
+ if (response.status !== 204 && response.status !== 205) {
231
+ const responseText = await response.text();
232
+ if (isJson && responseText) {
233
+ try {
234
+ dataResult = JSON.parse(responseText);
235
+ }
236
+ catch {
237
+ dataResult = responseText;
238
+ }
239
+ }
240
+ else {
241
+ dataResult = responseText;
242
+ }
243
+ }
244
+ if (!response.ok) {
245
+ const responseHeaders = {};
246
+ response.headers.forEach((value, key) => {
247
+ responseHeaders[key] = value;
248
+ });
249
+ const error = new Error(`Request failed with status code ${response.status}`);
250
+ error.response = {
251
+ status: response.status,
252
+ statusText: response.statusText,
253
+ data: dataResult,
254
+ headers: responseHeaders,
255
+ };
256
+ throw error;
257
+ }
258
+ return dataResult;
259
+ }
260
+ catch (err) {
261
+ // Normalize fetch/AbortError/network errors into an Axios-style shape
262
+ if ((err === null || err === void 0 ? void 0 : err.name) === "AbortError") {
263
+ err.code = "ECONNABORTED";
264
+ }
265
+ if (!err.response) {
266
+ // Attach only minimal request info to avoid leaking sensitive data
267
+ err.request = { url };
268
+ }
269
+ throw err;
270
+ }
271
+ finally {
272
+ if (timeoutId) {
273
+ clearTimeout(timeoutId);
274
+ }
275
+ }
276
+ }
@@ -0,0 +1,46 @@
1
+ import type { Configuration } from './configuration';
2
+ export type RequestOptions = RequestInit & {
3
+ /**
4
+ * Optional request timeout in milliseconds.
5
+ * When provided, the client will abort the request after this duration.
6
+ */
7
+ timeout?: number;
8
+ /**
9
+ * Optional headers bag. This stays loosely typed to be compatible with
10
+ * any existing code that spreads arbitrary objects into headers.
11
+ */
12
+ headers?: Record<string, any>;
13
+ };
14
+ export declare const BASE_PATH: string;
15
+ export declare const COLLECTION_FORMATS: {
16
+ csv: string;
17
+ ssv: string;
18
+ tsv: string;
19
+ pipes: string;
20
+ };
21
+ export interface RequestArgs {
22
+ url: string;
23
+ options: RequestOptions;
24
+ }
25
+ export declare class BaseAPI {
26
+ protected configuration: Configuration | undefined;
27
+ protected basePath: string;
28
+ /**
29
+ * Minimal base class that stores configuration and basePath.
30
+ * Concrete API classes are responsible for performing requests using
31
+ * the global `fetch` (or any polyfill provided by the consumer).
32
+ */
33
+ constructor(configuration?: Configuration, basePath?: string);
34
+ }
35
+ export declare class RequiredError extends Error {
36
+ field: string;
37
+ constructor(field: string, msg?: string);
38
+ }
39
+ interface ServerMap {
40
+ [key: string]: {
41
+ url: string;
42
+ description: string;
43
+ }[];
44
+ }
45
+ export declare const operationServerMap: ServerMap;
46
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.operationServerMap = exports.RequiredError = exports.BaseAPI = exports.COLLECTION_FORMATS = exports.BASE_PATH = void 0;
4
+ const constants_1 = require("../constants/constants");
5
+ exports.BASE_PATH = constants_1.API_CONFIG.BASE_URL.replace(/\/+$/, "");
6
+ exports.COLLECTION_FORMATS = {
7
+ csv: ",",
8
+ ssv: " ",
9
+ tsv: "\t",
10
+ pipes: "|",
11
+ };
12
+ class BaseAPI {
13
+ /**
14
+ * Minimal base class that stores configuration and basePath.
15
+ * Concrete API classes are responsible for performing requests using
16
+ * the global `fetch` (or any polyfill provided by the consumer).
17
+ */
18
+ constructor(configuration, basePath = exports.BASE_PATH) {
19
+ var _a;
20
+ this.basePath = exports.BASE_PATH;
21
+ if (configuration) {
22
+ this.configuration = configuration;
23
+ this.basePath = (_a = configuration.basePath) !== null && _a !== void 0 ? _a : basePath;
24
+ }
25
+ else {
26
+ this.basePath = basePath;
27
+ }
28
+ }
29
+ }
30
+ exports.BaseAPI = BaseAPI;
31
+ ;
32
+ class RequiredError extends Error {
33
+ constructor(field, msg) {
34
+ super(msg);
35
+ this.field = field;
36
+ this.name = "RequiredError";
37
+ }
38
+ }
39
+ exports.RequiredError = RequiredError;
40
+ exports.operationServerMap = {};
@@ -0,0 +1,20 @@
1
+ import type { Configuration } from "./configuration";
2
+ export declare const DUMMY_BASE_URL = "https://example.com";
3
+ /**
4
+ *
5
+ * @throws {RequiredError}
6
+ */
7
+ export declare const assertParamExists: (functionName: string, paramName: string, paramValue: unknown) => void;
8
+ export declare const setApiKeyToObject: (object: any, keyParamName: string, configuration?: Configuration) => Promise<void>;
9
+ export declare const setBasicAuthToObject: (object: any, configuration?: Configuration) => void;
10
+ export declare const setBearerAuthToObject: (object: any, configuration?: Configuration) => Promise<void>;
11
+ export declare const setOAuthToObject: (object: any, name: string, scopes: string[], configuration?: Configuration) => Promise<void>;
12
+ export declare const setSearchParams: (url: URL, ...objects: any[]) => void;
13
+ /**
14
+ * JSON serialization helper function which replaces instances of unserializable types with serializable ones.
15
+ * This function will run for every key-value pair encountered by JSON.stringify while traversing an object.
16
+ * Converting a set to a string will return an empty object, so an intermediate conversion to an array is required.
17
+ */
18
+ export declare const replaceWithSerializableTypeIfNeeded: (key: string, value: any) => any;
19
+ export declare const serializeDataIfNeeded: (value: any, requestOptions: any, configuration?: Configuration) => any;
20
+ export declare const toPathString: (url: URL) => string;