firebase-functions 4.2.0 → 4.2.1

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.
@@ -31,14 +31,9 @@ const path_1 = require("../../common/utilities/path");
31
31
  class DataSnapshot {
32
32
  constructor(data, path, // path is undefined for the database root
33
33
  app, instance) {
34
- var _a, _b;
35
34
  this.app = app;
36
35
  const config = (0, config_1.firebaseConfig)();
37
- if ((_b = (_a = app === null || app === void 0 ? void 0 : app.options) === null || _a === void 0 ? void 0 : _a.databaseURL) === null || _b === void 0 ? void 0 : _b.startsWith("http:")) {
38
- // In this case we're dealing with an emulator
39
- this.instance = app.options.databaseURL;
40
- }
41
- else if (instance) {
36
+ if (instance) {
42
37
  // SDK always supplies instance, but user's unit tests may not
43
38
  this.instance = instance;
44
39
  }
@@ -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.onCallHandler = exports.checkAuthToken = exports.unsafeDecodeAppCheckToken = exports.unsafeDecodeIdToken = exports.unsafeDecodeToken = exports.decode = exports.encode = exports.isValidRequest = exports.HttpsError = void 0;
24
+ exports.onCallHandler = exports.checkAuthToken = exports.unsafeDecodeAppCheckToken = exports.unsafeDecodeIdToken = exports.unsafeDecodeToken = exports.decode = exports.encode = exports.isValidRequest = exports.HttpsError = exports.ORIGINAL_AUTH_HEADER = exports.CALLABLE_AUTH_HEADER = void 0;
25
25
  const cors = require("cors");
26
26
  const logger = require("../../logger");
27
27
  // TODO(inlined): Decide whether we want to un-version apps or whether we want a
@@ -31,6 +31,10 @@ const auth_1 = require("firebase-admin/auth");
31
31
  const app_1 = require("../app");
32
32
  const debug_1 = require("../debug");
33
33
  const JWT_REGEX = /^[a-zA-Z0-9\-_=]+?\.[a-zA-Z0-9\-_=]+?\.([a-zA-Z0-9\-_=]+)?$/;
34
+ /** @internal */
35
+ exports.CALLABLE_AUTH_HEADER = "x-callable-context-auth";
36
+ /** @internal */
37
+ exports.ORIGINAL_AUTH_HEADER = "x-original-auth";
34
38
  /**
35
39
  * Standard error codes and HTTP statuses for different ways a request can fail,
36
40
  * as defined by:
@@ -382,6 +386,29 @@ function wrapOnCallHandler(options, handler) {
382
386
  throw new HttpsError("invalid-argument", "Bad Request");
383
387
  }
384
388
  const context = { rawRequest: req };
389
+ // TODO(colerogers): yank this when we release a breaking change of the CLI that removes
390
+ // our monkey-patching code referenced below and increases the minimum supported SDK version.
391
+ //
392
+ // Note: This code is needed to fix v1 callable functions in the emulator with a monorepo setup.
393
+ // The original monkey-patched code lived in the functionsEmulatorRuntime
394
+ // (link: https://github.com/firebase/firebase-tools/blob/accea7abda3cc9fa6bb91368e4895faf95281c60/src/emulator/functionsEmulatorRuntime.ts#L480)
395
+ // and was not compatible with how monorepos separate out packages (see https://github.com/firebase/firebase-tools/issues/5210).
396
+ if ((0, debug_1.isDebugFeatureEnabled)("skipTokenVerification") && handler.length === 2) {
397
+ const authContext = context.rawRequest.header(exports.CALLABLE_AUTH_HEADER);
398
+ if (authContext) {
399
+ logger.debug("Callable functions auth override", {
400
+ key: exports.CALLABLE_AUTH_HEADER,
401
+ value: authContext,
402
+ });
403
+ context.auth = JSON.parse(decodeURIComponent(authContext));
404
+ delete context.rawRequest.headers[exports.CALLABLE_AUTH_HEADER];
405
+ }
406
+ const originalAuth = context.rawRequest.header(exports.ORIGINAL_AUTH_HEADER);
407
+ if (originalAuth) {
408
+ context.rawRequest.headers["authorization"] = originalAuth;
409
+ delete context.rawRequest.headers[exports.ORIGINAL_AUTH_HEADER];
410
+ }
411
+ }
385
412
  const tokenStatus = await checkTokens(req, context);
386
413
  if (tokenStatus.auth === "INVALID") {
387
414
  throw new HttpsError("unauthenticated", "Unauthenticated");
@@ -121,7 +121,7 @@ export declare class ResultStorage {
121
121
  * - `USE_DESTINATION_ARTIFACTS`: One or more of the test targets defined in the
122
122
  * .xctestrun file specifies "UseDestinationArtifacts", which is disallowed.
123
123
  *
124
- * - `TEST_NON_APP_HOSTED`: XC tests which run on physical devices must have
124
+ * - `TEST_NOT_APP_HOSTED`: XC tests which run on physical devices must have
125
125
  * "IsAppHostedTestBundle" == "true" in the xctestrun file.
126
126
  *
127
127
  * - `PLIST_CANNOT_BE_PARSED`: An Info.plist file in the XCTest zip could not be
@@ -178,7 +178,7 @@ function onChangedOperation(eventType, referenceOrOpts, handler) {
178
178
  // wrap the handler
179
179
  const func = (raw) => {
180
180
  const event = raw;
181
- const instanceUrl = `https://${event.instance}.${event.firebasedatabasehost}`;
181
+ const instanceUrl = getInstance(event);
182
182
  const params = makeParams(event, pathPattern, instancePattern);
183
183
  const databaseEvent = makeChangedDatabaseEvent(event, instanceUrl, params);
184
184
  return (0, trace_1.wrapTraceContext)(handler)(databaseEvent);
@@ -196,7 +196,7 @@ function onOperation(eventType, referenceOrOpts, handler) {
196
196
  // wrap the handler
197
197
  const func = (raw) => {
198
198
  const event = raw;
199
- const instanceUrl = `https://${event.instance}.${event.firebasedatabasehost}`;
199
+ const instanceUrl = getInstance(event);
200
200
  const params = makeParams(event, pathPattern, instancePattern);
201
201
  const data = eventType === exports.deletedEventType ? event.data.data : event.data.delta;
202
202
  const databaseEvent = makeDatabaseEvent(event, data, instanceUrl, params);
@@ -207,3 +207,9 @@ function onOperation(eventType, referenceOrOpts, handler) {
207
207
  return func;
208
208
  }
209
209
  exports.onOperation = onOperation;
210
+ function getInstance(event) {
211
+ const emuHost = process.env.FIREBASE_DATABASE_EMULATOR_HOST;
212
+ return emuHost
213
+ ? `http://${emuHost}/?ns=${event.instance}`
214
+ : `https://${event.instance}.${event.firebasedatabasehost}`;
215
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",