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 +92 -106
- package/cjs/action-tool/action-elysia.js +1 -1
- package/cjs/action-tool/action-express.js +1 -1
- package/cjs/action-tool/action-fastify.js +1 -1
- package/cjs/action-tool/action-hono.js +1 -1
- package/cjs/action-tool/action-next.js +1 -1
- package/cjs/index.js +1 -1
- package/cjs/lib/actions.js +1 -1
- package/cjs/lib/message.js +1 -1
- package/cjs/lib/policy.js +1 -1
- package/cjs/lib/registry.js +1 -1
- package/cjs/utils/format-value.js +1 -0
- package/esm/action-tool/action-elysia.js +1 -1
- package/esm/action-tool/action-express.js +1 -1
- package/esm/action-tool/action-fastify.js +1 -1
- package/esm/action-tool/action-hono.js +1 -1
- package/esm/action-tool/action-next.js +1 -1
- package/esm/index.d.ts +16 -3
- package/esm/index.js +1 -1
- package/esm/lib/actions.js +1 -1
- package/esm/lib/message.js +1 -1
- package/esm/lib/policy.d.ts +3 -3
- package/esm/lib/policy.js +1 -1
- package/esm/lib/registry.d.ts +2 -2
- package/esm/lib/registry.js +1 -1
- package/esm/types/registry.type.d.ts +3 -3
- package/esm/utils/format-value.d.ts +8 -0
- package/esm/utils/format-value.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,114 +1,100 @@
|
|
|
1
1
|
# Seishiro API
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
import
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
64
|
+
email: "user@example.com",
|
|
65
|
+
password: "password123"
|
|
92
66
|
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(`[31m[Seishiro Deprecation Warning][0m: '${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(`[31m[Seishiro Deprecation Warning][0m: 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};
|
package/cjs/lib/actions.js
CHANGED
|
@@ -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(),
|
|
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;
|
package/cjs/lib/message.js
CHANGED
|
@@ -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
|
|
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;
|
|
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;
|
package/cjs/lib/registry.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
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(`[31m[Seishiro Deprecation Warning][0m: '${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(`[31m[Seishiro Deprecation Warning][0m: 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};
|
package/esm/lib/actions.js
CHANGED
|
@@ -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),
|
|
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})}}
|
package/esm/lib/message.js
CHANGED
|
@@ -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
|
|
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)))}}}
|
package/esm/lib/policy.d.ts
CHANGED
|
@@ -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
|
|
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,
|
|
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
|
-
|
|
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
|
|
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}}
|
package/esm/lib/registry.d.ts
CHANGED
|
@@ -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.
|
package/esm/lib/registry.js
CHANGED
|
@@ -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
|
|
12
|
+
lang?: string | "en";
|
|
13
13
|
};
|
|
14
14
|
type: RegistryKey;
|
|
15
15
|
context_manager?: string;
|
|
16
|
-
middleware?:
|
|
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.
|
|
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": "
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
27
|
"author": "Ernestoyoofi",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@biomejs/biome": "^2.4.4",
|