File size: 1,191 Bytes
95b671e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
export type SuperlogEdition = "community" | "cloud" | "private";
export type BillingProvider = "none" | "stripe";

export type SystemCapabilities = {
  edition: SuperlogEdition;
  billing: BillingProvider;
  managedAgents: boolean;
  ossAgents: boolean;
  cloudUpgradeLinks: boolean;
};

type CapabilityEnv = Partial<
  Pick<
    NodeJS.ProcessEnv,
    "SUPERLOG_EDITION" | "SUPERLOG_BILLING_PROVIDER" | "SUPERLOG_MANAGED_AGENTS_ENABLED"
  >
>;

export function buildSystemCapabilities(env: CapabilityEnv = process.env): SystemCapabilities {
  const edition = parseEdition(env.SUPERLOG_EDITION);
  const billing = parseBillingProvider(env.SUPERLOG_BILLING_PROVIDER);
  const managedAgents = env.SUPERLOG_MANAGED_AGENTS_ENABLED === "true";

  return {
    edition,
    billing,
    managedAgents,
    ossAgents: true,
    cloudUpgradeLinks: edition === "community",
  };
}

function parseEdition(value: string | undefined): SuperlogEdition {
  if (value === "cloud" || value === "private" || value === "community") return value;
  return "community";
}

function parseBillingProvider(value: string | undefined): BillingProvider {
  if (value === "stripe") return "stripe";
  return "none";
}