@fnlb-project/shared 1.5.35 → 1.5.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/index.js +1 -1
- package/dist/util/index.d.ts +9 -2
- package/dist/util/index.js +1 -1
- package/dist/validator/index.js +1 -1
- package/package.json +5 -4
package/dist/commands/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class w{params;constructor(f){this.params=f??[]}addParam(f,b,h,j,v){return this.params.push({id:f,type:0,name:b,description:h,extended:j??!1,examples:v}),this}addOptionalParam(f,b,h,j,v){return this.params.push({id:f,type:1,name:b,description:h,extended:j??!1,examples:v}),this}addSelect(f,b,h,j,v){return this.params.push({id:f,type:2,name:b,description:h,options:j,examples:v}),this}addOptionalSelect(f,b,h,j,v){return this.params.push({id:f,type:3,name:b,description:h,options:j,examples:v}),this}addNumericParam(f,b,h,j){return this.params.push({id:f,type:4,name:b,description:h,examples:j}),this}addNumericOptionalParam(f,b,h,j){return this.params.push({id:f,type:5,name:b,description:h,examples:j}),this}getUsage(){return this.params.map((f)=>w.getParamUsage(f)).join(" ")}getExample(){return this.params.map((f)=>w.getParamExample(f)).join(" ")}static getParamUsage(f){switch(f.type){case 0:return`<${f.extended?"...":""}${f.name}>`;case 1:return`[${f.extended?"...":""}${f.name}]`;case 2:return`<${f.options.map((b)=>b.name).join(" | ")}>`;case 3:return`[${f.options.map((b)=>b.name).join(" | ")}]`;case 4:return`<$${f.name}>`;case 5:return`[$${f.name}]`;default:return""}}static getParamExample(f){let b=(q)=>q[Math.floor(Math.random()*q.length)],h=(q)=>q?b(q):b(["Angel","Brian","Catherine","David","Emma","Frank","Grace","Hannah","Ian","Julia"]),j=(q)=>q?b(q):b(["Brian Stronghold","Catherine Joyful","David Noble","Emma Graceful","Frank Fearless","Grace Serene","Hannah Bold","Ian Clever","Julia Kindhearted"]),v=(q)=>b(q)?.name,z=(q)=>q?b(q):Math.floor(Math.random()*1000);switch(f.type){case 1:case 0:return f.extended?j(f.examples):h(f.examples);case 2:case 3:return v(f.options);case 4:case 5:return z(f.examples);default:return""}}}export{w as CommandUsageClient};
|
|
1
|
+
class w{params;constructor(f){this.params=f??[]}addParam(f,b,h,j,v){return this.params.push({id:f,type:0,name:b,description:h,extended:j??!1,examples:v}),this}addOptionalParam(f,b,h,j,v){return this.params.push({id:f,type:1,name:b,description:h,extended:j??!1,examples:v}),this}addSelect(f,b,h,j,v){return this.params.push({id:f,type:2,name:b,description:h,options:j,examples:v}),this}addOptionalSelect(f,b,h,j,v){return this.params.push({id:f,type:3,name:b,description:h,options:j,examples:v}),this}addNumericParam(f,b,h,j){return this.params.push({id:f,type:4,name:b,description:h,examples:j}),this}addNumericOptionalParam(f,b,h,j){return this.params.push({id:f,type:5,name:b,description:h,examples:j}),this}getUsage(){return this.params.map((f)=>w.getParamUsage(f)).join(" ")}getExample(){return this.params.map((f)=>w.getParamExample(f)).join(" ")}static getParamUsage(f){switch(f.type){case 0:return`<${f.extended?"...":""}${f.name}>`;case 1:return`[${f.extended?"...":""}${f.name}]`;case 2:return`<${f.options.map((b)=>b.name).join(" | ")}>`;case 3:return`[${f.options.map((b)=>b.name).join(" | ")}]`;case 4:return`<$${f.name}>`;case 5:return`[$${f.name}]`;default:return""}}static getParamExample(f){let b=(q)=>q[Math.floor(Math.random()*q.length)],h=(q)=>q?b(q):b(["Angel","Brian","Catherine","David","Emma","Frank","Grace","Hannah","Ian","Julia","Josefina"]),j=(q)=>q?b(q):b(["Brian Stronghold","Catherine Joyful","David Noble","Emma Graceful","Frank Fearless","Grace Serene","Hannah Bold","Ian Clever","Julia Kindhearted","Romana Einstein"]),v=(q)=>b(q)?.name,z=(q)=>q?b(q):Math.floor(Math.random()*1000);switch(f.type){case 1:case 0:return f.extended?j(f.examples):h(f.examples);case 2:case 3:return v(f.options);case 4:case 5:return z(f.examples);default:return""}}}export{w as CommandUsageClient};
|
package/dist/util/index.d.ts
CHANGED
|
@@ -8,8 +8,15 @@ export declare class AsyncLock {
|
|
|
8
8
|
lock(): void;
|
|
9
9
|
unlock(): void;
|
|
10
10
|
}
|
|
11
|
-
export declare
|
|
12
|
-
|
|
11
|
+
export declare const AU_HASH_ALGORITHM = "md5";
|
|
12
|
+
export declare const AU_STRING_ENCODING = "base64url";
|
|
13
|
+
export declare const AU_ID_BYTE_LENGTH = 12;
|
|
14
|
+
export declare const AU_AUTH_MIN_BYTE_LENGTH = 8;
|
|
15
|
+
export declare const AU_AUTH_MAX_BYTE_LENGTH = 64;
|
|
16
|
+
export declare class AuthUtil {
|
|
17
|
+
private static isValidBase64Url;
|
|
18
|
+
private static validateInputLengths;
|
|
19
|
+
static encodeToken(idHex: string, authHex: string): string | null;
|
|
13
20
|
static decodeToken(token: string): {
|
|
14
21
|
id: string;
|
|
15
22
|
auth: string;
|
package/dist/util/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class b{lockPromise;constructor(){this.lockPromise=void 0}get isLocked(){return!!this.lockPromise}wait(){return this.lockPromise?.promise||Promise.resolve()}lock(){let e,r=new Promise((t)=>{e=t});this.lockPromise={promise:r,resolve:e}}unlock(){this.lockPromise?.resolve(),this.lockPromise=void 0}}import c from"crypto";var h="md5",a="base64url",u=12,T=8,v=64,d=process.env.TOKEN_SECRET;if(!d)throw new Error("TOKEN_SECRET not set.");var m=d;class E{static isValidBase64Url(e){if(!e)return!1;for(let r=0;r<e.length;r++){let t=e.charCodeAt(r);if(!(t>=65&&t<=90||t>=97&&t<=122||t>=48&&t<=57||t===45||t===95))return!1}return!0}static validateInputLengths(e,r){if(e.length%2!==0||r.length%2!==0)return!1;if(e.length!==u*2)return!1;let t=r.length/2;if(t<T||t>v)return!1;return!0}static encodeToken(e,r){if(!this.validateInputLengths(e,r))return null;try{let t=Buffer.from(e,"hex"),s=Buffer.from(r,"hex"),n=Buffer.concat([t,s]),i=n.toString(a),o=c.createHmac(h,m);o.update(n);let l=o.digest().toString(a);return`${i}.${l}`}catch(t){return console.error("Error encoding token:",t),null}}static decodeToken(e){if(!e)return null;let r=e.split(".");if(r.length!==2)return null;let[t,s]=r;if(!t||!s)return null;if(!this.isValidBase64Url(t)||!this.isValidBase64Url(s))return null;try{let n=Buffer.from(t,a),i=Buffer.from(s,a),o=c.createHmac(h,m);o.update(n);let l=o.digest();if(n.length<u)return null;if(i.length!==l.length)return null;if(!c.timingSafeEqual(i,l))return null;let g=n.subarray(0,u),y=n.subarray(u),p=g.toString("hex"),f=y.toString("hex");if(!this.validateInputLengths(p,f))return null;return{id:p,auth:f}}catch(n){return null}}}class x{static wait(e){return new Promise((r)=>setTimeout(r,e))}}class B extends Map{ttl;constructor(e){super();this.ttl=e}pull(e){return super.get(e)?.value}push(e,r){let t=setTimeout(()=>this.delete(e),this.ttl);return super.set(e,{handle:t,value:r})}remove(e){let r=this.get(e);if(r)clearTimeout(r.handle);return super.delete(e)}modify(e,r){let t=super.get(e);if(t)return t.value=r,!0;return!1}}class _{static cutText(e,r,t=!0){return e.length>r?`${e.slice(0,t?Math.max(r-3,0):r)}${t?"...":""}`:e}}export{_ as TextUtil,B as TemporalMap,x as PromiseUtil,E as AuthUtil,b as AsyncLock,a as AU_STRING_ENCODING,u as AU_ID_BYTE_LENGTH,h as AU_HASH_ALGORITHM,T as AU_AUTH_MIN_BYTE_LENGTH,v as AU_AUTH_MAX_BYTE_LENGTH};
|
package/dist/validator/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class r{static isValidNumber(t){return!Number.isNaN(t)}static isValidInteger(t){return r.isValidNumber(t)&&Number.isInteger(t)}static isValidString(t){return typeof t==="string"&&!!t.trim()}static isAlphanumeric(t){return r.isValidString(t)&&/^[\w-.=:]+$/.test(t)}static isValidStringArray(t){return t.every((e)=>r.isValidString(e))}static isValidStringList(...t){return r.isValidStringArray(t)}static isStringLengthBetweenLimits(t,e,i){return r.isValidString(t)&&t.length>=e&&t.length<=i}static isStringArrayLengthBetweenLimits(t,e,i){return i.every((n)=>r.isStringLengthBetweenLimits(n,t,e))}static isStringListLengthBetweenLimits(t,e,...i){return r.isStringArrayLengthBetweenLimits(t,e,i)}static isFlatArrayUnique(t){let e=new Set;for(let i of t){if(e.has(i))return!1;e.add(i)}return!0}static isFlatArrayListUnique(...t){return t.every((e)=>r.isFlatArrayUnique(e))}static isArrayUniqueByValue(t,e){let i=new Set;for(let n of t){let s=e?e(n):JSON.stringify(n);if(i.has(s))return!1;i.add(s)}return!0}static isArrayListUniqueByValue(t,...e){return e.every((i)=>r.isArrayUniqueByValue(i,t))}static isValidEmail(t){if(!r.isValidString(t))return!1;let e=t.trim();if(!/^(?![_.-])(?!.*[_.-]{2})[a-zA-Z0-9._-]+(?<![_.-])@[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+$/.test(e))return!1;if(e.length>254)return!1;let n=e.split("@");if(n.length!==2)return!1;let[s,u]=n;if(!u)return!1;if(!s||s.length>64)return!1;if(u.split(".").some((a)=>a.length===0)||u.startsWith("-")||u.endsWith("-"))return!1;if(["mailinator.com","10minutemail.com","tempmail.com"].includes(u.toLowerCase()))return!1;return!0}}export{r as DataValidator};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fnlb-project/shared",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.38",
|
|
4
4
|
"description": "FNLB Shared Library",
|
|
5
5
|
"files": ["dist"],
|
|
6
6
|
"author": "FNLB-Project",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@biomejs/biome": "^1.9.4",
|
|
10
10
|
"@types/bun": "1.2.3",
|
|
11
11
|
"bun-plugin-dts": "^0.3.0",
|
|
12
|
-
"typescript": "^5.8.
|
|
12
|
+
"typescript": "^5.8.3"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
"./commands": {
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"lint": "bun run lint:biome && bun run lint:tsc",
|
|
48
48
|
"lint:biome": "bun biome check --write .",
|
|
49
49
|
"lint:tsc": "bun tsc --noEmit",
|
|
50
|
-
"test": "bun run test
|
|
50
|
+
"test": "bun run lint && bun test"
|
|
51
51
|
},
|
|
52
|
-
"type": "module"
|
|
52
|
+
"type": "module",
|
|
53
|
+
"trustedDependencies": ["@biomejs/biome"]
|
|
53
54
|
}
|