@superjackfruitlabs/treaty-matrix-events 0.0.10 → 0.0.12

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/README.md CHANGED
@@ -27,4 +27,5 @@ the old one; an additive change bumps `schema_version` inside the content, and r
27
27
  properties they do not know.
28
28
 
29
29
  The board-room names (`boardRoomAlias`, `boardSpeakerMxid`) are the names existing rooms have, in
30
- the AgentPod appservice's namespace.
30
+ the AgentPod appservice's namespace. `boardRoomNames(carrier)` gives each carrier its own set:
31
+ `agentpod` returns those same names, `superexchange` names inside SuperExchange's namespace.
@@ -8,7 +8,8 @@
8
8
  *
9
9
  * The localpart and the alias sit inside the AgentPod appservice's exclusive `@agent_.*` and
10
10
  * `#agentpod_.*` namespaces, which is where every board room lives today. A carrier with its own
11
- * namespace (SuperExchange) needs its own names; these stay what existing rooms are called.
11
+ * namespace (SuperExchange) needs its own names; these stay what existing rooms are called, and
12
+ * `boardRoomNames` gives each carrier its set.
12
13
  */
13
14
  /** The localpart the board speaks as. */
14
15
  export declare const BOARD_SPEAKER_LOCALPART = "agent_superpipeline";
@@ -18,3 +19,20 @@ export declare const BOARD_SPEAKER_DISPLAY_NAME = "superpipeline";
18
19
  export declare function boardRoomAlias(boardId: string): string;
19
20
  /** The speaker's full Matrix id on a homeserver. */
20
21
  export declare function boardSpeakerMxid(domain: string): string;
22
+ /** The carriers that hold board rooms, each inside its own appservice's exclusive namespace. */
23
+ export type BoardRoomCarrier = "agentpod" | "superexchange";
24
+ /** One carrier's board-room names. */
25
+ export interface BoardRoomNames {
26
+ /** The localpart the board speaks as. */
27
+ speakerLocalpart: string;
28
+ /** The room alias's localpart for a board, unsafe characters as `_`. */
29
+ alias(boardId: string): string;
30
+ /** The speaker's full Matrix id on a homeserver. */
31
+ speakerMxid(domain: string): string;
32
+ }
33
+ /**
34
+ * A carrier's board-room names. Both speak with the display name `BOARD_SPEAKER_DISPLAY_NAME`, so
35
+ * a person sees the board, not the carrier. A board's room under one carrier is a different room
36
+ * from its room under the other: neither carrier can speak in, or claim the alias of, the other's.
37
+ */
38
+ export declare function boardRoomNames(carrier: BoardRoomCarrier): BoardRoomNames;
@@ -8,7 +8,8 @@
8
8
  *
9
9
  * The localpart and the alias sit inside the AgentPod appservice's exclusive `@agent_.*` and
10
10
  * `#agentpod_.*` namespaces, which is where every board room lives today. A carrier with its own
11
- * namespace (SuperExchange) needs its own names; these stay what existing rooms are called.
11
+ * namespace (SuperExchange) needs its own names; these stay what existing rooms are called, and
12
+ * `boardRoomNames` gives each carrier its set.
12
13
  */
13
14
  /** The localpart the board speaks as. */
14
15
  export const BOARD_SPEAKER_LOCALPART = "agent_superpipeline";
@@ -22,3 +23,28 @@ export function boardRoomAlias(boardId) {
22
23
  export function boardSpeakerMxid(domain) {
23
24
  return `@${BOARD_SPEAKER_LOCALPART}:${domain}`;
24
25
  }
26
+ const LOCALPART = {
27
+ // Inside `@agent_.*` and `#agentpod_.*`: the names every existing room has.
28
+ agentpod: {
29
+ speaker: BOARD_SPEAKER_LOCALPART,
30
+ aliasPrefix: "agentpod_board_",
31
+ },
32
+ // Inside `@superexchange_.*` and `#superexchange_.*`.
33
+ superexchange: {
34
+ speaker: "superexchange_board",
35
+ aliasPrefix: "superexchange_board_",
36
+ },
37
+ };
38
+ /**
39
+ * A carrier's board-room names. Both speak with the display name `BOARD_SPEAKER_DISPLAY_NAME`, so
40
+ * a person sees the board, not the carrier. A board's room under one carrier is a different room
41
+ * from its room under the other: neither carrier can speak in, or claim the alias of, the other's.
42
+ */
43
+ export function boardRoomNames(carrier) {
44
+ const { speaker, aliasPrefix } = LOCALPART[carrier];
45
+ return {
46
+ speakerLocalpart: speaker,
47
+ alias: (boardId) => `${aliasPrefix}${boardId.replace(/[^A-Za-z0-9_-]/g, "_")}`,
48
+ speakerMxid: (domain) => `@${speaker}:${domain}`,
49
+ };
50
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A subject's expiry, `subject.expires_at`: an RFC 3339 date-time with seconds and an explicit
3
+ * offset, such as `2030-01-02T03:04:05Z` or `2030-01-02T08:34:05.5+05:30`.
4
+ *
5
+ * The one spelling every reader accepts. Looser ones that `Date.parse` happens to read (a date
6
+ * only, `Jan 2 2030`, no seconds, no offset, a space for the `T`) are refused, because a strict
7
+ * reader of the event would drop it, and two readers disagreeing on when an approval lapses is
8
+ * worse than either refusing it. SuperPipeline sends only this form.
9
+ *
10
+ * The schemas (`subject.expires_at` in gate.v2, question.v2, delivery.v2, permission.v2) carry the
11
+ * same rule as `"format": "date-time"` and as this pattern, because a JSON Schema validator need
12
+ * not assert `format`.
13
+ */
14
+ /** The pattern the schemas carry, as a JSON Schema `pattern` string. */
15
+ export declare const SUBJECT_EXPIRY_PATTERN = "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.\\d+)?(Z|[+-]([01]\\d|2[0-3]):[0-5]\\d)$";
16
+ /** The schemas' `maxLength` on `expires_at`. */
17
+ export declare const SUBJECT_EXPIRY_MAX = 200;
18
+ /** Is this an expiry in the one form a subject may carry, naming a real calendar day? */
19
+ export declare function isSubjectExpiry(v: unknown): v is string;
package/dist/expiry.js ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A subject's expiry, `subject.expires_at`: an RFC 3339 date-time with seconds and an explicit
3
+ * offset, such as `2030-01-02T03:04:05Z` or `2030-01-02T08:34:05.5+05:30`.
4
+ *
5
+ * The one spelling every reader accepts. Looser ones that `Date.parse` happens to read (a date
6
+ * only, `Jan 2 2030`, no seconds, no offset, a space for the `T`) are refused, because a strict
7
+ * reader of the event would drop it, and two readers disagreeing on when an approval lapses is
8
+ * worse than either refusing it. SuperPipeline sends only this form.
9
+ *
10
+ * The schemas (`subject.expires_at` in gate.v2, question.v2, delivery.v2, permission.v2) carry the
11
+ * same rule as `"format": "date-time"` and as this pattern, because a JSON Schema validator need
12
+ * not assert `format`.
13
+ */
14
+ /** The pattern the schemas carry, as a JSON Schema `pattern` string. */
15
+ export const SUBJECT_EXPIRY_PATTERN = "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.\\d+)?(Z|[+-]([01]\\d|2[0-3]):[0-5]\\d)$";
16
+ /** The schemas' `maxLength` on `expires_at`. */
17
+ export const SUBJECT_EXPIRY_MAX = 200;
18
+ const EXPIRY = new RegExp(SUBJECT_EXPIRY_PATTERN);
19
+ /** Is this an expiry in the one form a subject may carry, naming a real calendar day? */
20
+ export function isSubjectExpiry(v) {
21
+ if (typeof v !== "string" || v.length > SUBJECT_EXPIRY_MAX)
22
+ return false;
23
+ if (!EXPIRY.test(v))
24
+ return false;
25
+ const year = Number(v.slice(0, 4));
26
+ const month = Number(v.slice(5, 7));
27
+ const day = Number(v.slice(8, 10));
28
+ // 2030-02-30 matches the pattern; the calendar refuses it, as `format: date-time` does.
29
+ return new Date(Date.UTC(year, month - 1, day)).getUTCDate() === day;
30
+ }
package/dist/gate.js CHANGED
@@ -11,6 +11,7 @@ import { quorumField } from "./quorum.js";
11
11
  import { releaseField, releaseSentence, releaseV2 } from "./release.js";
12
12
  import { checksField, checksSentence, checksV2 } from "./checks.js";
13
13
  import { isHttpsUrl } from "./safe-url.js";
14
+ import { isSubjectExpiry } from "./expiry.js";
14
15
  export const GATE_EVENT_TYPE = "dev.superpipeline.gate.v1";
15
16
  export const GATE_DECISION_SUITE_TYPE = "dev.superpipeline.gate.decision.v1";
16
17
  /**
@@ -272,7 +273,15 @@ const RawSubject = z.object({
272
273
  digest: z.string().min(1).max(SUBJECT_KEY_MAX),
273
274
  schema: z.string().min(1).max(PREVIEW_FIELD_MAX),
274
275
  revision: z.number().int().nonnegative(),
275
- expiresAt: z.string().max(PREVIEW_FIELD_MAX).nullish().catch(null),
276
+ /**
277
+ * Strict (`isSubjectExpiry`): a loosely spelled expiry refuses the whole subject, since carrying
278
+ * it would emit an event its schema refuses, and dropping it would carry an approval with no
279
+ * expiry. A value that is not a string at all is read as none, as before.
280
+ */
281
+ expiresAt: z
282
+ .unknown()
283
+ .refine((v) => typeof v !== "string" || isSubjectExpiry(v))
284
+ .transform((v) => (typeof v === "string" ? v : null)),
276
285
  preview: z.array(z.unknown()).optional().catch(undefined),
277
286
  /** False when the board had to cut or drop blocks to fit the bounds. Absent from older boards. */
278
287
  previewComplete: z.boolean().optional().catch(undefined),
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * from "./decision-timeout.ts";
17
17
  export * from "./deliveries.ts";
18
18
  export * from "./delivery.ts";
19
19
  export * from "./elicitation.ts";
20
+ export * from "./expiry.ts";
20
21
  export * from "./gate.ts";
21
22
  export * from "./permission.ts";
22
23
  export * from "./question.ts";
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ export * from "./decision-timeout.js";
17
17
  export * from "./deliveries.js";
18
18
  export * from "./delivery.js";
19
19
  export * from "./elicitation.js";
20
+ export * from "./expiry.js";
20
21
  export * from "./gate.js";
21
22
  export * from "./permission.js";
22
23
  export * from "./question.js";