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

@iflix/events-receiver-client

Package Overview
Dependencies
Maintainers
44
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iflix/events-receiver-client - npm Package Compare versions

Comparing version 1.0.0-beta.4 to 1.0.0-beta.5

built/src/logger.d.ts

5

built/src/buffer/EventBuffer.d.ts
import { Event } from '../types';
export declare type LockKey = string;
export interface EventBuffer {

@@ -6,4 +7,4 @@ queue(event: Event): Promise<void>;

dequeue(events: Event[]): Promise<void>;
lock(durationMs: number): Promise<boolean>;
unlock(): Promise<void>;
lock(durationMs: number): Promise<LockKey | undefined>;
unlock(key: LockKey): Promise<void>;
}

14

built/src/buffer/IndexedDbBuffer.d.ts
import { Event } from '../types';
import { IdbKv } from '../utils/idb';
declare type LockKey = string;
import { LockKey } from './EventBuffer';
export interface IndexedDbBufferOptions {
db?: string;
store?: string;
}
export declare class IndexedDbBuffer {
db: IdbKv;
lockKey: LockKey;
eventKeys: IDBKeyRange;
lockKeys: IDBKeyRange;
constructor();
constructor(options?: IndexedDbBufferOptions);
queue(event: Event): Promise<void>;
peek(count: number): Promise<Event[]>;
dequeue(events: Event[]): Promise<void>;
lock(durationMs: number): Promise<boolean>;
unlock(): Promise<void>;
lock(durationMs: number): Promise<LockKey | undefined>;
unlock(lockKey: LockKey): Promise<void>;
}
export {};

@@ -8,4 +8,5 @@ "use strict";

const idb_1 = require("../utils/idb");
const EVENT_DB = 'iflix-events';
const EVENT_STORE = 'event-store';
const logger_1 = require("../logger");
const DEFAULT_EVENT_DB = 'iflix-events';
const DEFAULT_EVENT_STORE = 'event-store';
const EVENT_KEY_PREFIX = 'event!';

@@ -16,7 +17,10 @@ const LOCK_KEY_PREFIX = 'lock!';

}
let nextSequence = 0;
function makeLock(key, durationMs) {
const createdAt = Date.now();
const sequence = nextSequence++;
return {
key,
createdAt,
sequence,
expiresAt: createdAt + durationMs

@@ -26,6 +30,10 @@ };

function lockSort(a, b) {
const diff = a.createdAt - b.createdAt;
if (diff !== 0) {
return diff;
const diffTime = a.createdAt - b.createdAt;
if (diffTime !== 0) {
return diffTime;
}
const diffSeq = a.sequence - b.sequence;
if (diffSeq !== 0) {
return diffSeq;
}
return a.key.localeCompare(b.key);

@@ -43,8 +51,11 @@ }

class IndexedDbBuffer {
constructor() {
this.db = new idb_1.IdbKv(EVENT_DB, EVENT_STORE);
this.lockKey = `${LOCK_KEY_PREFIX}${v4_1.default()}`;
constructor(options) {
var _a, _b, _c, _d;
const dbName = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.db, (_b !== null && _b !== void 0 ? _b : DEFAULT_EVENT_DB));
const storeName = (_d = (_c = options) === null || _c === void 0 ? void 0 : _c.store, (_d !== null && _d !== void 0 ? _d : DEFAULT_EVENT_STORE));
this.db = new idb_1.IdbKv(dbName, storeName);
// These can't just be global constants because we may not have access to IDBKeyRange (on Node, for example)
this.eventKeys = IDBKeyRange.bound(EVENT_KEY_PREFIX, EVENT_KEY_PREFIX + '\uffff', false, false);
this.lockKeys = IDBKeyRange.bound(LOCK_KEY_PREFIX, LOCK_KEY_PREFIX + '\uffff', false, false);
logger_1.log.info('Using IndexedDbBuffer', dbName, storeName);
}

@@ -63,28 +74,25 @@ async queue(event) {

const existingLock = winningLock(existingLocks);
if (existingLock === this.lockKey) {
console.log(` (${this.lockKey}) already locked to us`);
return false;
const lockKey = `${LOCK_KEY_PREFIX}${v4_1.default()}`;
if (existingLock) {
logger_1.log.info(` (${lockKey}) already locked by ${existingLock}`);
return undefined;
}
else if (existingLock) {
console.log(` (${this.lockKey}) already locked by ${existingLock}`);
return false;
}
await this.db.put(makeLock(this.lockKey, durationMs), this.lockKey);
await this.db.put(makeLock(lockKey, durationMs), lockKey);
const locks = await this.db.getAll(this.lockKeys);
const winning = winningLock(locks);
if (winning === this.lockKey) {
console.log(` (${this.lockKey}) we locked it!`);
if (winning === lockKey) {
logger_1.log.info(` (${lockKey}) we locked it!`);
}
else {
console.log(` (${this.lockKey}) someone else locked it! -> ${winning}`);
logger_1.log.info(` (${lockKey}) someone else locked it! -> ${winning}`);
}
return winning === this.lockKey;
return winning === lockKey ? lockKey : undefined;
}
async unlock() {
async unlock(lockKey) {
const locks = await this.db.getAll(this.lockKeys);
if (winningLock(locks) !== this.lockKey) {
console.warn(` (${this.lockKey}) unlocking but we weren't in charge`);
if (winningLock(locks) !== lockKey) {
logger_1.log.warn(` (${lockKey}) unlocking but we weren't in charge`);
}
else {
console.log(` (${this.lockKey}) unlocking`);
logger_1.log.info(` (${lockKey}) unlocking`);
}

@@ -91,0 +99,0 @@ await this.db.deleteKeys(locks.map(lock => lock.key));

import { Event } from '../types';
import { LockKey } from './EventBuffer';
export declare class MemBuffer {

@@ -9,4 +10,4 @@ events: Event[];

dequeue(eventsToRemove: Event[]): Promise<void>;
lock(durationMs: number): Promise<boolean>;
unlock(): Promise<void>;
lock(durationMs: number): Promise<LockKey | undefined>;
unlock(_key: LockKey): Promise<void>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = require("../logger");
class MemBuffer {

@@ -7,2 +8,3 @@ constructor() {

this.lockedUntil = 0;
logger_1.log.info('Using MemBuffer');
}

@@ -20,3 +22,3 @@ async queue(event) {

if (index === undefined || index === -1) {
console.warn(`attempting to dequeue event ${eventToRemove.guid} but it's not in queue`);
logger_1.log.warn(`attempting to dequeue event ${eventToRemove.guid} but it's not in queue`);
continue;

@@ -30,8 +32,8 @@ }

if (this.lockedUntil >= now) {
return false;
return undefined;
}
this.lockedUntil = now + durationMs;
return true;
return "KEY";
}
async unlock() {
async unlock(_key) {
this.lockedUntil = 0;

@@ -38,0 +40,0 @@ }

import { createQueue } from './queue';
import { IndexedDbBufferOptions } from './buffer/IndexedDbBuffer';
import { PartialClientInfo } from './types';
export * from './types';
export { CookieStore, getCookie, setCookie, deleteCookie } from './utils/cookie';
export { Logger, setLogger } from './logger';
export declare const getDeviceId: () => string;

@@ -9,3 +11,7 @@ export declare const getDeviceSessionId: () => string;

export declare const createClientInfo: (info: PartialClientInfo) => import("./types").ClientInfo;
export interface BufferOptions {
indexedDb?: IndexedDbBufferOptions;
}
export interface ClientOptions {
buffer?: BufferOptions;
submitUrl: string;

@@ -15,2 +21,2 @@ client: PartialClientInfo;

export declare type EventQueuer = ReturnType<typeof createQueue>;
export declare function createClient({ submitUrl, client: clientInfo }: ClientOptions): EventQueuer;
export declare function createClient({ buffer: bufferOptions, submitUrl, client: clientInfo }: ClientOptions): EventQueuer;

@@ -25,2 +25,4 @@ "use strict";

exports.deleteCookie = cookie_1.deleteCookie;
var logger_1 = require("./logger");
exports.setLogger = logger_1.setLogger;
exports.getDeviceId = deviceId_1.createDeviceIdGetter();

@@ -37,6 +39,6 @@ exports.getDeviceSessionId = deviceSessionId_1.createDeviceSessionIdGetter();

});
function createBuffer() {
function createBuffer(options) {
var _a;
if (idb_1.idbAvailable()) {
console.info('detected indexeddb');
return new IndexedDbBuffer_1.IndexedDbBuffer(); // TODO params
return new IndexedDbBuffer_1.IndexedDbBuffer((_a = options) === null || _a === void 0 ? void 0 : _a.indexedDb);
}

@@ -47,3 +49,3 @@ else {

}
function createClient({ submitUrl, client: clientInfo }) {
function createClient({ buffer: bufferOptions, submitUrl, client: clientInfo }) {
const send = sender_1.createSender({

@@ -59,3 +61,3 @@ submitUrl,

send,
buffer: createBuffer()
buffer: createBuffer(bufferOptions)
});

@@ -62,0 +64,0 @@ return queueEvent;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("./types");
const logger_1 = require("./logger");
const BATCH_SIZE = 50;

@@ -41,3 +42,3 @@ const BATCH_AGE = 20000;

catch (err) {
console.error(`Event failed to queue: ${err.message}`);
logger_1.log.error(`Event failed to queue: ${err.message}`);
}

@@ -48,3 +49,3 @@ }

if (!lock) {
console.log('flush already in progress');
logger_1.log.info('flush already in progress');
return;

@@ -56,3 +57,3 @@ }

if (needFlushing(events, force)) {
console.log('flushing', events.length, eventAge(events[0]));
logger_1.log.info('flushing', events.length, eventAge(events[0]));
const batch = batchEvents(events);

@@ -64,3 +65,3 @@ try {

catch (err) {
console.error(`Event flush failed: ${err.message}`);
logger_1.log.error(`Event flush failed: ${err.message}`);
flushPause = BATCH_DIVISOR;

@@ -76,3 +77,3 @@ return;

finally {
await buffer.unlock();
await buffer.unlock(lock);
}

@@ -82,3 +83,3 @@ }

if (!force && flushPause > 0) {
console.log('pausing', flushPause);
logger_1.log.info('pausing', flushPause);
flushPause--;

@@ -88,3 +89,3 @@ return;

const events = await buffer.peek(BATCH_SIZE);
console.log('peeked', events.length, eventAge(events[0]));
logger_1.log.info('peeked', events.length, eventAge(events[0]));
if (needFlushing(events, force)) {

@@ -97,3 +98,3 @@ return flush(force);

async function shutdown() {
console.log('shutting down');
logger_1.log.info('shutting down');
clearInterval(interval);

@@ -100,0 +101,0 @@ await flush(true);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const sleep_1 = require("./utils/sleep");
const logger_1 = require("./logger");
const BACKOFFS = [0, 500];
function createSender({ submitUrl, fetch }) {
return async function send(batch) {
console.log('sending', batch.events.length);
logger_1.log.info('sending', batch.events.length);
const params = {

@@ -9,0 +10,0 @@ method: 'POST',

@@ -5,2 +5,3 @@ "use strict";

const cookie_1 = require("./cookie");
const logger_1 = require("../logger");
class CookieMap {

@@ -26,3 +27,3 @@ constructor(document, suffix = '') {

}
console.info('detected cookies');
logger_1.log.info('detected cookies');
try {

@@ -32,3 +33,3 @@ return SimpleMap_1.testMap(new CookieMap(document, suffix));

catch (err) {
console.error(`cookie map creation failed: ${err.message}`);
logger_1.log.error(`cookie map creation failed: ${err.message}`);
return undefined;

@@ -35,0 +36,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const SimpleMap_1 = require("./SimpleMap");
const logger_1 = require("../logger");
function expiryKey(key) {

@@ -45,3 +46,3 @@ return `${key}ExpiryTimestampMs`; // don't love this, but kept for compatibility with events-client lib

}
console.info('detected local storage');
logger_1.log.info('detected local storage');
try {

@@ -51,3 +52,3 @@ return SimpleMap_1.testMap(new StorageMap(localStorage, ttlSeconds));

catch (err) {
console.error(`cookie map creation failed: ${err.message}`);
logger_1.log.error(`cookie map creation failed: ${err.message}`);
return undefined;

@@ -54,0 +55,0 @@ }

{
"name": "@iflix/events-receiver-client",
"version": "1.0.0-beta.4",
"version": "1.0.0-beta.5",
"description": "Decodes (and encodes) user tokens",

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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