nuxt-users 1.1.3 → 1.1.5
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 +86 -0
- package/README.md +12 -0
- package/dist/cli.mjs +33 -346
- package/dist/module.d.mts +1 -49
- package/dist/module.d.ts +1 -49
- package/dist/module.json +2 -2
- package/dist/runtime/components/ForgotPasswordForm.vue +21 -23
- package/dist/runtime/components/LoginForm.vue +42 -30
- package/dist/runtime/components/LoginForm.vue.d.ts +8 -8
- package/dist/runtime/components/ResetPasswordForm.vue +40 -33
- package/dist/runtime/plugin.js +1 -1
- package/dist/runtime/server/api/login.post.js +1 -1
- package/dist/runtime/server/services/password.js +1 -2
- package/dist/shared/nuxt-users.Dtq4WcpY.d.mts +58 -0
- package/dist/shared/nuxt-users.Dtq4WcpY.d.ts +58 -0
- package/dist/shared/nuxt-users.eSQUrS6l.mjs +333 -0
- package/dist/utils.d.mts +37 -0
- package/dist/utils.d.ts +37 -0
- package/dist/utils.mjs +3 -0
- package/package.json +49 -33
- package/dist/chunks/better-sqlite3.mjs +0 -45
- package/dist/chunks/mysql2.mjs +0 -49
- package/dist/chunks/postgresql.mjs +0 -58
- package/dist/shared/nuxt-users.C9d5M6B1.mjs +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,92 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v1.1.5
|
|
5
|
+
|
|
6
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.1.4...v1.1.5)
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
|
|
10
|
+
- **deps:** Exclude bcrypt from client-side bundle ([a678a96](https://github.com/rrd108/nuxt-users/commit/a678a96))
|
|
11
|
+
|
|
12
|
+
### 💅 Refactors
|
|
13
|
+
|
|
14
|
+
- **cli:** Commands to load options ([403a281](https://github.com/rrd108/nuxt-users/commit/403a281))
|
|
15
|
+
|
|
16
|
+
### 🏡 Chore
|
|
17
|
+
|
|
18
|
+
- **release:** V1.1.4 ([4980c98](https://github.com/rrd108/nuxt-users/commit/4980c98))
|
|
19
|
+
|
|
20
|
+
### ✅ Tests
|
|
21
|
+
|
|
22
|
+
- Ensures database cleanup on test completion ([a1a528c](https://github.com/rrd108/nuxt-users/commit/a1a528c))
|
|
23
|
+
|
|
24
|
+
### ❤️ Contributors
|
|
25
|
+
|
|
26
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
27
|
+
|
|
28
|
+
## v1.1.4
|
|
29
|
+
|
|
30
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.1.0...v1.1.4)
|
|
31
|
+
|
|
32
|
+
### 🩹 Fixes
|
|
33
|
+
|
|
34
|
+
- CLI tool for database management ([0a4793f](https://github.com/rrd108/nuxt-users/commit/0a4793f))
|
|
35
|
+
- Handling cli commands ([120c396](https://github.com/rrd108/nuxt-users/commit/120c396))
|
|
36
|
+
- Database handling and setup ([11ddc20](https://github.com/rrd108/nuxt-users/commit/11ddc20))
|
|
37
|
+
- Proper check for migrations table ([08701a1](https://github.com/rrd108/nuxt-users/commit/08701a1))
|
|
38
|
+
- Migration command in warning message ([1a62e50](https://github.com/rrd108/nuxt-users/commit/1a62e50))
|
|
39
|
+
- Improves database connector error handling ([db3b670](https://github.com/rrd108/nuxt-users/commit/db3b670))
|
|
40
|
+
- Use sql connector defined in nuxt.config ([b37900d](https://github.com/rrd108/nuxt-users/commit/b37900d))
|
|
41
|
+
- Module metadata and build process ([3da5410](https://github.com/rrd108/nuxt-users/commit/3da5410))
|
|
42
|
+
- **ci:** Install optional dependencies ([38d6ee8](https://github.com/rrd108/nuxt-users/commit/38d6ee8))
|
|
43
|
+
- Adds necessary database drivers for testing ([f1815f4](https://github.com/rrd108/nuxt-users/commit/f1815f4))
|
|
44
|
+
- **ci:** Installs peer dependencies in CI workflows ([423d4e9](https://github.com/rrd108/nuxt-users/commit/423d4e9))
|
|
45
|
+
- Test paths ([047f0e8](https://github.com/rrd108/nuxt-users/commit/047f0e8))
|
|
46
|
+
- Type errors ([3d5b35c](https://github.com/rrd108/nuxt-users/commit/3d5b35c))
|
|
47
|
+
- Consolidates build config and external deps ([48b4980](https://github.com/rrd108/nuxt-users/commit/48b4980))
|
|
48
|
+
- **ci:** Downgrade mariadb ([b1be244](https://github.com/rrd108/nuxt-users/commit/b1be244))
|
|
49
|
+
- Adds db0 to external dependencies ([b276c58](https://github.com/rrd108/nuxt-users/commit/b276c58))
|
|
50
|
+
|
|
51
|
+
### 💅 Refactors
|
|
52
|
+
|
|
53
|
+
- CLI commands to use environment variables ([3fc6c9f](https://github.com/rrd108/nuxt-users/commit/3fc6c9f))
|
|
54
|
+
- Remove unused types ([06b5e9f](https://github.com/rrd108/nuxt-users/commit/06b5e9f))
|
|
55
|
+
- Database connection logic ([f5baadf](https://github.com/rrd108/nuxt-users/commit/f5baadf))
|
|
56
|
+
- Moves user existence check to user utils ([62cc871](https://github.com/rrd108/nuxt-users/commit/62cc871))
|
|
57
|
+
- Remove unused options ([b391013](https://github.com/rrd108/nuxt-users/commit/b391013))
|
|
58
|
+
- Adds a color palette and styles login forms ([d3bffab](https://github.com/rrd108/nuxt-users/commit/d3bffab))
|
|
59
|
+
- Adds color palette and improves styling ([7cfab67](https://github.com/rrd108/nuxt-users/commit/7cfab67))
|
|
60
|
+
- Db check to plugin ([d466e2f](https://github.com/rrd108/nuxt-users/commit/d466e2f))
|
|
61
|
+
- Consolidates utils and CLI build ([21e9f3c](https://github.com/rrd108/nuxt-users/commit/21e9f3c))
|
|
62
|
+
- Remove unused option ([d9e3525](https://github.com/rrd108/nuxt-users/commit/d9e3525))
|
|
63
|
+
- Utils import paths ([e3b59c3](https://github.com/rrd108/nuxt-users/commit/e3b59c3))
|
|
64
|
+
- Module utils and improves CLI output ([e80b160](https://github.com/rrd108/nuxt-users/commit/e80b160))
|
|
65
|
+
|
|
66
|
+
### 🏡 Chore
|
|
67
|
+
|
|
68
|
+
- **release:** V1.1.0 ([bfc24f6](https://github.com/rrd108/nuxt-users/commit/bfc24f6))
|
|
69
|
+
- Adds script to deploy documentation to server ([81f7f74](https://github.com/rrd108/nuxt-users/commit/81f7f74))
|
|
70
|
+
- Adds script to deploy documentation ([7e2f642](https://github.com/rrd108/nuxt-users/commit/7e2f642))
|
|
71
|
+
- **release:** V1.1.1 ([e3bda8a](https://github.com/rrd108/nuxt-users/commit/e3bda8a))
|
|
72
|
+
- **release:** V1.1.2 ([3a2d2ae](https://github.com/rrd108/nuxt-users/commit/3a2d2ae))
|
|
73
|
+
- **release:** V1.1.3 ([b32a05f](https://github.com/rrd108/nuxt-users/commit/b32a05f))
|
|
74
|
+
- Updates dependencies in yarn.lock ([f29a369](https://github.com/rrd108/nuxt-users/commit/f29a369))
|
|
75
|
+
- Adds nodemailer to externals and dependencies ([b717d49](https://github.com/rrd108/nuxt-users/commit/b717d49))
|
|
76
|
+
- Removes stub build from dev prepare script ([dd96376](https://github.com/rrd108/nuxt-users/commit/dd96376))
|
|
77
|
+
- Remove examples ([d2f5c04](https://github.com/rrd108/nuxt-users/commit/d2f5c04))
|
|
78
|
+
- Remove comments ([6b45d71](https://github.com/rrd108/nuxt-users/commit/6b45d71))
|
|
79
|
+
- Renames unbuild config file ([bd7299f](https://github.com/rrd108/nuxt-users/commit/bd7299f))
|
|
80
|
+
|
|
81
|
+
### ✅ Tests
|
|
82
|
+
|
|
83
|
+
- Cleanup added ([50369a9](https://github.com/rrd108/nuxt-users/commit/50369a9))
|
|
84
|
+
- Ensures database cleanup on test completion ([a1a528c](https://github.com/rrd108/nuxt-users/commit/a1a528c))
|
|
85
|
+
|
|
86
|
+
### ❤️ Contributors
|
|
87
|
+
|
|
88
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
89
|
+
|
|
4
90
|
## v1.1.3
|
|
5
91
|
|
|
6
92
|
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.1.0...v1.1.3)
|
package/README.md
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,346 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { defineCommand, runMain } from 'citty';
|
|
3
|
-
import
|
|
3
|
+
import 'db0';
|
|
4
|
+
import 'bcrypt';
|
|
5
|
+
import { r as runMigrations, a as createUser$1, d as createUsersTable$1, e as createPersonalAccessTokensTable$1, g as createPasswordResetTokensTable$1, h as createMigrationsTable$1 } from './shared/nuxt-users.eSQUrS6l.mjs';
|
|
4
6
|
import { loadNuxt } from '@nuxt/kit';
|
|
5
7
|
|
|
6
|
-
function sqlTemplate(strings, ...values) {
|
|
7
|
-
if (!isTemplateStringsArray(strings) || !Array.isArray(values)) {
|
|
8
|
-
throw new Error("[db0] invalid template invocation");
|
|
9
|
-
}
|
|
10
|
-
const staticIndexes = [];
|
|
11
|
-
let result = strings[0] || "";
|
|
12
|
-
for (let i = 1; i < strings.length; i++) {
|
|
13
|
-
if (result.endsWith("{") && strings[i].startsWith("}")) {
|
|
14
|
-
result = result.slice(0, -1) + values[i - 1] + strings[i].slice(1);
|
|
15
|
-
staticIndexes.push(i - 1);
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
result += `?${strings[i] ?? ""}`;
|
|
19
|
-
}
|
|
20
|
-
const dynamicValues = values.filter((_, i) => !staticIndexes.includes(i));
|
|
21
|
-
return [result.trim(), dynamicValues];
|
|
22
|
-
}
|
|
23
|
-
function isTemplateStringsArray(strings) {
|
|
24
|
-
return Array.isArray(strings) && "raw" in strings && Array.isArray(strings.raw);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const SQL_SELECT_RE = /^select/i;
|
|
28
|
-
const SQL_RETURNING_RE = /[\s]returning[\s]/i;
|
|
29
|
-
const DIALECTS_WITH_RET = /* @__PURE__ */ new Set(["postgresql", "sqlite"]);
|
|
30
|
-
function createDatabase(connector) {
|
|
31
|
-
return {
|
|
32
|
-
get dialect() {
|
|
33
|
-
return connector.dialect;
|
|
34
|
-
},
|
|
35
|
-
getInstance() {
|
|
36
|
-
return connector.getInstance();
|
|
37
|
-
},
|
|
38
|
-
exec: (sql) => {
|
|
39
|
-
return Promise.resolve(connector.exec(sql));
|
|
40
|
-
},
|
|
41
|
-
prepare: (sql) => {
|
|
42
|
-
return connector.prepare(sql);
|
|
43
|
-
},
|
|
44
|
-
sql: async (strings, ...values) => {
|
|
45
|
-
const [sql, params] = sqlTemplate(strings, ...values);
|
|
46
|
-
if (SQL_SELECT_RE.test(sql) || // prettier-ignore
|
|
47
|
-
DIALECTS_WITH_RET.has(connector.dialect) && SQL_RETURNING_RE.test(sql)) {
|
|
48
|
-
const rows = await connector.prepare(sql).all(...params);
|
|
49
|
-
return {
|
|
50
|
-
rows,
|
|
51
|
-
success: true
|
|
52
|
-
};
|
|
53
|
-
} else {
|
|
54
|
-
const res = await connector.prepare(sql).run(...params);
|
|
55
|
-
return res;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const getConnector = async (name) => {
|
|
62
|
-
switch (name) {
|
|
63
|
-
case "mysql":
|
|
64
|
-
return (await import('./chunks/mysql2.mjs')).default;
|
|
65
|
-
case "postgresql":
|
|
66
|
-
return (await import('./chunks/postgresql.mjs')).default;
|
|
67
|
-
case "sqlite":
|
|
68
|
-
return (await import('./chunks/better-sqlite3.mjs')).default;
|
|
69
|
-
default:
|
|
70
|
-
throw new Error(`Unsupported database connector: ${name}`);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const useDb = async (options) => {
|
|
74
|
-
const connectorName = options.connector.name;
|
|
75
|
-
const connector = await getConnector(connectorName);
|
|
76
|
-
const connectorOptions = { ...options.connector.options };
|
|
77
|
-
if (connectorName !== "sqlite") {
|
|
78
|
-
delete connectorOptions.path;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
return createDatabase(connector(connectorOptions));
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.warn(`[Nuxt Users DB] \u26A0\uFE0F Failed to connect to ${connectorName} database:`, error instanceof Error ? error.message : "Unknown error");
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const createUser$1 = async (userData, options) => {
|
|
89
|
-
const db = await useDb(options);
|
|
90
|
-
const usersTable = options.tables.users;
|
|
91
|
-
const hashedPassword = await bcrypt.hash(userData.password, 10);
|
|
92
|
-
await db.sql`
|
|
93
|
-
INSERT INTO {${usersTable}} (email, name, password, created_at, updated_at)
|
|
94
|
-
VALUES (${userData.email}, ${userData.name}, ${hashedPassword}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
|
95
|
-
`;
|
|
96
|
-
const result = await db.sql`SELECT id, email, name, created_at, updated_at FROM {${usersTable}} WHERE email = ${userData.email}`;
|
|
97
|
-
if (result.rows.length === 0) {
|
|
98
|
-
throw new Error("Failed to retrieve created user.");
|
|
99
|
-
}
|
|
100
|
-
const user = result.rows[0];
|
|
101
|
-
return {
|
|
102
|
-
id: user.id,
|
|
103
|
-
email: user.email,
|
|
104
|
-
name: user.name,
|
|
105
|
-
created_at: user.created_at instanceof Date ? user.created_at.toISOString() : user.created_at,
|
|
106
|
-
updated_at: user.updated_at instanceof Date ? user.updated_at.toISOString() : user.updated_at
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const createUsersTable$1 = async (options) => {
|
|
111
|
-
const connectorName = options.connector.name;
|
|
112
|
-
const db = await useDb(options);
|
|
113
|
-
const tableName = options.tables.users;
|
|
114
|
-
console.log(`[DB:Create ${connectorName} Users Table] Creating ${tableName}...`);
|
|
115
|
-
if (connectorName === "sqlite") {
|
|
116
|
-
await db.sql`
|
|
117
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
118
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
119
|
-
email TEXT NOT NULL UNIQUE,
|
|
120
|
-
name TEXT NOT NULL,
|
|
121
|
-
password TEXT NOT NULL,
|
|
122
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
123
|
-
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
124
|
-
)
|
|
125
|
-
`;
|
|
126
|
-
}
|
|
127
|
-
if (connectorName === "mysql") {
|
|
128
|
-
await db.sql`
|
|
129
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
130
|
-
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
131
|
-
email VARCHAR(255) NOT NULL UNIQUE,
|
|
132
|
-
name VARCHAR(255) NOT NULL,
|
|
133
|
-
password VARCHAR(255) NOT NULL,
|
|
134
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
135
|
-
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
136
|
-
)
|
|
137
|
-
`;
|
|
138
|
-
}
|
|
139
|
-
if (connectorName === "postgresql") {
|
|
140
|
-
await db.sql`
|
|
141
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
142
|
-
id SERIAL PRIMARY KEY,
|
|
143
|
-
email VARCHAR(255) NOT NULL UNIQUE,
|
|
144
|
-
name VARCHAR(255) NOT NULL,
|
|
145
|
-
password VARCHAR(255) NOT NULL,
|
|
146
|
-
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
147
|
-
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
148
|
-
)
|
|
149
|
-
`;
|
|
150
|
-
}
|
|
151
|
-
console.log(`[DB:Create ${connectorName} Users Table] Fields: id, email, name, password, created_at, updated_at \u2705`);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const createPersonalAccessTokensTable$1 = async (options) => {
|
|
155
|
-
const connectorName = options.connector.name;
|
|
156
|
-
const db = await useDb(options);
|
|
157
|
-
const tableName = options.tables.personalAccessTokens;
|
|
158
|
-
console.log(`[DB:Create Personal Access Tokens ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
|
|
159
|
-
if (connectorName === "sqlite") {
|
|
160
|
-
await db.sql`
|
|
161
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
162
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
163
|
-
tokenable_type TEXT NOT NULL,
|
|
164
|
-
tokenable_id INTEGER NOT NULL,
|
|
165
|
-
name TEXT NOT NULL,
|
|
166
|
-
token TEXT NOT NULL UNIQUE,
|
|
167
|
-
abilities TEXT,
|
|
168
|
-
last_used_at DATETIME,
|
|
169
|
-
expires_at DATETIME,
|
|
170
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
171
|
-
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
172
|
-
)
|
|
173
|
-
`;
|
|
174
|
-
}
|
|
175
|
-
if (connectorName === "mysql") {
|
|
176
|
-
await db.sql`
|
|
177
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
178
|
-
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
179
|
-
tokenable_type VARCHAR(255) NOT NULL,
|
|
180
|
-
tokenable_id INT NOT NULL,
|
|
181
|
-
name VARCHAR(255) NOT NULL,
|
|
182
|
-
token VARCHAR(255) NOT NULL UNIQUE,
|
|
183
|
-
abilities TEXT,
|
|
184
|
-
last_used_at DATETIME,
|
|
185
|
-
expires_at DATETIME,
|
|
186
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
187
|
-
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
188
|
-
)
|
|
189
|
-
`;
|
|
190
|
-
}
|
|
191
|
-
if (connectorName === "postgresql") {
|
|
192
|
-
await db.sql`
|
|
193
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
194
|
-
id SERIAL PRIMARY KEY,
|
|
195
|
-
tokenable_type VARCHAR(255) NOT NULL,
|
|
196
|
-
tokenable_id INT NOT NULL,
|
|
197
|
-
name VARCHAR(255) NOT NULL,
|
|
198
|
-
token VARCHAR(255) NOT NULL UNIQUE,
|
|
199
|
-
abilities TEXT,
|
|
200
|
-
last_used_at TIMESTAMPTZ,
|
|
201
|
-
expires_at TIMESTAMPTZ,
|
|
202
|
-
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
203
|
-
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
204
|
-
)
|
|
205
|
-
`;
|
|
206
|
-
}
|
|
207
|
-
console.log(`[DB:Create Personal Access Tokens ${connectorName} Table] Fields: id, tokenable_type, tokenable_id, name, token, abilities, last_used_at, expires_at, created_at, updated_at \u2705`);
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const createPasswordResetTokensTable$1 = async (options) => {
|
|
211
|
-
const connectorName = options.connector.name;
|
|
212
|
-
const db = await useDb(options);
|
|
213
|
-
const tableName = options.tables.passwordResetTokens;
|
|
214
|
-
console.log(`[DB:Create Password Reset Tokens ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
|
|
215
|
-
if (connectorName === "sqlite") {
|
|
216
|
-
await db.sql`
|
|
217
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
218
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
219
|
-
email TEXT NOT NULL,
|
|
220
|
-
token TEXT NOT NULL UNIQUE,
|
|
221
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
222
|
-
)
|
|
223
|
-
`;
|
|
224
|
-
}
|
|
225
|
-
if (connectorName === "mysql") {
|
|
226
|
-
await db.sql`
|
|
227
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
228
|
-
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
229
|
-
email VARCHAR(255) NOT NULL,
|
|
230
|
-
token VARCHAR(255) NOT NULL UNIQUE,
|
|
231
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
232
|
-
)
|
|
233
|
-
`;
|
|
234
|
-
}
|
|
235
|
-
if (connectorName === "postgresql") {
|
|
236
|
-
await db.sql`
|
|
237
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
238
|
-
id SERIAL PRIMARY KEY,
|
|
239
|
-
email VARCHAR(255) NOT NULL,
|
|
240
|
-
token VARCHAR(255) NOT NULL UNIQUE,
|
|
241
|
-
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
242
|
-
)
|
|
243
|
-
`;
|
|
244
|
-
}
|
|
245
|
-
await db.sql`CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_email ON {${tableName}} (email)`;
|
|
246
|
-
await db.sql`CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_token ON {${tableName}} (token)`;
|
|
247
|
-
console.log(`[DB:Create Password Reset Tokens ${connectorName} Table] Fields: id, email, token, created_at \u2705`);
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const createMigrationsTable$1 = async (options) => {
|
|
251
|
-
const connectorName = options.connector.name;
|
|
252
|
-
const db = await useDb(options);
|
|
253
|
-
const tableName = "migrations";
|
|
254
|
-
console.log(`[DB:Create Migrations ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
|
|
255
|
-
if (connectorName === "sqlite") {
|
|
256
|
-
await db.sql`
|
|
257
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
258
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
259
|
-
name TEXT NOT NULL UNIQUE,
|
|
260
|
-
executed_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
261
|
-
)
|
|
262
|
-
`;
|
|
263
|
-
}
|
|
264
|
-
if (connectorName === "mysql") {
|
|
265
|
-
await db.sql`
|
|
266
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
267
|
-
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
268
|
-
name VARCHAR(255) NOT NULL UNIQUE,
|
|
269
|
-
executed_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
270
|
-
)
|
|
271
|
-
`;
|
|
272
|
-
}
|
|
273
|
-
if (connectorName === "postgresql") {
|
|
274
|
-
await db.sql`
|
|
275
|
-
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
276
|
-
id SERIAL PRIMARY KEY,
|
|
277
|
-
name VARCHAR(255) NOT NULL UNIQUE,
|
|
278
|
-
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
279
|
-
)
|
|
280
|
-
`;
|
|
281
|
-
}
|
|
282
|
-
console.log(`[DB:Create Migrations ${connectorName} Table] successfull \u2705`);
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
const migrations = [
|
|
286
|
-
{
|
|
287
|
-
name: "create_migrations_table",
|
|
288
|
-
run: createMigrationsTable$1
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
name: "create_users_table",
|
|
292
|
-
run: createUsersTable$1
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
name: "create_personal_access_tokens_table",
|
|
296
|
-
run: createPersonalAccessTokensTable$1
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
name: "create_password_reset_tokens_table",
|
|
300
|
-
run: createPasswordResetTokensTable$1
|
|
301
|
-
}
|
|
302
|
-
];
|
|
303
|
-
const getAppliedMigrations = async (options) => {
|
|
304
|
-
const db = await useDb(options);
|
|
305
|
-
try {
|
|
306
|
-
const result = await db.sql`SELECT name FROM migrations ORDER BY id`;
|
|
307
|
-
return result.rows.map((row) => row.name);
|
|
308
|
-
} catch {
|
|
309
|
-
return [];
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
const markMigrationAsApplied = async (options, migrationName) => {
|
|
313
|
-
const db = await useDb(options);
|
|
314
|
-
await db.sql`INSERT INTO migrations (name) VALUES (${migrationName})`;
|
|
315
|
-
};
|
|
316
|
-
const runMigrations = async (options) => {
|
|
317
|
-
console.log("[Nuxt Users] Starting migration system...");
|
|
318
|
-
await createMigrationsTable$1(options);
|
|
319
|
-
const appliedMigrations = await getAppliedMigrations(options);
|
|
320
|
-
console.log(`[Nuxt Users] Applied migrations: ${appliedMigrations.join(", ")}`);
|
|
321
|
-
const pendingMigrations = migrations.filter((migration) => !appliedMigrations.includes(migration.name));
|
|
322
|
-
if (pendingMigrations.length === 0) {
|
|
323
|
-
console.log("[Nuxt Users] No pending migrations to run.");
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
console.log(`[Nuxt Users] Found ${pendingMigrations.length} pending migrations:`);
|
|
327
|
-
pendingMigrations.forEach((migration) => {
|
|
328
|
-
console.log(` - ${migration.name}`);
|
|
329
|
-
});
|
|
330
|
-
for (const migration of pendingMigrations) {
|
|
331
|
-
console.log(`[Nuxt Users] Running migration: ${migration.name}`);
|
|
332
|
-
try {
|
|
333
|
-
await migration.run(options);
|
|
334
|
-
await markMigrationAsApplied(options, migration.name);
|
|
335
|
-
console.log(`[Nuxt Users] \u2713 Migration ${migration.name} successfull \u2705`);
|
|
336
|
-
} catch (error) {
|
|
337
|
-
console.error(`[Nuxt Users] \u2717 Migration ${migration.name} failed:`, error);
|
|
338
|
-
throw error;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
console.log("[Nuxt Users] All migrations successfull \u2705");
|
|
342
|
-
};
|
|
343
|
-
|
|
344
8
|
const defaultOptions = {
|
|
345
9
|
connector: {
|
|
346
10
|
name: "sqlite",
|
|
@@ -406,6 +70,25 @@ const getOptionsFromEnv = () => {
|
|
|
406
70
|
}
|
|
407
71
|
};
|
|
408
72
|
};
|
|
73
|
+
const loadOptions = async () => {
|
|
74
|
+
try {
|
|
75
|
+
console.log("[Nuxt Users] Loading Nuxt project...");
|
|
76
|
+
const nuxt = await loadNuxt({ cwd: process.cwd() });
|
|
77
|
+
const nuxtUsersConfig = nuxt.options.runtimeConfig?.nuxtUsers;
|
|
78
|
+
await nuxt.close();
|
|
79
|
+
if (nuxtUsersConfig) {
|
|
80
|
+
console.log("[Nuxt Users] Using configuration from Nuxt project");
|
|
81
|
+
return nuxtUsersConfig;
|
|
82
|
+
} else {
|
|
83
|
+
console.log("[Nuxt Users] No nuxt-users configuration found, using environment variables");
|
|
84
|
+
return getOptionsFromEnv();
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.log("[Nuxt Users] Could not load Nuxt project, using environment variables");
|
|
88
|
+
console.error(error);
|
|
89
|
+
return getOptionsFromEnv();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
409
92
|
|
|
410
93
|
const migrate = defineCommand({
|
|
411
94
|
meta: {
|
|
@@ -414,10 +97,11 @@ const migrate = defineCommand({
|
|
|
414
97
|
},
|
|
415
98
|
async run() {
|
|
416
99
|
console.log("[Nuxt Users] Starting migration system...");
|
|
417
|
-
const options =
|
|
100
|
+
const options = await loadOptions();
|
|
418
101
|
try {
|
|
419
102
|
await runMigrations(options);
|
|
420
103
|
console.log("[Nuxt Users] Migration completed successfully!");
|
|
104
|
+
process.exit(0);
|
|
421
105
|
} catch (error) {
|
|
422
106
|
console.error("[Nuxt Users] Migration failed:", error);
|
|
423
107
|
process.exit(1);
|
|
@@ -432,16 +116,19 @@ const createUser = defineCommand({
|
|
|
432
116
|
},
|
|
433
117
|
args: {
|
|
434
118
|
email: {
|
|
119
|
+
alias: "e",
|
|
435
120
|
type: "string",
|
|
436
121
|
description: "User email address",
|
|
437
122
|
required: true
|
|
438
123
|
},
|
|
439
124
|
name: {
|
|
125
|
+
alias: "n",
|
|
440
126
|
type: "string",
|
|
441
127
|
description: "User full name",
|
|
442
128
|
required: true
|
|
443
129
|
},
|
|
444
130
|
password: {
|
|
131
|
+
alias: "p",
|
|
445
132
|
type: "string",
|
|
446
133
|
description: "User password",
|
|
447
134
|
required: true
|
|
@@ -449,7 +136,7 @@ const createUser = defineCommand({
|
|
|
449
136
|
},
|
|
450
137
|
async run({ args }) {
|
|
451
138
|
const { email, name, password } = args;
|
|
452
|
-
const options =
|
|
139
|
+
const options = await loadOptions();
|
|
453
140
|
try {
|
|
454
141
|
const user = await createUser$1({ email, name, password }, options);
|
|
455
142
|
console.log(`[DB:Create User] User created successfully: ${user.email}`);
|
|
@@ -467,7 +154,7 @@ const createUsersTable = defineCommand({
|
|
|
467
154
|
},
|
|
468
155
|
async run() {
|
|
469
156
|
console.log("[Nuxt Users] Creating users table...");
|
|
470
|
-
const options =
|
|
157
|
+
const options = await loadOptions();
|
|
471
158
|
try {
|
|
472
159
|
await createUsersTable$1(options);
|
|
473
160
|
console.log("[Nuxt Users] Users table created successfully!");
|
|
@@ -485,7 +172,7 @@ const createPersonalAccessTokensTable = defineCommand({
|
|
|
485
172
|
},
|
|
486
173
|
async run() {
|
|
487
174
|
console.log("[Nuxt Users] Creating personal access tokens table...");
|
|
488
|
-
const options =
|
|
175
|
+
const options = await loadOptions();
|
|
489
176
|
try {
|
|
490
177
|
await createPersonalAccessTokensTable$1(options);
|
|
491
178
|
console.log("[Nuxt Users] Personal access tokens table created successfully!");
|
|
@@ -503,7 +190,7 @@ const createPasswordResetTokensTable = defineCommand({
|
|
|
503
190
|
},
|
|
504
191
|
async run() {
|
|
505
192
|
console.log("[Nuxt Users] Creating password reset tokens table...");
|
|
506
|
-
const options =
|
|
193
|
+
const options = await loadOptions();
|
|
507
194
|
try {
|
|
508
195
|
await createPasswordResetTokensTable$1(options);
|
|
509
196
|
console.log("[Nuxt Users] Password reset tokens table created successfully!");
|
|
@@ -521,7 +208,7 @@ const createMigrationsTable = defineCommand({
|
|
|
521
208
|
},
|
|
522
209
|
async run() {
|
|
523
210
|
console.log("[Nuxt Users] Creating migrations table...");
|
|
524
|
-
const options =
|
|
211
|
+
const options = await loadOptions();
|
|
525
212
|
try {
|
|
526
213
|
await createMigrationsTable$1(options);
|
|
527
214
|
console.log("[Nuxt Users] Migrations table created successfully!");
|
|
@@ -572,7 +259,7 @@ const main = defineCommand({
|
|
|
572
259
|
meta: {
|
|
573
260
|
name: "nuxt-users",
|
|
574
261
|
description: "CLI for Nuxt Users Module - Manage users, migrations, and database operations",
|
|
575
|
-
version: "1.1.
|
|
262
|
+
version: "1.1.3"
|
|
576
263
|
},
|
|
577
264
|
subCommands: {
|
|
578
265
|
migrate,
|
package/dist/module.d.mts
CHANGED
|
@@ -1,53 +1,5 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
|
|
3
|
-
type DatabaseType = 'sqlite' | 'mysql' | 'postgresql';
|
|
4
|
-
type DatabaseConfig = {
|
|
5
|
-
path?: string;
|
|
6
|
-
host?: string;
|
|
7
|
-
port?: number;
|
|
8
|
-
user?: string;
|
|
9
|
-
password?: string;
|
|
10
|
-
database?: string;
|
|
11
|
-
};
|
|
12
|
-
interface ModuleOptions {
|
|
13
|
-
connector?: {
|
|
14
|
-
name: DatabaseType;
|
|
15
|
-
options: DatabaseConfig;
|
|
16
|
-
};
|
|
17
|
-
tables: {
|
|
18
|
-
migrations: string;
|
|
19
|
-
users: string;
|
|
20
|
-
personalAccessTokens: string;
|
|
21
|
-
passwordResetTokens: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Mailer configuration options for sending emails (e.g., password resets)
|
|
25
|
-
* Uses nodemailer
|
|
26
|
-
*/
|
|
27
|
-
mailer?: MailerOptions;
|
|
28
|
-
/**
|
|
29
|
-
* Base URL for password reset links
|
|
30
|
-
* @default 'http://localhost:3000' // Example, will be set in module defaults
|
|
31
|
-
*/
|
|
32
|
-
passwordResetBaseUrl?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Skip database checks during module setup to prevent hanging
|
|
35
|
-
* @default false
|
|
36
|
-
*/
|
|
37
|
-
skipDatabaseChecks?: boolean;
|
|
38
|
-
}
|
|
39
|
-
interface MailerOptions {
|
|
40
|
-
host: string;
|
|
41
|
-
port: number;
|
|
42
|
-
secure?: boolean;
|
|
43
|
-
auth: {
|
|
44
|
-
user: string;
|
|
45
|
-
pass: string;
|
|
46
|
-
};
|
|
47
|
-
defaults?: {
|
|
48
|
-
from: string;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
2
|
+
import { M as ModuleOptions } from './shared/nuxt-users.Dtq4WcpY.mjs';
|
|
51
3
|
|
|
52
4
|
declare const defaultOptions: ModuleOptions;
|
|
53
5
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
package/dist/module.d.ts
CHANGED
|
@@ -1,53 +1,5 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
|
|
3
|
-
type DatabaseType = 'sqlite' | 'mysql' | 'postgresql';
|
|
4
|
-
type DatabaseConfig = {
|
|
5
|
-
path?: string;
|
|
6
|
-
host?: string;
|
|
7
|
-
port?: number;
|
|
8
|
-
user?: string;
|
|
9
|
-
password?: string;
|
|
10
|
-
database?: string;
|
|
11
|
-
};
|
|
12
|
-
interface ModuleOptions {
|
|
13
|
-
connector?: {
|
|
14
|
-
name: DatabaseType;
|
|
15
|
-
options: DatabaseConfig;
|
|
16
|
-
};
|
|
17
|
-
tables: {
|
|
18
|
-
migrations: string;
|
|
19
|
-
users: string;
|
|
20
|
-
personalAccessTokens: string;
|
|
21
|
-
passwordResetTokens: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Mailer configuration options for sending emails (e.g., password resets)
|
|
25
|
-
* Uses nodemailer
|
|
26
|
-
*/
|
|
27
|
-
mailer?: MailerOptions;
|
|
28
|
-
/**
|
|
29
|
-
* Base URL for password reset links
|
|
30
|
-
* @default 'http://localhost:3000' // Example, will be set in module defaults
|
|
31
|
-
*/
|
|
32
|
-
passwordResetBaseUrl?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Skip database checks during module setup to prevent hanging
|
|
35
|
-
* @default false
|
|
36
|
-
*/
|
|
37
|
-
skipDatabaseChecks?: boolean;
|
|
38
|
-
}
|
|
39
|
-
interface MailerOptions {
|
|
40
|
-
host: string;
|
|
41
|
-
port: number;
|
|
42
|
-
secure?: boolean;
|
|
43
|
-
auth: {
|
|
44
|
-
user: string;
|
|
45
|
-
pass: string;
|
|
46
|
-
};
|
|
47
|
-
defaults?: {
|
|
48
|
-
from: string;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
2
|
+
import { M as ModuleOptions } from './shared/nuxt-users.Dtq4WcpY.js';
|
|
51
3
|
|
|
52
4
|
declare const defaultOptions: ModuleOptions;
|
|
53
5
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|