@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 +35 -22
- package/dist/FaableAuthApi.d.ts +14 -3
- package/dist/FaableAuthApi.js +10 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/package.json +2 -2
- package/spec/openapi.json +1 -1
package/README.md
CHANGED
|
@@ -25,53 +25,66 @@ npm install @faable/auth-sdk
|
|
|
25
25
|
|
|
26
26
|
## Authentication
|
|
27
27
|
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
48
|
-
client_id:
|
|
49
|
-
client_secret:
|
|
50
|
-
domain: "
|
|
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
|
-
|
|
62
|
-
|
|
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
|
|
69
|
-
|
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
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
|
|
package/dist/FaableAuthApi.d.ts
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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);
|
package/dist/FaableAuthApi.js
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 && {
|
|
24
|
-
|
|
25
|
-
|
|
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": "
|
|
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.
|
|
13
|
+
"@faable/sdk-base": "^1.5.0"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@ava/typescript": "^5.0.0",
|
package/spec/openapi.json
CHANGED