-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathbase.ts
More file actions
97 lines (83 loc) · 2.4 KB
/
Copy pathbase.ts
File metadata and controls
97 lines (83 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* tslint:disable */
/* eslint-disable */
/**
* Pipedrive API v2
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 2.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import type { Configuration } from './configuration';
// Some imports not used depending on template conditions
// @ts-ignore
import type { AxiosError, AxiosResponse, AxiosRequestConfig , InternalAxiosRequestConfig , AxiosInstance } from 'axios';
import axios from 'axios';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const _pkg = require('../../../package.json') as { version: string };
export const BASE_PATH = "https://api.pipedrive.com/api/v2".replace(/\/+$/, "");
/**
*
* @export
*/
export const COLLECTION_FORMATS = {
csv: ",",
ssv: " ",
tsv: "\t",
pipes: "|",
};
/**
*
* @export
* @interface RequestArgs
*/
export interface RequestArgs {
url: string;
options: AxiosRequestConfig;
}
export const versionInterceptor = async (config:InternalAxiosRequestConfig) => {
config.headers['User-Agent'] = `Pipedrive-SDK-Javascript-${_pkg.version}`;
return config;
}
export const responseInterceptor = (response: AxiosResponse) => {
return response?.data ? response.data: response;
};
export const errorInterceptor = (error: AxiosError) => {
if (error.response && error.response.data) {
return Promise.reject(error.response.data);
}
return Promise.reject(error);
};
/**
*
* @export
* @class BaseAPI
*/
export class BaseAPI {
protected configuration: Configuration | undefined;
protected basePath: string = BASE_PATH;
protected axios : AxiosInstance = axios.create();
constructor(configuration: Configuration) {
if (configuration) {
this.configuration = configuration;
this.basePath = configuration.basePath || this.basePath;
}
this.axios.interceptors.response.use(responseInterceptor, errorInterceptor);
this.axios.interceptors.request.use(versionInterceptor);
}
};
/**
*
* @export
* @class RequiredError
* @extends {Error}
*/
export class RequiredError extends Error {
constructor(public field: string, msg?: string) {
super(msg);
this.name = "RequiredError"
}
}