firebase-tools-with-isolate 12.9.1-1
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.
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/lib/accountExporter.js +207 -0
- package/lib/accountImporter.js +305 -0
- package/lib/api.js +84 -0
- package/lib/apiv2.js +353 -0
- package/lib/appdistribution/client.js +193 -0
- package/lib/appdistribution/distribution.js +51 -0
- package/lib/appdistribution/options-parser-util.js +51 -0
- package/lib/archiveDirectory.js +120 -0
- package/lib/auth.js +535 -0
- package/lib/bin/firebase.js +132 -0
- package/lib/checkMinRequiredVersion.js +14 -0
- package/lib/checkValidTargetFilters.js +46 -0
- package/lib/command.js +250 -0
- package/lib/commands/appdistribution-distribute.js +121 -0
- package/lib/commands/appdistribution-group-create.js +19 -0
- package/lib/commands/appdistribution-group-delete.js +24 -0
- package/lib/commands/appdistribution-testers-add.js +24 -0
- package/lib/commands/appdistribution-testers-remove.js +40 -0
- package/lib/commands/apps-android-sha-create.js +29 -0
- package/lib/commands/apps-android-sha-delete.js +16 -0
- package/lib/commands/apps-android-sha-list.js +42 -0
- package/lib/commands/apps-create.js +166 -0
- package/lib/commands/apps-list.js +53 -0
- package/lib/commands/apps-sdkconfig.js +103 -0
- package/lib/commands/auth-export.js +44 -0
- package/lib/commands/auth-import.js +114 -0
- package/lib/commands/crashlytics-mappingfile-generateid.js +26 -0
- package/lib/commands/crashlytics-mappingfile-upload.js +46 -0
- package/lib/commands/crashlytics-symbols-upload.js +78 -0
- package/lib/commands/database-get.js +122 -0
- package/lib/commands/database-import.js +85 -0
- package/lib/commands/database-instances-create.js +29 -0
- package/lib/commands/database-instances-list.js +53 -0
- package/lib/commands/database-profile.js +46 -0
- package/lib/commands/database-push.js +63 -0
- package/lib/commands/database-remove.js +42 -0
- package/lib/commands/database-rules-canary.js +24 -0
- package/lib/commands/database-rules-get.js +22 -0
- package/lib/commands/database-rules-list.js +36 -0
- package/lib/commands/database-rules-release.js +24 -0
- package/lib/commands/database-rules-stage.js +26 -0
- package/lib/commands/database-set.js +68 -0
- package/lib/commands/database-settings-get.js +44 -0
- package/lib/commands/database-settings-set.js +46 -0
- package/lib/commands/database-update.js +69 -0
- package/lib/commands/deploy.js +101 -0
- package/lib/commands/emulators-exec.js +19 -0
- package/lib/commands/emulators-export.js +14 -0
- package/lib/commands/emulators-start.js +115 -0
- package/lib/commands/experimental-functions-shell.js +13 -0
- package/lib/commands/experiments-describe.js +31 -0
- package/lib/commands/experiments-disable.js +28 -0
- package/lib/commands/experiments-enable.js +28 -0
- package/lib/commands/experiments-list.js +29 -0
- package/lib/commands/ext-configure.js +110 -0
- package/lib/commands/ext-dev-deprecate.js +68 -0
- package/lib/commands/ext-dev-init.js +148 -0
- package/lib/commands/ext-dev-list.js +47 -0
- package/lib/commands/ext-dev-publish.js +32 -0
- package/lib/commands/ext-dev-register.js +50 -0
- package/lib/commands/ext-dev-undeprecate.js +57 -0
- package/lib/commands/ext-dev-upload.js +88 -0
- package/lib/commands/ext-dev-usage.js +141 -0
- package/lib/commands/ext-export.js +68 -0
- package/lib/commands/ext-info.js +118 -0
- package/lib/commands/ext-install.js +167 -0
- package/lib/commands/ext-list.js +18 -0
- package/lib/commands/ext-uninstall.js +29 -0
- package/lib/commands/ext-update.js +105 -0
- package/lib/commands/ext.js +41 -0
- package/lib/commands/firestore-databases-create.js +55 -0
- package/lib/commands/firestore-databases-delete.js +39 -0
- package/lib/commands/firestore-databases-get.js +25 -0
- package/lib/commands/firestore-databases-list.js +24 -0
- package/lib/commands/firestore-databases-update.js +59 -0
- package/lib/commands/firestore-delete.js +88 -0
- package/lib/commands/firestore-indexes-list.js +38 -0
- package/lib/commands/firestore-locations.js +24 -0
- package/lib/commands/frameworks-backends-create.js +14 -0
- package/lib/commands/frameworks-backends-delete.js +98 -0
- package/lib/commands/frameworks-backends-get.js +80 -0
- package/lib/commands/frameworks-backends-list.js +68 -0
- package/lib/commands/functions-config-clone.js +53 -0
- package/lib/commands/functions-config-export.js +118 -0
- package/lib/commands/functions-config-get.js +35 -0
- package/lib/commands/functions-config-set.js +43 -0
- package/lib/commands/functions-config-unset.js +42 -0
- package/lib/commands/functions-delete.js +95 -0
- package/lib/commands/functions-deletegcfartifacts.js +44 -0
- package/lib/commands/functions-list.js +47 -0
- package/lib/commands/functions-log.js +34 -0
- package/lib/commands/functions-secrets-access.js +22 -0
- package/lib/commands/functions-secrets-destroy.js +64 -0
- package/lib/commands/functions-secrets-get.js +28 -0
- package/lib/commands/functions-secrets-prune.js +57 -0
- package/lib/commands/functions-secrets-set.js +108 -0
- package/lib/commands/functions-shell.js +15 -0
- package/lib/commands/help.js +27 -0
- package/lib/commands/hosting-channel-create.js +78 -0
- package/lib/commands/hosting-channel-delete.js +47 -0
- package/lib/commands/hosting-channel-deploy.js +146 -0
- package/lib/commands/hosting-channel-list.js +40 -0
- package/lib/commands/hosting-channel-open.js +48 -0
- package/lib/commands/hosting-clone.js +103 -0
- package/lib/commands/hosting-disable.js +31 -0
- package/lib/commands/hosting-sites-create.js +34 -0
- package/lib/commands/hosting-sites-delete.js +39 -0
- package/lib/commands/hosting-sites-get.js +27 -0
- package/lib/commands/hosting-sites-list.js +28 -0
- package/lib/commands/index.js +191 -0
- package/lib/commands/init.js +195 -0
- package/lib/commands/internaltesting-frameworks-compose.js +22 -0
- package/lib/commands/internaltesting-functions-discover.js +25 -0
- package/lib/commands/login-add.js +32 -0
- package/lib/commands/login-ci.js +25 -0
- package/lib/commands/login-list.js +28 -0
- package/lib/commands/login-use.js +24 -0
- package/lib/commands/login.js +57 -0
- package/lib/commands/logout.js +76 -0
- package/lib/commands/open.js +100 -0
- package/lib/commands/projects-addfirebase.js +19 -0
- package/lib/commands/projects-create.js +37 -0
- package/lib/commands/projects-list.js +61 -0
- package/lib/commands/remoteconfig-get.js +68 -0
- package/lib/commands/remoteconfig-rollback.js +48 -0
- package/lib/commands/remoteconfig-versions-list.js +34 -0
- package/lib/commands/serve.js +60 -0
- package/lib/commands/setup-emulators-database.js +12 -0
- package/lib/commands/setup-emulators-firestore.js +12 -0
- package/lib/commands/setup-emulators-pubsub.js +12 -0
- package/lib/commands/setup-emulators-storage.js +12 -0
- package/lib/commands/setup-emulators-ui.js +12 -0
- package/lib/commands/target-apply.js +24 -0
- package/lib/commands/target-clear.js +20 -0
- package/lib/commands/target-remove.js +20 -0
- package/lib/commands/target.js +34 -0
- package/lib/commands/use.js +162 -0
- package/lib/config.js +227 -0
- package/lib/configstore.js +6 -0
- package/lib/crashlytics/buildToolsJarHelper.js +51 -0
- package/lib/database/api.js +19 -0
- package/lib/database/import.js +218 -0
- package/lib/database/listRemote.js +37 -0
- package/lib/database/metadata.js +67 -0
- package/lib/database/remove.js +88 -0
- package/lib/database/removeRemote.js +51 -0
- package/lib/database/rulesConfig.js +79 -0
- package/lib/database/settings.js +62 -0
- package/lib/defaultCredentials.js +80 -0
- package/lib/deploy/database/deploy.js +5 -0
- package/lib/deploy/database/index.js +9 -0
- package/lib/deploy/database/prepare.js +54 -0
- package/lib/deploy/database/release.js +30 -0
- package/lib/deploy/extensions/args.js +2 -0
- package/lib/deploy/extensions/deploy.js +49 -0
- package/lib/deploy/extensions/deploymentSummary.js +56 -0
- package/lib/deploy/extensions/errors.js +31 -0
- package/lib/deploy/extensions/index.js +9 -0
- package/lib/deploy/extensions/planner.js +157 -0
- package/lib/deploy/extensions/prepare.js +110 -0
- package/lib/deploy/extensions/release.js +57 -0
- package/lib/deploy/extensions/secrets.js +150 -0
- package/lib/deploy/extensions/tasks.js +156 -0
- package/lib/deploy/extensions/v2FunctionHelper.js +53 -0
- package/lib/deploy/extensions/validate.js +17 -0
- package/lib/deploy/firestore/deploy.js +44 -0
- package/lib/deploy/firestore/index.js +9 -0
- package/lib/deploy/firestore/prepare.js +59 -0
- package/lib/deploy/firestore/release.js +22 -0
- package/lib/deploy/functions/args.js +2 -0
- package/lib/deploy/functions/backend.js +316 -0
- package/lib/deploy/functions/build.js +311 -0
- package/lib/deploy/functions/cache/applyHash.js +22 -0
- package/lib/deploy/functions/cache/hash.js +30 -0
- package/lib/deploy/functions/cel.js +365 -0
- package/lib/deploy/functions/checkIam.js +183 -0
- package/lib/deploy/functions/containerCleaner.js +305 -0
- package/lib/deploy/functions/deploy.js +108 -0
- package/lib/deploy/functions/ensure.js +105 -0
- package/lib/deploy/functions/ensureCloudBuildEnabled.js +1 -0
- package/lib/deploy/functions/functionsDeployHelper.js +134 -0
- package/lib/deploy/functions/index.js +9 -0
- package/lib/deploy/functions/params.js +517 -0
- package/lib/deploy/functions/prepare.js +304 -0
- package/lib/deploy/functions/prepareFunctionsUpload.js +113 -0
- package/lib/deploy/functions/pricing.js +171 -0
- package/lib/deploy/functions/prompts.js +157 -0
- package/lib/deploy/functions/release/executor.js +51 -0
- package/lib/deploy/functions/release/fabricator.js +584 -0
- package/lib/deploy/functions/release/index.js +93 -0
- package/lib/deploy/functions/release/planner.js +205 -0
- package/lib/deploy/functions/release/reporter.js +196 -0
- package/lib/deploy/functions/release/sourceTokenScraper.js +67 -0
- package/lib/deploy/functions/release/timer.js +14 -0
- package/lib/deploy/functions/runtimes/discovery/index.js +85 -0
- package/lib/deploy/functions/runtimes/discovery/mockDiscoveryServer.js +14 -0
- package/lib/deploy/functions/runtimes/discovery/parsing.js +95 -0
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +296 -0
- package/lib/deploy/functions/runtimes/index.js +59 -0
- package/lib/deploy/functions/runtimes/node/extractTriggers.js +23 -0
- package/lib/deploy/functions/runtimes/node/index.js +173 -0
- package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +57 -0
- package/lib/deploy/functions/runtimes/node/parseTriggers.js +332 -0
- package/lib/deploy/functions/runtimes/node/triggerParser.js +72 -0
- package/lib/deploy/functions/runtimes/node/validate.js +34 -0
- package/lib/deploy/functions/runtimes/node/versioning.js +95 -0
- package/lib/deploy/functions/runtimes/python/index.js +154 -0
- package/lib/deploy/functions/services/auth.js +95 -0
- package/lib/deploy/functions/services/database.js +14 -0
- package/lib/deploy/functions/services/firebaseAlerts.js +14 -0
- package/lib/deploy/functions/services/firestore.js +17 -0
- package/lib/deploy/functions/services/index.js +117 -0
- package/lib/deploy/functions/services/remoteConfig.js +14 -0
- package/lib/deploy/functions/services/storage.js +44 -0
- package/lib/deploy/functions/services/testLab.js +14 -0
- package/lib/deploy/functions/triggerRegionHelper.js +16 -0
- package/lib/deploy/functions/validate.js +198 -0
- package/lib/deploy/hosting/args.js +2 -0
- package/lib/deploy/hosting/context.js +2 -0
- package/lib/deploy/hosting/convertConfig.js +181 -0
- package/lib/deploy/hosting/deploy.js +85 -0
- package/lib/deploy/hosting/hashcache.js +48 -0
- package/lib/deploy/hosting/index.js +9 -0
- package/lib/deploy/hosting/prepare.js +162 -0
- package/lib/deploy/hosting/release.js +40 -0
- package/lib/deploy/hosting/uploader.js +207 -0
- package/lib/deploy/index.js +127 -0
- package/lib/deploy/lifecycleHooks.js +151 -0
- package/lib/deploy/remoteconfig/deploy.js +4 -0
- package/lib/deploy/remoteconfig/functions.js +69 -0
- package/lib/deploy/remoteconfig/index.js +9 -0
- package/lib/deploy/remoteconfig/prepare.js +23 -0
- package/lib/deploy/remoteconfig/release.js +14 -0
- package/lib/deploy/storage/deploy.js +12 -0
- package/lib/deploy/storage/index.js +9 -0
- package/lib/deploy/storage/prepare.js +52 -0
- package/lib/deploy/storage/release.js +27 -0
- package/lib/deploymentTool.js +22 -0
- package/lib/detectProjectRoot.js +28 -0
- package/lib/downloadUtils.js +37 -0
- package/lib/dynamicImport.js +22 -0
- package/lib/emulator/ExpressBasedEmulator.js +92 -0
- package/lib/emulator/adminSdkConfig.js +65 -0
- package/lib/emulator/auth/apiSpec.js +8138 -0
- package/lib/emulator/auth/cloudFunctions.js +70 -0
- package/lib/emulator/auth/errors.js +77 -0
- package/lib/emulator/auth/handlers.js +281 -0
- package/lib/emulator/auth/index.js +146 -0
- package/lib/emulator/auth/operations.js +2145 -0
- package/lib/emulator/auth/schema.js +2 -0
- package/lib/emulator/auth/server.js +474 -0
- package/lib/emulator/auth/state.js +668 -0
- package/lib/emulator/auth/types.js +2 -0
- package/lib/emulator/auth/utils.js +84 -0
- package/lib/emulator/auth/widget_ui.js +620 -0
- package/lib/emulator/commandUtils.js +380 -0
- package/lib/emulator/constants.js +111 -0
- package/lib/emulator/controller.js +654 -0
- package/lib/emulator/databaseEmulator.js +172 -0
- package/lib/emulator/dns.js +49 -0
- package/lib/emulator/download.js +88 -0
- package/lib/emulator/downloadableEmulators.js +384 -0
- package/lib/emulator/emulatorLogger.js +237 -0
- package/lib/emulator/env.js +37 -0
- package/lib/emulator/eventarcEmulator.js +143 -0
- package/lib/emulator/eventarcEmulatorUtils.js +62 -0
- package/lib/emulator/events/types.js +28 -0
- package/lib/emulator/extensions/postinstall.js +41 -0
- package/lib/emulator/extensions/validation.js +72 -0
- package/lib/emulator/extensionsEmulator.js +254 -0
- package/lib/emulator/firestoreEmulator.js +96 -0
- package/lib/emulator/functionsEmulator.js +1038 -0
- package/lib/emulator/functionsEmulatorRuntime.js +730 -0
- package/lib/emulator/functionsEmulatorShared.js +322 -0
- package/lib/emulator/functionsEmulatorShell.js +88 -0
- package/lib/emulator/functionsEmulatorUtils.js +91 -0
- package/lib/emulator/functionsRuntimeWorker.js +314 -0
- package/lib/emulator/hostingEmulator.js +40 -0
- package/lib/emulator/hub.js +162 -0
- package/lib/emulator/hubClient.js +53 -0
- package/lib/emulator/hubExport.js +208 -0
- package/lib/emulator/loggingEmulator.js +118 -0
- package/lib/emulator/portUtils.js +323 -0
- package/lib/emulator/pubsubEmulator.js +186 -0
- package/lib/emulator/registry.js +122 -0
- package/lib/emulator/shared/request.js +19 -0
- package/lib/emulator/storage/apis/firebase.js +500 -0
- package/lib/emulator/storage/apis/gcloud.js +405 -0
- package/lib/emulator/storage/apis/shared.js +44 -0
- package/lib/emulator/storage/cloudFunctions.js +88 -0
- package/lib/emulator/storage/crc.js +33 -0
- package/lib/emulator/storage/errors.js +9 -0
- package/lib/emulator/storage/files.js +410 -0
- package/lib/emulator/storage/index.js +98 -0
- package/lib/emulator/storage/metadata.js +349 -0
- package/lib/emulator/storage/multipart.js +63 -0
- package/lib/emulator/storage/persistence.js +92 -0
- package/lib/emulator/storage/rules/config.js +53 -0
- package/lib/emulator/storage/rules/expressionValue.js +2 -0
- package/lib/emulator/storage/rules/manager.js +88 -0
- package/lib/emulator/storage/rules/runtime.js +363 -0
- package/lib/emulator/storage/rules/types.js +19 -0
- package/lib/emulator/storage/rules/utils.js +60 -0
- package/lib/emulator/storage/server.js +113 -0
- package/lib/emulator/storage/upload.js +143 -0
- package/lib/emulator/types.js +200 -0
- package/lib/emulator/ui.js +52 -0
- package/lib/emulator/workQueue.js +114 -0
- package/lib/ensureApiEnabled.js +110 -0
- package/lib/ensureCloudResourceLocation.js +12 -0
- package/lib/error.js +29 -0
- package/lib/errorOut.js +23 -0
- package/lib/experiments.js +153 -0
- package/lib/extensions/askUserForEventsConfig.js +97 -0
- package/lib/extensions/askUserForParam.js +338 -0
- package/lib/extensions/billingMigrationHelper.js +61 -0
- package/lib/extensions/change-log.js +95 -0
- package/lib/extensions/checkProjectBilling.js +82 -0
- package/lib/extensions/diagnose.js +56 -0
- package/lib/extensions/displayExtensionInfo.js +175 -0
- package/lib/extensions/emulator/optionsHelper.js +73 -0
- package/lib/extensions/emulator/specHelper.js +102 -0
- package/lib/extensions/emulator/triggerHelper.js +105 -0
- package/lib/extensions/etags.js +28 -0
- package/lib/extensions/export.js +64 -0
- package/lib/extensions/extensionsApi.js +361 -0
- package/lib/extensions/extensionsHelper.js +862 -0
- package/lib/extensions/listExtensions.js +53 -0
- package/lib/extensions/localHelper.js +67 -0
- package/lib/extensions/manifest.js +205 -0
- package/lib/extensions/metricsTypeDef.js +2 -0
- package/lib/extensions/metricsUtils.js +98 -0
- package/lib/extensions/paramHelper.js +140 -0
- package/lib/extensions/provisioningHelper.js +109 -0
- package/lib/extensions/publishHelpers.js +8 -0
- package/lib/extensions/publisherApi.js +214 -0
- package/lib/extensions/refs.js +67 -0
- package/lib/extensions/resolveSource.js +24 -0
- package/lib/extensions/secretsUtils.js +60 -0
- package/lib/extensions/tos.js +90 -0
- package/lib/extensions/types.js +25 -0
- package/lib/extensions/updateHelper.js +127 -0
- package/lib/extensions/utils.js +63 -0
- package/lib/extensions/versionHelper.js +14 -0
- package/lib/extensions/warnings.js +44 -0
- package/lib/fetchMOTD.js +46 -0
- package/lib/fetchWebSetup.js +75 -0
- package/lib/filterTargets.js +34 -0
- package/lib/firebaseConfig.js +2 -0
- package/lib/firebaseConfigValidate.js +29 -0
- package/lib/firestore/api-sort.js +118 -0
- package/lib/firestore/api-spec.js +2 -0
- package/lib/firestore/api-types.js +60 -0
- package/lib/firestore/api.js +566 -0
- package/lib/firestore/checkDatabaseType.js +18 -0
- package/lib/firestore/delete.js +347 -0
- package/lib/firestore/encodeFirestoreValue.js +59 -0
- package/lib/firestore/fsConfig.js +74 -0
- package/lib/firestore/options.js +2 -0
- package/lib/firestore/util.js +39 -0
- package/lib/firestore/validator.js +38 -0
- package/lib/frameworks/angular/index.js +193 -0
- package/lib/frameworks/angular/interfaces.js +2 -0
- package/lib/frameworks/angular/utils.js +431 -0
- package/lib/frameworks/astro/index.js +73 -0
- package/lib/frameworks/astro/utils.js +40 -0
- package/lib/frameworks/compose/discover/filesystem.js +52 -0
- package/lib/frameworks/compose/discover/frameworkMatcher.js +76 -0
- package/lib/frameworks/compose/discover/frameworkSpec.js +39 -0
- package/lib/frameworks/compose/discover/index.js +32 -0
- package/lib/frameworks/compose/discover/runtime/node.js +149 -0
- package/lib/frameworks/compose/discover/types.js +2 -0
- package/lib/frameworks/compose/driver/docker.js +187 -0
- package/lib/frameworks/compose/driver/hooks.js +22 -0
- package/lib/frameworks/compose/driver/index.js +16 -0
- package/lib/frameworks/compose/driver/local.js +51 -0
- package/lib/frameworks/compose/index.js +31 -0
- package/lib/frameworks/compose/interfaces.js +21 -0
- package/lib/frameworks/constants.js +40 -0
- package/lib/frameworks/docs/index.js +2 -0
- package/lib/frameworks/express/index.js +102 -0
- package/lib/frameworks/flutter/constants.js +72 -0
- package/lib/frameworks/flutter/index.js +58 -0
- package/lib/frameworks/flutter/utils.js +11 -0
- package/lib/frameworks/frameworks.js +31 -0
- package/lib/frameworks/index.js +421 -0
- package/lib/frameworks/interfaces.js +2 -0
- package/lib/frameworks/lit/index.js +23 -0
- package/lib/frameworks/next/constants.js +12 -0
- package/lib/frameworks/next/index.js +403 -0
- package/lib/frameworks/next/interfaces.js +2 -0
- package/lib/frameworks/next/utils.js +197 -0
- package/lib/frameworks/nuxt/index.js +92 -0
- package/lib/frameworks/nuxt/interfaces.js +2 -0
- package/lib/frameworks/nuxt/utils.js +23 -0
- package/lib/frameworks/nuxt2/index.js +79 -0
- package/lib/frameworks/preact/index.js +23 -0
- package/lib/frameworks/react/index.js +23 -0
- package/lib/frameworks/svelte/index.js +23 -0
- package/lib/frameworks/sveltekit/index.js +54 -0
- package/lib/frameworks/sveltekit/interfaces.js +2 -0
- package/lib/frameworks/utils.js +260 -0
- package/lib/frameworks/vite/index.js +99 -0
- package/lib/fsAsync.js +43 -0
- package/lib/fsutils.js +35 -0
- package/lib/functional.js +87 -0
- package/lib/functions/constants.js +14 -0
- package/lib/functions/ensureTargeted.js +21 -0
- package/lib/functions/env.js +246 -0
- package/lib/functions/events/index.js +7 -0
- package/lib/functions/events/v1.js +6 -0
- package/lib/functions/events/v2.js +25 -0
- package/lib/functions/functionslog.js +35 -0
- package/lib/functions/projectConfig.js +68 -0
- package/lib/functions/python.js +23 -0
- package/lib/functions/runtimeConfigExport.js +141 -0
- package/lib/functions/secrets.js +239 -0
- package/lib/functionsConfig.js +157 -0
- package/lib/functionsConfigClone.js +68 -0
- package/lib/functionsShellCommandAction.js +112 -0
- package/lib/gcp/artifactregistry.js +16 -0
- package/lib/gcp/auth.js +16 -0
- package/lib/gcp/cloudbilling.js +25 -0
- package/lib/gcp/cloudbuild.js +50 -0
- package/lib/gcp/cloudfunctions.js +351 -0
- package/lib/gcp/cloudfunctionsv2.js +389 -0
- package/lib/gcp/cloudlogging.js +25 -0
- package/lib/gcp/cloudmonitoring.js +77 -0
- package/lib/gcp/cloudscheduler.js +155 -0
- package/lib/gcp/cloudtasks.js +162 -0
- package/lib/gcp/docker.js +80 -0
- package/lib/gcp/eventarc.js +42 -0
- package/lib/gcp/firestore.js +47 -0
- package/lib/gcp/frameworks.js +40 -0
- package/lib/gcp/iam.js +76 -0
- package/lib/gcp/identityPlatform.js +44 -0
- package/lib/gcp/index.js +11 -0
- package/lib/gcp/location.js +44 -0
- package/lib/gcp/proto.js +130 -0
- package/lib/gcp/pubsub.js +34 -0
- package/lib/gcp/resourceManager.js +74 -0
- package/lib/gcp/rules.js +156 -0
- package/lib/gcp/run.js +157 -0
- package/lib/gcp/runtimeconfig.js +127 -0
- package/lib/gcp/secretManager.js +207 -0
- package/lib/gcp/serviceusage.js +24 -0
- package/lib/gcp/storage.js +111 -0
- package/lib/getDefaultDatabaseInstance.js +10 -0
- package/lib/getDefaultHostingSite.js +32 -0
- package/lib/getProjectNumber.js +15 -0
- package/lib/handlePreviewToggles.js +38 -0
- package/lib/hosting/api.js +289 -0
- package/lib/hosting/cloudRunProxy.js +52 -0
- package/lib/hosting/config.js +189 -0
- package/lib/hosting/expireUtils.js +33 -0
- package/lib/hosting/functionsProxy.js +42 -0
- package/lib/hosting/implicitInit.js +58 -0
- package/lib/hosting/initMiddleware.js +63 -0
- package/lib/hosting/interactive.js +75 -0
- package/lib/hosting/options.js +3 -0
- package/lib/hosting/proxy.js +143 -0
- package/lib/hosting/runTags.js +114 -0
- package/lib/index.js +71 -0
- package/lib/init/features/account.js +62 -0
- package/lib/init/features/database.js +133 -0
- package/lib/init/features/emulators.js +102 -0
- package/lib/init/features/extensions/index.js +16 -0
- package/lib/init/features/firestore/index.js +36 -0
- package/lib/init/features/firestore/indexes.js +71 -0
- package/lib/init/features/firestore/rules.js +80 -0
- package/lib/init/features/frameworks/constants.js +7 -0
- package/lib/init/features/frameworks/index.js +116 -0
- package/lib/init/features/frameworks/repo.js +125 -0
- package/lib/init/features/functions/index.js +165 -0
- package/lib/init/features/functions/javascript.js +46 -0
- package/lib/init/features/functions/npm-dependencies.js +37 -0
- package/lib/init/features/functions/python.js +48 -0
- package/lib/init/features/functions/typescript.js +61 -0
- package/lib/init/features/hosting/github.js +397 -0
- package/lib/init/features/hosting/index.js +183 -0
- package/lib/init/features/index.js +27 -0
- package/lib/init/features/project.js +101 -0
- package/lib/init/features/remoteconfig.js +32 -0
- package/lib/init/features/storage.js +27 -0
- package/lib/init/index.js +45 -0
- package/lib/listFiles.js +15 -0
- package/lib/loadCJSON.js +17 -0
- package/lib/localFunction.js +222 -0
- package/lib/logError.js +29 -0
- package/lib/logger.js +31 -0
- package/lib/management/apps.js +280 -0
- package/lib/management/database.js +184 -0
- package/lib/management/projects.js +312 -0
- package/lib/metaprogramming.js +2 -0
- package/lib/monospace/index.js +82 -0
- package/lib/monospace/interfaces.js +2 -0
- package/lib/operation-poller.js +59 -0
- package/lib/options.js +2 -0
- package/lib/parseBoltRules.js +29 -0
- package/lib/profileReport.js +577 -0
- package/lib/profiler.js +99 -0
- package/lib/projectPath.js +16 -0
- package/lib/projectUtils.js +59 -0
- package/lib/prompt.js +50 -0
- package/lib/rc.js +165 -0
- package/lib/remoteconfig/get.js +49 -0
- package/lib/remoteconfig/interfaces.js +17 -0
- package/lib/remoteconfig/rollback.js +22 -0
- package/lib/remoteconfig/versionslist.js +33 -0
- package/lib/requireAuth.js +81 -0
- package/lib/requireConfig.js +13 -0
- package/lib/requireDatabaseInstance.js +26 -0
- package/lib/requireHostingSite.js +12 -0
- package/lib/requireInteractive.js +12 -0
- package/lib/requirePermissions.js +30 -0
- package/lib/responseToError.js +58 -0
- package/lib/rtdb.js +35 -0
- package/lib/rulesDeploy.js +180 -0
- package/lib/scopes.js +10 -0
- package/lib/serve/functions.js +64 -0
- package/lib/serve/hosting.js +115 -0
- package/lib/serve/index.js +53 -0
- package/lib/shortenUrl.js +29 -0
- package/lib/throttler/errors/retries-exhausted-error.js +11 -0
- package/lib/throttler/errors/task-error.js +9 -0
- package/lib/throttler/errors/timeout-error.js +9 -0
- package/lib/throttler/queue.js +23 -0
- package/lib/throttler/stack.js +28 -0
- package/lib/throttler/throttler.js +230 -0
- package/lib/track.js +196 -0
- package/lib/unzip.js +126 -0
- package/lib/utils.js +488 -0
- package/package.json +239 -0
- package/schema/extension-yaml.json +432 -0
- package/schema/firebase-config.json +2619 -0
- package/standalone/check.js +6 -0
- package/standalone/config.template.js +19 -0
- package/standalone/firepit.js +1074 -0
- package/standalone/package-lock.json +7019 -0
- package/standalone/package.json +36 -0
- package/standalone/runtime.js +122 -0
- package/standalone/welcome.js +178 -0
- package/templates/_gitignore +66 -0
- package/templates/banner.txt +6 -0
- package/templates/emulators/default_storage.rules +8 -0
- package/templates/extensions/CL-template.md +2 -0
- package/templates/extensions/POSTINSTALL.md +29 -0
- package/templates/extensions/PREINSTALL.md +22 -0
- package/templates/extensions/extension.yaml +61 -0
- package/templates/extensions/integration-test.env +2 -0
- package/templates/extensions/integration-test.json +14 -0
- package/templates/extensions/javascript/WELCOME.md +18 -0
- package/templates/extensions/javascript/_gitignore +1 -0
- package/templates/extensions/javascript/index.js +25 -0
- package/templates/extensions/javascript/integration-test.js +13 -0
- package/templates/extensions/javascript/package.lint.json +25 -0
- package/templates/extensions/javascript/package.nolint.json +19 -0
- package/templates/extensions/typescript/WELCOME.md +22 -0
- package/templates/extensions/typescript/_gitignore +8 -0
- package/templates/extensions/typescript/_mocharc +10 -0
- package/templates/extensions/typescript/index.ts +26 -0
- package/templates/extensions/typescript/integration-test.ts +13 -0
- package/templates/extensions/typescript/package.lint.json +31 -0
- package/templates/extensions/typescript/package.nolint.json +24 -0
- package/templates/extensions/typescript/tsconfig.dev.json +5 -0
- package/templates/extensions/typescript/tsconfig.json +15 -0
- package/templates/firebase.json +9 -0
- package/templates/hosting/init.js +36 -0
- package/templates/init/firestore/firestore.indexes.json +26 -0
- package/templates/init/firestore/firestore.rules +16 -0
- package/templates/init/functions/javascript/_eslintrc +28 -0
- package/templates/init/functions/javascript/_gitignore +1 -0
- package/templates/init/functions/javascript/index.js +19 -0
- package/templates/init/functions/javascript/package.lint.json +26 -0
- package/templates/init/functions/javascript/package.nolint.json +23 -0
- package/templates/init/functions/python/_gitignore +0 -0
- package/templates/init/functions/python/main.py +13 -0
- package/templates/init/functions/python/requirements.txt +1 -0
- package/templates/init/functions/typescript/_eslintrc +32 -0
- package/templates/init/functions/typescript/_gitignore +9 -0
- package/templates/init/functions/typescript/index.ts +19 -0
- package/templates/init/functions/typescript/package.lint.json +31 -0
- package/templates/init/functions/typescript/package.nolint.json +25 -0
- package/templates/init/functions/typescript/tsconfig.dev.json +5 -0
- package/templates/init/functions/typescript/tsconfig.json +15 -0
- package/templates/init/hosting/404.html +33 -0
- package/templates/init/hosting/index.html +89 -0
- package/templates/init/storage/storage.rules +12 -0
- package/templates/loginFailure.html +34 -0
- package/templates/loginSuccess.html +32 -0
- package/templates/loginSuccessGithub.html +32 -0
- package/templates/setup/web.js +5 -0
|
@@ -0,0 +1,1038 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FunctionsEmulator = exports.TCPConn = exports.IPCConn = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const express = require("express");
|
|
7
|
+
const clc = require("colorette");
|
|
8
|
+
const http = require("http");
|
|
9
|
+
const jwt = require("jsonwebtoken");
|
|
10
|
+
const cors = require("cors");
|
|
11
|
+
const semver = require("semver");
|
|
12
|
+
const url_1 = require("url");
|
|
13
|
+
const events_1 = require("events");
|
|
14
|
+
const logger_1 = require("../logger");
|
|
15
|
+
const track_1 = require("../track");
|
|
16
|
+
const constants_1 = require("./constants");
|
|
17
|
+
const types_1 = require("./types");
|
|
18
|
+
const chokidar = require("chokidar");
|
|
19
|
+
const portfinder = require("portfinder");
|
|
20
|
+
const spawn = require("cross-spawn");
|
|
21
|
+
const functionsEmulatorShared_1 = require("./functionsEmulatorShared");
|
|
22
|
+
const registry_1 = require("./registry");
|
|
23
|
+
const emulatorLogger_1 = require("./emulatorLogger");
|
|
24
|
+
const functionsRuntimeWorker_1 = require("./functionsRuntimeWorker");
|
|
25
|
+
const error_1 = require("../error");
|
|
26
|
+
const workQueue_1 = require("./workQueue");
|
|
27
|
+
const utils_1 = require("../utils");
|
|
28
|
+
const defaultCredentials_1 = require("../defaultCredentials");
|
|
29
|
+
const adminSdkConfig_1 = require("./adminSdkConfig");
|
|
30
|
+
const validate_1 = require("../deploy/functions/validate");
|
|
31
|
+
const secretManager_1 = require("../gcp/secretManager");
|
|
32
|
+
const runtimes = require("../deploy/functions/runtimes");
|
|
33
|
+
const backend = require("../deploy/functions/backend");
|
|
34
|
+
const functionsEnv = require("../functions/env");
|
|
35
|
+
const v1_1 = require("../functions/events/v1");
|
|
36
|
+
const build_1 = require("../deploy/functions/build");
|
|
37
|
+
const env_1 = require("./env");
|
|
38
|
+
const python_1 = require("../functions/python");
|
|
39
|
+
const EVENT_INVOKE_GA4 = "functions_invoke";
|
|
40
|
+
const DATABASE_PATH_PATTERN = new RegExp("^projects/[^/]+/instances/([^/]+)/refs(/.*)$");
|
|
41
|
+
class IPCConn {
|
|
42
|
+
constructor(socketPath) {
|
|
43
|
+
this.socketPath = socketPath;
|
|
44
|
+
}
|
|
45
|
+
httpReqOpts() {
|
|
46
|
+
return {
|
|
47
|
+
socketPath: this.socketPath,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.IPCConn = IPCConn;
|
|
52
|
+
class TCPConn {
|
|
53
|
+
constructor(host, port) {
|
|
54
|
+
this.host = host;
|
|
55
|
+
this.port = port;
|
|
56
|
+
}
|
|
57
|
+
httpReqOpts() {
|
|
58
|
+
return {
|
|
59
|
+
host: this.host,
|
|
60
|
+
port: this.port,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.TCPConn = TCPConn;
|
|
65
|
+
class FunctionsEmulator {
|
|
66
|
+
static getHttpFunctionUrl(projectId, name, region, info) {
|
|
67
|
+
let url;
|
|
68
|
+
if (info) {
|
|
69
|
+
url = new url_1.URL("http://" + (0, functionsEmulatorShared_1.formatHost)(info));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
url = registry_1.EmulatorRegistry.url(types_1.Emulators.FUNCTIONS);
|
|
73
|
+
}
|
|
74
|
+
url.pathname = `/${projectId}/${region}/${name}`;
|
|
75
|
+
return url.toString();
|
|
76
|
+
}
|
|
77
|
+
constructor(args) {
|
|
78
|
+
this.args = args;
|
|
79
|
+
this.triggers = {};
|
|
80
|
+
this.triggerGeneration = 0;
|
|
81
|
+
this.logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.FUNCTIONS);
|
|
82
|
+
this.multicastTriggers = {};
|
|
83
|
+
this.blockingFunctionsConfig = {};
|
|
84
|
+
this.debugMode = false;
|
|
85
|
+
emulatorLogger_1.EmulatorLogger.setVerbosity(this.args.verbosity ? emulatorLogger_1.Verbosity[this.args.verbosity] : emulatorLogger_1.Verbosity["DEBUG"]);
|
|
86
|
+
if (this.args.debugPort) {
|
|
87
|
+
this.args.disabledRuntimeFeatures = this.args.disabledRuntimeFeatures || {};
|
|
88
|
+
this.args.disabledRuntimeFeatures.timeout = true;
|
|
89
|
+
this.debugMode = true;
|
|
90
|
+
}
|
|
91
|
+
this.adminSdkConfig = Object.assign(Object.assign({}, this.args.adminSdkConfig), { projectId: this.args.projectId });
|
|
92
|
+
const mode = this.debugMode ? types_1.FunctionsExecutionMode.SEQUENTIAL : types_1.FunctionsExecutionMode.AUTO;
|
|
93
|
+
this.workerPools = {};
|
|
94
|
+
for (const backend of this.args.emulatableBackends) {
|
|
95
|
+
const pool = new functionsRuntimeWorker_1.RuntimeWorkerPool(mode);
|
|
96
|
+
this.workerPools[backend.codebase] = pool;
|
|
97
|
+
}
|
|
98
|
+
this.workQueue = new workQueue_1.WorkQueue(mode);
|
|
99
|
+
}
|
|
100
|
+
async getCredentialsEnvironment() {
|
|
101
|
+
const credentialEnv = {};
|
|
102
|
+
if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
|
|
103
|
+
this.logger.logLabeled("WARN", "functions", `Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to ${process.env.GOOGLE_APPLICATION_CREDENTIALS}. Non-emulated services will access production using these credentials. Be careful!`);
|
|
104
|
+
}
|
|
105
|
+
else if (this.args.account) {
|
|
106
|
+
const defaultCredPath = await (0, defaultCredentials_1.getCredentialPathAsync)(this.args.account);
|
|
107
|
+
if (defaultCredPath) {
|
|
108
|
+
this.logger.log("DEBUG", `Setting GAC to ${defaultCredPath}`);
|
|
109
|
+
credentialEnv.GOOGLE_APPLICATION_CREDENTIALS = defaultCredPath;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
this.logger.logLabeled("WARN", "functions", "You are not signed in to the Firebase CLI. If you have authorized this machine using gcloud application-default credentials those may be discovered and used to access production services.");
|
|
114
|
+
}
|
|
115
|
+
return credentialEnv;
|
|
116
|
+
}
|
|
117
|
+
createHubServer() {
|
|
118
|
+
this.workQueue.start();
|
|
119
|
+
const hub = express();
|
|
120
|
+
const dataMiddleware = (req, res, next) => {
|
|
121
|
+
const chunks = [];
|
|
122
|
+
req.on("data", (chunk) => {
|
|
123
|
+
chunks.push(chunk);
|
|
124
|
+
});
|
|
125
|
+
req.on("end", () => {
|
|
126
|
+
req.rawBody = Buffer.concat(chunks);
|
|
127
|
+
next();
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
const backgroundFunctionRoute = `/functions/projects/:project_id/triggers/:trigger_name(*)`;
|
|
131
|
+
const httpsFunctionRoute = `/${this.args.projectId}/:region/:trigger_name`;
|
|
132
|
+
const multicastFunctionRoute = `/functions/projects/:project_id/trigger_multicast`;
|
|
133
|
+
const httpsFunctionRoutes = [httpsFunctionRoute, `${httpsFunctionRoute}/*`];
|
|
134
|
+
const listBackendsRoute = `/backends`;
|
|
135
|
+
const httpsHandler = (req, res) => {
|
|
136
|
+
const work = () => {
|
|
137
|
+
return this.handleHttpsTrigger(req, res);
|
|
138
|
+
};
|
|
139
|
+
work.type = `${req.path}-${new Date().toISOString()}`;
|
|
140
|
+
this.workQueue.submit(work);
|
|
141
|
+
};
|
|
142
|
+
const multicastHandler = (req, res) => {
|
|
143
|
+
var _a;
|
|
144
|
+
const projectId = req.params.project_id;
|
|
145
|
+
const rawBody = req.rawBody;
|
|
146
|
+
const event = JSON.parse(rawBody.toString());
|
|
147
|
+
let triggerKey;
|
|
148
|
+
if ((_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.includes("cloudevent")) {
|
|
149
|
+
triggerKey = `${this.args.projectId}:${event.type}`;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
triggerKey = `${this.args.projectId}:${event.eventType}`;
|
|
153
|
+
}
|
|
154
|
+
if (event.data.bucket) {
|
|
155
|
+
triggerKey += `:${event.data.bucket}`;
|
|
156
|
+
}
|
|
157
|
+
const triggers = this.multicastTriggers[triggerKey] || [];
|
|
158
|
+
const { host, port } = this.getInfo();
|
|
159
|
+
triggers.forEach((triggerId) => {
|
|
160
|
+
const work = () => {
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
const trigReq = http.request({
|
|
163
|
+
host: (0, utils_1.connectableHostname)(host),
|
|
164
|
+
port,
|
|
165
|
+
method: req.method,
|
|
166
|
+
path: `/functions/projects/${projectId}/triggers/${triggerId}`,
|
|
167
|
+
headers: req.headers,
|
|
168
|
+
});
|
|
169
|
+
trigReq.on("error", reject);
|
|
170
|
+
trigReq.write(rawBody);
|
|
171
|
+
trigReq.end();
|
|
172
|
+
resolve();
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
work.type = `${triggerId}-${new Date().toISOString()}`;
|
|
176
|
+
this.workQueue.submit(work);
|
|
177
|
+
});
|
|
178
|
+
res.json({ status: "multicast_acknowledged" });
|
|
179
|
+
};
|
|
180
|
+
const listBackendsHandler = (req, res) => {
|
|
181
|
+
res.json({ backends: this.getBackendInfo() });
|
|
182
|
+
};
|
|
183
|
+
hub.get(listBackendsRoute, cors({ origin: true }), listBackendsHandler);
|
|
184
|
+
hub.post(backgroundFunctionRoute, dataMiddleware, httpsHandler);
|
|
185
|
+
hub.post(multicastFunctionRoute, dataMiddleware, multicastHandler);
|
|
186
|
+
hub.all(httpsFunctionRoutes, dataMiddleware, httpsHandler);
|
|
187
|
+
hub.all("*", dataMiddleware, (req, res) => {
|
|
188
|
+
logger_1.logger.debug(`Functions emulator received unknown request at path ${req.path}`);
|
|
189
|
+
res.sendStatus(404);
|
|
190
|
+
});
|
|
191
|
+
return hub;
|
|
192
|
+
}
|
|
193
|
+
async sendRequest(trigger, body) {
|
|
194
|
+
const record = this.getTriggerRecordByKey(this.getTriggerKey(trigger));
|
|
195
|
+
const pool = this.workerPools[record.backend.codebase];
|
|
196
|
+
if (!pool.readyForWork(trigger.id)) {
|
|
197
|
+
try {
|
|
198
|
+
await this.startRuntime(record.backend, trigger);
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
this.logger.logLabeled("ERROR", `Failed to start runtime for ${trigger.id}: ${e}`);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const worker = pool.getIdleWorker(trigger.id);
|
|
206
|
+
if (this.debugMode) {
|
|
207
|
+
await worker.sendDebugMsg({
|
|
208
|
+
functionTarget: trigger.entryPoint,
|
|
209
|
+
functionSignature: (0, functionsEmulatorShared_1.getSignatureType)(trigger),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const reqBody = JSON.stringify(body);
|
|
213
|
+
const headers = {
|
|
214
|
+
"Content-Type": "application/json",
|
|
215
|
+
"Content-Length": `${reqBody.length}`,
|
|
216
|
+
};
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
const req = http.request(Object.assign(Object.assign({}, worker.runtime.conn.httpReqOpts()), { path: `/`, headers: headers }), resolve);
|
|
219
|
+
req.on("error", reject);
|
|
220
|
+
req.write(reqBody);
|
|
221
|
+
req.end();
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
async start() {
|
|
225
|
+
const credentialEnv = await this.getCredentialsEnvironment();
|
|
226
|
+
for (const e of this.args.emulatableBackends) {
|
|
227
|
+
e.env = Object.assign(Object.assign({}, credentialEnv), e.env);
|
|
228
|
+
}
|
|
229
|
+
if (Object.keys(this.adminSdkConfig || {}).length <= 1) {
|
|
230
|
+
const adminSdkConfig = await (0, adminSdkConfig_1.getProjectAdminSdkConfigOrCached)(this.args.projectId);
|
|
231
|
+
if (adminSdkConfig) {
|
|
232
|
+
this.adminSdkConfig = adminSdkConfig;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
this.logger.logLabeled("WARN", "functions", "Unable to fetch project Admin SDK configuration, Admin SDK behavior in Cloud Functions emulator may be incorrect.");
|
|
236
|
+
this.adminSdkConfig = (0, adminSdkConfig_1.constructDefaultAdminSdkConfig)(this.args.projectId);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const { host, port } = this.getInfo();
|
|
240
|
+
this.workQueue.start();
|
|
241
|
+
const server = this.createHubServer().listen(port, host);
|
|
242
|
+
this.destroyServer = (0, utils_1.createDestroyer)(server);
|
|
243
|
+
return Promise.resolve();
|
|
244
|
+
}
|
|
245
|
+
async connect() {
|
|
246
|
+
for (const backend of this.args.emulatableBackends) {
|
|
247
|
+
this.logger.logLabeled("BULLET", "functions", `Watching "${backend.functionsDir}" for Cloud Functions...`);
|
|
248
|
+
const watcher = chokidar.watch(backend.functionsDir, {
|
|
249
|
+
ignored: [
|
|
250
|
+
/.+?[\\\/]node_modules[\\\/].+?/,
|
|
251
|
+
/(^|[\/\\])\../,
|
|
252
|
+
/.+\.log/,
|
|
253
|
+
/.+?[\\\/]venv[\\\/].+?/,
|
|
254
|
+
],
|
|
255
|
+
persistent: true,
|
|
256
|
+
});
|
|
257
|
+
const debouncedLoadTriggers = (0, utils_1.debounce)(() => this.loadTriggers(backend), 1000);
|
|
258
|
+
watcher.on("change", (filePath) => {
|
|
259
|
+
this.logger.log("DEBUG", `File ${filePath} changed, reloading triggers`);
|
|
260
|
+
return debouncedLoadTriggers();
|
|
261
|
+
});
|
|
262
|
+
await this.loadTriggers(backend, true);
|
|
263
|
+
}
|
|
264
|
+
await this.performPostLoadOperations();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
async stop() {
|
|
268
|
+
try {
|
|
269
|
+
await this.workQueue.flush();
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
this.logger.logLabeled("WARN", "functions", "Functions emulator work queue did not empty before stopping");
|
|
273
|
+
}
|
|
274
|
+
this.workQueue.stop();
|
|
275
|
+
for (const pool of Object.values(this.workerPools)) {
|
|
276
|
+
pool.exit();
|
|
277
|
+
}
|
|
278
|
+
if (this.destroyServer) {
|
|
279
|
+
await this.destroyServer();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async discoverTriggers(emulatableBackend) {
|
|
283
|
+
if (emulatableBackend.predefinedTriggers) {
|
|
284
|
+
return (0, functionsEmulatorShared_1.emulatedFunctionsByRegion)(emulatableBackend.predefinedTriggers, emulatableBackend.secretEnv);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const runtimeConfig = this.getRuntimeConfig(emulatableBackend);
|
|
288
|
+
const runtimeDelegateContext = {
|
|
289
|
+
projectId: this.args.projectId,
|
|
290
|
+
projectDir: this.args.projectDir,
|
|
291
|
+
sourceDir: emulatableBackend.functionsDir,
|
|
292
|
+
runtime: emulatableBackend.runtime,
|
|
293
|
+
};
|
|
294
|
+
const runtimeDelegate = await runtimes.getRuntimeDelegate(runtimeDelegateContext);
|
|
295
|
+
logger_1.logger.debug(`Validating ${runtimeDelegate.name} source`);
|
|
296
|
+
await runtimeDelegate.validate();
|
|
297
|
+
logger_1.logger.debug(`Building ${runtimeDelegate.name} source`);
|
|
298
|
+
await runtimeDelegate.build();
|
|
299
|
+
emulatableBackend.runtime = runtimeDelegate.runtime;
|
|
300
|
+
emulatableBackend.bin = runtimeDelegate.bin;
|
|
301
|
+
const firebaseConfig = this.getFirebaseConfig();
|
|
302
|
+
const environment = Object.assign(Object.assign(Object.assign(Object.assign({}, this.getSystemEnvs()), this.getEmulatorEnvs()), { FIREBASE_CONFIG: firebaseConfig }), emulatableBackend.env);
|
|
303
|
+
const userEnvOpt = {
|
|
304
|
+
functionsSource: emulatableBackend.functionsDir,
|
|
305
|
+
projectId: this.args.projectId,
|
|
306
|
+
projectAlias: this.args.projectAlias,
|
|
307
|
+
isEmulator: true,
|
|
308
|
+
};
|
|
309
|
+
const userEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
|
|
310
|
+
const discoveredBuild = await runtimeDelegate.discoverBuild(runtimeConfig, environment);
|
|
311
|
+
const resolution = await (0, build_1.resolveBackend)(discoveredBuild, JSON.parse(firebaseConfig), userEnvOpt, userEnvs);
|
|
312
|
+
const discoveredBackend = resolution.backend;
|
|
313
|
+
const endpoints = backend.allEndpoints(discoveredBackend);
|
|
314
|
+
(0, functionsEmulatorShared_1.prepareEndpoints)(endpoints);
|
|
315
|
+
for (const e of endpoints) {
|
|
316
|
+
e.codebase = emulatableBackend.codebase;
|
|
317
|
+
}
|
|
318
|
+
return (0, functionsEmulatorShared_1.emulatedFunctionsFromEndpoints)(endpoints);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
async loadTriggers(emulatableBackend, force = false) {
|
|
322
|
+
var _a;
|
|
323
|
+
let triggerDefinitions = [];
|
|
324
|
+
try {
|
|
325
|
+
triggerDefinitions = await this.discoverTriggers(emulatableBackend);
|
|
326
|
+
this.logger.logLabeled("SUCCESS", "functions", `Loaded functions definitions from source: ${triggerDefinitions
|
|
327
|
+
.map((t) => t.entryPoint)
|
|
328
|
+
.join(", ")}.`);
|
|
329
|
+
}
|
|
330
|
+
catch (e) {
|
|
331
|
+
this.logger.logLabeled("ERROR", "functions", `Failed to load function definition from source: ${e}`);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (this.debugMode) {
|
|
335
|
+
this.workerPools[emulatableBackend.codebase].exit();
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
this.workerPools[emulatableBackend.codebase].refresh();
|
|
339
|
+
}
|
|
340
|
+
const toSetup = triggerDefinitions.filter((definition) => {
|
|
341
|
+
if (force) {
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
const anyEnabledMatch = Object.values(this.triggers).some((record) => {
|
|
345
|
+
const sameEntryPoint = record.def.entryPoint === definition.entryPoint;
|
|
346
|
+
const sameEventTrigger = JSON.stringify(record.def.eventTrigger) === JSON.stringify(definition.eventTrigger);
|
|
347
|
+
if (sameEntryPoint && !sameEventTrigger) {
|
|
348
|
+
this.logger.log("DEBUG", `Definition for trigger ${definition.entryPoint} changed from ${JSON.stringify(record.def.eventTrigger)} to ${JSON.stringify(definition.eventTrigger)}`);
|
|
349
|
+
}
|
|
350
|
+
return record.enabled && sameEntryPoint && sameEventTrigger;
|
|
351
|
+
});
|
|
352
|
+
return !anyEnabledMatch;
|
|
353
|
+
});
|
|
354
|
+
for (const definition of toSetup) {
|
|
355
|
+
try {
|
|
356
|
+
(0, validate_1.functionIdsAreValid)([Object.assign(Object.assign({}, definition), { id: definition.name })]);
|
|
357
|
+
}
|
|
358
|
+
catch (e) {
|
|
359
|
+
throw new error_1.FirebaseError(`functions[${definition.id}]: Invalid function id: ${e.message}`);
|
|
360
|
+
}
|
|
361
|
+
let added = false;
|
|
362
|
+
let url = undefined;
|
|
363
|
+
if (definition.httpsTrigger) {
|
|
364
|
+
added = true;
|
|
365
|
+
url = FunctionsEmulator.getHttpFunctionUrl(this.args.projectId, definition.name, definition.region);
|
|
366
|
+
}
|
|
367
|
+
else if (definition.eventTrigger) {
|
|
368
|
+
const service = (0, functionsEmulatorShared_1.getFunctionService)(definition);
|
|
369
|
+
const key = this.getTriggerKey(definition);
|
|
370
|
+
const signature = (0, functionsEmulatorShared_1.getSignatureType)(definition);
|
|
371
|
+
switch (service) {
|
|
372
|
+
case constants_1.Constants.SERVICE_FIRESTORE:
|
|
373
|
+
added = await this.addFirestoreTrigger(this.args.projectId, key, definition.eventTrigger, signature);
|
|
374
|
+
break;
|
|
375
|
+
case constants_1.Constants.SERVICE_REALTIME_DATABASE:
|
|
376
|
+
added = await this.addRealtimeDatabaseTrigger(this.args.projectId, definition.id, key, definition.eventTrigger, signature, definition.region);
|
|
377
|
+
break;
|
|
378
|
+
case constants_1.Constants.SERVICE_PUBSUB:
|
|
379
|
+
added = await this.addPubsubTrigger(definition.name, key, definition.eventTrigger, signature, definition.schedule);
|
|
380
|
+
break;
|
|
381
|
+
case constants_1.Constants.SERVICE_EVENTARC:
|
|
382
|
+
added = await this.addEventarcTrigger(this.args.projectId, key, definition.eventTrigger);
|
|
383
|
+
break;
|
|
384
|
+
case constants_1.Constants.SERVICE_AUTH:
|
|
385
|
+
added = this.addAuthTrigger(this.args.projectId, key, definition.eventTrigger);
|
|
386
|
+
break;
|
|
387
|
+
case constants_1.Constants.SERVICE_STORAGE:
|
|
388
|
+
added = this.addStorageTrigger(this.args.projectId, key, definition.eventTrigger);
|
|
389
|
+
break;
|
|
390
|
+
default:
|
|
391
|
+
this.logger.log("DEBUG", `Unsupported trigger: ${JSON.stringify(definition)}`);
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
else if (definition.blockingTrigger) {
|
|
396
|
+
url = FunctionsEmulator.getHttpFunctionUrl(this.args.projectId, definition.name, definition.region);
|
|
397
|
+
added = this.addBlockingTrigger(url, definition.blockingTrigger);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
this.logger.log("WARN", `Unsupported function type on ${definition.name}. Expected either an httpsTrigger, eventTrigger, or blockingTrigger.`);
|
|
401
|
+
}
|
|
402
|
+
const ignored = !added;
|
|
403
|
+
this.addTriggerRecord(definition, { backend: emulatableBackend, ignored, url });
|
|
404
|
+
const type = definition.httpsTrigger
|
|
405
|
+
? "http"
|
|
406
|
+
: constants_1.Constants.getServiceName((0, functionsEmulatorShared_1.getFunctionService)(definition));
|
|
407
|
+
if (ignored) {
|
|
408
|
+
const msg = `function ignored because the ${type} emulator does not exist or is not running.`;
|
|
409
|
+
this.logger.logLabeled("BULLET", `functions[${definition.id}]`, msg);
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
const msg = url
|
|
413
|
+
? `${clc.bold(type)} function initialized (${url}).`
|
|
414
|
+
: `${clc.bold(type)} function initialized.`;
|
|
415
|
+
this.logger.logLabeled("SUCCESS", `functions[${definition.id}]`, msg);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (this.debugMode) {
|
|
419
|
+
if (!((_a = emulatableBackend.runtime) === null || _a === void 0 ? void 0 : _a.startsWith("node"))) {
|
|
420
|
+
this.logger.log("WARN", "--inspect-functions only supported for Node.js runtimes.");
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
emulatableBackend.secretEnv = Object.values(triggerDefinitions.reduce((acc, curr) => {
|
|
424
|
+
for (const secret of curr.secretEnvironmentVariables || []) {
|
|
425
|
+
acc[secret.key] = secret;
|
|
426
|
+
}
|
|
427
|
+
return acc;
|
|
428
|
+
}, {}));
|
|
429
|
+
try {
|
|
430
|
+
await this.startRuntime(emulatableBackend);
|
|
431
|
+
}
|
|
432
|
+
catch (e) {
|
|
433
|
+
this.logger.logLabeled("ERROR", `Failed to start functions in ${emulatableBackend.functionsDir}: ${e}`);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
addEventarcTrigger(projectId, key, eventTrigger) {
|
|
439
|
+
if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
|
|
440
|
+
return Promise.resolve(false);
|
|
441
|
+
}
|
|
442
|
+
const bundle = {
|
|
443
|
+
eventTrigger: Object.assign(Object.assign({}, eventTrigger), { service: "eventarc.googleapis.com" }),
|
|
444
|
+
};
|
|
445
|
+
logger_1.logger.debug(`addEventarcTrigger`, JSON.stringify(bundle));
|
|
446
|
+
return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
|
|
447
|
+
.post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle)
|
|
448
|
+
.then(() => true)
|
|
449
|
+
.catch((err) => {
|
|
450
|
+
this.logger.log("WARN", "Error adding Eventarc function: " + err);
|
|
451
|
+
return false;
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
async performPostLoadOperations() {
|
|
455
|
+
if (!this.blockingFunctionsConfig.triggers &&
|
|
456
|
+
!this.blockingFunctionsConfig.forwardInboundCredentials) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.AUTH)) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
const path = `/identitytoolkit.googleapis.com/v2/projects/${this.getProjectId()}/config?updateMask=blockingFunctions`;
|
|
463
|
+
try {
|
|
464
|
+
const client = registry_1.EmulatorRegistry.client(types_1.Emulators.AUTH);
|
|
465
|
+
await client.patch(path, { blockingFunctions: this.blockingFunctionsConfig }, {
|
|
466
|
+
headers: { Authorization: "Bearer owner" },
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
catch (err) {
|
|
470
|
+
this.logger.log("WARN", "Error updating blocking functions config to the auth emulator: " + err);
|
|
471
|
+
throw err;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
getV1DatabaseApiAttributes(projectId, key, eventTrigger) {
|
|
475
|
+
const result = DATABASE_PATH_PATTERN.exec(eventTrigger.resource);
|
|
476
|
+
if (result === null || result.length !== 3) {
|
|
477
|
+
this.logger.log("WARN", `Event function "${key}" has malformed "resource" member. ` + `${eventTrigger.resource}`);
|
|
478
|
+
throw new error_1.FirebaseError(`Event function ${key} has malformed resource member`);
|
|
479
|
+
}
|
|
480
|
+
const instance = result[1];
|
|
481
|
+
const bundle = JSON.stringify({
|
|
482
|
+
name: `projects/${projectId}/locations/_/functions/${key}`,
|
|
483
|
+
path: result[2],
|
|
484
|
+
event: eventTrigger.eventType,
|
|
485
|
+
topic: `projects/${projectId}/topics/${key}`,
|
|
486
|
+
});
|
|
487
|
+
let apiPath = "/.settings/functionTriggers.json";
|
|
488
|
+
if (instance !== "") {
|
|
489
|
+
apiPath += `?ns=${instance}`;
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
this.logger.log("WARN", `No project in use. Registering function for sentinel namespace '${constants_1.Constants.DEFAULT_DATABASE_EMULATOR_NAMESPACE}'`);
|
|
493
|
+
}
|
|
494
|
+
return { bundle, apiPath, instance };
|
|
495
|
+
}
|
|
496
|
+
getV2DatabaseApiAttributes(projectId, id, key, eventTrigger, region) {
|
|
497
|
+
var _a, _b, _c;
|
|
498
|
+
const instance = ((_a = eventTrigger.eventFilters) === null || _a === void 0 ? void 0 : _a.instance) || ((_b = eventTrigger.eventFilterPathPatterns) === null || _b === void 0 ? void 0 : _b.instance);
|
|
499
|
+
if (!instance) {
|
|
500
|
+
throw new error_1.FirebaseError("A database instance must be supplied.");
|
|
501
|
+
}
|
|
502
|
+
const ref = (_c = eventTrigger.eventFilterPathPatterns) === null || _c === void 0 ? void 0 : _c.ref;
|
|
503
|
+
if (!ref) {
|
|
504
|
+
throw new error_1.FirebaseError("A database reference must be supplied.");
|
|
505
|
+
}
|
|
506
|
+
if (region !== "us-central1") {
|
|
507
|
+
this.logger.logLabeled("WARN", `functions[${id}]`, `function region is defined outside the database region, will not trigger.`);
|
|
508
|
+
}
|
|
509
|
+
const bundle = JSON.stringify({
|
|
510
|
+
name: `projects/${projectId}/locations/${region}/triggers/${key}`,
|
|
511
|
+
path: ref,
|
|
512
|
+
event: eventTrigger.eventType,
|
|
513
|
+
topic: `projects/${projectId}/topics/${key}`,
|
|
514
|
+
namespacePattern: instance,
|
|
515
|
+
});
|
|
516
|
+
const apiPath = "/.settings/functionTriggers.json";
|
|
517
|
+
return { bundle, apiPath, instance };
|
|
518
|
+
}
|
|
519
|
+
async addRealtimeDatabaseTrigger(projectId, id, key, eventTrigger, signature, region) {
|
|
520
|
+
if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.DATABASE)) {
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
523
|
+
const { bundle, apiPath, instance } = signature === "cloudevent"
|
|
524
|
+
? this.getV2DatabaseApiAttributes(projectId, id, key, eventTrigger, region)
|
|
525
|
+
: this.getV1DatabaseApiAttributes(projectId, key, eventTrigger);
|
|
526
|
+
logger_1.logger.debug(`addRealtimeDatabaseTrigger[${instance}]`, JSON.stringify(bundle));
|
|
527
|
+
const client = registry_1.EmulatorRegistry.client(types_1.Emulators.DATABASE);
|
|
528
|
+
try {
|
|
529
|
+
await client.post(apiPath, bundle, { headers: { Authorization: "Bearer owner" } });
|
|
530
|
+
}
|
|
531
|
+
catch (err) {
|
|
532
|
+
this.logger.log("WARN", "Error adding Realtime Database function: " + err);
|
|
533
|
+
throw err;
|
|
534
|
+
}
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
537
|
+
getV1FirestoreAttributes(projectId, key, eventTrigger) {
|
|
538
|
+
const bundle = JSON.stringify({
|
|
539
|
+
eventTrigger: Object.assign(Object.assign({}, eventTrigger), { service: "firestore.googleapis.com" }),
|
|
540
|
+
});
|
|
541
|
+
const path = `/emulator/v1/projects/${projectId}/triggers/${key}`;
|
|
542
|
+
return { bundle, path };
|
|
543
|
+
}
|
|
544
|
+
getV2FirestoreAttributes(projectId, key, eventTrigger) {
|
|
545
|
+
var _a, _b, _c, _d, _e, _f;
|
|
546
|
+
logger_1.logger.debug("Found a v2 firestore trigger.");
|
|
547
|
+
const database = (_a = eventTrigger.eventFilters) === null || _a === void 0 ? void 0 : _a.database;
|
|
548
|
+
if (!database) {
|
|
549
|
+
throw new error_1.FirebaseError("A database must be supplied.");
|
|
550
|
+
}
|
|
551
|
+
const namespace = (_b = eventTrigger.eventFilters) === null || _b === void 0 ? void 0 : _b.namespace;
|
|
552
|
+
if (!namespace) {
|
|
553
|
+
throw new error_1.FirebaseError("A namespace must be supplied.");
|
|
554
|
+
}
|
|
555
|
+
let doc;
|
|
556
|
+
let match;
|
|
557
|
+
if ((_c = eventTrigger.eventFilters) === null || _c === void 0 ? void 0 : _c.document) {
|
|
558
|
+
doc = (_d = eventTrigger.eventFilters) === null || _d === void 0 ? void 0 : _d.document;
|
|
559
|
+
match = "EXACT";
|
|
560
|
+
}
|
|
561
|
+
if ((_e = eventTrigger.eventFilterPathPatterns) === null || _e === void 0 ? void 0 : _e.document) {
|
|
562
|
+
doc = (_f = eventTrigger.eventFilterPathPatterns) === null || _f === void 0 ? void 0 : _f.document;
|
|
563
|
+
match = "PATH_PATTERN";
|
|
564
|
+
}
|
|
565
|
+
if (!doc) {
|
|
566
|
+
throw new error_1.FirebaseError("A document must be supplied.");
|
|
567
|
+
}
|
|
568
|
+
const bundle = JSON.stringify({
|
|
569
|
+
eventType: eventTrigger.eventType,
|
|
570
|
+
database,
|
|
571
|
+
namespace,
|
|
572
|
+
document: {
|
|
573
|
+
value: doc,
|
|
574
|
+
matchType: match,
|
|
575
|
+
},
|
|
576
|
+
});
|
|
577
|
+
const path = `/emulator/v1/projects/${projectId}/eventarcTrigger?eventarcTriggerId=${key}`;
|
|
578
|
+
return { bundle, path };
|
|
579
|
+
}
|
|
580
|
+
async addFirestoreTrigger(projectId, key, eventTrigger, signature) {
|
|
581
|
+
if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.FIRESTORE)) {
|
|
582
|
+
return Promise.resolve(false);
|
|
583
|
+
}
|
|
584
|
+
const { bundle, path } = signature === "cloudevent"
|
|
585
|
+
? this.getV2FirestoreAttributes(projectId, key, eventTrigger)
|
|
586
|
+
: this.getV1FirestoreAttributes(projectId, key, eventTrigger);
|
|
587
|
+
logger_1.logger.debug(`addFirestoreTrigger`, JSON.stringify(bundle));
|
|
588
|
+
const client = registry_1.EmulatorRegistry.client(types_1.Emulators.FIRESTORE);
|
|
589
|
+
try {
|
|
590
|
+
signature === "cloudevent" ? await client.post(path, bundle) : await client.put(path, bundle);
|
|
591
|
+
}
|
|
592
|
+
catch (err) {
|
|
593
|
+
this.logger.log("WARN", "Error adding firestore function: " + err);
|
|
594
|
+
throw err;
|
|
595
|
+
}
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
598
|
+
async addPubsubTrigger(triggerName, key, eventTrigger, signatureType, schedule) {
|
|
599
|
+
const pubsubEmulator = registry_1.EmulatorRegistry.get(types_1.Emulators.PUBSUB);
|
|
600
|
+
if (!pubsubEmulator) {
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
logger_1.logger.debug(`addPubsubTrigger`, JSON.stringify({ eventTrigger }));
|
|
604
|
+
const resource = eventTrigger.resource;
|
|
605
|
+
let topic;
|
|
606
|
+
if (schedule) {
|
|
607
|
+
topic = "firebase-schedule-" + triggerName;
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
const resourceParts = resource.split("/");
|
|
611
|
+
topic = resourceParts[resourceParts.length - 1];
|
|
612
|
+
}
|
|
613
|
+
try {
|
|
614
|
+
await pubsubEmulator.addTrigger(topic, key, signatureType);
|
|
615
|
+
return true;
|
|
616
|
+
}
|
|
617
|
+
catch (e) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
addAuthTrigger(projectId, key, eventTrigger) {
|
|
622
|
+
logger_1.logger.debug(`addAuthTrigger`, JSON.stringify({ eventTrigger }));
|
|
623
|
+
const eventTriggerId = `${projectId}:${eventTrigger.eventType}`;
|
|
624
|
+
const triggers = this.multicastTriggers[eventTriggerId] || [];
|
|
625
|
+
triggers.push(key);
|
|
626
|
+
this.multicastTriggers[eventTriggerId] = triggers;
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
addStorageTrigger(projectId, key, eventTrigger) {
|
|
630
|
+
logger_1.logger.debug(`addStorageTrigger`, JSON.stringify({ eventTrigger }));
|
|
631
|
+
const bucket = eventTrigger.resource.startsWith("projects/_/buckets/")
|
|
632
|
+
? eventTrigger.resource.split("/")[3]
|
|
633
|
+
: eventTrigger.resource;
|
|
634
|
+
const eventTriggerId = `${projectId}:${eventTrigger.eventType}:${bucket}`;
|
|
635
|
+
const triggers = this.multicastTriggers[eventTriggerId] || [];
|
|
636
|
+
triggers.push(key);
|
|
637
|
+
this.multicastTriggers[eventTriggerId] = triggers;
|
|
638
|
+
return true;
|
|
639
|
+
}
|
|
640
|
+
addBlockingTrigger(url, blockingTrigger) {
|
|
641
|
+
logger_1.logger.debug(`addBlockingTrigger`, JSON.stringify({ blockingTrigger }));
|
|
642
|
+
const eventType = blockingTrigger.eventType;
|
|
643
|
+
if (!v1_1.AUTH_BLOCKING_EVENTS.includes(eventType)) {
|
|
644
|
+
return false;
|
|
645
|
+
}
|
|
646
|
+
if (blockingTrigger.eventType === v1_1.BEFORE_CREATE_EVENT) {
|
|
647
|
+
this.blockingFunctionsConfig.triggers = Object.assign(Object.assign({}, this.blockingFunctionsConfig.triggers), { beforeCreate: {
|
|
648
|
+
functionUri: url,
|
|
649
|
+
} });
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
this.blockingFunctionsConfig.triggers = Object.assign(Object.assign({}, this.blockingFunctionsConfig.triggers), { beforeSignIn: {
|
|
653
|
+
functionUri: url,
|
|
654
|
+
} });
|
|
655
|
+
}
|
|
656
|
+
this.blockingFunctionsConfig.forwardInboundCredentials = {
|
|
657
|
+
accessToken: !!blockingTrigger.options.accessToken,
|
|
658
|
+
idToken: !!blockingTrigger.options.idToken,
|
|
659
|
+
refreshToken: !!blockingTrigger.options.refreshToken,
|
|
660
|
+
};
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
getProjectId() {
|
|
664
|
+
return this.args.projectId;
|
|
665
|
+
}
|
|
666
|
+
getInfo() {
|
|
667
|
+
const host = this.args.host || constants_1.Constants.getDefaultHost();
|
|
668
|
+
const port = this.args.port || constants_1.Constants.getDefaultPort(types_1.Emulators.FUNCTIONS);
|
|
669
|
+
return {
|
|
670
|
+
name: this.getName(),
|
|
671
|
+
host,
|
|
672
|
+
port,
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
getName() {
|
|
676
|
+
return types_1.Emulators.FUNCTIONS;
|
|
677
|
+
}
|
|
678
|
+
getTriggerDefinitions() {
|
|
679
|
+
return Object.values(this.triggers).map((record) => record.def);
|
|
680
|
+
}
|
|
681
|
+
getTriggerRecordByKey(triggerKey) {
|
|
682
|
+
const record = this.triggers[triggerKey];
|
|
683
|
+
if (!record) {
|
|
684
|
+
logger_1.logger.debug(`Could not find key=${triggerKey} in ${JSON.stringify(this.triggers)}`);
|
|
685
|
+
throw new error_1.FirebaseError(`No function with key ${triggerKey}`);
|
|
686
|
+
}
|
|
687
|
+
return record;
|
|
688
|
+
}
|
|
689
|
+
getTriggerKey(def) {
|
|
690
|
+
if (def.eventTrigger) {
|
|
691
|
+
const triggerKey = `${def.id}-${this.triggerGeneration}`;
|
|
692
|
+
return def.eventTrigger.channel ? `${triggerKey}-${def.eventTrigger.channel}` : triggerKey;
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
return def.id;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
getBackendInfo() {
|
|
699
|
+
const cf3Triggers = this.getCF3Triggers();
|
|
700
|
+
return this.args.emulatableBackends.map((e) => {
|
|
701
|
+
return (0, functionsEmulatorShared_1.toBackendInfo)(e, cf3Triggers);
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
getCF3Triggers() {
|
|
705
|
+
return Object.values(this.triggers)
|
|
706
|
+
.filter((t) => !t.backend.extensionInstanceId)
|
|
707
|
+
.map((t) => t.def);
|
|
708
|
+
}
|
|
709
|
+
addTriggerRecord(def, opts) {
|
|
710
|
+
const key = this.getTriggerKey(def);
|
|
711
|
+
this.triggers[key] = {
|
|
712
|
+
def,
|
|
713
|
+
enabled: true,
|
|
714
|
+
backend: opts.backend,
|
|
715
|
+
ignored: opts.ignored,
|
|
716
|
+
url: opts.url,
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
setTriggersForTesting(triggers, backend) {
|
|
720
|
+
this.triggers = {};
|
|
721
|
+
triggers.forEach((def) => this.addTriggerRecord(def, { backend, ignored: false }));
|
|
722
|
+
}
|
|
723
|
+
getRuntimeConfig(backend) {
|
|
724
|
+
const configPath = `${backend.functionsDir}/.runtimeconfig.json`;
|
|
725
|
+
try {
|
|
726
|
+
const configContent = fs.readFileSync(configPath, "utf8");
|
|
727
|
+
return JSON.parse(configContent.toString());
|
|
728
|
+
}
|
|
729
|
+
catch (e) {
|
|
730
|
+
}
|
|
731
|
+
return {};
|
|
732
|
+
}
|
|
733
|
+
getUserEnvs(backend) {
|
|
734
|
+
const projectInfo = {
|
|
735
|
+
functionsSource: backend.functionsDir,
|
|
736
|
+
projectId: this.args.projectId,
|
|
737
|
+
projectAlias: this.args.projectAlias,
|
|
738
|
+
isEmulator: true,
|
|
739
|
+
};
|
|
740
|
+
if (functionsEnv.hasUserEnvs(projectInfo)) {
|
|
741
|
+
try {
|
|
742
|
+
return functionsEnv.loadUserEnvs(projectInfo);
|
|
743
|
+
}
|
|
744
|
+
catch (e) {
|
|
745
|
+
logger_1.logger.debug("Failed to load local environment variables", e);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
return {};
|
|
749
|
+
}
|
|
750
|
+
getSystemEnvs(trigger) {
|
|
751
|
+
const envs = {};
|
|
752
|
+
envs.GCLOUD_PROJECT = this.args.projectId;
|
|
753
|
+
envs.K_REVISION = "1";
|
|
754
|
+
envs.PORT = "80";
|
|
755
|
+
envs.GOOGLE_CLOUD_QUOTA_PROJECT = this.args.projectId;
|
|
756
|
+
if (trigger) {
|
|
757
|
+
const target = trigger.entryPoint;
|
|
758
|
+
envs.FUNCTION_TARGET = target;
|
|
759
|
+
envs.FUNCTION_SIGNATURE_TYPE = (0, functionsEmulatorShared_1.getSignatureType)(trigger);
|
|
760
|
+
envs.K_SERVICE = trigger.name;
|
|
761
|
+
}
|
|
762
|
+
return envs;
|
|
763
|
+
}
|
|
764
|
+
getEmulatorEnvs() {
|
|
765
|
+
const envs = {};
|
|
766
|
+
envs.FUNCTIONS_EMULATOR = "true";
|
|
767
|
+
envs.TZ = "UTC";
|
|
768
|
+
envs.FIREBASE_DEBUG_MODE = "true";
|
|
769
|
+
envs.FIREBASE_DEBUG_FEATURES = JSON.stringify({
|
|
770
|
+
skipTokenVerification: true,
|
|
771
|
+
enableCors: true,
|
|
772
|
+
});
|
|
773
|
+
let emulatorInfos = registry_1.EmulatorRegistry.listRunningWithInfo();
|
|
774
|
+
if (this.args.remoteEmulators) {
|
|
775
|
+
emulatorInfos = emulatorInfos.concat(Object.values(this.args.remoteEmulators));
|
|
776
|
+
}
|
|
777
|
+
(0, env_1.setEnvVarsForEmulators)(envs, emulatorInfos);
|
|
778
|
+
if (this.debugMode) {
|
|
779
|
+
envs["FUNCTION_DEBUG_MODE"] = "true";
|
|
780
|
+
}
|
|
781
|
+
return envs;
|
|
782
|
+
}
|
|
783
|
+
getFirebaseConfig() {
|
|
784
|
+
const databaseEmulator = this.getEmulatorInfo(types_1.Emulators.DATABASE);
|
|
785
|
+
let emulatedDatabaseURL = undefined;
|
|
786
|
+
if (databaseEmulator) {
|
|
787
|
+
let ns = this.args.projectId;
|
|
788
|
+
if (this.adminSdkConfig.databaseURL) {
|
|
789
|
+
const asUrl = new url_1.URL(this.adminSdkConfig.databaseURL);
|
|
790
|
+
ns = asUrl.hostname.split(".")[0];
|
|
791
|
+
}
|
|
792
|
+
emulatedDatabaseURL = `http://${(0, functionsEmulatorShared_1.formatHost)(databaseEmulator)}/?ns=${ns}`;
|
|
793
|
+
}
|
|
794
|
+
return JSON.stringify({
|
|
795
|
+
storageBucket: this.adminSdkConfig.storageBucket,
|
|
796
|
+
databaseURL: emulatedDatabaseURL || this.adminSdkConfig.databaseURL,
|
|
797
|
+
projectId: this.args.projectId,
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
getRuntimeEnvs(backend, trigger) {
|
|
801
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this.getUserEnvs(backend)), this.getSystemEnvs(trigger)), this.getEmulatorEnvs()), { FIREBASE_CONFIG: this.getFirebaseConfig() }), backend.env);
|
|
802
|
+
}
|
|
803
|
+
async resolveSecretEnvs(backend, trigger) {
|
|
804
|
+
let secretEnvs = {};
|
|
805
|
+
const secretPath = (0, functionsEmulatorShared_1.getSecretLocalPath)(backend, this.args.projectDir);
|
|
806
|
+
try {
|
|
807
|
+
const data = fs.readFileSync(secretPath, "utf8");
|
|
808
|
+
secretEnvs = functionsEnv.parseStrict(data);
|
|
809
|
+
}
|
|
810
|
+
catch (e) {
|
|
811
|
+
if (e.code !== "ENOENT") {
|
|
812
|
+
this.logger.logLabeled("ERROR", "functions", `Failed to read local secrets file ${secretPath}: ${e.message}`);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
const secrets = (trigger === null || trigger === void 0 ? void 0 : trigger.secretEnvironmentVariables) || backend.secretEnv;
|
|
816
|
+
const accesses = secrets
|
|
817
|
+
.filter((s) => !secretEnvs[s.key])
|
|
818
|
+
.map(async (s) => {
|
|
819
|
+
var _a;
|
|
820
|
+
this.logger.logLabeled("INFO", "functions", `Trying to access secret ${s.secret}@latest`);
|
|
821
|
+
const value = await (0, secretManager_1.accessSecretVersion)(this.getProjectId(), s.secret, (_a = s.version) !== null && _a !== void 0 ? _a : "latest");
|
|
822
|
+
return [s.key, value];
|
|
823
|
+
});
|
|
824
|
+
const accessResults = await (0, utils_1.allSettled)(accesses);
|
|
825
|
+
const errs = [];
|
|
826
|
+
for (const result of accessResults) {
|
|
827
|
+
if (result.status === "rejected") {
|
|
828
|
+
errs.push(result.reason);
|
|
829
|
+
}
|
|
830
|
+
else {
|
|
831
|
+
const [k, v] = result.value;
|
|
832
|
+
secretEnvs[k] = v;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
if (errs.length > 0) {
|
|
836
|
+
this.logger.logLabeled("ERROR", "functions", "Unable to access secret environment variables from Google Cloud Secret Manager. " +
|
|
837
|
+
"Make sure the credential used for the Functions Emulator have access " +
|
|
838
|
+
`or provide override values in ${secretPath}:\n\t` +
|
|
839
|
+
errs.join("\n\t"));
|
|
840
|
+
}
|
|
841
|
+
return secretEnvs;
|
|
842
|
+
}
|
|
843
|
+
async startNode(backend, envs) {
|
|
844
|
+
const args = [path.join(__dirname, "functionsEmulatorRuntime")];
|
|
845
|
+
if (this.debugMode) {
|
|
846
|
+
if (process.env.FIREPIT_VERSION) {
|
|
847
|
+
this.logger.log("WARN", `To enable function inspection, please run "npm i node@${semver.coerce(backend.runtime || "18.0.0")} --save-dev" in your functions directory`);
|
|
848
|
+
}
|
|
849
|
+
else {
|
|
850
|
+
const { host } = this.getInfo();
|
|
851
|
+
args.unshift(`--inspect=${(0, utils_1.connectableHostname)(host)}:${this.args.debugPort}`);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
const pnpPath = path.join(backend.functionsDir, ".pnp.js");
|
|
855
|
+
if (fs.existsSync(pnpPath)) {
|
|
856
|
+
emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.FUNCTIONS).logLabeled("WARN_ONCE", "functions", "Detected yarn@2 with PnP. " +
|
|
857
|
+
"Cloud Functions for Firebase requires a node_modules folder to work correctly and is therefore incompatible with PnP. " +
|
|
858
|
+
"See https://yarnpkg.com/getting-started/migration#step-by-step for more information.");
|
|
859
|
+
}
|
|
860
|
+
const bin = backend.bin;
|
|
861
|
+
if (!bin) {
|
|
862
|
+
throw new Error(`No binary associated with ${backend.functionsDir}. ` +
|
|
863
|
+
"Make sure function runtime is configured correctly in firebase.json.");
|
|
864
|
+
}
|
|
865
|
+
const socketPath = (0, functionsEmulatorShared_1.getTemporarySocketPath)();
|
|
866
|
+
const childProcess = spawn(bin, args, {
|
|
867
|
+
cwd: backend.functionsDir,
|
|
868
|
+
env: Object.assign(Object.assign(Object.assign({ node: backend.bin }, process.env), envs), { PORT: socketPath }),
|
|
869
|
+
stdio: ["pipe", "pipe", "pipe", "ipc"],
|
|
870
|
+
});
|
|
871
|
+
return Promise.resolve({
|
|
872
|
+
process: childProcess,
|
|
873
|
+
events: new events_1.EventEmitter(),
|
|
874
|
+
cwd: backend.functionsDir,
|
|
875
|
+
conn: new IPCConn(socketPath),
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
async startPython(backend, envs) {
|
|
879
|
+
const args = ["functions-framework"];
|
|
880
|
+
if (this.debugMode) {
|
|
881
|
+
this.logger.log("WARN", "--inspect-functions not supported for Python functions. Ignored.");
|
|
882
|
+
}
|
|
883
|
+
const port = await portfinder.getPortPromise({
|
|
884
|
+
port: 8081 + (0, utils_1.randomInt)(0, 1000),
|
|
885
|
+
});
|
|
886
|
+
const childProcess = (0, python_1.runWithVirtualEnv)(args, backend.functionsDir, Object.assign(Object.assign(Object.assign({}, process.env), envs), { PYTHONUNBUFFERED: "1", DEBUG: "False", HOST: "127.0.0.1", PORT: port.toString() }));
|
|
887
|
+
return {
|
|
888
|
+
process: childProcess,
|
|
889
|
+
events: new events_1.EventEmitter(),
|
|
890
|
+
cwd: backend.functionsDir,
|
|
891
|
+
conn: new TCPConn("127.0.0.1", port),
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
async startRuntime(backend, trigger) {
|
|
895
|
+
var _a;
|
|
896
|
+
const runtimeEnv = this.getRuntimeEnvs(backend, trigger);
|
|
897
|
+
const secretEnvs = await this.resolveSecretEnvs(backend, trigger);
|
|
898
|
+
let runtime;
|
|
899
|
+
if (backend.runtime.startsWith("python")) {
|
|
900
|
+
runtime = await this.startPython(backend, Object.assign(Object.assign({}, runtimeEnv), secretEnvs));
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
runtime = await this.startNode(backend, Object.assign(Object.assign({}, runtimeEnv), secretEnvs));
|
|
904
|
+
}
|
|
905
|
+
const extensionLogInfo = {
|
|
906
|
+
instanceId: backend.extensionInstanceId,
|
|
907
|
+
ref: (_a = backend.extensionVersion) === null || _a === void 0 ? void 0 : _a.ref,
|
|
908
|
+
};
|
|
909
|
+
const pool = this.workerPools[backend.codebase];
|
|
910
|
+
const worker = pool.addWorker(trigger, runtime, extensionLogInfo);
|
|
911
|
+
await worker.waitForSocketReady();
|
|
912
|
+
return worker;
|
|
913
|
+
}
|
|
914
|
+
async disableBackgroundTriggers() {
|
|
915
|
+
Object.values(this.triggers).forEach((record) => {
|
|
916
|
+
if (record.def.eventTrigger && record.enabled) {
|
|
917
|
+
this.logger.logLabeled("BULLET", `functions[${record.def.entryPoint}]`, "function temporarily disabled.");
|
|
918
|
+
record.enabled = false;
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
await this.workQueue.flush();
|
|
922
|
+
}
|
|
923
|
+
async reloadTriggers() {
|
|
924
|
+
this.triggerGeneration++;
|
|
925
|
+
this.blockingFunctionsConfig = {};
|
|
926
|
+
for (const backend of this.args.emulatableBackends) {
|
|
927
|
+
await this.loadTriggers(backend);
|
|
928
|
+
}
|
|
929
|
+
await this.performPostLoadOperations();
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
getEmulatorInfo(emulator) {
|
|
933
|
+
if (this.args.remoteEmulators) {
|
|
934
|
+
if (this.args.remoteEmulators[emulator]) {
|
|
935
|
+
return this.args.remoteEmulators[emulator];
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return registry_1.EmulatorRegistry.getInfo(emulator);
|
|
939
|
+
}
|
|
940
|
+
tokenFromAuthHeader(authHeader) {
|
|
941
|
+
const match = /^Bearer (.*)$/.exec(authHeader);
|
|
942
|
+
if (!match) {
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
let idToken = match[1];
|
|
946
|
+
logger_1.logger.debug(`ID Token: ${idToken}`);
|
|
947
|
+
if (idToken && idToken.includes("=")) {
|
|
948
|
+
idToken = idToken.replace(/[=]+?\./g, ".");
|
|
949
|
+
logger_1.logger.debug(`ID Token contained invalid padding, new value: ${idToken}`);
|
|
950
|
+
}
|
|
951
|
+
try {
|
|
952
|
+
const decoded = jwt.decode(idToken, { complete: true });
|
|
953
|
+
if (!decoded || typeof decoded !== "object") {
|
|
954
|
+
logger_1.logger.debug(`Failed to decode ID Token: ${decoded}`);
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const claims = decoded.payload;
|
|
958
|
+
claims.uid = claims.sub;
|
|
959
|
+
return claims;
|
|
960
|
+
}
|
|
961
|
+
catch (e) {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
async handleHttpsTrigger(req, res) {
|
|
966
|
+
var _a;
|
|
967
|
+
const method = req.method;
|
|
968
|
+
let triggerId = req.params.trigger_name;
|
|
969
|
+
if (req.params.region) {
|
|
970
|
+
triggerId = `${req.params.region}-${triggerId}`;
|
|
971
|
+
}
|
|
972
|
+
if (!this.triggers[triggerId]) {
|
|
973
|
+
res
|
|
974
|
+
.status(404)
|
|
975
|
+
.send(`Function ${triggerId} does not exist, valid functions are: ${Object.keys(this.triggers).join(", ")}`);
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
const record = this.getTriggerRecordByKey(triggerId);
|
|
979
|
+
if (!record.enabled) {
|
|
980
|
+
res.status(204).send("Background triggers are currently disabled.");
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
const trigger = record.def;
|
|
984
|
+
logger_1.logger.debug(`Accepted request ${method} ${req.url} --> ${triggerId}`);
|
|
985
|
+
let reqBody = req.rawBody;
|
|
986
|
+
if ((0, functionsEmulatorShared_1.getSignatureType)(trigger) === "cloudevent") {
|
|
987
|
+
if ((_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.includes("application/protobuf")) {
|
|
988
|
+
reqBody = Uint8Array.from(atob(reqBody.toString()), (c) => c.charCodeAt(0));
|
|
989
|
+
req.headers["content-length"] = reqBody.length.toString();
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
const isCallable = trigger.labels && trigger.labels["deployment-callable"] === "true";
|
|
993
|
+
const authHeader = req.header("Authorization");
|
|
994
|
+
if (authHeader && isCallable && trigger.platform !== "gcfv2") {
|
|
995
|
+
const token = this.tokenFromAuthHeader(authHeader);
|
|
996
|
+
if (token) {
|
|
997
|
+
const contextAuth = {
|
|
998
|
+
uid: token.uid,
|
|
999
|
+
token: token,
|
|
1000
|
+
};
|
|
1001
|
+
req.headers[functionsEmulatorShared_1.HttpConstants.ORIGINAL_AUTH_HEADER] = req.headers["authorization"];
|
|
1002
|
+
delete req.headers["authorization"];
|
|
1003
|
+
req.headers[functionsEmulatorShared_1.HttpConstants.CALLABLE_AUTH_HEADER] = encodeURIComponent(JSON.stringify(contextAuth));
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
void (0, track_1.trackEmulator)(EVENT_INVOKE_GA4, {
|
|
1007
|
+
function_service: (0, functionsEmulatorShared_1.getFunctionService)(trigger),
|
|
1008
|
+
});
|
|
1009
|
+
this.logger.log("DEBUG", `[functions] Runtime ready! Sending request!`);
|
|
1010
|
+
const url = new url_1.URL(`${req.protocol}://${req.hostname}${req.url}`);
|
|
1011
|
+
const path = `${url.pathname}${url.search}`.replace(new RegExp(`\/${this.args.projectId}\/[^\/]*\/${req.params.trigger_name}\/?`), "/");
|
|
1012
|
+
this.logger.log("DEBUG", `[functions] Got req.url=${req.url}, mapping to path=${path}`);
|
|
1013
|
+
const pool = this.workerPools[record.backend.codebase];
|
|
1014
|
+
if (!pool.readyForWork(trigger.id)) {
|
|
1015
|
+
try {
|
|
1016
|
+
await this.startRuntime(record.backend, trigger);
|
|
1017
|
+
}
|
|
1018
|
+
catch (e) {
|
|
1019
|
+
this.logger.logLabeled("ERROR", `Failed to handle request for function ${trigger.id}`);
|
|
1020
|
+
this.logger.logLabeled("ERROR", `Failed to start functions in ${record.backend.functionsDir}: ${e}`);
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
let debugBundle;
|
|
1025
|
+
if (this.debugMode) {
|
|
1026
|
+
debugBundle = {
|
|
1027
|
+
functionTarget: trigger.entryPoint,
|
|
1028
|
+
functionSignature: (0, functionsEmulatorShared_1.getSignatureType)(trigger),
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
await pool.submitRequest(trigger.id, {
|
|
1032
|
+
method,
|
|
1033
|
+
path,
|
|
1034
|
+
headers: req.headers,
|
|
1035
|
+
}, res, reqBody, debugBundle);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
exports.FunctionsEmulator = FunctionsEmulator;
|