-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathusers.ts
More file actions
138 lines (120 loc) · 4.64 KB
/
Copy pathusers.ts
File metadata and controls
138 lines (120 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { z } from 'zod';
import {
HandleSchema,
NamespaceMemberSchema,
NamespaceTypeSchema,
} from '@mediforce/platform-core';
export const GetMeInputSchema = z
.object({
/**
* Server-to-server escape hatch: an apiKey caller has no user identity of
* its own, so it must name the user whose `me` view it wants. Bearer-token
* callers always derive the uid from the verified token; if `uid` is set
* for a user caller it MUST match `caller.uid` or the handler 403s.
*/
uid: z.string().min(1).optional(),
})
.strict();
export const MeNamespaceSchema = z.object({
handle: HandleSchema,
type: NamespaceTypeSchema,
displayName: z.string(),
role: z.enum(['owner', 'admin', 'member']),
avatarUrl: z.string().url().optional(),
icon: z.string().optional(),
logo: z.string().optional(),
brandPrimaryColor: z.string().optional(),
brandAccentColor: z.string().optional(),
});
export const GetMeOutputSchema = z.object({
user: z.object({
uid: z.string(),
email: z.string().email().nullable(),
displayName: z.string().nullable(),
/**
* `true` when the user must change their password before continuing.
* Defaults to `false` when no `users/{uid}` profile doc exists yet — see
* `UserProfileRepository.getProfile`. Cleared via
* `POST /api/users/me/clear-must-change-password`.
*/
mustChangePassword: z.boolean(),
}),
namespaces: z.array(MeNamespaceSchema),
});
export type GetMeInput = z.infer<typeof GetMeInputSchema>;
export type GetMeOutput = z.infer<typeof GetMeOutputSchema>;
export type MeNamespace = z.infer<typeof MeNamespaceSchema>;
const NamespaceQuery = z.object({ namespace: z.string().min(1) });
export const ListNamespaceMembersInputSchema = NamespaceQuery;
export const NamespaceMemberWithAuthSchema = NamespaceMemberSchema.extend({
/**
* Resolved display name for the member: the workspace-scoped `displayName`
* on the member doc when set, otherwise the Firebase Auth profile name
* looked up via `userDirectory.getUserMetadata`, otherwise `null`. UI
* chains `?? member.uid` to render a stable fallback.
*/
displayName: z.string().nullable(),
email: z.string().nullable(),
lastSignInTime: z.string().nullable(),
});
export const ListNamespaceMembersOutputSchema = z.object({
members: z.array(NamespaceMemberWithAuthSchema),
});
export type ListNamespaceMembersInput = z.infer<typeof ListNamespaceMembersInputSchema>;
export type ListNamespaceMembersOutput = z.infer<typeof ListNamespaceMembersOutputSchema>;
export type NamespaceMemberWithAuth = z.infer<typeof NamespaceMemberWithAuthSchema>;
export const InviteUserInputSchema = z.object({
email: z.string().email(),
displayName: z.string().min(1).optional(),
namespaceHandle: z
.string()
.min(1)
.regex(/^[a-z0-9-]+$/, 'namespaceHandle must be lowercase alphanumeric with hyphens only'),
role: z.enum(['member', 'admin']).optional().default('member'),
inviterName: z.string().min(1).optional(),
});
export const InviteUserOutputSchema = z.object({
uid: z.string(),
email: z.string(),
temporaryPassword: z.string(),
emailSent: z.boolean(),
isExisting: z.boolean(),
});
export type InviteUserInput = z.infer<typeof InviteUserInputSchema>;
export type InviteUserOutput = z.infer<typeof InviteUserOutputSchema>;
export const ResendInviteInputSchema = z.object({
uid: z.string().min(1),
namespaceHandle: z
.string()
.min(1)
.regex(/^[a-z0-9-]+$/, 'namespaceHandle must be lowercase alphanumeric with hyphens only'),
});
export const ResendInviteOutputSchema = z.object({
uid: z.string(),
email: z.string(),
temporaryPassword: z.string(),
emailSent: z.boolean(),
});
export type ResendInviteInput = z.infer<typeof ResendInviteInputSchema>;
export type ResendInviteOutput = z.infer<typeof ResendInviteOutputSchema>;
export const ClearMustChangePasswordInputSchema = z
.object({
/**
* Server-to-server escape hatch: when an apiKey caller invokes this
* endpoint (e.g. CLI `mediforce users clear-must-change-password`), it
* must name the target uid since the system actor has no implicit
* identity. User callers always derive the uid from the verified token;
* if `uid` is set for a user caller it MUST match `caller.uid` or the
* handler 403s.
*/
uid: z.string().min(1).optional(),
})
.strict();
export const ClearMustChangePasswordOutputSchema = z.object({
user: z.object({
uid: z.string(),
mustChangePassword: z.literal(false),
}),
});
export type ClearMustChangePasswordInput = z.infer<typeof ClearMustChangePasswordInputSchema>;
export type ClearMustChangePasswordOutput = z.infer<typeof ClearMustChangePasswordOutputSchema>;