fix: expose client fetch and signed adjustments
Quality / quality (ubuntu-latest) (push) Failing after 9m49s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
2026-08-23 18:56:05 +05:30
parent 6258495b67
commit 4be4b2c346
8 changed files with 64 additions and 8 deletions
+14 -2
View File
@@ -90,6 +90,10 @@ export function defineMeter(options: MeterOptions) {
Number.isSafeInteger(units) && units > 0
? null
: { ok: false, reason: `${label} must be a positive whole number` };
const validSigned = (units: number): MeterResult | null =>
Number.isSafeInteger(units) && units !== 0
? null
: { ok: false, reason: `${label} adjustment must be a non-zero whole number` };
const fault = (error: unknown, operation: string): MeterResult => {
options.onFault?.(error, operation);
return {
@@ -138,7 +142,15 @@ export function defineMeter(options: MeterOptions) {
add("purchase", subjectId, units, reason, reference),
refund: (subjectId: string, units: number, reason: string, reference = "") =>
add("refund", subjectId, units, reason, reference),
adjust: (subjectId: string, units: number, reason: string, reference = "") =>
add("adjust", subjectId, units, reason, reference),
async adjust(subjectId: string, units: number, reason: string, reference = "") {
const invalid = validSigned(units);
if (invalid) return invalid;
try {
await options.store.write(subjectId, units, "adjust", reason, reference);
return { ok: true } as const;
} catch (error) {
return fault(error, "adjust");
}
},
};
}