nurev 0.0.8 → 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 +52 -0
- package/bun.lock +84 -0
- package/index.js +16 -72
- package/package.json +3 -1
- package/templates/base/frontend/bun.lock +1480 -0
- package/templates/base/frontend/package.json +1 -1
- package/templates/base/frontend/server/plugins/pocketbase.ts +4 -1
- package/templates/pocketbase/.env.example +1 -1
- package/templates/pocketbase/README.md +8 -10
- package/templates/pocketbase/backend/go.mod +4 -4
- package/templates/pocketbase/backend/go.sum +8 -0
- package/templates/pocketbase-bun/Makefile +4 -4
- package/utils/sqlite.js +33 -0
- package/workflows/pocketbase/index.js +111 -0
|
@@ -7,7 +7,10 @@ export default defineNitroPlugin(async (nitroApp) => {
|
|
|
7
7
|
try {
|
|
8
8
|
await pb
|
|
9
9
|
.collection("users")
|
|
10
|
-
.authWithPassword(
|
|
10
|
+
.authWithPassword(
|
|
11
|
+
config.pocketbaseUser,
|
|
12
|
+
config.pocketbasePassword.toString(),
|
|
13
|
+
);
|
|
11
14
|
|
|
12
15
|
nitroApp.hooks.hook("request", (event) => {
|
|
13
16
|
event.context.pocketbase = pb;
|
|
@@ -53,22 +53,20 @@ Tech stack:
|
|
|
53
53
|
make backend-dev
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
3.
|
|
57
|
-
|
|
58
|
-
4. Create a collection named `posts` and change API Rules for give permissions with `@request.auth.id != ""`
|
|
59
|
-
|
|
60
|
-
5. Create a new post
|
|
61
|
-
|
|
62
|
-
6. Start frontend dev mode
|
|
56
|
+
3. Start frontend dev mode
|
|
63
57
|
|
|
64
58
|
```bash
|
|
65
59
|
make frontend-dev
|
|
66
60
|
```
|
|
67
61
|
|
|
68
|
-
|
|
62
|
+
4. Copy a post ID from the `posts` collection
|
|
63
|
+
|
|
64
|
+
5. Open `http://localhost:3000/posts/[id]` and replace `[id]` with the copied post ID
|
|
65
|
+
|
|
66
|
+
6. Verify caching by checking the `ETag` header in the response (Network tab in browser dev tools). The `ETag` will change when you modify post records or create a backup
|
|
69
67
|
|
|
70
|
-
##
|
|
68
|
+
## More commands
|
|
71
69
|
|
|
72
70
|
```bash
|
|
73
|
-
make
|
|
71
|
+
make help
|
|
74
72
|
```
|
|
@@ -5,7 +5,7 @@ go 1.25.0
|
|
|
5
5
|
require (
|
|
6
6
|
github.com/golang-jwt/jwt/v5 v5.3.1
|
|
7
7
|
github.com/joho/godotenv v1.5.1
|
|
8
|
-
github.com/pocketbase/pocketbase v0.36.
|
|
8
|
+
github.com/pocketbase/pocketbase v0.36.8
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
require (
|
|
@@ -13,7 +13,7 @@ require (
|
|
|
13
13
|
github.com/disintegration/imaging v1.6.2 // indirect
|
|
14
14
|
github.com/domodwyer/mailyak/v3 v3.6.2 // indirect
|
|
15
15
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
|
16
|
-
github.com/fatih/color v1.
|
|
16
|
+
github.com/fatih/color v1.19.0 // indirect
|
|
17
17
|
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
|
|
18
18
|
github.com/ganigeorgiev/fexpr v0.5.0 // indirect
|
|
19
19
|
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
|
|
@@ -29,7 +29,7 @@ require (
|
|
|
29
29
|
github.com/spf13/cobra v1.10.2 // indirect
|
|
30
30
|
github.com/spf13/pflag v1.0.10 // indirect
|
|
31
31
|
golang.org/x/crypto v0.49.0 // indirect
|
|
32
|
-
golang.org/x/image v0.
|
|
32
|
+
golang.org/x/image v0.38.0 // indirect
|
|
33
33
|
golang.org/x/net v0.52.0 // indirect
|
|
34
34
|
golang.org/x/oauth2 v0.36.0 // indirect
|
|
35
35
|
golang.org/x/sync v0.20.0 // indirect
|
|
@@ -38,5 +38,5 @@ require (
|
|
|
38
38
|
modernc.org/libc v1.70.0 // indirect
|
|
39
39
|
modernc.org/mathutil v1.7.1 // indirect
|
|
40
40
|
modernc.org/memory v1.11.0 // indirect
|
|
41
|
-
modernc.org/sqlite v1.
|
|
41
|
+
modernc.org/sqlite v1.48.0 // indirect
|
|
42
42
|
)
|
|
@@ -12,6 +12,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
|
|
|
12
12
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
|
13
13
|
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
|
14
14
|
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
|
15
|
+
github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
|
|
16
|
+
github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
|
|
15
17
|
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
|
16
18
|
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
|
17
19
|
github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9Ufpk2AcUM=
|
|
@@ -53,6 +55,8 @@ github.com/pocketbase/dbx v1.12.0 h1:/oLErM+A0b4xI0PWTGPqSDVjzix48PqI/bng2l0PzoA
|
|
|
53
55
|
github.com/pocketbase/dbx v1.12.0/go.mod h1:xXRCIAKTHMgUCyCKZm55pUOdvFziJjQfXaWKhu2vhMs=
|
|
54
56
|
github.com/pocketbase/pocketbase v0.36.7 h1:MrViB7BptPYrf2Nt25pJEYBqUdFjuhRKu1p5GTrkvPA=
|
|
55
57
|
github.com/pocketbase/pocketbase v0.36.7/go.mod h1:qX4HuVjoKXtEg41fSJVM0JLfGWXbBmHxVv/FaE446r4=
|
|
58
|
+
github.com/pocketbase/pocketbase v0.36.8 h1:gCNqoesZ44saYOD3J7edhi5nDwUWKyQG7boM/kVwz2c=
|
|
59
|
+
github.com/pocketbase/pocketbase v0.36.8/go.mod h1:OY4WaXbP0WnF/EXoBbboWJK+ZSZ1A85tiA0sjrTKxTA=
|
|
56
60
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
|
57
61
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
|
58
62
|
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
|
@@ -75,6 +79,8 @@ golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtC
|
|
|
75
79
|
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
|
76
80
|
golang.org/x/image v0.37.0 h1:ZiRjArKI8GwxZOoEtUfhrBtaCN+4b/7709dlT6SSnQA=
|
|
77
81
|
golang.org/x/image v0.37.0/go.mod h1:/3f6vaXC+6CEanU4KJxbcUZyEePbyKbaLoDOe4ehFYY=
|
|
82
|
+
golang.org/x/image v0.38.0 h1:5l+q+Y9JDC7mBOMjo4/aPhMDcxEptsX+Tt3GgRQRPuE=
|
|
83
|
+
golang.org/x/image v0.38.0/go.mod h1:/3f6vaXC+6CEanU4KJxbcUZyEePbyKbaLoDOe4ehFYY=
|
|
78
84
|
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
|
|
79
85
|
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
|
|
80
86
|
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
|
@@ -124,6 +130,8 @@ modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
|
|
124
130
|
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
|
125
131
|
modernc.org/sqlite v1.46.2 h1:gkXQ6R0+AjxFC/fTDaeIVLbNLNrRoOK7YYVz5BKhTcE=
|
|
126
132
|
modernc.org/sqlite v1.46.2/go.mod h1:hWjRO6Tj/5Ik8ieqxQybiEOUXy0NJFNp2tpvVpKlvig=
|
|
133
|
+
modernc.org/sqlite v1.48.0 h1:ElZyLop3Q2mHYk5IFPPXADejZrlHu7APbpB0sF78bq4=
|
|
134
|
+
modernc.org/sqlite v1.48.0/go.mod h1:hWjRO6Tj/5Ik8ieqxQybiEOUXy0NJFNp2tpvVpKlvig=
|
|
127
135
|
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
|
128
136
|
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
|
129
137
|
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
|
@@ -38,19 +38,19 @@ frontend-setup:
|
|
|
38
38
|
|
|
39
39
|
frontend-install:
|
|
40
40
|
@echo "Installing frontend dependencies..."
|
|
41
|
-
cd frontend && bun
|
|
41
|
+
cd frontend && bun install
|
|
42
42
|
|
|
43
43
|
frontend-dev: frontend-install
|
|
44
44
|
@echo "Starting frontend development server..."
|
|
45
|
-
cd frontend && bun
|
|
45
|
+
cd frontend && bun run dev
|
|
46
46
|
|
|
47
47
|
frontend-build: frontend-install
|
|
48
48
|
@echo "Building frontend for production..."
|
|
49
|
-
cd frontend && bun
|
|
49
|
+
cd frontend && bun run build
|
|
50
50
|
|
|
51
51
|
frontend-preview: frontend-build
|
|
52
52
|
@echo "Previewing frontend production build..."
|
|
53
|
-
cd frontend && bun
|
|
53
|
+
cd frontend && bun run preview
|
|
54
54
|
|
|
55
55
|
install: backend-update frontend-install
|
|
56
56
|
@echo "Dependencies installed"
|
package/utils/sqlite.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Database from "better-sqlite3";
|
|
2
|
+
|
|
3
|
+
export class SQLiteManager {
|
|
4
|
+
constructor(filePath) {
|
|
5
|
+
this.db = new Database(filePath);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
create(name, params) {
|
|
9
|
+
return new Promise(async (resolve, reject) => {
|
|
10
|
+
try {
|
|
11
|
+
this.db.exec(
|
|
12
|
+
`CREATE TABLE IF NOT EXISTS ${name} (${params.toString()})`,
|
|
13
|
+
);
|
|
14
|
+
resolve();
|
|
15
|
+
} catch (error) {
|
|
16
|
+
reject(error);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
insert(name, values) {
|
|
22
|
+
return new Promise(async (resolve, reject) => {
|
|
23
|
+
try {
|
|
24
|
+
this.db.exec(
|
|
25
|
+
`INSERT INTO ${name} (${Object.keys(values).toString()}) VALUES (${Object.values(values).toString()})`,
|
|
26
|
+
);
|
|
27
|
+
resolve();
|
|
28
|
+
} catch (error) {
|
|
29
|
+
reject(error);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { default as prompts } from "prompts";
|
|
2
|
+
import { writeEnvFile } from "../../utils/file.js";
|
|
3
|
+
import { spawnPromise } from "../../utils/cmd.js";
|
|
4
|
+
import { SQLiteManager } from "../../utils/sqlite.js";
|
|
5
|
+
import { default as bcrypt } from "bcrypt";
|
|
6
|
+
|
|
7
|
+
const questions = [
|
|
8
|
+
{
|
|
9
|
+
type: "text",
|
|
10
|
+
name: "admin",
|
|
11
|
+
message: "Email address to assign to the Pocketbase superuser",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
type: "text",
|
|
15
|
+
style: "password",
|
|
16
|
+
name: "adminpassword",
|
|
17
|
+
message: "Password for superuser",
|
|
18
|
+
validate: (password) =>
|
|
19
|
+
password.length > 7 ? true : `8 characters needed or more`,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
name: "user",
|
|
24
|
+
message: "Email for the API user",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: "text",
|
|
28
|
+
style: "password",
|
|
29
|
+
name: "userpassword",
|
|
30
|
+
message: "Password for API user",
|
|
31
|
+
validate: (userpassword) =>
|
|
32
|
+
userpassword.length > 7 ? true : `8 characters needed or more`,
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export function setup(paths) {
|
|
37
|
+
return new Promise(async (resolve, reject) => {
|
|
38
|
+
try {
|
|
39
|
+
console.log(`\n Pocketbase selected \n`);
|
|
40
|
+
const responsePocketbase = await prompts(questions);
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
Object.keys(questions).length !== Object.keys(responsePocketbase).length
|
|
44
|
+
) {
|
|
45
|
+
reject(new Error("Questions not completed"));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await writeEnvFile(paths.destination.env, {
|
|
49
|
+
NUXT_POCKETBASE_USER: responsePocketbase.user,
|
|
50
|
+
NUXT_POCKETBASE_PASSWORD: responsePocketbase.userpassword,
|
|
51
|
+
NUXT_JWT_SECRET: Buffer.from(
|
|
52
|
+
crypto.getRandomValues(new Uint8Array(32)),
|
|
53
|
+
).toString("hex"),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
await spawnPromise("make", [
|
|
57
|
+
"-s",
|
|
58
|
+
"backend-superuser",
|
|
59
|
+
`email=${responsePocketbase.admin}`,
|
|
60
|
+
`password=${responsePocketbase.adminpassword}`,
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
const hash = bcrypt.hashSync(responsePocketbase.userpassword, 12);
|
|
64
|
+
const db = new SQLiteManager(
|
|
65
|
+
paths.destination.base + "/backend/pb_data/data.db",
|
|
66
|
+
);
|
|
67
|
+
const date = new Date().toISOString().replace("T", " ");
|
|
68
|
+
|
|
69
|
+
await db.insert("users", {
|
|
70
|
+
created: `'${date}'`,
|
|
71
|
+
email: `'${responsePocketbase.user}'`,
|
|
72
|
+
emailVisibility: false,
|
|
73
|
+
password: `'${hash}'`,
|
|
74
|
+
updated: `'${date}'`,
|
|
75
|
+
verified: false,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
console.log(`\nUser API created\n`);
|
|
79
|
+
|
|
80
|
+
await db.insert("_collections", {
|
|
81
|
+
created: `'${date}'`,
|
|
82
|
+
fields: `'[{"autogeneratePattern":"[a-z0-9]{15}","hidden":false,"id":"text3208210256","max":15,"min":15,"name":"id","pattern":"^[a-z0-9]+$","presentable":false,"primaryKey":true,"required":true,"system":true,"type":"text"},{"hidden":false,"id":"autodate2990389176","name":"created","onCreate":true,"onUpdate":false,"presentable":false,"system":false,"type":"autodate"},{"hidden":false,"id":"autodate3332085495","name":"updated","onCreate":true,"onUpdate":true,"presentable":false,"system":false,"type":"autodate"}]'`,
|
|
83
|
+
indexes: `'[]'`,
|
|
84
|
+
name: `'posts'`,
|
|
85
|
+
options: `'{}'`,
|
|
86
|
+
system: false,
|
|
87
|
+
updated: `'${date}'`,
|
|
88
|
+
type: `'base'`,
|
|
89
|
+
listRule: `'@request.auth.id != ""'`,
|
|
90
|
+
viewRule: `'@request.auth.id != ""'`,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
await db.create("posts", [
|
|
94
|
+
`created TEXT DEFAULT '' NOT NULL`,
|
|
95
|
+
`id TEXT PRIMARY KEY DEFAULT ('r'||lower(hex(randomblob(7)))) NOT NULL`,
|
|
96
|
+
`updated TEXT DEFAULT '' NOT NULL`,
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
await db.insert("posts", {
|
|
100
|
+
created: `'${date}'`,
|
|
101
|
+
updated: `'${date}'`,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
console.log(`\nPosts example created\n`);
|
|
105
|
+
|
|
106
|
+
resolve();
|
|
107
|
+
} catch (error) {
|
|
108
|
+
reject(error);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|