@jskit-ai/workspaces-core 0.1.31 → 0.1.33

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.
Files changed (62) hide show
  1. package/package.descriptor.mjs +11 -22
  2. package/package.json +11 -9
  3. package/src/server/WorkspacesCoreServiceProvider.js +22 -2
  4. package/src/server/common/repositories/workspaceInvitesRepository.js +233 -78
  5. package/src/server/common/repositories/workspaceMembershipsRepository.js +177 -86
  6. package/src/server/common/repositories/workspacesRepository.js +179 -86
  7. package/src/server/common/services/workspaceContextService.js +28 -26
  8. package/src/server/common/validators/routeParamsValidator.js +36 -53
  9. package/src/server/registerWorkspaceCore.js +9 -10
  10. package/src/server/registerWorkspaceRepositories.js +7 -3
  11. package/src/server/support/workspaceServerScopeSupport.js +1 -1
  12. package/src/server/workspaceBootstrapContributor.js +5 -14
  13. package/src/server/workspaceDirectory/bootWorkspaceDirectoryRoutes.js +54 -27
  14. package/src/server/workspaceDirectory/workspaceDirectoryActions.js +30 -24
  15. package/src/server/workspaceMembers/bootWorkspaceMembers.js +70 -32
  16. package/src/server/workspaceMembers/workspaceMembersActions.js +61 -27
  17. package/src/server/workspaceMembers/workspaceMembersService.js +43 -7
  18. package/src/server/workspacePendingInvitations/bootWorkspacePendingInvitations.js +28 -13
  19. package/src/server/workspacePendingInvitations/workspacePendingInvitationsActions.js +13 -15
  20. package/src/server/workspacePendingInvitations/workspacePendingInvitationsService.js +33 -10
  21. package/src/server/workspaceSettings/bootWorkspaceSettings.js +32 -13
  22. package/src/server/workspaceSettings/registerWorkspaceSettings.js +5 -1
  23. package/src/server/workspaceSettings/workspaceSettingsActions.js +18 -12
  24. package/src/server/workspaceSettings/workspaceSettingsRepository.js +104 -91
  25. package/src/server/workspaceSettings/workspaceSettingsService.js +5 -6
  26. package/src/shared/jsonApiTransports.js +79 -0
  27. package/src/shared/resources/workspaceInvitesResource.js +158 -0
  28. package/src/shared/resources/workspaceMembersResource.js +176 -311
  29. package/src/shared/resources/workspaceMembershipsResource.js +96 -0
  30. package/src/shared/resources/workspacePendingInvitationsResource.js +25 -72
  31. package/src/shared/resources/workspaceResource.js +113 -144
  32. package/src/shared/resources/workspaceRoleCatalogSchema.js +31 -0
  33. package/src/shared/resources/workspaceSettingsResource.js +276 -148
  34. package/test/repositoryContracts.test.js +16 -4
  35. package/test/resourcesCanonical.test.js +39 -16
  36. package/test/routeParamsValidator.test.js +37 -19
  37. package/test/usersRouteResources.test.js +27 -17
  38. package/test/workspaceActionContextContributor.test.js +1 -1
  39. package/test/workspaceInternalCrudResources.test.js +98 -0
  40. package/test/workspaceInvitesRepository.test.js +196 -148
  41. package/test/workspaceMembersResource.test.js +35 -0
  42. package/test/workspaceMembershipsRepository.test.js +155 -115
  43. package/test/workspacePendingInvitationsResource.test.js +18 -23
  44. package/test/workspacePendingInvitationsService.test.js +2 -1
  45. package/test/workspaceServerScopeSupport.test.js +77 -3
  46. package/test/workspaceService.test.js +26 -5
  47. package/test/workspaceSettingsActions.test.js +5 -7
  48. package/test/workspaceSettingsInternalResource.test.js +8 -0
  49. package/test/workspaceSettingsRepository.test.js +158 -123
  50. package/test/workspaceSettingsResource.test.js +51 -62
  51. package/test/workspaceSettingsService.test.js +0 -1
  52. package/test/workspacesRepository.test.js +318 -174
  53. package/test/workspacesRouteRequestInputValidator.test.js +25 -11
  54. package/src/server/common/resources/workspaceInvitesResource.js +0 -207
  55. package/src/server/common/resources/workspaceMembershipsResource.js +0 -154
  56. package/src/server/common/resources/workspacesResource.js +0 -170
  57. package/src/server/common/validators/authenticatedUserValidator.js +0 -43
  58. package/src/shared/resources/resolveGlobalArrayRegistry.js +0 -6
  59. package/src/shared/resources/workspaceSettingsFields.js +0 -65
  60. package/templates/packages/main/src/shared/resources/workspaceSettingsFields.js +0 -197
  61. package/test/settingsFieldRegistriesSingleton.test.js +0 -14
  62. package/test-support/registerDefaultSettingsFields.js +0 -1
@@ -1,207 +0,0 @@
1
- import { Type } from "typebox";
2
- import {
3
- createCursorListValidator,
4
- normalizeObjectInput,
5
- recordIdInputSchema,
6
- recordIdSchema
7
- } from "@jskit-ai/kernel/shared/validators";
8
- import {
9
- normalizeIfPresent,
10
- normalizeLowerText,
11
- normalizeRecordId,
12
- normalizeText,
13
- normalizeOrNull
14
- } from "@jskit-ai/kernel/shared/support/normalize";
15
- import { normalizeDbRecordId, toIsoString, toNullableDateTime } from "@jskit-ai/database-runtime/shared";
16
-
17
- function normalizeInviteRecord(payload = {}) {
18
- const source = normalizeObjectInput(payload);
19
-
20
- return {
21
- id: normalizeIfPresent(source.id, (value) => normalizeDbRecordId(value, { fallback: null })),
22
- workspaceId: normalizeIfPresent(
23
- source.workspaceId ?? source.workspace_id,
24
- (value) => normalizeDbRecordId(value, { fallback: null })
25
- ),
26
- email: normalizeLowerText(source.email),
27
- roleSid: normalizeLowerText(source.roleSid ?? source.role_sid ?? "member") || "member",
28
- status: normalizeLowerText(source.status ?? "pending") || "pending",
29
- tokenHash: normalizeText(source.tokenHash ?? source.token_hash),
30
- invitedByUserId: normalizeOrNull(
31
- source.invitedByUserId ?? source.invited_by_user_id,
32
- (value) => normalizeDbRecordId(value, { fallback: null })
33
- ),
34
- expiresAt: normalizeOrNull(source.expiresAt ?? source.expires_at, toIsoString),
35
- acceptedAt: normalizeOrNull(source.acceptedAt ?? source.accepted_at, toIsoString),
36
- revokedAt: normalizeOrNull(source.revokedAt ?? source.revoked_at, toIsoString),
37
- createdAt: normalizeIfPresent(source.createdAt ?? source.created_at, toIsoString),
38
- updatedAt: normalizeIfPresent(source.updatedAt ?? source.updated_at, toIsoString)
39
- };
40
- }
41
-
42
- function normalizeInviteInput(payload = {}) {
43
- const source = normalizeObjectInput(payload);
44
- const normalized = {};
45
-
46
- if (Object.hasOwn(source, "workspaceId")) {
47
- normalized.workspaceId = normalizeRecordId(source.workspaceId, { fallback: "" });
48
- }
49
- if (Object.hasOwn(source, "email")) {
50
- normalized.email = normalizeLowerText(source.email);
51
- }
52
- if (Object.hasOwn(source, "roleSid")) {
53
- normalized.roleSid = normalizeLowerText(source.roleSid);
54
- }
55
- if (Object.hasOwn(source, "status")) {
56
- normalized.status = normalizeLowerText(source.status);
57
- }
58
- if (Object.hasOwn(source, "tokenHash")) {
59
- normalized.tokenHash = normalizeText(source.tokenHash);
60
- }
61
- if (Object.hasOwn(source, "invitedByUserId")) {
62
- normalized.invitedByUserId =
63
- source.invitedByUserId == null
64
- ? null
65
- : normalizeRecordId(source.invitedByUserId, { fallback: null });
66
- }
67
- if (Object.hasOwn(source, "expiresAt")) {
68
- normalized.expiresAt = toNullableDateTime(source.expiresAt);
69
- }
70
- if (Object.hasOwn(source, "acceptedAt")) {
71
- normalized.acceptedAt = toNullableDateTime(source.acceptedAt);
72
- }
73
- if (Object.hasOwn(source, "revokedAt")) {
74
- normalized.revokedAt = toNullableDateTime(source.revokedAt);
75
- }
76
-
77
- return normalized;
78
- }
79
-
80
- const recordOutputSchema = Type.Object(
81
- {
82
- id: recordIdSchema,
83
- workspaceId: recordIdSchema,
84
- email: Type.String({ minLength: 1 }),
85
- roleSid: Type.String({ minLength: 1 }),
86
- status: Type.String({ minLength: 1 }),
87
- tokenHash: Type.String({ minLength: 1 }),
88
- invitedByUserId: Type.Union([recordIdSchema, Type.Null()]),
89
- expiresAt: Type.Union([Type.String({ format: "date-time", minLength: 1 }), Type.Null()]),
90
- acceptedAt: Type.Union([Type.String({ format: "date-time", minLength: 1 }), Type.Null()]),
91
- revokedAt: Type.Union([Type.String({ format: "date-time", minLength: 1 }), Type.Null()]),
92
- createdAt: Type.String({ format: "date-time", minLength: 1 }),
93
- updatedAt: Type.String({ format: "date-time", minLength: 1 })
94
- },
95
- { additionalProperties: false }
96
- );
97
-
98
- const createBodySchema = Type.Object(
99
- {
100
- workspaceId: recordIdInputSchema,
101
- email: Type.String({ minLength: 1, maxLength: 255 }),
102
- tokenHash: Type.String({ minLength: 1, maxLength: 255 }),
103
- roleSid: Type.Optional(Type.String({ minLength: 1, maxLength: 64 })),
104
- status: Type.Optional(Type.String({ minLength: 1, maxLength: 64 })),
105
- invitedByUserId: Type.Optional(Type.Union([recordIdInputSchema, Type.Null()])),
106
- expiresAt: Type.Optional(Type.Union([Type.String({ format: "date-time", minLength: 1 }), Type.Null()]))
107
- },
108
- {
109
- additionalProperties: false,
110
- required: []
111
- }
112
- );
113
-
114
- const patchBodySchema = Type.Object(
115
- {
116
- roleSid: Type.Optional(Type.String({ minLength: 1, maxLength: 64 })),
117
- status: Type.Optional(Type.String({ minLength: 1, maxLength: 64 })),
118
- invitedByUserId: Type.Optional(Type.Union([recordIdInputSchema, Type.Null()])),
119
- expiresAt: Type.Optional(Type.Union([Type.String({ format: "date-time", minLength: 1 }), Type.Null()])),
120
- acceptedAt: Type.Optional(Type.Union([Type.String({ format: "date-time", minLength: 1 }), Type.Null()])),
121
- revokedAt: Type.Optional(Type.Union([Type.String({ format: "date-time", minLength: 1 }), Type.Null()]))
122
- },
123
- {
124
- additionalProperties: false
125
- }
126
- );
127
-
128
- const recordOutputValidator = Object.freeze({
129
- schema: recordOutputSchema,
130
- normalize: normalizeInviteRecord
131
- });
132
-
133
- const createBodyValidator = Object.freeze({
134
- schema: createBodySchema,
135
- normalize: normalizeInviteInput
136
- });
137
-
138
- const patchBodyValidator = Object.freeze({
139
- schema: patchBodySchema,
140
- normalize: normalizeInviteInput
141
- });
142
-
143
- const workspaceInvitesResource = Object.freeze({
144
- namespace: "workspaceInvites",
145
- tableName: "workspace_invites",
146
- idColumn: "id",
147
- operations: Object.freeze({
148
- list: Object.freeze({
149
- method: "GET",
150
- outputValidator: createCursorListValidator(recordOutputValidator)
151
- }),
152
- view: Object.freeze({
153
- method: "GET",
154
- outputValidator: recordOutputValidator
155
- }),
156
- create: Object.freeze({
157
- method: "POST",
158
- bodyValidator: createBodyValidator,
159
- outputValidator: recordOutputValidator
160
- }),
161
- patch: Object.freeze({
162
- method: "PATCH",
163
- bodyValidator: patchBodyValidator,
164
- outputValidator: recordOutputValidator
165
- })
166
- }),
167
- fieldMeta: Object.freeze([
168
- Object.freeze({
169
- key: "workspaceId",
170
- repository: { column: "workspace_id" }
171
- }),
172
- Object.freeze({
173
- key: "roleSid",
174
- repository: { column: "role_sid" }
175
- }),
176
- Object.freeze({
177
- key: "tokenHash",
178
- repository: { column: "token_hash" }
179
- }),
180
- Object.freeze({
181
- key: "invitedByUserId",
182
- repository: { column: "invited_by_user_id" }
183
- }),
184
- Object.freeze({
185
- key: "expiresAt",
186
- repository: { column: "expires_at" }
187
- }),
188
- Object.freeze({
189
- key: "acceptedAt",
190
- repository: { column: "accepted_at" }
191
- }),
192
- Object.freeze({
193
- key: "revokedAt",
194
- repository: { column: "revoked_at" }
195
- }),
196
- Object.freeze({
197
- key: "createdAt",
198
- repository: { column: "created_at" }
199
- }),
200
- Object.freeze({
201
- key: "updatedAt",
202
- repository: { column: "updated_at" }
203
- })
204
- ])
205
- });
206
-
207
- export { workspaceInvitesResource };
@@ -1,154 +0,0 @@
1
- import { Type } from "typebox";
2
- import {
3
- createCursorListValidator,
4
- normalizeObjectInput,
5
- recordIdInputSchema,
6
- recordIdSchema
7
- } from "@jskit-ai/kernel/shared/validators";
8
- import {
9
- normalizeIfPresent,
10
- normalizeLowerText,
11
- normalizeRecordId
12
- } from "@jskit-ai/kernel/shared/support/normalize";
13
- import { normalizeDbRecordId, toIsoString } from "@jskit-ai/database-runtime/shared";
14
-
15
- function normalizeMembershipRecord(payload = {}) {
16
- const source = normalizeObjectInput(payload);
17
-
18
- return {
19
- id: normalizeIfPresent(source.id, (value) => normalizeDbRecordId(value, { fallback: null })),
20
- workspaceId: normalizeIfPresent(
21
- source.workspaceId ?? source.workspace_id,
22
- (value) => normalizeDbRecordId(value, { fallback: null })
23
- ),
24
- userId: normalizeIfPresent(
25
- source.userId ?? source.user_id,
26
- (value) => normalizeDbRecordId(value, { fallback: null })
27
- ),
28
- roleSid: normalizeLowerText(source.roleSid ?? source.role_sid ?? "member") || "member",
29
- status: normalizeLowerText(source.status ?? "active") || "active",
30
- createdAt: normalizeIfPresent(source.createdAt ?? source.created_at, toIsoString),
31
- updatedAt: normalizeIfPresent(source.updatedAt ?? source.updated_at, toIsoString)
32
- };
33
- }
34
-
35
- function normalizeMembershipInput(payload = {}) {
36
- const source = normalizeObjectInput(payload);
37
- const normalized = {};
38
-
39
- if (Object.hasOwn(source, "workspaceId")) {
40
- normalized.workspaceId = normalizeRecordId(source.workspaceId, { fallback: "" });
41
- }
42
- if (Object.hasOwn(source, "userId")) {
43
- normalized.userId = normalizeRecordId(source.userId, { fallback: "" });
44
- }
45
- if (Object.hasOwn(source, "roleSid")) {
46
- normalized.roleSid = normalizeLowerText(source.roleSid);
47
- }
48
- if (Object.hasOwn(source, "status")) {
49
- normalized.status = normalizeLowerText(source.status);
50
- }
51
-
52
- return normalized;
53
- }
54
-
55
- const recordOutputSchema = Type.Object(
56
- {
57
- id: recordIdSchema,
58
- workspaceId: recordIdSchema,
59
- userId: recordIdSchema,
60
- roleSid: Type.String({ minLength: 1 }),
61
- status: Type.String({ minLength: 1 }),
62
- createdAt: Type.String({ format: "date-time", minLength: 1 }),
63
- updatedAt: Type.String({ format: "date-time", minLength: 1 })
64
- },
65
- { additionalProperties: false }
66
- );
67
-
68
- const createBodySchema = Type.Object(
69
- {
70
- workspaceId: recordIdInputSchema,
71
- userId: recordIdInputSchema,
72
- roleSid: Type.Optional(Type.String({ minLength: 1, maxLength: 64 })),
73
- status: Type.Optional(Type.String({ minLength: 1, maxLength: 32 }))
74
- },
75
- {
76
- additionalProperties: false,
77
- required: []
78
- }
79
- );
80
-
81
- const patchBodySchema = Type.Object(
82
- {
83
- roleSid: Type.Optional(Type.String({ minLength: 1, maxLength: 64 })),
84
- status: Type.Optional(Type.String({ minLength: 1, maxLength: 32 }))
85
- },
86
- {
87
- additionalProperties: false
88
- }
89
- );
90
-
91
- const recordOutputValidator = Object.freeze({
92
- schema: recordOutputSchema,
93
- normalize: normalizeMembershipRecord
94
- });
95
-
96
- const createBodyValidator = Object.freeze({
97
- schema: createBodySchema,
98
- normalize: normalizeMembershipInput
99
- });
100
-
101
- const patchBodyValidator = Object.freeze({
102
- schema: patchBodySchema,
103
- normalize: normalizeMembershipInput
104
- });
105
-
106
- const workspaceMembershipsResource = Object.freeze({
107
- namespace: "workspaceMemberships",
108
- tableName: "workspace_memberships",
109
- idColumn: "id",
110
- operations: Object.freeze({
111
- list: Object.freeze({
112
- method: "GET",
113
- outputValidator: createCursorListValidator(recordOutputValidator)
114
- }),
115
- view: Object.freeze({
116
- method: "GET",
117
- outputValidator: recordOutputValidator
118
- }),
119
- create: Object.freeze({
120
- method: "POST",
121
- bodyValidator: createBodyValidator,
122
- outputValidator: recordOutputValidator
123
- }),
124
- patch: Object.freeze({
125
- method: "PATCH",
126
- bodyValidator: patchBodyValidator,
127
- outputValidator: recordOutputValidator
128
- })
129
- }),
130
- fieldMeta: Object.freeze([
131
- Object.freeze({
132
- key: "workspaceId",
133
- repository: { column: "workspace_id" }
134
- }),
135
- Object.freeze({
136
- key: "userId",
137
- repository: { column: "user_id" }
138
- }),
139
- Object.freeze({
140
- key: "roleSid",
141
- repository: { column: "role_sid" }
142
- }),
143
- Object.freeze({
144
- key: "createdAt",
145
- repository: { column: "created_at" }
146
- }),
147
- Object.freeze({
148
- key: "updatedAt",
149
- repository: { column: "updated_at" }
150
- })
151
- ])
152
- });
153
-
154
- export { workspaceMembershipsResource };
@@ -1,170 +0,0 @@
1
- import { Type } from "typebox";
2
- import {
3
- createCursorListValidator,
4
- normalizeObjectInput,
5
- recordIdInputSchema,
6
- recordIdSchema
7
- } from "@jskit-ai/kernel/shared/validators";
8
- import {
9
- normalizeBoolean,
10
- normalizeIfPresent,
11
- normalizeLowerText,
12
- normalizeRecordId,
13
- normalizeText,
14
- normalizeOrNull
15
- } from "@jskit-ai/kernel/shared/support/normalize";
16
- import { normalizeDbRecordId, toIsoString, toNullableDateTime } from "@jskit-ai/database-runtime/shared";
17
-
18
- function normalizeWorkspaceRecord(payload = {}) {
19
- const source = normalizeObjectInput(payload);
20
-
21
- return {
22
- id: normalizeIfPresent(source.id, (value) => normalizeDbRecordId(value, { fallback: null })),
23
- slug: normalizeLowerText(source.slug),
24
- name: normalizeText(source.name),
25
- ownerUserId: normalizeIfPresent(
26
- source.ownerUserId ?? source.owner_user_id,
27
- (value) => normalizeDbRecordId(value, { fallback: null })
28
- ),
29
- isPersonal: normalizeBoolean(source.isPersonal ?? source.is_personal),
30
- avatarUrl: normalizeText(source.avatarUrl ?? source.avatar_url),
31
- createdAt: normalizeIfPresent(source.createdAt ?? source.created_at, toIsoString),
32
- updatedAt: normalizeIfPresent(source.updatedAt ?? source.updated_at, toIsoString),
33
- deletedAt: normalizeOrNull(source.deletedAt ?? source.deleted_at, toIsoString)
34
- };
35
- }
36
-
37
- function normalizeWorkspaceInput(payload = {}) {
38
- const source = normalizeObjectInput(payload);
39
- const normalized = {};
40
-
41
- if (Object.hasOwn(source, "slug")) {
42
- normalized.slug = normalizeLowerText(source.slug);
43
- }
44
- if (Object.hasOwn(source, "name")) {
45
- normalized.name = normalizeText(source.name);
46
- }
47
- if (Object.hasOwn(source, "ownerUserId")) {
48
- normalized.ownerUserId = normalizeRecordId(source.ownerUserId, { fallback: "" });
49
- }
50
- if (Object.hasOwn(source, "isPersonal")) {
51
- normalized.isPersonal = normalizeBoolean(source.isPersonal);
52
- }
53
- if (Object.hasOwn(source, "avatarUrl")) {
54
- normalized.avatarUrl = normalizeText(source.avatarUrl);
55
- }
56
- if (Object.hasOwn(source, "deletedAt")) {
57
- normalized.deletedAt = toNullableDateTime(source.deletedAt);
58
- }
59
-
60
- return normalized;
61
- }
62
-
63
- const recordOutputSchema = Type.Object(
64
- {
65
- id: recordIdSchema,
66
- slug: Type.String({ minLength: 1 }),
67
- name: Type.String({ minLength: 1, maxLength: 160 }),
68
- ownerUserId: recordIdSchema,
69
- isPersonal: Type.Boolean(),
70
- avatarUrl: Type.String(),
71
- createdAt: Type.String({ format: "date-time", minLength: 1 }),
72
- updatedAt: Type.String({ format: "date-time", minLength: 1 }),
73
- deletedAt: Type.Union([Type.String({ format: "date-time", minLength: 1 }), Type.Null()])
74
- },
75
- { additionalProperties: false }
76
- );
77
-
78
- const createBodySchema = Type.Object(
79
- {
80
- slug: Type.String({ minLength: 1, maxLength: 120 }),
81
- name: Type.String({ minLength: 1, maxLength: 160 }),
82
- ownerUserId: recordIdInputSchema,
83
- isPersonal: Type.Optional(Type.Boolean()),
84
- avatarUrl: Type.Optional(Type.String({ maxLength: 512 }))
85
- },
86
- {
87
- additionalProperties: false,
88
- required: []
89
- }
90
- );
91
-
92
- const patchBodySchema = Type.Object(
93
- {
94
- name: Type.Optional(Type.String({ minLength: 1, maxLength: 160 })),
95
- avatarUrl: Type.Optional(Type.String({ maxLength: 512 })),
96
- deletedAt: Type.Optional(Type.Union([Type.String({ format: "date-time", minLength: 1 }), Type.Null()]))
97
- },
98
- {
99
- additionalProperties: false
100
- }
101
- );
102
-
103
- const recordOutputValidator = Object.freeze({
104
- schema: recordOutputSchema,
105
- normalize: normalizeWorkspaceRecord
106
- });
107
-
108
- const createBodyValidator = Object.freeze({
109
- schema: createBodySchema,
110
- normalize: normalizeWorkspaceInput
111
- });
112
-
113
- const patchBodyValidator = Object.freeze({
114
- schema: patchBodySchema,
115
- normalize: normalizeWorkspaceInput
116
- });
117
-
118
- const workspacesResource = Object.freeze({
119
- namespace: "workspaces",
120
- tableName: "workspaces",
121
- idColumn: "id",
122
- operations: Object.freeze({
123
- list: Object.freeze({
124
- method: "GET",
125
- outputValidator: createCursorListValidator(recordOutputValidator)
126
- }),
127
- view: Object.freeze({
128
- method: "GET",
129
- outputValidator: recordOutputValidator
130
- }),
131
- create: Object.freeze({
132
- method: "POST",
133
- bodyValidator: createBodyValidator,
134
- outputValidator: recordOutputValidator
135
- }),
136
- patch: Object.freeze({
137
- method: "PATCH",
138
- bodyValidator: patchBodyValidator,
139
- outputValidator: recordOutputValidator
140
- })
141
- }),
142
- fieldMeta: Object.freeze([
143
- Object.freeze({
144
- key: "ownerUserId",
145
- repository: { column: "owner_user_id" }
146
- }),
147
- Object.freeze({
148
- key: "isPersonal",
149
- repository: { column: "is_personal" }
150
- }),
151
- Object.freeze({
152
- key: "avatarUrl",
153
- repository: { column: "avatar_url" }
154
- }),
155
- Object.freeze({
156
- key: "createdAt",
157
- repository: { column: "created_at" }
158
- }),
159
- Object.freeze({
160
- key: "updatedAt",
161
- repository: { column: "updated_at" }
162
- }),
163
- Object.freeze({
164
- key: "deletedAt",
165
- repository: { column: "deleted_at" }
166
- })
167
- ])
168
- });
169
-
170
- export { workspacesResource };
@@ -1,43 +0,0 @@
1
- import { Type } from "@fastify/type-provider-typebox";
2
- import { normalizeObjectInput, recordIdInputSchema } from "@jskit-ai/kernel/shared/validators";
3
- import { normalizeLowerText, normalizeText } from "@jskit-ai/kernel/shared/actions/textNormalization";
4
- import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
5
-
6
- function normalizeAuthenticatedUser(input = {}) {
7
- const source = normalizeObjectInput(input);
8
- const id = normalizeRecordId(source.id, { fallback: null });
9
- if (!id) {
10
- return null;
11
- }
12
-
13
- const email = normalizeLowerText(source.email);
14
- return {
15
- id,
16
- email,
17
- username: normalizeLowerText(source.username),
18
- displayName: normalizeText(source.displayName) || email || `User ${id}`,
19
- authProvider: normalizeLowerText(source.authProvider),
20
- authProviderUserSid: normalizeText(source.authProviderUserSid),
21
- avatarStorageKey: source.avatarStorageKey ? normalizeText(source.avatarStorageKey) : null,
22
- avatarVersion: source.avatarVersion == null ? null : String(source.avatarVersion)
23
- };
24
- }
25
-
26
- const authenticatedUserValidator = Object.freeze({
27
- schema: Type.Object(
28
- {
29
- id: recordIdInputSchema,
30
- email: Type.String({ minLength: 1 }),
31
- username: Type.Optional(Type.String()),
32
- displayName: Type.Optional(Type.String()),
33
- authProvider: Type.Optional(Type.String()),
34
- authProviderUserSid: Type.Optional(Type.String()),
35
- avatarStorageKey: Type.Optional(Type.Union([Type.String(), Type.Null()])),
36
- avatarVersion: Type.Optional(Type.Union([Type.String(), Type.Number(), Type.Null()]))
37
- },
38
- { additionalProperties: true }
39
- ),
40
- normalize: normalizeAuthenticatedUser
41
- });
42
-
43
- export { authenticatedUserValidator };
@@ -1,6 +0,0 @@
1
- function resolveGlobalArrayRegistry(symbolKey) {
2
- globalThis[symbolKey] = Array.isArray(globalThis[symbolKey]) ? globalThis[symbolKey] : [];
3
- return globalThis[symbolKey];
4
- }
5
-
6
- export { resolveGlobalArrayRegistry };
@@ -1,65 +0,0 @@
1
- import { normalizeText } from "@jskit-ai/kernel/shared/actions/textNormalization";
2
- import { resolveGlobalArrayRegistry } from "./resolveGlobalArrayRegistry.js";
3
-
4
- const workspaceSettingsFields = resolveGlobalArrayRegistry("jskit.workspaces-core.workspaceSettingsFields");
5
-
6
- function defineField(field = {}) {
7
- const key = normalizeText(field.key);
8
- if (!key) {
9
- throw new TypeError("workspaceSettingsFields.defineField requires field.key.");
10
- }
11
- if (workspaceSettingsFields.some((entry) => entry.key === key)) {
12
- throw new Error(`workspaceSettingsFields.defineField duplicate key: ${key}`);
13
- }
14
- if (!field.inputSchema || typeof field.inputSchema !== "object") {
15
- throw new TypeError(`workspaceSettingsFields.defineField("${key}") requires inputSchema.`);
16
- }
17
- if (!field.outputSchema || typeof field.outputSchema !== "object") {
18
- throw new TypeError(`workspaceSettingsFields.defineField("${key}") requires outputSchema.`);
19
- }
20
- const repository = field?.repository;
21
- if (!repository || typeof repository !== "object" || Array.isArray(repository)) {
22
- throw new TypeError(`workspaceSettingsFields.defineField("${key}") requires repository.column.`);
23
- }
24
- const repositoryColumn = normalizeText(repository.column);
25
- if (!repositoryColumn) {
26
- throw new TypeError(`workspaceSettingsFields.defineField("${key}") requires repository.column.`);
27
- }
28
- if (typeof field.normalizeInput !== "function") {
29
- throw new TypeError(`workspaceSettingsFields.defineField("${key}") requires normalizeInput.`);
30
- }
31
- if (typeof field.normalizeOutput !== "function") {
32
- throw new TypeError(`workspaceSettingsFields.defineField("${key}") requires normalizeOutput.`);
33
- }
34
- if (typeof field.resolveDefault !== "function") {
35
- throw new TypeError(`workspaceSettingsFields.defineField("${key}") requires resolveDefault.`);
36
- }
37
-
38
- workspaceSettingsFields.push({
39
- key,
40
- repository: Object.freeze({
41
- column: repositoryColumn
42
- }),
43
- required: field.required !== false,
44
- inputSchema: field.inputSchema,
45
- outputSchema: field.outputSchema,
46
- normalizeInput: field.normalizeInput,
47
- normalizeOutput: field.normalizeOutput,
48
- resolveDefault: field.resolveDefault
49
- });
50
- }
51
-
52
- function resetWorkspaceSettingsFields() {
53
- workspaceSettingsFields.splice(0, workspaceSettingsFields.length);
54
- }
55
-
56
- function resolveWorkspaceSettingsFieldKeys() {
57
- return workspaceSettingsFields.map((field) => field.key);
58
- }
59
-
60
- export {
61
- defineField,
62
- resetWorkspaceSettingsFields,
63
- resolveWorkspaceSettingsFieldKeys,
64
- workspaceSettingsFields
65
- };