denotify-client 1.1.4 → 1.1.6
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/dist/alertbuilder.js +24 -1
- package/dist/denotifyclient.js +13 -3
- package/dist/examples/balance-monitor.js +57 -0
- package/dist/functionbuilder.js +9 -0
- package/dist/index.js +316 -167
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +297 -167
- package/dist/notifications/notify_discord_webhook.js +11 -0
- package/dist/triggers/handler_function_call.js +14 -0
- package/dist/triggers/handler_function_call_v2.js +29 -0
- package/dist/triggers/handler_onchain_event.js +16 -0
- package/dist/triggers/trigger.js +1 -1
- package/dist/util/filter.js +29 -0
- package/package.json +9 -4
- package/types/alertbuilder.d.ts +57 -3
- package/types/denotifyclient.d.ts +31 -7
- package/types/examples/aave-healthcheck.d.ts +1 -1
- package/types/examples/balance-monitor.d.ts +1 -0
- package/types/functionbuilder.d.ts +7 -0
- package/types/notifications/notification.d.ts +7 -0
- package/types/notifications/notify_discord_webhook.d.ts +6 -0
- package/types/triggers/handler_function_call.d.ts +9 -0
- package/types/triggers/handler_function_call_v2.d.ts +26 -0
- package/types/triggers/handler_onchain_event.d.ts +11 -1
- package/types/triggers/trigger.d.ts +19 -4
- package/types/util/filter.d.ts +11 -0
package/dist/util/filter.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import * as yup from 'yup';
|
1
2
|
export class Filter {
|
2
3
|
static version() {
|
3
4
|
return 'v1';
|
@@ -128,4 +129,32 @@ export class FilterBuilder {
|
|
128
129
|
}
|
129
130
|
return this.groups;
|
130
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
|
+
}
|
131
160
|
}
|
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"version": "1.1.
|
2
|
+
"version": "1.1.6",
|
3
3
|
"name": "denotify-client",
|
4
4
|
"umd:name": "denotify-client",
|
5
5
|
"repository": "robo-labs/denotify-client",
|
@@ -52,14 +52,19 @@
|
|
52
52
|
"rollup-plugin-terser": "7.0.2",
|
53
53
|
"rollup-plugin-typescript2": "0.27.1",
|
54
54
|
"tsm": "2.2.1",
|
55
|
-
"
|
56
|
-
"
|
55
|
+
"typescript": "^4.9.5",
|
56
|
+
"uvu": "0.5.3"
|
57
57
|
},
|
58
58
|
"dependencies": {
|
59
59
|
"@supabase/supabase-js": "^2.10.0",
|
60
60
|
"@types/axios": "^0.14.0",
|
61
61
|
"axois": "^0.0.1-security",
|
62
62
|
"ethers": "^6.0.8",
|
63
|
-
"
|
63
|
+
"follow-redirects": "^1.15.2",
|
64
|
+
"form-data": "^4.0.0",
|
65
|
+
"proxy-from-env": "^1.1.0",
|
66
|
+
"ts-node": "^10.9.1",
|
67
|
+
"typescript": "^4.9.5",
|
68
|
+
"yup": "^1.0.2"
|
64
69
|
}
|
65
70
|
}
|
package/types/alertbuilder.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { NotificationConfig, NotificationTypeId } from "./notifications/notification.js";
|
2
|
-
import { Network,
|
2
|
+
import { Network, TriggerTypeId } from "./triggers/trigger.js";
|
3
3
|
import { AlertConfig } from "./types/types.js";
|
4
4
|
export declare class AlertBuilder {
|
5
5
|
private name;
|
@@ -11,7 +11,61 @@ export declare class AlertBuilder {
|
|
11
11
|
private constructor();
|
12
12
|
static create(name: string): AlertBuilder;
|
13
13
|
onNetwork(network: Network): AlertBuilder;
|
14
|
-
|
14
|
+
/**
|
15
|
+
* Call withTrigger with one of the TriggerConfig types:
|
16
|
+
* PollFunctionV2 | PollFunctionV1 | OnchainEventV1
|
17
|
+
* @param id Simple ID
|
18
|
+
* @param options Desired trigger configuration
|
19
|
+
* @returns self for piping
|
20
|
+
*/
|
21
|
+
withTrigger<T>(id: TriggerTypeId, options: T): AlertBuilder;
|
15
22
|
withNotification<T = NotificationConfig>(id: NotificationTypeId, options: T): AlertBuilder;
|
16
|
-
|
23
|
+
validate(): Promise<{
|
24
|
+
condition?: string | undefined;
|
25
|
+
constant?: number | undefined;
|
26
|
+
paramsIndex?: number | undefined;
|
27
|
+
paramsDecimals?: number | undefined;
|
28
|
+
address: string;
|
29
|
+
event: string;
|
30
|
+
abi: any[];
|
31
|
+
} | {
|
32
|
+
condition?: string | undefined;
|
33
|
+
constant?: number | undefined;
|
34
|
+
nBlocks?: number | undefined;
|
35
|
+
responseArgIndex?: number | undefined;
|
36
|
+
responseArgDecimals?: number | undefined;
|
37
|
+
address: string;
|
38
|
+
abi: any[];
|
39
|
+
} | {
|
40
|
+
nBlocks?: number | undefined;
|
41
|
+
timePeriod?: string | undefined;
|
42
|
+
debounceCount?: number | undefined;
|
43
|
+
functions?: {
|
44
|
+
function: string;
|
45
|
+
address: string;
|
46
|
+
bytecode: string;
|
47
|
+
abiHash: string;
|
48
|
+
}[] | undefined;
|
49
|
+
filter?: {
|
50
|
+
conditions?: {
|
51
|
+
constant?: {} | undefined;
|
52
|
+
operation?: string | undefined;
|
53
|
+
logic: NonNullable<"AND" | "OR" | "XOR" | "NAND" | "NOR" | "WHERE" | undefined>;
|
54
|
+
key: string;
|
55
|
+
type: NonNullable<"String" | "Address" | "Number" | undefined>;
|
56
|
+
}[] | undefined;
|
57
|
+
logic: NonNullable<"AND" | "OR" | "XOR" | "NAND" | "NOR" | "WHERE" | undefined>;
|
58
|
+
}[] | undefined;
|
59
|
+
filterVersion?: string | undefined;
|
60
|
+
timeBase: NonNullable<"blocks" | "time" | undefined>;
|
61
|
+
startTime: number;
|
62
|
+
triggerOn: "always" | "filter";
|
63
|
+
latch: boolean;
|
64
|
+
} | {
|
65
|
+
username?: string | undefined;
|
66
|
+
avatar_url?: string | undefined;
|
67
|
+
message: string;
|
68
|
+
url: string;
|
69
|
+
} | undefined>;
|
70
|
+
config(): Promise<AlertConfig>;
|
17
71
|
}
|
@@ -1,17 +1,40 @@
|
|
1
|
+
import { NotificationRawResponse, NotifyRawId } from "./notifications/notification.js";
|
1
2
|
import { AlertConfig, DeNotifyOptions } from "./types/types.js";
|
2
|
-
import { TriggerUpdate } from "./triggers/trigger.js";
|
3
|
+
import { TriggerRawResponse, TriggerTypeRawId, TriggerUpdate } from "./triggers/trigger.js";
|
4
|
+
type Pagination = {
|
5
|
+
page?: number;
|
6
|
+
size?: number;
|
7
|
+
};
|
8
|
+
type HistoryParams = {
|
9
|
+
id?: number;
|
10
|
+
page?: number;
|
11
|
+
size?: number;
|
12
|
+
};
|
13
|
+
type AlertHistory = {
|
14
|
+
type: 'trigger' | 'notification';
|
15
|
+
set: boolean;
|
16
|
+
alert_id: number;
|
17
|
+
block: number;
|
18
|
+
metadata: any;
|
19
|
+
subtype: TriggerTypeRawId | NotifyRawId;
|
20
|
+
};
|
21
|
+
type AlertRawResponse = {
|
22
|
+
alertId: number;
|
23
|
+
trigger: TriggerRawResponse;
|
24
|
+
notification: NotificationRawResponse;
|
25
|
+
};
|
3
26
|
export declare class DeNotifyClient {
|
4
27
|
private url;
|
5
28
|
private token;
|
6
29
|
private headers;
|
7
30
|
private constructor();
|
8
31
|
static create(options: DeNotifyOptions): Promise<DeNotifyClient>;
|
9
|
-
alertHistory(id
|
10
|
-
|
11
|
-
|
12
|
-
}
|
13
|
-
getAlert(id: number): Promise<
|
14
|
-
getAlerts(): Promise<
|
32
|
+
alertHistory(id?: number | null, pagination?: Pagination): Promise<{
|
33
|
+
params: HistoryParams;
|
34
|
+
history: AlertHistory[];
|
35
|
+
}>;
|
36
|
+
getAlert(id: number): Promise<AlertRawResponse>;
|
37
|
+
getAlerts(): Promise<AlertRawResponse[]>;
|
15
38
|
createAlert(config: AlertConfig): Promise<any>;
|
16
39
|
deleteAlert(id: number): Promise<any>;
|
17
40
|
private request;
|
@@ -26,3 +49,4 @@ export declare class DeNotifyClient {
|
|
26
49
|
updateNotification(triggerId: number): Promise<void>;
|
27
50
|
updateTrigger(triggerId: number, update: TriggerUpdate): Promise<any>;
|
28
51
|
}
|
52
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export {};
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { DeNotifyClient } from "./denotifyclient.js";
|
2
|
+
import * as yup from 'yup';
|
2
3
|
export type FunctionCallerConfig = {
|
3
4
|
address: string;
|
4
5
|
bytecode: string;
|
@@ -13,4 +14,10 @@ export declare class FunctionBuilder {
|
|
13
14
|
getAbiHash(abi: any): Promise<string>;
|
14
15
|
addFunction<T = any>(address: string, func: string, args: T[], abi: any): Promise<this>;
|
15
16
|
get(): FunctionCallerConfig;
|
17
|
+
static schema(): yup.ArraySchema<{
|
18
|
+
function: string;
|
19
|
+
address: string;
|
20
|
+
bytecode: string;
|
21
|
+
abiHash: string;
|
22
|
+
}[] | undefined, yup.AnyObject, "", "">;
|
16
23
|
}
|
@@ -10,6 +10,13 @@ export type NotificationRawConfig = {
|
|
10
10
|
notify_type: NotifyRawId;
|
11
11
|
notify: NotifyRawConfig;
|
12
12
|
};
|
13
|
+
export type NotificationRawResponse = {
|
14
|
+
notify_type: NotifyRawId;
|
15
|
+
notify: NotifyRawResponse;
|
16
|
+
error: boolean;
|
17
|
+
error_message: string | null;
|
18
|
+
error_timestamp: number | null;
|
19
|
+
};
|
13
20
|
export declare class Notification {
|
14
21
|
static SimpleToRaw(id: NotificationTypeId, config: NotificationConfig): NotificationRawConfig;
|
15
22
|
}
|
@@ -29,4 +29,10 @@ export type NotifyDiscordWebhookRawUpdate = {
|
|
29
29
|
};
|
30
30
|
export declare class NotifyDiscordWebhook {
|
31
31
|
static SimpleToRaw(config: DiscordWebhook): NotificationRawConfig;
|
32
|
+
static validateCreate(options: any): Promise<{
|
33
|
+
username?: string | undefined;
|
34
|
+
avatar_url?: string | undefined;
|
35
|
+
message: string;
|
36
|
+
url: string;
|
37
|
+
}>;
|
32
38
|
}
|
@@ -50,4 +50,13 @@ export type HandlerFunctionCallRawUpdate = {
|
|
50
50
|
};
|
51
51
|
export declare class HandlerFunctionCall {
|
52
52
|
static SimpleToRaw(name: string, network: Network, config: PollFunctionV1): TriggerRawConfig;
|
53
|
+
static validateCreate(options: any): Promise<{
|
54
|
+
condition?: string | undefined;
|
55
|
+
nBlocks?: number | undefined;
|
56
|
+
constant?: number | undefined;
|
57
|
+
responseArgIndex?: number | undefined;
|
58
|
+
responseArgDecimals?: number | undefined;
|
59
|
+
address: string;
|
60
|
+
abi: any[];
|
61
|
+
}>;
|
53
62
|
}
|
@@ -61,5 +61,31 @@ export type HandlerFunctionCallV2RawUpdate = {
|
|
61
61
|
};
|
62
62
|
export declare class HandlerFunctionCallV2 {
|
63
63
|
static SimpleToRaw(name: string, network: Network, config: PollFunctionV2): TriggerRawConfig;
|
64
|
+
static validateCreate(options: any): Promise<{
|
65
|
+
filter?: {
|
66
|
+
conditions?: {
|
67
|
+
operation?: string | undefined;
|
68
|
+
constant?: {} | undefined;
|
69
|
+
logic: NonNullable<"AND" | "OR" | "XOR" | "NAND" | "NOR" | "WHERE" | undefined>;
|
70
|
+
key: string;
|
71
|
+
type: NonNullable<"String" | "Address" | "Number" | undefined>;
|
72
|
+
}[] | undefined;
|
73
|
+
logic: NonNullable<"AND" | "OR" | "XOR" | "NAND" | "NOR" | "WHERE" | undefined>;
|
74
|
+
}[] | undefined;
|
75
|
+
nBlocks?: number | undefined;
|
76
|
+
timePeriod?: string | undefined;
|
77
|
+
debounceCount?: number | undefined;
|
78
|
+
functions?: {
|
79
|
+
function: string;
|
80
|
+
address: string;
|
81
|
+
bytecode: string;
|
82
|
+
abiHash: string;
|
83
|
+
}[] | undefined;
|
84
|
+
filterVersion?: string | undefined;
|
85
|
+
latch: boolean;
|
86
|
+
timeBase: NonNullable<"blocks" | "time" | undefined>;
|
87
|
+
startTime: number;
|
88
|
+
triggerOn: "always" | "filter";
|
89
|
+
}>;
|
64
90
|
}
|
65
91
|
export {};
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { Condition } from "../util/filter.js";
|
2
1
|
import { Network, TriggerRawConfig } from "./trigger.js";
|
2
|
+
import { Condition } from "../types/types.js";
|
3
3
|
export type OnchainEventV1 = {
|
4
4
|
address: string;
|
5
5
|
event: string;
|
@@ -40,4 +40,14 @@ export type HandlerOnchainEventRawUpdate = {
|
|
40
40
|
};
|
41
41
|
export declare class HandlerOnchainEvent {
|
42
42
|
static SimpleToRaw(name: string, network: Network, config: OnchainEventV1): TriggerRawConfig;
|
43
|
+
static validateCreate(options: any): Promise<{
|
44
|
+
condition?: string | undefined;
|
45
|
+
constant?: number | undefined;
|
46
|
+
paramsIndex?: number | undefined;
|
47
|
+
paramsDecimals?: number | undefined;
|
48
|
+
event: string;
|
49
|
+
address: string;
|
50
|
+
abi: any[];
|
51
|
+
}>;
|
52
|
+
static validateUpdate(options: any): void;
|
43
53
|
}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { HandlerFunctionCallRawConfig, HandlerFunctionCallUpdate, PollFunctionV1 } from "./handler_function_call.js";
|
2
|
-
import { HandlerOnchainEventRawConfig, HandlerOnchainEventUpdate, OnchainEventV1 } from "./handler_onchain_event.js";
|
3
|
-
import { HandlerFunctionCallV2RawConfig, HandlerFunctionCallV2Update, PollFunctionV2 } from "./handler_function_call_v2.js";
|
1
|
+
import { HandlerFunctionCallRawConfig, HandlerFunctionCallRawResponse, HandlerFunctionCallUpdate, PollFunctionV1 } from "./handler_function_call.js";
|
2
|
+
import { HandlerOnchainEventRawConfig, HandlerOnchainEventRawResponse, HandlerOnchainEventUpdate, OnchainEventV1 } from "./handler_onchain_event.js";
|
3
|
+
import { HandlerFunctionCallV2RawConfig, HandlerFunctionCallV2RawResponse, HandlerFunctionCallV2Update, PollFunctionV2 } from "./handler_function_call_v2.js";
|
4
4
|
export type Network = 'avalanche' | 'ethereum';
|
5
5
|
export type TriggerConfig = PollFunctionV2 | PollFunctionV1 | OnchainEventV1;
|
6
|
-
export type TriggerTypeId = 'PollFunctionV2' | '
|
6
|
+
export type TriggerTypeId = 'PollFunctionV2' | 'OnchainEventV1' | 'PollFunctionV1';
|
7
7
|
export type TriggerUpdate = HandlerFunctionCallV2Update | HandlerFunctionCallUpdate | HandlerOnchainEventUpdate;
|
8
8
|
export type TriggerTypeRawId = 'handler_function_call' | 'handler_onchain_event' | 'handler_function_call_v2';
|
9
9
|
export type TriggerOn = 'event' | 'latch';
|
@@ -15,6 +15,21 @@ export type TriggerRawConfig = {
|
|
15
15
|
network: Network;
|
16
16
|
handler: HandlerRawConfig;
|
17
17
|
};
|
18
|
+
export type HandlerRawResponse = HandlerFunctionCallV2RawResponse | HandlerFunctionCallRawResponse | HandlerOnchainEventRawResponse;
|
19
|
+
export type TriggerRawResponse = {
|
20
|
+
id: number;
|
21
|
+
type: TriggerTypeRawId;
|
22
|
+
triggered: boolean;
|
23
|
+
lastBlock: number;
|
24
|
+
alertType: 'event' | 'latch';
|
25
|
+
enabled: boolean;
|
26
|
+
nickname: string;
|
27
|
+
error: boolean;
|
28
|
+
error_message: string | null;
|
29
|
+
error_timestamp: number | null;
|
30
|
+
network: Network;
|
31
|
+
handler: HandlerRawResponse;
|
32
|
+
};
|
18
33
|
export declare class Trigger {
|
19
34
|
static SimpleToRaw(name: string, id: TriggerTypeId, network: Network, config: TriggerConfig): TriggerRawConfig;
|
20
35
|
}
|
package/types/util/filter.d.ts
CHANGED
@@ -4,6 +4,7 @@ type StringOperation = 'contains' | '!contains' | 'is' | '!is' | 'isEmpty' | '!i
|
|
4
4
|
type AddressOperation = 'is' | '!is' | 'isEmpty' | '!isEmpty';
|
5
5
|
type FilterDataTypes = 'String' | 'Address' | 'Number';
|
6
6
|
type FilterOpertationType = NumericOperation | StringOperation | AddressOperation;
|
7
|
+
import * as yup from 'yup';
|
7
8
|
export type Condition = {
|
8
9
|
logic?: Logic;
|
9
10
|
key: string;
|
@@ -31,5 +32,15 @@ export declare class FilterBuilder {
|
|
31
32
|
newGroup(logic: Logic): FilterBuilder;
|
32
33
|
addCondition(logic: Logic, key: string, type: FilterDataTypes, operation: FilterOpertationType, constant: string | number): FilterBuilder;
|
33
34
|
finalise(): ConditionGroup[];
|
35
|
+
static schema(): yup.ArraySchema<{
|
36
|
+
conditions?: {
|
37
|
+
operation?: string | undefined;
|
38
|
+
constant?: {} | undefined;
|
39
|
+
logic: NonNullable<"AND" | "OR" | "XOR" | "NAND" | "NOR" | "WHERE" | undefined>;
|
40
|
+
key: string;
|
41
|
+
type: NonNullable<"String" | "Address" | "Number" | undefined>;
|
42
|
+
}[] | undefined;
|
43
|
+
logic: NonNullable<"AND" | "OR" | "XOR" | "NAND" | "NOR" | "WHERE" | undefined>;
|
44
|
+
}[] | undefined, yup.AnyObject, "", "">;
|
34
45
|
}
|
35
46
|
export {};
|