firebase-functions 7.0.6 → 7.1.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.
@@ -1,9 +1,9 @@
1
1
  import { debug, error, warn } from "../../logger/index.mjs";
2
2
  import { getApp } from "../app.mjs";
3
3
  import { isDebugFeatureEnabled } from "../debug.mjs";
4
+ import { getAuth } from "firebase-admin/auth";
4
5
  import cors from "cors";
5
6
  import { getAppCheck } from "firebase-admin/app-check";
6
- import { getAuth } from "firebase-admin/auth";
7
7
 
8
8
  //#region src/common/providers/https.ts
9
9
  const JWT_REGEX = /^[a-zA-Z0-9\-_=]+?\.[a-zA-Z0-9\-_=]+?\.([a-zA-Z0-9\-_=]+)?$/;
@@ -5,9 +5,9 @@ import { firebaseConfig } from "../common/config.mjs";
5
5
  import { setApp } from "../common/app.mjs";
6
6
  import { Change } from "../common/change.mjs";
7
7
  import { onInit } from "../common/onInit.mjs";
8
- import { config } from "./config.mjs";
9
8
  import { DEFAULT_FAILURE_POLICY, INGRESS_SETTINGS_OPTIONS, MAX_NUMBER_USER_LABELS, MAX_TIMEOUT_SECONDS, MIN_TIMEOUT_SECONDS, SUPPORTED_REGIONS, VALID_MEMORY_OPTIONS, VPC_EGRESS_SETTINGS_OPTIONS } from "./function-configuration.mjs";
10
9
  import { makeCloudFunction, optionsToEndpoint, optionsToTrigger } from "./cloud-functions.mjs";
10
+ import { config } from "./config.mjs";
11
11
  import { analytics_exports } from "./providers/analytics.mjs";
12
12
  import { auth_exports } from "./providers/auth.mjs";
13
13
  import { database_exports } from "./providers/database.mjs";
@@ -1,8 +1,8 @@
1
1
  import { __export } from "../../_virtual/rolldown_runtime.mjs";
2
2
  import { initV1Endpoint } from "../../runtime/manifest.mjs";
3
+ import { makeCloudFunction, optionsToEndpoint, optionsToTrigger } from "../cloud-functions.mjs";
3
4
  import { HttpsError } from "../../common/providers/https.mjs";
4
5
  import { UserRecordMetadata, userRecordConstructor, wrapHandler } from "../../common/providers/identity.mjs";
5
- import { makeCloudFunction, optionsToEndpoint, optionsToTrigger } from "../cloud-functions.mjs";
6
6
 
7
7
  //#region src/v1/providers/auth.ts
8
8
  var auth_exports = /* @__PURE__ */ __export({
@@ -1,10 +1,10 @@
1
1
  import { __export } from "../../_virtual/rolldown_runtime.mjs";
2
2
  import { firebaseConfig } from "../../common/config.mjs";
3
3
  import { getApp } from "../../common/app.mjs";
4
+ import { makeCloudFunction } from "../cloud-functions.mjs";
4
5
  import { normalizePath } from "../../common/utilities/path.mjs";
5
6
  import { DataSnapshot } from "../../common/providers/database.mjs";
6
7
  import { applyChange } from "../../common/utilities/utils.mjs";
7
- import { makeCloudFunction } from "../cloud-functions.mjs";
8
8
 
9
9
  //#region src/v1/providers/database.ts
10
10
  var database_exports = /* @__PURE__ */ __export({
@@ -1,7 +1,7 @@
1
1
  import { __export } from "../../_virtual/rolldown_runtime.mjs";
2
2
  import { Change } from "../../common/change.mjs";
3
- import { createBeforeSnapshotFromJson, createSnapshotFromJson } from "../../common/providers/firestore.mjs";
4
3
  import { makeCloudFunction } from "../cloud-functions.mjs";
4
+ import { createBeforeSnapshotFromJson, createSnapshotFromJson } from "../../common/providers/firestore.mjs";
5
5
  import { posix } from "path";
6
6
 
7
7
  //#region src/v1/providers/firestore.ts
@@ -2,9 +2,9 @@ import { __export } from "../../_virtual/rolldown_runtime.mjs";
2
2
  import { initV1Endpoint } from "../../runtime/manifest.mjs";
3
3
  import { convertIfPresent, convertInvoker } from "../../common/encoding.mjs";
4
4
  import { withInit } from "../../common/onInit.mjs";
5
- import { wrapTraceContext } from "../../v2/trace.mjs";
6
- import { HttpsError, onCallHandler, withErrorHandler } from "../../common/providers/https.mjs";
7
5
  import { optionsToEndpoint, optionsToTrigger } from "../cloud-functions.mjs";
6
+ import { HttpsError, onCallHandler, withErrorHandler } from "../../common/providers/https.mjs";
7
+ import { wrapTraceContext } from "../../v2/trace.mjs";
8
8
 
9
9
  //#region src/v1/providers/https.ts
10
10
  var https_exports = /* @__PURE__ */ __export({
@@ -1,8 +1,8 @@
1
1
  import { __export } from "../../_virtual/rolldown_runtime.mjs";
2
2
  import { initTaskQueueTrigger, initV1Endpoint } from "../../runtime/manifest.mjs";
3
3
  import { convertIfPresent, convertInvoker, copyIfPresent } from "../../common/encoding.mjs";
4
- import { onDispatchHandler } from "../../common/providers/tasks.mjs";
5
4
  import { optionsToEndpoint, optionsToTrigger } from "../cloud-functions.mjs";
5
+ import { onDispatchHandler } from "../../common/providers/tasks.mjs";
6
6
 
7
7
  //#region src/v1/providers/tasks.ts
8
8
  var tasks_exports = /* @__PURE__ */ __export({
@@ -0,0 +1,77 @@
1
+ import { Message } from "./providers/pubsub.mjs";
2
+
3
+ //#region src/v2/compat.ts
4
+ const V1_COMPAT_PATCHED = Symbol.for("firebase.functions.v2.compat");
5
+ /**
6
+ * Patches a CloudEvent with V1 compatibility properties (context and message) if it's a supported type (e.g., Pub/Sub).
7
+ * This function ensures idempotency by using a Symbol to mark already patched events.
8
+ * @param event The CloudEvent to potentially patch.
9
+ * @returns The patched CloudEvent with V1 compatibility properties, or the original event if not a supported event type or already patched.
10
+ */
11
+ function patchV1Compat(event) {
12
+ if (event[V1_COMPAT_PATCHED]) {
13
+ return event;
14
+ }
15
+ Object.defineProperty(event, V1_COMPAT_PATCHED, {
16
+ value: true,
17
+ enumerable: false,
18
+ writable: false,
19
+ configurable: false
20
+ });
21
+ switch (event.type) {
22
+ case "google.cloud.pubsub.topic.v1.messagePublished": {
23
+ const pubsubEvent = event;
24
+ const pubsubData = pubsubEvent.data;
25
+ if (!pubsubData || !pubsubData.message) {
26
+ throw new Error("Malformed Pub/Sub event: missing 'message' property.");
27
+ }
28
+ if (!(pubsubData.message instanceof Message)) {
29
+ pubsubData.message = new Message(pubsubData.message);
30
+ }
31
+ const v2Message = pubsubData.message;
32
+ Object.defineProperty(pubsubEvent, "context", {
33
+ get: () => {
34
+ const service = "pubsub.googleapis.com";
35
+ const sourcePrefix = `//${service}/`;
36
+ return {
37
+ eventId: v2Message.messageId,
38
+ timestamp: v2Message.publishTime,
39
+ eventType: "google.pubsub.topic.publish",
40
+ resource: {
41
+ service,
42
+ name: event.source?.startsWith(sourcePrefix) ? event.source.substring(sourcePrefix.length) : event.source || ""
43
+ },
44
+ params: {}
45
+ };
46
+ },
47
+ configurable: true,
48
+ enumerable: true
49
+ });
50
+ Object.defineProperty(pubsubEvent, "message", {
51
+ get: () => {
52
+ const baseV1Message = {
53
+ data: v2Message.data,
54
+ messageId: v2Message.messageId,
55
+ publishTime: v2Message.publishTime,
56
+ attributes: v2Message.attributes,
57
+ ...v2Message.orderingKey && { orderingKey: v2Message.orderingKey }
58
+ };
59
+ return {
60
+ ...baseV1Message,
61
+ get json() {
62
+ return v2Message.json;
63
+ },
64
+ toJSON: () => baseV1Message
65
+ };
66
+ },
67
+ configurable: true,
68
+ enumerable: true
69
+ });
70
+ return pubsubEvent;
71
+ }
72
+ default: return event;
73
+ }
74
+ }
75
+
76
+ //#endregion
77
+ export { patchV1Compat };
@@ -4,14 +4,15 @@ import { params_exports } from "../params/index.mjs";
4
4
  import { setApp } from "../common/app.mjs";
5
5
  import { Change } from "../common/change.mjs";
6
6
  import { onInit } from "../common/onInit.mjs";
7
- import "./core.mjs";
7
+ import { config } from "../v1/config.mjs";
8
8
  import { setGlobalOptions } from "./options.mjs";
9
+ import { pubsub_exports } from "./providers/pubsub.mjs";
10
+ import "./core.mjs";
9
11
  import { alerts_exports } from "./providers/alerts/index.mjs";
10
12
  import { database_exports } from "./providers/database.mjs";
11
13
  import { eventarc_exports } from "./providers/eventarc.mjs";
12
14
  import { https_exports } from "./providers/https.mjs";
13
15
  import { identity_exports } from "./providers/identity.mjs";
14
- import { pubsub_exports } from "./providers/pubsub.mjs";
15
16
  import { scheduler_exports } from "./providers/scheduler.mjs";
16
17
  import { storage_exports } from "./providers/storage.mjs";
17
18
  import { tasks_exports } from "./providers/tasks.mjs";
@@ -19,7 +20,6 @@ import { remoteConfig_exports } from "./providers/remoteConfig.mjs";
19
20
  import { testLab_exports } from "./providers/testLab.mjs";
20
21
  import { firestore_exports } from "./providers/firestore.mjs";
21
22
  import { dataconnect_exports } from "./providers/dataconnect/index.mjs";
22
- import { config } from "../v1/config.mjs";
23
23
 
24
24
  //#region src/v2/index.ts
25
25
  const app = { setEmulatedAdminApp: setApp };
@@ -2,12 +2,12 @@ import { __export } from "../../_virtual/rolldown_runtime.mjs";
2
2
  import { initV2Endpoint } from "../../runtime/manifest.mjs";
3
3
  import { getApp } from "../../common/app.mjs";
4
4
  import { withInit } from "../../common/onInit.mjs";
5
- import { wrapTraceContext } from "../trace.mjs";
6
- import { getGlobalOptions, optionsToEndpoint } from "../options.mjs";
7
5
  import { normalizePath } from "../../common/utilities/path.mjs";
8
6
  import { DataSnapshot } from "../../common/providers/database.mjs";
9
- import { PathPattern } from "../../common/utilities/path-pattern.mjs";
10
7
  import { applyChange } from "../../common/utilities/utils.mjs";
8
+ import { wrapTraceContext } from "../trace.mjs";
9
+ import { getGlobalOptions, optionsToEndpoint } from "../options.mjs";
10
+ import { PathPattern } from "../../common/utilities/path-pattern.mjs";
11
11
 
12
12
  //#region src/v2/providers/database.ts
13
13
  var database_exports = /* @__PURE__ */ __export({
@@ -1,9 +1,9 @@
1
1
  import { initV2Endpoint } from "../../../runtime/manifest.mjs";
2
2
  import { convertIfPresent, convertInvoker } from "../../../common/encoding.mjs";
3
3
  import { withInit } from "../../../common/onInit.mjs";
4
+ import { withErrorHandler } from "../../../common/providers/https.mjs";
4
5
  import { wrapTraceContext } from "../../trace.mjs";
5
6
  import { getGlobalOptions, optionsToEndpoint } from "../../options.mjs";
6
- import { withErrorHandler } from "../../../common/providers/https.mjs";
7
7
  import express from "express";
8
8
  import fs from "fs";
9
9
  import { ApolloServer } from "@apollo/server";
@@ -60,7 +60,6 @@ async function initGraphqlServer(opts) {
60
60
  }
61
61
  }
62
62
  /**
63
- * @hidden
64
63
  * Handles HTTPS GraphQL requests.
65
64
  * @param {GraphqlServerOptions} opts - Options for configuring the GraphQL server.
66
65
  * @returns {HttpsFunction} A function you can export and deploy.
@@ -1,9 +1,9 @@
1
1
  import { __export } from "../../../_virtual/rolldown_runtime.mjs";
2
2
  import { initV2Endpoint } from "../../../runtime/manifest.mjs";
3
3
  import { withInit } from "../../../common/onInit.mjs";
4
+ import { normalizePath } from "../../../common/utilities/path.mjs";
4
5
  import { wrapTraceContext } from "../../trace.mjs";
5
6
  import { getGlobalOptions, optionsToEndpoint } from "../../options.mjs";
6
- import { normalizePath } from "../../../common/utilities/path.mjs";
7
7
  import { PathPattern } from "../../../common/utilities/path-pattern.mjs";
8
8
 
9
9
  //#region src/v2/providers/dataconnect/index.ts
@@ -3,12 +3,12 @@ import { error } from "../../logger/index.mjs";
3
3
  import { initV2Endpoint } from "../../runtime/manifest.mjs";
4
4
  import { Change } from "../../common/change.mjs";
5
5
  import { withInit } from "../../common/onInit.mjs";
6
- import "../core.mjs";
6
+ import { normalizePath } from "../../common/utilities/path.mjs";
7
+ import { createBeforeSnapshotFromJson, createBeforeSnapshotFromProtobuf, createSnapshotFromJson, createSnapshotFromProtobuf } from "../../common/providers/firestore.mjs";
7
8
  import { wrapTraceContext } from "../trace.mjs";
8
9
  import { getGlobalOptions, optionsToEndpoint } from "../options.mjs";
9
- import { normalizePath } from "../../common/utilities/path.mjs";
10
+ import "../core.mjs";
10
11
  import { PathPattern } from "../../common/utilities/path-pattern.mjs";
11
- import { createBeforeSnapshotFromJson, createBeforeSnapshotFromProtobuf, createSnapshotFromJson, createSnapshotFromProtobuf } from "../../common/providers/firestore.mjs";
12
12
 
13
13
  //#region src/v2/providers/firestore.ts
14
14
  var firestore_exports = /* @__PURE__ */ __export({
@@ -6,9 +6,9 @@ import { initV2Endpoint } from "../../runtime/manifest.mjs";
6
6
  import { isDebugFeatureEnabled } from "../../common/debug.mjs";
7
7
  import { convertIfPresent, convertInvoker, copyIfPresent } from "../../common/encoding.mjs";
8
8
  import { withInit } from "../../common/onInit.mjs";
9
+ import { HttpsError, onCallHandler, withErrorHandler } from "../../common/providers/https.mjs";
9
10
  import { wrapTraceContext } from "../trace.mjs";
10
11
  import { getGlobalOptions, optionsToEndpoint, optionsToTriggerAnnotations } from "../options.mjs";
11
- import { HttpsError, onCallHandler, withErrorHandler } from "../../common/providers/https.mjs";
12
12
  import cors from "cors";
13
13
 
14
14
  //#region src/v2/providers/https.ts
@@ -1,10 +1,10 @@
1
1
  import { __export } from "../../_virtual/rolldown_runtime.mjs";
2
2
  import { initV2Endpoint } from "../../runtime/manifest.mjs";
3
3
  import { withInit } from "../../common/onInit.mjs";
4
- import { wrapTraceContext } from "../trace.mjs";
5
- import { getGlobalOptions, optionsToEndpoint } from "../options.mjs";
6
4
  import { HttpsError } from "../../common/providers/https.mjs";
7
5
  import { wrapHandler } from "../../common/providers/identity.mjs";
6
+ import { wrapTraceContext } from "../trace.mjs";
7
+ import { getGlobalOptions, optionsToEndpoint } from "../options.mjs";
8
8
 
9
9
  //#region src/v2/providers/identity.ts
10
10
  var identity_exports = /* @__PURE__ */ __export({
@@ -4,14 +4,13 @@ import { copyIfPresent } from "../../common/encoding.mjs";
4
4
  import { withInit } from "../../common/onInit.mjs";
5
5
  import { wrapTraceContext } from "../trace.mjs";
6
6
  import { getGlobalOptions, optionsToEndpoint, optionsToTriggerAnnotations } from "../options.mjs";
7
+ import { patchV1Compat } from "../compat.mjs";
7
8
 
8
9
  //#region src/v2/providers/pubsub.ts
9
10
  var pubsub_exports = /* @__PURE__ */ __export({
10
11
  Message: () => Message,
11
12
  onMessagePublished: () => onMessagePublished
12
13
  });
13
- const V1_CONTEXT = Symbol("v1Context");
14
- const V1_MESSAGE = Symbol("v1Message");
15
14
  /**
16
15
  * Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
17
16
  * You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
@@ -34,7 +33,6 @@ const V1_MESSAGE = Symbol("v1Message");
34
33
  */
35
34
  /**
36
35
  * Interface representing a Google Cloud Pub/Sub message.
37
- *
38
36
  * @param data - Payload of a Pub/Sub message.
39
37
  * @typeParam T - Type representing `Message.data`'s JSON format
40
38
  */
@@ -66,7 +64,6 @@ var Message = class {
66
64
  }
67
65
  /**
68
66
  * Returns a JSON-serializable representation of this object.
69
- *
70
67
  * @returns A JSON-serializable representation of this object.
71
68
  */
72
69
  toJSON() {
@@ -102,69 +99,8 @@ function onMessagePublished(topicOrOptions, handler) {
102
99
  delete opts.topic;
103
100
  }
104
101
  const func = (raw) => {
105
- const messagePublishedData = raw.data;
106
- if (!(messagePublishedData.message instanceof Message)) {
107
- messagePublishedData.message = new Message(messagePublishedData.message);
108
- }
109
- /**
110
- * Get the v1-compatible EventContext object.
111
- * This is a compatibility layer to ease migration from v1 to v2.
112
- * @returns A v1 EventContext-like object.
113
- */
114
- Object.defineProperty(raw, "context", { get: function() {
115
- if (this[V1_CONTEXT]) {
116
- return this[V1_CONTEXT];
117
- }
118
- const data = this.data;
119
- if (!data?.message) {
120
- throw new Error("Malformed Pub/Sub event: 'data.message' is missing.");
121
- }
122
- const v1Context = {
123
- eventId: data.message.messageId,
124
- timestamp: data.message.publishTime,
125
- eventType: "google.pubsub.topic.publish",
126
- resource: {
127
- service: "pubsub.googleapis.com",
128
- name: this.source.replace("//pubsub.googleapis.com/", "")
129
- },
130
- params: {}
131
- };
132
- this[V1_CONTEXT] = v1Context;
133
- return this[V1_CONTEXT];
134
- } });
135
- /**
136
- * Get the v1-compatible Message object.
137
- * This is a compatibility layer to ease migration from v1 to v2.
138
- * @returns A plain object mimicking the v1 Message structure.
139
- */
140
- Object.defineProperty(raw, "message", { get: function() {
141
- if (this[V1_MESSAGE]) {
142
- return this[V1_MESSAGE];
143
- }
144
- const data = this.data;
145
- if (!data || !data.message) {
146
- throw new Error("Malformed Pub/Sub event: 'data.message' is missing.");
147
- }
148
- const v2Message = data.message;
149
- const baseMessage = {
150
- data: v2Message.data,
151
- messageId: v2Message.messageId,
152
- publishTime: v2Message.publishTime,
153
- attributes: v2Message.attributes || {}
154
- };
155
- if (v2Message.orderingKey) {
156
- baseMessage.orderingKey = v2Message.orderingKey;
157
- }
158
- this[V1_MESSAGE] = {
159
- ...baseMessage,
160
- get json() {
161
- return v2Message.json;
162
- },
163
- toJSON: () => baseMessage
164
- };
165
- return this[V1_MESSAGE];
166
- } });
167
- return wrapTraceContext(withInit(handler))(raw);
102
+ const event = patchV1Compat(raw);
103
+ return wrapTraceContext(withInit(handler))(event);
168
104
  };
169
105
  func.run = handler;
170
106
  Object.defineProperty(func, "__trigger", { get: () => {
@@ -3,8 +3,8 @@ import { initTaskQueueTrigger, initV2Endpoint } from "../../runtime/manifest.mjs
3
3
  import { convertIfPresent, convertInvoker, copyIfPresent } from "../../common/encoding.mjs";
4
4
  import { withInit } from "../../common/onInit.mjs";
5
5
  import { wrapTraceContext } from "../trace.mjs";
6
- import { getGlobalOptions, optionsToEndpoint, optionsToTriggerAnnotations } from "../options.mjs";
7
6
  import { onDispatchHandler } from "../../common/providers/tasks.mjs";
7
+ import { getGlobalOptions, optionsToEndpoint, optionsToTriggerAnnotations } from "../options.mjs";
8
8
 
9
9
  //#region src/v2/providers/tasks.ts
10
10
  var tasks_exports = /* @__PURE__ */ __export({ onTaskDispatched: () => onTaskDispatched });
@@ -0,0 +1,15 @@
1
+ import { CloudEvent } from "./core";
2
+ import { MessagePublishedData, V1PubSubMessage } from "./providers/pubsub";
3
+ import { EventContext as V1EventContext } from "../v1";
4
+ export interface V1Context extends Omit<V1EventContext, "resource"> {
5
+ resource: {
6
+ service: string;
7
+ name: string;
8
+ };
9
+ }
10
+ export type PubSubCloudEvent<T> = CloudEvent<MessagePublishedData<T>> & {
11
+ context: V1Context;
12
+ message: V1PubSubMessage<T>;
13
+ };
14
+ export declare function patchV1Compat<T>(event: CloudEvent<MessagePublishedData<T>>): PubSubCloudEvent<T>;
15
+ export declare function patchV1Compat<T>(event: CloudEvent<T>): CloudEvent<T>;
@@ -0,0 +1,77 @@
1
+ const require_v2_providers_pubsub = require('./providers/pubsub.js');
2
+
3
+ //#region src/v2/compat.ts
4
+ const V1_COMPAT_PATCHED = Symbol.for("firebase.functions.v2.compat");
5
+ /**
6
+ * Patches a CloudEvent with V1 compatibility properties (context and message) if it's a supported type (e.g., Pub/Sub).
7
+ * This function ensures idempotency by using a Symbol to mark already patched events.
8
+ * @param event The CloudEvent to potentially patch.
9
+ * @returns The patched CloudEvent with V1 compatibility properties, or the original event if not a supported event type or already patched.
10
+ */
11
+ function patchV1Compat(event) {
12
+ if (event[V1_COMPAT_PATCHED]) {
13
+ return event;
14
+ }
15
+ Object.defineProperty(event, V1_COMPAT_PATCHED, {
16
+ value: true,
17
+ enumerable: false,
18
+ writable: false,
19
+ configurable: false
20
+ });
21
+ switch (event.type) {
22
+ case "google.cloud.pubsub.topic.v1.messagePublished": {
23
+ const pubsubEvent = event;
24
+ const pubsubData = pubsubEvent.data;
25
+ if (!pubsubData || !pubsubData.message) {
26
+ throw new Error("Malformed Pub/Sub event: missing 'message' property.");
27
+ }
28
+ if (!(pubsubData.message instanceof require_v2_providers_pubsub.Message)) {
29
+ pubsubData.message = new require_v2_providers_pubsub.Message(pubsubData.message);
30
+ }
31
+ const v2Message = pubsubData.message;
32
+ Object.defineProperty(pubsubEvent, "context", {
33
+ get: () => {
34
+ const service = "pubsub.googleapis.com";
35
+ const sourcePrefix = `//${service}/`;
36
+ return {
37
+ eventId: v2Message.messageId,
38
+ timestamp: v2Message.publishTime,
39
+ eventType: "google.pubsub.topic.publish",
40
+ resource: {
41
+ service,
42
+ name: event.source?.startsWith(sourcePrefix) ? event.source.substring(sourcePrefix.length) : event.source || ""
43
+ },
44
+ params: {}
45
+ };
46
+ },
47
+ configurable: true,
48
+ enumerable: true
49
+ });
50
+ Object.defineProperty(pubsubEvent, "message", {
51
+ get: () => {
52
+ const baseV1Message = {
53
+ data: v2Message.data,
54
+ messageId: v2Message.messageId,
55
+ publishTime: v2Message.publishTime,
56
+ attributes: v2Message.attributes,
57
+ ...v2Message.orderingKey && { orderingKey: v2Message.orderingKey }
58
+ };
59
+ return {
60
+ ...baseV1Message,
61
+ get json() {
62
+ return v2Message.json;
63
+ },
64
+ toJSON: () => baseV1Message
65
+ };
66
+ },
67
+ configurable: true,
68
+ enumerable: true
69
+ });
70
+ return pubsubEvent;
71
+ }
72
+ default: return event;
73
+ }
74
+ }
75
+
76
+ //#endregion
77
+ exports.patchV1Compat = patchV1Compat;
package/lib/v2/index.d.ts CHANGED
@@ -26,6 +26,7 @@ export { onInit } from "./core";
26
26
  export type { CloudFunction, CloudEvent, ParamsOf } from "./core";
27
27
  export { Change } from "../common/change";
28
28
  export { traceContext } from "../common/trace";
29
+ export type { PubSubCloudEvent } from "./compat";
29
30
  import * as params from "../params";
30
31
  export { params };
31
32
  export { config } from "../v1/config";
package/lib/v2/index.js CHANGED
@@ -5,14 +5,14 @@ const require_common_app = require('../common/app.js');
5
5
  const require_common_change = require('../common/change.js');
6
6
  const require_common_onInit = require('../common/onInit.js');
7
7
  const require_v1_config = require('../v1/config.js');
8
- require('./core.js');
9
8
  const require_v2_options = require('./options.js');
9
+ const require_v2_providers_pubsub = require('./providers/pubsub.js');
10
+ require('./core.js');
10
11
  const require_v2_providers_alerts_index = require('./providers/alerts/index.js');
11
12
  const require_v2_providers_database = require('./providers/database.js');
12
13
  const require_v2_providers_eventarc = require('./providers/eventarc.js');
13
14
  const require_v2_providers_https = require('./providers/https.js');
14
15
  const require_v2_providers_identity = require('./providers/identity.js');
15
- const require_v2_providers_pubsub = require('./providers/pubsub.js');
16
16
  const require_v2_providers_scheduler = require('./providers/scheduler.js');
17
17
  const require_v2_providers_storage = require('./providers/storage.js');
18
18
  const require_v2_providers_tasks = require('./providers/tasks.js');
@@ -4,14 +4,12 @@ import { HttpsFunction, HttpsOptions } from "../https";
4
4
  /** @hidden */
5
5
  export declare function initGraphqlServer(opts: GraphqlServerOptions): Promise<express.Express>;
6
6
  /**
7
- * @hidden
8
7
  * Handles HTTPS GraphQL requests.
9
8
  * @param {GraphqlServerOptions} opts - Options for configuring the GraphQL server.
10
9
  * @returns {HttpsFunction} A function you can export and deploy.
11
10
  */
12
11
  export declare function onGraphRequest(opts: GraphqlServerOptions): HttpsFunction;
13
12
  /**
14
- * @hidden
15
13
  * Options for configuring the GraphQL server.
16
14
  */
17
15
  export interface GraphqlServerOptions extends Omit<HttpsOptions, "cors"> {
@@ -35,7 +33,6 @@ export interface GraphqlServerOptions extends Omit<HttpsOptions, "cors"> {
35
33
  resolvers: GraphqlResolvers;
36
34
  }
37
35
  /**
38
- * @hidden
39
36
  * Per-request context state shared by all resolvers in a particular query.
40
37
  */
41
38
  export interface FirebaseContext {
@@ -45,7 +42,6 @@ export interface FirebaseContext {
45
42
  };
46
43
  }
47
44
  /**
48
- * @hidden
49
45
  * Resolver functions that populate data for individual GraphQL schema fields.
50
46
  */
51
47
  export interface GraphqlResolvers {
@@ -65,7 +65,6 @@ async function initGraphqlServer(opts) {
65
65
  }
66
66
  }
67
67
  /**
68
- * @hidden
69
68
  * Handles HTTPS GraphQL requests.
70
69
  * @param {GraphqlServerOptions} opts - Options for configuring the GraphQL server.
71
70
  * @returns {HttpsFunction} A function you can export and deploy.
@@ -6,8 +6,8 @@ const require_common_onInit = require('../../common/onInit.js');
6
6
  const require_common_utilities_path = require('../../common/utilities/path.js');
7
7
  const require_common_providers_firestore = require('../../common/providers/firestore.js');
8
8
  const require_v2_trace = require('../trace.js');
9
- require('../core.js');
10
9
  const require_v2_options = require('../options.js');
10
+ require('../core.js');
11
11
  const require_common_utilities_path_pattern = require('../../common/utilities/path-pattern.js');
12
12
 
13
13
  //#region src/v2/providers/firestore.ts
@@ -1,9 +1,9 @@
1
1
  import { ResetValue } from "../../common/options";
2
- import { CloudEvent, CloudFunction } from "../core";
3
- import type { EventContext } from "../../v1/index";
2
+ import { CloudFunction } from "../core";
4
3
  import { Expression } from "../../params";
5
4
  import * as options from "../options";
6
5
  import { SupportedSecretParam } from "../../params/types";
6
+ import { PubSubCloudEvent } from "../compat";
7
7
  /**
8
8
  * Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
9
9
  * You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
@@ -26,7 +26,6 @@ import { SupportedSecretParam } from "../../params/types";
26
26
  */
27
27
  /**
28
28
  * Interface representing a Google Cloud Pub/Sub message.
29
- *
30
29
  * @param data - Payload of a Pub/Sub message.
31
30
  * @typeParam T - Type representing `Message.data`'s JSON format
32
31
  */
@@ -66,7 +65,6 @@ export declare class Message<T> {
66
65
  get json(): T;
67
66
  /**
68
67
  * Returns a JSON-serializable representation of this object.
69
- *
70
68
  * @returns A JSON-serializable representation of this object.
71
69
  */
72
70
  toJSON(): any;
@@ -97,17 +95,6 @@ export interface V1PubSubMessage<T = any> {
97
95
  readonly json: T;
98
96
  toJSON(): any;
99
97
  }
100
- export interface MessagePublishedEvent<T = any> extends CloudEvent<MessagePublishedData<T>> {
101
- /**
102
- * v1-compatible EventContext.
103
- */
104
- readonly context: EventContext;
105
- /**
106
- * v1-compatible Pub/Sub Message.
107
- * Note: This is a plain object mimicking the v1 Message structure, not an instance of the v1 Message class.
108
- */
109
- readonly message: V1PubSubMessage<T>;
110
- }
111
98
  /** PubSubOptions extend EventHandlerOptions but must include a topic. */
112
99
  export interface PubSubOptions extends options.EventHandlerOptions {
113
100
  /** The Pub/Sub topic to watch for message events */
@@ -127,7 +114,6 @@ export interface PubSubOptions extends options.EventHandlerOptions {
127
114
  /**
128
115
  * Timeout for the function in seconds, possible values are 0 to 540.
129
116
  * HTTPS functions can specify a higher timeout.
130
- *
131
117
  * @remarks
132
118
  * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
133
119
  * function depends on the type of function: Event handling functions have a
@@ -138,7 +124,6 @@ export interface PubSubOptions extends options.EventHandlerOptions {
138
124
  timeoutSeconds?: number | Expression<number> | ResetValue;
139
125
  /**
140
126
  * Min number of actual instances to be running at a given time.
141
- *
142
127
  * @remarks
143
128
  * Instances will be billed for memory allocation and 10% of CPU allocation
144
129
  * while idle.
@@ -150,7 +135,6 @@ export interface PubSubOptions extends options.EventHandlerOptions {
150
135
  maxInstances?: number | Expression<number> | ResetValue;
151
136
  /**
152
137
  * Number of requests a function can serve at once.
153
- *
154
138
  * @remarks
155
139
  * Can only be applied to functions running on Cloud Functions v2.
156
140
  * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
@@ -160,7 +144,6 @@ export interface PubSubOptions extends options.EventHandlerOptions {
160
144
  concurrency?: number | Expression<number> | ResetValue;
161
145
  /**
162
146
  * Fractional number of CPUs to allocate to a function.
163
- *
164
147
  * @remarks
165
148
  * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
166
149
  * This is different from the defaults when using the gcloud utility and is different from
@@ -199,11 +182,11 @@ export interface PubSubOptions extends options.EventHandlerOptions {
199
182
  * @param handler - runs every time a Cloud Pub/Sub message is published
200
183
  * @typeParam T - Type representing `Message.data`'s JSON format
201
184
  */
202
- export declare function onMessagePublished<T = any>(topic: string, handler: (event: MessagePublishedEvent<T>) => any | Promise<any>): CloudFunction<MessagePublishedEvent<T>>;
185
+ export declare function onMessagePublished<T = any>(topic: string, handler: (event: PubSubCloudEvent<T>) => any | Promise<any>): CloudFunction<PubSubCloudEvent<T>>;
203
186
  /**
204
187
  * Handle a message being published to a Pub/Sub topic.
205
188
  * @param options - Option containing information (topic) for event
206
189
  * @param handler - runs every time a Cloud Pub/Sub message is published
207
190
  * @typeParam T - Type representing `Message.data`'s JSON format
208
191
  */
209
- export declare function onMessagePublished<T = any>(options: PubSubOptions, handler: (event: MessagePublishedEvent<T>) => any | Promise<any>): CloudFunction<MessagePublishedEvent<T>>;
192
+ export declare function onMessagePublished<T = any>(options: PubSubOptions, handler: (event: PubSubCloudEvent<T>) => any | Promise<any>): CloudFunction<PubSubCloudEvent<T>>;
@@ -4,14 +4,13 @@ const require_common_encoding = require('../../common/encoding.js');
4
4
  const require_common_onInit = require('../../common/onInit.js');
5
5
  const require_v2_trace = require('../trace.js');
6
6
  const require_v2_options = require('../options.js');
7
+ const require_v2_compat = require('../compat.js');
7
8
 
8
9
  //#region src/v2/providers/pubsub.ts
9
10
  var pubsub_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
10
11
  Message: () => Message,
11
12
  onMessagePublished: () => onMessagePublished
12
13
  });
13
- const V1_CONTEXT = Symbol("v1Context");
14
- const V1_MESSAGE = Symbol("v1Message");
15
14
  /**
16
15
  * Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
17
16
  * You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
@@ -34,7 +33,6 @@ const V1_MESSAGE = Symbol("v1Message");
34
33
  */
35
34
  /**
36
35
  * Interface representing a Google Cloud Pub/Sub message.
37
- *
38
36
  * @param data - Payload of a Pub/Sub message.
39
37
  * @typeParam T - Type representing `Message.data`'s JSON format
40
38
  */
@@ -66,7 +64,6 @@ var Message = class {
66
64
  }
67
65
  /**
68
66
  * Returns a JSON-serializable representation of this object.
69
- *
70
67
  * @returns A JSON-serializable representation of this object.
71
68
  */
72
69
  toJSON() {
@@ -102,69 +99,8 @@ function onMessagePublished(topicOrOptions, handler) {
102
99
  delete opts.topic;
103
100
  }
104
101
  const func = (raw) => {
105
- const messagePublishedData = raw.data;
106
- if (!(messagePublishedData.message instanceof Message)) {
107
- messagePublishedData.message = new Message(messagePublishedData.message);
108
- }
109
- /**
110
- * Get the v1-compatible EventContext object.
111
- * This is a compatibility layer to ease migration from v1 to v2.
112
- * @returns A v1 EventContext-like object.
113
- */
114
- Object.defineProperty(raw, "context", { get: function() {
115
- if (this[V1_CONTEXT]) {
116
- return this[V1_CONTEXT];
117
- }
118
- const data = this.data;
119
- if (!data?.message) {
120
- throw new Error("Malformed Pub/Sub event: 'data.message' is missing.");
121
- }
122
- const v1Context = {
123
- eventId: data.message.messageId,
124
- timestamp: data.message.publishTime,
125
- eventType: "google.pubsub.topic.publish",
126
- resource: {
127
- service: "pubsub.googleapis.com",
128
- name: this.source.replace("//pubsub.googleapis.com/", "")
129
- },
130
- params: {}
131
- };
132
- this[V1_CONTEXT] = v1Context;
133
- return this[V1_CONTEXT];
134
- } });
135
- /**
136
- * Get the v1-compatible Message object.
137
- * This is a compatibility layer to ease migration from v1 to v2.
138
- * @returns A plain object mimicking the v1 Message structure.
139
- */
140
- Object.defineProperty(raw, "message", { get: function() {
141
- if (this[V1_MESSAGE]) {
142
- return this[V1_MESSAGE];
143
- }
144
- const data = this.data;
145
- if (!data || !data.message) {
146
- throw new Error("Malformed Pub/Sub event: 'data.message' is missing.");
147
- }
148
- const v2Message = data.message;
149
- const baseMessage = {
150
- data: v2Message.data,
151
- messageId: v2Message.messageId,
152
- publishTime: v2Message.publishTime,
153
- attributes: v2Message.attributes || {}
154
- };
155
- if (v2Message.orderingKey) {
156
- baseMessage.orderingKey = v2Message.orderingKey;
157
- }
158
- this[V1_MESSAGE] = {
159
- ...baseMessage,
160
- get json() {
161
- return v2Message.json;
162
- },
163
- toJSON: () => baseMessage
164
- };
165
- return this[V1_MESSAGE];
166
- } });
167
- return require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler))(raw);
102
+ const event = require_v2_compat.patchV1Compat(raw);
103
+ return require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler))(event);
168
104
  };
169
105
  func.run = handler;
170
106
  Object.defineProperty(func, "__trigger", { get: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "7.0.6",
3
+ "version": "7.1.0",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",