@teincfood/core 0.9.3 → 0.9.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.
|
@@ -13,6 +13,7 @@ import { insertCommand, getPendingCommands, markCommandInFlight, updateCommandSt
|
|
|
13
13
|
import { syncLogger } from "../utils/sync-logger";
|
|
14
14
|
import { recordAttempt } from "../utils/attempt-stats";
|
|
15
15
|
import { TransitionError, isReplayDeferred, TRANSITION_ERROR_CODES } from "./transition-errors";
|
|
16
|
+
import { assertBusinessOpenForCreate } from "../utils/business-hours";
|
|
16
17
|
import { extractApiErrorCode } from "../utils/error";
|
|
17
18
|
import { generateEventId } from "../utils/uuid";
|
|
18
19
|
import { generateLocalCalloutNumber, generateOrderNumberForBusiness, generateOrderNumber, } from "./order-number";
|
|
@@ -203,6 +204,14 @@ class CommandQueueService {
|
|
|
203
204
|
* Returns an optimistic domain event so the caller can update the UI.
|
|
204
205
|
*/
|
|
205
206
|
async enqueue(command) {
|
|
207
|
+
// Queue-time hours gate: a closed business can never legally sync an
|
|
208
|
+
// order:create, so fail fast with BusinessHoursError instead of queuing
|
|
209
|
+
// an optimistic order that would sit pending forever. Other command
|
|
210
|
+
// types (transitions, payments, delivery) are unaffected so in-progress
|
|
211
|
+
// orders can still be completed while closed.
|
|
212
|
+
if (command.command_type === "order:create") {
|
|
213
|
+
await assertBusinessOpenForCreate(command.business_id);
|
|
214
|
+
}
|
|
206
215
|
const db = getSyncDatabase();
|
|
207
216
|
const preparedCommand = injectLocalOrderNumber(command);
|
|
208
217
|
await insertCommand(db, { command: preparedCommand, status: "pending" });
|
package/dist/sync/engine.js
CHANGED
|
@@ -149,6 +149,20 @@ export class SyncEngine {
|
|
|
149
149
|
return events;
|
|
150
150
|
}
|
|
151
151
|
catch (error) {
|
|
152
|
+
// Definitive hours-guard rejection (thrown by createLocalOrder before
|
|
153
|
+
// any HTTP): the business is closed. Surface it immediately — do not
|
|
154
|
+
// mark cloud unreachable and do not fall back to the outbox, which
|
|
155
|
+
// would either re-throw from the enqueue gate or mask a real decision
|
|
156
|
+
// as a connectivity problem.
|
|
157
|
+
const code = errorCodeOf(error);
|
|
158
|
+
if (code === "BUSINESS_CLOSED" || code === "HOURS_NOT_SYNCED") {
|
|
159
|
+
syncLogger.warn("SyncEngine", "Command blocked: business closed", {
|
|
160
|
+
command_type: command.command_type,
|
|
161
|
+
command_id: command.command_id,
|
|
162
|
+
code,
|
|
163
|
+
});
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
152
166
|
// Definitive server rejection (4xx): the backend answered with a real
|
|
153
167
|
// decision (e.g. INVALID_TRANSITION, PAYMENT_REQUIRED, FORBIDDEN).
|
|
154
168
|
// Surface it instead of masking it as a connectivity problem and
|
|
@@ -159,7 +173,6 @@ export class SyncEngine {
|
|
|
159
173
|
? error.status
|
|
160
174
|
: undefined;
|
|
161
175
|
if (rejectionStatus !== undefined && rejectionStatus >= 400 && rejectionStatus < 500) {
|
|
162
|
-
const code = errorCodeOf(error);
|
|
163
176
|
syncLogger.warn("SyncEngine", "Cloud command rejected by server", {
|
|
164
177
|
command_type: command.command_type,
|
|
165
178
|
command_id: command.command_id,
|
package/package.json
CHANGED