firebase-functions 3.24.1 → 4.0.0-rc.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 (130) hide show
  1. package/README.md +7 -9
  2. package/lib/bin/firebase-functions.js +13 -15
  3. package/lib/common/app.d.ts +14 -0
  4. package/lib/common/app.js +62 -0
  5. package/lib/common/change.d.ts +0 -5
  6. package/lib/common/change.js +5 -7
  7. package/lib/common/config.d.ts +6 -0
  8. package/lib/common/config.js +49 -0
  9. package/lib/common/debug.js +2 -2
  10. package/lib/common/encoding.d.ts +0 -8
  11. package/lib/common/encoding.js +6 -29
  12. package/lib/common/options.d.ts +14 -0
  13. package/lib/common/options.js +44 -0
  14. package/lib/common/params.d.ts +32 -0
  15. package/lib/common/params.js +23 -0
  16. package/lib/common/providers/database.d.ts +17 -19
  17. package/lib/common/providers/database.js +68 -39
  18. package/lib/common/providers/https.d.ts +11 -52
  19. package/lib/common/providers/https.js +115 -110
  20. package/lib/common/providers/identity.d.ts +8 -8
  21. package/lib/common/providers/identity.js +71 -79
  22. package/lib/common/providers/tasks.d.ts +11 -10
  23. package/lib/common/providers/tasks.js +10 -9
  24. package/lib/common/timezone.js +538 -538
  25. package/lib/common/trace.d.ts +14 -0
  26. package/lib/common/trace.js +69 -0
  27. package/lib/{encoder.d.ts → common/utilities/encoder.d.ts} +0 -0
  28. package/lib/{encoder.js → common/utilities/encoder.js} +1 -1
  29. package/lib/{utilities → common/utilities}/path-pattern.d.ts +0 -0
  30. package/lib/{utilities → common/utilities}/path-pattern.js +17 -16
  31. package/lib/{utilities → common/utilities}/path.d.ts +0 -0
  32. package/lib/{utilities → common/utilities}/path.js +5 -7
  33. package/lib/{utils.d.ts → common/utilities/utils.d.ts} +1 -1
  34. package/lib/{utils.js → common/utilities/utils.js} +18 -12
  35. package/lib/logger/common.d.ts +1 -3
  36. package/lib/logger/common.js +9 -14
  37. package/lib/logger/compat.js +9 -9
  38. package/lib/logger/index.d.ts +1 -1
  39. package/lib/logger/index.js +24 -30
  40. package/lib/{v2/params → params}/index.d.ts +22 -9
  41. package/lib/{v2/params → params}/index.js +22 -14
  42. package/lib/params/types.d.ts +180 -0
  43. package/lib/params/types.js +289 -0
  44. package/lib/runtime/loader.js +12 -14
  45. package/lib/runtime/manifest.d.ts +56 -24
  46. package/lib/runtime/manifest.js +114 -4
  47. package/lib/v1/cloud-functions.d.ts +232 -0
  48. package/lib/v1/cloud-functions.js +205 -0
  49. package/lib/v1/config.d.ts +8 -0
  50. package/lib/v1/config.js +75 -0
  51. package/lib/{function-builder.d.ts → v1/function-builder.d.ts} +16 -16
  52. package/lib/{function-builder.js → v1/function-builder.js} +56 -46
  53. package/lib/v1/function-configuration.d.ts +197 -0
  54. package/lib/v1/function-configuration.js +70 -0
  55. package/lib/v1/index.d.ts +20 -0
  56. package/lib/{index.js → v1/index.js} +5 -10
  57. package/lib/{providers → v1/providers}/analytics.d.ts +5 -11
  58. package/lib/{providers → v1/providers}/analytics.js +49 -43
  59. package/lib/{providers → v1/providers}/auth.d.ts +28 -18
  60. package/lib/{providers → v1/providers}/auth.js +45 -34
  61. package/lib/{providers → v1/providers}/database.d.ts +25 -42
  62. package/lib/{providers → v1/providers}/database.js +46 -46
  63. package/lib/{providers → v1/providers}/firestore.d.ts +15 -33
  64. package/lib/{providers → v1/providers}/firestore.js +40 -44
  65. package/lib/{providers → v1/providers}/https.d.ts +3 -8
  66. package/lib/{providers → v1/providers}/https.js +14 -22
  67. package/lib/{providers → v1/providers}/pubsub.d.ts +8 -16
  68. package/lib/{providers → v1/providers}/pubsub.js +22 -26
  69. package/lib/{providers → v1/providers}/remoteConfig.d.ts +2 -11
  70. package/lib/{providers → v1/providers}/remoteConfig.js +9 -9
  71. package/lib/{providers → v1/providers}/storage.d.ts +11 -26
  72. package/lib/{providers → v1/providers}/storage.js +24 -29
  73. package/lib/{providers → v1/providers}/tasks.d.ts +6 -8
  74. package/lib/{providers → v1/providers}/tasks.js +12 -17
  75. package/lib/{providers → v1/providers}/testLab.d.ts +86 -46
  76. package/lib/{providers → v1/providers}/testLab.js +14 -14
  77. package/lib/v2/core.d.ts +4 -5
  78. package/lib/v2/index.d.ts +16 -14
  79. package/lib/v2/index.js +5 -1
  80. package/lib/v2/options.d.ts +52 -32
  81. package/lib/v2/options.js +32 -47
  82. package/lib/v2/providers/alerts/alerts.d.ts +20 -18
  83. package/lib/v2/providers/alerts/alerts.js +9 -6
  84. package/lib/v2/providers/alerts/appDistribution.d.ts +28 -26
  85. package/lib/v2/providers/alerts/appDistribution.js +8 -7
  86. package/lib/v2/providers/alerts/billing.d.ts +5 -5
  87. package/lib/v2/providers/alerts/billing.js +5 -4
  88. package/lib/v2/providers/alerts/crashlytics.d.ts +32 -30
  89. package/lib/v2/providers/alerts/crashlytics.js +10 -9
  90. package/lib/v2/providers/alerts/index.d.ts +5 -5
  91. package/lib/v2/providers/alerts/performance.d.ts +3 -3
  92. package/lib/v2/providers/alerts/performance.js +5 -7
  93. package/lib/v2/providers/database.d.ts +41 -38
  94. package/lib/v2/providers/database.js +22 -17
  95. package/lib/v2/providers/eventarc.d.ts +25 -23
  96. package/lib/v2/providers/eventarc.js +10 -7
  97. package/lib/v2/providers/https.d.ts +43 -33
  98. package/lib/v2/providers/https.js +18 -56
  99. package/lib/v2/providers/identity.d.ts +25 -23
  100. package/lib/v2/providers/identity.js +10 -7
  101. package/lib/v2/providers/pubsub.d.ts +25 -23
  102. package/lib/v2/providers/pubsub.js +11 -27
  103. package/lib/v2/providers/remoteConfig.d.ts +63 -0
  104. package/lib/v2/providers/remoteConfig.js +65 -0
  105. package/lib/v2/providers/scheduler.d.ts +14 -12
  106. package/lib/v2/providers/scheduler.js +16 -14
  107. package/lib/v2/providers/storage.d.ts +32 -30
  108. package/lib/v2/providers/storage.js +16 -32
  109. package/lib/v2/providers/tasks.d.ts +30 -26
  110. package/lib/v2/providers/tasks.js +14 -31
  111. package/lib/v2/providers/testLab.d.ts +110 -0
  112. package/lib/v2/providers/testLab.js +65 -0
  113. package/lib/v2/trace.d.ts +4 -0
  114. package/lib/v2/trace.js +21 -0
  115. package/package.json +61 -66
  116. package/lib/apps.d.ts +0 -35
  117. package/lib/apps.js +0 -112
  118. package/lib/cloud-functions.d.ts +0 -231
  119. package/lib/cloud-functions.js +0 -251
  120. package/lib/config.d.ts +0 -24
  121. package/lib/config.js +0 -117
  122. package/lib/function-configuration.d.ts +0 -108
  123. package/lib/function-configuration.js +0 -71
  124. package/lib/handler-builder.d.ts +0 -256
  125. package/lib/handler-builder.js +0 -349
  126. package/lib/index.d.ts +0 -19
  127. package/lib/setup.d.ts +0 -1
  128. package/lib/setup.js +0 -60
  129. package/lib/v2/params/types.d.ts +0 -118
  130. package/lib/v2/params/types.js +0 -196
@@ -1,14 +1,16 @@
1
- import * as express from 'express';
2
- import { CallableRequest, FunctionsErrorCode, HttpsError, Request } from '../../common/providers/https';
3
- import { ManifestEndpoint } from '../../runtime/manifest';
4
- import * as options from '../options';
5
- import { GlobalOptions, SupportedRegion } from '../options';
6
- import { Expression } from '../params';
1
+ import * as express from "express";
2
+ import { ResetValue } from "../../common/options";
3
+ import { CallableRequest, FunctionsErrorCode, HttpsError, Request } from "../../common/providers/https";
4
+ import { ManifestEndpoint } from "../../runtime/manifest";
5
+ import { GlobalOptions, SupportedRegion } from "../options";
6
+ import { Expression } from "../../params";
7
+ import { SecretParam } from "../../params/types";
8
+ import * as options from "../options";
7
9
  export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
8
10
  /**
9
- * Options that can be set on an individual HTTPS function.
11
+ * Options that can be set on an onRequest HTTPS function.
10
12
  */
11
- export interface HttpsOptions extends Omit<GlobalOptions, 'region'> {
13
+ export interface HttpsOptions extends Omit<GlobalOptions, "region"> {
12
14
  /** HTTP functions can override global options and can specify multiple regions to deploy to. */
13
15
  region?: SupportedRegion | string | Array<SupportedRegion | string>;
14
16
  /** If true, allows CORS on requests to this function.
@@ -19,80 +21,90 @@ export interface HttpsOptions extends Omit<GlobalOptions, 'region'> {
19
21
  cors?: string | boolean | RegExp | Array<string | RegExp>;
20
22
  /**
21
23
  * Amount of memory to allocate to a function.
22
- * A value of null restores the defaults of 256MB.
23
24
  */
24
- memory?: options.MemoryOption | Expression<number> | null;
25
+ memory?: options.MemoryOption | Expression<number> | ResetValue;
25
26
  /**
26
27
  * Timeout for the function in sections, possible values are 0 to 540.
27
28
  * HTTPS functions can specify a higher timeout.
28
- * A value of null restores the default of 60s
29
+ *
30
+ * @remarks
29
31
  * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
30
32
  * function depends on the type of function: Event handling functions have a
31
33
  * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
32
34
  * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
33
35
  * timeout of 1,800s (30 minutes)
34
36
  */
35
- timeoutSeconds?: number | Expression<number> | null;
37
+ timeoutSeconds?: number | Expression<number> | ResetValue;
36
38
  /**
37
39
  * Min number of actual instances to be running at a given time.
40
+ *
41
+ * @remarks
38
42
  * Instances will be billed for memory allocation and 10% of CPU allocation
39
43
  * while idle.
40
- * A value of null restores the default min instances.
41
44
  */
42
- minInstances?: number | Expression<number> | null;
45
+ minInstances?: number | Expression<number> | ResetValue;
43
46
  /**
44
47
  * Max number of instances to be running in parallel.
45
- * A value of null restores the default max instances.
46
48
  */
47
- maxInstances?: number | Expression<number> | null;
49
+ maxInstances?: number | Expression<number> | ResetValue;
48
50
  /**
49
51
  * Number of requests a function can serve at once.
52
+ *
53
+ * @remarks
50
54
  * Can only be applied to functions running on Cloud Functions v2.
51
55
  * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
52
56
  * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
53
57
  * The maximum value for concurrency is 1,000.
54
58
  */
55
- concurrency?: number | Expression<number> | null;
59
+ concurrency?: number | Expression<number> | ResetValue;
56
60
  /**
57
61
  * Fractional number of CPUs to allocate to a function.
62
+ *
63
+ * @remarks
58
64
  * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
59
65
  * This is different from the defaults when using the gcloud utility and is different from
60
66
  * the fixed amount assigned in Google Cloud Functions generation 1.
61
67
  * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
62
68
  * to the value "gcf_gen1"
63
69
  */
64
- cpu?: number | 'gcf_gen1';
70
+ cpu?: number | "gcf_gen1";
65
71
  /**
66
72
  * Connect cloud function to specified VPC connector.
67
- * A value of null removes the VPC connector
68
73
  */
69
- vpcConnector?: string | null;
74
+ vpcConnector?: string | ResetValue;
70
75
  /**
71
76
  * Egress settings for VPC connector.
72
- * A value of null turns off VPC connector egress settings
73
77
  */
74
- vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
78
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
75
79
  /**
76
80
  * Specific service account for the function to run as.
77
- * A value of null restores the default service account.
78
81
  */
79
- serviceAccount?: string | null;
82
+ serviceAccount?: string | ResetValue;
80
83
  /**
81
84
  * Ingress settings which control where this function can be called from.
82
- * A value of null turns off ingress settings.
83
85
  */
84
- ingressSettings?: options.IngressSetting | null;
86
+ ingressSettings?: options.IngressSetting | ResetValue;
85
87
  /**
86
88
  * User labels to set on the function.
87
89
  */
88
90
  labels?: Record<string, string>;
91
+ secrets?: (string | SecretParam)[];
89
92
  /**
90
93
  * Invoker to set access control on https functions.
91
94
  */
92
- invoker?: 'public' | 'private' | string | string[];
93
- secrets?: string[];
94
- /** Whether failed executions should be delivered again. */
95
- retry?: boolean;
95
+ invoker?: "public" | "private" | string | string[];
96
+ }
97
+ /**
98
+ * Options that can be set on a callable HTTPS function.
99
+ */
100
+ export interface CallableOptions extends HttpsOptions {
101
+ /**
102
+ * Determines whether Firebase AppCheck is enforced.
103
+ * When true, requests with invalid tokens autorespond with a 401
104
+ * (Unauthorized) error.
105
+ * When false, requests with invalid tokens set event.app to undefiend.
106
+ */
107
+ enforceAppCheck?: boolean;
96
108
  }
97
109
  /**
98
110
  * Handles HTTPS requests.
@@ -102,8 +114,6 @@ export declare type HttpsFunction = ((
102
114
  req: Request,
103
115
  /** An Express response object, for this function to respond to callers. */
104
116
  res: express.Response) => void | Promise<void>) & {
105
- /** @alpha */
106
- __trigger?: unknown;
107
117
  /** @alpha */
108
118
  __endpoint: ManifestEndpoint;
109
119
  };
@@ -136,7 +146,7 @@ export declare function onRequest(handler: (request: Request, response: express.
136
146
  * @param handler - A function that takes a {@link https.CallableRequest}.
137
147
  * @returns A function that you can export and deploy.
138
148
  */
139
- export declare function onCall<T = any, Return = any | Promise<any>>(opts: HttpsOptions, handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
149
+ export declare function onCall<T = any, Return = any | Promise<any>>(opts: CallableOptions, handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
140
150
  /**
141
151
  * Declares a callable method for clients to call using a Firebase SDK.
142
152
  * @param handler - A function that takes a {@link https.CallableRequest}.
@@ -28,9 +28,11 @@ exports.onCall = exports.onRequest = exports.HttpsError = void 0;
28
28
  */
29
29
  const cors = require("cors");
30
30
  const encoding_1 = require("../../common/encoding");
31
+ const trace_1 = require("../trace");
31
32
  const debug_1 = require("../../common/debug");
32
33
  const https_1 = require("../../common/providers/https");
33
34
  Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
35
+ const manifest_1 = require("../../runtime/manifest");
34
36
  const options = require("../options");
35
37
  function onRequest(optsOrHandler, handler) {
36
38
  let opts;
@@ -41,46 +43,26 @@ function onRequest(optsOrHandler, handler) {
41
43
  else {
42
44
  opts = optsOrHandler;
43
45
  }
44
- if ((0, debug_1.isDebugFeatureEnabled)('enableCors') || 'cors' in opts) {
45
- const origin = (0, debug_1.isDebugFeatureEnabled)('enableCors') ? true : opts.cors;
46
+ if ((0, debug_1.isDebugFeatureEnabled)("enableCors") || "cors" in opts) {
47
+ const origin = (0, debug_1.isDebugFeatureEnabled)("enableCors") ? true : opts.cors;
46
48
  const userProvidedHandler = handler;
47
49
  handler = (req, res) => {
48
50
  return new Promise((resolve) => {
49
- res.on('finish', resolve);
51
+ res.on("finish", resolve);
50
52
  cors({ origin })(req, res, () => {
51
53
  resolve(userProvidedHandler(req, res));
52
54
  });
53
55
  });
54
56
  };
55
57
  }
56
- Object.defineProperty(handler, '__trigger', {
57
- get: () => {
58
- const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
59
- // global options calls region a scalar and https allows it to be an array,
60
- // but optionsToTriggerAnnotations handles both cases.
61
- const specificOpts = options.optionsToTriggerAnnotations(opts);
62
- const trigger = {
63
- platform: 'gcfv2',
64
- ...baseOpts,
65
- ...specificOpts,
66
- labels: {
67
- ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
68
- ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
69
- },
70
- httpsTrigger: {
71
- allowInsecure: false,
72
- },
73
- };
74
- (0, encoding_1.convertIfPresent)(trigger.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
75
- return trigger;
76
- },
77
- });
58
+ handler = (0, trace_1.wrapTraceContext)(handler);
78
59
  const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
79
60
  // global options calls region a scalar and https allows it to be an array,
80
61
  // but optionsToTriggerAnnotations handles both cases.
81
62
  const specificOpts = options.optionsToEndpoint(opts);
82
63
  const endpoint = {
83
- platform: 'gcfv2',
64
+ ...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
65
+ platform: "gcfv2",
84
66
  ...baseOpts,
85
67
  ...specificOpts,
86
68
  labels: {
@@ -89,56 +71,36 @@ function onRequest(optsOrHandler, handler) {
89
71
  },
90
72
  httpsTrigger: {},
91
73
  };
92
- (0, encoding_1.convertIfPresent)(endpoint.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
74
+ (0, encoding_1.convertIfPresent)(endpoint.httpsTrigger, opts, "invoker", "invoker", encoding_1.convertInvoker);
93
75
  handler.__endpoint = endpoint;
94
76
  return handler;
95
77
  }
96
78
  exports.onRequest = onRequest;
97
79
  function onCall(optsOrHandler, handler) {
80
+ var _a;
98
81
  let opts;
99
- if (arguments.length == 1) {
82
+ if (arguments.length === 1) {
100
83
  opts = {};
101
84
  handler = optsOrHandler;
102
85
  }
103
86
  else {
104
87
  opts = optsOrHandler;
105
88
  }
106
- const origin = (0, debug_1.isDebugFeatureEnabled)('enableCors')
107
- ? true
108
- : 'cors' in opts
109
- ? opts.cors
110
- : true;
89
+ const origin = (0, debug_1.isDebugFeatureEnabled)("enableCors") ? true : "cors" in opts ? opts.cors : true;
111
90
  // onCallHandler sniffs the function length to determine which API to present.
112
91
  // fix the length to prevent api versions from being mismatched.
113
92
  const fixedLen = (req) => handler(req);
114
- const func = (0, https_1.onCallHandler)({ cors: { origin, methods: 'POST' } }, fixedLen);
115
- Object.defineProperty(func, '__trigger', {
116
- get: () => {
117
- const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
118
- // global options calls region a scalar and https allows it to be an array,
119
- // but optionsToTriggerAnnotations handles both cases.
120
- const specificOpts = options.optionsToTriggerAnnotations(opts);
121
- return {
122
- platform: 'gcfv2',
123
- ...baseOpts,
124
- ...specificOpts,
125
- labels: {
126
- ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
127
- ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
128
- 'deployment-callable': 'true',
129
- },
130
- httpsTrigger: {
131
- allowInsecure: false,
132
- },
133
- };
134
- },
135
- });
93
+ const func = (0, https_1.onCallHandler)({
94
+ cors: { origin, methods: "POST" },
95
+ enforceAppCheck: (_a = opts.enforceAppCheck) !== null && _a !== void 0 ? _a : options.getGlobalOptions().enforceAppCheck,
96
+ }, fixedLen);
136
97
  const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
137
98
  // global options calls region a scalar and https allows it to be an array,
138
99
  // but optionsToEndpoint handles both cases.
139
100
  const specificOpts = options.optionsToEndpoint(opts);
140
101
  func.__endpoint = {
141
- platform: 'gcfv2',
102
+ ...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
103
+ platform: "gcfv2",
142
104
  ...baseOpts,
143
105
  ...specificOpts,
144
106
  labels: {
@@ -2,10 +2,12 @@
2
2
  * Cloud functions to handle events from Google Cloud Identity Platform.
3
3
  * @packageDocumentation
4
4
  */
5
- import { BlockingFunction } from '../../cloud-functions';
6
- import { AuthBlockingEvent, AuthBlockingEventType, AuthUserRecord, BeforeCreateResponse, BeforeSignInResponse, HttpsError } from '../../common/providers/identity';
7
- import * as options from '../options';
8
- import { Expression } from '../params';
5
+ import { ResetValue } from "../../common/options";
6
+ import { AuthBlockingEvent, AuthBlockingEventType, AuthUserRecord, BeforeCreateResponse, BeforeSignInResponse, HttpsError } from "../../common/providers/identity";
7
+ import { BlockingFunction } from "../../v1/cloud-functions";
8
+ import { Expression } from "../../params";
9
+ import * as options from "../options";
10
+ import { SecretParam } from "../../params/types";
9
11
  export { AuthUserRecord, AuthBlockingEvent, HttpsError };
10
12
  /** @hidden Internally used when parsing the options. */
11
13
  interface InternalOptions {
@@ -30,74 +32,74 @@ export interface BlockingOptions {
30
32
  region?: options.SupportedRegion | string;
31
33
  /**
32
34
  * Amount of memory to allocate to a function.
33
- * A value of null restores the defaults of 256MB.
34
35
  */
35
- memory?: options.MemoryOption | Expression<number> | null;
36
+ memory?: options.MemoryOption | Expression<number> | ResetValue;
36
37
  /**
37
38
  * Timeout for the function in sections, possible values are 0 to 540.
38
39
  * HTTPS functions can specify a higher timeout.
39
- * A value of null restores the default of 60s
40
+ *
41
+ * @remarks
40
42
  * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
41
43
  * function depends on the type of function: Event handling functions have a
42
44
  * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
43
45
  * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
44
46
  * timeout of 1,800s (30 minutes)
45
47
  */
46
- timeoutSeconds?: number | Expression<number> | null;
48
+ timeoutSeconds?: number | Expression<number> | ResetValue;
47
49
  /**
48
50
  * Min number of actual instances to be running at a given time.
51
+ *
52
+ * @remarks
49
53
  * Instances will be billed for memory allocation and 10% of CPU allocation
50
54
  * while idle.
51
- * A value of null restores the default min instances.
52
55
  */
53
- minInstances?: number | Expression<number> | null;
56
+ minInstances?: number | Expression<number> | ResetValue;
54
57
  /**
55
58
  * Max number of instances to be running in parallel.
56
- * A value of null restores the default max instances.
57
59
  */
58
- maxInstances?: number | Expression<number> | null;
60
+ maxInstances?: number | Expression<number> | ResetValue;
59
61
  /**
60
62
  * Number of requests a function can serve at once.
63
+ *
64
+ * @remarks
61
65
  * Can only be applied to functions running on Cloud Functions v2.
62
66
  * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
63
67
  * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
64
68
  * The maximum value for concurrency is 1,000.
65
69
  */
66
- concurrency?: number | Expression<number> | null;
70
+ concurrency?: number | Expression<number> | ResetValue;
67
71
  /**
68
72
  * Fractional number of CPUs to allocate to a function.
73
+ *
74
+ * @remarks
69
75
  * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
70
76
  * This is different from the defaults when using the gcloud utility and is different from
71
77
  * the fixed amount assigned in Google Cloud Functions generation 1.
72
78
  * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
73
79
  * to the value "gcf_gen1"
74
80
  */
75
- cpu?: number | 'gcf_gen1';
81
+ cpu?: number | "gcf_gen1";
76
82
  /**
77
83
  * Connect cloud function to specified VPC connector.
78
- * A value of null removes the VPC connector
79
84
  */
80
- vpcConnector?: string | null;
85
+ vpcConnector?: string | ResetValue;
81
86
  /**
82
87
  * Egress settings for VPC connector.
83
- * A value of null turns off VPC connector egress settings
84
88
  */
85
- vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
89
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
86
90
  /**
87
91
  * Specific service account for the function to run as.
88
- * A value of null restores the default service account.
89
92
  */
90
- serviceAccount?: string | null;
93
+ serviceAccount?: string | ResetValue;
91
94
  /**
92
95
  * Ingress settings which control where this function can be called from.
93
- * A value of null turns off ingress settings.
94
96
  */
95
- ingressSettings?: options.IngressSetting | null;
97
+ ingressSettings?: options.IngressSetting | ResetValue;
96
98
  /**
97
99
  * User labels to set on the function.
98
100
  */
99
101
  labels?: Record<string, string>;
100
- secrets?: string[];
102
+ secrets?: (string | SecretParam)[];
101
103
  }
102
104
  /**
103
105
  * Handles an event that is triggered before a user is created.
@@ -24,6 +24,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.getOpts = exports.beforeOperation = exports.beforeUserSignedIn = exports.beforeUserCreated = exports.HttpsError = void 0;
25
25
  const identity_1 = require("../../common/providers/identity");
26
26
  Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return identity_1.HttpsError; } });
27
+ const trace_1 = require("../trace");
28
+ const manifest_1 = require("../../runtime/manifest");
27
29
  const options = require("../options");
28
30
  /**
29
31
  * Handles an event that is triggered before a user is created
@@ -31,7 +33,7 @@ const options = require("../options");
31
33
  * @param handler? - If defined, an event handler which is run every time before a user is created
32
34
  */
33
35
  function beforeUserCreated(optsOrHandler, handler) {
34
- return beforeOperation('beforeCreate', optsOrHandler, handler);
36
+ return beforeOperation("beforeCreate", optsOrHandler, handler);
35
37
  }
36
38
  exports.beforeUserCreated = beforeUserCreated;
37
39
  /**
@@ -40,12 +42,12 @@ exports.beforeUserCreated = beforeUserCreated;
40
42
  * @param handler - Event handler which is run every time before a user is signed in
41
43
  */
42
44
  function beforeUserSignedIn(optsOrHandler, handler) {
43
- return beforeOperation('beforeSignIn', optsOrHandler, handler);
45
+ return beforeOperation("beforeSignIn", optsOrHandler, handler);
44
46
  }
45
47
  exports.beforeUserSignedIn = beforeUserSignedIn;
46
48
  /** @hidden */
47
49
  function beforeOperation(eventType, optsOrHandler, handler) {
48
- if (!handler || typeof optsOrHandler === 'function') {
50
+ if (!handler || typeof optsOrHandler === "function") {
49
51
  handler = optsOrHandler;
50
52
  optsOrHandler = {};
51
53
  }
@@ -53,13 +55,14 @@ function beforeOperation(eventType, optsOrHandler, handler) {
53
55
  // Create our own function that just calls the provided function so we know for sure that
54
56
  // handler takes one argument. This is something common/providers/identity depends on.
55
57
  const wrappedHandler = (event) => handler(event);
56
- const func = (0, identity_1.wrapHandler)(eventType, wrappedHandler);
58
+ const func = (0, trace_1.wrapTraceContext)((0, identity_1.wrapHandler)(eventType, wrappedHandler));
57
59
  const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
58
60
  /** Endpoint */
59
61
  const baseOptsEndpoint = options.optionsToEndpoint(options.getGlobalOptions());
60
62
  const specificOptsEndpoint = options.optionsToEndpoint(opts);
61
63
  func.__endpoint = {
62
- platform: 'gcfv2',
64
+ ...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
65
+ platform: "gcfv2",
63
66
  ...baseOptsEndpoint,
64
67
  ...specificOptsEndpoint,
65
68
  labels: {
@@ -77,8 +80,8 @@ function beforeOperation(eventType, optsOrHandler, handler) {
77
80
  };
78
81
  func.__requiredAPIs = [
79
82
  {
80
- api: 'identitytoolkit.googleapis.com',
81
- reason: 'Needed for auth blocking functions',
83
+ api: "identitytoolkit.googleapis.com",
84
+ reason: "Needed for auth blocking functions",
82
85
  },
83
86
  ];
84
87
  func.run = handler;
@@ -1,6 +1,8 @@
1
- import { CloudEvent, CloudFunction } from '../core';
2
- import * as options from '../options';
3
- import { Expression } from '../params';
1
+ import { ResetValue } from "../../common/options";
2
+ import { CloudEvent, CloudFunction } from "../core";
3
+ import { Expression } from "../../params";
4
+ import * as options from "../options";
5
+ import { SecretParam } from "../../params/types";
4
6
  /**
5
7
  * Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
6
8
  * You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
@@ -88,76 +90,76 @@ export interface PubSubOptions extends options.EventHandlerOptions {
88
90
  region?: options.SupportedRegion | string;
89
91
  /**
90
92
  * Amount of memory to allocate to a function.
91
- * A value of null restores the defaults of 256MB.
92
93
  */
93
- memory?: options.MemoryOption | Expression<number> | null;
94
+ memory?: options.MemoryOption | Expression<number> | ResetValue;
94
95
  /**
95
96
  * Timeout for the function in sections, possible values are 0 to 540.
96
97
  * HTTPS functions can specify a higher timeout.
97
- * A value of null restores the default of 60s
98
+ *
99
+ * @remarks
98
100
  * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
99
101
  * function depends on the type of function: Event handling functions have a
100
102
  * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
101
103
  * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
102
104
  * timeout of 1,800s (30 minutes)
103
105
  */
104
- timeoutSeconds?: number | Expression<number> | null;
106
+ timeoutSeconds?: number | Expression<number> | ResetValue;
105
107
  /**
106
108
  * Min number of actual instances to be running at a given time.
109
+ *
110
+ * @remarks
107
111
  * Instances will be billed for memory allocation and 10% of CPU allocation
108
112
  * while idle.
109
- * A value of null restores the default min instances.
110
113
  */
111
- minInstances?: number | Expression<number> | null;
114
+ minInstances?: number | Expression<number> | ResetValue;
112
115
  /**
113
116
  * Max number of instances to be running in parallel.
114
- * A value of null restores the default max instances.
115
117
  */
116
- maxInstances?: number | Expression<number> | null;
118
+ maxInstances?: number | Expression<number> | ResetValue;
117
119
  /**
118
120
  * Number of requests a function can serve at once.
121
+ *
122
+ * @remarks
119
123
  * Can only be applied to functions running on Cloud Functions v2.
120
124
  * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
121
125
  * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
122
126
  * The maximum value for concurrency is 1,000.
123
127
  */
124
- concurrency?: number | Expression<number> | null;
128
+ concurrency?: number | Expression<number> | ResetValue;
125
129
  /**
126
130
  * Fractional number of CPUs to allocate to a function.
131
+ *
132
+ * @remarks
127
133
  * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
128
134
  * This is different from the defaults when using the gcloud utility and is different from
129
135
  * the fixed amount assigned in Google Cloud Functions generation 1.
130
136
  * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
131
137
  * to the value "gcf_gen1"
132
138
  */
133
- cpu?: number | 'gcf_gen1';
139
+ cpu?: number | "gcf_gen1";
134
140
  /**
135
141
  * Connect cloud function to specified VPC connector.
136
- * A value of null removes the VPC connector
137
142
  */
138
- vpcConnector?: string | null;
143
+ vpcConnector?: string | ResetValue;
139
144
  /**
140
145
  * Egress settings for VPC connector.
141
- * A value of null turns off VPC connector egress settings
142
146
  */
143
- vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
147
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
144
148
  /**
145
149
  * Specific service account for the function to run as.
146
- * A value of null restores the default service account.
147
150
  */
148
- serviceAccount?: string | null;
151
+ serviceAccount?: string | ResetValue;
149
152
  /**
150
153
  * Ingress settings which control where this function can be called from.
151
- * A value of null turns off ingress settings.
152
154
  */
153
- ingressSettings?: options.IngressSetting | null;
155
+ ingressSettings?: options.IngressSetting | ResetValue;
154
156
  /**
155
157
  * User labels to set on the function.
156
158
  */
157
159
  labels?: Record<string, string>;
158
- secrets?: string[];
160
+ secrets?: (string | SecretParam)[];
159
161
  /** Whether failed executions should be delivered again. */
160
- retry?: boolean;
162
+ retry?: boolean | Expression<boolean> | ResetValue;
161
163
  }
162
164
  /**
163
165
  * Handle a message being published to a Pub/Sub topic.
@@ -27,6 +27,8 @@ exports.onMessagePublished = exports.Message = void 0;
27
27
  * @packageDocumentation
28
28
  */
29
29
  const encoding_1 = require("../../common/encoding");
30
+ const manifest_1 = require("../../runtime/manifest");
31
+ const trace_1 = require("../trace");
30
32
  const options = require("../options");
31
33
  /**
32
34
  * Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
@@ -63,7 +65,7 @@ class Message {
63
65
  this.messageId = data.messageId;
64
66
  this.data = data.data;
65
67
  this.attributes = data.attributes || {};
66
- this.orderingKey = data.orderingKey || '';
68
+ this.orderingKey = data.orderingKey || "";
67
69
  this.publishTime = data.publishTime || new Date().toISOString();
68
70
  this._json = data.json;
69
71
  }
@@ -71,9 +73,9 @@ class Message {
71
73
  * The JSON data payload of this message object, if any.
72
74
  */
73
75
  get json() {
74
- if (typeof this._json === 'undefined') {
76
+ if (typeof this._json === "undefined") {
75
77
  try {
76
- this._json = JSON.parse(Buffer.from(this.data, 'base64').toString('utf8'));
78
+ this._json = JSON.parse(Buffer.from(this.data, "base64").toString("utf8"));
77
79
  }
78
80
  catch (err) {
79
81
  throw new Error(`Unable to parse Pub/Sub message data as JSON: ${err.message}`);
@@ -111,7 +113,7 @@ exports.Message = Message;
111
113
  function onMessagePublished(topicOrOptions, handler) {
112
114
  let topic;
113
115
  let opts;
114
- if (typeof topicOrOptions === 'string') {
116
+ if (typeof topicOrOptions === "string") {
115
117
  topic = topicOrOptions;
116
118
  opts = {};
117
119
  }
@@ -123,32 +125,14 @@ function onMessagePublished(topicOrOptions, handler) {
123
125
  const func = (raw) => {
124
126
  const messagePublishedData = raw.data;
125
127
  messagePublishedData.message = new Message(messagePublishedData.message);
126
- return handler(raw);
128
+ return (0, trace_1.wrapTraceContext)(handler)(raw);
127
129
  };
128
130
  func.run = handler;
129
- Object.defineProperty(func, '__trigger', {
130
- get: () => {
131
- const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
132
- const specificOpts = options.optionsToTriggerAnnotations(opts);
133
- return {
134
- platform: 'gcfv2',
135
- ...baseOpts,
136
- ...specificOpts,
137
- labels: {
138
- ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
139
- ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
140
- },
141
- eventTrigger: {
142
- eventType: 'google.cloud.pubsub.topic.v1.messagePublished',
143
- resource: `projects/${process.env.GCLOUD_PROJECT}/topics/${topic}`,
144
- },
145
- };
146
- },
147
- });
148
131
  const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
149
132
  const specificOpts = options.optionsToEndpoint(opts);
150
133
  const endpoint = {
151
- platform: 'gcfv2',
134
+ ...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
135
+ platform: "gcfv2",
152
136
  ...baseOpts,
153
137
  ...specificOpts,
154
138
  labels: {
@@ -156,12 +140,12 @@ function onMessagePublished(topicOrOptions, handler) {
156
140
  ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
157
141
  },
158
142
  eventTrigger: {
159
- eventType: 'google.cloud.pubsub.topic.v1.messagePublished',
143
+ eventType: "google.cloud.pubsub.topic.v1.messagePublished",
160
144
  eventFilters: { topic },
161
145
  retry: false,
162
146
  },
163
147
  };
164
- (0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, 'retry', 'retry');
148
+ (0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, "retry", "retry");
165
149
  func.__endpoint = endpoint;
166
150
  return func;
167
151
  }