@riocrypto/common-server 1.0.1229 → 1.0.1231

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.
@@ -0,0 +1,9 @@
1
+ import { RioEnv } from "@riocrypto/common";
2
+ declare class cloudVisionAPIClient {
3
+ private env;
4
+ googleAuth: any;
5
+ constructor(env: RioEnv);
6
+ getDataFromPDF(bucketName: string, fileName: string, outputPrefix: string): Promise<void>;
7
+ }
8
+ export declare const googleVisionAPIClient: cloudVisionAPIClient;
9
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.googleVisionAPIClient = void 0;
13
+ const googleapis_1 = require("googleapis");
14
+ const vision_1 = require("@google-cloud/vision");
15
+ class cloudVisionAPIClient {
16
+ constructor(env) {
17
+ this.env = env;
18
+ this.googleAuth = new googleapis_1.google.auth.GoogleAuth({
19
+ keyFile: "/etc/secrets/cloud-vision/cloud-vision-service-account-key.json",
20
+ });
21
+ }
22
+ getDataFromPDF(bucketName, fileName, outputPrefix) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const client = new vision_1.v1.ImageAnnotatorClient({
25
+ auth: this.googleAuth,
26
+ });
27
+ const gcsSourceUri = `gs://${bucketName}/${fileName}`;
28
+ const gcsDestinationUri = `gs://${bucketName}/${outputPrefix}/`;
29
+ const inputConfig = {
30
+ // Supported mime_types are: 'application/pdf' and 'image/tiff'
31
+ mimeType: "application/pdf",
32
+ gcsSource: {
33
+ uri: gcsSourceUri,
34
+ },
35
+ };
36
+ const outputConfig = {
37
+ gcsDestination: {
38
+ uri: gcsDestinationUri,
39
+ },
40
+ };
41
+ const features = [{ type: "DOCUMENT_TEXT_DETECTION" }];
42
+ const request = {
43
+ requests: [
44
+ {
45
+ inputConfig: inputConfig,
46
+ features: features,
47
+ outputConfig: outputConfig,
48
+ },
49
+ ],
50
+ };
51
+ //@ts-ignore
52
+ const [operation] = yield client.asyncBatchAnnotateFiles(request);
53
+ const [filesResponse] = yield operation.promise();
54
+ const destinationUri = filesResponse.responses[0].outputConfig.gcsDestination.uri;
55
+ console.log("Json saved to: " + destinationUri);
56
+ });
57
+ }
58
+ }
59
+ exports.googleVisionAPIClient = new cloudVisionAPIClient(process.env.RIO_ENV || process.env.NEXT_PUBLIC_RIO_ENV);
@@ -1,8 +1,9 @@
1
1
  import { Quote, Fiat, Crypto, BitsoBankAccount } from "@riocrypto/common";
2
2
  declare class ClusterClient {
3
+ private baseUrl;
3
4
  private clusterApiKey;
4
5
  private axios;
5
- constructor(clusterApiKey: string);
6
+ constructor(baseUrl: string, clusterApiKey: string);
6
7
  getNewQuote(orderId: string, quote: Quote, newAmountFiat?: number, newAmountCrypto?: number): Promise<Quote>;
7
8
  createBitsoBankAccount(userId: string): Promise<BitsoBankAccount>;
8
9
  getBalance(asset: Crypto | Fiat): Promise<number>;
@@ -17,9 +17,21 @@ const common_1 = require("@riocrypto/common");
17
17
  const axios_1 = __importDefault(require("axios"));
18
18
  const secret_manager_client_1 = require("./secret-manager-client");
19
19
  class ClusterClient {
20
- constructor(clusterApiKey) {
20
+ constructor(baseUrl, clusterApiKey) {
21
+ this.baseUrl = baseUrl;
21
22
  this.clusterApiKey = clusterApiKey;
22
- this.axios = axios_1.default.create({});
23
+ this.axios = axios_1.default.create({
24
+ baseURL: baseUrl,
25
+ headers: {
26
+ Host: process.env.RIO_ENV === common_1.RioEnv.Development
27
+ ? "dev.riotransfer.co"
28
+ : process.env.RIO_ENV === common_1.RioEnv.Staging
29
+ ? "staging.riotransfer.co"
30
+ : process.env.RIO_ENV === common_1.RioEnv.Sandbox
31
+ ? "sandbox.riotransfer.co"
32
+ : "www.riotransfer.co",
33
+ },
34
+ });
23
35
  }
24
36
  getNewQuote(orderId, quote, newAmountFiat, newAmountCrypto) {
25
37
  return __awaiter(this, void 0, void 0, function* () {
@@ -43,7 +55,7 @@ class ClusterClient {
43
55
  amountCrypto = undefined;
44
56
  }
45
57
  }
46
- const response = yield this.axios.post(`/api/quotes`, {
58
+ const response = yield this.axios.post(`${this.baseUrl}/api/quotes`, {
47
59
  orderId,
48
60
  userId: quote.userId,
49
61
  side: quote.side,
@@ -65,7 +77,7 @@ class ClusterClient {
65
77
  }
66
78
  createBitsoBankAccount(userId) {
67
79
  return __awaiter(this, void 0, void 0, function* () {
68
- const response = yield this.axios.post(`/api/bank/accounts/bitso`, {
80
+ const response = yield this.axios.post(`${this.baseUrl}/api/bank/accounts/bitso`, {
69
81
  userId,
70
82
  }, {
71
83
  headers: {
@@ -77,7 +89,7 @@ class ClusterClient {
77
89
  }
78
90
  getBalance(asset) {
79
91
  return __awaiter(this, void 0, void 0, function* () {
80
- const rioResponse = yield this.axios.get(`/api/liquidity/${asset}`, {
92
+ const rioResponse = yield this.axios.get(`${this.baseUrl}/api/liquidity/${asset}`, {
81
93
  headers: {
82
94
  "x-cluster-api-key": this.clusterApiKey,
83
95
  },
@@ -92,6 +104,13 @@ const buildClusterClient = () => __awaiter(void 0, void 0, void 0, function* ()
92
104
  if (!CLUSTER_API_KEY) {
93
105
  throw new common_1.SecretManagerError();
94
106
  }
95
- return new ClusterClient(CLUSTER_API_KEY);
107
+ const baseUrl = process.env.RIO_ENV === common_1.RioEnv.Development
108
+ ? "https://dev.riotransfer.co"
109
+ : process.env.RIO_ENV === common_1.RioEnv.Production
110
+ ? "https://www.riotransfer.co"
111
+ : process.env.RIO_ENV === common_1.RioEnv.Staging
112
+ ? "https://staging.riotransfer.co"
113
+ : "https://sandbox.riotransfer.co";
114
+ return new ClusterClient(baseUrl, CLUSTER_API_KEY);
96
115
  });
97
116
  exports.buildClusterClient = buildClusterClient;
package/build/index.d.ts CHANGED
@@ -50,6 +50,7 @@ export * from "./clients/kapstar-client";
50
50
  export * from "./clients/etherscan-client";
51
51
  export * from "./clients/secret-manager-client";
52
52
  export * from "./clients/gcloud-storage-client";
53
+ export * from "./clients/cloud-vision-api-client";
53
54
  export * from "./clients/currency-api-client";
54
55
  export * from "./clients/aiprise-client";
55
56
  export * from "./clients/bridge-client";
package/build/index.js CHANGED
@@ -66,6 +66,7 @@ __exportStar(require("./clients/kapstar-client"), exports);
66
66
  __exportStar(require("./clients/etherscan-client"), exports);
67
67
  __exportStar(require("./clients/secret-manager-client"), exports);
68
68
  __exportStar(require("./clients/gcloud-storage-client"), exports);
69
+ __exportStar(require("./clients/cloud-vision-api-client"), exports);
69
70
  __exportStar(require("./clients/currency-api-client"), exports);
70
71
  __exportStar(require("./clients/aiprise-client"), exports);
71
72
  __exportStar(require("./clients/bridge-client"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1229",
3
+ "version": "1.0.1231",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -26,6 +26,7 @@
26
26
  "@aws-sdk/client-s3": "^3.297.0",
27
27
  "@everapi/currencyapi-js": "^1.0.6",
28
28
  "@google-cloud/storage": "^6.9.5",
29
+ "@google-cloud/vision": "^4.0.2",
29
30
  "@riocrypto/common": "^1.0.1123",
30
31
  "@types/express": "^4.17.13",
31
32
  "axios": "^0.27.2",