11import { Contents , RestContentProvider } from '@jupyterlab/services' ;
22import { transformDeepnoteYamlToNotebookContent } from './transform-deepnote-yaml-to-notebook-content' ;
33import { requestAPI } from './handler' ;
4+ import { z } from 'zod' ;
45
56export const deepnoteContentProviderName = 'deepnote-content-provider' ;
7+
8+ const deepnoteFileResponseSchema = z . object ( {
9+ deepnoteFileModel : z . object ( {
10+ name : z . string ( ) ,
11+ path : z . string ( ) ,
12+ created : z . string ( ) ,
13+ last_modified : z . string ( ) ,
14+ content : z . string ( ) ,
15+ mimetype : z . string ( ) . optional ( )
16+ } )
17+ } ) ;
18+
619export class DeepnoteContentProvider extends RestContentProvider {
720 async get (
821 localPath : string ,
@@ -17,24 +30,13 @@ export class DeepnoteContentProvider extends RestContentProvider {
1730 }
1831
1932 // Call custom API route to fetch the Deepnote file content
20- let data : any ;
21-
22- try {
23- data = await requestAPI < any > (
24- `file?path=${ encodeURIComponent ( localPath ) } `
25- ) ;
26- } catch ( error ) {
27- console . error ( `Failed to fetch Deepnote file: ${ localPath } ` , error ) ;
28- throw new Error ( `Failed to fetch .deepnote file: ${ error } ` ) ;
33+ const data = await requestAPI ( `file?path=${ encodeURIComponent ( localPath ) } ` ) ;
34+ const parsed = deepnoteFileResponseSchema . safeParse ( data ) ;
35+ if ( ! parsed . success ) {
36+ console . error ( 'Invalid API response shape' , parsed . error ) ;
37+ throw new Error ( 'Invalid API response shape' ) ;
2938 }
30-
31- if ( ! data . deepnoteFileModel ) {
32- throw new Error (
33- `Invalid API response: missing deepnoteFileModel for ${ localPath } `
34- ) ;
35- }
36-
37- const modelData = data . deepnoteFileModel ;
39+ const modelData = parsed . data . deepnoteFileModel ;
3840
3941 // Transform the Deepnote YAML to Jupyter notebook content
4042 const notebookContent = await transformDeepnoteYamlToNotebookContent (
0 commit comments