alepha 0.20.6 → 0.20.7

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.
Files changed (243) hide show
  1. package/AGENTS.md +0 -1
  2. package/CLAUDE.md +0 -1
  3. package/assets/agents-template.md +0 -1
  4. package/dist/api/audits/index.browser.js +1 -0
  5. package/dist/api/audits/index.browser.js.map +1 -1
  6. package/dist/api/audits/index.d.ts +370 -355
  7. package/dist/api/audits/index.d.ts.map +1 -1
  8. package/dist/api/audits/index.js +1 -0
  9. package/dist/api/audits/index.js.map +1 -1
  10. package/dist/api/files/index.browser.js +1 -0
  11. package/dist/api/files/index.browser.js.map +1 -1
  12. package/dist/api/files/index.d.ts +179 -170
  13. package/dist/api/files/index.d.ts.map +1 -1
  14. package/dist/api/files/index.js +1 -0
  15. package/dist/api/files/index.js.map +1 -1
  16. package/dist/api/jobs/index.browser.js +7 -0
  17. package/dist/api/jobs/index.browser.js.map +1 -1
  18. package/dist/api/jobs/index.d.ts +271 -262
  19. package/dist/api/jobs/index.d.ts.map +1 -1
  20. package/dist/api/jobs/index.js +21 -3
  21. package/dist/api/jobs/index.js.map +1 -1
  22. package/dist/api/keys/index.d.ts +198 -192
  23. package/dist/api/keys/index.d.ts.map +1 -1
  24. package/dist/api/keys/index.js +1 -0
  25. package/dist/api/keys/index.js.map +1 -1
  26. package/dist/api/notifications/index.d.ts +246 -245
  27. package/dist/api/notifications/index.d.ts.map +1 -1
  28. package/dist/api/organizations/index.d.ts +100 -97
  29. package/dist/api/organizations/index.d.ts.map +1 -1
  30. package/dist/api/parameters/index.d.ts +323 -320
  31. package/dist/api/parameters/index.d.ts.map +1 -1
  32. package/dist/api/payments/index.d.ts +431 -376
  33. package/dist/api/payments/index.d.ts.map +1 -1
  34. package/dist/api/payments/index.js +202 -87
  35. package/dist/api/payments/index.js.map +1 -1
  36. package/dist/api/subscriptions/index.d.ts +1695 -0
  37. package/dist/api/subscriptions/index.d.ts.map +1 -0
  38. package/dist/api/subscriptions/index.js +1919 -0
  39. package/dist/api/subscriptions/index.js.map +1 -0
  40. package/dist/api/users/index.d.ts +863 -847
  41. package/dist/api/users/index.d.ts.map +1 -1
  42. package/dist/api/verifications/index.d.ts +126 -125
  43. package/dist/api/verifications/index.d.ts.map +1 -1
  44. package/dist/bucket/index.d.ts +3 -2
  45. package/dist/bucket/index.d.ts.map +1 -1
  46. package/dist/cache/core/index.d.ts +114 -4
  47. package/dist/cache/core/index.d.ts.map +1 -1
  48. package/dist/cache/core/index.js +181 -15
  49. package/dist/cache/core/index.js.map +1 -1
  50. package/dist/cache/core/index.workerd.js +181 -15
  51. package/dist/cache/core/index.workerd.js.map +1 -1
  52. package/dist/cache/database/index.d.ts +20 -19
  53. package/dist/cache/database/index.d.ts.map +1 -1
  54. package/dist/cache/redis/index.d.ts +3 -2
  55. package/dist/cache/redis/index.d.ts.map +1 -1
  56. package/dist/cli/core/index.d.ts +113 -129
  57. package/dist/cli/core/index.d.ts.map +1 -1
  58. package/dist/cli/core/index.js +75 -7
  59. package/dist/cli/core/index.js.map +1 -1
  60. package/dist/cli/devtools/index.d.ts +3 -2
  61. package/dist/cli/devtools/index.d.ts.map +1 -1
  62. package/dist/cli/platform/index.d.ts +346 -290
  63. package/dist/cli/platform/index.d.ts.map +1 -1
  64. package/dist/cli/platform/index.js +105 -6
  65. package/dist/cli/platform/index.js.map +1 -1
  66. package/dist/cli/vendor/index.d.ts +12 -11
  67. package/dist/cli/vendor/index.d.ts.map +1 -1
  68. package/dist/command/index.d.ts +5 -4
  69. package/dist/command/index.d.ts.map +1 -1
  70. package/dist/core/index.browser.js +1 -1
  71. package/dist/core/index.browser.js.map +1 -1
  72. package/dist/core/index.d.ts +119 -118
  73. package/dist/core/index.d.ts.map +1 -1
  74. package/dist/core/index.js +1 -1
  75. package/dist/core/index.js.map +1 -1
  76. package/dist/core/index.native.js +1 -1
  77. package/dist/core/index.native.js.map +1 -1
  78. package/dist/core/index.workerd.js +1 -1
  79. package/dist/core/index.workerd.js.map +1 -1
  80. package/dist/crypto/index.d.ts +3 -2
  81. package/dist/crypto/index.d.ts.map +1 -1
  82. package/dist/email/core/index.d.ts +3 -2
  83. package/dist/email/core/index.d.ts.map +1 -1
  84. package/dist/email/smtp/index.d.ts +7 -6
  85. package/dist/email/smtp/index.d.ts.map +1 -1
  86. package/dist/lock/core/index.d.ts +5 -4
  87. package/dist/lock/core/index.d.ts.map +1 -1
  88. package/dist/logger/index.d.ts +10 -9
  89. package/dist/logger/index.d.ts.map +1 -1
  90. package/dist/mcp/index.d.ts +9 -8
  91. package/dist/mcp/index.d.ts.map +1 -1
  92. package/dist/mcp/index.js +1 -1
  93. package/dist/mcp/index.js.map +1 -1
  94. package/dist/orm/core/index.browser.js +9 -3
  95. package/dist/orm/core/index.browser.js.map +1 -1
  96. package/dist/orm/core/index.bun.js +31 -10
  97. package/dist/orm/core/index.bun.js.map +1 -1
  98. package/dist/orm/core/index.d.ts +33 -14
  99. package/dist/orm/core/index.d.ts.map +1 -1
  100. package/dist/orm/core/index.js +31 -10
  101. package/dist/orm/core/index.js.map +1 -1
  102. package/dist/orm/postgres/index.d.ts +6 -5
  103. package/dist/orm/postgres/index.d.ts.map +1 -1
  104. package/dist/queue/core/index.d.ts +5 -4
  105. package/dist/queue/core/index.d.ts.map +1 -1
  106. package/dist/queue/redis/index.d.ts +3 -2
  107. package/dist/queue/redis/index.d.ts.map +1 -1
  108. package/dist/react/form/index.d.ts +5 -0
  109. package/dist/react/form/index.d.ts.map +1 -1
  110. package/dist/react/form/index.js +6 -4
  111. package/dist/react/form/index.js.map +1 -1
  112. package/dist/react/i18n/index.d.ts +2 -1
  113. package/dist/react/i18n/index.d.ts.map +1 -1
  114. package/dist/react/router/index.d.ts +206 -205
  115. package/dist/react/router/index.d.ts.map +1 -1
  116. package/dist/react/ui/index.d.ts +11 -11
  117. package/dist/react/ui/index.d.ts.map +1 -1
  118. package/dist/scheduler/index.d.ts +3 -2
  119. package/dist/scheduler/index.d.ts.map +1 -1
  120. package/dist/security/index.browser.js +29 -1
  121. package/dist/security/index.browser.js.map +1 -1
  122. package/dist/security/index.d.ts +82 -35
  123. package/dist/security/index.d.ts.map +1 -1
  124. package/dist/security/index.js +56 -3
  125. package/dist/security/index.js.map +1 -1
  126. package/dist/server/auth/index.d.ts +163 -158
  127. package/dist/server/auth/index.d.ts.map +1 -1
  128. package/dist/server/auth/index.js +16 -4
  129. package/dist/server/auth/index.js.map +1 -1
  130. package/dist/server/core/index.d.ts +35 -34
  131. package/dist/server/core/index.d.ts.map +1 -1
  132. package/dist/server/cors/index.d.ts +7 -6
  133. package/dist/server/cors/index.d.ts.map +1 -1
  134. package/dist/server/health/index.d.ts +16 -15
  135. package/dist/server/health/index.d.ts.map +1 -1
  136. package/dist/server/links/index.d.ts +51 -50
  137. package/dist/server/links/index.d.ts.map +1 -1
  138. package/dist/server/rate-limit/index.d.ts +6 -5
  139. package/dist/server/rate-limit/index.d.ts.map +1 -1
  140. package/dist/server/swagger/index.d.ts +2 -1
  141. package/dist/server/swagger/index.d.ts.map +1 -1
  142. package/dist/topic/redis/index.d.ts +3 -2
  143. package/dist/topic/redis/index.d.ts.map +1 -1
  144. package/package.json +16 -32
  145. package/src/api/audits/entities/audits.ts +1 -0
  146. package/src/api/files/entities/files.ts +1 -0
  147. package/src/api/jobs/__tests__/$job.spec.ts +92 -40
  148. package/src/api/jobs/entities/jobExecutionEntity.ts +1 -0
  149. package/src/api/jobs/providers/JobProvider.ts +20 -5
  150. package/src/api/jobs/schemas/jobConfigAtom.ts +5 -0
  151. package/src/api/keys/entities/apiKeyEntity.ts +1 -0
  152. package/src/api/payments/controllers/MockCheckoutController.ts +146 -0
  153. package/src/api/payments/index.ts +3 -0
  154. package/src/api/payments/providers/MemoryPaymentProvider.ts +9 -4
  155. package/src/api/payments/providers/PaymentProvider.ts +25 -9
  156. package/src/api/payments/services/PaymentService.ts +3 -0
  157. package/src/api/subscriptions/__tests__/BillingService.spec.ts +218 -0
  158. package/src/api/subscriptions/__tests__/SubscriptionService.spec.ts +278 -0
  159. package/src/api/subscriptions/controllers/AdminSubscriptionController.ts +212 -0
  160. package/src/api/subscriptions/controllers/SubscriptionController.ts +189 -0
  161. package/src/api/subscriptions/entities/subscriptionEvents.ts +54 -0
  162. package/src/api/subscriptions/entities/subscriptions.ts +68 -0
  163. package/src/api/subscriptions/index.ts +133 -0
  164. package/src/api/subscriptions/jobs/SubscriptionJobs.ts +382 -0
  165. package/src/api/subscriptions/middleware/$requireLimit.ts +50 -0
  166. package/src/api/subscriptions/middleware/$requirePlan.ts +49 -0
  167. package/src/api/subscriptions/notifications/SubscriptionNotifications.ts +110 -0
  168. package/src/api/subscriptions/schemas/cancelSubscriptionSchema.ts +8 -0
  169. package/src/api/subscriptions/schemas/changePlanSchema.ts +9 -0
  170. package/src/api/subscriptions/schemas/createSubscriptionSchema.ts +11 -0
  171. package/src/api/subscriptions/schemas/entitlementsSchema.ts +21 -0
  172. package/src/api/subscriptions/schemas/mrrSchema.ts +13 -0
  173. package/src/api/subscriptions/schemas/planDefinitionSchema.ts +71 -0
  174. package/src/api/subscriptions/schemas/planResourceSchema.ts +25 -0
  175. package/src/api/subscriptions/schemas/subscriptionEventResourceSchema.ts +8 -0
  176. package/src/api/subscriptions/schemas/subscriptionQuerySchema.ts +19 -0
  177. package/src/api/subscriptions/schemas/subscriptionResourceSchema.ts +6 -0
  178. package/src/api/subscriptions/schemas/subscriptionSettingsSchema.ts +32 -0
  179. package/src/api/subscriptions/schemas/subscriptionStatsSchema.ts +23 -0
  180. package/src/api/subscriptions/services/BillingService.ts +437 -0
  181. package/src/api/subscriptions/services/SubscriptionConfig.ts +56 -0
  182. package/src/api/subscriptions/services/SubscriptionService.ts +867 -0
  183. package/src/api/subscriptions/services/UsageService.ts +118 -0
  184. package/src/cache/core/__tests__/$cache.memory.spec.ts +450 -0
  185. package/src/cache/core/__tests__/$cache.swr.spec.ts +394 -0
  186. package/src/cache/core/index.ts +16 -0
  187. package/src/cache/core/primitives/$cache.ts +347 -21
  188. package/src/cli/core/tasks/BuildCloudflareTask.ts +16 -0
  189. package/src/cli/core/templates/agentMd.ts +39 -4
  190. package/src/cli/core/templates/biomeJson.ts +25 -1
  191. package/src/cli/core/templates/saasAdminLayoutTsx.ts +2 -2
  192. package/src/cli/platform/__tests__/CloudflareAdapter.spec.ts +117 -0
  193. package/src/cli/platform/adapters/CloudflareAdapter.ts +104 -7
  194. package/src/cli/platform/atoms/platformOptions.ts +13 -0
  195. package/src/cli/platform/schemas/platform.ts +1 -0
  196. package/src/cli/platform/services/CloudflareApi.ts +61 -0
  197. package/src/cli/platform/services/PlatformOrchestrator.ts +9 -4
  198. package/src/core/__tests__/$module.spec.ts +2 -2
  199. package/src/core/primitives/$module.ts +4 -4
  200. package/src/mcp/providers/McpServerProvider.ts +1 -1
  201. package/src/orm/core/providers/DatabaseTypeProvider.ts +9 -3
  202. package/src/orm/core/providers/drivers/DatabaseProvider.ts +1 -1
  203. package/src/orm/core/schemas/insertSchema.ts +10 -2
  204. package/src/orm/core/services/Repository.ts +27 -7
  205. package/src/react/form/hooks/useFormState.ts +8 -1
  206. package/src/react/form/index.ts +10 -1
  207. package/src/react/form/services/FormModel.ts +9 -3
  208. package/src/security/atoms/currentTenantAtom.ts +34 -0
  209. package/src/security/index.browser.ts +1 -0
  210. package/src/security/index.ts +12 -1
  211. package/src/security/primitives/$issuer.ts +17 -1
  212. package/src/security/providers/SecurityProvider.ts +37 -0
  213. package/src/server/auth/__tests__/validateRedirectUri.spec.ts +78 -0
  214. package/src/server/auth/providers/ServerAuthProvider.ts +21 -5
  215. package/tsconfig.base.json +2 -1
  216. package/dist/react/websocket/index.d.ts +0 -117
  217. package/dist/react/websocket/index.d.ts.map +0 -1
  218. package/dist/react/websocket/index.js +0 -108
  219. package/dist/react/websocket/index.js.map +0 -1
  220. package/dist/websocket/index.browser.js +0 -848
  221. package/dist/websocket/index.browser.js.map +0 -1
  222. package/dist/websocket/index.d.ts +0 -876
  223. package/dist/websocket/index.d.ts.map +0 -1
  224. package/dist/websocket/index.js +0 -1185
  225. package/dist/websocket/index.js.map +0 -1
  226. package/src/react/websocket/hooks/useRoom.tsx +0 -251
  227. package/src/react/websocket/index.ts +0 -7
  228. package/src/websocket/__tests__/$channel.spec.ts +0 -30
  229. package/src/websocket/__tests__/$websocket-new.spec.ts +0 -195
  230. package/src/websocket/__tests__/RoomManager.spec.ts +0 -146
  231. package/src/websocket/__tests__/websocket-integration.spec.ts +0 -951
  232. package/src/websocket/errors/WebSocketError.ts +0 -34
  233. package/src/websocket/index.browser.ts +0 -25
  234. package/src/websocket/index.shared.ts +0 -8
  235. package/src/websocket/index.ts +0 -85
  236. package/src/websocket/interfaces/WebSocketInterfaces.ts +0 -252
  237. package/src/websocket/primitives/$channel.ts +0 -131
  238. package/src/websocket/primitives/$websocket.ts +0 -107
  239. package/src/websocket/providers/NodeWebSocketServerProvider.ts +0 -617
  240. package/src/websocket/providers/WebSocketServerProvider.ts +0 -56
  241. package/src/websocket/services/RoomManager.ts +0 -160
  242. package/src/websocket/services/WebSocketClient.ts +0 -642
  243. package/src/websocket/services/WebSocketTopicService.ts +0 -108
@@ -0,0 +1,1695 @@
1
+ import * as _$alepha from "alepha";
2
+ import { Alepha, Middleware, Static, TNull, TObject, TOptional, TSchema, TUnion } from "alepha";
3
+ import * as _$alepha_server0 from "alepha/server";
4
+ import * as _$alepha_orm0 from "alepha/orm";
5
+ import { Page } from "alepha/orm";
6
+ import * as _$alepha_api_parameters0 from "alepha/api/parameters";
7
+ import { DateTimeProvider } from "alepha/datetime";
8
+ import * as _$alepha_logger0 from "alepha/logger";
9
+ import * as _$alepha_api_jobs0 from "alepha/api/jobs";
10
+ import { PaymentService } from "alepha/api/payments";
11
+ import * as _$alepha_api_notifications0 from "alepha/api/notifications";
12
+ import { CacheProvider } from "alepha/cache";
13
+ import * as _$typebox from "typebox";
14
+ import { BuildExtraConfigColumns, SQL } from "drizzle-orm";
15
+ import { PgColumnBuilderBase, PgSequenceOptions, PgTableExtraConfigValue, UpdateDeleteAction } from "drizzle-orm/pg-core";
16
+ //#region ../../src/orm/core/schemas/insertSchema.d.ts
17
+ /**
18
+ * Transforms a TObject schema for insert operations.
19
+ * All default properties at the root level are made optional.
20
+ * Generated columns are excluded entirely.
21
+ *
22
+ * @example
23
+ * Before: { name: string; age: number(default=0); fullName: generated }
24
+ * After: { name: string; age?: number; }
25
+ */
26
+ type TObjectInsert<T extends TObject> = TObject<{ [K in keyof T["properties"] as T["properties"][K] extends {
27
+ [PG_GENERATED]: any;
28
+ } ? never : K]: T["properties"][K] extends {
29
+ [PG_DEFAULT]: any;
30
+ } | {
31
+ [PG_ORGANIZATION]: any;
32
+ } | {
33
+ "~optional": true;
34
+ } ? TOptional<T["properties"][K]> : T["properties"][K] }>;
35
+ //#endregion
36
+ //#region ../../src/orm/core/schemas/updateSchema.d.ts
37
+ /**
38
+ * Transforms a TObject schema for update operations.
39
+ * All optional properties at the root level are made nullable (i.e., `T | null`).
40
+ * Generated columns are excluded entirely.
41
+ *
42
+ * @example
43
+ * Before: { name?: string; age: number; fullName: generated }
44
+ * After: { name?: string | null; age: number; }
45
+ */
46
+ type TObjectUpdate<T extends TObject> = TObject<{ [K in keyof T["properties"] as T["properties"][K] extends {
47
+ [PG_GENERATED]: any;
48
+ } ? never : K]: T["properties"][K] extends TOptional<infer U> ? TOptional<TUnion<[U, TNull]>> : T["properties"][K] }>;
49
+ //#endregion
50
+ //#region ../../src/orm/core/primitives/$entity.d.ts
51
+ interface EntityPrimitiveOptions<T extends TObject, Keys = keyof Static<T>> {
52
+ /**
53
+ * The database table name that will be created for this entity.
54
+ * If not provided, name will be inferred from the $repository variable name.
55
+ */
56
+ name: string;
57
+ /**
58
+ * TypeBox schema defining the table structure and column types.
59
+ */
60
+ schema: T;
61
+ /**
62
+ * Database indexes to create for query optimization.
63
+ */
64
+ indexes?: (Keys | {
65
+ /**
66
+ * Single column to index.
67
+ */
68
+ column: Keys;
69
+ /**
70
+ * Whether this should be a unique index (enforces uniqueness constraint).
71
+ */
72
+ unique?: boolean;
73
+ /**
74
+ * Custom name for the index. If not provided, generates name automatically.
75
+ */
76
+ name?: string;
77
+ /**
78
+ * Partial index condition. Only rows matching this SQL expression are indexed.
79
+ */
80
+ where?: SQL;
81
+ } | {
82
+ /**
83
+ * Multiple columns for composite index (order matters for query optimization).
84
+ */
85
+ columns: Keys[];
86
+ /**
87
+ * Whether this should be a unique index (enforces uniqueness constraint).
88
+ */
89
+ unique?: boolean;
90
+ /**
91
+ * Custom name for the index. If not provided, generates name automatically.
92
+ */
93
+ name?: string;
94
+ /**
95
+ * Partial index condition. Only rows matching this SQL expression are indexed.
96
+ */
97
+ where?: SQL;
98
+ } | {
99
+ /**
100
+ * SQL expressions for expression-based indexes.
101
+ *
102
+ * Can include column references and SQL functions like `LOWER()`, `UPPER()`, etc.
103
+ * Columns and expressions can be mixed together.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * // Case-insensitive unique username per realm
108
+ * indexes: [{
109
+ * expressions: (self) => [self.realm, sql`LOWER(${self.username})`],
110
+ * unique: true,
111
+ * name: "users_realm_username_lower_idx",
112
+ * }]
113
+ * ```
114
+ */
115
+ expressions: (self: Record<Keys & string, any>) => (SQL | any)[];
116
+ /**
117
+ * Whether this should be a unique index (enforces uniqueness constraint).
118
+ */
119
+ unique?: boolean;
120
+ /**
121
+ * Custom name for the index. If not provided, generates name automatically.
122
+ */
123
+ name: string;
124
+ /**
125
+ * Partial index condition. Only rows matching this SQL expression are indexed.
126
+ */
127
+ where?: SQL;
128
+ })[];
129
+ /**
130
+ * Foreign key constraints to maintain referential integrity.
131
+ */
132
+ foreignKeys?: Array<{
133
+ /**
134
+ * Optional name for the foreign key constraint.
135
+ */
136
+ name?: string;
137
+ /**
138
+ * Local columns that reference the foreign table.
139
+ */
140
+ columns: Array<keyof Static<T>>;
141
+ /**
142
+ * Referenced columns in the foreign table.
143
+ * Must be EntityColumn references from other entities.
144
+ */
145
+ foreignColumns: Array<() => EntityColumn<any>>;
146
+ }>;
147
+ /**
148
+ * Additional table constraints for data validation.
149
+ *
150
+ * Constraints enforce business rules at the database level, providing
151
+ * an additional layer of data integrity beyond application validation.
152
+ *
153
+ * **Constraint Types**:
154
+ * - **Unique constraints**: Prevent duplicate values across columns
155
+ * - **Check constraints**: Enforce custom validation rules with SQL expressions
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * constraints: [
160
+ * {
161
+ * name: "unique_user_email",
162
+ * columns: ["email"],
163
+ * unique: true
164
+ * },
165
+ * {
166
+ * name: "valid_age_range",
167
+ * columns: ["age"],
168
+ * check: sql`age >= 0 AND age <= 150`
169
+ * },
170
+ * {
171
+ * name: "unique_user_username_per_tenant",
172
+ * columns: ["tenantId", "username"],
173
+ * unique: true
174
+ * }
175
+ * ]
176
+ * ```
177
+ */
178
+ constraints?: Array<{
179
+ /**
180
+ * Columns involved in this constraint.
181
+ */
182
+ columns: Array<keyof Static<T>>;
183
+ /**
184
+ * Optional name for the constraint.
185
+ */
186
+ name?: string;
187
+ /**
188
+ * Whether this is a unique constraint.
189
+ */
190
+ unique?: boolean | {};
191
+ /**
192
+ * SQL expression for check constraint validation.
193
+ */
194
+ check?: SQL;
195
+ }>;
196
+ /**
197
+ * Advanced Drizzle ORM configuration for complex table setups.
198
+ */
199
+ config?: (self: BuildExtraConfigColumns<string, FromSchema<T>, "pg">) => PgTableExtraConfigValue[];
200
+ }
201
+ declare class EntityPrimitive<T extends TObject = TObject> {
202
+ readonly options: EntityPrimitiveOptions<T>;
203
+ constructor(options: EntityPrimitiveOptions<T>);
204
+ alias(alias: string): this;
205
+ get cols(): EntityColumns<T>;
206
+ get name(): string;
207
+ get schema(): T;
208
+ get insertSchema(): TObjectInsert<T>;
209
+ get updateSchema(): TObjectUpdate<T>;
210
+ }
211
+ /**
212
+ * Convert a schema to columns.
213
+ */
214
+ type FromSchema<T extends TObject> = { [key in keyof T["properties"]]: PgColumnBuilderBase };
215
+ type EntityColumn<T extends TObject> = {
216
+ name: string;
217
+ entity: EntityPrimitive<T>;
218
+ };
219
+ type EntityColumns<T extends TObject> = { [key in keyof T["properties"]]: EntityColumn<T> };
220
+ //#endregion
221
+ //#region ../../src/orm/core/constants/PG_SYMBOLS.d.ts
222
+ declare const PG_DEFAULT: unique symbol;
223
+ declare const PG_PRIMARY_KEY: unique symbol;
224
+ declare const PG_CREATED_AT: unique symbol;
225
+ declare const PG_UPDATED_AT: unique symbol;
226
+ declare const PG_DELETED_AT: unique symbol;
227
+ declare const PG_VERSION: unique symbol;
228
+ declare const PG_IDENTITY: unique symbol;
229
+ declare const PG_ENUM: unique symbol;
230
+ declare const PG_REF: unique symbol;
231
+ declare const PG_GENERATED: unique symbol;
232
+ declare const PG_ORGANIZATION: unique symbol;
233
+ /**
234
+ * @deprecated Use `PG_IDENTITY` instead.
235
+ */
236
+ declare const PG_SERIAL: unique symbol;
237
+ type PgSymbols = {
238
+ [PG_DEFAULT]: {};
239
+ [PG_PRIMARY_KEY]: {};
240
+ [PG_CREATED_AT]: {};
241
+ [PG_UPDATED_AT]: {};
242
+ [PG_DELETED_AT]: {};
243
+ [PG_VERSION]: {};
244
+ [PG_IDENTITY]: PgIdentityOptions;
245
+ [PG_REF]: PgRefOptions;
246
+ [PG_ENUM]: PgEnumOptions;
247
+ [PG_GENERATED]: PgGeneratedOptions;
248
+ [PG_ORGANIZATION]: {};
249
+ /**
250
+ * @deprecated Use `PG_IDENTITY` instead.
251
+ */
252
+ [PG_SERIAL]: {};
253
+ };
254
+ type PgSymbolKeys = keyof PgSymbols;
255
+ type PgIdentityOptions = {
256
+ mode: "always" | "byDefault";
257
+ } & PgSequenceOptions & {
258
+ name?: string;
259
+ };
260
+ interface PgEnumOptions {
261
+ name?: string;
262
+ description?: string;
263
+ }
264
+ interface PgGeneratedOptions {
265
+ /**
266
+ * SQL expression for the generated column.
267
+ */
268
+ expression: SQL;
269
+ /**
270
+ * Storage mode for the generated column.
271
+ * - `"stored"` — value is computed on write and stored on disk (default for PostgreSQL).
272
+ * - `"virtual"` — value is computed on read (default for SQLite).
273
+ */
274
+ mode?: "stored" | "virtual";
275
+ }
276
+ interface PgRefOptions {
277
+ ref: () => {
278
+ name: string;
279
+ entity: EntityPrimitive;
280
+ };
281
+ actions?: {
282
+ onUpdate?: UpdateDeleteAction;
283
+ onDelete?: UpdateDeleteAction;
284
+ };
285
+ }
286
+ //#endregion
287
+ //#region ../../src/orm/core/helpers/pgAttr.d.ts
288
+ /**
289
+ * Type representation.
290
+ */
291
+ type PgAttr<T extends TSchema, TAttr extends PgSymbolKeys> = T & { [K in TAttr]: PgSymbols[K] };
292
+ //#endregion
293
+ //#region ../../src/orm/core/schemas/databaseEnvSchema.d.ts
294
+ /**
295
+ * Base database environment schema.
296
+ *
297
+ * Defines the `DATABASE_URL` connection string used by all ORM providers
298
+ * to determine the database driver and connection target.
299
+ *
300
+ * Supported URL formats:
301
+ * - `sqlite://:memory:` or `sqlite://./path/to/db` — SQLite (Node.js or Bun)
302
+ * - `postgres://user:password@host:port/database` — PostgreSQL (Node.js or Bun)
303
+ * - `pglite://:memory:` or `pglite://./path` — PGlite (embedded Postgres)
304
+ * - `d1://BINDING_NAME` — Cloudflare D1
305
+ * - `hyperdrive://BINDING_NAME` — Cloudflare Hyperdrive
306
+ */
307
+ declare const databaseEnvSchema: _$typebox.TObject<{
308
+ DATABASE_URL: _$typebox.TOptional<_$typebox.TString>;
309
+ /**
310
+ * Enable or disable push-based schema synchronization (drizzle-kit push).
311
+ *
312
+ * Defaults to `true` in development and test, `false` in production.
313
+ * Set to `false` in development to skip automatic schema sync
314
+ * (e.g. when managing migrations manually).
315
+ */
316
+ DATABASE_SYNC: _$typebox.TOptional<_$typebox.TBoolean>;
317
+ }>;
318
+ declare module "alepha" {
319
+ interface Env extends Partial<Static<typeof databaseEnvSchema>> {}
320
+ } //# sourceMappingURL=databaseEnvSchema.d.ts.map
321
+ //#endregion
322
+ //#region ../../src/api/subscriptions/schemas/planDefinitionSchema.d.ts
323
+ declare const planDefinitionSchema: _$typebox.TObject<{
324
+ /**
325
+ * Unique plan identifier (e.g., "free", "starter", "pro", "enterprise").
326
+ */
327
+ id: _$typebox.TString;
328
+ /**
329
+ * Display name (e.g., "Pro Plan").
330
+ */
331
+ name: _$typebox.TString;
332
+ /**
333
+ * Optional description.
334
+ */
335
+ description: _$typebox.TOptional<_$typebox.TString>;
336
+ /**
337
+ * Whether this plan is available for new subscriptions.
338
+ */
339
+ available: _$typebox.TBoolean;
340
+ /**
341
+ * Pricing per billing interval.
342
+ * Multiple entries for monthly/yearly.
343
+ */
344
+ pricing: _$typebox.TArray<_$typebox.TObject<{
345
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
346
+ amount: _$typebox.TInteger;
347
+ currency: _$typebox.TString;
348
+ }>>;
349
+ /**
350
+ * Trial configuration for this plan.
351
+ * Overrides global settings.trialDays if set.
352
+ */
353
+ trial: _$typebox.TOptional<_$typebox.TObject<{
354
+ days: _$typebox.TInteger;
355
+ requirePaymentMethod: _$typebox.TBoolean;
356
+ }>>;
357
+ /**
358
+ * Feature entitlements. Boolean flags for feature access.
359
+ * Checked via SubscriptionService.can("feature-name").
360
+ */
361
+ features: _$typebox.TArray<_$typebox.TString>;
362
+ /**
363
+ * Usage limits. Numeric caps on resources.
364
+ * Checked via SubscriptionService.limit("resource-name").
365
+ * -1 = unlimited.
366
+ */
367
+ limits: _$typebox.TRecord<"^.*$", _$typebox.TInteger>;
368
+ /**
369
+ * Sort order for display (lower = first).
370
+ */
371
+ order: _$typebox.TInteger;
372
+ /**
373
+ * Metadata for app-specific plan data.
374
+ */
375
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
376
+ }>;
377
+ type PlanDefinition = Static<typeof planDefinitionSchema>;
378
+ //#endregion
379
+ //#region ../../src/api/subscriptions/schemas/subscriptionSettingsSchema.d.ts
380
+ declare const subscriptionSettingsSchema: _$typebox.TObject<{
381
+ /**
382
+ * Default trial days (overridden per-plan if plan.trial.days is set).
383
+ */
384
+ trialDays: _$typebox.TInteger;
385
+ /**
386
+ * Days after payment failure before suspension.
387
+ * During grace period, subscription remains active but flagged.
388
+ */
389
+ gracePeriodDays: _$typebox.TInteger;
390
+ /**
391
+ * Days after first payment failure to retry, relative to the failure date.
392
+ * e.g., [1, 3, 5, 7] means retry on day 1, 3, 5, 7 after failure.
393
+ */
394
+ dunningSchedule: _$typebox.TArray<_$typebox.TInteger>;
395
+ /**
396
+ * When user cancels, wait until period end (true) or cancel immediately (false).
397
+ */
398
+ cancelAtPeriodEnd: _$typebox.TBoolean;
399
+ /**
400
+ * Prorate charges when changing plans mid-cycle.
401
+ */
402
+ prorateOnChange: _$typebox.TBoolean;
403
+ }>;
404
+ type SubscriptionSettings = Static<typeof subscriptionSettingsSchema>;
405
+ //#endregion
406
+ //#region ../../src/api/subscriptions/services/SubscriptionConfig.d.ts
407
+ declare class SubscriptionConfig {
408
+ protected readonly plans: _$alepha_api_parameters0.ParameterPrimitive<_$typebox.TObject<{
409
+ plans: _$typebox.TArray<_$typebox.TObject<{
410
+ id: _$typebox.TString;
411
+ name: _$typebox.TString;
412
+ description: _$typebox.TOptional<_$typebox.TString>;
413
+ available: _$typebox.TBoolean;
414
+ pricing: _$typebox.TArray<_$typebox.TObject<{
415
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
416
+ amount: _$typebox.TInteger;
417
+ currency: _$typebox.TString;
418
+ }>>;
419
+ trial: _$typebox.TOptional<_$typebox.TObject<{
420
+ days: _$typebox.TInteger;
421
+ requirePaymentMethod: _$typebox.TBoolean;
422
+ }>>;
423
+ features: _$typebox.TArray<_$typebox.TString>;
424
+ limits: _$typebox.TRecord<"^.*$", _$typebox.TInteger>;
425
+ order: _$typebox.TInteger;
426
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
427
+ }>>;
428
+ }>>;
429
+ protected readonly settings: _$alepha_api_parameters0.ParameterPrimitive<_$typebox.TObject<{
430
+ trialDays: _$typebox.TInteger;
431
+ gracePeriodDays: _$typebox.TInteger;
432
+ dunningSchedule: _$typebox.TArray<_$typebox.TInteger>;
433
+ cancelAtPeriodEnd: _$typebox.TBoolean;
434
+ prorateOnChange: _$typebox.TBoolean;
435
+ }>>;
436
+ getPlans(): Promise<PlanDefinition[]>;
437
+ getSettings(): Promise<SubscriptionSettings>;
438
+ getPlan(planId: string): Promise<PlanDefinition>;
439
+ getPlanPricing(planId: string, interval: "monthly" | "yearly"): Promise<{
440
+ interval: "monthly" | "yearly";
441
+ amount: number;
442
+ currency: string;
443
+ }>;
444
+ }
445
+ //#endregion
446
+ //#region ../../src/api/subscriptions/entities/subscriptionEvents.d.ts
447
+ declare const subscriptionEvents: _$alepha_orm0.EntityPrimitive<_$typebox.TObject<{
448
+ id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
449
+ createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
450
+ subscriptionId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_REF>;
451
+ organizationId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_ORGANIZATION>;
452
+ type: _$typebox.TUnsafe<"past_due" | "suspended" | "cancelled" | "expired" | "created" | "trial_started" | "trial_ended" | "activated" | "renewed" | "payment_failed" | "payment_retried" | "reactivated" | "plan_changed" | "plan_change_scheduled" | "resumed">;
453
+ previousStatus: _$typebox.TOptional<_$typebox.TString>;
454
+ newStatus: _$typebox.TOptional<_$typebox.TString>;
455
+ previousPlanId: _$typebox.TOptional<_$typebox.TString>;
456
+ newPlanId: _$typebox.TOptional<_$typebox.TString>;
457
+ paymentIntentId: _$typebox.TOptional<_$typebox.TString>;
458
+ amount: _$typebox.TOptional<_$typebox.TInteger>;
459
+ currency: _$typebox.TOptional<_$typebox.TString>;
460
+ triggeredBy: _$typebox.TOptional<_$typebox.TString>;
461
+ userId: _$typebox.TOptional<_$typebox.TString>;
462
+ note: _$typebox.TOptional<_$typebox.TString>;
463
+ }>>;
464
+ type SubscriptionEventEntity = Static<typeof subscriptionEvents.schema>;
465
+ //#endregion
466
+ //#region ../../src/api/subscriptions/entities/subscriptions.d.ts
467
+ declare const subscriptions: _$alepha_orm0.EntityPrimitive<_$typebox.TObject<{
468
+ id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
469
+ version: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_VERSION>, typeof _$alepha_orm0.PG_DEFAULT>;
470
+ createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
471
+ updatedAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_UPDATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
472
+ organizationId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_ORGANIZATION>;
473
+ planId: _$typebox.TString;
474
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
475
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
476
+ currentPeriodStart: _$typebox.TString;
477
+ currentPeriodEnd: _$typebox.TString;
478
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
479
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
480
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
481
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
482
+ cancelAtPeriodEnd: _$typebox.TBoolean;
483
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
484
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
485
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
486
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
487
+ dunningAttempt: _$typebox.TInteger;
488
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
489
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
490
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
491
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
492
+ }>>;
493
+ type SubscriptionEntity = Static<typeof subscriptions.schema>;
494
+ //#endregion
495
+ //#region ../../src/api/subscriptions/schemas/entitlementsSchema.d.ts
496
+ declare const entitlementsSchema: _$typebox.TObject<{
497
+ planId: _$typebox.TString;
498
+ planName: _$typebox.TString;
499
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
500
+ features: _$typebox.TArray<_$typebox.TString>;
501
+ limits: _$typebox.TRecord<"^.*$", _$typebox.TInteger>;
502
+ trialEndsAt: _$typebox.TOptional<_$typebox.TString>;
503
+ periodEndsAt: _$typebox.TString;
504
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
505
+ }>;
506
+ type Entitlements = Static<typeof entitlementsSchema>;
507
+ //#endregion
508
+ //#region ../../src/api/subscriptions/schemas/subscriptionQuerySchema.d.ts
509
+ declare const subscriptionQuerySchema: _$typebox.TObject<{
510
+ page: _$typebox.TOptional<_$typebox.TInteger>;
511
+ size: _$typebox.TOptional<_$typebox.TInteger>;
512
+ sort: _$typebox.TOptional<_$typebox.TString>;
513
+ status: _$typebox.TOptional<_$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">>;
514
+ planId: _$typebox.TOptional<_$typebox.TString>;
515
+ organizationId: _$typebox.TOptional<_$typebox.TString>;
516
+ }>;
517
+ type SubscriptionQuery = Static<typeof subscriptionQuerySchema>;
518
+ //#endregion
519
+ //#region ../../src/api/subscriptions/schemas/subscriptionStatsSchema.d.ts
520
+ declare const subscriptionStatsSchema: _$typebox.TObject<{
521
+ total: _$typebox.TInteger;
522
+ trialing: _$typebox.TInteger;
523
+ active: _$typebox.TInteger;
524
+ pastDue: _$typebox.TInteger;
525
+ suspended: _$typebox.TInteger;
526
+ cancelled: _$typebox.TInteger;
527
+ expired: _$typebox.TInteger;
528
+ trialConversionRate: _$typebox.TNumber;
529
+ churnRate: _$typebox.TNumber;
530
+ byPlan: _$typebox.TRecord<"^.*$", _$typebox.TObject<{
531
+ active: _$typebox.TInteger;
532
+ trialing: _$typebox.TInteger;
533
+ total: _$typebox.TInteger;
534
+ }>>;
535
+ }>;
536
+ type SubscriptionStats = Static<typeof subscriptionStatsSchema>;
537
+ //#endregion
538
+ //#region ../../src/api/subscriptions/services/SubscriptionService.d.ts
539
+ interface SubscribeOptions {
540
+ /**
541
+ * Override plan/global trial days.
542
+ */
543
+ trialDays?: number;
544
+ /**
545
+ * Go straight to active (requires payment).
546
+ */
547
+ skipTrial?: boolean;
548
+ /**
549
+ * Metadata to attach to the subscription.
550
+ */
551
+ metadata?: Record<string, unknown>;
552
+ }
553
+ interface CancelOptions {
554
+ /**
555
+ * Cancellation reason.
556
+ */
557
+ reason?: string;
558
+ /**
559
+ * Cancel immediately instead of at period end.
560
+ */
561
+ immediate?: boolean;
562
+ /**
563
+ * User who initiated the cancellation.
564
+ */
565
+ cancelledBy?: string;
566
+ }
567
+ interface ChangePlanOptions {
568
+ /**
569
+ * Apply now (with proration) or at period end.
570
+ */
571
+ immediate?: boolean;
572
+ /**
573
+ * Override settings.prorateOnChange.
574
+ */
575
+ prorate?: boolean;
576
+ }
577
+ interface EventContext$2 {
578
+ previousStatus?: string;
579
+ newStatus?: string;
580
+ previousPlanId?: string;
581
+ newPlanId?: string;
582
+ paymentIntentId?: string;
583
+ amount?: number;
584
+ currency?: string;
585
+ triggeredBy?: string;
586
+ userId?: string;
587
+ note?: string;
588
+ }
589
+ declare class SubscriptionService {
590
+ protected readonly alepha: Alepha;
591
+ protected readonly log: _$alepha_logger0.Logger;
592
+ protected readonly dateTime: DateTimeProvider;
593
+ protected readonly subscriptionRepo: _$alepha_orm0.Repository<_$typebox.TObject<{
594
+ id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
595
+ version: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_VERSION>, typeof _$alepha_orm0.PG_DEFAULT>;
596
+ createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
597
+ updatedAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_UPDATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
598
+ organizationId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_ORGANIZATION>;
599
+ planId: _$typebox.TString;
600
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
601
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
602
+ currentPeriodStart: _$typebox.TString;
603
+ currentPeriodEnd: _$typebox.TString;
604
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
605
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
606
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
607
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
608
+ cancelAtPeriodEnd: _$typebox.TBoolean;
609
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
610
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
611
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
612
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
613
+ dunningAttempt: _$typebox.TInteger;
614
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
615
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
616
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
617
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
618
+ }>>;
619
+ protected readonly eventRepo: _$alepha_orm0.Repository<_$typebox.TObject<{
620
+ id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
621
+ createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
622
+ subscriptionId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_REF>;
623
+ organizationId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_ORGANIZATION>;
624
+ type: _$typebox.TUnsafe<"past_due" | "suspended" | "cancelled" | "expired" | "created" | "trial_started" | "trial_ended" | "activated" | "renewed" | "payment_failed" | "payment_retried" | "reactivated" | "plan_changed" | "plan_change_scheduled" | "resumed">;
625
+ previousStatus: _$typebox.TOptional<_$typebox.TString>;
626
+ newStatus: _$typebox.TOptional<_$typebox.TString>;
627
+ previousPlanId: _$typebox.TOptional<_$typebox.TString>;
628
+ newPlanId: _$typebox.TOptional<_$typebox.TString>;
629
+ paymentIntentId: _$typebox.TOptional<_$typebox.TString>;
630
+ amount: _$typebox.TOptional<_$typebox.TInteger>;
631
+ currency: _$typebox.TOptional<_$typebox.TString>;
632
+ triggeredBy: _$typebox.TOptional<_$typebox.TString>;
633
+ userId: _$typebox.TOptional<_$typebox.TString>;
634
+ note: _$typebox.TOptional<_$typebox.TString>;
635
+ }>>;
636
+ protected readonly config: SubscriptionConfig;
637
+ /**
638
+ * Find a subscription by organization ID.
639
+ * Returns null if no subscription exists.
640
+ */
641
+ getByOrganization(organizationId: string): Promise<SubscriptionEntity | null>;
642
+ /**
643
+ * Get a subscription by ID. Throws NotFoundError if not found.
644
+ */
645
+ getSubscription(id: string): Promise<SubscriptionEntity>;
646
+ /**
647
+ * Returns true if the subscription currently grants access.
648
+ * Accessible statuses: trialing, active, past_due (grace period),
649
+ * or cancelled with cancelAtPeriodEnd before period end.
650
+ */
651
+ isAccessible(sub: SubscriptionEntity): boolean;
652
+ /**
653
+ * Record a subscription event in the event log.
654
+ */
655
+ recordEvent(subscriptionId: string, organizationId: string, type: SubscriptionEventEntity["type"], context?: EventContext$2): Promise<void>;
656
+ /**
657
+ * Compute the end of a billing interval from a start date.
658
+ */
659
+ computeIntervalEnd(start: string, interval: "monthly" | "yearly"): string;
660
+ /**
661
+ * Create a new subscription for an organization.
662
+ */
663
+ subscribe(organizationId: string, planId: string, interval: "monthly" | "yearly", options?: SubscribeOptions): Promise<SubscriptionEntity>;
664
+ /**
665
+ * Cancel a subscription.
666
+ * If immediate, the subscription expires right away.
667
+ * If at period end, the subscription remains accessible until the period ends.
668
+ */
669
+ cancel(subscriptionId: string, options?: CancelOptions): Promise<void>;
670
+ /**
671
+ * Resume a cancelled subscription before its period ends.
672
+ * Only valid for subscriptions cancelled with cancelAtPeriodEnd.
673
+ */
674
+ resume(subscriptionId: string): Promise<void>;
675
+ /**
676
+ * Change the plan of a subscription.
677
+ * If immediate, proration is calculated and the plan changes now.
678
+ * If at period end, the change is scheduled for the next renewal.
679
+ * Returns the net proration amount (positive = charge, negative = credit).
680
+ */
681
+ changePlan(subscriptionId: string, newPlanId: string, newInterval?: "monthly" | "yearly", options?: ChangePlanOptions): Promise<number>;
682
+ /**
683
+ * Reactivate a suspended subscription (admin action).
684
+ * Resets dunning state and starts a new billing period.
685
+ */
686
+ reactivate(subscriptionId: string): Promise<void>;
687
+ /**
688
+ * Extend the trial period of a trialing subscription.
689
+ */
690
+ extendTrial(subscriptionId: string, days: number): Promise<void>;
691
+ /**
692
+ * Check if an organization has access to a specific feature.
693
+ */
694
+ can(organizationId: string, feature: string): Promise<boolean>;
695
+ /**
696
+ * Get the usage limit for a resource.
697
+ * Returns -1 for unlimited, 0 for no access.
698
+ */
699
+ limit(organizationId: string, resource: string): Promise<number>;
700
+ /**
701
+ * Get the full entitlements snapshot for an organization.
702
+ */
703
+ getEntitlements(organizationId: string): Promise<Entitlements>;
704
+ /**
705
+ * Find subscriptions with pagination and filtering.
706
+ */
707
+ findSubscriptions(query?: SubscriptionQuery): Promise<Page<SubscriptionEntity>>;
708
+ /**
709
+ * Get the event history for a subscription, ordered by most recent first.
710
+ */
711
+ getHistory(subscriptionId: string): Promise<SubscriptionEventEntity[]>;
712
+ /**
713
+ * Get aggregated subscription statistics.
714
+ */
715
+ getStats(): Promise<SubscriptionStats>;
716
+ /**
717
+ * Get revenue data from recent subscription events.
718
+ * Sums amounts from renewed and activated events within the specified window.
719
+ */
720
+ getRevenue(days?: number): Promise<{
721
+ total: number;
722
+ count: number;
723
+ }>;
724
+ /**
725
+ * Calculate proration for a mid-cycle plan change.
726
+ * Returns the net amount: positive = charge, negative = credit.
727
+ */
728
+ protected calculateProration(sub: SubscriptionEntity, newPlanId: string, newInterval: "monthly" | "yearly"): Promise<number>;
729
+ }
730
+ //#endregion
731
+ //#region ../../src/api/subscriptions/controllers/AdminSubscriptionController.d.ts
732
+ declare class AdminSubscriptionController {
733
+ protected readonly url = "/subscriptions";
734
+ protected readonly group = "admin:subscriptions";
735
+ protected readonly service: SubscriptionService;
736
+ protected readonly config: SubscriptionConfig;
737
+ /**
738
+ * Find subscriptions with pagination and filtering.
739
+ */
740
+ readonly findSubscriptions: _$alepha_server0.ActionPrimitiveFn<{
741
+ query: _$typebox.TObject<{
742
+ page: _$typebox.TOptional<_$typebox.TInteger>;
743
+ size: _$typebox.TOptional<_$typebox.TInteger>;
744
+ sort: _$typebox.TOptional<_$typebox.TString>;
745
+ status: _$typebox.TOptional<_$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">>;
746
+ planId: _$typebox.TOptional<_$typebox.TString>;
747
+ organizationId: _$typebox.TOptional<_$typebox.TString>;
748
+ }>;
749
+ response: _$alepha.TPage<_$typebox.TObject<{
750
+ id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
751
+ version: PgAttr<PgAttr<_$typebox.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
752
+ createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
753
+ updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
754
+ organizationId: PgAttr<_$typebox.TString, typeof PG_ORGANIZATION>;
755
+ planId: _$typebox.TString;
756
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
757
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
758
+ currentPeriodStart: _$typebox.TString;
759
+ currentPeriodEnd: _$typebox.TString;
760
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
761
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
762
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
763
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
764
+ cancelAtPeriodEnd: _$typebox.TBoolean;
765
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
766
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
767
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
768
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
769
+ dunningAttempt: _$typebox.TInteger;
770
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
771
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
772
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
773
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
774
+ }>>;
775
+ }>;
776
+ /**
777
+ * Get a subscription by ID.
778
+ */
779
+ readonly getSubscription: _$alepha_server0.ActionPrimitiveFn<{
780
+ params: _$typebox.TObject<{
781
+ id: _$typebox.TString;
782
+ }>;
783
+ response: _$typebox.TObject<{
784
+ id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
785
+ version: PgAttr<PgAttr<_$typebox.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
786
+ createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
787
+ updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
788
+ organizationId: PgAttr<_$typebox.TString, typeof PG_ORGANIZATION>;
789
+ planId: _$typebox.TString;
790
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
791
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
792
+ currentPeriodStart: _$typebox.TString;
793
+ currentPeriodEnd: _$typebox.TString;
794
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
795
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
796
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
797
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
798
+ cancelAtPeriodEnd: _$typebox.TBoolean;
799
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
800
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
801
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
802
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
803
+ dunningAttempt: _$typebox.TInteger;
804
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
805
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
806
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
807
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
808
+ }>;
809
+ }>;
810
+ /**
811
+ * Get aggregated subscription statistics.
812
+ */
813
+ readonly getStats: _$alepha_server0.ActionPrimitiveFn<{
814
+ response: _$typebox.TObject<{
815
+ total: _$typebox.TInteger;
816
+ trialing: _$typebox.TInteger;
817
+ active: _$typebox.TInteger;
818
+ pastDue: _$typebox.TInteger;
819
+ suspended: _$typebox.TInteger;
820
+ cancelled: _$typebox.TInteger;
821
+ expired: _$typebox.TInteger;
822
+ trialConversionRate: _$typebox.TNumber;
823
+ churnRate: _$typebox.TNumber;
824
+ byPlan: _$typebox.TRecord<"^.*$", _$typebox.TObject<{
825
+ active: _$typebox.TInteger;
826
+ trialing: _$typebox.TInteger;
827
+ total: _$typebox.TInteger;
828
+ }>>;
829
+ }>;
830
+ }>;
831
+ /**
832
+ * Get revenue data from recent subscription events.
833
+ */
834
+ readonly getRevenue: _$alepha_server0.ActionPrimitiveFn<{
835
+ query: _$typebox.TObject<{
836
+ days: _$typebox.TOptional<_$typebox.TInteger>;
837
+ }>;
838
+ response: _$typebox.TObject<{
839
+ total: _$typebox.TInteger;
840
+ count: _$typebox.TInteger;
841
+ }>;
842
+ }>;
843
+ /**
844
+ * Get Monthly Recurring Revenue breakdown.
845
+ */
846
+ readonly getMrr: _$alepha_server0.ActionPrimitiveFn<{
847
+ response: _$typebox.TObject<{
848
+ total: _$typebox.TInteger;
849
+ byPlan: _$typebox.TRecord<"^.*$", _$typebox.TInteger>;
850
+ growth: _$typebox.TInteger;
851
+ newMrr: _$typebox.TInteger;
852
+ expansionMrr: _$typebox.TInteger;
853
+ contractionMrr: _$typebox.TInteger;
854
+ churnMrr: _$typebox.TInteger;
855
+ }>;
856
+ }>;
857
+ /**
858
+ * Force a plan change for a subscription (admin action).
859
+ */
860
+ readonly adminChangePlan: _$alepha_server0.ActionPrimitiveFn<{
861
+ params: _$typebox.TObject<{
862
+ id: _$typebox.TString;
863
+ }>;
864
+ body: _$typebox.TObject<{
865
+ planId: _$typebox.TString;
866
+ interval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
867
+ immediate: _$typebox.TOptional<_$typebox.TBoolean>;
868
+ }>;
869
+ response: _$typebox.TObject<{
870
+ id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
871
+ version: PgAttr<PgAttr<_$typebox.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
872
+ createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
873
+ updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
874
+ organizationId: PgAttr<_$typebox.TString, typeof PG_ORGANIZATION>;
875
+ planId: _$typebox.TString;
876
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
877
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
878
+ currentPeriodStart: _$typebox.TString;
879
+ currentPeriodEnd: _$typebox.TString;
880
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
881
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
882
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
883
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
884
+ cancelAtPeriodEnd: _$typebox.TBoolean;
885
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
886
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
887
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
888
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
889
+ dunningAttempt: _$typebox.TInteger;
890
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
891
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
892
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
893
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
894
+ }>;
895
+ }>;
896
+ /**
897
+ * Force cancel a subscription (admin action).
898
+ */
899
+ readonly adminCancel: _$alepha_server0.ActionPrimitiveFn<{
900
+ params: _$typebox.TObject<{
901
+ id: _$typebox.TString;
902
+ }>;
903
+ body: _$typebox.TObject<{
904
+ reason: _$typebox.TOptional<_$typebox.TString>;
905
+ immediate: _$typebox.TOptional<_$typebox.TBoolean>;
906
+ }>;
907
+ response: _$typebox.TObject<{
908
+ ok: _$typebox.TBoolean;
909
+ id: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TString, _$typebox.TInteger]>>;
910
+ count: _$typebox.TOptional<_$typebox.TNumber>;
911
+ }>;
912
+ }>;
913
+ /**
914
+ * Reactivate a suspended subscription (admin action).
915
+ */
916
+ readonly adminReactivate: _$alepha_server0.ActionPrimitiveFn<{
917
+ params: _$typebox.TObject<{
918
+ id: _$typebox.TString;
919
+ }>;
920
+ response: _$typebox.TObject<{
921
+ ok: _$typebox.TBoolean;
922
+ id: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TString, _$typebox.TInteger]>>;
923
+ count: _$typebox.TOptional<_$typebox.TNumber>;
924
+ }>;
925
+ }>;
926
+ /**
927
+ * Extend the trial period for a trialing subscription (admin action).
928
+ */
929
+ readonly adminExtendTrial: _$alepha_server0.ActionPrimitiveFn<{
930
+ params: _$typebox.TObject<{
931
+ id: _$typebox.TString;
932
+ }>;
933
+ body: _$typebox.TObject<{
934
+ days: _$typebox.TInteger;
935
+ }>;
936
+ response: _$typebox.TObject<{
937
+ ok: _$typebox.TBoolean;
938
+ id: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TString, _$typebox.TInteger]>>;
939
+ count: _$typebox.TOptional<_$typebox.TNumber>;
940
+ }>;
941
+ }>;
942
+ }
943
+ //#endregion
944
+ //#region ../../src/api/subscriptions/controllers/SubscriptionController.d.ts
945
+ declare class SubscriptionController {
946
+ protected readonly url = "/subscriptions";
947
+ protected readonly group = "subscriptions";
948
+ protected readonly service: SubscriptionService;
949
+ protected readonly config: SubscriptionConfig;
950
+ /**
951
+ * List available subscription plans with pricing.
952
+ */
953
+ readonly getPlans: _$alepha_server0.ActionPrimitiveFn<{
954
+ response: _$typebox.TArray<_$typebox.TObject<{
955
+ id: _$typebox.TString;
956
+ name: _$typebox.TString;
957
+ description: _$typebox.TOptional<_$typebox.TString>;
958
+ pricing: _$typebox.TArray<_$typebox.TObject<{
959
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
960
+ amount: _$typebox.TInteger;
961
+ currency: _$typebox.TString;
962
+ }>>;
963
+ features: _$typebox.TArray<_$typebox.TString>;
964
+ limits: _$typebox.TRecord<"^.*$", _$typebox.TInteger>;
965
+ trial: _$typebox.TOptional<_$typebox.TObject<{
966
+ days: _$typebox.TInteger;
967
+ requirePaymentMethod: _$typebox.TBoolean;
968
+ }>>;
969
+ order: _$typebox.TInteger;
970
+ }>>;
971
+ }>;
972
+ /**
973
+ * Get the current organization's subscription.
974
+ */
975
+ readonly getMySubscription: _$alepha_server0.ActionPrimitiveFn<{
976
+ response: _$typebox.TObject<{
977
+ id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
978
+ version: PgAttr<PgAttr<_$typebox.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
979
+ createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
980
+ updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
981
+ organizationId: PgAttr<_$typebox.TString, typeof PG_ORGANIZATION>;
982
+ planId: _$typebox.TString;
983
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
984
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
985
+ currentPeriodStart: _$typebox.TString;
986
+ currentPeriodEnd: _$typebox.TString;
987
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
988
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
989
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
990
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
991
+ cancelAtPeriodEnd: _$typebox.TBoolean;
992
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
993
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
994
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
995
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
996
+ dunningAttempt: _$typebox.TInteger;
997
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
998
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
999
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
1000
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
1001
+ }>;
1002
+ }>;
1003
+ /**
1004
+ * Create a new subscription for the current organization.
1005
+ */
1006
+ readonly subscribe: _$alepha_server0.ActionPrimitiveFn<{
1007
+ body: _$typebox.TObject<{
1008
+ planId: _$typebox.TString;
1009
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
1010
+ paymentMethodId: _$typebox.TOptional<_$typebox.TString>;
1011
+ skipTrial: _$typebox.TOptional<_$typebox.TBoolean>;
1012
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
1013
+ }>;
1014
+ response: _$typebox.TObject<{
1015
+ id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
1016
+ version: PgAttr<PgAttr<_$typebox.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
1017
+ createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1018
+ updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1019
+ organizationId: PgAttr<_$typebox.TString, typeof PG_ORGANIZATION>;
1020
+ planId: _$typebox.TString;
1021
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
1022
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
1023
+ currentPeriodStart: _$typebox.TString;
1024
+ currentPeriodEnd: _$typebox.TString;
1025
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
1026
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
1027
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
1028
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
1029
+ cancelAtPeriodEnd: _$typebox.TBoolean;
1030
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
1031
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
1032
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
1033
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
1034
+ dunningAttempt: _$typebox.TInteger;
1035
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
1036
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
1037
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
1038
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
1039
+ }>;
1040
+ }>;
1041
+ /**
1042
+ * Change the plan for the current organization's subscription.
1043
+ */
1044
+ readonly changePlan: _$alepha_server0.ActionPrimitiveFn<{
1045
+ body: _$typebox.TObject<{
1046
+ planId: _$typebox.TString;
1047
+ interval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
1048
+ immediate: _$typebox.TOptional<_$typebox.TBoolean>;
1049
+ }>;
1050
+ response: _$typebox.TObject<{
1051
+ id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
1052
+ version: PgAttr<PgAttr<_$typebox.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
1053
+ createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1054
+ updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1055
+ organizationId: PgAttr<_$typebox.TString, typeof PG_ORGANIZATION>;
1056
+ planId: _$typebox.TString;
1057
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
1058
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
1059
+ currentPeriodStart: _$typebox.TString;
1060
+ currentPeriodEnd: _$typebox.TString;
1061
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
1062
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
1063
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
1064
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
1065
+ cancelAtPeriodEnd: _$typebox.TBoolean;
1066
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
1067
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
1068
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
1069
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
1070
+ dunningAttempt: _$typebox.TInteger;
1071
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
1072
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
1073
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
1074
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
1075
+ }>;
1076
+ }>;
1077
+ /**
1078
+ * Cancel the current organization's subscription.
1079
+ */
1080
+ readonly cancel: _$alepha_server0.ActionPrimitiveFn<{
1081
+ body: _$typebox.TObject<{
1082
+ reason: _$typebox.TOptional<_$typebox.TString>;
1083
+ immediate: _$typebox.TOptional<_$typebox.TBoolean>;
1084
+ }>;
1085
+ response: _$typebox.TObject<{
1086
+ ok: _$typebox.TBoolean;
1087
+ id: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TString, _$typebox.TInteger]>>;
1088
+ count: _$typebox.TOptional<_$typebox.TNumber>;
1089
+ }>;
1090
+ }>;
1091
+ /**
1092
+ * Resume a cancelled subscription before the period ends.
1093
+ */
1094
+ readonly resume: _$alepha_server0.ActionPrimitiveFn<{
1095
+ response: _$typebox.TObject<{
1096
+ ok: _$typebox.TBoolean;
1097
+ id: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TString, _$typebox.TInteger]>>;
1098
+ count: _$typebox.TOptional<_$typebox.TNumber>;
1099
+ }>;
1100
+ }>;
1101
+ /**
1102
+ * Get the billing event history for the current organization's subscription.
1103
+ */
1104
+ readonly getSubscriptionHistory: _$alepha_server0.ActionPrimitiveFn<{
1105
+ response: _$typebox.TArray<_$typebox.TObject<{
1106
+ id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
1107
+ createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1108
+ subscriptionId: PgAttr<_$typebox.TString, typeof PG_REF>;
1109
+ organizationId: PgAttr<_$typebox.TString, typeof PG_ORGANIZATION>;
1110
+ type: _$typebox.TUnsafe<"past_due" | "suspended" | "cancelled" | "expired" | "created" | "trial_started" | "trial_ended" | "activated" | "renewed" | "payment_failed" | "payment_retried" | "reactivated" | "plan_changed" | "plan_change_scheduled" | "resumed">;
1111
+ previousStatus: _$typebox.TOptional<_$typebox.TString>;
1112
+ newStatus: _$typebox.TOptional<_$typebox.TString>;
1113
+ previousPlanId: _$typebox.TOptional<_$typebox.TString>;
1114
+ newPlanId: _$typebox.TOptional<_$typebox.TString>;
1115
+ paymentIntentId: _$typebox.TOptional<_$typebox.TString>;
1116
+ amount: _$typebox.TOptional<_$typebox.TInteger>;
1117
+ currency: _$typebox.TOptional<_$typebox.TString>;
1118
+ triggeredBy: _$typebox.TOptional<_$typebox.TString>;
1119
+ userId: _$typebox.TOptional<_$typebox.TString>;
1120
+ note: _$typebox.TOptional<_$typebox.TString>;
1121
+ }>>;
1122
+ }>;
1123
+ /**
1124
+ * Get the feature and usage limit entitlements for the current organization.
1125
+ */
1126
+ readonly getEntitlements: _$alepha_server0.ActionPrimitiveFn<{
1127
+ response: _$typebox.TObject<{
1128
+ planId: _$typebox.TString;
1129
+ planName: _$typebox.TString;
1130
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
1131
+ features: _$typebox.TArray<_$typebox.TString>;
1132
+ limits: _$typebox.TRecord<"^.*$", _$typebox.TInteger>;
1133
+ trialEndsAt: _$typebox.TOptional<_$typebox.TString>;
1134
+ periodEndsAt: _$typebox.TString;
1135
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
1136
+ }>;
1137
+ }>;
1138
+ }
1139
+ //#endregion
1140
+ //#region ../../src/api/subscriptions/jobs/SubscriptionJobs.d.ts
1141
+ interface EventContext$1 {
1142
+ previousStatus?: string;
1143
+ newStatus?: string;
1144
+ paymentIntentId?: string;
1145
+ amount?: number;
1146
+ currency?: string;
1147
+ triggeredBy?: string;
1148
+ note?: string;
1149
+ }
1150
+ declare class SubscriptionJobs {
1151
+ protected readonly log: _$alepha_logger0.Logger;
1152
+ protected readonly dateTime: DateTimeProvider;
1153
+ protected readonly paymentService: PaymentService;
1154
+ protected readonly config: SubscriptionConfig;
1155
+ protected readonly subscriptionRepo: _$alepha_orm0.Repository<_$typebox.TObject<{
1156
+ id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
1157
+ version: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_VERSION>, typeof _$alepha_orm0.PG_DEFAULT>;
1158
+ createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
1159
+ updatedAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_UPDATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
1160
+ organizationId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_ORGANIZATION>;
1161
+ planId: _$typebox.TString;
1162
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
1163
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
1164
+ currentPeriodStart: _$typebox.TString;
1165
+ currentPeriodEnd: _$typebox.TString;
1166
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
1167
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
1168
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
1169
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
1170
+ cancelAtPeriodEnd: _$typebox.TBoolean;
1171
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
1172
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
1173
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
1174
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
1175
+ dunningAttempt: _$typebox.TInteger;
1176
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
1177
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
1178
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
1179
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
1180
+ }>>;
1181
+ protected readonly eventRepo: _$alepha_orm0.Repository<_$typebox.TObject<{
1182
+ id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
1183
+ createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
1184
+ subscriptionId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_REF>;
1185
+ organizationId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_ORGANIZATION>;
1186
+ type: _$typebox.TUnsafe<"past_due" | "suspended" | "cancelled" | "expired" | "created" | "trial_started" | "trial_ended" | "activated" | "renewed" | "payment_failed" | "payment_retried" | "reactivated" | "plan_changed" | "plan_change_scheduled" | "resumed">;
1187
+ previousStatus: _$typebox.TOptional<_$typebox.TString>;
1188
+ newStatus: _$typebox.TOptional<_$typebox.TString>;
1189
+ previousPlanId: _$typebox.TOptional<_$typebox.TString>;
1190
+ newPlanId: _$typebox.TOptional<_$typebox.TString>;
1191
+ paymentIntentId: _$typebox.TOptional<_$typebox.TString>;
1192
+ amount: _$typebox.TOptional<_$typebox.TInteger>;
1193
+ currency: _$typebox.TOptional<_$typebox.TString>;
1194
+ triggeredBy: _$typebox.TOptional<_$typebox.TString>;
1195
+ userId: _$typebox.TOptional<_$typebox.TString>;
1196
+ note: _$typebox.TOptional<_$typebox.TString>;
1197
+ }>>;
1198
+ /**
1199
+ * Record a subscription event in the event log.
1200
+ */
1201
+ protected recordEvent(subscriptionId: string, organizationId: string, type: SubscriptionEventEntity["type"], context?: EventContext$1): Promise<void>;
1202
+ /**
1203
+ * Creates payment intents for subscriptions due for renewal.
1204
+ * Runs hourly.
1205
+ */
1206
+ readonly billingCycle: _$alepha_api_jobs0.JobPrimitive<_$typebox.TSchema>;
1207
+ /**
1208
+ * Retries failed payments on the dunning schedule.
1209
+ * Runs hourly.
1210
+ */
1211
+ readonly dunningRetry: _$alepha_api_jobs0.JobPrimitive<_$typebox.TSchema>;
1212
+ /**
1213
+ * Handles trial expirations.
1214
+ * Runs hourly.
1215
+ */
1216
+ readonly trialExpiry: _$alepha_api_jobs0.JobPrimitive<_$typebox.TSchema>;
1217
+ /**
1218
+ * Expires cancelled subscriptions that reached period end.
1219
+ * Runs hourly.
1220
+ */
1221
+ readonly expirationSweep: _$alepha_api_jobs0.JobPrimitive<_$typebox.TSchema>;
1222
+ /**
1223
+ * Suspends past_due subscriptions where grace period has elapsed.
1224
+ * Runs daily at 2 AM.
1225
+ */
1226
+ readonly gracePeriodSweep: _$alepha_api_jobs0.JobPrimitive<_$typebox.TSchema>;
1227
+ /**
1228
+ * Purges old subscription events older than 365 days.
1229
+ * Runs daily at 3 AM.
1230
+ */
1231
+ readonly purgeEvents: _$alepha_api_jobs0.JobPrimitive<_$typebox.TSchema>;
1232
+ }
1233
+ //#endregion
1234
+ //#region ../../src/api/subscriptions/middleware/$requireLimit.d.ts
1235
+ /**
1236
+ * Middleware that enforces a per-organization usage limit for a resource.
1237
+ *
1238
+ * Resolves the organization from `args[0].user.organization`, increments the
1239
+ * usage counter for the given resource, and throws `ForbiddenError` if the
1240
+ * plan limit has been reached.
1241
+ * Throws `ForbiddenError` if no organization is present or the limit is exceeded.
1242
+ *
1243
+ * ```typescript
1244
+ * class ApiController {
1245
+ * search = $action({
1246
+ * use: [$requireLimit("api_calls")],
1247
+ * handler: async ({ query }) => { ... },
1248
+ * });
1249
+ * }
1250
+ * ```
1251
+ *
1252
+ * @param resource The resource identifier to track (e.g., "api_calls", "exports").
1253
+ */
1254
+ declare const $requireLimit: (resource: string) => Middleware;
1255
+ //#endregion
1256
+ //#region ../../src/api/subscriptions/middleware/$requirePlan.d.ts
1257
+ /**
1258
+ * Middleware that gates access to a handler behind a subscription feature flag.
1259
+ *
1260
+ * Resolves the organization from `args[0].user.organization` and checks whether
1261
+ * the organization's current plan includes the given feature.
1262
+ * Throws `ForbiddenError` if no organization is present or the feature is not available.
1263
+ *
1264
+ * ```typescript
1265
+ * class ReportController {
1266
+ * generate = $action({
1267
+ * use: [$requirePlan("advanced_reports")],
1268
+ * handler: async ({ user }) => { ... },
1269
+ * });
1270
+ * }
1271
+ * ```
1272
+ *
1273
+ * @param feature The feature identifier to check against the plan's feature list.
1274
+ */
1275
+ declare const $requirePlan: (feature: string) => Middleware;
1276
+ //#endregion
1277
+ //#region ../../src/api/subscriptions/notifications/SubscriptionNotifications.d.ts
1278
+ declare class SubscriptionNotifications {
1279
+ /**
1280
+ * Sent when a trial is ending soon.
1281
+ */
1282
+ protected readonly trialEnding: _$alepha_api_notifications0.NotificationPrimitive<_$typebox.TObject<{
1283
+ planName: _$typebox.TString;
1284
+ trialEndDate: _$typebox.TString;
1285
+ amount: _$typebox.TString;
1286
+ interval: _$typebox.TString;
1287
+ }>>;
1288
+ /**
1289
+ * Sent when a payment fails. Critical notification.
1290
+ */
1291
+ protected readonly paymentFailed: _$alepha_api_notifications0.NotificationPrimitive<_$typebox.TObject<{
1292
+ planName: _$typebox.TString;
1293
+ amount: _$typebox.TString;
1294
+ retryDate: _$typebox.TOptional<_$typebox.TString>;
1295
+ }>>;
1296
+ /**
1297
+ * Sent when a subscription is suspended due to failed payments. Critical notification.
1298
+ */
1299
+ protected readonly subscriptionSuspended: _$alepha_api_notifications0.NotificationPrimitive<_$typebox.TObject<{
1300
+ planName: _$typebox.TString;
1301
+ }>>;
1302
+ /**
1303
+ * Sent when a subscription is successfully renewed.
1304
+ */
1305
+ protected readonly subscriptionRenewed: _$alepha_api_notifications0.NotificationPrimitive<_$typebox.TObject<{
1306
+ planName: _$typebox.TString;
1307
+ amount: _$typebox.TString;
1308
+ nextBillingDate: _$typebox.TString;
1309
+ }>>;
1310
+ /**
1311
+ * Sent when a subscription plan is changed.
1312
+ */
1313
+ protected readonly planChanged: _$alepha_api_notifications0.NotificationPrimitive<_$typebox.TObject<{
1314
+ oldPlanName: _$typebox.TString;
1315
+ newPlanName: _$typebox.TString;
1316
+ effectiveDate: _$typebox.TString;
1317
+ }>>;
1318
+ /**
1319
+ * Sent when a subscription is cancelled.
1320
+ */
1321
+ protected readonly cancellationConfirmed: _$alepha_api_notifications0.NotificationPrimitive<_$typebox.TObject<{
1322
+ planName: _$typebox.TString;
1323
+ accessUntil: _$typebox.TOptional<_$typebox.TString>;
1324
+ }>>;
1325
+ }
1326
+ //#endregion
1327
+ //#region ../../src/api/subscriptions/schemas/cancelSubscriptionSchema.d.ts
1328
+ declare const cancelSubscriptionSchema: _$typebox.TObject<{
1329
+ reason: _$typebox.TOptional<_$typebox.TString>;
1330
+ immediate: _$typebox.TOptional<_$typebox.TBoolean>;
1331
+ }>;
1332
+ type CancelSubscription = Static<typeof cancelSubscriptionSchema>;
1333
+ //#endregion
1334
+ //#region ../../src/api/subscriptions/schemas/changePlanSchema.d.ts
1335
+ declare const changePlanSchema: _$typebox.TObject<{
1336
+ planId: _$typebox.TString;
1337
+ interval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
1338
+ immediate: _$typebox.TOptional<_$typebox.TBoolean>;
1339
+ }>;
1340
+ type ChangePlan = Static<typeof changePlanSchema>;
1341
+ //#endregion
1342
+ //#region ../../src/api/subscriptions/schemas/createSubscriptionSchema.d.ts
1343
+ declare const createSubscriptionSchema: _$typebox.TObject<{
1344
+ planId: _$typebox.TString;
1345
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
1346
+ paymentMethodId: _$typebox.TOptional<_$typebox.TString>;
1347
+ skipTrial: _$typebox.TOptional<_$typebox.TBoolean>;
1348
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
1349
+ }>;
1350
+ type CreateSubscription = Static<typeof createSubscriptionSchema>;
1351
+ //#endregion
1352
+ //#region ../../src/api/subscriptions/schemas/mrrSchema.d.ts
1353
+ declare const mrrSchema: _$typebox.TObject<{
1354
+ total: _$typebox.TInteger;
1355
+ byPlan: _$typebox.TRecord<"^.*$", _$typebox.TInteger>;
1356
+ growth: _$typebox.TInteger;
1357
+ newMrr: _$typebox.TInteger;
1358
+ expansionMrr: _$typebox.TInteger;
1359
+ contractionMrr: _$typebox.TInteger;
1360
+ churnMrr: _$typebox.TInteger;
1361
+ }>;
1362
+ type MrrData = Static<typeof mrrSchema>;
1363
+ //#endregion
1364
+ //#region ../../src/api/subscriptions/schemas/planResourceSchema.d.ts
1365
+ declare const planResourceSchema: _$typebox.TObject<{
1366
+ id: _$typebox.TString;
1367
+ name: _$typebox.TString;
1368
+ description: _$typebox.TOptional<_$typebox.TString>;
1369
+ pricing: _$typebox.TArray<_$typebox.TObject<{
1370
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
1371
+ amount: _$typebox.TInteger;
1372
+ currency: _$typebox.TString;
1373
+ }>>;
1374
+ features: _$typebox.TArray<_$typebox.TString>;
1375
+ limits: _$typebox.TRecord<"^.*$", _$typebox.TInteger>;
1376
+ trial: _$typebox.TOptional<_$typebox.TObject<{
1377
+ days: _$typebox.TInteger;
1378
+ requirePaymentMethod: _$typebox.TBoolean;
1379
+ }>>;
1380
+ order: _$typebox.TInteger;
1381
+ }>;
1382
+ type PlanResource = Static<typeof planResourceSchema>;
1383
+ //#endregion
1384
+ //#region ../../src/api/subscriptions/schemas/subscriptionEventResourceSchema.d.ts
1385
+ declare const subscriptionEventResourceSchema: _$typebox.TObject<{
1386
+ id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
1387
+ createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1388
+ subscriptionId: PgAttr<_$typebox.TString, typeof PG_REF>;
1389
+ organizationId: PgAttr<_$typebox.TString, typeof PG_ORGANIZATION>;
1390
+ type: _$typebox.TUnsafe<"past_due" | "suspended" | "cancelled" | "expired" | "created" | "trial_started" | "trial_ended" | "activated" | "renewed" | "payment_failed" | "payment_retried" | "reactivated" | "plan_changed" | "plan_change_scheduled" | "resumed">;
1391
+ previousStatus: _$typebox.TOptional<_$typebox.TString>;
1392
+ newStatus: _$typebox.TOptional<_$typebox.TString>;
1393
+ previousPlanId: _$typebox.TOptional<_$typebox.TString>;
1394
+ newPlanId: _$typebox.TOptional<_$typebox.TString>;
1395
+ paymentIntentId: _$typebox.TOptional<_$typebox.TString>;
1396
+ amount: _$typebox.TOptional<_$typebox.TInteger>;
1397
+ currency: _$typebox.TOptional<_$typebox.TString>;
1398
+ triggeredBy: _$typebox.TOptional<_$typebox.TString>;
1399
+ userId: _$typebox.TOptional<_$typebox.TString>;
1400
+ note: _$typebox.TOptional<_$typebox.TString>;
1401
+ }>;
1402
+ type SubscriptionEventResource = Static<typeof subscriptionEventResourceSchema>;
1403
+ //#endregion
1404
+ //#region ../../src/api/subscriptions/schemas/subscriptionResourceSchema.d.ts
1405
+ declare const subscriptionResourceSchema: _$typebox.TObject<{
1406
+ id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
1407
+ version: PgAttr<PgAttr<_$typebox.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
1408
+ createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1409
+ updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1410
+ organizationId: PgAttr<_$typebox.TString, typeof PG_ORGANIZATION>;
1411
+ planId: _$typebox.TString;
1412
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
1413
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
1414
+ currentPeriodStart: _$typebox.TString;
1415
+ currentPeriodEnd: _$typebox.TString;
1416
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
1417
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
1418
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
1419
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
1420
+ cancelAtPeriodEnd: _$typebox.TBoolean;
1421
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
1422
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
1423
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
1424
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
1425
+ dunningAttempt: _$typebox.TInteger;
1426
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
1427
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
1428
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
1429
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
1430
+ }>;
1431
+ type SubscriptionResource = Static<typeof subscriptionResourceSchema>;
1432
+ //#endregion
1433
+ //#region ../../src/api/subscriptions/services/BillingService.d.ts
1434
+ interface PaymentEvent {
1435
+ intentId: string;
1436
+ amount: number;
1437
+ currency: string;
1438
+ metadata?: unknown;
1439
+ }
1440
+ interface EventContext {
1441
+ previousStatus?: string;
1442
+ newStatus?: string;
1443
+ previousPlanId?: string;
1444
+ newPlanId?: string;
1445
+ paymentIntentId?: string;
1446
+ amount?: number;
1447
+ currency?: string;
1448
+ triggeredBy?: string;
1449
+ userId?: string;
1450
+ note?: string;
1451
+ }
1452
+ declare class BillingService {
1453
+ protected readonly alepha: Alepha;
1454
+ protected readonly log: _$alepha_logger0.Logger;
1455
+ protected readonly dateTime: DateTimeProvider;
1456
+ protected readonly subscriptionRepo: _$alepha_orm0.Repository<_$typebox.TObject<{
1457
+ id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
1458
+ version: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_VERSION>, typeof _$alepha_orm0.PG_DEFAULT>;
1459
+ createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
1460
+ updatedAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_UPDATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
1461
+ organizationId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_ORGANIZATION>;
1462
+ planId: _$typebox.TString;
1463
+ interval: _$typebox.TUnsafe<"monthly" | "yearly">;
1464
+ status: _$typebox.TUnsafe<"trialing" | "active" | "past_due" | "suspended" | "cancelled" | "expired">;
1465
+ currentPeriodStart: _$typebox.TString;
1466
+ currentPeriodEnd: _$typebox.TString;
1467
+ trialStart: _$typebox.TOptional<_$typebox.TString>;
1468
+ trialEnd: _$typebox.TOptional<_$typebox.TString>;
1469
+ cancelledAt: _$typebox.TOptional<_$typebox.TString>;
1470
+ cancelReason: _$typebox.TOptional<_$typebox.TString>;
1471
+ cancelAtPeriodEnd: _$typebox.TBoolean;
1472
+ lastPaymentIntentId: _$typebox.TOptional<_$typebox.TString>;
1473
+ lastPaymentAt: _$typebox.TOptional<_$typebox.TString>;
1474
+ nextBillingAt: _$typebox.TOptional<_$typebox.TString>;
1475
+ dunningStartedAt: _$typebox.TOptional<_$typebox.TString>;
1476
+ dunningAttempt: _$typebox.TInteger;
1477
+ dunningNextRetryAt: _$typebox.TOptional<_$typebox.TString>;
1478
+ pendingPlanId: _$typebox.TOptional<_$typebox.TString>;
1479
+ pendingInterval: _$typebox.TOptional<_$typebox.TUnsafe<"monthly" | "yearly">>;
1480
+ metadata: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
1481
+ }>>;
1482
+ protected readonly eventRepo: _$alepha_orm0.Repository<_$typebox.TObject<{
1483
+ id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
1484
+ createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
1485
+ subscriptionId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_REF>;
1486
+ organizationId: _$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_ORGANIZATION>;
1487
+ type: _$typebox.TUnsafe<"past_due" | "suspended" | "cancelled" | "expired" | "created" | "trial_started" | "trial_ended" | "activated" | "renewed" | "payment_failed" | "payment_retried" | "reactivated" | "plan_changed" | "plan_change_scheduled" | "resumed">;
1488
+ previousStatus: _$typebox.TOptional<_$typebox.TString>;
1489
+ newStatus: _$typebox.TOptional<_$typebox.TString>;
1490
+ previousPlanId: _$typebox.TOptional<_$typebox.TString>;
1491
+ newPlanId: _$typebox.TOptional<_$typebox.TString>;
1492
+ paymentIntentId: _$typebox.TOptional<_$typebox.TString>;
1493
+ amount: _$typebox.TOptional<_$typebox.TInteger>;
1494
+ currency: _$typebox.TOptional<_$typebox.TString>;
1495
+ triggeredBy: _$typebox.TOptional<_$typebox.TString>;
1496
+ userId: _$typebox.TOptional<_$typebox.TString>;
1497
+ note: _$typebox.TOptional<_$typebox.TString>;
1498
+ }>>;
1499
+ protected readonly paymentService: PaymentService;
1500
+ protected readonly config: SubscriptionConfig;
1501
+ /**
1502
+ * React to successful payment capture.
1503
+ * Routes to the appropriate handler based on subscription status.
1504
+ */
1505
+ protected readonly onPaymentCaptured: _$alepha.HookPrimitive<"payments:captured">;
1506
+ /**
1507
+ * React to failed payment.
1508
+ * Starts or advances the dunning flow.
1509
+ */
1510
+ protected readonly onPaymentFailed: _$alepha.HookPrimitive<"payments:failed">;
1511
+ /**
1512
+ * Find a subscription by its last payment intent ID.
1513
+ * Returns null if no subscription matches.
1514
+ */
1515
+ protected findByPaymentIntent(intentId: string): Promise<SubscriptionEntity | null>;
1516
+ /**
1517
+ * Trial to active transition.
1518
+ * Sets the first paid billing period and records activation events.
1519
+ */
1520
+ protected activate(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
1521
+ /**
1522
+ * Active to active cycle renewal.
1523
+ * Applies any pending plan change, then advances the billing period.
1524
+ */
1525
+ protected renew(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
1526
+ /**
1527
+ * Recover from dunning: past_due to active.
1528
+ * Resets all dunning state and records reactivation.
1529
+ */
1530
+ protected recoverFromDunning(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
1531
+ /**
1532
+ * Reactivate from suspended state after a successful payment.
1533
+ * Resets dunning, sets a fresh billing period, and records reactivation.
1534
+ */
1535
+ protected reactivateFromPayment(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
1536
+ /**
1537
+ * Handle a failed payment: start or advance dunning.
1538
+ * Updates dunning state and transitions to past_due if needed.
1539
+ */
1540
+ protected handlePaymentFailure(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
1541
+ /**
1542
+ * Compute the end of a billing interval from a start date.
1543
+ */
1544
+ protected computeIntervalEnd(start: string, interval: "monthly" | "yearly"): string;
1545
+ /**
1546
+ * Record a subscription event in the event log.
1547
+ */
1548
+ protected recordEvent(subscriptionId: string, organizationId: string, type: SubscriptionEventEntity["type"], context?: EventContext): Promise<void>;
1549
+ }
1550
+ //#endregion
1551
+ //#region ../../src/api/subscriptions/services/UsageService.d.ts
1552
+ /**
1553
+ * The result of a usage check or increment operation.
1554
+ */
1555
+ interface UsageResult {
1556
+ /**
1557
+ * Whether the operation is allowed given the current usage and limit.
1558
+ */
1559
+ allowed: boolean;
1560
+ /**
1561
+ * Current usage count for the period.
1562
+ */
1563
+ current: number;
1564
+ /**
1565
+ * The plan limit for the resource. -1 means unlimited.
1566
+ */
1567
+ limit: number;
1568
+ /**
1569
+ * Remaining capacity. -1 means unlimited.
1570
+ */
1571
+ remaining: number;
1572
+ }
1573
+ /**
1574
+ * Tracks and enforces per-organization resource usage limits.
1575
+ *
1576
+ * Usage counters are keyed by `organizationId:resource:YYYY-MM` and stored in the cache.
1577
+ * Limits are resolved from the organization's current subscription plan.
1578
+ */
1579
+ declare class UsageService {
1580
+ protected readonly cache: CacheProvider;
1581
+ protected readonly dateTime: DateTimeProvider;
1582
+ protected readonly subscriptionService: SubscriptionService;
1583
+ /**
1584
+ * Increment a resource counter for the current period and return the usage result.
1585
+ *
1586
+ * @param organizationId The organization to track usage for.
1587
+ * @param resource The resource identifier (e.g., "api_calls", "seats").
1588
+ * @param amount Amount to increment by (default: 1).
1589
+ */
1590
+ increment(organizationId: string, resource: string, amount?: number): Promise<UsageResult>;
1591
+ /**
1592
+ * Get the current usage for a resource without incrementing.
1593
+ *
1594
+ * @param organizationId The organization to query usage for.
1595
+ * @param resource The resource identifier.
1596
+ */
1597
+ getUsage(organizationId: string, resource: string): Promise<UsageResult>;
1598
+ /**
1599
+ * Reset all usage counters for an organization.
1600
+ *
1601
+ * Used at the start of a new billing period.
1602
+ *
1603
+ * @param organizationId The organization whose counters to reset.
1604
+ */
1605
+ resetForPeriod(organizationId: string): Promise<void>;
1606
+ /**
1607
+ * Build the cache key for a usage counter.
1608
+ *
1609
+ * Format: `organizationId:resource:YYYY-MM`
1610
+ */
1611
+ protected buildKey(organizationId: string, resource: string): string;
1612
+ }
1613
+ //#endregion
1614
+ //#region ../../src/api/subscriptions/index.d.ts
1615
+ declare module "alepha" {
1616
+ interface Hooks {
1617
+ "subscription:created": {
1618
+ subscriptionId: string;
1619
+ organizationId: string;
1620
+ planId: string;
1621
+ trial: boolean;
1622
+ };
1623
+ "subscription:activated": {
1624
+ subscriptionId: string;
1625
+ organizationId: string;
1626
+ planId: string;
1627
+ };
1628
+ "subscription:renewed": {
1629
+ subscriptionId: string;
1630
+ organizationId: string;
1631
+ planId: string;
1632
+ amount: number;
1633
+ currency: string;
1634
+ };
1635
+ "subscription:cancelled": {
1636
+ subscriptionId: string;
1637
+ organizationId: string;
1638
+ planId: string;
1639
+ reason?: string;
1640
+ immediate: boolean;
1641
+ };
1642
+ "subscription:expired": {
1643
+ subscriptionId: string;
1644
+ organizationId: string;
1645
+ planId: string;
1646
+ };
1647
+ "subscription:resumed": {
1648
+ subscriptionId: string;
1649
+ organizationId: string;
1650
+ planId: string;
1651
+ };
1652
+ "subscription:plan_changed": {
1653
+ subscriptionId: string;
1654
+ organizationId: string;
1655
+ oldPlanId: string;
1656
+ newPlanId: string;
1657
+ immediate: boolean;
1658
+ };
1659
+ "subscription:payment_failed": {
1660
+ subscriptionId: string;
1661
+ organizationId: string;
1662
+ planId: string;
1663
+ attempt: number;
1664
+ };
1665
+ "subscription:suspended": {
1666
+ subscriptionId: string;
1667
+ organizationId: string;
1668
+ planId: string;
1669
+ };
1670
+ "subscription:reactivated": {
1671
+ subscriptionId: string;
1672
+ organizationId: string;
1673
+ planId: string;
1674
+ };
1675
+ "subscription:trial_ending": {
1676
+ subscriptionId: string;
1677
+ organizationId: string;
1678
+ planId: string;
1679
+ endsAt: string;
1680
+ };
1681
+ }
1682
+ }
1683
+ /**
1684
+ * Subscription management module — plan-based access control, billing integration,
1685
+ * usage limits, and lifecycle events (trial, renewal, cancellation, suspension).
1686
+ *
1687
+ * Depends on `AlephaPayments` for payment processing — register it in your app
1688
+ * alongside this module. Use `SubscriptionConfig` to declare your plans and limits.
1689
+ *
1690
+ * @module alepha.api.subscriptions
1691
+ */
1692
+ declare const AlephaApiSubscriptions: _$alepha.Service<_$alepha.Module>;
1693
+ //#endregion
1694
+ export { $requireLimit, $requirePlan, AdminSubscriptionController, AlephaApiSubscriptions, BillingService, CancelSubscription, ChangePlan, CreateSubscription, Entitlements, MrrData, PlanDefinition, PlanResource, SubscriptionConfig, SubscriptionController, SubscriptionEntity, SubscriptionEventEntity, SubscriptionEventResource, SubscriptionJobs, SubscriptionNotifications, SubscriptionQuery, SubscriptionResource, SubscriptionService, SubscriptionSettings, SubscriptionStats, UsageResult, UsageService, cancelSubscriptionSchema, changePlanSchema, createSubscriptionSchema, entitlementsSchema, mrrSchema, planDefinitionSchema, planResourceSchema, subscriptionEventResourceSchema, subscriptionEvents, subscriptionQuerySchema, subscriptionResourceSchema, subscriptionSettingsSchema, subscriptionStatsSchema, subscriptions };
1695
+ //# sourceMappingURL=index.d.ts.map