pi-kiosk-shared 1.0.11 → 1.0.13
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/api.d.ts +10 -0
- package/dist/api.js +15 -1
- package/dist/types.d.ts +16 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +42 -0
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
export declare const API_ENDPOINTS: {
|
|
2
2
|
readonly PRODUCTS: "/api/products";
|
|
3
3
|
readonly PRODUCT_CLICK: "/api/products/:id/click";
|
|
4
|
+
readonly PAYMENT_CREATE_QR: "/api/payments/create-qr";
|
|
5
|
+
readonly PAYMENT_CREATE_MULTI_QR: "/api/payments/create-multi-qr";
|
|
6
|
+
readonly PAYMENT_CHECK_STATUS: "/api/payments/check-status/:paymentId";
|
|
7
|
+
readonly PAYMENT_COMPLETE: "/api/payments/complete";
|
|
4
8
|
readonly ADMIN_LOGIN: "/admin/login";
|
|
5
9
|
readonly ADMIN_PRODUCTS: "/admin/products";
|
|
10
|
+
readonly ADMIN_PRODUCTS_INVENTORY: "/admin/products/inventory/:kioskId";
|
|
11
|
+
readonly ADMIN_PRODUCT_INVENTORY: "/admin/products/:id/inventory";
|
|
12
|
+
readonly ADMIN_PRODUCT_INVENTORY_UPDATE: "/admin/products/:productId/inventory/:kioskId";
|
|
13
|
+
readonly ADMIN_PRODUCT_VISIBILITY: "/admin/products/:productId/visibility/:kioskId";
|
|
6
14
|
readonly ADMIN_KIOSKS: "/admin/kiosks";
|
|
15
|
+
readonly ADMIN_KIOSK_DETAILS: "/admin/kiosks/:id";
|
|
7
16
|
readonly HEALTH: "/health";
|
|
8
17
|
readonly CHECK_TRANSACTIONS: "/api/check-new-transactions";
|
|
18
|
+
readonly EVENTS: "/events/:kioskId";
|
|
9
19
|
};
|
|
10
20
|
export declare class APIClient {
|
|
11
21
|
private baseUrl;
|
package/dist/api.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
// Shared API utilities
|
|
2
2
|
export const API_ENDPOINTS = {
|
|
3
|
+
// Product endpoints
|
|
3
4
|
PRODUCTS: '/api/products',
|
|
4
5
|
PRODUCT_CLICK: '/api/products/:id/click',
|
|
6
|
+
// Payment endpoints
|
|
7
|
+
PAYMENT_CREATE_QR: '/api/payments/create-qr',
|
|
8
|
+
PAYMENT_CREATE_MULTI_QR: '/api/payments/create-multi-qr',
|
|
9
|
+
PAYMENT_CHECK_STATUS: '/api/payments/check-status/:paymentId',
|
|
10
|
+
PAYMENT_COMPLETE: '/api/payments/complete',
|
|
11
|
+
// Admin endpoints
|
|
5
12
|
ADMIN_LOGIN: '/admin/login',
|
|
6
13
|
ADMIN_PRODUCTS: '/admin/products',
|
|
14
|
+
ADMIN_PRODUCTS_INVENTORY: '/admin/products/inventory/:kioskId',
|
|
15
|
+
ADMIN_PRODUCT_INVENTORY: '/admin/products/:id/inventory',
|
|
16
|
+
ADMIN_PRODUCT_INVENTORY_UPDATE: '/admin/products/:productId/inventory/:kioskId',
|
|
17
|
+
ADMIN_PRODUCT_VISIBILITY: '/admin/products/:productId/visibility/:kioskId',
|
|
7
18
|
ADMIN_KIOSKS: '/admin/kiosks',
|
|
19
|
+
ADMIN_KIOSK_DETAILS: '/admin/kiosks/:id',
|
|
20
|
+
// System endpoints
|
|
8
21
|
HEALTH: '/health',
|
|
9
|
-
CHECK_TRANSACTIONS: '/api/check-new-transactions'
|
|
22
|
+
CHECK_TRANSACTIONS: '/api/check-new-transactions',
|
|
23
|
+
EVENTS: '/events/:kioskId'
|
|
10
24
|
};
|
|
11
25
|
export class APIClient {
|
|
12
26
|
constructor(baseUrl, kioskSecret) {
|
package/dist/types.d.ts
CHANGED
|
@@ -9,6 +9,15 @@ export interface Product {
|
|
|
9
9
|
clickedOn: number;
|
|
10
10
|
numberOfPurchases: number;
|
|
11
11
|
}
|
|
12
|
+
export interface CartItem {
|
|
13
|
+
product: Product;
|
|
14
|
+
quantity: number;
|
|
15
|
+
}
|
|
16
|
+
export interface Cart {
|
|
17
|
+
items: CartItem[];
|
|
18
|
+
totalAmount: number;
|
|
19
|
+
totalItems: number;
|
|
20
|
+
}
|
|
12
21
|
export interface PaymentData {
|
|
13
22
|
productId: number;
|
|
14
23
|
productName: string;
|
|
@@ -17,6 +26,13 @@ export interface PaymentData {
|
|
|
17
26
|
qrCode: string;
|
|
18
27
|
paymentId: string;
|
|
19
28
|
}
|
|
29
|
+
export interface MultiProductPaymentData {
|
|
30
|
+
items: CartItem[];
|
|
31
|
+
totalAmount: number;
|
|
32
|
+
customerEmail: string;
|
|
33
|
+
qrCode: string;
|
|
34
|
+
paymentId: string;
|
|
35
|
+
}
|
|
20
36
|
export interface AdminProduct {
|
|
21
37
|
id: number;
|
|
22
38
|
name: string;
|
package/dist/utils.d.ts
CHANGED
|
@@ -6,3 +6,12 @@ export declare const formatDate: (date: Date | string) => string;
|
|
|
6
6
|
export declare const debounce: <T extends (...args: any[]) => any>(func: T, delay: number) => ((...args: Parameters<T>) => void);
|
|
7
7
|
export declare const generatePaymentId: () => string;
|
|
8
8
|
export declare const validateKioskId: (kioskId: number) => boolean;
|
|
9
|
+
export declare const createEmptyCart: () => {
|
|
10
|
+
items: never[];
|
|
11
|
+
totalAmount: number;
|
|
12
|
+
totalItems: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const addToCart: (cart: any, product: any, quantity?: number) => any;
|
|
15
|
+
export declare const removeFromCart: (cart: any, productId: number) => any;
|
|
16
|
+
export declare const updateCartItemQuantity: (cart: any, productId: number, quantity: number) => any;
|
|
17
|
+
export declare const clearCart: (cart: any) => any;
|
package/dist/utils.js
CHANGED
|
@@ -48,4 +48,46 @@ export const generatePaymentId = () => {
|
|
|
48
48
|
export const validateKioskId = (kioskId) => {
|
|
49
49
|
return Number.isInteger(kioskId) && kioskId > 0;
|
|
50
50
|
};
|
|
51
|
+
// Cart utility functions
|
|
52
|
+
export const createEmptyCart = () => ({
|
|
53
|
+
items: [],
|
|
54
|
+
totalAmount: 0,
|
|
55
|
+
totalItems: 0
|
|
56
|
+
});
|
|
57
|
+
export const addToCart = (cart, product, quantity = 1) => {
|
|
58
|
+
const existingItem = cart.items.find((item) => item.product.id === product.id);
|
|
59
|
+
if (existingItem) {
|
|
60
|
+
existingItem.quantity += quantity;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
cart.items.push({ product, quantity });
|
|
64
|
+
}
|
|
65
|
+
cart.totalAmount = cart.items.reduce((sum, item) => sum + (item.product.price * item.quantity), 0);
|
|
66
|
+
cart.totalItems = cart.items.reduce((sum, item) => sum + item.quantity, 0);
|
|
67
|
+
return cart;
|
|
68
|
+
};
|
|
69
|
+
export const removeFromCart = (cart, productId) => {
|
|
70
|
+
cart.items = cart.items.filter((item) => item.product.id !== productId);
|
|
71
|
+
cart.totalAmount = cart.items.reduce((sum, item) => sum + (item.product.price * item.quantity), 0);
|
|
72
|
+
cart.totalItems = cart.items.reduce((sum, item) => sum + item.quantity, 0);
|
|
73
|
+
return cart;
|
|
74
|
+
};
|
|
75
|
+
export const updateCartItemQuantity = (cart, productId, quantity) => {
|
|
76
|
+
const item = cart.items.find((item) => item.product.id === productId);
|
|
77
|
+
if (item) {
|
|
78
|
+
if (quantity <= 0) {
|
|
79
|
+
return removeFromCart(cart, productId);
|
|
80
|
+
}
|
|
81
|
+
item.quantity = quantity;
|
|
82
|
+
cart.totalAmount = cart.items.reduce((sum, item) => sum + (item.product.price * item.quantity), 0);
|
|
83
|
+
cart.totalItems = cart.items.reduce((sum, item) => sum + item.quantity, 0);
|
|
84
|
+
}
|
|
85
|
+
return cart;
|
|
86
|
+
};
|
|
87
|
+
export const clearCart = (cart) => {
|
|
88
|
+
cart.items = [];
|
|
89
|
+
cart.totalAmount = 0;
|
|
90
|
+
cart.totalItems = 0;
|
|
91
|
+
return cart;
|
|
92
|
+
};
|
|
51
93
|
// Note: getErrorMessage is now exported from ./errors.ts instead
|