@@ -83,6 +83,22 @@ const statics = {
8383 HttpsErrorCode,
8484} ;
8585
86+ function normalizeHttpsCallableTimeoutOptions ( options : HttpsCallableOptions ) : HttpsCallableOptions {
87+ if ( ! options . timeout ) {
88+ return options ;
89+ }
90+ if ( ! isNumber ( options . timeout ) ) {
91+ throw new Error ( 'HttpsCallableOptions.timeout expected a Number in milliseconds' ) ;
92+ }
93+ if ( isOther ) {
94+ return options ;
95+ }
96+ return {
97+ ...options ,
98+ timeout : options . timeout / 1000 ,
99+ } ;
100+ }
101+
86102let _id_functions_streaming_event = 0 ;
87103
88104class FirebaseFunctionsModule extends FirebaseModule {
@@ -278,13 +294,7 @@ class FirebaseFunctionsModule extends FirebaseModule {
278294 }
279295
280296 httpsCallable ( name : string , options : HttpsCallableOptions = { } ) {
281- if ( options . timeout ) {
282- if ( isNumber ( options . timeout ) ) {
283- options . timeout = options . timeout / 1000 ;
284- } else {
285- throw new Error ( 'HttpsCallableOptions.timeout expected a Number in milliseconds' ) ;
286- }
287- }
297+ const normalizedOptions = normalizeHttpsCallableTimeoutOptions ( options ) ;
288298
289299 const callableFunction = ( ( data ?: unknown ) => {
290300 const nativePromise = this . native . httpsCallable (
@@ -294,7 +304,7 @@ class FirebaseFunctionsModule extends FirebaseModule {
294304 {
295305 data,
296306 } ,
297- options ,
307+ normalizedOptions ,
298308 ) ;
299309 return nativePromise . catch ( ( nativeError : NativeError ) => {
300310 const { code, message, details } = nativeError . userInfo || { } ;
@@ -314,9 +324,9 @@ class FirebaseFunctionsModule extends FirebaseModule {
314324 streamOptions ?: HttpsCallableStreamOptions ,
315325 ) => {
316326 const platformOptions = ! isOther
317- ? options
327+ ? normalizedOptions
318328 : ( {
319- ...options ,
329+ ...normalizedOptions ,
320330 httpsCallableStreamOptions : streamOptions || { } ,
321331 } as CustomHttpsCallableOptions ) ;
322332 return this . _createStreamHandler ( listenerId => {
@@ -335,13 +345,7 @@ class FirebaseFunctionsModule extends FirebaseModule {
335345 }
336346
337347 httpsCallableFromUrl ( url : string , options : HttpsCallableOptions = { } ) {
338- if ( options . timeout ) {
339- if ( isNumber ( options . timeout ) ) {
340- options . timeout = options . timeout / 1000 ;
341- } else {
342- throw new Error ( 'HttpsCallableOptions.timeout expected a Number in milliseconds' ) ;
343- }
344- }
348+ const normalizedOptions = normalizeHttpsCallableTimeoutOptions ( options ) ;
345349
346350 const callableFunction = ( ( data ?: unknown ) => {
347351 const nativePromise = this . native . httpsCallableFromUrl (
@@ -351,7 +355,7 @@ class FirebaseFunctionsModule extends FirebaseModule {
351355 {
352356 data,
353357 } ,
354- options ,
358+ normalizedOptions ,
355359 ) ;
356360 return nativePromise . catch ( ( nativeError : NativeError ) => {
357361 const { code, message, details } = nativeError . userInfo || { } ;
@@ -371,9 +375,9 @@ class FirebaseFunctionsModule extends FirebaseModule {
371375 streamOptions ?: HttpsCallableStreamOptions ,
372376 ) => {
373377 const platformOptions = ! isOther
374- ? options
378+ ? normalizedOptions
375379 : ( {
376- ...options ,
380+ ...normalizedOptions ,
377381 httpsCallableStreamOptions : streamOptions || { } ,
378382 } as CustomHttpsCallableOptions ) ;
379383 return this . _createStreamHandler ( listenerId => {
0 commit comments