@jskit-ai/users-core 0.2.4 → 0.2.6
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/locales/en.json +1 -7
- package/package.json +42 -19
- package/patterns/user-administration-server/PATTERN.md +16 -1
- package/patterns/user-administration-server/example/packages/users/package.json +3 -2
- package/patterns/user-administration-server/example/packages/users/src/server/types.js +5 -0
- package/patterns/user-administration-server/example/packages/users-workspace/package.json +4 -3
- package/patterns/user-administration-server/example/packages/users-workspace/src/server/UsersWorkspaceFeature.js +2 -9
- package/patterns/user-administration-server/example/packages/users-workspace/src/server/types.js +5 -0
- package/src/server/UsersFeature.js +26 -78
- package/src/server/UsersIdentityProvider.js +11 -22
- package/src/server/accountNotifications/accountNotificationsActions.js +28 -41
- package/src/server/accountNotifications/{bootAccountNotificationsRoutes.js → accountNotificationsRoutes.js} +1 -4
- package/src/server/accountNotifications/accountNotificationsService.js +9 -10
- package/src/server/accountPreferences/accountPreferencesActions.js +28 -41
- package/src/server/accountPreferences/{bootAccountPreferencesRoutes.js → accountPreferencesRoutes.js} +1 -4
- package/src/server/accountPreferences/accountPreferencesService.js +10 -10
- package/src/server/accountProfile/accountProfileActions.js +87 -127
- package/src/server/accountProfile/{bootAccountProfileRoutes.js → accountProfileRoutes.js} +12 -18
- package/src/server/accountProfile/accountProfileService.js +19 -35
- package/src/server/accountProfile/avatarService.js +15 -39
- package/src/server/accountProfile/avatarStorageService.js +2 -1
- package/src/server/accountSecurity/accountSecurityActions.js +100 -148
- package/src/server/accountSecurity/{bootAccountSecurityRoutes.js → accountSecurityRoutes.js} +9 -8
- package/src/server/accountSecurity/accountSecurityService.js +15 -44
- package/src/server/common/formatters/accountAvatarFormatter.js +4 -4
- package/src/server/common/formatters/accountSecurityStatusFormatter.js +2 -3
- package/src/server/common/formatters/accountSettingsResponseFormatter.js +11 -2
- package/src/server/common/repositories/userProfilesRepository.js +31 -55
- package/src/server/common/repositories/userSettingsRepository.js +16 -21
- package/src/server/common/services/accountContextService.js +9 -7
- package/src/server/common/services/authProfileSyncService.js +15 -42
- package/src/server/common/support/accountSettingsJsonApiTransport.js +10 -3
- package/src/server/common/support/realtimeServiceEvents.js +3 -2
- package/src/server/common/support/resolveActionUser.js +9 -2
- package/src/server/types.js +29 -0
- package/src/server/usersBootstrapContributor.js +60 -84
- package/src/server/usersExtensions.js +1 -0
- package/src/server/usersIdentity.js +28 -0
- package/src/server/usersRuntime.js +61 -0
- package/src/shared/operationMessages.js +6 -15
- package/src/shared/resources/userProfileResource.js +3 -31
- package/src/shared/resources/userProfileValues.js +32 -0
- package/src/shared/resources/userSettingsResource.js +2 -4
- package/test/accountProfileService.test.js +1 -0
- package/test/accountSecurityService.test.js +2 -4
- package/test/exportsContract.test.js +2 -0
- package/test/featureRuntime.test.js +11 -8
- package/test/i18nCodes.test.js +3 -10
- package/test/usersBootstrapContributor.test.js +0 -1
- package/test/usersPackageScaffoldContract.test.js +3 -5
- package/test/usersRouteRequestInputValidator.test.js +4 -4
- package/src/server/common/repositories/repositoryUtils.js +0 -44
- package/src/server/common/support/deepFreeze.js +0 -1
package/locales/en.json
CHANGED
|
@@ -5,15 +5,9 @@
|
|
|
5
5
|
"notFound": "User profile was not found."
|
|
6
6
|
},
|
|
7
7
|
"avatar": {
|
|
8
|
-
"notFound": "Avatar not found."
|
|
9
|
-
"uploadResultMissing": "Avatar upload completed without a profile result."
|
|
8
|
+
"notFound": "Avatar not found."
|
|
10
9
|
},
|
|
11
10
|
"security": {
|
|
12
|
-
"passwordChangeUnavailable": "Password change is not available.",
|
|
13
|
-
"passwordMethodToggleUnavailable": "Password method toggle is not available.",
|
|
14
|
-
"oauthLinkUnavailable": "OAuth linking is not available.",
|
|
15
|
-
"oauthUnlinkUnavailable": "OAuth unlink is not available.",
|
|
16
|
-
"logoutOtherSessionsUnavailable": "Logout other sessions is not available.",
|
|
17
11
|
"passwordConfirmationMismatch": "Password confirmation does not match.",
|
|
18
12
|
"passwordUpdated": "Password updated."
|
|
19
13
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/users-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -9,18 +9,20 @@
|
|
|
9
9
|
"./server/UsersFeature": "./src/server/UsersFeature.js",
|
|
10
10
|
"./server/UsersIdentityProvider": "./src/server/UsersIdentityProvider.js",
|
|
11
11
|
"./server/usersExtensions": "./src/server/usersExtensions.js",
|
|
12
|
+
"./server/resolveActionUser": "./src/server/common/support/resolveActionUser.js",
|
|
13
|
+
"./server/types": "./src/server/types.js",
|
|
12
14
|
"./shared/resources/userProfileResource": "./src/shared/resources/userProfileResource.js",
|
|
13
15
|
"./shared/resources/userSettingsResource": "./src/shared/resources/userSettingsResource.js",
|
|
14
16
|
"./shared/settings": "./src/shared/settings.js",
|
|
15
17
|
"./locales/en.json": "./locales/en.json"
|
|
16
18
|
},
|
|
17
19
|
"dependencies": {
|
|
18
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
19
|
-
"@jskit-ai/json-rest-api-core": "0.2.
|
|
20
|
-
"@jskit-ai/resource-core": "0.1.
|
|
21
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
22
|
-
"@jskit-ai/storage-runtime": "0.1.
|
|
23
|
-
"@jskit-ai/uploads-runtime": "0.2.
|
|
20
|
+
"@jskit-ai/database-runtime": "0.1.254",
|
|
21
|
+
"@jskit-ai/json-rest-api-core": "0.2.5",
|
|
22
|
+
"@jskit-ai/resource-core": "0.1.196",
|
|
23
|
+
"@jskit-ai/resource-crud-core": "0.1.196",
|
|
24
|
+
"@jskit-ai/storage-runtime": "0.1.251",
|
|
25
|
+
"@jskit-ai/uploads-runtime": "0.2.5",
|
|
24
26
|
"json-rest-schema": "^1.0.17"
|
|
25
27
|
},
|
|
26
28
|
"description": "Users/account runtime plus HTTP routes for account features.",
|
|
@@ -30,10 +32,10 @@
|
|
|
30
32
|
"provides": [
|
|
31
33
|
"users.core",
|
|
32
34
|
"users.identity",
|
|
33
|
-
"users.extensions"
|
|
35
|
+
"users.extensions",
|
|
36
|
+
"auth.profile.projector"
|
|
34
37
|
],
|
|
35
38
|
"requires": [
|
|
36
|
-
"auth.extensions",
|
|
37
39
|
"auth.service",
|
|
38
40
|
"runtime.actions",
|
|
39
41
|
"runtime.bootstrap",
|
|
@@ -78,22 +80,43 @@
|
|
|
78
80
|
"apiSummary": {
|
|
79
81
|
"surfaces": [
|
|
80
82
|
{
|
|
81
|
-
"subpath": "./server",
|
|
82
|
-
"summary": "Exports
|
|
83
|
+
"subpath": "./server/UsersFeature",
|
|
84
|
+
"summary": "Exports UsersFeature, which provides users.core: the account settings, profile, avatar and security services, their actions and routes, and the users bootstrap."
|
|
83
85
|
},
|
|
84
86
|
{
|
|
85
|
-
"subpath": "./
|
|
86
|
-
"summary": "Exports
|
|
87
|
+
"subpath": "./server/UsersIdentityProvider",
|
|
88
|
+
"summary": "Exports UsersIdentityProvider, which provides users.identity (the user profile and settings repositories) and auth.profile.projector."
|
|
87
89
|
},
|
|
88
90
|
{
|
|
89
|
-
"subpath": "./
|
|
90
|
-
"summary": "Exports
|
|
91
|
+
"subpath": "./server/usersExtensions",
|
|
92
|
+
"summary": "Exports createUsersExtensions, the users.extensions registry of profile synchronization lifecycle contributors."
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"subpath": "./server/resolveActionUser",
|
|
96
|
+
"summary": "Exports resolveActionUser, which reads an action's signed-in user."
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"subpath": "./shared/resources/userProfileResource",
|
|
100
|
+
"summary": "Exports the shared user profile resource."
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"subpath": "./shared/resources/userSettingsResource",
|
|
104
|
+
"summary": "Exports the shared user settings resource."
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"subpath": "./shared/settings",
|
|
108
|
+
"summary": "Exports the users settings defaults."
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"subpath": "./server/types",
|
|
112
|
+
"summary": "Types of the users.core, users.identity and users.extensions capabilities, for features that require them."
|
|
91
113
|
}
|
|
92
114
|
],
|
|
93
115
|
"capabilities": [
|
|
94
116
|
"users.core",
|
|
95
117
|
"users.identity",
|
|
96
|
-
"users.extensions"
|
|
118
|
+
"users.extensions",
|
|
119
|
+
"auth.profile.projector"
|
|
97
120
|
]
|
|
98
121
|
},
|
|
99
122
|
"server": {
|
|
@@ -168,8 +191,8 @@
|
|
|
168
191
|
}
|
|
169
192
|
},
|
|
170
193
|
"peerDependencies": {
|
|
171
|
-
"@jskit-ai/auth-core": "0.2.
|
|
172
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
173
|
-
"@jskit-ai/kernel": "0.2.
|
|
194
|
+
"@jskit-ai/auth-core": "0.2.5",
|
|
195
|
+
"@jskit-ai/http-runtime": "0.2.5",
|
|
196
|
+
"@jskit-ai/kernel": "0.2.5"
|
|
174
197
|
}
|
|
175
198
|
}
|
|
@@ -38,12 +38,25 @@ and the resource contracts from `@jskit-ai/resource-crud-core`.
|
|
|
38
38
|
- Shared profile persistence remains owned by `@jskit-ai/users-core`.
|
|
39
39
|
- The resource is the field contract; the feature projects its repository,
|
|
40
40
|
service, actions, and routes without app-local ceremony.
|
|
41
|
+
- Each package exports the type of the capability it provides:
|
|
42
|
+
`src/server/types.js` declares `AppUsers` (for `app.users`) or
|
|
43
|
+
`AppUsersWorkspace` (for `app.users-workspace`) as crud-core's
|
|
44
|
+
`CrudResourceApi`, exported as `./server/types`. A feature that requires the
|
|
45
|
+
capability names that type in a JSDoc `@param`.
|
|
46
|
+
- Code added to a declaration follows [typed features](https://github.com/mobily-enterprises/jskit-ai/blob/main/packages/agent-docs/site/guide/framework/typed-features.md):
|
|
47
|
+
decorators, lifecycle hooks and named actions call the collaborators they
|
|
48
|
+
receive directly, with no `typeof` probe, optional call, absent default,
|
|
49
|
+
slot setter or module-level registry, and each action's `execute` is one
|
|
50
|
+
call to one service method with the validated input. Keep one copy of each
|
|
51
|
+
helper per package, files under 750 lines and functions under 600.
|
|
41
52
|
|
|
42
53
|
## Example files
|
|
43
54
|
|
|
44
55
|
`example/packages/users/` is a global administration package.
|
|
45
56
|
`example/packages/users-workspace/` demonstrates the workspace route/action
|
|
46
|
-
boundary while reusing the same
|
|
57
|
+
boundary, with workspaces-core's `WORKSPACE_CRUD_SCOPE`, while reusing the same
|
|
58
|
+
service contract. Each package's
|
|
59
|
+
`src/server/types.js` declares the type of the capability it provides. Copy only the composition
|
|
47
60
|
that matches the product and adapt it as ordinary application source.
|
|
48
61
|
|
|
49
62
|
## Variation points
|
|
@@ -62,3 +75,5 @@ isolation, missing records, null/cleared fields, filtering, and pagination.
|
|
|
62
75
|
- trusting route scope without repository scope
|
|
63
76
|
- adding app-local mechanics already provided by `defineCrudJsonApiFeature()`
|
|
64
77
|
- generator metadata or field questionnaires
|
|
78
|
+
- probing a collaborator, defaulting one to `null`, `{}` or a no-op, setters
|
|
79
|
+
that fill a slot after construction, and module-level registries
|
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
"./server/UsersFeature": "./src/server/UsersFeature.js",
|
|
9
|
+
"./server/types": "./src/server/types.js",
|
|
9
10
|
"./shared": "./src/shared/index.js"
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
|
-
"@jskit-ai/crud-core": "0.2.
|
|
13
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
13
|
+
"@jskit-ai/crud-core": "0.2.5",
|
|
14
|
+
"@jskit-ai/resource-crud-core": "0.1.196"
|
|
14
15
|
},
|
|
15
16
|
"jskit": {
|
|
16
17
|
"kind": "runtime",
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
"./server/UsersWorkspaceFeature": "./src/server/UsersWorkspaceFeature.js",
|
|
9
|
+
"./server/types": "./src/server/types.js",
|
|
9
10
|
"./shared": "./src/shared/index.js"
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
|
-
"@jskit-ai/crud-core": "0.2.
|
|
13
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
14
|
-
"@jskit-ai/workspaces-core": "0.2.
|
|
13
|
+
"@jskit-ai/crud-core": "0.2.5",
|
|
14
|
+
"@jskit-ai/resource-crud-core": "0.1.196",
|
|
15
|
+
"@jskit-ai/workspaces-core": "0.2.6"
|
|
15
16
|
},
|
|
16
17
|
"jskit": {
|
|
17
18
|
"kind": "runtime",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { defineCrudJsonApiFeature } from "@jskit-ai/crud-core/server/defineCrudJsonApiFeature";
|
|
2
|
-
import {
|
|
3
|
-
import { workspaceSlugParamsValidator } from "@jskit-ai/workspaces-core/server/validators/routeParamsValidator";
|
|
2
|
+
import { WORKSPACE_CRUD_SCOPE } from "@jskit-ai/workspaces-core/server/support/workspaceCrud";
|
|
4
3
|
import { resource } from "../shared/userResource.js";
|
|
5
4
|
|
|
6
5
|
const UsersWorkspaceFeature = defineCrudJsonApiFeature({
|
|
@@ -10,13 +9,7 @@ const UsersWorkspaceFeature = defineCrudJsonApiFeature({
|
|
|
10
9
|
surface: "admin",
|
|
11
10
|
ownershipFilter: "workspace",
|
|
12
11
|
relativePath: "/users",
|
|
13
|
-
scope:
|
|
14
|
-
routeBase: "/w/:workspaceSlug",
|
|
15
|
-
actionInputValidator: workspaceSlugParamsValidator,
|
|
16
|
-
routeParamsValidator: workspaceSlugParamsValidator,
|
|
17
|
-
inputKeys: ["workspaceSlug"],
|
|
18
|
-
input: (request) => buildWorkspaceInputFromRouteParams(request.input.params)
|
|
19
|
-
}
|
|
12
|
+
scope: WORKSPACE_CRUD_SCOPE
|
|
20
13
|
});
|
|
21
14
|
|
|
22
15
|
export { UsersWorkspaceFeature };
|
|
@@ -1,68 +1,14 @@
|
|
|
1
1
|
import { defineFeature } from "@jskit-ai/kernel/server/features";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
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";
|
|
2
|
+
import { createAccountNotificationsActions } from "./accountNotifications/accountNotificationsActions.js";
|
|
3
|
+
import { registerAccountNotificationsRoutes } from "./accountNotifications/accountNotificationsRoutes.js";
|
|
4
|
+
import { createAccountPreferencesActions } from "./accountPreferences/accountPreferencesActions.js";
|
|
5
|
+
import { registerAccountPreferencesRoutes } from "./accountPreferences/accountPreferencesRoutes.js";
|
|
6
|
+
import { createAccountProfileActions } from "./accountProfile/accountProfileActions.js";
|
|
7
|
+
import { registerAccountProfileRoutes } from "./accountProfile/accountProfileRoutes.js";
|
|
8
|
+
import { createAccountSecurityActions } from "./accountSecurity/accountSecurityActions.js";
|
|
9
|
+
import { registerAccountSecurityRoutes } from "./accountSecurity/accountSecurityRoutes.js";
|
|
17
10
|
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
|
-
}
|
|
11
|
+
import { createUsersRuntime } from "./usersRuntime.js";
|
|
66
12
|
|
|
67
13
|
const UsersFeature = defineFeature({
|
|
68
14
|
id: "users.core",
|
|
@@ -78,14 +24,16 @@ const UsersFeature = defineFeature({
|
|
|
78
24
|
provides: {
|
|
79
25
|
users: "users.core"
|
|
80
26
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @param {object} capabilities
|
|
29
|
+
* @param {import("@jskit-ai/auth-core/server/types").AuthService} capabilities.authService
|
|
30
|
+
* @param {import("@jskit-ai/kernel/server/types").RuntimeBootstrap} capabilities.bootstrap
|
|
31
|
+
* @param {import("@jskit-ai/kernel/server/types").RuntimeHttp} capabilities.http
|
|
32
|
+
* @param {import("./types.js").UsersIdentity} capabilities.identity
|
|
33
|
+
* @param {import("@jskit-ai/storage-runtime/server/types").RuntimeStorage} capabilities.storage
|
|
34
|
+
* @param {import("@jskit-ai/uploads-runtime/server/types").RuntimeUploads} capabilities.uploads
|
|
35
|
+
*/
|
|
36
|
+
setup({ authService, bootstrap, http, identity, storage, uploads }) {
|
|
89
37
|
const users = createUsersRuntime({ authService, identity, storage });
|
|
90
38
|
registerAccountProfileRoutes(http.router, {
|
|
91
39
|
accountProfileService: users.services.accountProfile,
|
|
@@ -107,13 +55,13 @@ const UsersFeature = defineFeature({
|
|
|
107
55
|
return { users };
|
|
108
56
|
},
|
|
109
57
|
actions({ users }) {
|
|
110
|
-
return [
|
|
111
|
-
...
|
|
112
|
-
...
|
|
113
|
-
...
|
|
114
|
-
...
|
|
115
|
-
];
|
|
58
|
+
return Object.freeze([
|
|
59
|
+
...createAccountProfileActions({ accountProfileService: users.services.accountProfile }),
|
|
60
|
+
...createAccountPreferencesActions({ accountPreferencesService: users.services.accountPreferences }),
|
|
61
|
+
...createAccountNotificationsActions({ accountNotificationsService: users.services.accountNotifications }),
|
|
62
|
+
...createAccountSecurityActions({ accountSecurityService: users.services.accountSecurity })
|
|
63
|
+
]);
|
|
116
64
|
}
|
|
117
65
|
});
|
|
118
66
|
|
|
119
|
-
export { UsersFeature
|
|
67
|
+
export { UsersFeature };
|
|
@@ -6,21 +6,24 @@ import {
|
|
|
6
6
|
import { defineProvider } from "@jskit-ai/kernel/shared/capabilities";
|
|
7
7
|
import { userProfileResource } from "../shared/resources/userProfileResource.js";
|
|
8
8
|
import { userSettingsResource } from "../shared/resources/userSettingsResource.js";
|
|
9
|
-
import {
|
|
10
|
-
import { createRepository as createUserSettingsRepository } from "./common/repositories/userSettingsRepository.js";
|
|
11
|
-
import { createService as createAuthProfileSyncService } from "./common/services/authProfileSyncService.js";
|
|
9
|
+
import { createUsersIdentity } from "./usersIdentity.js";
|
|
12
10
|
|
|
13
11
|
const UsersIdentityProvider = defineProvider({
|
|
14
12
|
id: "users.identity",
|
|
15
13
|
requires: {
|
|
16
|
-
authExtensions: "auth.extensions",
|
|
17
14
|
extensions: "users.extensions",
|
|
18
15
|
jsonRestApi: "runtime.json-rest-api"
|
|
19
16
|
},
|
|
20
17
|
provides: {
|
|
21
|
-
identity: "users.identity"
|
|
18
|
+
identity: "users.identity",
|
|
19
|
+
profileProjector: "auth.profile.projector"
|
|
22
20
|
},
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @param {object} capabilities
|
|
23
|
+
* @param {import("./types.js").UsersExtensions} capabilities.extensions
|
|
24
|
+
* @param {import("@jskit-ai/json-rest-api-core/server/types").RuntimeJsonRestApi} capabilities.jsonRestApi
|
|
25
|
+
*/
|
|
26
|
+
async setup({ extensions, jsonRestApi }) {
|
|
24
27
|
const scopeOptions = {
|
|
25
28
|
writeSerializers: { "datetime-utc": toDatabaseDateTimeUtc }
|
|
26
29
|
};
|
|
@@ -34,22 +37,8 @@ const UsersIdentityProvider = defineProvider({
|
|
|
34
37
|
"userSettings",
|
|
35
38
|
createJsonRestResourceScopeOptions(userSettingsResource, scopeOptions)
|
|
36
39
|
);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
userSettings: createUserSettingsRepository({ api: jsonRestApi })
|
|
40
|
-
});
|
|
41
|
-
const profileProjector = createAuthProfileSyncService({
|
|
42
|
-
userProfilesRepository: repositories.userProfiles,
|
|
43
|
-
userSettingsRepository: repositories.userSettings,
|
|
44
|
-
resolveLifecycleContributors: extensions.profileSyncLifecycleContributors
|
|
45
|
-
});
|
|
46
|
-
authExtensions.registerProfileProjector({
|
|
47
|
-
projectorId: "users.profile",
|
|
48
|
-
...profileProjector
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
identity: Object.freeze({ repositories, profileProjector })
|
|
52
|
-
};
|
|
40
|
+
const identity = createUsersIdentity({ jsonRestApi, extensions });
|
|
41
|
+
return { identity, profileProjector: identity.profileProjector };
|
|
53
42
|
}
|
|
54
43
|
});
|
|
55
44
|
|
|
@@ -5,48 +5,35 @@ import { userSettingsResource } from "../../shared/resources/userSettingsResourc
|
|
|
5
5
|
import { resolveActionUser } from "../common/support/resolveActionUser.js";
|
|
6
6
|
import { ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS } from "../common/support/realtimeServiceEvents.js";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
/** @param {{ accountNotificationsService: import("../types.js").AccountNotificationsService }} dependencies */
|
|
9
|
+
function createAccountNotificationsActions({ accountNotificationsService }) {
|
|
10
|
+
return Object.freeze([
|
|
11
|
+
Object.freeze({
|
|
12
|
+
id: "settings.notifications.update",
|
|
13
|
+
version: 1,
|
|
14
|
+
kind: "command",
|
|
15
|
+
channels: ["api", "automation", "internal"],
|
|
16
|
+
surfaces: ["*"],
|
|
17
|
+
permission: {
|
|
18
|
+
require: "authenticated"
|
|
19
|
+
},
|
|
20
|
+
input: userSettingsResource.operations.notificationsUpdate.body,
|
|
21
|
+
output: null,
|
|
22
|
+
extensions: {
|
|
23
|
+
assistant: {
|
|
24
|
+
description: "Update the signed-in user’s notification preferences.",
|
|
25
|
+
output: userSettingsResource.operations.notificationsUpdate.output,
|
|
26
|
+
transformResult: (result) => result.value
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
events: ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS,
|
|
30
|
+
execute: (input, context) => accountNotificationsService.updateNotifications(
|
|
31
31
|
resolveRequest(context),
|
|
32
32
|
resolveActionUser(context, input),
|
|
33
|
-
input
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
function buildAccountNotificationsActions({ accountNotificationsService } = {}) {
|
|
43
|
-
if (!accountNotificationsService) throw new TypeError("buildAccountNotificationsActions requires accountNotificationsService.");
|
|
44
|
-
return accountNotificationsActionSpecifications.map(({ run, ...definition }) => Object.freeze({
|
|
45
|
-
...definition,
|
|
46
|
-
execute(input, context) {
|
|
47
|
-
return run(accountNotificationsService, input, context);
|
|
48
|
-
}
|
|
49
|
-
}));
|
|
33
|
+
input
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
]);
|
|
50
37
|
}
|
|
51
38
|
|
|
52
|
-
export {
|
|
39
|
+
export { createAccountNotificationsActions };
|
|
@@ -2,11 +2,8 @@ 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
|
+
/** @param {import("@jskit-ai/kernel/server/types").RuntimeRouter} router */
|
|
5
6
|
function registerAccountNotificationsRoutes(router) {
|
|
6
|
-
if (!router || typeof router.register !== "function") {
|
|
7
|
-
throw new TypeError("registerAccountNotificationsRoutes requires router.register().");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
7
|
router.register(
|
|
11
8
|
"PATCH",
|
|
12
9
|
"/api/settings/notifications",
|
|
@@ -8,16 +8,15 @@ import {
|
|
|
8
8
|
accountSettingsResponseFormatter
|
|
9
9
|
} from "../common/formatters/accountSettingsResponseFormatter.js";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
async function updateNotifications(request, user, payload = {}, options = {}) {
|
|
11
|
+
/**
|
|
12
|
+
* A signed-in user's notification settings.
|
|
13
|
+
* @param {object} dependencies
|
|
14
|
+
* @param {import("../types.js").UserSettingsRepository} dependencies.userSettingsRepository
|
|
15
|
+
* @param {import("../types.js").UserProfilesRepository} dependencies.userProfilesRepository
|
|
16
|
+
* @param {import("@jskit-ai/auth-core/server/types").AuthService} dependencies.authService The installed provider's `auth.service`; it reports the security status.
|
|
17
|
+
*/
|
|
18
|
+
function createService({ userSettingsRepository, userProfilesRepository, authService }) {
|
|
19
|
+
async function updateNotifications(request, user, payload) {
|
|
21
20
|
const profile = await resolveUserProfile(userProfilesRepository, user);
|
|
22
21
|
if (!profile) {
|
|
23
22
|
throw new AppError(404, "User profile was not found.", { code: "users.profile.notFound" });
|
|
@@ -5,48 +5,35 @@ import { userSettingsResource } from "../../shared/resources/userSettingsResourc
|
|
|
5
5
|
import { resolveActionUser } from "../common/support/resolveActionUser.js";
|
|
6
6
|
import { ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS } from "../common/support/realtimeServiceEvents.js";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
/** @param {{ accountPreferencesService: import("../types.js").AccountPreferencesService }} dependencies */
|
|
9
|
+
function createAccountPreferencesActions({ accountPreferencesService }) {
|
|
10
|
+
return Object.freeze([
|
|
11
|
+
Object.freeze({
|
|
12
|
+
id: "settings.preferences.update",
|
|
13
|
+
version: 1,
|
|
14
|
+
kind: "command",
|
|
15
|
+
channels: ["api", "automation", "internal"],
|
|
16
|
+
surfaces: ["*"],
|
|
17
|
+
permission: {
|
|
18
|
+
require: "authenticated"
|
|
19
|
+
},
|
|
20
|
+
input: userSettingsResource.operations.preferencesUpdate.body,
|
|
21
|
+
output: null,
|
|
22
|
+
extensions: {
|
|
23
|
+
assistant: {
|
|
24
|
+
description: "Update the signed-in user’s display and regional preferences.",
|
|
25
|
+
output: userSettingsResource.operations.preferencesUpdate.output,
|
|
26
|
+
transformResult: (result) => result.value
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
events: ACCOUNT_SETTINGS_AND_BOOTSTRAP_EVENTS,
|
|
30
|
+
execute: (input, context) => accountPreferencesService.updatePreferences(
|
|
31
31
|
resolveRequest(context),
|
|
32
32
|
resolveActionUser(context, input),
|
|
33
|
-
input
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
function buildAccountPreferencesActions({ accountPreferencesService } = {}) {
|
|
43
|
-
if (!accountPreferencesService) throw new TypeError("buildAccountPreferencesActions requires accountPreferencesService.");
|
|
44
|
-
return accountPreferencesActionSpecifications.map(({ run, ...definition }) => Object.freeze({
|
|
45
|
-
...definition,
|
|
46
|
-
execute(input, context) {
|
|
47
|
-
return run(accountPreferencesService, input, context);
|
|
48
|
-
}
|
|
49
|
-
}));
|
|
33
|
+
input
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
]);
|
|
50
37
|
}
|
|
51
38
|
|
|
52
|
-
export {
|
|
39
|
+
export { createAccountPreferencesActions };
|
|
@@ -2,11 +2,8 @@ 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
|
+
/** @param {import("@jskit-ai/kernel/server/types").RuntimeRouter} router */
|
|
5
6
|
function registerAccountPreferencesRoutes(router) {
|
|
6
|
-
if (!router || typeof router.register !== "function") {
|
|
7
|
-
throw new TypeError("registerAccountPreferencesRoutes requires router.register().");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
7
|
router.register(
|
|
11
8
|
"PATCH",
|
|
12
9
|
"/api/settings/preferences",
|