@instockng/api-client 1.0.8 → 1.0.10

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