seishiro 0.2.2-release → 0.2.4-release

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 CHANGED
@@ -1,114 +1,100 @@
1
1
  # Seishiro API
2
2
 
3
- Seishiro eliminates the complexity of routing folder structures and replaces them with a single control center. Just use one endpoint, manage it through the Registry, and control your entire application data flow (Web, Mobile, and SSR) with consistent standards.
3
+ > [!CAUTION]
4
+ > This library is currently in development. Although several stable versions have been released, it is not yet ready for production use. Please review its usage carefully. At this time, it only supports the Next.js, Express.js, and Nova.js frameworks.
5
+ >
6
+ > Thank you for using this library. If you encounter any issues, please report them so we can address them in the development version.
7
+
8
+ Seishiro **eliminates the complexity of routing folder structures and replaces them with a single control center**. Just use one endpoint, manage it through the Registry, and control your entire application data flow (Web, Mobile, and SSR) with consistent standards.
9
+
10
+ ## Features
11
+
12
+ - **Centralized Registry**: Manage all your application logic in one place.
13
+ - **Built-in Policy**: Control versioning and access rules with ease.
14
+ - **Smart Messaging**: Multi-language support with dynamic variables.
15
+ - **Protocol Agnostic**: Works seamlessly with REST APIs, Server Actions (Next.js), and SSR.
16
+ - **Secure by Default**: Registry list encryption using AES-256-CTR.
4
17
 
5
18
  ## Installation
6
19
 
7
- 1. Manual Library Installation
8
-
9
- ```sh
10
- npm install seishiro
11
- # OR
12
- bun add seishiro
13
- # OR
14
- yarn add seishiro
15
- ```
16
-
17
- 2. Copy the file example and then copy some of its structure for the sample. You can manage this system to be much more complex.
18
- 3. Set up and customize it as you like.
19
- 4. Add auth-cookie to put the default placeholder and client version.
20
- 5. Boom! Done!
21
-
22
- ## Usage
23
-
24
- ```js
25
- import dotenv from "dotenv"
26
- import { UserLogin, UserProfile } from "@/controllers"
27
- import { MiddlewareSystem } from "@/middlewares"
28
- import { RegistryBuilder, MessageBuilder, PolicyBuilder, Actions } from "seishiro"
29
-
30
- // Init ENV
31
- dotenv.config()
32
-
33
- // Registry
34
- const registry = new RegistryBuilder()
35
- registry.set("user:login", UserLogin)
36
- registry.set("user:profile", UserProfile, MiddlewareSystem) // Using Middleware
37
-
38
- // Message Error
39
- const message = new MessageBuilder("en")
40
- // Default Variable Message
41
- message.set("no-response-sending", "Server not response!");
42
- message.set("no-registry", "Registry not found!");
43
- message.set("internal-server-error", "Internal server error!");
44
- // Costum Variable Message
45
- message.set("user-not-login", "{{username}} has not login!")
46
- message.set("user-not-found", "{{username}} not found!")
47
-
48
- // Rules System
49
- const policy = new PolicyBuilder({
50
- passkey: process.env.SEISHIRO_PASSKEY, // (Require!) For Book Registry Access
51
- version_now: "1.4.5", // (Require!) Only support number (0-9.)
52
- version_min: "1.4.0", // (Require!) Minimum version
53
- version_forceupdate: true, // (Require!) If client on minimum version, client need to force update
54
- })
55
- policy.noaction("user:login", ["server-action"]) // block from server action
56
- policy.noaction("user:login", ["api-action"]) // block from api action
57
-
58
- // Action Setup
59
- const action = new Actions({
60
- registry: registry,
61
- message: message,
62
- policy: policy,
63
- })
64
-
65
- // System Action - For Server Side Rendering
66
- const sysaction = await action.SystemAction({
67
- system: {
68
- headers: {...}, // Header KV (Key, Value)
69
- cookies: {...}, // Cookie KV (Key, Value)
70
- ip: "127.0.0.1", // IP Address (IP Client - Example)
71
- location: "JKT, Jakarta, Jakarta Pusat", // Location (Location Client By IP & PeerDB - Example)
72
- },
73
- type: "user:login", // Type Action
74
- data: {
75
- email: "testing@localhost.id",
76
- password: "testing1234"
77
- }
78
- })
79
- console.log(sysaction.response) // Response Data
80
-
81
- // Server Action - For Server Action (Next.js)
82
- const serveraction = await action.ServerAction({
83
- system: {
84
- headers: {...}, // Header KV (Key, Value)
85
- cookies: {...}, // Cookie KV (Key, Value)
86
- ip: "127.0.0.1", // IP Address (IP Client - Example)
87
- location: "JKT, Jakarta, Jakarta Pusat", // Location (Location Client By IP & PeerDB - Example)
88
- },
89
- type: "user:profile", // Type Action
20
+ To get started with Seishiro, install it via your favorite package manager:
21
+
22
+ ```bash
23
+ # npm
24
+ npm install seishiro
25
+ # bun
26
+ bun add seishiro
27
+ # yarn
28
+ yarn add seishiro
29
+ # pnpm
30
+ pnpm add seishiro
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ Seishiro's workflow is built around three pillars: **Registry, Message, and Policy.**
36
+
37
+ ```javascript
38
+ import { Registry, Message, Policy, Actions } from "seishiro";
39
+
40
+ // 1. Setup Registry (Your Business Logic)
41
+ const registry = new Registry();
42
+ registry.set("user:login", UserLogin);
43
+ registry.set("user:profile", UserProfile, [AuthMiddleware]); // Supports Middlewares!
44
+
45
+ // 2. Setup Messaging (Multi-language Support)
46
+ const message = new Message("en");
47
+ message.set("user-not-found", "{{username}} not found!");
48
+
49
+ // 3. Setup Policy (Access & Versioning Control)
50
+ const policy = new Policy({
51
+ passkey: process.env.SEISHIRO_PASSKEY,
52
+ version_now: "1.0.0",
53
+ version_min: "0.9.0",
54
+ version_forceupdate: true,
55
+ });
56
+
57
+ // 4. Initialize Action Center
58
+ const action = new Actions({ registry, message, policy });
59
+
60
+ // 5. Execute - Choose your protocol!
61
+ const response = await action.APIAction({
62
+ type: "user:login",
90
63
  data: {
91
- username: "testing1234"
64
+ email: "user@example.com",
65
+ password: "password123"
92
66
  }
93
- })
94
- console.log(serveraction.response) // Response Data
95
-
96
- // API Action - For Rest API
97
- const apiaction = action.APIAction({
98
- system: {
99
- headers: {...}, // Header KV (Key, Value)
100
- cookies: {...}, // Cookie KV (Key, Value)
101
- ip: "127.0.0.1", // IP Address (IP Client - Example)
102
- location: "JKT, Jakarta, Jakarta Pusat", // Location (Location Client By IP & PeerDB - Example)
103
- },
104
- type: "user:profile", // Type Action
105
- data: {
106
- username: "testing1234"
107
- }
108
- })
109
- console.log(apiaction.response) // Response Data
67
+ });
68
+
69
+ console.log(response.response);
70
+ ```
71
+
72
+ ### Modern Architecture
73
+
74
+ | Component | Description |
75
+ | :--- | :--- |
76
+ | **Registry** | Maps action types to their corresponding controllers and middlewares. |
77
+ | **Message** | Handles all system responses and multi-language error messages. |
78
+ | **Policy** | Enforces security, versioning, and access control for specific actions. |
79
+ | **Action** | The execution engine that processes requests through the system. |
80
+
81
+ ## Learn More
82
+
83
+ Ready to dive deeper? Explore our specialized documentation and framework integrations.
84
+
85
+ ### Framework Integrations
86
+
87
+ > [!IMPORTANT]
88
+ > Action Tools is now available, but some features require improvements to function properly. Currently, there are no benchmarks and testing for multiple REST API frameworks, and for now, Action Tools is primarily focused on Next.js, Express.js, and Zod as validators.
89
+
90
+ We provide specialized tools and examples for modern web frameworks:
91
+
92
+ - [Zod Validation (Library validator)](./docs/action-tool/zod-validate.md) - ✅ Stable
93
+ - [Next.js](./docs/action-tool/action-next.md) - ✅ Stable
94
+ - [Elysia JS](./docs/action-tool/action-elysia.md) - ⚠️ Work in progress & Testing
95
+ - [Hono](./docs/action-tool/action-hono.md) - ⚠️ Work in progress & Testing
96
+ - [Express](./docs/action-tool/action-express.md) - ⚠️ Need to fix
97
+ - [Fastify](./docs/action-tool/action-fastify.md) - ⚠️ Work in progress & Testing
98
+
99
+ Explore all action tools here: [**Action Tools Documentation**](./docs/action-tool)
110
100
 
111
- // Book Registry (List All Registry On Base Encrypted)
112
- const bookRegistryJson = action.BookRegistry()
113
- console.log(bookRegistryJson)
114
- ```
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=t,exports.ActionResponse=r;const e=require("../utils/system-helpers.js");async function t(t){const r=(0,e.mapHeaders)(t.request.headers),s={};t.cookie&&Object.entries(t.cookie).forEach(([e,t])=>s[e]=String(t.value).trim());const o=t.body||{};return{system:{headers:r,cookies:s,ip:(0,e.getIp)(r,t.request.headers.get("x-real-ip")),location:(0,e.getLocation)(r)},type:String(o?.type||""),data:o?.data||{}}}function r(e,t){if(!t.redirect)return Array.isArray(t.header)&&t.header.forEach(t=>{t.key&&t.value&&(e.headers[t.key]=t.value)}),e.status=t.status||200,t.response||{};e.redirect=t.redirect}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=t,exports.ActionResponse=r;const e=require("../utils/system-helpers.js");async function t(t){const r=(0,e.mapHeaders)(t.request.headers),s={};t.cookie&&Object.entries(t.cookie).forEach(([e,t])=>s[e]=String(t.value).trim());const o=t.body||{};return{system:{headers:r,cookies:s,ip:(0,e.getIp)(r,t.request.headers.get("x-real-ip")),location:(0,e.getLocation)(r)},type:String(o?.type||""),data:o?.data||{}}}function r(e,t){if(!t?.redirect)return Array.isArray(t.header)&&t.header.forEach(t=>{t.key&&t.value&&(e.headers[t.key]=t.value)}),e.status=t.status||200,t.response||{};e.redirect=t.redirect}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=r,exports.ActionResponse=o;const e=require("../utils/system-helpers.js");function r(r){const o=(0,e.mapHeaders)(r.headers),t={};r.cookies&&Object.entries(r.cookies).forEach(([e,r])=>t[e]=String(r).trim());const s=r.body||{};return{system:{headers:o,cookies:t,ip:(0,e.getIp)(o,r.ip||r.connection?.remoteAddress),location:(0,e.getLocation)(o)},type:String(s?.type||""),data:s?.data||{}}}function o(e,r){return r.redirect?e.redirect(r.redirect):(e.status(r.status||200),Array.isArray(r.header)&&r.header.forEach(r=>{r.key&&r.value&&e.set(r.key,r.value)}),Array.isArray(r.set_cookie)&&r.set_cookie.forEach(r=>{r.key&&r.value&&e.cookie(r.key,r.value,r.options||{})}),Array.isArray(r.rm_cookie)&&r.rm_cookie.forEach(r=>{const o="string"==typeof r?r:r?.key;o&&e.clearCookie(o)}),e.json(r.response||{}))}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=r,exports.ActionResponse=o;const e=require("../utils/system-helpers.js");function r(r){const o=(0,e.mapHeaders)(r.headers),t={};r.cookies&&Object.entries(r.cookies).forEach(([e,r])=>t[e]=String(r).trim());const s=r.body||{};return{system:{headers:o,cookies:t,ip:(0,e.getIp)(o,r.ip||r.connection?.remoteAddress),location:(0,e.getLocation)(o)},type:String(s?.type||""),data:s?.data||{}}}function o(e,r){return r?.redirect?e.redirect(r.redirect):(e.status(r.status||200),Array.isArray(r.header)&&r.header.forEach(r=>{r.key&&r.value&&e.set(r.key,r.value)}),Array.isArray(r.set_cookie)&&r.set_cookie.forEach(r=>{r.key&&r.value&&e.cookie(r.key,r.value,r.options||{})}),Array.isArray(r.rm_cookie)&&r.rm_cookie.forEach(r=>{const o="string"==typeof r?r:r?.key;o&&e.clearCookie(o)}),e.json(r.response||{}))}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=o,exports.ActionResponse=r;const e=require("../utils/system-helpers.js");function o(o){const r=(0,e.mapHeaders)(o.headers),t={};o.cookies&&Object.entries(o.cookies).forEach(([e,o])=>t[e]=String(o).trim());const s=o.body||{};return{system:{headers:r,cookies:t,ip:(0,e.getIp)(r,o.ip),location:(0,e.getLocation)(r)},type:String(s?.type||""),data:s?.data||{}}}function r(e,o){return o.redirect?e.redirect(o.redirect):(Array.isArray(o.header)&&o.header.forEach(o=>{o.key&&o.value&&e.header(o.key,o.value)}),Array.isArray(o.set_cookie)&&o.set_cookie.forEach(o=>{o.key&&o.value&&"function"==typeof e.setCookie?e.setCookie(o.key,o.value,o.options||{}):o.key&&o.value&&e.header("Set-Cookie",`${o.key}=${o.value}`,{append:!0})}),Array.isArray(o.rm_cookie)&&o.rm_cookie.forEach(o=>{const r="string"==typeof o?o:o?.key;r&&"function"==typeof e.clearCookie&&e.clearCookie(r)}),e.code(o.status||200).send(o.response||{}))}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=o,exports.ActionResponse=r;const e=require("../utils/system-helpers.js");function o(o){const r=(0,e.mapHeaders)(o.headers),t={};o.cookies&&Object.entries(o.cookies).forEach(([e,o])=>t[e]=String(o).trim());const s=o.body||{};return{system:{headers:r,cookies:t,ip:(0,e.getIp)(r,o.ip),location:(0,e.getLocation)(r)},type:String(s?.type||""),data:s?.data||{}}}function r(e,o){return o?.redirect?e.redirect(o.redirect):(Array.isArray(o.header)&&o.header.forEach(o=>{o.key&&o.value&&e.header(o.key,o.value)}),Array.isArray(o.set_cookie)&&o.set_cookie.forEach(o=>{o.key&&o.value&&"function"==typeof e.setCookie?e.setCookie(o.key,o.value,o.options||{}):o.key&&o.value&&e.header("Set-Cookie",`${o.key}=${o.value}`,{append:!0})}),Array.isArray(o.rm_cookie)&&o.rm_cookie.forEach(o=>{const r="string"==typeof o?o:o?.key;r&&"function"==typeof e.clearCookie&&e.clearCookie(r)}),e.code(o.status||200).send(o.response||{}))}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=t,exports.ActionResponse=r;const e=require("../utils/system-helpers.js");async function t(t){const r=(0,e.mapHeaders)(t.req.header()),a={};(t.req.header("cookie")||"").split(";").forEach(e=>{const[t,r]=e.split("=").map(e=>e.trim());t&&r&&(a[t]=r)});let s={type:"",data:{}};try{s=(t.req.header("content-type")||"").includes("json")?await t.req.json():await t.req.parseBody()}catch(e){}return{system:{headers:r,cookies:a,ip:(0,e.getIp)(r),location:(0,e.getLocation)(r)},type:String(s?.type||""),data:s?.data||{}}}function r(e,t){return t.redirect?e.redirect(t.redirect):(Array.isArray(t.header)&&t.header.forEach(t=>{t.key&&t.value&&e.header(t.key,t.value)}),Array.isArray(t.set_cookie)&&t.set_cookie.forEach(t=>{t.key&&t.value&&e.header("Set-Cookie",`${t.key}=${t.value}`,{append:!0})}),e.json(t.response||{},t.status||200))}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=t,exports.ActionResponse=r;const e=require("../utils/system-helpers.js");async function t(t){const r=(0,e.mapHeaders)(t.req.header()),a={};(t.req.header("cookie")||"").split(";").forEach(e=>{const[t,r]=e.split("=").map(e=>e.trim());t&&r&&(a[t]=r)});let s={type:"",data:{}};try{s=(t.req.header("content-type")||"").includes("json")?await t.req.json():await t.req.parseBody()}catch(e){}return{system:{headers:r,cookies:a,ip:(0,e.getIp)(r),location:(0,e.getLocation)(r)},type:String(s?.type||""),data:s?.data||{}}}function r(e,t){return t?.redirect?e.redirect(t.redirect):(Array.isArray(t.header)&&t.header.forEach(t=>{t.key&&t.value&&e.header(t.key,t.value)}),Array.isArray(t.set_cookie)&&t.set_cookie.forEach(t=>{t.key&&t.value&&e.header("Set-Cookie",`${t.key}=${t.value}`,{append:!0})}),e.json(t.response||{},t.status||200))}
@@ -1 +1 @@
1
- "use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},r(e)};return function(o){if(o&&o.__esModule)return o;var n={};if(null!=o)for(var i=r(o),s=0;s<i.length;s++)"default"!==i[s]&&e(n,o,i[s]);return t(n,o),n}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=n,exports.ActionResponse=i;const o=require("../utils/system-helpers.js");async function n(e){const{headers:t,cookies:n}=await Promise.resolve().then(()=>r(require("next/headers"))),{ipAddress:i}=await Promise.resolve().then(()=>r(require("@vercel/functions"))),s=await t(),a=await n(),c=(0,o.mapHeaders)(s),u=(0,o.getIp)(c,"function"==typeof i?i({headers:s}):void 0),l=(0,o.getLocation)(c),f=s.get("content-type")||"";let d={type:"",data:{}};try{if(f.includes("application/json"))d=await e.json();else if(f.includes("multipart/form-data")||f.includes("application/x-www-form-urlencoded")){const t=await e.formData(),r={};for(const[e,o]of t.entries()){const t=e.split(".");let n=r;for(let e=0;e<t.length;e++){const r=t[e];if(e===t.length-1)if(o instanceof Blob){const e=await o.arrayBuffer();n[r]=Buffer.from(e)}else n[r]=o;else n[r]=n[r]||{},n=n[r]}}d=r}}catch(e){console.error("[Seishiro ActionRequest]: Body parsing failed:",e.message)}const p={},y=a.getAll();if(Array.isArray(y))for(const e of y)p[e.name]=String(e.value).trim();return{system:{headers:c,cookies:p,ip:u,location:l},type:String(d?.type||""),data:d?.data||{}}}async function i(e,t){const{NextResponse:o}=await Promise.resolve().then(()=>r(require("next/server")));if(t.redirect)return o.redirect(new URL(t.redirect,e.url));const n=o.json(t.response||{},{status:t.status||200});return Array.isArray(t.header)&&t.header.forEach(e=>{e.key&&e.value&&n.headers.set(e.key,e.value)}),Array.isArray(t.set_cookie)&&t.set_cookie.forEach(e=>{e.key&&e.value&&n.cookies.set(e.key,e.value,e.options||{})}),Array.isArray(t.rm_cookie)&&t.rm_cookie.forEach(e=>{const t="string"==typeof e?e:e?.key;t&&n.cookies.delete(t)}),n}
1
+ "use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},r(e)};return function(o){if(o&&o.__esModule)return o;var i={};if(null!=o)for(var n=r(o),s=0;s<n.length;s++)"default"!==n[s]&&e(i,o,n[s]);return t(i,o),i}}(),o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionRequest=s,exports.ActionResponse=a;const i=require("../utils/system-helpers.js"),n=o(require("../utils/format-value.js"));async function s(e){const{headers:t,cookies:o}=await Promise.resolve().then(()=>r(require("next/headers"))),{ipAddress:s}=await Promise.resolve().then(()=>r(require("@vercel/functions"))),a=await t(),c=await o(),u=(0,i.mapHeaders)(a),l=(0,i.getIp)(u,"function"==typeof s?s({headers:a}):void 0),f=(0,i.getLocation)(u),d=a.get("content-type")||"";let p={type:"",data:{}};try{if(d.includes("application/json"))p=await e.json();else if(d.includes("multipart/form-data")||d.includes("application/x-www-form-urlencoded")){const t=await e.formData(),r={};for(const[e,o]of t.entries()){const t=e.split(".");let i=r;for(let e=0;e<t.length;e++){const r=t[e];if(e===t.length-1)if(o instanceof Blob){const e=await o.arrayBuffer();i[r]=Buffer.from(e)}else i[r]=(0,n.default)(o);else i[r]=i[r]||{},i=i[r]}}p=r}}catch(e){console.error("[Seishiro ActionRequest]: Body parsing failed:",e.message)}const y={},h=c.getAll();if(Array.isArray(h))for(const e of h)y[e.name]=String(e.value).trim();return{system:{headers:u,cookies:y,ip:l,location:f},type:String(p?.type||""),data:p?.data||{}}}async function a(e,t){const{NextResponse:o}=await Promise.resolve().then(()=>r(require("next/server")));if(t?.redirect)return o.redirect(new URL(t.redirect,e.url));const i=o.json(t.response||{},{status:t.status||200});return Array.isArray(t.header)&&t.header.forEach(e=>{e.key&&e.value&&i.headers.set(e.key,e.value)}),Array.isArray(t.set_cookie)&&t.set_cookie.forEach(e=>{e.key&&e.value&&i.cookies.set(e.key,e.value,e.options||{})}),Array.isArray(t.rm_cookie)&&t.rm_cookie.forEach(e=>{const t="string"==typeof e?e:e?.key;t&&i.cookies.delete(t)}),i}
package/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},r(e)};return function(o){if(o&&o.__esModule)return o;var i={};if(null!=o)for(var n=r(o),u=0;u<n.length;u++)"default"!==n[u]&&e(i,o,n[u]);return t(i,o),i}}(),o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionTools=exports.Actions=exports.PolicyBuilder=exports.MessageBuilder=exports.RegistryBuilder=void 0;const i=o(require("./action-tool/zod-validate.js")),n=r(require("./action-tool/action-next.js")),u=r(require("./action-tool/action-express.js")),a=r(require("./action-tool/action-hono.js")),s=r(require("./action-tool/action-fastify.js")),l=r(require("./action-tool/action-elysia.js"));var c=require("./lib/registry.js");Object.defineProperty(exports,"RegistryBuilder",{enumerable:!0,get:function(){return o(c).default}});var f=require("./lib/message.js");Object.defineProperty(exports,"MessageBuilder",{enumerable:!0,get:function(){return o(f).default}});var d=require("./lib/policy.js");Object.defineProperty(exports,"PolicyBuilder",{enumerable:!0,get:function(){return o(d).default}});var p=require("./lib/actions.js");Object.defineProperty(exports,"Actions",{enumerable:!0,get:function(){return o(p).default}}),exports.ActionTools={ZodValidatorContent:i.default,NextJS:n,ExpressJS:u,Hono:a,Fastify:s,Elysia:l};
1
+ "use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},r(e)};return function(o){if(o&&o.__esModule)return o;var i={};if(null!=o)for(var s=r(o),n=0;n<s.length;n++)"default"!==s[n]&&e(i,o,s[n]);return t(i,o),i}}(),o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionTools=exports.PolicyBuilder=exports.MessageBuilder=exports.RegistryBuilder=exports.Policy=exports.Message=exports.Registry=exports.Actions=void 0;const i=o(require("./action-tool/zod-validate.js")),s=r(require("./action-tool/action-next.js")),n=r(require("./action-tool/action-express.js")),a=r(require("./action-tool/action-hono.js")),u=r(require("./action-tool/action-fastify.js")),l=r(require("./action-tool/action-elysia.js")),c=o(require("./lib/registry.js"));exports.Registry=c.default;const d=o(require("./lib/message.js"));exports.Message=d.default;const f=o(require("./lib/policy.js"));exports.Policy=f.default;var p=require("./lib/actions.js");function g(e,t,r){return new Proxy(e,{construct:(e,o)=>(console.warn(`[Seishiro Deprecation Warning]: '${t}' is deprecated and will be removed in future versions. Please use '${r}' instead.`),new e(...o)),get:(e,o)=>("prototype"!==o&&"name"!==o&&console.warn(`[Seishiro Deprecation Warning]: Accessing '${t}.${String(o)}' is deprecated. Please use '${r}' instead.`),e[o])})}Object.defineProperty(exports,"Actions",{enumerable:!0,get:function(){return o(p).default}}),exports.RegistryBuilder=g(c.default,"RegistryBuilder","Registry"),exports.MessageBuilder=g(d.default,"MessageBuilder","Message"),exports.PolicyBuilder=g(f.default,"PolicyBuilder","Policy"),exports.ActionTools={ZodValidatorContent:i.default,NextJS:s,ExpressJS:n,Hono:a,Fastify:u,Elysia:l};
@@ -1 +1 @@
1
- "use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const t=e(require("../utils/extract-lang.js")),r=e(require("crypto")),s=require("buffer");class i{registry;message;policy;heading;cache_book;constructor({registry:e,message:t,policy:r,heading:s={version:"x-seishiro-client",lang:"x-seishiro-lang"}}){this.registry=e,this.message=t,this.policy=r,this.heading=s,this.cache_book=null}BookRegistry(){if(this.cache_book)return this.cache_book;const e="hex",t=r.default.randomBytes(16),i=this.policy.apply(),a=this.registry.apply(),n=r.default.createHash("sha256").update(String(i.passkey||"").trim()).digest(),o={listkey:Object.keys(a).filter(e=>!i.noaction_api.includes(e)),version_now:i.version_now,version_min:i.version_min,version_forceupdate:i.version_forceupdate},c=r.default.createCipheriv("aes-256-ctr",n,t),l=s.Buffer.concat([t,c.update(JSON.stringify(o),"utf-8"),c.final()]),d={iv_length:16,type_base:e,iv:t.toString(e),data:l.toString(e)};return this.cache_book=d,d}ResponseBuilder(e={},t,r="en"){const s=!e||"object"!=typeof e||Array.isArray(e)||!!e.error||!e.data,i=e?.status||(s?400:200),a={header:Object.entries(e?.headers||{}).filter(([e,t])=>void 0!==t).map(([e,t])=>({key:e,value:t})),set_cookie:(Array.isArray(e?.set_cookie)?e.set_cookie:[]).filter(e=>e?.key&&e?.value),rm_cookie:(Array.isArray(e?.rm_cookie)?e.rm_cookie:[]).filter(e=>"string"==typeof e||e?.key),status:i,redirect:e?.redirect||null};if(s){const t=e?.error||"system:no-response-sending",s=this.message.error(t,e?.params||[],r);return{...a,error:t,response:{status:i,message:s.message,protocol:s.protocol,context:s.context,params:s.params}}}return{...a,error:null,response:{status:i,data:e.data||{}}}}async SystemAction({system:e,middleware:r={},context_manager:s="system-action",type:i,data:a}){const n=(0,t.default)(e?.headers?.[this.heading.lang]||e?.headers?.["accept-language"]||e?.lang||"en");try{const t=this.policy.apply(),o=String(e?.headers?.[this.heading.version]||"").trim();if("api-action"===s&&!o)return this.ResponseBuilder({error:"system:client-version-required",status:400},e,n);if(o&&"api-action"===s){const r=this.policy.version_info(o);if(!r.is_version_min&&r.info_upgrade)return this.ResponseBuilder({error:"system:need-upgrade-client",status:426,params:[{min:t.version_min,now:t.version_now}]},e,n)}const c=this.registry.get(i||"");if(!c)return this.ResponseBuilder({error:"system:no-registry",status:404},e,n);const l={...e,lang:n};let d=r,u=c;if(Array.isArray(c)){const[e,s]=c,o=await e({system:l,middleware:r,type:i,data:a});d=t.skip_middleware_context||o?.skipBuilder?o:this.ResponseBuilder(o,l,n),u=s}const y=await u({system:l,middleware:d,type:i,data:a});return this.ResponseBuilder(y,l,n)}catch(t){return console.error("[Seishiro Core Error]:",t),this.ResponseBuilder({error:"system:internal-server-error",status:500},e,n)}}async ServerAction({system:e,middleware:r,type:s,data:i}){if(this.policy.apply().noaction_server.includes(s||"")){const r=(0,t.default)(e?.headers?.[this.heading.lang]||e?.headers?.["accept-language"]||e?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},e,r)}return this.SystemAction({system:e,middleware:r,context_manager:"server-action",type:s,data:i})}async APIAction({system:e,middleware:r,type:s,data:i}){if(this.policy.apply().noaction_api.includes(s||"")){const r=(0,t.default)(e?.headers?.[this.heading.lang]||e?.headers?.["accept-language"]||e?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},e,r)}return this.SystemAction({system:e,middleware:r,context_manager:"api-action",type:s,data:i})}}exports.default=i;
1
+ "use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const t=e(require("../utils/extract-lang.js")),r=e(require("crypto")),s=require("buffer");class i{registry;message;policy;heading;cache_book;constructor({registry:e,message:t,policy:r,heading:s={version:"x-seishiro-client",lang:"x-seishiro-lang"}}){this.registry=e,this.message=t,this.policy=r,this.heading=s,this.cache_book=null}BookRegistry(){if(this.cache_book)return this.cache_book;const e="hex",t=r.default.randomBytes(16),i=this.policy.apply(),a=this.registry.apply(),o=r.default.createHash("sha256").update(String(i.passkey||"").trim()).digest(),n={listkey:Object.keys(a).filter(e=>!i.noaction_api.includes(e)),version_now:i.version_now,version_min:i.version_min,version_forceupdate:i.version_forceupdate},c=r.default.createCipheriv("aes-256-ctr",o,t),l=s.Buffer.concat([t,c.update(JSON.stringify(n),"utf-8"),c.final()]),d={iv_length:16,type_base:e,iv:t.toString(e),data:l.toString(e)};return this.cache_book=d,d}ResponseBuilder(e={},t,r="en"){const s=!e||"object"!=typeof e||Array.isArray(e)||!!e.error||!e.data,i=e?.status||(s?400:200),a={header:Object.entries(e?.headers||{}).filter(([e,t])=>void 0!==t).map(([e,t])=>({key:e,value:t})),set_cookie:(Array.isArray(e?.set_cookie)?e.set_cookie:[]).filter(e=>e?.key&&e?.value),rm_cookie:(Array.isArray(e?.rm_cookie)?e.rm_cookie:[]).filter(e=>"string"==typeof e||e?.key),status:i,redirect:e?.redirect||null};if(s){const t=e?.error||"system:no-response-sending",s=this.message.error(t,e?.params||[],r);return{...a,error:t,response:{status:i,message:s.message,protocol:s.protocol,context:s.context,params:s.params}}}return{...a,error:null,response:{status:i,data:e.data||{}}}}async SystemAction({system:e,middleware:r={},context_manager:s="system-action",type:i,data:a}){const o=(0,t.default)(e?.headers?.[this.heading.lang]||e?.headers?.["accept-language"]||e?.lang||"en");try{const t=this.policy.apply(),n=String(e?.headers?.[this.heading.version]||"").trim();if("api-action"===s&&!n)return this.ResponseBuilder({error:"system:client-version-required",status:400},e,o);if(n&&"api-action"===s){const r=this.policy.version_info(n);if(!r.is_version_min&&r.info_upgrade)return this.ResponseBuilder({error:"system:need-upgrade-client",status:426,params:[{min:t.version_min,now:t.version_now}]},e,o)}const c=this.registry.get(i||"");if(!c)return this.ResponseBuilder({error:"system:no-registry",status:404},e,o);const l={...e,lang:o};let d=r,u=c;if(Array.isArray(c)){const[e,r]=c,s=Array.isArray(e)?e:[e],n=[];for(const e of s){const r=await e({system:l,middleware:n,type:i,data:a});if(r?.error&&t.catch_middleware_context)return this.ResponseBuilder(r,l,o);n.push(r)}d=n,u=r}const y=await u({system:l,middleware:d,type:i,data:a});return this.ResponseBuilder(y,l,o)}catch(t){return console.error("[Seishiro Core Error]:",t),this.ResponseBuilder({error:"system:internal-server-error",status:500},e,o)}}async ServerAction({system:e,middleware:r,type:s,data:i}){if(this.policy.apply().noaction_server.includes(s||"")){const r=(0,t.default)(e?.headers?.[this.heading.lang]||e?.headers?.["accept-language"]||e?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},e,r)}return this.SystemAction({system:e,middleware:r,context_manager:"server-action",type:s,data:i})}async APIAction({system:e,middleware:r,type:s,data:i}){if(this.policy.apply().noaction_api.includes(s||"")){const r=(0,t.default)(e?.headers?.[this.heading.lang]||e?.headers?.["accept-language"]||e?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},e,r)}return this.SystemAction({system:e,middleware:r,context_manager:"api-action",type:s,data:i})}}exports.default=i;
@@ -1 +1 @@
1
- "use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const s=e(require("../utils/format-key.js")),t=require("../constants/message.js");class a{message_build_lang="";message_logic=new Map;constructor(e="en"){this.message_build_lang=String(e||"en").toLowerCase().replace(/[^a-z]/g,"").slice(0,2),this.message_logic=new Map}set(e,t){if("string"!=typeof t||"string"!=typeof e)throw new Error("Key and Value must be string!");this.message_logic.has(this.message_build_lang)||this.message_logic.set(this.message_build_lang,new Map),this.message_logic.get(this.message_build_lang).set((0,s.default)(e),t.trim())}get(e="",a=this.message_build_lang){const i=(0,s.default)(e);let g=this.message_logic.get(a);return g||(g=this.message_logic.get(t.DefaultLanguage),!g&&this.message_logic.size>0&&(g=this.message_logic.values().next().value)),g?g.get(i)||"":`[!NoneVariable ${i}]`}errorMessage(e="",s={},t=this.message_build_lang){const a=this.get(e,t);return s&&0!==Object.keys(s).length?a.replace(/{{(\w+)}}/g,(e,t)=>s[t]||e):a}error(e="",t=[],a=this.message_build_lang){const i=e.indexOf(":");if(-1===i)return{protocol:"unknown",context:[e],params:t,message:e};const g=(0,s.default)(e.substring(0,i)),r=e.substring(i+1).split("|");let l="";for(let e=0;e<r.length;e++){l+=(0===e?"":", ")+this.errorMessage(r[e],t[e],a)}return{protocol:g,context:r,params:t,message:l}}apply(){return this.message_logic}use(e){if(e instanceof a)e.apply().forEach((e,s)=>{const t=this.message_logic.get(s)||new Map;this.message_logic.has(s)||this.message_logic.set(s,t),e.forEach((e,s)=>t.set(s,e))});else{if("object"!=typeof e||!e)throw new Error("Invalid 'use' input!");Object.entries(e).forEach(([e,s])=>this.set(e,String(s)))}}}exports.default=a;
1
+ "use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const s=e(require("../utils/format-key.js")),t=require("../constants/message.js");class r{message_build_lang="";message_logic=new Map;constructor(e="en"){this.message_build_lang=String(e||"en").toLowerCase().replace(/[^a-z]/g,"").slice(0,2),this.message_logic.set(this.message_build_lang,new Map([["no-response-sending","Server returned no response."],["client-version-required","Client version header is required."],["need-upgrade-client","Please upgrade your application."],["no-registry","Service registry not found."],["internal-server-error","Internal server error."]]))}set(e,t){if("string"!=typeof t||"string"!=typeof e)throw new Error("Key and Value must be string!");this.message_logic.has(this.message_build_lang)||this.message_logic.set(this.message_build_lang,new Map),this.message_logic.get(this.message_build_lang).set((0,s.default)(e),t.trim())}get(e="",r=this.message_build_lang){const i=(0,s.default)(e);let a=this.message_logic.get(r);return a||(a=this.message_logic.get(t.DefaultLanguage),!a&&this.message_logic.size>0&&(a=this.message_logic.values().next().value)),a?a.get(i)||"":`[!NoneVariable ${i}]`}errorMessage(e="",s={},t=this.message_build_lang){const r=this.get(e,t);return s&&0!==Object.keys(s).length?r.replace(/{{(\w+)}}/g,(e,t)=>s[t]||e):r}error(e="",t=[],r=this.message_build_lang){const i=e.indexOf(":");if(-1===i)return{protocol:"unknown",context:[e],params:t,message:e};const a=(0,s.default)(e.substring(0,i)),n=e.substring(i+1).split("|");let g="";for(let e=0;e<n.length;e++){g+=(0===e?"":", ")+this.errorMessage(n[e],t[e],r)}return{protocol:a,context:n,params:t,message:g}}apply(){return this.message_logic}use(e){if(e instanceof r)e.apply().forEach((e,s)=>{const t=this.message_logic.get(s)||new Map;this.message_logic.has(s)||this.message_logic.set(s,t),e.forEach((e,s)=>t.set(s,e))});else{if("object"!=typeof e||!e)throw new Error("Invalid 'use' input!");Object.entries(e).forEach(([e,s])=>this.set(e,String(s)))}}}exports.default=r;
package/cjs/lib/policy.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e{passkey;version_now;version_min;version_forceupdate;noaction_api;noaction_server;compiled_policy=null;skip_middleware_context;parsed_min;parsed_now;constructor({passkey:e,version_now:i,version_min:o,version_forceupdate:s=!0,skip_middleware_context:r=!1}){if(!e||!i||!o)throw new Error("PolicyBuilder: passkey, version_now, and version_min are required!");this.passkey=e,this.version_now=i,this.version_min=o,this.parsed_min=this.parseVersion(o),this.parsed_now=this.parseVersion(i),this.version_forceupdate=s,this.noaction_api=[],this.noaction_server=[],this.skip_middleware_context=r,this.refresh()}noaction(e="",i=[]){const o=["server-action","api-action"];for(let e of i)if(!o.includes(e))throw new Error(`Invalid action type: ${e}. Only allowed actions are: ${o.join(", ")}`);if("string"!=typeof e)throw new Error("Invalid key type, it only string!");for(let o of i)"api-action"===o?this.noaction_api.push(e):"server-action"===o&&this.noaction_server.push(e)}parseVersion(e){return e.split(".").map(Number)}compare(e,i){const o=Math.max(e.length,i.length);for(let s=0;s<o;s++){const o=e[s]||0,r=i[s]||0;if(o!==r)return o>r?1:-1}return 0}version_info(e=""){const i=this.parseVersion(e);return{info_upgrade:this.version_forceupdate,is_version_min:this.compare(i,this.parsed_min)>=0,is_version_now:this.compare(i,this.parsed_now)>=0}}refresh(){this.compiled_policy={passkey:this.passkey,version_now:this.version_now,version_min:this.version_min,version_forceupdate:this.version_forceupdate,noaction_api:this.noaction_api,noaction_server:this.noaction_server,skip_middleware_context:this.skip_middleware_context}}apply(){return this.compiled_policy}}exports.default=e;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e{passkey;version_now;version_min;version_forceupdate;noaction_api;noaction_server;compiled_policy=null;catch_middleware_context;parsed_min;parsed_now;constructor({passkey:e="seishiro",version_now:i,version_min:o,version_forceupdate:s=!0,catch_middleware_context:r=!0}){if(!e||!i||!o)throw new Error("PolicyBuilder: passkey, version_now, and version_min are required!");"seishiro"===e&&console.warn("[Seishiro/Policy Warn]: Passkey is currently still the default, please change it to a much safer one, it is not recommended to use the default one."),this.passkey=e,this.version_now=i,this.version_min=o,this.parsed_min=this.parseVersion(o),this.parsed_now=this.parseVersion(i),this.version_forceupdate=s,this.noaction_api=[],this.noaction_server=[],this.catch_middleware_context=r,this.refresh()}noaction(e="",i=[]){const o=["server-action","api-action"];for(let e of i)if(!o.includes(e))throw new Error(`Invalid action type: ${e}. Only allowed actions are: ${o.join(", ")}`);if("string"!=typeof e)throw new Error("Invalid key type, it only string!");for(let o of i)"api-action"===o?this.noaction_api.push(e):"server-action"===o&&this.noaction_server.push(e)}parseVersion(e){return e.split(".").map(Number)}compare(e,i){const o=Math.max(e.length,i.length);for(let s=0;s<o;s++){const o=e[s]||0,r=i[s]||0;if(o!==r)return o>r?1:-1}return 0}version_info(e=""){const i=this.parseVersion(e);return{info_upgrade:this.version_forceupdate,is_version_min:this.compare(i,this.parsed_min)>=0,is_version_now:this.compare(i,this.parsed_now)>=0}}refresh(){this.compiled_policy={passkey:this.passkey,version_now:this.version_now,version_min:this.version_min,version_forceupdate:this.version_forceupdate,noaction_api:this.noaction_api,noaction_server:this.noaction_server,catch_middleware_context:this.catch_middleware_context}}apply(){return this.compiled_policy}}exports.default=e;
@@ -1 +1 @@
1
- "use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});const e=t(require("../utils/format-key.js"));class r{registry_logic;constructor(){this.registry_logic=new Map}set(t,r,i){const s=(0,e.default)(t);if("function"!=typeof r)throw new Error("Registry function is only type function!");if("string"!=typeof t)throw new Error("Registry key is only type string!");i&&"function"==typeof i?this.registry_logic.set(s,[i,r]):this.registry_logic.set(s,r)}get(t){const r=(0,e.default)(t);return this.registry_logic.get(r)||void 0}apply(){return this.registry_logic}use(t){if(t instanceof r)t.apply().forEach((t,e)=>this.registry_logic.set(e,t));else{if("object"!=typeof t||!t)throw new Error("Invalid 'use' input!");Object.entries(t).forEach(([t,e])=>{Array.isArray(e)?this.set(t,e[1],e[0]):this.set(t,e)})}}}exports.default=r;
1
+ "use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});const e=t(require("../utils/format-key.js"));class r{registry_logic;constructor(){this.registry_logic=new Map}set(t,r,i){const s=(0,e.default)(t);if("function"!=typeof r)throw new Error("Registry function is only type function!");if("string"!=typeof t)throw new Error("Registry key is only type string!");i&&("function"==typeof i||Array.isArray(i))?this.registry_logic.set(s,[i,r]):this.registry_logic.set(s,r)}get(t){const r=(0,e.default)(t);return this.registry_logic.get(r)||void 0}apply(){return this.registry_logic}use(t){if(t instanceof r)t.apply().forEach((t,e)=>this.registry_logic.set(e,t));else{if("object"!=typeof t||!t)throw new Error("Invalid 'use' input!");Object.entries(t).forEach(([t,e])=>{Array.isArray(e)?this.set(t,e[1],e[0]):this.set(t,e)})}}}exports.default=r;
@@ -0,0 +1 @@
1
+ "use strict";function t(t){if("string"!=typeof t)return t;const r=t.trim(),e=r.toLowerCase();if("true"===e)return!0;if("false"===e)return!1;if("null"===e)return null;if("undefined"!==e){if(""!==r&&!isNaN(Number(r)))return Number(r);if(/^-?\d+n$/.test(r))try{return BigInt(r.slice(0,-1))}catch{return t}if(r.startsWith("[")&&r.endsWith("]")||r.startsWith("{")&&r.endsWith("}"))try{return JSON.parse(r)}catch{return t}return t}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=t;
@@ -1 +1 @@
1
- import{mapHeaders as e,getIp as r,getLocation as t}from"../utils/system-helpers.js";export async function ActionRequest(s){const o=e(s.request.headers),a={};s.cookie&&Object.entries(s.cookie).forEach(([e,r])=>a[e]=String(r.value).trim());const i=s.body||{};return{system:{headers:o,cookies:a,ip:r(o,s.request.headers.get("x-real-ip")),location:t(o)},type:String(i?.type||""),data:i?.data||{}}}export function ActionResponse(e,r){if(!r.redirect)return Array.isArray(r.header)&&r.header.forEach(r=>{r.key&&r.value&&(e.headers[r.key]=r.value)}),e.status=r.status||200,r.response||{};e.redirect=r.redirect}
1
+ import{mapHeaders as e,getIp as r,getLocation as t}from"../utils/system-helpers.js";export async function ActionRequest(s){const o=e(s.request.headers),a={};s.cookie&&Object.entries(s.cookie).forEach(([e,r])=>a[e]=String(r.value).trim());const i=s.body||{};return{system:{headers:o,cookies:a,ip:r(o,s.request.headers.get("x-real-ip")),location:t(o)},type:String(i?.type||""),data:i?.data||{}}}export function ActionResponse(e,r){if(!r?.redirect)return Array.isArray(r.header)&&r.header.forEach(r=>{r.key&&r.value&&(e.headers[r.key]=r.value)}),e.status=r.status||200,r.response||{};e.redirect=r.redirect}
@@ -1 +1 @@
1
- import{mapHeaders as e,getIp as r,getLocation as o}from"../utils/system-helpers.js";export function ActionRequest(t){const s=e(t.headers),i={};t.cookies&&Object.entries(t.cookies).forEach(([e,r])=>i[e]=String(r).trim());const c=t.body||{};return{system:{headers:s,cookies:i,ip:r(s,t.ip||t.connection?.remoteAddress),location:o(s)},type:String(c?.type||""),data:c?.data||{}}}export function ActionResponse(e,r){return r.redirect?e.redirect(r.redirect):(e.status(r.status||200),Array.isArray(r.header)&&r.header.forEach(r=>{r.key&&r.value&&e.set(r.key,r.value)}),Array.isArray(r.set_cookie)&&r.set_cookie.forEach(r=>{r.key&&r.value&&e.cookie(r.key,r.value,r.options||{})}),Array.isArray(r.rm_cookie)&&r.rm_cookie.forEach(r=>{const o="string"==typeof r?r:r?.key;o&&e.clearCookie(o)}),e.json(r.response||{}))}
1
+ import{mapHeaders as e,getIp as r,getLocation as o}from"../utils/system-helpers.js";export function ActionRequest(t){const s=e(t.headers),i={};t.cookies&&Object.entries(t.cookies).forEach(([e,r])=>i[e]=String(r).trim());const c=t.body||{};return{system:{headers:s,cookies:i,ip:r(s,t.ip||t.connection?.remoteAddress),location:o(s)},type:String(c?.type||""),data:c?.data||{}}}export function ActionResponse(e,r){return r?.redirect?e.redirect(r.redirect):(e.status(r.status||200),Array.isArray(r.header)&&r.header.forEach(r=>{r.key&&r.value&&e.set(r.key,r.value)}),Array.isArray(r.set_cookie)&&r.set_cookie.forEach(r=>{r.key&&r.value&&e.cookie(r.key,r.value,r.options||{})}),Array.isArray(r.rm_cookie)&&r.rm_cookie.forEach(r=>{const o="string"==typeof r?r:r?.key;o&&e.clearCookie(o)}),e.json(r.response||{}))}
@@ -1 +1 @@
1
- import{mapHeaders as e,getIp as o,getLocation as r}from"../utils/system-helpers.js";export function ActionRequest(t){const i=e(t.headers),s={};t.cookies&&Object.entries(t.cookies).forEach(([e,o])=>s[e]=String(o).trim());const a=t.body||{};return{system:{headers:i,cookies:s,ip:o(i,t.ip),location:r(i)},type:String(a?.type||""),data:a?.data||{}}}export function ActionResponse(e,o){return o.redirect?e.redirect(o.redirect):(Array.isArray(o.header)&&o.header.forEach(o=>{o.key&&o.value&&e.header(o.key,o.value)}),Array.isArray(o.set_cookie)&&o.set_cookie.forEach(o=>{o.key&&o.value&&"function"==typeof e.setCookie?e.setCookie(o.key,o.value,o.options||{}):o.key&&o.value&&e.header("Set-Cookie",`${o.key}=${o.value}`,{append:!0})}),Array.isArray(o.rm_cookie)&&o.rm_cookie.forEach(o=>{const r="string"==typeof o?o:o?.key;r&&"function"==typeof e.clearCookie&&e.clearCookie(r)}),e.code(o.status||200).send(o.response||{}))}
1
+ import{mapHeaders as e,getIp as o,getLocation as r}from"../utils/system-helpers.js";export function ActionRequest(t){const i=e(t.headers),s={};t.cookies&&Object.entries(t.cookies).forEach(([e,o])=>s[e]=String(o).trim());const a=t.body||{};return{system:{headers:i,cookies:s,ip:o(i,t.ip),location:r(i)},type:String(a?.type||""),data:a?.data||{}}}export function ActionResponse(e,o){return o?.redirect?e.redirect(o.redirect):(Array.isArray(o.header)&&o.header.forEach(o=>{o.key&&o.value&&e.header(o.key,o.value)}),Array.isArray(o.set_cookie)&&o.set_cookie.forEach(o=>{o.key&&o.value&&"function"==typeof e.setCookie?e.setCookie(o.key,o.value,o.options||{}):o.key&&o.value&&e.header("Set-Cookie",`${o.key}=${o.value}`,{append:!0})}),Array.isArray(o.rm_cookie)&&o.rm_cookie.forEach(o=>{const r="string"==typeof o?o:o?.key;r&&"function"==typeof e.clearCookie&&e.clearCookie(r)}),e.code(o.status||200).send(o.response||{}))}
@@ -1 +1 @@
1
- import{mapHeaders as e,getIp as r,getLocation as t}from"../utils/system-helpers.js";export async function ActionRequest(a){const o=e(a.req.header()),s={};(a.req.header("cookie")||"").split(";").forEach(e=>{const[r,t]=e.split("=").map(e=>e.trim());r&&t&&(s[r]=t)});let i={type:"",data:{}};try{i=(a.req.header("content-type")||"").includes("json")?await a.req.json():await a.req.parseBody()}catch(e){}return{system:{headers:o,cookies:s,ip:r(o),location:t(o)},type:String(i?.type||""),data:i?.data||{}}}export function ActionResponse(e,r){return r.redirect?e.redirect(r.redirect):(Array.isArray(r.header)&&r.header.forEach(r=>{r.key&&r.value&&e.header(r.key,r.value)}),Array.isArray(r.set_cookie)&&r.set_cookie.forEach(r=>{r.key&&r.value&&e.header("Set-Cookie",`${r.key}=${r.value}`,{append:!0})}),e.json(r.response||{},r.status||200))}
1
+ import{mapHeaders as e,getIp as r,getLocation as t}from"../utils/system-helpers.js";export async function ActionRequest(a){const o=e(a.req.header()),s={};(a.req.header("cookie")||"").split(";").forEach(e=>{const[r,t]=e.split("=").map(e=>e.trim());r&&t&&(s[r]=t)});let i={type:"",data:{}};try{i=(a.req.header("content-type")||"").includes("json")?await a.req.json():await a.req.parseBody()}catch(e){}return{system:{headers:o,cookies:s,ip:r(o),location:t(o)},type:String(i?.type||""),data:i?.data||{}}}export function ActionResponse(e,r){return r?.redirect?e.redirect(r.redirect):(Array.isArray(r.header)&&r.header.forEach(r=>{r.key&&r.value&&e.header(r.key,r.value)}),Array.isArray(r.set_cookie)&&r.set_cookie.forEach(r=>{r.key&&r.value&&e.header("Set-Cookie",`${r.key}=${r.value}`,{append:!0})}),e.json(r.response||{},r.status||200))}
@@ -1 +1 @@
1
- import{mapHeaders as e,getIp as t,getLocation as r}from"../utils/system-helpers.js";export async function ActionRequest(o){const{headers:s,cookies:a}=await import("next/headers"),{ipAddress:i}=await import("@vercel/functions"),n=await s(),c=await a(),l=e(n),f=t(l,"function"==typeof i?i({headers:n}):void 0),p=r(l),y=n.get("content-type")||"";let d={type:"",data:{}};try{if(y.includes("application/json"))d=await o.json();else if(y.includes("multipart/form-data")||y.includes("application/x-www-form-urlencoded")){const e=await o.formData(),t={};for(const[r,o]of e.entries()){const e=r.split(".");let s=t;for(let t=0;t<e.length;t++){const r=e[t];if(t===e.length-1)if(o instanceof Blob){const e=await o.arrayBuffer();s[r]=Buffer.from(e)}else s[r]=o;else s[r]=s[r]||{},s=s[r]}}d=t}}catch(e){console.error("[Seishiro ActionRequest]: Body parsing failed:",e.message)}const u={},m=c.getAll();if(Array.isArray(m))for(const e of m)u[e.name]=String(e.value).trim();return{system:{headers:l,cookies:u,ip:f,location:p},type:String(d?.type||""),data:d?.data||{}}}export async function ActionResponse(e,t){const{NextResponse:r}=await import("next/server");if(t.redirect)return r.redirect(new URL(t.redirect,e.url));const o=r.json(t.response||{},{status:t.status||200});return Array.isArray(t.header)&&t.header.forEach(e=>{e.key&&e.value&&o.headers.set(e.key,e.value)}),Array.isArray(t.set_cookie)&&t.set_cookie.forEach(e=>{e.key&&e.value&&o.cookies.set(e.key,e.value,e.options||{})}),Array.isArray(t.rm_cookie)&&t.rm_cookie.forEach(e=>{const t="string"==typeof e?e:e?.key;t&&o.cookies.delete(t)}),o}
1
+ import{mapHeaders as e,getIp as t,getLocation as r}from"../utils/system-helpers.js";import o from"../utils/format-value.js";export async function ActionRequest(s){const{headers:a,cookies:i}=await import("next/headers"),{ipAddress:n}=await import("@vercel/functions"),c=await a(),l=await i(),f=e(c),p=t(f,"function"==typeof n?n({headers:c}):void 0),u=r(f),y=c.get("content-type")||"";let d={type:"",data:{}};try{if(y.includes("application/json"))d=await s.json();else if(y.includes("multipart/form-data")||y.includes("application/x-www-form-urlencoded")){const e=await s.formData(),t={};for(const[r,s]of e.entries()){const e=r.split(".");let a=t;for(let t=0;t<e.length;t++){const r=e[t];if(t===e.length-1)if(s instanceof Blob){const e=await s.arrayBuffer();a[r]=Buffer.from(e)}else a[r]=o(s);else a[r]=a[r]||{},a=a[r]}}d=t}}catch(e){console.error("[Seishiro ActionRequest]: Body parsing failed:",e.message)}const m={},h=l.getAll();if(Array.isArray(h))for(const e of h)m[e.name]=String(e.value).trim();return{system:{headers:f,cookies:m,ip:p,location:u},type:String(d?.type||""),data:d?.data||{}}}export async function ActionResponse(e,t){const{NextResponse:r}=await import("next/server");if(t?.redirect)return r.redirect(new URL(t.redirect,e.url));const o=r.json(t.response||{},{status:t.status||200});return Array.isArray(t.header)&&t.header.forEach(e=>{e.key&&e.value&&o.headers.set(e.key,e.value)}),Array.isArray(t.set_cookie)&&t.set_cookie.forEach(e=>{e.key&&e.value&&o.cookies.set(e.key,e.value,e.options||{})}),Array.isArray(t.rm_cookie)&&t.rm_cookie.forEach(e=>{const t="string"==typeof e?e:e?.key;t&&o.cookies.delete(t)}),o}
package/esm/index.d.ts CHANGED
@@ -4,10 +4,23 @@ import * as ExpressJSAction from "./action-tool/action-express.js";
4
4
  import * as HonoAction from "./action-tool/action-hono.js";
5
5
  import * as FastifyAction from "./action-tool/action-fastify.js";
6
6
  import * as ElysiaAction from "./action-tool/action-elysia.js";
7
- export { default as RegistryBuilder } from "./lib/registry.js";
8
- export { default as MessageBuilder } from "./lib/message.js";
9
- export { default as PolicyBuilder } from "./lib/policy.js";
7
+ import Registry from "./lib/registry.js";
8
+ import Message from "./lib/message.js";
9
+ import Policy from "./lib/policy.js";
10
10
  export { default as Actions } from "./lib/actions.js";
11
+ export { Registry, Message, Policy };
12
+ /** @deprecated Seishiro: Use `Registry` instead. This will be removed in future versions. */
13
+ export declare const RegistryBuilder: typeof Registry;
14
+ /** @deprecated Seishiro: Use `Message` instead. This will be removed in future versions. */
15
+ export declare const MessageBuilder: typeof Message;
16
+ /** @deprecated Seishiro: Use `Policy` instead. This will be removed in future versions. */
17
+ export declare const PolicyBuilder: typeof Policy;
18
+ /** @deprecated Seishiro: Use `Registry` instead. */
19
+ export type RegistryBuilder = Registry;
20
+ /** @deprecated Seishiro: Use `Message` instead. */
21
+ export type MessageBuilder = Message;
22
+ /** @deprecated Seishiro: Use `Policy` instead. */
23
+ export type PolicyBuilder = Policy;
11
24
  export declare const ActionTools: {
12
25
  ZodValidatorContent: typeof ZodValidatorContent;
13
26
  NextJS: typeof NextJSAction;
package/esm/index.js CHANGED
@@ -1 +1 @@
1
- import o from"./action-tool/zod-validate.js";import*as t from"./action-tool/action-next.js";import*as i from"./action-tool/action-express.js";import*as s from"./action-tool/action-hono.js";import*as a from"./action-tool/action-fastify.js";import*as r from"./action-tool/action-elysia.js";export{default as RegistryBuilder}from"./lib/registry.js";export{default as MessageBuilder}from"./lib/message.js";export{default as PolicyBuilder}from"./lib/policy.js";export{default as Actions}from"./lib/actions.js";export const ActionTools={ZodValidatorContent:o,NextJS:t,ExpressJS:i,Hono:s,Fastify:a,Elysia:r};
1
+ import o from"./action-tool/zod-validate.js";import*as e from"./action-tool/action-next.js";import*as t from"./action-tool/action-express.js";import*as i from"./action-tool/action-hono.js";import*as s from"./action-tool/action-fastify.js";import*as r from"./action-tool/action-elysia.js";import n from"./lib/registry.js";import a from"./lib/message.js";import c from"./lib/policy.js";export{default as Actions}from"./lib/actions.js";export{n as Registry,a as Message,c as Policy};function l(o,e,t){return new Proxy(o,{construct:(o,i)=>(console.warn(`[Seishiro Deprecation Warning]: '${e}' is deprecated and will be removed in future versions. Please use '${t}' instead.`),new o(...i)),get:(o,i)=>("prototype"!==i&&"name"!==i&&console.warn(`[Seishiro Deprecation Warning]: Accessing '${e}.${String(i)}' is deprecated. Please use '${t}' instead.`),o[i])})}export const RegistryBuilder=l(n,"RegistryBuilder","Registry");export const MessageBuilder=l(a,"MessageBuilder","Message");export const PolicyBuilder=l(c,"PolicyBuilder","Policy");export const ActionTools={ZodValidatorContent:o,NextJS:e,ExpressJS:t,Hono:i,Fastify:s,Elysia:r};
@@ -1 +1 @@
1
- import e from"../utils/extract-lang.js";import r from"crypto";import{Buffer as t}from"buffer";export default class s{registry;message;policy;heading;cache_book;constructor({registry:e,message:r,policy:t,heading:s={version:"x-seishiro-client",lang:"x-seishiro-lang"}}){this.registry=e,this.message=r,this.policy=t,this.heading=s,this.cache_book=null}BookRegistry(){if(this.cache_book)return this.cache_book;const e="hex",s=r.randomBytes(16),i=this.policy.apply(),a=this.registry.apply(),o=r.createHash("sha256").update(String(i.passkey||"").trim()).digest(),n={listkey:Object.keys(a).filter(e=>!i.noaction_api.includes(e)),version_now:i.version_now,version_min:i.version_min,version_forceupdate:i.version_forceupdate},c=r.createCipheriv("aes-256-ctr",o,s),l=t.concat([s,c.update(JSON.stringify(n),"utf-8"),c.final()]),d={iv_length:16,type_base:e,iv:s.toString(e),data:l.toString(e)};return this.cache_book=d,d}ResponseBuilder(e={},r,t="en"){const s=!e||"object"!=typeof e||Array.isArray(e)||!!e.error||!e.data,i=e?.status||(s?400:200),a={header:Object.entries(e?.headers||{}).filter(([e,r])=>void 0!==r).map(([e,r])=>({key:e,value:r})),set_cookie:(Array.isArray(e?.set_cookie)?e.set_cookie:[]).filter(e=>e?.key&&e?.value),rm_cookie:(Array.isArray(e?.rm_cookie)?e.rm_cookie:[]).filter(e=>"string"==typeof e||e?.key),status:i,redirect:e?.redirect||null};if(s){const r=e?.error||"system:no-response-sending",s=this.message.error(r,e?.params||[],t);return{...a,error:r,response:{status:i,message:s.message,protocol:s.protocol,context:s.context,params:s.params}}}return{...a,error:null,response:{status:i,data:e.data||{}}}}async SystemAction({system:r,middleware:t={},context_manager:s="system-action",type:i,data:a}){const o=e(r?.headers?.[this.heading.lang]||r?.headers?.["accept-language"]||r?.lang||"en");try{const e=this.policy.apply(),n=String(r?.headers?.[this.heading.version]||"").trim();if("api-action"===s&&!n)return this.ResponseBuilder({error:"system:client-version-required",status:400},r,o);if(n&&"api-action"===s){const t=this.policy.version_info(n);if(!t.is_version_min&&t.info_upgrade)return this.ResponseBuilder({error:"system:need-upgrade-client",status:426,params:[{min:e.version_min,now:e.version_now}]},r,o)}const c=this.registry.get(i||"");if(!c)return this.ResponseBuilder({error:"system:no-registry",status:404},r,o);const l={...r,lang:o};let d=t,y=c;if(Array.isArray(c)){const[r,s]=c,n=await r({system:l,middleware:t,type:i,data:a});d=e.skip_middleware_context||n?.skipBuilder?n:this.ResponseBuilder(n,l,o),y=s}const p=await y({system:l,middleware:d,type:i,data:a});return this.ResponseBuilder(p,l,o)}catch(e){return console.error("[Seishiro Core Error]:",e),this.ResponseBuilder({error:"system:internal-server-error",status:500},r,o)}}async ServerAction({system:r,middleware:t,type:s,data:i}){if(this.policy.apply().noaction_server.includes(s||"")){const t=e(r?.headers?.[this.heading.lang]||r?.headers?.["accept-language"]||r?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},r,t)}return this.SystemAction({system:r,middleware:t,context_manager:"server-action",type:s,data:i})}async APIAction({system:r,middleware:t,type:s,data:i}){if(this.policy.apply().noaction_api.includes(s||"")){const t=e(r?.headers?.[this.heading.lang]||r?.headers?.["accept-language"]||r?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},r,t)}return this.SystemAction({system:r,middleware:t,context_manager:"api-action",type:s,data:i})}}
1
+ import e from"../utils/extract-lang.js";import r from"crypto";import{Buffer as t}from"buffer";export default class s{registry;message;policy;heading;cache_book;constructor({registry:e,message:r,policy:t,heading:s={version:"x-seishiro-client",lang:"x-seishiro-lang"}}){this.registry=e,this.message=r,this.policy=t,this.heading=s,this.cache_book=null}BookRegistry(){if(this.cache_book)return this.cache_book;const e="hex",s=r.randomBytes(16),i=this.policy.apply(),a=this.registry.apply(),o=r.createHash("sha256").update(String(i.passkey||"").trim()).digest(),n={listkey:Object.keys(a).filter(e=>!i.noaction_api.includes(e)),version_now:i.version_now,version_min:i.version_min,version_forceupdate:i.version_forceupdate},c=r.createCipheriv("aes-256-ctr",o,s),y=t.concat([s,c.update(JSON.stringify(n),"utf-8"),c.final()]),l={iv_length:16,type_base:e,iv:s.toString(e),data:y.toString(e)};return this.cache_book=l,l}ResponseBuilder(e={},r,t="en"){const s=!e||"object"!=typeof e||Array.isArray(e)||!!e.error||!e.data,i=e?.status||(s?400:200),a={header:Object.entries(e?.headers||{}).filter(([e,r])=>void 0!==r).map(([e,r])=>({key:e,value:r})),set_cookie:(Array.isArray(e?.set_cookie)?e.set_cookie:[]).filter(e=>e?.key&&e?.value),rm_cookie:(Array.isArray(e?.rm_cookie)?e.rm_cookie:[]).filter(e=>"string"==typeof e||e?.key),status:i,redirect:e?.redirect||null};if(s){const r=e?.error||"system:no-response-sending",s=this.message.error(r,e?.params||[],t);return{...a,error:r,response:{status:i,message:s.message,protocol:s.protocol,context:s.context,params:s.params}}}return{...a,error:null,response:{status:i,data:e.data||{}}}}async SystemAction({system:r,middleware:t={},context_manager:s="system-action",type:i,data:a}){const o=e(r?.headers?.[this.heading.lang]||r?.headers?.["accept-language"]||r?.lang||"en");try{const e=this.policy.apply(),n=String(r?.headers?.[this.heading.version]||"").trim();if("api-action"===s&&!n)return this.ResponseBuilder({error:"system:client-version-required",status:400},r,o);if(n&&"api-action"===s){const t=this.policy.version_info(n);if(!t.is_version_min&&t.info_upgrade)return this.ResponseBuilder({error:"system:need-upgrade-client",status:426,params:[{min:e.version_min,now:e.version_now}]},r,o)}const c=this.registry.get(i||"");if(!c)return this.ResponseBuilder({error:"system:no-registry",status:404},r,o);const y={...r,lang:o};let l=t,d=c;if(Array.isArray(c)){const[r,t]=c,s=Array.isArray(r)?r:[r],n=[];for(const r of s){const t=await r({system:y,middleware:n,type:i,data:a});if(t?.error&&e.catch_middleware_context)return this.ResponseBuilder(t,y,o);n.push(t)}l=n,d=t}const p=await d({system:y,middleware:l,type:i,data:a});return this.ResponseBuilder(p,y,o)}catch(e){return console.error("[Seishiro Core Error]:",e),this.ResponseBuilder({error:"system:internal-server-error",status:500},r,o)}}async ServerAction({system:r,middleware:t,type:s,data:i}){if(this.policy.apply().noaction_server.includes(s||"")){const t=e(r?.headers?.[this.heading.lang]||r?.headers?.["accept-language"]||r?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},r,t)}return this.SystemAction({system:r,middleware:t,context_manager:"server-action",type:s,data:i})}async APIAction({system:r,middleware:t,type:s,data:i}){if(this.policy.apply().noaction_api.includes(s||"")){const t=e(r?.headers?.[this.heading.lang]||r?.headers?.["accept-language"]||r?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},r,t)}return this.SystemAction({system:r,middleware:t,context_manager:"api-action",type:s,data:i})}}
@@ -1 +1 @@
1
- import e from"../utils/format-key.js";import{DefaultLanguage as s}from"../constants/message.js";export default class t{message_build_lang="";message_logic=new Map;constructor(e="en"){this.message_build_lang=String(e||"en").toLowerCase().replace(/[^a-z]/g,"").slice(0,2),this.message_logic=new Map}set(s,t){if("string"!=typeof t||"string"!=typeof s)throw new Error("Key and Value must be string!");this.message_logic.has(this.message_build_lang)||this.message_logic.set(this.message_build_lang,new Map),this.message_logic.get(this.message_build_lang).set(e(s),t.trim())}get(t="",i=this.message_build_lang){const a=e(t);let g=this.message_logic.get(i);return g||(g=this.message_logic.get(s),!g&&this.message_logic.size>0&&(g=this.message_logic.values().next().value)),g?g.get(a)||"":`[!NoneVariable ${a}]`}errorMessage(e="",s={},t=this.message_build_lang){const i=this.get(e,t);return s&&0!==Object.keys(s).length?i.replace(/{{(\w+)}}/g,(e,t)=>s[t]||e):i}error(s="",t=[],i=this.message_build_lang){const a=s.indexOf(":");if(-1===a)return{protocol:"unknown",context:[s],params:t,message:s};const g=e(s.substring(0,a)),r=s.substring(a+1).split("|");let o="";for(let e=0;e<r.length;e++){o+=(0===e?"":", ")+this.errorMessage(r[e],t[e],i)}return{protocol:g,context:r,params:t,message:o}}apply(){return this.message_logic}use(e){if(e instanceof t)e.apply().forEach((e,s)=>{const t=this.message_logic.get(s)||new Map;this.message_logic.has(s)||this.message_logic.set(s,t),e.forEach((e,s)=>t.set(s,e))});else{if("object"!=typeof e||!e)throw new Error("Invalid 'use' input!");Object.entries(e).forEach(([e,s])=>this.set(e,String(s)))}}}
1
+ import e from"../utils/format-key.js";import{DefaultLanguage as s}from"../constants/message.js";export default class t{message_build_lang="";message_logic=new Map;constructor(e="en"){this.message_build_lang=String(e||"en").toLowerCase().replace(/[^a-z]/g,"").slice(0,2),this.message_logic.set(this.message_build_lang,new Map([["no-response-sending","Server returned no response."],["client-version-required","Client version header is required."],["need-upgrade-client","Please upgrade your application."],["no-registry","Service registry not found."],["internal-server-error","Internal server error."]]))}set(s,t){if("string"!=typeof t||"string"!=typeof s)throw new Error("Key and Value must be string!");this.message_logic.has(this.message_build_lang)||this.message_logic.set(this.message_build_lang,new Map),this.message_logic.get(this.message_build_lang).set(e(s),t.trim())}get(t="",r=this.message_build_lang){const i=e(t);let a=this.message_logic.get(r);return a||(a=this.message_logic.get(s),!a&&this.message_logic.size>0&&(a=this.message_logic.values().next().value)),a?a.get(i)||"":`[!NoneVariable ${i}]`}errorMessage(e="",s={},t=this.message_build_lang){const r=this.get(e,t);return s&&0!==Object.keys(s).length?r.replace(/{{(\w+)}}/g,(e,t)=>s[t]||e):r}error(s="",t=[],r=this.message_build_lang){const i=s.indexOf(":");if(-1===i)return{protocol:"unknown",context:[s],params:t,message:s};const a=e(s.substring(0,i)),n=s.substring(i+1).split("|");let g="";for(let e=0;e<n.length;e++){g+=(0===e?"":", ")+this.errorMessage(n[e],t[e],r)}return{protocol:a,context:n,params:t,message:g}}apply(){return this.message_logic}use(e){if(e instanceof t)e.apply().forEach((e,s)=>{const t=this.message_logic.get(s)||new Map;this.message_logic.has(s)||this.message_logic.set(s,t),e.forEach((e,s)=>t.set(s,e))});else{if("object"!=typeof e||!e)throw new Error("Invalid 'use' input!");Object.entries(e).forEach(([e,s])=>this.set(e,String(s)))}}}
@@ -12,7 +12,7 @@ export default class PolicyBuilder {
12
12
  private noaction_api;
13
13
  private noaction_server;
14
14
  private compiled_policy;
15
- private skip_middleware_context;
15
+ private catch_middleware_context;
16
16
  private parsed_min;
17
17
  private parsed_now;
18
18
  /**
@@ -24,12 +24,12 @@ export default class PolicyBuilder {
24
24
  * @param {boolean} [config.version_forceupdate=true] - Flag to indicate if clients below version_min must update.
25
25
  * @throws {Error} If passkey, version_now, or version_min is missing.
26
26
  */
27
- constructor({ passkey, version_now, version_min, version_forceupdate, skip_middleware_context, }: {
27
+ constructor({ passkey, version_now, version_min, version_forceupdate, catch_middleware_context, }: {
28
28
  passkey: string;
29
29
  version_now: string;
30
30
  version_min: string;
31
31
  version_forceupdate?: boolean;
32
- skip_middleware_context?: boolean;
32
+ catch_middleware_context?: boolean;
33
33
  });
34
34
  /**
35
35
  * @method noaction
package/esm/lib/policy.js CHANGED
@@ -1 +1 @@
1
- export default class i{passkey;version_now;version_min;version_forceupdate;noaction_api;noaction_server;compiled_policy=null;skip_middleware_context;parsed_min;parsed_now;constructor({passkey:i,version_now:e,version_min:o,version_forceupdate:s=!0,skip_middleware_context:n=!1}){if(!i||!e||!o)throw new Error("PolicyBuilder: passkey, version_now, and version_min are required!");this.passkey=i,this.version_now=e,this.version_min=o,this.parsed_min=this.parseVersion(o),this.parsed_now=this.parseVersion(e),this.version_forceupdate=s,this.noaction_api=[],this.noaction_server=[],this.skip_middleware_context=n,this.refresh()}noaction(i="",e=[]){const o=["server-action","api-action"];for(let i of e)if(!o.includes(i))throw new Error(`Invalid action type: ${i}. Only allowed actions are: ${o.join(", ")}`);if("string"!=typeof i)throw new Error("Invalid key type, it only string!");for(let o of e)"api-action"===o?this.noaction_api.push(i):"server-action"===o&&this.noaction_server.push(i)}parseVersion(i){return i.split(".").map(Number)}compare(i,e){const o=Math.max(i.length,e.length);for(let s=0;s<o;s++){const o=i[s]||0,n=e[s]||0;if(o!==n)return o>n?1:-1}return 0}version_info(i=""){const e=this.parseVersion(i);return{info_upgrade:this.version_forceupdate,is_version_min:this.compare(e,this.parsed_min)>=0,is_version_now:this.compare(e,this.parsed_now)>=0}}refresh(){this.compiled_policy={passkey:this.passkey,version_now:this.version_now,version_min:this.version_min,version_forceupdate:this.version_forceupdate,noaction_api:this.noaction_api,noaction_server:this.noaction_server,skip_middleware_context:this.skip_middleware_context}}apply(){return this.compiled_policy}}
1
+ export default class e{passkey;version_now;version_min;version_forceupdate;noaction_api;noaction_server;compiled_policy=null;catch_middleware_context;parsed_min;parsed_now;constructor({passkey:e="seishiro",version_now:i,version_min:o,version_forceupdate:s=!0,catch_middleware_context:n=!0}){if(!e||!i||!o)throw new Error("PolicyBuilder: passkey, version_now, and version_min are required!");"seishiro"===e&&console.warn("[Seishiro/Policy Warn]: Passkey is currently still the default, please change it to a much safer one, it is not recommended to use the default one."),this.passkey=e,this.version_now=i,this.version_min=o,this.parsed_min=this.parseVersion(o),this.parsed_now=this.parseVersion(i),this.version_forceupdate=s,this.noaction_api=[],this.noaction_server=[],this.catch_middleware_context=n,this.refresh()}noaction(e="",i=[]){const o=["server-action","api-action"];for(let e of i)if(!o.includes(e))throw new Error(`Invalid action type: ${e}. Only allowed actions are: ${o.join(", ")}`);if("string"!=typeof e)throw new Error("Invalid key type, it only string!");for(let o of i)"api-action"===o?this.noaction_api.push(e):"server-action"===o&&this.noaction_server.push(e)}parseVersion(e){return e.split(".").map(Number)}compare(e,i){const o=Math.max(e.length,i.length);for(let s=0;s<o;s++){const o=e[s]||0,n=i[s]||0;if(o!==n)return o>n?1:-1}return 0}version_info(e=""){const i=this.parseVersion(e);return{info_upgrade:this.version_forceupdate,is_version_min:this.compare(i,this.parsed_min)>=0,is_version_now:this.compare(i,this.parsed_now)>=0}}refresh(){this.compiled_policy={passkey:this.passkey,version_now:this.version_now,version_min:this.version_min,version_forceupdate:this.version_forceupdate,noaction_api:this.noaction_api,noaction_server:this.noaction_server,catch_middleware_context:this.catch_middleware_context}}apply(){return this.compiled_policy}}
@@ -20,7 +20,7 @@ export default class RegistryBuilder {
20
20
  * @param {RegistryMiddleware} [middleware] - Optional middleware function to execute before the main controller.
21
21
  * @throws {Error} If the controller is not a function or the key is not a string.
22
22
  */
23
- set(key: RegistryKey, function_regis: RegistryFunction, middleware?: RegistryMiddleware): void;
23
+ set(key: RegistryKey, function_regis: RegistryFunction, middleware?: RegistryMiddleware | RegistryMiddleware[]): void;
24
24
  /**
25
25
  * @method get
26
26
  * @description Retrieves the registered function(s) associated with a specific key.
@@ -28,7 +28,7 @@ export default class RegistryBuilder {
28
28
  * @returns {RegistryFunction | [RegistryMiddleware, RegistryFunction] | undefined}
29
29
  * Returns a single function, an array containing [middleware, controller], or undefined if not found.
30
30
  */
31
- get(key: RegistryKey): RegistryFunction | [RegistryMiddleware, RegistryFunction] | undefined;
31
+ get(key: RegistryKey): RegistryFunction | [RegistryMiddleware | RegistryMiddleware[], RegistryFunction] | undefined;
32
32
  /**
33
33
  * @method apply
34
34
  * @description Returns the raw internal registry logic mapping.
@@ -1 +1 @@
1
- import t from"../utils/format-key.js";export default class r{registry_logic;constructor(){this.registry_logic=new Map}set(r,i,e){const s=t(r);if("function"!=typeof i)throw new Error("Registry function is only type function!");if("string"!=typeof r)throw new Error("Registry key is only type string!");e&&"function"==typeof e?this.registry_logic.set(s,[e,i]):this.registry_logic.set(s,i)}get(r){const i=t(r);return this.registry_logic.get(i)||void 0}apply(){return this.registry_logic}use(t){if(t instanceof r)t.apply().forEach((t,r)=>this.registry_logic.set(r,t));else{if("object"!=typeof t||!t)throw new Error("Invalid 'use' input!");Object.entries(t).forEach(([t,r])=>{Array.isArray(r)?this.set(t,r[1],r[0]):this.set(t,r)})}}}
1
+ import t from"../utils/format-key.js";export default class r{registry_logic;constructor(){this.registry_logic=new Map}set(r,i,e){const s=t(r);if("function"!=typeof i)throw new Error("Registry function is only type function!");if("string"!=typeof r)throw new Error("Registry key is only type string!");e&&("function"==typeof e||Array.isArray(e))?this.registry_logic.set(s,[e,i]):this.registry_logic.set(s,i)}get(r){const i=t(r);return this.registry_logic.get(i)||void 0}apply(){return this.registry_logic}use(t){if(t instanceof r)t.apply().forEach((t,r)=>this.registry_logic.set(r,t));else{if("object"!=typeof t||!t)throw new Error("Invalid 'use' input!");Object.entries(t).forEach(([t,r])=>{Array.isArray(r)?this.set(t,r[1],r[0]):this.set(t,r)})}}}
@@ -9,13 +9,13 @@ export type RegistryParams = {
9
9
  };
10
10
  ip: string;
11
11
  location: string;
12
- lang: string | "en";
12
+ lang?: string | "en";
13
13
  };
14
14
  type: RegistryKey;
15
15
  context_manager?: string;
16
- middleware?: object | Function | Promise<any>;
16
+ middleware?: any;
17
17
  data: object;
18
18
  };
19
19
  export type RegistryFunction = (params: RegistryParams) => any;
20
20
  export type RegistryMiddleware = (params: RegistryParams) => any;
21
- export type RegistryLogic = Map<RegistryKey, RegistryFunction | [RegistryMiddleware, RegistryFunction]>;
21
+ export type RegistryLogic = Map<RegistryKey, RegistryFunction | [RegistryMiddleware | RegistryMiddleware[], RegistryFunction]>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @function formatValue
3
+ * @description Automatically detects and converts string-based values into their
4
+ * respective primitive types (number, boolean, null, or string).
5
+ * @param {any} value - The input value to format.
6
+ * @returns {any} The formatted value in its detected type.
7
+ */
8
+ export default function formatValue(value: any): any;
@@ -0,0 +1 @@
1
+ export default function t(t){if("string"!=typeof t)return t;const r=t.trim(),e=r.toLowerCase();if("true"===e)return!0;if("false"===e)return!1;if("null"===e)return null;if("undefined"!==e){if(""!==r&&!isNaN(Number(r)))return Number(r);if(/^-?\d+n$/.test(r))try{return BigInt(r.slice(0,-1))}catch{return t}if(r.startsWith("[")&&r.endsWith("]")||r.startsWith("{")&&r.endsWith("}"))try{return JSON.parse(r)}catch{return t}return t}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seishiro",
3
- "version": "0.2.2-release",
3
+ "version": "0.2.4-release",
4
4
  "description": "The Centralized API Orchestrator for Modern Web Applications.",
5
5
  "type": "module",
6
6
  "main": "./cjs/index.js",
@@ -23,7 +23,7 @@
23
23
  "lint": "biome check",
24
24
  "format": "biome format --write"
25
25
  },
26
- "license": "AGPL-3.0",
26
+ "license": "Apache-2.0",
27
27
  "author": "Ernestoyoofi",
28
28
  "devDependencies": {
29
29
  "@biomejs/biome": "^2.4.4",