const store = new ControlPlaneStore(sqlite);
// Required: create the org and at least one project before recording any data.
const org = store.createOrg({
orgId: "org_acme",
slug: "acme",
name: "Acme",
});
const project = store.createProject({
orgId: org.orgId,
projectId: "project_app",
slug: "app",
name: "App",
});
// Optional: record a usage event and set a quota for a metric.
store.recordUsage({
orgId: org.orgId,
projectId: project.projectId,
runId: "run_123",
metric: "agent_runtime_ms",
quantity: 42_000,
unit: "ms",
});
store.setUsageLimit({
orgId: org.orgId,
projectId: project.projectId,
metric: "agent_runtime_ms",
unit: "ms",
period: "monthly",
limitQuantity: 10_000_000,
});
// period must be "daily", "weekly", or "monthly"; checkUsageLimit uses it
// as the default rolling window when sinceMs is omitted.
// Optional: register a SAML or OIDC provider for the org.
store.upsertIdentityProvider({
orgId: org.orgId,
providerId: "idp_okta",
type: "saml",
issuer: "https://acme.okta.com",
ssoUrl: "https://acme.okta.com/app/smithers/sso/saml",
certificateRef: "vault://identity/acme-okta-cert",
});
// Optional: store a reference to a secret in an external provider (not the value).
store.putSecretRef({
orgId: org.orgId,
projectId: project.projectId,
name: "deploy-token",
provider: "aws-secrets-manager",
ref: "arn:aws:secretsmanager:us-east-1:123:secret:deploy",
});
// Check whether recorded project usage exceeds the configured limit.
const quota = store.checkUsageLimit({
orgId: org.orgId,
projectId: project.projectId,
metric: "agent_runtime_ms",
unit: "ms",
period: "monthly",
});
// quota is null when no matching limit exists; otherwise it includes
// { usedQuantity, remainingQuantity, exceeded, limitQuantity, ...limitMetadata }.
// `period` is a label used to match a configured limit; `checkUsageLimit()` does not reset usage automatically for calendar periods.
// Pass sinceMs/untilMs when you need the used quantity scoped to a billing or reporting window.
const audit = store.exportOrgAudit({ orgId: org.orgId });