@@ -83,6 +83,24 @@ const statics = {
8383 HttpsErrorCode,
8484} ;
8585
86+ function normalizeHttpsCallableTimeoutOptions (
87+ options : HttpsCallableOptions ,
88+ ) : HttpsCallableOptions {
89+ if ( ! options . timeout ) {
90+ return options ;
91+ }
92+ if ( ! isNumber ( options . timeout ) ) {
93+ throw new Error ( 'HttpsCallableOptions.timeout expected a Number in milliseconds' ) ;
94+ }
95+ if ( isOther ) {
96+ return options ;
97+ }
98+ return {
99+ ...options ,
100+ timeout : options . timeout / 1000 ,
101+ } ;
102+ }
103+
86104let _id_functions_streaming_event = 0 ;
87105
88106class FirebaseFunctionsModule extends FirebaseModule {
@@ -278,13 +296,7 @@ class FirebaseFunctionsModule extends FirebaseModule {
278296 }
279297
280298 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- }
299+ const normalizedOptions = normalizeHttpsCallableTimeoutOptions ( options ) ;
288300
289301 const callableFunction = ( ( data ?: unknown ) => {
290302 const nativePromise = this . native . httpsCallable (
@@ -294,7 +306,7 @@ class FirebaseFunctionsModule extends FirebaseModule {
294306 {
295307 data,
296308 } ,
297- options ,
309+ normalizedOptions ,
298310 ) ;
299311 return nativePromise . catch ( ( nativeError : NativeError ) => {
300312 const { code, message, details } = nativeError . userInfo || { } ;
@@ -314,9 +326,9 @@ class FirebaseFunctionsModule extends FirebaseModule {
314326 streamOptions ?: HttpsCallableStreamOptions ,
315327 ) => {
316328 const platformOptions = ! isOther
317- ? options
329+ ? normalizedOptions
318330 : ( {
319- ...options ,
331+ ...normalizedOptions ,
320332 httpsCallableStreamOptions : streamOptions || { } ,
321333 } as CustomHttpsCallableOptions ) ;
322334 return this . _createStreamHandler ( listenerId => {
@@ -335,13 +347,7 @@ class FirebaseFunctionsModule extends FirebaseModule {
335347 }
336348
337349 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- }
350+ const normalizedOptions = normalizeHttpsCallableTimeoutOptions ( options ) ;
345351
346352 const callableFunction = ( ( data ?: unknown ) => {
347353 const nativePromise = this . native . httpsCallableFromUrl (
@@ -351,7 +357,7 @@ class FirebaseFunctionsModule extends FirebaseModule {
351357 {
352358 data,
353359 } ,
354- options ,
360+ normalizedOptions ,
355361 ) ;
356362 return nativePromise . catch ( ( nativeError : NativeError ) => {
357363 const { code, message, details } = nativeError . userInfo || { } ;
@@ -371,9 +377,9 @@ class FirebaseFunctionsModule extends FirebaseModule {
371377 streamOptions ?: HttpsCallableStreamOptions ,
372378 ) => {
373379 const platformOptions = ! isOther
374- ? options
380+ ? normalizedOptions
375381 : ( {
376- ...options ,
382+ ...normalizedOptions ,
377383 httpsCallableStreamOptions : streamOptions || { } ,
378384 } as CustomHttpsCallableOptions ) ;
379385 return this . _createStreamHandler ( listenerId => {
0 commit comments