@headless-lms/core 0.2.0 → 0.3.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 +39 -21
- package/dist/assets/events.js +1 -1
- package/dist/assets/events.js.map +1 -1
- package/dist/assets/file-urls.d.ts +20 -0
- package/dist/assets/file-urls.js +25 -0
- package/dist/assets/file-urls.js.map +1 -0
- package/dist/assets/index.d.ts +5 -4
- package/dist/assets/index.js +3 -2
- package/dist/assets/model.d.ts +2 -2
- package/dist/assets/ports.d.ts +45 -15
- package/dist/assets/service.d.ts +39 -7
- package/dist/assets/service.js +291 -38
- package/dist/assets/service.js.map +1 -1
- package/dist/automations/actions.d.ts +13 -24
- package/dist/automations/actions.js +168 -43
- package/dist/automations/actions.js.map +1 -1
- package/dist/automations/catalog.d.ts +2 -1
- package/dist/automations/catalog.js +229 -13
- package/dist/automations/catalog.js.map +1 -1
- package/dist/automations/community-derivations.d.ts +14 -0
- package/dist/automations/community-derivations.js +439 -0
- package/dist/automations/community-derivations.js.map +1 -0
- package/dist/automations/community-mail.d.ts +112 -0
- package/dist/automations/community-mail.js +90 -0
- package/dist/automations/community-mail.js.map +1 -0
- package/dist/automations/community-notifications.d.ts +16 -0
- package/dist/automations/community-notifications.js +84 -0
- package/dist/automations/community-notifications.js.map +1 -0
- package/dist/automations/events.d.ts +28 -0
- package/dist/automations/index.d.ts +4 -2
- package/dist/automations/index.js +3 -2
- package/dist/automations/model.d.ts +10 -3
- package/dist/automations/model.js +15 -2
- package/dist/automations/model.js.map +1 -1
- package/dist/automations/ports.d.ts +5 -1
- package/dist/automations/schedule.d.ts +6 -0
- package/dist/automations/schedule.js +41 -0
- package/dist/automations/schedule.js.map +1 -0
- package/dist/automations/seeds.d.ts +17 -0
- package/dist/automations/seeds.js +235 -0
- package/dist/automations/seeds.js.map +1 -0
- package/dist/automations/service.d.ts +22 -3
- package/dist/automations/service.js +306 -43
- package/dist/automations/service.js.map +1 -1
- package/dist/content/events.d.ts +631 -19
- package/dist/content/events.js +44 -1
- package/dist/content/events.js.map +1 -1
- package/dist/content/index.d.ts +4 -4
- package/dist/content/model.d.ts +2 -2
- package/dist/content/ports.d.ts +71 -18
- package/dist/content/service.d.ts +57 -18
- package/dist/content/service.js +502 -23
- package/dist/content/service.js.map +1 -1
- package/dist/content/types.d.ts +2 -2
- package/dist/discussion/authors.d.ts +10 -0
- package/dist/discussion/authors.js +23 -0
- package/dist/discussion/authors.js.map +1 -0
- package/dist/discussion/chats.d.ts +104 -0
- package/dist/discussion/chats.js +798 -0
- package/dist/discussion/chats.js.map +1 -0
- package/dist/discussion/events.d.ts +619 -56
- package/dist/discussion/events.js +106 -3
- package/dist/discussion/events.js.map +1 -1
- package/dist/discussion/index.d.ts +7 -3
- package/dist/discussion/index.js +4 -1
- package/dist/discussion/ports.d.ts +288 -27
- package/dist/discussion/ports.js +6 -1
- package/dist/discussion/ports.js.map +1 -0
- package/dist/discussion/posts.d.ts +103 -0
- package/dist/discussion/posts.js +723 -0
- package/dist/discussion/posts.js.map +1 -0
- package/dist/discussion/service.d.ts +32 -10
- package/dist/discussion/service.js +293 -78
- package/dist/discussion/service.js.map +1 -1
- package/dist/entitlements/events.d.ts +178 -11
- package/dist/entitlements/events.js +28 -1
- package/dist/entitlements/events.js.map +1 -1
- package/dist/entitlements/index.d.ts +5 -4
- package/dist/entitlements/index.js +2 -1
- package/dist/entitlements/model.d.ts +3 -2
- package/dist/entitlements/ports.d.ts +124 -11
- package/dist/entitlements/rules.d.ts +12 -0
- package/dist/entitlements/rules.js +17 -0
- package/dist/entitlements/rules.js.map +1 -0
- package/dist/entitlements/service.d.ts +54 -3
- package/dist/entitlements/service.js +472 -2
- package/dist/entitlements/service.js.map +1 -1
- package/dist/identity/access.d.ts +6 -0
- package/dist/identity/access.js +7 -0
- package/dist/identity/access.js.map +1 -0
- package/dist/identity/index.d.ts +6 -4
- package/dist/identity/index.js +3 -1
- package/dist/identity/model.d.ts +2 -1
- package/dist/identity/notifications.d.ts +27 -0
- package/dist/identity/notifications.js +101 -0
- package/dist/identity/notifications.js.map +1 -0
- package/dist/identity/ports.d.ts +73 -3
- package/dist/identity/service.d.ts +14 -3
- package/dist/identity/service.js +62 -5
- package/dist/identity/service.js.map +1 -1
- package/dist/integrations/model.js +1 -1
- package/dist/integrations/model.js.map +1 -1
- package/dist/integrations/service.js +2 -2
- package/dist/integrations/service.js.map +1 -1
- package/dist/organizations/access-scopes.d.ts +19 -0
- package/dist/organizations/access-scopes.js +89 -0
- package/dist/organizations/access-scopes.js.map +1 -0
- package/dist/organizations/events.d.ts +74 -32
- package/dist/organizations/events.js +6 -0
- package/dist/organizations/events.js.map +1 -1
- package/dist/organizations/index.d.ts +7 -6
- package/dist/organizations/index.js +4 -3
- package/dist/organizations/members.d.ts +8 -5
- package/dist/organizations/members.js.map +1 -1
- package/dist/organizations/ports.d.ts +14 -11
- package/dist/organizations/roles.d.ts +6 -10
- package/dist/organizations/roles.js +19 -7
- package/dist/organizations/roles.js.map +1 -1
- package/dist/organizations/service.d.ts +20 -11
- package/dist/organizations/service.js +157 -47
- package/dist/organizations/service.js.map +1 -1
- package/dist/organizations/types.d.ts +1 -10
- package/dist/progress/index.d.ts +2 -2
- package/dist/progress/ports.d.ts +6 -1
- package/dist/progress/service.d.ts +3 -1
- package/dist/progress/service.js +6 -2
- package/dist/progress/service.js.map +1 -1
- package/dist/reporting/admin/index.d.ts +4 -0
- package/dist/reporting/admin/index.js +2 -0
- package/dist/reporting/admin/model.d.ts +108 -0
- package/dist/reporting/admin/ports.d.ts +27 -0
- package/dist/reporting/admin/service.d.ts +22 -0
- package/dist/reporting/admin/service.js +38 -0
- package/dist/reporting/admin/service.js.map +1 -0
- package/dist/reporting/member/index.d.ts +5 -0
- package/dist/reporting/member/index.js +2 -0
- package/dist/reporting/member/model.d.ts +124 -0
- package/dist/reporting/member/ports.d.ts +45 -0
- package/dist/reporting/member/service.d.ts +73 -0
- package/dist/reporting/member/service.js +286 -0
- package/dist/reporting/member/service.js.map +1 -0
- package/dist/shared/actor.d.ts +9 -0
- package/dist/shared/errors.d.ts +7 -1
- package/dist/shared/errors.js +10 -1
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/id.d.ts +11 -0
- package/dist/shared/id.js +12 -1
- package/dist/shared/id.js.map +1 -1
- package/dist/shared/mailer.d.ts +4 -1
- package/dist/shared/mailer.js.map +1 -1
- package/dist/shared/network.d.ts +10 -0
- package/dist/shared/network.js +211 -0
- package/dist/shared/network.js.map +1 -0
- package/dist/types/assets.d.ts +2 -2
- package/dist/types/automations.d.ts +10 -2
- package/dist/types/content.d.ts +2 -2
- package/dist/types/discussion.d.ts +11 -3
- package/dist/types/email-templates.d.ts +121 -0
- package/dist/types/entitlements.d.ts +2 -2
- package/dist/types/identity.d.ts +48 -2
- package/dist/types/index.d.ts +9 -9
- package/dist/types/ports.d.ts +6 -0
- package/dist/types/schemas/assets.d.ts +65 -37
- package/dist/types/schemas/assets.js +17 -12
- package/dist/types/schemas/assets.js.map +1 -1
- package/dist/types/schemas/automations.d.ts +18 -1
- package/dist/types/schemas/automations.js +15 -6
- package/dist/types/schemas/automations.js.map +1 -1
- package/dist/types/schemas/content.d.ts +335 -3
- package/dist/types/schemas/content.js +139 -3
- package/dist/types/schemas/content.js.map +1 -1
- package/dist/types/schemas/discussion.d.ts +370 -3
- package/dist/types/schemas/discussion.js +199 -4
- package/dist/types/schemas/discussion.js.map +1 -1
- package/dist/types/schemas/entitlements.d.ts +36 -2
- package/dist/types/schemas/entitlements.js +23 -1
- package/dist/types/schemas/entitlements.js.map +1 -1
- package/dist/types/schemas/identity.d.ts +111 -1
- package/dist/types/schemas/identity.js +55 -2
- package/dist/types/schemas/identity.js.map +1 -1
- package/dist/types/schemas/index.d.ts +8 -8
- package/dist/types/schemas/index.js +8 -8
- package/dist/types/schemas/organizations.d.ts +8 -0
- package/dist/types/schemas/organizations.js +2 -0
- package/dist/types/schemas/organizations.js.map +1 -1
- package/dist/types/schemas/shared.d.ts +3 -1
- package/dist/types/schemas/shared.js +5 -1
- package/dist/types/schemas/shared.js.map +1 -1
- package/package.json +2 -2
- package/dist/reporting/courses/index.d.ts +0 -4
- package/dist/reporting/courses/index.js +0 -2
- package/dist/reporting/courses/model.d.ts +0 -24
- package/dist/reporting/courses/ports.d.ts +0 -13
- package/dist/reporting/courses/service.d.ts +0 -19
- package/dist/reporting/courses/service.js +0 -20
- package/dist/reporting/courses/service.js.map +0 -1
- package/dist/reporting/dashboard/index.d.ts +0 -4
- package/dist/reporting/dashboard/index.js +0 -2
- package/dist/reporting/dashboard/model.d.ts +0 -14
- package/dist/reporting/dashboard/ports.d.ts +0 -13
- package/dist/reporting/dashboard/service.d.ts +0 -19
- package/dist/reporting/dashboard/service.js +0 -20
- package/dist/reporting/dashboard/service.js.map +0 -1
- package/dist/reporting/learn/index.d.ts +0 -5
- package/dist/reporting/learn/index.js +0 -2
- package/dist/reporting/learn/model.d.ts +0 -23
- package/dist/reporting/learn/ports.d.ts +0 -43
- package/dist/reporting/learn/ports.js +0 -1
- package/dist/reporting/learn/service.d.ts +0 -49
- package/dist/reporting/learn/service.js +0 -116
- package/dist/reporting/learn/service.js.map +0 -1
- package/dist/reporting/students/index.d.ts +0 -4
- package/dist/reporting/students/index.js +0 -2
- package/dist/reporting/students/model.d.ts +0 -51
- package/dist/reporting/students/model.js +0 -1
- package/dist/reporting/students/ports.d.ts +0 -15
- package/dist/reporting/students/ports.js +0 -1
- package/dist/reporting/students/service.d.ts +0 -20
- package/dist/reporting/students/service.js +0 -23
- package/dist/reporting/students/service.js.map +0 -1
- /package/dist/reporting/{courses → admin}/model.js +0 -0
- /package/dist/reporting/{courses → admin}/ports.js +0 -0
- /package/dist/reporting/{dashboard → member}/model.js +0 -0
- /package/dist/reporting/{dashboard → member}/ports.js +0 -0
- /package/dist/{reporting/learn/model.js → shared/actor.js} +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Logger } from "../types/ports.js";
|
|
2
|
+
import { Notification, NotificationKind, NotificationPreference } from "../types/schemas/identity.js";
|
|
3
|
+
import "../shared/ports.js";
|
|
4
|
+
import "./model.js";
|
|
5
|
+
import { NewNotification, NotificationPage, NotificationService, NotificationsQuery, NotificationsRepository } from "./ports.js";
|
|
6
|
+
//#region src/identity/notifications.d.ts
|
|
7
|
+
declare function defaultPreference(kind: NotificationKind): NotificationPreference;
|
|
8
|
+
declare class NotificationServiceImpl implements NotificationService {
|
|
9
|
+
private readonly repo;
|
|
10
|
+
private readonly logger;
|
|
11
|
+
constructor(params: {
|
|
12
|
+
repo: NotificationsRepository;
|
|
13
|
+
logger?: Logger;
|
|
14
|
+
});
|
|
15
|
+
notify(orgId: string, notifications: NewNotification[]): Promise<void>;
|
|
16
|
+
preferencesFor(orgId: string, userIds: string[], kind: NotificationKind): Promise<Record<string, NotificationPreference>>;
|
|
17
|
+
listNotifications(orgId: string, userId: string, query: NotificationsQuery): Promise<NotificationPage>;
|
|
18
|
+
markNotificationRead(orgId: string, userId: string, notificationId: string): Promise<Notification>;
|
|
19
|
+
markAllNotificationsRead(orgId: string, userId: string): Promise<{
|
|
20
|
+
updated: number;
|
|
21
|
+
}>;
|
|
22
|
+
notificationPreferences(orgId: string, userId: string): Promise<NotificationPreference[]>;
|
|
23
|
+
setNotificationPreferences(orgId: string, userId: string, preferences: NotificationPreference[]): Promise<NotificationPreference[]>;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { NotificationServiceImpl, defaultPreference };
|
|
27
|
+
//# sourceMappingURL=notifications.d.ts.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { notificationKindSchema } from "../types/schemas/identity.js";
|
|
2
|
+
import { genId } from "../shared/id.js";
|
|
3
|
+
import { NotFoundError } from "../shared/errors.js";
|
|
4
|
+
import { noopLogger } from "../shared/logger.js";
|
|
5
|
+
//#region src/identity/notifications.ts
|
|
6
|
+
function defaultPreference(kind) {
|
|
7
|
+
return {
|
|
8
|
+
kind,
|
|
9
|
+
inApp: true,
|
|
10
|
+
email: true
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
var NotificationServiceImpl = class {
|
|
14
|
+
repo;
|
|
15
|
+
logger;
|
|
16
|
+
constructor(params) {
|
|
17
|
+
this.repo = params.repo;
|
|
18
|
+
this.logger = params.logger ?? noopLogger;
|
|
19
|
+
}
|
|
20
|
+
async notify(orgId, notifications) {
|
|
21
|
+
if (notifications.length === 0) return;
|
|
22
|
+
const now = /* @__PURE__ */ new Date();
|
|
23
|
+
const rows = notifications.map((notification) => ({
|
|
24
|
+
...notification,
|
|
25
|
+
orgId,
|
|
26
|
+
id: genId("notification"),
|
|
27
|
+
createdAt: now,
|
|
28
|
+
readAt: null
|
|
29
|
+
}));
|
|
30
|
+
await this.repo.insert(orgId, rows);
|
|
31
|
+
this.logger.info("notifications added", {
|
|
32
|
+
orgId,
|
|
33
|
+
kinds: [...new Set(rows.map((row) => row.kind))],
|
|
34
|
+
count: rows.length
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async preferencesFor(orgId, userIds, kind) {
|
|
38
|
+
const unique = [...new Set(userIds)];
|
|
39
|
+
const stored = await this.repo.preferences(orgId, unique);
|
|
40
|
+
const result = {};
|
|
41
|
+
for (const userId of unique) result[userId] = defaultPreference(kind);
|
|
42
|
+
for (const row of stored) if (row.kind === kind) result[row.userId] = {
|
|
43
|
+
kind,
|
|
44
|
+
inApp: row.inApp,
|
|
45
|
+
email: row.email
|
|
46
|
+
};
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
async listNotifications(orgId, userId, query) {
|
|
50
|
+
const page = await this.repo.page(orgId, userId, query);
|
|
51
|
+
this.logger.debug("notifications listed", {
|
|
52
|
+
orgId,
|
|
53
|
+
userId,
|
|
54
|
+
count: page.rows.length
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
...page,
|
|
58
|
+
page: query.page,
|
|
59
|
+
pageSize: query.pageSize
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async markNotificationRead(orgId, userId, notificationId) {
|
|
63
|
+
const row = await this.repo.markRead(orgId, userId, notificationId, /* @__PURE__ */ new Date());
|
|
64
|
+
if (!row) throw new NotFoundError("Notification", notificationId);
|
|
65
|
+
return row;
|
|
66
|
+
}
|
|
67
|
+
async markAllNotificationsRead(orgId, userId) {
|
|
68
|
+
const updated = await this.repo.markAllRead(orgId, userId, /* @__PURE__ */ new Date());
|
|
69
|
+
this.logger.debug("notifications marked read", {
|
|
70
|
+
orgId,
|
|
71
|
+
userId,
|
|
72
|
+
updated
|
|
73
|
+
});
|
|
74
|
+
return { updated };
|
|
75
|
+
}
|
|
76
|
+
async notificationPreferences(orgId, userId) {
|
|
77
|
+
const stored = await this.repo.preferences(orgId, [userId]);
|
|
78
|
+
const byKind = new Map(stored.map((row) => [row.kind, row]));
|
|
79
|
+
return notificationKindSchema.options.map((kind) => {
|
|
80
|
+
const row = byKind.get(kind);
|
|
81
|
+
return row ? {
|
|
82
|
+
kind,
|
|
83
|
+
inApp: row.inApp,
|
|
84
|
+
email: row.email
|
|
85
|
+
} : defaultPreference(kind);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async setNotificationPreferences(orgId, userId, preferences) {
|
|
89
|
+
await this.repo.upsertPreferences(orgId, userId, preferences);
|
|
90
|
+
this.logger.info("notification preferences updated", {
|
|
91
|
+
orgId,
|
|
92
|
+
userId,
|
|
93
|
+
kinds: preferences.map((pref) => pref.kind)
|
|
94
|
+
});
|
|
95
|
+
return this.notificationPreferences(orgId, userId);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
export { NotificationServiceImpl, defaultPreference };
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=notifications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications.js","names":[],"sources":["../../src/identity/notifications.ts"],"sourcesContent":["import { NotFoundError } from '../shared/errors.js';\nimport { genId } from '../shared/id.js';\nimport { noopLogger } from '../shared/logger.js';\nimport type { Logger } from '../shared/ports.js';\nimport { notificationKindSchema } from '../types/schemas/identity.js';\nimport type { Notification, NotificationKind, NotificationPreference } from './model.js';\nimport type {\n NewNotification,\n NotificationPage,\n NotificationService,\n NotificationsQuery,\n NotificationsRepository,\n} from './ports.js';\n\nexport function defaultPreference(kind: NotificationKind): NotificationPreference {\n return { kind, inApp: true, email: true };\n}\n\nexport class NotificationServiceImpl implements NotificationService {\n private readonly repo: NotificationsRepository;\n private readonly logger: Logger;\n\n constructor(params: { repo: NotificationsRepository; logger?: Logger }) {\n this.repo = params.repo;\n this.logger = params.logger ?? noopLogger;\n }\n\n async notify(orgId: string, notifications: NewNotification[]): Promise<void> {\n if (notifications.length === 0) {\n return;\n }\n const now = new Date();\n const rows: Notification[] = notifications.map((notification) => ({\n ...notification,\n orgId,\n id: genId('notification'),\n createdAt: now,\n readAt: null,\n }));\n await this.repo.insert(orgId, rows);\n this.logger.info('notifications added', {\n orgId,\n kinds: [...new Set(rows.map((row) => row.kind))],\n count: rows.length,\n });\n }\n\n async preferencesFor(\n orgId: string,\n userIds: string[],\n kind: NotificationKind,\n ): Promise<Record<string, NotificationPreference>> {\n const unique = [...new Set(userIds)];\n const stored = await this.repo.preferences(orgId, unique);\n const result: Record<string, NotificationPreference> = {};\n for (const userId of unique) {\n result[userId] = defaultPreference(kind);\n }\n for (const row of stored) {\n if (row.kind === kind) {\n result[row.userId] = { kind, inApp: row.inApp, email: row.email };\n }\n }\n return result;\n }\n\n async listNotifications(\n orgId: string,\n userId: string,\n query: NotificationsQuery,\n ): Promise<NotificationPage> {\n const page = await this.repo.page(orgId, userId, query);\n this.logger.debug('notifications listed', { orgId, userId, count: page.rows.length });\n return { ...page, page: query.page, pageSize: query.pageSize };\n }\n\n async markNotificationRead(\n orgId: string,\n userId: string,\n notificationId: string,\n ): Promise<Notification> {\n const row = await this.repo.markRead(orgId, userId, notificationId, new Date());\n if (!row) {\n throw new NotFoundError('Notification', notificationId);\n }\n return row;\n }\n\n async markAllNotificationsRead(orgId: string, userId: string): Promise<{ updated: number }> {\n const updated = await this.repo.markAllRead(orgId, userId, new Date());\n this.logger.debug('notifications marked read', { orgId, userId, updated });\n return { updated };\n }\n\n async notificationPreferences(orgId: string, userId: string): Promise<NotificationPreference[]> {\n const stored = await this.repo.preferences(orgId, [userId]);\n const byKind = new Map(stored.map((row) => [row.kind, row]));\n return notificationKindSchema.options.map((kind) => {\n const row = byKind.get(kind);\n return row ? { kind, inApp: row.inApp, email: row.email } : defaultPreference(kind);\n });\n }\n\n async setNotificationPreferences(\n orgId: string,\n userId: string,\n preferences: NotificationPreference[],\n ): Promise<NotificationPreference[]> {\n await this.repo.upsertPreferences(orgId, userId, preferences);\n this.logger.info('notification preferences updated', {\n orgId,\n userId,\n kinds: preferences.map((pref) => pref.kind),\n });\n return this.notificationPreferences(orgId, userId);\n }\n}\n"],"mappings":";;;;;AAcA,SAAgB,kBAAkB,MAAgD;CAChF,OAAO;EAAE;EAAM,OAAO;EAAM,OAAO;CAAK;AAC1C;AAEA,IAAa,0BAAb,MAAoE;CAClE;CACA;CAEA,YAAY,QAA4D;EACtE,KAAK,OAAO,OAAO;EACnB,KAAK,SAAS,OAAO,UAAU;CACjC;CAEA,MAAM,OAAO,OAAe,eAAiD;EAC3E,IAAI,cAAc,WAAW,GAC3B;EAEF,MAAM,sBAAM,IAAI,KAAK;EACrB,MAAM,OAAuB,cAAc,KAAK,kBAAkB;GAChE,GAAG;GACH;GACA,IAAI,MAAM,cAAc;GACxB,WAAW;GACX,QAAQ;EACV,EAAE;EACF,MAAM,KAAK,KAAK,OAAO,OAAO,IAAI;EAClC,KAAK,OAAO,KAAK,uBAAuB;GACtC;GACA,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC;GAC/C,OAAO,KAAK;EACd,CAAC;CACH;CAEA,MAAM,eACJ,OACA,SACA,MACiD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,IAAI,IAAI;GAC3B,OAAO,MAAM;IAAE;IAAM,OAAO,IAAI;IAAO,OAAO,IAAI;GAAM,IAAI,kBAAkB,IAAI;EACpF,CAAC;CACH;CAEA,MAAM,2BACJ,OACA,QACA,aACmC;EACnC,MAAM,KAAK,KAAK,kBAAkB,OAAO,QAAQ,WAAW;EAC5D,KAAK,OAAO,KAAK,oCAAoC;GACnD;GACA;GACA,OAAO,YAAY,KAAK,SAAS,KAAK,IAAI;EAC5C,CAAC;EACD,OAAO,KAAK,wBAAwB,OAAO,MAAM;CACnD;AACF"}
|
package/dist/identity/ports.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonValue } from "../types/shared.js";
|
|
2
|
+
import { CreateUserInput, Notification, NotificationKind, NotificationPreference, UpdateUserInput, UserProfile, UserProfileView } from "../types/schemas/identity.js";
|
|
2
3
|
import { User } from "../types/identity.js";
|
|
4
|
+
import "../types/index.js";
|
|
3
5
|
import { OutboxAppender, UnitOfWork } from "../shared/ports.js";
|
|
4
6
|
import "./model.js";
|
|
5
7
|
import "./types.js";
|
|
6
8
|
//#region src/identity/ports.d.ts
|
|
9
|
+
interface UpdateProfileInput {
|
|
10
|
+
displayName?: string | null;
|
|
11
|
+
headline?: string | null;
|
|
12
|
+
bio?: string | null;
|
|
13
|
+
imageAssetId?: string | null;
|
|
14
|
+
extra?: JsonValue;
|
|
15
|
+
}
|
|
16
|
+
interface ProfilePatch extends UpdateProfileInput {
|
|
17
|
+
imageAssetOrgId?: string | null;
|
|
18
|
+
}
|
|
7
19
|
interface UserProvisioner {
|
|
8
20
|
createUser(input: CreateUserInput): Promise<User>;
|
|
9
21
|
/** Auth signup entry point. Claims a person provisioned at invite time by
|
|
@@ -43,13 +55,71 @@ interface SessionAdmin {
|
|
|
43
55
|
/** Points the caller's current session at `orgId`. */
|
|
44
56
|
stampActiveOrganization(headers: AuthHeaders, orgId: string): Promise<boolean>;
|
|
45
57
|
}
|
|
46
|
-
interface
|
|
58
|
+
interface NewNotification {
|
|
59
|
+
userId: string;
|
|
60
|
+
kind: NotificationKind;
|
|
61
|
+
actorOrgUserId: string | null;
|
|
62
|
+
communityId: string | null;
|
|
63
|
+
spaceId: string | null;
|
|
64
|
+
postId: string | null;
|
|
65
|
+
commentId: string | null;
|
|
66
|
+
chatId: string | null;
|
|
67
|
+
messageId: string | null;
|
|
68
|
+
}
|
|
69
|
+
interface NotificationsQuery {
|
|
70
|
+
page: number;
|
|
71
|
+
pageSize: number;
|
|
72
|
+
}
|
|
73
|
+
interface NotificationPage {
|
|
74
|
+
rows: Notification[];
|
|
75
|
+
total: number;
|
|
76
|
+
page: number;
|
|
77
|
+
pageSize: number;
|
|
78
|
+
unreadCount: number;
|
|
79
|
+
}
|
|
80
|
+
/** What automations calls to tell people. */
|
|
81
|
+
interface NotificationDesk {
|
|
82
|
+
notify(orgId: string, notifications: NewNotification[]): Promise<void>;
|
|
83
|
+
preferencesFor(orgId: string, userIds: string[], kind: NotificationKind): Promise<Record<string, NotificationPreference>>;
|
|
84
|
+
}
|
|
85
|
+
/** A person's own notifications and preferences. */
|
|
86
|
+
interface NotificationInbox {
|
|
87
|
+
listNotifications(orgId: string, userId: string, query: NotificationsQuery): Promise<NotificationPage>;
|
|
88
|
+
markNotificationRead(orgId: string, userId: string, notificationId: string): Promise<Notification>;
|
|
89
|
+
markAllNotificationsRead(orgId: string, userId: string): Promise<{
|
|
90
|
+
updated: number;
|
|
91
|
+
}>;
|
|
92
|
+
notificationPreferences(orgId: string, userId: string): Promise<NotificationPreference[]>;
|
|
93
|
+
setNotificationPreferences(orgId: string, userId: string, preferences: NotificationPreference[]): Promise<NotificationPreference[]>;
|
|
94
|
+
}
|
|
95
|
+
interface NotificationService extends NotificationDesk, NotificationInbox {}
|
|
96
|
+
interface IdentityService extends UserProvisioner, UserResolver, UserEditor {
|
|
97
|
+
profileOf(orgId: string, userId: string): Promise<UserProfileView>;
|
|
98
|
+
displayName(userId: string | null): Promise<string>;
|
|
99
|
+
updateProfile(orgId: string, userId: string, actorUserId: string, orgUserId: string, patch: UpdateProfileInput): Promise<UserProfileView>;
|
|
100
|
+
}
|
|
47
101
|
interface IdentityRepository {
|
|
48
102
|
insertUser(input: CreateUserInput): Promise<User>;
|
|
49
103
|
updateUser(id: string, input: UpdateUserInput): Promise<User | null>;
|
|
50
104
|
findUserById(id: string): Promise<User | null>;
|
|
51
105
|
findUserByExternalId(externalId: string): Promise<User | null>;
|
|
52
106
|
findUserByEmail(email: string): Promise<User | null>;
|
|
107
|
+
findProfile(userId: string): Promise<UserProfile | null>;
|
|
108
|
+
upsertProfile(userId: string, patch: ProfilePatch): Promise<UserProfile>;
|
|
109
|
+
}
|
|
110
|
+
interface NotificationsRepository {
|
|
111
|
+
insert(orgId: string, rows: Notification[]): Promise<void>;
|
|
112
|
+
page(orgId: string, userId: string, query: NotificationsQuery): Promise<{
|
|
113
|
+
rows: Notification[];
|
|
114
|
+
total: number;
|
|
115
|
+
unreadCount: number;
|
|
116
|
+
}>;
|
|
117
|
+
markRead(orgId: string, userId: string, notificationId: string, at: Date): Promise<Notification | null>;
|
|
118
|
+
markAllRead(orgId: string, userId: string, at: Date): Promise<number>;
|
|
119
|
+
preferences(orgId: string, userIds: string[]): Promise<(NotificationPreference & {
|
|
120
|
+
userId: string;
|
|
121
|
+
})[]>;
|
|
122
|
+
upsertPreferences(orgId: string, userId: string, preferences: NotificationPreference[]): Promise<void>;
|
|
53
123
|
}
|
|
54
124
|
interface IdentityTxScope {
|
|
55
125
|
identity: IdentityRepository;
|
|
@@ -57,5 +127,5 @@ interface IdentityTxScope {
|
|
|
57
127
|
}
|
|
58
128
|
type IdentityUnitOfWork = UnitOfWork<IdentityTxScope>;
|
|
59
129
|
//#endregion
|
|
60
|
-
export { AuthHeaders, IdentityRepository, IdentityService, IdentityTxScope, IdentityUnitOfWork, SessionAdmin, UserEditor, UserProvisioner, UserResolver };
|
|
130
|
+
export { AuthHeaders, IdentityRepository, IdentityService, IdentityTxScope, IdentityUnitOfWork, NewNotification, NotificationDesk, NotificationInbox, NotificationPage, NotificationService, NotificationsQuery, NotificationsRepository, ProfilePatch, SessionAdmin, UpdateProfileInput, UserEditor, UserProvisioner, UserResolver };
|
|
61
131
|
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { Logger } from "../types/ports.js";
|
|
2
|
-
import { CreateUserInput, UpdateUserInput } from "../types/schemas/identity.js";
|
|
2
|
+
import { CreateUserInput, UpdateUserInput, UserProfileView } from "../types/schemas/identity.js";
|
|
3
3
|
import { User } from "../types/identity.js";
|
|
4
4
|
import "../shared/ports.js";
|
|
5
|
-
import {
|
|
5
|
+
import { FileUrls } from "../assets/file-urls.js";
|
|
6
|
+
import { MemberImageReader } from "../assets/ports.js";
|
|
7
|
+
import "../assets/index.js";
|
|
6
8
|
import "./model.js";
|
|
7
9
|
import "./types.js";
|
|
8
|
-
import { IdentityRepository, IdentityService, IdentityUnitOfWork } from "./ports.js";
|
|
10
|
+
import { IdentityRepository, IdentityService, IdentityUnitOfWork, UpdateProfileInput } from "./ports.js";
|
|
11
|
+
import { Mailer } from "../shared/mailer.js";
|
|
9
12
|
//#region src/identity/service.d.ts
|
|
10
13
|
declare class IdentityServiceImpl implements IdentityService {
|
|
11
14
|
private readonly repo;
|
|
12
15
|
private readonly logger;
|
|
13
16
|
private readonly uow;
|
|
14
17
|
private readonly mailer;
|
|
18
|
+
private readonly images;
|
|
19
|
+
private readonly fileUrls;
|
|
15
20
|
constructor(input: {
|
|
16
21
|
repo: IdentityRepository;
|
|
17
22
|
logger?: Logger;
|
|
18
23
|
mailer: Mailer;
|
|
19
24
|
uow: IdentityUnitOfWork;
|
|
25
|
+
images: MemberImageReader;
|
|
26
|
+
fileUrls: FileUrls;
|
|
20
27
|
});
|
|
21
28
|
createUser(input: CreateUserInput): Promise<User>;
|
|
22
29
|
linkOrCreateUser(input: CreateUserInput): Promise<User>;
|
|
@@ -35,6 +42,10 @@ declare class IdentityServiceImpl implements IdentityService {
|
|
|
35
42
|
email: string;
|
|
36
43
|
url: string;
|
|
37
44
|
}): Promise<void>;
|
|
45
|
+
profileOf(orgId: string, userId: string): Promise<UserProfileView>;
|
|
46
|
+
private view;
|
|
47
|
+
displayName(userId: string | null): Promise<string>;
|
|
48
|
+
updateProfile(orgId: string, userId: string, actorUserId: string, orgUserId: string, patch: UpdateProfileInput): Promise<UserProfileView>;
|
|
38
49
|
}
|
|
39
50
|
//#endregion
|
|
40
51
|
export { IdentityServiceImpl };
|
package/dist/identity/service.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import { noopLogger } from "../shared/logger.js";
|
|
2
1
|
import { genId } from "../shared/id.js";
|
|
3
|
-
import { ConflictError, NotFoundError } from "../shared/errors.js";
|
|
2
|
+
import { ConflictError, ForbiddenError, NotFoundError } from "../shared/errors.js";
|
|
3
|
+
import { noopLogger } from "../shared/logger.js";
|
|
4
4
|
import { identityEvents } from "./events.js";
|
|
5
5
|
//#region src/identity/service.ts
|
|
6
|
+
const UNNAMED = "A member";
|
|
6
7
|
var IdentityServiceImpl = class {
|
|
7
8
|
repo;
|
|
8
9
|
logger;
|
|
9
10
|
uow;
|
|
10
11
|
mailer;
|
|
12
|
+
images;
|
|
13
|
+
fileUrls;
|
|
11
14
|
constructor(input) {
|
|
12
15
|
this.repo = input.repo;
|
|
13
16
|
this.mailer = input.mailer;
|
|
14
17
|
this.logger = input.logger ?? noopLogger;
|
|
15
18
|
this.uow = input.uow;
|
|
19
|
+
this.images = input.images;
|
|
20
|
+
this.fileUrls = input.fileUrls;
|
|
16
21
|
}
|
|
17
22
|
async createUser(input) {
|
|
18
23
|
const created = await this.uow.run(async ({ identity, outbox }) => {
|
|
@@ -23,7 +28,7 @@ var IdentityServiceImpl = class {
|
|
|
23
28
|
})]);
|
|
24
29
|
return user;
|
|
25
30
|
});
|
|
26
|
-
this.logger.info("user created", {
|
|
31
|
+
this.logger.info("user created", { userId: created.id });
|
|
27
32
|
return created;
|
|
28
33
|
}
|
|
29
34
|
async linkOrCreateUser(input) {
|
|
@@ -49,7 +54,7 @@ var IdentityServiceImpl = class {
|
|
|
49
54
|
})]);
|
|
50
55
|
return user;
|
|
51
56
|
});
|
|
52
|
-
this.logger.info("user linked to auth account", {
|
|
57
|
+
this.logger.info("user linked to auth account", { userId: linked.id });
|
|
53
58
|
return linked;
|
|
54
59
|
}
|
|
55
60
|
async updateUser(id, input) {
|
|
@@ -62,7 +67,7 @@ var IdentityServiceImpl = class {
|
|
|
62
67
|
})]);
|
|
63
68
|
return user;
|
|
64
69
|
});
|
|
65
|
-
this.logger.info("user updated", {
|
|
70
|
+
this.logger.info("user updated", { userId: updated.id });
|
|
66
71
|
return updated;
|
|
67
72
|
}
|
|
68
73
|
async getUserByExternalId(externalId) {
|
|
@@ -83,6 +88,58 @@ var IdentityServiceImpl = class {
|
|
|
83
88
|
async sendMagicLink(input) {
|
|
84
89
|
await this.mailer.send(input.email, "magicLink", { url: input.url });
|
|
85
90
|
}
|
|
91
|
+
async profileOf(orgId, userId) {
|
|
92
|
+
const stored = await this.repo.findProfile(userId);
|
|
93
|
+
if (stored) return this.view(orgId, stored);
|
|
94
|
+
const never = /* @__PURE__ */ new Date(0);
|
|
95
|
+
return {
|
|
96
|
+
userId,
|
|
97
|
+
displayName: null,
|
|
98
|
+
headline: null,
|
|
99
|
+
bio: null,
|
|
100
|
+
imageAssetOrgId: null,
|
|
101
|
+
imageAssetId: null,
|
|
102
|
+
imageUrl: null,
|
|
103
|
+
extra: {},
|
|
104
|
+
createdAt: never,
|
|
105
|
+
updatedAt: never
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
view(orgId, profile) {
|
|
109
|
+
const imageAssetId = profile.imageAssetOrgId === orgId ? profile.imageAssetId : null;
|
|
110
|
+
return {
|
|
111
|
+
...profile,
|
|
112
|
+
imageUrl: imageAssetId ? this.fileUrls.memberUpload(imageAssetId) : null
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async displayName(userId) {
|
|
116
|
+
if (userId === null) return UNNAMED;
|
|
117
|
+
const [profile, user] = await Promise.all([this.repo.findProfile(userId), this.repo.findUserById(userId)]);
|
|
118
|
+
const named = profile?.displayName?.trim();
|
|
119
|
+
if (named) return named;
|
|
120
|
+
return [user?.firstName, user?.lastName].filter(Boolean).join(" ").trim() || UNNAMED;
|
|
121
|
+
}
|
|
122
|
+
async updateProfile(orgId, userId, actorUserId, orgUserId, patch) {
|
|
123
|
+
if (actorUserId !== userId) throw new ForbiddenError("You can only update your own profile");
|
|
124
|
+
if (!await this.repo.findUserById(userId)) throw new NotFoundError("User", userId);
|
|
125
|
+
if (patch.imageAssetId != null) {
|
|
126
|
+
if (!await this.images.ownsImage(orgId, patch.imageAssetId, orgUserId)) {
|
|
127
|
+
this.logger.debug("profile photo refused", {
|
|
128
|
+
userId,
|
|
129
|
+
orgUserId,
|
|
130
|
+
assetId: patch.imageAssetId
|
|
131
|
+
});
|
|
132
|
+
throw new NotFoundError("Asset", patch.imageAssetId);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const imageAssetOrgId = patch.imageAssetId === void 0 ? void 0 : patch.imageAssetId === null ? null : orgId;
|
|
136
|
+
const profile = await this.repo.upsertProfile(userId, {
|
|
137
|
+
...patch,
|
|
138
|
+
imageAssetOrgId
|
|
139
|
+
});
|
|
140
|
+
this.logger.info("profile updated", { userId });
|
|
141
|
+
return this.view(orgId, profile);
|
|
142
|
+
}
|
|
86
143
|
};
|
|
87
144
|
//#endregion
|
|
88
145
|
export { IdentityServiceImpl };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","names":[],"sources":["../../src/identity/service.ts"],"sourcesContent":["import type { IdentityRepository, IdentityService, IdentityUnitOfWork } from './ports.js';\nimport type { User } from './model.js';\nimport type { CreateUserInput, UpdateUserInput } from './types.js';\nimport type { Logger } from '../shared/ports.js';\nimport { noopLogger } from '../shared/logger.js';\nimport { genId } from '../shared/id.js';\nimport { ConflictError, NotFoundError } from '../shared/errors.js';\nimport type { Mailer } from '../shared/mailer.js';\nimport { identityEvents } from './events.js';\n\nexport class IdentityServiceImpl implements IdentityService {\n private readonly repo: IdentityRepository;\n private readonly logger: Logger;\n private readonly uow: IdentityUnitOfWork;\n private readonly mailer: Pick<Mailer, 'send'>;\n\n constructor(input: {\n repo: IdentityRepository;\n logger?: Logger;\n mailer: Mailer;\n uow: IdentityUnitOfWork;\n }) {\n this.repo = input.repo;\n this.mailer = input.mailer;\n this.logger = input.logger ?? noopLogger;\n this.uow = input.uow;\n }\n\n async createUser(input: CreateUserInput): Promise<User> {\n const created = await this.uow.run(async ({ identity, outbox }) => {\n const user = await identity.insertUser(input);\n await outbox.append([identityEvents.userCreated.make({ orgId: '-', data: user })]);\n return user;\n });\n this.logger.info('user created', {
|
|
1
|
+
{"version":3,"file":"service.js","names":[],"sources":["../../src/identity/service.ts"],"sourcesContent":["import type { IdentityRepository, IdentityService, IdentityUnitOfWork } from './ports.js';\nimport type { User, UserProfile, UserProfileView } from './model.js';\nimport type { UpdateProfileInput } from './ports.js';\nimport type { CreateUserInput, UpdateUserInput } from './types.js';\nimport type { Logger } from '../shared/ports.js';\nimport { noopLogger } from '../shared/logger.js';\nimport { genId } from '../shared/id.js';\nimport { ConflictError, ForbiddenError, NotFoundError } from '../shared/errors.js';\nimport type { Mailer } from '../shared/mailer.js';\nimport type { FileUrls, MemberImageReader } from '../assets/index.js';\nimport { identityEvents } from './events.js';\n\nconst UNNAMED = 'A member';\n\nexport class IdentityServiceImpl implements IdentityService {\n private readonly repo: IdentityRepository;\n private readonly logger: Logger;\n private readonly uow: IdentityUnitOfWork;\n private readonly mailer: Pick<Mailer, 'send'>;\n private readonly images: MemberImageReader;\n private readonly fileUrls: FileUrls;\n\n constructor(input: {\n repo: IdentityRepository;\n logger?: Logger;\n mailer: Mailer;\n uow: IdentityUnitOfWork;\n images: MemberImageReader;\n fileUrls: FileUrls;\n }) {\n this.repo = input.repo;\n this.mailer = input.mailer;\n this.logger = input.logger ?? noopLogger;\n this.uow = input.uow;\n this.images = input.images;\n this.fileUrls = input.fileUrls;\n }\n\n async createUser(input: CreateUserInput): Promise<User> {\n const created = await this.uow.run(async ({ identity, outbox }) => {\n const user = await identity.insertUser(input);\n await outbox.append([identityEvents.userCreated.make({ orgId: '-', data: user })]);\n return user;\n });\n this.logger.info('user created', { userId: created.id });\n return created;\n }\n\n async linkOrCreateUser(input: CreateUserInput): Promise<User> {\n const existing = await this.repo.findUserByEmail(input.email);\n if (!existing) {\n const id = input.id ?? genId('user');\n return this.createUser({ ...input, id, externalId: id });\n }\n if (existing.externalId !== null) {\n throw new ConflictError('That email already has an account');\n }\n // Existing user without external link, so invited. update the user with the\n // id.\n const linked = await this.uow.run(async ({ identity, outbox }) => {\n const user = await identity.updateUser(existing.id, {\n externalId: existing.id,\n ...(input.firstName !== undefined && { firstName: input.firstName }),\n ...(input.lastName !== undefined && { lastName: input.lastName }),\n });\n await outbox.append([identityEvents.userUpdated.make({ orgId: '-', data: user! })]);\n return user!;\n });\n this.logger.info('user linked to auth account', { userId: linked.id });\n return linked;\n }\n\n async updateUser(id: string, input: UpdateUserInput): Promise<User> {\n const person = await this.repo.findUserById(id);\n if (!person) {\n throw new NotFoundError('User', id);\n }\n\n const updated = await this.uow.run(async ({ identity, outbox }) => {\n const user = await identity.updateUser(id, input);\n await outbox.append([identityEvents.userUpdated.make({ orgId: '-', data: user! })]);\n return user!;\n });\n this.logger.info('user updated', { userId: updated.id });\n return updated;\n }\n\n async getUserByExternalId(externalId: string): Promise<User | null> {\n return this.repo.findUserByExternalId(externalId);\n }\n\n async getUserByEmail(email: string): Promise<User | null> {\n return this.repo.findUserByEmail(email);\n }\n\n async getUserById(id: string): Promise<User | null> {\n return this.repo.findUserById(id);\n }\n\n async sendPasswordReset(input: { email: string; url: string }): Promise<void> {\n await this.mailer.send(input.email, 'passwordReset', { resetUrl: input.url });\n }\n\n async sendPasswordChanged(input: { email: string }): Promise<void> {\n await this.mailer.send(input.email, 'passwordChanged', {});\n }\n\n async sendMagicLink(input: { email: string; url: string }): Promise<void> {\n await this.mailer.send(input.email, 'magicLink', { url: input.url });\n }\n\n async profileOf(orgId: string, userId: string): Promise<UserProfileView> {\n const stored = await this.repo.findProfile(userId);\n if (stored) {\n return this.view(orgId, stored);\n }\n const never = new Date(0);\n return {\n userId,\n displayName: null,\n headline: null,\n bio: null,\n imageAssetOrgId: null,\n imageAssetId: null,\n imageUrl: null,\n extra: {},\n createdAt: never,\n updatedAt: never,\n };\n }\n\n private view(orgId: string, profile: UserProfile): UserProfileView {\n const imageAssetId = profile.imageAssetOrgId === orgId ? profile.imageAssetId : null;\n return { ...profile, imageUrl: imageAssetId ? this.fileUrls.memberUpload(imageAssetId) : null };\n }\n\n async displayName(userId: string | null): Promise<string> {\n if (userId === null) {\n return UNNAMED;\n }\n const [profile, user] = await Promise.all([\n this.repo.findProfile(userId),\n this.repo.findUserById(userId),\n ]);\n const named = profile?.displayName?.trim();\n if (named) {\n return named;\n }\n const composed = [user?.firstName, user?.lastName].filter(Boolean).join(' ').trim();\n return composed || UNNAMED;\n }\n\n async updateProfile(\n orgId: string,\n userId: string,\n actorUserId: string,\n orgUserId: string,\n patch: UpdateProfileInput,\n ): Promise<UserProfileView> {\n if (actorUserId !== userId) {\n throw new ForbiddenError('You can only update your own profile');\n }\n const user = await this.repo.findUserById(userId);\n if (!user) {\n throw new NotFoundError('User', userId);\n }\n if (patch.imageAssetId != null) {\n const owned = await this.images.ownsImage(orgId, patch.imageAssetId, orgUserId);\n if (!owned) {\n this.logger.debug('profile photo refused', {\n userId,\n orgUserId,\n assetId: patch.imageAssetId,\n });\n throw new NotFoundError('Asset', patch.imageAssetId);\n }\n }\n const imageAssetOrgId =\n patch.imageAssetId === undefined ? undefined : patch.imageAssetId === null ? null : orgId;\n const profile = await this.repo.upsertProfile(userId, { ...patch, imageAssetOrgId });\n this.logger.info('profile updated', { userId });\n return this.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GAAG;GAAO;EAAgB,CAAC;EACnF,KAAK,OAAO,KAAK,mBAAmB,EAAE,OAAO,CAAC;EAC9C,OAAO,KAAK,KAAK,OAAO,OAAO;CACjC;AACF"}
|
|
@@ -22,7 +22,7 @@ var ActionInvocationError = class extends Error {
|
|
|
22
22
|
integrationId;
|
|
23
23
|
actionId;
|
|
24
24
|
constructor(integrationId, actionId, cause) {
|
|
25
|
-
super(`action "${integrationId}.${actionId}" failed: ${cause instanceof Error ? cause.message : String(cause)}
|
|
25
|
+
super(`action "${integrationId}.${actionId}" failed: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
26
26
|
this.integrationId = integrationId;
|
|
27
27
|
this.actionId = actionId;
|
|
28
28
|
this.name = "ActionInvocationError";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../src/integrations/model.ts"],"sourcesContent":["// integrations context — entities & DTOs are owned by @headless-lms/core/types;\n// the domain errors below are runtime code and stay in core.\nexport type { Connection, ConnectInput, ConfigureInput } from '../types/index.js';\n\n/** An org already has a connection for this integration (one per integration per org). */\nexport class AlreadyConnectedError extends Error {\n constructor(readonly integrationId: string) {\n super(`a connection for \"${integrationId}\" already exists`);\n this.name = 'AlreadyConnectedError';\n }\n}\n\n/** The named integration is not declared in the registry. */\nexport class UnknownIntegrationError extends Error {\n constructor(readonly integrationId: string) {\n super(`unknown integration \"${integrationId}\"`);\n this.name = 'UnknownIntegrationError';\n }\n}\n\n/** An action's external call failed (or the action rejected its input). */\nexport class ActionInvocationError extends Error {\n constructor(\n readonly integrationId: string,\n readonly actionId: string,\n cause: unknown,\n ) {\n super(\n `action \"${integrationId}.${actionId}\" failed: ${\n cause instanceof Error ? cause.message : String(cause)\n }`,\n );\n this.name = 'ActionInvocationError';\n }\n}\n\n/** The config was rejected by the integration's validator. */\nexport class InvalidConfigError extends Error {\n constructor(\n readonly integrationId: string,\n readonly errors: string[],\n ) {\n super(`invalid config for \"${integrationId}\": ${errors.join('; ')}`);\n this.name = 'InvalidConfigError';\n }\n}\n"],"mappings":";;AAKA,IAAa,wBAAb,cAA2C,MAAM;CAC1B;CAArB,YAAY,eAAgC;EAC1C,MAAM,qBAAqB,cAAc,iBAAiB;EADvC,KAAA,gBAAA;EAEnB,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,0BAAb,cAA6C,MAAM;CAC5B;CAArB,YAAY,eAAgC;EAC1C,MAAM,wBAAwB,cAAc,EAAE;EAD3B,KAAA,gBAAA;EAEnB,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,wBAAb,cAA2C,MAAM;CAEpC;CACA;CAFX,YACE,eACA,UACA,OACA;EACA,MACE,WAAW,cAAc,GAAG,SAAS,YACnC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/integrations/model.ts"],"sourcesContent":["// integrations context — entities & DTOs are owned by @headless-lms/core/types;\n// the domain errors below are runtime code and stay in core.\nexport type { Connection, ConnectInput, ConfigureInput } from '../types/index.js';\n\n/** An org already has a connection for this integration (one per integration per org). */\nexport class AlreadyConnectedError extends Error {\n constructor(readonly integrationId: string) {\n super(`a connection for \"${integrationId}\" already exists`);\n this.name = 'AlreadyConnectedError';\n }\n}\n\n/** The named integration is not declared in the registry. */\nexport class UnknownIntegrationError extends Error {\n constructor(readonly integrationId: string) {\n super(`unknown integration \"${integrationId}\"`);\n this.name = 'UnknownIntegrationError';\n }\n}\n\n/** An action's external call failed (or the action rejected its input). */\nexport class ActionInvocationError extends Error {\n constructor(\n readonly integrationId: string,\n readonly actionId: string,\n cause: unknown,\n ) {\n super(\n `action \"${integrationId}.${actionId}\" failed: ${\n cause instanceof Error ? cause.message : String(cause)\n }`,\n { cause },\n );\n this.name = 'ActionInvocationError';\n }\n}\n\n/** The config was rejected by the integration's validator. */\nexport class InvalidConfigError extends Error {\n constructor(\n readonly integrationId: string,\n readonly errors: string[],\n ) {\n super(`invalid config for \"${integrationId}\": ${errors.join('; ')}`);\n this.name = 'InvalidConfigError';\n }\n}\n"],"mappings":";;AAKA,IAAa,wBAAb,cAA2C,MAAM;CAC1B;CAArB,YAAY,eAAgC;EAC1C,MAAM,qBAAqB,cAAc,iBAAiB;EADvC,KAAA,gBAAA;EAEnB,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,0BAAb,cAA6C,MAAM;CAC5B;CAArB,YAAY,eAAgC;EAC1C,MAAM,wBAAwB,cAAc,EAAE;EAD3B,KAAA,gBAAA;EAEnB,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,wBAAb,cAA2C,MAAM;CAEpC;CACA;CAFX,YACE,eACA,UACA,OACA;EACA,MACE,WAAW,cAAc,GAAG,SAAS,YACnC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KAEvD,EAAE,MAAM,CACV;EATS,KAAA,gBAAA;EACA,KAAA,WAAA;EAST,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,qBAAb,cAAwC,MAAM;CAEjC;CACA;CAFX,YACE,eACA,QACA;EACA,MAAM,uBAAuB,cAAc,KAAK,OAAO,KAAK,IAAI,GAAG;EAH1D,KAAA,gBAAA;EACA,KAAA,SAAA;EAGT,KAAK,OAAO;CACd;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { noopLogger } from "../shared/logger.js";
|
|
2
1
|
import { genId } from "../shared/id.js";
|
|
3
2
|
import { ConflictError, NotFoundError } from "../shared/errors.js";
|
|
3
|
+
import { noopLogger } from "../shared/logger.js";
|
|
4
4
|
import { ActionInvocationError, AlreadyConnectedError, InvalidConfigError, UnknownIntegrationError } from "./model.js";
|
|
5
5
|
import { integrationEvents } from "./events.js";
|
|
6
6
|
//#region src/integrations/service.ts
|
|
@@ -172,7 +172,7 @@ var IntegrationsServiceImpl = class {
|
|
|
172
172
|
connectionId,
|
|
173
173
|
integrationId: connection.integrationId,
|
|
174
174
|
actionId,
|
|
175
|
-
|
|
175
|
+
err
|
|
176
176
|
});
|
|
177
177
|
throw new ActionInvocationError(connection.integrationId, actionId, err);
|
|
178
178
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","names":[],"sources":["../../src/integrations/service.ts"],"sourcesContent":["// integrations context — service implementation (inbound port). Owns the\n// connection lifecycle; credentials live in the shared secure credential store\n// (this service holds only the ref). The integrations the system supports are\n// declared at startup via the IntegrationsRegistry: connect/configure reject\n// unknown integration ids and validate config with the integration's own\n// validator. The domain never calls the external service — consumers take the\n// connection, reveal the credential at point of use, and build their own adapter.\n//\n// Mutations run inside the context's UnitOfWork: credential writes, connection\n// writes, and the outbox append commit in ONE transaction (transactional\n// outbox; this also closed the historical orphan-credential window). The\n// outbox relay — not this service — publishes to the EventBus.\nimport { genId } from '../shared/id.js';\nimport {\n ActionInvocationError,\n AlreadyConnectedError,\n InvalidConfigError,\n UnknownIntegrationError,\n type ConfigureInput,\n type ConnectInput,\n type Connection,\n} from './model.js';\nimport type {\n ConnectionsRepository,\n IntegrationsRegistry,\n IntegrationsService,\n IntegrationsUnitOfWork,\n} from './ports.js';\nimport type { CredentialStore, Logger } from '../shared/ports.js';\nimport { ConflictError, NotFoundError } from '../shared/errors.js';\nimport { noopLogger } from '../shared/logger.js';\nimport { integrationEvents } from './events.js';\n\nexport type IntegrationsServiceParams = {\n registry: IntegrationsRegistry;\n /** Read-only access (find/list) — runs outside any transaction. */\n repo: ConnectionsRepository;\n /** Atomic write scope: tx-bound connections repo + credential store + outbox. */\n uow: IntegrationsUnitOfWork;\n /** Point-of-use credential reveal for action invocation — reads only. */\n credentials: CredentialStore;\n logger?: Logger;\n};\n\nexport class IntegrationsServiceImpl implements IntegrationsService {\n private readonly registry: IntegrationsRegistry;\n private readonly repo: ConnectionsRepository;\n private readonly uow: IntegrationsUnitOfWork;\n private readonly credentials: CredentialStore;\n private readonly logger: Logger;\n\n constructor(params: IntegrationsServiceParams) {\n this.registry = params.registry;\n this.repo = params.repo;\n this.uow = params.uow;\n this.credentials = params.credentials;\n this.logger = params.logger ?? noopLogger;\n }\n\n available() {\n return this.registry.list().map((integration) => ({\n id: integration.id,\n configSchema: integration.configSchema(),\n secretsSchema: integration.secretsSchema(),\n actions: integration.actions.map((action) => ({\n id: action.id,\n description: action.description,\n inputSchema: action.inputSchema(),\n outputSchema: action.outputSchema(),\n })),\n }));\n }\n\n private validate(integrationId: string, config: Record<string, unknown>): void {\n const integration = this.registry.get(integrationId);\n if (!integration) {\n this.logger.warn('unknown integration rejected', { integrationId });\n throw new UnknownIntegrationError(integrationId);\n }\n const result = integration.validateConfig(config);\n if (!result.ok) {\n this.logger.warn('invalid integration config rejected', {\n integrationId,\n errors: result.errors,\n });\n throw new InvalidConfigError(integrationId, result.errors);\n }\n }\n\n async connect(orgId: string, input: ConnectInput): Promise<Connection> {\n const config = input.config ?? {};\n this.validate(input.integrationId, config);\n const existing = await this.repo.findByIntegration(orgId, input.integrationId);\n if (existing) {\n this.logger.warn('duplicate connection rejected', {\n orgId,\n integrationId: input.integrationId,\n });\n throw new AlreadyConnectedError(input.integrationId);\n }\n const connection = await this.uow.run(async ({ connections, credentials, outbox }) => {\n const credentialRef = await credentials.store(orgId, input.secrets);\n const at = new Date();\n const created = await connections.insert(orgId, {\n orgId,\n id: genId('connection'),\n integrationId: input.integrationId,\n config,\n active: true,\n credentialRef,\n createdAt: at,\n updatedAt: at,\n });\n await outbox.append([\n integrationEvents.connectionCreated.make({\n orgId,\n data: created,\n }),\n ]);\n return created;\n });\n this.logger.info('integration connected', {\n orgId,\n integrationId: connection.integrationId,\n connectionId: connection.id,\n });\n return connection;\n }\n\n async reconnect(\n orgId: string,\n id: string,\n secrets: Record<string, unknown>,\n ): Promise<Connection | null> {\n const connection = await this.repo.findById(orgId, id);\n if (!connection) {\n return null;\n }\n const updated = await this.uow.run(async ({ connections, credentials, outbox }) => {\n await credentials.update(orgId, connection.credentialRef, secrets);\n const result = await connections.update(orgId, id, { updatedAt: new Date() });\n if (result) {\n await outbox.append([integrationEvents.connectionUpdated.make({ orgId, data: result })]);\n }\n return result;\n });\n this.logger.info('integration credentials rotated', {\n orgId,\n connectionId: id,\n integrationId: connection.integrationId,\n });\n return updated;\n }\n\n async configure(orgId: string, id: string, input: ConfigureInput): Promise<Connection | null> {\n const connection = await this.repo.findById(orgId, id);\n if (!connection) {\n return null;\n }\n if (input.config !== undefined) {\n this.validate(connection.integrationId, input.config);\n }\n const updated = await this.uow.run(async ({ connections, outbox }) => {\n const result = await connections.update(orgId, id, {\n ...(input.config !== undefined ? { config: input.config } : {}),\n ...(input.active !== undefined ? { active: input.active } : {}),\n updatedAt: new Date(),\n });\n if (result) {\n await outbox.append([integrationEvents.connectionUpdated.make({ orgId, data: result })]);\n }\n return result;\n });\n this.logger.info('integration configured', {\n orgId,\n connectionId: id,\n integrationId: connection.integrationId,\n });\n return updated;\n }\n\n async disconnect(orgId: string, id: string): Promise<boolean> {\n const connection = await this.repo.findById(orgId, id);\n if (!connection) {\n return false;\n }\n const deleted = await this.uow.run(async ({ connections, credentials, outbox }) => {\n // Connection first: it holds the FK onto the credential row.\n const ok = await connections.delete(orgId, id);\n await credentials.destroy(orgId, connection.credentialRef);\n await outbox.append([integrationEvents.connectionRemoved.make({ orgId, data: connection })]);\n return ok;\n });\n this.logger.info('integration disconnected', {\n orgId,\n connectionId: id,\n integrationId: connection.integrationId,\n });\n return deleted;\n }\n\n list(orgId: string): Promise<Connection[]> {\n return this.repo.list(orgId);\n }\n\n get(orgId: string, id: string): Promise<Connection | null> {\n return this.repo.findById(orgId, id);\n }\n\n getByIntegration(orgId: string, integrationId: string): Promise<Connection | null> {\n return this.repo.findByIntegration(orgId, integrationId);\n }\n\n async invoke(\n orgId: string,\n connectionId: string,\n actionId: string,\n input: Record<string, unknown>,\n ): Promise<unknown> {\n const connection = await this.repo.findById(orgId, connectionId);\n if (!connection) {\n throw new NotFoundError('Connection', connectionId);\n }\n if (!connection.active) {\n throw new ConflictError(`connection \"${connectionId}\" is inactive`);\n }\n const integration = this.registry.get(connection.integrationId);\n if (!integration) {\n throw new UnknownIntegrationError(connection.integrationId);\n }\n const action = integration.actions.find((a) => a.id === actionId);\n if (!action) {\n throw new NotFoundError('Action', actionId);\n }\n const secrets = await this.credentials.reveal(orgId, connection.credentialRef);\n if (!secrets) {\n throw new NotFoundError('Credential', connectionId);\n }\n try {\n return await action.invoke({ secrets, config: connection.config }, input);\n } catch (err) {\n this.logger.warn('integration action failed', {\n orgId,\n connectionId,\n integrationId: connection.integrationId,\n actionId,\n error: err instanceof Error ? err.message : String(err),\n });\n throw new ActionInvocationError(connection.integrationId, actionId, err);\n }\n }\n}\n"],"mappings":";;;;;;AA4CA,IAAa,0BAAb,MAAoE;CAClE;CACA;CACA;CACA;CACA;CAEA,YAAY,QAAmC;EAC7C,KAAK,WAAW,OAAO;EACvB,KAAK,OAAO,OAAO;EACnB,KAAK,MAAM,OAAO;EAClB,KAAK,cAAc,OAAO;EAC1B,KAAK,SAAS,OAAO,UAAU;CACjC;CAEA,YAAY;EACV,OAAO,KAAK,SAAS,KAAK,CAAC,CAAC,KAAK,iBAAiB;GAChD,IAAI,YAAY;GAChB,cAAc,YAAY,aAAa;GACvC,eAAe,YAAY,cAAc;GACzC,SAAS,YAAY,QAAQ,KAAK,YAAY;IAC5C,IAAI,OAAO;IACX,aAAa,OAAO;IACpB,aAAa,OAAO,YAAY;IAChC,cAAc,OAAO,aAAa;GACpC,EAAE;EACJ,EAAE;CACJ;CAEA,SAAiB,eAAuB,QAAuC;EAC7E,MAAM,cAAc,KAAK,SAAS,IAAI,aAAa;EACnD,IAAI,CAAC,aAAa;GAChB,KAAK,OAAO,KAAK,gCAAgC,EAAE,cAAc,CAAC;GAClE,MAAM,IAAI,wBAAwB,aAAa;EACjD;EACA,MAAM,SAAS,YAAY,eAAe,MAAM;EAChD,IAAI,CAAC,OAAO,IAAI;GACd,KAAK,OAAO,KAAK,uCAAuC;IACtD;IACA,QAAQ,OAAO;GACjB,CAAC;GACD,MAAM,IAAI,mBAAmB,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../../src/integrations/service.ts"],"sourcesContent":["// integrations context — service implementation (inbound port). Owns the\n// connection lifecycle; credentials live in the shared secure credential store\n// (this service holds only the ref). The integrations the system supports are\n// declared at startup via the IntegrationsRegistry: connect/configure reject\n// unknown integration ids and validate config with the integration's own\n// validator. The domain never calls the external service — consumers take the\n// connection, reveal the credential at point of use, and build their own adapter.\n//\n// Mutations run inside the context's UnitOfWork: credential writes, connection\n// writes, and the outbox append commit in ONE transaction (transactional\n// outbox; this also closed the historical orphan-credential window). The\n// outbox relay — not this service — publishes to the EventBus.\nimport { genId } from '../shared/id.js';\nimport {\n ActionInvocationError,\n AlreadyConnectedError,\n InvalidConfigError,\n UnknownIntegrationError,\n type ConfigureInput,\n type ConnectInput,\n type Connection,\n} from './model.js';\nimport type {\n ConnectionsRepository,\n IntegrationsRegistry,\n IntegrationsService,\n IntegrationsUnitOfWork,\n} from './ports.js';\nimport type { CredentialStore, Logger } from '../shared/ports.js';\nimport { ConflictError, NotFoundError } from '../shared/errors.js';\nimport { noopLogger } from '../shared/logger.js';\nimport { integrationEvents } from './events.js';\n\nexport type IntegrationsServiceParams = {\n registry: IntegrationsRegistry;\n /** Read-only access (find/list) — runs outside any transaction. */\n repo: ConnectionsRepository;\n /** Atomic write scope: tx-bound connections repo + credential store + outbox. */\n uow: IntegrationsUnitOfWork;\n /** Point-of-use credential reveal for action invocation — reads only. */\n credentials: CredentialStore;\n logger?: Logger;\n};\n\nexport class IntegrationsServiceImpl implements IntegrationsService {\n private readonly registry: IntegrationsRegistry;\n private readonly repo: ConnectionsRepository;\n private readonly uow: IntegrationsUnitOfWork;\n private readonly credentials: CredentialStore;\n private readonly logger: Logger;\n\n constructor(params: IntegrationsServiceParams) {\n this.registry = params.registry;\n this.repo = params.repo;\n this.uow = params.uow;\n this.credentials = params.credentials;\n this.logger = params.logger ?? noopLogger;\n }\n\n available() {\n return this.registry.list().map((integration) => ({\n id: integration.id,\n configSchema: integration.configSchema(),\n secretsSchema: integration.secretsSchema(),\n actions: integration.actions.map((action) => ({\n id: action.id,\n description: action.description,\n inputSchema: action.inputSchema(),\n outputSchema: action.outputSchema(),\n })),\n }));\n }\n\n private validate(integrationId: string, config: Record<string, unknown>): void {\n const integration = this.registry.get(integrationId);\n if (!integration) {\n this.logger.warn('unknown integration rejected', { integrationId });\n throw new UnknownIntegrationError(integrationId);\n }\n const result = integration.validateConfig(config);\n if (!result.ok) {\n this.logger.warn('invalid integration config rejected', {\n integrationId,\n errors: result.errors,\n });\n throw new InvalidConfigError(integrationId, result.errors);\n }\n }\n\n async connect(orgId: string, input: ConnectInput): Promise<Connection> {\n const config = input.config ?? {};\n this.validate(input.integrationId, config);\n const existing = await this.repo.findByIntegration(orgId, input.integrationId);\n if (existing) {\n this.logger.warn('duplicate connection rejected', {\n orgId,\n integrationId: input.integrationId,\n });\n throw new AlreadyConnectedError(input.integrationId);\n }\n const connection = await this.uow.run(async ({ connections, credentials, outbox }) => {\n const credentialRef = await credentials.store(orgId, input.secrets);\n const at = new Date();\n const created = await connections.insert(orgId, {\n orgId,\n id: genId('connection'),\n integrationId: input.integrationId,\n config,\n active: true,\n credentialRef,\n createdAt: at,\n updatedAt: at,\n });\n await outbox.append([\n integrationEvents.connectionCreated.make({\n orgId,\n data: created,\n }),\n ]);\n return created;\n });\n this.logger.info('integration connected', {\n orgId,\n integrationId: connection.integrationId,\n connectionId: connection.id,\n });\n return connection;\n }\n\n async reconnect(\n orgId: string,\n id: string,\n secrets: Record<string, unknown>,\n ): Promise<Connection | null> {\n const connection = await this.repo.findById(orgId, id);\n if (!connection) {\n return null;\n }\n const updated = await this.uow.run(async ({ connections, credentials, outbox }) => {\n await credentials.update(orgId, connection.credentialRef, secrets);\n const result = await connections.update(orgId, id, { updatedAt: new Date() });\n if (result) {\n await outbox.append([integrationEvents.connectionUpdated.make({ orgId, data: result })]);\n }\n return result;\n });\n this.logger.info('integration credentials rotated', {\n orgId,\n connectionId: id,\n integrationId: connection.integrationId,\n });\n return updated;\n }\n\n async configure(orgId: string, id: string, input: ConfigureInput): Promise<Connection | null> {\n const connection = await this.repo.findById(orgId, id);\n if (!connection) {\n return null;\n }\n if (input.config !== undefined) {\n this.validate(connection.integrationId, input.config);\n }\n const updated = await this.uow.run(async ({ connections, outbox }) => {\n const result = await connections.update(orgId, id, {\n ...(input.config !== undefined ? { config: input.config } : {}),\n ...(input.active !== undefined ? { active: input.active } : {}),\n updatedAt: new Date(),\n });\n if (result) {\n await outbox.append([integrationEvents.connectionUpdated.make({ orgId, data: result })]);\n }\n return result;\n });\n this.logger.info('integration configured', {\n orgId,\n connectionId: id,\n integrationId: connection.integrationId,\n });\n return updated;\n }\n\n async disconnect(orgId: string, id: string): Promise<boolean> {\n const connection = await this.repo.findById(orgId, id);\n if (!connection) {\n return false;\n }\n const deleted = await this.uow.run(async ({ connections, credentials, outbox }) => {\n // Connection first: it holds the FK onto the credential row.\n const ok = await connections.delete(orgId, id);\n await credentials.destroy(orgId, connection.credentialRef);\n await outbox.append([integrationEvents.connectionRemoved.make({ orgId, data: connection })]);\n return ok;\n });\n this.logger.info('integration disconnected', {\n orgId,\n connectionId: id,\n integrationId: connection.integrationId,\n });\n return deleted;\n }\n\n list(orgId: string): Promise<Connection[]> {\n return this.repo.list(orgId);\n }\n\n get(orgId: string, id: string): Promise<Connection | null> {\n return this.repo.findById(orgId, id);\n }\n\n getByIntegration(orgId: string, integrationId: string): Promise<Connection | null> {\n return this.repo.findByIntegration(orgId, integrationId);\n }\n\n async invoke(\n orgId: string,\n connectionId: string,\n actionId: string,\n input: Record<string, unknown>,\n ): Promise<unknown> {\n const connection = await this.repo.findById(orgId, connectionId);\n if (!connection) {\n throw new NotFoundError('Connection', connectionId);\n }\n if (!connection.active) {\n throw new ConflictError(`connection \"${connectionId}\" is inactive`);\n }\n const integration = this.registry.get(connection.integrationId);\n if (!integration) {\n throw new UnknownIntegrationError(connection.integrationId);\n }\n const action = integration.actions.find((a) => a.id === actionId);\n if (!action) {\n throw new NotFoundError('Action', actionId);\n }\n const secrets = await this.credentials.reveal(orgId, connection.credentialRef);\n if (!secrets) {\n throw new NotFoundError('Credential', connectionId);\n }\n try {\n return await action.invoke({ secrets, config: connection.config }, input);\n } catch (err) {\n this.logger.warn('integration action failed', {\n orgId,\n connectionId,\n integrationId: connection.integrationId,\n actionId,\n err,\n });\n throw new ActionInvocationError(connection.integrationId, actionId, err);\n }\n }\n}\n"],"mappings":";;;;;;AA4CA,IAAa,0BAAb,MAAoE;CAClE;CACA;CACA;CACA;CACA;CAEA,YAAY,QAAmC;EAC7C,KAAK,WAAW,OAAO;EACvB,KAAK,OAAO,OAAO;EACnB,KAAK,MAAM,OAAO;EAClB,KAAK,cAAc,OAAO;EAC1B,KAAK,SAAS,OAAO,UAAU;CACjC;CAEA,YAAY;EACV,OAAO,KAAK,SAAS,KAAK,CAAC,CAAC,KAAK,iBAAiB;GAChD,IAAI,YAAY;GAChB,cAAc,YAAY,aAAa;GACvC,eAAe,YAAY,cAAc;GACzC,SAAS,YAAY,QAAQ,KAAK,YAAY;IAC5C,IAAI,OAAO;IACX,aAAa,OAAO;IACpB,aAAa,OAAO,YAAY;IAChC,cAAc,OAAO,aAAa;GACpC,EAAE;EACJ,EAAE;CACJ;CAEA,SAAiB,eAAuB,QAAuC;EAC7E,MAAM,cAAc,KAAK,SAAS,IAAI,aAAa;EACnD,IAAI,CAAC,aAAa;GAChB,KAAK,OAAO,KAAK,gCAAgC,EAAE,cAAc,CAAC;GAClE,MAAM,IAAI,wBAAwB,aAAa;EACjD;EACA,MAAM,SAAS,YAAY,eAAe,MAAM;EAChD,IAAI,CAAC,OAAO,IAAI;GACd,KAAK,OAAO,KAAK,uCAAuC;IACtD;IACA,QAAQ,OAAO;GACjB,CAAC;GACD,MAAM,IAAI,mBAAmB,eAAe,OAAO,MAAM;EAC3D;CACF;CAEA,MAAM,QAAQ,OAAe,OAA0C;EACrE,MAAM,SAAS,MAAM,UAAU,CAAC;EAChC,KAAK,SAAS,MAAM,eAAe,MAAM;EAEzC,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C;EACzC,OAAO,KAAK,KAAK,KAAK,KAAK;CAC7B;CAEA,IAAI,OAAe,IAAwC;EACzD,OAAO,KAAK,KAAK,SAAS,OAAO,EAAE;CACrC;CAEA,iBAAiB,OAAe,eAAmD;EACjF,OAAO,KAAK,KAAK,kBAAkB,OAAO,aAAa;CACzD;CAEA,MAAM,OACJ,OACA,cACA,UACA,OACkB;EAClB,MAAM,aAAa,MAAM,KAAK,KAAK,SAAS,OAAO,YAAY;EAC/D,IAAI,CAAC,YACH,MAAM,IAAI,cAAc,cAAc,YAAY;EAEpD,IAAI,CAAC,WAAW,QACd,MAAM,IAAI,cAAc,eAAe,aAAa,cAAc;EAEpE,MAAM,cAAc,KAAK,SAAS,IAAI,WAAW,aAAa;EAC9D,IAAI,CAAC,aACH,MAAM,IAAI,wBAAwB,WAAW,aAAa;EAE5D,MAAM,SAAS,YAAY,QAAQ,MAAM,MAAM,EAAE,OAAO,QAAQ;EAChE,IAAI,CAAC,QACH,MAAM,IAAI,cAAc,UAAU,QAAQ;EAE5C,MAAM,UAAU,MAAM,KAAK,YAAY,OAAO,OAAO,WAAW,aAAa;EAC7E,IAAI,CAAC,SACH,MAAM,IAAI,cAAc,cAAc,YAAY;EAEpD,IAAI;GACF,OAAO,MAAM,OAAO,OAAO;IAAE;IAAS,QAAQ,WAAW;GAAO,GAAG,KAAK;EAC1E,SAAS,KAAK;GACZ,KAAK,OAAO,KAAK,6BAA6B;IAC5C;IACA;IACA,eAAe,WAAW;IAC1B;IACA;GACF,CAAC;GACD,MAAM,IAAI,sBAAsB,WAAW,eAAe,UAAU,GAAG;EACzE;CACF;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Role } from "../types/schemas/organizations.js";
|
|
2
|
+
import { Permission } from "./roles.js";
|
|
3
|
+
//#region src/organizations/access-scopes.d.ts
|
|
4
|
+
declare const ACCESS_SCOPES: readonly ["courses:read", "courses:write", "courses:delete", "downloads:read", "downloads:write", "downloads:delete", "bundles:read", "bundles:write", "bundles:delete", "media:read", "students:read", "students:invite", "access:read", "access:write", "analytics:read", "automations:read", "automations:write", "automations:delete", "comments:read", "comments:moderate", "communities:read", "communities:write", "communities:delete", "community_members:read", "community_members:write", "community_moderation:read", "community_moderation:write"];
|
|
5
|
+
type AccessScope = (typeof ACCESS_SCOPES)[number];
|
|
6
|
+
declare const SCOPE_PERMISSION: Record<AccessScope, Permission | null>;
|
|
7
|
+
type ScopeOption = {
|
|
8
|
+
scope: AccessScope;
|
|
9
|
+
allowed: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare function isAccessScope(value: string): value is AccessScope;
|
|
12
|
+
declare function isDeleteScope(scope: AccessScope): boolean;
|
|
13
|
+
declare function roleHoldsScope(role: Role, scope: AccessScope): boolean;
|
|
14
|
+
declare function scopesForRole(role: Role): AccessScope[];
|
|
15
|
+
declare function scopeOptions(role: Role): ScopeOption[];
|
|
16
|
+
declare function assertRoleHoldsScopes(role: Role, scopes: readonly AccessScope[]): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ACCESS_SCOPES, AccessScope, SCOPE_PERMISSION, ScopeOption, assertRoleHoldsScopes, isAccessScope, isDeleteScope, roleHoldsScope, scopeOptions, scopesForRole };
|
|
19
|
+
//# sourceMappingURL=access-scopes.d.ts.map
|