firebase-functions 6.5.0 → 6.6.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.
@@ -2,10 +2,10 @@
2
2
  * @hidden
3
3
  * @alpha
4
4
  */
5
- import { BooleanParam, Expression, IntParam, Param, ParamOptions, SecretParam, StringParam, ListParam } from "./types";
5
+ import { BooleanParam, Expression, IntParam, Param, ParamOptions, SecretParam, JsonSecretParam, StringParam, ListParam } from "./types";
6
6
  export { BUCKET_PICKER, TextInput, SelectInput, SelectOptions, MultiSelectInput, select, multiSelect, } from "./types";
7
7
  export { ParamOptions, Expression };
8
- type SecretOrExpr = Param<any> | SecretParam;
8
+ type SecretOrExpr = Param<any> | SecretParam | JsonSecretParam<any>;
9
9
  export declare const declaredParams: SecretOrExpr[];
10
10
  /**
11
11
  * A built-in parameter that resolves to the default RTDB database URL associated
@@ -37,6 +37,19 @@ export declare const storageBucket: Param<string>;
37
37
  * @returns A parameter with a `string` return type for `.value`.
38
38
  */
39
39
  export declare function defineSecret(name: string): SecretParam;
40
+ /**
41
+ * Declares a secret parameter that retrieves a structured JSON object in Cloud Secret Manager.
42
+ * This is useful for managing groups of related configuration values, such as all settings
43
+ * for a third-party API, as a single unit.
44
+ *
45
+ * The secret value must be a valid JSON string. At runtime, the value will be automatically parsed
46
+ * and returned as a JavaScript object. If the value is not set or is not valid JSON, an error will be thrown.
47
+ *
48
+ * @param name The name of the environment variable to use to load the parameter.
49
+ * @returns A parameter whose `.value()` method returns the parsed JSON object.
50
+ * ```
51
+ */
52
+ export declare function defineJsonSecret<T = any>(name: string): JsonSecretParam<T>;
40
53
  /**
41
54
  * Declare a string parameter.
42
55
  *
@@ -21,7 +21,7 @@
21
21
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.defineList = exports.defineFloat = exports.defineInt = exports.defineBoolean = exports.defineString = exports.defineSecret = exports.storageBucket = exports.gcloudProject = exports.projectID = exports.databaseURL = exports.clearParams = exports.declaredParams = exports.Expression = exports.multiSelect = exports.select = exports.BUCKET_PICKER = void 0;
24
+ exports.defineList = exports.defineFloat = exports.defineInt = exports.defineBoolean = exports.defineString = exports.defineJsonSecret = exports.defineSecret = exports.storageBucket = exports.gcloudProject = exports.projectID = exports.databaseURL = exports.clearParams = exports.declaredParams = exports.Expression = exports.multiSelect = exports.select = exports.BUCKET_PICKER = void 0;
25
25
  /**
26
26
  * @hidden
27
27
  * @alpha
@@ -89,6 +89,24 @@ function defineSecret(name) {
89
89
  return param;
90
90
  }
91
91
  exports.defineSecret = defineSecret;
92
+ /**
93
+ * Declares a secret parameter that retrieves a structured JSON object in Cloud Secret Manager.
94
+ * This is useful for managing groups of related configuration values, such as all settings
95
+ * for a third-party API, as a single unit.
96
+ *
97
+ * The secret value must be a valid JSON string. At runtime, the value will be automatically parsed
98
+ * and returned as a JavaScript object. If the value is not set or is not valid JSON, an error will be thrown.
99
+ *
100
+ * @param name The name of the environment variable to use to load the parameter.
101
+ * @returns A parameter whose `.value()` method returns the parsed JSON object.
102
+ * ```
103
+ */
104
+ function defineJsonSecret(name) {
105
+ const param = new types_1.JsonSecretParam(name);
106
+ registerParam(param);
107
+ return param;
108
+ }
109
+ exports.defineJsonSecret = defineJsonSecret;
92
110
  /**
93
111
  * Declare a string parameter.
94
112
  *
@@ -114,6 +114,8 @@ export type ParamSpec<T extends string | number | boolean | string[]> = {
114
114
  description?: string;
115
115
  /** The way in which the Firebase CLI will prompt for the value of this parameter. Defaults to a TextInput. */
116
116
  input?: ParamInput<T>;
117
+ /** Optional format annotation for additional type information (e.g., "json" for JSON-encoded secrets). */
118
+ format?: string;
117
119
  };
118
120
  /**
119
121
  * Representation of parameters for the stack over the wire.
@@ -130,6 +132,7 @@ export type WireParamSpec<T extends string | number | boolean | string[]> = {
130
132
  description?: string;
131
133
  type: ParamValueType;
132
134
  input?: ParamInput<T>;
135
+ format?: string;
133
136
  };
134
137
  /** Configuration options which can be used to customize the prompting behavior of a parameter. */
135
138
  export type ParamOptions<T extends string | number | boolean | string[]> = Omit<ParamSpec<T>, "name" | "type">;
@@ -177,6 +180,20 @@ export declare class SecretParam {
177
180
  /** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
178
181
  value(): string;
179
182
  }
183
+ /**
184
+ * A parametrized object whose value is stored as a JSON string in Cloud Secret Manager.
185
+ * This is useful for managing groups of related configuration values, such as all settings
186
+ * for a third-party API, as a single unit. Supply instances of JsonSecretParam to the
187
+ * secrets array while defining a Function to make their values accessible during execution
188
+ * of that Function.
189
+ */
190
+ export declare class JsonSecretParam<T = any> {
191
+ static type: ParamValueType;
192
+ name: string;
193
+ constructor(name: string);
194
+ /** Returns the secret's parsed JSON value at runtime. Throws an error if accessed during deployment, if the secret is not set, or if the value is not valid JSON. */
195
+ value(): T;
196
+ }
180
197
  /**
181
198
  * A parametrized value of String type that will be read from .env files
182
199
  * if present, or prompted for by the CLI if missing.
@@ -21,7 +21,7 @@
21
21
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.ListParam = exports.BooleanParam = exports.FloatParam = exports.IntParam = exports.InternalExpression = exports.StringParam = exports.SecretParam = exports.Param = exports.BUCKET_PICKER = exports.multiSelect = exports.select = exports.CompareExpression = exports.TernaryExpression = exports.Expression = void 0;
24
+ exports.ListParam = exports.BooleanParam = exports.FloatParam = exports.IntParam = exports.InternalExpression = exports.StringParam = exports.JsonSecretParam = exports.SecretParam = exports.Param = exports.BUCKET_PICKER = exports.multiSelect = exports.select = exports.CompareExpression = exports.TernaryExpression = exports.Expression = void 0;
25
25
  const logger = require("../logger");
26
26
  /*
27
27
  * A CEL expression which can be evaluated during function deployment, and
@@ -293,6 +293,48 @@ class SecretParam {
293
293
  }
294
294
  exports.SecretParam = SecretParam;
295
295
  SecretParam.type = "secret";
296
+ /**
297
+ * A parametrized object whose value is stored as a JSON string in Cloud Secret Manager.
298
+ * This is useful for managing groups of related configuration values, such as all settings
299
+ * for a third-party API, as a single unit. Supply instances of JsonSecretParam to the
300
+ * secrets array while defining a Function to make their values accessible during execution
301
+ * of that Function.
302
+ */
303
+ class JsonSecretParam {
304
+ constructor(name) {
305
+ this.name = name;
306
+ }
307
+ /** @internal */
308
+ runtimeValue() {
309
+ const val = process.env[this.name];
310
+ if (val === undefined) {
311
+ throw new Error(`No value found for secret parameter "${this.name}". A function can only access a secret if you include the secret in the function's dependency array.`);
312
+ }
313
+ try {
314
+ return JSON.parse(val);
315
+ }
316
+ catch (error) {
317
+ throw new Error(`"${this.name}" could not be parsed as JSON. Please verify its value in Secret Manager. Details: ${error}`);
318
+ }
319
+ }
320
+ /** @internal */
321
+ toSpec() {
322
+ return {
323
+ type: "secret",
324
+ name: this.name,
325
+ format: "json",
326
+ };
327
+ }
328
+ /** Returns the secret's parsed JSON value at runtime. Throws an error if accessed during deployment, if the secret is not set, or if the value is not valid JSON. */
329
+ value() {
330
+ if (process.env.FUNCTIONS_CONTROL_API === "true") {
331
+ throw new Error(`Cannot access the value of secret "${this.name}" during function deployment. Secret values are only available at runtime.`);
332
+ }
333
+ return this.runtimeValue();
334
+ }
335
+ }
336
+ exports.JsonSecretParam = JsonSecretParam;
337
+ JsonSecretParam.type = "secret";
296
338
  /**
297
339
  * A parametrized value of String type that will be read from .env files
298
340
  * if present, or prompted for by the CLI if missing.
@@ -104,6 +104,19 @@ class AnalyticsEvent {
104
104
  }
105
105
  }
106
106
  exports.AnalyticsEvent = AnalyticsEvent;
107
+ function isValidUserProperty(property) {
108
+ if (property == null || typeof property !== "object" || !("value" in property)) {
109
+ return false;
110
+ }
111
+ const { value } = property;
112
+ if (value == null) {
113
+ return false;
114
+ }
115
+ if (typeof value === "object" && Object.keys(value).length === 0) {
116
+ return false;
117
+ }
118
+ return true;
119
+ }
107
120
  /**
108
121
  * Interface representing the user who triggered the events.
109
122
  */
@@ -116,7 +129,9 @@ class UserDimensions {
116
129
  copyTimestampToString(wireFormat, this, "firstOpenTimestampMicros", "firstOpenTime");
117
130
  this.userProperties = {}; // With no entries in the wire format, present an empty (as opposed to absent) map.
118
131
  copyField(wireFormat, this, "userProperties", (r) => {
119
- const entries = Object.entries(r).map(([k, v]) => [k, new UserPropertyValue(v)]);
132
+ const entries = Object.entries(r)
133
+ .filter(([, v]) => isValidUserProperty(v))
134
+ .map(([k, v]) => [k, new UserPropertyValue(v)]);
120
135
  return Object.fromEntries(entries);
121
136
  });
122
137
  copyField(wireFormat, this, "bundleInfo", (r) => new ExportBundleInfo(r));
@@ -203,8 +218,19 @@ function mapKeys(obj, transform) {
203
218
  // 'unwrapValue' method just below.
204
219
  /** @hidden */
205
220
  function unwrapValueAsString(wrapped) {
206
- const key = Object.keys(wrapped)[0];
207
- return wrapped[key].toString();
221
+ if (!wrapped || typeof wrapped !== "object") {
222
+ return "";
223
+ }
224
+ const keys = Object.keys(wrapped);
225
+ if (keys.length === 0) {
226
+ return "";
227
+ }
228
+ const key = keys[0];
229
+ const value = wrapped[key];
230
+ if (value === null || value === undefined) {
231
+ return "";
232
+ }
233
+ return value.toString();
208
234
  }
209
235
  // Ditto as the method above, but returning the values in the idiomatic JavaScript type (string for strings,
210
236
  // number for numbers):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "6.5.0",
3
+ "version": "6.6.0",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",