@faable/auth-sdk 1.3.35 → 2.0.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/README.md CHANGED
@@ -25,53 +25,66 @@ npm install @faable/auth-sdk
25
25
 
26
26
  ## Authentication
27
27
 
28
- The SDK accepts any auth strategy from [`@faable/sdk-base`](https://www.npmjs.com/package/@faable/sdk-base). Two strategies are typically used:
28
+ Auth is **explicit and pluggable**: you pick an `authStrategy` and pass its
29
+ config in `auth`. The SDK **never reads credentials from the environment** —
30
+ read them yourself and pass them in. The strategy you choose drives the type of
31
+ `auth`, so the editor autocompletes the right fields. The strategies are
32
+ re-exported from `@faable/auth-sdk`, so you only ever import from this package.
33
+
34
+ > **Breaking change (v2):** the old `createClientCredentials()` /
35
+ > `createApikeyAuth()` helpers (which read `FAABLE_*` env vars automatically)
36
+ > were removed. Use the `authStrategy` + `auth` pair below. `domain` is now
37
+ > **required** — there is no hardcoded default host anymore.
29
38
 
30
39
  ### Client credentials (recommended)
31
40
 
32
- Reads `FAABLE_CLIENT_ID`, `FAABLE_CLIENT_SECRET` and `FAABLE_DOMAIN` from the environment by default:
41
+ `authClientCredentials` is the **default** strategy, so you only pass `auth`
42
+ with `{ client_id, client_secret }` — no need to set `authStrategy`:
33
43
 
34
44
  ```ts
35
45
  import { FaableAuthApi } from "@faable/auth-sdk";
36
- import { createClientCredentials } from "@faable/sdk-base";
37
46
 
38
47
  const api = FaableAuthApi.create({
39
- auth: createClientCredentials(),
40
- team_id: "team_xxxxxxxxxxxxxxxxxxxxxxxx",
48
+ domain: "https://<your-account>.auth.faable.link",
49
+ auth: {
50
+ client_id: process.env.FAABLEAUTH_CLIENT_ID!,
51
+ client_secret: process.env.FAABLEAUTH_CLIENT_SECRET!,
52
+ },
41
53
  });
42
54
  ```
43
55
 
44
- You may also pass credentials explicitly:
56
+ By default the token is requested from `<domain>/oauth/token`. If your API host
57
+ is **not** the auth server, override it with `auth.domain`:
45
58
 
46
59
  ```ts
47
- const auth = createClientCredentials({
48
- client_id: process.env.FAABLE_CLIENT_ID!,
49
- client_secret: process.env.FAABLE_CLIENT_SECRET!,
50
- domain: "faable.auth.faable.link",
51
- });
60
+ auth: {
61
+ client_id: "...",
62
+ client_secret: "...",
63
+ domain: "https://<your-account>.auth.faable.link", // where /oauth/token lives
64
+ }
52
65
  ```
53
66
 
54
67
  ### API key
55
68
 
56
69
  ```ts
57
- import { FaableAuthApi } from "@faable/auth-sdk";
58
- import { createApikeyAuth } from "@faable/sdk-base";
70
+ import { FaableAuthApi, authApikey } from "@faable/auth-sdk";
59
71
 
60
72
  const api = FaableAuthApi.create({
61
- auth: createApikeyAuth("fak_xxxxxxxxxxxxxxxx"),
62
- team_id: "team_xxxxxxxxxxxxxxxxxxxxxxxx",
73
+ domain: "https://<your-account>.auth.faable.link",
74
+ authStrategy: authApikey,
75
+ auth: { apikey: "fak_xxxxxxxxxxxxxxxx" },
63
76
  });
64
77
  ```
65
78
 
66
79
  ### Constructor options
67
80
 
68
- | Option | Type | Description |
69
- | ------------ | -------- | -------------------------------------------------------------------------------------------- |
70
- | `auth` | strategy | Auth strategy from `@faable/sdk-base`. Required. |
71
- | `team_id` | string | Scopes calls to a specific team (sent as `x-faable-team` header). |
72
- | `account_id` | string | Scopes calls to a specific FaableAuth account (sent as `x-faableauth-account` header). |
73
- | `domain` | string | Override the API host. Defaults to `https://faable.auth.faable.link`. |
74
- | `debug` | boolean | Enables verbose logging in the underlying fetcher. |
81
+ | Option | Type | Description |
82
+ | -------------- | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
83
+ | `domain` | string | **Required.** The account host to target, e.g. `https://<your-account>.auth.faable.link`. No default. |
84
+ | `authStrategy` | strategy builder | Auth strategy (`authClientCredentials` \| `authApikey`), re-exported from `@faable/auth-sdk`. Defaults to `authClientCredentials`. |
85
+ | `auth` | config | Config for the chosen strategy. Its shape is inferred from `authStrategy` (e.g. `{ client_id, client_secret }`). |
86
+ | `debug` | boolean | Enables verbose logging in the underlying fetcher. |
87
+ | `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`). |
75
88
 
76
89
  ---
77
90
 
@@ -1,9 +1,20 @@
1
1
  import { TeamCreate, UserCreate, UserUpdate } from "./api/api-types.js";
2
2
  import { ApiParams, FaableApi } from "@faable/sdk-base";
3
3
  type FaableAuthApiParams = {
4
- team_id?: string;
5
- account_id?: string;
6
- domain?: string;
4
+ domain: string;
5
+ /**
6
+ * Advanced / testing escape hatch: keep targeting `domain` but have the
7
+ * server resolve a DIFFERENT team or account, via request headers. Only the
8
+ * dashboard and some tests need this (e.g. point at a concrete host but
9
+ * resolve another account) — it is intentionally kept out of the normal
10
+ * config surface. Maps to:
11
+ * - `team_id` → `x-faable-team`
12
+ * - `account_id` → `x-faableauth-account`
13
+ */
14
+ headers?: {
15
+ team_id?: string;
16
+ account_id?: string;
17
+ };
7
18
  } & ApiParams;
8
19
  export declare class FaableAuthApi extends FaableApi {
9
20
  constructor(params?: FaableAuthApiParams);
@@ -4,10 +4,12 @@ import { FaableApi } from "@faable/sdk-base";
4
4
  import { version } from "./version.js";
5
5
  export class FaableAuthApi extends FaableApi {
6
6
  constructor(params) {
7
- let baseURL = "https://faable.auth.faable.link";
8
- if (params?.domain) {
9
- baseURL = getDomain(params.domain);
7
+ if (!params?.domain) {
8
+ throw new FaableApiError("FaableAuthApi: `domain` is required. Pass your account host, e.g. " +
9
+ "`new FaableAuthApi({ domain: 'https://<your-account>.auth.faable.link', ... })`. " +
10
+ "The hardcoded default was removed so SDK calls never target another tenant by accident.");
10
11
  }
12
+ const baseURL = getDomain(params.domain);
11
13
  super({
12
14
  baseURL,
13
15
  ...params,
@@ -20,9 +22,11 @@ export class FaableAuthApi extends FaableApi {
20
22
  // canonical logs). Format: `<name>/<version>`.
21
23
  "x-faable-client": `auth-sdk/${version}`,
22
24
  ...params?.fetcher?.headers,
23
- ...(params?.team_id && { "x-faable-team": params.team_id }),
24
- ...(params?.account_id && {
25
- "x-faableauth-account": params.account_id,
25
+ ...(params?.headers?.team_id && {
26
+ "x-faable-team": params.headers.team_id,
27
+ }),
28
+ ...(params?.headers?.account_id && {
29
+ "x-faableauth-account": params.headers.account_id,
26
30
  }),
27
31
  },
28
32
  },
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from "./FaableAuthApi.js";
2
2
  export * from "./api/api-types.js";
3
3
  export * from "./api/types.js";
4
+ export { authClientCredentials, authApikey } from "@faable/sdk-base";
5
+ export type { ApiParams, ClientCredentialsConfig, ApikeyConfig, AuthStrategy, AuthStrategyBuilder, AuthStrategyContext, } from "@faable/sdk-base";
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
1
  export * from "./FaableAuthApi.js";
2
2
  export * from "./api/api-types.js";
3
3
  export * from "./api/types.js";
4
+ // Re-export the auth strategies (and their config/types) from
5
+ // @faable/sdk-base so consumers depend on @faable/auth-sdk ONLY — sdk-base
6
+ // stays a transitive dependency and no app needs to import it directly.
7
+ export { authClientCredentials, authApikey } from "@faable/sdk-base";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/auth-sdk",
3
- "version": "1.3.35",
3
+ "version": "2.0.1",
4
4
  "author": "Marc Pomar <marc@faable.com>",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "type": "module",
12
12
  "dependencies": {
13
- "@faable/sdk-base": "^1.1.2"
13
+ "@faable/sdk-base": "^1.5.0"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@ava/typescript": "^5.0.0",
package/spec/openapi.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "info": {
4
4
  "title": "@faablecloud/auth",
5
5
  "description": "Auth Platform made by Faable. Manage Users and Roles",
6
- "version": "1.10.10",
6
+ "version": "1.11.0",
7
7
  "license": {
8
8
  "name": "private",
9
9
  "url": "https://faable.com/docs/platform/privacy-policy"