firebase-functions 3.20.1 → 3.21.2

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 (65) hide show
  1. package/lib/apps.js +1 -1
  2. package/lib/bin/firebase-functions.js +22 -1
  3. package/lib/cloud-functions.d.ts +56 -35
  4. package/lib/cloud-functions.js +12 -12
  5. package/lib/common/encoding.js +21 -1
  6. package/lib/common/providers/https.d.ts +37 -17
  7. package/lib/common/providers/https.js +11 -6
  8. package/lib/common/providers/identity.d.ts +11 -1
  9. package/lib/common/providers/identity.js +59 -207
  10. package/lib/common/providers/tasks.d.ts +9 -0
  11. package/lib/function-builder.d.ts +2 -2
  12. package/lib/function-builder.js +1 -1
  13. package/lib/handler-builder.js +3 -3
  14. package/lib/index.js +6 -2
  15. package/lib/logger/common.js +21 -0
  16. package/lib/logger/compat.js +22 -1
  17. package/lib/logger/index.d.ts +14 -6
  18. package/lib/logger/index.js +33 -6
  19. package/lib/providers/analytics.js +1 -1
  20. package/lib/providers/auth.d.ts +44 -10
  21. package/lib/providers/auth.js +80 -14
  22. package/lib/providers/database.js +11 -11
  23. package/lib/providers/firestore.js +7 -7
  24. package/lib/providers/https.js +7 -7
  25. package/lib/providers/pubsub.d.ts +6 -6
  26. package/lib/providers/pubsub.js +8 -8
  27. package/lib/providers/remoteConfig.js +1 -1
  28. package/lib/providers/storage.js +2 -2
  29. package/lib/providers/tasks.d.ts +30 -15
  30. package/lib/providers/tasks.js +19 -12
  31. package/lib/providers/testLab.js +1 -1
  32. package/lib/runtime/loader.js +9 -7
  33. package/lib/runtime/manifest.d.ts +5 -0
  34. package/lib/setup.js +3 -3
  35. package/lib/v2/core.d.ts +24 -20
  36. package/lib/v2/index.d.ts +11 -4
  37. package/lib/v2/index.js +12 -5
  38. package/lib/v2/options.d.ts +25 -35
  39. package/lib/v2/options.js +28 -88
  40. package/lib/v2/params/index.d.ts +4 -1
  41. package/lib/v2/params/index.js +25 -1
  42. package/lib/v2/params/types.js +21 -0
  43. package/lib/v2/providers/alerts/alerts.d.ts +107 -8
  44. package/lib/v2/providers/alerts/alerts.js +23 -7
  45. package/lib/v2/providers/alerts/appDistribution.d.ts +112 -12
  46. package/lib/v2/providers/alerts/appDistribution.js +29 -2
  47. package/lib/v2/providers/alerts/billing.d.ts +39 -12
  48. package/lib/v2/providers/alerts/billing.js +38 -1
  49. package/lib/v2/providers/alerts/crashlytics.d.ts +255 -47
  50. package/lib/v2/providers/alerts/crashlytics.js +63 -2
  51. package/lib/v2/providers/alerts/index.d.ts +6 -0
  52. package/lib/v2/providers/alerts/index.js +32 -1
  53. package/lib/v2/providers/eventarc.d.ts +90 -6
  54. package/lib/v2/providers/eventarc.js +7 -3
  55. package/lib/v2/providers/https.d.ts +128 -4
  56. package/lib/v2/providers/https.js +18 -14
  57. package/lib/v2/providers/identity.d.ts +126 -0
  58. package/lib/v2/providers/identity.js +104 -0
  59. package/lib/v2/providers/pubsub.d.ts +125 -8
  60. package/lib/v2/providers/pubsub.js +60 -7
  61. package/lib/v2/providers/storage.d.ts +209 -17
  62. package/lib/v2/providers/storage.js +57 -13
  63. package/lib/v2/providers/tasks.d.ts +107 -7
  64. package/lib/v2/providers/tasks.js +11 -8
  65. package/package.json +18 -3
@@ -22,8 +22,12 @@
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.onCustomEventPublished = void 0;
25
- const options = require("../options");
25
+ /**
26
+ * Cloud functions to integrate directly with Eventarc.
27
+ * @packageDocumentation
28
+ */
26
29
  const encoding_1 = require("../../common/encoding");
30
+ const options = require("../options");
27
31
  function onCustomEventPublished(eventTypeOrOpts, handler) {
28
32
  var _a;
29
33
  let opts;
@@ -57,8 +61,8 @@ function onCustomEventPublished(eventTypeOrOpts, handler) {
57
61
  channel,
58
62
  },
59
63
  };
60
- encoding_1.convertIfPresent(endpoint.eventTrigger, opts, 'eventFilters', 'filters');
61
- encoding_1.copyIfPresent(endpoint.eventTrigger, opts, 'retry');
64
+ (0, encoding_1.convertIfPresent)(endpoint.eventTrigger, opts, 'eventFilters', 'filters');
65
+ (0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, 'retry');
62
66
  func.__endpoint = endpoint;
63
67
  return func;
64
68
  }
@@ -1,20 +1,144 @@
1
1
  import * as express from 'express';
2
- import * as options from '../options';
3
2
  import { CallableRequest, FunctionsErrorCode, HttpsError, Request } from '../../common/providers/https';
4
3
  import { ManifestEndpoint } from '../../runtime/manifest';
4
+ import * as options from '../options';
5
+ import { GlobalOptions, SupportedRegion } from '../options';
5
6
  export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
6
- export interface HttpsOptions extends Omit<options.GlobalOptions, 'region'> {
7
- region?: options.SupportedRegion | string | Array<options.SupportedRegion | string>;
7
+ /**
8
+ * Options that can be set on an individual HTTPS function.
9
+ */
10
+ export interface HttpsOptions extends Omit<GlobalOptions, 'region'> {
11
+ /** HTTP functions can override global options and can specify multiple regions to deploy to. */
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
+ */
8
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;
9
95
  }
10
- 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 */
11
105
  __trigger?: unknown;
106
+ /** @alpha */
12
107
  __endpoint: ManifestEndpoint;
13
108
  };
109
+ /**
110
+ * Creates a callable method for clients to call using a Firebase SDK.
111
+ */
14
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
+ */
15
117
  run(data: CallableRequest<T>): Return;
16
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
+ */
17
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
+ */
18
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
+ */
19
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
+ */
20
144
  export declare function onCall<T = any, Return = any | Promise<any>>(handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
@@ -22,11 +22,16 @@
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");
27
- const options = require("../options");
31
+ const debug_1 = require("../../common/debug");
28
32
  const https_1 = require("../../common/providers/https");
29
33
  Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
34
+ const options = require("../options");
30
35
  function onRequest(optsOrHandler, handler) {
31
36
  let opts;
32
37
  if (arguments.length === 1) {
@@ -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
  });
@@ -54,9 +60,6 @@ function onRequest(optsOrHandler, handler) {
54
60
  // but optionsToTriggerAnnotations handles both cases.
55
61
  const specificOpts = options.optionsToTriggerAnnotations(opts);
56
62
  const trigger = {
57
- // TODO(inlined): Remove "apiVersion" once the latest version of the CLI
58
- // has migrated to "platform".
59
- apiVersion: 2,
60
63
  platform: 'gcfv2',
61
64
  ...baseOpts,
62
65
  ...specificOpts,
@@ -68,7 +71,7 @@ function onRequest(optsOrHandler, handler) {
68
71
  allowInsecure: false,
69
72
  },
70
73
  };
71
- encoding_1.convertIfPresent(trigger.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
74
+ (0, encoding_1.convertIfPresent)(trigger.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
72
75
  return trigger;
73
76
  },
74
77
  });
@@ -86,7 +89,7 @@ function onRequest(optsOrHandler, handler) {
86
89
  },
87
90
  httpsTrigger: {},
88
91
  };
89
- encoding_1.convertIfPresent(endpoint.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
92
+ (0, encoding_1.convertIfPresent)(endpoint.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
90
93
  handler.__endpoint = endpoint;
91
94
  return handler;
92
95
  }
@@ -100,11 +103,15 @@ function onCall(optsOrHandler, handler) {
100
103
  else {
101
104
  opts = optsOrHandler;
102
105
  }
103
- 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;
104
111
  // onCallHandler sniffs the function length to determine which API to present.
105
112
  // fix the length to prevent api versions from being mismatched.
106
113
  const fixedLen = (req) => handler(req);
107
- const func = https_1.onCallHandler({ cors: { origin, methods: 'POST' } }, fixedLen);
114
+ const func = (0, https_1.onCallHandler)({ cors: { origin, methods: 'POST' } }, fixedLen);
108
115
  Object.defineProperty(func, '__trigger', {
109
116
  get: () => {
110
117
  const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
@@ -112,9 +119,6 @@ function onCall(optsOrHandler, handler) {
112
119
  // but optionsToTriggerAnnotations handles both cases.
113
120
  const specificOpts = options.optionsToTriggerAnnotations(opts);
114
121
  return {
115
- // TODO(inlined): Remove "apiVersion" once the latest version of the CLI
116
- // has migrated to "platform".
117
- apiVersion: 2,
118
122
  platform: 'gcfv2',
119
123
  ...baseOpts,
120
124
  ...specificOpts,
@@ -131,7 +135,7 @@ function onCall(optsOrHandler, handler) {
131
135
  });
132
136
  const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
133
137
  // global options calls region a scalar and https allows it to be an array,
134
- // but optionsToManifestEndpoint handles both cases.
138
+ // but optionsToEndpoint handles both cases.
135
139
  const specificOpts = options.optionsToEndpoint(opts);
136
140
  func.__endpoint = {
137
141
  platform: 'gcfv2',
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Cloud functions to handle events from Google Cloud Identity Platform.
3
+ * @packageDocumentation
4
+ */
5
+ import { BlockingFunction } from '../../cloud-functions';
6
+ import { AuthBlockingEvent, AuthBlockingEventType, BeforeCreateResponse, BeforeSignInResponse, HttpsError } from '../../common/providers/identity';
7
+ import * as options from '../options';
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
+ }
16
+ /**
17
+ * All function options plus idToken, accessToken, and refreshToken.
18
+ */
19
+ export interface BlockingOptions {
20
+ /** Pass the ID Token credential to the function. */
21
+ idToken?: boolean;
22
+ /** Pass the Access Token credential to the function. */
23
+ accessToken?: boolean;
24
+ /** Pass the Refresh Token credential to the function. */
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[];
100
+ }
101
+ /**
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
104
+ */
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
+ */
111
+ export declare function beforeUserCreated(opts: BlockingOptions, handler: (event: AuthBlockingEvent) => BeforeCreateResponse | Promise<BeforeCreateResponse> | void | Promise<void>): BlockingFunction;
112
+ /**
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
115
+ */
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
+ */
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;
@@ -0,0 +1,104 @@
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.
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.getOpts = exports.beforeOperation = exports.beforeUserSignedIn = exports.beforeUserCreated = exports.HttpsError = void 0;
25
+ const identity_1 = require("../../common/providers/identity");
26
+ Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return identity_1.HttpsError; } });
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
+ */
33
+ function beforeUserCreated(optsOrHandler, handler) {
34
+ return beforeOperation('beforeCreate', optsOrHandler, handler);
35
+ }
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
+ */
42
+ function beforeUserSignedIn(optsOrHandler, handler) {
43
+ return beforeOperation('beforeSignIn', optsOrHandler, handler);
44
+ }
45
+ exports.beforeUserSignedIn = beforeUserSignedIn;
46
+ /** @hidden */
47
+ function beforeOperation(eventType, optsOrHandler, handler) {
48
+ if (!handler || typeof optsOrHandler === 'function') {
49
+ handler = optsOrHandler;
50
+ optsOrHandler = {};
51
+ }
52
+ const { opts, accessToken, idToken, refreshToken } = getOpts(optsOrHandler);
53
+ // Create our own function that just calls the provided function so we know for sure that
54
+ // handler takes one argument. This is something common/providers/identity depends on.
55
+ const wrappedHandler = (event) => handler(event);
56
+ const func = (0, identity_1.wrapHandler)(eventType, wrappedHandler);
57
+ const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
58
+ /** Endpoint */
59
+ const baseOptsEndpoint = options.optionsToEndpoint(options.getGlobalOptions());
60
+ const specificOptsEndpoint = options.optionsToEndpoint(opts);
61
+ func.__endpoint = {
62
+ platform: 'gcfv2',
63
+ ...baseOptsEndpoint,
64
+ ...specificOptsEndpoint,
65
+ labels: {
66
+ ...baseOptsEndpoint === null || baseOptsEndpoint === void 0 ? void 0 : baseOptsEndpoint.labels,
67
+ ...specificOptsEndpoint === null || specificOptsEndpoint === void 0 ? void 0 : specificOptsEndpoint.labels,
68
+ },
69
+ blockingTrigger: {
70
+ eventType: legacyEventType,
71
+ options: {
72
+ accessToken,
73
+ idToken,
74
+ refreshToken,
75
+ },
76
+ },
77
+ };
78
+ func.__requiredAPIs = [
79
+ {
80
+ api: 'identitytoolkit.googleapis.com',
81
+ reason: 'Needed for auth blocking functions',
82
+ },
83
+ ];
84
+ func.run = handler;
85
+ return func;
86
+ }
87
+ exports.beforeOperation = beforeOperation;
88
+ /** @hidden */
89
+ function getOpts(blockingOptions) {
90
+ const accessToken = blockingOptions.accessToken || false;
91
+ const idToken = blockingOptions.idToken || false;
92
+ const refreshToken = blockingOptions.refreshToken || false;
93
+ const opts = { ...blockingOptions };
94
+ delete opts.accessToken;
95
+ delete opts.idToken;
96
+ delete opts.refreshToken;
97
+ return {
98
+ opts,
99
+ accessToken,
100
+ idToken,
101
+ refreshToken,
102
+ };
103
+ }
104
+ exports.getOpts = getOpts;
@@ -1,9 +1,30 @@
1
- import * as options from '../options';
2
1
  import { CloudEvent, CloudFunction } from '../core';
2
+ import * as options from '../options';
3
+ /**
4
+ * Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
5
+ * You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
6
+ *
7
+ * This function triggers whenever a new pub/sub message is sent to a specific topic.
8
+ * You must specify the Pub/Sub topic name that you want to trigger your function, and set the event within the
9
+ * onPublish() event handler.
10
+ *
11
+ * PubSub Topic:
12
+ * <ul>
13
+ * <li>A resource that you can publish messages to and then consume those messages via subscriptions.
14
+ * <li>An isolated data stream for pub/sub messages.
15
+ * <li>Messages are published to a topic.
16
+ * <li>Messages are listened to via a subscription.
17
+ * <li>Each subscription listens to the messages published to exactly one topic.
18
+ *
19
+ * Subscriptions - Resource that listens to the messages published by exactly one topic.
20
+ *
21
+ * [More info here](https://firebase.google.com/docs/functions/pubsub-events)
22
+ */
3
23
  /**
4
24
  * Interface representing a Google Cloud Pub/Sub message.
5
25
  *
6
- * @param data Payload of a Pub/Sub message.
26
+ * @param data - Payload of a Pub/Sub message.
27
+ * @typeParam T - Type representing `Message.data`'s JSON format
7
28
  */
8
29
  export declare class Message<T> {
9
30
  /**
@@ -30,6 +51,10 @@ export declare class Message<T> {
30
51
  readonly orderingKey: string;
31
52
  /** @hidden */
32
53
  private _json;
54
+ /**
55
+ * @hidden
56
+ * @alpha
57
+ */
33
58
  constructor(data: any);
34
59
  /**
35
60
  * The JSON data payload of this message object, if any.
@@ -38,20 +63,112 @@ export declare class Message<T> {
38
63
  /**
39
64
  * Returns a JSON-serializable representation of this object.
40
65
  *
41
- * @return A JSON-serializable representation of this object.
66
+ * @returns A JSON-serializable representation of this object.
42
67
  */
43
68
  toJSON(): any;
44
69
  }
45
- /** The interface published in a Pub/Sub publish subscription. */
70
+ /**
71
+ * The interface published in a Pub/Sub publish subscription.
72
+ * @typeParam T - Type representing `Message.data`'s JSON format
73
+ */
46
74
  export interface MessagePublishedData<T = any> {
75
+ /** Google Cloud Pub/Sub message. */
47
76
  readonly message: Message<T>;
77
+ /** A subscription resource. */
48
78
  readonly subscription: string;
49
79
  }
50
80
  /** PubSubOptions extend EventHandlerOptions but must include a topic. */
51
81
  export interface PubSubOptions extends options.EventHandlerOptions {
82
+ /** The Pub/Sub topic to watch for message events */
52
83
  topic: string;
84
+ /**
85
+ * Region where functions should be deployed.
86
+ */
87
+ region?: options.SupportedRegion | string;
88
+ /**
89
+ * Amount of memory to allocate to a function.
90
+ * A value of null restores the defaults of 256MB.
91
+ */
92
+ memory?: options.MemoryOption | null;
93
+ /**
94
+ * Timeout for the function in sections, possible values are 0 to 540.
95
+ * HTTPS functions can specify a higher timeout.
96
+ * A value of null restores the default of 60s
97
+ * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
98
+ * function depends on the type of function: Event handling functions have a
99
+ * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
100
+ * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
101
+ * timeout of 1,800s (30 minutes)
102
+ */
103
+ timeoutSeconds?: number | null;
104
+ /**
105
+ * Min number of actual instances to be running at a given time.
106
+ * Instances will be billed for memory allocation and 10% of CPU allocation
107
+ * while idle.
108
+ * A value of null restores the default min instances.
109
+ */
110
+ minInstances?: number | null;
111
+ /**
112
+ * Max number of instances to be running in parallel.
113
+ * A value of null restores the default max instances.
114
+ */
115
+ maxInstances?: number | null;
116
+ /**
117
+ * Number of requests a function can serve at once.
118
+ * Can only be applied to functions running on Cloud Functions v2.
119
+ * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
120
+ * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
121
+ * The maximum value for concurrency is 1,000.
122
+ */
123
+ concurrency?: number | null;
124
+ /**
125
+ * Fractional number of CPUs to allocate to a function.
126
+ * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
127
+ * This is different from the defaults when using the gcloud utility and is different from
128
+ * the fixed amount assigned in Google Cloud Functions generation 1.
129
+ * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
130
+ * to the value "gcf_gen1"
131
+ */
132
+ cpu?: number | 'gcf_gen1';
133
+ /**
134
+ * Connect cloud function to specified VPC connector.
135
+ * A value of null removes the VPC connector
136
+ */
137
+ vpcConnector?: string | null;
138
+ /**
139
+ * Egress settings for VPC connector.
140
+ * A value of null turns off VPC connector egress settings
141
+ */
142
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
143
+ /**
144
+ * Specific service account for the function to run as.
145
+ * A value of null restores the default service account.
146
+ */
147
+ serviceAccount?: string | null;
148
+ /**
149
+ * Ingress settings which control where this function can be called from.
150
+ * A value of null turns off ingress settings.
151
+ */
152
+ ingressSettings?: options.IngressSetting | null;
153
+ /**
154
+ * User labels to set on the function.
155
+ */
156
+ labels?: Record<string, string>;
157
+ secrets?: string[];
158
+ /** Whether failed executions should be delivered again. */
159
+ retry?: boolean;
53
160
  }
54
- /** Handle a message being published to a Pub/Sub topic. */
55
- export declare function onMessagePublished<T = any>(topic: string, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<MessagePublishedData<T>>;
56
- /** Handle a message being published to a Pub/Sub topic. */
57
- export declare function onMessagePublished<T = any>(options: PubSubOptions, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<MessagePublishedData<T>>;
161
+ /**
162
+ * Handle a message being published to a Pub/Sub topic.
163
+ * @param topic - The Pub/Sub topic to watch for message events.
164
+ * @param handler - runs every time a Cloud Pub/Sub message is published
165
+ * @typeParam T - Type representing `Message.data`'s JSON format
166
+ */
167
+ export declare function onMessagePublished<T = any>(topic: string, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;
168
+ /**
169
+ * Handle a message being published to a Pub/Sub topic.
170
+ * @param options - Option containing information (topic) for event
171
+ * @param handler - runs every time a Cloud Pub/Sub message is published
172
+ * @typeParam T - Type representing `Message.data`'s JSON format
173
+ */
174
+ export declare function onMessagePublished<T = any>(options: PubSubOptions, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;