File tree Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1
1
export * as pages from "./api/pages.ts" ;
2
+ export * as users from "./api/users.ts" ;
Original file line number Diff line number Diff line change
1
+ export * as me from "./users/me.ts" ;
Original file line number Diff line number Diff line change
1
+ import type { GuestUser , MemberUser } from "@cosense/types/rest" ;
2
+ import type { ResponseOfEndpoint } from "../../targeted_response.ts" ;
3
+ import { type BaseOptions , setDefaults } from "../../util.ts" ;
4
+ import { cookie } from "../../rest/auth.ts" ;
5
+
6
+ /** Constructs a request for the `/api/users/me endpoint`
7
+ *
8
+ * This endpoint retrieves the current user's profile information,
9
+ * which can be either a {@linkcode MemberUser} or {@linkcode GuestUser} profile.
10
+ *
11
+ * @param init - Options including `connect.sid` (session ID) and other configuration
12
+ * @returns A {@linkcode Request} object for fetching user profile data
13
+ */
14
+ export const makeGetRequest = < R extends Response | undefined > (
15
+ init ?: BaseOptions < R > ,
16
+ ) : Request => {
17
+ const { sid, hostName } = setDefaults ( init ?? { } ) ;
18
+ return new Request (
19
+ `https://${ hostName } /api/users/me` ,
20
+ sid ? { headers : { Cookie : cookie ( sid ) } } : undefined ,
21
+ ) ;
22
+ } ;
23
+
24
+ /** get the user profile
25
+ *
26
+ * @param init - Options including `connect.sid` (session ID) and other configuration
27
+ * @returns A {@linkcode Response} object containing the user profile data
28
+ */
29
+ export const get = < R extends Response | undefined = Response > (
30
+ init ?: BaseOptions < R > ,
31
+ ) : Promise <
32
+ ResponseOfEndpoint < { 200 : MemberUser | GuestUser } , R >
33
+ > =>
34
+ setDefaults ( init ?? { } ) . fetch (
35
+ makeGetRequest ( init ) ,
36
+ ) as Promise < ResponseOfEndpoint < { 200 : MemberUser | GuestUser } , R > > ;
Original file line number Diff line number Diff line change 24
24
"./unstable-api" : " ./api.ts" ,
25
25
"./unstable-api/pages" : " ./api/pages.ts" ,
26
26
"./unstable-api/pages/project" : " ./api/pages/project.ts" ,
27
- "./unstable-api/pages/project/title" : " ./api/pages/project/title.ts"
27
+ "./unstable-api/pages/project/title" : " ./api/pages/project/title.ts" ,
28
+ "./unstable-api/users" : " ./api/users.ts" ,
29
+ "./unstable-api/users/me" : " ./api/users/me.ts"
28
30
},
29
31
"imports" : {
30
32
"@core/unknownutil" : " jsr:@core/unknownutil@^4.0.0" ,
You can’t perform that action at this time.
0 commit comments