@ai-matrx/auth 0.3.0 → 0.3.1

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,9 @@
1
1
  # Changelog — @ai-matrx/auth
2
2
 
3
+ ## 0.3.1
4
+ - `clearStaleHeld` fix: a held choice already stale when the read began is cleared even when no organization can be answered,
5
+ and a choice made while the read was in flight is never cleared. Test: `active-organization.test.ts`.
6
+
3
7
  ## 0.3.0
4
8
  ### auth consolidation tail (round 3)
5
9
 
@@ -583,6 +583,7 @@ function createActiveOrganization(options) {
583
583
  const memberships = options.accountChoices ? orderOrganizations(rawMemberships, favourites) : rawMemberships;
584
584
  const readAccount = () => account ? Promise.resolve(account) : readAccountOrganizationChoices(client, person.id);
585
585
  const before = prior;
586
+ const heldAtStart = options.clearStaleHeld ? await held.read(person.id) : null;
586
587
  const linkOptions = options.link;
587
588
  let resolved;
588
589
  let linkDecision = null;
@@ -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);
@@ -503,6 +503,7 @@ function createActiveOrganization(options) {
503
503
  const memberships = options.accountChoices ? orderOrganizations(rawMemberships, favourites) : rawMemberships;
504
504
  const readAccount = () => account ? Promise.resolve(account) : readAccountOrganizationChoices(client, person.id);
505
505
  const before = prior;
506
+ const heldAtStart = options.clearStaleHeld ? await held.read(person.id) : null;
506
507
  const linkOptions = options.link;
507
508
  let resolved;
508
509
  let linkDecision = null;
@@ -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.1",
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": "63d7fd1430cbe05b6ed9f0e638ae4c630232497a"
215
215
  }