@riocrypto/common-server 1.0.1759 → 1.0.1761

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,4 +1,4 @@
1
- import { Crypto } from "@riocrypto/common";
1
+ import { Crypto, User } from "@riocrypto/common";
2
2
  declare class CoincoverClient {
3
3
  private apiKey;
4
4
  private baseUrl;
@@ -15,6 +15,11 @@ declare class CoincoverClient {
15
15
  blocklistedAddress?: string;
16
16
  };
17
17
  }>;
18
+ registerIndividualUser(user: User): Promise<void>;
19
+ registerBusinessUser(user: User, contactPersonName: string, contactPersonEmail: string): Promise<void>;
20
+ private formatDate;
21
+ private formatAddress;
22
+ private getResidenceCountry;
18
23
  }
19
24
  export declare const buildCoincoverClient: () => Promise<CoincoverClient>;
20
25
  export {};
@@ -19,6 +19,21 @@ const common_1 = require("@riocrypto/common");
19
19
  class CoincoverClient {
20
20
  constructor(apiKey) {
21
21
  this.apiKey = apiKey;
22
+ this.formatDate = (date) => {
23
+ const year = date.getFullYear();
24
+ const month = (date.getMonth() + 1).toString().padStart(2, "0"); // Months are 0-indexed, so add 1
25
+ const day = date.getDate().toString().padStart(2, "0");
26
+ return `${year}-${month}-${day}`;
27
+ };
28
+ this.formatAddress = (street1, city, state, postalCode, country, street2) => {
29
+ const address = `${street1}${street2 ? ", " + street2 : ""}, ${city}, ${state} ${postalCode}, ${country}`;
30
+ return address;
31
+ };
32
+ this.getResidenceCountry = (user) => {
33
+ var _a, _b;
34
+ const highestOnboardingCountry = (0, common_1.getHighestOnboardingStatus)(user).country;
35
+ return (_b = (_a = user.onboarding[highestOnboardingCountry]) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.country;
36
+ };
22
37
  if ([common_1.RioEnv.Development, common_1.RioEnv.Production, common_1.RioEnv.Staging].includes(process.env.RIO_ENV)) {
23
38
  this.baseUrl = "https://api.txm.coincover.com";
24
39
  }
@@ -60,6 +75,43 @@ class CoincoverClient {
60
75
  return data;
61
76
  });
62
77
  }
78
+ registerIndividualUser(user) {
79
+ var _a, _b, _c;
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const { data } = yield axios_with_logging_1.default.post(`${this.baseUrl}/user`, {
82
+ userId: user.id,
83
+ firstName: (_a = user.individualData) === null || _a === void 0 ? void 0 : _a.firstName,
84
+ lastName: (_b = user.individualData) === null || _b === void 0 ? void 0 : _b.lastName,
85
+ dob: ((_c = user.individualData) === null || _c === void 0 ? void 0 : _c.birthday)
86
+ ? this.formatDate(user.individualData.birthday)
87
+ : undefined,
88
+ residenceCountry: this.getResidenceCountry(user),
89
+ }, {
90
+ headers: {
91
+ Authorization: `Bearer ${this.apiKey}`,
92
+ },
93
+ });
94
+ return data;
95
+ });
96
+ }
97
+ registerBusinessUser(user, contactPersonName, contactPersonEmail) {
98
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const highestOnboardingCountry = (0, common_1.getHighestOnboardingStatus)(user).country;
101
+ const { data } = yield axios_with_logging_1.default.post(`${this.baseUrl}/business`, {
102
+ businessId: user.id,
103
+ name: (_a = user.businessData) === null || _a === void 0 ? void 0 : _a.businessName,
104
+ address: this.formatAddress((_c = (_b = user.onboarding[highestOnboardingCountry]) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c.street1, (_e = (_d = user.onboarding[highestOnboardingCountry]) === null || _d === void 0 ? void 0 : _d.address) === null || _e === void 0 ? void 0 : _e.city, (_g = (_f = user.onboarding[highestOnboardingCountry]) === null || _f === void 0 ? void 0 : _f.address) === null || _g === void 0 ? void 0 : _g.state, (_j = (_h = user.onboarding[highestOnboardingCountry]) === null || _h === void 0 ? void 0 : _h.address) === null || _j === void 0 ? void 0 : _j.postalCode, (_l = (_k = user.onboarding[highestOnboardingCountry]) === null || _k === void 0 ? void 0 : _k.address) === null || _l === void 0 ? void 0 : _l.country, (_o = (_m = user.onboarding[highestOnboardingCountry]) === null || _m === void 0 ? void 0 : _m.address) === null || _o === void 0 ? void 0 : _o.street2),
105
+ contactPersonName,
106
+ contactPersonEmail,
107
+ }, {
108
+ headers: {
109
+ Authorization: `Bearer ${this.apiKey}`,
110
+ },
111
+ });
112
+ return data;
113
+ });
114
+ }
63
115
  }
64
116
  const buildCoincoverClient = () => __awaiter(void 0, void 0, void 0, function* () {
65
117
  // Retrieve secrets asynchronously
@@ -11,6 +11,7 @@ const sanitizeUserDoc = (doc) => {
11
11
  delete obj.risk;
12
12
  delete obj.quotationTime;
13
13
  delete obj.rioBankAccount;
14
+ delete obj.registeredWithCoincover;
14
15
  return obj;
15
16
  };
16
17
  exports.sanitizeUserDoc = sanitizeUserDoc;
@@ -3,6 +3,7 @@ import { Mongoose, Model, Document } from "mongoose";
3
3
  interface UserAttrs {
4
4
  createdAt: Date;
5
5
  authIds?: string[];
6
+ registeredWithCoincover?: boolean;
6
7
  individualData?: {
7
8
  firstName: string;
8
9
  middleName?: string;
@@ -114,6 +115,7 @@ interface UserDoc extends Document {
114
115
  _id: string;
115
116
  createdAt: Date;
116
117
  authIds?: string[];
118
+ registeredWithCoincover?: boolean;
117
119
  individualData?: {
118
120
  firstName: string;
119
121
  middleName?: string;
@@ -20,6 +20,9 @@ const buildUser = (mongoose) => {
20
20
  type: String,
21
21
  required: true,
22
22
  },
23
+ registeredWithCoincover: {
24
+ type: Boolean,
25
+ },
23
26
  phoneNumber: {
24
27
  type: String,
25
28
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1759",
3
+ "version": "1.0.1761",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "@google-cloud/secret-manager": "^5.3.0",
27
27
  "@google-cloud/storage": "^6.9.5",
28
28
  "@hyperdx/node-opentelemetry": "^0.4.2",
29
- "@riocrypto/common": "^1.0.1549",
29
+ "@riocrypto/common": "^1.0.1550",
30
30
  "@types/express": "^4.17.13",
31
31
  "axios": "^1.6.0",
32
32
  "crypto-js": "^4.2.0",