@faable/auth-sdk 2.5.37 → 2.5.38

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.
@@ -1,5 +1,6 @@
1
1
  import { GeneratedFaableAuthApi } from "./api/generated-client.js";
2
2
  import { type ApiParams } from "@faable/sdk-base";
3
+ export declare const __resetAudienceCacheForTests: () => void;
3
4
  type FaableAuthApiParams = {
4
5
  domain: string;
5
6
  /**
@@ -10,9 +10,17 @@ import { version } from "./version.js";
10
10
  // resolves the account by host and exposes its id as `account`) lazily on the
11
11
  // first token request, and memoize it. Omitting `scope` then yields the full
12
12
  // management catalog server-side (Auth0 parity), so no scope wiring is needed.
13
+ //
14
+ // The memo is module-level, keyed by host. It used to be a closure created per
15
+ // constructor, so it only ever helped an instance that outlived several token
16
+ // refreshes — and a multi-tenant consumer does the opposite: it builds one
17
+ // instance per tenant (a tenant is scoped through the constructor `headers`),
18
+ // so every one of them re-ran discovery. The account id a host resolves to does
19
+ // not change, so caching it per host is the honest scope.
20
+ const audience_by_host = new Map();
13
21
  const discoverManagementAudience = (baseURL) => {
14
- let cached;
15
22
  return async () => {
23
+ const cached = audience_by_host.get(baseURL);
16
24
  if (cached)
17
25
  return cached;
18
26
  const url = `${baseURL}/.well-known/openid-configuration`;
@@ -27,10 +35,13 @@ const discoverManagementAudience = (baseURL) => {
27
35
  "auth server may be older than the management-audience support. " +
28
36
  "Pass `auth.audience` explicitly (faable:management:<account_id>).");
29
37
  }
30
- cached = `faable:management:${doc.account}`;
31
- return cached;
38
+ const audience = `faable:management:${doc.account}`;
39
+ audience_by_host.set(baseURL, audience);
40
+ return audience;
32
41
  };
33
42
  };
43
+ // Testing seam: the memo outlives any single api instance.
44
+ export const __resetAudienceCacheForTests = () => audience_by_host.clear();
34
45
  export class FaableAuthApi extends GeneratedFaableAuthApi {
35
46
  constructor(params) {
36
47
  if (!params?.domain) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/auth-sdk",
3
- "version": "2.5.37",
3
+ "version": "2.5.38",
4
4
  "author": "Marc Pomar <marc@faable.com>",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",