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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/api/invitations/entities/invitations.ts","../../../src/orm/core/schemas/insertSchema.ts","../../../src/orm/core/schemas/updateSchema.ts","../../../src/orm/core/primitives/$entity.ts","../../../src/orm/core/constants/PG_SYMBOLS.ts","../../../src/orm/core/helpers/pgAttr.ts","../../../src/orm/core/schemas/databaseEnvSchema.ts","../../../src/api/invitations/providers/InvitationProvider.ts","../../../src/api/invitations/schemas/createInvitationSchema.ts","../../../src/api/invitations/schemas/invitationQuerySchema.ts","../../../src/api/invitations/schemas/invitationWithResourceInfoSchema.ts","../../../src/api/invitations/schemas/myInvitationsQuerySchema.ts","../../../src/api/invitations/services/InvitationService.ts","../../../src/api/invitations/controllers/AdminInvitationController.ts","../../../src/api/invitations/controllers/InvitationController.ts","../../../src/api/invitations/jobs/InvitationJobs.ts","../../../src/api/invitations/schemas/invitationConfigAtom.ts","../../../src/api/invitations/schemas/invitationResourceSchema.ts","../../../src/api/invitations/index.ts"],"mappings":";;;;;;;;;;;;;cAIa,WAAA,EAAW,aAAA,CAAA,eAAA,UAAA,OAAA;gDA0BtB,QAAA,CAAA,OAAA;;;;;;;;;;;;;;;;KAEU,gBAAA,GAAmB,MAAA,QAAc,WAAA,CAAY,MAAA;;;;;;;;;;;;KCnB7C,aAAA,WAAwB,OAAA,IAAW,OAAA,eACjC,CAAA,kBAAmB,CAAA,eAAgB,CAAA;EAAA,CAC5C,YAAA;AAA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UAAA,OAAA;kBAiB/B,QAAA,CAAA,QAAA;;;;;;;cChBW,wBAAA,WAAwB,OAAA;oBAAqB,QAAA,CAAA,OAAA;;;;;;;;;;;;;;;;KAE9C,kBAAA,GAAqB,MAAA,QAAc,wBAAA;;;;YCenC,KAAA;IACR,oBAAA;MACE,UAAA,EAL0C,gBAAA;MAM1C,KAAA;MACA,OAAA;QAAW,EAAA;QAAY,KAAA;MAAA;IAAA;IAEzB,qBAAA;MACE,UAAA,EALgE,gBAAA;MAMhE,UAAA;QAAc,EAAA;QAAY,KAAA;MAAA;IAAA;IAE5B,qBAAA;MACE,UAAA,EAJgE,gBAAA;MAKhE,UAAA;QAAc,EAAA;QAAY,KAAA;MAAA;IAAA;IAE5B,oBAAA;MACE,UAAA,EAJgE,gBAAA;IAAA;IAMlE,oBAAA;MACE,UAAA,EAHgE,gBAAA;MAIhE,SAAA;QAAa,EAAA;MAAA;IAAA;EAAA;AAAA;;;;;;cAUN,oBAAA,EAAoB,QAAA,CAAA,OAAA,CAQ/B,QAAA,CAR+B,MAAA"}
|
|
@@ -1,662 +0,0 @@
|
|
|
1
|
-
import { $atom, $inject, $module, Alepha, t } from "alepha";
|
|
2
|
-
import { $secure } from "alepha/security";
|
|
3
|
-
import { $action, BadRequestError, ForbiddenError, okSchema } from "alepha/server";
|
|
4
|
-
import { $entity, $repository, db, pageQuerySchema } from "alepha/orm";
|
|
5
|
-
import { users } from "alepha/api/users";
|
|
6
|
-
import { CryptoProvider } from "alepha/crypto";
|
|
7
|
-
import { DateTimeProvider } from "alepha/datetime";
|
|
8
|
-
import { $logger } from "alepha/logger";
|
|
9
|
-
import { $job } from "alepha/api/jobs";
|
|
10
|
-
//#region ../../src/api/invitations/schemas/invitationQuerySchema.ts
|
|
11
|
-
const invitationQuerySchema = t.extend(pageQuerySchema, {
|
|
12
|
-
email: t.optional(t.text({ description: "Filter by invited email" })),
|
|
13
|
-
resourceType: t.optional(t.text({ description: "Filter by resource type" })),
|
|
14
|
-
resourceId: t.optional(t.text({ description: "Filter by resource ID" })),
|
|
15
|
-
status: t.optional(t.enum([
|
|
16
|
-
"pending",
|
|
17
|
-
"accepted",
|
|
18
|
-
"declined",
|
|
19
|
-
"expired",
|
|
20
|
-
"revoked"
|
|
21
|
-
])),
|
|
22
|
-
invitedBy: t.optional(t.uuid())
|
|
23
|
-
});
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region ../../src/api/invitations/entities/invitations.ts
|
|
26
|
-
const invitations = $entity({
|
|
27
|
-
name: "invitations",
|
|
28
|
-
schema: t.object({
|
|
29
|
-
id: db.primaryKey(t.uuid()),
|
|
30
|
-
version: db.version(),
|
|
31
|
-
createdAt: db.createdAt(),
|
|
32
|
-
updatedAt: db.updatedAt(),
|
|
33
|
-
invitedBy: db.ref(t.uuid(), () => users.cols.id, { onDelete: "cascade" }),
|
|
34
|
-
email: t.string({ format: "email" }),
|
|
35
|
-
resourceType: t.text({
|
|
36
|
-
minLength: 1,
|
|
37
|
-
maxLength: 100
|
|
38
|
-
}),
|
|
39
|
-
resourceId: t.text({
|
|
40
|
-
minLength: 1,
|
|
41
|
-
maxLength: 255
|
|
42
|
-
}),
|
|
43
|
-
status: t.enum([
|
|
44
|
-
"pending",
|
|
45
|
-
"accepted",
|
|
46
|
-
"declined",
|
|
47
|
-
"expired",
|
|
48
|
-
"revoked"
|
|
49
|
-
]),
|
|
50
|
-
roles: t.optional(t.array(t.text())),
|
|
51
|
-
metadata: t.optional(t.record(t.text(), t.any())),
|
|
52
|
-
token: t.text(),
|
|
53
|
-
expiresAt: t.datetime(),
|
|
54
|
-
resolvedAt: t.optional(t.datetime()),
|
|
55
|
-
resolvedBy: t.optional(db.ref(t.uuid(), () => users.cols.id))
|
|
56
|
-
}),
|
|
57
|
-
indexes: [
|
|
58
|
-
{ columns: ["email", "status"] },
|
|
59
|
-
{ columns: [
|
|
60
|
-
"resourceType",
|
|
61
|
-
"resourceId",
|
|
62
|
-
"email",
|
|
63
|
-
"status"
|
|
64
|
-
] },
|
|
65
|
-
{ columns: ["invitedBy"] },
|
|
66
|
-
{ columns: ["expiresAt"] },
|
|
67
|
-
{
|
|
68
|
-
columns: ["token"],
|
|
69
|
-
unique: true
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
});
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region ../../src/api/invitations/schemas/invitationResourceSchema.ts
|
|
75
|
-
const invitationResourceSchema = invitations.schema;
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region ../../src/api/invitations/providers/InvitationProvider.ts
|
|
78
|
-
/**
|
|
79
|
-
* Abstract provider that apps implement to customize invitation behavior
|
|
80
|
-
* per resource type.
|
|
81
|
-
*/
|
|
82
|
-
var InvitationProvider = class {};
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region ../../src/api/invitations/schemas/invitationConfigAtom.ts
|
|
85
|
-
const invitationConfigAtom = $atom({
|
|
86
|
-
name: "alepha.api.invitations.config",
|
|
87
|
-
schema: t.object({
|
|
88
|
-
expirationDays: t.integer({
|
|
89
|
-
minimum: 1,
|
|
90
|
-
maximum: 90
|
|
91
|
-
}),
|
|
92
|
-
maxPendingPerResource: t.integer({
|
|
93
|
-
minimum: 1,
|
|
94
|
-
maximum: 500
|
|
95
|
-
}),
|
|
96
|
-
maxPendingPerInviter: t.integer({
|
|
97
|
-
minimum: 1,
|
|
98
|
-
maximum: 1e3
|
|
99
|
-
}),
|
|
100
|
-
purgeDays: t.integer({
|
|
101
|
-
minimum: 0,
|
|
102
|
-
maximum: 365
|
|
103
|
-
})
|
|
104
|
-
}),
|
|
105
|
-
default: {
|
|
106
|
-
expirationDays: 7,
|
|
107
|
-
maxPendingPerResource: 50,
|
|
108
|
-
maxPendingPerInviter: 100,
|
|
109
|
-
purgeDays: 90
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region ../../src/api/invitations/services/InvitationService.ts
|
|
114
|
-
var InvitationService = class {
|
|
115
|
-
alepha = $inject(Alepha);
|
|
116
|
-
log = $logger();
|
|
117
|
-
repo = $repository(invitations);
|
|
118
|
-
users = $repository(users);
|
|
119
|
-
crypto = $inject(CryptoProvider);
|
|
120
|
-
dateTime = $inject(DateTimeProvider);
|
|
121
|
-
provider = $inject(InvitationProvider);
|
|
122
|
-
/**
|
|
123
|
-
* Get an invitation by ID.
|
|
124
|
-
*/
|
|
125
|
-
async getById(id) {
|
|
126
|
-
return this.repo.getById(id);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Create a new invitation.
|
|
130
|
-
*/
|
|
131
|
-
async create(data, inviter) {
|
|
132
|
-
if (data.email === inviter.email) throw new BadRequestError("Cannot invite yourself");
|
|
133
|
-
await this.provider.validateResource(data.resourceType, data.resourceId, inviter);
|
|
134
|
-
const existingUser = await this.users.findOne({ where: { email: { eq: data.email } } });
|
|
135
|
-
if (existingUser) {
|
|
136
|
-
if (await this.provider.isMember(data.resourceType, data.resourceId, data.email, existingUser.id)) throw new BadRequestError("User is already a member of this resource");
|
|
137
|
-
}
|
|
138
|
-
if (await this.repo.findOne({ where: {
|
|
139
|
-
resourceType: { eq: data.resourceType },
|
|
140
|
-
resourceId: { eq: data.resourceId },
|
|
141
|
-
email: { eq: data.email },
|
|
142
|
-
status: { eq: "pending" }
|
|
143
|
-
} })) throw new BadRequestError("A pending invitation already exists for this email and resource");
|
|
144
|
-
const config = this.alepha.store.get(invitationConfigAtom);
|
|
145
|
-
if (await this.repo.count({
|
|
146
|
-
resourceType: { eq: data.resourceType },
|
|
147
|
-
resourceId: { eq: data.resourceId },
|
|
148
|
-
status: { eq: "pending" }
|
|
149
|
-
}) >= config.maxPendingPerResource) throw new BadRequestError(`Maximum pending invitations per resource reached (${config.maxPendingPerResource})`);
|
|
150
|
-
if (await this.repo.count({
|
|
151
|
-
invitedBy: { eq: inviter.id },
|
|
152
|
-
status: { eq: "pending" }
|
|
153
|
-
}) >= config.maxPendingPerInviter) throw new BadRequestError(`Maximum pending invitations per inviter reached (${config.maxPendingPerInviter})`);
|
|
154
|
-
const token = this.crypto.randomUUID();
|
|
155
|
-
const tokenHash = this.crypto.hash(token, "sha256");
|
|
156
|
-
const expiresAt = this.dateTime.now().add(config.expirationDays, "days").toISOString();
|
|
157
|
-
const entity = await this.repo.create({
|
|
158
|
-
invitedBy: inviter.id,
|
|
159
|
-
email: data.email,
|
|
160
|
-
resourceType: data.resourceType,
|
|
161
|
-
resourceId: data.resourceId,
|
|
162
|
-
status: "pending",
|
|
163
|
-
roles: data.roles,
|
|
164
|
-
metadata: data.metadata,
|
|
165
|
-
token: tokenHash,
|
|
166
|
-
expiresAt
|
|
167
|
-
});
|
|
168
|
-
this.log.info("Invitation created", {
|
|
169
|
-
id: entity.id,
|
|
170
|
-
email: data.email,
|
|
171
|
-
resourceType: data.resourceType,
|
|
172
|
-
resourceId: data.resourceId,
|
|
173
|
-
invitedBy: inviter.id
|
|
174
|
-
});
|
|
175
|
-
await this.alepha.events.emit("invitation:created", {
|
|
176
|
-
invitation: entity,
|
|
177
|
-
token,
|
|
178
|
-
inviter
|
|
179
|
-
});
|
|
180
|
-
return entity;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Accept a pending invitation.
|
|
184
|
-
*/
|
|
185
|
-
async accept(invitationId, acceptedBy) {
|
|
186
|
-
const invitation = await this.repo.getById(invitationId);
|
|
187
|
-
if (invitation.status !== "pending") throw new BadRequestError(`Invitation is not pending (current status: ${invitation.status})`);
|
|
188
|
-
if (invitation.email !== acceptedBy.email) throw new ForbiddenError("This invitation was sent to a different email");
|
|
189
|
-
const now = this.dateTime.now();
|
|
190
|
-
if (now.isAfter(invitation.expiresAt)) {
|
|
191
|
-
await this.repo.updateById(invitationId, {
|
|
192
|
-
status: "expired",
|
|
193
|
-
resolvedAt: now.toISOString()
|
|
194
|
-
});
|
|
195
|
-
throw new BadRequestError("Invitation has expired");
|
|
196
|
-
}
|
|
197
|
-
if (await this.provider.isMember(invitation.resourceType, invitation.resourceId, invitation.email, acceptedBy.id)) {
|
|
198
|
-
await this.repo.updateById(invitationId, {
|
|
199
|
-
status: "accepted",
|
|
200
|
-
resolvedAt: now.toISOString(),
|
|
201
|
-
resolvedBy: acceptedBy.id
|
|
202
|
-
});
|
|
203
|
-
this.log.info("Invitation accepted (already member)", {
|
|
204
|
-
id: invitationId,
|
|
205
|
-
acceptedBy: acceptedBy.id
|
|
206
|
-
});
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
await this.provider.onAccept(invitation, acceptedBy);
|
|
210
|
-
await this.repo.updateById(invitationId, {
|
|
211
|
-
status: "accepted",
|
|
212
|
-
resolvedAt: now.toISOString(),
|
|
213
|
-
resolvedBy: acceptedBy.id
|
|
214
|
-
});
|
|
215
|
-
this.log.info("Invitation accepted", {
|
|
216
|
-
id: invitationId,
|
|
217
|
-
email: invitation.email,
|
|
218
|
-
resourceType: invitation.resourceType,
|
|
219
|
-
resourceId: invitation.resourceId,
|
|
220
|
-
acceptedBy: acceptedBy.id
|
|
221
|
-
});
|
|
222
|
-
await this.alepha.events.emit("invitation:accepted", {
|
|
223
|
-
invitation,
|
|
224
|
-
acceptedBy
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Decline a pending invitation.
|
|
229
|
-
*/
|
|
230
|
-
async decline(invitationId, declinedBy) {
|
|
231
|
-
const invitation = await this.repo.getById(invitationId);
|
|
232
|
-
if (invitation.status !== "pending") throw new BadRequestError(`Invitation is not pending (current status: ${invitation.status})`);
|
|
233
|
-
if (invitation.email !== declinedBy.email) throw new ForbiddenError("This invitation was sent to a different email");
|
|
234
|
-
const now = this.dateTime.now();
|
|
235
|
-
await this.repo.updateById(invitationId, {
|
|
236
|
-
status: "declined",
|
|
237
|
-
resolvedAt: now.toISOString(),
|
|
238
|
-
resolvedBy: declinedBy.id
|
|
239
|
-
});
|
|
240
|
-
this.log.info("Invitation declined", {
|
|
241
|
-
id: invitationId,
|
|
242
|
-
email: invitation.email,
|
|
243
|
-
resourceType: invitation.resourceType,
|
|
244
|
-
resourceId: invitation.resourceId,
|
|
245
|
-
declinedBy: declinedBy.id
|
|
246
|
-
});
|
|
247
|
-
await this.alepha.events.emit("invitation:declined", {
|
|
248
|
-
invitation,
|
|
249
|
-
declinedBy
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Revoke a pending invitation (by the inviter or admin).
|
|
254
|
-
*/
|
|
255
|
-
async revoke(invitationId, revokedBy) {
|
|
256
|
-
const invitation = await this.repo.getById(invitationId);
|
|
257
|
-
if (invitation.status !== "pending") throw new BadRequestError(`Invitation is not pending (current status: ${invitation.status})`);
|
|
258
|
-
const now = this.dateTime.now();
|
|
259
|
-
await this.repo.updateById(invitationId, {
|
|
260
|
-
status: "revoked",
|
|
261
|
-
resolvedAt: now.toISOString(),
|
|
262
|
-
resolvedBy: revokedBy.id
|
|
263
|
-
});
|
|
264
|
-
this.log.info("Invitation revoked", {
|
|
265
|
-
id: invitationId,
|
|
266
|
-
email: invitation.email,
|
|
267
|
-
resourceType: invitation.resourceType,
|
|
268
|
-
resourceId: invitation.resourceId,
|
|
269
|
-
revokedBy: revokedBy.id
|
|
270
|
-
});
|
|
271
|
-
await this.alepha.events.emit("invitation:revoked", {
|
|
272
|
-
invitation,
|
|
273
|
-
revokedBy
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Find invitations for a given email with resource info enrichment.
|
|
278
|
-
*/
|
|
279
|
-
async findByEmail(email, query = {}) {
|
|
280
|
-
const where = this.repo.createQueryWhere();
|
|
281
|
-
where.email = { eq: email };
|
|
282
|
-
if (query.status) where.status = { eq: query.status };
|
|
283
|
-
const results = await this.repo.findMany({
|
|
284
|
-
where,
|
|
285
|
-
orderBy: {
|
|
286
|
-
column: "createdAt",
|
|
287
|
-
direction: "desc"
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
const inviterIds = [...new Set(results.map((inv) => inv.invitedBy))];
|
|
291
|
-
const inviters = await this.loadInviters(inviterIds);
|
|
292
|
-
const enriched = [];
|
|
293
|
-
for (const inv of results) {
|
|
294
|
-
const inviter = inviters.get(inv.invitedBy);
|
|
295
|
-
let resourceName = inv.resourceType;
|
|
296
|
-
let resourceUrl;
|
|
297
|
-
try {
|
|
298
|
-
const info = await this.provider.getResourceInfo(inv.resourceType, inv.resourceId);
|
|
299
|
-
resourceName = info.name;
|
|
300
|
-
resourceUrl = info.url;
|
|
301
|
-
} catch (error) {
|
|
302
|
-
this.log.warn("Failed to load resource info for invitation", {
|
|
303
|
-
invitationId: inv.id,
|
|
304
|
-
resourceType: inv.resourceType,
|
|
305
|
-
resourceId: inv.resourceId,
|
|
306
|
-
error
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
enriched.push({
|
|
310
|
-
id: inv.id,
|
|
311
|
-
email: inv.email,
|
|
312
|
-
resourceType: inv.resourceType,
|
|
313
|
-
resourceId: inv.resourceId,
|
|
314
|
-
resourceName,
|
|
315
|
-
resourceUrl,
|
|
316
|
-
invitedBy: inv.invitedBy,
|
|
317
|
-
inviterName: this.formatInviterName(inviter),
|
|
318
|
-
inviterEmail: inviter?.email,
|
|
319
|
-
roles: inv.roles,
|
|
320
|
-
status: inv.status,
|
|
321
|
-
createdAt: inv.createdAt,
|
|
322
|
-
expiresAt: inv.expiresAt
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
return enriched;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Find invitations for a specific resource.
|
|
329
|
-
*/
|
|
330
|
-
async findByResource(resourceType, resourceId, status) {
|
|
331
|
-
const where = this.repo.createQueryWhere();
|
|
332
|
-
where.resourceType = { eq: resourceType };
|
|
333
|
-
where.resourceId = { eq: resourceId };
|
|
334
|
-
if (status) where.status = { eq: status };
|
|
335
|
-
return this.repo.findMany({
|
|
336
|
-
where,
|
|
337
|
-
orderBy: {
|
|
338
|
-
column: "createdAt",
|
|
339
|
-
direction: "desc"
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Find invitations with pagination and filtering (admin).
|
|
345
|
-
*/
|
|
346
|
-
async findInvitations(query = {}) {
|
|
347
|
-
query.sort ??= "-createdAt";
|
|
348
|
-
const where = this.repo.createQueryWhere();
|
|
349
|
-
if (query.email) where.email = { like: `%${query.email}%` };
|
|
350
|
-
if (query.resourceType) where.resourceType = { eq: query.resourceType };
|
|
351
|
-
if (query.resourceId) where.resourceId = { eq: query.resourceId };
|
|
352
|
-
if (query.status) where.status = { eq: query.status };
|
|
353
|
-
if (query.invitedBy) where.invitedBy = { eq: query.invitedBy };
|
|
354
|
-
return this.repo.paginate(query, { where }, { count: true });
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Delete an invitation (admin). Only non-pending invitations can be deleted.
|
|
358
|
-
*/
|
|
359
|
-
async deleteInvitation(id) {
|
|
360
|
-
if ((await this.repo.getById(id)).status === "pending") throw new BadRequestError("Cannot delete a pending invitation. Revoke it first.");
|
|
361
|
-
await this.repo.deleteById(id);
|
|
362
|
-
this.log.info("Invitation deleted", { id });
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Expire all pending invitations that have passed their expiration date.
|
|
366
|
-
* Returns the number of expired invitations.
|
|
367
|
-
*/
|
|
368
|
-
async expirePending() {
|
|
369
|
-
const now = this.dateTime.nowISOString();
|
|
370
|
-
const expired = await this.repo.findMany({ where: {
|
|
371
|
-
status: { eq: "pending" },
|
|
372
|
-
expiresAt: { lt: now }
|
|
373
|
-
} });
|
|
374
|
-
if (expired.length === 0) return 0;
|
|
375
|
-
const ids = expired.map((inv) => inv.id);
|
|
376
|
-
await this.repo.updateMany({ id: { inArray: ids } }, {
|
|
377
|
-
status: "expired",
|
|
378
|
-
resolvedAt: now
|
|
379
|
-
});
|
|
380
|
-
for (const inv of expired) await this.alepha.events.emit("invitation:expired", { invitation: inv });
|
|
381
|
-
this.log.info("Expired pending invitations", { count: expired.length });
|
|
382
|
-
return expired.length;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Purge resolved invitations older than the configured purge days.
|
|
386
|
-
* Returns the number of purged invitations.
|
|
387
|
-
*/
|
|
388
|
-
async purgeResolved() {
|
|
389
|
-
const config = this.alepha.store.get(invitationConfigAtom);
|
|
390
|
-
if (config.purgeDays === 0) return 0;
|
|
391
|
-
const cutoff = this.dateTime.now().subtract(config.purgeDays, "days").toISOString();
|
|
392
|
-
const ids = await this.repo.deleteMany({
|
|
393
|
-
status: { inArray: [
|
|
394
|
-
"accepted",
|
|
395
|
-
"declined",
|
|
396
|
-
"expired",
|
|
397
|
-
"revoked"
|
|
398
|
-
] },
|
|
399
|
-
resolvedAt: { lt: cutoff }
|
|
400
|
-
});
|
|
401
|
-
if (ids.length > 0) this.log.info("Purged resolved invitations", { count: ids.length });
|
|
402
|
-
return ids.length;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Load user records for a list of inviter IDs.
|
|
406
|
-
*/
|
|
407
|
-
async loadInviters(ids) {
|
|
408
|
-
if (ids.length === 0) return /* @__PURE__ */ new Map();
|
|
409
|
-
const result = await this.users.findMany({ where: { id: { inArray: ids } } });
|
|
410
|
-
return new Map(result.map((user) => [user.id, user]));
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Format inviter display name from user entity.
|
|
414
|
-
*/
|
|
415
|
-
formatInviterName(user) {
|
|
416
|
-
if (!user) return;
|
|
417
|
-
if (user.firstName && user.lastName) return `${user.firstName} ${user.lastName}`;
|
|
418
|
-
if (user.firstName) return user.firstName;
|
|
419
|
-
return user.username ?? user.email;
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
//#endregion
|
|
423
|
-
//#region ../../src/api/invitations/controllers/AdminInvitationController.ts
|
|
424
|
-
var AdminInvitationController = class {
|
|
425
|
-
url = "/invitations";
|
|
426
|
-
group = "admin:invitations";
|
|
427
|
-
invitationService = $inject(InvitationService);
|
|
428
|
-
/**
|
|
429
|
-
* Find invitations with pagination and filtering.
|
|
430
|
-
*/
|
|
431
|
-
findInvitations = $action({
|
|
432
|
-
path: this.url,
|
|
433
|
-
group: this.group,
|
|
434
|
-
use: [$secure({ permissions: ["admin:invitation:read"] })],
|
|
435
|
-
description: "Find invitations with pagination and filtering",
|
|
436
|
-
schema: {
|
|
437
|
-
query: invitationQuerySchema,
|
|
438
|
-
response: t.page(invitationResourceSchema)
|
|
439
|
-
},
|
|
440
|
-
handler: ({ query }) => this.invitationService.findInvitations(query)
|
|
441
|
-
});
|
|
442
|
-
/**
|
|
443
|
-
* Get an invitation by ID.
|
|
444
|
-
*/
|
|
445
|
-
getInvitation = $action({
|
|
446
|
-
path: `${this.url}/:id`,
|
|
447
|
-
group: this.group,
|
|
448
|
-
use: [$secure({ permissions: ["admin:invitation:read"] })],
|
|
449
|
-
description: "Get an invitation by ID",
|
|
450
|
-
schema: {
|
|
451
|
-
params: t.object({ id: t.uuid() }),
|
|
452
|
-
response: invitationResourceSchema
|
|
453
|
-
},
|
|
454
|
-
handler: ({ params }) => this.invitationService.getById(params.id)
|
|
455
|
-
});
|
|
456
|
-
/**
|
|
457
|
-
* Revoke a pending invitation.
|
|
458
|
-
*/
|
|
459
|
-
revokeInvitation = $action({
|
|
460
|
-
method: "POST",
|
|
461
|
-
path: `${this.url}/:id/revoke`,
|
|
462
|
-
group: this.group,
|
|
463
|
-
use: [$secure({ permissions: ["admin:invitation:delete"] })],
|
|
464
|
-
description: "Revoke a pending invitation",
|
|
465
|
-
schema: {
|
|
466
|
-
params: t.object({ id: t.uuid() }),
|
|
467
|
-
response: okSchema
|
|
468
|
-
},
|
|
469
|
-
handler: async ({ params, user }) => {
|
|
470
|
-
await this.invitationService.revoke(params.id, { id: user.id });
|
|
471
|
-
return { ok: true };
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
/**
|
|
475
|
-
* Delete an invitation.
|
|
476
|
-
*/
|
|
477
|
-
deleteInvitation = $action({
|
|
478
|
-
method: "DELETE",
|
|
479
|
-
path: `${this.url}/:id`,
|
|
480
|
-
group: this.group,
|
|
481
|
-
use: [$secure({ permissions: ["admin:invitation:delete"] })],
|
|
482
|
-
description: "Delete an invitation",
|
|
483
|
-
schema: {
|
|
484
|
-
params: t.object({ id: t.uuid() }),
|
|
485
|
-
response: okSchema
|
|
486
|
-
},
|
|
487
|
-
handler: async ({ params }) => {
|
|
488
|
-
await this.invitationService.deleteInvitation(params.id);
|
|
489
|
-
return {
|
|
490
|
-
ok: true,
|
|
491
|
-
id: params.id
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
|
-
};
|
|
496
|
-
//#endregion
|
|
497
|
-
//#region ../../src/api/invitations/schemas/createInvitationSchema.ts
|
|
498
|
-
const createInvitationSchema = t.object({
|
|
499
|
-
email: t.string({ format: "email" }),
|
|
500
|
-
resourceType: t.text({
|
|
501
|
-
minLength: 1,
|
|
502
|
-
maxLength: 100
|
|
503
|
-
}),
|
|
504
|
-
resourceId: t.text({
|
|
505
|
-
minLength: 1,
|
|
506
|
-
maxLength: 255
|
|
507
|
-
}),
|
|
508
|
-
roles: t.optional(t.array(t.text())),
|
|
509
|
-
metadata: t.optional(t.record(t.text(), t.any()))
|
|
510
|
-
});
|
|
511
|
-
//#endregion
|
|
512
|
-
//#region ../../src/api/invitations/schemas/invitationWithResourceInfoSchema.ts
|
|
513
|
-
const invitationWithResourceInfoSchema = t.object({
|
|
514
|
-
id: t.uuid(),
|
|
515
|
-
email: t.string({ format: "email" }),
|
|
516
|
-
resourceType: t.text(),
|
|
517
|
-
resourceId: t.text(),
|
|
518
|
-
resourceName: t.text(),
|
|
519
|
-
resourceUrl: t.optional(t.text()),
|
|
520
|
-
invitedBy: t.uuid(),
|
|
521
|
-
inviterName: t.optional(t.text()),
|
|
522
|
-
inviterEmail: t.optional(t.string({ format: "email" })),
|
|
523
|
-
roles: t.optional(t.array(t.text())),
|
|
524
|
-
status: t.enum([
|
|
525
|
-
"pending",
|
|
526
|
-
"accepted",
|
|
527
|
-
"declined",
|
|
528
|
-
"expired",
|
|
529
|
-
"revoked"
|
|
530
|
-
]),
|
|
531
|
-
createdAt: t.datetime(),
|
|
532
|
-
expiresAt: t.datetime()
|
|
533
|
-
});
|
|
534
|
-
//#endregion
|
|
535
|
-
//#region ../../src/api/invitations/schemas/myInvitationsQuerySchema.ts
|
|
536
|
-
const myInvitationsQuerySchema = t.object({ status: t.optional(t.enum([
|
|
537
|
-
"pending",
|
|
538
|
-
"accepted",
|
|
539
|
-
"declined",
|
|
540
|
-
"expired",
|
|
541
|
-
"revoked"
|
|
542
|
-
])) });
|
|
543
|
-
//#endregion
|
|
544
|
-
//#region ../../src/api/invitations/controllers/InvitationController.ts
|
|
545
|
-
var InvitationController = class {
|
|
546
|
-
url = "/invitations";
|
|
547
|
-
group = "invitations";
|
|
548
|
-
invitationService = $inject(InvitationService);
|
|
549
|
-
/**
|
|
550
|
-
* Create a new invitation.
|
|
551
|
-
*/
|
|
552
|
-
createInvitation = $action({
|
|
553
|
-
method: "POST",
|
|
554
|
-
path: this.url,
|
|
555
|
-
group: this.group,
|
|
556
|
-
use: [$secure({ permissions: ["invitation:create"] })],
|
|
557
|
-
description: "Create a new invitation",
|
|
558
|
-
schema: {
|
|
559
|
-
body: createInvitationSchema,
|
|
560
|
-
response: invitationResourceSchema
|
|
561
|
-
},
|
|
562
|
-
handler: ({ body, user }) => this.invitationService.create(body, user)
|
|
563
|
-
});
|
|
564
|
-
/**
|
|
565
|
-
* List invitations for the current user.
|
|
566
|
-
*/
|
|
567
|
-
getMyInvitations = $action({
|
|
568
|
-
path: `${this.url}/mine`,
|
|
569
|
-
group: this.group,
|
|
570
|
-
use: [$secure()],
|
|
571
|
-
description: "List invitations for the current user",
|
|
572
|
-
schema: {
|
|
573
|
-
query: myInvitationsQuerySchema,
|
|
574
|
-
response: t.array(invitationWithResourceInfoSchema)
|
|
575
|
-
},
|
|
576
|
-
handler: ({ query, user }) => this.invitationService.findByEmail(user.email, query)
|
|
577
|
-
});
|
|
578
|
-
/**
|
|
579
|
-
* Accept an invitation.
|
|
580
|
-
*/
|
|
581
|
-
acceptInvitation = $action({
|
|
582
|
-
method: "POST",
|
|
583
|
-
path: `${this.url}/:id/accept`,
|
|
584
|
-
group: this.group,
|
|
585
|
-
use: [$secure()],
|
|
586
|
-
description: "Accept an invitation",
|
|
587
|
-
schema: {
|
|
588
|
-
params: t.object({ id: t.uuid() }),
|
|
589
|
-
response: okSchema
|
|
590
|
-
},
|
|
591
|
-
handler: async ({ params, user }) => {
|
|
592
|
-
await this.invitationService.accept(params.id, user);
|
|
593
|
-
return { ok: true };
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
/**
|
|
597
|
-
* Decline an invitation.
|
|
598
|
-
*/
|
|
599
|
-
declineInvitation = $action({
|
|
600
|
-
method: "POST",
|
|
601
|
-
path: `${this.url}/:id/decline`,
|
|
602
|
-
group: this.group,
|
|
603
|
-
use: [$secure()],
|
|
604
|
-
description: "Decline an invitation",
|
|
605
|
-
schema: {
|
|
606
|
-
params: t.object({ id: t.uuid() }),
|
|
607
|
-
response: okSchema
|
|
608
|
-
},
|
|
609
|
-
handler: async ({ params, user }) => {
|
|
610
|
-
await this.invitationService.decline(params.id, user);
|
|
611
|
-
return { ok: true };
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
};
|
|
615
|
-
//#endregion
|
|
616
|
-
//#region ../../src/api/invitations/jobs/InvitationJobs.ts
|
|
617
|
-
var InvitationJobs = class {
|
|
618
|
-
log = $logger();
|
|
619
|
-
invitationService = $inject(InvitationService);
|
|
620
|
-
/**
|
|
621
|
-
* Expire pending invitations that have passed their expiration date.
|
|
622
|
-
*/
|
|
623
|
-
expireInvitations = $job({
|
|
624
|
-
cron: "0 * * * *",
|
|
625
|
-
lock: true,
|
|
626
|
-
handler: async () => {
|
|
627
|
-
const count = await this.invitationService.expirePending();
|
|
628
|
-
if (count > 0) this.log.info(`Expired ${count} invitations`);
|
|
629
|
-
}
|
|
630
|
-
});
|
|
631
|
-
/**
|
|
632
|
-
* Purge old resolved invitations.
|
|
633
|
-
*/
|
|
634
|
-
purgeInvitations = $job({
|
|
635
|
-
cron: "0 3 * * *",
|
|
636
|
-
lock: true,
|
|
637
|
-
handler: async () => {
|
|
638
|
-
const count = await this.invitationService.purgeResolved();
|
|
639
|
-
if (count > 0) this.log.info(`Purged ${count} old invitations`);
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
};
|
|
643
|
-
//#endregion
|
|
644
|
-
//#region ../../src/api/invitations/index.ts
|
|
645
|
-
/**
|
|
646
|
-
* Invitation management module — create, accept, decline, revoke, and expire invitations.
|
|
647
|
-
*
|
|
648
|
-
* @module alepha.api.invitations
|
|
649
|
-
*/
|
|
650
|
-
const AlephaApiInvitations = $module({
|
|
651
|
-
name: "alepha.api.invitations",
|
|
652
|
-
services: [
|
|
653
|
-
InvitationService,
|
|
654
|
-
InvitationJobs,
|
|
655
|
-
InvitationController,
|
|
656
|
-
AdminInvitationController
|
|
657
|
-
]
|
|
658
|
-
});
|
|
659
|
-
//#endregion
|
|
660
|
-
export { AdminInvitationController, AlephaApiInvitations, InvitationController, InvitationJobs, InvitationProvider, InvitationService, createInvitationSchema, invitationConfigAtom, invitationQuerySchema, invitationResourceSchema, invitationWithResourceInfoSchema, invitations, myInvitationsQuerySchema };
|
|
661
|
-
|
|
662
|
-
//# sourceMappingURL=index.js.map
|