Skip to content

Commit 838a23b

Browse files
committed
updates
1 parent 7d4c8ea commit 838a23b

16 files changed

+155
-63
lines changed

rollup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default defineConfig([
2222
plugins: [
2323
alias({
2424
entries: [
25-
{ find: '@', replacement: resolve(__dirname, 'src') },
25+
{ find: '~', replacement: resolve(__dirname, 'src') },
2626
]
2727
}),
2828
nodeResolve(),

src/api/boards.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import type { Client, Request } from '@/interfaces';
2-
import { boardSchema, Board, CreateBoard } from '@/schemas/api/boards';
1+
import type { Client, Request } from '~/interfaces';
2+
import { boardSchema, Board, CreateBoard } from '~/schemas/api/boards';
3+
import { TrelloId } from '~/schemas/common';
4+
import { Members } from './members';
35

46
export class Boards {
5-
constructor(private client: Client) {}
7+
private membersClient: Members;
8+
9+
constructor(private client: Client) {
10+
this.membersClient = new Members(this.client);
11+
}
612

713
/** Create a new board. */
814
async create<T = Board>(board: CreateBoard): Promise<T> {
@@ -15,5 +21,38 @@ export class Boards {
1521
return this.client.sendRequest<T, never>(request, boardSchema);
1622
}
1723

18-
async delete(boardId) {}
24+
// async list() {
25+
// const request: Request = {
26+
// url: '/members/me/'
27+
// };
28+
//
29+
// return this.client.sendRequest(request);
30+
// }
31+
32+
async getAll() {
33+
const boardsId = await this.membersClient.getBoards('me');
34+
35+
const boards: Board[] = [];
36+
37+
for (const { id } of boardsId) {
38+
const board = await this.get(id);
39+
40+
boards.push(board);
41+
}
42+
43+
return boards;
44+
}
45+
46+
/** Request a single board. */
47+
async get(boardId: TrelloId): Promise<Board> {
48+
const request: Request = {
49+
url: `/boards/${boardId}`,
50+
method: 'GET',
51+
// todo additional queries
52+
};
53+
54+
return this.client.sendRequest(request, boardSchema);
55+
}
56+
57+
// async delete(boardId) {}
1958
}

src/api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './boards';
2+
export * from './members';

src/api/members.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { Client, Request } from '~/interfaces';
2+
import type { TrelloId } from '~/schemas/common';
3+
4+
export class Members {
5+
constructor(private client: Client) {}
6+
7+
getBoards<T = {id: string}[]>(memberId: TrelloId): Promise<T> {
8+
const request: Request = {
9+
url: `/members/${memberId}/boards`,
10+
method: 'GET',
11+
query: {
12+
fields: 'id', // todo
13+
}
14+
}
15+
16+
return this.client.sendRequest(request);
17+
}
18+
}

src/baseClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Config, configSchema } from '@/schemas';
2-
import type { Client, Request } from '@/interfaces';
1+
import { Config, configSchema } from '~/schemas';
2+
import type { Client, Request } from '~/interfaces';
33
import { ZodSchema } from 'zod';
44

55
export class BaseClient implements Client {
@@ -24,7 +24,7 @@ export class BaseClient implements Client {
2424
url.searchParams.set('token', this.config.token);
2525

2626
const response = await fetch(url, {
27-
method: 'POST',
27+
method: request.method,
2828
headers,
2929
});
3030

src/schemas/api/boards/boardSchema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
2-
import { prefsSchema } from '@/schemas/common/prefsSchema';
3-
import { colorSchema } from '@/schemas/common';
2+
import { prefsSchema } from '~/schemas/common/prefsSchema';
3+
import { colorSchema } from '~/schemas/common';
44

55
export const boardSchema = z.object({
66
id: z.string(),
@@ -15,7 +15,7 @@ export const boardSchema = z.object({
1515
shortUrl: z.string().url(),
1616
prefs: prefsSchema,
1717
labelNames: z.record(colorSchema, z.string()),
18-
limits: z.object({}).strict(),
18+
limits: z.object({}).strict().optional(),
1919
}).strict();
2020

2121
export type Board = z.infer<typeof boardSchema>;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { z } from 'zod';
2+
3+
export const backgroundScaledImageSchema = z.object({
4+
width: z.number().int().positive(),
5+
height: z.number().int().positive(),
6+
url: z.string().url()
7+
});
8+
9+
export type BackgroundScaledImage = z.infer<typeof backgroundScaledImageSchema>;

src/schemas/common/colorSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ export const colorSchema = z.enum([
3030
'sky_light',
3131
'lime_light',
3232
'pink_light',
33-
'black_light'
33+
'black_light',
3434
]);

src/schemas/common/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export * from './backgroundScaledImageSchema';
12
export * from './colorSchema';
23
export * from './hexColorSchema';
34
export * from './prefsSchema';
5+
export * from './trelloIdSchema';

src/schemas/common/prefsSchema.ts

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
11
import { z } from 'zod';
22
import { colorSchema } from './colorSchema';
33
import { hexColorSchema } from './hexColorSchema';
4+
import { backgroundScaledImageSchema } from '~/schemas/common/backgroundScaledImageSchema';
5+
import { trelloIdSchema } from '~/schemas/common/trelloIdSchema';
46

5-
export const prefsSchema = z.object({
6-
permissionLevel: z.enum(['private']),
7-
hideVotes: z.boolean(),
8-
voting: z.enum(['disabled']),
9-
comments: z.enum(['members']),
10-
invitations: z.enum(['members']),
11-
selfJoin: z.boolean(),
12-
cardCovers: z.boolean(),
13-
showCompleteStatus: z.boolean(),
14-
cardCounts: z.boolean(),
15-
isTemplate: z.boolean(),
16-
cardAging: z.enum(['regular']),
17-
calendarFeedEnabled: z.boolean(),
18-
hiddenPluginBoardButtons: z.array(z.unknown()),
19-
switcherViews: z.array(z.object({
20-
viewType: z.enum(['Board', 'Table', 'Calendar', 'Dashboard', 'Timeline', 'Map']),
21-
enabled: z.boolean(),
22-
}).strict()),
23-
background: colorSchema,
24-
backgroundColor: hexColorSchema,
25-
backgroundDarkColor: hexColorSchema.nullable(),
26-
backgroundImage: z.unknown().nullable(),
27-
backgroundDarkImage: z.unknown().nullable(),
28-
backgroundImageScaled: z.unknown().nullable(),
29-
backgroundTile: z.boolean(),
30-
backgroundBrightness: z.enum(['dark']),
31-
sharedSourceUrl: z.string().url().nullable(),
32-
backgroundBottomColor: hexColorSchema,
33-
backgroundTopColor: hexColorSchema,
34-
canBePublic: z.boolean(),
35-
canBeEnterprise: z.boolean(),
36-
canBeOrg: z.boolean(),
37-
canBePrivate: z.boolean(),
38-
canInvite: z.boolean(),
39-
}).strict();
7+
export const prefsSchema = z
8+
.object({
9+
background: z.union([colorSchema, trelloIdSchema]), // todo use discriminatedUnion
10+
backgroundBottomColor: hexColorSchema,
11+
backgroundBrightness: z.enum(['light', 'dark']),
12+
backgroundColor: hexColorSchema.nullable(),
13+
backgroundDarkColor: hexColorSchema.nullable(),
14+
backgroundDarkImage: z.unknown().nullable(),
15+
backgroundImage: z.string().url().nullable(),
16+
backgroundImageScaled: z.array(backgroundScaledImageSchema).nullable(),
17+
backgroundTile: z.boolean(),
18+
backgroundTopColor: hexColorSchema,
19+
calendarFeedEnabled: z.boolean(),
20+
canBeEnterprise: z.boolean(),
21+
canBeOrg: z.boolean(),
22+
canBePrivate: z.boolean(),
23+
canBePublic: z.boolean(),
24+
canInvite: z.boolean(),
25+
cardAging: z.enum(['regular']),
26+
cardCounts: z.boolean(),
27+
cardCovers: z.boolean(),
28+
comments: z.enum(['members']),
29+
hiddenPluginBoardButtons: z.array(z.unknown()),
30+
hideVotes: z.boolean(),
31+
invitations: z.enum(['members']),
32+
isTemplate: z.boolean(),
33+
permissionLevel: z.enum(['private', 'org', 'board']),
34+
selfJoin: z.boolean(),
35+
sharedSourceUrl: z.string().url().nullable(),
36+
showCompleteStatus: z.boolean(),
37+
switcherViews: z.array(
38+
z
39+
.object({
40+
viewType: z.enum(['Board', 'Table', 'Calendar', 'Dashboard', 'Timeline', 'Map']),
41+
enabled: z.boolean(),
42+
})
43+
.strict(),
44+
),
45+
voting: z.enum(['disabled', 'members']),
46+
})
47+
.strict();
4048

4149
export type Prefs = z.infer<typeof prefsSchema>;

0 commit comments

Comments
 (0)