@faable/auth-sdk 2.7.21 → 2.7.22

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/README.md CHANGED
@@ -170,7 +170,7 @@ await api.fetcher.get(`/user/${id}`, { timeout: 800, retry: false });
170
170
  | `authStrategy` | strategy builder | Auth strategy (`authClientCredentials` \| `authApikey` \| `authBearer` \| `authCookie`), re-exported from `@faable/auth-sdk`. Defaults to `authClientCredentials` when `auth` is given; anonymous when neither is. |
171
171
  | `auth` | config | Config for the chosen strategy. Its shape is inferred from `authStrategy` (e.g. `{ client_id, client_secret }`). |
172
172
  | `debug` | boolean | Enables verbose logging in the underlying fetcher. |
173
- | `headers` | `{ team_id?; account_id? }` | Advanced / testing escape hatch — target `domain` but have the server resolve a different team/account (sent as `x-faable-team` / `x-faableauth-account`). |
173
+ | `headers` | `{ project_id?; account_id? }` | Advanced / testing escape hatch — target `domain` but have the server resolve a different project/account (sent as `x-faable-project` / `x-faableauth-account`). `team_id` is a deprecated alias of `project_id`: a `team_<hex>` value is sent as `project_<hex>`, and passing both with different ids throws. The SDK no longer sends `x-faable-team`. |
174
174
  | `clientInfo` | `{ client?; name?; instance? }` | How this integration identifies itself (`x-faable-client` / `x-faable-instance`). `client` replaces the SDK's own `auth-sdk/<version>+<sha>`. |
175
175
 
176
176
  ---
@@ -9,10 +9,22 @@ type FaableAuthApiParams = {
9
9
  * dashboard and some tests need this (e.g. point at a concrete host but
10
10
  * resolve another account) — it is intentionally kept out of the normal
11
11
  * config surface. Maps to:
12
- * - `team_id` → `x-faable-team`
12
+ * - `project_id` → `x-faable-project` (`project_<hex>`)
13
+ * - `team_id` → `x-faable-project` too (deprecated alias, see below)
13
14
  * - `account_id` → `x-faableauth-account`
15
+ *
16
+ * A project and a team are the same object under two prefixes (same hex
17
+ * suffix). The SDK never sends the deprecated `x-faable-team` header.
14
18
  */
15
19
  headers?: {
20
+ /** Project to resolve, `project_<hex>`. Sent as `x-faable-project`. */
21
+ project_id?: string;
22
+ /**
23
+ * @deprecated use `project_id`. A `team_<hex>` value is rewritten to
24
+ * `project_<hex>` and sent as `x-faable-project`; `x-faable-team` is no
25
+ * longer sent. Giving both `project_id` and `team_id` is allowed only when
26
+ * they name the same project.
27
+ */
16
28
  team_id?: string;
17
29
  account_id?: string;
18
30
  };
@@ -42,6 +42,25 @@ const discoverManagementAudience = (baseURL) => {
42
42
  };
43
43
  // Testing seam: the memo outlives any single api instance.
44
44
  export const __resetAudienceCacheForTests = () => audience_by_host.clear();
45
+ // `team_<hex>` and `project_<hex>` are the same object; the canonical form on
46
+ // the wire is `project_`. Idempotent: a `project_` (or unprefixed) value is
47
+ // returned as is.
48
+ const toProjectId = (id) => id.startsWith("team_") ? `project_${id.slice("team_".length)}` : id;
49
+ // Resolve `headers.project_id` / the deprecated `headers.team_id` alias to the
50
+ // single `x-faable-project` value. Conflicting ids throw here, at construction,
51
+ // rather than as a 400 from the server on the first call.
52
+ const resolveProjectHeader = (headers) => {
53
+ const from_project = headers?.project_id
54
+ ? toProjectId(headers.project_id)
55
+ : undefined;
56
+ const from_team = headers?.team_id ? toProjectId(headers.team_id) : undefined;
57
+ if (from_project && from_team && from_project !== from_team) {
58
+ throw new FaableApiError(`FaableAuthApi: \`headers.project_id\` (${headers?.project_id}) and the ` +
59
+ `deprecated \`headers.team_id\` (${headers?.team_id}) name different ` +
60
+ "projects. Pass only `project_id`.");
61
+ }
62
+ return from_project ?? from_team;
63
+ };
45
64
  export class FaableAuthApi extends GeneratedFaableAuthApi {
46
65
  constructor(params) {
47
66
  if (!params?.domain) {
@@ -50,6 +69,7 @@ export class FaableAuthApi extends GeneratedFaableAuthApi {
50
69
  "The hardcoded default was removed so SDK calls never target another tenant by accident.");
51
70
  }
52
71
  const baseURL = getDomain(params.domain);
72
+ const project_id = resolveProjectHeader(params.headers);
53
73
  // When authenticating via client_credentials without an explicit audience,
54
74
  // default it to this tenant's management audience (discovered from the
55
75
  // domain). Only when the resolved strategy is client_credentials — an
@@ -89,9 +109,7 @@ export class FaableAuthApi extends GeneratedFaableAuthApi {
89
109
  ...params?.fetcher,
90
110
  headers: {
91
111
  ...params?.fetcher?.headers,
92
- ...(params?.headers?.team_id && {
93
- "x-faable-team": params.headers.team_id,
94
- }),
112
+ ...(project_id && { "x-faable-project": project_id }),
95
113
  ...(params?.headers?.account_id && {
96
114
  "x-faableauth-account": params.headers.account_id,
97
115
  }),
package/dist/version.js CHANGED
@@ -9,13 +9,13 @@
9
9
  // login pages could not import the SDK at all. Same pattern as auth-js.
10
10
  //
11
11
  // The sentinels MUST stay byte-identical to the `from` values in `.releaserc`.
12
- export const version = "2.7.21";
12
+ export const version = "2.7.22";
13
13
  // Short git SHA of the released commit. The version dates a build; this names
14
14
  // the exact tree, so a canonical log line or an audit entry leads straight to
15
15
  // `git show <sha>`. Deliberately NOT hex: an unreleased build (dev, a local
16
16
  // link) cannot be mistaken for a real commit — auth only records values that
17
17
  // look like a SHA, and this one never will.
18
- export const commit = "eda9c4d";
18
+ export const commit = "49d06d3";
19
19
  // What this SDK writes in `x-faable-client`. Exported for a consumer that
20
20
  // builds a strategy on its own (outside `FaableAuthApi`) and still wants the
21
21
  // token request attributed — a bare `authClientCredentials` stamps only what
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/auth-sdk",
3
- "version": "2.7.21",
3
+ "version": "2.7.22",
4
4
  "author": "Marc Pomar <marc@faable.com>",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",