@jsdev_ninja/core 0.13.26 → 0.13.28

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.
Files changed (55) hide show
  1. package/dist/core.cjs.js +1 -1
  2. package/dist/core.cjs.js.map +1 -1
  3. package/dist/core.es.js +149 -145
  4. package/dist/core.es.js.map +1 -1
  5. package/dist/core.umd.js +1 -1
  6. package/dist/core.umd.js.map +1 -1
  7. package/dist/lib/entities/Order.d.ts +3 -0
  8. package/dist/lib/entities/Order.d.ts.map +1 -1
  9. package/dist/lib/entities/Order.js +1 -0
  10. package/dist/lib/entities/Store.d.ts +46 -0
  11. package/dist/lib/entities/Store.d.ts.map +1 -1
  12. package/dist/lib/entities/Store.js +3 -0
  13. package/dist/tsconfig.app.tsbuildinfo +1 -1
  14. package/package.json +9 -2
  15. package/eslint.config.js +0 -28
  16. package/index.html +0 -13
  17. package/lib/entities/Address.ts +0 -13
  18. package/lib/entities/Atoms.ts +0 -11
  19. package/lib/entities/Cart.ts +0 -24
  20. package/lib/entities/Category.ts +0 -35
  21. package/lib/entities/Company.ts +0 -9
  22. package/lib/entities/DeliveryNote.ts +0 -70
  23. package/lib/entities/Discount/__tests__/engine.test.ts +0 -337
  24. package/lib/entities/Discount/__tests__/factory.test.ts +0 -91
  25. package/lib/entities/Discount/__tests__/integration.test.ts +0 -132
  26. package/lib/entities/Discount/__tests__/simple.test.ts +0 -215
  27. package/lib/entities/Discount/__tests__/utils.test.ts +0 -69
  28. package/lib/entities/Discount/engine.ts +0 -138
  29. package/lib/entities/Discount/factory.ts +0 -25
  30. package/lib/entities/Discount/index.ts +0 -10
  31. package/lib/entities/Discount/strategies/BundleStrategy.ts +0 -119
  32. package/lib/entities/Discount/strategies/__tests__/BundleStrategy.test.ts +0 -295
  33. package/lib/entities/Discount/strategy.ts +0 -6
  34. package/lib/entities/Discount/types.ts +0 -68
  35. package/lib/entities/Discount/utils.ts +0 -42
  36. package/lib/entities/FavoriteProduct.ts +0 -12
  37. package/lib/entities/Invoice.ts +0 -57
  38. package/lib/entities/Locale.ts +0 -8
  39. package/lib/entities/Order.ts +0 -66
  40. package/lib/entities/Organization.ts +0 -23
  41. package/lib/entities/Product.ts +0 -68
  42. package/lib/entities/Profile.ts +0 -56
  43. package/lib/entities/Store.ts +0 -23
  44. package/lib/entities/index.ts +0 -14
  45. package/lib/firebase-api/app.ts +0 -18
  46. package/lib/firebase-api/index.ts +0 -46
  47. package/lib/index.tsx +0 -3
  48. package/lib/utils/index.ts +0 -127
  49. package/src/main.tsx +0 -1
  50. package/src/vite-env.d.ts +0 -1
  51. package/tsconfig.app.json +0 -20
  52. package/tsconfig.json +0 -7
  53. package/tsconfig.node.json +0 -26
  54. package/vite.config.ts +0 -27
  55. package/vitest.config.ts +0 -10
@@ -1,56 +0,0 @@
1
- import { z } from "zod";
2
- import { AddressSchema } from "./Address";
3
- import { notEmptyTextSchema } from "./Atoms";
4
-
5
- export const ProfilePaymentTypeSchema = z.enum(["default", "delayed"], {
6
- description: "delayed is J5 transaction",
7
- });
8
- export type TProfilePaymentType = z.infer<typeof ProfilePaymentTypeSchema>;
9
-
10
- export const ProfileSchema = z.object({
11
- type: z.literal("Profile"),
12
- id: notEmptyTextSchema,
13
- companyId: notEmptyTextSchema,
14
- storeId: notEmptyTextSchema,
15
- tenantId: notEmptyTextSchema,
16
- clientType: z.enum(["user", "company"]),
17
- companyName: z.string().optional(),
18
- displayName: notEmptyTextSchema,
19
- email: z.string().email(),
20
- phoneNumber: z.string().optional(),
21
- address: AddressSchema.optional(),
22
- isAnonymous: z.boolean(),
23
- createdDate: z.number(),
24
- lastActivityDate: z.number(),
25
- paymentType: ProfilePaymentTypeSchema,
26
- organizationId: z.string().optional().nullable(),
27
- });
28
-
29
- export type TProfile = z.infer<typeof ProfileSchema>;
30
-
31
- export function createEmptyProfile(): TProfile {
32
- return {
33
- type: "Profile",
34
- id: "",
35
- companyId: "",
36
- storeId: "",
37
- tenantId: "",
38
- clientType: "user",
39
- displayName: "",
40
- email: "",
41
- phoneNumber: "",
42
- address: {
43
- country: "",
44
- city: "",
45
- street: "",
46
- streetNumber: "",
47
- floor: "",
48
- apartmentEnterNumber: "",
49
- apartmentNumber: "",
50
- },
51
- createdDate: 0,
52
- lastActivityDate: 0,
53
- isAnonymous: true,
54
- paymentType: ProfilePaymentTypeSchema.Values.default,
55
- };
56
- }
@@ -1,23 +0,0 @@
1
- import { z } from "zod";
2
- import { AddressSchema } from "./Address";
3
-
4
- export const clientTypesSchema = z.enum(["individual", "company"]);
5
-
6
- export const StoreSchema = z.object({
7
- id: z.string(),
8
- companyId: z.string(),
9
- name: z.string(),
10
- urls: z.array(z.string()),
11
- logoUrl: z.string(),
12
- tenantId: z.string(), // firebase auth tenantId
13
- paymentType: z.enum(["external", "j5"]),
14
- allowAnonymousClients: z.boolean(),
15
- isVatIncludedInPrice: z.boolean(),
16
- clientTypes: z.array(clientTypesSchema),
17
- minimumOrder: z.number().optional(),
18
- freeDeliveryPrice: z.number().optional(),
19
- deliveryPrice: z.number().optional(),
20
- address: AddressSchema.optional(),
21
- });
22
-
23
- export type TStore = z.infer<typeof StoreSchema>;
@@ -1,14 +0,0 @@
1
- export * from "./Address";
2
- export * from "./Atoms";
3
- export * from "./Cart";
4
- export * from "./Category";
5
- export * from "./Company";
6
- export * from "./FavoriteProduct";
7
- export * from "./Locale";
8
- export * from "./Order";
9
- export * from "./Product";
10
- export * from "./Profile";
11
- export * from "./Store";
12
- export * from "./Discount";
13
- export * from "./Organization";
14
- export * from "./DeliveryNote";
@@ -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/index.tsx DELETED
@@ -1,3 +0,0 @@
1
- export * from "./entities";
2
- export * from "./utils";
3
- export { FirebaseAPI } from "./firebase-api";
@@ -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/main.tsx DELETED
@@ -1 +0,0 @@
1
- export {};
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
@@ -1,7 +0,0 @@
1
- {
2
- "files": [],
3
- "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }],
4
- "compilerOptions": {
5
- "composite": true
6
- }
7
- }
@@ -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
@@ -1,10 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],
8
- exclude: ['node_modules', 'dist'],
9
- },
10
- });