@jsdev_ninja/core 0.13.27 → 0.13.29
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 +2 -0
- package/dist/core.cjs.js.map +1 -0
- package/dist/core.es.js +3584 -0
- package/dist/core.es.js.map +1 -0
- package/dist/core.umd.js +2 -0
- package/dist/core.umd.js.map +1 -0
- package/dist/lib/entities/Address.d.ts +28 -0
- package/dist/lib/entities/Address.d.ts.map +1 -0
- package/dist/lib/entities/Address.js +10 -0
- package/dist/lib/entities/Atoms.d.ts +16 -0
- package/dist/lib/entities/Atoms.d.ts.map +1 -0
- package/{lib/entities/Atoms.ts → dist/lib/entities/Atoms.js} +2 -6
- package/dist/lib/entities/Cart.d.ts +1278 -0
- package/dist/lib/entities/Cart.d.ts.map +1 -0
- package/dist/lib/entities/Cart.js +18 -0
- package/dist/lib/entities/Category.d.ts +103 -0
- package/dist/lib/entities/Category.d.ts.map +1 -0
- package/dist/lib/entities/Category.js +20 -0
- package/dist/lib/entities/Company.d.ts +16 -0
- package/dist/lib/entities/Company.d.ts.map +1 -0
- package/dist/lib/entities/Company.js +6 -0
- package/dist/lib/entities/DeliveryNote.d.ts +248 -0
- package/dist/lib/entities/DeliveryNote.d.ts.map +1 -0
- package/dist/lib/entities/DeliveryNote.js +61 -0
- package/dist/lib/entities/Discount/__tests__/engine.test.d.ts +2 -0
- package/dist/lib/entities/Discount/__tests__/engine.test.d.ts.map +1 -0
- package/dist/lib/entities/Discount/__tests__/engine.test.js +298 -0
- package/dist/lib/entities/Discount/__tests__/factory.test.d.ts +2 -0
- package/dist/lib/entities/Discount/__tests__/factory.test.d.ts.map +1 -0
- package/dist/lib/entities/Discount/__tests__/factory.test.js +75 -0
- package/dist/lib/entities/Discount/__tests__/integration.test.d.ts +2 -0
- package/dist/lib/entities/Discount/__tests__/integration.test.d.ts.map +1 -0
- package/dist/lib/entities/Discount/__tests__/integration.test.js +115 -0
- package/dist/lib/entities/Discount/__tests__/simple.test.d.ts +2 -0
- package/dist/lib/entities/Discount/__tests__/simple.test.d.ts.map +1 -0
- package/dist/lib/entities/Discount/__tests__/simple.test.js +186 -0
- package/dist/lib/entities/Discount/__tests__/utils.test.d.ts +2 -0
- package/dist/lib/entities/Discount/__tests__/utils.test.d.ts.map +1 -0
- package/dist/lib/entities/Discount/__tests__/utils.test.js +55 -0
- package/dist/lib/entities/Discount/engine.d.ts +29 -0
- package/dist/lib/entities/Discount/engine.d.ts.map +1 -0
- package/dist/lib/entities/Discount/engine.js +85 -0
- package/dist/lib/entities/Discount/factory.d.ts +10 -0
- package/dist/lib/entities/Discount/factory.d.ts.map +1 -0
- package/dist/lib/entities/Discount/factory.js +18 -0
- package/dist/lib/entities/Discount/index.d.ts +9 -0
- package/dist/lib/entities/Discount/index.d.ts.map +1 -0
- package/{lib/entities/Discount/index.ts → dist/lib/entities/Discount/index.js} +0 -2
- package/dist/lib/entities/Discount/strategies/BundleStrategy.d.ts +12 -0
- package/dist/lib/entities/Discount/strategies/BundleStrategy.d.ts.map +1 -0
- package/dist/lib/entities/Discount/strategies/BundleStrategy.js +78 -0
- package/dist/lib/entities/Discount/strategies/__tests__/BundleStrategy.test.d.ts +2 -0
- package/dist/lib/entities/Discount/strategies/__tests__/BundleStrategy.test.d.ts.map +1 -0
- package/dist/lib/entities/Discount/strategies/__tests__/BundleStrategy.test.js +265 -0
- package/dist/lib/entities/Discount/strategy.d.ts +6 -0
- package/dist/lib/entities/Discount/strategy.d.ts.map +1 -0
- package/dist/lib/entities/Discount/types.d.ts +148 -0
- package/dist/lib/entities/Discount/types.d.ts.map +1 -0
- package/dist/lib/entities/Discount/types.js +29 -0
- package/dist/lib/entities/Discount/utils.d.ts +29 -0
- package/dist/lib/entities/Discount/utils.d.ts.map +1 -0
- package/{lib/entities/Discount/utils.ts → dist/lib/entities/Discount/utils.js} +12 -15
- package/dist/lib/entities/FavoriteProduct.d.ts +25 -0
- package/dist/lib/entities/FavoriteProduct.d.ts.map +1 -0
- package/dist/lib/entities/FavoriteProduct.js +9 -0
- package/dist/lib/entities/Invoice.d.ts +210 -0
- package/dist/lib/entities/Invoice.d.ts.map +1 -0
- package/dist/lib/entities/Invoice.js +49 -0
- package/dist/lib/entities/Locale.d.ts +22 -0
- package/dist/lib/entities/Locale.d.ts.map +1 -0
- package/{lib/entities/Locale.ts → dist/lib/entities/Locale.js} +2 -4
- package/dist/lib/entities/Order.d.ts +1806 -0
- package/dist/lib/entities/Order.d.ts.map +1 -0
- package/dist/lib/entities/Order.js +63 -0
- package/dist/lib/entities/Organization.d.ts +100 -0
- package/dist/lib/entities/Organization.d.ts.map +1 -0
- package/dist/lib/entities/Organization.js +17 -0
- package/dist/lib/entities/Payment/index.d.ts +4 -0
- package/dist/lib/entities/Payment/index.d.ts.map +1 -0
- package/dist/lib/entities/Payment/index.js +4 -0
- package/dist/lib/entities/Product.d.ts +694 -0
- package/dist/lib/entities/Product.d.ts.map +1 -0
- package/dist/lib/entities/Product.js +61 -0
- package/dist/lib/entities/Profile.d.ts +95 -0
- package/dist/lib/entities/Profile.d.ts.map +1 -0
- package/dist/lib/entities/Profile.js +22 -0
- package/dist/lib/entities/Store.d.ts +93 -0
- package/dist/lib/entities/Store.d.ts.map +1 -0
- package/dist/lib/entities/Store.js +21 -0
- package/dist/lib/entities/index.d.ts +16 -0
- package/dist/lib/entities/index.d.ts.map +1 -0
- package/{lib/entities/index.ts → dist/lib/entities/index.js} +1 -0
- package/dist/lib/firebase-api/app.d.ts +2 -0
- package/dist/lib/firebase-api/app.d.ts.map +1 -0
- package/dist/lib/firebase-api/app.js +16 -0
- package/dist/lib/firebase-api/index.d.ts +75 -0
- package/dist/lib/firebase-api/index.d.ts.map +1 -0
- package/dist/lib/firebase-api/index.js +33 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/utils/index.d.ts +109 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +95 -0
- package/dist/tsconfig.app.tsbuildinfo +1 -0
- package/dist/tsconfig.node.tsbuildinfo +1 -0
- package/dist/vite.config.d.ts +3 -0
- package/dist/vite.config.d.ts.map +1 -0
- package/dist/vite.config.js +25 -0
- package/package.json +8 -1
- package/eslint.config.js +0 -28
- package/index.html +0 -13
- package/lib/entities/Address.ts +0 -13
- package/lib/entities/Cart.ts +0 -24
- package/lib/entities/Category.ts +0 -35
- package/lib/entities/Company.ts +0 -9
- package/lib/entities/DeliveryNote.ts +0 -70
- package/lib/entities/Discount/__tests__/engine.test.ts +0 -337
- package/lib/entities/Discount/__tests__/factory.test.ts +0 -91
- package/lib/entities/Discount/__tests__/integration.test.ts +0 -132
- package/lib/entities/Discount/__tests__/simple.test.ts +0 -215
- package/lib/entities/Discount/__tests__/utils.test.ts +0 -69
- package/lib/entities/Discount/engine.ts +0 -138
- package/lib/entities/Discount/factory.ts +0 -25
- package/lib/entities/Discount/strategies/BundleStrategy.ts +0 -119
- package/lib/entities/Discount/strategies/__tests__/BundleStrategy.test.ts +0 -295
- package/lib/entities/Discount/strategy.ts +0 -6
- package/lib/entities/Discount/types.ts +0 -68
- package/lib/entities/FavoriteProduct.ts +0 -12
- package/lib/entities/Invoice.ts +0 -57
- package/lib/entities/Order.ts +0 -67
- package/lib/entities/Organization.ts +0 -23
- package/lib/entities/Product.ts +0 -68
- package/lib/entities/Profile.ts +0 -56
- package/lib/entities/Store.ts +0 -24
- package/lib/firebase-api/app.ts +0 -18
- package/lib/firebase-api/index.ts +0 -46
- package/lib/utils/index.ts +0 -127
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.app.json +0 -20
- package/tsconfig.json +0 -7
- package/tsconfig.node.json +0 -26
- package/vite.config.ts +0 -27
- package/vitest.config.ts +0 -10
- /package/{src/main.tsx → dist/lib/entities/Discount/strategy.js} +0 -0
- /package/{lib/index.tsx → dist/lib/index.js} +0 -0
package/lib/firebase-api/app.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Import the functions you need from the SDKs you need
|
|
2
|
-
import { initializeApp } from "firebase/app";
|
|
3
|
-
// Your web app's Firebase configuration
|
|
4
|
-
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
|
|
5
|
-
const firebaseConfig = {
|
|
6
|
-
apiKey: "AIzaSyAXtA4pdBs7GLX45lK3jYZRiUwo7M06-_s",
|
|
7
|
-
authDomain: "jsdev-stores-prod.firebaseapp.com",
|
|
8
|
-
projectId: "jsdev-stores-prod",
|
|
9
|
-
storageBucket: "jsdev-stores-prod.appspot.com",
|
|
10
|
-
messagingSenderId: "333321054844",
|
|
11
|
-
appId: "1:333321054844:web:7d3c15617daa54107537f9",
|
|
12
|
-
measurementId: "G-CJ44QNETK8",
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// Initialize Firebase
|
|
16
|
-
export const app = initializeApp(firebaseConfig);
|
|
17
|
-
|
|
18
|
-
// TESTER
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export const systemCollections = {
|
|
2
|
-
stores: "STORES",
|
|
3
|
-
companies: "COMPANIES",
|
|
4
|
-
} as const;
|
|
5
|
-
|
|
6
|
-
export const storeCollections = {
|
|
7
|
-
products: "products",
|
|
8
|
-
profiles: "profiles",
|
|
9
|
-
cart: "cart",
|
|
10
|
-
clients: "clients",
|
|
11
|
-
orders: "orders",
|
|
12
|
-
categories: "categories",
|
|
13
|
-
favorites: "favorites",
|
|
14
|
-
payments: "payments",
|
|
15
|
-
settings: "settings",
|
|
16
|
-
discounts: "discounts",
|
|
17
|
-
organizations: "organizations",
|
|
18
|
-
invoices: "invoices",
|
|
19
|
-
} as const;
|
|
20
|
-
|
|
21
|
-
export const FirestoreApi = {
|
|
22
|
-
systemCollections,
|
|
23
|
-
storeCollections,
|
|
24
|
-
// for client and server
|
|
25
|
-
getPath: ({
|
|
26
|
-
companyId,
|
|
27
|
-
storeId,
|
|
28
|
-
collectionName,
|
|
29
|
-
id,
|
|
30
|
-
}: {
|
|
31
|
-
companyId: string;
|
|
32
|
-
storeId: string;
|
|
33
|
-
collectionName: keyof typeof storeCollections;
|
|
34
|
-
id?: string;
|
|
35
|
-
}) => {
|
|
36
|
-
return `${companyId}/${storeId}/${collectionName}${id ? `/${id}` : ""}`;
|
|
37
|
-
},
|
|
38
|
-
// for firestore events
|
|
39
|
-
getDocPath: (collectionName: keyof typeof storeCollections) => {
|
|
40
|
-
return `{companyId}/{storeId}/${collectionName}/{id}`;
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const FirebaseAPI = {
|
|
45
|
-
firestore: FirestoreApi,
|
|
46
|
-
};
|
package/lib/utils/index.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { TCart, TDiscount, TProduct, TStore } from "../entities";
|
|
2
|
-
import { DiscountEngine } from "../entities/Discount/engine";
|
|
3
|
-
|
|
4
|
-
const CONFIG = {
|
|
5
|
-
VAT: 18,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
function calculateDiscount(product: TProduct) {
|
|
9
|
-
if (product.discount?.type === "percent") {
|
|
10
|
-
return (product.price * (product.discount.value ?? 100)) / 100;
|
|
11
|
-
}
|
|
12
|
-
if (product.discount?.type === "number") {
|
|
13
|
-
return product.discount.value ?? 0;
|
|
14
|
-
}
|
|
15
|
-
return 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getPriceAfterDiscount(product: TProduct) {
|
|
19
|
-
if (product.discount?.type === "percent") {
|
|
20
|
-
const dscountAmount = (product.price * product.discount.value) / 100;
|
|
21
|
-
return product.price - dscountAmount;
|
|
22
|
-
}
|
|
23
|
-
if (product.discount?.type === "number") {
|
|
24
|
-
const dscountAmount = product.price - product.discount.value;
|
|
25
|
-
return dscountAmount;
|
|
26
|
-
}
|
|
27
|
-
return product.price;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// main
|
|
31
|
-
export function getCartCost({
|
|
32
|
-
cart,
|
|
33
|
-
discounts,
|
|
34
|
-
deliveryPrice = 0,
|
|
35
|
-
freeDeliveryPrice = 0,
|
|
36
|
-
isVatIncludedInPrice = false,
|
|
37
|
-
}: {
|
|
38
|
-
cart: TCart["items"];
|
|
39
|
-
discounts: TDiscount[];
|
|
40
|
-
deliveryPrice?: number;
|
|
41
|
-
freeDeliveryPrice?: number;
|
|
42
|
-
isVatIncludedInPrice?: boolean;
|
|
43
|
-
}) {
|
|
44
|
-
// Convert cart items to the format expected by the discount engine
|
|
45
|
-
const cartForEngine = cart.map((item) => ({
|
|
46
|
-
amount: item.amount,
|
|
47
|
-
product: {
|
|
48
|
-
id: item.product.id,
|
|
49
|
-
price: item.product.price,
|
|
50
|
-
},
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
// Apply discounts using the new discount engine
|
|
54
|
-
const discountResult = DiscountEngine.calculateDiscounts(cartForEngine, discounts);
|
|
55
|
-
|
|
56
|
-
// Map the results back to the original format with additional product info
|
|
57
|
-
const result = cart.map((item, index) => {
|
|
58
|
-
const engineItem = discountResult.items[index];
|
|
59
|
-
return {
|
|
60
|
-
amount: item.amount,
|
|
61
|
-
product: { ...item.product },
|
|
62
|
-
originalPrice: item.product.price,
|
|
63
|
-
finalPrice: engineItem ? engineItem.finalPrice : getPriceAfterDiscount(item.product),
|
|
64
|
-
finalDiscount: engineItem ? engineItem.finalDiscount : calculateDiscount(item.product),
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const cartDetails = result.reduce(
|
|
69
|
-
(acc, item) => {
|
|
70
|
-
const { product, amount, finalPrice, finalDiscount } = item;
|
|
71
|
-
|
|
72
|
-
let productVatValue: number = 0;
|
|
73
|
-
if (product.vat) {
|
|
74
|
-
let vat = 0;
|
|
75
|
-
|
|
76
|
-
if (isVatIncludedInPrice) {
|
|
77
|
-
const vat_amount = finalPrice * (CONFIG.VAT / (100 + CONFIG.VAT));
|
|
78
|
-
productVatValue = Number(vat_amount.toFixed(2));
|
|
79
|
-
productVatValue = productVatValue * amount;
|
|
80
|
-
|
|
81
|
-
vat = Number(productVatValue.toFixed(2));
|
|
82
|
-
} else {
|
|
83
|
-
productVatValue = (finalPrice * CONFIG.VAT) / 100;
|
|
84
|
-
productVatValue = productVatValue * amount;
|
|
85
|
-
vat = Number(productVatValue.toFixed(2));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
acc.vat = Number((acc.vat + vat).toFixed(2));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Round finalPrice to prevent floating point errors from discount engine
|
|
92
|
-
const roundedFinalPrice = Number(finalPrice.toFixed(2));
|
|
93
|
-
|
|
94
|
-
acc.cost += amount * roundedFinalPrice;
|
|
95
|
-
acc.discount += finalDiscount ? amount * finalDiscount : finalDiscount;
|
|
96
|
-
acc.finalCost += amount * roundedFinalPrice + (isVatIncludedInPrice ? 0 : productVatValue);
|
|
97
|
-
acc.productsCost +=
|
|
98
|
-
amount * roundedFinalPrice + (isVatIncludedInPrice ? 0 : productVatValue);
|
|
99
|
-
|
|
100
|
-
// Round all accumulated values to prevent floating point errors
|
|
101
|
-
acc.cost = Number(acc.cost.toFixed(2));
|
|
102
|
-
acc.discount = Number(acc.discount.toFixed(2));
|
|
103
|
-
acc.finalCost = Number(acc.finalCost.toFixed(2));
|
|
104
|
-
acc.productsCost = Number(acc.productsCost.toFixed(2));
|
|
105
|
-
|
|
106
|
-
return acc;
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
discount: 0,
|
|
110
|
-
cost: 0,
|
|
111
|
-
finalCost: 0,
|
|
112
|
-
vat: 0,
|
|
113
|
-
productsCost: 0,
|
|
114
|
-
deliveryPrice: deliveryPrice,
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
if (cartDetails.deliveryPrice && cartDetails.productsCost >= freeDeliveryPrice) {
|
|
119
|
-
cartDetails.deliveryPrice = 0;
|
|
120
|
-
} else {
|
|
121
|
-
cartDetails.finalCost += cartDetails.deliveryPrice;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
console.log("cartDetails", cartDetails);
|
|
125
|
-
|
|
126
|
-
return { items: result, ...cartDetails };
|
|
127
|
-
}
|
package/src/vite-env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
package/tsconfig.app.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"lib": ["ES2020", "DOM"],
|
|
6
|
-
"jsx": "react-jsx",
|
|
7
|
-
"moduleResolution": "node",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"declarationMap": true,
|
|
11
|
-
"emitDeclarationOnly": false,
|
|
12
|
-
"outDir": "./dist",
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"skipLibCheck": true,
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"composite": true
|
|
17
|
-
},
|
|
18
|
-
"include": ["lib"],
|
|
19
|
-
"exclude": ["node_modules", "src", "dist", "vite.config.ts"]
|
|
20
|
-
}
|
package/tsconfig.json
DELETED
package/tsconfig.node.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"lib": ["ES2023"],
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
|
|
8
|
-
/* Bundler mode */
|
|
9
|
-
"moduleResolution": "bundler",
|
|
10
|
-
"isolatedModules": true,
|
|
11
|
-
"moduleDetection": "force",
|
|
12
|
-
|
|
13
|
-
/* Linting */
|
|
14
|
-
"strict": true,
|
|
15
|
-
"noUnusedLocals": true,
|
|
16
|
-
"noUnusedParameters": true,
|
|
17
|
-
"noFallthroughCasesInSwitch": true,
|
|
18
|
-
"outDir": "./dist",
|
|
19
|
-
"declaration": true,
|
|
20
|
-
"declarationMap": true,
|
|
21
|
-
"emitDeclarationOnly": false,
|
|
22
|
-
"esModuleInterop": true,
|
|
23
|
-
"forceConsistentCasingInFileNames": true
|
|
24
|
-
},
|
|
25
|
-
"include": ["vite.config.ts"]
|
|
26
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vite";
|
|
2
|
-
import react from "@vitejs/plugin-react-swc";
|
|
3
|
-
import { resolve } from "path";
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
plugins: [react()],
|
|
7
|
-
|
|
8
|
-
build: {
|
|
9
|
-
lib: {
|
|
10
|
-
entry: resolve(__dirname, "lib/index.tsx"),
|
|
11
|
-
name: "core",
|
|
12
|
-
formats: ["es", "cjs", "umd"],
|
|
13
|
-
fileName: (format) => `core.${format}.js`,
|
|
14
|
-
},
|
|
15
|
-
rollupOptions: {
|
|
16
|
-
external: ["react", "react-dom"], // Exclude dependencies from the bundle
|
|
17
|
-
output: {
|
|
18
|
-
globals: {
|
|
19
|
-
react: "React",
|
|
20
|
-
"react-dom": "ReactDOM",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
sourcemap: true,
|
|
25
|
-
minify: "esbuild",
|
|
26
|
-
},
|
|
27
|
-
});
|
package/vitest.config.ts
DELETED
|
File without changes
|
|
File without changes
|