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,39 @@
1
+ migrate(
2
+ (db) => {
3
+ try {
4
+ const APP_DEFAULTS = {
5
+ appName: 'Acme',
6
+ appUrl: 'http://localhost:8090',
7
+ senderName: 'Support',
8
+ senderAddress: 'support@example.com',
9
+ }
10
+
11
+ const { PH_APP_NAME, PH_INSTANCE_URL, PH_APEX_DOMAIN } = process.env
12
+
13
+ const dao = new Dao(db)
14
+
15
+ const settings = dao.findSettings()
16
+ if (!settings) {
17
+ throw new Error(`Expected settings here`)
18
+ }
19
+
20
+ const fix = (field, newValue) => {
21
+ if (!newValue || settings.meta[field] !== APP_DEFAULTS[field]) return
22
+ settings.meta[field] = newValue
23
+ }
24
+ fix(`appName`, PH_APP_NAME)
25
+ fix(`appUrl`, PH_INSTANCE_URL)
26
+ fix(`senderName`, PH_APP_NAME)
27
+ fix(`senderAddress`, `${PH_APP_NAME}@app.pockethost.io`)
28
+
29
+ dao.saveSettings(settings)
30
+
31
+ console.log(`***defaults successfully applied`)
32
+ } catch (e) {
33
+ console.error(`***error applying defaults: ${e}`)
34
+ }
35
+ },
36
+ (db) => {
37
+ // add down queries...
38
+ },
39
+ )
@@ -0,0 +1,71 @@
1
+ $app.onBeforeServe().add((e) => {
2
+ const dao = $app.dao()
3
+ const { mkLog } = /** @type {Lib} */ (require(`${__hooks}/_ph_lib.js`))
4
+
5
+ const log = mkLog(`admin-sync`)
6
+
7
+ const { id, email, tokenKey, passwordHash } = (() => {
8
+ try {
9
+ return /** @type{{id:string, email:string, tokenKey:string,passwordHash:string}} */ (
10
+ JSON.parse($os.getenv(`ADMIN_SYNC`))
11
+ )
12
+ } catch (e) {
13
+ return { id: '', email: '', tokenKey: '', passwordHash: '' }
14
+ }
15
+ })()
16
+
17
+ if (!email) {
18
+ log(`Not active - skipped`)
19
+ return
20
+ }
21
+
22
+ const result = new DynamicModel({
23
+ // describe the shape of the data (used also as initial values)
24
+ id: '',
25
+ })
26
+
27
+ try {
28
+ dao
29
+ .db()
30
+ .newQuery('SELECT * from _admins where email = {:email}')
31
+ .bind({ email })
32
+ .one(result)
33
+ log(
34
+ `Existing admin record matching PocketHost login found - updating with latest credentials`,
35
+ )
36
+ try {
37
+ dao
38
+ .db()
39
+ .newQuery(
40
+ 'update _admins set tokenKey={:tokenKey}, passwordHash={:passwordHash} where email={:email}',
41
+ )
42
+ .bind({ email, tokenKey, passwordHash })
43
+ .execute()
44
+ log(`Success`)
45
+ } catch (e) {
46
+ log(`Failed to update admin credentials: ${e}`)
47
+ }
48
+ } catch (e) {
49
+ log(`No admin record matching PocketHost credentials - creating`)
50
+
51
+ try {
52
+ dao
53
+ .db()
54
+ .newQuery(
55
+ 'insert into _admins (id,email, tokenKey, passwordHash) VALUES ({:id}, {:email}, {:tokenKey}, {:passwordHash})',
56
+ )
57
+ .bind({
58
+ id,
59
+ email,
60
+ tokenKey,
61
+ passwordHash,
62
+ created: new Date().toISOString(),
63
+ updated: new Date().toISOString(),
64
+ })
65
+ .execute()
66
+ log(`Success`)
67
+ } catch (e) {
68
+ log(`Failed to insert admin credentials: ${e}`)
69
+ }
70
+ }
71
+ })
@@ -0,0 +1,19 @@
1
+ /** @type {Lib['mkLog']} */
2
+ const mkLog =
3
+ (namespace) =>
4
+ /**
5
+ * @param {...any} s
6
+ * @returns
7
+ */
8
+ (...s) =>
9
+ console.log(
10
+ `[${namespace}]`,
11
+ ...s.map((p) => {
12
+ if (typeof p === 'object') return JSON.stringify(p, null, 2)
13
+ return p
14
+ }),
15
+ )
16
+
17
+ module.exports = {
18
+ mkLog,
19
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "noImplicitAny": false,
5
+ "strictNullChecks": false
6
+ },
7
+ "include": ["pb_hooks", "types"]
8
+ }
@@ -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
@@ -0,0 +1,5 @@
1
+ type Logger = (...args: any[]) => void
2
+
3
+ interface Lib {
4
+ mkLog: (namespace: string) => Logger
5
+ }