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.
- package/dist/api/files/index.js +2 -1
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.browser.js +64 -148
- package/dist/api/jobs/index.browser.js.map +1 -1
- package/dist/api/jobs/index.d.ts +371 -573
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/jobs/index.js +605 -1012
- package/dist/api/jobs/index.js.map +1 -1
- package/dist/api/notifications/index.d.ts +78 -17
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/notifications/index.js +90 -23
- package/dist/api/notifications/index.js.map +1 -1
- package/dist/api/payments/index.d.ts +2 -1
- package/dist/api/payments/index.d.ts.map +1 -1
- package/dist/api/payments/index.js +4 -2
- package/dist/api/payments/index.js.map +1 -1
- package/dist/api/users/index.d.ts +34 -31
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +13 -7
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.js +2 -1
- package/dist/api/verifications/index.js.map +1 -1
- package/dist/cli/core/index.d.ts +8 -34
- package/dist/cli/core/index.d.ts.map +1 -1
- package/dist/cli/core/index.js +43 -232
- package/dist/cli/core/index.js.map +1 -1
- package/dist/cli/platform/index.d.ts +36 -11
- package/dist/cli/platform/index.d.ts.map +1 -1
- package/dist/cli/platform/index.js +93 -27
- package/dist/cli/platform/index.js.map +1 -1
- package/dist/command/index.d.ts +1 -1
- package/dist/core/index.browser.js +6 -0
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +6 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +6 -0
- package/dist/core/index.native.js.map +1 -1
- package/dist/core/index.workerd.js +6 -0
- package/dist/core/index.workerd.js.map +1 -1
- package/dist/react/form/index.d.ts +60 -1
- package/dist/react/form/index.d.ts.map +1 -1
- package/dist/react/form/index.js +86 -1
- package/dist/react/form/index.js.map +1 -1
- package/dist/react/head/index.browser.js +16 -1
- package/dist/react/head/index.browser.js.map +1 -1
- package/dist/react/head/index.d.ts +6 -0
- package/dist/react/head/index.d.ts.map +1 -1
- package/dist/react/head/index.js +16 -1
- package/dist/react/head/index.js.map +1 -1
- package/dist/react/router/index.browser.js +0 -10
- package/dist/react/router/index.browser.js.map +1 -1
- package/dist/react/router/index.d.ts +35 -12
- package/dist/react/router/index.d.ts.map +1 -1
- package/dist/react/router/index.js +0 -10
- package/dist/react/router/index.js.map +1 -1
- package/dist/react/ui/index.d.ts +124 -0
- package/dist/react/ui/index.d.ts.map +1 -0
- package/dist/react/ui/index.js +206 -0
- package/dist/react/ui/index.js.map +1 -0
- package/dist/router/index.d.ts +13 -13
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +45 -32
- package/dist/router/index.js.map +1 -1
- package/dist/system/index.d.ts.map +1 -1
- package/dist/system/index.js +1 -0
- package/dist/system/index.js.map +1 -1
- package/dist/topic/core/index.js +1 -1
- package/dist/topic/core/index.js.map +1 -1
- package/package.json +6 -23
- package/src/api/files/jobs/FileJobs.ts +2 -1
- package/src/api/jobs/__tests__/$job.spec.ts +316 -2867
- package/src/api/jobs/controllers/AdminJobController.ts +29 -138
- package/src/api/jobs/entities/jobExecutionEntity.ts +27 -19
- package/src/api/jobs/index.browser.ts +5 -7
- package/src/api/jobs/index.ts +23 -51
- package/src/api/jobs/primitives/$job.ts +66 -58
- package/src/api/jobs/providers/JobProvider.ts +561 -566
- package/src/api/jobs/providers/JobQueueProvider.ts +18 -19
- package/src/api/jobs/schemas/jobConfigAtom.ts +20 -23
- package/src/api/jobs/schemas/jobExecutionQuerySchema.ts +3 -27
- package/src/api/jobs/schemas/jobExecutionResourceSchema.ts +5 -7
- package/src/api/jobs/schemas/jobRegistrationSchema.ts +7 -4
- package/src/api/jobs/schemas/triggerJobSchema.ts +0 -1
- package/src/api/jobs/services/JobService.ts +90 -483
- package/src/api/notifications/controllers/AdminNotificationController.ts +19 -12
- package/src/api/notifications/index.ts +7 -4
- package/src/api/notifications/jobs/NotificationJobs.ts +83 -12
- package/src/api/payments/services/PaymentService.ts +4 -2
- package/src/api/users/__tests__/UserJobs.spec.ts +10 -49
- package/src/api/users/audits/UserAudits.ts +3 -1
- package/src/api/users/buckets/UserBuckets.ts +2 -1
- package/src/api/users/index.ts +1 -4
- package/src/api/users/jobs/UserJobs.ts +5 -4
- package/src/api/verifications/jobs/VerificationJobs.ts +2 -1
- package/src/cli/core/__tests__/init.spec.ts +1 -1
- package/src/cli/core/commands/init.ts +0 -12
- package/src/cli/core/services/PackageManagerUtils.ts +2 -9
- package/src/cli/core/services/ProjectScaffolder.ts +17 -65
- package/src/cli/core/templates/agentMd.ts +2 -8
- package/src/cli/core/templates/apiIndexTs.ts +4 -18
- package/src/cli/core/templates/mainCss.ts +1 -36
- package/src/cli/core/templates/vitestConfigTs.ts +17 -0
- package/src/cli/core/templates/webAppRouterTs.ts +2 -85
- package/src/cli/platform/__tests__/CloudflareAdapter.spec.ts +22 -71
- package/src/cli/platform/adapters/CloudflareAdapter.ts +12 -11
- package/src/cli/platform/atoms/platformOptions.ts +9 -0
- package/src/cli/platform/schemas/cloudflare.ts +3 -2
- package/src/cli/platform/services/CloudflareApi.ts +164 -25
- package/src/cli/platform/services/WranglerApi.ts +0 -17
- package/src/core/Alepha.ts +9 -0
- package/src/react/form/index.ts +2 -0
- package/src/react/form/services/parseField.ts +163 -0
- package/src/react/form/services/prettyName.ts +19 -0
- package/src/react/head/providers/BrowserHeadProvider.ts +31 -10
- package/src/react/router/primitives/$page.ts +35 -12
- package/src/react/ui/atoms/uiAtom.ts +28 -0
- package/src/react/ui/components/ColorScheme.tsx +36 -0
- package/src/react/ui/hooks/useColorMode.ts +49 -0
- package/src/react/ui/hooks/useSidebarState.ts +26 -0
- package/src/react/ui/hooks/useTheme.ts +22 -0
- package/src/react/ui/index.ts +35 -0
- package/src/react/ui/services/UiPersistence.ts +41 -0
- package/src/router/TemplatedPathParser.ts +50 -51
- package/src/router/__tests__/RouterProvider.spec.ts +62 -0
- package/src/router/__tests__/TemplatedPathParser.spec.ts +18 -0
- package/src/router/providers/RouterProvider.ts +10 -5
- package/src/system/providers/NodeShellProvider.ts +1 -0
- package/src/topic/core/providers/TopicProvider.ts +1 -1
- package/dist/api/invitations/index.d.ts +0 -790
- package/dist/api/invitations/index.d.ts.map +0 -1
- package/dist/api/invitations/index.js +0 -662
- package/dist/api/invitations/index.js.map +0 -1
- package/dist/api/issues/index.d.ts +0 -810
- package/dist/api/issues/index.d.ts.map +0 -1
- package/dist/api/issues/index.js +0 -444
- package/dist/api/issues/index.js.map +0 -1
- package/dist/api/subscriptions/index.d.ts +0 -1692
- package/dist/api/subscriptions/index.d.ts.map +0 -1
- package/dist/api/subscriptions/index.js +0 -1867
- package/dist/api/subscriptions/index.js.map +0 -1
- package/dist/api/workflows/index.browser.js +0 -246
- package/dist/api/workflows/index.browser.js.map +0 -1
- package/dist/api/workflows/index.d.ts +0 -1618
- package/dist/api/workflows/index.d.ts.map +0 -1
- package/dist/api/workflows/index.js +0 -1495
- package/dist/api/workflows/index.js.map +0 -1
- package/src/api/invitations/__tests__/InvitationService.spec.ts +0 -439
- package/src/api/invitations/controllers/AdminInvitationController.ts +0 -86
- package/src/api/invitations/controllers/InvitationController.ts +0 -84
- package/src/api/invitations/entities/invitations.ts +0 -33
- package/src/api/invitations/index.ts +0 -58
- package/src/api/invitations/jobs/InvitationJobs.ts +0 -37
- package/src/api/invitations/providers/InvitationProvider.ts +0 -45
- package/src/api/invitations/schemas/createInvitationSchema.ts +0 -12
- package/src/api/invitations/schemas/invitationConfigAtom.ts +0 -20
- package/src/api/invitations/schemas/invitationQuerySchema.ts +0 -15
- package/src/api/invitations/schemas/invitationResourceSchema.ts +0 -6
- package/src/api/invitations/schemas/invitationWithResourceInfoSchema.ts +0 -22
- package/src/api/invitations/schemas/myInvitationsQuerySchema.ts +0 -10
- package/src/api/invitations/services/InvitationService.ts +0 -556
- package/src/api/issues/__tests__/IssueService.spec.ts +0 -263
- package/src/api/issues/controllers/AdminIssueController.ts +0 -149
- package/src/api/issues/controllers/IssueController.ts +0 -44
- package/src/api/issues/entities/issues.ts +0 -49
- package/src/api/issues/index.ts +0 -50
- package/src/api/issues/schemas/createIssueSchema.ts +0 -13
- package/src/api/issues/schemas/issueConfigAtom.ts +0 -13
- package/src/api/issues/schemas/issueQuerySchema.ts +0 -18
- package/src/api/issues/schemas/issueResourceSchema.ts +0 -6
- package/src/api/issues/schemas/myIssueQuerySchema.ts +0 -10
- package/src/api/issues/schemas/updateIssueSchema.ts +0 -13
- package/src/api/issues/services/IssueService.ts +0 -264
- package/src/api/jobs/__tests__/$job-middleware.spec.ts +0 -126
- package/src/api/jobs/__tests__/JobService.spec.ts +0 -31
- package/src/api/jobs/entities/jobExecutionLogEntity.ts +0 -13
- package/src/api/jobs/schemas/jobActivitySchema.ts +0 -15
- package/src/api/jobs/schemas/jobCronInfoSchema.ts +0 -22
- package/src/api/jobs/schemas/jobExecutionDetailResourceSchema.ts +0 -20
- package/src/api/jobs/schemas/jobFailureSchema.ts +0 -9
- package/src/api/jobs/schemas/jobQueueDepthSchema.ts +0 -14
- package/src/api/jobs/schemas/jobStatsSchema.ts +0 -14
- package/src/api/jobs/services/JobService-tests.ts +0 -157
- package/src/api/subscriptions/__tests__/BillingService.spec.ts +0 -218
- package/src/api/subscriptions/__tests__/SubscriptionService.spec.ts +0 -278
- package/src/api/subscriptions/controllers/AdminSubscriptionController.ts +0 -212
- package/src/api/subscriptions/controllers/SubscriptionController.ts +0 -189
- package/src/api/subscriptions/entities/subscriptionEvents.ts +0 -54
- package/src/api/subscriptions/entities/subscriptions.ts +0 -68
- package/src/api/subscriptions/index.ts +0 -133
- package/src/api/subscriptions/jobs/SubscriptionJobs.ts +0 -382
- package/src/api/subscriptions/middleware/$requireLimit.ts +0 -50
- package/src/api/subscriptions/middleware/$requirePlan.ts +0 -49
- package/src/api/subscriptions/notifications/SubscriptionNotifications.ts +0 -110
- package/src/api/subscriptions/schemas/cancelSubscriptionSchema.ts +0 -8
- package/src/api/subscriptions/schemas/changePlanSchema.ts +0 -9
- package/src/api/subscriptions/schemas/createSubscriptionSchema.ts +0 -11
- package/src/api/subscriptions/schemas/entitlementsSchema.ts +0 -21
- package/src/api/subscriptions/schemas/mrrSchema.ts +0 -13
- package/src/api/subscriptions/schemas/planDefinitionSchema.ts +0 -71
- package/src/api/subscriptions/schemas/planResourceSchema.ts +0 -25
- package/src/api/subscriptions/schemas/subscriptionEventResourceSchema.ts +0 -8
- package/src/api/subscriptions/schemas/subscriptionQuerySchema.ts +0 -19
- package/src/api/subscriptions/schemas/subscriptionResourceSchema.ts +0 -6
- package/src/api/subscriptions/schemas/subscriptionSettingsSchema.ts +0 -32
- package/src/api/subscriptions/schemas/subscriptionStatsSchema.ts +0 -23
- package/src/api/subscriptions/services/BillingService.ts +0 -437
- package/src/api/subscriptions/services/SubscriptionConfig.ts +0 -56
- package/src/api/subscriptions/services/SubscriptionService.ts +0 -867
- package/src/api/subscriptions/services/UsageService.ts +0 -118
- package/src/api/workflows/__tests__/$workflow.spec.ts +0 -616
- package/src/api/workflows/controllers/AdminWorkflowController.ts +0 -191
- package/src/api/workflows/entities/workflowExecutions.ts +0 -74
- package/src/api/workflows/entities/workflowStepExecutions.ts +0 -74
- package/src/api/workflows/entities/workflowStepLogs.ts +0 -13
- package/src/api/workflows/index.browser.ts +0 -22
- package/src/api/workflows/index.ts +0 -115
- package/src/api/workflows/jobs/WorkflowJobs.ts +0 -77
- package/src/api/workflows/primitives/$workflow.ts +0 -202
- package/src/api/workflows/providers/WorkflowProvider.ts +0 -1284
- package/src/api/workflows/schemas/workflowActivitySchema.ts +0 -15
- package/src/api/workflows/schemas/workflowConfigAtom.ts +0 -51
- package/src/api/workflows/schemas/workflowExecutionDetailSchema.ts +0 -18
- package/src/api/workflows/schemas/workflowExecutionQuerySchema.ts +0 -26
- package/src/api/workflows/schemas/workflowExecutionResourceSchema.ts +0 -30
- package/src/api/workflows/schemas/workflowRegistrationSchema.ts +0 -26
- package/src/api/workflows/schemas/workflowStatsSchema.ts +0 -16
- package/src/api/workflows/schemas/workflowStepExecutionResourceSchema.ts +0 -15
- package/src/api/workflows/services/WorkflowService.ts +0 -382
- package/src/cli/core/templates/apiAppSecurityTs.ts +0 -43
- 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
|
-
});
|