@open-mercato/core 0.9.1-develop.7513.1.ae2715553f → 0.9.1-develop.7515.1.e2712c8b00
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/.turbo/turbo-build.log +1 -1
- package/dist/modules/shipping_carriers/api/webhook/[provider]/route.js +4 -7
- package/dist/modules/shipping_carriers/api/webhook/[provider]/route.js.map +2 -2
- package/dist/modules/shipping_carriers/lib/shipping-service.js +29 -11
- package/dist/modules/shipping_carriers/lib/shipping-service.js.map +2 -2
- package/dist/modules/shipping_carriers/lib/status-sync.js +2 -2
- package/dist/modules/shipping_carriers/lib/status-sync.js.map +2 -2
- package/dist/modules/shipping_carriers/workers/webhook-processor.js +60 -33
- package/dist/modules/shipping_carriers/workers/webhook-processor.js.map +3 -3
- package/dist/modules/warranty_claims/commands/claim-lines.js +89 -68
- package/dist/modules/warranty_claims/commands/claim-lines.js.map +2 -2
- package/dist/modules/warranty_claims/commands/claims.js +14 -13
- package/dist/modules/warranty_claims/commands/claims.js.map +2 -2
- package/dist/modules/warranty_claims/commands/shared.js +8 -2
- package/dist/modules/warranty_claims/commands/shared.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/shipping_carriers/api/webhook/[provider]/route.ts +4 -7
- package/src/modules/shipping_carriers/lib/shipping-service.ts +29 -11
- package/src/modules/shipping_carriers/lib/status-sync.ts +2 -2
- package/src/modules/shipping_carriers/workers/webhook-processor.ts +71 -39
- package/src/modules/warranty_claims/commands/claim-lines.ts +107 -66
- package/src/modules/warranty_claims/commands/claims.ts +14 -13
- package/src/modules/warranty_claims/commands/shared.ts +7 -1
|
@@ -68,6 +68,7 @@ import {
|
|
|
68
68
|
ensureTenantScope,
|
|
69
69
|
extractUndoPayload,
|
|
70
70
|
requireScopedClaim,
|
|
71
|
+
throwUndoRefusal,
|
|
71
72
|
type WarrantyClaimScope,
|
|
72
73
|
} from './shared'
|
|
73
74
|
|
|
@@ -628,8 +629,8 @@ function restoreLineDelta(line: WarrantyClaimLine, before: ClaimLineSnapshot, af
|
|
|
628
629
|
line.updatedAt = new Date()
|
|
629
630
|
}
|
|
630
631
|
|
|
631
|
-
function throwClaimUndoConflict(): never {
|
|
632
|
-
|
|
632
|
+
function throwClaimUndoConflict(): Promise<never> {
|
|
633
|
+
return throwUndoRefusal('warranty_claims.errors.conflict', 'This claim changed while you were editing it.')
|
|
633
634
|
}
|
|
634
635
|
|
|
635
636
|
async function requireCurrentUndoSnapshot(
|
|
@@ -645,7 +646,7 @@ async function requireCurrentUndoSnapshot(
|
|
|
645
646
|
scope,
|
|
646
647
|
)
|
|
647
648
|
const expectedClaimUpdatedAt = toIso(after.updatedAt)
|
|
648
|
-
if (!claim || !expectedClaimUpdatedAt || toIso(claim.updatedAt) !== expectedClaimUpdatedAt) throwClaimUndoConflict()
|
|
649
|
+
if (!claim || !expectedClaimUpdatedAt || toIso(claim.updatedAt) !== expectedClaimUpdatedAt) return throwClaimUndoConflict()
|
|
649
650
|
const lines = await findWithDecryption(
|
|
650
651
|
em,
|
|
651
652
|
WarrantyClaimLine,
|
|
@@ -654,12 +655,12 @@ async function requireCurrentUndoSnapshot(
|
|
|
654
655
|
scope,
|
|
655
656
|
)
|
|
656
657
|
const afterLines = Array.isArray(after.lines) ? after.lines : []
|
|
657
|
-
if (lines.length !== afterLines.length) throwClaimUndoConflict()
|
|
658
|
+
if (lines.length !== afterLines.length) return throwClaimUndoConflict()
|
|
658
659
|
const afterLinesById = new Map(afterLines.map((line) => [line.id, line]))
|
|
659
660
|
for (const line of lines) {
|
|
660
661
|
const expected = afterLinesById.get(line.id)
|
|
661
662
|
const expectedLineUpdatedAt = toIso(expected?.updatedAt)
|
|
662
|
-
if (!expectedLineUpdatedAt || toIso(line.updatedAt) !== expectedLineUpdatedAt) throwClaimUndoConflict()
|
|
663
|
+
if (!expectedLineUpdatedAt || toIso(line.updatedAt) !== expectedLineUpdatedAt) return throwClaimUndoConflict()
|
|
663
664
|
}
|
|
664
665
|
return { claim, lines }
|
|
665
666
|
}
|
|
@@ -679,7 +680,7 @@ async function restoreSnapshot(em: EntityManager, before: ClaimSnapshot, after:
|
|
|
679
680
|
for (const line of lines) {
|
|
680
681
|
const beforeLine = beforeLinesById.get(line.id)
|
|
681
682
|
const afterLine = afterLinesById.get(line.id)
|
|
682
|
-
if (!beforeLine || !afterLine) throwClaimUndoConflict()
|
|
683
|
+
if (!beforeLine || !afterLine) return throwClaimUndoConflict()
|
|
683
684
|
if (snapshotValueChanged(beforeLine, afterLine)) restoreLineDelta(line, beforeLine, afterLine)
|
|
684
685
|
}
|
|
685
686
|
return claim
|
|
@@ -1690,7 +1691,7 @@ const updateClaimCommand: CommandHandler<ClaimUpdateInput, { claimId: string }>
|
|
|
1690
1691
|
const before = payload?.before
|
|
1691
1692
|
if (!before) return
|
|
1692
1693
|
const after = payload?.after
|
|
1693
|
-
if (!after) throwClaimUndoConflict()
|
|
1694
|
+
if (!after) return throwClaimUndoConflict()
|
|
1694
1695
|
const em = (ctx.container.resolve('em') as EntityManager).fork()
|
|
1695
1696
|
let claim!: WarrantyClaim
|
|
1696
1697
|
await withAtomicFlush(em, [
|
|
@@ -1754,7 +1755,7 @@ const deleteClaimCommand: CommandHandler<ClaimDeleteInput, { claimId: string }>
|
|
|
1754
1755
|
const before = payload?.before
|
|
1755
1756
|
if (!before) return
|
|
1756
1757
|
const after = payload?.after
|
|
1757
|
-
if (!after) throwClaimUndoConflict()
|
|
1758
|
+
if (!after) return throwClaimUndoConflict()
|
|
1758
1759
|
const em = (ctx.container.resolve('em') as EntityManager).fork()
|
|
1759
1760
|
let claim!: WarrantyClaim
|
|
1760
1761
|
await withAtomicFlush(em, [
|
|
@@ -1939,7 +1940,7 @@ const transitionClaimCommand: CommandHandler<TransitionClaimInput, { claimId: st
|
|
|
1939
1940
|
const before = payload?.before
|
|
1940
1941
|
if (!before) return
|
|
1941
1942
|
const after = payload?.after
|
|
1942
|
-
if (!after) throwClaimUndoConflict()
|
|
1943
|
+
if (!after) return throwClaimUndoConflict()
|
|
1943
1944
|
const em = (ctx.container.resolve('em') as EntityManager).fork()
|
|
1944
1945
|
let claim!: WarrantyClaim
|
|
1945
1946
|
await withAtomicFlush(em, [
|
|
@@ -2043,7 +2044,7 @@ const setReturnLabelCommand: CommandHandler<ClaimSetReturnLabelInput, ClaimSetRe
|
|
|
2043
2044
|
const before = payload?.before
|
|
2044
2045
|
if (!before) return
|
|
2045
2046
|
const after = payload?.after
|
|
2046
|
-
if (!after) throwClaimUndoConflict()
|
|
2047
|
+
if (!after) return throwClaimUndoConflict()
|
|
2047
2048
|
const em = (ctx.container.resolve('em') as EntityManager).fork()
|
|
2048
2049
|
let claim!: WarrantyClaim
|
|
2049
2050
|
await withAtomicFlush(em, [
|
|
@@ -2522,7 +2523,7 @@ const createSalesReturnCommand: CommandHandler<ClaimCreateSalesReturnInput, Clai
|
|
|
2522
2523
|
const before = payload?.before
|
|
2523
2524
|
if (!before) return
|
|
2524
2525
|
const after = payload?.after
|
|
2525
|
-
if (!after) throwClaimUndoConflict()
|
|
2526
|
+
if (!after) return throwClaimUndoConflict()
|
|
2526
2527
|
await assertUndoSnapshotCurrent(ctx, after)
|
|
2527
2528
|
const scope: WarrantyClaimScope = { tenantId: before.tenantId, organizationId: before.organizationId }
|
|
2528
2529
|
const salesReturn = payload?.salesReturn ?? null
|
|
@@ -2911,7 +2912,7 @@ const createCreditMemoCommand: CommandHandler<ClaimCreateCreditMemoInput, ClaimC
|
|
|
2911
2912
|
const before = payload?.before
|
|
2912
2913
|
if (!before) return
|
|
2913
2914
|
const after = payload?.after
|
|
2914
|
-
if (!after) throwClaimUndoConflict()
|
|
2915
|
+
if (!after) return throwClaimUndoConflict()
|
|
2915
2916
|
await assertUndoSnapshotCurrent(ctx, after)
|
|
2916
2917
|
const scope: WarrantyClaimScope = { tenantId: before.tenantId, organizationId: before.organizationId }
|
|
2917
2918
|
const creditMemo = payload?.creditMemo ?? null
|
|
@@ -3275,7 +3276,7 @@ const createReplacementOrderCommand: CommandHandler<ClaimCreateReplacementOrderI
|
|
|
3275
3276
|
const before = payload?.before
|
|
3276
3277
|
if (!before) return
|
|
3277
3278
|
const after = payload?.after
|
|
3278
|
-
if (!after) throwClaimUndoConflict()
|
|
3279
|
+
if (!after) return throwClaimUndoConflict()
|
|
3279
3280
|
await assertUndoSnapshotCurrent(ctx, after)
|
|
3280
3281
|
const scope: WarrantyClaimScope = { tenantId: before.tenantId, organizationId: before.organizationId }
|
|
3281
3282
|
const replacementOrder = payload?.replacementOrder ?? null
|
|
@@ -2,13 +2,14 @@ import { randomUUID } from 'crypto'
|
|
|
2
2
|
import type { FindOneOptions } from '@mikro-orm/core'
|
|
3
3
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
4
4
|
import type { CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
|
|
5
|
-
import { assertFound } from '@open-mercato/shared/lib/crud/errors'
|
|
5
|
+
import { CrudHttpError, assertFound } from '@open-mercato/shared/lib/crud/errors'
|
|
6
6
|
import { invalidateCrudCache } from '@open-mercato/shared/lib/crud/cache'
|
|
7
7
|
import { enforceCommandOptimisticLockWithGuards } from '@open-mercato/shared/lib/crud/optimistic-lock-command'
|
|
8
8
|
import { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'
|
|
9
9
|
import { emitCrudSideEffects, flushCrudSideEffects } from '@open-mercato/shared/lib/commands/helpers'
|
|
10
10
|
import type { DataEngine } from '@open-mercato/shared/lib/data/engine'
|
|
11
11
|
import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
12
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
12
13
|
import {
|
|
13
14
|
WarrantyClaim,
|
|
14
15
|
WarrantyClaimEvent,
|
|
@@ -65,6 +66,11 @@ export async function enforceWarrantyClaimOptimisticLock(
|
|
|
65
66
|
})
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
export async function throwUndoRefusal(key: string, fallback: string): Promise<never> {
|
|
70
|
+
const { translate } = await resolveTranslations()
|
|
71
|
+
throw new CrudHttpError(409, { error: translate(key, fallback), code: key })
|
|
72
|
+
}
|
|
73
|
+
|
|
68
74
|
export async function loadScopedClaim(
|
|
69
75
|
em: EntityManager,
|
|
70
76
|
id: string,
|