seishiro 0.2.0-release → 0.2.1-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 +6 -6
- package/cjs/lib/actions.js +1 -1
- package/esm/lib/actions.js +1 -1
- package/package.json +14 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Seishiro API
|
|
2
2
|
|
|
3
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.
|
|
4
|
-
|
|
4
|
+
<!--
|
|
5
5
|
## Tasks
|
|
6
6
|
|
|
7
7
|
- [x] Registry Controllers
|
|
@@ -11,8 +11,8 @@ Seishiro eliminates the complexity of routing folder structures and replaces the
|
|
|
11
11
|
- [x] Protocol Response
|
|
12
12
|
- [x] Middleware Runner
|
|
13
13
|
- [x] Action Executed
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
14
|
+
- [x] Versioning Header
|
|
15
|
+
- [x] Language Switch -->
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
@@ -78,7 +78,7 @@ const sysaction = await action.SystemAction({
|
|
|
78
78
|
system: {
|
|
79
79
|
headers: {...}, // Header KV (Key, Value)
|
|
80
80
|
cookies: {...}, // Cookie KV (Key, Value)
|
|
81
|
-
ip: "
|
|
81
|
+
ip: "127.0.0.1", // IP Address (IP Client - Example)
|
|
82
82
|
location: "JKT, Jakarta, Jakarta Pusat", // Location (Location Client By IP & PeerDB - Example)
|
|
83
83
|
},
|
|
84
84
|
type: "user:login", // Type Action
|
|
@@ -94,7 +94,7 @@ const serveraction = await action.ServerAction({
|
|
|
94
94
|
system: {
|
|
95
95
|
headers: {...}, // Header KV (Key, Value)
|
|
96
96
|
cookies: {...}, // Cookie KV (Key, Value)
|
|
97
|
-
ip: "
|
|
97
|
+
ip: "127.0.0.1", // IP Address (IP Client - Example)
|
|
98
98
|
location: "JKT, Jakarta, Jakarta Pusat", // Location (Location Client By IP & PeerDB - Example)
|
|
99
99
|
},
|
|
100
100
|
type: "user:profile", // Type Action
|
|
@@ -109,7 +109,7 @@ const apiaction = action.APIAction({
|
|
|
109
109
|
system: {
|
|
110
110
|
headers: {...}, // Header KV (Key, Value)
|
|
111
111
|
cookies: {...}, // Cookie KV (Key, Value)
|
|
112
|
-
ip: "
|
|
112
|
+
ip: "127.0.0.1", // IP Address (IP Client - Example)
|
|
113
113
|
location: "JKT, Jakarta, Jakarta Pusat", // Location (Location Client By IP & PeerDB - Example)
|
|
114
114
|
},
|
|
115
115
|
type: "user:profile", // Type Action
|
package/cjs/lib/actions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const crypto_1=__importDefault(require("crypto")),buffer_1=require("buffer"),extract_lang_js_1=__importDefault(require("../utils/extract-lang.js"));class Actions{registry;message;policy;cache_book;constructor({registry:e,message:t,policy:r}){this.registry=e,this.message=t,this.policy=r,this.cache_book=null}BookRegistry(){if(this.cache_book)return this.cache_book;const e="hex",t=crypto_1.default.randomBytes(16),r=this.policy.apply(),s=this.registry.apply(),
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const crypto_1=__importDefault(require("crypto")),buffer_1=require("buffer"),extract_lang_js_1=__importDefault(require("../utils/extract-lang.js"));class Actions{registry;message;policy;cache_book;constructor({registry:e,message:t,policy:r}){this.registry=e,this.message=t,this.policy=r,this.cache_book=null}BookRegistry(){if(this.cache_book)return this.cache_book;const e="hex",t=crypto_1.default.randomBytes(16),r=this.policy.apply(),s=this.registry.apply(),i=crypto_1.default.createHash("sha256").update(String(r.passkey||"").trim()).digest(),o={listkey:Object.keys(s).filter(e=>!r.noaction_api.includes(e)),version_now:r.version_now,version_min:r.version_min,version_forceupdate:r.version_forceupdate},a=crypto_1.default.createCipheriv("aes-256-ctr",i,t),n=buffer_1.Buffer.concat([t,a.update(JSON.stringify(o),"utf-8"),a.final()]),c={iv_length:16,type_base:e,iv:t.toString(e),data:n.toString(e)};return this.cache_book=c,c}ResponseBuilder(e={},t,r="en"){const s=!e||"object"!=typeof e||Array.isArray(e)||!!e.error||!e.data,i=e?.status||(s?400:200),o=e?.redirect||null,a=[];if(e?.headers&&"object"==typeof e.headers&&!Array.isArray(e.headers))for(const[t,r]of Object.entries(e.headers))a.push({key:t,value:r});const n=[];if(Array.isArray(e?.set_cookie))for(const t of e.set_cookie)t&&"object"==typeof t&&t.key&&t.value&&n.push(t);const c=[];if(Array.isArray(e?.rm_cookie))for(const t of e.rm_cookie)t&&"string"==typeof t&&c.push(t);const l={header:a,set_cookie:n,rm_cookie:c,status:i,redirect:o};if(s){const t=e?.error||"system:no-response-sending",s=this.message.error(t,e?.params||[],r);return{...l,error:t,response:{status:i,message:s.message,protocol:s.protocol,context:s.context,params:s.params}}}return{...l,error:null,response:{status:i,data:e.data||{}}}}async SystemAction({system:e,middleware:t={},context_manager:r="system-action",type:s,data:i}){const o=e?.headers||{},a=o["x-seishiro-lang"]||o["accept-language"],n=a?(0,extract_lang_js_1.default)(a):e?.lang||"en";try{const a=this.policy.apply(),c=o["x-seishiro-client"];if("api-action"===r&&!c)return this.ResponseBuilder({error:"system:client-version-required",status:400},e,n);if(c&&"api-action"===r){const t=this.policy.version_info(c);if(!t.is_version_min&&t.info_upgrade)return this.ResponseBuilder({error:"system:need-upgrade-client",status:426,params:[{min:a.version_min,now:a.version_now}]},e,n)}const l=this.registry.get(s||"");if(!l)return this.ResponseBuilder({error:"system:no-registry",status:404},e,n);const u={...e,lang:n};let p=t,y=l;if(Array.isArray(l)){const[e,r]=l,o=await e({system:u,middleware:t,type:s,data:i});p=a.skip_middleware_context||o?.skipBuilder?o:this.ResponseBuilder(o,u,n),y=r}const d=await y({system:u,middleware:p,type:s,data:i});return this.ResponseBuilder(d,u,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:t,type:r,data:s}){if(this.policy.apply().noaction_server.includes(r||"")){const t=(0,extract_lang_js_1.default)(e?.headers?.["x-seishiro-lang"]||e?.headers?.["accept-language"]||e?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},e,t)}return this.SystemAction({system:e,middleware:t,context_manager:"server-action",type:r,data:s})}async APIAction({system:e,middleware:t,type:r,data:s}){if(this.policy.apply().noaction_api.includes(r||"")){const t=(0,extract_lang_js_1.default)(e?.headers?.["x-seishiro-lang"]||e?.headers?.["accept-language"]||e?.lang||"en");return this.ResponseBuilder({error:"system:no-registry",status:404},e,t)}return this.SystemAction({system:e,middleware:t,context_manager:"api-action",type:r,data:s})}}exports.default=Actions;
|
package/esm/lib/actions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import crypto from"crypto";import{Buffer}from"buffer";import extractLanguage from"../utils/extract-lang.js";export default class Actions{registry;message;policy;cache_book;constructor({registry:e,message:
|
|
1
|
+
import crypto from"crypto";import{Buffer}from"buffer";import extractLanguage from"../utils/extract-lang.js";export default class Actions{registry;message;policy;cache_book;constructor({registry:e,message:r,policy:t}){this.registry=e,this.message=r,this.policy=t,this.cache_book=null}BookRegistry(){if(this.cache_book)return this.cache_book;const e="hex",r=crypto.randomBytes(16),t=this.policy.apply(),s=this.registry.apply(),o=crypto.createHash("sha256").update(String(t.passkey||"").trim()).digest(),i={listkey:Object.keys(s).filter(e=>!t.noaction_api.includes(e)),version_now:t.version_now,version_min:t.version_min,version_forceupdate:t.version_forceupdate},a=crypto.createCipheriv("aes-256-ctr",o,r),n=Buffer.concat([r,a.update(JSON.stringify(i),"utf-8"),a.final()]),c={iv_length:16,type_base:e,iv:r.toString(e),data:n.toString(e)};return this.cache_book=c,c}ResponseBuilder(e={},r,t="en"){const s=!e||"object"!=typeof e||Array.isArray(e)||!!e.error||!e.data,o=e?.status||(s?400:200),i=e?.redirect||null,a=[];if(e?.headers&&"object"==typeof e.headers&&!Array.isArray(e.headers))for(const[r,t]of Object.entries(e.headers))a.push({key:r,value:t});const n=[];if(Array.isArray(e?.set_cookie))for(const r of e.set_cookie)r&&"object"==typeof r&&r.key&&r.value&&n.push(r);const c=[];if(Array.isArray(e?.rm_cookie))for(const r of e.rm_cookie)r&&"string"==typeof r&&c.push(r);const p={header:a,set_cookie:n,rm_cookie:c,status:o,redirect:i};if(s){const r=e?.error||"system:no-response-sending",s=this.message.error(r,e?.params||[],t);return{...p,error:r,response:{status:o,message:s.message,protocol:s.protocol,context:s.context,params:s.params}}}return{...p,error:null,response:{status:o,data:e.data||{}}}}async SystemAction({system:e,middleware:r={},context_manager:t="system-action",type:s,data:o}){const i=e?.headers||{},a=i["x-seishiro-lang"]||i["accept-language"],n=a?extractLanguage(a):e?.lang||"en";try{const a=this.policy.apply(),c=i["x-seishiro-client"];if("api-action"===t&&!c)return this.ResponseBuilder({error:"system:client-version-required",status:400},e,n);if(c&&"api-action"===t){const r=this.policy.version_info(c);if(!r.is_version_min&&r.info_upgrade)return this.ResponseBuilder({error:"system:need-upgrade-client",status:426,params:[{min:a.version_min,now:a.version_now}]},e,n)}const p=this.registry.get(s||"");if(!p)return this.ResponseBuilder({error:"system:no-registry",status:404},e,n);const y={...e,lang:n};let l=r,u=p;if(Array.isArray(p)){const[e,t]=p,i=await e({system:y,middleware:r,type:s,data:o});l=a.skip_middleware_context||i?.skipBuilder?i:this.ResponseBuilder(i,y,n),u=t}const d=await u({system:y,middleware:l,type:s,data:o});return this.ResponseBuilder(d,y,n)}catch(r){return console.error("[Seishiro Core Error]:",r),this.ResponseBuilder({error:"system:internal-server-error",status:500},e,n)}}async ServerAction({system:e,middleware:r,type:t,data:s}){if(this.policy.apply().noaction_server.includes(t||"")){const r=extractLanguage(e?.headers?.["x-seishiro-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:t,data:s})}async APIAction({system:e,middleware:r,type:t,data:s}){if(this.policy.apply().noaction_api.includes(t||"")){const r=extractLanguage(e?.headers?.["x-seishiro-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:t,data:s})}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "seishiro",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-release",
|
|
4
4
|
"description": "A simple response context API that eliminates the complexity of routing folder structures and replaces them with a single control center.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./cjs/index.js",
|
|
@@ -31,5 +31,18 @@
|
|
|
31
31
|
"@types/node": "^25.2.2",
|
|
32
32
|
"glob": "^13.0.2",
|
|
33
33
|
"terser": "^5.46.0"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/ernestoyoofi/seishiro.git"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/ernestoyoofi/seishiro#readme",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"api",
|
|
42
|
+
"context",
|
|
43
|
+
"seishiro"
|
|
44
|
+
],
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/ernestoyoofi/seishiro/issues"
|
|
34
47
|
}
|
|
35
48
|
}
|