alepha 0.19.2 → 0.19.4

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