@jsdev_ninja/core 0.14.3 → 0.14.6

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.
@@ -0,0 +1,96 @@
1
+ import { z } from "zod";
2
+ export declare const ChatSessionSchema: z.ZodObject<{
3
+ type: z.ZodLiteral<"ChatSession">;
4
+ id: z.ZodString;
5
+ storeId: z.ZodString;
6
+ companyId: z.ZodString;
7
+ tenantId: z.ZodString;
8
+ userId: z.ZodNullable<z.ZodString>;
9
+ userType: z.ZodEnum<["anonymous", "client", "admin", "superAdmin"]>;
10
+ createdAt: z.ZodNumber;
11
+ updatedAt: z.ZodNumber;
12
+ messageCount: z.ZodNumber;
13
+ status: z.ZodEnum<["active", "archived"]>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ type: "ChatSession";
16
+ status: "active" | "archived";
17
+ id: string;
18
+ companyId: string;
19
+ storeId: string;
20
+ userId: string | null;
21
+ tenantId: string;
22
+ createdAt: number;
23
+ userType: "admin" | "client" | "anonymous" | "superAdmin";
24
+ updatedAt: number;
25
+ messageCount: number;
26
+ }, {
27
+ type: "ChatSession";
28
+ status: "active" | "archived";
29
+ id: string;
30
+ companyId: string;
31
+ storeId: string;
32
+ userId: string | null;
33
+ tenantId: string;
34
+ createdAt: number;
35
+ userType: "admin" | "client" | "anonymous" | "superAdmin";
36
+ updatedAt: number;
37
+ messageCount: number;
38
+ }>;
39
+ export type TChatSession = z.infer<typeof ChatSessionSchema>;
40
+ export declare const ChatSessionMessageSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
41
+ type: z.ZodLiteral<"message">;
42
+ id: z.ZodString;
43
+ role: z.ZodEnum<["user", "assistant", "system"]>;
44
+ content: z.ZodString;
45
+ timestamp: z.ZodNumber;
46
+ }, "strip", z.ZodTypeAny, {
47
+ type: "message";
48
+ id: string;
49
+ role: "user" | "assistant" | "system";
50
+ content: string;
51
+ timestamp: number;
52
+ }, {
53
+ type: "message";
54
+ id: string;
55
+ role: "user" | "assistant" | "system";
56
+ content: string;
57
+ timestamp: number;
58
+ }>, z.ZodObject<{
59
+ type: z.ZodLiteral<"function_call">;
60
+ id: z.ZodString;
61
+ name: z.ZodString;
62
+ arguments: z.ZodRecord<z.ZodString, z.ZodAny>;
63
+ timestamp: z.ZodNumber;
64
+ }, "strip", z.ZodTypeAny, {
65
+ type: "function_call";
66
+ id: string;
67
+ name: string;
68
+ timestamp: number;
69
+ arguments: Record<string, any>;
70
+ }, {
71
+ type: "function_call";
72
+ id: string;
73
+ name: string;
74
+ timestamp: number;
75
+ arguments: Record<string, any>;
76
+ }>, z.ZodObject<{
77
+ type: z.ZodLiteral<"tool_result">;
78
+ id: z.ZodString;
79
+ name: z.ZodString;
80
+ result: z.ZodAny;
81
+ timestamp: z.ZodNumber;
82
+ }, "strip", z.ZodTypeAny, {
83
+ type: "tool_result";
84
+ id: string;
85
+ name: string;
86
+ timestamp: number;
87
+ result?: any;
88
+ }, {
89
+ type: "tool_result";
90
+ id: string;
91
+ name: string;
92
+ timestamp: number;
93
+ result?: any;
94
+ }>]>;
95
+ export type TChatSessionMessage = z.infer<typeof ChatSessionMessageSchema>;
96
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/entities/Chatbot/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAY5B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE7D,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsBnC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+ export const ChatSessionSchema = z.object({
3
+ type: z.literal("ChatSession"),
4
+ id: z.string(),
5
+ storeId: z.string(),
6
+ companyId: z.string(),
7
+ tenantId: z.string(),
8
+ userId: z.string().nullable(),
9
+ userType: z.enum(["anonymous", "client", "admin", "superAdmin"]),
10
+ createdAt: z.number(),
11
+ updatedAt: z.number(),
12
+ messageCount: z.number(),
13
+ status: z.enum(["active", "archived"]),
14
+ });
15
+ export const ChatSessionMessageSchema = z.discriminatedUnion("type", [
16
+ z.object({
17
+ type: z.literal("message"),
18
+ id: z.string(),
19
+ role: z.enum(["user", "assistant", "system"]),
20
+ content: z.string(),
21
+ timestamp: z.number(),
22
+ }),
23
+ z.object({
24
+ type: z.literal("function_call"),
25
+ id: z.string(),
26
+ name: z.string(),
27
+ arguments: z.record(z.string(), z.any()),
28
+ timestamp: z.number(),
29
+ }),
30
+ z.object({
31
+ type: z.literal("tool_result"),
32
+ id: z.string(),
33
+ name: z.string(),
34
+ result: z.any(),
35
+ timestamp: z.number(),
36
+ }),
37
+ ]);
@@ -16,4 +16,5 @@ export * from "./DeliveryNote";
16
16
  export * from "./Payment";
17
17
  export * from "./Supplier";
18
18
  export * from "./SupplierInvoice";
19
+ export * from "./Chatbot";
19
20
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,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,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC"}
@@ -16,3 +16,4 @@ export * from "./DeliveryNote";
16
16
  export * from "./Payment";
17
17
  export * from "./Supplier";
18
18
  export * from "./SupplierInvoice";
19
+ export * from "./Chatbot";
@@ -18,6 +18,9 @@ export declare const storeCollections: {
18
18
  readonly invoices: "invoices";
19
19
  readonly suppliers: "suppliers";
20
20
  readonly supplierInvoices: "supplierInvoices";
21
+ readonly chatSessions: "chatSessions";
22
+ readonly chatSessionMessages: "chatSessionMessages";
23
+ readonly contactSubmissions: "contactSubmissions";
21
24
  };
22
25
  export declare const FirestoreApi: {
23
26
  systemCollections: {
@@ -40,6 +43,9 @@ export declare const FirestoreApi: {
40
43
  readonly invoices: "invoices";
41
44
  readonly suppliers: "suppliers";
42
45
  readonly supplierInvoices: "supplierInvoices";
46
+ readonly chatSessions: "chatSessions";
47
+ readonly chatSessionMessages: "chatSessionMessages";
48
+ readonly contactSubmissions: "contactSubmissions";
43
49
  };
44
50
  getPath: ({ companyId, storeId, collectionName, id, }: {
45
51
  companyId: string;
@@ -47,7 +53,16 @@ export declare const FirestoreApi: {
47
53
  collectionName: keyof typeof storeCollections;
48
54
  id?: string;
49
55
  }) => string;
56
+ getSubPath: ({ companyId, storeId, collectionName, subCollectionName, id, subId, }: {
57
+ companyId: string;
58
+ storeId: string;
59
+ collectionName: keyof typeof storeCollections;
60
+ subCollectionName: keyof typeof storeCollections;
61
+ id: string;
62
+ subId?: string;
63
+ }) => string;
50
64
  getDocPath: (collectionName: keyof typeof storeCollections) => string;
65
+ getSubDocPath: (collectionName: keyof typeof storeCollections, id: string, subCollectionName: keyof typeof storeCollections) => string;
51
66
  };
52
67
  export declare const FirebaseAPI: {
53
68
  firestore: {
@@ -71,6 +86,9 @@ export declare const FirebaseAPI: {
71
86
  readonly invoices: "invoices";
72
87
  readonly suppliers: "suppliers";
73
88
  readonly supplierInvoices: "supplierInvoices";
89
+ readonly chatSessions: "chatSessions";
90
+ readonly chatSessionMessages: "chatSessionMessages";
91
+ readonly contactSubmissions: "contactSubmissions";
74
92
  };
75
93
  getPath: ({ companyId, storeId, collectionName, id, }: {
76
94
  companyId: string;
@@ -78,7 +96,16 @@ export declare const FirebaseAPI: {
78
96
  collectionName: keyof typeof storeCollections;
79
97
  id?: string;
80
98
  }) => string;
99
+ getSubPath: ({ companyId, storeId, collectionName, subCollectionName, id, subId, }: {
100
+ companyId: string;
101
+ storeId: string;
102
+ collectionName: keyof typeof storeCollections;
103
+ subCollectionName: keyof typeof storeCollections;
104
+ id: string;
105
+ subId?: string;
106
+ }) => string;
81
107
  getDocPath: (collectionName: keyof typeof storeCollections) => string;
108
+ getSubDocPath: (collectionName: keyof typeof storeCollections, id: string, subCollectionName: keyof typeof storeCollections) => string;
82
109
  };
83
110
  };
84
111
  //# sourceMappingURL=index.d.ts.map
@@ -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;;;;;;;;;;;;;;;;CAgBnB,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
+ {"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;;;;;;;;;;;;;;;;;;;CAmBnB,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;wFAUE;QACF,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,MAAM,OAAO,gBAAgB,CAAC;QAC9C,iBAAiB,EAAE,MAAM,OAAO,gBAAgB,CAAC;QACjD,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;KACf;iCAI4B,MAAM,OAAO,gBAAgB;oCAIzC,MAAM,OAAO,gBAAgB,MACzC,MAAM,qBACS,MAAM,OAAO,gBAAgB;CAIjD,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;+DAtCpB;YACF,SAAS,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,MAAM,CAAC;YAChB,cAAc,EAAE,MAAM,OAAO,gBAAgB,CAAC;YAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;SACZ;4FAUE;YACF,SAAS,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,MAAM,CAAC;YAChB,cAAc,EAAE,MAAM,OAAO,gBAAgB,CAAC;YAC9C,iBAAiB,EAAE,MAAM,OAAO,gBAAgB,CAAC;YACjD,EAAE,EAAE,MAAM,CAAC;YACX,KAAK,CAAC,EAAE,MAAM,CAAC;SACf;qCAI4B,MAAM,OAAO,gBAAgB;wCAIzC,MAAM,OAAO,gBAAgB,MACzC,MAAM,qBACS,MAAM,OAAO,gBAAgB;;CAQjD,CAAC"}
@@ -18,6 +18,9 @@ export const storeCollections = {
18
18
  invoices: "invoices",
19
19
  suppliers: "suppliers",
20
20
  supplierInvoices: "supplierInvoices",
21
+ chatSessions: "chatSessions",
22
+ chatSessionMessages: "chatSessionMessages",
23
+ contactSubmissions: "contactSubmissions",
21
24
  };
22
25
  export const FirestoreApi = {
23
26
  systemCollections,
@@ -26,10 +29,16 @@ export const FirestoreApi = {
26
29
  getPath: ({ companyId, storeId, collectionName, id, }) => {
27
30
  return `${companyId}/${storeId}/${collectionName}${id ? `/${id}` : ""}`;
28
31
  },
32
+ getSubPath: ({ companyId, storeId, collectionName, subCollectionName, id, subId, }) => {
33
+ return `${companyId}/${storeId}/${collectionName}/${id}/${subCollectionName}${subId ? `/${subId}` : ""}`;
34
+ },
29
35
  // for firestore events
30
36
  getDocPath: (collectionName) => {
31
37
  return `{companyId}/{storeId}/${collectionName}/{id}`;
32
38
  },
39
+ getSubDocPath: (collectionName, id, subCollectionName) => {
40
+ return `{companyId}/{storeId}/${collectionName}/${id}/${subCollectionName}/{id}`;
41
+ },
33
42
  };
34
43
  export const FirebaseAPI = {
35
44
  firestore: FirestoreApi,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAoB,MAAM,aAAa,CAAC;AA8BjE,wBAAgB,WAAW,CAAC,EAC3B,IAAI,EACJ,SAAS,EACT,aAAiB,EACjB,iBAAqB,EACrB,oBAA4B,GAC5B,EAAE;IACF,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACrB,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+FA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAY,MAAM,aAAa,CAAC;AAmCzD,wBAAgB,WAAW,CAAC,EAC3B,IAAI,EACJ,SAAS,EACT,aAAiB,EACjB,iBAAqB,EACrB,oBAA4B,GAC5B,EAAE;IACF,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACrB,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqFA"}
@@ -1,8 +1,8 @@
1
- import { DiscountEngine } from "../entities/Discount/engine";
1
+ // import { DiscountEngine } from "../entities/Discount/engine";
2
2
  const CONFIG = {
3
3
  VAT: 18,
4
4
  };
5
- function calculateDiscount(product) {
5
+ function calculateDiscount(product, isVatIncludedInPrice) {
6
6
  if (product.discount?.type === "percent") {
7
7
  return (product.price * (product.discount.value ?? 100)) / 100;
8
8
  }
@@ -11,38 +11,41 @@ function calculateDiscount(product) {
11
11
  }
12
12
  return 0;
13
13
  }
14
- function getPriceAfterDiscount(product) {
14
+ function getPriceAfterDiscount(product, isVatIncludedInPrice) {
15
+ const price = isVatIncludedInPrice && product.vat
16
+ ? product.price + (product.price * CONFIG.VAT) / 100
17
+ : product.price;
15
18
  if (product.discount?.type === "percent") {
16
- const dscountAmount = (product.price * product.discount.value) / 100;
19
+ const dscountAmount = (price * product.discount.value) / 100;
17
20
  return product.price - dscountAmount;
18
21
  }
19
22
  if (product.discount?.type === "number") {
20
- const dscountAmount = product.price - product.discount.value;
23
+ const dscountAmount = price - product.discount.value;
21
24
  return dscountAmount;
22
25
  }
23
- return product.price;
26
+ return price;
24
27
  }
25
28
  // main
26
29
  export function getCartCost({ cart, discounts, deliveryPrice = 0, freeDeliveryPrice = 0, isVatIncludedInPrice = false, }) {
27
30
  // Convert cart items to the format expected by the discount engine
28
- const cartForEngine = cart.map((item) => ({
29
- amount: item.amount,
30
- product: {
31
- id: item.product.id,
32
- price: item.product.price,
33
- },
34
- }));
31
+ // const cartForEngine = cart.map((item) => ({
32
+ // amount: item.amount,
33
+ // product: {
34
+ // id: item.product.id,
35
+ // price: item.product.price,
36
+ // },
37
+ // }));
35
38
  // Apply discounts using the new discount engine
36
- const discountResult = DiscountEngine.calculateDiscounts(cartForEngine, discounts);
39
+ // const discountResult = DiscountEngine.calculateDiscounts(cartForEngine, discounts);
37
40
  // Map the results back to the original format with additional product info
38
41
  const result = cart.map((item, index) => {
39
- const engineItem = discountResult.items[index];
42
+ // const engineItem = discountResult.items[index];
40
43
  return {
41
44
  amount: item.amount,
42
45
  product: { ...item.product },
43
46
  originalPrice: item.product.price,
44
- finalPrice: engineItem ? engineItem.finalPrice : getPriceAfterDiscount(item.product),
45
- finalDiscount: engineItem ? engineItem.finalDiscount : calculateDiscount(item.product),
47
+ finalPrice: getPriceAfterDiscount(item.product, isVatIncludedInPrice),
48
+ finalDiscount: calculateDiscount(item.product, isVatIncludedInPrice),
46
49
  };
47
50
  });
48
51
  // isVatIncludedInPrice = false
@@ -77,13 +80,6 @@ export function getCartCost({ cart, discounts, deliveryPrice = 0, freeDeliveryPr
77
80
  acc.discount = Number(acc.discount.toFixed(2));
78
81
  acc.finalCost = Number(acc.finalCost.toFixed(2));
79
82
  acc.productsCost = Number(acc.productsCost.toFixed(2));
80
- // console.log(
81
- // "product",
82
- // product.name[0].value,
83
- // finalPrice,
84
- // amount,
85
- // amount * roundedFinalPrice + (isVatIncludedInPrice ? 0 : productVatValue)
86
- // );
87
83
  return acc;
88
84
  }, {
89
85
  discount: 0,
@@ -99,6 +95,5 @@ export function getCartCost({ cart, discounts, deliveryPrice = 0, freeDeliveryPr
99
95
  else {
100
96
  cartDetails.finalCost += cartDetails.deliveryPrice;
101
97
  }
102
- console.log("cartDetails", cartDetails);
103
98
  return { items: result, ...cartDetails };
104
99
  }