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
@@ -22,38 +22,37 @@
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.ExportBundleInfo = exports.UserPropertyValue = exports.UserDimensions = exports.AnalyticsEvent = exports.AnalyticsEventBuilder = exports._eventWithOptions = exports.event = exports.service = exports.provider = void 0;
25
- const _ = require("lodash");
26
25
  const cloud_functions_1 = require("../cloud-functions");
27
- /** @hidden */
28
- exports.provider = 'google.analytics';
29
- /** @hidden */
30
- exports.service = 'app-measurement.com';
26
+ /** @internal */
27
+ exports.provider = "google.analytics";
28
+ /** @internal */
29
+ exports.service = "app-measurement.com";
31
30
  /**
32
31
  * Registers a function to handle analytics events.
33
32
  *
34
33
  * @param analyticsEventType Name of the analytics event type to which
35
34
  * this Cloud Function is scoped.
36
35
  *
37
- * @return Analytics event builder interface.
36
+ * @returns Analytics event builder interface.
38
37
  */
39
38
  function event(analyticsEventType) {
40
39
  return _eventWithOptions(analyticsEventType, {});
41
40
  }
42
41
  exports.event = event;
43
- /** @hidden */
42
+ /** @internal */
44
43
  function _eventWithOptions(analyticsEventType, options) {
45
44
  return new AnalyticsEventBuilder(() => {
46
45
  if (!process.env.GCLOUD_PROJECT) {
47
- throw new Error('process.env.GCLOUD_PROJECT is not set.');
46
+ throw new Error("process.env.GCLOUD_PROJECT is not set.");
48
47
  }
49
- return ('projects/' + process.env.GCLOUD_PROJECT + '/events/' + analyticsEventType);
48
+ return "projects/" + process.env.GCLOUD_PROJECT + "/events/" + analyticsEventType;
50
49
  }, options);
51
50
  }
52
51
  exports._eventWithOptions = _eventWithOptions;
53
52
  /**
54
53
  * The Firebase Analytics event builder interface.
55
54
  *
56
- * Access via [`functions.analytics.event()`](functions.analytics#.event).
55
+ * Access via `functions.analytics.event()`.
57
56
  */
58
57
  class AnalyticsEventBuilder {
59
58
  /** @hidden */
@@ -67,7 +66,7 @@ class AnalyticsEventBuilder {
67
66
  * @param handler Event handler that fires every time a Firebase Analytics event
68
67
  * occurs.
69
68
  *
70
- * @return A function that you can export and deploy.
69
+ * @returns A function that you can export and deploy.
71
70
  */
72
71
  onLog(handler) {
73
72
  const dataConstructor = (raw) => {
@@ -76,7 +75,7 @@ class AnalyticsEventBuilder {
76
75
  return (0, cloud_functions_1.makeCloudFunction)({
77
76
  handler,
78
77
  provider: exports.provider,
79
- eventType: 'event.log',
78
+ eventType: "event.log",
80
79
  service: exports.service,
81
80
  legacyEventType: `providers/google.firebase.analytics/eventTypes/event.log`,
82
81
  triggerResource: this.triggerResource,
@@ -94,14 +93,14 @@ class AnalyticsEvent {
94
93
  if (wireFormat.eventDim && wireFormat.eventDim.length > 0) {
95
94
  // If there's an eventDim, there'll always be exactly one.
96
95
  const eventDim = wireFormat.eventDim[0];
97
- copyField(eventDim, this, 'name');
98
- copyField(eventDim, this, 'params', (p) => _.mapValues(p, unwrapValue));
99
- copyFieldTo(eventDim, this, 'valueInUsd', 'valueInUSD');
100
- copyFieldTo(eventDim, this, 'date', 'reportingDate');
101
- copyTimestampToString(eventDim, this, 'timestampMicros', 'logTime');
102
- copyTimestampToString(eventDim, this, 'previousTimestampMicros', 'previousLogTime');
96
+ copyField(eventDim, this, "name");
97
+ copyField(eventDim, this, "params", (p) => mapKeys(p, unwrapValue));
98
+ copyFieldTo(eventDim, this, "valueInUsd", "valueInUSD");
99
+ copyFieldTo(eventDim, this, "date", "reportingDate");
100
+ copyTimestampToString(eventDim, this, "timestampMicros", "logTime");
101
+ copyTimestampToString(eventDim, this, "previousTimestampMicros", "previousLogTime");
103
102
  }
104
- copyFieldTo(wireFormat, this, 'userDim', 'user', (dim) => new UserDimensions(dim));
103
+ copyFieldTo(wireFormat, this, "userDim", "user", (dim) => new UserDimensions(dim));
105
104
  }
106
105
  }
107
106
  exports.AnalyticsEvent = AnalyticsEvent;
@@ -112,21 +111,19 @@ class UserDimensions {
112
111
  /** @hidden */
113
112
  constructor(wireFormat) {
114
113
  // These are interfaces or primitives, no transformation needed.
115
- copyFields(wireFormat, this, [
116
- 'userId',
117
- 'deviceInfo',
118
- 'geoInfo',
119
- 'appInfo',
120
- ]);
114
+ copyFields(wireFormat, this, ["userId", "deviceInfo", "geoInfo", "appInfo"]);
121
115
  // The following fields do need transformations of some sort.
122
- copyTimestampToString(wireFormat, this, 'firstOpenTimestampMicros', 'firstOpenTime');
116
+ copyTimestampToString(wireFormat, this, "firstOpenTimestampMicros", "firstOpenTime");
123
117
  this.userProperties = {}; // With no entries in the wire format, present an empty (as opposed to absent) map.
124
- copyField(wireFormat, this, 'userProperties', (r) => _.mapValues(r, (p) => new UserPropertyValue(p)));
125
- copyField(wireFormat, this, 'bundleInfo', (r) => new ExportBundleInfo(r));
118
+ copyField(wireFormat, this, "userProperties", (r) => {
119
+ const entries = Object.entries(r).map(([k, v]) => [k, new UserPropertyValue(v)]);
120
+ return Object.fromEntries(entries);
121
+ });
122
+ copyField(wireFormat, this, "bundleInfo", (r) => new ExportBundleInfo(r));
126
123
  // BUG(36000368) Remove when no longer necessary
127
124
  /* tslint:disable:no-string-literal */
128
- if (!this.userId && this.userProperties['user_id']) {
129
- this.userId = this.userProperties['user_id'].value;
125
+ if (!this.userId && this.userProperties["user_id"]) {
126
+ this.userId = this.userProperties["user_id"].value;
130
127
  }
131
128
  /* tslint:enable:no-string-literal */
132
129
  }
@@ -136,8 +133,8 @@ exports.UserDimensions = UserDimensions;
136
133
  class UserPropertyValue {
137
134
  /** @hidden */
138
135
  constructor(wireFormat) {
139
- copyField(wireFormat, this, 'value', unwrapValueAsString);
140
- copyTimestampToString(wireFormat, this, 'setTimestampUsec', 'setTime');
136
+ copyField(wireFormat, this, "value", unwrapValueAsString);
137
+ copyTimestampToString(wireFormat, this, "setTimestampUsec", "setTime");
141
138
  }
142
139
  }
143
140
  exports.UserPropertyValue = UserPropertyValue;
@@ -145,19 +142,24 @@ exports.UserPropertyValue = UserPropertyValue;
145
142
  class ExportBundleInfo {
146
143
  /** @hidden */
147
144
  constructor(wireFormat) {
148
- copyField(wireFormat, this, 'bundleSequenceId');
149
- copyTimestampToMillis(wireFormat, this, 'serverTimestampOffsetMicros', 'serverTimestampOffset');
145
+ copyField(wireFormat, this, "bundleSequenceId");
146
+ copyTimestampToMillis(wireFormat, this, "serverTimestampOffsetMicros", "serverTimestampOffset");
150
147
  }
151
148
  }
152
149
  exports.ExportBundleInfo = ExportBundleInfo;
153
150
  /** @hidden */
154
- function copyFieldTo(from, to, fromField, toField, transform = _.identity) {
155
- if (from[fromField] !== undefined) {
151
+ function copyFieldTo(from, to, fromField, toField, transform) {
152
+ if (typeof from[fromField] === "undefined") {
153
+ return;
154
+ }
155
+ if (transform) {
156
156
  to[toField] = transform(from[fromField]);
157
+ return;
157
158
  }
159
+ to[toField] = from[fromField];
158
160
  }
159
161
  /** @hidden */
160
- function copyField(from, to, field, transform = _.identity) {
162
+ function copyField(from, to, field, transform = (from) => from) {
161
163
  copyFieldTo(from, to, field, field, transform);
162
164
  }
163
165
  /** @hidden */
@@ -166,6 +168,10 @@ function copyFields(from, to, fields) {
166
168
  copyField(from, to, field);
167
169
  }
168
170
  }
171
+ function mapKeys(obj, transform) {
172
+ const entries = Object.entries(obj).map(([k, v]) => [k, transform(v)]);
173
+ return Object.fromEntries(entries);
174
+ }
169
175
  // The incoming payload will have fields like:
170
176
  // {
171
177
  // 'myInt': {
@@ -197,8 +203,8 @@ function copyFields(from, to, fields) {
197
203
  // 'unwrapValue' method just below.
198
204
  /** @hidden */
199
205
  function unwrapValueAsString(wrapped) {
200
- const key = _.keys(wrapped)[0];
201
- return _.toString(wrapped[key]);
206
+ const key = Object.keys(wrapped)[0];
207
+ return wrapped[key].toString();
202
208
  }
203
209
  // Ditto as the method above, but returning the values in the idiomatic JavaScript type (string for strings,
204
210
  // number for numbers):
@@ -214,12 +220,12 @@ function unwrapValueAsString(wrapped) {
214
220
  // JavaScript's 'number' type, since we prefer using idiomatic types. Note that this may lead to loss
215
221
  // in precision for int64 fields, so use with care.
216
222
  /** @hidden */
217
- const xValueNumberFields = ['intValue', 'floatValue', 'doubleValue'];
223
+ const xValueNumberFields = ["intValue", "floatValue", "doubleValue"];
218
224
  /** @hidden */
219
225
  function unwrapValue(wrapped) {
220
- const key = _.keys(wrapped)[0];
226
+ const key = Object.keys(wrapped)[0];
221
227
  const value = unwrapValueAsString(wrapped);
222
- return _.includes(xValueNumberFields, key) ? _.toNumber(value) : value;
228
+ return xValueNumberFields.includes(key) ? Number(value) : value;
223
229
  }
224
230
  // The JSON payload delivers timestamp fields as strings of timestamps denoted in microseconds.
225
231
  // The JavaScript convention is to use numbers denoted in milliseconds. This method
@@ -227,7 +233,7 @@ function unwrapValue(wrapped) {
227
233
  /** @hidden */
228
234
  function copyTimestampToMillis(from, to, fromName, toName) {
229
235
  if (from[fromName] !== undefined) {
230
- to[toName] = _.round(from[fromName] / 1000);
236
+ to[toName] = Math.round(from[fromName] / 1000);
231
237
  }
232
238
  }
233
239
  // The JSON payload delivers timestamp fields as strings of timestamps denoted in microseconds.
@@ -1,15 +1,9 @@
1
- import { BlockingFunction, CloudFunction, EventContext } from '../cloud-functions';
2
- import { AuthEventContext, AuthUserRecord, BeforeCreateResponse, BeforeSignInResponse, HttpsError, UserInfo, UserRecord, userRecordConstructor, UserRecordMetadata } from '../common/providers/identity';
3
- import { DeploymentOptions } from '../function-configuration';
1
+ import { AuthEventContext, AuthUserRecord, BeforeCreateResponse, BeforeSignInResponse, HttpsError, UserInfo, UserRecord, userRecordConstructor, UserRecordMetadata } from "../../common/providers/identity";
2
+ import { BlockingFunction, CloudFunction, EventContext } from "../cloud-functions";
4
3
  export { UserRecord, UserInfo, UserRecordMetadata, userRecordConstructor };
5
4
  export { HttpsError };
6
- /** @hidden */
7
- export declare const provider = "google.firebase.auth";
8
- /** @hidden */
9
- export declare const service = "firebaseauth.googleapis.com";
10
5
  /**
11
- * Resource level options
12
- * @public
6
+ * Options for Auth blocking function.
13
7
  */
14
8
  export interface UserOptions {
15
9
  /** Options to set configuration at the resource level for blocking functions. */
@@ -23,16 +17,16 @@ export interface UserOptions {
23
17
  };
24
18
  }
25
19
  /**
26
- * Handles events related to Firebase authentication users.
20
+ * Handles events related to Firebase Auth users events.
21
+ *
27
22
  * @param userOptions - Resource level options
28
- * @returns UserBuilder - Builder used to create Cloud Functions for Firebase Auth user lifecycle events
23
+ * @returns UserBuilder - Builder used to create functions for Firebase Auth user lifecycle events
24
+ *
29
25
  * @public
30
26
  */
31
27
  export declare function user(userOptions?: UserOptions): UserBuilder;
32
- /** @hidden */
33
- export declare function _userWithOptions(options: DeploymentOptions, userOptions: UserOptions): UserBuilder;
34
28
  /**
35
- * Builder used to create Cloud Functions for Firebase Auth user lifecycle events.
29
+ * Builder used to create functions for Firebase Auth user lifecycle events.
36
30
  * @public
37
31
  */
38
32
  export declare class UserBuilder {
@@ -40,22 +34,38 @@ export declare class UserBuilder {
40
34
  private options;
41
35
  private userOptions?;
42
36
  private static dataConstructor;
43
- /** @hidden */
44
- constructor(triggerResource: () => string, options: DeploymentOptions, userOptions?: UserOptions);
45
37
  /**
46
38
  * Responds to the creation of a Firebase Auth user.
39
+ *
40
+ * @param handler Event handler that responds to the creation of a Firebase Auth user.
41
+ *
47
42
  * @public
48
43
  */
49
44
  onCreate(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
50
45
  /**
51
46
  * Responds to the deletion of a Firebase Auth user.
47
+ *
48
+ * @param handler Event handler that responds to the deletion of a Firebase Auth user.
49
+ *
52
50
  * @public
53
51
  */
54
52
  onDelete(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
53
+ /**
54
+ * Blocks request to create a Firebase Auth user.
55
+ *
56
+ * @param handler Event handler that blocks creation of a Firebase Auth user.
57
+ *
58
+ * @public
59
+ */
55
60
  beforeCreate(handler: (user: AuthUserRecord, context: AuthEventContext) => BeforeCreateResponse | void | Promise<BeforeCreateResponse> | Promise<void>): BlockingFunction;
61
+ /**
62
+ * Blocks request to sign-in a Firebase Auth user.
63
+ *
64
+ * @param handler Event handler that blocks sign-in of a Firebase Auth user.
65
+ *
66
+ * @public
67
+ */
56
68
  beforeSignIn(handler: (user: AuthUserRecord, context: AuthEventContext) => BeforeSignInResponse | void | Promise<BeforeSignInResponse> | Promise<void>): BlockingFunction;
57
- /** @hidden */
58
69
  private onOperation;
59
- /** @hidden */
60
70
  private beforeOperation;
61
71
  }
@@ -22,41 +22,44 @@
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.UserBuilder = exports._userWithOptions = exports.user = exports.service = exports.provider = exports.HttpsError = exports.userRecordConstructor = exports.UserRecordMetadata = void 0;
25
- const cloud_functions_1 = require("../cloud-functions");
26
- const identity_1 = require("../common/providers/identity");
25
+ const identity_1 = require("../../common/providers/identity");
27
26
  Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return identity_1.HttpsError; } });
28
27
  Object.defineProperty(exports, "userRecordConstructor", { enumerable: true, get: function () { return identity_1.userRecordConstructor; } });
29
28
  Object.defineProperty(exports, "UserRecordMetadata", { enumerable: true, get: function () { return identity_1.UserRecordMetadata; } });
30
- /** @hidden */
31
- exports.provider = 'google.firebase.auth';
32
- /** @hidden */
33
- exports.service = 'firebaseauth.googleapis.com';
29
+ const cloud_functions_1 = require("../cloud-functions");
30
+ const manifest_1 = require("../../runtime/manifest");
31
+ /** @internal */
32
+ exports.provider = "google.firebase.auth";
33
+ /** @internal */
34
+ exports.service = "firebaseauth.googleapis.com";
34
35
  /**
35
- * Handles events related to Firebase authentication users.
36
+ * Handles events related to Firebase Auth users events.
37
+ *
36
38
  * @param userOptions - Resource level options
37
- * @returns UserBuilder - Builder used to create Cloud Functions for Firebase Auth user lifecycle events
39
+ * @returns UserBuilder - Builder used to create functions for Firebase Auth user lifecycle events
40
+ *
38
41
  * @public
39
42
  */
40
43
  function user(userOptions) {
41
44
  return _userWithOptions({}, userOptions || {});
42
45
  }
43
46
  exports.user = user;
44
- /** @hidden */
47
+ /** @internal */
45
48
  function _userWithOptions(options, userOptions) {
46
49
  return new UserBuilder(() => {
47
50
  if (!process.env.GCLOUD_PROJECT) {
48
- throw new Error('process.env.GCLOUD_PROJECT is not set.');
51
+ throw new Error("process.env.GCLOUD_PROJECT is not set.");
49
52
  }
50
- return 'projects/' + process.env.GCLOUD_PROJECT;
53
+ return "projects/" + process.env.GCLOUD_PROJECT;
51
54
  }, options, userOptions);
52
55
  }
53
56
  exports._userWithOptions = _userWithOptions;
54
57
  /**
55
- * Builder used to create Cloud Functions for Firebase Auth user lifecycle events.
58
+ * Builder used to create functions for Firebase Auth user lifecycle events.
56
59
  * @public
57
60
  */
58
61
  class UserBuilder {
59
- /** @hidden */
62
+ /* @internal */
60
63
  constructor(triggerResource, options, userOptions) {
61
64
  this.triggerResource = triggerResource;
62
65
  this.options = options;
@@ -67,25 +70,44 @@ class UserBuilder {
67
70
  }
68
71
  /**
69
72
  * Responds to the creation of a Firebase Auth user.
73
+ *
74
+ * @param handler Event handler that responds to the creation of a Firebase Auth user.
75
+ *
70
76
  * @public
71
77
  */
72
78
  onCreate(handler) {
73
- return this.onOperation(handler, 'user.create');
79
+ return this.onOperation(handler, "user.create");
74
80
  }
75
81
  /**
76
82
  * Responds to the deletion of a Firebase Auth user.
83
+ *
84
+ * @param handler Event handler that responds to the deletion of a Firebase Auth user.
85
+ *
77
86
  * @public
78
87
  */
79
88
  onDelete(handler) {
80
- return this.onOperation(handler, 'user.delete');
89
+ return this.onOperation(handler, "user.delete");
81
90
  }
91
+ /**
92
+ * Blocks request to create a Firebase Auth user.
93
+ *
94
+ * @param handler Event handler that blocks creation of a Firebase Auth user.
95
+ *
96
+ * @public
97
+ */
82
98
  beforeCreate(handler) {
83
- return this.beforeOperation(handler, 'beforeCreate');
99
+ return this.beforeOperation(handler, "beforeCreate");
84
100
  }
101
+ /**
102
+ * Blocks request to sign-in a Firebase Auth user.
103
+ *
104
+ * @param handler Event handler that blocks sign-in of a Firebase Auth user.
105
+ *
106
+ * @public
107
+ */
85
108
  beforeSignIn(handler) {
86
- return this.beforeOperation(handler, 'beforeSignIn');
109
+ return this.beforeOperation(handler, "beforeSignIn");
87
110
  }
88
- /** @hidden */
89
111
  onOperation(handler, eventType) {
90
112
  return (0, cloud_functions_1.makeCloudFunction)({
91
113
  handler,
@@ -93,12 +115,12 @@ class UserBuilder {
93
115
  eventType,
94
116
  service: exports.service,
95
117
  triggerResource: this.triggerResource,
118
+ // eslint-disable-next-line @typescript-eslint/unbound-method
96
119
  dataConstructor: UserBuilder.dataConstructor,
97
120
  legacyEventType: `providers/firebase.auth/eventTypes/${eventType}`,
98
121
  options: this.options,
99
122
  });
100
123
  }
101
- /** @hidden */
102
124
  beforeOperation(handler, eventType) {
103
125
  var _a, _b, _c, _d, _e, _f;
104
126
  const accessToken = ((_b = (_a = this.userOptions) === null || _a === void 0 ? void 0 : _a.blockingOptions) === null || _b === void 0 ? void 0 : _b.accessToken) || false;
@@ -109,21 +131,10 @@ class UserBuilder {
109
131
  const wrappedHandler = (user, context) => handler(user, context);
110
132
  const func = (0, identity_1.wrapHandler)(eventType, wrappedHandler);
111
133
  const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
112
- func.__trigger = {
113
- labels: {},
114
- ...(0, cloud_functions_1.optionsToTrigger)(this.options),
115
- blockingTrigger: {
116
- eventType: legacyEventType,
117
- options: {
118
- accessToken,
119
- idToken,
120
- refreshToken,
121
- },
122
- },
123
- };
124
134
  func.__endpoint = {
125
- platform: 'gcfv1',
135
+ platform: "gcfv1",
126
136
  labels: {},
137
+ ...(0, manifest_1.initV1Endpoint)(this.options),
127
138
  ...(0, cloud_functions_1.optionsToEndpoint)(this.options),
128
139
  blockingTrigger: {
129
140
  eventType: legacyEventType,
@@ -136,8 +147,8 @@ class UserBuilder {
136
147
  };
137
148
  func.__requiredAPIs = [
138
149
  {
139
- api: 'identitytoolkit.googleapis.com',
140
- reason: 'Needed for auth blocking functions',
150
+ api: "identitytoolkit.googleapis.com",
151
+ reason: "Needed for auth blocking functions",
141
152
  },
142
153
  ];
143
154
  func.run = handler;
@@ -1,17 +1,14 @@
1
- import { apps } from '../apps';
2
- import { CloudFunction, EventContext } from '../cloud-functions';
3
- import { Change } from '../common/change';
4
- import { DataSnapshot } from '../common/providers/database';
5
- import { DeploymentOptions } from '../function-configuration';
1
+ import { Change } from "../../common/change";
2
+ import { ParamsOf } from "../../common/params";
3
+ import { DataSnapshot } from "../../common/providers/database";
4
+ import { CloudFunction, EventContext } from "../cloud-functions";
5
+ import { DeploymentOptions } from "../function-configuration";
6
6
  export { DataSnapshot };
7
- /** @hidden */
8
- export declare const provider = "google.firebase.database";
9
- /** @hidden */
10
- export declare const service = "firebaseio.com";
11
7
  /**
12
8
  * Registers a function that triggers on events from a specific
13
9
  * Firebase Realtime Database instance.
14
10
  *
11
+ * @remarks
15
12
  * Use this method together with `ref` to specify the instance on which to
16
13
  * watch for database events. For example: `firebase.database.instance('my-app-db-2').ref('/foo/bar')`
17
14
  *
@@ -20,13 +17,14 @@ export declare const service = "firebaseio.com";
20
17
  *
21
18
  * @param instance The instance name of the database instance
22
19
  * to watch for write events.
23
- * @return Firebase Realtime Database instance builder interface.
20
+ * @returns Firebase Realtime Database instance builder interface.
24
21
  */
25
22
  export declare function instance(instance: string): InstanceBuilder;
26
23
  /**
27
24
  * Registers a function that triggers on Firebase Realtime Database write
28
25
  * events.
29
26
  *
27
+ * @remarks
30
28
  * This method behaves very similarly to the method of the same name in the
31
29
  * client and Admin Firebase SDKs. Any change to the Database that affects the
32
30
  * data at or below the provided `path` will fire an event in Cloud Functions.
@@ -34,6 +32,7 @@ export declare function instance(instance: string): InstanceBuilder;
34
32
  * There are three important differences between listening to a Realtime
35
33
  * Database event in Cloud Functions and using the Realtime Database in the
36
34
  * client and Admin SDKs:
35
+ *
37
36
  * 1. Cloud Functions allows wildcards in the `path` name. Any `path` component
38
37
  * in curly brackets (`{}`) is a wildcard that matches all strings. The value
39
38
  * that matched a certain invocation of a Cloud Function is returned as part
@@ -42,18 +41,18 @@ export declare function instance(instance: string): InstanceBuilder;
42
41
  * `/messages/message1` or `/messages/message2`, resulting in
43
42
  * `event.params.messageId` being set to `"message1"` or `"message2"`,
44
43
  * respectively.
44
+ *
45
45
  * 2. Cloud Functions do not fire an event for data that already existed before
46
46
  * the Cloud Function was deployed.
47
+ *
47
48
  * 3. Cloud Function events have access to more information, including a
48
49
  * snapshot of the previous event data and information about the user who
49
50
  * triggered the Cloud Function.
50
51
  *
51
52
  * @param path The path within the Database to watch for write events.
52
- * @return Firebase Realtime Database builder interface.
53
+ * @returns Firebase Realtime Database builder interface.
53
54
  */
54
- export declare function ref(path: string): RefBuilder;
55
- /** @hidden */
56
- export declare function _instanceWithOptions(instance: string, options: DeploymentOptions): InstanceBuilder;
55
+ export declare function ref<Ref extends string>(path: Ref): RefBuilder<Ref>;
57
56
  /**
58
57
  * The Firebase Realtime Database instance builder interface.
59
58
  *
@@ -62,73 +61,57 @@ export declare function _instanceWithOptions(instance: string, options: Deployme
62
61
  export declare class InstanceBuilder {
63
62
  private instance;
64
63
  private options;
65
- /** @hidden */
66
64
  constructor(instance: string, options: DeploymentOptions);
67
65
  /**
68
- * @return Firebase Realtime Database reference builder interface.
66
+ * @returns Firebase Realtime Database reference builder interface.
69
67
  */
70
- ref(path: string): RefBuilder;
68
+ ref<Ref extends string>(path: Ref): RefBuilder<Ref>;
71
69
  }
72
- /** @hidden */
73
- export declare function _refWithOptions(path: string, options: DeploymentOptions): RefBuilder;
74
70
  /**
75
71
  * The Firebase Realtime Database reference builder interface.
76
72
  *
77
73
  * Access via [`functions.database.ref()`](functions.database#.ref).
78
74
  */
79
- export declare class RefBuilder {
80
- private apps;
75
+ export declare class RefBuilder<Ref extends string> {
81
76
  private triggerResource;
82
77
  private options;
83
- /** @hidden */
84
- constructor(apps: apps.Apps, triggerResource: () => string, options: DeploymentOptions);
78
+ constructor(triggerResource: () => string, options: DeploymentOptions);
85
79
  /**
86
80
  * Event handler that fires every time a Firebase Realtime Database write
87
81
  * of any kind (creation, update, or delete) occurs.
88
82
  *
89
83
  * @param handler Event handler that runs every time a Firebase Realtime Database
90
84
  * write occurs.
91
- * @return A Cloud Function that you can export and deploy.
85
+ * @returns A function that you can export and deploy.
92
86
  */
93
- onWrite(handler: (change: Change<DataSnapshot>, context: EventContext) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;
87
+ onWrite(handler: (change: Change<DataSnapshot>, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;
94
88
  /**
95
89
  * Event handler that fires every time data is updated in
96
90
  * Firebase Realtime Database.
97
91
  *
98
92
  * @param handler Event handler which is run every time a Firebase Realtime Database
99
93
  * write occurs.
100
- * @return A Cloud
101
- * Function which you can export and deploy.
94
+ * @returns A function which you can export and deploy.
102
95
  */
103
- onUpdate(handler: (change: Change<DataSnapshot>, context: EventContext) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;
96
+ onUpdate(handler: (change: Change<DataSnapshot>, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;
104
97
  /**
105
98
  * Event handler that fires every time new data is created in
106
99
  * Firebase Realtime Database.
107
100
  *
108
101
  * @param handler Event handler that runs every time new data is created in
109
102
  * Firebase Realtime Database.
110
- * @return A Cloud Function that you can export and deploy.
103
+ * @returns A function that you can export and deploy.
111
104
  */
112
- onCreate(handler: (snapshot: DataSnapshot, context: EventContext) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;
105
+ onCreate(handler: (snapshot: DataSnapshot, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;
113
106
  /**
114
107
  * Event handler that fires every time data is deleted from
115
108
  * Firebase Realtime Database.
116
109
  *
117
110
  * @param handler Event handler that runs every time data is deleted from
118
111
  * Firebase Realtime Database.
119
- * @return A Cloud Function that you can export and deploy.
112
+ * @returns A function that you can export and deploy.
120
113
  */
121
- onDelete(handler: (snapshot: DataSnapshot, context: EventContext) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;
114
+ onDelete(handler: (snapshot: DataSnapshot, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;
122
115
  private onOperation;
123
116
  private changeConstructor;
124
117
  }
125
- /**
126
- * Utility function to extract database reference from resource string
127
- *
128
- * @param optional database domain override for the original of the source database.
129
- * It defaults to `firebaseio.com`.
130
- * Multi-region RTDB will be served from different domains.
131
- * Since region is not part of the resource name, it is provided through context.
132
- */
133
- /** @hidden */
134
- export declare function extractInstanceAndPath(resource: string, domain?: string): string[];