@ip2geo/sdk 0.0.1 → 0.0.2
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.
- package/README.md +9 -3
- package/cjs/data/Constants.js +77 -1
- package/cjs/helpers/Http.js +3 -5
- package/cjs/index.js +16 -1
- package/cjs/langs/en_US.js +3 -1
- package/cjs/methods/ConvertIP.js +2 -2
- package/cjs/methods/ConvertIPs.js +6 -2
- package/cjs/methods/GetConversion.js +40 -0
- package/cjs/methods/GetConversions.js +44 -0
- package/cjs/methods/ListConversions.js +37 -0
- package/cjs/prebuild/package.json.js +1 -1
- package/esm/data/Constants.js +77 -2
- package/esm/helpers/Http.js +3 -5
- package/esm/index.js +12 -2
- package/esm/langs/en_US.js +3 -1
- package/esm/methods/ConvertIP.js +2 -2
- package/esm/methods/ConvertIPs.js +6 -2
- package/esm/methods/GetConversion.js +36 -0
- package/esm/methods/GetConversions.js +40 -0
- package/esm/methods/ListConversions.js +33 -0
- package/esm/prebuild/package.json.js +1 -1
- package/index.d.ts +772 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align='center'>
|
|
2
|
-
<a href='https://
|
|
2
|
+
<a href='https://ip2geo.dev'>
|
|
3
3
|
<img
|
|
4
4
|
src='https://cdn-prod.ip2geo.dev/assets/npm/generals/ip2geo.svg'
|
|
5
5
|
alt='Ip2Geo Logo'
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
12
|
<p align='center'>
|
|
13
|
-
Your go-to IP-to-Geo cloud service — fast, accurate, and built for developers. Start free with 2,000 monthly
|
|
13
|
+
Your go-to IP-to-Geo cloud service — fast, accurate, and built for developers. Start free with 2,000 monthly stored conversions.
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
16
|
<p align='center'>
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
•
|
|
23
23
|
<a href='https://app.ip2geo.dev'>
|
|
24
24
|
<b>
|
|
25
|
-
|
|
25
|
+
Dashboard
|
|
26
26
|
</b>
|
|
27
27
|
</a>
|
|
28
28
|
•
|
|
@@ -31,6 +31,12 @@
|
|
|
31
31
|
Documentation
|
|
32
32
|
</b>
|
|
33
33
|
</a>
|
|
34
|
+
•
|
|
35
|
+
<a href='https://status.ip2geo.dev'>
|
|
36
|
+
<b>
|
|
37
|
+
Services Status
|
|
38
|
+
</b>
|
|
39
|
+
</a>
|
|
34
40
|
</p>
|
|
35
41
|
|
|
36
42
|
<br />
|
package/cjs/data/Constants.js
CHANGED
|
@@ -19,7 +19,82 @@ const HEADER_TYPES = {
|
|
|
19
19
|
CONTENT_TYPE: 'Content-Type'
|
|
20
20
|
};
|
|
21
21
|
const ENDPOINTS = {
|
|
22
|
-
CONVERT: '/convert'
|
|
22
|
+
CONVERT: '/convert',
|
|
23
|
+
CONVERSIONS: {
|
|
24
|
+
GET: '/conversions/get',
|
|
25
|
+
LIST: '/conversions/list'
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const SELECT = {
|
|
29
|
+
CONVERSION: {
|
|
30
|
+
ID: 'id',
|
|
31
|
+
UNIQUE_ID: 'uniqueId',
|
|
32
|
+
DATA: 'data',
|
|
33
|
+
STATUS: 'status',
|
|
34
|
+
STARTED_AT: 'startedAt',
|
|
35
|
+
COMPLETED_AT: 'completedAt',
|
|
36
|
+
CREATED_AT: 'createdAt',
|
|
37
|
+
CREDITED: 'credited',
|
|
38
|
+
CONVERT_ONLY: 'convertOnly'
|
|
39
|
+
},
|
|
40
|
+
DATA: {
|
|
41
|
+
IP: 'data.ip',
|
|
42
|
+
TYPE: 'data.type',
|
|
43
|
+
IS_EU: 'data.is_eu',
|
|
44
|
+
CONTINENT: {
|
|
45
|
+
NAME: 'data.continent.name',
|
|
46
|
+
CODE: 'data.continent.code',
|
|
47
|
+
GEONAME_ID: 'data.continent.geoname_id',
|
|
48
|
+
COUNTRY: {
|
|
49
|
+
NAME: 'data.continent.country.name',
|
|
50
|
+
CODE: 'data.continent.country.code',
|
|
51
|
+
GEONAME_ID: 'data.continent.country.geoname_id',
|
|
52
|
+
PHONE_CODE: 'data.continent.country.phone_code',
|
|
53
|
+
CAPITAL: 'data.continent.country.capital',
|
|
54
|
+
TLD: 'data.continent.country.tld',
|
|
55
|
+
SUBDIVISION: {
|
|
56
|
+
NAME: 'data.continent.country.subdivision.name',
|
|
57
|
+
CODE: 'data.continent.country.subdivision.code'
|
|
58
|
+
},
|
|
59
|
+
CITY: {
|
|
60
|
+
NAME: 'data.continent.country.city.name',
|
|
61
|
+
GEONAME_ID: 'data.continent.country.city.geoname_id',
|
|
62
|
+
LATITUDE: 'data.continent.country.city.latitude',
|
|
63
|
+
LONGITUDE: 'data.continent.country.city.longitude',
|
|
64
|
+
ACCURACY_RADIUS: 'data.continent.country.city.accuracy_radius',
|
|
65
|
+
METRO_CODE: 'data.continent.country.city.metro_code',
|
|
66
|
+
POSTAL_CODE: 'data.continent.country.city.postal_code',
|
|
67
|
+
TIMEZONE: {
|
|
68
|
+
NAME: 'data.continent.country.city.timezone.name',
|
|
69
|
+
TIME_NOW: 'data.continent.country.city.timezone.time_now'
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
FLAG: {
|
|
73
|
+
IMG: 'data.continent.country.flag.img',
|
|
74
|
+
EMOJI: 'data.continent.country.flag.emoji',
|
|
75
|
+
EMOJI_UNICODE: 'data.continent.country.flag.emoji_unicode'
|
|
76
|
+
},
|
|
77
|
+
CURRENCY: {
|
|
78
|
+
NAME: 'data.continent.country.currency.name',
|
|
79
|
+
CODE: 'data.continent.country.currency.code',
|
|
80
|
+
SYMBOL: 'data.continent.country.currency.symbol'
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
REGISTERED_COUNTRY: {
|
|
85
|
+
NAME: 'data.registered_country.name',
|
|
86
|
+
CODE: 'data.registered_country.code',
|
|
87
|
+
GEONAME_ID: 'data.registered_country.geoname_id'
|
|
88
|
+
},
|
|
89
|
+
ASN: {
|
|
90
|
+
NUMBER: 'data.asn.number',
|
|
91
|
+
NAME: 'data.asn.name'
|
|
92
|
+
},
|
|
93
|
+
COMPLETION_TIME: {
|
|
94
|
+
MILISECONDS: 'data.completion_time.miliseconds',
|
|
95
|
+
SECONDS: 'data.completion_time.seconds'
|
|
96
|
+
}
|
|
97
|
+
}
|
|
23
98
|
};
|
|
24
99
|
|
|
25
100
|
exports.API_ENDPOINT = API_ENDPOINT;
|
|
@@ -31,3 +106,4 @@ exports.HEADER_KEYS = HEADER_KEYS;
|
|
|
31
106
|
exports.HEADER_TYPES = HEADER_TYPES;
|
|
32
107
|
exports.HTTP_METHODS = HTTP_METHODS;
|
|
33
108
|
exports.NPM_REGISTRY_URL = NPM_REGISTRY_URL;
|
|
109
|
+
exports.SELECT = SELECT;
|
package/cjs/helpers/Http.js
CHANGED
|
@@ -7,7 +7,7 @@ var States = require('../data/States.js');
|
|
|
7
7
|
var Console = require('./Console.js');
|
|
8
8
|
var IsBrowser = require('./IsBrowser.js');
|
|
9
9
|
|
|
10
|
-
const Http = async (endpoint,
|
|
10
|
+
const Http = async (endpoint, body) => {
|
|
11
11
|
const options = {
|
|
12
12
|
method: Constants.HTTP_METHODS.GET,
|
|
13
13
|
headers: {
|
|
@@ -15,11 +15,9 @@ const Http = async (endpoint, ipAddresses) => {
|
|
|
15
15
|
[Constants.HEADER_KEYS.X_API_KEY]: States.STATE.AUTH_KEY
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
-
if (
|
|
18
|
+
if (body && Object.keys(body).length > 0) {
|
|
19
19
|
options['method'] = Constants.HTTP_METHODS.POST;
|
|
20
|
-
options['body'] = JSON.stringify(
|
|
21
|
-
ips: ipAddresses
|
|
22
|
-
});
|
|
20
|
+
options['body'] = JSON.stringify(body);
|
|
23
21
|
}
|
|
24
22
|
const isBrowser = IsBrowser.default();
|
|
25
23
|
if (!isBrowser) {
|
package/cjs/index.js
CHANGED
|
@@ -4,15 +4,30 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var ConvertIP = require('./methods/ConvertIP.js');
|
|
6
6
|
var ConvertIPs = require('./methods/ConvertIPs.js');
|
|
7
|
+
var GetConversion = require('./methods/GetConversion.js');
|
|
8
|
+
var GetConversions = require('./methods/GetConversions.js');
|
|
9
|
+
var ListConversions = require('./methods/ListConversions.js');
|
|
7
10
|
var Init = require('./methods/Init.js');
|
|
11
|
+
var Constants = require('./data/Constants.js');
|
|
12
|
+
var IpValidation = require('./helpers/IpValidation.js');
|
|
8
13
|
|
|
9
14
|
const Ip2Geo = {
|
|
10
15
|
ConvertIPs: ConvertIPs.default,
|
|
11
16
|
ConvertIP: ConvertIP.default,
|
|
12
|
-
|
|
17
|
+
GetConversion: GetConversion.default,
|
|
18
|
+
GetConversions: GetConversions.default,
|
|
19
|
+
ListConversions: ListConversions.default,
|
|
20
|
+
Init: Init.default,
|
|
21
|
+
IpValidation: IpValidation.default,
|
|
22
|
+
SELECT: Constants.SELECT
|
|
13
23
|
};
|
|
14
24
|
|
|
15
25
|
exports.ConvertIP = ConvertIP.default;
|
|
16
26
|
exports.ConvertIPs = ConvertIPs.default;
|
|
27
|
+
exports.GetConversion = GetConversion.default;
|
|
28
|
+
exports.GetConversions = GetConversions.default;
|
|
29
|
+
exports.ListConversions = ListConversions.default;
|
|
17
30
|
exports.Init = Init.default;
|
|
31
|
+
exports.SELECT = Constants.SELECT;
|
|
32
|
+
exports.IpValidation = IpValidation.default;
|
|
18
33
|
exports.default = Ip2Geo;
|
package/cjs/langs/en_US.js
CHANGED
|
@@ -25,7 +25,9 @@ const en_US = {
|
|
|
25
25
|
'ip-addresses-are-required-to-convert-them': 'IP addresses are required to convert them.',
|
|
26
26
|
'invalid-ip-address-so-we-could-not-convert-it': 'Invalid IP address so we could not convert it.',
|
|
27
27
|
'all-ip-addresses-are-invalid': 'All IP addresses are invalid.',
|
|
28
|
-
'some-ip-addresses-are-invalid': 'Some IP addresses are invalid.'
|
|
28
|
+
'some-ip-addresses-are-invalid': 'Some IP addresses are invalid.',
|
|
29
|
+
'conversion-id-is-required': 'Conversion ID is required to retrieve the conversion.',
|
|
30
|
+
'conversion-ids-are-required': 'Conversion IDs are required to retrieve the conversions.'
|
|
29
31
|
}
|
|
30
32
|
};
|
|
31
33
|
|
package/cjs/methods/ConvertIP.js
CHANGED
|
@@ -9,7 +9,7 @@ var IpValidation = require('../helpers/IpValidation.js');
|
|
|
9
9
|
var Translation = require('../helpers/Translation.js');
|
|
10
10
|
|
|
11
11
|
const ConvertIP = async (options) => {
|
|
12
|
-
const { ip } = options || {};
|
|
12
|
+
const { ip, convertOnly = false } = options || {};
|
|
13
13
|
if (!ip)
|
|
14
14
|
return {
|
|
15
15
|
success: false,
|
|
@@ -34,7 +34,7 @@ const ConvertIP = async (options) => {
|
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
try {
|
|
37
|
-
const ipLink = `${Constants.API_ENDPOINT}${Constants.ENDPOINTS.CONVERT}?ip=${ip}`;
|
|
37
|
+
const ipLink = `${Constants.API_ENDPOINT}${Constants.ENDPOINTS.CONVERT}?ip=${ip}&convertOnly=${convertOnly}`;
|
|
38
38
|
const ipResponse = await Http.default(ipLink);
|
|
39
39
|
if (ipResponse)
|
|
40
40
|
return ipResponse;
|
|
@@ -9,7 +9,7 @@ var IpValidation = require('../helpers/IpValidation.js');
|
|
|
9
9
|
var Translation = require('../helpers/Translation.js');
|
|
10
10
|
|
|
11
11
|
const ConvertIPs = async (props) => {
|
|
12
|
-
const { ips } = props;
|
|
12
|
+
const { ips, convertOnly = false } = props || {};
|
|
13
13
|
if (!ips || !Array.isArray(ips) || ips.length === 0)
|
|
14
14
|
return {
|
|
15
15
|
success: false,
|
|
@@ -44,7 +44,11 @@ const ConvertIPs = async (props) => {
|
|
|
44
44
|
};
|
|
45
45
|
try {
|
|
46
46
|
const ipLink = `${Constants.API_ENDPOINT}${Constants.ENDPOINTS.CONVERT}`;
|
|
47
|
-
const
|
|
47
|
+
const body = {
|
|
48
|
+
ips,
|
|
49
|
+
convertOnly
|
|
50
|
+
};
|
|
51
|
+
const ipResponse = await Http.default(ipLink, body);
|
|
48
52
|
if (ipResponse)
|
|
49
53
|
return ipResponse;
|
|
50
54
|
else
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var Constants = require('../data/Constants.js');
|
|
6
|
+
var Console = require('../helpers/Console.js');
|
|
7
|
+
var Http = require('../helpers/Http.js');
|
|
8
|
+
var Translation = require('../helpers/Translation.js');
|
|
9
|
+
|
|
10
|
+
const GetConversion = async (options) => {
|
|
11
|
+
const { conversionId, select } = options || {};
|
|
12
|
+
if (!conversionId)
|
|
13
|
+
return {
|
|
14
|
+
success: false,
|
|
15
|
+
message: Translation.default('conversions.conversion-id-is-required'),
|
|
16
|
+
code: 400,
|
|
17
|
+
data: null,
|
|
18
|
+
_req: {
|
|
19
|
+
reqId: null,
|
|
20
|
+
resTime: 0
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
try {
|
|
24
|
+
const params = new URLSearchParams();
|
|
25
|
+
if (select && select.length > 0)
|
|
26
|
+
params.append('select', select.join(','));
|
|
27
|
+
const url = `${Constants.API_ENDPOINT}${Constants.ENDPOINTS.CONVERSIONS.GET}?${params.toString()}`;
|
|
28
|
+
const response = await Http.default(url);
|
|
29
|
+
if (response)
|
|
30
|
+
return response;
|
|
31
|
+
else
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
Console.default.Error('GetConversion', error);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.default = GetConversion;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var Constants = require('../data/Constants.js');
|
|
6
|
+
var Console = require('../helpers/Console.js');
|
|
7
|
+
var Http = require('../helpers/Http.js');
|
|
8
|
+
var Translation = require('../helpers/Translation.js');
|
|
9
|
+
|
|
10
|
+
const GetConversions = async (options) => {
|
|
11
|
+
const { conversionIds, select } = options || {};
|
|
12
|
+
if (!conversionIds || conversionIds.length === 0)
|
|
13
|
+
return {
|
|
14
|
+
success: false,
|
|
15
|
+
message: Translation.default('conversions.conversion-ids-are-required'),
|
|
16
|
+
code: 400,
|
|
17
|
+
data: null,
|
|
18
|
+
_req: {
|
|
19
|
+
reqId: null,
|
|
20
|
+
resTime: 0
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
try {
|
|
24
|
+
const params = new URLSearchParams();
|
|
25
|
+
if (select && select.length > 0)
|
|
26
|
+
params.append('select', select.join(','));
|
|
27
|
+
const queryString = params.toString();
|
|
28
|
+
const url = `${Constants.API_ENDPOINT}${Constants.ENDPOINTS.CONVERSIONS.GET}${queryString ? `?${queryString}` : ''}`;
|
|
29
|
+
const response = await Http.default(url, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
body: JSON.stringify({ conversionIds })
|
|
32
|
+
});
|
|
33
|
+
if (response)
|
|
34
|
+
return response;
|
|
35
|
+
else
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
Console.default.Error('GetConversions', error);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.default = GetConversions;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var Constants = require('../data/Constants.js');
|
|
6
|
+
var Console = require('../helpers/Console.js');
|
|
7
|
+
var Http = require('../helpers/Http.js');
|
|
8
|
+
|
|
9
|
+
const ListConversions = async (options) => {
|
|
10
|
+
const { offset = 0, limit = 50, select, ipSearch } = options || {};
|
|
11
|
+
try {
|
|
12
|
+
const params = new URLSearchParams();
|
|
13
|
+
if (offset > 0)
|
|
14
|
+
params.append('offset', offset.toString());
|
|
15
|
+
if (limit && limit !== 50)
|
|
16
|
+
params.append('limit', limit.toString());
|
|
17
|
+
if (select && select.length > 0)
|
|
18
|
+
params.append('select', select.join(','));
|
|
19
|
+
if (ipSearch)
|
|
20
|
+
params.append('ipSearch', ipSearch);
|
|
21
|
+
const queryString = params.toString();
|
|
22
|
+
const url = queryString
|
|
23
|
+
? `${Constants.API_ENDPOINT}${Constants.ENDPOINTS.CONVERSIONS.LIST}?${queryString}`
|
|
24
|
+
: `${Constants.API_ENDPOINT}${Constants.ENDPOINTS.CONVERSIONS.LIST}`;
|
|
25
|
+
const response = await Http.default(url);
|
|
26
|
+
if (response)
|
|
27
|
+
return response;
|
|
28
|
+
else
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
Console.default.Error('ListConversions', error);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.default = ListConversions;
|
package/esm/data/Constants.js
CHANGED
|
@@ -17,7 +17,82 @@ const HEADER_TYPES = {
|
|
|
17
17
|
CONTENT_TYPE: 'Content-Type'
|
|
18
18
|
};
|
|
19
19
|
const ENDPOINTS = {
|
|
20
|
-
CONVERT: '/convert'
|
|
20
|
+
CONVERT: '/convert',
|
|
21
|
+
CONVERSIONS: {
|
|
22
|
+
GET: '/conversions/get',
|
|
23
|
+
LIST: '/conversions/list'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const SELECT = {
|
|
27
|
+
CONVERSION: {
|
|
28
|
+
ID: 'id',
|
|
29
|
+
UNIQUE_ID: 'uniqueId',
|
|
30
|
+
DATA: 'data',
|
|
31
|
+
STATUS: 'status',
|
|
32
|
+
STARTED_AT: 'startedAt',
|
|
33
|
+
COMPLETED_AT: 'completedAt',
|
|
34
|
+
CREATED_AT: 'createdAt',
|
|
35
|
+
CREDITED: 'credited',
|
|
36
|
+
CONVERT_ONLY: 'convertOnly'
|
|
37
|
+
},
|
|
38
|
+
DATA: {
|
|
39
|
+
IP: 'data.ip',
|
|
40
|
+
TYPE: 'data.type',
|
|
41
|
+
IS_EU: 'data.is_eu',
|
|
42
|
+
CONTINENT: {
|
|
43
|
+
NAME: 'data.continent.name',
|
|
44
|
+
CODE: 'data.continent.code',
|
|
45
|
+
GEONAME_ID: 'data.continent.geoname_id',
|
|
46
|
+
COUNTRY: {
|
|
47
|
+
NAME: 'data.continent.country.name',
|
|
48
|
+
CODE: 'data.continent.country.code',
|
|
49
|
+
GEONAME_ID: 'data.continent.country.geoname_id',
|
|
50
|
+
PHONE_CODE: 'data.continent.country.phone_code',
|
|
51
|
+
CAPITAL: 'data.continent.country.capital',
|
|
52
|
+
TLD: 'data.continent.country.tld',
|
|
53
|
+
SUBDIVISION: {
|
|
54
|
+
NAME: 'data.continent.country.subdivision.name',
|
|
55
|
+
CODE: 'data.continent.country.subdivision.code'
|
|
56
|
+
},
|
|
57
|
+
CITY: {
|
|
58
|
+
NAME: 'data.continent.country.city.name',
|
|
59
|
+
GEONAME_ID: 'data.continent.country.city.geoname_id',
|
|
60
|
+
LATITUDE: 'data.continent.country.city.latitude',
|
|
61
|
+
LONGITUDE: 'data.continent.country.city.longitude',
|
|
62
|
+
ACCURACY_RADIUS: 'data.continent.country.city.accuracy_radius',
|
|
63
|
+
METRO_CODE: 'data.continent.country.city.metro_code',
|
|
64
|
+
POSTAL_CODE: 'data.continent.country.city.postal_code',
|
|
65
|
+
TIMEZONE: {
|
|
66
|
+
NAME: 'data.continent.country.city.timezone.name',
|
|
67
|
+
TIME_NOW: 'data.continent.country.city.timezone.time_now'
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
FLAG: {
|
|
71
|
+
IMG: 'data.continent.country.flag.img',
|
|
72
|
+
EMOJI: 'data.continent.country.flag.emoji',
|
|
73
|
+
EMOJI_UNICODE: 'data.continent.country.flag.emoji_unicode'
|
|
74
|
+
},
|
|
75
|
+
CURRENCY: {
|
|
76
|
+
NAME: 'data.continent.country.currency.name',
|
|
77
|
+
CODE: 'data.continent.country.currency.code',
|
|
78
|
+
SYMBOL: 'data.continent.country.currency.symbol'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
REGISTERED_COUNTRY: {
|
|
83
|
+
NAME: 'data.registered_country.name',
|
|
84
|
+
CODE: 'data.registered_country.code',
|
|
85
|
+
GEONAME_ID: 'data.registered_country.geoname_id'
|
|
86
|
+
},
|
|
87
|
+
ASN: {
|
|
88
|
+
NUMBER: 'data.asn.number',
|
|
89
|
+
NAME: 'data.asn.name'
|
|
90
|
+
},
|
|
91
|
+
COMPLETION_TIME: {
|
|
92
|
+
MILISECONDS: 'data.completion_time.miliseconds',
|
|
93
|
+
SECONDS: 'data.completion_time.seconds'
|
|
94
|
+
}
|
|
95
|
+
}
|
|
21
96
|
};
|
|
22
97
|
|
|
23
|
-
export { API_ENDPOINT, DOCS_URL, ENDPOINTS, FILE_FORMATS, FILE_TYPES, HEADER_KEYS, HEADER_TYPES, HTTP_METHODS, NPM_REGISTRY_URL };
|
|
98
|
+
export { API_ENDPOINT, DOCS_URL, ENDPOINTS, FILE_FORMATS, FILE_TYPES, HEADER_KEYS, HEADER_TYPES, HTTP_METHODS, NPM_REGISTRY_URL, SELECT };
|
package/esm/helpers/Http.js
CHANGED
|
@@ -3,7 +3,7 @@ import { STATE } from '../data/States.js';
|
|
|
3
3
|
import Console from './Console.js';
|
|
4
4
|
import IsBrowser from './IsBrowser.js';
|
|
5
5
|
|
|
6
|
-
const Http = async (endpoint,
|
|
6
|
+
const Http = async (endpoint, body) => {
|
|
7
7
|
const options = {
|
|
8
8
|
method: HTTP_METHODS.GET,
|
|
9
9
|
headers: {
|
|
@@ -11,11 +11,9 @@ const Http = async (endpoint, ipAddresses) => {
|
|
|
11
11
|
[HEADER_KEYS.X_API_KEY]: STATE.AUTH_KEY
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
|
-
if (
|
|
14
|
+
if (body && Object.keys(body).length > 0) {
|
|
15
15
|
options['method'] = HTTP_METHODS.POST;
|
|
16
|
-
options['body'] = JSON.stringify(
|
|
17
|
-
ips: ipAddresses
|
|
18
|
-
});
|
|
16
|
+
options['body'] = JSON.stringify(body);
|
|
19
17
|
}
|
|
20
18
|
const isBrowser = IsBrowser();
|
|
21
19
|
if (!isBrowser) {
|
package/esm/index.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import ConvertIP from './methods/ConvertIP.js';
|
|
2
2
|
import ConvertIPs from './methods/ConvertIPs.js';
|
|
3
|
+
import GetConversion from './methods/GetConversion.js';
|
|
4
|
+
import GetConversions from './methods/GetConversions.js';
|
|
5
|
+
import ListConversions from './methods/ListConversions.js';
|
|
3
6
|
import Init from './methods/Init.js';
|
|
7
|
+
import { SELECT } from './data/Constants.js';
|
|
8
|
+
import IpValidation from './helpers/IpValidation.js';
|
|
4
9
|
|
|
5
10
|
const Ip2Geo = {
|
|
6
11
|
ConvertIPs,
|
|
7
12
|
ConvertIP,
|
|
8
|
-
|
|
13
|
+
GetConversion,
|
|
14
|
+
GetConversions,
|
|
15
|
+
ListConversions,
|
|
16
|
+
Init,
|
|
17
|
+
IpValidation,
|
|
18
|
+
SELECT
|
|
9
19
|
};
|
|
10
20
|
|
|
11
|
-
export { ConvertIP, ConvertIPs, Init, Ip2Geo as default };
|
|
21
|
+
export { ConvertIP, ConvertIPs, GetConversion, GetConversions, Init, IpValidation, ListConversions, SELECT, Ip2Geo as default };
|
package/esm/langs/en_US.js
CHANGED
|
@@ -21,7 +21,9 @@ const en_US = {
|
|
|
21
21
|
'ip-addresses-are-required-to-convert-them': 'IP addresses are required to convert them.',
|
|
22
22
|
'invalid-ip-address-so-we-could-not-convert-it': 'Invalid IP address so we could not convert it.',
|
|
23
23
|
'all-ip-addresses-are-invalid': 'All IP addresses are invalid.',
|
|
24
|
-
'some-ip-addresses-are-invalid': 'Some IP addresses are invalid.'
|
|
24
|
+
'some-ip-addresses-are-invalid': 'Some IP addresses are invalid.',
|
|
25
|
+
'conversion-id-is-required': 'Conversion ID is required to retrieve the conversion.',
|
|
26
|
+
'conversion-ids-are-required': 'Conversion IDs are required to retrieve the conversions.'
|
|
25
27
|
}
|
|
26
28
|
};
|
|
27
29
|
|
package/esm/methods/ConvertIP.js
CHANGED
|
@@ -5,7 +5,7 @@ import IpValidation from '../helpers/IpValidation.js';
|
|
|
5
5
|
import Translation from '../helpers/Translation.js';
|
|
6
6
|
|
|
7
7
|
const ConvertIP = async (options) => {
|
|
8
|
-
const { ip } = options || {};
|
|
8
|
+
const { ip, convertOnly = false } = options || {};
|
|
9
9
|
if (!ip)
|
|
10
10
|
return {
|
|
11
11
|
success: false,
|
|
@@ -30,7 +30,7 @@ const ConvertIP = async (options) => {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
try {
|
|
33
|
-
const ipLink = `${API_ENDPOINT}${ENDPOINTS.CONVERT}?ip=${ip}`;
|
|
33
|
+
const ipLink = `${API_ENDPOINT}${ENDPOINTS.CONVERT}?ip=${ip}&convertOnly=${convertOnly}`;
|
|
34
34
|
const ipResponse = await Http(ipLink);
|
|
35
35
|
if (ipResponse)
|
|
36
36
|
return ipResponse;
|
|
@@ -5,7 +5,7 @@ import IpValidation from '../helpers/IpValidation.js';
|
|
|
5
5
|
import Translation from '../helpers/Translation.js';
|
|
6
6
|
|
|
7
7
|
const ConvertIPs = async (props) => {
|
|
8
|
-
const { ips } = props;
|
|
8
|
+
const { ips, convertOnly = false } = props || {};
|
|
9
9
|
if (!ips || !Array.isArray(ips) || ips.length === 0)
|
|
10
10
|
return {
|
|
11
11
|
success: false,
|
|
@@ -40,7 +40,11 @@ const ConvertIPs = async (props) => {
|
|
|
40
40
|
};
|
|
41
41
|
try {
|
|
42
42
|
const ipLink = `${API_ENDPOINT}${ENDPOINTS.CONVERT}`;
|
|
43
|
-
const
|
|
43
|
+
const body = {
|
|
44
|
+
ips,
|
|
45
|
+
convertOnly
|
|
46
|
+
};
|
|
47
|
+
const ipResponse = await Http(ipLink, body);
|
|
44
48
|
if (ipResponse)
|
|
45
49
|
return ipResponse;
|
|
46
50
|
else
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { API_ENDPOINT, ENDPOINTS } from '../data/Constants.js';
|
|
2
|
+
import Console from '../helpers/Console.js';
|
|
3
|
+
import Http from '../helpers/Http.js';
|
|
4
|
+
import Translation from '../helpers/Translation.js';
|
|
5
|
+
|
|
6
|
+
const GetConversion = async (options) => {
|
|
7
|
+
const { conversionId, select } = options || {};
|
|
8
|
+
if (!conversionId)
|
|
9
|
+
return {
|
|
10
|
+
success: false,
|
|
11
|
+
message: Translation('conversions.conversion-id-is-required'),
|
|
12
|
+
code: 400,
|
|
13
|
+
data: null,
|
|
14
|
+
_req: {
|
|
15
|
+
reqId: null,
|
|
16
|
+
resTime: 0
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const params = new URLSearchParams();
|
|
21
|
+
if (select && select.length > 0)
|
|
22
|
+
params.append('select', select.join(','));
|
|
23
|
+
const url = `${API_ENDPOINT}${ENDPOINTS.CONVERSIONS.GET}?${params.toString()}`;
|
|
24
|
+
const response = await Http(url);
|
|
25
|
+
if (response)
|
|
26
|
+
return response;
|
|
27
|
+
else
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
Console.Error('GetConversion', error);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { GetConversion as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { API_ENDPOINT, ENDPOINTS } from '../data/Constants.js';
|
|
2
|
+
import Console from '../helpers/Console.js';
|
|
3
|
+
import Http from '../helpers/Http.js';
|
|
4
|
+
import Translation from '../helpers/Translation.js';
|
|
5
|
+
|
|
6
|
+
const GetConversions = async (options) => {
|
|
7
|
+
const { conversionIds, select } = options || {};
|
|
8
|
+
if (!conversionIds || conversionIds.length === 0)
|
|
9
|
+
return {
|
|
10
|
+
success: false,
|
|
11
|
+
message: Translation('conversions.conversion-ids-are-required'),
|
|
12
|
+
code: 400,
|
|
13
|
+
data: null,
|
|
14
|
+
_req: {
|
|
15
|
+
reqId: null,
|
|
16
|
+
resTime: 0
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const params = new URLSearchParams();
|
|
21
|
+
if (select && select.length > 0)
|
|
22
|
+
params.append('select', select.join(','));
|
|
23
|
+
const queryString = params.toString();
|
|
24
|
+
const url = `${API_ENDPOINT}${ENDPOINTS.CONVERSIONS.GET}${queryString ? `?${queryString}` : ''}`;
|
|
25
|
+
const response = await Http(url, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
body: JSON.stringify({ conversionIds })
|
|
28
|
+
});
|
|
29
|
+
if (response)
|
|
30
|
+
return response;
|
|
31
|
+
else
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
Console.Error('GetConversions', error);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { GetConversions as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { API_ENDPOINT, ENDPOINTS } from '../data/Constants.js';
|
|
2
|
+
import Console from '../helpers/Console.js';
|
|
3
|
+
import Http from '../helpers/Http.js';
|
|
4
|
+
|
|
5
|
+
const ListConversions = async (options) => {
|
|
6
|
+
const { offset = 0, limit = 50, select, ipSearch } = options || {};
|
|
7
|
+
try {
|
|
8
|
+
const params = new URLSearchParams();
|
|
9
|
+
if (offset > 0)
|
|
10
|
+
params.append('offset', offset.toString());
|
|
11
|
+
if (limit && limit !== 50)
|
|
12
|
+
params.append('limit', limit.toString());
|
|
13
|
+
if (select && select.length > 0)
|
|
14
|
+
params.append('select', select.join(','));
|
|
15
|
+
if (ipSearch)
|
|
16
|
+
params.append('ipSearch', ipSearch);
|
|
17
|
+
const queryString = params.toString();
|
|
18
|
+
const url = queryString
|
|
19
|
+
? `${API_ENDPOINT}${ENDPOINTS.CONVERSIONS.LIST}?${queryString}`
|
|
20
|
+
: `${API_ENDPOINT}${ENDPOINTS.CONVERSIONS.LIST}`;
|
|
21
|
+
const response = await Http(url);
|
|
22
|
+
if (response)
|
|
23
|
+
return response;
|
|
24
|
+
else
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
Console.Error('ListConversions', error);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { ListConversions as default };
|