pockethost 1.3.2 → 1.5.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 +27 -0
- package/package.json +7 -4
- package/readme.md +7 -6
- package/src/cli/commands/ServeCommand/index.ts +22 -6
- package/src/cli/index.ts +17 -2
- package/src/common/Logger.ts +8 -6
- package/src/common/plugin/action.ts +5 -0
- package/src/common/plugin/filter.ts +23 -0
- package/src/constants.ts +2 -8
- package/src/core/index.ts +1 -0
- package/src/core/logSettings.ts +7 -0
- package/src/instance-app/types/all.d.ts +3 -0
- package/src/instance-app/types/goja.d.ts +58 -0
- package/src/instance-app/types/lib.d.ts +5 -0
- package/src/instance-app/types/types.d.ts +19573 -0
- package/src/plugin.ts +36 -0
- package/src/server.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# pockethost
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5e9ed51: Added `--extra-plugins` global switch to temporarily load extra plugins from CLI
|
|
8
|
+
- 2376b0d: Add InstanceConfig filter, fix instance logger namespace, add core instance app lib
|
|
9
|
+
- 737b4b8: logSettings now exported from core
|
|
10
|
+
- 114b1d2: Add namespace() export to core Logger service
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 211fba6: Plugin authoring docs update
|
|
15
|
+
- 675e634: Added docs and updated maildev with plugin hook guards
|
|
16
|
+
- 3daf7f5: Fix: [INFO] logging prefixes
|
|
17
|
+
- 139468f: Updated documentation
|
|
18
|
+
- 1e5321b: Fix: improve plugin loading order
|
|
19
|
+
- Updated dependencies [517f602]
|
|
20
|
+
- @pockethost/plugin-launcher-spawn@0.3.0
|
|
21
|
+
- @pockethost/plugin-console-logger@0.2.1
|
|
22
|
+
- @pockethost/plugin-auto-admin@0.1.1
|
|
23
|
+
|
|
24
|
+
## 1.4.0
|
|
25
|
+
|
|
26
|
+
### Minor Changes
|
|
27
|
+
|
|
28
|
+
- b7e4323: Added ability for plugins to respond to `pockethost serve`
|
|
29
|
+
|
|
3
30
|
## 1.3.2
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pockethost",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Ben Allfree",
|
|
6
6
|
"url": "https://github.com/benallfree"
|
|
@@ -26,8 +26,10 @@
|
|
|
26
26
|
"express-async-errors": "^3.1.1",
|
|
27
27
|
"get-port": "^6.1.2",
|
|
28
28
|
"http-proxy": "^1.18.1",
|
|
29
|
+
"immer": "^10.1.1",
|
|
29
30
|
"json-stringify-safe": "^5.0.1",
|
|
30
31
|
"listr2": "^8.2.3",
|
|
32
|
+
"minimist": "^1.2.8",
|
|
31
33
|
"nanoid": "^5.0.2",
|
|
32
34
|
"node-fetch": "^3.3.2",
|
|
33
35
|
"pocketbase": "^0.21.3",
|
|
@@ -39,14 +41,15 @@
|
|
|
39
41
|
"typescript": "^5.4.5",
|
|
40
42
|
"update-notifier": "^7.0.0",
|
|
41
43
|
"url-pattern": "^1.0.3",
|
|
42
|
-
"@pockethost/plugin-
|
|
43
|
-
"@pockethost/plugin-
|
|
44
|
-
"@pockethost/plugin-
|
|
44
|
+
"@pockethost/plugin-auto-admin": "^0.1.1",
|
|
45
|
+
"@pockethost/plugin-console-logger": "^0.2.1",
|
|
46
|
+
"@pockethost/plugin-launcher-spawn": "^0.3.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@types/express": "^4.17.21",
|
|
48
50
|
"@types/http-proxy": "^1.17.13",
|
|
49
51
|
"@types/json-stringify-safe": "^5.0.2",
|
|
52
|
+
"@types/minimist": "^1.2.5",
|
|
50
53
|
"@types/node": "^20.8.10",
|
|
51
54
|
"@types/semver": "^7.5.4",
|
|
52
55
|
"@types/tmp": "^0.2.5",
|
package/readme.md
CHANGED
|
@@ -48,11 +48,12 @@ PocketHost uses a hook architecture and features a growing list plugins. Some pl
|
|
|
48
48
|
|
|
49
49
|
Current plugins:
|
|
50
50
|
|
|
51
|
-
| name
|
|
52
|
-
|
|
|
53
|
-
| plugin-console-logger
|
|
54
|
-
| plugin-auto-admin
|
|
55
|
-
| plugin-launcher-spawn
|
|
51
|
+
| name | description |
|
|
52
|
+
| -------------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
53
|
+
| plugin-console-logger | Routes log messages to the console |
|
|
54
|
+
| plugin-auto-admin | Auto-creates a default admin account on instance launch |
|
|
55
|
+
| plugin-launcher-spawn | Launches PocketBase instances via `spawn()` on the local machine. PocketHost uses this by default |
|
|
56
|
+
| plugin-cloudflare-request-logger | Log additional data when running behind Cloudflare |
|
|
56
57
|
|
|
57
58
|
Coming soon:
|
|
58
59
|
| name | description |
|
|
@@ -63,7 +64,7 @@ Coming soon:
|
|
|
63
64
|
| plugin-waf-enforce-ssl | Enforce SSL at the
|
|
64
65
|
WAF
|
|
65
66
|
|
|
66
|
-
See the [
|
|
67
|
+
See the [Plugin Authoring Guide](https://github.com/pockethost/pockethost/blob/master/packages/pockethost/plugin-guide.md) for details about what hooks and filters are available.
|
|
67
68
|
|
|
68
69
|
## Support
|
|
69
70
|
|
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
LoggerService,
|
|
4
|
+
doServeAction,
|
|
5
|
+
doServeSlugsFilter,
|
|
6
|
+
} from '../../../common'
|
|
4
7
|
|
|
5
8
|
type Options = {
|
|
6
|
-
|
|
9
|
+
only: string[]
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
export const ServeCommand = () => {
|
|
12
|
+
export const ServeCommand = async () => {
|
|
13
|
+
const serveSlugs = await doServeSlugsFilter([])
|
|
14
|
+
|
|
10
15
|
const cmd = new Command(`serve`)
|
|
11
16
|
.description(`Run PocketHost`)
|
|
12
|
-
.
|
|
17
|
+
.option(
|
|
18
|
+
`-o, --only <only>`,
|
|
19
|
+
`Only run the specified services`,
|
|
20
|
+
(s) =>
|
|
21
|
+
s
|
|
22
|
+
.split(/,/)
|
|
23
|
+
.map((s) => s.trim())
|
|
24
|
+
.filter((s) => serveSlugs.includes(s)),
|
|
25
|
+
serveSlugs,
|
|
26
|
+
)
|
|
27
|
+
.action(async (options: Options, cmd: Command) => {
|
|
13
28
|
const logger = LoggerService().create(`ServeCommand`)
|
|
14
29
|
const { dbg, error, info, warn } = logger
|
|
15
30
|
info(`Starting`)
|
|
16
31
|
|
|
17
|
-
|
|
32
|
+
const { only } = options
|
|
33
|
+
await doServeAction({ only })
|
|
18
34
|
})
|
|
19
35
|
return cmd
|
|
20
36
|
}
|
package/src/cli/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { uniq } from '@s-libs/micro-dash'
|
|
4
4
|
import { program } from 'commander'
|
|
5
5
|
import { readFileSync } from 'fs'
|
|
6
|
+
import minimist from 'minimist'
|
|
6
7
|
import updateNotifier from 'update-notifier'
|
|
7
8
|
import { PH_PLUGINS, PH_PROJECT_DIR } from '../../core'
|
|
8
9
|
import {
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
doCliCommandsFilter,
|
|
13
14
|
loadPlugins,
|
|
14
15
|
} from '../common'
|
|
16
|
+
import { pockethost } from '../plugin'
|
|
15
17
|
import { ConfigCommand } from './commands/ConfigCommand'
|
|
16
18
|
import { PluginCommand } from './commands/PluginCommand'
|
|
17
19
|
import { ServeCommand } from './commands/ServeCommand'
|
|
@@ -20,8 +22,11 @@ export const { dbg, info, error } = LoggerService({
|
|
|
20
22
|
level: DEBUG() ? LogLevelName.Debug : LogLevelName.Info,
|
|
21
23
|
})
|
|
22
24
|
|
|
25
|
+
export type GlobalOptions = {
|
|
26
|
+
extraPlugins: string[]
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
export const main = async () => {
|
|
24
|
-
await loadPlugins(uniq(PH_PLUGINS()))
|
|
25
30
|
const pkg = await JSON.parse(
|
|
26
31
|
readFileSync(PH_PROJECT_DIR(`package.json`), 'utf8').toString(),
|
|
27
32
|
)
|
|
@@ -29,13 +34,23 @@ export const main = async () => {
|
|
|
29
34
|
|
|
30
35
|
const { version } = pkg
|
|
31
36
|
|
|
37
|
+
const argv = minimist<{ e: string }>(process.argv.slice(2), {
|
|
38
|
+
alias: { e: 'extra-plugins' },
|
|
39
|
+
})
|
|
40
|
+
const extraPlugins = argv.e
|
|
41
|
+
.split(/,/)
|
|
42
|
+
.map((s) => s.trim())
|
|
43
|
+
.filter((v) => !!v)
|
|
44
|
+
await loadPlugins([pockethost, ...uniq(PH_PLUGINS()), ...extraPlugins])
|
|
45
|
+
|
|
32
46
|
program
|
|
33
47
|
.name('pockethost')
|
|
34
48
|
.description('Multitenant PocketBase hosting')
|
|
35
49
|
.version(version)
|
|
50
|
+
.option(`-e, --extra-plugins <plugins...>`, `Extra plugins to load`, [])
|
|
36
51
|
|
|
37
52
|
const commands = await doCliCommandsFilter([
|
|
38
|
-
ServeCommand(),
|
|
53
|
+
await ServeCommand(),
|
|
39
54
|
ConfigCommand(),
|
|
40
55
|
PluginCommand(),
|
|
41
56
|
])
|
package/src/common/Logger.ts
CHANGED
|
@@ -53,6 +53,12 @@ export const LogLevels = {
|
|
|
53
53
|
[LogLevelName.Abort]: 6,
|
|
54
54
|
} as const
|
|
55
55
|
|
|
56
|
+
export const namespace = (...names: string[]) =>
|
|
57
|
+
names
|
|
58
|
+
.filter((v) => !!v)
|
|
59
|
+
.map((p) => `[${p}]`)
|
|
60
|
+
.join(' ')
|
|
61
|
+
|
|
56
62
|
export const createLogger = (config: Partial<LoggerConfig>) => {
|
|
57
63
|
const _config = mergeConfig<LoggerConfig>(
|
|
58
64
|
{
|
|
@@ -67,11 +73,7 @@ export const createLogger = (config: Partial<LoggerConfig>) => {
|
|
|
67
73
|
_config.level = level
|
|
68
74
|
}
|
|
69
75
|
|
|
70
|
-
const _pfx = (s: string) =>
|
|
71
|
-
[s, ...pfx]
|
|
72
|
-
.filter((v) => !!v)
|
|
73
|
-
.map((p) => `[${p}]`)
|
|
74
|
-
.join(' ')
|
|
76
|
+
const _pfx = (s: string) => namespace(s, ...pfx)
|
|
75
77
|
|
|
76
78
|
const _log = (levelIn: LogLevelName, ...args: any[]) => {
|
|
77
79
|
doLogAction({
|
|
@@ -96,7 +98,7 @@ export const createLogger = (config: Partial<LoggerConfig>) => {
|
|
|
96
98
|
const info = (...args: any[]) => {
|
|
97
99
|
const _args = (() => {
|
|
98
100
|
if (isLevelGt(LogLevelName.Info, _config.level)) {
|
|
99
|
-
return [chalk.gray(`INFO`), ...args]
|
|
101
|
+
return [_pfx(chalk.gray(`INFO`)), ...args]
|
|
100
102
|
}
|
|
101
103
|
return [...args]
|
|
102
104
|
})()
|
|
@@ -5,6 +5,7 @@ import { InstanceFields } from '../schema'
|
|
|
5
5
|
|
|
6
6
|
enum CoreActions {
|
|
7
7
|
Init = 'core_init',
|
|
8
|
+
Serve = 'core_serve',
|
|
8
9
|
AppMounted = 'core_on_app_mount',
|
|
9
10
|
AfterServeStart = 'core_after_serve_start',
|
|
10
11
|
|
|
@@ -125,3 +126,7 @@ export const [doAfterInstanceStoppedAction, onAfterInstanceStoppedAction] =
|
|
|
125
126
|
createCustomActionWithContext<{ instance: InstanceFields; url: string }>(
|
|
126
127
|
CoreActions.AfterInstanceStopped,
|
|
127
128
|
)
|
|
129
|
+
|
|
130
|
+
export const [doServeAction, onServeAction] = createCustomActionWithContext<{
|
|
131
|
+
only: string[]
|
|
132
|
+
}>(CoreActions.Serve)
|
|
@@ -5,9 +5,11 @@ import { InstanceFields, InstanceId } from '../schema'
|
|
|
5
5
|
|
|
6
6
|
export enum CoreFilters {
|
|
7
7
|
CliCommands = 'core_cli_commands',
|
|
8
|
+
ServeSlugs = 'core_serve_slugs',
|
|
8
9
|
SpawnConfig = 'core_spawn_config',
|
|
9
10
|
GetInstanceByRequestInfo = 'core_get_instance_by_request_info',
|
|
10
11
|
GetInstanceById = 'core_get_instance_by_id',
|
|
12
|
+
InstanceConfig = 'core_instance_config',
|
|
11
13
|
ErrorSpawningInstanceMessage = 'core_error_spawning_instance_message',
|
|
12
14
|
FailedToLaunchInstanceMessage = 'core_failed_to_launch_instance_message',
|
|
13
15
|
AuthenticateRequest = 'core_authenticate_request',
|
|
@@ -113,3 +115,24 @@ export const [
|
|
|
113
115
|
instance: InstanceFields
|
|
114
116
|
}
|
|
115
117
|
>(CoreFilters.GetOrProvisionInstanceUrl)
|
|
118
|
+
|
|
119
|
+
export const [doServeSlugsFilter, onServeSlugsFilter] = createCustomFilter<
|
|
120
|
+
string[]
|
|
121
|
+
>(CoreFilters.ServeSlugs)
|
|
122
|
+
|
|
123
|
+
export type Bind = {
|
|
124
|
+
base: string
|
|
125
|
+
src: string
|
|
126
|
+
}
|
|
127
|
+
export type Binds = {
|
|
128
|
+
data: Bind[]
|
|
129
|
+
hooks: Bind[]
|
|
130
|
+
migrations: Bind[]
|
|
131
|
+
public: Bind[]
|
|
132
|
+
}
|
|
133
|
+
export type InstanceConfig = {
|
|
134
|
+
binds: Binds
|
|
135
|
+
env: { [_: string]: string }
|
|
136
|
+
}
|
|
137
|
+
export const [doInstanceConfigFilter, onInstanceConfigFilter] =
|
|
138
|
+
createCustomFilter<InstanceConfig>(CoreFilters.InstanceConfig)
|
package/src/constants.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { forEach } from '@s-libs/micro-dash'
|
|
2
1
|
import { config } from 'dotenv'
|
|
3
2
|
import envPaths from 'env-paths'
|
|
4
3
|
import { dirname, join } from 'path'
|
|
@@ -8,6 +7,7 @@ import { mkBoolean, mkCsvString, mkNumber, mkPath, mkString } from '../core'
|
|
|
8
7
|
import { InstanceId } from './common'
|
|
9
8
|
import { DEBUG, IS_DEV } from './common/debug'
|
|
10
9
|
import { Settings } from './core/Settings'
|
|
10
|
+
import { logSettings } from './core/logSettings'
|
|
11
11
|
|
|
12
12
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
13
13
|
|
|
@@ -58,12 +58,6 @@ export const NODE_ENV = () => process.env.NODE_ENV
|
|
|
58
58
|
export const INSTANCE_DATA_DIR = (id: InstanceId, ...paths: string[]) =>
|
|
59
59
|
join(DATA_DIR(), id, ...paths)
|
|
60
60
|
|
|
61
|
-
export const logConstants = () => {
|
|
62
|
-
forEach(settings, (v, k) => {
|
|
63
|
-
console.log(`${k}: ${v}`)
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
61
|
if (DEBUG()) {
|
|
68
|
-
|
|
62
|
+
logSettings(settings)
|
|
69
63
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
interface Require {
|
|
2
|
+
(id: string): any
|
|
3
|
+
}
|
|
4
|
+
declare var require: Require
|
|
5
|
+
|
|
6
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console) */
|
|
7
|
+
interface Console {
|
|
8
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/assert) */
|
|
9
|
+
assert(condition?: boolean, ...data: any[]): void
|
|
10
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/clear) */
|
|
11
|
+
clear(): void
|
|
12
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/count) */
|
|
13
|
+
count(label?: string): void
|
|
14
|
+
/**
|
|
15
|
+
* [MDN
|
|
16
|
+
* Reference](https://developer.mozilla.org/docs/Web/API/console/countReset)
|
|
17
|
+
*/
|
|
18
|
+
countReset(label?: string): void
|
|
19
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/debug) */
|
|
20
|
+
debug(...data: any[]): void
|
|
21
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dir) */
|
|
22
|
+
dir(item?: any, options?: any): void
|
|
23
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dirxml) */
|
|
24
|
+
dirxml(...data: any[]): void
|
|
25
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/error) */
|
|
26
|
+
error(...data: any[]): void
|
|
27
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/group) */
|
|
28
|
+
group(...data: any[]): void
|
|
29
|
+
/**
|
|
30
|
+
* [MDN
|
|
31
|
+
* Reference](https://developer.mozilla.org/docs/Web/API/console/groupCollapsed)
|
|
32
|
+
*/
|
|
33
|
+
groupCollapsed(...data: any[]): void
|
|
34
|
+
/**
|
|
35
|
+
* [MDN
|
|
36
|
+
* Reference](https://developer.mozilla.org/docs/Web/API/console/groupEnd)
|
|
37
|
+
*/
|
|
38
|
+
groupEnd(): void
|
|
39
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/info) */
|
|
40
|
+
info(...data: any[]): void
|
|
41
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log) */
|
|
42
|
+
log(...data: any[]): void
|
|
43
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/table) */
|
|
44
|
+
table(tabularData?: any, properties?: string[]): void
|
|
45
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/time) */
|
|
46
|
+
time(label?: string): void
|
|
47
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeEnd) */
|
|
48
|
+
timeEnd(label?: string): void
|
|
49
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeLog) */
|
|
50
|
+
timeLog(label?: string, ...data: any[]): void
|
|
51
|
+
timeStamp(label?: string): void
|
|
52
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/trace) */
|
|
53
|
+
trace(...data: any[]): void
|
|
54
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/warn) */
|
|
55
|
+
warn(...data: any[]): void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare var console: Console
|