index.d.ts 383 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308
  1. /**
  2. * @license
  3. * Copyright 2021 Google LLC
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * <code>firebase</code> is a global namespace from which all Firebase
  19. * services are accessed.
  20. */
  21. declare namespace firebase {
  22. /**
  23. * @hidden
  24. */
  25. type NextFn<T> = (value: T) => void;
  26. /**
  27. * @hidden
  28. */
  29. type ErrorFn<E = Error> = (error: E) => void;
  30. /**
  31. * @hidden
  32. */
  33. type CompleteFn = () => void;
  34. /**
  35. * `FirebaseError` is a subclass of the standard JavaScript `Error` object. In
  36. * addition to a message string and stack trace, it contains a string code.
  37. */
  38. interface FirebaseError {
  39. /**
  40. * Error codes are strings using the following format: `"service/string-code"`.
  41. * Some examples include `"app/no-app"` and `"auth/user-not-found"`.
  42. *
  43. * While the message for a given error can change, the code will remain the same
  44. * between backward-compatible versions of the Firebase SDK.
  45. */
  46. code: string;
  47. /**
  48. * An explanatory message for the error that just occurred.
  49. *
  50. * This message is designed to be helpful to you, the developer. Because
  51. * it generally does not convey meaningful information to end users,
  52. * this message should not be displayed in your application.
  53. */
  54. message: string;
  55. /**
  56. * The name of the class of errors, which is `"FirebaseError"`.
  57. */
  58. name: 'FirebaseError';
  59. /**
  60. * A string value containing the execution backtrace when the error originally
  61. * occurred. This may not always be available.
  62. *
  63. * When it is available, this information can be sent to
  64. * {@link https://firebase.google.com/support/ Firebase Support} to help
  65. * explain the cause of an error.
  66. */
  67. stack?: string;
  68. }
  69. /**
  70. * @hidden
  71. */
  72. interface Observer<T, E = Error> {
  73. next: NextFn<T>;
  74. error: ErrorFn<E>;
  75. complete: CompleteFn;
  76. }
  77. /**
  78. * The JS SDK supports 5 log levels and also allows a user the ability to
  79. * silence the logs altogether.
  80. *
  81. * The order is as follows:
  82. * silent < debug < verbose < info < warn < error
  83. */
  84. type LogLevel = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent';
  85. /**
  86. * The current SDK version.
  87. */
  88. var SDK_VERSION: string;
  89. /**
  90. * Registers a library's name and version for platform logging purposes.
  91. * @param library Name of 1p or 3p library (e.g. firestore, angularfire)
  92. * @param version Current version of that library.
  93. * @param variant Bundle variant, e.g., node, rn, etc.
  94. */
  95. function registerVersion(
  96. library: string,
  97. version: string,
  98. variant?: string
  99. ): void;
  100. /**
  101. * Sets log level for all Firebase packages.
  102. *
  103. * All of the log types above the current log level are captured (i.e. if
  104. * you set the log level to `info`, errors are logged, but `debug` and
  105. * `verbose` logs are not).
  106. */
  107. function setLogLevel(logLevel: LogLevel): void;
  108. /**
  109. * Sets log handler for all Firebase packages.
  110. * @param logCallback An optional custom log handler that executes user code whenever
  111. * the Firebase SDK makes a logging call.
  112. */
  113. function onLog(
  114. logCallback: (callbackParams: {
  115. /**
  116. * Level of event logged.
  117. */
  118. level: LogLevel;
  119. /**
  120. * Any text from logged arguments joined into one string.
  121. */
  122. message: string;
  123. /**
  124. * The raw arguments passed to the log call.
  125. */
  126. args: any[];
  127. /**
  128. * A string indicating the name of the package that made the log call,
  129. * such as `@firebase/firestore`.
  130. */
  131. type: string;
  132. }) => void,
  133. options?: {
  134. /**
  135. * Threshhold log level. Only logs at or above this level trigger the `logCallback`
  136. * passed to `onLog`.
  137. */
  138. level: LogLevel;
  139. }
  140. ): void;
  141. /**
  142. * @hidden
  143. */
  144. type Unsubscribe = () => void;
  145. /**
  146. * A user account.
  147. */
  148. interface User extends firebase.UserInfo {
  149. /**
  150. * Deletes and signs out the user.
  151. *
  152. * <b>Important:</b> this is a security-sensitive operation that requires the
  153. * user to have recently signed in. If this requirement isn't met, ask the user
  154. * to authenticate again and then call
  155. * {@link firebase.User.reauthenticateWithCredential}.
  156. *
  157. * <h4>Error Codes</h4>
  158. * <dl>
  159. * <dt>auth/requires-recent-login</dt>
  160. * <dd>Thrown if the user's last sign-in time does not meet the security
  161. * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
  162. * resolve. This does not apply if the user is anonymous.</dd>
  163. * </dl>
  164. */
  165. delete(): Promise<void>;
  166. emailVerified: boolean;
  167. getIdTokenResult(
  168. forceRefresh?: boolean
  169. ): Promise<firebase.auth.IdTokenResult>;
  170. /**
  171. * Returns a JSON Web Token (JWT) used to identify the user to a Firebase
  172. * service.
  173. *
  174. * Returns the current token if it has not expired. Otherwise, this will
  175. * refresh the token and return a new one.
  176. *
  177. * @param forceRefresh Force refresh regardless of token
  178. * expiration.
  179. */
  180. getIdToken(forceRefresh?: boolean): Promise<string>;
  181. isAnonymous: boolean;
  182. /**
  183. * Links the user account with the given credentials and returns any available
  184. * additional user information, such as user name.
  185. *
  186. * <h4>Error Codes</h4>
  187. * <dl>
  188. * <dt>auth/provider-already-linked</dt>
  189. * <dd>Thrown if the provider has already been linked to the user. This error is
  190. * thrown even if this is not the same provider's account that is currently
  191. * linked to the user.</dd>
  192. * <dt>auth/invalid-credential</dt>
  193. * <dd>Thrown if the provider's credential is not valid. This can happen if it
  194. * has already expired when calling link, or if it used invalid token(s).
  195. * See the Firebase documentation for your provider, and make sure you pass
  196. * in the correct parameters to the credential method.</dd>
  197. * <dt>auth/credential-already-in-use</dt>
  198. * <dd>Thrown if the account corresponding to the credential already exists
  199. * among your users, or is already linked to a Firebase User.
  200. * For example, this error could be thrown if you are upgrading an anonymous
  201. * user to a Google user by linking a Google credential to it and the Google
  202. * credential used is already associated with an existing Firebase Google
  203. * user.
  204. * The fields <code>error.email</code>, <code>error.phoneNumber</code>, and
  205. * <code>error.credential</code> ({@link firebase.auth.AuthCredential})
  206. * may be provided, depending on the type of credential. You can recover
  207. * from this error by signing in with <code>error.credential</code> directly
  208. * via {@link firebase.auth.Auth.signInWithCredential}.</dd>
  209. * <dt>auth/email-already-in-use</dt>
  210. * <dd>Thrown if the email corresponding to the credential already exists
  211. * among your users. When thrown while linking a credential to an existing
  212. * user, an <code>error.email</code> and <code>error.credential</code>
  213. * ({@link firebase.auth.AuthCredential}) fields are also provided.
  214. * You have to link the credential to the existing user with that email if
  215. * you wish to continue signing in with that credential. To do so, call
  216. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
  217. * <code>error.email</code> via one of the providers returned and then
  218. * {@link firebase.User.linkWithCredential} the original credential to that
  219. * newly signed in user.</dd>
  220. * <dt>auth/operation-not-allowed</dt>
  221. * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
  222. * to the Firebase Console for your project, in the Auth section and the
  223. * <strong>Sign in Method</strong> tab and configure the provider.</dd>
  224. * <dt>auth/invalid-email</dt>
  225. * <dd>Thrown if the email used in a
  226. * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd>
  227. * <dt>auth/wrong-password</dt>
  228. * <dd>Thrown if the password used in a
  229. * {@link firebase.auth.EmailAuthProvider.credential} is not correct or
  230. * when the user associated with the email does not have a password.</dd>
  231. * <dt>auth/invalid-verification-code</dt>
  232. * <dd>Thrown if the credential is a
  233. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  234. * code of the credential is not valid.</dd>
  235. * <dt>auth/invalid-verification-id</dt>
  236. * <dd>Thrown if the credential is a
  237. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  238. * ID of the credential is not valid.</dd>
  239. * </dl>
  240. *
  241. * @deprecated This method is deprecated. Use
  242. * {@link firebase.User.linkWithCredential} instead.
  243. *
  244. * @param credential The auth credential.
  245. */
  246. linkAndRetrieveDataWithCredential(
  247. credential: firebase.auth.AuthCredential
  248. ): Promise<firebase.auth.UserCredential>;
  249. /**
  250. * Links the user account with the given credentials.
  251. *
  252. * <h4>Error Codes</h4>
  253. * <dl>
  254. * <dt>auth/provider-already-linked</dt>
  255. * <dd>Thrown if the provider has already been linked to the user. This error is
  256. * thrown even if this is not the same provider's account that is currently
  257. * linked to the user.</dd>
  258. * <dt>auth/invalid-credential</dt>
  259. * <dd>Thrown if the provider's credential is not valid. This can happen if it
  260. * has already expired when calling link, or if it used invalid token(s).
  261. * See the Firebase documentation for your provider, and make sure you pass
  262. * in the correct parameters to the credential method.</dd>
  263. * <dt>auth/credential-already-in-use</dt>
  264. * <dd>Thrown if the account corresponding to the credential already exists
  265. * among your users, or is already linked to a Firebase User.
  266. * For example, this error could be thrown if you are upgrading an anonymous
  267. * user to a Google user by linking a Google credential to it and the Google
  268. * credential used is already associated with an existing Firebase Google
  269. * user.
  270. * The fields <code>error.email</code>, <code>error.phoneNumber</code>, and
  271. * <code>error.credential</code> ({@link firebase.auth.AuthCredential})
  272. * may be provided, depending on the type of credential. You can recover
  273. * from this error by signing in with <code>error.credential</code> directly
  274. * via {@link firebase.auth.Auth.signInWithCredential}.</dd>
  275. * <dt>auth/email-already-in-use</dt>
  276. * <dd>Thrown if the email corresponding to the credential already exists
  277. * among your users. When thrown while linking a credential to an existing
  278. * user, an <code>error.email</code> and <code>error.credential</code>
  279. * ({@link firebase.auth.AuthCredential}) fields are also provided.
  280. * You have to link the credential to the existing user with that email if
  281. * you wish to continue signing in with that credential. To do so, call
  282. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
  283. * <code>error.email</code> via one of the providers returned and then
  284. * {@link firebase.User.linkWithCredential} the original credential to that
  285. * newly signed in user.</dd>
  286. * <dt>auth/operation-not-allowed</dt>
  287. * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
  288. * to the Firebase Console for your project, in the Auth section and the
  289. * <strong>Sign in Method</strong> tab and configure the provider.</dd>
  290. * <dt>auth/invalid-email</dt>
  291. * <dd>Thrown if the email used in a
  292. * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd>
  293. * <dt>auth/wrong-password</dt>
  294. * <dd>Thrown if the password used in a
  295. * {@link firebase.auth.EmailAuthProvider.credential} is not correct or
  296. * when the user associated with the email does not have a password.</dd>
  297. * <dt>auth/invalid-verification-code</dt>
  298. * <dd>Thrown if the credential is a
  299. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  300. * code of the credential is not valid.</dd>
  301. * <dt>auth/invalid-verification-id</dt>
  302. * <dd>Thrown if the credential is a
  303. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  304. * ID of the credential is not valid.</dd>
  305. * </dl>
  306. *
  307. * @param credential The auth credential.
  308. */
  309. linkWithCredential(
  310. credential: firebase.auth.AuthCredential
  311. ): Promise<firebase.auth.UserCredential>;
  312. /**
  313. * Links the user account with the given phone number.
  314. *
  315. * <h4>Error Codes</h4>
  316. * <dl>
  317. * <dt>auth/provider-already-linked</dt>
  318. * <dd>Thrown if the provider has already been linked to the user. This error is
  319. * thrown even if this is not the same provider's account that is currently
  320. * linked to the user.</dd>
  321. * <dt>auth/captcha-check-failed</dt>
  322. * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
  323. * this method was called from a non-whitelisted domain.</dd>
  324. * <dt>auth/invalid-phone-number</dt>
  325. * <dd>Thrown if the phone number has an invalid format.</dd>
  326. * <dt>auth/missing-phone-number</dt>
  327. * <dd>Thrown if the phone number is missing.</dd>
  328. * <dt>auth/quota-exceeded</dt>
  329. * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
  330. * <dt>auth/user-disabled</dt>
  331. * <dd>Thrown if the user corresponding to the given phone number has been
  332. * disabled.</dd>
  333. * <dt>auth/credential-already-in-use</dt>
  334. * <dd>Thrown if the account corresponding to the phone number already exists
  335. * among your users, or is already linked to a Firebase User.
  336. * The fields <code>error.phoneNumber</code> and
  337. * <code>error.credential</code> ({@link firebase.auth.AuthCredential})
  338. * are provided in this case. You can recover from this error by signing in
  339. * with that credential directly via
  340. * {@link firebase.auth.Auth.signInWithCredential}.</dd>
  341. * <dt>auth/operation-not-allowed</dt>
  342. * <dd>Thrown if you have not enabled the phone authentication provider in the
  343. * Firebase Console. Go to the Firebase Console for your project, in the
  344. * Auth section and the <strong>Sign in Method</strong> tab and configure
  345. * the provider.</dd>
  346. * </dl>
  347. *
  348. * @param phoneNumber The user's phone number in E.164 format (e.g.
  349. * +16505550101).
  350. * @param applicationVerifier
  351. */
  352. linkWithPhoneNumber(
  353. phoneNumber: string,
  354. applicationVerifier: firebase.auth.ApplicationVerifier
  355. ): Promise<firebase.auth.ConfirmationResult>;
  356. /**
  357. * Links the authenticated provider to the user account using a pop-up based
  358. * OAuth flow.
  359. *
  360. * If the linking is successful, the returned result will contain the user
  361. * and the provider's credential.
  362. *
  363. * <h4>Error Codes</h4>
  364. * <dl>
  365. * <dt>auth/auth-domain-config-required</dt>
  366. * <dd>Thrown if authDomain configuration is not provided when calling
  367. * firebase.initializeApp(). Check Firebase Console for instructions on
  368. * determining and passing that field.</dd>
  369. * <dt>auth/cancelled-popup-request</dt>
  370. * <dd>Thrown if successive popup operations are triggered. Only one popup
  371. * request is allowed at one time on a user or an auth instance. All the
  372. * popups would fail with this error except for the last one.</dd>
  373. * <dt>auth/credential-already-in-use</dt>
  374. * <dd>Thrown if the account corresponding to the credential already exists
  375. * among your users, or is already linked to a Firebase User.
  376. * For example, this error could be thrown if you are upgrading an anonymous
  377. * user to a Google user by linking a Google credential to it and the Google
  378. * credential used is already associated with an existing Firebase Google
  379. * user.
  380. * An <code>error.email</code> and <code>error.credential</code>
  381. * ({@link firebase.auth.AuthCredential}) fields are also provided. You can
  382. * recover from this error by signing in with that credential directly via
  383. * {@link firebase.auth.Auth.signInWithCredential}.</dd>
  384. * <dt>auth/email-already-in-use</dt>
  385. * <dd>Thrown if the email corresponding to the credential already exists
  386. * among your users. When thrown while linking a credential to an existing
  387. * user, an <code>error.email</code> and <code>error.credential</code>
  388. * ({@link firebase.auth.AuthCredential}) fields are also provided.
  389. * You have to link the credential to the existing user with that email if
  390. * you wish to continue signing in with that credential. To do so, call
  391. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
  392. * <code>error.email</code> via one of the providers returned and then
  393. * {@link firebase.User.linkWithCredential} the original credential to that
  394. * newly signed in user.</dd>
  395. * <dt>auth/operation-not-allowed</dt>
  396. * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
  397. * to the Firebase Console for your project, in the Auth section and the
  398. * <strong>Sign in Method</strong> tab and configure the provider.</dd>
  399. * <dt>auth/popup-blocked</dt>
  400. * <dt>auth/operation-not-supported-in-this-environment</dt>
  401. * <dd>Thrown if this operation is not supported in the environment your
  402. * application is running on. "location.protocol" must be http or https.
  403. * </dd>
  404. * <dd>Thrown if the popup was blocked by the browser, typically when this
  405. * operation is triggered outside of a click handler.</dd>
  406. * <dt>auth/popup-closed-by-user</dt>
  407. * <dd>Thrown if the popup window is closed by the user without completing the
  408. * sign in to the provider.</dd>
  409. * <dt>auth/provider-already-linked</dt>
  410. * <dd>Thrown if the provider has already been linked to the user. This error is
  411. * thrown even if this is not the same provider's account that is currently
  412. * linked to the user.</dd>
  413. * <dt>auth/unauthorized-domain</dt>
  414. * <dd>Thrown if the app domain is not authorized for OAuth operations for your
  415. * Firebase project. Edit the list of authorized domains from the Firebase
  416. * console.</dd>
  417. * </dl>
  418. *
  419. * This method does not work in a Node.js environment.
  420. *
  421. * @example
  422. * ```javascript
  423. * // Creates the provider object.
  424. * var provider = new firebase.auth.FacebookAuthProvider();
  425. * // You can add additional scopes to the provider:
  426. * provider.addScope('email');
  427. * provider.addScope('user_friends');
  428. * // Link with popup:
  429. * user.linkWithPopup(provider).then(function(result) {
  430. * // The firebase.User instance:
  431. * var user = result.user;
  432. * // The Facebook firebase.auth.AuthCredential containing the Facebook
  433. * // access token:
  434. * var credential = result.credential;
  435. * }, function(error) {
  436. * // An error happened.
  437. * });
  438. * ```
  439. *
  440. * @param provider The provider to authenticate.
  441. * The provider has to be an OAuth provider. Non-OAuth providers like {@link
  442. * firebase.auth.EmailAuthProvider} will throw an error.
  443. */
  444. linkWithPopup(
  445. provider: firebase.auth.AuthProvider
  446. ): Promise<firebase.auth.UserCredential>;
  447. /**
  448. * Links the authenticated provider to the user account using a full-page
  449. * redirect flow.
  450. *
  451. * <h4>Error Codes</h4>
  452. * <dl>
  453. * <dt>auth/auth-domain-config-required</dt>
  454. * <dd>Thrown if authDomain configuration is not provided when calling
  455. * firebase.initializeApp(). Check Firebase Console for instructions on
  456. * determining and passing that field.</dd>
  457. * <dt>auth/operation-not-supported-in-this-environment</dt>
  458. * <dd>Thrown if this operation is not supported in the environment your
  459. * application is running on. "location.protocol" must be http or https.
  460. * </dd>
  461. * <dt>auth/provider-already-linked</dt>
  462. * <dd>Thrown if the provider has already been linked to the user. This error is
  463. * thrown even if this is not the same provider's account that is currently
  464. * linked to the user.</dd>
  465. * <dt>auth/unauthorized-domain</dt>
  466. * <dd>Thrown if the app domain is not authorized for OAuth operations for your
  467. * Firebase project. Edit the list of authorized domains from the Firebase
  468. * console.</dd>
  469. * </dl>
  470. *
  471. * @param provider The provider to authenticate.
  472. * The provider has to be an OAuth provider. Non-OAuth providers like {@link
  473. * firebase.auth.EmailAuthProvider} will throw an error.
  474. */
  475. linkWithRedirect(provider: firebase.auth.AuthProvider): Promise<void>;
  476. metadata: firebase.auth.UserMetadata;
  477. /**
  478. * The {@link firebase.User.MultiFactorUser} object corresponding to the current user.
  479. * This is used to access all multi-factor properties and operations related to the
  480. * current user.
  481. */
  482. multiFactor: firebase.User.MultiFactorUser;
  483. /**
  484. * The phone number normalized based on the E.164 standard (e.g. +16505550101)
  485. * for the current user. This is null if the user has no phone credential linked
  486. * to the account.
  487. */
  488. phoneNumber: string | null;
  489. providerData: (firebase.UserInfo | null)[];
  490. /**
  491. * Re-authenticates a user using a fresh credential, and returns any available
  492. * additional user information, such as user name. Use before operations
  493. * such as {@link firebase.User.updatePassword} that require tokens from recent
  494. * sign-in attempts.
  495. *
  496. * <h4>Error Codes</h4>
  497. * <dl>
  498. * <dt>auth/user-mismatch</dt>
  499. * <dd>Thrown if the credential given does not correspond to the user.</dd>
  500. * <dt>auth/user-not-found</dt>
  501. * <dd>Thrown if the credential given does not correspond to any existing user.
  502. * </dd>
  503. * <dt>auth/invalid-credential</dt>
  504. * <dd>Thrown if the provider's credential is not valid. This can happen if it
  505. * has already expired when calling link, or if it used invalid token(s).
  506. * See the Firebase documentation for your provider, and make sure you pass
  507. * in the correct parameters to the credential method.</dd>
  508. * <dt>auth/invalid-email</dt>
  509. * <dd>Thrown if the email used in a
  510. * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd>
  511. * <dt>auth/wrong-password</dt>
  512. * <dd>Thrown if the password used in a
  513. * {@link firebase.auth.EmailAuthProvider.credential} is not correct or when
  514. * the user associated with the email does not have a password.</dd>
  515. * <dt>auth/invalid-verification-code</dt>
  516. * <dd>Thrown if the credential is a
  517. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  518. * code of the credential is not valid.</dd>
  519. * <dt>auth/invalid-verification-id</dt>
  520. * <dd>Thrown if the credential is a
  521. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  522. * ID of the credential is not valid.</dd>
  523. * </dl>
  524. *
  525. * @deprecated
  526. * This method is deprecated. Use
  527. * {@link firebase.User.reauthenticateWithCredential} instead.
  528. *
  529. * @param credential
  530. */
  531. reauthenticateAndRetrieveDataWithCredential(
  532. credential: firebase.auth.AuthCredential
  533. ): Promise<firebase.auth.UserCredential>;
  534. /**
  535. * Re-authenticates a user using a fresh credential. Use before operations
  536. * such as {@link firebase.User.updatePassword} that require tokens from recent
  537. * sign-in attempts.
  538. *
  539. * <h4>Error Codes</h4>
  540. * <dl>
  541. * <dt>auth/user-mismatch</dt>
  542. * <dd>Thrown if the credential given does not correspond to the user.</dd>
  543. * <dt>auth/user-not-found</dt>
  544. * <dd>Thrown if the credential given does not correspond to any existing user.
  545. * </dd>
  546. * <dt>auth/invalid-credential</dt>
  547. * <dd>Thrown if the provider's credential is not valid. This can happen if it
  548. * has already expired when calling link, or if it used invalid token(s).
  549. * See the Firebase documentation for your provider, and make sure you pass
  550. * in the correct parameters to the credential method.</dd>
  551. * <dt>auth/invalid-email</dt>
  552. * <dd>Thrown if the email used in a
  553. * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd>
  554. * <dt>auth/wrong-password</dt>
  555. * <dd>Thrown if the password used in a
  556. * {@link firebase.auth.EmailAuthProvider.credential} is not correct or when
  557. * the user associated with the email does not have a password.</dd>
  558. * <dt>auth/invalid-verification-code</dt>
  559. * <dd>Thrown if the credential is a
  560. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  561. * code of the credential is not valid.</dd>
  562. * <dt>auth/invalid-verification-id</dt>
  563. * <dd>Thrown if the credential is a
  564. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  565. * ID of the credential is not valid.</dd>
  566. * </dl>
  567. *
  568. * @param credential
  569. */
  570. reauthenticateWithCredential(
  571. credential: firebase.auth.AuthCredential
  572. ): Promise<firebase.auth.UserCredential>;
  573. /**
  574. * Re-authenticates a user using a fresh credential. Use before operations
  575. * such as {@link firebase.User.updatePassword} that require tokens from recent
  576. * sign-in attempts.
  577. *
  578. * <h4>Error Codes</h4>
  579. * <dl>
  580. * <dt>auth/user-mismatch</dt>
  581. * <dd>Thrown if the credential given does not correspond to the user.</dd>
  582. * <dt>auth/user-not-found</dt>
  583. * <dd>Thrown if the credential given does not correspond to any existing user.
  584. * </dd>
  585. * <dt>auth/captcha-check-failed</dt>
  586. * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
  587. * this method was called from a non-whitelisted domain.</dd>
  588. * <dt>auth/invalid-phone-number</dt>
  589. * <dd>Thrown if the phone number has an invalid format.</dd>
  590. * <dt>auth/missing-phone-number</dt>
  591. * <dd>Thrown if the phone number is missing.</dd>
  592. * <dt>auth/quota-exceeded</dt>
  593. * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
  594. * </dl>
  595. *
  596. * @param phoneNumber The user's phone number in E.164 format (e.g.
  597. * +16505550101).
  598. * @param applicationVerifier
  599. */
  600. reauthenticateWithPhoneNumber(
  601. phoneNumber: string,
  602. applicationVerifier: firebase.auth.ApplicationVerifier
  603. ): Promise<firebase.auth.ConfirmationResult>;
  604. /**
  605. * Reauthenticates the current user with the specified provider using a pop-up
  606. * based OAuth flow.
  607. *
  608. * If the reauthentication is successful, the returned result will contain the
  609. * user and the provider's credential.
  610. *
  611. * <h4>Error Codes</h4>
  612. * <dl>
  613. * <dt>auth/auth-domain-config-required</dt>
  614. * <dd>Thrown if authDomain configuration is not provided when calling
  615. * firebase.initializeApp(). Check Firebase Console for instructions on
  616. * determining and passing that field.</dd>
  617. * <dt>auth/cancelled-popup-request</dt>
  618. * <dd>Thrown if successive popup operations are triggered. Only one popup
  619. * request is allowed at one time on a user or an auth instance. All the
  620. * popups would fail with this error except for the last one.</dd>
  621. * <dt>auth/user-mismatch</dt>
  622. * <dd>Thrown if the credential given does not correspond to the user.</dd>
  623. * <dt>auth/operation-not-allowed</dt>
  624. * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
  625. * to the Firebase Console for your project, in the Auth section and the
  626. * <strong>Sign in Method</strong> tab and configure the provider.</dd>
  627. * <dt>auth/popup-blocked</dt>
  628. * <dd>Thrown if the popup was blocked by the browser, typically when this
  629. * operation is triggered outside of a click handler.</dd>
  630. * <dt>auth/operation-not-supported-in-this-environment</dt>
  631. * <dd>Thrown if this operation is not supported in the environment your
  632. * application is running on. "location.protocol" must be http or https.
  633. * </dd>
  634. * <dt>auth/popup-closed-by-user</dt>
  635. * <dd>Thrown if the popup window is closed by the user without completing the
  636. * sign in to the provider.</dd>
  637. * <dt>auth/unauthorized-domain</dt>
  638. * <dd>Thrown if the app domain is not authorized for OAuth operations for your
  639. * Firebase project. Edit the list of authorized domains from the Firebase
  640. * console.</dd>
  641. * </dl>
  642. *
  643. * This method does not work in a Node.js environment.
  644. *
  645. * @example
  646. * ```javascript
  647. * // Creates the provider object.
  648. * var provider = new firebase.auth.FacebookAuthProvider();
  649. * // You can add additional scopes to the provider:
  650. * provider.addScope('email');
  651. * provider.addScope('user_friends');
  652. * // Reauthenticate with popup:
  653. * user.reauthenticateWithPopup(provider).then(function(result) {
  654. * // The firebase.User instance:
  655. * var user = result.user;
  656. * // The Facebook firebase.auth.AuthCredential containing the Facebook
  657. * // access token:
  658. * var credential = result.credential;
  659. * }, function(error) {
  660. * // An error happened.
  661. * });
  662. * ```
  663. *
  664. * @param provider The provider to authenticate.
  665. * The provider has to be an OAuth provider. Non-OAuth providers like {@link
  666. * firebase.auth.EmailAuthProvider} will throw an error.
  667. */
  668. reauthenticateWithPopup(
  669. provider: firebase.auth.AuthProvider
  670. ): Promise<firebase.auth.UserCredential>;
  671. /**
  672. * Reauthenticates the current user with the specified OAuth provider using a
  673. * full-page redirect flow.
  674. *
  675. * <h4>Error Codes</h4>
  676. * <dl>
  677. * <dt>auth/auth-domain-config-required</dt>
  678. * <dd>Thrown if authDomain configuration is not provided when calling
  679. * firebase.initializeApp(). Check Firebase Console for instructions on
  680. * determining and passing that field.</dd>
  681. * <dt>auth/operation-not-supported-in-this-environment</dt>
  682. * <dd>Thrown if this operation is not supported in the environment your
  683. * application is running on. "location.protocol" must be http or https.
  684. * </dd>
  685. * <dt>auth/user-mismatch</dt>
  686. * <dd>Thrown if the credential given does not correspond to the user.</dd>
  687. * <dt>auth/unauthorized-domain</dt>
  688. * <dd>Thrown if the app domain is not authorized for OAuth operations for your
  689. * Firebase project. Edit the list of authorized domains from the Firebase
  690. * console.</dd>
  691. * </dl>
  692. *
  693. * This method does not work in a Node.js environment.
  694. *
  695. * @param provider The provider to authenticate.
  696. * The provider has to be an OAuth provider. Non-OAuth providers like {@link
  697. * firebase.auth.EmailAuthProvider} will throw an error.
  698. */
  699. reauthenticateWithRedirect(
  700. provider: firebase.auth.AuthProvider
  701. ): Promise<void>;
  702. refreshToken: string;
  703. /**
  704. * Refreshes the current user, if signed in.
  705. *
  706. */
  707. reload(): Promise<void>;
  708. /**
  709. * Sends a verification email to a user.
  710. *
  711. * The verification process is completed by calling
  712. * {@link firebase.auth.Auth.applyActionCode}
  713. *
  714. * <h4>Error Codes</h4>
  715. * <dl>
  716. * <dt>auth/missing-android-pkg-name</dt>
  717. * <dd>An Android package name must be provided if the Android app is required
  718. * to be installed.</dd>
  719. * <dt>auth/missing-continue-uri</dt>
  720. * <dd>A continue URL must be provided in the request.</dd>
  721. * <dt>auth/missing-ios-bundle-id</dt>
  722. * <dd>An iOS bundle ID must be provided if an App Store ID is provided.</dd>
  723. * <dt>auth/invalid-continue-uri</dt>
  724. * <dd>The continue URL provided in the request is invalid.</dd>
  725. * <dt>auth/unauthorized-continue-uri</dt>
  726. * <dd>The domain of the continue URL is not whitelisted. Whitelist
  727. * the domain in the Firebase console.</dd>
  728. * </dl>
  729. *
  730. * @example
  731. * ```javascript
  732. * var actionCodeSettings = {
  733. * url: 'https://www.example.com/cart?email=user@example.com&cartId=123',
  734. * iOS: {
  735. * bundleId: 'com.example.ios'
  736. * },
  737. * android: {
  738. * packageName: 'com.example.android',
  739. * installApp: true,
  740. * minimumVersion: '12'
  741. * },
  742. * handleCodeInApp: true
  743. * };
  744. * firebase.auth().currentUser.sendEmailVerification(actionCodeSettings)
  745. * .then(function() {
  746. * // Verification email sent.
  747. * })
  748. * .catch(function(error) {
  749. * // Error occurred. Inspect error.code.
  750. * });
  751. * ```
  752. *
  753. * @param actionCodeSettings The action
  754. * code settings. If specified, the state/continue URL will be set as the
  755. * "continueUrl" parameter in the email verification link. The default email
  756. * verification landing page will use this to display a link to go back to
  757. * the app if it is installed.
  758. * If the actionCodeSettings is not specified, no URL is appended to the
  759. * action URL.
  760. * The state URL provided must belong to a domain that is whitelisted by the
  761. * developer in the console. Otherwise an error will be thrown.
  762. * Mobile app redirects will only be applicable if the developer configures
  763. * and accepts the Firebase Dynamic Links terms of condition.
  764. * The Android package name and iOS bundle ID will be respected only if they
  765. * are configured in the same Firebase Auth project used.
  766. */
  767. sendEmailVerification(
  768. actionCodeSettings?: firebase.auth.ActionCodeSettings | null
  769. ): Promise<void>;
  770. /**
  771. * The current user's tenant ID. This is a read-only property, which indicates
  772. * the tenant ID used to sign in the current user. This is null if the user is
  773. * signed in from the parent project.
  774. *
  775. * @example
  776. * ```javascript
  777. * // Set the tenant ID on Auth instance.
  778. * firebase.auth().tenantId = ‘TENANT_PROJECT_ID’;
  779. *
  780. * // All future sign-in request now include tenant ID.
  781. * firebase.auth().signInWithEmailAndPassword(email, password)
  782. * .then(function(result) {
  783. * // result.user.tenantId should be ‘TENANT_PROJECT_ID’.
  784. * }).catch(function(error) {
  785. * // Handle error.
  786. * });
  787. * ```
  788. */
  789. tenantId: string | null;
  790. /**
  791. * Returns a JSON-serializable representation of this object.
  792. *
  793. * @return A JSON-serializable representation of this object.
  794. */
  795. toJSON(): Object;
  796. /**
  797. * Unlinks a provider from a user account.
  798. *
  799. * <h4>Error Codes</h4>
  800. * <dl>
  801. * <dt>auth/no-such-provider</dt>
  802. * <dd>Thrown if the user does not have this provider linked or when the
  803. * provider ID given does not exist.</dd>
  804. * </dt>
  805. *
  806. * @param providerId
  807. */
  808. unlink(providerId: string): Promise<firebase.User>;
  809. /**
  810. * Updates the user's email address.
  811. *
  812. * An email will be sent to the original email address (if it was set) that
  813. * allows to revoke the email address change, in order to protect them from
  814. * account hijacking.
  815. *
  816. * <b>Important:</b> this is a security sensitive operation that requires the
  817. * user to have recently signed in. If this requirement isn't met, ask the user
  818. * to authenticate again and then call
  819. * {@link firebase.User.reauthenticateWithCredential}.
  820. *
  821. * <h4>Error Codes</h4>
  822. * <dl>
  823. * <dt>auth/invalid-email</dt>
  824. * <dd>Thrown if the email used is invalid.</dd>
  825. * <dt>auth/email-already-in-use</dt>
  826. * <dd>Thrown if the email is already used by another user.</dd>
  827. * <dt>auth/requires-recent-login</dt>
  828. * <dd>Thrown if the user's last sign-in time does not meet the security
  829. * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
  830. * resolve. This does not apply if the user is anonymous.</dd>
  831. * </dl>
  832. *
  833. * @param newEmail The new email address.
  834. */
  835. updateEmail(newEmail: string): Promise<void>;
  836. /**
  837. * Updates the user's password.
  838. *
  839. * <b>Important:</b> this is a security sensitive operation that requires the
  840. * user to have recently signed in. If this requirement isn't met, ask the user
  841. * to authenticate again and then call
  842. * {@link firebase.User.reauthenticateWithCredential}.
  843. *
  844. * <h4>Error Codes</h4>
  845. * <dl>
  846. * <dt>auth/weak-password</dt>
  847. * <dd>Thrown if the password is not strong enough.</dd>
  848. * <dt>auth/requires-recent-login</dt>
  849. * <dd>Thrown if the user's last sign-in time does not meet the security
  850. * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
  851. * resolve. This does not apply if the user is anonymous.</dd>
  852. * </dl>
  853. *
  854. * @param newPassword
  855. */
  856. updatePassword(newPassword: string): Promise<void>;
  857. /**
  858. * Updates the user's phone number.
  859. *
  860. * <h4>Error Codes</h4>
  861. * <dl>
  862. * <dt>auth/invalid-verification-code</dt>
  863. * <dd>Thrown if the verification code of the credential is not valid.</dd>
  864. * <dt>auth/invalid-verification-id</dt>
  865. * <dd>Thrown if the verification ID of the credential is not valid.</dd>
  866. * </dl>
  867. *
  868. * @param phoneCredential
  869. */
  870. updatePhoneNumber(
  871. phoneCredential: firebase.auth.AuthCredential
  872. ): Promise<void>;
  873. /**
  874. * Updates a user's profile data.
  875. *
  876. * @example
  877. * ```javascript
  878. * // Updates the user attributes:
  879. * user.updateProfile({
  880. * displayName: "Jane Q. User",
  881. * photoURL: "https://example.com/jane-q-user/profile.jpg"
  882. * }).then(function() {
  883. * // Profile updated successfully!
  884. * // "Jane Q. User"
  885. * var displayName = user.displayName;
  886. * // "https://example.com/jane-q-user/profile.jpg"
  887. * var photoURL = user.photoURL;
  888. * }, function(error) {
  889. * // An error happened.
  890. * });
  891. *
  892. * // Passing a null value will delete the current attribute's value, but not
  893. * // passing a property won't change the current attribute's value:
  894. * // Let's say we're using the same user than before, after the update.
  895. * user.updateProfile({photoURL: null}).then(function() {
  896. * // Profile updated successfully!
  897. * // "Jane Q. User", hasn't changed.
  898. * var displayName = user.displayName;
  899. * // Now, this is null.
  900. * var photoURL = user.photoURL;
  901. * }, function(error) {
  902. * // An error happened.
  903. * });
  904. * ```
  905. *
  906. * @param profile The profile's
  907. * displayName and photoURL to update.
  908. */
  909. updateProfile(profile: {
  910. displayName?: string | null;
  911. photoURL?: string | null;
  912. }): Promise<void>;
  913. /**
  914. * Sends a verification email to a new email address. The user's email will be
  915. * updated to the new one after being verified.
  916. *
  917. * If you have a custom email action handler, you can complete the verification
  918. * process by calling {@link firebase.auth.Auth.applyActionCode}.
  919. *
  920. * <h4>Error Codes</h4>
  921. * <dl>
  922. * <dt>auth/missing-android-pkg-name</dt>
  923. * <dd>An Android package name must be provided if the Android app is required
  924. * to be installed.</dd>
  925. * <dt>auth/missing-continue-uri</dt>
  926. * <dd>A continue URL must be provided in the request.</dd>
  927. * <dt>auth/missing-ios-bundle-id</dt>
  928. * <dd>An iOS bundle ID must be provided if an App Store ID is provided.</dd>
  929. * <dt>auth/invalid-continue-uri</dt>
  930. * <dd>The continue URL provided in the request is invalid.</dd>
  931. * <dt>auth/unauthorized-continue-uri</dt>
  932. * <dd>The domain of the continue URL is not whitelisted. Whitelist
  933. * the domain in the Firebase console.</dd>
  934. * </dl>
  935. *
  936. * @example
  937. * ```javascript
  938. * var actionCodeSettings = {
  939. * url: 'https://www.example.com/cart?email=user@example.com&cartId=123',
  940. * iOS: {
  941. * bundleId: 'com.example.ios'
  942. * },
  943. * android: {
  944. * packageName: 'com.example.android',
  945. * installApp: true,
  946. * minimumVersion: '12'
  947. * },
  948. * handleCodeInApp: true
  949. * };
  950. * firebase.auth().currentUser.verifyBeforeUpdateEmail(
  951. * 'user@example.com', actionCodeSettings)
  952. * .then(function() {
  953. * // Verification email sent.
  954. * })
  955. * .catch(function(error) {
  956. * // Error occurred. Inspect error.code.
  957. * });
  958. * ```
  959. *
  960. * @param newEmail The email address to be verified and updated to.
  961. * @param actionCodeSettings The action
  962. * code settings. If specified, the state/continue URL will be set as the
  963. * "continueUrl" parameter in the email verification link. The default email
  964. * verification landing page will use this to display a link to go back to
  965. * the app if it is installed.
  966. * If the actionCodeSettings is not specified, no URL is appended to the
  967. * action URL.
  968. * The state URL provided must belong to a domain that is whitelisted by the
  969. * developer in the console. Otherwise an error will be thrown.
  970. * Mobile app redirects will only be applicable if the developer configures
  971. * and accepts the Firebase Dynamic Links terms of condition.
  972. * The Android package name and iOS bundle ID will be respected only if they
  973. * are configured in the same Firebase Auth project used.
  974. */
  975. verifyBeforeUpdateEmail(
  976. newEmail: string,
  977. actionCodeSettings?: firebase.auth.ActionCodeSettings | null
  978. ): Promise<void>;
  979. }
  980. /**
  981. * User profile information, visible only to the Firebase project's
  982. * apps.
  983. *
  984. */
  985. interface UserInfo {
  986. displayName: string | null;
  987. email: string | null;
  988. phoneNumber: string | null;
  989. photoURL: string | null;
  990. providerId: string;
  991. /**
  992. * The user's unique ID.
  993. */
  994. uid: string;
  995. }
  996. type FirebaseSignInProvider =
  997. | 'custom'
  998. | 'email'
  999. | 'password'
  1000. | 'phone'
  1001. | 'anonymous'
  1002. | 'google.com'
  1003. | 'facebook.com'
  1004. | 'github.com'
  1005. | 'twitter.com'
  1006. | 'microsoft.com'
  1007. | 'apple.com';
  1008. interface FirebaseIdToken {
  1009. /** Always set to https://securetoken.google.com/PROJECT_ID */
  1010. iss: string;
  1011. /** Always set to PROJECT_ID */
  1012. aud: string;
  1013. /** The user's unique ID */
  1014. sub: string;
  1015. /** The token issue time, in seconds since epoch */
  1016. iat: number;
  1017. /** The token expiry time, normally 'iat' + 3600 */
  1018. exp: number;
  1019. /** The user's unique ID. Must be equal to 'sub' */
  1020. user_id: string;
  1021. /** The time the user authenticated, normally 'iat' */
  1022. auth_time: number;
  1023. /** The sign in provider, only set when the provider is 'anonymous' */
  1024. provider_id?: 'anonymous';
  1025. /** The user's primary email */
  1026. email?: string;
  1027. /** The user's email verification status */
  1028. email_verified?: boolean;
  1029. /** The user's primary phone number */
  1030. phone_number?: string;
  1031. /** The user's display name */
  1032. name?: string;
  1033. /** The user's profile photo URL */
  1034. picture?: string;
  1035. /** Information on all identities linked to this user */
  1036. firebase: {
  1037. /** The primary sign-in provider */
  1038. sign_in_provider: FirebaseSignInProvider;
  1039. /** A map of providers to the user's list of unique identifiers from each provider */
  1040. identities?: { [provider in FirebaseSignInProvider]?: string[] };
  1041. };
  1042. /** Custom claims set by the developer */
  1043. [claim: string]: unknown;
  1044. // NO LONGER SUPPORTED. Use "sub" instead. (Not a jsdoc comment to avoid generating docs.)
  1045. uid?: never;
  1046. }
  1047. export type EmulatorMockTokenOptions = (
  1048. | { user_id: string }
  1049. | { sub: string }
  1050. ) &
  1051. Partial<FirebaseIdToken>;
  1052. /**
  1053. * Retrieves a Firebase {@link firebase.app.App app} instance.
  1054. *
  1055. * When called with no arguments, the default app is returned. When an app name
  1056. * is provided, the app corresponding to that name is returned.
  1057. *
  1058. * An exception is thrown if the app being retrieved has not yet been
  1059. * initialized.
  1060. *
  1061. * @example
  1062. * ```javascript
  1063. * // Return the default app
  1064. * var app = firebase.app();
  1065. * ```
  1066. *
  1067. * @example
  1068. * ```javascript
  1069. * // Return a named app
  1070. * var otherApp = firebase.app("otherApp");
  1071. * ```
  1072. *
  1073. * @param name Optional name of the app to return. If no name is
  1074. * provided, the default is `"[DEFAULT]"`.
  1075. *
  1076. * @return The app corresponding to the provided app name.
  1077. * If no app name is provided, the default app is returned.
  1078. */
  1079. function app(name?: string): firebase.app.App;
  1080. /**
  1081. * A (read-only) array of all initialized apps.
  1082. */
  1083. var apps: firebase.app.App[];
  1084. /**
  1085. * Gets the {@link firebase.auth.Auth `Auth`} service for the default app or a
  1086. * given app.
  1087. *
  1088. * `firebase.auth()` can be called with no arguments to access the default app's
  1089. * {@link firebase.auth.Auth `Auth`} service or as `firebase.auth(app)` to
  1090. * access the {@link firebase.auth.Auth `Auth`} service associated with a
  1091. * specific app.
  1092. *
  1093. * @example
  1094. * ```javascript
  1095. *
  1096. * // Get the Auth service for the default app
  1097. * var defaultAuth = firebase.auth();
  1098. * ```
  1099. * @example
  1100. * ```javascript
  1101. *
  1102. * // Get the Auth service for a given app
  1103. * var otherAuth = firebase.auth(otherApp);
  1104. * ```
  1105. * @param app
  1106. */
  1107. function auth(app?: firebase.app.App): firebase.auth.Auth;
  1108. /**
  1109. * Gets the {@link firebase.database.Database `Database`} service for the
  1110. * default app or a given app.
  1111. *
  1112. * `firebase.database()` can be called with no arguments to access the default
  1113. * app's {@link firebase.database.Database `Database`} service or as
  1114. * `firebase.database(app)` to access the
  1115. * {@link firebase.database.Database `Database`} service associated with a
  1116. * specific app.
  1117. *
  1118. * `firebase.database` is also a namespace that can be used to access global
  1119. * constants and methods associated with the `Database` service.
  1120. *
  1121. * @example
  1122. * ```javascript
  1123. * // Get the Database service for the default app
  1124. * var defaultDatabase = firebase.database();
  1125. * ```
  1126. *
  1127. * @example
  1128. * ```javascript
  1129. * // Get the Database service for a specific app
  1130. * var otherDatabase = firebase.database(app);
  1131. * ```
  1132. *
  1133. * @namespace
  1134. * @param app Optional app whose Database service to
  1135. * return. If not provided, the default Database service will be returned.
  1136. * @return The default Database service if no app
  1137. * is provided or the Database service associated with the provided app.
  1138. */
  1139. function database(app?: firebase.app.App): firebase.database.Database;
  1140. /**
  1141. * Creates and initializes a Firebase {@link firebase.app.App app} instance.
  1142. *
  1143. * See
  1144. * {@link
  1145. * https://firebase.google.com/docs/web/setup#add_firebase_to_your_app
  1146. * Add Firebase to your app} and
  1147. * {@link
  1148. * https://firebase.google.com/docs/web/learn-more#multiple-projects
  1149. * Initialize multiple projects} for detailed documentation.
  1150. *
  1151. * @example
  1152. * ```javascript
  1153. *
  1154. * // Initialize default app
  1155. * // Retrieve your own options values by adding a web app on
  1156. * // https://console.firebase.google.com
  1157. * firebase.initializeApp({
  1158. * apiKey: "AIza....", // Auth / General Use
  1159. * appId: "1:27992087142:web:ce....", // General Use
  1160. * projectId: "my-firebase-project", // General Use
  1161. * authDomain: "YOUR_APP.firebaseapp.com", // Auth with popup/redirect
  1162. * databaseURL: "https://YOUR_APP.firebaseio.com", // Realtime Database
  1163. * storageBucket: "YOUR_APP.appspot.com", // Storage
  1164. * messagingSenderId: "123456789", // Cloud Messaging
  1165. * measurementId: "G-12345" // Analytics
  1166. * });
  1167. * ```
  1168. *
  1169. * @example
  1170. * ```javascript
  1171. *
  1172. * // Initialize another app
  1173. * var otherApp = firebase.initializeApp({
  1174. * apiKey: "AIza....",
  1175. * appId: "1:27992087142:web:ce....",
  1176. * projectId: "my-firebase-project",
  1177. * databaseURL: "https://<OTHER_DATABASE_NAME>.firebaseio.com",
  1178. * storageBucket: "<OTHER_STORAGE_BUCKET>.appspot.com"
  1179. * }, "nameOfOtherApp");
  1180. * ```
  1181. *
  1182. * @param options Options to configure the app's services.
  1183. * @param name Optional name of the app to initialize. If no name
  1184. * is provided, the default is `"[DEFAULT]"`.
  1185. *
  1186. * @return {!firebase.app.App} The initialized app.
  1187. */
  1188. function initializeApp(options: Object, name?: string): firebase.app.App;
  1189. /**
  1190. * Gets the {@link firebase.messaging.Messaging `Messaging`} service for the
  1191. * default app or a given app.
  1192. *
  1193. * `firebase.messaging()` can be called with no arguments to access the default
  1194. * app's {@link firebase.messaging.Messaging `Messaging`} service or as
  1195. * `firebase.messaging(app)` to access the
  1196. * {@link firebase.messaging.Messaging `Messaging`} service associated with a
  1197. * specific app.
  1198. *
  1199. * Calling `firebase.messaging()` in a service worker results in Firebase
  1200. * generating notifications if the push message payload has a `notification`
  1201. * parameter.
  1202. *
  1203. * The Messaging SDK does not work in a Node.js environment.
  1204. *
  1205. * @example
  1206. * ```javascript
  1207. * // Get the Messaging service for the default app
  1208. * var defaultMessaging = firebase.messaging();
  1209. * ```
  1210. *
  1211. * @example
  1212. * ```javascript
  1213. * // Get the Messaging service for a given app
  1214. * var otherMessaging = firebase.messaging(otherApp);
  1215. * ```
  1216. *
  1217. * @namespace
  1218. * @param app The app to create a Messaging service for.
  1219. * If not passed, uses the default app.
  1220. */
  1221. function messaging(app?: firebase.app.App): firebase.messaging.Messaging;
  1222. /**
  1223. * Gets the {@link firebase.storage.Storage `Storage`} service for the default
  1224. * app or a given app.
  1225. *
  1226. * `firebase.storage()` can be called with no arguments to access the default
  1227. * app's {@link firebase.storage.Storage `Storage`} service or as
  1228. * `firebase.storage(app)` to access the
  1229. * {@link firebase.storage.Storage `Storage`} service associated with a
  1230. * specific app.
  1231. *
  1232. * @example
  1233. * ```javascript
  1234. * // Get the Storage service for the default app
  1235. * var defaultStorage = firebase.storage();
  1236. * ```
  1237. *
  1238. * @example
  1239. * ```javascript
  1240. * // Get the Storage service for a given app
  1241. * var otherStorage = firebase.storage(otherApp);
  1242. * ```
  1243. *
  1244. * @param app The app to create a storage service for.
  1245. * If not passed, uses the default app.
  1246. */
  1247. function storage(app?: firebase.app.App): firebase.storage.Storage;
  1248. function firestore(app?: firebase.app.App): firebase.firestore.Firestore;
  1249. function functions(app?: firebase.app.App): firebase.functions.Functions;
  1250. /**
  1251. * Gets the {@link firebase.performance.Performance `Performance`} service.
  1252. *
  1253. * `firebase.performance()` can be called with no arguments to access the default
  1254. * app's {@link firebase.performance.Performance `Performance`} service.
  1255. * The {@link firebase.performance.Performance `Performance`} service does not work with
  1256. * any other app.
  1257. *
  1258. * The Performance SDK does not work in a Node.js environment.
  1259. *
  1260. * @example
  1261. * ```javascript
  1262. * // Get the Performance service for the default app
  1263. * const defaultPerformance = firebase.performance();
  1264. * ```
  1265. *
  1266. * @param app The app to create a performance service for. Performance Monitoring only works with
  1267. * the default app.
  1268. * If not passed, uses the default app.
  1269. */
  1270. function performance(
  1271. app?: firebase.app.App
  1272. ): firebase.performance.Performance;
  1273. /**
  1274. * Gets the {@link firebase.remoteConfig.RemoteConfig `RemoteConfig`} instance.
  1275. *
  1276. * The Remote Config SDK does not work in a Node.js environment.
  1277. *
  1278. * @example
  1279. * ```javascript
  1280. * // Get the RemoteConfig instance for the default app
  1281. * const defaultRemoteConfig = firebase.remoteConfig();
  1282. * ```
  1283. *
  1284. * @param app The app to create a Remote Config service for. If not passed, uses the default app.
  1285. */
  1286. function remoteConfig(
  1287. app?: firebase.app.App
  1288. ): firebase.remoteConfig.RemoteConfig;
  1289. /**
  1290. * Gets the {@link firebase.analytics.Analytics `Analytics`} service.
  1291. *
  1292. * `firebase.analytics()` can be called with no arguments to access the default
  1293. * app's {@link firebase.analytics.Analytics `Analytics`} service.
  1294. *
  1295. * The Analytics SDK does not work in a Node.js environment.
  1296. *
  1297. * @example
  1298. * ```javascript
  1299. * // Get the Analytics service for the default app
  1300. * const defaultAnalytics = firebase.analytics();
  1301. * ```
  1302. *
  1303. * @param app The app to create an analytics service for.
  1304. * If not passed, uses the default app.
  1305. */
  1306. function analytics(app?: firebase.app.App): firebase.analytics.Analytics;
  1307. function appCheck(app?: firebase.app.App): firebase.appCheck.AppCheck;
  1308. }
  1309. declare namespace firebase.app {
  1310. /**
  1311. * A Firebase App holds the initialization information for a collection of
  1312. * services.
  1313. *
  1314. * Do not call this constructor directly. Instead, use
  1315. * {@link firebase.initializeApp|`firebase.initializeApp()`} to create an app.
  1316. *
  1317. */
  1318. interface App {
  1319. /**
  1320. * Gets the {@link firebase.auth.Auth `Auth`} service for the current app.
  1321. *
  1322. * @example
  1323. * ```javascript
  1324. * var auth = app.auth();
  1325. * // The above is shorthand for:
  1326. * // var auth = firebase.auth(app);
  1327. * ```
  1328. */
  1329. auth(): firebase.auth.Auth;
  1330. /**
  1331. * Gets the {@link firebase.database.Database `Database`} service for the
  1332. * current app.
  1333. *
  1334. * @example
  1335. * ```javascript
  1336. * var database = app.database();
  1337. * // The above is shorthand for:
  1338. * // var database = firebase.database(app);
  1339. * ```
  1340. */
  1341. database(url?: string): firebase.database.Database;
  1342. /**
  1343. * Renders this app unusable and frees the resources of all associated
  1344. * services.
  1345. *
  1346. * @example
  1347. * ```javascript
  1348. * app.delete()
  1349. * .then(function() {
  1350. * console.log("App deleted successfully");
  1351. * })
  1352. * .catch(function(error) {
  1353. * console.log("Error deleting app:", error);
  1354. * });
  1355. * ```
  1356. */
  1357. delete(): Promise<any>;
  1358. /**
  1359. * Gets the {@link firebase.installations.Installations `Installations`} service for the
  1360. * current app.
  1361. *
  1362. * The Installations SDK does not work in a Node.js environment.
  1363. *
  1364. * @example
  1365. * ```javascript
  1366. * const installations = app.installations();
  1367. * // The above is shorthand for:
  1368. * // const installations = firebase.installations(app);
  1369. * ```
  1370. */
  1371. installations(): firebase.installations.Installations;
  1372. /**
  1373. * Gets the {@link firebase.messaging.Messaging `Messaging`} service for the
  1374. * current app.
  1375. *
  1376. * The Messaging SDK does not work in a Node.js environment.
  1377. *
  1378. * @example
  1379. * ```javascript
  1380. * var messaging = app.messaging();
  1381. * // The above is shorthand for:
  1382. * // var messaging = firebase.messaging(app);
  1383. * ```
  1384. */
  1385. messaging(): firebase.messaging.Messaging;
  1386. /**
  1387. * The (read-only) name for this app.
  1388. *
  1389. * The default app's name is `"[DEFAULT]"`.
  1390. *
  1391. * @example
  1392. * ```javascript
  1393. * // The default app's name is "[DEFAULT]"
  1394. * firebase.initializeApp(defaultAppConfig);
  1395. * console.log(firebase.app().name); // "[DEFAULT]"
  1396. * ```
  1397. *
  1398. * @example
  1399. * ```javascript
  1400. * // A named app's name is what you provide to initializeApp()
  1401. * var otherApp = firebase.initializeApp(otherAppConfig, "other");
  1402. * console.log(otherApp.name); // "other"
  1403. * ```
  1404. */
  1405. name: string;
  1406. /**
  1407. * The settable config flag for GDPR opt-in/opt-out
  1408. */
  1409. automaticDataCollectionEnabled: boolean;
  1410. /**
  1411. * The (read-only) configuration options for this app. These are the original
  1412. * parameters given in
  1413. * {@link firebase.initializeApp `firebase.initializeApp()`}.
  1414. *
  1415. * @example
  1416. * ```javascript
  1417. * var app = firebase.initializeApp(config);
  1418. * console.log(app.options.databaseURL === config.databaseURL); // true
  1419. * ```
  1420. */
  1421. options: Object;
  1422. /**
  1423. * Gets the {@link firebase.storage.Storage `Storage`} service for the current
  1424. * app, optionally initialized with a custom storage bucket.
  1425. *
  1426. * @example
  1427. * ```javascript
  1428. * var storage = app.storage();
  1429. * // The above is shorthand for:
  1430. * // var storage = firebase.storage(app);
  1431. * ```
  1432. *
  1433. * @example
  1434. * ```javascript
  1435. * var storage = app.storage("gs://your-app.appspot.com");
  1436. * ```
  1437. *
  1438. * @param url The gs:// url to your Firebase Storage Bucket.
  1439. * If not passed, uses the app's default Storage Bucket.
  1440. */
  1441. storage(url?: string): firebase.storage.Storage;
  1442. firestore(): firebase.firestore.Firestore;
  1443. functions(regionOrCustomDomain?: string): firebase.functions.Functions;
  1444. /**
  1445. * Gets the {@link firebase.performance.Performance `Performance`} service for the
  1446. * current app. If the current app is not the default one, throws an error.
  1447. *
  1448. * The Performance SDK does not work in a Node.js environment.
  1449. *
  1450. * @example
  1451. * ```javascript
  1452. * const perf = app.performance();
  1453. * // The above is shorthand for:
  1454. * // const perf = firebase.performance(app);
  1455. * ```
  1456. */
  1457. performance(): firebase.performance.Performance;
  1458. /**
  1459. * Gets the {@link firebase.remoteConfig.RemoteConfig `RemoteConfig`} instance.
  1460. *
  1461. * The Remote Config SDK does not work in a Node.js environment.
  1462. *
  1463. * @example
  1464. * ```javascript
  1465. * const rc = app.remoteConfig();
  1466. * // The above is shorthand for:
  1467. * // const rc = firebase.remoteConfig(app);
  1468. * ```
  1469. */
  1470. remoteConfig(): firebase.remoteConfig.RemoteConfig;
  1471. /**
  1472. * Gets the {@link firebase.analytics.Analytics `Analytics`} service for the
  1473. * current app. If the current app is not the default one, throws an error.
  1474. *
  1475. * The Analytics SDK does not work in a Node.js environment.
  1476. *
  1477. * @example
  1478. * ```javascript
  1479. * const analytics = app.analytics();
  1480. * // The above is shorthand for:
  1481. * // const analytics = firebase.analytics(app);
  1482. * ```
  1483. */
  1484. analytics(): firebase.analytics.Analytics;
  1485. appCheck(): firebase.appCheck.AppCheck;
  1486. }
  1487. }
  1488. /**
  1489. * Firebase App Check does not work in a Node.js environment using `ReCaptchaV3Provider` or
  1490. * `ReCaptchaEnterpriseProvider`, but can be used in Node.js if you use
  1491. * `CustomProvider` and write your own attestation method.
  1492. */
  1493. declare namespace firebase.appCheck {
  1494. /**
  1495. * Result returned by
  1496. * {@link firebase.appCheck.AppCheck.getToken `firebase.appCheck().getToken()`}.
  1497. */
  1498. interface AppCheckTokenResult {
  1499. token: string;
  1500. }
  1501. /*
  1502. * reCAPTCHA v3 token provider.
  1503. */
  1504. class ReCaptchaV3Provider {
  1505. /**
  1506. * @param siteKey - reCAPTCHA v3 site key (public key).
  1507. */
  1508. constructor(siteKey: string);
  1509. }
  1510. /*
  1511. * reCAPTCHA Enterprise token provider.
  1512. */
  1513. class ReCaptchaEnterpriseProvider {
  1514. /**
  1515. * @param keyId - reCAPTCHA Enterprise key ID.
  1516. */
  1517. constructor(keyId: string);
  1518. }
  1519. /*
  1520. * Custom token provider.
  1521. */
  1522. class CustomProvider {
  1523. /**
  1524. * @param options - Options for creating the custom provider.
  1525. */
  1526. constructor(options: CustomProviderOptions);
  1527. }
  1528. /**
  1529. * Options when creating a CustomProvider.
  1530. */
  1531. interface CustomProviderOptions {
  1532. /**
  1533. * Function to get an App Check token through a custom provider
  1534. * service.
  1535. */
  1536. getToken: () => Promise<AppCheckToken>;
  1537. }
  1538. /**
  1539. * The Firebase AppCheck service interface.
  1540. *
  1541. * Do not call this constructor directly. Instead, use
  1542. * {@link firebase.appCheck `firebase.appCheck()`}.
  1543. */
  1544. export interface AppCheck {
  1545. /**
  1546. * Activate AppCheck
  1547. * @param provider This can be a `ReCaptchaV3Provider` instance,
  1548. * a `ReCaptchaEnterpriseProvider` instance, a `CustomProvider` instance,
  1549. * an object with a custom `getToken()` method, or a reCAPTCHA site key.
  1550. * @param isTokenAutoRefreshEnabled If true, the SDK automatically
  1551. * refreshes App Check tokens as needed. If undefined, defaults to the
  1552. * value of `app.automaticDataCollectionEnabled`, which defaults to
  1553. * false and can be set in the app config.
  1554. */
  1555. activate(
  1556. provider:
  1557. | ReCaptchaV3Provider
  1558. | ReCaptchaEnterpriseProvider
  1559. | CustomProvider
  1560. | AppCheckProvider
  1561. | { getToken: () => AppCheckToken }
  1562. | string,
  1563. isTokenAutoRefreshEnabled?: boolean
  1564. ): void;
  1565. /**
  1566. *
  1567. * @param isTokenAutoRefreshEnabled If true, the SDK automatically
  1568. * refreshes App Check tokens as needed. This overrides any value set
  1569. * during `activate()`.
  1570. */
  1571. setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled: boolean): void;
  1572. /**
  1573. * Get the current App Check token. Attaches to the most recent
  1574. * in-flight request if one is present. Returns null if no token
  1575. * is present and no token requests are in-flight.
  1576. *
  1577. * @param forceRefresh - If true, will always try to fetch a fresh token.
  1578. * If false, will use a cached token if found in storage.
  1579. */
  1580. getToken(
  1581. forceRefresh?: boolean
  1582. ): Promise<firebase.appCheck.AppCheckTokenResult>;
  1583. /**
  1584. * Registers a listener to changes in the token state. There can be more
  1585. * than one listener registered at the same time for one or more
  1586. * App Check instances. The listeners call back on the UI thread whenever
  1587. * the current token associated with this App Check instance changes.
  1588. *
  1589. * @param observer An object with `next`, `error`, and `complete`
  1590. * properties. `next` is called with an
  1591. * {@link firebase.appCheck.AppCheckTokenResult `AppCheckTokenResult`}
  1592. * whenever the token changes. `error` is optional and is called if an
  1593. * error is thrown by the listener (the `next` function). `complete`
  1594. * is unused, as the token stream is unending.
  1595. *
  1596. * @returns A function that unsubscribes this listener.
  1597. */
  1598. onTokenChanged(observer: {
  1599. next: (tokenResult: firebase.appCheck.AppCheckTokenResult) => void;
  1600. error?: (error: Error) => void;
  1601. complete?: () => void;
  1602. }): Unsubscribe;
  1603. /**
  1604. * Registers a listener to changes in the token state. There can be more
  1605. * than one listener registered at the same time for one or more
  1606. * App Check instances. The listeners call back on the UI thread whenever
  1607. * the current token associated with this App Check instance changes.
  1608. *
  1609. * @param onNext When the token changes, this function is called with aa
  1610. * {@link firebase.appCheck.AppCheckTokenResult `AppCheckTokenResult`}.
  1611. * @param onError Optional. Called if there is an error thrown by the
  1612. * listener (the `onNext` function).
  1613. * @param onCompletion Currently unused, as the token stream is unending.
  1614. * @returns A function that unsubscribes this listener.
  1615. */
  1616. onTokenChanged(
  1617. onNext: (tokenResult: firebase.appCheck.AppCheckTokenResult) => void,
  1618. onError?: (error: Error) => void,
  1619. onCompletion?: () => void
  1620. ): Unsubscribe;
  1621. }
  1622. /**
  1623. * An App Check provider. This can be either the built-in reCAPTCHA
  1624. * provider or a custom provider. For more on custom providers, see
  1625. * https://firebase.google.com/docs/app-check/web-custom-provider
  1626. */
  1627. interface AppCheckProvider {
  1628. /**
  1629. * Returns an AppCheck token.
  1630. */
  1631. getToken(): Promise<AppCheckToken>;
  1632. }
  1633. /**
  1634. * The token returned from an {@link firebase.appCheck.AppCheckProvider `AppCheckProvider`}.
  1635. */
  1636. interface AppCheckToken {
  1637. /**
  1638. * The token string in JWT format.
  1639. */
  1640. readonly token: string;
  1641. /**
  1642. * The local timestamp after which the token will expire.
  1643. */
  1644. readonly expireTimeMillis: number;
  1645. }
  1646. }
  1647. /**
  1648. * The Installations SDK does not work in a Node.js environment.
  1649. */
  1650. declare namespace firebase.installations {
  1651. /**
  1652. * The Firebase Installations service interface.
  1653. *
  1654. * Do not call this constructor directly. Instead, use
  1655. * {@link firebase.installations `firebase.installations()`}.
  1656. */
  1657. export interface Installations {
  1658. /**
  1659. * The {@link firebase.app.App app} associated with the `Installations` service
  1660. * instance.
  1661. *
  1662. * @example
  1663. * ```javascript
  1664. * var app = analytics.app;
  1665. * ```
  1666. */
  1667. app: firebase.app.App;
  1668. /**
  1669. * Creates a Firebase Installation if there isn't one for the app and
  1670. * returns the Installation ID.
  1671. *
  1672. * @return Firebase Installation ID
  1673. */
  1674. getId(): Promise<string>;
  1675. /**
  1676. * Returns an Authentication Token for the current Firebase Installation.
  1677. *
  1678. * @return Firebase Installation Authentication Token
  1679. */
  1680. getToken(forceRefresh?: boolean): Promise<string>;
  1681. /**
  1682. * Deletes the Firebase Installation and all associated data.
  1683. */
  1684. delete(): Promise<void>;
  1685. /**
  1686. * Sets a new callback that will get called when Installlation ID changes.
  1687. * Returns an unsubscribe function that will remove the callback when called.
  1688. */
  1689. onIdChange(callback: (installationId: string) => void): () => void;
  1690. }
  1691. }
  1692. /**
  1693. * The Performance SDK does not work in a Node.js environment.
  1694. */
  1695. declare namespace firebase.performance {
  1696. /**
  1697. * The Firebase Performance Monitoring service interface.
  1698. *
  1699. * Do not call this constructor directly. Instead, use
  1700. * {@link firebase.performance `firebase.performance()`}.
  1701. */
  1702. export interface Performance {
  1703. /**
  1704. * The {@link firebase.app.App app} associated with the `Performance` service
  1705. * instance.
  1706. *
  1707. * @example
  1708. * ```javascript
  1709. * var app = analytics.app;
  1710. * ```
  1711. */
  1712. app: firebase.app.App;
  1713. /**
  1714. * Creates an uninitialized instance of {@link firebase.performance.Trace `trace`} and returns
  1715. * it.
  1716. *
  1717. * @param traceName The name of the trace instance.
  1718. * @return The Trace instance.
  1719. */
  1720. trace(traceName: string): Trace;
  1721. /**
  1722. * Controls the logging of automatic traces and HTTP/S network monitoring.
  1723. */
  1724. instrumentationEnabled: boolean;
  1725. /**
  1726. * Controls the logging of custom traces.
  1727. */
  1728. dataCollectionEnabled: boolean;
  1729. }
  1730. export interface Trace {
  1731. /**
  1732. * Starts the timing for the {@link firebase.performance.Trace `trace`} instance.
  1733. */
  1734. start(): void;
  1735. /**
  1736. * Stops the timing of the {@link firebase.performance.Trace `trace`} instance and logs the
  1737. * data of the instance.
  1738. */
  1739. stop(): void;
  1740. /**
  1741. * Records a {@link firebase.performance.Trace `trace`} from given parameters. This provides a
  1742. * direct way to use {@link firebase.performance.Trace `trace`} without a need to start/stop.
  1743. * This is useful for use cases in which the {@link firebase.performance.Trace `trace`} cannot
  1744. * directly be used (e.g. if the duration was captured before the Performance SDK was loaded).
  1745. *
  1746. * @param startTime Trace start time since epoch in millisec.
  1747. * @param duration The duraction of the trace in millisec.
  1748. * @param options An object which can optionally hold maps of custom metrics and
  1749. * custom attributes.
  1750. */
  1751. record(
  1752. startTime: number,
  1753. duration: number,
  1754. options?: {
  1755. metrics?: { [key: string]: number };
  1756. attributes?: { [key: string]: string };
  1757. }
  1758. ): void;
  1759. /**
  1760. * Adds to the value of a custom metric. If a custom metric with the provided name does not
  1761. * exist, it creates one with that name and the value equal to the given number.
  1762. *
  1763. * @param metricName The name of the custom metric.
  1764. * @param num The number to be added to the value of the custom metric. If not provided, it
  1765. * uses a default value of one.
  1766. */
  1767. incrementMetric(metricName: string, num?: number): void;
  1768. /**
  1769. * Sets the value of the specified custom metric to the given number regardless of whether
  1770. * a metric with that name already exists on the {@link firebase.performance.Trace `trace`}
  1771. * instance or not.
  1772. *
  1773. * @param metricName Name of the custom metric.
  1774. * @param num Value to of the custom metric.
  1775. */
  1776. putMetric(metricName: string, num: number): void;
  1777. /**
  1778. * Returns the value of the custom metric by that name. If a custom metric with that name does
  1779. * not exist returns zero.
  1780. *
  1781. * @param metricName Name of the custom metric.
  1782. */
  1783. getMetric(metricName: string): number;
  1784. /**
  1785. * Set a custom attribute of a {@link firebase.performance.Trace `trace`} to a certain value.
  1786. *
  1787. * @param attr Name of the custom attribute.
  1788. * @param value Value of the custom attribute.
  1789. */
  1790. putAttribute(attr: string, value: string): void;
  1791. /**
  1792. * Retrieves the value that the custom attribute is set to.
  1793. *
  1794. * @param attr Name of the custom attribute.
  1795. */
  1796. getAttribute(attr: string): string | undefined;
  1797. /**
  1798. * Removes the specified custom attribute from a {@link firebase.performance.Trace `trace`}
  1799. * instance.
  1800. *
  1801. * @param attr Name of the custom attribute.
  1802. */
  1803. removeAttribute(attr: string): void;
  1804. /**
  1805. * Returns a map of all custom attributes of a {@link firebase.performance.Trace `trace`}
  1806. * instance.
  1807. */
  1808. getAttributes(): { [key: string]: string };
  1809. }
  1810. }
  1811. /**
  1812. * The Remote Config SDK does not work in a Node.js environment.
  1813. */
  1814. declare namespace firebase.remoteConfig {
  1815. /**
  1816. * The Firebase Remote Config service interface.
  1817. *
  1818. * Do not call this constructor directly. Instead, use
  1819. * {@link firebase.remoteConfig `firebase.remoteConfig()`}.
  1820. */
  1821. export interface RemoteConfig {
  1822. /**
  1823. * The {@link firebase.app.App app} associated with the `Performance` service
  1824. * instance.
  1825. *
  1826. * @example
  1827. * ```javascript
  1828. * var app = analytics.app;
  1829. * ```
  1830. */
  1831. app: firebase.app.App;
  1832. /**
  1833. * Defines configuration for the Remote Config SDK.
  1834. */
  1835. settings: Settings;
  1836. /**
  1837. * Object containing default values for configs.
  1838. */
  1839. defaultConfig: { [key: string]: string | number | boolean };
  1840. /**
  1841. * The Unix timestamp in milliseconds of the last <i>successful</i> fetch, or negative one if
  1842. * the {@link RemoteConfig} instance either hasn't fetched or initialization
  1843. * is incomplete.
  1844. */
  1845. fetchTimeMillis: number;
  1846. /**
  1847. * The status of the last fetch <i>attempt</i>.
  1848. */
  1849. lastFetchStatus: FetchStatus;
  1850. /**
  1851. * Makes the last fetched config available to the getters.
  1852. * Returns a promise which resolves to true if the current call activated the fetched configs.
  1853. * If the fetched configs were already activated, the promise will resolve to false.
  1854. */
  1855. activate(): Promise<boolean>;
  1856. /**
  1857. * Ensures the last activated config are available to the getters.
  1858. */
  1859. ensureInitialized(): Promise<void>;
  1860. /**
  1861. * Fetches and caches configuration from the Remote Config service.
  1862. */
  1863. fetch(): Promise<void>;
  1864. /**
  1865. * Performs fetch and activate operations, as a convenience.
  1866. * Returns a promise which resolves to true if the current call activated the fetched configs.
  1867. * If the fetched configs were already activated, the promise will resolve to false.
  1868. */
  1869. fetchAndActivate(): Promise<boolean>;
  1870. /**
  1871. * Gets all config.
  1872. */
  1873. getAll(): { [key: string]: Value };
  1874. /**
  1875. * Gets the value for the given key as a boolean.
  1876. *
  1877. * Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.
  1878. */
  1879. getBoolean(key: string): boolean;
  1880. /**
  1881. * Gets the value for the given key as a number.
  1882. *
  1883. * Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.
  1884. */
  1885. getNumber(key: string): number;
  1886. /**
  1887. * Gets the value for the given key as a String.
  1888. *
  1889. * Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.
  1890. */
  1891. getString(key: string): string;
  1892. /**
  1893. * Gets the {@link Value} for the given key.
  1894. */
  1895. getValue(key: string): Value;
  1896. /**
  1897. * Defines the log level to use.
  1898. */
  1899. setLogLevel(logLevel: LogLevel): void;
  1900. }
  1901. /**
  1902. * Indicates the source of a value.
  1903. *
  1904. * <ul>
  1905. * <li>"static" indicates the value was defined by a static constant.</li>
  1906. * <li>"default" indicates the value was defined by default config.</li>
  1907. * <li>"remote" indicates the value was defined by fetched config.</li>
  1908. * </ul>
  1909. */
  1910. export type ValueSource = 'static' | 'default' | 'remote';
  1911. /**
  1912. * Wraps a value with metadata and type-safe getters.
  1913. */
  1914. export interface Value {
  1915. /**
  1916. * Gets the value as a boolean.
  1917. *
  1918. * The following values (case insensitive) are interpreted as true:
  1919. * "1", "true", "t", "yes", "y", "on". Other values are interpreted as false.
  1920. */
  1921. asBoolean(): boolean;
  1922. /**
  1923. * Gets the value as a number. Comparable to calling <code>Number(value) || 0</code>.
  1924. */
  1925. asNumber(): number;
  1926. /**
  1927. * Gets the value as a string.
  1928. */
  1929. asString(): string;
  1930. /**
  1931. * Gets the {@link ValueSource} for the given key.
  1932. */
  1933. getSource(): ValueSource;
  1934. }
  1935. /**
  1936. * Defines configuration options for the Remote Config SDK.
  1937. */
  1938. export interface Settings {
  1939. /**
  1940. * Defines the maximum age in milliseconds of an entry in the config cache before
  1941. * it is considered stale. Defaults to 43200000 (Twelve hours).
  1942. */
  1943. minimumFetchIntervalMillis: number;
  1944. /**
  1945. * Defines the maximum amount of milliseconds to wait for a response when fetching
  1946. * configuration from the Remote Config server. Defaults to 60000 (One minute).
  1947. */
  1948. fetchTimeoutMillis: number;
  1949. }
  1950. /**
  1951. * Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.
  1952. *
  1953. * <ul>
  1954. * <li>"no-fetch-yet" indicates the {@link RemoteConfig} instance has not yet attempted
  1955. * to fetch config, or that SDK initialization is incomplete.</li>
  1956. * <li>"success" indicates the last attempt succeeded.</li>
  1957. * <li>"failure" indicates the last attempt failed.</li>
  1958. * <li>"throttle" indicates the last attempt was rate-limited.</li>
  1959. * </ul>
  1960. */
  1961. export type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
  1962. /**
  1963. * Defines levels of Remote Config logging.
  1964. */
  1965. export type LogLevel = 'debug' | 'error' | 'silent';
  1966. /**
  1967. * This method provides two different checks:
  1968. *
  1969. * 1. Check if IndexedDB exists in the browser environment.
  1970. * 2. Check if the current browser context allows IndexedDB `open()` calls.
  1971. *
  1972. * It returns a `Promise` which resolves to true if a {@link RemoteConfig} instance
  1973. * can be initialized in this environment, or false if it cannot.
  1974. */
  1975. export function isSupported(): Promise<boolean>;
  1976. }
  1977. declare namespace firebase.functions {
  1978. /**
  1979. * An HttpsCallableResult wraps a single result from a function call.
  1980. */
  1981. export interface HttpsCallableResult {
  1982. readonly data: any;
  1983. }
  1984. /**
  1985. * An HttpsCallable is a reference to a "callable" http trigger in
  1986. * Google Cloud Functions.
  1987. */
  1988. export interface HttpsCallable {
  1989. (data?: any): Promise<HttpsCallableResult>;
  1990. }
  1991. export interface HttpsCallableOptions {
  1992. timeout?: number;
  1993. }
  1994. /**
  1995. * The Cloud Functions for Firebase service interface.
  1996. *
  1997. * Do not call this constructor directly. Instead, use
  1998. * {@link firebase.functions `firebase.functions()`}.
  1999. */
  2000. export class Functions {
  2001. private constructor();
  2002. /**
  2003. * Modify this instance to communicate with the Cloud Functions emulator.
  2004. *
  2005. * Note: this must be called before this instance has been used to do any operations.
  2006. *
  2007. * @param host The emulator host (ex: localhost)
  2008. * @param port The emulator port (ex: 5001)
  2009. */
  2010. useEmulator(host: string, port: number): void;
  2011. /**
  2012. * Changes this instance to point to a Cloud Functions emulator running
  2013. * locally. See https://firebase.google.com/docs/functions/local-emulator
  2014. *
  2015. * @deprecated Prefer the useEmulator(host, port) method.
  2016. * @param origin The origin of the local emulator, such as
  2017. * "http://localhost:5005".
  2018. */
  2019. useFunctionsEmulator(url: string): void;
  2020. /**
  2021. * Gets an `HttpsCallable` instance that refers to the function with the given
  2022. * name.
  2023. *
  2024. * @param name The name of the https callable function.
  2025. * @param options The options for this HttpsCallable instance.
  2026. * @return The `HttpsCallable` instance.
  2027. */
  2028. httpsCallable(name: string, options?: HttpsCallableOptions): HttpsCallable;
  2029. }
  2030. /**
  2031. * The set of Firebase Functions status codes. The codes are the same at the
  2032. * ones exposed by gRPC here:
  2033. * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
  2034. *
  2035. * Possible values:
  2036. * - 'cancelled': The operation was cancelled (typically by the caller).
  2037. * - 'unknown': Unknown error or an error from a different error domain.
  2038. * - 'invalid-argument': Client specified an invalid argument. Note that this
  2039. * differs from 'failed-precondition'. 'invalid-argument' indicates
  2040. * arguments that are problematic regardless of the state of the system
  2041. * (e.g. an invalid field name).
  2042. * - 'deadline-exceeded': Deadline expired before operation could complete.
  2043. * For operations that change the state of the system, this error may be
  2044. * returned even if the operation has completed successfully. For example,
  2045. * a successful response from a server could have been delayed long enough
  2046. * for the deadline to expire.
  2047. * - 'not-found': Some requested document was not found.
  2048. * - 'already-exists': Some document that we attempted to create already
  2049. * exists.
  2050. * - 'permission-denied': The caller does not have permission to execute the
  2051. * specified operation.
  2052. * - 'resource-exhausted': Some resource has been exhausted, perhaps a
  2053. * per-user quota, or perhaps the entire file system is out of space.
  2054. * - 'failed-precondition': Operation was rejected because the system is not
  2055. * in a state required for the operation's execution.
  2056. * - 'aborted': The operation was aborted, typically due to a concurrency
  2057. * issue like transaction aborts, etc.
  2058. * - 'out-of-range': Operation was attempted past the valid range.
  2059. * - 'unimplemented': Operation is not implemented or not supported/enabled.
  2060. * - 'internal': Internal errors. Means some invariants expected by
  2061. * underlying system has been broken. If you see one of these errors,
  2062. * something is very broken.
  2063. * - 'unavailable': The service is currently unavailable. This is most likely
  2064. * a transient condition and may be corrected by retrying with a backoff.
  2065. * - 'data-loss': Unrecoverable data loss or corruption.
  2066. * - 'unauthenticated': The request does not have valid authentication
  2067. * credentials for the operation.
  2068. */
  2069. export type FunctionsErrorCode =
  2070. | 'ok'
  2071. | 'cancelled'
  2072. | 'unknown'
  2073. | 'invalid-argument'
  2074. | 'deadline-exceeded'
  2075. | 'not-found'
  2076. | 'already-exists'
  2077. | 'permission-denied'
  2078. | 'resource-exhausted'
  2079. | 'failed-precondition'
  2080. | 'aborted'
  2081. | 'out-of-range'
  2082. | 'unimplemented'
  2083. | 'internal'
  2084. | 'unavailable'
  2085. | 'data-loss'
  2086. | 'unauthenticated';
  2087. export interface HttpsError extends Error {
  2088. /**
  2089. * A standard error code that will be returned to the client. This also
  2090. * determines the HTTP status code of the response, as defined in code.proto.
  2091. */
  2092. readonly code: FunctionsErrorCode;
  2093. /**
  2094. * Extra data to be converted to JSON and included in the error response.
  2095. */
  2096. readonly details?: any;
  2097. }
  2098. }
  2099. declare namespace firebase.auth {
  2100. /**
  2101. * A utility class to parse email action URLs.
  2102. */
  2103. class ActionCodeURL {
  2104. private constructor();
  2105. /**
  2106. * The API key of the email action link.
  2107. */
  2108. apiKey: string;
  2109. /**
  2110. * The action code of the email action link.
  2111. */
  2112. code: string;
  2113. /**
  2114. * The continue URL of the email action link. Null if not provided.
  2115. */
  2116. continueUrl: string | null;
  2117. /**
  2118. * The language code of the email action link. Null if not provided.
  2119. */
  2120. languageCode: string | null;
  2121. /**
  2122. * The action performed by the email action link. It returns from one
  2123. * of the types from {@link firebase.auth.ActionCodeInfo}.
  2124. */
  2125. operation: firebase.auth.ActionCodeInfo.Operation;
  2126. /**
  2127. * Parses the email action link string and returns an ActionCodeURL object
  2128. * if the link is valid, otherwise returns null.
  2129. *
  2130. * @param link The email action link string.
  2131. * @return The ActionCodeURL object, or null if the link is invalid.
  2132. */
  2133. static parseLink(link: string): firebase.auth.ActionCodeURL | null;
  2134. /**
  2135. * The tenant ID of the email action link. Null if the email action
  2136. * is from the parent project.
  2137. */
  2138. tenantId: string | null;
  2139. }
  2140. /**
  2141. * A response from {@link firebase.auth.Auth.checkActionCode}.
  2142. */
  2143. interface ActionCodeInfo {
  2144. /**
  2145. * The data associated with the action code.
  2146. *
  2147. * For the `PASSWORD_RESET`, `VERIFY_EMAIL`, and `RECOVER_EMAIL` actions, this object
  2148. * contains an `email` field with the address the email was sent to.
  2149. *
  2150. * For the RECOVER_EMAIL action, which allows a user to undo an email address
  2151. * change, this object also contains a `previousEmail` field with the user account's
  2152. * current email address. After the action completes, the user's email address will
  2153. * revert to the value in the `email` field from the value in `previousEmail` field.
  2154. *
  2155. * For the VERIFY_AND_CHANGE_EMAIL action, which allows a user to verify the email
  2156. * before updating it, this object contains a `previousEmail` field with the user
  2157. * account's email address before updating. After the action completes, the user's
  2158. * email address will be updated to the value in the `email` field from the value
  2159. * in `previousEmail` field.
  2160. *
  2161. * For the REVERT_SECOND_FACTOR_ADDITION action, which allows a user to unenroll
  2162. * a newly added second factor, this object contains a `multiFactorInfo` field with
  2163. * the information about the second factor. For phone second factor, the
  2164. * `multiFactorInfo` is a {@link firebase.auth.PhoneMultiFactorInfo} object,
  2165. * which contains the phone number.
  2166. */
  2167. data: {
  2168. email?: string | null;
  2169. /**
  2170. * @deprecated
  2171. * This field is deprecated in favor of previousEmail.
  2172. */
  2173. fromEmail?: string | null;
  2174. multiFactorInfo?: firebase.auth.MultiFactorInfo | null;
  2175. previousEmail?: string | null;
  2176. };
  2177. /**
  2178. * The type of operation that generated the action code. This could be:
  2179. * <ul>
  2180. * <li>`EMAIL_SIGNIN`: email sign in code generated via
  2181. * {@link firebase.auth.Auth.sendSignInLinkToEmail}.</li>
  2182. * <li>`PASSWORD_RESET`: password reset code generated via
  2183. * {@link firebase.auth.Auth.sendPasswordResetEmail}.</li>
  2184. * <li>`RECOVER_EMAIL`: email change revocation code generated via
  2185. * {@link firebase.User.updateEmail}.</li>
  2186. * <li>`REVERT_SECOND_FACTOR_ADDITION`: revert second factor addition
  2187. * code generated via
  2188. * {@link firebase.User.MultiFactorUser.enroll}.</li>
  2189. * <li>`VERIFY_AND_CHANGE_EMAIL`: verify and change email code generated
  2190. * via {@link firebase.User.verifyBeforeUpdateEmail}.</li>
  2191. * <li>`VERIFY_EMAIL`: email verification code generated via
  2192. * {@link firebase.User.sendEmailVerification}.</li>
  2193. * </ul>
  2194. */
  2195. operation: string;
  2196. }
  2197. /**
  2198. * This is the interface that defines the required continue/state URL with
  2199. * optional Android and iOS bundle identifiers.
  2200. * The action code setting fields are:
  2201. * <ul>
  2202. * <li><p>url: Sets the link continue/state URL, which has different meanings
  2203. * in different contexts:</p>
  2204. * <ul>
  2205. * <li>When the link is handled in the web action widgets, this is the deep
  2206. * link in the continueUrl query parameter.</li>
  2207. * <li>When the link is handled in the app directly, this is the continueUrl
  2208. * query parameter in the deep link of the Dynamic Link.</li>
  2209. * </ul>
  2210. * </li>
  2211. * <li>iOS: Sets the iOS bundle ID. This will try to open the link in an iOS app
  2212. * if it is installed.</li>
  2213. * <li>android: Sets the Android package name. This will try to open the link in
  2214. * an android app if it is installed. If installApp is passed, it specifies
  2215. * whether to install the Android app if the device supports it and the app
  2216. * is not already installed. If this field is provided without a
  2217. * packageName, an error is thrown explaining that the packageName must be
  2218. * provided in conjunction with this field.
  2219. * If minimumVersion is specified, and an older version of the app is
  2220. * installed, the user is taken to the Play Store to upgrade the app.</li>
  2221. * <li>handleCodeInApp: The default is false. When set to true, the action code
  2222. * link will be be sent as a Universal Link or Android App Link and will be
  2223. * opened by the app if installed. In the false case, the code will be sent
  2224. * to the web widget first and then on continue will redirect to the app if
  2225. * installed.</li>
  2226. * </ul>
  2227. */
  2228. type ActionCodeSettings = {
  2229. android?: {
  2230. installApp?: boolean;
  2231. minimumVersion?: string;
  2232. packageName: string;
  2233. };
  2234. handleCodeInApp?: boolean;
  2235. iOS?: { bundleId: string };
  2236. url: string;
  2237. dynamicLinkDomain?: string;
  2238. };
  2239. /**
  2240. * A structure containing additional user information from a federated identity
  2241. * provider.
  2242. */
  2243. type AdditionalUserInfo = {
  2244. isNewUser: boolean;
  2245. profile: Object | null;
  2246. providerId: string;
  2247. username?: string | null;
  2248. };
  2249. /**
  2250. * A verifier for domain verification and abuse prevention. Currently, the
  2251. * only implementation is {@link firebase.auth.RecaptchaVerifier}.
  2252. */
  2253. interface ApplicationVerifier {
  2254. /**
  2255. * Identifies the type of application verifier (e.g. "recaptcha").
  2256. */
  2257. type: string;
  2258. /**
  2259. * Executes the verification process.
  2260. * @return A Promise for a token that can be used to
  2261. * assert the validity of a request.
  2262. */
  2263. verify(): Promise<string>;
  2264. }
  2265. /**
  2266. * Interface representing an Auth instance's settings, currently used for
  2267. * enabling/disabling app verification for phone Auth testing.
  2268. */
  2269. interface AuthSettings {
  2270. /**
  2271. * When set, this property disables app verification for the purpose of testing
  2272. * phone authentication. For this property to take effect, it needs to be set
  2273. * before rendering a reCAPTCHA app verifier. When this is disabled, a
  2274. * mock reCAPTCHA is rendered instead. This is useful for manual testing during
  2275. * development or for automated integration tests.
  2276. *
  2277. * In order to use this feature, you will need to
  2278. * {@link https://firebase.google.com/docs/auth/web/phone-auth#test-with-whitelisted-phone-numbers
  2279. * whitelist your phone number} via the
  2280. * Firebase Console.
  2281. *
  2282. * The default value is false (app verification is enabled).
  2283. */
  2284. appVerificationDisabledForTesting: boolean;
  2285. }
  2286. /**
  2287. * Interface representing the Auth config.
  2288. *
  2289. * @public
  2290. */
  2291. export interface Config {
  2292. /**
  2293. * The API Key used to communicate with the Firebase Auth backend.
  2294. */
  2295. apiKey: string;
  2296. /**
  2297. * The host at which the Firebase Auth backend is running.
  2298. */
  2299. apiHost: string;
  2300. /**
  2301. * The scheme used to communicate with the Firebase Auth backend.
  2302. */
  2303. apiScheme: string;
  2304. /**
  2305. * The host at which the Secure Token API is running.
  2306. */
  2307. tokenApiHost: string;
  2308. /**
  2309. * The SDK Client Version.
  2310. */
  2311. sdkClientVersion: string;
  2312. /**
  2313. * The domain at which the web widgets are hosted (provided via Firebase Config).
  2314. */
  2315. authDomain?: string;
  2316. }
  2317. /**
  2318. * Configuration of Firebase Authentication Emulator.
  2319. */
  2320. export interface EmulatorConfig {
  2321. /**
  2322. * The protocol used to communicate with the emulator ("http"/"https").
  2323. */
  2324. readonly protocol: string;
  2325. /**
  2326. * The hostname of the emulator, which may be a domain ("localhost"), IPv4 address ("127.0.0.1")
  2327. * or quoted IPv6 address ("[::1]").
  2328. */
  2329. readonly host: string;
  2330. /**
  2331. * The port of the emulator, or null if port isn't specified (i.e. protocol default).
  2332. */
  2333. readonly port: number | null;
  2334. /**
  2335. * The emulator-specific options.
  2336. */
  2337. readonly options: {
  2338. /**
  2339. * Whether the warning banner attached to the DOM was disabled.
  2340. */
  2341. readonly disableWarnings: boolean;
  2342. };
  2343. }
  2344. /**
  2345. * The Firebase Auth service interface.
  2346. *
  2347. * Do not call this constructor directly. Instead, use
  2348. * {@link firebase.auth `firebase.auth()`}.
  2349. *
  2350. * See
  2351. * {@link https://firebase.google.com/docs/auth/ Firebase Authentication}
  2352. * for a full guide on how to use the Firebase Auth service.
  2353. *
  2354. */
  2355. interface Auth {
  2356. /** The name of the app associated with the Auth service instance. */
  2357. readonly name: string;
  2358. /** The config used to initialize this instance. */
  2359. readonly config: Config;
  2360. /** The current emulator configuration (or null). */
  2361. readonly emulatorConfig: EmulatorConfig | null;
  2362. /**
  2363. * The {@link firebase.app.App app} associated with the `Auth` service
  2364. * instance.
  2365. *
  2366. * @example
  2367. * ```javascript
  2368. * var app = auth.app;
  2369. * ```
  2370. */
  2371. app: firebase.app.App;
  2372. /**
  2373. * Applies a verification code sent to the user by email or other out-of-band
  2374. * mechanism.
  2375. *
  2376. * <h4>Error Codes</h4>
  2377. * <dl>
  2378. * <dt>auth/expired-action-code</dt>
  2379. * <dd>Thrown if the action code has expired.</dd>
  2380. * <dt>auth/invalid-action-code</dt>
  2381. * <dd>Thrown if the action code is invalid. This can happen if the code is
  2382. * malformed or has already been used.</dd>
  2383. * <dt>auth/user-disabled</dt>
  2384. * <dd>Thrown if the user corresponding to the given action code has been
  2385. * disabled.</dd>
  2386. * <dt>auth/user-not-found</dt>
  2387. * <dd>Thrown if there is no user corresponding to the action code. This may
  2388. * have happened if the user was deleted between when the action code was
  2389. * issued and when this method was called.</dd>
  2390. * </dl>
  2391. *
  2392. * @param code A verification code sent to the user.
  2393. */
  2394. applyActionCode(code: string): Promise<void>;
  2395. /**
  2396. * Checks a verification code sent to the user by email or other out-of-band
  2397. * mechanism.
  2398. *
  2399. * Returns metadata about the code.
  2400. *
  2401. * <h4>Error Codes</h4>
  2402. * <dl>
  2403. * <dt>auth/expired-action-code</dt>
  2404. * <dd>Thrown if the action code has expired.</dd>
  2405. * <dt>auth/invalid-action-code</dt>
  2406. * <dd>Thrown if the action code is invalid. This can happen if the code is
  2407. * malformed or has already been used.</dd>
  2408. * <dt>auth/user-disabled</dt>
  2409. * <dd>Thrown if the user corresponding to the given action code has been
  2410. * disabled.</dd>
  2411. * <dt>auth/user-not-found</dt>
  2412. * <dd>Thrown if there is no user corresponding to the action code. This may
  2413. * have happened if the user was deleted between when the action code was
  2414. * issued and when this method was called.</dd>
  2415. * </dl>
  2416. *
  2417. * @param code A verification code sent to the user.
  2418. */
  2419. checkActionCode(code: string): Promise<firebase.auth.ActionCodeInfo>;
  2420. /**
  2421. * Completes the password reset process, given a confirmation code and new
  2422. * password.
  2423. *
  2424. * <h4>Error Codes</h4>
  2425. * <dl>
  2426. * <dt>auth/expired-action-code</dt>
  2427. * <dd>Thrown if the password reset code has expired.</dd>
  2428. * <dt>auth/invalid-action-code</dt>
  2429. * <dd>Thrown if the password reset code is invalid. This can happen if the
  2430. * code is malformed or has already been used.</dd>
  2431. * <dt>auth/user-disabled</dt>
  2432. * <dd>Thrown if the user corresponding to the given password reset code has
  2433. * been disabled.</dd>
  2434. * <dt>auth/user-not-found</dt>
  2435. * <dd>Thrown if there is no user corresponding to the password reset code. This
  2436. * may have happened if the user was deleted between when the code was
  2437. * issued and when this method was called.</dd>
  2438. * <dt>auth/weak-password</dt>
  2439. * <dd>Thrown if the new password is not strong enough.</dd>
  2440. * </dl>
  2441. *
  2442. * @param code The confirmation code send via email to the user.
  2443. * @param newPassword The new password.
  2444. */
  2445. confirmPasswordReset(code: string, newPassword: string): Promise<void>;
  2446. /**
  2447. * Creates a new user account associated with the specified email address and
  2448. * password.
  2449. *
  2450. * On successful creation of the user account, this user will also be
  2451. * signed in to your application.
  2452. *
  2453. * User account creation can fail if the account already exists or the password
  2454. * is invalid.
  2455. *
  2456. * Note: The email address acts as a unique identifier for the user and
  2457. * enables an email-based password reset. This function will create
  2458. * a new user account and set the initial user password.
  2459. *
  2460. * <h4>Error Codes</h4>
  2461. * <dl>
  2462. * <dt>auth/email-already-in-use</dt>
  2463. * <dd>Thrown if there already exists an account with the given email
  2464. * address.</dd>
  2465. * <dt>auth/invalid-email</dt>
  2466. * <dd>Thrown if the email address is not valid.</dd>
  2467. * <dt>auth/operation-not-allowed</dt>
  2468. * <dd>Thrown if email/password accounts are not enabled. Enable email/password
  2469. * accounts in the Firebase Console, under the Auth tab.</dd>
  2470. * <dt>auth/weak-password</dt>
  2471. * <dd>Thrown if the password is not strong enough.</dd>
  2472. * </dl>
  2473. *
  2474. * @example
  2475. * ```javascript
  2476. * firebase.auth().createUserWithEmailAndPassword(email, password)
  2477. * .catch(function(error) {
  2478. * // Handle Errors here.
  2479. * var errorCode = error.code;
  2480. * var errorMessage = error.message;
  2481. * if (errorCode == 'auth/weak-password') {
  2482. * alert('The password is too weak.');
  2483. * } else {
  2484. * alert(errorMessage);
  2485. * }
  2486. * console.log(error);
  2487. * });
  2488. * ```
  2489. * @param email The user's email address.
  2490. * @param password The user's chosen password.
  2491. */
  2492. createUserWithEmailAndPassword(
  2493. email: string,
  2494. password: string
  2495. ): Promise<firebase.auth.UserCredential>;
  2496. /**
  2497. * The currently signed-in user (or null).
  2498. */
  2499. currentUser: firebase.User | null;
  2500. /**
  2501. * Gets the list of possible sign in methods for the given email address. This
  2502. * is useful to differentiate methods of sign-in for the same provider,
  2503. * eg. `EmailAuthProvider` which has 2 methods of sign-in, email/password and
  2504. * email/link.
  2505. *
  2506. * <h4>Error Codes</h4>
  2507. * <dl>
  2508. * <dt>auth/invalid-email</dt>
  2509. * <dd>Thrown if the email address is not valid.</dd>
  2510. * </dl>
  2511. */
  2512. fetchSignInMethodsForEmail(email: string): Promise<Array<string>>;
  2513. /**
  2514. * Checks if an incoming link is a sign-in with email link.
  2515. */
  2516. isSignInWithEmailLink(emailLink: string): boolean;
  2517. /**
  2518. * Returns a UserCredential from the redirect-based sign-in flow.
  2519. *
  2520. * If sign-in succeeded, returns the signed in user. If sign-in was
  2521. * unsuccessful, fails with an error. If no redirect operation was called, returns `null`.
  2522. *
  2523. * <h4>Error Codes</h4>
  2524. * <dl>
  2525. * <dt>auth/account-exists-with-different-credential</dt>
  2526. * <dd>Thrown if there already exists an account with the email address
  2527. * asserted by the credential. Resolve this by calling
  2528. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} with the error.email
  2529. * and then asking the user to sign in using one of the returned providers.
  2530. * Once the user is signed in, the original credential retrieved from the
  2531. * error.credential can be linked to the user with
  2532. * {@link firebase.User.linkWithCredential} to prevent the user from signing
  2533. * in again to the original provider via popup or redirect. If you are using
  2534. * redirects for sign in, save the credential in session storage and then
  2535. * retrieve on redirect and repopulate the credential using for example
  2536. * {@link firebase.auth.GoogleAuthProvider.credential} depending on the
  2537. * credential provider id and complete the link.</dd>
  2538. * <dt>auth/auth-domain-config-required</dt>
  2539. * <dd>Thrown if authDomain configuration is not provided when calling
  2540. * firebase.initializeApp(). Check Firebase Console for instructions on
  2541. * determining and passing that field.</dd>
  2542. * <dt>auth/credential-already-in-use</dt>
  2543. * <dd>Thrown if the account corresponding to the credential already exists
  2544. * among your users, or is already linked to a Firebase User.
  2545. * For example, this error could be thrown if you are upgrading an anonymous
  2546. * user to a Google user by linking a Google credential to it and the Google
  2547. * credential used is already associated with an existing Firebase Google
  2548. * user.
  2549. * An <code>error.email</code> and <code>error.credential</code>
  2550. * ({@link firebase.auth.AuthCredential}) fields are also provided. You can
  2551. * recover from this error by signing in with that credential directly via
  2552. * {@link firebase.auth.Auth.signInWithCredential}.</dd>
  2553. * <dt>auth/email-already-in-use</dt>
  2554. * <dd>Thrown if the email corresponding to the credential already exists
  2555. * among your users. When thrown while linking a credential to an existing
  2556. * user, an <code>error.email</code> and <code>error.credential</code>
  2557. * ({@link firebase.auth.AuthCredential}) fields are also provided.
  2558. * You have to link the credential to the existing user with that email if
  2559. * you wish to continue signing in with that credential. To do so, call
  2560. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
  2561. * <code>error.email</code> via one of the providers returned and then
  2562. * {@link firebase.User.linkWithCredential} the original credential to that
  2563. * newly signed in user.</dd>
  2564. * <dt>auth/operation-not-allowed</dt>
  2565. * <dd>Thrown if the type of account corresponding to the credential
  2566. * is not enabled. Enable the account type in the Firebase Console, under
  2567. * the Auth tab.</dd>
  2568. * <dt>auth/operation-not-supported-in-this-environment</dt>
  2569. * <dd>Thrown if this operation is not supported in the environment your
  2570. * application is running on. "location.protocol" must be http or https.
  2571. * </dd>
  2572. * <dt>auth/timeout</dt>
  2573. * <dd>Thrown typically if the app domain is not authorized for OAuth operations
  2574. * for your Firebase project. Edit the list of authorized domains from the
  2575. * Firebase console.</dd>
  2576. * </dl>
  2577. *
  2578. * This method does not work in a Node.js environment.
  2579. *
  2580. * @example
  2581. * ```javascript
  2582. * // First, we perform the signInWithRedirect.
  2583. * // Creates the provider object.
  2584. * var provider = new firebase.auth.FacebookAuthProvider();
  2585. * // You can add additional scopes to the provider:
  2586. * provider.addScope('email');
  2587. * provider.addScope('user_friends');
  2588. * // Sign in with redirect:
  2589. * auth.signInWithRedirect(provider)
  2590. * ////////////////////////////////////////////////////////////
  2591. * // The user is redirected to the provider's sign in flow...
  2592. * ////////////////////////////////////////////////////////////
  2593. * // Then redirected back to the app, where we check the redirect result:
  2594. * auth.getRedirectResult().then(function(result) {
  2595. * // The firebase.User instance:
  2596. * var user = result.user;
  2597. * // The Facebook firebase.auth.AuthCredential containing the Facebook
  2598. * // access token:
  2599. * var credential = result.credential;
  2600. * // As this API can be used for sign-in, linking and reauthentication,
  2601. * // check the operationType to determine what triggered this redirect
  2602. * // operation.
  2603. * var operationType = result.operationType;
  2604. * }, function(error) {
  2605. * // The provider's account email, can be used in case of
  2606. * // auth/account-exists-with-different-credential to fetch the providers
  2607. * // linked to the email:
  2608. * var email = error.email;
  2609. * // The provider's credential:
  2610. * var credential = error.credential;
  2611. * // In case of auth/account-exists-with-different-credential error,
  2612. * // you can fetch the providers using this:
  2613. * if (error.code === 'auth/account-exists-with-different-credential') {
  2614. * auth.fetchSignInMethodsForEmail(email).then(function(providers) {
  2615. * // The returned 'providers' is a list of the available providers
  2616. * // linked to the email address. Please refer to the guide for a more
  2617. * // complete explanation on how to recover from this error.
  2618. * });
  2619. * }
  2620. * });
  2621. * ```
  2622. */
  2623. getRedirectResult(): Promise<firebase.auth.UserCredential>;
  2624. /**
  2625. * The current Auth instance's language code. This is a readable/writable
  2626. * property. When set to null, the default Firebase Console language setting
  2627. * is applied. The language code will propagate to email action templates
  2628. * (password reset, email verification and email change revocation), SMS
  2629. * templates for phone authentication, reCAPTCHA verifier and OAuth
  2630. * popup/redirect operations provided the specified providers support
  2631. * localization with the language code specified.
  2632. */
  2633. languageCode: string | null;
  2634. /**
  2635. * The current Auth instance's settings. This is used to edit/read configuration
  2636. * related options like app verification mode for phone authentication.
  2637. */
  2638. settings: firebase.auth.AuthSettings;
  2639. /**
  2640. * Adds an observer for changes to the user's sign-in state.
  2641. *
  2642. * Prior to 4.0.0, this triggered the observer when users were signed in,
  2643. * signed out, or when the user's ID token changed in situations such as token
  2644. * expiry or password change. After 4.0.0, the observer is only triggered
  2645. * on sign-in or sign-out.
  2646. *
  2647. * To keep the old behavior, see {@link firebase.auth.Auth.onIdTokenChanged}.
  2648. *
  2649. * @example
  2650. * ```javascript
  2651. * firebase.auth().onAuthStateChanged(function(user) {
  2652. * if (user) {
  2653. * // User is signed in.
  2654. * }
  2655. * });
  2656. * ```
  2657. */
  2658. onAuthStateChanged(
  2659. nextOrObserver:
  2660. | firebase.Observer<any>
  2661. | ((a: firebase.User | null) => any),
  2662. error?: (a: firebase.auth.Error) => any,
  2663. completed?: firebase.Unsubscribe
  2664. ): firebase.Unsubscribe;
  2665. /**
  2666. * Adds an observer for changes to the signed-in user's ID token, which includes
  2667. * sign-in, sign-out, and token refresh events. This method has the same
  2668. * behavior as {@link firebase.auth.Auth.onAuthStateChanged} had prior to 4.0.0.
  2669. *
  2670. * @example
  2671. * ```javascript
  2672. * firebase.auth().onIdTokenChanged(function(user) {
  2673. * if (user) {
  2674. * // User is signed in or token was refreshed.
  2675. * }
  2676. * });
  2677. * ```
  2678. * @param
  2679. * nextOrObserver An observer object or a function triggered on change.
  2680. * @param error Optional A function
  2681. * triggered on auth error.
  2682. * @param completed Optional A function triggered when the
  2683. * observer is removed.
  2684. */
  2685. onIdTokenChanged(
  2686. nextOrObserver:
  2687. | firebase.Observer<any>
  2688. | ((a: firebase.User | null) => any),
  2689. error?: (a: firebase.auth.Error) => any,
  2690. completed?: firebase.Unsubscribe
  2691. ): firebase.Unsubscribe;
  2692. /**
  2693. * Sends a sign-in email link to the user with the specified email.
  2694. *
  2695. * The sign-in operation has to always be completed in the app unlike other out
  2696. * of band email actions (password reset and email verifications). This is
  2697. * because, at the end of the flow, the user is expected to be signed in and
  2698. * their Auth state persisted within the app.
  2699. *
  2700. * To complete sign in with the email link, call
  2701. * {@link firebase.auth.Auth.signInWithEmailLink} with the email address and
  2702. * the email link supplied in the email sent to the user.
  2703. *
  2704. * <h4>Error Codes</h4>
  2705. * <dl>
  2706. * <dt>auth/argument-error</dt>
  2707. * <dd>Thrown if handleCodeInApp is false.</dd>
  2708. * <dt>auth/invalid-email</dt>
  2709. * <dd>Thrown if the email address is not valid.</dd>
  2710. * <dt>auth/missing-android-pkg-name</dt>
  2711. * <dd>An Android package name must be provided if the Android app is required
  2712. * to be installed.</dd>
  2713. * <dt>auth/missing-continue-uri</dt>
  2714. * <dd>A continue URL must be provided in the request.</dd>
  2715. * <dt>auth/missing-ios-bundle-id</dt>
  2716. * <dd>An iOS Bundle ID must be provided if an App Store ID is provided.</dd>
  2717. * <dt>auth/invalid-continue-uri</dt>
  2718. * <dd>The continue URL provided in the request is invalid.</dd>
  2719. * <dt>auth/unauthorized-continue-uri</dt>
  2720. * <dd>The domain of the continue URL is not whitelisted. Whitelist
  2721. * the domain in the Firebase console.</dd>
  2722. * </dl>
  2723. *
  2724. * @example
  2725. * ```javascript
  2726. * var actionCodeSettings = {
  2727. * // The URL to redirect to for sign-in completion. This is also the deep
  2728. * // link for mobile redirects. The domain (www.example.com) for this URL
  2729. * // must be whitelisted in the Firebase Console.
  2730. * url: 'https://www.example.com/finishSignUp?cartId=1234',
  2731. * iOS: {
  2732. * bundleId: 'com.example.ios'
  2733. * },
  2734. * android: {
  2735. * packageName: 'com.example.android',
  2736. * installApp: true,
  2737. * minimumVersion: '12'
  2738. * },
  2739. * // This must be true.
  2740. * handleCodeInApp: true
  2741. * };
  2742. * firebase.auth().sendSignInLinkToEmail('user@example.com', actionCodeSettings)
  2743. * .then(function() {
  2744. * // The link was successfully sent. Inform the user. Save the email
  2745. * // locally so you don't need to ask the user for it again if they open
  2746. * // the link on the same device.
  2747. * })
  2748. * .catch(function(error) {
  2749. * // Some error occurred, you can inspect the code: error.code
  2750. * });
  2751. * ```
  2752. * @param email The email account to sign in with.
  2753. * @param actionCodeSettings The action
  2754. * code settings. The action code settings which provides Firebase with
  2755. * instructions on how to construct the email link. This includes the
  2756. * sign in completion URL or the deep link for mobile redirects, the mobile
  2757. * apps to use when the sign-in link is opened on an Android or iOS device.
  2758. * Mobile app redirects will only be applicable if the developer configures
  2759. * and accepts the Firebase Dynamic Links terms of condition.
  2760. * The Android package name and iOS bundle ID will be respected only if they
  2761. * are configured in the same Firebase Auth project used.
  2762. */
  2763. sendSignInLinkToEmail(
  2764. email: string,
  2765. actionCodeSettings: firebase.auth.ActionCodeSettings
  2766. ): Promise<void>;
  2767. /**
  2768. * Sends a password reset email to the given email address.
  2769. *
  2770. * To complete the password reset, call
  2771. * {@link firebase.auth.Auth.confirmPasswordReset} with the code supplied in the
  2772. * email sent to the user, along with the new password specified by the user.
  2773. *
  2774. * <h4>Error Codes</h4>
  2775. * <dl>
  2776. * <dt>auth/invalid-email</dt>
  2777. * <dd>Thrown if the email address is not valid.</dd>
  2778. * <dt>auth/missing-android-pkg-name</dt>
  2779. * <dd>An Android package name must be provided if the Android app is required
  2780. * to be installed.</dd>
  2781. * <dt>auth/missing-continue-uri</dt>
  2782. * <dd>A continue URL must be provided in the request.</dd>
  2783. * <dt>auth/missing-ios-bundle-id</dt>
  2784. * <dd>An iOS Bundle ID must be provided if an App Store ID is provided.</dd>
  2785. * <dt>auth/invalid-continue-uri</dt>
  2786. * <dd>The continue URL provided in the request is invalid.</dd>
  2787. * <dt>auth/unauthorized-continue-uri</dt>
  2788. * <dd>The domain of the continue URL is not whitelisted. Whitelist
  2789. * the domain in the Firebase console.</dd>
  2790. * <dt>auth/user-not-found</dt>
  2791. * <dd>Thrown if there is no user corresponding to the email address.</dd>
  2792. * </dl>
  2793. *
  2794. * @example
  2795. * ```javascript
  2796. * var actionCodeSettings = {
  2797. * url: 'https://www.example.com/?email=user@example.com',
  2798. * iOS: {
  2799. * bundleId: 'com.example.ios'
  2800. * },
  2801. * android: {
  2802. * packageName: 'com.example.android',
  2803. * installApp: true,
  2804. * minimumVersion: '12'
  2805. * },
  2806. * handleCodeInApp: true
  2807. * };
  2808. * firebase.auth().sendPasswordResetEmail(
  2809. * 'user@example.com', actionCodeSettings)
  2810. * .then(function() {
  2811. * // Password reset email sent.
  2812. * })
  2813. * .catch(function(error) {
  2814. * // Error occurred. Inspect error.code.
  2815. * });
  2816. * ```
  2817. *
  2818. * @param email The email address with the password to be reset.
  2819. * @param actionCodeSettings The action
  2820. * code settings. If specified, the state/continue URL will be set as the
  2821. * "continueUrl" parameter in the password reset link. The default password
  2822. * reset landing page will use this to display a link to go back to the app
  2823. * if it is installed.
  2824. * If the actionCodeSettings is not specified, no URL is appended to the
  2825. * action URL.
  2826. * The state URL provided must belong to a domain that is whitelisted by the
  2827. * developer in the console. Otherwise an error will be thrown.
  2828. * Mobile app redirects will only be applicable if the developer configures
  2829. * and accepts the Firebase Dynamic Links terms of condition.
  2830. * The Android package name and iOS bundle ID will be respected only if they
  2831. * are configured in the same Firebase Auth project used.
  2832. */
  2833. sendPasswordResetEmail(
  2834. email: string,
  2835. actionCodeSettings?: firebase.auth.ActionCodeSettings | null
  2836. ): Promise<void>;
  2837. /**
  2838. * Changes the current type of persistence on the current Auth instance for the
  2839. * currently saved Auth session and applies this type of persistence for
  2840. * future sign-in requests, including sign-in with redirect requests. This will
  2841. * return a promise that will resolve once the state finishes copying from one
  2842. * type of storage to the other.
  2843. * Calling a sign-in method after changing persistence will wait for that
  2844. * persistence change to complete before applying it on the new Auth state.
  2845. *
  2846. * This makes it easy for a user signing in to specify whether their session
  2847. * should be remembered or not. It also makes it easier to never persist the
  2848. * Auth state for applications that are shared by other users or have sensitive
  2849. * data.
  2850. *
  2851. * The default for web browser apps and React Native apps is 'local' (provided
  2852. * the browser supports this mechanism) whereas it is 'none' for Node.js backend
  2853. * apps.
  2854. *
  2855. * <h4>Error Codes (thrown synchronously)</h4>
  2856. * <dl>
  2857. * <dt>auth/invalid-persistence-type</dt>
  2858. * <dd>Thrown if the specified persistence type is invalid.</dd>
  2859. * <dt>auth/unsupported-persistence-type</dt>
  2860. * <dd>Thrown if the current environment does not support the specified
  2861. * persistence type.</dd>
  2862. * </dl>
  2863. *
  2864. * @example
  2865. * ```javascript
  2866. * firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
  2867. * .then(function() {
  2868. * // Existing and future Auth states are now persisted in the current
  2869. * // session only. Closing the window would clear any existing state even if
  2870. * // a user forgets to sign out.
  2871. * });
  2872. * ```
  2873. */
  2874. setPersistence(persistence: firebase.auth.Auth.Persistence): Promise<void>;
  2875. /**
  2876. * Asynchronously signs in with the given credentials, and returns any available
  2877. * additional user information, such as user name.
  2878. *
  2879. * <h4>Error Codes</h4>
  2880. * <dl>
  2881. * <dt>auth/account-exists-with-different-credential</dt>
  2882. * <dd>Thrown if there already exists an account with the email address
  2883. * asserted by the credential. Resolve this by calling
  2884. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} and then asking the
  2885. * user to sign in using one of the returned providers. Once the user is
  2886. * signed in, the original credential can be linked to the user with
  2887. * {@link firebase.User.linkWithCredential}.</dd>
  2888. * <dt>auth/invalid-credential</dt>
  2889. * <dd>Thrown if the credential is malformed or has expired.</dd>
  2890. * <dt>auth/operation-not-allowed</dt>
  2891. * <dd>Thrown if the type of account corresponding to the credential
  2892. * is not enabled. Enable the account type in the Firebase Console, under
  2893. * the Auth tab.</dd>
  2894. * <dt>auth/user-disabled</dt>
  2895. * <dd>Thrown if the user corresponding to the given credential has been
  2896. * disabled.</dd>
  2897. * <dt>auth/user-not-found</dt>
  2898. * <dd>Thrown if signing in with a credential from
  2899. * {@link firebase.auth.EmailAuthProvider.credential} and there is no user
  2900. * corresponding to the given email. </dd>
  2901. * <dt>auth/wrong-password</dt>
  2902. * <dd>Thrown if signing in with a credential from
  2903. * {@link firebase.auth.EmailAuthProvider.credential} and the password is
  2904. * invalid for the given email, or if the account corresponding to the email
  2905. * does not have a password set.</dd>
  2906. * <dt>auth/invalid-verification-code</dt>
  2907. * <dd>Thrown if the credential is a
  2908. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  2909. * code of the credential is not valid.</dd>
  2910. * <dt>auth/invalid-verification-id</dt>
  2911. * <dd>Thrown if the credential is a
  2912. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  2913. * ID of the credential is not valid.</dd>
  2914. * </dl>
  2915. *
  2916. * @deprecated
  2917. * This method is deprecated. Use
  2918. * {@link firebase.auth.Auth.signInWithCredential} instead.
  2919. *
  2920. * @example
  2921. * ```javascript
  2922. * firebase.auth().signInAndRetrieveDataWithCredential(credential)
  2923. * .then(function(userCredential) {
  2924. * console.log(userCredential.additionalUserInfo.username);
  2925. * });
  2926. * ```
  2927. * @param credential The auth credential.
  2928. */
  2929. signInAndRetrieveDataWithCredential(
  2930. credential: firebase.auth.AuthCredential
  2931. ): Promise<firebase.auth.UserCredential>;
  2932. /**
  2933. * Asynchronously signs in as an anonymous user.
  2934. *
  2935. *
  2936. * If there is already an anonymous user signed in, that user will be returned;
  2937. * otherwise, a new anonymous user identity will be created and returned.
  2938. *
  2939. * <h4>Error Codes</h4>
  2940. * <dl>
  2941. * <dt>auth/operation-not-allowed</dt>
  2942. * <dd>Thrown if anonymous accounts are not enabled. Enable anonymous accounts
  2943. * in the Firebase Console, under the Auth tab.</dd>
  2944. * </dl>
  2945. *
  2946. * @example
  2947. * ```javascript
  2948. * firebase.auth().signInAnonymously().catch(function(error) {
  2949. * // Handle Errors here.
  2950. * var errorCode = error.code;
  2951. * var errorMessage = error.message;
  2952. *
  2953. * if (errorCode === 'auth/operation-not-allowed') {
  2954. * alert('You must enable Anonymous auth in the Firebase Console.');
  2955. * } else {
  2956. * console.error(error);
  2957. * }
  2958. * });
  2959. * ```
  2960. */
  2961. signInAnonymously(): Promise<firebase.auth.UserCredential>;
  2962. /**
  2963. * Asynchronously signs in with the given credentials.
  2964. *
  2965. * <h4>Error Codes</h4>
  2966. * <dl>
  2967. * <dt>auth/account-exists-with-different-credential</dt>
  2968. * <dd>Thrown if there already exists an account with the email address
  2969. * asserted by the credential. Resolve this by calling
  2970. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} and then asking the
  2971. * user to sign in using one of the returned providers. Once the user is
  2972. * signed in, the original credential can be linked to the user with
  2973. * {@link firebase.User.linkWithCredential}.</dd>
  2974. * <dt>auth/invalid-credential</dt>
  2975. * <dd>Thrown if the credential is malformed or has expired.</dd>
  2976. * <dt>auth/operation-not-allowed</dt>
  2977. * <dd>Thrown if the type of account corresponding to the credential
  2978. * is not enabled. Enable the account type in the Firebase Console, under
  2979. * the Auth tab.</dd>
  2980. * <dt>auth/user-disabled</dt>
  2981. * <dd>Thrown if the user corresponding to the given credential has been
  2982. * disabled.</dd>
  2983. * <dt>auth/user-not-found</dt>
  2984. * <dd>Thrown if signing in with a credential from
  2985. * {@link firebase.auth.EmailAuthProvider.credential} and there is no user
  2986. * corresponding to the given email. </dd>
  2987. * <dt>auth/wrong-password</dt>
  2988. * <dd>Thrown if signing in with a credential from
  2989. * {@link firebase.auth.EmailAuthProvider.credential} and the password is
  2990. * invalid for the given email, or if the account corresponding to the email
  2991. * does not have a password set.</dd>
  2992. * <dt>auth/invalid-verification-code</dt>
  2993. * <dd>Thrown if the credential is a
  2994. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  2995. * code of the credential is not valid.</dd>
  2996. * <dt>auth/invalid-verification-id</dt>
  2997. * <dd>Thrown if the credential is a
  2998. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  2999. * ID of the credential is not valid.</dd>
  3000. * </dl>
  3001. *
  3002. * @example
  3003. * ```javascript
  3004. * firebase.auth().signInWithCredential(credential).catch(function(error) {
  3005. * // Handle Errors here.
  3006. * var errorCode = error.code;
  3007. * var errorMessage = error.message;
  3008. * // The email of the user's account used.
  3009. * var email = error.email;
  3010. * // The firebase.auth.AuthCredential type that was used.
  3011. * var credential = error.credential;
  3012. * if (errorCode === 'auth/account-exists-with-different-credential') {
  3013. * alert('Email already associated with another account.');
  3014. * // Handle account linking here, if using.
  3015. * } else {
  3016. * console.error(error);
  3017. * }
  3018. * });
  3019. * ```
  3020. *
  3021. * @param credential The auth credential.
  3022. */
  3023. signInWithCredential(
  3024. credential: firebase.auth.AuthCredential
  3025. ): Promise<firebase.auth.UserCredential>;
  3026. /**
  3027. * Asynchronously signs in using a custom token.
  3028. *
  3029. * Custom tokens are used to integrate Firebase Auth with existing auth systems,
  3030. * and must be generated by the auth backend.
  3031. *
  3032. * Fails with an error if the token is invalid, expired, or not accepted by the
  3033. * Firebase Auth service.
  3034. *
  3035. * <h4>Error Codes</h4>
  3036. * <dl>
  3037. * <dt>auth/custom-token-mismatch</dt>
  3038. * <dd>Thrown if the custom token is for a different Firebase App.</dd>
  3039. * <dt>auth/invalid-custom-token</dt>
  3040. * <dd>Thrown if the custom token format is incorrect.</dd>
  3041. * </dl>
  3042. *
  3043. * @example
  3044. * ```javascript
  3045. * firebase.auth().signInWithCustomToken(token).catch(function(error) {
  3046. * // Handle Errors here.
  3047. * var errorCode = error.code;
  3048. * var errorMessage = error.message;
  3049. * if (errorCode === 'auth/invalid-custom-token') {
  3050. * alert('The token you provided is not valid.');
  3051. * } else {
  3052. * console.error(error);
  3053. * }
  3054. * });
  3055. * ```
  3056. *
  3057. * @param token The custom token to sign in with.
  3058. */
  3059. signInWithCustomToken(token: string): Promise<firebase.auth.UserCredential>;
  3060. /**
  3061. * Asynchronously signs in using an email and password.
  3062. *
  3063. * Fails with an error if the email address and password do not match.
  3064. *
  3065. * Note: The user's password is NOT the password used to access the user's email
  3066. * account. The email address serves as a unique identifier for the user, and
  3067. * the password is used to access the user's account in your Firebase project.
  3068. *
  3069. * See also: {@link firebase.auth.Auth.createUserWithEmailAndPassword}.
  3070. *
  3071. * <h4>Error Codes</h4>
  3072. * <dl>
  3073. * <dt>auth/invalid-email</dt>
  3074. * <dd>Thrown if the email address is not valid.</dd>
  3075. * <dt>auth/user-disabled</dt>
  3076. * <dd>Thrown if the user corresponding to the given email has been
  3077. * disabled.</dd>
  3078. * <dt>auth/user-not-found</dt>
  3079. * <dd>Thrown if there is no user corresponding to the given email.</dd>
  3080. * <dt>auth/wrong-password</dt>
  3081. * <dd>Thrown if the password is invalid for the given email, or the account
  3082. * corresponding to the email does not have a password set.</dd>
  3083. * </dl>
  3084. *
  3085. * @example
  3086. * ```javascript
  3087. * firebase.auth().signInWithEmailAndPassword(email, password)
  3088. * .catch(function(error) {
  3089. * // Handle Errors here.
  3090. * var errorCode = error.code;
  3091. * var errorMessage = error.message;
  3092. * if (errorCode === 'auth/wrong-password') {
  3093. * alert('Wrong password.');
  3094. * } else {
  3095. * alert(errorMessage);
  3096. * }
  3097. * console.log(error);
  3098. * });
  3099. * ```
  3100. *
  3101. * @param email The users email address.
  3102. * @param password The users password.
  3103. */
  3104. signInWithEmailAndPassword(
  3105. email: string,
  3106. password: string
  3107. ): Promise<firebase.auth.UserCredential>;
  3108. /**
  3109. * Asynchronously signs in using a phone number. This method sends a code via
  3110. * SMS to the given phone number, and returns a
  3111. * {@link firebase.auth.ConfirmationResult}. After the user provides the code
  3112. * sent to their phone, call {@link firebase.auth.ConfirmationResult.confirm}
  3113. * with the code to sign the user in.
  3114. *
  3115. * For abuse prevention, this method also requires a
  3116. * {@link firebase.auth.ApplicationVerifier}. The Firebase Auth SDK includes
  3117. * a reCAPTCHA-based implementation, {@link firebase.auth.RecaptchaVerifier}.
  3118. *
  3119. * <h4>Error Codes</h4>
  3120. * <dl>
  3121. * <dt>auth/captcha-check-failed</dt>
  3122. * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
  3123. * this method was called from a non-whitelisted domain.</dd>
  3124. * <dt>auth/invalid-phone-number</dt>
  3125. * <dd>Thrown if the phone number has an invalid format.</dd>
  3126. * <dt>auth/missing-phone-number</dt>
  3127. * <dd>Thrown if the phone number is missing.</dd>
  3128. * <dt>auth/quota-exceeded</dt>
  3129. * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
  3130. * <dt>auth/user-disabled</dt>
  3131. * <dd>Thrown if the user corresponding to the given phone number has been
  3132. * disabled.</dd>
  3133. * <dt>auth/operation-not-allowed</dt>
  3134. * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
  3135. * to the Firebase Console for your project, in the Auth section and the
  3136. * <strong>Sign in Method</strong> tab and configure the provider.</dd>
  3137. * </dl>
  3138. *
  3139. * @example
  3140. * ```javascript
  3141. * // 'recaptcha-container' is the ID of an element in the DOM.
  3142. * var applicationVerifier = new firebase.auth.RecaptchaVerifier(
  3143. * 'recaptcha-container');
  3144. * firebase.auth().signInWithPhoneNumber(phoneNumber, applicationVerifier)
  3145. * .then(function(confirmationResult) {
  3146. * var verificationCode = window.prompt('Please enter the verification ' +
  3147. * 'code that was sent to your mobile device.');
  3148. * return confirmationResult.confirm(verificationCode);
  3149. * })
  3150. * .catch(function(error) {
  3151. * // Handle Errors here.
  3152. * });
  3153. * ```
  3154. *
  3155. * @param phoneNumber The user's phone number in E.164 format (e.g.
  3156. * +16505550101).
  3157. * @param applicationVerifier
  3158. */
  3159. signInWithPhoneNumber(
  3160. phoneNumber: string,
  3161. applicationVerifier: firebase.auth.ApplicationVerifier
  3162. ): Promise<firebase.auth.ConfirmationResult>;
  3163. /**
  3164. * Asynchronously signs in using an email and sign-in email link. If no link
  3165. * is passed, the link is inferred from the current URL.
  3166. *
  3167. * Fails with an error if the email address is invalid or OTP in email link
  3168. * expires.
  3169. *
  3170. * Note: Confirm the link is a sign-in email link before calling this method
  3171. * {@link firebase.auth.Auth.isSignInWithEmailLink}.
  3172. *
  3173. * <h4>Error Codes</h4>
  3174. * <dl>
  3175. * <dt>auth/expired-action-code</dt>
  3176. * <dd>Thrown if OTP in email link expires.</dd>
  3177. * <dt>auth/invalid-email</dt>
  3178. * <dd>Thrown if the email address is not valid.</dd>
  3179. * <dt>auth/user-disabled</dt>
  3180. * <dd>Thrown if the user corresponding to the given email has been
  3181. * disabled.</dd>
  3182. * </dl>
  3183. *
  3184. * @example
  3185. * ```javascript
  3186. * firebase.auth().signInWithEmailLink(email, emailLink)
  3187. * .catch(function(error) {
  3188. * // Some error occurred, you can inspect the code: error.code
  3189. * // Common errors could be invalid email and invalid or expired OTPs.
  3190. * });
  3191. * ```
  3192. *
  3193. * @param email The email account to sign in with.
  3194. * @param emailLink The optional link which contains the OTP needed
  3195. * to complete the sign in with email link. If not specified, the current
  3196. * URL is used instead.
  3197. */
  3198. signInWithEmailLink(
  3199. email: string,
  3200. emailLink?: string
  3201. ): Promise<firebase.auth.UserCredential>;
  3202. /**
  3203. * Authenticates a Firebase client using a popup-based OAuth authentication
  3204. * flow.
  3205. *
  3206. * If succeeds, returns the signed in user along with the provider's credential.
  3207. * If sign in was unsuccessful, returns an error object containing additional
  3208. * information about the error.
  3209. *
  3210. * <h4>Error Codes</h4>
  3211. * <dl>
  3212. * <dt>auth/account-exists-with-different-credential</dt>
  3213. * <dd>Thrown if there already exists an account with the email address
  3214. * asserted by the credential. Resolve this by calling
  3215. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} with the error.email
  3216. * and then asking the user to sign in using one of the returned providers.
  3217. * Once the user is signed in, the original credential retrieved from the
  3218. * error.credential can be linked to the user with
  3219. * {@link firebase.User.linkWithCredential} to prevent the user from signing
  3220. * in again to the original provider via popup or redirect. If you are using
  3221. * redirects for sign in, save the credential in session storage and then
  3222. * retrieve on redirect and repopulate the credential using for example
  3223. * {@link firebase.auth.GoogleAuthProvider.credential} depending on the
  3224. * credential provider id and complete the link.</dd>
  3225. * <dt>auth/auth-domain-config-required</dt>
  3226. * <dd>Thrown if authDomain configuration is not provided when calling
  3227. * firebase.initializeApp(). Check Firebase Console for instructions on
  3228. * determining and passing that field.</dd>
  3229. * <dt>auth/cancelled-popup-request</dt>
  3230. * <dd>Thrown if successive popup operations are triggered. Only one popup
  3231. * request is allowed at one time. All the popups would fail with this error
  3232. * except for the last one.</dd>
  3233. * <dt>auth/operation-not-allowed</dt>
  3234. * <dd>Thrown if the type of account corresponding to the credential
  3235. * is not enabled. Enable the account type in the Firebase Console, under
  3236. * the Auth tab.</dd>
  3237. * <dt>auth/operation-not-supported-in-this-environment</dt>
  3238. * <dd>Thrown if this operation is not supported in the environment your
  3239. * application is running on. "location.protocol" must be http or https.
  3240. * </dd>
  3241. * <dt>auth/popup-blocked</dt>
  3242. * <dd>Thrown if the popup was blocked by the browser, typically when this
  3243. * operation is triggered outside of a click handler.</dd>
  3244. * <dt>auth/popup-closed-by-user</dt>
  3245. * <dd>Thrown if the popup window is closed by the user without completing the
  3246. * sign in to the provider.</dd>
  3247. * <dt>auth/unauthorized-domain</dt>
  3248. * <dd>Thrown if the app domain is not authorized for OAuth operations for your
  3249. * Firebase project. Edit the list of authorized domains from the Firebase
  3250. * console.</dd>
  3251. * </dl>
  3252. *
  3253. * This method does not work in a Node.js environment.
  3254. *
  3255. * @example
  3256. * ```javascript
  3257. * // Creates the provider object.
  3258. * var provider = new firebase.auth.FacebookAuthProvider();
  3259. * // You can add additional scopes to the provider:
  3260. * provider.addScope('email');
  3261. * provider.addScope('user_friends');
  3262. * // Sign in with popup:
  3263. * auth.signInWithPopup(provider).then(function(result) {
  3264. * // The firebase.User instance:
  3265. * var user = result.user;
  3266. * // The Facebook firebase.auth.AuthCredential containing the Facebook
  3267. * // access token:
  3268. * var credential = result.credential;
  3269. * }, function(error) {
  3270. * // The provider's account email, can be used in case of
  3271. * // auth/account-exists-with-different-credential to fetch the providers
  3272. * // linked to the email:
  3273. * var email = error.email;
  3274. * // The provider's credential:
  3275. * var credential = error.credential;
  3276. * // In case of auth/account-exists-with-different-credential error,
  3277. * // you can fetch the providers using this:
  3278. * if (error.code === 'auth/account-exists-with-different-credential') {
  3279. * auth.fetchSignInMethodsForEmail(email).then(function(providers) {
  3280. * // The returned 'providers' is a list of the available providers
  3281. * // linked to the email address. Please refer to the guide for a more
  3282. * // complete explanation on how to recover from this error.
  3283. * });
  3284. * }
  3285. * });
  3286. * ```
  3287. *
  3288. * @param provider The provider to authenticate.
  3289. * The provider has to be an OAuth provider. Non-OAuth providers like {@link
  3290. * firebase.auth.EmailAuthProvider} will throw an error.
  3291. */
  3292. signInWithPopup(
  3293. provider: firebase.auth.AuthProvider
  3294. ): Promise<firebase.auth.UserCredential>;
  3295. /**
  3296. * Authenticates a Firebase client using a full-page redirect flow. To handle
  3297. * the results and errors for this operation, refer to {@link
  3298. * firebase.auth.Auth.getRedirectResult}.
  3299. *
  3300. * <h4>Error Codes</h4>
  3301. * <dl>
  3302. * <dt>auth/auth-domain-config-required</dt>
  3303. * <dd>Thrown if authDomain configuration is not provided when calling
  3304. * firebase.initializeApp(). Check Firebase Console for instructions on
  3305. * determining and passing that field.</dd>
  3306. * <dt>auth/operation-not-supported-in-this-environment</dt>
  3307. * <dd>Thrown if this operation is not supported in the environment your
  3308. * application is running on. "location.protocol" must be http or https.
  3309. * </dd>
  3310. * <dt>auth/unauthorized-domain</dt>
  3311. * <dd>Thrown if the app domain is not authorized for OAuth operations for your
  3312. * Firebase project. Edit the list of authorized domains from the Firebase
  3313. * console.</dd>
  3314. * </dl>
  3315. *
  3316. * This method does not work in a Node.js environment.
  3317. *
  3318. * @param provider The provider to authenticate.
  3319. * The provider has to be an OAuth provider. Non-OAuth providers like {@link
  3320. * firebase.auth.EmailAuthProvider} will throw an error.
  3321. */
  3322. signInWithRedirect(provider: firebase.auth.AuthProvider): Promise<void>;
  3323. /**
  3324. * Signs out the current user.
  3325. */
  3326. signOut(): Promise<void>;
  3327. /**
  3328. * The current Auth instance's tenant ID. This is a readable/writable
  3329. * property. When you set the tenant ID of an Auth instance, all future
  3330. * sign-in/sign-up operations will pass this tenant ID and sign in or
  3331. * sign up users to the specified tenant project.
  3332. * When set to null, users are signed in to the parent project. By default,
  3333. * this is set to null.
  3334. *
  3335. * @example
  3336. * ```javascript
  3337. * // Set the tenant ID on Auth instance.
  3338. * firebase.auth().tenantId = ‘TENANT_PROJECT_ID’;
  3339. *
  3340. * // All future sign-in request now include tenant ID.
  3341. * firebase.auth().signInWithEmailAndPassword(email, password)
  3342. * .then(function(result) {
  3343. * // result.user.tenantId should be ‘TENANT_PROJECT_ID’.
  3344. * }).catch(function(error) {
  3345. * // Handle error.
  3346. * });
  3347. * ```
  3348. */
  3349. tenantId: string | null;
  3350. /**
  3351. * Asynchronously sets the provided user as `currentUser` on the current Auth
  3352. * instance. A new instance copy of the user provided will be made and set as
  3353. * `currentUser`.
  3354. *
  3355. * This will trigger {@link firebase.auth.Auth.onAuthStateChanged} and
  3356. * {@link firebase.auth.Auth.onIdTokenChanged} listeners like other sign in
  3357. * methods.
  3358. *
  3359. * The operation fails with an error if the user to be updated belongs to a
  3360. * different Firebase project.
  3361. *
  3362. * <h4>Error Codes</h4>
  3363. * <dl>
  3364. * <dt>auth/invalid-user-token</dt>
  3365. * <dd>Thrown if the user to be updated belongs to a diffent Firebase
  3366. * project.</dd>
  3367. * <dt>auth/user-token-expired</dt>
  3368. * <dd>Thrown if the token of the user to be updated is expired.</dd>
  3369. * <dt>auth/null-user</dt>
  3370. * <dd>Thrown if the user to be updated is null.</dd>
  3371. * <dt>auth/tenant-id-mismatch</dt>
  3372. * <dd>Thrown if the provided user's tenant ID does not match the
  3373. * underlying Auth instance's configured tenant ID</dd>
  3374. * </dl>
  3375. */
  3376. updateCurrentUser(user: firebase.User | null): Promise<void>;
  3377. /**
  3378. * Sets the current language to the default device/browser preference.
  3379. */
  3380. useDeviceLanguage(): void;
  3381. /**
  3382. * Modify this Auth instance to communicate with the Firebase Auth emulator. This must be
  3383. * called synchronously immediately following the first call to `firebase.auth()`. Do not use
  3384. * with production credentials as emulator traffic is not encrypted.
  3385. *
  3386. * @param url The URL at which the emulator is running (eg, 'http://localhost:9099')
  3387. */
  3388. useEmulator(url: string): void;
  3389. /**
  3390. * Checks a password reset code sent to the user by email or other out-of-band
  3391. * mechanism.
  3392. *
  3393. * Returns the user's email address if valid.
  3394. *
  3395. * <h4>Error Codes</h4>
  3396. * <dl>
  3397. * <dt>auth/expired-action-code</dt>
  3398. * <dd>Thrown if the password reset code has expired.</dd>
  3399. * <dt>auth/invalid-action-code</dt>
  3400. * <dd>Thrown if the password reset code is invalid. This can happen if the code
  3401. * is malformed or has already been used.</dd>
  3402. * <dt>auth/user-disabled</dt>
  3403. * <dd>Thrown if the user corresponding to the given password reset code has
  3404. * been disabled.</dd>
  3405. * <dt>auth/user-not-found</dt>
  3406. * <dd>Thrown if there is no user corresponding to the password reset code. This
  3407. * may have happened if the user was deleted between when the code was
  3408. * issued and when this method was called.</dd>
  3409. * </dl>
  3410. *
  3411. * @param code A verification code sent to the user.
  3412. */
  3413. verifyPasswordResetCode(code: string): Promise<string>;
  3414. }
  3415. /**
  3416. * Interface that represents the credentials returned by an auth provider.
  3417. * Implementations specify the details about each auth provider's credential
  3418. * requirements.
  3419. *
  3420. */
  3421. abstract class AuthCredential {
  3422. /**
  3423. * The authentication provider ID for the credential.
  3424. * For example, 'facebook.com', or 'google.com'.
  3425. */
  3426. providerId: string;
  3427. /**
  3428. * The authentication sign in method for the credential.
  3429. * For example, 'password', or 'emailLink. This corresponds to the sign-in
  3430. * method identifier as returned in
  3431. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
  3432. */
  3433. signInMethod: string;
  3434. /**
  3435. * Returns a JSON-serializable representation of this object.
  3436. */
  3437. toJSON(): Object;
  3438. /**
  3439. * Static method to deserialize a JSON representation of an object into an
  3440. * {@link firebase.auth.AuthCredential}. Input can be either Object or the
  3441. * stringified representation of the object. When string is provided,
  3442. * JSON.parse would be called first. If the JSON input does not represent
  3443. * an`AuthCredential`, null is returned.
  3444. * @param json The plain object representation of an
  3445. * AuthCredential.
  3446. */
  3447. static fromJSON(json: Object | string): AuthCredential | null;
  3448. }
  3449. /**
  3450. * Interface that represents the OAuth credentials returned by an OAuth
  3451. * provider. Implementations specify the details about each auth provider's
  3452. * credential requirements.
  3453. *
  3454. */
  3455. class OAuthCredential extends AuthCredential {
  3456. private constructor();
  3457. /**
  3458. * The OAuth ID token associated with the credential if it belongs to an
  3459. * OIDC provider, such as `google.com`.
  3460. */
  3461. idToken?: string;
  3462. /**
  3463. * The OAuth access token associated with the credential if it belongs to
  3464. * an OAuth provider, such as `facebook.com`, `twitter.com`, etc.
  3465. */
  3466. accessToken?: string;
  3467. /**
  3468. * The OAuth access token secret associated with the credential if it
  3469. * belongs to an OAuth 1.0 provider, such as `twitter.com`.
  3470. */
  3471. secret?: string;
  3472. }
  3473. /**
  3474. * Interface that represents an auth provider.
  3475. */
  3476. interface AuthProvider {
  3477. providerId: string;
  3478. }
  3479. /**
  3480. * A result from a phone number sign-in, link, or reauthenticate call.
  3481. */
  3482. interface ConfirmationResult {
  3483. /**
  3484. * Finishes a phone number sign-in, link, or reauthentication, given the code
  3485. * that was sent to the user's mobile device.
  3486. *
  3487. * <h4>Error Codes</h4>
  3488. * <dl>
  3489. * <dt>auth/invalid-verification-code</dt>
  3490. * <dd>Thrown if the verification code is not valid.</dd>
  3491. * <dt>auth/missing-verification-code</dt>
  3492. * <dd>Thrown if the verification code is missing.</dd>
  3493. * </dl>
  3494. */
  3495. confirm(verificationCode: string): Promise<firebase.auth.UserCredential>;
  3496. /**
  3497. * The phone number authentication operation's verification ID. This can be used
  3498. * along with the verification code to initialize a phone auth credential.
  3499. */
  3500. verificationId: string;
  3501. }
  3502. /**
  3503. * Email and password auth provider implementation.
  3504. *
  3505. * To authenticate: {@link firebase.auth.Auth.createUserWithEmailAndPassword}
  3506. * and {@link firebase.auth.Auth.signInWithEmailAndPassword}.
  3507. */
  3508. class EmailAuthProvider extends EmailAuthProvider_Instance {
  3509. static PROVIDER_ID: string;
  3510. /**
  3511. * This corresponds to the sign-in method identifier as returned in
  3512. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
  3513. */
  3514. static EMAIL_PASSWORD_SIGN_IN_METHOD: string;
  3515. /**
  3516. * This corresponds to the sign-in method identifier as returned in
  3517. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
  3518. */
  3519. static EMAIL_LINK_SIGN_IN_METHOD: string;
  3520. /**
  3521. * @example
  3522. * ```javascript
  3523. * var cred = firebase.auth.EmailAuthProvider.credential(
  3524. * email,
  3525. * password
  3526. * );
  3527. * ```
  3528. *
  3529. * @param email Email address.
  3530. * @param password User account password.
  3531. * @return The auth provider credential.
  3532. */
  3533. static credential(
  3534. email: string,
  3535. password: string
  3536. ): firebase.auth.AuthCredential;
  3537. /**
  3538. * Initialize an `EmailAuthProvider` credential using an email and an email link
  3539. * after a sign in with email link operation.
  3540. *
  3541. * @example
  3542. * ```javascript
  3543. * var cred = firebase.auth.EmailAuthProvider.credentialWithLink(
  3544. * email,
  3545. * emailLink
  3546. * );
  3547. * ```
  3548. *
  3549. * @param email Email address.
  3550. * @param emailLink Sign-in email link.
  3551. * @return The auth provider credential.
  3552. */
  3553. static credentialWithLink(
  3554. email: string,
  3555. emailLink: string
  3556. ): firebase.auth.AuthCredential;
  3557. }
  3558. /**
  3559. * @hidden
  3560. */
  3561. class EmailAuthProvider_Instance implements firebase.auth.AuthProvider {
  3562. providerId: string;
  3563. }
  3564. /**
  3565. * An authentication error.
  3566. * For method-specific error codes, refer to the specific methods in the
  3567. * documentation. For common error codes, check the reference below. Use{@link
  3568. * firebase.auth.Error.code} to get the specific error code. For a detailed
  3569. * message, use {@link firebase.auth.Error.message}.
  3570. * Errors with the code <strong>auth/account-exists-with-different-credential
  3571. * </strong> will have the additional fields <strong>email</strong> and <strong>
  3572. * credential</strong> which are needed to provide a way to resolve these
  3573. * specific errors. Refer to {@link firebase.auth.Auth.signInWithPopup} for more
  3574. * information.
  3575. *
  3576. * <h4>Common Error Codes</h4>
  3577. * <dl>
  3578. * <dt>auth/app-deleted</dt>
  3579. * <dd>Thrown if the instance of FirebaseApp has been deleted.</dd>
  3580. * <dt>auth/app-not-authorized</dt>
  3581. * <dd>Thrown if the app identified by the domain where it's hosted, is not
  3582. * authorized to use Firebase Authentication with the provided API key.
  3583. * Review your key configuration in the Google API console.</dd>
  3584. * <dt>auth/argument-error</dt>
  3585. * <dd>Thrown if a method is called with incorrect arguments.</dd>
  3586. * <dt>auth/invalid-api-key</dt>
  3587. * <dd>Thrown if the provided API key is invalid. Please check that you have
  3588. * copied it correctly from the Firebase Console.</dd>
  3589. * <dt>auth/invalid-user-token</dt>
  3590. * <dd>Thrown if the user's credential is no longer valid. The user must sign in
  3591. * again.</dd>
  3592. * <dt>auth/invalid-tenant-id</dt>
  3593. * <dd>Thrown if the tenant ID provided is invalid.</dd>
  3594. * <dt>auth/network-request-failed</dt>
  3595. * <dd>Thrown if a network error (such as timeout, interrupted connection or
  3596. * unreachable host) has occurred.</dd>
  3597. * <dt>auth/operation-not-allowed</dt>
  3598. * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
  3599. * to the Firebase Console for your project, in the Auth section and the
  3600. * <strong>Sign in Method</strong> tab and configure the provider.</dd>
  3601. * <dt>auth/requires-recent-login</dt>
  3602. * <dd>Thrown if the user's last sign-in time does not meet the security
  3603. * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
  3604. * resolve. This does not apply if the user is anonymous.</dd>
  3605. * <dt>auth/too-many-requests</dt>
  3606. * <dd>Thrown if requests are blocked from a device due to unusual activity.
  3607. * Trying again after some delay would unblock.</dd>
  3608. * <dt>auth/unauthorized-domain</dt>
  3609. * <dd>Thrown if the app domain is not authorized for OAuth operations for your
  3610. * Firebase project. Edit the list of authorized domains from the Firebase
  3611. * console.</dd>
  3612. * <dt>auth/user-disabled</dt>
  3613. * <dd>Thrown if the user account has been disabled by an administrator.
  3614. * Accounts can be enabled or disabled in the Firebase Console, the Auth
  3615. * section and Users subsection.</dd>
  3616. * <dt>auth/user-token-expired</dt>
  3617. * <dd>Thrown if the user's credential has expired. This could also be thrown if
  3618. * a user has been deleted. Prompting the user to sign in again should
  3619. * resolve this for either case.</dd>
  3620. * <dt>auth/web-storage-unsupported</dt>
  3621. * <dd>Thrown if the browser does not support web storage or if the user
  3622. * disables them.</dd>
  3623. * </dl>
  3624. */
  3625. interface Error {
  3626. name: string;
  3627. /**
  3628. * Unique error code.
  3629. */
  3630. code: string;
  3631. /**
  3632. * Complete error message.
  3633. */
  3634. message: string;
  3635. }
  3636. /**
  3637. * The account conflict error.
  3638. * Refer to {@link firebase.auth.Auth.signInWithPopup} for more information.
  3639. *
  3640. * <h4>Common Error Codes</h4>
  3641. * <dl>
  3642. * <dt>auth/account-exists-with-different-credential</dt>
  3643. * <dd>Thrown if there already exists an account with the email address
  3644. * asserted by the credential. Resolve this by calling
  3645. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} with the error.email
  3646. * and then asking the user to sign in using one of the returned providers.
  3647. * Once the user is signed in, the original credential retrieved from the
  3648. * error.credential can be linked to the user with
  3649. * {@link firebase.User.linkWithCredential} to prevent the user from signing
  3650. * in again to the original provider via popup or redirect. If you are using
  3651. * redirects for sign in, save the credential in session storage and then
  3652. * retrieve on redirect and repopulate the credential using for example
  3653. * {@link firebase.auth.GoogleAuthProvider.credential} depending on the
  3654. * credential provider id and complete the link.</dd>
  3655. * <dt>auth/credential-already-in-use</dt>
  3656. * <dd>Thrown if the account corresponding to the credential already exists
  3657. * among your users, or is already linked to a Firebase User.
  3658. * For example, this error could be thrown if you are upgrading an anonymous
  3659. * user to a Google user by linking a Google credential to it and the Google
  3660. * credential used is already associated with an existing Firebase Google
  3661. * user.
  3662. * The fields <code>error.email</code>, <code>error.phoneNumber</code>, and
  3663. * <code>error.credential</code> ({@link firebase.auth.AuthCredential})
  3664. * may be provided, depending on the type of credential. You can recover
  3665. * from this error by signing in with <code>error.credential</code> directly
  3666. * via {@link firebase.auth.Auth.signInWithCredential}.</dd>
  3667. * <dt>auth/email-already-in-use</dt>
  3668. * <dd>Thrown if the email corresponding to the credential already exists
  3669. * among your users. When thrown while linking a credential to an existing
  3670. * user, an <code>error.email</code> and <code>error.credential</code>
  3671. * ({@link firebase.auth.AuthCredential}) fields are also provided.
  3672. * You have to link the credential to the existing user with that email if
  3673. * you wish to continue signing in with that credential. To do so, call
  3674. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
  3675. * <code>error.email</code> via one of the providers returned and then
  3676. * {@link firebase.User.linkWithCredential} the original credential to that
  3677. * newly signed in user.</dd>
  3678. * </dl>
  3679. */
  3680. interface AuthError extends firebase.auth.Error {
  3681. /**
  3682. * The {@link firebase.auth.AuthCredential} that can be used to resolve the
  3683. * error.
  3684. */
  3685. credential?: firebase.auth.AuthCredential;
  3686. /**
  3687. * The email of the user's account used for sign-in/linking.
  3688. */
  3689. email?: string;
  3690. /**
  3691. * The phone number of the user's account used for sign-in/linking.
  3692. */
  3693. phoneNumber?: string;
  3694. /**
  3695. * The tenant ID being used for sign-in/linking. If you use
  3696. * {@link firebase.auth.Auth.signInWithRedirect} to sign in, you have to
  3697. * set the tenant ID on Auth instanace again as the tenant ID is not
  3698. * persisted after redirection.
  3699. */
  3700. tenantId?: string;
  3701. }
  3702. /**
  3703. * The error thrown when the user needs to provide a second factor to sign in
  3704. * successfully.
  3705. * The error code for this error is <code>auth/multi-factor-auth-required</code>.
  3706. * This error provides a {@link firebase.auth.MultiFactorResolver} object,
  3707. * which you can use to get the second sign-in factor from the user.
  3708. *
  3709. * @example
  3710. * ```javascript
  3711. * firebase.auth().signInWithEmailAndPassword()
  3712. * .then(function(result) {
  3713. * // User signed in. No 2nd factor challenge is needed.
  3714. * })
  3715. * .catch(function(error) {
  3716. * if (error.code == 'auth/multi-factor-auth-required') {
  3717. * var resolver = error.resolver;
  3718. * var multiFactorHints = resolver.hints;
  3719. * } else {
  3720. * // Handle other errors.
  3721. * }
  3722. * });
  3723. *
  3724. * resolver.resolveSignIn(multiFactorAssertion)
  3725. * .then(function(userCredential) {
  3726. * // User signed in.
  3727. * });
  3728. * ```
  3729. */
  3730. interface MultiFactorError extends firebase.auth.AuthError {
  3731. /**
  3732. * The multi-factor resolver to complete second factor sign-in.
  3733. */
  3734. resolver: firebase.auth.MultiFactorResolver;
  3735. }
  3736. /**
  3737. * Facebook auth provider.
  3738. *
  3739. * @example
  3740. * ```javascript
  3741. * // Sign in using a redirect.
  3742. * firebase.auth().getRedirectResult().then(function(result) {
  3743. * if (result.credential) {
  3744. * // This gives you a Google Access Token.
  3745. * var token = result.credential.accessToken;
  3746. * }
  3747. * var user = result.user;
  3748. * })
  3749. * // Start a sign in process for an unauthenticated user.
  3750. * var provider = new firebase.auth.FacebookAuthProvider();
  3751. * provider.addScope('user_birthday');
  3752. * firebase.auth().signInWithRedirect(provider);
  3753. * ```
  3754. *
  3755. * @example
  3756. * ```javascript
  3757. * // Sign in using a popup.
  3758. * var provider = new firebase.auth.FacebookAuthProvider();
  3759. * provider.addScope('user_birthday');
  3760. * firebase.auth().signInWithPopup(provider).then(function(result) {
  3761. * // This gives you a Facebook Access Token.
  3762. * var token = result.credential.accessToken;
  3763. * // The signed-in user info.
  3764. * var user = result.user;
  3765. * });
  3766. * ```
  3767. *
  3768. * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
  3769. * changes.
  3770. */
  3771. class FacebookAuthProvider extends FacebookAuthProvider_Instance {
  3772. static PROVIDER_ID: string;
  3773. /**
  3774. * This corresponds to the sign-in method identifier as returned in
  3775. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
  3776. */
  3777. static FACEBOOK_SIGN_IN_METHOD: string;
  3778. /**
  3779. * @example
  3780. * ```javascript
  3781. * var cred = firebase.auth.FacebookAuthProvider.credential(
  3782. * // `event` from the Facebook auth.authResponseChange callback.
  3783. * event.authResponse.accessToken
  3784. * );
  3785. * ```
  3786. *
  3787. * @param token Facebook access token.
  3788. */
  3789. static credential(token: string): firebase.auth.OAuthCredential;
  3790. }
  3791. /**
  3792. * @hidden
  3793. */
  3794. class FacebookAuthProvider_Instance implements firebase.auth.AuthProvider {
  3795. /**
  3796. * @param scope Facebook OAuth scope.
  3797. * @return The provider instance itself.
  3798. */
  3799. addScope(scope: string): firebase.auth.AuthProvider;
  3800. providerId: string;
  3801. /**
  3802. * Sets the OAuth custom parameters to pass in a Facebook OAuth request for
  3803. * popup and redirect sign-in operations.
  3804. * Valid parameters include 'auth_type', 'display' and 'locale'.
  3805. * For a detailed list, check the
  3806. * {@link https://goo.gl/pve4fo Facebook}
  3807. * documentation.
  3808. * Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
  3809. * 'scope', 'response_type' and 'state' are not allowed and will be ignored.
  3810. * @param customOAuthParameters The custom OAuth parameters to pass
  3811. * in the OAuth request.
  3812. * @return The provider instance itself.
  3813. */
  3814. setCustomParameters(
  3815. customOAuthParameters: Object
  3816. ): firebase.auth.AuthProvider;
  3817. }
  3818. /**
  3819. * GitHub auth provider.
  3820. *
  3821. * GitHub requires an OAuth 2.0 redirect, so you can either handle the redirect
  3822. * directly, or use the signInWithPopup handler:
  3823. *
  3824. * @example
  3825. * ```javascript
  3826. * // Using a redirect.
  3827. * firebase.auth().getRedirectResult().then(function(result) {
  3828. * if (result.credential) {
  3829. * // This gives you a GitHub Access Token.
  3830. * var token = result.credential.accessToken;
  3831. * }
  3832. * var user = result.user;
  3833. * }).catch(function(error) {
  3834. * // Handle Errors here.
  3835. * var errorCode = error.code;
  3836. * var errorMessage = error.message;
  3837. * // The email of the user's account used.
  3838. * var email = error.email;
  3839. * // The firebase.auth.AuthCredential type that was used.
  3840. * var credential = error.credential;
  3841. * if (errorCode === 'auth/account-exists-with-different-credential') {
  3842. * alert('You have signed up with a different provider for that email.');
  3843. * // Handle linking here if your app allows it.
  3844. * } else {
  3845. * console.error(error);
  3846. * }
  3847. * });
  3848. *
  3849. * // Start a sign in process for an unauthenticated user.
  3850. * var provider = new firebase.auth.GithubAuthProvider();
  3851. * provider.addScope('repo');
  3852. * firebase.auth().signInWithRedirect(provider);
  3853. * ```
  3854. *
  3855. * @example
  3856. * ```javascript
  3857. * // With popup.
  3858. * var provider = new firebase.auth.GithubAuthProvider();
  3859. * provider.addScope('repo');
  3860. * firebase.auth().signInWithPopup(provider).then(function(result) {
  3861. * // This gives you a GitHub Access Token.
  3862. * var token = result.credential.accessToken;
  3863. * // The signed-in user info.
  3864. * var user = result.user;
  3865. * }).catch(function(error) {
  3866. * // Handle Errors here.
  3867. * var errorCode = error.code;
  3868. * var errorMessage = error.message;
  3869. * // The email of the user's account used.
  3870. * var email = error.email;
  3871. * // The firebase.auth.AuthCredential type that was used.
  3872. * var credential = error.credential;
  3873. * if (errorCode === 'auth/account-exists-with-different-credential') {
  3874. * alert('You have signed up with a different provider for that email.');
  3875. * // Handle linking here if your app allows it.
  3876. * } else {
  3877. * console.error(error);
  3878. * }
  3879. * });
  3880. * ```
  3881. *
  3882. * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
  3883. * changes.
  3884. */
  3885. class GithubAuthProvider extends GithubAuthProvider_Instance {
  3886. static PROVIDER_ID: string;
  3887. /**
  3888. * This corresponds to the sign-in method identifier as returned in
  3889. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
  3890. */
  3891. static GITHUB_SIGN_IN_METHOD: string;
  3892. /**
  3893. * @example
  3894. * ```javascript
  3895. * var cred = firebase.auth.GithubAuthProvider.credential(
  3896. * // `event` from the Github auth.authResponseChange callback.
  3897. * event.authResponse.accessToken
  3898. * );
  3899. * ```
  3900. *
  3901. * @param token Github access token.
  3902. * @return {!firebase.auth.OAuthCredential} The auth provider credential.
  3903. */
  3904. static credential(token: string): firebase.auth.OAuthCredential;
  3905. }
  3906. /**
  3907. * @hidden
  3908. */
  3909. class GithubAuthProvider_Instance implements firebase.auth.AuthProvider {
  3910. /**
  3911. * @param scope Github OAuth scope.
  3912. * @return The provider instance itself.
  3913. */
  3914. addScope(scope: string): firebase.auth.AuthProvider;
  3915. providerId: string;
  3916. /**
  3917. * Sets the OAuth custom parameters to pass in a GitHub OAuth request for popup
  3918. * and redirect sign-in operations.
  3919. * Valid parameters include 'allow_signup'.
  3920. * For a detailed list, check the
  3921. * {@link https://developer.github.com/v3/oauth/ GitHub} documentation.
  3922. * Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
  3923. * 'scope', 'response_type' and 'state' are not allowed and will be ignored.
  3924. * @param customOAuthParameters The custom OAuth parameters to pass
  3925. * in the OAuth request.
  3926. * @return The provider instance itself.
  3927. */
  3928. setCustomParameters(
  3929. customOAuthParameters: Object
  3930. ): firebase.auth.AuthProvider;
  3931. }
  3932. /**
  3933. * Google auth provider.
  3934. *
  3935. * @example
  3936. * ```javascript
  3937. * // Using a redirect.
  3938. * firebase.auth().getRedirectResult().then(function(result) {
  3939. * if (result.credential) {
  3940. * // This gives you a Google Access Token.
  3941. * var token = result.credential.accessToken;
  3942. * }
  3943. * var user = result.user;
  3944. * });
  3945. *
  3946. * // Start a sign in process for an unauthenticated user.
  3947. * var provider = new firebase.auth.GoogleAuthProvider();
  3948. * provider.addScope('profile');
  3949. * provider.addScope('email');
  3950. * firebase.auth().signInWithRedirect(provider);
  3951. * ```
  3952. *
  3953. * @example
  3954. * ```javascript
  3955. * // Using a popup.
  3956. * var provider = new firebase.auth.GoogleAuthProvider();
  3957. * provider.addScope('profile');
  3958. * provider.addScope('email');
  3959. * firebase.auth().signInWithPopup(provider).then(function(result) {
  3960. * // This gives you a Google Access Token.
  3961. * var token = result.credential.accessToken;
  3962. * // The signed-in user info.
  3963. * var user = result.user;
  3964. * });
  3965. * ```
  3966. *
  3967. * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
  3968. * changes.
  3969. */
  3970. class GoogleAuthProvider extends GoogleAuthProvider_Instance {
  3971. static PROVIDER_ID: string;
  3972. /**
  3973. * This corresponds to the sign-in method identifier as returned in
  3974. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
  3975. */
  3976. static GOOGLE_SIGN_IN_METHOD: string;
  3977. /**
  3978. * Creates a credential for Google. At least one of ID token and access token
  3979. * is required.
  3980. *
  3981. * @example
  3982. * ```javascript
  3983. * // \`googleUser\` from the onsuccess Google Sign In callback.
  3984. * var credential = firebase.auth.GoogleAuthProvider.credential(
  3985. googleUser.getAuthResponse().id_token);
  3986. * firebase.auth().signInWithCredential(credential)
  3987. * ```
  3988. * @param idToken Google ID token.
  3989. * @param accessToken Google access token.
  3990. * @return The auth provider credential.
  3991. */
  3992. static credential(
  3993. idToken?: string | null,
  3994. accessToken?: string | null
  3995. ): firebase.auth.OAuthCredential;
  3996. }
  3997. /**
  3998. * @hidden
  3999. */
  4000. class GoogleAuthProvider_Instance implements firebase.auth.AuthProvider {
  4001. /**
  4002. * @param scope Google OAuth scope.
  4003. * @return The provider instance itself.
  4004. */
  4005. addScope(scope: string): firebase.auth.AuthProvider;
  4006. providerId: string;
  4007. /**
  4008. * Sets the OAuth custom parameters to pass in a Google OAuth request for popup
  4009. * and redirect sign-in operations.
  4010. * Valid parameters include 'hd', 'hl', 'include_granted_scopes', 'login_hint'
  4011. * and 'prompt'.
  4012. * For a detailed list, check the
  4013. * {@link https://goo.gl/Xo01Jm Google}
  4014. * documentation.
  4015. * Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
  4016. * 'scope', 'response_type' and 'state' are not allowed and will be ignored.
  4017. * @param customOAuthParameters The custom OAuth parameters to pass
  4018. * in the OAuth request.
  4019. * @return The provider instance itself.
  4020. */
  4021. setCustomParameters(
  4022. customOAuthParameters: Object
  4023. ): firebase.auth.AuthProvider;
  4024. }
  4025. /**
  4026. * Generic OAuth provider.
  4027. *
  4028. * @example
  4029. * ```javascript
  4030. * // Using a redirect.
  4031. * firebase.auth().getRedirectResult().then(function(result) {
  4032. * if (result.credential) {
  4033. * // This gives you the OAuth Access Token for that provider.
  4034. * var token = result.credential.accessToken;
  4035. * }
  4036. * var user = result.user;
  4037. * });
  4038. *
  4039. * // Start a sign in process for an unauthenticated user.
  4040. * var provider = new firebase.auth.OAuthProvider('google.com');
  4041. * provider.addScope('profile');
  4042. * provider.addScope('email');
  4043. * firebase.auth().signInWithRedirect(provider);
  4044. * ```
  4045. * @example
  4046. * ```javascript
  4047. * // Using a popup.
  4048. * var provider = new firebase.auth.OAuthProvider('google.com');
  4049. * provider.addScope('profile');
  4050. * provider.addScope('email');
  4051. * firebase.auth().signInWithPopup(provider).then(function(result) {
  4052. * // This gives you the OAuth Access Token for that provider.
  4053. * var token = result.credential.accessToken;
  4054. * // The signed-in user info.
  4055. * var user = result.user;
  4056. * });
  4057. * ```
  4058. *
  4059. * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
  4060. * changes.
  4061. * @param providerId The associated provider ID, such as `github.com`.
  4062. */
  4063. class OAuthProvider implements firebase.auth.AuthProvider {
  4064. constructor(providerId: string);
  4065. providerId: string;
  4066. /**
  4067. * @param scope Provider OAuth scope to add.
  4068. */
  4069. addScope(scope: string): firebase.auth.AuthProvider;
  4070. /**
  4071. * Creates a Firebase credential from a generic OAuth provider's access token or
  4072. * ID token. The raw nonce is required when an ID token with a nonce field is
  4073. * provided. The SHA-256 hash of the raw nonce must match the nonce field in
  4074. * the ID token.
  4075. *
  4076. * @example
  4077. * ```javascript
  4078. * // `googleUser` from the onsuccess Google Sign In callback.
  4079. * // Initialize a generate OAuth provider with a `google.com` providerId.
  4080. * var provider = new firebase.auth.OAuthProvider('google.com');
  4081. * var credential = provider.credential({
  4082. * idToken: googleUser.getAuthResponse().id_token,
  4083. * });
  4084. * firebase.auth().signInWithCredential(credential)
  4085. * ```
  4086. *
  4087. * @param optionsOrIdToken Either the options object containing
  4088. * the ID token, access token and raw nonce or the ID token string.
  4089. * @param accessToken The OAuth access token.
  4090. */
  4091. credential(
  4092. optionsOrIdToken: firebase.auth.OAuthCredentialOptions | string | null,
  4093. accessToken?: string
  4094. ): firebase.auth.OAuthCredential;
  4095. /**
  4096. * Sets the OAuth custom parameters to pass in an OAuth request for popup
  4097. * and redirect sign-in operations.
  4098. * For a detailed list, check the
  4099. * reserved required OAuth 2.0 parameters such as `client_id`, `redirect_uri`,
  4100. * `scope`, `response_type` and `state` are not allowed and will be ignored.
  4101. * @param customOAuthParameters The custom OAuth parameters to pass
  4102. * in the OAuth request.
  4103. */
  4104. setCustomParameters(
  4105. customOAuthParameters: Object
  4106. ): firebase.auth.AuthProvider;
  4107. }
  4108. class SAMLAuthProvider implements firebase.auth.AuthProvider {
  4109. constructor(providerId: string);
  4110. providerId: string;
  4111. }
  4112. /**
  4113. * Interface representing ID token result obtained from
  4114. * {@link firebase.User.getIdTokenResult}. It contains the ID token JWT string
  4115. * and other helper properties for getting different data associated with the
  4116. * token as well as all the decoded payload claims.
  4117. *
  4118. * Note that these claims are not to be trusted as they are parsed client side.
  4119. * Only server side verification can guarantee the integrity of the token
  4120. * claims.
  4121. */
  4122. interface IdTokenResult {
  4123. /**
  4124. * The Firebase Auth ID token JWT string.
  4125. */
  4126. token: string;
  4127. /**
  4128. * The ID token expiration time formatted as a UTC string.
  4129. */
  4130. expirationTime: string;
  4131. /**
  4132. * The authentication time formatted as a UTC string. This is the time the
  4133. * user authenticated (signed in) and not the time the token was refreshed.
  4134. */
  4135. authTime: string;
  4136. /**
  4137. * The ID token issued at time formatted as a UTC string.
  4138. */
  4139. issuedAtTime: string;
  4140. /**
  4141. * The sign-in provider through which the ID token was obtained (anonymous,
  4142. * custom, phone, password, etc). Note, this does not map to provider IDs.
  4143. */
  4144. signInProvider: string | null;
  4145. /**
  4146. * The type of second factor associated with this session, provided the user
  4147. * was multi-factor authenticated (eg. phone, etc).
  4148. */
  4149. signInSecondFactor: string | null;
  4150. /**
  4151. * The entire payload claims of the ID token including the standard reserved
  4152. * claims as well as the custom claims.
  4153. */
  4154. claims: {
  4155. [key: string]: any;
  4156. };
  4157. }
  4158. /**
  4159. * Defines the options for initializing an
  4160. * {@link firebase.auth.OAuthCredential}. For ID tokens with nonce claim,
  4161. * the raw nonce has to also be provided.
  4162. */
  4163. interface OAuthCredentialOptions {
  4164. /**
  4165. * The OAuth ID token used to initialize the OAuthCredential.
  4166. */
  4167. idToken?: string;
  4168. /**
  4169. * The OAuth access token used to initialize the OAuthCredential.
  4170. */
  4171. accessToken?: string;
  4172. /**
  4173. * The raw nonce associated with the ID token. It is required when an ID token
  4174. * with a nonce field is provided. The SHA-256 hash of the raw nonce must match
  4175. * the nonce field in the ID token.
  4176. */
  4177. rawNonce?: string;
  4178. }
  4179. /**
  4180. * The base class for asserting ownership of a second factor. This is used to
  4181. * facilitate enrollment of a second factor on an existing user
  4182. * or sign-in of a user who already verified the first factor.
  4183. *
  4184. */
  4185. abstract class MultiFactorAssertion {
  4186. /**
  4187. * The identifier of the second factor.
  4188. */
  4189. factorId: string;
  4190. }
  4191. /**
  4192. * The class for asserting ownership of a phone second factor.
  4193. */
  4194. class PhoneMultiFactorAssertion extends firebase.auth.MultiFactorAssertion {
  4195. private constructor();
  4196. }
  4197. /**
  4198. * The class used to initialize {@link firebase.auth.PhoneMultiFactorAssertion}.
  4199. */
  4200. class PhoneMultiFactorGenerator {
  4201. private constructor();
  4202. /**
  4203. * The identifier of the phone second factor: `phone`.
  4204. */
  4205. static FACTOR_ID: string;
  4206. /**
  4207. * Initializes the {@link firebase.auth.PhoneMultiFactorAssertion} to confirm ownership
  4208. * of the phone second factor.
  4209. */
  4210. static assertion(
  4211. phoneAuthCredential: firebase.auth.PhoneAuthCredential
  4212. ): firebase.auth.PhoneMultiFactorAssertion;
  4213. }
  4214. /**
  4215. * A structure containing the information of a second factor entity.
  4216. */
  4217. interface MultiFactorInfo {
  4218. /**
  4219. * The multi-factor enrollment ID.
  4220. */
  4221. uid: string;
  4222. /**
  4223. * The user friendly name of the current second factor.
  4224. */
  4225. displayName?: string | null;
  4226. /**
  4227. * The enrollment date of the second factor formatted as a UTC string.
  4228. */
  4229. enrollmentTime: string;
  4230. /**
  4231. * The identifier of the second factor.
  4232. */
  4233. factorId: string;
  4234. }
  4235. /**
  4236. * The subclass of the MultiFactorInfo interface for phone number second factors.
  4237. * The factorId of this second factor is
  4238. * {@link firebase.auth.PhoneMultiFactorGenerator.FACTOR_ID}.
  4239. */
  4240. interface PhoneMultiFactorInfo extends firebase.auth.MultiFactorInfo {
  4241. /**
  4242. * The phone number associated with the current second factor.
  4243. */
  4244. phoneNumber: string;
  4245. }
  4246. /**
  4247. * The information required to verify the ownership of a phone number. The
  4248. * information that's required depends on whether you are doing single-factor
  4249. * sign-in, multi-factor enrollment or multi-factor sign-in.
  4250. */
  4251. type PhoneInfoOptions =
  4252. | firebase.auth.PhoneSingleFactorInfoOptions
  4253. | firebase.auth.PhoneMultiFactorEnrollInfoOptions
  4254. | firebase.auth.PhoneMultiFactorSignInInfoOptions;
  4255. /**
  4256. * The phone info options for single-factor sign-in. Only phone number is
  4257. * required.
  4258. */
  4259. interface PhoneSingleFactorInfoOptions {
  4260. phoneNumber: string;
  4261. }
  4262. /**
  4263. * The phone info options for multi-factor enrollment. Phone number and
  4264. * multi-factor session are required.
  4265. */
  4266. interface PhoneMultiFactorEnrollInfoOptions {
  4267. phoneNumber: string;
  4268. session: firebase.auth.MultiFactorSession;
  4269. }
  4270. /**
  4271. * The phone info options for multi-factor sign-in. Either multi-factor hint or
  4272. * multi-factor UID and multi-factor session are required.
  4273. */
  4274. interface PhoneMultiFactorSignInInfoOptions {
  4275. multiFactorHint?: firebase.auth.MultiFactorInfo;
  4276. multiFactorUid?: string;
  4277. session: firebase.auth.MultiFactorSession;
  4278. }
  4279. /**
  4280. * The class used to facilitate recovery from
  4281. * {@link firebase.auth.MultiFactorError} when a user needs to provide a second
  4282. * factor to sign in.
  4283. *
  4284. * @example
  4285. * ```javascript
  4286. * firebase.auth().signInWithEmailAndPassword()
  4287. * .then(function(result) {
  4288. * // User signed in. No 2nd factor challenge is needed.
  4289. * })
  4290. * .catch(function(error) {
  4291. * if (error.code == 'auth/multi-factor-auth-required') {
  4292. * var resolver = error.resolver;
  4293. * // Show UI to let user select second factor.
  4294. * var multiFactorHints = resolver.hints;
  4295. * } else {
  4296. * // Handle other errors.
  4297. * }
  4298. * });
  4299. *
  4300. * // The enrolled second factors that can be used to complete
  4301. * // sign-in are returned in the `MultiFactorResolver.hints` list.
  4302. * // UI needs to be presented to allow the user to select a second factor
  4303. * // from that list.
  4304. *
  4305. * var selectedHint = // ; selected from multiFactorHints
  4306. * var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
  4307. * var phoneInfoOptions = {
  4308. * multiFactorHint: selectedHint,
  4309. * session: resolver.session
  4310. * };
  4311. * phoneAuthProvider.verifyPhoneNumber(
  4312. * phoneInfoOptions,
  4313. * appVerifier
  4314. * ).then(function(verificationId) {
  4315. * // store verificationID and show UI to let user enter verification code.
  4316. * });
  4317. *
  4318. * // UI to enter verification code and continue.
  4319. * // Continue button click handler
  4320. * var phoneAuthCredential =
  4321. * firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
  4322. * var multiFactorAssertion =
  4323. * firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
  4324. * resolver.resolveSignIn(multiFactorAssertion)
  4325. * .then(function(userCredential) {
  4326. * // User signed in.
  4327. * });
  4328. * ```
  4329. */
  4330. class MultiFactorResolver {
  4331. private constructor();
  4332. /**
  4333. * The Auth instance used to sign in with the first factor.
  4334. */
  4335. auth: firebase.auth.Auth;
  4336. /**
  4337. * The session identifier for the current sign-in flow, which can be used
  4338. * to complete the second factor sign-in.
  4339. */
  4340. session: firebase.auth.MultiFactorSession;
  4341. /**
  4342. * The list of hints for the second factors needed to complete the sign-in
  4343. * for the current session.
  4344. */
  4345. hints: firebase.auth.MultiFactorInfo[];
  4346. /**
  4347. * A helper function to help users complete sign in with a second factor
  4348. * using an {@link firebase.auth.MultiFactorAssertion} confirming the user
  4349. * successfully completed the second factor challenge.
  4350. *
  4351. * <h4>Error Codes</h4>
  4352. * <dl>
  4353. * <dt>auth/invalid-verification-code</dt>
  4354. * <dd>Thrown if the verification code is not valid.</dd>
  4355. * <dt>auth/missing-verification-code</dt>
  4356. * <dd>Thrown if the verification code is missing.</dd>
  4357. * <dt>auth/invalid-verification-id</dt>
  4358. * <dd>Thrown if the credential is a
  4359. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  4360. * ID of the credential is not valid.</dd>
  4361. * <dt>auth/missing-verification-id</dt>
  4362. * <dd>Thrown if the verification ID is missing.</dd>
  4363. * <dt>auth/code-expired</dt>
  4364. * <dd>Thrown if the verification code has expired.</dd>
  4365. * <dt>auth/invalid-multi-factor-session</dt>
  4366. * <dd>Thrown if the request does not contain a valid proof of first factor
  4367. * successful sign-in.</dd>
  4368. * <dt>auth/missing-multi-factor-session</dt>
  4369. * <dd>Thrown if The request is missing proof of first factor successful
  4370. * sign-in.</dd>
  4371. * </dl>
  4372. *
  4373. * @param assertion The multi-factor assertion to resolve sign-in with.
  4374. * @return The promise that resolves with the user credential object.
  4375. */
  4376. resolveSignIn(
  4377. assertion: firebase.auth.MultiFactorAssertion
  4378. ): Promise<firebase.auth.UserCredential>;
  4379. }
  4380. /**
  4381. * The multi-factor session object used for enrolling a second factor on a
  4382. * user or helping sign in an enrolled user with a second factor.
  4383. */
  4384. class MultiFactorSession {
  4385. private constructor();
  4386. }
  4387. /**
  4388. * Classes that represents the Phone Auth credentials returned by a
  4389. * {@link firebase.auth.PhoneAuthProvider}.
  4390. *
  4391. */
  4392. class PhoneAuthCredential extends AuthCredential {
  4393. private constructor();
  4394. }
  4395. /**
  4396. * Phone number auth provider.
  4397. *
  4398. * @example
  4399. * ```javascript
  4400. * // 'recaptcha-container' is the ID of an element in the DOM.
  4401. * var applicationVerifier = new firebase.auth.RecaptchaVerifier(
  4402. * 'recaptcha-container');
  4403. * var provider = new firebase.auth.PhoneAuthProvider();
  4404. * provider.verifyPhoneNumber('+16505550101', applicationVerifier)
  4405. * .then(function(verificationId) {
  4406. * var verificationCode = window.prompt('Please enter the verification ' +
  4407. * 'code that was sent to your mobile device.');
  4408. * return firebase.auth.PhoneAuthProvider.credential(verificationId,
  4409. * verificationCode);
  4410. * })
  4411. * .then(function(phoneCredential) {
  4412. * return firebase.auth().signInWithCredential(phoneCredential);
  4413. * });
  4414. * ```
  4415. * @param auth The Firebase Auth instance in which
  4416. * sign-ins should occur. Uses the default Auth instance if unspecified.
  4417. */
  4418. class PhoneAuthProvider extends PhoneAuthProvider_Instance {
  4419. static PROVIDER_ID: string;
  4420. /**
  4421. * This corresponds to the sign-in method identifier as returned in
  4422. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
  4423. */
  4424. static PHONE_SIGN_IN_METHOD: string;
  4425. /**
  4426. * Creates a phone auth credential, given the verification ID from
  4427. * {@link firebase.auth.PhoneAuthProvider.verifyPhoneNumber} and the code
  4428. * that was sent to the user's mobile device.
  4429. *
  4430. * <h4>Error Codes</h4>
  4431. * <dl>
  4432. * <dt>auth/missing-verification-code</dt>
  4433. * <dd>Thrown if the verification code is missing.</dd>
  4434. * <dt>auth/missing-verification-id</dt>
  4435. * <dd>Thrown if the verification ID is missing.</dd>
  4436. * </dl>
  4437. *
  4438. * @param verificationId The verification ID returned from
  4439. * {@link firebase.auth.PhoneAuthProvider.verifyPhoneNumber}.
  4440. * @param verificationCode The verification code sent to the user's
  4441. * mobile device.
  4442. * @return The auth provider credential.
  4443. */
  4444. static credential(
  4445. verificationId: string,
  4446. verificationCode: string
  4447. ): firebase.auth.AuthCredential;
  4448. }
  4449. /**
  4450. * @hidden
  4451. */
  4452. class PhoneAuthProvider_Instance implements firebase.auth.AuthProvider {
  4453. constructor(auth?: firebase.auth.Auth | null);
  4454. providerId: string;
  4455. /**
  4456. * Starts a phone number authentication flow by sending a verification code to
  4457. * the given phone number. Returns an ID that can be passed to
  4458. * {@link firebase.auth.PhoneAuthProvider.credential} to identify this flow.
  4459. *
  4460. * For abuse prevention, this method also requires a
  4461. * {@link firebase.auth.ApplicationVerifier}. The Firebase Auth SDK includes
  4462. * a reCAPTCHA-based implementation, {@link firebase.auth.RecaptchaVerifier}.
  4463. *
  4464. * <h4>Error Codes</h4>
  4465. * <dl>
  4466. * <dt>auth/captcha-check-failed</dt>
  4467. * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
  4468. * this method was called from a non-whitelisted domain.</dd>
  4469. * <dt>auth/invalid-phone-number</dt>
  4470. * <dd>Thrown if the phone number has an invalid format.</dd>
  4471. * <dt>auth/missing-phone-number</dt>
  4472. * <dd>Thrown if the phone number is missing.</dd>
  4473. * <dt>auth/quota-exceeded</dt>
  4474. * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
  4475. * <dt>auth/user-disabled</dt>
  4476. * <dd>Thrown if the user corresponding to the given phone number has been
  4477. * disabled.</dd>
  4478. * <dt>auth/maximum-second-factor-count-exceeded</dt>
  4479. * <dd>Thrown if The maximum allowed number of second factors on a user
  4480. * has been exceeded.</dd>
  4481. * <dt>auth/second-factor-already-in-use</dt>
  4482. * <dd>Thrown if the second factor is already enrolled on this account.</dd>
  4483. * <dt>auth/unsupported-first-factor</dt>
  4484. * <dd>Thrown if the first factor being used to sign in is not supported.</dd>
  4485. * <dt>auth/unverified-email</dt>
  4486. * <dd>Thrown if the email of the account is not verified.</dd>
  4487. * </dl>
  4488. *
  4489. * @param phoneInfoOptions The user's {@link firebase.auth.PhoneInfoOptions}.
  4490. * The phone number should be in E.164 format (e.g. +16505550101).
  4491. * @param applicationVerifier
  4492. * @return A Promise for the verification ID.
  4493. */
  4494. verifyPhoneNumber(
  4495. phoneInfoOptions: firebase.auth.PhoneInfoOptions | string,
  4496. applicationVerifier: firebase.auth.ApplicationVerifier
  4497. ): Promise<string>;
  4498. }
  4499. /**
  4500. * An {@link https://www.google.com/recaptcha/ reCAPTCHA}-based application
  4501. * verifier.
  4502. *
  4503. * This class does not work in a Node.js environment.
  4504. *
  4505. * @param container The reCAPTCHA container parameter. This
  4506. * has different meaning depending on whether the reCAPTCHA is hidden or
  4507. * visible. For a visible reCAPTCHA the container must be empty. If a string
  4508. * is used, it has to correspond to an element ID. The corresponding element
  4509. * must also must be in the DOM at the time of initialization.
  4510. * @param parameters The optional reCAPTCHA parameters. Check the
  4511. * reCAPTCHA docs for a comprehensive list. All parameters are accepted
  4512. * except for the sitekey. Firebase Auth backend provisions a reCAPTCHA for
  4513. * each project and will configure this upon rendering. For an invisible
  4514. * reCAPTCHA, a size key must have the value 'invisible'.
  4515. * @param app The corresponding Firebase app. If none is
  4516. * provided, the default Firebase App instance is used. A Firebase App
  4517. * instance must be initialized with an API key, otherwise an error will be
  4518. * thrown.
  4519. */
  4520. class RecaptchaVerifier extends RecaptchaVerifier_Instance {}
  4521. /**
  4522. * @hidden
  4523. */
  4524. class RecaptchaVerifier_Instance
  4525. implements firebase.auth.ApplicationVerifier
  4526. {
  4527. constructor(
  4528. container: any | string,
  4529. parameters?: Object | null,
  4530. app?: firebase.app.App | null
  4531. );
  4532. /**
  4533. * Clears the reCAPTCHA widget from the page and destroys the current instance.
  4534. */
  4535. clear(): void;
  4536. /**
  4537. * Renders the reCAPTCHA widget on the page.
  4538. * @return A Promise that resolves with the
  4539. * reCAPTCHA widget ID.
  4540. */
  4541. render(): Promise<number>;
  4542. /**
  4543. * The application verifier type. For a reCAPTCHA verifier, this is 'recaptcha'.
  4544. */
  4545. type: string;
  4546. /**
  4547. * Waits for the user to solve the reCAPTCHA and resolves with the reCAPTCHA
  4548. * token.
  4549. * @return A Promise for the reCAPTCHA token.
  4550. */
  4551. verify(): Promise<string>;
  4552. }
  4553. /**
  4554. * Twitter auth provider.
  4555. *
  4556. * @example
  4557. * ```javascript
  4558. * // Using a redirect.
  4559. * firebase.auth().getRedirectResult().then(function(result) {
  4560. * if (result.credential) {
  4561. * // For accessing the Twitter API.
  4562. * var token = result.credential.accessToken;
  4563. * var secret = result.credential.secret;
  4564. * }
  4565. * var user = result.user;
  4566. * });
  4567. *
  4568. * // Start a sign in process for an unauthenticated user.
  4569. * var provider = new firebase.auth.TwitterAuthProvider();
  4570. * firebase.auth().signInWithRedirect(provider);
  4571. * ```
  4572. * @example
  4573. * ```javascript
  4574. * // Using a popup.
  4575. * var provider = new firebase.auth.TwitterAuthProvider();
  4576. * firebase.auth().signInWithPopup(provider).then(function(result) {
  4577. * // For accessing the Twitter API.
  4578. * var token = result.credential.accessToken;
  4579. * var secret = result.credential.secret;
  4580. * // The signed-in user info.
  4581. * var user = result.user;
  4582. * });
  4583. * ```
  4584. *
  4585. * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
  4586. * changes.
  4587. */
  4588. class TwitterAuthProvider extends TwitterAuthProvider_Instance {
  4589. static PROVIDER_ID: string;
  4590. /**
  4591. * This corresponds to the sign-in method identifier as returned in
  4592. * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
  4593. *
  4594. */
  4595. static TWITTER_SIGN_IN_METHOD: string;
  4596. /**
  4597. * @param token Twitter access token.
  4598. * @param secret Twitter secret.
  4599. * @return The auth provider credential.
  4600. */
  4601. static credential(
  4602. token: string,
  4603. secret: string
  4604. ): firebase.auth.OAuthCredential;
  4605. }
  4606. /**
  4607. * @hidden
  4608. */
  4609. class TwitterAuthProvider_Instance implements firebase.auth.AuthProvider {
  4610. providerId: string;
  4611. /**
  4612. * Sets the OAuth custom parameters to pass in a Twitter OAuth request for popup
  4613. * and redirect sign-in operations.
  4614. * Valid parameters include 'lang'.
  4615. * Reserved required OAuth 1.0 parameters such as 'oauth_consumer_key',
  4616. * 'oauth_token', 'oauth_signature', etc are not allowed and will be ignored.
  4617. * @param customOAuthParameters The custom OAuth parameters to pass
  4618. * in the OAuth request.
  4619. * @return The provider instance itself.
  4620. */
  4621. setCustomParameters(
  4622. customOAuthParameters: Object
  4623. ): firebase.auth.AuthProvider;
  4624. }
  4625. /**
  4626. * A structure containing a User, an AuthCredential, the operationType, and
  4627. * any additional user information that was returned from the identity provider.
  4628. * operationType could be 'signIn' for a sign-in operation, 'link' for a linking
  4629. * operation and 'reauthenticate' for a reauthentication operation.
  4630. */
  4631. type UserCredential = {
  4632. additionalUserInfo?: firebase.auth.AdditionalUserInfo | null;
  4633. credential: firebase.auth.AuthCredential | null;
  4634. operationType?: string | null;
  4635. user: firebase.User | null;
  4636. };
  4637. /**
  4638. * Interface representing a user's metadata.
  4639. */
  4640. interface UserMetadata {
  4641. creationTime?: string;
  4642. lastSignInTime?: string;
  4643. }
  4644. }
  4645. /**
  4646. * The Analytics SDK does not work in a Node.js environment.
  4647. */
  4648. declare namespace firebase.analytics {
  4649. /**
  4650. * The Firebase Analytics service interface.
  4651. *
  4652. * Do not call this constructor directly. Instead, use
  4653. * {@link firebase.analytics `firebase.analytics()`}.
  4654. */
  4655. export interface Analytics {
  4656. /**
  4657. * The {@link firebase.app.App app} associated with the `Analytics` service
  4658. * instance.
  4659. *
  4660. * @example
  4661. * ```javascript
  4662. * var app = analytics.app;
  4663. * ```
  4664. */
  4665. app: firebase.app.App;
  4666. /**
  4667. * Sends analytics event with given `eventParams`. This method
  4668. * automatically associates this logged event with this Firebase web
  4669. * app instance on this device.
  4670. * List of recommended event parameters can be found in
  4671. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4672. * | the GA4 reference documentation}.
  4673. */
  4674. logEvent(
  4675. eventName: 'add_payment_info',
  4676. eventParams?: {
  4677. coupon?: EventParams['coupon'];
  4678. currency?: EventParams['currency'];
  4679. items?: EventParams['items'];
  4680. payment_type?: EventParams['payment_type'];
  4681. value?: EventParams['value'];
  4682. [key: string]: any;
  4683. },
  4684. options?: firebase.analytics.AnalyticsCallOptions
  4685. ): void;
  4686. /**
  4687. * Sends analytics event with given `eventParams`. This method
  4688. * automatically associates this logged event with this Firebase web
  4689. * app instance on this device.
  4690. * List of recommended event parameters can be found in
  4691. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4692. * | the GA4 reference documentation}.
  4693. */
  4694. logEvent(
  4695. eventName: 'add_shipping_info',
  4696. eventParams?: {
  4697. coupon?: EventParams['coupon'];
  4698. currency?: EventParams['currency'];
  4699. items?: EventParams['items'];
  4700. shipping_tier?: EventParams['shipping_tier'];
  4701. value?: EventParams['value'];
  4702. [key: string]: any;
  4703. },
  4704. options?: firebase.analytics.AnalyticsCallOptions
  4705. ): void;
  4706. /**
  4707. * Sends analytics event with given `eventParams`. This method
  4708. * automatically associates this logged event with this Firebase web
  4709. * app instance on this device.
  4710. * List of recommended event parameters can be found in
  4711. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4712. * | the GA4 reference documentation}.
  4713. */
  4714. logEvent(
  4715. eventName: 'add_to_cart' | 'add_to_wishlist' | 'remove_from_cart',
  4716. eventParams?: {
  4717. currency?: EventParams['currency'];
  4718. value?: EventParams['value'];
  4719. items?: EventParams['items'];
  4720. [key: string]: any;
  4721. },
  4722. options?: firebase.analytics.AnalyticsCallOptions
  4723. ): void;
  4724. /**
  4725. * Sends analytics event with given `eventParams`. This method
  4726. * automatically associates this logged event with this Firebase web
  4727. * app instance on this device.
  4728. * List of recommended event parameters can be found in
  4729. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4730. * | the GA4 reference documentation}.
  4731. */
  4732. logEvent(
  4733. eventName: 'begin_checkout',
  4734. eventParams?: {
  4735. currency?: EventParams['currency'];
  4736. coupon?: EventParams['coupon'];
  4737. value?: EventParams['value'];
  4738. items?: EventParams['items'];
  4739. [key: string]: any;
  4740. },
  4741. options?: firebase.analytics.AnalyticsCallOptions
  4742. ): void;
  4743. /**
  4744. * Sends analytics event with given `eventParams`. This method
  4745. * automatically associates this logged event with this Firebase web
  4746. * app instance on this device.
  4747. * List of recommended event parameters can be found in
  4748. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4749. * | the GA4 reference documentation}.
  4750. */
  4751. logEvent(
  4752. eventName: 'checkout_progress',
  4753. eventParams?: {
  4754. currency?: EventParams['currency'];
  4755. coupon?: EventParams['coupon'];
  4756. value?: EventParams['value'];
  4757. items?: EventParams['items'];
  4758. checkout_step?: EventParams['checkout_step'];
  4759. checkout_option?: EventParams['checkout_option'];
  4760. [key: string]: any;
  4761. },
  4762. options?: firebase.analytics.AnalyticsCallOptions
  4763. ): void;
  4764. /**
  4765. * Sends analytics event with given `eventParams`. This method
  4766. * automatically associates this logged event with this Firebase web
  4767. * app instance on this device.
  4768. * See
  4769. * {@link https://developers.google.com/analytics/devguides/collection/ga4/exceptions
  4770. * | Measure exceptions}.
  4771. */
  4772. logEvent(
  4773. eventName: 'exception',
  4774. eventParams?: {
  4775. description?: EventParams['description'];
  4776. fatal?: EventParams['fatal'];
  4777. [key: string]: any;
  4778. },
  4779. options?: firebase.analytics.AnalyticsCallOptions
  4780. ): void;
  4781. /**
  4782. * Sends analytics event with given `eventParams`. This method
  4783. * automatically associates this logged event with this Firebase web
  4784. * app instance on this device.
  4785. * List of recommended event parameters can be found in
  4786. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4787. * | the GA4 reference documentation}.
  4788. */
  4789. logEvent(
  4790. eventName: 'generate_lead',
  4791. eventParams?: {
  4792. value?: EventParams['value'];
  4793. currency?: EventParams['currency'];
  4794. [key: string]: any;
  4795. },
  4796. options?: firebase.analytics.AnalyticsCallOptions
  4797. ): void;
  4798. /**
  4799. * Sends analytics event with given `eventParams`. This method
  4800. * automatically associates this logged event with this Firebase web
  4801. * app instance on this device.
  4802. * List of recommended event parameters can be found in
  4803. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4804. * | the GA4 reference documentation}.
  4805. */
  4806. logEvent(
  4807. eventName: 'login',
  4808. eventParams?: {
  4809. method?: EventParams['method'];
  4810. [key: string]: any;
  4811. },
  4812. options?: firebase.analytics.AnalyticsCallOptions
  4813. ): void;
  4814. /**
  4815. * Sends analytics event with given `eventParams`. This method
  4816. * automatically associates this logged event with this Firebase web
  4817. * app instance on this device.
  4818. * See
  4819. * {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view
  4820. * | Page views}.
  4821. */
  4822. logEvent(
  4823. eventName: 'page_view',
  4824. eventParams?: {
  4825. page_title?: string;
  4826. page_location?: string;
  4827. page_path?: string;
  4828. [key: string]: any;
  4829. },
  4830. options?: firebase.analytics.AnalyticsCallOptions
  4831. ): void;
  4832. /**
  4833. * Sends analytics event with given `eventParams`. This method
  4834. * automatically associates this logged event with this Firebase web
  4835. * app instance on this device.
  4836. * List of recommended event parameters can be found in
  4837. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4838. * | the GA4 reference documentation}.
  4839. */
  4840. logEvent(
  4841. eventName: 'purchase' | 'refund',
  4842. eventParams?: {
  4843. value?: EventParams['value'];
  4844. currency?: EventParams['currency'];
  4845. transaction_id: EventParams['transaction_id'];
  4846. tax?: EventParams['tax'];
  4847. shipping?: EventParams['shipping'];
  4848. items?: EventParams['items'];
  4849. coupon?: EventParams['coupon'];
  4850. affiliation?: EventParams['affiliation'];
  4851. [key: string]: any;
  4852. },
  4853. options?: firebase.analytics.AnalyticsCallOptions
  4854. ): void;
  4855. /**
  4856. * Sends analytics event with given `eventParams`. This method
  4857. * automatically associates this logged event with this Firebase web
  4858. * app instance on this device.
  4859. * See {@link https://firebase.google.com/docs/analytics/screenviews
  4860. * | Track Screenviews}.
  4861. */
  4862. logEvent(
  4863. eventName: 'screen_view',
  4864. eventParams?: {
  4865. firebase_screen: EventParams['firebase_screen'];
  4866. firebase_screen_class: EventParams['firebase_screen_class'];
  4867. [key: string]: any;
  4868. },
  4869. options?: firebase.analytics.AnalyticsCallOptions
  4870. ): void;
  4871. /**
  4872. * Sends analytics event with given `eventParams`. This method
  4873. * automatically associates this logged event with this Firebase web
  4874. * app instance on this device.
  4875. * List of recommended event parameters can be found in
  4876. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4877. * | the GA4 reference documentation}.
  4878. */
  4879. logEvent(
  4880. eventName: 'search' | 'view_search_results',
  4881. eventParams?: {
  4882. search_term?: EventParams['search_term'];
  4883. [key: string]: any;
  4884. },
  4885. options?: firebase.analytics.AnalyticsCallOptions
  4886. ): void;
  4887. /**
  4888. * Sends analytics event with given `eventParams`. This method
  4889. * automatically associates this logged event with this Firebase web
  4890. * app instance on this device.
  4891. * List of recommended event parameters can be found in
  4892. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4893. * | the GA4 reference documentation}.
  4894. */
  4895. logEvent(
  4896. eventName: 'select_content',
  4897. eventParams?: {
  4898. content_type?: EventParams['content_type'];
  4899. item_id?: EventParams['item_id'];
  4900. [key: string]: any;
  4901. },
  4902. options?: firebase.analytics.AnalyticsCallOptions
  4903. ): void;
  4904. /**
  4905. * Sends analytics event with given `eventParams`. This method
  4906. * automatically associates this logged event with this Firebase web
  4907. * app instance on this device.
  4908. * List of recommended event parameters can be found in
  4909. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4910. * | the GA4 reference documentation}.
  4911. */
  4912. logEvent(
  4913. eventName: 'select_item',
  4914. eventParams?: {
  4915. items?: EventParams['items'];
  4916. item_list_name?: EventParams['item_list_name'];
  4917. item_list_id?: EventParams['item_list_id'];
  4918. [key: string]: any;
  4919. },
  4920. options?: firebase.analytics.AnalyticsCallOptions
  4921. ): void;
  4922. /**
  4923. * Sends analytics event with given `eventParams`. This method
  4924. * automatically associates this logged event with this Firebase web
  4925. * app instance on this device.
  4926. * List of recommended event parameters can be found in
  4927. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4928. * | the GA4 reference documentation}.
  4929. */
  4930. logEvent(
  4931. eventName: 'select_promotion' | 'view_promotion',
  4932. eventParams?: {
  4933. items?: EventParams['items'];
  4934. promotion_id?: EventParams['promotion_id'];
  4935. promotion_name?: EventParams['promotion_name'];
  4936. [key: string]: any;
  4937. },
  4938. options?: firebase.analytics.AnalyticsCallOptions
  4939. ): void;
  4940. /**
  4941. * Sends analytics event with given `eventParams`. This method
  4942. * automatically associates this logged event with this Firebase web
  4943. * app instance on this device.
  4944. * List of recommended event parameters can be found in
  4945. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4946. * | the GA4 reference documentation}.
  4947. */
  4948. logEvent(
  4949. eventName: 'set_checkout_option',
  4950. eventParams?: {
  4951. checkout_step?: EventParams['checkout_step'];
  4952. checkout_option?: EventParams['checkout_option'];
  4953. [key: string]: any;
  4954. },
  4955. options?: firebase.analytics.AnalyticsCallOptions
  4956. ): void;
  4957. /**
  4958. * Sends analytics event with given `eventParams`. This method
  4959. * automatically associates this logged event with this Firebase web
  4960. * app instance on this device.
  4961. * List of recommended event parameters can be found in
  4962. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4963. * | the GA4 reference documentation}.
  4964. */
  4965. logEvent(
  4966. eventName: 'share',
  4967. eventParams?: {
  4968. method?: EventParams['method'];
  4969. content_type?: EventParams['content_type'];
  4970. item_id?: EventParams['item_id'];
  4971. [key: string]: any;
  4972. },
  4973. options?: firebase.analytics.AnalyticsCallOptions
  4974. ): void;
  4975. /**
  4976. * Sends analytics event with given `eventParams`. This method
  4977. * automatically associates this logged event with this Firebase web
  4978. * app instance on this device.
  4979. * List of recommended event parameters can be found in
  4980. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4981. * | the GA4 reference documentation}.
  4982. */
  4983. logEvent(
  4984. eventName: 'sign_up',
  4985. eventParams?: {
  4986. method?: EventParams['method'];
  4987. [key: string]: any;
  4988. },
  4989. options?: firebase.analytics.AnalyticsCallOptions
  4990. ): void;
  4991. /**
  4992. * Sends analytics event with given `eventParams`. This method
  4993. * automatically associates this logged event with this Firebase web
  4994. * app instance on this device.
  4995. * List of recommended event parameters can be found in
  4996. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  4997. * | the GA4 reference documentation}.
  4998. */
  4999. logEvent(
  5000. eventName: 'timing_complete',
  5001. eventParams?: {
  5002. name: string;
  5003. value: number;
  5004. event_category?: string;
  5005. event_label?: string;
  5006. [key: string]: any;
  5007. },
  5008. options?: firebase.analytics.AnalyticsCallOptions
  5009. ): void;
  5010. /**
  5011. * Sends analytics event with given `eventParams`. This method
  5012. * automatically associates this logged event with this Firebase web
  5013. * app instance on this device.
  5014. * List of recommended event parameters can be found in
  5015. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  5016. * | the GA4 reference documentation}.
  5017. */
  5018. logEvent(
  5019. eventName: 'view_cart' | 'view_item',
  5020. eventParams?: {
  5021. currency?: EventParams['currency'];
  5022. items?: EventParams['items'];
  5023. value?: EventParams['value'];
  5024. [key: string]: any;
  5025. },
  5026. options?: firebase.analytics.AnalyticsCallOptions
  5027. ): void;
  5028. /**
  5029. * Sends analytics event with given `eventParams`. This method
  5030. * automatically associates this logged event with this Firebase web
  5031. * app instance on this device.
  5032. * List of recommended event parameters can be found in
  5033. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  5034. * | the GA4 reference documentation}.
  5035. */
  5036. logEvent(
  5037. eventName: 'view_item_list',
  5038. eventParams?: {
  5039. items?: EventParams['items'];
  5040. item_list_name?: EventParams['item_list_name'];
  5041. item_list_id?: EventParams['item_list_id'];
  5042. [key: string]: any;
  5043. },
  5044. options?: firebase.analytics.AnalyticsCallOptions
  5045. ): void;
  5046. /**
  5047. * Sends analytics event with given `eventParams`. This method
  5048. * automatically associates this logged event with this Firebase web
  5049. * app instance on this device.
  5050. * List of recommended event parameters can be found in
  5051. * {@link https://developers.google.com/gtagjs/reference/ga4-events
  5052. * | the GA4 reference documentation}.
  5053. */
  5054. logEvent<T extends string>(
  5055. eventName: CustomEventName<T>,
  5056. eventParams?: { [key: string]: any },
  5057. options?: firebase.analytics.AnalyticsCallOptions
  5058. ): void;
  5059. /**
  5060. * Use gtag 'config' command to set 'screen_name'.
  5061. *
  5062. * @deprecated Use {@link logEvent} with `eventName` as 'screen_view' and add relevant `eventParams`.
  5063. * See {@link https://firebase.google.com/docs/analytics/screenviews | Track Screenviews}.
  5064. */
  5065. setCurrentScreen(
  5066. screenName: string,
  5067. options?: firebase.analytics.AnalyticsCallOptions
  5068. ): void;
  5069. /**
  5070. * Use gtag 'config' command to set 'user_id'.
  5071. */
  5072. setUserId(
  5073. id: string,
  5074. options?: firebase.analytics.AnalyticsCallOptions
  5075. ): void;
  5076. /**
  5077. * Use gtag 'config' command to set all params specified.
  5078. */
  5079. setUserProperties(
  5080. properties: firebase.analytics.CustomParams,
  5081. options?: firebase.analytics.AnalyticsCallOptions
  5082. ): void;
  5083. /**
  5084. * Sets whether analytics collection is enabled for this app on this device.
  5085. * window['ga-disable-analyticsId'] = true;
  5086. */
  5087. setAnalyticsCollectionEnabled(enabled: boolean): void;
  5088. }
  5089. export type CustomEventName<T> = T extends EventNameString ? never : T;
  5090. /**
  5091. * Additional options that can be passed to Firebase Analytics method
  5092. * calls such as `logEvent`, `setCurrentScreen`, etc.
  5093. */
  5094. export interface AnalyticsCallOptions {
  5095. /**
  5096. * If true, this config or event call applies globally to all
  5097. * analytics properties on the page.
  5098. */
  5099. global: boolean;
  5100. }
  5101. /**
  5102. * Specifies custom options for your Firebase Analytics instance.
  5103. * You must set these before initializing `firebase.analytics()`.
  5104. */
  5105. export interface SettingsOptions {
  5106. /** Sets custom name for `gtag` function. */
  5107. gtagName?: string;
  5108. /** Sets custom name for `dataLayer` array used by gtag. */
  5109. dataLayerName?: string;
  5110. }
  5111. /**
  5112. * Configures Firebase Analytics to use custom `gtag` or `dataLayer` names.
  5113. * Intended to be used if `gtag.js` script has been installed on
  5114. * this page independently of Firebase Analytics, and is using non-default
  5115. * names for either the `gtag` function or for `dataLayer`.
  5116. * Must be called before calling `firebase.analytics()` or it won't
  5117. * have any effect.
  5118. */
  5119. export function settings(settings: firebase.analytics.SettingsOptions): void;
  5120. /**
  5121. * Standard gtag.js control parameters.
  5122. * For more information, see
  5123. * {@link https://developers.google.com/gtagjs/reference/parameter
  5124. * the gtag.js documentation on parameters}.
  5125. */
  5126. export interface ControlParams {
  5127. groups?: string | string[];
  5128. send_to?: string | string[];
  5129. event_callback?: () => void;
  5130. event_timeout?: number;
  5131. }
  5132. /**
  5133. * Standard gtag.js event parameters.
  5134. * For more information, see
  5135. * {@link https://developers.google.com/gtagjs/reference/parameter
  5136. * the gtag.js documentation on parameters}.
  5137. */
  5138. export interface EventParams {
  5139. checkout_option?: string;
  5140. checkout_step?: number;
  5141. item_id?: string;
  5142. content_type?: string;
  5143. coupon?: string;
  5144. currency?: string;
  5145. description?: string;
  5146. fatal?: boolean;
  5147. items?: Item[];
  5148. method?: string;
  5149. number?: string;
  5150. promotions?: Promotion[];
  5151. screen_name?: string;
  5152. /**
  5153. * Firebase-specific. Use to log a `screen_name` to Firebase Analytics.
  5154. */
  5155. firebase_screen?: string;
  5156. /**
  5157. * Firebase-specific. Use to log a `screen_class` to Firebase Analytics.
  5158. */
  5159. firebase_screen_class?: string;
  5160. search_term?: string;
  5161. shipping?: Currency;
  5162. tax?: Currency;
  5163. transaction_id?: string;
  5164. value?: number;
  5165. event_label?: string;
  5166. event_category: string;
  5167. shipping_tier?: string;
  5168. item_list_id?: string;
  5169. item_list_name?: string;
  5170. promotion_id?: string;
  5171. promotion_name?: string;
  5172. payment_type?: string;
  5173. affiliation?: string;
  5174. }
  5175. /**
  5176. * Any custom params the user may pass to gtag.js.
  5177. */
  5178. export interface CustomParams {
  5179. [key: string]: any;
  5180. }
  5181. /**
  5182. * Type for standard gtag.js event names. `logEvent` also accepts any
  5183. * custom string and interprets it as a custom event name.
  5184. */
  5185. export type EventNameString =
  5186. | 'add_payment_info'
  5187. | 'add_shipping_info'
  5188. | 'add_to_cart'
  5189. | 'add_to_wishlist'
  5190. | 'begin_checkout'
  5191. | 'checkout_progress'
  5192. | 'exception'
  5193. | 'generate_lead'
  5194. | 'login'
  5195. | 'page_view'
  5196. | 'purchase'
  5197. | 'refund'
  5198. | 'remove_from_cart'
  5199. | 'screen_view'
  5200. | 'search'
  5201. | 'select_content'
  5202. | 'select_item'
  5203. | 'select_promotion'
  5204. | 'set_checkout_option'
  5205. | 'share'
  5206. | 'sign_up'
  5207. | 'timing_complete'
  5208. | 'view_cart'
  5209. | 'view_item'
  5210. | 'view_item_list'
  5211. | 'view_promotion'
  5212. | 'view_search_results';
  5213. /**
  5214. * Enum of standard gtag.js event names provided for convenient
  5215. * developer usage. `logEvent` will also accept any custom string
  5216. * and interpret it as a custom event name.
  5217. */
  5218. export enum EventName {
  5219. ADD_PAYMENT_INFO = 'add_payment_info',
  5220. ADD_SHIPPING_INFO = 'add_shipping_info',
  5221. ADD_TO_CART = 'add_to_cart',
  5222. ADD_TO_WISHLIST = 'add_to_wishlist',
  5223. BEGIN_CHECKOUT = 'begin_checkout',
  5224. /** @deprecated */
  5225. CHECKOUT_PROGRESS = 'checkout_progress',
  5226. EXCEPTION = 'exception',
  5227. GENERATE_LEAD = 'generate_lead',
  5228. LOGIN = 'login',
  5229. PAGE_VIEW = 'page_view',
  5230. PURCHASE = 'purchase',
  5231. REFUND = 'refund',
  5232. REMOVE_FROM_CART = 'remove_from_cart',
  5233. SCREEN_VIEW = 'screen_view',
  5234. SEARCH = 'search',
  5235. SELECT_CONTENT = 'select_content',
  5236. SELECT_ITEM = 'select_item',
  5237. SELECT_PROMOTION = 'select_promotion',
  5238. /** @deprecated */
  5239. SET_CHECKOUT_OPTION = 'set_checkout_option',
  5240. SHARE = 'share',
  5241. SIGN_UP = 'sign_up',
  5242. TIMING_COMPLETE = 'timing_complete',
  5243. VIEW_CART = 'view_cart',
  5244. VIEW_ITEM = 'view_item',
  5245. VIEW_ITEM_LIST = 'view_item_list',
  5246. VIEW_PROMOTION = 'view_promotion',
  5247. VIEW_SEARCH_RESULTS = 'view_search_results'
  5248. }
  5249. export type Currency = string | number;
  5250. export interface Item {
  5251. item_id?: string;
  5252. item_name?: string;
  5253. item_brand?: string;
  5254. item_category?: string;
  5255. item_category2?: string;
  5256. item_category3?: string;
  5257. item_category4?: string;
  5258. item_category5?: string;
  5259. item_variant?: string;
  5260. price?: Currency;
  5261. quantity?: number;
  5262. index?: number;
  5263. coupon?: string;
  5264. item_list_name?: string;
  5265. item_list_id?: string;
  5266. discount?: Currency;
  5267. affiliation?: string;
  5268. creative_name?: string;
  5269. creative_slot?: string;
  5270. promotion_id?: string;
  5271. promotion_name?: string;
  5272. location_id?: string;
  5273. /** @deprecated Use item_brand instead. */
  5274. brand?: string;
  5275. /** @deprecated Use item_category instead. */
  5276. category?: string;
  5277. /** @deprecated Use item_id instead. */
  5278. id?: string;
  5279. /** @deprecated Use item_name instead. */
  5280. name?: string;
  5281. }
  5282. /** @deprecated Use Item instead. */
  5283. export interface Promotion {
  5284. creative_name?: string;
  5285. creative_slot?: string;
  5286. id?: string;
  5287. name?: string;
  5288. }
  5289. /**
  5290. * An async function that returns true if current browser context supports initialization of analytics module
  5291. * (`firebase.analytics()`).
  5292. *
  5293. * Returns false otherwise.
  5294. *
  5295. *
  5296. */
  5297. function isSupported(): Promise<boolean>;
  5298. }
  5299. declare namespace firebase.auth.Auth {
  5300. type Persistence = string;
  5301. /**
  5302. * An enumeration of the possible persistence mechanism types.
  5303. */
  5304. var Persistence: {
  5305. /**
  5306. * Indicates that the state will be persisted even when the browser window is
  5307. * closed or the activity is destroyed in react-native.
  5308. */
  5309. LOCAL: Persistence;
  5310. /**
  5311. * Indicates that the state will only be stored in memory and will be cleared
  5312. * when the window or activity is refreshed.
  5313. */
  5314. NONE: Persistence;
  5315. /**
  5316. * Indicates that the state will only persist in current session/tab, relevant
  5317. * to web only, and will be cleared when the tab is closed.
  5318. */
  5319. SESSION: Persistence;
  5320. };
  5321. }
  5322. declare namespace firebase.User {
  5323. /**
  5324. * This is the interface that defines the multi-factor related properties and
  5325. * operations pertaining to a {@link firebase.User}.
  5326. */
  5327. interface MultiFactorUser {
  5328. /**
  5329. * Returns a list of the user's enrolled second factors.
  5330. */
  5331. enrolledFactors: firebase.auth.MultiFactorInfo[];
  5332. /**
  5333. * Enrolls a second factor as identified by the
  5334. * {@link firebase.auth.MultiFactorAssertion} for the current user.
  5335. * On resolution, the user tokens are updated to reflect the change in the
  5336. * JWT payload.
  5337. * Accepts an additional display name parameter used to identify the second
  5338. * factor to the end user.
  5339. * Recent re-authentication is required for this operation to succeed.
  5340. * On successful enrollment, existing Firebase sessions (refresh tokens) are
  5341. * revoked. When a new factor is enrolled, an email notification is sent
  5342. * to the user’s email.
  5343. *
  5344. * <h4>Error Codes</h4>
  5345. * <dl>
  5346. * <dt>auth/invalid-verification-code</dt>
  5347. * <dd>Thrown if the verification code is not valid.</dd>
  5348. * <dt>auth/missing-verification-code</dt>
  5349. * <dd>Thrown if the verification code is missing.</dd>
  5350. * <dt>auth/invalid-verification-id</dt>
  5351. * <dd>Thrown if the credential is a
  5352. * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
  5353. * ID of the credential is not valid.</dd>
  5354. * <dt>auth/missing-verification-id</dt>
  5355. * <dd>Thrown if the verification ID is missing.</dd>
  5356. * <dt>auth/code-expired</dt>
  5357. * <dd>Thrown if the verification code has expired.</dd>
  5358. * <dt>auth/maximum-second-factor-count-exceeded</dt>
  5359. * <dd>Thrown if The maximum allowed number of second factors on a user
  5360. * has been exceeded.</dd>
  5361. * <dt>auth/second-factor-already-in-use</dt>
  5362. * <dd>Thrown if the second factor is already enrolled on this account.</dd>
  5363. * <dt>auth/unsupported-first-factor</dt>
  5364. * <dd>Thrown if the first factor being used to sign in is not supported.</dd>
  5365. * <dt>auth/unverified-email</dt>
  5366. * <dd>Thrown if the email of the account is not verified.</dd>
  5367. * <dt>auth/requires-recent-login</dt>
  5368. * <dd>Thrown if the user's last sign-in time does not meet the security
  5369. * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
  5370. * resolve.</dd>
  5371. * </dl>
  5372. *
  5373. * @example
  5374. * ```javascript
  5375. * firebase.auth().currentUser.multiFactor.getSession()
  5376. * .then(function(multiFactorSession) {
  5377. * // Send verification code
  5378. * var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
  5379. * var phoneInfoOptions = {
  5380. * phoneNumber: phoneNumber,
  5381. * session: multiFactorSession
  5382. * };
  5383. * return phoneAuthProvider.verifyPhoneNumber(
  5384. * phoneInfoOptions, appVerifier);
  5385. * }).then(function(verificationId) {
  5386. * // Store verificationID and show UI to let user enter verification code.
  5387. * });
  5388. *
  5389. * var phoneAuthCredential =
  5390. * firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
  5391. * var multiFactorAssertion =
  5392. * firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
  5393. * firebase.auth().currentUser.multiFactor.enroll(multiFactorAssertion)
  5394. * .then(function() {
  5395. * // Second factor enrolled.
  5396. * });
  5397. * ```
  5398. *
  5399. * @param assertion The multi-factor assertion to enroll with.
  5400. * @param displayName The display name of the second factor.
  5401. */
  5402. enroll(
  5403. assertion: firebase.auth.MultiFactorAssertion,
  5404. displayName?: string | null
  5405. ): Promise<void>;
  5406. /**
  5407. * Returns the session identifier for a second factor enrollment operation.
  5408. * This is used to identify the current user trying to enroll a second factor.
  5409. * @return The promise that resolves with the
  5410. * {@link firebase.auth.MultiFactorSession}.
  5411. *
  5412. * <h4>Error Codes</h4>
  5413. * <dl>
  5414. * <dt>auth/user-token-expired</dt>
  5415. * <dd>Thrown if the token of the user is expired.</dd>
  5416. * </dl>
  5417. */
  5418. getSession(): Promise<firebase.auth.MultiFactorSession>;
  5419. /**
  5420. * Unenrolls the specified second factor. To specify the factor to remove, pass
  5421. * a {@link firebase.auth.MultiFactorInfo} object
  5422. * (retrieved from <code>enrolledFactors()</code>)
  5423. * or the factor's UID string.
  5424. * Sessions are not revoked when the account is downgraded. An email
  5425. * notification is likely to be sent to the user notifying them of the change.
  5426. * Recent re-authentication is required for this operation to succeed.
  5427. * When an existing factor is unenrolled, an email notification is sent to the
  5428. * user’s email.
  5429. *
  5430. * <h4>Error Codes</h4>
  5431. * <dl>
  5432. * <dt>auth/multi-factor-info-not-found</dt>
  5433. * <dd>Thrown if the user does not have a second factor matching the
  5434. * identifier provided.</dd>
  5435. * <dt>auth/requires-recent-login</dt>
  5436. * <dd>Thrown if the user's last sign-in time does not meet the security
  5437. * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
  5438. * resolve.</dd>
  5439. * </dl>
  5440. *
  5441. * @example
  5442. * ```javascript
  5443. * var options = firebase.auth().currentUser.multiFactor.enrolledFactors;
  5444. * // Present user the option to unenroll.
  5445. * return firebase.auth().currentUser.multiFactor.unenroll(options[i])
  5446. * .then(function() {
  5447. * // User successfully unenrolled selected factor.
  5448. * }).catch(function(error) {
  5449. * // Handler error.
  5450. * });
  5451. * ```
  5452. *
  5453. * @param option The multi-factor option to unenroll.
  5454. */
  5455. unenroll(option: firebase.auth.MultiFactorInfo | string): Promise<void>;
  5456. }
  5457. }
  5458. declare namespace firebase.auth.ActionCodeInfo {
  5459. type Operation = string;
  5460. /**
  5461. * An enumeration of the possible email action types.
  5462. */
  5463. var Operation: {
  5464. /**
  5465. * The email link sign-in action.
  5466. */
  5467. EMAIL_SIGNIN: Operation;
  5468. /**
  5469. * The password reset action.
  5470. */
  5471. PASSWORD_RESET: Operation;
  5472. /**
  5473. * The email revocation action.
  5474. */
  5475. RECOVER_EMAIL: Operation;
  5476. /**
  5477. * The revert second factor addition email action.
  5478. */
  5479. REVERT_SECOND_FACTOR_ADDITION: Operation;
  5480. /**
  5481. * The verify and update email action.
  5482. */
  5483. VERIFY_AND_CHANGE_EMAIL: Operation;
  5484. /**
  5485. * The email verification action.
  5486. */
  5487. VERIFY_EMAIL: Operation;
  5488. };
  5489. }
  5490. declare namespace firebase.database {
  5491. /**
  5492. * A `DataSnapshot` contains data from a Database location.
  5493. *
  5494. * Any time you read data from the Database, you receive the data as a
  5495. * `DataSnapshot`. A `DataSnapshot` is passed to the event callbacks you attach
  5496. * with `on()` or `once()`. You can extract the contents of the snapshot as a
  5497. * JavaScript object by calling the `val()` method. Alternatively, you can
  5498. * traverse into the snapshot by calling `child()` to return child snapshots
  5499. * (which you could then call `val()` on).
  5500. *
  5501. * A `DataSnapshot` is an efficiently generated, immutable copy of the data at
  5502. * a Database location. It cannot be modified and will never change (to modify
  5503. * data, you always call the `set()` method on a `Reference` directly).
  5504. *
  5505. */
  5506. interface DataSnapshot {
  5507. /**
  5508. * Gets another `DataSnapshot` for the location at the specified relative path.
  5509. *
  5510. * Passing a relative path to the `child()` method of a DataSnapshot returns
  5511. * another `DataSnapshot` for the location at the specified relative path. The
  5512. * relative path can either be a simple child name (for example, "ada") or a
  5513. * deeper, slash-separated path (for example, "ada/name/first"). If the child
  5514. * location has no data, an empty `DataSnapshot` (that is, a `DataSnapshot`
  5515. * whose value is `null`) is returned.
  5516. *
  5517. * @example
  5518. * ```javascript
  5519. * // Assume we have the following data in the Database:
  5520. * {
  5521. * "name": {
  5522. * "first": "Ada",
  5523. * "last": "Lovelace"
  5524. * }
  5525. * }
  5526. *
  5527. * // Test for the existence of certain keys within a DataSnapshot
  5528. * var ref = firebase.database().ref("users/ada");
  5529. * ref.once("value")
  5530. * .then(function(snapshot) {
  5531. * var name = snapshot.child("name").val(); // {first:"Ada",last:"Lovelace"}
  5532. * var firstName = snapshot.child("name/first").val(); // "Ada"
  5533. * var lastName = snapshot.child("name").child("last").val(); // "Lovelace"
  5534. * var age = snapshot.child("age").val(); // null
  5535. * });
  5536. * ```
  5537. *
  5538. * @param path A relative path to the location of child data.
  5539. */
  5540. child(path: string): firebase.database.DataSnapshot;
  5541. /**
  5542. * Returns true if this `DataSnapshot` contains any data. It is slightly more
  5543. * efficient than using `snapshot.val() !== null`.
  5544. *
  5545. * @example
  5546. * ```javascript
  5547. * // Assume we have the following data in the Database:
  5548. * {
  5549. * "name": {
  5550. * "first": "Ada",
  5551. * "last": "Lovelace"
  5552. * }
  5553. * }
  5554. *
  5555. * // Test for the existence of certain keys within a DataSnapshot
  5556. * var ref = firebase.database().ref("users/ada");
  5557. * ref.once("value")
  5558. * .then(function(snapshot) {
  5559. * var a = snapshot.exists(); // true
  5560. * var b = snapshot.child("name").exists(); // true
  5561. * var c = snapshot.child("name/first").exists(); // true
  5562. * var d = snapshot.child("name/middle").exists(); // false
  5563. * });
  5564. * ```
  5565. */
  5566. exists(): boolean;
  5567. /**
  5568. * Exports the entire contents of the DataSnapshot as a JavaScript object.
  5569. *
  5570. * The `exportVal()` method is similar to `val()`, except priority information
  5571. * is included (if available), making it suitable for backing up your data.
  5572. *
  5573. * @return The DataSnapshot's contents as a JavaScript value (Object,
  5574. * Array, string, number, boolean, or `null`).
  5575. */
  5576. exportVal(): any;
  5577. /**
  5578. * Enumerates the top-level children in the `DataSnapshot`.
  5579. *
  5580. * Because of the way JavaScript objects work, the ordering of data in the
  5581. * JavaScript object returned by `val()` is not guaranteed to match the ordering
  5582. * on the server nor the ordering of `child_added` events. That is where
  5583. * `forEach()` comes in handy. It guarantees the children of a `DataSnapshot`
  5584. * will be iterated in their query order.
  5585. *
  5586. * If no explicit `orderBy*()` method is used, results are returned
  5587. * ordered by key (unless priorities are used, in which case, results are
  5588. * returned by priority).
  5589. *
  5590. * @example
  5591. * ```javascript
  5592. * // Assume we have the following data in the Database:
  5593. * {
  5594. * "users": {
  5595. * "ada": {
  5596. * "first": "Ada",
  5597. * "last": "Lovelace"
  5598. * },
  5599. * "alan": {
  5600. * "first": "Alan",
  5601. * "last": "Turing"
  5602. * }
  5603. * }
  5604. * }
  5605. *
  5606. * // Loop through users in order with the forEach() method. The callback
  5607. * // provided to forEach() will be called synchronously with a DataSnapshot
  5608. * // for each child:
  5609. * var query = firebase.database().ref("users").orderByKey();
  5610. * query.once("value")
  5611. * .then(function(snapshot) {
  5612. * snapshot.forEach(function(childSnapshot) {
  5613. * // key will be "ada" the first time and "alan" the second time
  5614. * var key = childSnapshot.key;
  5615. * // childData will be the actual contents of the child
  5616. * var childData = childSnapshot.val();
  5617. * });
  5618. * });
  5619. * ```
  5620. *
  5621. * @example
  5622. * ```javascript
  5623. * // You can cancel the enumeration at any point by having your callback
  5624. * // function return true. For example, the following code sample will only
  5625. * // fire the callback function one time:
  5626. * var query = firebase.database().ref("users").orderByKey();
  5627. * query.once("value")
  5628. * .then(function(snapshot) {
  5629. * snapshot.forEach(function(childSnapshot) {
  5630. * var key = childSnapshot.key; // "ada"
  5631. *
  5632. * // Cancel enumeration
  5633. * return true;
  5634. * });
  5635. * });
  5636. * ```
  5637. *
  5638. * @param action A function
  5639. * that will be called for each child DataSnapshot. The callback can return
  5640. * true to cancel further enumeration.
  5641. * @return true if enumeration was canceled due to your callback
  5642. * returning true.
  5643. */
  5644. forEach(
  5645. action: (a: firebase.database.DataSnapshot) => boolean | void
  5646. ): boolean;
  5647. /**
  5648. * Gets the priority value of the data in this `DataSnapshot`.
  5649. *
  5650. * Applications need not use priority but can order collections by
  5651. * ordinary properties (see
  5652. * {@link
  5653. * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
  5654. * Sorting and filtering data}).
  5655. */
  5656. getPriority(): string | number | null;
  5657. /**
  5658. * Returns true if the specified child path has (non-null) data.
  5659. *
  5660. * @example
  5661. * ```javascript
  5662. * // Assume we have the following data in the Database:
  5663. * {
  5664. * "name": {
  5665. * "first": "Ada",
  5666. * "last": "Lovelace"
  5667. * }
  5668. * }
  5669. *
  5670. * // Determine which child keys in DataSnapshot have data.
  5671. * var ref = firebase.database().ref("users/ada");
  5672. * ref.once("value")
  5673. * .then(function(snapshot) {
  5674. * var hasName = snapshot.hasChild("name"); // true
  5675. * var hasAge = snapshot.hasChild("age"); // false
  5676. * });
  5677. * ```
  5678. *
  5679. * @param path A relative path to the location of a potential child.
  5680. * @return `true` if data exists at the specified child path; else
  5681. * `false`.
  5682. */
  5683. hasChild(path: string): boolean;
  5684. /**
  5685. * Returns whether or not the `DataSnapshot` has any non-`null` child
  5686. * properties.
  5687. *
  5688. * You can use `hasChildren()` to determine if a `DataSnapshot` has any
  5689. * children. If it does, you can enumerate them using `forEach()`. If it
  5690. * doesn't, then either this snapshot contains a primitive value (which can be
  5691. * retrieved with `val()`) or it is empty (in which case, `val()` will return
  5692. * `null`).
  5693. *
  5694. * @example
  5695. * ```javascript
  5696. * // Assume we have the following data in the Database:
  5697. * {
  5698. * "name": {
  5699. * "first": "Ada",
  5700. * "last": "Lovelace"
  5701. * }
  5702. * }
  5703. *
  5704. * var ref = firebase.database().ref("users/ada");
  5705. * ref.once("value")
  5706. * .then(function(snapshot) {
  5707. * var a = snapshot.hasChildren(); // true
  5708. * var b = snapshot.child("name").hasChildren(); // true
  5709. * var c = snapshot.child("name/first").hasChildren(); // false
  5710. * });
  5711. * ```
  5712. *
  5713. * @return true if this snapshot has any children; else false.
  5714. */
  5715. hasChildren(): boolean;
  5716. /**
  5717. * The key (last part of the path) of the location of this `DataSnapshot`.
  5718. *
  5719. * The last token in a Database location is considered its key. For example,
  5720. * "ada" is the key for the /users/ada/ node. Accessing the key on any
  5721. * `DataSnapshot` will return the key for the location that generated it.
  5722. * However, accessing the key on the root URL of a Database will return `null`.
  5723. *
  5724. * @example
  5725. * ```javascript
  5726. * // Assume we have the following data in the Database:
  5727. * {
  5728. * "name": {
  5729. * "first": "Ada",
  5730. * "last": "Lovelace"
  5731. * }
  5732. * }
  5733. *
  5734. * var ref = firebase.database().ref("users/ada");
  5735. * ref.once("value")
  5736. * .then(function(snapshot) {
  5737. * var key = snapshot.key; // "ada"
  5738. * var childKey = snapshot.child("name/last").key; // "last"
  5739. * });
  5740. * ```
  5741. *
  5742. * @example
  5743. * ```javascript
  5744. * var rootRef = firebase.database().ref();
  5745. * rootRef.once("value")
  5746. * .then(function(snapshot) {
  5747. * var key = snapshot.key; // null
  5748. * var childKey = snapshot.child("users/ada").key; // "ada"
  5749. * });
  5750. * ```
  5751. */
  5752. key: string | null;
  5753. /**
  5754. * Returns the number of child properties of this `DataSnapshot`.
  5755. *
  5756. * @example
  5757. * ```javascript
  5758. * // Assume we have the following data in the Database:
  5759. * {
  5760. * "name": {
  5761. * "first": "Ada",
  5762. * "last": "Lovelace"
  5763. * }
  5764. * }
  5765. *
  5766. * var ref = firebase.database().ref("users/ada");
  5767. * ref.once("value")
  5768. * .then(function(snapshot) {
  5769. * var a = snapshot.numChildren(); // 1 ("name")
  5770. * var b = snapshot.child("name").numChildren(); // 2 ("first", "last")
  5771. * var c = snapshot.child("name/first").numChildren(); // 0
  5772. * });
  5773. * ```
  5774. */
  5775. numChildren(): number;
  5776. /**
  5777. * Extracts a JavaScript value from a `DataSnapshot`.
  5778. *
  5779. * Depending on the data in a `DataSnapshot`, the `val()` method may return a
  5780. * scalar type (string, number, or boolean), an array, or an object. It may also
  5781. * return null, indicating that the `DataSnapshot` is empty (contains no data).
  5782. *
  5783. * @example
  5784. * ```javascript
  5785. * // Write and then read back a string from the Database.
  5786. * ref.set("hello")
  5787. * .then(function() {
  5788. * return ref.once("value");
  5789. * })
  5790. * .then(function(snapshot) {
  5791. * var data = snapshot.val(); // data === "hello"
  5792. * });
  5793. * ```
  5794. *
  5795. * @example
  5796. * ```javascript
  5797. * // Write and then read back a JavaScript object from the Database.
  5798. * ref.set({ name: "Ada", age: 36 })
  5799. * .then(function() {
  5800. * return ref.once("value");
  5801. * })
  5802. * .then(function(snapshot) {
  5803. * var data = snapshot.val();
  5804. * // data is { "name": "Ada", "age": 36 }
  5805. * // data.name === "Ada"
  5806. * // data.age === 36
  5807. * });
  5808. * ```
  5809. *
  5810. * @return The DataSnapshot's contents as a JavaScript value (Object,
  5811. * Array, string, number, boolean, or `null`).
  5812. */
  5813. val(): any;
  5814. /**
  5815. * The `Reference` for the location that generated this `DataSnapshot`.
  5816. */
  5817. ref: firebase.database.Reference;
  5818. /**
  5819. * Returns a JSON-serializable representation of this object.
  5820. */
  5821. toJSON(): Object | null;
  5822. }
  5823. /**
  5824. * The Firebase Database service interface.
  5825. *
  5826. * Do not call this constructor directly. Instead, use
  5827. * {@link firebase.database `firebase.database()`}.
  5828. *
  5829. * See
  5830. * {@link
  5831. * https://firebase.google.com/docs/database/web/start/
  5832. * Installation &amp; Setup in JavaScript}
  5833. * for a full guide on how to use the Firebase Database service.
  5834. */
  5835. interface Database {
  5836. /**
  5837. * The {@link firebase.app.App app} associated with the `Database` service
  5838. * instance.
  5839. *
  5840. * @example
  5841. * ```javascript
  5842. * var app = database.app;
  5843. * ```
  5844. */
  5845. app: firebase.app.App;
  5846. /**
  5847. * Additional methods for debugging and special cases.
  5848. *
  5849. */
  5850. INTERNAL: {
  5851. /**
  5852. * Force the use of WebSockets instead of long polling.
  5853. */
  5854. forceWebSockets: () => void;
  5855. /**
  5856. * Force the use of long polling instead of WebSockets. This will be ignored if the WebSocket protocol is used in `databaseURL`.
  5857. */
  5858. forceLongPolling: () => void;
  5859. };
  5860. /**
  5861. * Modify this instance to communicate with the Realtime Database emulator.
  5862. *
  5863. * <p>Note: This method must be called before performing any other operation.
  5864. *
  5865. * @param host the emulator host (ex: localhost)
  5866. * @param port the emulator port (ex: 8080)
  5867. * @param options.mockUserToken the mock auth token to use for unit testing Security Rules
  5868. */
  5869. useEmulator(
  5870. host: string,
  5871. port: number,
  5872. options?: {
  5873. mockUserToken?: EmulatorMockTokenOptions | string;
  5874. }
  5875. ): void;
  5876. /**
  5877. * Disconnects from the server (all Database operations will be completed
  5878. * offline).
  5879. *
  5880. * The client automatically maintains a persistent connection to the Database
  5881. * server, which will remain active indefinitely and reconnect when
  5882. * disconnected. However, the `goOffline()` and `goOnline()` methods may be used
  5883. * to control the client connection in cases where a persistent connection is
  5884. * undesirable.
  5885. *
  5886. * While offline, the client will no longer receive data updates from the
  5887. * Database. However, all Database operations performed locally will continue to
  5888. * immediately fire events, allowing your application to continue behaving
  5889. * normally. Additionally, each operation performed locally will automatically
  5890. * be queued and retried upon reconnection to the Database server.
  5891. *
  5892. * To reconnect to the Database and begin receiving remote events, see
  5893. * `goOnline()`.
  5894. *
  5895. * @example
  5896. * ```javascript
  5897. * firebase.database().goOffline();
  5898. * ```
  5899. */
  5900. goOffline(): any;
  5901. /**
  5902. * Reconnects to the server and synchronizes the offline Database state
  5903. * with the server state.
  5904. *
  5905. * This method should be used after disabling the active connection with
  5906. * `goOffline()`. Once reconnected, the client will transmit the proper data
  5907. * and fire the appropriate events so that your client "catches up"
  5908. * automatically.
  5909. *
  5910. * @example
  5911. * ```javascript
  5912. * firebase.database().goOnline();
  5913. * ```
  5914. */
  5915. goOnline(): any;
  5916. /**
  5917. * Returns a `Reference` representing the location in the Database
  5918. * corresponding to the provided path. If no path is provided, the `Reference`
  5919. * will point to the root of the Database.
  5920. *
  5921. * @example
  5922. * ```javascript
  5923. * // Get a reference to the root of the Database
  5924. * var rootRef = firebase.database().ref();
  5925. * ```
  5926. *
  5927. * @example
  5928. * ```javascript
  5929. * // Get a reference to the /users/ada node
  5930. * var adaRef = firebase.database().ref("users/ada");
  5931. * // The above is shorthand for the following operations:
  5932. * //var rootRef = firebase.database().ref();
  5933. * //var adaRef = rootRef.child("users/ada");
  5934. * ```
  5935. *
  5936. * @param path Optional path representing the location the returned
  5937. * `Reference` will point. If not provided, the returned `Reference` will
  5938. * point to the root of the Database.
  5939. * @return If a path is provided, a `Reference`
  5940. * pointing to the provided path. Otherwise, a `Reference` pointing to the
  5941. * root of the Database.
  5942. */
  5943. ref(path?: string): firebase.database.Reference;
  5944. /**
  5945. * Returns a `Reference` representing the location in the Database
  5946. * corresponding to the provided Firebase URL.
  5947. *
  5948. * An exception is thrown if the URL is not a valid Firebase Database URL or it
  5949. * has a different domain than the current `Database` instance.
  5950. *
  5951. * Note that all query parameters (`orderBy`, `limitToLast`, etc.) are ignored
  5952. * and are not applied to the returned `Reference`.
  5953. *
  5954. * @example
  5955. * ```javascript
  5956. * // Get a reference to the root of the Database
  5957. * var rootRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com");
  5958. * ```
  5959. *
  5960. * @example
  5961. * ```javascript
  5962. * // Get a reference to the /users/ada node
  5963. * var adaRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com/users/ada");
  5964. * ```
  5965. *
  5966. * @param url The Firebase URL at which the returned `Reference` will
  5967. * point.
  5968. * @return A `Reference` pointing to the provided
  5969. * Firebase URL.
  5970. */
  5971. refFromURL(url: string): firebase.database.Reference;
  5972. }
  5973. /**
  5974. * The `onDisconnect` class allows you to write or clear data when your client
  5975. * disconnects from the Database server. These updates occur whether your
  5976. * client disconnects cleanly or not, so you can rely on them to clean up data
  5977. * even if a connection is dropped or a client crashes.
  5978. *
  5979. * The `onDisconnect` class is most commonly used to manage presence in
  5980. * applications where it is useful to detect how many clients are connected and
  5981. * when other clients disconnect. See
  5982. * {@link
  5983. * https://firebase.google.com/docs/database/web/offline-capabilities
  5984. * Enabling Offline Capabilities in JavaScript} for more information.
  5985. *
  5986. * To avoid problems when a connection is dropped before the requests can be
  5987. * transferred to the Database server, these functions should be called before
  5988. * writing any data.
  5989. *
  5990. * Note that `onDisconnect` operations are only triggered once. If you want an
  5991. * operation to occur each time a disconnect occurs, you'll need to re-establish
  5992. * the `onDisconnect` operations each time you reconnect.
  5993. */
  5994. interface OnDisconnect {
  5995. /**
  5996. * Cancels all previously queued `onDisconnect()` set or update events for this
  5997. * location and all children.
  5998. *
  5999. * If a write has been queued for this location via a `set()` or `update()` at a
  6000. * parent location, the write at this location will be canceled, though writes
  6001. * to sibling locations will still occur.
  6002. *
  6003. * @example
  6004. * ```javascript
  6005. * var ref = firebase.database().ref("onlineState");
  6006. * ref.onDisconnect().set(false);
  6007. * // ... sometime later
  6008. * ref.onDisconnect().cancel();
  6009. * ```
  6010. *
  6011. * @param onComplete An optional callback function that will
  6012. * be called when synchronization to the server has completed. The callback
  6013. * will be passed a single parameter: null for success, or an Error object
  6014. * indicating a failure.
  6015. * @return Resolves when synchronization to the server
  6016. * is complete.
  6017. */
  6018. cancel(onComplete?: (a: Error | null) => any): Promise<any>;
  6019. /**
  6020. * Ensures the data at this location is deleted when the client is disconnected
  6021. * (due to closing the browser, navigating to a new page, or network issues).
  6022. *
  6023. * @param onComplete An optional callback function that will
  6024. * be called when synchronization to the server has completed. The callback
  6025. * will be passed a single parameter: null for success, or an Error object
  6026. * indicating a failure.
  6027. * @return Resolves when synchronization to the server
  6028. * is complete.
  6029. */
  6030. remove(onComplete?: (a: Error | null) => any): Promise<any>;
  6031. /**
  6032. * Ensures the data at this location is set to the specified value when the
  6033. * client is disconnected (due to closing the browser, navigating to a new page,
  6034. * or network issues).
  6035. *
  6036. * `set()` is especially useful for implementing "presence" systems, where a
  6037. * value should be changed or cleared when a user disconnects so that they
  6038. * appear "offline" to other users. See
  6039. * {@link
  6040. * https://firebase.google.com/docs/database/web/offline-capabilities
  6041. * Enabling Offline Capabilities in JavaScript} for more information.
  6042. *
  6043. * Note that `onDisconnect` operations are only triggered once. If you want an
  6044. * operation to occur each time a disconnect occurs, you'll need to re-establish
  6045. * the `onDisconnect` operations each time.
  6046. *
  6047. * @example
  6048. * ```javascript
  6049. * var ref = firebase.database().ref("users/ada/status");
  6050. * ref.onDisconnect().set("I disconnected!");
  6051. * ```
  6052. *
  6053. * @param value The value to be written to this location on
  6054. * disconnect (can be an object, array, string, number, boolean, or null).
  6055. * @param onComplete An optional callback function that
  6056. * will be called when synchronization to the Database server has completed.
  6057. * The callback will be passed a single parameter: null for success, or an
  6058. * `Error` object indicating a failure.
  6059. * @return Resolves when synchronization to the
  6060. * Database is complete.
  6061. */
  6062. set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
  6063. /**
  6064. * Ensures the data at this location is set to the specified value and priority
  6065. * when the client is disconnected (due to closing the browser, navigating to a
  6066. * new page, or network issues).
  6067. */
  6068. setWithPriority(
  6069. value: any,
  6070. priority: number | string | null,
  6071. onComplete?: (a: Error | null) => any
  6072. ): Promise<any>;
  6073. /**
  6074. * Writes multiple values at this location when the client is disconnected (due
  6075. * to closing the browser, navigating to a new page, or network issues).
  6076. *
  6077. * The `values` argument contains multiple property-value pairs that will be
  6078. * written to the Database together. Each child property can either be a simple
  6079. * property (for example, "name") or a relative path (for example, "name/first")
  6080. * from the current location to the data to update.
  6081. *
  6082. * As opposed to the `set()` method, `update()` can be use to selectively update
  6083. * only the referenced properties at the current location (instead of replacing
  6084. * all the child properties at the current location).
  6085. *
  6086. * See more examples using the connected version of
  6087. * {@link firebase.database.Reference.update `update()`}.
  6088. *
  6089. * @example
  6090. * ```javascript
  6091. * var ref = firebase.database().ref("users/ada");
  6092. * ref.update({
  6093. * onlineState: true,
  6094. * status: "I'm online."
  6095. * });
  6096. * ref.onDisconnect().update({
  6097. * onlineState: false,
  6098. * status: "I'm offline."
  6099. * });
  6100. * ```
  6101. *
  6102. * @param values Object containing multiple values.
  6103. * @param onComplete An optional callback function that will
  6104. * be called when synchronization to the server has completed. The
  6105. * callback will be passed a single parameter: null for success, or an Error
  6106. * object indicating a failure.
  6107. * @return Resolves when synchronization to the
  6108. * Database is complete.
  6109. */
  6110. update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
  6111. }
  6112. type EventType =
  6113. | 'value'
  6114. | 'child_added'
  6115. | 'child_changed'
  6116. | 'child_moved'
  6117. | 'child_removed';
  6118. /**
  6119. * A `Query` sorts and filters the data at a Database location so only a subset
  6120. * of the child data is included. This can be used to order a collection of
  6121. * data by some attribute (for example, height of dinosaurs) as well as to
  6122. * restrict a large list of items (for example, chat messages) down to a number
  6123. * suitable for synchronizing to the client. Queries are created by chaining
  6124. * together one or more of the filter methods defined here.
  6125. *
  6126. * Just as with a `Reference`, you can receive data from a `Query` by using the
  6127. * `on()` method. You will only receive events and `DataSnapshot`s for the
  6128. * subset of the data that matches your query.
  6129. *
  6130. * Read our documentation on
  6131. * {@link
  6132. * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
  6133. * Sorting and filtering data} for more information.
  6134. */
  6135. interface Query {
  6136. /**
  6137. * Creates a `Query` with the specified ending point.
  6138. *
  6139. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  6140. * allows you to choose arbitrary starting and ending points for your queries.
  6141. *
  6142. * The ending point is inclusive, so children with exactly the specified value
  6143. * will be included in the query. The optional key argument can be used to
  6144. * further limit the range of the query. If it is specified, then children that
  6145. * have exactly the specified value must also have a key name less than or equal
  6146. * to the specified key.
  6147. *
  6148. * You can read more about `endAt()` in
  6149. * {@link
  6150. * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
  6151. * Filtering data}.
  6152. *
  6153. * @example
  6154. * ```javascript
  6155. * // Find all dinosaurs whose names come before Pterodactyl lexicographically.
  6156. * // Include Pterodactyl in the result.
  6157. * var ref = firebase.database().ref("dinosaurs");
  6158. * ref.orderByKey().endAt("pterodactyl").on("child_added", function(snapshot) {
  6159. * console.log(snapshot.key);
  6160. * });
  6161. * ```
  6162. *
  6163. * @param value The value to end at. The argument
  6164. * type depends on which `orderBy*()` function was used in this query.
  6165. * Specify a value that matches the `orderBy*()` type. When used in
  6166. * combination with `orderByKey()`, the value must be a string.
  6167. * @param key The child key to end at, among the children with the
  6168. * previously specified priority. This argument is only allowed if ordering by
  6169. * child, value, or priority.
  6170. */
  6171. endAt(
  6172. value: number | string | boolean | null,
  6173. key?: string
  6174. ): firebase.database.Query;
  6175. /**
  6176. * Creates a `Query` with the specified ending point (exclusive).
  6177. *
  6178. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  6179. * allows you to choose arbitrary starting and ending points for your queries.
  6180. *
  6181. * The ending point is exclusive. If only a value is provided, children
  6182. * with a value less than the specified value will be included in the query.
  6183. * If a key is specified, then children must have a value lesss than or equal
  6184. * to the specified value and a a key name less than the specified key.
  6185. *
  6186. * @example
  6187. * ```javascript
  6188. * // Find all dinosaurs whose names come before Pterodactyl lexicographically.
  6189. * // Do not include Pterodactyl in the result.
  6190. * var ref = firebase.database().ref("dinosaurs");
  6191. * ref.orderByKey().endBefore("pterodactyl").on("child_added", function(snapshot) {
  6192. * console.log(snapshot.key);
  6193. * });
  6194. *
  6195. * @param value The value to end before. The argument
  6196. * type depends on which `orderBy*()` function was used in this query.
  6197. * Specify a value that matches the `orderBy*()` type. When used in
  6198. * combination with `orderByKey()`, the value must be a string.
  6199. * @param key The child key to end before, among the children with the
  6200. * previously specified priority. This argument is only allowed if ordering by
  6201. * child, value, or priority.
  6202. */
  6203. endBefore(
  6204. value: number | string | boolean | null,
  6205. key?: string
  6206. ): firebase.database.Query;
  6207. /**
  6208. * Creates a `Query` that includes children that match the specified value.
  6209. *
  6210. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  6211. * allows you to choose arbitrary starting and ending points for your queries.
  6212. *
  6213. * The optional key argument can be used to further limit the range of the
  6214. * query. If it is specified, then children that have exactly the specified
  6215. * value must also have exactly the specified key as their key name. This can be
  6216. * used to filter result sets with many matches for the same value.
  6217. *
  6218. * You can read more about `equalTo()` in
  6219. * {@link
  6220. * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
  6221. * Filtering data}.
  6222. *
  6223. * @example
  6224. * ```javascript
  6225. * // Find all dinosaurs whose height is exactly 25 meters.
  6226. * var ref = firebase.database().ref("dinosaurs");
  6227. * ref.orderByChild("height").equalTo(25).on("child_added", function(snapshot) {
  6228. * console.log(snapshot.key);
  6229. * });
  6230. * ```
  6231. *
  6232. * @param value The value to match for. The
  6233. * argument type depends on which `orderBy*()` function was used in this
  6234. * query. Specify a value that matches the `orderBy*()` type. When used in
  6235. * combination with `orderByKey()`, the value must be a string.
  6236. * @param key The child key to start at, among the children with the
  6237. * previously specified priority. This argument is only allowed if ordering by
  6238. * child, value, or priority.
  6239. */
  6240. equalTo(
  6241. value: number | string | boolean | null,
  6242. key?: string
  6243. ): firebase.database.Query;
  6244. /**
  6245. * Returns whether or not the current and provided queries represent the same
  6246. * location, have the same query parameters, and are from the same instance of
  6247. * `firebase.app.App`.
  6248. *
  6249. * Two `Reference` objects are equivalent if they represent the same location
  6250. * and are from the same instance of `firebase.app.App`.
  6251. *
  6252. * Two `Query` objects are equivalent if they represent the same location, have
  6253. * the same query parameters, and are from the same instance of
  6254. * `firebase.app.App`. Equivalent queries share the same sort order, limits, and
  6255. * starting and ending points.
  6256. *
  6257. * @example
  6258. * ```javascript
  6259. * var rootRef = firebase.database.ref();
  6260. * var usersRef = rootRef.child("users");
  6261. *
  6262. * usersRef.isEqual(rootRef); // false
  6263. * usersRef.isEqual(rootRef.child("users")); // true
  6264. * usersRef.parent.isEqual(rootRef); // true
  6265. * ```
  6266. *
  6267. * @example
  6268. * ```javascript
  6269. * var rootRef = firebase.database.ref();
  6270. * var usersRef = rootRef.child("users");
  6271. * var usersQuery = usersRef.limitToLast(10);
  6272. *
  6273. * usersQuery.isEqual(usersRef); // false
  6274. * usersQuery.isEqual(usersRef.limitToLast(10)); // true
  6275. * usersQuery.isEqual(rootRef.limitToLast(10)); // false
  6276. * usersQuery.isEqual(usersRef.orderByKey().limitToLast(10)); // false
  6277. * ```
  6278. *
  6279. * @param other The query to compare against.
  6280. * @return Whether or not the current and provided queries are
  6281. * equivalent.
  6282. */
  6283. isEqual(other: firebase.database.Query | null): boolean;
  6284. /**
  6285. * Generates a new `Query` limited to the first specific number of children.
  6286. *
  6287. * The `limitToFirst()` method is used to set a maximum number of children to be
  6288. * synced for a given callback. If we set a limit of 100, we will initially only
  6289. * receive up to 100 `child_added` events. If we have fewer than 100 messages
  6290. * stored in our Database, a `child_added` event will fire for each message.
  6291. * However, if we have over 100 messages, we will only receive a `child_added`
  6292. * event for the first 100 ordered messages. As items change, we will receive
  6293. * `child_removed` events for each item that drops out of the active list so
  6294. * that the total number stays at 100.
  6295. *
  6296. * You can read more about `limitToFirst()` in
  6297. * {@link
  6298. * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
  6299. * Filtering data}.
  6300. *
  6301. * @example
  6302. * ```javascript
  6303. * // Find the two shortest dinosaurs.
  6304. * var ref = firebase.database().ref("dinosaurs");
  6305. * ref.orderByChild("height").limitToFirst(2).on("child_added", function(snapshot) {
  6306. * // This will be called exactly two times (unless there are less than two
  6307. * // dinosaurs in the Database).
  6308. *
  6309. * // It will also get fired again if one of the first two dinosaurs is
  6310. * // removed from the data set, as a new dinosaur will now be the second
  6311. * // shortest.
  6312. * console.log(snapshot.key);
  6313. * });
  6314. * ```
  6315. *
  6316. * @param limit The maximum number of nodes to include in this query.
  6317. */
  6318. limitToFirst(limit: number): firebase.database.Query;
  6319. /**
  6320. * Generates a new `Query` object limited to the last specific number of
  6321. * children.
  6322. *
  6323. * The `limitToLast()` method is used to set a maximum number of children to be
  6324. * synced for a given callback. If we set a limit of 100, we will initially only
  6325. * receive up to 100 `child_added` events. If we have fewer than 100 messages
  6326. * stored in our Database, a `child_added` event will fire for each message.
  6327. * However, if we have over 100 messages, we will only receive a `child_added`
  6328. * event for the last 100 ordered messages. As items change, we will receive
  6329. * `child_removed` events for each item that drops out of the active list so
  6330. * that the total number stays at 100.
  6331. *
  6332. * You can read more about `limitToLast()` in
  6333. * {@link
  6334. * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
  6335. * Filtering data}.
  6336. *
  6337. * @example
  6338. * ```javascript
  6339. * // Find the two heaviest dinosaurs.
  6340. * var ref = firebase.database().ref("dinosaurs");
  6341. * ref.orderByChild("weight").limitToLast(2).on("child_added", function(snapshot) {
  6342. * // This callback will be triggered exactly two times, unless there are
  6343. * // fewer than two dinosaurs stored in the Database. It will also get fired
  6344. * // for every new, heavier dinosaur that gets added to the data set.
  6345. * console.log(snapshot.key);
  6346. * });
  6347. * ```
  6348. *
  6349. * @param limit The maximum number of nodes to include in this query.
  6350. */
  6351. limitToLast(limit: number): firebase.database.Query;
  6352. /**
  6353. * Detaches a callback previously attached with `on()`.
  6354. *
  6355. * Detach a callback previously attached with `on()`. Note that if `on()` was
  6356. * called multiple times with the same eventType and callback, the callback
  6357. * will be called multiple times for each event, and `off()` must be called
  6358. * multiple times to remove the callback. Calling `off()` on a parent listener
  6359. * will not automatically remove listeners registered on child nodes, `off()`
  6360. * must also be called on any child listeners to remove the callback.
  6361. *
  6362. * If a callback is not specified, all callbacks for the specified eventType
  6363. * will be removed. Similarly, if no eventType is specified, all callbacks
  6364. * for the `Reference` will be removed.
  6365. *
  6366. * @example
  6367. * ```javascript
  6368. * var onValueChange = function(dataSnapshot) { ... };
  6369. * ref.on('value', onValueChange);
  6370. * ref.child('meta-data').on('child_added', onChildAdded);
  6371. * // Sometime later...
  6372. * ref.off('value', onValueChange);
  6373. *
  6374. * // You must also call off() for any child listeners on ref
  6375. * // to cancel those callbacks
  6376. * ref.child('meta-data').off('child_added', onValueAdded);
  6377. * ```
  6378. *
  6379. * @example
  6380. * ```javascript
  6381. * // Or you can save a line of code by using an inline function
  6382. * // and on()'s return value.
  6383. * var onValueChange = ref.on('value', function(dataSnapshot) { ... });
  6384. * // Sometime later...
  6385. * ref.off('value', onValueChange);
  6386. * ```
  6387. *
  6388. * @param eventType One of the following strings: "value",
  6389. * "child_added", "child_changed", "child_removed", or "child_moved." If
  6390. * omitted, all callbacks for the `Reference` will be removed.
  6391. * @param callback The callback function that was passed to `on()` or
  6392. * `undefined` to remove all callbacks.
  6393. * @param context The context that was passed to `on()`.
  6394. */
  6395. off(
  6396. eventType?: EventType,
  6397. callback?: (a: firebase.database.DataSnapshot, b?: string | null) => any,
  6398. context?: Object | null
  6399. ): void;
  6400. /**
  6401. * Gets the most up-to-date result for this query.
  6402. *
  6403. * @return A promise which resolves to the resulting DataSnapshot if
  6404. * a value is available, or rejects if the client is unable to return
  6405. * a value (e.g., if the server is unreachable and there is nothing
  6406. * cached).
  6407. */
  6408. get(): Promise<DataSnapshot>;
  6409. /**
  6410. * Listens for data changes at a particular location.
  6411. *
  6412. * This is the primary way to read data from a Database. Your callback
  6413. * will be triggered for the initial data and again whenever the data changes.
  6414. * Use `off( )` to stop receiving updates. See
  6415. * {@link https://firebase.google.com/docs/database/web/retrieve-data
  6416. * Retrieve Data on the Web}
  6417. * for more details.
  6418. *
  6419. * <h4>value event</h4>
  6420. *
  6421. * This event will trigger once with the initial data stored at this location,
  6422. * and then trigger again each time the data changes. The `DataSnapshot` passed
  6423. * to the callback will be for the location at which `on()` was called. It
  6424. * won't trigger until the entire contents has been synchronized. If the
  6425. * location has no data, it will be triggered with an empty `DataSnapshot`
  6426. * (`val()` will return `null`).
  6427. *
  6428. * <h4>child_added event</h4>
  6429. *
  6430. * This event will be triggered once for each initial child at this location,
  6431. * and it will be triggered again every time a new child is added. The
  6432. * `DataSnapshot` passed into the callback will reflect the data for the
  6433. * relevant child. For ordering purposes, it is passed a second argument which
  6434. * is a string containing the key of the previous sibling child by sort order,
  6435. * or `null` if it is the first child.
  6436. *
  6437. * <h4>child_removed event</h4>
  6438. *
  6439. * This event will be triggered once every time a child is removed. The
  6440. * `DataSnapshot` passed into the callback will be the old data for the child
  6441. * that was removed. A child will get removed when either:
  6442. *
  6443. * - a client explicitly calls `remove()` on that child or one of its ancestors
  6444. * - a client calls `set(null)` on that child or one of its ancestors
  6445. * - that child has all of its children removed
  6446. * - there is a query in effect which now filters out the child (because it's
  6447. * sort order changed or the max limit was hit)
  6448. *
  6449. * <h4>child_changed event</h4>
  6450. *
  6451. * This event will be triggered when the data stored in a child (or any of its
  6452. * descendants) changes. Note that a single `child_changed` event may represent
  6453. * multiple changes to the child. The `DataSnapshot` passed to the callback will
  6454. * contain the new child contents. For ordering purposes, the callback is also
  6455. * passed a second argument which is a string containing the key of the previous
  6456. * sibling child by sort order, or `null` if it is the first child.
  6457. *
  6458. * <h4>child_moved event</h4>
  6459. *
  6460. * This event will be triggered when a child's sort order changes such that its
  6461. * position relative to its siblings changes. The `DataSnapshot` passed to the
  6462. * callback will be for the data of the child that has moved. It is also passed
  6463. * a second argument which is a string containing the key of the previous
  6464. * sibling child by sort order, or `null` if it is the first child.
  6465. *
  6466. * @example **Handle a new value:**
  6467. * ```javascript
  6468. * ref.on('value', function(dataSnapshot) {
  6469. * ...
  6470. * });
  6471. * ```
  6472. *
  6473. * @example **Handle a new child:**
  6474. * ```javascript
  6475. * ref.on('child_added', function(childSnapshot, prevChildKey) {
  6476. * ...
  6477. * });
  6478. * ```
  6479. *
  6480. * @example **Handle child removal:**
  6481. * ```javascript
  6482. * ref.on('child_removed', function(oldChildSnapshot) {
  6483. * ...
  6484. * });
  6485. * ```
  6486. *
  6487. * @example **Handle child data changes:**
  6488. * ```javascript
  6489. * ref.on('child_changed', function(childSnapshot, prevChildKey) {
  6490. * ...
  6491. * });
  6492. * ```
  6493. *
  6494. * @example **Handle child ordering changes:**
  6495. * ```javascript
  6496. * ref.on('child_moved', function(childSnapshot, prevChildKey) {
  6497. * ...
  6498. * });
  6499. * ```
  6500. *
  6501. * @param eventType One of the following strings: "value",
  6502. * "child_added", "child_changed", "child_removed", or "child_moved."
  6503. * @param callback A
  6504. * callback that fires when the specified event occurs. The callback will be
  6505. * passed a DataSnapshot. For ordering purposes, "child_added",
  6506. * "child_changed", and "child_moved" will also be passed a string containing
  6507. * the key of the previous child, by sort order, or `null` if it is the
  6508. * first child.
  6509. * @param cancelCallbackOrContext An optional
  6510. * callback that will be notified if your event subscription is ever canceled
  6511. * because your client does not have permission to read this data (or it had
  6512. * permission but has now lost it). This callback will be passed an `Error`
  6513. * object indicating why the failure occurred.
  6514. * @param context If provided, this object will be used as `this`
  6515. * when calling your callback(s).
  6516. * @return The provided
  6517. * callback function is returned unmodified. This is just for convenience if
  6518. * you want to pass an inline function to `on()` but store the callback
  6519. * function for later passing to `off()`.
  6520. */
  6521. on(
  6522. eventType: EventType,
  6523. callback: (a: firebase.database.DataSnapshot, b?: string | null) => any,
  6524. cancelCallbackOrContext?: ((a: Error) => any) | Object | null,
  6525. context?: Object | null
  6526. ): (a: firebase.database.DataSnapshot | null, b?: string | null) => any;
  6527. /**
  6528. * Listens for exactly one event of the specified event type, and then stops
  6529. * listening.
  6530. *
  6531. * This is equivalent to calling {@link firebase.database.Query.on `on()`}, and
  6532. * then calling {@link firebase.database.Query.off `off()`} inside the callback
  6533. * function. See {@link firebase.database.Query.on `on()`} for details on the
  6534. * event types.
  6535. *
  6536. * @example
  6537. * ```javascript
  6538. * // Basic usage of .once() to read the data located at ref.
  6539. * ref.once('value')
  6540. * .then(function(dataSnapshot) {
  6541. * // handle read data.
  6542. * });
  6543. * ```
  6544. *
  6545. * @param eventType One of the following strings: "value",
  6546. * "child_added", "child_changed", "child_removed", or "child_moved."
  6547. * @param successCallback A
  6548. * callback that fires when the specified event occurs. The callback will be
  6549. * passed a DataSnapshot. For ordering purposes, "child_added",
  6550. * "child_changed", and "child_moved" will also be passed a string containing
  6551. * the key of the previous child by sort order, or `null` if it is the
  6552. * first child.
  6553. * @param failureCallbackOrContext An optional
  6554. * callback that will be notified if your client does not have permission to
  6555. * read the data. This callback will be passed an `Error` object indicating
  6556. * why the failure occurred.
  6557. * @param context If provided, this object will be used as `this`
  6558. * when calling your callback(s).
  6559. */
  6560. once(
  6561. eventType: EventType,
  6562. successCallback?: (
  6563. a: firebase.database.DataSnapshot,
  6564. b?: string | null
  6565. ) => any,
  6566. failureCallbackOrContext?: ((a: Error) => void) | Object | null,
  6567. context?: Object | null
  6568. ): Promise<firebase.database.DataSnapshot>;
  6569. /**
  6570. * Generates a new `Query` object ordered by the specified child key.
  6571. *
  6572. * Queries can only order by one key at a time. Calling `orderByChild()`
  6573. * multiple times on the same query is an error.
  6574. *
  6575. * Firebase queries allow you to order your data by any child key on the fly.
  6576. * However, if you know in advance what your indexes will be, you can define
  6577. * them via the .indexOn rule in your Security Rules for better performance. See
  6578. * the {@link https://firebase.google.com/docs/database/security/indexing-data
  6579. * .indexOn} rule for more information.
  6580. *
  6581. * You can read more about `orderByChild()` in
  6582. * {@link
  6583. * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
  6584. * Sort data}.
  6585. *
  6586. * @example
  6587. * ```javascript
  6588. * var ref = firebase.database().ref("dinosaurs");
  6589. * ref.orderByChild("height").on("child_added", function(snapshot) {
  6590. * console.log(snapshot.key + " was " + snapshot.val().height + " m tall");
  6591. * });
  6592. * ```
  6593. */
  6594. orderByChild(path: string): firebase.database.Query;
  6595. /**
  6596. * Generates a new `Query` object ordered by key.
  6597. *
  6598. * Sorts the results of a query by their (ascending) key values.
  6599. *
  6600. * You can read more about `orderByKey()` in
  6601. * {@link
  6602. * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
  6603. * Sort data}.
  6604. *
  6605. * @example
  6606. * ```javascript
  6607. * var ref = firebase.database().ref("dinosaurs");
  6608. * ref.orderByKey().on("child_added", function(snapshot) {
  6609. * console.log(snapshot.key);
  6610. * });
  6611. * ```
  6612. */
  6613. orderByKey(): firebase.database.Query;
  6614. /**
  6615. * Generates a new `Query` object ordered by priority.
  6616. *
  6617. * Applications need not use priority but can order collections by
  6618. * ordinary properties (see
  6619. * {@link
  6620. * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
  6621. * Sort data} for alternatives to priority.
  6622. */
  6623. orderByPriority(): firebase.database.Query;
  6624. /**
  6625. * Generates a new `Query` object ordered by value.
  6626. *
  6627. * If the children of a query are all scalar values (string, number, or
  6628. * boolean), you can order the results by their (ascending) values.
  6629. *
  6630. * You can read more about `orderByValue()` in
  6631. * {@link
  6632. * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
  6633. * Sort data}.
  6634. *
  6635. * @example
  6636. * ```javascript
  6637. * var scoresRef = firebase.database().ref("scores");
  6638. * scoresRef.orderByValue().limitToLast(3).on("value", function(snapshot) {
  6639. * snapshot.forEach(function(data) {
  6640. * console.log("The " + data.key + " score is " + data.val());
  6641. * });
  6642. * });
  6643. * ```
  6644. */
  6645. orderByValue(): firebase.database.Query;
  6646. /**
  6647. * Returns a `Reference` to the `Query`'s location.
  6648. */
  6649. ref: firebase.database.Reference;
  6650. /**
  6651. * Creates a `Query` with the specified starting point.
  6652. *
  6653. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  6654. * allows you to choose arbitrary starting and ending points for your queries.
  6655. *
  6656. * The starting point is inclusive, so children with exactly the specified value
  6657. * will be included in the query. The optional key argument can be used to
  6658. * further limit the range of the query. If it is specified, then children that
  6659. * have exactly the specified value must also have a key name greater than or
  6660. * equal to the specified key.
  6661. *
  6662. * You can read more about `startAt()` in
  6663. * {@link
  6664. * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
  6665. * Filtering data}.
  6666. *
  6667. * @example
  6668. * ```javascript
  6669. * // Find all dinosaurs that are at least three meters tall.
  6670. * var ref = firebase.database().ref("dinosaurs");
  6671. * ref.orderByChild("height").startAt(3).on("child_added", function(snapshot) {
  6672. * console.log(snapshot.key)
  6673. * });
  6674. * ```
  6675. *
  6676. * @param value The value to start at. The argument
  6677. * type depends on which `orderBy*()` function was used in this query.
  6678. * Specify a value that matches the `orderBy*()` type. When used in
  6679. * combination with `orderByKey()`, the value must be a string.
  6680. * @param key The child key to start at. This argument is only allowed
  6681. * if ordering by child, value, or priority.
  6682. */
  6683. startAt(
  6684. value: number | string | boolean | null,
  6685. key?: string
  6686. ): firebase.database.Query;
  6687. /**
  6688. * Creates a `Query` with the specified starting point (exclusive).
  6689. *
  6690. * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
  6691. * allows you to choose arbitrary starting and ending points for your queries.
  6692. *
  6693. * The starting point is exclusive. If only a value is provided, children
  6694. * with a value greater than the specified value will be included in the query.
  6695. * If a key is specified, then children must have a value greater than or equal
  6696. * to the specified value and a a key name greater than the specified key.
  6697. *
  6698. * @example
  6699. * ```javascript
  6700. * // Find all dinosaurs that are more than three meters tall.
  6701. * var ref = firebase.database().ref("dinosaurs");
  6702. * ref.orderByChild("height").startAfter(3).on("child_added", function(snapshot) {
  6703. * console.log(snapshot.key)
  6704. * });
  6705. * ```
  6706. *
  6707. * @param value The value to start after. The argument
  6708. * type depends on which `orderBy*()` function was used in this query.
  6709. * Specify a value that matches the `orderBy*()` type. When used in
  6710. * combination with `orderByKey()`, the value must be a string.
  6711. * @param key The child key to start after. This argument is only allowed
  6712. * if ordering by child, value, or priority.
  6713. */
  6714. startAfter(
  6715. value: number | string | boolean | null,
  6716. key?: string
  6717. ): firebase.database.Query;
  6718. /**
  6719. * Returns a JSON-serializable representation of this object.
  6720. *
  6721. * @return A JSON-serializable representation of this object.
  6722. */
  6723. toJSON(): Object;
  6724. /**
  6725. * Gets the absolute URL for this location.
  6726. *
  6727. * The `toString()` method returns a URL that is ready to be put into a browser,
  6728. * curl command, or a `firebase.database().refFromURL()` call. Since all of
  6729. * those expect the URL to be url-encoded, `toString()` returns an encoded URL.
  6730. *
  6731. * Append '.json' to the returned URL when typed into a browser to download
  6732. * JSON-formatted data. If the location is secured (that is, not publicly
  6733. * readable), you will get a permission-denied error.
  6734. *
  6735. * @example
  6736. * ```javascript
  6737. * // Calling toString() on a root Firebase reference returns the URL where its
  6738. * // data is stored within the Database:
  6739. * var rootRef = firebase.database().ref();
  6740. * var rootUrl = rootRef.toString();
  6741. * // rootUrl === "https://sample-app.firebaseio.com/".
  6742. *
  6743. * // Calling toString() at a deeper Firebase reference returns the URL of that
  6744. * // deep path within the Database:
  6745. * var adaRef = rootRef.child('users/ada');
  6746. * var adaURL = adaRef.toString();
  6747. * // adaURL === "https://sample-app.firebaseio.com/users/ada".
  6748. * ```
  6749. *
  6750. * @return The absolute URL for this location.
  6751. */
  6752. toString(): string;
  6753. }
  6754. /**
  6755. * A `Reference` represents a specific location in your Database and can be used
  6756. * for reading or writing data to that Database location.
  6757. *
  6758. * You can reference the root or child location in your Database by calling
  6759. * `firebase.database().ref()` or `firebase.database().ref("child/path")`.
  6760. *
  6761. * Writing is done with the `set()` method and reading can be done with the
  6762. * `on()` method. See
  6763. * {@link
  6764. * https://firebase.google.com/docs/database/web/read-and-write
  6765. * Read and Write Data on the Web}
  6766. */
  6767. interface Reference extends firebase.database.Query {
  6768. /**
  6769. * Gets a `Reference` for the location at the specified relative path.
  6770. *
  6771. * The relative path can either be a simple child name (for example, "ada") or
  6772. * a deeper slash-separated path (for example, "ada/name/first").
  6773. *
  6774. * @example
  6775. * ```javascript
  6776. * var usersRef = firebase.database().ref('users');
  6777. * var adaRef = usersRef.child('ada');
  6778. * var adaFirstNameRef = adaRef.child('name/first');
  6779. * var path = adaFirstNameRef.toString();
  6780. * // path is now 'https://sample-app.firebaseio.com/users/ada/name/first'
  6781. * ```
  6782. *
  6783. * @param path A relative path from this location to the desired child
  6784. * location.
  6785. * @return The specified child location.
  6786. */
  6787. child(path: string): firebase.database.Reference;
  6788. /**
  6789. * The last part of the `Reference`'s path.
  6790. *
  6791. * For example, `"ada"` is the key for
  6792. * `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
  6793. *
  6794. * The key of a root `Reference` is `null`.
  6795. *
  6796. * @example
  6797. * ```javascript
  6798. * // The key of a root reference is null
  6799. * var rootRef = firebase.database().ref();
  6800. * var key = rootRef.key; // key === null
  6801. * ```
  6802. *
  6803. * @example
  6804. * ```javascript
  6805. * // The key of any non-root reference is the last token in the path
  6806. * var adaRef = firebase.database().ref("users/ada");
  6807. * var key = adaRef.key; // key === "ada"
  6808. * key = adaRef.child("name/last").key; // key === "last"
  6809. * ```
  6810. */
  6811. key: string | null;
  6812. /**
  6813. * Returns an `OnDisconnect` object - see
  6814. * {@link
  6815. * https://firebase.google.com/docs/database/web/offline-capabilities
  6816. * Enabling Offline Capabilities in JavaScript} for more information on how
  6817. * to use it.
  6818. */
  6819. onDisconnect(): firebase.database.OnDisconnect;
  6820. /**
  6821. * The parent location of a `Reference`.
  6822. *
  6823. * The parent of a root `Reference` is `null`.
  6824. *
  6825. * @example
  6826. * ```javascript
  6827. * // The parent of a root reference is null
  6828. * var rootRef = firebase.database().ref();
  6829. * parent = rootRef.parent; // parent === null
  6830. * ```
  6831. *
  6832. * @example
  6833. * ```javascript
  6834. * // The parent of any non-root reference is the parent location
  6835. * var usersRef = firebase.database().ref("users");
  6836. * var adaRef = firebase.database().ref("users/ada");
  6837. * // usersRef and adaRef.parent represent the same location
  6838. * ```
  6839. */
  6840. parent: firebase.database.Reference | null;
  6841. /**
  6842. * Generates a new child location using a unique key and returns its
  6843. * `Reference`.
  6844. *
  6845. * This is the most common pattern for adding data to a collection of items.
  6846. *
  6847. * If you provide a value to `push()`, the value is written to the
  6848. * generated location. If you don't pass a value, nothing is written to the
  6849. * database and the child remains empty (but you can use the `Reference`
  6850. * elsewhere).
  6851. *
  6852. * The unique keys generated by `push()` are ordered by the current time, so the
  6853. * resulting list of items is chronologically sorted. The keys are also
  6854. * designed to be unguessable (they contain 72 random bits of entropy).
  6855. *
  6856. *
  6857. * See
  6858. * {@link
  6859. * https://firebase.google.com/docs/database/web/lists-of-data#append_to_a_list_of_data
  6860. * Append to a list of data}
  6861. * </br>See
  6862. * {@link
  6863. * https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html
  6864. * The 2^120 Ways to Ensure Unique Identifiers}
  6865. *
  6866. * @example
  6867. * ```javascript
  6868. * var messageListRef = firebase.database().ref('message_list');
  6869. * var newMessageRef = messageListRef.push();
  6870. * newMessageRef.set({
  6871. * 'user_id': 'ada',
  6872. * 'text': 'The Analytical Engine weaves algebraical patterns just as the Jacquard loom weaves flowers and leaves.'
  6873. * });
  6874. * // We've appended a new message to the message_list location.
  6875. * var path = newMessageRef.toString();
  6876. * // path will be something like
  6877. * // 'https://sample-app.firebaseio.com/message_list/-IKo28nwJLH0Nc5XeFmj'
  6878. * ```
  6879. *
  6880. * @param value Optional value to be written at the generated location.
  6881. * @param onComplete Callback called when write to server is
  6882. * complete.
  6883. * @return Combined `Promise` and `Reference`; resolves when write is complete, but can be
  6884. * used immediately as the `Reference` to the child location.
  6885. */
  6886. push(
  6887. value?: any,
  6888. onComplete?: (a: Error | null) => any
  6889. ): firebase.database.ThenableReference;
  6890. /**
  6891. * Removes the data at this Database location.
  6892. *
  6893. * Any data at child locations will also be deleted.
  6894. *
  6895. * The effect of the remove will be visible immediately and the corresponding
  6896. * event 'value' will be triggered. Synchronization of the remove to the
  6897. * Firebase servers will also be started, and the returned Promise will resolve
  6898. * when complete. If provided, the onComplete callback will be called
  6899. * asynchronously after synchronization has finished.
  6900. *
  6901. * @example
  6902. * ```javascript
  6903. * var adaRef = firebase.database().ref('users/ada');
  6904. * adaRef.remove()
  6905. * .then(function() {
  6906. * console.log("Remove succeeded.")
  6907. * })
  6908. * .catch(function(error) {
  6909. * console.log("Remove failed: " + error.message)
  6910. * });
  6911. * ```
  6912. *
  6913. * @param onComplete Callback called when write to server is
  6914. * complete.
  6915. * @return Resolves when remove on server is complete.
  6916. */
  6917. remove(onComplete?: (a: Error | null) => void): Promise<void>;
  6918. /**
  6919. * The root `Reference` of the Database.
  6920. *
  6921. * @example
  6922. * ```javascript
  6923. * // The root of a root reference is itself
  6924. * var rootRef = firebase.database().ref();
  6925. * // rootRef and rootRef.root represent the same location
  6926. * ```
  6927. *
  6928. * @example
  6929. * ```javascript
  6930. * // The root of any non-root reference is the root location
  6931. * var adaRef = firebase.database().ref("users/ada");
  6932. * // rootRef and adaRef.root represent the same location
  6933. * ```
  6934. */
  6935. root: firebase.database.Reference;
  6936. /**
  6937. * Writes data to this Database location.
  6938. *
  6939. * This will overwrite any data at this location and all child locations.
  6940. *
  6941. * The effect of the write will be visible immediately, and the corresponding
  6942. * events ("value", "child_added", etc.) will be triggered. Synchronization of
  6943. * the data to the Firebase servers will also be started, and the returned
  6944. * Promise will resolve when complete. If provided, the `onComplete` callback
  6945. * will be called asynchronously after synchronization has finished.
  6946. *
  6947. * Passing `null` for the new value is equivalent to calling `remove()`; namely,
  6948. * all data at this location and all child locations will be deleted.
  6949. *
  6950. * `set()` will remove any priority stored at this location, so if priority is
  6951. * meant to be preserved, you need to use `setWithPriority()` instead.
  6952. *
  6953. * Note that modifying data with `set()` will cancel any pending transactions
  6954. * at that location, so extreme care should be taken if mixing `set()` and
  6955. * `transaction()` to modify the same data.
  6956. *
  6957. * A single `set()` will generate a single "value" event at the location where
  6958. * the `set()` was performed.
  6959. *
  6960. * @example
  6961. * ```javascript
  6962. * var adaNameRef = firebase.database().ref('users/ada/name');
  6963. * adaNameRef.child('first').set('Ada');
  6964. * adaNameRef.child('last').set('Lovelace');
  6965. * // We've written 'Ada' to the Database location storing Ada's first name,
  6966. * // and 'Lovelace' to the location storing her last name.
  6967. * ```
  6968. *
  6969. * @example
  6970. * ```javascript
  6971. * adaNameRef.set({ first: 'Ada', last: 'Lovelace' });
  6972. * // Exact same effect as the previous example, except we've written
  6973. * // Ada's first and last name simultaneously.
  6974. * ```
  6975. *
  6976. * @example
  6977. * ```javascript
  6978. * adaNameRef.set({ first: 'Ada', last: 'Lovelace' })
  6979. * .then(function() {
  6980. * console.log('Synchronization succeeded');
  6981. * })
  6982. * .catch(function(error) {
  6983. * console.log('Synchronization failed');
  6984. * });
  6985. * // Same as the previous example, except we will also log a message
  6986. * // when the data has finished synchronizing.
  6987. * ```
  6988. *
  6989. * @param value The value to be written (string, number, boolean, object,
  6990. * array, or null).
  6991. * @param onComplete Callback called when write to server is
  6992. * complete.
  6993. * @return Resolves when write to server is complete.
  6994. */
  6995. set(value: any, onComplete?: (a: Error | null) => void): Promise<void>;
  6996. /**
  6997. * Sets a priority for the data at this Database location.
  6998. *
  6999. * Applications need not use priority but can order collections by
  7000. * ordinary properties (see
  7001. * {@link
  7002. * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
  7003. * Sorting and filtering data}).
  7004. */
  7005. setPriority(
  7006. priority: string | number | null,
  7007. onComplete: (a: Error | null) => void
  7008. ): Promise<void>;
  7009. /**
  7010. * Writes data the Database location. Like `set()` but also specifies the
  7011. * priority for that data.
  7012. *
  7013. * Applications need not use priority but can order collections by
  7014. * ordinary properties (see
  7015. * {@link
  7016. * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
  7017. * Sorting and filtering data}).
  7018. */
  7019. setWithPriority(
  7020. newVal: any,
  7021. newPriority: string | number | null,
  7022. onComplete?: (a: Error | null) => void
  7023. ): Promise<void>;
  7024. /**
  7025. * Atomically modifies the data at this location.
  7026. *
  7027. * Atomically modify the data at this location. Unlike a normal `set()`, which
  7028. * just overwrites the data regardless of its previous value, `transaction()` is
  7029. * used to modify the existing value to a new value, ensuring there are no
  7030. * conflicts with other clients writing to the same location at the same time.
  7031. *
  7032. * To accomplish this, you pass `transaction()` an update function which is used
  7033. * to transform the current value into a new value. If another client writes to
  7034. * the location before your new value is successfully written, your update
  7035. * function will be called again with the new current value, and the write will
  7036. * be retried. This will happen repeatedly until your write succeeds without
  7037. * conflict or you abort the transaction by not returning a value from your
  7038. * update function.
  7039. *
  7040. * Note: Modifying data with `set()` will cancel any pending transactions at
  7041. * that location, so extreme care should be taken if mixing `set()` and
  7042. * `transaction()` to update the same data.
  7043. *
  7044. * Note: When using transactions with Security and Firebase Rules in place, be
  7045. * aware that a client needs `.read` access in addition to `.write` access in
  7046. * order to perform a transaction. This is because the client-side nature of
  7047. * transactions requires the client to read the data in order to transactionally
  7048. * update it.
  7049. *
  7050. * @example
  7051. * ```javascript
  7052. * // Increment Ada's rank by 1.
  7053. * var adaRankRef = firebase.database().ref('users/ada/rank');
  7054. * adaRankRef.transaction(function(currentRank) {
  7055. * // If users/ada/rank has never been set, currentRank will be `null`.
  7056. * return currentRank + 1;
  7057. * });
  7058. * ```
  7059. *
  7060. * @example
  7061. * ```javascript
  7062. * // Try to create a user for ada, but only if the user id 'ada' isn't
  7063. * // already taken
  7064. * var adaRef = firebase.database().ref('users/ada');
  7065. * adaRef.transaction(function(currentData) {
  7066. * if (currentData === null) {
  7067. * return { name: { first: 'Ada', last: 'Lovelace' } };
  7068. * } else {
  7069. * console.log('User ada already exists.');
  7070. * return; // Abort the transaction.
  7071. * }
  7072. * }, function(error, committed, snapshot) {
  7073. * if (error) {
  7074. * console.log('Transaction failed abnormally!', error);
  7075. * } else if (!committed) {
  7076. * console.log('We aborted the transaction (because ada already exists).');
  7077. * } else {
  7078. * console.log('User ada added!');
  7079. * }
  7080. * console.log("Ada's data: ", snapshot.val());
  7081. * });
  7082. * ```
  7083. *
  7084. * @param transactionUpdate A developer-supplied function which
  7085. * will be passed the current data stored at this location (as a JavaScript
  7086. * object). The function should return the new value it would like written (as
  7087. * a JavaScript object). If `undefined` is returned (i.e. you return with no
  7088. * arguments) the transaction will be aborted and the data at this location
  7089. * will not be modified.
  7090. * @param onComplete A callback
  7091. * function that will be called when the transaction completes. The callback
  7092. * is passed three arguments: a possibly-null `Error`, a `boolean` indicating
  7093. * whether the transaction was committed, and a `DataSnapshot` indicating the
  7094. * final result. If the transaction failed abnormally, the first argument will
  7095. * be an `Error` object indicating the failure cause. If the transaction
  7096. * finished normally, but no data was committed because no data was returned
  7097. * from `transactionUpdate`, then second argument will be false. If the
  7098. * transaction completed and committed data to Firebase, the second argument
  7099. * will be true. Regardless, the third argument will be a `DataSnapshot`
  7100. * containing the resulting data in this location.
  7101. * @param applyLocally By default, events are raised each time the
  7102. * transaction update function runs. So if it is run multiple times, you may
  7103. * see intermediate states. You can set this to false to suppress these
  7104. * intermediate states and instead wait until the transaction has completed
  7105. * before events are raised.
  7106. * @return Returns a Promise that can optionally be used instead of the onComplete
  7107. * callback to handle success and failure.
  7108. */
  7109. transaction(
  7110. transactionUpdate: (a: any) => any,
  7111. onComplete?: (
  7112. a: Error | null,
  7113. b: boolean,
  7114. c: firebase.database.DataSnapshot | null
  7115. ) => void,
  7116. applyLocally?: boolean
  7117. ): Promise<TransactionResult>;
  7118. /**
  7119. * Writes multiple values to the Database at once.
  7120. *
  7121. * The `values` argument contains multiple property-value pairs that will be
  7122. * written to the Database together. Each child property can either be a simple
  7123. * property (for example, "name") or a relative path (for example,
  7124. * "name/first") from the current location to the data to update.
  7125. *
  7126. * As opposed to the `set()` method, `update()` can be use to selectively update
  7127. * only the referenced properties at the current location (instead of replacing
  7128. * all the child properties at the current location).
  7129. *
  7130. * The effect of the write will be visible immediately, and the corresponding
  7131. * events ('value', 'child_added', etc.) will be triggered. Synchronization of
  7132. * the data to the Firebase servers will also be started, and the returned
  7133. * Promise will resolve when complete. If provided, the `onComplete` callback
  7134. * will be called asynchronously after synchronization has finished.
  7135. *
  7136. * A single `update()` will generate a single "value" event at the location
  7137. * where the `update()` was performed, regardless of how many children were
  7138. * modified.
  7139. *
  7140. * Note that modifying data with `update()` will cancel any pending
  7141. * transactions at that location, so extreme care should be taken if mixing
  7142. * `update()` and `transaction()` to modify the same data.
  7143. *
  7144. * Passing `null` to `update()` will remove the data at this location.
  7145. *
  7146. * See
  7147. * {@link
  7148. * https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html
  7149. * Introducing multi-location updates and more}.
  7150. *
  7151. * @example
  7152. * ```javascript
  7153. * var adaNameRef = firebase.database().ref('users/ada/name');
  7154. * // Modify the 'first' and 'last' properties, but leave other data at
  7155. * // adaNameRef unchanged.
  7156. * adaNameRef.update({ first: 'Ada', last: 'Lovelace' });
  7157. * ```
  7158. *
  7159. * @param values Object containing multiple values.
  7160. * @param onComplete Callback called when write to server is
  7161. * complete.
  7162. * @return Resolves when update on server is complete.
  7163. */
  7164. update(
  7165. values: Object,
  7166. onComplete?: (a: Error | null) => void
  7167. ): Promise<void>;
  7168. }
  7169. interface TransactionResult {
  7170. /**
  7171. * Whether the transaction was successfully committed.
  7172. */
  7173. committed: boolean;
  7174. /**
  7175. * The resulting data snapshot.
  7176. */
  7177. snapshot: DataSnapshot;
  7178. }
  7179. interface ThenableReference
  7180. extends firebase.database.Reference,
  7181. Pick<Promise<Reference>, 'then' | 'catch'> {}
  7182. /**
  7183. * Logs debugging information to the console.
  7184. *
  7185. * @example
  7186. * ```javascript
  7187. * // Enable logging
  7188. * firebase.database.enableLogging(true);
  7189. * ```
  7190. *
  7191. * @example
  7192. * ```javascript
  7193. * // Disable logging
  7194. * firebase.database.enableLogging(false);
  7195. * ```
  7196. *
  7197. * @example
  7198. * ```javascript
  7199. * // Enable logging across page refreshes
  7200. * firebase.database.enableLogging(true, true);
  7201. * ```
  7202. *
  7203. * @example
  7204. * ```javascript
  7205. * // Provide custom logger which prefixes log statements with "[FIREBASE]"
  7206. * firebase.database.enableLogging(function(message) {
  7207. * console.log("[FIREBASE]", message);
  7208. * });
  7209. * ```
  7210. *
  7211. * @param logger Enables logging if `true`;
  7212. * disables logging if `false`. You can also provide a custom logger function
  7213. * to control how things get logged.
  7214. * @param persistent Remembers the logging state between page
  7215. * refreshes if `true`.
  7216. */
  7217. function enableLogging(
  7218. logger?: boolean | ((a: string) => any),
  7219. persistent?: boolean
  7220. ): any;
  7221. export type EmulatorMockTokenOptions = firebase.EmulatorMockTokenOptions;
  7222. }
  7223. declare namespace firebase.database.ServerValue {
  7224. /**
  7225. * A placeholder value for auto-populating the current timestamp (time
  7226. * since the Unix epoch, in milliseconds) as determined by the Firebase
  7227. * servers.
  7228. *
  7229. * @example
  7230. * ```javascript
  7231. * var sessionsRef = firebase.database().ref("sessions");
  7232. * sessionsRef.push({
  7233. * startedAt: firebase.database.ServerValue.TIMESTAMP
  7234. * });
  7235. * ```
  7236. */
  7237. var TIMESTAMP: Object;
  7238. /**
  7239. * Returns a placeholder value that can be used to atomically increment the
  7240. * current database value by the provided delta.
  7241. *
  7242. * @param delta the amount to modify the current value atomically.
  7243. * @return a placeholder value for modifying data atomically server-side.
  7244. */
  7245. function increment(delta: number): Object;
  7246. }
  7247. /**
  7248. * The Messaging SDK does not work in a Node.js environment.
  7249. */
  7250. declare namespace firebase.messaging {
  7251. /**
  7252. * The Firebase Messaging service interface.
  7253. *
  7254. * Do not call this constructor directly. Instead, use
  7255. * {@link firebase.messaging `firebase.messaging()`}.
  7256. *
  7257. * See {@link https://firebase.google.com/docs/cloud-messaging/js/client
  7258. * Set Up a JavaScript Firebase Cloud Messaging Client App} for a full guide on how to use the
  7259. * Firebase Messaging service.
  7260. *
  7261. */
  7262. interface Messaging {
  7263. /**
  7264. * Deletes the registration token associated with this messaging instance and unsubscribes the
  7265. * messaging instance from the push subscription.
  7266. *
  7267. * @return The promise resolves when the token has been successfully deleted.
  7268. */
  7269. deleteToken(): Promise<boolean>;
  7270. /**
  7271. * Subscribes the messaging instance to push notifications. Returns an FCM registration token
  7272. * that can be used to send push messages to that messaging instance.
  7273. *
  7274. * If a notification permission isn't already granted, this method asks the user for permission.
  7275. * The returned promise rejects if the user does not allow the app to show notifications.
  7276. *
  7277. * @param options.vapidKey The public server key provided to push services. It is used to
  7278. * authenticate the push subscribers to receive push messages only from sending servers that
  7279. * hold the corresponding private key. If it is not provided, a default VAPID key is used. Note
  7280. * that some push services (Chrome Push Service) require a non-default VAPID key. Therefore, it
  7281. * is recommended to generate and import a VAPID key for your project with
  7282. * {@link https://firebase.google.com/docs/cloud-messaging/js/client#configure_web_credentials_with_fcm Configure Web Credentials with FCM}.
  7283. * See
  7284. * {@link https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol The Web Push Protocol}
  7285. * for details on web push services.}
  7286. *
  7287. * @param options.serviceWorkerRegistration The service worker registration for receiving push
  7288. * messaging. If the registration is not provided explicitly, you need to have a
  7289. * `firebase-messaging-sw.js` at your root location. See
  7290. * {@link https://firebase.google.com/docs/cloud-messaging/js/client#retrieve-the-current-registration-token Retrieve the current registration token}
  7291. * for more details.
  7292. *
  7293. * @return The promise resolves with an FCM registration token.
  7294. *
  7295. */
  7296. getToken(options?: {
  7297. vapidKey?: string;
  7298. serviceWorkerRegistration?: ServiceWorkerRegistration;
  7299. }): Promise<string>;
  7300. /**
  7301. * When a push message is received and the user is currently on a page for your origin, the
  7302. * message is passed to the page and an `onMessage()` event is dispatched with the payload of
  7303. * the push message.
  7304. *
  7305. * @param
  7306. * nextOrObserver This function, or observer object with `next` defined,
  7307. * is called when a message is received and the user is currently viewing your page.
  7308. * @return To stop listening for messages execute this returned function.
  7309. */
  7310. onMessage(
  7311. nextOrObserver: firebase.NextFn<any> | firebase.Observer<any>
  7312. ): firebase.Unsubscribe;
  7313. /**
  7314. * Called when a message is received while the app is in the background. An app is considered to
  7315. * be in the background if no active window is displayed.
  7316. *
  7317. * @param
  7318. * nextOrObserver This function, or observer object with `next` defined,
  7319. * is called when a message is received and the app is currently in the background.
  7320. *
  7321. * @return To stop listening for messages execute this returned function
  7322. */
  7323. onBackgroundMessage(
  7324. nextOrObserver:
  7325. | firebase.NextFn<MessagePayload>
  7326. | firebase.Observer<MessagePayload>
  7327. ): firebase.Unsubscribe;
  7328. }
  7329. /**
  7330. * Message payload that contains the notification payload that is represented with
  7331. * {@link firebase.messaging.NotificationPayload} and the data payload that contains an arbitrary
  7332. * number of key-value pairs sent by developers through the
  7333. * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification Send API}
  7334. */
  7335. export interface MessagePayload {
  7336. /**
  7337. * See {@link firebase.messaging.NotificationPayload}.
  7338. */
  7339. notification?: NotificationPayload;
  7340. /**
  7341. * Arbitrary key/value pairs.
  7342. */
  7343. data?: { [key: string]: string };
  7344. /**
  7345. * See {@link firebase.messaging.FcmOptions}.
  7346. */
  7347. fcmOptions?: FcmOptions;
  7348. /**
  7349. * The sender of this message.
  7350. */
  7351. from: string;
  7352. /**
  7353. * The collapse key of this message. See
  7354. * {@link https://firebase.google.com/docs/cloud-messaging/concept-options#collapsible_and_non-collapsible_messages
  7355. * Collapsible and non-collapsible messages}.
  7356. */
  7357. collapseKey: string;
  7358. }
  7359. /**
  7360. * Options for features provided by the FCM SDK for Web. See
  7361. * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushfcmoptions
  7362. * WebpushFcmOptions}.
  7363. */
  7364. export interface FcmOptions {
  7365. /**
  7366. * The link to open when the user clicks on the notification. For all URL values, HTTPS is
  7367. * required. For example, by setting this value to your app's URL, a notification click event
  7368. * will put your app in focus for the user.
  7369. */
  7370. link?: string;
  7371. /**
  7372. * Label associated with the message's analytics data. See
  7373. * {@link https://firebase.google.com/docs/cloud-messaging/understand-delivery#adding-analytics-labels-to-messages
  7374. * Adding analytics labels}.
  7375. */
  7376. analyticsLabel?: string;
  7377. }
  7378. /**
  7379. * Parameters that define how a push notification is displayed to users.
  7380. */
  7381. export interface NotificationPayload {
  7382. /**
  7383. * The title of a notification.
  7384. */
  7385. title?: string;
  7386. /**
  7387. * The body of a notification.
  7388. */
  7389. body?: string;
  7390. /**
  7391. * The URL of the image that is shown with the notification. See
  7392. * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification
  7393. * `notification.image`} for supported image format.
  7394. */
  7395. image?: string;
  7396. }
  7397. function isSupported(): boolean;
  7398. }
  7399. declare namespace firebase.storage {
  7400. /**
  7401. * The full set of object metadata, including read-only properties.
  7402. */
  7403. interface FullMetadata extends firebase.storage.UploadMetadata {
  7404. /**
  7405. * The bucket this object is contained in.
  7406. */
  7407. bucket: string;
  7408. /**
  7409. * The full path of this object.
  7410. */
  7411. fullPath: string;
  7412. /**
  7413. * The object's generation.
  7414. * @see {@link https://cloud.google.com/storage/docs/generations-preconditions}
  7415. */
  7416. generation: string;
  7417. /**
  7418. * The object's metageneration.
  7419. * @see {@link https://cloud.google.com/storage/docs/generations-preconditions}
  7420. */
  7421. metageneration: string;
  7422. /**
  7423. * The short name of this object, which is the last component of the full path.
  7424. * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
  7425. */
  7426. name: string;
  7427. /**
  7428. * The size of this object, in bytes.
  7429. */
  7430. size: number;
  7431. /**
  7432. * A date string representing when this object was created.
  7433. */
  7434. timeCreated: string;
  7435. /**
  7436. * A date string representing when this object was last updated.
  7437. */
  7438. updated: string;
  7439. }
  7440. /**
  7441. * Represents a reference to a Google Cloud Storage object. Developers can
  7442. * upload, download, and delete objects, as well as get/set object metadata.
  7443. */
  7444. interface Reference {
  7445. /**
  7446. * The name of the bucket containing this reference's object.
  7447. */
  7448. bucket: string;
  7449. /**
  7450. * Returns a reference to a relative path from this reference.
  7451. * @param path The relative path from this reference.
  7452. * Leading, trailing, and consecutive slashes are removed.
  7453. * @return The reference to the given path.
  7454. */
  7455. child(path: string): firebase.storage.Reference;
  7456. /**
  7457. * Deletes the object at this reference's location.
  7458. * @return A Promise that resolves if the deletion
  7459. * succeeded and rejects if it failed, including if the object didn't exist.
  7460. */
  7461. delete(): Promise<void>;
  7462. /**
  7463. * The full path of this object.
  7464. */
  7465. fullPath: string;
  7466. /**
  7467. * Fetches a long lived download URL for this object.
  7468. * @return A Promise that resolves with the download
  7469. * URL or rejects if the fetch failed, including if the object did not
  7470. * exist.
  7471. */
  7472. getDownloadURL(): Promise<string>;
  7473. /**
  7474. * Fetches metadata for the object at this location, if one exists.
  7475. * @return A Promise that
  7476. * resolves with the metadata, or rejects if the fetch failed, including if
  7477. * the object did not exist.
  7478. */
  7479. getMetadata(): Promise<FullMetadata>;
  7480. /**
  7481. * The short name of this object, which is the last component of the full path.
  7482. * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
  7483. */
  7484. name: string;
  7485. /**
  7486. * A reference pointing to the parent location of this reference, or null if
  7487. * this reference is the root.
  7488. */
  7489. parent: firebase.storage.Reference | null;
  7490. /**
  7491. * Uploads data to this reference's location.
  7492. * @param data The data to upload.
  7493. * @param metadata Metadata for the newly
  7494. * uploaded object.
  7495. * @return An object that can be used to monitor
  7496. * and manage the upload.
  7497. */
  7498. put(
  7499. data: Blob | Uint8Array | ArrayBuffer,
  7500. metadata?: firebase.storage.UploadMetadata
  7501. ): firebase.storage.UploadTask;
  7502. /**
  7503. * Uploads string data to this reference's location.
  7504. * @param data The string to upload.
  7505. * @param format The format of the string to
  7506. * upload.
  7507. * @param metadata Metadata for the newly
  7508. * uploaded object.
  7509. * @throws If the format is not an allowed format, or if the given string
  7510. * doesn't conform to the specified format.
  7511. */
  7512. putString(
  7513. data: string,
  7514. format?: firebase.storage.StringFormat,
  7515. metadata?: firebase.storage.UploadMetadata
  7516. ): firebase.storage.UploadTask;
  7517. /**
  7518. * A reference to the root of this reference's bucket.
  7519. */
  7520. root: firebase.storage.Reference;
  7521. /**
  7522. * The storage service associated with this reference.
  7523. */
  7524. storage: firebase.storage.Storage;
  7525. /**
  7526. * Returns a gs:// URL for this object in the form
  7527. * `gs://<bucket>/<path>/<to>/<object>`
  7528. * @return The gs:// URL.
  7529. */
  7530. toString(): string;
  7531. /**
  7532. * Updates the metadata for the object at this location, if one exists.
  7533. * @param metadata The new metadata.
  7534. * Setting a property to 'null' removes it on the server, while leaving
  7535. * a property as 'undefined' has no effect.
  7536. * @return A Promise that
  7537. * resolves with the full updated metadata or rejects if the updated failed,
  7538. * including if the object did not exist.
  7539. */
  7540. updateMetadata(
  7541. metadata: firebase.storage.SettableMetadata
  7542. ): Promise<FullMetadata>;
  7543. /**
  7544. * List all items (files) and prefixes (folders) under this storage reference.
  7545. *
  7546. * This is a helper method for calling `list()` repeatedly until there are
  7547. * no more results. The default pagination size is 1000.
  7548. *
  7549. * Note: The results may not be consistent if objects are changed while this
  7550. * operation is running.
  7551. *
  7552. * Warning: `listAll` may potentially consume too many resources if there are
  7553. * too many results.
  7554. *
  7555. * @return A Promise that resolves with all the items and prefixes under
  7556. * the current storage reference. `prefixes` contains references to
  7557. * sub-directories and `items` contains references to objects in this
  7558. * folder. `nextPageToken` is never returned.
  7559. */
  7560. listAll(): Promise<ListResult>;
  7561. /**
  7562. * List items (files) and prefixes (folders) under this storage reference.
  7563. *
  7564. * List API is only available for Firebase Rules Version 2.
  7565. *
  7566. * GCS is a key-blob store. Firebase Storage imposes the semantic of '/'
  7567. * delimited folder structure.
  7568. * Refer to GCS's List API if you want to learn more.
  7569. *
  7570. * To adhere to Firebase Rules's Semantics, Firebase Storage does not
  7571. * support objects whose paths end with "/" or contain two consecutive
  7572. * "/"s. Firebase Storage List API will filter these unsupported objects.
  7573. * `list()` may fail if there are too many unsupported objects in the bucket.
  7574. *
  7575. * @param options See `ListOptions` for details.
  7576. * @return A Promise that resolves with the items and prefixes.
  7577. * `prefixes` contains references to sub-folders and `items`
  7578. * contains references to objects in this folder. `nextPageToken`
  7579. * can be used to get the rest of the results.
  7580. */
  7581. list(options?: ListOptions): Promise<ListResult>;
  7582. }
  7583. /**
  7584. * Result returned by list().
  7585. */
  7586. interface ListResult {
  7587. /**
  7588. * References to prefixes (sub-folders). You can call list() on them to
  7589. * get its contents.
  7590. *
  7591. * Folders are implicit based on '/' in the object paths.
  7592. * For example, if a bucket has two objects '/a/b/1' and '/a/b/2', list('/a')
  7593. * will return '/a/b' as a prefix.
  7594. */
  7595. prefixes: Reference[];
  7596. /**
  7597. * Objects in this directory.
  7598. * You can call getMetadata() and getDownloadUrl() on them.
  7599. */
  7600. items: Reference[];
  7601. /**
  7602. * If set, there might be more results for this list. Use this token to resume the list.
  7603. */
  7604. nextPageToken: string | null;
  7605. }
  7606. /**
  7607. * The options `list()` accepts.
  7608. */
  7609. interface ListOptions {
  7610. /**
  7611. * If set, limits the total number of `prefixes` and `items` to return.
  7612. * The default and maximum maxResults is 1000.
  7613. */
  7614. maxResults?: number | null;
  7615. /**
  7616. * The `nextPageToken` from a previous call to `list()`. If provided,
  7617. * listing is resumed from the previous position.
  7618. */
  7619. pageToken?: string | null;
  7620. }
  7621. /**
  7622. * Object metadata that can be set at any time.
  7623. */
  7624. interface SettableMetadata {
  7625. /**
  7626. * Served as the 'Cache-Control' header on object download.
  7627. */
  7628. cacheControl?: string | null;
  7629. contentDisposition?: string | null;
  7630. /**
  7631. * Served as the 'Content-Encoding' header on object download.
  7632. */
  7633. contentEncoding?: string | null;
  7634. /**
  7635. * Served as the 'Content-Language' header on object download.
  7636. */
  7637. contentLanguage?: string | null;
  7638. /**
  7639. * Served as the 'Content-Type' header on object download.
  7640. */
  7641. contentType?: string | null;
  7642. /**
  7643. * Additional user-defined custom metadata.
  7644. */
  7645. customMetadata?: {
  7646. [/* warning: coerced from ? */ key: string]: string;
  7647. } | null;
  7648. }
  7649. /**
  7650. * The Firebase Storage service interface.
  7651. *
  7652. * Do not call this constructor directly. Instead, use
  7653. * {@link firebase.storage `firebase.storage()`}.
  7654. *
  7655. * See
  7656. * {@link
  7657. * https://firebase.google.com/docs/storage/web/start/
  7658. * Get Started on Web}
  7659. * for a full guide on how to use the Firebase Storage service.
  7660. */
  7661. interface Storage {
  7662. /**
  7663. * The {@link firebase.app.App app} associated with the `Storage` service
  7664. * instance.
  7665. *
  7666. * @example
  7667. * ```javascript
  7668. * var app = storage.app;
  7669. * ```
  7670. */
  7671. app: firebase.app.App;
  7672. /**
  7673. * The maximum time to retry operations other than uploads or downloads in
  7674. * milliseconds.
  7675. */
  7676. maxOperationRetryTime: number;
  7677. /**
  7678. * The maximum time to retry uploads in milliseconds.
  7679. */
  7680. maxUploadRetryTime: number;
  7681. /**
  7682. * Returns a reference for the given path in the default bucket.
  7683. * @param path A relative path to initialize the reference with,
  7684. * for example `path/to/image.jpg`. If not passed, the returned reference
  7685. * points to the bucket root.
  7686. * @return A reference for the given path.
  7687. */
  7688. ref(path?: string): firebase.storage.Reference;
  7689. /**
  7690. * Returns a reference for the given absolute URL.
  7691. * @param url A URL in the form: <br />
  7692. * 1) a gs:// URL, for example `gs://bucket/files/image.png` <br />
  7693. * 2) a download URL taken from object metadata. <br />
  7694. * @return A reference for the given URL.
  7695. */
  7696. refFromURL(url: string): firebase.storage.Reference;
  7697. /**
  7698. * @param time The new maximum operation retry time in milliseconds.
  7699. * @see {@link firebase.storage.Storage.maxOperationRetryTime}
  7700. */
  7701. setMaxOperationRetryTime(time: number): any;
  7702. /**
  7703. * @param time The new maximum upload retry time in milliseconds.
  7704. * @see {@link firebase.storage.Storage.maxUploadRetryTime}
  7705. */
  7706. setMaxUploadRetryTime(time: number): any;
  7707. /**
  7708. * Modify this `Storage` instance to communicate with the Cloud Storage emulator.
  7709. *
  7710. * @param host - The emulator host (ex: localhost)
  7711. * @param port - The emulator port (ex: 5001)
  7712. * @param options.mockUserToken the mock auth token to use for unit testing Security Rules
  7713. */
  7714. useEmulator(
  7715. host: string,
  7716. port: number,
  7717. options?: {
  7718. mockUserToken?: EmulatorMockTokenOptions | string;
  7719. }
  7720. ): void;
  7721. }
  7722. /**
  7723. * @enum {string}
  7724. * An enumeration of the possible string formats for upload.
  7725. */
  7726. type StringFormat = string;
  7727. var StringFormat: {
  7728. /**
  7729. * Indicates the string should be interpreted as base64-encoded data.
  7730. * Padding characters (trailing '='s) are optional.
  7731. * Example: The string 'rWmO++E6t7/rlw==' becomes the byte sequence
  7732. * ad 69 8e fb e1 3a b7 bf eb 97
  7733. */
  7734. BASE64: StringFormat;
  7735. /**
  7736. * Indicates the string should be interpreted as base64url-encoded data.
  7737. * Padding characters (trailing '='s) are optional.
  7738. * Example: The string 'rWmO--E6t7_rlw==' becomes the byte sequence
  7739. * ad 69 8e fb e1 3a b7 bf eb 97
  7740. */
  7741. BASE64URL: StringFormat;
  7742. /**
  7743. * Indicates the string is a data URL, such as one obtained from
  7744. * canvas.toDataURL().
  7745. * Example: the string 'data:application/octet-stream;base64,aaaa'
  7746. * becomes the byte sequence
  7747. * 69 a6 9a
  7748. * (the content-type "application/octet-stream" is also applied, but can
  7749. * be overridden in the metadata object).
  7750. */
  7751. DATA_URL: StringFormat;
  7752. /**
  7753. * Indicates the string should be interpreted "raw", that is, as normal text.
  7754. * The string will be interpreted as UTF-16, then uploaded as a UTF-8 byte
  7755. * sequence.
  7756. * Example: The string 'Hello! \ud83d\ude0a' becomes the byte sequence
  7757. * 48 65 6c 6c 6f 21 20 f0 9f 98 8a
  7758. */
  7759. RAW: StringFormat;
  7760. };
  7761. /**
  7762. * An event that is triggered on a task.
  7763. * @enum {string}
  7764. * @see {@link firebase.storage.UploadTask.on}
  7765. */
  7766. type TaskEvent = string;
  7767. var TaskEvent: {
  7768. /**
  7769. * For this event,
  7770. * <ul>
  7771. * <li>The `next` function is triggered on progress updates and when the
  7772. * task is paused/resumed with a
  7773. * {@link firebase.storage.UploadTaskSnapshot} as the first
  7774. * argument.</li>
  7775. * <li>The `error` function is triggered if the upload is canceled or fails
  7776. * for another reason.</li>
  7777. * <li>The `complete` function is triggered if the upload completes
  7778. * successfully.</li>
  7779. * </ul>
  7780. */
  7781. STATE_CHANGED: TaskEvent;
  7782. };
  7783. /**
  7784. * Represents the current state of a running upload.
  7785. * @enum {string}
  7786. */
  7787. type TaskState = string;
  7788. var TaskState: {
  7789. CANCELED: TaskState;
  7790. ERROR: TaskState;
  7791. PAUSED: TaskState;
  7792. RUNNING: TaskState;
  7793. SUCCESS: TaskState;
  7794. };
  7795. /**
  7796. * Object metadata that can be set at upload.
  7797. */
  7798. interface UploadMetadata extends firebase.storage.SettableMetadata {
  7799. /**
  7800. * A Base64-encoded MD5 hash of the object being uploaded.
  7801. */
  7802. md5Hash?: string | null;
  7803. }
  7804. /**
  7805. * Error codes that can be attached to `StorageError` objects.
  7806. */
  7807. export enum StorageErrorCode {
  7808. UNKNOWN = 'unknown',
  7809. OBJECT_NOT_FOUND = 'object-not-found',
  7810. BUCKET_NOT_FOUND = 'bucket-not-found',
  7811. PROJECT_NOT_FOUND = 'project-not-found',
  7812. QUOTA_EXCEEDED = 'quota-exceeded',
  7813. UNAUTHENTICATED = 'unauthenticated',
  7814. UNAUTHORIZED = 'unauthorized',
  7815. UNAUTHORIZED_APP = 'unauthorized-app',
  7816. RETRY_LIMIT_EXCEEDED = 'retry-limit-exceeded',
  7817. INVALID_CHECKSUM = 'invalid-checksum',
  7818. CANCELED = 'canceled',
  7819. INVALID_EVENT_NAME = 'invalid-event-name',
  7820. INVALID_URL = 'invalid-url',
  7821. INVALID_DEFAULT_BUCKET = 'invalid-default-bucket',
  7822. NO_DEFAULT_BUCKET = 'no-default-bucket',
  7823. CANNOT_SLICE_BLOB = 'cannot-slice-blob',
  7824. SERVER_FILE_WRONG_SIZE = 'server-file-wrong-size',
  7825. NO_DOWNLOAD_URL = 'no-download-url',
  7826. INVALID_ARGUMENT = 'invalid-argument',
  7827. INVALID_ARGUMENT_COUNT = 'invalid-argument-count',
  7828. APP_DELETED = 'app-deleted',
  7829. INVALID_ROOT_OPERATION = 'invalid-root-operation',
  7830. INVALID_FORMAT = 'invalid-format',
  7831. INTERNAL_ERROR = 'internal-error',
  7832. UNSUPPORTED_ENVIRONMENT = 'unsupported-environment'
  7833. }
  7834. interface StorageObserver<T> {
  7835. next?: NextFn<T> | null;
  7836. error?: (error: FirebaseStorageError) => void | null;
  7837. complete?: CompleteFn | null;
  7838. }
  7839. /**
  7840. * Represents the process of uploading an object. Allows you to monitor and
  7841. * manage the upload.
  7842. */
  7843. interface UploadTask {
  7844. /**
  7845. * Cancels a running task. Has no effect on a complete or failed task.
  7846. * @return True if the cancel had an effect.
  7847. */
  7848. cancel(): boolean;
  7849. /**
  7850. * Equivalent to calling `then(null, onRejected)`.
  7851. */
  7852. catch(onRejected: (error: FirebaseStorageError) => any): Promise<any>;
  7853. /**
  7854. * Listens for events on this task.
  7855. *
  7856. * Events have three callback functions (referred to as `next`, `error`, and
  7857. * `complete`).
  7858. *
  7859. * If only the event is passed, a function that can be used to register the
  7860. * callbacks is returned. Otherwise, the callbacks are passed after the event.
  7861. *
  7862. * Callbacks can be passed either as three separate arguments <em>or</em> as the
  7863. * `next`, `error`, and `complete` properties of an object. Any of the three
  7864. * callbacks is optional, as long as at least one is specified. In addition,
  7865. * when you add your callbacks, you get a function back. You can call this
  7866. * function to unregister the associated callbacks.
  7867. *
  7868. * @example **Pass callbacks separately or in an object.**
  7869. * ```javascript
  7870. * var next = function(snapshot) {};
  7871. * var error = function(error) {};
  7872. * var complete = function() {};
  7873. *
  7874. * // The first example.
  7875. * uploadTask.on(
  7876. * firebase.storage.TaskEvent.STATE_CHANGED,
  7877. * next,
  7878. * error,
  7879. * complete);
  7880. *
  7881. * // This is equivalent to the first example.
  7882. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
  7883. * 'next': next,
  7884. * 'error': error,
  7885. * 'complete': complete
  7886. * });
  7887. *
  7888. * // This is equivalent to the first example.
  7889. * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  7890. * subscribe(next, error, complete);
  7891. *
  7892. * // This is equivalent to the first example.
  7893. * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  7894. * subscribe({
  7895. * 'next': next,
  7896. * 'error': error,
  7897. * 'complete': complete
  7898. * });
  7899. * ```
  7900. *
  7901. * @example **Any callback is optional.**
  7902. * ```javascript
  7903. * // Just listening for completion, this is legal.
  7904. * uploadTask.on(
  7905. * firebase.storage.TaskEvent.STATE_CHANGED,
  7906. * null,
  7907. * null,
  7908. * function() {
  7909. * console.log('upload complete!');
  7910. * });
  7911. *
  7912. * // Just listening for progress/state changes, this is legal.
  7913. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) {
  7914. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  7915. * console.log(percent + "% done");
  7916. * });
  7917. *
  7918. * // This is also legal.
  7919. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
  7920. * 'complete': function() {
  7921. * console.log('upload complete!');
  7922. * }
  7923. * });
  7924. * ```
  7925. *
  7926. * @example **Use the returned function to remove callbacks.**
  7927. * ```javascript
  7928. * var unsubscribe = uploadTask.on(
  7929. * firebase.storage.TaskEvent.STATE_CHANGED,
  7930. * function(snapshot) {
  7931. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  7932. * console.log(percent + "% done");
  7933. * // Stop after receiving one update.
  7934. * unsubscribe();
  7935. * });
  7936. *
  7937. * // This code is equivalent to the above.
  7938. * var handle = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  7939. * unsubscribe = handle(function(snapshot) {
  7940. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  7941. * console.log(percent + "% done");
  7942. * // Stop after receiving one update.
  7943. * unsubscribe();
  7944. * });
  7945. * ```
  7946. *
  7947. * @param event The event to listen for.
  7948. * @param nextOrObserver
  7949. * The `next` function, which gets called for each item in
  7950. * the event stream, or an observer object with some or all of these three
  7951. * properties (`next`, `error`, `complete`).
  7952. * @param error A function that gets called with a `FirebaseStorageError`
  7953. * if the event stream ends due to an error.
  7954. * @param complete A function that gets called if the
  7955. * event stream ends normally.
  7956. * @return
  7957. * If only the event argument is passed, returns a function you can use to
  7958. * add callbacks (see the examples above). If more than just the event
  7959. * argument is passed, returns a function you can call to unregister the
  7960. * callbacks.
  7961. */
  7962. on(
  7963. event: firebase.storage.TaskEvent,
  7964. nextOrObserver?:
  7965. | StorageObserver<UploadTaskSnapshot>
  7966. | null
  7967. | ((snapshot: UploadTaskSnapshot) => any),
  7968. error?: ((error: FirebaseStorageError) => any) | null,
  7969. complete?: firebase.Unsubscribe | null
  7970. ): Function;
  7971. /**
  7972. * Pauses a running task. Has no effect on a paused or failed task.
  7973. * @return True if the pause had an effect.
  7974. */
  7975. pause(): boolean;
  7976. /**
  7977. * Resumes a paused task. Has no effect on a running or failed task.
  7978. * @return True if the resume had an effect.
  7979. */
  7980. resume(): boolean;
  7981. /**
  7982. * A snapshot of the current task state.
  7983. */
  7984. snapshot: firebase.storage.UploadTaskSnapshot;
  7985. /**
  7986. * This object behaves like a Promise, and resolves with its snapshot data when
  7987. * the upload completes.
  7988. * @param onFulfilled
  7989. * The fulfillment callback. Promise chaining works as normal.
  7990. * @param onRejected The rejection callback.
  7991. */
  7992. then(
  7993. onFulfilled?:
  7994. | ((snapshot: firebase.storage.UploadTaskSnapshot) => any)
  7995. | null,
  7996. onRejected?: ((error: FirebaseStorageError) => any) | null
  7997. ): Promise<any>;
  7998. }
  7999. /**
  8000. * Holds data about the current state of the upload task.
  8001. */
  8002. interface UploadTaskSnapshot {
  8003. /**
  8004. * The number of bytes that have been successfully uploaded so far.
  8005. */
  8006. bytesTransferred: number;
  8007. /**
  8008. * Before the upload completes, contains the metadata sent to the server.
  8009. * After the upload completes, contains the metadata sent back from the server.
  8010. */
  8011. metadata: firebase.storage.FullMetadata;
  8012. /**
  8013. * The reference that spawned this snapshot's upload task.
  8014. */
  8015. ref: firebase.storage.Reference;
  8016. /**
  8017. * The current state of the task.
  8018. */
  8019. state: firebase.storage.TaskState;
  8020. /**
  8021. * The task of which this is a snapshot.
  8022. */
  8023. task: firebase.storage.UploadTask;
  8024. /**
  8025. * The total number of bytes to be uploaded.
  8026. */
  8027. totalBytes: number;
  8028. }
  8029. /**
  8030. * An error returned by the Firebase Storage SDK.
  8031. */
  8032. export interface FirebaseStorageError extends FirebaseError {
  8033. /**
  8034. * Stores custom error data unique to the `StorageError`.
  8035. */
  8036. customData: {
  8037. serverResponse: string | null;
  8038. };
  8039. get status(): number;
  8040. set status(status: number);
  8041. /**
  8042. * Compares a `StorageErrorCode` against this error's code, filtering out the prefix.
  8043. */
  8044. _codeEquals(code: StorageErrorCode): boolean;
  8045. /**
  8046. * Optional response message that was added by the server.
  8047. */
  8048. get serverResponse(): null | string;
  8049. set serverResponse(serverResponse: string | null);
  8050. }
  8051. }
  8052. declare namespace firebase.firestore {
  8053. /**
  8054. * Document data (for use with `DocumentReference.set()`) consists of fields
  8055. * mapped to values.
  8056. */
  8057. export type DocumentData = { [field: string]: any };
  8058. /**
  8059. * Update data (for use with `DocumentReference.update()`) consists of field
  8060. * paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
  8061. * reference nested fields within the document.
  8062. */
  8063. export type UpdateData = { [fieldPath: string]: any };
  8064. /**
  8065. * Constant used to indicate the LRU garbage collection should be disabled.
  8066. * Set this value as the `cacheSizeBytes` on the settings passed to the
  8067. * `Firestore` instance.
  8068. */
  8069. export const CACHE_SIZE_UNLIMITED: number;
  8070. /**
  8071. * Specifies custom configurations for your Cloud Firestore instance.
  8072. * You must set these before invoking any other methods.
  8073. */
  8074. export interface Settings {
  8075. /** The hostname to connect to. */
  8076. host?: string;
  8077. /** Whether to use SSL when connecting. */
  8078. ssl?: boolean;
  8079. /**
  8080. * An approximate cache size threshold for the on-disk data. If the cache grows beyond this
  8081. * size, Firestore will start removing data that hasn't been recently used. The size is not a
  8082. * guarantee that the cache will stay below that size, only that if the cache exceeds the given
  8083. * size, cleanup will be attempted.
  8084. *
  8085. * The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to
  8086. * CACHE_SIZE_UNLIMITED to disable garbage collection.
  8087. */
  8088. cacheSizeBytes?: number;
  8089. /**
  8090. * Forces the SDK’s underlying network transport (WebChannel) to use
  8091. * long-polling. Each response from the backend will be closed immediately
  8092. * after the backend sends data (by default responses are kept open in
  8093. * case the backend has more data to send). This avoids incompatibility
  8094. * issues with certain proxies, antivirus software, etc. that incorrectly
  8095. * buffer traffic indefinitely. Use of this option will cause some
  8096. * performance degradation though.
  8097. *
  8098. * This setting cannot be used with `experimentalAutoDetectLongPolling` and
  8099. * may be removed in a future release. If you find yourself using it to
  8100. * work around a specific network reliability issue, please tell us about
  8101. * it in https://github.com/firebase/firebase-js-sdk/issues/1674.
  8102. *
  8103. * This setting does not work in a Node.js environment.
  8104. */
  8105. experimentalForceLongPolling?: boolean;
  8106. /**
  8107. * Configures the SDK's underlying transport (WebChannel) to automatically detect if
  8108. * long-polling should be used. This is very similar to `experimentalForceLongPolling`,
  8109. * but only uses long-polling if required.
  8110. *
  8111. * This setting will likely be enabled by default in future releases and cannot be
  8112. * combined with `experimentalForceLongPolling`.
  8113. *
  8114. * This setting does not work in a Node.js environment.
  8115. */
  8116. experimentalAutoDetectLongPolling?: boolean;
  8117. /**
  8118. * Whether to skip nested properties that are set to `undefined` during
  8119. * object serialization. If set to `true`, these properties are skipped
  8120. * and not written to Firestore. If set to `false` or omitted, the SDK
  8121. * throws an exception when it encounters properties of type `undefined`.
  8122. */
  8123. ignoreUndefinedProperties?: boolean;
  8124. /**
  8125. * Whether to merge the provided settings with the existing settings. If
  8126. * set to `true`, the settings are merged with existing settings. If
  8127. * set to `false` or left unset, the settings replace the existing
  8128. * settings.
  8129. */
  8130. merge?: boolean;
  8131. }
  8132. /**
  8133. * Settings that can be passed to Firestore.enablePersistence() to configure
  8134. * Firestore persistence.
  8135. */
  8136. export interface PersistenceSettings {
  8137. /**
  8138. * Whether to synchronize the in-memory state of multiple tabs. Setting this
  8139. * to `true` in all open tabs enables shared access to local persistence,
  8140. * shared execution of queries and latency-compensated local document updates
  8141. * across all connected instances.
  8142. *
  8143. * To enable this mode, `synchronizeTabs:true` needs to be set globally in all
  8144. * active tabs. If omitted or set to 'false', `enablePersistence()` will fail
  8145. * in all but the first tab.
  8146. */
  8147. synchronizeTabs?: boolean;
  8148. /**
  8149. * Whether to force enable persistence for the client. This cannot be used
  8150. * with `synchronizeTabs:true` and is primarily intended for use with Web
  8151. * Workers. Setting this to `true` will enable persistence, but cause other
  8152. * tabs using persistence to fail.
  8153. *
  8154. * This setting may be removed in a future release. If you find yourself
  8155. * using it for a specific use case or run into any issues, please tell us
  8156. * about it in
  8157. * https://github.com/firebase/firebase-js-sdk/issues/983.
  8158. */
  8159. experimentalForceOwningTab?: boolean;
  8160. }
  8161. export type LogLevel = 'debug' | 'error' | 'silent';
  8162. /**
  8163. * Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
  8164. *
  8165. * @param logLevel
  8166. * The verbosity you set for activity and error logging. Can be any of
  8167. * the following values:
  8168. *
  8169. * <ul>
  8170. * <li><code>debug</code> for the most verbose logging level, primarily for
  8171. * debugging.</li>
  8172. * <li><code>error</code> to log errors only.</li>
  8173. * <li><code>silent</code> to turn off logging.</li>
  8174. * </ul>
  8175. */
  8176. export function setLogLevel(logLevel: LogLevel): void;
  8177. /**
  8178. * Converter used by `withConverter()` to transform user objects of type T
  8179. * into Firestore data.
  8180. *
  8181. * Using the converter allows you to specify generic type arguments when
  8182. * storing and retrieving objects from Firestore.
  8183. *
  8184. * @example
  8185. * ```typescript
  8186. * class Post {
  8187. * constructor(readonly title: string, readonly author: string) {}
  8188. *
  8189. * toString(): string {
  8190. * return this.title + ', by ' + this.author;
  8191. * }
  8192. * }
  8193. *
  8194. * const postConverter = {
  8195. * toFirestore(post: Post): firebase.firestore.DocumentData {
  8196. * return {title: post.title, author: post.author};
  8197. * },
  8198. * fromFirestore(
  8199. * snapshot: firebase.firestore.QueryDocumentSnapshot,
  8200. * options: firebase.firestore.SnapshotOptions
  8201. * ): Post {
  8202. * const data = snapshot.data(options)!;
  8203. * return new Post(data.title, data.author);
  8204. * }
  8205. * };
  8206. *
  8207. * const postSnap = await firebase.firestore()
  8208. * .collection('posts')
  8209. * .withConverter(postConverter)
  8210. * .doc().get();
  8211. * const post = postSnap.data();
  8212. * if (post !== undefined) {
  8213. * post.title; // string
  8214. * post.toString(); // Should be defined
  8215. * post.someNonExistentProperty; // TS error
  8216. * }
  8217. * ```
  8218. */
  8219. export interface FirestoreDataConverter<T> {
  8220. /**
  8221. * Called by the Firestore SDK to convert a custom model object of type T
  8222. * into a plain Javascript object (suitable for writing directly to the
  8223. * Firestore database). To use `set()` with `merge` and `mergeFields`,
  8224. * `toFirestore()` must be defined with `Partial<T>`.
  8225. */
  8226. toFirestore(modelObject: T): DocumentData;
  8227. toFirestore(modelObject: Partial<T>, options: SetOptions): DocumentData;
  8228. /**
  8229. * Called by the Firestore SDK to convert Firestore data into an object of
  8230. * type T. You can access your data by calling: `snapshot.data(options)`.
  8231. *
  8232. * @param snapshot A QueryDocumentSnapshot containing your data and metadata.
  8233. * @param options The SnapshotOptions from the initial call to `data()`.
  8234. */
  8235. fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): T;
  8236. }
  8237. /**
  8238. * The Cloud Firestore service interface.
  8239. *
  8240. * Do not call this constructor directly. Instead, use
  8241. * {@link firebase.firestore `firebase.firestore()`}.
  8242. */
  8243. export class Firestore {
  8244. private constructor();
  8245. /**
  8246. * Specifies custom settings to be used to configure the `Firestore`
  8247. * instance. Must be set before invoking any other methods.
  8248. *
  8249. * @param settings The settings to use.
  8250. */
  8251. settings(settings: Settings): void;
  8252. /**
  8253. * Modify this instance to communicate with the Cloud Firestore emulator.
  8254. *
  8255. * <p>Note: this must be called before this instance has been used to do any operations.
  8256. *
  8257. * @param host the emulator host (ex: localhost).
  8258. * @param port the emulator port (ex: 9000).
  8259. * @param options.mockUserToken - the mock auth token to use for unit
  8260. * testing Security Rules.
  8261. */
  8262. useEmulator(
  8263. host: string,
  8264. port: number,
  8265. options?: {
  8266. mockUserToken?: EmulatorMockTokenOptions | string;
  8267. }
  8268. ): void;
  8269. /**
  8270. * Attempts to enable persistent storage, if possible.
  8271. *
  8272. * Must be called before any other methods (other than settings() and
  8273. * clearPersistence()).
  8274. *
  8275. * If this fails, enablePersistence() will reject the promise it returns.
  8276. * Note that even after this failure, the firestore instance will remain
  8277. * usable, however offline persistence will be disabled.
  8278. *
  8279. * There are several reasons why this can fail, which can be identified by
  8280. * the `code` on the error.
  8281. *
  8282. * * failed-precondition: The app is already open in another browser tab.
  8283. * * unimplemented: The browser is incompatible with the offline
  8284. * persistence implementation.
  8285. *
  8286. * @param settings Optional settings object to configure persistence.
  8287. * @return A promise that represents successfully enabling persistent
  8288. * storage.
  8289. */
  8290. enablePersistence(settings?: PersistenceSettings): Promise<void>;
  8291. /**
  8292. * Gets a `CollectionReference` instance that refers to the collection at
  8293. * the specified path.
  8294. *
  8295. * @param collectionPath A slash-separated path to a collection.
  8296. * @return The `CollectionReference` instance.
  8297. */
  8298. collection(collectionPath: string): CollectionReference<DocumentData>;
  8299. /**
  8300. * Gets a `DocumentReference` instance that refers to the document at the
  8301. * specified path.
  8302. *
  8303. * @param documentPath A slash-separated path to a document.
  8304. * @return The `DocumentReference` instance.
  8305. */
  8306. doc(documentPath: string): DocumentReference<DocumentData>;
  8307. /**
  8308. * Creates and returns a new Query that includes all documents in the
  8309. * database that are contained in a collection or subcollection with the
  8310. * given collectionId.
  8311. *
  8312. * @param collectionId Identifies the collections to query over. Every
  8313. * collection or subcollection with this ID as the last segment of its path
  8314. * will be included. Cannot contain a slash.
  8315. * @return The created Query.
  8316. */
  8317. collectionGroup(collectionId: string): Query<DocumentData>;
  8318. /**
  8319. * Executes the given `updateFunction` and then attempts to commit the changes
  8320. * applied within the transaction. If any document read within the transaction
  8321. * has changed, Cloud Firestore retries the `updateFunction`. If it fails to
  8322. * commit after 5 attempts, the transaction fails.
  8323. *
  8324. * The maximum number of writes allowed in a single transaction is 500, but
  8325. * note that each usage of `FieldValue.serverTimestamp()`,
  8326. * `FieldValue.arrayUnion()`, `FieldValue.arrayRemove()`, or
  8327. * `FieldValue.increment()` inside a transaction counts as an additional write.
  8328. *
  8329. * @param updateFunction
  8330. * The function to execute within the transaction context.
  8331. *
  8332. * @return
  8333. * If the transaction completed successfully or was explicitly aborted
  8334. * (the `updateFunction` returned a failed promise),
  8335. * the promise returned by the updateFunction is returned here. Else, if the
  8336. * transaction failed, a rejected promise with the corresponding failure
  8337. * error will be returned.
  8338. */
  8339. runTransaction<T>(
  8340. updateFunction: (transaction: Transaction) => Promise<T>
  8341. ): Promise<T>;
  8342. /**
  8343. * Creates a write batch, used for performing multiple writes as a single
  8344. * atomic operation. The maximum number of writes allowed in a single WriteBatch
  8345. * is 500, but note that each usage of `FieldValue.serverTimestamp()`,
  8346. * `FieldValue.arrayUnion()`, `FieldValue.arrayRemove()`, or
  8347. * `FieldValue.increment()` inside a WriteBatch counts as an additional write.
  8348. *
  8349. * @return
  8350. * A `WriteBatch` that can be used to atomically execute multiple writes.
  8351. */
  8352. batch(): WriteBatch;
  8353. /**
  8354. * The {@link firebase.app.App app} associated with this `Firestore` service
  8355. * instance.
  8356. */
  8357. app: firebase.app.App;
  8358. /**
  8359. * Clears the persistent storage. This includes pending writes and cached
  8360. * documents.
  8361. *
  8362. * Must be called while the firestore instance is not started (after the app
  8363. * is shutdown or when the app is first initialized). On startup, this
  8364. * method must be called before other methods (other than settings()). If
  8365. * the firestore instance is still running, the promise will be rejected
  8366. * with the error code of `failed-precondition`.
  8367. *
  8368. * Note: clearPersistence() is primarily intended to help write reliable
  8369. * tests that use Cloud Firestore. It uses an efficient mechanism for
  8370. * dropping existing data but does not attempt to securely overwrite or
  8371. * otherwise make cached data unrecoverable. For applications that are
  8372. * sensitive to the disclosure of cached data in between user sessions, we
  8373. * strongly recommend not enabling persistence at all.
  8374. *
  8375. * @return A promise that is resolved when the persistent storage is
  8376. * cleared. Otherwise, the promise is rejected with an error.
  8377. */
  8378. clearPersistence(): Promise<void>;
  8379. /**
  8380. * Re-enables use of the network for this Firestore instance after a prior
  8381. * call to {@link firebase.firestore.Firestore.disableNetwork
  8382. * `disableNetwork()`}.
  8383. *
  8384. * @return A promise that is resolved once the network has been
  8385. * enabled.
  8386. */
  8387. enableNetwork(): Promise<void>;
  8388. /**
  8389. * Disables network usage for this instance. It can be re-enabled via
  8390. * {@link firebase.firestore.Firestore.enableNetwork `enableNetwork()`}. While
  8391. * the network is disabled, any snapshot listeners or get() calls will return
  8392. * results from cache, and any write operations will be queued until the network
  8393. * is restored.
  8394. *
  8395. * @return A promise that is resolved once the network has been
  8396. * disabled.
  8397. */
  8398. disableNetwork(): Promise<void>;
  8399. /**
  8400. * Waits until all currently pending writes for the active user have been acknowledged by the
  8401. * backend.
  8402. *
  8403. * The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
  8404. * Promise waits for all previously issued writes (including those written in a previous app
  8405. * session), but it does not wait for writes that were added after the method is called. If you
  8406. * want to wait for additional writes, call `waitForPendingWrites()` again.
  8407. *
  8408. * Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
  8409. *
  8410. * @return A Promise which resolves when all currently pending writes have been
  8411. * acknowledged by the backend.
  8412. */
  8413. waitForPendingWrites(): Promise<void>;
  8414. /**
  8415. * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
  8416. * event indicates that all listeners affected by a given change have fired,
  8417. * even if a single server-generated change affects multiple listeners.
  8418. *
  8419. * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
  8420. * with each other, but does not relate to whether those snapshots are in sync
  8421. * with the server. Use SnapshotMetadata in the individual listeners to
  8422. * determine if a snapshot is from the cache or the server.
  8423. *
  8424. * @param observer A single object containing `next` and `error` callbacks.
  8425. * @return An unsubscribe function that can be called to cancel the snapshot
  8426. * listener.
  8427. */
  8428. onSnapshotsInSync(observer: {
  8429. next?: (value: void) => void;
  8430. error?: (error: FirestoreError) => void;
  8431. complete?: () => void;
  8432. }): () => void;
  8433. /**
  8434. * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
  8435. * event indicates that all listeners affected by a given change have fired,
  8436. * even if a single server-generated change affects multiple listeners.
  8437. *
  8438. * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
  8439. * with each other, but does not relate to whether those snapshots are in sync
  8440. * with the server. Use SnapshotMetadata in the individual listeners to
  8441. * determine if a snapshot is from the cache or the server.
  8442. *
  8443. * @param onSync A callback to be called every time all snapshot listeners are
  8444. * in sync with each other.
  8445. * @return An unsubscribe function that can be called to cancel the snapshot
  8446. * listener.
  8447. */
  8448. onSnapshotsInSync(onSync: () => void): () => void;
  8449. /**
  8450. * Terminates this Firestore instance.
  8451. *
  8452. * After calling `terminate()` only the `clearPersistence()` method may be used. Any other method
  8453. * will throw a `FirestoreError`.
  8454. *
  8455. * To restart after termination, create a new instance of FirebaseFirestore with
  8456. * `firebase.firestore()`.
  8457. *
  8458. * Termination does not cancel any pending writes, and any promises that are awaiting a response
  8459. * from the server will not be resolved. If you have persistence enabled, the next time you
  8460. * start this instance, it will resume sending these writes to the server.
  8461. *
  8462. * Note: Under normal circumstances, calling `terminate()` is not required. This
  8463. * method is useful only when you want to force this instance to release all of its resources or
  8464. * in combination with `clearPersistence()` to ensure that all local state is destroyed
  8465. * between test runs.
  8466. *
  8467. * @return A promise that is resolved when the instance has been successfully terminated.
  8468. */
  8469. terminate(): Promise<void>;
  8470. /**
  8471. * Loads a Firestore bundle into the local cache.
  8472. *
  8473. * @param bundleData
  8474. * An object representing the bundle to be loaded. Valid objects are `ArrayBuffer`,
  8475. * `ReadableStream<Uint8Array>` or `string`.
  8476. *
  8477. * @return
  8478. * A `LoadBundleTask` object, which notifies callers with progress updates, and completion
  8479. * or error events. It can be used as a `Promise<LoadBundleTaskProgress>`.
  8480. */
  8481. loadBundle(
  8482. bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
  8483. ): LoadBundleTask;
  8484. /**
  8485. * Reads a Firestore `Query` from local cache, identified by the given name.
  8486. *
  8487. * The named queries are packaged into bundles on the server side (along
  8488. * with resulting documents), and loaded to local cache using `loadBundle`. Once in local
  8489. * cache, use this method to extract a `Query` by name.
  8490. */
  8491. namedQuery(name: string): Promise<Query<DocumentData> | null>;
  8492. /**
  8493. * @hidden
  8494. */
  8495. INTERNAL: { delete: () => Promise<void> };
  8496. }
  8497. /**
  8498. * Represents the task of loading a Firestore bundle. It provides progress of bundle
  8499. * loading, as well as task completion and error events.
  8500. *
  8501. * The API is compatible with `Promise<LoadBundleTaskProgress>`.
  8502. */
  8503. export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
  8504. /**
  8505. * Registers functions to listen to bundle loading progress events.
  8506. * @param next
  8507. * Called when there is a progress update from bundle loading. Typically `next` calls occur
  8508. * each time a Firestore document is loaded from the bundle.
  8509. * @param error
  8510. * Called when an error occurs during bundle loading. The task aborts after reporting the
  8511. * error, and there should be no more updates after this.
  8512. * @param complete
  8513. * Called when the loading task is complete.
  8514. */
  8515. onProgress(
  8516. next?: (progress: LoadBundleTaskProgress) => any,
  8517. error?: (error: Error) => any,
  8518. complete?: () => void
  8519. ): void;
  8520. /**
  8521. * Implements the `Promise<LoadBundleTaskProgress>.then` interface.
  8522. *
  8523. * @param onFulfilled
  8524. * Called on the completion of the loading task with a final `LoadBundleTaskProgress` update.
  8525. * The update will always have its `taskState` set to `"Success"`.
  8526. * @param onRejected
  8527. * Called when an error occurs during bundle loading.
  8528. */
  8529. then<T, R>(
  8530. onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
  8531. onRejected?: (a: Error) => R | PromiseLike<R>
  8532. ): Promise<T | R>;
  8533. /**
  8534. * Implements the `Promise<LoadBundleTaskProgress>.catch` interface.
  8535. *
  8536. * @param onRejected
  8537. * Called when an error occurs during bundle loading.
  8538. */
  8539. catch<R>(
  8540. onRejected: (a: Error) => R | PromiseLike<R>
  8541. ): Promise<R | LoadBundleTaskProgress>;
  8542. }
  8543. /**
  8544. * Represents a progress update or a final state from loading bundles.
  8545. */
  8546. export interface LoadBundleTaskProgress {
  8547. /** How many documents have been loaded. */
  8548. documentsLoaded: number;
  8549. /** How many documents are in the bundle being loaded. */
  8550. totalDocuments: number;
  8551. /** How many bytes have been loaded. */
  8552. bytesLoaded: number;
  8553. /** How many bytes are in the bundle being loaded. */
  8554. totalBytes: number;
  8555. /** Current task state. */
  8556. taskState: TaskState;
  8557. }
  8558. /**
  8559. * Represents the state of bundle loading tasks.
  8560. *
  8561. * Both 'Error' and 'Success' are sinking state: task will abort or complete and there will
  8562. * be no more updates after they are reported.
  8563. */
  8564. export type TaskState = 'Error' | 'Running' | 'Success';
  8565. /**
  8566. * An immutable object representing a geo point in Firestore. The geo point
  8567. * is represented as latitude/longitude pair.
  8568. *
  8569. * Latitude values are in the range of [-90, 90].
  8570. * Longitude values are in the range of [-180, 180].
  8571. */
  8572. export class GeoPoint {
  8573. /**
  8574. * Creates a new immutable GeoPoint object with the provided latitude and
  8575. * longitude values.
  8576. * @param latitude The latitude as number between -90 and 90.
  8577. * @param longitude The longitude as number between -180 and 180.
  8578. */
  8579. constructor(latitude: number, longitude: number);
  8580. /**
  8581. * The latitude of this GeoPoint instance.
  8582. */
  8583. readonly latitude: number;
  8584. /**
  8585. * The longitude of this GeoPoint instance.
  8586. */
  8587. readonly longitude: number;
  8588. /**
  8589. * Returns true if this `GeoPoint` is equal to the provided one.
  8590. *
  8591. * @param other The `GeoPoint` to compare against.
  8592. * @return true if this `GeoPoint` is equal to the provided one.
  8593. */
  8594. isEqual(other: GeoPoint): boolean;
  8595. }
  8596. /**
  8597. * A Timestamp represents a point in time independent of any time zone or
  8598. * calendar, represented as seconds and fractions of seconds at nanosecond
  8599. * resolution in UTC Epoch time.
  8600. *
  8601. * It is encoded using the Proleptic Gregorian
  8602. * Calendar which extends the Gregorian calendar backwards to year one. It is
  8603. * encoded assuming all minutes are 60 seconds long, i.e. leap seconds are
  8604. * "smeared" so that no leap second table is needed for interpretation. Range is
  8605. * from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
  8606. *
  8607. * @see https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto
  8608. */
  8609. export class Timestamp {
  8610. /**
  8611. * Creates a new timestamp.
  8612. *
  8613. * @param seconds The number of seconds of UTC time since Unix epoch
  8614. * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
  8615. * 9999-12-31T23:59:59Z inclusive.
  8616. * @param nanoseconds The non-negative fractions of a second at nanosecond
  8617. * resolution. Negative second values with fractions must still have
  8618. * non-negative nanoseconds values that count forward in time. Must be
  8619. * from 0 to 999,999,999 inclusive.
  8620. */
  8621. constructor(seconds: number, nanoseconds: number);
  8622. /**
  8623. * Creates a new timestamp with the current date, with millisecond precision.
  8624. *
  8625. * @return a new timestamp representing the current date.
  8626. */
  8627. static now(): Timestamp;
  8628. /**
  8629. * Creates a new timestamp from the given date.
  8630. *
  8631. * @param date The date to initialize the `Timestamp` from.
  8632. * @return A new `Timestamp` representing the same point in time as the given
  8633. * date.
  8634. */
  8635. static fromDate(date: Date): Timestamp;
  8636. /**
  8637. * Creates a new timestamp from the given number of milliseconds.
  8638. *
  8639. * @param milliseconds Number of milliseconds since Unix epoch
  8640. * 1970-01-01T00:00:00Z.
  8641. * @return A new `Timestamp` representing the same point in time as the given
  8642. * number of milliseconds.
  8643. */
  8644. static fromMillis(milliseconds: number): Timestamp;
  8645. readonly seconds: number;
  8646. readonly nanoseconds: number;
  8647. /**
  8648. * Convert a Timestamp to a JavaScript `Date` object. This conversion causes
  8649. * a loss of precision since `Date` objects only support millisecond precision.
  8650. *
  8651. * @return JavaScript `Date` object representing the same point in time as
  8652. * this `Timestamp`, with millisecond precision.
  8653. */
  8654. toDate(): Date;
  8655. /**
  8656. * Convert a timestamp to a numeric timestamp (in milliseconds since epoch).
  8657. * This operation causes a loss of precision.
  8658. *
  8659. * @return The point in time corresponding to this timestamp, represented as
  8660. * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
  8661. */
  8662. toMillis(): number;
  8663. /**
  8664. * Returns true if this `Timestamp` is equal to the provided one.
  8665. *
  8666. * @param other The `Timestamp` to compare against.
  8667. * @return true if this `Timestamp` is equal to the provided one.
  8668. */
  8669. isEqual(other: Timestamp): boolean;
  8670. /**
  8671. * Converts this object to a primitive string, which allows Timestamp objects to be compared
  8672. * using the `>`, `<=`, `>=` and `>` operators.
  8673. */
  8674. valueOf(): string;
  8675. }
  8676. /**
  8677. * An immutable object representing an array of bytes.
  8678. */
  8679. export class Blob {
  8680. private constructor();
  8681. /**
  8682. * Creates a new Blob from the given Base64 string, converting it to
  8683. * bytes.
  8684. *
  8685. * @param base64
  8686. * The Base64 string used to create the Blob object.
  8687. */
  8688. static fromBase64String(base64: string): Blob;
  8689. /**
  8690. * Creates a new Blob from the given Uint8Array.
  8691. *
  8692. * @param array
  8693. * The Uint8Array used to create the Blob object.
  8694. */
  8695. static fromUint8Array(array: Uint8Array): Blob;
  8696. /**
  8697. * Returns the bytes of a Blob as a Base64-encoded string.
  8698. *
  8699. * @return
  8700. * The Base64-encoded string created from the Blob object.
  8701. */
  8702. public toBase64(): string;
  8703. /**
  8704. * Returns the bytes of a Blob in a new Uint8Array.
  8705. *
  8706. * @return
  8707. * The Uint8Array created from the Blob object.
  8708. */
  8709. public toUint8Array(): Uint8Array;
  8710. /**
  8711. * Returns true if this `Blob` is equal to the provided one.
  8712. *
  8713. * @param other The `Blob` to compare against.
  8714. * @return true if this `Blob` is equal to the provided one.
  8715. */
  8716. isEqual(other: Blob): boolean;
  8717. }
  8718. /**
  8719. * A reference to a transaction.
  8720. * The `Transaction` object passed to a transaction's updateFunction provides
  8721. * the methods to read and write data within the transaction context. See
  8722. * `Firestore.runTransaction()`.
  8723. */
  8724. export class Transaction {
  8725. private constructor();
  8726. /**
  8727. * Reads the document referenced by the provided `DocumentReference.`
  8728. *
  8729. * @param documentRef A reference to the document to be read.
  8730. * @return A DocumentSnapshot for the read data.
  8731. */
  8732. get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  8733. /**
  8734. * Writes to the document referred to by the provided `DocumentReference`.
  8735. * If the document does not exist yet, it will be created. If you pass
  8736. * `SetOptions`, the provided data can be merged into the existing document.
  8737. *
  8738. * @param documentRef A reference to the document to be set.
  8739. * @param data An object of the fields and values for the document.
  8740. * @param options An object to configure the set behavior.
  8741. * @return This `Transaction` instance. Used for chaining method calls.
  8742. */
  8743. set<T>(
  8744. documentRef: DocumentReference<T>,
  8745. data: Partial<T>,
  8746. options: SetOptions
  8747. ): Transaction;
  8748. /**
  8749. * Writes to the document referred to by the provided `DocumentReference`.
  8750. * If the document does not exist yet, it will be created. If you pass
  8751. * `SetOptions`, the provided data can be merged into the existing document.
  8752. *
  8753. * @param documentRef A reference to the document to be set.
  8754. * @param data An object of the fields and values for the document.
  8755. * @return This `Transaction` instance. Used for chaining method calls.
  8756. */
  8757. set<T>(documentRef: DocumentReference<T>, data: T): Transaction;
  8758. /**
  8759. * Updates fields in the document referred to by the provided
  8760. * `DocumentReference`. The update will fail if applied to a document that
  8761. * does not exist.
  8762. *
  8763. * @param documentRef A reference to the document to be updated.
  8764. * @param data An object containing the fields and values with which to
  8765. * update the document. Fields can contain dots to reference nested fields
  8766. * within the document.
  8767. * @return This `Transaction` instance. Used for chaining method calls.
  8768. */
  8769. update(documentRef: DocumentReference<any>, data: UpdateData): Transaction;
  8770. /**
  8771. * Updates fields in the document referred to by the provided
  8772. * `DocumentReference`. The update will fail if applied to a document that
  8773. * does not exist.
  8774. *
  8775. * Nested fields can be updated by providing dot-separated field path
  8776. * strings or by providing FieldPath objects.
  8777. *
  8778. * @param documentRef A reference to the document to be updated.
  8779. * @param field The first field to update.
  8780. * @param value The first value.
  8781. * @param moreFieldsAndValues Additional key/value pairs.
  8782. * @return A Promise resolved once the data has been successfully written
  8783. * to the backend (Note that it won't resolve while you're offline).
  8784. */
  8785. update(
  8786. documentRef: DocumentReference<any>,
  8787. field: string | FieldPath,
  8788. value: any,
  8789. ...moreFieldsAndValues: any[]
  8790. ): Transaction;
  8791. /**
  8792. * Deletes the document referred to by the provided `DocumentReference`.
  8793. *
  8794. * @param documentRef A reference to the document to be deleted.
  8795. * @return This `Transaction` instance. Used for chaining method calls.
  8796. */
  8797. delete(documentRef: DocumentReference<any>): Transaction;
  8798. }
  8799. /**
  8800. * A write batch, used to perform multiple writes as a single atomic unit.
  8801. *
  8802. * A `WriteBatch` object can be acquired by calling `Firestore.batch()`. It
  8803. * provides methods for adding writes to the write batch. None of the
  8804. * writes will be committed (or visible locally) until `WriteBatch.commit()`
  8805. * is called.
  8806. *
  8807. * Unlike transactions, write batches are persisted offline and therefore are
  8808. * preferable when you don't need to condition your writes on read data.
  8809. */
  8810. export class WriteBatch {
  8811. private constructor();
  8812. /**
  8813. * Writes to the document referred to by the provided `DocumentReference`.
  8814. * If the document does not exist yet, it will be created. If you pass
  8815. * `SetOptions`, the provided data can be merged into the existing document.
  8816. *
  8817. * @param documentRef A reference to the document to be set.
  8818. * @param data An object of the fields and values for the document.
  8819. * @param options An object to configure the set behavior.
  8820. * @return This `WriteBatch` instance. Used for chaining method calls.
  8821. */
  8822. set<T>(
  8823. documentRef: DocumentReference<T>,
  8824. data: Partial<T>,
  8825. options: SetOptions
  8826. ): WriteBatch;
  8827. /**
  8828. * Writes to the document referred to by the provided `DocumentReference`.
  8829. * If the document does not exist yet, it will be created. If you pass
  8830. * `SetOptions`, the provided data can be merged into the existing document.
  8831. *
  8832. * @param documentRef A reference to the document to be set.
  8833. * @param data An object of the fields and values for the document.
  8834. * @return This `WriteBatch` instance. Used for chaining method calls.
  8835. */
  8836. set<T>(documentRef: DocumentReference<T>, data: T): WriteBatch;
  8837. /**
  8838. * Updates fields in the document referred to by the provided
  8839. * `DocumentReference`. The update will fail if applied to a document that
  8840. * does not exist.
  8841. *
  8842. * @param documentRef A reference to the document to be updated.
  8843. * @param data An object containing the fields and values with which to
  8844. * update the document. Fields can contain dots to reference nested fields
  8845. * within the document.
  8846. * @return This `WriteBatch` instance. Used for chaining method calls.
  8847. */
  8848. update(documentRef: DocumentReference<any>, data: UpdateData): WriteBatch;
  8849. /**
  8850. * Updates fields in the document referred to by this `DocumentReference`.
  8851. * The update will fail if applied to a document that does not exist.
  8852. *
  8853. * Nested fields can be update by providing dot-separated field path strings
  8854. * or by providing FieldPath objects.
  8855. *
  8856. * @param documentRef A reference to the document to be updated.
  8857. * @param field The first field to update.
  8858. * @param value The first value.
  8859. * @param moreFieldsAndValues Additional key value pairs.
  8860. * @return A Promise resolved once the data has been successfully written
  8861. * to the backend (Note that it won't resolve while you're offline).
  8862. */
  8863. update(
  8864. documentRef: DocumentReference<any>,
  8865. field: string | FieldPath,
  8866. value: any,
  8867. ...moreFieldsAndValues: any[]
  8868. ): WriteBatch;
  8869. /**
  8870. * Deletes the document referred to by the provided `DocumentReference`.
  8871. *
  8872. * @param documentRef A reference to the document to be deleted.
  8873. * @return This `WriteBatch` instance. Used for chaining method calls.
  8874. */
  8875. delete(documentRef: DocumentReference<any>): WriteBatch;
  8876. /**
  8877. * Commits all of the writes in this write batch as a single atomic unit.
  8878. *
  8879. * @return A Promise resolved once all of the writes in the batch have been
  8880. * successfully written to the backend as an atomic unit. Note that it won't
  8881. * resolve while you're offline.
  8882. */
  8883. commit(): Promise<void>;
  8884. }
  8885. /**
  8886. * An options object that can be passed to `DocumentReference.onSnapshot()`,
  8887. * `Query.onSnapshot()` and `QuerySnapshot.docChanges()` to control which
  8888. * types of changes to include in the result set.
  8889. */
  8890. export interface SnapshotListenOptions {
  8891. /**
  8892. * Include a change even if only the metadata of the query or of a document
  8893. * changed. Default is false.
  8894. */
  8895. readonly includeMetadataChanges?: boolean;
  8896. }
  8897. /**
  8898. * An options object that configures the behavior of `set()` calls in
  8899. * {@link firebase.firestore.DocumentReference.set DocumentReference}, {@link
  8900. * firebase.firestore.WriteBatch.set WriteBatch} and {@link
  8901. * firebase.firestore.Transaction.set Transaction}. These calls can be
  8902. * configured to perform granular merges instead of overwriting the target
  8903. * documents in their entirety by providing a `SetOptions` with `merge: true`.
  8904. */
  8905. export interface SetOptions {
  8906. /**
  8907. * Changes the behavior of a set() call to only replace the values specified
  8908. * in its data argument. Fields omitted from the set() call remain
  8909. * untouched.
  8910. */
  8911. readonly merge?: boolean;
  8912. /**
  8913. * Changes the behavior of set() calls to only replace the specified field
  8914. * paths. Any field path that is not specified is ignored and remains
  8915. * untouched.
  8916. */
  8917. readonly mergeFields?: (string | FieldPath)[];
  8918. }
  8919. /**
  8920. * An options object that configures the behavior of `get()` calls on
  8921. * `DocumentReference` and `Query`. By providing a `GetOptions` object, these
  8922. * methods can be configured to fetch results only from the server, only from
  8923. * the local cache or attempt to fetch results from the server and fall back to
  8924. * the cache (which is the default).
  8925. */
  8926. export interface GetOptions {
  8927. /**
  8928. * Describes whether we should get from server or cache.
  8929. *
  8930. * Setting to `default` (or not setting at all), causes Firestore to try to
  8931. * retrieve an up-to-date (server-retrieved) snapshot, but fall back to
  8932. * returning cached data if the server can't be reached.
  8933. *
  8934. * Setting to `server` causes Firestore to avoid the cache, generating an
  8935. * error if the server cannot be reached. Note that the cache will still be
  8936. * updated if the server request succeeds. Also note that latency-compensation
  8937. * still takes effect, so any pending write operations will be visible in the
  8938. * returned data (merged into the server-provided data).
  8939. *
  8940. * Setting to `cache` causes Firestore to immediately return a value from the
  8941. * cache, ignoring the server completely (implying that the returned value
  8942. * may be stale with respect to the value on the server.) If there is no data
  8943. * in the cache to satisfy the `get()` call, `DocumentReference.get()` will
  8944. * return an error and `QuerySnapshot.get()` will return an empty
  8945. * `QuerySnapshot` with no documents.
  8946. */
  8947. readonly source?: 'default' | 'server' | 'cache';
  8948. }
  8949. /**
  8950. * A `DocumentReference` refers to a document location in a Firestore database
  8951. * and can be used to write, read, or listen to the location. The document at
  8952. * the referenced location may or may not exist. A `DocumentReference` can
  8953. * also be used to create a `CollectionReference` to a subcollection.
  8954. */
  8955. export class DocumentReference<T = DocumentData> {
  8956. private constructor();
  8957. /**
  8958. * The document's identifier within its collection.
  8959. */
  8960. readonly id: string;
  8961. /**
  8962. * The {@link firebase.firestore.Firestore} the document is in.
  8963. * This is useful for performing transactions, for example.
  8964. */
  8965. readonly firestore: Firestore;
  8966. /**
  8967. * The Collection this `DocumentReference` belongs to.
  8968. */
  8969. readonly parent: CollectionReference<T>;
  8970. /**
  8971. * A string representing the path of the referenced document (relative
  8972. * to the root of the database).
  8973. */
  8974. readonly path: string;
  8975. /**
  8976. * Gets a `CollectionReference` instance that refers to the collection at
  8977. * the specified path.
  8978. *
  8979. * @param collectionPath A slash-separated path to a collection.
  8980. * @return The `CollectionReference` instance.
  8981. */
  8982. collection(collectionPath: string): CollectionReference<DocumentData>;
  8983. /**
  8984. * Returns true if this `DocumentReference` is equal to the provided one.
  8985. *
  8986. * @param other The `DocumentReference` to compare against.
  8987. * @return true if this `DocumentReference` is equal to the provided one.
  8988. */
  8989. isEqual(other: DocumentReference<T>): boolean;
  8990. /**
  8991. * Writes to the document referred to by this `DocumentReference`. If the
  8992. * document does not yet exist, it will be created. If you pass
  8993. * `SetOptions`, the provided data can be merged into an existing document.
  8994. *
  8995. * @param data A map of the fields and values for the document.
  8996. * @param options An object to configure the set behavior.
  8997. * @return A Promise resolved once the data has been successfully written
  8998. * to the backend (Note that it won't resolve while you're offline).
  8999. */
  9000. set(data: Partial<T>, options: SetOptions): Promise<void>;
  9001. /**
  9002. * Writes to the document referred to by this `DocumentReference`. If the
  9003. * document does not yet exist, it will be created. If you pass
  9004. * `SetOptions`, the provided data can be merged into an existing document.
  9005. *
  9006. * @param data A map of the fields and values for the document.
  9007. * @return A Promise resolved once the data has been successfully written
  9008. * to the backend (Note that it won't resolve while you're offline).
  9009. */
  9010. set(data: T): Promise<void>;
  9011. /**
  9012. * Updates fields in the document referred to by this `DocumentReference`.
  9013. * The update will fail if applied to a document that does not exist.
  9014. *
  9015. * @param data An object containing the fields and values with which to
  9016. * update the document. Fields can contain dots to reference nested fields
  9017. * within the document.
  9018. * @return A Promise resolved once the data has been successfully written
  9019. * to the backend (Note that it won't resolve while you're offline).
  9020. */
  9021. update(data: UpdateData): Promise<void>;
  9022. /**
  9023. * Updates fields in the document referred to by this `DocumentReference`.
  9024. * The update will fail if applied to a document that does not exist.
  9025. *
  9026. * Nested fields can be updated by providing dot-separated field path
  9027. * strings or by providing FieldPath objects.
  9028. *
  9029. * @param field The first field to update.
  9030. * @param value The first value.
  9031. * @param moreFieldsAndValues Additional key value pairs.
  9032. * @return A Promise resolved once the data has been successfully written
  9033. * to the backend (Note that it won't resolve while you're offline).
  9034. */
  9035. update(
  9036. field: string | FieldPath,
  9037. value: any,
  9038. ...moreFieldsAndValues: any[]
  9039. ): Promise<void>;
  9040. /**
  9041. * Deletes the document referred to by this `DocumentReference`.
  9042. *
  9043. * @return A Promise resolved once the document has been successfully
  9044. * deleted from the backend (Note that it won't resolve while you're
  9045. * offline).
  9046. */
  9047. delete(): Promise<void>;
  9048. /**
  9049. * Reads the document referred to by this `DocumentReference`.
  9050. *
  9051. * Note: By default, get() attempts to provide up-to-date data when possible
  9052. * by waiting for data from the server, but it may return cached data or fail
  9053. * if you are offline and the server cannot be reached. This behavior can be
  9054. * altered via the `GetOptions` parameter.
  9055. *
  9056. * @param options An object to configure the get behavior.
  9057. * @return A Promise resolved with a DocumentSnapshot containing the
  9058. * current document contents.
  9059. */
  9060. get(options?: GetOptions): Promise<DocumentSnapshot<T>>;
  9061. /**
  9062. * Attaches a listener for DocumentSnapshot events. You may either pass
  9063. * individual `onNext` and `onError` callbacks or pass a single observer
  9064. * object with `next` and `error` callbacks.
  9065. *
  9066. * NOTE: Although an `onCompletion` callback can be provided, it will
  9067. * never be called because the snapshot stream is never-ending.
  9068. *
  9069. * @param observer A single object containing `next` and `error` callbacks.
  9070. * @return An unsubscribe function that can be called to cancel
  9071. * the snapshot listener.
  9072. */
  9073. onSnapshot(observer: {
  9074. next?: (snapshot: DocumentSnapshot<T>) => void;
  9075. error?: (error: FirestoreError) => void;
  9076. complete?: () => void;
  9077. }): () => void;
  9078. /**
  9079. * Attaches a listener for DocumentSnapshot events. You may either pass
  9080. * individual `onNext` and `onError` callbacks or pass a single observer
  9081. * object with `next` and `error` callbacks.
  9082. *
  9083. * NOTE: Although an `onCompletion` callback can be provided, it will
  9084. * never be called because the snapshot stream is never-ending.
  9085. *
  9086. * @param options Options controlling the listen behavior.
  9087. * @param observer A single object containing `next` and `error` callbacks.
  9088. * @return An unsubscribe function that can be called to cancel
  9089. * the snapshot listener.
  9090. */
  9091. onSnapshot(
  9092. options: SnapshotListenOptions,
  9093. observer: {
  9094. next?: (snapshot: DocumentSnapshot<T>) => void;
  9095. error?: (error: FirestoreError) => void;
  9096. complete?: () => void;
  9097. }
  9098. ): () => void;
  9099. /**
  9100. * Attaches a listener for DocumentSnapshot events. You may either pass
  9101. * individual `onNext` and `onError` callbacks or pass a single observer
  9102. * object with `next` and `error` callbacks.
  9103. *
  9104. * NOTE: Although an `onCompletion` callback can be provided, it will
  9105. * never be called because the snapshot stream is never-ending.
  9106. *
  9107. * @param onNext A callback to be called every time a new `DocumentSnapshot`
  9108. * is available.
  9109. * @param onError A callback to be called if the listen fails or is
  9110. * cancelled. No further callbacks will occur.
  9111. * @return An unsubscribe function that can be called to cancel
  9112. * the snapshot listener.
  9113. */
  9114. onSnapshot(
  9115. onNext: (snapshot: DocumentSnapshot<T>) => void,
  9116. onError?: (error: FirestoreError) => void,
  9117. onCompletion?: () => void
  9118. ): () => void;
  9119. /**
  9120. * Attaches a listener for DocumentSnapshot events. You may either pass
  9121. * individual `onNext` and `onError` callbacks or pass a single observer
  9122. * object with `next` and `error` callbacks.
  9123. *
  9124. * NOTE: Although an `onCompletion` callback can be provided, it will
  9125. * never be called because the snapshot stream is never-ending.
  9126. *
  9127. * @param options Options controlling the listen behavior.
  9128. * @param onNext A callback to be called every time a new `DocumentSnapshot`
  9129. * is available.
  9130. * @param onError A callback to be called if the listen fails or is
  9131. * cancelled. No further callbacks will occur.
  9132. * @return An unsubscribe function that can be called to cancel
  9133. * the snapshot listener.
  9134. */
  9135. onSnapshot(
  9136. options: SnapshotListenOptions,
  9137. onNext: (snapshot: DocumentSnapshot<T>) => void,
  9138. onError?: (error: FirestoreError) => void,
  9139. onCompletion?: () => void
  9140. ): () => void;
  9141. /**
  9142. * Applies a custom data converter to this DocumentReference, allowing you
  9143. * to use your own custom model objects with Firestore. When you call
  9144. * set(), get(), etc. on the returned DocumentReference instance, the
  9145. * provided converter will convert between Firestore data and your custom
  9146. * type U.
  9147. *
  9148. * Passing in `null` as the converter parameter removes the current
  9149. * converter.
  9150. *
  9151. * @param converter Converts objects to and from Firestore. Passing in
  9152. * `null` removes the current converter.
  9153. * @return A DocumentReference<U> that uses the provided converter.
  9154. */
  9155. withConverter(converter: null): DocumentReference<DocumentData>;
  9156. /**
  9157. * Applies a custom data converter to this DocumentReference, allowing you
  9158. * to use your own custom model objects with Firestore. When you call
  9159. * set(), get(), etc. on the returned DocumentReference instance, the
  9160. * provided converter will convert between Firestore data and your custom
  9161. * type U.
  9162. *
  9163. * Passing in `null` as the converter parameter removes the current
  9164. * converter.
  9165. *
  9166. * @param converter Converts objects to and from Firestore. Passing in
  9167. * `null` removes the current converter.
  9168. * @return A DocumentReference<U> that uses the provided converter.
  9169. */
  9170. withConverter<U>(
  9171. converter: FirestoreDataConverter<U>
  9172. ): DocumentReference<U>;
  9173. }
  9174. /**
  9175. * Options that configure how data is retrieved from a `DocumentSnapshot`
  9176. * (e.g. the desired behavior for server timestamps that have not yet been set
  9177. * to their final value).
  9178. */
  9179. export interface SnapshotOptions {
  9180. /**
  9181. * If set, controls the return value for server timestamps that have not yet
  9182. * been set to their final value.
  9183. *
  9184. * By specifying 'estimate', pending server timestamps return an estimate
  9185. * based on the local clock. This estimate will differ from the final value
  9186. * and cause these values to change once the server result becomes available.
  9187. *
  9188. * By specifying 'previous', pending timestamps will be ignored and return
  9189. * their previous value instead.
  9190. *
  9191. * If omitted or set to 'none', `null` will be returned by default until the
  9192. * server value becomes available.
  9193. */
  9194. readonly serverTimestamps?: 'estimate' | 'previous' | 'none';
  9195. }
  9196. /**
  9197. * Metadata about a snapshot, describing the state of the snapshot.
  9198. */
  9199. export interface SnapshotMetadata {
  9200. /**
  9201. * True if the snapshot contains the result of local writes (e.g. set() or
  9202. * update() calls) that have not yet been committed to the backend.
  9203. * If your listener has opted into metadata updates (via
  9204. * `SnapshotListenOptions`) you will receive another
  9205. * snapshot with `hasPendingWrites` equal to false once the writes have been
  9206. * committed to the backend.
  9207. */
  9208. readonly hasPendingWrites: boolean;
  9209. /**
  9210. * True if the snapshot was created from cached data rather than guaranteed
  9211. * up-to-date server data. If your listener has opted into metadata updates
  9212. * (via `SnapshotListenOptions`)
  9213. * you will receive another snapshot with `fromCache` set to false once
  9214. * the client has received up-to-date data from the backend.
  9215. */
  9216. readonly fromCache: boolean;
  9217. /**
  9218. * Returns true if this `SnapshotMetadata` is equal to the provided one.
  9219. *
  9220. * @param other The `SnapshotMetadata` to compare against.
  9221. * @return true if this `SnapshotMetadata` is equal to the provided one.
  9222. */
  9223. isEqual(other: SnapshotMetadata): boolean;
  9224. }
  9225. /**
  9226. * A `DocumentSnapshot` contains data read from a document in your Firestore
  9227. * database. The data can be extracted with `.data()` or `.get(<field>)` to
  9228. * get a specific field.
  9229. *
  9230. * For a `DocumentSnapshot` that points to a non-existing document, any data
  9231. * access will return 'undefined'. You can use the `exists` property to
  9232. * explicitly verify a document's existence.
  9233. */
  9234. export class DocumentSnapshot<T = DocumentData> {
  9235. protected constructor();
  9236. /**
  9237. * Property of the `DocumentSnapshot` that signals whether or not the data
  9238. * exists. True if the document exists.
  9239. */
  9240. readonly exists: boolean;
  9241. /**
  9242. * The `DocumentReference` for the document included in the `DocumentSnapshot`.
  9243. */
  9244. readonly ref: DocumentReference<T>;
  9245. /**
  9246. * Property of the `DocumentSnapshot` that provides the document's ID.
  9247. */
  9248. readonly id: string;
  9249. /**
  9250. * Metadata about the `DocumentSnapshot`, including information about its
  9251. * source and local modifications.
  9252. */
  9253. readonly metadata: SnapshotMetadata;
  9254. /**
  9255. * Retrieves all fields in the document as an Object. Returns 'undefined' if
  9256. * the document doesn't exist.
  9257. *
  9258. * By default, `FieldValue.serverTimestamp()` values that have not yet been
  9259. * set to their final value will be returned as `null`. You can override
  9260. * this by passing an options object.
  9261. *
  9262. * @param options An options object to configure how data is retrieved from
  9263. * the snapshot (e.g. the desired behavior for server timestamps that have
  9264. * not yet been set to their final value).
  9265. * @return An Object containing all fields in the document or 'undefined' if
  9266. * the document doesn't exist.
  9267. */
  9268. data(options?: SnapshotOptions): T | undefined;
  9269. /**
  9270. * Retrieves the field specified by `fieldPath`. Returns `undefined` if the
  9271. * document or field doesn't exist.
  9272. *
  9273. * By default, a `FieldValue.serverTimestamp()` that has not yet been set to
  9274. * its final value will be returned as `null`. You can override this by
  9275. * passing an options object.
  9276. *
  9277. * @param fieldPath The path (e.g. 'foo' or 'foo.bar') to a specific field.
  9278. * @param options An options object to configure how the field is retrieved
  9279. * from the snapshot (e.g. the desired behavior for server timestamps that have
  9280. * not yet been set to their final value).
  9281. * @return The data at the specified field location or undefined if no such
  9282. * field exists in the document.
  9283. */
  9284. get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
  9285. /**
  9286. * Returns true if this `DocumentSnapshot` is equal to the provided one.
  9287. *
  9288. * @param other The `DocumentSnapshot` to compare against.
  9289. * @return true if this `DocumentSnapshot` is equal to the provided one.
  9290. */
  9291. isEqual(other: DocumentSnapshot<T>): boolean;
  9292. }
  9293. /**
  9294. * A `QueryDocumentSnapshot` contains data read from a document in your
  9295. * Firestore database as part of a query. The document is guaranteed to exist
  9296. * and its data can be extracted with `.data()` or `.get(<field>)` to get a
  9297. * specific field.
  9298. *
  9299. * A `QueryDocumentSnapshot` offers the same API surface as a
  9300. * `DocumentSnapshot`. Since query results contain only existing documents, the
  9301. * `exists` property will always be true and `data()` will never return
  9302. * 'undefined'.
  9303. */
  9304. export class QueryDocumentSnapshot<
  9305. T = DocumentData
  9306. > extends DocumentSnapshot<T> {
  9307. private constructor();
  9308. /**
  9309. * Retrieves all fields in the document as an Object.
  9310. *
  9311. * By default, `FieldValue.serverTimestamp()` values that have not yet been
  9312. * set to their final value will be returned as `null`. You can override
  9313. * this by passing an options object.
  9314. *
  9315. * @override
  9316. * @param options An options object to configure how data is retrieved from
  9317. * the snapshot (e.g. the desired behavior for server timestamps that have
  9318. * not yet been set to their final value).
  9319. * @return An Object containing all fields in the document.
  9320. */
  9321. data(options?: SnapshotOptions): T;
  9322. }
  9323. /**
  9324. * The direction of a `Query.orderBy()` clause is specified as 'desc' or 'asc'
  9325. * (descending or ascending).
  9326. */
  9327. export type OrderByDirection = 'desc' | 'asc';
  9328. /**
  9329. * Filter conditions in a `Query.where()` clause are specified using the
  9330. * strings '<', '<=', '==', '!=', '>=', '>', 'array-contains', 'in',
  9331. * 'array-contains-any', and 'not-in'.
  9332. */
  9333. export type WhereFilterOp =
  9334. | '<'
  9335. | '<='
  9336. | '=='
  9337. | '!='
  9338. | '>='
  9339. | '>'
  9340. | 'array-contains'
  9341. | 'in'
  9342. | 'array-contains-any'
  9343. | 'not-in';
  9344. /**
  9345. * A `Query` refers to a Query which you can read or listen to. You can also
  9346. * construct refined `Query` objects by adding filters and ordering.
  9347. */
  9348. export class Query<T = DocumentData> {
  9349. protected constructor();
  9350. /**
  9351. * The `Firestore` for the Firestore database (useful for performing
  9352. * transactions, etc.).
  9353. */
  9354. readonly firestore: Firestore;
  9355. /**
  9356. * Creates and returns a new Query with the additional filter that documents
  9357. * must contain the specified field and the value should satisfy the
  9358. * relation constraint provided.
  9359. *
  9360. * @param fieldPath The path to compare
  9361. * @param opStr The operation string (e.g "<", "<=", "==", ">", ">=").
  9362. * @param value The value for comparison
  9363. * @return The created Query.
  9364. */
  9365. where(
  9366. fieldPath: string | FieldPath,
  9367. opStr: WhereFilterOp,
  9368. value: any
  9369. ): Query<T>;
  9370. /**
  9371. * Creates and returns a new Query that's additionally sorted by the
  9372. * specified field, optionally in descending order instead of ascending.
  9373. *
  9374. * @param fieldPath The field to sort by.
  9375. * @param directionStr Optional direction to sort by (`asc` or `desc`). If
  9376. * not specified, order will be ascending.
  9377. * @return The created Query.
  9378. */
  9379. orderBy(
  9380. fieldPath: string | FieldPath,
  9381. directionStr?: OrderByDirection
  9382. ): Query<T>;
  9383. /**
  9384. * Creates and returns a new Query that only returns the first matching
  9385. * documents.
  9386. *
  9387. * @param limit The maximum number of items to return.
  9388. * @return The created Query.
  9389. */
  9390. limit(limit: number): Query<T>;
  9391. /**
  9392. * Creates and returns a new Query that only returns the last matching
  9393. * documents.
  9394. *
  9395. * You must specify at least one `orderBy` clause for `limitToLast` queries,
  9396. * otherwise an exception will be thrown during execution.
  9397. *
  9398. * @param limit The maximum number of items to return.
  9399. * @return The created Query.
  9400. */
  9401. limitToLast(limit: number): Query<T>;
  9402. /**
  9403. * Creates and returns a new Query that starts at the provided document
  9404. * (inclusive). The starting position is relative to the order of the query.
  9405. * The document must contain all of the fields provided in the `orderBy` of
  9406. * this query.
  9407. *
  9408. * @param snapshot The snapshot of the document to start at.
  9409. * @return The created Query.
  9410. */
  9411. startAt(snapshot: DocumentSnapshot<any>): Query<T>;
  9412. /**
  9413. * Creates and returns a new Query that starts at the provided fields
  9414. * relative to the order of the query. The order of the field values
  9415. * must match the order of the order by clauses of the query.
  9416. *
  9417. * @param fieldValues The field values to start this query at, in order
  9418. * of the query's order by.
  9419. * @return The created Query.
  9420. */
  9421. startAt(...fieldValues: any[]): Query<T>;
  9422. /**
  9423. * Creates and returns a new Query that starts after the provided document
  9424. * (exclusive). The starting position is relative to the order of the query.
  9425. * The document must contain all of the fields provided in the orderBy of
  9426. * this query.
  9427. *
  9428. * @param snapshot The snapshot of the document to start after.
  9429. * @return The created Query.
  9430. */
  9431. startAfter(snapshot: DocumentSnapshot<any>): Query<T>;
  9432. /**
  9433. * Creates and returns a new Query that starts after the provided fields
  9434. * relative to the order of the query. The order of the field values
  9435. * must match the order of the order by clauses of the query.
  9436. *
  9437. * @param fieldValues The field values to start this query after, in order
  9438. * of the query's order by.
  9439. * @return The created Query.
  9440. */
  9441. startAfter(...fieldValues: any[]): Query<T>;
  9442. /**
  9443. * Creates and returns a new Query that ends before the provided document
  9444. * (exclusive). The end position is relative to the order of the query. The
  9445. * document must contain all of the fields provided in the orderBy of this
  9446. * query.
  9447. *
  9448. * @param snapshot The snapshot of the document to end before.
  9449. * @return The created Query.
  9450. */
  9451. endBefore(snapshot: DocumentSnapshot<any>): Query<T>;
  9452. /**
  9453. * Creates and returns a new Query that ends before the provided fields
  9454. * relative to the order of the query. The order of the field values
  9455. * must match the order of the order by clauses of the query.
  9456. *
  9457. * @param fieldValues The field values to end this query before, in order
  9458. * of the query's order by.
  9459. * @return The created Query.
  9460. */
  9461. endBefore(...fieldValues: any[]): Query<T>;
  9462. /**
  9463. * Creates and returns a new Query that ends at the provided document
  9464. * (inclusive). The end position is relative to the order of the query. The
  9465. * document must contain all of the fields provided in the orderBy of this
  9466. * query.
  9467. *
  9468. * @param snapshot The snapshot of the document to end at.
  9469. * @return The created Query.
  9470. */
  9471. endAt(snapshot: DocumentSnapshot<any>): Query<T>;
  9472. /**
  9473. * Creates and returns a new Query that ends at the provided fields
  9474. * relative to the order of the query. The order of the field values
  9475. * must match the order of the order by clauses of the query.
  9476. *
  9477. * @param fieldValues The field values to end this query at, in order
  9478. * of the query's order by.
  9479. * @return The created Query.
  9480. */
  9481. endAt(...fieldValues: any[]): Query<T>;
  9482. /**
  9483. * Returns true if this `Query` is equal to the provided one.
  9484. *
  9485. * @param other The `Query` to compare against.
  9486. * @return true if this `Query` is equal to the provided one.
  9487. */
  9488. isEqual(other: Query<T>): boolean;
  9489. /**
  9490. * Executes the query and returns the results as a `QuerySnapshot`.
  9491. *
  9492. * Note: By default, get() attempts to provide up-to-date data when possible
  9493. * by waiting for data from the server, but it may return cached data or fail
  9494. * if you are offline and the server cannot be reached. This behavior can be
  9495. * altered via the `GetOptions` parameter.
  9496. *
  9497. * @param options An object to configure the get behavior.
  9498. * @return A Promise that will be resolved with the results of the Query.
  9499. */
  9500. get(options?: GetOptions): Promise<QuerySnapshot<T>>;
  9501. /**
  9502. * Attaches a listener for QuerySnapshot events. You may either pass
  9503. * individual `onNext` and `onError` callbacks or pass a single observer
  9504. * object with `next` and `error` callbacks. The listener can be cancelled by
  9505. * calling the function that is returned when `onSnapshot` is called.
  9506. *
  9507. * NOTE: Although an `onCompletion` callback can be provided, it will
  9508. * never be called because the snapshot stream is never-ending.
  9509. *
  9510. * @param observer A single object containing `next` and `error` callbacks.
  9511. * @return An unsubscribe function that can be called to cancel
  9512. * the snapshot listener.
  9513. */
  9514. onSnapshot(observer: {
  9515. next?: (snapshot: QuerySnapshot<T>) => void;
  9516. error?: (error: FirestoreError) => void;
  9517. complete?: () => void;
  9518. }): () => void;
  9519. /**
  9520. * Attaches a listener for QuerySnapshot events. You may either pass
  9521. * individual `onNext` and `onError` callbacks or pass a single observer
  9522. * object with `next` and `error` callbacks. The listener can be cancelled by
  9523. * calling the function that is returned when `onSnapshot` is called.
  9524. *
  9525. * NOTE: Although an `onCompletion` callback can be provided, it will
  9526. * never be called because the snapshot stream is never-ending.
  9527. *
  9528. * @param options Options controlling the listen behavior.
  9529. * @param observer A single object containing `next` and `error` callbacks.
  9530. * @return An unsubscribe function that can be called to cancel
  9531. * the snapshot listener.
  9532. */
  9533. onSnapshot(
  9534. options: SnapshotListenOptions,
  9535. observer: {
  9536. next?: (snapshot: QuerySnapshot<T>) => void;
  9537. error?: (error: FirestoreError) => void;
  9538. complete?: () => void;
  9539. }
  9540. ): () => void;
  9541. /**
  9542. * Attaches a listener for QuerySnapshot events. You may either pass
  9543. * individual `onNext` and `onError` callbacks or pass a single observer
  9544. * object with `next` and `error` callbacks. The listener can be cancelled by
  9545. * calling the function that is returned when `onSnapshot` is called.
  9546. *
  9547. * NOTE: Although an `onCompletion` callback can be provided, it will
  9548. * never be called because the snapshot stream is never-ending.
  9549. *
  9550. * @param onNext A callback to be called every time a new `QuerySnapshot`
  9551. * is available.
  9552. * @param onError A callback to be called if the listen fails or is
  9553. * cancelled. No further callbacks will occur.
  9554. * @return An unsubscribe function that can be called to cancel
  9555. * the snapshot listener.
  9556. */
  9557. onSnapshot(
  9558. onNext: (snapshot: QuerySnapshot<T>) => void,
  9559. onError?: (error: FirestoreError) => void,
  9560. onCompletion?: () => void
  9561. ): () => void;
  9562. /**
  9563. * Attaches a listener for QuerySnapshot events. You may either pass
  9564. * individual `onNext` and `onError` callbacks or pass a single observer
  9565. * object with `next` and `error` callbacks. The listener can be cancelled by
  9566. * calling the function that is returned when `onSnapshot` is called.
  9567. *
  9568. * NOTE: Although an `onCompletion` callback can be provided, it will
  9569. * never be called because the snapshot stream is never-ending.
  9570. *
  9571. * @param options Options controlling the listen behavior.
  9572. * @param onNext A callback to be called every time a new `QuerySnapshot`
  9573. * is available.
  9574. * @param onError A callback to be called if the listen fails or is
  9575. * cancelled. No further callbacks will occur.
  9576. * @return An unsubscribe function that can be called to cancel
  9577. * the snapshot listener.
  9578. */
  9579. onSnapshot(
  9580. options: SnapshotListenOptions,
  9581. onNext: (snapshot: QuerySnapshot<T>) => void,
  9582. onError?: (error: FirestoreError) => void,
  9583. onCompletion?: () => void
  9584. ): () => void;
  9585. /**
  9586. * Applies a custom data converter to this Query, allowing you to use your
  9587. * own custom model objects with Firestore. When you call get() on the
  9588. * returned Query, the provided converter will convert between Firestore
  9589. * data and your custom type U.
  9590. *
  9591. * Passing in `null` as the converter parameter removes the current
  9592. * converter.
  9593. *
  9594. * @param converter Converts objects to and from Firestore. Passing in
  9595. * `null` removes the current converter.
  9596. * @return A Query<U> that uses the provided converter.
  9597. */
  9598. withConverter(converter: null): Query<DocumentData>;
  9599. /**
  9600. * Applies a custom data converter to this Query, allowing you to use your
  9601. * own custom model objects with Firestore. When you call get() on the
  9602. * returned Query, the provided converter will convert between Firestore
  9603. * data and your custom type U.
  9604. *
  9605. * Passing in `null` as the converter parameter removes the current
  9606. * converter.
  9607. *
  9608. * @param converter Converts objects to and from Firestore. Passing in
  9609. * `null` removes the current converter.
  9610. * @return A Query<U> that uses the provided converter.
  9611. */
  9612. withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
  9613. }
  9614. /**
  9615. * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects
  9616. * representing the results of a query. The documents can be accessed as an
  9617. * array via the `docs` property or enumerated using the `forEach` method. The
  9618. * number of documents can be determined via the `empty` and `size`
  9619. * properties.
  9620. */
  9621. export class QuerySnapshot<T = DocumentData> {
  9622. private constructor();
  9623. /**
  9624. * The query on which you called `get` or `onSnapshot` in order to get this
  9625. * `QuerySnapshot`.
  9626. */
  9627. readonly query: Query<T>;
  9628. /**
  9629. * Metadata about this snapshot, concerning its source and if it has local
  9630. * modifications.
  9631. */
  9632. readonly metadata: SnapshotMetadata;
  9633. /** An array of all the documents in the `QuerySnapshot`. */
  9634. readonly docs: Array<QueryDocumentSnapshot<T>>;
  9635. /** The number of documents in the `QuerySnapshot`. */
  9636. readonly size: number;
  9637. /** True if there are no documents in the `QuerySnapshot`. */
  9638. readonly empty: boolean;
  9639. /**
  9640. * Returns an array of the documents changes since the last snapshot. If this
  9641. * is the first snapshot, all documents will be in the list as added changes.
  9642. *
  9643. * @param options `SnapshotListenOptions` that control whether metadata-only
  9644. * changes (i.e. only `DocumentSnapshot.metadata` changed) should trigger
  9645. * snapshot events.
  9646. */
  9647. docChanges(options?: SnapshotListenOptions): Array<DocumentChange<T>>;
  9648. /**
  9649. * Enumerates all of the documents in the `QuerySnapshot`.
  9650. *
  9651. * @param callback A callback to be called with a `QueryDocumentSnapshot` for
  9652. * each document in the snapshot.
  9653. * @param thisArg The `this` binding for the callback.
  9654. */
  9655. forEach(
  9656. callback: (result: QueryDocumentSnapshot<T>) => void,
  9657. thisArg?: any
  9658. ): void;
  9659. /**
  9660. * Returns true if this `QuerySnapshot` is equal to the provided one.
  9661. *
  9662. * @param other The `QuerySnapshot` to compare against.
  9663. * @return true if this `QuerySnapshot` is equal to the provided one.
  9664. */
  9665. isEqual(other: QuerySnapshot<T>): boolean;
  9666. }
  9667. /**
  9668. * The type of a `DocumentChange` may be 'added', 'removed', or 'modified'.
  9669. */
  9670. export type DocumentChangeType = 'added' | 'removed' | 'modified';
  9671. /**
  9672. * A `DocumentChange` represents a change to the documents matching a query.
  9673. * It contains the document affected and the type of change that occurred.
  9674. */
  9675. export interface DocumentChange<T = DocumentData> {
  9676. /** The type of change ('added', 'modified', or 'removed'). */
  9677. readonly type: DocumentChangeType;
  9678. /** The document affected by this change. */
  9679. readonly doc: QueryDocumentSnapshot<T>;
  9680. /**
  9681. * The index of the changed document in the result set immediately prior to
  9682. * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` objects
  9683. * have been applied). Is -1 for 'added' events.
  9684. */
  9685. readonly oldIndex: number;
  9686. /**
  9687. * The index of the changed document in the result set immediately after
  9688. * this `DocumentChange` (i.e. supposing that all prior `DocumentChange`
  9689. * objects and the current `DocumentChange` object have been applied).
  9690. * Is -1 for 'removed' events.
  9691. */
  9692. readonly newIndex: number;
  9693. }
  9694. /**
  9695. * A `CollectionReference` object can be used for adding documents, getting
  9696. * document references, and querying for documents (using the methods
  9697. * inherited from `Query`).
  9698. */
  9699. export class CollectionReference<T = DocumentData> extends Query<T> {
  9700. private constructor();
  9701. /** The collection's identifier. */
  9702. readonly id: string;
  9703. /**
  9704. * A reference to the containing `DocumentReference` if this is a subcollection.
  9705. * If this isn't a subcollection, the reference is null.
  9706. */
  9707. readonly parent: DocumentReference<DocumentData> | null;
  9708. /**
  9709. * A string representing the path of the referenced collection (relative
  9710. * to the root of the database).
  9711. */
  9712. readonly path: string;
  9713. /**
  9714. * Get a `DocumentReference` for the document within the collection at the
  9715. * specified path. If no path is specified, an automatically-generated
  9716. * unique ID will be used for the returned DocumentReference.
  9717. *
  9718. * @param documentPath A slash-separated path to a document.
  9719. * @return The `DocumentReference` instance.
  9720. */
  9721. doc(documentPath?: string): DocumentReference<T>;
  9722. /**
  9723. * Add a new document to this collection with the specified data, assigning
  9724. * it a document ID automatically.
  9725. *
  9726. * @param data An Object containing the data for the new document.
  9727. * @return A Promise resolved with a `DocumentReference` pointing to the
  9728. * newly created document after it has been written to the backend.
  9729. */
  9730. add(data: T): Promise<DocumentReference<T>>;
  9731. /**
  9732. * Returns true if this `CollectionReference` is equal to the provided one.
  9733. *
  9734. * @param other The `CollectionReference` to compare against.
  9735. * @return true if this `CollectionReference` is equal to the provided one.
  9736. */
  9737. isEqual(other: CollectionReference<T>): boolean;
  9738. /**
  9739. * Applies a custom data converter to this CollectionReference, allowing you
  9740. * to use your own custom model objects with Firestore. When you call add()
  9741. * on the returned CollectionReference instance, the provided converter will
  9742. * convert between Firestore data and your custom type U.
  9743. *
  9744. * Passing in `null` as the converter parameter removes the current
  9745. * converter.
  9746. *
  9747. * @param converter Converts objects to and from Firestore. Passing in
  9748. * `null` removes the current converter.
  9749. * @return A CollectionReference<U> that uses the provided converter.
  9750. */
  9751. withConverter(converter: null): CollectionReference<DocumentData>;
  9752. /**
  9753. * Applies a custom data converter to this CollectionReference, allowing you
  9754. * to use your own custom model objects with Firestore. When you call add()
  9755. * on the returned CollectionReference instance, the provided converter will
  9756. * convert between Firestore data and your custom type U.
  9757. *
  9758. * Passing in `null` as the converter parameter removes the current
  9759. * converter.
  9760. *
  9761. * @param converter Converts objects to and from Firestore. Passing in
  9762. * `null` removes the current converter.
  9763. * @return A CollectionReference<U> that uses the provided converter.
  9764. */
  9765. withConverter<U>(
  9766. converter: FirestoreDataConverter<U>
  9767. ): CollectionReference<U>;
  9768. }
  9769. /**
  9770. * Sentinel values that can be used when writing document fields with `set()`
  9771. * or `update()`.
  9772. */
  9773. export class FieldValue {
  9774. private constructor();
  9775. /**
  9776. * Returns a sentinel used with `set()` or `update()` to include a
  9777. * server-generated timestamp in the written data.
  9778. */
  9779. static serverTimestamp(): FieldValue;
  9780. /**
  9781. * Returns a sentinel for use with `update()` to mark a field for deletion.
  9782. */
  9783. static delete(): FieldValue;
  9784. /**
  9785. * Returns a special value that can be used with `set()` or `update()` that tells
  9786. * the server to union the given elements with any array value that already
  9787. * exists on the server. Each specified element that doesn't already exist in
  9788. * the array will be added to the end. If the field being modified is not
  9789. * already an array it will be overwritten with an array containing exactly
  9790. * the specified elements.
  9791. *
  9792. * @param elements The elements to union into the array.
  9793. * @return The FieldValue sentinel for use in a call to `set()` or `update()`.
  9794. */
  9795. static arrayUnion(...elements: any[]): FieldValue;
  9796. /**
  9797. * Returns a special value that can be used with `set()` or `update()` that tells
  9798. * the server to remove the given elements from any array value that already
  9799. * exists on the server. All instances of each element specified will be
  9800. * removed from the array. If the field being modified is not already an
  9801. * array it will be overwritten with an empty array.
  9802. *
  9803. * @param elements The elements to remove from the array.
  9804. * @return The FieldValue sentinel for use in a call to `set()` or `update()`.
  9805. */
  9806. static arrayRemove(...elements: any[]): FieldValue;
  9807. /**
  9808. * Returns a special value that can be used with `set()` or `update()` that tells
  9809. * the server to increment the field's current value by the given value.
  9810. *
  9811. * If either the operand or the current field value uses floating point precision,
  9812. * all arithmetic follows IEEE 754 semantics. If both values are integers,
  9813. * values outside of JavaScript's safe number range (`Number.MIN_SAFE_INTEGER` to
  9814. * `Number.MAX_SAFE_INTEGER`) are also subject to precision loss. Furthermore,
  9815. * once processed by the Firestore backend, all integer operations are capped
  9816. * between -2^63 and 2^63-1.
  9817. *
  9818. * If the current field value is not of type `number`, or if the field does not
  9819. * yet exist, the transformation sets the field to the given value.
  9820. *
  9821. * @param n The value to increment by.
  9822. * @return The FieldValue sentinel for use in a call to `set()` or `update()`.
  9823. */
  9824. static increment(n: number): FieldValue;
  9825. /**
  9826. * Returns true if this `FieldValue` is equal to the provided one.
  9827. *
  9828. * @param other The `FieldValue` to compare against.
  9829. * @return true if this `FieldValue` is equal to the provided one.
  9830. */
  9831. isEqual(other: FieldValue): boolean;
  9832. }
  9833. /**
  9834. * A FieldPath refers to a field in a document. The path may consist of a
  9835. * single field name (referring to a top-level field in the document), or a
  9836. * list of field names (referring to a nested field in the document).
  9837. *
  9838. * Create a FieldPath by providing field names. If more than one field
  9839. * name is provided, the path will point to a nested field in a document.
  9840. *
  9841. */
  9842. export class FieldPath {
  9843. /**
  9844. * Creates a FieldPath from the provided field names. If more than one field
  9845. * name is provided, the path will point to a nested field in a document.
  9846. *
  9847. * @param fieldNames A list of field names.
  9848. */
  9849. constructor(...fieldNames: string[]);
  9850. /**
  9851. * Returns a special sentinel `FieldPath` to refer to the ID of a document.
  9852. * It can be used in queries to sort or filter by the document ID.
  9853. */
  9854. static documentId(): FieldPath;
  9855. /**
  9856. * Returns true if this `FieldPath` is equal to the provided one.
  9857. *
  9858. * @param other The `FieldPath` to compare against.
  9859. * @return true if this `FieldPath` is equal to the provided one.
  9860. */
  9861. isEqual(other: FieldPath): boolean;
  9862. }
  9863. /**
  9864. * The set of Firestore status codes. The codes are the same at the ones
  9865. * exposed by gRPC here:
  9866. * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
  9867. *
  9868. * Possible values:
  9869. * - 'cancelled': The operation was cancelled (typically by the caller).
  9870. * - 'unknown': Unknown error or an error from a different error domain.
  9871. * - 'invalid-argument': Client specified an invalid argument. Note that this
  9872. * differs from 'failed-precondition'. 'invalid-argument' indicates
  9873. * arguments that are problematic regardless of the state of the system
  9874. * (e.g. an invalid field name).
  9875. * - 'deadline-exceeded': Deadline expired before operation could complete.
  9876. * For operations that change the state of the system, this error may be
  9877. * returned even if the operation has completed successfully. For example,
  9878. * a successful response from a server could have been delayed long enough
  9879. * for the deadline to expire.
  9880. * - 'not-found': Some requested document was not found.
  9881. * - 'already-exists': Some document that we attempted to create already
  9882. * exists.
  9883. * - 'permission-denied': The caller does not have permission to execute the
  9884. * specified operation.
  9885. * - 'resource-exhausted': Some resource has been exhausted, perhaps a
  9886. * per-user quota, or perhaps the entire file system is out of space.
  9887. * - 'failed-precondition': Operation was rejected because the system is not
  9888. * in a state required for the operation's execution.
  9889. * - 'aborted': The operation was aborted, typically due to a concurrency
  9890. * issue like transaction aborts, etc.
  9891. * - 'out-of-range': Operation was attempted past the valid range.
  9892. * - 'unimplemented': Operation is not implemented or not supported/enabled.
  9893. * - 'internal': Internal errors. Means some invariants expected by
  9894. * underlying system has been broken. If you see one of these errors,
  9895. * something is very broken.
  9896. * - 'unavailable': The service is currently unavailable. This is most likely
  9897. * a transient condition and may be corrected by retrying with a backoff.
  9898. * - 'data-loss': Unrecoverable data loss or corruption.
  9899. * - 'unauthenticated': The request does not have valid authentication
  9900. * credentials for the operation.
  9901. */
  9902. export type FirestoreErrorCode =
  9903. | 'cancelled'
  9904. | 'unknown'
  9905. | 'invalid-argument'
  9906. | 'deadline-exceeded'
  9907. | 'not-found'
  9908. | 'already-exists'
  9909. | 'permission-denied'
  9910. | 'resource-exhausted'
  9911. | 'failed-precondition'
  9912. | 'aborted'
  9913. | 'out-of-range'
  9914. | 'unimplemented'
  9915. | 'internal'
  9916. | 'unavailable'
  9917. | 'data-loss'
  9918. | 'unauthenticated';
  9919. /** An error returned by a Firestore operation. */
  9920. // TODO(b/63008957): FirestoreError should extend firebase.FirebaseError
  9921. export interface FirestoreError {
  9922. code: FirestoreErrorCode;
  9923. message: string;
  9924. name: string;
  9925. stack?: string;
  9926. }
  9927. export type EmulatorMockTokenOptions = firebase.EmulatorMockTokenOptions;
  9928. }
  9929. export default firebase;
  9930. export as namespace firebase;