firebase-functions 7.0.2 → 7.0.4

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.
@@ -19,7 +19,7 @@ import { tasks_exports } from "./providers/tasks.mjs";
19
19
  import { remoteConfig_exports } from "./providers/remoteConfig.mjs";
20
20
  import { testLab_exports } from "./providers/testLab.mjs";
21
21
  import { firestore_exports } from "./providers/firestore.mjs";
22
- import { dataconnect_exports } from "./providers/dataconnect.mjs";
22
+ import { dataconnect_exports } from "./providers/dataconnect/index.mjs";
23
23
 
24
24
  //#region src/v2/index.ts
25
25
  const app = { setEmulatedAdminApp: setApp };
@@ -0,0 +1,89 @@
1
+ import { initV2Endpoint } from "../../../runtime/manifest.mjs";
2
+ import { convertIfPresent, convertInvoker } from "../../../common/encoding.mjs";
3
+ import { withInit } from "../../../common/onInit.mjs";
4
+ import { withErrorHandler } from "../../../common/providers/https.mjs";
5
+ import { wrapTraceContext } from "../../trace.mjs";
6
+ import { getGlobalOptions, optionsToEndpoint } from "../../options.mjs";
7
+ import express from "express";
8
+ import fs from "fs";
9
+ import { ApolloServer } from "@apollo/server";
10
+ import { expressMiddleware } from "@as-integrations/express4";
11
+
12
+ //#region src/v2/providers/dataconnect/graphql.ts
13
+ const FIREBASE_AUTH_HEADER = "X-Firebase-Auth-Token";
14
+ /** @hidden */
15
+ async function initGraphqlServer(opts) {
16
+ if (!opts.schema && !opts.schemaFilePath || opts.schema && opts.schemaFilePath) {
17
+ throw new Error("Exactly one of 'schema' or 'schemaFilePath' must be provided.");
18
+ }
19
+ if (opts.schemaFilePath) {
20
+ opts.schema = fs.readFileSync(opts.schemaFilePath, "utf-8");
21
+ }
22
+ if (!opts.resolvers.query && !opts.resolvers.mutation) {
23
+ throw new Error("At least one query or mutation resolver must be provided.");
24
+ }
25
+ const apolloResolvers = {};
26
+ if (opts.resolvers.query) {
27
+ apolloResolvers.Query = opts.resolvers.query;
28
+ }
29
+ if (opts.resolvers.mutation) {
30
+ apolloResolvers.Mutation = opts.resolvers.mutation;
31
+ }
32
+ try {
33
+ const serverPromise = (async () => {
34
+ const app = express();
35
+ const server = new ApolloServer({
36
+ typeDefs: opts.schema,
37
+ resolvers: apolloResolvers
38
+ });
39
+ await server.start();
40
+ app.use(`/${opts.path ?? "graphql"}`, express.json(), expressMiddleware(server, { context: ({ req }) => Promise.resolve({ auth: { token: req.header(FIREBASE_AUTH_HEADER) } }) }));
41
+ return app;
42
+ })();
43
+ return serverPromise;
44
+ } catch (e) {
45
+ if (e instanceof Error) {
46
+ throw new Error("Error initializing GraphQL server: " + e.message);
47
+ } else {
48
+ throw e;
49
+ }
50
+ }
51
+ }
52
+ /**
53
+ * @hidden
54
+ * Handles HTTPS GraphQL requests.
55
+ * @param {GraphqlServerOptions} opts - Options for configuring the GraphQL server.
56
+ * @returns {HttpsFunction} A function you can export and deploy.
57
+ */
58
+ function onGraphRequest(opts) {
59
+ let serverPromise = null;
60
+ const handler = wrapTraceContext(withInit(withErrorHandler(async (req, res) => {
61
+ serverPromise = serverPromise ?? initGraphqlServer(opts);
62
+ const app = await serverPromise;
63
+ app(req, res);
64
+ })));
65
+ const globalOpts = getGlobalOptions();
66
+ const baseOpts = optionsToEndpoint(globalOpts);
67
+ const specificOpts = optionsToEndpoint(opts);
68
+ const endpoint = {
69
+ ...initV2Endpoint(globalOpts, opts),
70
+ platform: "gcfv2",
71
+ ...baseOpts,
72
+ ...specificOpts,
73
+ labels: {
74
+ ...baseOpts?.labels,
75
+ ...specificOpts?.labels
76
+ },
77
+ dataConnectGraphqlTrigger: {}
78
+ };
79
+ convertIfPresent(endpoint.dataConnectGraphqlTrigger, globalOpts, "invoker", "invoker", convertInvoker);
80
+ convertIfPresent(endpoint.dataConnectGraphqlTrigger, opts, "invoker", "invoker", convertInvoker);
81
+ if (opts.schemaFilePath) {
82
+ endpoint.dataConnectGraphqlTrigger.schemaFilePath = opts.schemaFilePath;
83
+ }
84
+ handler.__endpoint = endpoint;
85
+ return handler;
86
+ }
87
+
88
+ //#endregion
89
+ export { initGraphqlServer, onGraphRequest };
@@ -1,12 +1,12 @@
1
- import { __export } from "../../_virtual/rolldown_runtime.mjs";
2
- import { initV2Endpoint } from "../../runtime/manifest.mjs";
3
- import { withInit } from "../../common/onInit.mjs";
4
- import { normalizePath } from "../../common/utilities/path.mjs";
5
- import { wrapTraceContext } from "../trace.mjs";
6
- import { getGlobalOptions, optionsToEndpoint } from "../options.mjs";
7
- import { PathPattern } from "../../common/utilities/path-pattern.mjs";
1
+ import { __export } from "../../../_virtual/rolldown_runtime.mjs";
2
+ import { initV2Endpoint } from "../../../runtime/manifest.mjs";
3
+ import { withInit } from "../../../common/onInit.mjs";
4
+ import { normalizePath } from "../../../common/utilities/path.mjs";
5
+ import { wrapTraceContext } from "../../trace.mjs";
6
+ import { getGlobalOptions, optionsToEndpoint } from "../../options.mjs";
7
+ import { PathPattern } from "../../../common/utilities/path-pattern.mjs";
8
8
 
9
- //#region src/v2/providers/dataconnect.ts
9
+ //#region src/v2/providers/dataconnect/index.ts
10
10
  var dataconnect_exports = /* @__PURE__ */ __export({
11
11
  mutationExecutedEventType: () => mutationExecutedEventType,
12
12
  onMutationExecuted: () => onMutationExecuted
@@ -45,6 +45,10 @@ export interface ManifestEndpoint {
45
45
  callableTrigger?: {
46
46
  genkitAction?: string;
47
47
  };
48
+ dataConnectGraphqlTrigger?: {
49
+ invoker?: string[];
50
+ schemaFilePath?: string;
51
+ };
48
52
  eventTrigger?: {
49
53
  eventFilters: Record<string, string | Expression<string>>;
50
54
  eventFilterPathPatterns?: Record<string, string | Expression<string>>;
package/lib/v2/index.js CHANGED
@@ -19,7 +19,7 @@ const require_v2_providers_tasks = require('./providers/tasks.js');
19
19
  const require_v2_providers_remoteConfig = require('./providers/remoteConfig.js');
20
20
  const require_v2_providers_testLab = require('./providers/testLab.js');
21
21
  const require_v2_providers_firestore = require('./providers/firestore.js');
22
- const require_v2_providers_dataconnect = require('./providers/dataconnect.js');
22
+ const require_v2_providers_dataconnect_index = require('./providers/dataconnect/index.js');
23
23
 
24
24
  //#region src/v2/index.ts
25
25
  const app = { setEmulatedAdminApp: require_common_app.setApp };
@@ -43,7 +43,7 @@ Object.defineProperty(exports, 'database', {
43
43
  Object.defineProperty(exports, 'dataconnect', {
44
44
  enumerable: true,
45
45
  get: function () {
46
- return require_v2_providers_dataconnect.dataconnect_exports;
46
+ return require_v2_providers_dataconnect_index.dataconnect_exports;
47
47
  }
48
48
  });
49
49
  Object.defineProperty(exports, 'eventarc', {
@@ -0,0 +1,58 @@
1
+ import express from "express";
2
+ import type { GraphQLResolveInfo } from "graphql";
3
+ import { HttpsFunction, HttpsOptions } from "../https";
4
+ /** @hidden */
5
+ export declare function initGraphqlServer(opts: GraphqlServerOptions): Promise<express.Express>;
6
+ /**
7
+ * @hidden
8
+ * Handles HTTPS GraphQL requests.
9
+ * @param {GraphqlServerOptions} opts - Options for configuring the GraphQL server.
10
+ * @returns {HttpsFunction} A function you can export and deploy.
11
+ */
12
+ export declare function onGraphRequest(opts: GraphqlServerOptions): HttpsFunction;
13
+ /**
14
+ * @hidden
15
+ * Options for configuring the GraphQL server.
16
+ */
17
+ export interface GraphqlServerOptions extends Omit<HttpsOptions, "cors"> {
18
+ /**
19
+ * A valid SDL string that represents the GraphQL server's schema.
20
+ * Either `schema` or `schemaFilePath` is required.
21
+ */
22
+ schema?: string;
23
+ /**
24
+ * A relative file path from the Firebase project directory to a valid GraphQL schema.
25
+ * Either `schema` or `schemaFilePath` is required.
26
+ */
27
+ schemaFilePath?: string;
28
+ /**
29
+ * The path where the GraphQL server will be served on the Cloud Run function.
30
+ * e.g. https://...run.app/{path}
31
+ * If no path is provided, "graphql" is used as the default.
32
+ */
33
+ path?: string;
34
+ /** A map of functions that populate data for individual GraphQL schema fields. */
35
+ resolvers: GraphqlResolvers;
36
+ }
37
+ /**
38
+ * @hidden
39
+ * Per-request context state shared by all resolvers in a particular query.
40
+ */
41
+ export interface FirebaseContext {
42
+ auth: {
43
+ /** The token attached to the `X-Firebase-Auth-Token` in the request, if present. */
44
+ token?: string;
45
+ };
46
+ }
47
+ /**
48
+ * @hidden
49
+ * Resolver functions that populate data for individual GraphQL schema fields.
50
+ */
51
+ export interface GraphqlResolvers {
52
+ query?: {
53
+ [resolver: string]: (parent: unknown, args: Record<string, unknown>, context: FirebaseContext, info: GraphQLResolveInfo) => unknown;
54
+ };
55
+ mutation?: {
56
+ [key: string]: (parent: unknown, args: Record<string, unknown>, context: FirebaseContext, info: GraphQLResolveInfo) => unknown;
57
+ };
58
+ }
@@ -0,0 +1,95 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.js');
2
+ const require_runtime_manifest = require('../../../runtime/manifest.js');
3
+ const require_common_encoding = require('../../../common/encoding.js');
4
+ const require_common_onInit = require('../../../common/onInit.js');
5
+ const require_common_providers_https = require('../../../common/providers/https.js');
6
+ const require_v2_trace = require('../../trace.js');
7
+ const require_v2_options = require('../../options.js');
8
+ let express = require("express");
9
+ express = require_rolldown_runtime.__toESM(express);
10
+ let fs = require("fs");
11
+ fs = require_rolldown_runtime.__toESM(fs);
12
+ let __apollo_server = require("@apollo/server");
13
+ __apollo_server = require_rolldown_runtime.__toESM(__apollo_server);
14
+ let __as_integrations_express4 = require("@as-integrations/express4");
15
+ __as_integrations_express4 = require_rolldown_runtime.__toESM(__as_integrations_express4);
16
+
17
+ //#region src/v2/providers/dataconnect/graphql.ts
18
+ const FIREBASE_AUTH_HEADER = "X-Firebase-Auth-Token";
19
+ /** @hidden */
20
+ async function initGraphqlServer(opts) {
21
+ if (!opts.schema && !opts.schemaFilePath || opts.schema && opts.schemaFilePath) {
22
+ throw new Error("Exactly one of 'schema' or 'schemaFilePath' must be provided.");
23
+ }
24
+ if (opts.schemaFilePath) {
25
+ opts.schema = fs.default.readFileSync(opts.schemaFilePath, "utf-8");
26
+ }
27
+ if (!opts.resolvers.query && !opts.resolvers.mutation) {
28
+ throw new Error("At least one query or mutation resolver must be provided.");
29
+ }
30
+ const apolloResolvers = {};
31
+ if (opts.resolvers.query) {
32
+ apolloResolvers.Query = opts.resolvers.query;
33
+ }
34
+ if (opts.resolvers.mutation) {
35
+ apolloResolvers.Mutation = opts.resolvers.mutation;
36
+ }
37
+ try {
38
+ const serverPromise = (async () => {
39
+ const app = (0, express.default)();
40
+ const server = new __apollo_server.ApolloServer({
41
+ typeDefs: opts.schema,
42
+ resolvers: apolloResolvers
43
+ });
44
+ await server.start();
45
+ app.use(`/${opts.path ?? "graphql"}`, express.default.json(), (0, __as_integrations_express4.expressMiddleware)(server, { context: ({ req }) => Promise.resolve({ auth: { token: req.header(FIREBASE_AUTH_HEADER) } }) }));
46
+ return app;
47
+ })();
48
+ return serverPromise;
49
+ } catch (e) {
50
+ if (e instanceof Error) {
51
+ throw new Error("Error initializing GraphQL server: " + e.message);
52
+ } else {
53
+ throw e;
54
+ }
55
+ }
56
+ }
57
+ /**
58
+ * @hidden
59
+ * Handles HTTPS GraphQL requests.
60
+ * @param {GraphqlServerOptions} opts - Options for configuring the GraphQL server.
61
+ * @returns {HttpsFunction} A function you can export and deploy.
62
+ */
63
+ function onGraphRequest(opts) {
64
+ let serverPromise = null;
65
+ const handler = require_v2_trace.wrapTraceContext(require_common_onInit.withInit(require_common_providers_https.withErrorHandler(async (req, res) => {
66
+ serverPromise = serverPromise ?? initGraphqlServer(opts);
67
+ const app = await serverPromise;
68
+ app(req, res);
69
+ })));
70
+ const globalOpts = require_v2_options.getGlobalOptions();
71
+ const baseOpts = require_v2_options.optionsToEndpoint(globalOpts);
72
+ const specificOpts = require_v2_options.optionsToEndpoint(opts);
73
+ const endpoint = {
74
+ ...require_runtime_manifest.initV2Endpoint(globalOpts, opts),
75
+ platform: "gcfv2",
76
+ ...baseOpts,
77
+ ...specificOpts,
78
+ labels: {
79
+ ...baseOpts?.labels,
80
+ ...specificOpts?.labels
81
+ },
82
+ dataConnectGraphqlTrigger: {}
83
+ };
84
+ require_common_encoding.convertIfPresent(endpoint.dataConnectGraphqlTrigger, globalOpts, "invoker", "invoker", require_common_encoding.convertInvoker);
85
+ require_common_encoding.convertIfPresent(endpoint.dataConnectGraphqlTrigger, opts, "invoker", "invoker", require_common_encoding.convertInvoker);
86
+ if (opts.schemaFilePath) {
87
+ endpoint.dataConnectGraphqlTrigger.schemaFilePath = opts.schemaFilePath;
88
+ }
89
+ handler.__endpoint = endpoint;
90
+ return handler;
91
+ }
92
+
93
+ //#endregion
94
+ exports.initGraphqlServer = initGraphqlServer;
95
+ exports.onGraphRequest = onGraphRequest;
@@ -1,8 +1,8 @@
1
- import { CloudEvent, CloudFunction } from "../core";
2
- import { ParamsOf, VarName } from "../../common/params";
3
- import { EventHandlerOptions, SupportedRegion } from "../options";
4
- import { Expression } from "../../params";
5
- import { ResetValue } from "../../common/options";
1
+ import { CloudEvent, CloudFunction } from "../../core";
2
+ import { ParamsOf, VarName } from "../../../common/params";
3
+ import { EventHandlerOptions, SupportedRegion } from "../../options";
4
+ import { Expression } from "../../../params";
5
+ import { ResetValue } from "../../../common/options";
6
6
  /** @hidden */
7
7
  export interface SourceLocation {
8
8
  line: number;
@@ -1,12 +1,12 @@
1
- const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
2
- const require_runtime_manifest = require('../../runtime/manifest.js');
3
- const require_common_onInit = require('../../common/onInit.js');
4
- const require_common_utilities_path = require('../../common/utilities/path.js');
5
- const require_v2_trace = require('../trace.js');
6
- const require_v2_options = require('../options.js');
7
- const require_common_utilities_path_pattern = require('../../common/utilities/path-pattern.js');
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.js');
2
+ const require_runtime_manifest = require('../../../runtime/manifest.js');
3
+ const require_common_onInit = require('../../../common/onInit.js');
4
+ const require_common_utilities_path = require('../../../common/utilities/path.js');
5
+ const require_v2_trace = require('../../trace.js');
6
+ const require_v2_options = require('../../options.js');
7
+ const require_common_utilities_path_pattern = require('../../../common/utilities/path-pattern.js');
8
8
 
9
- //#region src/v2/providers/dataconnect.ts
9
+ //#region src/v2/providers/dataconnect/index.ts
10
10
  var dataconnect_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
11
11
  mutationExecutedEventType: () => mutationExecutedEventType,
12
12
  onMutationExecuted: () => onMutationExecuted
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "7.0.2",
3
+ "version": "7.0.4",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",
@@ -199,9 +199,14 @@
199
199
  "require": "./lib/v2/providers/firestore.js"
200
200
  },
201
201
  "./dataconnect": {
202
- "types": "./lib/v2/providers/dataconnect.d.ts",
203
- "import": "./lib/esm/v2/providers/dataconnect.mjs",
204
- "require": "./lib/v2/providers/dataconnect.js"
202
+ "types": "./lib/v2/providers/dataconnect/index.d.ts",
203
+ "import": "./lib/esm/v2/providers/dataconnect/index.mjs",
204
+ "require": "./lib/v2/providers/dataconnect/index.js"
205
+ },
206
+ "./dataconnect/graphql": {
207
+ "types": "./lib/v2/providers/dataconnect/graphql.d.ts",
208
+ "import": "./lib/esm/v2/providers/dataconnect/graphql.mjs",
209
+ "require": "./lib/v2/providers/dataconnect/graphql.js"
205
210
  },
206
211
  "./v2": {
207
212
  "types": "./lib/v2/index.d.ts",
@@ -299,9 +304,14 @@
299
304
  "require": "./lib/v2/providers/firestore.js"
300
305
  },
301
306
  "./v2/dataconnect": {
302
- "types": "./lib/v2/providers/dataconnect.d.ts",
303
- "import": "./lib/esm/v2/providers/dataconnect.mjs",
304
- "require": "./lib/v2/providers/dataconnect.js"
307
+ "types": "./lib/v2/providers/dataconnect/index.d.ts",
308
+ "import": "./lib/esm/v2/providers/dataconnect/index.mjs",
309
+ "require": "./lib/v2/providers/dataconnect/index.js"
310
+ },
311
+ "./v2/dataconnect/graphql": {
312
+ "types": "./lib/v2/providers/dataconnect/graphql.d.ts",
313
+ "import": "./lib/esm/v2/providers/dataconnect/graphql.mjs",
314
+ "require": "./lib/v2/providers/dataconnect/graphql.js"
305
315
  }
306
316
  },
307
317
  "typesVersions": {
@@ -403,7 +413,10 @@
403
413
  "lib/v2/providers/firestore"
404
414
  ],
405
415
  "dataconnect": [
406
- "lib/v2/providers/dataconnect"
416
+ "lib/v2/providers/dataconnect/index"
417
+ ],
418
+ "dataconnect/graphql": [
419
+ "lib/v2/providers/dataconnect/graphql"
407
420
  ],
408
421
  "v2": [
409
422
  "lib/v2/index"
@@ -466,7 +479,10 @@
466
479
  "lib/v2/providers/firestore"
467
480
  ],
468
481
  "v2/dataconnect": [
469
- "lib/v2/providers/dataconnect"
482
+ "lib/v2/providers/dataconnect/index"
483
+ ],
484
+ "v2/dataconnect/graphql": [
485
+ "lib/v2/providers/dataconnect/graphql"
470
486
  ],
471
487
  "*": [
472
488
  "lib/v2/index.d.ts"
@@ -508,6 +524,8 @@
508
524
  "protobufjs": "^7.2.2"
509
525
  },
510
526
  "devDependencies": {
527
+ "@apollo/server": "^5.2.0",
528
+ "@as-integrations/express4": "^1.1.2",
511
529
  "@eslint/eslintrc": "^3.3.1",
512
530
  "@firebase/api-documenter": "^0.2.0",
513
531
  "@microsoft/api-documenter": "^7.13.45",
@@ -534,6 +552,7 @@
534
552
  "eslint-plugin-prettier": "^4.2.1",
535
553
  "firebase-admin": "^13.0.0",
536
554
  "genkit": "^1.0.0-rc.4",
555
+ "graphql": "^16.12.0",
537
556
  "jsdom": "^16.2.1",
538
557
  "jsonwebtoken": "^9.0.0",
539
558
  "jwk-to-pem": "^2.0.5",
@@ -554,8 +573,22 @@
554
573
  "yargs": "^15.3.1"
555
574
  },
556
575
  "peerDependencies": {
576
+ "@apollo/server": "^5.2.0",
577
+ "@as-integrations/express4": "^1.1.2",
578
+ "graphql": "^16.12.0",
557
579
  "firebase-admin": "^11.10.0 || ^12.0.0 || ^13.0.0"
558
580
  },
581
+ "peerDependenciesMeta": {
582
+ "@apollo/server": {
583
+ "optional": true
584
+ },
585
+ "@as-integrations/express4": {
586
+ "optional": true
587
+ },
588
+ "graphql": {
589
+ "optional": true
590
+ }
591
+ },
559
592
  "engines": {
560
593
  "node": ">=18.0.0"
561
594
  }