firebase-functions 7.1.1 → 7.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.
@@ -18,6 +18,32 @@ export type VpcEgressSetting = "PRIVATE_RANGES_ONLY" | "ALL_TRAFFIC";
18
18
  * List of available options for `IngressSettings`.
19
19
  */
20
20
  export type IngressSetting = "ALLOW_ALL" | "ALLOW_INTERNAL_ONLY" | "ALLOW_INTERNAL_AND_GCLB";
21
+ /**
22
+ * Interface for a direct VPC network connection.
23
+ * At least one of network or subnetwork must be specified.
24
+ */
25
+ export interface NetworkInterface {
26
+ /**
27
+ * Network to use for VPC direct connect.
28
+ * network or subnetwork must be specified to use VPC direct connect, though
29
+ * both can be specified as well. "default" is an acceptable value.
30
+ * Mutually exclusive with vpcConnector.
31
+ */
32
+ network?: string | Expression<string> | ResetValue;
33
+ /**
34
+ * Subnetwork to use for VPC direct connect.
35
+ * network or subnetwork must be specified to use VPC direct connect, though
36
+ * both can be specified as well. "default" is an acceptable value.
37
+ * Mutually exclusive with vpcConnector.
38
+ */
39
+ subnetwork?: string | Expression<string> | ResetValue;
40
+ /**
41
+ * Tags for VPC traffic.
42
+ * An optional field for VPC direct connect
43
+ * mutually exclusive with vpcConnector.
44
+ */
45
+ tags?: string | string[] | Expression<string> | Expression<string[]> | ResetValue;
46
+ }
21
47
  /**
22
48
  * `GlobalOptions` are options that can be set across an entire project.
23
49
  * These options are common to HTTPS and event handling functions.
@@ -82,12 +108,21 @@ export interface GlobalOptions {
82
108
  cpu?: number | "gcf_gen1";
83
109
  /**
84
110
  * Connect a function to a specified VPC connector.
111
+ * Mutually exclusive with networkInterface
85
112
  */
86
113
  vpcConnector?: string | Expression<string> | ResetValue;
87
114
  /**
88
115
  * Egress settings for VPC connector.
89
116
  */
90
117
  vpcConnectorEgressSettings?: VpcEgressSetting | ResetValue;
118
+ /**
119
+ * An alias for vpcConnectorEgressSettings.
120
+ */
121
+ vpcEgress?: VpcEgressSetting | ResetValue;
122
+ /**
123
+ * Network Interface to use with VPC Direct Connect
124
+ */
125
+ networkInterface?: NetworkInterface | ResetValue;
91
126
  /**
92
127
  * Specific service account for the function to run as.
93
128
  */
package/lib/v2/options.js CHANGED
@@ -40,7 +40,15 @@ function getGlobalOptions() {
40
40
  */
41
41
  function optionsToTriggerAnnotations(opts) {
42
42
  const annotation = {};
43
- require_common_encoding.copyIfPresent(annotation, opts, "concurrency", "minInstances", "maxInstances", "ingressSettings", "labels", "vpcConnector", "vpcConnectorEgressSettings", "secrets");
43
+ require_common_encoding.copyIfPresent(annotation, opts, "concurrency", "minInstances", "maxInstances", "ingressSettings", "labels", "vpcConnector", "secrets");
44
+ const vpcEgress = opts.vpcEgress ?? opts.vpcConnectorEgressSettings;
45
+ if (vpcEgress !== undefined) {
46
+ if (vpcEgress === null || vpcEgress instanceof require_common_options.ResetValue) {
47
+ annotation.vpcConnectorEgressSettings = null;
48
+ } else {
49
+ annotation.vpcConnectorEgressSettings = vpcEgress;
50
+ }
51
+ }
44
52
  require_common_encoding.convertIfPresent(annotation, opts, "availableMemoryMb", "memory", (mem) => {
45
53
  return MemoryOptionToMB[mem];
46
54
  });
@@ -65,12 +73,33 @@ function optionsToEndpoint(opts) {
65
73
  const endpoint = {};
66
74
  require_common_encoding.copyIfPresent(endpoint, opts, "omit", "concurrency", "minInstances", "maxInstances", "ingressSettings", "labels", "timeoutSeconds", "cpu");
67
75
  require_common_encoding.convertIfPresent(endpoint, opts, "serviceAccountEmail", "serviceAccount");
68
- if (opts.vpcConnector !== undefined) {
69
- if (opts.vpcConnector === null || opts.vpcConnector instanceof require_common_options.ResetValue) {
76
+ if (opts.vpcEgress && opts.vpcConnectorEgressSettings) {
77
+ require_logger_index.warn("vpcEgress and vpcConnectorEgressSettings are both set. Using vpcEgress");
78
+ }
79
+ const vpcEgress = opts.vpcEgress ?? opts.vpcConnectorEgressSettings;
80
+ const connector = opts.vpcConnector;
81
+ const networkInterface = opts.networkInterface;
82
+ if (connector !== undefined || vpcEgress !== undefined || networkInterface !== undefined) {
83
+ const resetConnector = connector === null || connector instanceof require_common_options.ResetValue;
84
+ const hasConnector = !!connector;
85
+ const resetNetwork = networkInterface === null || networkInterface instanceof require_common_options.ResetValue;
86
+ const hasNetwork = !!networkInterface && !resetNetwork;
87
+ if (hasNetwork) {
88
+ if (!networkInterface.network && !networkInterface.subnetwork) {
89
+ throw new Error("At least one of network or subnetwork must be specified in networkInterface.");
90
+ }
91
+ }
92
+ if (hasNetwork && hasConnector) {
93
+ throw new Error("Cannot set both vpcConnector and networkInterface");
94
+ } else if (resetConnector && !hasNetwork || resetNetwork && !hasConnector) {
70
95
  endpoint.vpc = require_common_options.RESET_VALUE;
71
96
  } else {
72
- const vpc = { connector: opts.vpcConnector };
73
- require_common_encoding.convertIfPresent(vpc, opts, "egressSettings", "vpcConnectorEgressSettings");
97
+ const vpc = {};
98
+ require_common_encoding.convertIfPresent(vpc, opts, "connector", "vpcConnector");
99
+ if (vpcEgress !== undefined) {
100
+ vpc.egressSettings = vpcEgress;
101
+ }
102
+ require_common_encoding.convertIfPresent(vpc, opts, "networkInterfaces", "networkInterface", (a) => [a]);
74
103
  endpoint.vpc = vpc;
75
104
  }
76
105
  }
@@ -19,7 +19,17 @@ export interface RawRTDBCloudEvent extends CloudEvent<RawRTDBCloudEventData> {
19
19
  instance: string;
20
20
  ref: string;
21
21
  location: string;
22
+ authtype: AuthType;
23
+ authid?: string;
22
24
  }
25
+ /**
26
+ * AuthType defines the possible values for the authType field in a Realtime Database event.
27
+ * - app_user: an end user of an application..
28
+ * - admin: an admin user of an application. In the context of impersonate endpoints used by the admin SDK, the impersonator.
29
+ * - unauthenticated: no credentials were used to authenticate the change that triggered the occurrence.
30
+ * - unknown: a general type to capture all other principals not captured in the other auth types.
31
+ */
32
+ export type AuthType = "app_user" | "admin" | "unauthenticated" | "unknown";
23
33
  /** A CloudEvent that contains a DataSnapshot or a Change<DataSnapshot> */
24
34
  export interface DatabaseEvent<T, Params = Record<string, string>> extends CloudEvent<T> {
25
35
  /** The domain of the database instance */
@@ -35,6 +45,14 @@ export interface DatabaseEvent<T, Params = Record<string, string>> extends Cloud
35
45
  * Only named capture groups will be populated - {key}, {key=*}, {key=**}
36
46
  */
37
47
  params: Params;
48
+ /**
49
+ * The type of principal that triggered the event.
50
+ */
51
+ authType: AuthType;
52
+ /**
53
+ * The unique identifier of the principal.
54
+ */
55
+ authId?: string;
38
56
  }
39
57
  /** ReferenceOptions extend EventHandlerOptions with provided ref and optional instance */
40
58
  export interface ReferenceOptions<Ref extends string = string> extends options.EventHandlerOptions {
@@ -106,9 +106,13 @@ function makeDatabaseEvent(event, data, instance, params) {
106
106
  ...event,
107
107
  firebaseDatabaseHost: event.firebasedatabasehost,
108
108
  data: snapshot,
109
- params
109
+ params,
110
+ authType: event.authtype || "unknown",
111
+ authId: event.authid
110
112
  };
111
113
  delete databaseEvent.firebasedatabasehost;
114
+ delete databaseEvent.authtype;
115
+ delete databaseEvent.authid;
112
116
  return databaseEvent;
113
117
  }
114
118
  /** @hidden */
@@ -122,9 +126,13 @@ function makeChangedDatabaseEvent(event, instance, params) {
122
126
  before,
123
127
  after
124
128
  },
125
- params
129
+ params,
130
+ authType: event.authtype || "unknown",
131
+ authId: event.authid
126
132
  };
127
133
  delete databaseEvent.firebasedatabasehost;
134
+ delete databaseEvent.authtype;
135
+ delete databaseEvent.authid;
128
136
  return databaseEvent;
129
137
  }
130
138
  /** @internal */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "7.1.1",
3
+ "version": "7.2.0",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",