@moshaver/cmb-activity 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mobin Karam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # `@moshaver/cmb-activity`
2
+
3
+ Generic presence normalization, heartbeat de-duplication, projection, and activity paging. Moshaver event vocabulary, student/task persistence, attention signals, and access policy remain product-owned.
4
+
5
+ ## Install and use
6
+
7
+ ```bash
8
+ npm install @moshaver/cmb-activity
9
+ ```
10
+
11
+ ```js
12
+ const { normalizePresenceState, shouldPersistPresence } = require("@moshaver/cmb-activity");
13
+ const state = normalizePresenceState("online");
14
+ ```
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@moshaver/cmb-activity",
3
+ "version": "0.1.0",
4
+ "description": "Composable Modular Backend activity primitives.",
5
+ "type": "commonjs",
6
+ "main": "./src/index.js",
7
+ "types": "./src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./src/index.d.ts",
11
+ "require": "./src/index.js",
12
+ "default": "./src/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "src",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "keywords": [
21
+ "cmb",
22
+ "modular-backend",
23
+ "backend",
24
+ "framework-agnostic",
25
+ "activity"
26
+ ],
27
+ "engines": {
28
+ "node": ">=22.13.0 <23"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/Mobin-Karam/moshaver.git",
33
+ "directory": "packages/cmb/activity"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/Mobin-Karam/moshaver/issues"
37
+ },
38
+ "homepage": "https://github.com/Mobin-Karam/moshaver/tree/main/packages/cmb",
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "license": "MIT",
43
+ "sideEffects": false,
44
+ "dependencies": {
45
+ "@moshaver/cmb-kernel": "^0.1.0"
46
+ }
47
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export const ACTIVITY_MODULE: Readonly<{ id: "activity"; version: string; kind: "platform"; dependencies: readonly string[] }>;
2
+ export const DEFAULT_PRESENCE_STATES: readonly string[];
3
+ export function normalizePresenceState(value: unknown, allowedStates?: readonly string[], fallback?: string): string;
4
+ export function shouldPersistPresence(previous: { state: string; resourceId?: string | null; lastSeenAt: Date } | null | undefined, next: { state: string; resourceId?: string | null }, now?: Date, debounceMs?: number): boolean;
5
+ export function projectPresence(row: { state: string; lastSeenAt: Date; resource?: { id: string; title: string } | null }, now?: Date, onlineWindowMs?: number): { online: boolean; state: string; lastSeenAt: Date; currentTask: { id: string; title: string } | null };
6
+ export function clampActivityLimit(value: unknown, fallback?: number, maximum?: number): number;
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ const { defineModule } = require("@moshaver/cmb-kernel");
3
+ const ACTIVITY_MODULE = defineModule({ id: "activity", version: "0.1.0", kind: "platform", dependencies: ["kernel"] });
4
+ const DEFAULT_PRESENCE_STATES = Object.freeze(["idle", "studying", "quiz", "exam", "offline"]);
5
+ function normalizePresenceState(value, allowedStates = DEFAULT_PRESENCE_STATES, fallback = "idle") { const state = String(value ?? ""); return allowedStates.includes(state) ? state : fallback; }
6
+ function shouldPersistPresence(previous, next, now = new Date(), debounceMs = 30_000) { if (!previous) return true; return previous.state !== next.state || (previous.resourceId ?? null) !== (next.resourceId ?? null) || now.getTime() - previous.lastSeenAt.getTime() >= debounceMs; }
7
+ function projectPresence(row, now = new Date(), onlineWindowMs = 90_000) { const online = now.getTime() - row.lastSeenAt.getTime() <= onlineWindowMs; return { online, state: online ? row.state : "offline", lastSeenAt: row.lastSeenAt, currentTask: row.resource ? { id: row.resource.id, title: row.resource.title } : null }; }
8
+ function clampActivityLimit(value, fallback = 50, maximum = 100) { return Math.min(Math.max(Number(value) || fallback, 1), maximum); }
9
+ module.exports = { ACTIVITY_MODULE, DEFAULT_PRESENCE_STATES, normalizePresenceState, shouldPersistPresence, projectPresence, clampActivityLimit };