denotify-client 1.1.8 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +9 -0
- package/.eslintignore +8 -0
- package/.eslintrc +18 -0
- package/.lintstagedrc +4 -0
- package/.prettierignore +8 -0
- package/.prettierrc +16 -0
- package/.stylelintignore +8 -0
- package/.stylelintrc +18 -0
- package/CHANGELOG.md +0 -0
- package/dts-bundle-generator.config.ts +18 -0
- package/favicon.svg +15 -0
- package/index.html +13 -0
- package/jest.config.ts +9 -0
- package/package.json +51 -65
- package/tsconfig.json +22 -0
- package/vite.config.ts +35 -0
- package/dist/alertbuilder.js +0 -67
- package/dist/denotifyclient.js +0 -125
- package/dist/examples/balance-monitor.js +0 -47
- package/dist/examples/delete-alert.js +0 -11
- package/dist/functionbuilder.js +0 -39
- package/dist/index.js +0 -4751
- package/dist/index.min.js +0 -1
- package/dist/index.mjs +0 -4713
- package/dist/notifications/index.js +0 -3
- package/dist/notifications/notification.js +0 -8
- package/dist/notifications/notify_discord_webhook.js +0 -21
- package/dist/triggers/handler_function_call.js +0 -26
- package/dist/triggers/handler_function_call_v2.js +0 -41
- package/dist/triggers/handler_onchain_event.js +0 -28
- package/dist/triggers/index.js +0 -5
- package/dist/triggers/trigger.js +0 -14
- package/dist/types/types.js +0 -1
- package/dist/util/filter.js +0 -160
- /package/{license → LICENSE.md} +0 -0
@@ -1,21 +0,0 @@
|
|
1
|
-
import * as yup from 'yup';
|
2
|
-
export const NOTIFY_DISCORD_WEBHOOK_RAW_ID = 'notify_discord_webhook';
|
3
|
-
export class NotifyDiscordWebhook {
|
4
|
-
static SimpleToRaw(config) {
|
5
|
-
return {
|
6
|
-
name: '',
|
7
|
-
notify_type: NOTIFY_DISCORD_WEBHOOK_RAW_ID,
|
8
|
-
notify: config
|
9
|
-
};
|
10
|
-
}
|
11
|
-
static validateCreate(options) {
|
12
|
-
const urlRegex = /^(https?|ftp):\/\/(-\.)?([^\s/?\.#]+\.?)+([^\s\.?#]+)?(\?\S*)?$/;
|
13
|
-
const schema = yup.object({
|
14
|
-
url: yup.string().matches(urlRegex, 'url is not a valid url').required(),
|
15
|
-
username: yup.string(),
|
16
|
-
avatar_url: yup.string().matches(urlRegex, 'url is not a valid url'),
|
17
|
-
message: yup.string().required()
|
18
|
-
});
|
19
|
-
return schema.validate(options);
|
20
|
-
}
|
21
|
-
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import * as yup from 'yup';
|
2
|
-
const HANDLER_FUNCTION_CALL_V1_RAW_ID = 'handler_function_call';
|
3
|
-
export class HandlerFunctionCall {
|
4
|
-
static SimpleToRaw(name, network, config) {
|
5
|
-
return {
|
6
|
-
alertType: 'event',
|
7
|
-
network,
|
8
|
-
nickname: name,
|
9
|
-
type: HANDLER_FUNCTION_CALL_V1_RAW_ID,
|
10
|
-
handler: config
|
11
|
-
};
|
12
|
-
}
|
13
|
-
static validateCreate(options) {
|
14
|
-
const requiredWhenConditional = ([condition], schema) => condition === 'true' ? schema.notRequired() : schema.required();
|
15
|
-
const schema = yup.object({
|
16
|
-
address: yup.string().required(),
|
17
|
-
abi: yup.array().required(),
|
18
|
-
nBlocks: yup.number().min(10),
|
19
|
-
condition: yup.string().oneOf(['>', '>=', '<', '<=', '=', 'true']),
|
20
|
-
constant: yup.number().min(0).when('condition', requiredWhenConditional),
|
21
|
-
responseArgIndex: yup.number().min(0).when('condition', requiredWhenConditional),
|
22
|
-
responseArgDecimals: yup.number().min(0).when('condition', requiredWhenConditional),
|
23
|
-
});
|
24
|
-
return schema.validate(options);
|
25
|
-
}
|
26
|
-
}
|
@@ -1,41 +0,0 @@
|
|
1
|
-
import { FunctionBuilder } from "../functionbuilder.js";
|
2
|
-
import { FilterBuilder } from "../util/filter.js";
|
3
|
-
import * as yup from 'yup';
|
4
|
-
const HANDLER_FUNCTION_CALL_V2_RAW_ID = 'handler_function_call_v2';
|
5
|
-
export class HandlerFunctionCallV2 {
|
6
|
-
static SimpleToRaw(name, network, config) {
|
7
|
-
return {
|
8
|
-
alertType: 'event',
|
9
|
-
network,
|
10
|
-
nickname: name,
|
11
|
-
type: HANDLER_FUNCTION_CALL_V2_RAW_ID,
|
12
|
-
handler: config
|
13
|
-
};
|
14
|
-
}
|
15
|
-
static validateCreate(options) {
|
16
|
-
const timePeriodRegex = /^(\d+)([SMHD])$/i;
|
17
|
-
const onchainEventSchema = yup.object({
|
18
|
-
timeBase: yup.string().oneOf(['blocks', 'time']).required(),
|
19
|
-
// Blocks config
|
20
|
-
nBlocks: yup.number()
|
21
|
-
.min(10)
|
22
|
-
.when('timeBase', ([timeBase], schema) => timeBase === 'blocks' ? schema.required() : schema),
|
23
|
-
// Or Time config
|
24
|
-
timePeriod: yup.string()
|
25
|
-
.matches(timePeriodRegex, 'timePeriod must be of the format n[s|m|h|d], eg 10s for 10 seconds')
|
26
|
-
.when('timeBase', ([timeBase], schema) => timeBase === 'time' ? schema.required() : schema),
|
27
|
-
startTime: yup.number().default(0),
|
28
|
-
// Debouncing. Default is 0
|
29
|
-
debounceCount: yup.number(),
|
30
|
-
// Functions
|
31
|
-
functions: FunctionBuilder.schema(),
|
32
|
-
// Trigger
|
33
|
-
triggerOn: yup.string().oneOf(['always', 'filter']).default('always'),
|
34
|
-
latch: yup.boolean().default(false),
|
35
|
-
// Filter
|
36
|
-
filterVersion: yup.string().when('triggerOn', ([triggerOn], schema) => triggerOn === 'filter' ? schema.required() : schema),
|
37
|
-
filter: FilterBuilder.schema().when('triggerOn', ([triggerOn], schema) => triggerOn === 'filter' ? schema.required() : schema),
|
38
|
-
});
|
39
|
-
return onchainEventSchema.validate(options);
|
40
|
-
}
|
41
|
-
}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import * as yup from 'yup';
|
2
|
-
const HANDLER_ONCHAIN_EVENT_V1_RAW_ID = 'handler_onchain_event';
|
3
|
-
export class HandlerOnchainEvent {
|
4
|
-
static SimpleToRaw(name, network, config) {
|
5
|
-
return {
|
6
|
-
alertType: 'event',
|
7
|
-
network,
|
8
|
-
nickname: name,
|
9
|
-
type: HANDLER_ONCHAIN_EVENT_V1_RAW_ID,
|
10
|
-
handler: config
|
11
|
-
};
|
12
|
-
}
|
13
|
-
static validateCreate(options) {
|
14
|
-
const requiredWhenConditional = ([condition], schema) => condition === 'true' ? schema.notRequired() : schema.required();
|
15
|
-
const onchainEventSchema = yup.object({
|
16
|
-
address: yup.string().required(),
|
17
|
-
event: yup.string().required(),
|
18
|
-
abi: yup.array().required(),
|
19
|
-
condition: yup.string().oneOf(['>', '>=', '<', '<=', '=', 'true']),
|
20
|
-
constant: yup.number().min(0).when('condition', requiredWhenConditional),
|
21
|
-
paramsIndex: yup.number().min(0).when('condition', requiredWhenConditional),
|
22
|
-
paramsDecimals: yup.number().min(0).when('condition', requiredWhenConditional),
|
23
|
-
});
|
24
|
-
return onchainEventSchema.validate(options);
|
25
|
-
}
|
26
|
-
static validateUpdate(options) {
|
27
|
-
}
|
28
|
-
}
|
package/dist/triggers/index.js
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
import { Trigger } from "./trigger.js";
|
2
|
-
import { HandlerFunctionCallV2 } from "./handler_function_call_v2.js";
|
3
|
-
import { HandlerFunctionCall } from "./handler_function_call.js";
|
4
|
-
import { HandlerOnchainEvent } from "./handler_onchain_event.js";
|
5
|
-
export { Trigger, HandlerFunctionCallV2, HandlerFunctionCall, HandlerOnchainEvent, };
|
package/dist/triggers/trigger.js
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { HandlerFunctionCall } from "./handler_function_call.js";
|
2
|
-
import { HandlerOnchainEvent } from "./handler_onchain_event.js";
|
3
|
-
import { HandlerFunctionCallV2 } from "./handler_function_call_v2.js";
|
4
|
-
export class Trigger {
|
5
|
-
static SimpleToRaw(name, id, network, config) {
|
6
|
-
switch (id) {
|
7
|
-
case 'PollFunctionV2': return HandlerFunctionCallV2.SimpleToRaw(name, network, config);
|
8
|
-
case 'PollFunctionV1': return HandlerFunctionCall.SimpleToRaw(name, network, config);
|
9
|
-
case 'OnchainEventV1': return HandlerOnchainEvent.SimpleToRaw(name, network, config);
|
10
|
-
default:
|
11
|
-
throw new Error('Invalid Trigger ID');
|
12
|
-
}
|
13
|
-
}
|
14
|
-
}
|
package/dist/types/types.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/dist/util/filter.js
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
import * as yup from 'yup';
|
2
|
-
export class Filter {
|
3
|
-
static version() {
|
4
|
-
return 'v1';
|
5
|
-
}
|
6
|
-
static execute(record, groupsIn, version = 'v1') {
|
7
|
-
// Deep copy to so we can edit the object during recursion
|
8
|
-
const groups = JSON.parse(JSON.stringify(groupsIn));
|
9
|
-
let lhs = true;
|
10
|
-
for (const group of groups) {
|
11
|
-
const rhs = Filter.process(record, group.conditions);
|
12
|
-
lhs = Filter.execLogic(lhs, group.logic, rhs);
|
13
|
-
}
|
14
|
-
return lhs;
|
15
|
-
}
|
16
|
-
static process(record, conditions, lhs) {
|
17
|
-
const condition = conditions.shift();
|
18
|
-
if (!condition) {
|
19
|
-
if (lhs === undefined)
|
20
|
-
return true;
|
21
|
-
return lhs;
|
22
|
-
}
|
23
|
-
// lhs <logic> rhs
|
24
|
-
const rhs = Filter.execCondition(record, condition);
|
25
|
-
if (lhs === undefined || condition.logic === 'WHERE')
|
26
|
-
return Filter.process(record, conditions, rhs);
|
27
|
-
if (condition.logic === undefined)
|
28
|
-
throw new Error('Invalid filter. Condition must have logic value');
|
29
|
-
const next = Filter.execLogic(lhs, condition.logic, rhs);
|
30
|
-
return Filter.process(record, conditions, next);
|
31
|
-
}
|
32
|
-
static execLogic(lhs, logic, rhs) {
|
33
|
-
switch (logic) {
|
34
|
-
case 'AND': return lhs && rhs;
|
35
|
-
case 'OR': return lhs || rhs;
|
36
|
-
case 'XOR': return (lhs || rhs) && !(lhs && rhs);
|
37
|
-
case 'NAND': return !(lhs && rhs);
|
38
|
-
case 'NOR': return !(lhs && rhs);
|
39
|
-
case 'WHERE': return rhs;
|
40
|
-
default: throw new Error(`Invalid Filter. Bad logic value: ${logic}`);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
static execCondition(record, condition) {
|
44
|
-
const data = record[condition.key];
|
45
|
-
if (condition.type === 'Number') {
|
46
|
-
if (typeof condition.constant !== 'number' || typeof data !== 'number')
|
47
|
-
throw new Error(`Invalid filter. Type miss-match. Type: ${condition.type}, Variable: ${condition.constant}, Data: ${data}`);
|
48
|
-
const n = data;
|
49
|
-
const constant = condition.constant;
|
50
|
-
switch (condition.operation) {
|
51
|
-
case 'eq': return n === constant;
|
52
|
-
case '!eq': return n !== constant;
|
53
|
-
case 'gt': return n > constant;
|
54
|
-
case 'gte': return n >= constant;
|
55
|
-
case 'lt': return n < constant;
|
56
|
-
case 'lte': return n <= constant;
|
57
|
-
default: throw new Error('Invalid Filter. Operation does not match type');
|
58
|
-
}
|
59
|
-
}
|
60
|
-
if (condition.type === 'String') {
|
61
|
-
if (typeof condition.constant !== 'string' || typeof data !== 'string')
|
62
|
-
throw new Error(`Invalid filter. Type miss-match. Type: ${condition.type}, Variable: ${condition.constant}, Data: ${data}`);
|
63
|
-
const str = data;
|
64
|
-
const constant = condition.constant;
|
65
|
-
switch (condition.operation) {
|
66
|
-
case 'contains': return str.includes(constant);
|
67
|
-
case '!contains': return !str.includes(constant);
|
68
|
-
case 'is': return str === constant;
|
69
|
-
case '!is': return str !== constant;
|
70
|
-
case 'isEmpty': return str === '';
|
71
|
-
case '!isEmpty': return str !== '';
|
72
|
-
default: throw new Error('Invalid Filter. Operation does not match type');
|
73
|
-
}
|
74
|
-
}
|
75
|
-
if (condition.type === 'Address') {
|
76
|
-
if (typeof condition.constant !== 'string' || typeof data !== 'string')
|
77
|
-
throw new Error(`Invalid filter. Type miss-match. Type: ${condition.type}, Variable: ${condition.constant}, Data: ${data}`);
|
78
|
-
const str = data;
|
79
|
-
const constant = condition.constant;
|
80
|
-
switch (condition.operation) {
|
81
|
-
case 'contains': return str.toLowerCase().includes(constant.toLowerCase());
|
82
|
-
case '!contains': return !str.toLowerCase().includes(constant.toLowerCase());
|
83
|
-
case 'is': return str.toLowerCase() === constant.toLowerCase();
|
84
|
-
case '!is': return str.toLowerCase() !== constant.toLowerCase();
|
85
|
-
case 'isEmpty': return str === '';
|
86
|
-
case '!isEmpty': return str !== '';
|
87
|
-
default: throw new Error('Invalid Filter. Operation does not match type');
|
88
|
-
}
|
89
|
-
}
|
90
|
-
throw new Error('Invalid Filter. Unknown Type');
|
91
|
-
}
|
92
|
-
}
|
93
|
-
export class FilterBuilder {
|
94
|
-
groups = [];
|
95
|
-
constructor() {
|
96
|
-
this.newGroup('WHERE');
|
97
|
-
}
|
98
|
-
static version() {
|
99
|
-
return Filter.version();
|
100
|
-
}
|
101
|
-
static new() {
|
102
|
-
return new FilterBuilder();
|
103
|
-
}
|
104
|
-
newGroup(logic) {
|
105
|
-
if (this.groups.length !== 0 && logic === 'WHERE')
|
106
|
-
throw new Error('Only the first groups can start with "WHERE"');
|
107
|
-
this.groups.push({ logic: 'WHERE', conditions: [] });
|
108
|
-
return this;
|
109
|
-
}
|
110
|
-
addCondition(logic, key, type, operation, constant) {
|
111
|
-
const group = this.groups[this.groups.length - 1];
|
112
|
-
if (group.conditions.length === 0 && logic !== 'WHERE')
|
113
|
-
throw new Error('Logic for the first condition of a group must be "WHERE"');
|
114
|
-
if (group.conditions.length > 0 && logic === 'WHERE')
|
115
|
-
throw new Error('Only the first condition of a group can be "WHERE"');
|
116
|
-
group.conditions.push({
|
117
|
-
logic,
|
118
|
-
key,
|
119
|
-
type,
|
120
|
-
operation,
|
121
|
-
constant
|
122
|
-
});
|
123
|
-
return this;
|
124
|
-
}
|
125
|
-
finalise() {
|
126
|
-
for (const group of this.groups) {
|
127
|
-
if (group.conditions.length === 0)
|
128
|
-
throw new Error('Bad Filter. All Groups must have atleast one condition');
|
129
|
-
}
|
130
|
-
return this.groups;
|
131
|
-
}
|
132
|
-
static schema() {
|
133
|
-
const logic = yup.string().oneOf(['AND', 'OR', 'XOR', 'NAND', 'NOR', 'WHERE']).required();
|
134
|
-
const condition = yup.object({
|
135
|
-
logic,
|
136
|
-
key: yup.string().required(),
|
137
|
-
type: yup.string().oneOf(['String', 'Address', 'Number']).required(),
|
138
|
-
operation: yup.string().when('type', ([type], schema) => {
|
139
|
-
switch (type) {
|
140
|
-
case 'String': return schema.oneOf(['contains', '!contains', 'is', '!is', 'isEmpty', '!isEmpty']);
|
141
|
-
case 'Address': return schema.oneOf(['is', '!is', 'isEmpty', '!isEmpty']);
|
142
|
-
case 'Number': return schema.oneOf(['String', 'Address', 'Number']);
|
143
|
-
default: throw new Error('Invalid Filter Data Type');
|
144
|
-
}
|
145
|
-
}),
|
146
|
-
constant: yup.mixed().when('type', ([type]) => {
|
147
|
-
switch (type) {
|
148
|
-
case 'String': return yup.string();
|
149
|
-
case 'Address': return yup.string();
|
150
|
-
case 'Number': return yup.number();
|
151
|
-
default: throw new Error('Invalid Filter Data Type');
|
152
|
-
}
|
153
|
-
}),
|
154
|
-
});
|
155
|
-
return yup.array().of(yup.object({
|
156
|
-
logic,
|
157
|
-
conditions: yup.array().of(condition)
|
158
|
-
}));
|
159
|
-
}
|
160
|
-
}
|
/package/{license → LICENSE.md}
RENAMED
File without changes
|