homebridge-myleviton 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +112 -0
  3. package/config.schema.json +136 -0
  4. package/dist/api/cache.d.ts +108 -0
  5. package/dist/api/cache.d.ts.map +1 -0
  6. package/dist/api/cache.js +206 -0
  7. package/dist/api/cache.js.map +1 -0
  8. package/dist/api/circuit-breaker.d.ts +118 -0
  9. package/dist/api/circuit-breaker.d.ts.map +1 -0
  10. package/dist/api/circuit-breaker.js +223 -0
  11. package/dist/api/circuit-breaker.js.map +1 -0
  12. package/dist/api/client.d.ts +116 -0
  13. package/dist/api/client.d.ts.map +1 -0
  14. package/dist/api/client.js +358 -0
  15. package/dist/api/client.js.map +1 -0
  16. package/dist/api/index.d.ts +23 -0
  17. package/dist/api/index.d.ts.map +1 -0
  18. package/dist/api/index.js +47 -0
  19. package/dist/api/index.js.map +1 -0
  20. package/dist/api/persistence.d.ts +107 -0
  21. package/dist/api/persistence.d.ts.map +1 -0
  22. package/dist/api/persistence.js +285 -0
  23. package/dist/api/persistence.js.map +1 -0
  24. package/dist/api/rate-limiter.d.ts +102 -0
  25. package/dist/api/rate-limiter.d.ts.map +1 -0
  26. package/dist/api/rate-limiter.js +173 -0
  27. package/dist/api/rate-limiter.js.map +1 -0
  28. package/dist/api/request-queue.d.ts +104 -0
  29. package/dist/api/request-queue.d.ts.map +1 -0
  30. package/dist/api/request-queue.js +223 -0
  31. package/dist/api/request-queue.js.map +1 -0
  32. package/dist/api/websocket.d.ts +116 -0
  33. package/dist/api/websocket.d.ts.map +1 -0
  34. package/dist/api/websocket.js +319 -0
  35. package/dist/api/websocket.js.map +1 -0
  36. package/dist/errors/index.d.ts +182 -0
  37. package/dist/errors/index.d.ts.map +1 -0
  38. package/dist/errors/index.js +273 -0
  39. package/dist/errors/index.js.map +1 -0
  40. package/dist/index.d.ts +16 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +42 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/platform.d.ts +139 -0
  45. package/dist/platform.d.ts.map +1 -0
  46. package/dist/platform.js +664 -0
  47. package/dist/platform.js.map +1 -0
  48. package/dist/types/index.d.ts +225 -0
  49. package/dist/types/index.d.ts.map +1 -0
  50. package/dist/types/index.js +34 -0
  51. package/dist/types/index.js.map +1 -0
  52. package/dist/utils/index.d.ts +15 -0
  53. package/dist/utils/index.d.ts.map +1 -0
  54. package/dist/utils/index.js +52 -0
  55. package/dist/utils/index.js.map +1 -0
  56. package/dist/utils/logger.d.ts +103 -0
  57. package/dist/utils/logger.d.ts.map +1 -0
  58. package/dist/utils/logger.js +184 -0
  59. package/dist/utils/logger.js.map +1 -0
  60. package/dist/utils/retry.d.ts +56 -0
  61. package/dist/utils/retry.d.ts.map +1 -0
  62. package/dist/utils/retry.js +141 -0
  63. package/dist/utils/retry.js.map +1 -0
  64. package/dist/utils/sanitizers.d.ts +37 -0
  65. package/dist/utils/sanitizers.d.ts.map +1 -0
  66. package/dist/utils/sanitizers.js +128 -0
  67. package/dist/utils/sanitizers.js.map +1 -0
  68. package/dist/utils/validators.d.ts +51 -0
  69. package/dist/utils/validators.d.ts.map +1 -0
  70. package/dist/utils/validators.js +243 -0
  71. package/dist/utils/validators.js.map +1 -0
  72. package/package.json +69 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (which shall not include Communications that are clearly marked or
39
+ otherwise designated in writing by the copyright owner as "Not a Work").
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based upon (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is clearly marked or otherwise designated
61
+ in writing by the copyright owner as "Not a Contribution".
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct or
86
+ contributory patent infringement, then any patent licenses granted to
87
+ You under this License for that Work shall terminate as of the date
88
+ such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 tbaur
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # homebridge-myleviton
2
+
3
+ [![Tests](https://github.com/tbaur/homebridge-myleviton/actions/workflows/test.yml/badge.svg)](https://github.com/tbaur/homebridge-myleviton/actions/workflows/test.yml)
4
+ [![npm version](https://badgen.net/npm/v/homebridge-myleviton)](https://www.npmjs.com/package/homebridge-myleviton)
5
+ [![npm downloads](https://badgen.net/npm/dt/homebridge-myleviton)](https://www.npmjs.com/package/homebridge-myleviton)
6
+ [![Node.js](https://badgen.net/badge/node/%3E=20/green)](https://nodejs.org)
7
+ [![Homebridge](https://badgen.net/badge/homebridge/%3E=1.6.0/purple)](https://homebridge.io)
8
+ [![License: Apache-2.0](https://badgen.net/badge/license/Apache-2.0/blue)](LICENSE)
9
+
10
+ Control your **My Leviton Decora Smart** WiFi devices through Apple HomeKit using Homebridge.
11
+
12
+ ## Features
13
+
14
+ ### Device Control
15
+ - **Automatic Discovery** — Instantly finds all devices from your My Leviton account
16
+ - **Full Dimmer Support** — On/off and brightness control (1-100%)
17
+ - **Fan Speed Control** — 4-speed fan controllers (25/50/75/100%)
18
+ - **Switches & Outlets** — On/off control for all switch and outlet types
19
+ - **Motion Sensors** — D2MSD motion dimmers expose both dimmer and motion sensor
20
+
21
+ ### Reliability
22
+ - **Automatic State Sync** — Polls device state every 30 seconds (configurable)
23
+ - **Rate Limiting** — Prevents API throttling (300 requests/minute)
24
+ - **Circuit Breaker** — Graceful degradation during API outages
25
+ - **Auto-Reconnect** — Automatically recovers from connection issues
26
+ - **State Persistence** — Faster startup with cached device data
27
+ - **Token Auto-Refresh** — Seamless authentication management
28
+
29
+ ### Quality
30
+ - **300+ Tests** — Comprehensive test suite with 95%+ code coverage
31
+ - **Child Bridge Support** — Run as isolated bridge for maximum stability
32
+ - **Flexible Logging** — Debug, info, warn, error levels + JSON structured logs
33
+ - **No Analytics** — Zero tracking or data collection
34
+ - **Well Documented** — Detailed docs for users and developers
35
+
36
+ ## Quick Start
37
+
38
+ ### 1. Install
39
+
40
+ **Homebridge UI** (recommended):
41
+ Plugins → Search `homebridge-myleviton` → Install
42
+
43
+ **Command line:**
44
+ ```bash
45
+ npm install -g homebridge-myleviton
46
+ ```
47
+
48
+ ### 2. Configure
49
+
50
+ Add to your Homebridge config:
51
+
52
+ ```json
53
+ {
54
+ "platforms": [
55
+ {
56
+ "platform": "MyLevitonDecoraSmart",
57
+ "email": "your@email.com",
58
+ "password": "yourpassword"
59
+ }
60
+ ]
61
+ }
62
+ ```
63
+
64
+ ### 3. Restart Homebridge
65
+
66
+ Your devices will appear in the Home app automatically.
67
+
68
+ ## Supported Devices
69
+
70
+ | Type | Examples |
71
+ |------|----------|
72
+ | **Dimmers** | DW6HD, D26HD, DW1KD, DW3HL, D23LP, DWVAA |
73
+ | **Switches** | DW15S, D215S |
74
+ | **Outlets** | DW15P, DW15A, DW15R, D215P |
75
+ | **Fans** | DW4SF |
76
+ | **Motion Dimmers** | D2MSD |
77
+
78
+ ## Configuration Options
79
+
80
+ | Option | Required | Description |
81
+ |--------|:--------:|-------------|
82
+ | `email` | ✓ | My Leviton account email |
83
+ | `password` | ✓ | My Leviton account password |
84
+ | `loglevel` | | `debug`, `info` (default), `warn`, `error` |
85
+ | `pollInterval` | | Seconds between state updates (default: 30) |
86
+ | `excludedModels` | | Device models to skip, e.g. `["DW15P"]` |
87
+ | `excludedSerials` | | Device serials to skip |
88
+
89
+ ## Not Working?
90
+
91
+ 1. **Check credentials** — Must match the My Leviton app exactly
92
+ 2. **Check device status** — Devices must be online in My Leviton app
93
+ 3. **Enable debug logs** — Set `"loglevel": "debug"` and restart
94
+ 4. **Restart Homebridge** — Required after any config change
95
+
96
+ ## Requirements
97
+
98
+ - Homebridge 1.6.0+ or 2.0+
99
+ - Node.js 20+
100
+ - My Leviton account with registered devices
101
+
102
+ ## More Info
103
+
104
+ - [Details](docs/README-DETAILED.md)
105
+ - [Report Issues](https://github.com/tbaur/homebridge-myleviton/issues)
106
+ - [Changelog](CHANGELOG.md)
107
+
108
+ ## License
109
+
110
+ Copyright 2026 tbaur
111
+
112
+ Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) file for details.
@@ -0,0 +1,136 @@
1
+ {
2
+ "pluginAlias": "MyLevitonDecoraSmart",
3
+ "pluginType": "platform",
4
+ "singular": true,
5
+ "headerDisplay": "Control your Leviton Decora Smart Wi-Fi switches, dimmers, outlets, and fan controllers through HomeKit.",
6
+ "footerDisplay": "---\n\n**Need Help?** Check out the [GitHub Repository](https://github.com/tbaur/homebridge-myleviton) for documentation, troubleshooting guides, and to report issues.",
7
+ "schema": {
8
+ "type": "object",
9
+ "properties": {
10
+ "email": {
11
+ "title": "Username ",
12
+ "type": "string",
13
+ "required": true,
14
+ "format": "email",
15
+ "placeholder": "you@example.com",
16
+ "description": "The email address you use to sign in to the My Leviton app",
17
+ "x-schema-form": {
18
+ "type": "username"
19
+ }
20
+ },
21
+ "password": {
22
+ "title": "Password ",
23
+ "type": "string",
24
+ "required": true,
25
+ "placeholder": "••••••••••••",
26
+ "description": "Your My Leviton account password (stored securely in your Homebridge config)",
27
+ "x-schema-form": {
28
+ "type": "password"
29
+ }
30
+ },
31
+ "loglevel": {
32
+ "title": "Log Level",
33
+ "type": "string",
34
+ "default": "info",
35
+ "oneOf": [
36
+ { "title": "Debug - Verbose logging for troubleshooting", "enum": ["debug"] },
37
+ { "title": "Info - Standard operational messages", "enum": ["info"] },
38
+ { "title": "Warn - Warnings and important notices", "enum": ["warn"] },
39
+ { "title": "Error - Only errors and critical issues", "enum": ["error"] }
40
+ ],
41
+ "description": "Controls how much detail appears in Homebridge logs. Use Debug when troubleshooting issues."
42
+ },
43
+ "pollInterval": {
44
+ "title": "Poll Interval",
45
+ "type": "integer",
46
+ "default": 30,
47
+ "minimum": 10,
48
+ "maximum": 300,
49
+ "description": "How often (in seconds) to check device states. Lower values = faster updates but more API calls. Default: 30 seconds."
50
+ },
51
+ "excludedModels": {
52
+ "title": "Excluded Models",
53
+ "type": "array",
54
+ "description": "Device models to exclude from HomeKit. Enter the model number (e.g., DW4BC for button controllers). Useful for devices you don't want to control via HomeKit.",
55
+ "items": {
56
+ "type": "string",
57
+ "title": "Model Number",
58
+ "placeholder": "e.g., DW4BC"
59
+ }
60
+ },
61
+ "excludedSerials": {
62
+ "title": "Excluded Serial Numbers",
63
+ "type": "array",
64
+ "description": "Specific devices to exclude by serial number. Find the serial in the My Leviton app under device settings.",
65
+ "items": {
66
+ "type": "string",
67
+ "title": "Serial Number",
68
+ "placeholder": "e.g., ABC123DEF456"
69
+ }
70
+ },
71
+ "structuredLogs": {
72
+ "title": "Enable Structured Logging (JSON)",
73
+ "type": "boolean",
74
+ "default": false,
75
+ "description": "Output logs in JSON format for integration with log management tools like Datadog, Splunk, or ELK stack."
76
+ }
77
+ }
78
+ },
79
+ "layout": [
80
+ {
81
+ "type": "fieldset",
82
+ "title": "Account Credentials",
83
+ "description": "Enter your My Leviton account details.",
84
+ "expandable": false,
85
+ "items": [
86
+ "email",
87
+ "password"
88
+ ]
89
+ },
90
+ {
91
+ "type": "fieldset",
92
+ "title": "General Settings",
93
+ "expandable": true,
94
+ "expanded": true,
95
+ "items": [
96
+ "loglevel",
97
+ "pollInterval"
98
+ ]
99
+ },
100
+ {
101
+ "type": "fieldset",
102
+ "title": "Device Exclusions",
103
+ "description": "Optionally exclude specific device types or individual devices from appearing in HomeKit.",
104
+ "expandable": true,
105
+ "expanded": false,
106
+ "items": [
107
+ {
108
+ "key": "excludedModels",
109
+ "type": "array",
110
+ "buttonText": "Add Model to Exclude",
111
+ "items": {
112
+ "type": "string"
113
+ }
114
+ },
115
+ {
116
+ "key": "excludedSerials",
117
+ "type": "array",
118
+ "buttonText": "Add Serial to Exclude",
119
+ "items": {
120
+ "type": "string"
121
+ }
122
+ }
123
+ ]
124
+ },
125
+ {
126
+ "type": "fieldset",
127
+ "title": "Advanced Options",
128
+ "description": "Settings for power users and developers.",
129
+ "expandable": true,
130
+ "expanded": false,
131
+ "items": [
132
+ "structuredLogs"
133
+ ]
134
+ }
135
+ ]
136
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Copyright (c) 2026 tbaur
3
+ *
4
+ * Licensed under the Apache License, Version 2.0
5
+ * See LICENSE file for full license text
6
+ *
7
+ * @fileoverview Response caching with TTL and LRU eviction
8
+ */
9
+ /**
10
+ * Cache configuration
11
+ */
12
+ export interface CacheConfig {
13
+ /** Time-to-live in milliseconds */
14
+ ttlMs: number;
15
+ /** Maximum number of entries */
16
+ maxSize: number;
17
+ /** Whether to update timestamp on access */
18
+ updateOnAccess?: boolean;
19
+ }
20
+ /**
21
+ * Default cache configuration
22
+ */
23
+ export declare const DEFAULT_CACHE_CONFIG: CacheConfig;
24
+ /**
25
+ * Response cache with TTL and optional LRU eviction
26
+ */
27
+ export declare class ResponseCache<T = unknown> {
28
+ private readonly cache;
29
+ private readonly ttlMs;
30
+ private readonly maxSize;
31
+ private readonly updateOnAccess;
32
+ private hits;
33
+ private misses;
34
+ constructor(config?: Partial<CacheConfig>);
35
+ /**
36
+ * Check if entry is expired
37
+ */
38
+ private isExpired;
39
+ /**
40
+ * Evict oldest entries if over capacity
41
+ */
42
+ private evictIfNeeded;
43
+ /**
44
+ * Get cached value if still valid
45
+ * @returns Cached data or null if expired/missing
46
+ */
47
+ get(key: string): T | null;
48
+ /**
49
+ * Set cache value
50
+ */
51
+ set(key: string, data: T): void;
52
+ /**
53
+ * Check if key exists and is not expired
54
+ */
55
+ has(key: string): boolean;
56
+ /**
57
+ * Delete a specific key
58
+ */
59
+ delete(key: string): boolean;
60
+ /**
61
+ * Clear expired entries
62
+ */
63
+ clearExpired(): number;
64
+ /**
65
+ * Clear all cache entries
66
+ */
67
+ clear(): void;
68
+ /**
69
+ * Get number of entries
70
+ */
71
+ get size(): number;
72
+ /**
73
+ * Get cache hit ratio
74
+ */
75
+ get hitRatio(): number;
76
+ /**
77
+ * Get cache statistics
78
+ */
79
+ getStats(): {
80
+ size: number;
81
+ maxSize: number;
82
+ ttlMs: number;
83
+ hits: number;
84
+ misses: number;
85
+ hitRatio: number;
86
+ };
87
+ /**
88
+ * Reset statistics
89
+ */
90
+ resetStats(): void;
91
+ /**
92
+ * Get all keys
93
+ */
94
+ keys(): string[];
95
+ /**
96
+ * Get or set a value using a factory function
97
+ */
98
+ getOrSet(key: string, factory: () => Promise<T>): Promise<T>;
99
+ }
100
+ /**
101
+ * Get or create the global cache
102
+ */
103
+ export declare function getResponseCache(config?: Partial<CacheConfig>): ResponseCache;
104
+ /**
105
+ * Reset the global cache (for testing)
106
+ */
107
+ export declare function resetGlobalCache(): void;
108
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/api/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,4CAA4C;IAC5C,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAIlC,CAAA;AAED;;GAEG;AACH,qBAAa,aAAa,CAAC,CAAC,GAAG,OAAO;IACpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwC;IAC9D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAGxC,OAAO,CAAC,IAAI,CAAI;IAChB,OAAO,CAAC,MAAM,CAAI;gBAEN,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM;IAO7C;;OAEG;IACH,OAAO,CAAC,SAAS;IAIjB;;OAEG;IACH,OAAO,CAAC,aAAa;IAYrB;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IA2B1B;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;IAQ/B;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAUzB;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI5B;;OAEG;IACH,YAAY,IAAI,MAAM;IAWtB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAGrB;IAED;;OAEG;IACH,QAAQ,IAAI;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;QACd,QAAQ,EAAE,MAAM,CAAA;KACjB;IAWD;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;OAEG;IACH,IAAI,IAAI,MAAM,EAAE;IAIhB;;OAEG;IACG,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAUnE;AAOD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,aAAa,CAK7E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}