firebase-functions 3.24.1 → 4.0.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
@@ -0,0 +1,14 @@
1
+ export interface TraceContext {
2
+ version: string;
3
+ traceId: string;
4
+ parentId: string;
5
+ sample: boolean;
6
+ }
7
+ /**
8
+ * Extracts trace context from given carrier object, if any.
9
+ *
10
+ * Supports Cloud Trace and traceparent format.
11
+ *
12
+ * @param carrier
13
+ */
14
+ export declare function extractTraceContext(carrier: unknown): TraceContext | undefined;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractTraceContext = exports.traceContext = void 0;
4
+ const async_hooks_1 = require("async_hooks");
5
+ /* @internal */
6
+ exports.traceContext = new async_hooks_1.AsyncLocalStorage();
7
+ /**
8
+ * A regex to match the Cloud Trace header.
9
+ * - ([A-Fa-f0-9]{32}): The trace id, a 32 character hex value. (e.g. 4bf92f3577b34da6a3ce929d0e0e4736)
10
+ * - ([0-9]+): The parent span id, a 64 bit integer. (e.g. 00f067aa0ba902b7)
11
+ * - (?:;o=([0-3])): The trace mask, 1-3 denote it should be traced.
12
+ */
13
+ const CLOUD_TRACE_REGEX = new RegExp("^(?<traceId>[A-Fa-f0-9]{32})/" + "(?<parentIdInt>[0-9]+)" + "(?:;o=(?<traceMask>[0-3]))?$");
14
+ const CLOUD_TRACE_HEADER = "X-Cloud-Trace-Context";
15
+ function matchCloudTraceHeader(carrier) {
16
+ let header = carrier === null || carrier === void 0 ? void 0 : carrier[CLOUD_TRACE_HEADER];
17
+ if (!header) {
18
+ // try lowercase header
19
+ header = carrier === null || carrier === void 0 ? void 0 : carrier[CLOUD_TRACE_HEADER.toLowerCase()];
20
+ }
21
+ if (header && typeof header === "string") {
22
+ const matches = CLOUD_TRACE_REGEX.exec(header);
23
+ if (matches && matches.groups) {
24
+ const { traceId, parentIdInt, traceMask } = matches.groups;
25
+ // Convert parentId from unsigned int to hex
26
+ const parentId = parseInt(parentIdInt);
27
+ if (isNaN(parentId)) {
28
+ // Ignore traces with invalid parentIds
29
+ return;
30
+ }
31
+ const sample = !!traceMask && traceMask !== "0";
32
+ return { traceId, parentId: parentId.toString(16), sample, version: "00" };
33
+ }
34
+ }
35
+ }
36
+ /**
37
+ * A regex to match the traceparent header.
38
+ * - ^([a-f0-9]{2}): The specification version (e.g. 00)
39
+ * - ([a-f0-9]{32}): The trace id, a 16-byte array. (e.g. 4bf92f3577b34da6a3ce929d0e0e4736)
40
+ * - ([a-f0-9]{16}): The parent span id, an 8-byte array. (e.g. 00f067aa0ba902b7)
41
+ * - ([a-f0-9]{2}: The sampled flag. (e.g. 00)
42
+ */
43
+ const TRACEPARENT_REGEX = new RegExp("^(?<version>[a-f0-9]{2})-" +
44
+ "(?<traceId>[a-f0-9]{32})-" +
45
+ "(?<parentId>[a-f0-9]{16})-" +
46
+ "(?<flag>[a-f0-9]{2})$");
47
+ const TRACEPARENT_HEADER = "traceparent";
48
+ function matchTraceparentHeader(carrier) {
49
+ const header = carrier === null || carrier === void 0 ? void 0 : carrier[TRACEPARENT_HEADER];
50
+ if (header && typeof header === "string") {
51
+ const matches = TRACEPARENT_REGEX.exec(header);
52
+ if (matches && matches.groups) {
53
+ const { version, traceId, parentId, flag } = matches.groups;
54
+ const sample = flag === "01";
55
+ return { traceId, parentId, sample, version };
56
+ }
57
+ }
58
+ }
59
+ /**
60
+ * Extracts trace context from given carrier object, if any.
61
+ *
62
+ * Supports Cloud Trace and traceparent format.
63
+ *
64
+ * @param carrier
65
+ */
66
+ function extractTraceContext(carrier) {
67
+ return matchCloudTraceHeader(carrier) || matchTraceparentHeader(carrier);
68
+ }
69
+ exports.extractTraceContext = extractTraceContext;
@@ -23,7 +23,7 @@
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.dateToTimestampProto = void 0;
25
25
  function dateToTimestampProto(timeString) {
26
- if (typeof timeString === 'undefined') {
26
+ if (typeof timeString === "undefined") {
27
27
  return;
28
28
  }
29
29
  const date = new Date(timeString);
@@ -25,12 +25,12 @@ exports.PathPattern = exports.trimParam = void 0;
25
25
  const path_1 = require("./path");
26
26
  /** https://cloud.google.com/eventarc/docs/path-patterns */
27
27
  /** @hidden */
28
- const WILDCARD_CAPTURE_REGEX = new RegExp('{[^/{}]+}', 'g');
28
+ const WILDCARD_CAPTURE_REGEX = new RegExp("{[^/{}]+}", "g");
29
29
  /** @internal */
30
30
  function trimParam(param) {
31
31
  const paramNoBraces = param.slice(1, -1);
32
- if (paramNoBraces.includes('=')) {
33
- return paramNoBraces.slice(0, paramNoBraces.indexOf('='));
32
+ if (paramNoBraces.includes("=")) {
33
+ return paramNoBraces.slice(0, paramNoBraces.indexOf("="));
34
34
  }
35
35
  return paramNoBraces;
36
36
  }
@@ -39,21 +39,21 @@ exports.trimParam = trimParam;
39
39
  class Segment {
40
40
  constructor(value) {
41
41
  this.value = value;
42
- this.name = 'segment';
42
+ this.name = "segment";
43
43
  this.trimmed = value;
44
44
  }
45
45
  isSingleSegmentWildcard() {
46
- return this.value.includes('*') && !this.isMultiSegmentWildcard();
46
+ return this.value.includes("*") && !this.isMultiSegmentWildcard();
47
47
  }
48
48
  isMultiSegmentWildcard() {
49
- return this.value.includes('**');
49
+ return this.value.includes("**");
50
50
  }
51
51
  }
52
52
  /** @hidden */
53
53
  class SingleCaptureSegment {
54
54
  constructor(value) {
55
55
  this.value = value;
56
- this.name = 'single-capture';
56
+ this.name = "single-capture";
57
57
  this.trimmed = trimParam(value);
58
58
  }
59
59
  isSingleSegmentWildcard() {
@@ -67,7 +67,7 @@ class SingleCaptureSegment {
67
67
  class MultiCaptureSegment {
68
68
  constructor(value) {
69
69
  this.value = value;
70
- this.name = 'multi-capture';
70
+ this.name = "multi-capture";
71
71
  this.trimmed = trimParam(value);
72
72
  }
73
73
  isSingleSegmentWildcard() {
@@ -88,7 +88,10 @@ class PathPattern {
88
88
  this.initPathSegments(raw);
89
89
  }
90
90
  /** @throws on validation error */
91
- static compile(rawPath) { }
91
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
92
+ static compile(rawPath) {
93
+ return undefined;
94
+ }
92
95
  getValue() {
93
96
  return this.raw;
94
97
  }
@@ -97,7 +100,7 @@ class PathPattern {
97
100
  return this.segments.some((segment) => segment.isSingleSegmentWildcard() || segment.isMultiSegmentWildcard());
98
101
  }
99
102
  hasCaptures() {
100
- return this.segments.some((segment) => segment.name == 'single-capture' || segment.name === 'multi-capture');
103
+ return this.segments.some((segment) => segment.name === "single-capture" || segment.name === "multi-capture");
101
104
  }
102
105
  extractMatches(path) {
103
106
  const matches = {};
@@ -110,13 +113,11 @@ class PathPattern {
110
113
  const segment = this.segments[segmentNdx];
111
114
  const remainingSegments = this.segments.length - 1 - segmentNdx;
112
115
  const nextPathNdx = pathSegments.length - remainingSegments;
113
- if (segment.name === 'single-capture') {
116
+ if (segment.name === "single-capture") {
114
117
  matches[segment.trimmed] = pathSegments[pathNdx];
115
118
  }
116
- else if (segment.name === 'multi-capture') {
117
- matches[segment.trimmed] = pathSegments
118
- .slice(pathNdx, nextPathNdx)
119
- .join('/');
119
+ else if (segment.name === "multi-capture") {
120
+ matches[segment.trimmed] = pathSegments.slice(pathNdx, nextPathNdx).join("/");
120
121
  }
121
122
  pathNdx = segment.isMultiSegmentWildcard() ? nextPathNdx : pathNdx + 1;
122
123
  }
@@ -128,7 +129,7 @@ class PathPattern {
128
129
  let segment;
129
130
  const capture = part.match(WILDCARD_CAPTURE_REGEX);
130
131
  if (capture && capture.length === 1) {
131
- segment = part.includes('**')
132
+ segment = part.includes("**")
132
133
  ? new MultiCaptureSegment(part)
133
134
  : new SingleCaptureSegment(part);
134
135
  }
File without changes
@@ -8,9 +8,9 @@ exports.joinPath = exports.pathParts = exports.normalizePath = void 0;
8
8
  */
9
9
  function normalizePath(path) {
10
10
  if (!path) {
11
- return '';
11
+ return "";
12
12
  }
13
- return path.replace(/^\//, '').replace(/\/$/, '');
13
+ return path.replace(/^\//, "").replace(/\/$/, "");
14
14
  }
15
15
  exports.normalizePath = normalizePath;
16
16
  /**
@@ -19,10 +19,10 @@ exports.normalizePath = normalizePath;
19
19
  * @param path A path to split, in POSIX format.
20
20
  */
21
21
  function pathParts(path) {
22
- if (!path || path === '' || path === '/') {
22
+ if (!path || path === "" || path === "/") {
23
23
  return [];
24
24
  }
25
- return normalizePath(path).split('/');
25
+ return normalizePath(path).split("/");
26
26
  }
27
27
  exports.pathParts = pathParts;
28
28
  /**
@@ -32,8 +32,6 @@ exports.pathParts = pathParts;
32
32
  * @param child A second path segment, in POSIX format.
33
33
  */
34
34
  function joinPath(base, child) {
35
- return pathParts(base)
36
- .concat(pathParts(child))
37
- .join('/');
35
+ return pathParts(base).concat(pathParts(child)).join("/");
38
36
  }
39
37
  exports.joinPath = joinPath;
@@ -1,2 +1,2 @@
1
+ /** @hidden */
1
2
  export declare function applyChange(src: any, dest: any): any;
2
- export declare function pruneNulls(obj: any): any;
@@ -21,26 +21,32 @@
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.pruneNulls = exports.applyChange = void 0;
24
+ exports.applyChange = void 0;
25
+ function isObject(obj) {
26
+ return typeof obj === "object" && !!obj;
27
+ }
25
28
  /** @hidden */
26
- const _ = require("lodash");
27
29
  function applyChange(src, dest) {
28
30
  // if not mergeable, don't merge
29
- if (!_.isPlainObject(dest) || !_.isPlainObject(src)) {
31
+ if (!isObject(dest) || !isObject(src)) {
30
32
  return dest;
31
33
  }
32
- return pruneNulls(_.merge({}, src, dest));
34
+ return merge(src, dest);
33
35
  }
34
36
  exports.applyChange = applyChange;
35
- function pruneNulls(obj) {
36
- for (const key in obj) {
37
- if (obj[key] === null) {
38
- delete obj[key];
37
+ function merge(src, dest) {
38
+ const res = {};
39
+ const keys = new Set([...Object.keys(src), ...Object.keys(dest)]);
40
+ for (const key of keys.values()) {
41
+ if (key in dest) {
42
+ if (dest[key] === null) {
43
+ continue;
44
+ }
45
+ res[key] = applyChange(src[key], dest[key]);
39
46
  }
40
- else if (_.isPlainObject(obj[key])) {
41
- pruneNulls(obj[key]);
47
+ else if (src[key] !== null) {
48
+ res[key] = src[key];
42
49
  }
43
50
  }
44
- return obj;
51
+ return res;
45
52
  }
46
- exports.pruneNulls = pruneNulls;
@@ -1,8 +1,6 @@
1
1
  /** @hidden */
2
- export declare const SUPPORTS_STRUCTURED_LOGS: boolean;
3
- /** @hidden */
4
2
  export declare const CONSOLE_SEVERITY: {
5
- [severity: string]: 'debug' | 'info' | 'warn' | 'error';
3
+ [severity: string]: "debug" | "info" | "warn" | "error";
6
4
  };
7
5
  /** @hidden */
8
6
  export declare const UNPATCHED_CONSOLE: {
@@ -20,24 +20,19 @@
20
20
  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  // SOFTWARE.
23
- var _a, _b, _c;
24
23
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.UNPATCHED_CONSOLE = exports.CONSOLE_SEVERITY = exports.SUPPORTS_STRUCTURED_LOGS = void 0;
26
- // Determine if structured logs are supported (node >= 10). If something goes wrong,
27
- // assume no since unstructured is safer.
28
- /** @hidden */
29
- exports.SUPPORTS_STRUCTURED_LOGS = parseInt(((_c = (_b = (_a = process.versions) === null || _a === void 0 ? void 0 : _a.node) === null || _b === void 0 ? void 0 : _b.split('.')) === null || _c === void 0 ? void 0 : _c[0]) || '8', 10) >= 10;
24
+ exports.UNPATCHED_CONSOLE = exports.CONSOLE_SEVERITY = void 0;
30
25
  // Map LogSeverity types to their equivalent `console.*` method.
31
26
  /** @hidden */
32
27
  exports.CONSOLE_SEVERITY = {
33
- DEBUG: 'debug',
34
- INFO: 'info',
35
- NOTICE: 'info',
36
- WARNING: 'warn',
37
- ERROR: 'error',
38
- CRITICAL: 'error',
39
- ALERT: 'error',
40
- EMERGENCY: 'error',
28
+ DEBUG: "debug",
29
+ INFO: "info",
30
+ NOTICE: "info",
31
+ WARNING: "warn",
32
+ ERROR: "error",
33
+ CRITICAL: "error",
34
+ ALERT: "error",
35
+ EMERGENCY: "error",
41
36
  };
42
37
  // safely preserve unpatched console.* methods in case of compat require
43
38
  /** @hidden */
@@ -26,16 +26,16 @@ const common_1 = require("./common");
26
26
  /** @hidden */
27
27
  function patchedConsole(severity) {
28
28
  return function (data, ...args) {
29
- if (common_1.SUPPORTS_STRUCTURED_LOGS) {
30
- common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](JSON.stringify({ severity, message: (0, util_1.format)(data, ...args) }));
31
- return;
29
+ let message = (0, util_1.format)(data, ...args);
30
+ if (severity === "ERROR") {
31
+ message = new Error(message).stack || message;
32
32
  }
33
- common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](data, ...args);
33
+ common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](JSON.stringify({ severity, message }));
34
34
  };
35
35
  }
36
36
  // IMPORTANT -- "../logger" must be imported before monkeypatching!
37
- console.debug = patchedConsole('DEBUG');
38
- console.info = patchedConsole('INFO');
39
- console.log = patchedConsole('INFO');
40
- console.warn = patchedConsole('WARNING');
41
- console.error = patchedConsole('ERROR');
37
+ console.debug = patchedConsole("DEBUG");
38
+ console.info = patchedConsole("INFO");
39
+ console.log = patchedConsole("INFO");
40
+ console.warn = patchedConsole("WARNING");
41
+ console.error = patchedConsole("ERROR");
@@ -2,7 +2,7 @@
2
2
  * `LogSeverity` indicates the detailed severity of the log entry. See [LogSeverity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity).
3
3
  * @public
4
4
  */
5
- export declare type LogSeverity = 'DEBUG' | 'INFO' | 'NOTICE' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'ALERT' | 'EMERGENCY';
5
+ export declare type LogSeverity = "DEBUG" | "INFO" | "NOTICE" | "WARNING" | "ERROR" | "CRITICAL" | "ALERT" | "EMERGENCY";
6
6
  /**
7
7
  * `LogEntry` represents a [structured Cloud Logging](https://cloud.google.com/logging/docs/structured-logging)
8
8
  * entry. All keys aside from `severity` and `message` are
@@ -23,10 +23,11 @@
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.error = exports.warn = exports.info = exports.log = exports.debug = exports.write = void 0;
25
25
  const util_1 = require("util");
26
+ const trace_1 = require("../common/trace");
26
27
  const common_1 = require("./common");
27
28
  /** @internal */
28
29
  function removeCircular(obj, refs = []) {
29
- if (typeof obj !== 'object' || !obj) {
30
+ if (typeof obj !== "object" || !obj) {
30
31
  return obj;
31
32
  }
32
33
  // If the object defines its own toJSON, prefer that.
@@ -34,7 +35,7 @@ function removeCircular(obj, refs = []) {
34
35
  return obj.toJSON();
35
36
  }
36
37
  if (refs.includes(obj)) {
37
- return '[Circular]';
38
+ return "[Circular]";
38
39
  }
39
40
  else {
40
41
  refs.push(obj);
@@ -48,7 +49,7 @@ function removeCircular(obj, refs = []) {
48
49
  }
49
50
  for (const k in obj) {
50
51
  if (refs.includes(obj[k])) {
51
- returnObj[k] = '[Circular]';
52
+ returnObj[k] = "[Circular]";
52
53
  }
53
54
  else {
54
55
  returnObj[k] = removeCircular(obj[k], refs);
@@ -62,23 +63,7 @@ function removeCircular(obj, refs = []) {
62
63
  * @public
63
64
  */
64
65
  function write(entry) {
65
- if (common_1.SUPPORTS_STRUCTURED_LOGS) {
66
- common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[entry.severity]](JSON.stringify(removeCircular(entry)));
67
- return;
68
- }
69
- let message = entry.message || '';
70
- const jsonPayload = {};
71
- let jsonKeyCount = 0;
72
- for (const k in entry) {
73
- if (!['severity', 'message'].includes(k)) {
74
- jsonKeyCount++;
75
- jsonPayload[k] = entry[k];
76
- }
77
- }
78
- if (jsonKeyCount > 0) {
79
- message = `${message} ${JSON.stringify(removeCircular(jsonPayload), null, 2)}`;
80
- }
81
- common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[entry.severity]](message);
66
+ common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[entry.severity]](JSON.stringify(removeCircular(entry)));
82
67
  }
83
68
  exports.write = write;
84
69
  /**
@@ -88,7 +73,7 @@ exports.write = write;
88
73
  * @public
89
74
  */
90
75
  function debug(...args) {
91
- write(entryFromArgs('DEBUG', args));
76
+ write(entryFromArgs("DEBUG", args));
92
77
  }
93
78
  exports.debug = debug;
94
79
  /**
@@ -98,7 +83,7 @@ exports.debug = debug;
98
83
  * @public
99
84
  */
100
85
  function log(...args) {
101
- write(entryFromArgs('INFO', args));
86
+ write(entryFromArgs("INFO", args));
102
87
  }
103
88
  exports.log = log;
104
89
  /**
@@ -108,7 +93,7 @@ exports.log = log;
108
93
  * @public
109
94
  */
110
95
  function info(...args) {
111
- write(entryFromArgs('INFO', args));
96
+ write(entryFromArgs("INFO", args));
112
97
  }
113
98
  exports.info = info;
114
99
  /**
@@ -118,7 +103,7 @@ exports.info = info;
118
103
  * @public
119
104
  */
120
105
  function warn(...args) {
121
- write(entryFromArgs('WARNING', args));
106
+ write(entryFromArgs("WARNING", args));
122
107
  }
123
108
  exports.warn = warn;
124
109
  /**
@@ -128,19 +113,28 @@ exports.warn = warn;
128
113
  * @public
129
114
  */
130
115
  function error(...args) {
131
- write(entryFromArgs('ERROR', args));
116
+ write(entryFromArgs("ERROR", args));
132
117
  }
133
118
  exports.error = error;
134
119
  /** @hidden */
135
120
  function entryFromArgs(severity, args) {
136
121
  let entry = {};
137
122
  const lastArg = args[args.length - 1];
138
- if (lastArg && typeof lastArg == 'object' && lastArg.constructor == Object) {
123
+ if (lastArg && typeof lastArg === "object" && lastArg.constructor === Object) {
139
124
  entry = args.pop();
140
125
  }
141
- return Object.assign({}, entry, {
126
+ const ctx = trace_1.traceContext.getStore();
127
+ // mimic `console.*` behavior, see https://nodejs.org/api/console.html#console_console_log_data_args
128
+ let message = (0, util_1.format)(...args);
129
+ if (severity === "ERROR" && !args.find((arg) => arg instanceof Error)) {
130
+ message = new Error(message).stack || message;
131
+ }
132
+ return {
133
+ "logging.googleapis.com/trace": (ctx === null || ctx === void 0 ? void 0 : ctx.traceId)
134
+ ? `projects/${process.env.GCLOUD_PROJECT}/traces/${ctx.traceId}`
135
+ : undefined,
136
+ ...entry,
142
137
  severity,
143
- // mimic `console.*` behavior, see https://nodejs.org/api/console.html#console_console_log_data_args
144
- message: util_1.format.apply(null, args),
145
- });
138
+ message,
139
+ };
146
140
  }
@@ -2,10 +2,31 @@
2
2
  * @hidden
3
3
  * @alpha
4
4
  */
5
- import { BooleanParam, Expression, FloatParam, IntParam, ListParam, Param, ParamOptions, SecretParam, StringParam } from './types';
5
+ import { BooleanParam, Expression, FloatParam, IntParam, Param, ParamOptions, SecretParam, StringParam } from "./types";
6
6
  export { ParamOptions, Expression };
7
7
  declare type SecretOrExpr = Param<any> | SecretParam;
8
8
  export declare const declaredParams: SecretOrExpr[];
9
+ /**
10
+ * A builtin param that resolves to the default RTDB database URL associated
11
+ * with the project, without prompting the deployer. Empty string if none exists.
12
+ */
13
+ export declare const databaseURL: Param<string>;
14
+ /**
15
+ * A builtin param that resolves to the Cloud project ID associated with
16
+ * the project, without prompting the deployer.
17
+ */
18
+ export declare const projectID: Param<string>;
19
+ /**
20
+ * A builtin param that resolves to the Cloud project ID, without prompting
21
+ * the deployer.
22
+ */
23
+ export declare const gcloudProject: Param<string>;
24
+ /**
25
+ * A builtin param that resolves to the Cloud storage bucket associated
26
+ * with the function, without prompting the deployer. Empty string if not
27
+ * defined.
28
+ */
29
+ export declare const storageBucket: Param<string>;
9
30
  /**
10
31
  * Declares a secret param, that will persist values only in Cloud Secret Manager.
11
32
  * Secrets are stored interally as bytestrings. Use ParamOptions.`as` to provide type
@@ -48,11 +69,3 @@ export declare function defineInt(name: string, options?: ParamOptions<number>):
48
69
  * @returns A Param with a `number` return type for `.value`.
49
70
  */
50
71
  export declare function defineFloat(name: string, options?: ParamOptions<number>): FloatParam;
51
- /**
52
- * Declare a list param (array of strings).
53
- *
54
- * @param name The name of the environment variable to use to load the param.
55
- * @param options Configuration options for the param.
56
- * @returns A Param with a `string[]` return type for `.value`.
57
- */
58
- export declare function defineList(name: string, options?: ParamOptions<string[]>): ListParam;
@@ -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.defineList = exports.defineFloat = exports.defineInt = exports.defineBoolean = exports.defineString = exports.defineSecret = exports.clearParams = exports.declaredParams = exports.Expression = void 0;
24
+ exports.defineFloat = exports.defineInt = exports.defineBoolean = exports.defineString = exports.defineSecret = exports.storageBucket = exports.gcloudProject = exports.projectID = exports.databaseURL = exports.clearParams = exports.declaredParams = exports.Expression = void 0;
25
25
  /**
26
26
  * @hidden
27
27
  * @alpha
@@ -50,6 +50,27 @@ function clearParams() {
50
50
  exports.declaredParams.splice(0, exports.declaredParams.length);
51
51
  }
52
52
  exports.clearParams = clearParams;
53
+ /**
54
+ * A builtin param that resolves to the default RTDB database URL associated
55
+ * with the project, without prompting the deployer. Empty string if none exists.
56
+ */
57
+ exports.databaseURL = new types_1.InternalExpression("DATABASE_URL", (env) => { var _a; return ((_a = JSON.parse(env.FIREBASE_CONFIG)) === null || _a === void 0 ? void 0 : _a.databaseURL) || ""; });
58
+ /**
59
+ * A builtin param that resolves to the Cloud project ID associated with
60
+ * the project, without prompting the deployer.
61
+ */
62
+ exports.projectID = new types_1.InternalExpression("PROJECT_ID", (env) => { var _a; return ((_a = JSON.parse(env.FIREBASE_CONFIG)) === null || _a === void 0 ? void 0 : _a.projectId) || ""; });
63
+ /**
64
+ * A builtin param that resolves to the Cloud project ID, without prompting
65
+ * the deployer.
66
+ */
67
+ exports.gcloudProject = new types_1.InternalExpression("GCLOUD_PROJECT", (env) => { var _a; return ((_a = JSON.parse(env.FIREBASE_CONFIG)) === null || _a === void 0 ? void 0 : _a.projectId) || ""; });
68
+ /**
69
+ * A builtin param that resolves to the Cloud storage bucket associated
70
+ * with the function, without prompting the deployer. Empty string if not
71
+ * defined.
72
+ */
73
+ exports.storageBucket = new types_1.InternalExpression("STORAGE_BUCKET", (env) => { var _a; return ((_a = JSON.parse(env.FIREBASE_CONFIG)) === null || _a === void 0 ? void 0 : _a.storageBucket) || ""; });
53
74
  /**
54
75
  * Declares a secret param, that will persist values only in Cloud Secret Manager.
55
76
  * Secrets are stored interally as bytestrings. Use ParamOptions.`as` to provide type
@@ -117,16 +138,3 @@ function defineFloat(name, options = {}) {
117
138
  return param;
118
139
  }
119
140
  exports.defineFloat = defineFloat;
120
- /**
121
- * Declare a list param (array of strings).
122
- *
123
- * @param name The name of the environment variable to use to load the param.
124
- * @param options Configuration options for the param.
125
- * @returns A Param with a `string[]` return type for `.value`.
126
- */
127
- function defineList(name, options = {}) {
128
- const param = new types_1.ListParam(name, options);
129
- registerParam(param);
130
- return param;
131
- }
132
- exports.defineList = defineList;