@jsdev_ninja/core 0.12.11 → 0.13.14
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/core.cjs.js +1 -1
- package/dist/core.cjs.js.map +1 -1
- package/dist/core.es.js +283 -235
- package/dist/core.es.js.map +1 -1
- package/dist/core.umd.js +1 -1
- package/dist/core.umd.js.map +1 -1
- package/dist/entities/DeliveryNote.d.ts +134 -0
- package/dist/entities/DeliveryNote.d.ts.map +1 -0
- package/dist/entities/DeliveryNote.js +34 -0
- package/dist/entities/Discount/engine.d.ts.map +1 -1
- package/dist/entities/Discount/engine.js +15 -10
- package/dist/entities/Order.d.ts +10 -0
- package/dist/entities/Order.d.ts.map +1 -1
- package/dist/entities/Order.js +1 -0
- package/dist/entities/Organization.d.ts +34 -0
- package/dist/entities/Organization.d.ts.map +1 -0
- package/dist/entities/Organization.js +9 -0
- package/dist/entities/Profile.d.ts +3 -0
- package/dist/entities/Profile.d.ts.map +1 -1
- package/dist/entities/Profile.js +1 -0
- package/dist/entities/Store.d.ts +2 -2
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +2 -0
- package/dist/firebase-api/index.d.ts +3 -0
- package/dist/firebase-api/index.d.ts.map +1 -1
- package/dist/firebase-api/index.js +1 -0
- package/dist/tsconfig.app.tsbuildinfo +1 -1
- package/lib/entities/DeliveryNote.ts +42 -0
- package/lib/entities/Discount/engine.ts +134 -125
- package/lib/entities/Order.ts +1 -0
- package/lib/entities/Organization.ts +14 -0
- package/lib/entities/Profile.ts +1 -0
- package/lib/entities/index.ts +2 -0
- package/lib/firebase-api/index.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CalculatedDataSchema: z.ZodObject<{
|
|
3
|
+
_COMMENT: z.ZodOptional<z.ZodString>;
|
|
4
|
+
transaction_id: z.ZodString;
|
|
5
|
+
date: z.ZodString;
|
|
6
|
+
currency: z.ZodString;
|
|
7
|
+
rate: z.ZodNumber;
|
|
8
|
+
vat: z.ZodString;
|
|
9
|
+
vat_price: z.ZodNumber;
|
|
10
|
+
price_discount: z.ZodNumber;
|
|
11
|
+
price_discount_in_currency: z.ZodNumber;
|
|
12
|
+
price_total: z.ZodString;
|
|
13
|
+
price_total_in_currency: z.ZodNumber;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
date: string;
|
|
16
|
+
vat: string;
|
|
17
|
+
currency: string;
|
|
18
|
+
transaction_id: string;
|
|
19
|
+
rate: number;
|
|
20
|
+
vat_price: number;
|
|
21
|
+
price_discount: number;
|
|
22
|
+
price_discount_in_currency: number;
|
|
23
|
+
price_total: string;
|
|
24
|
+
price_total_in_currency: number;
|
|
25
|
+
_COMMENT?: string | undefined;
|
|
26
|
+
}, {
|
|
27
|
+
date: string;
|
|
28
|
+
vat: string;
|
|
29
|
+
currency: string;
|
|
30
|
+
transaction_id: string;
|
|
31
|
+
rate: number;
|
|
32
|
+
vat_price: number;
|
|
33
|
+
price_discount: number;
|
|
34
|
+
price_discount_in_currency: number;
|
|
35
|
+
price_total: string;
|
|
36
|
+
price_total_in_currency: number;
|
|
37
|
+
_COMMENT?: string | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
export declare const DeliveryNoteSchema: z.ZodObject<{
|
|
40
|
+
doc_uuid: z.ZodString;
|
|
41
|
+
pdf_link: z.ZodString;
|
|
42
|
+
pdf_link_copy: z.ZodString;
|
|
43
|
+
doc_number: z.ZodString;
|
|
44
|
+
sent_mails: z.ZodArray<z.ZodString, "many">;
|
|
45
|
+
success: z.ZodBoolean;
|
|
46
|
+
ua_uuid: z.ZodString;
|
|
47
|
+
calculatedData: z.ZodObject<{
|
|
48
|
+
_COMMENT: z.ZodOptional<z.ZodString>;
|
|
49
|
+
transaction_id: z.ZodString;
|
|
50
|
+
date: z.ZodString;
|
|
51
|
+
currency: z.ZodString;
|
|
52
|
+
rate: z.ZodNumber;
|
|
53
|
+
vat: z.ZodString;
|
|
54
|
+
vat_price: z.ZodNumber;
|
|
55
|
+
price_discount: z.ZodNumber;
|
|
56
|
+
price_discount_in_currency: z.ZodNumber;
|
|
57
|
+
price_total: z.ZodString;
|
|
58
|
+
price_total_in_currency: z.ZodNumber;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
date: string;
|
|
61
|
+
vat: string;
|
|
62
|
+
currency: string;
|
|
63
|
+
transaction_id: string;
|
|
64
|
+
rate: number;
|
|
65
|
+
vat_price: number;
|
|
66
|
+
price_discount: number;
|
|
67
|
+
price_discount_in_currency: number;
|
|
68
|
+
price_total: string;
|
|
69
|
+
price_total_in_currency: number;
|
|
70
|
+
_COMMENT?: string | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
date: string;
|
|
73
|
+
vat: string;
|
|
74
|
+
currency: string;
|
|
75
|
+
transaction_id: string;
|
|
76
|
+
rate: number;
|
|
77
|
+
vat_price: number;
|
|
78
|
+
price_discount: number;
|
|
79
|
+
price_discount_in_currency: number;
|
|
80
|
+
price_total: string;
|
|
81
|
+
price_total_in_currency: number;
|
|
82
|
+
_COMMENT?: string | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
warning: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
|
+
doc_uuid: string;
|
|
87
|
+
pdf_link: string;
|
|
88
|
+
pdf_link_copy: string;
|
|
89
|
+
doc_number: string;
|
|
90
|
+
sent_mails: string[];
|
|
91
|
+
success: boolean;
|
|
92
|
+
ua_uuid: string;
|
|
93
|
+
calculatedData: {
|
|
94
|
+
date: string;
|
|
95
|
+
vat: string;
|
|
96
|
+
currency: string;
|
|
97
|
+
transaction_id: string;
|
|
98
|
+
rate: number;
|
|
99
|
+
vat_price: number;
|
|
100
|
+
price_discount: number;
|
|
101
|
+
price_discount_in_currency: number;
|
|
102
|
+
price_total: string;
|
|
103
|
+
price_total_in_currency: number;
|
|
104
|
+
_COMMENT?: string | undefined;
|
|
105
|
+
};
|
|
106
|
+
warning?: string | undefined;
|
|
107
|
+
}, {
|
|
108
|
+
doc_uuid: string;
|
|
109
|
+
pdf_link: string;
|
|
110
|
+
pdf_link_copy: string;
|
|
111
|
+
doc_number: string;
|
|
112
|
+
sent_mails: string[];
|
|
113
|
+
success: boolean;
|
|
114
|
+
ua_uuid: string;
|
|
115
|
+
calculatedData: {
|
|
116
|
+
date: string;
|
|
117
|
+
vat: string;
|
|
118
|
+
currency: string;
|
|
119
|
+
transaction_id: string;
|
|
120
|
+
rate: number;
|
|
121
|
+
vat_price: number;
|
|
122
|
+
price_discount: number;
|
|
123
|
+
price_discount_in_currency: number;
|
|
124
|
+
price_total: string;
|
|
125
|
+
price_total_in_currency: number;
|
|
126
|
+
_COMMENT?: string | undefined;
|
|
127
|
+
};
|
|
128
|
+
warning?: string | undefined;
|
|
129
|
+
}>;
|
|
130
|
+
export type TDeliveryNote = z.infer<typeof DeliveryNoteSchema>;
|
|
131
|
+
export type TCalculatedData = z.infer<typeof CalculatedDataSchema>;
|
|
132
|
+
export declare function isDeliveryNote(data: unknown): data is TDeliveryNote;
|
|
133
|
+
export declare function isCalculatedData(data: unknown): data is TCalculatedData;
|
|
134
|
+
//# sourceMappingURL=DeliveryNote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeliveryNote.d.ts","sourceRoot":"","sources":["../../lib/entities/DeliveryNote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAY/B,CAAC;AAGH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAU7B,CAAC;AAGH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC/D,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAGnE,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,aAAa,CAEnE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,eAAe,CAEvE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// Schema for the calculated data section
|
|
3
|
+
export const CalculatedDataSchema = z.object({
|
|
4
|
+
_COMMENT: z.string().optional(),
|
|
5
|
+
transaction_id: z.string(),
|
|
6
|
+
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format"),
|
|
7
|
+
currency: z.string().length(3, "Currency must be 3 characters"),
|
|
8
|
+
rate: z.number().positive(),
|
|
9
|
+
vat: z.string().regex(/^\d+\.\d{2}$/, "VAT must be in format XX.XX"),
|
|
10
|
+
vat_price: z.number().positive(),
|
|
11
|
+
price_discount: z.number(),
|
|
12
|
+
price_discount_in_currency: z.number(),
|
|
13
|
+
price_total: z.string().regex(/^\d+\.\d{2}$/, "Price total must be in format XX.XX"),
|
|
14
|
+
price_total_in_currency: z.number().positive(),
|
|
15
|
+
});
|
|
16
|
+
// Main DeliveryNote schema
|
|
17
|
+
export const DeliveryNoteSchema = z.object({
|
|
18
|
+
doc_uuid: z.string().uuid("Document UUID must be a valid UUID"),
|
|
19
|
+
pdf_link: z.string().url("PDF link must be a valid URL"),
|
|
20
|
+
pdf_link_copy: z.string().url("PDF copy link must be a valid URL"),
|
|
21
|
+
doc_number: z.string().min(1, "Document number is required"),
|
|
22
|
+
sent_mails: z.array(z.string().email("Each email must be valid")),
|
|
23
|
+
success: z.boolean(),
|
|
24
|
+
ua_uuid: z.string().uuid("UA UUID must be a valid UUID"),
|
|
25
|
+
calculatedData: CalculatedDataSchema,
|
|
26
|
+
warning: z.string().optional(),
|
|
27
|
+
});
|
|
28
|
+
// Validation functions
|
|
29
|
+
export function isDeliveryNote(data) {
|
|
30
|
+
return DeliveryNoteSchema.safeParse(data).success;
|
|
31
|
+
}
|
|
32
|
+
export function isCalculatedData(data) {
|
|
33
|
+
return CalculatedDataSchema.safeParse(data).success;
|
|
34
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../lib/entities/Discount/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAmB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../lib/entities/Discount/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAmB,MAAM,SAAS,CAAC;AAYtE,qBAAa,cAAc;IAC1B,MAAM,CAAC,kBAAkB,CACxB,IAAI,EAAE,KAAK,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE;YACR,EAAE,EAAE,MAAM,CAAC;YACX,KAAK,EAAE,MAAM,CAAC;SACd,CAAC;KACF,CAAC,EACF,SAAS,EAAE,SAAS,EAAE,EACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B;QACF,KAAK,EAAE,KAAK,CAAC;YACZ,MAAM,EAAE,MAAM,CAAC;YACf,OAAO,EAAE;gBACR,EAAE,EAAE,MAAM,CAAC;gBACX,KAAK,EAAE,MAAM,CAAC;aACd,CAAC;YACF,aAAa,EAAE,MAAM,CAAC;YACtB,UAAU,EAAE,MAAM,CAAC;YACnB,aAAa,EAAE,MAAM,CAAC;YACtB,gBAAgB,EAAE,MAAM,EAAE,CAAC;SAC3B,CAAC,CAAC;QACH,aAAa,EAAE,MAAM,CAAC;QACtB,gBAAgB,EAAE,eAAe,EAAE,CAAC;KACpC;IAuDD,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAOpC,OAAO,CAAC,MAAM,CAAC,oBAAoB;IA8BnC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO;IAKrD,MAAM,CAAC,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE;CAG9D"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { DiscountStrategyFactory } from "./factory";
|
|
2
|
+
// discount engine - calculate discounts and return final prices
|
|
3
|
+
// should register all discount types
|
|
4
|
+
// should receive all store discounts
|
|
5
|
+
// should check active discount that should be applied on cart
|
|
6
|
+
// should find best discount per product
|
|
7
|
+
// should apply discount to if stackable or best one
|
|
8
|
+
// any applyd discount should mark products that effected and price before and after and average price per product in cart
|
|
9
|
+
// should return items list with all calculations and final prices and discounts
|
|
2
10
|
export class DiscountEngine {
|
|
3
11
|
static calculateDiscounts(cart, discounts, user) {
|
|
4
12
|
const context = {
|
|
@@ -18,6 +26,7 @@ export class DiscountEngine {
|
|
|
18
26
|
if (!strategy.canApply(discount, context))
|
|
19
27
|
continue;
|
|
20
28
|
// Check if discount is stackable
|
|
29
|
+
// todo
|
|
21
30
|
if (!discount.conditions?.stackable && appliedDiscounts.length > 0)
|
|
22
31
|
continue;
|
|
23
32
|
// Calculate discount
|
|
@@ -45,15 +54,13 @@ export class DiscountEngine {
|
|
|
45
54
|
}
|
|
46
55
|
static filterActiveDiscounts(discounts) {
|
|
47
56
|
const now = Date.now();
|
|
48
|
-
return discounts.filter(discount => discount.active &&
|
|
49
|
-
discount.startDate <= now &&
|
|
50
|
-
discount.endDate >= now);
|
|
57
|
+
return discounts.filter((discount) => discount.active && discount.startDate <= now && discount.endDate >= now);
|
|
51
58
|
}
|
|
52
59
|
static calculateFinalPrices(cart, appliedDiscounts) {
|
|
53
|
-
return cart.map(item => {
|
|
54
|
-
const itemDiscounts = appliedDiscounts.filter(discount => discount.affectedItems.some(affected => affected.productId === item.product.id));
|
|
60
|
+
return cart.map((item) => {
|
|
61
|
+
const itemDiscounts = appliedDiscounts.filter((discount) => discount.affectedItems.some((affected) => affected.productId === item.product.id));
|
|
55
62
|
const totalItemDiscount = itemDiscounts.reduce((sum, discount) => {
|
|
56
|
-
const affectedItem = discount.affectedItems.find(affected => affected.productId === item.product.id);
|
|
63
|
+
const affectedItem = discount.affectedItems.find((affected) => affected.productId === item.product.id);
|
|
57
64
|
return sum + (affectedItem?.discountAmount || 0);
|
|
58
65
|
}, 0);
|
|
59
66
|
const discountPerUnit = totalItemDiscount / item.amount;
|
|
@@ -64,15 +71,13 @@ export class DiscountEngine {
|
|
|
64
71
|
originalPrice: Number(item.product.price.toFixed(2)),
|
|
65
72
|
finalPrice: Number(Math.max(0, finalPrice).toFixed(2)),
|
|
66
73
|
finalDiscount: Number(totalItemDiscount.toFixed(2)),
|
|
67
|
-
appliedDiscounts: itemDiscounts.map(d => d.discountId),
|
|
74
|
+
appliedDiscounts: itemDiscounts.map((d) => d.discountId),
|
|
68
75
|
};
|
|
69
76
|
});
|
|
70
77
|
}
|
|
71
78
|
static isDiscountActive(discount) {
|
|
72
79
|
const now = Date.now();
|
|
73
|
-
return discount.active &&
|
|
74
|
-
discount.startDate <= now &&
|
|
75
|
-
discount.endDate >= now;
|
|
80
|
+
return discount.active && discount.startDate <= now && discount.endDate >= now;
|
|
76
81
|
}
|
|
77
82
|
static getActiveDiscounts(discounts) {
|
|
78
83
|
return this.filterActiveDiscounts(discounts);
|
package/dist/entities/Order.d.ts
CHANGED
|
@@ -545,6 +545,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
545
545
|
cartDiscount: z.ZodNumber;
|
|
546
546
|
cartTotal: z.ZodNumber;
|
|
547
547
|
cartVat: z.ZodNumber;
|
|
548
|
+
deliveryPrice: z.ZodOptional<z.ZodNumber>;
|
|
548
549
|
}, "strip", z.ZodTypeAny, {
|
|
549
550
|
id: string;
|
|
550
551
|
items: {
|
|
@@ -643,6 +644,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
643
644
|
cartDiscount: number;
|
|
644
645
|
cartTotal: number;
|
|
645
646
|
cartVat: number;
|
|
647
|
+
deliveryPrice?: number | undefined;
|
|
646
648
|
}, {
|
|
647
649
|
id: string;
|
|
648
650
|
items: {
|
|
@@ -741,6 +743,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
741
743
|
cartDiscount: number;
|
|
742
744
|
cartTotal: number;
|
|
743
745
|
cartVat: number;
|
|
746
|
+
deliveryPrice?: number | undefined;
|
|
744
747
|
}>;
|
|
745
748
|
originalAmount: z.ZodOptional<z.ZodNumber>;
|
|
746
749
|
actualAmount: z.ZodOptional<z.ZodNumber>;
|
|
@@ -786,6 +789,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
786
789
|
createdDate: z.ZodNumber;
|
|
787
790
|
lastActivityDate: z.ZodNumber;
|
|
788
791
|
paymentType: z.ZodEnum<["default", "delayed"]>;
|
|
792
|
+
organizationId: z.ZodOptional<z.ZodString>;
|
|
789
793
|
}, "strip", z.ZodTypeAny, {
|
|
790
794
|
type: "Profile";
|
|
791
795
|
id: string;
|
|
@@ -810,6 +814,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
810
814
|
apartmentEnterNumber: string;
|
|
811
815
|
apartmentNumber: string;
|
|
812
816
|
} | undefined;
|
|
817
|
+
organizationId?: string | undefined;
|
|
813
818
|
}, {
|
|
814
819
|
type: "Profile";
|
|
815
820
|
id: string;
|
|
@@ -834,6 +839,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
834
839
|
apartmentEnterNumber: string;
|
|
835
840
|
apartmentNumber: string;
|
|
836
841
|
} | undefined;
|
|
842
|
+
organizationId?: string | undefined;
|
|
837
843
|
}>;
|
|
838
844
|
nameOnInvoice: z.ZodOptional<z.ZodString>;
|
|
839
845
|
clientComment: z.ZodOptional<z.ZodString>;
|
|
@@ -944,6 +950,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
944
950
|
cartDiscount: number;
|
|
945
951
|
cartTotal: number;
|
|
946
952
|
cartVat: number;
|
|
953
|
+
deliveryPrice?: number | undefined;
|
|
947
954
|
};
|
|
948
955
|
deliveryDate: number;
|
|
949
956
|
client: {
|
|
@@ -970,6 +977,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
970
977
|
apartmentEnterNumber: string;
|
|
971
978
|
apartmentNumber: string;
|
|
972
979
|
} | undefined;
|
|
980
|
+
organizationId?: string | undefined;
|
|
973
981
|
};
|
|
974
982
|
originalAmount?: number | undefined;
|
|
975
983
|
actualAmount?: number | undefined;
|
|
@@ -1082,6 +1090,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
1082
1090
|
cartDiscount: number;
|
|
1083
1091
|
cartTotal: number;
|
|
1084
1092
|
cartVat: number;
|
|
1093
|
+
deliveryPrice?: number | undefined;
|
|
1085
1094
|
};
|
|
1086
1095
|
deliveryDate: number;
|
|
1087
1096
|
client: {
|
|
@@ -1108,6 +1117,7 @@ export declare const OrderSchema: z.ZodObject<{
|
|
|
1108
1117
|
apartmentEnterNumber: string;
|
|
1109
1118
|
apartmentNumber: string;
|
|
1110
1119
|
} | undefined;
|
|
1120
|
+
organizationId?: string | undefined;
|
|
1111
1121
|
};
|
|
1112
1122
|
originalAmount?: number | undefined;
|
|
1113
1123
|
actualAmount?: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Order.d.ts","sourceRoot":"","sources":["../../lib/entities/Order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"Order.d.ts","sourceRoot":"","sources":["../../lib/entities/Order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCtB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
package/dist/entities/Order.js
CHANGED
|
@@ -31,6 +31,7 @@ export const OrderSchema = z.object({
|
|
|
31
31
|
cartDiscount: z.number(),
|
|
32
32
|
cartTotal: z.number(),
|
|
33
33
|
cartVat: z.number(),
|
|
34
|
+
deliveryPrice: z.number().optional(),
|
|
34
35
|
}),
|
|
35
36
|
originalAmount: z.number().positive().optional(), // what client pay
|
|
36
37
|
actualAmount: z.number().positive().optional(), // what store charge
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const OrganizationSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
discountPercentage: z.ZodOptional<z.ZodNumber>;
|
|
6
|
+
nameOnInvoice: z.ZodOptional<z.ZodString>;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
nameOnInvoice?: string | undefined;
|
|
11
|
+
discountPercentage?: number | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
nameOnInvoice?: string | undefined;
|
|
16
|
+
discountPercentage?: number | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const NewOrganizationSchema: z.ZodObject<Omit<{
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
discountPercentage: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
nameOnInvoice: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, "id">, "strip", z.ZodTypeAny, {
|
|
24
|
+
name: string;
|
|
25
|
+
nameOnInvoice?: string | undefined;
|
|
26
|
+
discountPercentage?: number | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
name: string;
|
|
29
|
+
nameOnInvoice?: string | undefined;
|
|
30
|
+
discountPercentage?: number | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
export type TNewOrganization = z.infer<typeof NewOrganizationSchema>;
|
|
33
|
+
export type TOrganization = z.infer<typeof OrganizationSchema>;
|
|
34
|
+
//# sourceMappingURL=Organization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Organization.d.ts","sourceRoot":"","sources":["../../lib/entities/Organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;EAK7B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;EAAwC,CAAC;AAE3E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACrE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// client organization for clients
|
|
3
|
+
export const OrganizationSchema = z.object({
|
|
4
|
+
id: z.string(),
|
|
5
|
+
name: z.string(),
|
|
6
|
+
discountPercentage: z.number().positive().min(0).max(100).optional(),
|
|
7
|
+
nameOnInvoice: z.string().optional(),
|
|
8
|
+
});
|
|
9
|
+
export const NewOrganizationSchema = OrganizationSchema.omit({ id: true });
|
|
@@ -41,6 +41,7 @@ export declare const ProfileSchema: z.ZodObject<{
|
|
|
41
41
|
createdDate: z.ZodNumber;
|
|
42
42
|
lastActivityDate: z.ZodNumber;
|
|
43
43
|
paymentType: z.ZodEnum<["default", "delayed"]>;
|
|
44
|
+
organizationId: z.ZodOptional<z.ZodString>;
|
|
44
45
|
}, "strip", z.ZodTypeAny, {
|
|
45
46
|
type: "Profile";
|
|
46
47
|
id: string;
|
|
@@ -65,6 +66,7 @@ export declare const ProfileSchema: z.ZodObject<{
|
|
|
65
66
|
apartmentEnterNumber: string;
|
|
66
67
|
apartmentNumber: string;
|
|
67
68
|
} | undefined;
|
|
69
|
+
organizationId?: string | undefined;
|
|
68
70
|
}, {
|
|
69
71
|
type: "Profile";
|
|
70
72
|
id: string;
|
|
@@ -89,6 +91,7 @@ export declare const ProfileSchema: z.ZodObject<{
|
|
|
89
91
|
apartmentEnterNumber: string;
|
|
90
92
|
apartmentNumber: string;
|
|
91
93
|
} | undefined;
|
|
94
|
+
organizationId?: string | undefined;
|
|
92
95
|
}>;
|
|
93
96
|
export type TProfile = z.infer<typeof ProfileSchema>;
|
|
94
97
|
export declare function createEmptyProfile(): TProfile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Profile.d.ts","sourceRoot":"","sources":["../../lib/entities/Profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,wBAAwB,mCAEnC,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE3E,eAAO,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"Profile.d.ts","sourceRoot":"","sources":["../../lib/entities/Profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,wBAAwB,mCAEnC,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE3E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBxB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAErD,wBAAgB,kBAAkB,IAAI,QAAQ,CAyB7C"}
|
package/dist/entities/Profile.js
CHANGED
package/dist/entities/Store.d.ts
CHANGED
|
@@ -25,9 +25,9 @@ export declare const StoreSchema: z.ZodObject<{
|
|
|
25
25
|
allowAnonymousClients: boolean;
|
|
26
26
|
isVatIncludedInPrice: boolean;
|
|
27
27
|
clientTypes: ("company" | "individual")[];
|
|
28
|
+
deliveryPrice?: number | undefined;
|
|
28
29
|
minimumOrder?: number | undefined;
|
|
29
30
|
freeDeliveryPrice?: number | undefined;
|
|
30
|
-
deliveryPrice?: number | undefined;
|
|
31
31
|
}, {
|
|
32
32
|
id: string;
|
|
33
33
|
companyId: string;
|
|
@@ -39,9 +39,9 @@ export declare const StoreSchema: z.ZodObject<{
|
|
|
39
39
|
allowAnonymousClients: boolean;
|
|
40
40
|
isVatIncludedInPrice: boolean;
|
|
41
41
|
clientTypes: ("company" | "individual")[];
|
|
42
|
+
deliveryPrice?: number | undefined;
|
|
42
43
|
minimumOrder?: number | undefined;
|
|
43
44
|
freeDeliveryPrice?: number | undefined;
|
|
44
|
-
deliveryPrice?: number | undefined;
|
|
45
45
|
}>;
|
|
46
46
|
export type TStore = z.infer<typeof StoreSchema>;
|
|
47
47
|
//# sourceMappingURL=Store.d.ts.map
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
package/dist/entities/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export declare const storeCollections: {
|
|
|
13
13
|
readonly payments: "payments";
|
|
14
14
|
readonly settings: "settings";
|
|
15
15
|
readonly discounts: "discounts";
|
|
16
|
+
readonly organizations: "organizations";
|
|
16
17
|
};
|
|
17
18
|
export declare const FirestoreApi: {
|
|
18
19
|
systemCollections: {
|
|
@@ -30,6 +31,7 @@ export declare const FirestoreApi: {
|
|
|
30
31
|
readonly payments: "payments";
|
|
31
32
|
readonly settings: "settings";
|
|
32
33
|
readonly discounts: "discounts";
|
|
34
|
+
readonly organizations: "organizations";
|
|
33
35
|
};
|
|
34
36
|
getPath: ({ companyId, storeId, collectionName, id, }: {
|
|
35
37
|
companyId: string;
|
|
@@ -56,6 +58,7 @@ export declare const FirebaseAPI: {
|
|
|
56
58
|
readonly payments: "payments";
|
|
57
59
|
readonly settings: "settings";
|
|
58
60
|
readonly discounts: "discounts";
|
|
61
|
+
readonly organizations: "organizations";
|
|
59
62
|
};
|
|
60
63
|
getPath: ({ companyId, storeId, collectionName, id, }: {
|
|
61
64
|
companyId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/firebase-api/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/firebase-api/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAYnB,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;2DASrB;QACF,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,MAAM,OAAO,gBAAgB,CAAC;QAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;KACZ;iCAI4B,MAAM,OAAO,gBAAgB;CAG1D,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;+DAdpB;YACF,SAAS,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,MAAM,CAAC;YAChB,cAAc,EAAE,MAAM,OAAO,gBAAgB,CAAC;YAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;SACZ;qCAI4B,MAAM,OAAO,gBAAgB;;CAO1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../lib/index.tsx","../lib/entities/address.ts","../lib/entities/atoms.ts","../lib/entities/cart.ts","../lib/entities/category.ts","../lib/entities/company.ts","../lib/entities/favoriteproduct.ts","../lib/entities/locale.ts","../lib/entities/order.ts","../lib/entities/product.ts","../lib/entities/profile.ts","../lib/entities/store.ts","../lib/entities/index.ts","../lib/entities/discount/engine.ts","../lib/entities/discount/factory.ts","../lib/entities/discount/index.ts","../lib/entities/discount/strategy.ts","../lib/entities/discount/types.ts","../lib/entities/discount/utils.ts","../lib/entities/discount/__tests__/engine.test.ts","../lib/entities/discount/__tests__/factory.test.ts","../lib/entities/discount/__tests__/integration.test.ts","../lib/entities/discount/__tests__/simple.test.ts","../lib/entities/discount/__tests__/utils.test.ts","../lib/entities/discount/strategies/bundlestrategy.ts","../lib/entities/discount/strategies/__tests__/bundlestrategy.test.ts","../lib/firebase-api/app.ts","../lib/firebase-api/index.ts","../lib/utils/index.ts"],"version":"5.7.3"}
|
|
1
|
+
{"root":["../lib/index.tsx","../lib/entities/address.ts","../lib/entities/atoms.ts","../lib/entities/cart.ts","../lib/entities/category.ts","../lib/entities/company.ts","../lib/entities/deliverynote.ts","../lib/entities/favoriteproduct.ts","../lib/entities/locale.ts","../lib/entities/order.ts","../lib/entities/organization.ts","../lib/entities/product.ts","../lib/entities/profile.ts","../lib/entities/store.ts","../lib/entities/index.ts","../lib/entities/discount/engine.ts","../lib/entities/discount/factory.ts","../lib/entities/discount/index.ts","../lib/entities/discount/strategy.ts","../lib/entities/discount/types.ts","../lib/entities/discount/utils.ts","../lib/entities/discount/__tests__/engine.test.ts","../lib/entities/discount/__tests__/factory.test.ts","../lib/entities/discount/__tests__/integration.test.ts","../lib/entities/discount/__tests__/simple.test.ts","../lib/entities/discount/__tests__/utils.test.ts","../lib/entities/discount/strategies/bundlestrategy.ts","../lib/entities/discount/strategies/__tests__/bundlestrategy.test.ts","../lib/firebase-api/app.ts","../lib/firebase-api/index.ts","../lib/utils/index.ts"],"version":"5.7.3"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
// Schema for the calculated data section
|
|
4
|
+
export const CalculatedDataSchema = z.object({
|
|
5
|
+
_COMMENT: z.string().optional(),
|
|
6
|
+
transaction_id: z.string(),
|
|
7
|
+
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format"),
|
|
8
|
+
currency: z.string().length(3, "Currency must be 3 characters"),
|
|
9
|
+
rate: z.number().positive(),
|
|
10
|
+
vat: z.string().regex(/^\d+\.\d{2}$/, "VAT must be in format XX.XX"),
|
|
11
|
+
vat_price: z.number().positive(),
|
|
12
|
+
price_discount: z.number(),
|
|
13
|
+
price_discount_in_currency: z.number(),
|
|
14
|
+
price_total: z.string().regex(/^\d+\.\d{2}$/, "Price total must be in format XX.XX"),
|
|
15
|
+
price_total_in_currency: z.number().positive(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Main DeliveryNote schema
|
|
19
|
+
export const DeliveryNoteSchema = z.object({
|
|
20
|
+
doc_uuid: z.string().uuid("Document UUID must be a valid UUID"),
|
|
21
|
+
pdf_link: z.string().url("PDF link must be a valid URL"),
|
|
22
|
+
pdf_link_copy: z.string().url("PDF copy link must be a valid URL"),
|
|
23
|
+
doc_number: z.string().min(1, "Document number is required"),
|
|
24
|
+
sent_mails: z.array(z.string().email("Each email must be valid")),
|
|
25
|
+
success: z.boolean(),
|
|
26
|
+
ua_uuid: z.string().uuid("UA UUID must be a valid UUID"),
|
|
27
|
+
calculatedData: CalculatedDataSchema,
|
|
28
|
+
warning: z.string().optional(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Type inference
|
|
32
|
+
export type TDeliveryNote = z.infer<typeof DeliveryNoteSchema>;
|
|
33
|
+
export type TCalculatedData = z.infer<typeof CalculatedDataSchema>;
|
|
34
|
+
|
|
35
|
+
// Validation functions
|
|
36
|
+
export function isDeliveryNote(data: unknown): data is TDeliveryNote {
|
|
37
|
+
return DeliveryNoteSchema.safeParse(data).success;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function isCalculatedData(data: unknown): data is TCalculatedData {
|
|
41
|
+
return CalculatedDataSchema.safeParse(data).success;
|
|
42
|
+
}
|