anbaric-cloud-hosting 1.24.0 → 1.26.0

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/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export * from "./auth/CliKeyStore";
9
9
  export * from "./auth/HttpCliKeyStore";
10
10
  export * from "./auth/InMemoryCliKeyStore";
11
11
  export * from "./auth/AuthenticatorLoader";
12
+ export * from "./notifications/NotifierLoader";
12
13
  export * from "./auth/KeyPair";
13
14
  export * from "./auth/Role";
14
15
  export * from "./auth/SessionSigner";
@@ -49,6 +50,7 @@ export * from "./plugins/PluginLoader";
49
50
  export * from "./plugins/PageDirectory";
50
51
  export * from "./hosting/handlers/QueueHandler";
51
52
  export * from "./hosting/handlers/JobRunSchedulesHandler";
53
+ export * from "./hosting/handlers/NotificationsHandler";
52
54
  export * from "./hosting/handlers/SecretsHandler";
53
55
  export * from "./hosting/handlers/StateMachinesHandler";
54
56
  export * from "./hosting/handlers/auth/AuthorizeCliHandler";
package/src/main.ts CHANGED
@@ -3,6 +3,7 @@ import {SecretStore} from "anbaric-tsapi";
3
3
  import {InMemorySecretStore} from "anbaric-data-store";
4
4
  import {Pool} from "pg";
5
5
  import {loadAuthenticator} from "./auth/AuthenticatorLoader";
6
+ import {loadNotifier} from "./notifications/NotifierLoader";
6
7
  import {CliAuthorizer} from "./auth/CliAuthorizer";
7
8
  import {HttpCliKeyStore} from "./auth/HttpCliKeyStore";
8
9
  import {TokenAuthenticator} from "./auth/TokenAuthenticator";
@@ -84,7 +85,7 @@ const plugins = await new PluginLoader().load(process.env.ANBARIC_PLUGINS ?? "an
84
85
  const server = new HostingServer(new PostgresJobPersistence(pool), queue, registry, buildLayer,
85
86
  (appId, collection) => new PostgresJsonStore(pool, appId, collection), secretStoreFor, authenticator, cliAuthorizer,
86
87
  tokenAuthenticator, process.env.ANBARIC_TENANT, new PostgresAuditRecordStore(pool), plugins,
87
- new PostgresJobRunSchedulePersistence(pool));
88
+ new PostgresJobRunSchedulePersistence(pool), await loadNotifier(process.env.ANBARIC_NOTIFIER_MODULE));
88
89
  const port = await server.listen(hostingPort);
89
90
  const internal = await server.listenInternal(internalPort);
90
91
 
@@ -0,0 +1,18 @@
1
+ import {Notifier} from "anbaric-tsapi";
2
+
3
+ /* Loads the server-side notifier by module name, the same way the authenticator
4
+ is loaded (see AuthenticatorLoader). The platform is open source and cannot
5
+ name a proprietary delivery mechanism, so a host names its module through
6
+ ANBARIC_NOTIFIER_MODULE and that module exports a createNotifier factory.
7
+ With nothing named, the platform accepts notifications but delivers nothing. */
8
+ const loadNotifier = async (moduleName? : string) : Promise<Notifier | undefined> => {
9
+ if (!moduleName) return undefined;
10
+
11
+ const module = await import(moduleName);
12
+ if (typeof module.createNotifier !== "function") {
13
+ throw new Error(`Notifier module "${moduleName}" does not export a createNotifier function`);
14
+ }
15
+ return module.createNotifier();
16
+ };
17
+
18
+ export { loadNotifier }