@7365admin1/core 3.72.1-staging.327 → 3.72.1-staging.328

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.d.ts CHANGED
@@ -13237,6 +13237,8 @@ declare function useHidAmicoRepo(): {
13237
13237
  findIdentitiesByHidUserIds: (reader: string | ObjectId, hidUserIds: Array<string | number>) => Promise<mongodb.WithId<bson.Document>[]>;
13238
13238
  acquireEnrollmentLock: (reader: string | ObjectId, owner: string, ttlSeconds: number) => Promise<boolean>;
13239
13239
  releaseEnrollmentLock: (reader: string | ObjectId, owner?: string) => Promise<boolean>;
13240
+ setEnrollmentSession: (reader: string | ObjectId, owner: string, session: string) => Promise<boolean>;
13241
+ getEnrollmentSession: (reader: string | ObjectId) => Promise<string>;
13240
13242
  assertOrganizationSiteAccess: (site: string | ObjectId, org: string | ObjectId) => Promise<{
13241
13243
  siteId: ObjectId;
13242
13244
  orgId: ObjectId;
package/dist/index.js CHANGED
@@ -45129,6 +45129,20 @@ function useHidAmicoRepo() {
45129
45129
  throw error;
45130
45130
  }
45131
45131
  }
45132
+ async function setEnrollmentSession(reader, owner, session) {
45133
+ const result = await enrollmentLocks().updateOne(
45134
+ { _id: toId3(reader, "reader ID"), owner },
45135
+ { $set: { session, sessionAt: /* @__PURE__ */ new Date() } }
45136
+ );
45137
+ return result.matchedCount > 0;
45138
+ }
45139
+ async function getEnrollmentSession(reader) {
45140
+ const lock = await enrollmentLocks().findOne({
45141
+ _id: toId3(reader, "reader ID"),
45142
+ expiresAt: { $gt: /* @__PURE__ */ new Date() }
45143
+ });
45144
+ return String(lock?.session ?? "");
45145
+ }
45132
45146
  async function releaseEnrollmentLock(reader, owner) {
45133
45147
  const result = await enrollmentLocks().deleteOne({
45134
45148
  _id: toId3(reader, "reader ID"),
@@ -45687,6 +45701,8 @@ function useHidAmicoRepo() {
45687
45701
  findIdentitiesByHidUserIds,
45688
45702
  acquireEnrollmentLock,
45689
45703
  releaseEnrollmentLock,
45704
+ setEnrollmentSession,
45705
+ getEnrollmentSession,
45690
45706
  assertOrganizationSiteAccess,
45691
45707
  getSitePermissions,
45692
45708
  listSitePermissionDocuments,
@@ -46935,6 +46951,8 @@ var HidAmicoClient = class {
46935
46951
  constructor(reader) {
46936
46952
  this.reader = reader;
46937
46953
  this.session = "";
46954
+ /** True while `session` belongs to another request. See `adoptSession`. */
46955
+ this.borrowedSession = false;
46938
46956
  const relayAuth = getRelayAuth();
46939
46957
  this.http = import_axios.default.create({
46940
46958
  baseURL: normalizeHidReaderBaseUrl(reader.baseUrl),
@@ -46994,6 +47012,7 @@ var HidAmicoClient = class {
46994
47012
  throw new import_node_server_utils141.BadRequestError("HID Amico login failed: missing session.");
46995
47013
  }
46996
47014
  this.session = res.data.session;
47015
+ this.borrowedSession = false;
46997
47016
  return this.session;
46998
47017
  }
46999
47018
  async sessionIsValid() {
@@ -47146,10 +47165,34 @@ var HidAmicoClient = class {
47146
47165
  verified: true
47147
47166
  };
47148
47167
  }
47168
+ /**
47169
+ * Take over a session somebody else opened, without logging in.
47170
+ *
47171
+ * For the cancel path only. While an enrolment is listening the reader will
47172
+ * not serve a second `hidlogin.fcgi` inside the client's 15 second timeout, so
47173
+ * the cancel has to ride the enrolment's session or it never reaches the
47174
+ * device at all.
47175
+ *
47176
+ * A borrowed session is NOT this client's to close - see `logout`.
47177
+ */
47178
+ adoptSession(session) {
47179
+ this.session = String(session ?? "");
47180
+ this.borrowedSession = Boolean(this.session);
47181
+ return this.session;
47182
+ }
47183
+ /** Whether this client may end the session it is holding. */
47184
+ get ownsSession() {
47185
+ return Boolean(this.session) && !this.borrowedSession;
47186
+ }
47149
47187
  async logout() {
47150
47188
  if (!this.session) {
47151
47189
  return;
47152
47190
  }
47191
+ if (this.borrowedSession) {
47192
+ this.session = "";
47193
+ this.borrowedSession = false;
47194
+ return;
47195
+ }
47153
47196
  const logoutUrl = this.url("/logout.fcgi");
47154
47197
  try {
47155
47198
  this.session = "";
@@ -49866,7 +49909,8 @@ function useHidAmicoService() {
49866
49909
  throw new import_node_server_utils141.BadRequestError("Another physical HID card enrollment is already running on this reader.");
49867
49910
  }
49868
49911
  try {
49869
- await client.login();
49912
+ const session = await client.login();
49913
+ await repo.setEnrollmentSession(readerId, lockOwner, session);
49870
49914
  await assertHidUserExists(client, hidUserId);
49871
49915
  await ensurePhysicalCardIdentification(client);
49872
49916
  const beforeRows = await loadPhysicalCardRows(client, hidUserId);
@@ -49947,15 +49991,20 @@ function useHidAmicoService() {
49947
49991
  async function cancelUserCardEnrollment(readerId) {
49948
49992
  const reader = await getActiveReader(readerId);
49949
49993
  const client = new HidAmicoClient(reader);
49994
+ const runningSession = await repo.getEnrollmentSession(readerId);
49950
49995
  try {
49951
- await client.login();
49996
+ if (runningSession) {
49997
+ client.adoptSession(runningSession);
49998
+ } else {
49999
+ await client.login();
50000
+ }
49952
50001
  await client.cancelRemoteEnrollment();
49953
50002
  const enrollmentWasRunning = await repo.releaseEnrollmentLock(readerId);
49954
50003
  await repo.addEvent({
49955
50004
  reader: readerId,
49956
50005
  site: reader.site,
49957
50006
  type: "user_card_enrollment_cancelled",
49958
- payload: { enrollmentWasRunning }
50007
+ payload: { enrollmentWasRunning, borrowedSession: Boolean(runningSession) }
49959
50008
  });
49960
50009
  return { readerId, cancelled: true };
49961
50010
  } finally {