@open-mercato/core 0.11.1-develop.8531.1.9c9f5e2b21 → 0.11.1-develop.8532.1.ffc8ada7f5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/core",
3
- "version": "0.11.1-develop.8531.1.9c9f5e2b21",
3
+ "version": "0.11.1-develop.8532.1.ffc8ada7f5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -268,16 +268,16 @@
268
268
  "zod": "^4.6.6"
269
269
  },
270
270
  "peerDependencies": {
271
- "@open-mercato/ai-assistant": "0.11.1-develop.8531.1.9c9f5e2b21",
272
- "@open-mercato/shared": "0.11.1-develop.8531.1.9c9f5e2b21",
273
- "@open-mercato/ui": "0.11.1-develop.8531.1.9c9f5e2b21",
271
+ "@open-mercato/ai-assistant": "0.11.1-develop.8532.1.ffc8ada7f5",
272
+ "@open-mercato/shared": "0.11.1-develop.8532.1.ffc8ada7f5",
273
+ "@open-mercato/ui": "0.11.1-develop.8532.1.ffc8ada7f5",
274
274
  "react": "^19.0.0",
275
275
  "react-dom": "^19.0.0"
276
276
  },
277
277
  "devDependencies": {
278
- "@open-mercato/ai-assistant": "0.11.1-develop.8531.1.9c9f5e2b21",
279
- "@open-mercato/shared": "0.11.1-develop.8531.1.9c9f5e2b21",
280
- "@open-mercato/ui": "0.11.1-develop.8531.1.9c9f5e2b21",
278
+ "@open-mercato/ai-assistant": "0.11.1-develop.8532.1.ffc8ada7f5",
279
+ "@open-mercato/shared": "0.11.1-develop.8532.1.ffc8ada7f5",
280
+ "@open-mercato/ui": "0.11.1-develop.8532.1.ffc8ada7f5",
281
281
  "@testing-library/dom": "^10.4.1",
282
282
  "@testing-library/jest-dom": "^7.0.1",
283
283
  "@testing-library/react": "^16.3.3",
@@ -769,7 +769,7 @@ const createCompanyCommand: CommandHandler<CompanyCreateInput, { entityId: strin
769
769
  const restoredProfile = profile
770
770
 
771
771
  await withAtomicFlush(em, [
772
- () => syncEntityTags(em, restoredEntity, after.tagIds),
772
+ () => syncEntityTags(em, restoredEntity, after.tagIds, { ignoreMissing: true }),
773
773
  ], { transaction: true })
774
774
 
775
775
  const restoreValues = buildCustomFieldResetMap(after.custom, undefined)
@@ -796,7 +796,7 @@ const createCompanyCommand: CommandHandler<CompanyCreateInput, { entityId: strin
796
796
  },
797
797
  }
798
798
 
799
- const updateCompanyCommand: CommandHandler<CompanyUpdateInput, { entityId: string }> = {
799
+ const updateCompanyCommand = {
800
800
  id: 'customers.companies.update',
801
801
  async prepare(rawInput, ctx) {
802
802
  const { parsed } = parseWithCustomFields(companyUpdateSchema, rawInput)
@@ -804,7 +804,11 @@ const updateCompanyCommand: CommandHandler<CompanyUpdateInput, { entityId: strin
804
804
  const snapshot = await loadCompanySnapshot(em, parsed.id, ctx)
805
805
  return snapshot ? { before: snapshot } : {}
806
806
  },
807
- async execute(rawInput, ctx) {
807
+ async execute(
808
+ rawInput: CompanyUpdateInput,
809
+ ctx: CommandRuntimeContext,
810
+ ignoreMissingTags = false,
811
+ ): Promise<{ entityId: string; updatedAt: Date }> {
808
812
  const { parsed: parsedInput, custom } = parseWithCustomFields(companyUpdateSchema, rawInput)
809
813
  const parsed = withExactAmounts(parsedInput, rawInput, ['annualRevenue'] as const)
810
814
  const em = (ctx.container.resolve('em') as EntityManager).fork()
@@ -873,7 +877,7 @@ const updateCompanyCommand: CommandHandler<CompanyUpdateInput, { entityId: strin
873
877
  record.updatedAt = new Date()
874
878
  }
875
879
  },
876
- () => syncEntityTags(em, record, parsed.tags),
880
+ () => syncEntityTags(em, record, parsed.tags, { ignoreMissing: ignoreMissingTags }),
877
881
  ], { transaction: true })
878
882
 
879
883
  await setCompanyCustomFields(ctx, record.id, profile.id, record.organizationId, record.tenantId, custom)
@@ -1014,7 +1018,7 @@ const updateCompanyCommand: CommandHandler<CompanyUpdateInput, { entityId: strin
1014
1018
  }
1015
1019
 
1016
1020
  await em.flush()
1017
- await syncEntityTags(em, entity, before.tagIds)
1021
+ await syncEntityTags(em, entity, before.tagIds, { ignoreMissing: true })
1018
1022
  await em.flush()
1019
1023
 
1020
1024
  await em.nativeDelete(CustomerDealCompanyLink, { company: entity })
@@ -1088,7 +1092,10 @@ const updateCompanyCommand: CommandHandler<CompanyUpdateInput, { entityId: strin
1088
1092
  await setCompanyCustomFields(ctx, entity.id, profile.id, entity.organizationId, entity.tenantId, resetValues)
1089
1093
  }
1090
1094
  },
1091
- }
1095
+ redo({ input, ctx }): Promise<{ entityId: string }> {
1096
+ return updateCompanyCommand.execute(input, ctx, true)
1097
+ },
1098
+ } satisfies CommandHandler<CompanyUpdateInput, { entityId: string }>
1092
1099
 
1093
1100
  const deleteCompanyCommand: CommandHandler<
1094
1101
  { body?: Record<string, unknown>; query?: Record<string, unknown> },
@@ -1386,7 +1393,7 @@ const deleteCompanyCommand: CommandHandler<
1386
1393
  let restoredLabelAssignments: LabelAssignmentRestoreSnapshot[] = []
1387
1394
 
1388
1395
  await withAtomicFlush(em, [
1389
- () => syncEntityTags(em, entity, before.tagIds),
1396
+ () => syncEntityTags(em, entity, before.tagIds, { ignoreMissing: true }),
1390
1397
  async () => {
1391
1398
  const relatedDealIds = new Set<string>()
1392
1399
  for (const link of beforeDeals) relatedDealIds.add(link.dealId)
@@ -922,7 +922,7 @@ const createPersonCommand: CommandHandler<PersonCreateInput, { entityId: string;
922
922
  newProfile = graph.profile
923
923
  },
924
924
  () => syncLegacyPrimaryCompanyLink(em, newEntity, newProfile, after.profile.companyEntityId),
925
- () => syncEntityTags(em, newEntity, after.tagIds),
925
+ () => syncEntityTags(em, newEntity, after.tagIds, { ignoreMissing: true }),
926
926
  ], { transaction: true })
927
927
  entity = newEntity
928
928
  profile = newProfile
@@ -965,7 +965,7 @@ const createPersonCommand: CommandHandler<PersonCreateInput, { entityId: string;
965
965
  profile.twitterUrl = after.profile.twitterUrl
966
966
  },
967
967
  () => syncLegacyPrimaryCompanyLink(em, survivingEntity, profile, after.profile.companyEntityId),
968
- () => syncEntityTags(em, survivingEntity, after.tagIds),
968
+ () => syncEntityTags(em, survivingEntity, after.tagIds, { ignoreMissing: true }),
969
969
  ], { transaction: true })
970
970
  }
971
971
 
@@ -996,7 +996,7 @@ const createPersonCommand: CommandHandler<PersonCreateInput, { entityId: string;
996
996
  },
997
997
  }
998
998
 
999
- const updatePersonCommand: CommandHandler<PersonUpdateInput, { entityId: string }> = {
999
+ const updatePersonCommand = {
1000
1000
  id: 'customers.people.update',
1001
1001
  async prepare(rawInput, ctx) {
1002
1002
  const { parsed } = parseWithCustomFields(personUpdateSchema, rawInput)
@@ -1004,7 +1004,11 @@ const updatePersonCommand: CommandHandler<PersonUpdateInput, { entityId: string
1004
1004
  const snapshot = await loadPersonSnapshot(em, parsed.id, ctx)
1005
1005
  return snapshot ? { before: snapshot } : {}
1006
1006
  },
1007
- async execute(rawInput, ctx) {
1007
+ async execute(
1008
+ rawInput: PersonUpdateInput,
1009
+ ctx: CommandRuntimeContext,
1010
+ ignoreMissingTags = false,
1011
+ ): Promise<{ entityId: string; updatedAt: Date }> {
1008
1012
  const { parsed, custom } = parseWithCustomFields(personUpdateSchema, rawInput)
1009
1013
  const em = (ctx.container.resolve('em') as EntityManager).fork()
1010
1014
  const entity = await findScopedCustomerCommandTarget(
@@ -1135,7 +1139,7 @@ const updatePersonCommand: CommandHandler<PersonUpdateInput, { entityId: string
1135
1139
  await syncLegacyPrimaryCompanyLink(em, record, profile, parsed.companyEntityId)
1136
1140
  }
1137
1141
  },
1138
- () => syncEntityTags(em, record, parsed.tags),
1142
+ () => syncEntityTags(em, record, parsed.tags, { ignoreMissing: ignoreMissingTags }),
1139
1143
  ], { transaction: true })
1140
1144
 
1141
1145
  await invalidateDictionaryKindCaches(ctx, record, createdDictionaryKinds)
@@ -1243,7 +1247,7 @@ const updatePersonCommand: CommandHandler<PersonUpdateInput, { entityId: string
1243
1247
  em.persist(newProfile)
1244
1248
  },
1245
1249
  () => syncLegacyPrimaryCompanyLink(em, newEntity, newProfile, before.profile.companyEntityId),
1246
- () => syncEntityTags(em, newEntity, before.tagIds),
1250
+ () => syncEntityTags(em, newEntity, before.tagIds, { ignoreMissing: true }),
1247
1251
  ], { transaction: true })
1248
1252
  } else {
1249
1253
  await withAtomicFlush(em, [
@@ -1285,7 +1289,7 @@ const updatePersonCommand: CommandHandler<PersonUpdateInput, { entityId: string
1285
1289
  await syncLegacyPrimaryCompanyLink(em, entity, profile, before.profile.companyEntityId)
1286
1290
  }
1287
1291
  },
1288
- () => syncEntityTags(em, entity, before.tagIds),
1292
+ () => syncEntityTags(em, entity, before.tagIds, { ignoreMissing: true }),
1289
1293
  ], { transaction: true })
1290
1294
  }
1291
1295
 
@@ -1317,7 +1321,10 @@ const updatePersonCommand: CommandHandler<PersonUpdateInput, { entityId: string
1317
1321
  await setCustomFieldsForPerson(ctx, before.entity.id, before.profile.id, before.entity.organizationId, before.entity.tenantId, resetValues)
1318
1322
  }
1319
1323
  },
1320
- }
1324
+ redo({ input, ctx }): Promise<{ entityId: string }> {
1325
+ return updatePersonCommand.execute(input, ctx, true)
1326
+ },
1327
+ } satisfies CommandHandler<PersonUpdateInput, { entityId: string }>
1321
1328
 
1322
1329
  const deletePersonCommand: CommandHandler<
1323
1330
  { body?: Record<string, unknown>; query?: Record<string, unknown> },
@@ -1656,7 +1663,7 @@ const deletePersonCommand: CommandHandler<
1656
1663
  }
1657
1664
  }
1658
1665
  await withAtomicFlush(em, [
1659
- () => syncEntityTags(em, entity, before.tagIds),
1666
+ () => syncEntityTags(em, entity, before.tagIds, { ignoreMissing: true }),
1660
1667
  ])
1661
1668
  const restoredLabelAssignments = await restoreEntityLabelAssignments(em, entity, payload?.labelAssignments)
1662
1669
  await em.flush()
@@ -205,10 +205,12 @@ export function shouldBumpOptimisticLockVersion(
205
205
  export async function syncEntityTags(
206
206
  em: EntityManager,
207
207
  entity: CustomerEntity,
208
- tags: string[] | undefined | null
208
+ tags: string[] | undefined | null,
209
+ { ignoreMissing = false }: { ignoreMissing?: boolean } = {},
209
210
  ): Promise<void> {
210
211
  if (tags === undefined) return
211
- const desired = Array.from(new Set((tags ?? []).filter((id) => typeof id === 'string')))
212
+ const requested = (tags ?? []).filter((id) => typeof id === 'string')
213
+ const desired = Array.from(new Set(ignoreMissing ? requested.map((id) => id.toLowerCase()) : requested))
212
214
  const existing = await loadEntityTagIds(em, entity)
213
215
  const toRemove = existing.filter((id) => !desired.includes(id))
214
216
  if (toRemove.length) {
@@ -221,10 +223,11 @@ export async function syncEntityTags(
221
223
  organizationId: entity.organizationId,
222
224
  tenantId: entity.tenantId,
223
225
  })
224
- if (tagsInScope.length !== toAdd.length) {
226
+ if (!ignoreMissing && tagsInScope.length !== toAdd.length) {
225
227
  throw new CrudHttpError(400, { error: 'One or more tags not found for this scope' })
226
228
  }
227
- for (const tag of toAdd) {
229
+ const tagsToAssign = ignoreMissing ? tagsInScope.map(({ id }) => id) : toAdd
230
+ for (const tag of tagsToAssign) {
228
231
  const assignment = em.create(CustomerTagAssignment, {
229
232
  tenantId: entity.tenantId,
230
233
  organizationId: entity.organizationId,
@@ -1163,11 +1163,13 @@ async function applyDocumentUpdate({
1163
1163
  entity,
1164
1164
  input,
1165
1165
  em,
1166
+ ignoreMissingTags,
1166
1167
  }: {
1167
1168
  kind: "order" | "quote";
1168
1169
  entity: SalesOrder | SalesQuote;
1169
1170
  input: DocumentUpdateInput;
1170
1171
  em: EntityManager;
1172
+ ignoreMissingTags: boolean;
1171
1173
  }): Promise<void> {
1172
1174
  const organizationId = (entity as any).organizationId as string;
1173
1175
  const tenantId = (entity as any).tenantId as string;
@@ -1622,6 +1624,7 @@ async function applyDocumentUpdate({
1622
1624
  organizationId,
1623
1625
  tenantId,
1624
1626
  tagIds: input.tags,
1627
+ ignoreMissing: ignoreMissingTags,
1625
1628
  });
1626
1629
  }
1627
1630
 
@@ -4142,18 +4145,17 @@ async function syncSalesDocumentTags(
4142
4145
  organizationId: string;
4143
4146
  tenantId: string;
4144
4147
  tagIds?: Array<string | null | undefined> | null;
4148
+ ignoreMissing: boolean;
4145
4149
  },
4146
4150
  ) {
4147
4151
  if (params.tagIds === undefined) return;
4148
- const tagIds = normalizeTagIds(params.tagIds);
4152
+ const tagIds = normalizeTagIds(
4153
+ params.ignoreMissing ? params.tagIds?.map((id) => id?.toLowerCase()) : params.tagIds,
4154
+ );
4149
4155
  const byId = new Map<string, SalesDocumentTag>();
4150
4156
  if (tagIds.length > 0) {
4151
- const tagsInScope = await em.find(SalesDocumentTag, {
4152
- id: { $in: tagIds },
4153
- organizationId: params.organizationId,
4154
- tenantId: params.tenantId,
4155
- });
4156
- if (tagsInScope.length !== tagIds.length) {
4157
+ const tagsInScope = await findScopedDocumentTags(em, tagIds, params);
4158
+ if (!params.ignoreMissing && tagsInScope.length !== tagIds.length) {
4157
4159
  throw new CrudHttpError(400, {
4158
4160
  error: "One or more tags not found for this scope",
4159
4161
  });
@@ -4169,7 +4171,7 @@ async function syncSalesDocumentTags(
4169
4171
  const tagId = readAssignmentTagId(assignment);
4170
4172
  if (tagId) existingByTagId.set(tagId, assignment);
4171
4173
  });
4172
- const wanted = new Set(tagIds);
4174
+ const wanted = new Set(params.ignoreMissing ? byId.keys() : tagIds);
4173
4175
  const toRemove = existing.filter((assignment) => {
4174
4176
  const tagId = readAssignmentTagId(assignment);
4175
4177
  return tagId === null || !wanted.has(tagId);
@@ -4199,6 +4201,30 @@ async function syncSalesDocumentTags(
4199
4201
  }
4200
4202
  }
4201
4203
 
4204
+ function findScopedDocumentTags(
4205
+ em: EntityManager,
4206
+ tagIds: string[],
4207
+ { organizationId, tenantId }: { organizationId: string; tenantId: string },
4208
+ ) {
4209
+ return em.find(SalesDocumentTag, {
4210
+ id: { $in: tagIds },
4211
+ organizationId,
4212
+ tenantId,
4213
+ });
4214
+ }
4215
+
4216
+ async function survivingTagAssignments(
4217
+ em: EntityManager,
4218
+ assignments: TagAssignmentSnapshot[] | undefined,
4219
+ scope: { organizationId: string; tenantId: string },
4220
+ ): Promise<TagAssignmentSnapshot[]> {
4221
+ if (!Array.isArray(assignments) || !assignments.length) return [];
4222
+ const tagIds = normalizeTagIds(assignments.map(({ tagId }) => tagId));
4223
+ const tags = await findScopedDocumentTags(em, tagIds, scope);
4224
+ const availableIds = new Set(tags.map(({ id }) => id));
4225
+ return assignments.filter(({ tagId }) => availableIds.has(tagId));
4226
+ }
4227
+
4202
4228
  function applyQuoteSnapshot(
4203
4229
  quote: SalesQuote,
4204
4230
  snapshot: QuoteGraphSnapshot["quote"],
@@ -4344,8 +4370,9 @@ async function assertQuoteGraphUndoCurrent(
4344
4370
  sameIds(current.lines, expected.lines) &&
4345
4371
  sameIds(current.adjustments, expected.adjustments) &&
4346
4372
  sameRecords(current.notes, expected.notes) &&
4347
- sameRecords(current.tags, expected.tags) &&
4348
- sameRecords(current.addresses, expected.addresses);
4373
+ sameRecords(current.addresses, expected.addresses) &&
4374
+ (sameRecords(current.tags, expected.tags) ||
4375
+ sameRecords(current.tags, await survivingTagAssignments(em, expected.tags, expected.quote)));
4349
4376
  if (!unchanged) return throwDocumentUndoStale("quote");
4350
4377
  }
4351
4378
 
@@ -4502,7 +4529,7 @@ async function restoreQuoteGraph(
4502
4529
  ? snapshot.addresses
4503
4530
  : [];
4504
4531
  const noteSnapshots = Array.isArray(snapshot.notes) ? snapshot.notes : [];
4505
- const tagSnapshots = Array.isArray(snapshot.tags) ? snapshot.tags : [];
4532
+ const tagSnapshots = await survivingTagAssignments(em, snapshot.tags, quote);
4506
4533
  const verifiedIds = (entries: ReadonlyArray<{ id: string }> | undefined) =>
4507
4534
  verified ? { id: { $in: (entries ?? []).map((entry) => entry.id) } } : {};
4508
4535
  await em.nativeDelete(SalesDocumentAddress, {
@@ -4816,8 +4843,9 @@ async function assertOrderGraphUndoCurrent(
4816
4843
  sameRecords(current.shipments, expected.shipments) &&
4817
4844
  sameRecords(withoutAllocationIds(current.payments), withoutAllocationIds(expected.payments)) &&
4818
4845
  sameRecords(current.notes, expected.notes) &&
4819
- sameRecords(current.tags, expected.tags) &&
4820
- sameRecords(current.addresses, expected.addresses);
4846
+ sameRecords(current.addresses, expected.addresses) &&
4847
+ (sameRecords(current.tags, expected.tags) ||
4848
+ sameRecords(current.tags, await survivingTagAssignments(em, expected.tags, expected.order)));
4821
4849
  if (!unchanged) return throwDocumentUndoStale("order");
4822
4850
  }
4823
4851
 
@@ -5037,7 +5065,7 @@ async function restoreOrderGraph(
5037
5065
  ? snapshot.addresses
5038
5066
  : [];
5039
5067
  const noteSnapshots = Array.isArray(snapshot.notes) ? snapshot.notes : [];
5040
- const tagSnapshots = Array.isArray(snapshot.tags) ? snapshot.tags : [];
5068
+ const tagSnapshots = await survivingTagAssignments(em, snapshot.tags, order);
5041
5069
  const shipmentSnapshots = Array.isArray(snapshot.shipments)
5042
5070
  ? snapshot.shipments
5043
5071
  : [];
@@ -5263,12 +5291,13 @@ async function restoreOrderGraph(
5263
5291
  return order;
5264
5292
  }
5265
5293
 
5266
- const createQuoteCommand: CommandHandler<
5267
- QuoteCreateInput,
5268
- { quoteId: string }
5269
- > = {
5294
+ const createQuoteCommand = {
5270
5295
  id: "sales.quotes.create",
5271
- async execute(rawInput, ctx) {
5296
+ async execute(
5297
+ rawInput: QuoteCreateInput,
5298
+ ctx: CommandRuntimeContext,
5299
+ ignoreMissingTags = false,
5300
+ ): Promise<{ quoteId: string }> {
5272
5301
  const generator = ctx.container.resolve(
5273
5302
  "salesDocumentNumberGenerator",
5274
5303
  ) as SalesDocumentNumberGenerator;
@@ -5541,6 +5570,7 @@ const createQuoteCommand: CommandHandler<
5541
5570
  organizationId: quote.organizationId,
5542
5571
  tenantId: quote.tenantId,
5543
5572
  tagIds: parsed.tags,
5573
+ ignoreMissing: ignoreMissingTags,
5544
5574
  });
5545
5575
  await setDocumentCustomFieldsIfSupplied(em, {
5546
5576
  entityId: E.sales.sales_quote,
@@ -5673,7 +5703,10 @@ const createQuoteCommand: CommandHandler<
5673
5703
  await tx.flush();
5674
5704
  });
5675
5705
  },
5676
- };
5706
+ redo({ input, ctx }): Promise<{ quoteId: string }> {
5707
+ return createQuoteCommand.execute(input, ctx, true);
5708
+ },
5709
+ } satisfies CommandHandler<QuoteCreateInput, { quoteId: string }>;
5677
5710
 
5678
5711
  const deleteQuoteCommand: CommandHandler<
5679
5712
  { body?: Record<string, unknown>; query?: Record<string, unknown> },
@@ -6057,10 +6090,7 @@ async function captureLockedQuoteGraphAfter(
6057
6090
  return loadQuoteSnapshot(em, quoteId);
6058
6091
  }
6059
6092
 
6060
- const updateQuoteCommand: CommandHandler<
6061
- DocumentUpdateInput,
6062
- { quote: SalesQuote }
6063
- > = {
6093
+ const updateQuoteCommand = {
6064
6094
  id: "sales.quotes.update",
6065
6095
  async prepare(input, ctx) {
6066
6096
  const parsed = documentUpdateSchema.parse(input ?? {});
@@ -6075,7 +6105,11 @@ const updateQuoteCommand: CommandHandler<
6075
6105
  }
6076
6106
  return snapshot ? { before: snapshot } : {};
6077
6107
  },
6078
- async execute(rawInput, ctx) {
6108
+ async execute(
6109
+ rawInput: DocumentUpdateInput,
6110
+ ctx: CommandRuntimeContext,
6111
+ ignoreMissingTags = false,
6112
+ ): Promise<{ quote: SalesQuote }> {
6079
6113
  const parsed = withExactAmounts(
6080
6114
  documentUpdateSchema.parse(rawInput ?? {}),
6081
6115
  rawInput,
@@ -6108,6 +6142,7 @@ const updateQuoteCommand: CommandHandler<
6108
6142
  entity: quote,
6109
6143
  input: parsed,
6110
6144
  em,
6145
+ ignoreMissingTags,
6111
6146
  });
6112
6147
  // After applyDocumentUpdate, not before it: the reset must not happen
6113
6148
  // for an update that turns out to be invalid, or a rejected payload
@@ -6290,7 +6325,10 @@ const updateQuoteCommand: CommandHandler<
6290
6325
  if (!before) return;
6291
6326
  await undoQuoteGraph(ctx, before, payload?.after);
6292
6327
  },
6293
- };
6328
+ redo({ input, ctx }): Promise<{ quote: SalesQuote }> {
6329
+ return updateQuoteCommand.execute(input, ctx, true);
6330
+ },
6331
+ } satisfies CommandHandler<DocumentUpdateInput, { quote: SalesQuote }>;
6294
6332
 
6295
6333
  /**
6296
6334
  * Output contracts for the order commands, consumed by the workflows context
@@ -6335,10 +6373,7 @@ const orderUpdateOutputSchema = z.object({ order: orderEntityOutputSchema });
6335
6373
 
6336
6374
  const orderIdOutputSchema = z.object({ orderId: z.string().uuid() });
6337
6375
 
6338
- const updateOrderCommand: CommandHandler<
6339
- DocumentUpdateInput,
6340
- { order: SalesOrder }
6341
- > = {
6376
+ const updateOrderCommand = {
6342
6377
  id: "sales.orders.update",
6343
6378
  outputSchema: orderUpdateOutputSchema,
6344
6379
  async prepare(input, ctx) {
@@ -6354,7 +6389,11 @@ const updateOrderCommand: CommandHandler<
6354
6389
  }
6355
6390
  return snapshot ? { before: snapshot } : {};
6356
6391
  },
6357
- async execute(rawInput, ctx) {
6392
+ async execute(
6393
+ rawInput: DocumentUpdateInput,
6394
+ ctx: CommandRuntimeContext,
6395
+ ignoreMissingTags = false,
6396
+ ): Promise<{ order: SalesOrder }> {
6358
6397
  const parsed = withExactAmounts(
6359
6398
  documentUpdateSchema.parse(rawInput ?? {}),
6360
6399
  rawInput,
@@ -6418,6 +6457,7 @@ const updateOrderCommand: CommandHandler<
6418
6457
  entity: order,
6419
6458
  input: parsed,
6420
6459
  em,
6460
+ ignoreMissingTags,
6421
6461
  });
6422
6462
  },
6423
6463
  // Scalar mutations above are persisted by withAtomicFlush's per-phase
@@ -6631,15 +6671,21 @@ const updateOrderCommand: CommandHandler<
6631
6671
  if (!before) return;
6632
6672
  await undoOrderGraph(ctx, before, payload?.after);
6633
6673
  },
6634
- };
6674
+ redo({ input, ctx }): Promise<{ order: SalesOrder }> {
6675
+ return updateOrderCommand.execute(input, ctx, true);
6676
+ },
6677
+ } satisfies CommandHandler<DocumentUpdateInput, { order: SalesOrder }>;
6635
6678
 
6636
- const createOrderCommand: CommandHandler<
6637
- OrderCreateInput,
6638
- { orderId: string; warnings?: OrderPaymentLedgerWarning[] }
6639
- > = {
6679
+ type CreateOrderResult = { orderId: string; warnings?: OrderPaymentLedgerWarning[] };
6680
+
6681
+ const createOrderCommand = {
6640
6682
  id: "sales.orders.create",
6641
6683
  outputSchema: orderIdOutputSchema,
6642
- async execute(rawInput, ctx) {
6684
+ async execute(
6685
+ rawInput: OrderCreateInput,
6686
+ ctx: CommandRuntimeContext,
6687
+ ignoreMissingTags = false,
6688
+ ): Promise<CreateOrderResult> {
6643
6689
  const generator = ctx.container.resolve(
6644
6690
  "salesDocumentNumberGenerator",
6645
6691
  ) as SalesDocumentNumberGenerator;
@@ -6975,6 +7021,7 @@ const createOrderCommand: CommandHandler<
6975
7021
  organizationId: order.organizationId,
6976
7022
  tenantId: order.tenantId,
6977
7023
  tagIds: parsed.tags,
7024
+ ignoreMissing: ignoreMissingTags,
6978
7025
  });
6979
7026
  await setDocumentCustomFieldsIfSupplied(em, {
6980
7027
  entityId: E.sales.sales_order,
@@ -7132,7 +7179,10 @@ const createOrderCommand: CommandHandler<
7132
7179
  },
7133
7180
  );
7134
7181
  },
7135
- };
7182
+ redo({ input, ctx }): Promise<CreateOrderResult> {
7183
+ return createOrderCommand.execute(input, ctx, true);
7184
+ },
7185
+ } satisfies CommandHandler<OrderCreateInput, CreateOrderResult>;
7136
7186
 
7137
7187
  const deleteOrderCommand: CommandHandler<
7138
7188
  { body?: Record<string, unknown>; query?: Record<string, unknown> },