@riocrypto/common-server 1.0.1758 → 1.0.1760

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 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getOrderFromReference = void 0;
13
13
  const order_1 = require("../models/order");
14
+ const common_1 = require("@riocrypto/common");
14
15
  const getOrderFromReference = (reference, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
15
16
  // Ensure reference is defined and exactly 6 characters long
16
17
  if (!reference || reference.length !== 6) {
@@ -19,8 +20,9 @@ const getOrderFromReference = (reference, mongoose) => __awaiter(void 0, void 0,
19
20
  // Convert reference to lowercase to ensure case-insensitive comparison
20
21
  const orderIdPart = reference.toLowerCase();
21
22
  const Order = (0, order_1.buildOrder)(mongoose);
22
- // Fetch all orders and filter them by the last 6 characters of their ObjectId
23
- const orders = yield Order.find().exec();
23
+ const orders = yield Order.find({
24
+ status: { $in: [common_1.OrderStatus.AwaitingPayment, common_1.OrderStatus.Processing] },
25
+ });
24
26
  const order = orders.find((order) => order.id.toString().endsWith(orderIdPart));
25
27
  if (!order) {
26
28
  throw new Error("Order not found");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1758",
3
+ "version": "1.0.1760",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",