@vilio/sample-module 0.0.3

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.
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ "use server";
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getSampleConfig = getSampleConfig;
8
+ exports.updateSampleConfig = updateSampleConfig;
9
+ var _core = require("@vilio/core");
10
+ var _server = require("@vilio/core/server");
11
+ var _server2 = require("@vilio/modules/server");
12
+ var _cache = require("next/cache");
13
+ async function getSampleConfig() {
14
+ const config = await (0, _server2.getModuleConfig)("sample-module");
15
+ return config ?? {
16
+ defaultVar: ""
17
+ };
18
+ }
19
+ async function updateSampleConfig(config) {
20
+ await (0, _server2.updateModuleConfig)("sample-module", config);
21
+ (0, _cache.revalidatePath)(`${(0, _server2.getVilioPathPrefix)()}/sample-module/settings`);
22
+ const {
23
+ user
24
+ } = await (0, _server.getCurrentSession)();
25
+ await _core.eventBus.publish("activity.create", {
26
+ action: "sample-module.config.updated",
27
+ description: `User updated sample module config`,
28
+ userId: user?.id,
29
+ metadata: config
30
+ }, "sample-module");
31
+ return {
32
+ success: true
33
+ };
34
+ }
@@ -0,0 +1,7 @@
1
+ export interface SampleConfig {
2
+ defaultVar: string;
3
+ }
4
+ export declare function getSampleConfig(): Promise<any>;
5
+ export declare function updateSampleConfig(config: SampleConfig): Promise<{
6
+ success: boolean;
7
+ }>;
@@ -0,0 +1,31 @@
1
+ "use server";
2
+ import { eventBus } from "@vilio/core";
3
+ import { getCurrentSession } from "@vilio/core/server";
4
+ import {
5
+ getModuleConfig,
6
+ getVilioPathPrefix,
7
+ updateModuleConfig
8
+ } from "@vilio/modules/server";
9
+ import { revalidatePath } from "next/cache";
10
+ export async function getSampleConfig() {
11
+ const config = await getModuleConfig("sample-module");
12
+ return config ?? {
13
+ defaultVar: ""
14
+ };
15
+ }
16
+ export async function updateSampleConfig(config) {
17
+ await updateModuleConfig("sample-module", config);
18
+ revalidatePath(`${getVilioPathPrefix()}/sample-module/settings`);
19
+ const { user } = await getCurrentSession();
20
+ await eventBus.publish(
21
+ "activity.create",
22
+ {
23
+ action: "sample-module.config.updated",
24
+ description: `User updated sample module config`,
25
+ userId: user?.id,
26
+ metadata: config
27
+ },
28
+ "sample-module"
29
+ );
30
+ return { success: true };
31
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _intl = require("@vilio/intl");
8
+ var _global = _interopRequireDefault(require("../locales/en/global.json"));
9
+ var _global2 = _interopRequireDefault(require("../locales/pl/global.json"));
10
+ var _manifest = _interopRequireDefault(require("../manifest.json"));
11
+ var _routes = require("./routes.cjs");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ const _module = {
14
+ manifest: _manifest.default,
15
+ translations: {
16
+ en: _global.default,
17
+ pl: _global2.default
18
+ },
19
+ onEnable: async () => {},
20
+ onDisable: async () => {
21
+ console.log("[Module:Sample] onDisable: Dropping all tables physically...");
22
+ },
23
+ routes: {
24
+ private: _routes.privateRoutes,
25
+ api: _routes.apiRoutes
26
+ },
27
+ navigation: {
28
+ admin: {
29
+ [(0, _intl.i18n)("General")]: [{
30
+ id: "sample-settings",
31
+ title: (0, _intl.i18n)("Sample Configuration"),
32
+ url: "/sample/settings",
33
+ icon: "solar:box-bold-duotone"
34
+ }]
35
+ }
36
+ }
37
+ };
38
+ module.exports = _module;
@@ -0,0 +1,3 @@
1
+ import type { IModule } from "@vilio/modules";
2
+ declare const module: IModule;
3
+ export default module;
package/dist/index.mjs ADDED
@@ -0,0 +1,34 @@
1
+ import { i18n } from "@vilio/intl";
2
+ import localesEn from "../locales/en/global.json" with { type: "json" };
3
+ import localesPl from "../locales/pl/global.json" with { type: "json" };
4
+ import manifest from "../manifest.json";
5
+ import { apiRoutes, privateRoutes } from "./routes.mjs";
6
+ const module = {
7
+ manifest,
8
+ translations: {
9
+ en: localesEn,
10
+ pl: localesPl
11
+ },
12
+ onEnable: async () => {
13
+ },
14
+ onDisable: async () => {
15
+ console.log("[Module:Sample] onDisable: Dropping all tables physically...");
16
+ },
17
+ routes: {
18
+ private: privateRoutes,
19
+ api: apiRoutes
20
+ },
21
+ navigation: {
22
+ admin: {
23
+ [i18n("General")]: [
24
+ {
25
+ id: "sample-settings",
26
+ title: i18n("Sample Configuration"),
27
+ url: "/sample/settings",
28
+ icon: "solar:box-bold-duotone"
29
+ }
30
+ ]
31
+ }
32
+ }
33
+ };
34
+ export default module;
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 "@vilio/intl" {
10
+ export interface IntlMessages extends JsonDataType { }
11
+ }
12
+
13
+ export { };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.privateRoutes = exports.apiRoutes = void 0;
7
+ var _settingsPage = _interopRequireDefault(require("./ui/settings-page.cjs"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ const privateRoutes = exports.privateRoutes = [{
10
+ path: "/sample/settings",
11
+ // Będzie widoczne pod /sample/settings
12
+ component: _settingsPage.default,
13
+ auth: true
14
+ }];
15
+ const apiRoutes = exports.apiRoutes = [];
@@ -0,0 +1,3 @@
1
+ import type { ApiRouteDefinition, PrivateRouteDefinition } from "@vilio/modules";
2
+ export declare const privateRoutes: PrivateRouteDefinition[];
3
+ export declare const apiRoutes: ApiRouteDefinition[];
@@ -0,0 +1,10 @@
1
+ import SampleSettingsPage from "./ui/settings-page.mjs";
2
+ export const privateRoutes = [
3
+ {
4
+ path: "/sample/settings",
5
+ // Będzie widoczne pod /sample/settings
6
+ component: SampleSettingsPage,
7
+ auth: true
8
+ }
9
+ ];
10
+ export const apiRoutes = [];
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sampleTable = exports.sampleSchema = void 0;
7
+ var _core = require("@vilio/core");
8
+ var _pgCore = require("drizzle-orm/pg-core");
9
+ const sampleTable = exports.sampleTable = (0, _pgCore.pgTable)("sample", {
10
+ id: (0, _pgCore.text)("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
11
+ userId: (0, _pgCore.text)("user_id").references(() => _core.userTable.id, {
12
+ onDelete: "cascade"
13
+ }).notNull(),
14
+ createdAt: (0, _pgCore.timestamp)("created_at").defaultNow().notNull()
15
+ });
16
+ const sampleSchema = exports.sampleSchema = {
17
+ sampleTable
18
+ };
@@ -0,0 +1,112 @@
1
+ export declare const sampleTable: import("drizzle-orm/pg-core").PgTableWithColumns<{
2
+ name: "sample";
3
+ schema: undefined;
4
+ columns: {
5
+ id: import("drizzle-orm/pg-core").PgColumn<{
6
+ name: string;
7
+ tableName: "sample";
8
+ dataType: "string";
9
+ data: string;
10
+ driverParam: string;
11
+ notNull: true;
12
+ hasDefault: true;
13
+ isPrimaryKey: true;
14
+ isAutoincrement: false;
15
+ hasRuntimeDefault: true;
16
+ enumValues: [string, ...string[]];
17
+ baseColumn: never;
18
+ identity: undefined;
19
+ generated: undefined;
20
+ }, {}>;
21
+ userId: import("drizzle-orm/pg-core").PgColumn<{
22
+ name: string;
23
+ tableName: "sample";
24
+ dataType: "string";
25
+ data: string;
26
+ driverParam: string;
27
+ notNull: true;
28
+ hasDefault: false;
29
+ isPrimaryKey: false;
30
+ isAutoincrement: false;
31
+ hasRuntimeDefault: false;
32
+ enumValues: [string, ...string[]];
33
+ baseColumn: never;
34
+ identity: undefined;
35
+ generated: undefined;
36
+ }, {}>;
37
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
38
+ name: string;
39
+ tableName: "sample";
40
+ dataType: "object date";
41
+ data: Date;
42
+ driverParam: string;
43
+ notNull: true;
44
+ hasDefault: true;
45
+ isPrimaryKey: false;
46
+ isAutoincrement: false;
47
+ hasRuntimeDefault: false;
48
+ enumValues: undefined;
49
+ baseColumn: never;
50
+ identity: undefined;
51
+ generated: undefined;
52
+ }, {}>;
53
+ };
54
+ dialect: "pg";
55
+ }>;
56
+ export declare const sampleSchema: {
57
+ sampleTable: import("drizzle-orm/pg-core").PgTableWithColumns<{
58
+ name: "sample";
59
+ schema: undefined;
60
+ columns: {
61
+ id: import("drizzle-orm/pg-core").PgColumn<{
62
+ name: string;
63
+ tableName: "sample";
64
+ dataType: "string";
65
+ data: string;
66
+ driverParam: string;
67
+ notNull: true;
68
+ hasDefault: true;
69
+ isPrimaryKey: true;
70
+ isAutoincrement: false;
71
+ hasRuntimeDefault: true;
72
+ enumValues: [string, ...string[]];
73
+ baseColumn: never;
74
+ identity: undefined;
75
+ generated: undefined;
76
+ }, {}>;
77
+ userId: import("drizzle-orm/pg-core").PgColumn<{
78
+ name: string;
79
+ tableName: "sample";
80
+ dataType: "string";
81
+ data: string;
82
+ driverParam: string;
83
+ notNull: true;
84
+ hasDefault: false;
85
+ isPrimaryKey: false;
86
+ isAutoincrement: false;
87
+ hasRuntimeDefault: false;
88
+ enumValues: [string, ...string[]];
89
+ baseColumn: never;
90
+ identity: undefined;
91
+ generated: undefined;
92
+ }, {}>;
93
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
94
+ name: string;
95
+ tableName: "sample";
96
+ dataType: "object date";
97
+ data: Date;
98
+ driverParam: string;
99
+ notNull: true;
100
+ hasDefault: true;
101
+ isPrimaryKey: false;
102
+ isAutoincrement: false;
103
+ hasRuntimeDefault: false;
104
+ enumValues: undefined;
105
+ baseColumn: never;
106
+ identity: undefined;
107
+ generated: undefined;
108
+ }, {}>;
109
+ };
110
+ dialect: "pg";
111
+ }>;
112
+ };
@@ -0,0 +1,10 @@
1
+ import { userTable } from "@vilio/core";
2
+ import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
3
+ export const sampleTable = pgTable("sample", {
4
+ id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
5
+ userId: text("user_id").references(() => userTable.id, { onDelete: "cascade" }).notNull(),
6
+ createdAt: timestamp("created_at").defaultNow().notNull()
7
+ });
8
+ export const sampleSchema = {
9
+ sampleTable
10
+ };
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ "use client";
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ module.exports = SampleSettingsPage;
8
+ var _intl = require("@vilio/intl");
9
+ var _button = require("@vilio/ui/components/button");
10
+ var _card = require("@vilio/ui/components/card");
11
+ var _input = require("@vilio/ui/components/input");
12
+ var _label = require("@vilio/ui/components/label");
13
+ var _react = _interopRequireWildcard(require("react"));
14
+ var React = _react;
15
+ var _sonner = require("sonner");
16
+ var _settings = require("../actions/settings.cjs");
17
+ 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); }
18
+ 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; }
19
+ function SampleSettingsPage() {
20
+ const {
21
+ t
22
+ } = (0, _intl.useTranslation)();
23
+ const [config, setConfig] = (0, _react.useState)({
24
+ defaultVar: ""
25
+ });
26
+ const [loading, setLoading] = (0, _react.useState)(true);
27
+ (0, _react.useEffect)(() => {
28
+ (0, _settings.getSampleConfig)().then(data => {
29
+ setConfig(data);
30
+ setLoading(false);
31
+ });
32
+ }, []);
33
+ const handleSave = async e => {
34
+ e.preventDefault();
35
+ try {
36
+ await (0, _settings.updateSampleConfig)(config);
37
+ _sonner.toast.success(t("Settings saved successfully"));
38
+ } catch {
39
+ _sonner.toast.error(t("Failed to save settings"));
40
+ }
41
+ };
42
+ if (loading) return /* @__PURE__ */React.createElement("div", null, t("Loading Sample Settings..."));
43
+ return /* @__PURE__ */React.createElement("div", {
44
+ className: "container mx-auto py-10 max-w-2xl"
45
+ }, /* @__PURE__ */React.createElement(_card.Card, null, /* @__PURE__ */React.createElement(_card.CardHeader, null, /* @__PURE__ */React.createElement(_card.CardTitle, null, t("Sample Settings")), /* @__PURE__ */React.createElement(_card.CardDescription, null, t("Configure your Sample Configuration."))), /* @__PURE__ */React.createElement(_card.CardContent, null, /* @__PURE__ */React.createElement("form", {
46
+ onSubmit: handleSave,
47
+ className: "space-y-4"
48
+ }, /* @__PURE__ */React.createElement("div", {
49
+ className: "space-y-2"
50
+ }, /* @__PURE__ */React.createElement(_label.Label, {
51
+ htmlFor: "defaultVar"
52
+ }, t("Default Var")), /* @__PURE__ */React.createElement(_input.Input, {
53
+ id: "defaultVar",
54
+ value: config.defaultVar,
55
+ onChange: e => setConfig({
56
+ ...config,
57
+ defaultVar: e.target.value
58
+ }),
59
+ placeholder: ""
60
+ })), /* @__PURE__ */React.createElement(_button.Button, {
61
+ type: "submit",
62
+ className: "w-full"
63
+ }, t("Save Configuration"))))));
64
+ }
@@ -0,0 +1,2 @@
1
+ import * as React from "react";
2
+ export default function SampleSettingsPage(): React.JSX.Element;
@@ -0,0 +1,51 @@
1
+ "use client";
2
+ import { useTranslation } from "@vilio/intl";
3
+ import { Button } from "@vilio/ui/components/button";
4
+ import {
5
+ Card,
6
+ CardContent,
7
+ CardDescription,
8
+ CardHeader,
9
+ CardTitle
10
+ } from "@vilio/ui/components/card";
11
+ import { Input } from "@vilio/ui/components/input";
12
+ import { Label } from "@vilio/ui/components/label";
13
+ import * as React from "react";
14
+ import { useEffect, useState } from "react";
15
+ import { toast } from "sonner";
16
+ import {
17
+ getSampleConfig,
18
+ updateSampleConfig
19
+ } from "../actions/settings.mjs";
20
+ export default function SampleSettingsPage() {
21
+ const { t } = useTranslation();
22
+ const [config, setConfig] = useState({
23
+ defaultVar: ""
24
+ });
25
+ const [loading, setLoading] = useState(true);
26
+ useEffect(() => {
27
+ getSampleConfig().then((data) => {
28
+ setConfig(data);
29
+ setLoading(false);
30
+ });
31
+ }, []);
32
+ const handleSave = async (e) => {
33
+ e.preventDefault();
34
+ try {
35
+ await updateSampleConfig(config);
36
+ toast.success(t("Settings saved successfully"));
37
+ } catch {
38
+ toast.error(t("Failed to save settings"));
39
+ }
40
+ };
41
+ if (loading) return /* @__PURE__ */ React.createElement("div", null, t("Loading Sample Settings..."));
42
+ return /* @__PURE__ */ React.createElement("div", { className: "container mx-auto py-10 max-w-2xl" }, /* @__PURE__ */ React.createElement(Card, null, /* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(CardTitle, null, t("Sample Settings")), /* @__PURE__ */ React.createElement(CardDescription, null, t("Configure your Sample Configuration."))), /* @__PURE__ */ React.createElement(CardContent, null, /* @__PURE__ */ React.createElement("form", { onSubmit: handleSave, className: "space-y-4" }, /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement(Label, { htmlFor: "defaultVar" }, t("Default Var")), /* @__PURE__ */ React.createElement(
43
+ Input,
44
+ {
45
+ id: "defaultVar",
46
+ value: config.defaultVar,
47
+ onChange: (e) => setConfig({ ...config, defaultVar: e.target.value }),
48
+ placeholder: ""
49
+ }
50
+ )), /* @__PURE__ */ React.createElement(Button, { type: "submit", className: "w-full" }, t("Save Configuration"))))));
51
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "Settings saved successfully": "Settings saved successfully",
3
+ "Failed to save settings": "Failed to save settings",
4
+ "Loading Sample Settings...": "Loading Sample Settings...",
5
+ "Sample Settings": "Sample Settings",
6
+ "Configure your Sample Configuration.": "Configure your Sample Configuration.",
7
+ "Default Var": "Default Var",
8
+ "Save Configuration": "Save Configuration",
9
+ "General": "General",
10
+ "Sample Configuration": "Sample Configuration"
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "Settings saved successfully": "Ustawienia zostały zapisane pomyślnie",
3
+ "Failed to save settings": "Nie udało się zapisać ustawień",
4
+ "Loading Sample Settings...": "Ładowanie przykładowych ustawień...",
5
+ "Sample Settings": "Przykładowe ustawienia",
6
+ "Configure your Sample Configuration.": "Skonfiguruj swoją przykładową konfigurację.",
7
+ "Default Var": "Domyślna zmienna",
8
+ "Save Configuration": "Zapisz konfigurację",
9
+ "General": "Ogólny",
10
+ "Sample Configuration": "Przykładowa konfiguracja"
11
+ }
package/manifest.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "sample-module",
3
+ "name": "Sample Module",
4
+ "version": "0.0.1",
5
+ "description": "Sample module to vilio-framework",
6
+ "enabled": true,
7
+ "system": false,
8
+ "dependencies": ["blog-module"],
9
+ "extends": [],
10
+ "isNpm": true
11
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@vilio/sample-module",
3
+ "version": "0.0.3",
4
+ "description": "Sample module for Vilio framework",
5
+ "type": "module",
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
+ "dev": "unbuild --stub",
25
+ "build": "unbuild"
26
+ },
27
+ "dependencies": {
28
+ "@hookform/resolvers": "^3.10.0",
29
+ "@vilio/ui": "^0.0.4",
30
+ "@vilio/modules": "^0.0.4",
31
+ "lucide-react": "^0.475.0",
32
+ "react-hook-form": "^7.54.2",
33
+ "drizzle-orm": "1.0.0-beta.6-4414a19",
34
+ "sonner": "^2.0.7",
35
+ "zod": "^3.24.1"
36
+ },
37
+ "devDependencies": {
38
+ "@vilio/core": "^0.0.4",
39
+ "@types/react": "^19",
40
+ "next": "16.1.1",
41
+ "react": "^19.0.0",
42
+ "typescript": "^5.3.3",
43
+ "unbuild": "^3.6.1"
44
+ },
45
+ "peerDependencies": {
46
+ "@vilio/core": "^0.0.4",
47
+ "@vilio/intl": "^0.0.4",
48
+ "@vilio/ui": "^0.0.4",
49
+ "next": ">=13.0.0",
50
+ "react": "^19.0.0"
51
+ },
52
+ "main": "./dist/index.mjs"
53
+ }