@arch-cadre/setup 0.0.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.
- package/dist/actions.cjs +125 -0
- package/dist/actions.d.ts +16 -0
- package/dist/actions.mjs +112 -0
- package/dist/index.cjs +32 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +13 -0
- package/dist/intl.d.ts +13 -0
- package/dist/routes.cjs +12 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.mjs +8 -0
- package/dist/ui/pages/setup-wizard.cjs +166 -0
- package/dist/ui/pages/setup-wizard.d.ts +2 -0
- package/dist/ui/pages/setup-wizard.mjs +108 -0
- package/locales/en/global.json +25 -0
- package/manifest.json +11 -0
- package/package.json +51 -0
package/dist/actions.cjs
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use server";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.checkDbConnection = checkDbConnection;
|
|
8
|
+
exports.finishSetup = finishSetup;
|
|
9
|
+
exports.getAvailableModules = getAvailableModules;
|
|
10
|
+
exports.syncDatabase = syncDatabase;
|
|
11
|
+
var _nodeChild_process = require("node:child_process");
|
|
12
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
13
|
+
var _nodeUtil = require("node:util");
|
|
14
|
+
var _server = require("@arch-cadre/core/server");
|
|
15
|
+
var _server2 = require("@arch-cadre/modules/server");
|
|
16
|
+
var _drizzleOrm = require("drizzle-orm");
|
|
17
|
+
var _navigation = require("next/navigation");
|
|
18
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
+
const execAsync = (0, _nodeUtil.promisify)(_nodeChild_process.exec);
|
|
20
|
+
async function syncDatabase() {
|
|
21
|
+
try {
|
|
22
|
+
const root = process.cwd();
|
|
23
|
+
const configPath = _nodePath.default.join(root, "drizzle.config.ts");
|
|
24
|
+
console.log(`[Setup:Actions] Using config: ${configPath}`);
|
|
25
|
+
const {
|
|
26
|
+
stdout,
|
|
27
|
+
stderr
|
|
28
|
+
} = await execAsync(`npx drizzle-kit push --config=${configPath}`, {
|
|
29
|
+
cwd: root,
|
|
30
|
+
env: {
|
|
31
|
+
...process.env,
|
|
32
|
+
// Ensure we are in non-interactive mode if the tool supports it
|
|
33
|
+
CI: "true"
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
console.log("[Setup:Actions] Sync stdout:", stdout);
|
|
37
|
+
if (stderr) console.warn("[Setup:Actions] Sync stderr:", stderr);
|
|
38
|
+
return {
|
|
39
|
+
success: true
|
|
40
|
+
};
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error("[Setup:Actions] Sync failed:", e);
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
error: e.message
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function getAvailableModules() {
|
|
50
|
+
const modules = await (0, _server2.getModules)();
|
|
51
|
+
return modules.filter(m => m.id !== "setup");
|
|
52
|
+
}
|
|
53
|
+
async function finishSetup(formData, selectedModuleIds) {
|
|
54
|
+
const email = formData.get("email");
|
|
55
|
+
const username = formData.get("username");
|
|
56
|
+
const password = formData.get("password");
|
|
57
|
+
if (!email || !username || !password) {
|
|
58
|
+
throw new Error("Missing required fields");
|
|
59
|
+
}
|
|
60
|
+
const user = await (0, _server.createUser)(email, username, password);
|
|
61
|
+
await _server.db.transaction(async tx => {
|
|
62
|
+
await tx.update(_server.userTable).set({
|
|
63
|
+
emailVerifiedAt: /* @__PURE__ */new Date()
|
|
64
|
+
}).where((0, _drizzleOrm.eq)(_server.userTable.id, user.id));
|
|
65
|
+
let [adminRole] = await tx.select().from(_server.rolesTable).where((0, _drizzleOrm.eq)(_server.rolesTable.name, "admin"));
|
|
66
|
+
if (!adminRole) {
|
|
67
|
+
const [newRole] = await tx.insert(_server.rolesTable).values({
|
|
68
|
+
name: "admin",
|
|
69
|
+
description: "System Administrator with full access"
|
|
70
|
+
}).returning();
|
|
71
|
+
adminRole = newRole;
|
|
72
|
+
}
|
|
73
|
+
const systemPermissions = [{
|
|
74
|
+
name: "system:modules",
|
|
75
|
+
description: "Manage system modules"
|
|
76
|
+
}, {
|
|
77
|
+
name: "system:rbac",
|
|
78
|
+
description: "Manage roles and permissions"
|
|
79
|
+
}, {
|
|
80
|
+
name: "system:activity-logs",
|
|
81
|
+
description: "View system activity logs"
|
|
82
|
+
}];
|
|
83
|
+
console.log("Ensuring system permissions exist...");
|
|
84
|
+
for (const perm of systemPermissions) {
|
|
85
|
+
const [existing] = await tx.select().from(_server.permissionsTable).where((0, _drizzleOrm.eq)(_server.permissionsTable.name, perm.name));
|
|
86
|
+
let permId = existing?.id;
|
|
87
|
+
if (!existing) {
|
|
88
|
+
const [inserted] = await tx.insert(_server.permissionsTable).values(perm).returning();
|
|
89
|
+
permId = inserted.id;
|
|
90
|
+
}
|
|
91
|
+
await tx.insert(_server.rolesToPermissionsTable).values({
|
|
92
|
+
roleId: adminRole.id,
|
|
93
|
+
permissionId: permId
|
|
94
|
+
}).onConflictDoNothing();
|
|
95
|
+
}
|
|
96
|
+
await tx.insert(_server.usersToRolesTable).values({
|
|
97
|
+
userId: user.id,
|
|
98
|
+
roleId: adminRole.id
|
|
99
|
+
});
|
|
100
|
+
if (selectedModuleIds.length > 0) {
|
|
101
|
+
for (const modId of selectedModuleIds) {
|
|
102
|
+
await tx.insert(_server.systemModulesTable).values({
|
|
103
|
+
id: modId,
|
|
104
|
+
enabled: true,
|
|
105
|
+
system: true,
|
|
106
|
+
installed: true
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
(0, _navigation.redirect)(await (0, _server2.getKryoPathPrefix)());
|
|
112
|
+
}
|
|
113
|
+
async function checkDbConnection() {
|
|
114
|
+
try {
|
|
115
|
+
await _server.db.execute((0, _drizzleOrm.sql)`SELECT 1`);
|
|
116
|
+
return {
|
|
117
|
+
success: true
|
|
118
|
+
};
|
|
119
|
+
} catch (e) {
|
|
120
|
+
return {
|
|
121
|
+
success: false,
|
|
122
|
+
error: String(e)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function syncDatabase(): Promise<{
|
|
2
|
+
success: boolean;
|
|
3
|
+
error?: undefined;
|
|
4
|
+
} | {
|
|
5
|
+
success: boolean;
|
|
6
|
+
error: any;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function getAvailableModules(): Promise<any>;
|
|
9
|
+
export declare function finishSetup(formData: FormData, selectedModuleIds: string[]): Promise<void>;
|
|
10
|
+
export declare function checkDbConnection(): Promise<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
error?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
success: boolean;
|
|
15
|
+
error: string;
|
|
16
|
+
}>;
|
package/dist/actions.mjs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { exec } from "node:child_process";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import {
|
|
6
|
+
createUser,
|
|
7
|
+
db,
|
|
8
|
+
permissionsTable,
|
|
9
|
+
rolesTable,
|
|
10
|
+
rolesToPermissionsTable,
|
|
11
|
+
systemModulesTable,
|
|
12
|
+
usersToRolesTable,
|
|
13
|
+
userTable
|
|
14
|
+
} from "@arch-cadre/core/server";
|
|
15
|
+
import { getKryoPathPrefix, getModules } from "@arch-cadre/modules/server";
|
|
16
|
+
import { eq, sql } from "drizzle-orm";
|
|
17
|
+
import { redirect } from "next/navigation";
|
|
18
|
+
const execAsync = promisify(exec);
|
|
19
|
+
export async function syncDatabase() {
|
|
20
|
+
try {
|
|
21
|
+
const root = process.cwd();
|
|
22
|
+
const configPath = path.join(root, "drizzle.config.ts");
|
|
23
|
+
console.log(`[Setup:Actions] Using config: ${configPath}`);
|
|
24
|
+
const { stdout, stderr } = await execAsync(
|
|
25
|
+
`npx drizzle-kit push --config=${configPath}`,
|
|
26
|
+
{
|
|
27
|
+
cwd: root,
|
|
28
|
+
env: {
|
|
29
|
+
...process.env,
|
|
30
|
+
// Ensure we are in non-interactive mode if the tool supports it
|
|
31
|
+
CI: "true"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
console.log("[Setup:Actions] Sync stdout:", stdout);
|
|
36
|
+
if (stderr) console.warn("[Setup:Actions] Sync stderr:", stderr);
|
|
37
|
+
return { success: true };
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error("[Setup:Actions] Sync failed:", e);
|
|
40
|
+
return { success: false, error: e.message };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export async function getAvailableModules() {
|
|
44
|
+
const modules = await getModules();
|
|
45
|
+
return modules.filter((m) => m.id !== "setup");
|
|
46
|
+
}
|
|
47
|
+
export async function finishSetup(formData, selectedModuleIds) {
|
|
48
|
+
const email = formData.get("email");
|
|
49
|
+
const username = formData.get("username");
|
|
50
|
+
const password = formData.get("password");
|
|
51
|
+
if (!email || !username || !password) {
|
|
52
|
+
throw new Error("Missing required fields");
|
|
53
|
+
}
|
|
54
|
+
const user = await createUser(email, username, password);
|
|
55
|
+
await db.transaction(async (tx) => {
|
|
56
|
+
await tx.update(userTable).set({
|
|
57
|
+
emailVerifiedAt: /* @__PURE__ */ new Date()
|
|
58
|
+
}).where(eq(userTable.id, user.id));
|
|
59
|
+
let [adminRole] = await tx.select().from(rolesTable).where(eq(rolesTable.name, "admin"));
|
|
60
|
+
if (!adminRole) {
|
|
61
|
+
const [newRole] = await tx.insert(rolesTable).values({
|
|
62
|
+
name: "admin",
|
|
63
|
+
description: "System Administrator with full access"
|
|
64
|
+
}).returning();
|
|
65
|
+
adminRole = newRole;
|
|
66
|
+
}
|
|
67
|
+
const systemPermissions = [
|
|
68
|
+
{ name: "system:modules", description: "Manage system modules" },
|
|
69
|
+
{ name: "system:rbac", description: "Manage roles and permissions" },
|
|
70
|
+
{
|
|
71
|
+
name: "system:activity-logs",
|
|
72
|
+
description: "View system activity logs"
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
console.log("Ensuring system permissions exist...");
|
|
76
|
+
for (const perm of systemPermissions) {
|
|
77
|
+
const [existing] = await tx.select().from(permissionsTable).where(eq(permissionsTable.name, perm.name));
|
|
78
|
+
let permId = existing?.id;
|
|
79
|
+
if (!existing) {
|
|
80
|
+
const [inserted] = await tx.insert(permissionsTable).values(perm).returning();
|
|
81
|
+
permId = inserted.id;
|
|
82
|
+
}
|
|
83
|
+
await tx.insert(rolesToPermissionsTable).values({
|
|
84
|
+
roleId: adminRole.id,
|
|
85
|
+
permissionId: permId
|
|
86
|
+
}).onConflictDoNothing();
|
|
87
|
+
}
|
|
88
|
+
await tx.insert(usersToRolesTable).values({
|
|
89
|
+
userId: user.id,
|
|
90
|
+
roleId: adminRole.id
|
|
91
|
+
});
|
|
92
|
+
if (selectedModuleIds.length > 0) {
|
|
93
|
+
for (const modId of selectedModuleIds) {
|
|
94
|
+
await tx.insert(systemModulesTable).values({
|
|
95
|
+
id: modId,
|
|
96
|
+
enabled: true,
|
|
97
|
+
system: true,
|
|
98
|
+
installed: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
redirect(await getKryoPathPrefix());
|
|
104
|
+
}
|
|
105
|
+
export async function checkDbConnection() {
|
|
106
|
+
try {
|
|
107
|
+
await db.execute(sql`SELECT 1`);
|
|
108
|
+
return { success: true };
|
|
109
|
+
} catch (e) {
|
|
110
|
+
return { success: false, error: String(e) };
|
|
111
|
+
}
|
|
112
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {};
|
|
7
|
+
|
|
8
|
+
var _manifest = _interopRequireDefault(require("../manifest.json"));
|
|
9
|
+
var _routes = require("./routes.cjs");
|
|
10
|
+
var _actions = require("./actions.cjs");
|
|
11
|
+
Object.keys(_actions).forEach(function (key) {
|
|
12
|
+
if (key === "default" || key === "__esModule") return;
|
|
13
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
14
|
+
if (key in exports && exports[key] === _actions[key]) return;
|
|
15
|
+
Object.defineProperty(exports, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () {
|
|
18
|
+
return _actions[key];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
|
+
const setupModule = {
|
|
24
|
+
manifest: _manifest.default,
|
|
25
|
+
init: async () => {
|
|
26
|
+
console.log("[SetupModule] initialized.");
|
|
27
|
+
},
|
|
28
|
+
routes: {
|
|
29
|
+
public: _routes.publicRoutes
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
module.exports = setupModule;
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import manifest from "../manifest.json";
|
|
2
|
+
import { publicRoutes } from "./routes.mjs";
|
|
3
|
+
export * from "./actions.mjs";
|
|
4
|
+
const setupModule = {
|
|
5
|
+
manifest,
|
|
6
|
+
init: async () => {
|
|
7
|
+
console.log("[SetupModule] initialized.");
|
|
8
|
+
},
|
|
9
|
+
routes: {
|
|
10
|
+
public: publicRoutes
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export default setupModule;
|
package/dist/intl.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type messages from "../locales/en/global.json";
|
|
2
|
+
|
|
3
|
+
type JsonDataType = typeof messages;
|
|
4
|
+
|
|
5
|
+
// declare global {
|
|
6
|
+
// interface IntlMessages extends JsonDataType {}
|
|
7
|
+
// }
|
|
8
|
+
|
|
9
|
+
declare module "@arch-cadre/intl" {
|
|
10
|
+
export interface IntlMessages extends JsonDataType {}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {};
|
package/dist/routes.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.publicRoutes = void 0;
|
|
7
|
+
var _setupWizard = require("./ui/pages/setup-wizard.cjs");
|
|
8
|
+
const publicRoutes = exports.publicRoutes = [{
|
|
9
|
+
path: "/setup",
|
|
10
|
+
component: _setupWizard.SetupWizard,
|
|
11
|
+
auth: false
|
|
12
|
+
}];
|
package/dist/routes.d.ts
ADDED
package/dist/routes.mjs
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SetupWizard = SetupWizard;
|
|
8
|
+
var _intl = require("@arch-cadre/intl");
|
|
9
|
+
var _ui = require("@arch-cadre/ui");
|
|
10
|
+
var _logo = require("@arch-cadre/ui/brand/logo");
|
|
11
|
+
var _loader = require("@arch-cadre/ui/shared/loader");
|
|
12
|
+
var _lucideReact = require("lucide-react");
|
|
13
|
+
var React = _interopRequireWildcard(require("react"));
|
|
14
|
+
var _actions = require("../../actions.cjs");
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
function SetupWizard() {
|
|
18
|
+
const {
|
|
19
|
+
t
|
|
20
|
+
} = (0, _intl.useTranslation)();
|
|
21
|
+
const [step, setStep] = React.useState(1);
|
|
22
|
+
const [loading, setLoading] = React.useState(false);
|
|
23
|
+
const [syncStatus, setSyncStatus] = React.useState("idle");
|
|
24
|
+
const [availableModules, setAvailableModules] = React.useState([]);
|
|
25
|
+
const [selectedModules, setSelectedModules] = React.useState([]);
|
|
26
|
+
const nextStep = () => setStep(s => s + 1);
|
|
27
|
+
const handleSync = async () => {
|
|
28
|
+
setSyncStatus("syncing");
|
|
29
|
+
const result = await (0, _actions.syncDatabase)();
|
|
30
|
+
if (result.success) {
|
|
31
|
+
setSyncStatus("success");
|
|
32
|
+
const modules = await (0, _actions.getAvailableModules)();
|
|
33
|
+
setAvailableModules(modules.filter(m => !m.system));
|
|
34
|
+
setSelectedModules(modules.filter(m => m.system).map(m => m.id));
|
|
35
|
+
setTimeout(nextStep, 1500);
|
|
36
|
+
} else {
|
|
37
|
+
setSyncStatus("error");
|
|
38
|
+
alert(`Database sync failed: ${result.error}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const toggleModule = id => {
|
|
42
|
+
setSelectedModules(prev => prev.includes(id) ? prev.filter(m => m !== id) : [...prev, id]);
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */React.createElement("div", {
|
|
45
|
+
className: "min-h-screen flex items-center justify-center bg-muted/30 p-4"
|
|
46
|
+
}, /* @__PURE__ */React.createElement("div", {
|
|
47
|
+
className: "w-full max-w-md space-y-8"
|
|
48
|
+
}, /* @__PURE__ */React.createElement("div", {
|
|
49
|
+
className: "flex flex-col gap-4 items-center justify-center text-center"
|
|
50
|
+
}, /* @__PURE__ */React.createElement(_logo.Logo, {
|
|
51
|
+
className: "mx-auto"
|
|
52
|
+
}), /* @__PURE__ */React.createElement("p", {
|
|
53
|
+
className: "mt-2 text-sm text-muted-foreground"
|
|
54
|
+
}, t("setup_description"))), /* @__PURE__ */React.createElement(_ui.Card, {
|
|
55
|
+
className: "border-2 shadow-xl"
|
|
56
|
+
}, step === 1 && /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement(_ui.CardHeader, null, /* @__PURE__ */React.createElement(_ui.CardTitle, {
|
|
57
|
+
className: "flex items-center gap-2"
|
|
58
|
+
}, /* @__PURE__ */React.createElement(_lucideReact.Rocket, {
|
|
59
|
+
className: "h-5 w-5 text-primary"
|
|
60
|
+
}), t("welcome")), /* @__PURE__ */React.createElement(_ui.CardDescription, null, t("thank_you"))), /* @__PURE__ */React.createElement(_ui.CardContent, null, /* @__PURE__ */React.createElement("div", {
|
|
61
|
+
className: "space-y-4"
|
|
62
|
+
}, /* @__PURE__ */React.createElement("p", {
|
|
63
|
+
className: "text-sm"
|
|
64
|
+
}, t("step_1_desc")))), /* @__PURE__ */React.createElement(_ui.CardFooter, null, /* @__PURE__ */React.createElement(_ui.Button, {
|
|
65
|
+
onClick: nextStep,
|
|
66
|
+
className: "w-full"
|
|
67
|
+
}, t("get_started")))), step === 2 && /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement(_ui.CardHeader, null, /* @__PURE__ */React.createElement(_ui.CardTitle, {
|
|
68
|
+
className: "flex items-center gap-2"
|
|
69
|
+
}, /* @__PURE__ */React.createElement(_lucideReact.Database, {
|
|
70
|
+
className: "h-5 w-5 text-primary"
|
|
71
|
+
}), t("db_prep")), /* @__PURE__ */React.createElement(_ui.CardDescription, null, t("db_desc"))), /* @__PURE__ */React.createElement(_ui.CardContent, {
|
|
72
|
+
className: "flex flex-col items-center justify-center py-6"
|
|
73
|
+
}, syncStatus === "idle" && /* @__PURE__ */React.createElement(_lucideReact.Database, {
|
|
74
|
+
className: "h-12 w-12 text-muted-foreground mb-4"
|
|
75
|
+
}), syncStatus === "syncing" && /* @__PURE__ */React.createElement(_loader.Loader, {
|
|
76
|
+
className: "h-12 w-12 text-primary animate-spin mb-4"
|
|
77
|
+
}), syncStatus === "success" && /* @__PURE__ */React.createElement(_lucideReact.CheckCircle2, {
|
|
78
|
+
className: "h-12 w-12 text-green-500 mb-4"
|
|
79
|
+
}), /* @__PURE__ */React.createElement("p", {
|
|
80
|
+
className: "text-center text-sm font-medium"
|
|
81
|
+
}, syncStatus === "idle" && t("db_ready_to_sync"), syncStatus === "syncing" && t("db_creating_tables"), syncStatus === "success" && t("db_ready"), syncStatus === "error" && t("db_sync_failed"))), /* @__PURE__ */React.createElement(_ui.CardFooter, null, /* @__PURE__ */React.createElement(_ui.Button, {
|
|
82
|
+
onClick: handleSync,
|
|
83
|
+
className: "w-full",
|
|
84
|
+
disabled: syncStatus === "syncing" || syncStatus === "success"
|
|
85
|
+
}, syncStatus === "syncing" ? t("db_syncing_btn") : t("db_init_btn")))), step === 3 && /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement(_ui.CardHeader, null, /* @__PURE__ */React.createElement(_ui.CardTitle, {
|
|
86
|
+
className: "flex items-center gap-2"
|
|
87
|
+
}, /* @__PURE__ */React.createElement(_lucideReact.LayoutGrid, {
|
|
88
|
+
className: "h-5 w-5 text-primary"
|
|
89
|
+
}), t("select_modules")), /* @__PURE__ */React.createElement(_ui.CardDescription, null, t("select_modules_desc"))), /* @__PURE__ */React.createElement(_ui.CardContent, {
|
|
90
|
+
className: "space-y-4 max-h-[300px] overflow-y-auto"
|
|
91
|
+
}, availableModules.map(mod => /* @__PURE__ */React.createElement("label", {
|
|
92
|
+
htmlFor: mod.id,
|
|
93
|
+
key: mod.id,
|
|
94
|
+
className: "cursor-pointer flex items-start space-x-3 space-y-0 rounded-md border p-3"
|
|
95
|
+
}, /* @__PURE__ */React.createElement(_ui.Checkbox, {
|
|
96
|
+
id: mod.id,
|
|
97
|
+
checked: selectedModules.includes(mod.id),
|
|
98
|
+
onCheckedChange: () => toggleModule(mod.id),
|
|
99
|
+
disabled: mod.system
|
|
100
|
+
}), /* @__PURE__ */React.createElement("div", {
|
|
101
|
+
className: "grid gap-1.5 leading-none"
|
|
102
|
+
}, /* @__PURE__ */React.createElement("div", {
|
|
103
|
+
className: "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 flex items-center gap-2"
|
|
104
|
+
}, mod.name, mod.system && /* @__PURE__ */React.createElement(_ui.Badge, {
|
|
105
|
+
variant: "outline",
|
|
106
|
+
className: "text-[10px] h-4"
|
|
107
|
+
}, "System")), /* @__PURE__ */React.createElement("p", {
|
|
108
|
+
className: "text-xs text-muted-foreground"
|
|
109
|
+
}, mod.description || "No description available."))))), /* @__PURE__ */React.createElement(_ui.CardFooter, null, /* @__PURE__ */React.createElement(_ui.Button, {
|
|
110
|
+
onClick: nextStep,
|
|
111
|
+
className: "w-full"
|
|
112
|
+
}, t("continue_to_admin")))), step === 4 && /* @__PURE__ */React.createElement("form", {
|
|
113
|
+
action: async formData => {
|
|
114
|
+
setLoading(true);
|
|
115
|
+
try {
|
|
116
|
+
await (0, _actions.finishSetup)(formData, selectedModules);
|
|
117
|
+
} catch (_e) {
|
|
118
|
+
setLoading(false);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}, /* @__PURE__ */React.createElement(_ui.CardHeader, null, /* @__PURE__ */React.createElement(_ui.CardTitle, {
|
|
122
|
+
className: "flex items-center gap-2"
|
|
123
|
+
}, /* @__PURE__ */React.createElement(_lucideReact.UserPlus, {
|
|
124
|
+
className: "h-5 w-5 text-primary"
|
|
125
|
+
}), t("admin_account")), /* @__PURE__ */React.createElement(_ui.CardDescription, null, t("admin_description"))), /* @__PURE__ */React.createElement(_ui.CardContent, {
|
|
126
|
+
className: "space-y-4"
|
|
127
|
+
}, /* @__PURE__ */React.createElement("div", {
|
|
128
|
+
className: "space-y-2"
|
|
129
|
+
}, /* @__PURE__ */React.createElement("label", {
|
|
130
|
+
className: "text-sm font-medium"
|
|
131
|
+
}, t("username")), /* @__PURE__ */React.createElement(_ui.Input, {
|
|
132
|
+
name: "username",
|
|
133
|
+
placeholder: "admin",
|
|
134
|
+
required: true
|
|
135
|
+
})), /* @__PURE__ */React.createElement("div", {
|
|
136
|
+
className: "space-y-2"
|
|
137
|
+
}, /* @__PURE__ */React.createElement("label", {
|
|
138
|
+
className: "text-sm font-medium"
|
|
139
|
+
}, t("email")), /* @__PURE__ */React.createElement(_ui.Input, {
|
|
140
|
+
name: "email",
|
|
141
|
+
type: "email",
|
|
142
|
+
placeholder: "admin@kryo.io",
|
|
143
|
+
required: true
|
|
144
|
+
})), /* @__PURE__ */React.createElement("div", {
|
|
145
|
+
className: "space-y-2"
|
|
146
|
+
}, /* @__PURE__ */React.createElement("label", {
|
|
147
|
+
className: "text-sm font-medium"
|
|
148
|
+
}, t("password")), /* @__PURE__ */React.createElement(_ui.Input, {
|
|
149
|
+
name: "password",
|
|
150
|
+
type: "password",
|
|
151
|
+
required: true
|
|
152
|
+
}))), /* @__PURE__ */React.createElement(_ui.CardFooter, {
|
|
153
|
+
className: "mt-4"
|
|
154
|
+
}, /* @__PURE__ */React.createElement(_ui.Button, {
|
|
155
|
+
type: "submit",
|
|
156
|
+
className: "w-full",
|
|
157
|
+
disabled: loading
|
|
158
|
+
}, loading ? /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement(_loader.Loader, {
|
|
159
|
+
className: "mr-2 h-4 w-4 animate-spin"
|
|
160
|
+
}), t("setting_up")) : t("complete"))))), /* @__PURE__ */React.createElement("div", {
|
|
161
|
+
className: "flex justify-center gap-2"
|
|
162
|
+
}, [1, 2, 3, 4].map(s => /* @__PURE__ */React.createElement("div", {
|
|
163
|
+
key: s,
|
|
164
|
+
className: `h-1.5 w-8 rounded-full transition-colors ${step >= s ? "bg-primary" : "bg-primary/10"}`
|
|
165
|
+
})))));
|
|
166
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useTranslation } from "@arch-cadre/intl";
|
|
3
|
+
import {
|
|
4
|
+
Badge,
|
|
5
|
+
Button,
|
|
6
|
+
Card,
|
|
7
|
+
CardContent,
|
|
8
|
+
CardDescription,
|
|
9
|
+
CardFooter,
|
|
10
|
+
CardHeader,
|
|
11
|
+
CardTitle,
|
|
12
|
+
Checkbox,
|
|
13
|
+
Input
|
|
14
|
+
} from "@arch-cadre/ui";
|
|
15
|
+
import { Logo } from "@arch-cadre/ui/brand/logo";
|
|
16
|
+
import { Loader } from "@arch-cadre/ui/shared/loader";
|
|
17
|
+
import {
|
|
18
|
+
CheckCircle2,
|
|
19
|
+
Database,
|
|
20
|
+
LayoutGrid,
|
|
21
|
+
Rocket,
|
|
22
|
+
UserPlus
|
|
23
|
+
} from "lucide-react";
|
|
24
|
+
import * as React from "react";
|
|
25
|
+
import { finishSetup, getAvailableModules, syncDatabase } from "../../actions.mjs";
|
|
26
|
+
export function SetupWizard() {
|
|
27
|
+
const { t } = useTranslation();
|
|
28
|
+
const [step, setStep] = React.useState(1);
|
|
29
|
+
const [loading, setLoading] = React.useState(false);
|
|
30
|
+
const [syncStatus, setSyncStatus] = React.useState("idle");
|
|
31
|
+
const [availableModules, setAvailableModules] = React.useState([]);
|
|
32
|
+
const [selectedModules, setSelectedModules] = React.useState([]);
|
|
33
|
+
const nextStep = () => setStep((s) => s + 1);
|
|
34
|
+
const handleSync = async () => {
|
|
35
|
+
setSyncStatus("syncing");
|
|
36
|
+
const result = await syncDatabase();
|
|
37
|
+
if (result.success) {
|
|
38
|
+
setSyncStatus("success");
|
|
39
|
+
const modules = await getAvailableModules();
|
|
40
|
+
setAvailableModules(modules.filter((m) => !m.system));
|
|
41
|
+
setSelectedModules(modules.filter((m) => m.system).map((m) => m.id));
|
|
42
|
+
setTimeout(nextStep, 1500);
|
|
43
|
+
} else {
|
|
44
|
+
setSyncStatus("error");
|
|
45
|
+
alert(`Database sync failed: ${result.error}`);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const toggleModule = (id) => {
|
|
49
|
+
setSelectedModules(
|
|
50
|
+
(prev) => prev.includes(id) ? prev.filter((m) => m !== id) : [...prev, id]
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
return /* @__PURE__ */ React.createElement("div", { className: "min-h-screen flex items-center justify-center bg-muted/30 p-4" }, /* @__PURE__ */ React.createElement("div", { className: "w-full max-w-md space-y-8" }, /* @__PURE__ */ React.createElement("div", { className: "flex flex-col gap-4 items-center justify-center text-center" }, /* @__PURE__ */ React.createElement(Logo, { className: "mx-auto" }), /* @__PURE__ */ React.createElement("p", { className: "mt-2 text-sm text-muted-foreground" }, t("setup_description"))), /* @__PURE__ */ React.createElement(Card, { className: "border-2 shadow-xl" }, step === 1 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(CardTitle, { className: "flex items-center gap-2" }, /* @__PURE__ */ React.createElement(Rocket, { className: "h-5 w-5 text-primary" }), t("welcome")), /* @__PURE__ */ React.createElement(CardDescription, null, t("thank_you"))), /* @__PURE__ */ React.createElement(CardContent, null, /* @__PURE__ */ React.createElement("div", { className: "space-y-4" }, /* @__PURE__ */ React.createElement("p", { className: "text-sm" }, t("step_1_desc")))), /* @__PURE__ */ React.createElement(CardFooter, null, /* @__PURE__ */ React.createElement(Button, { onClick: nextStep, className: "w-full" }, t("get_started")))), step === 2 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(CardTitle, { className: "flex items-center gap-2" }, /* @__PURE__ */ React.createElement(Database, { className: "h-5 w-5 text-primary" }), t("db_prep")), /* @__PURE__ */ React.createElement(CardDescription, null, t("db_desc"))), /* @__PURE__ */ React.createElement(CardContent, { className: "flex flex-col items-center justify-center py-6" }, syncStatus === "idle" && /* @__PURE__ */ React.createElement(Database, { className: "h-12 w-12 text-muted-foreground mb-4" }), syncStatus === "syncing" && /* @__PURE__ */ React.createElement(Loader, { className: "h-12 w-12 text-primary animate-spin mb-4" }), syncStatus === "success" && /* @__PURE__ */ React.createElement(CheckCircle2, { className: "h-12 w-12 text-green-500 mb-4" }), /* @__PURE__ */ React.createElement("p", { className: "text-center text-sm font-medium" }, syncStatus === "idle" && t("db_ready_to_sync"), syncStatus === "syncing" && t("db_creating_tables"), syncStatus === "success" && t("db_ready"), syncStatus === "error" && t("db_sync_failed"))), /* @__PURE__ */ React.createElement(CardFooter, null, /* @__PURE__ */ React.createElement(
|
|
54
|
+
Button,
|
|
55
|
+
{
|
|
56
|
+
onClick: handleSync,
|
|
57
|
+
className: "w-full",
|
|
58
|
+
disabled: syncStatus === "syncing" || syncStatus === "success"
|
|
59
|
+
},
|
|
60
|
+
syncStatus === "syncing" ? t("db_syncing_btn") : t("db_init_btn")
|
|
61
|
+
))), step === 3 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(CardTitle, { className: "flex items-center gap-2" }, /* @__PURE__ */ React.createElement(LayoutGrid, { className: "h-5 w-5 text-primary" }), t("select_modules")), /* @__PURE__ */ React.createElement(CardDescription, null, t("select_modules_desc"))), /* @__PURE__ */ React.createElement(CardContent, { className: "space-y-4 max-h-[300px] overflow-y-auto" }, availableModules.map((mod) => /* @__PURE__ */ React.createElement(
|
|
62
|
+
"label",
|
|
63
|
+
{
|
|
64
|
+
htmlFor: mod.id,
|
|
65
|
+
key: mod.id,
|
|
66
|
+
className: "cursor-pointer flex items-start space-x-3 space-y-0 rounded-md border p-3"
|
|
67
|
+
},
|
|
68
|
+
/* @__PURE__ */ React.createElement(
|
|
69
|
+
Checkbox,
|
|
70
|
+
{
|
|
71
|
+
id: mod.id,
|
|
72
|
+
checked: selectedModules.includes(mod.id),
|
|
73
|
+
onCheckedChange: () => toggleModule(mod.id),
|
|
74
|
+
disabled: mod.system
|
|
75
|
+
}
|
|
76
|
+
),
|
|
77
|
+
/* @__PURE__ */ React.createElement("div", { className: "grid gap-1.5 leading-none" }, /* @__PURE__ */ React.createElement("div", { className: "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 flex items-center gap-2" }, mod.name, mod.system && /* @__PURE__ */ React.createElement(Badge, { variant: "outline", className: "text-[10px] h-4" }, "System")), /* @__PURE__ */ React.createElement("p", { className: "text-xs text-muted-foreground" }, mod.description || "No description available."))
|
|
78
|
+
))), /* @__PURE__ */ React.createElement(CardFooter, null, /* @__PURE__ */ React.createElement(Button, { onClick: nextStep, className: "w-full" }, t("continue_to_admin")))), step === 4 && /* @__PURE__ */ React.createElement(
|
|
79
|
+
"form",
|
|
80
|
+
{
|
|
81
|
+
action: async (formData) => {
|
|
82
|
+
setLoading(true);
|
|
83
|
+
try {
|
|
84
|
+
await finishSetup(formData, selectedModules);
|
|
85
|
+
} catch (_e) {
|
|
86
|
+
setLoading(false);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
/* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(CardTitle, { className: "flex items-center gap-2" }, /* @__PURE__ */ React.createElement(UserPlus, { className: "h-5 w-5 text-primary" }), t("admin_account")), /* @__PURE__ */ React.createElement(CardDescription, null, t("admin_description"))),
|
|
91
|
+
/* @__PURE__ */ React.createElement(CardContent, { className: "space-y-4" }, /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("label", { className: "text-sm font-medium" }, t("username")), /* @__PURE__ */ React.createElement(Input, { name: "username", placeholder: "admin", required: true })), /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("label", { className: "text-sm font-medium" }, t("email")), /* @__PURE__ */ React.createElement(
|
|
92
|
+
Input,
|
|
93
|
+
{
|
|
94
|
+
name: "email",
|
|
95
|
+
type: "email",
|
|
96
|
+
placeholder: "admin@kryo.io",
|
|
97
|
+
required: true
|
|
98
|
+
}
|
|
99
|
+
)), /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("label", { className: "text-sm font-medium" }, t("password")), /* @__PURE__ */ React.createElement(Input, { name: "password", type: "password", required: true }))),
|
|
100
|
+
/* @__PURE__ */ React.createElement(CardFooter, { className: "mt-4" }, /* @__PURE__ */ React.createElement(Button, { type: "submit", className: "w-full", disabled: loading }, loading ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Loader, { className: "mr-2 h-4 w-4 animate-spin" }), t("setting_up")) : t("complete")))
|
|
101
|
+
)), /* @__PURE__ */ React.createElement("div", { className: "flex justify-center gap-2" }, [1, 2, 3, 4].map((s) => /* @__PURE__ */ React.createElement(
|
|
102
|
+
"div",
|
|
103
|
+
{
|
|
104
|
+
key: s,
|
|
105
|
+
className: `h-1.5 w-8 rounded-full transition-colors ${step >= s ? "bg-primary" : "bg-primary/10"}`
|
|
106
|
+
}
|
|
107
|
+
)))));
|
|
108
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"setup_description": "setup_description",
|
|
3
|
+
"welcome": "welcome",
|
|
4
|
+
"thank_you": "thank_you",
|
|
5
|
+
"step_1_desc": "step_1_desc",
|
|
6
|
+
"get_started": "get_started",
|
|
7
|
+
"db_prep": "db_prep",
|
|
8
|
+
"db_desc": "db_desc",
|
|
9
|
+
"db_ready_to_sync": "db_ready_to_sync",
|
|
10
|
+
"db_creating_tables": "db_creating_tables",
|
|
11
|
+
"db_ready": "db_ready",
|
|
12
|
+
"db_sync_failed": "db_sync_failed",
|
|
13
|
+
"db_syncing_btn": "db_syncing_btn",
|
|
14
|
+
"db_init_btn": "db_init_btn",
|
|
15
|
+
"select_modules": "select_modules",
|
|
16
|
+
"select_modules_desc": "select_modules_desc",
|
|
17
|
+
"continue_to_admin": "continue_to_admin",
|
|
18
|
+
"admin_account": "admin_account",
|
|
19
|
+
"admin_description": "admin_description",
|
|
20
|
+
"username": "username",
|
|
21
|
+
"email": "email",
|
|
22
|
+
"password": "password",
|
|
23
|
+
"setting_up": "setting_up",
|
|
24
|
+
"complete": "complete"
|
|
25
|
+
}
|
package/manifest.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arch-cadre/setup",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Installation and setup module for Kryo",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json",
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"locales",
|
|
17
|
+
"manifest.json"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"release": "npm publish --access public --no-git-checks",
|
|
21
|
+
"clean": "rm -rf ./dist",
|
|
22
|
+
"switch:dev": "node scripts/switchToSrc.js",
|
|
23
|
+
"switch:prod": "node scripts/switchToDist.js",
|
|
24
|
+
"build": "unbuild",
|
|
25
|
+
"dev": "unbuild --stub",
|
|
26
|
+
"lint": "biome check --write"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@arch-cadre/modules": "^0.0.15",
|
|
30
|
+
"@arch-cadre/ui": "^0.0.15",
|
|
31
|
+
"drizzle-orm": "1.0.0-beta.15-859cf75",
|
|
32
|
+
"lucide-react": "^0.475.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@arch-cadre/core": "^0.0.15",
|
|
36
|
+
"@types/node": "^20.19.9",
|
|
37
|
+
"@types/react": "^19",
|
|
38
|
+
"@types/react-dom": "^19",
|
|
39
|
+
"next": "16.1.1",
|
|
40
|
+
"typescript": "^5.3.3",
|
|
41
|
+
"unbuild": "^3.6.1"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@arch-cadre/core": "^0.0.15",
|
|
45
|
+
"@arch-cadre/intl": "^0.0.15",
|
|
46
|
+
"next": ">=13.0.0",
|
|
47
|
+
"react": "^19.0.0",
|
|
48
|
+
"react-dom": "^19.0.0"
|
|
49
|
+
},
|
|
50
|
+
"main": "./dist/index.mjs"
|
|
51
|
+
}
|