@riocrypto/common 1.0.2150 → 1.0.2151

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 { PayoutAdvanceTransactionType } from "../types/payout-advance-transaction";
1
+ import { PayoutAdvanceTransactionType } from "../types/payout-advance-transaction-type";
2
2
  import { Subjects } from "./subjects";
3
3
  import { Fiat } from "../types/fiat";
4
4
  import { Crypto } from "../types/crypto";
@@ -0,0 +1,2 @@
1
+ import { Country } from "../types/country";
2
+ export declare const getCountryTimezone: (country: Country) => string;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCountryTimezone = void 0;
4
+ const country_1 = require("../types/country");
5
+ const getCountryTimezone = (country) => {
6
+ switch (country) {
7
+ case country_1.Country.Mexico:
8
+ return "America/Mexico_City";
9
+ case country_1.Country.Peru:
10
+ return "America/Lima";
11
+ case country_1.Country.UnitedStates:
12
+ return "America/New_York";
13
+ default:
14
+ throw new Error(`Unsupported country: ${country}`);
15
+ }
16
+ };
17
+ exports.getCountryTimezone = getCountryTimezone;
@@ -0,0 +1,10 @@
1
+ import { Country } from "../types/country";
2
+ import { DeferredPaymentType } from "../types/deferred-payment-type";
3
+ export declare const getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate: ({ country, holidays, twoWaySettlementDate, deferredPaymentType, }: {
4
+ country: Country;
5
+ holidays: {
6
+ dates: string[];
7
+ };
8
+ twoWaySettlementDate: Date;
9
+ deferredPaymentType: DeferredPaymentType;
10
+ }) => number;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate = void 0;
4
+ const deferred_payment_type_1 = require("../types/deferred-payment-type");
5
+ const get_country_timezone_1 = require("./get-country-timezone");
6
+ const formatDateInTimezone = (date, timezone) => {
7
+ // Format the date in the specified timezone as YYYY-MM-DD
8
+ const dateInTimezone = new Date(date.toLocaleString("en-US", { timeZone: timezone }));
9
+ const year = dateInTimezone.getFullYear();
10
+ const month = String(dateInTimezone.getMonth() + 1).padStart(2, "0");
11
+ const day = String(dateInTimezone.getDate()).padStart(2, "0");
12
+ return `${year}-${month}-${day}`;
13
+ };
14
+ const getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate = ({ country, holidays, twoWaySettlementDate, deferredPaymentType, }) => {
15
+ if (deferredPaymentType !== deferred_payment_type_1.DeferredPaymentType.OneDayAfter) {
16
+ return 0;
17
+ }
18
+ const timezone = (0, get_country_timezone_1.getCountryTimezone)(country);
19
+ // Convert the two way settlement date to the country's timezone
20
+ const settlementDateInCountryTZ = new Date(twoWaySettlementDate.toLocaleString("en-US", { timeZone: timezone }));
21
+ // Find the next business day after the settlement date
22
+ const nextBusinessDay = new Date(settlementDateInCountryTZ);
23
+ nextBusinessDay.setDate(settlementDateInCountryTZ.getDate() + 1);
24
+ while (true) {
25
+ const isWeekend = nextBusinessDay.getDay() === 0 || nextBusinessDay.getDay() === 6;
26
+ const isHoliday = holidays.dates.includes(formatDateInTimezone(nextBusinessDay, timezone));
27
+ if (!isWeekend && !isHoliday) {
28
+ break; // Found the next business day
29
+ }
30
+ nextBusinessDay.setDate(nextBusinessDay.getDate() + 1);
31
+ }
32
+ // Calculate the calendar days difference between settlement date and next business day
33
+ const timeDifference = nextBusinessDay.getTime() - settlementDateInCountryTZ.getTime();
34
+ const daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));
35
+ return daysDifference;
36
+ };
37
+ exports.getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate = getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate;
@@ -0,0 +1,8 @@
1
+ import { Country } from "../types/country";
2
+ export declare const getDaysUntilTwoWaySettlementDate: ({ country, holidays, twoWaySettlementDateOffset, }: {
3
+ country: Country;
4
+ holidays: {
5
+ dates: string[];
6
+ };
7
+ twoWaySettlementDateOffset: number;
8
+ }) => number;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDaysUntilTwoWaySettlementDate = void 0;
4
+ const get_country_timezone_1 = require("./get-country-timezone");
5
+ const should_add_one_day_to_settlement_date_1 = require("./should-add-one-day-to-settlement-date");
6
+ const formatDateInTimezone = (date, timezone) => {
7
+ // Format the date in the specified timezone as YYYY-MM-DD
8
+ const dateInTimezone = new Date(date.toLocaleString("en-US", { timeZone: timezone }));
9
+ const year = dateInTimezone.getFullYear();
10
+ const month = String(dateInTimezone.getMonth() + 1).padStart(2, "0");
11
+ const day = String(dateInTimezone.getDate()).padStart(2, "0");
12
+ return `${year}-${month}-${day}`;
13
+ };
14
+ const getDaysUntilTwoWaySettlementDate = ({ country, holidays, twoWaySettlementDateOffset, }) => {
15
+ let businessDaysToAdd = twoWaySettlementDateOffset;
16
+ // If in Asia time, add 1 day to the offset
17
+ const isAsiaTime = (0, should_add_one_day_to_settlement_date_1.shouldAddOneDayToSettlementDate)();
18
+ if (isAsiaTime) {
19
+ businessDaysToAdd += 1;
20
+ }
21
+ const timezone = (0, get_country_timezone_1.getCountryTimezone)(country);
22
+ // Get today's date in the country's timezone
23
+ const today = new Date();
24
+ const todayInCountryTZ = new Date(today.toLocaleString("en-US", { timeZone: timezone }));
25
+ // Calculate settlement date from today in country's timezone
26
+ const settlementDate = new Date(todayInCountryTZ);
27
+ if (businessDaysToAdd === 0) {
28
+ // Find today if it's a business day, otherwise the next business day
29
+ while (true) {
30
+ const isWeekend = settlementDate.getDay() === 0 || settlementDate.getDay() === 6;
31
+ const isHoliday = holidays.dates.includes(formatDateInTimezone(settlementDate, timezone));
32
+ if (!isWeekend && !isHoliday) {
33
+ break; // Found the business day
34
+ }
35
+ settlementDate.setDate(settlementDate.getDate() + 1);
36
+ }
37
+ }
38
+ else {
39
+ // Add the specified number of business days from today
40
+ let businessDaysAdded = 0;
41
+ while (businessDaysAdded < businessDaysToAdd) {
42
+ settlementDate.setDate(settlementDate.getDate() + 1);
43
+ const isWeekend = settlementDate.getDay() === 0 || settlementDate.getDay() === 6;
44
+ const isHoliday = holidays.dates.includes(formatDateInTimezone(settlementDate, timezone));
45
+ if (!isWeekend && !isHoliday) {
46
+ businessDaysAdded++;
47
+ }
48
+ }
49
+ }
50
+ // Calculate the calendar days difference between today and settlement date
51
+ // Both dates are in the country's timezone
52
+ const timeDifference = settlementDate.getTime() - todayInCountryTZ.getTime();
53
+ const daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));
54
+ return daysDifference;
55
+ };
56
+ exports.getDaysUntilTwoWaySettlementDate = getDaysUntilTwoWaySettlementDate;
@@ -0,0 +1,5 @@
1
+ import { Country } from "../types/country";
2
+ export declare const getTwoWaySettlementDate: ({ country, daysUntilSettlementDate, }: {
3
+ country: Country;
4
+ daysUntilSettlementDate: number;
5
+ }) => Date;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTwoWaySettlementDate = void 0;
4
+ const get_country_timezone_1 = require("./get-country-timezone");
5
+ const getTwoWaySettlementDate = ({ country, daysUntilSettlementDate, }) => {
6
+ const timezone = (0, get_country_timezone_1.getCountryTimezone)(country);
7
+ // Get today's date in the country's timezone
8
+ const today = new Date();
9
+ const todayInCountryTZ = new Date(today.toLocaleString("en-US", { timeZone: timezone }));
10
+ // Add the specified number of days
11
+ const settlementDate = new Date(todayInCountryTZ);
12
+ settlementDate.setDate(todayInCountryTZ.getDate() + daysUntilSettlementDate);
13
+ return settlementDate;
14
+ };
15
+ exports.getTwoWaySettlementDate = getTwoWaySettlementDate;
@@ -7,6 +7,11 @@ const shouldAddOneDayToSettlementDate = () => {
7
7
  timeZone: "America/Mexico_City",
8
8
  });
9
9
  const now = new Date(mexicoCityTime);
10
+ // Return false if it's Saturday or Sunday
11
+ const dayOfWeek = now.getDay(); // 0 = Sunday, 1 = Monday, ..., 6 = Saturday
12
+ if (dayOfWeek === 0 || dayOfWeek === 6) {
13
+ return false;
14
+ }
10
15
  const currentHour = now.getHours();
11
16
  const currentMinute = now.getMinutes();
12
17
  // Check if between 2:55PM (14:55) and 12:00AM (00:00)
package/build/index.d.ts CHANGED
@@ -334,8 +334,8 @@ export * from "./types/arbitrage-provider-status";
334
334
  export * from "./types/arbitrage-trade";
335
335
  export * from "./types/arbitrage-trade-status";
336
336
  export * from "./types/arbitrage-trade-type";
337
- export * from "./types/pre-settlement-transaction";
338
337
  export * from "./types/payout-advance-transaction";
338
+ export * from "./types/payout-advance-transaction-type";
339
339
  export * from "./types/currency-with-country";
340
340
  export * from "./types/CEP";
341
341
  export * from "./types/CEP-status";
@@ -399,5 +399,9 @@ export * from "./helpers/is-bitso-bank-account";
399
399
  export * from "./helpers/is-overnight-or-weekend-mexico-city";
400
400
  export * from "./helpers/get-user-payout-vault-id";
401
401
  export * from "./helpers/should-add-one-day-to-settlement-date";
402
+ export * from "./helpers/get-country-timezone";
403
+ export * from "./helpers/get-days-between-agreed-two-way-settlement-date-and-payment-date";
404
+ export * from "./helpers/get-days-until-two-way-settlement-date";
405
+ export * from "./helpers/get-two-way-settlement-date";
402
406
  export * from "./constants/mexico-fiscal-regimens";
403
407
  export * from "./constants/mexican-banks";
package/build/index.js CHANGED
@@ -350,8 +350,8 @@ __exportStar(require("./types/arbitrage-provider-status"), exports);
350
350
  __exportStar(require("./types/arbitrage-trade"), exports);
351
351
  __exportStar(require("./types/arbitrage-trade-status"), exports);
352
352
  __exportStar(require("./types/arbitrage-trade-type"), exports);
353
- __exportStar(require("./types/pre-settlement-transaction"), exports);
354
353
  __exportStar(require("./types/payout-advance-transaction"), exports);
354
+ __exportStar(require("./types/payout-advance-transaction-type"), exports);
355
355
  __exportStar(require("./types/currency-with-country"), exports);
356
356
  __exportStar(require("./types/CEP"), exports);
357
357
  __exportStar(require("./types/CEP-status"), exports);
@@ -415,5 +415,9 @@ __exportStar(require("./helpers/is-bitso-bank-account"), exports);
415
415
  __exportStar(require("./helpers/is-overnight-or-weekend-mexico-city"), exports);
416
416
  __exportStar(require("./helpers/get-user-payout-vault-id"), exports);
417
417
  __exportStar(require("./helpers/should-add-one-day-to-settlement-date"), exports);
418
+ __exportStar(require("./helpers/get-country-timezone"), exports);
419
+ __exportStar(require("./helpers/get-days-between-agreed-two-way-settlement-date-and-payment-date"), exports);
420
+ __exportStar(require("./helpers/get-days-until-two-way-settlement-date"), exports);
421
+ __exportStar(require("./helpers/get-two-way-settlement-date"), exports);
418
422
  __exportStar(require("./constants/mexico-fiscal-regimens"), exports);
419
423
  __exportStar(require("./constants/mexican-banks"), exports);
@@ -0,0 +1,4 @@
1
+ export declare enum PayoutAdvanceTransactionType {
2
+ Credit = "credit",
3
+ Debit = "debit"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PayoutAdvanceTransactionType = void 0;
4
+ var PayoutAdvanceTransactionType;
5
+ (function (PayoutAdvanceTransactionType) {
6
+ PayoutAdvanceTransactionType["Credit"] = "credit";
7
+ PayoutAdvanceTransactionType["Debit"] = "debit";
8
+ })(PayoutAdvanceTransactionType = exports.PayoutAdvanceTransactionType || (exports.PayoutAdvanceTransactionType = {}));
@@ -1,4 +1,21 @@
1
- export declare enum PayoutAdvanceTransactionType {
2
- Credit = "credit",
3
- Debit = "debit"
1
+ import { PayoutAdvanceTransactionType } from "./payout-advance-transaction-type";
2
+ import { Fiat } from "./fiat";
3
+ import { Crypto } from "./crypto";
4
+ export interface PayoutAdvanceTransaction {
5
+ id: string;
6
+ createdAt: Date;
7
+ userId: string;
8
+ bankAccountId?: string;
9
+ cryptoAddressId?: string;
10
+ type: PayoutAdvanceTransactionType;
11
+ amount: number;
12
+ currency: Fiat | Crypto;
13
+ orderId?: string;
14
+ SPEITrackingNumber?: string;
15
+ SPIDTrackingNumber?: string;
16
+ blockchainTxId?: string;
17
+ oppositeTransactionAmount?: number;
18
+ oppositeTransactions?: string[];
19
+ reference?: string;
20
+ CEPLink?: string;
4
21
  }
@@ -1,8 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PayoutAdvanceTransactionType = void 0;
4
- var PayoutAdvanceTransactionType;
5
- (function (PayoutAdvanceTransactionType) {
6
- PayoutAdvanceTransactionType["Credit"] = "credit";
7
- PayoutAdvanceTransactionType["Debit"] = "debit";
8
- })(PayoutAdvanceTransactionType = exports.PayoutAdvanceTransactionType || (exports.PayoutAdvanceTransactionType = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.2150",
3
+ "version": "1.0.2151",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -1,21 +0,0 @@
1
- import { PayoutAdvanceTransactionType } from "./payout-advance-transaction";
2
- import { Fiat } from "./fiat";
3
- import { Crypto } from "./crypto";
4
- export interface PayoutAdvanceTransaction {
5
- id: string;
6
- createdAt: Date;
7
- userId: string;
8
- bankAccountId?: string;
9
- cryptoAddressId?: string;
10
- type: PayoutAdvanceTransactionType;
11
- amount: number;
12
- currency: Fiat | Crypto;
13
- orderId?: string;
14
- SPEITrackingNumber?: string;
15
- SPIDTrackingNumber?: string;
16
- blockchainTxId?: string;
17
- oppositeTransactionAmount?: number;
18
- oppositeTransactions?: string[];
19
- reference?: string;
20
- CEPLink?: string;
21
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });