firebase-functions 4.1.1 → 4.2.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,7 +2,7 @@
2
2
  * @hidden
3
3
  * @alpha
4
4
  */
5
- import { BooleanParam, Expression, FloatParam, IntParam, Param, ParamOptions, SecretParam, StringParam } from "./types";
5
+ import { BooleanParam, Expression, IntParam, Param, ParamOptions, SecretParam, StringParam, ListParam } from "./types";
6
6
  export { ParamOptions, Expression };
7
7
  declare type SecretOrExpr = Param<any> | SecretParam;
8
8
  export declare const declaredParams: SecretOrExpr[];
@@ -62,10 +62,10 @@ export declare function defineBoolean(name: string, options?: ParamOptions<boole
62
62
  */
63
63
  export declare function defineInt(name: string, options?: ParamOptions<number>): IntParam;
64
64
  /**
65
- * Declare a float param.
65
+ * Declare a list param.
66
66
  *
67
67
  * @param name The name of the environment variable to use to load the param.
68
68
  * @param options Configuration options for the param.
69
- * @returns A Param with a `number` return type for `.value`.
69
+ * @returns A Param with a `string[]` return type for `.value`.
70
70
  */
71
- export declare function defineFloat(name: string, options?: ParamOptions<number>): FloatParam;
71
+ export declare function defineList(name: string, options?: ParamOptions<string[]>): ListParam;
@@ -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.defineFloat = exports.defineInt = exports.defineBoolean = exports.defineString = exports.defineSecret = exports.storageBucket = exports.gcloudProject = exports.projectID = exports.databaseURL = exports.clearParams = exports.declaredParams = exports.Expression = void 0;
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 = void 0;
25
25
  /**
26
26
  * @hidden
27
27
  * @alpha
@@ -131,6 +131,8 @@ exports.defineInt = defineInt;
131
131
  * @param name The name of the environment variable to use to load the param.
132
132
  * @param options Configuration options for the param.
133
133
  * @returns A Param with a `number` return type for `.value`.
134
+ *
135
+ * @internal
134
136
  */
135
137
  function defineFloat(name, options = {}) {
136
138
  const param = new types_1.FloatParam(name, options);
@@ -138,3 +140,16 @@ function defineFloat(name, options = {}) {
138
140
  return param;
139
141
  }
140
142
  exports.defineFloat = defineFloat;
143
+ /**
144
+ * Declare a list param.
145
+ *
146
+ * @param name The name of the environment variable to use to load the param.
147
+ * @param options Configuration options for the param.
148
+ * @returns A Param with a `string[]` return type for `.value`.
149
+ */
150
+ function defineList(name, options = {}) {
151
+ const param = new types_1.ListParam(name, options);
152
+ registerParam(param);
153
+ return param;
154
+ }
155
+ exports.defineList = defineList;
@@ -34,6 +34,8 @@ declare type ParamInput<T> = {
34
34
  text: TextInput<T>;
35
35
  } | {
36
36
  select: SelectInput<T>;
37
+ } | {
38
+ multiSelect: MultiSelectInput;
37
39
  } | {
38
40
  resource: ResourceInput;
39
41
  };
@@ -73,6 +75,14 @@ export interface ResourceInput {
73
75
  export interface SelectInput<T = unknown> {
74
76
  options: Array<SelectOptions<T>>;
75
77
  }
78
+ /**
79
+ * Specifies that a Param's value should be determined by having the user select
80
+ * a subset from a list of pre-canned options interactively at deploy-time.
81
+ * Will result in errors if used on Params of type other than string[].
82
+ */
83
+ export interface MultiSelectInput {
84
+ options: Array<SelectOptions<string>>;
85
+ }
76
86
  /**
77
87
  * One of the options provided to a SelectInput, containing a value and
78
88
  * optionally a human-readable label to display in the selection interface.
@@ -186,4 +196,19 @@ export declare class BooleanParam extends Param<boolean> {
186
196
  then<T extends string | number | boolean>(ifTrue: T | Expression<T>, ifFalse: T | Expression<T>): TernaryExpression<T>;
187
197
  thenElse<T extends string | number | boolean>(ifTrue: T | Expression<T>, ifFalse: T | Expression<T>): TernaryExpression<T>;
188
198
  }
199
+ /**
200
+ * A parametrized value of String[] type that will be read from .env files
201
+ * if present, or prompted for by the CLI if missing.
202
+ */
203
+ export declare class ListParam extends Param<string[]> {
204
+ static type: ParamValueType;
205
+ /** @hidden */
206
+ greaterThan(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
207
+ /** @hidden */
208
+ greaterThanOrEqualTo(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
209
+ /** @hidden */
210
+ lessThan(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
211
+ /** @hidden */
212
+ lessThanorEqualTo(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
213
+ }
189
214
  export {};
@@ -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.BooleanParam = exports.FloatParam = exports.IntParam = exports.InternalExpression = exports.StringParam = exports.SecretParam = exports.Param = exports.CompareExpression = exports.TernaryExpression = exports.Expression = void 0;
24
+ exports.ListParam = exports.BooleanParam = exports.FloatParam = exports.IntParam = exports.InternalExpression = exports.StringParam = exports.SecretParam = exports.Param = 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
@@ -51,15 +51,29 @@ class Expression {
51
51
  }
52
52
  }
53
53
  exports.Expression = Expression;
54
- function quoteIfString(literal) {
55
- // TODO(vsfan@): CEL's string escape semantics are slightly different than Javascript's, what do we do here?
56
- return typeof literal === "string" ? `"${literal}"` : literal;
57
- }
58
54
  function valueOf(arg) {
59
55
  return arg instanceof Expression ? arg.runtimeValue() : arg;
60
56
  }
57
+ /**
58
+ * Returns how an entity (either an Expression or a literal value) should be represented in CEL.
59
+ * - Expressions delegate to the .toString() method, which is used by the WireManifest
60
+ * - Strings have to be quoted explicitly
61
+ * - Arrays are represented as []-delimited, parsable JSON
62
+ * - Numbers and booleans are not quoted explicitly
63
+ */
61
64
  function refOf(arg) {
62
- return arg instanceof Expression ? arg.toString() : quoteIfString(arg).toString();
65
+ if (arg instanceof Expression) {
66
+ return arg.toString();
67
+ }
68
+ else if (typeof arg === "string") {
69
+ return `"${arg}"`;
70
+ }
71
+ else if (Array.isArray(arg)) {
72
+ return JSON.stringify(arg);
73
+ }
74
+ else {
75
+ return arg.toString();
76
+ }
63
77
  }
64
78
  /**
65
79
  * A CEL expression corresponding to a ternary operator, e.g {{ cond ? ifTrue : ifFalse }}
@@ -99,9 +113,9 @@ class CompareExpression extends Expression {
99
113
  const right = valueOf(this.rhs);
100
114
  switch (this.cmp) {
101
115
  case "==":
102
- return left === right;
116
+ return Array.isArray(left) ? this.arrayEquals(left, right) : left === right;
103
117
  case "!=":
104
- return left !== right;
118
+ return Array.isArray(left) ? !this.arrayEquals(left, right) : left !== right;
105
119
  case ">":
106
120
  return left > right;
107
121
  case ">=":
@@ -114,6 +128,10 @@ class CompareExpression extends Expression {
114
128
  throw new Error(`Unknown comparator ${this.cmp}`);
115
129
  }
116
130
  }
131
+ /** @internal */
132
+ arrayEquals(a, b) {
133
+ return a.every((item) => b.includes(item)) && b.every((item) => a.includes(item));
134
+ }
117
135
  toString() {
118
136
  const rhsStr = refOf(this.rhs);
119
137
  return `${this.lhs} ${this.cmp} ${rhsStr}`;
@@ -309,3 +327,39 @@ class BooleanParam extends Param {
309
327
  }
310
328
  exports.BooleanParam = BooleanParam;
311
329
  BooleanParam.type = "boolean";
330
+ /**
331
+ * A parametrized value of String[] type that will be read from .env files
332
+ * if present, or prompted for by the CLI if missing.
333
+ */
334
+ class ListParam extends Param {
335
+ /** @internal */
336
+ runtimeValue() {
337
+ const val = JSON.parse(process.env[this.name]);
338
+ if (!Array.isArray(val) || !val.every((v) => typeof v === "string")) {
339
+ return [];
340
+ }
341
+ return val;
342
+ }
343
+ /** @hidden */
344
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
345
+ greaterThan(rhs) {
346
+ throw new Error(">/< comparison operators not supported on params of type List");
347
+ }
348
+ /** @hidden */
349
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
350
+ greaterThanOrEqualTo(rhs) {
351
+ throw new Error(">/< comparison operators not supported on params of type List");
352
+ }
353
+ /** @hidden */
354
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
355
+ lessThan(rhs) {
356
+ throw new Error(">/< comparison operators not supported on params of type List");
357
+ }
358
+ /** @hidden */
359
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
360
+ lessThanorEqualTo(rhs) {
361
+ throw new Error(">/< comparison operators not supported on params of type List");
362
+ }
363
+ }
364
+ exports.ListParam = ListParam;
365
+ ListParam.type = "list";
@@ -141,7 +141,7 @@ export interface RuntimeOptions {
141
141
  /**
142
142
  * Connect cloud function to specified VPC connector.
143
143
  */
144
- vpcConnector?: string | ResetValue;
144
+ vpcConnector?: string | Expression<string> | ResetValue;
145
145
  /**
146
146
  * Egress settings for VPC connector.
147
147
  */
@@ -83,7 +83,7 @@ export interface GlobalOptions {
83
83
  /**
84
84
  * Connect cloud function to specified VPC connector.
85
85
  */
86
- vpcConnector?: string | ResetValue;
86
+ vpcConnector?: string | Expression<string> | ResetValue;
87
87
  /**
88
88
  * Egress settings for VPC connector.
89
89
  */
@@ -97,7 +97,7 @@ export interface FirebaseAlertOptions extends options.EventHandlerOptions {
97
97
  * Connect cloud function to specified VPC connector.
98
98
  * A value of null removes the VPC connector
99
99
  */
100
- vpcConnector?: string | ResetValue;
100
+ vpcConnector?: string | Expression<string> | ResetValue;
101
101
  /**
102
102
  * Egress settings for VPC connector.
103
103
  * A value of null turns off VPC connector egress settings
@@ -123,7 +123,7 @@ export interface AppDistributionOptions extends options.EventHandlerOptions {
123
123
  /**
124
124
  * Connect cloud function to specified VPC connector.
125
125
  */
126
- vpcConnector?: string | ResetValue;
126
+ vpcConnector?: string | Expression<string> | ResetValue;
127
127
  /**
128
128
  * Egress settings for VPC connector.
129
129
  */
@@ -189,7 +189,7 @@ export interface CrashlyticsOptions extends options.EventHandlerOptions {
189
189
  /**
190
190
  * Connect cloud function to specified VPC connector.
191
191
  */
192
- vpcConnector?: string | ResetValue;
192
+ vpcConnector?: string | Expression<string> | ResetValue;
193
193
  /**
194
194
  * Egress settings for VPC connector.
195
195
  */
@@ -111,7 +111,7 @@ export interface ReferenceOptions<Ref extends string = string> extends options.E
111
111
  /**
112
112
  * Connect cloud function to specified VPC connector.
113
113
  */
114
- vpcConnector?: string | ResetValue;
114
+ vpcConnector?: string | Expression<string> | ResetValue;
115
115
  /**
116
116
  * Egress settings for VPC connector.
117
117
  */
@@ -88,7 +88,7 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions {
88
88
  /**
89
89
  * Connect cloud function to specified VPC connector.
90
90
  */
91
- vpcConnector?: string | ResetValue;
91
+ vpcConnector?: string | Expression<string> | ResetValue;
92
92
  /**
93
93
  * Egress settings for VPC connector.
94
94
  */
@@ -67,6 +67,12 @@ function onCustomEventPublished(eventTypeOrOpts, handler) {
67
67
  (0, encoding_1.convertIfPresent)(endpoint.eventTrigger, opts, "eventFilters", "filters");
68
68
  (0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, "retry");
69
69
  func.__endpoint = endpoint;
70
+ func.__requiredAPIs = [
71
+ {
72
+ api: "eventarcpublishing.googleapis.com",
73
+ reason: "Needed for custom event functions",
74
+ },
75
+ ];
70
76
  return func;
71
77
  }
72
78
  exports.onCustomEventPublished = onCustomEventPublished;
@@ -75,7 +75,7 @@ export interface HttpsOptions extends Omit<GlobalOptions, "region"> {
75
75
  /**
76
76
  * Connect cloud function to specified VPC connector.
77
77
  */
78
- vpcConnector?: string | ResetValue;
78
+ vpcConnector?: string | Expression<string> | ResetValue;
79
79
  /**
80
80
  * Egress settings for VPC connector.
81
81
  */
@@ -44,7 +44,11 @@ function onRequest(optsOrHandler, handler) {
44
44
  opts = optsOrHandler;
45
45
  }
46
46
  if ((0, debug_1.isDebugFeatureEnabled)("enableCors") || "cors" in opts) {
47
- const origin = (0, debug_1.isDebugFeatureEnabled)("enableCors") ? true : opts.cors;
47
+ let origin = opts.cors;
48
+ if ((0, debug_1.isDebugFeatureEnabled)("enableCors")) {
49
+ // Respect `cors: false` to turn off cors even if debug feature is enabled.
50
+ origin = opts.cors === false ? false : true;
51
+ }
48
52
  const userProvidedHandler = handler;
49
53
  handler = (req, res) => {
50
54
  return new Promise((resolve) => {
@@ -86,7 +86,7 @@ export interface BlockingOptions {
86
86
  /**
87
87
  * Connect cloud function to specified VPC connector.
88
88
  */
89
- vpcConnector?: string | ResetValue;
89
+ vpcConnector?: string | Expression<string> | ResetValue;
90
90
  /**
91
91
  * Egress settings for VPC connector.
92
92
  */
@@ -144,7 +144,7 @@ export interface PubSubOptions extends options.EventHandlerOptions {
144
144
  /**
145
145
  * Connect cloud function to specified VPC connector.
146
146
  */
147
- vpcConnector?: string | ResetValue;
147
+ vpcConnector?: string | Expression<string> | ResetValue;
148
148
  /**
149
149
  * Egress settings for VPC connector.
150
150
  */
@@ -220,7 +220,7 @@ export interface StorageOptions extends options.EventHandlerOptions {
220
220
  /**
221
221
  * Connect cloud function to specified VPC connector.
222
222
  */
223
- vpcConnector?: string | ResetValue;
223
+ vpcConnector?: string | Expression<string> | ResetValue;
224
224
  /**
225
225
  * Egress settings for VPC connector.
226
226
  */
@@ -79,7 +79,7 @@ export interface TaskQueueOptions extends options.EventHandlerOptions {
79
79
  /**
80
80
  * Connect cloud function to specified VPC connector.
81
81
  */
82
- vpcConnector?: string | ResetValue;
82
+ vpcConnector?: string | Expression<string> | ResetValue;
83
83
  /**
84
84
  * Egress settings for VPC connector.
85
85
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "4.1.1",
3
+ "version": "4.2.0",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",
@@ -201,7 +201,7 @@
201
201
  "@microsoft/api-extractor": "^7.18.7",
202
202
  "@types/chai": "^4.1.7",
203
203
  "@types/chai-as-promised": "^7.1.0",
204
- "@types/jsonwebtoken": "^8.3.2",
204
+ "@types/jsonwebtoken": "^9.0.0",
205
205
  "@types/mocha": "^5.2.7",
206
206
  "@types/mock-require": "^2.0.0",
207
207
  "@types/nock": "^10.0.3",
@@ -222,7 +222,7 @@
222
222
  "firebase-admin": "^10.3.0",
223
223
  "js-yaml": "^3.13.1",
224
224
  "jsdom": "^16.2.1",
225
- "jsonwebtoken": "^8.5.1",
225
+ "jsonwebtoken": "^9.0.0",
226
226
  "jwk-to-pem": "^2.0.5",
227
227
  "mocha": "^6.1.4",
228
228
  "mock-require": "^3.0.3",