@jskit-ai/users-core 0.1.47 → 0.1.49
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.descriptor.mjs +9 -46
- package/package.json +8 -19
- package/src/server/UsersCoreServiceProvider.js +0 -4
- package/src/server/common/registerCommonRepositories.js +0 -5
- package/src/server/common/services/authProfileSyncService.js +28 -7
- package/src/server/common/support/realtimeServiceEvents.js +1 -59
- package/src/server/profileSyncLifecycleContributorRegistry.js +56 -0
- package/src/server/registerUsersBootstrap.js +1 -3
- package/src/server/registerUsersCore.js +2 -14
- package/src/server/usersBootstrapContributor.js +10 -85
- package/src/shared/index.js +2 -99
- package/src/shared/settings.js +1 -119
- package/templates/migrations/users_core_generic_initial.cjs +0 -16
- package/test/authProfileSyncService.test.js +19 -10
- package/test/registerServiceRealtimeEvents.test.js +0 -94
- package/test/registerUsersCore.test.js +6 -19
- package/test/repositoryContracts.test.js +1 -11
- package/test/resourcesCanonical.test.js +1 -19
- package/test/settingsFieldRegistriesSingleton.test.js +0 -10
- package/test/usersBootstrapContributor.test.js +20 -38
- package/test/usersRouteRequestInputValidator.test.js +2 -43
- package/test/usersRouteResources.test.js +2 -20
- package/test-support/registerDefaultSettingsFields.js +0 -1
- package/src/server/UsersWorkspacesServiceProvider.js +0 -44
- package/src/server/common/contributors/workspaceActionContextContributor.js +0 -88
- package/src/server/common/contributors/workspaceAuthPolicyContextResolver.js +0 -34
- package/src/server/common/contributors/workspaceRouteVisibilityResolver.js +0 -78
- package/src/server/common/formatters/workspaceFormatter.js +0 -53
- package/src/server/common/repositories/workspaceInvitesRepository.js +0 -208
- package/src/server/common/repositories/workspaceMembershipsRepository.js +0 -190
- package/src/server/common/repositories/workspacesRepository.js +0 -202
- package/src/server/common/services/workspaceContextService.js +0 -281
- package/src/server/common/support/workspaceRoutePaths.js +0 -17
- package/src/server/common/validators/routeParamsValidator.js +0 -62
- package/src/server/consoleSettings/bootConsoleSettingsRoutes.js +0 -63
- package/src/server/consoleSettings/consoleService.js +0 -36
- package/src/server/consoleSettings/consoleSettingsActions.js +0 -55
- package/src/server/consoleSettings/consoleSettingsRepository.js +0 -115
- package/src/server/consoleSettings/consoleSettingsService.js +0 -40
- package/src/server/consoleSettings/registerConsoleSettings.js +0 -56
- package/src/server/registerWorkspaceBootstrap.js +0 -27
- package/src/server/registerWorkspaceCore.js +0 -73
- package/src/server/registerWorkspaceRepositories.js +0 -26
- package/src/server/support/resolveWorkspace.js +0 -16
- package/src/server/support/workspaceActionSurfaces.js +0 -135
- package/src/server/support/workspaceInvitationsPolicy.js +0 -45
- package/src/server/support/workspaceRouteInput.js +0 -22
- package/src/server/workspaceBootstrapContributor.js +0 -211
- package/src/server/workspaceDirectory/bootWorkspaceDirectoryRoutes.js +0 -133
- package/src/server/workspaceDirectory/registerWorkspaceDirectory.js +0 -19
- package/src/server/workspaceDirectory/workspaceDirectoryActions.js +0 -133
- package/src/server/workspaceMembers/bootWorkspaceMembers.js +0 -236
- package/src/server/workspaceMembers/registerWorkspaceMembers.js +0 -108
- package/src/server/workspaceMembers/workspaceMembersActions.js +0 -186
- package/src/server/workspaceMembers/workspaceMembersService.js +0 -222
- package/src/server/workspacePendingInvitations/bootWorkspacePendingInvitations.js +0 -62
- package/src/server/workspacePendingInvitations/registerWorkspacePendingInvitations.js +0 -119
- package/src/server/workspacePendingInvitations/workspacePendingInvitationsActions.js +0 -74
- package/src/server/workspacePendingInvitations/workspacePendingInvitationsService.js +0 -138
- package/src/server/workspaceSettings/bootWorkspaceSettings.js +0 -76
- package/src/server/workspaceSettings/registerWorkspaceSettings.js +0 -62
- package/src/server/workspaceSettings/workspaceSettingsActions.js +0 -72
- package/src/server/workspaceSettings/workspaceSettingsRepository.js +0 -154
- package/src/server/workspaceSettings/workspaceSettingsService.js +0 -66
- package/src/shared/resources/consoleSettingsFields.js +0 -54
- package/src/shared/resources/consoleSettingsResource.js +0 -119
- package/src/shared/resources/workspaceMembersResource.js +0 -354
- package/src/shared/resources/workspacePendingInvitationsResource.js +0 -82
- package/src/shared/resources/workspaceResource.js +0 -176
- package/src/shared/resources/workspaceSettingsFields.js +0 -59
- package/src/shared/resources/workspaceSettingsResource.js +0 -169
- package/src/shared/roles.js +0 -161
- package/src/shared/support/usersApiPaths.js +0 -43
- package/src/shared/support/usersVisibility.js +0 -42
- package/src/shared/support/workspacePathModel.js +0 -145
- package/src/shared/tenancyMode.js +0 -35
- package/src/shared/tenancyProfile.js +0 -73
- package/templates/migrations/users_core_console_owner.cjs +0 -37
- package/templates/packages/main/src/shared/resources/consoleSettingsFields.js +0 -11
- package/test/consoleService.test.js +0 -57
- package/test/consoleSettingsService.test.js +0 -86
- package/test/registerWorkspaceDirectory.test.js +0 -31
- package/test/registerWorkspaceSettings.test.js +0 -40
- package/test/roles.test.js +0 -159
- package/test/tenancyProfile.test.js +0 -67
- package/test/usersApiPaths.test.js +0 -49
- package/test/usersRouteValidators.test.js +0 -49
- package/test/usersVisibility.test.js +0 -27
- package/test/workspaceActionContextContributor.test.js +0 -344
- package/test/workspaceActionSurfaces.test.js +0 -105
- package/test/workspaceAuthPolicyContextResolver.test.js +0 -119
- package/test/workspaceBootstrapContributor.test.js +0 -154
- package/test/workspaceInvitationsPolicy.test.js +0 -71
- package/test/workspaceInvitesRepository.test.js +0 -111
- package/test/workspaceMembersService.test.js +0 -398
- package/test/workspacePathModel.test.js +0 -93
- package/test/workspacePendingInvitationsResource.test.js +0 -38
- package/test/workspacePendingInvitationsService.test.js +0 -151
- package/test/workspaceRouteVisibilityResolver.test.js +0 -83
- package/test/workspaceService.test.js +0 -546
- package/test/workspaceSettingsActions.test.js +0 -52
- package/test/workspaceSettingsRepository.test.js +0 -202
- package/test/workspaceSettingsResource.test.js +0 -169
- package/test/workspaceSettingsService.test.js +0 -140
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { Type } from "typebox";
|
|
2
|
-
import { createOperationMessages } from "../operationMessages.js";
|
|
3
|
-
import {
|
|
4
|
-
createCursorListValidator,
|
|
5
|
-
normalizeObjectInput,
|
|
6
|
-
normalizeSettingsFieldInput,
|
|
7
|
-
normalizeSettingsFieldOutput
|
|
8
|
-
} from "@jskit-ai/kernel/shared/validators";
|
|
9
|
-
import { consoleSettingsFields } from "./consoleSettingsFields.js";
|
|
10
|
-
|
|
11
|
-
function buildCreateSchema() {
|
|
12
|
-
const properties = {};
|
|
13
|
-
for (const field of consoleSettingsFields) {
|
|
14
|
-
properties[field.key] = field.required === false ? Type.Optional(field.inputSchema) : field.inputSchema;
|
|
15
|
-
}
|
|
16
|
-
return Type.Object(properties, { additionalProperties: false });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function buildOutputSchema() {
|
|
20
|
-
const properties = {};
|
|
21
|
-
for (const field of consoleSettingsFields) {
|
|
22
|
-
properties[field.key] = field.outputSchema;
|
|
23
|
-
}
|
|
24
|
-
return Type.Object(properties, { additionalProperties: false });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function buildConsoleSettingsRecordSchema() {
|
|
28
|
-
return Type.Object(
|
|
29
|
-
{
|
|
30
|
-
settings: buildOutputSchema()
|
|
31
|
-
},
|
|
32
|
-
{ additionalProperties: false }
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function buildConsoleSettingsCreateSchema() {
|
|
37
|
-
return buildCreateSchema();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function buildConsoleSettingsReplaceSchema() {
|
|
41
|
-
return buildConsoleSettingsCreateSchema();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function buildConsoleSettingsPatchSchema() {
|
|
45
|
-
return Type.Partial(buildConsoleSettingsCreateSchema(), {
|
|
46
|
-
additionalProperties: false
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function normalizeConsoleSettingsInput(payload = {}) {
|
|
51
|
-
return normalizeSettingsFieldInput(payload, consoleSettingsFields);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const consoleSettingsOutputValidator = Object.freeze({
|
|
55
|
-
get schema() {
|
|
56
|
-
return buildConsoleSettingsRecordSchema();
|
|
57
|
-
},
|
|
58
|
-
normalize(payload = {}) {
|
|
59
|
-
const source = normalizeObjectInput(payload);
|
|
60
|
-
const settingsSource = normalizeObjectInput(source.settings);
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
settings: normalizeSettingsFieldOutput(settingsSource, consoleSettingsFields)
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const CONSOLE_SETTINGS_OPERATION_MESSAGES = createOperationMessages();
|
|
69
|
-
|
|
70
|
-
const consoleSettingsResource = Object.freeze({
|
|
71
|
-
resource: "consoleSettings",
|
|
72
|
-
operations: Object.freeze({
|
|
73
|
-
view: Object.freeze({
|
|
74
|
-
method: "GET",
|
|
75
|
-
messages: CONSOLE_SETTINGS_OPERATION_MESSAGES,
|
|
76
|
-
outputValidator: consoleSettingsOutputValidator
|
|
77
|
-
}),
|
|
78
|
-
list: Object.freeze({
|
|
79
|
-
method: "GET",
|
|
80
|
-
messages: CONSOLE_SETTINGS_OPERATION_MESSAGES,
|
|
81
|
-
outputValidator: createCursorListValidator(consoleSettingsOutputValidator)
|
|
82
|
-
}),
|
|
83
|
-
create: Object.freeze({
|
|
84
|
-
method: "POST",
|
|
85
|
-
messages: CONSOLE_SETTINGS_OPERATION_MESSAGES,
|
|
86
|
-
bodyValidator: Object.freeze({
|
|
87
|
-
get schema() {
|
|
88
|
-
return buildConsoleSettingsCreateSchema();
|
|
89
|
-
},
|
|
90
|
-
normalize: normalizeConsoleSettingsInput
|
|
91
|
-
}),
|
|
92
|
-
outputValidator: consoleSettingsOutputValidator
|
|
93
|
-
}),
|
|
94
|
-
replace: Object.freeze({
|
|
95
|
-
method: "PUT",
|
|
96
|
-
messages: CONSOLE_SETTINGS_OPERATION_MESSAGES,
|
|
97
|
-
bodyValidator: Object.freeze({
|
|
98
|
-
get schema() {
|
|
99
|
-
return buildConsoleSettingsReplaceSchema();
|
|
100
|
-
},
|
|
101
|
-
normalize: normalizeConsoleSettingsInput
|
|
102
|
-
}),
|
|
103
|
-
outputValidator: consoleSettingsOutputValidator
|
|
104
|
-
}),
|
|
105
|
-
patch: Object.freeze({
|
|
106
|
-
method: "PATCH",
|
|
107
|
-
messages: CONSOLE_SETTINGS_OPERATION_MESSAGES,
|
|
108
|
-
bodyValidator: Object.freeze({
|
|
109
|
-
get schema() {
|
|
110
|
-
return buildConsoleSettingsPatchSchema();
|
|
111
|
-
},
|
|
112
|
-
normalize: normalizeConsoleSettingsInput
|
|
113
|
-
}),
|
|
114
|
-
outputValidator: consoleSettingsOutputValidator
|
|
115
|
-
})
|
|
116
|
-
})
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
export { consoleSettingsResource };
|
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { Type } from "@fastify/type-provider-typebox";
|
|
2
|
-
import { normalizeLowerText, normalizeText } from "@jskit-ai/kernel/shared/actions/textNormalization";
|
|
3
|
-
import {
|
|
4
|
-
normalizeObjectInput,
|
|
5
|
-
recordIdSchema,
|
|
6
|
-
recordIdInputSchema,
|
|
7
|
-
nullableRecordIdSchema
|
|
8
|
-
} from "@jskit-ai/kernel/shared/validators";
|
|
9
|
-
import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
|
|
10
|
-
import { createOperationMessages } from "../operationMessages.js";
|
|
11
|
-
import { createWorkspaceRoleCatalog, OWNER_ROLE_ID } from "../roles.js";
|
|
12
|
-
|
|
13
|
-
const workspaceSummaryOutputSchema = Type.Object(
|
|
14
|
-
{
|
|
15
|
-
id: recordIdSchema,
|
|
16
|
-
slug: Type.String({ minLength: 1 }),
|
|
17
|
-
name: Type.String({ minLength: 1 }),
|
|
18
|
-
ownerUserId: recordIdSchema,
|
|
19
|
-
avatarUrl: Type.String()
|
|
20
|
-
},
|
|
21
|
-
{ additionalProperties: false }
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const memberSummaryOutputSchema = Type.Object(
|
|
25
|
-
{
|
|
26
|
-
userId: recordIdSchema,
|
|
27
|
-
roleSid: Type.String({ minLength: 1 }),
|
|
28
|
-
status: Type.String({ minLength: 1 }),
|
|
29
|
-
displayName: Type.String(),
|
|
30
|
-
email: Type.String({ minLength: 1 }),
|
|
31
|
-
isOwner: Type.Boolean()
|
|
32
|
-
},
|
|
33
|
-
{ additionalProperties: false }
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const inviteSummaryOutputSchema = Type.Object(
|
|
37
|
-
{
|
|
38
|
-
id: recordIdSchema,
|
|
39
|
-
email: Type.String({ minLength: 3, format: "email" }),
|
|
40
|
-
roleSid: Type.String({ minLength: 1 }),
|
|
41
|
-
status: Type.String({ minLength: 1 }),
|
|
42
|
-
expiresAt: Type.String({ minLength: 1 }),
|
|
43
|
-
invitedByUserId: nullableRecordIdSchema
|
|
44
|
-
},
|
|
45
|
-
{ additionalProperties: false }
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
function normalizeWorkspaceAdminSummary(workspace) {
|
|
49
|
-
const source = normalizeObjectInput(workspace);
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
id: normalizeRecordId(source.id, { fallback: "" }),
|
|
53
|
-
slug: normalizeText(source.slug),
|
|
54
|
-
name: normalizeText(source.name),
|
|
55
|
-
ownerUserId: normalizeRecordId(source.ownerUserId, { fallback: "" }),
|
|
56
|
-
avatarUrl: normalizeText(source.avatarUrl)
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function normalizeMemberSummary(member, workspace) {
|
|
61
|
-
const source = normalizeObjectInput(member);
|
|
62
|
-
const userId = normalizeRecordId(source.userId, { fallback: "" });
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
userId,
|
|
66
|
-
roleSid: normalizeLowerText(source.roleSid || "member") || "member",
|
|
67
|
-
status: normalizeLowerText(source.status || "active") || "active",
|
|
68
|
-
displayName: normalizeText(source.displayName),
|
|
69
|
-
email: normalizeLowerText(source.email),
|
|
70
|
-
isOwner: userId === workspace.ownerUserId || normalizeLowerText(source.roleSid) === OWNER_ROLE_ID
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function normalizeInviteSummary(invite) {
|
|
75
|
-
const source = normalizeObjectInput(invite);
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
id: normalizeRecordId(source.id, { fallback: "" }),
|
|
79
|
-
email: normalizeLowerText(source.email),
|
|
80
|
-
roleSid: normalizeLowerText(source.roleSid || "member") || "member",
|
|
81
|
-
status: normalizeLowerText(source.status || "pending") || "pending",
|
|
82
|
-
expiresAt: source.expiresAt,
|
|
83
|
-
invitedByUserId: source.invitedByUserId == null ? null : normalizeRecordId(source.invitedByUserId, { fallback: null })
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function normalizeWorkspaceOutputEnvelope(
|
|
88
|
-
payload = {},
|
|
89
|
-
{ itemsKey, normalizeItem, includeInviteTokenPreview = false } = {}
|
|
90
|
-
) {
|
|
91
|
-
const source = normalizeObjectInput(payload);
|
|
92
|
-
const workspace = normalizeWorkspaceAdminSummary(source.workspace);
|
|
93
|
-
const items = Array.isArray(source[itemsKey]) ? source[itemsKey] : [];
|
|
94
|
-
const roleCatalog = normalizeObjectInput(source.roleCatalog);
|
|
95
|
-
const hasRoleCatalog =
|
|
96
|
-
Array.isArray(roleCatalog.roles) &&
|
|
97
|
-
roleCatalog.roles.length > 0 &&
|
|
98
|
-
Array.isArray(roleCatalog.assignableRoleIds);
|
|
99
|
-
const normalized = {
|
|
100
|
-
workspace,
|
|
101
|
-
[itemsKey]: items.map((item) => normalizeItem(item, workspace)),
|
|
102
|
-
roleCatalog: hasRoleCatalog ? roleCatalog : createWorkspaceRoleCatalog()
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
if (includeInviteTokenPreview && Object.hasOwn(source, "inviteTokenPreview")) {
|
|
106
|
-
normalized.inviteTokenPreview = normalizeText(source.inviteTokenPreview);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return normalized;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function normalizeWorkspaceMembersOutput(payload = {}) {
|
|
113
|
-
return normalizeWorkspaceOutputEnvelope(payload, {
|
|
114
|
-
itemsKey: "members",
|
|
115
|
-
normalizeItem: normalizeMemberSummary
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function normalizeWorkspaceInvitesOutput(payload = {}) {
|
|
120
|
-
return normalizeWorkspaceOutputEnvelope(payload, {
|
|
121
|
-
itemsKey: "invites",
|
|
122
|
-
normalizeItem: normalizeInviteSummary,
|
|
123
|
-
includeInviteTokenPreview: true
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const workspaceRoleCatalogOutputValidator = Object.freeze({
|
|
128
|
-
schema: Type.Object(
|
|
129
|
-
{
|
|
130
|
-
collaborationEnabled: Type.Boolean(),
|
|
131
|
-
defaultInviteRole: Type.String(),
|
|
132
|
-
roles: Type.Array(Type.Object({}, { additionalProperties: true })),
|
|
133
|
-
assignableRoleIds: Type.Array(Type.String({ minLength: 1 }))
|
|
134
|
-
},
|
|
135
|
-
{ additionalProperties: true }
|
|
136
|
-
)
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
const workspaceMembersOutputValidator = Object.freeze({
|
|
140
|
-
schema: Type.Object(
|
|
141
|
-
{
|
|
142
|
-
workspace: workspaceSummaryOutputSchema,
|
|
143
|
-
members: Type.Array(memberSummaryOutputSchema),
|
|
144
|
-
roleCatalog: workspaceRoleCatalogOutputValidator.schema
|
|
145
|
-
},
|
|
146
|
-
{ additionalProperties: false }
|
|
147
|
-
),
|
|
148
|
-
normalize: normalizeWorkspaceMembersOutput
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
const workspaceInvitesOutputValidator = Object.freeze({
|
|
152
|
-
schema: Type.Object(
|
|
153
|
-
{
|
|
154
|
-
workspace: workspaceSummaryOutputSchema,
|
|
155
|
-
invites: Type.Array(inviteSummaryOutputSchema),
|
|
156
|
-
roleCatalog: workspaceRoleCatalogOutputValidator.schema,
|
|
157
|
-
inviteTokenPreview: Type.Optional(Type.String({ minLength: 1 }))
|
|
158
|
-
},
|
|
159
|
-
{ additionalProperties: false }
|
|
160
|
-
),
|
|
161
|
-
normalize: normalizeWorkspaceInvitesOutput
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
const updateMemberRoleBodyValidator = Object.freeze({
|
|
165
|
-
schema: Type.Object(
|
|
166
|
-
{
|
|
167
|
-
roleSid: Type.String({ minLength: 1 })
|
|
168
|
-
},
|
|
169
|
-
{ additionalProperties: false }
|
|
170
|
-
),
|
|
171
|
-
normalize(payload = {}) {
|
|
172
|
-
const source = normalizeObjectInput(payload);
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
roleSid: normalizeLowerText(source.roleSid)
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
const updateMemberRoleInputValidator = Object.freeze({
|
|
181
|
-
schema: Type.Object(
|
|
182
|
-
{
|
|
183
|
-
memberUserId: recordIdInputSchema,
|
|
184
|
-
roleSid: Type.String({ minLength: 1 })
|
|
185
|
-
},
|
|
186
|
-
{ additionalProperties: false }
|
|
187
|
-
),
|
|
188
|
-
normalize(payload = {}) {
|
|
189
|
-
const source = normalizeObjectInput(payload);
|
|
190
|
-
|
|
191
|
-
return {
|
|
192
|
-
memberUserId: normalizeRecordId(source.memberUserId, { fallback: "" }),
|
|
193
|
-
roleSid: normalizeLowerText(source.roleSid)
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
const removeMemberInputValidator = Object.freeze({
|
|
199
|
-
schema: Type.Object(
|
|
200
|
-
{
|
|
201
|
-
memberUserId: recordIdInputSchema
|
|
202
|
-
},
|
|
203
|
-
{ additionalProperties: false }
|
|
204
|
-
),
|
|
205
|
-
normalize(payload = {}) {
|
|
206
|
-
const source = normalizeObjectInput(payload);
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
memberUserId: normalizeRecordId(source.memberUserId, { fallback: "" })
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
const createInviteBodyValidator = Object.freeze({
|
|
215
|
-
schema: Type.Object(
|
|
216
|
-
{
|
|
217
|
-
email: Type.String({ minLength: 3, format: "email" }),
|
|
218
|
-
roleSid: Type.String({ minLength: 1 })
|
|
219
|
-
},
|
|
220
|
-
{ additionalProperties: false }
|
|
221
|
-
),
|
|
222
|
-
normalize(payload = {}) {
|
|
223
|
-
const source = normalizeObjectInput(payload);
|
|
224
|
-
|
|
225
|
-
return {
|
|
226
|
-
email: normalizeLowerText(source.email),
|
|
227
|
-
roleSid: normalizeLowerText(source.roleSid || "member") || "member"
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const revokeInviteInputValidator = Object.freeze({
|
|
233
|
-
schema: Type.Object(
|
|
234
|
-
{
|
|
235
|
-
inviteId: recordIdInputSchema
|
|
236
|
-
},
|
|
237
|
-
{ additionalProperties: false }
|
|
238
|
-
),
|
|
239
|
-
normalize(payload = {}) {
|
|
240
|
-
const source = normalizeObjectInput(payload);
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
inviteId: normalizeRecordId(source.inviteId, { fallback: "" })
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
const redeemInviteBodyValidator = Object.freeze({
|
|
249
|
-
schema: Type.Object(
|
|
250
|
-
{
|
|
251
|
-
token: Type.String({
|
|
252
|
-
minLength: 1,
|
|
253
|
-
messages: {
|
|
254
|
-
required: "Invite token is required.",
|
|
255
|
-
minLength: "Invite token is required.",
|
|
256
|
-
default: "Invite token is invalid."
|
|
257
|
-
}
|
|
258
|
-
}),
|
|
259
|
-
decision: Type.Union([Type.Literal("accept"), Type.Literal("refuse")], {
|
|
260
|
-
messages: {
|
|
261
|
-
required: "Decision is required.",
|
|
262
|
-
default: "Decision must be accept or refuse."
|
|
263
|
-
}
|
|
264
|
-
})
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
additionalProperties: false,
|
|
268
|
-
messages: {
|
|
269
|
-
additionalProperties: "Unexpected field."
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
),
|
|
273
|
-
normalize(payload = {}) {
|
|
274
|
-
const source = normalizeObjectInput(payload);
|
|
275
|
-
|
|
276
|
-
return {
|
|
277
|
-
token: normalizeText(source.token),
|
|
278
|
-
decision: normalizeLowerText(source.decision)
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
const redeemInviteOutputValidator = Object.freeze({
|
|
284
|
-
schema: Type.Object(
|
|
285
|
-
{
|
|
286
|
-
decision: Type.Union([Type.Literal("accepted"), Type.Literal("refused")])
|
|
287
|
-
},
|
|
288
|
-
{ additionalProperties: false }
|
|
289
|
-
),
|
|
290
|
-
normalize(payload = {}) {
|
|
291
|
-
const source = normalizeObjectInput(payload);
|
|
292
|
-
|
|
293
|
-
return {
|
|
294
|
-
decision: normalizeLowerText(source.decision)
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
const WORKSPACE_MEMBERS_MESSAGES = createOperationMessages();
|
|
300
|
-
|
|
301
|
-
const workspaceMembersResource = Object.freeze({
|
|
302
|
-
resource: "workspaceMembers",
|
|
303
|
-
messages: WORKSPACE_MEMBERS_MESSAGES,
|
|
304
|
-
operations: Object.freeze({
|
|
305
|
-
rolesList: Object.freeze({
|
|
306
|
-
method: "GET",
|
|
307
|
-
messages: WORKSPACE_MEMBERS_MESSAGES,
|
|
308
|
-
outputValidator: workspaceRoleCatalogOutputValidator
|
|
309
|
-
}),
|
|
310
|
-
membersList: Object.freeze({
|
|
311
|
-
method: "GET",
|
|
312
|
-
messages: WORKSPACE_MEMBERS_MESSAGES,
|
|
313
|
-
outputValidator: workspaceMembersOutputValidator
|
|
314
|
-
}),
|
|
315
|
-
updateMemberRole: Object.freeze({
|
|
316
|
-
method: "PATCH",
|
|
317
|
-
messages: WORKSPACE_MEMBERS_MESSAGES,
|
|
318
|
-
bodyValidator: updateMemberRoleBodyValidator,
|
|
319
|
-
inputValidator: updateMemberRoleInputValidator,
|
|
320
|
-
outputValidator: workspaceMembersOutputValidator
|
|
321
|
-
}),
|
|
322
|
-
removeMember: Object.freeze({
|
|
323
|
-
method: "DELETE",
|
|
324
|
-
messages: WORKSPACE_MEMBERS_MESSAGES,
|
|
325
|
-
inputValidator: removeMemberInputValidator,
|
|
326
|
-
outputValidator: workspaceMembersOutputValidator
|
|
327
|
-
}),
|
|
328
|
-
invitesList: Object.freeze({
|
|
329
|
-
method: "GET",
|
|
330
|
-
messages: WORKSPACE_MEMBERS_MESSAGES,
|
|
331
|
-
outputValidator: workspaceInvitesOutputValidator
|
|
332
|
-
}),
|
|
333
|
-
createInvite: Object.freeze({
|
|
334
|
-
method: "POST",
|
|
335
|
-
messages: WORKSPACE_MEMBERS_MESSAGES,
|
|
336
|
-
bodyValidator: createInviteBodyValidator,
|
|
337
|
-
outputValidator: workspaceInvitesOutputValidator
|
|
338
|
-
}),
|
|
339
|
-
revokeInvite: Object.freeze({
|
|
340
|
-
method: "DELETE",
|
|
341
|
-
messages: WORKSPACE_MEMBERS_MESSAGES,
|
|
342
|
-
inputValidator: revokeInviteInputValidator,
|
|
343
|
-
outputValidator: workspaceInvitesOutputValidator
|
|
344
|
-
}),
|
|
345
|
-
redeemInvite: Object.freeze({
|
|
346
|
-
method: "POST",
|
|
347
|
-
messages: WORKSPACE_MEMBERS_MESSAGES,
|
|
348
|
-
bodyValidator: redeemInviteBodyValidator,
|
|
349
|
-
outputValidator: redeemInviteOutputValidator
|
|
350
|
-
})
|
|
351
|
-
})
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
export { workspaceMembersResource };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { Type } from "@fastify/type-provider-typebox";
|
|
2
|
-
import { encodeInviteTokenHash } from "@jskit-ai/auth-core/shared/inviteTokens";
|
|
3
|
-
import { normalizeLowerText, normalizeText } from "@jskit-ai/kernel/shared/actions/textNormalization";
|
|
4
|
-
import { createOperationMessages } from "../operationMessages.js";
|
|
5
|
-
import { normalizeObjectInput, recordIdSchema } from "@jskit-ai/kernel/shared/validators";
|
|
6
|
-
import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
|
|
7
|
-
|
|
8
|
-
function normalizePendingInvite(invite) {
|
|
9
|
-
const id = normalizeRecordId(invite?.id, { fallback: null });
|
|
10
|
-
const workspaceId = normalizeRecordId(invite?.workspaceId, { fallback: null });
|
|
11
|
-
const tokenHash = normalizeText(invite?.tokenHash);
|
|
12
|
-
|
|
13
|
-
if (!id || !workspaceId || !tokenHash) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
id,
|
|
19
|
-
workspaceId,
|
|
20
|
-
workspaceSlug: normalizeText(invite?.workspaceSlug),
|
|
21
|
-
workspaceName: normalizeText(invite?.workspaceName || invite?.workspaceSlug),
|
|
22
|
-
workspaceAvatarUrl: normalizeText(invite?.workspaceAvatarUrl),
|
|
23
|
-
roleSid: normalizeLowerText(invite?.roleSid || "member") || "member",
|
|
24
|
-
status: normalizeLowerText(invite?.status || "pending") || "pending",
|
|
25
|
-
expiresAt: invite?.expiresAt || null,
|
|
26
|
-
token: encodeInviteTokenHash(tokenHash)
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function normalizePendingInviteList(invites) {
|
|
31
|
-
return (Array.isArray(invites) ? invites : []).map((invite) => normalizePendingInvite(invite)).filter(Boolean);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const pendingInviteRecordValidator = Object.freeze({
|
|
35
|
-
schema: Type.Object(
|
|
36
|
-
{
|
|
37
|
-
id: recordIdSchema,
|
|
38
|
-
workspaceId: recordIdSchema,
|
|
39
|
-
workspaceSlug: Type.String({ minLength: 1 }),
|
|
40
|
-
workspaceName: Type.String({ minLength: 1 }),
|
|
41
|
-
workspaceAvatarUrl: Type.String(),
|
|
42
|
-
roleSid: Type.String({ minLength: 1 }),
|
|
43
|
-
status: Type.String({ minLength: 1 }),
|
|
44
|
-
expiresAt: Type.Union([Type.String({ minLength: 1 }), Type.Null()]),
|
|
45
|
-
token: Type.String({ minLength: 1 })
|
|
46
|
-
},
|
|
47
|
-
{ additionalProperties: false }
|
|
48
|
-
),
|
|
49
|
-
normalize: normalizePendingInvite
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const pendingInvitationsListOutputValidator = Object.freeze({
|
|
53
|
-
schema: Type.Object(
|
|
54
|
-
{
|
|
55
|
-
pendingInvites: Type.Array(pendingInviteRecordValidator.schema)
|
|
56
|
-
},
|
|
57
|
-
{ additionalProperties: false }
|
|
58
|
-
),
|
|
59
|
-
normalize(payload = {}) {
|
|
60
|
-
const source = normalizeObjectInput(payload);
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
pendingInvites: normalizePendingInviteList(source.pendingInvites)
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const WORKSPACE_PENDING_INVITATIONS_MESSAGES = createOperationMessages();
|
|
69
|
-
|
|
70
|
-
const workspacePendingInvitationsResource = Object.freeze({
|
|
71
|
-
resource: "workspacePendingInvitations",
|
|
72
|
-
messages: WORKSPACE_PENDING_INVITATIONS_MESSAGES,
|
|
73
|
-
operations: Object.freeze({
|
|
74
|
-
list: Object.freeze({
|
|
75
|
-
method: "GET",
|
|
76
|
-
messages: WORKSPACE_PENDING_INVITATIONS_MESSAGES,
|
|
77
|
-
outputValidator: pendingInvitationsListOutputValidator
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
export { workspacePendingInvitationsResource };
|