feat: initial mini simple event sourcing for pending application updates

This commit is contained in:
Pierre Martin
2024-02-07 23:48:42 +01:00
parent 76a8909dc1
commit df5bfe4e1a
14 changed files with 207 additions and 14 deletions

View File

@@ -1,3 +1,6 @@
import EventStore from "../domain/EventStore";
import { ApplicationUpdateStarted } from "../domain/events/ApplicationUpdateStarted";
type TODO_TypeDefinition = any;
class Application {
@@ -52,12 +55,18 @@ class Application {
class Caprover {
private authToken: string = "";
private readonly apiUrl: string;
private readonly eventStore: EventStore;
constructor(readonly domain?: string, private readonly password?: string) {
constructor(
eventStore: EventStore,
readonly domain?: string,
private readonly password?: string
) {
if (!domain || !password) {
throw new Error("Missing domain or password");
}
this.apiUrl = `https://${domain}/api/v2`;
this.eventStore = eventStore;
}
async getApps(): Promise<Application[]> {
@@ -70,6 +79,16 @@ class Caprover {
);
}
async updateApplication(appName: string, version: string) {
console.log("TODO: Implement remote call", appName, version); // TODO
this.eventStore.append(
new ApplicationUpdateStarted(
{ id: appName, newVersion: version },
new Date()
)
);
}
private async authenticate() {
if (this.authToken) {
return;