@wrongstack/primitives 0.313.0 → 0.316.1

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/dist/index.d.ts CHANGED
@@ -6,5 +6,6 @@
6
6
  * belong here.
7
7
  */
8
8
  export { type CompileFail, type CompileResult, type CompileUserRegexResult, capSubject, compileUserRegex, MAX_SUBJECT_LEN, } from './regex-guard.js';
9
+ export { isSystemSessionId, requireSessionId, SESSION_ID_REQUIRED, SessionIdRequiredError, SYSTEM_SESSION_PREFIX, systemSessionId, } from './session-id.js';
9
10
  export { nowIso } from './time.js';
10
11
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -124,14 +124,43 @@ function capSubject(line) {
124
124
  return line.length > MAX_SUBJECT_LEN ? line.slice(0, MAX_SUBJECT_LEN) : line;
125
125
  }
126
126
 
127
+ // src/session-id.ts
128
+ var SESSION_ID_REQUIRED = "SESSION_ID_REQUIRED";
129
+ var SessionIdRequiredError = class extends Error {
130
+ code = SESSION_ID_REQUIRED;
131
+ constructor(operation) {
132
+ super(`Session id is required for ${operation}`);
133
+ this.name = "SessionIdRequiredError";
134
+ }
135
+ };
136
+ function requireSessionId(sessionId, operation) {
137
+ if (typeof sessionId !== "string" || sessionId.trim().length === 0) {
138
+ throw new SessionIdRequiredError(operation);
139
+ }
140
+ return sessionId;
141
+ }
142
+ var SYSTEM_SESSION_PREFIX = "system:";
143
+ function systemSessionId(actor) {
144
+ return `${SYSTEM_SESSION_PREFIX}${actor}`;
145
+ }
146
+ function isSystemSessionId(sessionId) {
147
+ return sessionId.startsWith(SYSTEM_SESSION_PREFIX);
148
+ }
149
+
127
150
  // src/time.ts
128
151
  function nowIso() {
129
152
  return (/* @__PURE__ */ new Date()).toISOString();
130
153
  }
131
154
  export {
132
155
  MAX_SUBJECT_LEN,
156
+ SESSION_ID_REQUIRED,
157
+ SYSTEM_SESSION_PREFIX,
158
+ SessionIdRequiredError,
133
159
  capSubject,
134
160
  compileUserRegex,
135
- nowIso
161
+ isSystemSessionId,
162
+ nowIso,
163
+ requireSessionId,
164
+ systemSessionId
136
165
  };
137
166
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,29 @@
1
+ /** Stable machine-readable code for session ownership invariant violations. */
2
+ export declare const SESSION_ID_REQUIRED: 'SESSION_ID_REQUIRED';
3
+ /** Thrown when session-scoped work is attempted without a usable session id. */
4
+ export declare class SessionIdRequiredError extends Error {
5
+ readonly code: "SESSION_ID_REQUIRED";
6
+ constructor(operation: string);
7
+ }
8
+ /**
9
+ * Enforce that session-scoped work has an explicit, non-blank owner.
10
+ * Returns the original id so slash-containing persisted ids remain unchanged.
11
+ */
12
+ export declare function requireSessionId(sessionId: string | null | undefined, operation: string): string;
13
+ /** Prefix marking a session id that belongs to a daemon rather than a user tab. */
14
+ export declare const SYSTEM_SESSION_PREFIX: 'system:';
15
+ /**
16
+ * Owning "session" for work a project-level daemon does on its own initiative
17
+ * — the Kanban supervisor's stale-lease recovery, a run mirror's projection
18
+ * refresh. No user tab asked for these, but the events they write still have
19
+ * to name an owner, and attributing them to whichever tab happened to be
20
+ * focused would be a lie that "stop this session's work" would then act on.
21
+ *
22
+ * The `system:` prefix keeps them filterable: a UI showing one tab's activity
23
+ * excludes them, and an operator auditing the ledger can see which daemon
24
+ * acted.
25
+ */
26
+ export declare function systemSessionId(actor: string): string;
27
+ /** Whether this id names a daemon rather than a user session. */
28
+ export declare function isSystemSessionId(sessionId: string): boolean;
29
+ //# sourceMappingURL=session-id.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrongstack/primitives",
3
- "version": "0.313.0",
3
+ "version": "0.316.1",
4
4
  "license": "MIT",
5
5
  "description": "Dependency-leaf primitives shared across WrongStack packages (regex guard, slugs, timestamps).",
6
6
  "repository": {