UNPKG

4.17 kBTypeScriptView Raw
1/**
2 * The namespace for ServerConnection functions.
3 *
4 * #### Notes
5 * This is only intended to manage communication with the Jupyter server.
6 *
7 * The default values can be used in a JupyterLab or Jupyter Notebook context.
8 *
9 * We use `token` authentication if available, falling back on an XSRF
10 * cookie if one has been provided on the `document`.
11 *
12 * A content type of `'application/json'` is added when using authentication
13 * and there is no body data to allow the server to prevent malicious forms.
14 */
15export declare namespace ServerConnection {
16 /**
17 * A Jupyter server settings object.
18 * Note that all of the settings are optional when passed to
19 * [[makeSettings]]. The default settings are given in [[defaultSettings]].
20 */
21 interface ISettings {
22 /**
23 * The base url of the server.
24 */
25 readonly baseUrl: string;
26 /**
27 * The app url of the JupyterLab application.
28 */
29 readonly appUrl: string;
30 /**
31 * The base ws url of the server.
32 */
33 readonly wsUrl: string;
34 /**
35 * The default request init options.
36 */
37 readonly init: RequestInit;
38 /**
39 * The authentication token for requests. Use an empty string to disable.
40 */
41 readonly token: string;
42 /**
43 * Whether to append a token to a Websocket url. The default is `false` in the browser
44 * and `true` in node or jest.
45 */
46 readonly appendToken: boolean;
47 /**
48 * The `fetch` method to use.
49 */
50 readonly fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
51 /**
52 * The `Request` object constructor.
53 */
54 readonly Request: typeof Request;
55 /**
56 * The `Headers` object constructor.
57 */
58 readonly Headers: typeof Headers;
59 /**
60 * The `WebSocket` object constructor.
61 */
62 readonly WebSocket: typeof WebSocket;
63 }
64 /**
65 * Create a settings object given a subset of options.
66 *
67 * @param options - An optional partial set of options.
68 *
69 * @returns The full settings object.
70 */
71 function makeSettings(options?: Partial<ISettings>): ISettings;
72 /**
73 * Make an request to the notebook server.
74 *
75 * @param url - The url for the request.
76 *
77 * @param init - The initialization options for the request.
78 *
79 * @param settings - The server settings to apply to the request.
80 *
81 * @returns a Promise that resolves with the response.
82 *
83 * @throws If the url of the request is not a notebook server url.
84 *
85 * #### Notes
86 * The `url` must start with `settings.baseUrl`. The `init` settings are
87 * merged with `settings.init`, with `init` taking precedence.
88 * The headers in the two objects are not merged.
89 * If there is no body data, we set the content type to `application/json`
90 * because it is required by the Notebook server.
91 */
92 function makeRequest(url: string, init: RequestInit, settings: ISettings): Promise<Response>;
93 /**
94 * A wrapped error for a fetch response.
95 */
96 class ResponseError extends Error {
97 /**
98 * Create a ResponseError from a response, handling the traceback and message
99 * as appropriate.
100 *
101 * @param response The response object.
102 *
103 * @returns A promise that resolves with a `ResponseError` object.
104 */
105 static create(response: Response): Promise<ResponseError>;
106 /**
107 * Create a new response error.
108 */
109 constructor(response: Response, message?: string, traceback?: string);
110 /**
111 * The response associated with the error.
112 */
113 response: Response;
114 /**
115 * The traceback associated with the error.
116 */
117 traceback: string;
118 }
119 /**
120 * A wrapped error for a network error.
121 */
122 class NetworkError extends TypeError {
123 /**
124 * Create a new network error.
125 */
126 constructor(original: TypeError);
127 }
128}