signalk-maintenance-tracker 1.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.
- package/CHANGELOG.md +46 -0
- package/LICENSE +201 -0
- package/README.md +75 -0
- package/dist/api/router.js +193 -0
- package/dist/api/router.js.map +1 -0
- package/dist/auth.js +22 -0
- package/dist/auth.js.map +1 -0
- package/dist/config.js +50 -0
- package/dist/config.js.map +1 -0
- package/dist/db/database.js +47 -0
- package/dist/db/database.js.map +1 -0
- package/dist/db/logs.repo.js +91 -0
- package/dist/db/logs.repo.js.map +1 -0
- package/dist/db/migrations.js +57 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/db/tags.repo.js +78 -0
- package/dist/db/tags.repo.js.map +1 -0
- package/dist/db/tasks.repo.js +78 -0
- package/dist/db/tasks.repo.js.map +1 -0
- package/dist/domain/slug.js +27 -0
- package/dist/domain/slug.js.map +1 -0
- package/dist/domain/status.js +110 -0
- package/dist/domain/status.js.map +1 -0
- package/dist/index.js +130 -0
- package/dist/index.js.map +1 -0
- package/dist/service.js +370 -0
- package/dist/service.js.map +1 -0
- package/dist/signalk/notifications.js +115 -0
- package/dist/signalk/notifications.js.map +1 -0
- package/dist/signalk/runtime.js +103 -0
- package/dist/signalk/runtime.js.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/docs/screenshots/completed.png +0 -0
- package/docs/screenshots/dark-mode.png +0 -0
- package/docs/screenshots/edit-task.png +0 -0
- package/docs/screenshots/homepage.png +0 -0
- package/docs/screenshots/main-log.png +0 -0
- package/docs/screenshots/task-detail.png +0 -0
- package/package.json +82 -0
- package/public/app/api/client.js +75 -0
- package/public/app/api/hooks.js +159 -0
- package/public/app/api/resource.js +156 -0
- package/public/app/api/signalkPaths.js +66 -0
- package/public/app/app.js +71 -0
- package/public/app/auth/auth.js +158 -0
- package/public/app/components/AuthControl.js +22 -0
- package/public/app/components/ConfirmModal.js +55 -0
- package/public/app/components/LogEntryModal.js +150 -0
- package/public/app/components/LoginModal.js +86 -0
- package/public/app/components/MarkdownView.js +17 -0
- package/public/app/components/Modal.js +89 -0
- package/public/app/components/Pagination.js +35 -0
- package/public/app/components/PathPicker.js +66 -0
- package/public/app/components/ProgressBar.js +26 -0
- package/public/app/components/StatusBadge.js +9 -0
- package/public/app/components/Table.js +99 -0
- package/public/app/components/TagInput.js +93 -0
- package/public/app/components/TaskFormModal.js +310 -0
- package/public/app/components/ThemeToggle.js +17 -0
- package/public/app/components/Toaster.js +24 -0
- package/public/app/lib/format.js +90 -0
- package/public/app/lib/html.js +6 -0
- package/public/app/lib/router.js +105 -0
- package/public/app/lib/sanitize.js +64 -0
- package/public/app/lib/slug.js +16 -0
- package/public/app/lib/theme.js +52 -0
- package/public/app/lib/toasts.js +33 -0
- package/public/app/lib/useListParams.js +28 -0
- package/public/app/main.js +20 -0
- package/public/app/pages/MasterLogPage.js +279 -0
- package/public/app/pages/TaskDetailPage.js +294 -0
- package/public/app/pages/TaskListPage.js +279 -0
- package/public/app/types.js +90 -0
- package/public/icons/apple-touch-icon.png +0 -0
- package/public/icons/favicon-16.png +0 -0
- package/public/icons/favicon-32.png +0 -0
- package/public/icons/favicon.ico +0 -0
- package/public/icons/icon-192.png +0 -0
- package/public/icons/icon-512.png +0 -0
- package/public/index.html +82 -0
- package/public/manifest.webmanifest +37 -0
- package/public/styles/main.css +787 -0
- package/public/styles/tokens.css +55 -0
- package/public/vendor/VERSIONS.json +9 -0
- package/public/vendor/bootstrap-icons/bootstrap-icons.css +2106 -0
- package/public/vendor/bootstrap-icons/fonts/bootstrap-icons.woff +0 -0
- package/public/vendor/bootstrap-icons/fonts/bootstrap-icons.woff2 +0 -0
- package/public/vendor/dayjs/constant.js +25 -0
- package/public/vendor/dayjs/index.d.ts +1 -0
- package/public/vendor/dayjs/index.js +541 -0
- package/public/vendor/dayjs/locale/en.js +12 -0
- package/public/vendor/dayjs/utils.js +58 -0
- package/public/vendor/htm.d.ts +1 -0
- package/public/vendor/htm.js +1 -0
- package/public/vendor/preact-hooks.d.ts +1 -0
- package/public/vendor/preact-hooks.js +2 -0
- package/public/vendor/preact.d.ts +1 -0
- package/public/vendor/preact.js +2 -0
- package/public/vendor/signals-core.d.ts +1 -0
- package/public/vendor/signals-core.js +1 -0
- package/public/vendor/signals.d.ts +1 -0
- package/public/vendor/signals.js +1 -0
- package/public/vendor/snarkdown.d.ts +1 -0
- package/public/vendor/snarkdown.js +2 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# v1.0.0
|
|
2
|
+
|
|
3
|
+
The first release of Maintenance Tracker! 🎉
|
|
4
|
+
|
|
5
|
+
This is a SignalK server plugin that keeps track of recurring boat
|
|
6
|
+
maintenance — oil changes, winch service, watermaker filters, zinc swaps,
|
|
7
|
+
and anything else that comes due either by engine hours, by the calendar, or
|
|
8
|
+
both. Install it, add your tasks, and let your boat tell you what needs doing.
|
|
9
|
+
|
|
10
|
+
## Highlights
|
|
11
|
+
|
|
12
|
+
- **Runtime and calendar intervals.** Set a task to come due after so many
|
|
13
|
+
runtime hours (read live from a SignalK path like `propulsion.port.runTime`),
|
|
14
|
+
after a stretch of calendar time (days/weeks/months/years), or both — whichever arrives first wins. Tasks with no interval at all work as plain informational records.
|
|
15
|
+
- **At-a-glance status.** Every task is `overdue`, `due soon`, `ok`, or
|
|
16
|
+
`unknown`, and the task list sorts the most urgent work to the top so you
|
|
17
|
+
always see what matters first.
|
|
18
|
+
- **A real maintenance log.** Mark a task complete and it's recorded with the
|
|
19
|
+
date, who did it, and free-form markdown notes. Browse the history for a
|
|
20
|
+
single task or the master log across your whole boat.
|
|
21
|
+
- **Notifications that show up everywhere.** Overdue and due-soon status is
|
|
22
|
+
published to `notifications.maintenance.{slug}` as standard SignalK
|
|
23
|
+
`alarm`/`warn`/`normal` notifications, so your existing dashboards, apps,
|
|
24
|
+
and alarm consumers pick them up with no extra setup.
|
|
25
|
+
- **A modern webapp — that runs on old chartplotters.** A searchable,
|
|
26
|
+
filterable task table with tag chips, progress bars, and a light/dark theme,
|
|
27
|
+
served straight from the SignalK Webapps menu with live polling. It's a
|
|
28
|
+
buildless Preact app, so it even runs on browsers as old as Chromium 69
|
|
29
|
+
(Navico/B&G MFDs).
|
|
30
|
+
- **Logs in against SignalK itself.** The webapp authenticates through the
|
|
31
|
+
server's own `/signalk/v1/auth/*` endpoints (with an optional "remember me"),
|
|
32
|
+
and the server enforces API access — the plugin adds no separate accounts or
|
|
33
|
+
passwords of its own.
|
|
34
|
+
|
|
35
|
+
## Under the hood
|
|
36
|
+
|
|
37
|
+
- **Zero native dependencies.** Storage uses Node's built-in `node:sqlite`, so
|
|
38
|
+
there's nothing to compile — perfect for a Raspberry Pi. Requires
|
|
39
|
+
**Node ≥ 22.5** (SignalK on Node 24 recommended).
|
|
40
|
+
- **REST API** mounted at `/plugins/signalk-maintenance-tracker/api` for tasks,
|
|
41
|
+
logs, and tags — access controlled by the SignalK server.
|
|
42
|
+
- **Configurable notification timing.** Master on/off switch, notification
|
|
43
|
+
method, and how far ahead ("due soon" lead time) to warn for both runtime
|
|
44
|
+
hours and calendar days — all in the plugin config.
|
|
45
|
+
|
|
46
|
+
Thanks for trying it out — feedback and issues are very welcome.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# signalk-maintenance-tracker
|
|
2
|
+
|
|
3
|
+
A [SignalK](https://signalk.org) server plugin that tracks recurring boat
|
|
4
|
+
maintenance — oil changes, winch service, watermaker filters, and anything
|
|
5
|
+
else that comes due by engine hours, by calendar time, or both.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Tasks with two interval dimensions** — runtime hours (read live from a
|
|
10
|
+
SignalK path such as `propulsion.port.runTime`) and/or calendar time
|
|
11
|
+
(days/weeks/months/years). Tasks with neither interval work as
|
|
12
|
+
informational records.
|
|
13
|
+
- **Status tracking** — each task is `overdue`, `due soon`, `ok`, or
|
|
14
|
+
`unknown`; the task list sorts most-urgent first.
|
|
15
|
+
- **Maintenance log** — per-task history plus a master log across all tasks,
|
|
16
|
+
with markdown notes and who logged the work.
|
|
17
|
+
- **SignalK notifications** — overdue/due-soon status is published to
|
|
18
|
+
`notifications.maintenance.{slug}` (`alarm`/`warn`/`normal`), so it shows up
|
|
19
|
+
in any SignalK notification consumer.
|
|
20
|
+
- **Modern webapp** — buildless Preact SPA served from the SignalK webapps
|
|
21
|
+
menu: searchable/filterable task table, tag chips, progress bars, light/dark
|
|
22
|
+
theme, live polling. Runs on browsers as old as Chromium 69 (Navico/B&G
|
|
23
|
+
MFDs) — no bundler, no transpile step; the files in `public/` are exactly
|
|
24
|
+
what the browser executes.
|
|
25
|
+
- **SignalK-native auth** — the webapp logs in against the server's own
|
|
26
|
+
`/signalk/v1/auth/*` endpoints; the server enforces access to the API. The
|
|
27
|
+
plugin adds no auth of its own.
|
|
28
|
+
- **Zero native dependencies** — SQLite via Node's built-in `node:sqlite`,
|
|
29
|
+
ideal on a Raspberry Pi. Requires **Node ≥ 22.5** (SignalK on Node 24
|
|
30
|
+
recommended).
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
From the SignalK Appstore (once published), or manually:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
cd ~/.signalk
|
|
38
|
+
npm install signalk-maintenance-tracker
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Enable the plugin in the SignalK admin UI (Server → Plugin Config →
|
|
42
|
+
Maintenance Tracker). The webapp appears under Webapps as **Maintenance
|
|
43
|
+
Tracker**; data is stored in the plugin's data directory as `maintenance.db`.
|
|
44
|
+
|
|
45
|
+
### Plugin options
|
|
46
|
+
|
|
47
|
+
| option | default | purpose |
|
|
48
|
+
| ------------------------ | ------------ | -------------------------------------------- |
|
|
49
|
+
| `enableNotifications` | `true` | master switch for notification publishing |
|
|
50
|
+
| `notificationMethods` | `["visual"]` | SignalK notification `method` |
|
|
51
|
+
| `runtimeNotifyLeadHours` | `10` | runtime hours before due to raise "due soon" |
|
|
52
|
+
| `timeNotifyLeadDays` | `7` | days before due to raise "due soon" |
|
|
53
|
+
| `recomputeIntervalMs` | `60000` | status recompute tick in ms |
|
|
54
|
+
|
|
55
|
+
## REST API
|
|
56
|
+
|
|
57
|
+
Mounted at `/plugins/signalk-maintenance-tracker/api` (access controlled by
|
|
58
|
+
the SignalK server — currently admin):
|
|
59
|
+
|
|
60
|
+
- `GET/POST /tasks`, `GET/PUT/DELETE /tasks/:slug`
|
|
61
|
+
- `GET/POST /tasks/:slug/logs` (POST = mark complete)
|
|
62
|
+
- `GET /logs`, `PUT/DELETE /logs/:id`
|
|
63
|
+
- `GET /tags`
|
|
64
|
+
- `GET /health`
|
|
65
|
+
|
|
66
|
+
See [docs/specification.md](docs/specification.md) for the full spec.
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
Setup, the buildless webapp workflow, CI, and the release process are
|
|
71
|
+
documented in [DEVELOPMENT.md](DEVELOPMENT.md).
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mountApi = mountApi;
|
|
4
|
+
const auth_1 = require("../auth");
|
|
5
|
+
const service_1 = require("../service");
|
|
6
|
+
/**
|
|
7
|
+
* Mounts the plugin REST API (§8) on the router SignalK provides via
|
|
8
|
+
* registerWithRouter. The router is mounted at /plugins/{pluginId}, so routes
|
|
9
|
+
* here live under /api/*.
|
|
10
|
+
*
|
|
11
|
+
* No authorization here by design (§9): SignalK gates access to these routes
|
|
12
|
+
* before requests reach us.
|
|
13
|
+
*/
|
|
14
|
+
function mountApi(router, getServices) {
|
|
15
|
+
router.use(jsonBody);
|
|
16
|
+
const withServices = (fn) => (req, res) => {
|
|
17
|
+
const services = getServices();
|
|
18
|
+
if (!services) {
|
|
19
|
+
res.status(503).json({
|
|
20
|
+
error: { code: 'not_started', message: 'Plugin is not started' },
|
|
21
|
+
});
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
fn(services, req, res);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
if (err instanceof service_1.ApiError) {
|
|
29
|
+
res
|
|
30
|
+
.status(err.status)
|
|
31
|
+
.json({ error: { code: err.code, message: err.message } });
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
res.status(500).json({
|
|
35
|
+
error: {
|
|
36
|
+
code: 'internal',
|
|
37
|
+
message: err instanceof Error ? err.message : String(err),
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
// ---- tasks (§8.1) ----
|
|
44
|
+
router.get('/api/tasks', withServices((s, req, res) => {
|
|
45
|
+
res.json(s.service.listTasks(parseTaskListQuery(req)));
|
|
46
|
+
}));
|
|
47
|
+
router.post('/api/tasks', withServices((s, req, res) => {
|
|
48
|
+
res.status(201).json(s.service.createTask(req.body ?? {}));
|
|
49
|
+
}));
|
|
50
|
+
router.get('/api/tasks/:slug', withServices((s, req, res) => {
|
|
51
|
+
res.json(s.service.getTask(req.params.slug));
|
|
52
|
+
}));
|
|
53
|
+
router.put('/api/tasks/:slug', withServices((s, req, res) => {
|
|
54
|
+
res.json(s.service.updateTask(req.params.slug, req.body ?? {}));
|
|
55
|
+
}));
|
|
56
|
+
router.delete('/api/tasks/:slug', withServices((s, req, res) => {
|
|
57
|
+
s.service.deleteTask(req.params.slug);
|
|
58
|
+
res.status(204).end();
|
|
59
|
+
}));
|
|
60
|
+
// ---- logs (§8.2) ----
|
|
61
|
+
router.get('/api/tasks/:slug/logs', withServices((s, req, res) => {
|
|
62
|
+
res.json({ data: s.service.listTaskLogs(req.params.slug) });
|
|
63
|
+
}));
|
|
64
|
+
router.post('/api/tasks/:slug/logs', withServices((s, req, res) => {
|
|
65
|
+
// logged_by comes from the SignalK principal, never the body (§9.1)
|
|
66
|
+
const entry = s.service.addLog(req.params.slug, req.body ?? {}, (0, auth_1.getRequestUser)(req));
|
|
67
|
+
res.status(201).json(entry);
|
|
68
|
+
}));
|
|
69
|
+
router.get('/api/logs', withServices((s, req, res) => {
|
|
70
|
+
const { page, pageSize } = parsePaging(req);
|
|
71
|
+
const sort = pickEnum(req.query.sort, [
|
|
72
|
+
'maintenance_date',
|
|
73
|
+
'task',
|
|
74
|
+
'runtime_hours',
|
|
75
|
+
]);
|
|
76
|
+
const order = pickEnum(req.query.order, ['asc', 'desc']);
|
|
77
|
+
res.json(s.service.listMasterLog({
|
|
78
|
+
search: str(req.query.search),
|
|
79
|
+
sort,
|
|
80
|
+
order,
|
|
81
|
+
page,
|
|
82
|
+
pageSize,
|
|
83
|
+
}));
|
|
84
|
+
}));
|
|
85
|
+
router.put('/api/logs/:id', withServices((s, req, res) => {
|
|
86
|
+
res.json(s.service.updateLog(intParam(req.params.id), req.body ?? {}));
|
|
87
|
+
}));
|
|
88
|
+
router.delete('/api/logs/:id', withServices((s, req, res) => {
|
|
89
|
+
s.service.deleteLog(intParam(req.params.id));
|
|
90
|
+
res.status(204).end();
|
|
91
|
+
}));
|
|
92
|
+
// ---- tags (§8.3) ----
|
|
93
|
+
router.get('/api/tags', withServices((s, _req, res) => {
|
|
94
|
+
res.json({ data: s.service.listTags() });
|
|
95
|
+
}));
|
|
96
|
+
// ---- health (§8.5) ----
|
|
97
|
+
router.get('/api/health', withServices((s, _req, res) => {
|
|
98
|
+
res.json({
|
|
99
|
+
...s.service.health(),
|
|
100
|
+
subscribedPaths: s.runtime.subscribedPaths,
|
|
101
|
+
lastRuntimeUpdate: s.runtime.lastUpdateAt,
|
|
102
|
+
version: s.version,
|
|
103
|
+
});
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Minimal JSON body reader. SignalK versions differ on whether plugin routers
|
|
108
|
+
* get body-parsing middleware, so parse only if req.body is still unset.
|
|
109
|
+
*/
|
|
110
|
+
function jsonBody(req, res, next) {
|
|
111
|
+
if (req.body !== undefined ||
|
|
112
|
+
req.method === 'GET' ||
|
|
113
|
+
req.method === 'DELETE') {
|
|
114
|
+
next();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let data = '';
|
|
118
|
+
req.setEncoding('utf8');
|
|
119
|
+
req.on('data', (chunk) => {
|
|
120
|
+
data += chunk;
|
|
121
|
+
});
|
|
122
|
+
req.on('end', () => {
|
|
123
|
+
if (!data) {
|
|
124
|
+
req.body = {};
|
|
125
|
+
next();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
req.body = JSON.parse(data);
|
|
130
|
+
next();
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
res.status(400).json({
|
|
134
|
+
error: {
|
|
135
|
+
code: 'invalid_json',
|
|
136
|
+
message: 'Request body is not valid JSON',
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function parseTaskListQuery(req) {
|
|
143
|
+
const { page, pageSize } = parsePaging(req);
|
|
144
|
+
return {
|
|
145
|
+
search: str(req.query.search),
|
|
146
|
+
tags: csv(req.query.tags),
|
|
147
|
+
status: csv(req.query.status)?.filter((s) => ['overdue', 'due_soon', 'ok', 'unknown'].includes(s)),
|
|
148
|
+
sort: pickEnum(req.query.sort, [
|
|
149
|
+
'name',
|
|
150
|
+
'remaining_runtime',
|
|
151
|
+
'remaining_time',
|
|
152
|
+
'status',
|
|
153
|
+
]),
|
|
154
|
+
order: pickEnum(req.query.order, ['asc', 'desc']),
|
|
155
|
+
page,
|
|
156
|
+
pageSize,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function parsePaging(req) {
|
|
160
|
+
return { page: int(req.query.page), pageSize: int(req.query.pageSize) };
|
|
161
|
+
}
|
|
162
|
+
function str(v) {
|
|
163
|
+
return typeof v === 'string' && v !== '' ? v : undefined;
|
|
164
|
+
}
|
|
165
|
+
function csv(v) {
|
|
166
|
+
const s = str(v);
|
|
167
|
+
return s
|
|
168
|
+
? s
|
|
169
|
+
.split(',')
|
|
170
|
+
.map((x) => x.trim())
|
|
171
|
+
.filter(Boolean)
|
|
172
|
+
: undefined;
|
|
173
|
+
}
|
|
174
|
+
function int(v) {
|
|
175
|
+
const s = str(v);
|
|
176
|
+
if (s === undefined)
|
|
177
|
+
return undefined;
|
|
178
|
+
const n = Number.parseInt(s, 10);
|
|
179
|
+
return Number.isFinite(n) ? n : undefined;
|
|
180
|
+
}
|
|
181
|
+
function intParam(v) {
|
|
182
|
+
const n = Number.parseInt(v, 10);
|
|
183
|
+
if (!Number.isFinite(n))
|
|
184
|
+
throw new service_1.ApiError(400, 'invalid_id', 'id must be an integer');
|
|
185
|
+
return n;
|
|
186
|
+
}
|
|
187
|
+
function pickEnum(v, allowed) {
|
|
188
|
+
const s = str(v);
|
|
189
|
+
return s !== undefined && allowed.includes(s)
|
|
190
|
+
? s
|
|
191
|
+
: undefined;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/api/router.ts"],"names":[],"mappings":";;AAsBA,4BAyJC;AA9KD,kCAAyC;AACzC,wCAAyE;AAYzE;;;;;;;GAOG;AACH,SAAgB,QAA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AAS,GAAG,CAAC,CAAU;IACrB,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACjB,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACtC,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5C,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS;IACzB,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QACrB,MAAM,IAAI,kBAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,uBAAuB,CAAC,CAAC;IACjE,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,QAAQ,CACf,CAAU,EACV,OAAqB;IAErB,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,KAAK,SAAS,IAAK,OAA6B,CAAC,QAAQ,CAAC,CAAC,CAAC;QAClE,CAAC,CAAE,CAAO;QACV,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRequestUser = getRequestUser;
|
|
4
|
+
/**
|
|
5
|
+
* Read the SignalK request principal's identifier, used only to stamp
|
|
6
|
+
* log_entries.logged_by (§9.1). The plugin does no authorization of its own —
|
|
7
|
+
* SignalK enforces access before requests reach our handlers.
|
|
8
|
+
*
|
|
9
|
+
* The exact field varies across signalk-server versions, so every known shape
|
|
10
|
+
* is probed here and nowhere else.
|
|
11
|
+
*/
|
|
12
|
+
function getRequestUser(req) {
|
|
13
|
+
const r = req;
|
|
14
|
+
return (r?.skPrincipal?.identifier ??
|
|
15
|
+
r?.skUser?.id ??
|
|
16
|
+
r?.skUser?.username ??
|
|
17
|
+
r?.user?.id ??
|
|
18
|
+
r?.user?.username ??
|
|
19
|
+
(typeof r?.user === 'string' ? r.user : null) ??
|
|
20
|
+
null);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";;AAQA,wCAWC;AAnBD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,GAAY;IACzC,MAAM,CAAC,GAAG,GAA0B,CAAC;IACrC,OAAO,CACL,CAAC,EAAE,WAAW,EAAE,UAAU;QAC1B,CAAC,EAAE,MAAM,EAAE,EAAE;QACb,CAAC,EAAE,MAAM,EAAE,QAAQ;QACnB,CAAC,EAAE,IAAI,EAAE,EAAE;QACX,CAAC,EAAE,IAAI,EAAE,QAAQ;QACjB,CAAC,OAAO,CAAC,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAC7C,IAAI,CACL,CAAC;AACJ,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = exports.DEFAULT_OPTIONS = void 0;
|
|
4
|
+
exports.withDefaults = withDefaults;
|
|
5
|
+
exports.DEFAULT_OPTIONS = {
|
|
6
|
+
enableNotifications: true,
|
|
7
|
+
notificationMethods: ['visual'],
|
|
8
|
+
runtimeNotifyLeadHours: 10,
|
|
9
|
+
timeNotifyLeadDays: 7,
|
|
10
|
+
recomputeIntervalMs: 60000,
|
|
11
|
+
};
|
|
12
|
+
function withDefaults(options) {
|
|
13
|
+
return { ...exports.DEFAULT_OPTIONS, ...(options ?? {}) };
|
|
14
|
+
}
|
|
15
|
+
exports.schema = {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
enableNotifications: {
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
title: 'Enable notifications',
|
|
21
|
+
description: 'Publish overdue/upcoming status to notifications.maintenance.*',
|
|
22
|
+
default: exports.DEFAULT_OPTIONS.enableNotifications,
|
|
23
|
+
},
|
|
24
|
+
notificationMethods: {
|
|
25
|
+
type: 'array',
|
|
26
|
+
title: 'Notification methods',
|
|
27
|
+
items: { type: 'string', enum: ['visual', 'sound'] },
|
|
28
|
+
default: exports.DEFAULT_OPTIONS.notificationMethods,
|
|
29
|
+
},
|
|
30
|
+
runtimeNotifyLeadHours: {
|
|
31
|
+
type: 'number',
|
|
32
|
+
title: 'Runtime lead window (hours)',
|
|
33
|
+
description: 'Tasks within this many runtime hours of due are "due soon"',
|
|
34
|
+
default: exports.DEFAULT_OPTIONS.runtimeNotifyLeadHours,
|
|
35
|
+
},
|
|
36
|
+
timeNotifyLeadDays: {
|
|
37
|
+
type: 'number',
|
|
38
|
+
title: 'Time lead window (days)',
|
|
39
|
+
description: 'Tasks within this many days of due are "due soon"',
|
|
40
|
+
default: exports.DEFAULT_OPTIONS.timeNotifyLeadDays,
|
|
41
|
+
},
|
|
42
|
+
recomputeIntervalMs: {
|
|
43
|
+
type: 'number',
|
|
44
|
+
title: 'Recompute interval (ms)',
|
|
45
|
+
description: 'How often to re-evaluate task status and refresh notifications',
|
|
46
|
+
default: exports.DEFAULT_OPTIONS.recomputeIntervalMs,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAgBA,oCAEC;AAVY,QAAA,eAAe,GA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perty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openDatabase = openDatabase;
|
|
4
|
+
exports.migrate = migrate;
|
|
5
|
+
exports.schemaVersion = schemaVersion;
|
|
6
|
+
const node_sqlite_1 = require("node:sqlite");
|
|
7
|
+
const migrations_1 = require("./migrations");
|
|
8
|
+
function openDatabase(dbPath) {
|
|
9
|
+
const db = new node_sqlite_1.DatabaseSync(dbPath);
|
|
10
|
+
db.exec('PRAGMA journal_mode = WAL');
|
|
11
|
+
// DatabaseSync enables FK constraints by default; keep it explicit — the
|
|
12
|
+
// cascade rules on task_tags/log_entries depend on it.
|
|
13
|
+
db.exec('PRAGMA foreign_keys = ON');
|
|
14
|
+
migrate(db);
|
|
15
|
+
return db;
|
|
16
|
+
}
|
|
17
|
+
function migrate(db) {
|
|
18
|
+
db.exec(`CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT NOT NULL)`);
|
|
19
|
+
const row = db
|
|
20
|
+
.prepare(`SELECT value FROM meta WHERE key = 'schema_version'`)
|
|
21
|
+
.get();
|
|
22
|
+
let version = row ? Number(row.value) : 0;
|
|
23
|
+
for (const m of migrations_1.migrations) {
|
|
24
|
+
if (m.version <= version)
|
|
25
|
+
continue;
|
|
26
|
+
// node:sqlite has no db.transaction() helper — manage explicitly (§5.8)
|
|
27
|
+
db.exec('BEGIN');
|
|
28
|
+
try {
|
|
29
|
+
m.up(db);
|
|
30
|
+
db.prepare(`INSERT INTO meta (key, value) VALUES ('schema_version', ?)
|
|
31
|
+
ON CONFLICT(key) DO UPDATE SET value = excluded.value`).run(String(m.version));
|
|
32
|
+
db.exec('COMMIT');
|
|
33
|
+
version = m.version;
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
db.exec('ROLLBACK');
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function schemaVersion(db) {
|
|
42
|
+
const row = db
|
|
43
|
+
.prepare(`SELECT value FROM meta WHERE key = 'schema_version'`)
|
|
44
|
+
.get();
|
|
45
|
+
return row ? Number(row.value) : 0;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/db/database.ts"],"names":[],"mappings":";;AAGA,oCAQC;AAED,0BA0BC;AAED,sCAKC;AA9CD,6CAA2C;AAC3C,6CAA0C;AAE1C,SAAgB,YAAY,CAAC,MAAc;IACzC,MAAM,EAAE,GAAG,IAAI,0BAAY,CAAC,MAAM,CAAC,CAAC;IACpC,EAAE,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IACrC,yEAAyE;IACzE,uDAAuD;IACvD,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,CAAC,CAAC;IACZ,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAgB,OAAO,CAAC,EAAgB;IACtC,EAAE,CAAC,IAAI,CACL,6EAA6E,CAC9E,CAAC;IACF,MAAM,GAAG,GAAG,EAAE;SACX,OAAO,CAAC,qDAAqD,CAAC;SAC9D,GAAG,EAAmC,CAAC;IAC1C,IAAI,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1C,KAAK,MAAM,CAAC,IAAI,uBAAU,EAAE,CAAC;QAC3B,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO;YAAE,SAAS;QACnC,wEAAwE;QACxE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjB,IAAI,CAAC;YACH,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YACT,EAAE,CAAC,OAAO,CACR;+DACuD,CACxD,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;YACzB,EAAE,CAAC,IAAI,CA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