firebase-tools-with-isolate 13.29.1 → 14.10.1-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 (396) hide show
  1. package/README.md +53 -4
  2. package/lib/api.js +10 -2
  3. package/lib/appdistribution/client.js +2 -2
  4. package/lib/apphosting/backend.js +157 -55
  5. package/lib/apphosting/config.js +121 -101
  6. package/lib/apphosting/githubConnections.js +65 -100
  7. package/lib/apphosting/repo.js +22 -36
  8. package/lib/apphosting/rollout.js +5 -11
  9. package/lib/apphosting/secrets/dialogs.js +13 -11
  10. package/lib/apphosting/secrets/index.js +47 -5
  11. package/lib/apphosting/utils.js +1 -3
  12. package/lib/apphosting/yaml.js +35 -49
  13. package/lib/auth.js +23 -6
  14. package/lib/bin/cli.js +99 -0
  15. package/lib/bin/firebase.js +7 -123
  16. package/lib/bin/mcp.js +49 -0
  17. package/lib/checkValidTargetFilters.js +1 -0
  18. package/lib/command.js +3 -2
  19. package/lib/commands/appdistribution-distribute.js +1 -1
  20. package/lib/commands/appdistribution-groups-create.js +1 -1
  21. package/lib/commands/appdistribution-groups-delete.js +1 -1
  22. package/lib/commands/appdistribution-groups-list.js +2 -2
  23. package/lib/commands/appdistribution-testers-add.js +1 -1
  24. package/lib/commands/appdistribution-testers-list.js +3 -3
  25. package/lib/commands/appdistribution-testers-remove.js +1 -1
  26. package/lib/commands/apphosting-backends-create.js +3 -3
  27. package/lib/commands/apphosting-backends-delete.js +23 -27
  28. package/lib/commands/apphosting-backends-get.js +12 -12
  29. package/lib/commands/apphosting-backends-list.js +5 -5
  30. package/lib/commands/apphosting-builds-create.js +8 -2
  31. package/lib/commands/apphosting-builds-get.js +8 -1
  32. package/lib/commands/apphosting-rollouts-create.js +3 -3
  33. package/lib/commands/apphosting-rollouts-list.js +8 -2
  34. package/lib/commands/apphosting-secrets-access.js +1 -1
  35. package/lib/commands/apphosting-secrets-describe.js +2 -2
  36. package/lib/commands/apphosting-secrets-grantaccess.js +20 -10
  37. package/lib/commands/apphosting-secrets-set.js +27 -1
  38. package/lib/commands/apps-android-sha-create.js +1 -1
  39. package/lib/commands/apps-android-sha-delete.js +1 -1
  40. package/lib/commands/apps-android-sha-list.js +2 -2
  41. package/lib/commands/apps-create.js +4 -108
  42. package/lib/commands/apps-init.js +94 -0
  43. package/lib/commands/apps-list.js +1 -1
  44. package/lib/commands/apps-sdkconfig.js +5 -10
  45. package/lib/commands/auth-export.js +1 -1
  46. package/lib/commands/auth-import.js +1 -1
  47. package/lib/commands/database-import.js +4 -6
  48. package/lib/commands/database-instances-create.js +1 -1
  49. package/lib/commands/database-instances-list.js +1 -1
  50. package/lib/commands/database-profile.js +1 -2
  51. package/lib/commands/database-remove.js +4 -6
  52. package/lib/commands/database-set.js +6 -6
  53. package/lib/commands/database-settings-set.js +1 -1
  54. package/lib/commands/database-update.js +6 -6
  55. package/lib/commands/dataconnect-sdk-generate.js +5 -2
  56. package/lib/commands/dataconnect-services-list.js +2 -2
  57. package/lib/commands/dataconnect-sql-diff.js +2 -2
  58. package/lib/commands/dataconnect-sql-grant.js +3 -3
  59. package/lib/commands/dataconnect-sql-migrate.js +2 -2
  60. package/lib/commands/dataconnect-sql-setup.js +39 -0
  61. package/lib/commands/dataconnect-sql-shell.js +5 -7
  62. package/lib/commands/deploy.js +4 -3
  63. package/lib/commands/emulators-exec.js +1 -1
  64. package/lib/commands/emulators-start.js +4 -3
  65. package/lib/commands/experiments-list.js +1 -1
  66. package/lib/commands/ext-dev-deprecate.js +1 -0
  67. package/lib/commands/ext-dev-init.js +3 -12
  68. package/lib/commands/ext-dev-list.js +1 -1
  69. package/lib/commands/ext-dev-register.js +3 -5
  70. package/lib/commands/ext-dev-undeprecate.js +1 -2
  71. package/lib/commands/ext-dev-usage.js +4 -6
  72. package/lib/commands/ext-export.js +1 -2
  73. package/lib/commands/ext-install.js +3 -3
  74. package/lib/commands/ext-sdk-install.js +1 -0
  75. package/lib/commands/ext-update.js +1 -0
  76. package/lib/commands/firestore-backups-delete.js +3 -4
  77. package/lib/commands/firestore-backups-get.js +1 -1
  78. package/lib/commands/firestore-backups-list.js +2 -2
  79. package/lib/commands/firestore-backups-schedules-create.js +4 -4
  80. package/lib/commands/firestore-backups-schedules-delete.js +3 -4
  81. package/lib/commands/firestore-backups-schedules-list.js +2 -2
  82. package/lib/commands/firestore-backups-schedules-update.js +1 -1
  83. package/lib/commands/firestore-databases-create.js +6 -6
  84. package/lib/commands/firestore-databases-delete.js +3 -7
  85. package/lib/commands/firestore-databases-get.js +1 -1
  86. package/lib/commands/firestore-databases-list.js +1 -1
  87. package/lib/commands/firestore-databases-restore.js +5 -5
  88. package/lib/commands/firestore-databases-update.js +4 -4
  89. package/lib/commands/firestore-delete.js +13 -14
  90. package/lib/commands/firestore-indexes-list.js +4 -4
  91. package/lib/commands/firestore-locations.js +1 -1
  92. package/lib/commands/functions-artifacts-setpolicy.js +132 -0
  93. package/lib/commands/functions-config-export.js +6 -10
  94. package/lib/commands/functions-delete.js +5 -7
  95. package/lib/commands/functions-deletegcfartifacts.js +5 -5
  96. package/lib/commands/functions-list.js +24 -33
  97. package/lib/commands/functions-secrets-access.js +1 -1
  98. package/lib/commands/functions-secrets-describe.js +1 -1
  99. package/lib/commands/functions-secrets-destroy.js +10 -12
  100. package/lib/commands/functions-secrets-get.js +1 -1
  101. package/lib/commands/functions-secrets-prune.js +14 -15
  102. package/lib/commands/functions-secrets-set.js +14 -18
  103. package/lib/commands/hosting-channel-create.js +1 -2
  104. package/lib/commands/hosting-channel-delete.js +4 -4
  105. package/lib/commands/hosting-channel-list.js +1 -1
  106. package/lib/commands/hosting-channel-open.js +2 -3
  107. package/lib/commands/hosting-disable.js +5 -5
  108. package/lib/commands/hosting-sites-delete.js +4 -4
  109. package/lib/commands/hosting-sites-get.js +1 -1
  110. package/lib/commands/hosting-sites-list.js +1 -1
  111. package/lib/commands/index.js +7 -4
  112. package/lib/commands/init.js +54 -60
  113. package/lib/commands/internaltesting-frameworks-compose.js +1 -1
  114. package/lib/commands/login-use.js +2 -11
  115. package/lib/commands/login.js +10 -8
  116. package/lib/commands/logout.js +2 -3
  117. package/lib/commands/mcp.js +11 -0
  118. package/lib/commands/open.js +4 -2
  119. package/lib/commands/projects-create.js +1 -2
  120. package/lib/commands/projects-list.js +1 -1
  121. package/lib/commands/remoteconfig-get.js +1 -1
  122. package/lib/commands/remoteconfig-rollback.js +5 -5
  123. package/lib/commands/remoteconfig-versions-list.js +2 -2
  124. package/lib/commands/setup-emulators-database.js +1 -1
  125. package/lib/commands/setup-emulators-dataconnect.js +1 -1
  126. package/lib/commands/setup-emulators-firestore.js +1 -1
  127. package/lib/commands/setup-emulators-pubsub.js +1 -1
  128. package/lib/commands/setup-emulators-storage.js +1 -1
  129. package/lib/commands/setup-emulators-ui.js +1 -1
  130. package/lib/commands/use.js +115 -111
  131. package/lib/config.js +49 -33
  132. package/lib/crashlytics/buildToolsJarHelper.js +1 -1
  133. package/lib/crashlytics/listTopIssues.js +45 -0
  134. package/lib/dataconnect/build.js +61 -4
  135. package/lib/dataconnect/client.js +26 -17
  136. package/lib/dataconnect/cloudAICompanionClient.js +72 -0
  137. package/lib/dataconnect/dataplaneClient.js +19 -2
  138. package/lib/dataconnect/ensureApis.js +6 -3
  139. package/lib/dataconnect/fileUtils.js +39 -6
  140. package/lib/dataconnect/freeTrial.js +21 -9
  141. package/lib/dataconnect/graphqlError.js +56 -2
  142. package/lib/dataconnect/provisionCloudSql.js +23 -12
  143. package/lib/dataconnect/schemaMigration.js +46 -26
  144. package/lib/dataconnect/types.js +5 -1
  145. package/lib/defaultCredentials.js +12 -1
  146. package/lib/deploy/apphosting/args.js +2 -0
  147. package/lib/deploy/apphosting/deploy.js +77 -0
  148. package/lib/deploy/apphosting/index.js +9 -0
  149. package/lib/deploy/apphosting/prepare.js +138 -0
  150. package/lib/deploy/apphosting/release.js +56 -0
  151. package/lib/deploy/apphosting/util.js +65 -0
  152. package/lib/deploy/dataconnect/deploy.js +14 -7
  153. package/lib/deploy/dataconnect/prepare.js +3 -5
  154. package/lib/deploy/extensions/v2FunctionHelper.js +2 -1
  155. package/lib/deploy/firestore/deploy.js +50 -4
  156. package/lib/deploy/functions/build.js +1 -0
  157. package/lib/deploy/functions/checkIam.js +41 -6
  158. package/lib/deploy/functions/containerCleaner.js +17 -2
  159. package/lib/deploy/functions/ensure.js +2 -1
  160. package/lib/deploy/functions/params.js +10 -17
  161. package/lib/deploy/functions/prepare.js +51 -18
  162. package/lib/deploy/functions/prepareFunctionsUpload.js +9 -5
  163. package/lib/deploy/functions/prompts.js +24 -17
  164. package/lib/deploy/functions/release/fabricator.js +4 -4
  165. package/lib/deploy/functions/release/index.js +27 -9
  166. package/lib/deploy/functions/release/planner.js +1 -0
  167. package/lib/deploy/functions/runtimes/discovery/index.js +13 -5
  168. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +4 -4
  169. package/lib/deploy/functions/runtimes/python/index.js +4 -1
  170. package/lib/deploy/functions/runtimes/supported/types.js +17 -11
  171. package/lib/deploy/functions/services/firestore.js +23 -4
  172. package/lib/deploy/index.js +29 -10
  173. package/lib/deploy/lifecycleHooks.js +6 -12
  174. package/lib/emulator/ExpressBasedEmulator.js +1 -1
  175. package/lib/emulator/apphosting/config.js +15 -14
  176. package/lib/emulator/apphosting/index.js +2 -0
  177. package/lib/emulator/apphosting/serve.js +147 -10
  178. package/lib/emulator/auth/cloudFunctions.js +13 -1
  179. package/lib/emulator/auth/operations.js +2 -1
  180. package/lib/emulator/auth/widget_ui.js +2 -1
  181. package/lib/emulator/commandUtils.js +14 -20
  182. package/lib/emulator/constants.js +2 -0
  183. package/lib/emulator/controller.js +24 -9
  184. package/lib/emulator/dataconnect/pgliteServer.js +136 -45
  185. package/lib/emulator/dataconnectEmulator.js +34 -6
  186. package/lib/emulator/dataconnectToolkitController.js +5 -0
  187. package/lib/emulator/downloadableEmulatorInfo.json +81 -0
  188. package/lib/emulator/downloadableEmulators.js +28 -80
  189. package/lib/emulator/env.js +47 -1
  190. package/lib/emulator/extensionsEmulator.js +5 -3
  191. package/lib/emulator/functionsEmulator.js +6 -26
  192. package/lib/emulator/hub.js +5 -4
  193. package/lib/emulator/hubClient.js +5 -0
  194. package/lib/emulator/initEmulators.js +29 -15
  195. package/lib/emulator/ui.js +4 -8
  196. package/lib/ensureApiEnabled.js +32 -1
  197. package/lib/experiments.js +11 -12
  198. package/lib/extensions/askUserForEventsConfig.js +6 -15
  199. package/lib/extensions/askUserForParam.js +23 -52
  200. package/lib/extensions/change-log.js +1 -25
  201. package/lib/extensions/checkProjectBilling.js +3 -9
  202. package/lib/extensions/diagnose.js +3 -6
  203. package/lib/extensions/emulator/triggerHelper.js +4 -0
  204. package/lib/extensions/extensionsHelper.js +25 -31
  205. package/lib/extensions/listExtensions.js +1 -1
  206. package/lib/extensions/manifest.js +3 -7
  207. package/lib/extensions/paramHelper.js +11 -2
  208. package/lib/extensions/provisioningHelper.js +1 -1
  209. package/lib/extensions/tos.js +4 -2
  210. package/lib/extensions/utils.js +1 -10
  211. package/lib/firebaseConfigValidate.js +7 -5
  212. package/lib/firestore/delete.js +5 -4
  213. package/lib/firestore/pretty-print.js +1 -1
  214. package/lib/frameworks/angular/index.js +11 -6
  215. package/lib/frameworks/angular/utils.js +76 -47
  216. package/lib/frameworks/constants.js +1 -1
  217. package/lib/frameworks/index.js +6 -4
  218. package/lib/frameworks/next/index.js +7 -4
  219. package/lib/frameworks/utils.js +11 -3
  220. package/lib/frameworks/vite/index.js +2 -3
  221. package/lib/fsAsync.js +9 -2
  222. package/lib/fsutils.js +16 -1
  223. package/lib/functions/artifacts.js +196 -0
  224. package/lib/functions/secrets.js +15 -16
  225. package/lib/gcp/apphosting.js +13 -1
  226. package/lib/gcp/artifactregistry.js +27 -2
  227. package/lib/gcp/auth.js +113 -1
  228. package/lib/gcp/cloudbilling.js +12 -1
  229. package/lib/gcp/cloudfunctions.js +32 -4
  230. package/lib/gcp/cloudfunctionsv2.js +15 -9
  231. package/lib/gcp/cloudscheduler.js +2 -2
  232. package/lib/gcp/cloudsql/cloudsqladmin.js +32 -11
  233. package/lib/gcp/cloudsql/connect.js +21 -14
  234. package/lib/gcp/cloudsql/interactive.js +1 -1
  235. package/lib/gcp/cloudsql/permissions.js +46 -99
  236. package/lib/gcp/cloudsql/permissionsSetup.js +224 -0
  237. package/lib/gcp/computeEngine.js +19 -2
  238. package/lib/gcp/devConnect.js +6 -1
  239. package/lib/gcp/firestore.js +55 -16
  240. package/lib/gcp/iam.js +1 -5
  241. package/lib/gcp/proto.js +4 -3
  242. package/lib/gcp/run.js +18 -1
  243. package/lib/gcp/serviceusage.js +2 -1
  244. package/lib/gcp/storage.js +47 -1
  245. package/lib/gemini/fdcExperience.js +56 -0
  246. package/lib/gemini/types.js +2 -0
  247. package/lib/hosting/api.js +4 -0
  248. package/lib/hosting/implicitInit.js +7 -3
  249. package/lib/hosting/interactive.js +2 -3
  250. package/lib/index.js +1 -2
  251. package/lib/init/features/account.js +2 -4
  252. package/lib/init/features/apphosting.js +75 -6
  253. package/lib/init/features/database.js +63 -62
  254. package/lib/init/features/dataconnect/index.js +131 -85
  255. package/lib/init/features/dataconnect/sdk.js +73 -18
  256. package/lib/init/features/emulators.js +29 -46
  257. package/lib/init/features/firestore/index.js +79 -43
  258. package/lib/init/features/firestore/indexes.js +30 -45
  259. package/lib/init/features/firestore/rules.js +36 -62
  260. package/lib/init/features/functions/index.js +11 -16
  261. package/lib/init/features/functions/javascript.js +17 -30
  262. package/lib/init/features/functions/npm-dependencies.js +4 -8
  263. package/lib/init/features/functions/python.js +1 -3
  264. package/lib/init/features/functions/typescript.js +25 -43
  265. package/lib/init/features/genkit/index.js +111 -106
  266. package/lib/init/features/hosting/github.js +22 -52
  267. package/lib/init/features/hosting/index.js +37 -57
  268. package/lib/init/features/index.js +10 -5
  269. package/lib/init/features/project.js +18 -21
  270. package/lib/init/features/remoteconfig.js +5 -10
  271. package/lib/init/features/storage.js +30 -10
  272. package/lib/init/index.js +79 -24
  273. package/lib/logger.js +76 -3
  274. package/lib/management/apps.js +292 -7
  275. package/lib/management/projects.js +100 -52
  276. package/lib/mcp/errors.js +20 -0
  277. package/lib/mcp/index.js +227 -0
  278. package/lib/mcp/tool.js +12 -0
  279. package/lib/mcp/tools/apphosting/fetch_logs.js +68 -0
  280. package/lib/mcp/tools/apphosting/index.js +6 -0
  281. package/lib/mcp/tools/apphosting/list_backends.js +51 -0
  282. package/lib/mcp/tools/auth/disable_user.js +30 -0
  283. package/lib/mcp/tools/auth/get_user.js +38 -0
  284. package/lib/mcp/tools/auth/index.js +15 -0
  285. package/lib/mcp/tools/auth/list_users.js +36 -0
  286. package/lib/mcp/tools/auth/set_claims.js +43 -0
  287. package/lib/mcp/tools/auth/set_sms_region_policy.js +36 -0
  288. package/lib/mcp/tools/core/consult_assistant.js +28 -0
  289. package/lib/mcp/tools/core/create_android_sha.js +43 -0
  290. package/lib/mcp/tools/core/create_app.js +90 -0
  291. package/lib/mcp/tools/core/create_project.js +68 -0
  292. package/lib/mcp/tools/core/get_admin_sdk_config.js +26 -0
  293. package/lib/mcp/tools/core/get_environment.js +51 -0
  294. package/lib/mcp/tools/core/get_project.js +22 -0
  295. package/lib/mcp/tools/core/get_sdk_config.js +40 -0
  296. package/lib/mcp/tools/core/index.js +29 -0
  297. package/lib/mcp/tools/core/init.js +153 -0
  298. package/lib/mcp/tools/core/list_apps.js +34 -0
  299. package/lib/mcp/tools/core/list_projects.js +45 -0
  300. package/lib/mcp/tools/core/update_environment.js +55 -0
  301. package/lib/mcp/tools/crashlytics/index.js +5 -0
  302. package/lib/mcp/tools/crashlytics/list_top_issues.js +39 -0
  303. package/lib/mcp/tools/dataconnect/converter.js +60 -0
  304. package/lib/mcp/tools/dataconnect/emulator.js +16 -0
  305. package/lib/mcp/tools/dataconnect/execute_graphql.js +48 -0
  306. package/lib/mcp/tools/dataconnect/execute_graphql_read.js +48 -0
  307. package/lib/mcp/tools/dataconnect/execute_mutation.js +62 -0
  308. package/lib/mcp/tools/dataconnect/execute_query.js +62 -0
  309. package/lib/mcp/tools/dataconnect/generate_operation.js +34 -0
  310. package/lib/mcp/tools/dataconnect/generate_schema.js +26 -0
  311. package/lib/mcp/tools/dataconnect/get_connector.js +31 -0
  312. package/lib/mcp/tools/dataconnect/get_schema.js +31 -0
  313. package/lib/mcp/tools/dataconnect/index.js +23 -0
  314. package/lib/mcp/tools/dataconnect/list_services.js +23 -0
  315. package/lib/mcp/tools/firestore/converter.js +102 -0
  316. package/lib/mcp/tools/firestore/delete_document.js +50 -0
  317. package/lib/mcp/tools/firestore/get_documents.js +58 -0
  318. package/lib/mcp/tools/firestore/index.js +17 -0
  319. package/lib/mcp/tools/firestore/list_collections.js +36 -0
  320. package/lib/mcp/tools/firestore/query_collection.js +132 -0
  321. package/lib/mcp/tools/index.js +62 -0
  322. package/lib/mcp/tools/messaging/index.js +5 -0
  323. package/lib/mcp/tools/messaging/send_message.js +42 -0
  324. package/lib/mcp/tools/remoteconfig/get_template.js +27 -0
  325. package/lib/mcp/tools/remoteconfig/index.js +7 -0
  326. package/lib/mcp/tools/remoteconfig/publish_template.js +34 -0
  327. package/lib/mcp/tools/remoteconfig/rollback_template.js +29 -0
  328. package/lib/mcp/tools/rules/get_rules.js +29 -0
  329. package/lib/mcp/tools/rules/validate_rules.js +97 -0
  330. package/lib/mcp/tools/storage/get_download_url.js +40 -0
  331. package/lib/mcp/tools/storage/get_rules.js +26 -0
  332. package/lib/mcp/tools/storage/index.js +11 -0
  333. package/lib/mcp/types.js +13 -0
  334. package/lib/mcp/util.js +214 -0
  335. package/lib/mcp/util.test.js +468 -0
  336. package/lib/messaging/interfaces.js +2 -0
  337. package/lib/messaging/sendMessage.js +48 -0
  338. package/lib/operation-poller.js +3 -1
  339. package/lib/profileReport.js +1 -1
  340. package/lib/prompt.js +86 -54
  341. package/lib/remoteconfig/publish.js +39 -0
  342. package/lib/requireAuth.js +2 -2
  343. package/lib/requireTosAcceptance.js +4 -0
  344. package/lib/rulesDeploy.js +10 -15
  345. package/lib/track.js +7 -37
  346. package/lib/utils.js +28 -41
  347. package/lib/vsCodeUtils.js +7 -3
  348. package/package.json +31 -15
  349. package/schema/connector-yaml.json +12 -0
  350. package/schema/dataconnect-yaml.json +5 -0
  351. package/schema/extension-yaml.json +17 -4
  352. package/schema/firebase-config.json +1117 -2121
  353. package/standalone/package-lock.json +1255 -992
  354. package/standalone/package.json +1 -1
  355. package/templates/dataconnect-prompts/operation-generation-cursor-windsurf-rule.txt +273 -0
  356. package/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt +653 -0
  357. package/templates/genkit/firebase.0.9.0.template +1 -1
  358. package/templates/genkit/firebase.1.0.0.template +71 -0
  359. package/templates/init/dataconnect/connector.yaml +4 -1
  360. package/templates/init/dataconnect/dataconnect.yaml +1 -1
  361. package/templates/init/dataconnect/mutations.gql +9 -26
  362. package/templates/init/dataconnect/queries.gql +9 -14
  363. package/templates/init/dataconnect/schema.gql +28 -21
  364. package/templates/init/firestore/firestore.rules +2 -0
  365. package/templates/init/functions/javascript/index.js +14 -1
  366. package/templates/init/functions/javascript/package.lint.json +1 -1
  367. package/templates/init/functions/javascript/package.nolint.json +1 -1
  368. package/templates/init/functions/python/_gitignore +6 -1
  369. package/templates/init/functions/python/main.py +8 -0
  370. package/templates/init/functions/typescript/index.ts +14 -1
  371. package/templates/init/functions/typescript/package.lint.json +2 -2
  372. package/templates/init/functions/typescript/package.nolint.json +3 -3
  373. package/lib/commands/apphosting-config-export.js +0 -28
  374. package/lib/commands/experimental-functions-shell.js +0 -13
  375. package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +0 -11
  376. package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +0 -58
  377. package/lib/emulator/dataconnect/pg-gateway/auth/index.js +0 -22
  378. package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +0 -124
  379. package/lib/emulator/dataconnect/pg-gateway/auth/password.js +0 -54
  380. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +0 -34
  381. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +0 -270
  382. package/lib/emulator/dataconnect/pg-gateway/backend-error.js +0 -75
  383. package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +0 -54
  384. package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +0 -79
  385. package/lib/emulator/dataconnect/pg-gateway/connection.js +0 -315
  386. package/lib/emulator/dataconnect/pg-gateway/connection.types.js +0 -8
  387. package/lib/emulator/dataconnect/pg-gateway/crypto.js +0 -40
  388. package/lib/emulator/dataconnect/pg-gateway/duplex.js +0 -53
  389. package/lib/emulator/dataconnect/pg-gateway/index.js +0 -27
  390. package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +0 -82
  391. package/lib/emulator/dataconnect/pg-gateway/message-codes.js +0 -52
  392. package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +0 -16
  393. package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +0 -35
  394. package/lib/emulator/dataconnect/pg-gateway/utils.js +0 -40
  395. package/templates/setup/web.js +0 -5
  396. /package/lib/{emulator/dataconnect/pg-gateway/auth/trust.js → dataconnect/cloudAICompanionTypes.js} +0 -0
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeGraphQL = exports.dataconnectDataplaneClient = exports.DATACONNECT_API_VERSION = void 0;
3
+ exports.executeGraphQLMutation = exports.executeGraphQLQuery = exports.executeGraphQLRead = exports.executeGraphQL = exports.dataconnectDataplaneClient = exports.DATACONNECT_API_VERSION = exports.dataconnectOrigin = void 0;
4
4
  const api_1 = require("../api");
5
+ var api_2 = require("../api");
6
+ Object.defineProperty(exports, "dataconnectOrigin", { enumerable: true, get: function () { return api_2.dataconnectOrigin; } });
5
7
  const apiv2_1 = require("../apiv2");
6
- exports.DATACONNECT_API_VERSION = "v1beta";
8
+ exports.DATACONNECT_API_VERSION = "v1";
7
9
  function dataconnectDataplaneClient() {
8
10
  return new apiv2_1.Client({
9
11
  urlPrefix: (0, api_1.dataconnectOrigin)(),
@@ -17,3 +19,18 @@ async function executeGraphQL(client, servicePath, body) {
17
19
  return res;
18
20
  }
19
21
  exports.executeGraphQL = executeGraphQL;
22
+ async function executeGraphQLRead(client, servicePath, body) {
23
+ const res = await client.post(`${servicePath}:executeGraphqlRead`, body, { resolveOnHTTPError: true });
24
+ return res;
25
+ }
26
+ exports.executeGraphQLRead = executeGraphQLRead;
27
+ async function executeGraphQLQuery(client, connectorPath, body) {
28
+ const res = await client.post(`${connectorPath}:executeQuery`, body, { resolveOnHTTPError: true });
29
+ return res;
30
+ }
31
+ exports.executeGraphQLQuery = executeGraphQLQuery;
32
+ async function executeGraphQLMutation(client, connectorPath, body) {
33
+ const res = await client.post(`${connectorPath}:executeMutation`, body, { resolveOnHTTPError: true });
34
+ return res;
35
+ }
36
+ exports.executeGraphQLMutation = executeGraphQLMutation;
@@ -1,17 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureSparkApis = exports.ensureApis = void 0;
3
+ exports.ensureGIFApis = exports.ensureSparkApis = exports.ensureApis = void 0;
4
4
  const api = require("../api");
5
5
  const ensureApiEnabled_1 = require("../ensureApiEnabled");
6
+ const prefix = "dataconnect";
6
7
  async function ensureApis(projectId) {
7
- const prefix = "dataconnect";
8
8
  await (0, ensureApiEnabled_1.ensure)(projectId, api.dataconnectOrigin(), prefix);
9
9
  await (0, ensureApiEnabled_1.ensure)(projectId, api.cloudSQLAdminOrigin(), prefix);
10
10
  await (0, ensureApiEnabled_1.ensure)(projectId, api.computeOrigin(), prefix);
11
11
  }
12
12
  exports.ensureApis = ensureApis;
13
13
  async function ensureSparkApis(projectId) {
14
- const prefix = "dataconnect";
15
14
  await (0, ensureApiEnabled_1.ensure)(projectId, api.cloudSQLAdminOrigin(), prefix);
16
15
  }
17
16
  exports.ensureSparkApis = ensureSparkApis;
17
+ async function ensureGIFApis(projectId) {
18
+ await (0, ensureApiEnabled_1.ensure)(projectId, api.cloudAiCompanionOrigin(), prefix);
19
+ }
20
+ exports.ensureGIFApis = ensureGIFApis;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPlatformFromFolder = exports.pickService = exports.readGQLFiles = exports.readConnectorYaml = exports.readDataConnectYaml = exports.readFirebaseJson = void 0;
3
+ exports.getFrameworksFromPackageJson = exports.frameworksMap = exports.SUPPORTED_FRAMEWORKS = exports.resolvePackageJson = exports.getPlatformFromFolder = exports.pickService = exports.readGQLFiles = exports.readConnectorYaml = exports.readDataConnectYaml = exports.readFirebaseJson = void 0;
4
4
  const fs = require("fs-extra");
5
5
  const path = require("path");
6
+ const clc = require("colorette");
6
7
  const error_1 = require("../error");
7
8
  const types_1 = require("./types");
8
9
  const utils_1 = require("../utils");
@@ -77,10 +78,16 @@ async function pickService(projectId, config, serviceId) {
77
78
  const serviceCfgs = readFirebaseJson(config);
78
79
  let serviceInfo;
79
80
  if (serviceCfgs.length === 0) {
80
- throw new error_1.FirebaseError("No Data Connect services found in firebase.json.");
81
+ throw new error_1.FirebaseError("No Data Connect services found in firebase.json." +
82
+ `\nYou can run ${clc.bold("firebase init dataconnect")} to add a Data Connect service.`);
81
83
  }
82
84
  else if (serviceCfgs.length === 1) {
83
85
  serviceInfo = await (0, load_1.load)(projectId, config, serviceCfgs[0].source);
86
+ if (serviceId && serviceId !== serviceInfo.dataConnectYaml.serviceId) {
87
+ throw new error_1.FirebaseError(`No service named ${serviceId} declared in firebase.json. Found ${serviceInfo.dataConnectYaml.serviceId}.` +
88
+ `\nYou can run ${clc.bold("firebase init dataconnect")} to add this Data Connect service.`);
89
+ }
90
+ return serviceInfo;
84
91
  }
85
92
  else {
86
93
  if (!serviceId) {
@@ -89,15 +96,15 @@ async function pickService(projectId, config, serviceId) {
89
96
  const infos = await Promise.all(serviceCfgs.map((c) => (0, load_1.load)(projectId, config, c.source)));
90
97
  const maybe = infos.find((i) => i.dataConnectYaml.serviceId === serviceId);
91
98
  if (!maybe) {
92
- throw new error_1.FirebaseError(`No service named ${serviceId} declared in firebase.json.`);
99
+ throw new error_1.FirebaseError(`No service named ${serviceId} declared in firebase.json. Found ${infos.map((i) => i.dataConnectYaml.serviceId).join(", ")}.` +
100
+ `\nYou can run ${clc.bold("firebase init dataconnect")} to add this Data Connect service.`);
93
101
  }
94
- serviceInfo = maybe;
102
+ return maybe;
95
103
  }
96
- return serviceInfo;
97
104
  }
98
105
  exports.pickService = pickService;
99
106
  const WEB_INDICATORS = ["package.json", "package-lock.json", "node_modules"];
100
- const IOS_INDICATORS = ["info.plist", "podfile", "package.swift"];
107
+ const IOS_INDICATORS = ["info.plist", "podfile", "package.swift", ".xcodeproj"];
101
108
  const ANDROID_INDICATORS = ["androidmanifest.xml", "build.gradle", "build.gradle.kts"];
102
109
  const DART_INDICATORS = ["pubspec.yaml", "pubspec.lock"];
103
110
  const IOS_POSTFIX_INDICATORS = [".xcworkspace", ".xcodeproj"];
@@ -133,3 +140,29 @@ async function getPlatformFromFolder(dirPath) {
133
140
  return types_1.Platform.MULTIPLE;
134
141
  }
135
142
  exports.getPlatformFromFolder = getPlatformFromFolder;
143
+ async function resolvePackageJson(packageJsonPath) {
144
+ let validPackageJsonPath = packageJsonPath;
145
+ if (!packageJsonPath.endsWith("package.json")) {
146
+ validPackageJsonPath = path.join(packageJsonPath, "package.json");
147
+ }
148
+ validPackageJsonPath = path.resolve(validPackageJsonPath);
149
+ try {
150
+ return JSON.parse((await fs.readFile(validPackageJsonPath)).toString());
151
+ }
152
+ catch {
153
+ return undefined;
154
+ }
155
+ }
156
+ exports.resolvePackageJson = resolvePackageJson;
157
+ exports.SUPPORTED_FRAMEWORKS = ["react", "angular"];
158
+ exports.frameworksMap = {
159
+ react: ["react", "next"],
160
+ angular: ["@angular/core"],
161
+ };
162
+ function getFrameworksFromPackageJson(packageJson) {
163
+ const devDependencies = Object.keys(packageJson.devDependencies ?? {});
164
+ const dependencies = Object.keys(packageJson.dependencies ?? {});
165
+ const allDeps = Array.from(new Set([...devDependencies, ...dependencies]));
166
+ return exports.SUPPORTED_FRAMEWORKS.filter((framework) => exports.frameworksMap[framework].find((dep) => allDeps.includes(dep)));
167
+ }
168
+ exports.getFrameworksFromPackageJson = getFrameworksFromPackageJson;
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.upgradeInstructions = exports.printFreeTrialUnavailable = exports.getFreeTrialInstanceId = exports.checkFreeTrialInstanceUsed = exports.freeTrialTermsLink = void 0;
3
+ exports.upgradeInstructions = exports.printFreeTrialUnavailable = exports.isFreeTrialError = exports.getFreeTrialInstanceId = exports.checkFreeTrialInstanceUsed = exports.freeTrialTermsLink = void 0;
4
+ const clc = require("colorette");
4
5
  const cloudmonitoring_1 = require("../gcp/cloudmonitoring");
5
6
  const cloudsqladmin_1 = require("../gcp/cloudsql/cloudsqladmin");
6
7
  const utils = require("../utils");
7
- const clc = require("colorette");
8
8
  function freeTrialTermsLink() {
9
9
  return "https://firebase.google.com/pricing";
10
10
  }
11
11
  exports.freeTrialTermsLink = freeTrialTermsLink;
12
12
  const FREE_TRIAL_METRIC = "sqladmin.googleapis.com/fdc_lifetime_free_trial_per_project";
13
13
  async function checkFreeTrialInstanceUsed(projectId) {
14
+ utils.logLabeledBullet("dataconnect", "Checking Cloud SQL no cost trial eligibility...");
14
15
  const past7d = new Date();
15
16
  past7d.setDate(past7d.getDate() - 7);
16
17
  const query = {
@@ -20,12 +21,17 @@ async function checkFreeTrialInstanceUsed(projectId) {
20
21
  };
21
22
  try {
22
23
  const ts = await (0, cloudmonitoring_1.queryTimeSeries)(query, projectId);
24
+ let used = true;
23
25
  if (ts.length) {
24
- return ts[0].points.some((p) => p.value.int64Value);
26
+ used = ts[0].points.some((p) => p.value.int64Value);
25
27
  }
26
- return true;
28
+ if (used) {
29
+ utils.logLabeledWarning("dataconnect", "CloudSQL no cost trial has already been used on this project.");
30
+ }
31
+ return used;
27
32
  }
28
33
  catch (err) {
34
+ utils.logLabeledSuccess("dataconnect", "CloudSQL no cost trial available!");
29
35
  return false;
30
36
  }
31
37
  }
@@ -35,17 +41,23 @@ async function getFreeTrialInstanceId(projectId) {
35
41
  return instances.find((i) => i.settings.userLabels?.["firebase-data-connect"] === "ft")?.name;
36
42
  }
37
43
  exports.getFreeTrialInstanceId = getFreeTrialInstanceId;
44
+ async function isFreeTrialError(err, projectId) {
45
+ return err.message.includes("Quota Exhausted") && (await checkFreeTrialInstanceUsed(projectId))
46
+ ? true
47
+ : false;
48
+ }
49
+ exports.isFreeTrialError = isFreeTrialError;
38
50
  function printFreeTrialUnavailable(projectId, configYamlPath, instanceId) {
39
51
  if (!instanceId) {
40
- utils.logLabeledError("data connect", "The CloudSQL free trial has already been used on this project.");
41
- utils.logLabeledError("data connect", `You may create or use a paid CloudSQL instance by visiting https://console.cloud.google.com/sql/instances`);
52
+ utils.logLabeledError("dataconnect", "The CloudSQL free trial has already been used on this project.");
53
+ utils.logLabeledError("dataconnect", `You may create or use a paid CloudSQL instance by visiting https://console.cloud.google.com/sql/instances`);
42
54
  return;
43
55
  }
44
- utils.logLabeledError("data connect", `Project '${projectId} already has a CloudSQL instance '${instanceId}' on the Firebase Data Connect no-cost trial.`);
56
+ utils.logLabeledError("dataconnect", `Project '${projectId} already has a CloudSQL instance '${instanceId}' on the Firebase Data Connect no-cost trial.`);
45
57
  const reuseHint = `To use a different database in the same instance, ${clc.bold(`change the ${clc.blue("instanceId")} to "${instanceId}"`)} and update ${clc.blue("location")} in ` +
46
58
  `${clc.green(configYamlPath)}.`;
47
- utils.logLabeledError("data connect", reuseHint);
48
- utils.logLabeledError("data connect", `Alternatively, you may create a new (paid) CloudSQL instance at https://console.cloud.google.com/sql/instances`);
59
+ utils.logLabeledError("dataconnect", reuseHint);
60
+ utils.logLabeledError("dataconnect", `Alternatively, you may create a new (paid) CloudSQL instance at https://console.cloud.google.com/sql/instances`);
49
61
  }
50
62
  exports.printFreeTrialUnavailable = printFreeTrialUnavailable;
51
63
  function upgradeInstructions(projectId) {
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prettify = void 0;
3
+ exports.prettifyTable = exports.prettify = void 0;
4
+ const Table = require("cli-table3");
4
5
  function prettify(err) {
5
- const message = err.message;
6
+ let message = err.message;
6
7
  let header = err.extensions?.file ?? "";
7
8
  if (err.locations && err.locations.length) {
8
9
  const line = err.locations[0]?.line ?? "";
@@ -10,6 +11,59 @@ function prettify(err) {
10
11
  header += `:${line}`;
11
12
  }
12
13
  }
14
+ if (err.path && err.path.length) {
15
+ let pathStr = "On ";
16
+ for (let i = 0; i < err.path.length; i++) {
17
+ if (typeof err.path[i] === "string") {
18
+ if (i === 0) {
19
+ pathStr += err.path[i];
20
+ }
21
+ else {
22
+ pathStr = `${pathStr}.${err.path[i]}`;
23
+ }
24
+ }
25
+ else {
26
+ pathStr = `${pathStr}[${err.path[i]}]`;
27
+ }
28
+ }
29
+ message = `${pathStr}: ${message}`;
30
+ }
13
31
  return header.length ? `${header}: ${message}` : message;
14
32
  }
15
33
  exports.prettify = prettify;
34
+ function splitIssueMessage(err) {
35
+ const msg = err.message.split(": ");
36
+ if (msg.length >= 2) {
37
+ return [msg[0], msg.slice(1).join(":")];
38
+ }
39
+ return ["", err.message];
40
+ }
41
+ function prettifyTable(errs) {
42
+ const table = new Table({
43
+ head: ["Type", "Issue", "Workaround", "Reason"],
44
+ style: { head: ["yellow"] },
45
+ colWidths: [20, 50, 50, 50],
46
+ wordWrap: true,
47
+ });
48
+ errs.sort((a, b) => a.message.localeCompare(b.message));
49
+ for (const e of errs) {
50
+ const msg = splitIssueMessage(e);
51
+ e.message = msg[1];
52
+ if (!e.extensions?.workarounds?.length) {
53
+ table.push([msg[0], prettify(e), "", ""]);
54
+ }
55
+ else {
56
+ const workarounds = e.extensions.workarounds;
57
+ for (let i = 0; i < workarounds.length; i++) {
58
+ if (i === 0) {
59
+ table.push([msg[0], prettify(e), workarounds[i].description, workarounds[i].reason]);
60
+ }
61
+ else {
62
+ table.push(["", "", workarounds[i].description, workarounds[i].reason]);
63
+ }
64
+ }
65
+ }
66
+ }
67
+ return table.toString();
68
+ }
69
+ exports.prettifyTable = prettifyTable;
@@ -8,10 +8,9 @@ const utils_1 = require("../utils");
8
8
  const logger_1 = require("../logger");
9
9
  const GOOGLE_ML_INTEGRATION_ROLE = "roles/aiplatform.user";
10
10
  const freeTrial_1 = require("./freeTrial");
11
- const error_1 = require("../error");
12
11
  async function provisionCloudSql(args) {
13
12
  let connectionName = "";
14
- const { projectId, locationId, instanceId, databaseId, configYamlPath, enableGoogleMlIntegration, waitForCreation, silent, dryRun, } = args;
13
+ const { projectId, location, instanceId, databaseId, enableGoogleMlIntegration, waitForCreation, silent, dryRun, } = args;
15
14
  try {
16
15
  const existingInstance = await cloudSqlAdminClient.getInstance(projectId, instanceId);
17
16
  silent || utils.logLabeledBullet("dataconnect", `Found existing instance ${instanceId}.`);
@@ -33,19 +32,25 @@ async function provisionCloudSql(args) {
33
32
  if (err.status !== 404) {
34
33
  throw err;
35
34
  }
36
- const freeTrialInstanceId = await (0, freeTrial_1.getFreeTrialInstanceId)(projectId);
37
- if (await (0, freeTrial_1.checkFreeTrialInstanceUsed)(projectId)) {
38
- (0, freeTrial_1.printFreeTrialUnavailable)(projectId, configYamlPath, freeTrialInstanceId);
39
- throw new error_1.FirebaseError("No-cost Cloud SQL trial has already been used on this project.");
40
- }
35
+ cmekWarning();
41
36
  const cta = dryRun ? "It will be created on your next deploy" : "Creating it now.";
37
+ const freeTrialUsed = await (0, freeTrial_1.checkFreeTrialInstanceUsed)(projectId);
42
38
  silent ||
43
- utils.logLabeledBullet("dataconnect", `CloudSQL instance '${instanceId}' not found.` +
44
- cta +
45
- `\nThis instance is provided under the terms of the Data Connect no-cost trial ${(0, freeTrial_1.freeTrialTermsLink)()}` +
46
- `\nMonitor the progress at ${cloudSqlAdminClient.instanceConsoleLink(projectId, instanceId)}`);
39
+ utils.logLabeledBullet("dataconnect", `CloudSQL instance '${instanceId}' not found.` + cta + freeTrialUsed
40
+ ? ""
41
+ : `\nThis instance is provided under the terms of the Data Connect no-cost trial ${(0, freeTrial_1.freeTrialTermsLink)()}` +
42
+ dryRun
43
+ ? `\nMonitor the progress at ${cloudSqlAdminClient.instanceConsoleLink(projectId, instanceId)}`
44
+ : "");
47
45
  if (!dryRun) {
48
- const newInstance = await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.createInstance(projectId, locationId, instanceId, enableGoogleMlIntegration, waitForCreation), "Creating your instance...");
46
+ const newInstance = await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.createInstance({
47
+ projectId,
48
+ location,
49
+ instanceId,
50
+ enableGoogleMlIntegration,
51
+ waitForCreation,
52
+ freeTrial: !freeTrialUsed,
53
+ }), "Creating your instance...");
49
54
  if (newInstance) {
50
55
  silent || utils.logLabeledBullet("dataconnect", "Instance created");
51
56
  connectionName = newInstance?.connectionName || "";
@@ -106,3 +111,9 @@ function getUpdateReason(instance, requireGoogleMlIntegration) {
106
111
  return reason;
107
112
  }
108
113
  exports.getUpdateReason = getUpdateReason;
114
+ function cmekWarning() {
115
+ const message = "Cloud SQL instances created via the Firebase CLI do not support customer managed encryption keys.\n" +
116
+ "If you'd like to use a CMEK to encrypt your data, first create a CMEK encrypted instance (https://cloud.google.com/sql/docs/postgres/configure-cmek#createcmekinstance).\n" +
117
+ "Then, edit your `dataconnect.yaml` file to use the encrypted instance and redeploy.";
118
+ utils.logLabeledWarning("dataconnect", message);
119
+ }
@@ -1,35 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIdentifiers = exports.grantRoleToUserInSchema = exports.migrateSchema = exports.diffSchema = void 0;
3
+ exports.ensureServiceIsConnectedToCloudSql = exports.getIdentifiers = exports.grantRoleToUserInSchema = exports.migrateSchema = exports.diffSchema = void 0;
4
4
  const clc = require("colorette");
5
5
  const sql_formatter_1 = require("sql-formatter");
6
6
  const types_1 = require("./types");
7
7
  const client_1 = require("./client");
8
8
  const connect_1 = require("../gcp/cloudsql/connect");
9
- const permissions_1 = require("../gcp/cloudsql/permissions");
10
- const cloudSqlAdminClient = require("../gcp/cloudsql/cloudsqladmin");
11
9
  const projectUtils_1 = require("../projectUtils");
10
+ const permissionsSetup_1 = require("../gcp/cloudsql/permissionsSetup");
11
+ const permissions_1 = require("../gcp/cloudsql/permissions");
12
12
  const prompt_1 = require("../prompt");
13
13
  const logger_1 = require("../logger");
14
14
  const error_1 = require("../error");
15
15
  const utils_1 = require("../utils");
16
+ const cloudsqladmin_1 = require("../gcp/cloudsql/cloudsqladmin");
17
+ const cloudSqlAdminClient = require("../gcp/cloudsql/cloudsqladmin");
16
18
  const errors = require("./errors");
17
- async function diffSchema(schema, schemaValidation) {
18
- const { serviceName, instanceName, databaseId } = getIdentifiers(schema);
19
+ async function setupSchemaIfNecessary(instanceId, databaseId, options) {
20
+ await (0, connect_1.setupIAMUsers)(instanceId, databaseId, options);
21
+ const schemaInfo = await (0, permissionsSetup_1.getSchemaMetadata)(instanceId, databaseId, permissions_1.DEFAULT_SCHEMA, options);
22
+ if (schemaInfo.setupStatus !== permissionsSetup_1.SchemaSetupStatus.BrownField &&
23
+ schemaInfo.setupStatus !== permissionsSetup_1.SchemaSetupStatus.GreenField) {
24
+ return await (0, permissionsSetup_1.setupSQLPermissions)(instanceId, databaseId, schemaInfo, options, true);
25
+ }
26
+ else {
27
+ logger_1.logger.debug(`Detected schema "${schemaInfo.name}" is setup in ${schemaInfo.setupStatus} mode. Skipping Setup.`);
28
+ }
29
+ return schemaInfo.setupStatus;
30
+ }
31
+ async function diffSchema(options, schema, schemaValidation) {
32
+ (0, utils_1.logLabeledBullet)("dataconnect", `generating required schema changes...`);
33
+ const { serviceName, instanceName, databaseId, instanceId } = getIdentifiers(schema);
19
34
  await ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId, false);
20
35
  let diffs = [];
36
+ await setupSchemaIfNecessary(instanceId, databaseId, options);
21
37
  let validationMode = schemaValidation ?? "COMPATIBLE";
22
38
  setSchemaValidationMode(schema, validationMode);
23
39
  try {
24
- if (!schemaValidation) {
25
- (0, utils_1.logLabeledBullet)("dataconnect", `generating required schema changes...`);
26
- }
27
40
  await (0, client_1.upsertSchema)(schema, true);
28
41
  if (validationMode === "STRICT") {
29
- (0, utils_1.logLabeledSuccess)("dataconnect", `Database schema is up to date.`);
42
+ (0, utils_1.logLabeledSuccess)("dataconnect", `database schema of ${instanceId}:${databaseId} is up to date.`);
30
43
  }
31
44
  else {
32
- (0, utils_1.logLabeledSuccess)("dataconnect", `Database schema is compatible.`);
45
+ (0, utils_1.logLabeledSuccess)("dataconnect", `database schema of ${instanceId}:${databaseId} is compatible.`);
33
46
  }
34
47
  }
35
48
  catch (err) {
@@ -82,15 +95,18 @@ async function diffSchema(schema, schemaValidation) {
82
95
  }
83
96
  exports.diffSchema = diffSchema;
84
97
  async function migrateSchema(args) {
98
+ (0, utils_1.logLabeledBullet)("dataconnect", `generating required schema changes...`);
85
99
  const { options, schema, validateOnly, schemaValidation } = args;
86
100
  const { serviceName, instanceId, instanceName, databaseId } = getIdentifiers(schema);
87
101
  await ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId, true);
102
+ await (0, connect_1.setupIAMUsers)(instanceId, databaseId, options);
88
103
  let diffs = [];
104
+ await setupSchemaIfNecessary(instanceId, databaseId, options);
89
105
  let validationMode = schemaValidation ?? "COMPATIBLE";
90
106
  setSchemaValidationMode(schema, validationMode);
91
107
  try {
92
108
  await (0, client_1.upsertSchema)(schema, validateOnly);
93
- logger_1.logger.debug(`Database schema was up to date for ${instanceId}:${databaseId}`);
109
+ (0, utils_1.logLabeledBullet)("dataconnect", `database schema of ${instanceId}:${databaseId} is up to date.`);
94
110
  }
95
111
  catch (err) {
96
112
  if (err?.status !== 400) {
@@ -156,12 +172,17 @@ async function grantRoleToUserInSchema(options, schema) {
156
172
  const { instanceId, databaseId } = getIdentifiers(schema);
157
173
  const projectId = (0, projectUtils_1.needProjectId)(options);
158
174
  const { user, mode } = (0, connect_1.toDatabaseUser)(email);
159
- const fdcSqlRole = permissions_1.fdcSqlRoleMap[role](databaseId);
160
- const userIsCSQLAdmin = await (0, permissions_1.iamUserIsCSQLAdmin)(options);
175
+ const fdcSqlRole = permissionsSetup_1.fdcSqlRoleMap[role](databaseId);
176
+ await (0, connect_1.setupIAMUsers)(instanceId, databaseId, options);
177
+ const userIsCSQLAdmin = await (0, cloudsqladmin_1.iamUserIsCSQLAdmin)(options);
161
178
  if (!userIsCSQLAdmin) {
162
179
  throw new error_1.FirebaseError(`Only users with 'roles/cloudsql.admin' can grant SQL roles. If you do not have this role, ask your database administrator to run this command or manually grant ${fdcSqlRole} to ${user}`);
163
180
  }
164
- await (0, connect_1.setupIAMUsers)(instanceId, databaseId, options);
181
+ const schemaSetupStatus = await setupSchemaIfNecessary(instanceId, databaseId, options);
182
+ if (schemaSetupStatus !== permissionsSetup_1.SchemaSetupStatus.GreenField &&
183
+ fdcSqlRole === (0, permissions_1.firebaseowner)(databaseId, permissions_1.DEFAULT_SCHEMA)) {
184
+ throw new error_1.FirebaseError(`Owner rule isn't available in brownfield databases. If you would like Data Connect to manage and own your database schema, run 'firebase dataconnect:sql:setup'`);
185
+ }
165
186
  await cloudSqlAdminClient.createUser(projectId, instanceId, mode, user);
166
187
  await (0, connect_1.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, [`GRANT "${fdcSqlRole}" TO "${user}"`], false);
167
188
  }
@@ -231,16 +252,19 @@ async function handleIncompatibleSchemaError(args) {
231
252
  if (commandsToExecute.length) {
232
253
  const commandsToExecuteBySuperUser = commandsToExecute.filter((sql) => sql.startsWith("CREATE EXTENSION") || sql.startsWith("CREATE SCHEMA"));
233
254
  const commandsToExecuteByOwner = commandsToExecute.filter((sql) => !commandsToExecuteBySuperUser.includes(sql));
234
- const userIsCSQLAdmin = await (0, permissions_1.iamUserIsCSQLAdmin)(options);
255
+ const userIsCSQLAdmin = await (0, cloudsqladmin_1.iamUserIsCSQLAdmin)(options);
235
256
  if (!userIsCSQLAdmin && commandsToExecuteBySuperUser.length) {
236
257
  throw new error_1.FirebaseError(`Some SQL commands required for this migration require Admin permissions.\n
237
258
  Please ask a user with 'roles/cloudsql.admin' to apply the following commands.\n
238
259
  ${commandsToExecuteBySuperUser.join("\n")}`);
239
260
  }
240
- if (userIsCSQLAdmin) {
241
- await (0, connect_1.setupIAMUsers)(instanceId, databaseId, options);
261
+ const schemaInfo = await (0, permissionsSetup_1.getSchemaMetadata)(instanceId, databaseId, permissions_1.DEFAULT_SCHEMA, options);
262
+ if (schemaInfo.setupStatus !== permissionsSetup_1.SchemaSetupStatus.GreenField) {
263
+ throw new error_1.FirebaseError(`Brownfield database are protected from SQL changes by Data Connect.\n` +
264
+ `You can use the SQL diff generated by 'firebase dataconnect:sql:diff' to assist you in applying the required changes to your CloudSQL database. Connector deployment will succeed when there is no required diff changes.\n` +
265
+ `If you would like Data Connect to manage your database schema, run 'firebase dataconnect:sql:setup'`);
242
266
  }
243
- if (!(await (0, permissions_1.checkSQLRoleIsGranted)(options, instanceId, databaseId, (0, permissions_1.firebaseowner)(databaseId), (await (0, connect_1.getIAMUser)(options)).user))) {
267
+ if (!(await (0, permissionsSetup_1.checkSQLRoleIsGranted)(options, instanceId, databaseId, (0, permissions_1.firebaseowner)(databaseId), (await (0, connect_1.getIAMUser)(options)).user))) {
244
268
  throw new error_1.FirebaseError(`Command aborted. Only users granted firebaseowner SQL role can run migrations.`);
245
269
  }
246
270
  if (commandsToExecuteBySuperUser.length) {
@@ -281,12 +305,7 @@ async function promptForSchemaMigration(options, instanceName, databaseId, err,
281
305
  { name: "Abort changes", value: "none" },
282
306
  ];
283
307
  const defaultValue = validationMode === "STRICT_AFTER_COMPATIBLE" ? "none" : "all";
284
- return await (0, prompt_1.promptOnce)({
285
- message: message,
286
- type: "list",
287
- choices,
288
- default: defaultValue,
289
- });
308
+ return await (0, prompt_1.select)({ message, choices, default: defaultValue });
290
309
  }
291
310
  if (!validateOnly) {
292
311
  throw new error_1.FirebaseError("Command aborted. Your database schema is incompatible with your Data Connect schema. Run `firebase dataconnect:sql:migrate` to migrate your database schema");
@@ -315,7 +334,7 @@ async function promptForInvalidConnectorError(options, serviceName, invalidConne
315
334
  if (!options.nonInteractive &&
316
335
  (await (0, prompt_1.confirm)({
317
336
  ...options,
318
- message: `Would you like to delete and recreate these connectors? This will cause ${clc.red(`downtime.`)}.`,
337
+ message: `Would you like to delete and recreate these connectors? This will cause ${clc.red(`downtime`)}.`,
319
338
  }))) {
320
339
  return true;
321
340
  }
@@ -337,7 +356,7 @@ async function ensureServiceIsConnectedToCloudSql(serviceName, instanceId, datab
337
356
  (0, utils_1.logLabeledWarning)("dataconnect", `Not yet linked to the Cloud SQL instance.`);
338
357
  return;
339
358
  }
340
- (0, utils_1.logLabeledBullet)("dataconnect", `Linking the Cloud SQL instance...`);
359
+ (0, utils_1.logLabeledBullet)("dataconnect", `linking the Cloud SQL instance...`);
341
360
  currentSchema = {
342
361
  name: `${serviceName}/schemas/${types_1.SCHEMA_ID}`,
343
362
  source: {
@@ -378,6 +397,7 @@ async function ensureServiceIsConnectedToCloudSql(serviceName, instanceId, datab
378
397
  logger_1.logger.debug(err);
379
398
  }
380
399
  }
400
+ exports.ensureServiceIsConnectedToCloudSql = ensureServiceIsConnectedToCloudSql;
381
401
  function displaySchemaChanges(error, validationMode, instanceName, databaseId) {
382
402
  switch (error.violationType) {
383
403
  case "INCOMPATIBLE_SCHEMA":
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toDatasource = exports.Platform = exports.requiresVector = exports.SCHEMA_ID = void 0;
3
+ exports.isGraphQLResponseError = exports.isGraphQLResponse = exports.toDatasource = exports.Platform = exports.requiresVector = exports.SCHEMA_ID = void 0;
4
4
  exports.SCHEMA_ID = "main";
5
5
  function requiresVector(dm) {
6
6
  return dm?.primaryDataSource?.postgres?.requiredExtensions?.includes("vector") ?? false;
@@ -30,3 +30,7 @@ function toDatasource(projectId, locationId, ds) {
30
30
  return {};
31
31
  }
32
32
  exports.toDatasource = toDatasource;
33
+ const isGraphQLResponse = (g) => !!g.data || !!g.errors;
34
+ exports.isGraphQLResponse = isGraphQLResponse;
35
+ const isGraphQLResponseError = (g) => !!g.error;
36
+ exports.isGraphQLResponseError = isGraphQLResponseError;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clearCredentials = exports.getCredentialPathAsync = void 0;
3
+ exports.hasDefaultCredentials = exports.clearCredentials = exports.getCredentialPathAsync = void 0;
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
+ const google_auth_library_1 = require("google-auth-library");
6
7
  const api_1 = require("./api");
7
8
  const logger_1 = require("./logger");
8
9
  async function getCredentialPathAsync(account) {
@@ -78,3 +79,13 @@ function userEmailSlug(user) {
78
79
  const slug = email.replace("@", "_").replace(".", "_");
79
80
  return slug;
80
81
  }
82
+ async function hasDefaultCredentials() {
83
+ try {
84
+ await google_auth_library_1.auth.getApplicationDefault();
85
+ return true;
86
+ }
87
+ catch (err) {
88
+ return false;
89
+ }
90
+ }
91
+ exports.hasDefaultCredentials = hasDefaultCredentials;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const error_1 = require("../../error");
6
+ const gcs = require("../../gcp/storage");
7
+ const getProjectNumber_1 = require("../../getProjectNumber");
8
+ const projectUtils_1 = require("../../projectUtils");
9
+ const utils_1 = require("../../utils");
10
+ const util_1 = require("./util");
11
+ async function default_1(context, options) {
12
+ if (context.backendConfigs.size === 0) {
13
+ return;
14
+ }
15
+ const projectId = (0, projectUtils_1.needProjectId)(options);
16
+ options.projectNumber = await (0, getProjectNumber_1.getProjectNumber)(options);
17
+ if (!context.backendConfigs) {
18
+ return;
19
+ }
20
+ for (const loc of context.backendLocations.values()) {
21
+ const bucketName = `firebaseapphosting-sources-${options.projectNumber}-${loc.toLowerCase()}`;
22
+ try {
23
+ await gcs.getBucket(bucketName);
24
+ }
25
+ catch (err) {
26
+ const errStatus = (0, error_1.getErrStatus)(err.original);
27
+ if (errStatus === 403 || errStatus === 404) {
28
+ (0, utils_1.logLabeledBullet)("apphosting", `Creating Cloud Storage bucket in ${loc} to store App Hosting source code uploads at ${bucketName}...`);
29
+ try {
30
+ await gcs.createBucket(projectId, {
31
+ name: bucketName,
32
+ location: loc,
33
+ lifecycle: {
34
+ rule: [
35
+ {
36
+ action: {
37
+ type: "Delete",
38
+ },
39
+ condition: {
40
+ age: 30,
41
+ },
42
+ },
43
+ ],
44
+ },
45
+ });
46
+ }
47
+ catch (err) {
48
+ if ((0, error_1.getErrStatus)(err.original) === 403) {
49
+ (0, utils_1.logLabeledWarning)("apphosting", "Failed to create Cloud Storage bucket because user does not have sufficient permissions. " +
50
+ "See https://cloud.google.com/storage/docs/access-control/iam-roles for more details on " +
51
+ "IAM roles that are able to create a Cloud Storage bucket, and ask your project administrator " +
52
+ "to grant you one of those roles.");
53
+ throw err.original;
54
+ }
55
+ }
56
+ }
57
+ else {
58
+ throw err;
59
+ }
60
+ }
61
+ }
62
+ for (const cfg of context.backendConfigs.values()) {
63
+ const { projectSourcePath, zippedSourcePath } = await (0, util_1.createArchive)(cfg, options.projectRoot);
64
+ const backendLocation = context.backendLocations.get(cfg.backendId);
65
+ if (!backendLocation) {
66
+ throw new error_1.FirebaseError(`Failed to find location for backend ${cfg.backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`);
67
+ }
68
+ (0, utils_1.logLabeledBullet)("apphosting", `Uploading source code at ${projectSourcePath} for backend ${cfg.backendId}...`);
69
+ const { bucket, object } = await gcs.uploadObject({
70
+ file: zippedSourcePath,
71
+ stream: fs.createReadStream(zippedSourcePath),
72
+ }, `firebaseapphosting-sources-${options.projectNumber}-${backendLocation.toLowerCase()}`);
73
+ (0, utils_1.logLabeledBullet)("apphosting", `Source code uploaded at gs://${bucket}/${object}`);
74
+ context.backendStorageUris.set(cfg.backendId, `gs://firebaseapphosting-sources-${options.projectNumber}-${backendLocation.toLowerCase()}/${path.basename(zippedSourcePath)}`);
75
+ }
76
+ }
77
+ exports.default = default_1;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.release = exports.deploy = exports.prepare = void 0;
4
+ const prepare_1 = require("./prepare");
5
+ exports.prepare = prepare_1.default;
6
+ const deploy_1 = require("./deploy");
7
+ exports.deploy = deploy_1.default;
8
+ const release_1 = require("./release");
9
+ exports.release = release_1.default;