alepha 0.20.1 → 0.20.2

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 (232) hide show
  1. package/dist/api/files/index.js +2 -1
  2. package/dist/api/files/index.js.map +1 -1
  3. package/dist/api/jobs/index.browser.js +64 -148
  4. package/dist/api/jobs/index.browser.js.map +1 -1
  5. package/dist/api/jobs/index.d.ts +371 -573
  6. package/dist/api/jobs/index.d.ts.map +1 -1
  7. package/dist/api/jobs/index.js +605 -1012
  8. package/dist/api/jobs/index.js.map +1 -1
  9. package/dist/api/notifications/index.d.ts +78 -17
  10. package/dist/api/notifications/index.d.ts.map +1 -1
  11. package/dist/api/notifications/index.js +90 -23
  12. package/dist/api/notifications/index.js.map +1 -1
  13. package/dist/api/payments/index.d.ts +2 -1
  14. package/dist/api/payments/index.d.ts.map +1 -1
  15. package/dist/api/payments/index.js +4 -2
  16. package/dist/api/payments/index.js.map +1 -1
  17. package/dist/api/users/index.d.ts +34 -31
  18. package/dist/api/users/index.d.ts.map +1 -1
  19. package/dist/api/users/index.js +13 -7
  20. package/dist/api/users/index.js.map +1 -1
  21. package/dist/api/verifications/index.js +2 -1
  22. package/dist/api/verifications/index.js.map +1 -1
  23. package/dist/cli/core/index.d.ts +8 -34
  24. package/dist/cli/core/index.d.ts.map +1 -1
  25. package/dist/cli/core/index.js +43 -232
  26. package/dist/cli/core/index.js.map +1 -1
  27. package/dist/cli/platform/index.d.ts +36 -11
  28. package/dist/cli/platform/index.d.ts.map +1 -1
  29. package/dist/cli/platform/index.js +93 -27
  30. package/dist/cli/platform/index.js.map +1 -1
  31. package/dist/command/index.d.ts +1 -1
  32. package/dist/core/index.browser.js +6 -0
  33. package/dist/core/index.browser.js.map +1 -1
  34. package/dist/core/index.d.ts +6 -0
  35. package/dist/core/index.d.ts.map +1 -1
  36. package/dist/core/index.js +6 -0
  37. package/dist/core/index.js.map +1 -1
  38. package/dist/core/index.native.js +6 -0
  39. package/dist/core/index.native.js.map +1 -1
  40. package/dist/core/index.workerd.js +6 -0
  41. package/dist/core/index.workerd.js.map +1 -1
  42. package/dist/react/form/index.d.ts +60 -1
  43. package/dist/react/form/index.d.ts.map +1 -1
  44. package/dist/react/form/index.js +86 -1
  45. package/dist/react/form/index.js.map +1 -1
  46. package/dist/react/head/index.browser.js +16 -1
  47. package/dist/react/head/index.browser.js.map +1 -1
  48. package/dist/react/head/index.d.ts +6 -0
  49. package/dist/react/head/index.d.ts.map +1 -1
  50. package/dist/react/head/index.js +16 -1
  51. package/dist/react/head/index.js.map +1 -1
  52. package/dist/react/router/index.browser.js +0 -10
  53. package/dist/react/router/index.browser.js.map +1 -1
  54. package/dist/react/router/index.d.ts +35 -12
  55. package/dist/react/router/index.d.ts.map +1 -1
  56. package/dist/react/router/index.js +0 -10
  57. package/dist/react/router/index.js.map +1 -1
  58. package/dist/react/ui/index.d.ts +124 -0
  59. package/dist/react/ui/index.d.ts.map +1 -0
  60. package/dist/react/ui/index.js +206 -0
  61. package/dist/react/ui/index.js.map +1 -0
  62. package/dist/router/index.d.ts +13 -13
  63. package/dist/router/index.d.ts.map +1 -1
  64. package/dist/router/index.js +45 -32
  65. package/dist/router/index.js.map +1 -1
  66. package/dist/system/index.d.ts.map +1 -1
  67. package/dist/system/index.js +1 -0
  68. package/dist/system/index.js.map +1 -1
  69. package/dist/topic/core/index.js +1 -1
  70. package/dist/topic/core/index.js.map +1 -1
  71. package/package.json +6 -23
  72. package/src/api/files/jobs/FileJobs.ts +2 -1
  73. package/src/api/jobs/__tests__/$job.spec.ts +316 -2867
  74. package/src/api/jobs/controllers/AdminJobController.ts +29 -138
  75. package/src/api/jobs/entities/jobExecutionEntity.ts +27 -19
  76. package/src/api/jobs/index.browser.ts +5 -7
  77. package/src/api/jobs/index.ts +23 -51
  78. package/src/api/jobs/primitives/$job.ts +66 -58
  79. package/src/api/jobs/providers/JobProvider.ts +561 -566
  80. package/src/api/jobs/providers/JobQueueProvider.ts +18 -19
  81. package/src/api/jobs/schemas/jobConfigAtom.ts +20 -23
  82. package/src/api/jobs/schemas/jobExecutionQuerySchema.ts +3 -27
  83. package/src/api/jobs/schemas/jobExecutionResourceSchema.ts +5 -7
  84. package/src/api/jobs/schemas/jobRegistrationSchema.ts +7 -4
  85. package/src/api/jobs/schemas/triggerJobSchema.ts +0 -1
  86. package/src/api/jobs/services/JobService.ts +90 -483
  87. package/src/api/notifications/controllers/AdminNotificationController.ts +19 -12
  88. package/src/api/notifications/index.ts +7 -4
  89. package/src/api/notifications/jobs/NotificationJobs.ts +83 -12
  90. package/src/api/payments/services/PaymentService.ts +4 -2
  91. package/src/api/users/__tests__/UserJobs.spec.ts +10 -49
  92. package/src/api/users/audits/UserAudits.ts +3 -1
  93. package/src/api/users/buckets/UserBuckets.ts +2 -1
  94. package/src/api/users/index.ts +1 -4
  95. package/src/api/users/jobs/UserJobs.ts +5 -4
  96. package/src/api/verifications/jobs/VerificationJobs.ts +2 -1
  97. package/src/cli/core/__tests__/init.spec.ts +1 -1
  98. package/src/cli/core/commands/init.ts +0 -12
  99. package/src/cli/core/services/PackageManagerUtils.ts +2 -9
  100. package/src/cli/core/services/ProjectScaffolder.ts +17 -65
  101. package/src/cli/core/templates/agentMd.ts +2 -8
  102. package/src/cli/core/templates/apiIndexTs.ts +4 -18
  103. package/src/cli/core/templates/mainCss.ts +1 -36
  104. package/src/cli/core/templates/vitestConfigTs.ts +17 -0
  105. package/src/cli/core/templates/webAppRouterTs.ts +2 -85
  106. package/src/cli/platform/__tests__/CloudflareAdapter.spec.ts +22 -71
  107. package/src/cli/platform/adapters/CloudflareAdapter.ts +12 -11
  108. package/src/cli/platform/atoms/platformOptions.ts +9 -0
  109. package/src/cli/platform/schemas/cloudflare.ts +3 -2
  110. package/src/cli/platform/services/CloudflareApi.ts +164 -25
  111. package/src/cli/platform/services/WranglerApi.ts +0 -17
  112. package/src/core/Alepha.ts +9 -0
  113. package/src/react/form/index.ts +2 -0
  114. package/src/react/form/services/parseField.ts +163 -0
  115. package/src/react/form/services/prettyName.ts +19 -0
  116. package/src/react/head/providers/BrowserHeadProvider.ts +31 -10
  117. package/src/react/router/primitives/$page.ts +35 -12
  118. package/src/react/ui/atoms/uiAtom.ts +28 -0
  119. package/src/react/ui/components/ColorScheme.tsx +36 -0
  120. package/src/react/ui/hooks/useColorMode.ts +49 -0
  121. package/src/react/ui/hooks/useSidebarState.ts +26 -0
  122. package/src/react/ui/hooks/useTheme.ts +22 -0
  123. package/src/react/ui/index.ts +35 -0
  124. package/src/react/ui/services/UiPersistence.ts +41 -0
  125. package/src/router/TemplatedPathParser.ts +50 -51
  126. package/src/router/__tests__/RouterProvider.spec.ts +62 -0
  127. package/src/router/__tests__/TemplatedPathParser.spec.ts +18 -0
  128. package/src/router/providers/RouterProvider.ts +10 -5
  129. package/src/system/providers/NodeShellProvider.ts +1 -0
  130. package/src/topic/core/providers/TopicProvider.ts +1 -1
  131. package/dist/api/invitations/index.d.ts +0 -790
  132. package/dist/api/invitations/index.d.ts.map +0 -1
  133. package/dist/api/invitations/index.js +0 -662
  134. package/dist/api/invitations/index.js.map +0 -1
  135. package/dist/api/issues/index.d.ts +0 -810
  136. package/dist/api/issues/index.d.ts.map +0 -1
  137. package/dist/api/issues/index.js +0 -444
  138. package/dist/api/issues/index.js.map +0 -1
  139. package/dist/api/subscriptions/index.d.ts +0 -1692
  140. package/dist/api/subscriptions/index.d.ts.map +0 -1
  141. package/dist/api/subscriptions/index.js +0 -1867
  142. package/dist/api/subscriptions/index.js.map +0 -1
  143. package/dist/api/workflows/index.browser.js +0 -246
  144. package/dist/api/workflows/index.browser.js.map +0 -1
  145. package/dist/api/workflows/index.d.ts +0 -1618
  146. package/dist/api/workflows/index.d.ts.map +0 -1
  147. package/dist/api/workflows/index.js +0 -1495
  148. package/dist/api/workflows/index.js.map +0 -1
  149. package/src/api/invitations/__tests__/InvitationService.spec.ts +0 -439
  150. package/src/api/invitations/controllers/AdminInvitationController.ts +0 -86
  151. package/src/api/invitations/controllers/InvitationController.ts +0 -84
  152. package/src/api/invitations/entities/invitations.ts +0 -33
  153. package/src/api/invitations/index.ts +0 -58
  154. package/src/api/invitations/jobs/InvitationJobs.ts +0 -37
  155. package/src/api/invitations/providers/InvitationProvider.ts +0 -45
  156. package/src/api/invitations/schemas/createInvitationSchema.ts +0 -12
  157. package/src/api/invitations/schemas/invitationConfigAtom.ts +0 -20
  158. package/src/api/invitations/schemas/invitationQuerySchema.ts +0 -15
  159. package/src/api/invitations/schemas/invitationResourceSchema.ts +0 -6
  160. package/src/api/invitations/schemas/invitationWithResourceInfoSchema.ts +0 -22
  161. package/src/api/invitations/schemas/myInvitationsQuerySchema.ts +0 -10
  162. package/src/api/invitations/services/InvitationService.ts +0 -556
  163. package/src/api/issues/__tests__/IssueService.spec.ts +0 -263
  164. package/src/api/issues/controllers/AdminIssueController.ts +0 -149
  165. package/src/api/issues/controllers/IssueController.ts +0 -44
  166. package/src/api/issues/entities/issues.ts +0 -49
  167. package/src/api/issues/index.ts +0 -50
  168. package/src/api/issues/schemas/createIssueSchema.ts +0 -13
  169. package/src/api/issues/schemas/issueConfigAtom.ts +0 -13
  170. package/src/api/issues/schemas/issueQuerySchema.ts +0 -18
  171. package/src/api/issues/schemas/issueResourceSchema.ts +0 -6
  172. package/src/api/issues/schemas/myIssueQuerySchema.ts +0 -10
  173. package/src/api/issues/schemas/updateIssueSchema.ts +0 -13
  174. package/src/api/issues/services/IssueService.ts +0 -264
  175. package/src/api/jobs/__tests__/$job-middleware.spec.ts +0 -126
  176. package/src/api/jobs/__tests__/JobService.spec.ts +0 -31
  177. package/src/api/jobs/entities/jobExecutionLogEntity.ts +0 -13
  178. package/src/api/jobs/schemas/jobActivitySchema.ts +0 -15
  179. package/src/api/jobs/schemas/jobCronInfoSchema.ts +0 -22
  180. package/src/api/jobs/schemas/jobExecutionDetailResourceSchema.ts +0 -20
  181. package/src/api/jobs/schemas/jobFailureSchema.ts +0 -9
  182. package/src/api/jobs/schemas/jobQueueDepthSchema.ts +0 -14
  183. package/src/api/jobs/schemas/jobStatsSchema.ts +0 -14
  184. package/src/api/jobs/services/JobService-tests.ts +0 -157
  185. package/src/api/subscriptions/__tests__/BillingService.spec.ts +0 -218
  186. package/src/api/subscriptions/__tests__/SubscriptionService.spec.ts +0 -278
  187. package/src/api/subscriptions/controllers/AdminSubscriptionController.ts +0 -212
  188. package/src/api/subscriptions/controllers/SubscriptionController.ts +0 -189
  189. package/src/api/subscriptions/entities/subscriptionEvents.ts +0 -54
  190. package/src/api/subscriptions/entities/subscriptions.ts +0 -68
  191. package/src/api/subscriptions/index.ts +0 -133
  192. package/src/api/subscriptions/jobs/SubscriptionJobs.ts +0 -382
  193. package/src/api/subscriptions/middleware/$requireLimit.ts +0 -50
  194. package/src/api/subscriptions/middleware/$requirePlan.ts +0 -49
  195. package/src/api/subscriptions/notifications/SubscriptionNotifications.ts +0 -110
  196. package/src/api/subscriptions/schemas/cancelSubscriptionSchema.ts +0 -8
  197. package/src/api/subscriptions/schemas/changePlanSchema.ts +0 -9
  198. package/src/api/subscriptions/schemas/createSubscriptionSchema.ts +0 -11
  199. package/src/api/subscriptions/schemas/entitlementsSchema.ts +0 -21
  200. package/src/api/subscriptions/schemas/mrrSchema.ts +0 -13
  201. package/src/api/subscriptions/schemas/planDefinitionSchema.ts +0 -71
  202. package/src/api/subscriptions/schemas/planResourceSchema.ts +0 -25
  203. package/src/api/subscriptions/schemas/subscriptionEventResourceSchema.ts +0 -8
  204. package/src/api/subscriptions/schemas/subscriptionQuerySchema.ts +0 -19
  205. package/src/api/subscriptions/schemas/subscriptionResourceSchema.ts +0 -6
  206. package/src/api/subscriptions/schemas/subscriptionSettingsSchema.ts +0 -32
  207. package/src/api/subscriptions/schemas/subscriptionStatsSchema.ts +0 -23
  208. package/src/api/subscriptions/services/BillingService.ts +0 -437
  209. package/src/api/subscriptions/services/SubscriptionConfig.ts +0 -56
  210. package/src/api/subscriptions/services/SubscriptionService.ts +0 -867
  211. package/src/api/subscriptions/services/UsageService.ts +0 -118
  212. package/src/api/workflows/__tests__/$workflow.spec.ts +0 -616
  213. package/src/api/workflows/controllers/AdminWorkflowController.ts +0 -191
  214. package/src/api/workflows/entities/workflowExecutions.ts +0 -74
  215. package/src/api/workflows/entities/workflowStepExecutions.ts +0 -74
  216. package/src/api/workflows/entities/workflowStepLogs.ts +0 -13
  217. package/src/api/workflows/index.browser.ts +0 -22
  218. package/src/api/workflows/index.ts +0 -115
  219. package/src/api/workflows/jobs/WorkflowJobs.ts +0 -77
  220. package/src/api/workflows/primitives/$workflow.ts +0 -202
  221. package/src/api/workflows/providers/WorkflowProvider.ts +0 -1284
  222. package/src/api/workflows/schemas/workflowActivitySchema.ts +0 -15
  223. package/src/api/workflows/schemas/workflowConfigAtom.ts +0 -51
  224. package/src/api/workflows/schemas/workflowExecutionDetailSchema.ts +0 -18
  225. package/src/api/workflows/schemas/workflowExecutionQuerySchema.ts +0 -26
  226. package/src/api/workflows/schemas/workflowExecutionResourceSchema.ts +0 -30
  227. package/src/api/workflows/schemas/workflowRegistrationSchema.ts +0 -26
  228. package/src/api/workflows/schemas/workflowStatsSchema.ts +0 -16
  229. package/src/api/workflows/schemas/workflowStepExecutionResourceSchema.ts +0 -15
  230. package/src/api/workflows/services/WorkflowService.ts +0 -382
  231. package/src/cli/core/templates/apiAppSecurityTs.ts +0 -43
  232. package/src/cli/core/templates/webAdminDashboardTsx.ts +0 -17
@@ -1,189 +0,0 @@
1
- import { $inject, t } from "alepha";
2
- import { $secure } from "alepha/security";
3
- import { $action, NotFoundError, okSchema } from "alepha/server";
4
- import { cancelSubscriptionSchema } from "../schemas/cancelSubscriptionSchema.ts";
5
- import { changePlanSchema } from "../schemas/changePlanSchema.ts";
6
- import { createSubscriptionSchema } from "../schemas/createSubscriptionSchema.ts";
7
- import { entitlementsSchema } from "../schemas/entitlementsSchema.ts";
8
- import { planResourceSchema } from "../schemas/planResourceSchema.ts";
9
- import { subscriptionEventResourceSchema } from "../schemas/subscriptionEventResourceSchema.ts";
10
- import { subscriptionResourceSchema } from "../schemas/subscriptionResourceSchema.ts";
11
- import { SubscriptionConfig } from "../services/SubscriptionConfig.ts";
12
- import { SubscriptionService } from "../services/SubscriptionService.ts";
13
-
14
- export class SubscriptionController {
15
- protected readonly url = "/subscriptions";
16
- protected readonly group = "subscriptions";
17
- protected readonly service = $inject(SubscriptionService);
18
- protected readonly config = $inject(SubscriptionConfig);
19
-
20
- /**
21
- * List available subscription plans with pricing.
22
- */
23
- public readonly getPlans = $action({
24
- path: `${this.url}/plans`,
25
- group: this.group,
26
- description: "List available subscription plans",
27
- schema: {
28
- response: t.array(planResourceSchema),
29
- },
30
- handler: async () => {
31
- const plans = await this.config.getPlans();
32
- return plans
33
- .filter((p) => p.available)
34
- .map((p) => ({
35
- id: p.id,
36
- name: p.name,
37
- description: p.description,
38
- pricing: p.pricing,
39
- features: p.features,
40
- limits: p.limits,
41
- trial: p.trial,
42
- order: p.order,
43
- }));
44
- },
45
- });
46
-
47
- /**
48
- * Get the current organization's subscription.
49
- */
50
- public readonly getMySubscription = $action({
51
- path: `${this.url}/mine`,
52
- group: this.group,
53
- use: [$secure()],
54
- description: "Get the current organization subscription",
55
- schema: {
56
- response: subscriptionResourceSchema,
57
- },
58
- handler: async ({ user }) => {
59
- const sub = await this.service.getByOrganization(user.organization!);
60
- if (!sub)
61
- throw new NotFoundError("No subscription found for your organization");
62
- return sub;
63
- },
64
- });
65
-
66
- /**
67
- * Create a new subscription for the current organization.
68
- */
69
- public readonly subscribe = $action({
70
- method: "POST",
71
- path: this.url,
72
- group: this.group,
73
- use: [$secure({ permissions: ["subscription:create"] })],
74
- description: "Create a new subscription",
75
- schema: {
76
- body: createSubscriptionSchema,
77
- response: subscriptionResourceSchema,
78
- },
79
- handler: ({ body, user }) =>
80
- this.service.subscribe(user.organization!, body.planId, body.interval, {
81
- skipTrial: body.skipTrial,
82
- metadata: body.metadata,
83
- }),
84
- });
85
-
86
- /**
87
- * Change the plan for the current organization's subscription.
88
- */
89
- public readonly changePlan = $action({
90
- method: "POST",
91
- path: `${this.url}/mine/change-plan`,
92
- group: this.group,
93
- use: [$secure({ permissions: ["subscription:update"] })],
94
- description: "Upgrade or downgrade the subscription plan",
95
- schema: {
96
- body: changePlanSchema,
97
- response: subscriptionResourceSchema,
98
- },
99
- handler: async ({ body, user }) => {
100
- const sub = await this.service.getByOrganization(user.organization!);
101
- if (!sub)
102
- throw new NotFoundError("No subscription found for your organization");
103
- await this.service.changePlan(sub.id, body.planId, body.interval, {
104
- immediate: body.immediate,
105
- });
106
- return this.service.getSubscription(sub.id);
107
- },
108
- });
109
-
110
- /**
111
- * Cancel the current organization's subscription.
112
- */
113
- public readonly cancel = $action({
114
- method: "POST",
115
- path: `${this.url}/mine/cancel`,
116
- group: this.group,
117
- use: [$secure({ permissions: ["subscription:update"] })],
118
- description: "Cancel the current subscription",
119
- schema: {
120
- body: cancelSubscriptionSchema,
121
- response: okSchema,
122
- },
123
- handler: async ({ body, user }) => {
124
- const sub = await this.service.getByOrganization(user.organization!);
125
- if (!sub)
126
- throw new NotFoundError("No subscription found for your organization");
127
- await this.service.cancel(sub.id, {
128
- reason: body.reason,
129
- immediate: body.immediate,
130
- });
131
- return { ok: true };
132
- },
133
- });
134
-
135
- /**
136
- * Resume a cancelled subscription before the period ends.
137
- */
138
- public readonly resume = $action({
139
- method: "POST",
140
- path: `${this.url}/mine/resume`,
141
- group: this.group,
142
- use: [$secure({ permissions: ["subscription:update"] })],
143
- description: "Resume a cancelled subscription",
144
- schema: {
145
- response: okSchema,
146
- },
147
- handler: async ({ user }) => {
148
- const sub = await this.service.getByOrganization(user.organization!);
149
- if (!sub)
150
- throw new NotFoundError("No subscription found for your organization");
151
- await this.service.resume(sub.id);
152
- return { ok: true };
153
- },
154
- });
155
-
156
- /**
157
- * Get the billing event history for the current organization's subscription.
158
- */
159
- public readonly getSubscriptionHistory = $action({
160
- path: `${this.url}/mine/history`,
161
- group: this.group,
162
- use: [$secure()],
163
- description: "Get the subscription billing event history",
164
- schema: {
165
- response: t.array(subscriptionEventResourceSchema),
166
- },
167
- handler: async ({ user }) => {
168
- const sub = await this.service.getByOrganization(user.organization!);
169
- if (!sub)
170
- throw new NotFoundError("No subscription found for your organization");
171
- return this.service.getHistory(sub.id);
172
- },
173
- });
174
-
175
- /**
176
- * Get the feature and usage limit entitlements for the current organization.
177
- */
178
- public readonly getEntitlements = $action({
179
- path: `${this.url}/mine/entitlements`,
180
- group: this.group,
181
- use: [$secure()],
182
- description:
183
- "Get the feature and limit entitlements for the current organization",
184
- schema: {
185
- response: entitlementsSchema,
186
- },
187
- handler: ({ user }) => this.service.getEntitlements(user.organization!),
188
- });
189
- }
@@ -1,54 +0,0 @@
1
- import { type Static, t } from "alepha";
2
- import { $entity, db } from "alepha/orm";
3
- import { subscriptions } from "./subscriptions.ts";
4
-
5
- export const subscriptionEvents = $entity({
6
- name: "subscription_events",
7
- schema: t.object({
8
- id: db.primaryKey(t.uuid()),
9
- createdAt: db.createdAt(),
10
- subscriptionId: db.ref(t.uuid(), () => subscriptions.cols.id, {
11
- onDelete: "cascade",
12
- }),
13
- organizationId: db.organization(),
14
-
15
- type: t.enum([
16
- "created",
17
- "trial_started",
18
- "trial_ended",
19
- "activated",
20
- "renewed",
21
- "payment_failed",
22
- "payment_retried",
23
- "past_due",
24
- "suspended",
25
- "reactivated",
26
- "plan_changed",
27
- "plan_change_scheduled",
28
- "cancelled",
29
- "expired",
30
- "resumed",
31
- ]),
32
-
33
- // Context
34
- previousStatus: t.optional(t.string()),
35
- newStatus: t.optional(t.string()),
36
- previousPlanId: t.optional(t.string()),
37
- newPlanId: t.optional(t.string()),
38
- paymentIntentId: t.optional(t.uuid()),
39
- amount: t.optional(t.integer()),
40
- currency: t.optional(t.string()),
41
-
42
- // Who / why
43
- triggeredBy: t.optional(t.string()),
44
- userId: t.optional(t.uuid()),
45
- note: t.optional(t.string()),
46
- }),
47
- indexes: [
48
- { columns: ["subscriptionId", "createdAt"] },
49
- { columns: ["organizationId", "createdAt"] },
50
- { columns: ["type"] },
51
- ],
52
- });
53
-
54
- export type SubscriptionEventEntity = Static<typeof subscriptionEvents.schema>;
@@ -1,68 +0,0 @@
1
- import { type Static, t } from "alepha";
2
- import { $entity, db } from "alepha/orm";
3
-
4
- export const subscriptions = $entity({
5
- name: "subscriptions",
6
- schema: t.object({
7
- id: db.primaryKey(t.uuid()),
8
- version: db.version(),
9
- createdAt: db.createdAt(),
10
- updatedAt: db.updatedAt(),
11
- organizationId: db.organization(),
12
-
13
- // Plan
14
- planId: t.string(),
15
- interval: t.enum(["monthly", "yearly"]),
16
-
17
- // Status
18
- status: t.enum([
19
- "trialing",
20
- "active",
21
- "past_due",
22
- "suspended",
23
- "cancelled",
24
- "expired",
25
- ]),
26
-
27
- // Billing cycle
28
- currentPeriodStart: t.datetime(),
29
- currentPeriodEnd: t.datetime(),
30
-
31
- // Trial
32
- trialStart: t.optional(t.datetime()),
33
- trialEnd: t.optional(t.datetime()),
34
-
35
- // Cancellation
36
- cancelledAt: t.optional(t.datetime()),
37
- cancelReason: t.optional(t.string()),
38
- cancelAtPeriodEnd: t.boolean({ default: false }),
39
-
40
- // Payment tracking
41
- lastPaymentIntentId: t.optional(t.uuid()),
42
- lastPaymentAt: t.optional(t.datetime()),
43
- nextBillingAt: t.optional(t.datetime()),
44
-
45
- // Dunning state
46
- dunningStartedAt: t.optional(t.datetime()),
47
- dunningAttempt: t.integer({ default: 0 }),
48
- dunningNextRetryAt: t.optional(t.datetime()),
49
-
50
- // Plan change (pending)
51
- pendingPlanId: t.optional(t.string()),
52
- pendingInterval: t.optional(t.enum(["monthly", "yearly"])),
53
-
54
- // Metadata
55
- metadata: t.optional(t.record(t.text(), t.any())),
56
- }),
57
- indexes: [
58
- { columns: ["organizationId"], unique: true },
59
- { columns: ["status"] },
60
- { columns: ["planId", "status"] },
61
- { columns: ["nextBillingAt"] },
62
- { columns: ["trialEnd"] },
63
- { columns: ["dunningNextRetryAt"] },
64
- { columns: ["currentPeriodEnd"] },
65
- ],
66
- });
67
-
68
- export type SubscriptionEntity = Static<typeof subscriptions.schema>;
@@ -1,133 +0,0 @@
1
- import { $module } from "alepha";
2
- import { AdminSubscriptionController } from "./controllers/AdminSubscriptionController.ts";
3
- import { SubscriptionController } from "./controllers/SubscriptionController.ts";
4
- import { SubscriptionJobs } from "./jobs/SubscriptionJobs.ts";
5
- import { SubscriptionNotifications } from "./notifications/SubscriptionNotifications.ts";
6
- import { BillingService } from "./services/BillingService.ts";
7
- import { SubscriptionConfig } from "./services/SubscriptionConfig.ts";
8
- import { SubscriptionService } from "./services/SubscriptionService.ts";
9
- import { UsageService } from "./services/UsageService.ts";
10
-
11
- // Controllers
12
- export * from "./controllers/AdminSubscriptionController.ts";
13
- export * from "./controllers/SubscriptionController.ts";
14
- // Entities
15
- export * from "./entities/subscriptionEvents.ts";
16
- export * from "./entities/subscriptions.ts";
17
- // Jobs
18
- export * from "./jobs/SubscriptionJobs.ts";
19
- // Middleware
20
- export * from "./middleware/$requireLimit.ts";
21
- export * from "./middleware/$requirePlan.ts";
22
- // Notifications
23
- export * from "./notifications/SubscriptionNotifications.ts";
24
- // Schemas
25
- export * from "./schemas/cancelSubscriptionSchema.ts";
26
- export * from "./schemas/changePlanSchema.ts";
27
- export * from "./schemas/createSubscriptionSchema.ts";
28
- export * from "./schemas/entitlementsSchema.ts";
29
- export * from "./schemas/mrrSchema.ts";
30
- export * from "./schemas/planDefinitionSchema.ts";
31
- export * from "./schemas/planResourceSchema.ts";
32
- export * from "./schemas/subscriptionEventResourceSchema.ts";
33
- export * from "./schemas/subscriptionQuerySchema.ts";
34
- export * from "./schemas/subscriptionResourceSchema.ts";
35
- export * from "./schemas/subscriptionSettingsSchema.ts";
36
- export * from "./schemas/subscriptionStatsSchema.ts";
37
- // Services
38
- export * from "./services/BillingService.ts";
39
- export * from "./services/SubscriptionConfig.ts";
40
- export * from "./services/SubscriptionService.ts";
41
- export * from "./services/UsageService.ts";
42
-
43
- declare module "alepha" {
44
- interface Hooks {
45
- "subscription:created": {
46
- subscriptionId: string;
47
- organizationId: string;
48
- planId: string;
49
- trial: boolean;
50
- };
51
- "subscription:activated": {
52
- subscriptionId: string;
53
- organizationId: string;
54
- planId: string;
55
- };
56
- "subscription:renewed": {
57
- subscriptionId: string;
58
- organizationId: string;
59
- planId: string;
60
- amount: number;
61
- currency: string;
62
- };
63
- "subscription:cancelled": {
64
- subscriptionId: string;
65
- organizationId: string;
66
- planId: string;
67
- reason?: string;
68
- immediate: boolean;
69
- };
70
- "subscription:expired": {
71
- subscriptionId: string;
72
- organizationId: string;
73
- planId: string;
74
- };
75
- "subscription:resumed": {
76
- subscriptionId: string;
77
- organizationId: string;
78
- planId: string;
79
- };
80
- "subscription:plan_changed": {
81
- subscriptionId: string;
82
- organizationId: string;
83
- oldPlanId: string;
84
- newPlanId: string;
85
- immediate: boolean;
86
- };
87
- "subscription:payment_failed": {
88
- subscriptionId: string;
89
- organizationId: string;
90
- planId: string;
91
- attempt: number;
92
- };
93
- "subscription:suspended": {
94
- subscriptionId: string;
95
- organizationId: string;
96
- planId: string;
97
- };
98
- "subscription:reactivated": {
99
- subscriptionId: string;
100
- organizationId: string;
101
- planId: string;
102
- };
103
- "subscription:trial_ending": {
104
- subscriptionId: string;
105
- organizationId: string;
106
- planId: string;
107
- endsAt: string;
108
- };
109
- }
110
- }
111
-
112
- /**
113
- * Subscription management module — plan-based access control, billing integration,
114
- * usage limits, and lifecycle events (trial, renewal, cancellation, suspension).
115
- *
116
- * Depends on `AlephaPayments` for payment processing — register it in your app
117
- * alongside this module. Use `SubscriptionConfig` to declare your plans and limits.
118
- *
119
- * @module alepha.api.subscriptions
120
- */
121
- export const AlephaApiSubscriptions = $module({
122
- name: "alepha.api.subscriptions",
123
- services: [
124
- SubscriptionConfig,
125
- SubscriptionService,
126
- BillingService,
127
- UsageService,
128
- SubscriptionJobs,
129
- SubscriptionNotifications,
130
- SubscriptionController,
131
- AdminSubscriptionController,
132
- ],
133
- });