@company-semantics/contracts 45.0.0 → 45.1.0

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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@company-semantics/contracts",
3
- "version": "45.0.0",
3
+ "version": "45.1.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -116,6 +116,7 @@
116
116
  "generate:current": "tsx ../company-semantics-ci/scripts/generate-current.ts",
117
117
  "adr:new": "tsx ../company-semantics-control/scripts/adr/adr-new-cli.ts",
118
118
  "repo-map": "tsx ../company-semantics-ci/scripts/generate-repo-map.ts --roots src --name company-semantics-contracts --write",
119
+ "sync:workflow-pins": "tsx ../company-semantics-ci/scripts/sync-workflow-pins.ts --write",
119
120
  "repo-map:check": "tsx ../company-semantics-ci/scripts/generate-repo-map.ts --roots src --name company-semantics-contracts --check",
120
121
  "readme-api": "tsx ../company-semantics-ci/scripts/generate-readme-api.ts --roots src --write --jsdoc",
121
122
  "readme-api:check": "tsx ../company-semantics-ci/scripts/generate-readme-api.ts --roots src --check --jsdoc",
@@ -134,7 +135,7 @@
134
135
  "amphtml-validator": "^1.0.38",
135
136
  "culori": "^4.0.2",
136
137
  "husky": "^9.1.7",
137
- "lint-staged": "^17.2.0",
138
+ "lint-staged": "^17.3.0",
138
139
  "markdownlint-cli2": "^0.23.2",
139
140
  "openapi-typescript": "^7.13.0",
140
141
  "prettier": "^3.9.6",
@@ -146,7 +147,7 @@
146
147
  },
147
148
  "pnpm": {
148
149
  "overrides": {
149
- "brace-expansion@<5.0.8": ">=5.0.8",
150
+ "brace-expansion@<5.0.9": ">=5.0.9",
150
151
  "minimatch@<10.2.3": ">=10.2.3",
151
152
  "js-yaml@>=4.0.0 <4.3.0": ">=4.3.0 <5.0.0",
152
153
  "js-yaml@>=5.0.0 <5.2.2": ">=5.2.2 <6.0.0",
@@ -162,5 +163,5 @@
162
163
  "*.md": "markdownlint-cli2",
163
164
  "package.json": "node -e \"JSON.parse(require('fs').readFileSync('package.json'))\""
164
165
  },
165
- "securityRequirementsVersion": "9ffb1b974fa033f13a73539f8338cad319b62bb95695aa4ac7b5215a50493513"
166
+ "securityRequirementsVersion": "5227de9b2a68460019c85186c0318d77915e02df1eb8aa8d1516b001e84bc524"
166
167
  }
@@ -11,8 +11,6 @@
11
11
  * ./config.ts so the package public surface is unchanged.
12
12
  *
13
13
  * Design principle: Configuration is data, not code.
14
- *
15
- * @architecture-role universal
16
14
  */
17
15
 
18
16
  // =============================================================================
@@ -10,8 +10,6 @@
10
10
  * ./config.ts so the package public surface is unchanged.
11
11
  *
12
12
  * Design principle: Configuration is data, not code.
13
- *
14
- * @architecture-role universal
15
13
  */
16
14
 
17
15
  import type { Soc2ControlArea } from "./types";
@@ -142,6 +142,62 @@ describe("CompanyMdCollabSseEventSchema — raw backend frames", () => {
142
142
  ).not.toThrow();
143
143
  });
144
144
 
145
+ /**
146
+ * `canEdit` is permission and `status` is occupancy — the pair below is the
147
+ * case that motivated the field (ADR-CONTRACTS-114). A read-only participant
148
+ * and an edit-capable one who is merely reading BOTH report `viewing`, so a
149
+ * consumer that split the roster on `status` would get the wrong answer for
150
+ * one of them. These three assertions lock that the schema keeps the two
151
+ * axes independent, including the absent case a rollout produces.
152
+ */
153
+ it("carries canEdit independently of status", () => {
154
+ const base = {
155
+ type: "collab-presence" as const,
156
+ v: 1 as const,
157
+ userId: USER_ID,
158
+ clientKey: CLIENT_KEY,
159
+ };
160
+
161
+ // Edit-capable, but reading. Occupancy says viewing; permission says yes.
162
+ const reader = CompanyMdCollabSseEventSchema.parse({
163
+ ...base,
164
+ status: "viewing",
165
+ canEdit: true,
166
+ });
167
+ expect(reader).toMatchObject({ status: "viewing", canEdit: true });
168
+
169
+ // Read-only, and on the editor tab. Occupancy is the same; permission is not.
170
+ const viewer = CompanyMdCollabSseEventSchema.parse({
171
+ ...base,
172
+ status: "viewing",
173
+ canEdit: false,
174
+ });
175
+ expect(viewer).toMatchObject({ status: "viewing", canEdit: false });
176
+
177
+ // An older server omits the field. It must parse, and it must not
178
+ // materialize as `true` — absent means no edit rights, so a consumer
179
+ // reading `canEdit === true` fails closed on its own.
180
+ const legacy = CompanyMdCollabSseEventSchema.parse({
181
+ ...base,
182
+ status: "editing",
183
+ });
184
+ expect(legacy).toMatchObject({ status: "editing" });
185
+ expect((legacy as { canEdit?: boolean }).canEdit).toBeUndefined();
186
+ });
187
+
188
+ it("rejects a non-boolean canEdit", () => {
189
+ expect(() =>
190
+ CompanyMdCollabSseEventSchema.parse({
191
+ type: "collab-presence",
192
+ v: 1,
193
+ userId: USER_ID,
194
+ clientKey: CLIENT_KEY,
195
+ status: "editing",
196
+ canEdit: "yes",
197
+ }),
198
+ ).toThrow();
199
+ });
200
+
145
201
  it("parses a collab-reset frame for each reason the backend sends", () => {
146
202
  for (const reason of ["epoch-mismatch", "compacted", "cursor-ahead"]) {
147
203
  expect(() =>
@@ -235,7 +235,9 @@ export type CompanyMdCollabUpdateEvent = z.infer<
235
235
  * `userId` is trustworthy: the server stamps it from the posting session and
236
236
  * never takes it from a client body. That is why no client-supplied identity
237
237
  * type is published — receiving clients resolve name/avatar/colour from
238
- * `userId` themselves.
238
+ * `userId` themselves. `canEdit` is stamped from the same session for the same
239
+ * reason: it is an authority answer, and an authority answer a client could
240
+ * assert about itself is not one.
239
241
  */
240
242
  export const CompanyMdCollabPresenceEventSchema = z.object({
241
243
  type: z.literal("collab-presence"),
@@ -247,6 +249,23 @@ export const CompanyMdCollabPresenceEventSchema = z.object({
247
249
  clientKey: z.string().uuid(),
248
250
  /** What that editor instance is doing. */
249
251
  status: z.enum(["editing", "viewing"]),
252
+ /**
253
+ * Whether this participant may WRITE the document — server-stamped from the
254
+ * same `CompanyMd.CanEdit` binding the sync handshake reports as `editable`,
255
+ * never taken from a client body.
256
+ *
257
+ * Distinct from `status`, which is occupancy: `status` says what one editor
258
+ * instance is doing right now, this says what the person is ALLOWED to do.
259
+ * The roster admits viewers on purpose (CanView, not CanEdit), so a reader
260
+ * cannot tell the two apart without this — and a client must never re-derive
261
+ * it from an ACL, which would stand up a second access authority in the
262
+ * browser.
263
+ *
264
+ * Optional so an older server stays representable on the wire. ABSENT MEANS
265
+ * NO EDIT RIGHTS: a consumer reads the missing field as `false` rather than
266
+ * guessing, which keeps the surface default-deny through a rollout.
267
+ */
268
+ canEdit: z.boolean().optional(),
250
269
  /** Selection anchor — an encoded Y.RelativePosition blob. */
251
270
  anchor: z.string().optional(),
252
271
  /** Selection head — an encoded Y.RelativePosition blob. */