@vigneshreddy/cms-sdk 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,192 +0,0 @@
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
- }
@@ -1,276 +0,0 @@
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
- }
@@ -1,46 +0,0 @@
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 {};
@@ -1,39 +0,0 @@
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
- exports.BASE_PATH = "https://www.cutmeshort.com".replace(/\/+$/, "");
5
- exports.COLLECTION_FORMATS = {
6
- csv: ",",
7
- ssv: " ",
8
- tsv: "\t",
9
- pipes: "|",
10
- };
11
- class BaseAPI {
12
- /**
13
- * Minimal base class that stores configuration and basePath.
14
- * Concrete API classes are responsible for performing requests using
15
- * the global `fetch` (or any polyfill provided by the consumer).
16
- */
17
- constructor(configuration, basePath = exports.BASE_PATH) {
18
- var _a;
19
- this.basePath = exports.BASE_PATH;
20
- if (configuration) {
21
- this.configuration = configuration;
22
- this.basePath = (_a = configuration.basePath) !== null && _a !== void 0 ? _a : basePath;
23
- }
24
- else {
25
- this.basePath = basePath;
26
- }
27
- }
28
- }
29
- exports.BaseAPI = BaseAPI;
30
- ;
31
- class RequiredError extends Error {
32
- constructor(field, msg) {
33
- super(msg);
34
- this.field = field;
35
- this.name = "RequiredError";
36
- }
37
- }
38
- exports.RequiredError = RequiredError;
39
- exports.operationServerMap = {};
@@ -1,20 +0,0 @@
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;
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toPathString = exports.serializeDataIfNeeded = exports.replaceWithSerializableTypeIfNeeded = exports.setSearchParams = exports.setOAuthToObject = exports.setBearerAuthToObject = exports.setBasicAuthToObject = exports.setApiKeyToObject = exports.assertParamExists = exports.DUMMY_BASE_URL = void 0;
4
- const base_1 = require("./base");
5
- exports.DUMMY_BASE_URL = 'https://example.com';
6
- /**
7
- *
8
- * @throws {RequiredError}
9
- */
10
- const assertParamExists = function (functionName, paramName, paramValue) {
11
- if (paramValue === null || paramValue === undefined) {
12
- throw new base_1.RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
13
- }
14
- };
15
- exports.assertParamExists = assertParamExists;
16
- const setApiKeyToObject = async function (object, keyParamName, configuration) {
17
- if (configuration && configuration.apiKey) {
18
- const localVarApiKeyValue = typeof configuration.apiKey === 'function'
19
- ? await configuration.apiKey(keyParamName)
20
- : await configuration.apiKey;
21
- object[keyParamName] = localVarApiKeyValue;
22
- }
23
- };
24
- exports.setApiKeyToObject = setApiKeyToObject;
25
- const setBasicAuthToObject = function (object, configuration) {
26
- if (configuration && (configuration.username || configuration.password)) {
27
- object["auth"] = { username: configuration.username, password: configuration.password };
28
- }
29
- };
30
- exports.setBasicAuthToObject = setBasicAuthToObject;
31
- const setBearerAuthToObject = async function (object, configuration) {
32
- if (configuration && configuration.accessToken) {
33
- const accessToken = typeof configuration.accessToken === 'function'
34
- ? await configuration.accessToken()
35
- : await configuration.accessToken;
36
- object["Authorization"] = "Bearer " + accessToken;
37
- }
38
- };
39
- exports.setBearerAuthToObject = setBearerAuthToObject;
40
- const setOAuthToObject = async function (object, name, scopes, configuration) {
41
- if (configuration && configuration.accessToken) {
42
- const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
43
- ? await configuration.accessToken(name, scopes)
44
- : await configuration.accessToken;
45
- object["Authorization"] = "Bearer " + localVarAccessTokenValue;
46
- }
47
- };
48
- exports.setOAuthToObject = setOAuthToObject;
49
- function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
50
- if (parameter == null)
51
- return;
52
- if (typeof parameter === "object") {
53
- if (Array.isArray(parameter) || parameter instanceof Set) {
54
- parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
55
- }
56
- else {
57
- Object.keys(parameter).forEach(currentKey => setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`));
58
- }
59
- }
60
- else {
61
- if (urlSearchParams.has(key)) {
62
- urlSearchParams.append(key, parameter);
63
- }
64
- else {
65
- urlSearchParams.set(key, parameter);
66
- }
67
- }
68
- }
69
- const setSearchParams = function (url, ...objects) {
70
- const searchParams = new URLSearchParams(url.search);
71
- setFlattenedQueryParams(searchParams, objects);
72
- url.search = searchParams.toString();
73
- };
74
- exports.setSearchParams = setSearchParams;
75
- /**
76
- * JSON serialization helper function which replaces instances of unserializable types with serializable ones.
77
- * This function will run for every key-value pair encountered by JSON.stringify while traversing an object.
78
- * Converting a set to a string will return an empty object, so an intermediate conversion to an array is required.
79
- */
80
- // @ts-ignore
81
- const replaceWithSerializableTypeIfNeeded = function (key, value) {
82
- if (value instanceof Set) {
83
- return Array.from(value);
84
- }
85
- else {
86
- return value;
87
- }
88
- };
89
- exports.replaceWithSerializableTypeIfNeeded = replaceWithSerializableTypeIfNeeded;
90
- const serializeDataIfNeeded = function (value, requestOptions, configuration) {
91
- const nonString = typeof value !== 'string';
92
- const needsSerialization = nonString && configuration && configuration.isJsonMime
93
- ? configuration.isJsonMime(requestOptions.headers['Content-Type'])
94
- : nonString;
95
- return needsSerialization
96
- ? JSON.stringify(value !== undefined ? value : {}, exports.replaceWithSerializableTypeIfNeeded)
97
- : (value || "");
98
- };
99
- exports.serializeDataIfNeeded = serializeDataIfNeeded;
100
- const toPathString = function (url) {
101
- return url.pathname + url.search + url.hash;
102
- };
103
- exports.toPathString = toPathString;