firebase-functions 7.1.0 → 7.2.0-rc.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.
@@ -0,0 +1,24 @@
1
+ import { traceContext } from "../common/trace.mjs";
2
+ import { logger } from "../logger/index.mjs";
3
+ import { params_exports } from "../params/index.mjs";
4
+ import { Change } from "../common/change.mjs";
5
+ import { onInit } from "../common/onInit.mjs";
6
+ import { config } from "../v1/config.mjs";
7
+ import { setGlobalOptions } from "./options.mjs";
8
+ import { pubsub_exports } from "./providers/pubsub.mjs";
9
+ import { alerts_exports } from "./providers/alerts/index.mjs";
10
+ import { database_exports } from "./providers/database.mjs";
11
+ import { eventarc_exports } from "./providers/eventarc.mjs";
12
+ import { https_exports } from "./providers/https.mjs";
13
+ import { identity_exports } from "./providers/identity.mjs";
14
+ import { scheduler_exports } from "./providers/scheduler.mjs";
15
+ import { storage_exports } from "./providers/storage.mjs";
16
+ import { tasks_exports } from "./providers/tasks.mjs";
17
+ import { remoteConfig_exports } from "./providers/remoteConfig.mjs";
18
+ import { testLab_exports } from "./providers/testLab.mjs";
19
+ import { firestore_exports } from "./providers/firestore.mjs";
20
+ import { dataconnect_exports } from "./providers/dataconnect/index.mjs";
21
+ import { app } from "./index.mjs";
22
+ import { graphql_exports } from "./providers/dataconnect/graphql.mjs";
23
+
24
+ export { Change, alerts_exports as alerts, app, config, database_exports as database, dataconnect_exports as dataconnect, eventarc_exports as eventarc, firestore_exports as firestore, graphql_exports as graphql, https_exports as https, identity_exports as identity, logger, onInit, params_exports as params, pubsub_exports as pubsub, remoteConfig_exports as remoteConfig, scheduler_exports as scheduler, setGlobalOptions, storage_exports as storage, tasks_exports as tasks, testLab_exports as testLab, traceContext };
@@ -40,7 +40,15 @@ function getGlobalOptions() {
40
40
  */
41
41
  function optionsToTriggerAnnotations(opts) {
42
42
  const annotation = {};
43
- copyIfPresent(annotation, opts, "concurrency", "minInstances", "maxInstances", "ingressSettings", "labels", "vpcConnector", "vpcConnectorEgressSettings", "secrets");
43
+ 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 ResetValue) {
47
+ annotation.vpcConnectorEgressSettings = null;
48
+ } else {
49
+ annotation.vpcConnectorEgressSettings = vpcEgress;
50
+ }
51
+ }
44
52
  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
  copyIfPresent(endpoint, opts, "omit", "concurrency", "minInstances", "maxInstances", "ingressSettings", "labels", "timeoutSeconds", "cpu");
67
75
  convertIfPresent(endpoint, opts, "serviceAccountEmail", "serviceAccount");
68
- if (opts.vpcConnector !== undefined) {
69
- if (opts.vpcConnector === null || opts.vpcConnector instanceof ResetValue) {
76
+ if (opts.vpcEgress && opts.vpcConnectorEgressSettings) {
77
+ 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 ResetValue;
84
+ const hasConnector = !!connector;
85
+ const resetNetwork = networkInterface === null || networkInterface instanceof 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 = RESET_VALUE;
71
96
  } else {
72
- const vpc = { connector: opts.vpcConnector };
73
- convertIfPresent(vpc, opts, "egressSettings", "vpcConnectorEgressSettings");
97
+ const vpc = {};
98
+ convertIfPresent(vpc, opts, "connector", "vpcConnector");
99
+ if (vpcEgress !== undefined) {
100
+ vpc.egressSettings = vpcEgress;
101
+ }
102
+ convertIfPresent(vpc, opts, "networkInterfaces", "networkInterface", (a) => [a]);
74
103
  endpoint.vpc = vpc;
75
104
  }
76
105
  }
@@ -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 */
@@ -1,3 +1,4 @@
1
+ import { __export } from "../../../_virtual/rolldown_runtime.mjs";
1
2
  import { initV2Endpoint } from "../../../runtime/manifest.mjs";
2
3
  import { convertIfPresent, convertInvoker } from "../../../common/encoding.mjs";
3
4
  import { withInit } from "../../../common/onInit.mjs";
@@ -10,6 +11,10 @@ import { ApolloServer } from "@apollo/server";
10
11
  import { expressMiddleware } from "@as-integrations/express4";
11
12
 
12
13
  //#region src/v2/providers/dataconnect/graphql.ts
14
+ var graphql_exports = /* @__PURE__ */ __export({
15
+ initGraphqlServer: () => initGraphqlServer,
16
+ onGraphRequest: () => onGraphRequest
17
+ });
13
18
  const FIREBASE_AUTH_HEADER = "X-Firebase-Auth-Token";
14
19
  const PRELUDE_GQL = [
15
20
  "scalar UUID",
@@ -95,4 +100,4 @@ function onGraphRequest(opts) {
95
100
  }
96
101
 
97
102
  //#endregion
98
- export { initGraphqlServer, onGraphRequest };
103
+ export { graphql_exports, initGraphqlServer, onGraphRequest };
@@ -27,8 +27,13 @@ export interface ManifestEndpoint {
27
27
  concurrency?: number | Expression<number> | ResetValue;
28
28
  timeoutSeconds?: number | Expression<number> | ResetValue;
29
29
  vpc?: {
30
- connector: string | Expression<string>;
30
+ connector?: string | Expression<string>;
31
31
  egressSettings?: string | Expression<string> | ResetValue;
32
+ networkInterfaces?: Array<{
33
+ network?: string | Expression<string> | ResetValue;
34
+ subnetwork?: string | Expression<string> | ResetValue;
35
+ tags?: string | string[] | Expression<string> | Expression<string[]> | ResetValue;
36
+ }> | ResetValue;
32
37
  } | ResetValue;
33
38
  serviceAccountEmail?: string | Expression<string> | ResetValue;
34
39
  cpu?: number | "gcf_gen1";
@@ -0,0 +1 @@
1
+ export * as graphql from "./providers/dataconnect/graphql";
@@ -0,0 +1,120 @@
1
+ const require_common_trace = require('../common/trace.js');
2
+ const require_logger_index = require('../logger/index.js');
3
+ const require_params_index = require('../params/index.js');
4
+ const require_common_change = require('../common/change.js');
5
+ const require_common_onInit = require('../common/onInit.js');
6
+ const require_v1_config = require('../v1/config.js');
7
+ const require_v2_options = require('./options.js');
8
+ const require_v2_providers_pubsub = require('./providers/pubsub.js');
9
+ const require_v2_providers_alerts_index = require('./providers/alerts/index.js');
10
+ const require_v2_providers_database = require('./providers/database.js');
11
+ const require_v2_providers_eventarc = require('./providers/eventarc.js');
12
+ const require_v2_providers_https = require('./providers/https.js');
13
+ const require_v2_providers_identity = require('./providers/identity.js');
14
+ const require_v2_providers_scheduler = require('./providers/scheduler.js');
15
+ const require_v2_providers_storage = require('./providers/storage.js');
16
+ const require_v2_providers_tasks = require('./providers/tasks.js');
17
+ const require_v2_providers_remoteConfig = require('./providers/remoteConfig.js');
18
+ const require_v2_providers_testLab = require('./providers/testLab.js');
19
+ const require_v2_providers_firestore = require('./providers/firestore.js');
20
+ const require_v2_providers_dataconnect_index = require('./providers/dataconnect/index.js');
21
+ const require_v2_index = require('./index.js');
22
+ const require_v2_providers_dataconnect_graphql = require('./providers/dataconnect/graphql.js');
23
+
24
+ exports.Change = require_common_change.Change;
25
+ Object.defineProperty(exports, 'alerts', {
26
+ enumerable: true,
27
+ get: function () {
28
+ return require_v2_providers_alerts_index.alerts_exports;
29
+ }
30
+ });
31
+ exports.app = require_v2_index.app;
32
+ exports.config = require_v1_config.config;
33
+ Object.defineProperty(exports, 'database', {
34
+ enumerable: true,
35
+ get: function () {
36
+ return require_v2_providers_database.database_exports;
37
+ }
38
+ });
39
+ Object.defineProperty(exports, 'dataconnect', {
40
+ enumerable: true,
41
+ get: function () {
42
+ return require_v2_providers_dataconnect_index.dataconnect_exports;
43
+ }
44
+ });
45
+ Object.defineProperty(exports, 'eventarc', {
46
+ enumerable: true,
47
+ get: function () {
48
+ return require_v2_providers_eventarc.eventarc_exports;
49
+ }
50
+ });
51
+ Object.defineProperty(exports, 'firestore', {
52
+ enumerable: true,
53
+ get: function () {
54
+ return require_v2_providers_firestore.firestore_exports;
55
+ }
56
+ });
57
+ Object.defineProperty(exports, 'graphql', {
58
+ enumerable: true,
59
+ get: function () {
60
+ return require_v2_providers_dataconnect_graphql.graphql_exports;
61
+ }
62
+ });
63
+ Object.defineProperty(exports, 'https', {
64
+ enumerable: true,
65
+ get: function () {
66
+ return require_v2_providers_https.https_exports;
67
+ }
68
+ });
69
+ Object.defineProperty(exports, 'identity', {
70
+ enumerable: true,
71
+ get: function () {
72
+ return require_v2_providers_identity.identity_exports;
73
+ }
74
+ });
75
+ exports.logger = require_logger_index.logger;
76
+ exports.onInit = require_common_onInit.onInit;
77
+ Object.defineProperty(exports, 'params', {
78
+ enumerable: true,
79
+ get: function () {
80
+ return require_params_index.params_exports;
81
+ }
82
+ });
83
+ Object.defineProperty(exports, 'pubsub', {
84
+ enumerable: true,
85
+ get: function () {
86
+ return require_v2_providers_pubsub.pubsub_exports;
87
+ }
88
+ });
89
+ Object.defineProperty(exports, 'remoteConfig', {
90
+ enumerable: true,
91
+ get: function () {
92
+ return require_v2_providers_remoteConfig.remoteConfig_exports;
93
+ }
94
+ });
95
+ Object.defineProperty(exports, 'scheduler', {
96
+ enumerable: true,
97
+ get: function () {
98
+ return require_v2_providers_scheduler.scheduler_exports;
99
+ }
100
+ });
101
+ exports.setGlobalOptions = require_v2_options.setGlobalOptions;
102
+ Object.defineProperty(exports, 'storage', {
103
+ enumerable: true,
104
+ get: function () {
105
+ return require_v2_providers_storage.storage_exports;
106
+ }
107
+ });
108
+ Object.defineProperty(exports, 'tasks', {
109
+ enumerable: true,
110
+ get: function () {
111
+ return require_v2_providers_tasks.tasks_exports;
112
+ }
113
+ });
114
+ Object.defineProperty(exports, 'testLab', {
115
+ enumerable: true,
116
+ get: function () {
117
+ return require_v2_providers_testLab.testLab_exports;
118
+ }
119
+ });
120
+ exports.traceContext = require_common_trace.traceContext;
@@ -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 */
@@ -15,6 +15,10 @@ let __as_integrations_express4 = require("@as-integrations/express4");
15
15
  __as_integrations_express4 = require_rolldown_runtime.__toESM(__as_integrations_express4);
16
16
 
17
17
  //#region src/v2/providers/dataconnect/graphql.ts
18
+ var graphql_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
19
+ initGraphqlServer: () => initGraphqlServer,
20
+ onGraphRequest: () => onGraphRequest
21
+ });
18
22
  const FIREBASE_AUTH_HEADER = "X-Firebase-Auth-Token";
19
23
  const PRELUDE_GQL = [
20
24
  "scalar UUID",
@@ -100,5 +104,11 @@ function onGraphRequest(opts) {
100
104
  }
101
105
 
102
106
  //#endregion
107
+ Object.defineProperty(exports, 'graphql_exports', {
108
+ enumerable: true,
109
+ get: function () {
110
+ return graphql_exports;
111
+ }
112
+ });
103
113
  exports.initGraphqlServer = initGraphqlServer;
104
114
  exports.onGraphRequest = onGraphRequest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "7.1.0",
3
+ "version": "7.2.0-rc.0",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",