forked from SmartDropLabs/smartdrop-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhookEvents.js
More file actions
51 lines (42 loc) · 1.54 KB
/
Copy pathwebhookEvents.js
File metadata and controls
51 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const POOL_EVENTS = Object.freeze([
'pool.created',
'pool.assets_locked',
'pool.assets_unlocked',
'pool.rewards_distributed',
'pool.closed',
]);
const PRICE_EVENTS = Object.freeze(['price.alert']);
// Only 'airdrop.failed' is registered here — it's the one event this
// codebase actually dispatches today (the expiry reconciliation job, #88).
// The README also documents airdrop.created/executing/completed, but
// nothing in the codebase dispatches those yet; registering unused event
// names here would let a client subscribe to something that can never
// fire, so they're left out until whatever feature actually dispatches
// them lands.
const AIRDROP_EVENTS = Object.freeze(['airdrop.failed']);
const ALL_EVENTS = Object.freeze([...POOL_EVENTS, ...PRICE_EVENTS, ...AIRDROP_EVENTS]);
const EVENT_SET = new Set(ALL_EVENTS);
const WILDCARD = '*';
function isKnownEvent(eventType) {
return typeof eventType === 'string' && EVENT_SET.has(eventType);
}
function isValidSubscription(events) {
if (!Array.isArray(events) || events.length === 0) return false;
return events.every((e) => e === WILDCARD || EVENT_SET.has(e));
}
function matchesSubscription(subscribedEvents, eventType) {
if (!Array.isArray(subscribedEvents) || subscribedEvents.length === 0) return false;
if (subscribedEvents.includes(WILDCARD)) return true;
return subscribedEvents.includes(eventType);
}
module.exports = {
POOL_EVENTS,
PRICE_EVENTS,
AIRDROP_EVENTS,
ALL_EVENTS,
WILDCARD,
isKnownEvent,
isValidSubscription,
matchesSubscription,
};