firebase-functions 3.21.0 → 3.21.1

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 (49) hide show
  1. package/lib/bin/firebase-functions.js +21 -0
  2. package/lib/cloud-functions.d.ts +53 -40
  3. package/lib/common/encoding.js +21 -1
  4. package/lib/common/providers/https.d.ts +37 -17
  5. package/lib/common/providers/https.js +3 -0
  6. package/lib/common/providers/identity.d.ts +5 -1
  7. package/lib/common/providers/tasks.d.ts +9 -0
  8. package/lib/function-builder.d.ts +1 -1
  9. package/lib/logger/common.js +21 -0
  10. package/lib/logger/compat.js +21 -0
  11. package/lib/logger/index.d.ts +14 -6
  12. package/lib/logger/index.js +33 -6
  13. package/lib/providers/auth.d.ts +26 -5
  14. package/lib/providers/auth.js +18 -4
  15. package/lib/providers/pubsub.d.ts +6 -6
  16. package/lib/providers/pubsub.js +6 -6
  17. package/lib/providers/tasks.d.ts +29 -14
  18. package/lib/providers/tasks.js +10 -3
  19. package/lib/v2/core.d.ts +23 -1
  20. package/lib/v2/index.d.ts +9 -3
  21. package/lib/v2/index.js +8 -3
  22. package/lib/v2/options.d.ts +13 -34
  23. package/lib/v2/options.js +6 -58
  24. package/lib/v2/params/index.d.ts +4 -1
  25. package/lib/v2/params/index.js +25 -1
  26. package/lib/v2/params/types.js +21 -0
  27. package/lib/v2/providers/alerts/alerts.d.ts +94 -3
  28. package/lib/v2/providers/alerts/alerts.js +23 -7
  29. package/lib/v2/providers/alerts/appDistribution.d.ts +101 -1
  30. package/lib/v2/providers/alerts/appDistribution.js +28 -1
  31. package/lib/v2/providers/alerts/billing.d.ts +23 -2
  32. package/lib/v2/providers/alerts/billing.js +37 -0
  33. package/lib/v2/providers/alerts/crashlytics.d.ts +193 -18
  34. package/lib/v2/providers/alerts/crashlytics.js +62 -1
  35. package/lib/v2/providers/alerts/index.d.ts +6 -0
  36. package/lib/v2/providers/alerts/index.js +27 -0
  37. package/lib/v2/providers/eventarc.d.ts +89 -5
  38. package/lib/v2/providers/eventarc.js +4 -0
  39. package/lib/v2/providers/https.d.ts +123 -2
  40. package/lib/v2/providers/https.js +13 -3
  41. package/lib/v2/providers/identity.d.ts +108 -4
  42. package/lib/v2/providers/identity.js +33 -2
  43. package/lib/v2/providers/pubsub.d.ts +122 -5
  44. package/lib/v2/providers/pubsub.js +58 -2
  45. package/lib/v2/providers/storage.d.ts +192 -4
  46. package/lib/v2/providers/storage.js +52 -9
  47. package/lib/v2/providers/tasks.d.ts +106 -6
  48. package/lib/v2/providers/tasks.js +4 -0
  49. package/package.json +6 -4
@@ -1,6 +1,31 @@
1
1
  "use strict";
2
+ // The MIT License (MIT)
3
+ //
4
+ // Copyright (c) 2022 Firebase
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in all
14
+ // copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ // SOFTWARE.
2
23
  Object.defineProperty(exports, "__esModule", { value: true });
3
24
  exports.getOptsAndApp = exports.onOperation = exports.onNewAnrIssuePublished = exports.onVelocityAlertPublished = exports.onStabilityDigestPublished = exports.onRegressionAlertPublished = exports.onNewNonfatalIssuePublished = exports.onNewFatalIssuePublished = exports.newAnrIssueAlert = exports.velocityAlert = exports.stabilityDigestAlert = exports.regressionAlert = exports.newNonfatalIssueAlert = exports.newFatalIssueAlert = void 0;
25
+ /**
26
+ * Cloud functions to handle Crashlytics events from Firebase Alerts.
27
+ * @packageDocumentation
28
+ */
4
29
  const _1 = require(".");
5
30
  /** @internal */
6
31
  exports.newFatalIssueAlert = 'crashlytics.newFatalIssue';
@@ -14,26 +39,62 @@ exports.stabilityDigestAlert = 'crashlytics.stabilityDigest';
14
39
  exports.velocityAlert = 'crashlytics.velocity';
15
40
  /** @internal */
16
41
  exports.newAnrIssueAlert = 'crashlytics.newAnrIssue';
42
+ /**
43
+ * Declares a function that can handle a new fatal issue published to Crashlytics.
44
+ * @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
45
+ * @param handler - Event handler that is triggered when a new fatal issue is published to Crashlytics.
46
+ * @returns A function that you can export and deploy.
47
+ */
17
48
  function onNewFatalIssuePublished(appIdOrOptsOrHandler, handler) {
18
49
  return onOperation(exports.newFatalIssueAlert, appIdOrOptsOrHandler, handler);
19
50
  }
20
51
  exports.onNewFatalIssuePublished = onNewFatalIssuePublished;
52
+ /**
53
+ * Declares a function that can handle a new non-fatal issue published to Crashlytics.
54
+ * @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
55
+ * @param handler - Event handler that is triggered when a new non-fatal issue is published to Crashlytics.
56
+ * @returns A function that you can export and deploy.
57
+ */
21
58
  function onNewNonfatalIssuePublished(appIdOrOptsOrHandler, handler) {
22
59
  return onOperation(exports.newNonfatalIssueAlert, appIdOrOptsOrHandler, handler);
23
60
  }
24
61
  exports.onNewNonfatalIssuePublished = onNewNonfatalIssuePublished;
62
+ /**
63
+ * Declares a function that can handle a regression alert published to Crashlytics.
64
+ * @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
65
+ * @param handler - Event handler that is triggered when a regression alert is published to Crashlytics.
66
+ * @returns A function that you can export and deploy.
67
+ */
25
68
  function onRegressionAlertPublished(appIdOrOptsOrHandler, handler) {
26
69
  return onOperation(exports.regressionAlert, appIdOrOptsOrHandler, handler);
27
70
  }
28
71
  exports.onRegressionAlertPublished = onRegressionAlertPublished;
72
+ /**
73
+ * Declares a function that can handle a stability digest published to Crashlytics.
74
+ * @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
75
+ * @param handler - Event handler that is triggered when a stability digest is published to Crashlytics.
76
+ * @returns A function that you can export and deploy.
77
+ */
29
78
  function onStabilityDigestPublished(appIdOrOptsOrHandler, handler) {
30
79
  return onOperation(exports.stabilityDigestAlert, appIdOrOptsOrHandler, handler);
31
80
  }
32
81
  exports.onStabilityDigestPublished = onStabilityDigestPublished;
82
+ /**
83
+ * Declares a function that can handle a velocity alert published to Crashlytics.
84
+ * @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
85
+ * @param handler - Event handler that is triggered when a velocity alert is published to Crashlytics.
86
+ * @returns A function that you can export and deploy.
87
+ */
33
88
  function onVelocityAlertPublished(appIdOrOptsOrHandler, handler) {
34
89
  return onOperation(exports.velocityAlert, appIdOrOptsOrHandler, handler);
35
90
  }
36
91
  exports.onVelocityAlertPublished = onVelocityAlertPublished;
92
+ /**
93
+ * Declares a function that can handle a new Application Not Responding issue published to Crashlytics.
94
+ * @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
95
+ * @param handler - Event handler that is triggered when a new Application Not Responding issue is published to Crashlytics.
96
+ * @returns A function that you can export and deploy.
97
+ */
37
98
  function onNewAnrIssuePublished(appIdOrOptsOrHandler, handler) {
38
99
  return onOperation(exports.newAnrIssueAlert, appIdOrOptsOrHandler, handler);
39
100
  }
@@ -54,8 +115,8 @@ function onOperation(alertType, appIdOrOptsOrHandler, handler) {
54
115
  }
55
116
  exports.onOperation = onOperation;
56
117
  /**
57
- * @internal
58
118
  * Helper function to parse the function opts and appId.
119
+ * @internal
59
120
  */
60
121
  function getOptsAndApp(appIdOrOpts) {
61
122
  let opts;
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Cloud functions to handle events from Firebase Alerts.
3
+ * Subpackages give stronger typing to specific services which
4
+ * notify users via Firebase Alerts.
5
+ * @packageDocumentation
6
+ */
1
7
  import * as appDistribution from './appDistribution';
2
8
  import * as billing from './billing';
3
9
  import * as crashlytics from './crashlytics';
@@ -1,4 +1,25 @@
1
1
  "use strict";
2
+ // The MIT License (MIT)
3
+ //
4
+ // Copyright (c) 2022 Firebase
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in all
14
+ // copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ // SOFTWARE.
2
23
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
24
  if (k2 === undefined) k2 = k;
4
25
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -15,6 +36,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
36
  };
16
37
  Object.defineProperty(exports, "__esModule", { value: true });
17
38
  exports.crashlytics = exports.billing = exports.appDistribution = void 0;
39
+ /**
40
+ * Cloud functions to handle events from Firebase Alerts.
41
+ * Subpackages give stronger typing to specific services which
42
+ * notify users via Firebase Alerts.
43
+ * @packageDocumentation
44
+ */
18
45
  const appDistribution = require("./appDistribution");
19
46
  exports.appDistribution = appDistribution;
20
47
  const billing = require("./billing");
@@ -3,7 +3,7 @@ import * as options from '../options';
3
3
  /** Options that can be set on an Eventarc trigger. */
4
4
  export interface EventarcTriggerOptions extends options.EventHandlerOptions {
5
5
  /**
6
- * Type of the event.
6
+ * Type of the event to trigger on.
7
7
  */
8
8
  eventType: string;
9
9
  /**
@@ -25,8 +25,92 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions {
25
25
  * Eventarc event exact match filter.
26
26
  */
27
27
  filters?: Record<string, string>;
28
+ /**
29
+ * Region where functions should be deployed.
30
+ */
31
+ region?: options.SupportedRegion | string;
32
+ /**
33
+ * Amount of memory to allocate to a function.
34
+ * A value of null restores the defaults of 256MB.
35
+ */
36
+ memory?: options.MemoryOption | null;
37
+ /**
38
+ * Timeout for the function in sections, possible values are 0 to 540.
39
+ * HTTPS functions can specify a higher timeout.
40
+ * A value of null restores the default of 60s
41
+ * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
42
+ * function depends on the type of function: Event handling functions have a
43
+ * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
44
+ * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
45
+ * timeout of 1,800s (30 minutes)
46
+ */
47
+ timeoutSeconds?: number | null;
48
+ /**
49
+ * Min number of actual instances to be running at a given time.
50
+ * Instances will be billed for memory allocation and 10% of CPU allocation
51
+ * while idle.
52
+ * A value of null restores the default min instances.
53
+ */
54
+ minInstances?: number | null;
55
+ /**
56
+ * Max number of instances to be running in parallel.
57
+ * A value of null restores the default max instances.
58
+ */
59
+ maxInstances?: number | null;
60
+ /**
61
+ * Number of requests a function can serve at once.
62
+ * Can only be applied to functions running on Cloud Functions v2.
63
+ * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
64
+ * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
65
+ * The maximum value for concurrency is 1,000.
66
+ */
67
+ concurrency?: number | null;
68
+ /**
69
+ * Fractional number of CPUs to allocate to a function.
70
+ * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
71
+ * This is different from the defaults when using the gcloud utility and is different from
72
+ * the fixed amount assigned in Google Cloud Functions generation 1.
73
+ * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
74
+ * to the value "gcf_gen1"
75
+ */
76
+ cpu?: number | 'gcf_gen1';
77
+ /**
78
+ * Connect cloud function to specified VPC connector.
79
+ * A value of null removes the VPC connector
80
+ */
81
+ vpcConnector?: string | null;
82
+ /**
83
+ * Egress settings for VPC connector.
84
+ * A value of null turns off VPC connector egress settings
85
+ */
86
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
87
+ /**
88
+ * Specific service account for the function to run as.
89
+ * A value of null restores the default service account.
90
+ */
91
+ serviceAccount?: string | null;
92
+ /**
93
+ * Ingress settings which control where this function can be called from.
94
+ * A value of null turns off ingress settings.
95
+ */
96
+ ingressSettings?: options.IngressSetting | null;
97
+ /**
98
+ * User labels to set on the function.
99
+ */
100
+ labels?: Record<string, string>;
101
+ secrets?: string[];
102
+ /** Whether failed executions should be delivered again. */
103
+ retry?: boolean;
28
104
  }
29
- export declare type CloudEventHandler = (event: CloudEvent<any>) => any | Promise<any>;
30
- /** Handle an Eventarc event published on the default channel. */
31
- export declare function onCustomEventPublished<T = any>(eventType: string, handler: CloudEventHandler): CloudFunction<CloudEvent<T>>;
32
- export declare function onCustomEventPublished<T = any>(opts: EventarcTriggerOptions, handler: CloudEventHandler): CloudFunction<CloudEvent<T>>;
105
+ /** Handles an Eventarc event published on the default channel.
106
+ * @param eventType - Type of the event to trigger on.
107
+ * @param handler - A function to execute when triggered.
108
+ * @returns A function that you can export and deploy.
109
+ */
110
+ export declare function onCustomEventPublished<T = any>(eventType: string, handler: (event: CloudEvent<T>) => any | Promise<any>): CloudFunction<CloudEvent<T>>;
111
+ /** Handles an Eventarc event.
112
+ * @param opts - Options to set on this function
113
+ * @param handler - A function to execute when triggered.
114
+ * @returns A function that you can export and deploy.
115
+ */
116
+ export declare function onCustomEventPublished<T = any>(opts: EventarcTriggerOptions, handler: (event: CloudEvent<T>) => any | Promise<any>): CloudFunction<CloudEvent<T>>;
@@ -22,6 +22,10 @@
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.onCustomEventPublished = void 0;
25
+ /**
26
+ * Cloud functions to integrate directly with Eventarc.
27
+ * @packageDocumentation
28
+ */
25
29
  const encoding_1 = require("../../common/encoding");
26
30
  const options = require("../options");
27
31
  function onCustomEventPublished(eventTypeOrOpts, handler) {
@@ -1,23 +1,144 @@
1
1
  import * as express from 'express';
2
2
  import { CallableRequest, FunctionsErrorCode, HttpsError, Request } from '../../common/providers/https';
3
3
  import { ManifestEndpoint } from '../../runtime/manifest';
4
+ import * as options from '../options';
4
5
  import { GlobalOptions, SupportedRegion } from '../options';
5
6
  export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
6
7
  /**
7
- * Options that can be set on an individual HTTPS Cloud Function.
8
+ * Options that can be set on an individual HTTPS function.
8
9
  */
9
10
  export interface HttpsOptions extends Omit<GlobalOptions, 'region'> {
11
+ /** HTTP functions can override global options and can specify multiple regions to deploy to. */
10
12
  region?: SupportedRegion | string | Array<SupportedRegion | string>;
13
+ /** If true, allows CORS on requests to this function.
14
+ * If this is a `string` or `RegExp`, allows requests from domains that match the provided value.
15
+ * If this is an `Array`, allows requests from domains matching at least one entry of the array.
16
+ * Defaults to true for {@link https.CallableFunction} and false otherwise.
17
+ */
11
18
  cors?: string | boolean | RegExp | Array<string | RegExp>;
19
+ /**
20
+ * Amount of memory to allocate to a function.
21
+ * A value of null restores the defaults of 256MB.
22
+ */
23
+ memory?: options.MemoryOption | null;
24
+ /**
25
+ * Timeout for the function in sections, possible values are 0 to 540.
26
+ * HTTPS functions can specify a higher timeout.
27
+ * A value of null restores the default of 60s
28
+ * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
29
+ * function depends on the type of function: Event handling functions have a
30
+ * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
31
+ * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
32
+ * timeout of 1,800s (30 minutes)
33
+ */
34
+ timeoutSeconds?: number | null;
35
+ /**
36
+ * Min number of actual instances to be running at a given time.
37
+ * Instances will be billed for memory allocation and 10% of CPU allocation
38
+ * while idle.
39
+ * A value of null restores the default min instances.
40
+ */
41
+ minInstances?: number | null;
42
+ /**
43
+ * Max number of instances to be running in parallel.
44
+ * A value of null restores the default max instances.
45
+ */
46
+ maxInstances?: number | null;
47
+ /**
48
+ * Number of requests a function can serve at once.
49
+ * Can only be applied to functions running on Cloud Functions v2.
50
+ * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
51
+ * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
52
+ * The maximum value for concurrency is 1,000.
53
+ */
54
+ concurrency?: number | null;
55
+ /**
56
+ * Fractional number of CPUs to allocate to a function.
57
+ * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
58
+ * This is different from the defaults when using the gcloud utility and is different from
59
+ * the fixed amount assigned in Google Cloud Functions generation 1.
60
+ * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
61
+ * to the value "gcf_gen1"
62
+ */
63
+ cpu?: number | 'gcf_gen1';
64
+ /**
65
+ * Connect cloud function to specified VPC connector.
66
+ * A value of null removes the VPC connector
67
+ */
68
+ vpcConnector?: string | null;
69
+ /**
70
+ * Egress settings for VPC connector.
71
+ * A value of null turns off VPC connector egress settings
72
+ */
73
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
74
+ /**
75
+ * Specific service account for the function to run as.
76
+ * A value of null restores the default service account.
77
+ */
78
+ serviceAccount?: string | null;
79
+ /**
80
+ * Ingress settings which control where this function can be called from.
81
+ * A value of null turns off ingress settings.
82
+ */
83
+ ingressSettings?: options.IngressSetting | null;
84
+ /**
85
+ * User labels to set on the function.
86
+ */
87
+ labels?: Record<string, string>;
88
+ /**
89
+ * Invoker to set access control on https functions.
90
+ */
91
+ invoker?: 'public' | 'private' | string | string[];
92
+ secrets?: string[];
93
+ /** Whether failed executions should be delivered again. */
94
+ retry?: boolean;
12
95
  }
13
- export declare type HttpsFunction = ((req: Request, res: express.Response) => void | Promise<void>) & {
96
+ /**
97
+ * Handles HTTPS requests.
98
+ */
99
+ export declare type HttpsFunction = ((
100
+ /** An Express request object representing the HTTPS call to the function. */
101
+ req: Request,
102
+ /** An Express response object, for this function to respond to callers. */
103
+ res: express.Response) => void | Promise<void>) & {
104
+ /** @alpha */
14
105
  __trigger?: unknown;
106
+ /** @alpha */
15
107
  __endpoint: ManifestEndpoint;
16
108
  };
109
+ /**
110
+ * Creates a callable method for clients to call using a Firebase SDK.
111
+ */
17
112
  export interface CallableFunction<T, Return> extends HttpsFunction {
113
+ /** Executes the handler function with the provided data as input. Used for unit testing.
114
+ * @param data - An input for the handler function.
115
+ * @returns The output of the handler function.
116
+ */
18
117
  run(data: CallableRequest<T>): Return;
19
118
  }
119
+ /**
120
+ * Handles HTTPS requests.
121
+ * @param opts - Options to set on this function
122
+ * @param handler - A function that takes a {@link https.Request} and response object, same signature as an Express app.
123
+ * @returns A function that you can export and deploy.
124
+ */
20
125
  export declare function onRequest(opts: HttpsOptions, handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
126
+ /**
127
+ * Handles HTTPS requests.
128
+ * @param handler - A function that takes a {@link https.Request} and response object, same signature as an Express app.
129
+ * @returns A function that you can export and deploy.
130
+ */
21
131
  export declare function onRequest(handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
132
+ /**
133
+ * Declares a callable method for clients to call using a Firebase SDK.
134
+ * @param opts - Options to set on this function.
135
+ * @param handler - A function that takes a {@link https.CallableRequest}.
136
+ * @returns A function that you can export and deploy.
137
+ */
22
138
  export declare function onCall<T = any, Return = any | Promise<any>>(opts: HttpsOptions, handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
139
+ /**
140
+ * Declares a callable method for clients to call using a Firebase SDK.
141
+ * @param handler - A function that takes a {@link https.CallableRequest}.
142
+ * @returns A function that you can export and deploy.
143
+ */
23
144
  export declare function onCall<T = any, Return = any | Promise<any>>(handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
@@ -22,8 +22,13 @@
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.onCall = exports.onRequest = exports.HttpsError = void 0;
25
+ /**
26
+ * Cloud functions to handle HTTPS request or callable RPCs.
27
+ * @packageDocumentation
28
+ */
25
29
  const cors = require("cors");
26
30
  const encoding_1 = require("../../common/encoding");
31
+ const debug_1 = require("../../common/debug");
27
32
  const https_1 = require("../../common/providers/https");
28
33
  Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
29
34
  const options = require("../options");
@@ -36,12 +41,13 @@ function onRequest(optsOrHandler, handler) {
36
41
  else {
37
42
  opts = optsOrHandler;
38
43
  }
39
- if ('cors' in opts) {
44
+ if ((0, debug_1.isDebugFeatureEnabled)('enableCors') || 'cors' in opts) {
45
+ const origin = (0, debug_1.isDebugFeatureEnabled)('enableCors') ? true : opts.cors;
40
46
  const userProvidedHandler = handler;
41
47
  handler = (req, res) => {
42
48
  return new Promise((resolve) => {
43
49
  res.on('finish', resolve);
44
- cors({ origin: opts.cors })(req, res, () => {
50
+ cors({ origin })(req, res, () => {
45
51
  resolve(userProvidedHandler(req, res));
46
52
  });
47
53
  });
@@ -97,7 +103,11 @@ function onCall(optsOrHandler, handler) {
97
103
  else {
98
104
  opts = optsOrHandler;
99
105
  }
100
- const origin = 'cors' in opts ? opts.cors : true;
106
+ const origin = (0, debug_1.isDebugFeatureEnabled)('enableCors')
107
+ ? true
108
+ : 'cors' in opts
109
+ ? opts.cors
110
+ : true;
101
111
  // onCallHandler sniffs the function length to determine which API to present.
102
112
  // fix the length to prevent api versions from being mismatched.
103
113
  const fixedLen = (req) => handler(req);
@@ -1,22 +1,126 @@
1
+ /**
2
+ * Cloud functions to handle events from Google Cloud Identity Platform.
3
+ * @packageDocumentation
4
+ */
1
5
  import { BlockingFunction } from '../../cloud-functions';
2
- import { AuthBlockingEvent, BeforeCreateResponse, BeforeSignInResponse, HttpsError } from '../../common/providers/identity';
6
+ import { AuthBlockingEvent, AuthBlockingEventType, BeforeCreateResponse, BeforeSignInResponse, HttpsError } from '../../common/providers/identity';
3
7
  import * as options from '../options';
4
8
  export { HttpsError };
9
+ /** @hidden Internally used when parsing the options. */
10
+ interface InternalOptions {
11
+ opts: options.GlobalOptions;
12
+ idToken: boolean;
13
+ accessToken: boolean;
14
+ refreshToken: boolean;
15
+ }
5
16
  /**
6
17
  * All function options plus idToken, accessToken, and refreshToken.
7
18
  */
8
- export interface BlockingOptions extends options.GlobalOptions {
19
+ export interface BlockingOptions {
20
+ /** Pass the ID Token credential to the function. */
9
21
  idToken?: boolean;
22
+ /** Pass the Access Token credential to the function. */
10
23
  accessToken?: boolean;
24
+ /** Pass the Refresh Token credential to the function. */
11
25
  refreshToken?: boolean;
26
+ /**
27
+ * Region where functions should be deployed.
28
+ */
29
+ region?: options.SupportedRegion | string;
30
+ /**
31
+ * Amount of memory to allocate to a function.
32
+ * A value of null restores the defaults of 256MB.
33
+ */
34
+ memory?: options.MemoryOption | null;
35
+ /**
36
+ * Timeout for the function in sections, possible values are 0 to 540.
37
+ * HTTPS functions can specify a higher timeout.
38
+ * A value of null restores the default of 60s
39
+ * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
40
+ * function depends on the type of function: Event handling functions have a
41
+ * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
42
+ * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
43
+ * timeout of 1,800s (30 minutes)
44
+ */
45
+ timeoutSeconds?: number | null;
46
+ /**
47
+ * Min number of actual instances to be running at a given time.
48
+ * Instances will be billed for memory allocation and 10% of CPU allocation
49
+ * while idle.
50
+ * A value of null restores the default min instances.
51
+ */
52
+ minInstances?: number | null;
53
+ /**
54
+ * Max number of instances to be running in parallel.
55
+ * A value of null restores the default max instances.
56
+ */
57
+ maxInstances?: number | null;
58
+ /**
59
+ * Number of requests a function can serve at once.
60
+ * Can only be applied to functions running on Cloud Functions v2.
61
+ * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
62
+ * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
63
+ * The maximum value for concurrency is 1,000.
64
+ */
65
+ concurrency?: number | null;
66
+ /**
67
+ * Fractional number of CPUs to allocate to a function.
68
+ * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
69
+ * This is different from the defaults when using the gcloud utility and is different from
70
+ * the fixed amount assigned in Google Cloud Functions generation 1.
71
+ * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
72
+ * to the value "gcf_gen1"
73
+ */
74
+ cpu?: number | 'gcf_gen1';
75
+ /**
76
+ * Connect cloud function to specified VPC connector.
77
+ * A value of null removes the VPC connector
78
+ */
79
+ vpcConnector?: string | null;
80
+ /**
81
+ * Egress settings for VPC connector.
82
+ * A value of null turns off VPC connector egress settings
83
+ */
84
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
85
+ /**
86
+ * Specific service account for the function to run as.
87
+ * A value of null restores the default service account.
88
+ */
89
+ serviceAccount?: string | null;
90
+ /**
91
+ * Ingress settings which control where this function can be called from.
92
+ * A value of null turns off ingress settings.
93
+ */
94
+ ingressSettings?: options.IngressSetting | null;
95
+ /**
96
+ * User labels to set on the function.
97
+ */
98
+ labels?: Record<string, string>;
99
+ secrets?: string[];
12
100
  }
13
101
  /**
14
- * Handle an event that is triggered before a user is created.
102
+ * Handles an event that is triggered before a user is created.
103
+ * @param handler - Event handler which is run every time before a user is created
15
104
  */
16
105
  export declare function beforeUserCreated(handler: (event: AuthBlockingEvent) => BeforeCreateResponse | Promise<BeforeCreateResponse> | void | Promise<void>): BlockingFunction;
106
+ /**
107
+ * Handles an event that is triggered before a user is created.
108
+ * @param opts - Object containing function options
109
+ * @param handler - Event handler which is run every time before a user is created
110
+ */
17
111
  export declare function beforeUserCreated(opts: BlockingOptions, handler: (event: AuthBlockingEvent) => BeforeCreateResponse | Promise<BeforeCreateResponse> | void | Promise<void>): BlockingFunction;
18
112
  /**
19
- * Handle an event that is triggered before a user is signed in.
113
+ * Handles an event that is triggered before a user is signed in.
114
+ * @param handler - Event handler which is run every time before a user is signed in
20
115
  */
21
116
  export declare function beforeUserSignedIn(handler: (event: AuthBlockingEvent) => BeforeSignInResponse | Promise<BeforeSignInResponse> | void | Promise<void>): BlockingFunction;
117
+ /**
118
+ * Handles an event that is triggered before a user is signed in.
119
+ * @param opts - Object containing function options
120
+ * @param handler - Event handler which is run every time before a user is signed in
121
+ */
22
122
  export declare function beforeUserSignedIn(opts: BlockingOptions, handler: (event: AuthBlockingEvent) => BeforeSignInResponse | Promise<BeforeSignInResponse> | void | Promise<void>): BlockingFunction;
123
+ /** @hidden */
124
+ export declare function beforeOperation(eventType: AuthBlockingEventType, optsOrHandler: BlockingOptions | ((event: AuthBlockingEvent) => BeforeCreateResponse | BeforeSignInResponse | void | Promise<BeforeCreateResponse> | Promise<BeforeSignInResponse> | Promise<void>), handler: (event: AuthBlockingEvent) => BeforeCreateResponse | BeforeSignInResponse | void | Promise<BeforeCreateResponse> | Promise<BeforeSignInResponse> | Promise<void>): BlockingFunction;
125
+ /** @hidden */
126
+ export declare function getOpts(blockingOptions: BlockingOptions): InternalOptions;
@@ -1,18 +1,49 @@
1
1
  "use strict";
2
+ // The MIT License (MIT)
3
+ //
4
+ // Copyright (c) 2022 Firebase
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in all
14
+ // copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ // SOFTWARE.
2
23
  Object.defineProperty(exports, "__esModule", { value: true });
3
24
  exports.getOpts = exports.beforeOperation = exports.beforeUserSignedIn = exports.beforeUserCreated = exports.HttpsError = void 0;
4
25
  const identity_1 = require("../../common/providers/identity");
5
26
  Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return identity_1.HttpsError; } });
6
27
  const options = require("../options");
28
+ /**
29
+ * Handles an event that is triggered before a user is created
30
+ * @param optsOrHandler - Either an object containing function options, or an event handler (run before user creation)
31
+ * @param handler? - If defined, an event handler which is run every time before a user is created
32
+ */
7
33
  function beforeUserCreated(optsOrHandler, handler) {
8
34
  return beforeOperation('beforeCreate', optsOrHandler, handler);
9
35
  }
10
36
  exports.beforeUserCreated = beforeUserCreated;
37
+ /**
38
+ * Handles an event that is triggered before a user is signed in.
39
+ * @param optsOrHandler - Either an object containing function options, or an event handler (run before user signin)
40
+ * @param handler - Event handler which is run every time before a user is signed in
41
+ */
11
42
  function beforeUserSignedIn(optsOrHandler, handler) {
12
43
  return beforeOperation('beforeSignIn', optsOrHandler, handler);
13
44
  }
14
45
  exports.beforeUserSignedIn = beforeUserSignedIn;
15
- /** @internal */
46
+ /** @hidden */
16
47
  function beforeOperation(eventType, optsOrHandler, handler) {
17
48
  if (!handler || typeof optsOrHandler === 'function') {
18
49
  handler = optsOrHandler;
@@ -54,7 +85,7 @@ function beforeOperation(eventType, optsOrHandler, handler) {
54
85
  return func;
55
86
  }
56
87
  exports.beforeOperation = beforeOperation;
57
- /** @internal */
88
+ /** @hidden */
58
89
  function getOpts(blockingOptions) {
59
90
  const accessToken = blockingOptions.accessToken || false;
60
91
  const idToken = blockingOptions.idToken || false;