firebase-functions 3.20.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 (66) 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 +55 -207
  10. package/lib/common/providers/tasks.d.ts +9 -0
  11. package/lib/common/providers/tasks.js +12 -3
  12. package/lib/function-builder.d.ts +2 -2
  13. package/lib/function-builder.js +1 -1
  14. package/lib/handler-builder.js +3 -3
  15. package/lib/index.js +6 -2
  16. package/lib/logger/common.js +21 -0
  17. package/lib/logger/compat.js +22 -1
  18. package/lib/logger/index.d.ts +14 -6
  19. package/lib/logger/index.js +33 -6
  20. package/lib/providers/analytics.js +1 -1
  21. package/lib/providers/auth.d.ts +44 -10
  22. package/lib/providers/auth.js +80 -14
  23. package/lib/providers/database.js +11 -11
  24. package/lib/providers/firestore.js +7 -7
  25. package/lib/providers/https.js +7 -7
  26. package/lib/providers/pubsub.d.ts +6 -6
  27. package/lib/providers/pubsub.js +8 -8
  28. package/lib/providers/remoteConfig.js +1 -1
  29. package/lib/providers/storage.js +2 -2
  30. package/lib/providers/tasks.d.ts +30 -15
  31. package/lib/providers/tasks.js +19 -12
  32. package/lib/providers/testLab.js +1 -1
  33. package/lib/runtime/loader.js +9 -7
  34. package/lib/runtime/manifest.d.ts +5 -0
  35. package/lib/setup.js +3 -3
  36. package/lib/v2/core.d.ts +24 -20
  37. package/lib/v2/index.d.ts +11 -3
  38. package/lib/v2/index.js +12 -3
  39. package/lib/v2/options.d.ts +25 -35
  40. package/lib/v2/options.js +28 -88
  41. package/lib/v2/params/index.d.ts +4 -1
  42. package/lib/v2/params/index.js +25 -1
  43. package/lib/v2/params/types.js +21 -0
  44. package/lib/v2/providers/alerts/alerts.d.ts +107 -8
  45. package/lib/v2/providers/alerts/alerts.js +23 -7
  46. package/lib/v2/providers/alerts/appDistribution.d.ts +112 -12
  47. package/lib/v2/providers/alerts/appDistribution.js +29 -2
  48. package/lib/v2/providers/alerts/billing.d.ts +39 -12
  49. package/lib/v2/providers/alerts/billing.js +38 -1
  50. package/lib/v2/providers/alerts/crashlytics.d.ts +255 -47
  51. package/lib/v2/providers/alerts/crashlytics.js +63 -2
  52. package/lib/v2/providers/alerts/index.d.ts +6 -0
  53. package/lib/v2/providers/alerts/index.js +32 -1
  54. package/lib/v2/providers/eventarc.d.ts +116 -0
  55. package/lib/v2/providers/eventarc.js +69 -0
  56. package/lib/v2/providers/https.d.ts +128 -4
  57. package/lib/v2/providers/https.js +18 -14
  58. package/lib/v2/providers/identity.d.ts +126 -0
  59. package/lib/v2/providers/identity.js +104 -0
  60. package/lib/v2/providers/pubsub.d.ts +125 -8
  61. package/lib/v2/providers/pubsub.js +60 -7
  62. package/lib/v2/providers/storage.d.ts +209 -17
  63. package/lib/v2/providers/storage.js +57 -13
  64. package/lib/v2/providers/tasks.d.ts +107 -7
  65. package/lib/v2/providers/tasks.js +11 -8
  66. package/package.json +22 -3
@@ -1,22 +1,122 @@
1
+ import { AuthData, RateLimits, Request, RetryConfig } from '../../common/providers/tasks';
1
2
  import * as options from '../options';
2
3
  import { HttpsFunction } from './https';
3
- import { AuthData, RateLimits, Request, RetryConfig } from '../../common/providers/tasks';
4
- export { AuthData, RateLimits, Request, RetryConfig as RetryPolicy };
5
- export interface TaskQueueOptions extends options.GlobalOptions {
4
+ export { AuthData, RateLimits, Request, RetryConfig };
5
+ export interface TaskQueueOptions extends options.EventHandlerOptions {
6
+ /** How a task should be retried in the event of a non-2xx return. */
6
7
  retryConfig?: RetryConfig;
8
+ /** How congestion control should be applied to the function. */
7
9
  rateLimits?: RateLimits;
8
10
  /**
9
11
  * Who can enqueue tasks for this function.
10
12
  * If left unspecified, only service accounts which have
11
- * roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
13
+ * `roles/cloudtasks.enqueuer` and `roles/cloudfunctions.invoker`
12
14
  * will have permissions.
13
15
  */
14
16
  invoker?: 'private' | string | string[];
17
+ /**
18
+ * Region where functions should be deployed.
19
+ */
20
+ region?: options.SupportedRegion | string;
21
+ /**
22
+ * Amount of memory to allocate to a function.
23
+ * A value of null restores the defaults of 256MB.
24
+ */
25
+ memory?: options.MemoryOption | null;
26
+ /**
27
+ * Timeout for the function in sections, possible values are 0 to 540.
28
+ * HTTPS functions can specify a higher timeout.
29
+ * A value of null restores the default of 60s
30
+ * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
31
+ * function depends on the type of function: Event handling functions have a
32
+ * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
33
+ * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
34
+ * timeout of 1,800s (30 minutes)
35
+ */
36
+ timeoutSeconds?: number | null;
37
+ /**
38
+ * Min number of actual instances to be running at a given time.
39
+ * Instances will be billed for memory allocation and 10% of CPU allocation
40
+ * while idle.
41
+ * A value of null restores the default min instances.
42
+ */
43
+ minInstances?: number | null;
44
+ /**
45
+ * Max number of instances to be running in parallel.
46
+ * A value of null restores the default max instances.
47
+ */
48
+ maxInstances?: number | null;
49
+ /**
50
+ * Number of requests a function can serve at once.
51
+ * Can only be applied to functions running on Cloud Functions v2.
52
+ * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
53
+ * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
54
+ * The maximum value for concurrency is 1,000.
55
+ */
56
+ concurrency?: number | null;
57
+ /**
58
+ * Fractional number of CPUs to allocate to a function.
59
+ * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
60
+ * This is different from the defaults when using the gcloud utility and is different from
61
+ * the fixed amount assigned in Google Cloud Functions generation 1.
62
+ * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
63
+ * to the value "gcf_gen1"
64
+ */
65
+ cpu?: number | 'gcf_gen1';
66
+ /**
67
+ * Connect cloud function to specified VPC connector.
68
+ * A value of null removes the VPC connector
69
+ */
70
+ vpcConnector?: string | null;
71
+ /**
72
+ * Egress settings for VPC connector.
73
+ * A value of null turns off VPC connector egress settings
74
+ */
75
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
76
+ /**
77
+ * Specific service account for the function to run as.
78
+ * A value of null restores the default service account.
79
+ */
80
+ serviceAccount?: string | null;
81
+ /**
82
+ * Ingress settings which control where this function can be called from.
83
+ * A value of null turns off ingress settings.
84
+ */
85
+ ingressSettings?: options.IngressSetting | null;
86
+ /**
87
+ * User labels to set on the function.
88
+ */
89
+ labels?: Record<string, string>;
90
+ secrets?: string[];
91
+ /** Whether failed executions should be delivered again. */
92
+ retry?: boolean;
15
93
  }
94
+ /**
95
+ * A handler for tasks.
96
+ * @typeParam T - The task data interface. Task data is unmarshaled from JSON.
97
+ */
16
98
  export interface TaskQueueFunction<T = any> extends HttpsFunction {
17
- run(data: Request<T>): void | Promise<void>;
99
+ /**
100
+ * The callback passed to the `TaskQueueFunction` constructor.
101
+ * @param request - A TaskRequest containing data and auth information.
102
+ * @returns Any return value. Google Cloud Functions will await any promise
103
+ * before shutting down your function. Resolved return values
104
+ * are only used for unit testing purposes.
105
+ */
106
+ run(request: Request<T>): void | Promise<void>;
18
107
  }
19
- /** Handle a request sent to a Cloud Tasks queue. */
108
+ /**
109
+ * Creates a handler for tasks sent to a Google Cloud Tasks queue.
110
+ * @param handler - A callback to handle task requests.
111
+ * @typeParam Args - The interface for the request's `data` field.
112
+ * @returns A Cloud Function you can export and deploy.
113
+ */
20
114
  export declare function onTaskDispatched<Args = any>(handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
21
- /** Handle a request sent to a Cloud Tasks queue. */
115
+ /**
116
+ * Creates a handler for tasks sent to a Google Cloud Tasks queue.
117
+ * @param options - Configuration for the task queue or Cloud Function.
118
+ * @param handler - A callback to handle task requests.
119
+ * @typeParam Args - The interface for the request's `data` field.
120
+ * @returns A Cloud Function you can export and deploy.
121
+ */
22
122
  export declare function onTaskDispatched<Args = any>(options: TaskQueueOptions, handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
@@ -22,9 +22,13 @@
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.onTaskDispatched = void 0;
25
- const options = require("../options");
25
+ /**
26
+ * Cloud functions to handle Tasks enqueued with Google Cloud Tasks.
27
+ * @packageDocumentation
28
+ */
26
29
  const encoding_1 = require("../../common/encoding");
27
30
  const tasks_1 = require("../../common/providers/tasks");
31
+ const options = require("../options");
28
32
  function onTaskDispatched(optsOrHandler, handler) {
29
33
  let opts;
30
34
  if (arguments.length == 1) {
@@ -37,7 +41,7 @@ function onTaskDispatched(optsOrHandler, handler) {
37
41
  // onDispatchHandler sniffs the function length to determine which API to present.
38
42
  // fix the length to prevent api versions from being mismatched.
39
43
  const fixedLen = (req) => handler(req);
40
- const func = tasks_1.onDispatchHandler(fixedLen);
44
+ const func = (0, tasks_1.onDispatchHandler)(fixedLen);
41
45
  Object.defineProperty(func, '__trigger', {
42
46
  get: () => {
43
47
  const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
@@ -45,10 +49,9 @@ function onTaskDispatched(optsOrHandler, handler) {
45
49
  // but optionsToTriggerAnnotations handles both cases.
46
50
  const specificOpts = options.optionsToTriggerAnnotations(opts);
47
51
  const taskQueueTrigger = {};
48
- encoding_1.copyIfPresent(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
49
- encoding_1.convertIfPresent(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
52
+ (0, encoding_1.copyIfPresent)(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
53
+ (0, encoding_1.convertIfPresent)(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
50
54
  return {
51
- apiVersion: 2,
52
55
  platform: 'gcfv2',
53
56
  ...baseOpts,
54
57
  ...specificOpts,
@@ -74,9 +77,9 @@ function onTaskDispatched(optsOrHandler, handler) {
74
77
  },
75
78
  taskQueueTrigger: {},
76
79
  };
77
- encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, opts, 'retryConfig');
78
- encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, opts, 'rateLimits');
79
- encoding_1.convertIfPresent(func.__endpoint.taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
80
+ (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, opts, 'retryConfig');
81
+ (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, opts, 'rateLimits');
82
+ (0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
80
83
  func.__requiredAPIs = [
81
84
  {
82
85
  api: 'cloudtasks.googleapis.com',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "3.20.0",
3
+ "version": "3.21.1",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",
@@ -63,7 +63,9 @@
63
63
  "./v2/alerts": "./lib/v2/providers/alerts/index.js",
64
64
  "./v2/alerts/appDistribution": "./lib/v2/providers/alerts/appDistribution.js",
65
65
  "./v2/alerts/billing": "./lib/v2/providers/alerts/billing.js",
66
- "./v2/alerts/crashlytics": "./lib/v2/providers/alerts/crashlytics.js"
66
+ "./v2/alerts/crashlytics": "./lib/v2/providers/alerts/crashlytics.js",
67
+ "./v2/eventarc": "./lib/v2/providers/eventarc.js",
68
+ "./v2/identity": "./lib/v2/providers/identity.js"
67
69
  },
68
70
  "typesVersions": {
69
71
  "*": {
@@ -124,6 +126,12 @@
124
126
  "v2/base": [
125
127
  "lib/v2/base"
126
128
  ],
129
+ "v2/eventarc": [
130
+ "lib/v2/providers/eventarc"
131
+ ],
132
+ "v2/identity": [
133
+ "lib/v2/providers/identity"
134
+ ],
127
135
  "v2/options": [
128
136
  "lib/v2/options"
129
137
  ],
@@ -149,6 +157,13 @@
149
157
  },
150
158
  "scripts": {
151
159
  "apidocs": "node docgen/generate-docs.js",
160
+ "docgen:v1:extract": "api-extractor run -c docgen/api-extractor.v1.json --local",
161
+ "docgen:v1:gen": "api-documenter-fire markdown -i docgen/v1 -o docgen/v1/markdown && api-documenter-fire toc -i docgen/v1 -o docgen/v1/markdown/toc -p /docs/reference/functions",
162
+ "docgen:v1": "npm run build && npm run docgen:v1:extract && npm run docgen:v1:gen",
163
+ "docgen:v2:extract": "api-extractor run -c docgen/api-extractor.v2.json --local",
164
+ "docgen:v2:toc": "ts-node docgen/toc.ts --input docgen/v2/markdown --output docgen/v2/markdown/toc --path /docs/functions/beta/reference",
165
+ "docgen:v2:gen": "api-documenter-fire markdown -i docgen/v2 -o docgen/v2/markdown && npm run docgen:v2:toc",
166
+ "docgen:v2": "npm run build && npm run docgen:v2:extract && npm run docgen:v2:gen",
152
167
  "build:pack": "rm -rf lib && npm install && tsc -p tsconfig.release.json && npm pack",
153
168
  "build:release": "npm ci --production && npm install --no-save typescript firebase-admin && tsc -p tsconfig.release.json",
154
169
  "build": "tsc -p tsconfig.release.json",
@@ -169,6 +184,9 @@
169
184
  "node-fetch": "^2.6.7"
170
185
  },
171
186
  "devDependencies": {
187
+ "@firebase/api-documenter": "^0.1.2",
188
+ "@microsoft/api-documenter": "^7.13.45",
189
+ "@microsoft/api-extractor": "^7.18.7",
172
190
  "@types/chai": "^4.1.7",
173
191
  "@types/chai-as-promised": "^7.1.0",
174
192
  "@types/jsonwebtoken": "^8.3.2",
@@ -179,10 +197,11 @@
179
197
  "@types/node": "^8.10.50",
180
198
  "@types/node-fetch": "^3.0.3",
181
199
  "@types/sinon": "^7.0.13",
200
+ "api-extractor-model-me": "^0.1.1",
182
201
  "chai": "^4.2.0",
183
202
  "chai-as-promised": "^7.1.1",
184
203
  "child-process-promise": "^2.2.1",
185
- "firebase-admin": "10.0.0",
204
+ "firebase-admin": "^10.1.0",
186
205
  "js-yaml": "^3.13.1",
187
206
  "jsdom": "^16.2.1",
188
207
  "jsonwebtoken": "^8.5.1",