firebase-functions 3.19.0 → 3.20.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/apps.js +1 -1
  2. package/lib/bin/firebase-functions.js +1 -1
  3. package/lib/cloud-functions.js +15 -18
  4. package/lib/common/providers/https.d.ts +20 -49
  5. package/lib/common/providers/https.js +10 -50
  6. package/lib/common/providers/identity.d.ts +187 -4
  7. package/lib/common/providers/identity.js +553 -27
  8. package/lib/common/providers/tasks.d.ts +58 -0
  9. package/lib/common/providers/tasks.js +68 -0
  10. package/lib/function-builder.d.ts +4 -1
  11. package/lib/function-builder.js +6 -1
  12. package/lib/handler-builder.d.ts +13 -2
  13. package/lib/handler-builder.js +18 -5
  14. package/lib/index.d.ts +2 -1
  15. package/lib/index.js +5 -7
  16. package/lib/logger/compat.js +1 -1
  17. package/lib/providers/analytics.js +1 -1
  18. package/lib/providers/auth.js +2 -2
  19. package/lib/providers/database.js +11 -11
  20. package/lib/providers/firestore.js +7 -7
  21. package/lib/providers/https.d.ts +2 -44
  22. package/lib/providers/https.js +8 -56
  23. package/lib/providers/pubsub.js +2 -2
  24. package/lib/providers/remoteConfig.js +1 -1
  25. package/lib/providers/storage.js +2 -2
  26. package/lib/providers/tasks.d.ts +46 -0
  27. package/lib/providers/tasks.js +75 -0
  28. package/lib/providers/testLab.js +1 -1
  29. package/lib/runtime/manifest.d.ts +3 -10
  30. package/lib/runtime/manifest.js +21 -0
  31. package/lib/setup.js +3 -3
  32. package/lib/v2/index.d.ts +2 -1
  33. package/lib/v2/index.js +3 -1
  34. package/lib/v2/options.js +11 -11
  35. package/lib/v2/providers/alerts/alerts.js +4 -10
  36. package/lib/v2/providers/alerts/appDistribution.js +1 -1
  37. package/lib/v2/providers/alerts/billing.js +1 -1
  38. package/lib/v2/providers/alerts/crashlytics.js +1 -1
  39. package/lib/v2/providers/alerts/index.js +1 -5
  40. package/lib/v2/providers/https.d.ts +2 -20
  41. package/lib/v2/providers/https.js +4 -43
  42. package/lib/v2/providers/pubsub.js +2 -2
  43. package/lib/v2/providers/storage.js +3 -3
  44. package/lib/v2/providers/tasks.d.ts +22 -0
  45. package/lib/v2/providers/tasks.js +89 -0
  46. package/package.json +23 -13
@@ -0,0 +1,68 @@
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.onDispatchHandler = void 0;
25
+ const logger = require("../../logger");
26
+ const https = require("./https");
27
+ /** @internal */
28
+ function onDispatchHandler(handler) {
29
+ return async (req, res) => {
30
+ try {
31
+ if (!https.isValidRequest(req)) {
32
+ logger.error('Invalid request, unable to process.');
33
+ throw new https.HttpsError('invalid-argument', 'Bad Request');
34
+ }
35
+ const context = {};
36
+ const status = await https.checkAuthToken(req, context);
37
+ // Note: this should never happen since task queue functions are guarded by IAM.
38
+ if (status === 'INVALID') {
39
+ throw new https.HttpsError('unauthenticated', 'Unauthenticated');
40
+ }
41
+ const data = https.decode(req.body.data);
42
+ if (handler.length === 2) {
43
+ await handler(data, context);
44
+ }
45
+ else {
46
+ const arg = {
47
+ ...context,
48
+ data,
49
+ };
50
+ // For some reason the type system isn't picking up that the handler
51
+ // is a one argument function.
52
+ await handler(arg);
53
+ }
54
+ res.status(204).end();
55
+ }
56
+ catch (err) {
57
+ if (!(err instanceof https.HttpsError)) {
58
+ // This doesn't count as an 'explicit' error.
59
+ logger.error('Unhandled error', err);
60
+ err = new https.HttpsError('internal', 'INTERNAL');
61
+ }
62
+ const { status } = err.httpErrorCode;
63
+ const body = { error: err.toJSON() };
64
+ res.status(status).send(body);
65
+ }
66
+ };
67
+ }
68
+ exports.onDispatchHandler = onDispatchHandler;
@@ -9,6 +9,7 @@ import * as https from './providers/https';
9
9
  import * as pubsub from './providers/pubsub';
10
10
  import * as remoteConfig from './providers/remoteConfig';
11
11
  import * as storage from './providers/storage';
12
+ import * as tasks from './providers/tasks';
12
13
  import * as testLab from './providers/testLab';
13
14
  /**
14
15
  * Configure the regions that the function is deployed to.
@@ -78,12 +79,14 @@ export declare class FunctionBuilder {
78
79
  * @param handler A method that takes a data and context and returns a value.
79
80
  */
80
81
  onCall: (handler: (data: any, context: https.CallableContext) => any | Promise<any>) => import("./cloud-functions").TriggerAnnotated & import("./cloud-functions").EndpointAnnotated & ((req: express.Request<import("express-serve-static-core").ParamsDictionary>, resp: express.Response<any>) => void | Promise<void>) & import("./cloud-functions").Runnable<any>;
82
+ };
83
+ get tasks(): {
81
84
  /**
82
85
  * Declares a task queue function for clients to call using a Firebase Admin SDK.
83
86
  * @param options Configurations for the task queue function.
84
87
  */
85
88
  /** @hidden */
86
- taskQueue: (options?: https.TaskQueueOptions) => https.TaskQueueBuilder;
89
+ taskQueue: (options?: tasks.TaskQueueOptions) => tasks.TaskQueueBuilder;
87
90
  };
88
91
  get database(): {
89
92
  /**
@@ -32,6 +32,7 @@ const https = require("./providers/https");
32
32
  const pubsub = require("./providers/pubsub");
33
33
  const remoteConfig = require("./providers/remoteConfig");
34
34
  const storage = require("./providers/storage");
35
+ const tasks = require("./providers/tasks");
35
36
  const testLab = require("./providers/testLab");
36
37
  /**
37
38
  * Assert that the runtime options passed in are valid.
@@ -238,13 +239,17 @@ class FunctionBuilder {
238
239
  * @param handler A method that takes a data and context and returns a value.
239
240
  */
240
241
  onCall: (handler) => https._onCallWithOptions(handler, this.options),
242
+ };
243
+ }
244
+ get tasks() {
245
+ return {
241
246
  /**
242
247
  * Declares a task queue function for clients to call using a Firebase Admin SDK.
243
248
  * @param options Configurations for the task queue function.
244
249
  */
245
250
  /** @hidden */
246
251
  taskQueue: (options) => {
247
- return new https.TaskQueueBuilder(options, this.options);
252
+ return new tasks.TaskQueueBuilder(options, this.options);
248
253
  },
249
254
  };
250
255
  }
@@ -8,6 +8,7 @@ import * as https from './providers/https';
8
8
  import * as pubsub from './providers/pubsub';
9
9
  import * as remoteConfig from './providers/remoteConfig';
10
10
  import * as storage from './providers/storage';
11
+ import * as tasks from './providers/tasks';
11
12
  import * as testLab from './providers/testLab';
12
13
  /**
13
14
  * The `HandlerBuilder` class facilitates the writing of functions by developers
@@ -40,9 +41,19 @@ export declare class HandlerBuilder {
40
41
  get https(): {
41
42
  onRequest: (handler: (req: express.Request, resp: express.Response) => void) => HttpsFunction;
42
43
  onCall: (handler: (data: any, context: https.CallableContext) => any | Promise<any>) => HttpsFunction;
43
- /** @hidden */
44
+ };
45
+ /**
46
+ * Create a handler for tasks functions.
47
+ *
48
+ * @example
49
+ * ```javascript
50
+ * exports.myFunction = functions.handler.tasks.onDispatch((data, context) => { ... })
51
+ * ```
52
+ */
53
+ /** @hidden */
54
+ get tasks(): {
44
55
  readonly taskQueue: {
45
- onEnqueue(handler: (data: any, context: https.TaskContext) => void | Promise<void>): https.TaskQueueFunction;
56
+ onDispatch: (handler: (data: any, context: tasks.TaskContext) => void | Promise<void>) => HttpsFunction;
46
57
  };
47
58
  };
48
59
  /**
@@ -31,6 +31,7 @@ const https = require("./providers/https");
31
31
  const pubsub = require("./providers/pubsub");
32
32
  const remoteConfig = require("./providers/remoteConfig");
33
33
  const storage = require("./providers/storage");
34
+ const tasks = require("./providers/tasks");
34
35
  const testLab = require("./providers/testLab");
35
36
  /**
36
37
  * The `HandlerBuilder` class facilitates the writing of functions by developers
@@ -76,11 +77,23 @@ class HandlerBuilder {
76
77
  func.__requiredAPIs = undefined;
77
78
  return func;
78
79
  },
79
- /** @hidden */
80
+ };
81
+ }
82
+ /**
83
+ * Create a handler for tasks functions.
84
+ *
85
+ * @example
86
+ * ```javascript
87
+ * exports.myFunction = functions.handler.tasks.onDispatch((data, context) => { ... })
88
+ * ```
89
+ */
90
+ /** @hidden */
91
+ get tasks() {
92
+ return {
80
93
  get taskQueue() {
81
94
  return {
82
- onEnqueue(handler) {
83
- const builder = new https.TaskQueueBuilder();
95
+ onDispatch: (handler) => {
96
+ const builder = new tasks.TaskQueueBuilder();
84
97
  const func = builder.onDispatch(handler);
85
98
  func.__trigger = {};
86
99
  func.__endpoint = undefined;
@@ -128,12 +141,12 @@ class HandlerBuilder {
128
141
  get instance() {
129
142
  return {
130
143
  get ref() {
131
- return new database.RefBuilder((0, apps_1.apps)(), () => null, {});
144
+ return new database.RefBuilder(apps_1.apps(), () => null, {});
132
145
  },
133
146
  };
134
147
  },
135
148
  get ref() {
136
- return new database.RefBuilder((0, apps_1.apps)(), () => null, {});
149
+ return new database.RefBuilder(apps_1.apps(), () => null, {});
137
150
  },
138
151
  };
139
152
  }
package/lib/index.d.ts CHANGED
@@ -6,12 +6,13 @@ import * as https from './providers/https';
6
6
  import * as pubsub from './providers/pubsub';
7
7
  import * as remoteConfig from './providers/remoteConfig';
8
8
  import * as storage from './providers/storage';
9
+ import * as tasks from './providers/tasks';
9
10
  import * as testLab from './providers/testLab';
10
11
  import * as apps from './apps';
11
12
  import { handler } from './handler-builder';
12
13
  import * as logger from './logger';
13
14
  declare const app: apps.apps.Apps;
14
- export { analytics, app, auth, database, firestore, handler, https, pubsub, remoteConfig, storage, testLab, logger, };
15
+ export { analytics, app, auth, database, firestore, handler, https, pubsub, remoteConfig, storage, tasks, testLab, logger, };
15
16
  export * from './cloud-functions';
16
17
  export * from './config';
17
18
  export * from './function-builder';
package/lib/index.js CHANGED
@@ -22,11 +22,7 @@
22
22
  // SOFTWARE.
23
23
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
24
  if (k2 === undefined) k2 = k;
25
- var desc = Object.getOwnPropertyDescriptor(m, k);
26
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
- desc = { enumerable: true, get: function() { return m[k]; } };
28
- }
29
- Object.defineProperty(o, k2, desc);
25
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
30
26
  }) : (function(o, m, k, k2) {
31
27
  if (k2 === undefined) k2 = k;
32
28
  o[k2] = m[k];
@@ -35,7 +31,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
31
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
32
  };
37
33
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.logger = exports.testLab = exports.storage = exports.remoteConfig = exports.pubsub = exports.https = exports.handler = exports.firestore = exports.database = exports.auth = exports.app = exports.analytics = void 0;
34
+ exports.logger = exports.testLab = exports.tasks = exports.storage = exports.remoteConfig = exports.pubsub = exports.https = exports.handler = exports.firestore = exports.database = exports.auth = exports.app = exports.analytics = void 0;
39
35
  // Providers:
40
36
  const analytics = require("./providers/analytics");
41
37
  exports.analytics = analytics;
@@ -53,6 +49,8 @@ const remoteConfig = require("./providers/remoteConfig");
53
49
  exports.remoteConfig = remoteConfig;
54
50
  const storage = require("./providers/storage");
55
51
  exports.storage = storage;
52
+ const tasks = require("./providers/tasks");
53
+ exports.tasks = tasks;
56
54
  const testLab = require("./providers/testLab");
57
55
  exports.testLab = testLab;
58
56
  const apps = require("./apps");
@@ -68,4 +66,4 @@ __exportStar(require("./cloud-functions"), exports);
68
66
  __exportStar(require("./config"), exports);
69
67
  __exportStar(require("./function-builder"), exports);
70
68
  __exportStar(require("./function-configuration"), exports);
71
- (0, setup_1.setup)();
69
+ setup_1.setup();
@@ -6,7 +6,7 @@ const common_1 = require("./common");
6
6
  function patchedConsole(severity) {
7
7
  return function (data, ...args) {
8
8
  if (common_1.SUPPORTS_STRUCTURED_LOGS) {
9
- common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](JSON.stringify({ severity, message: (0, util_1.format)(data, ...args) }));
9
+ common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](JSON.stringify({ severity, message: util_1.format(data, ...args) }));
10
10
  return;
11
11
  }
12
12
  common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](data, ...args);
@@ -73,7 +73,7 @@ class AnalyticsEventBuilder {
73
73
  const dataConstructor = (raw) => {
74
74
  return new AnalyticsEvent(raw.data);
75
75
  };
76
- return (0, cloud_functions_1.makeCloudFunction)({
76
+ return cloud_functions_1.makeCloudFunction({
77
77
  handler,
78
78
  provider: exports.provider,
79
79
  eventType: 'event.log',
@@ -55,7 +55,7 @@ class UserBuilder {
55
55
  this.options = options;
56
56
  }
57
57
  static dataConstructor(raw) {
58
- return (0, identity_1.userRecordConstructor)(raw.data);
58
+ return identity_1.userRecordConstructor(raw.data);
59
59
  }
60
60
  /** Respond to the creation of a Firebase Auth user. */
61
61
  onCreate(handler) {
@@ -66,7 +66,7 @@ class UserBuilder {
66
66
  return this.onOperation(handler, 'user.delete');
67
67
  }
68
68
  onOperation(handler, eventType) {
69
- return (0, cloud_functions_1.makeCloudFunction)({
69
+ return cloud_functions_1.makeCloudFunction({
70
70
  handler,
71
71
  provider: exports.provider,
72
72
  eventType,
@@ -104,20 +104,20 @@ class InstanceBuilder {
104
104
  * @return Firebase Realtime Database reference builder interface.
105
105
  */
106
106
  ref(path) {
107
- const normalized = (0, path_1.normalizePath)(path);
108
- return new RefBuilder((0, apps_1.apps)(), () => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
107
+ const normalized = path_1.normalizePath(path);
108
+ return new RefBuilder(apps_1.apps(), () => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
109
109
  }
110
110
  }
111
111
  exports.InstanceBuilder = InstanceBuilder;
112
112
  /** @hidden */
113
113
  function _refWithOptions(path, options) {
114
114
  const resourceGetter = () => {
115
- const normalized = (0, path_1.normalizePath)(path);
116
- const databaseURL = (0, config_1.firebaseConfig)().databaseURL;
115
+ const normalized = path_1.normalizePath(path);
116
+ const databaseURL = config_1.firebaseConfig().databaseURL;
117
117
  if (!databaseURL) {
118
118
  throw new Error('Missing expected firebase config value databaseURL, ' +
119
119
  'config is actually' +
120
- JSON.stringify((0, config_1.firebaseConfig)()) +
120
+ JSON.stringify(config_1.firebaseConfig()) +
121
121
  '\n If you are unit testing, please set process.env.FIREBASE_CONFIG');
122
122
  }
123
123
  let instance;
@@ -136,7 +136,7 @@ function _refWithOptions(path, options) {
136
136
  }
137
137
  return `projects/_/instances/${instance}/refs/${normalized}`;
138
138
  };
139
- return new RefBuilder((0, apps_1.apps)(), resourceGetter, options);
139
+ return new RefBuilder(apps_1.apps(), resourceGetter, options);
140
140
  }
141
141
  exports._refWithOptions = _refWithOptions;
142
142
  /**
@@ -153,7 +153,7 @@ class RefBuilder {
153
153
  this.changeConstructor = (raw) => {
154
154
  const [dbInstance, path] = extractInstanceAndPath(raw.context.resource.name, raw.context.domain);
155
155
  const before = new DataSnapshot(raw.data.data, path, this.apps.admin, dbInstance);
156
- const after = new DataSnapshot((0, utils_1.applyChange)(raw.data.data, raw.data.delta), path, this.apps.admin, dbInstance);
156
+ const after = new DataSnapshot(utils_1.applyChange(raw.data.data, raw.data.delta), path, this.apps.admin, dbInstance);
157
157
  return {
158
158
  before,
159
159
  after,
@@ -214,7 +214,7 @@ class RefBuilder {
214
214
  return this.onOperation(handler, 'ref.delete', dataConstructor);
215
215
  }
216
216
  onOperation(handler, eventType, dataConstructor) {
217
- return (0, cloud_functions_1.makeCloudFunction)({
217
+ return cloud_functions_1.makeCloudFunction({
218
218
  handler,
219
219
  provider: exports.provider,
220
220
  service: exports.service,
@@ -311,7 +311,7 @@ class DataSnapshot {
311
311
  * However, accessing the key on the root URL of a Database will return `null`.
312
312
  */
313
313
  get key() {
314
- const last = _.last((0, path_1.pathParts)(this._fullPath()));
314
+ const last = _.last(path_1.pathParts(this._fullPath()));
315
315
  return !last || last === '' ? null : last;
316
316
  }
317
317
  /**
@@ -326,7 +326,7 @@ class DataSnapshot {
326
326
  * Array, string, number, boolean, or `null`).
327
327
  */
328
328
  val() {
329
- const parts = (0, path_1.pathParts)(this._childPath);
329
+ const parts = path_1.pathParts(this._childPath);
330
330
  const source = this._data;
331
331
  const node = _.cloneDeep(parts.length ? _.get(source, parts, null) : source);
332
332
  return this._checkAndConvertToArray(node);
@@ -494,7 +494,7 @@ class DataSnapshot {
494
494
  const dup = new DataSnapshot(this._data, undefined, this.app, this.instance);
495
495
  [dup._path, dup._childPath] = [this._path, this._childPath];
496
496
  if (childPath) {
497
- dup._childPath = (0, path_1.joinPath)(dup._childPath, childPath);
497
+ dup._childPath = path_1.joinPath(dup._childPath, childPath);
498
498
  }
499
499
  return dup;
500
500
  }
@@ -113,8 +113,8 @@ function _getValueProto(data, resource, valueFieldName) {
113
113
  }
114
114
  const proto = {
115
115
  fields: _.get(data, [valueFieldName, 'fields'], {}),
116
- createTime: (0, encoder_1.dateToTimestampProto)(_.get(data, [valueFieldName, 'createTime'])),
117
- updateTime: (0, encoder_1.dateToTimestampProto)(_.get(data, [valueFieldName, 'updateTime'])),
116
+ createTime: encoder_1.dateToTimestampProto(_.get(data, [valueFieldName, 'createTime'])),
117
+ updateTime: encoder_1.dateToTimestampProto(_.get(data, [valueFieldName, 'updateTime'])),
118
118
  name: _.get(data, [valueFieldName, 'name'], resource),
119
119
  };
120
120
  return proto;
@@ -123,7 +123,7 @@ function _getValueProto(data, resource, valueFieldName) {
123
123
  function snapshotConstructor(event) {
124
124
  var _a;
125
125
  if (!firestoreInstance) {
126
- firestoreInstance = firebase.firestore((0, apps_1.apps)().admin);
126
+ firestoreInstance = firebase.firestore(apps_1.apps().admin);
127
127
  }
128
128
  const valueProto = _getValueProto(event.data, event.context.resource.name, 'value');
129
129
  let timeString = (_a = _.get(event, 'data.value.readTime')) !== null && _a !== void 0 ? _a : _.get(event, 'data.value.updateTime');
@@ -131,7 +131,7 @@ function snapshotConstructor(event) {
131
131
  logger.warn('Snapshot has no readTime. Using now()');
132
132
  timeString = new Date().toISOString();
133
133
  }
134
- const readTime = (0, encoder_1.dateToTimestampProto)(timeString);
134
+ const readTime = encoder_1.dateToTimestampProto(timeString);
135
135
  return firestoreInstance.snapshot_(valueProto, readTime, 'json');
136
136
  }
137
137
  exports.snapshotConstructor = snapshotConstructor;
@@ -139,10 +139,10 @@ exports.snapshotConstructor = snapshotConstructor;
139
139
  // TODO remove this function when wire format changes to new format
140
140
  function beforeSnapshotConstructor(event) {
141
141
  if (!firestoreInstance) {
142
- firestoreInstance = firebase.firestore((0, apps_1.apps)().admin);
142
+ firestoreInstance = firebase.firestore(apps_1.apps().admin);
143
143
  }
144
144
  const oldValueProto = _getValueProto(event.data, event.context.resource.name, 'oldValue');
145
- const oldReadTime = (0, encoder_1.dateToTimestampProto)(_.get(event, 'data.oldValue.readTime'));
145
+ const oldReadTime = encoder_1.dateToTimestampProto(_.get(event, 'data.oldValue.readTime'));
146
146
  return firestoreInstance.snapshot_(oldValueProto, oldReadTime, 'json');
147
147
  }
148
148
  exports.beforeSnapshotConstructor = beforeSnapshotConstructor;
@@ -173,7 +173,7 @@ class DocumentBuilder {
173
173
  return this.onOperation(handler, 'document.delete', beforeSnapshotConstructor);
174
174
  }
175
175
  onOperation(handler, eventType, dataConstructor) {
176
- return (0, cloud_functions_1.makeCloudFunction)({
176
+ return cloud_functions_1.makeCloudFunction({
177
177
  handler,
178
178
  provider: exports.provider,
179
179
  eventType,
@@ -1,15 +1,8 @@
1
1
  import * as express from 'express';
2
2
  import { HttpsFunction, Runnable } from '../cloud-functions';
3
- import { ManifestEndpoint, ManifestRequiredAPI } from '../runtime/manifest';
4
- import { CallableContext, FunctionsErrorCode, HttpsError, Request, TaskContext, TaskRateLimits, TaskRetryConfig } from '../common/providers/https';
3
+ import { CallableContext, FunctionsErrorCode, HttpsError, Request } from '../common/providers/https';
5
4
  import { DeploymentOptions } from '../function-configuration';
6
- export { Request, CallableContext, FunctionsErrorCode, HttpsError,
7
- /** @hidden */
8
- TaskRetryConfig as TaskRetryPolicy,
9
- /** @hidden */
10
- TaskRateLimits,
11
- /** @hidden */
12
- TaskContext, };
5
+ export { Request, CallableContext, FunctionsErrorCode, HttpsError };
13
6
  /**
14
7
  * Handle HTTP requests.
15
8
  * @param handler A function that takes a request and response object,
@@ -21,41 +14,6 @@ export declare function onRequest(handler: (req: Request, resp: express.Response
21
14
  * @param handler A method that takes a data and context and returns a value.
22
15
  */
23
16
  export declare function onCall(handler: (data: any, context: CallableContext) => any | Promise<any>): HttpsFunction & Runnable<any>;
24
- /**
25
- * Configurations for Task Queue Functions.
26
- * @hidden
27
- */
28
- export interface TaskQueueOptions {
29
- retryConfig?: TaskRetryConfig;
30
- rateLimits?: TaskRateLimits;
31
- /**
32
- * Who can enqueue tasks for this function.
33
- * If left unspecified, only service accounts which have
34
- * roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
35
- * will have permissions.
36
- */
37
- invoker?: 'private' | string | string[];
38
- }
39
- /** @hidden */
40
- export interface TaskQueueFunction {
41
- (req: Request, res: express.Response): Promise<void>;
42
- __trigger: unknown;
43
- __endpoint: ManifestEndpoint;
44
- __requiredAPIs?: ManifestRequiredAPI[];
45
- run(data: any, context: TaskContext): void | Promise<void>;
46
- }
47
- /** @hidden */
48
- export declare class TaskQueueBuilder {
49
- private readonly tqOpts?;
50
- private readonly depOpts?;
51
- onDispatch(handler: (data: any, context: TaskContext) => void | Promise<void>): TaskQueueFunction;
52
- }
53
- /**
54
- * Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
55
- * @param options Configuration for the Task Queue that feeds into this function.
56
- * @hidden
57
- */
58
- export declare function taskQueue(options?: TaskQueueOptions): TaskQueueBuilder;
59
17
  /** @hidden */
60
18
  export declare function _onRequestWithOptions(handler: (req: Request, resp: express.Response) => void | Promise<void>, options: DeploymentOptions): HttpsFunction;
61
19
  /** @hidden */
@@ -21,7 +21,7 @@
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._onCallWithOptions = exports._onRequestWithOptions = exports.taskQueue = exports.TaskQueueBuilder = exports.onCall = exports.onRequest = exports.HttpsError = void 0;
24
+ exports._onCallWithOptions = exports._onRequestWithOptions = exports.onCall = exports.onRequest = exports.HttpsError = void 0;
25
25
  const cloud_functions_1 = require("../cloud-functions");
26
26
  const encoding_1 = require("../common/encoding");
27
27
  const https_1 = require("../common/providers/https");
@@ -44,71 +44,23 @@ function onCall(handler) {
44
44
  }
45
45
  exports.onCall = onCall;
46
46
  /** @hidden */
47
- class TaskQueueBuilder {
48
- /** @internal */
49
- constructor(tqOpts, depOpts) {
50
- this.tqOpts = tqOpts;
51
- this.depOpts = depOpts;
52
- }
53
- onDispatch(handler) {
54
- // onEnqueueHandler sniffs the function length of the passed-in callback
55
- // and the user could have only tried to listen to data. Wrap their handler
56
- // in another handler to avoid accidentally triggering the v2 API
57
- const fixedLen = (data, context) => handler(data, context);
58
- const func = (0, https_1.onDispatchHandler)(fixedLen);
59
- func.__trigger = {
60
- ...(0, cloud_functions_1.optionsToTrigger)(this.depOpts || {}),
61
- taskQueueTrigger: {},
62
- };
63
- (0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'retryConfig');
64
- (0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'rateLimits');
65
- (0, encoding_1.convertIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
66
- func.__endpoint = {
67
- platform: 'gcfv1',
68
- ...(0, cloud_functions_1.optionsToEndpoint)(this.depOpts),
69
- taskQueueTrigger: {},
70
- };
71
- (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'retryConfig');
72
- (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'rateLimits');
73
- (0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
74
- func.__requiredAPIs = [
75
- {
76
- api: 'cloudtasks.googleapis.com',
77
- reason: 'Needed for task queue functions',
78
- },
79
- ];
80
- func.run = handler;
81
- return func;
82
- }
83
- }
84
- exports.TaskQueueBuilder = TaskQueueBuilder;
85
- /**
86
- * Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
87
- * @param options Configuration for the Task Queue that feeds into this function.
88
- * @hidden
89
- */
90
- function taskQueue(options) {
91
- return new TaskQueueBuilder(options);
92
- }
93
- exports.taskQueue = taskQueue;
94
- /** @hidden */
95
47
  function _onRequestWithOptions(handler, options) {
96
48
  // lets us add __trigger without altering handler:
97
49
  const cloudFunction = (req, res) => {
98
50
  return handler(req, res);
99
51
  };
100
52
  cloudFunction.__trigger = {
101
- ...(0, cloud_functions_1.optionsToTrigger)(options),
53
+ ...cloud_functions_1.optionsToTrigger(options),
102
54
  httpsTrigger: {},
103
55
  };
104
- (0, encoding_1.convertIfPresent)(cloudFunction.__trigger.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
56
+ encoding_1.convertIfPresent(cloudFunction.__trigger.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
105
57
  // TODO parse the options
106
58
  cloudFunction.__endpoint = {
107
59
  platform: 'gcfv1',
108
- ...(0, cloud_functions_1.optionsToEndpoint)(options),
60
+ ...cloud_functions_1.optionsToEndpoint(options),
109
61
  httpsTrigger: {},
110
62
  };
111
- (0, encoding_1.convertIfPresent)(cloudFunction.__endpoint.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
63
+ encoding_1.convertIfPresent(cloudFunction.__endpoint.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
112
64
  return cloudFunction;
113
65
  }
114
66
  exports._onRequestWithOptions = _onRequestWithOptions;
@@ -118,20 +70,20 @@ function _onCallWithOptions(handler, options) {
118
70
  // and the user could have only tried to listen to data. Wrap their handler
119
71
  // in another handler to avoid accidentally triggering the v2 API
120
72
  const fixedLen = (data, context) => handler(data, context);
121
- const func = (0, https_1.onCallHandler)({
73
+ const func = https_1.onCallHandler({
122
74
  allowInvalidAppCheckToken: options.allowInvalidAppCheckToken,
123
75
  cors: { origin: true, methods: 'POST' },
124
76
  }, fixedLen);
125
77
  func.__trigger = {
126
78
  labels: {},
127
- ...(0, cloud_functions_1.optionsToTrigger)(options),
79
+ ...cloud_functions_1.optionsToTrigger(options),
128
80
  httpsTrigger: {},
129
81
  };
130
82
  func.__trigger.labels['deployment-callable'] = 'true';
131
83
  func.__endpoint = {
132
84
  platform: 'gcfv1',
133
85
  labels: {},
134
- ...(0, cloud_functions_1.optionsToEndpoint)(options),
86
+ ...cloud_functions_1.optionsToEndpoint(options),
135
87
  callableTrigger: {},
136
88
  };
137
89
  func.run = handler;
@@ -71,7 +71,7 @@ class TopicBuilder {
71
71
  * @return A Cloud Function that you can export and deploy.
72
72
  */
73
73
  onPublish(handler) {
74
- return (0, cloud_functions_1.makeCloudFunction)({
74
+ return cloud_functions_1.makeCloudFunction({
75
75
  handler,
76
76
  provider: exports.provider,
77
77
  service: exports.service,
@@ -140,7 +140,7 @@ class ScheduleBuilder {
140
140
  * @return A Cloud Function that you can export and deploy.
141
141
  */
142
142
  onRun(handler) {
143
- const cloudFunction = (0, cloud_functions_1.makeCloudFunction)({
143
+ const cloudFunction = cloud_functions_1.makeCloudFunction({
144
144
  contextOnlyHandler: handler,
145
145
  provider: exports.provider,
146
146
  service: exports.service,
@@ -65,7 +65,7 @@ class UpdateBuilder {
65
65
  * version metadata as an argument.
66
66
  */
67
67
  onUpdate(handler) {
68
- return (0, cloud_functions_1.makeCloudFunction)({
68
+ return cloud_functions_1.makeCloudFunction({
69
69
  handler,
70
70
  provider: exports.provider,
71
71
  service: exports.service,
@@ -53,7 +53,7 @@ exports.object = object;
53
53
  /** @hidden */
54
54
  function _bucketWithOptions(options, bucket) {
55
55
  const resourceGetter = () => {
56
- bucket = bucket || (0, config_1.firebaseConfig)().storageBucket;
56
+ bucket = bucket || config_1.firebaseConfig().storageBucket;
57
57
  if (!bucket) {
58
58
  throw new Error('Missing bucket name. If you are unit testing, please provide a bucket name' +
59
59
  ' through `functions.storage.bucket(bucketName)`, or set process.env.FIREBASE_CONFIG.');
@@ -170,7 +170,7 @@ class ObjectBuilder {
170
170
  }
171
171
  /** @hidden */
172
172
  onOperation(handler, eventType) {
173
- return (0, cloud_functions_1.makeCloudFunction)({
173
+ return cloud_functions_1.makeCloudFunction({
174
174
  handler,
175
175
  provider: exports.provider,
176
176
  service: exports.service,