@jskit-ai/users-core 0.1.172 → 0.1.174
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/package.json +41 -253
- package/patterns/user-administration-server/PATTERN.md +64 -0
- package/patterns/user-administration-server/example/packages/users/package.json +42 -0
- package/patterns/user-administration-server/example/packages/users/src/server/UsersFeature.js +13 -0
- package/patterns/user-administration-server/example/packages/users/src/shared/index.js +1 -0
- package/patterns/user-administration-server/example/packages/users-workspace/package.json +43 -0
- package/patterns/user-administration-server/example/packages/users-workspace/src/server/UsersWorkspaceFeature.js +22 -0
- package/patterns/user-administration-server/example/packages/users-workspace/src/shared/userResource.js +56 -0
- package/src/server/UsersExtensionsProvider.js +14 -0
- package/src/server/UsersFeature.js +119 -0
- package/src/server/UsersIdentityProvider.js +57 -0
- package/src/server/accountNotifications/accountNotificationsActions.js +17 -5
- package/src/server/accountNotifications/bootAccountNotificationsRoutes.js +4 -6
- package/src/server/accountPreferences/accountPreferencesActions.js +17 -5
- package/src/server/accountPreferences/bootAccountPreferencesRoutes.js +4 -6
- package/src/server/accountProfile/accountProfileActions.js +28 -14
- package/src/server/accountProfile/bootAccountProfileRoutes.js +11 -10
- package/src/server/accountSecurity/accountSecurityActions.js +27 -17
- package/src/server/accountSecurity/bootAccountSecurityRoutes.js +4 -7
- package/src/server/common/services/authProfileSyncService.js +11 -4
- package/src/server/common/support/realtimeServiceEvents.js +8 -11
- package/src/server/usersBootstrapContributor.js +4 -28
- package/src/server/usersExtensions.js +65 -0
- package/test/authProfileSyncService.test.js +2 -2
- package/test/exportsContract.test.js +6 -1
- package/test/featureRuntime.test.js +78 -0
- package/test/usersBootstrapContributor.test.js +1 -43
- package/test/usersPackageScaffoldContract.test.js +58 -204
- package/test/usersRouteRequestInputValidator.test.js +19 -43
- package/src/server/UsersCoreServiceProvider.js +0 -56
- package/src/server/accountNotifications/registerAccountNotifications.js +0 -37
- package/src/server/accountPreferences/registerAccountPreferences.js +0 -37
- package/src/server/accountProfile/registerAccountProfile.js +0 -56
- package/src/server/accountSecurity/registerAccountSecurity.js +0 -29
- package/src/server/common/registerCommonRepositories.js +0 -23
- package/src/server/common/registerSharedApi.js +0 -9
- package/src/server/profileSyncLifecycleContributorRegistry.js +0 -56
- package/src/server/registerUsersBootstrap.js +0 -20
- package/src/server/registerUsersCore.js +0 -22
- package/templates/packages/users/package.json +0 -82
- package/templates/packages/users/src/server/UsersProvider.js +0 -90
- package/templates/packages/users/src/server/actions.js +0 -68
- package/templates/packages/users/src/server/registerRoutes.js +0 -101
- package/templates/packages/users/src/server/repository.js +0 -51
- package/templates/packages/users/src/server/service.js +0 -32
- package/templates/packages/users-workspace/package.json +0 -83
- package/templates/packages/users-workspace/src/server/UsersProvider.js +0 -91
- package/templates/packages/users-workspace/src/server/actions.js +0 -77
- package/templates/packages/users-workspace/src/server/registerRoutes.js +0 -111
- package/test/providerLifecycle.test.js +0 -63
- package/test/registerCommonRepositories.test.js +0 -57
- package/test/registerServiceRealtimeEvents.test.js +0 -57
- package/test/registerUsersCore.test.js +0 -53
- /package/{templates/migrations → migrations}/users_core_generic_initial.cjs +0 -0
- /package/{templates/migrations → migrations}/users_core_profile_updated_at.cjs +0 -0
- /package/{templates/migrations → migrations}/users_core_profile_username.cjs +0 -0
- /package/{templates → patterns/user-administration-server/example}/packages/users/src/shared/userResource.js +0 -0
- /package/{templates/packages/users → patterns/user-administration-server/example/packages/users-workspace}/src/shared/index.js +0 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { defineFeature } from "@jskit-ai/kernel/server/features";
|
|
2
|
+
import { USERS_SHARED_API } from "../shared/index.js";
|
|
3
|
+
import { buildAccountNotificationsActions } from "./accountNotifications/accountNotificationsActions.js";
|
|
4
|
+
import { createService as createAccountNotificationsService } from "./accountNotifications/accountNotificationsService.js";
|
|
5
|
+
import { registerAccountNotificationsRoutes } from "./accountNotifications/bootAccountNotificationsRoutes.js";
|
|
6
|
+
import { buildAccountPreferencesActions } from "./accountPreferences/accountPreferencesActions.js";
|
|
7
|
+
import { createService as createAccountPreferencesService } from "./accountPreferences/accountPreferencesService.js";
|
|
8
|
+
import { registerAccountPreferencesRoutes } from "./accountPreferences/bootAccountPreferencesRoutes.js";
|
|
9
|
+
import { buildAccountProfileActions } from "./accountProfile/accountProfileActions.js";
|
|
10
|
+
import { createService as createAccountProfileService } from "./accountProfile/accountProfileService.js";
|
|
11
|
+
import { createService as createAvatarService } from "./accountProfile/avatarService.js";
|
|
12
|
+
import { createService as createAvatarStorageService } from "./accountProfile/avatarStorageService.js";
|
|
13
|
+
import { registerAccountProfileRoutes } from "./accountProfile/bootAccountProfileRoutes.js";
|
|
14
|
+
import { buildAccountSecurityActions } from "./accountSecurity/accountSecurityActions.js";
|
|
15
|
+
import { createService as createAccountSecurityService } from "./accountSecurity/accountSecurityService.js";
|
|
16
|
+
import { registerAccountSecurityRoutes } from "./accountSecurity/bootAccountSecurityRoutes.js";
|
|
17
|
+
import { createUsersBootstrapContributor } from "./usersBootstrapContributor.js";
|
|
18
|
+
|
|
19
|
+
function createUsersRuntime({
|
|
20
|
+
authService,
|
|
21
|
+
identity,
|
|
22
|
+
storage
|
|
23
|
+
} = {}) {
|
|
24
|
+
const userProfilesRepository = identity.repositories.userProfiles;
|
|
25
|
+
const userSettingsRepository = identity.repositories.userSettings;
|
|
26
|
+
const avatarStorageService = createAvatarStorageService({ storage });
|
|
27
|
+
const avatarService = createAvatarService({ userProfilesRepository, avatarStorageService });
|
|
28
|
+
const accountProfileService = createAccountProfileService({
|
|
29
|
+
authService,
|
|
30
|
+
avatarService,
|
|
31
|
+
userProfilesRepository,
|
|
32
|
+
userSettingsRepository
|
|
33
|
+
});
|
|
34
|
+
const accountPreferencesService = createAccountPreferencesService({
|
|
35
|
+
authService,
|
|
36
|
+
userProfilesRepository,
|
|
37
|
+
userSettingsRepository
|
|
38
|
+
});
|
|
39
|
+
const accountNotificationsService = createAccountNotificationsService({
|
|
40
|
+
authService,
|
|
41
|
+
userProfilesRepository,
|
|
42
|
+
userSettingsRepository
|
|
43
|
+
});
|
|
44
|
+
const accountSecurityService = createAccountSecurityService({
|
|
45
|
+
authService,
|
|
46
|
+
userProfilesRepository,
|
|
47
|
+
userSettingsRepository
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return Object.freeze({
|
|
51
|
+
repositories: Object.freeze({
|
|
52
|
+
userProfiles: userProfilesRepository,
|
|
53
|
+
userSettings: userSettingsRepository
|
|
54
|
+
}),
|
|
55
|
+
services: Object.freeze({
|
|
56
|
+
accountNotifications: accountNotificationsService,
|
|
57
|
+
accountPreferences: accountPreferencesService,
|
|
58
|
+
accountProfile: accountProfileService,
|
|
59
|
+
accountSecurity: accountSecurityService,
|
|
60
|
+
avatar: avatarService,
|
|
61
|
+
profileProjector: identity.profileProjector
|
|
62
|
+
}),
|
|
63
|
+
shared: USERS_SHARED_API
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const UsersFeature = defineFeature({
|
|
68
|
+
id: "users.core",
|
|
69
|
+
domain: "settings",
|
|
70
|
+
requires: {
|
|
71
|
+
authService: "auth.service",
|
|
72
|
+
bootstrap: "runtime.bootstrap",
|
|
73
|
+
http: "runtime.http",
|
|
74
|
+
identity: "users.identity",
|
|
75
|
+
storage: "runtime.storage",
|
|
76
|
+
uploads: "runtime.uploads"
|
|
77
|
+
},
|
|
78
|
+
provides: {
|
|
79
|
+
users: "users.core"
|
|
80
|
+
},
|
|
81
|
+
async setup({
|
|
82
|
+
authService,
|
|
83
|
+
bootstrap,
|
|
84
|
+
http,
|
|
85
|
+
identity,
|
|
86
|
+
storage,
|
|
87
|
+
uploads
|
|
88
|
+
}) {
|
|
89
|
+
const users = createUsersRuntime({ authService, identity, storage });
|
|
90
|
+
registerAccountProfileRoutes(http.router, {
|
|
91
|
+
accountProfileService: users.services.accountProfile,
|
|
92
|
+
authService,
|
|
93
|
+
uploads
|
|
94
|
+
});
|
|
95
|
+
registerAccountPreferencesRoutes(http.router);
|
|
96
|
+
registerAccountNotificationsRoutes(http.router);
|
|
97
|
+
registerAccountSecurityRoutes(http.router, { authService });
|
|
98
|
+
bootstrap.register({
|
|
99
|
+
id: "users.bootstrap",
|
|
100
|
+
order: 100,
|
|
101
|
+
contribute: createUsersBootstrapContributor({
|
|
102
|
+
authService,
|
|
103
|
+
userProfilesRepository: users.repositories.userProfiles,
|
|
104
|
+
userSettingsRepository: users.repositories.userSettings
|
|
105
|
+
}).contribute
|
|
106
|
+
});
|
|
107
|
+
return { users };
|
|
108
|
+
},
|
|
109
|
+
actions({ users }) {
|
|
110
|
+
return [
|
|
111
|
+
...buildAccountProfileActions({ accountProfileService: users.services.accountProfile }),
|
|
112
|
+
...buildAccountPreferencesActions({ accountPreferencesService: users.services.accountPreferences }),
|
|
113
|
+
...buildAccountNotificationsActions({ accountNotificationsService: users.services.accountNotifications }),
|
|
114
|
+
...buildAccountSecurityActions({ accountSecurityService: users.services.accountSecurity })
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
export { UsersFeature, createUsersRuntime };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { toDatabaseDateTimeUtc } from "@jskit-ai/database-runtime/shared";
|
|
2
|
+
import {
|
|
3
|
+
addResourceIfMissing,
|
|
4
|
+
createJsonRestResourceScopeOptions
|
|
5
|
+
} from "@jskit-ai/json-rest-api-core/server/jsonRestApiHost";
|
|
6
|
+
import { defineProvider } from "@jskit-ai/kernel/shared/capabilities";
|
|
7
|
+
import { userProfileResource } from "../shared/resources/userProfileResource.js";
|
|
8
|
+
import { userSettingsResource } from "../shared/resources/userSettingsResource.js";
|
|
9
|
+
import { createRepository as createUserProfilesRepository } from "./common/repositories/userProfilesRepository.js";
|
|
10
|
+
import { createRepository as createUserSettingsRepository } from "./common/repositories/userSettingsRepository.js";
|
|
11
|
+
import { createService as createAuthProfileSyncService } from "./common/services/authProfileSyncService.js";
|
|
12
|
+
|
|
13
|
+
const UsersIdentityProvider = defineProvider({
|
|
14
|
+
id: "users.identity",
|
|
15
|
+
requires: {
|
|
16
|
+
authExtensions: "auth.extensions",
|
|
17
|
+
database: "runtime.database",
|
|
18
|
+
extensions: "users.extensions",
|
|
19
|
+
jsonRestApi: "runtime.json-rest-api"
|
|
20
|
+
},
|
|
21
|
+
provides: {
|
|
22
|
+
identity: "users.identity"
|
|
23
|
+
},
|
|
24
|
+
async setup({ authExtensions, database, extensions, jsonRestApi }) {
|
|
25
|
+
const scopeOptions = {
|
|
26
|
+
writeSerializers: { "datetime-utc": toDatabaseDateTimeUtc }
|
|
27
|
+
};
|
|
28
|
+
await addResourceIfMissing(
|
|
29
|
+
jsonRestApi,
|
|
30
|
+
"userProfiles",
|
|
31
|
+
createJsonRestResourceScopeOptions(userProfileResource, scopeOptions)
|
|
32
|
+
);
|
|
33
|
+
await addResourceIfMissing(
|
|
34
|
+
jsonRestApi,
|
|
35
|
+
"userSettings",
|
|
36
|
+
createJsonRestResourceScopeOptions(userSettingsResource, scopeOptions)
|
|
37
|
+
);
|
|
38
|
+
const repositories = Object.freeze({
|
|
39
|
+
userProfiles: createUserProfilesRepository({ api: jsonRestApi, knex: database.knex }),
|
|
40
|
+
userSettings: createUserSettingsRepository({ api: jsonRestApi, knex: database.knex })
|
|
41
|
+
});
|
|
42
|
+
const profileProjector = createAuthProfileSyncService({
|
|
43
|
+
userProfilesRepository: repositories.userProfiles,
|
|
44
|
+
userSettingsRepository: repositories.userSettings,
|
|
45
|
+
resolveLifecycleContributors: extensions.profileSyncLifecycleContributors
|
|
46
|
+
});
|
|
47
|
+
authExtensions.registerProfileProjector({
|
|
48
|
+
projectorId: "users.profile",
|
|
49
|
+
...profileProjector
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
identity: Object.freeze({ repositories, profileProjector })
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export { UsersIdentityProvider };
|
|
@@ -3,14 +3,15 @@ import {
|
|
|
3
3
|
} from "@jskit-ai/kernel/shared/actions/actionContributorHelpers";
|
|
4
4
|
import { userSettingsResource } from "../../shared/resources/userSettingsResource.js";
|
|
5
5
|
import { resolveActionUser } from "../common/support/resolveActionUser.js";
|
|
6
|
+
import { ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS } from "../common/support/realtimeServiceEvents.js";
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const accountNotificationsActionSpecifications = Object.freeze([
|
|
8
9
|
{
|
|
9
10
|
id: "settings.notifications.update",
|
|
10
11
|
version: 1,
|
|
11
12
|
kind: "command",
|
|
12
13
|
channels: ["api", "automation", "internal"],
|
|
13
|
-
|
|
14
|
+
surfaces: ["*"],
|
|
14
15
|
permission: {
|
|
15
16
|
require: "authenticated"
|
|
16
17
|
},
|
|
@@ -21,8 +22,9 @@ const accountNotificationsActions = Object.freeze([
|
|
|
21
22
|
actionName: "settings.notifications.update"
|
|
22
23
|
},
|
|
23
24
|
observability: {},
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
events: ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS,
|
|
26
|
+
async run(accountNotificationsService, input, context) {
|
|
27
|
+
return accountNotificationsService.updateNotifications(
|
|
26
28
|
resolveRequest(context),
|
|
27
29
|
resolveActionUser(context, input),
|
|
28
30
|
input,
|
|
@@ -34,4 +36,14 @@ const accountNotificationsActions = Object.freeze([
|
|
|
34
36
|
}
|
|
35
37
|
]);
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
function buildAccountNotificationsActions({ accountNotificationsService } = {}) {
|
|
40
|
+
if (!accountNotificationsService) throw new TypeError("buildAccountNotificationsActions requires accountNotificationsService.");
|
|
41
|
+
return accountNotificationsActionSpecifications.map(({ run, ...definition }) => Object.freeze({
|
|
42
|
+
...definition,
|
|
43
|
+
execute(input, context) {
|
|
44
|
+
return run(accountNotificationsService, input, context);
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { accountNotificationsActionSpecifications, buildAccountNotificationsActions };
|
|
@@ -2,13 +2,11 @@ import { createJsonApiResourceRouteContract } from "@jskit-ai/http-runtime/share
|
|
|
2
2
|
import { userSettingsResource } from "../../shared/resources/userSettingsResource.js";
|
|
3
3
|
import { resolveAccountSettingsResourceId } from "../common/support/accountSettingsJsonApiTransport.js";
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
if (!
|
|
7
|
-
throw new
|
|
5
|
+
function registerAccountNotificationsRoutes(router) {
|
|
6
|
+
if (!router || typeof router.register !== "function") {
|
|
7
|
+
throw new TypeError("registerAccountNotificationsRoutes requires router.register().");
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const router = app.make("jskit.http.router");
|
|
11
|
-
|
|
12
10
|
router.register(
|
|
13
11
|
"PATCH",
|
|
14
12
|
"/api/settings/notifications",
|
|
@@ -38,4 +36,4 @@ function bootAccountNotificationsRoutes(app) {
|
|
|
38
36
|
);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
export {
|
|
39
|
+
export { registerAccountNotificationsRoutes };
|
|
@@ -3,14 +3,15 @@ import {
|
|
|
3
3
|
} from "@jskit-ai/kernel/shared/actions/actionContributorHelpers";
|
|
4
4
|
import { userSettingsResource } from "../../shared/resources/userSettingsResource.js";
|
|
5
5
|
import { resolveActionUser } from "../common/support/resolveActionUser.js";
|
|
6
|
+
import { ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS } from "../common/support/realtimeServiceEvents.js";
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const accountPreferencesActionSpecifications = Object.freeze([
|
|
8
9
|
{
|
|
9
10
|
id: "settings.preferences.update",
|
|
10
11
|
version: 1,
|
|
11
12
|
kind: "command",
|
|
12
13
|
channels: ["api", "automation", "internal"],
|
|
13
|
-
|
|
14
|
+
surfaces: ["*"],
|
|
14
15
|
permission: {
|
|
15
16
|
require: "authenticated"
|
|
16
17
|
},
|
|
@@ -21,8 +22,9 @@ const accountPreferencesActions = Object.freeze([
|
|
|
21
22
|
actionName: "settings.preferences.update"
|
|
22
23
|
},
|
|
23
24
|
observability: {},
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
events: ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS,
|
|
26
|
+
async run(accountPreferencesService, input, context) {
|
|
27
|
+
return accountPreferencesService.updatePreferences(
|
|
26
28
|
resolveRequest(context),
|
|
27
29
|
resolveActionUser(context, input),
|
|
28
30
|
input,
|
|
@@ -34,4 +36,14 @@ const accountPreferencesActions = Object.freeze([
|
|
|
34
36
|
}
|
|
35
37
|
]);
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
function buildAccountPreferencesActions({ accountPreferencesService } = {}) {
|
|
40
|
+
if (!accountPreferencesService) throw new TypeError("buildAccountPreferencesActions requires accountPreferencesService.");
|
|
41
|
+
return accountPreferencesActionSpecifications.map(({ run, ...definition }) => Object.freeze({
|
|
42
|
+
...definition,
|
|
43
|
+
execute(input, context) {
|
|
44
|
+
return run(accountPreferencesService, input, context);
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { accountPreferencesActionSpecifications, buildAccountPreferencesActions };
|
|
@@ -2,13 +2,11 @@ import { createJsonApiResourceRouteContract } from "@jskit-ai/http-runtime/share
|
|
|
2
2
|
import { userSettingsResource } from "../../shared/resources/userSettingsResource.js";
|
|
3
3
|
import { resolveAccountSettingsResourceId } from "../common/support/accountSettingsJsonApiTransport.js";
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
if (!
|
|
7
|
-
throw new
|
|
5
|
+
function registerAccountPreferencesRoutes(router) {
|
|
6
|
+
if (!router || typeof router.register !== "function") {
|
|
7
|
+
throw new TypeError("registerAccountPreferencesRoutes requires router.register().");
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const router = app.make("jskit.http.router");
|
|
11
|
-
|
|
12
10
|
router.register(
|
|
13
11
|
"PATCH",
|
|
14
12
|
"/api/settings/preferences",
|
|
@@ -38,4 +36,4 @@ function bootAccountPreferencesRoutes(app) {
|
|
|
38
36
|
);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
export {
|
|
39
|
+
export { registerAccountPreferencesRoutes };
|
|
@@ -5,19 +5,20 @@ import {
|
|
|
5
5
|
import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
|
|
6
6
|
import { userProfileResource } from "../../shared/resources/userProfileResource.js";
|
|
7
7
|
import { resolveActionUser } from "../common/support/resolveActionUser.js";
|
|
8
|
+
import { ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS } from "../common/support/realtimeServiceEvents.js";
|
|
8
9
|
|
|
9
10
|
const settingsProfileUpdateInputValidator = deepFreeze({
|
|
10
11
|
schema: userProfileResource.operations.patch.body.schema,
|
|
11
12
|
mode: userProfileResource.operations.patch.body.mode
|
|
12
13
|
});
|
|
13
14
|
|
|
14
|
-
const
|
|
15
|
+
const accountProfileActionSpecifications = deepFreeze([
|
|
15
16
|
{
|
|
16
17
|
id: "settings.read",
|
|
17
18
|
version: 1,
|
|
18
19
|
kind: "query",
|
|
19
20
|
channels: ["api", "automation", "internal"],
|
|
20
|
-
|
|
21
|
+
surfaces: ["*"],
|
|
21
22
|
permission: {
|
|
22
23
|
require: "authenticated"
|
|
23
24
|
},
|
|
@@ -28,8 +29,8 @@ const accountProfileActions = deepFreeze([
|
|
|
28
29
|
actionName: "settings.read"
|
|
29
30
|
},
|
|
30
31
|
observability: {},
|
|
31
|
-
async
|
|
32
|
-
return
|
|
32
|
+
async run(accountProfileService, input, context) {
|
|
33
|
+
return accountProfileService.getForUser(resolveRequest(context), resolveActionUser(context, input), {
|
|
33
34
|
context
|
|
34
35
|
});
|
|
35
36
|
}
|
|
@@ -39,7 +40,7 @@ const accountProfileActions = deepFreeze([
|
|
|
39
40
|
version: 1,
|
|
40
41
|
kind: "command",
|
|
41
42
|
channels: ["api", "automation", "internal"],
|
|
42
|
-
|
|
43
|
+
surfaces: ["*"],
|
|
43
44
|
permission: {
|
|
44
45
|
require: "authenticated"
|
|
45
46
|
},
|
|
@@ -50,8 +51,9 @@ const accountProfileActions = deepFreeze([
|
|
|
50
51
|
actionName: "settings.profile.update"
|
|
51
52
|
},
|
|
52
53
|
observability: {},
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
events: ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS,
|
|
55
|
+
async run(accountProfileService, input, context) {
|
|
56
|
+
return accountProfileService.updateProfile(
|
|
55
57
|
resolveRequest(context),
|
|
56
58
|
resolveActionUser(context, input),
|
|
57
59
|
input,
|
|
@@ -66,7 +68,7 @@ const accountProfileActions = deepFreeze([
|
|
|
66
68
|
version: 1,
|
|
67
69
|
kind: "command",
|
|
68
70
|
channels: ["api", "automation", "internal"],
|
|
69
|
-
|
|
71
|
+
surfaces: ["*"],
|
|
70
72
|
permission: {
|
|
71
73
|
require: "authenticated"
|
|
72
74
|
},
|
|
@@ -77,7 +79,8 @@ const accountProfileActions = deepFreeze([
|
|
|
77
79
|
actionName: "settings.profile.avatar.upload"
|
|
78
80
|
},
|
|
79
81
|
observability: {},
|
|
80
|
-
|
|
82
|
+
events: ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS,
|
|
83
|
+
async run(accountProfileService, input, context) {
|
|
81
84
|
const avatarUpload = {
|
|
82
85
|
stream: input.stream,
|
|
83
86
|
mimeType: input.mimeType,
|
|
@@ -85,7 +88,7 @@ const accountProfileActions = deepFreeze([
|
|
|
85
88
|
uploadDimension: input.uploadDimension
|
|
86
89
|
};
|
|
87
90
|
|
|
88
|
-
return
|
|
91
|
+
return accountProfileService.uploadAvatar(
|
|
89
92
|
resolveRequest(context),
|
|
90
93
|
resolveActionUser(context, input),
|
|
91
94
|
avatarUpload,
|
|
@@ -100,7 +103,7 @@ const accountProfileActions = deepFreeze([
|
|
|
100
103
|
version: 1,
|
|
101
104
|
kind: "command",
|
|
102
105
|
channels: ["api", "automation", "internal"],
|
|
103
|
-
|
|
106
|
+
surfaces: ["*"],
|
|
104
107
|
permission: {
|
|
105
108
|
require: "authenticated"
|
|
106
109
|
},
|
|
@@ -111,8 +114,9 @@ const accountProfileActions = deepFreeze([
|
|
|
111
114
|
actionName: "settings.profile.avatar.delete"
|
|
112
115
|
},
|
|
113
116
|
observability: {},
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
events: ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS,
|
|
118
|
+
async run(accountProfileService, input, context) {
|
|
119
|
+
return accountProfileService.deleteAvatar(
|
|
116
120
|
resolveRequest(context),
|
|
117
121
|
resolveActionUser(context, input),
|
|
118
122
|
{
|
|
@@ -123,4 +127,14 @@ const accountProfileActions = deepFreeze([
|
|
|
123
127
|
}
|
|
124
128
|
]);
|
|
125
129
|
|
|
126
|
-
|
|
130
|
+
function buildAccountProfileActions({ accountProfileService } = {}) {
|
|
131
|
+
if (!accountProfileService) throw new TypeError("buildAccountProfileActions requires accountProfileService.");
|
|
132
|
+
return accountProfileActionSpecifications.map(({ run, ...definition }) => Object.freeze({
|
|
133
|
+
...definition,
|
|
134
|
+
execute(input, context) {
|
|
135
|
+
return run(accountProfileService, input, context);
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export { accountProfileActionSpecifications, buildAccountProfileActions };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { withStandardErrorResponses } from "@jskit-ai/http-runtime/shared/validators/errorResponses";
|
|
2
2
|
import { createJsonApiResourceRouteContract } from "@jskit-ai/http-runtime/shared/validators/jsonApiRouteTransport";
|
|
3
3
|
import { DEFAULT_IMAGE_UPLOAD_MAX_BYTES } from "@jskit-ai/uploads-runtime/shared";
|
|
4
|
-
import { readSingleMultipartFile } from "@jskit-ai/uploads-runtime/server/multipart/readSingleMultipartFile";
|
|
5
4
|
import { userSettingsResource } from "../../shared/resources/userSettingsResource.js";
|
|
6
5
|
import { userProfileResource } from "../../shared/resources/userProfileResource.js";
|
|
7
6
|
import { resolveAccountSettingsResourceId } from "../common/support/accountSettingsJsonApiTransport.js";
|
|
@@ -13,12 +12,16 @@ const USER_SETTINGS_RESOURCE_TRANSPORT = Object.freeze({
|
|
|
13
12
|
getRecordId: resolveAccountSettingsResourceId
|
|
14
13
|
});
|
|
15
14
|
|
|
16
|
-
function
|
|
17
|
-
if (!
|
|
18
|
-
throw new
|
|
15
|
+
function registerAccountProfileRoutes(router, { accountProfileService, authService, uploads } = {}) {
|
|
16
|
+
if (!router || typeof router.register !== "function") {
|
|
17
|
+
throw new TypeError("registerAccountProfileRoutes requires router.register().");
|
|
18
|
+
}
|
|
19
|
+
if (!accountProfileService || typeof accountProfileService.readAvatar !== "function") {
|
|
20
|
+
throw new TypeError("registerAccountProfileRoutes requires accountProfileService.");
|
|
21
|
+
}
|
|
22
|
+
if (!uploads || typeof uploads.readSingleMultipartFile !== "function") {
|
|
23
|
+
throw new TypeError("registerAccountProfileRoutes requires runtime.uploads.");
|
|
19
24
|
}
|
|
20
|
-
|
|
21
|
-
const router = app.make("jskit.http.router");
|
|
22
25
|
|
|
23
26
|
router.register(
|
|
24
27
|
"GET",
|
|
@@ -63,7 +66,6 @@ function bootAccountProfileRoutes(app) {
|
|
|
63
66
|
input: request.input.body
|
|
64
67
|
});
|
|
65
68
|
|
|
66
|
-
const authService = app.make("authService");
|
|
67
69
|
if (result?.session && typeof authService.writeSessionCookies === "function") {
|
|
68
70
|
authService.writeSessionCookies(reply, result.session);
|
|
69
71
|
}
|
|
@@ -83,7 +85,6 @@ function bootAccountProfileRoutes(app) {
|
|
|
83
85
|
}
|
|
84
86
|
},
|
|
85
87
|
async function (request, reply) {
|
|
86
|
-
const accountProfileService = app.make("users.accountProfile.service");
|
|
87
88
|
const avatar = await accountProfileService.readAvatar(request, request.user, {
|
|
88
89
|
context: {
|
|
89
90
|
actor: request.user
|
|
@@ -120,7 +121,7 @@ function bootAccountProfileRoutes(app) {
|
|
|
120
121
|
)
|
|
121
122
|
},
|
|
122
123
|
async function (request, reply) {
|
|
123
|
-
const filePart = await readSingleMultipartFile(request, {
|
|
124
|
+
const filePart = await uploads.readSingleMultipartFile(request, {
|
|
124
125
|
fieldName: "avatar",
|
|
125
126
|
required: true,
|
|
126
127
|
fieldErrorKey: "avatar",
|
|
@@ -165,4 +166,4 @@ function bootAccountProfileRoutes(app) {
|
|
|
165
166
|
);
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
export {
|
|
169
|
+
export { registerAccountProfileRoutes };
|
|
@@ -13,13 +13,13 @@ const oauthLinkStartInputValidator = composeSchemaDefinitions([
|
|
|
13
13
|
context: "accountSecurityActions.oauthLinkStartInputValidator"
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const accountSecurityActionSpecifications = Object.freeze([
|
|
17
17
|
{
|
|
18
18
|
id: "settings.security.password.change",
|
|
19
19
|
version: 1,
|
|
20
20
|
kind: "command",
|
|
21
21
|
channels: ["api", "automation", "internal"],
|
|
22
|
-
|
|
22
|
+
surfaces: ["*"],
|
|
23
23
|
permission: {
|
|
24
24
|
require: "authenticated"
|
|
25
25
|
},
|
|
@@ -30,8 +30,8 @@ const accountSecurityActions = Object.freeze([
|
|
|
30
30
|
actionName: "settings.security.password.change"
|
|
31
31
|
},
|
|
32
32
|
observability: {},
|
|
33
|
-
async
|
|
34
|
-
return
|
|
33
|
+
async run(accountSecurityService, input, context) {
|
|
34
|
+
return accountSecurityService.changePassword(
|
|
35
35
|
resolveRequest(context),
|
|
36
36
|
resolveActionUser(context, input),
|
|
37
37
|
input,
|
|
@@ -46,7 +46,7 @@ const accountSecurityActions = Object.freeze([
|
|
|
46
46
|
version: 1,
|
|
47
47
|
kind: "command",
|
|
48
48
|
channels: ["api", "automation", "internal"],
|
|
49
|
-
|
|
49
|
+
surfaces: ["*"],
|
|
50
50
|
permission: {
|
|
51
51
|
require: "authenticated"
|
|
52
52
|
},
|
|
@@ -57,8 +57,8 @@ const accountSecurityActions = Object.freeze([
|
|
|
57
57
|
actionName: "settings.security.password_method.toggle"
|
|
58
58
|
},
|
|
59
59
|
observability: {},
|
|
60
|
-
async
|
|
61
|
-
return
|
|
60
|
+
async run(accountSecurityService, input, context) {
|
|
61
|
+
return accountSecurityService.setPasswordMethodEnabled(
|
|
62
62
|
resolveRequest(context),
|
|
63
63
|
resolveActionUser(context, input),
|
|
64
64
|
input,
|
|
@@ -73,7 +73,7 @@ const accountSecurityActions = Object.freeze([
|
|
|
73
73
|
version: 1,
|
|
74
74
|
kind: "query",
|
|
75
75
|
channels: ["api", "automation", "internal"],
|
|
76
|
-
|
|
76
|
+
surfaces: ["*"],
|
|
77
77
|
permission: {
|
|
78
78
|
require: "authenticated"
|
|
79
79
|
},
|
|
@@ -84,8 +84,8 @@ const accountSecurityActions = Object.freeze([
|
|
|
84
84
|
actionName: "settings.security.oauth.link.start"
|
|
85
85
|
},
|
|
86
86
|
observability: {},
|
|
87
|
-
async
|
|
88
|
-
return
|
|
87
|
+
async run(accountSecurityService, input, context) {
|
|
88
|
+
return accountSecurityService.startOAuthProviderLink(
|
|
89
89
|
resolveRequest(context),
|
|
90
90
|
resolveActionUser(context, input),
|
|
91
91
|
input,
|
|
@@ -100,7 +100,7 @@ const accountSecurityActions = Object.freeze([
|
|
|
100
100
|
version: 1,
|
|
101
101
|
kind: "command",
|
|
102
102
|
channels: ["api", "automation", "internal"],
|
|
103
|
-
|
|
103
|
+
surfaces: ["*"],
|
|
104
104
|
permission: {
|
|
105
105
|
require: "authenticated"
|
|
106
106
|
},
|
|
@@ -111,8 +111,8 @@ const accountSecurityActions = Object.freeze([
|
|
|
111
111
|
actionName: "settings.security.oauth.unlink"
|
|
112
112
|
},
|
|
113
113
|
observability: {},
|
|
114
|
-
async
|
|
115
|
-
return
|
|
114
|
+
async run(accountSecurityService, input, context) {
|
|
115
|
+
return accountSecurityService.unlinkOAuthProvider(
|
|
116
116
|
resolveRequest(context),
|
|
117
117
|
resolveActionUser(context, input),
|
|
118
118
|
input,
|
|
@@ -127,7 +127,7 @@ const accountSecurityActions = Object.freeze([
|
|
|
127
127
|
version: 1,
|
|
128
128
|
kind: "command",
|
|
129
129
|
channels: ["api", "automation", "internal"],
|
|
130
|
-
|
|
130
|
+
surfaces: ["*"],
|
|
131
131
|
permission: {
|
|
132
132
|
require: "authenticated"
|
|
133
133
|
},
|
|
@@ -138,12 +138,22 @@ const accountSecurityActions = Object.freeze([
|
|
|
138
138
|
actionName: "settings.security.sessions.logout_others"
|
|
139
139
|
},
|
|
140
140
|
observability: {},
|
|
141
|
-
async
|
|
142
|
-
return
|
|
141
|
+
async run(accountSecurityService, input, context) {
|
|
142
|
+
return accountSecurityService.logoutOtherSessions(resolveRequest(context), resolveActionUser(context, input), {
|
|
143
143
|
context
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
]);
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
function buildAccountSecurityActions({ accountSecurityService } = {}) {
|
|
150
|
+
if (!accountSecurityService) throw new TypeError("buildAccountSecurityActions requires accountSecurityService.");
|
|
151
|
+
return accountSecurityActionSpecifications.map(({ run, ...definition }) => Object.freeze({
|
|
152
|
+
...definition,
|
|
153
|
+
execute(input, context) {
|
|
154
|
+
return run(accountSecurityService, input, context);
|
|
155
|
+
}
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { accountSecurityActionSpecifications, buildAccountSecurityActions };
|
|
@@ -16,13 +16,11 @@ const passwordChangeMetaOutputValidator = deepFreeze({
|
|
|
16
16
|
mode: "replace"
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
function
|
|
20
|
-
if (!
|
|
21
|
-
throw new
|
|
19
|
+
function registerAccountSecurityRoutes(router, { authService } = {}) {
|
|
20
|
+
if (!router || typeof router.register !== "function") {
|
|
21
|
+
throw new TypeError("registerAccountSecurityRoutes requires router.register().");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const router = app.make("jskit.http.router");
|
|
25
|
-
|
|
26
24
|
router.register(
|
|
27
25
|
"POST",
|
|
28
26
|
"/api/settings/security/change-password",
|
|
@@ -50,7 +48,6 @@ function bootAccountSecurityRoutes(app) {
|
|
|
50
48
|
input: request.input.body
|
|
51
49
|
});
|
|
52
50
|
|
|
53
|
-
const authService = app.make("authService");
|
|
54
51
|
if (result?.session && typeof authService.writeSessionCookies === "function") {
|
|
55
52
|
authService.writeSessionCookies(reply, result.session);
|
|
56
53
|
}
|
|
@@ -192,4 +189,4 @@ function bootAccountSecurityRoutes(app) {
|
|
|
192
189
|
);
|
|
193
190
|
}
|
|
194
191
|
|
|
195
|
-
export {
|
|
192
|
+
export { registerAccountSecurityRoutes };
|