@project-ajax/sdk 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +22 -0
  2. package/dist/block.d.ts +321 -0
  3. package/dist/block.d.ts.map +1 -0
  4. package/dist/block.js +0 -0
  5. package/dist/builder.d.ts +12 -0
  6. package/dist/builder.d.ts.map +1 -0
  7. package/dist/builder.js +22 -0
  8. package/dist/capabilities/slashCommand.d.ts +56 -0
  9. package/dist/capabilities/slashCommand.d.ts.map +1 -0
  10. package/dist/capabilities/slashCommand.js +32 -0
  11. package/dist/capabilities/sync.d.ts +58 -0
  12. package/dist/capabilities/sync.d.ts.map +1 -0
  13. package/dist/capabilities/sync.js +26 -0
  14. package/dist/capabilities/tool.d.ts +69 -0
  15. package/dist/capabilities/tool.d.ts.map +1 -0
  16. package/dist/capabilities/tool.js +75 -0
  17. package/dist/capabilities/tool.test.d.ts +2 -0
  18. package/dist/capabilities/tool.test.d.ts.map +1 -0
  19. package/dist/cli/api/client.d.ts +185 -0
  20. package/dist/cli/api/client.d.ts.map +1 -0
  21. package/dist/cli/api/client.js +315 -0
  22. package/dist/cli/api/result.d.ts +43 -0
  23. package/dist/cli/api/result.d.ts.map +1 -0
  24. package/dist/cli/api/result.js +43 -0
  25. package/dist/cli/bin/cli.d.ts +3 -0
  26. package/dist/cli/bin/cli.d.ts.map +1 -0
  27. package/dist/cli/bin/cli.js +5 -0
  28. package/dist/cli/commands/auth.d.ts +2 -0
  29. package/dist/cli/commands/auth.d.ts.map +1 -0
  30. package/dist/cli/commands/auth.impl.d.ts +10 -0
  31. package/dist/cli/commands/auth.impl.d.ts.map +1 -0
  32. package/dist/cli/commands/auth.impl.js +68 -0
  33. package/dist/cli/commands/auth.js +71 -0
  34. package/dist/cli/commands/bundle.d.ts +2 -0
  35. package/dist/cli/commands/bundle.d.ts.map +1 -0
  36. package/dist/cli/commands/bundle.impl.d.ts +2 -0
  37. package/dist/cli/commands/bundle.impl.d.ts.map +1 -0
  38. package/dist/cli/commands/bundle.impl.js +21 -0
  39. package/dist/cli/commands/bundle.js +23 -0
  40. package/dist/cli/commands/capabilities.d.ts +2 -0
  41. package/dist/cli/commands/capabilities.d.ts.map +1 -0
  42. package/dist/cli/commands/capabilities.impl.d.ts +3 -0
  43. package/dist/cli/commands/capabilities.impl.d.ts.map +1 -0
  44. package/dist/cli/commands/capabilities.impl.js +40 -0
  45. package/dist/cli/commands/capabilities.js +24 -0
  46. package/dist/cli/commands/deploy.d.ts +3 -0
  47. package/dist/cli/commands/deploy.d.ts.map +1 -0
  48. package/dist/cli/commands/deploy.impl.d.ts +2 -0
  49. package/dist/cli/commands/deploy.impl.d.ts.map +1 -0
  50. package/dist/cli/commands/deploy.impl.js +31 -0
  51. package/dist/cli/commands/deploy.js +16 -0
  52. package/dist/cli/commands/exec.d.ts +3 -0
  53. package/dist/cli/commands/exec.d.ts.map +1 -0
  54. package/dist/cli/commands/exec.impl.d.ts +7 -0
  55. package/dist/cli/commands/exec.impl.d.ts.map +1 -0
  56. package/dist/cli/commands/exec.impl.js +122 -0
  57. package/dist/cli/commands/exec.js +30 -0
  58. package/dist/cli/commands/runs.d.ts +2 -0
  59. package/dist/cli/commands/runs.d.ts.map +1 -0
  60. package/dist/cli/commands/runs.impl.d.ts +4 -0
  61. package/dist/cli/commands/runs.impl.d.ts.map +1 -0
  62. package/dist/cli/commands/runs.impl.js +71 -0
  63. package/dist/cli/commands/runs.js +45 -0
  64. package/dist/cli/commands/secrets.d.ts +2 -0
  65. package/dist/cli/commands/secrets.d.ts.map +1 -0
  66. package/dist/cli/commands/secrets.impl.d.ts +5 -0
  67. package/dist/cli/commands/secrets.impl.d.ts.map +1 -0
  68. package/dist/cli/commands/secrets.impl.js +93 -0
  69. package/dist/cli/commands/secrets.js +64 -0
  70. package/dist/cli/config.d.ts +38 -0
  71. package/dist/cli/config.d.ts.map +1 -0
  72. package/dist/cli/config.js +133 -0
  73. package/dist/cli/context.d.ts +15 -0
  74. package/dist/cli/context.d.ts.map +1 -0
  75. package/dist/cli/context.js +16 -0
  76. package/dist/cli/deploy.d.ts +25 -0
  77. package/dist/cli/deploy.d.ts.map +1 -0
  78. package/dist/cli/deploy.js +101 -0
  79. package/dist/cli/flags.d.ts +16 -0
  80. package/dist/cli/flags.d.ts.map +1 -0
  81. package/dist/cli/flags.js +24 -0
  82. package/dist/cli/handler.d.ts +14 -0
  83. package/dist/cli/handler.d.ts.map +1 -0
  84. package/dist/cli/handler.js +30 -0
  85. package/dist/cli/routes.d.ts +2 -0
  86. package/dist/cli/routes.d.ts.map +1 -0
  87. package/dist/cli/routes.js +44 -0
  88. package/dist/cli/utils/array.d.ts +2 -0
  89. package/dist/cli/utils/array.d.ts.map +1 -0
  90. package/dist/cli/utils/array.js +10 -0
  91. package/dist/cli/utils/string.d.ts +2 -0
  92. package/dist/cli/utils/string.d.ts.map +1 -0
  93. package/dist/cli/utils/string.js +12 -0
  94. package/dist/cli/writer.d.ts +48 -0
  95. package/dist/cli/writer.d.ts.map +1 -0
  96. package/dist/cli/writer.js +73 -0
  97. package/dist/error.d.ts +8 -0
  98. package/dist/error.d.ts.map +1 -0
  99. package/dist/error.js +11 -0
  100. package/dist/index.d.ts +4 -0
  101. package/dist/index.d.ts.map +1 -0
  102. package/dist/index.js +8 -0
  103. package/dist/schema.d.ts +45 -0
  104. package/dist/schema.d.ts.map +1 -0
  105. package/dist/schema.js +14 -0
  106. package/dist/types.d.ts +11 -0
  107. package/dist/types.d.ts.map +1 -0
  108. package/dist/types.js +0 -0
  109. package/package.json +79 -0
  110. package/src/block.ts +529 -0
  111. package/src/builder.ts +26 -0
  112. package/src/capabilities/slashCommand.ts +71 -0
  113. package/src/capabilities/sync.ts +76 -0
  114. package/src/capabilities/tool.test.ts +181 -0
  115. package/src/capabilities/tool.ts +145 -0
  116. package/src/cli/api/client.ts +588 -0
  117. package/src/cli/api/result.ts +71 -0
  118. package/src/cli/bin/cli.ts +7 -0
  119. package/src/cli/commands/auth.impl.ts +92 -0
  120. package/src/cli/commands/auth.ts +77 -0
  121. package/src/cli/commands/bundle.impl.ts +21 -0
  122. package/src/cli/commands/bundle.ts +23 -0
  123. package/src/cli/commands/capabilities.impl.ts +47 -0
  124. package/src/cli/commands/capabilities.ts +25 -0
  125. package/src/cli/commands/deploy.impl.ts +34 -0
  126. package/src/cli/commands/deploy.ts +16 -0
  127. package/src/cli/commands/exec.impl.ts +169 -0
  128. package/src/cli/commands/exec.ts +32 -0
  129. package/src/cli/commands/runs.impl.ts +87 -0
  130. package/src/cli/commands/runs.ts +49 -0
  131. package/src/cli/commands/secrets.impl.ts +124 -0
  132. package/src/cli/commands/secrets.ts +73 -0
  133. package/src/cli/config.ts +175 -0
  134. package/src/cli/context.ts +26 -0
  135. package/src/cli/deploy.ts +175 -0
  136. package/src/cli/flags.ts +43 -0
  137. package/src/cli/handler.ts +62 -0
  138. package/src/cli/routes.ts +43 -0
  139. package/src/cli/utils/array.ts +7 -0
  140. package/src/cli/utils/string.ts +9 -0
  141. package/src/cli/writer.ts +97 -0
  142. package/src/error.ts +12 -0
  143. package/src/index.ts +3 -0
  144. package/src/schema.ts +54 -0
  145. package/src/types.ts +10 -0
package/src/block.ts ADDED
@@ -0,0 +1,529 @@
1
+ // ============================================================================
2
+ // Block Type Definitions
3
+ // ============================================================================
4
+
5
+ // Color types
6
+ type ApiColor =
7
+ | "default"
8
+ | "gray"
9
+ | "brown"
10
+ | "orange"
11
+ | "yellow"
12
+ | "green"
13
+ | "blue"
14
+ | "purple"
15
+ | "pink"
16
+ | "red"
17
+ | "gray_background"
18
+ | "brown_background"
19
+ | "orange_background"
20
+ | "yellow_background"
21
+ | "green_background"
22
+ | "blue_background"
23
+ | "purple_background"
24
+ | "pink_background"
25
+ | "red_background";
26
+
27
+ // Rich text annotations
28
+ type RichTextAnnotations = {
29
+ bold: boolean;
30
+ italic: boolean;
31
+ strikethrough: boolean;
32
+ underline: boolean;
33
+ code: boolean;
34
+ color: ApiColor;
35
+ };
36
+
37
+ // Base rich text structure
38
+ type RichTextBase = {
39
+ plain_text: string;
40
+ href: string | null;
41
+ annotations: RichTextAnnotations;
42
+ };
43
+
44
+ // Text content
45
+ type TextContent = {
46
+ content: string;
47
+ link: { url: string } | null;
48
+ };
49
+
50
+ // Equation content
51
+ type EquationContent = {
52
+ expression: string;
53
+ };
54
+
55
+ // Date mention
56
+ type DateMention = {
57
+ type: "date";
58
+ date: {
59
+ start: string;
60
+ end?: string | null;
61
+ time_zone?: string | null;
62
+ };
63
+ };
64
+
65
+ // Custom emoji mention
66
+ type CustomEmojiMention = {
67
+ type: "custom_emoji";
68
+ custom_emoji: {
69
+ id: string;
70
+ name?: string;
71
+ url?: string;
72
+ };
73
+ };
74
+
75
+ // Link preview mention
76
+ type LinkPreviewMention = {
77
+ type: "link_preview";
78
+ link_preview: {
79
+ url: string;
80
+ };
81
+ };
82
+
83
+ // Link mention
84
+ type LinkMention = {
85
+ type: "link_mention";
86
+ link_mention: {
87
+ href: string;
88
+ };
89
+ };
90
+
91
+ // All mention types
92
+ type MentionContent =
93
+ | DateMention
94
+ | CustomEmojiMention
95
+ | LinkPreviewMention
96
+ | LinkMention;
97
+
98
+ // Rich text item
99
+ type RichTextItem = RichTextBase &
100
+ (
101
+ | { type: "text"; text: TextContent }
102
+ | { type: "mention"; mention: MentionContent }
103
+ | { type: "equation"; equation: EquationContent }
104
+ );
105
+
106
+ // Rich text array
107
+ type RichText = RichTextItem[];
108
+
109
+ // Icon types
110
+ type EmojiIcon = {
111
+ type: "emoji";
112
+ emoji: string;
113
+ };
114
+
115
+ type ExternalIcon = {
116
+ type: "external";
117
+ external: { url: string };
118
+ };
119
+
120
+ type FileIcon = {
121
+ type: "file";
122
+ file: {
123
+ url: string;
124
+ expiry_time: string;
125
+ };
126
+ };
127
+
128
+ type Icon = EmojiIcon | ExternalIcon | FileIcon;
129
+
130
+ // File object types
131
+ type ExternalFile = {
132
+ type: "external";
133
+ external: {
134
+ url: string;
135
+ };
136
+ };
137
+
138
+ type HostedFile = {
139
+ type: "file";
140
+ file: {
141
+ url: string;
142
+ expiry_time: string;
143
+ };
144
+ name?: string;
145
+ };
146
+
147
+ type FileObject = ExternalFile | HostedFile;
148
+
149
+ // Base block structure
150
+ type BlockBase = {
151
+ object: "block";
152
+ };
153
+
154
+ // Text blocks
155
+ type ParagraphBlock = BlockBase & {
156
+ type: "paragraph";
157
+ paragraph: {
158
+ rich_text: RichText;
159
+ color?: ApiColor;
160
+ children?: Block[];
161
+ };
162
+ };
163
+
164
+ type Heading1Block = BlockBase & {
165
+ type: "heading_1";
166
+ heading_1: {
167
+ rich_text: RichText;
168
+ color?: ApiColor;
169
+ is_toggleable?: boolean;
170
+ children?: Block[];
171
+ };
172
+ };
173
+
174
+ type Heading2Block = BlockBase & {
175
+ type: "heading_2";
176
+ heading_2: {
177
+ rich_text: RichText;
178
+ color?: ApiColor;
179
+ is_toggleable?: boolean;
180
+ children?: Block[];
181
+ };
182
+ };
183
+
184
+ type Heading3Block = BlockBase & {
185
+ type: "heading_3";
186
+ heading_3: {
187
+ rich_text: RichText;
188
+ color?: ApiColor;
189
+ is_toggleable?: boolean;
190
+ children?: Block[];
191
+ };
192
+ };
193
+
194
+ type BulletedListItemBlock = BlockBase & {
195
+ type: "bulleted_list_item";
196
+ bulleted_list_item: {
197
+ rich_text: RichText;
198
+ color?: ApiColor;
199
+ children?: Block[];
200
+ };
201
+ };
202
+
203
+ type NumberedListItemBlock = BlockBase & {
204
+ type: "numbered_list_item";
205
+ numbered_list_item: {
206
+ rich_text: RichText;
207
+ color?: ApiColor;
208
+ children?: Block[];
209
+ };
210
+ };
211
+
212
+ type ToDoBlock = BlockBase & {
213
+ type: "to_do";
214
+ to_do: {
215
+ rich_text: RichText;
216
+ checked: boolean;
217
+ color?: ApiColor;
218
+ children?: Block[];
219
+ };
220
+ };
221
+
222
+ type ToggleBlock = BlockBase & {
223
+ type: "toggle";
224
+ toggle: {
225
+ rich_text: RichText;
226
+ color?: ApiColor;
227
+ children?: Block[];
228
+ };
229
+ };
230
+
231
+ type QuoteBlock = BlockBase & {
232
+ type: "quote";
233
+ quote: {
234
+ rich_text: RichText;
235
+ color?: ApiColor;
236
+ children?: Block[];
237
+ };
238
+ };
239
+
240
+ type CalloutBlock = BlockBase & {
241
+ type: "callout";
242
+ callout: {
243
+ rich_text: RichText;
244
+ icon?: Icon | null;
245
+ color?: ApiColor;
246
+ children?: Block[];
247
+ };
248
+ };
249
+
250
+ // Code block
251
+ type CodeBlock = BlockBase & {
252
+ type: "code";
253
+ code: {
254
+ rich_text: RichText;
255
+ caption?: RichText;
256
+ language: string;
257
+ };
258
+ };
259
+
260
+ // Equation block
261
+ type EquationBlock = BlockBase & {
262
+ type: "equation";
263
+ equation: {
264
+ expression: string;
265
+ };
266
+ };
267
+
268
+ // Divider block
269
+ type DividerBlock = BlockBase & {
270
+ type: "divider";
271
+ divider: Record<string, never>;
272
+ };
273
+
274
+ // Breadcrumb block
275
+ type BreadcrumbBlock = BlockBase & {
276
+ type: "breadcrumb";
277
+ breadcrumb: Record<string, never>;
278
+ };
279
+
280
+ // Table of contents block
281
+ type TableOfContentsBlock = BlockBase & {
282
+ type: "table_of_contents";
283
+ table_of_contents: {
284
+ color?: ApiColor;
285
+ };
286
+ };
287
+
288
+ // Column layout blocks
289
+ type ColumnListBlock = BlockBase & {
290
+ type: "column_list";
291
+ column_list: {
292
+ children: ColumnBlock[];
293
+ };
294
+ };
295
+
296
+ type ColumnBlock = BlockBase & {
297
+ type: "column";
298
+ column: {
299
+ children?: Block[];
300
+ };
301
+ };
302
+
303
+ // Media blocks
304
+ type ImageBlock = BlockBase & {
305
+ type: "image";
306
+ image: FileObject & {
307
+ caption?: RichText;
308
+ };
309
+ };
310
+
311
+ type VideoBlock = BlockBase & {
312
+ type: "video";
313
+ video: FileObject & {
314
+ caption?: RichText;
315
+ };
316
+ };
317
+
318
+ type AudioBlock = BlockBase & {
319
+ type: "audio";
320
+ audio: FileObject & {
321
+ caption?: RichText;
322
+ };
323
+ };
324
+
325
+ type PDFBlock = BlockBase & {
326
+ type: "pdf";
327
+ pdf: FileObject & {
328
+ caption?: RichText;
329
+ };
330
+ };
331
+
332
+ type FileBlock = BlockBase & {
333
+ type: "file";
334
+ file: FileObject & {
335
+ caption?: RichText;
336
+ };
337
+ };
338
+
339
+ // Embed and bookmark blocks
340
+ type EmbedBlock = BlockBase & {
341
+ type: "embed";
342
+ embed: {
343
+ url: string;
344
+ caption?: RichText;
345
+ };
346
+ };
347
+
348
+ type BookmarkBlock = BlockBase & {
349
+ type: "bookmark";
350
+ bookmark: {
351
+ url: string;
352
+ caption?: RichText;
353
+ };
354
+ };
355
+
356
+ // Link preview block
357
+ type LinkPreviewBlock = BlockBase & {
358
+ type: "link_preview";
359
+ link_preview: {
360
+ url: string;
361
+ };
362
+ };
363
+
364
+ // Reference blocks
365
+ type ChildPageBlock = BlockBase & {
366
+ type: "child_page";
367
+ child_page: {
368
+ title: string;
369
+ };
370
+ };
371
+
372
+ type ChildDatabaseBlock = BlockBase & {
373
+ type: "child_database";
374
+ child_database: {
375
+ title: string;
376
+ };
377
+ };
378
+
379
+ // type LinkToPageBlock = BlockBase & {
380
+ // type: "link_to_page"
381
+ // link_to_page:
382
+ // | { type: "page_id"; page_id: string }
383
+ // | { type: "database_id"; database_id: string }
384
+ // }
385
+
386
+ // // Synced block
387
+ // type SyncedBlock = BlockBase & {
388
+ // type: "synced_block"
389
+ // synced_block: {
390
+ // synced_from: {
391
+ // type: "block_id"
392
+ // block_id: string
393
+ // } | null
394
+ // children?: Block[]
395
+ // }
396
+ // }
397
+
398
+ // Template block
399
+ type TemplateBlock = BlockBase & {
400
+ type: "template";
401
+ template: {
402
+ rich_text: RichText;
403
+ children?: Block[];
404
+ };
405
+ };
406
+
407
+ // Table blocks
408
+ type TableBlock = BlockBase & {
409
+ type: "table";
410
+ table: {
411
+ table_width: number;
412
+ has_column_header: boolean;
413
+ has_row_header: boolean;
414
+ children: TableRowBlock[];
415
+ };
416
+ };
417
+
418
+ type TableRowBlock = BlockBase & {
419
+ type: "table_row";
420
+ table_row: {
421
+ cells: RichText[];
422
+ };
423
+ };
424
+
425
+ // AI block
426
+ type AIBlock = BlockBase & {
427
+ type: "ai_block";
428
+ ai_block: {
429
+ prompt?: string;
430
+ };
431
+ };
432
+
433
+ // Unsupported block
434
+ type UnsupportedBlock = BlockBase & {
435
+ type: "unsupported";
436
+ unsupported: Record<string, never>;
437
+ };
438
+
439
+ // All block types union
440
+ type Block =
441
+ | ParagraphBlock
442
+ | Heading1Block
443
+ | Heading2Block
444
+ | Heading3Block
445
+ | BulletedListItemBlock
446
+ | NumberedListItemBlock
447
+ | ToDoBlock
448
+ | ToggleBlock
449
+ | QuoteBlock
450
+ | CalloutBlock
451
+ | CodeBlock
452
+ | EquationBlock
453
+ | DividerBlock
454
+ | BreadcrumbBlock
455
+ | TableOfContentsBlock
456
+ | ColumnListBlock
457
+ | ColumnBlock
458
+ | ImageBlock
459
+ | VideoBlock
460
+ | AudioBlock
461
+ | PDFBlock
462
+ | FileBlock
463
+ | EmbedBlock
464
+ | BookmarkBlock
465
+ | LinkPreviewBlock
466
+ | ChildPageBlock
467
+ | ChildDatabaseBlock
468
+ | TemplateBlock
469
+ | TableBlock
470
+ | TableRowBlock
471
+ | AIBlock
472
+ | UnsupportedBlock;
473
+
474
+ // Export all types
475
+ export type {
476
+ RichText,
477
+ RichTextItem,
478
+ RichTextBase,
479
+ RichTextAnnotations,
480
+ TextContent,
481
+ EquationContent,
482
+ MentionContent,
483
+ DateMention,
484
+ CustomEmojiMention,
485
+ LinkPreviewMention,
486
+ LinkMention,
487
+ ApiColor,
488
+ Icon,
489
+ EmojiIcon,
490
+ ExternalIcon,
491
+ FileIcon,
492
+ FileObject,
493
+ ExternalFile,
494
+ HostedFile,
495
+ BlockBase,
496
+ ParagraphBlock,
497
+ Heading1Block,
498
+ Heading2Block,
499
+ Heading3Block,
500
+ BulletedListItemBlock,
501
+ NumberedListItemBlock,
502
+ ToDoBlock,
503
+ ToggleBlock,
504
+ QuoteBlock,
505
+ CalloutBlock,
506
+ CodeBlock,
507
+ EquationBlock,
508
+ DividerBlock,
509
+ BreadcrumbBlock,
510
+ TableOfContentsBlock,
511
+ ColumnListBlock,
512
+ ColumnBlock,
513
+ ImageBlock,
514
+ VideoBlock,
515
+ AudioBlock,
516
+ PDFBlock,
517
+ FileBlock,
518
+ EmbedBlock,
519
+ BookmarkBlock,
520
+ LinkPreviewBlock,
521
+ ChildPageBlock,
522
+ ChildDatabaseBlock,
523
+ TemplateBlock,
524
+ TableBlock,
525
+ TableRowBlock,
526
+ AIBlock,
527
+ UnsupportedBlock,
528
+ Block,
529
+ };
package/src/builder.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { TextValue } from "./types.js";
2
+
3
+ export function richText(content: string): TextValue {
4
+ return [[content]];
5
+ }
6
+
7
+ export function url(url: string): TextValue {
8
+ return [[url]];
9
+ }
10
+
11
+ export function title(content: string): TextValue {
12
+ return [[content]];
13
+ }
14
+
15
+ export function text(content: string): TextValue {
16
+ return [[content]];
17
+ }
18
+
19
+ /**
20
+ * Creates a link with custom display text
21
+ * @param displayText - The text to display
22
+ * @param url - The URL to link to
23
+ */
24
+ export function link(displayText: string, url: string): TextValue {
25
+ return [[displayText, [["a", url]]]];
26
+ }
@@ -0,0 +1,71 @@
1
+ import type { Block } from "../block.js";
2
+ import { ExecutionError } from "../error.js";
3
+
4
+ export type SlashCommandConfiguration = {
5
+ menuTitle: string;
6
+ menuDescription: string;
7
+ search: {
8
+ placeholder: string;
9
+ debounce: number;
10
+ };
11
+
12
+ /**
13
+ * A function that returns a list of items to display in the search results
14
+ * as well as the corresponding blocks to insert for each item should it be selected.
15
+ */
16
+ executeSearch: (searchQuery: string) => Promise<{
17
+ items: { title: string; description: string; id: string }[];
18
+ }>;
19
+ executeSelect: (selectedItemId: string) => Promise<Block[]>;
20
+ };
21
+
22
+ export type SlashCommandHandlerResult = {
23
+ menuTitle: string;
24
+ menuDescription: string;
25
+ search: {
26
+ placeholder: string;
27
+ debounce: number;
28
+ };
29
+ };
30
+
31
+ /**
32
+ * Creates a special handler for handling slash commands.
33
+ *
34
+ * @param slashCommandConfiguration - The configuration for the slash command.
35
+ * @returns A handler function that executes the slash command function, and passes data
36
+ * needed to complete the operation back to the platform.
37
+ */
38
+ export function slashCommand(
39
+ slashCommandConfiguration: SlashCommandConfiguration,
40
+ ) {
41
+ return {
42
+ _tag: "slashCommand",
43
+ config: {
44
+ menuTitle: slashCommandConfiguration.menuTitle,
45
+ menuDescription: slashCommandConfiguration.menuDescription,
46
+ search: slashCommandConfiguration.search,
47
+ },
48
+ async handleSearch(searchQuery: string) {
49
+ const result = await slashCommandConfiguration
50
+ .executeSearch(searchQuery)
51
+ .catch((err) => {
52
+ throw new ExecutionError(err);
53
+ });
54
+
55
+ process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
56
+
57
+ return result;
58
+ },
59
+ async handleSelect(selectedItemId: string) {
60
+ const result = await slashCommandConfiguration
61
+ .executeSelect(selectedItemId)
62
+ .catch((err) => {
63
+ throw new ExecutionError(err);
64
+ });
65
+
66
+ process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
67
+
68
+ return result;
69
+ },
70
+ };
71
+ }
@@ -0,0 +1,76 @@
1
+ import { ExecutionError } from "../error.js";
2
+ import type { PropertySchema, Schema } from "../schema.js";
3
+ import type { TextValue } from "../types.js";
4
+
5
+ /**
6
+ * An object representing a third-party record to be synced.
7
+ */
8
+ export type SyncedObject<PK extends string, S extends PropertySchema<PK>> = {
9
+ key: string;
10
+ properties: { [Property in keyof S]: TextValue };
11
+ };
12
+
13
+ /**
14
+ * A configuration object that enables synchronization between a data
15
+ * source and a third-party source.
16
+ */
17
+ export type SyncConfiguration<PK extends string, S extends Schema<PK>> = {
18
+ /**
19
+ * The property of the data source that maps to a "primary key" in the
20
+ * third-party data. This is used to match existing pages to
21
+ * records in the third-party service. Must be a property defined in the schema.
22
+ */
23
+ primaryKeyProperty: PK;
24
+
25
+ /**
26
+ * The schema defining the structure of properties in the collection.
27
+ */
28
+ schema: S;
29
+
30
+ /**
31
+ * A function that fetches the data to sync from the third-party service.
32
+ *
33
+ * For now, this function must return all of the data to be synced each time
34
+ * it's called. The runtime will handle diffing this against the data source
35
+ * and creating, updating, and deleting pages as necessary.
36
+ */
37
+ execute: () => Promise<SyncedObject<PK, PropertySchema<PK>>[]>;
38
+ };
39
+
40
+ export type SyncHandlerResult<PK extends string> = {
41
+ primaryKeyProperty: PK;
42
+ objects: SyncedObject<PK, PropertySchema<PK>>[];
43
+ };
44
+
45
+ /**
46
+ * Creates a special handler for syncing third-party data to a collection.
47
+ *
48
+ * @param syncConfiguration - The configuration for the sync.
49
+ * @returns A handler function that executes the sync function, and passes data
50
+ * needed to complete the sync back to the platform.
51
+ */
52
+ export function sync<PK extends string, S extends Schema<PK>>(
53
+ syncConfiguration: SyncConfiguration<PK, S>,
54
+ ) {
55
+ return {
56
+ _tag: "sync",
57
+ config: {
58
+ schema: syncConfiguration.schema,
59
+ },
60
+ async handler() {
61
+ const objects = await syncConfiguration.execute().catch((err) => {
62
+ throw new ExecutionError(err);
63
+ });
64
+
65
+ const result = {
66
+ schema: syncConfiguration.schema,
67
+ primaryKeyProperty: syncConfiguration.primaryKeyProperty,
68
+ objects,
69
+ };
70
+
71
+ process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
72
+
73
+ return result;
74
+ },
75
+ };
76
+ }