@jskit-ai/workspaces-core 0.2.29 → 0.2.30

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 CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - A test copy (`SIDE_EFFECTS` is not `live`) sends no invitation email: a provided invite mailer is replaced by one that logs the invitation and answers the new delivery status `simulated`, with "Test copy: the invitation email was not sent. Copy the invite link to share it." (`workspaces.invite.simulated`). The feature now requires `runtime.logger`.
5
6
  - A workspace route that names no permission of its own, such as every CRUD route, reads its workspace context once per request instead of twice. The route visibility resolver read the workspace, the membership and the settings without the request, so the workspace action context contributor read them all again: a CRUD list sent six statements more than it needed (on SQLite, 13 statements where 7 do). The visibility resolver now passes the request, and both share the request's one resolution, as the auth policy and the action context already did. The same user, workspace, membership and permissions decide, with the same refusals: 401 signed out, 403 `workspaces.workspace.accessDenied` for a non-member, 404 `workspaces.workspace.notFound` for an unknown slug and 403 `ACTION_PERMISSION_DENIED` for a member without the permission.
6
7
  - The unknown-grant refusal now says, right after the grants it reports, to search the application's own code for a permission before removing or renaming its grant (`hasPermission()`, `can()`, permission string checks, including names built in code such as `` `crud.${resource}.list` ``), since the check cannot see those; a permission the application checks goes in `roleCatalog.customPermissions`, and a grant is removed only when nothing uses it. Before, a reported grant that an application service still checked with `hasPermission()` read as dead, and removing it took that access from every role but the owner. The did-you-mean suggestions are unchanged, and the workspace-server pattern says the same.
7
8
  - A role that grants a permission nothing requires is caught when the server starts, where before it silently left the role refused (`ACTION_PERMISSION_DENIED`) wherever the grant was meant to allow it, such as `crud.labels.patch` for the update operation. The new `WorkspaceRoleGrantsProvider` (`workspaces.role-grants`, which needs `runtime.logger`) compares each role's own grants with the permissions the registered actions, the routes' `permission` and the surface access policies require, and the new `roleCatalog.customPermissions`, a list of the permission names the application checks itself (a service, a row policy, the browser). A grant that covers none, an exact name, a `<prefix>.*` or a `*` placed where it matches nothing, is reported at the role that writes it with the name it probably meant: `Role "member" grants "crud.labels.patch", which no action requires; did you mean "crud.labels.update"?`. Outside production the server refuses to start; in production it starts and logs a warning, since such a grant gives nothing. An application whose roles grant a permission it checks only itself adds it to `customPermissions`. Without workspaces nothing is checked.
package/locales/en.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "emailMismatchAccount": "Invitation email does not match account email.",
39
39
  "notAvailable": "Invitation is not available.",
40
40
  "mailerUnconfigured": "No workspace invite mailer is configured.",
41
+ "simulated": "Test copy: the invitation email was not sent. Copy the invite link to share it.",
41
42
  "sendFailed": "Unable to send workspace invite email.",
42
43
  "decisionRequired": "Decision is required.",
43
44
  "decisionInvalid": "Decision must be accept or refuse."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/workspaces-core",
3
- "version": "0.2.29",
3
+ "version": "0.2.30",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -23,9 +23,9 @@
23
23
  "./locales/en.json": "./locales/en.json"
24
24
  },
25
25
  "dependencies": {
26
- "@jskit-ai/resource-core": "0.1.210",
27
- "@jskit-ai/resource-crud-core": "0.1.212",
28
- "@jskit-ai/users-core": "0.2.29",
26
+ "@jskit-ai/resource-core": "0.1.211",
27
+ "@jskit-ai/resource-crud-core": "0.1.213",
28
+ "@jskit-ai/users-core": "0.2.30",
29
29
  "json-rest-schema": "^1.0.20"
30
30
  },
31
31
  "description": "Workspace tenancy runtime plus HTTP routes, role catalog, and workspace config scaffolding.",
@@ -211,10 +211,10 @@
211
211
  }
212
212
  },
213
213
  "peerDependencies": {
214
- "@jskit-ai/auth-core": "0.2.19",
215
- "@jskit-ai/database-runtime": "0.1.268",
216
- "@jskit-ai/http-runtime": "0.2.19",
217
- "@jskit-ai/kernel": "0.2.19",
218
- "@jskit-ai/resource-runtime": "0.2.24"
214
+ "@jskit-ai/auth-core": "0.2.20",
215
+ "@jskit-ai/database-runtime": "0.1.269",
216
+ "@jskit-ai/http-runtime": "0.2.20",
217
+ "@jskit-ai/kernel": "0.2.20",
218
+ "@jskit-ai/resource-runtime": "0.2.25"
219
219
  }
220
220
  }
@@ -1,4 +1,5 @@
1
1
  import { defineFeature } from "@jskit-ai/kernel/server/features";
2
+ import { sideEffectsAreLive } from "@jskit-ai/kernel/shared/support/sideEffects";
2
3
  import { createWorkspaceBootstrapContributor } from "./workspaceBootstrapContributor.js";
3
4
  import { registerWorkspaceDirectoryRoutes } from "./workspaceDirectory/workspaceDirectoryRoutes.js";
4
5
  import { createWorkspaceDirectoryActions } from "./workspaceDirectory/workspaceDirectoryActions.js";
@@ -8,6 +9,7 @@ import { registerWorkspacePendingInvitationsRoutes } from "./workspacePendingInv
8
9
  import { createWorkspacePendingInvitationsActions } from "./workspacePendingInvitations/workspacePendingInvitationsActions.js";
9
10
  import { registerWorkspaceSettingsRoutes } from "./workspaceSettings/workspaceSettingsRoutes.js";
10
11
  import { unconfiguredWorkspaceInviteMailer } from "./workspaceMembers/unconfiguredWorkspaceInviteMailer.js";
12
+ import { createSimulatedWorkspaceInviteMailer } from "./workspaceMembers/simulatedWorkspaceInviteMailer.js";
11
13
  import { renderDefaultWorkspaceInviteEmail } from "./workspaceMembers/defaultWorkspaceInviteEmail.js";
12
14
  import { noInviteAcceptanceParticipant } from "./workspacePendingInvitations/noInviteAcceptanceParticipant.js";
13
15
  import { noWorkspaceCreatedParticipant } from "./workspaceDirectory/noWorkspaceCreatedParticipant.js";
@@ -25,6 +27,7 @@ const WorkspacesFeature = defineFeature({
25
27
  config: "runtime.config",
26
28
  env: "runtime.env",
27
29
  http: "runtime.http",
30
+ logger: "runtime.logger",
28
31
  userProfiles: "users.profiles",
29
32
  userSettings: "users.settings"
30
33
  },
@@ -47,6 +50,7 @@ const WorkspacesFeature = defineFeature({
47
50
  * @param {import("@jskit-ai/kernel/server/types").RuntimeConfig} capabilities.config
48
51
  * @param {import("@jskit-ai/kernel/server/types").RuntimeEnv} capabilities.env
49
52
  * @param {import("@jskit-ai/kernel/server/types").RuntimeHttp} capabilities.http
53
+ * @param {import("@jskit-ai/kernel/server/types").RuntimeLogger} capabilities.logger
50
54
  * @param {import("./types.js").WorkspaceInviteAcceptanceParticipant | null} capabilities.inviteAcceptanceParticipant
51
55
  * @param {import("./types.js").WorkspaceInviteEmailTemplate | null} capabilities.inviteEmailTemplate
52
56
  * @param {import("./types.js").WorkspaceInviteMailer | null} capabilities.inviteMailer
@@ -65,6 +69,7 @@ const WorkspacesFeature = defineFeature({
65
69
  inviteAcceptanceParticipant,
66
70
  inviteEmailTemplate,
67
71
  inviteMailer,
72
+ logger,
68
73
  personalWorkspaceName,
69
74
  resources,
70
75
  userProfiles,
@@ -78,7 +83,10 @@ const WorkspacesFeature = defineFeature({
78
83
  env,
79
84
  inviteAcceptanceParticipant: inviteAcceptanceParticipant ?? noInviteAcceptanceParticipant,
80
85
  inviteEmailTemplate: inviteEmailTemplate ?? renderDefaultWorkspaceInviteEmail,
81
- inviteMailer: inviteMailer ?? unconfiguredWorkspaceInviteMailer,
86
+ // A test copy (SIDE_EFFECTS is not live) logs the invitations a provided mailer would send, and sends none.
87
+ inviteMailer: inviteMailer
88
+ ? (sideEffectsAreLive(env) ? inviteMailer : createSimulatedWorkspaceInviteMailer(logger))
89
+ : unconfiguredWorkspaceInviteMailer,
82
90
  personalWorkspaceName: personalWorkspaceName ?? buildWorkspaceName,
83
91
  resources,
84
92
  userProfiles,
@@ -0,0 +1,29 @@
1
+ import { logSimulatedSideEffect } from "@jskit-ai/kernel/server/runtime/sideEffects";
2
+
3
+ /**
4
+ * The invite mailer of a test copy (SIDE_EFFECTS is not `live`) in place of the provided
5
+ * `workspaces.invite-mailer`: it emails nothing, logs the invitation's recipient, subject and link, and reports the
6
+ * delivery as simulated, so the inviter copies the link to share it.
7
+ * @param {import("@jskit-ai/kernel/server/types").RuntimeLogger} logger
8
+ * @returns {import("../types.js").WorkspaceInviteMailer}
9
+ */
10
+ function createSimulatedWorkspaceInviteMailer(logger) {
11
+ async function sendWorkspaceInvite({ email, inviteUrl, message }) {
12
+ logSimulatedSideEffect(logger, {
13
+ kind: "email",
14
+ summary: `the workspace invitation email to ${email}`,
15
+ details: { email, subject: String(message?.subject || ""), inviteUrl }
16
+ });
17
+ return {
18
+ status: "simulated",
19
+ message: "Test copy: the invitation email was not sent. Copy the invite link to share it.",
20
+ messageCode: "workspaces.invite.simulated",
21
+ messageParams: {},
22
+ providerMessageId: ""
23
+ };
24
+ }
25
+
26
+ return Object.freeze({ sendWorkspaceInvite });
27
+ }
28
+
29
+ export { createSimulatedWorkspaceInviteMailer };
@@ -14,7 +14,7 @@ const workspaceInviteAssistantOutput = createSchemaDefinition(createSchema({
14
14
  expiresAt: { type: "string", required: true }
15
15
  })
16
16
  },
17
- deliveryStatus: { type: "string", required: true, enum: ["sent", "failed", "mailer_unconfigured"] }
17
+ deliveryStatus: { type: "string", required: true, enum: ["sent", "simulated", "failed", "mailer_unconfigured"] }
18
18
  }), "replace");
19
19
 
20
20
  const pendingInvitationsAssistantOutput = createSchemaDefinition(createSchema({
@@ -120,7 +120,7 @@ const workspaceInviteCreateOutputSchema = createSchema({
120
120
  status: {
121
121
  type: "string",
122
122
  required: true,
123
- enum: ["sent", "failed", "mailer_unconfigured"]
123
+ enum: ["sent", "simulated", "failed", "mailer_unconfigured"]
124
124
  },
125
125
  message: {
126
126
  type: "string",
@@ -0,0 +1,29 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { createSimulatedWorkspaceInviteMailer } from "../src/server/workspaceMembers/simulatedWorkspaceInviteMailer.js";
4
+
5
+ test("a test copy's invite mailer sends nothing, logs the invitation and reports it simulated", async () => {
6
+ const logs = [];
7
+ const mailer = createSimulatedWorkspaceInviteMailer({
8
+ info: (details, message) => logs.push({ details, message }),
9
+ warn() {},
10
+ error() {},
11
+ debug() {}
12
+ });
13
+ const delivery = await mailer.sendWorkspaceInvite({
14
+ email: "guest@example.com",
15
+ inviteUrl: "https://app.example.test/invite?token=abc",
16
+ message: { subject: "You're invited to Books", text: "Join us", html: "<p>Join us</p>" }
17
+ });
18
+ assert.equal(delivery.status, "simulated");
19
+ assert.equal(delivery.messageCode, "workspaces.invite.simulated");
20
+ assert.equal(logs.length, 1);
21
+ assert.deepEqual(logs[0].details, {
22
+ sideEffects: "simulate",
23
+ kind: "email",
24
+ email: "guest@example.com",
25
+ subject: "You're invited to Books",
26
+ inviteUrl: "https://app.example.test/invite?token=abc"
27
+ });
28
+ assert.match(logs[0].message, /^Test copy: the workspace invitation email to guest@example\.com was simulated, not sent/u);
29
+ });
@@ -35,7 +35,7 @@ test("workspace members invite mutation outputs expose their tracking ids explic
35
35
  assert.deepEqual(inviteDeliverySchema.required, ["status", "message", "providerMessageId"]);
36
36
  assert.deepEqual(
37
37
  inviteDeliverySchema.properties.status.enum,
38
- ["sent", "failed", "mailer_unconfigured"]
38
+ ["sent", "simulated", "failed", "mailer_unconfigured"]
39
39
  );
40
40
  assert.equal(revokeOutputSchema.properties.revokedInviteId.type, "string");
41
41
  assert.equal(revokeOutputSchema.properties.roleCatalog["x-json-rest-schema"]?.castType, "object");