@open-mercato/core 0.9.1-develop.7499.1.fcec456e4e → 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.
Files changed (89) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/audit_logs/components/AuditLogsActions.js +1 -1
  3. package/dist/modules/audit_logs/components/AuditLogsActions.js.map +2 -2
  4. package/dist/modules/auth/frontend/reset.js +7 -3
  5. package/dist/modules/auth/frontend/reset.js.map +2 -2
  6. package/dist/modules/business_rules/api/rules/route.js +12 -1
  7. package/dist/modules/business_rules/api/rules/route.js.map +2 -2
  8. package/dist/modules/catalog/backend/catalog/products/[id]/page.js +17 -2
  9. package/dist/modules/catalog/backend/catalog/products/[id]/page.js.map +2 -2
  10. package/dist/modules/catalog/backend/catalog/products/[productId]/variants/[variantId]/page.js +3 -2
  11. package/dist/modules/catalog/backend/catalog/products/[productId]/variants/[variantId]/page.js.map +2 -2
  12. package/dist/modules/catalog/backend/catalog/products/create/page.js +1 -0
  13. package/dist/modules/catalog/backend/catalog/products/create/page.js.map +2 -2
  14. package/dist/modules/catalog/components/products/productFormUtils.js +9 -0
  15. package/dist/modules/catalog/components/products/productFormUtils.js.map +2 -2
  16. package/dist/modules/customers/backend/customers/companies/page.js +32 -32
  17. package/dist/modules/customers/backend/customers/companies/page.js.map +2 -2
  18. package/dist/modules/customers/backend/customers/deals/page.js +22 -22
  19. package/dist/modules/customers/backend/customers/deals/page.js.map +2 -2
  20. package/dist/modules/customers/backend/customers/people/page.js +34 -34
  21. package/dist/modules/customers/backend/customers/people/page.js.map +2 -2
  22. package/dist/modules/ecommerce/search.js +1 -2
  23. package/dist/modules/ecommerce/search.js.map +2 -2
  24. package/dist/modules/shipping_carriers/api/webhook/[provider]/route.js +4 -7
  25. package/dist/modules/shipping_carriers/api/webhook/[provider]/route.js.map +2 -2
  26. package/dist/modules/shipping_carriers/lib/shipping-service.js +29 -11
  27. package/dist/modules/shipping_carriers/lib/shipping-service.js.map +2 -2
  28. package/dist/modules/shipping_carriers/lib/status-sync.js +2 -2
  29. package/dist/modules/shipping_carriers/lib/status-sync.js.map +2 -2
  30. package/dist/modules/shipping_carriers/workers/webhook-processor.js +60 -33
  31. package/dist/modules/shipping_carriers/workers/webhook-processor.js.map +3 -3
  32. package/dist/modules/staff/backend/staff/time-tracking/entries/page.js +10 -7
  33. package/dist/modules/staff/backend/staff/time-tracking/entries/page.js.map +2 -2
  34. package/dist/modules/warranty_claims/commands/claim-lines.js +89 -68
  35. package/dist/modules/warranty_claims/commands/claim-lines.js.map +2 -2
  36. package/dist/modules/warranty_claims/commands/claims.js +14 -13
  37. package/dist/modules/warranty_claims/commands/claims.js.map +2 -2
  38. package/dist/modules/warranty_claims/commands/shared.js +8 -2
  39. package/dist/modules/warranty_claims/commands/shared.js.map +2 -2
  40. package/dist/modules/wms/api/interceptors.js +3 -0
  41. package/dist/modules/wms/api/interceptors.js.map +2 -2
  42. package/dist/modules/wms/commands/configuration.js +16 -16
  43. package/dist/modules/wms/commands/configuration.js.map +2 -2
  44. package/dist/modules/wms/events.js +1 -0
  45. package/dist/modules/wms/events.js.map +2 -2
  46. package/dist/modules/wms/lib/catalogInventoryProfileIntent.js +9 -0
  47. package/dist/modules/wms/lib/catalogInventoryProfileIntent.js.map +2 -2
  48. package/dist/modules/wms/widgets/injection/catalog-inventory-profile/widget.js +11 -3
  49. package/dist/modules/wms/widgets/injection/catalog-inventory-profile/widget.js.map +2 -2
  50. package/package.json +7 -7
  51. package/src/modules/audit_logs/components/AuditLogsActions.tsx +1 -1
  52. package/src/modules/auth/frontend/reset.tsx +8 -3
  53. package/src/modules/business_rules/api/rules/route.ts +11 -0
  54. package/src/modules/business_rules/i18n/de.json +1 -0
  55. package/src/modules/business_rules/i18n/en.json +1 -0
  56. package/src/modules/business_rules/i18n/es.json +1 -0
  57. package/src/modules/business_rules/i18n/ko.json +1 -0
  58. package/src/modules/business_rules/i18n/pl.json +1 -0
  59. package/src/modules/catalog/backend/catalog/products/[id]/page.tsx +20 -1
  60. package/src/modules/catalog/backend/catalog/products/[productId]/variants/[variantId]/page.tsx +2 -1
  61. package/src/modules/catalog/backend/catalog/products/create/page.tsx +1 -0
  62. package/src/modules/catalog/components/products/productFormUtils.ts +9 -0
  63. package/src/modules/customers/backend/customers/companies/page.tsx +32 -32
  64. package/src/modules/customers/backend/customers/deals/page.tsx +22 -22
  65. package/src/modules/customers/backend/customers/people/page.tsx +34 -34
  66. package/src/modules/customers/i18n/de.json +12 -0
  67. package/src/modules/customers/i18n/en.json +12 -0
  68. package/src/modules/customers/i18n/es.json +12 -0
  69. package/src/modules/customers/i18n/ko.json +12 -0
  70. package/src/modules/customers/i18n/pl.json +12 -0
  71. package/src/modules/ecommerce/i18n/de.json +2 -1
  72. package/src/modules/ecommerce/i18n/en.json +2 -1
  73. package/src/modules/ecommerce/i18n/es.json +2 -1
  74. package/src/modules/ecommerce/i18n/ko.json +2 -1
  75. package/src/modules/ecommerce/i18n/pl.json +2 -1
  76. package/src/modules/ecommerce/search.ts +0 -1
  77. package/src/modules/shipping_carriers/api/webhook/[provider]/route.ts +4 -7
  78. package/src/modules/shipping_carriers/lib/shipping-service.ts +29 -11
  79. package/src/modules/shipping_carriers/lib/status-sync.ts +2 -2
  80. package/src/modules/shipping_carriers/workers/webhook-processor.ts +71 -39
  81. package/src/modules/staff/backend/staff/time-tracking/entries/page.tsx +20 -14
  82. package/src/modules/warranty_claims/commands/claim-lines.ts +107 -66
  83. package/src/modules/warranty_claims/commands/claims.ts +14 -13
  84. package/src/modules/warranty_claims/commands/shared.ts +7 -1
  85. package/src/modules/wms/api/interceptors.ts +9 -0
  86. package/src/modules/wms/commands/configuration.ts +28 -16
  87. package/src/modules/wms/events.ts +1 -0
  88. package/src/modules/wms/lib/catalogInventoryProfileIntent.ts +9 -0
  89. package/src/modules/wms/widgets/injection/catalog-inventory-profile/widget.ts +13 -4
@@ -8,7 +8,7 @@ import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
8
8
  import { invalidateCrudCache } from "@open-mercato/shared/lib/crud/cache";
9
9
  import { findOneWithDecryption, findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
10
10
  import { E } from "../../../generated/entities.ids.generated.js";
11
- import { WarrantyClaimLine } from "../data/entities.js";
11
+ import { WarrantyClaim, WarrantyClaimLine } from "../data/entities.js";
12
12
  import {
13
13
  claimLineCreateSchema,
14
14
  claimLineReceiveSchema,
@@ -31,7 +31,8 @@ import {
31
31
  ensureOrganizationScope,
32
32
  ensureTenantScope,
33
33
  extractUndoPayload,
34
- requireScopedClaim
34
+ requireScopedClaim,
35
+ throwUndoRefusal
35
36
  } from "./shared.js";
36
37
  import { assertPendingClaimQuantitiesWithinSold, validateClaimReferences } from "./claims.js";
37
38
  const claimCrudEvents = {
@@ -61,6 +62,17 @@ const mutableParentStatuses = /* @__PURE__ */ new Set([
61
62
  "received",
62
63
  "inspecting"
63
64
  ]);
65
+ const receivingParentStatuses = /* @__PURE__ */ new Set(["received", "inspecting"]);
66
+ const mutableParentUndoRule = {
67
+ allowedParentStatuses: mutableParentStatuses,
68
+ lockedKey: "warranty_claims.errors.lineLocked",
69
+ lockedFallback: "This line is locked in the current claim status."
70
+ };
71
+ const receivingParentUndoRule = {
72
+ allowedParentStatuses: receivingParentStatuses,
73
+ lockedKey: "warranty_claims.errors.receivingStatusInvalid",
74
+ lockedFallback: "Receiving details can only be saved when the claim is received or under inspection."
75
+ };
64
76
  function parseCommandInput(schema, rawInput) {
65
77
  const result = schema.safeParse(rawInput ?? {});
66
78
  if (!result.success) {
@@ -360,6 +372,31 @@ async function recomputeClaimRollups(em, claim) {
360
372
  claim.totalApprovedAmount = String(totals.totalApprovedAmount);
361
373
  claim.updatedAt = /* @__PURE__ */ new Date();
362
374
  }
375
+ function refuseLineUndoConflict() {
376
+ return throwUndoRefusal("warranty_claims.errors.conflict", "This claim changed while you were editing it.");
377
+ }
378
+ async function requireCurrentLineUndoState(em, after, rule) {
379
+ if (!after) return refuseLineUndoConflict();
380
+ const scope = { tenantId: after.tenantId, organizationId: after.organizationId };
381
+ const claim = await findOneWithDecryption(
382
+ em,
383
+ WarrantyClaim,
384
+ { id: after.claimId, tenantId: scope.tenantId, organizationId: scope.organizationId, deletedAt: null },
385
+ { lockMode: LockMode.PESSIMISTIC_WRITE },
386
+ scope
387
+ );
388
+ if (!claim) return refuseLineUndoConflict();
389
+ if (!rule.allowedParentStatuses.has(claim.status)) return throwUndoRefusal(rule.lockedKey, rule.lockedFallback);
390
+ const line = await findOneWithDecryption(
391
+ em,
392
+ WarrantyClaimLine,
393
+ { id: after.id, tenantId: scope.tenantId, organizationId: scope.organizationId },
394
+ { lockMode: LockMode.PESSIMISTIC_WRITE },
395
+ scope
396
+ );
397
+ if (!line || !after.updatedAt || toIso(line.updatedAt) !== after.updatedAt) return refuseLineUndoConflict();
398
+ return { claim, line };
399
+ }
363
400
  async function requireScopedLine(em, lineId, scope) {
364
401
  const line = await findOneWithDecryption(
365
402
  em,
@@ -500,22 +537,20 @@ const createClaimLineCommand = {
500
537
  buildLog: async ({ result, snapshots }) => buildLineLog("warranty_claims.audit.claim_line.create", result.lineId, snapshots),
501
538
  undo: async ({ logEntry, ctx }) => {
502
539
  const payload = extractUndoPayload(logEntry);
503
- const after = payload?.after;
504
- if (!after) return;
505
- const scope = { tenantId: after.tenantId, organizationId: after.organizationId };
506
540
  const em = ctx.container.resolve("em").fork();
507
- const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: after.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ["claim"] }, scope);
508
- const claim = line ? claimOf(line) : null;
509
- if (!line || !claim) return;
541
+ let state;
510
542
  await withAtomicFlush(em, [
543
+ async () => {
544
+ state = await requireCurrentLineUndoState(em, payload?.after, mutableParentUndoRule);
545
+ },
511
546
  () => {
512
- line.deletedAt = /* @__PURE__ */ new Date();
513
- line.updatedAt = /* @__PURE__ */ new Date();
547
+ state.line.deletedAt = /* @__PURE__ */ new Date();
548
+ state.line.updatedAt = /* @__PURE__ */ new Date();
514
549
  },
515
- () => recomputeClaimRollups(em, claim)
550
+ () => recomputeClaimRollups(em, state.claim)
516
551
  ], { transaction: true, label: "warranty_claims.claim_line.create.undo" });
517
- await emitClaimUpdated(ctx, claim);
518
- await emitLineUndoCrud(ctx, "deleted", line);
552
+ await emitClaimUpdated(ctx, state.claim);
553
+ await emitLineUndoCrud(ctx, "deleted", state.line);
519
554
  }
520
555
  };
521
556
  const updateClaimLineCommand = {
@@ -587,17 +622,17 @@ const updateClaimLineCommand = {
587
622
  const payload = extractUndoPayload(logEntry);
588
623
  const before = payload?.before;
589
624
  if (!before) return;
590
- const scope = { tenantId: before.tenantId, organizationId: before.organizationId };
591
625
  const em = ctx.container.resolve("em").fork();
592
- const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ["claim"] }, scope);
593
- if (!line) return;
594
- const claim = claimOf(line) ?? await requireScopedClaim(em, before.claimId, scope);
626
+ let state;
595
627
  await withAtomicFlush(em, [
596
- () => restoreLineFromSnapshot(line, before),
597
- () => recomputeClaimRollups(em, claim)
628
+ async () => {
629
+ state = await requireCurrentLineUndoState(em, payload?.after, mutableParentUndoRule);
630
+ },
631
+ () => restoreLineFromSnapshot(state.line, before),
632
+ () => recomputeClaimRollups(em, state.claim)
598
633
  ], { transaction: true, label: "warranty_claims.claim_line.update.undo" });
599
- await emitClaimUpdated(ctx, claim);
600
- await emitLineUndoCrud(ctx, "updated", line);
634
+ await emitClaimUpdated(ctx, state.claim);
635
+ await emitLineUndoCrud(ctx, "updated", state.line);
601
636
  }
602
637
  };
603
638
  const deleteClaimLineCommand = {
@@ -642,35 +677,20 @@ const deleteClaimLineCommand = {
642
677
  const payload = extractUndoPayload(logEntry);
643
678
  const before = payload?.before;
644
679
  if (!before) return;
645
- const scope = { tenantId: before.tenantId, organizationId: before.organizationId };
646
680
  const em = ctx.container.resolve("em").fork();
647
- let line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ["claim"] }, scope);
648
- const claim = (line ? claimOf(line) : null) ?? await requireScopedClaim(em, before.claimId, scope);
681
+ let state;
649
682
  await withAtomicFlush(em, [
683
+ async () => {
684
+ state = await requireCurrentLineUndoState(em, payload?.after, mutableParentUndoRule);
685
+ },
650
686
  () => {
651
- if (!line) {
652
- line = em.create(WarrantyClaimLine, {
653
- id: before.id,
654
- claim,
655
- organizationId: before.organizationId,
656
- tenantId: before.tenantId,
657
- lineNo: before.lineNo,
658
- qtyClaimed: before.qtyClaimed,
659
- lineStatus: before.lineStatus,
660
- warrantyStatus: before.warrantyStatus,
661
- createdAt: /* @__PURE__ */ new Date(),
662
- updatedAt: /* @__PURE__ */ new Date()
663
- });
664
- em.persist(line);
665
- }
666
- restoreLineFromSnapshot(line, before);
667
- line.deletedAt = null;
687
+ restoreLineFromSnapshot(state.line, before);
688
+ state.line.deletedAt = null;
668
689
  },
669
- () => recomputeClaimRollups(em, claim)
690
+ () => recomputeClaimRollups(em, state.claim)
670
691
  ], { transaction: true, label: "warranty_claims.claim_line.delete.undo" });
671
- if (!line) return;
672
- await emitClaimUpdated(ctx, claim);
673
- await emitLineUndoCrud(ctx, "created", line);
692
+ await emitClaimUpdated(ctx, state.claim);
693
+ await emitLineUndoCrud(ctx, "created", state.line);
674
694
  }
675
695
  };
676
696
  const receiveClaimLineCommand = {
@@ -752,17 +772,17 @@ const receiveClaimLineCommand = {
752
772
  const payload = extractUndoPayload(logEntry);
753
773
  const before = payload?.before;
754
774
  if (!before) return;
755
- const scope = { tenantId: before.tenantId, organizationId: before.organizationId };
756
775
  const em = ctx.container.resolve("em").fork();
757
- const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ["claim"] }, scope);
758
- if (!line) return;
759
- const claim = await requireScopedClaim(em, before.claimId, scope);
776
+ let state;
760
777
  await withAtomicFlush(em, [
761
- () => restoreLineFromSnapshot(line, before),
762
- () => recomputeClaimRollups(em, claim)
778
+ async () => {
779
+ state = await requireCurrentLineUndoState(em, payload?.after, receivingParentUndoRule);
780
+ },
781
+ () => restoreLineFromSnapshot(state.line, before),
782
+ () => recomputeClaimRollups(em, state.claim)
763
783
  ], { transaction: true, label: "warranty_claims.claim_line.receive.undo" });
764
- await emitClaimUpdated(ctx, claim);
765
- await emitLineUndoCrud(ctx, "updated", line);
784
+ await emitClaimUpdated(ctx, state.claim);
785
+ await emitLineUndoCrud(ctx, "updated", state.line);
766
786
  }
767
787
  };
768
788
  const releaseClaimLineQuarantineCommand = {
@@ -813,17 +833,17 @@ const releaseClaimLineQuarantineCommand = {
813
833
  const payload = extractUndoPayload(logEntry);
814
834
  const before = payload?.before;
815
835
  if (!before) return;
816
- const scope = { tenantId: before.tenantId, organizationId: before.organizationId };
817
836
  const em = ctx.container.resolve("em").fork();
818
- const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ["claim"] }, scope);
819
- if (!line) return;
820
- const claim = await requireScopedClaim(em, before.claimId, scope);
837
+ let state;
821
838
  await withAtomicFlush(em, [
822
- () => restoreLineFromSnapshot(line, before),
823
- () => recomputeClaimRollups(em, claim)
839
+ async () => {
840
+ state = await requireCurrentLineUndoState(em, payload?.after, receivingParentUndoRule);
841
+ },
842
+ () => restoreLineFromSnapshot(state.line, before),
843
+ () => recomputeClaimRollups(em, state.claim)
824
844
  ], { transaction: true, label: "warranty_claims.claim_line.release_quarantine.undo" });
825
- await emitClaimUpdated(ctx, claim);
826
- await emitLineUndoCrud(ctx, "updated", line);
845
+ await emitClaimUpdated(ctx, state.claim);
846
+ await emitLineUndoCrud(ctx, "updated", state.line);
827
847
  }
828
848
  };
829
849
  const setClaimLineAssessmentCommand = {
@@ -873,16 +893,17 @@ const setClaimLineAssessmentCommand = {
873
893
  const payload = extractUndoPayload(logEntry);
874
894
  const before = payload?.before;
875
895
  if (!before) return;
876
- const scope = { tenantId: before.tenantId, organizationId: before.organizationId };
877
896
  const em = ctx.container.resolve("em").fork();
878
- const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ["claim"] }, scope);
879
- if (!line) return;
880
- const claim = claimOf(line) ?? await requireScopedClaim(em, before.claimId, scope);
897
+ let state;
881
898
  await withAtomicFlush(em, [
882
- () => restoreLineFromSnapshot(line, before)
899
+ async () => {
900
+ state = await requireCurrentLineUndoState(em, payload?.after, mutableParentUndoRule);
901
+ },
902
+ () => restoreLineFromSnapshot(state.line, before),
903
+ () => recomputeClaimRollups(em, state.claim)
883
904
  ], { transaction: true, label: "warranty_claims.claim_line.set_assessment.undo" });
884
- await emitClaimUpdated(ctx, claim);
885
- await emitLineUndoCrud(ctx, "updated", line);
905
+ await emitClaimUpdated(ctx, state.claim);
906
+ await emitLineUndoCrud(ctx, "updated", state.line);
886
907
  }
887
908
  };
888
909
  registerCommand(createClaimLineCommand);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/warranty_claims/commands/claim-lines.ts"],
4
- "sourcesContent": ["import { randomUUID } from 'crypto'\nimport { LockMode } from '@mikro-orm/core'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { z } from 'zod'\nimport { registerCommand, type CommandHandler, type CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'\nimport { emitCrudSideEffects, emitCrudUndoSideEffects } from '@open-mercato/shared/lib/commands/helpers'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { invalidateCrudCache } from '@open-mercato/shared/lib/crud/cache'\nimport { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { E } from '#generated/entities.ids.generated'\nimport { WarrantyClaim, WarrantyClaimLine } from '../data/entities'\nimport {\n claimLineCreateSchema,\n claimLineReceiveSchema,\n claimLineReleaseQuarantineSchema,\n claimLineUpdateSchema,\n type ClaimLineCreateInput,\n type ClaimLineReceiveInput,\n type ClaimLineReleaseQuarantineInput,\n type ClaimLineUpdateInput,\n type WarrantyClaimDisposition,\n type WarrantyClaimLineStatus,\n type WarrantyClaimWarrantyStatus,\n} from '../data/validators'\nimport { emitWarrantyClaimsEvent } from '../events'\nimport {\n assertDispositionAllowedForGrade,\n suggestedDispositionForGrade,\n type ConditionGrade,\n} from '../lib/grading'\nimport { assertDispositionAllowedForType } from '../lib/claimTypeConfig'\nimport { resolveEffectiveWarrantyClaimSettings } from '../lib/settings'\nimport { computeHeaderRollups, lineStatusGuards } from '../lib/stateMachine'\nimport {\n WARRANTY_CLAIM_LINE_RESOURCE_KIND,\n WARRANTY_CLAIM_RESOURCE_KIND,\n appendClaimEvent,\n enforceWarrantyClaimOptimisticLock,\n ensureOrganizationScope,\n ensureTenantScope,\n extractUndoPayload,\n requireScopedClaim,\n type WarrantyClaimScope,\n} from './shared'\nimport { assertPendingClaimQuantitiesWithinSold, validateClaimReferences } from './claims'\n\nconst claimCrudEvents: CrudEventsConfig = {\n module: 'warranty_claims',\n entity: 'claim',\n persistent: true,\n}\n\nconst lineDeleteSchema = z\n .object({\n id: z.string().uuid(),\n claimId: z.string().uuid().optional(),\n organizationId: z.string().uuid().optional(),\n tenantId: z.string().uuid().optional(),\n })\n .strict()\n\ntype LineDeleteInput = z.infer<typeof lineDeleteSchema>\n\nconst lineSetAssessmentSchema = z\n .object({\n id: z.string().uuid(),\n organizationId: z.string().uuid().optional(),\n tenantId: z.string().uuid().optional(),\n assessmentPayload: z.record(z.string(), z.unknown()),\n updatedAt: z.union([z.string().datetime(), z.date()]).nullable().optional(),\n })\n .strict()\n\ntype LineSetAssessmentInput = z.infer<typeof lineSetAssessmentSchema>\n\ntype ScopeInput = {\n organizationId?: string | null\n tenantId?: string | null\n}\n\ntype LineSnapshot = {\n id: string\n claimId: string\n organizationId: string\n tenantId: string\n lineNo: number\n productId: string | null\n variantId: string | null\n sku: string | null\n productName: string | null\n orderLineId: string | null\n serialNumber: string | null\n lotNumber: string | null\n purchaseDate: string | null\n warrantyMonths: number | null\n warrantyExpiresAt: string | null\n warrantyStatus: WarrantyClaimWarrantyStatus\n faultCode: string | null\n faultDescription: string | null\n qtyClaimed: string\n qtyApproved: string | null\n qtyReceived: string | null\n conditionOnReceipt: string | null\n conditionGrade: string | null\n quarantineStatus: string\n inspectionNotes: string | null\n assessmentPayload: Record<string, unknown> | null\n disposition: WarrantyClaimDisposition | null\n lineStatus: WarrantyClaimLineStatus\n creditAmount: string | null\n restockingFee: string | null\n coreChargeAmount: string | null\n coreCreditAmount: string | null\n vendorClaimLineId: string | null\n vendorName: string | null\n deletedAt: string | null\n updatedAt: string | null\n}\n\ntype LineUndoPayload = {\n before?: LineSnapshot | null\n after?: LineSnapshot | null\n}\n\nconst mutableParentStatuses = new Set([\n 'draft',\n 'submitted',\n 'in_review',\n 'info_requested',\n 'approved',\n 'received',\n 'inspecting',\n])\n\nfunction parseCommandInput<T>(schema: z.ZodType<T>, rawInput: unknown): T {\n const result = schema.safeParse(rawInput ?? {})\n if (!result.success) {\n throw new CrudHttpError(400, { error: '[internal] invalid warranty claim line command input' })\n }\n return result.data\n}\n\nfunction hasOwn(input: object, key: string): boolean {\n return Object.prototype.hasOwnProperty.call(input, key)\n}\n\nfunction resolveScope(ctx: CommandRuntimeContext, input: ScopeInput): WarrantyClaimScope {\n const tenantId = input.tenantId ?? ctx.auth?.tenantId ?? null\n const organizationId = input.organizationId ?? ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null\n if (!tenantId) throw new CrudHttpError(400, { error: '[internal] tenant scope required for warranty claim line command' })\n if (!organizationId) throw new CrudHttpError(400, { error: '[internal] organization scope required for warranty claim line command' })\n ensureTenantScope(ctx, tenantId)\n ensureOrganizationScope(ctx, organizationId)\n return { tenantId, organizationId }\n}\n\nfunction toIso(value: Date | string | null | undefined): string | null {\n if (!value) return null\n const date = value instanceof Date ? value : new Date(value)\n return Number.isNaN(date.getTime()) ? null : date.toISOString()\n}\n\nfunction toDate(value: string | null): Date | null {\n if (!value) return null\n const date = new Date(value)\n return Number.isNaN(date.getTime()) ? null : date\n}\n\nfunction toDateOnlyIso(value: Date | string | null | undefined): string | null {\n const iso = toIso(value)\n return iso ? iso.slice(0, 10) : null\n}\n\nfunction toDateOnly(value: string | null): Date | null {\n if (!value) return null\n const date = new Date(`${value}T00:00:00.000Z`)\n return Number.isNaN(date.getTime()) ? null : date\n}\n\nfunction amountString(value: number | string | null | undefined, fallback = '0'): string | null {\n if (value === null) return null\n if (value === undefined) return fallback\n const parsed = typeof value === 'number' ? value : Number(value)\n if (!Number.isFinite(parsed)) return fallback\n return String(parsed)\n}\n\nfunction nullableAmountString(value: number | string | null | undefined): string | null {\n if (value === undefined || value === null) return null\n return amountString(value, '0')\n}\n\nfunction numberValue(value: string | number | null | undefined): number {\n if (value === null || value === undefined) return 0\n const parsed = typeof value === 'number' ? value : Number(value)\n return Number.isFinite(parsed) ? parsed : 0\n}\n\nfunction addMonths(date: Date, months: number): Date {\n const target = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + months, 1))\n const lastDay = new Date(Date.UTC(target.getUTCFullYear(), target.getUTCMonth() + 1, 0)).getUTCDate()\n const copy = new Date(date.getTime())\n copy.setUTCDate(1)\n copy.setUTCFullYear(target.getUTCFullYear(), target.getUTCMonth(), Math.min(date.getUTCDate(), lastDay))\n return copy\n}\n\nfunction computeWarrantyDates(\n purchaseDate: Date | null | undefined,\n warrantyMonths: number | null | undefined,\n): { warrantyExpiresAt: Date | null; warrantyStatus: WarrantyClaimWarrantyStatus } {\n if (!purchaseDate || warrantyMonths === null || warrantyMonths === undefined) {\n return { warrantyExpiresAt: null, warrantyStatus: 'unknown' }\n }\n const warrantyExpiresAt = addMonths(purchaseDate, warrantyMonths)\n const warrantyStatus = warrantyExpiresAt.getTime() >= Date.now() ? 'in_warranty' : 'out_of_warranty'\n return { warrantyExpiresAt, warrantyStatus }\n}\n\nfunction claimIdOf(line: WarrantyClaimLine): string {\n const claim = line.claim\n if (typeof claim === 'object' && claim && 'id' in claim && typeof claim.id === 'string') return claim.id\n return String(claim)\n}\n\nfunction claimOf(line: WarrantyClaimLine): WarrantyClaim | null {\n const claim = line.claim\n if (typeof claim === 'object' && claim && 'id' in claim && typeof claim.id === 'string') return claim as WarrantyClaim\n return null\n}\n\nfunction sameDateValue(left: Date | null | undefined, right: Date | null | undefined): boolean {\n const leftTime = left instanceof Date ? left.getTime() : null\n const rightTime = right instanceof Date ? right.getTime() : null\n return leftTime === rightTime\n}\n\nfunction assertParentMutable(claim: WarrantyClaim): void {\n if (!mutableParentStatuses.has(claim.status)) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.lineLocked' })\n }\n}\n\nfunction assertReceivingStatus(claim: WarrantyClaim): void {\n if (claim.status !== 'received' && claim.status !== 'inspecting') {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.receivingStatusInvalid' })\n }\n}\n\nfunction toConditionGrade(value: string | null | undefined): ConditionGrade | null {\n if (value === 'A' || value === 'B' || value === 'C' || value === 'D') return value\n return null\n}\n\nfunction assertLineQuantities(line: WarrantyClaimLine): void {\n const qtyClaimed = numberValue(line.qtyClaimed)\n const qtyApproved = line.qtyApproved === null || line.qtyApproved === undefined ? null : numberValue(line.qtyApproved)\n const qtyReceived = line.qtyReceived === null || line.qtyReceived === undefined ? null : numberValue(line.qtyReceived)\n if (qtyClaimed < 0 || (qtyApproved !== null && qtyApproved < 0) || (qtyReceived !== null && qtyReceived < 0)) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.lineLocked' })\n }\n if (qtyApproved !== null && qtyApproved > qtyClaimed) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.lineLocked' })\n }\n if (qtyReceived !== null && qtyReceived > qtyClaimed) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.lineLocked' })\n }\n}\n\nfunction assertLineStatusMove(from: WarrantyClaimLineStatus, to: WarrantyClaimLineStatus): void {\n if (from === to) return\n if (lineStatusGuards[from].includes(to)) return\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.invalidTransition' })\n}\n\nfunction buildLineCreateData(\n claim: WarrantyClaim,\n input: ClaimLineCreateInput,\n lineNo: number,\n): Partial<WarrantyClaimLine> & {\n id: string\n claim: WarrantyClaim\n organizationId: string\n tenantId: string\n lineNo: number\n qtyClaimed: string\n lineStatus: WarrantyClaimLineStatus\n warrantyStatus: WarrantyClaimWarrantyStatus\n createdAt: Date\n updatedAt: Date\n} {\n const purchaseDate = input.purchaseDate ?? null\n const warrantyMonths = input.warrantyMonths ?? null\n const computedWarranty = computeWarrantyDates(purchaseDate, warrantyMonths)\n return {\n id: randomUUID(),\n claim,\n organizationId: claim.organizationId,\n tenantId: claim.tenantId,\n lineNo,\n productId: input.productId ?? null,\n variantId: input.variantId ?? null,\n sku: input.sku ?? null,\n productName: input.productName ?? null,\n orderLineId: input.orderLineId ?? null,\n serialNumber: input.serialNumber ?? null,\n lotNumber: input.lotNumber ?? null,\n purchaseDate,\n warrantyMonths,\n warrantyExpiresAt: input.warrantyExpiresAt ?? computedWarranty.warrantyExpiresAt,\n warrantyStatus: input.warrantyStatus ?? computedWarranty.warrantyStatus,\n faultCode: input.faultCode ?? null,\n faultDescription: input.faultDescription ?? null,\n qtyClaimed: amountString(input.qtyClaimed, '1') ?? '1',\n qtyApproved: nullableAmountString(input.qtyApproved),\n qtyReceived: nullableAmountString(input.qtyReceived),\n conditionOnReceipt: input.conditionOnReceipt ?? null,\n inspectionNotes: input.inspectionNotes ?? null,\n disposition: input.disposition ?? null,\n vendorName: input.vendorName ?? null,\n lineStatus: 'pending',\n creditAmount: nullableAmountString(input.creditAmount),\n restockingFee: nullableAmountString(input.restockingFee),\n coreChargeAmount: nullableAmountString(input.coreChargeAmount),\n coreCreditAmount: nullableAmountString(input.coreCreditAmount),\n createdAt: new Date(),\n updatedAt: new Date(),\n }\n}\n\nfunction applyLineUpdate(line: WarrantyClaimLine, input: ClaimLineUpdateInput): void {\n const purchaseDateChanged = hasOwn(input, 'purchaseDate') && !sameDateValue(line.purchaseDate ?? null, input.purchaseDate ?? null)\n const warrantyMonthsChanged = hasOwn(input, 'warrantyMonths') && (line.warrantyMonths ?? null) !== (input.warrantyMonths ?? null)\n const hasExplicitWarranty = hasOwn(input, 'warrantyExpiresAt') || hasOwn(input, 'warrantyStatus')\n if (hasOwn(input, 'lineNo') && input.lineNo !== undefined) line.lineNo = input.lineNo\n if (hasOwn(input, 'productId')) line.productId = input.productId ?? null\n if (hasOwn(input, 'variantId')) line.variantId = input.variantId ?? null\n if (hasOwn(input, 'sku')) line.sku = input.sku ?? null\n if (hasOwn(input, 'productName')) line.productName = input.productName ?? null\n if (hasOwn(input, 'orderLineId')) line.orderLineId = input.orderLineId ?? null\n if (hasOwn(input, 'serialNumber')) line.serialNumber = input.serialNumber ?? null\n if (hasOwn(input, 'lotNumber')) line.lotNumber = input.lotNumber ?? null\n if (hasOwn(input, 'purchaseDate')) line.purchaseDate = input.purchaseDate ?? null\n if (hasOwn(input, 'warrantyMonths')) line.warrantyMonths = input.warrantyMonths ?? null\n if (hasOwn(input, 'warrantyExpiresAt')) line.warrantyExpiresAt = input.warrantyExpiresAt ?? null\n if (hasOwn(input, 'warrantyStatus') && input.warrantyStatus) line.warrantyStatus = input.warrantyStatus\n if (hasOwn(input, 'faultCode')) line.faultCode = input.faultCode ?? null\n if (hasOwn(input, 'faultDescription')) line.faultDescription = input.faultDescription ?? null\n if (hasOwn(input, 'qtyClaimed') && input.qtyClaimed !== undefined) line.qtyClaimed = amountString(input.qtyClaimed, '1') ?? '1'\n if (hasOwn(input, 'qtyApproved')) line.qtyApproved = nullableAmountString(input.qtyApproved)\n if (hasOwn(input, 'qtyReceived')) line.qtyReceived = nullableAmountString(input.qtyReceived)\n if (hasOwn(input, 'conditionOnReceipt')) line.conditionOnReceipt = input.conditionOnReceipt ?? null\n if (hasOwn(input, 'inspectionNotes')) line.inspectionNotes = input.inspectionNotes ?? null\n if (hasOwn(input, 'disposition')) line.disposition = input.disposition ?? null\n if (hasOwn(input, 'vendorName')) line.vendorName = input.vendorName ?? null\n if (hasOwn(input, 'lineStatus') && input.lineStatus) {\n assertLineStatusMove(line.lineStatus, input.lineStatus)\n line.lineStatus = input.lineStatus\n }\n if (hasOwn(input, 'creditAmount')) line.creditAmount = nullableAmountString(input.creditAmount)\n if (hasOwn(input, 'restockingFee')) line.restockingFee = nullableAmountString(input.restockingFee)\n if (hasOwn(input, 'coreChargeAmount')) line.coreChargeAmount = nullableAmountString(input.coreChargeAmount)\n if (hasOwn(input, 'coreCreditAmount')) line.coreCreditAmount = nullableAmountString(input.coreCreditAmount)\n if ((purchaseDateChanged || warrantyMonthsChanged) && !hasExplicitWarranty) {\n const computedWarranty = computeWarrantyDates(line.purchaseDate ?? null, line.warrantyMonths ?? null)\n line.warrantyExpiresAt = computedWarranty.warrantyExpiresAt\n line.warrantyStatus = computedWarranty.warrantyStatus\n }\n line.updatedAt = new Date()\n}\n\nfunction snapshotLine(line: WarrantyClaimLine): LineSnapshot {\n return {\n id: line.id,\n claimId: claimIdOf(line),\n organizationId: line.organizationId,\n tenantId: line.tenantId,\n lineNo: line.lineNo,\n productId: line.productId ?? null,\n variantId: line.variantId ?? null,\n sku: line.sku ?? null,\n productName: line.productName ?? null,\n orderLineId: line.orderLineId ?? null,\n serialNumber: line.serialNumber ?? null,\n lotNumber: line.lotNumber ?? null,\n purchaseDate: toDateOnlyIso(line.purchaseDate),\n warrantyMonths: line.warrantyMonths ?? null,\n warrantyExpiresAt: toDateOnlyIso(line.warrantyExpiresAt),\n warrantyStatus: line.warrantyStatus,\n faultCode: line.faultCode ?? null,\n faultDescription: line.faultDescription ?? null,\n qtyClaimed: line.qtyClaimed,\n qtyApproved: line.qtyApproved ?? null,\n qtyReceived: line.qtyReceived ?? null,\n conditionOnReceipt: line.conditionOnReceipt ?? null,\n conditionGrade: line.conditionGrade ?? null,\n quarantineStatus: line.quarantineStatus,\n inspectionNotes: line.inspectionNotes ?? null,\n assessmentPayload: line.assessmentPayload ?? null,\n disposition: line.disposition ?? null,\n lineStatus: line.lineStatus,\n creditAmount: line.creditAmount ?? null,\n restockingFee: line.restockingFee ?? null,\n coreChargeAmount: line.coreChargeAmount ?? null,\n coreCreditAmount: line.coreCreditAmount ?? null,\n vendorClaimLineId: line.vendorClaimLineId ?? null,\n vendorName: line.vendorName ?? null,\n deletedAt: toIso(line.deletedAt),\n updatedAt: toIso(line.updatedAt),\n }\n}\n\nasync function loadLineSnapshot(\n em: EntityManager,\n lineId: string,\n scope: WarrantyClaimScope,\n): Promise<LineSnapshot | null> {\n const line = await findOneWithDecryption(\n em,\n WarrantyClaimLine,\n { id: lineId, tenantId: scope.tenantId, organizationId: scope.organizationId },\n { populate: ['claim'] },\n scope,\n )\n return line ? snapshotLine(line) : null\n}\n\nfunction restoreLineFromSnapshot(line: WarrantyClaimLine, snapshot: LineSnapshot): void {\n line.lineNo = snapshot.lineNo\n line.productId = snapshot.productId\n line.variantId = snapshot.variantId\n line.sku = snapshot.sku\n line.productName = snapshot.productName\n line.orderLineId = snapshot.orderLineId\n line.serialNumber = snapshot.serialNumber\n line.lotNumber = snapshot.lotNumber\n line.purchaseDate = toDateOnly(snapshot.purchaseDate)\n line.warrantyMonths = snapshot.warrantyMonths\n line.warrantyExpiresAt = toDateOnly(snapshot.warrantyExpiresAt)\n line.warrantyStatus = snapshot.warrantyStatus\n line.faultCode = snapshot.faultCode\n line.faultDescription = snapshot.faultDescription\n line.qtyClaimed = snapshot.qtyClaimed\n line.qtyApproved = snapshot.qtyApproved\n line.qtyReceived = snapshot.qtyReceived\n line.conditionOnReceipt = snapshot.conditionOnReceipt\n line.conditionGrade = snapshot.conditionGrade\n line.quarantineStatus = snapshot.quarantineStatus\n line.inspectionNotes = snapshot.inspectionNotes\n line.assessmentPayload = snapshot.assessmentPayload\n line.disposition = snapshot.disposition\n line.lineStatus = snapshot.lineStatus\n line.creditAmount = snapshot.creditAmount\n line.restockingFee = snapshot.restockingFee\n line.coreChargeAmount = snapshot.coreChargeAmount\n line.coreCreditAmount = snapshot.coreCreditAmount\n line.vendorClaimLineId = snapshot.vendorClaimLineId\n line.vendorName = snapshot.vendorName\n line.deletedAt = toDate(snapshot.deletedAt)\n line.updatedAt = new Date()\n}\n\nasync function recomputeClaimRollups(em: EntityManager, claim: WarrantyClaim): Promise<void> {\n const lines = await findWithDecryption(\n em,\n WarrantyClaimLine,\n {\n claim: claim.id,\n tenantId: claim.tenantId,\n organizationId: claim.organizationId,\n deletedAt: null,\n },\n {},\n { tenantId: claim.tenantId, organizationId: claim.organizationId },\n )\n const totals = computeHeaderRollups(lines, { claimType: claim.claimType })\n claim.totalClaimedAmount = String(totals.totalClaimedAmount)\n claim.totalApprovedAmount = String(totals.totalApprovedAmount)\n claim.updatedAt = new Date()\n}\n\nasync function requireScopedLine(\n em: EntityManager,\n lineId: string,\n scope: WarrantyClaimScope,\n): Promise<WarrantyClaimLine> {\n const line = await findOneWithDecryption(\n em,\n WarrantyClaimLine,\n { id: lineId, tenantId: scope.tenantId, organizationId: scope.organizationId, deletedAt: null },\n { populate: ['claim'] },\n scope,\n )\n if (!line) throw new CrudHttpError(404, { error: 'warranty_claims.errors.notFound' })\n return line\n}\n\nasync function emitClaimUpdated(ctx: CommandRuntimeContext, claim: WarrantyClaim): Promise<void> {\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'updated',\n entity: claim,\n identifiers: { id: claim.id, organizationId: claim.organizationId, tenantId: claim.tenantId },\n indexer: { entityType: E.warranty_claims.warranty_claim },\n events: claimCrudEvents,\n })\n await invalidateCrudCache(\n ctx.container,\n 'warranty_claims.claim',\n { id: claim.id, organizationId: claim.organizationId, tenantId: claim.tenantId },\n ctx.auth?.tenantId ?? null,\n 'warranty_claims.claim_line.rollup',\n )\n}\n\nasync function emitLineCrud(\n ctx: CommandRuntimeContext,\n action: 'created' | 'updated' | 'deleted',\n line: WarrantyClaimLine,\n): Promise<void> {\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action,\n entity: line,\n identifiers: { id: line.id, organizationId: line.organizationId, tenantId: line.tenantId },\n indexer: { entityType: E.warranty_claims.warranty_claim_line },\n })\n await invalidateCrudCache(\n ctx.container,\n 'warranty_claims.claim_line',\n { id: line.id, organizationId: line.organizationId, tenantId: line.tenantId },\n ctx.auth?.tenantId ?? null,\n `warranty_claims.claim_line.${action}`,\n )\n}\n\nasync function emitLineUndoCrud(\n ctx: CommandRuntimeContext,\n action: 'created' | 'updated' | 'deleted',\n line: WarrantyClaimLine,\n): Promise<void> {\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action,\n entity: line,\n identifiers: { id: line.id, organizationId: line.organizationId, tenantId: line.tenantId },\n indexer: { entityType: E.warranty_claims.warranty_claim_line },\n })\n await invalidateCrudCache(\n ctx.container,\n 'warranty_claims.claim_line',\n { id: line.id, organizationId: line.organizationId, tenantId: line.tenantId },\n ctx.auth?.tenantId ?? null,\n `warranty_claims.claim_line.undo.${action}`,\n )\n}\n\nfunction buildLineLog(\n actionLabel: string,\n resourceId: string,\n snapshots: { before?: unknown; after?: unknown },\n): {\n actionLabel: string\n resourceKind: string\n resourceId: string\n parentResourceKind: string | null\n parentResourceId: string | null\n tenantId: string | null\n organizationId: string | null\n snapshotBefore: unknown\n snapshotAfter: unknown\n payload: { undo: LineUndoPayload }\n} {\n const after = snapshots.after as LineSnapshot | null | undefined\n const before = snapshots.before as LineSnapshot | null | undefined\n return {\n actionLabel,\n resourceKind: WARRANTY_CLAIM_LINE_RESOURCE_KIND,\n resourceId,\n parentResourceKind: WARRANTY_CLAIM_RESOURCE_KIND,\n parentResourceId: after?.claimId ?? before?.claimId ?? null,\n tenantId: after?.tenantId ?? before?.tenantId ?? null,\n organizationId: after?.organizationId ?? before?.organizationId ?? null,\n snapshotBefore: before ?? null,\n snapshotAfter: after ?? null,\n payload: { undo: { before: before ?? null, after: after ?? null } },\n }\n}\n\nconst createClaimLineCommand: CommandHandler<ClaimLineCreateInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.create',\n isUndoable: true,\n async execute(rawInput, ctx) {\n const input = parseCommandInput(claimLineCreateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const claim = await requireScopedClaim(em, input.claimId, scope)\n assertDispositionAllowedForType(claim.claimType, input.disposition ?? null)\n await enforceWarrantyClaimOptimisticLock(ctx, claim)\n assertParentMutable(claim)\n if (input.orderLineId) {\n await validateClaimReferences(ctx, scope, {\n lineOrderRefs: [{ orderLineId: input.orderLineId, orderId: claim.orderId ?? null }],\n })\n }\n let line!: WarrantyClaimLine\n let nextLineNo = input.lineNo ?? 1\n await withAtomicFlush(em, [\n async () => {\n await requireScopedClaim(em, claim.id, scope, { lockMode: LockMode.PESSIMISTIC_WRITE })\n const existingLines = await findWithDecryption(\n em,\n WarrantyClaimLine,\n {\n claim: claim.id,\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n deletedAt: null,\n },\n {},\n scope,\n )\n if (input.orderLineId) {\n await assertPendingClaimQuantitiesWithinSold(em, scope, new Map([[input.orderLineId, [{\n orderLineId: input.orderLineId,\n qtyClaimed: amountString(input.qtyClaimed, '1') ?? '1',\n }]]]), { currentClaimId: claim.id })\n }\n nextLineNo = input.lineNo ?? existingLines.reduce((max, entry) => Math.max(max, entry.lineNo), 0) + 1\n },\n () => {\n line = em.create(WarrantyClaimLine, buildLineCreateData(claim, input, nextLineNo))\n assertLineQuantities(line)\n em.persist(line)\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.create' })\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'created', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(claimLineCreateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.create', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n const scope = { tenantId: after.tenantId, organizationId: after.organizationId }\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: after.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ['claim'] }, scope)\n const claim = line ? claimOf(line) : null\n if (!line || !claim) return\n await withAtomicFlush(em, [\n () => {\n line.deletedAt = new Date()\n line.updatedAt = new Date()\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.create.undo' })\n await emitClaimUpdated(ctx, claim)\n await emitLineUndoCrud(ctx, 'deleted', line)\n },\n}\n\nconst updateClaimLineCommand: CommandHandler<ClaimLineUpdateInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.update',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(claimLineUpdateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(claimLineUpdateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = claimOf(line) ?? await requireScopedClaim(em, input.claimId ?? claimIdOf(line), scope)\n if (input.claimId && input.claimId !== claim.id) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.notFound' })\n }\n assertParentMutable(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND)\n if (hasOwn(input, 'orderLineId') && input.orderLineId && (input.orderLineId ?? null) !== (line.orderLineId ?? null)) {\n await validateClaimReferences(ctx, scope, {\n lineOrderRefs: [{ orderLineId: input.orderLineId, orderId: claim.orderId ?? null }],\n })\n }\n if (hasOwn(input, 'disposition')) {\n assertDispositionAllowedForType(claim.claimType, input.disposition ?? null)\n assertDispositionAllowedForGrade(toConditionGrade(line.conditionGrade), input.disposition ?? null)\n }\n const guardsClaimedQty = hasOwn(input, 'qtyClaimed') || hasOwn(input, 'orderLineId')\n await withAtomicFlush(em, [\n async () => {\n if (!guardsClaimedQty) return\n await requireScopedClaim(em, claim.id, scope, { lockMode: LockMode.PESSIMISTIC_WRITE })\n const orderLineId = hasOwn(input, 'orderLineId') ? (input.orderLineId ?? null) : (line.orderLineId ?? null)\n if (orderLineId) {\n await assertPendingClaimQuantitiesWithinSold(\n em,\n scope,\n new Map([[orderLineId, [{\n id: line.id,\n orderLineId,\n qtyClaimed: hasOwn(input, 'qtyClaimed')\n ? (amountString(input.qtyClaimed, '1') ?? '1')\n : line.qtyClaimed,\n }]]]),\n { currentClaimId: claim.id, excludedLineIds: new Set([line.id]) },\n )\n }\n },\n () => {\n applyLineUpdate(line, input)\n assertLineQuantities(line)\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.update' })\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'updated', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(claimLineUpdateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.update', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const scope = { tenantId: before.tenantId, organizationId: before.organizationId }\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ['claim'] }, scope)\n if (!line) return\n const claim = claimOf(line) ?? await requireScopedClaim(em, before.claimId, scope)\n await withAtomicFlush(em, [\n () => restoreLineFromSnapshot(line, before),\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.update.undo' })\n await emitClaimUpdated(ctx, claim)\n await emitLineUndoCrud(ctx, 'updated', line)\n },\n}\n\nconst deleteClaimLineCommand: CommandHandler<LineDeleteInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.delete',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(lineDeleteSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(lineDeleteSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = claimOf(line) ?? await requireScopedClaim(em, input.claimId ?? claimIdOf(line), scope)\n if (input.claimId && input.claimId !== claim.id) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.notFound' })\n }\n assertParentMutable(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND)\n await withAtomicFlush(em, [\n () => {\n line.deletedAt = new Date()\n line.updatedAt = new Date()\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.delete' })\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'deleted', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(lineDeleteSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.delete', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const scope = { tenantId: before.tenantId, organizationId: before.organizationId }\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n let line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ['claim'] }, scope)\n const claim = (line ? claimOf(line) : null) ?? await requireScopedClaim(em, before.claimId, scope)\n await withAtomicFlush(em, [\n () => {\n if (!line) {\n line = em.create(WarrantyClaimLine, {\n id: before.id,\n claim,\n organizationId: before.organizationId,\n tenantId: before.tenantId,\n lineNo: before.lineNo,\n qtyClaimed: before.qtyClaimed,\n lineStatus: before.lineStatus,\n warrantyStatus: before.warrantyStatus,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(line)\n }\n restoreLineFromSnapshot(line, before)\n line.deletedAt = null\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.delete.undo' })\n if (!line) return\n await emitClaimUpdated(ctx, claim)\n await emitLineUndoCrud(ctx, 'created', line)\n },\n}\n\nconst receiveClaimLineCommand: CommandHandler<ClaimLineReceiveInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.receive',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(claimLineReceiveSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(claimLineReceiveSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = await requireScopedClaim(em, claimIdOf(line), scope)\n assertReceivingStatus(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND, input.updatedAt ?? undefined)\n\n const grade: ConditionGrade = input.conditionGrade\n const effectiveSettings = await resolveEffectiveWarrantyClaimSettings(em, scope)\n const shouldQuarantine = Boolean(effectiveSettings.quarantineGrades?.includes(grade))\n\n await withAtomicFlush(em, [\n () => {\n line.conditionGrade = grade\n if (input.inspectionNotes !== undefined) line.inspectionNotes = input.inspectionNotes ?? null\n\n const suggestedDisposition = suggestedDispositionForGrade(grade)\n if (!line.disposition && suggestedDisposition) {\n assertDispositionAllowedForGrade(grade, suggestedDisposition)\n if (suggestedDisposition === 'restock' || suggestedDisposition === 'repair' || suggestedDisposition === 'scrap') {\n line.disposition = suggestedDisposition\n }\n }\n assertDispositionAllowedForGrade(grade, line.disposition ?? null)\n\n if (shouldQuarantine) line.quarantineStatus = 'held'\n line.updatedAt = new Date()\n appendClaimEvent(em, claim, 'system', {\n visibility: 'internal',\n payload: {\n action: 'line_received',\n lineId: line.id,\n conditionGrade: grade,\n disposition: line.disposition ?? null,\n quarantineStatus: line.quarantineStatus,\n quarantineHeld: shouldQuarantine,\n },\n actorUserId: ctx.auth?.sub ?? null,\n })\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.receive' })\n\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'updated', line)\n if (shouldQuarantine) {\n await emitWarrantyClaimsEvent('warranty_claims.claim_line.quarantined', {\n id: line.id,\n claimId: claim.id,\n lineId: line.id,\n grade,\n scope,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n }, {\n persistent: true,\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n })\n }\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(claimLineReceiveSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.receive', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const scope = { tenantId: before.tenantId, organizationId: before.organizationId }\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ['claim'] }, scope)\n if (!line) return\n const claim = await requireScopedClaim(em, before.claimId, scope)\n await withAtomicFlush(em, [\n () => restoreLineFromSnapshot(line, before),\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.receive.undo' })\n await emitClaimUpdated(ctx, claim)\n await emitLineUndoCrud(ctx, 'updated', line)\n },\n}\n\nconst releaseClaimLineQuarantineCommand: CommandHandler<ClaimLineReleaseQuarantineInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.release_quarantine',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(claimLineReleaseQuarantineSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(claimLineReleaseQuarantineSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = await requireScopedClaim(em, claimIdOf(line), scope)\n assertReceivingStatus(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND, input.updatedAt ?? undefined)\n\n await withAtomicFlush(em, [\n () => {\n line.quarantineStatus = 'released'\n line.updatedAt = new Date()\n appendClaimEvent(em, claim, 'system', {\n visibility: 'internal',\n payload: {\n action: 'line_quarantine_released',\n lineId: line.id,\n quarantineStatus: line.quarantineStatus,\n },\n actorUserId: ctx.auth?.sub ?? null,\n })\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.release_quarantine' })\n\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'updated', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(claimLineReleaseQuarantineSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.release_quarantine', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const scope = { tenantId: before.tenantId, organizationId: before.organizationId }\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ['claim'] }, scope)\n if (!line) return\n const claim = await requireScopedClaim(em, before.claimId, scope)\n await withAtomicFlush(em, [\n () => restoreLineFromSnapshot(line, before),\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.release_quarantine.undo' })\n await emitClaimUpdated(ctx, claim)\n await emitLineUndoCrud(ctx, 'updated', line)\n },\n}\n\nconst setClaimLineAssessmentCommand: CommandHandler<LineSetAssessmentInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.set_assessment',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(lineSetAssessmentSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(lineSetAssessmentSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = claimOf(line) ?? await requireScopedClaim(em, claimIdOf(line), scope)\n assertParentMutable(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND, input.updatedAt ?? undefined)\n\n await withAtomicFlush(em, [\n () => {\n line.assessmentPayload = input.assessmentPayload\n line.updatedAt = new Date()\n claim.updatedAt = new Date()\n appendClaimEvent(em, claim, 'system', {\n visibility: 'internal',\n payload: {\n action: 'ai_assessment_recorded',\n lineId: line.id,\n },\n actorUserId: ctx.auth?.sub ?? null,\n })\n },\n ], { transaction: true, label: 'warranty_claims.claim_line.set_assessment' })\n\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'updated', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(lineSetAssessmentSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.set_assessment', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const scope = { tenantId: before.tenantId, organizationId: before.organizationId }\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await findOneWithDecryption(em, WarrantyClaimLine, { id: before.id, tenantId: scope.tenantId, organizationId: scope.organizationId }, { populate: ['claim'] }, scope)\n if (!line) return\n const claim = claimOf(line) ?? await requireScopedClaim(em, before.claimId, scope)\n await withAtomicFlush(em, [\n () => restoreLineFromSnapshot(line, before),\n ], { transaction: true, label: 'warranty_claims.claim_line.set_assessment.undo' })\n await emitClaimUpdated(ctx, claim)\n await emitLineUndoCrud(ctx, 'updated', line)\n },\n}\n\nregisterCommand(createClaimLineCommand)\nregisterCommand(updateClaimLineCommand)\nregisterCommand(deleteClaimLineCommand)\nregisterCommand(receiveClaimLineCommand)\nregisterCommand(releaseClaimLineQuarantineCommand)\nregisterCommand(setClaimLineAssessmentCommand)\n\nexport const claimLineCommands = [\n createClaimLineCommand,\n updateClaimLineCommand,\n deleteClaimLineCommand,\n receiveClaimLineCommand,\n releaseClaimLineQuarantineCommand,\n setClaimLineAssessmentCommand,\n]\n\nexport {\n createClaimLineCommand,\n updateClaimLineCommand,\n deleteClaimLineCommand,\n receiveClaimLineCommand,\n releaseClaimLineQuarantineCommand,\n setClaimLineAssessmentCommand,\n}\n"],
5
- "mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAEzB,SAAS,SAAS;AAClB,SAAS,uBAAwE;AACjF,SAAS,uBAAuB;AAChC,SAAS,qBAAqB,+BAA+B;AAG7D,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,SAAS;AAClB,SAAwB,yBAAyB;AACjD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AACP,SAAS,+BAA+B;AACxC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,uCAAuC;AAChD,SAAS,6CAA6C;AACtD,SAAS,sBAAsB,wBAAwB;AACvD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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AQ,IAAI,EAAoB,KAAK;AAC/D,UAAM,OAAO,MAAM,sBAAsB,IAAI,mBAAmB,EAAE,IAAI,OAAO,IAAI,UAAU,MAAM,UAAU,gBAAgB,MAAM,eAAe,GAAG,EAAE,UAAU,CAAC,OAAO,EAAE,GAAG,KAAK;AACjL,QAAI,CAAC,KAAM;AACX,UAAM,QAAQ,QAAQ,IAAI,KAAK,MAAM,mBAAmB,IAAI,OAAO,SAAS,KAAK;AACjF,UAAM,gBAAgB,IAAI;AAAA,MACxB,MAAM,wBAAwB,MAAM,MAAM;AAAA,IAC5C,GAAG,EAAE,aAAa,MAAM,OAAO,iDAAiD,CAAC;AACjF,UAAM,iBAAiB,KAAK,KAAK;AACjC,UAAM,iBAAiB,KAAK,WAAW,IAAI;AAAA,EAC7C;AACF;AAEA,gBAAgB,sBAAsB;AACtC,gBAAgB,sBAAsB;AACtC,gBAAgB,sBAAsB;AACtC,gBAAgB,uBAAuB;AACvC,gBAAgB,iCAAiC;AACjD,gBAAgB,6BAA6B;AAEtC,MAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
4
+ "sourcesContent": ["import { randomUUID } from 'crypto'\nimport { LockMode } from '@mikro-orm/core'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { z } from 'zod'\nimport { registerCommand, type CommandHandler, type CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'\nimport { emitCrudSideEffects, emitCrudUndoSideEffects } from '@open-mercato/shared/lib/commands/helpers'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { invalidateCrudCache } from '@open-mercato/shared/lib/crud/cache'\nimport { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { E } from '#generated/entities.ids.generated'\nimport { WarrantyClaim, WarrantyClaimLine } from '../data/entities'\nimport {\n claimLineCreateSchema,\n claimLineReceiveSchema,\n claimLineReleaseQuarantineSchema,\n claimLineUpdateSchema,\n type ClaimLineCreateInput,\n type ClaimLineReceiveInput,\n type ClaimLineReleaseQuarantineInput,\n type ClaimLineUpdateInput,\n type WarrantyClaimDisposition,\n type WarrantyClaimLineStatus,\n type WarrantyClaimWarrantyStatus,\n} from '../data/validators'\nimport { emitWarrantyClaimsEvent } from '../events'\nimport {\n assertDispositionAllowedForGrade,\n suggestedDispositionForGrade,\n type ConditionGrade,\n} from '../lib/grading'\nimport { assertDispositionAllowedForType } from '../lib/claimTypeConfig'\nimport { resolveEffectiveWarrantyClaimSettings } from '../lib/settings'\nimport { computeHeaderRollups, lineStatusGuards } from '../lib/stateMachine'\nimport {\n WARRANTY_CLAIM_LINE_RESOURCE_KIND,\n WARRANTY_CLAIM_RESOURCE_KIND,\n appendClaimEvent,\n enforceWarrantyClaimOptimisticLock,\n ensureOrganizationScope,\n ensureTenantScope,\n extractUndoPayload,\n requireScopedClaim,\n throwUndoRefusal,\n type WarrantyClaimScope,\n} from './shared'\nimport { assertPendingClaimQuantitiesWithinSold, validateClaimReferences } from './claims'\n\nconst claimCrudEvents: CrudEventsConfig = {\n module: 'warranty_claims',\n entity: 'claim',\n persistent: true,\n}\n\nconst lineDeleteSchema = z\n .object({\n id: z.string().uuid(),\n claimId: z.string().uuid().optional(),\n organizationId: z.string().uuid().optional(),\n tenantId: z.string().uuid().optional(),\n })\n .strict()\n\ntype LineDeleteInput = z.infer<typeof lineDeleteSchema>\n\nconst lineSetAssessmentSchema = z\n .object({\n id: z.string().uuid(),\n organizationId: z.string().uuid().optional(),\n tenantId: z.string().uuid().optional(),\n assessmentPayload: z.record(z.string(), z.unknown()),\n updatedAt: z.union([z.string().datetime(), z.date()]).nullable().optional(),\n })\n .strict()\n\ntype LineSetAssessmentInput = z.infer<typeof lineSetAssessmentSchema>\n\ntype ScopeInput = {\n organizationId?: string | null\n tenantId?: string | null\n}\n\ntype LineSnapshot = {\n id: string\n claimId: string\n organizationId: string\n tenantId: string\n lineNo: number\n productId: string | null\n variantId: string | null\n sku: string | null\n productName: string | null\n orderLineId: string | null\n serialNumber: string | null\n lotNumber: string | null\n purchaseDate: string | null\n warrantyMonths: number | null\n warrantyExpiresAt: string | null\n warrantyStatus: WarrantyClaimWarrantyStatus\n faultCode: string | null\n faultDescription: string | null\n qtyClaimed: string\n qtyApproved: string | null\n qtyReceived: string | null\n conditionOnReceipt: string | null\n conditionGrade: string | null\n quarantineStatus: string\n inspectionNotes: string | null\n assessmentPayload: Record<string, unknown> | null\n disposition: WarrantyClaimDisposition | null\n lineStatus: WarrantyClaimLineStatus\n creditAmount: string | null\n restockingFee: string | null\n coreChargeAmount: string | null\n coreCreditAmount: string | null\n vendorClaimLineId: string | null\n vendorName: string | null\n deletedAt: string | null\n updatedAt: string | null\n}\n\ntype LineUndoPayload = {\n before?: LineSnapshot | null\n after?: LineSnapshot | null\n}\n\nconst mutableParentStatuses = new Set([\n 'draft',\n 'submitted',\n 'in_review',\n 'info_requested',\n 'approved',\n 'received',\n 'inspecting',\n])\n\nconst receivingParentStatuses = new Set(['received', 'inspecting'])\n\ntype LineUndoParentRule = {\n allowedParentStatuses: ReadonlySet<string>\n lockedKey: string\n lockedFallback: string\n}\n\ntype LineUndoState = {\n claim: WarrantyClaim\n line: WarrantyClaimLine\n}\n\nconst mutableParentUndoRule: LineUndoParentRule = {\n allowedParentStatuses: mutableParentStatuses,\n lockedKey: 'warranty_claims.errors.lineLocked',\n lockedFallback: 'This line is locked in the current claim status.',\n}\n\nconst receivingParentUndoRule: LineUndoParentRule = {\n allowedParentStatuses: receivingParentStatuses,\n lockedKey: 'warranty_claims.errors.receivingStatusInvalid',\n lockedFallback: 'Receiving details can only be saved when the claim is received or under inspection.',\n}\n\nfunction parseCommandInput<T>(schema: z.ZodType<T>, rawInput: unknown): T {\n const result = schema.safeParse(rawInput ?? {})\n if (!result.success) {\n throw new CrudHttpError(400, { error: '[internal] invalid warranty claim line command input' })\n }\n return result.data\n}\n\nfunction hasOwn(input: object, key: string): boolean {\n return Object.prototype.hasOwnProperty.call(input, key)\n}\n\nfunction resolveScope(ctx: CommandRuntimeContext, input: ScopeInput): WarrantyClaimScope {\n const tenantId = input.tenantId ?? ctx.auth?.tenantId ?? null\n const organizationId = input.organizationId ?? ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null\n if (!tenantId) throw new CrudHttpError(400, { error: '[internal] tenant scope required for warranty claim line command' })\n if (!organizationId) throw new CrudHttpError(400, { error: '[internal] organization scope required for warranty claim line command' })\n ensureTenantScope(ctx, tenantId)\n ensureOrganizationScope(ctx, organizationId)\n return { tenantId, organizationId }\n}\n\nfunction toIso(value: Date | string | null | undefined): string | null {\n if (!value) return null\n const date = value instanceof Date ? value : new Date(value)\n return Number.isNaN(date.getTime()) ? null : date.toISOString()\n}\n\nfunction toDate(value: string | null): Date | null {\n if (!value) return null\n const date = new Date(value)\n return Number.isNaN(date.getTime()) ? null : date\n}\n\nfunction toDateOnlyIso(value: Date | string | null | undefined): string | null {\n const iso = toIso(value)\n return iso ? iso.slice(0, 10) : null\n}\n\nfunction toDateOnly(value: string | null): Date | null {\n if (!value) return null\n const date = new Date(`${value}T00:00:00.000Z`)\n return Number.isNaN(date.getTime()) ? null : date\n}\n\nfunction amountString(value: number | string | null | undefined, fallback = '0'): string | null {\n if (value === null) return null\n if (value === undefined) return fallback\n const parsed = typeof value === 'number' ? value : Number(value)\n if (!Number.isFinite(parsed)) return fallback\n return String(parsed)\n}\n\nfunction nullableAmountString(value: number | string | null | undefined): string | null {\n if (value === undefined || value === null) return null\n return amountString(value, '0')\n}\n\nfunction numberValue(value: string | number | null | undefined): number {\n if (value === null || value === undefined) return 0\n const parsed = typeof value === 'number' ? value : Number(value)\n return Number.isFinite(parsed) ? parsed : 0\n}\n\nfunction addMonths(date: Date, months: number): Date {\n const target = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + months, 1))\n const lastDay = new Date(Date.UTC(target.getUTCFullYear(), target.getUTCMonth() + 1, 0)).getUTCDate()\n const copy = new Date(date.getTime())\n copy.setUTCDate(1)\n copy.setUTCFullYear(target.getUTCFullYear(), target.getUTCMonth(), Math.min(date.getUTCDate(), lastDay))\n return copy\n}\n\nfunction computeWarrantyDates(\n purchaseDate: Date | null | undefined,\n warrantyMonths: number | null | undefined,\n): { warrantyExpiresAt: Date | null; warrantyStatus: WarrantyClaimWarrantyStatus } {\n if (!purchaseDate || warrantyMonths === null || warrantyMonths === undefined) {\n return { warrantyExpiresAt: null, warrantyStatus: 'unknown' }\n }\n const warrantyExpiresAt = addMonths(purchaseDate, warrantyMonths)\n const warrantyStatus = warrantyExpiresAt.getTime() >= Date.now() ? 'in_warranty' : 'out_of_warranty'\n return { warrantyExpiresAt, warrantyStatus }\n}\n\nfunction claimIdOf(line: WarrantyClaimLine): string {\n const claim = line.claim\n if (typeof claim === 'object' && claim && 'id' in claim && typeof claim.id === 'string') return claim.id\n return String(claim)\n}\n\nfunction claimOf(line: WarrantyClaimLine): WarrantyClaim | null {\n const claim = line.claim\n if (typeof claim === 'object' && claim && 'id' in claim && typeof claim.id === 'string') return claim as WarrantyClaim\n return null\n}\n\nfunction sameDateValue(left: Date | null | undefined, right: Date | null | undefined): boolean {\n const leftTime = left instanceof Date ? left.getTime() : null\n const rightTime = right instanceof Date ? right.getTime() : null\n return leftTime === rightTime\n}\n\nfunction assertParentMutable(claim: WarrantyClaim): void {\n if (!mutableParentStatuses.has(claim.status)) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.lineLocked' })\n }\n}\n\nfunction assertReceivingStatus(claim: WarrantyClaim): void {\n if (claim.status !== 'received' && claim.status !== 'inspecting') {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.receivingStatusInvalid' })\n }\n}\n\nfunction toConditionGrade(value: string | null | undefined): ConditionGrade | null {\n if (value === 'A' || value === 'B' || value === 'C' || value === 'D') return value\n return null\n}\n\nfunction assertLineQuantities(line: WarrantyClaimLine): void {\n const qtyClaimed = numberValue(line.qtyClaimed)\n const qtyApproved = line.qtyApproved === null || line.qtyApproved === undefined ? null : numberValue(line.qtyApproved)\n const qtyReceived = line.qtyReceived === null || line.qtyReceived === undefined ? null : numberValue(line.qtyReceived)\n if (qtyClaimed < 0 || (qtyApproved !== null && qtyApproved < 0) || (qtyReceived !== null && qtyReceived < 0)) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.lineLocked' })\n }\n if (qtyApproved !== null && qtyApproved > qtyClaimed) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.lineLocked' })\n }\n if (qtyReceived !== null && qtyReceived > qtyClaimed) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.lineLocked' })\n }\n}\n\nfunction assertLineStatusMove(from: WarrantyClaimLineStatus, to: WarrantyClaimLineStatus): void {\n if (from === to) return\n if (lineStatusGuards[from].includes(to)) return\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.invalidTransition' })\n}\n\nfunction buildLineCreateData(\n claim: WarrantyClaim,\n input: ClaimLineCreateInput,\n lineNo: number,\n): Partial<WarrantyClaimLine> & {\n id: string\n claim: WarrantyClaim\n organizationId: string\n tenantId: string\n lineNo: number\n qtyClaimed: string\n lineStatus: WarrantyClaimLineStatus\n warrantyStatus: WarrantyClaimWarrantyStatus\n createdAt: Date\n updatedAt: Date\n} {\n const purchaseDate = input.purchaseDate ?? null\n const warrantyMonths = input.warrantyMonths ?? null\n const computedWarranty = computeWarrantyDates(purchaseDate, warrantyMonths)\n return {\n id: randomUUID(),\n claim,\n organizationId: claim.organizationId,\n tenantId: claim.tenantId,\n lineNo,\n productId: input.productId ?? null,\n variantId: input.variantId ?? null,\n sku: input.sku ?? null,\n productName: input.productName ?? null,\n orderLineId: input.orderLineId ?? null,\n serialNumber: input.serialNumber ?? null,\n lotNumber: input.lotNumber ?? null,\n purchaseDate,\n warrantyMonths,\n warrantyExpiresAt: input.warrantyExpiresAt ?? computedWarranty.warrantyExpiresAt,\n warrantyStatus: input.warrantyStatus ?? computedWarranty.warrantyStatus,\n faultCode: input.faultCode ?? null,\n faultDescription: input.faultDescription ?? null,\n qtyClaimed: amountString(input.qtyClaimed, '1') ?? '1',\n qtyApproved: nullableAmountString(input.qtyApproved),\n qtyReceived: nullableAmountString(input.qtyReceived),\n conditionOnReceipt: input.conditionOnReceipt ?? null,\n inspectionNotes: input.inspectionNotes ?? null,\n disposition: input.disposition ?? null,\n vendorName: input.vendorName ?? null,\n lineStatus: 'pending',\n creditAmount: nullableAmountString(input.creditAmount),\n restockingFee: nullableAmountString(input.restockingFee),\n coreChargeAmount: nullableAmountString(input.coreChargeAmount),\n coreCreditAmount: nullableAmountString(input.coreCreditAmount),\n createdAt: new Date(),\n updatedAt: new Date(),\n }\n}\n\nfunction applyLineUpdate(line: WarrantyClaimLine, input: ClaimLineUpdateInput): void {\n const purchaseDateChanged = hasOwn(input, 'purchaseDate') && !sameDateValue(line.purchaseDate ?? null, input.purchaseDate ?? null)\n const warrantyMonthsChanged = hasOwn(input, 'warrantyMonths') && (line.warrantyMonths ?? null) !== (input.warrantyMonths ?? null)\n const hasExplicitWarranty = hasOwn(input, 'warrantyExpiresAt') || hasOwn(input, 'warrantyStatus')\n if (hasOwn(input, 'lineNo') && input.lineNo !== undefined) line.lineNo = input.lineNo\n if (hasOwn(input, 'productId')) line.productId = input.productId ?? null\n if (hasOwn(input, 'variantId')) line.variantId = input.variantId ?? null\n if (hasOwn(input, 'sku')) line.sku = input.sku ?? null\n if (hasOwn(input, 'productName')) line.productName = input.productName ?? null\n if (hasOwn(input, 'orderLineId')) line.orderLineId = input.orderLineId ?? null\n if (hasOwn(input, 'serialNumber')) line.serialNumber = input.serialNumber ?? null\n if (hasOwn(input, 'lotNumber')) line.lotNumber = input.lotNumber ?? null\n if (hasOwn(input, 'purchaseDate')) line.purchaseDate = input.purchaseDate ?? null\n if (hasOwn(input, 'warrantyMonths')) line.warrantyMonths = input.warrantyMonths ?? null\n if (hasOwn(input, 'warrantyExpiresAt')) line.warrantyExpiresAt = input.warrantyExpiresAt ?? null\n if (hasOwn(input, 'warrantyStatus') && input.warrantyStatus) line.warrantyStatus = input.warrantyStatus\n if (hasOwn(input, 'faultCode')) line.faultCode = input.faultCode ?? null\n if (hasOwn(input, 'faultDescription')) line.faultDescription = input.faultDescription ?? null\n if (hasOwn(input, 'qtyClaimed') && input.qtyClaimed !== undefined) line.qtyClaimed = amountString(input.qtyClaimed, '1') ?? '1'\n if (hasOwn(input, 'qtyApproved')) line.qtyApproved = nullableAmountString(input.qtyApproved)\n if (hasOwn(input, 'qtyReceived')) line.qtyReceived = nullableAmountString(input.qtyReceived)\n if (hasOwn(input, 'conditionOnReceipt')) line.conditionOnReceipt = input.conditionOnReceipt ?? null\n if (hasOwn(input, 'inspectionNotes')) line.inspectionNotes = input.inspectionNotes ?? null\n if (hasOwn(input, 'disposition')) line.disposition = input.disposition ?? null\n if (hasOwn(input, 'vendorName')) line.vendorName = input.vendorName ?? null\n if (hasOwn(input, 'lineStatus') && input.lineStatus) {\n assertLineStatusMove(line.lineStatus, input.lineStatus)\n line.lineStatus = input.lineStatus\n }\n if (hasOwn(input, 'creditAmount')) line.creditAmount = nullableAmountString(input.creditAmount)\n if (hasOwn(input, 'restockingFee')) line.restockingFee = nullableAmountString(input.restockingFee)\n if (hasOwn(input, 'coreChargeAmount')) line.coreChargeAmount = nullableAmountString(input.coreChargeAmount)\n if (hasOwn(input, 'coreCreditAmount')) line.coreCreditAmount = nullableAmountString(input.coreCreditAmount)\n if ((purchaseDateChanged || warrantyMonthsChanged) && !hasExplicitWarranty) {\n const computedWarranty = computeWarrantyDates(line.purchaseDate ?? null, line.warrantyMonths ?? null)\n line.warrantyExpiresAt = computedWarranty.warrantyExpiresAt\n line.warrantyStatus = computedWarranty.warrantyStatus\n }\n line.updatedAt = new Date()\n}\n\nfunction snapshotLine(line: WarrantyClaimLine): LineSnapshot {\n return {\n id: line.id,\n claimId: claimIdOf(line),\n organizationId: line.organizationId,\n tenantId: line.tenantId,\n lineNo: line.lineNo,\n productId: line.productId ?? null,\n variantId: line.variantId ?? null,\n sku: line.sku ?? null,\n productName: line.productName ?? null,\n orderLineId: line.orderLineId ?? null,\n serialNumber: line.serialNumber ?? null,\n lotNumber: line.lotNumber ?? null,\n purchaseDate: toDateOnlyIso(line.purchaseDate),\n warrantyMonths: line.warrantyMonths ?? null,\n warrantyExpiresAt: toDateOnlyIso(line.warrantyExpiresAt),\n warrantyStatus: line.warrantyStatus,\n faultCode: line.faultCode ?? null,\n faultDescription: line.faultDescription ?? null,\n qtyClaimed: line.qtyClaimed,\n qtyApproved: line.qtyApproved ?? null,\n qtyReceived: line.qtyReceived ?? null,\n conditionOnReceipt: line.conditionOnReceipt ?? null,\n conditionGrade: line.conditionGrade ?? null,\n quarantineStatus: line.quarantineStatus,\n inspectionNotes: line.inspectionNotes ?? null,\n assessmentPayload: line.assessmentPayload ?? null,\n disposition: line.disposition ?? null,\n lineStatus: line.lineStatus,\n creditAmount: line.creditAmount ?? null,\n restockingFee: line.restockingFee ?? null,\n coreChargeAmount: line.coreChargeAmount ?? null,\n coreCreditAmount: line.coreCreditAmount ?? null,\n vendorClaimLineId: line.vendorClaimLineId ?? null,\n vendorName: line.vendorName ?? null,\n deletedAt: toIso(line.deletedAt),\n updatedAt: toIso(line.updatedAt),\n }\n}\n\nasync function loadLineSnapshot(\n em: EntityManager,\n lineId: string,\n scope: WarrantyClaimScope,\n): Promise<LineSnapshot | null> {\n const line = await findOneWithDecryption(\n em,\n WarrantyClaimLine,\n { id: lineId, tenantId: scope.tenantId, organizationId: scope.organizationId },\n { populate: ['claim'] },\n scope,\n )\n return line ? snapshotLine(line) : null\n}\n\nfunction restoreLineFromSnapshot(line: WarrantyClaimLine, snapshot: LineSnapshot): void {\n line.lineNo = snapshot.lineNo\n line.productId = snapshot.productId\n line.variantId = snapshot.variantId\n line.sku = snapshot.sku\n line.productName = snapshot.productName\n line.orderLineId = snapshot.orderLineId\n line.serialNumber = snapshot.serialNumber\n line.lotNumber = snapshot.lotNumber\n line.purchaseDate = toDateOnly(snapshot.purchaseDate)\n line.warrantyMonths = snapshot.warrantyMonths\n line.warrantyExpiresAt = toDateOnly(snapshot.warrantyExpiresAt)\n line.warrantyStatus = snapshot.warrantyStatus\n line.faultCode = snapshot.faultCode\n line.faultDescription = snapshot.faultDescription\n line.qtyClaimed = snapshot.qtyClaimed\n line.qtyApproved = snapshot.qtyApproved\n line.qtyReceived = snapshot.qtyReceived\n line.conditionOnReceipt = snapshot.conditionOnReceipt\n line.conditionGrade = snapshot.conditionGrade\n line.quarantineStatus = snapshot.quarantineStatus\n line.inspectionNotes = snapshot.inspectionNotes\n line.assessmentPayload = snapshot.assessmentPayload\n line.disposition = snapshot.disposition\n line.lineStatus = snapshot.lineStatus\n line.creditAmount = snapshot.creditAmount\n line.restockingFee = snapshot.restockingFee\n line.coreChargeAmount = snapshot.coreChargeAmount\n line.coreCreditAmount = snapshot.coreCreditAmount\n line.vendorClaimLineId = snapshot.vendorClaimLineId\n line.vendorName = snapshot.vendorName\n line.deletedAt = toDate(snapshot.deletedAt)\n line.updatedAt = new Date()\n}\n\nasync function recomputeClaimRollups(em: EntityManager, claim: WarrantyClaim): Promise<void> {\n const lines = await findWithDecryption(\n em,\n WarrantyClaimLine,\n {\n claim: claim.id,\n tenantId: claim.tenantId,\n organizationId: claim.organizationId,\n deletedAt: null,\n },\n {},\n { tenantId: claim.tenantId, organizationId: claim.organizationId },\n )\n const totals = computeHeaderRollups(lines, { claimType: claim.claimType })\n claim.totalClaimedAmount = String(totals.totalClaimedAmount)\n claim.totalApprovedAmount = String(totals.totalApprovedAmount)\n claim.updatedAt = new Date()\n}\n\nfunction refuseLineUndoConflict(): Promise<never> {\n return throwUndoRefusal('warranty_claims.errors.conflict', 'This claim changed while you were editing it.')\n}\n\nasync function requireCurrentLineUndoState(\n em: EntityManager,\n after: LineSnapshot | null | undefined,\n rule: LineUndoParentRule,\n): Promise<LineUndoState> {\n if (!after) return refuseLineUndoConflict()\n const scope: WarrantyClaimScope = { tenantId: after.tenantId, organizationId: after.organizationId }\n const claim = await findOneWithDecryption(\n em,\n WarrantyClaim,\n { id: after.claimId, tenantId: scope.tenantId, organizationId: scope.organizationId, deletedAt: null },\n { lockMode: LockMode.PESSIMISTIC_WRITE },\n scope,\n )\n if (!claim) return refuseLineUndoConflict()\n if (!rule.allowedParentStatuses.has(claim.status)) return throwUndoRefusal(rule.lockedKey, rule.lockedFallback)\n const line = await findOneWithDecryption(\n em,\n WarrantyClaimLine,\n { id: after.id, tenantId: scope.tenantId, organizationId: scope.organizationId },\n { lockMode: LockMode.PESSIMISTIC_WRITE },\n scope,\n )\n if (!line || !after.updatedAt || toIso(line.updatedAt) !== after.updatedAt) return refuseLineUndoConflict()\n return { claim, line }\n}\n\nasync function requireScopedLine(\n em: EntityManager,\n lineId: string,\n scope: WarrantyClaimScope,\n): Promise<WarrantyClaimLine> {\n const line = await findOneWithDecryption(\n em,\n WarrantyClaimLine,\n { id: lineId, tenantId: scope.tenantId, organizationId: scope.organizationId, deletedAt: null },\n { populate: ['claim'] },\n scope,\n )\n if (!line) throw new CrudHttpError(404, { error: 'warranty_claims.errors.notFound' })\n return line\n}\n\nasync function emitClaimUpdated(ctx: CommandRuntimeContext, claim: WarrantyClaim): Promise<void> {\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'updated',\n entity: claim,\n identifiers: { id: claim.id, organizationId: claim.organizationId, tenantId: claim.tenantId },\n indexer: { entityType: E.warranty_claims.warranty_claim },\n events: claimCrudEvents,\n })\n await invalidateCrudCache(\n ctx.container,\n 'warranty_claims.claim',\n { id: claim.id, organizationId: claim.organizationId, tenantId: claim.tenantId },\n ctx.auth?.tenantId ?? null,\n 'warranty_claims.claim_line.rollup',\n )\n}\n\nasync function emitLineCrud(\n ctx: CommandRuntimeContext,\n action: 'created' | 'updated' | 'deleted',\n line: WarrantyClaimLine,\n): Promise<void> {\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action,\n entity: line,\n identifiers: { id: line.id, organizationId: line.organizationId, tenantId: line.tenantId },\n indexer: { entityType: E.warranty_claims.warranty_claim_line },\n })\n await invalidateCrudCache(\n ctx.container,\n 'warranty_claims.claim_line',\n { id: line.id, organizationId: line.organizationId, tenantId: line.tenantId },\n ctx.auth?.tenantId ?? null,\n `warranty_claims.claim_line.${action}`,\n )\n}\n\nasync function emitLineUndoCrud(\n ctx: CommandRuntimeContext,\n action: 'created' | 'updated' | 'deleted',\n line: WarrantyClaimLine,\n): Promise<void> {\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action,\n entity: line,\n identifiers: { id: line.id, organizationId: line.organizationId, tenantId: line.tenantId },\n indexer: { entityType: E.warranty_claims.warranty_claim_line },\n })\n await invalidateCrudCache(\n ctx.container,\n 'warranty_claims.claim_line',\n { id: line.id, organizationId: line.organizationId, tenantId: line.tenantId },\n ctx.auth?.tenantId ?? null,\n `warranty_claims.claim_line.undo.${action}`,\n )\n}\n\nfunction buildLineLog(\n actionLabel: string,\n resourceId: string,\n snapshots: { before?: unknown; after?: unknown },\n): {\n actionLabel: string\n resourceKind: string\n resourceId: string\n parentResourceKind: string | null\n parentResourceId: string | null\n tenantId: string | null\n organizationId: string | null\n snapshotBefore: unknown\n snapshotAfter: unknown\n payload: { undo: LineUndoPayload }\n} {\n const after = snapshots.after as LineSnapshot | null | undefined\n const before = snapshots.before as LineSnapshot | null | undefined\n return {\n actionLabel,\n resourceKind: WARRANTY_CLAIM_LINE_RESOURCE_KIND,\n resourceId,\n parentResourceKind: WARRANTY_CLAIM_RESOURCE_KIND,\n parentResourceId: after?.claimId ?? before?.claimId ?? null,\n tenantId: after?.tenantId ?? before?.tenantId ?? null,\n organizationId: after?.organizationId ?? before?.organizationId ?? null,\n snapshotBefore: before ?? null,\n snapshotAfter: after ?? null,\n payload: { undo: { before: before ?? null, after: after ?? null } },\n }\n}\n\nconst createClaimLineCommand: CommandHandler<ClaimLineCreateInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.create',\n isUndoable: true,\n async execute(rawInput, ctx) {\n const input = parseCommandInput(claimLineCreateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const claim = await requireScopedClaim(em, input.claimId, scope)\n assertDispositionAllowedForType(claim.claimType, input.disposition ?? null)\n await enforceWarrantyClaimOptimisticLock(ctx, claim)\n assertParentMutable(claim)\n if (input.orderLineId) {\n await validateClaimReferences(ctx, scope, {\n lineOrderRefs: [{ orderLineId: input.orderLineId, orderId: claim.orderId ?? null }],\n })\n }\n let line!: WarrantyClaimLine\n let nextLineNo = input.lineNo ?? 1\n await withAtomicFlush(em, [\n async () => {\n await requireScopedClaim(em, claim.id, scope, { lockMode: LockMode.PESSIMISTIC_WRITE })\n const existingLines = await findWithDecryption(\n em,\n WarrantyClaimLine,\n {\n claim: claim.id,\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n deletedAt: null,\n },\n {},\n scope,\n )\n if (input.orderLineId) {\n await assertPendingClaimQuantitiesWithinSold(em, scope, new Map([[input.orderLineId, [{\n orderLineId: input.orderLineId,\n qtyClaimed: amountString(input.qtyClaimed, '1') ?? '1',\n }]]]), { currentClaimId: claim.id })\n }\n nextLineNo = input.lineNo ?? existingLines.reduce((max, entry) => Math.max(max, entry.lineNo), 0) + 1\n },\n () => {\n line = em.create(WarrantyClaimLine, buildLineCreateData(claim, input, nextLineNo))\n assertLineQuantities(line)\n em.persist(line)\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.create' })\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'created', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(claimLineCreateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.create', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n let state!: LineUndoState\n await withAtomicFlush(em, [\n async () => {\n state = await requireCurrentLineUndoState(em, payload?.after, mutableParentUndoRule)\n },\n () => {\n state.line.deletedAt = new Date()\n state.line.updatedAt = new Date()\n },\n () => recomputeClaimRollups(em, state.claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.create.undo' })\n await emitClaimUpdated(ctx, state.claim)\n await emitLineUndoCrud(ctx, 'deleted', state.line)\n },\n}\n\nconst updateClaimLineCommand: CommandHandler<ClaimLineUpdateInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.update',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(claimLineUpdateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(claimLineUpdateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = claimOf(line) ?? await requireScopedClaim(em, input.claimId ?? claimIdOf(line), scope)\n if (input.claimId && input.claimId !== claim.id) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.notFound' })\n }\n assertParentMutable(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND)\n if (hasOwn(input, 'orderLineId') && input.orderLineId && (input.orderLineId ?? null) !== (line.orderLineId ?? null)) {\n await validateClaimReferences(ctx, scope, {\n lineOrderRefs: [{ orderLineId: input.orderLineId, orderId: claim.orderId ?? null }],\n })\n }\n if (hasOwn(input, 'disposition')) {\n assertDispositionAllowedForType(claim.claimType, input.disposition ?? null)\n assertDispositionAllowedForGrade(toConditionGrade(line.conditionGrade), input.disposition ?? null)\n }\n const guardsClaimedQty = hasOwn(input, 'qtyClaimed') || hasOwn(input, 'orderLineId')\n await withAtomicFlush(em, [\n async () => {\n if (!guardsClaimedQty) return\n await requireScopedClaim(em, claim.id, scope, { lockMode: LockMode.PESSIMISTIC_WRITE })\n const orderLineId = hasOwn(input, 'orderLineId') ? (input.orderLineId ?? null) : (line.orderLineId ?? null)\n if (orderLineId) {\n await assertPendingClaimQuantitiesWithinSold(\n em,\n scope,\n new Map([[orderLineId, [{\n id: line.id,\n orderLineId,\n qtyClaimed: hasOwn(input, 'qtyClaimed')\n ? (amountString(input.qtyClaimed, '1') ?? '1')\n : line.qtyClaimed,\n }]]]),\n { currentClaimId: claim.id, excludedLineIds: new Set([line.id]) },\n )\n }\n },\n () => {\n applyLineUpdate(line, input)\n assertLineQuantities(line)\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.update' })\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'updated', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(claimLineUpdateSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.update', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n let state!: LineUndoState\n await withAtomicFlush(em, [\n async () => {\n state = await requireCurrentLineUndoState(em, payload?.after, mutableParentUndoRule)\n },\n () => restoreLineFromSnapshot(state.line, before),\n () => recomputeClaimRollups(em, state.claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.update.undo' })\n await emitClaimUpdated(ctx, state.claim)\n await emitLineUndoCrud(ctx, 'updated', state.line)\n },\n}\n\nconst deleteClaimLineCommand: CommandHandler<LineDeleteInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.delete',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(lineDeleteSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(lineDeleteSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = claimOf(line) ?? await requireScopedClaim(em, input.claimId ?? claimIdOf(line), scope)\n if (input.claimId && input.claimId !== claim.id) {\n throw new CrudHttpError(400, { error: 'warranty_claims.errors.notFound' })\n }\n assertParentMutable(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND)\n await withAtomicFlush(em, [\n () => {\n line.deletedAt = new Date()\n line.updatedAt = new Date()\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.delete' })\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'deleted', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(lineDeleteSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.delete', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n let state!: LineUndoState\n await withAtomicFlush(em, [\n async () => {\n state = await requireCurrentLineUndoState(em, payload?.after, mutableParentUndoRule)\n },\n () => {\n restoreLineFromSnapshot(state.line, before)\n state.line.deletedAt = null\n },\n () => recomputeClaimRollups(em, state.claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.delete.undo' })\n await emitClaimUpdated(ctx, state.claim)\n await emitLineUndoCrud(ctx, 'created', state.line)\n },\n}\n\nconst receiveClaimLineCommand: CommandHandler<ClaimLineReceiveInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.receive',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(claimLineReceiveSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(claimLineReceiveSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = await requireScopedClaim(em, claimIdOf(line), scope)\n assertReceivingStatus(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND, input.updatedAt ?? undefined)\n\n const grade: ConditionGrade = input.conditionGrade\n const effectiveSettings = await resolveEffectiveWarrantyClaimSettings(em, scope)\n const shouldQuarantine = Boolean(effectiveSettings.quarantineGrades?.includes(grade))\n\n await withAtomicFlush(em, [\n () => {\n line.conditionGrade = grade\n if (input.inspectionNotes !== undefined) line.inspectionNotes = input.inspectionNotes ?? null\n\n const suggestedDisposition = suggestedDispositionForGrade(grade)\n if (!line.disposition && suggestedDisposition) {\n assertDispositionAllowedForGrade(grade, suggestedDisposition)\n if (suggestedDisposition === 'restock' || suggestedDisposition === 'repair' || suggestedDisposition === 'scrap') {\n line.disposition = suggestedDisposition\n }\n }\n assertDispositionAllowedForGrade(grade, line.disposition ?? null)\n\n if (shouldQuarantine) line.quarantineStatus = 'held'\n line.updatedAt = new Date()\n appendClaimEvent(em, claim, 'system', {\n visibility: 'internal',\n payload: {\n action: 'line_received',\n lineId: line.id,\n conditionGrade: grade,\n disposition: line.disposition ?? null,\n quarantineStatus: line.quarantineStatus,\n quarantineHeld: shouldQuarantine,\n },\n actorUserId: ctx.auth?.sub ?? null,\n })\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.receive' })\n\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'updated', line)\n if (shouldQuarantine) {\n await emitWarrantyClaimsEvent('warranty_claims.claim_line.quarantined', {\n id: line.id,\n claimId: claim.id,\n lineId: line.id,\n grade,\n scope,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n }, {\n persistent: true,\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n })\n }\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(claimLineReceiveSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.receive', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n let state!: LineUndoState\n await withAtomicFlush(em, [\n async () => {\n state = await requireCurrentLineUndoState(em, payload?.after, receivingParentUndoRule)\n },\n () => restoreLineFromSnapshot(state.line, before),\n () => recomputeClaimRollups(em, state.claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.receive.undo' })\n await emitClaimUpdated(ctx, state.claim)\n await emitLineUndoCrud(ctx, 'updated', state.line)\n },\n}\n\nconst releaseClaimLineQuarantineCommand: CommandHandler<ClaimLineReleaseQuarantineInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.release_quarantine',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(claimLineReleaseQuarantineSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(claimLineReleaseQuarantineSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = await requireScopedClaim(em, claimIdOf(line), scope)\n assertReceivingStatus(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND, input.updatedAt ?? undefined)\n\n await withAtomicFlush(em, [\n () => {\n line.quarantineStatus = 'released'\n line.updatedAt = new Date()\n appendClaimEvent(em, claim, 'system', {\n visibility: 'internal',\n payload: {\n action: 'line_quarantine_released',\n lineId: line.id,\n quarantineStatus: line.quarantineStatus,\n },\n actorUserId: ctx.auth?.sub ?? null,\n })\n },\n () => recomputeClaimRollups(em, claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.release_quarantine' })\n\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'updated', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(claimLineReleaseQuarantineSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.release_quarantine', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n let state!: LineUndoState\n await withAtomicFlush(em, [\n async () => {\n state = await requireCurrentLineUndoState(em, payload?.after, receivingParentUndoRule)\n },\n () => restoreLineFromSnapshot(state.line, before),\n () => recomputeClaimRollups(em, state.claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.release_quarantine.undo' })\n await emitClaimUpdated(ctx, state.claim)\n await emitLineUndoCrud(ctx, 'updated', state.line)\n },\n}\n\nconst setClaimLineAssessmentCommand: CommandHandler<LineSetAssessmentInput, { lineId: string; claimId: string }> = {\n id: 'warranty_claims.claim_line.set_assessment',\n isUndoable: true,\n prepare: async (rawInput, ctx) => {\n const input = parseCommandInput(lineSetAssessmentSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return { before: await loadLineSnapshot(em, input.id, scope) }\n },\n async execute(rawInput, ctx) {\n const input = parseCommandInput(lineSetAssessmentSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const line = await requireScopedLine(em, input.id, scope)\n const claim = claimOf(line) ?? await requireScopedClaim(em, claimIdOf(line), scope)\n assertParentMutable(claim)\n await enforceWarrantyClaimOptimisticLock(ctx, line, WARRANTY_CLAIM_LINE_RESOURCE_KIND, input.updatedAt ?? undefined)\n\n await withAtomicFlush(em, [\n () => {\n line.assessmentPayload = input.assessmentPayload\n line.updatedAt = new Date()\n claim.updatedAt = new Date()\n appendClaimEvent(em, claim, 'system', {\n visibility: 'internal',\n payload: {\n action: 'ai_assessment_recorded',\n lineId: line.id,\n },\n actorUserId: ctx.auth?.sub ?? null,\n })\n },\n ], { transaction: true, label: 'warranty_claims.claim_line.set_assessment' })\n\n await emitClaimUpdated(ctx, claim)\n await emitLineCrud(ctx, 'updated', line)\n return { lineId: line.id, claimId: claim.id }\n },\n captureAfter: async (rawInput, result, ctx) => {\n const input = parseCommandInput(lineSetAssessmentSchema, rawInput)\n const scope = resolveScope(ctx, input)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadLineSnapshot(em, result.lineId, scope)\n },\n buildLog: async ({ result, snapshots }) => buildLineLog('warranty_claims.audit.claim_line.set_assessment', result.lineId, snapshots),\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LineUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n let state!: LineUndoState\n await withAtomicFlush(em, [\n async () => {\n state = await requireCurrentLineUndoState(em, payload?.after, mutableParentUndoRule)\n },\n () => restoreLineFromSnapshot(state.line, before),\n () => recomputeClaimRollups(em, state.claim),\n ], { transaction: true, label: 'warranty_claims.claim_line.set_assessment.undo' })\n await emitClaimUpdated(ctx, state.claim)\n await emitLineUndoCrud(ctx, 'updated', state.line)\n },\n}\n\nregisterCommand(createClaimLineCommand)\nregisterCommand(updateClaimLineCommand)\nregisterCommand(deleteClaimLineCommand)\nregisterCommand(receiveClaimLineCommand)\nregisterCommand(releaseClaimLineQuarantineCommand)\nregisterCommand(setClaimLineAssessmentCommand)\n\nexport const claimLineCommands = [\n createClaimLineCommand,\n updateClaimLineCommand,\n deleteClaimLineCommand,\n receiveClaimLineCommand,\n releaseClaimLineQuarantineCommand,\n setClaimLineAssessmentCommand,\n]\n\nexport {\n createClaimLineCommand,\n updateClaimLineCommand,\n deleteClaimLineCommand,\n receiveClaimLineCommand,\n releaseClaimLineQuarantineCommand,\n setClaimLineAssessmentCommand,\n}\n"],
5
+ "mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAEzB,SAAS,SAAS;AAClB,SAAS,uBAAwE;AACjF,SAAS,uBAAuB;AAChC,SAAS,qBAAqB,+BAA+B;AAG7D,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,SAAS;AAClB,SAAS,eAAe,yBAAyB;AACjD;AAAA,E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