@jskit-ai/workspaces-core 0.2.23 → 0.2.25
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/CHANGELOG.md +8 -0
- package/locales/en.json +2 -1
- package/package.json +10 -10
- package/patterns/workspace-server/PATTERN.md +9 -0
- package/src/server/WorkspacesFeature.js +8 -2
- package/src/server/WorkspacesIntegrationsProvider.js +16 -3
- package/src/server/common/repositories/workspaceInvitesRepository.js +30 -0
- package/src/server/common/repositories/workspaceMemberPagesRepository.js +84 -0
- package/src/server/common/repositories/workspaceMembershipsRepository.js +43 -14
- package/src/server/common/services/workspaceDirectoryService.js +42 -27
- package/src/server/types.js +11 -0
- package/src/server/workspaceDirectory/noWorkspaceCreatedParticipant.js +9 -0
- package/src/server/workspaceMembers/workspaceMembersActions.js +22 -4
- package/src/server/workspaceMembers/workspaceMembersRoutes.js +8 -2
- package/src/server/workspaceMembers/workspaceMembersService.js +43 -12
- package/src/server/workspacesRuntime.js +8 -0
- package/src/shared/resources/workspaceMembersResource.js +15 -0
- package/test/featureRuntime.test.js +39 -0
- package/test/repositories.integration.test.js +147 -0
- package/test/roleLabels.test.js +7 -1
- package/test/support/mysqlWorkspaces.js +2 -0
- package/test/userAdministrationExample.mysql.test.js +98 -0
- package/test/workspaceDirectoryService.mysql.test.js +2 -0
- package/test/workspaceMembersService.mysql.test.js +62 -4
- package/test/workspaceMembersService.test.js +106 -56
- package/test/workspaceRecords.test.js +24 -0
- package/test/workspaceService.test.js +76 -4
|
@@ -3,9 +3,12 @@ import assert from "node:assert/strict";
|
|
|
3
3
|
import { createWorkspaceActionContextContributor } from "../src/server/common/contributors/workspaceActionContextContributor.js";
|
|
4
4
|
import { createWorkspaceAuthPolicyContextResolver } from "../src/server/common/contributors/workspaceAuthPolicyContextResolver.js";
|
|
5
5
|
import { buildWorkspaceName, createService } from "../src/server/common/services/workspaceDirectoryService.js";
|
|
6
|
+
import { noWorkspaceCreatedParticipant } from "../src/server/workspaceDirectory/noWorkspaceCreatedParticipant.js";
|
|
6
7
|
import { createWorkspaceRoleCatalog } from "../src/shared/roles.js";
|
|
7
8
|
import { resolveTenancyProfile } from "../src/shared/tenancyProfile.js";
|
|
8
9
|
|
|
10
|
+
const TEST_TRX = Object.freeze({ name: "the creation transaction" });
|
|
11
|
+
|
|
9
12
|
// The service receives what the workspaces feature resolves from its config.
|
|
10
13
|
function resolvedSettings(appConfig) {
|
|
11
14
|
return {
|
|
@@ -41,6 +44,7 @@ function createWorkspaceServiceFixture({
|
|
|
41
44
|
userWorkspaceRows = null,
|
|
42
45
|
membershipResolver = null,
|
|
43
46
|
personalWorkspaceName = undefined,
|
|
47
|
+
createdParticipant = noWorkspaceCreatedParticipant,
|
|
44
48
|
personalWorkspace = {
|
|
45
49
|
id: "1",
|
|
46
50
|
slug: "tony3",
|
|
@@ -50,7 +54,10 @@ function createWorkspaceServiceFixture({
|
|
|
50
54
|
avatarUrl: ""
|
|
51
55
|
}
|
|
52
56
|
} = {}) {
|
|
57
|
+
// Each write and the participant, with the transaction it ran in: withTransaction hands work TEST_TRX.
|
|
58
|
+
const steps = [];
|
|
53
59
|
const calls = {
|
|
60
|
+
withTransaction: 0,
|
|
54
61
|
findBySlug: 0,
|
|
55
62
|
listSlugsIn: 0,
|
|
56
63
|
findPersonalByOwnerUserId: 0,
|
|
@@ -91,7 +98,15 @@ function createWorkspaceServiceFixture({
|
|
|
91
98
|
personalWorkspaceName,
|
|
92
99
|
roleCatalog: roleCatalog && typeof roleCatalog === "object" ? { ...roleCatalog } : roleCatalog
|
|
93
100
|
}),
|
|
101
|
+
async createdParticipant(created, options) {
|
|
102
|
+
steps.push(["participant", options.trx]);
|
|
103
|
+
return createdParticipant(created, options);
|
|
104
|
+
},
|
|
94
105
|
workspacesRepository: {
|
|
106
|
+
async withTransaction(options, work) {
|
|
107
|
+
calls.withTransaction += 1;
|
|
108
|
+
return work(Object.freeze({ ...options, trx: TEST_TRX }));
|
|
109
|
+
},
|
|
95
110
|
async findBySlug(slug) {
|
|
96
111
|
calls.findBySlug += 1;
|
|
97
112
|
const normalizedSlug = String(slug || "").trim().toLowerCase();
|
|
@@ -133,8 +148,9 @@ function createWorkspaceServiceFixture({
|
|
|
133
148
|
}
|
|
134
149
|
];
|
|
135
150
|
},
|
|
136
|
-
async insert(payload) {
|
|
151
|
+
async insert(payload, options = {}) {
|
|
137
152
|
calls.insert += 1;
|
|
153
|
+
steps.push(["insert", options.trx]);
|
|
138
154
|
insertedPayloads.push(payload);
|
|
139
155
|
const workspaceId = String(nextWorkspaceId++);
|
|
140
156
|
const inserted = {
|
|
@@ -173,8 +189,9 @@ function createWorkspaceServiceFixture({
|
|
|
173
189
|
}
|
|
174
190
|
},
|
|
175
191
|
workspaceMembershipsRepository: {
|
|
176
|
-
async ensureOwnerMembership() {
|
|
192
|
+
async ensureOwnerMembership(workspaceId, userId, options = {}) {
|
|
177
193
|
calls.ensureOwnerMembership += 1;
|
|
194
|
+
steps.push(["membership", options.trx]);
|
|
178
195
|
},
|
|
179
196
|
async findByWorkspaceIdAndUserId(workspaceId, userId) {
|
|
180
197
|
if (typeof membershipResolver === "function") {
|
|
@@ -189,8 +206,9 @@ function createWorkspaceServiceFixture({
|
|
|
189
206
|
}
|
|
190
207
|
},
|
|
191
208
|
workspaceSettingsRepository: {
|
|
192
|
-
async ensureForWorkspaceId() {
|
|
209
|
+
async ensureForWorkspaceId(workspaceId, options = {}) {
|
|
193
210
|
calls.ensureWorkspaceSettings += 1;
|
|
211
|
+
steps.push(["settings", options.trx]);
|
|
194
212
|
return {
|
|
195
213
|
invitesEnabled: true
|
|
196
214
|
};
|
|
@@ -198,7 +216,7 @@ function createWorkspaceServiceFixture({
|
|
|
198
216
|
}
|
|
199
217
|
});
|
|
200
218
|
|
|
201
|
-
return { service, calls, insertedPayloads };
|
|
219
|
+
return { service, calls, insertedPayloads, steps };
|
|
202
220
|
}
|
|
203
221
|
|
|
204
222
|
test("workspaceService keeps bootstrap payload assembly outside its API", () => {
|
|
@@ -421,6 +439,60 @@ test("workspaceService.createWorkspaceForAuthenticatedUser generates an omitted
|
|
|
421
439
|
assert.equal(insertedPayloads[0].ownerUserId, "7");
|
|
422
440
|
});
|
|
423
441
|
|
|
442
|
+
test("both ways of creating a workspace run the created participant last, in the creation's transaction", async () => {
|
|
443
|
+
const chiara = { id: "7", email: "chiara@example.com", displayName: "Chiara" };
|
|
444
|
+
const creations = {
|
|
445
|
+
named: async (service) => (await service.createWorkspaceForAuthenticatedUser(chiara, { name: "Operations Team" })).value,
|
|
446
|
+
personal: (service) => service.ensureProvisionedWorkspaceForAuthenticatedUser(chiara)
|
|
447
|
+
};
|
|
448
|
+
for (const [kind, create] of Object.entries(creations)) {
|
|
449
|
+
const received = [];
|
|
450
|
+
const { service, calls, steps } = createWorkspaceServiceFixture({
|
|
451
|
+
tenancyMode: kind === "personal" ? "personal" : "workspaces",
|
|
452
|
+
tenancyPolicy: { workspace: { allowSelfCreate: true } },
|
|
453
|
+
personalWorkspace: null,
|
|
454
|
+
async createdParticipant(created, options) {
|
|
455
|
+
received.push({ created, options });
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
const workspace = await create(service);
|
|
459
|
+
assert.equal(calls.withTransaction, 1, kind);
|
|
460
|
+
assert.deepEqual(steps, [
|
|
461
|
+
["insert", TEST_TRX], ["membership", TEST_TRX], ["settings", TEST_TRX], ["participant", TEST_TRX]
|
|
462
|
+
], kind);
|
|
463
|
+
assert.equal(received.length, 1, kind);
|
|
464
|
+
const [{ created, options }] = received;
|
|
465
|
+
assert.deepEqual(Object.keys(created).sort(), ["owner", "workspace"]);
|
|
466
|
+
assert.equal(created.workspace.id, workspace.id);
|
|
467
|
+
assert.equal(created.workspace.isPersonal, kind === "personal");
|
|
468
|
+
assert.deepEqual(created.owner, chiara);
|
|
469
|
+
assert.ok(Object.isFrozen(created.workspace) && Object.isFrozen(created.owner), kind);
|
|
470
|
+
assert.equal(options.trx, TEST_TRX);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
test("a created participant's failure fails the creation, and an existing personal workspace runs no participant", async () => {
|
|
475
|
+
const refusal = new Error("the application cannot set this workspace up");
|
|
476
|
+
async function refuse() {
|
|
477
|
+
throw refusal;
|
|
478
|
+
}
|
|
479
|
+
const { service, steps } = createWorkspaceServiceFixture({
|
|
480
|
+
tenancyMode: "workspaces",
|
|
481
|
+
tenancyPolicy: { workspace: { allowSelfCreate: true } },
|
|
482
|
+
createdParticipant: refuse
|
|
483
|
+
});
|
|
484
|
+
await assert.rejects(service.createWorkspaceForAuthenticatedUser({ id: "7" }, { name: "Operations Team" }), (error) => error === refusal);
|
|
485
|
+
assert.equal(steps.at(-1)[0], "participant");
|
|
486
|
+
|
|
487
|
+
const { service: personal, steps: personalSteps } = createWorkspaceServiceFixture({
|
|
488
|
+
tenancyMode: "personal",
|
|
489
|
+
createdParticipant: refuse
|
|
490
|
+
});
|
|
491
|
+
const existing = await personal.ensureProvisionedWorkspaceForAuthenticatedUser({ id: "7", displayName: "Chiara" });
|
|
492
|
+
assert.equal(existing.id, "1");
|
|
493
|
+
assert.ok(!personalSteps.some(([step]) => step === "participant"));
|
|
494
|
+
});
|
|
495
|
+
|
|
424
496
|
// The slug a new workspace named `name` gets while `takenSlugs` are held, and how many reads chose it.
|
|
425
497
|
async function chooseWorkspaceSlug(name, takenSlugs) {
|
|
426
498
|
const { service, calls } = createWorkspaceServiceFixture({
|