ecotransac-shared-js 1.1.5 → 1.1.7

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/dist/index.d.mts CHANGED
@@ -867,6 +867,15 @@ type User = {
867
867
  stripePortalUrl?: Maybe<Scalars['String']['output']>;
868
868
  };
869
869
 
870
+ declare const getLowThreshold: (isForPro: boolean) => {
871
+ limit: number;
872
+ fees: number;
873
+ };
874
+ declare const getFeesPercentage: (price: number, isForProfessionalUse: boolean) => 0 | 10 | 9 | 8 | 7 | 8.5 | 7.5 | 6.5 | 6 | 5;
875
+ type GetNetPriceMandate = Pick<Mandate, "isForProfessionalUse" | "isCommercialWallsSale" | "isBusinessAssetsTransfer" | "isLeaseRightsTransfer" | "netOwnerPrice" | "leaseRightsPrice" | "businessAssetsPrice">;
876
+ declare const getNetPrice: (mandate: GetNetPriceMandate) => number;
877
+ declare const getAgencyFees: (mandate: Mandate) => number;
878
+
870
879
  declare const getLabel: <T>(list: {
871
880
  value: T;
872
881
  label: string;
@@ -966,4 +975,4 @@ declare const MANDATE_EXCLUSIVITY: {
966
975
  label: string;
967
976
  }[];
968
977
 
969
- export { COMPANY_INFO, CONDITIONS, COUNTRIES, ESTATE_CONDITION, EXPOSURES, GENDER, HEATING_ENERGY, IDENTIFICATION_DOCUMENTS, KITCHEN_TYPE, LEASE_ESTABLISHMENT, LEASE_TRANSFERT_PERMISSIONS, LEGAL_NATURE, MANDATE_EXCLUSIVITY, MARITAL_STATUS, PRENUP_TYPES, SHARING_CONFIGURATION, STANDINGS, VIEWS, featuresFormFields, formatAddress, formatAgentLegalData, formatDate, formatMandateNumber, formatNumber, formatPhone, formatPrice, formatSeconds, getLabel, getPropertyTitle, propertyFields, surfacesFormFields, technicalFormFields };
978
+ export { COMPANY_INFO, CONDITIONS, COUNTRIES, ESTATE_CONDITION, EXPOSURES, GENDER, HEATING_ENERGY, IDENTIFICATION_DOCUMENTS, KITCHEN_TYPE, LEASE_ESTABLISHMENT, LEASE_TRANSFERT_PERMISSIONS, LEGAL_NATURE, MANDATE_EXCLUSIVITY, MARITAL_STATUS, PRENUP_TYPES, SHARING_CONFIGURATION, STANDINGS, VIEWS, featuresFormFields, formatAddress, formatAgentLegalData, formatDate, formatMandateNumber, formatNumber, formatPhone, formatPrice, formatSeconds, getAgencyFees, getFeesPercentage, getLabel, getLowThreshold, getNetPrice, getPropertyTitle, propertyFields, surfacesFormFields, technicalFormFields };
package/dist/index.d.ts CHANGED
@@ -867,6 +867,15 @@ type User = {
867
867
  stripePortalUrl?: Maybe<Scalars['String']['output']>;
868
868
  };
869
869
 
870
+ declare const getLowThreshold: (isForPro: boolean) => {
871
+ limit: number;
872
+ fees: number;
873
+ };
874
+ declare const getFeesPercentage: (price: number, isForProfessionalUse: boolean) => 0 | 10 | 9 | 8 | 7 | 8.5 | 7.5 | 6.5 | 6 | 5;
875
+ type GetNetPriceMandate = Pick<Mandate, "isForProfessionalUse" | "isCommercialWallsSale" | "isBusinessAssetsTransfer" | "isLeaseRightsTransfer" | "netOwnerPrice" | "leaseRightsPrice" | "businessAssetsPrice">;
876
+ declare const getNetPrice: (mandate: GetNetPriceMandate) => number;
877
+ declare const getAgencyFees: (mandate: Mandate) => number;
878
+
870
879
  declare const getLabel: <T>(list: {
871
880
  value: T;
872
881
  label: string;
@@ -966,4 +975,4 @@ declare const MANDATE_EXCLUSIVITY: {
966
975
  label: string;
967
976
  }[];
968
977
 
969
- export { COMPANY_INFO, CONDITIONS, COUNTRIES, ESTATE_CONDITION, EXPOSURES, GENDER, HEATING_ENERGY, IDENTIFICATION_DOCUMENTS, KITCHEN_TYPE, LEASE_ESTABLISHMENT, LEASE_TRANSFERT_PERMISSIONS, LEGAL_NATURE, MANDATE_EXCLUSIVITY, MARITAL_STATUS, PRENUP_TYPES, SHARING_CONFIGURATION, STANDINGS, VIEWS, featuresFormFields, formatAddress, formatAgentLegalData, formatDate, formatMandateNumber, formatNumber, formatPhone, formatPrice, formatSeconds, getLabel, getPropertyTitle, propertyFields, surfacesFormFields, technicalFormFields };
978
+ export { COMPANY_INFO, CONDITIONS, COUNTRIES, ESTATE_CONDITION, EXPOSURES, GENDER, HEATING_ENERGY, IDENTIFICATION_DOCUMENTS, KITCHEN_TYPE, LEASE_ESTABLISHMENT, LEASE_TRANSFERT_PERMISSIONS, LEGAL_NATURE, MANDATE_EXCLUSIVITY, MARITAL_STATUS, PRENUP_TYPES, SHARING_CONFIGURATION, STANDINGS, VIEWS, featuresFormFields, formatAddress, formatAgentLegalData, formatDate, formatMandateNumber, formatNumber, formatPhone, formatPrice, formatSeconds, getAgencyFees, getFeesPercentage, getLabel, getLowThreshold, getNetPrice, getPropertyTitle, propertyFields, surfacesFormFields, technicalFormFields };
package/dist/index.js CHANGED
@@ -57,7 +57,11 @@ __export(src_exports, {
57
57
  formatPhone: () => formatPhone,
58
58
  formatPrice: () => formatPrice,
59
59
  formatSeconds: () => formatSeconds,
60
+ getAgencyFees: () => getAgencyFees,
61
+ getFeesPercentage: () => getFeesPercentage,
60
62
  getLabel: () => getLabel,
63
+ getLowThreshold: () => getLowThreshold,
64
+ getNetPrice: () => getNetPrice,
61
65
  getPropertyTitle: () => getPropertyTitle,
62
66
  propertyFields: () => propertyFields,
63
67
  surfacesFormFields: () => surfacesFormFields,
@@ -65,8 +69,57 @@ __export(src_exports, {
65
69
  });
66
70
  module.exports = __toCommonJS(src_exports);
67
71
 
68
- // src/functions/format.ts
72
+ // src/functions/agency-fees.ts
69
73
  var import_currency = __toESM(require("currency.js"));
74
+ var import_lodash = require("lodash");
75
+ var getLowThreshold = (isForPro) => isForPro ? { limit: 5e4, fees: 4950 } : { limit: 6e4, fees: 5950 };
76
+ var getFeesPercentage = (price, isForProfessionalUse) => {
77
+ if (isForProfessionalUse) {
78
+ if (price < 5e4) return 0;
79
+ if ((0, import_lodash.inRange)(price, 5e4, 2e5)) return 10;
80
+ if ((0, import_lodash.inRange)(price, 2e5, 3e5)) return 9;
81
+ if ((0, import_lodash.inRange)(price, 3e5, 6e5)) return 8;
82
+ return 7;
83
+ }
84
+ if (price < 6e4) return 0;
85
+ if ((0, import_lodash.inRange)(price, 6e4, 12e4)) return 10;
86
+ if ((0, import_lodash.inRange)(price, 12e4, 16e4)) return 8.5;
87
+ if ((0, import_lodash.inRange)(price, 16e4, 23e4)) return 7.5;
88
+ if ((0, import_lodash.inRange)(price, 23e4, 32e4)) return 6.5;
89
+ if ((0, import_lodash.inRange)(price, 32e4, 65e4)) return 6;
90
+ return 5;
91
+ };
92
+ var getNetPrice = (mandate) => {
93
+ const {
94
+ isForProfessionalUse,
95
+ isCommercialWallsSale,
96
+ isBusinessAssetsTransfer,
97
+ isLeaseRightsTransfer,
98
+ netOwnerPrice = 0,
99
+ leaseRightsPrice = 0,
100
+ businessAssetsPrice = 0
101
+ } = mandate;
102
+ if (isForProfessionalUse) {
103
+ if (isCommercialWallsSale && !netOwnerPrice)
104
+ throw new Error("Missing netOwnerPrice");
105
+ if (isBusinessAssetsTransfer && !businessAssetsPrice)
106
+ throw new Error("Missing businessAssetsPrice");
107
+ if (isLeaseRightsTransfer && !leaseRightsPrice)
108
+ throw new Error("Missing leaseRightsPrice");
109
+ return (0, import_currency.default)(0).add(isCommercialWallsSale ? netOwnerPrice : 0).add(isBusinessAssetsTransfer ? businessAssetsPrice : 0).add(isLeaseRightsTransfer ? leaseRightsPrice : 0).value;
110
+ }
111
+ return netOwnerPrice;
112
+ };
113
+ var getAgencyFees = (mandate) => {
114
+ const netPrice = getNetPrice(mandate);
115
+ const { agencyFeePercentage, isForProfessionalUse } = mandate;
116
+ const { limit, fees } = getLowThreshold(isForProfessionalUse);
117
+ if (netPrice < limit) return fees;
118
+ return (0, import_currency.default)(netPrice).multiply((agencyFeePercentage || 100) / 100).value;
119
+ };
120
+
121
+ // src/functions/format.ts
122
+ var import_currency2 = __toESM(require("currency.js"));
70
123
  var import_date_fns = require("date-fns");
71
124
  var import_libphonenumber_js = require("libphonenumber-js");
72
125
  var getLabel = (list, value) => {
@@ -84,7 +137,7 @@ var formatDate = (date, withTime = false) => {
84
137
  if (!date) return null;
85
138
  return withTime ? (0, import_date_fns.format)(date || /* @__PURE__ */ new Date(), "dd/MM/yyyy \xE0 HH:mm") : (0, import_date_fns.format)(date || /* @__PURE__ */ new Date(), "dd/MM/yyyy");
86
139
  };
87
- var formatPrice = (price) => (0, import_currency.default)(price, {
140
+ var formatPrice = (price) => (0, import_currency2.default)(price, {
88
141
  separator: " ",
89
142
  decimal: ",",
90
143
  symbol: "\u20AC",
@@ -1238,7 +1291,11 @@ var MANDATE_EXCLUSIVITY = [
1238
1291
  formatPhone,
1239
1292
  formatPrice,
1240
1293
  formatSeconds,
1294
+ getAgencyFees,
1295
+ getFeesPercentage,
1241
1296
  getLabel,
1297
+ getLowThreshold,
1298
+ getNetPrice,
1242
1299
  getPropertyTitle,
1243
1300
  propertyFields,
1244
1301
  surfacesFormFields,
package/dist/index.mjs CHANGED
@@ -1,5 +1,54 @@
1
- // src/functions/format.ts
1
+ // src/functions/agency-fees.ts
2
2
  import currency from "currency.js";
3
+ import { inRange } from "lodash";
4
+ var getLowThreshold = (isForPro) => isForPro ? { limit: 5e4, fees: 4950 } : { limit: 6e4, fees: 5950 };
5
+ var getFeesPercentage = (price, isForProfessionalUse) => {
6
+ if (isForProfessionalUse) {
7
+ if (price < 5e4) return 0;
8
+ if (inRange(price, 5e4, 2e5)) return 10;
9
+ if (inRange(price, 2e5, 3e5)) return 9;
10
+ if (inRange(price, 3e5, 6e5)) return 8;
11
+ return 7;
12
+ }
13
+ if (price < 6e4) return 0;
14
+ if (inRange(price, 6e4, 12e4)) return 10;
15
+ if (inRange(price, 12e4, 16e4)) return 8.5;
16
+ if (inRange(price, 16e4, 23e4)) return 7.5;
17
+ if (inRange(price, 23e4, 32e4)) return 6.5;
18
+ if (inRange(price, 32e4, 65e4)) return 6;
19
+ return 5;
20
+ };
21
+ var getNetPrice = (mandate) => {
22
+ const {
23
+ isForProfessionalUse,
24
+ isCommercialWallsSale,
25
+ isBusinessAssetsTransfer,
26
+ isLeaseRightsTransfer,
27
+ netOwnerPrice = 0,
28
+ leaseRightsPrice = 0,
29
+ businessAssetsPrice = 0
30
+ } = mandate;
31
+ if (isForProfessionalUse) {
32
+ if (isCommercialWallsSale && !netOwnerPrice)
33
+ throw new Error("Missing netOwnerPrice");
34
+ if (isBusinessAssetsTransfer && !businessAssetsPrice)
35
+ throw new Error("Missing businessAssetsPrice");
36
+ if (isLeaseRightsTransfer && !leaseRightsPrice)
37
+ throw new Error("Missing leaseRightsPrice");
38
+ return currency(0).add(isCommercialWallsSale ? netOwnerPrice : 0).add(isBusinessAssetsTransfer ? businessAssetsPrice : 0).add(isLeaseRightsTransfer ? leaseRightsPrice : 0).value;
39
+ }
40
+ return netOwnerPrice;
41
+ };
42
+ var getAgencyFees = (mandate) => {
43
+ const netPrice = getNetPrice(mandate);
44
+ const { agencyFeePercentage, isForProfessionalUse } = mandate;
45
+ const { limit, fees } = getLowThreshold(isForProfessionalUse);
46
+ if (netPrice < limit) return fees;
47
+ return currency(netPrice).multiply((agencyFeePercentage || 100) / 100).value;
48
+ };
49
+
50
+ // src/functions/format.ts
51
+ import currency2 from "currency.js";
3
52
  import { format } from "date-fns";
4
53
  import { format as formatPhoneFn } from "libphonenumber-js";
5
54
  var getLabel = (list, value) => {
@@ -17,7 +66,7 @@ var formatDate = (date, withTime = false) => {
17
66
  if (!date) return null;
18
67
  return withTime ? format(date || /* @__PURE__ */ new Date(), "dd/MM/yyyy \xE0 HH:mm") : format(date || /* @__PURE__ */ new Date(), "dd/MM/yyyy");
19
68
  };
20
- var formatPrice = (price) => currency(price, {
69
+ var formatPrice = (price) => currency2(price, {
21
70
  separator: " ",
22
71
  decimal: ",",
23
72
  symbol: "\u20AC",
@@ -1170,7 +1219,11 @@ export {
1170
1219
  formatPhone,
1171
1220
  formatPrice,
1172
1221
  formatSeconds,
1222
+ getAgencyFees,
1223
+ getFeesPercentage,
1173
1224
  getLabel,
1225
+ getLowThreshold,
1226
+ getNetPrice,
1174
1227
  getPropertyTitle,
1175
1228
  propertyFields,
1176
1229
  surfacesFormFields,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecotransac-shared-js",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "modules": "dist/index.mjs",