Skip to content

Commit 8197863

Browse files
committed
Clean auth and rate limiting
1 parent 89bd164 commit 8197863

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

common/src/api/schema.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,39 @@ export const API = (_apiTypeCheck = {
4444
health: {
4545
method: 'GET',
4646
authed: false,
47+
rateLimited: false,
4748
props: z.object({}),
4849
returns: {} as { message: 'Server is working.'; uid?: string },
4950
},
5051
'get-supabase-token': {
5152
method: 'GET',
5253
authed: true,
54+
rateLimited: false,
5355
props: z.object({}),
5456
returns: {} as { jwt: string },
5557
},
5658
'mark-all-notifs-read': {
5759
method: 'POST',
5860
authed: true,
61+
rateLimited: false,
5962
props: z.object({}),
6063
},
6164
'user/by-id/:id/block': {
6265
method: 'POST',
6366
authed: true,
67+
rateLimited: false,
6468
props: z.object({id: z.string()}).strict(),
6569
},
6670
'user/by-id/:id/unblock': {
6771
method: 'POST',
6872
authed: true,
73+
rateLimited: false,
6974
props: z.object({id: z.string()}).strict(),
7075
},
7176
'ban-user': {
7277
method: 'POST',
7378
authed: true,
79+
rateLimited: false,
7480
props: z
7581
.object({
7682
userId: z.string(),
@@ -160,6 +166,7 @@ export const API = (_apiTypeCheck = {
160166
'update-notif-settings': {
161167
method: 'POST',
162168
authed: true,
169+
rateLimited: false,
163170
props: z.object({
164171
type: z.string() as z.ZodType<notification_preference>,
165172
medium: z.enum(['email', 'browser', 'mobile']),
@@ -184,27 +191,31 @@ export const API = (_apiTypeCheck = {
184191
'user/:username': {
185192
method: 'GET',
186193
authed: false,
194+
rateLimited: false,
187195
cache: DEFAULT_CACHE_STRATEGY,
188196
returns: {} as FullUser,
189197
props: z.object({username: z.string()}).strict(),
190198
},
191199
'user/:username/lite': {
192200
method: 'GET',
193201
authed: false,
202+
rateLimited: false,
194203
cache: DEFAULT_CACHE_STRATEGY,
195204
returns: {} as DisplayUser,
196205
props: z.object({username: z.string()}).strict(),
197206
},
198207
'user/by-id/:id': {
199208
method: 'GET',
200209
authed: false,
210+
rateLimited: false,
201211
cache: DEFAULT_CACHE_STRATEGY,
202212
returns: {} as FullUser,
203213
props: z.object({id: z.string()}).strict(),
204214
},
205215
'user/by-id/:id/lite': {
206216
method: 'GET',
207217
authed: false,
218+
rateLimited: false,
208219
cache: DEFAULT_CACHE_STRATEGY,
209220
returns: {} as DisplayUser,
210221
props: z.object({id: z.string()}).strict(),
@@ -225,7 +236,7 @@ export const API = (_apiTypeCheck = {
225236
},
226237
'compatible-profiles': {
227238
method: 'GET',
228-
authed: false,
239+
authed: true,
229240
rateLimited: true,
230241
props: z.object({userId: z.string()}),
231242
returns: {} as {
@@ -325,7 +336,7 @@ export const API = (_apiTypeCheck = {
325336
},
326337
'get-profiles': {
327338
method: 'GET',
328-
authed: false,
339+
authed: true,
329340
rateLimited: true,
330341
props: z
331342
.object({
@@ -415,6 +426,7 @@ export const API = (_apiTypeCheck = {
415426
'get-channel-seen-time': {
416427
method: 'GET',
417428
authed: true,
429+
rateLimited: false,
418430
props: z.object({
419431
channelIds: z
420432
.array(z.coerce.number())
@@ -426,18 +438,21 @@ export const API = (_apiTypeCheck = {
426438
'set-channel-seen-time': {
427439
method: 'POST',
428440
authed: true,
441+
rateLimited: false,
429442
props: z.object({
430443
channelId: z.coerce.number(),
431444
}),
432445
},
433446
'set-last-online-time': {
434447
method: 'POST',
435448
authed: true,
449+
rateLimited: false,
436450
props: z.object({}),
437451
},
438452
'get-notifications': {
439453
method: 'GET',
440454
authed: true,
455+
rateLimited: false,
441456
returns: [] as Notification[],
442457
props: z
443458
.object({
@@ -517,13 +532,14 @@ export const API = (_apiTypeCheck = {
517532
'get-messages-count': {
518533
method: 'GET',
519534
authed: true,
535+
rateLimited: false,
520536
props: z.object({}),
521537
returns: {} as { count: number },
522538
},
523539
} as const)
524540

525541
export type APIPath = keyof typeof API
526-
export type APISchema<N extends APIPath> = (typeof API)[N] & { rateLimited?: boolean }
542+
export type APISchema<N extends APIPath> = (typeof API)[N]
527543

528544
export type APIParams<N extends APIPath> = z.input<APISchema<N>['props']>
529545
export type ValidatedAPIParams<N extends APIPath> = z.output<

0 commit comments

Comments
 (0)