anbaric-cloud-hosting 1.64.1 → 1.65.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/main.ts CHANGED
@@ -36,6 +36,7 @@ import {HostingServer} from "./hosting/HostingServer";
36
36
  import {PluginLoader} from "./plugins/PluginLoader";
37
37
  import {UsageReporter} from "./usage/UsageReporter";
38
38
  import {HttpSubdomains} from "./subdomains/HttpSubdomains";
39
+ import {CentralBilling} from "./billing/CentralBilling";
39
40
 
40
41
  const pool = new Pool({ connectionString: process.env.ANBARIC_DATABASE_URL });
41
42
  await ensureSchema(pool);
@@ -118,6 +119,12 @@ const subdomains = process.env.ANBARIC_CLI_KEY_LOOKUP_URL && process.env.ANBARIC
118
119
  ? new HttpSubdomains(process.env.ANBARIC_CLI_KEY_LOOKUP_URL, process.env.ANBARIC_CLI_KEY_LOOKUP_SECRET ?? "", process.env.ANBARIC_TENANT)
119
120
  : undefined;
120
121
 
122
+ // What the tenant is spending, and where it pays: the control plane's to
123
+ // know, and only a tenant that has one can ask.
124
+ const billing = process.env.ANBARIC_CLI_KEY_LOOKUP_URL && process.env.ANBARIC_TENANT
125
+ ? new CentralBilling(process.env.ANBARIC_CLI_KEY_LOOKUP_URL, process.env.ANBARIC_CLI_KEY_LOOKUP_SECRET ?? "", process.env.ANBARIC_TENANT)
126
+ : undefined;
127
+
121
128
  /* Files are owned by an app, like secrets: on the hosted platform each app
122
129
  gets its own key prefix in the tenant's bucket, and locally its own folder
123
130
  under the storage root. A caller with no app - the console - gets the whole
@@ -137,7 +144,7 @@ const server = new HostingServer(jobs, queue, registry, buildLayer,
137
144
  tokenAuthenticator, process.env.ANBARIC_TENANT, auditRecords, plugins,
138
145
  new PostgresJobRunSchedulePersistence(pool), await loadNotifier(process.env.ANBARIC_NOTIFIER_MODULE),
139
146
  new PostgresEntitlementStore(pool), new PostgresUserDirectory(pool), memberships,
140
- (appId) => new PostgresPromptManager(pool, appId), fileStorageFor, subdomains);
147
+ (appId) => new PostgresPromptManager(pool, appId), fileStorageFor, subdomains, billing);
141
148
  const port = await server.listen(hostingPort);
142
149
  const internal = await server.listenInternal(internalPort);
143
150