firebase-functions 3.19.0 → 3.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/lib/cloud-functions.d.ts +8 -0
  2. package/lib/cloud-functions.js +4 -7
  3. package/lib/common/providers/https.d.ts +20 -49
  4. package/lib/common/providers/https.js +7 -45
  5. package/lib/common/providers/identity.d.ts +193 -4
  6. package/lib/common/providers/identity.js +402 -28
  7. package/lib/common/providers/tasks.d.ts +58 -0
  8. package/lib/common/providers/tasks.js +77 -0
  9. package/lib/function-builder.d.ts +5 -2
  10. package/lib/function-builder.js +7 -2
  11. package/lib/handler-builder.d.ts +13 -2
  12. package/lib/handler-builder.js +17 -4
  13. package/lib/index.d.ts +2 -1
  14. package/lib/index.js +3 -1
  15. package/lib/providers/auth.d.ts +19 -6
  16. package/lib/providers/auth.js +60 -8
  17. package/lib/providers/https.d.ts +2 -44
  18. package/lib/providers/https.js +1 -49
  19. package/lib/providers/tasks.d.ts +46 -0
  20. package/lib/providers/tasks.js +75 -0
  21. package/lib/runtime/loader.js +9 -7
  22. package/lib/runtime/manifest.d.ts +8 -10
  23. package/lib/runtime/manifest.js +21 -0
  24. package/lib/v2/core.d.ts +3 -21
  25. package/lib/v2/index.d.ts +4 -1
  26. package/lib/v2/index.js +7 -1
  27. package/lib/v2/options.d.ts +13 -2
  28. package/lib/v2/options.js +22 -30
  29. package/lib/v2/providers/alerts/alerts.d.ts +15 -7
  30. package/lib/v2/providers/alerts/alerts.js +4 -10
  31. package/lib/v2/providers/alerts/appDistribution.d.ts +11 -11
  32. package/lib/v2/providers/alerts/billing.d.ts +17 -11
  33. package/lib/v2/providers/alerts/crashlytics.d.ts +62 -29
  34. package/lib/v2/providers/eventarc.d.ts +32 -0
  35. package/lib/v2/providers/eventarc.js +65 -0
  36. package/lib/v2/providers/https.d.ts +8 -23
  37. package/lib/v2/providers/https.js +3 -48
  38. package/lib/v2/providers/identity.d.ts +22 -0
  39. package/lib/v2/providers/identity.js +73 -0
  40. package/lib/v2/providers/pubsub.d.ts +3 -3
  41. package/lib/v2/providers/pubsub.js +2 -5
  42. package/lib/v2/providers/storage.d.ts +17 -13
  43. package/lib/v2/providers/storage.js +5 -4
  44. package/lib/v2/providers/tasks.d.ts +22 -0
  45. package/lib/v2/providers/tasks.js +88 -0
  46. package/package.json +42 -15
@@ -21,12 +21,12 @@
21
21
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.onTaskDispatched = exports.onCall = exports.onRequest = exports.HttpsError = void 0;
24
+ exports.onCall = exports.onRequest = exports.HttpsError = void 0;
25
25
  const cors = require("cors");
26
26
  const encoding_1 = require("../../common/encoding");
27
- const options = require("../options");
28
27
  const https_1 = require("../../common/providers/https");
29
28
  Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
29
+ const options = require("../options");
30
30
  function onRequest(optsOrHandler, handler) {
31
31
  let opts;
32
32
  if (arguments.length === 1) {
@@ -54,9 +54,6 @@ function onRequest(optsOrHandler, handler) {
54
54
  // but optionsToTriggerAnnotations handles both cases.
55
55
  const specificOpts = options.optionsToTriggerAnnotations(opts);
56
56
  const trigger = {
57
- // TODO(inlined): Remove "apiVersion" once the latest version of the CLI
58
- // has migrated to "platform".
59
- apiVersion: 2,
60
57
  platform: 'gcfv2',
61
58
  ...baseOpts,
62
59
  ...specificOpts,
@@ -112,9 +109,6 @@ function onCall(optsOrHandler, handler) {
112
109
  // but optionsToTriggerAnnotations handles both cases.
113
110
  const specificOpts = options.optionsToTriggerAnnotations(opts);
114
111
  return {
115
- // TODO(inlined): Remove "apiVersion" once the latest version of the CLI
116
- // has migrated to "platform".
117
- apiVersion: 2,
118
112
  platform: 'gcfv2',
119
113
  ...baseOpts,
120
114
  ...specificOpts,
@@ -131,7 +125,7 @@ function onCall(optsOrHandler, handler) {
131
125
  });
132
126
  const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
133
127
  // global options calls region a scalar and https allows it to be an array,
134
- // but optionsToManifestEndpoint handles both cases.
128
+ // but optionsToEndpoint handles both cases.
135
129
  const specificOpts = options.optionsToEndpoint(opts);
136
130
  func.__endpoint = {
137
131
  platform: 'gcfv2',
@@ -147,42 +141,3 @@ function onCall(optsOrHandler, handler) {
147
141
  return func;
148
142
  }
149
143
  exports.onCall = onCall;
150
- function onTaskDispatched(optsOrHandler, handler) {
151
- let opts;
152
- if (arguments.length == 1) {
153
- opts = {};
154
- handler = optsOrHandler;
155
- }
156
- else {
157
- opts = optsOrHandler;
158
- }
159
- // onEnqueueHandler sniffs the function length to determine which API to present.
160
- // fix the length to prevent api versions from being mismatched.
161
- const fixedLen = (req) => handler(req);
162
- const func = (0, https_1.onDispatchHandler)(fixedLen);
163
- Object.defineProperty(func, '__trigger', {
164
- get: () => {
165
- const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
166
- // global options calls region a scalar and https allows it to be an array,
167
- // but optionsToTriggerAnnotations handles both cases.
168
- const specificOpts = options.optionsToTriggerAnnotations(opts);
169
- const taskQueueTrigger = {};
170
- (0, encoding_1.copyIfPresent)(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
171
- (0, encoding_1.convertIfPresent)(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
172
- return {
173
- apiVersion: 2,
174
- platform: 'gcfv2',
175
- ...baseOpts,
176
- ...specificOpts,
177
- labels: {
178
- ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
179
- ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
180
- },
181
- taskQueueTrigger,
182
- };
183
- },
184
- });
185
- func.run = handler;
186
- return func;
187
- }
188
- exports.onTaskDispatched = onTaskDispatched;
@@ -0,0 +1,22 @@
1
+ import { BlockingFunction } from '../../cloud-functions';
2
+ import { AuthBlockingEvent, BeforeCreateResponse, BeforeSignInResponse, HttpsError } from '../../common/providers/identity';
3
+ import * as options from '../options';
4
+ export { HttpsError };
5
+ /**
6
+ * All function options plus idToken, accessToken, and refreshToken.
7
+ */
8
+ export interface BlockingOptions extends options.GlobalOptions {
9
+ idToken?: boolean;
10
+ accessToken?: boolean;
11
+ refreshToken?: boolean;
12
+ }
13
+ /**
14
+ * Handle an event that is triggered before a user is created.
15
+ */
16
+ export declare function beforeUserCreated(handler: (event: AuthBlockingEvent) => BeforeCreateResponse | Promise<BeforeCreateResponse> | void | Promise<void>): BlockingFunction;
17
+ export declare function beforeUserCreated(opts: BlockingOptions, handler: (event: AuthBlockingEvent) => BeforeCreateResponse | Promise<BeforeCreateResponse> | void | Promise<void>): BlockingFunction;
18
+ /**
19
+ * Handle an event that is triggered before a user is signed in.
20
+ */
21
+ export declare function beforeUserSignedIn(handler: (event: AuthBlockingEvent) => BeforeSignInResponse | Promise<BeforeSignInResponse> | void | Promise<void>): BlockingFunction;
22
+ export declare function beforeUserSignedIn(opts: BlockingOptions, handler: (event: AuthBlockingEvent) => BeforeSignInResponse | Promise<BeforeSignInResponse> | void | Promise<void>): BlockingFunction;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOpts = exports.beforeOperation = exports.beforeUserSignedIn = exports.beforeUserCreated = exports.HttpsError = void 0;
4
+ const identity_1 = require("../../common/providers/identity");
5
+ Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return identity_1.HttpsError; } });
6
+ const options = require("../options");
7
+ function beforeUserCreated(optsOrHandler, handler) {
8
+ return beforeOperation('beforeCreate', optsOrHandler, handler);
9
+ }
10
+ exports.beforeUserCreated = beforeUserCreated;
11
+ function beforeUserSignedIn(optsOrHandler, handler) {
12
+ return beforeOperation('beforeSignIn', optsOrHandler, handler);
13
+ }
14
+ exports.beforeUserSignedIn = beforeUserSignedIn;
15
+ /** @internal */
16
+ function beforeOperation(eventType, optsOrHandler, handler) {
17
+ if (!handler || typeof optsOrHandler === 'function') {
18
+ handler = optsOrHandler;
19
+ optsOrHandler = {};
20
+ }
21
+ const { opts, accessToken, idToken, refreshToken } = getOpts(optsOrHandler);
22
+ // Create our own function that just calls the provided function so we know for sure that
23
+ // handler takes one argument. This is something common/providers/identity depends on.
24
+ const wrappedHandler = (event) => handler(event);
25
+ const func = (0, identity_1.wrapHandler)(eventType, wrappedHandler);
26
+ const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
27
+ /** Endpoint */
28
+ const baseOptsEndpoint = options.optionsToEndpoint(options.getGlobalOptions());
29
+ const specificOptsEndpoint = options.optionsToEndpoint(opts);
30
+ func.__endpoint = {
31
+ platform: 'gcfv2',
32
+ ...baseOptsEndpoint,
33
+ ...specificOptsEndpoint,
34
+ labels: {
35
+ ...baseOptsEndpoint === null || baseOptsEndpoint === void 0 ? void 0 : baseOptsEndpoint.labels,
36
+ ...specificOptsEndpoint === null || specificOptsEndpoint === void 0 ? void 0 : specificOptsEndpoint.labels,
37
+ },
38
+ blockingTrigger: {
39
+ eventType: legacyEventType,
40
+ options: {
41
+ accessToken,
42
+ idToken,
43
+ refreshToken,
44
+ },
45
+ },
46
+ };
47
+ func.__requiredAPIs = [
48
+ {
49
+ api: 'identitytoolkit.googleapis.com',
50
+ reason: 'Needed for auth blocking functions',
51
+ },
52
+ ];
53
+ func.run = handler;
54
+ return func;
55
+ }
56
+ exports.beforeOperation = beforeOperation;
57
+ /** @internal */
58
+ function getOpts(blockingOptions) {
59
+ const accessToken = blockingOptions.accessToken || false;
60
+ const idToken = blockingOptions.idToken || false;
61
+ const refreshToken = blockingOptions.refreshToken || false;
62
+ const opts = { ...blockingOptions };
63
+ delete opts.accessToken;
64
+ delete opts.idToken;
65
+ delete opts.refreshToken;
66
+ return {
67
+ opts,
68
+ accessToken,
69
+ idToken,
70
+ refreshToken,
71
+ };
72
+ }
73
+ exports.getOpts = getOpts;
@@ -1,5 +1,5 @@
1
- import * as options from '../options';
2
1
  import { CloudEvent, CloudFunction } from '../core';
2
+ import * as options from '../options';
3
3
  /**
4
4
  * Interface representing a Google Cloud Pub/Sub message.
5
5
  *
@@ -52,6 +52,6 @@ export interface PubSubOptions extends options.EventHandlerOptions {
52
52
  topic: string;
53
53
  }
54
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>>;
55
+ export declare function onMessagePublished<T = any>(topic: string, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;
56
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>>;
57
+ export declare function onMessagePublished<T = any>(options: PubSubOptions, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.onMessagePublished = exports.Message = void 0;
4
- const options = require("../options");
5
4
  const encoding_1 = require("../../common/encoding");
5
+ const options = require("../options");
6
6
  /**
7
7
  * Interface representing a Google Cloud Pub/Sub message.
8
8
  *
@@ -75,9 +75,6 @@ function onMessagePublished(topicOrOptions, handler) {
75
75
  const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
76
76
  const specificOpts = options.optionsToTriggerAnnotations(opts);
77
77
  return {
78
- // TODO(inlined): Remove "apiVersion" once the CLI has migrated to
79
- // "platform"
80
- apiVersion: 2,
81
78
  platform: 'gcfv2',
82
79
  ...baseOpts,
83
80
  ...specificOpts,
@@ -104,7 +101,7 @@ function onMessagePublished(topicOrOptions, handler) {
104
101
  },
105
102
  eventTrigger: {
106
103
  eventType: 'google.cloud.pubsub.topic.v1.messagePublished',
107
- eventFilters: [{ attribute: 'topic', value: topic }],
104
+ eventFilters: { topic },
108
105
  retry: false,
109
106
  },
110
107
  };
@@ -1,5 +1,5 @@
1
- import * as options from '../options';
2
1
  import { CloudEvent, CloudFunction } from '../core';
2
+ import * as options from '../options';
3
3
  /**
4
4
  * An object within Google Cloud Storage.
5
5
  * Ref: https://github.com/googleapis/google-cloudevents-nodejs/blob/main/cloud/storage/v1/StorageObjectData.ts
@@ -148,23 +148,27 @@ export interface CustomerEncryption {
148
148
  */
149
149
  keySha256?: string;
150
150
  }
151
+ export interface StorageEvent extends CloudEvent<StorageObjectData> {
152
+ /** The name of the bucket containing this object. */
153
+ bucket: string;
154
+ }
151
155
  /** StorageOptions extend EventHandlerOptions with a bucket name */
152
156
  export interface StorageOptions extends options.EventHandlerOptions {
153
157
  bucket?: string;
154
158
  }
155
159
  /** Handle a storage object archived */
156
- export declare function onObjectArchived(handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
157
- export declare function onObjectArchived(bucket: string, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
158
- export declare function onObjectArchived(opts: StorageOptions, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
160
+ export declare function onObjectArchived(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
161
+ export declare function onObjectArchived(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
162
+ export declare function onObjectArchived(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
159
163
  /** Handle a storage object finalized */
160
- export declare function onObjectFinalized(handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
161
- export declare function onObjectFinalized(bucket: string, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
162
- export declare function onObjectFinalized(opts: StorageOptions, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
164
+ export declare function onObjectFinalized(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
165
+ export declare function onObjectFinalized(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
166
+ export declare function onObjectFinalized(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
163
167
  /** Handle a storage object deleted */
164
- export declare function onObjectDeleted(handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
165
- export declare function onObjectDeleted(bucket: string, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
166
- export declare function onObjectDeleted(opts: StorageOptions, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
168
+ export declare function onObjectDeleted(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
169
+ export declare function onObjectDeleted(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
170
+ export declare function onObjectDeleted(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
167
171
  /** Handle a storage object metadata updated */
168
- export declare function onObjectMetadataUpdated(handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
169
- export declare function onObjectMetadataUpdated(bucket: string, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
170
- export declare function onObjectMetadataUpdated(opts: StorageOptions, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
172
+ export declare function onObjectMetadataUpdated(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
173
+ export declare function onObjectMetadataUpdated(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
174
+ export declare function onObjectMetadataUpdated(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
@@ -22,9 +22,9 @@
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.getOptsAndBucket = exports.onOperation = exports.onObjectMetadataUpdated = exports.onObjectDeleted = exports.onObjectFinalized = exports.onObjectArchived = exports.metadataUpdatedEvent = exports.deletedEvent = exports.finalizedEvent = exports.archivedEvent = void 0;
25
- const options = require("../options");
26
- const config_1 = require("../../config");
27
25
  const encoding_1 = require("../../common/encoding");
26
+ const config_1 = require("../../config");
27
+ const options = require("../options");
28
28
  /** @internal */
29
29
  exports.archivedEvent = 'google.cloud.storage.object.v1.archived';
30
30
  /** @internal */
@@ -99,7 +99,7 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
99
99
  },
100
100
  eventTrigger: {
101
101
  eventType,
102
- eventFilters: [{ attribute: 'bucket', value: bucket }],
102
+ eventFilters: { bucket },
103
103
  retry: false,
104
104
  },
105
105
  };
@@ -112,6 +112,7 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
112
112
  exports.onOperation = onOperation;
113
113
  /** @internal */
114
114
  function getOptsAndBucket(bucketOrOpts) {
115
+ var _a;
115
116
  let bucket;
116
117
  let opts;
117
118
  if (typeof bucketOrOpts === 'string') {
@@ -119,7 +120,7 @@ function getOptsAndBucket(bucketOrOpts) {
119
120
  opts = {};
120
121
  }
121
122
  else {
122
- bucket = bucketOrOpts.bucket || (0, config_1.firebaseConfig)().storageBucket;
123
+ bucket = bucketOrOpts.bucket || ((_a = (0, config_1.firebaseConfig)()) === null || _a === void 0 ? void 0 : _a.storageBucket);
123
124
  opts = { ...bucketOrOpts };
124
125
  delete opts.bucket;
125
126
  }
@@ -0,0 +1,22 @@
1
+ import { AuthData, RateLimits, Request, RetryConfig } from '../../common/providers/tasks';
2
+ import * as options from '../options';
3
+ import { HttpsFunction } from './https';
4
+ export { AuthData, RateLimits, Request, RetryConfig as RetryPolicy };
5
+ export interface TaskQueueOptions extends options.GlobalOptions {
6
+ retryConfig?: RetryConfig;
7
+ rateLimits?: RateLimits;
8
+ /**
9
+ * Who can enqueue tasks for this function.
10
+ * If left unspecified, only service accounts which have
11
+ * roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
12
+ * will have permissions.
13
+ */
14
+ invoker?: 'private' | string | string[];
15
+ }
16
+ export interface TaskQueueFunction<T = any> extends HttpsFunction {
17
+ run(data: Request<T>): void | Promise<void>;
18
+ }
19
+ /** Handle a request sent to a Cloud Tasks queue. */
20
+ 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. */
22
+ export declare function onTaskDispatched<Args = any>(options: TaskQueueOptions, handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
@@ -0,0 +1,88 @@
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.onTaskDispatched = void 0;
25
+ const encoding_1 = require("../../common/encoding");
26
+ const tasks_1 = require("../../common/providers/tasks");
27
+ const options = require("../options");
28
+ function onTaskDispatched(optsOrHandler, handler) {
29
+ let opts;
30
+ if (arguments.length == 1) {
31
+ opts = {};
32
+ handler = optsOrHandler;
33
+ }
34
+ else {
35
+ opts = optsOrHandler;
36
+ }
37
+ // onDispatchHandler sniffs the function length to determine which API to present.
38
+ // fix the length to prevent api versions from being mismatched.
39
+ const fixedLen = (req) => handler(req);
40
+ const func = (0, tasks_1.onDispatchHandler)(fixedLen);
41
+ Object.defineProperty(func, '__trigger', {
42
+ get: () => {
43
+ const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
44
+ // global options calls region a scalar and https allows it to be an array,
45
+ // but optionsToTriggerAnnotations handles both cases.
46
+ const specificOpts = options.optionsToTriggerAnnotations(opts);
47
+ const taskQueueTrigger = {};
48
+ (0, encoding_1.copyIfPresent)(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
49
+ (0, encoding_1.convertIfPresent)(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
50
+ return {
51
+ platform: 'gcfv2',
52
+ ...baseOpts,
53
+ ...specificOpts,
54
+ labels: {
55
+ ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
56
+ ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
57
+ },
58
+ taskQueueTrigger,
59
+ };
60
+ },
61
+ });
62
+ const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
63
+ // global options calls region a scalar and https allows it to be an array,
64
+ // but optionsToManifestEndpoint handles both cases.
65
+ const specificOpts = options.optionsToEndpoint(opts);
66
+ func.__endpoint = {
67
+ platform: 'gcfv2',
68
+ ...baseOpts,
69
+ ...specificOpts,
70
+ labels: {
71
+ ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
72
+ ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
73
+ },
74
+ taskQueueTrigger: {},
75
+ };
76
+ (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, opts, 'retryConfig');
77
+ (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, opts, 'rateLimits');
78
+ (0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
79
+ func.__requiredAPIs = [
80
+ {
81
+ api: 'cloudtasks.googleapis.com',
82
+ reason: 'Needed for task queue functions',
83
+ },
84
+ ];
85
+ func.run = handler;
86
+ return func;
87
+ }
88
+ exports.onTaskDispatched = onTaskDispatched;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "3.19.0",
3
+ "version": "3.21.0",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",
@@ -40,6 +40,7 @@
40
40
  "./lib/providers/pubsub": "./lib/providers/pubsub.js",
41
41
  "./lib/providers/remoteConfig": "./lib/providers/remoteConfig.js",
42
42
  "./lib/providers/storage": "./lib/providers/storage.js",
43
+ "./lib/providers/tasks": "./lib/providers/tasks.js",
43
44
  "./lib/providers/testLab": "./lib/providers/testLab.js",
44
45
  "./v1": "./lib/index.js",
45
46
  "./v1/analytics": "./lib/providers/analytics.js",
@@ -58,10 +59,13 @@
58
59
  "./v2/params": "./lib/v2/params/index.js",
59
60
  "./v2/pubsub": "./lib/v2/providers/pubsub.js",
60
61
  "./v2/storage": "./lib/v2/providers/storage.js",
62
+ "./v2/tasks": "./lib/v2/providers/tasks.js",
61
63
  "./v2/alerts": "./lib/v2/providers/alerts/index.js",
62
64
  "./v2/alerts/appDistribution": "./lib/v2/providers/alerts/appDistribution.js",
63
65
  "./v2/alerts/billing": "./lib/v2/providers/alerts/billing.js",
64
- "./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"
65
69
  },
66
70
  "typesVersions": {
67
71
  "*": {
@@ -98,15 +102,36 @@
98
102
  "v1/storage": [
99
103
  "lib/providers/storage"
100
104
  ],
105
+ "v1/tasks": [
106
+ "lib/providers/tasks"
107
+ ],
101
108
  "v1/testLab": [
102
109
  "lib/providers/testLab"
103
110
  ],
104
111
  "v2": [
105
112
  "lib/v2"
106
113
  ],
114
+ "v2/alerts": [
115
+ "lib/v2/providers/alerts"
116
+ ],
117
+ "v2/alerts/appDistribution": [
118
+ "lib/v2/providers/alerts/appDistribution"
119
+ ],
120
+ "v2/alerts/billing": [
121
+ "lib/v2/providers/alerts/billing"
122
+ ],
123
+ "v2/alerts/crashlytics": [
124
+ "lib/v2/providers/alerts/crashlytics"
125
+ ],
107
126
  "v2/base": [
108
127
  "lib/v2/base"
109
128
  ],
129
+ "v2/eventarc": [
130
+ "lib/v2/providers/eventarc"
131
+ ],
132
+ "v2/identity": [
133
+ "lib/v2/providers/identity"
134
+ ],
110
135
  "v2/options": [
111
136
  "lib/v2/options"
112
137
  ],
@@ -122,17 +147,8 @@
122
147
  "v2/storage": [
123
148
  "lib/v2/providers/storage"
124
149
  ],
125
- "v2/alerts": [
126
- "lib/v2/providers/alerts"
127
- ],
128
- "v2/alerts/appDistribution": [
129
- "lib/v2/providers/alerts/appDistribution"
130
- ],
131
- "v2/alerts/billing": [
132
- "lib/v2/providers/alerts/billing"
133
- ],
134
- "v2/alerts/crashlytics": [
135
- "lib/v2/providers/alerts/crashlytics"
150
+ "v2/tasks": [
151
+ "lib/v2/providers/tasks"
136
152
  ]
137
153
  }
138
154
  },
@@ -141,6 +157,12 @@
141
157
  },
142
158
  "scripts": {
143
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 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:gen": "api-documenter-fire markdown -i docgen/v2 -o docgen/v2/markdown && api-documenter-fire toc -i docgen/v2 -o docgen/v2/markdown/toc -p /docs/reference/functions/v2",
165
+ "docgen:v2": "npm run docgen:v2:extract && npm run docgen:v2:gen",
144
166
  "build:pack": "rm -rf lib && npm install && tsc -p tsconfig.release.json && npm pack",
145
167
  "build:release": "npm ci --production && npm install --no-save typescript firebase-admin && tsc -p tsconfig.release.json",
146
168
  "build": "tsc -p tsconfig.release.json",
@@ -157,9 +179,13 @@
157
179
  "@types/express": "4.17.3",
158
180
  "cors": "^2.8.5",
159
181
  "express": "^4.17.1",
160
- "lodash": "^4.17.14"
182
+ "lodash": "^4.17.14",
183
+ "node-fetch": "^2.6.7"
161
184
  },
162
185
  "devDependencies": {
186
+ "@firebase/api-documenter": "^0.1.2",
187
+ "@microsoft/api-documenter": "^7.13.45",
188
+ "@microsoft/api-extractor": "^7.18.7",
163
189
  "@types/chai": "^4.1.7",
164
190
  "@types/chai-as-promised": "^7.1.0",
165
191
  "@types/jsonwebtoken": "^8.3.2",
@@ -168,11 +194,12 @@
168
194
  "@types/mock-require": "^2.0.0",
169
195
  "@types/nock": "^10.0.3",
170
196
  "@types/node": "^8.10.50",
197
+ "@types/node-fetch": "^3.0.3",
171
198
  "@types/sinon": "^7.0.13",
172
199
  "chai": "^4.2.0",
173
200
  "chai-as-promised": "^7.1.1",
174
201
  "child-process-promise": "^2.2.1",
175
- "firebase-admin": "10.0.0",
202
+ "firebase-admin": "^10.1.0",
176
203
  "js-yaml": "^3.13.1",
177
204
  "jsdom": "^16.2.1",
178
205
  "jsonwebtoken": "^8.5.1",