New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wingbot-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wingbot-mongodb - npm Package Compare versions

Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2

.nyc_output/9435e7a6-0c43-410a-a4eb-cfc2ccefd749.json

2

package.json
{
"name": "wingbot-mongodb",
"version": "2.0.0-alpha.1",
"version": "2.0.0-alpha.2",
"description": "MongoDB storage for wingbot.ai",

@@ -5,0 +5,0 @@ "main": "src/main.js",

@@ -115,26 +115,44 @@ /**

case this.taksCollection:
await Promise.all([
this._insertIndexIfNotExists(collection, 'unique_task', {
pageId: 1, senderId: 1, sent: 1, campaignId: 1
}, { unique: true }),
this._insertIndexIfNotExists(collection, 'enqueue', {
enqueue: 1
})
await this._ensureIndexes(collection, [
{
index: {
pageId: 1, senderId: 1, campaignId: 1, sent: -1
},
options: { unique: true, name: 'unique_task' }
}, {
index: { enqueue: 1 },
options: { name: 'enqueue' }
}, {
index: {
pageId: 1, senderId: 1, sent: -1, read: 1
},
options: { name: 'search_by_read' }
}, {
index: {
pageId: 1, senderId: 1, sent: -1, delivery: 1
},
options: { name: 'search_by_delivery' }
}
]);
break;
case this.subscribtionsCollection:
await Promise.all([
this._insertIndexIfNotExists(collection, 'subscriber', {
pageId: 1, senderId: 1
}, { unique: true }),
this._insertIndexIfNotExists(collection, 'subs', {
subs: 1, pageId: 1
})
await this._ensureIndexes(collection, [
{
index: { pageId: 1, senderId: 1 },
options: { unique: true, name: 'subscriber' }
}, {
index: { subs: 1, pageId: 1 },
options: { name: 'subs' }
}
]);
break;
case this.campaignsCollection:
await Promise.all([
this._insertIndexIfNotExists(collection, 'identifier', {
id: 1
}, { unique: true })
await this._ensureIndexes(collection, [
{
index: { id: 1 },
options: { unique: true, name: 'identifier' }
}, {
index: { active: -1, startAt: -1 },
options: { name: 'startAt' }
}
]);

@@ -149,13 +167,14 @@ break;

async _insertIndexIfNotExists (collection, indexName, definition, options = {}) {
let indexExists;
async _ensureIndexes (collection, indexes) {
let existing;
try {
indexExists = await collection.indexExists(indexName);
existing = await collection.indexes();
} catch (e) {
indexExists = false;
existing = [];
}
if (!indexExists) {
await collection
.createIndex(definition, Object.assign({ name: indexName }, options));
}
await Promise.all(indexes
.filter(i => !existing.some(e => e.name === i.options.name))
.map(i => collection
.createIndex(i.index, i.options)));
}

@@ -206,3 +225,3 @@

if (typeof res.upsertedIds[i] !== 'undefined') {
return res;
return arr;
}

@@ -312,4 +331,27 @@ arr.push({

/**
* Get last sent task from campaign
*
* @param {string} pageId
* @param {string} senderId
* @param {string} campaignId
* @returns {Promise<Task|null>}
*/
async getSentTask (pageId, senderId, campaignId) {
const c = await this._getCollection(this.taksCollection);
const res = await c.findOne({
pageId,
senderId,
campaignId,
sent: { $gte: 1 }
}, {
sort: { sent: -1 }
});
return this._mapGenericObject(res);
}
/**
*
* @param {string} senderId
* @param {string} pageId

@@ -436,2 +478,22 @@ * @param {number} watermark

*
* @param {number} [now]
* @returns {Promise<Campaign|null>}
*/
async popCampaign (now = Date.now()) {
const c = await this._getCollection(this.campaignsCollection);
const res = await c.findOneAndUpdate({
startAt: { $ne: null, $lte: now },
active: true
}, {
$set: { startAt: null }
}, {
returnOriginal: true
});
return this._mapCampaign(res.value);
}
/**
*
* @param {string} campaignId

@@ -438,0 +500,0 @@ * @returns {Promise<null|Campaign>}

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