Skip to content

Configuration Sync

Purpose

Configuration Sync creates or updates the catalog from a file or object. It supports features, products, plans, billing cycles, add-ons, credit rules, and overrides on existing subscriptions. It does not import usage events or wallet balances.

Access and initialization

Access

const configSync = subscrio.configSync;
var configSync = subscrio.ConfigSync;

For construction-time configuration, see Subscrio. Sync must be invoked explicitly; merely supplying configuration does not apply it.

Method catalog

Database and connection failures may propagate from any operation. Method-specific errors are listed with each method.

Method Purpose
syncFromFile Loads a JSON file and applies its configuration.
syncFromJson Applies a configuration object and returns a report.
exportConfig Exports the catalog and optionally selected subscription overrides.
Method Purpose
SyncFromFileAsync Loads a JSON file and applies its configuration.
SyncFromJsonAsync Applies a configuration object and returns a report.
ExportConfigAsync Exports the catalog and optionally selected subscription overrides.

Method details

syncFromFile

Read a UTF-8 JSON file, validate it, and apply the same synchronization as the object method. TypeScript requires features to occur before products in the file text; .NET does not enforce property order.

syncFromFile(filePath: string): Promise<ConfigSyncReport>

Parameters

Returns ConfigSyncReport: Counts, changes, warnings, and per-entity failures.

Example

// catalog.json contains a ConfigSyncDto document.
const report = await subscrio.configSync.syncFromFile('./catalog.json');
console.log(report.errors);
Errors (1)
  • ValidationError: Reading, parsing, validation, or an uncaught sync operation fails.
Task<ConfigSyncReport> SyncFromFileAsync(string filePath)

Parameters

Returns ConfigSyncReport: Counts, changes, warnings, and per-entity failures.

Example

// catalog.json contains a ConfigSyncDto document.
var report = await subscrio.ConfigSync.SyncFromFileAsync("./catalog.json");
Console.WriteLine(report.Errors.Count);
Errors (1)
  • ValidationException: Reading, parsing, validation, or an uncaught sync operation fails.

syncFromJson

Validate configuration and references, then apply changes through the public library operations. Listed entities are created or updated; omitted entities remain untouched. An explicit archive flag changes status. Supplied relationship collections can remove associations or rules, as described on their fields.

The entire sync is not one transaction. Entity failures are collected and processing continues, so inspect the report even when the call succeeds. Earlier successful writes remain if later work fails.

syncFromJson(config: ConfigSyncDto): Promise<ConfigSyncReport>

Parameters

  • config: ConfigSyncDto. This is declarative synchronization, not the generic partial-update convention.

Returns ConfigSyncReport: Catalog counts and configuration changes, including partial failures.

Example

const report = await subscrio.configSync.syncFromJson({
  version: '1',
  features: [{ key: 'max-seats', displayName: 'Seats', valueType: 'numeric', defaultValue: '1' }],
  products: [{
    key: 'saas', displayName: 'SaaS', features: ['max-seats'],
    plans: [{
      key: 'pro', displayName: 'Pro', featureValues: { 'max-seats': '20' },
      billingCycles: [{ key: 'pro-monthly', displayName: 'Monthly', durationUnit: 'months', durationValue: 1 }]
    }]
  }]
});
console.log(report.created, report.errors);
Errors (2)
  • ZodError: The TypeScript schema, duplicate keys, or catalog references are invalid.
  • ValidationError: Accounting configuration or cross-references fail preflight validation.
Task<ConfigSyncReport> SyncFromJsonAsync(ConfigSyncDto config)

Parameters

  • config: ConfigSyncDto. This is declarative synchronization, not the generic partial-update convention.

Returns ConfigSyncReport: Catalog counts and configuration changes, including partial failures.

Example

var report = await subscrio.ConfigSync.SyncFromJsonAsync(new ConfigSyncDto(
    Version: "1",
    Features: [new FeatureConfig("max-seats", "Seats", ValueType: "numeric", DefaultValue: "1")],
    Products: [new ProductConfig("saas", "SaaS",
        Features: ["max-seats"],
        Plans: [new PlanConfig("pro", "Pro",
            FeatureValues: new() { ["max-seats"] = "20" },
            BillingCycles: [new BillingCycleConfig("pro-monthly", "Monthly", DurationValue: 1, DurationUnit: "months")])])]
));
Console.WriteLine($"Created plans: {report.Created.Plans}, errors: {report.Errors.Count}");
Errors (1)
  • ValidationException: Accounting configuration or cross-references fail preflight validation.

exportConfig

Read catalog definitions, including archived entries, feature relationships, add-ons, metering settings, and credit rules, into a configuration object. Subscription overrides are included only for the keys you request. This export does not include customer records, subscription lifecycle data, add-on attachments, usage history, or credit balances and transactions.

exportConfig(subscriptionKeys?: string[]): Promise<ConfigSyncDto>

Parameters

  • subscriptionKeys: Optional existing subscription keys whose overrides to include; defaults to an empty array.

Returns ConfigSyncDto: Catalog configuration that can be passed to syncFromJson.

Example

const config = await subscrio.configSync.exportConfig();
console.log(config.products.length);
Errors (1)
  • Error: A requested subscription does not exist.
Task<ConfigSyncDto> ExportConfigAsync(IEnumerable<string>? subscriptionKeys)

Parameters

  • subscriptionKeys: Optional existing subscription keys whose overrides to include; null or an empty collection includes none.

Returns ConfigSyncDto: Catalog configuration that can be passed to SyncFromJsonAsync.

Example

var config = await subscrio.ConfigSync.ExportConfigAsync();
Console.WriteLine(config.Products.Count);
Errors (1)
  • NotFoundException: A requested subscription does not exist.

Data types

Required means an input must be supplied, or a returned property is guaranteed present. Nested keys inherit their parent product or plan; keys remain globally unique. Refer to the corresponding object page for field validation limits.

ConfigSyncDto

Root synchronization input.

Field Type Required Default Meaning
creditConsumptionRules CreditConsumptionConfig[] | undefined No None When supplied at the root, replaces the complete set of feature/currency costs across the catalog. An empty array removes all costs. Do not duplicate a feature/currency pair in nested feature rules.
creditCurrencies CreditCurrencyConfig[] | undefined No None Currencies to create or update; omitted currencies remain unchanged.
subscriptions SubscriptionOverrideConfig[] | undefined No None Override changes for existing subscriptions only; this does not create subscriptions.
version string Yes None Configuration version label. Supply a nonempty string; no version-specific schema selection is performed.
features { key: string; displayName: string; valueType: "toggle" | "numeric" | "text" | "metered"; defaultValue: string; description?: string | undefined; groupName?: string | undefined; meteredConfig?: { resetPeriod: "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "billing_period"; enforcement: "hard" | "soft"; aggregation: "count" | "sum"; usageScope: "customer" | "subscription"; } | undefined; validator?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; creditConsumptionRules?: { currencyKey: string; creditsPerUnit: number; }[] | undefined; archived?: boolean | undefined; }[] Yes None Feature definitions. Product associations must refer to these keys in TypeScript.
products { key: string; displayName: string; description?: string | undefined; metadata?: Record<string, unknown> | undefined; addons?: { key: string; displayName: string; description?: string | undefined; compositionMode?: "additive" | "override" | undefined; priority?: number | undefined; archived?: boolean | undefined; metadata?: Record<string, unknown> | undefined; featureValues?: Record<string, string> | undefined; }[] | undefined; featureResolution?: Record<string, { addonRule?: "additive" | "most_generous" | "override_wins" | undefined; subscriptionRule?: "additive" | "most_generous" | "override_wins" | null | undefined; }> | undefined; archived?: boolean | undefined; features?: string[] | undefined; plans?: { key: string; displayName: string; description?: string | undefined; metadata?: Record<string, unknown> | undefined; onExpireTransitionToBillingCycleKey?: string | undefined; archived?: boolean | undefined; creditGrants?: { currencyKey: string; amount: number; cadence: "monthly" | "yearly" | "billing_period" | "once"; expiryPolicy?: "none" | "grant_period_end" | undefined; cancellationPolicy?: "retain" | "expire" | undefined; }[] | undefined; featureValues?: Record<string, string> | undefined; billingCycles?: { key: string; displayName: string; durationUnit: "days" | "weeks" | "months" | "years" | "forever"; description?: string | undefined; durationValue?: number | undefined; externalProductId?: string | undefined; archived?: boolean | undefined; }[] | undefined; }[] | undefined; }[] Yes None Products with nested plans and billing cycles.
Property Type Required Default Meaning
Version string Yes None Configuration version label. Supply a nonempty string; no version-specific schema selection is performed.
Features List<FeatureConfig> Yes None Feature definitions. Product associations must refer to these keys in TypeScript.
Products List<ProductConfig> Yes None Products with nested plans and billing cycles.
CreditCurrencies List<CreditCurrencyConfig>? No null Currencies to create or update; omitted currencies remain unchanged.
Subscriptions List<SubscriptionOverrideConfig>? No null Override changes for existing subscriptions only; this does not create subscriptions.
CreditConsumptionRules List<CreditConsumptionConfig>? No null When supplied at the root, replaces the complete set of feature/currency costs across the catalog. An empty array removes all costs. Do not duplicate a feature/currency pair in nested feature rules.

ConfigSyncReport

Synchronization outcome. TypeScript count, message, and details fields use the inline shapes documented below.

Field Type Required Default Meaning
created ConfigSyncCounts Yes Not applicable New core catalog entities.
updated ConfigSyncCounts Yes Not applicable Changed core catalog entities.
archived ConfigSyncCounts Yes Not applicable Entities archived.
unarchived ConfigSyncCounts Yes Not applicable Entities restored.
ignored ConfigSyncCounts Yes Not applicable Database entities absent from configuration.
errors ConfigSyncError[] Yes Not applicable Failures recorded while applying individual changes.
warnings ConfigSyncWarning[] Yes Not applicable Nonfatal skipped references or values.
details AccountingSyncReport | undefined No Not applicable Detailed before/after accounting-configuration changes; may be absent.
Property Type Required Default Meaning
Created ConfigSyncCounts Yes Not applicable New core catalog entities.
Updated ConfigSyncCounts Yes Not applicable Changed core catalog entities.
Archived ConfigSyncCounts Yes Not applicable Entities archived.
Unarchived ConfigSyncCounts Yes Not applicable Entities restored.
Ignored ConfigSyncCounts Yes Not applicable Database entities absent from configuration.
Errors List<ConfigSyncError> Yes Not applicable Failures recorded while applying individual changes.
Warnings List<ConfigSyncWarning> Yes Not applicable Nonfatal skipped references or values.
Details AccountingSyncReport? Yes Not applicable Detailed before/after accounting-configuration changes; may be absent.

FeatureConfig

Nested feature definition.

Field Type Required Default Meaning
key string Yes None Stable identifier.
displayName string Yes None Human-readable label, 1 to 255 characters.
valueType "toggle" | "numeric" | "text" | "metered" Yes None toggle, numeric, text, or metered.
defaultValue string Yes None String default matching the value type.
description string | undefined No None Optional description, up to 1,000 characters.
groupName string | undefined No None Optional feature grouping label.
meteredConfig MeteredFeatureConfigDto | undefined No None Complete metering configuration; required only for metered features.
validator Record<string, unknown> | undefined No None Optional feature validator configuration.
metadata Record<string, unknown> | undefined No None Application-defined metadata.
creditConsumptionRules Array<{ currencyKey: string; creditsPerUnit: number }> | undefined No None When supplied, replaces costs for this feature; an empty array removes its costs.
archived boolean | undefined No None true archives, false restores, omission preserves existing status.
Property Type Required Default Meaning
Key string Yes None Stable identifier.
DisplayName string Yes None Human-readable label, 1 to 255 characters.
Description string? No null Optional description, up to 1,000 characters.
ValueType string No "toggle" toggle, numeric, text, or metered.
DefaultValue string No "false" String default matching the value type.
GroupName string? No null Optional feature grouping label.
Validator Dictionary<string, object?>? No null Optional feature validator configuration.
Metadata Dictionary<string, object?>? No null Application-defined metadata.
Archived bool? No null true archives, false restores, omission preserves existing status.
MeteredConfig MeteredFeatureConfigDto? No null Complete metering configuration; required only for metered features.
CreditConsumptionRules List<CreditConsumptionRuleDto>? No null When supplied, replaces costs for this feature; an empty array removes its costs.

ProductConfig

Nested product definition.

Field Type Required Default Meaning
key string Yes None Stable identifier.
displayName string Yes None Human-readable label, 1 to 255 characters.
description string | undefined No None Optional description, up to 1,000 characters.
metadata Record<string, unknown> | undefined No None Application-defined metadata.
addons AddonConfig[] | undefined No None Add-on definitions for this product; omitted add-ons are retained.
featureResolution Record<string, FeatureResolutionOptions> | undefined No None Feature-key map of resolution options applied to associated features. Omitted entries preserve current rules.
archived boolean | undefined No None true archives, false restores, omission preserves existing status.
features string[] | undefined No None When supplied, replaces product-feature associations; an empty array dissociates all features.
plans PlanConfig[] | undefined No None Plans to create or update; omitted plans are retained.
Property Type Required Default Meaning
Key string Yes None Stable identifier.
DisplayName string Yes None Human-readable label, 1 to 255 characters.
Description string? No null Optional description, up to 1,000 characters.
Metadata Dictionary<string, object?>? No null Application-defined metadata.
Archived bool? No null true archives, false restores, omission preserves existing status.
Features List<string>? No null When supplied, replaces product-feature associations; an empty array dissociates all features.
Plans List<PlanConfig>? No null Plans to create or update; omitted plans are retained.
Addons List<AddonConfig>? No null Add-on definitions for this product; omitted add-ons are retained.
FeatureResolution Dictionary<string, FeatureResolutionOptions>? No null Feature-key map of resolution options applied to associated features. Omitted entries preserve current rules.

PlanConfig

Nested plan definition.

Field Type Required Default Meaning
key string Yes None Stable identifier.
displayName string Yes None Human-readable label, 1 to 255 characters.
description string | undefined No None Optional description, up to 1,000 characters.
metadata Record<string, unknown> | undefined No None Application-defined metadata.
onExpireTransitionToBillingCycleKey string | undefined No None Expiration-transition target; see PlanConfig details below.
archived boolean | undefined No None true archives, false restores, omission preserves existing status.
creditGrants Array<{ currencyKey: string; amount: number; cadence: "once" | "monthly" | "yearly" | "billing_period"; expiryPolicy?: "none" | "grant_period_end"; cancellationPolicy?: "retain" | "expire" }> | undefined No None When supplied, replaces active currency grant rules for this plan. An empty array deactivates them; issued grants remain.
featureValues Record<string, string> | undefined No None When supplied, replaces plan feature values; an empty map removes all plan values.
billingCycles BillingCycleConfig[] | undefined No None Billing cycles to create or update; omitted cycles are retained.
Property Type Required Default Meaning
Key string Yes None Stable identifier.
DisplayName string Yes None Human-readable label, 1 to 255 characters.
Description string? No null Optional description, up to 1,000 characters.
OnExpireTransitionToBillingCycleKey string? No null Expiration-transition target; see PlanConfig details below.
FeatureValues Dictionary<string, string>? No null When supplied, replaces plan feature values; an empty map removes all plan values.
BillingCycles List<BillingCycleConfig>? No null Billing cycles to create or update; omitted cycles are retained.
Metadata Dictionary<string, object?>? No null Application-defined metadata.
Archived bool? No null true archives, false restores, omission preserves existing status.
CreditGrants List<PlanCreditGrantDto>? No null When supplied, replaces active currency grant rules for this plan. An empty array deactivates them; issued grants remain.

Transition targets must belong to the same product. TypeScript validates that the target is present in this configuration's nested billing cycles. When an existing plan is included without a transition target, synchronization clears its saved target. Include the target to preserve it; omitting the plan entirely leaves it unchanged.

BillingCycleConfig

Nested billingcycle definition.

Field Type Required Default Meaning
key string Yes None Stable identifier.
displayName string Yes None Human-readable label, 1 to 255 characters.
durationUnit "days" | "weeks" | "months" | "years" | "forever" Yes None days, weeks, months, years, or forever.
description string | undefined No None Optional description, up to 1,000 characters.
durationValue number | undefined No None Positive count required for a finite duration; omit for forever.
externalProductId string | undefined No None External payment-provider price identifier.
archived boolean | undefined No None true archives, false restores, omission preserves existing status.
Property Type Required Default Meaning
Key string Yes None Stable identifier.
DisplayName string Yes None Human-readable label, 1 to 255 characters.
Description string? No null Optional description, up to 1,000 characters.
DurationValue int? No null Positive count required for a finite duration; omit for forever.
DurationUnit string No "days" days, weeks, months, years, or forever.
ExternalProductId string? No null External payment-provider price identifier.
Archived bool? No null true archives, false restores, omission preserves existing status.

CreditCurrencyConfig

Currency input; TypeScript uses an inline shape.

Field Type Required Default Meaning
key string Yes None Currency key.
displayName string Yes None Nonblank label.
archived boolean No None true archives, false restores, omission preserves existing status.
metadata Record<string, unknown> No None Replacement application metadata.
Property Type Required Default Meaning
Key string Yes None Currency key.
DisplayName string Yes None Nonblank label.
Archived bool? No null true archives, false restores, omission preserves existing status.
Metadata Dictionary<string, object?>? No null Replacement application metadata.

AddonConfig

Add-on input; TypeScript uses an inline shape and the parent supplies the product key.

Field Type Required Default Meaning
key string Yes None Add-on key.
displayName string Yes None Nonblank label.
description string No None Optional description.
compositionMode "additive" | "override" No None How the add-on contributes; additive on creation when omitted.
priority number No None Replacement priority, lower first; defaults to zero on creation.
archived boolean No None true archives, false restores, omission preserves existing status.
metadata Record<string, unknown> No None Replacement application metadata.
featureValues Record<string, string> No None Supplied feature-key/value map replaces the existing map; an empty map clears all stored contributions.
Property Type Required Default Meaning
Key string Yes None Add-on key.
DisplayName string Yes None Nonblank label.
Description string? No null Optional description.
CompositionMode string? No null How the add-on contributes; additive on creation when omitted.
Priority int? No null Replacement priority, lower first; defaults to zero on creation.
Archived bool? No null true archives, false restores, omission preserves existing status.
Metadata Dictionary<string, object?>? No null Replacement application metadata.
FeatureValues Dictionary<string, string>? No null Supplied feature-key/value map replaces the existing map; an empty map clears all stored contributions.

CreditConsumptionConfig

Root feature cost rule; TypeScript uses an inline shape.

Field Type Required Default Meaning
featureKey string Yes None Non-metered feature key.
currencyKey string Yes None Active credit currency key.
creditsPerUnit number Yes None Positive safe integer cost per action unit.
Property Type Required Default Meaning
FeatureKey string Yes None Non-metered feature key.
CurrencyKey string Yes None Active credit currency key.
CreditsPerUnit long Yes None Positive safe integer cost per action unit.

SubscriptionOverrideConfig

Changes to an existing subscription; TypeScript uses an inline shape.

Field Type Required Default Meaning
key string Yes None Existing unarchived subscription key.
featureOverrides FeatureOverrideConfig[] Yes None Explicit changes only; omitted overrides are retained.
Property Type Required Default Meaning
Key string Yes None Existing unarchived subscription key.
FeatureOverrides List<FeatureOverrideConfig> Yes None Explicit changes only; omitted overrides are retained.

FeatureOverrideConfig

One override change. TypeScript accepts either a removal object or a value-setting object.

Field Type Required Default Meaning
featureKey string Yes None Feature key.
remove boolean No None true removes the override and permits only featureKey and remove in TypeScript. Omit or false to set.
value string No None Required unless removing; must match the feature type.
type "permanent" | "temporary" | "timed" No None Required unless removing.
expiresAt string | null No None Future UTC timestamp required for timed; omit or null otherwise.
Property Type Required Default Meaning
FeatureKey string Yes None Feature key.
Value string? No null Required unless removing; must match the feature type.
Type string? No null Required unless removing.
ExpiresAt DateTime? No null Future UTC timestamp required for timed; omit or null otherwise.
Remove bool No false true removes the override and permits only featureKey and remove in TypeScript. Omit or false to set.

ConfigSyncCounts

Core entity counters; an inline object in TypeScript.

Field Type Required Default Meaning
features number Yes Not applicable Count of features.
products number Yes Not applicable Count of products.
plans number Yes Not applicable Count of plans.
billingCycles number Yes Not applicable Count of billingCycles.
Property Type Required Default Meaning
Features int Yes Not applicable Count of features.
Products int Yes Not applicable Count of products.
Plans int Yes Not applicable Count of plans.
BillingCycles int Yes Not applicable Count of billingCycles.

ConfigSyncError

One report message; an inline object in TypeScript.

Field Type Required Default Meaning
entityType "feature" | "product" | "plan" | "billingCycle" | "entitlement" Yes Not applicable Wire category of the affected operation.
key string Yes Not applicable Affected entity key.
message string Yes Not applicable Failure or warning explanation.
Property Type Required Default Meaning
EntityType string Yes Not applicable Wire category of the affected operation.
Key string Yes Not applicable Affected entity key.
Message string Yes Not applicable Failure or warning explanation.

ConfigSyncWarning

One report message; an inline object in TypeScript.

Field Type Required Default Meaning
entityType "feature" | "product" | "plan" | "billingCycle" | "entitlement" Yes Not applicable Wire category of the affected operation.
key string Yes Not applicable Affected entity key.
message string Yes Not applicable Failure or warning explanation.
Property Type Required Default Meaning
EntityType string Yes Not applicable Wire category of the affected operation.
Key string Yes Not applicable Affected entity key.
Message string Yes Not applicable Failure or warning explanation.

AccountingSyncReport

Configuration comparison; an inline object in TypeScript.

Field Type Required Default Meaning
created number Yes Not applicable Configuration entries added.
updated number Yes Not applicable Entries changed.
removed number Yes Not applicable Entries removed.
unchanged number Yes Not applicable Entries unchanged.
changes AccountingSyncChange[] Yes Not applicable Individual configuration changes.
Property Type Required Default Meaning
Created int Yes Not applicable Configuration entries added.
Updated int Yes Not applicable Entries changed.
Removed int Yes Not applicable Entries removed.
Unchanged int Yes Not applicable Entries unchanged.
Changes List<AccountingSyncChange> Yes Not applicable Individual configuration changes.

AccountingSyncChange

One configuration change; an inline object in TypeScript.

Field Type Required Default Meaning
entityType string Yes Not applicable Affected configuration kind.
key string Yes Not applicable Configuration entry identifier.
action string Yes Not applicable created, updated, removed, or unchanged.
Property Type Required Default Meaning
EntityType string Yes Not applicable Affected configuration kind.
Key string Yes Not applicable Configuration entry identifier.
Action string Yes Not applicable created, updated, removed, or unchanged.