@canton-network/core-ledger-client 0.34.0 → 0.35.0

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/dist/index.js CHANGED
@@ -28,7 +28,10 @@ async function awaitCompletion(ledgerClient, ledgerEnd, partyId, userId, command
28
28
  );
29
29
  const wantedCompletion = responses.find((r) => {
30
30
  if (r.completionResponse && "Completion" in r.completionResponse) {
31
- const completion = r.completionResponse.Completion.value;
31
+ const completion = r.completionResponse.Completion?.value;
32
+ if (!completion) {
33
+ return false;
34
+ }
32
35
  return completion.userId === userId && (completion.commandId === commandIdOrSubmissionId || completion.submissionId === commandIdOrSubmissionId);
33
36
  }
34
37
  return false;
@@ -233,7 +236,10 @@ var ACSContainer = class _ACSContainer {
233
236
  });
234
237
  const createdContracts = acs.initialAcs.concat(addedContracts);
235
238
  const result = createdContracts.filter(({ contractEntry }) => {
236
- const id = "JsActiveContract" in contractEntry ? contractEntry.JsActiveContract.createdEvent.contractId : "";
239
+ if (!contractEntry) {
240
+ return false;
241
+ }
242
+ const id = "JsActiveContract" in contractEntry ? contractEntry.JsActiveContract?.createdEvent?.contractId ?? "" : "";
237
243
  return !removedContractIds.has(id);
238
244
  });
239
245
  return Promise.resolve(result);
@@ -242,19 +248,25 @@ var ACSContainer = class _ACSContainer {
242
248
  const newEvents = [];
243
249
  let newOffset = fromOffset;
244
250
  updates.forEach((update) => {
251
+ if (!update || !update.update) {
252
+ return;
253
+ }
245
254
  if ("Transaction" in update.update) {
246
255
  const transaction = update.update.Transaction;
247
- const trOffset = transaction.value.offset;
248
- if (trOffset > newOffset) {
249
- const events = transaction.value.events ?? [];
256
+ const trOffset = transaction?.value?.offset;
257
+ if (trOffset && trOffset > newOffset) {
258
+ const events = transaction?.value?.events ?? [];
250
259
  events.forEach((event) => {
260
+ if (!event) {
261
+ return;
262
+ }
251
263
  if ("CreatedEvent" in event) {
252
264
  const acUpdate = {
253
265
  created: event.CreatedEvent,
254
266
  archivedContractId: null,
255
267
  offset: trOffset,
256
- workflowId: transaction.value.workflowId,
257
- synchronizerId: transaction.value.synchronizerId
268
+ workflowId: transaction?.value?.workflowId ?? null,
269
+ synchronizerId: transaction?.value?.synchronizerId ?? null
258
270
  };
259
271
  newEvents.push(acUpdate);
260
272
  newOffset = trOffset;
@@ -262,10 +274,10 @@ var ACSContainer = class _ACSContainer {
262
274
  const archivedEvent = event.ArchivedEvent;
263
275
  const acUpdate = {
264
276
  created: null,
265
- archivedContractId: archivedEvent.contractId,
277
+ archivedContractId: archivedEvent?.contractId ?? null,
266
278
  offset: trOffset,
267
- workflowId: transaction.value.workflowId,
268
- synchronizerId: transaction.value.synchronizerId
279
+ workflowId: transaction?.value?.workflowId ?? null,
280
+ synchronizerId: transaction?.value?.synchronizerId ?? null
269
281
  };
270
282
  newEvents.push(acUpdate);
271
283
  newOffset = trOffset;
@@ -274,7 +286,10 @@ var ACSContainer = class _ACSContainer {
274
286
  }
275
287
  } else if ("OffsetCheckpoint" in update.update) {
276
288
  const checkpoint = update.update.OffsetCheckpoint;
277
- newOffset = checkpoint.value.offset;
289
+ const offset = checkpoint?.value?.offset;
290
+ if (offset) {
291
+ newOffset = offset;
292
+ }
278
293
  } else {
279
294
  console.log(
280
295
  `ACS Update got unknown update type: ${JSON.stringify(update.update)}`
@@ -337,11 +352,15 @@ var ACSContainer = class _ACSContainer {
337
352
  }
338
353
  async readHttpACS(offset, key, api) {
339
354
  const format = this.createEventFormat(key);
340
- const acs = await api.postWithRetry("/v2/state/active-contracts", {
341
- activeAtOffset: offset,
342
- verbose: false,
343
- eventFormat: format
344
- });
355
+ const acs = await api.postWithRetry(
356
+ "/v2/state/active-contracts",
357
+ {
358
+ activeAtOffset: offset,
359
+ verbose: false,
360
+ eventFormat: format
361
+ },
362
+ defaultRetryableOptions
363
+ );
345
364
  return {
346
365
  acsOffset: offset,
347
366
  initialAcs: acs,
@@ -439,21 +458,25 @@ var ACSContainer = class _ACSContainer {
439
458
  }
440
459
  createEventFormat(key) {
441
460
  const cumulativeFilter = key.templateId ? this.createTemplateFilter(key.templateId) : this.createInterfaceFilter(key.interfaceId ?? "");
442
- const baseFormat = {
443
- filtersByParty: {},
444
- verbose: false
445
- };
446
461
  if (key.party) {
447
462
  if (!key.interfaceId && !key.templateId) {
448
- baseFormat.filtersByParty[key.party] = {};
449
- return baseFormat;
463
+ return {
464
+ filtersByParty: {
465
+ [key.party]: {}
466
+ },
467
+ verbose: false
468
+ };
450
469
  }
451
- baseFormat.filtersByParty[key.party] = cumulativeFilter;
452
- return baseFormat;
470
+ return {
471
+ filtersByParty: {
472
+ [key.party]: cumulativeFilter
473
+ },
474
+ verbose: false
475
+ };
453
476
  }
454
477
  return {
455
- ...baseFormat,
456
- filtersForAnyParty: cumulativeFilter
478
+ filtersForAnyParty: cumulativeFilter,
479
+ verbose: false
457
480
  };
458
481
  }
459
482
  };
@@ -602,8 +625,7 @@ var LedgerClient = class {
602
625
  logger,
603
626
  accessTokenProvider,
604
627
  version,
605
- acsHelperOptions,
606
- ...options
628
+ acsHelperOptions
607
629
  }) {
608
630
  // privately manage the active connected version and associated client codegen
609
631
  __publicField(this, "clients");
@@ -617,13 +639,12 @@ var LedgerClient = class {
617
639
  __publicField(this, "baseUrl");
618
640
  this.logger = logger.child({ component: "LedgerClient" });
619
641
  this.accessTokenProvider = accessTokenProvider;
620
- const baseFetch = options.fetch ?? fetch;
621
- const authenticatedFetch = async (url, options2 = {}) => {
642
+ const authenticatedFetch = async (url, options = {}) => {
622
643
  const token = await this.accessTokenProvider.getAccessToken();
623
- return baseFetch(url, {
624
- ...options2,
644
+ return fetch(url, {
645
+ ...options,
625
646
  headers: {
626
- ...options2.headers || {},
647
+ ...options.headers || {},
627
648
  ...token && { Authorization: `Bearer ${token}` }
628
649
  }
629
650
  });
@@ -984,12 +1005,14 @@ var LedgerClient = class {
984
1005
  }
985
1006
  throw new Error("Expected Transaction update");
986
1007
  }).map((data) => {
987
- const exercisedEvents = data.events?.filter((event) => "ExercisedEvent" in event).map(
1008
+ const exercisedEvents = data.events?.filter(
1009
+ (event) => !!event && "ExercisedEvent" in event
1010
+ ).map(
988
1011
  (event) => event.ExercisedEvent
989
- ).filter((event) => event.consuming);
990
- const createdEvents = data.events?.filter((event) => "CreatedEvent" in event).map(
1012
+ ).filter((event) => !!event).filter((event) => !!event.consuming);
1013
+ const createdEvents = data.events?.filter((event) => !!event && "CreatedEvent" in event).map(
991
1014
  (event) => event.CreatedEvent
992
- ).filter(
1015
+ ).filter((event) => !!event).filter(
993
1016
  (event) => Object.keys(
994
1017
  activeContractsArgs.filter?.filtersByParty ?? {}
995
1018
  ).includes(
@@ -997,9 +1020,11 @@ var LedgerClient = class {
997
1020
  )
998
1021
  );
999
1022
  exercisedEvents?.forEach((event) => {
1000
- exercisedContracts.add(event.contractId);
1023
+ if (event.contractId)
1024
+ exercisedContracts.add(event.contractId);
1001
1025
  });
1002
1026
  createdEvents?.forEach((event) => {
1027
+ if (!event.contractId) return;
1003
1028
  allContractsData.set(event.contractId, {
1004
1029
  workflowId: data.workflowId,
1005
1030
  contractEntry: {
@@ -1023,10 +1048,10 @@ var LedgerClient = class {
1023
1048
  }
1024
1049
  buildActiveContractFilter(options) {
1025
1050
  const filter = {
1026
- filter: {
1027
- filtersByParty: {}
1051
+ eventFormat: {
1052
+ filtersByParty: {},
1053
+ verbose: false
1028
1054
  },
1029
- verbose: false,
1030
1055
  activeAtOffset: options?.offset
1031
1056
  };
1032
1057
  const buildTemplateFilter = (templateIds) => {