@instockng/api-client 1.0.5 → 1.0.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.
Files changed (186) hide show
  1. package/dist/enum-types.d.ts +8 -0
  2. package/dist/enum-types.js +5 -0
  3. package/dist/fetchers/carts.js +5 -0
  4. package/dist/hooks/admin/abandoned-carts.js +12 -8
  5. package/dist/hooks/admin/brands.js +15 -10
  6. package/dist/hooks/admin/customers.js +3 -2
  7. package/dist/hooks/admin/delivery-zones.js +24 -16
  8. package/dist/hooks/admin/discount-codes.js +24 -16
  9. package/dist/hooks/admin/inventory.js +15 -10
  10. package/dist/hooks/admin/orders.js +18 -12
  11. package/dist/hooks/admin/products.js +15 -10
  12. package/dist/hooks/admin/stats.js +3 -2
  13. package/dist/hooks/admin/variants.js +18 -12
  14. package/dist/hooks/admin/warehouses.js +15 -10
  15. package/dist/hooks/useApiConfig.d.ts +2 -1
  16. package/dist/hooks/useApiConfig.js +2 -2
  17. package/dist/provider.d.ts +7 -4
  18. package/dist/provider.js +5 -3
  19. package/dist/types.d.ts +1 -0
  20. package/package.json +1 -1
  21. package/dist/apps/backend/src/generated/zod/index.d.ts +0 -1114
  22. package/dist/apps/backend/src/generated/zod/index.js +0 -670
  23. package/dist/apps/backend/src/http-app.d.ts +0 -40
  24. package/dist/apps/backend/src/http-app.js +0 -106
  25. package/dist/apps/backend/src/lib/brand-response.d.ts +0 -14
  26. package/dist/apps/backend/src/lib/brand-response.js +0 -8
  27. package/dist/apps/backend/src/lib/cart-helpers.d.ts +0 -280
  28. package/dist/apps/backend/src/lib/cart-helpers.js +0 -93
  29. package/dist/apps/backend/src/lib/cart-recovery.d.ts +0 -30
  30. package/dist/apps/backend/src/lib/cart-recovery.js +0 -147
  31. package/dist/apps/backend/src/lib/cart-response.d.ts +0 -121
  32. package/dist/apps/backend/src/lib/cart-response.js +0 -150
  33. package/dist/apps/backend/src/lib/clerk.d.ts +0 -18
  34. package/dist/apps/backend/src/lib/clerk.js +0 -167
  35. package/dist/apps/backend/src/lib/delivery-zone-response.d.ts +0 -62
  36. package/dist/apps/backend/src/lib/delivery-zone-response.js +0 -24
  37. package/dist/apps/backend/src/lib/discount-code-response.d.ts +0 -42
  38. package/dist/apps/backend/src/lib/discount-code-response.js +0 -19
  39. package/dist/apps/backend/src/lib/discount.d.ts +0 -20
  40. package/dist/apps/backend/src/lib/discount.js +0 -35
  41. package/dist/apps/backend/src/lib/inventory.d.ts +0 -26
  42. package/dist/apps/backend/src/lib/inventory.js +0 -160
  43. package/dist/apps/backend/src/lib/meta-capi.d.ts +0 -48
  44. package/dist/apps/backend/src/lib/meta-capi.js +0 -120
  45. package/dist/apps/backend/src/lib/openapi.d.ts +0 -36
  46. package/dist/apps/backend/src/lib/openapi.js +0 -69
  47. package/dist/apps/backend/src/lib/order-recovery.d.ts +0 -367
  48. package/dist/apps/backend/src/lib/order-recovery.js +0 -373
  49. package/dist/apps/backend/src/lib/order-response.d.ts +0 -136
  50. package/dist/apps/backend/src/lib/order-response.js +0 -61
  51. package/dist/apps/backend/src/lib/pricing.d.ts +0 -39
  52. package/dist/apps/backend/src/lib/pricing.js +0 -62
  53. package/dist/apps/backend/src/lib/prisma.d.ts +0 -9
  54. package/dist/apps/backend/src/lib/prisma.js +0 -30
  55. package/dist/apps/backend/src/lib/product-response.d.ts +0 -82
  56. package/dist/apps/backend/src/lib/product-response.js +0 -29
  57. package/dist/apps/backend/src/lib/utils.d.ts +0 -32
  58. package/dist/apps/backend/src/lib/utils.js +0 -63
  59. package/dist/apps/backend/src/middleware/clerk-auth.d.ts +0 -8
  60. package/dist/apps/backend/src/middleware/clerk-auth.js +0 -89
  61. package/dist/apps/backend/src/middleware/cors.d.ts +0 -8
  62. package/dist/apps/backend/src/middleware/cors.js +0 -11
  63. package/dist/apps/backend/src/notifications/producers/meta-capi-producer.d.ts +0 -55
  64. package/dist/apps/backend/src/notifications/producers/meta-capi-producer.js +0 -125
  65. package/dist/apps/backend/src/notifications/producers/order-notification.d.ts +0 -9
  66. package/dist/apps/backend/src/notifications/producers/order-notification.js +0 -18
  67. package/dist/apps/backend/src/notifications/producers/prospect-recovery-notification.d.ts +0 -10
  68. package/dist/apps/backend/src/notifications/producers/prospect-recovery-notification.js +0 -11
  69. package/dist/apps/backend/src/routes/admin/abandoned-carts.d.ts +0 -605
  70. package/dist/apps/backend/src/routes/admin/abandoned-carts.js +0 -194
  71. package/dist/apps/backend/src/routes/admin/brands.d.ts +0 -175
  72. package/dist/apps/backend/src/routes/admin/brands.js +0 -118
  73. package/dist/apps/backend/src/routes/admin/customers.d.ts +0 -306
  74. package/dist/apps/backend/src/routes/admin/customers.js +0 -39
  75. package/dist/apps/backend/src/routes/admin/delivery-zones.d.ts +0 -438
  76. package/dist/apps/backend/src/routes/admin/delivery-zones.js +0 -300
  77. package/dist/apps/backend/src/routes/admin/discount-codes.d.ts +0 -478
  78. package/dist/apps/backend/src/routes/admin/discount-codes.js +0 -418
  79. package/dist/apps/backend/src/routes/admin/inventory.d.ts +0 -273
  80. package/dist/apps/backend/src/routes/admin/inventory.js +0 -189
  81. package/dist/apps/backend/src/routes/admin/orders.d.ts +0 -1478
  82. package/dist/apps/backend/src/routes/admin/orders.js +0 -503
  83. package/dist/apps/backend/src/routes/admin/products.d.ts +0 -860
  84. package/dist/apps/backend/src/routes/admin/products.js +0 -107
  85. package/dist/apps/backend/src/routes/admin/stats.d.ts +0 -288
  86. package/dist/apps/backend/src/routes/admin/stats.js +0 -55
  87. package/dist/apps/backend/src/routes/admin/variants.d.ts +0 -239
  88. package/dist/apps/backend/src/routes/admin/variants.js +0 -173
  89. package/dist/apps/backend/src/routes/admin/warehouses.d.ts +0 -373
  90. package/dist/apps/backend/src/routes/admin/warehouses.js +0 -123
  91. package/dist/apps/backend/src/routes/public/brands.d.ts +0 -40
  92. package/dist/apps/backend/src/routes/public/brands.js +0 -38
  93. package/dist/apps/backend/src/routes/public/carts.d.ts +0 -2655
  94. package/dist/apps/backend/src/routes/public/carts.js +0 -631
  95. package/dist/apps/backend/src/routes/public/delivery-zones.d.ts +0 -35
  96. package/dist/apps/backend/src/routes/public/delivery-zones.js +0 -62
  97. package/dist/apps/backend/src/routes/public/orders.d.ts +0 -323
  98. package/dist/apps/backend/src/routes/public/orders.js +0 -160
  99. package/dist/apps/backend/src/routes/public/products.d.ts +0 -449
  100. package/dist/apps/backend/src/routes/public/products.js +0 -133
  101. package/dist/apps/backend/src/types/index.d.ts +0 -42
  102. package/dist/apps/backend/src/types/index.js +0 -2
  103. package/dist/apps/backend/src/validators/brand.d.ts +0 -17
  104. package/dist/apps/backend/src/validators/brand.js +0 -15
  105. package/dist/apps/backend/src/validators/delivery-zone.d.ts +0 -31
  106. package/dist/apps/backend/src/validators/delivery-zone.js +0 -51
  107. package/dist/apps/backend/src/validators/discount-code.d.ts +0 -74
  108. package/dist/apps/backend/src/validators/discount-code.js +0 -50
  109. package/dist/apps/backend/src/validators/inventory.d.ts +0 -20
  110. package/dist/apps/backend/src/validators/inventory.js +0 -15
  111. package/dist/apps/backend/src/validators/order.d.ts +0 -87
  112. package/dist/apps/backend/src/validators/order.js +0 -61
  113. package/dist/apps/backend/src/validators/product.d.ts +0 -18
  114. package/dist/apps/backend/src/validators/product.js +0 -19
  115. package/dist/apps/backend/src/validators/variant.d.ts +0 -19
  116. package/dist/apps/backend/src/validators/variant.js +0 -19
  117. package/dist/apps/backend/src/validators/warehouse.d.ts +0 -15
  118. package/dist/apps/backend/src/validators/warehouse.js +0 -15
  119. package/dist/packages/api-client/src/backend-types.d.ts +0 -10
  120. package/dist/packages/api-client/src/backend-types.js +0 -10
  121. package/dist/packages/api-client/src/client.d.ts +0 -20
  122. package/dist/packages/api-client/src/client.js +0 -40
  123. package/dist/packages/api-client/src/fetchers/brands.d.ts +0 -25
  124. package/dist/packages/api-client/src/fetchers/brands.js +0 -26
  125. package/dist/packages/api-client/src/fetchers/carts.d.ts +0 -2335
  126. package/dist/packages/api-client/src/fetchers/carts.js +0 -169
  127. package/dist/packages/api-client/src/fetchers/delivery-zones.d.ts +0 -28
  128. package/dist/packages/api-client/src/fetchers/delivery-zones.js +0 -26
  129. package/dist/packages/api-client/src/fetchers/index.d.ts +0 -22
  130. package/dist/packages/api-client/src/fetchers/index.js +0 -22
  131. package/dist/packages/api-client/src/fetchers/orders.d.ts +0 -283
  132. package/dist/packages/api-client/src/fetchers/orders.js +0 -44
  133. package/dist/packages/api-client/src/fetchers/products.d.ts +0 -386
  134. package/dist/packages/api-client/src/fetchers/products.js +0 -42
  135. package/dist/packages/api-client/src/hooks/admin/abandoned-carts.d.ts +0 -535
  136. package/dist/packages/api-client/src/hooks/admin/abandoned-carts.js +0 -83
  137. package/dist/packages/api-client/src/hooks/admin/brands.d.ts +0 -79
  138. package/dist/packages/api-client/src/hooks/admin/brands.js +0 -108
  139. package/dist/packages/api-client/src/hooks/admin/customers.d.ts +0 -278
  140. package/dist/packages/api-client/src/hooks/admin/customers.js +0 -26
  141. package/dist/packages/api-client/src/hooks/admin/delivery-zones.d.ts +0 -270
  142. package/dist/packages/api-client/src/hooks/admin/delivery-zones.js +0 -176
  143. package/dist/packages/api-client/src/hooks/admin/discount-codes.d.ts +0 -299
  144. package/dist/packages/api-client/src/hooks/admin/discount-codes.js +0 -165
  145. package/dist/packages/api-client/src/hooks/admin/index.d.ts +0 -16
  146. package/dist/packages/api-client/src/hooks/admin/index.js +0 -16
  147. package/dist/packages/api-client/src/hooks/admin/inventory.d.ts +0 -224
  148. package/dist/packages/api-client/src/hooks/admin/inventory.js +0 -107
  149. package/dist/packages/api-client/src/hooks/admin/orders.d.ts +0 -1380
  150. package/dist/packages/api-client/src/hooks/admin/orders.js +0 -175
  151. package/dist/packages/api-client/src/hooks/admin/products.d.ts +0 -374
  152. package/dist/packages/api-client/src/hooks/admin/products.js +0 -89
  153. package/dist/packages/api-client/src/hooks/admin/stats.d.ts +0 -277
  154. package/dist/packages/api-client/src/hooks/admin/stats.js +0 -25
  155. package/dist/packages/api-client/src/hooks/admin/variants.d.ts +0 -115
  156. package/dist/packages/api-client/src/hooks/admin/variants.js +0 -127
  157. package/dist/packages/api-client/src/hooks/admin/warehouses.d.ts +0 -277
  158. package/dist/packages/api-client/src/hooks/admin/warehouses.js +0 -108
  159. package/dist/packages/api-client/src/hooks/public/brands.d.ts +0 -33
  160. package/dist/packages/api-client/src/hooks/public/brands.js +0 -30
  161. package/dist/packages/api-client/src/hooks/public/carts.d.ts +0 -2405
  162. package/dist/packages/api-client/src/hooks/public/carts.js +0 -213
  163. package/dist/packages/api-client/src/hooks/public/delivery-zones.d.ts +0 -34
  164. package/dist/packages/api-client/src/hooks/public/delivery-zones.js +0 -28
  165. package/dist/packages/api-client/src/hooks/public/index.d.ts +0 -10
  166. package/dist/packages/api-client/src/hooks/public/index.js +0 -10
  167. package/dist/packages/api-client/src/hooks/public/orders.d.ts +0 -302
  168. package/dist/packages/api-client/src/hooks/public/orders.js +0 -50
  169. package/dist/packages/api-client/src/hooks/public/products.d.ts +0 -398
  170. package/dist/packages/api-client/src/hooks/public/products.js +0 -47
  171. package/dist/packages/api-client/src/hooks/use-query-unwrapped.d.ts +0 -20
  172. package/dist/packages/api-client/src/hooks/use-query-unwrapped.js +0 -22
  173. package/dist/packages/api-client/src/hooks/useApiConfig.d.ts +0 -12
  174. package/dist/packages/api-client/src/hooks/useApiConfig.js +0 -14
  175. package/dist/packages/api-client/src/index.d.ts +0 -20
  176. package/dist/packages/api-client/src/index.js +0 -25
  177. package/dist/packages/api-client/src/provider.d.ts +0 -36
  178. package/dist/packages/api-client/src/provider.js +0 -54
  179. package/dist/packages/api-client/src/rpc-client.d.ts +0 -9035
  180. package/dist/packages/api-client/src/rpc-client.js +0 -78
  181. package/dist/packages/api-client/src/rpc-types.d.ts +0 -76
  182. package/dist/packages/api-client/src/rpc-types.js +0 -7
  183. package/dist/packages/api-client/src/types.d.ts +0 -37
  184. package/dist/packages/api-client/src/types.js +0 -16
  185. package/dist/packages/api-client/src/utils/query-keys.d.ts +0 -106
  186. package/dist/packages/api-client/src/utils/query-keys.js +0 -108
@@ -1,40 +0,0 @@
1
- /**
2
- * HTTP application setup
3
- * This module is lazy-loaded only when handling HTTP requests
4
- */
5
- import publicOrders from './routes/public/orders';
6
- import publicProducts from './routes/public/products';
7
- import publicCarts from './routes/public/carts';
8
- import publicDeliveryZones from './routes/public/delivery-zones';
9
- import publicBrands from './routes/public/brands';
10
- import adminOrders from './routes/admin/orders';
11
- import adminBrands from './routes/admin/brands';
12
- import adminProducts from './routes/admin/products';
13
- import adminVariants from './routes/admin/variants';
14
- import adminWarehouses from './routes/admin/warehouses';
15
- import adminInventory from './routes/admin/inventory';
16
- import adminCustomers from './routes/admin/customers';
17
- import adminStats from './routes/admin/stats';
18
- import adminAbandonedCarts from './routes/admin/abandoned-carts';
19
- import adminDiscountCodes from './routes/admin/discount-codes';
20
- import adminDeliveryZones from './routes/admin/delivery-zones';
21
- export type CartsRPC = typeof publicCarts;
22
- export type OrdersRPC = typeof publicOrders;
23
- export type ProductsRPC = typeof publicProducts;
24
- export type DeliveryZonesRPC = typeof publicDeliveryZones;
25
- export type BrandsRPC = typeof publicBrands;
26
- export type AdminOrdersRPC = typeof adminOrders;
27
- export type AdminBrandsRPC = typeof adminBrands;
28
- export type AdminProductsRPC = typeof adminProducts;
29
- export type AdminVariantsRPC = typeof adminVariants;
30
- export type AdminWarehousesRPC = typeof adminWarehouses;
31
- export type AdminInventoryRPC = typeof adminInventory;
32
- export type AdminCustomersRPC = typeof adminCustomers;
33
- export type AdminStatsRPC = typeof adminStats;
34
- export type AdminAbandonedCartsRPC = typeof adminAbandonedCarts;
35
- export type AdminDiscountCodesRPC = typeof adminDiscountCodes;
36
- export type AdminDeliveryZonesRPC = typeof adminDeliveryZones;
37
- /**
38
- * Create the HTTP application with all routes and middleware
39
- */
40
- export declare function createHttpApp(): import("@hono/zod-openapi").OpenAPIHono<import("./types").AppContext, {}, "/">;
@@ -1,106 +0,0 @@
1
- /**
2
- * HTTP application setup
3
- * This module is lazy-loaded only when handling HTTP requests
4
- */
5
- import { Hono } from 'hono';
6
- import { corsMiddleware } from './middleware/cors';
7
- import { clerkAuthMiddleware } from './middleware/clerk-auth';
8
- import { createOpenAPIApp, openapiConfig } from './lib/openapi';
9
- import { swaggerUI } from '@hono/swagger-ui';
10
- import { HTTPException } from 'hono/http-exception';
11
- // Public routes
12
- import publicOrders from './routes/public/orders';
13
- import publicProducts from './routes/public/products';
14
- import publicCarts from './routes/public/carts';
15
- import publicDeliveryZones from './routes/public/delivery-zones';
16
- import publicBrands from './routes/public/brands';
17
- // Admin routes
18
- import adminOrders from './routes/admin/orders';
19
- import adminBrands from './routes/admin/brands';
20
- import adminProducts from './routes/admin/products';
21
- import adminVariants from './routes/admin/variants';
22
- import adminWarehouses from './routes/admin/warehouses';
23
- import adminInventory from './routes/admin/inventory';
24
- import adminCustomers from './routes/admin/customers';
25
- import adminStats from './routes/admin/stats';
26
- import adminAbandonedCarts from './routes/admin/abandoned-carts';
27
- import adminDiscountCodes from './routes/admin/discount-codes';
28
- import adminDeliveryZones from './routes/admin/delivery-zones';
29
- /**
30
- * Create the HTTP application with all routes and middleware
31
- */
32
- export function createHttpApp() {
33
- const app = createOpenAPIApp();
34
- // Global CORS middleware
35
- app.use('*', corsMiddleware);
36
- // Health check
37
- app.get('/', (c) => {
38
- return c.json({
39
- name: 'OMS API',
40
- version: '1.0.0',
41
- status: 'healthy',
42
- });
43
- });
44
- app.get('/health', (c) => {
45
- return c.json({ status: 'ok' });
46
- });
47
- // OpenAPI documentation
48
- app.doc('/openapi.json', openapiConfig);
49
- // Swagger UI
50
- app.get('/docs', swaggerUI({ url: '/openapi.json' }));
51
- // Admin API routes (Clerk auth protected)
52
- // Note: Must be mounted BEFORE public routes to match /v1/admin/* before /v1/*
53
- const adminApp = new Hono();
54
- adminApp.use('*', clerkAuthMiddleware);
55
- adminApp
56
- .route('/orders', adminOrders)
57
- .route('/brands', adminBrands)
58
- .route('/products', adminProducts)
59
- .route('/variants', adminVariants)
60
- .route('/warehouses', adminWarehouses)
61
- .route('/inventory', adminInventory)
62
- .route('/customers', adminCustomers)
63
- .route('/stats', adminStats)
64
- .route('/abandoned-carts', adminAbandonedCarts)
65
- .route('/discount-codes', adminDiscountCodes)
66
- .route('/delivery-zones', adminDeliveryZones);
67
- app.route('/v1/admin', adminApp);
68
- // Public API routes (CORS protected, no API key needed)
69
- // UUID-based resources (orders, carts) are self-authenticating
70
- // Rate limiting and CORS provide abuse protection
71
- const publicApi = createOpenAPIApp();
72
- publicApi.route('/orders', publicOrders);
73
- publicApi.route('/products', publicProducts);
74
- publicApi.route('/carts', publicCarts);
75
- publicApi.route('/delivery-zones', publicDeliveryZones);
76
- publicApi.route('/brands', publicBrands);
77
- app.route('/v1', publicApi);
78
- // 404 handler
79
- app.notFound((c) => {
80
- return c.json({
81
- error: {
82
- code: 'NOT_FOUND',
83
- message: 'The requested endpoint does not exist',
84
- },
85
- }, 404);
86
- });
87
- // Error handler
88
- app.onError((err, c) => {
89
- if (err instanceof HTTPException && err.status === 400) {
90
- return c.json({
91
- error: {
92
- code: 'BAD_REQUEST',
93
- message: 'Malformed JSON in request body',
94
- },
95
- }, 400);
96
- }
97
- console.error('Unhandled error:', err);
98
- return c.json({
99
- error: {
100
- code: 'INTERNAL_ERROR',
101
- message: 'An unexpected error occurred',
102
- },
103
- }, 500);
104
- });
105
- return app;
106
- }
@@ -1,14 +0,0 @@
1
- import type { Prisma } from '@prisma/client';
2
- export type BrandDBResponse = Prisma.BrandGetPayload<{}>;
3
- export declare function formatBrandResponse(brand: BrandDBResponse): {
4
- createdAt: string;
5
- updatedAt: string;
6
- deletedAt: string;
7
- name: string;
8
- id: string;
9
- slug: string;
10
- logoUrl: string | null;
11
- siteUrl: string;
12
- domain: string;
13
- metaPixelId: string | null;
14
- };
@@ -1,8 +0,0 @@
1
- export function formatBrandResponse(brand) {
2
- return {
3
- ...brand,
4
- createdAt: brand.createdAt.toISOString(),
5
- updatedAt: brand.updatedAt.toISOString(),
6
- deletedAt: brand.deletedAt ? brand.deletedAt.toISOString() : null,
7
- };
8
- }
@@ -1,280 +0,0 @@
1
- import { PrismaClient } from '@prisma/client';
2
- /**
3
- * Standard include pattern for cart queries with all necessary relations
4
- */
5
- export declare const CART_INCLUDE_FULL: {
6
- readonly brand: true;
7
- readonly deliveryZone: true;
8
- readonly recoveryDiscountCode: true;
9
- readonly items: {
10
- readonly include: {
11
- readonly variant: {
12
- readonly include: {
13
- readonly product: true;
14
- };
15
- };
16
- };
17
- };
18
- };
19
- /**
20
- * Include pattern for cart item queries that need the parent cart
21
- */
22
- export declare const CART_ITEM_WITH_CART_INCLUDE: {
23
- readonly cart: {
24
- readonly include: {
25
- readonly brand: true;
26
- };
27
- };
28
- };
29
- /**
30
- * Include pattern for order creation with discount code
31
- */
32
- export declare const ORDER_INCLUDE_FULL: {
33
- readonly brand: true;
34
- readonly deliveryZone: {
35
- readonly include: {
36
- readonly state: true;
37
- };
38
- };
39
- readonly items: {
40
- readonly include: {
41
- readonly variant: {
42
- readonly include: {
43
- readonly product: true;
44
- };
45
- };
46
- readonly warehouse: true;
47
- };
48
- };
49
- };
50
- type CartWithRelations = Awaited<ReturnType<typeof getCartWithRelations>>;
51
- declare function getCartWithRelations(prisma: PrismaClient, cartId: string): Promise<{
52
- brand: {
53
- name: string;
54
- id: string;
55
- slug: string;
56
- logoUrl: string | null;
57
- siteUrl: string;
58
- domain: string;
59
- metaPixelId: string | null;
60
- createdAt: Date;
61
- updatedAt: Date;
62
- deletedAt: Date | null;
63
- };
64
- deliveryZone: {
65
- name: string;
66
- id: string;
67
- createdAt: Date;
68
- updatedAt: Date;
69
- deletedAt: Date | null;
70
- brandId: string | null;
71
- stateId: string;
72
- deliveryCost: import("@prisma/client/runtime/library").Decimal;
73
- freeShippingThreshold: import("@prisma/client/runtime/library").Decimal | null;
74
- allowCOD: boolean;
75
- allowOnline: boolean;
76
- waybillOnly: boolean;
77
- estimatedDays: number | null;
78
- isActive: boolean;
79
- };
80
- recoveryDiscountCode: {
81
- id: string;
82
- createdAt: Date;
83
- updatedAt: Date;
84
- deletedAt: Date | null;
85
- brandId: string | null;
86
- isActive: boolean;
87
- code: string;
88
- type: string;
89
- value: import("@prisma/client/runtime/library").Decimal;
90
- minPurchase: import("@prisma/client/runtime/library").Decimal | null;
91
- maxDiscount: import("@prisma/client/runtime/library").Decimal | null;
92
- usageLimit: number | null;
93
- usageCount: number;
94
- perCustomerLimit: number | null;
95
- validFrom: Date;
96
- validUntil: Date | null;
97
- isAutoApply: boolean;
98
- description: string | null;
99
- category: string;
100
- createdBy: string | null;
101
- };
102
- items: ({
103
- variant: {
104
- product: {
105
- name: string;
106
- id: string;
107
- slug: string;
108
- createdAt: Date;
109
- updatedAt: Date;
110
- deletedAt: Date | null;
111
- brandId: string;
112
- isActive: boolean;
113
- description: string | null;
114
- thumbnailUrl: string | null;
115
- quantityDiscounts: import("@prisma/client/runtime/library").JsonValue | null;
116
- };
117
- } & {
118
- name: string | null;
119
- id: string;
120
- createdAt: Date;
121
- updatedAt: Date;
122
- deletedAt: Date | null;
123
- isActive: boolean;
124
- thumbnailUrl: string | null;
125
- productId: string;
126
- sku: string;
127
- price: import("@prisma/client/runtime/library").Decimal;
128
- trackInventory: boolean;
129
- lowStockThreshold: number | null;
130
- };
131
- } & {
132
- id: string;
133
- createdAt: Date;
134
- updatedAt: Date;
135
- variantId: string;
136
- quantity: number;
137
- cartId: string;
138
- })[];
139
- } & {
140
- id: string;
141
- createdAt: Date;
142
- updatedAt: Date;
143
- brandId: string;
144
- customerPhone: string | null;
145
- customerFirstName: string | null;
146
- customerLastName: string | null;
147
- expiresAt: Date;
148
- deliveryZoneId: string | null;
149
- deliveryZoneLockedAt: Date | null;
150
- availablePaymentMethods: import("@prisma/client").$Enums.PaymentMethod[];
151
- recoveryAttempts: number;
152
- lastRecoveryAttemptAt: Date | null;
153
- recoveryDiscountCodeId: string | null;
154
- convertedToOrderId: string | null;
155
- wasRecovered: boolean;
156
- appliedDiscountCodeId: string | null;
157
- customerEmail: string | null;
158
- }>;
159
- /**
160
- * Validate cart exists and is not expired
161
- */
162
- export declare function validateCart(prisma: PrismaClient, cartId: string): Promise<{
163
- cart: CartWithRelations | null;
164
- error?: {
165
- code: string;
166
- message: string;
167
- status: number;
168
- };
169
- }>;
170
- /**
171
- * Build cart response with pricing calculations
172
- */
173
- export declare function buildCartResponse(prisma: PrismaClient, cart: NonNullable<CartWithRelations>): Promise<{
174
- id: string;
175
- brand: {
176
- createdAt: string;
177
- updatedAt: string;
178
- deletedAt: string;
179
- name: string;
180
- id: string;
181
- slug: string;
182
- logoUrl: string | null;
183
- siteUrl: string;
184
- domain: string;
185
- metaPixelId: string | null;
186
- };
187
- customerPhone: string;
188
- customerEmail: string;
189
- customerFirstName: string;
190
- customerLastName: string;
191
- availablePaymentMethods: import("@prisma/client").$Enums.PaymentMethod[];
192
- deliveryZone: {
193
- id: string;
194
- name: string;
195
- };
196
- recoveryAttempts: number;
197
- lastRecoveryAttemptAt: Date;
198
- recoveryDiscountCode: {
199
- id: string;
200
- createdAt: Date;
201
- updatedAt: Date;
202
- deletedAt: Date | null;
203
- brandId: string | null;
204
- isActive: boolean;
205
- code: string;
206
- type: string;
207
- value: import("@prisma/client/runtime/library").Decimal;
208
- minPurchase: import("@prisma/client/runtime/library").Decimal | null;
209
- maxDiscount: import("@prisma/client/runtime/library").Decimal | null;
210
- usageLimit: number | null;
211
- usageCount: number;
212
- perCustomerLimit: number | null;
213
- validFrom: Date;
214
- validUntil: Date | null;
215
- isAutoApply: boolean;
216
- description: string | null;
217
- category: string;
218
- createdBy: string | null;
219
- };
220
- items: {
221
- id: string;
222
- variant: {
223
- price: number;
224
- product: {
225
- name: string;
226
- id: string;
227
- slug: string;
228
- createdAt: Date;
229
- updatedAt: Date;
230
- deletedAt: Date | null;
231
- brandId: string;
232
- isActive: boolean;
233
- description: string | null;
234
- thumbnailUrl: string | null;
235
- quantityDiscounts: import("@prisma/client/runtime/library").JsonValue | null;
236
- };
237
- name: string | null;
238
- id: string;
239
- createdAt: Date;
240
- updatedAt: Date;
241
- deletedAt: Date | null;
242
- isActive: boolean;
243
- thumbnailUrl: string | null;
244
- productId: string;
245
- sku: string;
246
- trackInventory: boolean;
247
- lowStockThreshold: number | null;
248
- };
249
- quantity: number;
250
- basePrice: number;
251
- discountPercent: number;
252
- finalPrice: number;
253
- subtotal: number;
254
- }[];
255
- pricing: {
256
- subtotal: number;
257
- deliveryCharge: number;
258
- discount: import("./cart-response").DiscountInfo;
259
- total: number;
260
- };
261
- createdAt: string;
262
- updatedAt: string;
263
- expiresAt: string;
264
- convertedToOrderId: string;
265
- wasRecovered: boolean;
266
- recoveryUrl: string;
267
- }>;
268
- /**
269
- * Generate ETag from date
270
- */
271
- export declare function etagFrom(date: Date): string;
272
- /**
273
- * Derive payment methods from delivery zone
274
- */
275
- export declare function paymentFromZone(zone: {
276
- allowCOD: boolean;
277
- allowOnline: boolean;
278
- waybillOnly: boolean;
279
- }): ('cod' | 'online')[];
280
- export {};
@@ -1,93 +0,0 @@
1
- import { buildCartResponseWithPricing } from './cart-response';
2
- /**
3
- * Standard include pattern for cart queries with all necessary relations
4
- */
5
- export const CART_INCLUDE_FULL = {
6
- brand: true,
7
- deliveryZone: true,
8
- recoveryDiscountCode: true,
9
- items: {
10
- include: {
11
- variant: {
12
- include: {
13
- product: true,
14
- },
15
- },
16
- },
17
- },
18
- };
19
- /**
20
- * Include pattern for cart item queries that need the parent cart
21
- */
22
- export const CART_ITEM_WITH_CART_INCLUDE = {
23
- cart: {
24
- include: {
25
- brand: true
26
- }
27
- },
28
- };
29
- /**
30
- * Include pattern for order creation with discount code
31
- */
32
- export const ORDER_INCLUDE_FULL = {
33
- brand: true,
34
- deliveryZone: { include: { state: true } },
35
- items: {
36
- include: {
37
- variant: {
38
- include: {
39
- product: true,
40
- },
41
- },
42
- warehouse: true,
43
- },
44
- },
45
- };
46
- async function getCartWithRelations(prisma, cartId) {
47
- return await prisma.cart.findUnique({
48
- where: { id: cartId },
49
- include: CART_INCLUDE_FULL,
50
- });
51
- }
52
- /**
53
- * Validate cart exists and is not expired
54
- */
55
- export async function validateCart(prisma, cartId) {
56
- const cart = await getCartWithRelations(prisma, cartId);
57
- if (!cart) {
58
- return {
59
- cart: null,
60
- error: { code: 'CART_NOT_FOUND', message: 'Cart not found', status: 404 }
61
- };
62
- }
63
- if (cart.expiresAt < new Date()) {
64
- return {
65
- cart: null,
66
- error: { code: 'CART_EXPIRED', message: 'Cart has expired', status: 410 }
67
- };
68
- }
69
- return { cart };
70
- }
71
- /**
72
- * Build cart response with pricing calculations
73
- */
74
- export async function buildCartResponse(prisma, cart) {
75
- return await buildCartResponseWithPricing(prisma, cart);
76
- }
77
- /**
78
- * Generate ETag from date
79
- */
80
- export function etagFrom(date) {
81
- return `W/"${date.getTime()}"`;
82
- }
83
- /**
84
- * Derive payment methods from delivery zone
85
- */
86
- export function paymentFromZone(zone) {
87
- const out = [];
88
- if (zone.allowOnline)
89
- out.push('online');
90
- if (zone.allowCOD && !zone.waybillOnly)
91
- out.push('cod');
92
- return out;
93
- }
@@ -1,30 +0,0 @@
1
- /**
2
- * Abandoned cart recovery scheduler
3
- * Handles automatic sending of recovery WhatsApp messages at different intervals
4
- */
5
- import type { PrismaClient } from '@prisma/client';
6
- import type { CartWithItemsAndBrand } from './cart-response';
7
- /**
8
- * Recovery schedule configuration
9
- */
10
- export declare const RECOVERY_SCHEDULE: {
11
- attemptNumber: number;
12
- hoursAfterAbandonment: number;
13
- discountPercent: number;
14
- }[];
15
- /**
16
- * Find carts eligible for recovery message at specific attempt
17
- */
18
- export declare function findCartsForRecovery(prisma: PrismaClient, attemptNumber: number): Promise<any[]>;
19
- /**
20
- * Prepares a cart for a recovery attempt.
21
- * This is the key atomic operation that:
22
- * 1. Updates the recovery attempt number to prevent duplicate messages
23
- * 2. Creates/updates the recovery discount code
24
- * 3. Applies the discount to the cart
25
- * This should be called *before* queueing any notifications.
26
- */
27
- export declare function prepareCartForRecoveryAttempt(prisma: PrismaClient, cart: CartWithItemsAndBrand, attemptNumber: number): Promise<{
28
- success: boolean;
29
- cartWithDiscount?: CartWithItemsAndBrand;
30
- }>;