Subscrio Core API Reference
Complete documentation of all data structures and methods exposed by Subscrio Core (TypeScript: core.typescript, .NET: core.dotnet).
Main Class
Subscrio
Direct construction:
using Subscrio.Core;
var subscrio = new Subscrio(new SubscrioConfig
{
Database = new DatabaseConfig
{
ConnectionString = Environment.GetEnvironmentVariable("DATABASE_URL") ?? ""
}
});
Dependency injection (ASP.NET Core / generic host): Register Subscrio with the service collection so it is resolved per scope (recommended for web apps). Add using Subscrio.Core.DependencyInjection; and call services.AddSubscrio(config, ServiceLifetime.Scoped). Then inject Subscrio in controllers or minimal API handlers. Use ServiceLifetime.Scoped for web apps; use Transient for console or background services. See Getting Started for a full bootstrap and DI example.
Method Catalog
| Method | Description | Returns |
|---|---|---|
installSchema | Creates every Subscrio database table, seeds configuration rows, and optionally writes the admin passphrase hash | Promise<void> |
migrate | Runs pending database migrations to update the schema to the latest version | Promise<number> |
verifySchema | Confirms whether the Subscrio schema is already installed and returns the current schema version | Promise<string \| null> |
dropSchema | Removes every table created by Subscrio (for local development resets or automated tests) | Promise<void> |
runInitialConfigSync | If initialConfig was passed to the constructor, runs config sync (file or JSON) and returns the report; otherwise returns null | Promise<ConfigSyncReport \| null> |
close | Closes the database connection pool | Promise<void> |
| Method | Description | Returns |
|---|---|---|
InstallSchemaAsync | Creates every Subscrio database table, seeds configuration rows, and optionally writes the admin passphrase hash | Task |
MigrateAsync | Runs pending database migrations to update the schema to the latest version | Task<int> |
VerifySchemaAsync | Confirms whether the Subscrio schema is already installed and returns the current schema version | Task<string?> |
DropSchemaAsync | Removes every table created by Subscrio (for local development resets or automated tests) | Task |
RunInitialConfigSyncAsync | If InitialConfig was passed to the constructor, runs config sync (file or JSON) and returns the report; otherwise returns null | Task<ConfigSyncReport?> |
Dispose | Closes the database connection pool | void |
Method Reference
Constructor
Description
Instantiates the core library, initializes the database connection, and wires every repository and service so callers can use Subscrio synchronously after construction.
Signature
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
config | SubscrioConfig | Yes | Database connection plus optional passphrase, Stripe, and logging overrides. |
Input Properties
SubscrioConfig– high-level shape that includes thedatabase,stripe, andloggingobjects defined later in this page.
Returns
Creates a new Subscrio instance that exposes the services listed in the “Public Services” table above.
Creates a new Subscrio instance that exposes the services listed in the "Public Services" table above.
Return Properties
Subscrio– instance with properties such asproducts,plans,featureChecker, etc.
Subscrio– instance with properties such asProducts,Plans,FeatureChecker, etc.
Expected Results
- Initializes a Postgres database connection using
config.database. - Constructs repository instances and wires each service with its dependencies.
- Keeps a shared schema installer for schema management helpers.
Potential Errors
| Error | When |
|---|---|
ConfigurationError | Thrown downstream if config is invalid or a database connection cannot be established. |
Example
Configuration object
Subscrio consumes a strongly typed config. Only database.connectionString (TypeScript) / Database.ConnectionString (.NET) is required; every other field is optional.
Config is defined in src/config/types.ts:
export interface SubscrioConfig {
database: {
connectionString: string;
ssl?: boolean;
poolSize?: number;
};
adminPassphrase?: string;
stripe?: { secretKey: string };
logging?: { level: 'debug' | 'info' | 'warn' | 'error' };
initialConfig?: InitialConfigSync; // { type: 'file', filePath: string } | { type: 'json', config: ConfigSyncDto }
}
Config is defined in Subscrio.Core.Config:
public class SubscrioConfig
{
public required DatabaseConfig Database { get; init; }
public string? AdminPassphrase { get; init; }
public StripeConfig? Stripe { get; init; }
public LoggingConfig? Logging { get; init; }
public InitialConfigOptions? InitialConfig { get; init; } // FilePath and/or Config for config sync
}
public class DatabaseConfig
{
public required string ConnectionString { get; init; }
public bool Ssl { get; init; }
public int PoolSize { get; init; } = 10;
}
database object
| Field | Type | Required | Description |
|---|---|---|---|
connectionString | string | Yes | Full Postgres URI (postgresql://user:pass@host:port/db). |
ssl | boolean | No | Forces SSL when running outside trusted networks. |
poolSize | number | No | Custom pg pool size; defaults to driver preset. |
| Property | Type | Required | Description |
|---|---|---|---|
ConnectionString | string | Yes | Full Postgres connection string. |
Ssl | bool | No | Forces SSL when running outside trusted networks. |
PoolSize | int | No | Custom pool size; defaults to 10. |
adminPassphrase
Optional override for the admin passphrase hash stored during installSchema() / InstallSchemaAsync(). If omitted you can pass the passphrase directly to the install method.
initialConfig / InitialConfig
Optional config sync input (same as used by ConfigSyncService): a file path or a ConfigSyncDto object. If set, call runInitialConfigSync() / RunInitialConfigSyncAsync() after construction (e.g. after installing or verifying the schema) to apply the configuration. When provided, that method runs the sync and returns the report; when omitted, it returns null.
stripe object
| Field | Type | Required | Description |
|---|---|---|---|
secretKey | string | Yes | Server-side Stripe secret used by helpers like createStripeSubscription. |
| Property | Type | Required | Description |
|---|---|---|---|
SecretKey | string | Yes | Server-side Stripe secret used by helpers like CreateStripeSubscriptionAsync. |
logging object
| Field | Type | Required | Description |
|---|---|---|---|
level | 'debug' \| 'info' \| 'warn' \| 'error' | Yes | Sets global log verbosity for Subscrio internals. |
| Property | Type | Required | Description |
|---|---|---|---|
Level | string | Yes | "debug", "info", "warn", or "error" – sets global log verbosity. |
installSchema
Description
Creates every Subscrio database table, seeds configuration rows, and optionally writes the admin passphrase hash when setting up a fresh environment.
Signature
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
adminPassphrase | string | No | Optional override that supersedes config.adminPassphrase. |
Input Properties
adminPassphrase– plain text string that will be hashed before being stored insystem_config.
Returns
Promise<void> – resolves when the schema is fully installed.
Task – completes when the schema is fully installed.
Return Properties
void
- None (
Taskreturns no value)
Expected Results
- Runs the schema installer to create all tables, extensions, and seed configuration rows.
- Stores the admin passphrase hash when provided.
Potential Errors
| Error | When |
|---|---|
ConfigurationError | Database connection unavailable or migration prerequisites missing. |
DomainError | Passphrase validation fails the policy enforced by the installer. |
Example
migrate
Description
Runs pending database migrations to update the schema to the latest version. Migrations are tracked via schema_version in the system_config table, so only pending migrations are applied.
Signature
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| None |
Input Properties
- None.
Returns
Promise<number> – resolves to the number of migrations applied.
Task<int> – resolves to the number of migrations applied.
Return Properties
number– count of migrations that were applied (0 if database is up to date).
int– count of migrations that were applied (0 if database is up to date).
Expected Results
- Checks current schema version from
system_config. - Runs only pending migrations (those with version numbers greater than current).
- Updates
schema_versioninsystem_configafter each migration. - Returns count of migrations applied.
Potential Errors
| Error | When |
|---|---|
ConfigurationError | Database connection unavailable or migration fails. |
Example
verifySchema
Description
Confirms whether the Subscrio schema is already installed and returns the current schema version. Returns null if the schema is not installed, allowing callers to decide whether to run installSchema() or proceed with normal operations.
Signature
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| None |
Input Properties
- None.
Returns
Promise<string | null> – resolves to the current schema version (e.g., "1.1.0") when installed, or null if not installed.
Task<string?> – resolves to the current schema version (e.g., "1.1.0") when installed, or null if not installed.
Return Properties
string | null– the schema version string if installed, ornullif not installed.
string?– the schema version string if installed, ornullif not installed.
Expected Results
- Executes lightweight checks on required tables and indexes via the schema installer.
- If schema exists, retrieves and returns the current schema version from
system_config. - Returns
nullif schema is not installed or version cannot be determined.
Potential Errors
| Error | When |
|---|---|
ConfigurationError | Database connection is unavailable. |
Example
dropSchema
Description
Removes every table created by Subscrio. Intended for local development resets or automated tests.
Signature
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| None |
Input Properties
- None.
Returns
Promise<void> – resolves after the installer drops all managed tables.
Task – completes after the installer drops all managed tables.
Return Properties
void
- None
Expected Results
- Drops every Subscrio-owned table via the installer. This is destructive and meant for local resets/tests.
Potential Errors
| Error | When |
|---|---|
ConfigurationError | Database refuses the drop (permissions, locks). |
Example
close
Description
Closes the shared database connection pool so the process can exit cleanly.
Signature
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| None |
Input Properties
- None.
Returns
Promise<void> – resolves after all connections are closed.
void – Dispose() is synchronous; use await using for proper cleanup.
Return Properties
void
- None
Expected Results
- Closes database connections and releases resources.
Potential Errors
| Error | When |
|---|---|
ConfigurationError | Database connection has already been torn down unexpectedly. |
Example
Service Reference Index
All service-level documentation now lives in dedicated markdown files so each method, DTO, error, and example can be described in depth. The following table shows where to find those references:
| Service | Scope | Reference |
|---|---|---|
| ProductManagementService | Product CRUD, feature associations | products.md |
| FeatureManagementService | Global feature definitions | features.md |
| PlanManagementService | Plans, feature values, transitions | plans.md |
| BillingCycleManagementService | Billing cadence + price mappings | billing-cycles.md |
| CustomerManagementService | Customer lifecycle | customers.md |
| SubscriptionManagementService | Subscriptions, overrides, batch jobs | subscriptions.md |
| FeatureCheckerService | Runtime feature resolution APIs | feature-checker.md |
| StripeIntegrationService | Stripe webhook processing & helpers | stripe-integration.md |
Every service doc follows a standard structure that standardizes sections for usage, inputs/outputs, DTOs, expected results, errors, and working examples.
Additional Reference Guides
subscriptions.mdcovers CRUD APIs, DTOs, overrides, and lifecycle automation APIs.subscription-lifecycle.mdfully documents how each status is calculated (with diagrams) and how transitions work.relationships.mdcentralizes the product/plan/feature/billing-cycle/customer relationships, the feature resolution hierarchy, and the customer key conventions.products.md,plans.md,features.md, andbilling-cycles.mddocument CRUD flows, DTOs, and association helpers for each domain surface.feature-checker.mdexplains the subscription override → plan value → feature default resolution order in depth.customers.mddetails how caller-supplied customer keys map to internal IDs and where they are required.stripe-integration.mdcontains the full Stripe workflow, including where signature verification must happen before callingprocessStripeEvent().