@rabbitio/ui-kit 1.0.0-beta.41 → 1.0.0-beta.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabbitio/ui-kit",
3
- "version": "1.0.0-beta.41",
3
+ "version": "1.0.0-beta.42",
4
4
  "description": "Rabbit.io react.js components kit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -0,0 +1,138 @@
1
+ import EventBusInstance from "eventbusjs";
2
+ import { ExternalApiProvider } from "../../robustExteranlApiCallerService/externalApiProvider.js";
3
+ import { ApiGroups } from "./apiGroups.js";
4
+ import { CachedRobustExternalApiCallerService } from "../../robustExteranlApiCallerService/cachedRobustExternalApiCallerService.js";
5
+ import { Cache } from "../utils/cache.js";
6
+ import { improveAndRethrow } from "../errorUtils.js";
7
+
8
+ class BigdatacloudIpAddressProvider extends ExternalApiProvider {
9
+ constructor() {
10
+ super(
11
+ "https://api.bigdatacloud.net/data/client-ip",
12
+ "get",
13
+ 15000,
14
+ ApiGroups.BIGDATACLOUD
15
+ );
16
+ }
17
+
18
+ getDataByResponse(
19
+ response,
20
+ params = [],
21
+ subRequestIndex = 0,
22
+ iterationsData = []
23
+ ) {
24
+ return response?.data && response.data?.ipString;
25
+ }
26
+ }
27
+
28
+ class TrackipIpAddressProvider extends ExternalApiProvider {
29
+ constructor() {
30
+ super("https://www.trackip.net/ip", "get", 15000, ApiGroups.TRACKIP);
31
+ }
32
+
33
+ getDataByResponse(
34
+ response,
35
+ params = [],
36
+ subRequestIndex = 0,
37
+ iterationsData = []
38
+ ) {
39
+ return response?.data;
40
+ }
41
+ }
42
+
43
+ class IpifyV6IpAddressProvider extends ExternalApiProvider {
44
+ constructor() {
45
+ super(
46
+ "https://api6.ipify.org/?format=json",
47
+ "get",
48
+ 15000,
49
+ ApiGroups.IPIFY
50
+ );
51
+ }
52
+
53
+ getDataByResponse(
54
+ response,
55
+ params = [],
56
+ subRequestIndex = 0,
57
+ iterationsData = []
58
+ ) {
59
+ return response?.data && response.data?.ip;
60
+ }
61
+ }
62
+
63
+ class IpifyIpAddressProvider extends ExternalApiProvider {
64
+ constructor() {
65
+ super(
66
+ "https://api.ipify.org/?format=json",
67
+ "get",
68
+ 15000,
69
+ ApiGroups.IPIFY
70
+ );
71
+ }
72
+
73
+ getDataByResponse(
74
+ response,
75
+ params = [],
76
+ subRequestIndex = 0,
77
+ iterationsData = []
78
+ ) {
79
+ return response?.data && response.data?.ip;
80
+ }
81
+ }
82
+
83
+ class WhatismyipaddressIpAddressProvider extends ExternalApiProvider {
84
+ constructor() {
85
+ super(
86
+ "http://bot.whatismyipaddress.com/",
87
+ "get",
88
+ 15000,
89
+ ApiGroups.WHATISMYIPADDRESS
90
+ );
91
+ }
92
+
93
+ getDataByResponse(
94
+ response,
95
+ params = [],
96
+ subRequestIndex = 0,
97
+ iterationsData = []
98
+ ) {
99
+ return response?.data;
100
+ }
101
+ }
102
+
103
+ export class IpAddressProvider {
104
+ static externalIPAddressAPICaller =
105
+ new CachedRobustExternalApiCallerService(
106
+ "externalIPAddressAPICaller",
107
+ new Cache(EventBusInstance),
108
+ [
109
+ new BigdatacloudIpAddressProvider(),
110
+ new TrackipIpAddressProvider(),
111
+ new IpifyV6IpAddressProvider(),
112
+ new IpifyIpAddressProvider(),
113
+ new WhatismyipaddressIpAddressProvider(),
114
+ ],
115
+ 300_000
116
+ );
117
+
118
+ /**
119
+ * Returns current public IP address identified by one of external services.
120
+ *
121
+ * It is easier than manual identification and also (as ip needed for server side to check it) it saves us from
122
+ * issues related to changes of infrastructure configurations (like adding proxies etc.) so we should not configure
123
+ * anything on server side to get correct client's IP.
124
+ *
125
+ * @returns {Promise<String>} IP address
126
+ * @throws {Error} if fails to retrieve IP address from all the services
127
+ */
128
+ static async getClientIpAddress() {
129
+ try {
130
+ return await this.externalIPAddressAPICaller.callExternalAPICached(
131
+ [],
132
+ 7000
133
+ );
134
+ } catch (e) {
135
+ improveAndRethrow(e, "getClientIpAddress");
136
+ }
137
+ }
138
+ }
package/src/index.js CHANGED
@@ -31,6 +31,7 @@ export { postponeExecution } from "./common/utils/postponeExecution.js";
31
31
  export { AxiosAdapter } from "./common/adapters/axiosAdapter.js";
32
32
 
33
33
  export { EmailsApi } from "./common/utils/emailAPI.js";
34
+ export { IpAddressProvider } from "./common/external-apis/ipAddressProviders.js";
34
35
 
35
36
  // Robust data retriever service and related APIs
36
37
  export { CacheAndConcurrentRequestsResolver } from "./robustExteranlApiCallerService/cacheAndConcurrentRequestsResolver.js";
@@ -19,7 +19,7 @@ export class RobustExternalAPICallerService {
19
19
  static statsCollector = new ExternalServicesStatsCollector();
20
20
 
21
21
  static getStats() {
22
- this.statsCollector.getStats();
22
+ return this.statsCollector.getStats();
23
23
  }
24
24
 
25
25
  /**