@headless-lms/core 0.3.0 → 0.4.0
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/assets/events.d.ts +9 -9
- package/dist/assets/index.d.ts +3 -2
- package/dist/assets/index.js +2 -1
- package/dist/assets/jobs.d.ts +15 -0
- package/dist/assets/jobs.js +30 -0
- package/dist/assets/jobs.js.map +1 -0
- package/dist/assets/ports.d.ts +4 -3
- package/dist/assets/service.d.ts +0 -1
- package/dist/assets/service.js +0 -4
- package/dist/assets/service.js.map +1 -1
- package/dist/automations/actions.js +2 -63
- package/dist/automations/actions.js.map +1 -1
- package/dist/automations/catalog.d.ts +1 -2
- package/dist/automations/catalog.js +69 -62
- package/dist/automations/catalog.js.map +1 -1
- package/dist/automations/community-derivations.js +4 -4
- package/dist/automations/community-derivations.js.map +1 -1
- package/dist/automations/community-mail.d.ts +3 -17
- package/dist/automations/community-mail.js +1 -21
- package/dist/automations/community-mail.js.map +1 -1
- package/dist/automations/events.d.ts +0 -10
- package/dist/automations/index.d.ts +11 -4
- package/dist/automations/index.js +8 -1
- package/dist/automations/notifications/debounce.d.ts +25 -0
- package/dist/automations/notifications/debounce.js +93 -0
- package/dist/automations/notifications/debounce.js.map +1 -0
- package/dist/automations/notifications/defaults.d.ts +8 -0
- package/dist/automations/notifications/defaults.js +316 -0
- package/dist/automations/notifications/defaults.js.map +1 -0
- package/dist/automations/notifications/delivery.d.ts +28 -0
- package/dist/automations/notifications/delivery.js +88 -0
- package/dist/automations/notifications/delivery.js.map +1 -0
- package/dist/automations/notifications/processor.d.ts +64 -0
- package/dist/automations/notifications/processor.js +270 -0
- package/dist/automations/notifications/processor.js.map +1 -0
- package/dist/automations/notifications/rules/content.d.ts +6 -0
- package/dist/automations/notifications/rules/content.js +39 -0
- package/dist/automations/notifications/rules/content.js.map +1 -0
- package/dist/automations/notifications/rules/discussion.d.ts +7 -0
- package/dist/automations/notifications/rules/discussion.js +678 -0
- package/dist/automations/notifications/rules/discussion.js.map +1 -0
- package/dist/automations/notifications/rules/entitlements.d.ts +6 -0
- package/dist/automations/notifications/rules/entitlements.js +249 -0
- package/dist/automations/notifications/rules/entitlements.js.map +1 -0
- package/dist/automations/notifications/rules/index.d.ts +6 -0
- package/dist/automations/notifications/rules/index.js +15 -0
- package/dist/automations/notifications/rules/index.js.map +1 -0
- package/dist/automations/notifications/rules/organizations.d.ts +6 -0
- package/dist/automations/notifications/rules/organizations.js +28 -0
- package/dist/automations/notifications/rules/organizations.js.map +1 -0
- package/dist/automations/notifications/rules/recipients.d.ts +32 -0
- package/dist/automations/notifications/rules/recipients.js +99 -0
- package/dist/automations/notifications/rules/recipients.js.map +1 -0
- package/dist/automations/notifications/service.d.ts +27 -0
- package/dist/automations/notifications/service.js +45 -0
- package/dist/automations/notifications/service.js.map +1 -0
- package/dist/automations/notifications/types.d.ts +7 -0
- package/dist/automations/notifications/types.js +473 -0
- package/dist/automations/notifications/types.js.map +1 -0
- package/dist/automations/ports.d.ts +119 -5
- package/dist/automations/service.d.ts +10 -13
- package/dist/automations/service.js +21 -83
- package/dist/automations/service.js.map +1 -1
- package/dist/content/events.d.ts +130 -80
- package/dist/content/events.js +11 -0
- package/dist/content/events.js.map +1 -1
- package/dist/content/index.d.ts +6 -4
- package/dist/content/index.js +3 -1
- package/dist/content/model.d.ts +2 -2
- package/dist/content/notification-categories.d.ts +36 -0
- package/dist/content/notification-categories.js +64 -0
- package/dist/content/notification-categories.js.map +1 -0
- package/dist/content/ports.d.ts +25 -6
- package/dist/content/service.d.ts +4 -4
- package/dist/content/service.js +24 -8
- package/dist/content/service.js.map +1 -1
- package/dist/content/titles.d.ts +22 -0
- package/dist/content/titles.js +69 -0
- package/dist/content/titles.js.map +1 -0
- package/dist/content/types.d.ts +2 -2
- package/dist/discussion/chats.d.ts +9 -4
- package/dist/discussion/chats.js +80 -47
- package/dist/discussion/chats.js.map +1 -1
- package/dist/discussion/digests.d.ts +24 -0
- package/dist/discussion/digests.js +104 -0
- package/dist/discussion/digests.js.map +1 -0
- package/dist/discussion/events.d.ts +194 -28
- package/dist/discussion/events.js +74 -17
- package/dist/discussion/events.js.map +1 -1
- package/dist/discussion/index.d.ts +7 -2
- package/dist/discussion/index.js +6 -1
- package/dist/discussion/jobs.d.ts +16 -0
- package/dist/discussion/jobs.js +40 -0
- package/dist/discussion/jobs.js.map +1 -0
- package/dist/discussion/mentions.d.ts +11 -0
- package/dist/discussion/mentions.js +35 -0
- package/dist/discussion/mentions.js.map +1 -0
- package/dist/discussion/ports.d.ts +107 -24
- package/dist/discussion/ports.js.map +1 -1
- package/dist/discussion/posts.d.ts +18 -8
- package/dist/discussion/posts.js +207 -155
- package/dist/discussion/posts.js.map +1 -1
- package/dist/discussion/service.d.ts +17 -8
- package/dist/discussion/service.js +105 -41
- package/dist/discussion/service.js.map +1 -1
- package/dist/discussion/subscriptions.d.ts +37 -0
- package/dist/discussion/subscriptions.js +99 -0
- package/dist/discussion/subscriptions.js.map +1 -0
- package/dist/discussion/titles.d.ts +26 -0
- package/dist/discussion/titles.js +84 -0
- package/dist/discussion/titles.js.map +1 -0
- package/dist/entitlements/events.d.ts +20 -20
- package/dist/entitlements/index.d.ts +2 -1
- package/dist/entitlements/index.js +2 -1
- package/dist/entitlements/jobs.d.ts +12 -0
- package/dist/entitlements/jobs.js +18 -0
- package/dist/entitlements/jobs.js.map +1 -0
- package/dist/entitlements/ports.d.ts +7 -3
- package/dist/entitlements/service.d.ts +5 -2
- package/dist/entitlements/service.js +23 -3
- package/dist/entitlements/service.js.map +1 -1
- package/dist/identity/devices.d.ts +30 -0
- package/dist/identity/devices.js +107 -0
- package/dist/identity/devices.js.map +1 -0
- package/dist/identity/events.d.ts +2 -2
- package/dist/identity/index.d.ts +5 -4
- package/dist/identity/index.js +3 -2
- package/dist/identity/model.d.ts +2 -2
- package/dist/identity/notification-settings.d.ts +28 -0
- package/dist/identity/notification-settings.js +113 -0
- package/dist/identity/notification-settings.js.map +1 -0
- package/dist/identity/ports.d.ts +78 -54
- package/dist/integrations/events.d.ts +3 -3
- package/dist/organizations/events.d.ts +32 -32
- package/dist/organizations/index.d.ts +2 -1
- package/dist/organizations/index.js +2 -1
- package/dist/organizations/notification-categories.d.ts +32 -0
- package/dist/organizations/notification-categories.js +51 -0
- package/dist/organizations/notification-categories.js.map +1 -0
- package/dist/organizations/ports.d.ts +3 -0
- package/dist/organizations/service.d.ts +2 -0
- package/dist/organizations/service.js +7 -0
- package/dist/organizations/service.js.map +1 -1
- package/dist/progress/events.d.ts +14 -14
- package/dist/reporting/member/index.d.ts +2 -2
- package/dist/reporting/member/model.d.ts +56 -23
- package/dist/reporting/member/ports.d.ts +9 -6
- package/dist/reporting/member/service.d.ts +33 -14
- package/dist/reporting/member/service.js +138 -60
- package/dist/reporting/member/service.js.map +1 -1
- package/dist/shared/errors.d.ts +13 -1
- package/dist/shared/errors.js +18 -1
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/id.d.ts +3 -0
- package/dist/shared/id.js +4 -1
- package/dist/shared/id.js.map +1 -1
- package/dist/shared/mailer.d.ts +11 -1
- package/dist/shared/mailer.js +32 -5
- package/dist/shared/mailer.js.map +1 -1
- package/dist/shared/notification-categories.d.ts +16 -0
- package/dist/shared/notification-categories.js +94 -0
- package/dist/shared/notification-categories.js.map +1 -0
- package/dist/shared/notification-settings.d.ts +14 -0
- package/dist/shared/notification-settings.js +61 -0
- package/dist/shared/notification-settings.js.map +1 -0
- package/dist/shared/ports.d.ts +48 -2
- package/dist/shared/settings.d.ts +2 -1
- package/dist/shared/settings.js +1 -0
- package/dist/shared/settings.js.map +1 -1
- package/dist/types/automations.d.ts +8 -2
- package/dist/types/content.d.ts +2 -2
- package/dist/types/discussion.d.ts +2 -2
- package/dist/types/email-templates.d.ts +97 -3
- package/dist/types/identity.d.ts +2 -2
- package/dist/types/index.d.ts +7 -6
- package/dist/types/notifications.d.ts +157 -0
- package/dist/types/notifications.js +1 -0
- package/dist/types/schemas/automations.d.ts +1 -10
- package/dist/types/schemas/automations.js +1 -3
- package/dist/types/schemas/automations.js.map +1 -1
- package/dist/types/schemas/content.d.ts +62 -1
- package/dist/types/schemas/content.js +25 -3
- package/dist/types/schemas/content.js.map +1 -1
- package/dist/types/schemas/discussion.d.ts +85 -12
- package/dist/types/schemas/discussion.js +47 -13
- package/dist/types/schemas/discussion.js.map +1 -1
- package/dist/types/schemas/identity.d.ts +1 -85
- package/dist/types/schemas/identity.js +1 -42
- package/dist/types/schemas/identity.js.map +1 -1
- package/dist/types/schemas/index.d.ts +6 -5
- package/dist/types/schemas/index.js +6 -5
- package/dist/types/schemas/notifications.d.ts +95 -0
- package/dist/types/schemas/notifications.js +56 -0
- package/dist/types/schemas/notifications.js.map +1 -0
- package/dist/types/schemas/progress.d.ts +3 -3
- package/package.json +1 -1
- package/dist/automations/community-notifications.d.ts +0 -16
- package/dist/automations/community-notifications.js +0 -84
- package/dist/automations/community-notifications.js.map +0 -1
- package/dist/automations/seeds.d.ts +0 -17
- package/dist/automations/seeds.js +0 -235
- package/dist/automations/seeds.js.map +0 -1
- package/dist/identity/notifications.d.ts +0 -27
- package/dist/identity/notifications.js +0 -101
- package/dist/identity/notifications.js.map +0 -1
|
@@ -18,8 +18,10 @@ interface OrganizationService {
|
|
|
18
18
|
getByExternalId(externalId: string): Promise<Organization | null>;
|
|
19
19
|
getOrgUser(orgId: string, userId: string): Promise<OrgUser | null>;
|
|
20
20
|
getOrgUserById(orgId: string, id: string): Promise<OrgUser | null>;
|
|
21
|
+
getOrgUsersByIds(orgId: string, ids: string[]): Promise<OrgUser[]>;
|
|
21
22
|
getOrgUsersForUser(userId: string): Promise<OrgUser[]>;
|
|
22
23
|
getById(id: string): Promise<Organization | null>;
|
|
24
|
+
orgIds(): Promise<string[]>;
|
|
23
25
|
createInvite(actor: Actor, input: CreateInviteInput): Promise<Invite>;
|
|
24
26
|
peekInvite(token: string): Promise<Invite | null>;
|
|
25
27
|
acceptInvite(input: AcceptInviteInput): Promise<OrgUser>;
|
|
@@ -60,6 +62,7 @@ interface OrganizationsRepository {
|
|
|
60
62
|
/** Drops the org row and its dependents; null when none matched. */
|
|
61
63
|
delete(id: string): Promise<Organization>;
|
|
62
64
|
findById(id: string): Promise<Organization | null>;
|
|
65
|
+
listIds(): Promise<string[]>;
|
|
63
66
|
findByExternalId(externalId: string): Promise<Organization | null>;
|
|
64
67
|
findBySlug(slug: string): Promise<Organization | null>;
|
|
65
68
|
/** Inserts a pending invite, or re-issues the org's existing pending one
|
|
@@ -49,10 +49,12 @@ declare class OrganizationServiceImpl implements OrganizationService {
|
|
|
49
49
|
private acceptStudentInvite;
|
|
50
50
|
private acceptStaffInvite;
|
|
51
51
|
getOrgUserById(orgId: string, id: string): Promise<OrgUser | null>;
|
|
52
|
+
getOrgUsersByIds(orgId: string, ids: string[]): Promise<OrgUser[]>;
|
|
52
53
|
getOrgUser(orgId: string, userId: string): Promise<OrgUser | null>;
|
|
53
54
|
deleteOrgUser(orgId: string, actor: Actor, id: string): Promise<OrgUser>;
|
|
54
55
|
getOrgUsersForUser(userId: string): Promise<OrgUser[]>;
|
|
55
56
|
getById(id: string): Promise<Organization | null>;
|
|
57
|
+
orgIds(): Promise<string[]>;
|
|
56
58
|
private sendInviteEmail;
|
|
57
59
|
getByExternalId(externalId: string): Promise<Organization | null>;
|
|
58
60
|
getBySlug(slug: string): Promise<Organization | null>;
|
|
@@ -316,6 +316,10 @@ var OrganizationServiceImpl = class {
|
|
|
316
316
|
getOrgUserById(orgId, id) {
|
|
317
317
|
return this.repo.findOrgUserById(orgId, id);
|
|
318
318
|
}
|
|
319
|
+
async getOrgUsersByIds(orgId, ids) {
|
|
320
|
+
const unique = [...new Set(ids)];
|
|
321
|
+
return unique.length > 0 ? this.repo.findOrgUsersByIds(orgId, unique) : [];
|
|
322
|
+
}
|
|
319
323
|
async getOrgUser(orgId, userId) {
|
|
320
324
|
return this.repo.findOrgUser(orgId, userId);
|
|
321
325
|
}
|
|
@@ -344,6 +348,9 @@ var OrganizationServiceImpl = class {
|
|
|
344
348
|
async getById(id) {
|
|
345
349
|
return this.repo.findById(id);
|
|
346
350
|
}
|
|
351
|
+
orgIds() {
|
|
352
|
+
return this.repo.listIds();
|
|
353
|
+
}
|
|
347
354
|
async sendInviteEmail(invite, token) {
|
|
348
355
|
if (!this.mailer || !this.inviteUrls) throw new Error("invite delivery is not configured (mailer / invite urls missing)");
|
|
349
356
|
const { email, role } = invite;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","names":[],"sources":["../../src/organizations/service.ts"],"sourcesContent":["// organizations context — service implementation (inbound port).\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport type {\n MemberRecord,\n MembersRepository,\n MemberWriteContext,\n OrgAdmin,\n OrganizationService,\n OrganizationsRepository,\n OrganizationsUnitOfWork,\n} from './ports.js';\nimport type { Invite, Organization, OrgUser } from './model.js';\nimport { capability, type Role, STAFF_ROLES, STUDENT_ROLE } from './roles.js';\nimport {\n InviteError,\n type Member,\n type MemberRoleChange,\n type MembersQuery,\n OrganizationRuleError,\n type Page,\n} from './members.js';\nimport type {\n AcceptInviteInput,\n AddOrgUserInput,\n CreateInviteInput,\n CreateOrganizationInput,\n ResendStudentInviteInput,\n UpdateOrganizationInput,\n UpdateOrgUserInput,\n} from './types.js';\nimport { organizationEvents, type OrganizationEvent } from './events.js';\nimport type { Logger, NewDomainEvent } from '../shared/ports.js';\nimport { noopLogger } from '../shared/logger.js';\nimport type { Mailer } from '../shared/mailer.js';\nimport { generateInviteToken, hashInviteToken } from '../shared/invite-token.js';\nimport { ForbiddenError, NotFoundError } from '../shared/errors.js';\nimport type { Actor } from '../shared/actor.js';\nimport type { IdentityService } from '../identity/index.js';\nimport { genId } from '../shared/id.js';\n\nconst INVITE_TTL_MS = 7 * 24 * 60 * 60 * 1000;\n\ntype NewOrganizationEvent = NewDomainEvent<OrganizationEvent>;\n\ninterface MemberWrite {\n orgUserId: string;\n actorOrgUserId: string;\n demote: boolean;\n}\n\nexport interface InviteUrls {\n studentPortalUrl: string;\n adminAppUrl: string;\n}\n\nfunction toMember(r: MemberRecord): Member {\n return {\n id: r.id,\n firstName: r.firstName,\n lastName: r.lastName,\n email: r.email,\n image: r.image,\n role: r.role,\n status: r.status,\n joinedAt: r.joinedAt,\n invitedAt: r.invitedAt,\n };\n}\n\nexport type OrganizationServiceParams = {\n repo: OrganizationsRepository;\n membersRepo: MembersRepository;\n people: IdentityService;\n uow: OrganizationsUnitOfWork;\n orgAdmin: () => OrgAdmin;\n logger?: Logger;\n mailer?: Pick<Mailer, 'send'>;\n inviteUrls?: InviteUrls;\n};\n\nexport class OrganizationServiceImpl implements OrganizationService {\n private readonly repo: OrganizationsRepository;\n private readonly membersRepo: MembersRepository;\n private readonly people: IdentityService;\n private readonly uow: OrganizationsUnitOfWork;\n private readonly orgAdmin: () => OrgAdmin;\n private readonly logger: Logger;\n private readonly mailer?: Pick<Mailer, 'send'>;\n private readonly inviteUrls?: InviteUrls;\n private readonly memberWrites = new AsyncLocalStorage<MemberWrite>();\n\n constructor(params: OrganizationServiceParams) {\n this.repo = params.repo;\n this.membersRepo = params.membersRepo;\n this.people = params.people;\n this.uow = params.uow;\n this.orgAdmin = params.orgAdmin;\n this.logger = params.logger ?? noopLogger;\n this.mailer = params.mailer;\n this.inviteUrls = params.inviteUrls;\n }\n\n async createOrganization(input: CreateOrganizationInput): Promise<Organization> {\n const created = await this.uow.run(async ({ organizations, outbox }) => {\n const id = genId('organization');\n\n const created = await organizations.create({\n id,\n // The auth provider adopts this id for its own org row, so the org is\n // its own external id — a lookup by either id lands on the same row.\n externalId: input.externalId ?? id,\n name: input.name ?? `My Org`,\n slug: input.slug ?? '',\n ownerId: input.ownerId,\n });\n await outbox.append([\n organizationEvents.organizationCreated.make({\n orgId: created.id,\n data: created,\n }),\n ]);\n return created;\n });\n this.logger.info('organization created', { orgId: created.id, slug: created.slug });\n return created;\n }\n\n async updateOrganization(id: string, input: UpdateOrganizationInput): Promise<Organization> {\n const updatedOrg = await this.uow.run(async ({ organizations, outbox }) => {\n const updated = await organizations.update(id, {\n name: input.name,\n slug: input.slug,\n });\n if (!updated) {\n throw new NotFoundError('Organization', id);\n }\n await outbox.append([\n organizationEvents.organizationUpdated.make({ orgId: id, data: updated }),\n ]);\n return updated;\n });\n\n this.logger.info('organization updated', { updatedOrg });\n return updatedOrg!;\n }\n\n async deleteOrganization(id: string): Promise<Organization> {\n const deleted = await this.uow.run(async ({ organizations, outbox }) => {\n const deleted = await organizations.delete(id);\n\n await outbox.append([\n organizationEvents.organizationDeleted.make({\n orgId: deleted.id,\n data: deleted,\n }),\n ]);\n return deleted;\n });\n this.logger.info('organization deleted', { orgId: deleted.id });\n return deleted;\n }\n\n async addOrgUser({ orgId, userId, role }: AddOrgUserInput): Promise<OrgUser> {\n const existing = await this.repo.findOrgUser(orgId, userId);\n if (existing) {\n return this.updateOrgUser(orgId, userId, { role, status: 'active' });\n }\n const orgUser = await this.uow.run(async ({ organizations, outbox }) => {\n const created = await organizations.createOrgUser({ orgId, role, userId, status: 'active' });\n await outbox.append([organizationEvents.orgUserLinked.make({ orgId, data: created })]);\n return created;\n });\n this.logger.info('user added to organization', { orgId, userId, role });\n return orgUser;\n }\n\n async removeOrgUser(orgId: string, userId: string): Promise<OrgUser> {\n const deleted = await this.uow.run(async ({ organizations, outbox }) => {\n const orgUser = await organizations.findOrgUser(orgId, userId);\n if (!orgUser) {\n throw new NotFoundError('Member', userId);\n }\n const write = this.memberWrite(orgUser.id);\n if (write?.demote) {\n const demoted = await organizations.updateOrgUser(orgId, orgUser.id, {\n role: STUDENT_ROLE,\n });\n if (!demoted) {\n throw new NotFoundError('Member', orgUser.id);\n }\n if (orgUser.role !== STUDENT_ROLE) {\n await outbox.append([\n organizationEvents.orgUserUpdated.make({\n orgId,\n data: demoted,\n metadata: { actorOrgUserId: write.actorOrgUserId },\n }),\n ]);\n }\n return demoted;\n }\n if (orgUser.role === STUDENT_ROLE) {\n return orgUser;\n }\n const deletedUser = await organizations.deleteOrgUser(orgId, orgUser.id);\n if (!deletedUser) {\n throw new NotFoundError('Member', orgUser.id);\n }\n await outbox.append([\n organizationEvents.orgUserDeleted.make({\n orgId,\n data: deletedUser,\n }),\n ]);\n return deletedUser;\n });\n this.logger.info('org user removed', { orgId, userId, orgUserId: deleted.id });\n return deleted;\n }\n\n async updateOrgUser(orgId: string, userId: string, patch: UpdateOrgUserInput): Promise<OrgUser> {\n const updated = await this.uow.run(async ({ organizations, outbox }) => {\n const orgUser = await organizations.findOrgUser(orgId, userId);\n if (!orgUser) {\n throw new NotFoundError('Member', userId);\n }\n const next = await organizations.updateOrgUser(orgId, orgUser.id, patch);\n if (!next) {\n throw new NotFoundError('Member', orgUser.id);\n }\n if (patch.role !== undefined && patch.role !== orgUser.role) {\n const actorOrgUserId = this.memberWrite(orgUser.id)?.actorOrgUserId;\n await outbox.append([\n organizationEvents.orgUserUpdated.make({\n orgId,\n data: next,\n ...(actorOrgUserId !== undefined && { metadata: { actorOrgUserId } }),\n }),\n ]);\n }\n return next;\n });\n this.logger.info('org user updated', { orgId, userId, orgUserId: updated.id, patch });\n return updated;\n }\n\n async createInvite(actor: Actor, input: CreateInviteInput): Promise<Invite> {\n const { orgId, email, role, inviterUserId, firstName, lastName } = input;\n this.assertManagesUsers(actor, orgId);\n this.assertNotOwner(role, orgId);\n const sendEmail = input.sendEmail ?? true;\n const { token, tokenHash } = generateInviteToken();\n const expiresAt = new Date(Date.now() + INVITE_TTL_MS);\n\n // A student belongs to the org from the moment an admin adds them, not from\n // the moment they click a link — so the person exists before the invite\n // does. Staff are excluded: their org_users row is mirrored from the auth\n // provider's member record, which does not exist until they join.\n const person =\n role === STUDENT_ROLE\n ? ((await this.people.getUserByEmail(email)) ??\n (await this.people.createUser({\n email,\n ...(firstName !== undefined && { firstName }),\n ...(lastName !== undefined && { lastName }),\n })))\n : null;\n\n const invite = await this.uow.run(async ({ organizations, outbox }) => {\n const events: NewOrganizationEvent[] = [];\n if (person) {\n const orgUser = await organizations.createOrgUser({\n orgId,\n userId: person.id,\n role: STUDENT_ROLE,\n status: 'invited',\n });\n events.push(organizationEvents.studentCreated.make({ orgId, data: orgUser }));\n }\n const row = await organizations.upsertPendingInvite(orgId, {\n email,\n role,\n invitedBy: inviterUserId,\n tokenHash,\n expiresAt,\n });\n events.push(organizationEvents.inviteCreated.make({ orgId, data: row }));\n await outbox.append(events);\n return row;\n });\n\n if (sendEmail) {\n // TODO make this workflow durable\n try {\n await this.sendInviteEmail(invite, token);\n } catch (err) {\n // A failed email must not abort invite creation: the token is already\n // minted and recorded, so the admin can fix transport and resend.\n this.logger.error('failed to send invite email', {\n orgId,\n inviteId: invite.id,\n role: invite.role,\n err: err instanceof Error ? err : new Error(String(err)),\n });\n }\n }\n\n this.logger.info('invite created', { orgId, inviteId: invite.id, role, sendEmail });\n return invite;\n }\n\n async resendStudentInvite(actor: Actor, input: ResendStudentInviteInput): Promise<void> {\n const { orgId, orgUserId, inviterUserId } = input;\n this.assertManagesUsers(actor, orgId);\n const orgUser = await this.repo.findOrgUserById(orgId, orgUserId);\n if (!orgUser || orgUser.role !== STUDENT_ROLE) {\n throw new NotFoundError('Student', orgUserId);\n }\n if (orgUser.status === 'active') {\n throw new OrganizationRuleError('That student has already accepted their invitation');\n }\n const person = await this.people.getUserById(orgUser.userId);\n if (!person) {\n throw new NotFoundError('User', orgUser.userId);\n }\n const pending = await this.repo.findPendingInvite(orgId, person.email);\n if (!pending) {\n throw new NotFoundError('Invite', person.email);\n }\n const { token, tokenHash } = generateInviteToken();\n const expiresAt = new Date(Date.now() + INVITE_TTL_MS);\n const invite = await this.repo.setInviteToken(orgId, pending.id, tokenHash, expiresAt);\n if (!invite) {\n throw new NotFoundError('Invite', pending.id);\n }\n await this.sendInviteEmail(invite, token);\n this.logger.info('student invite resent', {\n orgId,\n orgUserId,\n inviteId: invite.id,\n inviterUserId,\n });\n }\n\n async peekInvite(token: string): Promise<Invite | null> {\n const invite = await this.repo.findInviteByTokenHash(hashInviteToken(token));\n if (!invite || invite.status !== 'pending') {\n return null;\n }\n if (invite.expiresAt && invite.expiresAt < new Date()) {\n return null;\n }\n return invite;\n }\n\n async acceptInvite(input: AcceptInviteInput): Promise<OrgUser> {\n const invite = await this.peekInvite(input.token);\n if (!invite) {\n this.logger.warn('invite accept refused: token invalid or expired');\n throw new InviteError('invalid invite');\n }\n if (invite.email.toLowerCase() !== input.email.toLowerCase()) {\n this.logger.warn('invite accept refused: email mismatch', {\n orgId: invite.orgId,\n inviteId: invite.id,\n });\n throw new InviteError('emails must match');\n }\n const org = await this.repo.findById(invite.orgId);\n if (!org) {\n throw new InviteError('Org not found');\n }\n\n const orgUser =\n invite.role === STUDENT_ROLE\n ? await this.acceptStudentInvite(invite, input.userId)\n : await this.acceptStaffInvite(invite, org, input.userId);\n this.logger.info('invite accepted', { orgId: invite.orgId, userId: input.userId });\n return orgUser;\n }\n\n private async acceptStudentInvite(invite: Invite, userId: string): Promise<OrgUser> {\n return this.uow.run(async ({ organizations, outbox }) => {\n const existing = await organizations.findOrgUser(invite.orgId, userId);\n if (!existing) {\n throw new NotFoundError('Member', userId);\n }\n const activated = await organizations.updateOrgUser(invite.orgId, existing.id, {\n status: 'active',\n });\n if (!activated) {\n throw new NotFoundError('Member', existing.id);\n }\n const acceptedInvite = await organizations.setInviteStatus(\n invite.orgId,\n invite.id,\n 'accepted',\n );\n if (!acceptedInvite) {\n throw new NotFoundError('Invite', invite.id);\n }\n await outbox.append([\n organizationEvents.inviteAccepted.make({ orgId: invite.orgId, data: acceptedInvite }),\n organizationEvents.studentLinked.make({ orgId: invite.orgId, data: activated }),\n ]);\n return activated;\n });\n }\n\n private async acceptStaffInvite(\n invite: Invite,\n org: Organization,\n userId: string,\n ): Promise<OrgUser> {\n const person = await this.people.getUserById(userId);\n if (!person?.externalId) {\n throw new NotFoundError('User', userId);\n }\n await this.orgAdmin().grantMembership(org.externalId ?? org.id, person.externalId, invite.role);\n return this.uow.run(async ({ organizations, outbox }) => {\n const orgUser = await organizations.findOrgUser(invite.orgId, userId);\n if (!orgUser) {\n throw new NotFoundError('Member', userId);\n }\n const acceptedInvite = await organizations.setInviteStatus(\n invite.orgId,\n invite.id,\n 'accepted',\n );\n if (!acceptedInvite) {\n throw new NotFoundError('Invite', invite.id);\n }\n await outbox.append([\n organizationEvents.inviteAccepted.make({ orgId: invite.orgId, data: acceptedInvite }),\n ]);\n return orgUser;\n });\n }\n\n // By identity USER id — `(org_id, user_id)` is unique. Every caller (scope\n // resolution, the MCP principal, the member routes) asks \"what is this person\n // in this org\", never \"what is this org_users row\".\n getOrgUserById(orgId: string, id: string): Promise<OrgUser | null> {\n return this.repo.findOrgUserById(orgId, id);\n }\n\n async getOrgUser(orgId: string, userId: string): Promise<OrgUser | null> {\n return this.repo.findOrgUser(orgId, userId);\n }\n\n async deleteOrgUser(orgId: string, actor: Actor, id: string): Promise<OrgUser> {\n this.assertManagesUsers(actor, orgId);\n const deleted = await this.uow.run(async ({ organizations, outbox }) => {\n const orgUser = await organizations.findOrgUserById(orgId, id);\n if (!orgUser || orgUser.role !== STUDENT_ROLE) {\n throw new NotFoundError('Student', id);\n }\n const deletedUser = await organizations.deleteOrgUser(orgId, id);\n if (!deletedUser) {\n throw new NotFoundError('Student', id);\n }\n await outbox.append([organizationEvents.studentDeleted.make({ orgId, data: orgUser })]);\n return deletedUser;\n });\n this.logger.info('org user deleted', { orgId, orgUserId: id });\n return deleted;\n }\n\n async getOrgUsersForUser(userId: string): Promise<OrgUser[]> {\n return this.repo.findOrgUsersByUser(userId);\n }\n\n async getById(id: string): Promise<Organization | null> {\n return this.repo.findById(id);\n }\n\n private async sendInviteEmail(invite: Invite, token: string): Promise<void> {\n if (!this.mailer || !this.inviteUrls) {\n throw new Error('invite delivery is not configured (mailer / invite urls missing)');\n }\n const { email, role } = invite;\n const isStudent = role === STUDENT_ROLE;\n const base = isStudent\n ? `${this.inviteUrls.studentPortalUrl}/welcome`\n : `${this.inviteUrls.adminAppUrl}/invite`;\n // The portal resolves the token to the invited email, so the link carries\n // only the token. The admin app still reads it from the query.\n const query = isStudent\n ? new URLSearchParams({ token })\n : new URLSearchParams({ token, email });\n const inviteUrl = `${base}?${query.toString()}`;\n if (role === STUDENT_ROLE) {\n await this.mailer.send(email, 'studentInvite', { inviteUrl, studentName: email });\n } else {\n await this.mailer.send(email, 'memberInvite', {\n inviteUrl,\n inviterName: 'Your team',\n role,\n });\n }\n }\n\n async getByExternalId(externalId: string): Promise<Organization | null> {\n return this.repo.findByExternalId(externalId);\n }\n\n async getBySlug(slug: string): Promise<Organization | null> {\n return this.repo.findBySlug(slug);\n }\n\n staffOrgUserIds(orgId: string): Promise<string[]> {\n return this.repo.findOrgUserIdsByRole(orgId, [...STAFF_ROLES]);\n }\n\n listMembers(orgId: string, query: MembersQuery): Promise<Page<Member>> {\n return this.membersRepo.list(orgId, query);\n }\n\n async updateMemberRole(\n ctx: MemberWriteContext,\n actor: Actor,\n id: string,\n role: Role,\n ): Promise<MemberRoleChange | null> {\n this.assertManagesUsers(actor, ctx.orgId);\n this.assertNotOwner(role, ctx.orgId);\n const member = await this.membersRepo.findById(ctx.orgId, id);\n if (!member) {\n return this.promoteStudent(ctx, actor, id, role);\n }\n if (member.role === 'owner') {\n this.logger.warn('role change rejected: owner role immutable', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('The owner role cannot be reassigned');\n }\n if (member.kind !== 'member' || !member.userExternalId) {\n this.logger.warn('role change rejected: not an active member', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('Only active members can have their role changed');\n }\n if (role === STUDENT_ROLE) {\n return this.demoteModerator(ctx, actor, member, member.userExternalId);\n }\n const userExternalId = member.userExternalId;\n await this.asActor(actor, id, false, () =>\n this.orgAdmin().updateRole(ctx, userExternalId, role),\n );\n const updated = await this.membersRepo.findById(ctx.orgId, id);\n this.logger.info('member role updated', { orgId: ctx.orgId, memberId: id, role });\n return updated ? toMember(updated) : null;\n }\n\n private async demoteModerator(\n ctx: MemberWriteContext,\n actor: Actor,\n member: MemberRecord,\n userExternalId: string,\n ): Promise<MemberRoleChange | null> {\n if (member.role !== 'moderator') {\n this.logger.warn('role change rejected: only a moderator becomes a student', {\n orgId: ctx.orgId,\n memberId: member.id,\n });\n throw new OrganizationRuleError('Only a moderator can be made a student');\n }\n await this.asActor(actor, member.id, true, () =>\n this.orgAdmin().removeMember(ctx, userExternalId),\n );\n const orgUser = await this.repo.findOrgUserById(ctx.orgId, member.id);\n if (!orgUser) {\n return null;\n }\n this.logger.info('moderator made a student', { orgId: ctx.orgId, memberId: member.id });\n return { ...toMember(member), role: orgUser.role, status: orgUser.status };\n }\n\n private async promoteStudent(\n ctx: MemberWriteContext,\n actor: Actor,\n id: string,\n role: Role,\n ): Promise<MemberRoleChange | null> {\n const orgUser = await this.repo.findOrgUserById(ctx.orgId, id);\n if (!orgUser) {\n return null;\n }\n if (orgUser.role !== STUDENT_ROLE || role === STUDENT_ROLE) {\n this.logger.warn('role change rejected: not an active member', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('Only active members can have their role changed');\n }\n const person = await this.people.getUserById(orgUser.userId);\n if (!person?.externalId) {\n this.logger.warn('role change rejected: student has no account', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('That student has not joined yet');\n }\n const org = await this.repo.findById(ctx.orgId);\n if (!org) {\n return null;\n }\n const orgExternalId = org.externalId ?? org.id;\n const userExternalId = person.externalId;\n await this.asActor(actor, orgUser.id, false, async () => {\n await this.orgAdmin().grantMembership(orgExternalId, userExternalId, role);\n if (!(await this.membersRepo.findById(ctx.orgId, id))) {\n await this.orgAdmin().updateRole(ctx, userExternalId, role);\n }\n });\n const updated = await this.membersRepo.findById(ctx.orgId, id);\n if (!updated) {\n this.logger.warn('role change rejected: membership not mirrored', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('The role change did not take effect');\n }\n this.logger.info('student promoted', { orgId: ctx.orgId, memberId: id, role });\n return toMember(updated);\n }\n\n private asActor<T>(\n actor: Actor,\n orgUserId: string,\n demote: boolean,\n write: () => Promise<T>,\n ): Promise<T> {\n return this.memberWrites.run({ orgUserId, actorOrgUserId: actor.id, demote }, write);\n }\n\n private memberWrite(orgUserId: string): MemberWrite | undefined {\n const write = this.memberWrites.getStore();\n return write?.orgUserId === orgUserId ? write : undefined;\n }\n\n private assertManagesUsers(actor: Actor, orgId: string): void {\n if (capability(actor.role, 'manage_users') !== true) {\n this.logger.warn('member write rejected: actor cannot manage users', {\n orgId,\n actorOrgUserId: actor.id,\n });\n throw new ForbiddenError('Only an owner or admin can manage members');\n }\n }\n\n private assertNotOwner(role: Role, orgId: string): void {\n if (role === 'owner') {\n this.logger.warn('member write rejected: owner cannot be granted', { orgId });\n throw new OrganizationRuleError('Ownership cannot be granted');\n }\n }\n\n async removeMember(ctx: MemberWriteContext, actor: Actor, id: string): Promise<boolean> {\n this.assertManagesUsers(actor, ctx.orgId);\n const member = await this.membersRepo.findById(ctx.orgId, id);\n if (!member) {\n return false;\n }\n if (member.role === 'owner') {\n this.logger.warn('member removal rejected: owner cannot be removed', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('The owner cannot be removed');\n }\n if (member.kind === 'member' && member.userExternalId) {\n await this.orgAdmin().removeMember(ctx, member.userExternalId);\n } else if (member.kind === 'invite' && member.inviteId) {\n const inviteId = member.inviteId;\n await this.uow.run(async ({ organizations, outbox }) => {\n const canceled = await organizations.setInviteStatus(ctx.orgId, inviteId, 'canceled');\n if (!canceled) {\n throw new NotFoundError('Invite', inviteId);\n }\n await outbox.append([\n organizationEvents.inviteCanceled.make({ orgId: ctx.orgId, data: canceled }),\n ]);\n });\n }\n this.logger.info('member removed', { orgId: ctx.orgId, memberId: id });\n return true;\n }\n}\n"],"mappings":";;;;;;;;;AAwCA,MAAM,gBAAgB,QAAc,KAAK;AAezC,SAAS,SAAS,GAAyB;CACzC,OAAO;EACL,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E,OAAO,IAAI;IACX,UAAU;GACZ,CAAC;GACD,MAAM,IAAI,sBAAsB,6BAA6B;EAC/D;EACA,IAAI,OAAO,SAAS,YAAY,OAAO,gBACrC,MAAM,KAAK,SAAS,CAAC,CAAC,aAAa,KAAK,OAAO,cAAc;OACxD,IAAI,OAAO,SAAS,YAAY,OAAO,UAAU;GACtD,MAAM,WAAW,OAAO;GACxB,MAAM,KAAK,IAAI,IAAI,OAAO,EAAE,eAAe,aAAa;IACtD,MAAM,WAAW,MAAM,cAAc,gBAAgB,IAAI,OAAO,UAAU,UAAU;IACpF,IAAI,CAAC,UACH,MAAM,IAAI,cAAc,UAAU,QAAQ;IAE5C,MAAM,OAAO,OAAO,CAClB,mBAAmB,eAAe,KAAK;KAAE,OAAO,IAAI;KAAO,MAAM;IAAS,CAAC,CAC7E,CAAC;GACH,CAAC;EACH;EACA,KAAK,OAAO,KAAK,kBAAkB;GAAE,OAAO,IAAI;GAAO,UAAU;EAAG,CAAC;EACrE,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"service.js","names":[],"sources":["../../src/organizations/service.ts"],"sourcesContent":["// organizations context — service implementation (inbound port).\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport type {\n MemberRecord,\n MembersRepository,\n MemberWriteContext,\n OrgAdmin,\n OrganizationService,\n OrganizationsRepository,\n OrganizationsUnitOfWork,\n} from './ports.js';\nimport type { Invite, Organization, OrgUser } from './model.js';\nimport { capability, type Role, STAFF_ROLES, STUDENT_ROLE } from './roles.js';\nimport {\n InviteError,\n type Member,\n type MemberRoleChange,\n type MembersQuery,\n OrganizationRuleError,\n type Page,\n} from './members.js';\nimport type {\n AcceptInviteInput,\n AddOrgUserInput,\n CreateInviteInput,\n CreateOrganizationInput,\n ResendStudentInviteInput,\n UpdateOrganizationInput,\n UpdateOrgUserInput,\n} from './types.js';\nimport { organizationEvents, type OrganizationEvent } from './events.js';\nimport type { Logger, NewDomainEvent } from '../shared/ports.js';\nimport { noopLogger } from '../shared/logger.js';\nimport type { Mailer } from '../shared/mailer.js';\nimport { generateInviteToken, hashInviteToken } from '../shared/invite-token.js';\nimport { ForbiddenError, NotFoundError } from '../shared/errors.js';\nimport type { Actor } from '../shared/actor.js';\nimport type { IdentityService } from '../identity/index.js';\nimport { genId } from '../shared/id.js';\n\nconst INVITE_TTL_MS = 7 * 24 * 60 * 60 * 1000;\n\ntype NewOrganizationEvent = NewDomainEvent<OrganizationEvent>;\n\ninterface MemberWrite {\n orgUserId: string;\n actorOrgUserId: string;\n demote: boolean;\n}\n\nexport interface InviteUrls {\n studentPortalUrl: string;\n adminAppUrl: string;\n}\n\nfunction toMember(r: MemberRecord): Member {\n return {\n id: r.id,\n firstName: r.firstName,\n lastName: r.lastName,\n email: r.email,\n image: r.image,\n role: r.role,\n status: r.status,\n joinedAt: r.joinedAt,\n invitedAt: r.invitedAt,\n };\n}\n\nexport type OrganizationServiceParams = {\n repo: OrganizationsRepository;\n membersRepo: MembersRepository;\n people: IdentityService;\n uow: OrganizationsUnitOfWork;\n orgAdmin: () => OrgAdmin;\n logger?: Logger;\n mailer?: Pick<Mailer, 'send'>;\n inviteUrls?: InviteUrls;\n};\n\nexport class OrganizationServiceImpl implements OrganizationService {\n private readonly repo: OrganizationsRepository;\n private readonly membersRepo: MembersRepository;\n private readonly people: IdentityService;\n private readonly uow: OrganizationsUnitOfWork;\n private readonly orgAdmin: () => OrgAdmin;\n private readonly logger: Logger;\n private readonly mailer?: Pick<Mailer, 'send'>;\n private readonly inviteUrls?: InviteUrls;\n private readonly memberWrites = new AsyncLocalStorage<MemberWrite>();\n\n constructor(params: OrganizationServiceParams) {\n this.repo = params.repo;\n this.membersRepo = params.membersRepo;\n this.people = params.people;\n this.uow = params.uow;\n this.orgAdmin = params.orgAdmin;\n this.logger = params.logger ?? noopLogger;\n this.mailer = params.mailer;\n this.inviteUrls = params.inviteUrls;\n }\n\n async createOrganization(input: CreateOrganizationInput): Promise<Organization> {\n const created = await this.uow.run(async ({ organizations, outbox }) => {\n const id = genId('organization');\n\n const created = await organizations.create({\n id,\n // The auth provider adopts this id for its own org row, so the org is\n // its own external id — a lookup by either id lands on the same row.\n externalId: input.externalId ?? id,\n name: input.name ?? `My Org`,\n slug: input.slug ?? '',\n ownerId: input.ownerId,\n });\n await outbox.append([\n organizationEvents.organizationCreated.make({\n orgId: created.id,\n data: created,\n }),\n ]);\n return created;\n });\n this.logger.info('organization created', { orgId: created.id, slug: created.slug });\n return created;\n }\n\n async updateOrganization(id: string, input: UpdateOrganizationInput): Promise<Organization> {\n const updatedOrg = await this.uow.run(async ({ organizations, outbox }) => {\n const updated = await organizations.update(id, {\n name: input.name,\n slug: input.slug,\n });\n if (!updated) {\n throw new NotFoundError('Organization', id);\n }\n await outbox.append([\n organizationEvents.organizationUpdated.make({ orgId: id, data: updated }),\n ]);\n return updated;\n });\n\n this.logger.info('organization updated', { updatedOrg });\n return updatedOrg!;\n }\n\n async deleteOrganization(id: string): Promise<Organization> {\n const deleted = await this.uow.run(async ({ organizations, outbox }) => {\n const deleted = await organizations.delete(id);\n\n await outbox.append([\n organizationEvents.organizationDeleted.make({\n orgId: deleted.id,\n data: deleted,\n }),\n ]);\n return deleted;\n });\n this.logger.info('organization deleted', { orgId: deleted.id });\n return deleted;\n }\n\n async addOrgUser({ orgId, userId, role }: AddOrgUserInput): Promise<OrgUser> {\n const existing = await this.repo.findOrgUser(orgId, userId);\n if (existing) {\n return this.updateOrgUser(orgId, userId, { role, status: 'active' });\n }\n const orgUser = await this.uow.run(async ({ organizations, outbox }) => {\n const created = await organizations.createOrgUser({ orgId, role, userId, status: 'active' });\n await outbox.append([organizationEvents.orgUserLinked.make({ orgId, data: created })]);\n return created;\n });\n this.logger.info('user added to organization', { orgId, userId, role });\n return orgUser;\n }\n\n async removeOrgUser(orgId: string, userId: string): Promise<OrgUser> {\n const deleted = await this.uow.run(async ({ organizations, outbox }) => {\n const orgUser = await organizations.findOrgUser(orgId, userId);\n if (!orgUser) {\n throw new NotFoundError('Member', userId);\n }\n const write = this.memberWrite(orgUser.id);\n if (write?.demote) {\n const demoted = await organizations.updateOrgUser(orgId, orgUser.id, {\n role: STUDENT_ROLE,\n });\n if (!demoted) {\n throw new NotFoundError('Member', orgUser.id);\n }\n if (orgUser.role !== STUDENT_ROLE) {\n await outbox.append([\n organizationEvents.orgUserUpdated.make({\n orgId,\n data: demoted,\n metadata: { actorOrgUserId: write.actorOrgUserId },\n }),\n ]);\n }\n return demoted;\n }\n if (orgUser.role === STUDENT_ROLE) {\n return orgUser;\n }\n const deletedUser = await organizations.deleteOrgUser(orgId, orgUser.id);\n if (!deletedUser) {\n throw new NotFoundError('Member', orgUser.id);\n }\n await outbox.append([\n organizationEvents.orgUserDeleted.make({\n orgId,\n data: deletedUser,\n }),\n ]);\n return deletedUser;\n });\n this.logger.info('org user removed', { orgId, userId, orgUserId: deleted.id });\n return deleted;\n }\n\n async updateOrgUser(orgId: string, userId: string, patch: UpdateOrgUserInput): Promise<OrgUser> {\n const updated = await this.uow.run(async ({ organizations, outbox }) => {\n const orgUser = await organizations.findOrgUser(orgId, userId);\n if (!orgUser) {\n throw new NotFoundError('Member', userId);\n }\n const next = await organizations.updateOrgUser(orgId, orgUser.id, patch);\n if (!next) {\n throw new NotFoundError('Member', orgUser.id);\n }\n if (patch.role !== undefined && patch.role !== orgUser.role) {\n const actorOrgUserId = this.memberWrite(orgUser.id)?.actorOrgUserId;\n await outbox.append([\n organizationEvents.orgUserUpdated.make({\n orgId,\n data: next,\n ...(actorOrgUserId !== undefined && { metadata: { actorOrgUserId } }),\n }),\n ]);\n }\n return next;\n });\n this.logger.info('org user updated', { orgId, userId, orgUserId: updated.id, patch });\n return updated;\n }\n\n async createInvite(actor: Actor, input: CreateInviteInput): Promise<Invite> {\n const { orgId, email, role, inviterUserId, firstName, lastName } = input;\n this.assertManagesUsers(actor, orgId);\n this.assertNotOwner(role, orgId);\n const sendEmail = input.sendEmail ?? true;\n const { token, tokenHash } = generateInviteToken();\n const expiresAt = new Date(Date.now() + INVITE_TTL_MS);\n\n // A student belongs to the org from the moment an admin adds them, not from\n // the moment they click a link — so the person exists before the invite\n // does. Staff are excluded: their org_users row is mirrored from the auth\n // provider's member record, which does not exist until they join.\n const person =\n role === STUDENT_ROLE\n ? ((await this.people.getUserByEmail(email)) ??\n (await this.people.createUser({\n email,\n ...(firstName !== undefined && { firstName }),\n ...(lastName !== undefined && { lastName }),\n })))\n : null;\n\n const invite = await this.uow.run(async ({ organizations, outbox }) => {\n const events: NewOrganizationEvent[] = [];\n if (person) {\n const orgUser = await organizations.createOrgUser({\n orgId,\n userId: person.id,\n role: STUDENT_ROLE,\n status: 'invited',\n });\n events.push(organizationEvents.studentCreated.make({ orgId, data: orgUser }));\n }\n const row = await organizations.upsertPendingInvite(orgId, {\n email,\n role,\n invitedBy: inviterUserId,\n tokenHash,\n expiresAt,\n });\n events.push(organizationEvents.inviteCreated.make({ orgId, data: row }));\n await outbox.append(events);\n return row;\n });\n\n if (sendEmail) {\n // TODO make this workflow durable\n try {\n await this.sendInviteEmail(invite, token);\n } catch (err) {\n // A failed email must not abort invite creation: the token is already\n // minted and recorded, so the admin can fix transport and resend.\n this.logger.error('failed to send invite email', {\n orgId,\n inviteId: invite.id,\n role: invite.role,\n err: err instanceof Error ? err : new Error(String(err)),\n });\n }\n }\n\n this.logger.info('invite created', { orgId, inviteId: invite.id, role, sendEmail });\n return invite;\n }\n\n async resendStudentInvite(actor: Actor, input: ResendStudentInviteInput): Promise<void> {\n const { orgId, orgUserId, inviterUserId } = input;\n this.assertManagesUsers(actor, orgId);\n const orgUser = await this.repo.findOrgUserById(orgId, orgUserId);\n if (!orgUser || orgUser.role !== STUDENT_ROLE) {\n throw new NotFoundError('Student', orgUserId);\n }\n if (orgUser.status === 'active') {\n throw new OrganizationRuleError('That student has already accepted their invitation');\n }\n const person = await this.people.getUserById(orgUser.userId);\n if (!person) {\n throw new NotFoundError('User', orgUser.userId);\n }\n const pending = await this.repo.findPendingInvite(orgId, person.email);\n if (!pending) {\n throw new NotFoundError('Invite', person.email);\n }\n const { token, tokenHash } = generateInviteToken();\n const expiresAt = new Date(Date.now() + INVITE_TTL_MS);\n const invite = await this.repo.setInviteToken(orgId, pending.id, tokenHash, expiresAt);\n if (!invite) {\n throw new NotFoundError('Invite', pending.id);\n }\n await this.sendInviteEmail(invite, token);\n this.logger.info('student invite resent', {\n orgId,\n orgUserId,\n inviteId: invite.id,\n inviterUserId,\n });\n }\n\n async peekInvite(token: string): Promise<Invite | null> {\n const invite = await this.repo.findInviteByTokenHash(hashInviteToken(token));\n if (!invite || invite.status !== 'pending') {\n return null;\n }\n if (invite.expiresAt && invite.expiresAt < new Date()) {\n return null;\n }\n return invite;\n }\n\n async acceptInvite(input: AcceptInviteInput): Promise<OrgUser> {\n const invite = await this.peekInvite(input.token);\n if (!invite) {\n this.logger.warn('invite accept refused: token invalid or expired');\n throw new InviteError('invalid invite');\n }\n if (invite.email.toLowerCase() !== input.email.toLowerCase()) {\n this.logger.warn('invite accept refused: email mismatch', {\n orgId: invite.orgId,\n inviteId: invite.id,\n });\n throw new InviteError('emails must match');\n }\n const org = await this.repo.findById(invite.orgId);\n if (!org) {\n throw new InviteError('Org not found');\n }\n\n const orgUser =\n invite.role === STUDENT_ROLE\n ? await this.acceptStudentInvite(invite, input.userId)\n : await this.acceptStaffInvite(invite, org, input.userId);\n this.logger.info('invite accepted', { orgId: invite.orgId, userId: input.userId });\n return orgUser;\n }\n\n private async acceptStudentInvite(invite: Invite, userId: string): Promise<OrgUser> {\n return this.uow.run(async ({ organizations, outbox }) => {\n const existing = await organizations.findOrgUser(invite.orgId, userId);\n if (!existing) {\n throw new NotFoundError('Member', userId);\n }\n const activated = await organizations.updateOrgUser(invite.orgId, existing.id, {\n status: 'active',\n });\n if (!activated) {\n throw new NotFoundError('Member', existing.id);\n }\n const acceptedInvite = await organizations.setInviteStatus(\n invite.orgId,\n invite.id,\n 'accepted',\n );\n if (!acceptedInvite) {\n throw new NotFoundError('Invite', invite.id);\n }\n await outbox.append([\n organizationEvents.inviteAccepted.make({ orgId: invite.orgId, data: acceptedInvite }),\n organizationEvents.studentLinked.make({ orgId: invite.orgId, data: activated }),\n ]);\n return activated;\n });\n }\n\n private async acceptStaffInvite(\n invite: Invite,\n org: Organization,\n userId: string,\n ): Promise<OrgUser> {\n const person = await this.people.getUserById(userId);\n if (!person?.externalId) {\n throw new NotFoundError('User', userId);\n }\n await this.orgAdmin().grantMembership(org.externalId ?? org.id, person.externalId, invite.role);\n return this.uow.run(async ({ organizations, outbox }) => {\n const orgUser = await organizations.findOrgUser(invite.orgId, userId);\n if (!orgUser) {\n throw new NotFoundError('Member', userId);\n }\n const acceptedInvite = await organizations.setInviteStatus(\n invite.orgId,\n invite.id,\n 'accepted',\n );\n if (!acceptedInvite) {\n throw new NotFoundError('Invite', invite.id);\n }\n await outbox.append([\n organizationEvents.inviteAccepted.make({ orgId: invite.orgId, data: acceptedInvite }),\n ]);\n return orgUser;\n });\n }\n\n // By identity USER id — `(org_id, user_id)` is unique. Every caller (scope\n // resolution, the MCP principal, the member routes) asks \"what is this person\n // in this org\", never \"what is this org_users row\".\n getOrgUserById(orgId: string, id: string): Promise<OrgUser | null> {\n return this.repo.findOrgUserById(orgId, id);\n }\n\n async getOrgUsersByIds(orgId: string, ids: string[]): Promise<OrgUser[]> {\n const unique = [...new Set(ids)];\n return unique.length > 0 ? this.repo.findOrgUsersByIds(orgId, unique) : [];\n }\n\n async getOrgUser(orgId: string, userId: string): Promise<OrgUser | null> {\n return this.repo.findOrgUser(orgId, userId);\n }\n\n async deleteOrgUser(orgId: string, actor: Actor, id: string): Promise<OrgUser> {\n this.assertManagesUsers(actor, orgId);\n const deleted = await this.uow.run(async ({ organizations, outbox }) => {\n const orgUser = await organizations.findOrgUserById(orgId, id);\n if (!orgUser || orgUser.role !== STUDENT_ROLE) {\n throw new NotFoundError('Student', id);\n }\n const deletedUser = await organizations.deleteOrgUser(orgId, id);\n if (!deletedUser) {\n throw new NotFoundError('Student', id);\n }\n await outbox.append([organizationEvents.studentDeleted.make({ orgId, data: orgUser })]);\n return deletedUser;\n });\n this.logger.info('org user deleted', { orgId, orgUserId: id });\n return deleted;\n }\n\n async getOrgUsersForUser(userId: string): Promise<OrgUser[]> {\n return this.repo.findOrgUsersByUser(userId);\n }\n\n async getById(id: string): Promise<Organization | null> {\n return this.repo.findById(id);\n }\n\n orgIds(): Promise<string[]> {\n return this.repo.listIds();\n }\n\n private async sendInviteEmail(invite: Invite, token: string): Promise<void> {\n if (!this.mailer || !this.inviteUrls) {\n throw new Error('invite delivery is not configured (mailer / invite urls missing)');\n }\n const { email, role } = invite;\n const isStudent = role === STUDENT_ROLE;\n const base = isStudent\n ? `${this.inviteUrls.studentPortalUrl}/welcome`\n : `${this.inviteUrls.adminAppUrl}/invite`;\n // The portal resolves the token to the invited email, so the link carries\n // only the token. The admin app still reads it from the query.\n const query = isStudent\n ? new URLSearchParams({ token })\n : new URLSearchParams({ token, email });\n const inviteUrl = `${base}?${query.toString()}`;\n if (role === STUDENT_ROLE) {\n await this.mailer.send(email, 'studentInvite', { inviteUrl, studentName: email });\n } else {\n await this.mailer.send(email, 'memberInvite', {\n inviteUrl,\n inviterName: 'Your team',\n role,\n });\n }\n }\n\n async getByExternalId(externalId: string): Promise<Organization | null> {\n return this.repo.findByExternalId(externalId);\n }\n\n async getBySlug(slug: string): Promise<Organization | null> {\n return this.repo.findBySlug(slug);\n }\n\n staffOrgUserIds(orgId: string): Promise<string[]> {\n return this.repo.findOrgUserIdsByRole(orgId, [...STAFF_ROLES]);\n }\n\n listMembers(orgId: string, query: MembersQuery): Promise<Page<Member>> {\n return this.membersRepo.list(orgId, query);\n }\n\n async updateMemberRole(\n ctx: MemberWriteContext,\n actor: Actor,\n id: string,\n role: Role,\n ): Promise<MemberRoleChange | null> {\n this.assertManagesUsers(actor, ctx.orgId);\n this.assertNotOwner(role, ctx.orgId);\n const member = await this.membersRepo.findById(ctx.orgId, id);\n if (!member) {\n return this.promoteStudent(ctx, actor, id, role);\n }\n if (member.role === 'owner') {\n this.logger.warn('role change rejected: owner role immutable', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('The owner role cannot be reassigned');\n }\n if (member.kind !== 'member' || !member.userExternalId) {\n this.logger.warn('role change rejected: not an active member', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('Only active members can have their role changed');\n }\n if (role === STUDENT_ROLE) {\n return this.demoteModerator(ctx, actor, member, member.userExternalId);\n }\n const userExternalId = member.userExternalId;\n await this.asActor(actor, id, false, () =>\n this.orgAdmin().updateRole(ctx, userExternalId, role),\n );\n const updated = await this.membersRepo.findById(ctx.orgId, id);\n this.logger.info('member role updated', { orgId: ctx.orgId, memberId: id, role });\n return updated ? toMember(updated) : null;\n }\n\n private async demoteModerator(\n ctx: MemberWriteContext,\n actor: Actor,\n member: MemberRecord,\n userExternalId: string,\n ): Promise<MemberRoleChange | null> {\n if (member.role !== 'moderator') {\n this.logger.warn('role change rejected: only a moderator becomes a student', {\n orgId: ctx.orgId,\n memberId: member.id,\n });\n throw new OrganizationRuleError('Only a moderator can be made a student');\n }\n await this.asActor(actor, member.id, true, () =>\n this.orgAdmin().removeMember(ctx, userExternalId),\n );\n const orgUser = await this.repo.findOrgUserById(ctx.orgId, member.id);\n if (!orgUser) {\n return null;\n }\n this.logger.info('moderator made a student', { orgId: ctx.orgId, memberId: member.id });\n return { ...toMember(member), role: orgUser.role, status: orgUser.status };\n }\n\n private async promoteStudent(\n ctx: MemberWriteContext,\n actor: Actor,\n id: string,\n role: Role,\n ): Promise<MemberRoleChange | null> {\n const orgUser = await this.repo.findOrgUserById(ctx.orgId, id);\n if (!orgUser) {\n return null;\n }\n if (orgUser.role !== STUDENT_ROLE || role === STUDENT_ROLE) {\n this.logger.warn('role change rejected: not an active member', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('Only active members can have their role changed');\n }\n const person = await this.people.getUserById(orgUser.userId);\n if (!person?.externalId) {\n this.logger.warn('role change rejected: student has no account', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('That student has not joined yet');\n }\n const org = await this.repo.findById(ctx.orgId);\n if (!org) {\n return null;\n }\n const orgExternalId = org.externalId ?? org.id;\n const userExternalId = person.externalId;\n await this.asActor(actor, orgUser.id, false, async () => {\n await this.orgAdmin().grantMembership(orgExternalId, userExternalId, role);\n if (!(await this.membersRepo.findById(ctx.orgId, id))) {\n await this.orgAdmin().updateRole(ctx, userExternalId, role);\n }\n });\n const updated = await this.membersRepo.findById(ctx.orgId, id);\n if (!updated) {\n this.logger.warn('role change rejected: membership not mirrored', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('The role change did not take effect');\n }\n this.logger.info('student promoted', { orgId: ctx.orgId, memberId: id, role });\n return toMember(updated);\n }\n\n private asActor<T>(\n actor: Actor,\n orgUserId: string,\n demote: boolean,\n write: () => Promise<T>,\n ): Promise<T> {\n return this.memberWrites.run({ orgUserId, actorOrgUserId: actor.id, demote }, write);\n }\n\n private memberWrite(orgUserId: string): MemberWrite | undefined {\n const write = this.memberWrites.getStore();\n return write?.orgUserId === orgUserId ? write : undefined;\n }\n\n private assertManagesUsers(actor: Actor, orgId: string): void {\n if (capability(actor.role, 'manage_users') !== true) {\n this.logger.warn('member write rejected: actor cannot manage users', {\n orgId,\n actorOrgUserId: actor.id,\n });\n throw new ForbiddenError('Only an owner or admin can manage members');\n }\n }\n\n private assertNotOwner(role: Role, orgId: string): void {\n if (role === 'owner') {\n this.logger.warn('member write rejected: owner cannot be granted', { orgId });\n throw new OrganizationRuleError('Ownership cannot be granted');\n }\n }\n\n async removeMember(ctx: MemberWriteContext, actor: Actor, id: string): Promise<boolean> {\n this.assertManagesUsers(actor, ctx.orgId);\n const member = await this.membersRepo.findById(ctx.orgId, id);\n if (!member) {\n return false;\n }\n if (member.role === 'owner') {\n this.logger.warn('member removal rejected: owner cannot be removed', {\n orgId: ctx.orgId,\n memberId: id,\n });\n throw new OrganizationRuleError('The owner cannot be removed');\n }\n if (member.kind === 'member' && member.userExternalId) {\n await this.orgAdmin().removeMember(ctx, member.userExternalId);\n } else if (member.kind === 'invite' && member.inviteId) {\n const inviteId = member.inviteId;\n await this.uow.run(async ({ organizations, outbox }) => {\n const canceled = await organizations.setInviteStatus(ctx.orgId, inviteId, 'canceled');\n if (!canceled) {\n throw new NotFoundError('Invite', inviteId);\n }\n await outbox.append([\n organizationEvents.inviteCanceled.make({ orgId: ctx.orgId, data: canceled }),\n ]);\n });\n }\n this.logger.info('member removed', { orgId: ctx.orgId, memberId: id });\n return true;\n }\n}\n"],"mappings":";;;;;;;;;AAwCA,MAAM,gBAAgB,QAAc,KAAK;AAezC,SAAS,SAAS,GAAyB;CACzC,OAAO;EACL,IAAI,EAAE;EACN,WAAW,EAAE;EACb,UAAU,EAAE;EACZ,OAAO,EAAE;EACT,OAAO,EAAE;EACT,MAAM,EAAE;EACR,QAAQ,EAAE;EACV,UAAU,EAAE;EACZ,WAAW,EAAE;CACf;AACF;AAaA,IAAa,0BAAb,MAAoE;CAClE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,eAAgC,IAAI,kBAA+B;CAEnE,YAAY,QAAmC;EAC7C,KAAK,OAAO,OAAO;EACnB,KAAK,cAAc,OAAO;EAC1B,KAAK,SAAS,OAAO;EACrB,KAAK,MAAM,OAAO;EAClB,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO,UAAU;EAC/B,KAAK,SAAS,OAAO;EACrB,KAAK,aAAa,OAAO;CAC3B;CAEA,MAAM,mBAAmB,OAAuD;EAC9E,MAAM,UAAU,MAAM,KAAK,IAAI,IAAI,OAAO,EAAE,eAAe,aAAa;GACtE,MAAM,KAAK,MAAM,cAAc;GAE/B,MAAM,UAAU,MAAM,cAAc,OAAO;IACzC;IAGA,YAAY,MAAM,cAAc;IAChC,MAAM,MAAM,QAAQ;IACpB,MAAM,MAAM,QAAQ;IACpB,SA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E,CAAC;GACH,CAAC;EACH;EACA,KAAK,OAAO,KAAK,kBAAkB;GAAE,OAAO,IAAI;GAAO,UAAU;EAAG,CAAC;EACrE,OAAO;CACT;AACF"}
|
|
@@ -7,7 +7,7 @@ declare const progressEvents: {
|
|
|
7
7
|
id: string;
|
|
8
8
|
orgId: string;
|
|
9
9
|
orgUserId: string;
|
|
10
|
-
targetType: "
|
|
10
|
+
targetType: "activity" | "module" | "course";
|
|
11
11
|
targetId: string;
|
|
12
12
|
startedAt: Date;
|
|
13
13
|
position: JsonValue;
|
|
@@ -18,7 +18,7 @@ declare const progressEvents: {
|
|
|
18
18
|
id: string;
|
|
19
19
|
orgId: string;
|
|
20
20
|
orgUserId: string;
|
|
21
|
-
targetType: "
|
|
21
|
+
targetType: "activity" | "module" | "course";
|
|
22
22
|
targetId: string;
|
|
23
23
|
startedAt: unknown;
|
|
24
24
|
position: unknown;
|
|
@@ -26,25 +26,25 @@ declare const progressEvents: {
|
|
|
26
26
|
createdAt: unknown;
|
|
27
27
|
updatedAt: unknown;
|
|
28
28
|
}, import("zod").ZodObject<{
|
|
29
|
-
orgId: import("zod").ZodString;
|
|
30
29
|
id: import("zod").ZodString;
|
|
31
|
-
|
|
32
|
-
updatedAt: import("zod").ZodCoercedDate<unknown>;
|
|
33
|
-
startedAt: import("zod").ZodCoercedDate<unknown>;
|
|
30
|
+
orgId: import("zod").ZodString;
|
|
34
31
|
orgUserId: import("zod").ZodString;
|
|
35
32
|
targetType: import("zod").ZodEnum<{
|
|
36
|
-
course: "course";
|
|
37
33
|
activity: "activity";
|
|
38
34
|
module: "module";
|
|
35
|
+
course: "course";
|
|
39
36
|
}>;
|
|
40
37
|
targetId: import("zod").ZodString;
|
|
38
|
+
startedAt: import("zod").ZodCoercedDate<unknown>;
|
|
41
39
|
completedAt: import("zod").ZodNullable<import("zod").ZodCoercedDate<unknown>>;
|
|
40
|
+
createdAt: import("zod").ZodCoercedDate<unknown>;
|
|
41
|
+
updatedAt: import("zod").ZodCoercedDate<unknown>;
|
|
42
42
|
}, import("zod/v4/core").$strip>>;
|
|
43
43
|
progressCompleted: RuntimeEventDefinition<VersionedDomainEvent<{
|
|
44
44
|
id: string;
|
|
45
45
|
orgId: string;
|
|
46
46
|
orgUserId: string;
|
|
47
|
-
targetType: "
|
|
47
|
+
targetType: "activity" | "module" | "course";
|
|
48
48
|
targetId: string;
|
|
49
49
|
startedAt: Date;
|
|
50
50
|
position: JsonValue;
|
|
@@ -55,7 +55,7 @@ declare const progressEvents: {
|
|
|
55
55
|
id: string;
|
|
56
56
|
orgId: string;
|
|
57
57
|
orgUserId: string;
|
|
58
|
-
targetType: "
|
|
58
|
+
targetType: "activity" | "module" | "course";
|
|
59
59
|
targetId: string;
|
|
60
60
|
startedAt: unknown;
|
|
61
61
|
position: unknown;
|
|
@@ -63,19 +63,19 @@ declare const progressEvents: {
|
|
|
63
63
|
createdAt: unknown;
|
|
64
64
|
updatedAt: unknown;
|
|
65
65
|
}, import("zod").ZodObject<{
|
|
66
|
-
orgId: import("zod").ZodString;
|
|
67
66
|
id: import("zod").ZodString;
|
|
68
|
-
|
|
69
|
-
updatedAt: import("zod").ZodCoercedDate<unknown>;
|
|
70
|
-
startedAt: import("zod").ZodCoercedDate<unknown>;
|
|
67
|
+
orgId: import("zod").ZodString;
|
|
71
68
|
orgUserId: import("zod").ZodString;
|
|
72
69
|
targetType: import("zod").ZodEnum<{
|
|
73
|
-
course: "course";
|
|
74
70
|
activity: "activity";
|
|
75
71
|
module: "module";
|
|
72
|
+
course: "course";
|
|
76
73
|
}>;
|
|
77
74
|
targetId: import("zod").ZodString;
|
|
75
|
+
startedAt: import("zod").ZodCoercedDate<unknown>;
|
|
78
76
|
completedAt: import("zod").ZodNullable<import("zod").ZodCoercedDate<unknown>>;
|
|
77
|
+
createdAt: import("zod").ZodCoercedDate<unknown>;
|
|
78
|
+
updatedAt: import("zod").ZodCoercedDate<unknown>;
|
|
79
79
|
}, import("zod/v4/core").$strip>>;
|
|
80
80
|
};
|
|
81
81
|
type ProgressStarted = EventOf<typeof progressEvents.progressStarted>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CourseView, Module } from "../../types/schemas/content.js";
|
|
2
|
-
import { CommunityHome, CommunityHomeSpace, CourseProgressView, DirectoryEntry, DirectoryQuery, DirectoryRow, LockedCommunitySpace, NotificationView, NotificationsView, OpenCommunitySpace } from "./model.js";
|
|
2
|
+
import { CommunityHome, CommunityHomeSpace, CommunityNotificationSettingsView, CourseProgressView, DirectoryEntry, DirectoryQuery, DirectoryRow, LockedCommunitySpace, NotificationItemView, NotificationSettingsCategoryView, NotificationUnreadCounts, NotificationView, NotificationsView, OpenCommunitySpace, OrgNotificationSettingsView, SettingsChannelView } from "./model.js";
|
|
3
3
|
import { MemberReportRepository, MemberReportService } from "./ports.js";
|
|
4
4
|
import { MemberReportServiceImpl } from "./service.js";
|
|
5
|
-
export { type CommunityHome, type CommunityHomeSpace, type CourseProgressView, type CourseView, type DirectoryEntry, type DirectoryQuery, type DirectoryRow, type LockedCommunitySpace, type MemberReportRepository, type MemberReportService, MemberReportServiceImpl, type Module, type NotificationView, type NotificationsView, type OpenCommunitySpace };
|
|
5
|
+
export { type CommunityHome, type CommunityHomeSpace, type CommunityNotificationSettingsView, type CourseProgressView, type CourseView, type DirectoryEntry, type DirectoryQuery, type DirectoryRow, type LockedCommunitySpace, type MemberReportRepository, type MemberReportService, MemberReportServiceImpl, type Module, type NotificationItemView, type NotificationSettingsCategoryView, type NotificationUnreadCounts, type NotificationView, type NotificationsView, type OpenCommunitySpace, type OrgNotificationSettingsView, type SettingsChannelView };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { JsonValue } from "../../types/shared.js";
|
|
2
|
+
import { ActivityView, CourseView, DigestSchedule, DownloadFile, DownloadView, Module } from "../../types/schemas/content.js";
|
|
3
|
+
import { SubscriptionView } from "../../types/schemas/discussion.js";
|
|
4
|
+
import { Reason, Scope, SubjectRef } from "../../types/notifications.js";
|
|
5
|
+
import "../../types/index.js";
|
|
3
6
|
import "../../content/index.js";
|
|
4
|
-
import "../../
|
|
7
|
+
import { ResolvedChannel } from "../../shared/notification-settings.js";
|
|
5
8
|
//#region src/reporting/member/model.d.ts
|
|
6
9
|
/** Per-course progress for the student surface. Derived on read against the
|
|
7
10
|
* current published structure — never stored. */
|
|
@@ -53,6 +56,7 @@ interface OpenCommunitySpace extends CommunityHomeSpaceBase {
|
|
|
53
56
|
name: string;
|
|
54
57
|
}[];
|
|
55
58
|
links: CommunityHomeLink[];
|
|
59
|
+
subscription: SubscriptionView | null;
|
|
56
60
|
}
|
|
57
61
|
type CommunityHomeSpace = LockedCommunitySpace | OpenCommunitySpace;
|
|
58
62
|
interface CommunityHome {
|
|
@@ -81,18 +85,20 @@ interface CourseProgressView {
|
|
|
81
85
|
/** Per-activity reported state (the record's position map); absent key = none reported. */
|
|
82
86
|
positions: Record<string, unknown>;
|
|
83
87
|
}
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
interface NotificationItemView {
|
|
89
|
+
type: SubjectRef['type'];
|
|
90
|
+
id: string;
|
|
91
|
+
title?: string;
|
|
92
|
+
excerpt?: string;
|
|
93
|
+
}
|
|
86
94
|
interface NotificationView {
|
|
87
95
|
id: string;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
imageUrl: string | null;
|
|
95
|
-
} | null;
|
|
96
|
+
type: string;
|
|
97
|
+
scope: Scope;
|
|
98
|
+
reasons: Reason[];
|
|
99
|
+
matchedReason: Reason;
|
|
100
|
+
category: string;
|
|
101
|
+
display: Record<string, JsonValue>;
|
|
96
102
|
community: {
|
|
97
103
|
id: string;
|
|
98
104
|
title: string;
|
|
@@ -101,16 +107,22 @@ interface NotificationView {
|
|
|
101
107
|
id: string;
|
|
102
108
|
name: string;
|
|
103
109
|
} | null;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
commentId: string | null;
|
|
109
|
-
chat: {
|
|
110
|
-
id: string;
|
|
111
|
-
title: string;
|
|
110
|
+
actor: {
|
|
111
|
+
orgUserId: string;
|
|
112
|
+
name: string | null;
|
|
113
|
+
imageUrl: string | null;
|
|
112
114
|
} | null;
|
|
113
|
-
|
|
115
|
+
subject: NotificationItemView | null;
|
|
116
|
+
parent: NotificationItemView | null;
|
|
117
|
+
createdAt: Date;
|
|
118
|
+
readAt: Date | null;
|
|
119
|
+
}
|
|
120
|
+
interface NotificationUnreadCounts {
|
|
121
|
+
org: number;
|
|
122
|
+
communities: {
|
|
123
|
+
communityId: string;
|
|
124
|
+
unread: number;
|
|
125
|
+
}[];
|
|
114
126
|
}
|
|
115
127
|
interface NotificationsView {
|
|
116
128
|
rows: NotificationView[];
|
|
@@ -119,6 +131,27 @@ interface NotificationsView {
|
|
|
119
131
|
pageSize: number;
|
|
120
132
|
unreadCount: number;
|
|
121
133
|
}
|
|
134
|
+
interface SettingsChannelView extends ResolvedChannel {
|
|
135
|
+
default: boolean;
|
|
136
|
+
}
|
|
137
|
+
interface NotificationSettingsCategoryView {
|
|
138
|
+
key: string;
|
|
139
|
+
perSpace: boolean;
|
|
140
|
+
channels: SettingsChannelView[];
|
|
141
|
+
spaces?: {
|
|
142
|
+
spaceId: string;
|
|
143
|
+
name: string;
|
|
144
|
+
channels: SettingsChannelView[];
|
|
145
|
+
}[];
|
|
146
|
+
}
|
|
147
|
+
interface CommunityNotificationSettingsView {
|
|
148
|
+
communityId: string;
|
|
149
|
+
digest: DigestSchedule | null;
|
|
150
|
+
categories: NotificationSettingsCategoryView[];
|
|
151
|
+
}
|
|
152
|
+
interface OrgNotificationSettingsView {
|
|
153
|
+
categories: NotificationSettingsCategoryView[];
|
|
154
|
+
}
|
|
122
155
|
//#endregion
|
|
123
|
-
export { type ActivityView, CommunityHome, CommunityHomeLink, CommunityHomeSpace, CourseProgressView, type CourseView, DirectoryEntry, DirectoryQuery, DirectoryRow, type DownloadFile, type DownloadView, LockedCommunitySpace, type Module, NotificationView, NotificationsView, OpenCommunitySpace };
|
|
156
|
+
export { type ActivityView, CommunityHome, CommunityHomeLink, CommunityHomeSpace, CommunityNotificationSettingsView, CourseProgressView, type CourseView, DirectoryEntry, DirectoryQuery, DirectoryRow, type DownloadFile, type DownloadView, LockedCommunitySpace, type Module, NotificationItemView, NotificationSettingsCategoryView, NotificationUnreadCounts, NotificationView, NotificationsView, OpenCommunitySpace, OrgNotificationSettingsView, SettingsChannelView };
|
|
124
157
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Page } from "../../types/shared.js";
|
|
2
2
|
import { ActivityView, CourseView, DownloadFile, DownloadView, Module } from "../../types/schemas/content.js";
|
|
3
|
-
import {
|
|
3
|
+
import { NotificationFilter } from "../../types/notifications.js";
|
|
4
4
|
import "../../types/index.js";
|
|
5
5
|
import { Actor } from "../../shared/actor.js";
|
|
6
|
-
import "
|
|
7
|
-
import { CommunityHome, CommunityHomeSpace, CourseProgressView, DirectoryEntry, DirectoryQuery, DirectoryRow, NotificationView, NotificationsView } from "./model.js";
|
|
6
|
+
import { CommunityHome, CommunityHomeSpace, CommunityNotificationSettingsView, CourseProgressView, DirectoryEntry, DirectoryQuery, DirectoryRow, NotificationUnreadCounts, NotificationView, NotificationsView, OrgNotificationSettingsView } from "./model.js";
|
|
8
7
|
//#region src/reporting/member/ports.d.ts
|
|
9
8
|
interface MemberReportService {
|
|
10
9
|
listCourses(orgId: string, orgUserId: string): Promise<CourseView[]>;
|
|
@@ -28,12 +27,16 @@ interface MemberReportService {
|
|
|
28
27
|
directory(orgId: string, actor: Actor, communityId: string, query: DirectoryQuery): Promise<Page<DirectoryEntry> | null>;
|
|
29
28
|
communityHome(orgId: string, actor: Actor, communityId: string): Promise<CommunityHome | null>;
|
|
30
29
|
communitySpace(orgId: string, actor: Actor, communityId: string, spaceId: string): Promise<CommunityHomeSpace | null>;
|
|
31
|
-
notifications(orgId: string, actor: Actor, userId: string,
|
|
30
|
+
notifications(orgId: string, actor: Actor, userId: string, filter: NotificationFilter, page: {
|
|
32
31
|
page: number;
|
|
33
32
|
pageSize: number;
|
|
34
33
|
}): Promise<NotificationsView>;
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
notification(orgId: string, actor: Actor, userId: string, notificationId: string): Promise<NotificationView | null>;
|
|
35
|
+
notificationUnreadCounts(orgId: string, actor: Actor, userId: string): Promise<NotificationUnreadCounts>;
|
|
36
|
+
/** The person's notification settings in a community they can open, resolved per channel. */
|
|
37
|
+
communityNotificationSettings(orgId: string, actor: Actor, userId: string, communityId: string): Promise<CommunityNotificationSettingsView | null>;
|
|
38
|
+
/** The person's notification settings for the org's categories. */
|
|
39
|
+
orgNotificationSettings(orgId: string, userId: string): Promise<OrgNotificationSettingsView>;
|
|
37
40
|
}
|
|
38
41
|
interface MemberReportRepository {
|
|
39
42
|
directory(orgId: string, communityId: string, query: DirectoryQuery): Promise<Page<DirectoryRow>>;
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { Page } from "../../types/shared.js";
|
|
2
2
|
import { ActivityView, CourseView, DownloadFile, DownloadView, Module } from "../../types/schemas/content.js";
|
|
3
|
-
import {
|
|
3
|
+
import { NotificationFilter } from "../../types/notifications.js";
|
|
4
4
|
import "../../types/index.js";
|
|
5
|
+
import { ChannelRegistry, NotificationCategoryService } from "../../shared/ports.js";
|
|
5
6
|
import { FileUrls } from "../../assets/file-urls.js";
|
|
6
7
|
import { AssetFiles } from "../../assets/ports.js";
|
|
7
8
|
import "../../assets/index.js";
|
|
8
9
|
import { Actor } from "../../shared/actor.js";
|
|
9
|
-
import { ContentService } from "../../content/ports.js";
|
|
10
|
+
import { ContentService, ItemTitles } from "../../content/ports.js";
|
|
10
11
|
import "../../content/index.js";
|
|
11
|
-
import {
|
|
12
|
+
import { NotificationSettingsService } from "../../identity/ports.js";
|
|
12
13
|
import "../../identity/index.js";
|
|
13
14
|
import { EntitlementsService } from "../../entitlements/ports.js";
|
|
14
15
|
import "../../entitlements/index.js";
|
|
15
|
-
import {
|
|
16
|
+
import { NotificationsService } from "../../automations/ports.js";
|
|
17
|
+
import "../../automations/index.js";
|
|
18
|
+
import { ItemTitles as ItemTitles$1, SubscriptionService } from "../../discussion/ports.js";
|
|
16
19
|
import "../../discussion/index.js";
|
|
17
20
|
import { ProgressService } from "../../progress/ports.js";
|
|
18
21
|
import "../../progress/index.js";
|
|
19
|
-
import { CommunityHome, CommunityHomeSpace, CourseProgressView, DirectoryEntry, DirectoryQuery, NotificationView, NotificationsView } from "./model.js";
|
|
22
|
+
import { CommunityHome, CommunityHomeSpace, CommunityNotificationSettingsView, CourseProgressView, DirectoryEntry, DirectoryQuery, NotificationUnreadCounts, NotificationView, NotificationsView, OrgNotificationSettingsView } from "./model.js";
|
|
20
23
|
import { MemberReportRepository, MemberReportService } from "./ports.js";
|
|
21
24
|
//#region src/reporting/member/service.d.ts
|
|
22
|
-
type MemberAccess = Pick<EntitlementsService, 'isCommunityMember' | 'openSpaceIds' | 'spaceStandings' | 'hasAccess' | 'listAccessibleContent'>;
|
|
25
|
+
type MemberAccess = Pick<EntitlementsService, 'isCommunityMember' | 'openSpaceIds' | 'spaceStandings' | 'hasAccess' | 'listAccessibleContent' | 'openCommunityIds'>;
|
|
23
26
|
type MemberReportServiceParams = {
|
|
24
27
|
repo: MemberReportRepository;
|
|
25
28
|
content: ContentService;
|
|
@@ -27,9 +30,18 @@ type MemberReportServiceParams = {
|
|
|
27
30
|
files: Pick<AssetFiles, 'signFile'>;
|
|
28
31
|
fileUrls: FileUrls;
|
|
29
32
|
access: MemberAccess;
|
|
30
|
-
notifications: Pick<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
notifications: Pick<NotificationsService, 'list' | 'get' | 'unreadCounts'>;
|
|
34
|
+
titles: {
|
|
35
|
+
discussion: ItemTitles$1;
|
|
36
|
+
content: ItemTitles;
|
|
37
|
+
};
|
|
38
|
+
subscriptions: Pick<SubscriptionService, 'viewerSubscriptions'>;
|
|
39
|
+
notificationCategories: {
|
|
40
|
+
community: Pick<NotificationCategoryService, 'get'>;
|
|
41
|
+
org: Pick<NotificationCategoryService, 'get'>;
|
|
42
|
+
};
|
|
43
|
+
notificationSettings: Pick<NotificationSettingsService, 'get'>;
|
|
44
|
+
channels: Pick<ChannelRegistry, 'list'>;
|
|
33
45
|
};
|
|
34
46
|
declare class MemberReportServiceImpl implements MemberReportService {
|
|
35
47
|
private readonly repo;
|
|
@@ -38,15 +50,22 @@ declare class MemberReportServiceImpl implements MemberReportService {
|
|
|
38
50
|
private readonly files;
|
|
39
51
|
private readonly fileUrls;
|
|
40
52
|
private readonly access;
|
|
41
|
-
private readonly
|
|
42
|
-
private readonly
|
|
43
|
-
private readonly
|
|
53
|
+
private readonly notificationList;
|
|
54
|
+
private readonly titles;
|
|
55
|
+
private readonly subscriptions;
|
|
56
|
+
private readonly notificationCategories;
|
|
57
|
+
private readonly notificationSettings;
|
|
58
|
+
private readonly channels;
|
|
44
59
|
constructor(params: MemberReportServiceParams);
|
|
45
|
-
|
|
60
|
+
communityNotificationSettings(orgId: string, actor: Actor, userId: string, communityId: string): Promise<CommunityNotificationSettingsView | null>;
|
|
61
|
+
orgNotificationSettings(orgId: string, userId: string): Promise<OrgNotificationSettingsView>;
|
|
62
|
+
private settingsView;
|
|
63
|
+
notifications(orgId: string, actor: Actor, userId: string, filter: NotificationFilter, page: {
|
|
46
64
|
page: number;
|
|
47
65
|
pageSize: number;
|
|
48
66
|
}): Promise<NotificationsView>;
|
|
49
|
-
|
|
67
|
+
notification(orgId: string, actor: Actor, userId: string, notificationId: string): Promise<NotificationView | null>;
|
|
68
|
+
notificationUnreadCounts(orgId: string, actor: Actor, userId: string): Promise<NotificationUnreadCounts>;
|
|
50
69
|
private describeNotifications;
|
|
51
70
|
listCourses(orgId: string, orgUserId: string): Promise<CourseView[]>;
|
|
52
71
|
getCourse(orgId: string, orgUserId: string, courseId: string): Promise<CourseView | null>;
|