@@ -205,51 +205,108 @@ export function createWebTool(
205205 destinationAuthentication : common . UserSession ,
206206) : Promise < any > {
207207 return new Promise < any > ( ( resolve , reject ) => {
208- if ( templateDictionary ?. portalUrls ?. notebooks . https . length > 0 ) {
209- const notebookUrl = templateDictionary . portalUrls . notebooks . https [ 0 ] ;
210- const url = `https://${ notebookUrl } /admin/services/createService?f=json&request.preventCache=${ Date . now ( ) } ` ;
211-
212- const params = {
213- serviceProperties : {
214- description : template . item . description ,
215- provider : "notebooks" ,
216- type : "GPServer" ,
217- jsonProperties : {
218- timeoutInMinutes : template . data . timeoutInMinutes ,
219- title : template . item . title ,
220- notebookId : template . data . notebookId ,
221- tasks : [
222- {
223- type : "notebook" ,
224- name : template . data . name ,
208+ getNotebookServerCreateServiceURL (
209+ templateDictionary . portalBaseUrl ,
210+ destinationAuthentication ,
211+ templateDictionary ,
212+ ) . then (
213+ ( url ) => {
214+ if ( url ) {
215+ const params = {
216+ serviceProperties : {
217+ description : template . item . description ,
218+ provider : "notebooks" ,
219+ type : "GPServer" ,
220+ jsonProperties : {
221+ timeoutInMinutes : template . data . timeoutInMinutes ,
222+ title : template . item . title ,
223+ notebookId : template . data . notebookId ,
224+ tasks : [
225+ {
226+ type : "notebook" ,
227+ name : template . data . name ,
228+ } ,
229+ ] ,
225230 } ,
226- ] ,
227- } ,
228- } ,
229- } ;
230-
231- const requestOptions = {
232- httpMethod : "POST" ,
233- authentication : destinationAuthentication ,
234- params,
235- headers : {
236- "Accept" : "application/json" ,
237- "Authorization" : `Bearer ${ destinationAuthentication . token } ` ,
238- "Content-Type" : "application/json" ,
239- "X-Esri-Authorization" : `Bearer ${ destinationAuthentication . token } ` ,
240- } ,
241- } as common . IRequestOptions ;
231+ } ,
232+ } ;
242233
243- common . request ( url , requestOptions ) . then (
244- ( response ) => {
245- resolve ( response ) ;
246- } ,
247- ( e ) => {
248- reject ( e ) ;
249- } ,
250- ) ;
251- } else {
252- reject ( ) ;
253- }
234+ const requestOptions = {
235+ httpMethod : "POST" ,
236+ authentication : destinationAuthentication ,
237+ params,
238+ headers : {
239+ "Accept" : "application/json" ,
240+ "Authorization" : `Bearer ${ destinationAuthentication . token } ` ,
241+ "Content-Type" : "application/json" ,
242+ "X-Esri-Authorization" : `Bearer ${ destinationAuthentication . token } ` ,
243+ } ,
244+ } as common . IRequestOptions ;
245+
246+ common . request ( url , requestOptions ) . then (
247+ ( response ) => {
248+ resolve ( response ) ;
249+ } ,
250+ ( e ) => {
251+ reject ( e ) ;
252+ } ,
253+ ) ;
254+ } else {
255+ reject ( ) ;
256+ }
257+ } ,
258+ ( e ) => {
259+ reject ( e ) ;
260+ } ,
261+ ) ;
254262 } ) ;
255263}
264+
265+ /**
266+ * Get the URL for the Notebook server in Enterprise.
267+ *
268+ * @param portalBaseUrl URL of the portal endpoint, e.g., "https://gisserver.domain.com/server"
269+ * @param authentication Credentials for the request to AGO
270+ * @returns URL for the Notebook server Enterprise application (e.g., "https://abc123.esri.com:6443/gis"),
271+ * or an empty string if Notebook server is not installed
272+ */
273+ export async function getNotebookServerCreateServiceURL (
274+ portalBaseUrl : string ,
275+ authentication : common . UserSession ,
276+ templateDictionary : any ,
277+ ) : Promise < string > {
278+ const notebookUrl = templateDictionary . isPortal
279+ ? await getNotebookEnterpriseServerRootURL ( portalBaseUrl , authentication )
280+ : templateDictionary . portalUrls ?. notebooks . https . length > 0
281+ ? templateDictionary . portalUrls . notebooks . https [ 0 ]
282+ : "" ;
283+
284+ return notebookUrl && templateDictionary . isPortal
285+ ? `${ notebookUrl } /admin/services/createService?f=json&request.preventCache=${ Date . now ( ) } `
286+ : notebookUrl
287+ ? `https://${ notebookUrl } /admin/services/createService?f=json&request.preventCache=${ Date . now ( ) } `
288+ : "" ;
289+ }
290+
291+ /**
292+ * Get the URL for the Notebook server in Enterprise.
293+ *
294+ * @param portalBaseUrl URL of the portal endpoint, e.g., "https://gisserver.domain.com/server"
295+ * @param authentication Credentials for the request to AGO
296+ * @returns URL for the Notebook server Enterprise application (e.g., "https://abc123.esri.com:6443/gis"),
297+ * or an empty string if Notebook server is not installed
298+ */
299+ export async function getNotebookEnterpriseServerRootURL (
300+ portalBaseUrl : string ,
301+ authentication : common . UserSession ,
302+ ) : Promise < string > {
303+ // Get the servers
304+ const servers = await common . getEnterpriseServers ( `${ portalBaseUrl } /sharing/rest` , authentication ) ;
305+
306+ // Find the Notebook server
307+ const notebookServer = servers . find ( ( s : any ) => s . serverFunction . indexOf ( "NotebookServer" ) > - 1 ) ;
308+ if ( ! notebookServer ) {
309+ return "" ;
310+ }
311+ return notebookServer . url as string ;
312+ }
0 commit comments