@webex/storage-adapter-local-forage 3.13.0-next.5 → 3.13.0-next.7

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.
@@ -0,0 +1,511 @@
1
+ ---
2
+ type: Module Spec
3
+ title: 'storage-adapter-local-forage adapter specification'
4
+ description: Responsibilities, boundaries, design, invariants, and verification for the @webex/storage-adapter-local-forage IndexedDB storage adapter.
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: rsarika@cisco.com
12
+ updated_at: 2026-11-10T00:00:00Z
13
+ validation_status: pass-with-warnings
14
+ -->
15
+
16
+ # storage-adapter-local-forage adapter
17
+
18
+ This source-local document at `src/docs/README.md` owns the stable specification for the
19
+ **`@webex/storage-adapter-local-forage` adapter**: the `StorageAdapterLocalForage` class that lets
20
+ the Webex JS SDK storage layer persist namespaced key-value data in the browser through the
21
+ `localforage` library (IndexedDB first, then WebSQL, then `localStorage`).
22
+
23
+ The whole module is one file, `src/index.js`. It has no sub-module and makes no network call.
24
+
25
+ Related context: [repository architecture](../../docs/architecture.md) ·
26
+ [documentation index](../../docs/index.md) · [agent instructions](../../AGENTS.md) ·
27
+ [specification registry](../../docs/specs/README.md)
28
+
29
+ ## Metadata
30
+
31
+ | Field | Value |
32
+ | ----------------- | ----- |
33
+ | Owner | `@webex/web-client` (workspace CODEOWNERS entry for this package) |
34
+ | Source path | `src/` |
35
+ | Resource kind | Published npm package module (browser storage adapter) |
36
+ | Status | Active |
37
+ | Last verified | 2026-11-09 at `696c161e6e` |
38
+ | Module id | `storage-adapter-local-forage` |
39
+ | Parent spec | — |
40
+ | Doc kind | Module spec |
41
+ | Coverage score | 93% assessed 2026-11-09; 13 of 14 mandatory fields present, critical fields 7 of 7. Generator-side field measurement is complete. Weak field: test and characterization coverage (no executing test, no characterization baseline). Coverage state Partial (promoted from Untracked on 2026-11-09; no spec/code drift found) |
42
+ | Validation status | Pass-with-warnings, validated 2026-11-10 by runtime `codex`; 0 Blocking and 2 Important findings (I-01, I-02) |
43
+
44
+ ## Applicability
45
+
46
+ | Condition ID | Status | Evidence or reason | Owned section |
47
+ | ------------------------------------ | ---------- | ------------------ | ----------------------------- |
48
+ | `module.has_tiers` | N/A | No tier, SLO, or tiered review rule is declared in `package.json` or the package tree | Tier |
49
+ | `module.has_ui` | N/A | `src/index.js` renders nothing; there are no components, templates, or styles | UI use-case flow |
50
+ | `module.crosses_service_boundaries` | N/A | `src/index.js` imports no HTTP, socket, or RPC client; IndexedDB is a local browser API | Cross-boundary use-case flow |
51
+ | `module.holds_client_state` | Applicable | `src/index.js` keeps per-binding namespace and logger state for the life of each binding | Client state model |
52
+ | `module.enforces_domain_rules` | Applicable | `src/index.js` enforces bind preconditions, the key composition rule, and the stored-null versus missing-key distinction | Business rules and invariants |
53
+ | `module.is_concurrent_async` | Applicable | Every operation in `src/index.js` returns a promise, and get/del are de-duplicated with oneFlight | Concurrency and reactive flow |
54
+ | `module.owns_persistence` | Applicable | `src/index.js` owns the record layout written into the default localforage database (owner-confirmed 2026-10-06) | Data, schema, and migration |
55
+ | `module.stateful_transitions` | N/A | `src/index.js` has no lifecycle states or transition guards | State machine |
56
+ | `module.exposes_wire_protocol` | N/A | `src/index.js` defines no protocol or serializer; the persisted layout is specified once under Data, schema, and migration discipline | Protocol and wire format |
57
+ | `module.ui_multi_screen` | N/A | Gated by module.has_ui, which is N/A | UI flow |
58
+ | `module.large_data_model` | N/A | `src/index.js` stores one flat key-value record per namespaced key | Data model |
59
+ | `module.returns_caller_errors` | Applicable | `src/index.js` rejects with Error for invalid bind input and with NotFoundError for missing keys | Caller-visible failure modes |
60
+ | `module.module_specific_conventions` | Applicable | `src/index.js` and `.eslintrc.js` carry browser-only, logging, and decorator lint conventions | Module-specific rules |
61
+ | `module.published_package` | Applicable | `package.json` declares main, devMain, and a deploy:npm script | Export stability |
62
+ | `module.embedded_in_host` | Applicable | The adapter is plugged into the Webex SDK storage configuration and driven by its storage layer; `src/index.js` implements that host contract | Host integration and theming |
63
+ | `module.has_design_tradeoff` | Applicable | `src/index.js` uses the shared default localforage instance and a key-scan for null disambiguation (owner-confirmed 2026-10-06) | Key design trade-off |
64
+ | `module.has_submodules` | N/A | No other manifest module path lies below src/ | Sub-modules |
65
+
66
+ ## Evidence register
67
+
68
+ Rationale in this specification comes from code, tests, the canonical specifications of dependency
69
+ packages, and owner answers recorded on 2026-10-06 and re-confirmed on 2026-11-09. Commit history is
70
+ not used as evidence.
71
+
72
+ | Evidence | What it establishes |
73
+ | -------- | ------------------- |
74
+ | `src/index.js` | Every behavior specified here: bind preconditions, key composition, null disambiguation, clear scope, `oneFlight` wrapping, and logging |
75
+ | `test/unit/spec/storage-adapter-local-forage.js` | The suite runs inside `skipInNode(describe)` against `new StorageAdapterLocalForage('test')` and declares no case of its own |
76
+ | `package.json` | Entry points, runtime dependencies (including `localforage ^1.7.3`), scripts, and the absence of `test:unit` and `test:integration` scripts |
77
+ | `README.md` | The npm-facing statement of purpose |
78
+ | `.eslintrc.js`, `babel.config.js`, `jest.config.js` | All three inherit shared legacy configuration: the decorator transform, the Node Jest environment, and lint rules that ignore Markdown |
79
+ | Workspace-root Jest configuration (file jest.config.js at the monorepo root) | Lists this package among its Jest projects with `testEnvironment: 'node'`, so a root Jest run also skips the suite |
80
+ | Workspace pull-request workflow (file .github/workflows/pull-request.yml at the monorepo root) | The `Test - Browser` job runs `test:browser` in every changed workspace, so a change to this package triggers the Karma run |
81
+ | Legacy tools Karma constants (sibling package packages/legacy/tools, file src/utils/karma/karma.constants.ts) | Karma loads the `mocha` framework, which provides `before` but not the Jest-style `beforeAll` the shared suite calls |
82
+
83
+ Dependency facts come from each dependency's canonical specification where one exists, and from its
84
+ code otherwise:
85
+
86
+ - `@webex/common`: its module spec (sibling package `packages/@webex/common`, file
87
+ `src/docs/README.md`, `MOD-002` for `oneFlight`). That spec is rated Partial, so the facts were
88
+ cross-checked against its `src/one-flight.js`.
89
+ - `@webex/webex-core`: its storage sub-module spec (sibling package `packages/@webex/webex-core`, file
90
+ `src/lib/storage/docs/README.md`), cited by requirement ID below. That spec is rated Partial, so the
91
+ facts were cross-checked against `src/lib/storage/make-webex-store.js` and
92
+ `src/lib/storage/errors.js` in the same package.
93
+ - `@webex/storage-adapter-spec`: its module spec (sibling package `packages/@webex/storage-adapter-spec`,
94
+ file `src/docs/README.md`). That spec is rated Untracked, so its `src/index.js` is authoritative.
95
+ - `localforage`: no specification exists in this repository. Its behavior was read from version
96
+ 1.10.0, the version the workspace lockfile resolves for `^1.7.3`.
97
+
98
+ ## Purpose and boundary
99
+
100
+ - Responsibility: implement the Webex storage-adapter interface on top of `localforage`, so that the
101
+ SDK's storage layer can read, write, delete, and clear namespaced values that survive page reloads
102
+ and browser restarts.
103
+ - In scope: validating `bind` arguments, composing stored keys, translating `localforage` results into
104
+ the interface contract, de-duplicating concurrent reads and deletes, and debug logging through the
105
+ injected logger.
106
+ - Out of scope: choosing which adapter a host uses (host SDK configuration), caching bindings per
107
+ namespace and serializing plugin state (the `@webex/webex-core` storage layer), encryption or
108
+ integrity protection of values (not done anywhere in this path), and driver selection, quota
109
+ handling, and transactions (`localforage`).
110
+ - Consumers: the `@webex/webex-core` storage layer at runtime; `@webex/recipe-private-web-client`, the
111
+ only in-repo host that selects this adapter (workspace path
112
+ `packages/@webex/recipe-private-web-client/src/config.js`); and external npm hosts.
113
+
114
+ ## Structure and key files
115
+
116
+ | Path | Responsibility |
117
+ | ---- | -------------- |
118
+ | `src/index.js` | The whole module: `StorageAdapterLocalForage`, its per-instance `Bound` class, and the module-level `namespaces` and `loggers` WeakMaps |
119
+ | `src/docs/README.md` | This canonical module specification |
120
+ | `test/unit/spec/storage-adapter-local-forage.js` | Test entry point |
121
+ | `package.json` | Package manifest |
122
+ | `.eslintrc.js` | Package lint root |
123
+ | `babel.config.js` | Babel entry |
124
+ | `jest.config.js` | Jest entry |
125
+ | `process` | One-line module exporting `{browser: true}`; nothing in this package or its build tooling references it |
126
+
127
+ ## Public surface
128
+
129
+ Exact declarations live in `src/index.js`; the package entry points are declared in `package.json`.
130
+ The published contract ids are `local-forage-storage-adapter` (the npm surface) and
131
+ `local-forage-indexeddb-store` (the on-device record layout), both indexed in the
132
+ [architecture contract index](../../docs/architecture.md#public-and-consumer-surfaces).
133
+
134
+ | Surface | Consumer | Compatibility commitment | Source |
135
+ | ------- | -------- | ------------------------ | ------ |
136
+ | Default export `StorageAdapterLocalForage`, constructed with `new` | Host SDK configuration | Published; constructor arguments carry no meaning (`MOD-010`) | `src/index.js` |
137
+ | `bind(namespace, options)` returning `Promise<Bound>` | `@webex/webex-core` storage layer | Published; `MOD-001` to `MOD-003` | `src/index.js` |
138
+ | Binding methods `get(key)`, `put(key, value)`, `del(key)`, `clear()` | `@webex/webex-core` storage layer | Published; `MOD-004` to `MOD-012` | `src/index.js` |
139
+ | Record layout in the default `localforage` database | Later page loads and SDK releases on the same origin | Published; rule in [Data, schema, and migration discipline](#data-schema-and-migration-discipline) | `src/index.js` |
140
+
141
+ ## Dependencies
142
+
143
+ | Dependency | Why it is required | Failure behavior |
144
+ | ---------- | ------------------ | ---------------- |
145
+ | `localforage` (npm `^1.7.3`, resolves to 1.10.0) | All persistence: `getItem`, `setItem`, `removeItem`, `keys`, and `clear` on the default instance | Its rejections propagate unchanged (`MOD-013` covers the no-driver case) |
146
+ | `@webex/common` `oneFlight` | De-duplicates concurrent `get` and `del` calls | See Concurrency and reactive flow |
147
+ | `@webex/webex-core` `NotFoundError` | The rejection type for a missing key (`NotFoundError` extends `StorageError`; webex-core storage spec `MOD-033`) | The storage layer's hydration paths treat `NotFoundError` as "no data" and any other rejection as a real failure (webex-core storage spec `MOD-016`, `MOD-027`) |
148
+ | Injected `options.logger` | Info and debug logging | Required by `bind`; a logger without `debug` makes later calls throw synchronously |
149
+ | `@webex/storage-adapter-spec` | Shared conformance suite run by the package test | Test-only in practice (see Pitfalls and constraints) |
150
+ | Browser storage engine (IndexedDB, else WebSQL, else `localStorage`) | Backing store selected by `localforage` | Quota, private-mode, and transaction errors surface as `localforage` rejections; the adapter does not retry |
151
+
152
+ ## Requirements
153
+
154
+ | ID | WHAT | WHY | Source evidence | Test or example evidence | Assumptions or gaps | Confidence |
155
+ | -- | ---- | --- | --------------- | ------------------------ | ------------------- | ---------- |
156
+ | `MOD-001` | `bind(namespace, options)` rejects with ``Error('`namespace` is required')`` when `namespace` is falsy; this check runs before the logger check | The storage-adapter interface requires every binding to be namespaced, and the shared suite matches this message | `src/index.js` | None executing | The suite's assertion never runs (see Verification) | Present |
157
+ | `MOD-002` | `bind` treats a missing `options` as `{}` and rejects with ``Error('`options.logger` is required')`` when no logger is supplied | Every operation logs through the injected logger | `src/index.js` | None executing | Same suite gap as `MOD-001` | Present |
158
+ | `MOD-003` | A valid `bind` logs `storage-adapter-local-forage: returning binding` at info and resolves a new `Bound` instance on every call; the adapter caches no binding | Binding caching belongs to the storage layer | `src/index.js` | None executing | Not covered by the shared suite | Present |
159
+ | `MOD-004` | Every `get`, `put`, and `del` addresses the record key `${namespace}/${key}` in the default `localforage` database | Isolates namespaces from each other and keeps data written by earlier releases reachable | `src/index.js` | None executing | The suite's different-namespace case is broken (see Verification) | Present |
160
+ | `MOD-005` | `put(key, value)` with `value === undefined` calls `del(key)`; otherwise it calls `setItem` and resolves with the value `localforage` returns | The interface defines writing `undefined` as a delete, matching the storage layer's own `put` | `src/index.js` | None executing | — | Present |
161
+ | `MOD-006` | `get(key)` resolves the stored value; when `getItem` yields `null` it calls `keys()` and resolves `null` only if the composed key exists, otherwise it rejects with `NotFoundError('No value found for ' + composedKey)` | `localforage` returns `null` for both a missing key and a stored `null`, and the interface must tell them apart | `src/index.js` | None executing | Relies on `localforage` returning `null` for absent records | Present |
162
+ | `MOD-007` | `get` and `del` are wrapped with `oneFlight` keyed by the key: concurrent calls with the same key on the same binding share one in-flight promise; `put` and `clear` are not wrapped | Avoids redundant storage transactions when several callers request the same key at once | `src/index.js` | None executing | Not covered by the shared suite | Present |
163
+ | `MOD-008` | `del(key)` calls `removeItem` for the composed key and resolves whether or not the record existed | Deletes are idempotent for callers such as `put(key, undefined)` | `src/index.js` | None executing | — | Present |
164
+ | `MOD-009` | `clear()` calls `localforage.clear()` on the default instance, which removes every record in the default `localforage` store: all namespaces, all adapter instances, and any other data written through the default instance | Current behavior; the storage layer's logout path relies on it to erase persisted SDK data. Owner decision 2026-10-06: specify as-is, treat as a known hazard to fix separately, and do not promise it as a contract | `src/index.js` | None executing | The suite only checks that the binding's own key is gone, so it cannot detect the scope | Present |
165
+ | `MOD-010` | The constructor takes no parameters and ignores any arguments; every instance reads and writes the same default database | Current behavior. Owner decision 2026-10-06: specify as-is, treat as a known hazard to fix separately, and do not promise it as a contract | `src/index.js` | None executing | Callers pass a base key (`'test'` in the package test, `'web-client-internal'` in the in-repo host) that has no effect | Present |
166
+ | `MOD-011` | `get`, `put`, and `del` log at debug with the composed key (``reading `key` ``, ``writing `key` ``, ``deleting `key` ``); `clear()` logs `clearing localforage` | Gives SDK diagnostics a uniform trace of storage activity | `src/index.js` | None executing | Key names, such as encryption key URIs, appear in debug logs | Present |
167
+ | `MOD-012` | Values pass to `localforage` unchanged: the adapter does no serialization, validation, encryption, or size check | Serialization belongs to the storage layer and the `localforage` driver; owner-confirmed 2026-10-06 that stored data is security-sensitive | `src/index.js` | None executing | — | Present |
168
+ | `MOD-013` | The adapter works only where `localforage` finds a storage driver; with none (Node, or storage disabled) every operation rejects with `localforage`'s `No available storage method found.` error | The module targets browsers only (see Module-specific rules) | `src/index.js` | None executing | The message comes from `localforage` 1.10.0 and has not been exercised here | Weak |
169
+
170
+ ## Design overview
171
+
172
+ `StorageAdapterLocalForage` holds no data of its own. Its constructor only defines a `Bound` class on
173
+ the instance, and `bind` validates its arguments and returns `new this.Bound(namespace, options)`.
174
+ Each binding keeps its namespace and logger private in two module-level WeakMaps (`namespaces`,
175
+ `loggers`; see `INV-001`).
176
+
177
+ All persistence goes to the default `localforage` instance. The adapter never calls
178
+ `localforage.config` or `createInstance`, so the only separation between namespaces is the key prefix
179
+ (`MOD-004`). The benefits and costs of that choice, of the `keys()` scan behind `MOD-006`, and of
180
+ decorating only reads and deletes are recorded once, in [Key design trade-off](#key-design-trade-off).
181
+
182
+ The binding methods adapt `localforage` semantics to the storage-adapter interface (`MOD-005`,
183
+ `MOD-006`, `MOD-008`, `MOD-009`). `get` and `del` use the `oneFlight` method decorator, so the module
184
+ depends on the shared Babel configuration's decorator transform (`babel.config.js`).
185
+
186
+ ## Data flow and sequence coverage
187
+
188
+ Call style: in-process promise-returning method calls from the host storage layer into the adapter.
189
+ The adapter then makes asynchronous `localforage` calls, which `localforage` turns into IndexedDB
190
+ (or fallback driver) transactions. There is no network transport.
191
+
192
+ | Operation group | Entry and outcome | Diagram or evidence | Failure and recovery coverage |
193
+ | --------------- | ----------------- | ------------------- | ----------------------------- |
194
+ | Binding | `bind(namespace, options)` resolves a new binding or rejects | Binding diagram below; `src/index.js` | Missing namespace, missing logger |
195
+ | Read | `get(key)` resolves a value or `null`, or rejects with `NotFoundError` | Read diagram below; `src/index.js` | Missing key, stored `null`, coalesced concurrent reads, driver rejection |
196
+ | Write and delete | `put(key, value)` and `del(key)` resolve after the record is written or removed | Write and delete diagram below; `src/index.js` | `undefined` value routed to delete, driver rejection |
197
+ | Clear | `clear()` resolves after the default store is emptied | Clear diagram below; `src/index.js` | Driver rejection; logout fan-out |
198
+
199
+ Binding:
200
+
201
+ ```mermaid
202
+ sequenceDiagram
203
+ participant Host as webex-core storage layer
204
+ participant Adapter as StorageAdapterLocalForage
205
+ participant Bound as Bound binding
206
+ Host->>Adapter: bind(namespace, {logger})
207
+ alt namespace falsy
208
+ Adapter-->>Host: reject Error("`namespace` is required")
209
+ else options.logger missing
210
+ Adapter-->>Host: reject Error("`options.logger` is required")
211
+ else valid
212
+ Adapter->>Adapter: logger.info("returning binding")
213
+ Adapter->>Bound: new Bound(namespace, options)
214
+ Bound->>Bound: record namespace and logger in WeakMaps
215
+ Adapter-->>Host: resolve binding
216
+ end
217
+ ```
218
+
219
+ Read:
220
+
221
+ ```mermaid
222
+ sequenceDiagram
223
+ participant Caller as Storage layer
224
+ participant Get as Bound.get (oneFlight)
225
+ participant LF as localforage default instance
226
+ Caller->>Get: get(key)
227
+ alt flight for this key already in progress
228
+ Get-->>Caller: same in-flight promise
229
+ else no flight
230
+ Get->>LF: getItem(namespace/key)
231
+ alt value is not null
232
+ LF-->>Get: value
233
+ Get-->>Caller: resolve value
234
+ else value is null
235
+ Get->>LF: keys()
236
+ alt composed key listed
237
+ Get-->>Caller: resolve null (stored null)
238
+ else composed key absent
239
+ Get-->>Caller: reject NotFoundError
240
+ end
241
+ end
242
+ opt driver or transaction error
243
+ LF-->>Get: rejection
244
+ Get-->>Caller: reject unchanged
245
+ end
246
+ end
247
+ ```
248
+
249
+ Write and delete:
250
+
251
+ ```mermaid
252
+ sequenceDiagram
253
+ participant Caller as Storage layer
254
+ participant Bound as Bound binding
255
+ participant LF as localforage default instance
256
+ Caller->>Bound: put(key, value)
257
+ alt value is undefined
258
+ Bound->>Bound: del(key) via oneFlight
259
+ Bound->>LF: removeItem(namespace/key)
260
+ LF-->>Caller: resolve
261
+ else defined value
262
+ Bound->>LF: setItem(namespace/key, value)
263
+ LF-->>Caller: resolve stored value
264
+ end
265
+ Caller->>Bound: del(key)
266
+ Bound->>LF: removeItem(namespace/key)
267
+ LF-->>Caller: resolve, whether or not the record existed
268
+ opt driver, quota, or transaction error
269
+ LF-->>Caller: rejection propagated unchanged
270
+ end
271
+ ```
272
+
273
+ Clear (the logout path in `@webex/webex-core` calls both storages):
274
+
275
+ ```mermaid
276
+ sequenceDiagram
277
+ participant Logout as webex-core logout
278
+ participant Store as WebexStore (bounded and unbounded)
279
+ participant Bound as each cached binding
280
+ participant LF as localforage default instance
281
+ Logout->>Store: Promise.all(boundedStorage.clear(), unboundedStorage.clear())
282
+ loop every binding each store created this session
283
+ Store->>Bound: clear()
284
+ Bound->>LF: clear()
285
+ LF-->>Bound: default store emptied
286
+ end
287
+ alt every clear resolves
288
+ Store-->>Logout: resolve
289
+ else any clear rejects
290
+ Store-->>Logout: reject with the first failure
291
+ end
292
+ Note over Store,LF: A store with no cached binding clears nothing
293
+ ```
294
+
295
+ ## Class and component relationships
296
+
297
+ ```mermaid
298
+ classDiagram
299
+ class StorageAdapterLocalForage {
300
+ +Bound
301
+ +bind(namespace, options) Promise~Bound~
302
+ }
303
+ class Bound {
304
+ +clear() Promise
305
+ +del(key) Promise
306
+ +get(key) Promise
307
+ +put(key, value) Promise
308
+ }
309
+ class WeakMaps {
310
+ namespaces
311
+ loggers
312
+ }
313
+ StorageAdapterLocalForage *-- Bound : defines per instance
314
+ Bound ..> WeakMaps : namespace and logger lookup
315
+ Bound ..> localforage : default instance
316
+ Bound ..> oneFlight : decorates get and del
317
+ Bound ..> NotFoundError : missing key
318
+ WebexStore --> StorageAdapterLocalForage : bind(namespace, logger)
319
+ WebexStore --> Bound : get, put, del, clear
320
+ ```
321
+
322
+ `oneFlight` comes from `@webex/common`, `NotFoundError` and `WebexStore` from `@webex/webex-core`,
323
+ and `localforage` from npm.
324
+
325
+ ## Use cases and flows
326
+
327
+ | Use case | Actor or caller | Primary steps and outcome | Failure or boundary behavior | Evidence |
328
+ | -------- | --------------- | ------------------------- | ---------------------------- | -------- |
329
+ | `UC-001` | Host application | Selects this adapter for a storage slot (contract in [Host integration and theming](#host-integration-and-theming)); the first storage access in each plugin namespace yields a binding | Two slots configured with this adapter share one database (`MOD-010`) | `src/index.js`, `package.json` |
330
+ | `UC-002` | SDK plugin through the storage layer | Looks up a persisted value on demand, for example the encryption plugin reading a cached key by URI; a hit resolves the stored string | A miss rejects with `NotFoundError`; the encryption plugin treats any rejection as a miss, then fetches from KMS and calls `put` | `src/index.js` |
331
+ | `UC-003` | SDK plugin through the storage layer | Writes a value with `put`; it persists across reloads under its composed key | `put(key, undefined)` deletes instead of writing; driver errors reject | `src/index.js` |
332
+ | `UC-004` | Webex logout | Both SDK storages clear every binding they cached; each binding's `clear()` empties the default store | Other data written through the default instance is also erased | `src/index.js` |
333
+ | `UC-005` | Several callers at once | Concurrent `get(key)` calls on one binding receive the same promise from one `getItem` | Coalescing cost is in Key design trade-off | `src/index.js` |
334
+
335
+ <!-- Include if: the module holds client-side state. [condition-id: module.holds_client_state] -->
336
+
337
+ ## Client state model
338
+
339
+ | State or slice | Owner | Initial state | Transition triggers | Reset or persistence boundary |
340
+ | -------------- | ----- | ------------- | ------------------- | ----------------------------- |
341
+ | Binding namespace (`namespaces` WeakMap entry) | `src/index.js` module scope | Absent until a binding is constructed | Created by the `Bound` constructor during `bind` | Released when the binding is garbage-collected |
342
+ | Binding logger (`loggers` WeakMap entry) | `src/index.js` module scope | Absent until a binding is constructed | Created by the `Bound` constructor during `bind` | Released when the binding is garbage-collected |
343
+ | In-flight `get`/`del` promises | `@webex/common` `oneFlight` store | Empty | Added by the first call for a key; removed when that promise settles | In memory only; lost on page unload |
344
+
345
+ Persisted records are not client state of this module; they are specified under Data, schema, and
346
+ migration discipline.
347
+
348
+ <!-- Include if: the module enforces domain rules or entity invariants. [condition-id: module.enforces_domain_rules] -->
349
+
350
+ ## Business rules and invariants
351
+
352
+ The enforced input and data rules are requirements, each specified once above: `bind` preconditions
353
+ (`MOD-001`, `MOD-002`), key composition (`MOD-004`), `put(undefined)` as delete (`MOD-005`), and the
354
+ missing-key versus stored-`null` distinction (`MOD-006`). One invariant has no requirement row:
355
+
356
+ | ID | Invariant | WHY | Enforcement source | Test evidence |
357
+ | -- | --------- | --- | ------------------ | ------------- |
358
+ | `INV-001` | A binding's namespace and logger never change after construction | Every later key and log line for that binding depends on them; the WeakMap entries are written only in the `Bound` constructor and no setter or public property exists | `src/index.js` | none found |
359
+
360
+ <!-- Include if: the module is concurrent, asynchronous, reactive, or event-driven. [condition-id: module.is_concurrent_async] -->
361
+
362
+ ## Concurrency and reactive flow
363
+
364
+ - Execution model: single-threaded browser event loop. Every method returns a promise; `localforage`
365
+ runs each operation as an asynchronous storage transaction after its `ready()` promise resolves.
366
+ - Ordering guarantees: none of the adapter's own. Concurrent `put` calls on one key are not
367
+ serialized by the adapter; the last value stored follows `localforage` and IndexedDB transaction
368
+ ordering. A `get` that finds `null` makes two separate calls (`getItem`, then `keys()`), so a
369
+ concurrent `put` or `del` between them can change the outcome.
370
+ - Idempotency and retry: `del` is idempotent. The `oneFlight` entry for a `get` or `del` is evicted
371
+ when its promise settles, on success and on failure, so the next call starts a fresh operation.
372
+ The adapter never retries.
373
+ - Shared-state protection: no locks. `oneFlight` keys each flight by the binding instance, the
374
+ decorated prototype, and the method name plus key, so bindings never share flights.
375
+ - Blocking restrictions: no synchronous storage access; all I/O goes through `localforage` promises.
376
+
377
+ <!-- Include if: the module owns persisted data and its migrations. [condition-id: module.owns_persistence] -->
378
+
379
+ ## Data, schema, and migration discipline
380
+
381
+ | Store or schema | Owned entities or keys | Source of truth | Migration and compatibility rule |
382
+ | --------------- | ---------------------- | --------------- | -------------------------------- |
383
+ | `localforage` default database (name `localforage`, store `keyvaluepairs`; IndexedDB, else WebSQL, else `localStorage` with a `localforage/` key prefix) | One record per `${namespace}/${key}`, holding the value passed to `put` unchanged | `src/index.js` | No version field and no migration step. Changing the key composition, database name, or store name, or switching to a named `localforage` instance, orphans every record written by earlier releases, so any such change needs a data migration |
384
+
385
+ - Retention: unbounded. Records persist until `del`, `put(key, undefined)`, `clear()`, or the user
386
+ clearing site data.
387
+ - Deletion: `clear()` scope is defined by `MOD-009`.
388
+ - Backfill and rollback: none; the adapter reads whatever the store holds.
389
+ - Sensitivity: values are stored unencrypted (`MOD-012`). In this monorepo the encryption plugin
390
+ caches serialized KMS keys in unbounded storage, so when this adapter fills that slot, key material
391
+ is at rest in the browser (owner-confirmed 2026-10-06; see the
392
+ [security architecture](../../docs/architecture.md#security-architecture)).
393
+
394
+ <!-- Include if: the module returns or raises errors callers must handle. [condition-id: module.returns_caller_errors] -->
395
+
396
+ ## Caller-visible failure modes
397
+
398
+ | Condition | Signal or result | Caller behavior | Retry or recovery | Evidence |
399
+ | --------- | ---------------- | --------------- | ----------------- | -------- |
400
+ | `bind` called without a namespace | Rejected promise: ``Error('`namespace` is required')`` | Fix the call | None; deterministic | `src/index.js` |
401
+ | `bind` called without `options.logger` | Rejected promise: ``Error('`options.logger` is required')`` | Fix the call | None; deterministic | `src/index.js` |
402
+ | `get` on a missing key | Rejected promise: `NotFoundError` with message `No value found for ${namespace}/${key}` | The storage layer treats it as "no data" and continues | Not an error to retry | `src/index.js` |
403
+ | No storage driver available (Node, storage disabled) | Rejection from `localforage`: `No available storage method found.` | Choose another adapter for that environment | None in the adapter | `src/index.js` |
404
+ | Quota exceeded, transaction abort, or private-mode restriction | `localforage` rejection, propagated unchanged | Handle as a storage failure | None in the adapter | `src/index.js` |
405
+ | Logger missing `debug` or `info`, or a method called detached from its binding | Synchronous `TypeError` rather than a rejection | Pass a full logger and call methods on the binding | None | `src/index.js` |
406
+
407
+ ## Pitfalls and constraints
408
+
409
+ - **Logout repeats the whole-store wipe (`MOD-009`).** Logout clears both SDK storages, and each
410
+ clears every binding it cached, so the same default store is emptied once per cached binding. When
411
+ this adapter fills only the unbounded slot, those wipes still remove records that other bindings
412
+ wrote.
413
+ - **Two slots on this adapter collide (`MOD-010`).** If a host assigns this adapter to both the
414
+ bounded and the unbounded slot, each slot reads and clears the other's records. The constructor's
415
+ JSDoc still documents a `basekey` parameter that does not exist.
416
+ - **Logout erasure depends on a binding existing.** A storage clears only bindings it has created in
417
+ the current session, so persisted data survives logout when no namespace was accessed through it.
418
+ - **No passing run exercises the adapter.** In Node the suite is skipped, so a pass there says nothing
419
+ about this module. The Karma run that CI starts for a change to this package is expected to fail
420
+ while loading the suite. See Verification.
421
+ - **Installing this package also installs the test suite.** `package.json` lists
422
+ `@webex/storage-adapter-spec`, and with it its chai helper, under runtime `dependencies` although
423
+ only the test imports it.
424
+ - **`localforage` is old.** The workspace's unmaintained-dependency catalog flags `^1.7.3` as stale
425
+ (last npm publish 2021-08-18, high risk).
426
+
427
+ <!-- Include if: the module has conventions beyond repository-wide rules. [condition-id: module.module_specific_conventions] -->
428
+
429
+ ## Module-specific rules
430
+
431
+ - Do: keep the module browser-only. `src/index.js` declares `/* eslint-env browser */`, and the
432
+ package test is wrapped in `skipInNode`.
433
+ - Do: log through the binding's injected logger with the `storage-adapter-local-forage:` prefix and
434
+ never through `console`.
435
+ - Do: build every stored key from `namespaces.get(this)` so all methods address the same record.
436
+ - Do: keep the `// eslint-disable-next-line require-jsdoc` comment directly above each
437
+ `oneFlight`-decorated method; the code notes that decorators confuse the JSDoc rule.
438
+ - Do not: keep binding state anywhere but the module-level WeakMaps (`INV-001`).
439
+
440
+ <!-- Include if: the module is published or consumed as a package. [condition-id: module.published_package] -->
441
+
442
+ ## Export stability
443
+
444
+ | Export or entry point | Consumer | Stability | Versioning and deprecation rule | Declaration or API report |
445
+ | --------------------- | -------- | --------- | ------------------------------- | ------------------------- |
446
+ | Default export `StorageAdapterLocalForage` | Host SDK configurations | Stable, published | Released with the workspace-wide version through `deploy:npm`; removing or renaming it is breaking | `package.json` |
447
+ | `bind` and the binding's `get`/`put`/`del`/`clear` | `@webex/webex-core` storage layer | Stable; shape fixed by the storage-adapter interface | Any change must keep the semantics in Requirements | `src/index.js` |
448
+ | Record layout | Data written by earlier releases | Stable | Governed by Data, schema, and migration discipline | `src/index.js` |
449
+ | `adapter.Bound` instance property | None known | Unsupported; incidental result of assigning the class in the constructor | May change without notice | `src/index.js` |
450
+ | Package entry points `main: dist/index.js`, `devMain: src/index.js` | npm consumers and workspace tooling | Stable | `dist/index.js` is produced by `build`; consumers must not import other paths | `package.json` |
451
+
452
+ <!-- Include if: the module is embedded in a host application. [condition-id: module.embedded_in_host] -->
453
+
454
+ ## Host integration and theming
455
+
456
+ - Mount or entry contract: the host assigns an adapter instance to `storage.boundedAdapter` or
457
+ `storage.unboundedAdapter` in its Webex SDK configuration. The storage layer reads the slot on each
458
+ use, calls `bind(namespace, {logger})` once per namespace, caches the binding (concurrent first
459
+ operations share one `bind`; a rejected `bind` is not cached), and routes `get`/`put`/`del`/`clear`
460
+ to it (webex-core storage spec `MOD-017`, `MOD-018`, `MOD-019`).
461
+ - Required providers, peers, or host versions: the `@webex/webex-core` storage layer (for the binding
462
+ lifecycle and `NotFoundError`), and a browser in which `localforage` finds a storage driver.
463
+ - Theme and design-token contract: N/A; the module has no UI.
464
+ - Accessibility and lifecycle obligations: no accessibility surface. Bindings live as long as the
465
+ storage layer that cached them; logout drives `clear()` as shown in the Clear diagram. The storage
466
+ layer clears only bindings it created in this session (webex-core storage spec `MOD-022`).
467
+
468
+ <!-- Include if: the module has a non-obvious design trade-off consumers or maintainers must preserve. [condition-id: module.has_design_tradeoff] -->
469
+
470
+ ## Key design trade-off
471
+
472
+ | Chosen trade-off | Preserved invariant or benefit | Cost or limitation | Decision evidence |
473
+ | ---------------- | ------------------------------ | ------------------ | ----------------- |
474
+ | Use the default `localforage` instance instead of a configured or per-base-key instance | No configuration; every release and adapter instance on an origin reads the same records | No isolation beyond the key prefix, which is why `MOD-009` and `MOD-010` are hazards; collides with any other code using the default instance | `src/index.js` |
475
+ | Disambiguate `null` with a `keys()` scan | Exact `NotFoundError` semantics while falsy values round-trip | Every miss or stored `null` reads every key in the store, across all namespaces | `src/index.js` |
476
+ | `oneFlight` on `get` and `del` only | Duplicate concurrent reads and deletes share one transaction | A read that joins an in-flight `get` returns that read's result even if a `put` for the same key finished in between; writes are never coalesced | `src/index.js` |
477
+
478
+ ## Verification
479
+
480
+ The package has no executing automated coverage:
481
+
482
+ - `package.json` defines no `test:unit` script; the owner confirmed on 2026-10-06 that no canonical
483
+ unit-test command exists.
484
+ - Under the shared Jest configuration (Node environment) the test file's `skipInNode(describe)` skips
485
+ the suite. The workspace-root Jest configuration also lists this package with a Node environment, so
486
+ the same skip applies there.
487
+ - `test:browser` runs Karma with the Mocha framework, while the shared suite calls the Jest-only
488
+ `beforeAll` hook, which Mocha does not define. CI's `Test - Browser` job runs `test:browser` in
489
+ every changed workspace, so a change to this package is expected to fail while loading the suite
490
+ rather than run its cases. This is derived from code and was not measured, because the generation
491
+ worktree had no installed dependencies.
492
+
493
+ This module has no characterization baseline. One is required before any risky modification. Every
494
+ "none executing" entry below names a shared-suite case that exists but does not run.
495
+
496
+ | Requirement or invariant | Test level | Positive evidence | Negative or boundary evidence | Gap |
497
+ | ------------------------ | ---------- | ----------------- | ----------------------------- | --- |
498
+ | `MOD-001`, `MOD-002` | Contract (shared suite) | none executing | none executing | Suite cases "requires a namespace" and "requires a logger option" do not run |
499
+ | `MOD-003` | None | none found | none found | No case asserts a fresh binding per `bind` or the info log |
500
+ | `MOD-004` | Contract (shared suite) | none executing | none found | "puts same key in different namespaces" does not run and is broken: its inner promise is not returned, so its assertions cannot fail the test; nothing asserts the literal key format |
501
+ | `MOD-005` | Contract (shared suite) | none executing | none executing | `put(key, undefined)` cases under del and clear do not run |
502
+ | `MOD-006` | Contract (shared suite) | none executing | none executing | Falsy round-trip cases and "rejects if the key cannot be found" do not run |
503
+ | `MOD-007` | None | none found | none found | Nothing asserts read or delete coalescing |
504
+ | `MOD-008` | Contract (shared suite) | none executing | none executing | Delete cases, including the absent-key `del` in "removes an item from the store when putting `undefined`", do not run |
505
+ | `MOD-009` | Contract (shared suite) | none executing | none found | Clear cases do not run and assert only the binding's own key, not the store-wide scope |
506
+ | `MOD-010` | None | none found | none found | No case asserts that the constructor argument is ignored |
507
+ | `MOD-011` | None | none found | none found | The suite passes a no-op logger and asserts nothing about logging |
508
+ | `MOD-012`, `MOD-013`, `INV-001` | None | none found | none found | No case covers value pass-through, the no-driver rejection, or binding immutability |
509
+
510
+ Record coverage gaps explicitly and link follow-up work. A module specification is complete only when
511
+ its public surface, invariants, failure modes, and test evidence agree with the implementation.