@platformatic/watt-extra 0.1.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 +87 -0
- package/app.js +124 -0
- package/cli.js +141 -0
- package/clients/compliance/compliance-types.d.ts +887 -0
- package/clients/compliance/compliance.mjs +1049 -0
- package/clients/compliance/compliance.openapi.json +6127 -0
- package/clients/control-plane/control-plane-types.d.ts +2696 -0
- package/clients/control-plane/control-plane.mjs +3051 -0
- package/clients/control-plane/control-plane.openapi.json +13693 -0
- package/clients/cron/cron-types.d.ts +1479 -0
- package/clients/cron/cron.mjs +872 -0
- package/clients/cron/cron.openapi.json +9330 -0
- package/compliance/index.js +21 -0
- package/compliance/rules/dependencies.js +76 -0
- package/compliance/rules/utils.js +12 -0
- package/eslint.config.js +11 -0
- package/help/start.txt +12 -0
- package/help/watt-extra.txt +12 -0
- package/index.js +45 -0
- package/lib/banner.js +22 -0
- package/lib/errors.js +34 -0
- package/lib/utils.js +34 -0
- package/lib/wattpro.js +580 -0
- package/package.json +50 -0
- package/plugins/alerts.js +115 -0
- package/plugins/auth.js +89 -0
- package/plugins/compliancy.js +70 -0
- package/plugins/env.js +58 -0
- package/plugins/flamegraphs.js +100 -0
- package/plugins/init.js +70 -0
- package/plugins/metadata.js +84 -0
- package/plugins/scheduler.js +48 -0
- package/plugins/update.js +128 -0
- package/renovate.json +6 -0
- package/test/alerts.test.js +607 -0
- package/test/auth.test.js +128 -0
- package/test/auto-cache.test.js +401 -0
- package/test/cli.test.js +75 -0
- package/test/compliancy.test.js +87 -0
- package/test/fixtures/runtime-domains/alpha/package.json +5 -0
- package/test/fixtures/runtime-domains/alpha/platformatic.json +6 -0
- package/test/fixtures/runtime-domains/alpha/plugin.js +16 -0
- package/test/fixtures/runtime-domains/beta/package.json +5 -0
- package/test/fixtures/runtime-domains/beta/platformatic.json +6 -0
- package/test/fixtures/runtime-domains/beta/plugin.js +7 -0
- package/test/fixtures/runtime-domains/composer/package.json +5 -0
- package/test/fixtures/runtime-domains/composer/platformatic.json +19 -0
- package/test/fixtures/runtime-domains/package.json +1 -0
- package/test/fixtures/runtime-domains/platformatic.json +27 -0
- package/test/fixtures/runtime-health/package.json +20 -0
- package/test/fixtures/runtime-health/platformatic.json +16 -0
- package/test/fixtures/runtime-health/services/service-1/package.json +17 -0
- package/test/fixtures/runtime-health/services/service-1/platformatic.json +16 -0
- package/test/fixtures/runtime-health/services/service-1/plugins/example.js +6 -0
- package/test/fixtures/runtime-health/services/service-1/routes/root.cjs +8 -0
- package/test/fixtures/runtime-health/services/service-2/package.json +17 -0
- package/test/fixtures/runtime-health/services/service-2/platformatic.json +16 -0
- package/test/fixtures/runtime-health/services/service-2/plugins/example.js +6 -0
- package/test/fixtures/runtime-health/services/service-2/routes/root.cjs +8 -0
- package/test/fixtures/runtime-next/package.json +5 -0
- package/test/fixtures/runtime-next/platformatic.json +9 -0
- package/test/fixtures/runtime-next/web/next/next.config.js +2 -0
- package/test/fixtures/runtime-next/web/next/package.json +7 -0
- package/test/fixtures/runtime-next/web/next/platformatic.json +9 -0
- package/test/fixtures/runtime-next/web/next/src/app/direct/route.js +3 -0
- package/test/fixtures/runtime-next/web/next/src/app/layout.jsx +7 -0
- package/test/fixtures/runtime-next/web/next/src/app/page.jsx +3 -0
- package/test/fixtures/runtime-scheduler/main/package.json +5 -0
- package/test/fixtures/runtime-scheduler/main/platformatic.json +9 -0
- package/test/fixtures/runtime-scheduler/main/routes/root.cjs +11 -0
- package/test/fixtures/runtime-scheduler/package.json +1 -0
- package/test/fixtures/runtime-scheduler/platformatic.json +27 -0
- package/test/fixtures/runtime-service/main/package.json +5 -0
- package/test/fixtures/runtime-service/main/platformatic.json +12 -0
- package/test/fixtures/runtime-service/main/routes/root.cjs +11 -0
- package/test/fixtures/runtime-service/package.json +1 -0
- package/test/fixtures/runtime-service/platformatic.json +19 -0
- package/test/fixtures/service-1/package.json +7 -0
- package/test/fixtures/service-1/platformatic.json +18 -0
- package/test/fixtures/service-1/routes/root.cjs +48 -0
- package/test/fixtures/service-2/platformatic.json +21 -0
- package/test/fixtures/service-2/routes/root.cjs +5 -0
- package/test/fixtures/service-3/package.json +5 -0
- package/test/fixtures/service-3/platformatic.json +21 -0
- package/test/fixtures/service-3/routes/root.cjs +8 -0
- package/test/health.test.js +44 -0
- package/test/helper.js +274 -0
- package/test/init.test.js +243 -0
- package/test/patch-config.test.js +434 -0
- package/test/scheduler.test.js +71 -0
- package/test/send-to-icc-retry.test.js +138 -0
- package/test/shared-context.test.js +82 -0
- package/test/spawn.test.js +110 -0
- package/test/trigger-flamegraphs.test.js +226 -0
- package/test/update.test.js +519 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = async function (fastify) {
|
|
4
|
+
fastify.get('/alpha', async () => {
|
|
5
|
+
return { from: 'alpha' }
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
let counter = 0
|
|
9
|
+
fastify.get('/counter', async () => {
|
|
10
|
+
return { counter: counter++ }
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
fastify.get('/shared-context', async () => {
|
|
14
|
+
return globalThis.platformatic.sharedContext.get()
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/composer/2.44.0.json",
|
|
3
|
+
"composer": {
|
|
4
|
+
"services": [
|
|
5
|
+
{
|
|
6
|
+
"id": "beta",
|
|
7
|
+
"proxy": {
|
|
8
|
+
"prefix": "/2"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"id": "alpha",
|
|
13
|
+
"proxy": {
|
|
14
|
+
"prefix": "/1"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/2.44.0.json",
|
|
3
|
+
"services": [
|
|
4
|
+
{
|
|
5
|
+
"id": "composer",
|
|
6
|
+
"path": "composer",
|
|
7
|
+
"config": "platformatic.json"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "alpha",
|
|
11
|
+
"path": "alpha",
|
|
12
|
+
"config": "platformatic.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "beta",
|
|
16
|
+
"path": "beta",
|
|
17
|
+
"config": "platformatic.json"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"logger": {
|
|
21
|
+
"level": "error"
|
|
22
|
+
},
|
|
23
|
+
"httpCache": {
|
|
24
|
+
"cacheTagsHeader": "x-custom-cache-tags"
|
|
25
|
+
},
|
|
26
|
+
"entrypoint": "composer"
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "runtime-health",
|
|
3
|
+
"workspaces": [
|
|
4
|
+
"services/*"
|
|
5
|
+
],
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "platformatic start"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"fastify": "^5.0.0",
|
|
11
|
+
"borp": "^0.19.0"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@platformatic/runtime": "workspace:*",
|
|
15
|
+
"platformatic": "workspace:*"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": "^18.8.0 || >=20.6.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/2.62.1.json",
|
|
3
|
+
"entrypoint": "service-1",
|
|
4
|
+
"watch": true,
|
|
5
|
+
"autoload": {
|
|
6
|
+
"path": "services",
|
|
7
|
+
"exclude": ["docs"]
|
|
8
|
+
},
|
|
9
|
+
"logger": {
|
|
10
|
+
"level": "info"
|
|
11
|
+
},
|
|
12
|
+
"server": {
|
|
13
|
+
"hostname": "127.0.0.1",
|
|
14
|
+
"port": "3042"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "service-1",
|
|
3
|
+
"scripts": {
|
|
4
|
+
"start": "platformatic start",
|
|
5
|
+
"test": "borp"
|
|
6
|
+
},
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"fastify": "^5.0.0",
|
|
9
|
+
"borp": "^0.19.0"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@platformatic/service": "^2.70.0"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": "^18.8.0 || >=20.6.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/service/2.62.1.json",
|
|
3
|
+
"service": {
|
|
4
|
+
"openapi": true
|
|
5
|
+
},
|
|
6
|
+
"watch": true,
|
|
7
|
+
"plugins": {
|
|
8
|
+
"paths": [
|
|
9
|
+
{
|
|
10
|
+
"path": "./plugins",
|
|
11
|
+
"encapsulate": false
|
|
12
|
+
},
|
|
13
|
+
"./routes"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "service-2",
|
|
3
|
+
"scripts": {
|
|
4
|
+
"start": "platformatic start",
|
|
5
|
+
"test": "borp"
|
|
6
|
+
},
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"fastify": "^5.0.0",
|
|
9
|
+
"borp": "^0.19.0"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@platformatic/service": "^2.70.0"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": "^18.8.0 || >=20.6.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/service/2.62.1.json",
|
|
3
|
+
"service": {
|
|
4
|
+
"openapi": true
|
|
5
|
+
},
|
|
6
|
+
"watch": true,
|
|
7
|
+
"plugins": {
|
|
8
|
+
"paths": [
|
|
9
|
+
{
|
|
10
|
+
"path": "./plugins",
|
|
11
|
+
"encapsulate": false
|
|
12
|
+
},
|
|
13
|
+
"./routes"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/2.54.0.json",
|
|
3
|
+
"server": {
|
|
4
|
+
"https": {
|
|
5
|
+
"key": "key",
|
|
6
|
+
"cert": "cert"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"services": [
|
|
10
|
+
{
|
|
11
|
+
"id": "main",
|
|
12
|
+
"path": "main",
|
|
13
|
+
"config": "platformatic.json"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"logger": {
|
|
17
|
+
"level": "error"
|
|
18
|
+
},
|
|
19
|
+
"scheduler": [
|
|
20
|
+
{
|
|
21
|
+
"name": "test",
|
|
22
|
+
"callbackUrl": "http://localhost:3000",
|
|
23
|
+
"cron": "*/5 * * * *",
|
|
24
|
+
"method": "GET"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/2.58.0.json",
|
|
3
|
+
"server": {
|
|
4
|
+
"https": {
|
|
5
|
+
"key": "key",
|
|
6
|
+
"cert": "cert"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"services": [
|
|
10
|
+
{
|
|
11
|
+
"id": "main",
|
|
12
|
+
"path": "main",
|
|
13
|
+
"config": "platformatic.json"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"logger": {
|
|
17
|
+
"level": "error"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/service/2.54.0.json",
|
|
3
|
+
"server": {
|
|
4
|
+
"logger": {
|
|
5
|
+
"level": "silent"
|
|
6
|
+
},
|
|
7
|
+
"port": 3042,
|
|
8
|
+
"keepAliveTimeout": 1
|
|
9
|
+
},
|
|
10
|
+
"service": {
|
|
11
|
+
"openapi": true
|
|
12
|
+
},
|
|
13
|
+
"plugins": {
|
|
14
|
+
"paths": ["./routes"],
|
|
15
|
+
"typescript": false
|
|
16
|
+
},
|
|
17
|
+
"watch": true
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { join } = require("node:path");
|
|
4
|
+
const { readFile } = require("node:fs/promises");
|
|
5
|
+
const { request } = require("undici");
|
|
6
|
+
|
|
7
|
+
module.exports = async function (fastify) {
|
|
8
|
+
fastify.get("/example", async () => {
|
|
9
|
+
return { hello: "world" };
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
fastify.get("/config", async () => {
|
|
13
|
+
return fastify.platformatic.config;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
fastify.get("/preprocess", async () => {
|
|
17
|
+
return {
|
|
18
|
+
base: "~PLT_BASE_PATH",
|
|
19
|
+
leadingSlash: "/~PLT_BASE_PATH",
|
|
20
|
+
withPrefix: "~PLT_BASE_PATH/foo",
|
|
21
|
+
externalUrl: "~PLT_EXTERNAL_APP_URL",
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
fastify.get("/custom-ext-file", async () => {
|
|
26
|
+
const customExtFilePath = join(__dirname, "..", "file.custom");
|
|
27
|
+
const customExtFile = await readFile(customExtFilePath, "utf8");
|
|
28
|
+
return { data: customExtFile };
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
fastify.get("/env", async () => {
|
|
32
|
+
return { env: process.env };
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
fastify.post("/request", async (req) => {
|
|
36
|
+
const { method, url } = req.body;
|
|
37
|
+
|
|
38
|
+
const { statusCode, headers, body } = await request(url, {
|
|
39
|
+
method: method ?? "GET",
|
|
40
|
+
headers: {
|
|
41
|
+
"content-type": "application/json",
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const data = await body.text();
|
|
45
|
+
|
|
46
|
+
return { statusCode, headers, data };
|
|
47
|
+
});
|
|
48
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/service/2.54.0.json",
|
|
3
|
+
"server": {
|
|
4
|
+
"hostname": "127.0.0.1",
|
|
5
|
+
"port": "3042",
|
|
6
|
+
"logger": {
|
|
7
|
+
"level": "silent"
|
|
8
|
+
},
|
|
9
|
+
"keepAliveTimeout": 1
|
|
10
|
+
},
|
|
11
|
+
"service": {
|
|
12
|
+
"openapi": true
|
|
13
|
+
},
|
|
14
|
+
"plugins": {
|
|
15
|
+
"paths": [
|
|
16
|
+
"./routes"
|
|
17
|
+
],
|
|
18
|
+
"typescript": false
|
|
19
|
+
},
|
|
20
|
+
"watch": true
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/service/2.54.0.json",
|
|
3
|
+
"server": {
|
|
4
|
+
"hostname": "127.0.0.1",
|
|
5
|
+
"port": "3042",
|
|
6
|
+
"logger": {
|
|
7
|
+
"level": "silent"
|
|
8
|
+
},
|
|
9
|
+
"keepAliveTimeout": 1
|
|
10
|
+
},
|
|
11
|
+
"service": {
|
|
12
|
+
"openapi": true
|
|
13
|
+
},
|
|
14
|
+
"plugins": {
|
|
15
|
+
"paths": [
|
|
16
|
+
"./routes"
|
|
17
|
+
],
|
|
18
|
+
"typescript": false
|
|
19
|
+
},
|
|
20
|
+
"watch": true
|
|
21
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import { test } from 'node:test'
|
|
3
|
+
import { randomUUID } from 'node:crypto'
|
|
4
|
+
import { join, dirname } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
setUpEnvironment,
|
|
9
|
+
startICC
|
|
10
|
+
} from './helper.js'
|
|
11
|
+
import { start } from '../index.js'
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
14
|
+
const __dirname = dirname(__filename)
|
|
15
|
+
|
|
16
|
+
test('check that health is configured in runtime', async (t) => {
|
|
17
|
+
const appName = 'test-health'
|
|
18
|
+
const applicationId = randomUUID()
|
|
19
|
+
const applicationPath = join(__dirname, 'fixtures', 'runtime-health')
|
|
20
|
+
|
|
21
|
+
const icc = await startICC(t, {
|
|
22
|
+
applicationId
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
setUpEnvironment({
|
|
26
|
+
PLT_APP_NAME: appName,
|
|
27
|
+
PLT_APP_DIR: applicationPath,
|
|
28
|
+
PLT_ICC_URL: 'http://127.0.0.1:3000'
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const app = await start()
|
|
32
|
+
|
|
33
|
+
t.after(async () => {
|
|
34
|
+
await app.close()
|
|
35
|
+
await icc.close()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const runtimeConfig = await app.wattpro.runtime.getRuntimeConfig()
|
|
39
|
+
|
|
40
|
+
assert.ok(runtimeConfig.health, 'Health configuration should be present')
|
|
41
|
+
assert.strictEqual(runtimeConfig.health.enabled, true, 'Health monitoring should be enabled')
|
|
42
|
+
assert.strictEqual(runtimeConfig.health.interval, 1000)
|
|
43
|
+
assert.strictEqual(runtimeConfig.health.gracePeriod, 30000)
|
|
44
|
+
})
|