@happyvertical/smrt-subscriptions 0.60.13 → 0.60.15
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/AGENTS.md +74 -0
- package/README.md +11 -0
- package/dist/collections/TenantUsageMetricCollection.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +876 -391
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +2 -1
- package/dist/services/entitlement-changes.d.ts +115 -0
- package/dist/services/entitlement-changes.d.ts.map +1 -0
- package/dist/services/hosted-ai-spend.d.ts +182 -0
- package/dist/services/hosted-ai-spend.d.ts.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/subscription-feature-source.d.ts +89 -0
- package/dist/services/subscription-feature-source.d.ts.map +1 -0
- package/dist/services/subscription-resolver.d.ts +34 -1
- package/dist/services/subscription-resolver.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +7 -5
- package/dist/smrt-knowledge.okf.md +3 -2
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -3,11 +3,11 @@ import { _ as subscriberToColumns, a as samePlanTerms, c as deterministicUuid, d
|
|
|
3
3
|
import { r as SubscriptionPlan, t as SubscriptionPlanCollection } from "./chunks/SubscriptionPlanCollection-Dmkorx_Q.js";
|
|
4
4
|
import { r as SubscriptionPlanVersion, t as SubscriptionPlanVersionCollection } from "./chunks/SubscriptionPlanVersionCollection-yTE_Y-2z.js";
|
|
5
5
|
import { r as snapshotLegacyPlanVersion, t as pinSubscriptionPlanVersion } from "./chunks/plan-versioning-ChDyHPvn.js";
|
|
6
|
-
import { ObjectRegistry, SmrtCollection, SmrtObject, SmrtRecipe, crossPackageRef, field, foreignKey, isDatabaseInterface, isEmbeddedDatabase, isPostgresDatabase, smrt, withEmbeddedWriteTransaction } from "@happyvertical/smrt-core";
|
|
6
|
+
import { ObjectRegistry, SmrtCollection, SmrtObject, SmrtRecipe, classifyDatabaseError, crossPackageRef, field, foreignKey, isDatabaseInterface, isEmbeddedDatabase, isPostgresDatabase, smrt, usesPostgresDialect, withEmbeddedWriteTransaction } from "@happyvertical/smrt-core";
|
|
7
7
|
import { TenantIsolationError, TenantScoped, getTenantId, isSuperAdminBypass, isSystemContext, tenantId, withSystemContext } from "@happyvertical/smrt-tenancy";
|
|
8
8
|
import { preflightMinorUnitsRescale, rescaleMoneyColumnsToMinorUnits } from "@happyvertical/smrt-core/migrations";
|
|
9
9
|
//#region src/__smrt-register__.ts
|
|
10
|
-
ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-subscriptions","packageVersion":"0.60.13","objects":{"@happyvertical/smrt-subscriptions:SubscriptionPlanCollection":{"name":"subscriptionplancollection","className":"SubscriptionPlanCollection","qualifiedName":"@happyvertical/smrt-subscriptions:SubscriptionPlanCollection","collection":"subscriptionplans","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/collections/SubscriptionPlanCollection.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{"findByPlanKey":{"name":"findByPlanKey","async":true,"parameters":[{"name":"tenantId","type":"string | null","optional":false,"unionBranches":[{"type":"string"},{"type":"null"}]},{"name":"planKey","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlan | null>","isStatic":false,"isPublic":true},"findActive":{"name":"findActive","async":true,"parameters":[],"returnType":"Promise<SubscriptionPlan[]>","isStatic":false,"isPublic":true},"findByProviderPriceId":{"name":"findByProviderPriceId","async":true,"parameters":[{"name":"providerPriceId","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlan | null>","isStatic":false,"isPublic":true},"findByStripePriceId":{"name":"findByStripePriceId","async":true,"parameters":[{"name":"stripePriceId","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlan | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_subscription_plans","api":{"include":["list","get","create","update"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SubscriptionPlan","exportName":"SubscriptionPlanCollection","collectionExportName":"SubscriptionPlanCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:SubscriptionPlan","inheritedExposure":["api","mcp"],"schema":{"tableName":"_smrt_subscription_plans","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_subscription_plans\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"plan_key\\" TEXT DEFAULT '',\\n \\"name\\" TEXT DEFAULT '',\\n \\"description\\" TEXT DEFAULT '',\\n \\"status\\" TEXT DEFAULT 'active',\\n \\"sort_order\\" INTEGER DEFAULT 0,\\n \\"price_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"billing_interval\\" TEXT DEFAULT 'month',\\n \\"pricing_mode\\" TEXT DEFAULT 'fixed',\\n \\"minimum_amount\\" INTEGER DEFAULT 0,\\n \\"suggested_amount\\" INTEGER DEFAULT 0,\\n \\"external_provider\\" TEXT,\\n \\"provider_product_id\\" TEXT,\\n \\"provider_price_id\\" TEXT,\\n \\"stripe_product_id\\" TEXT,\\n \\"stripe_price_id\\" TEXT,\\n \\"features\\" TEXT DEFAULT '[]',\\n \\"thresholds\\" TEXT DEFAULT '[]',\\n \\"metadata\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"plan_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"description":{"type":"TEXT","notNull":false,"unique":false,"default":""},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"active"},"sort_order":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"price_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"billing_interval":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"pricing_mode":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed"},"minimum_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"suggested_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"external_provider":{"type":"TEXT","notNull":false,"unique":false},"provider_product_id":{"type":"TEXT","notNull":false,"unique":false},"provider_price_id":{"type":"TEXT","notNull":false,"unique":false},"stripe_product_id":{"type":"TEXT","notNull":false,"unique":false},"stripe_price_id":{"type":"TEXT","notNull":false,"unique":false},"features":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"thresholds":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"metadata":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_subscription_plans_tenant_id_plan_key_idx","columns":["tenant_id","plan_key"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_subscription_plans_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_subscription_plans_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"458e59be"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SubscriptionPlanVersionCollection":{"name":"subscriptionplanversioncollection","className":"SubscriptionPlanVersionCollection","qualifiedName":"@happyvertical/smrt-subscriptions:SubscriptionPlanVersionCollection","collection":"subscriptionplanversions","description":"Effective-dated plan versions (#4032).","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/collections/SubscriptionPlanVersionCollection.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{"findVisibleById":{"name":"findVisibleById","async":true,"parameters":[{"name":"id","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlanVersion | null>","isStatic":false,"isPublic":true},"listForPlan":{"name":"listForPlan","async":true,"parameters":[{"name":"planId","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlanVersion[]>","isStatic":false,"isPublic":true},"findLatest":{"name":"findLatest","async":true,"parameters":[{"name":"planId","type":"string","optional":false},{"name":"tenantId","type":"string | null","optional":true,"unionBranches":[{"type":"string"},{"type":"null"}]}],"returnType":"Promise<SubscriptionPlanVersion | null>","isStatic":false,"isPublic":true},"findInForce":{"name":"findInForce","async":true,"parameters":[{"name":"planId","type":"string","optional":false},{"name":"at","type":"Date","optional":false}],"returnType":"Promise<SubscriptionPlanVersion | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_subscription_plan_versions","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SubscriptionPlanVersion","exportName":"SubscriptionPlanVersionCollection","collectionExportName":"SubscriptionPlanVersionCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_subscription_plan_versions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_subscription_plan_versions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"plan_id\\" UUID,\\n \\"plan_key\\" TEXT DEFAULT '',\\n \\"version\\" INTEGER DEFAULT 0,\\n \\"effective_from\\" TIMESTAMP,\\n \\"name\\" TEXT DEFAULT '',\\n \\"status\\" TEXT DEFAULT 'active',\\n \\"price_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"billing_interval\\" TEXT DEFAULT 'month',\\n \\"pricing_mode\\" TEXT DEFAULT 'fixed',\\n \\"minimum_amount\\" INTEGER DEFAULT 0,\\n \\"suggested_amount\\" INTEGER DEFAULT 0,\\n \\"features\\" TEXT DEFAULT '[]',\\n \\"thresholds\\" TEXT DEFAULT '[]'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"plan_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plans","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"plan_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"version":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"effective_from":{"type":"TIMESTAMP","notNull":false,"unique":false},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"active"},"price_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"billing_interval":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"pricing_mode":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed"},"minimum_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"suggested_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"features":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"thresholds":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"}},"indexes":[{"name":"_smrt_subscription_plan_versions_plan_id_version_idx","columns":["plan_id","version"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_subscription_plan_versions_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_subscription_plan_versions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"f42156f9"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:TenantSubscriptionCollection":{"name":"tenantsubscriptioncollection","className":"TenantSubscriptionCollection","qualifiedName":"@happyvertical/smrt-subscriptions:TenantSubscriptionCollection","collection":"tenantsubscriptions","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/collections/TenantSubscriptionCollection.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{"findByTenant":{"name":"findByTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<TenantSubscription[]>","isStatic":false,"isPublic":true},"findCurrentForTenant":{"name":"findCurrentForTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false},{"name":"now","type":"any","optional":true}],"returnType":"Promise<TenantSubscription | null>","isStatic":false,"isPublic":true},"findCurrentForSubscriber":{"name":"findCurrentForSubscriber","async":true,"parameters":[{"name":"subscriber","type":"Subscriber","optional":false},{"name":"now","type":"any","optional":true}],"returnType":"Promise<TenantSubscription | null>","isStatic":false,"isPublic":true},"findByStripeSubscriptionId":{"name":"findByStripeSubscriptionId","async":true,"parameters":[{"name":"stripeSubscriptionId","type":"string","optional":false}],"returnType":"Promise<TenantSubscription | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_tenant_subscriptions","api":{"include":["list","get","create","update"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"TenantSubscription","exportName":"TenantSubscriptionCollection","collectionExportName":"TenantSubscriptionCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:TenantSubscription","inheritedExposure":["api","mcp"],"schema":{"tableName":"_smrt_tenant_subscriptions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_tenant_subscriptions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"plan_id\\" UUID,\\n \\"status\\" TEXT DEFAULT 'incomplete',\\n \\"started_at\\" TIMESTAMP,\\n \\"current_period_start\\" TIMESTAMP,\\n \\"current_period_end\\" TIMESTAMP,\\n \\"trial_ends_at\\" TIMESTAMP,\\n \\"cancel_at_period_end\\" BOOLEAN DEFAULT FALSE,\\n \\"canceled_at\\" TIMESTAMP,\\n \\"agreed_amount\\" INTEGER,\\n \\"plan_version_id\\" UUID,\\n \\"plan_version_pinned_at\\" TIMESTAMP,\\n \\"plan_version_pin_reason\\" TEXT,\\n \\"plan_version_pin_note\\" TEXT DEFAULT '',\\n \\"retains_paid_period\\" BOOLEAN DEFAULT FALSE,\\n \\"external_provider\\" TEXT,\\n \\"stripe_customer_id\\" TEXT DEFAULT '',\\n \\"stripe_subscription_id\\" TEXT DEFAULT '',\\n \\"stripe_checkout_session_id\\" TEXT DEFAULT '',\\n \\"metadata\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"plan_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plans","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"incomplete"},"started_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"current_period_start":{"type":"TIMESTAMP","notNull":false,"unique":false},"current_period_end":{"type":"TIMESTAMP","notNull":false,"unique":false},"trial_ends_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"cancel_at_period_end":{"type":"BOOLEAN","notNull":false,"unique":false,"default":false},"canceled_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"agreed_amount":{"type":"INTEGER","notNull":false,"unique":false},"plan_version_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plan_versions","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"plan_version_pinned_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"plan_version_pin_reason":{"type":"TEXT","notNull":false,"unique":false},"plan_version_pin_note":{"type":"TEXT","notNull":false,"unique":false,"default":""},"retains_paid_period":{"type":"BOOLEAN","notNull":false,"unique":false,"default":false},"external_provider":{"type":"TEXT","notNull":false,"unique":false},"stripe_customer_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"stripe_subscription_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"stripe_checkout_session_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metadata":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_tenant_subscriptions_tenant_id_subscriber_kind_idx","columns":["tenant_id","subscriber_kind","subscriber_external_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_tenant_subscriptions_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_tenant_subscriptions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_tenant_subscriptions_plan_id_idx","columns":["plan_id"]},{"name":"_smrt_tenant_subscriptions_plan_version_id_idx","columns":["plan_version_id"]}],"version":"c281741d"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:TenantUsageMetricCollection":{"name":"tenantusagemetriccollection","className":"TenantUsageMetricCollection","qualifiedName":"@happyvertical/smrt-subscriptions:TenantUsageMetricCollection","collection":"tenantusagemetrics","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/collections/TenantUsageMetricCollection.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{"recordUsage":{"name":"recordUsage","async":true,"parameters":[{"name":"options","type":"RecordUsageOptions","optional":false}],"returnType":"Promise<TenantUsageMetric>","isStatic":false,"isPublic":true},"findByTenantAndMetric":{"name":"findByTenantAndMetric","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false},{"name":"metricKey","type":"string","optional":false}],"returnType":"Promise<TenantUsageMetric[]>","isStatic":false,"isPublic":true},"summarizeUsage":{"name":"summarizeUsage","async":true,"parameters":[{"name":"options","type":"SummarizeUsageOptions","optional":false}],"returnType":"Promise<UsageSummary>","isStatic":false,"isPublic":true},"summarizeUsageBatch":{"name":"summarizeUsageBatch","async":true,"parameters":[{"name":"options","type":"SummarizeUsageBatchOptions","optional":false}],"returnType":"Promise<UsageSummary[]>","isStatic":false,"isPublic":true},"summarizeTenantAiUsage":{"name":"summarizeTenantAiUsage","async":true,"parameters":[{"name":"options","type":"SummarizeAiUsageOptions","optional":false}],"returnType":"Promise<AiUsageSummary>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_tenant_usage_metrics","api":{"include":["list","get","create"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get","create"]}},"extends":"SmrtCollection","extendsTypeArg":"TenantUsageMetric","exportName":"TenantUsageMetricCollection","collectionExportName":"TenantUsageMetricCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:TenantUsageMetric","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_tenant_usage_metrics","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_tenant_usage_metrics\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"window_start\\" TIMESTAMP,\\n \\"window_end\\" TIMESTAMP,\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"dimensions\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"window_start":{"type":"TIMESTAMP","notNull":false,"unique":false},"window_end":{"type":"TIMESTAMP","notNull":false,"unique":false},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"dimensions":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_tenant_usage_metrics_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_tenant_usage_metrics_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"4884a70d"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SubscriptionPlan":{"name":"subscriptionplan","className":"SubscriptionPlan","qualifiedName":"@happyvertical/smrt-subscriptions:SubscriptionPlan","collection":"subscriptionplans","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/SubscriptionPlan.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":false,"_meta":{"sqlType":"UUID","nullable":true,"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false}}},"planKey":{"type":"text","required":false,"default":"","description":"A short code that identifies the plan, such as starter or pro.","_meta":{"description":"A short code that identifies the plan, such as starter or pro."}},"name":{"type":"text","required":false,"default":"","description":"What the plan is called, as customers see it.","_meta":{"description":"What the plan is called, as customers see it."}},"description":{"type":"text","required":false,"default":"","description":"A sentence or two about what the plan offers.","_meta":{"description":"A sentence or two about what the plan offers."}},"status":{"type":"text","required":false,"default":"active","description":"Whether the plan is a draft, on sale (active) or archived.","_meta":{"description":"Whether the plan is a draft, on sale (active) or archived."},"enum":["active","archived","draft"]},"sortOrder":{"type":"integer","required":false,"default":0,"description":"Where the plan sits when plans are listed; lower numbers come first.","_meta":{"description":"Where the plan sits when plans are listed; lower numbers come first."}},"priceAmount":{"type":"integer","required":false,"default":0,"description":"What the plan costs each billing period, in cents, as a whole number.","_meta":{"description":"What the plan costs each billing period, in cents, as a whole number."}},"currency":{"type":"text","required":false,"default":"USD","description":"The currency the price is in, such as USD.","_meta":{"description":"The currency the price is in, such as USD."}},"billingInterval":{"type":"text","required":false,"default":"month","description":"How often the subscriber is billed: every day, week, month or year.","_meta":{"description":"How often the subscriber is billed: every day, week, month or year."},"enum":["day","week","month","year"]},"pricingMode":{"type":"text","required":false,"default":"fixed","description":"Whether the plan is free, has a fixed price, or lets the subscriber choose what to pay. It cannot change once the plan is saved.","_meta":{"description":"Whether the plan is free, has a fixed price, or lets the subscriber choose what to pay. It cannot change once the plan is saved."},"enum":["free","fixed","pay_what_you_can"]},"minimumAmount":{"type":"integer","required":false,"default":0,"description":"For a pay-what-you-can plan, the least a subscriber may pay, in cents.","_meta":{"description":"For a pay-what-you-can plan, the least a subscriber may pay, in cents."}},"suggestedAmount":{"type":"integer","required":false,"default":0,"description":"For a pay-what-you-can plan, the amount suggested to the subscriber, in cents.","_meta":{"description":"For a pay-what-you-can plan, the amount suggested to the subscriber, in cents."}},"externalProvider":{"type":"text","required":false},"providerProductId":{"type":"text","required":false},"providerPriceId":{"type":"text","required":false},"stripeProductId":{"type":"text","required":false},"stripePriceId":{"type":"text","required":false},"features":{"type":"text","required":false,"default":"[]"},"thresholds":{"type":"text","required":false,"default":"[]"},"metadata":{"type":"text","required":false,"default":"{}"}},"methods":{"isActive":{"name":"isActive","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getTerms":{"name":"getTerms","async":false,"parameters":[],"returnType":"PlanTerms","isStatic":false,"isPublic":true},"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SmrtSaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"publishTerms":{"name":"publishTerms","async":true,"parameters":[{"name":"options","type":"object","optional":true,"memberTypes":["Date"]}],"returnType":"Promise<SubscriptionPlanVersion>","isStatic":false,"isPublic":true},"getVersionInForce":{"name":"getVersionInForce","async":true,"parameters":[{"name":"at","type":"any","optional":true}],"returnType":"Promise<SubscriptionPlanVersion | null>","isStatic":false,"isPublic":true},"getFeatureGrants":{"name":"getFeatureGrants","async":false,"parameters":[],"returnType":"PlanFeatureGrant[]","isStatic":false,"isPublic":true},"setFeatureGrants":{"name":"setFeatureGrants","async":false,"parameters":[{"name":"grants","type":"Array<string | PlanFeatureGrant>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getFeatureKeys":{"name":"getFeatureKeys","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true},"getThresholds":{"name":"getThresholds","async":false,"parameters":[],"returnType":"PlanThreshold[]","isStatic":false,"isPublic":true},"setThresholds":{"name":"setThresholds","async":false,"parameters":[{"name":"thresholds","type":"PlanThreshold[]","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getMetadata":{"name":"getMetadata","async":false,"parameters":[],"returnType":"JsonObject","isStatic":false,"isPublic":true},"setMetadata":{"name":"setMetadata","async":false,"parameters":[{"name":"metadata","type":"JsonObject","optional":false}],"returnType":"void","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_subscription_plans","api":{"include":["list","get","create","update"]},"cli":{"skipApiCheck":true},"mcp":{"include":["list","get"]},"conflictColumns":["tenant_id","plan_key"],"tenantScoped":{"mode":"optional"}},"extends":"SmrtObject","exportName":"SubscriptionPlan","collectionExportName":"SubscriptionPlanCollection","displayLabelField":"name","schema":{"tableName":"_smrt_subscription_plans","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_subscription_plans\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"plan_key\\" TEXT DEFAULT '',\\n \\"name\\" TEXT DEFAULT '',\\n \\"description\\" TEXT DEFAULT '',\\n \\"status\\" TEXT DEFAULT 'active',\\n \\"sort_order\\" INTEGER DEFAULT 0,\\n \\"price_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"billing_interval\\" TEXT DEFAULT 'month',\\n \\"pricing_mode\\" TEXT DEFAULT 'fixed',\\n \\"minimum_amount\\" INTEGER DEFAULT 0,\\n \\"suggested_amount\\" INTEGER DEFAULT 0,\\n \\"external_provider\\" TEXT,\\n \\"provider_product_id\\" TEXT,\\n \\"provider_price_id\\" TEXT,\\n \\"stripe_product_id\\" TEXT,\\n \\"stripe_price_id\\" TEXT,\\n \\"features\\" TEXT DEFAULT '[]',\\n \\"thresholds\\" TEXT DEFAULT '[]',\\n \\"metadata\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"plan_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"description":{"type":"TEXT","notNull":false,"unique":false,"default":""},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"active"},"sort_order":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"price_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"billing_interval":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"pricing_mode":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed"},"minimum_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"suggested_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"external_provider":{"type":"TEXT","notNull":false,"unique":false},"provider_product_id":{"type":"TEXT","notNull":false,"unique":false},"provider_price_id":{"type":"TEXT","notNull":false,"unique":false},"stripe_product_id":{"type":"TEXT","notNull":false,"unique":false},"stripe_price_id":{"type":"TEXT","notNull":false,"unique":false},"features":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"thresholds":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"metadata":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_subscription_plans_tenant_id_plan_key_idx","columns":["tenant_id","plan_key"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_subscription_plans_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_subscription_plans_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"458e59be"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion":{"name":"subscriptionplanversion","className":"SubscriptionPlanVersion","qualifiedName":"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion","collection":"subscriptionplanversions","description":"An immutable, effective-dated snapshot of a plan's terms (#4032).","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/SubscriptionPlanVersion.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":false,"_meta":{"sqlType":"UUID","nullable":true,"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false}}},"planId":{"type":"foreignKey","required":false,"related":"SubscriptionPlan","description":"The plan this version belongs to.","_meta":{"description":"The plan this version belongs to."}},"planKey":{"type":"text","required":false,"default":"","description":"The plan code at the time this version was published.","_meta":{"description":"The plan code at the time this version was published."}},"version":{"type":"integer","required":false,"default":0,"description":"Which version of the plan this is, counting from 1.","_meta":{"description":"Which version of the plan this is, counting from 1."}},"effectiveFrom":{"type":"datetime","required":false,"description":"The date and time from which these terms apply.","_meta":{"description":"The date and time from which these terms apply."}},"name":{"type":"text","required":false,"default":"","description":"What the plan was called when this version was published.","_meta":{"description":"What the plan was called when this version was published."}},"status":{"type":"text","required":false,"default":"active","description":"Whether the plan was a draft, on sale (active) or archived under this version.","_meta":{"description":"Whether the plan was a draft, on sale (active) or archived under this version."},"enum":["active","archived","draft"]},"priceAmount":{"type":"integer","required":false,"default":0,"description":"What the plan cost each billing period under this version, in cents.","_meta":{"description":"What the plan cost each billing period under this version, in cents."}},"currency":{"type":"text","required":false,"default":"USD","description":"The currency the price is in, such as USD.","_meta":{"description":"The currency the price is in, such as USD."}},"billingInterval":{"type":"text","required":false,"default":"month","description":"How often the subscriber was billed: every day, week, month or year.","_meta":{"description":"How often the subscriber was billed: every day, week, month or year."},"enum":["day","week","month","year"]},"pricingMode":{"type":"text","required":false,"default":"fixed","description":"Whether the plan was free, had a fixed price, or let the subscriber choose what to pay.","_meta":{"description":"Whether the plan was free, had a fixed price, or let the subscriber choose what to pay."},"enum":["free","fixed","pay_what_you_can"]},"minimumAmount":{"type":"integer","required":false,"default":0,"description":"For a pay-what-you-can plan, the least a subscriber could pay, in cents.","_meta":{"description":"For a pay-what-you-can plan, the least a subscriber could pay, in cents."}},"suggestedAmount":{"type":"integer","required":false,"default":0,"description":"For a pay-what-you-can plan, the amount suggested to the subscriber, in cents.","_meta":{"description":"For a pay-what-you-can plan, the amount suggested to the subscriber, in cents."}},"features":{"type":"text","required":false,"default":"[]"},"thresholds":{"type":"text","required":false,"default":"[]"}},"methods":{"isActive":{"name":"isActive","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getTerms":{"name":"getTerms","async":false,"parameters":[],"returnType":"PlanTerms","isStatic":false,"isPublic":true},"getFeatureGrants":{"name":"getFeatureGrants","async":false,"parameters":[],"returnType":"PlanFeatureGrant[]","isStatic":false,"isPublic":true},"getFeatureKeys":{"name":"getFeatureKeys","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true},"getThresholds":{"name":"getThresholds","async":false,"parameters":[],"returnType":"PlanThreshold[]","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_subscription_plan_versions","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"conflictColumns":["plan_id","version"],"hooks":{"beforeDelete":"refuseDelete"},"tenantScoped":{"mode":"optional"}},"extends":"SmrtObject","exportName":"SubscriptionPlanVersion","collectionExportName":"SubscriptionPlanVersionCollection","displayLabelField":"name","schema":{"tableName":"_smrt_subscription_plan_versions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_subscription_plan_versions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"plan_id\\" UUID,\\n \\"plan_key\\" TEXT DEFAULT '',\\n \\"version\\" INTEGER DEFAULT 0,\\n \\"effective_from\\" TIMESTAMP,\\n \\"name\\" TEXT DEFAULT '',\\n \\"status\\" TEXT DEFAULT 'active',\\n \\"price_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"billing_interval\\" TEXT DEFAULT 'month',\\n \\"pricing_mode\\" TEXT DEFAULT 'fixed',\\n \\"minimum_amount\\" INTEGER DEFAULT 0,\\n \\"suggested_amount\\" INTEGER DEFAULT 0,\\n \\"features\\" TEXT DEFAULT '[]',\\n \\"thresholds\\" TEXT DEFAULT '[]'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"plan_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plans","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"plan_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"version":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"effective_from":{"type":"TIMESTAMP","notNull":false,"unique":false},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"active"},"price_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"billing_interval":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"pricing_mode":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed"},"minimum_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"suggested_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"features":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"thresholds":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"}},"indexes":[{"name":"_smrt_subscription_plan_versions_plan_id_version_idx","columns":["plan_id","version"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_subscription_plan_versions_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_subscription_plan_versions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"f42156f9"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:TenantSubscription":{"name":"tenantsubscription","className":"TenantSubscription","qualifiedName":"@happyvertical/smrt-subscriptions:TenantSubscription","collection":"tenantsubscriptions","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/TenantSubscription.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"subscriberKind":{"type":"text","required":false,"default":"tenant","description":"Whether the subscriber is your own workspace (tenant) or an outside customer (external).","_meta":{"description":"Whether the subscriber is your own workspace (tenant) or an outside customer (external)."},"enum":["tenant","external"]},"subscriberExternalId":{"type":"text","required":false,"default":"","description":"Who the outside subscriber is, when the subscriber type is external.","_meta":{"description":"Who the outside subscriber is, when the subscriber type is external."}},"planId":{"type":"foreignKey","required":false,"related":"SubscriptionPlan","description":"The plan this subscription is for.","_meta":{"description":"The plan this subscription is for."}},"status":{"type":"text","required":false,"default":"incomplete","description":"Where the subscription stands: incomplete, trialing, active, past due, unpaid or cancelled.","_meta":{"description":"Where the subscription stands: incomplete, trialing, active, past due, unpaid or cancelled."},"enum":["active","canceled","incomplete","past_due","trialing","unpaid"]},"startedAt":{"type":"datetime","required":false,"description":"The day the subscription began.","_meta":{"description":"The day the subscription began."}},"currentPeriodStart":{"type":"datetime","required":false,"description":"When the current billing period began.","_meta":{"description":"When the current billing period began."}},"currentPeriodEnd":{"type":"datetime","required":false,"description":"When the current billing period ends and the next one is due.","_meta":{"description":"When the current billing period ends and the next one is due."}},"trialEndsAt":{"type":"datetime","required":false,"description":"When the free trial ends, if there is one.","_meta":{"description":"When the free trial ends, if there is one."}},"cancelAtPeriodEnd":{"type":"boolean","required":false,"default":false,"description":"Tick to let the subscription run out at the end of the current period instead of renewing.","_meta":{"description":"Tick to let the subscription run out at the end of the current period instead of renewing."}},"canceledAt":{"type":"datetime","required":false,"description":"When the subscription was cancelled.","_meta":{"description":"When the subscription was cancelled."}},"agreedAmount":{"type":"integer","required":false,"description":"For a pay-what-you-can plan, the amount the subscriber chose to pay, in cents.","_meta":{"description":"For a pay-what-you-can plan, the amount the subscriber chose to pay, in cents."}},"planVersionId":{"type":"foreignKey","required":false,"related":"SubscriptionPlanVersion","description":"The version of the plan terms this subscription is held to for the current period. It is kept up to date automatically.","_meta":{"description":"The version of the plan terms this subscription is held to for the current period. It is kept up to date automatically."}},"planVersionPinnedAt":{"type":"datetime","required":false},"planVersionPinReason":{"type":"text","required":false,"enum":["period_start","renewal","upgrade","authorized","migration"]},"planVersionPinNote":{"type":"text","required":false,"default":""},"retainsPaidPeriod":{"type":"boolean","required":false,"default":false},"externalProvider":{"type":"text","required":false},"stripeCustomerId":{"type":"text","required":false,"default":""},"stripeSubscriptionId":{"type":"text","required":false,"default":""},"stripeCheckoutSessionId":{"type":"text","required":false,"default":""},"metadata":{"type":"text","required":false,"default":"{}"}},"methods":{"replacePlanVersion":{"name":"replacePlanVersion","async":true,"parameters":[{"name":"options","type":"any","optional":false,"typeUnresolved":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"isEntitled":{"name":"isEntitled","async":false,"parameters":[{"name":"now","type":"any","optional":true}],"returnType":"boolean","isStatic":false,"isPublic":true},"getSubscriber":{"name":"getSubscriber","async":false,"parameters":[],"returnType":"Subscriber | null","isStatic":false,"isPublic":true},"getMetadata":{"name":"getMetadata","async":false,"parameters":[],"returnType":"JsonObject","isStatic":false,"isPublic":true},"setMetadata":{"name":"setMetadata","async":false,"parameters":[{"name":"metadata","type":"JsonObject","optional":false}],"returnType":"void","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_tenant_subscriptions","api":{"include":["list","get","create","update"]},"cli":{"skipApiCheck":true},"mcp":{"include":["list","get"]},"conflictColumns":["tenant_id","subscriber_kind","subscriber_external_id"],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"TenantSubscription","collectionExportName":"TenantSubscriptionCollection","validationRules":[],"schema":{"tableName":"_smrt_tenant_subscriptions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_tenant_subscriptions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"plan_id\\" UUID,\\n \\"status\\" TEXT DEFAULT 'incomplete',\\n \\"started_at\\" TIMESTAMP,\\n \\"current_period_start\\" TIMESTAMP,\\n \\"current_period_end\\" TIMESTAMP,\\n \\"trial_ends_at\\" TIMESTAMP,\\n \\"cancel_at_period_end\\" BOOLEAN DEFAULT FALSE,\\n \\"canceled_at\\" TIMESTAMP,\\n \\"agreed_amount\\" INTEGER,\\n \\"plan_version_id\\" UUID,\\n \\"plan_version_pinned_at\\" TIMESTAMP,\\n \\"plan_version_pin_reason\\" TEXT,\\n \\"plan_version_pin_note\\" TEXT DEFAULT '',\\n \\"retains_paid_period\\" BOOLEAN DEFAULT FALSE,\\n \\"external_provider\\" TEXT,\\n \\"stripe_customer_id\\" TEXT DEFAULT '',\\n \\"stripe_subscription_id\\" TEXT DEFAULT '',\\n \\"stripe_checkout_session_id\\" TEXT DEFAULT '',\\n \\"metadata\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"plan_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plans","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"incomplete"},"started_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"current_period_start":{"type":"TIMESTAMP","notNull":false,"unique":false},"current_period_end":{"type":"TIMESTAMP","notNull":false,"unique":false},"trial_ends_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"cancel_at_period_end":{"type":"BOOLEAN","notNull":false,"unique":false,"default":false},"canceled_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"agreed_amount":{"type":"INTEGER","notNull":false,"unique":false},"plan_version_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plan_versions","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"plan_version_pinned_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"plan_version_pin_reason":{"type":"TEXT","notNull":false,"unique":false},"plan_version_pin_note":{"type":"TEXT","notNull":false,"unique":false,"default":""},"retains_paid_period":{"type":"BOOLEAN","notNull":false,"unique":false,"default":false},"external_provider":{"type":"TEXT","notNull":false,"unique":false},"stripe_customer_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"stripe_subscription_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"stripe_checkout_session_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metadata":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_tenant_subscriptions_tenant_id_subscriber_kind_idx","columns":["tenant_id","subscriber_kind","subscriber_external_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_tenant_subscriptions_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_tenant_subscriptions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_tenant_subscriptions_plan_id_idx","columns":["plan_id"]},{"name":"_smrt_tenant_subscriptions_plan_version_id_idx","columns":["plan_version_id"]}],"version":"c281741d"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:TenantUsageMetric":{"name":"tenantusagemetric","className":"TenantUsageMetric","qualifiedName":"@happyvertical/smrt-subscriptions:TenantUsageMetric","collection":"tenantusagemetrics","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/TenantUsageMetric.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"subscriberKind":{"type":"text","required":false,"default":"tenant","enum":["tenant","external"]},"subscriberExternalId":{"type":"text","required":false,"default":""},"metricKey":{"type":"text","required":false,"default":""},"quantity":{"type":"decimal","required":false,"default":0},"windowStart":{"type":"datetime","required":false},"windowEnd":{"type":"datetime","required":false},"source":{"type":"text","required":false,"default":""},"sourceId":{"type":"text","required":false,"default":""},"projectId":{"type":"text","required":false,"default":""},"workRefType":{"type":"text","required":false,"default":""},"workRefId":{"type":"text","required":false,"default":""},"provider":{"type":"text","required":false,"default":""},"dimensions":{"type":"text","required":false,"default":"{}"}},"methods":{"getSubscriber":{"name":"getSubscriber","async":false,"parameters":[],"returnType":"Subscriber | null","isStatic":false,"isPublic":true},"getDimensions":{"name":"getDimensions","async":false,"parameters":[],"returnType":"JsonObject","isStatic":false,"isPublic":true},"setDimensions":{"name":"setDimensions","async":false,"parameters":[{"name":"dimensions","type":"JsonObject","optional":false}],"returnType":"void","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_tenant_usage_metrics","api":{"include":["list","get","create"]},"cli":{"include":["list","get","create"]},"mcp":{"include":["list","get"]},"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"TenantUsageMetric","collectionExportName":"TenantUsageMetricCollection","validationRules":[],"schema":{"tableName":"_smrt_tenant_usage_metrics","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_tenant_usage_metrics\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"window_start\\" TIMESTAMP,\\n \\"window_end\\" TIMESTAMP,\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"dimensions\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"window_start":{"type":"TIMESTAMP","notNull":false,"unique":false},"window_end":{"type":"TIMESTAMP","notNull":false,"unique":false},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"dimensions":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_tenant_usage_metrics_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_tenant_usage_metrics_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"4884a70d"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PricingRule":{"name":"pricingrule","className":"PricingRule","qualifiedName":"@happyvertical/smrt-subscriptions:PricingRule","collection":"pricingrules","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"ruleKey":{"type":"text","required":false,"default":""},"metricKey":{"type":"text","required":false,"default":""},"serviceKey":{"type":"text","required":false,"default":""},"strategy":{"type":"text","required":false,"default":"fixed_unit","enum":["fixed_unit","cost_plus","multiplier","tiered","included_overage","flat","custom"]},"currency":{"type":"text","required":false,"default":"USD"},"effectiveFrom":{"type":"datetime","required":false},"effectiveTo":{"type":"datetime","required":false},"priority":{"type":"integer","required":false,"default":0},"terms":{"type":"text","required":false,"default":"{}"},"active":{"type":"boolean","required":false,"default":true},"priceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"}},"methods":{"getTerms":{"name":"getTerms","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setTerms":{"name":"setTerms","async":false,"parameters":[{"name":"value","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_pricing_rules","api":true,"cli":true,"mcp":true,"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"PricingRule","collectionExportName":"PricingRuleCollection","validationRules":[],"schema":{"tableName":"_smrt_pricing_rules","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_pricing_rules\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"rule_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"strategy\\" TEXT DEFAULT 'fixed_unit',\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"effective_from\\" TIMESTAMP,\\n \\"effective_to\\" TIMESTAMP,\\n \\"priority\\" INTEGER DEFAULT 0,\\n \\"terms\\" TEXT DEFAULT '{}',\\n \\"active\\" BOOLEAN DEFAULT TRUE,\\n \\"price_book_id\\" UUID\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"rule_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"strategy":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed_unit"},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"effective_from":{"type":"TIMESTAMP","notNull":false,"unique":false},"effective_to":{"type":"TIMESTAMP","notNull":false,"unique":false},"priority":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"terms":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}}},"indexes":[{"name":"_smrt_pricing_rules_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_pricing_rules_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_pricing_rules_price_book_id_idx","columns":["price_book_id"]}],"version":"37fd6ea9"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:ClientCharge":{"name":"clientcharge","className":"ClientCharge","qualifiedName":"@happyvertical/smrt-subscriptions:ClientCharge","collection":"clientcharges","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"usageEventId":{"type":"foreignKey","required":false,"related":"TenantUsageMetric"},"usageTenantId":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:Tenant"},"subscriberKind":{"type":"text","required":false,"default":"tenant"},"subscriberExternalId":{"type":"text","required":false,"default":""},"projectId":{"type":"text","required":false,"default":""},"workRefType":{"type":"text","required":false,"default":""},"workRefId":{"type":"text","required":false,"default":""},"provider":{"type":"text","required":false,"default":"","description":"Who supplied the service that was used.","_meta":{"description":"Who supplied the service that was used."}},"serviceKey":{"type":"text","required":false,"default":"","description":"The service that was used.","_meta":{"description":"The service that was used."}},"metricKey":{"type":"text","required":false,"default":"","description":"What was used, such as messages sent or minutes of audio.","_meta":{"description":"What was used, such as messages sent or minutes of audio."}},"quantity":{"type":"decimal","required":false,"default":0,"description":"How much of it was used.","_meta":{"description":"How much of it was used."}},"amount":{"type":"integer","required":false,"default":0,"description":"What it cost, in cents.","_meta":{"description":"What it cost, in cents."}},"currency":{"type":"text","required":false,"default":"USD","description":"The currency the amount is in, such as USD.","_meta":{"description":"The currency the amount is in, such as USD."}},"pricingRuleId":{"type":"foreignKey","required":false,"related":"PricingRule"},"priceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"},"pricingSnapshot":{"type":"text","required":false,"default":"{}"},"status":{"type":"text","required":false,"default":"draft","description":"Where the charge stands: draft, approved or adjusted.","_meta":{"description":"Where the charge stands: draft, approved or adjusted."},"enum":["draft","approved","adjusted"]},"approvedAt":{"type":"datetime","required":false,"description":"When the charge was approved.","_meta":{"description":"When the charge was approved."}}},"methods":{"getPricingSnapshot":{"name":"getPricingSnapshot","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_client_charges","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"conflictColumns":["usage_event_id"],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"ClientCharge","collectionExportName":"ClientChargeCollection","validationRules":[],"schema":{"tableName":"_smrt_client_charges","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_client_charges\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"usage_event_id\\" UUID,\\n \\"usage_tenant_id\\" UUID,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"pricing_rule_id\\" UUID,\\n \\"price_book_id\\" UUID,\\n \\"pricing_snapshot\\" TEXT DEFAULT '{}',\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"approved_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"usage_event_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_tenant_usage_metrics","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"usage_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"pricing_rule_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_pricing_rules","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_snapshot":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"draft"},"approved_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_client_charges_usage_event_id_idx","columns":["usage_event_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_client_charges_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_client_charges_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_client_charges_usage_tenant_id_idx","columns":["usage_tenant_id"]},{"name":"_smrt_client_charges_pricing_rule_id_idx","columns":["pricing_rule_id"]},{"name":"_smrt_client_charges_price_book_id_idx","columns":["price_book_id"]}],"version":"92fb8003"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:BillingAdjustment":{"name":"billingadjustment","className":"BillingAdjustment","qualifiedName":"@happyvertical/smrt-subscriptions:BillingAdjustment","collection":"billingadjustments","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"clientChargeId":{"type":"foreignKey","required":false,"related":"ClientCharge"},"amount":{"type":"integer","required":false,"default":0},"currency":{"type":"text","required":false,"default":"USD"},"reason":{"type":"text","required":false,"default":""},"source":{"type":"text","required":false,"default":""},"sourceId":{"type":"text","required":false,"default":""},"createdBy":{"type":"text","required":false,"default":""}},"methods":{},"decoratorConfig":{"tableName":"_smrt_billing_adjustments","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"BillingAdjustment","collectionExportName":"BillingAdjustmentCollection","validationRules":[],"schema":{"tableName":"_smrt_billing_adjustments","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_billing_adjustments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"client_charge_id\\" UUID,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"created_by\\" TEXT DEFAULT ''\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"client_charge_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_client_charges","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"created_by":{"type":"TEXT","notNull":false,"unique":false,"default":""}},"indexes":[{"name":"_smrt_billing_adjustments_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_billing_adjustments_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_billing_adjustments_client_charge_id_idx","columns":["client_charge_id"]}],"version":"cfbd2832"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SpendingPolicy":{"name":"spendingpolicy","className":"SpendingPolicy","qualifiedName":"@happyvertical/smrt-subscriptions:SpendingPolicy","collection":"spendingpolicies","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"name":{"type":"text","required":false,"default":""},"subscriberKind":{"type":"text","required":false,"default":""},"subscriberExternalId":{"type":"text","required":false,"default":""},"projectId":{"type":"text","required":false,"default":""},"serviceKey":{"type":"text","required":false,"default":""},"metricKey":{"type":"text","required":false,"default":""},"period":{"type":"text","required":false,"default":"month","enum":["day","week","month","year","rolling","balance"]},"rollingSeconds":{"type":"integer","required":false,"default":0},"limitAmount":{"type":"integer","required":false,"default":0},"currency":{"type":"text","required":false,"default":"USD"},"behavior":{"type":"text","required":false,"default":"observe","enum":["observe","warn","block","approval_required"]},"priority":{"type":"integer","required":false,"default":0},"active":{"type":"boolean","required":false,"default":true},"basis":{"type":"text","required":false,"default":"billed","enum":["billed","retail","wholesale"]},"setByTenantId":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:Tenant"},"balanceFrom":{"type":"datetime","required":false}},"methods":{},"decoratorConfig":{"tableName":"_smrt_spending_policies","conflictColumns":["tenant_id","subscriber_kind","subscriber_external_id","project_id","service_key","metric_key","period","name"],"api":true,"cli":true,"mcp":true,"hooks":{"beforeDelete":"assertDelegationAuthority"},"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"SpendingPolicy","collectionExportName":"SpendingPolicyCollection","displayLabelField":"name","validationRules":[],"schema":{"tableName":"_smrt_spending_policies","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_spending_policies\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"name\\" TEXT DEFAULT '',\\n \\"subscriber_kind\\" TEXT DEFAULT '',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"period\\" TEXT DEFAULT 'month',\\n \\"rolling_seconds\\" INTEGER DEFAULT 0,\\n \\"limit_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"behavior\\" TEXT DEFAULT 'observe',\\n \\"priority\\" INTEGER DEFAULT 0,\\n \\"active\\" BOOLEAN DEFAULT TRUE,\\n \\"basis\\" TEXT DEFAULT 'billed',\\n \\"set_by_tenant_id\\" UUID,\\n \\"balance_from\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":""},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"period":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"rolling_seconds":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"limit_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"behavior":{"type":"TEXT","notNull":false,"unique":false,"default":"observe"},"priority":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"basis":{"type":"TEXT","notNull":false,"unique":false,"default":"billed"},"set_by_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"balance_from":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_spending_policies_tenant_id_subscriber_kind_idx","columns":["tenant_id","subscriber_kind","subscriber_external_id","project_id","service_key","metric_key","period","name"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_spending_policies_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_spending_policies_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_spending_policies_set_by_tenant_id_idx","columns":["set_by_tenant_id"]}],"version":"21fbbb20"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PricingRuleCollection":{"name":"pricingrulecollection","className":"PricingRuleCollection","qualifiedName":"@happyvertical/smrt-subscriptions:PricingRuleCollection","collection":"pricingrules","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_pricing_rules"},"extends":"SmrtCollection","extendsTypeArg":"PricingRule","exportName":"PricingRuleCollection","collectionExportName":"PricingRuleCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:PricingRule","schema":{"tableName":"_smrt_pricing_rules","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_pricing_rules\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"rule_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"strategy\\" TEXT DEFAULT 'fixed_unit',\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"effective_from\\" TIMESTAMP,\\n \\"effective_to\\" TIMESTAMP,\\n \\"priority\\" INTEGER DEFAULT 0,\\n \\"terms\\" TEXT DEFAULT '{}',\\n \\"active\\" BOOLEAN DEFAULT TRUE,\\n \\"price_book_id\\" UUID\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"rule_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"strategy":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed_unit"},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"effective_from":{"type":"TIMESTAMP","notNull":false,"unique":false},"effective_to":{"type":"TIMESTAMP","notNull":false,"unique":false},"priority":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"terms":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}}},"indexes":[{"name":"_smrt_pricing_rules_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_pricing_rules_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_pricing_rules_price_book_id_idx","columns":["price_book_id"]}],"version":"37fd6ea9"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:ClientChargeCollection":{"name":"clientchargecollection","className":"ClientChargeCollection","qualifiedName":"@happyvertical/smrt-subscriptions:ClientChargeCollection","collection":"clientcharges","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_client_charges","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"ClientCharge","exportName":"ClientChargeCollection","collectionExportName":"ClientChargeCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:ClientCharge","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_client_charges","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_client_charges\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"usage_event_id\\" UUID,\\n \\"usage_tenant_id\\" UUID,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"pricing_rule_id\\" UUID,\\n \\"price_book_id\\" UUID,\\n \\"pricing_snapshot\\" TEXT DEFAULT '{}',\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"approved_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"usage_event_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_tenant_usage_metrics","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"usage_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"pricing_rule_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_pricing_rules","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_snapshot":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"draft"},"approved_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_client_charges_usage_event_id_idx","columns":["usage_event_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_client_charges_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_client_charges_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_client_charges_usage_tenant_id_idx","columns":["usage_tenant_id"]},{"name":"_smrt_client_charges_pricing_rule_id_idx","columns":["pricing_rule_id"]},{"name":"_smrt_client_charges_price_book_id_idx","columns":["price_book_id"]}],"version":"92fb8003"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:BillingAdjustmentCollection":{"name":"billingadjustmentcollection","className":"BillingAdjustmentCollection","qualifiedName":"@happyvertical/smrt-subscriptions:BillingAdjustmentCollection","collection":"billingadjustments","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_billing_adjustments","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"BillingAdjustment","exportName":"BillingAdjustmentCollection","collectionExportName":"BillingAdjustmentCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:BillingAdjustment","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_billing_adjustments","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_billing_adjustments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"client_charge_id\\" UUID,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"created_by\\" TEXT DEFAULT ''\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"client_charge_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_client_charges","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"created_by":{"type":"TEXT","notNull":false,"unique":false,"default":""}},"indexes":[{"name":"_smrt_billing_adjustments_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_billing_adjustments_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_billing_adjustments_client_charge_id_idx","columns":["client_charge_id"]}],"version":"cfbd2832"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SpendingPolicyCollection":{"name":"spendingpolicycollection","className":"SpendingPolicyCollection","qualifiedName":"@happyvertical/smrt-subscriptions:SpendingPolicyCollection","collection":"spendingpolicies","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_spending_policies"},"extends":"SmrtCollection","extendsTypeArg":"SpendingPolicy","exportName":"SpendingPolicyCollection","collectionExportName":"SpendingPolicyCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:SpendingPolicy","schema":{"tableName":"_smrt_spending_policies","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_spending_policies\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"name\\" TEXT DEFAULT '',\\n \\"subscriber_kind\\" TEXT DEFAULT '',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"period\\" TEXT DEFAULT 'month',\\n \\"rolling_seconds\\" INTEGER DEFAULT 0,\\n \\"limit_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"behavior\\" TEXT DEFAULT 'observe',\\n \\"priority\\" INTEGER DEFAULT 0,\\n \\"active\\" BOOLEAN DEFAULT TRUE,\\n \\"basis\\" TEXT DEFAULT 'billed',\\n \\"set_by_tenant_id\\" UUID,\\n \\"balance_from\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":""},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"period":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"rolling_seconds":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"limit_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"behavior":{"type":"TEXT","notNull":false,"unique":false,"default":"observe"},"priority":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"basis":{"type":"TEXT","notNull":false,"unique":false,"default":"billed"},"set_by_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"balance_from":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_spending_policies_tenant_id_subscriber_kind_idx","columns":["tenant_id","subscriber_kind","subscriber_external_id","project_id","service_key","metric_key","period","name"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_spending_policies_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_spending_policies_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_spending_policies_set_by_tenant_id_idx","columns":["set_by_tenant_id"]}],"version":"21fbbb20"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PriceBook":{"name":"pricebook","className":"PriceBook","qualifiedName":"@happyvertical/smrt-subscriptions:PriceBook","collection":"pricebooks","description":"A named set of prices published by one seller tenant. Its prices are ordinary PricingRule rows that carry this book's id and the same tenant; one rule per currency gives a price in several currencies.","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"bookKey":{"type":"text","required":false,"default":""},"name":{"type":"text","required":false,"default":""},"kind":{"type":"text","required":false,"default":"retail","enum":["wholesale","retail"]},"active":{"type":"boolean","required":false,"default":true}},"methods":{},"decoratorConfig":{"tableName":"_smrt_price_books","conflictColumns":["tenant_id","book_key"],"api":false,"cli":false,"mcp":false,"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"PriceBook","collectionExportName":"PriceBookCollection","displayLabelField":"name","validationRules":[],"schema":{"tableName":"_smrt_price_books","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_price_books\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"book_key\\" TEXT DEFAULT '',\\n \\"name\\" TEXT DEFAULT '',\\n \\"kind\\" TEXT DEFAULT 'retail',\\n \\"active\\" BOOLEAN DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"book_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"kind":{"type":"TEXT","notNull":false,"unique":false,"default":"retail"},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true}},"indexes":[{"name":"_smrt_price_books_tenant_id_book_key_idx","columns":["tenant_id","book_key"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_price_books_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_price_books_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"56296d2f"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PriceBookAssignment":{"name":"pricebookassignment","className":"PriceBookAssignment","qualifiedName":"@happyvertical/smrt-subscriptions:PriceBookAssignment","collection":"pricebookassignments","description":"Which price books rate one child tenant's usage, keyed like the tenancy billing relationship it belongs to (one row per child).","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"childTenantId":{"type":"crossPackageRef","required":true,"related":"@happyvertical/smrt-users:Tenant","_meta":{"required":true}},"resellerTenantId":{"type":"crossPackageRef","required":true,"related":"@happyvertical/smrt-users:Tenant","_meta":{"required":true}},"wholesalePriceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"},"wholesaleCurrency":{"type":"text","required":false,"default":""},"retailPriceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"},"retailCurrency":{"type":"text","required":false,"default":""}},"methods":{},"decoratorConfig":{"tableName":"_smrt_price_book_assignments","conflictColumns":["child_tenant_id"],"api":false,"cli":false,"mcp":false},"extends":"SmrtObject","exportName":"PriceBookAssignment","collectionExportName":"PriceBookAssignmentCollection","validationRules":[{"field":"childTenantId","rule":"required","fieldType":"crossPackageRef"},{"field":"resellerTenantId","rule":"required","fieldType":"crossPackageRef"}],"schema":{"tableName":"_smrt_price_book_assignments","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_price_book_assignments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"child_tenant_id\\" UUID NOT NULL,\\n \\"reseller_tenant_id\\" UUID NOT NULL,\\n \\"wholesale_price_book_id\\" UUID,\\n \\"wholesale_currency\\" TEXT DEFAULT '',\\n \\"retail_price_book_id\\" UUID,\\n \\"retail_currency\\" TEXT DEFAULT ''\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"child_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"reseller_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"wholesale_price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"wholesale_currency":{"type":"TEXT","notNull":false,"unique":false,"default":""},"retail_price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"retail_currency":{"type":"TEXT","notNull":false,"unique":false,"default":""}},"indexes":[{"name":"_smrt_price_book_assignments_child_tenant_id_idx","columns":["child_tenant_id"],"unique":true},{"name":"_smrt_price_book_assignments_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_price_book_assignments_created_at_idx","columns":["created_at"]},{"name":"_smrt_price_book_assignments_reseller_tenant_id_idx","columns":["reseller_tenant_id"]},{"name":"_smrt_price_book_assignments_wholesale_price_book_id_idx","columns":["wholesale_price_book_id"]},{"name":"_smrt_price_book_assignments_retail_price_book_id_idx","columns":["retail_price_book_id"]}],"version":"990da9b7"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:RetailCharge":{"name":"retailcharge","className":"RetailCharge","qualifiedName":"@happyvertical/smrt-subscriptions:RetailCharge","collection":"retailcharges","description":"What a reseller charges one child for one usage event, priced from the reseller's retail book.","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"resellerTenantId":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:Tenant"},"usageEventId":{"type":"foreignKey","required":false,"related":"TenantUsageMetric"},"clientChargeId":{"type":"foreignKey","required":false,"related":"ClientCharge"},"subscriberKind":{"type":"text","required":false,"default":"tenant"},"subscriberExternalId":{"type":"text","required":false,"default":""},"projectId":{"type":"text","required":false,"default":""},"workRefType":{"type":"text","required":false,"default":""},"workRefId":{"type":"text","required":false,"default":""},"provider":{"type":"text","required":false,"default":""},"serviceKey":{"type":"text","required":false,"default":""},"metricKey":{"type":"text","required":false,"default":""},"quantity":{"type":"decimal","required":false,"default":0},"amount":{"type":"integer","required":false,"default":0},"currency":{"type":"text","required":false,"default":"USD"},"priceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"},"pricingRuleId":{"type":"foreignKey","required":false,"related":"PricingRule"},"pricingSnapshot":{"type":"text","required":false,"default":"{}"},"status":{"type":"text","required":false,"default":"draft","enum":["draft","approved"]},"approvedAt":{"type":"datetime","required":false}},"methods":{"getPricingSnapshot":{"name":"getPricingSnapshot","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_retail_charges","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"conflictColumns":["usage_event_id"],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"RetailCharge","collectionExportName":"RetailChargeCollection","validationRules":[],"schema":{"tableName":"_smrt_retail_charges","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_retail_charges\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"reseller_tenant_id\\" UUID,\\n \\"usage_event_id\\" UUID,\\n \\"client_charge_id\\" UUID,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"price_book_id\\" UUID,\\n \\"pricing_rule_id\\" UUID,\\n \\"pricing_snapshot\\" TEXT DEFAULT '{}',\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"approved_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"reseller_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"usage_event_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_tenant_usage_metrics","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"client_charge_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_client_charges","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_rule_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_pricing_rules","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_snapshot":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"draft"},"approved_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_retail_charges_usage_event_id_idx","columns":["usage_event_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_retail_charges_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_retail_charges_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_retail_charges_reseller_tenant_id_idx","columns":["reseller_tenant_id"]},{"name":"_smrt_retail_charges_client_charge_id_idx","columns":["client_charge_id"]},{"name":"_smrt_retail_charges_price_book_id_idx","columns":["price_book_id"]},{"name":"_smrt_retail_charges_pricing_rule_id_idx","columns":["pricing_rule_id"]}],"version":"ad6930a8"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:CreditGrant":{"name":"creditgrant","className":"CreditGrant","qualifiedName":"@happyvertical/smrt-subscriptions:CreditGrant","collection":"creditgrants","description":"An append-only credit on a prepaid (period: 'balance') spending policy. Positive amounts add credit; a negative amount reverses an earlier grant.","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"spendingPolicyId":{"type":"foreignKey","required":false,"related":"SpendingPolicy"},"amount":{"type":"integer","required":false,"default":0},"currency":{"type":"text","required":false,"default":"USD"},"reason":{"type":"text","required":false,"default":""},"source":{"type":"text","required":false,"default":""},"sourceId":{"type":"text","required":false,"default":""},"grantedByTenantId":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:Tenant"}},"methods":{},"decoratorConfig":{"tableName":"_smrt_credit_grants","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"hooks":{"beforeDelete":"refuseDelete"},"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"CreditGrant","collectionExportName":"CreditGrantCollection","validationRules":[],"schema":{"tableName":"_smrt_credit_grants","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_credit_grants\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"spending_policy_id\\" UUID,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"granted_by_tenant_id\\" UUID\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"spending_policy_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_spending_policies","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"granted_by_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_credit_grants_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_credit_grants_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_credit_grants_spending_policy_id_idx","columns":["spending_policy_id"]},{"name":"_smrt_credit_grants_granted_by_tenant_id_idx","columns":["granted_by_tenant_id"]}],"version":"e11305fc"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PriceBookCollection":{"name":"pricebookcollection","className":"PriceBookCollection","qualifiedName":"@happyvertical/smrt-subscriptions:PriceBookCollection","collection":"pricebooks","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_price_books","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"PriceBook","exportName":"PriceBookCollection","collectionExportName":"PriceBookCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:PriceBook","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_price_books","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_price_books\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"book_key\\" TEXT DEFAULT '',\\n \\"name\\" TEXT DEFAULT '',\\n \\"kind\\" TEXT DEFAULT 'retail',\\n \\"active\\" BOOLEAN DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"book_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"kind":{"type":"TEXT","notNull":false,"unique":false,"default":"retail"},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true}},"indexes":[{"name":"_smrt_price_books_tenant_id_book_key_idx","columns":["tenant_id","book_key"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_price_books_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_price_books_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"56296d2f"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PriceBookAssignmentCollection":{"name":"pricebookassignmentcollection","className":"PriceBookAssignmentCollection","qualifiedName":"@happyvertical/smrt-subscriptions:PriceBookAssignmentCollection","collection":"pricebookassignments","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_price_book_assignments","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"PriceBookAssignment","exportName":"PriceBookAssignmentCollection","collectionExportName":"PriceBookAssignmentCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:PriceBookAssignment","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_price_book_assignments","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_price_book_assignments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"child_tenant_id\\" UUID NOT NULL,\\n \\"reseller_tenant_id\\" UUID NOT NULL,\\n \\"wholesale_price_book_id\\" UUID,\\n \\"wholesale_currency\\" TEXT DEFAULT '',\\n \\"retail_price_book_id\\" UUID,\\n \\"retail_currency\\" TEXT DEFAULT ''\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"child_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"reseller_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"wholesale_price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"wholesale_currency":{"type":"TEXT","notNull":false,"unique":false,"default":""},"retail_price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"retail_currency":{"type":"TEXT","notNull":false,"unique":false,"default":""}},"indexes":[{"name":"_smrt_price_book_assignments_child_tenant_id_idx","columns":["child_tenant_id"],"unique":true},{"name":"_smrt_price_book_assignments_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_price_book_assignments_created_at_idx","columns":["created_at"]},{"name":"_smrt_price_book_assignments_reseller_tenant_id_idx","columns":["reseller_tenant_id"]},{"name":"_smrt_price_book_assignments_wholesale_price_book_id_idx","columns":["wholesale_price_book_id"]},{"name":"_smrt_price_book_assignments_retail_price_book_id_idx","columns":["retail_price_book_id"]}],"version":"990da9b7"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:RetailChargeCollection":{"name":"retailchargecollection","className":"RetailChargeCollection","qualifiedName":"@happyvertical/smrt-subscriptions:RetailChargeCollection","collection":"retailcharges","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_retail_charges","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"RetailCharge","exportName":"RetailChargeCollection","collectionExportName":"RetailChargeCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:RetailCharge","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_retail_charges","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_retail_charges\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"reseller_tenant_id\\" UUID,\\n \\"usage_event_id\\" UUID,\\n \\"client_charge_id\\" UUID,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"price_book_id\\" UUID,\\n \\"pricing_rule_id\\" UUID,\\n \\"pricing_snapshot\\" TEXT DEFAULT '{}',\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"approved_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"reseller_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"usage_event_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_tenant_usage_metrics","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"client_charge_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_client_charges","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_rule_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_pricing_rules","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_snapshot":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"draft"},"approved_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_retail_charges_usage_event_id_idx","columns":["usage_event_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_retail_charges_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_retail_charges_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_retail_charges_reseller_tenant_id_idx","columns":["reseller_tenant_id"]},{"name":"_smrt_retail_charges_client_charge_id_idx","columns":["client_charge_id"]},{"name":"_smrt_retail_charges_price_book_id_idx","columns":["price_book_id"]},{"name":"_smrt_retail_charges_pricing_rule_id_idx","columns":["pricing_rule_id"]}],"version":"ad6930a8"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:CreditGrantCollection":{"name":"creditgrantcollection","className":"CreditGrantCollection","qualifiedName":"@happyvertical/smrt-subscriptions:CreditGrantCollection","collection":"creditgrants","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_credit_grants","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"CreditGrant","exportName":"CreditGrantCollection","collectionExportName":"CreditGrantCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:CreditGrant","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_credit_grants","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_credit_grants\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"spending_policy_id\\" UUID,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"granted_by_tenant_id\\" UUID\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"spending_policy_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_spending_policies","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"granted_by_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_credit_grants_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_credit_grants_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_credit_grants_spending_policy_id_idx","columns":["spending_policy_id"]},{"name":"_smrt_credit_grants_granted_by_tenant_id_idx","columns":["granted_by_tenant_id"]}],"version":"e11305fc"},"importPath":"@happyvertical/smrt-subscriptions"}},"moduleType":"smrt","recipes":[{"id":"subscriptions.plans","className":"SubscriptionPlansRecipe","label":"Subscriptions","summary":"Sell plans that renew, see who is subscribed to which, and what their usage cost.","synonyms":["subscriptions","subscription plans","plans","memberships","recurring billing","pricing tiers"],"models":["@happyvertical/smrt-subscriptions:SubscriptionPlan","@happyvertical/smrt-subscriptions:SubscriptionPlanVersion","@happyvertical/smrt-subscriptions:TenantSubscription","@happyvertical/smrt-subscriptions:ClientCharge"],"nav":[{"label":"Plans","model":"@happyvertical/smrt-subscriptions:SubscriptionPlan","icon":"tag","description":"The plans you sell, with their price and how often they bill.","noun":"plan"},{"label":"Subscriptions","model":"@happyvertical/smrt-subscriptions:TenantSubscription","icon":"repeat","description":"Who is subscribed to which plan, and where each one stands.","noun":"subscription"},{"label":"Plan versions","model":"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion","icon":"fileText","description":"Every set of terms a plan has had, and from when each applied.","noun":"plan version"},{"label":"Charges","model":"@happyvertical/smrt-subscriptions:ClientCharge","icon":"receipt","description":"What each subscriber used and what it cost them.","noun":"charge"}],"requires":[],"section":{"id":"sales","label":"Sales","icon":"shoppingBag","description":"Customers, orders and quotes: everything you sell."},"options":{"@happyvertical/smrt-subscriptions:SubscriptionPlan":{"fields":{"name":{"order":1},"planKey":{"label":"Plan code","order":2},"description":{"order":3},"status":{"order":4},"priceAmount":{"label":"Price (in cents)","order":5},"currency":{"order":6},"billingInterval":{"label":"Billed every","order":7},"pricingMode":{"label":"How it is priced","order":8},"minimumAmount":{"label":"Minimum (in cents)","visibility":"advanced"},"suggestedAmount":{"label":"Suggested (in cents)","visibility":"advanced"},"sortOrder":{"label":"Position in list","visibility":"advanced"},"tenantId":{"visibility":"hidden"},"features":{"visibility":"hidden"},"thresholds":{"visibility":"hidden"},"externalProvider":{"visibility":"hidden"},"providerProductId":{"visibility":"hidden"},"providerPriceId":{"visibility":"hidden"},"stripeProductId":{"visibility":"hidden"},"stripePriceId":{"visibility":"hidden"},"metadata":{"visibility":"hidden"}}},"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion":{"fields":{"planId":{"label":"Plan","order":1},"version":{"label":"Version number","order":2},"effectiveFrom":{"label":"In force from","order":3},"name":{"order":4},"status":{"order":5},"priceAmount":{"label":"Price (in cents)","order":6},"currency":{"order":7},"billingInterval":{"label":"Billed every","order":8},"planKey":{"label":"Plan code","visibility":"advanced"},"pricingMode":{"label":"How it is priced","visibility":"advanced"},"minimumAmount":{"label":"Minimum (in cents)","visibility":"advanced"},"suggestedAmount":{"label":"Suggested (in cents)","visibility":"advanced"},"tenantId":{"visibility":"hidden"},"features":{"visibility":"hidden"},"thresholds":{"visibility":"hidden"}}},"@happyvertical/smrt-subscriptions:TenantSubscription":{"fields":{"planId":{"label":"Plan","order":1},"status":{"order":2},"startedAt":{"label":"Started on","order":3},"currentPeriodStart":{"label":"Current period starts","order":4},"currentPeriodEnd":{"label":"Current period ends","order":5},"trialEndsAt":{"label":"Trial ends","order":6},"cancelAtPeriodEnd":{"label":"Cancel at end of period","order":7},"canceledAt":{"label":"Cancelled on","visibility":"advanced"},"agreedAmount":{"label":"Agreed amount (in cents)","visibility":"advanced"},"subscriberKind":{"label":"Subscriber type","visibility":"advanced"},"subscriberExternalId":{"label":"Outside subscriber","visibility":"advanced"},"planVersionId":{"label":"Plan version","visibility":"advanced","locked":true},"tenantId":{"visibility":"hidden"},"planVersionPinnedAt":{"visibility":"hidden"},"planVersionPinReason":{"visibility":"hidden"},"planVersionPinNote":{"visibility":"hidden"},"retainsPaidPeriod":{"visibility":"hidden"},"externalProvider":{"visibility":"hidden"},"stripeCustomerId":{"visibility":"hidden"},"stripeSubscriptionId":{"visibility":"hidden"},"stripeCheckoutSessionId":{"visibility":"hidden"},"metadata":{"visibility":"hidden"}}},"@happyvertical/smrt-subscriptions:ClientCharge":{"fields":{"metricKey":{"label":"What was used","order":1},"quantity":{"label":"How much","order":2},"amount":{"label":"Amount (in cents)","order":3},"currency":{"order":4},"status":{"order":5},"approvedAt":{"label":"Approved on","order":6},"serviceKey":{"label":"Service","visibility":"advanced"},"provider":{"visibility":"advanced"},"tenantId":{"visibility":"hidden"},"usageEventId":{"visibility":"hidden"},"usageTenantId":{"visibility":"hidden"},"subscriberKind":{"visibility":"hidden"},"subscriberExternalId":{"visibility":"hidden"},"projectId":{"visibility":"hidden"},"workRefType":{"visibility":"hidden"},"workRefId":{"visibility":"hidden"},"pricingRuleId":{"visibility":"hidden"},"priceBookId":{"visibility":"hidden"},"pricingSnapshot":{"visibility":"hidden"}}}},"help":{"markdown":"## Overview\\n\\nSubscriptions is where you sell plans that renew. A plan says what it costs,\\nhow often it bills and whether it is free, a fixed price or pay what you can.\\nA subscription joins a subscriber to a plan and shows where it stands, from\\ntrial to active to cancelled. Every time you change a plan's terms, the\\nearlier terms are kept as a plan version, so a subscriber who already paid for\\na period keeps what they paid for until it renews. Charges show what each\\nsubscriber used and what it cost them.\\n\\nAll amounts are whole numbers of cents, with no decimal point.\\n\\n## Tasks\\n\\n### Set up a plan\\n\\n1. Open the plans and choose **New**.\\n2. Type the **{field:SubscriptionPlan.name}** customers will see and a short **{field:SubscriptionPlan.planKey}** such as \\"starter\\".\\n3. Choose **{field:SubscriptionPlan.pricingMode}**: free, a fixed price, or pay what you can. This cannot change once the plan is saved; make a new plan instead.\\n4. For a fixed price, enter the **{field:SubscriptionPlan.priceAmount}** in cents and the **{field:SubscriptionPlan.currency}**.\\n5. Set how often it bills in **{field:SubscriptionPlan.billingInterval}**.\\n6. Set the **{field:SubscriptionPlan.status}** to active when it is ready to sell.\\n7. Save.\\n\\n### Change a plan's price or terms\\n\\n1. Open the plan and edit the **{field:SubscriptionPlan.priceAmount}**, **{field:SubscriptionPlan.billingInterval}** or **{field:SubscriptionPlan.status}**.\\n2. Save. The new terms apply to new subscribers and to existing ones from their next renewal; a period already paid for keeps its old terms.\\n\\n### Retire a plan\\n\\n1. Open the plan and set its **{field:SubscriptionPlan.status}** to archived.\\n2. Save. No one new can subscribe to it; existing subscribers keep going until they cancel.\\n\\n### Subscribe someone to a plan\\n\\n1. Open the subscriptions and choose **New**.\\n2. Pick the **{field:TenantSubscription.planId}**.\\n3. Enter the day it **{field:TenantSubscription.startedAt}** and, if there is a free trial, when the **{field:TenantSubscription.trialEndsAt}**.\\n4. Save. The **{field:TenantSubscription.status}** shows where the subscription stands once it has been paid for.\\n\\n### See where a subscription stands\\n\\n1. Open the subscriptions and find the one you want.\\n2. The **{field:TenantSubscription.status}** shows whether it is still incomplete, on trial, active, past due, unpaid or cancelled.\\n3. **{field:TenantSubscription.currentPeriodStart}** and **{field:TenantSubscription.currentPeriodEnd}** show the period that has been paid for.\\n\\n### Cancel a subscription\\n\\n1. Open the subscription.\\n2. Tick **{field:TenantSubscription.cancelAtPeriodEnd}** so it runs out when the current period ends instead of renewing.\\n3. Save.\\n\\n### Look up the terms a subscriber was sold\\n\\nPlan versions are written automatically whenever a plan is saved with changed\\nterms; you cannot add or edit them here.\\n\\n1. Open the plan versions and find the **{field:SubscriptionPlanVersion.planId}** you are interested in.\\n2. Each row shows the **{field:SubscriptionPlanVersion.version}** and the date it was **{field:SubscriptionPlanVersion.effectiveFrom}**.\\n3. Read the **{field:SubscriptionPlanVersion.priceAmount}**, **{field:SubscriptionPlanVersion.currency}** and **{field:SubscriptionPlanVersion.billingInterval}** that applied under it.\\n\\n### See what a subscriber was charged\\n\\nCharges are created by the usage and billing service as usage is recorded;\\nyou cannot add or edit them here.\\n\\n1. Open the charges.\\n2. Each row shows **{field:ClientCharge.metricKey}**, **{field:ClientCharge.quantity}** and the **{field:ClientCharge.amount}** in cents.\\n3. The **{field:ClientCharge.status}** shows whether the charge is still a draft, approved or adjusted.\\n","fieldRefs":["ClientCharge.amount","ClientCharge.metricKey","ClientCharge.quantity","ClientCharge.status","SubscriptionPlan.billingInterval","SubscriptionPlan.currency","SubscriptionPlan.name","SubscriptionPlan.planKey","SubscriptionPlan.priceAmount","SubscriptionPlan.pricingMode","SubscriptionPlan.status","SubscriptionPlanVersion.billingInterval","SubscriptionPlanVersion.currency","SubscriptionPlanVersion.effectiveFrom","SubscriptionPlanVersion.planId","SubscriptionPlanVersion.priceAmount","SubscriptionPlanVersion.version","TenantSubscription.cancelAtPeriodEnd","TenantSubscription.currentPeriodEnd","TenantSubscription.currentPeriodStart","TenantSubscription.planId","TenantSubscription.startedAt","TenantSubscription.status","TenantSubscription.trialEndsAt"]},"demo":{"mode":"server","reasons":["Needs a server because its package does not build for a browser: core migrations (node:crypto, node:os); and its package depends on @happyvertical/smrt-tenancy, which do not build for a browser (#3624, #3626)."]}}],"smrtDependencies":["@happyvertical/smrt-core","@happyvertical/smrt-tenancy"],"browser":{"status":"server-only","issues":["#3624","#3626"],"reason":"core migrations (node:crypto, node:os)","via":["@happyvertical/smrt-tenancy"]},"stampsConstructors":true}`));
|
|
10
|
+
ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-subscriptions","packageVersion":"0.60.15","objects":{"@happyvertical/smrt-subscriptions:SubscriptionPlanCollection":{"name":"subscriptionplancollection","className":"SubscriptionPlanCollection","qualifiedName":"@happyvertical/smrt-subscriptions:SubscriptionPlanCollection","collection":"subscriptionplans","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/collections/SubscriptionPlanCollection.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{"findByPlanKey":{"name":"findByPlanKey","async":true,"parameters":[{"name":"tenantId","type":"string | null","optional":false,"unionBranches":[{"type":"string"},{"type":"null"}]},{"name":"planKey","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlan | null>","isStatic":false,"isPublic":true},"findActive":{"name":"findActive","async":true,"parameters":[],"returnType":"Promise<SubscriptionPlan[]>","isStatic":false,"isPublic":true},"findByProviderPriceId":{"name":"findByProviderPriceId","async":true,"parameters":[{"name":"providerPriceId","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlan | null>","isStatic":false,"isPublic":true},"findByStripePriceId":{"name":"findByStripePriceId","async":true,"parameters":[{"name":"stripePriceId","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlan | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_subscription_plans","api":{"include":["list","get","create","update"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SubscriptionPlan","exportName":"SubscriptionPlanCollection","collectionExportName":"SubscriptionPlanCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:SubscriptionPlan","inheritedExposure":["api","mcp"],"schema":{"tableName":"_smrt_subscription_plans","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_subscription_plans\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"plan_key\\" TEXT DEFAULT '',\\n \\"name\\" TEXT DEFAULT '',\\n \\"description\\" TEXT DEFAULT '',\\n \\"status\\" TEXT DEFAULT 'active',\\n \\"sort_order\\" INTEGER DEFAULT 0,\\n \\"price_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"billing_interval\\" TEXT DEFAULT 'month',\\n \\"pricing_mode\\" TEXT DEFAULT 'fixed',\\n \\"minimum_amount\\" INTEGER DEFAULT 0,\\n \\"suggested_amount\\" INTEGER DEFAULT 0,\\n \\"external_provider\\" TEXT,\\n \\"provider_product_id\\" TEXT,\\n \\"provider_price_id\\" TEXT,\\n \\"stripe_product_id\\" TEXT,\\n \\"stripe_price_id\\" TEXT,\\n \\"features\\" TEXT DEFAULT '[]',\\n \\"thresholds\\" TEXT DEFAULT '[]',\\n \\"metadata\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"plan_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"description":{"type":"TEXT","notNull":false,"unique":false,"default":""},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"active"},"sort_order":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"price_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"billing_interval":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"pricing_mode":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed"},"minimum_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"suggested_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"external_provider":{"type":"TEXT","notNull":false,"unique":false},"provider_product_id":{"type":"TEXT","notNull":false,"unique":false},"provider_price_id":{"type":"TEXT","notNull":false,"unique":false},"stripe_product_id":{"type":"TEXT","notNull":false,"unique":false},"stripe_price_id":{"type":"TEXT","notNull":false,"unique":false},"features":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"thresholds":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"metadata":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_subscription_plans_tenant_id_plan_key_idx","columns":["tenant_id","plan_key"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_subscription_plans_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_subscription_plans_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"458e59be"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SubscriptionPlanVersionCollection":{"name":"subscriptionplanversioncollection","className":"SubscriptionPlanVersionCollection","qualifiedName":"@happyvertical/smrt-subscriptions:SubscriptionPlanVersionCollection","collection":"subscriptionplanversions","description":"Effective-dated plan versions (#4032).","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/collections/SubscriptionPlanVersionCollection.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{"findVisibleById":{"name":"findVisibleById","async":true,"parameters":[{"name":"id","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlanVersion | null>","isStatic":false,"isPublic":true},"listForPlan":{"name":"listForPlan","async":true,"parameters":[{"name":"planId","type":"string","optional":false}],"returnType":"Promise<SubscriptionPlanVersion[]>","isStatic":false,"isPublic":true},"findLatest":{"name":"findLatest","async":true,"parameters":[{"name":"planId","type":"string","optional":false},{"name":"tenantId","type":"string | null","optional":true,"unionBranches":[{"type":"string"},{"type":"null"}]}],"returnType":"Promise<SubscriptionPlanVersion | null>","isStatic":false,"isPublic":true},"findInForce":{"name":"findInForce","async":true,"parameters":[{"name":"planId","type":"string","optional":false},{"name":"at","type":"Date","optional":false}],"returnType":"Promise<SubscriptionPlanVersion | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_subscription_plan_versions","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SubscriptionPlanVersion","exportName":"SubscriptionPlanVersionCollection","collectionExportName":"SubscriptionPlanVersionCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_subscription_plan_versions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_subscription_plan_versions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"plan_id\\" UUID,\\n \\"plan_key\\" TEXT DEFAULT '',\\n \\"version\\" INTEGER DEFAULT 0,\\n \\"effective_from\\" TIMESTAMP,\\n \\"name\\" TEXT DEFAULT '',\\n \\"status\\" TEXT DEFAULT 'active',\\n \\"price_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"billing_interval\\" TEXT DEFAULT 'month',\\n \\"pricing_mode\\" TEXT DEFAULT 'fixed',\\n \\"minimum_amount\\" INTEGER DEFAULT 0,\\n \\"suggested_amount\\" INTEGER DEFAULT 0,\\n \\"features\\" TEXT DEFAULT '[]',\\n \\"thresholds\\" TEXT DEFAULT '[]'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"plan_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plans","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"plan_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"version":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"effective_from":{"type":"TIMESTAMP","notNull":false,"unique":false},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"active"},"price_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"billing_interval":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"pricing_mode":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed"},"minimum_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"suggested_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"features":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"thresholds":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"}},"indexes":[{"name":"_smrt_subscription_plan_versions_plan_id_version_idx","columns":["plan_id","version"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_subscription_plan_versions_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_subscription_plan_versions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"f42156f9"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:TenantSubscriptionCollection":{"name":"tenantsubscriptioncollection","className":"TenantSubscriptionCollection","qualifiedName":"@happyvertical/smrt-subscriptions:TenantSubscriptionCollection","collection":"tenantsubscriptions","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/collections/TenantSubscriptionCollection.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{"findByTenant":{"name":"findByTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<TenantSubscription[]>","isStatic":false,"isPublic":true},"findCurrentForTenant":{"name":"findCurrentForTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false},{"name":"now","type":"any","optional":true}],"returnType":"Promise<TenantSubscription | null>","isStatic":false,"isPublic":true},"findCurrentForSubscriber":{"name":"findCurrentForSubscriber","async":true,"parameters":[{"name":"subscriber","type":"Subscriber","optional":false},{"name":"now","type":"any","optional":true}],"returnType":"Promise<TenantSubscription | null>","isStatic":false,"isPublic":true},"findByStripeSubscriptionId":{"name":"findByStripeSubscriptionId","async":true,"parameters":[{"name":"stripeSubscriptionId","type":"string","optional":false}],"returnType":"Promise<TenantSubscription | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_tenant_subscriptions","api":{"include":["list","get","create","update"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"TenantSubscription","exportName":"TenantSubscriptionCollection","collectionExportName":"TenantSubscriptionCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:TenantSubscription","inheritedExposure":["api","mcp"],"schema":{"tableName":"_smrt_tenant_subscriptions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_tenant_subscriptions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"plan_id\\" UUID,\\n \\"status\\" TEXT DEFAULT 'incomplete',\\n \\"started_at\\" TIMESTAMP,\\n \\"current_period_start\\" TIMESTAMP,\\n \\"current_period_end\\" TIMESTAMP,\\n \\"trial_ends_at\\" TIMESTAMP,\\n \\"cancel_at_period_end\\" BOOLEAN DEFAULT FALSE,\\n \\"canceled_at\\" TIMESTAMP,\\n \\"agreed_amount\\" INTEGER,\\n \\"plan_version_id\\" UUID,\\n \\"plan_version_pinned_at\\" TIMESTAMP,\\n \\"plan_version_pin_reason\\" TEXT,\\n \\"plan_version_pin_note\\" TEXT DEFAULT '',\\n \\"retains_paid_period\\" BOOLEAN DEFAULT FALSE,\\n \\"external_provider\\" TEXT,\\n \\"stripe_customer_id\\" TEXT DEFAULT '',\\n \\"stripe_subscription_id\\" TEXT DEFAULT '',\\n \\"stripe_checkout_session_id\\" TEXT DEFAULT '',\\n \\"metadata\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"plan_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plans","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"incomplete"},"started_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"current_period_start":{"type":"TIMESTAMP","notNull":false,"unique":false},"current_period_end":{"type":"TIMESTAMP","notNull":false,"unique":false},"trial_ends_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"cancel_at_period_end":{"type":"BOOLEAN","notNull":false,"unique":false,"default":false},"canceled_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"agreed_amount":{"type":"INTEGER","notNull":false,"unique":false},"plan_version_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plan_versions","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"plan_version_pinned_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"plan_version_pin_reason":{"type":"TEXT","notNull":false,"unique":false},"plan_version_pin_note":{"type":"TEXT","notNull":false,"unique":false,"default":""},"retains_paid_period":{"type":"BOOLEAN","notNull":false,"unique":false,"default":false},"external_provider":{"type":"TEXT","notNull":false,"unique":false},"stripe_customer_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"stripe_subscription_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"stripe_checkout_session_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metadata":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_tenant_subscriptions_tenant_id_subscriber_kind_idx","columns":["tenant_id","subscriber_kind","subscriber_external_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_tenant_subscriptions_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_tenant_subscriptions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_tenant_subscriptions_plan_id_idx","columns":["plan_id"]},{"name":"_smrt_tenant_subscriptions_plan_version_id_idx","columns":["plan_version_id"]}],"version":"c281741d"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:TenantUsageMetricCollection":{"name":"tenantusagemetriccollection","className":"TenantUsageMetricCollection","qualifiedName":"@happyvertical/smrt-subscriptions:TenantUsageMetricCollection","collection":"tenantusagemetrics","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/collections/TenantUsageMetricCollection.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{"recordUsage":{"name":"recordUsage","async":true,"parameters":[{"name":"options","type":"RecordUsageOptions","optional":false}],"returnType":"Promise<TenantUsageMetric>","isStatic":false,"isPublic":true},"findByTenantAndMetric":{"name":"findByTenantAndMetric","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false},{"name":"metricKey","type":"string","optional":false}],"returnType":"Promise<TenantUsageMetric[]>","isStatic":false,"isPublic":true},"summarizeUsage":{"name":"summarizeUsage","async":true,"parameters":[{"name":"options","type":"SummarizeUsageOptions","optional":false}],"returnType":"Promise<UsageSummary>","isStatic":false,"isPublic":true},"summarizeUsageBatch":{"name":"summarizeUsageBatch","async":true,"parameters":[{"name":"options","type":"SummarizeUsageBatchOptions","optional":false}],"returnType":"Promise<UsageSummary[]>","isStatic":false,"isPublic":true},"summarizeTenantAiUsage":{"name":"summarizeTenantAiUsage","async":true,"parameters":[{"name":"options","type":"SummarizeAiUsageOptions","optional":false}],"returnType":"Promise<AiUsageSummary>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_tenant_usage_metrics","api":{"include":["list","get","create"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get","create"]}},"extends":"SmrtCollection","extendsTypeArg":"TenantUsageMetric","exportName":"TenantUsageMetricCollection","collectionExportName":"TenantUsageMetricCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:TenantUsageMetric","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_tenant_usage_metrics","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_tenant_usage_metrics\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"window_start\\" TIMESTAMP,\\n \\"window_end\\" TIMESTAMP,\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"dimensions\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"window_start":{"type":"TIMESTAMP","notNull":false,"unique":false},"window_end":{"type":"TIMESTAMP","notNull":false,"unique":false},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"dimensions":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_tenant_usage_metrics_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_tenant_usage_metrics_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"4884a70d"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SubscriptionPlan":{"name":"subscriptionplan","className":"SubscriptionPlan","qualifiedName":"@happyvertical/smrt-subscriptions:SubscriptionPlan","collection":"subscriptionplans","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/SubscriptionPlan.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":false,"_meta":{"sqlType":"UUID","nullable":true,"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false}}},"planKey":{"type":"text","required":false,"default":"","description":"A short code that identifies the plan, such as starter or pro.","_meta":{"description":"A short code that identifies the plan, such as starter or pro."}},"name":{"type":"text","required":false,"default":"","description":"What the plan is called, as customers see it.","_meta":{"description":"What the plan is called, as customers see it."}},"description":{"type":"text","required":false,"default":"","description":"A sentence or two about what the plan offers.","_meta":{"description":"A sentence or two about what the plan offers."}},"status":{"type":"text","required":false,"default":"active","description":"Whether the plan is a draft, on sale (active) or archived.","_meta":{"description":"Whether the plan is a draft, on sale (active) or archived."},"enum":["active","archived","draft"]},"sortOrder":{"type":"integer","required":false,"default":0,"description":"Where the plan sits when plans are listed; lower numbers come first.","_meta":{"description":"Where the plan sits when plans are listed; lower numbers come first."}},"priceAmount":{"type":"integer","required":false,"default":0,"description":"What the plan costs each billing period, in cents, as a whole number.","_meta":{"description":"What the plan costs each billing period, in cents, as a whole number."}},"currency":{"type":"text","required":false,"default":"USD","description":"The currency the price is in, such as USD.","_meta":{"description":"The currency the price is in, such as USD."}},"billingInterval":{"type":"text","required":false,"default":"month","description":"How often the subscriber is billed: every day, week, month or year.","_meta":{"description":"How often the subscriber is billed: every day, week, month or year."},"enum":["day","week","month","year"]},"pricingMode":{"type":"text","required":false,"default":"fixed","description":"Whether the plan is free, has a fixed price, or lets the subscriber choose what to pay. It cannot change once the plan is saved.","_meta":{"description":"Whether the plan is free, has a fixed price, or lets the subscriber choose what to pay. It cannot change once the plan is saved."},"enum":["free","fixed","pay_what_you_can"]},"minimumAmount":{"type":"integer","required":false,"default":0,"description":"For a pay-what-you-can plan, the least a subscriber may pay, in cents.","_meta":{"description":"For a pay-what-you-can plan, the least a subscriber may pay, in cents."}},"suggestedAmount":{"type":"integer","required":false,"default":0,"description":"For a pay-what-you-can plan, the amount suggested to the subscriber, in cents.","_meta":{"description":"For a pay-what-you-can plan, the amount suggested to the subscriber, in cents."}},"externalProvider":{"type":"text","required":false},"providerProductId":{"type":"text","required":false},"providerPriceId":{"type":"text","required":false},"stripeProductId":{"type":"text","required":false},"stripePriceId":{"type":"text","required":false},"features":{"type":"text","required":false,"default":"[]"},"thresholds":{"type":"text","required":false,"default":"[]"},"metadata":{"type":"text","required":false,"default":"{}"}},"methods":{"isActive":{"name":"isActive","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getTerms":{"name":"getTerms","async":false,"parameters":[],"returnType":"PlanTerms","isStatic":false,"isPublic":true},"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SmrtSaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"publishTerms":{"name":"publishTerms","async":true,"parameters":[{"name":"options","type":"object","optional":true,"memberTypes":["Date"]}],"returnType":"Promise<SubscriptionPlanVersion>","isStatic":false,"isPublic":true},"getVersionInForce":{"name":"getVersionInForce","async":true,"parameters":[{"name":"at","type":"any","optional":true}],"returnType":"Promise<SubscriptionPlanVersion | null>","isStatic":false,"isPublic":true},"getFeatureGrants":{"name":"getFeatureGrants","async":false,"parameters":[],"returnType":"PlanFeatureGrant[]","isStatic":false,"isPublic":true},"setFeatureGrants":{"name":"setFeatureGrants","async":false,"parameters":[{"name":"grants","type":"Array<string | PlanFeatureGrant>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getFeatureKeys":{"name":"getFeatureKeys","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true},"getThresholds":{"name":"getThresholds","async":false,"parameters":[],"returnType":"PlanThreshold[]","isStatic":false,"isPublic":true},"setThresholds":{"name":"setThresholds","async":false,"parameters":[{"name":"thresholds","type":"PlanThreshold[]","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getMetadata":{"name":"getMetadata","async":false,"parameters":[],"returnType":"JsonObject","isStatic":false,"isPublic":true},"setMetadata":{"name":"setMetadata","async":false,"parameters":[{"name":"metadata","type":"JsonObject","optional":false}],"returnType":"void","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_subscription_plans","api":{"include":["list","get","create","update"]},"cli":{"skipApiCheck":true},"mcp":{"include":["list","get"]},"conflictColumns":["tenant_id","plan_key"],"tenantScoped":{"mode":"optional"}},"extends":"SmrtObject","exportName":"SubscriptionPlan","collectionExportName":"SubscriptionPlanCollection","displayLabelField":"name","schema":{"tableName":"_smrt_subscription_plans","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_subscription_plans\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"plan_key\\" TEXT DEFAULT '',\\n \\"name\\" TEXT DEFAULT '',\\n \\"description\\" TEXT DEFAULT '',\\n \\"status\\" TEXT DEFAULT 'active',\\n \\"sort_order\\" INTEGER DEFAULT 0,\\n \\"price_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"billing_interval\\" TEXT DEFAULT 'month',\\n \\"pricing_mode\\" TEXT DEFAULT 'fixed',\\n \\"minimum_amount\\" INTEGER DEFAULT 0,\\n \\"suggested_amount\\" INTEGER DEFAULT 0,\\n \\"external_provider\\" TEXT,\\n \\"provider_product_id\\" TEXT,\\n \\"provider_price_id\\" TEXT,\\n \\"stripe_product_id\\" TEXT,\\n \\"stripe_price_id\\" TEXT,\\n \\"features\\" TEXT DEFAULT '[]',\\n \\"thresholds\\" TEXT DEFAULT '[]',\\n \\"metadata\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"plan_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"description":{"type":"TEXT","notNull":false,"unique":false,"default":""},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"active"},"sort_order":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"price_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"billing_interval":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"pricing_mode":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed"},"minimum_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"suggested_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"external_provider":{"type":"TEXT","notNull":false,"unique":false},"provider_product_id":{"type":"TEXT","notNull":false,"unique":false},"provider_price_id":{"type":"TEXT","notNull":false,"unique":false},"stripe_product_id":{"type":"TEXT","notNull":false,"unique":false},"stripe_price_id":{"type":"TEXT","notNull":false,"unique":false},"features":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"thresholds":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"metadata":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_subscription_plans_tenant_id_plan_key_idx","columns":["tenant_id","plan_key"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_subscription_plans_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_subscription_plans_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"458e59be"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion":{"name":"subscriptionplanversion","className":"SubscriptionPlanVersion","qualifiedName":"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion","collection":"subscriptionplanversions","description":"An immutable, effective-dated snapshot of a plan's terms (#4032).","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/SubscriptionPlanVersion.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":false,"_meta":{"sqlType":"UUID","nullable":true,"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false}}},"planId":{"type":"foreignKey","required":false,"related":"SubscriptionPlan","description":"The plan this version belongs to.","_meta":{"description":"The plan this version belongs to."}},"planKey":{"type":"text","required":false,"default":"","description":"The plan code at the time this version was published.","_meta":{"description":"The plan code at the time this version was published."}},"version":{"type":"integer","required":false,"default":0,"description":"Which version of the plan this is, counting from 1.","_meta":{"description":"Which version of the plan this is, counting from 1."}},"effectiveFrom":{"type":"datetime","required":false,"description":"The date and time from which these terms apply.","_meta":{"description":"The date and time from which these terms apply."}},"name":{"type":"text","required":false,"default":"","description":"What the plan was called when this version was published.","_meta":{"description":"What the plan was called when this version was published."}},"status":{"type":"text","required":false,"default":"active","description":"Whether the plan was a draft, on sale (active) or archived under this version.","_meta":{"description":"Whether the plan was a draft, on sale (active) or archived under this version."},"enum":["active","archived","draft"]},"priceAmount":{"type":"integer","required":false,"default":0,"description":"What the plan cost each billing period under this version, in cents.","_meta":{"description":"What the plan cost each billing period under this version, in cents."}},"currency":{"type":"text","required":false,"default":"USD","description":"The currency the price is in, such as USD.","_meta":{"description":"The currency the price is in, such as USD."}},"billingInterval":{"type":"text","required":false,"default":"month","description":"How often the subscriber was billed: every day, week, month or year.","_meta":{"description":"How often the subscriber was billed: every day, week, month or year."},"enum":["day","week","month","year"]},"pricingMode":{"type":"text","required":false,"default":"fixed","description":"Whether the plan was free, had a fixed price, or let the subscriber choose what to pay.","_meta":{"description":"Whether the plan was free, had a fixed price, or let the subscriber choose what to pay."},"enum":["free","fixed","pay_what_you_can"]},"minimumAmount":{"type":"integer","required":false,"default":0,"description":"For a pay-what-you-can plan, the least a subscriber could pay, in cents.","_meta":{"description":"For a pay-what-you-can plan, the least a subscriber could pay, in cents."}},"suggestedAmount":{"type":"integer","required":false,"default":0,"description":"For a pay-what-you-can plan, the amount suggested to the subscriber, in cents.","_meta":{"description":"For a pay-what-you-can plan, the amount suggested to the subscriber, in cents."}},"features":{"type":"text","required":false,"default":"[]"},"thresholds":{"type":"text","required":false,"default":"[]"}},"methods":{"isActive":{"name":"isActive","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getTerms":{"name":"getTerms","async":false,"parameters":[],"returnType":"PlanTerms","isStatic":false,"isPublic":true},"getFeatureGrants":{"name":"getFeatureGrants","async":false,"parameters":[],"returnType":"PlanFeatureGrant[]","isStatic":false,"isPublic":true},"getFeatureKeys":{"name":"getFeatureKeys","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true},"getThresholds":{"name":"getThresholds","async":false,"parameters":[],"returnType":"PlanThreshold[]","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_subscription_plan_versions","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"conflictColumns":["plan_id","version"],"hooks":{"beforeDelete":"refuseDelete"},"tenantScoped":{"mode":"optional"}},"extends":"SmrtObject","exportName":"SubscriptionPlanVersion","collectionExportName":"SubscriptionPlanVersionCollection","displayLabelField":"name","schema":{"tableName":"_smrt_subscription_plan_versions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_subscription_plan_versions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"plan_id\\" UUID,\\n \\"plan_key\\" TEXT DEFAULT '',\\n \\"version\\" INTEGER DEFAULT 0,\\n \\"effective_from\\" TIMESTAMP,\\n \\"name\\" TEXT DEFAULT '',\\n \\"status\\" TEXT DEFAULT 'active',\\n \\"price_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"billing_interval\\" TEXT DEFAULT 'month',\\n \\"pricing_mode\\" TEXT DEFAULT 'fixed',\\n \\"minimum_amount\\" INTEGER DEFAULT 0,\\n \\"suggested_amount\\" INTEGER DEFAULT 0,\\n \\"features\\" TEXT DEFAULT '[]',\\n \\"thresholds\\" TEXT DEFAULT '[]'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"plan_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plans","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"plan_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"version":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"effective_from":{"type":"TIMESTAMP","notNull":false,"unique":false},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"active"},"price_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"billing_interval":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"pricing_mode":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed"},"minimum_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"suggested_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"features":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"},"thresholds":{"type":"TEXT","notNull":false,"unique":false,"default":"[]"}},"indexes":[{"name":"_smrt_subscription_plan_versions_plan_id_version_idx","columns":["plan_id","version"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_subscription_plan_versions_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_subscription_plan_versions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"f42156f9"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:TenantSubscription":{"name":"tenantsubscription","className":"TenantSubscription","qualifiedName":"@happyvertical/smrt-subscriptions:TenantSubscription","collection":"tenantsubscriptions","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/TenantSubscription.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"subscriberKind":{"type":"text","required":false,"default":"tenant","description":"Whether the subscriber is your own workspace (tenant) or an outside customer (external).","_meta":{"description":"Whether the subscriber is your own workspace (tenant) or an outside customer (external)."},"enum":["tenant","external"]},"subscriberExternalId":{"type":"text","required":false,"default":"","description":"Who the outside subscriber is, when the subscriber type is external.","_meta":{"description":"Who the outside subscriber is, when the subscriber type is external."}},"planId":{"type":"foreignKey","required":false,"related":"SubscriptionPlan","description":"The plan this subscription is for.","_meta":{"description":"The plan this subscription is for."}},"status":{"type":"text","required":false,"default":"incomplete","description":"Where the subscription stands: incomplete, trialing, active, past due, unpaid or cancelled.","_meta":{"description":"Where the subscription stands: incomplete, trialing, active, past due, unpaid or cancelled."},"enum":["active","canceled","incomplete","past_due","trialing","unpaid"]},"startedAt":{"type":"datetime","required":false,"description":"The day the subscription began.","_meta":{"description":"The day the subscription began."}},"currentPeriodStart":{"type":"datetime","required":false,"description":"When the current billing period began.","_meta":{"description":"When the current billing period began."}},"currentPeriodEnd":{"type":"datetime","required":false,"description":"When the current billing period ends and the next one is due.","_meta":{"description":"When the current billing period ends and the next one is due."}},"trialEndsAt":{"type":"datetime","required":false,"description":"When the free trial ends, if there is one.","_meta":{"description":"When the free trial ends, if there is one."}},"cancelAtPeriodEnd":{"type":"boolean","required":false,"default":false,"description":"Tick to let the subscription run out at the end of the current period instead of renewing.","_meta":{"description":"Tick to let the subscription run out at the end of the current period instead of renewing."}},"canceledAt":{"type":"datetime","required":false,"description":"When the subscription was cancelled.","_meta":{"description":"When the subscription was cancelled."}},"agreedAmount":{"type":"integer","required":false,"description":"For a pay-what-you-can plan, the amount the subscriber chose to pay, in cents.","_meta":{"description":"For a pay-what-you-can plan, the amount the subscriber chose to pay, in cents."}},"planVersionId":{"type":"foreignKey","required":false,"related":"SubscriptionPlanVersion","description":"The version of the plan terms this subscription is held to for the current period. It is kept up to date automatically.","_meta":{"description":"The version of the plan terms this subscription is held to for the current period. It is kept up to date automatically."}},"planVersionPinnedAt":{"type":"datetime","required":false},"planVersionPinReason":{"type":"text","required":false,"enum":["period_start","renewal","upgrade","authorized","migration"]},"planVersionPinNote":{"type":"text","required":false,"default":""},"retainsPaidPeriod":{"type":"boolean","required":false,"default":false},"externalProvider":{"type":"text","required":false},"stripeCustomerId":{"type":"text","required":false,"default":""},"stripeSubscriptionId":{"type":"text","required":false,"default":""},"stripeCheckoutSessionId":{"type":"text","required":false,"default":""},"metadata":{"type":"text","required":false,"default":"{}"}},"methods":{"replacePlanVersion":{"name":"replacePlanVersion","async":true,"parameters":[{"name":"options","type":"any","optional":false,"typeUnresolved":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"isEntitled":{"name":"isEntitled","async":false,"parameters":[{"name":"now","type":"any","optional":true}],"returnType":"boolean","isStatic":false,"isPublic":true},"getSubscriber":{"name":"getSubscriber","async":false,"parameters":[],"returnType":"Subscriber | null","isStatic":false,"isPublic":true},"getMetadata":{"name":"getMetadata","async":false,"parameters":[],"returnType":"JsonObject","isStatic":false,"isPublic":true},"setMetadata":{"name":"setMetadata","async":false,"parameters":[{"name":"metadata","type":"JsonObject","optional":false}],"returnType":"void","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_tenant_subscriptions","api":{"include":["list","get","create","update"]},"cli":{"skipApiCheck":true},"mcp":{"include":["list","get"]},"conflictColumns":["tenant_id","subscriber_kind","subscriber_external_id"],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"TenantSubscription","collectionExportName":"TenantSubscriptionCollection","validationRules":[],"schema":{"tableName":"_smrt_tenant_subscriptions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_tenant_subscriptions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"plan_id\\" UUID,\\n \\"status\\" TEXT DEFAULT 'incomplete',\\n \\"started_at\\" TIMESTAMP,\\n \\"current_period_start\\" TIMESTAMP,\\n \\"current_period_end\\" TIMESTAMP,\\n \\"trial_ends_at\\" TIMESTAMP,\\n \\"cancel_at_period_end\\" BOOLEAN DEFAULT FALSE,\\n \\"canceled_at\\" TIMESTAMP,\\n \\"agreed_amount\\" INTEGER,\\n \\"plan_version_id\\" UUID,\\n \\"plan_version_pinned_at\\" TIMESTAMP,\\n \\"plan_version_pin_reason\\" TEXT,\\n \\"plan_version_pin_note\\" TEXT DEFAULT '',\\n \\"retains_paid_period\\" BOOLEAN DEFAULT FALSE,\\n \\"external_provider\\" TEXT,\\n \\"stripe_customer_id\\" TEXT DEFAULT '',\\n \\"stripe_subscription_id\\" TEXT DEFAULT '',\\n \\"stripe_checkout_session_id\\" TEXT DEFAULT '',\\n \\"metadata\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"plan_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plans","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"incomplete"},"started_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"current_period_start":{"type":"TIMESTAMP","notNull":false,"unique":false},"current_period_end":{"type":"TIMESTAMP","notNull":false,"unique":false},"trial_ends_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"cancel_at_period_end":{"type":"BOOLEAN","notNull":false,"unique":false,"default":false},"canceled_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"agreed_amount":{"type":"INTEGER","notNull":false,"unique":false},"plan_version_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_subscription_plan_versions","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"plan_version_pinned_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"plan_version_pin_reason":{"type":"TEXT","notNull":false,"unique":false},"plan_version_pin_note":{"type":"TEXT","notNull":false,"unique":false,"default":""},"retains_paid_period":{"type":"BOOLEAN","notNull":false,"unique":false,"default":false},"external_provider":{"type":"TEXT","notNull":false,"unique":false},"stripe_customer_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"stripe_subscription_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"stripe_checkout_session_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metadata":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_tenant_subscriptions_tenant_id_subscriber_kind_idx","columns":["tenant_id","subscriber_kind","subscriber_external_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_tenant_subscriptions_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_tenant_subscriptions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_tenant_subscriptions_plan_id_idx","columns":["plan_id"]},{"name":"_smrt_tenant_subscriptions_plan_version_id_idx","columns":["plan_version_id"]}],"version":"c281741d"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:TenantUsageMetric":{"name":"tenantusagemetric","className":"TenantUsageMetric","qualifiedName":"@happyvertical/smrt-subscriptions:TenantUsageMetric","collection":"tenantusagemetrics","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/TenantUsageMetric.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"subscriberKind":{"type":"text","required":false,"default":"tenant","enum":["tenant","external"]},"subscriberExternalId":{"type":"text","required":false,"default":""},"metricKey":{"type":"text","required":false,"default":""},"quantity":{"type":"decimal","required":false,"default":0},"windowStart":{"type":"datetime","required":false},"windowEnd":{"type":"datetime","required":false},"source":{"type":"text","required":false,"default":""},"sourceId":{"type":"text","required":false,"default":""},"projectId":{"type":"text","required":false,"default":""},"workRefType":{"type":"text","required":false,"default":""},"workRefId":{"type":"text","required":false,"default":""},"provider":{"type":"text","required":false,"default":""},"dimensions":{"type":"text","required":false,"default":"{}"}},"methods":{"getSubscriber":{"name":"getSubscriber","async":false,"parameters":[],"returnType":"Subscriber | null","isStatic":false,"isPublic":true},"getDimensions":{"name":"getDimensions","async":false,"parameters":[],"returnType":"JsonObject","isStatic":false,"isPublic":true},"setDimensions":{"name":"setDimensions","async":false,"parameters":[{"name":"dimensions","type":"JsonObject","optional":false}],"returnType":"void","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_tenant_usage_metrics","api":{"include":["list","get","create"]},"cli":{"include":["list","get","create"]},"mcp":{"include":["list","get"]},"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"TenantUsageMetric","collectionExportName":"TenantUsageMetricCollection","validationRules":[],"schema":{"tableName":"_smrt_tenant_usage_metrics","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_tenant_usage_metrics\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"window_start\\" TIMESTAMP,\\n \\"window_end\\" TIMESTAMP,\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"dimensions\\" TEXT DEFAULT '{}'\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"window_start":{"type":"TIMESTAMP","notNull":false,"unique":false},"window_end":{"type":"TIMESTAMP","notNull":false,"unique":false},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"dimensions":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"}},"indexes":[{"name":"_smrt_tenant_usage_metrics_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_tenant_usage_metrics_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"4884a70d"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PricingRule":{"name":"pricingrule","className":"PricingRule","qualifiedName":"@happyvertical/smrt-subscriptions:PricingRule","collection":"pricingrules","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"ruleKey":{"type":"text","required":false,"default":""},"metricKey":{"type":"text","required":false,"default":""},"serviceKey":{"type":"text","required":false,"default":""},"strategy":{"type":"text","required":false,"default":"fixed_unit","enum":["fixed_unit","cost_plus","multiplier","tiered","included_overage","flat","custom"]},"currency":{"type":"text","required":false,"default":"USD"},"effectiveFrom":{"type":"datetime","required":false},"effectiveTo":{"type":"datetime","required":false},"priority":{"type":"integer","required":false,"default":0},"terms":{"type":"text","required":false,"default":"{}"},"active":{"type":"boolean","required":false,"default":true},"priceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"}},"methods":{"getTerms":{"name":"getTerms","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setTerms":{"name":"setTerms","async":false,"parameters":[{"name":"value","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_pricing_rules","api":true,"cli":true,"mcp":true,"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"PricingRule","collectionExportName":"PricingRuleCollection","validationRules":[],"schema":{"tableName":"_smrt_pricing_rules","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_pricing_rules\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"rule_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"strategy\\" TEXT DEFAULT 'fixed_unit',\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"effective_from\\" TIMESTAMP,\\n \\"effective_to\\" TIMESTAMP,\\n \\"priority\\" INTEGER DEFAULT 0,\\n \\"terms\\" TEXT DEFAULT '{}',\\n \\"active\\" BOOLEAN DEFAULT TRUE,\\n \\"price_book_id\\" UUID\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"rule_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"strategy":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed_unit"},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"effective_from":{"type":"TIMESTAMP","notNull":false,"unique":false},"effective_to":{"type":"TIMESTAMP","notNull":false,"unique":false},"priority":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"terms":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}}},"indexes":[{"name":"_smrt_pricing_rules_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_pricing_rules_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_pricing_rules_price_book_id_idx","columns":["price_book_id"]}],"version":"37fd6ea9"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:ClientCharge":{"name":"clientcharge","className":"ClientCharge","qualifiedName":"@happyvertical/smrt-subscriptions:ClientCharge","collection":"clientcharges","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"usageEventId":{"type":"foreignKey","required":false,"related":"TenantUsageMetric"},"usageTenantId":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:Tenant"},"subscriberKind":{"type":"text","required":false,"default":"tenant"},"subscriberExternalId":{"type":"text","required":false,"default":""},"projectId":{"type":"text","required":false,"default":""},"workRefType":{"type":"text","required":false,"default":""},"workRefId":{"type":"text","required":false,"default":""},"provider":{"type":"text","required":false,"default":"","description":"Who supplied the service that was used.","_meta":{"description":"Who supplied the service that was used."}},"serviceKey":{"type":"text","required":false,"default":"","description":"The service that was used.","_meta":{"description":"The service that was used."}},"metricKey":{"type":"text","required":false,"default":"","description":"What was used, such as messages sent or minutes of audio.","_meta":{"description":"What was used, such as messages sent or minutes of audio."}},"quantity":{"type":"decimal","required":false,"default":0,"description":"How much of it was used.","_meta":{"description":"How much of it was used."}},"amount":{"type":"integer","required":false,"default":0,"description":"What it cost, in cents.","_meta":{"description":"What it cost, in cents."}},"currency":{"type":"text","required":false,"default":"USD","description":"The currency the amount is in, such as USD.","_meta":{"description":"The currency the amount is in, such as USD."}},"pricingRuleId":{"type":"foreignKey","required":false,"related":"PricingRule"},"priceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"},"pricingSnapshot":{"type":"text","required":false,"default":"{}"},"status":{"type":"text","required":false,"default":"draft","description":"Where the charge stands: draft, approved or adjusted.","_meta":{"description":"Where the charge stands: draft, approved or adjusted."},"enum":["draft","approved","adjusted"]},"approvedAt":{"type":"datetime","required":false,"description":"When the charge was approved.","_meta":{"description":"When the charge was approved."}}},"methods":{"getPricingSnapshot":{"name":"getPricingSnapshot","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_client_charges","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"conflictColumns":["usage_event_id"],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"ClientCharge","collectionExportName":"ClientChargeCollection","validationRules":[],"schema":{"tableName":"_smrt_client_charges","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_client_charges\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"usage_event_id\\" UUID,\\n \\"usage_tenant_id\\" UUID,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"pricing_rule_id\\" UUID,\\n \\"price_book_id\\" UUID,\\n \\"pricing_snapshot\\" TEXT DEFAULT '{}',\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"approved_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"usage_event_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_tenant_usage_metrics","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"usage_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"pricing_rule_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_pricing_rules","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_snapshot":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"draft"},"approved_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_client_charges_usage_event_id_idx","columns":["usage_event_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_client_charges_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_client_charges_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_client_charges_usage_tenant_id_idx","columns":["usage_tenant_id"]},{"name":"_smrt_client_charges_pricing_rule_id_idx","columns":["pricing_rule_id"]},{"name":"_smrt_client_charges_price_book_id_idx","columns":["price_book_id"]}],"version":"92fb8003"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:BillingAdjustment":{"name":"billingadjustment","className":"BillingAdjustment","qualifiedName":"@happyvertical/smrt-subscriptions:BillingAdjustment","collection":"billingadjustments","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"clientChargeId":{"type":"foreignKey","required":false,"related":"ClientCharge"},"amount":{"type":"integer","required":false,"default":0},"currency":{"type":"text","required":false,"default":"USD"},"reason":{"type":"text","required":false,"default":""},"source":{"type":"text","required":false,"default":""},"sourceId":{"type":"text","required":false,"default":""},"createdBy":{"type":"text","required":false,"default":""}},"methods":{},"decoratorConfig":{"tableName":"_smrt_billing_adjustments","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"BillingAdjustment","collectionExportName":"BillingAdjustmentCollection","validationRules":[],"schema":{"tableName":"_smrt_billing_adjustments","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_billing_adjustments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"client_charge_id\\" UUID,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"created_by\\" TEXT DEFAULT ''\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"client_charge_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_client_charges","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"created_by":{"type":"TEXT","notNull":false,"unique":false,"default":""}},"indexes":[{"name":"_smrt_billing_adjustments_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_billing_adjustments_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_billing_adjustments_client_charge_id_idx","columns":["client_charge_id"]}],"version":"cfbd2832"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SpendingPolicy":{"name":"spendingpolicy","className":"SpendingPolicy","qualifiedName":"@happyvertical/smrt-subscriptions:SpendingPolicy","collection":"spendingpolicies","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"name":{"type":"text","required":false,"default":""},"subscriberKind":{"type":"text","required":false,"default":""},"subscriberExternalId":{"type":"text","required":false,"default":""},"projectId":{"type":"text","required":false,"default":""},"serviceKey":{"type":"text","required":false,"default":""},"metricKey":{"type":"text","required":false,"default":""},"period":{"type":"text","required":false,"default":"month","enum":["day","week","month","year","rolling","balance"]},"rollingSeconds":{"type":"integer","required":false,"default":0},"limitAmount":{"type":"integer","required":false,"default":0},"currency":{"type":"text","required":false,"default":"USD"},"behavior":{"type":"text","required":false,"default":"observe","enum":["observe","warn","block","approval_required"]},"priority":{"type":"integer","required":false,"default":0},"active":{"type":"boolean","required":false,"default":true},"basis":{"type":"text","required":false,"default":"billed","enum":["billed","retail","wholesale"]},"setByTenantId":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:Tenant"},"balanceFrom":{"type":"datetime","required":false}},"methods":{},"decoratorConfig":{"tableName":"_smrt_spending_policies","conflictColumns":["tenant_id","subscriber_kind","subscriber_external_id","project_id","service_key","metric_key","period","name"],"api":true,"cli":true,"mcp":true,"hooks":{"beforeDelete":"assertDelegationAuthority"},"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"SpendingPolicy","collectionExportName":"SpendingPolicyCollection","displayLabelField":"name","validationRules":[],"schema":{"tableName":"_smrt_spending_policies","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_spending_policies\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"name\\" TEXT DEFAULT '',\\n \\"subscriber_kind\\" TEXT DEFAULT '',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"period\\" TEXT DEFAULT 'month',\\n \\"rolling_seconds\\" INTEGER DEFAULT 0,\\n \\"limit_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"behavior\\" TEXT DEFAULT 'observe',\\n \\"priority\\" INTEGER DEFAULT 0,\\n \\"active\\" BOOLEAN DEFAULT TRUE,\\n \\"basis\\" TEXT DEFAULT 'billed',\\n \\"set_by_tenant_id\\" UUID,\\n \\"balance_from\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":""},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"period":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"rolling_seconds":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"limit_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"behavior":{"type":"TEXT","notNull":false,"unique":false,"default":"observe"},"priority":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"basis":{"type":"TEXT","notNull":false,"unique":false,"default":"billed"},"set_by_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"balance_from":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_spending_policies_tenant_id_subscriber_kind_idx","columns":["tenant_id","subscriber_kind","subscriber_external_id","project_id","service_key","metric_key","period","name"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_spending_policies_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_spending_policies_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_spending_policies_set_by_tenant_id_idx","columns":["set_by_tenant_id"]}],"version":"21fbbb20"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PricingRuleCollection":{"name":"pricingrulecollection","className":"PricingRuleCollection","qualifiedName":"@happyvertical/smrt-subscriptions:PricingRuleCollection","collection":"pricingrules","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_pricing_rules"},"extends":"SmrtCollection","extendsTypeArg":"PricingRule","exportName":"PricingRuleCollection","collectionExportName":"PricingRuleCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:PricingRule","schema":{"tableName":"_smrt_pricing_rules","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_pricing_rules\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"rule_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"strategy\\" TEXT DEFAULT 'fixed_unit',\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"effective_from\\" TIMESTAMP,\\n \\"effective_to\\" TIMESTAMP,\\n \\"priority\\" INTEGER DEFAULT 0,\\n \\"terms\\" TEXT DEFAULT '{}',\\n \\"active\\" BOOLEAN DEFAULT TRUE,\\n \\"price_book_id\\" UUID\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"rule_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"strategy":{"type":"TEXT","notNull":false,"unique":false,"default":"fixed_unit"},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"effective_from":{"type":"TIMESTAMP","notNull":false,"unique":false},"effective_to":{"type":"TIMESTAMP","notNull":false,"unique":false},"priority":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"terms":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}}},"indexes":[{"name":"_smrt_pricing_rules_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_pricing_rules_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_pricing_rules_price_book_id_idx","columns":["price_book_id"]}],"version":"37fd6ea9"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:ClientChargeCollection":{"name":"clientchargecollection","className":"ClientChargeCollection","qualifiedName":"@happyvertical/smrt-subscriptions:ClientChargeCollection","collection":"clientcharges","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_client_charges","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"ClientCharge","exportName":"ClientChargeCollection","collectionExportName":"ClientChargeCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:ClientCharge","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_client_charges","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_client_charges\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"usage_event_id\\" UUID,\\n \\"usage_tenant_id\\" UUID,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"pricing_rule_id\\" UUID,\\n \\"price_book_id\\" UUID,\\n \\"pricing_snapshot\\" TEXT DEFAULT '{}',\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"approved_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"usage_event_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_tenant_usage_metrics","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"usage_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"pricing_rule_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_pricing_rules","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_snapshot":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"draft"},"approved_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_client_charges_usage_event_id_idx","columns":["usage_event_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_client_charges_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_client_charges_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_client_charges_usage_tenant_id_idx","columns":["usage_tenant_id"]},{"name":"_smrt_client_charges_pricing_rule_id_idx","columns":["pricing_rule_id"]},{"name":"_smrt_client_charges_price_book_id_idx","columns":["price_book_id"]}],"version":"92fb8003"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:BillingAdjustmentCollection":{"name":"billingadjustmentcollection","className":"BillingAdjustmentCollection","qualifiedName":"@happyvertical/smrt-subscriptions:BillingAdjustmentCollection","collection":"billingadjustments","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_billing_adjustments","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"BillingAdjustment","exportName":"BillingAdjustmentCollection","collectionExportName":"BillingAdjustmentCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:BillingAdjustment","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_billing_adjustments","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_billing_adjustments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"client_charge_id\\" UUID,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"created_by\\" TEXT DEFAULT ''\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"client_charge_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_client_charges","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"created_by":{"type":"TEXT","notNull":false,"unique":false,"default":""}},"indexes":[{"name":"_smrt_billing_adjustments_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_billing_adjustments_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_billing_adjustments_client_charge_id_idx","columns":["client_charge_id"]}],"version":"cfbd2832"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:SpendingPolicyCollection":{"name":"spendingpolicycollection","className":"SpendingPolicyCollection","qualifiedName":"@happyvertical/smrt-subscriptions:SpendingPolicyCollection","collection":"spendingpolicies","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/commercial.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_spending_policies"},"extends":"SmrtCollection","extendsTypeArg":"SpendingPolicy","exportName":"SpendingPolicyCollection","collectionExportName":"SpendingPolicyCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:SpendingPolicy","schema":{"tableName":"_smrt_spending_policies","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_spending_policies\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"name\\" TEXT DEFAULT '',\\n \\"subscriber_kind\\" TEXT DEFAULT '',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"period\\" TEXT DEFAULT 'month',\\n \\"rolling_seconds\\" INTEGER DEFAULT 0,\\n \\"limit_amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"behavior\\" TEXT DEFAULT 'observe',\\n \\"priority\\" INTEGER DEFAULT 0,\\n \\"active\\" BOOLEAN DEFAULT TRUE,\\n \\"basis\\" TEXT DEFAULT 'billed',\\n \\"set_by_tenant_id\\" UUID,\\n \\"balance_from\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":""},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"period":{"type":"TEXT","notNull":false,"unique":false,"default":"month"},"rolling_seconds":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"limit_amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"behavior":{"type":"TEXT","notNull":false,"unique":false,"default":"observe"},"priority":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"basis":{"type":"TEXT","notNull":false,"unique":false,"default":"billed"},"set_by_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"balance_from":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_spending_policies_tenant_id_subscriber_kind_idx","columns":["tenant_id","subscriber_kind","subscriber_external_id","project_id","service_key","metric_key","period","name"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_spending_policies_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_spending_policies_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_spending_policies_set_by_tenant_id_idx","columns":["set_by_tenant_id"]}],"version":"21fbbb20"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PriceBook":{"name":"pricebook","className":"PriceBook","qualifiedName":"@happyvertical/smrt-subscriptions:PriceBook","collection":"pricebooks","description":"A named set of prices published by one seller tenant. Its prices are ordinary PricingRule rows that carry this book's id and the same tenant; one rule per currency gives a price in several currencies.","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"bookKey":{"type":"text","required":false,"default":""},"name":{"type":"text","required":false,"default":""},"kind":{"type":"text","required":false,"default":"retail","enum":["wholesale","retail"]},"active":{"type":"boolean","required":false,"default":true}},"methods":{},"decoratorConfig":{"tableName":"_smrt_price_books","conflictColumns":["tenant_id","book_key"],"api":false,"cli":false,"mcp":false,"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"PriceBook","collectionExportName":"PriceBookCollection","displayLabelField":"name","validationRules":[],"schema":{"tableName":"_smrt_price_books","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_price_books\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"book_key\\" TEXT DEFAULT '',\\n \\"name\\" TEXT DEFAULT '',\\n \\"kind\\" TEXT DEFAULT 'retail',\\n \\"active\\" BOOLEAN DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"book_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"kind":{"type":"TEXT","notNull":false,"unique":false,"default":"retail"},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true}},"indexes":[{"name":"_smrt_price_books_tenant_id_book_key_idx","columns":["tenant_id","book_key"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_price_books_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_price_books_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"56296d2f"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PriceBookAssignment":{"name":"pricebookassignment","className":"PriceBookAssignment","qualifiedName":"@happyvertical/smrt-subscriptions:PriceBookAssignment","collection":"pricebookassignments","description":"Which price books rate one child tenant's usage, keyed like the tenancy billing relationship it belongs to (one row per child).","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"childTenantId":{"type":"crossPackageRef","required":true,"related":"@happyvertical/smrt-users:Tenant","_meta":{"required":true}},"resellerTenantId":{"type":"crossPackageRef","required":true,"related":"@happyvertical/smrt-users:Tenant","_meta":{"required":true}},"wholesalePriceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"},"wholesaleCurrency":{"type":"text","required":false,"default":""},"retailPriceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"},"retailCurrency":{"type":"text","required":false,"default":""}},"methods":{},"decoratorConfig":{"tableName":"_smrt_price_book_assignments","conflictColumns":["child_tenant_id"],"api":false,"cli":false,"mcp":false},"extends":"SmrtObject","exportName":"PriceBookAssignment","collectionExportName":"PriceBookAssignmentCollection","validationRules":[{"field":"childTenantId","rule":"required","fieldType":"crossPackageRef"},{"field":"resellerTenantId","rule":"required","fieldType":"crossPackageRef"}],"schema":{"tableName":"_smrt_price_book_assignments","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_price_book_assignments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"child_tenant_id\\" UUID NOT NULL,\\n \\"reseller_tenant_id\\" UUID NOT NULL,\\n \\"wholesale_price_book_id\\" UUID,\\n \\"wholesale_currency\\" TEXT DEFAULT '',\\n \\"retail_price_book_id\\" UUID,\\n \\"retail_currency\\" TEXT DEFAULT ''\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"child_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"reseller_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"wholesale_price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"wholesale_currency":{"type":"TEXT","notNull":false,"unique":false,"default":""},"retail_price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"retail_currency":{"type":"TEXT","notNull":false,"unique":false,"default":""}},"indexes":[{"name":"_smrt_price_book_assignments_child_tenant_id_idx","columns":["child_tenant_id"],"unique":true},{"name":"_smrt_price_book_assignments_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_price_book_assignments_created_at_idx","columns":["created_at"]},{"name":"_smrt_price_book_assignments_reseller_tenant_id_idx","columns":["reseller_tenant_id"]},{"name":"_smrt_price_book_assignments_wholesale_price_book_id_idx","columns":["wholesale_price_book_id"]},{"name":"_smrt_price_book_assignments_retail_price_book_id_idx","columns":["retail_price_book_id"]}],"version":"990da9b7"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:RetailCharge":{"name":"retailcharge","className":"RetailCharge","qualifiedName":"@happyvertical/smrt-subscriptions:RetailCharge","collection":"retailcharges","description":"What a reseller charges one child for one usage event, priced from the reseller's retail book.","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"resellerTenantId":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:Tenant"},"usageEventId":{"type":"foreignKey","required":false,"related":"TenantUsageMetric"},"clientChargeId":{"type":"foreignKey","required":false,"related":"ClientCharge"},"subscriberKind":{"type":"text","required":false,"default":"tenant"},"subscriberExternalId":{"type":"text","required":false,"default":""},"projectId":{"type":"text","required":false,"default":""},"workRefType":{"type":"text","required":false,"default":""},"workRefId":{"type":"text","required":false,"default":""},"provider":{"type":"text","required":false,"default":""},"serviceKey":{"type":"text","required":false,"default":""},"metricKey":{"type":"text","required":false,"default":""},"quantity":{"type":"decimal","required":false,"default":0},"amount":{"type":"integer","required":false,"default":0},"currency":{"type":"text","required":false,"default":"USD"},"priceBookId":{"type":"foreignKey","required":false,"related":"PriceBook"},"pricingRuleId":{"type":"foreignKey","required":false,"related":"PricingRule"},"pricingSnapshot":{"type":"text","required":false,"default":"{}"},"status":{"type":"text","required":false,"default":"draft","enum":["draft","approved"]},"approvedAt":{"type":"datetime","required":false}},"methods":{"getPricingSnapshot":{"name":"getPricingSnapshot","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_retail_charges","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"conflictColumns":["usage_event_id"],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"RetailCharge","collectionExportName":"RetailChargeCollection","validationRules":[],"schema":{"tableName":"_smrt_retail_charges","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_retail_charges\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"reseller_tenant_id\\" UUID,\\n \\"usage_event_id\\" UUID,\\n \\"client_charge_id\\" UUID,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"price_book_id\\" UUID,\\n \\"pricing_rule_id\\" UUID,\\n \\"pricing_snapshot\\" TEXT DEFAULT '{}',\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"approved_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"reseller_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"usage_event_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_tenant_usage_metrics","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"client_charge_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_client_charges","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_rule_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_pricing_rules","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_snapshot":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"draft"},"approved_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_retail_charges_usage_event_id_idx","columns":["usage_event_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_retail_charges_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_retail_charges_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_retail_charges_reseller_tenant_id_idx","columns":["reseller_tenant_id"]},{"name":"_smrt_retail_charges_client_charge_id_idx","columns":["client_charge_id"]},{"name":"_smrt_retail_charges_price_book_id_idx","columns":["price_book_id"]},{"name":"_smrt_retail_charges_pricing_rule_id_idx","columns":["pricing_rule_id"]}],"version":"ad6930a8"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:CreditGrant":{"name":"creditgrant","className":"CreditGrant","qualifiedName":"@happyvertical/smrt-subscriptions:CreditGrant","collection":"creditgrants","description":"An append-only credit on a prepaid (period: 'balance') spending policy. Positive amounts add credit; a negative amount reverses an earlier grant.","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"spendingPolicyId":{"type":"foreignKey","required":false,"related":"SpendingPolicy"},"amount":{"type":"integer","required":false,"default":0},"currency":{"type":"text","required":false,"default":"USD"},"reason":{"type":"text","required":false,"default":""},"source":{"type":"text","required":false,"default":""},"sourceId":{"type":"text","required":false,"default":""},"grantedByTenantId":{"type":"crossPackageRef","required":false,"related":"@happyvertical/smrt-users:Tenant"}},"methods":{},"decoratorConfig":{"tableName":"_smrt_credit_grants","api":{"include":["list","get"]},"cli":{"include":["list","get"]},"mcp":{"include":["list","get"]},"hooks":{"beforeDelete":"refuseDelete"},"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"CreditGrant","collectionExportName":"CreditGrantCollection","validationRules":[],"schema":{"tableName":"_smrt_credit_grants","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_credit_grants\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"spending_policy_id\\" UUID,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"granted_by_tenant_id\\" UUID\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"spending_policy_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_spending_policies","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"granted_by_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_credit_grants_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_credit_grants_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_credit_grants_spending_policy_id_idx","columns":["spending_policy_id"]},{"name":"_smrt_credit_grants_granted_by_tenant_id_idx","columns":["granted_by_tenant_id"]}],"version":"e11305fc"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PriceBookCollection":{"name":"pricebookcollection","className":"PriceBookCollection","qualifiedName":"@happyvertical/smrt-subscriptions:PriceBookCollection","collection":"pricebooks","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_price_books","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"PriceBook","exportName":"PriceBookCollection","collectionExportName":"PriceBookCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:PriceBook","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_price_books","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_price_books\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"book_key\\" TEXT DEFAULT '',\\n \\"name\\" TEXT DEFAULT '',\\n \\"kind\\" TEXT DEFAULT 'retail',\\n \\"active\\" BOOLEAN DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"book_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"name":{"type":"TEXT","notNull":false,"unique":false,"default":""},"kind":{"type":"TEXT","notNull":false,"unique":false,"default":"retail"},"active":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true}},"indexes":[{"name":"_smrt_price_books_tenant_id_book_key_idx","columns":["tenant_id","book_key"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_price_books_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_price_books_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"56296d2f"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:PriceBookAssignmentCollection":{"name":"pricebookassignmentcollection","className":"PriceBookAssignmentCollection","qualifiedName":"@happyvertical/smrt-subscriptions:PriceBookAssignmentCollection","collection":"pricebookassignments","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_price_book_assignments","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"PriceBookAssignment","exportName":"PriceBookAssignmentCollection","collectionExportName":"PriceBookAssignmentCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:PriceBookAssignment","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_price_book_assignments","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_price_book_assignments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"child_tenant_id\\" UUID NOT NULL,\\n \\"reseller_tenant_id\\" UUID NOT NULL,\\n \\"wholesale_price_book_id\\" UUID,\\n \\"wholesale_currency\\" TEXT DEFAULT '',\\n \\"retail_price_book_id\\" UUID,\\n \\"retail_currency\\" TEXT DEFAULT ''\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"child_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"reseller_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"wholesale_price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"wholesale_currency":{"type":"TEXT","notNull":false,"unique":false,"default":""},"retail_price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"retail_currency":{"type":"TEXT","notNull":false,"unique":false,"default":""}},"indexes":[{"name":"_smrt_price_book_assignments_child_tenant_id_idx","columns":["child_tenant_id"],"unique":true},{"name":"_smrt_price_book_assignments_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_price_book_assignments_created_at_idx","columns":["created_at"]},{"name":"_smrt_price_book_assignments_reseller_tenant_id_idx","columns":["reseller_tenant_id"]},{"name":"_smrt_price_book_assignments_wholesale_price_book_id_idx","columns":["wholesale_price_book_id"]},{"name":"_smrt_price_book_assignments_retail_price_book_id_idx","columns":["retail_price_book_id"]}],"version":"990da9b7"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:RetailChargeCollection":{"name":"retailchargecollection","className":"RetailChargeCollection","qualifiedName":"@happyvertical/smrt-subscriptions:RetailChargeCollection","collection":"retailcharges","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_retail_charges","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"RetailCharge","exportName":"RetailChargeCollection","collectionExportName":"RetailChargeCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:RetailCharge","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_retail_charges","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_retail_charges\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"reseller_tenant_id\\" UUID,\\n \\"usage_event_id\\" UUID,\\n \\"client_charge_id\\" UUID,\\n \\"subscriber_kind\\" TEXT DEFAULT 'tenant',\\n \\"subscriber_external_id\\" TEXT DEFAULT '',\\n \\"project_id\\" TEXT DEFAULT '',\\n \\"work_ref_type\\" TEXT DEFAULT '',\\n \\"work_ref_id\\" TEXT DEFAULT '',\\n \\"provider\\" TEXT DEFAULT '',\\n \\"service_key\\" TEXT DEFAULT '',\\n \\"metric_key\\" TEXT DEFAULT '',\\n \\"quantity\\" REAL DEFAULT 0,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"price_book_id\\" UUID,\\n \\"pricing_rule_id\\" UUID,\\n \\"pricing_snapshot\\" TEXT DEFAULT '{}',\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"approved_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"reseller_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"usage_event_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_tenant_usage_metrics","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"client_charge_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_client_charges","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"subscriber_kind":{"type":"TEXT","notNull":false,"unique":false,"default":"tenant"},"subscriber_external_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"project_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_type":{"type":"TEXT","notNull":false,"unique":false,"default":""},"work_ref_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"provider":{"type":"TEXT","notNull":false,"unique":false,"default":""},"service_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"metric_key":{"type":"TEXT","notNull":false,"unique":false,"default":""},"quantity":{"type":"REAL","notNull":false,"unique":false,"default":0},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"price_book_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_price_books","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_rule_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_pricing_rules","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"pricing_snapshot":{"type":"TEXT","notNull":false,"unique":false,"default":"{}"},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"draft"},"approved_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_retail_charges_usage_event_id_idx","columns":["usage_event_id"],"unique":true,"nullsNotDistinct":true},{"name":"_smrt_retail_charges_slug_context_idx","columns":["slug","context"]},{"name":"_smrt_retail_charges_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_retail_charges_reseller_tenant_id_idx","columns":["reseller_tenant_id"]},{"name":"_smrt_retail_charges_client_charge_id_idx","columns":["client_charge_id"]},{"name":"_smrt_retail_charges_price_book_id_idx","columns":["price_book_id"]},{"name":"_smrt_retail_charges_pricing_rule_id_idx","columns":["pricing_rule_id"]}],"version":"ad6930a8"},"importPath":"@happyvertical/smrt-subscriptions"},"@happyvertical/smrt-subscriptions:CreditGrantCollection":{"name":"creditgrantcollection","className":"CreditGrantCollection","qualifiedName":"@happyvertical/smrt-subscriptions:CreditGrantCollection","collection":"creditgrants","filePath":"/home/runner/work/smrt/smrt/packages/subscriptions/src/models/reseller.ts","packageName":"@happyvertical/smrt-subscriptions","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_credit_grants","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"CreditGrant","exportName":"CreditGrantCollection","collectionExportName":"CreditGrantCollectionCollection","collectionOf":"@happyvertical/smrt-subscriptions:CreditGrant","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_credit_grants","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_credit_grants\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"spending_policy_id\\" UUID,\\n \\"amount\\" INTEGER DEFAULT 0,\\n \\"currency\\" TEXT DEFAULT 'USD',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"source\\" TEXT DEFAULT '',\\n \\"source_id\\" TEXT DEFAULT '',\\n \\"granted_by_tenant_id\\" UUID\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"spending_policy_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_spending_policies","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"amount":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"currency":{"type":"TEXT","notNull":false,"unique":false,"default":"USD"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source":{"type":"TEXT","notNull":false,"unique":false,"default":""},"source_id":{"type":"TEXT","notNull":false,"unique":false,"default":""},"granted_by_tenant_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_credit_grants_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_credit_grants_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_credit_grants_spending_policy_id_idx","columns":["spending_policy_id"]},{"name":"_smrt_credit_grants_granted_by_tenant_id_idx","columns":["granted_by_tenant_id"]}],"version":"e11305fc"},"importPath":"@happyvertical/smrt-subscriptions"}},"moduleType":"smrt","recipes":[{"id":"subscriptions.plans","className":"SubscriptionPlansRecipe","label":"Subscriptions","summary":"Sell plans that renew, see who is subscribed to which, and what their usage cost.","synonyms":["subscriptions","subscription plans","plans","memberships","recurring billing","pricing tiers"],"models":["@happyvertical/smrt-subscriptions:SubscriptionPlan","@happyvertical/smrt-subscriptions:SubscriptionPlanVersion","@happyvertical/smrt-subscriptions:TenantSubscription","@happyvertical/smrt-subscriptions:ClientCharge"],"nav":[{"label":"Plans","model":"@happyvertical/smrt-subscriptions:SubscriptionPlan","icon":"tag","description":"The plans you sell, with their price and how often they bill.","noun":"plan"},{"label":"Subscriptions","model":"@happyvertical/smrt-subscriptions:TenantSubscription","icon":"repeat","description":"Who is subscribed to which plan, and where each one stands.","noun":"subscription"},{"label":"Plan versions","model":"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion","icon":"fileText","description":"Every set of terms a plan has had, and from when each applied.","noun":"plan version"},{"label":"Charges","model":"@happyvertical/smrt-subscriptions:ClientCharge","icon":"receipt","description":"What each subscriber used and what it cost them.","noun":"charge"}],"requires":[],"section":{"id":"sales","label":"Sales","icon":"shoppingBag","description":"Customers, orders and quotes: everything you sell."},"options":{"@happyvertical/smrt-subscriptions:SubscriptionPlan":{"fields":{"name":{"order":1},"planKey":{"label":"Plan code","order":2},"description":{"order":3},"status":{"order":4},"priceAmount":{"label":"Price (in cents)","order":5},"currency":{"order":6},"billingInterval":{"label":"Billed every","order":7},"pricingMode":{"label":"How it is priced","order":8},"minimumAmount":{"label":"Minimum (in cents)","visibility":"advanced"},"suggestedAmount":{"label":"Suggested (in cents)","visibility":"advanced"},"sortOrder":{"label":"Position in list","visibility":"advanced"},"tenantId":{"visibility":"hidden"},"features":{"visibility":"hidden"},"thresholds":{"visibility":"hidden"},"externalProvider":{"visibility":"hidden"},"providerProductId":{"visibility":"hidden"},"providerPriceId":{"visibility":"hidden"},"stripeProductId":{"visibility":"hidden"},"stripePriceId":{"visibility":"hidden"},"metadata":{"visibility":"hidden"}}},"@happyvertical/smrt-subscriptions:SubscriptionPlanVersion":{"fields":{"planId":{"label":"Plan","order":1},"version":{"label":"Version number","order":2},"effectiveFrom":{"label":"In force from","order":3},"name":{"order":4},"status":{"order":5},"priceAmount":{"label":"Price (in cents)","order":6},"currency":{"order":7},"billingInterval":{"label":"Billed every","order":8},"planKey":{"label":"Plan code","visibility":"advanced"},"pricingMode":{"label":"How it is priced","visibility":"advanced"},"minimumAmount":{"label":"Minimum (in cents)","visibility":"advanced"},"suggestedAmount":{"label":"Suggested (in cents)","visibility":"advanced"},"tenantId":{"visibility":"hidden"},"features":{"visibility":"hidden"},"thresholds":{"visibility":"hidden"}}},"@happyvertical/smrt-subscriptions:TenantSubscription":{"fields":{"planId":{"label":"Plan","order":1},"status":{"order":2},"startedAt":{"label":"Started on","order":3},"currentPeriodStart":{"label":"Current period starts","order":4},"currentPeriodEnd":{"label":"Current period ends","order":5},"trialEndsAt":{"label":"Trial ends","order":6},"cancelAtPeriodEnd":{"label":"Cancel at end of period","order":7},"canceledAt":{"label":"Cancelled on","visibility":"advanced"},"agreedAmount":{"label":"Agreed amount (in cents)","visibility":"advanced"},"subscriberKind":{"label":"Subscriber type","visibility":"advanced"},"subscriberExternalId":{"label":"Outside subscriber","visibility":"advanced"},"planVersionId":{"label":"Plan version","visibility":"advanced","locked":true},"tenantId":{"visibility":"hidden"},"planVersionPinnedAt":{"visibility":"hidden"},"planVersionPinReason":{"visibility":"hidden"},"planVersionPinNote":{"visibility":"hidden"},"retainsPaidPeriod":{"visibility":"hidden"},"externalProvider":{"visibility":"hidden"},"stripeCustomerId":{"visibility":"hidden"},"stripeSubscriptionId":{"visibility":"hidden"},"stripeCheckoutSessionId":{"visibility":"hidden"},"metadata":{"visibility":"hidden"}}},"@happyvertical/smrt-subscriptions:ClientCharge":{"fields":{"metricKey":{"label":"What was used","order":1},"quantity":{"label":"How much","order":2},"amount":{"label":"Amount (in cents)","order":3},"currency":{"order":4},"status":{"order":5},"approvedAt":{"label":"Approved on","order":6},"serviceKey":{"label":"Service","visibility":"advanced"},"provider":{"visibility":"advanced"},"tenantId":{"visibility":"hidden"},"usageEventId":{"visibility":"hidden"},"usageTenantId":{"visibility":"hidden"},"subscriberKind":{"visibility":"hidden"},"subscriberExternalId":{"visibility":"hidden"},"projectId":{"visibility":"hidden"},"workRefType":{"visibility":"hidden"},"workRefId":{"visibility":"hidden"},"pricingRuleId":{"visibility":"hidden"},"priceBookId":{"visibility":"hidden"},"pricingSnapshot":{"visibility":"hidden"}}}},"help":{"markdown":"## Overview\\n\\nSubscriptions is where you sell plans that renew. A plan says what it costs,\\nhow often it bills and whether it is free, a fixed price or pay what you can.\\nA subscription joins a subscriber to a plan and shows where it stands, from\\ntrial to active to cancelled. Every time you change a plan's terms, the\\nearlier terms are kept as a plan version, so a subscriber who already paid for\\na period keeps what they paid for until it renews. Charges show what each\\nsubscriber used and what it cost them.\\n\\nAll amounts are whole numbers of cents, with no decimal point.\\n\\n## Tasks\\n\\n### Set up a plan\\n\\n1. Open the plans and choose **New**.\\n2. Type the **{field:SubscriptionPlan.name}** customers will see and a short **{field:SubscriptionPlan.planKey}** such as \\"starter\\".\\n3. Choose **{field:SubscriptionPlan.pricingMode}**: free, a fixed price, or pay what you can. This cannot change once the plan is saved; make a new plan instead.\\n4. For a fixed price, enter the **{field:SubscriptionPlan.priceAmount}** in cents and the **{field:SubscriptionPlan.currency}**.\\n5. Set how often it bills in **{field:SubscriptionPlan.billingInterval}**.\\n6. Set the **{field:SubscriptionPlan.status}** to active when it is ready to sell.\\n7. Save.\\n\\n### Change a plan's price or terms\\n\\n1. Open the plan and edit the **{field:SubscriptionPlan.priceAmount}**, **{field:SubscriptionPlan.billingInterval}** or **{field:SubscriptionPlan.status}**.\\n2. Save. The new terms apply to new subscribers and to existing ones from their next renewal; a period already paid for keeps its old terms.\\n\\n### Retire a plan\\n\\n1. Open the plan and set its **{field:SubscriptionPlan.status}** to archived.\\n2. Save. No one new can subscribe to it; existing subscribers keep going until they cancel.\\n\\n### Subscribe someone to a plan\\n\\n1. Open the subscriptions and choose **New**.\\n2. Pick the **{field:TenantSubscription.planId}**.\\n3. Enter the day it **{field:TenantSubscription.startedAt}** and, if there is a free trial, when the **{field:TenantSubscription.trialEndsAt}**.\\n4. Save. The **{field:TenantSubscription.status}** shows where the subscription stands once it has been paid for.\\n\\n### See where a subscription stands\\n\\n1. Open the subscriptions and find the one you want.\\n2. The **{field:TenantSubscription.status}** shows whether it is still incomplete, on trial, active, past due, unpaid or cancelled.\\n3. **{field:TenantSubscription.currentPeriodStart}** and **{field:TenantSubscription.currentPeriodEnd}** show the period that has been paid for.\\n\\n### Cancel a subscription\\n\\n1. Open the subscription.\\n2. Tick **{field:TenantSubscription.cancelAtPeriodEnd}** so it runs out when the current period ends instead of renewing.\\n3. Save.\\n\\n### Look up the terms a subscriber was sold\\n\\nPlan versions are written automatically whenever a plan is saved with changed\\nterms; you cannot add or edit them here.\\n\\n1. Open the plan versions and find the **{field:SubscriptionPlanVersion.planId}** you are interested in.\\n2. Each row shows the **{field:SubscriptionPlanVersion.version}** and the date it was **{field:SubscriptionPlanVersion.effectiveFrom}**.\\n3. Read the **{field:SubscriptionPlanVersion.priceAmount}**, **{field:SubscriptionPlanVersion.currency}** and **{field:SubscriptionPlanVersion.billingInterval}** that applied under it.\\n\\n### See what a subscriber was charged\\n\\nCharges are created by the usage and billing service as usage is recorded;\\nyou cannot add or edit them here.\\n\\n1. Open the charges.\\n2. Each row shows **{field:ClientCharge.metricKey}**, **{field:ClientCharge.quantity}** and the **{field:ClientCharge.amount}** in cents.\\n3. The **{field:ClientCharge.status}** shows whether the charge is still a draft, approved or adjusted.\\n","fieldRefs":["ClientCharge.amount","ClientCharge.metricKey","ClientCharge.quantity","ClientCharge.status","SubscriptionPlan.billingInterval","SubscriptionPlan.currency","SubscriptionPlan.name","SubscriptionPlan.planKey","SubscriptionPlan.priceAmount","SubscriptionPlan.pricingMode","SubscriptionPlan.status","SubscriptionPlanVersion.billingInterval","SubscriptionPlanVersion.currency","SubscriptionPlanVersion.effectiveFrom","SubscriptionPlanVersion.planId","SubscriptionPlanVersion.priceAmount","SubscriptionPlanVersion.version","TenantSubscription.cancelAtPeriodEnd","TenantSubscription.currentPeriodEnd","TenantSubscription.currentPeriodStart","TenantSubscription.planId","TenantSubscription.startedAt","TenantSubscription.status","TenantSubscription.trialEndsAt"]},"demo":{"mode":"server","reasons":["Needs a server because its package does not build for a browser: core migrations (node:crypto, node:os); and its package depends on @happyvertical/smrt-tenancy, which do not build for a browser (#3624, #3626)."]}}],"smrtDependencies":["@happyvertical/smrt-core","@happyvertical/smrt-features","@happyvertical/smrt-tenancy"],"browser":{"status":"server-only","issues":["#3624","#3626"],"reason":"core migrations (node:crypto, node:os)","via":["@happyvertical/smrt-tenancy"]},"stampsConstructors":true}`));
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/models/TenantSubscription.ts
|
|
13
13
|
var __defProp$3 = Object.defineProperty;
|
|
@@ -607,6 +607,7 @@ var TenantUsageMetricCollection = class extends SmrtCollection {
|
|
|
607
607
|
COUNT(*) AS request_count
|
|
608
608
|
FROM _smrt_ai_usage
|
|
609
609
|
WHERE tenant_id = ?
|
|
610
|
+
AND operation <> 'blocked'
|
|
610
611
|
AND NOT (operation = 'external-agent' AND id LIKE 'external-agent:%')
|
|
611
612
|
AND created_at >= ?
|
|
612
613
|
AND created_at < ?`, options.tenantId, options.window.start.toISOString(), options.window.end.toISOString()));
|
|
@@ -2389,403 +2390,117 @@ function policyWindow(policy, at) {
|
|
|
2389
2390
|
return [start, end];
|
|
2390
2391
|
}
|
|
2391
2392
|
//#endregion
|
|
2392
|
-
//#region src/services/
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2393
|
+
//#region src/services/threshold-evaluator.ts
|
|
2394
|
+
function evaluateThreshold(threshold, usage) {
|
|
2395
|
+
const ratio = threshold.limit === 0 ? usage.quantity > 0 ? Infinity : 0 : usage.quantity / threshold.limit;
|
|
2396
|
+
const warningRatio = threshold.warningRatio ?? .8;
|
|
2397
|
+
const blocked = threshold.enforcement === "block" && (threshold.limit === 0 ? usage.quantity > 0 : usage.quantity >= threshold.limit);
|
|
2398
|
+
return {
|
|
2399
|
+
threshold,
|
|
2400
|
+
usage,
|
|
2401
|
+
ratio,
|
|
2402
|
+
state: blocked ? "blocked" : !blocked && ratio >= warningRatio ? "warn" : "ok",
|
|
2403
|
+
allowed: !blocked,
|
|
2404
|
+
remaining: Math.max(0, threshold.limit - usage.quantity)
|
|
2405
|
+
};
|
|
2400
2406
|
}
|
|
2401
|
-
function
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
}
|
|
2407
|
+
function evaluateThresholds(thresholds, usage) {
|
|
2408
|
+
const usageByMetric = new Map(usage.map((summary) => [summary.metricKey, summary]));
|
|
2409
|
+
return thresholds.map((threshold) => {
|
|
2410
|
+
return evaluateThreshold(threshold, usageByMetric.get(threshold.metricKey) ?? emptyUsageSummary$2(threshold.metricKey));
|
|
2411
|
+
});
|
|
2406
2412
|
}
|
|
2407
|
-
function
|
|
2413
|
+
function emptyUsageSummary$2(metricKey) {
|
|
2414
|
+
const now = /* @__PURE__ */ new Date();
|
|
2408
2415
|
return {
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2416
|
+
tenantId: "",
|
|
2417
|
+
metricKey,
|
|
2418
|
+
quantity: 0,
|
|
2419
|
+
windowStart: now,
|
|
2420
|
+
windowEnd: now
|
|
2413
2421
|
};
|
|
2414
2422
|
}
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
this.
|
|
2421
|
-
this.books = books;
|
|
2422
|
-
this.assignments = assignments;
|
|
2423
|
-
this.rules = rules;
|
|
2424
|
-
this.policies = policies;
|
|
2425
|
-
this.evaluator = evaluator;
|
|
2423
|
+
//#endregion
|
|
2424
|
+
//#region src/services/usage-meter.ts
|
|
2425
|
+
var TenantUsageMeter = class TenantUsageMeter {
|
|
2426
|
+
constructor(metrics, classOptions = {}) {
|
|
2427
|
+
this.metrics = metrics;
|
|
2428
|
+
this.classOptions = classOptions;
|
|
2426
2429
|
}
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
evaluator;
|
|
2433
|
-
static async create(options) {
|
|
2434
|
-
if (typeof options.billingRelationships?.getRelationship !== "function") throw new Error("Reseller billing requires a billingRelationships reader from smrt-tenancy.");
|
|
2435
|
-
const { billingRelationships: _reader, authorize: _authorize, ...rest } = options;
|
|
2436
|
-
const books = await PriceBookCollection.create(rest);
|
|
2437
|
-
const shared = {
|
|
2438
|
-
...rest,
|
|
2439
|
-
db: books.db
|
|
2440
|
-
};
|
|
2441
|
-
const policies = await SpendingPolicyCollection.create(shared);
|
|
2442
|
-
const evaluator = new SpendingPolicyEvaluator(policies, await ClientChargeCollection.create(shared), await BillingAdjustmentCollection.create(shared), {
|
|
2443
|
-
retailCharges: await RetailChargeCollection.create(shared),
|
|
2444
|
-
credits: await CreditGrantCollection.create(shared)
|
|
2445
|
-
});
|
|
2446
|
-
return new ResellerBillingService(options, books, await PriceBookAssignmentCollection.create(shared), await PricingRuleCollection.create(shared), policies, evaluator);
|
|
2430
|
+
metrics;
|
|
2431
|
+
classOptions;
|
|
2432
|
+
static async create(classOptions = {}) {
|
|
2433
|
+
const metrics = await TenantUsageMetricCollection.create(classOptions);
|
|
2434
|
+
return new TenantUsageMeter(metrics, classOptions);
|
|
2447
2435
|
}
|
|
2448
2436
|
/**
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2451
|
-
*
|
|
2437
|
+
* Record one usage row.
|
|
2438
|
+
*
|
|
2439
|
+
* Accepts the polymorphic subscriber fields directly on the options object
|
|
2440
|
+
* (`subscriberKind`/`subscriberExternalId`); when omitted defaults to a
|
|
2441
|
+
* `'tenant'`-kind row keyed off `tenantId`. The collection layer enforces
|
|
2442
|
+
* the XOR invariant — passing `subscriberKind: 'external'` without a
|
|
2443
|
+
* non-empty `subscriberExternalId` throws.
|
|
2452
2444
|
*/
|
|
2453
|
-
async
|
|
2454
|
-
|
|
2455
|
-
const sellerTenantId = canonicalTenantId(String(book.tenantId));
|
|
2456
|
-
await this.assertManage("define_prices", sellerTenantId, void 0, true);
|
|
2457
|
-
if (!input.ruleKey.trim() || !input.metricKey.trim()) throw new Error("Price book prices require a ruleKey and metricKey.");
|
|
2458
|
-
if (input.prices.length === 0) throw new ResellerBillingError("A price needs at least one currency.", "INVALID_CURRENCY");
|
|
2459
|
-
const currencies = /* @__PURE__ */ new Set();
|
|
2460
|
-
for (const { currency } of input.prices) {
|
|
2461
|
-
assertCurrency(currency);
|
|
2462
|
-
if (currencies.has(currency)) throw new ResellerBillingError(`Currency ${currency} is listed twice for one price.`, "INVALID_CURRENCY");
|
|
2463
|
-
currencies.add(currency);
|
|
2464
|
-
}
|
|
2465
|
-
const effectiveFrom = input.effectiveFrom ?? /* @__PURE__ */ new Date();
|
|
2466
|
-
return authorized(async () => {
|
|
2467
|
-
const saved = [];
|
|
2468
|
-
for (const { currency, terms } of input.prices) {
|
|
2469
|
-
const id = await deterministicUuid([
|
|
2470
|
-
"price-book-rule",
|
|
2471
|
-
String(book.id),
|
|
2472
|
-
input.ruleKey,
|
|
2473
|
-
input.metricKey,
|
|
2474
|
-
input.serviceKey ?? "",
|
|
2475
|
-
currency,
|
|
2476
|
-
effectiveFrom.toISOString()
|
|
2477
|
-
]);
|
|
2478
|
-
const values = {
|
|
2479
|
-
tenantId: book.tenantId,
|
|
2480
|
-
priceBookId: String(book.id),
|
|
2481
|
-
ruleKey: input.ruleKey,
|
|
2482
|
-
metricKey: input.metricKey,
|
|
2483
|
-
serviceKey: input.serviceKey ?? "",
|
|
2484
|
-
strategy: input.strategy,
|
|
2485
|
-
currency,
|
|
2486
|
-
effectiveFrom,
|
|
2487
|
-
effectiveTo: input.effectiveTo ?? null,
|
|
2488
|
-
priority: input.priority ?? 0,
|
|
2489
|
-
terms: JSON.stringify(terms),
|
|
2490
|
-
active: true
|
|
2491
|
-
};
|
|
2492
|
-
const existing = await this.rules.get(id);
|
|
2493
|
-
if (existing) {
|
|
2494
|
-
Object.assign(existing, values);
|
|
2495
|
-
await existing.save();
|
|
2496
|
-
saved.push(existing);
|
|
2497
|
-
} else saved.push(await this.rules.create({
|
|
2498
|
-
id,
|
|
2499
|
-
...values
|
|
2500
|
-
}));
|
|
2501
|
-
}
|
|
2502
|
-
return saved;
|
|
2503
|
-
});
|
|
2445
|
+
async record(options) {
|
|
2446
|
+
await this.metrics.recordUsage(options);
|
|
2504
2447
|
}
|
|
2505
2448
|
/**
|
|
2506
|
-
*
|
|
2507
|
-
*
|
|
2508
|
-
*
|
|
2509
|
-
*
|
|
2510
|
-
*
|
|
2511
|
-
* retail leg by the reseller (`assign_retail_price_book`).
|
|
2449
|
+
* Summarize usage over a window for a given subscriber.
|
|
2450
|
+
*
|
|
2451
|
+
* The `ai.*` short-circuit only fires for `'tenant'`-kind subscribers since
|
|
2452
|
+
* the `_smrt_ai_usage` system table is tenant-scoped; external subscribers
|
|
2453
|
+
* fall through to the normal `_smrt_tenant_usage_metrics` aggregation.
|
|
2512
2454
|
*/
|
|
2513
|
-
async
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2455
|
+
async summarize(options) {
|
|
2456
|
+
normalizeSubscriber({
|
|
2457
|
+
tenantId: options.tenantId,
|
|
2458
|
+
subscriberKind: options.subscriberKind,
|
|
2459
|
+
subscriberExternalId: options.subscriberExternalId
|
|
2460
|
+
});
|
|
2461
|
+
const aiSummary = await this.trySummarizeAiMetric(options);
|
|
2462
|
+
if (aiSummary) return aiSummary;
|
|
2463
|
+
return this.metrics.summarizeUsage(options);
|
|
2464
|
+
}
|
|
2465
|
+
async summarizeBatch(options) {
|
|
2466
|
+
const subscriber = normalizeSubscriber({
|
|
2467
|
+
tenantId: options.tenantId,
|
|
2468
|
+
subscriberKind: options.subscriberKind,
|
|
2469
|
+
subscriberExternalId: options.subscriberExternalId
|
|
2470
|
+
});
|
|
2471
|
+
const metricKeys = Array.from(new Set(options.metricKeys));
|
|
2472
|
+
if (metricKeys.length === 0) return [];
|
|
2473
|
+
const useTenantAiSummary = subscriber.kind === "tenant";
|
|
2474
|
+
const aiMetricKeys = useTenantAiSummary ? metricKeys.filter((metricKey) => metricKey.startsWith("ai.")) : [];
|
|
2475
|
+
const persistedMetricKeys = useTenantAiSummary ? metricKeys.filter((metricKey) => !metricKey.startsWith("ai.")) : metricKeys;
|
|
2476
|
+
const summaries = /* @__PURE__ */ new Map();
|
|
2477
|
+
let fallbackAiMetricKeys = [];
|
|
2478
|
+
if (aiMetricKeys.length > 0) if (!await this.hasAiUsageTable()) fallbackAiMetricKeys = aiMetricKeys;
|
|
2479
|
+
else try {
|
|
2480
|
+
const quantityByMetric = aiQuantityByMetric(await this.summarizeAiUsage({
|
|
2481
|
+
tenantId: options.tenantId,
|
|
2482
|
+
window: options.window
|
|
2483
|
+
}));
|
|
2484
|
+
for (const metricKey of aiMetricKeys) summaries.set(metricKey, {
|
|
2485
|
+
tenantId: options.tenantId,
|
|
2486
|
+
metricKey,
|
|
2487
|
+
quantity: quantityByMetric[metricKey] ?? 0,
|
|
2488
|
+
windowStart: options.window.start,
|
|
2489
|
+
windowEnd: options.window.end
|
|
2490
|
+
});
|
|
2491
|
+
} catch (error) {
|
|
2492
|
+
if (!isMissingAiUsageTableError(error)) throw error;
|
|
2493
|
+
fallbackAiMetricKeys = aiMetricKeys;
|
|
2529
2494
|
}
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
const fresh = row && tenantKey(row.resellerTenantId) === resellerTenantId ? assignmentView(row) : null;
|
|
2537
|
-
if (input.wholesale === null && fresh?.wholesale?.priceBookId !== current?.wholesale?.priceBookId) throw new ResellerBillingError("The wholesale assignment changed concurrently; retry.", "ASSIGNMENT_CONFLICT");
|
|
2538
|
-
const wholesale = input.wholesale === void 0 ? fresh?.wholesale ?? null : input.wholesale;
|
|
2539
|
-
const retail = input.retail === void 0 ? fresh?.retail ?? null : input.retail;
|
|
2540
|
-
const values = {
|
|
2541
|
-
childTenantId,
|
|
2542
|
-
resellerTenantId,
|
|
2543
|
-
wholesalePriceBookId: wholesale?.priceBookId ?? "",
|
|
2544
|
-
wholesaleCurrency: wholesale?.currency ?? "",
|
|
2545
|
-
retailPriceBookId: retail?.priceBookId ?? "",
|
|
2546
|
-
retailCurrency: retail?.currency ?? ""
|
|
2547
|
-
};
|
|
2548
|
-
if (row) {
|
|
2549
|
-
Object.assign(row, values);
|
|
2550
|
-
await row.save();
|
|
2551
|
-
return assignmentView(row);
|
|
2552
|
-
}
|
|
2553
|
-
return assignmentView(await assignments.create(values));
|
|
2554
|
-
}));
|
|
2495
|
+
const persistedSummaries = await this.metrics.summarizeUsageBatch({
|
|
2496
|
+
...options,
|
|
2497
|
+
metricKeys: [...persistedMetricKeys, ...fallbackAiMetricKeys]
|
|
2498
|
+
});
|
|
2499
|
+
for (const summary of persistedSummaries) summaries.set(summary.metricKey, summary);
|
|
2500
|
+
return metricKeys.map((metricKey) => summaries.get(metricKey) ?? emptyUsageSummary$1(subscriber, metricKey, options.window));
|
|
2555
2501
|
}
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
const relationship = await this.options.billingRelationships.getRelationship(canonicalTenantId(childTenantId));
|
|
2559
|
-
if (!relationship) return null;
|
|
2560
|
-
const row = await this.assignments.get({ childTenantId: relationship.childTenantId });
|
|
2561
|
-
if (!row || tenantKey(row.resellerTenantId) !== relationship.resellerTenantId) return null;
|
|
2562
|
-
return assignmentView(row);
|
|
2563
|
-
}
|
|
2564
|
-
/**
|
|
2565
|
-
* Create or replace a spending policy that a parent sets on its child. The
|
|
2566
|
-
* row belongs to the child (so the ordinary evaluator enforces it for the
|
|
2567
|
-
* child) and records the parent in `setByTenantId`, which locks it against
|
|
2568
|
-
* changes by the child. A delegated limit left by a former parent may be
|
|
2569
|
-
* replaced (not a former parent's prepaid balance, which keeps its credit
|
|
2570
|
-
* ledger); one the child set for itself may not. Use `period: 'balance'`
|
|
2571
|
-
* for a prepaid credit balance and fund it with {@link grantChildCredit}.
|
|
2572
|
-
*/
|
|
2573
|
-
async setDelegatedSpendingPolicy(input) {
|
|
2574
|
-
const parentTenantId = canonicalTenantId(input.parentTenantId);
|
|
2575
|
-
const relationship = await this.requireChildOf(input.childTenantId, parentTenantId);
|
|
2576
|
-
await this.assertManage("manage_child_spending", parentTenantId, relationship.childTenantId, false, relationship.resellerTenantId);
|
|
2577
|
-
assertCurrency(input.currency);
|
|
2578
|
-
if (input.limitAmount !== void 0 && !Number.isSafeInteger(input.limitAmount)) throw new ResellerBillingError(`Spending limits must be integer minor units \u2014 got ${input.limitAmount}.`, "INVALID_AMOUNT");
|
|
2579
|
-
const values = {
|
|
2580
|
-
tenantId: relationship.childTenantId,
|
|
2581
|
-
name: input.name,
|
|
2582
|
-
subscriberKind: input.subscriberKind ?? "",
|
|
2583
|
-
subscriberExternalId: input.subscriberExternalId ?? "",
|
|
2584
|
-
projectId: input.projectId ?? "",
|
|
2585
|
-
serviceKey: input.serviceKey ?? "",
|
|
2586
|
-
metricKey: input.metricKey ?? "",
|
|
2587
|
-
period: input.period ?? "month",
|
|
2588
|
-
rollingSeconds: input.rollingSeconds ?? 0,
|
|
2589
|
-
limitAmount: input.limitAmount ?? 0,
|
|
2590
|
-
currency: input.currency,
|
|
2591
|
-
behavior: input.behavior,
|
|
2592
|
-
priority: input.priority ?? 0,
|
|
2593
|
-
active: input.active ?? true,
|
|
2594
|
-
basis: input.basis,
|
|
2595
|
-
setByTenantId: parentTenantId,
|
|
2596
|
-
...input.balanceFrom ? { balanceFrom: input.balanceFrom } : {}
|
|
2597
|
-
};
|
|
2598
|
-
return authorized(async () => {
|
|
2599
|
-
const existing = (await this.policies.list({
|
|
2600
|
-
where: {
|
|
2601
|
-
tenantId: values.tenantId,
|
|
2602
|
-
subscriberKind: values.subscriberKind,
|
|
2603
|
-
subscriberExternalId: values.subscriberExternalId,
|
|
2604
|
-
projectId: values.projectId,
|
|
2605
|
-
serviceKey: values.serviceKey,
|
|
2606
|
-
metricKey: values.metricKey,
|
|
2607
|
-
period: values.period,
|
|
2608
|
-
name: values.name
|
|
2609
|
-
},
|
|
2610
|
-
limit: 1
|
|
2611
|
-
}))[0];
|
|
2612
|
-
if (existing) {
|
|
2613
|
-
const owner = tenantKey(existing.setByTenantId);
|
|
2614
|
-
if (!owner) throw new ResellerBillingError(`Spending policy '${input.name}' already exists for this child and was set by the child.`, "POLICY_CONFLICT");
|
|
2615
|
-
if (owner !== parentTenantId && existing.period === "balance") throw new ResellerBillingError(`Balance policy '${input.name}' belongs to a former parent; choose another name.`, "POLICY_CONFLICT");
|
|
2616
|
-
Object.assign(existing, values);
|
|
2617
|
-
await existing.save();
|
|
2618
|
-
return existing;
|
|
2619
|
-
}
|
|
2620
|
-
return this.policies.create(values);
|
|
2621
|
-
});
|
|
2622
|
-
}
|
|
2623
|
-
/** Credit a prepaid balance policy the parent set on its child. */
|
|
2624
|
-
async grantChildCredit(input) {
|
|
2625
|
-
const parentTenantId = canonicalTenantId(input.parentTenantId);
|
|
2626
|
-
const relationship = await this.requireChildOf(input.childTenantId, parentTenantId);
|
|
2627
|
-
await this.assertManage("manage_child_spending", parentTenantId, relationship.childTenantId, false, relationship.resellerTenantId);
|
|
2628
|
-
return authorized(async () => {
|
|
2629
|
-
const policy = await this.policies.get(input.spendingPolicyId);
|
|
2630
|
-
if (!policy || tenantKey(policy.tenantId) !== relationship.childTenantId || tenantKey(policy.setByTenantId) !== parentTenantId) throw new ResellerBillingError(`Spending policy ${input.spendingPolicyId} is not a policy this parent set on the child.`, "POLICY_NOT_FOUND");
|
|
2631
|
-
return this.evaluator.grantCredit({
|
|
2632
|
-
spendingPolicyId: input.spendingPolicyId,
|
|
2633
|
-
amount: input.amount,
|
|
2634
|
-
reason: input.reason,
|
|
2635
|
-
source: input.source,
|
|
2636
|
-
sourceId: input.sourceId,
|
|
2637
|
-
grantedByTenantId: parentTenantId
|
|
2638
|
-
});
|
|
2639
|
-
});
|
|
2640
|
-
}
|
|
2641
|
-
async requireRelationship(childTenantId) {
|
|
2642
|
-
const relationship = await this.options.billingRelationships.getRelationship(canonicalTenantId(childTenantId));
|
|
2643
|
-
if (!relationship) throw new ResellerBillingError(`Tenant ${childTenantId} has no reseller relationship.`, "RELATIONSHIP_REQUIRED");
|
|
2644
|
-
return relationship;
|
|
2645
|
-
}
|
|
2646
|
-
async requireChildOf(childTenantId, parentTenantId) {
|
|
2647
|
-
const relationship = await this.requireRelationship(childTenantId);
|
|
2648
|
-
if (relationship.resellerTenantId !== parentTenantId) throw new ResellerBillingError(`Tenant ${childTenantId} is not a child of ${parentTenantId}.`, "RELATIONSHIP_REQUIRED");
|
|
2649
|
-
return relationship;
|
|
2650
|
-
}
|
|
2651
|
-
/**
|
|
2652
|
-
* Read a book's metadata to learn its publisher and kind before deciding
|
|
2653
|
-
* authorization. Books belong to their seller, so the read is not scoped to
|
|
2654
|
-
* the caller; nothing beyond a validation error is returned on denial.
|
|
2655
|
-
*/
|
|
2656
|
-
async readBook(id) {
|
|
2657
|
-
const book = await authorized(() => this.books.get(id));
|
|
2658
|
-
if (!book?.id) throw new ResellerBillingError(`Price book ${id} was not found.`, "PRICE_BOOK_NOT_FOUND");
|
|
2659
|
-
return book;
|
|
2660
|
-
}
|
|
2661
|
-
async requireLeg(leg, kind) {
|
|
2662
|
-
assertCurrency(leg.currency);
|
|
2663
|
-
const book = await this.readBook(leg.priceBookId);
|
|
2664
|
-
if (book.kind !== kind) throw new ResellerBillingError(`Price book '${book.bookKey}' is a ${book.kind} book, not ${kind}.`, "PRICE_BOOK_KIND_MISMATCH");
|
|
2665
|
-
return book;
|
|
2666
|
-
}
|
|
2667
|
-
async assertManage(action, tenantId, childTenantId, allowOwnTenant = false, resellerTenantId) {
|
|
2668
|
-
if (isSystemContext() || isSuperAdminBypass() || allowOwnTenant && getTenantId()?.toLowerCase() === tenantId || await this.options.authorize?.({
|
|
2669
|
-
action,
|
|
2670
|
-
tenantId,
|
|
2671
|
-
childTenantId,
|
|
2672
|
-
...resellerTenantId ? { resellerTenantId } : {}
|
|
2673
|
-
})) return;
|
|
2674
|
-
throw new TenantIsolationError("Reseller billing mutation denied.");
|
|
2675
|
-
}
|
|
2676
|
-
};
|
|
2677
|
-
//#endregion
|
|
2678
|
-
//#region src/services/threshold-evaluator.ts
|
|
2679
|
-
function evaluateThreshold(threshold, usage) {
|
|
2680
|
-
const ratio = threshold.limit === 0 ? usage.quantity > 0 ? Infinity : 0 : usage.quantity / threshold.limit;
|
|
2681
|
-
const warningRatio = threshold.warningRatio ?? .8;
|
|
2682
|
-
const blocked = threshold.enforcement === "block" && (threshold.limit === 0 ? usage.quantity > 0 : usage.quantity >= threshold.limit);
|
|
2683
|
-
return {
|
|
2684
|
-
threshold,
|
|
2685
|
-
usage,
|
|
2686
|
-
ratio,
|
|
2687
|
-
state: blocked ? "blocked" : !blocked && ratio >= warningRatio ? "warn" : "ok",
|
|
2688
|
-
allowed: !blocked,
|
|
2689
|
-
remaining: Math.max(0, threshold.limit - usage.quantity)
|
|
2690
|
-
};
|
|
2691
|
-
}
|
|
2692
|
-
function evaluateThresholds(thresholds, usage) {
|
|
2693
|
-
const usageByMetric = new Map(usage.map((summary) => [summary.metricKey, summary]));
|
|
2694
|
-
return thresholds.map((threshold) => {
|
|
2695
|
-
return evaluateThreshold(threshold, usageByMetric.get(threshold.metricKey) ?? emptyUsageSummary$2(threshold.metricKey));
|
|
2696
|
-
});
|
|
2697
|
-
}
|
|
2698
|
-
function emptyUsageSummary$2(metricKey) {
|
|
2699
|
-
const now = /* @__PURE__ */ new Date();
|
|
2700
|
-
return {
|
|
2701
|
-
tenantId: "",
|
|
2702
|
-
metricKey,
|
|
2703
|
-
quantity: 0,
|
|
2704
|
-
windowStart: now,
|
|
2705
|
-
windowEnd: now
|
|
2706
|
-
};
|
|
2707
|
-
}
|
|
2708
|
-
//#endregion
|
|
2709
|
-
//#region src/services/usage-meter.ts
|
|
2710
|
-
var TenantUsageMeter = class TenantUsageMeter {
|
|
2711
|
-
constructor(metrics, classOptions = {}) {
|
|
2712
|
-
this.metrics = metrics;
|
|
2713
|
-
this.classOptions = classOptions;
|
|
2714
|
-
}
|
|
2715
|
-
metrics;
|
|
2716
|
-
classOptions;
|
|
2717
|
-
static async create(classOptions = {}) {
|
|
2718
|
-
const metrics = await TenantUsageMetricCollection.create(classOptions);
|
|
2719
|
-
return new TenantUsageMeter(metrics, classOptions);
|
|
2720
|
-
}
|
|
2721
|
-
/**
|
|
2722
|
-
* Record one usage row.
|
|
2723
|
-
*
|
|
2724
|
-
* Accepts the polymorphic subscriber fields directly on the options object
|
|
2725
|
-
* (`subscriberKind`/`subscriberExternalId`); when omitted defaults to a
|
|
2726
|
-
* `'tenant'`-kind row keyed off `tenantId`. The collection layer enforces
|
|
2727
|
-
* the XOR invariant — passing `subscriberKind: 'external'` without a
|
|
2728
|
-
* non-empty `subscriberExternalId` throws.
|
|
2729
|
-
*/
|
|
2730
|
-
async record(options) {
|
|
2731
|
-
await this.metrics.recordUsage(options);
|
|
2732
|
-
}
|
|
2733
|
-
/**
|
|
2734
|
-
* Summarize usage over a window for a given subscriber.
|
|
2735
|
-
*
|
|
2736
|
-
* The `ai.*` short-circuit only fires for `'tenant'`-kind subscribers since
|
|
2737
|
-
* the `_smrt_ai_usage` system table is tenant-scoped; external subscribers
|
|
2738
|
-
* fall through to the normal `_smrt_tenant_usage_metrics` aggregation.
|
|
2739
|
-
*/
|
|
2740
|
-
async summarize(options) {
|
|
2741
|
-
normalizeSubscriber({
|
|
2742
|
-
tenantId: options.tenantId,
|
|
2743
|
-
subscriberKind: options.subscriberKind,
|
|
2744
|
-
subscriberExternalId: options.subscriberExternalId
|
|
2745
|
-
});
|
|
2746
|
-
const aiSummary = await this.trySummarizeAiMetric(options);
|
|
2747
|
-
if (aiSummary) return aiSummary;
|
|
2748
|
-
return this.metrics.summarizeUsage(options);
|
|
2749
|
-
}
|
|
2750
|
-
async summarizeBatch(options) {
|
|
2751
|
-
const subscriber = normalizeSubscriber({
|
|
2752
|
-
tenantId: options.tenantId,
|
|
2753
|
-
subscriberKind: options.subscriberKind,
|
|
2754
|
-
subscriberExternalId: options.subscriberExternalId
|
|
2755
|
-
});
|
|
2756
|
-
const metricKeys = Array.from(new Set(options.metricKeys));
|
|
2757
|
-
if (metricKeys.length === 0) return [];
|
|
2758
|
-
const useTenantAiSummary = subscriber.kind === "tenant";
|
|
2759
|
-
const aiMetricKeys = useTenantAiSummary ? metricKeys.filter((metricKey) => metricKey.startsWith("ai.")) : [];
|
|
2760
|
-
const persistedMetricKeys = useTenantAiSummary ? metricKeys.filter((metricKey) => !metricKey.startsWith("ai.")) : metricKeys;
|
|
2761
|
-
const summaries = /* @__PURE__ */ new Map();
|
|
2762
|
-
let fallbackAiMetricKeys = [];
|
|
2763
|
-
if (aiMetricKeys.length > 0) if (!await this.hasAiUsageTable()) fallbackAiMetricKeys = aiMetricKeys;
|
|
2764
|
-
else try {
|
|
2765
|
-
const quantityByMetric = aiQuantityByMetric(await this.summarizeAiUsage({
|
|
2766
|
-
tenantId: options.tenantId,
|
|
2767
|
-
window: options.window
|
|
2768
|
-
}));
|
|
2769
|
-
for (const metricKey of aiMetricKeys) summaries.set(metricKey, {
|
|
2770
|
-
tenantId: options.tenantId,
|
|
2771
|
-
metricKey,
|
|
2772
|
-
quantity: quantityByMetric[metricKey] ?? 0,
|
|
2773
|
-
windowStart: options.window.start,
|
|
2774
|
-
windowEnd: options.window.end
|
|
2775
|
-
});
|
|
2776
|
-
} catch (error) {
|
|
2777
|
-
if (!isMissingAiUsageTableError(error)) throw error;
|
|
2778
|
-
fallbackAiMetricKeys = aiMetricKeys;
|
|
2779
|
-
}
|
|
2780
|
-
const persistedSummaries = await this.metrics.summarizeUsageBatch({
|
|
2781
|
-
...options,
|
|
2782
|
-
metricKeys: [...persistedMetricKeys, ...fallbackAiMetricKeys]
|
|
2783
|
-
});
|
|
2784
|
-
for (const summary of persistedSummaries) summaries.set(summary.metricKey, summary);
|
|
2785
|
-
return metricKeys.map((metricKey) => summaries.get(metricKey) ?? emptyUsageSummary$1(subscriber, metricKey, options.window));
|
|
2786
|
-
}
|
|
2787
|
-
async summarizeAiUsage(options) {
|
|
2788
|
-
return this.metrics.summarizeTenantAiUsage(options);
|
|
2502
|
+
async summarizeAiUsage(options) {
|
|
2503
|
+
return this.metrics.summarizeTenantAiUsage(options);
|
|
2789
2504
|
}
|
|
2790
2505
|
getOptions() {
|
|
2791
2506
|
return this.classOptions;
|
|
@@ -2912,17 +2627,53 @@ var SubscriptionResolver = class SubscriptionResolver {
|
|
|
2912
2627
|
};
|
|
2913
2628
|
}
|
|
2914
2629
|
/**
|
|
2915
|
-
*
|
|
2916
|
-
*
|
|
2917
|
-
*
|
|
2630
|
+
* Feature keys the subscriber's entitled terms grant, without evaluating
|
|
2631
|
+
* usage thresholds (#4761). Same subscription, plan-version and entitlement
|
|
2632
|
+
* rules as {@link resolveEntitlements}; used by `SubscriptionFeatureSource`
|
|
2633
|
+
* so a flag check never reads usage meters.
|
|
2918
2634
|
*/
|
|
2919
|
-
async
|
|
2635
|
+
async resolveFeatureGrants(subscriber, options = {}) {
|
|
2636
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
2637
|
+
const { identity, terms } = await this.resolveEntitledTerms(subscriber, now, options);
|
|
2638
|
+
return {
|
|
2639
|
+
featureKeys: terms ? terms.getFeatureKeys() : [],
|
|
2640
|
+
grants: terms ? terms.getFeatureGrants() : [],
|
|
2641
|
+
planId: identity?.planId ?? null,
|
|
2642
|
+
planKey: identity?.planKey ?? null
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
/**
|
|
2646
|
+
* The entitled plan terms' thresholds, without reading any usage meter
|
|
2647
|
+
* (#4760). Same subscription, plan-version and entitlement rules as
|
|
2648
|
+
* {@link resolveEntitlements}; `entitled` is false when there is no
|
|
2649
|
+
* current subscription or it does not entitle now (thresholds are then
|
|
2650
|
+
* empty). The hosted inference gate reads its spend caps from here and
|
|
2651
|
+
* meters `_smrt_ai_usage` itself. Thresholds are returned as stored, valid
|
|
2652
|
+
* or not (the models' `getThresholds()` drops invalid entries), so a caller
|
|
2653
|
+
* can refuse a malformed cap instead of skipping it; thresholds JSON that
|
|
2654
|
+
* is not an array throws.
|
|
2655
|
+
*/
|
|
2656
|
+
async resolvePlanThresholds(subscriber, options = {}) {
|
|
2920
2657
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
2658
|
+
const { identity, terms } = await this.resolveEntitledTerms(subscriber, now, options);
|
|
2659
|
+
return {
|
|
2660
|
+
entitled: terms !== null,
|
|
2661
|
+
thresholds: terms ? rawThresholds(terms.thresholds) : [],
|
|
2662
|
+
planId: identity?.planId ?? null,
|
|
2663
|
+
planKey: identity?.planKey ?? null,
|
|
2664
|
+
planVersionId: identity?.planVersionId ?? null,
|
|
2665
|
+
subscriptionId: identity?.subscriptionId ?? null
|
|
2666
|
+
};
|
|
2667
|
+
}
|
|
2668
|
+
async resolveEntitledTerms(subscriber, now, options) {
|
|
2921
2669
|
const { subscription, plan, planVersion } = await this.loadEntitlementContext(subscriber, {
|
|
2922
2670
|
...options,
|
|
2923
2671
|
now
|
|
2924
2672
|
});
|
|
2925
|
-
if (!subscription) return
|
|
2673
|
+
if (!subscription) return {
|
|
2674
|
+
identity: null,
|
|
2675
|
+
terms: null
|
|
2676
|
+
};
|
|
2926
2677
|
const terms = planVersion === void 0 ? plan : planVersion ?? (subscription.planVersionId ? null : plan);
|
|
2927
2678
|
const identity = {
|
|
2928
2679
|
planId: plan?.id ?? planVersion?.planId ?? subscription.planId ?? null,
|
|
@@ -2933,6 +2684,25 @@ var SubscriptionResolver = class SubscriptionResolver {
|
|
|
2933
2684
|
status: subscription.status
|
|
2934
2685
|
};
|
|
2935
2686
|
if (!terms?.isActive() || !subscription.isEntitled(now)) return {
|
|
2687
|
+
identity,
|
|
2688
|
+
terms: null
|
|
2689
|
+
};
|
|
2690
|
+
return {
|
|
2691
|
+
identity,
|
|
2692
|
+
terms
|
|
2693
|
+
};
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Polymorphic entitlement resolution. Works for both `'tenant'`-kind and
|
|
2697
|
+
* `'external'`-kind subscribers and is the preferred surface — the
|
|
2698
|
+
* `resolveTenantEntitlements(tenantId)` method below is a thin wrapper.
|
|
2699
|
+
*/
|
|
2700
|
+
async resolveEntitlements(subscriber, options = {}) {
|
|
2701
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
2702
|
+
const entitled = await this.resolveEntitledTerms(subscriber, now, options);
|
|
2703
|
+
if (!entitled.identity) return emptyResolution(subscriber);
|
|
2704
|
+
const { identity, terms } = entitled;
|
|
2705
|
+
if (!terms) return {
|
|
2936
2706
|
...emptyResolution(subscriber),
|
|
2937
2707
|
...identity
|
|
2938
2708
|
};
|
|
@@ -3137,7 +2907,722 @@ function emptyUsageSummary(subscriber, metricKey, window) {
|
|
|
3137
2907
|
};
|
|
3138
2908
|
return summary;
|
|
3139
2909
|
}
|
|
2910
|
+
function rawThresholds(value) {
|
|
2911
|
+
if (value === null || value === void 0 || value.trim() === "") return [];
|
|
2912
|
+
const parsed = JSON.parse(value);
|
|
2913
|
+
if (!Array.isArray(parsed)) throw new Error("Plan thresholds are not a JSON array.");
|
|
2914
|
+
return parsed.filter((entry) => entry !== null && typeof entry === "object" && !Array.isArray(entry));
|
|
2915
|
+
}
|
|
2916
|
+
//#endregion
|
|
2917
|
+
//#region src/services/subscription-feature-source.ts
|
|
2918
|
+
var FEATURE_GRANT_SOURCE_SLOT_KEY = "@happyvertical/smrt-features:grant-source";
|
|
2919
|
+
var SUBSCRIPTION_TABLES = /* @__PURE__ */ new Set([
|
|
2920
|
+
"_smrt_tenant_subscriptions",
|
|
2921
|
+
"_smrt_subscription_plans",
|
|
2922
|
+
"_smrt_subscription_plan_versions"
|
|
2923
|
+
]);
|
|
2924
|
+
var SubscriptionFeatureSource = class SubscriptionFeatureSource {
|
|
2925
|
+
resolver;
|
|
2926
|
+
plans;
|
|
2927
|
+
memoize;
|
|
2928
|
+
now;
|
|
2929
|
+
grants = /* @__PURE__ */ new Map();
|
|
2930
|
+
catalog = null;
|
|
2931
|
+
constructor(options) {
|
|
2932
|
+
this.resolver = options.resolver;
|
|
2933
|
+
this.plans = options.plans;
|
|
2934
|
+
this.memoize = options.memoize ?? true;
|
|
2935
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
2936
|
+
}
|
|
2937
|
+
/**
|
|
2938
|
+
* Build one source with its own resolver and plan catalog. Call once per
|
|
2939
|
+
* request (or once at setup with `memoize: false` for a global source).
|
|
2940
|
+
*/
|
|
2941
|
+
static async create(classOptions = {}, options = {}) {
|
|
2942
|
+
const [resolver, plans] = await Promise.all([SubscriptionResolver.create(classOptions), SubscriptionPlanCollection.create(classOptions)]);
|
|
2943
|
+
return new SubscriptionFeatureSource({
|
|
2944
|
+
...options,
|
|
2945
|
+
resolver,
|
|
2946
|
+
plans
|
|
2947
|
+
});
|
|
2948
|
+
}
|
|
2949
|
+
/** Feature keys the tenant's entitled plan grants, or `null` for none. */
|
|
2950
|
+
getGrants(tenantId) {
|
|
2951
|
+
if (!this.memoize) return this.loadGrants(tenantId);
|
|
2952
|
+
let pending = this.grants.get(tenantId);
|
|
2953
|
+
if (!pending) {
|
|
2954
|
+
pending = this.loadGrants(tenantId);
|
|
2955
|
+
this.grants.set(tenantId, pending);
|
|
2956
|
+
pending.catch(() => this.grants.delete(tenantId));
|
|
2957
|
+
}
|
|
2958
|
+
return pending;
|
|
2959
|
+
}
|
|
2960
|
+
/**
|
|
2961
|
+
* The first active plan (by `sortOrder`) visible in the current context
|
|
2962
|
+
* that grants `featureKey`, for an upgrade response.
|
|
2963
|
+
*/
|
|
2964
|
+
async findGrantingPlan(featureKey, _tenantId) {
|
|
2965
|
+
const plan = (await this.loadCatalog())?.find((candidate) => candidate.getFeatureKeys().includes(featureKey));
|
|
2966
|
+
if (!plan) return null;
|
|
2967
|
+
return {
|
|
2968
|
+
planKey: plan.planKey,
|
|
2969
|
+
planId: plan.id ? String(plan.id) : null,
|
|
2970
|
+
name: plan.name || null
|
|
2971
|
+
};
|
|
2972
|
+
}
|
|
2973
|
+
async loadGrants(tenantId) {
|
|
2974
|
+
try {
|
|
2975
|
+
const grants = await this.resolver.resolveFeatureGrants({
|
|
2976
|
+
kind: "tenant",
|
|
2977
|
+
tenantId
|
|
2978
|
+
}, { now: this.now() });
|
|
2979
|
+
return grants.featureKeys.length > 0 ? {
|
|
2980
|
+
featureKeys: grants.featureKeys,
|
|
2981
|
+
planId: grants.planId,
|
|
2982
|
+
planKey: grants.planKey
|
|
2983
|
+
} : null;
|
|
2984
|
+
} catch (error) {
|
|
2985
|
+
if (isMissingSubscriptionTableError(error)) return null;
|
|
2986
|
+
throw error;
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
loadCatalog() {
|
|
2990
|
+
if (!this.plans) return Promise.resolve(null);
|
|
2991
|
+
const load = async () => {
|
|
2992
|
+
try {
|
|
2993
|
+
return await this.plans?.findActive() ?? null;
|
|
2994
|
+
} catch (error) {
|
|
2995
|
+
if (isMissingSubscriptionTableError(error)) return null;
|
|
2996
|
+
throw error;
|
|
2997
|
+
}
|
|
2998
|
+
};
|
|
2999
|
+
if (!this.memoize) return load();
|
|
3000
|
+
if (!this.catalog) {
|
|
3001
|
+
this.catalog = load();
|
|
3002
|
+
this.catalog.catch(() => {
|
|
3003
|
+
this.catalog = null;
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
return this.catalog;
|
|
3007
|
+
}
|
|
3008
|
+
};
|
|
3009
|
+
function registerSubscriptionFeatureSource(source) {
|
|
3010
|
+
globalThis[Symbol.for(FEATURE_GRANT_SOURCE_SLOT_KEY)] = source;
|
|
3011
|
+
}
|
|
3012
|
+
function isMissingSubscriptionTableError(error) {
|
|
3013
|
+
let current = error;
|
|
3014
|
+
for (let depth = 0; current && depth < 8; depth++) {
|
|
3015
|
+
const candidate = current;
|
|
3016
|
+
if (candidate.code === "DB_SCHEMA_MISSING" && typeof candidate.details?.tableName === "string" && SUBSCRIPTION_TABLES.has(candidate.details.tableName)) return true;
|
|
3017
|
+
current = candidate.cause;
|
|
3018
|
+
}
|
|
3019
|
+
const classification = classifyDatabaseError(error);
|
|
3020
|
+
if (classification.kind !== "undefined_object") return false;
|
|
3021
|
+
if (classification.driverCodes.includes("42703")) return false;
|
|
3022
|
+
return classification.driverMessages.some((message) => {
|
|
3023
|
+
const lower = message.toLowerCase();
|
|
3024
|
+
return (lower.includes("no such table") || lower.includes("does not exist")) && Array.from(SUBSCRIPTION_TABLES).some((table) => lower.includes(table));
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
//#endregion
|
|
3028
|
+
//#region src/services/entitlement-changes.ts
|
|
3029
|
+
var ENTITLEMENT_CHANGE_LISTENERS_SLOT_KEY = "@happyvertical/smrt-subscriptions:entitlement-change-listeners";
|
|
3030
|
+
function listenerSet() {
|
|
3031
|
+
const slot = globalThis;
|
|
3032
|
+
const key = Symbol.for(ENTITLEMENT_CHANGE_LISTENERS_SLOT_KEY);
|
|
3033
|
+
let set = slot[key];
|
|
3034
|
+
if (!set) {
|
|
3035
|
+
set = /* @__PURE__ */ new Set();
|
|
3036
|
+
slot[key] = set;
|
|
3037
|
+
}
|
|
3038
|
+
return set;
|
|
3039
|
+
}
|
|
3040
|
+
function registerEntitlementChangeListener(listener) {
|
|
3041
|
+
const set = listenerSet();
|
|
3042
|
+
set.add(listener);
|
|
3043
|
+
return () => {
|
|
3044
|
+
set.delete(listener);
|
|
3045
|
+
};
|
|
3046
|
+
}
|
|
3047
|
+
function getEntitlementChangeListeners() {
|
|
3048
|
+
return [...listenerSet()];
|
|
3049
|
+
}
|
|
3050
|
+
function emptyEntitlementSnapshot() {
|
|
3051
|
+
return {
|
|
3052
|
+
planId: null,
|
|
3053
|
+
planKey: null,
|
|
3054
|
+
featureKeys: [],
|
|
3055
|
+
grants: []
|
|
3056
|
+
};
|
|
3057
|
+
}
|
|
3058
|
+
function canonicalJson(value) {
|
|
3059
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
3060
|
+
if (value && typeof value === "object") return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(",")}}`;
|
|
3061
|
+
return JSON.stringify(value ?? null);
|
|
3062
|
+
}
|
|
3063
|
+
async function snapshotEntitlements(resolver, tenantId, options = {}) {
|
|
3064
|
+
try {
|
|
3065
|
+
const resolved = await resolver.resolveFeatureGrants({
|
|
3066
|
+
kind: "tenant",
|
|
3067
|
+
tenantId
|
|
3068
|
+
}, options.now ? { now: options.now } : {});
|
|
3069
|
+
const grants = (resolved.grants ?? []).filter((grant) => grant.enabled !== false).sort((a, b) => a.featureKey.localeCompare(b.featureKey));
|
|
3070
|
+
return {
|
|
3071
|
+
planId: resolved.planId,
|
|
3072
|
+
planKey: resolved.planKey,
|
|
3073
|
+
featureKeys: [...new Set(resolved.featureKeys)].sort(),
|
|
3074
|
+
grants
|
|
3075
|
+
};
|
|
3076
|
+
} catch (error) {
|
|
3077
|
+
if (isMissingSubscriptionTableError(error)) return emptyEntitlementSnapshot();
|
|
3078
|
+
throw error;
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
function diffEntitlements(tenantId, before, after) {
|
|
3082
|
+
const was = new Set(before.featureKeys);
|
|
3083
|
+
const now = new Set(after.featureKeys);
|
|
3084
|
+
const metadataOf = (snapshot, key) => canonicalJson(snapshot.grants.find((grant) => grant.featureKey === key)?.metadata ?? null);
|
|
3085
|
+
return {
|
|
3086
|
+
tenantId,
|
|
3087
|
+
gained: after.featureKeys.filter((key) => !was.has(key)),
|
|
3088
|
+
lost: before.featureKeys.filter((key) => !now.has(key)),
|
|
3089
|
+
changed: after.featureKeys.filter((key) => was.has(key) && metadataOf(before, key) !== metadataOf(after, key)),
|
|
3090
|
+
before,
|
|
3091
|
+
after
|
|
3092
|
+
};
|
|
3093
|
+
}
|
|
3094
|
+
function hasEntitlementChange(change) {
|
|
3095
|
+
return change.gained.length > 0 || change.lost.length > 0 || change.changed.length > 0;
|
|
3096
|
+
}
|
|
3097
|
+
async function notifyEntitlementChange(change, options = {}) {
|
|
3098
|
+
const failures = [];
|
|
3099
|
+
if (!hasEntitlementChange(change)) return {
|
|
3100
|
+
change,
|
|
3101
|
+
failures
|
|
3102
|
+
};
|
|
3103
|
+
for (const listener of options.listeners ?? getEntitlementChangeListeners()) try {
|
|
3104
|
+
await listener(change);
|
|
3105
|
+
} catch (error) {
|
|
3106
|
+
failures.push({ error });
|
|
3107
|
+
}
|
|
3108
|
+
return {
|
|
3109
|
+
change,
|
|
3110
|
+
failures
|
|
3111
|
+
};
|
|
3112
|
+
}
|
|
3113
|
+
async function trackEntitlementChange(options, apply) {
|
|
3114
|
+
const at = () => options.now ? { now: options.now() } : {};
|
|
3115
|
+
const before = await snapshotEntitlements(options.resolver, options.tenantId, at());
|
|
3116
|
+
const result = await apply();
|
|
3117
|
+
const after = await snapshotEntitlements(options.resolver, options.tenantId, at());
|
|
3118
|
+
return {
|
|
3119
|
+
...await notifyEntitlementChange(diffEntitlements(options.tenantId, before, after), options.listeners ? { listeners: options.listeners } : {}),
|
|
3120
|
+
result
|
|
3121
|
+
};
|
|
3122
|
+
}
|
|
3123
|
+
//#endregion
|
|
3124
|
+
//#region src/services/hosted-ai-spend.ts
|
|
3125
|
+
var AI_HOSTED_SPEND_METRIC = "ai.hosted.spend_micros";
|
|
3126
|
+
var AI_HOSTED_USER_SPEND_METRIC = "ai.hosted.user_spend_micros";
|
|
3127
|
+
var MICROS_PER_USD = 1e6;
|
|
3128
|
+
var ROLLING_WINDOW_MS = 720 * 60 * 60 * 1e3;
|
|
3129
|
+
var HostedAiSpendPolicyError = class extends Error {
|
|
3130
|
+
constructor(message) {
|
|
3131
|
+
super(message);
|
|
3132
|
+
this.name = "HostedAiSpendPolicyError";
|
|
3133
|
+
}
|
|
3134
|
+
};
|
|
3135
|
+
function rows(result) {
|
|
3136
|
+
return Array.isArray(result) ? result : result?.rows ?? [];
|
|
3137
|
+
}
|
|
3138
|
+
function numberOf(value) {
|
|
3139
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : 0;
|
|
3140
|
+
if (typeof value === "bigint") return Number(value);
|
|
3141
|
+
if (typeof value === "string") return Number.parseFloat(value) || 0;
|
|
3142
|
+
return 0;
|
|
3143
|
+
}
|
|
3144
|
+
function dateOf(value) {
|
|
3145
|
+
if (value === null || value === void 0) return null;
|
|
3146
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
3147
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
3148
|
+
}
|
|
3149
|
+
function hostedAiTagFragment(key, value) {
|
|
3150
|
+
return `${JSON.stringify(key)}:${JSON.stringify(value)}`;
|
|
3151
|
+
}
|
|
3152
|
+
function containsSql(db) {
|
|
3153
|
+
return usesPostgresDialect(db) ? "strpos(tags, ?) > 0" : "instr(tags, ?) > 0";
|
|
3154
|
+
}
|
|
3155
|
+
function scopeSql(db, { tenantId, userId, window }) {
|
|
3156
|
+
const contains = containsSql(db);
|
|
3157
|
+
const params = [
|
|
3158
|
+
tenantId,
|
|
3159
|
+
window.start.toISOString(),
|
|
3160
|
+
window.end.toISOString(),
|
|
3161
|
+
hostedAiTagFragment("source", "hosted")
|
|
3162
|
+
];
|
|
3163
|
+
let where = `tenant_id = ?
|
|
3164
|
+
AND created_at >= ?
|
|
3165
|
+
AND created_at < ?
|
|
3166
|
+
AND operation <> 'blocked'
|
|
3167
|
+
AND NOT (operation = 'external-agent' AND id LIKE 'external-agent:%')
|
|
3168
|
+
AND ${contains}`;
|
|
3169
|
+
if (userId !== void 0) {
|
|
3170
|
+
params.push(hostedAiTagFragment("userId", userId));
|
|
3171
|
+
where += `
|
|
3172
|
+
AND ${contains}`;
|
|
3173
|
+
}
|
|
3174
|
+
return {
|
|
3175
|
+
where,
|
|
3176
|
+
params
|
|
3177
|
+
};
|
|
3178
|
+
}
|
|
3179
|
+
function createHostedAiSpendReader(db) {
|
|
3180
|
+
return {
|
|
3181
|
+
async summarize(scope) {
|
|
3182
|
+
const { where, params } = scopeSql(db, scope);
|
|
3183
|
+
const row = rows(await db.query(`SELECT COALESCE(SUM(estimated_cost), 0) AS cost
|
|
3184
|
+
FROM _smrt_ai_usage
|
|
3185
|
+
WHERE ${where}`, ...params))[0] ?? {};
|
|
3186
|
+
return { spend: Math.round(numberOf(row.cost) * MICROS_PER_USD) };
|
|
3187
|
+
},
|
|
3188
|
+
async liftsAt({ cap, windowMs, ...scope }) {
|
|
3189
|
+
if (cap <= 0) return null;
|
|
3190
|
+
const { where, params } = scopeSql(db, scope);
|
|
3191
|
+
const at = dateOf(rows(await db.query(`SELECT created_at
|
|
3192
|
+
FROM (
|
|
3193
|
+
SELECT created_at, id,
|
|
3194
|
+
SUM(estimated_cost) OVER (
|
|
3195
|
+
ORDER BY created_at DESC, id DESC
|
|
3196
|
+
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
|
|
3197
|
+
) AS running
|
|
3198
|
+
FROM _smrt_ai_usage
|
|
3199
|
+
WHERE ${where}
|
|
3200
|
+
AND estimated_cost IS NOT NULL
|
|
3201
|
+
) counted
|
|
3202
|
+
WHERE running * ${MICROS_PER_USD} >= ?
|
|
3203
|
+
ORDER BY created_at DESC, id DESC
|
|
3204
|
+
LIMIT 1`, ...params, cap - .5))[0]?.created_at);
|
|
3205
|
+
return at ? new Date(at.getTime() + windowMs) : null;
|
|
3206
|
+
}
|
|
3207
|
+
};
|
|
3208
|
+
}
|
|
3209
|
+
function policyFor(threshold) {
|
|
3210
|
+
if (threshold.metricKey === "ai.hosted.spend_micros") return "tenant-cap";
|
|
3211
|
+
if (threshold.metricKey === "ai.hosted.user_spend_micros") return "user-cap";
|
|
3212
|
+
return null;
|
|
3213
|
+
}
|
|
3214
|
+
function hostedAiSpendThresholds(thresholds) {
|
|
3215
|
+
const result = [];
|
|
3216
|
+
for (const threshold of thresholds) {
|
|
3217
|
+
const policy = policyFor(threshold);
|
|
3218
|
+
if (!policy) continue;
|
|
3219
|
+
if (!isValidThreshold(threshold) || !Number.isSafeInteger(threshold.limit)) throw new HostedAiSpendPolicyError(`Plan threshold ${threshold.metricKey} is not a valid hosted AI cap (limit must be a non-negative integer of micro-dollars).`);
|
|
3220
|
+
result.push({
|
|
3221
|
+
policy,
|
|
3222
|
+
threshold
|
|
3223
|
+
});
|
|
3224
|
+
}
|
|
3225
|
+
return result;
|
|
3226
|
+
}
|
|
3227
|
+
function evaluateHostedAiSpendThreshold(policy, threshold, summary, window) {
|
|
3228
|
+
const cap = threshold.limit;
|
|
3229
|
+
const spend = summary.spend;
|
|
3230
|
+
const over = spend >= cap;
|
|
3231
|
+
const warningRatio = threshold.warningRatio ?? .8;
|
|
3232
|
+
const nearing = cap === 0 ? over : spend >= cap * warningRatio;
|
|
3233
|
+
let state = "ok";
|
|
3234
|
+
if (threshold.enforcement === "block" && over) state = "blocked";
|
|
3235
|
+
else if (threshold.enforcement !== "observe" && nearing) state = "warn";
|
|
3236
|
+
return {
|
|
3237
|
+
policy,
|
|
3238
|
+
threshold,
|
|
3239
|
+
cap,
|
|
3240
|
+
spend,
|
|
3241
|
+
window,
|
|
3242
|
+
resetsAt: threshold.window === "rolling" ? null : window.end,
|
|
3243
|
+
state
|
|
3244
|
+
};
|
|
3245
|
+
}
|
|
3246
|
+
function laterReset(a, b) {
|
|
3247
|
+
if (!a.resetsAt) return a;
|
|
3248
|
+
if (!b.resetsAt) return b;
|
|
3249
|
+
return b.resetsAt.getTime() > a.resetsAt.getTime() ? b : a;
|
|
3250
|
+
}
|
|
3251
|
+
function closerToCap(a, b) {
|
|
3252
|
+
const ratio = (e) => e.cap === 0 ? Number.POSITIVE_INFINITY : e.spend / e.cap;
|
|
3253
|
+
return ratio(b) > ratio(a) ? b : a;
|
|
3254
|
+
}
|
|
3255
|
+
function decideHostedAiSpend(evaluations, plan) {
|
|
3256
|
+
const blocked = evaluations.filter((e) => e.state === "blocked");
|
|
3257
|
+
const warned = evaluations.filter((e) => e.state === "warn");
|
|
3258
|
+
const decidedBy = blocked.length > 0 ? blocked.reduce(laterReset) : warned.length > 0 ? warned.reduce(closerToCap) : null;
|
|
3259
|
+
return {
|
|
3260
|
+
state: blocked.length > 0 ? "blocked" : warned.length > 0 ? "warn" : "ok",
|
|
3261
|
+
entitled: plan.entitled,
|
|
3262
|
+
planId: plan.planId,
|
|
3263
|
+
planKey: plan.planKey,
|
|
3264
|
+
decidedBy,
|
|
3265
|
+
evaluations
|
|
3266
|
+
};
|
|
3267
|
+
}
|
|
3268
|
+
var HostedAiSpendEvaluator = class HostedAiSpendEvaluator {
|
|
3269
|
+
constructor(options) {
|
|
3270
|
+
this.options = options;
|
|
3271
|
+
this.termsTtlMs = options.termsTtlMs ?? 3e4;
|
|
3272
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
3273
|
+
}
|
|
3274
|
+
options;
|
|
3275
|
+
terms = /* @__PURE__ */ new Map();
|
|
3276
|
+
termsTtlMs;
|
|
3277
|
+
now;
|
|
3278
|
+
/** Build the default resolver and `_smrt_ai_usage` reader over one db. */
|
|
3279
|
+
static async create(classOptions, options = {}) {
|
|
3280
|
+
return new HostedAiSpendEvaluator({
|
|
3281
|
+
...options,
|
|
3282
|
+
resolver: await SubscriptionResolver.create(classOptions),
|
|
3283
|
+
spend: createHostedAiSpendReader(classOptions.db)
|
|
3284
|
+
});
|
|
3285
|
+
}
|
|
3286
|
+
/** Drop memoized plan thresholds (all tenants, or one). */
|
|
3287
|
+
invalidate(tenantId) {
|
|
3288
|
+
if (tenantId === void 0) this.terms.clear();
|
|
3289
|
+
else this.terms.delete(tenantId);
|
|
3290
|
+
}
|
|
3291
|
+
planThresholds(tenantId, resolverOptions) {
|
|
3292
|
+
const at = Date.now();
|
|
3293
|
+
const cached = this.terms.get(tenantId);
|
|
3294
|
+
if (cached && this.termsTtlMs > 0 && at - cached.at < this.termsTtlMs) return cached.value;
|
|
3295
|
+
const value = this.options.resolver.resolvePlanThresholds({
|
|
3296
|
+
kind: "tenant",
|
|
3297
|
+
tenantId
|
|
3298
|
+
}, resolverOptions);
|
|
3299
|
+
if (this.termsTtlMs > 0) {
|
|
3300
|
+
this.terms.set(tenantId, {
|
|
3301
|
+
at,
|
|
3302
|
+
value
|
|
3303
|
+
});
|
|
3304
|
+
value.catch(() => {
|
|
3305
|
+
if (this.terms.get(tenantId)?.value === value) this.terms.delete(tenantId);
|
|
3306
|
+
});
|
|
3307
|
+
}
|
|
3308
|
+
return value;
|
|
3309
|
+
}
|
|
3310
|
+
/**
|
|
3311
|
+
* Evaluate the plan's hosted caps for `tenantId` and, when given, the
|
|
3312
|
+
* per-user caps for `userId`. Without a `userId` the per-user caps are
|
|
3313
|
+
* skipped (no user to meter: jobs, shared agent clients).
|
|
3314
|
+
*/
|
|
3315
|
+
async evaluate(input) {
|
|
3316
|
+
const now = this.now();
|
|
3317
|
+
const plan = await this.planThresholds(input.tenantId, {
|
|
3318
|
+
...input.resolverOptions ?? {},
|
|
3319
|
+
now
|
|
3320
|
+
});
|
|
3321
|
+
const caps = hostedAiSpendThresholds(plan.thresholds).filter(({ policy }) => policy === "tenant-cap" || input.userId !== void 0);
|
|
3322
|
+
return decideHostedAiSpend(await Promise.all(caps.map(async ({ policy, threshold }) => {
|
|
3323
|
+
const window = getWindowForThreshold(threshold.window, now);
|
|
3324
|
+
const scope = {
|
|
3325
|
+
tenantId: input.tenantId,
|
|
3326
|
+
...policy === "user-cap" ? { userId: input.userId } : {},
|
|
3327
|
+
window
|
|
3328
|
+
};
|
|
3329
|
+
const evaluation = evaluateHostedAiSpendThreshold(policy, threshold, await this.options.spend.summarize(scope), window);
|
|
3330
|
+
if (evaluation.state === "blocked" && threshold.window === "rolling" && this.options.spend.liftsAt) evaluation.resetsAt = await this.options.spend.liftsAt({
|
|
3331
|
+
...scope,
|
|
3332
|
+
cap: evaluation.cap,
|
|
3333
|
+
windowMs: ROLLING_WINDOW_MS
|
|
3334
|
+
});
|
|
3335
|
+
return evaluation;
|
|
3336
|
+
})), plan);
|
|
3337
|
+
}
|
|
3338
|
+
};
|
|
3339
|
+
//#endregion
|
|
3340
|
+
//#region src/services/reseller.ts
|
|
3341
|
+
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3342
|
+
function canonicalTenantId(id) {
|
|
3343
|
+
if (typeof id !== "string" || !UUID_PATTERN.test(id)) throw new ResellerBillingError("Tenant IDs must be UUIDs.", "INVALID_TENANT");
|
|
3344
|
+
return id.toLowerCase();
|
|
3345
|
+
}
|
|
3346
|
+
function assertCurrency(currency) {
|
|
3347
|
+
if (!isCurrencyCode(currency)) throw new ResellerBillingError(`Currency '${currency}' must be a three-letter upper-case code.`, "INVALID_CURRENCY");
|
|
3348
|
+
}
|
|
3349
|
+
function legView(priceBookId, currency) {
|
|
3350
|
+
return priceBookId ? {
|
|
3351
|
+
priceBookId: String(priceBookId),
|
|
3352
|
+
currency
|
|
3353
|
+
} : null;
|
|
3354
|
+
}
|
|
3355
|
+
function assignmentView(row) {
|
|
3356
|
+
return {
|
|
3357
|
+
childTenantId: tenantKey(row.childTenantId),
|
|
3358
|
+
resellerTenantId: tenantKey(row.resellerTenantId),
|
|
3359
|
+
wholesale: legView(row.wholesalePriceBookId, row.wholesaleCurrency),
|
|
3360
|
+
retail: legView(row.retailPriceBookId, row.retailCurrency)
|
|
3361
|
+
};
|
|
3362
|
+
}
|
|
3363
|
+
function authorized(operation) {
|
|
3364
|
+
return withSystemContext(operation);
|
|
3365
|
+
}
|
|
3366
|
+
var ResellerBillingService = class ResellerBillingService {
|
|
3367
|
+
constructor(options, books, assignments, rules, policies, evaluator) {
|
|
3368
|
+
this.options = options;
|
|
3369
|
+
this.books = books;
|
|
3370
|
+
this.assignments = assignments;
|
|
3371
|
+
this.rules = rules;
|
|
3372
|
+
this.policies = policies;
|
|
3373
|
+
this.evaluator = evaluator;
|
|
3374
|
+
}
|
|
3375
|
+
options;
|
|
3376
|
+
books;
|
|
3377
|
+
assignments;
|
|
3378
|
+
rules;
|
|
3379
|
+
policies;
|
|
3380
|
+
evaluator;
|
|
3381
|
+
static async create(options) {
|
|
3382
|
+
if (typeof options.billingRelationships?.getRelationship !== "function") throw new Error("Reseller billing requires a billingRelationships reader from smrt-tenancy.");
|
|
3383
|
+
const { billingRelationships: _reader, authorize: _authorize, ...rest } = options;
|
|
3384
|
+
const books = await PriceBookCollection.create(rest);
|
|
3385
|
+
const shared = {
|
|
3386
|
+
...rest,
|
|
3387
|
+
db: books.db
|
|
3388
|
+
};
|
|
3389
|
+
const policies = await SpendingPolicyCollection.create(shared);
|
|
3390
|
+
const evaluator = new SpendingPolicyEvaluator(policies, await ClientChargeCollection.create(shared), await BillingAdjustmentCollection.create(shared), {
|
|
3391
|
+
retailCharges: await RetailChargeCollection.create(shared),
|
|
3392
|
+
credits: await CreditGrantCollection.create(shared)
|
|
3393
|
+
});
|
|
3394
|
+
return new ResellerBillingService(options, books, await PriceBookAssignmentCollection.create(shared), await PricingRuleCollection.create(shared), policies, evaluator);
|
|
3395
|
+
}
|
|
3396
|
+
/**
|
|
3397
|
+
* Publish one price in a book, in one or more currencies. Each currency is
|
|
3398
|
+
* a `PricingRule` owned by the book's seller; re-defining the same rule key,
|
|
3399
|
+
* currency, and effective date replaces that rule's terms.
|
|
3400
|
+
*/
|
|
3401
|
+
async definePrice(input) {
|
|
3402
|
+
const book = await this.readBook(input.priceBookId);
|
|
3403
|
+
const sellerTenantId = canonicalTenantId(String(book.tenantId));
|
|
3404
|
+
await this.assertManage("define_prices", sellerTenantId, void 0, true);
|
|
3405
|
+
if (!input.ruleKey.trim() || !input.metricKey.trim()) throw new Error("Price book prices require a ruleKey and metricKey.");
|
|
3406
|
+
if (input.prices.length === 0) throw new ResellerBillingError("A price needs at least one currency.", "INVALID_CURRENCY");
|
|
3407
|
+
const currencies = /* @__PURE__ */ new Set();
|
|
3408
|
+
for (const { currency } of input.prices) {
|
|
3409
|
+
assertCurrency(currency);
|
|
3410
|
+
if (currencies.has(currency)) throw new ResellerBillingError(`Currency ${currency} is listed twice for one price.`, "INVALID_CURRENCY");
|
|
3411
|
+
currencies.add(currency);
|
|
3412
|
+
}
|
|
3413
|
+
const effectiveFrom = input.effectiveFrom ?? /* @__PURE__ */ new Date();
|
|
3414
|
+
return authorized(async () => {
|
|
3415
|
+
const saved = [];
|
|
3416
|
+
for (const { currency, terms } of input.prices) {
|
|
3417
|
+
const id = await deterministicUuid([
|
|
3418
|
+
"price-book-rule",
|
|
3419
|
+
String(book.id),
|
|
3420
|
+
input.ruleKey,
|
|
3421
|
+
input.metricKey,
|
|
3422
|
+
input.serviceKey ?? "",
|
|
3423
|
+
currency,
|
|
3424
|
+
effectiveFrom.toISOString()
|
|
3425
|
+
]);
|
|
3426
|
+
const values = {
|
|
3427
|
+
tenantId: book.tenantId,
|
|
3428
|
+
priceBookId: String(book.id),
|
|
3429
|
+
ruleKey: input.ruleKey,
|
|
3430
|
+
metricKey: input.metricKey,
|
|
3431
|
+
serviceKey: input.serviceKey ?? "",
|
|
3432
|
+
strategy: input.strategy,
|
|
3433
|
+
currency,
|
|
3434
|
+
effectiveFrom,
|
|
3435
|
+
effectiveTo: input.effectiveTo ?? null,
|
|
3436
|
+
priority: input.priority ?? 0,
|
|
3437
|
+
terms: JSON.stringify(terms),
|
|
3438
|
+
active: true
|
|
3439
|
+
};
|
|
3440
|
+
const existing = await this.rules.get(id);
|
|
3441
|
+
if (existing) {
|
|
3442
|
+
Object.assign(existing, values);
|
|
3443
|
+
await existing.save();
|
|
3444
|
+
saved.push(existing);
|
|
3445
|
+
} else saved.push(await this.rules.create({
|
|
3446
|
+
id,
|
|
3447
|
+
...values
|
|
3448
|
+
}));
|
|
3449
|
+
}
|
|
3450
|
+
return saved;
|
|
3451
|
+
});
|
|
3452
|
+
}
|
|
3453
|
+
/**
|
|
3454
|
+
* Select the wholesale and/or retail book that rates a child's usage under
|
|
3455
|
+
* its current reseller relationship. The retail book must be published by
|
|
3456
|
+
* that reseller; the wholesale book must be published by someone other
|
|
3457
|
+
* than the reseller or child it charges. Each leg is authorized separately:
|
|
3458
|
+
* the wholesale leg by its publisher (`assign_wholesale_price_book`), the
|
|
3459
|
+
* retail leg by the reseller (`assign_retail_price_book`).
|
|
3460
|
+
*/
|
|
3461
|
+
async assignPriceBooks(input) {
|
|
3462
|
+
const { childTenantId, resellerTenantId } = await this.requireRelationship(input.childTenantId);
|
|
3463
|
+
const existing = await authorized(() => this.assignments.get({ childTenantId }));
|
|
3464
|
+
const current = existing && tenantKey(existing.resellerTenantId) === resellerTenantId ? assignmentView(existing) : null;
|
|
3465
|
+
if (input.wholesale !== void 0) {
|
|
3466
|
+
let publisher = resellerTenantId;
|
|
3467
|
+
if (input.wholesale) {
|
|
3468
|
+
const book = await this.requireLeg(input.wholesale, "wholesale");
|
|
3469
|
+
assertWholesalePublisher(book, resellerTenantId, childTenantId);
|
|
3470
|
+
publisher = tenantKey(book.tenantId);
|
|
3471
|
+
} else if (current?.wholesale) publisher = tenantKey((await this.readBook(current.wholesale.priceBookId)).tenantId);
|
|
3472
|
+
await this.assertManage("assign_wholesale_price_book", publisher, childTenantId, false, resellerTenantId);
|
|
3473
|
+
}
|
|
3474
|
+
if (input.retail) {
|
|
3475
|
+
const book = await this.requireLeg(input.retail, "retail");
|
|
3476
|
+
if (tenantKey(book.tenantId) !== resellerTenantId) throw new ResellerBillingError(`Retail price book '${book.bookKey}' is not published by the child's reseller.`, "PRICE_BOOK_OWNER_MISMATCH");
|
|
3477
|
+
}
|
|
3478
|
+
if (input.retail !== void 0 || input.wholesale === void 0) await this.assertManage("assign_retail_price_book", resellerTenantId, childTenantId, false, resellerTenantId);
|
|
3479
|
+
const db = this.assignments.db;
|
|
3480
|
+
return authorized(() => withEmbeddedWriteTransaction(db, isEmbeddedDatabase(db), async (transaction) => {
|
|
3481
|
+
if (isPostgresDatabase(transaction)) await transaction.query("SELECT pg_advisory_xact_lock(hashtext('smrt-price-book-assignments'))");
|
|
3482
|
+
const assignments = await PriceBookAssignmentCollection.create({ db: transaction });
|
|
3483
|
+
const row = await assignments.get({ childTenantId });
|
|
3484
|
+
const fresh = row && tenantKey(row.resellerTenantId) === resellerTenantId ? assignmentView(row) : null;
|
|
3485
|
+
if (input.wholesale === null && fresh?.wholesale?.priceBookId !== current?.wholesale?.priceBookId) throw new ResellerBillingError("The wholesale assignment changed concurrently; retry.", "ASSIGNMENT_CONFLICT");
|
|
3486
|
+
const wholesale = input.wholesale === void 0 ? fresh?.wholesale ?? null : input.wholesale;
|
|
3487
|
+
const retail = input.retail === void 0 ? fresh?.retail ?? null : input.retail;
|
|
3488
|
+
const values = {
|
|
3489
|
+
childTenantId,
|
|
3490
|
+
resellerTenantId,
|
|
3491
|
+
wholesalePriceBookId: wholesale?.priceBookId ?? "",
|
|
3492
|
+
wholesaleCurrency: wholesale?.currency ?? "",
|
|
3493
|
+
retailPriceBookId: retail?.priceBookId ?? "",
|
|
3494
|
+
retailCurrency: retail?.currency ?? ""
|
|
3495
|
+
};
|
|
3496
|
+
if (row) {
|
|
3497
|
+
Object.assign(row, values);
|
|
3498
|
+
await row.save();
|
|
3499
|
+
return assignmentView(row);
|
|
3500
|
+
}
|
|
3501
|
+
return assignmentView(await assignments.create(values));
|
|
3502
|
+
}));
|
|
3503
|
+
}
|
|
3504
|
+
/** The child's assignment under its current reseller, if any. */
|
|
3505
|
+
async getPriceBookAssignment(childTenantId) {
|
|
3506
|
+
const relationship = await this.options.billingRelationships.getRelationship(canonicalTenantId(childTenantId));
|
|
3507
|
+
if (!relationship) return null;
|
|
3508
|
+
const row = await this.assignments.get({ childTenantId: relationship.childTenantId });
|
|
3509
|
+
if (!row || tenantKey(row.resellerTenantId) !== relationship.resellerTenantId) return null;
|
|
3510
|
+
return assignmentView(row);
|
|
3511
|
+
}
|
|
3512
|
+
/**
|
|
3513
|
+
* Create or replace a spending policy that a parent sets on its child. The
|
|
3514
|
+
* row belongs to the child (so the ordinary evaluator enforces it for the
|
|
3515
|
+
* child) and records the parent in `setByTenantId`, which locks it against
|
|
3516
|
+
* changes by the child. A delegated limit left by a former parent may be
|
|
3517
|
+
* replaced (not a former parent's prepaid balance, which keeps its credit
|
|
3518
|
+
* ledger); one the child set for itself may not. Use `period: 'balance'`
|
|
3519
|
+
* for a prepaid credit balance and fund it with {@link grantChildCredit}.
|
|
3520
|
+
*/
|
|
3521
|
+
async setDelegatedSpendingPolicy(input) {
|
|
3522
|
+
const parentTenantId = canonicalTenantId(input.parentTenantId);
|
|
3523
|
+
const relationship = await this.requireChildOf(input.childTenantId, parentTenantId);
|
|
3524
|
+
await this.assertManage("manage_child_spending", parentTenantId, relationship.childTenantId, false, relationship.resellerTenantId);
|
|
3525
|
+
assertCurrency(input.currency);
|
|
3526
|
+
if (input.limitAmount !== void 0 && !Number.isSafeInteger(input.limitAmount)) throw new ResellerBillingError(`Spending limits must be integer minor units \u2014 got ${input.limitAmount}.`, "INVALID_AMOUNT");
|
|
3527
|
+
const values = {
|
|
3528
|
+
tenantId: relationship.childTenantId,
|
|
3529
|
+
name: input.name,
|
|
3530
|
+
subscriberKind: input.subscriberKind ?? "",
|
|
3531
|
+
subscriberExternalId: input.subscriberExternalId ?? "",
|
|
3532
|
+
projectId: input.projectId ?? "",
|
|
3533
|
+
serviceKey: input.serviceKey ?? "",
|
|
3534
|
+
metricKey: input.metricKey ?? "",
|
|
3535
|
+
period: input.period ?? "month",
|
|
3536
|
+
rollingSeconds: input.rollingSeconds ?? 0,
|
|
3537
|
+
limitAmount: input.limitAmount ?? 0,
|
|
3538
|
+
currency: input.currency,
|
|
3539
|
+
behavior: input.behavior,
|
|
3540
|
+
priority: input.priority ?? 0,
|
|
3541
|
+
active: input.active ?? true,
|
|
3542
|
+
basis: input.basis,
|
|
3543
|
+
setByTenantId: parentTenantId,
|
|
3544
|
+
...input.balanceFrom ? { balanceFrom: input.balanceFrom } : {}
|
|
3545
|
+
};
|
|
3546
|
+
return authorized(async () => {
|
|
3547
|
+
const existing = (await this.policies.list({
|
|
3548
|
+
where: {
|
|
3549
|
+
tenantId: values.tenantId,
|
|
3550
|
+
subscriberKind: values.subscriberKind,
|
|
3551
|
+
subscriberExternalId: values.subscriberExternalId,
|
|
3552
|
+
projectId: values.projectId,
|
|
3553
|
+
serviceKey: values.serviceKey,
|
|
3554
|
+
metricKey: values.metricKey,
|
|
3555
|
+
period: values.period,
|
|
3556
|
+
name: values.name
|
|
3557
|
+
},
|
|
3558
|
+
limit: 1
|
|
3559
|
+
}))[0];
|
|
3560
|
+
if (existing) {
|
|
3561
|
+
const owner = tenantKey(existing.setByTenantId);
|
|
3562
|
+
if (!owner) throw new ResellerBillingError(`Spending policy '${input.name}' already exists for this child and was set by the child.`, "POLICY_CONFLICT");
|
|
3563
|
+
if (owner !== parentTenantId && existing.period === "balance") throw new ResellerBillingError(`Balance policy '${input.name}' belongs to a former parent; choose another name.`, "POLICY_CONFLICT");
|
|
3564
|
+
Object.assign(existing, values);
|
|
3565
|
+
await existing.save();
|
|
3566
|
+
return existing;
|
|
3567
|
+
}
|
|
3568
|
+
return this.policies.create(values);
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3571
|
+
/** Credit a prepaid balance policy the parent set on its child. */
|
|
3572
|
+
async grantChildCredit(input) {
|
|
3573
|
+
const parentTenantId = canonicalTenantId(input.parentTenantId);
|
|
3574
|
+
const relationship = await this.requireChildOf(input.childTenantId, parentTenantId);
|
|
3575
|
+
await this.assertManage("manage_child_spending", parentTenantId, relationship.childTenantId, false, relationship.resellerTenantId);
|
|
3576
|
+
return authorized(async () => {
|
|
3577
|
+
const policy = await this.policies.get(input.spendingPolicyId);
|
|
3578
|
+
if (!policy || tenantKey(policy.tenantId) !== relationship.childTenantId || tenantKey(policy.setByTenantId) !== parentTenantId) throw new ResellerBillingError(`Spending policy ${input.spendingPolicyId} is not a policy this parent set on the child.`, "POLICY_NOT_FOUND");
|
|
3579
|
+
return this.evaluator.grantCredit({
|
|
3580
|
+
spendingPolicyId: input.spendingPolicyId,
|
|
3581
|
+
amount: input.amount,
|
|
3582
|
+
reason: input.reason,
|
|
3583
|
+
source: input.source,
|
|
3584
|
+
sourceId: input.sourceId,
|
|
3585
|
+
grantedByTenantId: parentTenantId
|
|
3586
|
+
});
|
|
3587
|
+
});
|
|
3588
|
+
}
|
|
3589
|
+
async requireRelationship(childTenantId) {
|
|
3590
|
+
const relationship = await this.options.billingRelationships.getRelationship(canonicalTenantId(childTenantId));
|
|
3591
|
+
if (!relationship) throw new ResellerBillingError(`Tenant ${childTenantId} has no reseller relationship.`, "RELATIONSHIP_REQUIRED");
|
|
3592
|
+
return relationship;
|
|
3593
|
+
}
|
|
3594
|
+
async requireChildOf(childTenantId, parentTenantId) {
|
|
3595
|
+
const relationship = await this.requireRelationship(childTenantId);
|
|
3596
|
+
if (relationship.resellerTenantId !== parentTenantId) throw new ResellerBillingError(`Tenant ${childTenantId} is not a child of ${parentTenantId}.`, "RELATIONSHIP_REQUIRED");
|
|
3597
|
+
return relationship;
|
|
3598
|
+
}
|
|
3599
|
+
/**
|
|
3600
|
+
* Read a book's metadata to learn its publisher and kind before deciding
|
|
3601
|
+
* authorization. Books belong to their seller, so the read is not scoped to
|
|
3602
|
+
* the caller; nothing beyond a validation error is returned on denial.
|
|
3603
|
+
*/
|
|
3604
|
+
async readBook(id) {
|
|
3605
|
+
const book = await authorized(() => this.books.get(id));
|
|
3606
|
+
if (!book?.id) throw new ResellerBillingError(`Price book ${id} was not found.`, "PRICE_BOOK_NOT_FOUND");
|
|
3607
|
+
return book;
|
|
3608
|
+
}
|
|
3609
|
+
async requireLeg(leg, kind) {
|
|
3610
|
+
assertCurrency(leg.currency);
|
|
3611
|
+
const book = await this.readBook(leg.priceBookId);
|
|
3612
|
+
if (book.kind !== kind) throw new ResellerBillingError(`Price book '${book.bookKey}' is a ${book.kind} book, not ${kind}.`, "PRICE_BOOK_KIND_MISMATCH");
|
|
3613
|
+
return book;
|
|
3614
|
+
}
|
|
3615
|
+
async assertManage(action, tenantId, childTenantId, allowOwnTenant = false, resellerTenantId) {
|
|
3616
|
+
if (isSystemContext() || isSuperAdminBypass() || allowOwnTenant && getTenantId()?.toLowerCase() === tenantId || await this.options.authorize?.({
|
|
3617
|
+
action,
|
|
3618
|
+
tenantId,
|
|
3619
|
+
childTenantId,
|
|
3620
|
+
...resellerTenantId ? { resellerTenantId } : {}
|
|
3621
|
+
})) return;
|
|
3622
|
+
throw new TenantIsolationError("Reseller billing mutation denied.");
|
|
3623
|
+
}
|
|
3624
|
+
};
|
|
3140
3625
|
//#endregion
|
|
3141
|
-
export { BillingAdjustment, BillingAdjustmentCollection, ClientCharge, ClientChargeCollection, CommercialBillingStorageConfigurationError, CommercialUsageService, CreditGrant, CreditGrantCollection, PLAN_TERM_FIELDS, PriceBook, PriceBookAssignment, PriceBookCollection, PricingRule, PricingRuleCollection, ResellerBillingError, ResellerBillingService, RetailCharge, RetailChargeCollection, SUBSCRIPTIONS_MONEY_COLUMNS, SUBSCRIPTIONS_MONEY_MINOR_UNITS_BACKFILL, SpendingPolicy, SpendingPolicyCollection, SpendingPolicyEvaluator, SubscriptionPlan, SubscriptionPlanCollection, SubscriptionPlanVersion, SubscriptionPlanVersionCollection, SubscriptionPlansRecipe, SubscriptionResolver, TenantSubscription, TenantSubscriptionCollection, TenantUsageMeter, TenantUsageMetric, TenantUsageMetricCollection, UnsupportedCommercialBillingStorageError, assertCommercialBillingStorageSupported, assertSubscriberInvariant, enabledFeatureKeys, evaluateThreshold, evaluateThresholds, extractPlanTerms, getWindowForThreshold, getWindowKey, isCurrencyCode, isEntitlementUpgrade, isPriceBookKind, isValidThreshold, migrateSubscriptionPlanVersions, migrateSubscriptionsMoneyToMinorUnits, normalizeFeatureGrants, normalizeSubscriber, preflightSubscriptionsMoneyMinorUnits, samePlanTerms, subscriberToColumns, validThresholds };
|
|
3626
|
+
export { AI_HOSTED_SPEND_METRIC, AI_HOSTED_USER_SPEND_METRIC, BillingAdjustment, BillingAdjustmentCollection, ClientCharge, ClientChargeCollection, CommercialBillingStorageConfigurationError, CommercialUsageService, CreditGrant, CreditGrantCollection, ENTITLEMENT_CHANGE_LISTENERS_SLOT_KEY, FEATURE_GRANT_SOURCE_SLOT_KEY, HostedAiSpendEvaluator, HostedAiSpendPolicyError, MICROS_PER_USD, PLAN_TERM_FIELDS, PriceBook, PriceBookAssignment, PriceBookCollection, PricingRule, PricingRuleCollection, ResellerBillingError, ResellerBillingService, RetailCharge, RetailChargeCollection, SUBSCRIPTIONS_MONEY_COLUMNS, SUBSCRIPTIONS_MONEY_MINOR_UNITS_BACKFILL, SpendingPolicy, SpendingPolicyCollection, SpendingPolicyEvaluator, SubscriptionFeatureSource, SubscriptionPlan, SubscriptionPlanCollection, SubscriptionPlanVersion, SubscriptionPlanVersionCollection, SubscriptionPlansRecipe, SubscriptionResolver, TenantSubscription, TenantSubscriptionCollection, TenantUsageMeter, TenantUsageMetric, TenantUsageMetricCollection, UnsupportedCommercialBillingStorageError, assertCommercialBillingStorageSupported, assertSubscriberInvariant, createHostedAiSpendReader, decideHostedAiSpend, diffEntitlements, emptyEntitlementSnapshot, enabledFeatureKeys, evaluateHostedAiSpendThreshold, evaluateThreshold, evaluateThresholds, extractPlanTerms, getEntitlementChangeListeners, getWindowForThreshold, getWindowKey, hasEntitlementChange, hostedAiSpendThresholds, hostedAiTagFragment, isCurrencyCode, isEntitlementUpgrade, isMissingSubscriptionTableError, isPriceBookKind, isValidThreshold, migrateSubscriptionPlanVersions, migrateSubscriptionsMoneyToMinorUnits, normalizeFeatureGrants, normalizeSubscriber, notifyEntitlementChange, preflightSubscriptionsMoneyMinorUnits, registerEntitlementChangeListener, registerSubscriptionFeatureSource, samePlanTerms, snapshotEntitlements, subscriberToColumns, trackEntitlementChange, validThresholds };
|
|
3142
3627
|
|
|
3143
3628
|
//# sourceMappingURL=index.js.map
|