@reyaxyz/risk-sdk 0.2.2 → 0.3.1

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,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -50,23 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
50
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
36
  }
52
37
  };
53
- var __importDefault = (this && this.__importDefault) || function (mod) {
54
- return (mod && mod.__esModule) ? mod : { "default": mod };
55
- };
56
38
  Object.defineProperty(exports, "__esModule", { value: true });
57
- var common_1 = require("@reyaxyz/common");
58
- var axios_1 = __importDefault(require("axios"));
59
- var GeofencingClient = /** @class */ (function (_super) {
60
- __extends(GeofencingClient, _super);
61
- function GeofencingClient(ipInfoApiKey, host, apiTimeout) {
62
- var _this = _super.call(this, host, apiTimeout) || this;
63
- _this.cache = {}; // Cache for storing IP info results
64
- _this.ipInfoApiKey = ipInfoApiKey;
65
- return _this;
39
+ var GeofencingClient = /** @class */ (function () {
40
+ function GeofencingClient(ipInfoApiKey) {
41
+ this.cache = {}; // Cache for storing IP info results
42
+ this.ipInfoApiKey = ipInfoApiKey;
66
43
  }
67
44
  GeofencingClient.prototype.checkIPAddress = function (params) {
68
45
  return __awaiter(this, void 0, void 0, function () {
69
- var cachedResult, url, response, ipInfo;
46
+ var cachedResult, url, response, ipInfo, error_1;
70
47
  return __generator(this, function (_a) {
71
48
  switch (_a.label) {
72
49
  case 0:
@@ -78,20 +55,39 @@ var GeofencingClient = /** @class */ (function (_super) {
78
55
  }];
79
56
  }
80
57
  url = "https://ipinfo.io/".concat(params.ipAddress, "?token=").concat(this.ipInfoApiKey);
81
- return [4 /*yield*/, axios_1.default.get(url)];
58
+ _a.label = 1;
82
59
  case 1:
60
+ _a.trys.push([1, 4, , 5]);
61
+ return [4 /*yield*/, fetch(url, {
62
+ method: 'GET',
63
+ headers: {
64
+ Accept: 'application/json',
65
+ },
66
+ })];
67
+ case 2:
83
68
  response = _a.sent();
84
- ipInfo = response.data;
85
- // Store the result in cache before returning
69
+ // Check if the response is successful
70
+ if (!response.ok) {
71
+ throw new Error("Error fetching IP info: ".concat(response.statusText));
72
+ }
73
+ return [4 /*yield*/, response.json()];
74
+ case 3:
75
+ ipInfo = (_a.sent());
76
+ // Proceed with the rest of your logic
86
77
  this.cache[params.ipAddress] = ipInfo;
87
78
  return [2 /*return*/, {
88
79
  isVpn: ipInfo.privacy.vpn,
89
80
  }];
81
+ case 4:
82
+ error_1 = _a.sent();
83
+ console.error('Failed to fetch IP info:', error_1);
84
+ throw new Error('Failed to check IP address');
85
+ case 5: return [2 /*return*/];
90
86
  }
91
87
  });
92
88
  });
93
89
  };
94
90
  return GeofencingClient;
95
- }(common_1.RestClient));
91
+ }());
96
92
  exports.default = GeofencingClient;
97
93
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/geofencing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAqD;AAErD,gDAA0B;AAO1B;IAA8C,oCAAU;IAItD,0BAAY,YAAoB,EAAE,IAAY,EAAE,UAA0B;QACxE,YAAA,MAAK,YAAC,IAAI,EAAE,UAAU,CAAC,SAAC;QAHlB,WAAK,GAAgB,EAAE,CAAC,CAAC,oCAAoC;QAInE,KAAI,CAAC,YAAY,GAAG,YAAY,CAAC;;IACnC,CAAC;IAEK,yCAAc,GAApB,UACE,MAA4B;;;;;;wBAGtB,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;wBAClD,IAAI,YAAY,EAAE,CAAC;4BACjB,wCAAwC;4BACxC,sBAAO;oCACL,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG;iCAChC,EAAC;wBACJ,CAAC;wBAGK,GAAG,GAAG,4BAAqB,MAAM,CAAC,SAAS,oBAAU,IAAI,CAAC,YAAY,CAAE,CAAC;wBAC9D,qBAAM,eAAK,CAAC,GAAG,CAAS,GAAG,CAAC,EAAA;;wBAAvC,QAAQ,GAAG,SAA4B;wBACvC,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC;wBAE7B,6CAA6C;wBAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;wBAEtC,sBAAO;gCACL,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG;6BAC1B,EAAC;;;;KACH;IACH,uBAAC;AAAD,CAAC,AAjCD,CAA8C,mBAAU,GAiCvD","sourcesContent":["import { RestClient, IpInfo } from '@reyaxyz/common';\nimport { CheckIPAddressParams, CheckIPAddressResult } from './types';\nimport axios from 'axios';\n\n// Define a cache interface\ninterface IpInfoCache {\n [key: string]: IpInfo;\n}\n\nexport default class GeofencingClient extends RestClient {\n readonly ipInfoApiKey: string;\n private cache: IpInfoCache = {}; // Cache for storing IP info results\n\n constructor(ipInfoApiKey: string, host: string, apiTimeout?: number | null) {\n super(host, apiTimeout);\n this.ipInfoApiKey = ipInfoApiKey;\n }\n\n async checkIPAddress(\n params: CheckIPAddressParams,\n ): Promise<CheckIPAddressResult> {\n // Check if we already have the result in cache\n const cachedResult = this.cache[params.ipAddress];\n if (cachedResult) {\n // Return the cached result if available\n return {\n isVpn: cachedResult.privacy.vpn,\n };\n }\n\n // If the result is not in cache, make a request to ipinfo\n const url = `https://ipinfo.io/${params.ipAddress}?token=${this.ipInfoApiKey}`;\n const response = await axios.get<IpInfo>(url);\n const ipInfo = response.data;\n\n // Store the result in cache before returning\n this.cache[params.ipAddress] = ipInfo;\n\n return {\n isVpn: ipInfo.privacy.vpn,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/geofencing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA;IAIE,0BAAY,YAAoB;QAFxB,UAAK,GAAgB,EAAE,CAAC,CAAC,oCAAoC;QAGnE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAEK,yCAAc,GAApB,UACE,MAA4B;;;;;;wBAGtB,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;wBAClD,IAAI,YAAY,EAAE,CAAC;4BACjB,wCAAwC;4BACxC,sBAAO;oCACL,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG;iCAChC,EAAC;wBACJ,CAAC;wBAGK,GAAG,GAAG,4BAAqB,MAAM,CAAC,SAAS,oBAAU,IAAI,CAAC,YAAY,CAAE,CAAC;;;;wBAG5D,qBAAM,KAAK,CAAC,GAAG,EAAE;gCAChC,MAAM,EAAE,KAAK;gCACb,OAAO,EAAE;oCACP,MAAM,EAAE,kBAAkB;iCAC3B;6BACF,CAAC,EAAA;;wBALI,QAAQ,GAAG,SAKf;wBAEF,sCAAsC;wBACtC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;4BACjB,MAAM,IAAI,KAAK,CAAC,kCAA2B,QAAQ,CAAC,UAAU,CAAE,CAAC,CAAC;wBACpE,CAAC;wBAGe,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA/B,MAAM,GAAG,CAAC,SAAqB,CAAW;wBAEhD,sCAAsC;wBACtC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;wBAEtC,sBAAO;gCACL,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG;6BAC1B,EAAC;;;wBAEF,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,OAAK,CAAC,CAAC;wBACjD,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;;;;;KAEjD;IACH,uBAAC;AAAD,CAAC,AAlDD,IAkDC","sourcesContent":["import { IpInfo } from '@reyaxyz/common';\nimport { CheckIPAddressParams, CheckIPAddressResult } from './types';\n\n// Define a cache interface\ninterface IpInfoCache {\n [key: string]: IpInfo;\n}\n\nexport default class GeofencingClient {\n readonly ipInfoApiKey: string;\n private cache: IpInfoCache = {}; // Cache for storing IP info results\n\n constructor(ipInfoApiKey: string) {\n this.ipInfoApiKey = ipInfoApiKey;\n }\n\n async checkIPAddress(\n params: CheckIPAddressParams,\n ): Promise<CheckIPAddressResult> {\n // Check if we already have the result in cache\n const cachedResult = this.cache[params.ipAddress];\n if (cachedResult) {\n // Return the cached result if available\n return {\n isVpn: cachedResult.privacy.vpn,\n };\n }\n\n // If the result is not in cache, make a request to ipinfo\n const url = `https://ipinfo.io/${params.ipAddress}?token=${this.ipInfoApiKey}`;\n\n try {\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n });\n\n // Check if the response is successful\n if (!response.ok) {\n throw new Error(`Error fetching IP info: ${response.statusText}`);\n }\n\n // Use type assertion here\n const ipInfo = (await response.json()) as IpInfo;\n\n // Proceed with the rest of your logic\n this.cache[params.ipAddress] = ipInfo;\n\n return {\n isVpn: ipInfo.privacy.vpn,\n };\n } catch (error) {\n console.error('Failed to fetch IP info:', error);\n throw new Error('Failed to check IP address');\n }\n }\n}\n"]}
@@ -11,7 +11,7 @@ var geofencing_1 = __importDefault(require("./modules/geofencing"));
11
11
  */
12
12
  var RiskClient = /** @class */ (function () {
13
13
  function RiskClient() {
14
- this._geofencingClient = new geofencing_1.default(RiskClient.ipInfoApiKey, RiskClient.config.apiEndpoint);
14
+ this._geofencingClient = new geofencing_1.default(RiskClient.ipInfoApiKey);
15
15
  }
16
16
  RiskClient.configure = function (environment, ipInfoApiKey) {
17
17
  RiskClient.config =
@@ -1 +1 @@
1
- {"version":3,"file":"risk-client.js","sourceRoot":"/","sources":["clients/risk-client.ts"],"names":[],"mappings":";;;;;;AAAA,0CAIyB;AACzB,oEAAoD;AACpD;;GAEG;AACH;IAME;QACE,IAAI,CAAC,iBAAiB,GAAG,IAAI,oBAAgB,CAC3C,UAAU,CAAC,YAAY,EACvB,UAAU,CAAC,MAAM,CAAC,WAAW,CAC9B,CAAC;IACJ,CAAC;IAEa,oBAAS,GAAvB,UACE,WAAyC,EACzC,YAAoB;QAEpB,UAAU,CAAC,MAAM;YACf,2BAAkB,CAAC,WAAW,CAAC,IAAI,2BAAkB,CAAC,MAAM,CAAC,CAAC;QAChE,UAAU,CAAC,YAAY,GAAG,YAAY,CAAC;QACvC,UAAU,CAAC,QAAQ,GAAG,IAAI,UAAU,EAAE,CAAC;IACzC,CAAC;IAEc,sBAAW,GAA1B;QACE,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;QACJ,CAAC;QACD,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,sBAAkB,qBAAO;aAAzB;YACE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC;QACjC,CAAC;;;OAAA;IASD,sBAAkB,wBAAU;QAP5B;;;;;;WAMG;aACH;YACE,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAC;QACpD,CAAC;;;OAAA;IA9Cc,iBAAM,GAAkB,2BAAkB,CAAC,MAAM,CAAC,CAAC;IA+CpE,iBAAC;CAAA,AAjDD,IAiDC;AAjDY,gCAAU","sourcesContent":["import {\n ReyaChainId,\n API_CLIENT_CONFIGS,\n ServiceConfig,\n} from '@reyaxyz/common';\nimport GeofencingClient from './modules/geofencing';\n/**\n * @description Client for Risk\n */\nexport class RiskClient {\n private static instance: RiskClient;\n private static config: ServiceConfig = API_CLIENT_CONFIGS['test'];\n private static ipInfoApiKey: string;\n private readonly _geofencingClient: GeofencingClient;\n\n private constructor() {\n this._geofencingClient = new GeofencingClient(\n RiskClient.ipInfoApiKey,\n RiskClient.config.apiEndpoint,\n );\n }\n\n public static configure(\n environment: ServiceConfig['environment'],\n ipInfoApiKey: string,\n ): void {\n RiskClient.config =\n API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];\n RiskClient.ipInfoApiKey = ipInfoApiKey;\n RiskClient.instance = new RiskClient();\n }\n\n private static getInstance(): RiskClient {\n if (!RiskClient.instance) {\n throw new Error(\n 'RiskClient is not configured. Please configure it before using.',\n );\n }\n return RiskClient.instance;\n }\n\n public static get network(): ReyaChainId {\n if (!RiskClient.config.chain) {\n throw new Error('RiskClient is not configured');\n }\n return RiskClient.config.chain;\n }\n\n /**\n * Provides access to the GeofencingClient instance.\n * This getter allows for interacting with GeofencingClient related API functionalities.\n *\n * @returns {GeofencingClient} An instance of GeofencingClient for account-related operations.\n * @memberof RiskClient\n */\n public static get geofencing(): GeofencingClient {\n return RiskClient.getInstance()._geofencingClient;\n }\n}\n"]}
1
+ {"version":3,"file":"risk-client.js","sourceRoot":"/","sources":["clients/risk-client.ts"],"names":[],"mappings":";;;;;;AAAA,0CAIyB;AACzB,oEAAoD;AACpD;;GAEG;AACH;IAME;QACE,IAAI,CAAC,iBAAiB,GAAG,IAAI,oBAAgB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACzE,CAAC;IAEa,oBAAS,GAAvB,UACE,WAAyC,EACzC,YAAoB;QAEpB,UAAU,CAAC,MAAM;YACf,2BAAkB,CAAC,WAAW,CAAC,IAAI,2BAAkB,CAAC,MAAM,CAAC,CAAC;QAChE,UAAU,CAAC,YAAY,GAAG,YAAY,CAAC;QACvC,UAAU,CAAC,QAAQ,GAAG,IAAI,UAAU,EAAE,CAAC;IACzC,CAAC;IAEc,sBAAW,GAA1B;QACE,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;QACJ,CAAC;QACD,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,sBAAkB,qBAAO;aAAzB;YACE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC;QACjC,CAAC;;;OAAA;IASD,sBAAkB,wBAAU;QAP5B;;;;;;WAMG;aACH;YACE,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAC;QACpD,CAAC;;;OAAA;IA3Cc,iBAAM,GAAkB,2BAAkB,CAAC,MAAM,CAAC,CAAC;IA4CpE,iBAAC;CAAA,AA9CD,IA8CC;AA9CY,gCAAU","sourcesContent":["import {\n ReyaChainId,\n API_CLIENT_CONFIGS,\n ServiceConfig,\n} from '@reyaxyz/common';\nimport GeofencingClient from './modules/geofencing';\n/**\n * @description Client for Risk\n */\nexport class RiskClient {\n private static instance: RiskClient;\n private static config: ServiceConfig = API_CLIENT_CONFIGS['test'];\n private static ipInfoApiKey: string;\n private readonly _geofencingClient: GeofencingClient;\n\n private constructor() {\n this._geofencingClient = new GeofencingClient(RiskClient.ipInfoApiKey);\n }\n\n public static configure(\n environment: ServiceConfig['environment'],\n ipInfoApiKey: string,\n ): void {\n RiskClient.config =\n API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];\n RiskClient.ipInfoApiKey = ipInfoApiKey;\n RiskClient.instance = new RiskClient();\n }\n\n private static getInstance(): RiskClient {\n if (!RiskClient.instance) {\n throw new Error(\n 'RiskClient is not configured. Please configure it before using.',\n );\n }\n return RiskClient.instance;\n }\n\n public static get network(): ReyaChainId {\n if (!RiskClient.config.chain) {\n throw new Error('RiskClient is not configured');\n }\n return RiskClient.config.chain;\n }\n\n /**\n * Provides access to the GeofencingClient instance.\n * This getter allows for interacting with GeofencingClient related API functionalities.\n *\n * @returns {GeofencingClient} An instance of GeofencingClient for account-related operations.\n * @memberof RiskClient\n */\n public static get geofencing(): GeofencingClient {\n return RiskClient.getInstance()._geofencingClient;\n }\n}\n"]}
@@ -1,9 +1,8 @@
1
- import { RestClient } from '@reyaxyz/common';
2
1
  import { CheckIPAddressParams, CheckIPAddressResult } from './types';
3
- export default class GeofencingClient extends RestClient {
2
+ export default class GeofencingClient {
4
3
  readonly ipInfoApiKey: string;
5
4
  private cache;
6
- constructor(ipInfoApiKey: string, host: string, apiTimeout?: number | null);
5
+ constructor(ipInfoApiKey: string);
7
6
  checkIPAddress(params: CheckIPAddressParams): Promise<CheckIPAddressResult>;
8
7
  }
9
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/geofencing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAU,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAQrE,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU;IACtD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,KAAK,CAAmB;gBAEpB,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAKpE,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;CAsBjC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/geofencing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAOrE,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,KAAK,CAAmB;gBAEpB,YAAY,EAAE,MAAM;IAI1B,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;CAwCjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"risk-client.d.ts","sourceRoot":"/","sources":["clients/risk-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAEX,aAAa,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,gBAAgB,MAAM,sBAAsB,CAAC;AACpD;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAa;IACpC,OAAO,CAAC,MAAM,CAAC,MAAM,CAA6C;IAClE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD,OAAO;WAOO,SAAS,CACrB,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,EACzC,YAAY,EAAE,MAAM,GACnB,IAAI;IAOP,OAAO,CAAC,MAAM,CAAC,WAAW;IAS1B,WAAkB,OAAO,IAAI,WAAW,CAKvC;IAED;;;;;;OAMG;IACH,WAAkB,UAAU,IAAI,gBAAgB,CAE/C;CACF"}
1
+ {"version":3,"file":"risk-client.d.ts","sourceRoot":"/","sources":["clients/risk-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAEX,aAAa,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,gBAAgB,MAAM,sBAAsB,CAAC;AACpD;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAa;IACpC,OAAO,CAAC,MAAM,CAAC,MAAM,CAA6C;IAClE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD,OAAO;WAIO,SAAS,CACrB,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,EACzC,YAAY,EAAE,MAAM,GACnB,IAAI;IAOP,OAAO,CAAC,MAAM,CAAC,WAAW;IAS1B,WAAkB,OAAO,IAAI,WAAW,CAKvC;IAED;;;;;;OAMG;IACH,WAAkB,UAAU,IAAI,gBAAgB,CAE/C;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/risk-sdk",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -33,9 +33,8 @@
33
33
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
34
34
  },
35
35
  "dependencies": {
36
- "@reyaxyz/common": "0.65.0",
37
- "axios": "^1.6.2"
36
+ "@reyaxyz/common": "0.66.0"
38
37
  },
39
38
  "packageManager": "pnpm@8.10.4",
40
- "gitHead": "2f5dd7c59e9a3f247acd87aa80ebb30a97e06791"
39
+ "gitHead": "39f5be036cd878a960d47576497d6672bddf113c"
41
40
  }
@@ -1,18 +1,16 @@
1
- import { RestClient, IpInfo } from '@reyaxyz/common';
1
+ import { IpInfo } from '@reyaxyz/common';
2
2
  import { CheckIPAddressParams, CheckIPAddressResult } from './types';
3
- import axios from 'axios';
4
3
 
5
4
  // Define a cache interface
6
5
  interface IpInfoCache {
7
6
  [key: string]: IpInfo;
8
7
  }
9
8
 
10
- export default class GeofencingClient extends RestClient {
9
+ export default class GeofencingClient {
11
10
  readonly ipInfoApiKey: string;
12
11
  private cache: IpInfoCache = {}; // Cache for storing IP info results
13
12
 
14
- constructor(ipInfoApiKey: string, host: string, apiTimeout?: number | null) {
15
- super(host, apiTimeout);
13
+ constructor(ipInfoApiKey: string) {
16
14
  this.ipInfoApiKey = ipInfoApiKey;
17
15
  }
18
16
 
@@ -30,14 +28,32 @@ export default class GeofencingClient extends RestClient {
30
28
 
31
29
  // If the result is not in cache, make a request to ipinfo
32
30
  const url = `https://ipinfo.io/${params.ipAddress}?token=${this.ipInfoApiKey}`;
33
- const response = await axios.get<IpInfo>(url);
34
- const ipInfo = response.data;
35
31
 
36
- // Store the result in cache before returning
37
- this.cache[params.ipAddress] = ipInfo;
32
+ try {
33
+ const response = await fetch(url, {
34
+ method: 'GET',
35
+ headers: {
36
+ Accept: 'application/json',
37
+ },
38
+ });
38
39
 
39
- return {
40
- isVpn: ipInfo.privacy.vpn,
41
- };
40
+ // Check if the response is successful
41
+ if (!response.ok) {
42
+ throw new Error(`Error fetching IP info: ${response.statusText}`);
43
+ }
44
+
45
+ // Use type assertion here
46
+ const ipInfo = (await response.json()) as IpInfo;
47
+
48
+ // Proceed with the rest of your logic
49
+ this.cache[params.ipAddress] = ipInfo;
50
+
51
+ return {
52
+ isVpn: ipInfo.privacy.vpn,
53
+ };
54
+ } catch (error) {
55
+ console.error('Failed to fetch IP info:', error);
56
+ throw new Error('Failed to check IP address');
57
+ }
42
58
  }
43
59
  }
@@ -14,10 +14,7 @@ export class RiskClient {
14
14
  private readonly _geofencingClient: GeofencingClient;
15
15
 
16
16
  private constructor() {
17
- this._geofencingClient = new GeofencingClient(
18
- RiskClient.ipInfoApiKey,
19
- RiskClient.config.apiEndpoint,
20
- );
17
+ this._geofencingClient = new GeofencingClient(RiskClient.ipInfoApiKey);
21
18
  }
22
19
 
23
20
  public static configure(