sleep-not-allowed 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/README.md +284 -0
- package/dist/core/requester.d.ts +2 -0
- package/dist/core/requester.d.ts.map +1 -0
- package/dist/core/requester.js +19 -0
- package/dist/core/requester.js.map +1 -0
- package/dist/core/scheduler.d.ts +3 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +26 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +6 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +31 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# SLEEP-NOT-ALLOWED
|
|
2
|
+
|
|
3
|
+
Keep a server deployment active with periodic HTTP health-check requests to a URL.
|
|
4
|
+
|
|
5
|
+
## Contributors
|
|
6
|
+
|
|
7
|
+
<table>
|
|
8
|
+
<tr>
|
|
9
|
+
<td align="center">
|
|
10
|
+
<a href="https://www.manuelpiresluis.site">
|
|
11
|
+
<img src="https://www.manuelpiresluis.site/assets/foto-perfil-B3C4QR9r.jpg" width="120" height="120" alt="Manuel Pires Luís" style="border-radius: 50%; object-fit: cover;" />
|
|
12
|
+
<br />
|
|
13
|
+
<sub><b><a href="https://github.com/ManuelPiresLuis01/">Manuel Pires Luís</a></b></sub>
|
|
14
|
+
</a>
|
|
15
|
+
<br />
|
|
16
|
+
Software Engineer & QA
|
|
17
|
+
</td>
|
|
18
|
+
</tr>
|
|
19
|
+
</table>
|
|
20
|
+
|
|
21
|
+
## Why sleep-not-allowed?
|
|
22
|
+
|
|
23
|
+
Some hosting platforms suspend or scale down services that receive no traffic for a period of time. For example:
|
|
24
|
+
|
|
25
|
+
| Platform | Inactivity behavior |
|
|
26
|
+
| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
27
|
+
| [Render Free web service](https://render.com/docs/free#spinning-down-on-idle) | Spins down after 15 minutes without inbound traffic |
|
|
28
|
+
| [Koyeb Free Instance](https://www.koyeb.com/docs/run-and-scale/scale-to-zero#idle-period) | Scales to zero after 1 hour without traffic |
|
|
29
|
+
| [Railway Free](https://docs.railway.com/reference/pricing/plans) | No fixed inactivity timeout is listed in the current plan documentation; usage is subject to the plan's included credits and limits |
|
|
30
|
+
| [Heroku Eco Dyno](https://devcenter.heroku.com/articles/dyno-sleeping) | Sleeps after 30 minutes of inactivity; Eco is a paid dyno plan, not a free tier |
|
|
31
|
+
|
|
32
|
+
`sleep-not-allowed` periodically sends HTTP requests to your application so that it continues receiving traffic while the scheduler is running.
|
|
33
|
+
|
|
34
|
+
> **Note:** Platform policies, pricing, and free-tier limitations may change over time. Always check your hosting provider's current documentation. The values above were checked in September 2026.
|
|
35
|
+
|
|
36
|
+
The package does not host an application or provide a health-check endpoint. It calls the URL that you configure.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- Periodic HTTP `GET` requests to a configured URL
|
|
41
|
+
- An immediate request when the scheduler starts
|
|
42
|
+
- Configurable request interval
|
|
43
|
+
- Configurable request timeout
|
|
44
|
+
- Configurable retries for failed requests
|
|
45
|
+
- Console logging for startup, successful requests, and failed requests
|
|
46
|
+
- TypeScript types included in the published package
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install sleep-not-allowed
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The package currently documents npm installation only.
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { sleepNotAllowed } from "sleep-not-allowed";
|
|
60
|
+
|
|
61
|
+
sleepNotAllowed({
|
|
62
|
+
url: "https://your-app.example.com/health",
|
|
63
|
+
interval: 5 * 60 * 1000,
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Calling `sleepNotAllowed` starts the scheduler. It sends the first request immediately and then repeats it every five minutes.
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
### Import the package
|
|
72
|
+
|
|
73
|
+
The package is published as an ES module and exposes `sleepNotAllowed` from its root entry point:
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
import { sleepNotAllowed } from "sleep-not-allowed";
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Start the scheduler
|
|
80
|
+
|
|
81
|
+
Pass an options object with a target URL and interval in milliseconds:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
const timer = sleepNotAllowed({
|
|
85
|
+
url: "https://your-app.example.com/health",
|
|
86
|
+
interval: 60_000,
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The function starts the first health check immediately. It then schedules another check after each interval.
|
|
91
|
+
|
|
92
|
+
### Options
|
|
93
|
+
|
|
94
|
+
| Option | Type | Required | Default | Description |
|
|
95
|
+
| ---------- | -------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------- |
|
|
96
|
+
| `url` | `string` | Yes | - | URL that receives the periodic HTTP `GET` request. |
|
|
97
|
+
| `interval` | `number` | Yes | - | Time between scheduled checks, in milliseconds. |
|
|
98
|
+
| `timeout` | `number` | No | `10000` | Maximum request time, in milliseconds. The request is aborted when this time is exceeded. |
|
|
99
|
+
| `retries` | `number` | No | `0` | Number of additional attempts after a failed request. Retries happen immediately during the current check. |
|
|
100
|
+
|
|
101
|
+
For example:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
import { sleepNotAllowed } from "sleep-not-allowed";
|
|
105
|
+
|
|
106
|
+
sleepNotAllowed({
|
|
107
|
+
url: "https://your-app.example.com/health",
|
|
108
|
+
interval: 60_000,
|
|
109
|
+
timeout: 5_000,
|
|
110
|
+
retries: 2,
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
This configuration makes one request immediately and then runs the scheduler every 60 seconds. Each request has a five-second timeout. If a request fails, the package makes up to two additional attempts before logging the failure.
|
|
115
|
+
|
|
116
|
+
### Stop the scheduler
|
|
117
|
+
|
|
118
|
+
`sleepNotAllowed` returns the timer created by `setInterval`. You can pass that value to `clearInterval` when the scheduler should stop:
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const timer = sleepNotAllowed({
|
|
122
|
+
url: "https://your-app.example.com/health",
|
|
123
|
+
interval: 60_000,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
clearInterval(timer);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
There is no separate stop method in the public API.
|
|
130
|
+
|
|
131
|
+
## How it works
|
|
132
|
+
|
|
133
|
+
```text
|
|
134
|
+
Application
|
|
135
|
+
|
|
|
136
|
+
v
|
|
137
|
+
sleep-not-allowed
|
|
138
|
+
|
|
|
139
|
+
v
|
|
140
|
+
Periodic HTTP GET request
|
|
141
|
+
|
|
|
142
|
+
v
|
|
143
|
+
User's server
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
When `sleepNotAllowed` is called:
|
|
147
|
+
|
|
148
|
+
1. The package logs the configured settings.
|
|
149
|
+
2. It sends a `GET` request immediately.
|
|
150
|
+
3. It schedules the same operation with `setInterval` using the configured `interval`.
|
|
151
|
+
4. Each request uses the configured `timeout`, or `10000` milliseconds by default.
|
|
152
|
+
5. If a request fails, the package retries it immediately until the configured number of retries is exhausted.
|
|
153
|
+
6. If all attempts fail, the failure is logged and the scheduler continues with the next scheduled interval.
|
|
154
|
+
|
|
155
|
+
A response is considered successful when its HTTP status is in the `2xx` range accepted by `fetch` through `response.ok`.
|
|
156
|
+
|
|
157
|
+
## Example
|
|
158
|
+
|
|
159
|
+
The following example starts a scheduler for an existing application health endpoint:
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
import { sleepNotAllowed } from "sleep-not-allowed";
|
|
163
|
+
|
|
164
|
+
const scheduler = sleepNotAllowed({
|
|
165
|
+
url: "https://api.example.com/health",
|
|
166
|
+
interval: 2 * 60 * 1000,
|
|
167
|
+
timeout: 10_000,
|
|
168
|
+
retries: 1,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Stop the periodic requests when they are no longer needed.
|
|
172
|
+
// clearInterval(scheduler);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The URL must point to a server that can receive the request. The package does not create or expose the `/health` endpoint.
|
|
176
|
+
|
|
177
|
+
## Configuration
|
|
178
|
+
|
|
179
|
+
Configuration is passed directly to `sleepNotAllowed` through the `SleepNotAllowedOptions` object:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
interface SleepNotAllowedOptions {
|
|
183
|
+
url: string;
|
|
184
|
+
interval: number;
|
|
185
|
+
timeout?: number;
|
|
186
|
+
retries?: number;
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`interval`, `timeout`, and the timer values are expressed in milliseconds. The implementation does not define additional configuration files or environment variables.
|
|
191
|
+
|
|
192
|
+
## API Reference
|
|
193
|
+
|
|
194
|
+
### `sleepNotAllowed(options)`
|
|
195
|
+
|
|
196
|
+
Starts periodic health-check requests.
|
|
197
|
+
|
|
198
|
+
**Parameters**
|
|
199
|
+
|
|
200
|
+
- `options: SleepNotAllowedOptions` - Scheduler configuration.
|
|
201
|
+
- `url: string` - Target URL for the HTTP `GET` request.
|
|
202
|
+
- `interval: number` - Interval between requests, in milliseconds.
|
|
203
|
+
- `timeout?: number` - Request timeout, in milliseconds. Defaults to `10000`.
|
|
204
|
+
- `retries?: number` - Additional immediate attempts after a failure. Defaults to `0`.
|
|
205
|
+
|
|
206
|
+
**Returns**
|
|
207
|
+
|
|
208
|
+
`NodeJS.Timeout` - The interval timer created by the scheduler. Use it with `clearInterval` to stop future scheduled requests.
|
|
209
|
+
|
|
210
|
+
**Example**
|
|
211
|
+
|
|
212
|
+
```js
|
|
213
|
+
import { sleepNotAllowed } from "sleep-not-allowed";
|
|
214
|
+
|
|
215
|
+
const timer = sleepNotAllowed({
|
|
216
|
+
url: "https://example.com/health",
|
|
217
|
+
interval: 30_000,
|
|
218
|
+
timeout: 10_000,
|
|
219
|
+
retries: 2,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Later:
|
|
223
|
+
clearInterval(timer);
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### `SleepNotAllowedOptions`
|
|
227
|
+
|
|
228
|
+
The package also exports `SleepNotAllowedOptions` as a TypeScript type:
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import type { SleepNotAllowedOptions } from "sleep-not-allowed";
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Error Handling
|
|
235
|
+
|
|
236
|
+
The underlying request uses `fetch` with an `AbortController`.
|
|
237
|
+
|
|
238
|
+
- If the response is not successful (`response.ok` is `false`), the request fails with an error containing the HTTP status, such as `Health check failed with status 503`.
|
|
239
|
+
- If the timeout is exceeded, the request is aborted.
|
|
240
|
+
- Network and other request errors are caught by the scheduler.
|
|
241
|
+
- The scheduler retries failed requests according to `retries`.
|
|
242
|
+
- After all attempts fail, the package logs the URL and error with `console.error`.
|
|
243
|
+
- A failed check does not stop the scheduler; the next scheduled check still runs.
|
|
244
|
+
|
|
245
|
+
## Development
|
|
246
|
+
|
|
247
|
+
Clone the repository and install its dependencies:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
git clone https://github.com/ManuelPiresLuis01/sleep-not-allowed.git
|
|
251
|
+
cd sleep-not-allowed
|
|
252
|
+
npm install
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Available npm scripts:
|
|
256
|
+
|
|
257
|
+
| Command | Description |
|
|
258
|
+
| ------------------------ | ----------------------------------------------------------------------------------- |
|
|
259
|
+
| `npm run build` | Compile the TypeScript source into `dist/`, including declarations and source maps. |
|
|
260
|
+
| `npm test` | Run the automated Node.js test suite. |
|
|
261
|
+
| `npm run format` | Format source, tests, and root JSON files with Prettier. |
|
|
262
|
+
| `npm run format:check` | Check formatting without changing files. |
|
|
263
|
+
| `npm run prepublishOnly` | Run the build before publishing. |
|
|
264
|
+
|
|
265
|
+
For a local development cycle:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
npm run format:check
|
|
269
|
+
npm run build
|
|
270
|
+
npm test
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Contributing
|
|
274
|
+
|
|
275
|
+
1. Fork the repository.
|
|
276
|
+
2. Clone your fork.
|
|
277
|
+
3. Create a branch for your changes.
|
|
278
|
+
4. Make your changes.
|
|
279
|
+
5. Run `npm run format:check`, `npm run build`, and `npm test`.
|
|
280
|
+
6. Create a Pull Request against the repository.
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
The package metadata declares the [ISC License](https://opensource.org/license/isc-license-txt). A separate `LICENSE` file is not currently included in the repository.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requester.d.ts","sourceRoot":"","sources":["../../src/core/requester.ts"],"names":[],"mappings":"AAAA,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBzE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export async function request(url, timeout) {
|
|
2
|
+
const controller = new AbortController();
|
|
3
|
+
const timeoutId = setTimeout(() => {
|
|
4
|
+
controller.abort();
|
|
5
|
+
}, timeout);
|
|
6
|
+
try {
|
|
7
|
+
const response = await fetch(url, {
|
|
8
|
+
method: "GET",
|
|
9
|
+
signal: controller.signal,
|
|
10
|
+
});
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
throw new Error(`Health check failed with status ${response.status}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
finally {
|
|
16
|
+
clearTimeout(timeoutId);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=requester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requester.js","sourceRoot":"","sources":["../../src/core/requester.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,GAAW,EAAE,OAAe;IACxD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;QAChC,UAAU,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC,EAAE,OAAO,CAAC,CAAC;IAEZ,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,UAAU,CAAC,MAAM;SAC1B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/core/scheduler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,wBAAgB,eAAe,CAC7B,OAAO,EAAE,sBAAsB,GAC9B,MAAM,CAAC,OAAO,CA8BhB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { request } from "./requester.js";
|
|
2
|
+
import { logger } from "../utils/logger.js";
|
|
3
|
+
export function createScheduler(options) {
|
|
4
|
+
const { url, interval, timeout = 10000, retries = 0 } = options;
|
|
5
|
+
logger.start(url, interval, timeout, retries);
|
|
6
|
+
const execute = async () => {
|
|
7
|
+
let attempts = 0;
|
|
8
|
+
while (attempts <= retries) {
|
|
9
|
+
try {
|
|
10
|
+
await request(url, timeout);
|
|
11
|
+
logger.success(url);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
attempts++;
|
|
16
|
+
if (attempts > retries) {
|
|
17
|
+
logger.error(url, error);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
execute();
|
|
24
|
+
return setInterval(execute, interval);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/core/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,MAAM,UAAU,eAAe,CAC7B,OAA+B;IAE/B,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,GAAG,KAAK,EAAE,OAAO,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAEhE,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAE9C,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;QACzB,IAAI,QAAQ,GAAG,CAAC,CAAC;QAEjB,OAAO,QAAQ,IAAI,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;gBAE5B,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAEpB,OAAO;YACT,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,QAAQ,EAAE,CAAC;gBAEX,IAAI,QAAQ,GAAG,OAAO,EAAE,CAAC;oBACvB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;oBAEzB,OAAO;gBACT,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,CAAC;IAEV,OAAO,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE/D,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,kBAE9D;AAED,YAAY,EAAE,sBAAsB,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,MAAM,UAAU,eAAe,CAAC,OAA+B;IAC7D,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM;IACjB,KAAK,MAAM,MAAM,YAAY,MAAM,WAAW,MAAM,WAAW,MAAM;IAwBrE,OAAO,MAAM,MAAM;IAInB,KAAK,MAAM,MAAM,SAAS,OAAO;CAGlC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const reset = "\x1b[0m";
|
|
2
|
+
const green = "\x1b[32m";
|
|
3
|
+
const cyan = "\x1b[36m";
|
|
4
|
+
const red = "\x1b[31m";
|
|
5
|
+
const gray = "\x1b[90m";
|
|
6
|
+
const bold = "\x1b[1m";
|
|
7
|
+
const prefix = `${gray}[${reset}${cyan}sleep-not-allowed${reset}${gray}]${reset}`;
|
|
8
|
+
export const logger = {
|
|
9
|
+
start(url, interval, timeout, retries) {
|
|
10
|
+
console.log("");
|
|
11
|
+
console.log(`${cyan}${bold}╔══════════════════════════════════════════════════╗${reset}`);
|
|
12
|
+
console.log(`${cyan}${bold}║ SLEEP-NOT-ALLOWED ║${reset}`);
|
|
13
|
+
console.log(`${cyan}${bold}║ by Manuel Pires Luís ║${reset}`);
|
|
14
|
+
console.log(`${cyan}${bold}╚══════════════════════════════════════════════════╝${reset}`);
|
|
15
|
+
console.log("");
|
|
16
|
+
console.log(`${prefix} ${green}✓${reset} Service started`);
|
|
17
|
+
console.log(`${prefix} ${cyan}→${reset} Target: ${url}`);
|
|
18
|
+
console.log(`${prefix} ${cyan}→${reset} Interval: ${interval}ms`);
|
|
19
|
+
console.log(`${prefix} ${cyan}→${reset} Timeout: ${timeout}ms`);
|
|
20
|
+
console.log(`${prefix} ${cyan}→${reset} Retries: ${retries}`);
|
|
21
|
+
console.log(`${prefix} ${green}✓${reset} Keep-alive is active`);
|
|
22
|
+
console.log("");
|
|
23
|
+
},
|
|
24
|
+
success(url) {
|
|
25
|
+
console.log(`${prefix} ${green}✓ Ping successful:${reset} ${url}`);
|
|
26
|
+
},
|
|
27
|
+
error(url, error) {
|
|
28
|
+
console.error(`${prefix} ${red}✗ Ping failed:${reset} ${url}`, error);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,MAAM,KAAK,GAAG,UAAU,CAAC;AACzB,MAAM,IAAI,GAAG,UAAU,CAAC;AACxB,MAAM,GAAG,GAAG,UAAU,CAAC;AACvB,MAAM,IAAI,GAAG,UAAU,CAAC;AACxB,MAAM,IAAI,GAAG,SAAS,CAAC;AAEvB,MAAM,MAAM,GAAG,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,oBAAoB,KAAK,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC;AAElF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,CAAC,GAAW,EAAE,QAAgB,EAAE,OAAe,EAAE,OAAe;QACnE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CACT,GAAG,IAAI,GAAG,IAAI,uDAAuD,KAAK,EAAE,CAC7E,CAAC;QACF,OAAO,CAAC,GAAG,CACT,GAAG,IAAI,GAAG,IAAI,sDAAsD,KAAK,EAAE,CAC5E,CAAC;QACF,OAAO,CAAC,GAAG,CACT,GAAG,IAAI,GAAG,IAAI,sDAAsD,KAAK,EAAE,CAC5E,CAAC;QACF,OAAO,CAAC,GAAG,CACT,GAAG,IAAI,GAAG,IAAI,uDAAuD,KAAK,EAAE,CAC7E,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,KAAK,IAAI,KAAK,kBAAkB,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,IAAI,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,IAAI,IAAI,KAAK,cAAc,QAAQ,IAAI,CAAC,CAAC;QAClE,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,IAAI,IAAI,KAAK,aAAa,OAAO,IAAI,CAAC,CAAC;QAChE,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,IAAI,IAAI,KAAK,aAAa,OAAO,EAAE,CAAC,CAAC;QAC9D,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,KAAK,IAAI,KAAK,uBAAuB,CAAC,CAAC;QAChE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,GAAW;QACjB,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,KAAK,qBAAqB,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,GAAW,EAAE,KAAc;QAC/B,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,GAAG,iBAAiB,KAAK,IAAI,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;IACxE,CAAC;CACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sleep-not-allowed",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Keep your server awake with configurable health checks.",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"main": "server.js",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"test": "node --test test/test-core.mjs",
|
|
19
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.mjs\" \"*.json\"",
|
|
20
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.mjs\" \"*.json\"",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/ManuelPiresLuis01/sleep-not-allowed.git"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"keep-alive",
|
|
29
|
+
"server",
|
|
30
|
+
"health-check",
|
|
31
|
+
"uptime",
|
|
32
|
+
"ping",
|
|
33
|
+
"sleep-not-allowed"
|
|
34
|
+
],
|
|
35
|
+
"author": "Manuel Pires Luis",
|
|
36
|
+
"license": "ISC",
|
|
37
|
+
"type": "module",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/ManuelPiresLuis01/sleep-not-allowed/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/ManuelPiresLuis01/sleep-not-allowed#readme",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.20.2",
|
|
44
|
+
"prettier": "^3.9.6",
|
|
45
|
+
"typescript": "^7.0.2"
|
|
46
|
+
}
|
|
47
|
+
}
|