Socket
Socket
Sign inDemoInstall

@google-cloud/debug-agent

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/debug-agent - npm Package Compare versions

Comparing version 7.2.1 to 7.2.2

74

build/src/agent/firebase-controller.js

@@ -27,2 +27,12 @@ "use strict";

const FIREBASE_APP_NAME = 'cdbg';
/**
* Waits ms milliseconds for the promise to resolve, or rejects with a timeout.
* @param ms
* @param promise
* @returns Promise wrapped in a timeout.
*/
const withTimeout = (ms, promise) => {
const timeout = new Promise((_, reject) => setTimeout(() => reject(`Timed out after ${ms} ms.`), ms));
return Promise.race([promise, timeout]);
};
class FirebaseController {

@@ -59,42 +69,44 @@ /**

// Build the database URL.
let databaseUrl;
const databaseUrls = [];
if (options.databaseUrl) {
databaseUrl = options.databaseUrl;
databaseUrls.push(options.databaseUrl);
}
else {
// TODO: Add fallback to -default
databaseUrl = `https://${projectId}-cdbg.firebaseio.com`;
databaseUrls.push(`https://${projectId}-cdbg.firebaseio.com`);
databaseUrls.push(`https://${projectId}-default-rtdb.firebaseio.com`);
}
let app;
if (credential) {
app = firebase.initializeApp({
credential: credential,
databaseURL: databaseUrl,
}, FIREBASE_APP_NAME);
}
else {
// Use the default credentials.
app = firebase.initializeApp({
databaseURL: databaseUrl,
}, FIREBASE_APP_NAME);
}
const db = firebase.database(app);
// Test the connection by reading the schema version.
try {
const version_snapshot = await db.ref('cdbg/schema_version').get();
if (version_snapshot) {
const version = version_snapshot.val();
debuglog(`Firebase app initialized. Connected to ${databaseUrl}` +
` with schema version ${version}`);
for (const databaseUrl of databaseUrls) {
let app;
if (credential) {
app = firebase.initializeApp({
credential: credential,
databaseURL: databaseUrl,
}, FIREBASE_APP_NAME);
}
else {
// Use the default credentials.
app = firebase.initializeApp({
databaseURL: databaseUrl,
}, FIREBASE_APP_NAME);
}
const db = firebase.database(app);
// Test the connection by reading the schema version.
try {
const version_snapshot = await withTimeout(10000, db.ref('cdbg/schema_version').get());
if (version_snapshot) {
const version = version_snapshot.val();
debuglog(`Firebase app initialized. Connected to ${databaseUrl}` +
` with schema version ${version}`);
return db;
}
else {
throw new Error('failed to fetch schema version from database');
}
}
catch (e) {
debuglog(`failed to connect to database ${databaseUrl}: ` + e);
app.delete();
throw new Error('failed to fetch schema version from database');
}
}
catch (e) {
app.delete();
throw e;
}
return db;
throw new Error(`Failed to initialize FirebaseApp, attempted URLs: ${databaseUrls}`);
}

@@ -101,0 +113,0 @@ /**

{
"name": "@google-cloud/debug-agent",
"version": "7.2.1",
"version": "7.2.2",
"author": "Google Inc.",

@@ -48,2 +48,3 @@ "description": "Stackdriver Debug Agent for Node.js",

"@google-cloud/common": "^4.0.0",
"@fastify/busboy": "1.1.0",
"acorn": "^8.0.0",

@@ -61,2 +62,7 @@ "coffeescript": "^2.0.0",

},
"overrides": {
"firebase-admin": {
"@fastify/busboy": "1.1.0"
}
},
"devDependencies": {

@@ -63,0 +69,0 @@ "@compodoc/compodoc": "1.1.19",

@@ -102,11 +102,8 @@ [//]: # "This README.md file is auto-generated, all changes to this file will be lost."

## Firebase Realtime Database backend
## Snapshot Debugger - Firebase Realtime Database Backend
The Cloud Debugger API is deprecated and will be turned down in May 2023.
This functionality is available for release 6.0.0 onward of this agent and
provides support for the Snapshot Debugger, which is being provided as a
replacement for the deprecated Cloud Debugger service.
You can use Firebase Realtime Database for data persistence as an
alternative.
### Enabling the agent
To enable the agent, add the following at the top of your app's main script

@@ -124,14 +121,10 @@ or entry point:

The following params are optional:
* firebaseDbUrl - https://**PROJECT_ID**-cdbg.firebaseio.com will be used if not
provided. where **PROJECT_ID** is your project ID.
* firebaseDbUrl - https://**PROJECT_ID**-cdbg.firebaseio.com will be used if
not provided. where **PROJECT_ID** is your project ID.
* firebaseKeyPath - Default google application credentials are used if not
provided.
### Using the Debugger
See https://github.com/GoogleCloudPlatform/snapshot-debugger and
https://cloud.google.com/debugger/docs/deprecations for more details.
Using the Debugger with the Firebase Realtime Database backend requires using
the Snapshot Debugger CLI.
See the [full Snapshot Debugger CLI documentation][snapshot-debugger-readme].
## Limitations and Requirements

@@ -138,0 +131,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc