firebase-functions 7.2.5 → 7.3.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.
Files changed (76) hide show
  1. package/lib/common/api.d.ts +7 -0
  2. package/lib/common/api.js +34 -0
  3. package/lib/common/providers/https.d.ts +7 -0
  4. package/lib/common/providers/https.js +40 -1
  5. package/lib/esm/common/api.mjs +31 -0
  6. package/lib/esm/common/providers/https.mjs +40 -2
  7. package/lib/esm/lifecycle/index.mjs +55 -0
  8. package/lib/esm/runtime/loader.mjs +12 -2
  9. package/lib/esm/runtime/manifest.mjs +0 -1
  10. package/lib/esm/security/roles.mjs +17 -0
  11. package/lib/esm/v1/cloud-functions.mjs +2 -1
  12. package/lib/esm/v1/function-builder.mjs +15 -1
  13. package/lib/esm/v1/index.mjs +2 -1
  14. package/lib/esm/v1/providers/https.mjs +28 -4
  15. package/lib/esm/v2/index.doc.mjs +4 -1
  16. package/lib/esm/v2/index.mjs +4 -1
  17. package/lib/esm/v2/options.mjs +79 -3
  18. package/lib/esm/v2/providers/ai/index.mjs +2 -2
  19. package/lib/esm/v2/providers/alerts/alerts.mjs +1 -1
  20. package/lib/esm/v2/providers/database.mjs +19 -6
  21. package/lib/esm/v2/providers/dataconnect/graphql.mjs +1 -1
  22. package/lib/esm/v2/providers/dataconnect/index.mjs +1 -1
  23. package/lib/esm/v2/providers/eventarc.mjs +1 -1
  24. package/lib/esm/v2/providers/firestore.mjs +1 -1
  25. package/lib/esm/v2/providers/https.mjs +9 -23
  26. package/lib/esm/v2/providers/identity.mjs +89 -4
  27. package/lib/esm/v2/providers/pubsub.mjs +4 -4
  28. package/lib/esm/v2/providers/remoteConfig.mjs +1 -1
  29. package/lib/esm/v2/providers/scheduler.mjs +1 -1
  30. package/lib/esm/v2/providers/storage.mjs +2 -2
  31. package/lib/esm/v2/providers/tasks.mjs +2 -2
  32. package/lib/esm/v2/providers/testLab.mjs +1 -1
  33. package/lib/esm/v2/security.mjs +19 -0
  34. package/lib/lifecycle/index.d.ts +44 -0
  35. package/lib/lifecycle/index.js +59 -0
  36. package/lib/logger/common.d.ts +20 -5
  37. package/lib/params/types.d.ts +9 -3
  38. package/lib/runtime/loader.js +12 -2
  39. package/lib/runtime/manifest.d.ts +24 -3
  40. package/lib/runtime/manifest.js +0 -1
  41. package/lib/security/roles.d.ts +5 -0
  42. package/lib/security/roles.js +19 -0
  43. package/lib/v1/cloud-functions.d.ts +8 -5
  44. package/lib/v1/cloud-functions.js +2 -1
  45. package/lib/v1/function-builder.d.ts +2 -2
  46. package/lib/v1/function-builder.js +15 -1
  47. package/lib/v1/index.d.ts +1 -0
  48. package/lib/v1/index.js +2 -0
  49. package/lib/v1/providers/https.d.ts +11 -3
  50. package/lib/v1/providers/https.js +28 -3
  51. package/lib/v2/index.d.ts +4 -2
  52. package/lib/v2/index.doc.js +7 -0
  53. package/lib/v2/index.js +7 -0
  54. package/lib/v2/options.d.ts +6 -2
  55. package/lib/v2/options.js +84 -2
  56. package/lib/v2/providers/ai/index.js +2 -2
  57. package/lib/v2/providers/alerts/alerts.js +1 -1
  58. package/lib/v2/providers/database.d.ts +1 -1
  59. package/lib/v2/providers/database.js +19 -6
  60. package/lib/v2/providers/dataconnect/graphql.js +1 -1
  61. package/lib/v2/providers/dataconnect/index.js +1 -1
  62. package/lib/v2/providers/eventarc.js +1 -1
  63. package/lib/v2/providers/firestore.js +1 -1
  64. package/lib/v2/providers/https.js +8 -22
  65. package/lib/v2/providers/identity.d.ts +71 -1
  66. package/lib/v2/providers/identity.js +91 -3
  67. package/lib/v2/providers/pubsub.d.ts +3 -3
  68. package/lib/v2/providers/pubsub.js +4 -4
  69. package/lib/v2/providers/remoteConfig.js +1 -1
  70. package/lib/v2/providers/scheduler.js +1 -1
  71. package/lib/v2/providers/storage.js +2 -2
  72. package/lib/v2/providers/tasks.js +2 -2
  73. package/lib/v2/providers/testLab.js +1 -1
  74. package/lib/v2/security.d.ts +11 -0
  75. package/lib/v2/security.js +19 -0
  76. package/package.json +17 -13
@@ -51,18 +51,12 @@ function onRequest(optsOrHandler, handler) {
51
51
  }
52
52
  handler = require_common_providers_https.withErrorHandler(handler);
53
53
  if (require_common_debug.isDebugFeatureEnabled("enableCors") || "cors" in opts) {
54
- let origin = opts.cors instanceof require_params_types.Expression ? opts.cors.value() : opts.cors;
55
- if (require_common_debug.isDebugFeatureEnabled("enableCors")) {
56
- origin = opts.cors === false ? false : true;
57
- }
58
- if (Array.isArray(origin) && origin.length === 1) {
59
- origin = origin[0];
60
- }
61
- const middleware = (0, cors.default)({ origin });
62
54
  const userProvidedHandler = handler;
63
55
  handler = (req, res) => {
64
56
  return new Promise((resolve) => {
65
57
  res.on("finish", resolve);
58
+ const origin = require_common_providers_https.resolveCorsOrigin(opts.cors);
59
+ const middleware = (0, cors.default)({ origin });
66
60
  middleware(req, res, () => {
67
61
  resolve(userProvidedHandler(req, res));
68
62
  });
@@ -72,7 +66,7 @@ function onRequest(optsOrHandler, handler) {
72
66
  handler = require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler));
73
67
  Object.defineProperty(handler, "__trigger", { get: () => {
74
68
  const baseOpts$1 = require_v2_options.optionsToTriggerAnnotations(require_v2_options.getGlobalOptions());
75
- const specificOpts$1 = require_v2_options.optionsToTriggerAnnotations(opts);
69
+ const specificOpts$1 = require_v2_options.optionsToTriggerAnnotations(opts, "https");
76
70
  const trigger = {
77
71
  platform: "gcfv2",
78
72
  ...baseOpts$1,
@@ -89,7 +83,7 @@ function onRequest(optsOrHandler, handler) {
89
83
  } });
90
84
  const globalOpts = require_v2_options.getGlobalOptions();
91
85
  const baseOpts = require_v2_options.optionsToEndpoint(globalOpts);
92
- const specificOpts = require_v2_options.optionsToEndpoint(opts);
86
+ const specificOpts = require_v2_options.optionsToEndpoint(opts, "https");
93
87
  const endpoint = {
94
88
  ...require_runtime_manifest.initV2Endpoint(globalOpts, opts),
95
89
  platform: "gcfv2",
@@ -116,18 +110,10 @@ function onCall(optsOrHandler, handler) {
116
110
  }
117
111
  let cors$2;
118
112
  if ("cors" in opts) {
119
- if (opts.cors instanceof require_params_types.Expression) {
120
- cors$2 = opts.cors.value();
121
- } else {
122
- cors$2 = opts.cors;
123
- }
113
+ cors$2 = opts.cors;
124
114
  } else {
125
115
  cors$2 = true;
126
116
  }
127
- let origin = require_common_debug.isDebugFeatureEnabled("enableCors") ? true : cors$2;
128
- if (Array.isArray(origin) && origin.length === 1) {
129
- origin = origin[0];
130
- }
131
117
  const fixedLen = (req, resp) => handler(req, resp);
132
118
  let enforceAppCheck = opts.enforceAppCheck ?? require_v2_options.getGlobalOptions().enforceAppCheck;
133
119
  if (enforceAppCheck instanceof require_params_types.Expression) {
@@ -139,7 +125,7 @@ function onCall(optsOrHandler, handler) {
139
125
  }
140
126
  let func = require_common_providers_https.onCallHandler({
141
127
  cors: {
142
- origin,
128
+ origin: cors$2,
143
129
  methods: "POST"
144
130
  },
145
131
  enforceAppCheck,
@@ -150,7 +136,7 @@ function onCall(optsOrHandler, handler) {
150
136
  func = require_v2_trace.wrapTraceContext(require_common_onInit.withInit(func));
151
137
  Object.defineProperty(func, "__trigger", { get: () => {
152
138
  const baseOpts$1 = require_v2_options.optionsToTriggerAnnotations(require_v2_options.getGlobalOptions());
153
- const specificOpts$1 = require_v2_options.optionsToTriggerAnnotations(opts);
139
+ const specificOpts$1 = require_v2_options.optionsToTriggerAnnotations(opts, "https");
154
140
  return {
155
141
  platform: "gcfv2",
156
142
  ...baseOpts$1,
@@ -164,7 +150,7 @@ function onCall(optsOrHandler, handler) {
164
150
  };
165
151
  } });
166
152
  const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
167
- const specificOpts = require_v2_options.optionsToEndpoint(opts);
153
+ const specificOpts = require_v2_options.optionsToEndpoint(opts, "https");
168
154
  func.__endpoint = {
169
155
  ...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
170
156
  platform: "gcfv2",
@@ -2,12 +2,14 @@
2
2
  * Cloud functions to handle events from Google Cloud Identity Platform.
3
3
  * @packageDocumentation
4
4
  */
5
- import { ResetValue } from "../../common/options";
5
+ import { ResetValue, RESET_VALUE } from "../../common/options";
6
6
  import { AuthBlockingEvent, AuthBlockingEventType, AuthUserRecord, BeforeCreateResponse, BeforeSignInResponse, BeforeEmailResponse, BeforeSmsResponse, HandlerV2, HttpsError, MaybeAsync } from "../../common/providers/identity";
7
7
  import { BlockingFunction } from "../../v1/cloud-functions";
8
8
  import { Expression } from "../../params";
9
9
  import * as options from "../options";
10
10
  import { SupportedSecretParam } from "../../params/types";
11
+ import { CloudEvent, CloudFunction } from "../core";
12
+ import { UserRecord as AdminUserRecord } from "firebase-admin/auth";
11
13
  export { HttpsError };
12
14
  export type { AuthUserRecord, AuthBlockingEvent };
13
15
  /** @hidden Internally used when parsing the options. */
@@ -154,3 +156,71 @@ export declare function beforeSmsSent(opts: Omit<BlockingOptions, "idToken" | "a
154
156
  export declare function beforeOperation(eventType: AuthBlockingEventType, optsOrHandler: BlockingOptions | ((event: AuthBlockingEvent) => MaybeAsync<BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void>), handler: HandlerV2): BlockingFunction;
155
157
  /** @hidden */
156
158
  export declare function getOpts(blockingOptions: BlockingOptions): InternalOptions;
159
+ /**
160
+ * The user data payload for an Auth Event. this is the standard "UserRecord"
161
+ * from the firebase Admin SDK.
162
+ */
163
+ export type User = AdminUserRecord;
164
+ /**
165
+ * The event object passed to the handler funcation for Firebase Authentication
166
+ * events.
167
+ */
168
+ export interface AuthEvent<T> extends CloudEvent<T> {
169
+ /** The project identifier */
170
+ project?: string;
171
+ /** The ID of the Identity Platform Tenant Associated with the event. If Applicable */
172
+ tenantId?: string;
173
+ }
174
+ /** Options for configuring a Firebase Authentication Trigger */
175
+ export interface AuthOptions extends options.EventHandlerOptions {
176
+ /**
177
+ * The Id of the Identity Platform tenant to scope the function to.
178
+ * If not set, the function triggers on users across all tenants
179
+ * Set to `IS_NOT_TENANT` to only trigger on users in the default
180
+ * project(no tenant).
181
+ */
182
+ tenantId?: string | Expression<string> | typeof RESET_VALUE;
183
+ }
184
+ export declare const IS_NOT_TENANT: ResetValue;
185
+ /**
186
+ * Handles user creation events in Firebase Authentication.
187
+ *
188
+ * To filter for users not associated with a tenant, use the `IS_NOT_TENANT` constant in options.
189
+ *
190
+ * @beta
191
+ *
192
+ * @param handler - Event handler which is run every time a new user is created.
193
+ * @returns A Cloud Function that you can export.
194
+ */
195
+ export declare function onUserCreated(handler: (event: AuthEvent<User>) => any | Promise<any>): CloudFunction<AuthEvent<User>>;
196
+ /**
197
+ * Handles user creation events in Firebase Authentication.
198
+ *
199
+ * @beta
200
+ *
201
+ * @param opts - Object containing function options.
202
+ * @param handler - Event handler which is run every time a new user is created.
203
+ * @returns A Cloud Function that you can export.
204
+ */
205
+ export declare function onUserCreated(opts: AuthOptions, handler: (event: AuthEvent<User>) => any | Promise<any>): CloudFunction<AuthEvent<User>>;
206
+ /**
207
+ * Handles user deletion events in Firebase Authentication.
208
+ *
209
+ * To filter for users not associated with a tenant, use the `IS_NOT_TENANT` constant in options.
210
+ *
211
+ * @beta
212
+ *
213
+ * @param handler - Event handler that is run every time a user is deleted.
214
+ * @returns A Cloud Function that you can export.
215
+ */
216
+ export declare function onUserDeleted(handler: (event: AuthEvent<User>) => any | Promise<any>): CloudFunction<AuthEvent<User>>;
217
+ /**
218
+ * Handles user deletion events in Firebase Authentication.
219
+ *
220
+ * @beta
221
+ *
222
+ * @param opts - Object containing function options.
223
+ * @param handler - Event handler that is run every time a user is deleted.
224
+ * @returns A Cloud Function that you can export.
225
+ */
226
+ export declare function onUserDeleted(opts: AuthOptions, handler: (event: AuthEvent<User>) => any | Promise<any>): CloudFunction<AuthEvent<User>>;
@@ -1,4 +1,5 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
2
+ const require_common_options = require('../../common/options.js');
2
3
  const require_runtime_manifest = require('../../runtime/manifest.js');
3
4
  const require_common_onInit = require('../../common/onInit.js');
4
5
  const require_common_providers_https = require('../../common/providers/https.js');
@@ -9,12 +10,15 @@ const require_v2_options = require('../options.js');
9
10
  //#region src/v2/providers/identity.ts
10
11
  var identity_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
11
12
  HttpsError: () => require_common_providers_https.HttpsError,
13
+ IS_NOT_TENANT: () => IS_NOT_TENANT,
12
14
  beforeEmailSent: () => beforeEmailSent,
13
15
  beforeOperation: () => beforeOperation,
14
16
  beforeSmsSent: () => beforeSmsSent,
15
17
  beforeUserCreated: () => beforeUserCreated,
16
18
  beforeUserSignedIn: () => beforeUserSignedIn,
17
- getOpts: () => getOpts
19
+ getOpts: () => getOpts,
20
+ onUserCreated: () => onUserCreated,
21
+ onUserDeleted: () => onUserDeleted
18
22
  });
19
23
  /**
20
24
  * Handles an event that is triggered before a user is created.
@@ -60,7 +64,7 @@ function beforeOperation(eventType, optsOrHandler, handler) {
60
64
  const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
61
65
  /** Endpoint */
62
66
  const baseOptsEndpoint = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
63
- const specificOptsEndpoint = require_v2_options.optionsToEndpoint(opts);
67
+ const specificOptsEndpoint = require_v2_options.optionsToEndpoint(opts, "identity");
64
68
  func.__endpoint = {
65
69
  ...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
66
70
  platform: "gcfv2",
@@ -98,9 +102,91 @@ function getOpts(blockingOptions) {
98
102
  refreshToken
99
103
  };
100
104
  }
105
+ const IS_NOT_TENANT = require_common_options.RESET_VALUE;
106
+ function getOptsAndHandler(optsOrHandler, handler) {
107
+ if (typeof optsOrHandler === "function") {
108
+ return {
109
+ opts: {},
110
+ handler: optsOrHandler
111
+ };
112
+ }
113
+ return {
114
+ opts: optsOrHandler,
115
+ handler
116
+ };
117
+ }
118
+ const PROJECT_ID_REGEX = /(?:^|\/)projects\/([^\/]+)/;
119
+ /** @hidden */
120
+ function getAuthEvent(raw) {
121
+ const event = { ...raw };
122
+ if (raw.data) {
123
+ event.data = require_common_providers_identity.userRecordConstructor(raw.data);
124
+ }
125
+ const rawAny = raw;
126
+ const tenantId = rawAny.tenantid || rawAny.tenantId;
127
+ if (tenantId) {
128
+ event.tenantId = tenantId;
129
+ }
130
+ if (raw.source) {
131
+ const match = raw.source.match(PROJECT_ID_REGEX);
132
+ if (match) {
133
+ event.project = match[1];
134
+ }
135
+ }
136
+ return event;
137
+ }
138
+ /** @hidden */
139
+ function makeAuthTrigger(eventType, optsOrHandler, handler) {
140
+ const { opts, handler: handlerFunc } = getOptsAndHandler(optsOrHandler, handler);
141
+ if (typeof handlerFunc !== "function") {
142
+ throw new Error("The handler must be a function.");
143
+ }
144
+ const wrappedHandler = require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handlerFunc));
145
+ const func = ((raw) => {
146
+ const event = getAuthEvent(raw);
147
+ return wrappedHandler(event);
148
+ });
149
+ func.run = handlerFunc;
150
+ const baseOptsEndpoint = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
151
+ const specificOptsEndpoint = require_v2_options.optionsToEndpoint(opts);
152
+ const endpoint = {
153
+ ...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
154
+ platform: "gcfv2",
155
+ ...baseOptsEndpoint,
156
+ ...specificOptsEndpoint,
157
+ labels: {
158
+ ...baseOptsEndpoint?.labels,
159
+ ...specificOptsEndpoint?.labels
160
+ },
161
+ eventTrigger: {
162
+ eventType,
163
+ eventFilters: {},
164
+ retry: opts.retry ?? false,
165
+ region: "global"
166
+ }
167
+ };
168
+ if (opts.tenantId !== undefined) {
169
+ if (opts.tenantId === IS_NOT_TENANT) {
170
+ endpoint.eventTrigger.eventFilters["tenantid"] = "";
171
+ } else {
172
+ endpoint.eventTrigger.eventFilters["tenantid"] = opts.tenantId;
173
+ }
174
+ }
175
+ func.__endpoint = endpoint;
176
+ return func;
177
+ }
178
+ const USER_CREATED_EVENT = "google.firebase.auth.user.v2.created";
179
+ function onUserCreated(optsOrHandler, handler) {
180
+ return makeAuthTrigger(USER_CREATED_EVENT, optsOrHandler, handler);
181
+ }
182
+ const USER_DELETED_EVENT = "google.firebase.auth.user.v2.deleted";
183
+ function onUserDeleted(optsOrHandler, handler) {
184
+ return makeAuthTrigger(USER_DELETED_EVENT, optsOrHandler, handler);
185
+ }
101
186
 
102
187
  //#endregion
103
188
  exports.HttpsError = require_common_providers_https.HttpsError;
189
+ exports.IS_NOT_TENANT = IS_NOT_TENANT;
104
190
  exports.beforeEmailSent = beforeEmailSent;
105
191
  exports.beforeOperation = beforeOperation;
106
192
  exports.beforeSmsSent = beforeSmsSent;
@@ -112,4 +198,6 @@ Object.defineProperty(exports, 'identity_exports', {
112
198
  get: function () {
113
199
  return identity_exports;
114
200
  }
115
- });
201
+ });
202
+ exports.onUserCreated = onUserCreated;
203
+ exports.onUserDeleted = onUserDeleted;
@@ -98,7 +98,7 @@ export interface V1PubSubMessage<T = any> {
98
98
  /** PubSubOptions extend EventHandlerOptions but must include a topic. */
99
99
  export interface PubSubOptions extends options.EventHandlerOptions {
100
100
  /** The Pub/Sub topic to watch for message events */
101
- topic: string;
101
+ topic: string | Expression<string>;
102
102
  /**
103
103
  * If true, do not deploy or emulate this function.
104
104
  */
@@ -182,14 +182,14 @@ export interface PubSubOptions extends options.EventHandlerOptions {
182
182
  * @param handler - runs every time a Cloud Pub/Sub message is published
183
183
  * @typeParam T - Type representing `Message.data`'s JSON format
184
184
  */
185
- export declare function onMessagePublished<T = any>(topic: string, handler: (event: CloudEvent<MessagePublishedData<T>> & V1Compat<"message", V1PubSubMessage<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;
185
+ export declare function onMessagePublished<T = any>(topic: string | Expression<string>, handler: (event: CloudEvent<MessagePublishedData<T>> & V1Compat<"message", V1PubSubMessage<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;
186
186
  /**
187
187
  * Handle a message being published to a Pub/Sub topic.
188
188
  * @param topic - The Pub/Sub topic to watch for message events.
189
189
  * @param handler - runs every time a Cloud Pub/Sub message is published
190
190
  * @typeParam T - Type representing `Message.data`'s JSON format
191
191
  */
192
- export declare function onMessagePublished<T = any>(topic: string, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;
192
+ export declare function onMessagePublished<T = any>(topic: string | Expression<string>, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;
193
193
  /**
194
194
  * Handle a message being published to a Pub/Sub topic.
195
195
  * @param options - Option containing information (topic) for event
@@ -90,7 +90,7 @@ var Message = class {
90
90
  function onMessagePublished(topicOrOptions, handler) {
91
91
  let topic;
92
92
  let opts;
93
- if (typeof topicOrOptions === "string") {
93
+ if (typeof topicOrOptions === "string" || "value" in topicOrOptions) {
94
94
  topic = topicOrOptions;
95
95
  opts = {};
96
96
  } else {
@@ -145,7 +145,7 @@ function onMessagePublished(topicOrOptions, handler) {
145
145
  func.run = handler;
146
146
  Object.defineProperty(func, "__trigger", { get: () => {
147
147
  const baseOpts$1 = require_v2_options.optionsToTriggerAnnotations(require_v2_options.getGlobalOptions());
148
- const specificOpts$1 = require_v2_options.optionsToTriggerAnnotations(opts);
148
+ const specificOpts$1 = require_v2_options.optionsToTriggerAnnotations(opts, "event");
149
149
  return {
150
150
  platform: "gcfv2",
151
151
  ...baseOpts$1,
@@ -156,12 +156,12 @@ function onMessagePublished(topicOrOptions, handler) {
156
156
  },
157
157
  eventTrigger: {
158
158
  eventType: "google.cloud.pubsub.topic.v1.messagePublished",
159
- resource: `projects/${process.env.GCLOUD_PROJECT}/topics/${topic}`
159
+ ...typeof topic === "string" && { resource: `projects/${process.env.GCLOUD_PROJECT}/topics/${topic}` }
160
160
  }
161
161
  };
162
162
  } });
163
163
  const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
164
- const specificOpts = require_v2_options.optionsToEndpoint(opts);
164
+ const specificOpts = require_v2_options.optionsToEndpoint(opts, "event");
165
165
  const endpoint = {
166
166
  ...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
167
167
  platform: "gcfv2",
@@ -25,7 +25,7 @@ function onConfigUpdated(optsOrHandler, handler) {
25
25
  optsOrHandler = {};
26
26
  }
27
27
  const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
28
- const specificOpts = require_v2_options.optionsToEndpoint(optsOrHandler);
28
+ const specificOpts = require_v2_options.optionsToEndpoint(optsOrHandler, "event");
29
29
  const func = require_v2_trace.wrapTraceContext(require_common_onInit.withInit((raw) => {
30
30
  const event = raw;
31
31
  const patchedEvent = require_v2_compat.addV1Compat(event, {
@@ -70,7 +70,7 @@ function onSchedule(args, handler) {
70
70
  func.run = handler;
71
71
  const globalOpts = require_v2_options.getGlobalOptions();
72
72
  const baseOptsEndpoint = require_v2_options.optionsToEndpoint(globalOpts);
73
- const specificOptsEndpoint = require_v2_options.optionsToEndpoint(separatedOpts.opts);
73
+ const specificOptsEndpoint = require_v2_options.optionsToEndpoint(separatedOpts.opts, "event");
74
74
  const ep = {
75
75
  ...require_runtime_manifest.initV2Endpoint(globalOpts, separatedOpts.opts),
76
76
  platform: "gcfv2",
@@ -114,7 +114,7 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
114
114
  func.run = handler;
115
115
  Object.defineProperty(func, "__trigger", { get: () => {
116
116
  const baseOpts = require_v2_options.optionsToTriggerAnnotations(require_v2_options.getGlobalOptions());
117
- const specificOpts = require_v2_options.optionsToTriggerAnnotations(opts);
117
+ const specificOpts = require_v2_options.optionsToTriggerAnnotations(opts, "event");
118
118
  return {
119
119
  platform: "gcfv2",
120
120
  ...baseOpts,
@@ -132,7 +132,7 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
132
132
  func.__endpoint = {};
133
133
  Object.defineProperty(func, "__endpoint", { get: () => {
134
134
  const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
135
- const specificOpts = require_v2_options.optionsToEndpoint(opts);
135
+ const specificOpts = require_v2_options.optionsToEndpoint(opts, "event");
136
136
  const endpoint = {
137
137
  platform: "gcfv2",
138
138
  ...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
@@ -20,7 +20,7 @@ function onTaskDispatched(optsOrHandler, handler) {
20
20
  const func = require_v2_trace.wrapTraceContext(require_common_onInit.withInit(require_common_providers_tasks.onDispatchHandler(fixedLen)));
21
21
  Object.defineProperty(func, "__trigger", { get: () => {
22
22
  const baseOpts$1 = require_v2_options.optionsToTriggerAnnotations(require_v2_options.getGlobalOptions());
23
- const specificOpts$1 = require_v2_options.optionsToTriggerAnnotations(opts);
23
+ const specificOpts$1 = require_v2_options.optionsToTriggerAnnotations(opts, "task");
24
24
  const taskQueueTrigger = {};
25
25
  require_common_encoding.copyIfPresent(taskQueueTrigger, opts, "retryConfig", "rateLimits");
26
26
  require_common_encoding.convertIfPresent(taskQueueTrigger, require_v2_options.getGlobalOptions(), "invoker", "invoker", require_common_encoding.convertInvoker);
@@ -37,7 +37,7 @@ function onTaskDispatched(optsOrHandler, handler) {
37
37
  };
38
38
  } });
39
39
  const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
40
- const specificOpts = require_v2_options.optionsToEndpoint(opts);
40
+ const specificOpts = require_v2_options.optionsToEndpoint(opts, "task");
41
41
  func.__endpoint = {
42
42
  platform: "gcfv2",
43
43
  ...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
@@ -25,7 +25,7 @@ function onTestMatrixCompleted(optsOrHandler, handler) {
25
25
  optsOrHandler = {};
26
26
  }
27
27
  const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
28
- const specificOpts = require_v2_options.optionsToEndpoint(optsOrHandler);
28
+ const specificOpts = require_v2_options.optionsToEndpoint(optsOrHandler, "event");
29
29
  const func = (raw) => {
30
30
  return require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler))(raw);
31
31
  };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A TypeScript literal type for IAM roles to provide compile-time validation.
3
+ */
4
+ export type Role = `roles/${string}.${string}` | `projects/${string}/roles/${string}` | `organizations/${string}/roles/${string}`;
5
+ /**
6
+ * Declares that this codebase requires the specified IAM role to operate.
7
+ * When deployed, the Firebase CLI will automatically provision a managed service account
8
+ * with this role and attach it to all functions in this codebase.
9
+ * @param role The IAM role required (e.g. "roles/bigquery.dataEditor")
10
+ */
11
+ export declare function requiresRole(role: Role): void;
@@ -0,0 +1,19 @@
1
+ const require_security_roles = require('../security/roles.js');
2
+
3
+ //#region src/v2/security.ts
4
+ /**
5
+ * Declares that this codebase requires the specified IAM role to operate.
6
+ * When deployed, the Firebase CLI will automatically provision a managed service account
7
+ * with this role and attach it to all functions in this codebase.
8
+ * @param role The IAM role required (e.g. "roles/bigquery.dataEditor")
9
+ */
10
+ function requiresRole(role) {
11
+ const roleRegex = /^(roles\/[a-zA-Z0-9_.-]+|projects\/[a-zA-Z0-9_-]+\/roles\/[a-zA-Z0-9_.-]+|organizations\/[a-zA-Z0-9_-]+\/roles\/[a-zA-Z0-9_.-]+)$/;
12
+ if (!roleRegex.test(role)) {
13
+ throw new Error(`Invalid role: "${role}". Role must be a valid GCP IAM role format (e.g., "roles/viewer", "projects/<project-id>/roles/<custom-role>", or "organizations/<org-id>/roles/<custom-role>").`);
14
+ }
15
+ require_security_roles.registerRole(role);
16
+ }
17
+
18
+ //#endregion
19
+ exports.requiresRole = requiresRole;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "7.2.5",
3
+ "version": "7.3.0-rc.0",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",
@@ -33,6 +33,11 @@
33
33
  "./lib/esm/logger/compat.mjs"
34
34
  ],
35
35
  "exports": {
36
+ "./lifecycle": {
37
+ "types": "./lib/lifecycle/index.d.ts",
38
+ "import": "./lib/esm/lifecycle/index.mjs",
39
+ "require": "./lib/lifecycle/index.js"
40
+ },
36
41
  "./logger/compat": {
37
42
  "types": "./lib/logger/compat.d.ts",
38
43
  "import": "./lib/esm/logger/compat.mjs",
@@ -346,6 +351,9 @@
346
351
  },
347
352
  "typesVersions": {
348
353
  "*": {
354
+ "lifecycle": [
355
+ "lib/lifecycle/index"
356
+ ],
349
357
  "logger": [
350
358
  "lib/logger/index"
351
359
  ],
@@ -578,37 +586,33 @@
578
586
  "@firebase/api-documenter": "^0.2.0",
579
587
  "@microsoft/api-documenter": "^7.13.45",
580
588
  "@microsoft/api-extractor": "^7.18.7",
589
+ "@microsoft/api-extractor-model": "^7.29.0",
581
590
  "@types/chai": "^4.1.7",
582
591
  "@types/chai-as-promised": "^7.1.0",
583
592
  "@types/jsonwebtoken": "^9.0.0",
584
- "@types/mocha": "^5.2.7",
593
+ "@types/mocha": "^10.0.0",
585
594
  "@types/mock-require": "^2.0.0",
586
595
  "@types/nock": "^10.0.3",
587
596
  "@types/node": "^18.0.0",
588
- "@types/node-fetch": "^3.0.3",
589
597
  "@types/sinon": "^9.0.11",
590
598
  "@typescript-eslint/eslint-plugin": "^8.46.2",
591
599
  "@typescript-eslint/parser": "^8.46.2",
592
- "api-extractor-model-me": "^0.1.1",
593
600
  "chai": "^4.2.0",
594
601
  "chai-as-promised": "^7.1.1",
595
- "child-process-promise": "^2.2.1",
596
602
  "eslint": "^9.38.0",
597
603
  "eslint-config-google": "^0.14.0",
598
604
  "eslint-config-prettier": "^10.1.8",
599
605
  "eslint-plugin-jsdoc": "^61.1.9",
600
606
  "eslint-plugin-prettier": "^4.2.1",
601
- "firebase-admin": "^13.0.0",
607
+ "firebase-admin": "^13.10.0",
602
608
  "genkit": "^1.0.0-rc.4",
603
609
  "graphql": "^16.12.0",
604
610
  "jsdom": "^16.2.1",
605
611
  "jsonwebtoken": "^9.0.0",
606
612
  "jwk-to-pem": "^2.0.5",
607
- "mocha": "^10.2.0",
613
+ "mocha": "^10.8.2",
608
614
  "mock-require": "^3.0.3",
609
- "mz": "^2.7.0",
610
615
  "nock": "^13.2.9",
611
- "node-fetch": "^2.6.7",
612
616
  "portfinder": "^1.0.28",
613
617
  "prettier": "^2.8.8",
614
618
  "protobufjs-cli": "^1.1.1",
@@ -617,14 +621,14 @@
617
621
  "ts-node": "^10.4.0",
618
622
  "tsdown": "^0.15.11",
619
623
  "typescript": "^5.9.3",
620
- "yaml": "^2.8.1",
624
+ "yaml": "^2.8.3",
621
625
  "yargs": "^15.3.1"
622
626
  },
623
627
  "peerDependencies": {
624
628
  "@apollo/server": "^5.2.0",
625
629
  "@as-integrations/express4": "^1.1.2",
626
- "graphql": "^16.12.0",
627
- "firebase-admin": "^11.10.0 || ^12.0.0 || ^13.0.0"
630
+ "firebase-admin": "^11.10.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
631
+ "graphql": "^16.12.0"
628
632
  },
629
633
  "peerDependenciesMeta": {
630
634
  "@apollo/server": {
@@ -638,6 +642,6 @@
638
642
  }
639
643
  },
640
644
  "engines": {
641
- "node": ">=18.0.0"
645
+ "node": ">=20.0.0"
642
646
  }
643
647
  }