@webex/webex-core 3.12.0-webex-services-ready.4 → 3.13.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.repo-context.json +653 -0
  2. package/.sdd/manifest.json +605 -0
  3. package/AGENTS.md +209 -0
  4. package/dist/config.js +30 -0
  5. package/dist/config.js.map +1 -1
  6. package/dist/index.js +14 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/interceptors/catalog-url.js +87 -0
  9. package/dist/interceptors/catalog-url.js.map +1 -0
  10. package/dist/interceptors/payload-transformer.js +25 -4
  11. package/dist/interceptors/payload-transformer.js.map +1 -1
  12. package/dist/lib/batcher.js +1 -1
  13. package/dist/lib/credentials/credentials.js +56 -1
  14. package/dist/lib/credentials/credentials.js.map +1 -1
  15. package/dist/lib/credentials/token.js +1 -1
  16. package/dist/lib/services/service-catalog.js +102 -8
  17. package/dist/lib/services/service-catalog.js.map +1 -1
  18. package/dist/lib/services/services.js +84 -48
  19. package/dist/lib/services/services.js.map +1 -1
  20. package/dist/lib/services-v2/service-catalog.js +8 -1
  21. package/dist/lib/services-v2/service-catalog.js.map +1 -1
  22. package/dist/lib/services-v2/services-v2.js +90 -50
  23. package/dist/lib/services-v2/services-v2.js.map +1 -1
  24. package/dist/lib/static-asset-loader.js +153 -0
  25. package/dist/lib/static-asset-loader.js.map +1 -0
  26. package/dist/plugins/logger.js +1 -1
  27. package/dist/webex-core.js +11 -3
  28. package/dist/webex-core.js.map +1 -1
  29. package/docs/adr/index.md +32 -0
  30. package/docs/architecture.md +298 -0
  31. package/docs/getting-started.md +96 -0
  32. package/docs/index.md +55 -0
  33. package/docs/specs/README.md +76 -0
  34. package/package.json +13 -13
  35. package/schemas/repo-context.schema.json +796 -0
  36. package/src/config.js +32 -0
  37. package/src/docs/README.md +732 -0
  38. package/src/index.js +2 -0
  39. package/src/interceptors/catalog-url.js +66 -0
  40. package/src/interceptors/docs/README.md +658 -0
  41. package/src/interceptors/payload-transformer.js +23 -1
  42. package/src/lib/credentials/credentials.js +43 -0
  43. package/src/lib/credentials/docs/README.md +846 -0
  44. package/src/lib/services/docs/README.md +737 -0
  45. package/src/lib/services/service-catalog.js +106 -6
  46. package/src/lib/services/services.js +77 -32
  47. package/src/lib/services-v2/docs/README.md +751 -0
  48. package/src/lib/services-v2/service-catalog.ts +10 -1
  49. package/src/lib/services-v2/services-v2.ts +86 -33
  50. package/src/lib/static-asset-loader.ts +128 -0
  51. package/src/lib/storage/docs/README.md +646 -0
  52. package/src/webex-core.js +8 -0
  53. package/test/integration/spec/services/services.js +148 -113
  54. package/test/integration/spec/services-v2/services-v2.js +134 -99
  55. package/test/unit/spec/credentials/credentials.js +114 -1
  56. package/test/unit/spec/interceptors/catalog-url.js +224 -0
  57. package/test/unit/spec/interceptors/payload-transformer.js +119 -1
  58. package/test/unit/spec/services/service-catalog.js +275 -0
  59. package/test/unit/spec/services/services.js +161 -2
  60. package/test/unit/spec/services-v2/service-catalog.ts +41 -0
  61. package/test/unit/spec/services-v2/services-v2.ts +279 -2
  62. package/test/unit/spec/static-asset-loader.ts +224 -0
  63. package/test/unit/spec/webex-core.js +77 -1
@@ -0,0 +1,737 @@
1
+ ---
2
+ type: Module Spec
3
+ title: 'services (v1 service discovery) specification'
4
+ description: Responsibilities, boundaries, design, invariants, and verification for the webex-core v1 service-discovery plugin, its catalog models, and the service, host-map and server-error interceptors.
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-10-07T13:20:21Z
13
+ validation_status: pass-with-warnings
14
+ -->
15
+
16
+ # services (v1 service discovery)
17
+
18
+ This source-local document at `src/lib/services/docs/README.md` owns the stable specification for
19
+ the **v1 service-discovery plugin**: collecting the U2C service catalog, modelling services, hosts
20
+ and URLs, resolving service names and URLs, selecting and failing over hosts, gating `webex.ready`
21
+ on catalog readiness, and the three interceptors (`ServiceInterceptor`, `HostMapInterceptor`,
22
+ `ServerErrorInterceptor`) in `src/lib/interceptors` that apply the catalog to outgoing requests.
23
+
24
+ The sibling v2 implementation is specified in
25
+ [`src/lib/services-v2/docs/README.md`](../../services-v2/docs/README.md) and is not restated here.
26
+ The package-level surface, interceptor ordering, and the auth and catalog-URL interceptors that
27
+ *consume* this module belong to the parent, specified in [`src/docs/README.md`](../../../docs/README.md).
28
+
29
+ Related context: [repository architecture](../../../../docs/architecture.md) ·
30
+ [documentation index](../../../../docs/index.md) · [agent instructions](../../../../AGENTS.md) ·
31
+ [specification registry](../../../../docs/specs/README.md)
32
+
33
+ ## Metadata
34
+
35
+ | Field | Value |
36
+ | ----------------- | -------------------------------------------------------------- |
37
+ | Owner | Cisco Webex for Developers |
38
+ | Source path | `src/lib/services` |
39
+ | Resource kind | Capability module (internal plugin `services`, plus interceptors) |
40
+ | Status | Active |
41
+ | Last verified | 2026-10-07 |
42
+ | Module id | `src/lib/services` |
43
+ | Parent spec | [`src/docs/README.md`](../../../docs/README.md) |
44
+ | Doc kind | Module spec |
45
+ | Coverage score | 100% assessed 2026-10-07; 16 of 16 mandatory fields present; critical 8 of 8; independent validation pass-with-warnings 2026-10-07 |
46
+ | Validation status | Pass with warnings — 2026-10-07; runtime `01a1166d-02d9-7772-bc25-1a801fb5f1d1`; 0 Blocking, 8 Important, 3 Medium |
47
+
48
+ ## Applicability
49
+
50
+ | Condition ID | Status | Evidence or reason | Owned section |
51
+ | ------------------------------------ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------- |
52
+ | `module.has_tiers` | N/A | The repository assigns no operational or review tiers | Tier |
53
+ | `module.has_ui` | N/A | No components or rendering | UI use-case flow |
54
+ | `module.crosses_service_boundaries` | Applicable | Fetches the U2C catalog and calls hydra, license and user-onboarding services in src/lib/services/services.js | Cross-boundary use-case flow |
55
+ | `module.holds_client_state` | Applicable | Catalog groups, readiness flags and host failure marks live in memory in src/lib/services/service-catalog.js and src/lib/services/service-url.js | Client state model |
56
+ | `module.enforces_domain_rules` | Applicable | Host priority and failover rules, URL-to-service origin matching, allowed-domain matching (src/lib/services/service-url.js, src/lib/services/service-catalog.js) | Business rules and invariants |
57
+ | `module.is_concurrent_async` | Applicable | Promise-based catalog collection with an in-flight guard, init-timeout race and event-driven readiness in src/lib/services/services.js | Concurrency and reactive flow |
58
+ | `module.owns_persistence` | Applicable | Owns a versioned localStorage cache entry with TTL and shape compatibility in src/lib/services/services.js | Data, schema, and migration |
59
+ | `module.stateful_transitions` | Applicable | Per-group collecting/ready flags and the services ready/initFailed lifecycle (src/lib/services/service-catalog.js, src/lib/services/services.js) | State machine |
60
+ | `module.exposes_wire_protocol` | N/A | Consumes the external U2C hostmap response and defines no protocol of its own; the cached JSON is covered under persistence | Protocol and wire format |
61
+ | `module.ui_multi_screen` | N/A | Gated by module.has_ui, which is N/A | UI flow |
62
+ | `module.large_data_model` | N/A | A handful of small entities (catalog, URL, host); no schema or migration surface beyond the cache entry | Data model |
63
+ | `module.returns_caller_errors` | Applicable | Rejections and thrown errors for invalid queries, unknown services and unknown URLs (src/lib/services/services.js, src/lib/interceptors/service.js) | Caller-visible failure modes |
64
+ | `module.module_specific_conventions` | Applicable | Ampersand-state classes versus plain ES classes, private underscore members, and the v1/v2 mirror (src/lib/services/services.js, src/lib/services/service-registry.js) | Module-specific rules |
65
+ | `module.published_package` | Applicable | Classes and interceptors are re-exported from the package entry (src/lib/services/index.js, src/index.js) | Export stability |
66
+ | `module.embedded_in_host` | N/A | Not mounted into a host application | Host integration and theming |
67
+ | `module.has_design_tradeoff` | Applicable | Gated versus ungated readiness, and a cache that bypasses fetch on warm start (src/lib/services/services.js) | Key design trade-off |
68
+ | `module.has_submodules` | N/A | No child modules; computed from the manifest module tree | Sub-modules |
69
+
70
+ ## Evidence register
71
+
72
+ | Evidence | What it establishes |
73
+ | -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
74
+ | `src/lib/services/index.js` | Registers the `services` internal plugin with two interceptors and re-exports six classes |
75
+ | `src/lib/services/services.js` | The plugin: config init, U2C collection, cache, init lifecycle, service and URL resolution, user validation |
76
+ | `src/lib/services/service-catalog.js` | The in-memory catalog: groups, status flags, precedence, URL matching, allowed domains, failover entry point |
77
+ | `src/lib/services/service-url.js` | One service with its default URL and hosts; priority-host selection and failure marking |
78
+ | `src/lib/services/service-host.js` | Validated host model with `failed`/`replaced` flags and a derived URL |
79
+ | `src/lib/services/service-registry.js` | Filterable host collection with catalog-name mapping and remote-hostmap mapping |
80
+ | `src/lib/services/service-state.js` | Per-catalog collecting/ready flag holder |
81
+ | `src/lib/services/service-fed-ramp.js` | The FedRAMP discovery URL set that replaces discovery config |
82
+ | `src/lib/interceptors/service.js` | Request-side resolution of `service` + `resource` into `uri` |
83
+ | `src/lib/interceptors/hostmap.js` | Request-side host rewriting from the host catalog |
84
+ | `src/lib/interceptors/server-error.js` | Response-error-side host failure marking behind a feature flag |
85
+ | `src/lib/domains.ts` | Allowed-domain normalization and dual-parser hostname matching used by the catalog |
86
+ | `src/lib/constants.js` | Catalog name enum, enum-type tags, and the commercial allowed-domain list |
87
+ | `src/config.js` | Default `services`, `calling.cacheU2C` and `fedramp` configuration |
88
+ | `src/webex-core.js` | Interceptor registry, pre/post ordering, `ready` derivation across children |
89
+ | `src/lib/webex-core-plugin-mixin.js` | How a plugin's `interceptors` option merges into the shared registry |
90
+ | `src/interceptors/auth.js` | A consumer of `waitForService`, `getServiceFromUrl`, `hasAllowedDomains` and `isAllowedDomainUrl` |
91
+ | `src/interceptors/catalog-url.js` | A consumer of `getServiceFromUrl` and the allowed-domain checks |
92
+ | `src/lib/services-v2/README.md` | Existing work-in-progress note for the v2 sibling, read as evidence only |
93
+ | `test/unit/spec/services/services.js` | Init lifecycle (gated and ungated), ready finalization, cache, hostmap formatting, credentials config, helper methods |
94
+ | `test/unit/spec/services/service-catalog.js` | URL-matching helpers, allowed-domain handling, catalog accessors |
95
+ | `test/unit/spec/services/service-url.js` | Priority selection, negative priorities, host failure and cluster selection |
96
+ | `test/unit/spec/services/service-host.js` | Host validation and flags |
97
+ | `test/unit/spec/services/service-registry.js` | Registry filters, load, clear, failed, replaced, reset and static mappers |
98
+ | `test/unit/spec/services/service-state.js` | State holder constructor and setters |
99
+ | `test/unit/spec/services/interceptors/service.js` | ServiceInterceptor URI generation, normalization, validation, and resolution outcomes |
100
+ | `test/unit/spec/services/interceptors/hostmap.js` | HostMapInterceptor call and error-swallowing behavior |
101
+ | `test/unit/spec/services/interceptors/server-error.js` | ServerErrorInterceptor behavior with the feature flag on and off |
102
+ | `test/integration/spec/services/services.js` | Real-U2C behavior of collection, waiting, user validation and failover (needs provisioned test users) |
103
+ | `test/integration/spec/services/service-catalog.js`| Real-U2C catalog population, lookups and failover |
104
+
105
+ ## Purpose and boundary
106
+
107
+ - **Responsibility:** know where every Webex service lives. Fetch the U2C hostmap for the right
108
+ catalog group at the right time, hold it as a catalog of service URLs with prioritized hosts,
109
+ answer name-to-URL and URL-to-service questions for the rest of the SDK, rewrite requests to
110
+ catalog URLs and hosts, and tell `webex.ready` when the catalog is usable.
111
+ - **In scope:** the `Services` plugin and its helper classes; catalog groups `discovery`,
112
+ `override`, `preauth`, `signin`, `postauth`; U2C collection with query handling and optional
113
+ force-refresh; the localStorage catalog cache; the gated and ungated init lifecycle and its
114
+ timeout; host selection, failover and failure marking; allowed-domain storage and matching
115
+ entry points; FedRAMP discovery substitution; user validation and activation helpers that
116
+ drive catalog collection; the `ServiceInterceptor`, `HostMapInterceptor`, `ServerErrorInterceptor`.
117
+ - **Out of scope:** the v2 implementation in [`src/lib/services-v2/docs/README.md`](../../services-v2/docs/README.md);
118
+ the auth and catalog-URL interceptors and the interceptor ordering in `src/webex-core.js` (parent
119
+ module); token acquisition and `getOrgId` (credentials module); the HTTP request/interceptor
120
+ machinery (`http-core`, summarized under Dependencies); the device plugin that defines the
121
+ `web-high-availability` feature flag.
122
+ - **Consumers:** about 27 sibling packages call the plugin through `webex.internal.services`
123
+ (for example device, mercury, conversation, meetings, rooms, memberships, metrics, authorization
124
+ plugins), and the parent's auth and catalog-URL interceptors.
125
+
126
+ ## Structure and key files
127
+
128
+ | Path | Responsibility |
129
+ | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
130
+ | `src/lib/services/index.js` | Side-effect registration of the plugin and the two interceptors it owns, plus named re-exports |
131
+ | `src/lib/services/services.js` | The `Services` plugin (ampersand-state extension of the webex plugin base); the only module that talks to U2C and storage |
132
+ | `src/lib/services/service-catalog.js` | `ServiceCatalog` (ampersand-state), plus exported URL-matching helpers `parseCatalogUrl`, `matchesParsedCatalogUrl`, `matchesCatalogUrl` |
133
+ | `src/lib/services/service-url.js` | `ServiceUrl` (ampersand-state): a default URL and hosts; priority-host selection and failure marking |
134
+ | `src/lib/services/service-host.js` | `ServiceHost` plain class with validation, `active`/`local`/`service`/`url` getters |
135
+ | `src/lib/services/service-registry.js` | `ServiceRegistry` plain class: host collection with composable filters; instantiated per webex but not populated by the plugin |
136
+ | `src/lib/services/service-state.js` | `ServiceState` plain class: collecting/ready flags per `SERVICE_CATALOGS` name; instantiated per webex but not driven by the plugin |
137
+ | `src/lib/services/service-fed-ramp.js` | Default export: the hydra, u2c and sqdiscovery URLs used when `fedramp` is on |
138
+ | `src/lib/interceptors/service.js` | `ServiceInterceptor`: turns `service`/`api` + `resource` into `uri` after waiting for the service |
139
+ | `src/lib/interceptors/hostmap.js` | `HostMapInterceptor`: rewrites the request host from the host catalog |
140
+ | `src/lib/interceptors/server-error.js` | `ServerErrorInterceptor`: on 500/502/503, marks the failed host when the HA feature flag is on |
141
+
142
+ `src/lib/interceptors/` contains exactly these three files; the other interceptors in the package live in `src/interceptors` and belong to the parent.
143
+
144
+ ## Public surface
145
+
146
+ | Surface | Contract | Consumer | Compatibility commitment | Source |
147
+ | --- | --- | --- | --- | --- |
148
+ | Internal plugin `services` (reached as `webex.internal.services`) | `webex-core-services` | Sibling plugins and the parent's interceptors | Method names and result shapes are relied on across about 27 packages; the behavior of the lookup, wait, failover and cache methods is summarized under Requirements. No version policy is declared in code | `src/lib/services/services.js` |
149
+ | `Services`, `ServiceCatalog`, `ServiceRegistry`, `ServiceState`, `ServiceHost`, `ServiceUrl` | `webex-core-services` | Package consumers and tests importing from the package entry | Named exports; no deprecation markers in code | `src/lib/services/index.js`, `src/index.js` |
150
+ | `ServiceInterceptor`, `ServerErrorInterceptor` (registered by the plugin) and `HostMapInterceptor` (registered by the core) | `webex-core-services` | The request pipeline; also exported for tests | Created by static `create()` with `this` bound to the webex instance | `src/lib/interceptors/service.js`, `src/lib/interceptors/server-error.js`, `src/lib/interceptors/hostmap.js`, `src/webex-core.js` |
151
+ | `parseCatalogUrl`, `matchesParsedCatalogUrl`, `matchesCatalogUrl` | `webex-core-services` | Catalog internals; exported from the catalog file | Not re-exported from the package entry | `src/lib/services/service-catalog.js` |
152
+ | Configuration `services.*` (`discovery`, `override`, `allowedDomains`, `validateDomains`, `validateCatalogUrls`, `servicesNotNeedValidation`, `waitForCatalogInit`, `catalogInitTimeout`, `skipPreauthCatalogOnUnauthenticated`, `useUserOnboardingServiceForActivations`), `calling.cacheU2C`, `fedramp` | `webex-core-services` | SDK integrators | Keys are read at the moment of `change:config`, not live | `src/config.js` |
153
+ | Session property `ready` and props `validateDomains`, `initFailed` | `webex-core-services` | `webex.ready` derivation, auth and catalog-URL interceptors | `ready` participates in `webex.ready` when it is `false` | `src/lib/services/services.js`, `src/webex-core.js` |
154
+
155
+ `waitForCatalogInit` is read by this module but has no default in `src/config.js`; absent means disabled.
156
+ `useCatalogOverride` exists in `src/config.js` but is read only by the v2 implementation, not by this module.
157
+
158
+ ## Dependencies
159
+
160
+ | Dependency | Why it is required | Failure behavior |
161
+ | --- | --- | --- |
162
+ | U2C HTTP service (contract `u2c-service`) | Source of the hostmap for the preauth (`/limited/catalog`), signin and postauth (`/catalog`) groups | A failed fetch rejects `updateServices`, clears the group's `collecting` flag, and in init paths sets `initFailed`; discovery URLs from config remain usable |
163
+ | `@webex/http-core` (contract `http-core-sdk`; specified in the http-core spec) | Provides the `Interceptor` base class and the request pipeline the three interceptors plug into; its error taxonomy supplies the 5xx classes the server-error interceptor tests for | Interceptor hooks follow the http-core contract: `onRequest` result or rejection, `onResponseError` returns a rejection to propagate |
164
+ | Credentials module of this package (contract `webex-core-credentials`) | `getOrgId`, `canAuthorize`, `supertoken`, `getUserToken`, `getClientToken`, `isRefreshing` and `config` drive preauth selection, postauth gating, cache org match, user validation and ready finalization | `getOrgId` throwing rejects `initServiceCatalogs`; elsewhere errors are caught and logged (cache paths) |
165
+ | Webex plugin base (`src/lib/webex-plugin.js`) | `request`, `logger`, `webex`, event helpers (`listenToOnce`) and `namespace` | Not applicable |
166
+ | `ampersand-state` (contract `ampersand-state-library`) | Base for `Services`, `ServiceCatalog`, `ServiceUrl`; supplies typed props, `session`, `trigger`/`once`/`listenToOnce` (read from code; no spec) | Assigning a wrong-typed prop throws per the library |
167
+ | `lodash` (`union`, `forEach`, `uniq`), `crypto-js/sha256` | Allowed-domain merge, hostmap iteration and email hashing for `emailhash` queries (read from code; no spec) | Not applicable |
168
+ | Node `url` module (legacy `Url.parse`/`Url.format`) and the WHATWG `URL` | Host URL generation and URL matching | `new URL` failures are caught in matching helpers and treated as no match |
169
+ | Device plugin (read from code; no spec) | `internal.device.features.developer.get('web-high-availability')` gates failover marking | A missing device plugin makes the server-error interceptor throw a TypeError instead of rejecting with the original reason |
170
+ | New-metrics and client-metrics plugins (read from code; no spec) | `callDiagnosticLatencies.measureLatency` wraps the U2C fetch when present; `submitClientMetrics` records not-found services and HA failures | Metrics are optional for the U2C fetch; the not-found metric call assumes `internal.metrics` exists |
171
+ | `@webex/common-timers` (contract `common-timers-sdk`) | Declared in the package manifest; not imported by any file in this module | Not applicable |
172
+ | Config sources `config.js`, `lib/constants.js`, `lib/domains.ts`, `lib/metrics.js` | Defaults, catalog enum and commercial allow-list, allowed-domain logic, metric names | Not applicable |
173
+
174
+ ## Requirements
175
+
176
+ | ID | WHAT | WHY | Source evidence | Test or example evidence | Assumptions or gaps | Confidence |
177
+ | --- | --- | --- | --- | --- | --- | --- |
178
+ | `SVC-001` | The plugin registers itself as internal plugin `services` together with `ServiceInterceptor` and `ServerErrorInterceptor`; `HostMapInterceptor` is registered by the core, not by this plugin | Request interception must exist whenever the plugin is loaded, while the host rewrite applies even in cores that do not load the plugin | `src/lib/services/index.js`, `src/webex-core.js`, `src/lib/webex-core-plugin-mixin.js` | `test/unit/spec/services/services.js` (initialize creates catalog, registry, state) | No test asserts the interceptor registration itself | Present |
179
+ | `SVC-002` | On `change:config` (once) the plugin loads discovery URLs and `services.override` into catalog groups `discovery` and `override`, substitutes the FedRAMP set for discovery when `fedramp` is on, sets allowed domains, and copies `validateDomains` from config | The u2c, hydra and sqdiscovery URLs must be resolvable before any catalog fetch, and the allowed-domain policy must exist before the first authenticated request | `src/lib/services/services.js`, `src/lib/services/service-fed-ramp.js`, `src/config.js` | `test/unit/spec/services/services.js` | The FedRAMP substitution branch is not unit tested | Present |
180
+ | `SVC-003` | Outside FedRAMP, `services.allowedDomains` is unioned with the commercial allowed-domain list (`wbx2.com`, `ciscospark.com`, `webex.com`, `webexapis.com` and four broadcloud domains); in FedRAMP only the configured list applies | Commercial builds must authorize Webex hosts by default while FedRAMP must not silently trust commercial domains | `src/lib/services/services.js`, `src/lib/constants.js` | `test/unit/spec/services/services.js` (allowed domains set from config) | No test pins the union or the FedRAMP exclusion | Present |
181
+ | `SVC-004` | Catalog groups are searched by name in precedence override, postauth, signin, preauth, discovery for `get` and cluster lookups; `list` builds its map from discovery up to override so higher groups overwrite lower ones | An explicit override or authenticated catalog must win over bootstrap URLs | `src/lib/services/service-catalog.js` | `test/unit/spec/services/service-catalog.js`, `test/integration/spec/services/service-catalog.js` | `findServiceUrlFromUrl` iterates the opposite order (see `SVC-014`) | Present |
182
+ | `SVC-005` | `updateServices` maps `from: 'limited'` to group `preauth`, `from: 'signin'` to `signin`, anything else to `postauth`, and requests `/limited/catalog`, `/signin/catalog` or `/catalog` on the `u2c` service with `format=hostmap` | The three groups carry different visibility, and U2C selects the response by path | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (limited catalog by email, userId, orgId, mode), `test/integration/spec/services/services.js` | Group mapping is covered only through query assertions, not the path | Present |
183
+ | `SVC-006` | For the preauth group the first key of `query` must be one of `email`, `emailhash`, `userId`, `orgId`, `mode`, otherwise the call rejects with `a query param of email, emailhash, userId, orgId, or mode is required`; an `email` value is lower-cased and sent as a SHA-256 `emailhash`; for signin the same email hashing applies and other keys pass through; only the first query key is used | U2C selects a catalog by identity or proximity and must not receive a raw email address | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (email hashed, userId, orgId, mode, nothing provided) | Rejection leaves the group stuck collecting (see Pitfalls) | Present |
184
+ | `SVC-007` | `forceRefresh` adds a `timestamp` query parameter to bypass U2C cache control; a `token` is sent as the `authorization` header | Caches in front of U2C otherwise serve stale catalogs; signin catalogs need a client token | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (forceRefresh true), `test/integration/spec/services/services.js` | None | Present |
185
+ | `SVC-008` | A second `updateServices` for a group whose `collecting` flag is true does not fetch again; it returns the pending `waitForCatalog` promise for the group | Concurrent callers share one in-flight fetch per group | `src/lib/services/services.js`, `src/lib/services/service-catalog.js` | none found | No test exercises the in-flight guard | Weak |
186
+ | `SVC-009` | A successful fetch formats the hostmap into per-service host lists (home-cluster hosts first with `homeCluster: true`, other clusters' hosts with the same service id with `homeCluster: false`), merges the host catalog and service links into instance state, updates the group (dropping services no longer present), marks it ready, triggers an event named after the group, updates credentials config and clears `collecting` | Consumers need prioritized hosts per service, with removed services disappearing on refresh | `src/lib/services/services.js`, `src/lib/services/service-catalog.js` | `test/unit/spec/services/services.js` (formatted hostmap), `test/unit/spec/services/service-catalog.js`, `test/integration/spec/services/service-catalog.js` | `_hostCatalog` and `_serviceUrls` are merged and never pruned | Present |
187
+ | `SVC-010` | `updateCredentialsConfig` copies the highest-priority `idbroker` and `identity` URLs (trailing slash removed) into credentials config, and sets `authorizeUrl` from idbroker unless an authorization string is configured | The OAuth endpoints must follow the discovered region, not the build-time default | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (idbroker, identity and authorize url cases) | Only one slash is stripped per string | Present |
188
+ | `SVC-011` | `waitForCatalog('postauth')` with a supertoken present and the group neither collecting nor ready starts collection itself (full init when preauth is not ready, otherwise `updateServices`) instead of waiting | A caller racing the init sequence must not wait for an event that has not been requested | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (initServiceCatalogs paths); `test/integration/spec/services/services.js` | The caller's timeout is ignored on this branch; no direct unit test of the branch | Weak |
189
+ | `SVC-012` | `ServiceCatalog.waitForCatalog` resolves immediately if the group is ready, otherwise resolves on the group's event or rejects after `timeout` seconds (60 when not a non-negative number) with `services: timeout occured while waiting for '<group>' catalog to populate` | Callers need bounded waiting with a consistent failure | `src/lib/services/service-catalog.js` | `test/integration/spec/services/service-catalog.js` (promise, timeout rejection, resolved once ready) | When already ready, the timer and listener are still created (see Pitfalls) | Present |
190
+ | `SVC-013` | `waitForService({name, url, timeout=5})` resolves in this order: the raw discovered link for names in `servicesNotNeedValidation`; the priority URL by name or by URL; when the catalog is ready, the given `url` as-is, else a rejection `services: service '<name>' was not found in any of the catalogs`; otherwise it waits on all three groups and resolves on the first hit, rejecting `services: service '<name>' was not found after waiting` only after all three settle; each not-found rejection reports a client metric | Request building must not fail merely because a catalog is still loading, yet unknown services must fail loudly | `src/lib/services/services.js` | `test/integration/spec/services/services.js` (name, url, name and url; existing, missing, becoming available) | Not unit tested; relies on live U2C | Present |
191
+ | `SVC-014` | `getServiceFromUrl` and `isServiceUrl` match a URL to a service when its origin (scheme, host, port) equals the service's default URL origin or an alternate-host URL, and its path equals or extends the service path at a `/` boundary; unparsable input matches nothing; groups are scanned discovery first, override last | A hostname that merely begins with a trusted host, a different port, scheme or path prefix must not be treated as a Webex service, because the result decides whether credentials are attached | `src/lib/services/service-catalog.js` | `test/unit/spec/services/service-catalog.js` (origin and path validation, SECURITY cases), `test/unit/spec/services/services.js`, `test/integration/spec/services/service-catalog.js` | Match result precedence differs from name precedence | Present |
192
+ | `SVC-015` | `isAllowedDomainUrl` is true only when the URL's hostname is an allowed domain or a subdomain of one, as decided by the domains helper; `hasAllowedDomains` reports whether any entry exists; `setAllowedDomains` and `addAllowedDomains` store canonicalized, de-duplicated entries | Allowed-domain checks gate whether the auth header is attached, so substring or parser-differential matches must not pass | `src/lib/services/service-catalog.js`, `src/lib/domains.ts`, `src/lib/services/services.js` | `test/unit/spec/services/service-catalog.js` (parametrized allowed-domain matching, set/add/get), `test/unit/spec/services/services.js` (isAllowedDomainUrl) | Matching rules themselves are owned by the helper in `src/lib/domains.ts` | Present |
193
+ | `SVC-016` | `get(name, true)` returns the URL of the best host: hosts with non-positive priority are ignored; without a cluster id only home-cluster hosts qualify; non-failed hosts are preferred; the lowest priority number wins; if every candidate has failed their `failed` flags are cleared and selection restarts; with no usable host the default URL is returned | Failover must degrade gracefully to the default URL and must never get stuck with every host disabled | `src/lib/services/service-url.js` | `test/unit/spec/services/service-url.js` (negative, zero, mixed priorities; reset when all failed; cluster id cases) | None | Present |
194
+ | `SVC-017` | `markFailedUrl(url, noPriorityHosts)` marks the matching host failed and returns the next viable URL (the default URL when `noPriorityHosts` is true or no host remains); marking the service default URL itself changes nothing; it returns `undefined` when no service owns the URL | Callers retrying after a server error need an alternative host without an extra lookup | `src/lib/services/service-catalog.js`, `src/lib/services/service-url.js` | `test/unit/spec/services/service-url.js` (failHost), `test/integration/spec/services/service-catalog.js`, `test/integration/spec/services/services.js` (marks failed, returns next, resets) | No unit test of the catalog-level method | Present |
195
+ | `SVC-018` | `getClusterId`, `getServiceFromClusterId` and `getServiceUrlFromClusterId` map between URLs, cluster ids and services; the last defaults `us` to the default cluster identifier and appends a service name when the id lacks one, and throws `Could not find service for cluster [<cluster>]` when nothing matches | Conversation and mercury flows address clusters by id rather than URL | `src/lib/services/service-catalog.js`, `src/lib/services/services.js` | `test/unit/spec/services/service-catalog.js`, `test/integration/spec/services/services.js` | `getServiceUrlFromClusterId` has no test; the default cluster comes from environment variables or a built-in constant | Weak |
196
+ | `SVC-019` | `convertUrlToPriorityHostUrl` replaces the service's default URL inside the given URL with its priority URL and throws `No service associated with url: [<url>]` for unknown URLs | Websocket and other long-lived connections need the preferred host for an already-known URL | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (converts; throws) | None | Present |
197
+ | `SVC-020` | `replaceHostFromHostmap` replaces the host of a URI with the first host catalog entry of its host key, and returns the URI unchanged when the host catalog is unset or has no entry | Requests that already carry absolute URLs must still use the discovered host | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (four cases) | None | Present |
198
+ | `SVC-021` | `HostMapInterceptor.onRequest` rewrites `options.uri` through `replaceHostFromHostmap` when a URI exists and swallows any error, leaving the URI untouched | A malformed or relative URI must not abort the request | `src/lib/interceptors/hostmap.js` | `test/unit/spec/services/interceptors/hostmap.js` | None | Present |
199
+ | `SVC-022` | `ServiceInterceptor.onRequest` returns options unchanged when `uri` is set; otherwise it maps `api` to `service` (without overriding an explicit `service`), requires both `resource` and `service` (throwing `a \`resource\` parameter is required` or `a valid 'service' parameter is required`), waits for the service honoring `waitForServiceTimeout`, and sets `uri` to the service URL joined with the resource | Callers address services by logical name so that region, override and failover are applied centrally | `src/lib/interceptors/service.js` | `test/unit/spec/services/interceptors/service.js` | None | Present |
200
+ | `SVC-023` | When the service cannot be resolved `ServiceInterceptor` rejects with `service-interceptor: '<service>' is not a known service`, discarding the underlying cause | Gives request callers a single recognizable failure | `src/lib/interceptors/service.js` | `test/unit/spec/services/interceptors/service.js` (rejected promise case) | The underlying wait failure (timeout versus not found) is not surfaced | Present |
201
+ | `SVC-024` | `ServerErrorInterceptor.onResponseError` reacts only to `InternalServerError`, `BadGateway` and `ServiceUnavailable` with a URI and only when developer feature `web-high-availability` is present and truthy; it then submits a `web-ha` client metric, calls `markFailedUrl` and still rejects with the original error; every other case rejects with the original error unchanged | Subsequent retries should use the next host, but only for orgs that enabled high availability, and the error must still reach the caller | `src/lib/interceptors/server-error.js` | `test/unit/spec/services/interceptors/server-error.js` | The retry itself is not performed here; it belongs to the caller or another interceptor | Present |
202
+ | `SVC-025` | `initServiceCatalogs` resolves the org id, collects the preauth catalog for it, and, when `canAuthorize`, collects the postauth catalog then sets `catalog.isReady`; a postauth failure sets `initFailed` and is swallowed; a failed `getOrgId` or preauth collection rejects | Authenticated users need the full catalog; a failed postauth fetch must not break login | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (initServiceCatalogs, initFailed), `test/integration/spec/services/services.js` | None | Present |
203
+ | `SVC-026` | By default (`waitForCatalogInit` not true) `services.ready` is set true immediately, and catalog collection starts on the first webex `ready` event: load from cache and finish if warm; with a supertoken run `initServiceCatalogs`; otherwise collect preauth by configured email or by proximity unless `skipPreauthCatalogOnUnauthenticated` is true; failures set `initFailed` and are logged | The historical behavior must not block `webex.ready` on the network | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (initialize ungated cases, skip preauth) | None | Present |
204
+ | `SVC-027` | With `waitForCatalogInit` true `services.ready` stays false until the initial collection has settled or `catalogInitTimeout` ms (15000 default) elapsed, and any in-flight credentials refresh has finished (`change:isRefreshing`); it listens on `loaded`, not `ready`; a fresh login (`change:canAuthorize`) triggers postauth collection when not already ready; a skipped preauth fetch still finalizes ready without creating a timer | `webex.ready` must imply a populated catalog and stable credentials, without a hung request blocking it forever or deadlocking on `ready` | `src/lib/services/services.js`, `src/config.js`, `src/webex-core.js` | `test/unit/spec/services/services.js` (gated init, timeout, refresh wait, fresh login, skip preauth), `test/integration/spec/services/services.js` (webex.ready blocked until services.ready) | The init timeout timer is never cleared | Present |
205
+ | `SVC-028` | With `calling.cacheU2C` true each successful collection writes the hostmap per group, with selection metadata for preauth and signin, org id, a `{fedramp, u2cDiscoveryUrl}` fingerprint and `cachedAt`, to localStorage key `services.v1.u2cHostMap`; with the flag false nothing is read or written | Browser reloads should not wait for U2C, but only when the integrator opts in | `src/lib/services/services.js`, `src/config.js` | `test/unit/spec/services/services.js` (cache write, metadata, env) | Write is not awaited by the caller | Present |
206
+ | `SVC-029` | Warm-up from cache is skipped, returning false, when: the flag is off, localStorage is unavailable, no entry, entry older than 24 hours (entry removed), authorized org differs from the cached org, environment fingerprint differs, preauth selection was proximity mode, or preauth selection differs from the intended selection (org id if authorized, else hashed configured email, else proximity); otherwise groups are applied, credentials config is aligned and `catalog.isReady` is set | A stale or foreign catalog must never be applied to another org, region or environment | `src/lib/services/services.js` | `test/unit/spec/services/services.js` (TTL expiry, selection match, proximity, mismatch, env mismatch, clear) | No test for the org-mismatch branch | Present |
207
+ | `SVC-030` | `validateUser` rejects without `email`; for an authorized client it refreshes the catalog and sends the activation with the user token; otherwise it needs client id and secret, collects preauth by email, obtains a client token from the discovered idbroker, collects the signin catalog, and reports `exists`/`activated`/`details` from the outcome; failures are rejected as `{statusCode, responseText, body}` | Sign-in UIs need to know whether an address belongs to an activated user before authentication | `src/lib/services/services.js` | `test/integration/spec/services/services.js` (authorized, EU, inactive, new, existing users; prelogin id) | Not unit tested; the outer catch converts every error | Present |
208
+ | `SVC-031` | `sendUserActivation` posts to `license` `users/activations`, or to `user-onboarding` `api/v1/users/activations` when `useUserOnboardingServiceForActivations` is true, with country code and time zone from region discovery (best effort) and without token refresh | Selects the backend by configuration and enriches activation with region data when available | `src/lib/services/services.js` | `test/integration/spec/services/services.js` (license default, user-onboarding configured) | None | Present |
209
+ | `SVC-032` | `fetchClientRegionInfo` and `getMeetingPreferences` resolve with `undefined` instead of rejecting when their request fails | Auxiliary lookups must never break callers | `src/lib/services/services.js` | `test/unit/spec/services/services.js` | None | Present |
210
+ | `SVC-033` | `getMobiusClusters` returns unique mobius cluster entries from the host catalog, `isValidHost` tells whether a host key has entries, and `isIntegrationEnvironment` is true when the configured u2c discovery URL contains `intb` | Mercury and contact-center need cluster and environment hints without parsing the catalog | `src/lib/services/services.js` | `test/unit/spec/services/services.js` | None | Present |
211
+ | `SVC-034` | `ServiceHost` validates its constructor input (catalog from `SERVICE_CATALOGS`, string `defaultUri`, `hostGroup`, `uri`, numeric `priority`, four-part `id`), derives `active` (not failed and not replaced), `local`, `service` and `url`, and `polyGenerate` builds a host from catalog, name and URL | Registry data comes from an external payload and must be rejected early | `src/lib/services/service-host.js` | `test/unit/spec/services/service-host.js` | None | Present |
212
+ | `SVC-035` | `ServiceRegistry` stores validated hosts, loading only those whose catalog name maps to a known catalog, and filters them by active, catalog, cluster, local, priority, service and URL, with `clear`, `failed`, `replaced` and `reset` acting on the filtered set | Gives a host collection with composable queries independent of the catalog model | `src/lib/services/service-registry.js` | `test/unit/spec/services/service-registry.js` | The plugin does not populate or query the registry; the priority-replacement branch is untested | Weak |
213
+ | `SVC-036` | `ServiceState` creates a `{collecting, ready}` pair for each catalog name and ignores setters for unknown names | A simple state holder for the registry-style catalog names | `src/lib/services/service-state.js` | `test/unit/spec/services/service-state.js` | The plugin does not drive it | Weak |
214
+
215
+ ## Design overview
216
+
217
+ The plugin keeps three layers. `Services` is the orchestrator: it owns configuration, the network
218
+ fetch, the cache, and the init lifecycle. `ServiceCatalog` is the in-memory model it delegates
219
+ lookups to: five named groups (`discovery`, `override`, `preauth`, `postauth`, `signin`), each an
220
+ array of `ServiceUrl`, plus per-group `{ready, collecting}` flags, an `isReady` boolean and the
221
+ allowed-domain list. `ServiceUrl` models one service: a default URL and a list of hosts
222
+ (`{host, id, priority, homeCluster, failed}`), and decides which host to hand out. All three are
223
+ ampersand-state objects; `ServiceHost`, `ServiceRegistry` and `ServiceState` are plain ES classes
224
+ that follow a different, registry-style model with different catalog names (`limited` instead of
225
+ `preauth`, plus `custom`) and are only instantiated and exported, not populated by the plugin.
226
+
227
+ Catalogs are bootstrapped in two steps. Static config puts discovery URLs (u2c, hydra, sqdiscovery)
228
+ and any `override` map into the catalog on `change:config`; that is enough for `ServiceInterceptor`
229
+ to resolve `u2c` itself. Then a U2C fetch fills `preauth` (limited, identity- or proximity-selected)
230
+ and, for authorized users, `postauth`; `signin` exists for the user-validation flow. Name lookups
231
+ prefer the highest-trust group; hosts are served with a priority algorithm that self-heals when all
232
+ hosts are marked failed.
233
+
234
+ Readiness has two switches. In the default mode the plugin does not block `webex.ready` and fetches
235
+ opportunistically after it. With `waitForCatalogInit` the plugin holds `ready` false until the
236
+ first collection settles, a timeout elapses, and any credential refresh has finished, so downstream
237
+ consumers see a stable catalog and stable `canAuthorize`. The `ready` session property feeds the
238
+ core's derived `webex.ready`, which requires every child's `ready` to be not `false`.
239
+
240
+ Request-time behavior is split across three interceptors that share the plugin as state: the
241
+ service interceptor builds URIs from names, the host-map interceptor swaps hosts, and the
242
+ server-error interceptor feeds host failures back into the catalog so the next `get(name, true)`
243
+ returns another host.
244
+
245
+ The v2 module (see its spec) mirrors this plugin with a different catalog model; the two are not
246
+ used together by the code in this module.
247
+
248
+ ## Data flow and sequence coverage
249
+
250
+ Transport and call style: in-process method calls and ampersand events inside one webex instance;
251
+ outbound HTTPS requests to U2C (and hydra, license, user-onboarding) go through the webex request
252
+ pipeline, so they also pass the interceptors.
253
+
254
+ | Operation group | Entry and outcome | Diagram or evidence | Failure and recovery coverage |
255
+ | --- | --- | --- | --- |
256
+ | Catalog collection (U2C) | `updateServices` and wrappers; group populated or request rejected | Sequence 1; `src/lib/services/services.js` | Invalid query, in-flight sharing, fetch failure clearing `collecting` |
257
+ | Initialization and readiness | `change:config`, `ready`/`loaded`, `change:canAuthorize`; `services.ready` flips | Sequence 2; `src/lib/services/services.js` | Init timeout, collection errors, credential refresh wait, skipped preauth, cache hit |
258
+ | Cache warm and write | `_loadCatalogFromCache` and `_cacheCatalog`; groups hydrated or ignored | Sequence 3; `src/lib/services/services.js` | Disabled, expired, org or environment mismatch, proximity mode, storage exceptions |
259
+ | Service resolution and waiting | `get`, `waitForService`, `waitForCatalog`; URL or rejection | Sequence 4; `src/lib/services/services.js` | Timeout, not found, ready-but-unknown URL |
260
+ | Request interception and failover | Interceptor chain; `uri` set, host swapped, host marked failed | Sequence 5; `src/lib/interceptors/service.js`, `src/lib/interceptors/hostmap.js`, `src/lib/interceptors/server-error.js` | Unknown service, malformed URI, HA flag off, 5xx |
261
+ | User validation | `validateUser`; user activation outcome | Sequence 6; `src/lib/services/services.js` | Not found versus inactive user, rejection mapping |
262
+
263
+ Sequence 1 - catalog collection.
264
+
265
+ ```mermaid
266
+ sequenceDiagram
267
+ participant Caller
268
+ participant Svc as Services
269
+ participant Cat as ServiceCatalog
270
+ participant Req as webex.request
271
+ participant U2C as U2C service
272
+ Caller->>Svc: updateServices(from, query, token, forceRefresh)
273
+ Svc->>Cat: status[group].collecting?
274
+ alt group already collecting
275
+ Svc-->>Caller: waitForCatalog(group) promise
276
+ else idle
277
+ Svc->>Cat: collecting = true
278
+ opt preauth and first query key not supported
279
+ Svc-->>Caller: reject Error (group stays collecting)
280
+ end
281
+ Svc->>Svc: email to emailhash (sha256)
282
+ Svc->>Req: GET u2c /limited/catalog, /signin/catalog or /catalog (format=hostmap, timestamp if forceRefresh)
283
+ Req->>U2C: HTTPS
284
+ alt success
285
+ U2C-->>Req: hostmap
286
+ Svc->>Svc: format hostmap, merge host catalog and service links
287
+ Svc->>Svc: cache write (async, only if cacheU2C)
288
+ Svc->>Cat: updateServiceUrls(group), ready = true, trigger group event
289
+ Svc->>Svc: updateCredentialsConfig
290
+ Svc->>Cat: collecting = false
291
+ else failure
292
+ Svc->>Cat: collecting = false
293
+ Svc-->>Caller: reject with request error
294
+ end
295
+ end
296
+ ```
297
+
298
+ Sequence 2 - initialization and readiness (both modes).
299
+
300
+ ```mermaid
301
+ sequenceDiagram
302
+ participant Core as webex core
303
+ participant Svc as Services
304
+ participant Cred as credentials
305
+ participant Cat as ServiceCatalog
306
+ Core->>Svc: change:config (once)
307
+ Svc->>Svc: initConfig (discovery, override, allowed domains)
308
+ alt waitForCatalogInit not true (default)
309
+ Svc->>Svc: ready = true
310
+ Core->>Svc: ready event
311
+ Svc->>Svc: load cache
312
+ alt cache warm
313
+ Svc->>Cat: isReady = true (no fetch)
314
+ else supertoken present
315
+ Svc->>Svc: initServiceCatalogs (errors set initFailed)
316
+ else unauthenticated
317
+ Svc->>Svc: collectPreauthCatalog unless skipPreauthCatalogOnUnauthenticated
318
+ end
319
+ else waitForCatalogInit true
320
+ Core->>Svc: loaded event
321
+ Svc->>Svc: load cache
322
+ alt cache warm
323
+ Svc->>Cat: isReady = true
324
+ Svc->>Cred: await change:isRefreshing if refreshing
325
+ Svc->>Svc: ready = true
326
+ else supertoken present
327
+ Svc->>Svc: race initServiceCatalogs vs catalogInitTimeout
328
+ Svc->>Cred: await refresh if in flight
329
+ Svc->>Svc: ready = true (also on error or timeout, initFailed set)
330
+ else unauthenticated
331
+ Svc->>Svc: listen change:canAuthorize then initServiceCatalogs
332
+ alt skipPreauthCatalogOnUnauthenticated
333
+ Svc->>Svc: ready = true (no timer)
334
+ else
335
+ Svc->>Svc: race collectPreauthCatalog vs timeout, then ready = true
336
+ end
337
+ end
338
+ end
339
+ ```
340
+
341
+ Sequence 3 - cache write and warm-up.
342
+
343
+ ```mermaid
344
+ sequenceDiagram
345
+ participant Svc as Services
346
+ participant LS as localStorage
347
+ participant Cat as ServiceCatalog
348
+ Note over Svc,LS: write after a successful collection
349
+ Svc->>Svc: cacheU2C false? stop
350
+ Svc->>LS: read existing entry (errors treated as empty)
351
+ Svc->>LS: write group hostmap, meta, orgId, env, cachedAt
352
+ Note over Svc,LS: warm-up at init
353
+ Svc->>Svc: cacheU2C false or no storage? return false
354
+ Svc->>LS: read entry
355
+ alt missing or older than 24h
356
+ Svc->>LS: remove (when expired)
357
+ Svc-->>Svc: false
358
+ else org differs (authorized) or env differs
359
+ Svc-->>Svc: false
360
+ else usable
361
+ loop preauth, signin, postauth
362
+ Svc->>Svc: skip preauth when proximity or selection mismatch
363
+ Svc->>Cat: updateServiceUrls(group, formatted hostmap)
364
+ end
365
+ Svc->>Svc: updateCredentialsConfig
366
+ Svc-->>Svc: true
367
+ end
368
+ ```
369
+
370
+ Sequence 4 - service resolution and waiting.
371
+
372
+ ```mermaid
373
+ sequenceDiagram
374
+ participant Caller
375
+ participant Svc as Services
376
+ participant Cat as ServiceCatalog
377
+ Caller->>Svc: waitForService(name, url, timeout)
378
+ alt name in servicesNotNeedValidation
379
+ Svc-->>Caller: discovered service link
380
+ else known by name or url
381
+ Svc-->>Caller: priority url
382
+ else catalog isReady
383
+ alt url given
384
+ Svc-->>Caller: url as-is
385
+ else
386
+ Svc->>Svc: submit not-found metric
387
+ Svc-->>Caller: reject not found
388
+ end
389
+ else catalogs still loading
390
+ loop each of preauth, signin, postauth, concurrently
391
+ Svc->>Cat: waitForCatalog(group, timeout)
392
+ Cat-->>Svc: ready or timeout
393
+ Svc->>Svc: re-check name or url, resolve on hit
394
+ end
395
+ Svc->>Svc: all groups settled without a hit
396
+ Svc-->>Caller: reject not found after waiting
397
+ end
398
+ ```
399
+
400
+ Sequence 5 - request interception and failover.
401
+
402
+ ```mermaid
403
+ sequenceDiagram
404
+ participant App as Caller
405
+ participant SI as ServiceInterceptor
406
+ participant HM as HostMapInterceptor
407
+ participant Net as network
408
+ participant SE as ServerErrorInterceptor
409
+ participant Svc as Services
410
+ App->>SI: request {service, resource}
411
+ alt uri already set
412
+ SI-->>HM: options unchanged
413
+ else
414
+ SI->>Svc: waitForService(service, waitForServiceTimeout)
415
+ alt resolved
416
+ SI-->>HM: options.uri = serviceUrl/resource
417
+ else
418
+ SI-->>App: reject service-interceptor unknown service
419
+ end
420
+ end
421
+ HM->>Svc: replaceHostFromHostmap(uri) (errors ignored)
422
+ HM->>Net: request
423
+ Net-->>SE: 500, 502 or 503 rejection
424
+ alt HA feature on
425
+ SE->>Svc: markFailedUrl(uri)
426
+ SE-->>App: reject original error
427
+ else
428
+ SE-->>App: reject original error
429
+ end
430
+ ```
431
+
432
+ Sequence 6 - user validation (client-authenticated path).
433
+
434
+ ```mermaid
435
+ sequenceDiagram
436
+ participant Caller
437
+ participant Svc as Services
438
+ participant Cred as credentials
439
+ participant IDB as idbroker
440
+ participant Lic as license or user-onboarding
441
+ Caller->>Svc: validateUser(email)
442
+ alt no email
443
+ Svc-->>Caller: reject email required
444
+ else canAuthorize
445
+ Svc->>Svc: updateServices
446
+ Svc->>Cred: getUserToken
447
+ Svc->>Lic: sendUserActivation
448
+ Svc-->>Caller: activated, exists
449
+ else client credentials missing
450
+ Svc-->>Caller: reject client authentication details not available
451
+ else
452
+ Svc->>Svc: collectPreauthCatalog(email)
453
+ Svc->>Cred: getClientToken via idbroker url
454
+ Cred->>IDB: token request
455
+ Svc->>Svc: collectSigninCatalog(email, token)
456
+ Note over Svc: any failure maps to exists / activated flags (NotFound means no user)
457
+ Svc->>Lic: sendUserActivation
458
+ Svc-->>Caller: return user, or {statusCode, responseText, body}
459
+ end
460
+ ```
461
+
462
+ ## Class and component relationships
463
+
464
+ ```mermaid
465
+ classDiagram
466
+ class Services {
467
+ +ready
468
+ +validateDomains
469
+ +initFailed
470
+ +updateServices()
471
+ +waitForService()
472
+ +markFailedUrl()
473
+ }
474
+ class ServiceCatalog {
475
+ +serviceGroups
476
+ +status
477
+ +isReady
478
+ +allowedDomains
479
+ }
480
+ class ServiceUrl {
481
+ +name
482
+ +defaultUrl
483
+ +hosts
484
+ +get()
485
+ +failHost()
486
+ }
487
+ class ServiceRegistry
488
+ class ServiceState
489
+ class ServiceHost
490
+ class ServiceInterceptor
491
+ class HostMapInterceptor
492
+ class ServerErrorInterceptor
493
+ class Interceptor
494
+ class WebexPlugin
495
+ WebexPlugin <|-- Services
496
+ Services --> ServiceCatalog : one per webex
497
+ Services --> ServiceRegistry : one per webex, unpopulated
498
+ Services --> ServiceState : one per webex, unused
499
+ ServiceCatalog "1" o-- "*" ServiceUrl : by group
500
+ ServiceRegistry "1" o-- "*" ServiceHost
501
+ Interceptor <|-- ServiceInterceptor
502
+ Interceptor <|-- HostMapInterceptor
503
+ Interceptor <|-- ServerErrorInterceptor
504
+ ServiceInterceptor ..> Services : waitForService
505
+ HostMapInterceptor ..> Services : replaceHostFromHostmap
506
+ ServerErrorInterceptor ..> Services : markFailedUrl
507
+ ```
508
+
509
+ Per-webex instances are held in prototype-level WeakMaps (`_catalogs`, `registries`, `states`) keyed by the webex object.
510
+
511
+ ## Use cases and flows
512
+
513
+ | Use case | Actor or caller | Primary steps and outcome | Failure or boundary behavior | Evidence |
514
+ | --- | --- | --- | --- | --- |
515
+ | `UC-001` | Plugin author | Issues a request with `service` and `resource`; the interceptor waits for the service and sets `uri` to `<service url>/<resource>` | Unknown service rejects with a known-service error | `src/lib/interceptors/service.js`, `test/unit/spec/services/interceptors/service.js` |
516
+ | `UC-002` | App with a stored session | Starts the SDK; default init warms from cache when enabled, else `initServiceCatalogs` collects preauth by org id then postauth | Postauth failure sets `initFailed` and is swallowed | `src/lib/services/services.js`, `test/unit/spec/services/services.js` |
517
+ | `UC-003` | App that must not render before discovery | Enables `waitForCatalogInit`; `webex.ready` fires after collection settles, times out, or the credential refresh ends | Collection error or timeout still flips ready and sets `initFailed` | `src/lib/services/services.js`, `test/unit/spec/services/services.js` |
518
+ | `UC-004` | Unauthenticated login screen | Calls `collectPreauthCatalog` (optionally with email) so identity and idbroker URLs are available before OAuth | Missing first query key rejects | `src/lib/services/services.js`, `test/integration/spec/services/services.js` |
519
+ | `UC-005` | Sign-in UI | Calls `validateUser(email)` to learn whether the address exists and is activated | `NotFound` maps to exists false; other errors to exists true and activated false | `src/lib/services/services.js`, `test/integration/spec/services/services.js` |
520
+ | `UC-006` | Device or mercury plugin | Looks up a service by name with priority hosts, or converts a socket URL to its priority host form | Unknown URL on conversion throws | `src/lib/services/services.js`, `test/unit/spec/services/services.js` |
521
+ | `UC-007` | HA-enabled org | A 5xx response marks the failed host; the next priority lookup returns another host, and when all hosts fail they reset | Feature off: no marking | `src/lib/interceptors/server-error.js`, `src/lib/services/service-url.js`, `test/unit/spec/services/interceptors/server-error.js`, `test/unit/spec/services/service-url.js` |
522
+ | `UC-008` | Auth or catalog-URL interceptor | Asks whether a URL is a catalog service or an allowed domain before attaching credentials | Unparsable URL matches nothing | `src/interceptors/auth.js`, `src/interceptors/catalog-url.js`, `test/unit/spec/services/service-catalog.js` |
523
+ | `UC-009` | Integrator on a browser | Sets `calling.cacheU2C`; reload skips the fetch while the entry is fresh and matches org and environment | Expiry, mismatch or proximity mode forces a fetch | `src/lib/services/services.js`, `test/unit/spec/services/services.js` |
524
+
525
+ ### Cross-boundary use-case flow
526
+
527
+ | Boundary | Transport and ordering | Compatibility, timeout, retry and recovery |
528
+ | --- | --- | --- |
529
+ | U2C catalog | `GET` on service `u2c` through the full interceptor chain; the bootstrap URL comes from discovery config, so the first fetch never waits on a previous fetch | No retry in this module; the init race ends after `catalogInitTimeout`; a request error rejects and the group can be re-collected |
530
+ | hydra (`meetingPreferences`) and region discovery | Best-effort `GET`; region info uses `sqdiscovery` without auth header and a 5 s timeout | Failure resolves `undefined`; never rejects |
531
+ | license or user-onboarding | `POST users/activations` with a client or user token, token refresh disabled | Errors propagate unchanged to `validateUser`, which maps them |
532
+ | idbroker | Client token requested from the discovered idbroker `idb/oauth2/v1/access_token` with scopes `webexsquare:admin webexsquare:get_conversation Identity:SCIM` | Any failure in the client-auth chain is mapped to a user status |
533
+
534
+ ## Client state model
535
+
536
+ | State or slice | Owner | Initial state | Transition triggers | Reset or persistence boundary |
537
+ | --- | --- | --- | --- | --- |
538
+ | Catalog groups (service URL lists) | `ServiceCatalog` | Empty arrays | `updateServiceUrls`, `initConfig`, cache warm | In memory; never cleared by the plugin; `clean` exists but has no caller outside tests |
539
+ | Group status `{ready, collecting}` | `ServiceCatalog` | Both false | `updateServices` sets collecting; `updateServiceUrls` sets ready | In memory |
540
+ | `isReady` | `ServiceCatalog` | false | Set after postauth success in `initServiceCatalogs`, or by a cache warm | In memory |
541
+ | `ready` (session) | `Services` | false; set true immediately in default mode | `_finalizeReady` in gated mode | Per instance |
542
+ | `initFailed` | `Services` | false | Init collection error or timeout | Never reset |
543
+ | Host catalog and service links | `Services` (`_hostCatalog`, `_serviceUrls`) | null | Every hostmap format, including cache warm | Merged, never pruned |
544
+ | Host `failed` flag | Host objects in `ServiceUrl` | unset | `failHost`; cleared when all candidates are failed or the group is refreshed with new host objects | In memory |
545
+ | Allowed domains | `ServiceCatalog` | empty | `setAllowedDomains`, `addAllowedDomains` | In memory |
546
+ | Cached catalog | localStorage | absent | Successful collection | 24-hour TTL; persisted across reloads |
547
+
548
+ ## Business rules and invariants
549
+
550
+ | ID | Invariant | WHY | Enforcement source | Test evidence |
551
+ | --- | --- | --- | --- | --- |
552
+ | `INV-001` | The origin and path-boundary match in `SVC-014` is the only way a URL is attributed to a catalog service | Prevents credential leakage to look-alike hosts and path-prefix confusion | `src/lib/services/service-catalog.js` | `test/unit/spec/services/service-catalog.js` |
553
+ | `INV-002` | A hostname is allowed only if it equals an allowed domain or is a subdomain of it, using both URL parsers that must agree | The match gates the Authorization header | `src/lib/domains.ts`, `src/lib/services/service-catalog.js` | `test/unit/spec/services/service-catalog.js` |
554
+ | `INV-003` | A host with priority 0 or less is never selected as a priority host; the lowest positive number wins | Negative priority marks hosts that must not receive traffic | `src/lib/services/service-url.js` | `test/unit/spec/services/service-url.js` |
555
+ | `INV-004` | Without a cluster id only home-cluster hosts are priority candidates; with one, hosts of that cluster (home or not) are | Default traffic stays in the user's home cluster while explicit cluster addressing is possible | `src/lib/services/service-url.js` | `test/unit/spec/services/service-url.js` |
556
+ | `INV-005` | Priority selection never returns a failed host unless all candidates have failed, in which case all are un-failed | Avoids a dead end when all hosts are marked down | `src/lib/services/service-url.js` | `test/unit/spec/services/service-url.js` |
557
+ | `INV-006` | A raw email is never sent to U2C; it is lower-cased and hashed | Privacy of the user's address | `src/lib/services/services.js` | `test/unit/spec/services/services.js` |
558
+ | `INV-007` | A cached catalog is applied only when every skip condition listed in `SVC-029` is absent | A catalog must not cross orgs, environments or networks | `src/lib/services/services.js` | `test/unit/spec/services/services.js` |
559
+ | `INV-008` | When gated, `services.ready` becomes true only after collection settles (or times out) and no credential refresh is in flight | `webex.ready` must mean a stable catalog and credential state | `src/lib/services/services.js` | `test/unit/spec/services/services.js` |
560
+ | `INV-009` | A `ServiceHost` always has a known catalog, string URIs, numeric priority and a four-part cluster id | Registry input comes from a remote payload | `src/lib/services/service-host.js` | `test/unit/spec/services/service-host.js` |
561
+
562
+ ## Concurrency and reactive flow
563
+
564
+ - **Execution model:** single-threaded promise code; readiness is signalled through ampersand
565
+ events: the catalog triggers an event named after the group on `updateServiceUrls`, the plugin
566
+ listens once to `change:config`, `ready`, `loaded` and `change:canAuthorize` on the webex
567
+ instance, and waits on `credentials` `change:isRefreshing`.
568
+ - **Ordering guarantees:** per group, at most one fetch at a time; the second caller joins the
569
+ wait. Different groups collect independently. A cache write is started but not awaited, so a
570
+ reload immediately after a collection may not see it.
571
+ - **Idempotency and retry:** collection is idempotent (the group is reconciled with the new
572
+ hostmap). There is no retry, backoff or periodic refresh in this module; refresh happens when a
573
+ caller invokes `updateServices` again.
574
+ - **Shared-state protection:** the `collecting` flag is the only guard; there is no lock. The
575
+ `ServiceUrl` hosts are mutated in place for failure marking. `_hostCatalog` and `_serviceUrls`
576
+ are replaced by merged copies.
577
+ - **Blocking restrictions:** `waitForService` and `waitForCatalog` park requests for up to
578
+ `timeout` seconds (5 by default for services, 60 for catalogs); the gated init bounds the
579
+ wait for `webex.ready` by `catalogInitTimeout`. Network collection must not be started from a
580
+ handler that `webex.ready` itself depends on (the gated path therefore listens on `loaded`).
581
+
582
+ ## Data, schema, and migration discipline
583
+
584
+ | Store or schema | Owned entities or keys | Source of truth | Migration and compatibility rule |
585
+ | --- | --- | --- | --- |
586
+ | localStorage entry `services.v1.u2cHostMap` | `orgId`, `env` (`fedramp`, `u2cDiscoveryUrl`), `cachedAt`, and one entry per group (`preauth`, `signin`, `postauth`) holding either a raw hostmap (older shape) or `{hostMap, meta: {selectionType, selectionValue}}` | `src/lib/services/services.js` | The reader accepts both group shapes; the key name carries a version marker but no migration code exists; entries are read with a 24-hour TTL measured from the last write of any group; JSON errors are treated as no cache |
587
+
588
+ Retention and cleanup: an expired entry is removed on warm-up; `clearCatalogCache` removes the key
589
+ but has no caller outside tests in the repository. There is no logout hook in this module.
590
+
591
+ ## State machine
592
+
593
+ Per-group catalog status (`collecting`, `ready` flags in `ServiceCatalog`):
594
+
595
+ ```mermaid
596
+ stateDiagram-v2
597
+ [*] --> Empty
598
+ Empty --> Collecting: updateServices
599
+ Collecting --> Ready: hostmap applied
600
+ Collecting --> Empty: request rejected
601
+ Ready --> Refreshing: updateServices
602
+ Refreshing --> Ready: hostmap applied
603
+ Refreshing --> Ready: request rejected
604
+ Empty --> Ready: updateCatalog or cache warm
605
+ Collecting --> Stuck: invalid preauth query rejected
606
+ Stuck --> Stuck: further updateServices join wait
607
+ ```
608
+
609
+ `Stuck` is a real state of the code, not a designed one: see the first pitfall. `Refreshing`
610
+ differs from `Collecting` only in that `ready` stays true; both have `collecting` true.
611
+
612
+ Plugin readiness (`ready`, `initFailed`, `isReady`):
613
+
614
+ ```mermaid
615
+ stateDiagram-v2
616
+ [*] --> NotReady
617
+ NotReady --> Ready: default mode, immediately on init
618
+ NotReady --> Settling: gated mode, loaded event
619
+ Settling --> AwaitingRefresh: collection settled, credentials refreshing
620
+ Settling --> Ready: collection settled or timed out
621
+ AwaitingRefresh --> Ready: change:isRefreshing
622
+ Ready --> [*]
623
+ ```
624
+
625
+ `ready` never returns to false. `initFailed` is set on an error or timeout in either mode and is
626
+ independent of `ready`. `catalog.isReady` is set separately by a postauth success or a cache warm,
627
+ and never becomes true for an unauthenticated user whose cache is cold.
628
+
629
+ ## Caller-visible failure modes
630
+
631
+ | Condition | Signal or result | Caller behavior | Retry or recovery | Evidence |
632
+ | --- | --- | --- | --- | --- |
633
+ | Preauth query missing or unsupported key | Rejection `a query param of email, emailhash, userId, orgId, or mode is required` | Fix the query | Calling again does not help until the group's wait times out (see Pitfalls) | `src/lib/services/services.js` |
634
+ | Signin collection without email or token | Rejection `` `email` is required `` or `` `token` is required `` | Provide both | Retry | `src/lib/services/services.js` |
635
+ | `validateUser` without email, or without client credentials | Rejection with the message | Fix input or config | Retry | `src/lib/services/services.js` |
636
+ | U2C request fails | Rejection with the request error; `collecting` cleared | Inspect error | Call again | `src/lib/services/services.js` |
637
+ | Catalog wait times out | Rejection `services: timeout occured while waiting for '<group>' catalog to populate` | Treat the service as unavailable | Retry later | `src/lib/services/service-catalog.js` |
638
+ | Service not found | Rejection `services: service '<name>' was not found in any of the catalogs` or `... after waiting` | Treat as unknown service | Retry after the catalog loads | `src/lib/services/services.js` |
639
+ | `ServiceInterceptor` cannot resolve | Rejection `service-interceptor: '<service>' is not a known service` | Check the service name | Retry later | `src/lib/interceptors/service.js` |
640
+ | `ServiceInterceptor` option error | Synchronous throw of the `resource` or `service` message | Fix the call | None | `src/lib/interceptors/service.js` |
641
+ | `convertUrlToPriorityHostUrl` or `getServiceUrlFromClusterId` on unknown input | Thrown error `No service associated with url: [...]` or `Could not find service for cluster [...]` | Guard with lookup methods | None | `src/lib/services/services.js` |
642
+ | Gated init fails or times out | `ready` still true; `initFailed` true; error logged | Check `initFailed` | Call `updateServices` | `src/lib/services/services.js` |
643
+ | `validateUser` client path failure | Rejection shaped `{statusCode, responseText, body}` | Show the message | Retry | `src/lib/services/services.js` |
644
+
645
+ ## Pitfalls and constraints
646
+
647
+ - **A rejected preauth query leaves the group stuck.** `updateServices` sets `collecting` to true before
648
+ validating a preauth query and returns the rejection without clearing it, so later calls for
649
+ that group join `waitForCatalog` and time out after 60 seconds. A `signin` call with no `query`
650
+ fails the same way (first key lookup on `undefined`).
651
+ - **Two precedence orders.** Name lookups prefer override > postauth > signin > preauth > discovery,
652
+ but `getServiceFromUrl` scans discovery > preauth > signin > postauth > override and returns the first match.
653
+ - **Registry and state are inert.** `ServiceRegistry`, `ServiceState` and `ServiceHost` use the catalog names
654
+ `discovery`, `limited`, `signin`, `postauth`, `custom` while the live catalog uses `preauth` and has no `custom`; the plugin never loads the registry or sets the state. In
655
+ `ServiceRegistry.filterPriority` the replacement branch compares with `<` on `priority` (documented as lower number
656
+ is higher priority), and its `splice(filteredHosts.indexOf(foundHost, 1))` has a misplaced argument, removing every
657
+ element from the found index onward. Do not rely on that branch without tests.
658
+ - **Only one slash is stripped.** The trailing-slash expression has no global flag, so a URL gets either its leading or its trailing
659
+ slash removed, not both; `ServiceInterceptor.generateUri` therefore keeps a trailing slash on a resource written `/a/`.
660
+ - **Cache semantics.** The JSDoc says "bounded storage" but the code uses `window.localStorage` directly, and nothing
661
+ clears the entry on logout. `cachedAt` is rewritten by every group write, so one fresh group extends the life of an
662
+ older one. A warm start sets `isReady` and skips the network, so the catalog can be up to 24 hours old.
663
+ - **The init-timeout timer is never cleared** after the race resolves (the test comments say so), so a pending timer
664
+ outlives init; tests fake timers for this reason.
665
+ - **`waitForCatalog` leaks.** For an already-ready group the promise resolves but the timeout timer and event listener are still created.
666
+ - **`waitForService` cost.** `isReady` is true only after a postauth success or cache warm, so an unauthenticated user asking for an unknown
667
+ service waits the whole timeout (5 s by default) on every call. For names in `servicesNotNeedValidation` the plugin
668
+ reads `_serviceUrls` directly, which throws a TypeError if no hostmap has ever been formatted.
669
+ - **`ServerErrorInterceptor`** assumes the device plugin exists (feature lookup); without it the interceptor throws instead of rejecting with the original error. It marks the host but does not retry.
670
+ - **`ServiceCatalog.markFailedUrl`** marks hosts as a side effect while probing each service, and a URL equal to a service's default URL
671
+ is reported as found without marking anything.
672
+ - **`clean` is partial.** It empties `preauth`, `signin` and `postauth` and replaces their status with `{ready: false}` (dropping `collecting`), but leaves `discovery`, `override` and `isReady`.
673
+ - **Config dead keys.** `useCatalogOverride` is read only by v2. `validateCatalogUrls` is read by the core to add the catalog-URL interceptor, not by this module.
674
+ - **Config is read once.** `initConfig` runs on the first `change:config` and mutates the config object (discovery replacement under FedRAMP and the allowed-domain union).
675
+ - **The host-map interceptor runs on every request** and normalizes URIs through `URL#toString`, so a bare origin gains a trailing slash.
676
+
677
+ ## Module-specific rules
678
+
679
+ - Do: keep catalog lookups synchronous and in `ServiceCatalog`/`ServiceUrl`; keep network and
680
+ storage in `Services` (`src/lib/services/services.js`).
681
+ - Do: read configuration only after `change:config` (`initConfig`, `initialize`), never at construction.
682
+ - Do: add new interceptors through the plugin `interceptors` option so they merge into the core registry (`src/lib/services/index.js`, `src/lib/webex-core-plugin-mixin.js`).
683
+ - Do: change v1 and v2 together when the behavior is intended to match; `src/lib/services-v2/services-v2.ts` closely mirrors the init lifecycle code.
684
+ - Do not: depend on `ServiceRegistry` or `ServiceState` for live data; they are not wired.
685
+ - Do not: narrow URL matching to string prefix or `includes`; `INV-001` and `INV-002` are security boundaries.
686
+ - Do not: await `catalog.isReady` as a sign of a populated unauthenticated catalog; use `waitForCatalog` or `waitForService`.
687
+
688
+ ## Export stability
689
+
690
+ | Export or entry point | Consumer | Stability | Versioning and deprecation rule | Declaration or API report |
691
+ | --- | --- | --- | --- | --- |
692
+ | `Services`, `ServiceCatalog`, `ServiceRegistry`, `ServiceState`, `ServiceHost`, `ServiceUrl` | Package consumers and plugins | Published through the package entry; no stability markers in code | None declared in code; the parent package version governs | `src/lib/services/index.js`, `src/index.js` |
693
+ | `ServiceInterceptor`, `ServerErrorInterceptor`, `HostMapInterceptor` | Package consumers and tests | Published through the package entry | None declared in code; the parent package version governs | `src/index.js` |
694
+ | Plugin methods on `webex.internal.services` | Sibling plugins | Internal plugin namespace used by many packages; underscore-prefixed members are private by convention | None declared in code; the parent package version governs | `src/lib/services/services.js` |
695
+
696
+ ## Key design trade-off
697
+
698
+ | Chosen trade-off | Preserved invariant or benefit | Cost or limitation | Decision evidence |
699
+ | --- | --- | --- | --- |
700
+ | Gated readiness is opt-in; default mode flips `ready` immediately and fetches catalogs in the background | Existing integrators keep non-blocking startup; opted-in ones get a ready that implies a catalog | Two code paths with different guarantees; requests made before collection rely on `waitForService` | `src/lib/services/services.js`, `src/config.js`, `test/unit/spec/services/services.js` |
701
+ | Cache warm start skips the network entirely | Fast reload and fewer U2C calls | Catalog may be stale up to the TTL; proximity-mode preauth is excluded to respect network changes | `src/lib/services/services.js`, `test/unit/spec/services/services.js` |
702
+ | Host failures are tracked in memory and reset when all hosts fail | Failover without configuration and without permanent lock-out | Failure state is lost on reload; no backoff or health probing | `src/lib/services/service-url.js`, `test/unit/spec/services/service-url.js` |
703
+
704
+ Recorded gap: no decision record states why both v1 and v2 exist in parallel (Not stated in code or tests; confidence Weak); the v2 note only says v2 is a work in progress.
705
+
706
+ ## Verification
707
+
708
+ | Requirement or invariant | Test level | Positive evidence | Negative or boundary evidence | Gap |
709
+ | --- | --- | --- | --- | --- |
710
+ | `SVC-001`, `SVC-002`, `SVC-003` | Unit | `test/unit/spec/services/services.js` | none found | FedRAMP substitution, commercial union and interceptor registration unasserted |
711
+ | `SVC-004`, `SVC-016`, `INV-003`, `INV-004`, `INV-005` | Unit, integration | `test/unit/spec/services/service-url.js`, `test/integration/spec/services/service-catalog.js` | `test/unit/spec/services/service-url.js` (negative, zero, all failed) | Precedence order across groups only in integration |
712
+ | `SVC-005`, `SVC-006`, `SVC-007`, `INV-006` | Unit, integration | `test/unit/spec/services/services.js`, `test/integration/spec/services/services.js` | `test/integration/spec/services/service-catalog.js` (invalid params rejection) | Unit tests of `updateServices` cover queries but not the request path or the unsupported-query rejection |
713
+ | `SVC-008`, `SVC-011` | none | none found | none found | In-flight guard and postauth kick-off in `waitForCatalog` untested |
714
+ | `SVC-009`, `SVC-010`, `SVC-020` | Unit | `test/unit/spec/services/services.js` | `test/unit/spec/services/services.js` (no hostmap, no host) | Pruning of removed services only via catalog unit tests |
715
+ | `SVC-012` | Integration, unit | `test/integration/spec/services/service-catalog.js` | `test/integration/spec/services/service-catalog.js` (timeout) | Leaked timer unasserted |
716
+ | `SVC-013` | Integration | `test/integration/spec/services/services.js` | `test/integration/spec/services/services.js` (missing service) | No unit test; `servicesNotNeedValidation` shortcut untested |
717
+ | `SVC-014`, `SVC-015`, `INV-001`, `INV-002` | Unit | `test/unit/spec/services/service-catalog.js` | `test/unit/spec/services/service-catalog.js` (SECURITY cases) | Dual-parser mismatch is in the domains helper, not asserted here |
718
+ | `SVC-017` | Unit, integration | `test/unit/spec/services/service-url.js`, `test/integration/spec/services/services.js` | `test/unit/spec/services/service-url.js` (default url not marked) | Catalog-level unit test absent |
719
+ | `SVC-018` | Unit, integration | `test/unit/spec/services/service-catalog.js` | `test/integration/spec/services/service-catalog.js` (undefined results) | `getServiceUrlFromClusterId` untested |
720
+ | `SVC-019` | Unit | `test/unit/spec/services/services.js` | `test/unit/spec/services/services.js` (throws) | None |
721
+ | `SVC-021`, `SVC-022`, `SVC-023`, `SVC-024` | Unit | `test/unit/spec/services/interceptors/hostmap.js`, `test/unit/spec/services/interceptors/service.js`, `test/unit/spec/services/interceptors/server-error.js` | The same files (error, flag off, non-5xx, no uri) | Missing device plugin case untested |
722
+ | `SVC-025`, `SVC-026`, `SVC-027`, `INV-008` | Unit | `test/unit/spec/services/services.js` | `test/unit/spec/services/services.js` (errors, timeout, refresh) | Real-timer behavior not tested; timer leak asserted only in comments |
723
+ | `SVC-028`, `SVC-029`, `INV-007` | Unit | `test/unit/spec/services/services.js` | `test/unit/spec/services/services.js` (TTL, proximity, mismatch, env) | Org-mismatch, disabled flag, storage exception branches untested |
724
+ | `SVC-030`, `SVC-031`, `SVC-032` | Integration, unit | `test/integration/spec/services/services.js`, `test/unit/spec/services/services.js` | `test/integration/spec/services/services.js` (non-existing and inactive users) | Integration tests need provisioned users and live services; no unit coverage of `validateUser` |
725
+ | `SVC-033` | Unit | `test/unit/spec/services/services.js` | `test/unit/spec/services/services.js` (non-string inputs, undefined config) | None |
726
+ | `SVC-034`, `INV-009` | Unit | `test/unit/spec/services/service-host.js` | `test/unit/spec/services/service-host.js` (validate errors) | None |
727
+ | `SVC-035`, `SVC-036` | Unit | `test/unit/spec/services/service-registry.js`, `test/unit/spec/services/service-state.js` | `test/unit/spec/services/service-registry.js` (invalid catalog, invalid service) | Priority replacement branch and splice behavior untested |
728
+
729
+ Frameworks and counts: unit tests run on Jest (`jest.config.js` through the legacy tools) with sinon,
730
+ chai asserts from the shared helper and `MockWebex`; roughly 278 unit `it` blocks across the nine files
731
+ under `test/unit/spec/services` (parametrized allowed-domain cases expand further). Integration tests
732
+ are Mocha/Karma files with about 142 `it` blocks that create real test users and talk to live U2C,
733
+ idbroker and license services (flaky and 429-retry wrappers are used), so they are not part of
734
+ the offline unit run. Other gaps: no unit test of `waitForService`, `validateUser`, in-flight sharing,
735
+ org-mismatch cache skip, or FedRAMP/commercial allowed-domain composition; no test that logout
736
+ leaves the cache in place; no test for concurrency across groups. A module specification is complete
737
+ only when these agree with the implementation; this one records the gaps above rather than closing them.