@internxt/sdk 1.12.2 → 1.12.4
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,5 +1,13 @@
|
|
|
1
|
+
import { ApiSecurity, ApiUrl, AppDetails } from '../../shared';
|
|
1
2
|
export interface UserLocation {
|
|
2
3
|
ip: string;
|
|
3
4
|
location: string;
|
|
4
5
|
}
|
|
5
|
-
export declare
|
|
6
|
+
export declare class Location {
|
|
7
|
+
private readonly client;
|
|
8
|
+
private readonly appDetails;
|
|
9
|
+
private constructor();
|
|
10
|
+
static client(apiUrl: ApiUrl, appDetails: AppDetails, apiSecurity?: ApiSecurity): Location;
|
|
11
|
+
getUserLocation(): Promise<UserLocation>;
|
|
12
|
+
private basicUserHeaders;
|
|
13
|
+
}
|
|
@@ -36,13 +36,32 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.Location = void 0;
|
|
40
|
+
var headers_1 = require("../../shared/headers");
|
|
40
41
|
var client_1 = require("../../shared/http/client");
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
var Location = /** @class */ (function () {
|
|
43
|
+
function Location(apiUrl, appDetails, apiSecurity) {
|
|
44
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
|
|
45
|
+
this.appDetails = appDetails;
|
|
46
|
+
}
|
|
47
|
+
Location.client = function (apiUrl, appDetails, apiSecurity) {
|
|
48
|
+
return new Location(apiUrl, appDetails, apiSecurity);
|
|
49
|
+
};
|
|
50
|
+
Location.prototype.getUserLocation = function () {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
return [2 /*return*/, this.client.get('', this.basicUserHeaders())];
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
Location.prototype.basicUserHeaders = function () {
|
|
58
|
+
return (0, headers_1.basicHeaders)({
|
|
59
|
+
clientName: this.appDetails.clientName,
|
|
60
|
+
clientVersion: this.appDetails.clientVersion,
|
|
61
|
+
desktopToken: this.appDetails.desktopHeader,
|
|
62
|
+
customHeaders: this.appDetails.customHeaders,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
return Location;
|
|
66
|
+
}());
|
|
67
|
+
exports.Location = Location;
|
|
@@ -2,6 +2,12 @@ import { BasicAuth, Token } from '../../auth';
|
|
|
2
2
|
export interface CustomHeaders {
|
|
3
3
|
[key: string]: string;
|
|
4
4
|
}
|
|
5
|
+
export interface BasicHeadersPayload {
|
|
6
|
+
clientName: string;
|
|
7
|
+
clientVersion: string;
|
|
8
|
+
customHeaders?: Record<string, string>;
|
|
9
|
+
desktopToken?: Token;
|
|
10
|
+
}
|
|
5
11
|
type InternxtHeaders = {
|
|
6
12
|
'content-type': string;
|
|
7
13
|
'internxt-version': string;
|
|
@@ -12,12 +18,7 @@ type InternxtHeaders = {
|
|
|
12
18
|
'internxt-resources-token'?: string;
|
|
13
19
|
'x-internxt-desktop-header'?: string;
|
|
14
20
|
};
|
|
15
|
-
export declare function basicHeaders({ clientName, clientVersion, customHeaders, desktopToken, }:
|
|
16
|
-
clientName: string;
|
|
17
|
-
clientVersion: string;
|
|
18
|
-
customHeaders?: Record<string, string>;
|
|
19
|
-
desktopToken?: Token;
|
|
20
|
-
}): InternxtHeaders;
|
|
21
|
+
export declare function basicHeaders({ clientName, clientVersion, customHeaders, desktopToken, }: BasicHeadersPayload): InternxtHeaders;
|
|
21
22
|
export declare function basicHeadersWithPassword({ clientName, clientVersion, password, desktopToken, }: {
|
|
22
23
|
clientName: string;
|
|
23
24
|
clientVersion: string;
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
+
import { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
1
2
|
import { Headers, Parameters, RequestCanceler, URL, UnauthorizedCallback } from './types';
|
|
2
3
|
export { RequestCanceler } from './types';
|
|
4
|
+
export interface CustomInterceptor {
|
|
5
|
+
request?: {
|
|
6
|
+
onFulfilled?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>;
|
|
7
|
+
onRejected?: (error: unknown) => unknown;
|
|
8
|
+
};
|
|
9
|
+
response?: {
|
|
10
|
+
onFulfilled?: (response: AxiosResponse) => AxiosResponse;
|
|
11
|
+
onRejected?: (error: unknown) => unknown;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
3
14
|
export declare class HttpClient {
|
|
4
15
|
private readonly axios;
|
|
5
16
|
private readonly unauthorizedCallback;
|
|
17
|
+
static globalInterceptors: CustomInterceptor[];
|
|
18
|
+
static setGlobalInterceptors(interceptors: CustomInterceptor[]): void;
|
|
6
19
|
static create(baseURL: URL, unauthorizedCallback?: UnauthorizedCallback): HttpClient;
|
|
7
20
|
private constructor();
|
|
8
21
|
/**
|
|
@@ -8,12 +8,24 @@ var axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
var errors_1 = __importDefault(require("../types/errors"));
|
|
9
9
|
var HttpClient = /** @class */ (function () {
|
|
10
10
|
function HttpClient(baseURL, unauthorizedCallback) {
|
|
11
|
+
var _this = this;
|
|
11
12
|
this.axios = axios_1.default.create({
|
|
12
13
|
baseURL: baseURL,
|
|
13
14
|
});
|
|
14
15
|
this.unauthorizedCallback = unauthorizedCallback;
|
|
16
|
+
HttpClient.globalInterceptors.forEach(function (interceptor) {
|
|
17
|
+
if (interceptor.request) {
|
|
18
|
+
_this.axios.interceptors.request.use(interceptor.request.onFulfilled, interceptor.request.onRejected);
|
|
19
|
+
}
|
|
20
|
+
if (interceptor.response) {
|
|
21
|
+
_this.axios.interceptors.response.use(interceptor.response.onFulfilled, interceptor.response.onRejected);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
15
24
|
this.initializeMiddleware();
|
|
16
25
|
}
|
|
26
|
+
HttpClient.setGlobalInterceptors = function (interceptors) {
|
|
27
|
+
HttpClient.globalInterceptors = interceptors;
|
|
28
|
+
};
|
|
17
29
|
HttpClient.create = function (baseURL, unauthorizedCallback) {
|
|
18
30
|
if (unauthorizedCallback === undefined) {
|
|
19
31
|
unauthorizedCallback = function () { return null; };
|
|
@@ -190,6 +202,7 @@ var HttpClient = /** @class */ (function () {
|
|
|
190
202
|
}
|
|
191
203
|
throw new errors_1.default(errorMessage, errorStatus, errorCode, errorHeaders);
|
|
192
204
|
};
|
|
205
|
+
HttpClient.globalInterceptors = [];
|
|
193
206
|
return HttpClient;
|
|
194
207
|
}());
|
|
195
208
|
exports.HttpClient = HttpClient;
|