@instockng/api-client 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apps/backend/src/generated/zod/index.d.ts +1114 -0
- package/dist/apps/backend/src/generated/zod/index.js +670 -0
- package/dist/apps/backend/src/http-app.d.ts +40 -0
- package/dist/apps/backend/src/http-app.js +106 -0
- package/dist/apps/backend/src/lib/brand-response.d.ts +14 -0
- package/dist/apps/backend/src/lib/brand-response.js +8 -0
- package/dist/apps/backend/src/lib/cart-helpers.d.ts +280 -0
- package/dist/apps/backend/src/lib/cart-helpers.js +93 -0
- package/dist/apps/backend/src/lib/cart-recovery.d.ts +30 -0
- package/dist/apps/backend/src/lib/cart-recovery.js +147 -0
- package/dist/apps/backend/src/lib/cart-response.d.ts +121 -0
- package/dist/apps/backend/src/lib/cart-response.js +150 -0
- package/dist/apps/backend/src/lib/clerk.d.ts +18 -0
- package/dist/apps/backend/src/lib/clerk.js +167 -0
- package/dist/apps/backend/src/lib/delivery-zone-response.d.ts +62 -0
- package/dist/apps/backend/src/lib/delivery-zone-response.js +24 -0
- package/dist/apps/backend/src/lib/discount-code-response.d.ts +42 -0
- package/dist/apps/backend/src/lib/discount-code-response.js +19 -0
- package/dist/apps/backend/src/lib/discount.d.ts +20 -0
- package/dist/apps/backend/src/lib/discount.js +35 -0
- package/dist/apps/backend/src/lib/inventory.d.ts +26 -0
- package/dist/apps/backend/src/lib/inventory.js +160 -0
- package/dist/apps/backend/src/lib/meta-capi.d.ts +48 -0
- package/dist/apps/backend/src/lib/meta-capi.js +120 -0
- package/dist/apps/backend/src/lib/openapi.d.ts +36 -0
- package/dist/apps/backend/src/lib/openapi.js +69 -0
- package/dist/apps/backend/src/lib/order-recovery.d.ts +367 -0
- package/dist/apps/backend/src/lib/order-recovery.js +373 -0
- package/dist/apps/backend/src/lib/order-response.d.ts +136 -0
- package/dist/apps/backend/src/lib/order-response.js +61 -0
- package/dist/apps/backend/src/lib/pricing.d.ts +39 -0
- package/dist/apps/backend/src/lib/pricing.js +62 -0
- package/dist/apps/backend/src/lib/prisma.d.ts +9 -0
- package/dist/apps/backend/src/lib/prisma.js +30 -0
- package/dist/apps/backend/src/lib/product-response.d.ts +82 -0
- package/dist/apps/backend/src/lib/product-response.js +29 -0
- package/dist/apps/backend/src/lib/utils.d.ts +32 -0
- package/dist/apps/backend/src/lib/utils.js +63 -0
- package/dist/apps/backend/src/middleware/clerk-auth.d.ts +8 -0
- package/dist/apps/backend/src/middleware/clerk-auth.js +89 -0
- package/dist/apps/backend/src/middleware/cors.d.ts +8 -0
- package/dist/apps/backend/src/middleware/cors.js +11 -0
- package/dist/apps/backend/src/notifications/producers/meta-capi-producer.d.ts +55 -0
- package/dist/apps/backend/src/notifications/producers/meta-capi-producer.js +125 -0
- package/dist/apps/backend/src/notifications/producers/order-notification.d.ts +9 -0
- package/dist/apps/backend/src/notifications/producers/order-notification.js +18 -0
- package/dist/apps/backend/src/notifications/producers/prospect-recovery-notification.d.ts +10 -0
- package/dist/apps/backend/src/notifications/producers/prospect-recovery-notification.js +11 -0
- package/dist/apps/backend/src/routes/admin/abandoned-carts.d.ts +605 -0
- package/dist/apps/backend/src/routes/admin/abandoned-carts.js +194 -0
- package/dist/apps/backend/src/routes/admin/brands.d.ts +175 -0
- package/dist/apps/backend/src/routes/admin/brands.js +118 -0
- package/dist/apps/backend/src/routes/admin/customers.d.ts +306 -0
- package/dist/apps/backend/src/routes/admin/customers.js +39 -0
- package/dist/apps/backend/src/routes/admin/delivery-zones.d.ts +438 -0
- package/dist/apps/backend/src/routes/admin/delivery-zones.js +300 -0
- package/dist/apps/backend/src/routes/admin/discount-codes.d.ts +478 -0
- package/dist/apps/backend/src/routes/admin/discount-codes.js +418 -0
- package/dist/apps/backend/src/routes/admin/inventory.d.ts +273 -0
- package/dist/apps/backend/src/routes/admin/inventory.js +189 -0
- package/dist/apps/backend/src/routes/admin/orders.d.ts +1478 -0
- package/dist/apps/backend/src/routes/admin/orders.js +503 -0
- package/dist/apps/backend/src/routes/admin/products.d.ts +860 -0
- package/dist/apps/backend/src/routes/admin/products.js +107 -0
- package/dist/apps/backend/src/routes/admin/stats.d.ts +288 -0
- package/dist/apps/backend/src/routes/admin/stats.js +55 -0
- package/dist/apps/backend/src/routes/admin/variants.d.ts +239 -0
- package/dist/apps/backend/src/routes/admin/variants.js +173 -0
- package/dist/apps/backend/src/routes/admin/warehouses.d.ts +373 -0
- package/dist/apps/backend/src/routes/admin/warehouses.js +123 -0
- package/dist/apps/backend/src/routes/public/brands.d.ts +40 -0
- package/dist/apps/backend/src/routes/public/brands.js +38 -0
- package/dist/apps/backend/src/routes/public/carts.d.ts +2655 -0
- package/dist/apps/backend/src/routes/public/carts.js +631 -0
- package/dist/apps/backend/src/routes/public/delivery-zones.d.ts +35 -0
- package/dist/apps/backend/src/routes/public/delivery-zones.js +62 -0
- package/dist/apps/backend/src/routes/public/orders.d.ts +323 -0
- package/dist/apps/backend/src/routes/public/orders.js +160 -0
- package/dist/apps/backend/src/routes/public/products.d.ts +449 -0
- package/dist/apps/backend/src/routes/public/products.js +133 -0
- package/dist/apps/backend/src/types/index.d.ts +42 -0
- package/dist/apps/backend/src/types/index.js +2 -0
- package/dist/apps/backend/src/validators/brand.d.ts +17 -0
- package/dist/apps/backend/src/validators/brand.js +15 -0
- package/dist/apps/backend/src/validators/delivery-zone.d.ts +31 -0
- package/dist/apps/backend/src/validators/delivery-zone.js +51 -0
- package/dist/apps/backend/src/validators/discount-code.d.ts +74 -0
- package/dist/apps/backend/src/validators/discount-code.js +50 -0
- package/dist/apps/backend/src/validators/inventory.d.ts +20 -0
- package/dist/apps/backend/src/validators/inventory.js +15 -0
- package/dist/apps/backend/src/validators/order.d.ts +87 -0
- package/dist/apps/backend/src/validators/order.js +61 -0
- package/dist/apps/backend/src/validators/product.d.ts +18 -0
- package/dist/apps/backend/src/validators/product.js +19 -0
- package/dist/apps/backend/src/validators/variant.d.ts +19 -0
- package/dist/apps/backend/src/validators/variant.js +19 -0
- package/dist/apps/backend/src/validators/warehouse.d.ts +15 -0
- package/dist/apps/backend/src/validators/warehouse.js +15 -0
- package/dist/fetchers/carts.d.ts +751 -755
- package/dist/fetchers/carts.js +4 -2
- package/dist/hooks/public/carts.d.ts +753 -755
- package/dist/hooks/public/carts.js +2 -2
- package/dist/packages/api-client/src/backend-types.d.ts +10 -0
- package/dist/packages/api-client/src/backend-types.js +10 -0
- package/dist/packages/api-client/src/client.d.ts +20 -0
- package/dist/packages/api-client/src/client.js +40 -0
- package/dist/packages/api-client/src/fetchers/brands.d.ts +25 -0
- package/dist/packages/api-client/src/fetchers/brands.js +26 -0
- package/dist/packages/api-client/src/fetchers/carts.d.ts +2335 -0
- package/dist/packages/api-client/src/fetchers/carts.js +169 -0
- package/dist/packages/api-client/src/fetchers/delivery-zones.d.ts +28 -0
- package/dist/packages/api-client/src/fetchers/delivery-zones.js +26 -0
- package/dist/packages/api-client/src/fetchers/index.d.ts +22 -0
- package/dist/packages/api-client/src/fetchers/index.js +22 -0
- package/dist/packages/api-client/src/fetchers/orders.d.ts +283 -0
- package/dist/packages/api-client/src/fetchers/orders.js +44 -0
- package/dist/packages/api-client/src/fetchers/products.d.ts +386 -0
- package/dist/packages/api-client/src/fetchers/products.js +42 -0
- package/dist/packages/api-client/src/hooks/admin/abandoned-carts.d.ts +535 -0
- package/dist/packages/api-client/src/hooks/admin/abandoned-carts.js +79 -0
- package/dist/packages/api-client/src/hooks/admin/brands.d.ts +79 -0
- package/dist/packages/api-client/src/hooks/admin/brands.js +103 -0
- package/dist/packages/api-client/src/hooks/admin/customers.d.ts +278 -0
- package/dist/packages/api-client/src/hooks/admin/customers.js +25 -0
- package/dist/packages/api-client/src/hooks/admin/delivery-zones.d.ts +270 -0
- package/dist/packages/api-client/src/hooks/admin/delivery-zones.js +168 -0
- package/dist/packages/api-client/src/hooks/admin/discount-codes.d.ts +299 -0
- package/dist/packages/api-client/src/hooks/admin/discount-codes.js +157 -0
- package/dist/packages/api-client/src/hooks/admin/index.d.ts +16 -0
- package/dist/packages/api-client/src/hooks/admin/index.js +16 -0
- package/dist/packages/api-client/src/hooks/admin/inventory.d.ts +224 -0
- package/dist/packages/api-client/src/hooks/admin/inventory.js +102 -0
- package/dist/packages/api-client/src/hooks/admin/orders.d.ts +1380 -0
- package/dist/packages/api-client/src/hooks/admin/orders.js +169 -0
- package/dist/packages/api-client/src/hooks/admin/products.d.ts +374 -0
- package/dist/packages/api-client/src/hooks/admin/products.js +84 -0
- package/dist/packages/api-client/src/hooks/admin/stats.d.ts +277 -0
- package/dist/packages/api-client/src/hooks/admin/stats.js +24 -0
- package/dist/packages/api-client/src/hooks/admin/variants.d.ts +115 -0
- package/dist/packages/api-client/src/hooks/admin/variants.js +121 -0
- package/dist/packages/api-client/src/hooks/admin/warehouses.d.ts +277 -0
- package/dist/packages/api-client/src/hooks/admin/warehouses.js +103 -0
- package/dist/packages/api-client/src/hooks/public/brands.d.ts +33 -0
- package/dist/packages/api-client/src/hooks/public/brands.js +30 -0
- package/dist/packages/api-client/src/hooks/public/carts.d.ts +2405 -0
- package/dist/packages/api-client/src/hooks/public/carts.js +213 -0
- package/dist/packages/api-client/src/hooks/public/delivery-zones.d.ts +34 -0
- package/dist/packages/api-client/src/hooks/public/delivery-zones.js +28 -0
- package/dist/packages/api-client/src/hooks/public/index.d.ts +10 -0
- package/dist/packages/api-client/src/hooks/public/index.js +10 -0
- package/dist/packages/api-client/src/hooks/public/orders.d.ts +302 -0
- package/dist/packages/api-client/src/hooks/public/orders.js +50 -0
- package/dist/packages/api-client/src/hooks/public/products.d.ts +398 -0
- package/dist/packages/api-client/src/hooks/public/products.js +47 -0
- package/dist/packages/api-client/src/hooks/use-query-unwrapped.d.ts +20 -0
- package/dist/packages/api-client/src/hooks/use-query-unwrapped.js +22 -0
- package/dist/packages/api-client/src/hooks/useApiConfig.d.ts +11 -0
- package/dist/packages/api-client/src/hooks/useApiConfig.js +14 -0
- package/dist/packages/api-client/src/index.d.ts +20 -0
- package/dist/packages/api-client/src/index.js +25 -0
- package/dist/packages/api-client/src/provider.d.ts +33 -0
- package/dist/packages/api-client/src/provider.js +52 -0
- package/dist/packages/api-client/src/rpc-client.d.ts +9035 -0
- package/dist/packages/api-client/src/rpc-client.js +78 -0
- package/dist/packages/api-client/src/rpc-types.d.ts +76 -0
- package/dist/packages/api-client/src/rpc-types.js +7 -0
- package/dist/packages/api-client/src/types.d.ts +33 -0
- package/dist/packages/api-client/src/types.js +16 -0
- package/dist/packages/api-client/src/utils/query-keys.d.ts +106 -0
- package/dist/packages/api-client/src/utils/query-keys.js +108 -0
- package/dist/rpc-client.d.ts +685 -693
- package/package.json +2 -2
|
@@ -0,0 +1,40 @@
|
|
|
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, {}, "/">;
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,280 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}>;
|