firebase-tools-with-isolate 13.16.0 → 13.26.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 (220) hide show
  1. package/lib/api.js +3 -1
  2. package/lib/apiv2.js +10 -3
  3. package/lib/appdistribution/client.js +62 -8
  4. package/lib/appdistribution/distribution.js +1 -1
  5. package/lib/apphosting/backend.js +299 -0
  6. package/lib/apphosting/config.js +31 -8
  7. package/lib/apphosting/githubConnections.js +70 -22
  8. package/lib/apphosting/index.js +3 -312
  9. package/lib/apphosting/rollout.js +138 -0
  10. package/lib/apphosting/secrets/index.js +70 -5
  11. package/lib/apphosting/utils.js +41 -0
  12. package/lib/apphosting/yaml.js +82 -0
  13. package/lib/archiveDirectory.js +1 -1
  14. package/lib/auth.js +31 -5
  15. package/lib/bin/firebase.js +2 -2
  16. package/lib/command.js +18 -4
  17. package/lib/commands/appdistribution-distribute.js +4 -4
  18. package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
  19. package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
  20. package/lib/commands/appdistribution-groups-list.js +55 -0
  21. package/lib/commands/appdistribution-testers-list.js +52 -0
  22. package/lib/commands/appdistribution-testers-remove.js +1 -1
  23. package/lib/commands/apphosting-backends-create.js +4 -4
  24. package/lib/commands/apphosting-backends-delete.js +7 -15
  25. package/lib/commands/apphosting-backends-get.js +1 -1
  26. package/lib/commands/apphosting-config-export.js +51 -0
  27. package/lib/commands/apphosting-repos-create.js +23 -0
  28. package/lib/commands/apphosting-rollouts-create.js +14 -15
  29. package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
  30. package/lib/commands/database-import.js +4 -2
  31. package/lib/commands/database-push.js +4 -2
  32. package/lib/commands/database-set.js +4 -2
  33. package/lib/commands/database-settings-get.js +1 -1
  34. package/lib/commands/database-settings-set.js +1 -1
  35. package/lib/commands/dataconnect-sdk-generate.js +4 -1
  36. package/lib/commands/dataconnect-services-list.js +4 -3
  37. package/lib/commands/dataconnect-sql-diff.js +1 -1
  38. package/lib/commands/dataconnect-sql-grant.js +37 -0
  39. package/lib/commands/dataconnect-sql-migrate.js +1 -1
  40. package/lib/commands/dataconnect-sql-shell.js +115 -0
  41. package/lib/commands/deploy.js +2 -0
  42. package/lib/commands/emulators-start.js +4 -1
  43. package/lib/commands/ext-dev-init.js +2 -2
  44. package/lib/commands/ext-dev-list.js +1 -1
  45. package/lib/commands/ext-dev-register.js +2 -2
  46. package/lib/commands/ext-dev-upload.js +2 -2
  47. package/lib/commands/ext-dev-usage.js +2 -2
  48. package/lib/commands/ext-info.js +3 -1
  49. package/lib/commands/ext-install.js +2 -2
  50. package/lib/commands/ext-sdk-install.js +88 -0
  51. package/lib/commands/ext.js +1 -0
  52. package/lib/commands/firestore-databases-restore.js +39 -1
  53. package/lib/commands/functions-secrets-access.js +2 -4
  54. package/lib/commands/index.js +15 -2
  55. package/lib/commands/init.js +25 -15
  56. package/lib/commands/setup-emulators-dataconnect.js +0 -13
  57. package/lib/commands/use.js +1 -1
  58. package/lib/config.js +14 -4
  59. package/lib/crashlytics/buildToolsJarHelper.js +2 -2
  60. package/lib/dataconnect/client.js +1 -1
  61. package/lib/dataconnect/dataplaneClient.js +12 -9
  62. package/lib/dataconnect/ensureApis.js +6 -1
  63. package/lib/dataconnect/fileUtils.js +15 -39
  64. package/lib/dataconnect/freeTrial.js +45 -9
  65. package/lib/dataconnect/load.js +3 -1
  66. package/lib/dataconnect/provisionCloudSql.js +39 -26
  67. package/lib/dataconnect/schemaMigration.js +215 -74
  68. package/lib/dataconnect/types.js +4 -1
  69. package/lib/dataconnect/webhook.js +32 -0
  70. package/lib/deploy/dataconnect/deploy.js +18 -15
  71. package/lib/deploy/dataconnect/prepare.js +41 -0
  72. package/lib/deploy/dataconnect/release.js +16 -7
  73. package/lib/deploy/extensions/deploy.js +3 -1
  74. package/lib/deploy/extensions/deploymentSummary.js +7 -3
  75. package/lib/deploy/extensions/planner.js +44 -5
  76. package/lib/deploy/extensions/prepare.js +45 -73
  77. package/lib/deploy/extensions/release.js +11 -10
  78. package/lib/deploy/extensions/tasks.js +32 -21
  79. package/lib/deploy/firestore/prepare.js +9 -0
  80. package/lib/deploy/firestore/release.js +3 -6
  81. package/lib/deploy/functions/checkIam.js +7 -2
  82. package/lib/deploy/functions/ensure.js +11 -3
  83. package/lib/deploy/functions/prepare.js +10 -2
  84. package/lib/deploy/functions/release/planner.js +2 -1
  85. package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
  86. package/lib/deploy/functions/runtimes/node/index.js +5 -0
  87. package/lib/deploy/functions/services/auth.js +34 -3
  88. package/lib/deploy/functions/services/index.js +2 -0
  89. package/lib/deploy/index.js +8 -5
  90. package/lib/deploy/lifecycleHooks.js +2 -1
  91. package/lib/emulator/apphosting/config.js +27 -0
  92. package/lib/emulator/apphosting/index.js +38 -0
  93. package/lib/emulator/apphosting/serve.js +50 -0
  94. package/lib/emulator/apphosting/utils.js +18 -0
  95. package/lib/emulator/auth/handlers.js +27 -0
  96. package/lib/emulator/auth/operations.js +41 -2
  97. package/lib/emulator/auth/state.js +2 -1
  98. package/lib/emulator/commandUtils.js +8 -3
  99. package/lib/emulator/constants.js +4 -1
  100. package/lib/emulator/controller.js +48 -5
  101. package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
  102. package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
  103. package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
  104. package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
  105. package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
  106. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
  107. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
  108. package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
  109. package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
  110. package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
  111. package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
  112. package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
  113. package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
  114. package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
  115. package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
  116. package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
  117. package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
  118. package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
  119. package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
  120. package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
  121. package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
  122. package/lib/emulator/dataconnect/pgliteServer.js +95 -0
  123. package/lib/emulator/dataconnectEmulator.js +58 -75
  124. package/lib/emulator/dataconnectToolkitController.js +44 -0
  125. package/lib/emulator/downloadableEmulators.js +27 -16
  126. package/lib/emulator/emulatorLogger.js +3 -0
  127. package/lib/emulator/eventarcEmulator.js +1 -1
  128. package/lib/emulator/extensionsEmulator.js +38 -6
  129. package/lib/emulator/functionsEmulator.js +85 -41
  130. package/lib/emulator/functionsEmulatorShared.js +2 -1
  131. package/lib/emulator/functionsRuntimeWorker.js +2 -1
  132. package/lib/emulator/hub.js +13 -9
  133. package/lib/emulator/hubExport.js +10 -3
  134. package/lib/emulator/loggingEmulator.js +2 -2
  135. package/lib/emulator/portUtils.js +10 -11
  136. package/lib/emulator/registry.js +1 -0
  137. package/lib/emulator/storage/persistence.js +2 -2
  138. package/lib/emulator/storage/rules/runtime.js +1 -1
  139. package/lib/emulator/tasksEmulator.js +5 -2
  140. package/lib/emulator/types.js +3 -0
  141. package/lib/emulator/ui.js +51 -25
  142. package/lib/error.js +31 -1
  143. package/lib/experiments.js +5 -0
  144. package/lib/extensions/emulator/triggerHelper.js +1 -1
  145. package/lib/extensions/extensionsApi.js +14 -10
  146. package/lib/extensions/extensionsHelper.js +15 -6
  147. package/lib/extensions/localHelper.js +31 -0
  148. package/lib/extensions/runtimes/common.js +179 -39
  149. package/lib/extensions/runtimes/node.js +401 -0
  150. package/lib/extensions/types.js +25 -14
  151. package/lib/extensions/warnings.js +5 -2
  152. package/lib/firestore/api.js +2 -1
  153. package/lib/firestore/checkDatabaseType.js +10 -3
  154. package/lib/firestore/delete.js +11 -0
  155. package/lib/firestore/options.js +7 -0
  156. package/lib/frameworks/angular/index.js +15 -3
  157. package/lib/frameworks/constants.js +1 -1
  158. package/lib/frameworks/flutter/index.js +6 -6
  159. package/lib/frameworks/flutter/utils.js +34 -1
  160. package/lib/frameworks/next/index.js +10 -2
  161. package/lib/frameworks/next/utils.js +8 -5
  162. package/lib/frameworks/vite/index.js +2 -2
  163. package/lib/fsutils.js +13 -1
  164. package/lib/functions/constants.js +4 -0
  165. package/lib/functions/events/v1.js +9 -2
  166. package/lib/gcp/apphosting.js +1 -1
  167. package/lib/gcp/cloudmonitoring.js +3 -3
  168. package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
  169. package/lib/gcp/cloudsql/connect.js +49 -37
  170. package/lib/gcp/cloudsql/interactive.js +49 -0
  171. package/lib/gcp/cloudsql/permissions.js +165 -0
  172. package/lib/gcp/devConnect.js +38 -1
  173. package/lib/gcp/firestore.js +5 -1
  174. package/lib/gcp/secretManager.js +12 -5
  175. package/lib/getProjectNumber.js +1 -1
  176. package/lib/init/features/apphosting.js +15 -0
  177. package/lib/init/features/dataconnect/index.js +159 -120
  178. package/lib/init/features/dataconnect/sdk.js +77 -84
  179. package/lib/init/features/emulators.js +2 -15
  180. package/lib/init/features/firestore/index.js +20 -1
  181. package/lib/init/features/firestore/indexes.js +4 -4
  182. package/lib/init/features/genkit/index.js +444 -0
  183. package/lib/init/features/hosting/index.js +2 -2
  184. package/lib/init/features/index.js +1 -1
  185. package/lib/init/features/project.js +6 -6
  186. package/lib/init/features/storage.js +0 -2
  187. package/lib/init/index.js +1 -0
  188. package/lib/init/spawn.js +23 -2
  189. package/lib/logger.js +2 -2
  190. package/lib/management/projects.js +24 -4
  191. package/lib/projectUtils.js +1 -1
  192. package/lib/prompt.js +1 -1
  193. package/lib/rc.js +1 -8
  194. package/lib/requireAuth.js +19 -5
  195. package/lib/requireDatabaseInstance.js +1 -1
  196. package/lib/requirePermissions.js +1 -1
  197. package/lib/responseToError.js +5 -2
  198. package/lib/rulesDeploy.js +1 -1
  199. package/lib/templates.js +2 -2
  200. package/lib/utils.js +16 -11
  201. package/lib/vsCodeUtils.js +8 -0
  202. package/package.json +7 -6
  203. package/schema/connector-yaml.json +57 -17
  204. package/schema/firebase-config.json +24 -0
  205. package/templates/extensions/javascript/package.lint.json +2 -2
  206. package/templates/extensions/javascript/package.nolint.json +2 -2
  207. package/templates/extensions/typescript/package.lint.json +2 -2
  208. package/templates/extensions/typescript/package.nolint.json +2 -2
  209. package/templates/genkit/firebase.0.9.0.template +57 -0
  210. package/templates/init/apphosting/apphosting.yaml +23 -0
  211. package/templates/init/dataconnect/connector.yaml +0 -1
  212. package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
  213. package/templates/init/dataconnect/dataconnect.yaml +1 -1
  214. package/templates/init/dataconnect/queries.gql +1 -2
  215. package/templates/init/functions/javascript/package.lint.json +2 -2
  216. package/templates/init/functions/javascript/package.nolint.json +2 -2
  217. package/templates/init/functions/typescript/package.lint.json +2 -2
  218. package/templates/init/functions/typescript/package.nolint.json +2 -2
  219. package/lib/ensureCloudResourceLocation.js +0 -12
  220. package/lib/init/features/genkit.js +0 -53
@@ -0,0 +1,401 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeSDK = exports.TYPESCRIPT_VERSION = exports.FIREBASE_FUNCTIONS_VERSION = exports.SDK_GENERATION_VERSION = void 0;
4
+ const path = require("path");
5
+ const child_process_1 = require("child_process");
6
+ const marked_terminal_1 = require("marked-terminal");
7
+ const marked_1 = require("marked");
8
+ const types_1 = require("../types");
9
+ const prompt_1 = require("../../prompt");
10
+ const secretsUtils = require("../secretsUtils");
11
+ const utils_1 = require("../../utils");
12
+ const common_1 = require("./common");
13
+ const askUserForEventsConfig_1 = require("../askUserForEventsConfig");
14
+ const extensionsHelper_1 = require("../extensionsHelper");
15
+ const error_1 = require("../../error");
16
+ marked_1.marked.use((0, marked_terminal_1.markedTerminal)());
17
+ exports.SDK_GENERATION_VERSION = "1.0.0";
18
+ exports.FIREBASE_FUNCTIONS_VERSION = ">=5.1.0";
19
+ exports.TYPESCRIPT_VERSION = "^4.9.0";
20
+ function makePackageName(extensionRef, name) {
21
+ if (!extensionRef) {
22
+ return `@firebase-extensions/local-${name}-sdk`;
23
+ }
24
+ const pub = extensionRef.split("/")[0];
25
+ return `@firebase-extensions/${pub}-${name}-sdk`;
26
+ }
27
+ function makeTypeName(name) {
28
+ let typeName = name.replace(/_/g, " ");
29
+ typeName = typeName.replace(/\w\S*/g, common_1.toTitleCase);
30
+ return typeName.replace(/ /g, "") + "Param";
31
+ }
32
+ const systemPrefixes = {
33
+ "firebaseextensions.v1beta.function": "_FUNCTION",
34
+ "firebaseextensions.v1beta.v2function": "_V2FUNCTION",
35
+ FUNCTION: "firebaseextensions.v1beta.function",
36
+ V2FUNCTION: "firebaseextensions.v1beta.v2function",
37
+ };
38
+ function convertSystemPrefix(prefix) {
39
+ return systemPrefixes[prefix];
40
+ }
41
+ function makeSystemTypeName(name) {
42
+ if (name.includes("/")) {
43
+ const prefix = name.split("/")[0];
44
+ let typeName = name.split("/")[1];
45
+ typeName = typeName.replace(/([A-Z])/g, " $1").trim();
46
+ typeName = `${convertSystemPrefix(prefix)}_${typeName}`;
47
+ return `System${makeTypeName(typeName)}`;
48
+ }
49
+ return makeTypeName(name);
50
+ }
51
+ function makeSystemParamName(name) {
52
+ if (name.includes("/")) {
53
+ const prefix = name.split("/")[0];
54
+ let paramName = name.split("/")[1];
55
+ paramName = paramName.replace(/([A-Z])/g, " $1").trim();
56
+ paramName = paramName.toUpperCase();
57
+ paramName = paramName.replace(/ /g, "_");
58
+ return `${convertSystemPrefix(prefix)}_${paramName}`;
59
+ }
60
+ return name;
61
+ }
62
+ function makeClassName(name) {
63
+ let className = name.replace(/[_-]/g, " ");
64
+ className = className.replace(/\w\S*/g, common_1.toTitleCase);
65
+ return className.replace(/ /g, "");
66
+ }
67
+ function makeEventName(name, prefix) {
68
+ let eventName;
69
+ const versionedEvent = /^(?:[^.]+[.])+(?:[vV]\d+[.])(?<event>.*)$/;
70
+ const match = versionedEvent.exec(name);
71
+ if (match) {
72
+ eventName = match[1];
73
+ }
74
+ else if (prefix.length < name.length) {
75
+ eventName = name.substring(prefix.length);
76
+ }
77
+ else {
78
+ const parts = name.split(".");
79
+ eventName = parts[parts.length - 1];
80
+ }
81
+ const allCaps = /^[A-Z._-]+$/;
82
+ eventName = allCaps.exec(eventName) ? eventName : eventName.replace(/([A-Z])/g, " $1").trim();
83
+ eventName = eventName.replace(/[._-]/g, " ");
84
+ eventName = eventName.toLowerCase().startsWith("on") ? eventName : "on " + eventName;
85
+ eventName = eventName.replace(/\w\S*/g, common_1.toTitleCase);
86
+ eventName = eventName.replace(/ /g, "");
87
+ eventName = eventName.charAt(0).toLowerCase() + eventName.substring(1);
88
+ return eventName;
89
+ }
90
+ function addPeerDependency(pkgJson, dependency, version) {
91
+ if (!pkgJson.peerDependencies) {
92
+ pkgJson.peerDependencies = {};
93
+ }
94
+ if (!(0, types_1.isObject)(pkgJson.peerDependencies)) {
95
+ throw new error_1.FirebaseError("Internal error generating peer dependencies.");
96
+ }
97
+ pkgJson.peerDependencies[dependency] = version;
98
+ }
99
+ async function writeSDK(extensionRef, localPath, spec, options) {
100
+ const sdkLines = [];
101
+ const className = makeClassName(spec.name);
102
+ let dirPath;
103
+ if (extensionRef) {
104
+ dirPath = path.join((0, common_1.getInstallPathPrefix)(options), extensionRef.replace("@", "/"));
105
+ }
106
+ else if (localPath) {
107
+ dirPath = path.join((0, common_1.getInstallPathPrefix)(options), "local", spec.name, spec.version);
108
+ if (await (0, prompt_1.confirm)({
109
+ message: `Copy local extension source to deployment directory? (required for successful deploy)`,
110
+ nonInteractive: options.nonInteractive,
111
+ force: options.force,
112
+ default: true,
113
+ })) {
114
+ const newLocalPath = path.join(dirPath, "src");
115
+ await (0, common_1.copyDirectory)(localPath, newLocalPath, options);
116
+ localPath = newLocalPath.replace(options.projectRoot || ".", ".");
117
+ }
118
+ }
119
+ if (!dirPath) {
120
+ throw new error_1.FirebaseError("Invalid extension definition. Must have either extensionRef or localPath");
121
+ }
122
+ const packageName = makePackageName(extensionRef, spec.name);
123
+ const pkgJson = {
124
+ name: packageName,
125
+ version: `${exports.SDK_GENERATION_VERSION}`,
126
+ description: `Generated SDK for ${spec.displayName || spec.name}@${spec.version}`,
127
+ main: "./output/index.js",
128
+ private: true,
129
+ scripts: {
130
+ build: "tsc",
131
+ "build:watch": "npm run build && tsc --watch",
132
+ },
133
+ devDependencies: {
134
+ typescript: exports.TYPESCRIPT_VERSION,
135
+ },
136
+ };
137
+ const tsconfigJson = {
138
+ compilerOptions: {
139
+ declaration: true,
140
+ declarationMap: true,
141
+ module: "commonjs",
142
+ strict: true,
143
+ target: "es2017",
144
+ removeComments: false,
145
+ outDir: "output",
146
+ },
147
+ };
148
+ sdkLines.push("/**");
149
+ sdkLines.push(` * ${spec.displayName || spec.name} SDK for ${spec.name}@${spec.version}`);
150
+ sdkLines.push(" *");
151
+ sdkLines.push(" * When filing bugs or feature requests please specify:");
152
+ if (extensionRef) {
153
+ sdkLines.push(` * "Extensions SDK v${exports.SDK_GENERATION_VERSION} for ${spec.name}@${spec.version}"`);
154
+ }
155
+ else {
156
+ sdkLines.push(` * "Extensions SDK v${exports.SDK_GENERATION_VERSION} for Local extension.`);
157
+ }
158
+ sdkLines.push(" * https://github.com/firebase/firebase-tools/issues/new/choose");
159
+ sdkLines.push(" *");
160
+ sdkLines.push(" * GENERATED FILE. DO NOT EDIT.");
161
+ sdkLines.push(" */\n");
162
+ const hasEvents = spec.events && spec.events.length > 0;
163
+ if (hasEvents) {
164
+ sdkLines.push(`import { CloudEvent } from "firebase-functions/v2";`);
165
+ sdkLines.push(`import { onCustomEventPublished, EventarcTriggerOptions } from "firebase-functions/v2/eventarc";`);
166
+ addPeerDependency(pkgJson, "firebase-functions", exports.FIREBASE_FUNCTIONS_VERSION);
167
+ }
168
+ const usesSecrets = secretsUtils.usesSecrets(spec);
169
+ if (usesSecrets) {
170
+ sdkLines.push(`import { defineSecret } from "firebase-functions/params";`);
171
+ addPeerDependency(pkgJson, "firebase-functions", exports.FIREBASE_FUNCTIONS_VERSION);
172
+ }
173
+ if (hasEvents || usesSecrets) {
174
+ sdkLines.push("");
175
+ }
176
+ if (hasEvents) {
177
+ sdkLines.push(`export type EventCallback<T> = (event: CloudEvent<T>) => unknown | Promise<unknown>;`);
178
+ sdkLines.push(`export type SimpleEventarcTriggerOptions = Omit<EventarcTriggerOptions, 'eventType' | 'channel' | 'region'>;`);
179
+ sdkLines.push(`export type EventArcRegionType = "${askUserForEventsConfig_1.ALLOWED_EVENT_ARC_REGIONS.join('" | "')}";`);
180
+ }
181
+ if (usesSecrets) {
182
+ sdkLines.push("export type SecretParam = ReturnType<typeof defineSecret>;");
183
+ }
184
+ if (spec.params && Array.isArray(spec.params) && spec.params.length > 0) {
185
+ for (const param of spec.params) {
186
+ let line;
187
+ if (param.type === types_1.ParamType.SELECT ||
188
+ param.type === types_1.ParamType.MULTISELECT ||
189
+ param.type === extensionsHelper_1.SpecParamType.SELECT ||
190
+ param.type === extensionsHelper_1.SpecParamType.MULTISELECT) {
191
+ line = `export type ${makeTypeName(param.param)} =`;
192
+ param.options?.forEach((opt, i) => {
193
+ if (i === 0) {
194
+ line = line.concat(` "${opt.value}"`);
195
+ }
196
+ else {
197
+ line = line.concat(` | "${opt.value}"`);
198
+ }
199
+ });
200
+ line = line.concat(";");
201
+ sdkLines.push(line);
202
+ }
203
+ }
204
+ }
205
+ sdkLines.push("");
206
+ if (spec.systemParams && Array.isArray(spec.systemParams) && spec.systemParams.length > 0) {
207
+ for (const sysParam of spec.systemParams) {
208
+ let line;
209
+ if (sysParam.type === types_1.ParamType.SELECT || sysParam.type === types_1.ParamType.MULTISELECT) {
210
+ line = `export type ${makeSystemTypeName(sysParam.param)} =`;
211
+ sysParam.options?.forEach((opt, i) => {
212
+ if (i === 0) {
213
+ line = line.concat(` "${opt.value}"`);
214
+ }
215
+ else {
216
+ line = line.concat(` | "${opt.value}"`);
217
+ }
218
+ });
219
+ line = line.concat(";");
220
+ sdkLines.push(line);
221
+ }
222
+ }
223
+ }
224
+ sdkLines.push("");
225
+ sdkLines.push("/**");
226
+ sdkLines.push(` * Parameters for ${spec.name}@${spec.version} extension`);
227
+ sdkLines.push(" */");
228
+ sdkLines.push(`export interface ${className}Params {`);
229
+ for (const param of spec.params) {
230
+ const opt = param.required ? "" : "?";
231
+ sdkLines.push(" /**");
232
+ sdkLines.push(` * ${param.label}`);
233
+ if (param.validationRegex && !param.validationRegex.includes("*/")) {
234
+ sdkLines.push(` * - Validation regex: ${param.validationRegex}`);
235
+ }
236
+ sdkLines.push(" */");
237
+ switch (param.type) {
238
+ case types_1.ParamType.STRING:
239
+ case extensionsHelper_1.SpecParamType.STRING:
240
+ sdkLines.push(` ${param.param}${opt}: string;`);
241
+ break;
242
+ case types_1.ParamType.MULTISELECT:
243
+ case extensionsHelper_1.SpecParamType.MULTISELECT:
244
+ sdkLines.push(` ${param.param}${opt}: ${makeTypeName(param.param)}[];`);
245
+ break;
246
+ case types_1.ParamType.SELECT:
247
+ case extensionsHelper_1.SpecParamType.SELECT:
248
+ sdkLines.push(` ${param.param}${opt}: ${makeTypeName(param.param)};`);
249
+ break;
250
+ case types_1.ParamType.SECRET:
251
+ case extensionsHelper_1.SpecParamType.SECRET:
252
+ sdkLines.push(` ${param.param}${opt}: SecretParam;`);
253
+ break;
254
+ case types_1.ParamType.SELECT_RESOURCE:
255
+ case extensionsHelper_1.SpecParamType.SELECTRESOURCE:
256
+ sdkLines.push(` ${param.param}${opt}: string;`);
257
+ break;
258
+ default:
259
+ sdkLines.push(` ${param.param}${opt}: string; // Assuming string for unknown type`);
260
+ }
261
+ sdkLines.push("");
262
+ }
263
+ if (hasEvents) {
264
+ sdkLines.push(" /**");
265
+ sdkLines.push(` * Event Arc Region`);
266
+ sdkLines.push(" */");
267
+ sdkLines.push(" _EVENT_ARC_REGION?: EventArcRegionType\n");
268
+ }
269
+ for (const sysParam of spec.systemParams) {
270
+ const opt = sysParam.required ? "" : "?";
271
+ sdkLines.push(" /**");
272
+ sdkLines.push(` * ${sysParam.label}`);
273
+ if (sysParam.validationRegex && !sysParam.validationRegex.includes("*/")) {
274
+ sdkLines.push(` * - Validation regex: ${sysParam.validationRegex}`);
275
+ }
276
+ sdkLines.push(" */");
277
+ switch (sysParam.type) {
278
+ case types_1.ParamType.STRING:
279
+ sdkLines.push(` ${makeSystemParamName(sysParam.param)}${opt}: string;`);
280
+ break;
281
+ case types_1.ParamType.MULTISELECT:
282
+ sdkLines.push(` ${makeSystemParamName(sysParam.param)}${opt}: ${makeSystemTypeName(sysParam.param)}[];`);
283
+ break;
284
+ case types_1.ParamType.SELECT:
285
+ sdkLines.push(` ${makeSystemParamName(sysParam.param)}${opt}: ${makeSystemTypeName(sysParam.param)};`);
286
+ break;
287
+ case types_1.ParamType.SECRET:
288
+ sdkLines.push(` ${makeSystemParamName(sysParam.param)}${opt}: SecretParam;`);
289
+ break;
290
+ case types_1.ParamType.SELECT_RESOURCE:
291
+ sdkLines.push(` ${sysParam.param}${opt}: string;`);
292
+ break;
293
+ default:
294
+ throw new error_1.FirebaseError(`Error: Unknown systemParam type: ${sysParam.type || "undefined"}.`);
295
+ }
296
+ sdkLines.push("");
297
+ }
298
+ sdkLines.push("}\n");
299
+ const lowerClassName = (0, common_1.lowercaseFirstLetter)(className);
300
+ sdkLines.push(`export function ${lowerClassName}(instanceId: string, params: ${className}Params) {`);
301
+ sdkLines.push(` return new ${className}(instanceId, params);`);
302
+ sdkLines.push("}\n");
303
+ sdkLines.push(`/**`);
304
+ sdkLines.push(` * ${spec.displayName || spec.name}`);
305
+ spec.description?.split("\n").forEach((val) => {
306
+ sdkLines.push(` * ${val.replace(/\*\//g, "* /")}`);
307
+ });
308
+ sdkLines.push(` */`);
309
+ sdkLines.push(`export class ${className} {`);
310
+ if (hasEvents) {
311
+ sdkLines.push(` events: string[] = [];`);
312
+ }
313
+ if (extensionRef) {
314
+ sdkLines.push(` readonly FIREBASE_EXTENSION_REFERENCE = "${extensionRef}";`);
315
+ sdkLines.push(` readonly EXTENSION_VERSION = "${extensionRef.split("@")[1]}";\n`);
316
+ }
317
+ else if (localPath) {
318
+ sdkLines.push(` readonly FIREBASE_EXTENSION_LOCAL_PATH = "${localPath}";`);
319
+ }
320
+ sdkLines.push(` constructor(private instanceId: string, private params: ${className}Params) {}\n`);
321
+ sdkLines.push(` getInstanceId(): string { return this.instanceId; }\n`);
322
+ sdkLines.push(` getParams(): ${className}Params { return this.params; }\n`);
323
+ if (spec.events) {
324
+ const prefix = (0, common_1.longestCommonPrefix)(spec.events.map((e) => e.type));
325
+ for (const event of spec.events) {
326
+ const eventName = makeEventName(event.type, prefix);
327
+ sdkLines.push(" /**");
328
+ sdkLines.push(` * ${event.description}`);
329
+ sdkLines.push(` */`);
330
+ sdkLines.push(` ${eventName}<T = unknown>(callback: EventCallback<T>, options?: SimpleEventarcTriggerOptions) {`);
331
+ sdkLines.push(` this.events.push("${event.type}");`);
332
+ sdkLines.push(` return onCustomEventPublished({`);
333
+ sdkLines.push(` ...options,`);
334
+ sdkLines.push(` "eventType": "${event.type}",`);
335
+ sdkLines.push(' "channel": `projects/locations/${this.params._EVENT_ARC_REGION}/channels/firebase`,');
336
+ sdkLines.push(' "region": `${this.params._EVENT_ARC_REGION}`');
337
+ sdkLines.push(" },");
338
+ sdkLines.push(" callback);");
339
+ sdkLines.push(` }\n`);
340
+ }
341
+ }
342
+ sdkLines.push(`}`);
343
+ const shortDirPath = dirPath.replace(process.cwd(), ".");
344
+ await (0, common_1.writeFile)(`${dirPath}/index.ts`, sdkLines.join("\n"), options);
345
+ await (0, common_1.writeFile)(`${dirPath}/package.json`, JSON.stringify(pkgJson, null, 2), options);
346
+ await (0, common_1.writeFile)(`${dirPath}/tsconfig.json`, JSON.stringify(tsconfigJson, null, 2), options);
347
+ (0, utils_1.logLabeledBullet)("extensions", `running 'npm --prefix ${shortDirPath} install'`);
348
+ try {
349
+ (0, child_process_1.execFileSync)("npm", ["--prefix", dirPath, "install"]);
350
+ }
351
+ catch (err) {
352
+ const errMsg = (0, error_1.getErrMsg)(err, "unknown error");
353
+ throw new error_1.FirebaseError(`Error during npm install in ${shortDirPath}: ${errMsg}`);
354
+ }
355
+ (0, utils_1.logLabeledBullet)("extensions", `running 'npm --prefix ${shortDirPath} run build'`);
356
+ try {
357
+ (0, child_process_1.execFileSync)("npm", ["--prefix", dirPath, "run", "build"]);
358
+ }
359
+ catch (err) {
360
+ const errMsg = (0, error_1.getErrMsg)(err, "unknown error");
361
+ throw new error_1.FirebaseError(`Error during npm run build in ${shortDirPath}: ${errMsg}`);
362
+ }
363
+ const codebaseDir = (0, common_1.getCodebaseDir)(options);
364
+ const shortCodebaseDir = codebaseDir.replace(process.cwd(), ".");
365
+ let installCmd = "";
366
+ if (await (0, prompt_1.confirm)({
367
+ message: `Do you want to install the SDK with npm now?`,
368
+ nonInteractive: options.nonInteractive,
369
+ force: options.force,
370
+ default: true,
371
+ })) {
372
+ (0, utils_1.logLabeledBullet)("extensions", `running 'npm --prefix ${shortCodebaseDir} install --save ${shortDirPath}'`);
373
+ try {
374
+ (0, child_process_1.execFileSync)("npm", ["--prefix", codebaseDir, "install", "--save", dirPath]);
375
+ }
376
+ catch (err) {
377
+ const errMsg = (0, error_1.getErrMsg)(err, "unknown error");
378
+ throw new error_1.FirebaseError(`Error during npm install in ${codebaseDir}: ${errMsg}`);
379
+ }
380
+ }
381
+ else {
382
+ installCmd = `npm --prefix ${shortCodebaseDir} install --save ${shortDirPath}`;
383
+ }
384
+ let sampleImport;
385
+ if ((0, common_1.isTypescriptCodebase)(codebaseDir)) {
386
+ sampleImport =
387
+ "```typescript\n" + `import { ${lowerClassName} } from "${packageName}";` + "\n```";
388
+ }
389
+ else {
390
+ sampleImport = "```js\n" + `const { ${lowerClassName} } = require("${packageName}");` + "\n```";
391
+ }
392
+ const prefix = installCmd
393
+ ? `\nTo install the SDK to your project run:\n ${installCmd}\n\nThen you `
394
+ : "\nYou ";
395
+ const instructions = prefix +
396
+ `can add this to your codebase to begin using the SDK:\n\n` +
397
+ (0, common_1.fixDarkBlueText)(await (0, marked_1.marked)(sampleImport)) +
398
+ `See also: ${(0, common_1.fixDarkBlueText)(await (0, marked_1.marked)("[Extension SDKs documentation](https://firebase.google.com/docs/extensions/install-extensions?interface=sdk#config)"))}`;
399
+ return instructions;
400
+ }
401
+ exports.writeSDK = writeSDK;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isExtensionSpec = exports.isResource = exports.isParam = exports.ParamType = exports.FUNCTIONS_V2_RESOURCE_TYPE = exports.FUNCTIONS_RESOURCE_TYPE = exports.Visibility = exports.RegistryLaunchStage = void 0;
3
+ exports.isExtensionSpec = exports.isResource = exports.isParam = exports.isObject = exports.ParamType = exports.FUNCTIONS_V2_RESOURCE_TYPE = exports.FUNCTIONS_RESOURCE_TYPE = exports.isExtensionInstance = exports.Visibility = exports.RegistryLaunchStage = void 0;
4
4
  var RegistryLaunchStage;
5
5
  (function (RegistryLaunchStage) {
6
6
  RegistryLaunchStage["EXPERIMENTAL"] = "EXPERIMENTAL";
@@ -14,6 +14,22 @@ var Visibility;
14
14
  Visibility["UNLISTED"] = "unlisted";
15
15
  Visibility["PUBLIC"] = "public";
16
16
  })(Visibility = exports.Visibility || (exports.Visibility = {}));
17
+ const extensionInstanceState = [
18
+ "STATE_UNSPECIFIED",
19
+ "DEPLOYING",
20
+ "UNINSTALLING",
21
+ "ACTIVE",
22
+ "ERRORED",
23
+ "PAUSED",
24
+ ];
25
+ const isExtensionInstance = (value) => {
26
+ if (!isObject(value) || typeof value.name !== "string") {
27
+ return false;
28
+ }
29
+ return true;
30
+ };
31
+ exports.isExtensionInstance = isExtensionInstance;
32
+ const lifecycleStages = ["STAGE_UNSPECIFIED", "ON_INSTALL", "ON_UPDATE", "ON_CONFIGURE"];
17
33
  exports.FUNCTIONS_RESOURCE_TYPE = "firebaseextensions.v1beta.function";
18
34
  exports.FUNCTIONS_V2_RESOURCE_TYPE = "firebaseextensions.v1beta.v2function";
19
35
  var ParamType;
@@ -27,6 +43,7 @@ var ParamType;
27
43
  function isObject(value) {
28
44
  return typeof value === "object" && value !== null;
29
45
  }
46
+ exports.isObject = isObject;
30
47
  const isParam = (param) => {
31
48
  return (isObject(param) && typeof param["param"] === "string" && typeof param["label"] === "string");
32
49
  };
@@ -39,41 +56,35 @@ const isExtensionSpec = (spec) => {
39
56
  if (!isObject(spec) || typeof spec.name !== "string" || typeof spec.version !== "string") {
40
57
  return false;
41
58
  }
42
- let validResources = true;
43
59
  if (spec.resources && Array.isArray(spec.resources)) {
44
60
  for (const res of spec.resources) {
45
- validResources = validResources && (0, exports.isResource)(res);
46
- if (!validResources) {
47
- break;
61
+ if (!(0, exports.isResource)(res)) {
62
+ return false;
48
63
  }
49
64
  }
50
65
  }
51
66
  else {
52
67
  return false;
53
68
  }
54
- let validParams = true;
55
69
  if (spec.params && Array.isArray(spec.params)) {
56
70
  for (const param of spec.params) {
57
- validParams = validParams && (0, exports.isParam)(param);
58
- if (!validParams) {
59
- break;
71
+ if (!(0, exports.isParam)(param)) {
72
+ return false;
60
73
  }
61
74
  }
62
75
  }
63
76
  else {
64
77
  return false;
65
78
  }
66
- let validSysParams = true;
67
79
  if (spec.systemParams && Array.isArray(spec.systemParams)) {
68
80
  for (const param of spec.systemParams) {
69
- validSysParams = validSysParams && (0, exports.isParam)(param);
70
- if (!validSysParams) {
71
- break;
81
+ if (!(0, exports.isParam)(param)) {
82
+ return false;
72
83
  }
73
84
  }
74
85
  }
75
86
  else {
76
- return false;
87
+ return !spec.systemParams;
77
88
  }
78
89
  return true;
79
90
  };
@@ -30,9 +30,12 @@ async function displayWarningsForDeploy(instancesToCreate) {
30
30
  return unpublishedExtensions.length > 0;
31
31
  }
32
32
  exports.displayWarningsForDeploy = displayWarningsForDeploy;
33
- function outOfBandChangesWarning(instanceIds) {
33
+ function outOfBandChangesWarning(instanceIds, isDynamic) {
34
+ const extra = isDynamic
35
+ ? ""
36
+ : " To avoid this, run `firebase ext:export` to sync these changes to your local extensions manifest.";
34
37
  logger_1.logger.warn("The following instances may have been changed in the Firebase console or by another machine since the last deploy from this machine.\n\t" +
35
38
  clc.bold(instanceIds.join("\n\t")) +
36
- "\nIf you proceed with this deployment, those changes will be overwritten. To avoid this, run `firebase ext:export` to sync these changes to your local extensions manifest.");
39
+ `\nIf you proceed with this deployment, those changes will be overwritten.${extra}`);
37
40
  }
38
41
  exports.outOfBandChangesWarning = outOfBandChangesWarning;
@@ -459,11 +459,12 @@ class FirestoreApi {
459
459
  }
460
460
  return database;
461
461
  }
462
- async restoreDatabase(project, databaseId, backupName) {
462
+ async restoreDatabase(project, databaseId, backupName, encryptionConfig) {
463
463
  const url = `/projects/${project}/databases:restore`;
464
464
  const payload = {
465
465
  databaseId,
466
466
  backup: backupName,
467
+ encryptionConfig: encryptionConfig,
467
468
  };
468
469
  const options = { queryParams: { databaseId: databaseId } };
469
470
  const res = await this.apiClient.post(url, payload, options);
@@ -4,14 +4,21 @@ exports.checkDatabaseType = void 0;
4
4
  const api_1 = require("../api");
5
5
  const apiv2_1 = require("../apiv2");
6
6
  const logger_1 = require("../logger");
7
- async function checkDatabaseType(projectId) {
7
+ const error_1 = require("../error");
8
+ async function checkDatabaseType(projectId, databaseId = "(default)") {
8
9
  try {
9
10
  const client = new apiv2_1.Client({ urlPrefix: (0, api_1.firestoreOrigin)(), apiVersion: "v1" });
10
- const resp = await client.get(`/projects/${projectId}/databases/(default)`);
11
+ const resp = await client.get(`/projects/${projectId}/databases/${databaseId}`);
11
12
  return resp.body.type;
12
13
  }
13
14
  catch (err) {
14
- logger_1.logger.debug("error getting database type", err);
15
+ logger_1.logger.debug("error getting database type: ", err);
16
+ if (err instanceof error_1.FirebaseError) {
17
+ if (err.status === 404) {
18
+ logger_1.logger.info(`${databaseId} does not exist in project ${projectId}.`);
19
+ return "DATABASE_DOES_NOT_EXIST";
20
+ }
21
+ }
15
22
  return undefined;
16
23
  }
17
24
  }
@@ -237,6 +237,17 @@ class FirestoreDelete {
237
237
  }
238
238
  queue.unshift(...toDelete);
239
239
  }
240
+ else if (e.status === 429 &&
241
+ this.deleteBatchSize >= 10 &&
242
+ e.message.includes("database has exceeded their maximum bandwidth")) {
243
+ logger_1.logger.debug("Database has exceeded maximum write bandwidth", e);
244
+ const newBatchSize = Math.floor(toDelete.length / 2);
245
+ if (newBatchSize < this.deleteBatchSize) {
246
+ utils.logLabeledWarning("firestore", `delete rate exceeding maximum bandwidth, reducing batch size from ${this.deleteBatchSize} to ${newBatchSize}`);
247
+ this.setDeleteBatchSize(newBatchSize);
248
+ }
249
+ queue.unshift(...toDelete);
250
+ }
240
251
  else if (e.status >= 500 && e.status < 600) {
241
252
  logger_1.logger.debug("Server error deleting doc batch", e);
242
253
  toDelete.forEach((doc) => {
@@ -1,2 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EncryptionType = void 0;
4
+ var EncryptionType;
5
+ (function (EncryptionType) {
6
+ EncryptionType["CUSTOMER_MANAGED_ENCRYPTION"] = "CUSTOMER_MANAGED_ENCRYPTION";
7
+ EncryptionType["USE_SOURCE_ENCRYPTION"] = "USE_SOURCE_ENCRYPTION";
8
+ EncryptionType["GOOGLE_DEFAULT_ENCRYPTION"] = "GOOGLE_DEFAULT_ENCRYPTION";
9
+ })(EncryptionType = exports.EncryptionType || (exports.EncryptionType = {}));
@@ -15,7 +15,7 @@ exports.support = "preview";
15
15
  exports.type = 3;
16
16
  exports.docsUrl = "https://firebase.google.com/docs/hosting/frameworks/angular";
17
17
  const DEFAULT_BUILD_SCRIPT = ["ng build"];
18
- exports.supportedRange = "14 - 17";
18
+ exports.supportedRange = "16 - 18";
19
19
  async function discover(dir) {
20
20
  if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
21
21
  return;
@@ -180,9 +180,21 @@ exports.handle = function(req,res) {
180
180
  };\n`;
181
181
  }
182
182
  else if (serverOutputPath) {
183
- bootstrapScript = `const app = ${serverEntry?.endsWith(".mjs")
183
+ bootstrapScript = `
184
+ const app = new Promise((resolve) => {
185
+ setTimeout(() => {
186
+ const port = process.env.PORT;
187
+ const socket = 'express.sock';
188
+ process.env.PORT = socket;
189
+
190
+ ${serverEntry?.endsWith(".mjs")
184
191
  ? `import(\`./${serverOutputPath}/${serverEntry}\`)`
185
- : `Promise.resolve(require('./${serverOutputPath}/${serverEntry}'))`}.then(server => server.app());
192
+ : `Promise.resolve(require('./${serverOutputPath}/${serverEntry}'))`}.then(({ app }) => {
193
+ process.env.PORT = port;
194
+ resolve(app());
195
+ });
196
+ }, 0);
197
+ });
186
198
  exports.handle = (req,res) => app.then(it => it(req,res));\n`;
187
199
  }
188
200
  else {
@@ -18,7 +18,7 @@ exports.MAILING_LIST_URL = "https://goo.gle/41enW5X";
18
18
  const DEFAULT_FIREBASE_FRAMEWORKS_VERSION = "^0.11.0";
19
19
  exports.FIREBASE_FRAMEWORKS_VERSION = (experiments.isEnabled("internaltesting") && process.env.FIREBASE_FRAMEWORKS_VERSION) ||
20
20
  DEFAULT_FIREBASE_FRAMEWORKS_VERSION;
21
- exports.FIREBASE_FUNCTIONS_VERSION = "^4.5.0";
21
+ exports.FIREBASE_FUNCTIONS_VERSION = "^6.0.1";
22
22
  exports.FIREBASE_ADMIN_VERSION = "^11.11.1";
23
23
  exports.SHARP_VERSION = "^0.32 || ^0.33";
24
24
  exports.NODE_VERSION = parseInt(process.versions.node, 10);
@@ -4,8 +4,6 @@ exports.ɵcodegenPublicDirectory = exports.build = exports.init = exports.discov
4
4
  const cross_spawn_1 = require("cross-spawn");
5
5
  const fs_extra_1 = require("fs-extra");
6
6
  const path_1 = require("path");
7
- const yaml = require("yaml");
8
- const promises_1 = require("fs/promises");
9
7
  const error_1 = require("../../error");
10
8
  const utils_1 = require("./utils");
11
9
  const constants_1 = require("./constants");
@@ -17,8 +15,7 @@ async function discover(dir) {
17
15
  return;
18
16
  if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "web"))))
19
17
  return;
20
- const pubSpecBuffer = await (0, promises_1.readFile)((0, path_1.join)(dir, "pubspec.yaml"));
21
- const pubSpec = yaml.parse(pubSpecBuffer.toString());
18
+ const pubSpec = await (0, utils_1.getPubSpec)(dir);
22
19
  const usingFlutter = pubSpec.dependencies?.flutter;
23
20
  if (!usingFlutter)
24
21
  return;
@@ -43,9 +40,12 @@ function init(setup, config) {
43
40
  return Promise.resolve();
44
41
  }
45
42
  exports.init = init;
46
- function build(cwd) {
43
+ async function build(cwd) {
47
44
  (0, utils_1.assertFlutterCliExists)();
48
- const build = (0, cross_spawn_1.sync)("flutter", ["build", "web"], { cwd, stdio: "inherit" });
45
+ const pubSpec = await (0, utils_1.getPubSpec)(cwd);
46
+ const otherArgs = (0, utils_1.getAdditionalBuildArgs)(pubSpec);
47
+ const buildArgs = ["build", "web", ...otherArgs].filter(Boolean);
48
+ const build = (0, cross_spawn_1.sync)("flutter", buildArgs, { cwd, stdio: "inherit" });
49
49
  if (build.status !== 0)
50
50
  throw new error_1.FirebaseError("Unable to build your Flutter app");
51
51
  return Promise.resolve({ wantsBackend: false });