pockethost 1.0.0-rc.1

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 (44) hide show
  1. package/LICENSE.md +16 -0
  2. package/dist/index.mjs +3156 -0
  3. package/dist/instance-app/migrations/1699198734_pockethost_defaults.js +39 -0
  4. package/dist/instance-app/pb_hooks/_ph_admin_sync.pb.js +71 -0
  5. package/dist/instance-app/pb_hooks/_ph_lib.js +19 -0
  6. package/dist/instance-app/tsconfig.json +8 -0
  7. package/dist/instance-app/types/goja.d.ts +58 -0
  8. package/dist/instance-app/types/lib.d.ts +5 -0
  9. package/dist/instance-app/types/types.d.ts +19573 -0
  10. package/dist/mothership-app/migrations/1705062576_collections_snapshot.js +1863 -0
  11. package/dist/mothership-app/migrations/1705083826_updated_stats.js +721 -0
  12. package/dist/mothership-app/migrations/1706060446_updated_instances.js +44 -0
  13. package/dist/mothership-app/pb_hooks/src/instances-create.pb.js +65 -0
  14. package/dist/mothership-app/pb_hooks/src/instances-delete.pb.js +69 -0
  15. package/dist/mothership-app/pb_hooks/src/instances-migrate-versions.pb.js +33 -0
  16. package/dist/mothership-app/pb_hooks/src/instances-notify-discord-after-create.pb.js +31 -0
  17. package/dist/mothership-app/pb_hooks/src/instances-notify-on-maintenance-mode.pb.js +52 -0
  18. package/dist/mothership-app/pb_hooks/src/instances-reset-idle.pb.js +7 -0
  19. package/dist/mothership-app/pb_hooks/src/instances-update.pb.js +121 -0
  20. package/dist/mothership-app/pb_hooks/src/instances-validate-before-create.pb.js +16 -0
  21. package/dist/mothership-app/pb_hooks/src/instances-validate-before-update.pb.js +43 -0
  22. package/dist/mothership-app/pb_hooks/src/lib.js +171 -0
  23. package/dist/mothership-app/pb_hooks/src/ls.pb.js +159 -0
  24. package/dist/mothership-app/pb_hooks/src/mail.pb.js +49 -0
  25. package/dist/mothership-app/pb_hooks/src/notifications.pb.js +62 -0
  26. package/dist/mothership-app/pb_hooks/src/random-words.js +2085 -0
  27. package/dist/mothership-app/pb_hooks/src/signup.pb.js +214 -0
  28. package/dist/mothership-app/pb_hooks/src/sns.pb.js +133 -0
  29. package/dist/mothership-app/pb_hooks/src/unsubscribe.pb.js +33 -0
  30. package/dist/mothership-app/pb_hooks/src/user-token.pb.js +33 -0
  31. package/dist/mothership-app/pb_hooks/src/user-welcome-msg.pb.js +32 -0
  32. package/dist/mothership-app/pb_hooks/src/versions-route.pb.js +12 -0
  33. package/dist/mothership-app/pb_hooks/src/versions.js +0 -0
  34. package/dist/mothership-app/pb_hooks/tsconfig.json +8 -0
  35. package/dist/mothership-app/pb_hooks/types/global.d.ts +1 -0
  36. package/dist/mothership-app/pb_hooks/types/goja.d.ts +58 -0
  37. package/dist/mothership-app/pb_hooks/types/lemon.d.ts +12 -0
  38. package/dist/mothership-app/pb_hooks/types/lib.d.ts +55 -0
  39. package/dist/mothership-app/pb_hooks/types/types.d.ts +19573 -0
  40. package/dist/mothership-app/ph_app/index.js +11 -0
  41. package/dist/mothership-app/ph_app/package-lock.json +657 -0
  42. package/dist/mothership-app/ph_app/package.json +14 -0
  43. package/package.json +144 -0
  44. package/readme.md +168 -0
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "ph_app",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "express": "^4.18.2"
13
+ }
14
+ }
package/package.json ADDED
@@ -0,0 +1,144 @@
1
+ {
2
+ "name": "pockethost",
3
+ "version": "1.0.0-rc.1",
4
+ "author": {
5
+ "name": "Ben Allfree",
6
+ "url": "https://github.com/benallfree"
7
+ },
8
+ "license": "MIT",
9
+ "main": "dist/index.mjs",
10
+ "scripts": {
11
+ "check:types": "concurrently 'pnpm:check:types:*'",
12
+ "check:types:dashboard": "cd frontends/dashboard && pnpm check:types",
13
+ "check:types:pockethost": "tsc --noEmit --skipLibCheck",
14
+ "lint": "prettier -c \"./**/*.{ts,js,cjs,svelte,json}\"",
15
+ "lint:fix": "prettier -w \"./**/*.{ts,js,cjs,svelte,json}\"",
16
+ "download-versions": "tsx ./src/cli/download.ts",
17
+ "build": "concurrently 'pnpm:build:*'",
18
+ "build-cli": "tsx build.ts",
19
+ "build-frontends": "concurrently 'pnpm:build:frontend:*'",
20
+ "build:frontend:dashboard": "cd frontends/dashboard && pnpm build",
21
+ "build:docker": "cd src/services/PocketBaseService && docker build . -t pockethost-instance",
22
+ "build:frontend:lander": "cd frontends/lander && pnpm build",
23
+ "build:frontend:superadmin": "cd frontends/superadmin && pnpm build",
24
+ "dev": "NODE_ENV=development concurrently 'pnpm:dev:*'",
25
+ "dev-cli": "nodemon --signal SIGTERM dist/index.mjs",
26
+ "dev:lander": "cd frontends/lander && pnpm start",
27
+ "dev:dashboard": "cd frontends/dashboard && pnpm dev",
28
+ "dev:superadmin": "cd frontends/superadmin && pnpm dev",
29
+ "prod:proxy": "dotenv tsx ./src/cli/proxy/server.ts",
30
+ "prod:edge:daemon": "tsx src/cli/edge-daemon.ts",
31
+ "prod:edge:ftp": "tsx src/cli/edge-ftp.ts",
32
+ "prod:edge:health": "tsx src/cli/edge-health.ts",
33
+ "prod:edge:syslog": "tsx src/cli/edge-syslogd.ts",
34
+ "prod:mothership": "tsx src/cli/mothership.ts",
35
+ "plop": "plop",
36
+ "nofile": "cat /proc/sys/fs/file-nr",
37
+ "mail": "tsx ./src/cli/sendmail.ts",
38
+ "watch": "node build.cjs"
39
+ },
40
+ "prettier": {
41
+ "semi": false,
42
+ "useTabs": false,
43
+ "singleQuote": true,
44
+ "trailingComma": "all",
45
+ "plugins": [
46
+ "./node_modules/prettier-plugin-organize-imports/index.js",
47
+ "./node_modules/prettier-plugin-svelte/plugin.js",
48
+ "./node_modules/prettier-plugin-jsdoc/dist/index.js"
49
+ ]
50
+ },
51
+ "type": "module",
52
+ "dependencies": {
53
+ "@s-libs/micro-dash": "^16.1.0",
54
+ "@types/node-os-utils": "^1.3.4",
55
+ "@types/winston-syslog": "^2.4.3",
56
+ "ajv": "^8.12.0",
57
+ "boolean": "^3.2.0",
58
+ "bottleneck": "^2.19.5",
59
+ "commander": "^11.1.0",
60
+ "cors": "^2.8.5",
61
+ "decompress": "^4.2.1",
62
+ "decompress-unzip": "https://github.com/pockethost/decompress-unzip.git#6ef397b9a2df11d39c7b26ce779e123833844751",
63
+ "dockerode": "^3.3.5",
64
+ "dotenv": "^16.3.1",
65
+ "event-source-polyfill": "^1.0.31",
66
+ "eventsource": "^2.0.2",
67
+ "exit-hook": "^4.0.0",
68
+ "express": "^4.18.2",
69
+ "express-async-errors": "^3.1.1",
70
+ "find-up": "^6.3.0",
71
+ "ftp-srv": "github:pockethost/ftp-srv#0fc708bae0d5d7a55ce948767f082d6fcfb2af59",
72
+ "get-port": "^6.1.2",
73
+ "glob": "^10.3.10",
74
+ "http-proxy": "^1.18.1",
75
+ "http-proxy-middleware": "^2.0.6",
76
+ "ip-cidr": "^3.1.0",
77
+ "json-stringify-safe": "^5.0.1",
78
+ "knex": "^2.5.1",
79
+ "memorystream": "^0.3.1",
80
+ "nanoid": "^5.0.2",
81
+ "node-fetch": "^3.3.2",
82
+ "node-os-utils": "^1.3.7",
83
+ "pocketbase": "^0.20.1",
84
+ "semver": "^7.5.4",
85
+ "sqlite3": "^5.1.6",
86
+ "syslog-parse": "^2.0.0",
87
+ "tail": "^2.2.6",
88
+ "tmp": "^0.2.1",
89
+ "url-pattern": "^1.0.3",
90
+ "vhost": "^3.0.2",
91
+ "winston": "^3.11.0",
92
+ "winston-syslog": "^2.7.0"
93
+ },
94
+ "devDependencies": {
95
+ "@swc/cli": "^0.1.62",
96
+ "@swc/core": "^1.3.95",
97
+ "@types/bootstrap": "^5.2.8",
98
+ "@types/copyfiles": "^2.4.4",
99
+ "@types/cors": "^2.8.17",
100
+ "@types/d3-scale": "^4.0.6",
101
+ "@types/d3-scale-chromatic": "^3.0.1",
102
+ "@types/decompress": "^4.2.6",
103
+ "@types/dockerode": "^3.3.21",
104
+ "@types/eventsource": "^1.1.14",
105
+ "@types/express": "^4.17.21",
106
+ "@types/http-proxy": "^1.17.13",
107
+ "@types/js-cookie": "^3.0.5",
108
+ "@types/json-stringify-safe": "^5.0.2",
109
+ "@types/marked": "^4.3.2",
110
+ "@types/memorystream": "^0.3.3",
111
+ "@types/ncp": "^2.0.8",
112
+ "@types/node": "^20.8.10",
113
+ "@types/semver": "^7.5.4",
114
+ "@types/tail": "^2.2.2",
115
+ "@types/tmp": "^0.2.5",
116
+ "@types/unzipper": "^0.10.8",
117
+ "@types/vhost": "^3.0.9",
118
+ "chalk": "^5.3.0",
119
+ "chokidar-cli": "^3.0.0",
120
+ "concurrently": "^8.2.2",
121
+ "copyfiles": "^2.4.1",
122
+ "date-fns": "^2.30.0",
123
+ "dotenv-cli": "^7.3.0",
124
+ "esbuild": "^0.20.0",
125
+ "esbuild-node-externals": "^1.13.0",
126
+ "js-yaml": "^4.1.0",
127
+ "ncp": "^2.0.0",
128
+ "nodemon": "^3.0.3",
129
+ "ora": "^7.0.1",
130
+ "plop": "^4.0.0",
131
+ "postinstall-postinstall": "^2.1.0",
132
+ "prettier": "^3.0.3",
133
+ "prettier-plugin-jsdoc": "^1.3.0",
134
+ "prettier-plugin-organize-imports": "^3.2.3",
135
+ "prettier-plugin-svelte": "^3.0.3",
136
+ "rizzdown": "^0.0.6",
137
+ "svelte": "^4.2.2",
138
+ "tslib": "^2.6.2",
139
+ "tsx": "^3.14.0",
140
+ "type-fest": "^4.6.0",
141
+ "typescript": "^5.2.2"
142
+ },
143
+ "packageManager": "pnpm@8.10.2"
144
+ }
package/readme.md ADDED
@@ -0,0 +1,168 @@
1
+ # pockethost.io
2
+
3
+ ## Introduction
4
+
5
+ PocketHost is the open source cloud hosting platform for PocketBase. https://pockethost.io is the flagship service running PocketHost, where you can host your PocketBase projects with zero setup. Create a project like you would in Firebase and Supabase and let PocketHost do the rest.
6
+
7
+ Features:
8
+
9
+ - Create unlimited PocketBase instances
10
+ - Each instance runs on a subdomain of `pockethost.io`
11
+ - Run your instance in an ultra-beefy shared environment
12
+
13
+ **Focus on your app**
14
+
15
+ Get a live PocketBase instance in 10 seconds with no backend setup:
16
+
17
+ 1. Create an account at pockethost.io
18
+ 2. Provision your first PocketBase instance
19
+ 3. Connect from anywhere
20
+
21
+ ```ts
22
+ const client = new PocketBase(`https://harvest.pockethost.io`)
23
+ ```
24
+
25
+ **Batteries Included**
26
+
27
+ Here's all the Linux/devops stuff that PocketHost does for you:
28
+
29
+ - Email and DKIM+SPF and more
30
+ - DNS jargon: MX, TXT, CNAME
31
+ - SSL cert provisioning and management
32
+ - Storage
33
+ - Volume mounts
34
+ - Cloud computing or VPS deployment
35
+ - CDN and static asset hosting
36
+ - Amazon AWS
37
+ - Lots more - scaling, firewalls, DDoS defense, user security, log rotation, patches, updates, build tools, CPU architectures, multitenancy, on and on
38
+
39
+ PocketHost is free and open source project licensed under the MIT License.
40
+
41
+ This monorepo contains the entire open source stack that powers pockethost.io. You can use it to run your own private or public multitenant platform.
42
+
43
+ **Questions?**
44
+
45
+ Head over to Discord and ask away.
46
+
47
+ ## Frontend only
48
+
49
+ If you just want to work on the UI/frontend client apps, they are configured to connect to pockethost.io out of the box. This is the most convenient way to make UI modifications to the PocketHost project.
50
+
51
+ ```bash
52
+ git clone git@github.com:benallfree/pockethost.git
53
+ cd pockethost
54
+ pnpm
55
+ pnpm dev:lander # Marketing/blog area
56
+ pnpm dev:dashboard # Dashboard/control panel
57
+ ```
58
+
59
+ ## All our base
60
+
61
+ **Running in dev mode**
62
+
63
+ Note for OS X users: if the `pocketbase` binaries do not run, it's probably your [security settings](https://support.apple.com/guide/mac-help/open-a-mac-app-from-an-unidentified-developer-mh40616/mac).
64
+
65
+ **Prerequisites**
66
+
67
+ Local PocketHost development relies on Caddy to create reverse proxies into the various services powering the PocketHost backend. We use `lvh.me` to work with subdomains that resolve to localhost.
68
+
69
+ ```bash
70
+ brew install caddy
71
+ ```
72
+
73
+ Then:
74
+
75
+ ```bash
76
+ git clone git@github.com:benallfree/pockethost.git
77
+ cd pockethost
78
+ pnpm
79
+ cp .env-template .env
80
+ ```
81
+
82
+ `.env-template` is preconfigured to make all of PocketHost run locally using `lvh.me` as follows:
83
+
84
+ ```bash
85
+ pnpm dev
86
+
87
+ # marketing/blog
88
+ open https://pockethost.lvh.me
89
+
90
+ # dashboard
91
+ open https://app.pockethost.lvh.me
92
+
93
+ # mothership
94
+ open https://pockethost-central.pockethost.lvh.me
95
+
96
+ # sample edge server (ph1)
97
+ open https://instance1.ph1.edge.pockethost.lvh.me
98
+
99
+ # second edge server (ph2)
100
+ open https://instance2.ph2.edge.pockethost.lvh.me
101
+ ```
102
+
103
+ Additionally, the setup creates the following users and instances:
104
+
105
+ **Admin**
106
+ https://pockethost-central.pockethost.lvh.me
107
+ login: `admin@pockethost.lvh.me`
108
+ password: `password`
109
+
110
+ **User**
111
+ https://app.pockethost.lvh.me
112
+ login: `user@pockethost.lvh.me`
113
+ password: `password`
114
+
115
+ The user `user@pockethost.lvh.me` owns `instance1` and `instance2`, each which is running in its own region on separate edge servers.
116
+
117
+ That's it! You can control all this and much more from the `.env-template` file. It's fully documented, but here it is again just in case.
118
+
119
+ ## Public Variables (available to frontend and backend)
120
+
121
+ | Name | Default | Discussion |
122
+ | ----------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
123
+ | PUBLIC_DEBUG | `true` | The global debugging variable, used by both frontends and backend services. |
124
+ | PUBLIC_HTTP_PROTOCOL | `https` | You can use `http` if you like, but there is really no reason to. Caddy automatically provisions SSL certificates even for local development, and Cloudflare (recommended for DNS and CDN) does too. |
125
+ | PUBLIC_APEX_DOMAIN | `pockethost.lvh.me` | The apex domain is the domain on which all other subdomains live. If you set up your own PocketHost-based service, you'll want to change this. If you're just focusing on contributing to the project (please do!), then you can leave this as-is. |
126
+ | PUBLIC_APP_DOMAIN | `app.<apex>` | The fully qualified domain on which the dashboard/control panel lives (app). Probably no reason to alter this, as it defaults to `app` on the apex domain defined earlier. |
127
+ | PUBLIC_BLOG_DOMAIN | `<apex>` | The marketing/blog site lives on `<apex>` itself. |
128
+ | PUBLIC_EDGE_APEX_DOMAIN | `<id>.edge.<apex>` | Edge servers are the work horses of PocketHost. They receive incoming requests and route them to PocketBase instances. Each edge server needs a unique `<id>`, which are generally named after geographic regions such as `sfo-1`, `nyc-2`, etc. |
129
+ | PUBLIC_MOTHERSHIP_URL | `pockethost-central.<apex>` | The mothership URL is configurable because there may be cases where you want to deploy the mothership to its own central region. It does not live on an edge node. |
130
+
131
+ ## Mothership Variables (backend only)
132
+
133
+ The Mothership is a set of backend services, including a central `pocketbase` instance, that is the source of truth for the state of PocketHost.
134
+
135
+ | Name | Default | Discussion |
136
+ | ------------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
137
+ | MOTHERSHIP_MIGRATIONS_DIR | `<root>/src/mothership-app/migrations` | The directory where the Mothership migrations live. This is typically kept in revision control, so the default location is within the project directory structure. |
138
+ | MOTHERSHIP_HOOKS_DIR | `<root>/src/mothership-app/pb_hooks` | The directory where the Mothership `pb_hooks` live. This is typically kept in revision control, so the default location is within the project directory structure. |
139
+ | MOTHERSHIP_ADMIN_USERNAME | `admin@pockethost.lvh.me` | This admin login is created the first time PocketHost runs. |
140
+ | MOTHERSHIP_ADMIN_PASSWORD | `password` | |
141
+ | DEMO_USER_USERNAME | `user@pockethost.lvh.me` | This login is created the first time PocketHost runs |
142
+ | DEMO_USER_PASSWORD | `password` | |
143
+ | MOTHERSHIP_PORT | `8091` | The port the Mothership service will listen on. |
144
+ | MOTHERSHIP_SEMVER | `(blank)` | The semver used to lock the Mothership to a specific `pocketbase` version range. The Mothership will never launch with a `pocketbase` binary version outside this range. |
145
+ | MOTHERSHIP_PRIVATE_URL | `http://mothership.pockdthost.lvh.me` | This should be set to an intranet IP address in production settings. |
146
+
147
+ ## Edge Variables (backend only)
148
+
149
+ An Edge node is the workhorse of PocketHost. Edge nodes manage `pocketbase` instances, spin them up, shut them down when idle, implement security, and afford regional access to instances. They communicate with the Mothership through `MOTHERSHIP_PRIVATE_URL`.
150
+
151
+ | Name | Default | Discussion |
152
+ | -------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
153
+ | EDGE_DATA_ROOT | `<root>/.data` | Where the edge node should store its pocketbase instance data |
154
+ | EDGE_INSTANCE_MIN_IDLE_TTL | `5000` | The minimum amount of time an instance must remain idle (no connections) before an edge node is allowed to shut it down to free up resources |
155
+ | EDGE_INSTANCE_POOL_SIZE | `20` | The maximum number of simultaneous instances the edge node will allow to run concurrently. If this limit is exceeded, connections to instances not yet running in the pool will be denied. |
156
+ | \*\*IP_CIDR | `(blank)` | A comma-separated list of upstream proxy IP addresses or ranges PocketHost will respond to. |
157
+
158
+ \* Note: `PUBLIC_*` environment variables are visible to the frontend as well.
159
+
160
+ \*\* Note: [Cloudflare IP addresses](https://www.cloudflare.com/ips/) are currently: `173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/13,104.24.0.0/14,172.64.0.0/13,131.0.72.0/22`. [Learn more about IP CIDR](https://developers.cloudflare.com/fundamentals/setup/allow-cloudflare-ip-addresses/).
161
+
162
+ ## Security Variables (backend only)
163
+
164
+ | Name | Default | Discussion |
165
+ | ------- | --------- | ------------------------------------------------------------------------------------------- |
166
+ | IP_CIDR | `(blank)` | A comma-separated list of upstream proxy IP addresses or ranges PocketHost will respond to. |
167
+
168
+ Note: [Cloudflare IP addresses](https://www.cloudflare.com/ips/) are currently: `173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/13,104.24.0.0/14,172.64.0.0/13,131.0.72.0/22`. [Learn more about IP CIDR](https://developers.cloudflare.com/fundamentals/setup/allow-cloudflare-ip-addresses/).