@vibe-flats/booking-engine-common-server 1.0.149 → 1.0.151

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.
package/build/index.d.ts CHANGED
@@ -4,5 +4,3 @@ export * from './src/utils/vibe-price';
4
4
  export * from './src/utils/monthly-diff';
5
5
  export * from './src/utils/purge-unit-cache';
6
6
  export * from './src/utils/cache';
7
- export type { ChannelDocument } from './src/models/channels';
8
- export { getChannel, DIRECT_CHANNEL_PUBLIC_ID } from './src/utils/channel-cache';
package/build/index.js CHANGED
@@ -14,13 +14,9 @@ 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
- exports.DIRECT_CHANNEL_PUBLIC_ID = exports.getChannel = void 0;
18
17
  __exportStar(require("./src/units-models"), exports);
19
18
  __exportStar(require("./src/config/app"), exports);
20
19
  __exportStar(require("./src/utils/vibe-price"), exports);
21
20
  __exportStar(require("./src/utils/monthly-diff"), exports);
22
21
  __exportStar(require("./src/utils/purge-unit-cache"), exports);
23
22
  __exportStar(require("./src/utils/cache"), exports);
24
- var channel_cache_1 = require("./src/utils/channel-cache");
25
- Object.defineProperty(exports, "getChannel", { enumerable: true, get: function () { return channel_cache_1.getChannel; } });
26
- Object.defineProperty(exports, "DIRECT_CHANNEL_PUBLIC_ID", { enumerable: true, get: function () { return channel_cache_1.DIRECT_CHANNEL_PUBLIC_ID; } });
@@ -8,10 +8,6 @@ export interface ChannelDocument extends mongoose.Document {
8
8
  isDefault: boolean;
9
9
  isExternal: boolean;
10
10
  isActive: boolean;
11
- excludeUtilities: boolean;
12
- website: {
13
- sourceOverride: string;
14
- };
15
11
  }
16
12
  export declare const ChannelModel: (connection: mongoose.Connection) => mongoose.Model<ChannelDocument, {}, {}, {}, mongoose.Document<unknown, {}, ChannelDocument> & ChannelDocument & Required<{
17
13
  _id: unknown;
@@ -42,17 +42,6 @@ const schema = new mongoose_1.default.Schema({
42
42
  type: Boolean,
43
43
  required: true,
44
44
  default: true
45
- },
46
- excludeUtilities: {
47
- type: Boolean,
48
- required: false,
49
- default: false
50
- },
51
- website: {
52
- sourceOverride: {
53
- type: String,
54
- required: false
55
- }
56
45
  }
57
46
  }, {
58
47
  timestamps: true
@@ -6,6 +6,22 @@ import { MarketDocument } from './markets';
6
6
  import { GuestDocument } from './guests';
7
7
  export type UnitReviewCategory = 'cleanliness' | 'communication' | 'checkin' | 'accuracy' | 'location' | 'value' | 'service';
8
8
  export type UnitReviewPlatform = 'direct' | 'airbnb' | 'vrbo' | 'booking' | 'expedia';
9
+ export declare const UNIT_TYPES: {
10
+ readonly SINGLE: "single";
11
+ readonly MULTI_PARENT: "multi-listing-parent";
12
+ readonly MULTI_CHILD: "multi-listing-child";
13
+ };
14
+ export type UnitType = (typeof UNIT_TYPES)[keyof typeof UNIT_TYPES];
15
+ export declare const TAX_UNITS: {
16
+ readonly PERCENTAGE: "PERCENTAGE";
17
+ readonly FIXED: "FIXED";
18
+ };
19
+ export type TaxUnits = (typeof TAX_UNITS)[keyof typeof TAX_UNITS];
20
+ export declare const TAX_QUANTIFIERS: {
21
+ readonly PER_STAY: "PER_STAY";
22
+ readonly PER_NIGHT: "PER_NIGHT";
23
+ };
24
+ export type TaxQuantifier = (typeof TAX_QUANTIFIERS)[keyof typeof TAX_QUANTIFIERS];
9
25
  export interface UnitDocument extends mongoose.Document {
10
26
  name: string;
11
27
  code: number;
@@ -69,6 +85,15 @@ export interface UnitDocument extends mongoose.Document {
69
85
  multiplier: 'PER_NIGHT' | 'PER_STAY' | 'PER_GUEST' | 'PER_GUEST_PER_NIGHT';
70
86
  isPercentage: boolean;
71
87
  }[];
88
+ taxes: {
89
+ guestyId: string;
90
+ type: string;
91
+ name: string;
92
+ amount: number;
93
+ units: TaxUnits;
94
+ quantifier: TaxQuantifier;
95
+ maxNightCountToApplyOn?: number;
96
+ }[];
72
97
  urls: {
73
98
  airbnb: string;
74
99
  vrbo: string;
@@ -110,6 +135,8 @@ export interface UnitDocument extends mongoose.Document {
110
135
  salesBlockWarning: string;
111
136
  hasOpenExtensionLink: boolean;
112
137
  lengthOfStayType: 'monthly' | 'hybrid' | 'nightly';
138
+ type: UnitType;
139
+ parent?: UnitDocument;
113
140
  guesty?: {
114
141
  sync?: {
115
142
  name?: string;
@@ -23,8 +23,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.UnitModel = void 0;
26
+ exports.UnitModel = exports.TAX_QUANTIFIERS = exports.TAX_UNITS = exports.UNIT_TYPES = void 0;
27
27
  const mongoose_1 = __importStar(require("mongoose"));
28
+ exports.UNIT_TYPES = {
29
+ SINGLE: 'single',
30
+ MULTI_PARENT: 'multi-listing-parent',
31
+ MULTI_CHILD: 'multi-listing-child'
32
+ };
33
+ exports.TAX_UNITS = {
34
+ PERCENTAGE: 'PERCENTAGE',
35
+ FIXED: 'FIXED'
36
+ };
37
+ exports.TAX_QUANTIFIERS = {
38
+ PER_STAY: 'PER_STAY',
39
+ PER_NIGHT: 'PER_NIGHT'
40
+ };
28
41
  const schema = new mongoose_1.default.Schema({
29
42
  name: { type: String, required: true },
30
43
  code: { type: Number, required: true },
@@ -97,6 +110,18 @@ const schema = new mongoose_1.default.Schema({
97
110
  _id: false
98
111
  }
99
112
  ],
113
+ taxes: [
114
+ {
115
+ guestyId: { type: String, required: true },
116
+ type: { type: String, required: true },
117
+ name: { type: String, required: true },
118
+ amount: { type: Number, required: true },
119
+ units: { type: String, enum: Object.values(exports.TAX_UNITS), required: true },
120
+ quantifier: { type: String, enum: Object.values(exports.TAX_QUANTIFIERS), required: true },
121
+ maxNightCountToApplyOn: { type: Number, required: false },
122
+ _id: false
123
+ }
124
+ ],
100
125
  urls: {
101
126
  type: new mongoose_1.default.Schema({
102
127
  airbnb: { type: String, required: false },
@@ -160,6 +185,8 @@ const schema = new mongoose_1.default.Schema({
160
185
  salesBlockWarning: { type: String, required: false },
161
186
  hasOpenExtensionLink: { type: Boolean, required: false },
162
187
  lengthOfStayType: { type: String, required: false },
188
+ type: { type: String, enum: Object.values(exports.UNIT_TYPES), required: true, default: exports.UNIT_TYPES.SINGLE },
189
+ parent: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Unit', required: false },
163
190
  guesty: {
164
191
  type: new mongoose_1.default.Schema({
165
192
  sync: {
@@ -183,6 +210,7 @@ const schema = new mongoose_1.default.Schema({
183
210
  schema.index({ publicId: 1 });
184
211
  schema.index({ code: 1 });
185
212
  schema.index({ hubspotId: 1 });
213
+ schema.index({ parent: 1 });
186
214
  const UnitModel = (connection) => {
187
215
  return connection.model('Unit', schema);
188
216
  };
@@ -1,13 +1,19 @@
1
1
  import { AvailabilityDocument } from '../models/availability';
2
2
  import { UnitDocument } from '../models/units';
3
+ export interface VibePriceTax {
4
+ name: string;
5
+ amount: number;
6
+ }
3
7
  export interface VibePrice {
4
8
  nights: number;
5
9
  rent: number;
6
10
  cleaning: number;
7
11
  utilities: number;
8
12
  subTotal: number;
9
- total: number;
10
13
  discount: number;
14
+ taxes: VibePriceTax[];
15
+ taxTotal: number;
16
+ total: number;
11
17
  monthly: {
12
18
  discount: number;
13
19
  rent: number;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vibePrice = void 0;
4
4
  const vibe_common_1 = require("@vibe-flats/vibe-common");
5
+ const units_1 = require("../models/units");
5
6
  const monthly_diff_1 = require("./monthly-diff");
6
7
  const vibePrice = (obj) => {
7
8
  const { unit, stay, excludeCleaning, excludeUtilities, markup, forceMonthlyDiscount } = obj;
@@ -23,13 +24,22 @@ const vibePrice = (obj) => {
23
24
  const discount = (nights >= vibe_common_1.DAYS_IN_MONTH || forceMonthlyDiscount) && unit.prices.monthlyPriceFactor !== 1
24
25
  ? +(rent * (1 - unit.prices.monthlyPriceFactor)).toFixed(0)
25
26
  : 0;
26
- const total = subTotal - discount;
27
+ const preTaxTotal = subTotal - discount;
28
+ const taxes = (unit.taxes || [])
29
+ .filter(tax => !tax.maxNightCountToApplyOn || nights <= tax.maxNightCountToApplyOn)
30
+ .map(tax => {
31
+ const baseAmount = tax.units === units_1.TAX_UNITS.PERCENTAGE ? Math.round(preTaxTotal * (tax.amount / 100)) : tax.amount;
32
+ const taxAmount = tax.quantifier === 'PER_NIGHT' ? baseAmount * nights : baseAmount;
33
+ return { name: tax.name, amount: Math.round(taxAmount) };
34
+ });
35
+ const taxTotal = taxes.reduce((sum, tax) => sum + tax.amount, 0);
36
+ const total = preTaxTotal + taxTotal;
27
37
  const monthly = {
28
38
  rent: Math.round(rent / monthsDiff),
29
39
  discount: Math.round(discount / monthsDiff),
30
40
  subTotal: Math.round(subTotal / monthsDiff),
31
41
  total: Math.round(total / monthsDiff)
32
42
  };
33
- return { nights, rent, cleaning, utilities, subTotal, discount, total, monthly };
43
+ return { nights, rent, cleaning, utilities, subTotal, discount, taxes, taxTotal, total, monthly };
34
44
  };
35
45
  exports.vibePrice = vibePrice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-flats/booking-engine-common-server",
3
- "version": "1.0.149",
3
+ "version": "1.0.151",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -1,4 +0,0 @@
1
- import mongoose from 'mongoose';
2
- import { ChannelDocument } from '../models/channels';
3
- export declare const DIRECT_CHANNEL_PUBLIC_ID = "direct";
4
- export declare const getChannel: (id: string, connection: mongoose.Connection) => Promise<ChannelDocument | null>;
@@ -1,29 +0,0 @@
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.getChannel = exports.DIRECT_CHANNEL_PUBLIC_ID = void 0;
13
- const units_models_1 = require("../units-models");
14
- exports.DIRECT_CHANNEL_PUBLIC_ID = 'direct';
15
- const CACHE_TTL_MS = 10 * 60 * 1000;
16
- const cache = new Map();
17
- const getChannel = (id, connection) => __awaiter(void 0, void 0, void 0, function* () {
18
- const cached = cache.get(id);
19
- if (cached && Date.now() - cached.cachedAt < CACHE_TTL_MS) {
20
- return cached.channel;
21
- }
22
- const { ChannelModel } = (0, units_models_1.unitsModels)(connection);
23
- const channel = yield ChannelModel.findOne({
24
- $or: [{ publicId: id }, { name: id }, { guestyId: id }]
25
- });
26
- cache.set(id, { channel, cachedAt: Date.now() });
27
- return channel;
28
- });
29
- exports.getChannel = getChannel;