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,46 @@
1
+ import * as express from 'express';
2
+ import { Request } from '../common/providers/https';
3
+ import { ManifestEndpoint, ManifestRequiredAPI } from '../runtime/manifest';
4
+ import { TaskContext, RateLimits, RetryConfig } from '../common/providers/tasks';
5
+ export {
6
+ /** @hidden */
7
+ RetryConfig as RetryPolicy,
8
+ /** @hidden */
9
+ RateLimits,
10
+ /** @hidden */
11
+ TaskContext, };
12
+ /**
13
+ * Configurations for Task Queue Functions.
14
+ * @hidden
15
+ */
16
+ export interface TaskQueueOptions {
17
+ retryConfig?: RetryConfig;
18
+ rateLimits?: RateLimits;
19
+ /**
20
+ * Who can enqueue tasks for this function.
21
+ * If left unspecified, only service accounts which have
22
+ * roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
23
+ * will have permissions.
24
+ */
25
+ invoker?: 'private' | string | string[];
26
+ }
27
+ /** @hidden */
28
+ export interface TaskQueueFunction {
29
+ (req: Request, res: express.Response): Promise<void>;
30
+ __trigger: unknown;
31
+ __endpoint: ManifestEndpoint;
32
+ __requiredAPIs?: ManifestRequiredAPI[];
33
+ run(data: any, context: TaskContext): void | Promise<void>;
34
+ }
35
+ /** @hidden */
36
+ export declare class TaskQueueBuilder {
37
+ private readonly tqOpts?;
38
+ private readonly depOpts?;
39
+ onDispatch(handler: (data: any, context: TaskContext) => void | Promise<void>): TaskQueueFunction;
40
+ }
41
+ /**
42
+ * Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
43
+ * @param options Configuration for the Task Queue that feeds into this function.
44
+ * @hidden
45
+ */
46
+ export declare function taskQueue(options?: TaskQueueOptions): TaskQueueBuilder;
@@ -0,0 +1,75 @@
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.taskQueue = exports.TaskQueueBuilder = void 0;
25
+ const cloud_functions_1 = require("../cloud-functions");
26
+ const encoding_1 = require("../common/encoding");
27
+ const tasks_1 = require("../common/providers/tasks");
28
+ /** @hidden */
29
+ class TaskQueueBuilder {
30
+ /** @internal */
31
+ constructor(tqOpts, depOpts) {
32
+ this.tqOpts = tqOpts;
33
+ this.depOpts = depOpts;
34
+ }
35
+ onDispatch(handler) {
36
+ // onEnqueueHandler sniffs the function length of the passed-in callback
37
+ // and the user could have only tried to listen to data. Wrap their handler
38
+ // in another handler to avoid accidentally triggering the v2 API
39
+ const fixedLen = (data, context) => handler(data, context);
40
+ const func = tasks_1.onDispatchHandler(fixedLen);
41
+ func.__trigger = {
42
+ ...cloud_functions_1.optionsToTrigger(this.depOpts || {}),
43
+ taskQueueTrigger: {},
44
+ };
45
+ encoding_1.copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'retryConfig');
46
+ encoding_1.copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'rateLimits');
47
+ encoding_1.convertIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
48
+ func.__endpoint = {
49
+ platform: 'gcfv1',
50
+ ...cloud_functions_1.optionsToEndpoint(this.depOpts),
51
+ taskQueueTrigger: {},
52
+ };
53
+ encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, 'retryConfig');
54
+ encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, 'rateLimits');
55
+ encoding_1.convertIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
56
+ func.__requiredAPIs = [
57
+ {
58
+ api: 'cloudtasks.googleapis.com',
59
+ reason: 'Needed for task queue functions',
60
+ },
61
+ ];
62
+ func.run = handler;
63
+ return func;
64
+ }
65
+ }
66
+ exports.TaskQueueBuilder = TaskQueueBuilder;
67
+ /**
68
+ * Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
69
+ * @param options Configuration for the Task Queue that feeds into this function.
70
+ * @hidden
71
+ */
72
+ function taskQueue(options) {
73
+ return new TaskQueueBuilder(options);
74
+ }
75
+ exports.taskQueue = taskQueue;
@@ -57,7 +57,7 @@ class TestMatrixBuilder {
57
57
  const dataConstructor = (raw) => {
58
58
  return new TestMatrix(raw.data);
59
59
  };
60
- return (0, cloud_functions_1.makeCloudFunction)({
60
+ return cloud_functions_1.makeCloudFunction({
61
61
  provider: exports.PROVIDER,
62
62
  eventType: exports.TEST_MATRIX_COMPLETE_EVENT_TYPE,
63
63
  triggerResource: this.triggerResource,
@@ -1,11 +1,3 @@
1
- /**
2
- * One or more event filters restrict the set of events delivered to an EventTrigger.
3
- */
4
- interface EventFilter {
5
- attribute: string;
6
- value: string;
7
- operator?: string;
8
- }
9
1
  /**
10
2
  * An definition of a function as appears in the Manifest.
11
3
  */
@@ -35,7 +27,9 @@ export interface ManifestEndpoint {
35
27
  };
36
28
  callableTrigger?: {};
37
29
  eventTrigger?: {
38
- eventFilters: EventFilter[];
30
+ eventFilters: Record<string, string>;
31
+ eventFilterPathPatterns?: Record<string, string>;
32
+ channel?: string;
39
33
  eventType: string;
40
34
  retry: boolean;
41
35
  region?: string;
@@ -65,4 +59,3 @@ export interface ManifestStack {
65
59
  requiredAPIs: ManifestRequiredAPI[];
66
60
  endpoints: Record<string, ManifestEndpoint>;
67
61
  }
68
- export {};
@@ -1,2 +1,23 @@
1
1
  "use strict";
2
+ // The MIT License (MIT)
3
+ //
4
+ // Copyright (c) 2021 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
14
+ // all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ // SOFTWARE.
2
23
  Object.defineProperty(exports, "__esModule", { value: true });
package/lib/setup.js CHANGED
@@ -31,7 +31,7 @@ function setup() {
31
31
  // Until the Cloud Functions builder can publish FIREBASE_CONFIG, automatically provide it on import based on what
32
32
  // we can deduce.
33
33
  if (!process.env.FIREBASE_CONFIG) {
34
- const cfg = (0, config_1.firebaseConfig)();
34
+ const cfg = config_1.firebaseConfig();
35
35
  if (cfg) {
36
36
  process.env.FIREBASE_CONFIG = JSON.stringify(cfg);
37
37
  }
@@ -43,7 +43,7 @@ function setup() {
43
43
  // If FIREBASE_CONFIG is still not found, try using GCLOUD_PROJECT to estimate
44
44
  if (!process.env.FIREBASE_CONFIG) {
45
45
  if (process.env.GCLOUD_PROJECT) {
46
- (0, logger_1.warn)('Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail');
46
+ logger_1.warn('Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail');
47
47
  process.env.FIREBASE_CONFIG = JSON.stringify({
48
48
  databaseURL: process.env.DATABASE_URL ||
49
49
  `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
@@ -53,7 +53,7 @@ function setup() {
53
53
  });
54
54
  }
55
55
  else {
56
- (0, logger_1.warn)('Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail');
56
+ logger_1.warn('Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail');
57
57
  }
58
58
  }
59
59
  }
package/lib/v2/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import * as alerts from './providers/alerts';
4
4
  import * as https from './providers/https';
5
5
  import * as pubsub from './providers/pubsub';
6
6
  import * as storage from './providers/storage';
7
- export { https, pubsub, storage, logger, params, alerts };
7
+ import * as tasks from './providers/tasks';
8
+ export { alerts, https, pubsub, storage, logger, params, tasks };
8
9
  export { setGlobalOptions, GlobalOptions } from './options';
9
10
  export { CloudFunction, CloudEvent } from './core';
package/lib/v2/index.js CHANGED
@@ -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.setGlobalOptions = exports.alerts = exports.params = exports.logger = exports.storage = exports.pubsub = exports.https = void 0;
24
+ exports.setGlobalOptions = exports.tasks = exports.params = exports.logger = exports.storage = exports.pubsub = exports.https = exports.alerts = void 0;
25
25
  const logger = require("../logger");
26
26
  exports.logger = logger;
27
27
  const params = require("./params");
@@ -34,5 +34,7 @@ const pubsub = require("./providers/pubsub");
34
34
  exports.pubsub = pubsub;
35
35
  const storage = require("./providers/storage");
36
36
  exports.storage = storage;
37
+ const tasks = require("./providers/tasks");
38
+ exports.tasks = tasks;
37
39
  var options_1 = require("./options");
38
40
  Object.defineProperty(exports, "setGlobalOptions", { enumerable: true, get: function () { return options_1.setGlobalOptions; } });
package/lib/v2/options.js CHANGED
@@ -120,19 +120,19 @@ exports.getGlobalOptions = getGlobalOptions;
120
120
  */
121
121
  function optionsToTriggerAnnotations(opts) {
122
122
  const annotation = {};
123
- (0, encoding_1.copyIfPresent)(annotation, opts, 'concurrency', 'minInstances', 'maxInstances', 'ingressSettings', 'labels', 'vpcConnector', 'vpcConnectorEgressSettings');
124
- (0, encoding_1.convertIfPresent)(annotation, opts, 'availableMemoryMb', 'memory', (mem) => {
123
+ encoding_1.copyIfPresent(annotation, opts, 'concurrency', 'minInstances', 'maxInstances', 'ingressSettings', 'labels', 'vpcConnector', 'vpcConnectorEgressSettings');
124
+ encoding_1.convertIfPresent(annotation, opts, 'availableMemoryMb', 'memory', (mem) => {
125
125
  return MemoryOptionToMB[mem];
126
126
  });
127
- (0, encoding_1.convertIfPresent)(annotation, opts, 'regions', 'region', (region) => {
127
+ encoding_1.convertIfPresent(annotation, opts, 'regions', 'region', (region) => {
128
128
  if (typeof region === 'string') {
129
129
  return [region];
130
130
  }
131
131
  return region;
132
132
  });
133
- (0, encoding_1.convertIfPresent)(annotation, opts, 'serviceAccountEmail', 'serviceAccount', encoding_1.serviceAccountFromShorthand);
134
- (0, encoding_1.convertIfPresent)(annotation, opts, 'timeout', 'timeoutSeconds', encoding_1.durationFromSeconds);
135
- (0, encoding_1.convertIfPresent)(annotation, opts, 'failurePolicy', 'retry', (retry) => {
133
+ encoding_1.convertIfPresent(annotation, opts, 'serviceAccountEmail', 'serviceAccount', encoding_1.serviceAccountFromShorthand);
134
+ encoding_1.convertIfPresent(annotation, opts, 'timeout', 'timeoutSeconds', encoding_1.durationFromSeconds);
135
+ encoding_1.convertIfPresent(annotation, opts, 'failurePolicy', 'retry', (retry) => {
136
136
  return retry ? { retry: true } : null;
137
137
  });
138
138
  return annotation;
@@ -144,14 +144,14 @@ exports.optionsToTriggerAnnotations = optionsToTriggerAnnotations;
144
144
  */
145
145
  function optionsToEndpoint(opts) {
146
146
  const endpoint = {};
147
- (0, encoding_1.copyIfPresent)(endpoint, opts, 'concurrency', 'minInstances', 'maxInstances', 'ingressSettings', 'labels', 'timeoutSeconds');
148
- (0, encoding_1.convertIfPresent)(endpoint, opts, 'serviceAccountEmail', 'serviceAccount');
147
+ encoding_1.copyIfPresent(endpoint, opts, 'concurrency', 'minInstances', 'maxInstances', 'ingressSettings', 'labels', 'timeoutSeconds');
148
+ encoding_1.convertIfPresent(endpoint, opts, 'serviceAccountEmail', 'serviceAccount');
149
149
  if (opts.vpcConnector) {
150
150
  const vpc = { connector: opts.vpcConnector };
151
- (0, encoding_1.convertIfPresent)(vpc, opts, 'egressSettings', 'vpcConnectorEgressSettings');
151
+ encoding_1.convertIfPresent(vpc, opts, 'egressSettings', 'vpcConnectorEgressSettings');
152
152
  endpoint.vpc = vpc;
153
153
  }
154
- (0, encoding_1.convertIfPresent)(endpoint, opts, 'availableMemoryMb', 'memory', (mem) => {
154
+ encoding_1.convertIfPresent(endpoint, opts, 'availableMemoryMb', 'memory', (mem) => {
155
155
  const memoryLookup = {
156
156
  '128MB': 128,
157
157
  '256MB': 256,
@@ -163,7 +163,7 @@ function optionsToEndpoint(opts) {
163
163
  };
164
164
  return memoryLookup[mem];
165
165
  });
166
- (0, encoding_1.convertIfPresent)(endpoint, opts, 'region', 'region', (region) => {
166
+ encoding_1.convertIfPresent(endpoint, opts, 'region', 'region', (region) => {
167
167
  if (typeof region === 'string') {
168
168
  return [region];
169
169
  }
@@ -36,20 +36,14 @@ function getEndpointAnnotation(opts, alertType, appId) {
36
36
  },
37
37
  eventTrigger: {
38
38
  eventType: exports.eventType,
39
- eventFilters: [
40
- {
41
- attribute: 'alerttype',
42
- value: alertType,
43
- },
44
- ],
39
+ eventFilters: {
40
+ alerttype: alertType,
41
+ },
45
42
  retry: !!opts.retry,
46
43
  },
47
44
  };
48
45
  if (appId) {
49
- endpoint.eventTrigger.eventFilters.push({
50
- attribute: 'appid',
51
- value: appId,
52
- });
46
+ endpoint.eventTrigger.eventFilters.appid = appId;
53
47
  }
54
48
  return endpoint;
55
49
  }
@@ -14,7 +14,7 @@ function onNewTesterIosDevicePublished(appIdOrOptsOrHandler, handler) {
14
14
  return handler(raw);
15
15
  };
16
16
  func.run = handler;
17
- func.__endpoint = (0, alerts_1.getEndpointAnnotation)(opts, exports.newTesterIosDeviceAlert, appId);
17
+ func.__endpoint = alerts_1.getEndpointAnnotation(opts, exports.newTesterIosDeviceAlert, appId);
18
18
  return func;
19
19
  }
20
20
  exports.onNewTesterIosDevicePublished = onNewTesterIosDevicePublished;
@@ -24,7 +24,7 @@ function onOperation(alertType, optsOrHandler, handler) {
24
24
  return handler(raw);
25
25
  };
26
26
  func.run = handler;
27
- func.__endpoint = (0, _1.getEndpointAnnotation)(optsOrHandler, alertType);
27
+ func.__endpoint = _1.getEndpointAnnotation(optsOrHandler, alertType);
28
28
  return func;
29
29
  }
30
30
  exports.onOperation = onOperation;
@@ -49,7 +49,7 @@ function onOperation(alertType, appIdOrOptsOrHandler, handler) {
49
49
  return handler(raw);
50
50
  };
51
51
  func.run = handler;
52
- func.__endpoint = (0, _1.getEndpointAnnotation)(opts, alertType, appId);
52
+ func.__endpoint = _1.getEndpointAnnotation(opts, alertType, appId);
53
53
  return func;
54
54
  }
55
55
  exports.onOperation = onOperation;
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -1,23 +1,12 @@
1
1
  import * as express from 'express';
2
2
  import * as options from '../options';
3
- import { CallableRequest, FunctionsErrorCode, HttpsError, Request, TaskRateLimits, TaskRequest, TaskRetryConfig } from '../../common/providers/https';
3
+ import { CallableRequest, FunctionsErrorCode, HttpsError, Request } from '../../common/providers/https';
4
4
  import { ManifestEndpoint } from '../../runtime/manifest';
5
- export { Request, CallableRequest, FunctionsErrorCode, HttpsError, TaskRateLimits, TaskRequest, TaskRetryConfig as TaskRetryPolicy, };
5
+ export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
6
6
  export interface HttpsOptions extends Omit<options.GlobalOptions, 'region'> {
7
7
  region?: options.SupportedRegion | string | Array<options.SupportedRegion | string>;
8
8
  cors?: string | boolean | RegExp | Array<string | RegExp>;
9
9
  }
10
- export interface TaskQueueOptions extends options.GlobalOptions {
11
- retryConfig?: TaskRetryConfig;
12
- rateLimits?: TaskRateLimits;
13
- /**
14
- * Who can enqueue tasks for this function.
15
- * If left unspecified, only service accounts which have
16
- * roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
17
- * will have permissions.
18
- */
19
- invoker?: 'private' | string | string[];
20
- }
21
10
  export declare type HttpsFunction = ((req: Request, res: express.Response) => void | Promise<void>) & {
22
11
  __trigger?: unknown;
23
12
  __endpoint: ManifestEndpoint;
@@ -25,14 +14,7 @@ export declare type HttpsFunction = ((req: Request, res: express.Response) => vo
25
14
  export interface CallableFunction<T, Return> extends HttpsFunction {
26
15
  run(data: CallableRequest<T>): Return;
27
16
  }
28
- export interface TaskQueueFunction<T = any> extends HttpsFunction {
29
- run(data: TaskRequest<T>): void | Promise<void>;
30
- }
31
17
  export declare function onRequest(opts: HttpsOptions, handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
32
18
  export declare function onRequest(handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
33
19
  export declare function onCall<T = any, Return = any | Promise<any>>(opts: HttpsOptions, handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
34
20
  export declare function onCall<T = any, Return = any | Promise<any>>(handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
35
- /** Handle a request sent to a Cloud Tasks queue. */
36
- export declare function onTaskDispatched<Args = any>(handler: (request: TaskRequest<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
37
- /** Handle a request sent to a Cloud Tasks queue. */
38
- export declare function onTaskDispatched<Args = any>(options: TaskQueueOptions, handler: (request: TaskRequest<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
@@ -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.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
27
  const options = require("../options");
@@ -68,7 +68,7 @@ function onRequest(optsOrHandler, handler) {
68
68
  allowInsecure: false,
69
69
  },
70
70
  };
71
- (0, encoding_1.convertIfPresent)(trigger.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
71
+ encoding_1.convertIfPresent(trigger.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
72
72
  return trigger;
73
73
  },
74
74
  });
@@ -86,7 +86,7 @@ function onRequest(optsOrHandler, handler) {
86
86
  },
87
87
  httpsTrigger: {},
88
88
  };
89
- (0, encoding_1.convertIfPresent)(endpoint.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
89
+ encoding_1.convertIfPresent(endpoint.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
90
90
  handler.__endpoint = endpoint;
91
91
  return handler;
92
92
  }
@@ -104,7 +104,7 @@ function onCall(optsOrHandler, handler) {
104
104
  // onCallHandler sniffs the function length to determine which API to present.
105
105
  // fix the length to prevent api versions from being mismatched.
106
106
  const fixedLen = (req) => handler(req);
107
- const func = (0, https_1.onCallHandler)({ cors: { origin, methods: 'POST' } }, fixedLen);
107
+ const func = https_1.onCallHandler({ cors: { origin, methods: 'POST' } }, fixedLen);
108
108
  Object.defineProperty(func, '__trigger', {
109
109
  get: () => {
110
110
  const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
@@ -147,42 +147,3 @@ function onCall(optsOrHandler, handler) {
147
147
  return func;
148
148
  }
149
149
  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;
@@ -104,11 +104,11 @@ function onMessagePublished(topicOrOptions, handler) {
104
104
  },
105
105
  eventTrigger: {
106
106
  eventType: 'google.cloud.pubsub.topic.v1.messagePublished',
107
- eventFilters: [{ attribute: 'topic', value: topic }],
107
+ eventFilters: { topic },
108
108
  retry: false,
109
109
  },
110
110
  };
111
- (0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, 'retry', 'retry');
111
+ encoding_1.copyIfPresent(endpoint.eventTrigger, opts, 'retry', 'retry');
112
112
  func.__endpoint = endpoint;
113
113
  return func;
114
114
  }
@@ -99,11 +99,11 @@ 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
  };
106
- (0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, 'retry', 'retry');
106
+ encoding_1.copyIfPresent(endpoint.eventTrigger, opts, 'retry', 'retry');
107
107
  return endpoint;
108
108
  },
109
109
  });
@@ -119,7 +119,7 @@ function getOptsAndBucket(bucketOrOpts) {
119
119
  opts = {};
120
120
  }
121
121
  else {
122
- bucket = bucketOrOpts.bucket || (0, config_1.firebaseConfig)().storageBucket;
122
+ bucket = bucketOrOpts.bucket || config_1.firebaseConfig().storageBucket;
123
123
  opts = { ...bucketOrOpts };
124
124
  delete opts.bucket;
125
125
  }
@@ -0,0 +1,22 @@
1
+ import * as options from '../options';
2
+ 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 {
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,89 @@
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 options = require("../options");
26
+ const encoding_1 = require("../../common/encoding");
27
+ const tasks_1 = require("../../common/providers/tasks");
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 = 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
+ encoding_1.copyIfPresent(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
49
+ encoding_1.convertIfPresent(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
50
+ return {
51
+ apiVersion: 2,
52
+ platform: 'gcfv2',
53
+ ...baseOpts,
54
+ ...specificOpts,
55
+ labels: {
56
+ ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
57
+ ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
58
+ },
59
+ taskQueueTrigger,
60
+ };
61
+ },
62
+ });
63
+ const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
64
+ // global options calls region a scalar and https allows it to be an array,
65
+ // but optionsToManifestEndpoint handles both cases.
66
+ const specificOpts = options.optionsToEndpoint(opts);
67
+ func.__endpoint = {
68
+ platform: 'gcfv2',
69
+ ...baseOpts,
70
+ ...specificOpts,
71
+ labels: {
72
+ ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
73
+ ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
74
+ },
75
+ taskQueueTrigger: {},
76
+ };
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
+ func.__requiredAPIs = [
81
+ {
82
+ api: 'cloudtasks.googleapis.com',
83
+ reason: 'Needed for task queue functions',
84
+ },
85
+ ];
86
+ func.run = handler;
87
+ return func;
88
+ }
89
+ exports.onTaskDispatched = onTaskDispatched;