@webex/internal-plugin-presence 3.13.0-next.3 → 3.13.0-next.5
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/.repo-context.json +477 -0
- package/.sdd/manifest.json +428 -0
- package/AGENTS.md +208 -0
- package/dist/presence.js +1 -1
- package/docs/adr/0001-retain-product-readme.md +98 -0
- package/docs/adr/index.md +25 -0
- package/docs/architecture.md +266 -0
- package/docs/getting-started.md +134 -0
- package/docs/index.md +44 -0
- package/docs/specs/README.md +70 -0
- package/package.json +4 -4
- package/schemas/repo-context.schema.json +796 -0
- package/src/docs/README.md +515 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: Module Spec
|
|
3
|
+
title: 'Presence plugin specification'
|
|
4
|
+
description: Responsibilities, boundaries, design, invariants, and verification for the Presence plugin module.
|
|
5
|
+
tags: [module, specification]
|
|
6
|
+
---
|
|
7
|
+
<!-- sdd-generated-metadata
|
|
8
|
+
doc_kind: module-spec
|
|
9
|
+
generated_from: module-spec@0.3.0
|
|
10
|
+
generated_by: claude-code
|
|
11
|
+
approved_by: rarajes2@cisco.com
|
|
12
|
+
updated_at: 2026-11-12T13:10:05Z
|
|
13
|
+
validation_status: blocked
|
|
14
|
+
-->
|
|
15
|
+
|
|
16
|
+
# Presence plugin
|
|
17
|
+
|
|
18
|
+
This source-local document at `src/docs/README.md` owns the stable specification for **the Presence
|
|
19
|
+
plugin**: the internal plugin `webex.internal.presence`. It reads, subscribes to, and sets user
|
|
20
|
+
presence on the presence service (catalog service `apheleia`), turns the presence feature toggle on
|
|
21
|
+
and off through the feature plugin, and runs an optional worker that fetches and subscribes to the
|
|
22
|
+
presence of the users a client is showing and reports changes as `updated` events. Ground every claim
|
|
23
|
+
in package evidence and link to the [package architecture](../../docs/architecture.md) instead of
|
|
24
|
+
repeating broader facts. No service specification exists because this package is a library.
|
|
25
|
+
|
|
26
|
+
Related context: [documentation index](../../docs/index.md) ·
|
|
27
|
+
[package agent instructions](../../AGENTS.md)
|
|
28
|
+
|
|
29
|
+
## Metadata
|
|
30
|
+
|
|
31
|
+
| Field | Value |
|
|
32
|
+
| ----------------- | ----- |
|
|
33
|
+
| Owner | @webex/web-sdk |
|
|
34
|
+
| Source path | `src` |
|
|
35
|
+
| Resource kind | package |
|
|
36
|
+
| Status | Draft |
|
|
37
|
+
| Last verified | 2026-11-12 at `fed37cf37c` |
|
|
38
|
+
| Module id | `internal-plugin-presence` |
|
|
39
|
+
| Parent spec | — |
|
|
40
|
+
| Doc kind | Module spec |
|
|
41
|
+
| Coverage score | 100% assessed 2026-11-12 by the generator — 15 of 15 mandatory fields PRESENT, critical 8 of 8; `test:unit` reports 29 cases, all skipped, so no requirement has a running test |
|
|
42
|
+
| Validation status | Blocked — assessed 2026-11-12 by validator runtime `01a1cfda-147b-79f2-a595-31f4dfab09c2`; 1 Blocking and 1 Important finding. A1-001 (no confirmed rationale for the `dnd` label exception) stays open: the maintainer answered on 2026-11-12 that the rationale is not known, so `MOD-010` and `INV-003` are unchanged. IMP-001 (command-source traceability for five command entries) is accepted as a warning |
|
|
43
|
+
|
|
44
|
+
## Applicability
|
|
45
|
+
|
|
46
|
+
| Condition ID | Status | Evidence or reason | Owned section |
|
|
47
|
+
| ------------------------------------ | ---------- | ------------------ | ------------- |
|
|
48
|
+
| `module.has_tiers` | N/A | No tier policy exists in `package.json` or `src/presence.js` | Tier |
|
|
49
|
+
| `module.has_ui` | N/A | `src/presence.js` and `src/presence-worker.js` send requests and emit events; they render nothing | UI use-case flow |
|
|
50
|
+
| `module.crosses_service_boundaries` | Applicable | `src/presence.js` and `src/presence-batcher.js` call the presence service; `src/presence-worker.js` listens to Mercury; `src/presence.js` calls the feature plugin | Cross-boundary use-case flow |
|
|
51
|
+
| `module.holds_client_state` | Applicable | `src/presence-worker.js` keeps six per-user maps; `src/presence-batcher.js` keeps pending lookups | Client state model |
|
|
52
|
+
| `module.enforces_domain_rules` | Applicable | The 50-subject batch limit and the dnd label rule in `src/presence.js`; the fetch, subscribe, renew, and expiry timings in `src/constants.js` | Business rules and invariants |
|
|
53
|
+
| `module.is_concurrent_async` | Applicable | Every method returns a promise; `src/presence-worker.js` runs a debounced fetch and a 20-second interval | Concurrency and reactive flow |
|
|
54
|
+
| `module.owns_persistence` | N/A | `src/presence-worker.js` keeps maps in memory only; nothing is stored | Data, schema, and migration discipline |
|
|
55
|
+
| `module.stateful_transitions` | Applicable | A watched user moves from camping to subscribed, renewed, and expired in `src/presence-worker.js` | State machine |
|
|
56
|
+
| `module.exposes_wire_protocol` | Applicable | The compositions, subscriptions, and events requests in `src/presence.js` and `src/presence-batcher.js`; the Mercury event and the updated envelope in `src/presence-worker.js` | Protocol and wire format |
|
|
57
|
+
| `module.ui_multi_screen` | N/A | No UI | UI flow |
|
|
58
|
+
| `module.large_data_model` | N/A | The package defines no model; the presence status object is the service's response, covered under Protocol and wire format | Data model |
|
|
59
|
+
| `module.returns_caller_errors` | Applicable | Argument checks and request failures reject the methods of `src/presence.js`; `src/presence-worker.js` throws on a missing webex | Caller-visible failure modes |
|
|
60
|
+
| `module.module_specific_conventions` | Applicable | The updated event and its three envelope types in `src/constants.js` | Module-specific rules |
|
|
61
|
+
| `module.published_package` | Applicable | `package.json` names the package @webex/internal-plugin-presence and defines deploy:npm | Export stability |
|
|
62
|
+
| `module.embedded_in_host` | N/A | No host theme or embed API | Host integration and theming |
|
|
63
|
+
| `module.has_design_tradeoff` | Applicable | The one-minute camping delay, the batched lookups, and the timestamp-only worker in `src/presence-worker.js` and `src/presence-batcher.js` | Key design trade-off |
|
|
64
|
+
| `module.has_submodules` | N/A | The src directory has no child module | Sub-modules |
|
|
65
|
+
|
|
66
|
+
## Evidence register
|
|
67
|
+
|
|
68
|
+
| Evidence | What it establishes |
|
|
69
|
+
| -------- | ------------------- |
|
|
70
|
+
| `src/index.js` | Imports `@webex/internal-plugin-device`, then `registerInternalPlugin('presence', Presence, {payloadTransformer, config})` at import time; re-exports the default `Presence`. The comment on the predicate names the events endpoint |
|
|
71
|
+
| `src/presence.js` | `Presence` extends `WebexPlugin` in namespace `Presence`, with child `batcher` and session property `worker`; methods `initialize`, `initializeWorker`, `emitEvent`, `enable`, `disable`, `isEnabled`, `get`, `list`, `subscribe`, `unsubscribe`, `setStatus`, `enqueue`, `dequeue`. The JSDoc, including the `PresenceStatusObject` typedef, and the batch-limit comment are recorded rationale |
|
|
72
|
+
| `src/presence-batcher.js` | `PresenceBatcher` extends the webex-core `Batcher` in namespace `Presence`: ids are their own fingerprints, the flush POSTs `compositions` with `{subjects}`, and each `statusList` entry resolves the lookup with the same `subject` |
|
|
73
|
+
| `src/presence-worker.js` | `PresenceWorker`: the six maps, Mercury wiring, the debounced fetch, and the groundskeeper. Its comments state why each step runs ("Subscribe if they've been camping for a minute", "Renew subscription if they're about to expire", "Tells client to delete it too") |
|
|
74
|
+
| `src/constants.js` | Timings (20 s interval, 300 ms fetch delay, 1 min staleness, 10 min expiry, 1 min camping, 1 min renewal margin, 10 min fallback subscription), the Mercury event name, the `updated` event name, and the envelope types |
|
|
75
|
+
| `src/config.js` | Defaults `presence.batcherWait`, `presence.batcherMaxCalls`, `presence.batcherMaxWait` |
|
|
76
|
+
| `package.json` | Name, `main` (`dist/index.js`), `devMain` (`src/index.js`), `engines` (`node >=16`), dependencies, and scripts; `test:unit` exists, `test:integration` does not |
|
|
77
|
+
| `test/unit/spec/presence.js` | Cases for the argument checks, the 50-id subscribe batching, the `dnd` label rule, and `initializeWorker`; the whole suite is `describe.skip` |
|
|
78
|
+
| `test/unit/spec/presence-worker.js` | Cases for `initialize`, `enqueue`, `dequeue`, `checkFetchers`, `checkCampers`, `checkSubscriptions`, `cleanPresences`, and `groundskeeper`; the whole suite is `describe.skip`, and `#enqueue()` is skipped again |
|
|
79
|
+
| `test/integration/spec/presence.js` | Live-service cases for every method and the Mercury update; `describe.skip` with the ticket SPARK-413317 |
|
|
80
|
+
| `README.md` | Retained npm page; context only. Its Usage block shows a placeholder member and no method; see `docs/adr/0001-retain-product-readme.md` |
|
|
81
|
+
| Sibling package webex-core, files src/docs/README.md, src/lib/batcher.js | Module spec consulted, agrees with code. `registerInternalPlugin` keys the plugin by its raw name and the first registration wins; registration `config` and `payloadTransformer` entries are merged into the global defaults (MOD-008); `transform` runs every matching predicate and named transform (MOD-037); `Batcher.request` shares one promise per fingerprint (MOD-050) and flushes on a capped debounce of at most `batcherMaxCalls` items (MOD-051). Source: a WebexHttpError flush failure falls back to rejecting every queued lookup when `options.body` has no `map`, and an unmatched response subject throws `Could not find pending request for received response` |
|
|
82
|
+
| Sibling package webex-core, files src/interceptors/docs/README.md, src/interceptors/payload-transformer.js | Interceptors spec consulted, agrees with code: every inbound response, and every inbound error, passes through `transform('inbound', …)` unless the request sets `disableTransform` (INT-018) |
|
|
83
|
+
| Sibling package webex-core, file src/lib/services/docs/README.md | Services spec consulted, agrees with code: `api` maps to `service` and the resource is joined to the catalog URL (SVC-022), so `api: 'apheleia'` and `service: 'apheleia'` address the same service |
|
|
84
|
+
| Sibling package internal-plugin-mercury, files src/docs/README.md, src/mercury.js | Module spec consulted. It agrees with code that `connect` resolves at once when connected and that an envelope with a dotted `data.eventType` is emitted as `event:<eventType>` (MOD-009). Its session-suffixed connection model is stale; `src/mercury.js` has one `connect(webSocketUrl)` that registers the device first, and is the referee |
|
|
85
|
+
| Sibling package internal-plugin-feature, files src/docs/README.md, src/feature.js | Module spec consulted, agrees with code and names this package as a `getFeature` consumer. `getFeature` resolves the value or `null` (MOD-003, MOD-004); `setFeature` POSTs `{key, mutable: true, val}` and resolves the merged record (MOD-006) |
|
|
86
|
+
| Sibling package internal-plugin-device, files src/docs/README.md, src/device.js | Spec consulted: `userId` is a registration DTO property set from the WDM body |
|
|
87
|
+
| Sibling package test-helper-mock-webex, file src/index.js | `presence` is in its `nonInternalPlugins` list, so `new MockWebex({children: {presence}})` mounts the plugin at `webex.presence`, not `webex.internal.presence` |
|
|
88
|
+
| Workspace search for consumers | `webex`, `webex-node`, and `@webex/recipe-private-web-client` import the package; no workspace source calls `webex.internal.presence` or sets `config.presence.initializeWorker`. The public `@webex/plugin-presence` is a separate TypeScript package that no workspace package imports |
|
|
89
|
+
| Observation, no stated WHY | Behavior the code shows without stating a reason is recorded once, under Pitfalls and constraints |
|
|
90
|
+
|
|
91
|
+
## Purpose and boundary
|
|
92
|
+
|
|
93
|
+
- Responsibility: let a Webex client read and set user presence, subscribe to presence changes, and
|
|
94
|
+
switch the presence feature on or off; and, through the worker, keep the presence of the users the
|
|
95
|
+
client is showing fresh with as few lookups and subscriptions as possible, telling the client what
|
|
96
|
+
changed through `updated` events.
|
|
97
|
+
- In scope: registration of `presence`, its batcher defaults, and its inbound response transform;
|
|
98
|
+
`enable`, `disable`, `isEnabled`; `get`, `list`, `subscribe`, `unsubscribe`, `setStatus`;
|
|
99
|
+
`emitEvent`; the worker's start, watch counting, fetch, subscription, renewal, and expiry.
|
|
100
|
+
- Out of scope: what the presence service stores or composes; the request coalescing and flush timing
|
|
101
|
+
of the webex-core `Batcher`; Mercury's socket and event dispatch (`@webex/internal-plugin-mercury`);
|
|
102
|
+
feature-toggle storage (`@webex/internal-plugin-feature` and the device plugin); device registration
|
|
103
|
+
and `userId` (`@webex/internal-plugin-device`); authorization, service-catalog resolution, and the
|
|
104
|
+
transform pipeline (webex-core); keeping the presence objects themselves, which the client does.
|
|
105
|
+
- Consumers: `webex`, `webex-node`, and `@webex/recipe-private-web-client` import the package to
|
|
106
|
+
register it. No in-repo code calls `webex.internal.presence`; first-party clients reach it there.
|
|
107
|
+
|
|
108
|
+
## Structure and key files
|
|
109
|
+
|
|
110
|
+
| Path | Responsibility |
|
|
111
|
+
| ---- | -------------- |
|
|
112
|
+
| `src/index.js` | Imports the device plugin, registers internal plugin `presence` with its transform and config, and exports the class as default |
|
|
113
|
+
| `src/presence.js` | `Presence`: the feature toggle, the presence service requests, `emitEvent`, and the worker entry points |
|
|
114
|
+
| `src/presence-batcher.js` | `PresenceBatcher`: batches `list` lookups into `compositions` requests |
|
|
115
|
+
| `src/presence-worker.js` | `PresenceWorker`: watch counting, fetches, subscriptions, renewal, expiry, and `updated` envelopes |
|
|
116
|
+
| `src/constants.js` | Worker timings, event names, and envelope types |
|
|
117
|
+
| `src/config.js` | Defaults under `presence` |
|
|
118
|
+
| `package.json` | Package name, entry points, scripts, and dependencies |
|
|
119
|
+
| `babel.config.js`, `jest.config.js` | Re-exports of the legacy Babel and Jest configurations |
|
|
120
|
+
| `.eslintrc.js` | Sets `root: true` and extends `@webex/eslint-config-legacy` |
|
|
121
|
+
| `process` | Package-root file exporting `{browser: true}`; not imported by `src/` |
|
|
122
|
+
| `src/docs/README.md` | This module specification; ignored by the build and by lint |
|
|
123
|
+
| `test/unit/spec/presence.js`, `test/unit/spec/presence-worker.js` | Unit cases run by `test:unit`; every case is skipped |
|
|
124
|
+
| `test/integration/spec/presence.js` | Live-service cases run by `test:browser`; skipped |
|
|
125
|
+
| dist/ (generated) | Build output of `build:src`; ignored by Git and never edited by hand |
|
|
126
|
+
|
|
127
|
+
## Public surface
|
|
128
|
+
|
|
129
|
+
| Surface | Consumer | Compatibility commitment | Source |
|
|
130
|
+
| ------- | -------- | ------------------------ | ------ |
|
|
131
|
+
| Import side effect: internal plugin `presence` with the defaults of `MOD-002` and the transform of `MOD-003`, plus the device plugin | `webex`, `webex-node`, `@webex/recipe-private-web-client` | First registration of the name wins; reached as `webex.internal.presence` | `src/index.js`, `src/config.js` |
|
|
132
|
+
| `enable()`, `disable()`, `isEnabled()` | First-party clients | Resolve the `user-presence-enabled` toggle value | `src/presence.js` |
|
|
133
|
+
| `get(personId)`, `list(personIds)` | First-party clients; the worker calls `list` | Resolve a presence status object, or `{statusList}` in input order | `src/presence.js` |
|
|
134
|
+
| `subscribe(personIds, subscriptionTtl)`, `unsubscribe(personIds)` | First-party clients; the worker calls `subscribe` | Resolve `{responses}`, or the raw unsubscribe response | `src/presence.js` |
|
|
135
|
+
| `setStatus(status, ttl)` | First-party clients | Resolves the events response body | `src/presence.js` |
|
|
136
|
+
| `initializeWorker()`, `enqueue(id)`, `dequeue(id)` | First-party clients | Drive the worker of `MOD-012` to `MOD-017` | `src/presence.js` |
|
|
137
|
+
| Event `updated` on `webex.internal.presence` with `{type, payload}` | First-party clients | Envelope types `subscription`, `presence`, `delete` | `src/presence-worker.js`, `src/constants.js` |
|
|
138
|
+
| `emitEvent(event, payload)`, `batcher`, `worker` | The worker; tests | Reachable on the instance but not a supported entry | `src/presence.js` |
|
|
139
|
+
| Default export `Presence` | Clients that mount the class themselves | The entry exports nothing else | `src/index.js` |
|
|
140
|
+
|
|
141
|
+
Contract ID `presence-internal-sdk` is indexed in the
|
|
142
|
+
[package architecture](../../docs/architecture.md#public-and-consumer-surfaces) and registered in
|
|
143
|
+
`.sdd/manifest.json`. Export stability is under [Export stability](#export-stability).
|
|
144
|
+
|
|
145
|
+
## Dependencies
|
|
146
|
+
|
|
147
|
+
| Dependency | Why it is required | Failure behavior |
|
|
148
|
+
| ---------- | ------------------ | ---------------- |
|
|
149
|
+
| `@webex/webex-core` plugin host (module spec consulted) | `registerInternalPlugin`, `WebexPlugin` (`webex`, `config`, `trigger`), `webex.request`, `webex.ready`, and the `ready` event | A request rejection rejects the method |
|
|
150
|
+
| `@webex/webex-core` `Batcher` (module spec consulted; code consulted) | Coalesces `list` lookups for `MOD-007` | A failed flush rejects every lookup in it |
|
|
151
|
+
| `@webex/webex-core` transform pipeline and services (interceptors and services specs consulted) | Runs the `MOD-003` transform on inbound responses; resolves `apheleia` from the catalog | See Pitfalls for the global scope of the transform |
|
|
152
|
+
| `@webex/internal-plugin-mercury` (module spec consulted, stale on sessions; code used) | `connected`, `connect()`, and the `event:apheleia.subscription_update` event for `MOD-012` and `MOD-015` | A `connect` rejection leaves the worker without updates (see Pitfalls) |
|
|
153
|
+
| `@webex/internal-plugin-feature` (module spec consulted) | `setFeature` and `getFeature` for `MOD-004` | Not declared in `package.json` or imported; the host must register it |
|
|
154
|
+
| `@webex/internal-plugin-device` (spec consulted) | Imported for registration; `userId` for `MOD-010` | An unset `userId` is sent as is |
|
|
155
|
+
| `lodash` | `has` for the transform predicate; `debounce` for the worker fetch | Not applicable |
|
|
156
|
+
| Presence service (external, catalog name `apheleia`) | Compositions, subscriptions, and events | Errors propagate |
|
|
157
|
+
|
|
158
|
+
`package.json` also lists four `@webex/test-helper-*` packages under `dependencies`; `src/` imports
|
|
159
|
+
none of them. The specs import them.
|
|
160
|
+
|
|
161
|
+
## Requirements
|
|
162
|
+
|
|
163
|
+
| ID | WHAT | WHY | Source evidence | Test or example evidence | Assumptions or gaps | Confidence |
|
|
164
|
+
| -- | ---- | --- | --------------- | ------------------------ | ------------------- | ---------- |
|
|
165
|
+
| `MOD-001` | Importing the package first imports `@webex/internal-plugin-device`, then registers `Presence` as internal plugin `presence` with the transform of `MOD-003` and the config of `MOD-002`, so the plugin is `webex.internal.presence`. | `setStatus` reads `webex.internal.device.userId`, so the device plugin must be registered with this one (inferred from the import and the read; no comment states it). | `src/index.js` | None found | WHY inferred from code; registration untested | Weak |
|
|
166
|
+
| `MOD-002` | Default config `presence` is `{batcherWait: 50, batcherMaxCalls: 50, batcherMaxWait: 150}`. `initializeWorker` has no default. | The webex-core `Batcher` reads its flush timing from its namespace's config and has no defaults of its own (webex-core MOD-051). | `src/config.js` | None found | No test asserts the defaults | Present |
|
|
167
|
+
| `MOD-003` | The inbound predicate `normalizeSingleStatusResponse` matches any response whose `body` has both `eventType` and `subject`, and its transform sets `body.status` to `body.eventType`. | The comment names the events endpoint: its response reports the status as `eventType`, and the transform gives it the `status` field of a presence status object (inferred from the typedef; no comment states the second half). | `src/index.js` | None found | WHY partly inferred; untested | Weak |
|
|
168
|
+
| `MOD-004` | `enable()` and `disable()` call `webex.internal.feature.setFeature('user', 'user-presence-enabled', true or false)` and resolve the merged record's `value`; `isEnabled()` resolves `getFeature('user', 'user-presence-enabled')`, which is the value or `null`. | The JSDoc: these enable and disable the presence feature and report whether it is enabled. | `src/presence.js` | `test/integration/spec/presence.js` enable, disable, and isEnabled cases (skipped) | No unit case | Weak |
|
|
169
|
+
| `MOD-005` | `get(personId)` rejects with `A person id is required` when `personId` is falsy; otherwise sends `GET` to service `apheleia`, resource `compositions?userId=<personId>`, and resolves the response body. | The JSDoc: it gets the current presence status of one person. | `src/presence.js` | `test/unit/spec/presence.js` #get(); `test/integration/spec/presence.js` #get() (both skipped) | None | Present |
|
|
170
|
+
| `MOD-006` | `list(personIds)` rejects with `An array of person ids is required` unless `personIds` is an array; otherwise it requests each id through `batcher.request` and resolves `{statusList}` with the results in input order. | The JSDoc: it gets the presence statuses of many people as `statusList`. | `src/presence.js` | `test/unit/spec/presence.js` #list(); `test/integration/spec/presence.js` #list() (both skipped) | None | Present |
|
|
171
|
+
| `MOD-007` | `PresenceBatcher` uses each id as its own request and response fingerprint, so duplicate ids share one pending lookup; a flush sends `POST` with `api: 'apheleia'`, resource `compositions`, body `{subjects: <ids>}`, and resolves each pending id with the `statusList` entry whose `subject` matches it. The flush timing and size follow `MOD-002` (webex-core MOD-050, MOD-051). | Collapses lookups made close together into one request (webex-core spec, MOD-050 and MOD-051). | `src/presence-batcher.js` | `test/integration/spec/presence.js` batching case (skipped) | No unit case | Weak |
|
|
172
|
+
| `MOD-008` | `subscribe(personIds, subscriptionTtl = 600)` rejects with `A person id is required` when `personIds` is falsy; it takes one id or an array, splits it into batches of 50, sends one `POST` per batch with `api: 'apheleia'`, resource `subscriptions`, body `{subjects, subscriptionTtl, includeStatus: true}`, all at once, and resolves `{responses}` with each batch's `body.responses` concatenated in batch order. | The JSDoc: updates then arrive as the Mercury event `apheleia.subscription_update`, and the TTL is in seconds; the comment: at most 50 ids per request. | `src/presence.js` | `test/unit/spec/presence.js` #subscribe(), including 100 ids in two requests; `test/integration/spec/presence.js` #subscribe (both skipped) | None | Present |
|
|
173
|
+
| `MOD-009` | `unsubscribe(personIds)` rejects with `A person id is required` when `personIds` is falsy; otherwise sends one `POST` with `api: 'apheleia'`, resource `subscriptions`, body `{subjects, subscriptionTtl: 0, includeStatus: true}`, without batching, and resolves the whole HTTP response. | The JSDoc: it unsubscribes from one person or a group; a zero TTL ends the subscription (inferred from the body). | `src/presence.js` | `test/unit/spec/presence.js` #unsubscribe(); `test/integration/spec/presence.js` #unsubscribe (both skipped) | WHY of the zero TTL inferred | Present |
|
|
174
|
+
| `MOD-010` | `setStatus(status, ttl)` rejects with `A status is required` when `status` is falsy; otherwise sends `POST` with `api: 'apheleia'`, resource `events`, body `{subject: device.userId, eventType: status, label: device.userId, ttl}`, leaving out `label` when `status` is `'dnd'`, and resolves the response body as normalized by `MOD-003`. | The JSDoc: it sets the current user's status, one of `active`, `inactive`, `ooo`, `dnd`, for `ttl` seconds. No comment states why `dnd` has no label. | `src/presence.js` | `test/unit/spec/presence.js` #setStatus(), label and no-label cases (skipped) | WHY of the `dnd` rule unknown; see Pitfalls for the integration expectation | Present |
|
|
175
|
+
| `MOD-011` | `emitEvent(event, payload)` triggers `event` on the plugin with `payload` only when `payload.type` and `payload.payload` are both truthy. The worker emits `updated` with `{type: 'subscription' or 'presence' or 'delete', payload}`. | Gives the client one event with a typed envelope for every worker change (inferred from the constants; no comment states it). | `src/presence.js`, `src/constants.js` | `test/unit/spec/presence-worker.js` checkFetchers and cleanPresences cases (skipped) | WHY inferred | Weak |
|
|
176
|
+
| `MOD-012` | On the webex `ready` event, `initialize` starts the worker when `config.initializeWorker` is truthy. `initializeWorker()` starts it now when `webex.ready`, else on `ready`. Starting it throws `Must initialize Presence Worker with webex!` when webex or `webex.internal` is missing; otherwise it calls `mercury.connect()` unless `mercury.connected`, then listens to `event:apheleia.subscription_update`, and starts the groundskeeper of `MOD-016` every 20 seconds. | The JSDoc: the worker connects to Mercury for presence and starts. | `src/presence.js`, `src/presence-worker.js` | `test/unit/spec/presence.js` #initializeWorker(); `test/unit/spec/presence-worker.js` #initialize() (both skipped) | None | Present |
|
|
177
|
+
| `MOD-013` | `enqueue(id)` adds one watcher for `id`. When `id` has a truthy subscription expiration it stops there. Otherwise it records the first camping time for `id`, and when no fetch is in flight for `id` and its last update is missing or older than one minute, it queues `id` and schedules a fetch 300 ms after the last such call. `dequeue(id)` removes one watcher; at zero it also drops `id`'s watcher count, queued fetch, and camping time. | The JSDoc: enqueue retrieves and subscribes to a user's presence, and dequeue retracts it; the comment lists when a fetch is needed. | `src/presence-worker.js`, `src/constants.js` | `test/unit/spec/presence-worker.js` #enqueue() and #dequeue() (skipped; #enqueue() skipped again) | None | Present |
|
|
178
|
+
| `MOD-014` | A fetch moves the queued ids to in flight and calls `presence.list(ids)`. When it resolves, each returned `subject` leaves in flight and gets an update time of now, and the worker emits `updated` with `{type: 'presence', payload: <list result>}`. | The JSDoc: it retrieves users' presences. | `src/presence-worker.js` | `test/unit/spec/presence-worker.js` #checkFetchers() (skipped) | None | Present |
|
|
179
|
+
| `MOD-015` | On `event:apheleia.subscription_update`, the worker sets the update time of `event.data.subject` to now and emits `updated` with `{type: 'subscription', payload: event.data}`. | The JSDoc: it triggers a subscription update event. | `src/presence-worker.js` | `test/integration/spec/presence.js` Mercury event case (skipped) | No unit case | Weak |
|
|
180
|
+
| `MOD-016` | Every 20 seconds the groundskeeper subscribes ids that have camped more than one minute (marking them with a `null` expiration) and renews ids that are still watched and expire within one minute; it deletes expired subscriptions that are not renewed. It calls `presence.subscribe(ids)` with the default TTL when any id is due; for each response with `responseCode` 200 it sets the expiration to now plus `subscriptionTtl` seconds and the update time of `status.subject` to now, and for any other code it sets the expiration to now plus 10 minutes. It then runs `MOD-017`. | The comments: subscribe after camping for a minute, renew when about to expire, and give a failed subscription an expiration "so we clean it out eventually". | `src/presence-worker.js`, `src/constants.js` | `test/unit/spec/presence-worker.js` #checkCampers(), #checkSubscriptions(), #groundskeeper() (skipped) | None | Present |
|
|
181
|
+
| `MOD-017` | `cleanPresences` deletes every update time older than 10 minutes and, when any was deleted, emits `updated` with `{type: 'delete', payload: <ids>}`. | The comments: remove stale presence objects and tell the client to delete them too. | `src/presence-worker.js`, `src/constants.js` | `test/unit/spec/presence-worker.js` #cleanPresences() (skipped) | None | Present |
|
|
182
|
+
|
|
183
|
+
## Design overview
|
|
184
|
+
|
|
185
|
+
`Presence` is a `WebexPlugin` with two parts. The first is a set of thin requests to the presence
|
|
186
|
+
service: read one user, read many users through a batcher, subscribe, unsubscribe, and set the
|
|
187
|
+
current user's status. The presence feature toggle goes through the feature plugin.
|
|
188
|
+
|
|
189
|
+
The second part is `PresenceWorker`, created per plugin instance but started only on request. A client
|
|
190
|
+
calls `enqueue(id)` when it starts showing a user and `dequeue(id)` when it stops. The worker fetches
|
|
191
|
+
that user's presence soon, subscribes once the user has been shown for a minute, renews the
|
|
192
|
+
subscription while the user is still shown, and lets it lapse otherwise. It keeps only times and
|
|
193
|
+
counts, never the presence objects; each change goes to the client as an `updated` event, and the
|
|
194
|
+
client keeps the data.
|
|
195
|
+
|
|
196
|
+
Registration also adds one inbound transform to the SDK's global transform pipeline, so the events
|
|
197
|
+
response carries a `status` field like the other presence responses.
|
|
198
|
+
|
|
199
|
+
## Data flow and sequence coverage
|
|
200
|
+
|
|
201
|
+
Call style: in-process method calls on `webex.internal.presence`; outbound HTTPS through
|
|
202
|
+
`webex.request`; inbound Mercury events; outbound plugin events. Three operation groups differ in
|
|
203
|
+
actors and outcome, and each has a diagram.
|
|
204
|
+
|
|
205
|
+
| Operation group | Entry and outcome | Diagram or evidence | Failure and recovery coverage |
|
|
206
|
+
| --------------- | ----------------- | ------------------- | ----------------------------- |
|
|
207
|
+
| Direct requests | `get`, `list`, `subscribe`, `unsubscribe`, `setStatus`, and the feature toggle resolve service results | Diagram 1; `src/presence.js`, `src/presence-batcher.js` | Argument checks and request errors reject |
|
|
208
|
+
| Worker watch and fetch | `enqueue` leads to a batched lookup and an `updated` presence envelope | Diagram 2; `src/presence-worker.js` | A failed lookup is not caught (see Pitfalls) |
|
|
209
|
+
| Worker subscription upkeep | The groundskeeper subscribes, renews, expires, and Mercury delivers updates | Diagram 3; `src/presence-worker.js` | A failed subscribe is not caught; a non-200 code gets a fallback expiration |
|
|
210
|
+
|
|
211
|
+
Diagram 1 — direct requests:
|
|
212
|
+
|
|
213
|
+
```mermaid
|
|
214
|
+
sequenceDiagram
|
|
215
|
+
participant C as Caller
|
|
216
|
+
participant P as Presence
|
|
217
|
+
participant B as PresenceBatcher
|
|
218
|
+
participant F as feature plugin
|
|
219
|
+
participant A as apheleia
|
|
220
|
+
C->>P: list([id1, id2])
|
|
221
|
+
P->>B: request(id1), request(id2)
|
|
222
|
+
B->>A: POST compositions {subjects}
|
|
223
|
+
A-->>B: {statusList}
|
|
224
|
+
B-->>P: status per id
|
|
225
|
+
P-->>C: {statusList}
|
|
226
|
+
C->>P: subscribe(ids, ttl)
|
|
227
|
+
P->>A: POST subscriptions per 50 ids
|
|
228
|
+
A-->>P: {responses}
|
|
229
|
+
P-->>C: {responses}
|
|
230
|
+
C->>P: setStatus(status, ttl)
|
|
231
|
+
P->>A: POST events {subject, eventType, label?, ttl}
|
|
232
|
+
A-->>P: body, status added by the transform
|
|
233
|
+
P-->>C: body
|
|
234
|
+
C->>P: enable()
|
|
235
|
+
P->>F: setFeature(user, user-presence-enabled, true)
|
|
236
|
+
F-->>P: record
|
|
237
|
+
P-->>C: record.value
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Diagram 2 — worker watch and fetch:
|
|
241
|
+
|
|
242
|
+
```mermaid
|
|
243
|
+
sequenceDiagram
|
|
244
|
+
participant C as Client
|
|
245
|
+
participant P as Presence
|
|
246
|
+
participant W as PresenceWorker
|
|
247
|
+
C->>P: enqueue(id)
|
|
248
|
+
P->>W: enqueue(id)
|
|
249
|
+
Note over W: watcher +1, camping time set, fetch queued when stale
|
|
250
|
+
W->>W: debounced fetch after 300 ms
|
|
251
|
+
W->>P: list(queued ids)
|
|
252
|
+
P-->>W: {statusList}
|
|
253
|
+
W->>P: emitEvent(updated, {type: presence, payload})
|
|
254
|
+
P-->>C: updated
|
|
255
|
+
C->>P: dequeue(id)
|
|
256
|
+
P->>W: dequeue(id)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Diagram 3 — worker subscription upkeep:
|
|
260
|
+
|
|
261
|
+
```mermaid
|
|
262
|
+
sequenceDiagram
|
|
263
|
+
participant W as PresenceWorker
|
|
264
|
+
participant P as Presence
|
|
265
|
+
participant M as Mercury
|
|
266
|
+
participant A as apheleia
|
|
267
|
+
participant C as Client
|
|
268
|
+
W->>M: connect() unless connected
|
|
269
|
+
W->>M: on(event:apheleia.subscription_update)
|
|
270
|
+
loop every 20 s
|
|
271
|
+
W->>W: campers over 1 min, renewals within 1 min
|
|
272
|
+
opt ids due
|
|
273
|
+
W->>P: subscribe(ids)
|
|
274
|
+
P->>A: POST subscriptions
|
|
275
|
+
A-->>W: {responses}
|
|
276
|
+
Note over W: expiration from subscriptionTtl, or 10 min when not 200
|
|
277
|
+
end
|
|
278
|
+
W->>W: cleanPresences
|
|
279
|
+
opt update times older than 10 min
|
|
280
|
+
W->>P: emitEvent(updated, {type: delete, payload: ids})
|
|
281
|
+
P-->>C: updated
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
M-->>W: event:apheleia.subscription_update
|
|
285
|
+
W->>P: emitEvent(updated, {type: subscription, payload: event.data})
|
|
286
|
+
P-->>C: updated
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Class and component relationships
|
|
290
|
+
|
|
291
|
+
```mermaid
|
|
292
|
+
classDiagram
|
|
293
|
+
class WebexPlugin
|
|
294
|
+
class Batcher
|
|
295
|
+
class Presence {
|
|
296
|
+
namespace Presence
|
|
297
|
+
batcher
|
|
298
|
+
worker
|
|
299
|
+
enable() disable() isEnabled()
|
|
300
|
+
get(personId) list(personIds)
|
|
301
|
+
subscribe(personIds, subscriptionTtl) unsubscribe(personIds)
|
|
302
|
+
setStatus(status, ttl)
|
|
303
|
+
initializeWorker() enqueue(id) dequeue(id)
|
|
304
|
+
emitEvent(event, payload)
|
|
305
|
+
}
|
|
306
|
+
class PresenceBatcher {
|
|
307
|
+
namespace Presence
|
|
308
|
+
submitHttpRequest(subjects)
|
|
309
|
+
handleHttpSuccess(res)
|
|
310
|
+
}
|
|
311
|
+
class PresenceWorker {
|
|
312
|
+
presences watchers fetchers flights campers subscribers
|
|
313
|
+
initialize(webex)
|
|
314
|
+
enqueue(id) dequeue(id)
|
|
315
|
+
groundskeeper()
|
|
316
|
+
}
|
|
317
|
+
WebexPlugin <|-- Presence
|
|
318
|
+
Batcher <|-- PresenceBatcher
|
|
319
|
+
Presence *-- PresenceBatcher : child batcher
|
|
320
|
+
Presence *-- PresenceWorker : session worker
|
|
321
|
+
PresenceWorker ..> Presence : list, subscribe, emitEvent
|
|
322
|
+
PresenceWorker ..> mercury : connect, on
|
|
323
|
+
Presence ..> feature : setFeature, getFeature
|
|
324
|
+
Presence ..> device : userId
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## Use cases and flows
|
|
328
|
+
|
|
329
|
+
| Use case | Actor or caller | Primary steps and outcome | Failure or boundary behavior | Evidence |
|
|
330
|
+
| -------- | --------------- | ------------------------- | ---------------------------- | -------- |
|
|
331
|
+
| `UC-001` | Client showing a list of people | `initializeWorker()` once; `enqueue(id)` per shown person, `dequeue(id)` when hidden; handle `updated` envelopes | The worker reports nothing for an id whose lookup or subscription fails | `src/presence.js`, `src/presence-worker.js` |
|
|
332
|
+
| `UC-002` | Client reading presence directly | `get(id)` or `list(ids)` | Argument checks and request errors reject | `src/presence.js` |
|
|
333
|
+
| `UC-003` | Client managing its own subscriptions | `subscribe(ids, ttl)`, then Mercury `event:apheleia.subscription_update`; `unsubscribe(ids)` | Request errors reject; Mercury must be connected by the client | `src/presence.js` |
|
|
334
|
+
| `UC-004` | Client setting the user's status | `setStatus('dnd', ttl)` and other statuses | Request errors reject | `src/presence.js` |
|
|
335
|
+
| `UC-005` | Client switching the presence feature | `enable()`, `disable()`, `isEnabled()` | Requires the feature plugin | `src/presence.js` |
|
|
336
|
+
|
|
337
|
+
### Cross-boundary use-case flow
|
|
338
|
+
|
|
339
|
+
| Boundary | Transport and ordering | Compatibility | Timeout, retry, and recovery |
|
|
340
|
+
| -------- | ---------------------- | ------------- | ---------------------------- |
|
|
341
|
+
| Presence service (`UC-001` to `UC-004`) | HTTPS through `webex.request`, service `apheleia` from the catalog; subscribe batches run concurrently | Bodies under Protocol and wire format | No retry or timeout in this module; webex-core interceptors apply |
|
|
342
|
+
| Mercury (`UC-001`, `UC-003`) | One listener for `event:apheleia.subscription_update` per started worker | Event name from `src/constants.js` | Mercury owns reconnects; the worker re-subscribes only through renewal |
|
|
343
|
+
| Feature plugin (`UC-005`) | In-process call; it POSTs to the feature service | `user` key type, key `user-presence-enabled` | Its rejection rejects the method |
|
|
344
|
+
|
|
345
|
+
## Client state model
|
|
346
|
+
|
|
347
|
+
| State or slice | Owner | Initial state | Transition triggers | Reset or persistence boundary |
|
|
348
|
+
| -------------- | ----- | ------------- | ------------------- | ----------------------------- |
|
|
349
|
+
| `watchers` (count per id) | `PresenceWorker` | Empty | `enqueue` adds, `dequeue` removes (`MOD-013`) | In memory for the life of the plugin |
|
|
350
|
+
| `campers` (first camping time per id) | `PresenceWorker` | Empty | `enqueue` sets; groundskeeper or last `dequeue` removes (`MOD-013`, `MOD-016`) | Same |
|
|
351
|
+
| `fetchers`, `flights` (queued and in-flight lookups) | `PresenceWorker` | Empty | `enqueue` queues; fetch moves to flight; a returned subject leaves flight (`MOD-014`) | Same |
|
|
352
|
+
| `subscribers` (expiration per id, or `null` while subscribing) | `PresenceWorker` | Empty | Groundskeeper sets, renews, and deletes (`MOD-016`) | Same; not cleared by `dequeue` |
|
|
353
|
+
| `presences` (last update time per id) | `PresenceWorker` | Empty | Fetch, subscription response, Mercury event; expiry deletes (`MOD-014` to `MOD-017`) | Same |
|
|
354
|
+
| `deferreds`, `queue` | `PresenceBatcher` (webex-core `Batcher`) | Empty | `list` lookups and flushes | Entries removed when a lookup settles |
|
|
355
|
+
| `config.presence` | webex-core config, defaults from `src/config.js` | `MOD-002` | Host config at construction | For the life of the SDK instance |
|
|
356
|
+
|
|
357
|
+
## Business rules and invariants
|
|
358
|
+
|
|
359
|
+
| ID | Invariant | WHY | Enforcement source | Test evidence |
|
|
360
|
+
| -- | --------- | --- | ------------------ | ------------- |
|
|
361
|
+
| `INV-001` | A `subscribe` request carries at most 50 subjects. | The code comment limits batches to 50 ids per request. | `src/presence.js` | `test/unit/spec/presence.js` (skipped) |
|
|
362
|
+
| `INV-002` | A `compositions` request carries at most `batcherMaxCalls` subjects. | Bounds the payload of a batched lookup (webex-core MOD-051). | `src/presence-batcher.js`, `src/config.js` | None found |
|
|
363
|
+
| `INV-003` | `setStatus` sends `label` exactly when `status` is not `'dnd'`. | Stated only by the code and its unit cases; no reason is given. | `src/presence.js` | `test/unit/spec/presence.js` (skipped) |
|
|
364
|
+
| `INV-004` | `enqueue` never queues a lookup for an id with a truthy subscription expiration, or for an id already in flight. | Subscribed users get updates from Mercury, and one lookup at a time is enough (inferred from the comment listing when to fetch). | `src/presence-worker.js` | `test/unit/spec/presence-worker.js` (skipped) |
|
|
365
|
+
| `INV-005` | The worker emits `updated` only through `emitEvent`, and `emitEvent` drops an envelope without both `type` and `payload`. | The client handles one typed envelope shape (inferred from `MOD-011`). | `src/presence.js`, `src/presence-worker.js` | None found |
|
|
366
|
+
| `INV-006` | Argument checks of `get`, `list`, `subscribe`, `unsubscribe`, and `setStatus` reject the returned promise instead of throwing. | Callers handle every failure on the promise (inferred from the uniform `Promise.reject`). | `src/presence.js` | `test/unit/spec/presence.js` (skipped) |
|
|
367
|
+
|
|
368
|
+
## Concurrency and reactive flow
|
|
369
|
+
|
|
370
|
+
- Execution model: one JavaScript event loop; every request method returns a promise; the worker
|
|
371
|
+
runs a lodash `debounce` of 300 ms for lookups and a `setInterval` of 20 seconds for upkeep.
|
|
372
|
+
- Ordering guarantees: `list` resolves in input order. `subscribe` sends its batches at once and
|
|
373
|
+
concatenates the results in batch order. Within a flush, the batcher sends lookups in request order.
|
|
374
|
+
- Idempotency and retry: nothing is retried here. Duplicate ids within one batching window share one
|
|
375
|
+
lookup (`MOD-007`). A lapsed subscription is renewed only while the id is watched.
|
|
376
|
+
- Fire-and-forget work: the worker's fetch, subscribe, and Mercury connect promises are not awaited;
|
|
377
|
+
their failure effects are under Pitfalls and constraints.
|
|
378
|
+
- Shared-state protection: none beyond the event loop. A fetch, a groundskeeper run, and a Mercury
|
|
379
|
+
event can each update `presences` for the same id in any order.
|
|
380
|
+
|
|
381
|
+
## State machine
|
|
382
|
+
|
|
383
|
+
```mermaid
|
|
384
|
+
stateDiagram-v2
|
|
385
|
+
[*] --> untracked
|
|
386
|
+
untracked --> camping: enqueue
|
|
387
|
+
camping --> untracked: last dequeue
|
|
388
|
+
camping --> subscribing: groundskeeper, camped over 1 min
|
|
389
|
+
subscribing --> subscribed: subscribe response
|
|
390
|
+
subscribed --> subscribing: groundskeeper, watched and within 1 min of expiry
|
|
391
|
+
subscribed --> untracked: groundskeeper, expired and not watched
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
The subscription life of one id in the worker. `camping` holds a camping time; `subscribing` holds a
|
|
395
|
+
`null` expiration; `subscribed` holds an expiration, from `subscriptionTtl` on a 200 response or
|
|
396
|
+
10 minutes on any other code. A renewal keeps the old expiration until its response arrives. Watch
|
|
397
|
+
counting (`MOD-013`) and the presence update time (`MOD-017`) run alongside: `dequeue` never leaves
|
|
398
|
+
`subscribing` or `subscribed`, and the update time expires on its own clock.
|
|
399
|
+
|
|
400
|
+
## Protocol and wire format
|
|
401
|
+
|
|
402
|
+
| Message or frame | Version | Producer or serializer | Consumer or parser | Compatibility and ordering rule |
|
|
403
|
+
| ---------------- | ------- | ---------------------- | ------------------ | ------------------------------- |
|
|
404
|
+
| `GET <apheleia>/compositions?userId=<personId>` | Unversioned | `get` | Presence service | Response body: one presence status object (`url`, `subject`, `status`, `statusTime`, `lastActive`, `expires`, `expiresTTL`, `expiresTime`, `vectorCounters`, `suppressNotifications`, `lastSeenDeviceUrl`, per the JSDoc typedef) |
|
|
405
|
+
| `POST <apheleia>/compositions`, body `{subjects: [<id>]}` | Unversioned | `PresenceBatcher` | Presence service | Response `{statusList: [<status object>]}`, matched to requests by `subject` |
|
|
406
|
+
| `POST <apheleia>/subscriptions`, body `{subjects, subscriptionTtl, includeStatus: true}` | Unversioned | `subscribe`; `unsubscribe` with `subscriptionTtl: 0` | Presence service | Response `{responses: [{subject, responseCode, subscriptionTtl, status}]}`; the worker reads these four fields |
|
|
407
|
+
| `POST <apheleia>/events`, body `{subject, eventType, label, ttl}` | Unversioned | `setStatus` | Presence service | `label` absent for `dnd` (`INV-003`); the response body gets `status` from `eventType` (`MOD-003`) |
|
|
408
|
+
| Mercury envelope, `data.eventType` `apheleia.subscription_update` | Unversioned | Presence service through Mercury | `PresenceWorker` | Reads `data.subject`; passes `data` on unchanged |
|
|
409
|
+
| Plugin event `updated`, `{type, payload}` | Unversioned | `PresenceWorker` through `emitEvent` | Client | `type` is `subscription` (payload: the Mercury `data`), `presence` (payload: the `list` result), or `delete` (payload: an array of ids) |
|
|
410
|
+
| Feature toggle `user` / `user-presence-enabled` | Unversioned | `enable`, `disable` through the feature plugin | Feature service | Value `true` or `false` |
|
|
411
|
+
|
|
412
|
+
## Caller-visible failure modes
|
|
413
|
+
|
|
414
|
+
| Condition | Signal or result | Caller behavior | Retry or recovery | Evidence |
|
|
415
|
+
| --------- | ---------------- | --------------- | ----------------- | -------- |
|
|
416
|
+
| Missing person id, non-array `list` argument, or missing status | Rejects with `A person id is required`, `An array of person ids is required`, or `A status is required` | Pass the argument | Call again | `src/presence.js` |
|
|
417
|
+
| The presence service rejects a request | The `webex.request` rejection, unchanged; one failed `subscribe` batch rejects the whole call | Handle the HTTP error | Call again | `src/presence.js` |
|
|
418
|
+
| A `compositions` flush fails | Every lookup in the flush rejects with the same error | Handle the error per `list` call | Call again | `src/presence-batcher.js` |
|
|
419
|
+
| A requested id is missing from a `statusList` | That lookup never settles, so its `list` call never resolves | Do not rely on `list` settling | None | `src/presence-batcher.js` |
|
|
420
|
+
| `webex.internal.feature` is not registered | `enable`, `disable`, and `isEnabled` throw `TypeError` synchronously | Register the feature plugin | None | `src/presence.js` |
|
|
421
|
+
| The worker is started without webex | `Must initialize Presence Worker with webex!` thrown synchronously | Start it through `initializeWorker()` | None | `src/presence-worker.js` |
|
|
422
|
+
|
|
423
|
+
## Pitfalls and constraints
|
|
424
|
+
|
|
425
|
+
- The worker starts only when a host calls `initializeWorker()` or sets
|
|
426
|
+
`config.presence.initializeWorker`; no workspace package does either (`MOD-012`).
|
|
427
|
+
- Each start adds another Mercury listener and another 20-second interval, and nothing removes them;
|
|
428
|
+
the plugin has no stop or logout hook, so calling `initializeWorker()` twice emits every
|
|
429
|
+
`subscription` envelope twice and runs the groundskeeper twice as often.
|
|
430
|
+
- The worker does not catch its own promises. A rejected lookup leaves its ids in flight, so `enqueue`
|
|
431
|
+
never fetches them again; a rejected `subscribe` leaves the newly subscribing ids with a `null`
|
|
432
|
+
expiration, which renewal and expiry skip, until a later `enqueue` makes them camp again; a rejected
|
|
433
|
+
Mercury `connect` means no listener is added.
|
|
434
|
+
- A `statusList` entry for an id that is not pending makes the batcher throw
|
|
435
|
+
`Could not find pending request for received response`, which rejects every lookup in that flush.
|
|
436
|
+
`PresenceBatcher.handleItemFailure` is never called, so no single item is treated as failed.
|
|
437
|
+
- The `MOD-003` transform is registered in the SDK-wide pipeline, so it rewrites `body.status` on any
|
|
438
|
+
inbound response or error with `body.eventType` and `body.subject`, not only presence responses. The
|
|
439
|
+
public `@webex/plugin-presence` registers a predicate and transform with the same name; a host
|
|
440
|
+
that loads both runs the transform more than once, with the same result.
|
|
441
|
+
- `get` addresses `service: 'apheleia'` and the other requests `api: 'apheleia'`; both resolve the
|
|
442
|
+
same catalog entry. `get` puts `personId` into the query string without encoding it.
|
|
443
|
+
- `unsubscribe` resolves the whole HTTP response while every other request method resolves the body.
|
|
444
|
+
- The integration case for `setStatus('dnd', …)` expects the response `label` to equal the user id,
|
|
445
|
+
although `INV-003` leaves `label` out of a `dnd` request; the case is skipped, so the conflict is
|
|
446
|
+
untested.
|
|
447
|
+
- The `setStatus` JSDoc lists `inactive`, while a comment in the integration spec says the service no
|
|
448
|
+
longer accepts it; the code sends any string.
|
|
449
|
+
- `test:style` reports four `require-jsdoc` warnings, three on the transform functions in
|
|
450
|
+
`src/index.js` and one on the `worker` default in `src/presence.js`, plus "File ignored" for this
|
|
451
|
+
specification.
|
|
452
|
+
|
|
453
|
+
## Module-specific rules
|
|
454
|
+
|
|
455
|
+
- Do: report worker changes only through `emitEvent(PRESENCE_UPDATE, {type: ENVELOPE_TYPE.…, payload})`
|
|
456
|
+
so the client sees one event and three envelope types (`INV-005`).
|
|
457
|
+
- Do: keep subscribe batches at 50 subjects (`INV-001`) and return argument failures as rejected
|
|
458
|
+
promises (`INV-006`).
|
|
459
|
+
- Do: keep the worker storing times and counts only; the client owns presence objects.
|
|
460
|
+
- Do not: log presence data, statuses, or user ids; the package has no log line today.
|
|
461
|
+
|
|
462
|
+
## Export stability
|
|
463
|
+
|
|
464
|
+
| Export or entry point | Consumer | Stability | Versioning and deprecation rule | Declaration or API report |
|
|
465
|
+
| --------------------- | -------- | --------- | ------------------------------- | ------------------------- |
|
|
466
|
+
| Import side effect: internal plugin `presence`, its config defaults, and its inbound transform | `webex`, `webex-node`, `@webex/recipe-private-web-client` | Internal | The README states that internal plugins do not strictly follow semantic versioning | `src/index.js` |
|
|
467
|
+
| Default export `Presence`, its request and worker methods, and the `updated` event | First-party clients | Internal | Same | `src/index.js`, `src/presence.js` |
|
|
468
|
+
|
|
469
|
+
The build writes JavaScript only; `package.json` has no `types` entry, so no declarations or API
|
|
470
|
+
report are published.
|
|
471
|
+
|
|
472
|
+
## Key design trade-off
|
|
473
|
+
|
|
474
|
+
| Chosen trade-off | Preserved invariant or benefit | Cost or limitation | Decision evidence |
|
|
475
|
+
| ---------------- | ------------------------------ | ------------------ | ----------------- |
|
|
476
|
+
| Subscribe only after a user has been watched for a minute | Users shown briefly never get a subscription | For the first minute the client sees only the fetched presence, with no live updates | `src/presence-worker.js`, `src/constants.js` |
|
|
477
|
+
| Batch `list` lookups through the webex-core `Batcher` | Fewer `compositions` requests; duplicate ids share one lookup | Up to 150 ms of added latency, and a missing subject never settles (see Caller-visible failure modes) | `src/presence-batcher.js`, `src/config.js` |
|
|
478
|
+
| Keep times and counts in the worker, not presence objects | One owner of presence data, the client, fed by `updated` envelopes | The client must merge `presence` and `subscription` envelopes and honor `delete` | `src/presence-worker.js` |
|
|
479
|
+
|
|
480
|
+
## Verification
|
|
481
|
+
|
|
482
|
+
| Requirement or invariant | Test level | Positive evidence | Negative or boundary evidence | Gap |
|
|
483
|
+
| ------------------------ | ---------- | ----------------- | ----------------------------- | --- |
|
|
484
|
+
| `MOD-001`, `MOD-002`, `MOD-003` | None | None found | None found | Registration, defaults, and transform untested |
|
|
485
|
+
| `MOD-004` | Integration (skipped) | `test/integration/spec/presence.js` | None found | No unit case |
|
|
486
|
+
| `MOD-005`, `MOD-006`, `INV-006` | Unit (skipped), integration (skipped) | `test/unit/spec/presence.js`, `test/integration/spec/presence.js` | `test/unit/spec/presence.js` argument cases | Nothing runs |
|
|
487
|
+
| `MOD-007`, `INV-002` | Integration (skipped) | `test/integration/spec/presence.js` batching case | None found | No unit case |
|
|
488
|
+
| `MOD-008`, `INV-001` | Unit (skipped), integration (skipped) | `test/unit/spec/presence.js` 100-id case | `test/unit/spec/presence.js` missing-id case | Nothing runs |
|
|
489
|
+
| `MOD-009` | Unit (skipped), integration (skipped) | `test/integration/spec/presence.js` | `test/unit/spec/presence.js` missing-id case | Nothing runs |
|
|
490
|
+
| `MOD-010`, `INV-003` | Unit (skipped), integration (skipped) | `test/unit/spec/presence.js` label case | `test/unit/spec/presence.js` dnd case | Integration expectation conflicts (see Pitfalls) |
|
|
491
|
+
| `MOD-011`, `INV-005` | Unit (skipped) | `test/unit/spec/presence-worker.js` emitEvent assertions | None found | `emitEvent` drop rule untested |
|
|
492
|
+
| `MOD-012` | Unit (skipped) | `test/unit/spec/presence.js` #initializeWorker() | `test/unit/spec/presence-worker.js` #initialize() | Nothing runs |
|
|
493
|
+
| `MOD-013`, `INV-004` | Unit (skipped) | `test/unit/spec/presence-worker.js` #enqueue() and #dequeue() | `test/unit/spec/presence-worker.js` in-flight and recent-presence cases | Nothing runs |
|
|
494
|
+
| `MOD-014` | Unit (skipped) | `test/unit/spec/presence-worker.js` #checkFetchers() | None found | Rejected lookup untested |
|
|
495
|
+
| `MOD-015` | Integration (skipped) | `test/integration/spec/presence.js` Mercury case | None found | No unit case |
|
|
496
|
+
| `MOD-016` | Unit (skipped) | `test/unit/spec/presence-worker.js` #checkCampers(), #checkSubscriptions(), #groundskeeper() | `test/unit/spec/presence-worker.js` non-200 and expiry cases | Nothing runs |
|
|
497
|
+
| `MOD-017` | Unit (skipped) | `test/unit/spec/presence-worker.js` #cleanPresences() | None found | Nothing runs |
|
|
498
|
+
|
|
499
|
+
`yarn workspace @webex/internal-plugin-presence test:unit` reported 2 skipped suites and 29 skipped
|
|
500
|
+
cases on 2026-11-12 under Node 22.14 after `build:src`, and exited zero. Both unit suites are
|
|
501
|
+
`describe.skip`: their comment says `presence` is registered as a public plugin, and
|
|
502
|
+
`@webex/test-helper-mock-webex` lists `presence` among its non-internal plugins, so the mock mounts
|
|
503
|
+
the plugin at `webex.presence` while the cases call `webex.internal.presence`. Inside the worker
|
|
504
|
+
suite, `#enqueue()` is skipped again because, per its comment, the batcher config is missing. The
|
|
505
|
+
unit specs import the package by name, so they load `dist/`; run `build:src` first. `test:browser`
|
|
506
|
+
runs the integration spec through karma and reported 0 tests on 2026-11-12 because the bundle failed
|
|
507
|
+
to parse `isbot`; that spec is also `describe.skip` (SPARK-413317). `package.json` has no
|
|
508
|
+
`test:integration` script, so the aggregate `test` script stops there. A module specification is
|
|
509
|
+
complete only when its public surface, invariants, failure modes, and test evidence agree with the
|
|
510
|
+
implementation. Generator-side field measurement is complete (100%, assessed 2026-11-12);
|
|
511
|
+
independent semantic validation ran on 2026-11-12 and is blocked by A1-001, the unconfirmed rationale
|
|
512
|
+
for the `dnd` label exception in `MOD-010` and `INV-003`; the maintainer does not know it, so those
|
|
513
|
+
entries still record it as unknown. IMP-001, the command-source traceability of the workspace-qualified
|
|
514
|
+
command form for five entries, is an accepted warning recorded in `.sdd/manifest.json`
|
|
515
|
+
`modules[0].coverage_evidence`. A characterization baseline and running unit cases remain pending.
|