Files
co-lite/solvway-admin-portal/app/lib/services/adminPos.ts
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

97 lines
4.1 KiB
TypeScript

import { apiGet, apiPost } from "@/app/lib/clientApi";
import type {
PosSellableEvent,
PosEventProduct,
PosTender,
PosPlaceSalePayload,
PosPlaceSaleResult,
PosWalletBalanceView,
PosWalletPreviewPayload,
PosWalletSalePayload,
PosWalletSaleResult,
MemberCheckoutPreviewResult,
CounterSplitSalePayload,
SplitSaleResult,
SplitSettlementStatus,
PosQuotePayload,
PickupOutletRow,
} from "@/app/lib/types";
// Client-side wrapper for the /pos page (add-event-pos-counter-sales, Task 10). Calls only the
// portal's own /api/pos/* route handlers — never solvway-mobile-api directly. Ids stay as strings
// end-to-end (repo convention snowflake-ids-json-string). All mutations go through apiPost so a
// Next.js GET prefetch can never trigger a sale (CLAUDE.md GET-prefetch rule).
export function listSellableEvents(): Promise<PosSellableEvent[]> {
return apiGet<PosSellableEvent[]>("/api/pos/events");
}
/** With an event, each row carries that event's warehouse availability (add-sale-channel-stock-badges). */
export function listEventProducts(eventId?: string): Promise<PosEventProduct[]> {
const qs = eventId ? `?eventId=${encodeURIComponent(eventId)}` : "";
return apiGet<PosEventProduct[]>(`/api/pos/products${qs}`);
}
/** List the POS-enabled, active tenders for the branch (add-pos-tender-recording, 2b). Pure read. */
export function listPosTenders(): Promise<PosTender[]> {
return apiGet<PosTender[]>("/api/pos/payment-methods");
}
export function placeSale(payload: PosPlaceSalePayload): Promise<PosPlaceSaleResult> {
return apiPost<PosPlaceSaleResult>("/api/pos/sale", payload);
}
// --- Wallet tender functions (Brick 3 Task 6) ---
// The PIN (candidatePin) is held only for the duration of the placeWalletSale call
// and is never stored, logged, or persisted client-side.
/** Read member wallet balances + PIN status for the wallet tender UI. Pure read — GET. */
export function readMemberWallet(memberCode: string): Promise<PosWalletBalanceView> {
return apiGet<PosWalletBalanceView>(
`/api/pos/wallet/${encodeURIComponent(memberCode)}`,
);
}
/** Preview the settlement split before placing a wallet sale. Mutation path — POST. */
export function previewWallet(
payload: PosWalletPreviewPayload,
): Promise<MemberCheckoutPreviewResult> {
return apiPost<MemberCheckoutPreviewResult>("/api/pos/wallet/preview", payload);
}
/** Price the Event POS cart net of promotions. Nothing is paid or written — POST so a prefetch never fires it. */
export function quoteSale(payload: PosQuotePayload): Promise<MemberCheckoutPreviewResult> {
return apiPost<MemberCheckoutPreviewResult>("/api/pos/quote", payload);
}
/**
* Place a wallet event sale authorized by the member's PIN.
* The candidatePin value must be discarded immediately after this call returns.
*/
export function placeWalletSale(payload: PosWalletSalePayload): Promise<PosWalletSaleResult> {
return apiPost<PosWalletSaleResult>("/api/pos/wallet/sale", payload);
}
// --- Split-tender (wallet + cash + gateway) sale + poll/cancel (split-payment gateway) ---
// The candidatePin (present only when a wallet amount is above 0) is held only for the duration of the
// placeSplitSale call and is never stored, logged, or persisted client-side.
/** Place an Event POS split-tender sale. Mutation path — POST. */
export function placeSplitSale(payload: CounterSplitSalePayload): Promise<SplitSaleResult> {
return apiPost<SplitSaleResult>("/api/pos/split/sale", payload);
}
/** Poll a split gateway sale's settlement state. Pure read — GET, prefetch-safe. */
export function pollSplitStatus(uuid: string): Promise<SplitSettlementStatus> {
return apiGet<SplitSettlementStatus>(`/api/pos/split/status/${encodeURIComponent(uuid)}`);
}
/** Cancel a still-pending split gateway sale (releases reserved stock). Mutation path — POST. */
export function cancelSplit(uuid: string): Promise<boolean> {
return apiPost<boolean>(`/api/pos/split/cancel/${encodeURIComponent(uuid)}`);
}
export function listPosPickupOutlets(): Promise<PickupOutletRow[]> {
return apiGet<PickupOutletRow[]>("/api/pos/pickup-outlets");
}