@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.
Files changed (95) hide show
  1. package/README.md +87 -0
  2. package/app.js +124 -0
  3. package/cli.js +141 -0
  4. package/clients/compliance/compliance-types.d.ts +887 -0
  5. package/clients/compliance/compliance.mjs +1049 -0
  6. package/clients/compliance/compliance.openapi.json +6127 -0
  7. package/clients/control-plane/control-plane-types.d.ts +2696 -0
  8. package/clients/control-plane/control-plane.mjs +3051 -0
  9. package/clients/control-plane/control-plane.openapi.json +13693 -0
  10. package/clients/cron/cron-types.d.ts +1479 -0
  11. package/clients/cron/cron.mjs +872 -0
  12. package/clients/cron/cron.openapi.json +9330 -0
  13. package/compliance/index.js +21 -0
  14. package/compliance/rules/dependencies.js +76 -0
  15. package/compliance/rules/utils.js +12 -0
  16. package/eslint.config.js +11 -0
  17. package/help/start.txt +12 -0
  18. package/help/watt-extra.txt +12 -0
  19. package/index.js +45 -0
  20. package/lib/banner.js +22 -0
  21. package/lib/errors.js +34 -0
  22. package/lib/utils.js +34 -0
  23. package/lib/wattpro.js +580 -0
  24. package/package.json +50 -0
  25. package/plugins/alerts.js +115 -0
  26. package/plugins/auth.js +89 -0
  27. package/plugins/compliancy.js +70 -0
  28. package/plugins/env.js +58 -0
  29. package/plugins/flamegraphs.js +100 -0
  30. package/plugins/init.js +70 -0
  31. package/plugins/metadata.js +84 -0
  32. package/plugins/scheduler.js +48 -0
  33. package/plugins/update.js +128 -0
  34. package/renovate.json +6 -0
  35. package/test/alerts.test.js +607 -0
  36. package/test/auth.test.js +128 -0
  37. package/test/auto-cache.test.js +401 -0
  38. package/test/cli.test.js +75 -0
  39. package/test/compliancy.test.js +87 -0
  40. package/test/fixtures/runtime-domains/alpha/package.json +5 -0
  41. package/test/fixtures/runtime-domains/alpha/platformatic.json +6 -0
  42. package/test/fixtures/runtime-domains/alpha/plugin.js +16 -0
  43. package/test/fixtures/runtime-domains/beta/package.json +5 -0
  44. package/test/fixtures/runtime-domains/beta/platformatic.json +6 -0
  45. package/test/fixtures/runtime-domains/beta/plugin.js +7 -0
  46. package/test/fixtures/runtime-domains/composer/package.json +5 -0
  47. package/test/fixtures/runtime-domains/composer/platformatic.json +19 -0
  48. package/test/fixtures/runtime-domains/package.json +1 -0
  49. package/test/fixtures/runtime-domains/platformatic.json +27 -0
  50. package/test/fixtures/runtime-health/package.json +20 -0
  51. package/test/fixtures/runtime-health/platformatic.json +16 -0
  52. package/test/fixtures/runtime-health/services/service-1/package.json +17 -0
  53. package/test/fixtures/runtime-health/services/service-1/platformatic.json +16 -0
  54. package/test/fixtures/runtime-health/services/service-1/plugins/example.js +6 -0
  55. package/test/fixtures/runtime-health/services/service-1/routes/root.cjs +8 -0
  56. package/test/fixtures/runtime-health/services/service-2/package.json +17 -0
  57. package/test/fixtures/runtime-health/services/service-2/platformatic.json +16 -0
  58. package/test/fixtures/runtime-health/services/service-2/plugins/example.js +6 -0
  59. package/test/fixtures/runtime-health/services/service-2/routes/root.cjs +8 -0
  60. package/test/fixtures/runtime-next/package.json +5 -0
  61. package/test/fixtures/runtime-next/platformatic.json +9 -0
  62. package/test/fixtures/runtime-next/web/next/next.config.js +2 -0
  63. package/test/fixtures/runtime-next/web/next/package.json +7 -0
  64. package/test/fixtures/runtime-next/web/next/platformatic.json +9 -0
  65. package/test/fixtures/runtime-next/web/next/src/app/direct/route.js +3 -0
  66. package/test/fixtures/runtime-next/web/next/src/app/layout.jsx +7 -0
  67. package/test/fixtures/runtime-next/web/next/src/app/page.jsx +3 -0
  68. package/test/fixtures/runtime-scheduler/main/package.json +5 -0
  69. package/test/fixtures/runtime-scheduler/main/platformatic.json +9 -0
  70. package/test/fixtures/runtime-scheduler/main/routes/root.cjs +11 -0
  71. package/test/fixtures/runtime-scheduler/package.json +1 -0
  72. package/test/fixtures/runtime-scheduler/platformatic.json +27 -0
  73. package/test/fixtures/runtime-service/main/package.json +5 -0
  74. package/test/fixtures/runtime-service/main/platformatic.json +12 -0
  75. package/test/fixtures/runtime-service/main/routes/root.cjs +11 -0
  76. package/test/fixtures/runtime-service/package.json +1 -0
  77. package/test/fixtures/runtime-service/platformatic.json +19 -0
  78. package/test/fixtures/service-1/package.json +7 -0
  79. package/test/fixtures/service-1/platformatic.json +18 -0
  80. package/test/fixtures/service-1/routes/root.cjs +48 -0
  81. package/test/fixtures/service-2/platformatic.json +21 -0
  82. package/test/fixtures/service-2/routes/root.cjs +5 -0
  83. package/test/fixtures/service-3/package.json +5 -0
  84. package/test/fixtures/service-3/platformatic.json +21 -0
  85. package/test/fixtures/service-3/routes/root.cjs +8 -0
  86. package/test/health.test.js +44 -0
  87. package/test/helper.js +274 -0
  88. package/test/init.test.js +243 -0
  89. package/test/patch-config.test.js +434 -0
  90. package/test/scheduler.test.js +71 -0
  91. package/test/send-to-icc-retry.test.js +138 -0
  92. package/test/shared-context.test.js +82 -0
  93. package/test/spawn.test.js +110 -0
  94. package/test/trigger-flamegraphs.test.js +226 -0
  95. 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,5 @@
1
+ {
2
+ "dependencies": {
3
+ "@platformatic/service": "workspace:*"
4
+ }
5
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/service/2.44.0.json",
3
+ "plugins": {
4
+ "paths": ["./plugin.js"]
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ module.exports = async function (fastify) {
4
+ fastify.get('/beta', async () => {
5
+ return { from: 'beta' }
6
+ })
7
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "dependencies": {
3
+ "@platformatic/composer": "workspace:*"
4
+ }
5
+ }
@@ -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,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,6 @@
1
+ /// <reference path="../global.d.ts" />
2
+ 'use strict'
3
+ /** @param {import('fastify').FastifyInstance} fastify */
4
+ module.exports = async function (fastify, opts) {
5
+ fastify.decorate('example', 'foobar')
6
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference path="../global.d.ts" />
2
+ 'use strict'
3
+ /** @param {import('fastify').FastifyInstance} fastify */
4
+ module.exports = async function (fastify, opts) {
5
+ fastify.get('/example', async (request, reply) => {
6
+ return { hello: fastify.example }
7
+ })
8
+ }
@@ -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,6 @@
1
+ /// <reference path="../global.d.ts" />
2
+ 'use strict'
3
+ /** @param {import('fastify').FastifyInstance} fastify */
4
+ module.exports = async function (fastify, opts) {
5
+ fastify.decorate('example', 'foobar')
6
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference path="../global.d.ts" />
2
+ 'use strict'
3
+ /** @param {import('fastify').FastifyInstance} fastify */
4
+ module.exports = async function (fastify, opts) {
5
+ fastify.get('/example', async (request, reply) => {
6
+ return { hello: fastify.example }
7
+ })
8
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "dependencies": {
3
+ "@platformatic/runtime": "workspace:*"
4
+ }
5
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/2.58.0.json",
3
+ "autoload": {
4
+ "path": "web"
5
+ },
6
+ "logger": {
7
+ "level": "error"
8
+ }
9
+ }
@@ -0,0 +1,2 @@
1
+ const nextConfig = {}
2
+ export default nextConfig
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "module",
3
+ "dependencies": {
4
+ "@platformatic/next": "workspace:*",
5
+ "next": "^15.3.0"
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/next/2.58.0.json",
3
+ "application": {
4
+ "basePath": "~PLT_BASE_PATH"
5
+ },
6
+ "next": {
7
+ "trailingSlash": true
8
+ }
9
+ }
@@ -0,0 +1,3 @@
1
+ export async function GET () {
2
+ return Response.json({ ok: true })
3
+ }
@@ -0,0 +1,7 @@
1
+ export default function RootLayout ({ children }) {
2
+ return (
3
+ <html lang='en'>
4
+ <body>{children}</body>
5
+ </html>
6
+ )
7
+ }
@@ -0,0 +1,3 @@
1
+ export default function Home () {
2
+ return <div>Hello from Next</div>
3
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "dependencies": {
3
+ "@platformatic/service": "^2.70.0"
4
+ }
5
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/service/2.44.0.json",
3
+ "server": {
4
+ "https": { "key": "key", "cert": "cert" }
5
+ },
6
+ "plugins": {
7
+ "paths": ["./routes"]
8
+ }
9
+ }
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ module.exports = async function (fastify) {
4
+ fastify.get('/example', async () => {
5
+ return { hello: 'world' }
6
+ })
7
+
8
+ fastify.get('/config', async () => {
9
+ return fastify.platformatic.config
10
+ })
11
+ }
@@ -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,5 @@
1
+ {
2
+ "dependencies": {
3
+ "@platformatic/service": "^2.70.0"
4
+ }
5
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/service/2.58.0.json",
3
+ "server": {
4
+ "https": {
5
+ "key": "key",
6
+ "cert": "cert"
7
+ }
8
+ },
9
+ "plugins": {
10
+ "paths": ["./routes"]
11
+ }
12
+ }
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ module.exports = async function (fastify) {
4
+ fastify.get('/example', async () => {
5
+ return { hello: 'world' }
6
+ })
7
+
8
+ fastify.get('/config', async () => {
9
+ return fastify.platformatic.config
10
+ })
11
+ }
@@ -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,7 @@
1
+ {
2
+ "dependencies": {
3
+ "@platformatic/runtime": "workspace:*",
4
+ "@foo/bar-1": "^1.0.0",
5
+ "missing": "^1.33.3"
6
+ }
7
+ }
@@ -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,5 @@
1
+ 'use strict'
2
+
3
+ module.exports = async function (fastify) {
4
+ throw new Error('This is a test error')
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "test-service-3",
3
+ "version": "1.0.0",
4
+ "private": true
5
+ }
@@ -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,8 @@
1
+ 'use strict'
2
+
3
+ module.exports = async function (fastify) {
4
+ fastify.get('/example', async (request, reply) => {
5
+ setTimeout(() => { process.exit(1) }, 500)
6
+ return { hello: 'world' }
7
+ })
8
+ }
@@ -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
+ })