@escapenavigator/utils 1.10.106 → 1.10.108

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.
Files changed (53) hide show
  1. package/dist/date-timezone.d.ts +5 -0
  2. package/dist/date-timezone.js +190 -0
  3. package/dist/date.d.ts +53 -0
  4. package/dist/date.js +362 -0
  5. package/dist/date.test.d.ts +1 -0
  6. package/dist/date.test.js +61 -0
  7. package/dist/format-amount/index.js +12 -12
  8. package/dist/get-documents-links.js +1 -2
  9. package/dist/get-email-result-section.js +1 -2
  10. package/dist/get-email-upsales-section.js +1 -2
  11. package/dist/get-full-name.js +1 -1
  12. package/dist/get-handled-error-message.js +1 -1
  13. package/dist/get-order-cancelation-date/index.js +4 -10
  14. package/dist/get-order-cancelation-state/index.js +12 -11
  15. package/dist/get-order-cancelation-state/index.test.js +5 -5
  16. package/dist/get-players-price.js +1 -1
  17. package/dist/get-promocode-discount.js +2 -0
  18. package/dist/get-service-error.js +3 -3
  19. package/dist/get-slot-cancelation-date/index.d.ts +3 -1
  20. package/dist/get-slot-cancelation-date/index.js +11 -14
  21. package/dist/get-slot-cancelation-date/index.test.js +4 -8
  22. package/dist/get-static-color.js +1 -2
  23. package/dist/has-text-outside-tags.js +1 -2
  24. package/dist/index.d.ts +9 -3
  25. package/dist/index.js +9 -3
  26. package/dist/is-axios-error.js +1 -2
  27. package/dist/is-network-error.js +1 -2
  28. package/dist/pick/index.d.ts +2 -0
  29. package/dist/pick/index.js +16 -0
  30. package/dist/pick/index.test.d.ts +1 -0
  31. package/dist/pick/index.test.js +23 -0
  32. package/dist/promocode-error-codes.d.ts +72 -0
  33. package/dist/promocode-error-codes.js +61 -0
  34. package/dist/promocode-nominal-rules.d.ts +29 -0
  35. package/dist/promocode-nominal-rules.js +39 -0
  36. package/dist/promocode-nominal-rules.spec.d.ts +1 -0
  37. package/dist/promocode-nominal-rules.spec.js +74 -0
  38. package/dist/serialize-slot.d.ts +1 -20
  39. package/dist/serialize-slot.js +8 -78
  40. package/dist/transform-text.js +6 -4
  41. package/dist/tz-date.d.ts +1 -1
  42. package/dist/tz-date.js +8 -9
  43. package/dist/utm-touchpoints.d.ts +63 -0
  44. package/dist/utm-touchpoints.js +66 -0
  45. package/dist/utm-touchpoints.spec.d.ts +1 -0
  46. package/dist/utm-touchpoints.spec.js +95 -0
  47. package/dist/validate-by-dto.d.ts +1 -1
  48. package/dist/validate-by-dto.js +2 -3
  49. package/dist/validate-promocode.d.ts +9 -4
  50. package/dist/validate-promocode.js +57 -38
  51. package/dist/validate-promocode.spec.d.ts +1 -0
  52. package/dist/validate-promocode.spec.js +129 -0
  53. package/package.json +4 -25
@@ -7,22 +7,22 @@ const getCurrency = (currency) => {
7
7
  [profile_currency_1.ProfileCurrencyEnum.USD]: '$',
8
8
  [profile_currency_1.ProfileCurrencyEnum.EUR]: '€',
9
9
  [profile_currency_1.ProfileCurrencyEnum.GBP]: '£',
10
- [profile_currency_1.ProfileCurrencyEnum.CHF]: 'CHF',
11
- [profile_currency_1.ProfileCurrencyEnum.SEK]: 'kr',
12
- [profile_currency_1.ProfileCurrencyEnum.DKK]: 'kr',
13
- [profile_currency_1.ProfileCurrencyEnum.CZK]: 'Kč',
14
- [profile_currency_1.ProfileCurrencyEnum.PLN]: 'zł',
15
- [profile_currency_1.ProfileCurrencyEnum.HUF]: 'Ft',
10
+ [profile_currency_1.ProfileCurrencyEnum.CHF]: 'CHF', // Швейцарский франк
11
+ [profile_currency_1.ProfileCurrencyEnum.SEK]: 'kr', // Шведская крона
12
+ [profile_currency_1.ProfileCurrencyEnum.DKK]: 'kr', // Датская крона
13
+ [profile_currency_1.ProfileCurrencyEnum.CZK]: 'Kč', // Чешская крона
14
+ [profile_currency_1.ProfileCurrencyEnum.PLN]: 'zł', // Польский злотый
15
+ [profile_currency_1.ProfileCurrencyEnum.HUF]: 'Ft', // Венгерский форинт
16
16
  [profile_currency_1.ProfileCurrencyEnum.RUB]: '₽',
17
17
  [profile_currency_1.ProfileCurrencyEnum.BGN]: 'лв',
18
18
  [profile_currency_1.ProfileCurrencyEnum.CAD]: 'C$',
19
19
  [profile_currency_1.ProfileCurrencyEnum.AUD]: '$',
20
- [profile_currency_1.ProfileCurrencyEnum.NOK]: 'kr',
21
- [profile_currency_1.ProfileCurrencyEnum.HRK]: 'kn',
22
- [profile_currency_1.ProfileCurrencyEnum.RON]: 'lei',
23
- [profile_currency_1.ProfileCurrencyEnum.RSD]: 'дин',
24
- [profile_currency_1.ProfileCurrencyEnum.ALL]: 'L',
25
- [profile_currency_1.ProfileCurrencyEnum.MKD]: 'ден',
20
+ [profile_currency_1.ProfileCurrencyEnum.NOK]: 'kr', // Норвежская крона
21
+ [profile_currency_1.ProfileCurrencyEnum.HRK]: 'kn', // Хорватская куна (до 2023 года)
22
+ [profile_currency_1.ProfileCurrencyEnum.RON]: 'lei', // Румынский лей
23
+ [profile_currency_1.ProfileCurrencyEnum.RSD]: 'дин', // Сербский динар
24
+ [profile_currency_1.ProfileCurrencyEnum.ALL]: 'L', // Албанский лек
25
+ [profile_currency_1.ProfileCurrencyEnum.MKD]: 'ден', // Македонский денар
26
26
  [profile_currency_1.ProfileCurrencyEnum.BAM]: 'KM',
27
27
  [profile_currency_1.ProfileCurrencyEnum.TRY]: '',
28
28
  [profile_currency_1.ProfileCurrencyEnum.GEL]: '',
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLinks = void 0;
3
+ exports.getLinks = getLinks;
4
4
  const agb_type_enum_1 = require("@escapenavigator/types/dist/agb/agb-type.enum");
5
5
  function getLinks(lang, domain) {
6
6
  return {
@@ -11,4 +11,3 @@ function getLinks(lang, domain) {
11
11
  REGISTRATION_NEW_PROFILE: `${domain}?type=${agb_type_enum_1.AgbTypeEnum.REGISTRATION_NEW_PROFILE}&country=${lang}`,
12
12
  };
13
13
  }
14
- exports.getLinks = getLinks;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEmailResultSection = void 0;
3
+ exports.getEmailResultSection = getEmailResultSection;
4
4
  const photoHtml = (photo) => `<a target="_blank" href="${photo}" style="padding-top: 12px; padding-right: 12px; outline: none; border: none"><img src="${photo}" style="width: 150px;height:150px; object-fit: cover;border-radius: 12px;"></a>`;
5
5
  function getEmailResultSection({ result, resultTitle, noResultTitle, photos, }) {
6
6
  if (!result && !photos.length)
@@ -12,4 +12,3 @@ function getEmailResultSection({ result, resultTitle, noResultTitle, photos, })
12
12
  text: `${photos.map((p) => photoHtml(p)).join('')}`,
13
13
  };
14
14
  }
15
- exports.getEmailResultSection = getEmailResultSection;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEmailUpsalesSection = void 0;
3
+ exports.getEmailUpsalesSection = getEmailUpsalesSection;
4
4
  function getEmailUpsalesSection({ upsales, link, buttonText, }) {
5
5
  return `${upsales.map((u) => `<b>${u.title}<b/> - ${u.description || ''}`).join('<br/>')}
6
6
  <a style="
@@ -26,4 +26,3 @@ function getEmailUpsalesSection({ upsales, link, buttonText, }) {
26
26
  </a>
27
27
  <p>`;
28
28
  }
29
- exports.getEmailUpsalesSection = getEmailUpsalesSection;
@@ -4,7 +4,7 @@ exports.getFullName = void 0;
4
4
  const getFullName = (row) => {
5
5
  if (!row)
6
6
  return 'Deleted';
7
- const { name, patronymic, surname, id, } = row;
7
+ const { name, patronymic, surname, id } = row;
8
8
  if (name || patronymic || surname) {
9
9
  return `${name || ''} ${patronymic || ''} ${surname || ''}`.replace(/\s+/g, ' ').trim();
10
10
  }
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHandledErrorMessage = void 0;
4
- const getHandledErrorMessage = (error) => (error.response ? error.response.data.message : error.message);
4
+ const getHandledErrorMessage = (error) => error.response ? error.response.data.message : error.message;
5
5
  exports.getHandledErrorMessage = getHandledErrorMessage;
@@ -1,19 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getOrderCancelationDate = void 0;
3
+ exports.getOrderCancelationDate = getOrderCancelationDate;
7
4
  const questroom_cancelation_type_enum_1 = require("@escapenavigator/types/dist/questroom/enum/questroom-cancelation-type.enum");
8
- const utcToZonedTime_1 = __importDefault(require("date-fns-tz/utcToZonedTime"));
9
- const addHours_1 = __importDefault(require("date-fns/addHours"));
10
- const format_1 = __importDefault(require("date-fns/format"));
5
+ const date_1 = require("../date");
11
6
  function getOrderCancelationDate({ utcDate, minHoursForFreeCanceling, cancelationRule, timeZone, }) {
12
7
  const minHours = cancelationRule === questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.NO ? 0 : minHoursForFreeCanceling;
13
- const date = (0, addHours_1.default)((0, utcToZonedTime_1.default)(utcDate, timeZone), minHours * -1);
8
+ const date = (0, date_1.addHours)((0, date_1.utcToZonedTime)(utcDate, timeZone), minHours * -1);
14
9
  return {
15
10
  orderCancelationDate: date,
16
- orderCancelationHumantDate: (0, format_1.default)(date, 'dd.MM.yyyy, HH:mm'),
11
+ orderCancelationHumantDate: (0, date_1.formatDate)(date, 'dd.MM.yyyy, HH:mm'),
17
12
  };
18
13
  }
19
- exports.getOrderCancelationDate = getOrderCancelationDate;
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getOrderCancelationState = exports.isCancelationAllowed = exports.FineDescriptions = void 0;
3
+ exports.isCancelationAllowed = exports.FineDescriptions = void 0;
4
+ exports.getOrderCancelationState = getOrderCancelationState;
7
5
  /* eslint-disable complexity */
8
6
  const order_cancel_reson_enum_1 = require("@escapenavigator/types/dist/order/enum/order-cancel-reson.enum");
9
7
  const questroom_cancelation_type_enum_1 = require("@escapenavigator/types/dist/questroom/enum/questroom-cancelation-type.enum");
10
8
  const transaction_type_enum_1 = require("@escapenavigator/types/dist/transaction/enum/transaction-type.enum");
11
- const differenceInHours_1 = __importDefault(require("date-fns/differenceInHours"));
9
+ const date_1 = require("../date");
12
10
  const get_cancelation_fee_amount_1 = require("../get-cancelation-fee-amount");
13
11
  const getReceivedTransactions = (transactions) => transactions.filter((transaction) => transaction.type === transaction_type_enum_1.TransactionTypeEnum.INSIDE ||
14
12
  transaction.type === transaction_type_enum_1.TransactionTypeEnum.PROCESSING ||
@@ -21,8 +19,8 @@ var FineDescriptions;
21
19
  FineDescriptions["HAND_RETURN"] = "descriptionFineWithReturn";
22
20
  FineDescriptions["FINE_PAID"] = "descriptionFinePaid";
23
21
  FineDescriptions["WITH_CHARGE"] = "descriptionFineWithCharge";
24
- })(FineDescriptions = exports.FineDescriptions || (exports.FineDescriptions = {}));
25
- const isCancelationAllowed = ({ date, minHoursForFreeCanceling = 0, }) => (0, differenceInHours_1.default)(new Date(date), new Date()) >= minHoursForFreeCanceling;
22
+ })(FineDescriptions || (exports.FineDescriptions = FineDescriptions = {}));
23
+ const isCancelationAllowed = ({ date, minHoursForFreeCanceling = 0, }) => (0, date_1.differenceInHours)(new Date(date), new Date()) >= minHoursForFreeCanceling;
26
24
  exports.isCancelationAllowed = isCancelationAllowed;
27
25
  function getOrderCancelationState({ cancelationReason, cancelationRule, cancelationAmount, transactions, date, returnCertificates, forceFine, certificates, minHoursForFreeCanceling, minHoursForFullFine, playersPrice, slotDiscount = 0, payed, minimalPrice, }) {
28
26
  const halfFineCancelation = cancelationRule !== questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.NO &&
@@ -38,7 +36,10 @@ function getOrderCancelationState({ cancelationReason, cancelationRule, cancelat
38
36
  date,
39
37
  minHoursForFreeCanceling: minHoursForFullFine,
40
38
  });
41
- const allowedCancelation = !forceFine && !halfFineCancelation && !foolFineCancelation;
39
+ const allowedCancelation = !forceFine &&
40
+ cancelationRule !== questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.NO &&
41
+ !halfFineCancelation &&
42
+ !foolFineCancelation;
42
43
  const receivedTransactions = getReceivedTransactions(transactions);
43
44
  const receivedTransactionsAmount = receivedTransactions.reduce((acc, tr) => acc + tr.amount - (tr.includedIncrease || 0), 0);
44
45
  const autoReturtAvailable = receivedTransactions.length === 1 &&
@@ -49,8 +50,9 @@ function getOrderCancelationState({ cancelationReason, cancelationRule, cancelat
49
50
  const cancelationType = foolFineCancelation
50
51
  ? questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.FULL_PRICE
51
52
  : cancelationRule;
52
- const fineAmount = typeof forceFine === 'number' ? forceFine :
53
- +(0, get_cancelation_fee_amount_1.getCancelationFeeAmount)({
53
+ const fineAmount = typeof forceFine === 'number'
54
+ ? forceFine
55
+ : +(0, get_cancelation_fee_amount_1.getCancelationFeeAmount)({
54
56
  cancelationRule: cancelationType,
55
57
  total: playersPrice,
56
58
  slotDiscount,
@@ -112,4 +114,3 @@ function getOrderCancelationState({ cancelationReason, cancelationRule, cancelat
112
114
  allowedCancelation,
113
115
  };
114
116
  }
115
- exports.getOrderCancelationState = getOrderCancelationState;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const order_cancel_reson_enum_1 = require("@escapenavigator/types/dist/order/enum/order-cancel-reson.enum");
5
5
  const questroom_cancelation_type_enum_1 = require("@escapenavigator/types/dist/questroom/enum/questroom-cancelation-type.enum");
6
6
  const transaction_type_enum_1 = require("@escapenavigator/types/dist/transaction/enum/transaction-type.enum");
7
- const date_fns_1 = require("date-fns");
7
+ const date_1 = require("../date");
8
8
  const _1 = require(".");
9
9
  describe('getOrderCancelationState function', () => {
10
10
  test('should return "no charge / no return" if cancelationReason is QUESTROOM', () => {
@@ -37,7 +37,7 @@ describe('getOrderCancelationState function', () => {
37
37
  cancelationAmount: 0,
38
38
  cancelationRule: questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.FULL_PRICE,
39
39
  transactions: [],
40
- date: (0, date_fns_1.addHours)(new Date(), 50).toISOString(),
40
+ date: (0, date_1.addHours)(new Date(), 50).toISOString(),
41
41
  returnCertificates: true,
42
42
  slotDiscount: 0,
43
43
  minHoursForFullFine: 0,
@@ -92,7 +92,7 @@ describe('getOrderCancelationState function', () => {
92
92
  type: transaction_type_enum_1.TransactionTypeEnum.INSIDE,
93
93
  },
94
94
  ],
95
- date: (0, date_fns_1.addHours)(new Date(), 50).toISOString(),
95
+ date: (0, date_1.addHours)(new Date(), 50).toISOString(),
96
96
  returnCertificates: true,
97
97
  certificates: [],
98
98
  minHoursForFreeCanceling: 48,
@@ -218,8 +218,8 @@ describe('getOrderCancelationState function', () => {
218
218
  });
219
219
  expect(result).toEqual({
220
220
  type: 'descriptionFineWithReturn',
221
- fineAmount: 50,
222
- returnAmount: 40,
221
+ fineAmount: 40,
222
+ returnAmount: 60,
223
223
  chargeAmount: 0,
224
224
  allowedCancelation: false,
225
225
  });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPlayersPrice = void 0;
4
4
  const getPlayersPrice = (order) => {
5
- if (!order || !order.price)
5
+ if (!order?.price)
6
6
  return 0;
7
7
  let baseAmount = order.price[order.players] || 0;
8
8
  if (!Number.isNaN(+order.price.child) && order.children) {
@@ -6,6 +6,8 @@ const get_players_price_1 = require("./get-players-price");
6
6
  const getPromocodeDiscount = ({ slotId, slotDiscount, total, promocodeType, promocodeDiscount, price, players, children = 0, }) => {
7
7
  const orderTotal = slotId ? total - slotDiscount : total;
8
8
  let amount = 0;
9
+ if (promocodeType === promocode_type_enum_1.PromocodeTypeEnum.PROMOTIONAL)
10
+ return 0;
9
11
  if (promocodeType === promocode_type_enum_1.PromocodeTypeEnum.FIXED)
10
12
  amount = promocodeDiscount;
11
13
  if (promocodeType === promocode_type_enum_1.PromocodeTypeEnum.PERCENT_BASE_SUM)
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getServiceError = exports.ErrorType = void 0;
3
+ exports.ErrorType = void 0;
4
+ exports.getServiceError = getServiceError;
4
5
  const is_axios_error_1 = require("./is-axios-error");
5
6
  const is_network_error_1 = require("./is-network-error");
6
7
  var ErrorType;
@@ -8,7 +9,7 @@ var ErrorType;
8
9
  ErrorType["NETWORK"] = "NETWORK";
9
10
  ErrorType["BUSINESS"] = "BUSINESS";
10
11
  ErrorType["INTERNAL"] = "INTERNAL";
11
- })(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
12
+ })(ErrorType || (exports.ErrorType = ErrorType = {}));
12
13
  const ERROR_CODES = {
13
14
  [ErrorType.INTERNAL]: 'INTERNAL_ERROR',
14
15
  [ErrorType.NETWORK]: 'NETWORK_ERROR',
@@ -63,4 +64,3 @@ function getServiceError(error) {
63
64
  originalError: error,
64
65
  };
65
66
  }
66
- exports.getServiceError = getServiceError;
@@ -5,8 +5,10 @@ type Props = {
5
5
  minHoursForFreeCanceling: number;
6
6
  cancelationRule: QuestroomCancelationTypeEnum;
7
7
  timeZone: string;
8
+ /** Для тестов: точка отсчёта «сейчас». */
9
+ now?: Date;
8
10
  };
9
- export declare function getSlotCancelationDate({ date, minHoursForFreeCanceling, cancelationRule, timeZone, }: Props): {
11
+ export declare function getSlotCancelationDate({ date, time, minHoursForFreeCanceling, cancelationRule, timeZone, now, }: Props): {
10
12
  canCancel: boolean;
11
13
  slotCancelationDate: Date;
12
14
  slotCancelationHumenDate: string;
@@ -1,22 +1,19 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSlotCancelationDate = void 0;
3
+ exports.getSlotCancelationDate = getSlotCancelationDate;
7
4
  const questroom_cancelation_type_enum_1 = require("@escapenavigator/types/dist/questroom/enum/questroom-cancelation-type.enum");
8
- const date_fns_1 = require("date-fns");
9
- const utcToZonedTime_1 = __importDefault(require("date-fns-tz/utcToZonedTime"));
10
- const format_1 = __importDefault(require("date-fns/format"));
11
- const isBefore_1 = __importDefault(require("date-fns/isBefore"));
12
- function getSlotCancelationDate({ date, minHoursForFreeCanceling, cancelationRule, timeZone, }) {
5
+ const date_1 = require("../date");
6
+ function getSlotCancelationDate({ date, time, minHoursForFreeCanceling, cancelationRule, timeZone, now = new Date(), }) {
13
7
  const minHours = cancelationRule === questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.NO ? 0 : minHoursForFreeCanceling;
14
- const zondedDate = (0, date_fns_1.addHours)(new Date(date), minHours);
15
- const d = (0, utcToZonedTime_1.default)(zondedDate.toISOString(), timeZone);
8
+ const timeHm = /^(\d{2}:\d{2})/.exec(time.trim())?.[1] ?? '00:00';
9
+ const slotUtc = (0, date_1.zonedTimeToUtc)(`${date} ${timeHm}`, timeZone);
10
+ /** Виджет передаёт отрицательное значение часов до слота; в тестах — положительное. */
11
+ const deadlineHours = minHours <= 0 ? minHours : -minHours;
12
+ const deadlineUtc = (0, date_1.addHours)(slotUtc, deadlineHours);
13
+ const d = (0, date_1.utcToZonedTime)(deadlineUtc.toISOString(), timeZone);
16
14
  return {
17
- canCancel: (0, isBefore_1.default)(new Date(), zondedDate),
15
+ canCancel: (0, date_1.isBefore)(now, deadlineUtc),
18
16
  slotCancelationDate: d,
19
- slotCancelationHumenDate: (0, format_1.default)(d, 'dd.MM.yyyy, HH:mm'),
17
+ slotCancelationHumenDate: (0, date_1.formatDate)(d, 'dd.MM.yyyy, HH:mm'),
20
18
  };
21
19
  }
22
- exports.getSlotCancelationDate = getSlotCancelationDate;
@@ -4,50 +4,46 @@ const questroom_cancelation_type_enum_1 = require("@escapenavigator/types/dist/q
4
4
  const _1 = require(".");
5
5
  describe('getSlotCancelationDate function', () => {
6
6
  test('should return canCancel false in summer time', () => {
7
- // значит в тае сейчас 19:00 а в Германии 12:00
8
- jest.useFakeTimers().setSystemTime(new Date(Date.UTC(2023, 5, 1, 10, 1)).valueOf());
9
7
  const result = (0, _1.getSlotCancelationDate)({
10
8
  date: '2023-06-03',
11
9
  cancelationRule: questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.FULL_PRICE,
12
10
  time: '12:00',
13
11
  minHoursForFreeCanceling: 48,
14
12
  timeZone: 'Europe/Berlin',
13
+ now: new Date(Date.UTC(2023, 5, 1, 10, 1)),
15
14
  });
16
15
  expect(result.canCancel).toBe(false);
17
16
  });
18
17
  test('should return canCancel false in winter time', () => {
19
- // значит в тае сейчас 19:00 а в Германии 11:00
20
- jest.useFakeTimers().setSystemTime(new Date(Date.UTC(2023, 0, 1, 10, 1)).valueOf());
21
18
  const result = (0, _1.getSlotCancelationDate)({
22
19
  date: '2023-01-03',
23
20
  cancelationRule: questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.FULL_PRICE,
24
21
  time: '11:00',
25
22
  minHoursForFreeCanceling: 48,
26
23
  timeZone: 'Europe/Berlin',
24
+ now: new Date(Date.UTC(2023, 0, 1, 10, 1)),
27
25
  });
28
26
  expect(result.canCancel).toBe(false);
29
27
  });
30
28
  test('should return canCancel true in summer time', () => {
31
- // значит в тае сейчас 19:00 а в Германии 12:00
32
- jest.useFakeTimers().setSystemTime(new Date(Date.UTC(2023, 5, 1, 9, 59)).valueOf());
33
29
  const result = (0, _1.getSlotCancelationDate)({
34
30
  cancelationRule: questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.FULL_PRICE,
35
31
  date: '2023-06-03',
36
32
  time: '12:00',
37
33
  minHoursForFreeCanceling: 48,
38
34
  timeZone: 'Europe/Berlin',
35
+ now: new Date(Date.UTC(2023, 5, 1, 9, 59)),
39
36
  });
40
37
  expect(result.canCancel).toBe(true);
41
38
  });
42
39
  test('should return canCancel true in winter time', () => {
43
- // значит в тае сейчас 19:00 а в Германии 11:00
44
- jest.useFakeTimers().setSystemTime(new Date(Date.UTC(2023, 0, 1, 9, 59)).valueOf());
45
40
  const result = (0, _1.getSlotCancelationDate)({
46
41
  cancelationRule: questroom_cancelation_type_enum_1.QuestroomCancelationTypeEnum.FULL_PRICE,
47
42
  date: '2023-01-03',
48
43
  time: '11:00',
49
44
  minHoursForFreeCanceling: 48,
50
45
  timeZone: 'Europe/Berlin',
46
+ now: new Date(Date.UTC(2023, 0, 1, 9, 59)),
51
47
  });
52
48
  expect(result.canCancel).toBe(true);
53
49
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getContrastColor = void 0;
3
+ exports.getContrastColor = getContrastColor;
4
4
  function getContrastColor(hexColor) {
5
5
  const r = parseInt(hexColor.slice(1, 3), 16);
6
6
  const g = parseInt(hexColor.slice(3, 5), 16);
@@ -8,4 +8,3 @@ function getContrastColor(hexColor) {
8
8
  const brightness = 0.2126 * r + 0.7152 * g + 0.0722 * b;
9
9
  return brightness > 130 ? '#000000' : '#FFFFFF';
10
10
  }
11
- exports.getContrastColor = getContrastColor;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasTextOutsideTags = void 0;
3
+ exports.hasTextOutsideTags = hasTextOutsideTags;
4
4
  function hasTextOutsideTags(html) {
5
5
  const text = html?.replace(/<[^>]+>/g, '').trim();
6
6
  return text?.length > 0;
7
7
  }
8
- exports.hasTextOutsideTags = hasTextOutsideTags;
package/dist/index.d.ts CHANGED
@@ -1,16 +1,22 @@
1
+ export * from './convert-hhmm-to-minutes';
2
+ export * from './convert-minutes-to-hhmm';
1
3
  export * from './convert-to-options';
4
+ export * from './date';
2
5
  export * from './enum-to-options';
3
6
  export * from './get-documents-links';
7
+ export * from './get-full-name';
4
8
  export * from './get-handled-error-message';
5
9
  export * from './get-order-cancelation-state';
6
10
  export * from './get-service-error';
7
11
  export * from './is-axios-error';
8
12
  export * from './is-network-error';
13
+ export * from './pick';
14
+ export * from './promocode-error-codes';
15
+ export * from './promocode-nominal-rules';
9
16
  export * from './redirect';
10
17
  export * from './serialize-record';
11
18
  export * from './serialize-slot';
12
19
  export * from './tz-date';
20
+ export * from './utm-touchpoints';
13
21
  export * from './validate-by-dto';
14
- export * from './convert-hhmm-to-minutes';
15
- export * from './convert-minutes-to-hhmm';
16
- export * from './get-full-name';
22
+ export * from './validate-promocode';
package/dist/index.js CHANGED
@@ -14,19 +14,25 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./convert-hhmm-to-minutes"), exports);
18
+ __exportStar(require("./convert-minutes-to-hhmm"), exports);
17
19
  __exportStar(require("./convert-to-options"), exports);
20
+ __exportStar(require("./date"), exports);
18
21
  __exportStar(require("./enum-to-options"), exports);
19
22
  __exportStar(require("./get-documents-links"), exports);
23
+ __exportStar(require("./get-full-name"), exports);
20
24
  __exportStar(require("./get-handled-error-message"), exports);
21
25
  __exportStar(require("./get-order-cancelation-state"), exports);
22
26
  __exportStar(require("./get-service-error"), exports);
23
27
  __exportStar(require("./is-axios-error"), exports);
24
28
  __exportStar(require("./is-network-error"), exports);
29
+ __exportStar(require("./pick"), exports);
30
+ __exportStar(require("./promocode-error-codes"), exports);
31
+ __exportStar(require("./promocode-nominal-rules"), exports);
25
32
  __exportStar(require("./redirect"), exports);
26
33
  __exportStar(require("./serialize-record"), exports);
27
34
  __exportStar(require("./serialize-slot"), exports);
28
35
  __exportStar(require("./tz-date"), exports);
36
+ __exportStar(require("./utm-touchpoints"), exports);
29
37
  __exportStar(require("./validate-by-dto"), exports);
30
- __exportStar(require("./convert-hhmm-to-minutes"), exports);
31
- __exportStar(require("./convert-minutes-to-hhmm"), exports);
32
- __exportStar(require("./get-full-name"), exports);
38
+ __exportStar(require("./validate-promocode"), exports);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAxiosError = void 0;
3
+ exports.isAxiosError = isAxiosError;
4
4
  /**
5
5
  * Возвращает `true`, если ошибка была выброшена axios
6
6
  * @param error Ошибка от сервиса
@@ -8,4 +8,3 @@ exports.isAxiosError = void 0;
8
8
  function isAxiosError(error) {
9
9
  return Boolean(error.isAxiosError);
10
10
  }
11
- exports.isAxiosError = isAxiosError;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNetworkError = void 0;
3
+ exports.isNetworkError = isNetworkError;
4
4
  const is_axios_error_1 = require("./is-axios-error");
5
5
  const NETWORK_ERROR_CODES = ['ENETUNREACH', 'ECONNABORTED', 'ENOTCONN'];
6
6
  /**
@@ -15,4 +15,3 @@ function isNetworkError(error) {
15
15
  }
16
16
  return false;
17
17
  }
18
- exports.isNetworkError = isNetworkError;
@@ -0,0 +1,2 @@
1
+ /** Subset of own enumerable properties (lodash.pick-style, ignores prototype chain). */
2
+ export declare function pick<T extends object, K extends keyof T>(object: T | null | undefined, keys: readonly K[]): Pick<T, K>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pick = pick;
4
+ /** Subset of own enumerable properties (lodash.pick-style, ignores prototype chain). */
5
+ function pick(object, keys) {
6
+ if (object == null) {
7
+ return {};
8
+ }
9
+ const result = {};
10
+ for (const key of keys) {
11
+ if (Object.hasOwn(object, key)) {
12
+ result[key] = object[key];
13
+ }
14
+ }
15
+ return result;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const _1 = require(".");
4
+ describe('pick', () => {
5
+ test('returns only listed own properties', () => {
6
+ const src = { a: 1, b: 2, c: 3 };
7
+ expect((0, _1.pick)(src, ['a', 'c'])).toEqual({ a: 1, c: 3 });
8
+ });
9
+ test('omits keys missing on the object', () => {
10
+ const src = { a: 1 };
11
+ expect((0, _1.pick)(src, ['a', 'b'])).toEqual({ a: 1 });
12
+ });
13
+ test('returns empty object for null and undefined', () => {
14
+ expect((0, _1.pick)(null, ['a'])).toEqual({});
15
+ expect((0, _1.pick)(undefined, ['a'])).toEqual({});
16
+ });
17
+ test('does not read inherited prototype keys', () => {
18
+ const proto = { inherited: 1 };
19
+ const src = Object.create(proto);
20
+ src.own = 2;
21
+ expect((0, _1.pick)(src, ['own', 'inherited'])).toEqual({ own: 2 });
22
+ });
23
+ });
@@ -0,0 +1,72 @@
1
+ export declare enum PromocodeErrorCode {
2
+ NOT_AVAILABLE_FOR_CERTIFICATES = "NOT_AVAILABLE_FOR_CERTIFICATES",
3
+ NOT_AVAILABLE_FOR_BOOKINGS = "NOT_AVAILABLE_FOR_BOOKINGS",
4
+ ALREADY_APPLIED = "ALREADY_APPLIED",
5
+ INSIDE_ONLY = "INSIDE_ONLY",
6
+ MAX_APPLYINGS_REACHED = "MAX_APPLYINGS_REACHED",
7
+ SINGLE_USE = "SINGLE_USE",
8
+ NOT_COMBINABLE_WITH_OTHER_DISCOUNTS = "NOT_COMBINABLE_WITH_OTHER_DISCOUNTS",
9
+ NOT_COMBINABLE_WITH_CERTIFICATES = "NOT_COMBINABLE_WITH_CERTIFICATES",
10
+ NOT_VALID_YET = "NOT_VALID_YET",
11
+ EXPIRED = "EXPIRED",
12
+ NOT_FOR_ORDER_DATE_FROM = "NOT_FOR_ORDER_DATE_FROM",
13
+ NOT_FOR_ORDER_DATE_TO = "NOT_FOR_ORDER_DATE_TO",
14
+ QUESTROOM_NOT_ALLOWED = "QUESTROOM_NOT_ALLOWED",
15
+ NOT_AVAILABLE_AT_THIS_TIME_FROM = "NOT_AVAILABLE_AT_THIS_TIME_FROM",
16
+ NOT_AVAILABLE_AT_THIS_TIME_TO = "NOT_AVAILABLE_AT_THIS_TIME_TO",
17
+ NOT_AVAILABLE_THIS_DAY = "NOT_AVAILABLE_THIS_DAY",
18
+ MIN_PLAYERS = "MIN_PLAYERS",
19
+ MAX_PLAYERS = "MAX_PLAYERS"
20
+ }
21
+ type ErrorPayloadMap = {
22
+ [PromocodeErrorCode.NOT_AVAILABLE_FOR_CERTIFICATES]: undefined;
23
+ [PromocodeErrorCode.NOT_AVAILABLE_FOR_BOOKINGS]: undefined;
24
+ [PromocodeErrorCode.ALREADY_APPLIED]: undefined;
25
+ [PromocodeErrorCode.INSIDE_ONLY]: undefined;
26
+ [PromocodeErrorCode.MAX_APPLYINGS_REACHED]: undefined;
27
+ [PromocodeErrorCode.SINGLE_USE]: undefined;
28
+ [PromocodeErrorCode.NOT_COMBINABLE_WITH_OTHER_DISCOUNTS]: undefined;
29
+ [PromocodeErrorCode.NOT_COMBINABLE_WITH_CERTIFICATES]: undefined;
30
+ [PromocodeErrorCode.NOT_VALID_YET]: {
31
+ validFrom: string;
32
+ };
33
+ [PromocodeErrorCode.EXPIRED]: {
34
+ validTo: string;
35
+ };
36
+ [PromocodeErrorCode.NOT_FOR_ORDER_DATE_FROM]: {
37
+ forOrdersFrom: string;
38
+ };
39
+ [PromocodeErrorCode.NOT_FOR_ORDER_DATE_TO]: {
40
+ forOrdersTo: string;
41
+ };
42
+ [PromocodeErrorCode.QUESTROOM_NOT_ALLOWED]: undefined;
43
+ [PromocodeErrorCode.NOT_AVAILABLE_AT_THIS_TIME_FROM]: {
44
+ availableFrom: string;
45
+ };
46
+ [PromocodeErrorCode.NOT_AVAILABLE_AT_THIS_TIME_TO]: {
47
+ availableTo: string;
48
+ };
49
+ [PromocodeErrorCode.NOT_AVAILABLE_THIS_DAY]: undefined;
50
+ [PromocodeErrorCode.MIN_PLAYERS]: {
51
+ minPlayers: number;
52
+ };
53
+ [PromocodeErrorCode.MAX_PLAYERS]: {
54
+ maxPlayers: number;
55
+ };
56
+ };
57
+ export type PromocodeError = {
58
+ [K in PromocodeErrorCode]: ErrorPayloadMap[K] extends undefined ? {
59
+ code: K;
60
+ } : {
61
+ code: K;
62
+ payload: ErrorPayloadMap[K];
63
+ };
64
+ }[PromocodeErrorCode];
65
+ /**
66
+ * Английский fallback для отображения кода ошибки промокода вне i18n-контекста.
67
+ * Для пользовательского UI нужно использовать i18n-ключи вида
68
+ * `errors.promocode.<CODE>` с подстановкой `payload`. Эта функция — последний
69
+ * рубеж, чтобы при ошибке всегда было что показать.
70
+ */
71
+ export declare function formatPromocodeErrorFallback(error: PromocodeError): string;
72
+ export {};