@faable/auth-sdk 1.3.18 → 1.3.20
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/dist/FaableAuthApi.js +21 -1
- package/dist/error_handler.d.ts +1 -1
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.js +12 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +9 -0
- package/package.json +1 -1
- package/spec/openapi.json +1 -1
package/dist/FaableAuthApi.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { getDomain } from "./helpers.js";
|
|
1
|
+
import { getDomain, isPlainObject, requireId } from "./helpers.js";
|
|
2
|
+
import { FaableApiError } from "./error_handler.js";
|
|
2
3
|
import { FaableApi } from "@faable/sdk-base";
|
|
4
|
+
import { version } from "./version.js";
|
|
3
5
|
export class FaableAuthApi extends FaableApi {
|
|
4
6
|
constructor(params) {
|
|
5
7
|
let baseURL = "https://faable.auth.faable.link";
|
|
@@ -12,6 +14,11 @@ export class FaableAuthApi extends FaableApi {
|
|
|
12
14
|
fetcher: {
|
|
13
15
|
...params?.fetcher,
|
|
14
16
|
headers: {
|
|
17
|
+
// Identify ourselves as a first-party client so the auth server can
|
|
18
|
+
// tell management-SDK traffic apart from the dashboard or auth-js
|
|
19
|
+
// (surfaced as the `client` / `client_version` tags in Sentry /
|
|
20
|
+
// canonical logs). Format: `<name>/<version>`.
|
|
21
|
+
"x-faable-client": `auth-sdk/${version}`,
|
|
15
22
|
...params?.fetcher?.headers,
|
|
16
23
|
...(params?.team_id && { "x-faable-team": params.team_id }),
|
|
17
24
|
...(params?.account_id && {
|
|
@@ -22,12 +29,17 @@ export class FaableAuthApi extends FaableApi {
|
|
|
22
29
|
});
|
|
23
30
|
}
|
|
24
31
|
async setUserMetadata(user_id, user_metadata) {
|
|
32
|
+
requireId("user_id", user_id);
|
|
33
|
+
if (!isPlainObject(user_metadata)) {
|
|
34
|
+
throw new FaableApiError(`FaableApiError: user_metadata must be an object (received ${JSON.stringify(user_metadata)})`);
|
|
35
|
+
}
|
|
25
36
|
const user = await this.fetcher.post(`/user/${user_id}`, {
|
|
26
37
|
user_metadata,
|
|
27
38
|
});
|
|
28
39
|
return user.user_metadata;
|
|
29
40
|
}
|
|
30
41
|
async getUserMetadata(user_id) {
|
|
42
|
+
requireId("user_id", user_id);
|
|
31
43
|
const user = await this.fetcher.get(`/user/${user_id}`);
|
|
32
44
|
return user.user_metadata;
|
|
33
45
|
}
|
|
@@ -38,18 +50,22 @@ export class FaableAuthApi extends FaableApi {
|
|
|
38
50
|
return this.paginator({ url: "/user", params });
|
|
39
51
|
}
|
|
40
52
|
getUser(user_id) {
|
|
53
|
+
requireId("user_id", user_id);
|
|
41
54
|
return this.fetcher.get(`/user/${user_id}`);
|
|
42
55
|
}
|
|
43
56
|
createUser(data) {
|
|
44
57
|
return this.fetcher.post(`/user`, data);
|
|
45
58
|
}
|
|
46
59
|
updateUser(user_id, data) {
|
|
60
|
+
requireId("user_id", user_id);
|
|
47
61
|
return this.fetcher.post(`/user/${user_id}`, data);
|
|
48
62
|
}
|
|
49
63
|
getTeam(team_id) {
|
|
64
|
+
requireId("team_id", team_id);
|
|
50
65
|
return this.fetcher.get(`/team/${team_id}`);
|
|
51
66
|
}
|
|
52
67
|
deleteTeam(team_id) {
|
|
68
|
+
requireId("team_id", team_id);
|
|
53
69
|
return this.fetcher.delete(`/team/${team_id}`);
|
|
54
70
|
}
|
|
55
71
|
createTeam(data) {
|
|
@@ -65,18 +81,22 @@ export class FaableAuthApi extends FaableApi {
|
|
|
65
81
|
});
|
|
66
82
|
}
|
|
67
83
|
isUserMemberOfTeam(user_id, team_id) {
|
|
84
|
+
requireId("user_id", user_id);
|
|
85
|
+
requireId("team_id", team_id);
|
|
68
86
|
return this.fetcher.check(`/team/${team_id}/member/check/${user_id}`);
|
|
69
87
|
}
|
|
70
88
|
listConections() {
|
|
71
89
|
return this.paginator({ url: "/connection" });
|
|
72
90
|
}
|
|
73
91
|
getConection(connection_id) {
|
|
92
|
+
requireId("connection_id", connection_id);
|
|
74
93
|
return this.fetcher.get(`/connection/${connection_id}`);
|
|
75
94
|
}
|
|
76
95
|
listClients(params) {
|
|
77
96
|
return this.paginator({ url: "/client", params });
|
|
78
97
|
}
|
|
79
98
|
getClient(client_id) {
|
|
99
|
+
requireId("client_id", client_id);
|
|
80
100
|
return this.fetcher.get(`/client/${client_id}`);
|
|
81
101
|
}
|
|
82
102
|
}
|
package/dist/error_handler.d.ts
CHANGED
package/dist/helpers.d.ts
CHANGED
package/dist/helpers.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FaableApiError } from "./error_handler.js";
|
|
1
2
|
export const getDomain = (domain) => {
|
|
2
3
|
if (!/^(https|http)?:\/\//.test(domain)) {
|
|
3
4
|
const protocol = "https";
|
|
@@ -5,3 +6,14 @@ export const getDomain = (domain) => {
|
|
|
5
6
|
}
|
|
6
7
|
return domain;
|
|
7
8
|
};
|
|
9
|
+
// Guard required path params (ids) before interpolating them into a URL.
|
|
10
|
+
// Without this, a `null`/`undefined` id silently builds e.g. `/user/null`
|
|
11
|
+
// and the server rejects it with a confusing 400 — failing fast here gives
|
|
12
|
+
// the caller a clear error and keeps that noise out of the auth server.
|
|
13
|
+
export const requireId = (name, value) => {
|
|
14
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
15
|
+
throw new FaableApiError(`FaableApiError: ${name} is required and must be a non-empty string (received ${JSON.stringify(value)})`);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
export const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
// Read the published package version at runtime. semantic-release bumps
|
|
3
|
+
// package.json at publish time (after `npm run build`), so a build-time
|
|
4
|
+
// constant would always be stale; reading it from the installed package
|
|
5
|
+
// instead always reflects the real version. From dist/version.js,
|
|
6
|
+
// "../package.json" resolves to the package root.
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const { version } = require("../package.json");
|
|
9
|
+
export { version };
|
package/package.json
CHANGED
package/spec/openapi.json
CHANGED