Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
earthtoday-couchdb-client
Advanced tools
This typescript module is copied from another dude, feel free to copy it again
A typescript package built around the CouchDB API for NodeJS using OOP practices. The foundation of this repo was inspired by pmorjan/couchdb-promise!
npm i earthtoday-couchdb-client
Once the package is installed, you just need to import it and use it!
import { CouchDB } from 'earthtoday-couchdb-client';
// Instatiate new CouchDB request class
const couchDb = new CouchDb({
auth: {
username: 'admin',
password: 'password'
}
});
Parameters:
Request Example:
new CouchDb({
host: 'https://couchdb.example.com';
port: 1433;
auth: {
username: 'admin',
password: 'password'
},
logging: true
defaultDatabase: 'test'
})
Whenever the API makes a call and runs into a catch block, you will get an error block that looks consistently like this:
{
error: Error
status: 500,
message: 'Internal Server Error',
duration: 300
}
This is essentially a "ping" endpoint .. just returns basic information if the server is up.
Request Example:
couchDb.getInfo()
Response Example:
{
"couchdb": "Welcome",
"uuid": "85fb71bf700c17267fef77535820e371",
"vendor": {
"name": "The Apache Software Foundation",
"version": "1.3.1"
},
"version": "1.3.1"
}
This endpoint just returns an array of all the database names
Request Example:
couchDb.getDatabases()
Response Example:
[
"_users",
"contacts",
"docs",
"invoices",
"locations"
]
Gets information about the specified database.
Parameters:
Request Example:
couchDb.getDatabase('testDB')
Response Example:
{
"db_name": "test",
"update_seq": "37-g1AAAABXeJ",
"sizes": {
"file": 172428,
"external": 3427,
"active": 13135
},
"purge_seq": 0,
"other": {
"data_size": 3427
},
"doc_del_count": 5,
"doc_count": 23,
"disk_size": 172428,
"disk_format_version": 6,
"data_size": 13135,
"compact_running": false,
"instance_start_time": "0"
}
Gets the revision limit for the specified database.
Parameters:
Request Example:
couchDb.getDatabaseRevisionLimit('testDB')
Response Example:
2
Creates a new database. If a revisionLimit is passed to the options object it will also set the revision limit for that database. The database name {db} must be composed by following next rules:
Parameters:
Request Example:
couchDb.createDatabase('testDB', { revisionLimit: 2 })
Response Example:
{
"ok": true
}
Returns the HTTP Headers containing a minimal amount of information about the specified database. Since the response body is empty, using the HEAD method is a lightweight way to check if the database exists already or not.
Parameters:
Request Example:
couchDb.checkDatabaseExists('testDB')
Response: This just returns a boolean if the database exists or not.
Response Example:
true
Request compaction of the specified database. Compaction compresses the disk database file by writing a new optimized version of the database and removing any old revisions, up to the database specific revision limit.
Parameters:
Request Example:
couchDb.compactDatabase('testDB')
Response Example:
{
"ok": true
}
Set the revision limit on the specified database.
Parameters:
Request Example:
couchDb.setDatabaseRevisionLimit('testDB', 2)
Response Example:
{
"ok": true
}
Deletes the specified database, and all the documents and attachments contained within it.
Parameters:
Request Example:
couchDb.deleteDatabase('testDB')
Response Example:
{
"ok": true
}
Sets the security object for the given database. Use the member permissions to lock down this database to either a username or role.
Parameters:
Request Example:
couchDb.updateDatabaseSecurity({
dbName: 'testDB',
admins: {
names: ['johnsmith']
},
members: {
names: ['johnsmith']
}
})
Response Example:
{
"ok": true,
}
This will create a member user which would be used to help lock down a database
Parameters:
Request Example:
couchDb.createUser({
username: 'johnsmith',
password: 'password',
roles: [
'reporter'
]
})
Response Example:
{
"ok": true,
"id": "org.couchdb.user:johnsmith",
"rev": "1-c7b59092b8e3e85eed24cce19e9350f7"
}
Returns a boolean for if the user exists or not.
Parameters:
Request Example:
couchDb.checkUserExists(username)
Response: This just returns a boolean if the database exists or not.
Response Example:
true
Returns document by the specified docid from the specified db. Unless you request a specific revision, the latest revision of the document will always be returned.
Parameters (All optional):
Request Example:
couchDb.getDocument({
dbName: 'testDB',
docId: '4342-432432-432432-4324'
})
Response:
Response Example:
{
"id": "16e458537602f5ef2a710089dffd9453",
"rev": "1-967a00dff5e02add41819138abb3284d"
}
Find documents using a declarative JSON querying syntax. Queries can use the built-in _all_docs index or custom indices, specified using the _index endpoint.
Parameters:
Request Example:
couchDb.findDocuments({
dbName: 'testDB',
findOptions: {
selector: {
year: {'$gt': 2010}
},
fields: ['_id', '_rev', 'year', 'title'],
sort: [{year: 'asc'}],
limit: 2,
skip: 0,
execution_stats: true
}
})
Response:
Response Example:
{
"docs": [
{
"_id": "176694",
"_rev": "1-54f8e950cc338d2385d9b0cda2fd918e",
"year": 2011,
"title": "The Tragedy of Man"
},
{
"_id": "780504",
"_rev": "1-5f14bab1a1e9ac3ebdf85905f47fb084",
"year": 2011,
"title": "Drive"
},
...
],
"execution_stats": {
"total_keys_examined": 0,
"total_docs_examined": 200,
"total_quorum_docs_examined": 0,
"results_returned": 2,
"execution_time_ms": 5.52
}
}
Returns a JSON structure of all of the documents in a given database. The information is returned as a JSON structure containing meta information about the return structure, including a list of all documents and basic contents, consisting the ID, revision and key. The key is the from the document’s _id.
Parameters (All optional):
Request Example:
couchDb.getDocuments({
dbName: 'testDB',
options: {
startKey: 'user'
}
})
Response:
Response Example:
{
"offset": 0,
"rows": [
{
"id": "16e458537602f5ef2a710089dffd9453",
"key": "16e458537602f5ef2a710089dffd9453",
"value": {
"rev": "1-967a00dff5e02add41819138abb3284d"
}
},
{
"id": "a4c51cdfa2069f3e905c431114001aff",
"key": "a4c51cdfa2069f3e905c431114001aff",
"value": {
"rev": "1-967a00dff5e02add41819138abb3284d"
}
},
{
"id": "a4c51cdfa2069f3e905c4311140034aa",
"key": "a4c51cdfa2069f3e905c4311140034aa",
"value": {
"rev": "5-6182c9c954200ab5e3c6bd5e76a1549f"
}
}
],
"total_rows": 3
}
Returns document by the specified docid from the specified db. Unless you request a specific revision, the latest revision of the document will always be returned.
Parameters (All optional):
Request Example:
couchDb.getDocument({
dbName: 'testDB',
docId: '4342-432432-432432-4324'
})
Response:
Response Example:
{
"id": "16e458537602f5ef2a710089dffd9453",
"rev": "1-967a00dff5e02add41819138abb3284d"
}
Returns the HTTP Headers containing a minimal amount of information about the specified document. The method supports the same query arguments as the GET /{db}/{docid} method, but only the header information (including document size, and the revision as an ETag), is returned.
The ETag header shows the current revision for the requested document, and the Content-Length specifies the length of the data, if the document were requested in full.
Adding any of the query arguments (see GET /{db}/{docid}), then the resulting HTTP Headers will correspond to what would be returned.
Parameters:
Request Example:
couchDb.checkDocumentExists({
dbName: 'testDB',
docId: 'user'
})
Response: This just returns a boolean if the database exists or not.
Response Example:
true
The COPY (which is non-standard HTTP) copies an existing document to a new or existing document. Copying a document is only possible within the same database.
The source document is specified on the request line, with the Destination header of the request specifying the target document.
Parameters:
Request Example:
couchDb.copyDocuments({
dbName: 'testDB',
docId: 'user',
newDocId: 'newUser'
})
Response Example:
{
"id": "newUser",
"ok": true,
"rev": "1-e86fdf912560c2321a5fcefc6264e6d9"
}
Creates a new document in the specified database, using the supplied JSON document structure. It will also, create the document under the docId if specified.
If the JSON structure includes the _id field, then the document will be created with the specified document ID.
If the _id field is not specified, a new unique ID will be generated, following whatever UUID algorithm is configured for that server.
Parameters:
Request Example:
couchDb.createDocument({
dbName: 'testDB',
doc: {
firstName: 'John',
lastName: 'Doe'
},
docId: 'currentUser'
})
Response Example:
{
"id": "currentUser"
"ok": true,
"rev": "1-9c65296036141e575d32ba9c034dd3ee"
}
When updating an existing document, the current document revision must be included in the document (i.e. the request body), as the rev query parameter, or in the If-Match request header.
Parameters:
Request Example:
couchDb.updateDocument({
dbName: 'testDB',
docId: 'currentUser',
rev: "1-9c65296036141e575d32ba9c034dd3ee",
updatedDoc: {
firstName: 'John',
lastName: 'Doe'
}
})
// or
couchDb.updateDocument({
dbName: 'testDB',
docId: 'currentUser',
updatedDoc: {
_rev: "1-9c65296036141e575d32ba9c034dd3ee",
firstName: 'John',
lastName: 'Doe'
}
})
Response Example:
{
"id": "currentUser"
"ok": true,
"rev": "1-9c65296036141e575d32ba9c034dd3ee"
}
The bulk document API allows you to create multiple documents at the same time within a single request. The basic operation is similar to creating single document, except that you batch the document structure and information. When creating new documents the document ID (_id
) is optional.
Parameters:
Request Example:
couchDb.upsertDocuments({
dbName: 'testDB',
docs: [{
firstName: 'John',
lastName: 'Doe'
}, {
_id: '3f32022a25e9b2b81b67a766b9004517',
_rev: '2-d538c7aaebdf4eb144b5d0070d3165ba',
firstName: 'Jan',
lastName: 'Doe'
}]
})
Response Example:
{
"ok": true
}
Marks the specified document as deleted by adding a field _deleted with the value true. Documents with this field will not be returned within requests anymore, but stay in the database. You must supply the current (latest) revision
Parameters:
Request Example:
couchDb.deleteDocument({
dbName: 'testDB',
docId: 'currentUser',
rev: '1-9c65296036141e575d32ba9c034dd3ee'
})
Response Example:
{
"id": "currentUser",
"ok": true,
"rev": "1-9c65296036141e575d32ba9c034dd3ee"
}
Requests one or more Universally Unique Identifiers (UUIDs) from the CouchDB instance. The response is a JSON object providing a list of UUIDs.
Parameters:
Request Example:
couchDb.getUuids(2)
Response Example:
{
"uuids":[
"6e1295ed6c29495e54cc05947f18c8af",
"4325432rfdf432weds3r4tregf454fg4"
]
}
To come later
To come later
To come later
To come later
To come later
To come later
To come later
To come later
// Import package
import { CouchDB } from 'earthtoday-node-couchdb-client';
// Instatiate new CouchDB request class
const couchDb = new CouchDb({
auth: {
username: 'admin',
password: 'password'
}
});
// Async example
async function getAllDatabases() {
try {
const databases = await this.couchDb.getAllDatabases();
// do something
}
catch(error) {
// catch error
}
}
// Promise (ES6) example
couchDb.getDocuments('databaseName').then(docs => {
// do something
}).catch(error => {
// catch error
});
FAQs
This typescript module is copied from another dude, feel free to copy it again
We found that earthtoday-couchdb-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.