forked from suekou/mcp-notion-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
1534 lines (1415 loc) · 42.1 KB
/
index.ts
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
/**
* All API endpoints support both JSON and Markdown response formats.
* Set the "format" parameter to "json" or "markdown" (default is "markdown").
* - Use "markdown" for human-readable output when only reading content
* - Use "json" when you need to process or modify the data programmatically
*
* Environment Variables:
* - NOTION_API_TOKEN: Required. Your Notion API integration token.
* - NOTION_MARKDOWN_CONVERSION: Optional. Set to "true" to enable
* experimental Markdown conversion. If not set or set to any other value,
* all responses will be in JSON format regardless of the "format" parameter.
*/
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequest,
CallToolRequestSchema,
ListToolsRequestSchema,
Tool,
} from "@modelcontextprotocol/sdk/types.js";
import { convertToMarkdown } from "./markdown/index.js";
import {
NotionResponse,
BlockResponse,
PageResponse,
DatabaseResponse,
ListResponse,
UserResponse,
CommentResponse,
RichTextItemResponse,
} from "./types/index.js";
// Type definitions for tool arguments
// Blocks
interface AppendBlockChildrenArgs {
block_id: string;
children: Partial<BlockResponse>[];
after?: string;
format?: "json" | "markdown";
}
interface RetrieveBlockArgs {
block_id: string;
format?: "json" | "markdown";
}
interface RetrieveBlockChildrenArgs {
block_id: string;
start_cursor?: string;
page_size?: number;
format?: "json" | "markdown";
}
interface DeleteBlockArgs {
block_id: string;
format?: "json" | "markdown";
}
// Pages
interface RetrievePageArgs {
page_id: string;
format?: "json" | "markdown";
}
interface UpdatePagePropertiesArgs {
page_id: string;
properties: Record<string, any>;
format?: "json" | "markdown";
}
// Users
interface ListAllUsersArgs {
start_cursor?: string;
page_size?: number;
format?: "json" | "markdown";
}
interface RetrieveUserArgs {
user_id: string;
format?: "json" | "markdown";
}
interface RetrieveBotUserArgs {
random_string: string;
format?: "json" | "markdown";
}
// Databases
interface CreateDatabaseArgs {
parent: {
type: string;
page_id?: string;
database_id?: string;
workspace?: boolean;
};
title: RichTextItemResponse[];
properties: Record<string, any>;
format?: "json" | "markdown";
}
interface QueryDatabaseArgs {
database_id: string;
filter?: Record<string, any>;
sorts?: Array<{
property?: string;
timestamp?: string;
direction: "ascending" | "descending";
}>;
start_cursor?: string;
page_size?: number;
format?: "json" | "markdown";
}
interface RetrieveDatabaseArgs {
database_id: string;
format?: "json" | "markdown";
}
interface UpdateDatabaseArgs {
database_id: string;
title?: RichTextItemResponse[];
description?: RichTextItemResponse[];
properties?: Record<string, any>;
format?: "json" | "markdown";
}
interface CreateDatabaseItemArgs {
database_id: string;
properties: Record<string, any>;
format?: "json" | "markdown";
}
// Comments
interface CreateCommentArgs {
parent?: { page_id: string };
discussion_id?: string;
rich_text: RichTextItemResponse[];
format?: "json" | "markdown";
}
interface RetrieveCommentsArgs {
block_id: string;
start_cursor?: string;
page_size?: number;
format?: "json" | "markdown";
}
// Search
interface SearchArgs {
query?: string;
filter?: { property: string; value: string };
sort?: {
direction: "ascending" | "descending";
timestamp: "last_edited_time";
};
start_cursor?: string;
page_size?: number;
format?: "json" | "markdown";
}
// TODO: Define Type-safe request/response handling using Zod schemas
const commonIdDescription =
"It should be a 32-character string (excluding hyphens) formatted as 8-4-4-4-12 with hyphens (-).";
// Add format parameter to common schema
const formatParameter = {
type: "string",
enum: ["json", "markdown"],
description:
"Specify the response format. 'json' returns the original data structure, 'markdown' returns a more readable format. Use 'markdown' when the user only needs to read the page and isn't planning to write or modify it. Use 'json' when the user needs to read the page with the intention of writing to or modifying it.",
default: "markdown",
};
// common object schema
const richTextObjectSchema = {
type: "object",
description: "A rich text object.",
properties: {
type: {
type: "string",
description:
"The type of this rich text object. Possible values: text, mention, equation.",
enum: ["text", "mention", "equation"],
},
text: {
type: "object",
description:
"Object containing text content and optional link info. Required if type is 'text'.",
properties: {
content: {
type: "string",
description: "The actual text content.",
},
link: {
type: "object",
description: "Optional link object with a 'url' field.",
properties: {
url: {
type: "string",
description: "The URL the text links to.",
},
},
},
},
},
mention: {
type: "object",
description:
"Mention object if type is 'mention'. Represents an inline mention of a database, date, link preview, page, template mention, or user.",
properties: {
type: {
type: "string",
description: "The type of the mention.",
enum: [
"database",
"date",
"link_preview",
"page",
"template_mention",
"user",
],
},
database: {
type: "object",
description:
"Database mention object. Contains a database reference with an 'id' field.",
properties: {
id: {
type: "string",
description:
"The ID of the mentioned database." + commonIdDescription,
},
},
required: ["id"],
},
date: {
type: "object",
description:
"Date mention object, containing a date property value object.",
properties: {
start: {
type: "string",
description: "An ISO 8601 formatted start date or date-time.",
},
end: {
type: ["string", "null"],
description:
"An ISO 8601 formatted end date or date-time, or null if not a range.",
},
time_zone: {
type: ["string", "null"],
description:
"Time zone information for start and end. If null, times are in UTC.",
},
},
required: ["start"],
},
link_preview: {
type: "object",
description:
"Link Preview mention object, containing a URL for the link preview.",
properties: {
url: {
type: "string",
description: "The URL for the link preview.",
},
},
required: ["url"],
},
page: {
type: "object",
description:
"Page mention object, containing a page reference with an 'id' field.",
properties: {
id: {
type: "string",
description:
"The ID of the mentioned page." + commonIdDescription,
},
},
required: ["id"],
},
template_mention: {
type: "object",
description:
"Template mention object, can be a template_mention_date or template_mention_user.",
properties: {
type: {
type: "string",
enum: ["template_mention_date", "template_mention_user"],
description: "The template mention type.",
},
template_mention_date: {
type: "string",
enum: ["today", "now"],
description: "For template_mention_date type, the date keyword.",
},
template_mention_user: {
type: "string",
enum: ["me"],
description: "For template_mention_user type, the user keyword.",
},
},
},
user: {
type: "object",
description: "User mention object, contains a user reference.",
properties: {
object: {
type: "string",
description: "Should be 'user'.",
enum: ["user"],
},
id: {
type: "string",
description: "The ID of the user." + commonIdDescription,
},
},
required: ["object", "id"],
},
},
required: ["type"],
oneOf: [
{ required: ["database"] },
{ required: ["date"] },
{ required: ["link_preview"] },
{ required: ["page"] },
{ required: ["template_mention"] },
{ required: ["user"] },
],
},
equation: {
type: "object",
description:
"Equation object if type is 'equation'. Represents an inline LaTeX equation.",
properties: {
expression: {
type: "string",
description: "LaTeX string representing the inline equation.",
},
},
required: ["expression"],
},
annotations: {
type: "object",
description: "Styling information for the text.",
properties: {
bold: { type: "boolean" },
italic: { type: "boolean" },
strikethrough: { type: "boolean" },
underline: { type: "boolean" },
code: { type: "boolean" },
color: {
type: "string",
description: "Color for the text.",
enum: [
"default",
"blue",
"blue_background",
"brown",
"brown_background",
"gray",
"gray_background",
"green",
"green_background",
"orange",
"orange_background",
"pink",
"pink_background",
"purple",
"purple_background",
"red",
"red_background",
"yellow",
"yellow_background",
],
},
},
},
href: {
type: "string",
description: "The URL of any link or mention in this text, if any.",
},
plain_text: {
type: "string",
description: "The plain text without annotations.",
},
},
required: ["type"],
};
const blockObjectSchema = {
type: "object",
description: "A Notion block object.",
properties: {
object: {
type: "string",
description: "Should be 'block'.",
enum: ["block"],
},
type: {
type: "string",
description:
"Type of the block. Possible values include 'paragraph', 'heading_1', 'heading_2', 'heading_3', 'bulleted_list_item', 'numbered_list_item', 'to_do', 'toggle', 'child_page', 'child_database', 'embed', 'callout', 'quote', 'equation', 'divider', 'table_of_contents', 'column', 'column_list', 'link_preview', 'synced_block', 'template', 'link_to_page', 'audio', 'bookmark', 'breadcrumb', 'code', 'file', 'image', 'pdf', 'video'. Not all types are supported for creation via API.",
},
paragraph: {
type: "object",
description: "Paragraph block object.",
properties: {
rich_text: richTextObjectSchema,
color: {
type: "string",
description: "The color of the block.",
enum: [
"default",
"blue",
"blue_background",
"brown",
"brown_background",
"gray",
"gray_background",
"green",
"green_background",
"orange",
"orange_background",
"pink",
"pink_background",
"purple",
"purple_background",
"red",
"red_background",
"yellow",
"yellow_background",
],
},
children: {
type: "array",
description: "Nested child blocks.",
items: {
type: "object",
description: "A nested block object.",
},
},
},
},
},
required: ["object", "type"],
};
// TODO: If modifications are made, since the original source information is necessary, add an explanation that retrieves the raw object that has not been converted to markdown, and create a dedicated tool to convert to markdown.
// Tool definitions
// Blocks
const appendBlockChildrenTool: Tool = {
name: "notion_append_block_children",
description:
"Append new children blocks to a specified parent block in Notion. Requires insert content capabilities. You can optionally specify the 'after' parameter to append after a certain block.",
inputSchema: {
type: "object",
properties: {
block_id: {
type: "string",
description: "The ID of the parent block." + commonIdDescription,
},
children: {
type: "array",
description:
"Array of block objects to append. Each block must follow the Notion block schema.",
items: blockObjectSchema,
},
after: {
type: "string",
description:
"The ID of the existing block that the new block should be appended after." +
commonIdDescription,
},
format: formatParameter,
},
required: ["block_id", "children"],
},
};
const retrieveBlockTool: Tool = {
name: "notion_retrieve_block",
description: "Retrieve a block from Notion",
inputSchema: {
type: "object",
properties: {
block_id: {
type: "string",
description: "The ID of the block to retrieve." + commonIdDescription,
},
format: formatParameter,
},
required: ["block_id"],
},
};
const retrieveBlockChildrenTool: Tool = {
name: "notion_retrieve_block_children",
description: "Retrieve the children of a block",
inputSchema: {
type: "object",
properties: {
block_id: {
type: "string",
description: "The ID of the block." + commonIdDescription,
},
start_cursor: {
type: "string",
description: "Pagination cursor for next page of results",
},
page_size: {
type: "number",
description: "Number of results per page (max 100)",
},
format: formatParameter,
},
required: ["block_id"],
},
};
const deleteBlockTool: Tool = {
name: "notion_delete_block",
description: "Delete a block in Notion",
inputSchema: {
type: "object",
properties: {
block_id: {
type: "string",
description: "The ID of the block to delete." + commonIdDescription,
},
format: formatParameter,
},
required: ["block_id"],
},
};
const updateBlockTool: Tool = {
name: "notion_update_block",
description: "Update the content of a block in Notion based on its type. The update replaces the entire value for a given field.",
inputSchema: {
type: "object",
properties: {
block_id: {
type: "string",
description: "The ID of the block to update." + commonIdDescription,
},
block: {
type: "object",
description: "The updated content for the block. Must match the block's type schema.",
},
format: formatParameter,
},
required: ["block_id", "block"],
},
};
// Pages
const retrievePageTool: Tool = {
name: "notion_retrieve_page",
description: "Retrieve a page from Notion",
inputSchema: {
type: "object",
properties: {
page_id: {
type: "string",
description: "The ID of the page to retrieve." + commonIdDescription,
},
format: formatParameter,
},
required: ["page_id"],
},
};
const updatePagePropertiesTool: Tool = {
name: "notion_update_page_properties",
description: "Update properties of a page or an item in a Notion database",
inputSchema: {
type: "object",
properties: {
page_id: {
type: "string",
description:
"The ID of the page or database item to update." +
commonIdDescription,
},
properties: {
type: "object",
description:
"Properties to update. These correspond to the columns or fields in the database.",
},
format: formatParameter,
},
required: ["page_id", "properties"],
},
};
// Users
const listAllUsersTool: Tool = {
name: "notion_list_all_users",
description:
"List all users in the Notion workspace. **Note:** This function requires upgrading to the Notion Enterprise plan and using an Organization API key to avoid permission errors.",
inputSchema: {
type: "object",
properties: {
start_cursor: {
type: "string",
description: "Pagination start cursor for listing users",
},
page_size: {
type: "number",
description: "Number of users to retrieve (max 100)",
},
format: formatParameter,
},
},
};
const retrieveUserTool: Tool = {
name: "notion_retrieve_user",
description:
"Retrieve a specific user by user_id in Notion. **Note:** This function requires upgrading to the Notion Enterprise plan and using an Organization API key to avoid permission errors.",
inputSchema: {
type: "object",
properties: {
user_id: {
type: "string",
description: "The ID of the user to retrieve." + commonIdDescription,
},
format: formatParameter,
},
required: ["user_id"],
},
};
const retrieveBotUserTool: Tool = {
name: "notion_retrieve_bot_user",
description:
"Retrieve the bot user associated with the current token in Notion",
inputSchema: {
type: "object",
properties: {
random_string: {
type: "string",
description: "Dummy parameter for no-parameter tools",
},
format: formatParameter,
},
required: ["random_string"],
},
};
// Databases
const createDatabaseTool: Tool = {
name: "notion_create_database",
description: "Create a database in Notion",
inputSchema: {
type: "object",
properties: {
parent: {
type: "object",
description: "Parent object of the database",
},
title: {
type: "array",
description:
"Title of database as it appears in Notion. An array of rich text objects.",
items: richTextObjectSchema,
},
properties: {
type: "object",
description:
"Property schema of database. The keys are the names of properties as they appear in Notion and the values are property schema objects.",
},
format: formatParameter,
},
required: ["parent", "properties"],
},
};
const queryDatabaseTool: Tool = {
name: "notion_query_database",
description: "Query a database in Notion",
inputSchema: {
type: "object",
properties: {
database_id: {
type: "string",
description: "The ID of the database to query." + commonIdDescription,
},
filter: {
type: "object",
description: "Filter conditions",
},
sorts: {
type: "array",
description: "Sort conditions",
items: {
type: "object",
properties: {
property: { type: "string" },
timestamp: { type: "string" },
direction: {
type: "string",
enum: ["ascending", "descending"]
}
},
required: ["direction"]
}
},
start_cursor: {
type: "string",
description: "Pagination cursor for next page of results",
},
page_size: {
type: "number",
description: "Number of results per page (max 100)",
},
format: formatParameter,
},
required: ["database_id"],
},
};
const retrieveDatabaseTool: Tool = {
name: "notion_retrieve_database",
description: "Retrieve a database in Notion",
inputSchema: {
type: "object",
properties: {
database_id: {
type: "string",
description:
"The ID of the database to retrieve." + commonIdDescription,
},
format: formatParameter,
},
required: ["database_id"],
},
};
const updateDatabaseTool: Tool = {
name: "notion_update_database",
description: "Update a database in Notion",
inputSchema: {
type: "object",
properties: {
database_id: {
type: "string",
description: "The ID of the database to update." + commonIdDescription,
},
title: {
type: "array",
description:
"An array of rich text objects that represents the title of the database that is displayed in the Notion UI.",
items: richTextObjectSchema,
},
description: {
type: "array",
description:
"An array of rich text objects that represents the description of the database that is displayed in the Notion UI.",
items: richTextObjectSchema,
},
properties: {
type: "object",
description:
"The properties of a database to be changed in the request, in the form of a JSON object.",
},
format: formatParameter,
},
required: ["database_id"],
},
};
const createDatabaseItemTool: Tool = {
name: "notion_create_database_item",
description: "Create a new item (page) in a Notion database",
inputSchema: {
type: "object",
properties: {
database_id: {
type: "string",
description:
"The ID of the database to add the item to." + commonIdDescription,
},
properties: {
type: "object",
description:
"Properties of the new database item. These should match the database schema.",
},
format: formatParameter,
},
required: ["database_id", "properties"],
},
};
// Comments
const createCommentTool: Tool = {
name: "notion_create_comment",
description:
"Create a comment in Notion. This requires the integration to have 'insert comment' capabilities. You can either specify a page parent or a discussion_id, but not both.",
inputSchema: {
type: "object",
properties: {
parent: {
type: "object",
description:
"Parent object that specifies the page to comment on. Must include a page_id if used.",
properties: {
page_id: {
type: "string",
description:
"The ID of the page to comment on." + commonIdDescription,
},
},
},
discussion_id: {
type: "string",
description:
"The ID of an existing discussion thread to add a comment to." +
commonIdDescription,
},
rich_text: {
type: "array",
description:
"Array of rich text objects representing the comment content.",
items: richTextObjectSchema,
},
format: formatParameter,
},
required: ["rich_text"],
},
};
const retrieveCommentsTool: Tool = {
name: "notion_retrieve_comments",
description:
"Retrieve a list of unresolved comments from a Notion page or block. Requires the integration to have 'read comment' capabilities.",
inputSchema: {
type: "object",
properties: {
block_id: {
type: "string",
description:
"The ID of the block or page whose comments you want to retrieve." +
commonIdDescription,
},
start_cursor: {
type: "string",
description:
"If supplied, returns a page of results starting after the cursor.",
},
page_size: {
type: "number",
description: "Number of comments to retrieve (max 100).",
},
format: formatParameter,
},
required: ["block_id"],
},
};
// Search
const searchTool: Tool = {
name: "notion_search",
description: "Search pages or databases by title in Notion",
inputSchema: {
type: "object",
properties: {
query: {
type: "string",
description: "Text to search for in page or database titles",
},
filter: {
type: "object",
description: "Filter results by object type (page or database)",
properties: {
property: {
type: "string",
description: "Must be 'object'",
},
value: {
type: "string",
description: "Either 'page' or 'database'",
},
},
},
sort: {
type: "object",
description: "Sort order of results",
properties: {
direction: {
type: "string",
enum: ["ascending", "descending"],
},
timestamp: {
type: "string",
enum: ["last_edited_time"],
},
},
},
start_cursor: {
type: "string",
description: "Pagination start cursor",
},
page_size: {
type: "number",
description: "Number of results to return (max 100). ",
},
format: formatParameter,
},
},
};
export class NotionClientWrapper {
private notionToken: string;
private baseUrl: string = "https://api.notion.com/v1";
private headers: { [key: string]: string };
constructor(token: string) {
this.notionToken = token;
this.headers = {
Authorization: `Bearer ${this.notionToken}`,
"Content-Type": "application/json",
"Notion-Version": "2022-06-28",
};
}
async appendBlockChildren(
block_id: string,
children: Partial<BlockResponse>[]
): Promise<BlockResponse> {
const body = { children };
const response = await fetch(
`${this.baseUrl}/blocks/${block_id}/children`,
{
method: "PATCH",
headers: this.headers,
body: JSON.stringify(body),
}
);
return response.json();
}
async retrieveBlock(block_id: string): Promise<BlockResponse> {
const response = await fetch(`${this.baseUrl}/blocks/${block_id}`, {
method: "GET",
headers: this.headers,
});
return response.json();
}
async retrieveBlockChildren(
block_id: string,
start_cursor?: string,
page_size?: number
): Promise<ListResponse> {
const params = new URLSearchParams();
if (start_cursor) params.append("start_cursor", start_cursor);
if (page_size) params.append("page_size", page_size.toString());
const response = await fetch(
`${this.baseUrl}/blocks/${block_id}/children?${params}`,
{
method: "GET",
headers: this.headers,
}
);
return response.json();
}
async deleteBlock(block_id: string): Promise<BlockResponse> {
const response = await fetch(`${this.baseUrl}/blocks/${block_id}`, {
method: "DELETE",
headers: this.headers,
});
return response.json();
}
async updateBlock(block_id: string, block: Partial<BlockResponse>): Promise<BlockResponse> {
const response = await fetch(`${this.baseUrl}/blocks/${block_id}`, {
method: "PATCH",
headers: this.headers,
body: JSON.stringify(block),
});
return response.json();
}
async retrievePage(page_id: string): Promise<PageResponse> {
const response = await fetch(`${this.baseUrl}/pages/${page_id}`, {
method: "GET",
headers: this.headers,