@molopos/shared 2.0.25 → 2.0.27

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/enum/index.d.ts CHANGED
@@ -63,7 +63,72 @@ export declare enum QueryTypeEnum {
63
63
  Subcategory = "SUBCATEGORY",
64
64
  ExpenseItem = "EXPENSEITEM",
65
65
  Organization = "ORGANIZATION",
66
- ApplicationSection = "APPLICATIONSECTION"
66
+ ApplicationSection = "APPLICATIONSECTION",
67
+ Task = "TASK",
68
+ Pipeline = "PIPELINE"
69
+ }
70
+ /**
71
+ * Activity model enum
72
+ */
73
+ export declare enum ActivityModelEnum {
74
+ ViewCount = "VIEW_COUNT",
75
+ ProductCreate = "PRODUCT_CREATE",
76
+ ProductUpdate = "PRODUCT_UPDATE",
77
+ CatalogCreate = "CATALOG_CREATE",
78
+ CatalogUpdate = "CATALOG_UPDATE",
79
+ VariantCreate = "VARIANT_CREATE",
80
+ VariantUpdate = "VARIANT_UPDATE",
81
+ CategoryCreate = "CATEGORY_CREATE",
82
+ CategoryUpdate = "CATEGORY_UPDATE",
83
+ BrandCreate = "BRAND_CREATE",
84
+ BrandUpdate = "BRAND_UPDATE",
85
+ AdditionCreate = "ADDITION_CREATE",
86
+ AdditionUpdate = "ADDITION_UPDATE",
87
+ DiscountCreate = "DISCOUNT_CREATE",
88
+ DiscountUpdate = "DISCOUNT_UPDATE",
89
+ UnitCreate = "UNIT_CREATE",
90
+ UnitUpdate = "UNIT_UPDATE",
91
+ OrderUpdate = "ORDER_UPDATE",
92
+ OrderConfirmed = "ORDER_CONFIRMED",
93
+ QuoteCreate = "QUOTE_CREATE",
94
+ QuoteUpdate = "QUOTE_UPDATE",
95
+ OrderItemCreate = "ORDER_ITEM_CREATE",
96
+ OrderItemUpdate = "ORDER_ITEM_UPDATE",
97
+ PointOfSaleCreate = "POINT_OF_SALE_CREATE",
98
+ PointOfSaleUpdate = "POINT_OF_SALE_UPDATE",
99
+ UserCreate = "USER_CREATE",
100
+ UserUpdate = "USER_UPDATE",
101
+ UserLogin = "USER_LOGIN",
102
+ WarehouseCreate = "WAREHOUSE_CREATE",
103
+ WarehouseUpdate = "WAREHOUSE_UPDATE",
104
+ QuoteItemUpdate = "QUOTE_ITEM_UPDATE",
105
+ QuoteItemCreate = "QUOTE_ITEM_CREATE",
106
+ UserPointOfSaleCreate = "USER_POINT_OF_SALE_CREATE",
107
+ UserPointOfSaleUpdate = "USER_POINT_OF_SALE_UPDATE",
108
+ ExpenseCreate = "EXPENSE_CREATE",
109
+ ExpenseUpdate = "EXPENSE_UPDATE",
110
+ ExpenseItemCreate = "EXPENSE_ITEM_CREATE",
111
+ ExpenseItemUpdate = "EXPENSE_ITEM_UPDATE",
112
+ SectionCreate = "SECTION_CREATE",
113
+ SectionUpdate = "SECTION_UPDATE",
114
+ QuoteOptionCreate = "QUOTE_OPTION_CREATE",
115
+ QuoteOptionUpdate = "QUOTE_OPTION_UPDATE",
116
+ ApplicationSectionCreate = "APPLICATION_SECTION_CREATE",
117
+ ApplicationSectionUpdate = "APPLICATION_SECTION_UPDATE",
118
+ ApplicationSectionDelete = "APPLICATION_SECTION_DELETE",
119
+ QuoteConfirmed = "QUOTE_CONFIRMED",
120
+ ProjectCreate = "PROJECT_CREATE",
121
+ ProjectUpdate = "PROJECT_UPDATE",
122
+ ProjectDelete = "PROJECT_DELETE",
123
+ PipelineCreate = "PIPELINE_CREATE",
124
+ PipelineUpdate = "PIPELINE_UPDATE",
125
+ PipelineDelete = "PIPELINE_DELETE",
126
+ TaskCreate = "TASK_CREATE",
127
+ TaskUpdate = "TASK_UPDATE",
128
+ TaskDelete = "TASK_DELETE",
129
+ NoteCreate = "NOTE_CREATE",
130
+ NoteUpdate = "NOTE_UPDATE",
131
+ NoteDelete = "NOTE_DELETE"
67
132
  }
68
133
  /**
69
134
  * Transaction direction enum
@@ -105,7 +170,6 @@ export declare enum ExportExtEnum {
105
170
  }
106
171
  /**
107
172
  * Currency codes used in the system
108
- * @see https://en.wikipedia.org/wiki/ISO_4217
109
173
  */
110
174
  export declare enum CurrencyEnum {
111
175
  USD = "USD",
package/enum/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatusEnum = exports.QuoteStatusEnum = exports.PricingTypeEnum = exports.UserStatusEnum = exports.ApplicationSectionModuleEnum = exports.PagesProviderEnum = exports.PrivatePublicEnum = exports.StatusQuoteItemEnum = exports.ContributorRoleEnum = exports.QuoteSignedViewEnum = exports.CurrencyEnum = exports.ExportExtEnum = exports.SortOrderEnum = exports.BooleanStringEnum = exports.TransactionModelEnum = exports.TransactionDirectionEnum = exports.QueryTypeEnum = exports.ProductTypeEnum = exports.PaymentMethodEnum = exports.DiscountTypeEnum = exports.CustomerTypeEnum = void 0;
3
+ exports.StatusEnum = exports.QuoteStatusEnum = exports.PricingTypeEnum = exports.UserStatusEnum = exports.ApplicationSectionModuleEnum = exports.PagesProviderEnum = exports.PrivatePublicEnum = exports.StatusQuoteItemEnum = exports.ContributorRoleEnum = exports.QuoteSignedViewEnum = exports.CurrencyEnum = exports.ExportExtEnum = exports.SortOrderEnum = exports.BooleanStringEnum = exports.TransactionModelEnum = exports.TransactionDirectionEnum = exports.ActivityModelEnum = exports.QueryTypeEnum = exports.ProductTypeEnum = exports.PaymentMethodEnum = exports.DiscountTypeEnum = exports.CustomerTypeEnum = void 0;
4
4
  /**
5
5
  * Customer type enum
6
6
  */
@@ -72,7 +72,73 @@ var QueryTypeEnum;
72
72
  QueryTypeEnum["ExpenseItem"] = "EXPENSEITEM";
73
73
  QueryTypeEnum["Organization"] = "ORGANIZATION";
74
74
  QueryTypeEnum["ApplicationSection"] = "APPLICATIONSECTION";
75
+ QueryTypeEnum["Task"] = "TASK";
76
+ QueryTypeEnum["Pipeline"] = "PIPELINE";
75
77
  })(QueryTypeEnum || (exports.QueryTypeEnum = QueryTypeEnum = {}));
78
+ /**
79
+ * Activity model enum
80
+ */
81
+ var ActivityModelEnum;
82
+ (function (ActivityModelEnum) {
83
+ ActivityModelEnum["ViewCount"] = "VIEW_COUNT";
84
+ ActivityModelEnum["ProductCreate"] = "PRODUCT_CREATE";
85
+ ActivityModelEnum["ProductUpdate"] = "PRODUCT_UPDATE";
86
+ ActivityModelEnum["CatalogCreate"] = "CATALOG_CREATE";
87
+ ActivityModelEnum["CatalogUpdate"] = "CATALOG_UPDATE";
88
+ ActivityModelEnum["VariantCreate"] = "VARIANT_CREATE";
89
+ ActivityModelEnum["VariantUpdate"] = "VARIANT_UPDATE";
90
+ ActivityModelEnum["CategoryCreate"] = "CATEGORY_CREATE";
91
+ ActivityModelEnum["CategoryUpdate"] = "CATEGORY_UPDATE";
92
+ ActivityModelEnum["BrandCreate"] = "BRAND_CREATE";
93
+ ActivityModelEnum["BrandUpdate"] = "BRAND_UPDATE";
94
+ ActivityModelEnum["AdditionCreate"] = "ADDITION_CREATE";
95
+ ActivityModelEnum["AdditionUpdate"] = "ADDITION_UPDATE";
96
+ ActivityModelEnum["DiscountCreate"] = "DISCOUNT_CREATE";
97
+ ActivityModelEnum["DiscountUpdate"] = "DISCOUNT_UPDATE";
98
+ ActivityModelEnum["UnitCreate"] = "UNIT_CREATE";
99
+ ActivityModelEnum["UnitUpdate"] = "UNIT_UPDATE";
100
+ ActivityModelEnum["OrderUpdate"] = "ORDER_UPDATE";
101
+ ActivityModelEnum["OrderConfirmed"] = "ORDER_CONFIRMED";
102
+ ActivityModelEnum["QuoteCreate"] = "QUOTE_CREATE";
103
+ ActivityModelEnum["QuoteUpdate"] = "QUOTE_UPDATE";
104
+ ActivityModelEnum["OrderItemCreate"] = "ORDER_ITEM_CREATE";
105
+ ActivityModelEnum["OrderItemUpdate"] = "ORDER_ITEM_UPDATE";
106
+ ActivityModelEnum["PointOfSaleCreate"] = "POINT_OF_SALE_CREATE";
107
+ ActivityModelEnum["PointOfSaleUpdate"] = "POINT_OF_SALE_UPDATE";
108
+ ActivityModelEnum["UserCreate"] = "USER_CREATE";
109
+ ActivityModelEnum["UserUpdate"] = "USER_UPDATE";
110
+ ActivityModelEnum["UserLogin"] = "USER_LOGIN";
111
+ ActivityModelEnum["WarehouseCreate"] = "WAREHOUSE_CREATE";
112
+ ActivityModelEnum["WarehouseUpdate"] = "WAREHOUSE_UPDATE";
113
+ ActivityModelEnum["QuoteItemUpdate"] = "QUOTE_ITEM_UPDATE";
114
+ ActivityModelEnum["QuoteItemCreate"] = "QUOTE_ITEM_CREATE";
115
+ ActivityModelEnum["UserPointOfSaleCreate"] = "USER_POINT_OF_SALE_CREATE";
116
+ ActivityModelEnum["UserPointOfSaleUpdate"] = "USER_POINT_OF_SALE_UPDATE";
117
+ ActivityModelEnum["ExpenseCreate"] = "EXPENSE_CREATE";
118
+ ActivityModelEnum["ExpenseUpdate"] = "EXPENSE_UPDATE";
119
+ ActivityModelEnum["ExpenseItemCreate"] = "EXPENSE_ITEM_CREATE";
120
+ ActivityModelEnum["ExpenseItemUpdate"] = "EXPENSE_ITEM_UPDATE";
121
+ ActivityModelEnum["SectionCreate"] = "SECTION_CREATE";
122
+ ActivityModelEnum["SectionUpdate"] = "SECTION_UPDATE";
123
+ ActivityModelEnum["QuoteOptionCreate"] = "QUOTE_OPTION_CREATE";
124
+ ActivityModelEnum["QuoteOptionUpdate"] = "QUOTE_OPTION_UPDATE";
125
+ ActivityModelEnum["ApplicationSectionCreate"] = "APPLICATION_SECTION_CREATE";
126
+ ActivityModelEnum["ApplicationSectionUpdate"] = "APPLICATION_SECTION_UPDATE";
127
+ ActivityModelEnum["ApplicationSectionDelete"] = "APPLICATION_SECTION_DELETE";
128
+ ActivityModelEnum["QuoteConfirmed"] = "QUOTE_CONFIRMED";
129
+ ActivityModelEnum["ProjectCreate"] = "PROJECT_CREATE";
130
+ ActivityModelEnum["ProjectUpdate"] = "PROJECT_UPDATE";
131
+ ActivityModelEnum["ProjectDelete"] = "PROJECT_DELETE";
132
+ ActivityModelEnum["PipelineCreate"] = "PIPELINE_CREATE";
133
+ ActivityModelEnum["PipelineUpdate"] = "PIPELINE_UPDATE";
134
+ ActivityModelEnum["PipelineDelete"] = "PIPELINE_DELETE";
135
+ ActivityModelEnum["TaskCreate"] = "TASK_CREATE";
136
+ ActivityModelEnum["TaskUpdate"] = "TASK_UPDATE";
137
+ ActivityModelEnum["TaskDelete"] = "TASK_DELETE";
138
+ ActivityModelEnum["NoteCreate"] = "NOTE_CREATE";
139
+ ActivityModelEnum["NoteUpdate"] = "NOTE_UPDATE";
140
+ ActivityModelEnum["NoteDelete"] = "NOTE_DELETE";
141
+ })(ActivityModelEnum || (exports.ActivityModelEnum = ActivityModelEnum = {}));
76
142
  /**
77
143
  * Transaction direction enum
78
144
  */
@@ -118,7 +184,6 @@ var ExportExtEnum;
118
184
  })(ExportExtEnum || (exports.ExportExtEnum = ExportExtEnum = {}));
119
185
  /**
120
186
  * Currency codes used in the system
121
- * @see https://en.wikipedia.org/wiki/ISO_4217
122
187
  */
123
188
  var CurrencyEnum;
124
189
  (function (CurrencyEnum) {
@@ -1,10 +1,46 @@
1
+ /**
2
+ * @example
3
+ * fromCents(2300) // 23
4
+ */
1
5
  export declare const fromCents: (value: number | string) => number;
6
+ /**
7
+ * @example
8
+ * toCents(23) // 2300
9
+ */
2
10
  export declare const toCents: (value: number | string) => number;
11
+ /**
12
+ * @example
13
+ * calculVat({ value: 2300, percentage: 20 }) // 460
14
+ */
3
15
  export declare const calculVat: ({ value, percentage, }: {
4
16
  value: number;
5
17
  percentage: number;
6
18
  }) => number;
19
+ /**
20
+ * @example
21
+ * calculDiscount({ value: 2300, percentage: 20 }) // 460
22
+ */
7
23
  export declare const calculDiscount: ({ value, percentage, }: {
8
24
  value: number;
9
25
  percentage: number;
10
26
  }) => number;
27
+ interface Props {
28
+ value: number;
29
+ isDivide?: boolean;
30
+ currency: string;
31
+ locale?: string;
32
+ }
33
+ /**
34
+ * @example
35
+ * formatePrice({ value: 2300, currency: 'EUR', locale: 'fr' }) // 23.00 €
36
+ */
37
+ export declare const formatePrice: ({ value, currency, locale, isDivide, }: Props) => string;
38
+ /**
39
+ * @example
40
+ * formatPercent({ value: 20, locale: 'fr' }) // 20%
41
+ */
42
+ export declare const formatPercent: ({ value, locale, }: {
43
+ value: number;
44
+ locale: string;
45
+ }) => string;
46
+ export {};
@@ -1,11 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculDiscount = exports.calculVat = exports.toCents = exports.fromCents = void 0;
3
+ exports.formatPercent = exports.formatePrice = exports.calculDiscount = exports.calculVat = exports.toCents = exports.fromCents = void 0;
4
+ /**
5
+ * @example
6
+ * fromCents(2300) // 23
7
+ */
4
8
  const fromCents = (value) => Number(value) / 100;
5
9
  exports.fromCents = fromCents;
10
+ /**
11
+ * @example
12
+ * toCents(23) // 2300
13
+ */
6
14
  const toCents = (value) => Number(value) * 100;
7
15
  exports.toCents = toCents;
16
+ /**
17
+ * @example
18
+ * calculVat({ value: 2300, percentage: 20 }) // 460
19
+ */
8
20
  const calculVat = ({ value, percentage, }) => (percentage > 0 ? value * (0, exports.fromCents)(percentage) : 0);
9
21
  exports.calculVat = calculVat;
22
+ /**
23
+ * @example
24
+ * calculDiscount({ value: 2300, percentage: 20 }) // 460
25
+ */
10
26
  const calculDiscount = ({ value, percentage, }) => (percentage > 0 ? (0, exports.fromCents)(value * percentage) : 0);
11
27
  exports.calculDiscount = calculDiscount;
28
+ /**
29
+ * @example
30
+ * formatePrice({ value: 2300, currency: 'EUR', locale: 'fr' }) // 23.00 €
31
+ */
32
+ const formatePrice = ({ value, currency, locale = "en", isDivide = false, }) => {
33
+ if (isNaN(value))
34
+ return "—";
35
+ const numberCal = isDivide ? (0, exports.fromCents)(value) : value;
36
+ const lang = ["fr", "it"].includes(locale.toLowerCase()) ? "de" : locale;
37
+ return new Intl.NumberFormat(lang, {
38
+ currency,
39
+ style: "currency",
40
+ notation: "standard",
41
+ maximumFractionDigits: 1,
42
+ }).format(numberCal);
43
+ };
44
+ exports.formatePrice = formatePrice;
45
+ /**
46
+ * @example
47
+ * formatPercent({ value: 20, locale: 'fr' }) // 20%
48
+ */
49
+ const formatPercent = ({ value, locale, }) => {
50
+ return new Intl.NumberFormat(locale, {
51
+ style: "percent",
52
+ notation: "standard",
53
+ maximumFractionDigits: 1,
54
+ }).format(value / 100);
55
+ };
56
+ exports.formatPercent = formatPercent;
@@ -22,4 +22,12 @@ describe("Utils", () => {
22
22
  expect(result).toEqual(20);
23
23
  expect(result).not.toBeNull();
24
24
  });
25
+ test("formatePrice", () => {
26
+ const result = (0, index_1.formatePrice)({ value: 2, currency: "EUR", locale: "fr" });
27
+ expect(result.toString()).not.toBeNull();
28
+ });
29
+ test("formatPercent", () => {
30
+ const result = (0, index_1.formatPercent)({ value: 20, locale: "fr" });
31
+ expect(result).not.toBeNull();
32
+ });
25
33
  });
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.25","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"date-fns":"^4.1.0","luxon":"^3.7.2"}}
1
+ {"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.27","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"date-fns":"^4.3.0","luxon":"^3.7.2"}}