@baseworks/iam 1.3.0 → 1.4.0
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/{chunk-26XPWBFV.js → chunk-NAVQMKZ3.js} +7 -0
- package/dist/client.d.ts +28 -4
- package/dist/client.js +10 -2
- package/dist/events.d.ts +14 -4
- package/dist/events.js +1 -1
- package/dist/projections.js +4 -1
- package/package.json +2 -2
- package/src/client.ts +14 -4
- package/src/events.ts +7 -0
- package/src/projections.ts +3 -0
- package/src/types.ts +19 -1
|
@@ -17,6 +17,13 @@ var UserEvents = defineAggregate("user", {
|
|
|
17
17
|
name: z.string().nullable(),
|
|
18
18
|
picture: z.string().nullable(),
|
|
19
19
|
at: z.number().int()
|
|
20
|
+
}),
|
|
21
|
+
// The person chose what they are called here (iam-service 0.5). Kept apart
|
|
22
|
+
// from `name`, which the identity provider sends on every sign-in and would
|
|
23
|
+
// otherwise overwrite it. `null` means "back to what the provider says".
|
|
24
|
+
UserRenamed: z.object({
|
|
25
|
+
displayName: z.string().min(1).nullable(),
|
|
26
|
+
at: z.number().int()
|
|
20
27
|
})
|
|
21
28
|
});
|
|
22
29
|
var TOKEN_TYPES = ["user", "service", "cli", "agent"];
|
package/dist/client.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ interface UserRow {
|
|
|
10
10
|
email: string;
|
|
11
11
|
name: string | null;
|
|
12
12
|
picture: string | null;
|
|
13
|
+
/** What the person chose to be called here; null or absent: the provider's `name`. */
|
|
14
|
+
display_name?: string | null;
|
|
13
15
|
created_at: number;
|
|
14
16
|
updated_at: number;
|
|
15
17
|
}
|
|
@@ -38,12 +40,27 @@ interface User {
|
|
|
38
40
|
created_at: number;
|
|
39
41
|
updated_at: number;
|
|
40
42
|
}
|
|
41
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Public-safe identity projection (returned by /users/lookup and
|
|
45
|
+
* /users/resolve). `name` is what the person chose to be called, else what
|
|
46
|
+
* their identity provider says.
|
|
47
|
+
*/
|
|
42
48
|
interface PublicUser {
|
|
43
49
|
id: string;
|
|
44
50
|
email: string;
|
|
45
51
|
name: string | null;
|
|
46
52
|
}
|
|
53
|
+
/** A person's own account, as `/me` gives it to them and to nobody else. */
|
|
54
|
+
interface Me extends PublicUser {
|
|
55
|
+
/** The name the identity provider sends; what `name` falls back to. */
|
|
56
|
+
provider_name: string | null;
|
|
57
|
+
/** True when `name` is one the person set here. */
|
|
58
|
+
name_is_own: boolean;
|
|
59
|
+
picture: string | null;
|
|
60
|
+
/** The identity provider this account signs in with. */
|
|
61
|
+
issuer: string;
|
|
62
|
+
created_at: number;
|
|
63
|
+
}
|
|
47
64
|
/** An OIDC identity presented to POST /sync (before a user id exists). */
|
|
48
65
|
interface OidcIdentity {
|
|
49
66
|
subject: string;
|
|
@@ -137,8 +154,15 @@ declare class IamClient {
|
|
|
137
154
|
api<T>(method: string, path: string, body?: unknown, extra?: Record<string, string>): Promise<T>;
|
|
138
155
|
/** Generic ApiClient (get/post/del) — used by the CLI plugin. */
|
|
139
156
|
get http(): HttpClient;
|
|
140
|
-
/** The signed-in user's own
|
|
141
|
-
me(): Promise<
|
|
157
|
+
/** The signed-in user's own account (no orgs — those live in @baseworks/org). */
|
|
158
|
+
me(): Promise<Me>;
|
|
159
|
+
/**
|
|
160
|
+
* Set what the signed-in person is called here. `null` goes back to the name
|
|
161
|
+
* their identity provider sends. Email and picture are the provider's.
|
|
162
|
+
*/
|
|
163
|
+
updateMe(input: {
|
|
164
|
+
name: string | null;
|
|
165
|
+
}): Promise<Me>;
|
|
142
166
|
/** Upsert an OIDC identity → the platform user. Called by auth-service (no auth). */
|
|
143
167
|
sync(identity: OidcIdentity): Promise<{
|
|
144
168
|
id: string;
|
|
@@ -175,4 +199,4 @@ declare class IamClient {
|
|
|
175
199
|
/** Factory used by the SDK capability registry. */
|
|
176
200
|
declare function createIamClient(opts: IamClientOptions): IamClient;
|
|
177
201
|
|
|
178
|
-
export { type ApiToken, type ApiTokenRow, type AuthContext, type HttpClient, IamClient, type IamClientOptions, IamError, type IssuedToken, type OidcIdentity, type PublicUser, type TokenPrincipal, TokenType, type User, type UserRow, createIamClient };
|
|
202
|
+
export { type ApiToken, type ApiTokenRow, type AuthContext, type HttpClient, IamClient, type IamClientOptions, IamError, type IssuedToken, type Me, type OidcIdentity, type PublicUser, type TokenPrincipal, TokenType, type User, type UserRow, createIamClient };
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TOKEN_TYPES
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NAVQMKZ3.js";
|
|
4
4
|
|
|
5
5
|
// src/client.ts
|
|
6
6
|
var IamError = class extends Error {
|
|
@@ -62,11 +62,19 @@ var IamClient = class _IamClient {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
// ── identity ────────────────────────────────────────────────────────────────
|
|
65
|
-
/** The signed-in user's own
|
|
65
|
+
/** The signed-in user's own account (no orgs — those live in @baseworks/org). */
|
|
66
66
|
async me() {
|
|
67
67
|
const { user } = await this.api("GET", "/me");
|
|
68
68
|
return user;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Set what the signed-in person is called here. `null` goes back to the name
|
|
72
|
+
* their identity provider sends. Email and picture are the provider's.
|
|
73
|
+
*/
|
|
74
|
+
async updateMe(input) {
|
|
75
|
+
const { user } = await this.api("PATCH", "/me", input);
|
|
76
|
+
return user;
|
|
77
|
+
}
|
|
70
78
|
/** Upsert an OIDC identity → the platform user. Called by auth-service (no auth). */
|
|
71
79
|
async sync(identity) {
|
|
72
80
|
const { user } = await this.api("POST", "/sync", identity);
|
package/dist/events.d.ts
CHANGED
|
@@ -25,17 +25,17 @@ declare const UserEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
25
25
|
picture: z.ZodNullable<z.ZodString>;
|
|
26
26
|
at: z.ZodNumber;
|
|
27
27
|
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
email: string;
|
|
28
29
|
at: number;
|
|
29
30
|
subject: string;
|
|
30
31
|
issuer: string;
|
|
31
|
-
email: string;
|
|
32
32
|
name: string | null;
|
|
33
33
|
picture: string | null;
|
|
34
34
|
}, {
|
|
35
|
+
email: string;
|
|
35
36
|
at: number;
|
|
36
37
|
subject: string;
|
|
37
38
|
issuer: string;
|
|
38
|
-
email: string;
|
|
39
39
|
name: string | null;
|
|
40
40
|
picture: string | null;
|
|
41
41
|
}>;
|
|
@@ -45,16 +45,26 @@ declare const UserEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
45
45
|
picture: z.ZodNullable<z.ZodString>;
|
|
46
46
|
at: z.ZodNumber;
|
|
47
47
|
}, "strip", z.ZodTypeAny, {
|
|
48
|
-
at: number;
|
|
49
48
|
email: string;
|
|
49
|
+
at: number;
|
|
50
50
|
name: string | null;
|
|
51
51
|
picture: string | null;
|
|
52
52
|
}, {
|
|
53
|
-
at: number;
|
|
54
53
|
email: string;
|
|
54
|
+
at: number;
|
|
55
55
|
name: string | null;
|
|
56
56
|
picture: string | null;
|
|
57
57
|
}>;
|
|
58
|
+
UserRenamed: z.ZodObject<{
|
|
59
|
+
displayName: z.ZodNullable<z.ZodString>;
|
|
60
|
+
at: z.ZodNumber;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
at: number;
|
|
63
|
+
displayName: string | null;
|
|
64
|
+
}, {
|
|
65
|
+
at: number;
|
|
66
|
+
displayName: string | null;
|
|
67
|
+
}>;
|
|
58
68
|
}> & {
|
|
59
69
|
newId(): string;
|
|
60
70
|
};
|
package/dist/events.js
CHANGED
package/dist/projections.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ApiTokenEvents,
|
|
3
3
|
UserEvents
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NAVQMKZ3.js";
|
|
5
5
|
|
|
6
6
|
// src/projections.ts
|
|
7
7
|
import { defineProjection } from "@baseworks/foldbase";
|
|
@@ -18,6 +18,9 @@ var readUsers = defineProjection("users", UserEvents, (on) => ({
|
|
|
18
18
|
email: e.email,
|
|
19
19
|
name: e.name,
|
|
20
20
|
picture: e.picture
|
|
21
|
+
})),
|
|
22
|
+
UserRenamed: on.UserRenamed.upsert((e) => ({
|
|
23
|
+
display_name: e.displayName
|
|
21
24
|
}))
|
|
22
25
|
}));
|
|
23
26
|
var readApiTokens = defineProjection("api_tokens", ApiTokenEvents, (on) => ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baseworks/iam",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "IAM capability: identity (users) + credentials (api tokens). Typed HTTP client, foldbase event catalog, projections, and CLI plugin for iam-service. Contract-first, versioned with the service. Roles/PDP live in @baseworks/org.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@baseworks/cli": "^0.2.0",
|
|
21
21
|
"commander": "^15.0.0",
|
|
22
22
|
"zod": "^3.25.76",
|
|
23
|
-
"@baseworks/foldbase": "0.
|
|
23
|
+
"@baseworks/foldbase": "0.2.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^22.20.0",
|
package/src/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PublicUser, OidcIdentity, ApiToken, IssuedToken, TokenPrincipal, TokenType } from './types.js'
|
|
1
|
+
import type { PublicUser, Me, OidcIdentity, ApiToken, IssuedToken, TokenPrincipal, TokenType } from './types.js'
|
|
2
2
|
|
|
3
3
|
// Value re-export (a runtime const, not just a type) so consumers can build
|
|
4
4
|
// validators from it, e.g. `z.enum(TOKEN_TYPES)`.
|
|
@@ -7,6 +7,7 @@ export { TOKEN_TYPES } from './types.js'
|
|
|
7
7
|
export type {
|
|
8
8
|
User,
|
|
9
9
|
PublicUser,
|
|
10
|
+
Me,
|
|
10
11
|
OidcIdentity,
|
|
11
12
|
ApiToken,
|
|
12
13
|
IssuedToken,
|
|
@@ -112,9 +113,18 @@ export class IamClient {
|
|
|
112
113
|
|
|
113
114
|
// ── identity ────────────────────────────────────────────────────────────────
|
|
114
115
|
|
|
115
|
-
/** The signed-in user's own
|
|
116
|
-
async me(): Promise<
|
|
117
|
-
const { user } = await this.api<{ user:
|
|
116
|
+
/** The signed-in user's own account (no orgs — those live in @baseworks/org). */
|
|
117
|
+
async me(): Promise<Me> {
|
|
118
|
+
const { user } = await this.api<{ user: Me }>('GET', '/me')
|
|
119
|
+
return user
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Set what the signed-in person is called here. `null` goes back to the name
|
|
124
|
+
* their identity provider sends. Email and picture are the provider's.
|
|
125
|
+
*/
|
|
126
|
+
async updateMe(input: { name: string | null }): Promise<Me> {
|
|
127
|
+
const { user } = await this.api<{ user: Me }>('PATCH', '/me', input)
|
|
118
128
|
return user
|
|
119
129
|
}
|
|
120
130
|
|
package/src/events.ts
CHANGED
|
@@ -36,6 +36,13 @@ export const UserEvents = defineAggregate('user', {
|
|
|
36
36
|
picture: z.string().nullable(),
|
|
37
37
|
at: z.number().int(),
|
|
38
38
|
}),
|
|
39
|
+
// The person chose what they are called here (iam-service 0.5). Kept apart
|
|
40
|
+
// from `name`, which the identity provider sends on every sign-in and would
|
|
41
|
+
// otherwise overwrite it. `null` means "back to what the provider says".
|
|
42
|
+
UserRenamed: z.object({
|
|
43
|
+
displayName: z.string().min(1).nullable(),
|
|
44
|
+
at: z.number().int(),
|
|
45
|
+
}),
|
|
39
46
|
})
|
|
40
47
|
|
|
41
48
|
// ── api_token ───────────────────────────────────────────────────────────────
|
package/src/projections.ts
CHANGED
|
@@ -25,6 +25,9 @@ export const readUsers = defineProjection('users', UserEvents, (on) => ({
|
|
|
25
25
|
name: e.name,
|
|
26
26
|
picture: e.picture,
|
|
27
27
|
})),
|
|
28
|
+
UserRenamed: on.UserRenamed.upsert((e) => ({
|
|
29
|
+
display_name: e.displayName,
|
|
30
|
+
})),
|
|
28
31
|
}))
|
|
29
32
|
|
|
30
33
|
export const readApiTokens = defineProjection('api_tokens', ApiTokenEvents, (on) => ({
|
package/src/types.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface UserRow {
|
|
|
14
14
|
email: string
|
|
15
15
|
name: string | null
|
|
16
16
|
picture: string | null
|
|
17
|
+
/** What the person chose to be called here; null or absent: the provider's `name`. */
|
|
18
|
+
display_name?: string | null
|
|
17
19
|
created_at: number
|
|
18
20
|
updated_at: number
|
|
19
21
|
}
|
|
@@ -51,13 +53,29 @@ export interface User {
|
|
|
51
53
|
updated_at: number
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Public-safe identity projection (returned by /users/lookup and
|
|
58
|
+
* /users/resolve). `name` is what the person chose to be called, else what
|
|
59
|
+
* their identity provider says.
|
|
60
|
+
*/
|
|
55
61
|
export interface PublicUser {
|
|
56
62
|
id: string
|
|
57
63
|
email: string
|
|
58
64
|
name: string | null
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
/** A person's own account, as `/me` gives it to them and to nobody else. */
|
|
68
|
+
export interface Me extends PublicUser {
|
|
69
|
+
/** The name the identity provider sends; what `name` falls back to. */
|
|
70
|
+
provider_name: string | null
|
|
71
|
+
/** True when `name` is one the person set here. */
|
|
72
|
+
name_is_own: boolean
|
|
73
|
+
picture: string | null
|
|
74
|
+
/** The identity provider this account signs in with. */
|
|
75
|
+
issuer: string
|
|
76
|
+
created_at: number
|
|
77
|
+
}
|
|
78
|
+
|
|
61
79
|
/** An OIDC identity presented to POST /sync (before a user id exists). */
|
|
62
80
|
export interface OidcIdentity {
|
|
63
81
|
subject: string
|