Skip to content

Commit fa75a27

Browse files
committed
feat: add endpoint to list providers and jsonschema property
1 parent 5da73e6 commit fa75a27

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/HermesMessengerPlugin.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export class ProviderManager {
3434

3535
return this.providers.get(providerName);
3636
}
37+
38+
listProviders(): BaseProvider<any>[] {
39+
return Array.from(this.providers.values());
40+
}
3741
}
3842

3943
export class HermesMessengerPlugin extends Plugin {
@@ -130,7 +134,9 @@ export class HermesMessengerPlugin extends Plugin {
130134

131135
await this.providerManager.init(this.config, this.context);
132136

133-
this.api = {};
137+
this.api = {
138+
hermes: this.controller.definition,
139+
};
134140

135141
await this.initDatabase();
136142
await this.initConfig();

lib/controllers/ProviderController.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export class ProviderController {
5656
handler: this.listAccounts.bind(this),
5757
http: [{ verb: "get", path: `hermes/providers/:provider/accounts` }],
5858
},
59+
listProviders: {
60+
handler: this.listProviders.bind(this),
61+
http: [{ verb: "get", path: `hermes/providers` }],
62+
},
5963
},
6064
};
6165
}
@@ -99,4 +103,8 @@ export class ProviderController {
99103

100104
return { accounts };
101105
}
106+
107+
async listProviders() {
108+
return this.providerManager.listProviders();
109+
}
102110
}

lib/providers/BaseProvider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export abstract class BaseProvider<T> {
2525
protected EVENT_ACCOUNT_ADD: string;
2626
protected EVENT_ACCOUNT_REMOVE: string;
2727

28+
protected jsonSchema: JSONObject;
29+
2830
get sdk() {
2931
return this.context.accessors.sdk;
3032
}
@@ -33,8 +35,9 @@ export abstract class BaseProvider<T> {
3335
return this.context.accessors.cluster;
3436
}
3537

36-
constructor(name: string) {
38+
constructor(name: string, jsonSchema: JSONObject) {
3739
this.name = name;
40+
this.jsonSchema = jsonSchema;
3841

3942
this.EVENT_ACCOUNT_ADD = `${this.name}:account:add`;
4043
this.EVENT_ACCOUNT_REMOVE = `${this.name}:account:remove`;
@@ -74,6 +77,10 @@ export abstract class BaseProvider<T> {
7477
return this.name;
7578
}
7679

80+
getJsonSchema(): JSONObject {
81+
return this.jsonSchema;
82+
}
83+
7784
abstract send(
7885
account: string,
7986
to: string[],

0 commit comments

Comments
 (0)