@dereekb/firebase-server 12.6.21 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/LICENSE +1 -1
  2. package/index.cjs.js +2937 -0
  3. package/index.esm.js +2775 -0
  4. package/mailgun/index.cjs.js +48 -0
  5. package/mailgun/index.esm.js +46 -0
  6. package/mailgun/package.json +26 -6
  7. package/model/index.cjs.js +5298 -0
  8. package/model/index.d.ts +1 -0
  9. package/model/index.esm.js +5161 -0
  10. package/model/package.json +31 -3
  11. package/model/src/lib/notification/notification.module.d.ts +10 -10
  12. package/model/src/lib/storagefile/storagefile.task.service.handler.d.ts +3 -14
  13. package/package.json +48 -27
  14. package/src/lib/auth/auth.context.d.ts +1 -1
  15. package/src/lib/auth/auth.service.d.ts +1 -1
  16. package/src/lib/function/assert.d.ts +2 -2
  17. package/src/lib/function/context.d.ts +1 -1
  18. package/src/lib/index.d.ts +1 -0
  19. package/src/lib/nest/app.d.ts +1 -1
  20. package/src/lib/nest/development/development.app.function.d.ts +1 -2
  21. package/src/lib/nest/function/call.d.ts +1 -1
  22. package/src/lib/nest/function/context.d.ts +0 -4
  23. package/src/lib/nest/function/index.d.ts +0 -1
  24. package/src/lib/nest/function/nest.d.ts +1 -1
  25. package/src/lib/nest/function/v2/blocking.d.ts +3 -2
  26. package/src/lib/nest/model/crud.assert.function.d.ts +0 -4
  27. package/src/lib/storage/storage.d.ts +1 -1
  28. package/src/lib/type.d.ts +9 -0
  29. package/test/index.cjs.js +1324 -0
  30. package/test/index.d.ts +1 -0
  31. package/test/index.esm.js +1247 -0
  32. package/test/package.json +34 -3
  33. package/test/src/lib/firebase/firebase.admin.auth.d.ts +22 -13
  34. package/test/src/lib/firebase/firebase.admin.collection.d.ts +6 -6
  35. package/test/src/lib/firebase/firebase.admin.d.ts +10 -10
  36. package/test/src/lib/firebase/firebase.admin.function.d.ts +9 -9
  37. package/test/src/lib/firebase/firebase.admin.nest.d.ts +8 -8
  38. package/test/src/lib/firebase/firebase.admin.nest.function.d.ts +9 -9
  39. package/test/src/lib/firebase/firebase.test.d.ts +30 -0
  40. package/test/src/lib/firebase/index.d.ts +1 -1
  41. package/test/src/lib/firestore/firestore.admin.d.ts +3 -3
  42. package/test/src/lib/firestore/firestore.d.ts +2 -2
  43. package/test/src/lib/storage/storage.admin.d.ts +3 -3
  44. package/test/src/lib/storage/storage.d.ts +2 -2
  45. package/zoho/LICENSE +1 -1
  46. package/zoho/index.d.ts +1 -0
  47. package/zoho/index.esm.js +2 -2
  48. package/zoho/package.json +12 -8
  49. package/CHANGELOG.md +0 -2233
  50. package/mailgun/src/index.js +0 -5
  51. package/mailgun/src/index.js.map +0 -1
  52. package/mailgun/src/lib/auth.mailgun.js +0 -41
  53. package/mailgun/src/lib/auth.mailgun.js.map +0 -1
  54. package/mailgun/src/lib/index.js +0 -5
  55. package/mailgun/src/lib/index.js.map +0 -1
  56. package/model/src/index.js +0 -5
  57. package/model/src/index.js.map +0 -1
  58. package/model/src/lib/index.js +0 -7
  59. package/model/src/lib/index.js.map +0 -1
  60. package/model/src/lib/mailgun/index.js +0 -5
  61. package/model/src/lib/mailgun/index.js.map +0 -1
  62. package/model/src/lib/mailgun/notification.send.service.mailgun.js +0 -68
  63. package/model/src/lib/mailgun/notification.send.service.mailgun.js.map +0 -1
  64. package/model/src/lib/notification/index.js +0 -20
  65. package/model/src/lib/notification/index.js.map +0 -1
  66. package/model/src/lib/notification/notification.action.init.service.js +0 -230
  67. package/model/src/lib/notification/notification.action.init.service.js.map +0 -1
  68. package/model/src/lib/notification/notification.action.service.js +0 -1487
  69. package/model/src/lib/notification/notification.action.service.js.map +0 -1
  70. package/model/src/lib/notification/notification.config.js +0 -13
  71. package/model/src/lib/notification/notification.config.js.map +0 -1
  72. package/model/src/lib/notification/notification.config.service.js +0 -60
  73. package/model/src/lib/notification/notification.config.service.js.map +0 -1
  74. package/model/src/lib/notification/notification.create.run.js +0 -59
  75. package/model/src/lib/notification/notification.create.run.js.map +0 -1
  76. package/model/src/lib/notification/notification.error.js +0 -87
  77. package/model/src/lib/notification/notification.error.js.map +0 -1
  78. package/model/src/lib/notification/notification.expedite.service.js +0 -112
  79. package/model/src/lib/notification/notification.expedite.service.js.map +0 -1
  80. package/model/src/lib/notification/notification.module.js +0 -106
  81. package/model/src/lib/notification/notification.module.js.map +0 -1
  82. package/model/src/lib/notification/notification.send.js +0 -3
  83. package/model/src/lib/notification/notification.send.js.map +0 -1
  84. package/model/src/lib/notification/notification.send.service.js +0 -10
  85. package/model/src/lib/notification/notification.send.service.js.map +0 -1
  86. package/model/src/lib/notification/notification.send.service.notificationsummary.js +0 -104
  87. package/model/src/lib/notification/notification.send.service.notificationsummary.js.map +0 -1
  88. package/model/src/lib/notification/notification.send.service.text.js +0 -29
  89. package/model/src/lib/notification/notification.send.service.text.js.map +0 -1
  90. package/model/src/lib/notification/notification.task.service.handler.js +0 -65
  91. package/model/src/lib/notification/notification.task.service.handler.js.map +0 -1
  92. package/model/src/lib/notification/notification.task.service.js +0 -10
  93. package/model/src/lib/notification/notification.task.service.js.map +0 -1
  94. package/model/src/lib/notification/notification.task.service.util.js +0 -27
  95. package/model/src/lib/notification/notification.task.service.util.js.map +0 -1
  96. package/model/src/lib/notification/notification.task.subtask.handler.js +0 -256
  97. package/model/src/lib/notification/notification.task.subtask.handler.js.map +0 -1
  98. package/model/src/lib/notification/notification.util.js +0 -478
  99. package/model/src/lib/notification/notification.util.js.map +0 -1
  100. package/model/src/lib/storagefile/index.js +0 -12
  101. package/model/src/lib/storagefile/index.js.map +0 -1
  102. package/model/src/lib/storagefile/storagefile.action.init.service.js +0 -155
  103. package/model/src/lib/storagefile/storagefile.action.init.service.js.map +0 -1
  104. package/model/src/lib/storagefile/storagefile.action.server.js +0 -797
  105. package/model/src/lib/storagefile/storagefile.action.server.js.map +0 -1
  106. package/model/src/lib/storagefile/storagefile.error.js +0 -106
  107. package/model/src/lib/storagefile/storagefile.error.js.map +0 -1
  108. package/model/src/lib/storagefile/storagefile.module.js +0 -64
  109. package/model/src/lib/storagefile/storagefile.module.js.map +0 -1
  110. package/model/src/lib/storagefile/storagefile.task.service.handler.js +0 -287
  111. package/model/src/lib/storagefile/storagefile.task.service.handler.js.map +0 -1
  112. package/model/src/lib/storagefile/storagefile.upload.service.initializer.js +0 -180
  113. package/model/src/lib/storagefile/storagefile.upload.service.initializer.js.map +0 -1
  114. package/model/src/lib/storagefile/storagefile.upload.service.js +0 -10
  115. package/model/src/lib/storagefile/storagefile.upload.service.js.map +0 -1
  116. package/model/src/lib/storagefile/storagefile.util.js +0 -54
  117. package/model/src/lib/storagefile/storagefile.util.js.map +0 -1
  118. package/src/index.js +0 -5
  119. package/src/index.js.map +0 -1
  120. package/src/lib/auth/auth.context.js +0 -13
  121. package/src/lib/auth/auth.context.js.map +0 -1
  122. package/src/lib/auth/auth.service.error.js +0 -34
  123. package/src/lib/auth/auth.service.error.js.map +0 -1
  124. package/src/lib/auth/auth.service.js +0 -427
  125. package/src/lib/auth/auth.service.js.map +0 -1
  126. package/src/lib/auth/auth.util.js +0 -23
  127. package/src/lib/auth/auth.util.js.map +0 -1
  128. package/src/lib/auth/index.js +0 -8
  129. package/src/lib/auth/index.js.map +0 -1
  130. package/src/lib/env/env.service.js +0 -7
  131. package/src/lib/env/env.service.js.map +0 -1
  132. package/src/lib/env/index.js +0 -5
  133. package/src/lib/env/index.js.map +0 -1
  134. package/src/lib/firestore/array.js +0 -34
  135. package/src/lib/firestore/array.js.map +0 -1
  136. package/src/lib/firestore/driver.accessor.batch.js +0 -93
  137. package/src/lib/firestore/driver.accessor.batch.js.map +0 -1
  138. package/src/lib/firestore/driver.accessor.default.js +0 -62
  139. package/src/lib/firestore/driver.accessor.default.js.map +0 -1
  140. package/src/lib/firestore/driver.accessor.js +0 -50
  141. package/src/lib/firestore/driver.accessor.js.map +0 -1
  142. package/src/lib/firestore/driver.accessor.transaction.js +0 -96
  143. package/src/lib/firestore/driver.accessor.transaction.js.map +0 -1
  144. package/src/lib/firestore/driver.js +0 -14
  145. package/src/lib/firestore/driver.js.map +0 -1
  146. package/src/lib/firestore/driver.query.js +0 -55
  147. package/src/lib/firestore/driver.query.js.map +0 -1
  148. package/src/lib/firestore/firestore.js +0 -10
  149. package/src/lib/firestore/firestore.js.map +0 -1
  150. package/src/lib/firestore/increment.js +0 -17
  151. package/src/lib/firestore/increment.js.map +0 -1
  152. package/src/lib/firestore/index.js +0 -9
  153. package/src/lib/firestore/index.js.map +0 -1
  154. package/src/lib/function/assert.js +0 -68
  155. package/src/lib/function/assert.js.map +0 -1
  156. package/src/lib/function/context.js +0 -14
  157. package/src/lib/function/context.js.map +0 -1
  158. package/src/lib/function/error.auth.js +0 -25
  159. package/src/lib/function/error.auth.js.map +0 -1
  160. package/src/lib/function/error.js +0 -221
  161. package/src/lib/function/error.js.map +0 -1
  162. package/src/lib/function/index.js +0 -9
  163. package/src/lib/function/index.js.map +0 -1
  164. package/src/lib/function/type.js +0 -3
  165. package/src/lib/function/type.js.map +0 -1
  166. package/src/lib/index.js +0 -11
  167. package/src/lib/index.js.map +0 -1
  168. package/src/lib/nest/app.js +0 -114
  169. package/src/lib/nest/app.js.map +0 -1
  170. package/src/lib/nest/auth/auth.module.js +0 -60
  171. package/src/lib/nest/auth/auth.module.js.map +0 -1
  172. package/src/lib/nest/auth/auth.util.js +0 -72
  173. package/src/lib/nest/auth/auth.util.js.map +0 -1
  174. package/src/lib/nest/auth/index.js +0 -6
  175. package/src/lib/nest/auth/index.js.map +0 -1
  176. package/src/lib/nest/development/development.app.function.js +0 -38
  177. package/src/lib/nest/development/development.app.function.js.map +0 -1
  178. package/src/lib/nest/development/development.assert.function.js +0 -3
  179. package/src/lib/nest/development/development.assert.function.js.map +0 -1
  180. package/src/lib/nest/development/development.function.js +0 -41
  181. package/src/lib/nest/development/development.function.js.map +0 -1
  182. package/src/lib/nest/development/development.schedule.function.error.js +0 -35
  183. package/src/lib/nest/development/development.schedule.function.error.js.map +0 -1
  184. package/src/lib/nest/development/development.schedule.function.js +0 -54
  185. package/src/lib/nest/development/development.schedule.function.js.map +0 -1
  186. package/src/lib/nest/development/index.js +0 -9
  187. package/src/lib/nest/development/index.js.map +0 -1
  188. package/src/lib/nest/env/env.service.js +0 -19
  189. package/src/lib/nest/env/env.service.js.map +0 -1
  190. package/src/lib/nest/env/env.util.js +0 -12
  191. package/src/lib/nest/env/env.util.js.map +0 -1
  192. package/src/lib/nest/env/index.js +0 -6
  193. package/src/lib/nest/env/index.js.map +0 -1
  194. package/src/lib/nest/firebase/firebase.module.js +0 -17
  195. package/src/lib/nest/firebase/firebase.module.js.map +0 -1
  196. package/src/lib/nest/firebase/index.js +0 -5
  197. package/src/lib/nest/firebase/index.js.map +0 -1
  198. package/src/lib/nest/firestore/firestore.module.js +0 -86
  199. package/src/lib/nest/firestore/firestore.module.js.map +0 -1
  200. package/src/lib/nest/firestore/index.js +0 -5
  201. package/src/lib/nest/firestore/index.js.map +0 -1
  202. package/src/lib/nest/function/call.js +0 -46
  203. package/src/lib/nest/function/call.js.map +0 -1
  204. package/src/lib/nest/function/context.js +0 -79
  205. package/src/lib/nest/function/context.js.map +0 -1
  206. package/src/lib/nest/function/index.js +0 -10
  207. package/src/lib/nest/function/index.js.map +0 -1
  208. package/src/lib/nest/function/nest.js +0 -17
  209. package/src/lib/nest/function/nest.js.map +0 -1
  210. package/src/lib/nest/function/schedule.js +0 -8
  211. package/src/lib/nest/function/schedule.js.map +0 -1
  212. package/src/lib/nest/function/v1/call.d.ts +0 -59
  213. package/src/lib/nest/function/v1/call.js +0 -55
  214. package/src/lib/nest/function/v1/call.js.map +0 -1
  215. package/src/lib/nest/function/v1/event.d.ts +0 -80
  216. package/src/lib/nest/function/v1/event.js +0 -52
  217. package/src/lib/nest/function/v1/event.js.map +0 -1
  218. package/src/lib/nest/function/v1/index.d.ts +0 -3
  219. package/src/lib/nest/function/v1/index.js +0 -7
  220. package/src/lib/nest/function/v1/index.js.map +0 -1
  221. package/src/lib/nest/function/v1/schedule.d.ts +0 -47
  222. package/src/lib/nest/function/v1/schedule.js +0 -68
  223. package/src/lib/nest/function/v1/schedule.js.map +0 -1
  224. package/src/lib/nest/function/v2/blocking.js +0 -38
  225. package/src/lib/nest/function/v2/blocking.js.map +0 -1
  226. package/src/lib/nest/function/v2/call.js +0 -31
  227. package/src/lib/nest/function/v2/call.js.map +0 -1
  228. package/src/lib/nest/function/v2/event.js +0 -25
  229. package/src/lib/nest/function/v2/event.js.map +0 -1
  230. package/src/lib/nest/function/v2/index.js +0 -9
  231. package/src/lib/nest/function/v2/index.js.map +0 -1
  232. package/src/lib/nest/function/v2/schedule.js +0 -56
  233. package/src/lib/nest/function/v2/schedule.js.map +0 -1
  234. package/src/lib/nest/function/v2/taskqueue.js +0 -26
  235. package/src/lib/nest/function/v2/taskqueue.js.map +0 -1
  236. package/src/lib/nest/index.js +0 -15
  237. package/src/lib/nest/index.js.map +0 -1
  238. package/src/lib/nest/middleware/appcheck.decorator.js +0 -12
  239. package/src/lib/nest/middleware/appcheck.decorator.js.map +0 -1
  240. package/src/lib/nest/middleware/appcheck.js +0 -3
  241. package/src/lib/nest/middleware/appcheck.js.map +0 -1
  242. package/src/lib/nest/middleware/appcheck.middleware.js +0 -74
  243. package/src/lib/nest/middleware/appcheck.middleware.js.map +0 -1
  244. package/src/lib/nest/middleware/appcheck.module.js +0 -21
  245. package/src/lib/nest/middleware/appcheck.module.js.map +0 -1
  246. package/src/lib/nest/middleware/globalprefix.js +0 -11
  247. package/src/lib/nest/middleware/globalprefix.js.map +0 -1
  248. package/src/lib/nest/middleware/index.js +0 -10
  249. package/src/lib/nest/middleware/index.js.map +0 -1
  250. package/src/lib/nest/middleware/rawbody.middleware.js +0 -16
  251. package/src/lib/nest/middleware/rawbody.middleware.js.map +0 -1
  252. package/src/lib/nest/middleware/webhook.js +0 -24
  253. package/src/lib/nest/middleware/webhook.js.map +0 -1
  254. package/src/lib/nest/model/call.model.function.js +0 -73
  255. package/src/lib/nest/model/call.model.function.js.map +0 -1
  256. package/src/lib/nest/model/create.model.function.js +0 -27
  257. package/src/lib/nest/model/create.model.function.js.map +0 -1
  258. package/src/lib/nest/model/crud.assert.function.js +0 -3
  259. package/src/lib/nest/model/crud.assert.function.js.map +0 -1
  260. package/src/lib/nest/model/delete.model.function.js +0 -27
  261. package/src/lib/nest/model/delete.model.function.js.map +0 -1
  262. package/src/lib/nest/model/index.js +0 -11
  263. package/src/lib/nest/model/index.js.map +0 -1
  264. package/src/lib/nest/model/permission.error.js +0 -24
  265. package/src/lib/nest/model/permission.error.js.map +0 -1
  266. package/src/lib/nest/model/read.model.function.js +0 -27
  267. package/src/lib/nest/model/read.model.function.js.map +0 -1
  268. package/src/lib/nest/model/specifier.function.js +0 -35
  269. package/src/lib/nest/model/specifier.function.js.map +0 -1
  270. package/src/lib/nest/model/update.model.function.js +0 -27
  271. package/src/lib/nest/model/update.model.function.js.map +0 -1
  272. package/src/lib/nest/nest.provider.js +0 -89
  273. package/src/lib/nest/nest.provider.js.map +0 -1
  274. package/src/lib/nest/storage/index.js +0 -5
  275. package/src/lib/nest/storage/index.js.map +0 -1
  276. package/src/lib/nest/storage/storage.module.js +0 -112
  277. package/src/lib/nest/storage/storage.module.js.map +0 -1
  278. package/src/lib/storage/driver.accessor.js +0 -299
  279. package/src/lib/storage/driver.accessor.js.map +0 -1
  280. package/src/lib/storage/driver.js +0 -12
  281. package/src/lib/storage/driver.js.map +0 -1
  282. package/src/lib/storage/index.js +0 -8
  283. package/src/lib/storage/index.js.map +0 -1
  284. package/src/lib/storage/storage.js +0 -20
  285. package/src/lib/storage/storage.js.map +0 -1
  286. package/src/lib/storage/storage.service.js +0 -26
  287. package/src/lib/storage/storage.service.js.map +0 -1
  288. package/test/src/index.js +0 -5
  289. package/test/src/index.js.map +0 -1
  290. package/test/src/lib/firebase/firebase.admin.auth.js +0 -260
  291. package/test/src/lib/firebase/firebase.admin.auth.js.map +0 -1
  292. package/test/src/lib/firebase/firebase.admin.collection.js +0 -108
  293. package/test/src/lib/firebase/firebase.admin.collection.js.map +0 -1
  294. package/test/src/lib/firebase/firebase.admin.function.js +0 -132
  295. package/test/src/lib/firebase/firebase.admin.function.js.map +0 -1
  296. package/test/src/lib/firebase/firebase.admin.js +0 -174
  297. package/test/src/lib/firebase/firebase.admin.js.map +0 -1
  298. package/test/src/lib/firebase/firebase.admin.nest.function.callable.context.js +0 -42
  299. package/test/src/lib/firebase/firebase.admin.nest.function.callable.context.js.map +0 -1
  300. package/test/src/lib/firebase/firebase.admin.nest.function.cloud.context.js +0 -40
  301. package/test/src/lib/firebase/firebase.admin.nest.function.cloud.context.js.map +0 -1
  302. package/test/src/lib/firebase/firebase.admin.nest.function.js +0 -64
  303. package/test/src/lib/firebase/firebase.admin.nest.function.js.map +0 -1
  304. package/test/src/lib/firebase/firebase.admin.nest.js +0 -107
  305. package/test/src/lib/firebase/firebase.admin.nest.js.map +0 -1
  306. package/test/src/lib/firebase/firebase.admin.test.server.js +0 -37
  307. package/test/src/lib/firebase/firebase.admin.test.server.js.map +0 -1
  308. package/test/src/lib/firebase/firebase.function.js +0 -58
  309. package/test/src/lib/firebase/firebase.function.js.map +0 -1
  310. package/test/src/lib/firebase/firebase.jest.d.ts +0 -21
  311. package/test/src/lib/firebase/firebase.jest.js +0 -45
  312. package/test/src/lib/firebase/firebase.jest.js.map +0 -1
  313. package/test/src/lib/firebase/firebase.js +0 -74
  314. package/test/src/lib/firebase/firebase.js.map +0 -1
  315. package/test/src/lib/firebase/index.js +0 -15
  316. package/test/src/lib/firebase/index.js.map +0 -1
  317. package/test/src/lib/firestore/firestore.admin.js +0 -21
  318. package/test/src/lib/firestore/firestore.admin.js.map +0 -1
  319. package/test/src/lib/firestore/firestore.js +0 -57
  320. package/test/src/lib/firestore/firestore.js.map +0 -1
  321. package/test/src/lib/firestore/index.js +0 -6
  322. package/test/src/lib/firestore/index.js.map +0 -1
  323. package/test/src/lib/index.js +0 -7
  324. package/test/src/lib/index.js.map +0 -1
  325. package/test/src/lib/storage/index.js +0 -6
  326. package/test/src/lib/storage/index.js.map +0 -1
  327. package/test/src/lib/storage/storage.admin.js +0 -21
  328. package/test/src/lib/storage/storage.admin.js.map +0 -1
  329. package/test/src/lib/storage/storage.js +0 -59
  330. package/test/src/lib/storage/storage.js.map +0 -1
  331. /package/{zoho/index.cjs.d.ts → index.d.ts} +0 -0
  332. /package/{zoho/index.esm.d.ts → mailgun/index.d.ts} +0 -0
@@ -0,0 +1,1247 @@
1
+ import 'core-js/modules/es.json.parse.js';
2
+ import 'core-js/modules/es.json.stringify.js';
3
+ import { randomEmailFactory, randomPhoneNumberFactory, mapGetter, incrementingNumberFactory, asGetter, getValueFromGetter, cachedGetter, asArray, mapObjectMap } from '@dereekb/util';
4
+ import { AbstractChildTestContextFixture, useTestContextFixture, testContextBuilder, AbstractTestContextFixture, useTestFunctionFixture, useTestFunctionMapFixture, ExpectedErrorOfSpecificTypeError } from '@dereekb/util/test';
5
+ import { decode } from 'jsonwebtoken';
6
+ import { flatFirestoreModelKey, twoWayFlatFirestoreModelKey, firestoreContextFactory, firebaseStorageContextFactory } from '@dereekb/firebase';
7
+ import admin from 'firebase-admin';
8
+ import functions from 'firebase-functions-test';
9
+ import { makeTestingFirestoreDrivers, TestFirestoreContextFixture, TestFirestoreInstance, makeTestingFirebaseStorageDrivers, TestFirebaseStorageContextFixture, TestFirebaseStorageInstance, mockItemFirestoreCollection, testWithMockItemCollectionFixture, testWithMockItemStorageFixture } from '@dereekb/firebase/test';
10
+ import { googleCloudFirestoreDrivers, googleCloudFirebaseStorageDrivers, googleCloudStorageFromFirebaseAdminStorage, DefaultFirebaseServerEnvService, FirebaseServerEnvService, firebaseServerAppTokenProvider, firebaseServerStorageDefaultBucketIdTokenProvider } from '@dereekb/firebase-server';
11
+ import { Firestore } from '@google-cloud/firestore';
12
+ import { Storage } from '@google-cloud/storage';
13
+ import 'core-js/modules/es.iterator.constructor.js';
14
+ import 'core-js/modules/es.iterator.for-each.js';
15
+ import { Test } from '@nestjs/testing';
16
+ import { serverEnvTokenProvider, ServerEnvironmentService } from '@dereekb/nestjs';
17
+ import { HttpsError } from 'firebase-functions/v1/https';
18
+ import { BaseError } from 'make-error';
19
+
20
+ class AuthorizedUserTestContextFixture extends AbstractChildTestContextFixture {
21
+ // MARK: AuthorizedUserTestContext (Forwarded)
22
+ get uid() {
23
+ return this.instance.uid;
24
+ }
25
+ loadUserRecord() {
26
+ return this.instance.loadUserRecord();
27
+ }
28
+ loadUserEmailAndPhone() {
29
+ return this.instance.loadUserEmailAndPhone();
30
+ }
31
+ loadIdToken() {
32
+ return this.instance.loadIdToken();
33
+ }
34
+ loadDecodedIdToken() {
35
+ return this.instance.loadDecodedIdToken();
36
+ }
37
+ makeContextOptions() {
38
+ return this.instance.makeContextOptions();
39
+ }
40
+ callWrappedFunction(fn, params, skipJsonConversion) {
41
+ return this.instance.callWrappedFunction(fn, params, skipJsonConversion);
42
+ }
43
+ callCloudFunction(fn, params, skipJsonConversion = false) {
44
+ return this.instance.callCloudFunction(fn, params, skipJsonConversion);
45
+ }
46
+ }
47
+ function convertParamsToParsedJsonObjectAndBack(object) {
48
+ const paramsAsJson = JSON.parse(JSON.stringify(object));
49
+ return paramsAsJson;
50
+ }
51
+ class AuthorizedUserTestContextInstance {
52
+ constructor(uid, testContext) {
53
+ this.uid = void 0;
54
+ this.testContext = void 0;
55
+ this.uid = uid;
56
+ this.testContext = testContext;
57
+ }
58
+ loadUserRecord() {
59
+ return this.testContext.auth.getUser(this.uid);
60
+ }
61
+ async loadUserEmailAndPhone() {
62
+ const record = await this.loadUserRecord();
63
+ return {
64
+ email: record.email,
65
+ phone: record.phoneNumber
66
+ };
67
+ }
68
+ loadIdToken() {
69
+ return this.loadUserRecord().then(record => createEncodedTestFirestoreTokenForUserRecord(this.testContext.auth, record));
70
+ }
71
+ loadDecodedIdToken() {
72
+ return this.loadIdToken().then(decodeEncodedCreateCustomTokenResult);
73
+ }
74
+ makeContextOptions() {
75
+ return this.loadUserRecord().then(record => createTestFunctionContextOptions(this.testContext.auth, record));
76
+ }
77
+ /**
78
+ * Calls a wrapped function with the input params and the context from makeContextOptions().
79
+ *
80
+ * @param fn
81
+ * @param params
82
+ * @param skipJsonConversion
83
+ */
84
+ callWrappedFunction(fn, params, skipJsonConversion) {
85
+ // Parse to JSON then back to simulate sending JSON to the server, and the server parsing it as a POJO.
86
+ const parsedParams = params == null || skipJsonConversion ? params : convertParamsToParsedJsonObjectAndBack(params);
87
+ return this.makeContextOptions().then(options => fn(parsedParams, options));
88
+ }
89
+ callCloudFunction(fn, params, skipJsonConversion = false) {
90
+ if (params != null && params.scheduleTime) {
91
+ // Workaround for https://github.com/firebase/firebase-functions-test/issues/210
92
+ const scheduleTime = params.scheduleTime;
93
+ delete params.scheduleTime;
94
+ params.timestamp = scheduleTime;
95
+ }
96
+ return this.callWrappedFunction(fn, params, skipJsonConversion);
97
+ }
98
+ /**
99
+ * Calls a wrapped gen 2 auth blocking function with the input params and context options from makeContextOptions().
100
+ *
101
+ * @param fn
102
+ * @param userRecord
103
+ * @param eventType
104
+ * @param eventOverride
105
+ * @param skipJsonConversion
106
+ * @returns
107
+ */
108
+ callAuthBlockingFunction(fn, userRecord, eventType, eventOverride, skipJsonConversion = false) {
109
+ const timestamp = new Date().toISOString();
110
+ const event = {
111
+ ipAddress: '127.0.0.1',
112
+ userAgent: 'testing',
113
+ eventId: '0',
114
+ params: {},
115
+ resource: {
116
+ service: 'dbx-test',
117
+ name: 'fake-resource'
118
+ },
119
+ timestamp,
120
+ ...eventOverride,
121
+ data: userRecord,
122
+ eventType
123
+ };
124
+ return this.callCloudFunction(fn, event, skipJsonConversion);
125
+ }
126
+ /**
127
+ * @deprecated gen 1
128
+ *
129
+ * @param fn
130
+ * @param params
131
+ * @param contextOptions
132
+ * @param skipJsonConversion
133
+ * @returns
134
+ */
135
+ callEventCloudFunction(fn, params, contextOptions, skipJsonConversion = false) {
136
+ const parsedParams = params == null || skipJsonConversion ? params : convertParamsToParsedJsonObjectAndBack(params);
137
+ return this.makeContextOptions().then(options => fn(parsedParams, contextOptions ? {
138
+ ...contextOptions,
139
+ ...options
140
+ } : options));
141
+ }
142
+ }
143
+ /**
144
+ * Convenience function for using authorizedUserContextFactory directly and passing buildTests.
145
+ */
146
+ function authorizedUserContext(config, buildTests) {
147
+ authorizedUserContextFactory(config)({
148
+ f: config.f
149
+ }, buildTests);
150
+ }
151
+ const AUTHORIZED_USER_RANDOM_EMAIL_FACTORY = randomEmailFactory();
152
+ const AUTHORIZED_USER_RANDOM_PHONE_NUMBER_FACTORY = randomPhoneNumberFactory();
153
+ /**
154
+ * Creates a new Jest Context that has a random user for authorization for use in firebase server tests.
155
+ */
156
+ function authorizedUserContextFactory(config) {
157
+ const {
158
+ uid: uidGetter,
159
+ makeInstance = (uid, testInstance) => new AuthorizedUserTestContextInstance(uid, testInstance),
160
+ makeFixture = f => new AuthorizedUserTestContextFixture(f),
161
+ makeUserDetails = () => ({}),
162
+ initUser
163
+ } = config;
164
+ const makeUid = uidGetter ? asGetter(uidGetter) : testUidFactory;
165
+ return (params, buildTests) => {
166
+ const {
167
+ f,
168
+ user: inputUserGetterOrValue,
169
+ addContactInfo: inputAddContactInfoGetterOrValue,
170
+ template: inputTemplateGetterOrValue
171
+ } = params;
172
+ const inputAddContactInfoGetter = asGetter(inputAddContactInfoGetterOrValue);
173
+ const inputUserGetter = asGetter(inputUserGetterOrValue);
174
+ const templateGetter = asGetter(inputTemplateGetterOrValue);
175
+ return useTestContextFixture({
176
+ fixture: makeFixture(f),
177
+ buildTests,
178
+ initInstance: async () => {
179
+ const inputAddContactInfo = await inputAddContactInfoGetter();
180
+ const inputUser = await inputUserGetter();
181
+ const inputTemplate = await templateGetter();
182
+ const uid = inputUser?.uid || makeUid();
183
+ const {
184
+ details,
185
+ claims,
186
+ addContactInfo: userDetailsAddContactInfo
187
+ } = {
188
+ ...makeUserDetails(uid, params),
189
+ ...inputTemplate
190
+ };
191
+ const {
192
+ phoneNumber: detailsPhoneNumber,
193
+ email: detailsEmail
194
+ } = details ?? {}; // keep details if provided
195
+ const addContactInfo = inputAddContactInfo || userDetailsAddContactInfo;
196
+ const auth = f.instance.auth;
197
+ let email;
198
+ let phoneNumber;
199
+ if (addContactInfo) {
200
+ email = detailsEmail ?? AUTHORIZED_USER_RANDOM_EMAIL_FACTORY();
201
+ phoneNumber = detailsPhoneNumber ?? AUTHORIZED_USER_RANDOM_PHONE_NUMBER_FACTORY();
202
+ } else {
203
+ email = detailsEmail;
204
+ phoneNumber = detailsPhoneNumber ?? undefined;
205
+ }
206
+ const userRecord = await auth.createUser({
207
+ uid,
208
+ displayName: 'Test Person',
209
+ ...details,
210
+ email,
211
+ phoneNumber,
212
+ ...inputUser
213
+ });
214
+ if (claims) {
215
+ await auth.setCustomUserClaims(uid, claims);
216
+ }
217
+ const instance = await makeInstance(uid, f.instance, params, userRecord);
218
+ if (initUser) {
219
+ await initUser(instance, params);
220
+ }
221
+ return instance;
222
+ },
223
+ destroyInstance: async instance => {
224
+ const app = instance.testContext.app;
225
+ const uid = instance.uid;
226
+ await app.auth().deleteUser(uid);
227
+ }
228
+ });
229
+ };
230
+ }
231
+ /**
232
+ * Incrementing number factory for generating test UID values.
233
+ *
234
+ * Has the format 'test-uid-<number>'
235
+ */
236
+ const testUidFactory = mapGetter(incrementingNumberFactory(), i => `${new Date().getTime()}0${i}`);
237
+ /**
238
+ * Creates a CallableContextOptions with auth attached corresponding to the input UserRecord.
239
+ *
240
+ * @param auth
241
+ * @param userRecord
242
+ * @returns
243
+ */
244
+ async function createTestFunctionContextOptions(auth, userRecord) {
245
+ const authData = await createTestFunctionContextAuthData(auth, userRecord);
246
+ const contextOptions = {
247
+ auth: authData
248
+ };
249
+ return contextOptions;
250
+ }
251
+ /**
252
+ * Creates AuthData from the input auth and user record.
253
+ *
254
+ * @param auth
255
+ * @param userRecord
256
+ * @returns
257
+ */
258
+ async function createTestFunctionContextAuthData(auth, userRecord) {
259
+ const token = await createTestFirestoreTokenForUserRecord(auth, userRecord);
260
+ const authData = {
261
+ uid: token.uid,
262
+ token,
263
+ rawToken: ''
264
+ };
265
+ return authData;
266
+ }
267
+ /**
268
+ * Creates and decodes a firestore token used for testing.
269
+ *
270
+ * @param auth
271
+ * @param userRecord
272
+ * @returns
273
+ */
274
+ function createTestFirestoreTokenForUserRecord(auth, userRecord) {
275
+ return createEncodedTestFirestoreTokenForUserRecord(auth, userRecord).then(decodeEncodedCreateCustomTokenResult);
276
+ }
277
+ /**
278
+ * Creates an encoded firestore token used for testing.
279
+ *
280
+ * @param auth
281
+ * @param userRecord
282
+ * @returns
283
+ */
284
+ function createEncodedTestFirestoreTokenForUserRecord(auth, userRecord) {
285
+ // TODO: Consider replacing createCustomToken, as the custom claims are put into an object called claims in the JWT, instead of spread over. The decodeEncodedCreateCustomTokenResult() function handles this issue, but it may not be expected.
286
+ return auth.createCustomToken(userRecord.uid, testFirestoreClaimsFromUserRecord(userRecord));
287
+ }
288
+ function decodeEncodedCreateCustomTokenResult(token) {
289
+ const decoded = decode(token);
290
+ const decodedToken = {
291
+ ...decoded,
292
+ ...decoded.claims,
293
+ auth_time: decoded.iat,
294
+ firebase: decoded.claims?.firebase ?? {}
295
+ };
296
+ delete decodedToken.claims; // remove the "claims" item if it exists.
297
+ return decodedToken;
298
+ }
299
+ function testFirestoreClaimsFromUserRecord(userRecord) {
300
+ // Copy claims to be similar to DecodedIdToken pieces.
301
+ const baseClaims = {
302
+ picture: userRecord.photoURL,
303
+ email: userRecord.email,
304
+ email_verified: userRecord.emailVerified ?? false,
305
+ firebase: {
306
+ sign_in_provider: '@dereekb/firebase-server/test',
307
+ identities: []
308
+ }
309
+ };
310
+ const customClaims = userRecord.customClaims;
311
+ const claims = {
312
+ ...customClaims,
313
+ ...baseClaims
314
+ };
315
+ return claims;
316
+ }
317
+
318
+ class ModelTestContextFixture extends AbstractChildTestContextFixture {
319
+ // MARK: ModelTestContext (Forwarded)
320
+ get documentId() {
321
+ return this.instance.documentId;
322
+ }
323
+ get documentKey() {
324
+ return this.instance.documentKey;
325
+ }
326
+ get documentFlatKey() {
327
+ return this.instance.documentFlatKey;
328
+ }
329
+ get documentTwoWayFlatKey() {
330
+ return this.instance.documentTwoWayFlatKey;
331
+ }
332
+ get documentRef() {
333
+ return this.instance.documentRef;
334
+ }
335
+ get document() {
336
+ return this.instance.document;
337
+ }
338
+ }
339
+ class ModelTestContextInstance {
340
+ constructor(collection, ref, testContext) {
341
+ this.collection = void 0;
342
+ this.ref = void 0;
343
+ this.testContext = void 0;
344
+ this.collection = collection;
345
+ this.ref = ref;
346
+ this.testContext = testContext;
347
+ }
348
+ get documentId() {
349
+ return this.ref.id;
350
+ }
351
+ get documentKey() {
352
+ return this.ref.path;
353
+ }
354
+ get documentFlatKey() {
355
+ return flatFirestoreModelKey(this.documentKey);
356
+ }
357
+ get documentTwoWayFlatKey() {
358
+ return twoWayFlatFirestoreModelKey(this.documentKey);
359
+ }
360
+ get documentRef() {
361
+ return this.ref;
362
+ }
363
+ get document() {
364
+ return this.collection.documentAccessor().loadDocument(this.ref);
365
+ }
366
+ }
367
+ /**
368
+ * Creates a new Test Context that has a random user for authorization for use in firebase server tests.
369
+ */
370
+ function modelTestContextFactory(config) {
371
+ const {
372
+ getCollection,
373
+ collectionForDocument,
374
+ makeRef = collection => {
375
+ const accessor = collection.documentAccessor();
376
+ if (accessor.newDocument == null) {
377
+ throw new Error('collection passed to makeRef() was not a full FirestoreCollection. Either supply a custom makeRef() function or a FirestoreCollection that has newDocument() available on the documentAccessor.');
378
+ }
379
+ return accessor.newDocument().documentRef;
380
+ },
381
+ makeInstance = (collection, ref, testInstance) => new ModelTestContextInstance(collection, ref, testInstance),
382
+ makeFixture = f => new ModelTestContextFixture(f),
383
+ initDocument,
384
+ destroyInstance
385
+ } = config;
386
+ return (params, buildTests) => {
387
+ const {
388
+ f
389
+ } = params;
390
+ return useTestContextFixture({
391
+ fixture: makeFixture(f),
392
+ buildTests,
393
+ initInstance: async () => {
394
+ const parentInstance = f.instance;
395
+ let ref;
396
+ let collection;
397
+ let init;
398
+ if (params.doc) {
399
+ const doc = await getValueFromGetter(params.doc);
400
+ if (!collectionForDocument) {
401
+ throw new Error('collectionForDocument() is required when using ModelTestContextDocumentRefParams values as input.');
402
+ }
403
+ collection = collectionForDocument(parentInstance, doc);
404
+ const expectedCollectionName = collection.documentAccessor().modelIdentity.collectionName;
405
+ if (expectedCollectionName !== doc.modelIdentity.collectionName) {
406
+ throw new Error(`Input doc is in a different collection (${doc.modelIdentity.collectionName}) than expected (${expectedCollectionName}).`);
407
+ }
408
+ ref = doc.documentRef;
409
+ init = false;
410
+ } else {
411
+ collection = getCollection(parentInstance, params);
412
+ ref = await makeRef(collection, params, parentInstance);
413
+ init = true;
414
+ }
415
+ const instance = await makeInstance(collection, ref, parentInstance);
416
+ if (init && initDocument) {
417
+ await initDocument(instance, params);
418
+ }
419
+ return instance;
420
+ },
421
+ destroyInstance
422
+ });
423
+ };
424
+ }
425
+
426
+ let adminEnvironmentInitialized = false;
427
+ function isAdminEnvironmentInitialized() {
428
+ return adminEnvironmentInitialized;
429
+ }
430
+ function generateNewProjectId() {
431
+ const projectId = 'firebase-test-' + new Date().getTime();
432
+ return projectId;
433
+ }
434
+ function rollNewGCloudProjectEnvironmentVariable() {
435
+ const projectId = generateNewProjectId();
436
+ process.env.GCLOUD_TEST_PROJECT = projectId;
437
+ process.env.GCLOUD_PROJECT = projectId;
438
+ applyFirebaseGCloudTestProjectIdToFirebaseConfigEnv();
439
+ return projectId;
440
+ }
441
+ function getGCloudProjectId() {
442
+ return process.env.GCLOUD_PROJECT;
443
+ }
444
+ function getGCloudTestProjectId() {
445
+ return process.env.GCLOUD_TEST_PROJECT;
446
+ }
447
+ /**
448
+ * Applies the current GCLOUD_PROJECT to FIREBASE_CONFIG.
449
+ *
450
+ * This is done as some external testing libraries (firebase-functions-test) will overwrite but we want to enforce using our project id
451
+ * so that each component can also
452
+ */
453
+ function applyFirebaseGCloudTestProjectIdToFirebaseConfigEnv() {
454
+ // firebase-functions-test overwrites this each time.
455
+ // https://github.com/firebase/firebase-functions-test/blob/acb068f4c086f3355b2960b9e9e5895716c7f8cc/src/lifecycle.ts#L37
456
+ const testProjectId = getGCloudTestProjectId();
457
+ // console.log('Test project: ', testProjectId);
458
+ if (!testProjectId) {
459
+ throw new Error('No test project id was available in the environment. Did you call initFirebaseAdminTestEnvironment() first?');
460
+ }
461
+ const config = JSON.parse(process.env.FIREBASE_CONFIG ?? '{}');
462
+ config.projectId = testProjectId;
463
+ process.env.FIREBASE_CONFIG = JSON.stringify(config);
464
+ process.env.GCLOUD_PROJECT = testProjectId; // re-apply to GCLOUD_PROJECT too
465
+ return testProjectId;
466
+ }
467
+ /**
468
+ * Should be called before calling/using adminFirebaseTestBuilder(). This should only be called once.
469
+ */
470
+ function initFirebaseAdminTestEnvironment(config) {
471
+ function crashForEmulator(emulator) {
472
+ throw new Error(`Emulator for ${emulator} was not set null or to a host. Crashing to prevent contamination.`);
473
+ }
474
+ function configureEmulator(emulator, envKey) {
475
+ const emulatorConfig = config.emulators[emulator];
476
+ if (emulatorConfig) {
477
+ process.env[envKey] = emulatorConfig;
478
+ } else if (config.emulators.firestore !== null) {
479
+ crashForEmulator(emulator);
480
+ }
481
+ }
482
+ rollNewGCloudProjectEnvironmentVariable();
483
+ configureEmulator('auth', 'FIREBASE_AUTH_EMULATOR_HOST');
484
+ configureEmulator('firestore', 'FIRESTORE_EMULATOR_HOST');
485
+ configureEmulator('storage', 'FIREBASE_STORAGE_EMULATOR_HOST');
486
+ applyFirebaseGCloudTestProjectIdToFirebaseConfigEnv();
487
+ adminEnvironmentInitialized = true;
488
+ }
489
+
490
+ function makeGoogleFirestoreContext(drivers, firestore) {
491
+ const context = firestoreContextFactory(drivers)(firestore);
492
+ context.drivers = drivers;
493
+ return context;
494
+ }
495
+ class GoogleCloudTestFirestoreInstance extends TestFirestoreInstance {
496
+ constructor(drivers, firestore) {
497
+ super(makeGoogleFirestoreContext(drivers, firestore));
498
+ }
499
+ }
500
+ class GoogleCloudTestFirestoreContextFixture extends TestFirestoreContextFixture {}
501
+ let COUNTER$1 = 0;
502
+ /**
503
+ * A TestContextBuilderFunction for building firestore test context factories using @google-cloud/firestore. This means SERVER TESTING ONLY. For client testing, look at @dereekb/firestore.
504
+ *
505
+ * This is used to build a @google-cloud/firestore Firestore instance for testing and point it to the emulators.
506
+ *
507
+ * If you need all of Firebase (firebase-admin library), look at adminFirebaseAdminTestBuilder() instead.
508
+ */
509
+ const googleCloudTestFirestoreBuilder = testContextBuilder({
510
+ buildConfig: input => {
511
+ const config = {
512
+ host: input?.host ?? 'localhost',
513
+ port: input?.port ?? 0
514
+ };
515
+ return config;
516
+ },
517
+ buildFixture: () => new GoogleCloudTestFirestoreContextFixture(),
518
+ setupInstance: async config => {
519
+ const random = Math.floor(Math.random() * 10000);
520
+ const drivers = makeTestingFirestoreDrivers(googleCloudFirestoreDrivers());
521
+ const projectId = `test-${COUNTER$1++}-${Date.now()}-${random}`.substring(0, 30);
522
+ const firestore = new Firestore({
523
+ projectId,
524
+ host: config.host,
525
+ port: config.port,
526
+ maxIdleChannels: 0
527
+ });
528
+ return new GoogleCloudTestFirestoreInstance(drivers, firestore);
529
+ },
530
+ teardownInstance: async (instance, config) => {
531
+ await instance.firestore.terminate();
532
+ }
533
+ });
534
+
535
+ function makeGoogleFirebaseStorageContext(drivers, firebaseStorage, defaultBucketId) {
536
+ const context = firebaseStorageContextFactory(drivers)(firebaseStorage, {
537
+ defaultBucketId
538
+ });
539
+ context.drivers = drivers;
540
+ return context;
541
+ }
542
+ class GoogleCloudTestFirebaseStorageInstance extends TestFirebaseStorageInstance {
543
+ constructor(drivers, firebaseStorage, defaultBucketId) {
544
+ super(makeGoogleFirebaseStorageContext(drivers, firebaseStorage, defaultBucketId));
545
+ }
546
+ }
547
+ class GoogleCloudTestFirebaseStorageContextFixture extends TestFirebaseStorageContextFixture {}
548
+ let COUNTER = 0;
549
+ /**
550
+ * A TestContextBuilderFunction for building firebase storage test context factories using @google-cloud/storage. This means SERVER TESTING ONLY. For client testing, look at @dereekb/firestore.
551
+ *
552
+ * This is used to build a @google-cloud/storage FirebaseStorage instance for testing and point it to the emulators.
553
+ *
554
+ * If you need all of Firebase (firebase-admin library), look at adminFirebaseAdminTestBuilder() instead.
555
+ */
556
+ const googleCloudTestFirebaseStorageBuilder = testContextBuilder({
557
+ buildConfig: input => {
558
+ const config = {
559
+ host: input?.host ?? 'localhost',
560
+ port: input?.port ?? 0
561
+ };
562
+ if (!config.port) {
563
+ throw new Error('Port for host is required.');
564
+ }
565
+ return config;
566
+ },
567
+ buildFixture: () => new GoogleCloudTestFirebaseStorageContextFixture(),
568
+ setupInstance: async config => {
569
+ const drivers = makeTestingFirebaseStorageDrivers(googleCloudFirebaseStorageDrivers());
570
+ const projectId = `firebase-storage-server-test-${new Date().getTime()}-${COUNTER++}`;
571
+ const firebaseStorage = new Storage({
572
+ projectId,
573
+ // ensure http:// is provided so the library doesn't default to/try https://
574
+ apiEndpoint: `http://${config.host}:${config.port}`
575
+ });
576
+ const defaultBucketId = projectId;
577
+ return new GoogleCloudTestFirebaseStorageInstance(drivers, firebaseStorage, defaultBucketId);
578
+ },
579
+ teardownInstance: async (instance, config) => {
580
+ // nothing to teardown
581
+ }
582
+ });
583
+
584
+ class FirebaseAdminTestContextFixture extends AbstractTestContextFixture {
585
+ // MARK: FirebaseAdminTestContext (Forwarded)
586
+ get app() {
587
+ return this.instance.app;
588
+ }
589
+ get auth() {
590
+ return this.instance.auth;
591
+ }
592
+ get firestore() {
593
+ return this.instance.firestore;
594
+ }
595
+ get firestoreInstance() {
596
+ return this.instance.firestoreInstance;
597
+ }
598
+ get firestoreContext() {
599
+ return this.instance.firestoreContext;
600
+ }
601
+ get storage() {
602
+ return this.instance.storage;
603
+ }
604
+ get storageInstance() {
605
+ return this.instance.storageInstance;
606
+ }
607
+ get storageContext() {
608
+ return this.instance.storageContext;
609
+ }
610
+ get fnWrapper() {
611
+ return this.instance.fnWrapper;
612
+ }
613
+ }
614
+ // MARK: FirebaseAdminTestBuilder
615
+ class FirebaseAdminTestContextInstance {
616
+ constructor(app) {
617
+ this.app = void 0;
618
+ this.getTestFirestoreInstance = cachedGetter(() => {
619
+ const drivers = makeTestingFirestoreDrivers(googleCloudFirestoreDrivers());
620
+ return new GoogleCloudTestFirestoreInstance(drivers, this.firestore);
621
+ });
622
+ this.getTestFirebaseStorageInstance = cachedGetter(() => {
623
+ const drivers = makeTestingFirebaseStorageDrivers(googleCloudFirebaseStorageDrivers());
624
+ const defaultBucketId = this.app.options.storageBucket;
625
+ return new GoogleCloudTestFirebaseStorageInstance(drivers, this.storage, defaultBucketId);
626
+ });
627
+ this.app = app;
628
+ }
629
+ get auth() {
630
+ return this.app.auth();
631
+ }
632
+ get firestore() {
633
+ return this.app.firestore();
634
+ }
635
+ get firestoreInstance() {
636
+ return this.getTestFirestoreInstance();
637
+ }
638
+ get firestoreContext() {
639
+ return this.firestoreInstance.firestoreContext;
640
+ }
641
+ get storage() {
642
+ return googleCloudStorageFromFirebaseAdminStorage(this.app.storage());
643
+ }
644
+ get storageInstance() {
645
+ return this.getTestFirebaseStorageInstance();
646
+ }
647
+ get storageContext() {
648
+ return this.storageInstance.storageContext;
649
+ }
650
+ get fnWrapper() {
651
+ throw new Error('wrapCloudFunction is unsupported by this type.');
652
+ }
653
+ }
654
+ class AbstractFirebaseAdminTestContextInstanceChild {
655
+ constructor(parent) {
656
+ this.parent = void 0;
657
+ this.parent = parent;
658
+ }
659
+ // MARK: FirebaseAdminTestContext (Forwarded)
660
+ get app() {
661
+ return this.parent.app;
662
+ }
663
+ get auth() {
664
+ return this.parent.auth;
665
+ }
666
+ get firestore() {
667
+ return this.parent.firestore;
668
+ }
669
+ get firestoreInstance() {
670
+ return this.parent.firestoreInstance;
671
+ }
672
+ get firestoreContext() {
673
+ return this.parent.firestoreContext;
674
+ }
675
+ get storage() {
676
+ return this.parent.storage;
677
+ }
678
+ get storageInstance() {
679
+ return this.parent.storageInstance;
680
+ }
681
+ get storageContext() {
682
+ return this.parent.storageContext;
683
+ }
684
+ get fnWrapper() {
685
+ return this.parent.fnWrapper;
686
+ }
687
+ }
688
+ /**
689
+ * A TestContextBuilderFunction for building firebase test context factories using firebase-admin.
690
+ *
691
+ * This can be used to easily build a testing context that sets up RulesTestEnvironment for tests that sets itself up and tears itself down.
692
+ */
693
+ const firebaseAdminTestBuilder = testContextBuilder({
694
+ buildConfig: input => {
695
+ const config = {
696
+ ...input
697
+ };
698
+ return config;
699
+ },
700
+ buildFixture: () => new FirebaseAdminTestContextFixture(),
701
+ setupInstance: async config => {
702
+ if (!isAdminEnvironmentInitialized()) {
703
+ throw new Error('Call initFirebaseAdminTestEnvironment() from @dereekb/firebase-server was not called before using adminFirebaseTestBuilder().');
704
+ }
705
+ const projectId = generateNewProjectId();
706
+ const storageBucket = 'b-' + projectId;
707
+ const app = admin.initializeApp({
708
+ projectId,
709
+ storageBucket
710
+ });
711
+ return new FirebaseAdminTestContextInstance(app);
712
+ },
713
+ teardownInstance: async (instance, config) => {
714
+ await instance.app.delete(); // clean up the instance
715
+ }
716
+ });
717
+ const firebaseAdminTestContextFactory = firebaseAdminTestBuilder({});
718
+ // MARK: Firestore Context
719
+ /**
720
+ * Convenience function to build a TestFirestoreContextFactory from a FirebaseAdminTestContextFactory.
721
+ *
722
+ * This is useful for composing child tests that will benefit from the firestore testing context, but want the full app available.
723
+ *
724
+ * @param factory
725
+ * @returns
726
+ */
727
+ function firebaseAdminFirestoreContextFixture(factory) {
728
+ return buildTests => {
729
+ factory(f => firebaseAdminFirestoreContextWithFixture(f, buildTests));
730
+ };
731
+ }
732
+ function firebaseAdminFirestoreContextWithFixture(f, buildTests) {
733
+ useTestContextFixture({
734
+ fixture: new TestFirestoreContextFixture(),
735
+ /**
736
+ * Build tests by passing the fixture to the testing functions.
737
+ *
738
+ * This will inject all tests and sub testing lifecycle items.
739
+ */
740
+ buildTests,
741
+ initInstance: () => f.instance.getTestFirestoreInstance()
742
+ });
743
+ }
744
+
745
+ function firebaseAdminCloudFunctionWrapper(instance) {
746
+ const wrapV1CloudFunction = x => {
747
+ return instance.wrap(x);
748
+ };
749
+ const wrapV2CallableRequest = x => {
750
+ const wrappedCloudFunction = instance.wrap(x);
751
+ // context is marked optional here to better match the gen 1 callable function signature
752
+ return async (data, context) => {
753
+ const request = {
754
+ ...context,
755
+ data,
756
+ // NOTE: These will typically not be used/available as they are express.js properties that are not available or useful to the handlers
757
+ rawRequest: context?.rawRequest ?? {},
758
+ acceptsStreaming: false
759
+ };
760
+ const result = await wrappedCloudFunction(request);
761
+ return result;
762
+ };
763
+ };
764
+ const wrapV2CloudFunction = x => {
765
+ return instance.wrap(x);
766
+ };
767
+ const wrapBlockingFunction = blockingFunction => {
768
+ return instance.wrap(blockingFunction);
769
+ };
770
+ const wrapCloudFunction = x => {
771
+ return instance.wrap(x);
772
+ };
773
+ const wrapper = {
774
+ wrapV1CloudFunction,
775
+ wrapV2CloudFunction,
776
+ wrapV2CallableRequest,
777
+ wrapCallableRequest: wrapV2CallableRequest,
778
+ wrapBlockingFunction,
779
+ wrapCloudFunction
780
+ };
781
+ return wrapper;
782
+ }
783
+ function wrapCloudFunctionV1ForTests(wrapper, getter) {
784
+ return () => wrapper.wrapV1CloudFunction(getter());
785
+ }
786
+ function wrapCallableRequestForTests(wrapper, getter) {
787
+ return () => wrapper.wrapCallableRequest(getter());
788
+ }
789
+
790
+ // MARK: FirebaseAdminFunctionTestBuilder
791
+ let functionsInitialized = false;
792
+ /**
793
+ * firebase-functions-test uses a singleton internally, so we must track the reference to properly tear it down too.
794
+ */
795
+ let firebaseFunctionsTestInstance;
796
+ function setupFirebaseAdminFunctionTestSingleton(reroll = false) {
797
+ if (!isAdminEnvironmentInitialized()) {
798
+ throw new Error('initFirebaseAdminTestEnvironment() was not called.');
799
+ }
800
+ if (firebaseFunctionsTestInstance) {
801
+ firebaseFunctionsTestInstance.cleanup(); // destroy the old instance if it is up.
802
+ }
803
+ firebaseFunctionsTestInstance = functions();
804
+ if (reroll) {
805
+ rollNewGCloudProjectEnvironmentVariable();
806
+ } else {
807
+ applyFirebaseGCloudTestProjectIdToFirebaseConfigEnv();
808
+ }
809
+ functionsInitialized = true;
810
+ return firebaseFunctionsTestInstance;
811
+ }
812
+ function rerollFirebaseAdminFunctionTestSingleton() {
813
+ return setupFirebaseAdminFunctionTestSingleton(true);
814
+ }
815
+ class FirebaseAdminFunctionTestContextFixture extends AbstractTestContextFixture {
816
+ // MARK: FirebaseAdminTestContext (Forwarded)
817
+ get app() {
818
+ return this.instance.app;
819
+ }
820
+ get auth() {
821
+ return this.instance.auth;
822
+ }
823
+ get firestore() {
824
+ return this.instance.firestore;
825
+ }
826
+ get firestoreInstance() {
827
+ return this.instance.firestoreInstance;
828
+ }
829
+ get firestoreContext() {
830
+ return this.instance.firestoreContext;
831
+ }
832
+ get storage() {
833
+ return this.instance.storage;
834
+ }
835
+ get storageInstance() {
836
+ return this.instance.storageInstance;
837
+ }
838
+ get storageContext() {
839
+ return this.instance.storageContext;
840
+ }
841
+ get fnWrapper() {
842
+ return this.instance.fnWrapper;
843
+ }
844
+ }
845
+ class FirebaseAdminFunctionTestContextInstance extends FirebaseAdminTestContextInstance {
846
+ constructor(instance, app) {
847
+ super(app);
848
+ this.instance = void 0;
849
+ this._fnWrapper = cachedGetter(() => firebaseAdminCloudFunctionWrapper(this.instance));
850
+ this.instance = instance;
851
+ }
852
+ get fnWrapper() {
853
+ return this._fnWrapper();
854
+ }
855
+ }
856
+ let DEFAULT_FIREBASE_ADMIN_FUNCTION_TEST_USE_FUNCTION_SINGLETON_CONTEXT = false;
857
+ function setDefaultFirebaseAdminFunctionTestUseFunctionSingleton(use) {
858
+ DEFAULT_FIREBASE_ADMIN_FUNCTION_TEST_USE_FUNCTION_SINGLETON_CONTEXT = use;
859
+ }
860
+ /**
861
+ * A TestContextBuilderFunction for building firebase test context factories using firebase-admin.
862
+ *
863
+ * This can be used to easily build a testing context that sets up RulesTestEnvironment for tests that sets itself up and tears itself down.
864
+ */
865
+ const firebaseAdminFunctionTestBuilder = testContextBuilder({
866
+ buildConfig: input => {
867
+ const config = {
868
+ ...input,
869
+ useFunctionSingletonContext: input?.useFunctionSingletonContext ?? DEFAULT_FIREBASE_ADMIN_FUNCTION_TEST_USE_FUNCTION_SINGLETON_CONTEXT
870
+ };
871
+ return config;
872
+ },
873
+ buildFixture: () => new FirebaseAdminFunctionTestContextFixture(),
874
+ setupInstance: async config => {
875
+ if (!isAdminEnvironmentInitialized()) {
876
+ throw new Error('initFirebaseAdminTestEnvironment() (in @dereekb/firebase-server package) was not called before using adminFirebaseTestBuilder().');
877
+ }
878
+ if (config.useFunctionSingletonContext) {
879
+ if (!functionsInitialized) {
880
+ throw new Error('Call setupFirebaseAdminFunctionTestSingleton() (in @dereekb/firebase-server package) if using functions in a singleton context (useFunctionSingletonContext = true/undefined).');
881
+ }
882
+ } else if (config.useFunctionSingletonContext === false) {
883
+ firebaseFunctionsTestInstance = rerollFirebaseAdminFunctionTestSingleton();
884
+ }
885
+ const projectId = getGCloudTestProjectId();
886
+ const storageBucket = 'b-' + projectId;
887
+ const app = admin.initializeApp({
888
+ projectId,
889
+ storageBucket
890
+ });
891
+ return new FirebaseAdminFunctionTestContextInstance(firebaseFunctionsTestInstance, app);
892
+ },
893
+ teardownInstance: async (instance, config) => {
894
+ if (config.useFunctionSingletonContext === false) {
895
+ try {
896
+ await instance.app.delete(); // will be called in cleanup
897
+ firebaseFunctionsTestInstance.cleanup();
898
+ } catch (e) {
899
+ // do nothing
900
+ }
901
+ firebaseFunctionsTestInstance = undefined;
902
+ }
903
+ }
904
+ });
905
+ const firebaseAdminFunctionTestContextFactory = firebaseAdminFunctionTestBuilder({});
906
+
907
+ class FirebaseAdminNestTestContextFixture extends AbstractChildTestContextFixture {
908
+ // MARK: Forwarded
909
+ get nest() {
910
+ return this.instance.nest;
911
+ }
912
+ get nestAppPromiseGetter() {
913
+ return this.instance.nestAppPromiseGetter;
914
+ }
915
+ get(typeOrToken, options) {
916
+ return this.instance.get(typeOrToken, options);
917
+ }
918
+ }
919
+ class FirebaseAdminNestTestContextInstance extends AbstractFirebaseAdminTestContextInstanceChild {
920
+ constructor(parent, nest) {
921
+ super(parent);
922
+ this.nest = void 0;
923
+ this.nestAppPromiseGetter = () => Promise.resolve(this.nest);
924
+ this.nest = nest;
925
+ }
926
+ get(typeOrToken, options) {
927
+ return options ? this.nest.get(typeOrToken, options) : this.nest.get(typeOrToken);
928
+ }
929
+ }
930
+ function firebaseAdminNestContextFixture(config, factory) {
931
+ return buildTests => {
932
+ factory(f => firebaseAdminNestContextWithFixture(config, f, buildTests));
933
+ };
934
+ }
935
+ class FirebaseAdminNestRootModule {}
936
+ function firebaseAdminNestContextWithFixture(config, f, buildTests) {
937
+ const {
938
+ nestModules,
939
+ makeProviders = () => [],
940
+ forceStorageBucket = false,
941
+ defaultStorageBucket: inputDefaultStorageBucket,
942
+ envConfig,
943
+ injectFirebaseServerAppTokenProvider,
944
+ injectServerEnvServiceProvider,
945
+ makeFixture = parent => new FirebaseAdminNestTestContextFixture(parent),
946
+ makeInstance = (instance, nest) => new FirebaseAdminNestTestContextInstance(instance, nest),
947
+ initInstance
948
+ } = config;
949
+ useTestContextFixture({
950
+ fixture: makeFixture(f),
951
+ /**
952
+ * Build tests by passing the fixture to the testing functions.
953
+ *
954
+ * This will inject all tests and sub Jest lifecycle items.
955
+ */
956
+ buildTests,
957
+ initInstance: async () => {
958
+ const imports = asArray(nestModules);
959
+ const providers = makeProviders(f.instance) ?? [];
960
+ const defaultStorageBucket = inputDefaultStorageBucket ?? f.instance.app.options.storageBucket;
961
+ // Inject the serverEnvTokenProvider and optionally the FirebaseServerEnvService
962
+ if (injectServerEnvServiceProvider !== false || envConfig != null) {
963
+ providers.push(serverEnvTokenProvider(envConfig || {
964
+ production: false
965
+ }));
966
+ if (injectServerEnvServiceProvider !== false) {
967
+ providers.push({
968
+ provide: FirebaseServerEnvService,
969
+ useClass: DefaultFirebaseServerEnvService
970
+ }, {
971
+ provide: ServerEnvironmentService,
972
+ useExisting: FirebaseServerEnvService
973
+ });
974
+ }
975
+ }
976
+ // Inject the firebaseServerAppTokenProvider
977
+ if (injectFirebaseServerAppTokenProvider) {
978
+ providers.push(firebaseServerAppTokenProvider(asGetter(f.instance.app)));
979
+ }
980
+ if (defaultStorageBucket) {
981
+ providers.push(firebaseServerStorageDefaultBucketIdTokenProvider({
982
+ defaultBucketId: defaultStorageBucket,
983
+ forceBucket: forceStorageBucket
984
+ }));
985
+ }
986
+ const rootModule = {
987
+ module: FirebaseAdminNestRootModule,
988
+ providers,
989
+ exports: providers,
990
+ global: true
991
+ };
992
+ const builder = Test.createTestingModule({
993
+ imports: [rootModule, ...imports]
994
+ });
995
+ const nest = await builder.compile();
996
+ const instance = makeInstance(f.instance, nest);
997
+ if (initInstance) {
998
+ await initInstance(instance);
999
+ }
1000
+ return instance;
1001
+ },
1002
+ destroyInstance: async instance => {
1003
+ await instance.nest.close();
1004
+ }
1005
+ });
1006
+ }
1007
+ function firebaseAdminNestContextFactory(config) {
1008
+ return firebaseAdminNestContextFixture(config, firebaseAdminTestContextFactory);
1009
+ }
1010
+
1011
+ function wrapCloudFunctionForNestTestsGetter(wrapper, fn) {
1012
+ return wrapCloudFunctionV1ForTests(wrapper.fnWrapper, () => fn(wrapper.nestAppPromiseGetter));
1013
+ }
1014
+ function wrapCallableRequestForNestTestsGetter(wrapper, fn) {
1015
+ return wrapCallableRequestForTests(wrapper.fnWrapper, () => fn(wrapper.nestAppPromiseGetter));
1016
+ }
1017
+ class FirebaseAdminFunctionNestTestContextFixture extends FirebaseAdminNestTestContextFixture {
1018
+ // MARK: FirebaseAdminTestContext (Forwarded)
1019
+ wrapCloudFunctionForNestTests(fn) {
1020
+ return this.wrapCloudFunctionForNestTestsGetter(fn)();
1021
+ }
1022
+ wrapCloudFunctionForNestTestsGetter(fn) {
1023
+ return wrapCloudFunctionForNestTestsGetter(this, fn);
1024
+ }
1025
+ wrapCallableRequestForNestTests(fn) {
1026
+ return this.wrapCallableRequestForNestTestsGetter(fn)();
1027
+ }
1028
+ wrapCallableRequestForNestTestsGetter(fn) {
1029
+ return wrapCallableRequestForNestTestsGetter(this, fn);
1030
+ }
1031
+ // MARK: FirebaseAdminCloudFunctionWrapperSource
1032
+ get fnWrapper() {
1033
+ return this.parent.instance.fnWrapper;
1034
+ }
1035
+ }
1036
+ class FirebaseAdminFunctionNestTestContextInstance extends FirebaseAdminNestTestContextInstance {
1037
+ // MARK: FirebaseAdminTestContext (Forwarded)
1038
+ get fnWrapper() {
1039
+ return this.parent.fnWrapper;
1040
+ }
1041
+ }
1042
+ function firebaseAdminFunctionNestContextFixture(config, factory) {
1043
+ return buildTests => {
1044
+ factory(f => firebaseAdminFunctionNestContextWithFixture(config, f, buildTests));
1045
+ };
1046
+ }
1047
+ class FirebaseAdminFunctionNestRootModule {}
1048
+ function firebaseAdminFunctionNestContextWithFixture(config, f, buildTests) {
1049
+ const mergedConfig = {
1050
+ makeFixture: parent => new FirebaseAdminFunctionNestTestContextFixture(parent),
1051
+ makeInstance: (instance, nest) => new FirebaseAdminFunctionNestTestContextInstance(instance, nest),
1052
+ ...config
1053
+ };
1054
+ return firebaseAdminNestContextWithFixture(mergedConfig, f, buildTests);
1055
+ }
1056
+ function firebaseAdminFunctionNestContextFactory(config) {
1057
+ return firebaseAdminFunctionNestContextFixture(config, firebaseAdminFunctionTestContextFactory);
1058
+ }
1059
+
1060
+ const CallableRequestTestMultipleFixtureSuffix = 'WrappedFn';
1061
+ function isCallableRequestTestSingleConfig(config) {
1062
+ const isSingle = Boolean(config.fn);
1063
+ return isSingle;
1064
+ }
1065
+ function callableRequestTest(config, buildTests) {
1066
+ if (isCallableRequestTestSingleConfig(config)) {
1067
+ const {
1068
+ f,
1069
+ fn
1070
+ } = config;
1071
+ useTestFunctionFixture({
1072
+ fn: () => {
1073
+ const x = wrapCallableRequestForNestTestsGetter(f, fn)();
1074
+ return x;
1075
+ }
1076
+ }, buildTests);
1077
+ } else {
1078
+ const {
1079
+ f,
1080
+ fns: inputFns
1081
+ } = config;
1082
+ const mappedFns = mapObjectMap(inputFns, fn => () => wrapCallableRequestForNestTestsGetter(f, fn)());
1083
+ const fns = {};
1084
+ Object.keys(mappedFns).forEach(key => {
1085
+ fns[`${key}${CallableRequestTestMultipleFixtureSuffix}`] = mappedFns[key];
1086
+ });
1087
+ useTestFunctionMapFixture({
1088
+ fns
1089
+ }, buildTests);
1090
+ }
1091
+ }
1092
+ function describeCallableRequestTest(label, config, buildTests) {
1093
+ describe(label, () => {
1094
+ callableRequestTest(config, buildTests);
1095
+ });
1096
+ }
1097
+
1098
+ function isCloudFunctionTestSingleConfig(config) {
1099
+ const isSingle = Boolean(config.fn);
1100
+ return isSingle;
1101
+ }
1102
+ function cloudFunctionTest(config, buildTests) {
1103
+ if (isCloudFunctionTestSingleConfig(config)) {
1104
+ const {
1105
+ f,
1106
+ fn
1107
+ } = config;
1108
+ useTestFunctionFixture({
1109
+ fn: () => {
1110
+ const x = wrapCloudFunctionForNestTestsGetter(f, fn)();
1111
+ return x;
1112
+ }
1113
+ }, buildTests);
1114
+ } else {
1115
+ const {
1116
+ f,
1117
+ fns: inputFns
1118
+ } = config;
1119
+ const mappedFns = mapObjectMap(inputFns, fn => () => wrapCloudFunctionForNestTestsGetter(f, fn)());
1120
+ const fns = {};
1121
+ Object.keys(mappedFns).forEach(key => {
1122
+ fns[`${key}CloudFn`] = mappedFns[key];
1123
+ });
1124
+ useTestFunctionMapFixture({
1125
+ fns
1126
+ }, buildTests);
1127
+ }
1128
+ }
1129
+ function describeCloudFunctionTest(label, config, buildTests) {
1130
+ describe(label, () => {
1131
+ cloudFunctionTest(config, buildTests);
1132
+ });
1133
+ }
1134
+
1135
+ function initFirebaseServerAdminTestEnvironment() {
1136
+ initFirebaseAdminTestEnvironment({
1137
+ emulators: {
1138
+ auth: '0.0.0.0:9903',
1139
+ firestore: '0.0.0.0:9904',
1140
+ storage: '0.0.0.0:9906'
1141
+ }
1142
+ });
1143
+ }
1144
+ function describeFirestoreTest(s) {
1145
+ let collection;
1146
+ beforeEach(() => {
1147
+ collection = mockItemFirestoreCollection(s.firestoreContext);
1148
+ });
1149
+ describe('firestore', () => {
1150
+ it('should interact with the firestore.', async () => {
1151
+ const document = collection.documentAccessor().newDocument();
1152
+ const setData = {
1153
+ value: 'a',
1154
+ test: true
1155
+ };
1156
+ await document.accessor.set(setData);
1157
+ const exists = await document.accessor.exists();
1158
+ expect(exists).toBe(true);
1159
+ const snapshot = await document.accessor.get();
1160
+ const data = snapshot.data();
1161
+ expect(data).toBeDefined();
1162
+ });
1163
+ });
1164
+ }
1165
+
1166
+ /**
1167
+ * Error thrown when the error type was different than the expected type.
1168
+ */
1169
+ class ExpectedHttpErrorWithSpecificServerErrorCode extends BaseError {
1170
+ constructor(httpError, expectedErrorCode) {
1171
+ const {
1172
+ code
1173
+ } = httpError.details;
1174
+ super(`Expected HttpError with an error code of "${expectedErrorCode}", but recieved "${code}" instead.`);
1175
+ this.httpError = void 0;
1176
+ this.expectedErrorCode = void 0;
1177
+ this.httpError = httpError;
1178
+ this.expectedErrorCode = expectedErrorCode;
1179
+ }
1180
+ }
1181
+ /**
1182
+ * Creates a ExpectFailAssertionFunction that asserts the encountered error is of the expected type using the instanceof keyword.
1183
+ *
1184
+ * Throws a ExpectedErrorOfSpecificTypeError if the input is not a HttpsError.
1185
+ * Throws a ExpectedHttpErrorWithSpecificServerErrorCode if the input's server error data has a different error code.
1186
+ *
1187
+ * @param expectedType
1188
+ * @returns
1189
+ */
1190
+ function expectFailAssertHttpErrorServerErrorCode(expectedCode) {
1191
+ return error => {
1192
+ if (error instanceof HttpsError) {
1193
+ const {
1194
+ code
1195
+ } = error.details;
1196
+ if (code !== expectedCode) {
1197
+ throw new ExpectedHttpErrorWithSpecificServerErrorCode(error, expectedCode);
1198
+ }
1199
+ } else {
1200
+ throw new ExpectedErrorOfSpecificTypeError(error, HttpsError);
1201
+ }
1202
+ return true;
1203
+ };
1204
+ }
1205
+ // MARK: Compat
1206
+ /**
1207
+ * @deprecated Use ExpectedHttpErrorWithSpecificServerErrorCode from shared instead. This is kept for backwards compatibility.
1208
+ */
1209
+ class JestExpectedHttpErrorWithSpecificServerErrorCode extends ExpectedHttpErrorWithSpecificServerErrorCode {}
1210
+ /**
1211
+ * @deprecated Use expectFailAssertHttpErrorServerErrorCode from shared instead. This is kept for backwards compatibility.
1212
+ */
1213
+ const jestExpectFailAssertHttpErrorServerErrorCode = expectFailAssertHttpErrorServerErrorCode;
1214
+
1215
+ /**
1216
+ * Default firestore admin factory.
1217
+ *
1218
+ * Host of localhost, port 9904
1219
+ */
1220
+ const adminFirestoreFactory = googleCloudTestFirestoreBuilder({
1221
+ host: 'localhost',
1222
+ port: 9904
1223
+ });
1224
+ /**
1225
+ * Convenience mock instance for tests within an authorized context.
1226
+ *
1227
+ * Uses @google-cloud/firestore
1228
+ */
1229
+ const dbxComponentsAdminTestWithMockItemCollection = testWithMockItemCollectionFixture()(adminFirestoreFactory);
1230
+
1231
+ /**
1232
+ * Default firestore admin factory.
1233
+ *
1234
+ * Host of localhost, port 9906
1235
+ */
1236
+ const adminFirebaseStorageFactory = googleCloudTestFirebaseStorageBuilder({
1237
+ host: '0.0.0.0',
1238
+ port: 9906
1239
+ });
1240
+ /**
1241
+ * Convenience mock instance for tests within an authorized context.
1242
+ *
1243
+ * Uses @google-cloud/firestore
1244
+ */
1245
+ const dbxComponentsAdminTestWithMockItemStorage = testWithMockItemStorageFixture()(adminFirebaseStorageFactory);
1246
+
1247
+ export { AUTHORIZED_USER_RANDOM_EMAIL_FACTORY, AUTHORIZED_USER_RANDOM_PHONE_NUMBER_FACTORY, AbstractFirebaseAdminTestContextInstanceChild, AuthorizedUserTestContextFixture, AuthorizedUserTestContextInstance, CallableRequestTestMultipleFixtureSuffix, DEFAULT_FIREBASE_ADMIN_FUNCTION_TEST_USE_FUNCTION_SINGLETON_CONTEXT, ExpectedHttpErrorWithSpecificServerErrorCode, FirebaseAdminFunctionNestRootModule, FirebaseAdminFunctionNestTestContextFixture, FirebaseAdminFunctionNestTestContextInstance, FirebaseAdminFunctionTestContextFixture, FirebaseAdminFunctionTestContextInstance, FirebaseAdminNestRootModule, FirebaseAdminNestTestContextFixture, FirebaseAdminNestTestContextInstance, FirebaseAdminTestContextFixture, FirebaseAdminTestContextInstance, GoogleCloudTestFirebaseStorageContextFixture, GoogleCloudTestFirebaseStorageInstance, GoogleCloudTestFirestoreContextFixture, GoogleCloudTestFirestoreInstance, JestExpectedHttpErrorWithSpecificServerErrorCode, ModelTestContextFixture, ModelTestContextInstance, adminFirebaseStorageFactory, adminFirestoreFactory, applyFirebaseGCloudTestProjectIdToFirebaseConfigEnv, authorizedUserContext, authorizedUserContextFactory, callableRequestTest, cloudFunctionTest, createEncodedTestFirestoreTokenForUserRecord, createTestFirestoreTokenForUserRecord, createTestFunctionContextAuthData, createTestFunctionContextOptions, dbxComponentsAdminTestWithMockItemCollection, dbxComponentsAdminTestWithMockItemStorage, decodeEncodedCreateCustomTokenResult, describeCallableRequestTest, describeCloudFunctionTest, describeFirestoreTest, expectFailAssertHttpErrorServerErrorCode, firebaseAdminFirestoreContextFixture, firebaseAdminFirestoreContextWithFixture, firebaseAdminFunctionNestContextFactory, firebaseAdminFunctionNestContextFixture, firebaseAdminFunctionNestContextWithFixture, firebaseAdminFunctionTestBuilder, firebaseAdminFunctionTestContextFactory, firebaseAdminNestContextFactory, firebaseAdminNestContextFixture, firebaseAdminNestContextWithFixture, firebaseAdminTestBuilder, firebaseAdminTestContextFactory, generateNewProjectId, getGCloudProjectId, getGCloudTestProjectId, googleCloudTestFirebaseStorageBuilder, googleCloudTestFirestoreBuilder, initFirebaseAdminTestEnvironment, initFirebaseServerAdminTestEnvironment, isAdminEnvironmentInitialized, isCallableRequestTestSingleConfig, isCloudFunctionTestSingleConfig, jestExpectFailAssertHttpErrorServerErrorCode, makeGoogleFirebaseStorageContext, makeGoogleFirestoreContext, modelTestContextFactory, rerollFirebaseAdminFunctionTestSingleton, rollNewGCloudProjectEnvironmentVariable, setDefaultFirebaseAdminFunctionTestUseFunctionSingleton, setupFirebaseAdminFunctionTestSingleton, testFirestoreClaimsFromUserRecord, testUidFactory, wrapCallableRequestForNestTestsGetter, wrapCloudFunctionForNestTestsGetter };