@ai-matrx/auth 0.3.0 → 0.3.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog — @ai-matrx/auth
2
2
 
3
+ ## 0.3.2
4
+ - `clearStaleHeld`: the held choice is read at the START of the read (before the memberships), so a choice made while the read is in
5
+ flight is never cleared by it. Test: `active-organization.test.ts` (racing choice).
6
+
7
+ ## 0.3.1
8
+ - `clearStaleHeld` fix: a held choice already stale when the read began is cleared even when no organization can be answered,
9
+ and a choice made while the read was in flight is never cleared. Test: `active-organization.test.ts`.
10
+
3
11
  ## 0.3.0
4
12
  ### auth consolidation tail (round 3)
5
13
 
@@ -565,6 +565,7 @@ function createActiveOrganization(options) {
565
565
  publish({ ...IDLE, status: "none", error: "signed-out" });
566
566
  return current;
567
567
  }
568
+ const heldAtStart = options.clearStaleHeld ? await held.read(person.id) : null;
568
569
  const rawMemberships = await readMemberships(client, person.id);
569
570
  if (gen !== generation) return current;
570
571
  let favourites = current.favourites;
@@ -609,15 +610,14 @@ function createActiveOrganization(options) {
609
610
  });
610
611
  }
611
612
  if (gen !== generation) return current;
613
+ if (heldAtStart && !memberships.some((m) => m.id === heldAtStart) && await held.read(person.id) === heldAtStart) {
614
+ await held.clear();
615
+ }
612
616
  if (!resolved) {
613
617
  publish({ ...IDLE, status: "none", userId: person.id, error: "no-memberships" });
614
618
  return current;
615
619
  }
616
620
  if (options.holdResolved ?? true) await held.write(person.id, resolved.organization.id);
617
- if (options.clearStaleHeld) {
618
- const stale = await held.read(person.id);
619
- if (stale && !memberships.some((m) => m.id === stale)) await held.clear();
620
- }
621
621
  const wasOrg = before.status === "ready" || before.status === "unchecked" ? before.organization : null;
622
622
  const lapsed = wasOrg && wasOrg.id !== resolved.organization.id && !memberships.some((m) => m.id === wasOrg.id) ? wasOrg : null;
623
623
  if (linkDecision && linkDecision.kind !== "no-link") options.link?.onDecision?.(linkDecision);
@@ -485,6 +485,7 @@ function createActiveOrganization(options) {
485
485
  publish({ ...IDLE, status: "none", error: "signed-out" });
486
486
  return current;
487
487
  }
488
+ const heldAtStart = options.clearStaleHeld ? await held.read(person.id) : null;
488
489
  const rawMemberships = await readMemberships(client, person.id);
489
490
  if (gen !== generation) return current;
490
491
  let favourites = current.favourites;
@@ -529,15 +530,14 @@ function createActiveOrganization(options) {
529
530
  });
530
531
  }
531
532
  if (gen !== generation) return current;
533
+ if (heldAtStart && !memberships.some((m) => m.id === heldAtStart) && await held.read(person.id) === heldAtStart) {
534
+ await held.clear();
535
+ }
532
536
  if (!resolved) {
533
537
  publish({ ...IDLE, status: "none", userId: person.id, error: "no-memberships" });
534
538
  return current;
535
539
  }
536
540
  if (options.holdResolved ?? true) await held.write(person.id, resolved.organization.id);
537
- if (options.clearStaleHeld) {
538
- const stale = await held.read(person.id);
539
- if (stale && !memberships.some((m) => m.id === stale)) await held.clear();
540
- }
541
541
  const wasOrg = before.status === "ready" || before.status === "unchecked" ? before.organization : null;
542
542
  const lapsed = wasOrg && wasOrg.id !== resolved.organization.id && !memberships.some((m) => m.id === wasOrg.id) ? wasOrg : null;
543
543
  if (linkDecision && linkDecision.kind !== "no-link") options.link?.onDecision?.(linkDecision);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-matrx/auth",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "AI Matrx sign-in, session and organizations for every app: sign in/out, session storage and refresh per platform (browser, Next.js, extension, desktop, Node), the current person, their organizations and favourites, the one active organization (held requests, never a list filter), and the credentials @ai-matrx/data and @ai-matrx/api read.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -211,5 +211,5 @@
211
211
  "test": "vitest run",
212
212
  "verify:tarball": "node ./scripts/verify-tarball.mjs"
213
213
  },
214
- "gitHead": "032b64c11a538c439562215e8dc33fba11bc0050"
214
+ "gitHead": "914209baa874d2bf03ffda7b2069c87b2c0b66e1"
215
215
  }