@molecule/app-status-dashboard-http 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/LICENSE +115 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/provider.d.ts +64 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +123 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP status dashboard provider for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Implements `StatusDashboardProvider` from `@molecule/app-status-dashboard` by
|
|
5
|
+
* fetching status data from the backend over plain HTTP, with automatic polling.
|
|
6
|
+
* Pairs with `@molecule/api-resource-status-page`, which serves the expected
|
|
7
|
+
* endpoints: `GET /status`, `GET /status/incidents`, and `GET /status/uptime`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { setProvider } from '@molecule/app-status-dashboard'
|
|
12
|
+
* import { createProvider } from '@molecule/app-status-dashboard-http'
|
|
13
|
+
*
|
|
14
|
+
* setProvider(createProvider({ baseUrl: '/api' }))
|
|
15
|
+
* // Now GET /api/status, /api/status/incidents?status=&limit=,
|
|
16
|
+
* // /api/status/uptime?serviceId= back the dashboard.
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* - **The backend must serve the three endpoints** (`/status`,
|
|
21
|
+
* `/status/incidents`, `/status/uptime`) relative to `baseUrl` — responses are
|
|
22
|
+
* `SystemStatus`, `{ incidents: StatusIncident[] }`, and
|
|
23
|
+
* `{ uptime: ServiceUptime[] }` respectively. `@molecule/api-resource-status-page`
|
|
24
|
+
* provides them.
|
|
25
|
+
* - **Error semantics differ per method**: `fetchStatus()` throws on non-2xx;
|
|
26
|
+
* `fetchIncidents()`/`fetchUptime()` return `[]` on ANY failure — an empty
|
|
27
|
+
* incidents list can mean "endpoint missing", not "all clear". Verify `/status`
|
|
28
|
+
* works first.
|
|
29
|
+
* - Polling defaults to every 30 s (`pollIntervalMs`), fetches immediately, and
|
|
30
|
+
* swallows per-tick errors (next tick retries). Keep the stop function returned by
|
|
31
|
+
* `startPolling()` and call it on unmount; `stopPolling()` cancels everything.
|
|
32
|
+
* - Per-call `config.apiBaseUrl`/`headers` override/merge over the constructor's
|
|
33
|
+
* `baseUrl`/`headers`.
|
|
34
|
+
*
|
|
35
|
+
* @module
|
|
36
|
+
*/
|
|
37
|
+
export * from './provider.js';
|
|
38
|
+
export * from './types.js';
|
|
39
|
+
/** Pre-instantiated provider singleton. */
|
|
40
|
+
export declare const provider: import("./provider.js").HttpStatusDashboardProvider;
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAI1B,2CAA2C;AAC3C,eAAO,MAAM,QAAQ,qDAAmB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP status dashboard provider for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Implements `StatusDashboardProvider` from `@molecule/app-status-dashboard` by
|
|
5
|
+
* fetching status data from the backend over plain HTTP, with automatic polling.
|
|
6
|
+
* Pairs with `@molecule/api-resource-status-page`, which serves the expected
|
|
7
|
+
* endpoints: `GET /status`, `GET /status/incidents`, and `GET /status/uptime`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { setProvider } from '@molecule/app-status-dashboard'
|
|
12
|
+
* import { createProvider } from '@molecule/app-status-dashboard-http'
|
|
13
|
+
*
|
|
14
|
+
* setProvider(createProvider({ baseUrl: '/api' }))
|
|
15
|
+
* // Now GET /api/status, /api/status/incidents?status=&limit=,
|
|
16
|
+
* // /api/status/uptime?serviceId= back the dashboard.
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* - **The backend must serve the three endpoints** (`/status`,
|
|
21
|
+
* `/status/incidents`, `/status/uptime`) relative to `baseUrl` — responses are
|
|
22
|
+
* `SystemStatus`, `{ incidents: StatusIncident[] }`, and
|
|
23
|
+
* `{ uptime: ServiceUptime[] }` respectively. `@molecule/api-resource-status-page`
|
|
24
|
+
* provides them.
|
|
25
|
+
* - **Error semantics differ per method**: `fetchStatus()` throws on non-2xx;
|
|
26
|
+
* `fetchIncidents()`/`fetchUptime()` return `[]` on ANY failure — an empty
|
|
27
|
+
* incidents list can mean "endpoint missing", not "all clear". Verify `/status`
|
|
28
|
+
* works first.
|
|
29
|
+
* - Polling defaults to every 30 s (`pollIntervalMs`), fetches immediately, and
|
|
30
|
+
* swallows per-tick errors (next tick retries). Keep the stop function returned by
|
|
31
|
+
* `startPolling()` and call it on unmount; `stopPolling()` cancels everything.
|
|
32
|
+
* - Per-call `config.apiBaseUrl`/`headers` override/merge over the constructor's
|
|
33
|
+
* `baseUrl`/`headers`.
|
|
34
|
+
*
|
|
35
|
+
* @module
|
|
36
|
+
*/
|
|
37
|
+
export * from './provider.js';
|
|
38
|
+
export * from './types.js';
|
|
39
|
+
import { createProvider } from './provider.js';
|
|
40
|
+
/** Pre-instantiated provider singleton. */
|
|
41
|
+
export const provider = createProvider();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP status dashboard provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Fetches status data from the backend API via standard HTTP requests
|
|
5
|
+
* and supports automatic polling for real-time updates.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { IncidentStatus, ServiceUptime, StatusDashboardConfig, StatusDashboardProvider, StatusIncident, SystemStatus } from '@molecule/app-status-dashboard';
|
|
10
|
+
import type { HttpStatusDashboardConfig } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* HTTP-based implementation of `StatusDashboardProvider`. Fetches system status,
|
|
13
|
+
* incidents, and uptime data from backend API endpoints via standard HTTP requests.
|
|
14
|
+
*/
|
|
15
|
+
export declare class HttpStatusDashboardProvider implements StatusDashboardProvider {
|
|
16
|
+
readonly name = "http";
|
|
17
|
+
private config;
|
|
18
|
+
private pollingTimers;
|
|
19
|
+
constructor(config?: HttpStatusDashboardConfig);
|
|
20
|
+
/**
|
|
21
|
+
* Fetches the current system status from the API.
|
|
22
|
+
* @param config - Status dashboard configuration including API base URL and headers.
|
|
23
|
+
* @returns The current system status including services and active incidents.
|
|
24
|
+
*/
|
|
25
|
+
fetchStatus(config: StatusDashboardConfig): Promise<SystemStatus>;
|
|
26
|
+
/**
|
|
27
|
+
* Fetches recent incidents from the API with optional filtering.
|
|
28
|
+
* @param config - Status dashboard configuration including API base URL and headers.
|
|
29
|
+
* @param options - Optional filters for incident status and result limit.
|
|
30
|
+
* @param options.status - Filter incidents by status.
|
|
31
|
+
* @param options.limit - Maximum number of incidents to return.
|
|
32
|
+
* @returns An array of status incidents, or an empty array if the request fails.
|
|
33
|
+
*/
|
|
34
|
+
fetchIncidents(config: StatusDashboardConfig, options?: {
|
|
35
|
+
status?: IncidentStatus;
|
|
36
|
+
limit?: number;
|
|
37
|
+
}): Promise<StatusIncident[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Fetches uptime data for all services or a specific service.
|
|
40
|
+
* @param config - Status dashboard configuration including API base URL and headers.
|
|
41
|
+
* @param serviceId - Optional service ID to filter uptime data.
|
|
42
|
+
* @returns An array of service uptime records, or an empty array if the request fails.
|
|
43
|
+
*/
|
|
44
|
+
fetchUptime(config: StatusDashboardConfig, serviceId?: string): Promise<ServiceUptime[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Starts polling for status updates at the configured interval.
|
|
47
|
+
* Fetches immediately and then at regular intervals.
|
|
48
|
+
* @param config - Status dashboard configuration including poll interval.
|
|
49
|
+
* @param onUpdate - Callback invoked with the latest system status on each successful poll.
|
|
50
|
+
* @returns A stop function that cancels this polling subscription.
|
|
51
|
+
*/
|
|
52
|
+
startPolling(config: StatusDashboardConfig, onUpdate: (status: SystemStatus) => void): () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Stops all active polling timers.
|
|
55
|
+
*/
|
|
56
|
+
stopPolling(): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates an `HttpStatusDashboardProvider` instance with optional configuration.
|
|
60
|
+
* @param config - HTTP-specific status dashboard configuration (base URL, headers).
|
|
61
|
+
* @returns An `HttpStatusDashboardProvider` that communicates with the backend via HTTP.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createProvider(config?: HttpStatusDashboardConfig): HttpStatusDashboardProvider;
|
|
64
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,uBAAuB,EACvB,cAAc,EACd,YAAY,EACb,MAAM,gCAAgC,CAAA;AAEvC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAE3D;;;GAGG;AACH,qBAAa,2BAA4B,YAAW,uBAAuB;IACzE,QAAQ,CAAC,IAAI,UAAS;IACtB,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,aAAa,CAAiD;gBAE1D,MAAM,GAAE,yBAA8B;IAIlD;;;;OAIG;IACG,WAAW,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,YAAY,CAAC;IAiBvE;;;;;;;OAOG;IACG,cAAc,CAClB,MAAM,EAAE,qBAAqB,EAC7B,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,cAAc,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GACpD,OAAO,CAAC,cAAc,EAAE,CAAC;IAY5B;;;;;OAKG;IACG,WAAW,CAAC,MAAM,EAAE,qBAAqB,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAW9F;;;;;;OAMG;IACH,YAAY,CACV,MAAM,EAAE,qBAAqB,EAC7B,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GACvC,MAAM,IAAI;IAuBb;;OAEG;IACH,WAAW,IAAI,IAAI;CAMpB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,yBAAyB,GAAG,2BAA2B,CAE9F"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP status dashboard provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Fetches status data from the backend API via standard HTTP requests
|
|
5
|
+
* and supports automatic polling for real-time updates.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { t } from '@molecule/app-i18n';
|
|
10
|
+
/**
|
|
11
|
+
* HTTP-based implementation of `StatusDashboardProvider`. Fetches system status,
|
|
12
|
+
* incidents, and uptime data from backend API endpoints via standard HTTP requests.
|
|
13
|
+
*/
|
|
14
|
+
export class HttpStatusDashboardProvider {
|
|
15
|
+
name = 'http';
|
|
16
|
+
config;
|
|
17
|
+
pollingTimers = new Set();
|
|
18
|
+
constructor(config = {}) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Fetches the current system status from the API.
|
|
23
|
+
* @param config - Status dashboard configuration including API base URL and headers.
|
|
24
|
+
* @returns The current system status including services and active incidents.
|
|
25
|
+
*/
|
|
26
|
+
async fetchStatus(config) {
|
|
27
|
+
const url = `${config.apiBaseUrl ?? this.config.baseUrl ?? ''}/status`;
|
|
28
|
+
const response = await fetch(url, { headers: { ...this.config.headers, ...config.headers } });
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
throw new Error(t('statusDashboard.error.fetchFailed', { status: response.status }, {
|
|
31
|
+
defaultValue: 'Failed to fetch status: HTTP {{status}}',
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
return (await response.json());
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetches recent incidents from the API with optional filtering.
|
|
38
|
+
* @param config - Status dashboard configuration including API base URL and headers.
|
|
39
|
+
* @param options - Optional filters for incident status and result limit.
|
|
40
|
+
* @param options.status - Filter incidents by status.
|
|
41
|
+
* @param options.limit - Maximum number of incidents to return.
|
|
42
|
+
* @returns An array of status incidents, or an empty array if the request fails.
|
|
43
|
+
*/
|
|
44
|
+
async fetchIncidents(config, options) {
|
|
45
|
+
const params = new URLSearchParams();
|
|
46
|
+
if (options?.status)
|
|
47
|
+
params.set('status', options.status);
|
|
48
|
+
if (options?.limit)
|
|
49
|
+
params.set('limit', String(options.limit));
|
|
50
|
+
const qs = params.toString();
|
|
51
|
+
const url = `${config.apiBaseUrl ?? this.config.baseUrl ?? ''}/status/incidents${qs ? `?${qs}` : ''}`;
|
|
52
|
+
const response = await fetch(url, { headers: { ...this.config.headers, ...config.headers } });
|
|
53
|
+
if (!response.ok)
|
|
54
|
+
return [];
|
|
55
|
+
const data = (await response.json());
|
|
56
|
+
return data.incidents ?? [];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fetches uptime data for all services or a specific service.
|
|
60
|
+
* @param config - Status dashboard configuration including API base URL and headers.
|
|
61
|
+
* @param serviceId - Optional service ID to filter uptime data.
|
|
62
|
+
* @returns An array of service uptime records, or an empty array if the request fails.
|
|
63
|
+
*/
|
|
64
|
+
async fetchUptime(config, serviceId) {
|
|
65
|
+
const params = new URLSearchParams();
|
|
66
|
+
if (serviceId)
|
|
67
|
+
params.set('serviceId', serviceId);
|
|
68
|
+
const qs = params.toString();
|
|
69
|
+
const url = `${config.apiBaseUrl ?? this.config.baseUrl ?? ''}/status/uptime${qs ? `?${qs}` : ''}`;
|
|
70
|
+
const response = await fetch(url, { headers: { ...this.config.headers, ...config.headers } });
|
|
71
|
+
if (!response.ok)
|
|
72
|
+
return [];
|
|
73
|
+
const data = (await response.json());
|
|
74
|
+
return data.uptime ?? [];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Starts polling for status updates at the configured interval.
|
|
78
|
+
* Fetches immediately and then at regular intervals.
|
|
79
|
+
* @param config - Status dashboard configuration including poll interval.
|
|
80
|
+
* @param onUpdate - Callback invoked with the latest system status on each successful poll.
|
|
81
|
+
* @returns A stop function that cancels this polling subscription.
|
|
82
|
+
*/
|
|
83
|
+
startPolling(config, onUpdate) {
|
|
84
|
+
const intervalMs = config.pollIntervalMs ?? 30000;
|
|
85
|
+
const timer = setInterval(async () => {
|
|
86
|
+
try {
|
|
87
|
+
const status = await this.fetchStatus(config);
|
|
88
|
+
onUpdate(status);
|
|
89
|
+
}
|
|
90
|
+
catch (_error) {
|
|
91
|
+
// Best-effort poll — network blips are transient; the next interval will retry.
|
|
92
|
+
}
|
|
93
|
+
}, intervalMs);
|
|
94
|
+
this.pollingTimers.add(timer);
|
|
95
|
+
// Fetch immediately
|
|
96
|
+
this.fetchStatus(config)
|
|
97
|
+
.then(onUpdate)
|
|
98
|
+
.catch((_error) => {
|
|
99
|
+
// Best-effort immediate fetch — the polling interval will retry shortly.
|
|
100
|
+
});
|
|
101
|
+
return () => {
|
|
102
|
+
clearInterval(timer);
|
|
103
|
+
this.pollingTimers.delete(timer);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Stops all active polling timers.
|
|
108
|
+
*/
|
|
109
|
+
stopPolling() {
|
|
110
|
+
for (const timer of this.pollingTimers) {
|
|
111
|
+
clearInterval(timer);
|
|
112
|
+
}
|
|
113
|
+
this.pollingTimers.clear();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Creates an `HttpStatusDashboardProvider` instance with optional configuration.
|
|
118
|
+
* @param config - HTTP-specific status dashboard configuration (base URL, headers).
|
|
119
|
+
* @returns An `HttpStatusDashboardProvider` that communicates with the backend via HTTP.
|
|
120
|
+
*/
|
|
121
|
+
export function createProvider(config) {
|
|
122
|
+
return new HttpStatusDashboardProvider(config);
|
|
123
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP status dashboard provider configuration.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for http status dashboard provider.
|
|
8
|
+
*/
|
|
9
|
+
export interface HttpStatusDashboardConfig {
|
|
10
|
+
/** Base URL for API requests. Defaults to '' (same origin). */
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
/** Custom headers to include in requests. */
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC"}
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-status-dashboard-http",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "HTTP status dashboard provider implementation",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"molecule",
|
|
24
|
+
"status",
|
|
25
|
+
"dashboard",
|
|
26
|
+
"http"
|
|
27
|
+
],
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@molecule/app-status-dashboard": "1.0.0",
|
|
31
|
+
"@molecule/app-i18n": "1.0.0",
|
|
32
|
+
"@types/node": "26.1.2",
|
|
33
|
+
"typescript": "6.0.3",
|
|
34
|
+
"vitest": "4.1.10"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@molecule/app-status-dashboard": "^1.0.0",
|
|
38
|
+
"@molecule/app-i18n": "^1.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@molecule/app-status-dashboard": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
48
|
+
"directory": "packages/app/bonds/status-dashboard/http"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/app/bonds/status-dashboard/http",
|
|
51
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
}
|
|
55
|
+
}
|