securequ 1.0.0 → 1.0.2

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/client/index.ts"],
4
- "sourcesContent": ["import crypto from \"../include/lib/crypto\";\r\nimport signeture from \"../include/signeture\";\r\nimport urlpath from \"../include/lib/urlpath\";\r\nimport { HttpRequestInit, RequestBody, SecurequClientConfig } from \"./types\";\r\nimport xanFetch from 'xanFetch'\r\nimport responseValue from \"../include/responseValue\";\r\nimport SecurequCache from \"../include/lib/cache\";\r\n\r\nclass SecurequClient {\r\n private config: SecurequClientConfig;\r\n private token: string = '';\r\n private tokenLoading: boolean = false;\r\n private Cache = new SecurequCache<Response>({ ttl: 1000 * 60 * 60, limit: 100 });\r\n\r\n private secret: string;\r\n private secret_length: number;\r\n private signerure: string;\r\n private reqkey: string = '';\r\n\r\n constructor(config: SecurequClientConfig) {\r\n this.config = { ...config }\r\n const secret = crypto.makeSecret(config.secret)\r\n this.config.secret = secret;\r\n this.secret_length = secret.length - (Math.floor(Math.random() * 11) + 5);\r\n this.secret = crypto.makeSecret(secret.substring(0, this.secret_length))\r\n this.signerure = signeture.make(this.secret, this.secret);\r\n }\r\n\r\n private setCache(path: string, method: string, response: any) {\r\n const cacheKey = `${method}:${path}`;\r\n if (this.config.cache === true) {\r\n this.Cache.set(cacheKey, response);\r\n } else if (this.config.cache) {\r\n this.config.cache.set(cacheKey, response);\r\n }\r\n }\r\n\r\n private getCache(path: string, method: string,) {\r\n const cacheKey = `${method}:${path}`;\r\n if (this.config.cache === true) {\r\n return this.Cache.get(cacheKey);\r\n } else if (this.config.cache) {\r\n return this.config.cache.get(cacheKey);\r\n }\r\n }\r\n\r\n private PATH_CACHE = new SecurequCache<string>({ ttl: 1000 * 60 * 60, limit: 100 });\r\n private path(path: string) {\r\n let pathKey = path\r\n let has = this.PATH_CACHE.get(pathKey)\r\n if (!has) {\r\n const { search, pathname } = new URL(path, window.location.origin);\r\n const params = new URLSearchParams(search);\r\n const paramsObject = Object.fromEntries(params.entries());\r\n let split = pathname.split(\"/\").map((s) => urlpath.encrypt(s)).filter((s) => s.length > 0);\r\n path = `${this.config.path}/${split.join(\"/\")}`;\r\n if (Object.keys(paramsObject).length) {\r\n for (let key in paramsObject) {\r\n paramsObject[urlpath.encrypt(key)] = paramsObject[key]\r\n delete paramsObject[key]\r\n }\r\n const string = JSON.stringify(paramsObject)\r\n const text = encodeURIComponent(crypto.encrypt(string, this.token));\r\n path += `?${this.reqkey}=${text}`;\r\n }\r\n this.PATH_CACHE.set(pathKey, path);\r\n } else {\r\n path = has\r\n }\r\n return path\r\n }\r\n\r\n private async handshake() {\r\n this.tokenLoading = true;\r\n const res = await xanFetch(this.path(`/handshake`), {\r\n method: \"GET\",\r\n headers: {\r\n ...this.config.headers,\r\n [signeture.key]: this.signerure\r\n },\r\n })\r\n\r\n const value: any = responseValue.decrypt(await res.text(), this.signerure)\r\n const token = crypto.decrypt(value, this.secret)\r\n this.token = token;\r\n this.reqkey = token.substring(0, token.length / 2);\r\n this.tokenLoading = false;\r\n }\r\n\r\n async send(path: string, init?: HttpRequestInit): Promise<Response> {\r\n if (path === '/handshake') {\r\n throw new Error(\"Path is not allowed\")\r\n }\r\n if (this.tokenLoading) {\r\n await new Promise((resolve) => {\r\n const interval = setInterval(() => {\r\n if (!this.tokenLoading) {\r\n clearInterval(interval);\r\n resolve(null);\r\n }\r\n }, 100);\r\n })\r\n }\r\n\r\n if (!this.token) {\r\n await this.handshake();\r\n }\r\n\r\n const info: any = {\r\n method: \"GET\",\r\n ...init,\r\n headers: {\r\n ...this.config.headers,\r\n ...init?.headers,\r\n [signeture.key]: this.signerure\r\n },\r\n }\r\n\r\n const cache_res = this.getCache(path, info.method);\r\n if (cache_res) {\r\n return cache_res.clone();\r\n }\r\n\r\n if (info.body) {\r\n if (!this.token) throw new Error(\"Token not loaded\")\r\n const body = new FormData();\r\n let _data: any = {}\r\n let hasFile = false;\r\n for (let key in info.body) {\r\n let ukey = urlpath.encrypt(key);\r\n if (info.body[key] instanceof File) {\r\n body.append(ukey, info.body[key]);\r\n hasFile = true;\r\n } else {\r\n _data[ukey] = info.body[key];\r\n }\r\n }\r\n\r\n body.append(this.reqkey, crypto.encrypt(_data, this.token));\r\n\r\n if (!hasFile) {\r\n info.body = new URLSearchParams(body as any);\r\n if (!info.headers['Content-Type']) {\r\n info.headers['Content-Type'] = 'application/x-www-form-urlencoded';\r\n }\r\n } else {\r\n if (info.method === \"GET\") {\r\n info.method = \"POST\"\r\n }\r\n info.body = body\r\n if (!info.headers['Content-Type']) {\r\n info.headers['Content-Type'] = 'multipart/form-data';\r\n }\r\n }\r\n }\r\n\r\n const response = await xanFetch(this.path(path), info);\r\n const res = response.clone();\r\n const text = await response.text();\r\n const value: any = responseValue.decrypt(text, this.signerure)\r\n res.text = async () => value;\r\n if (this.config.cache === true && res.ok) {\r\n this.setCache(path, info.method, res.clone());\r\n }\r\n return res\r\n }\r\n\r\n async get(path: string, init?: HttpRequestInit) {\r\n return await this.send(path, init);\r\n }\r\n\r\n async post(path: string, body: RequestBody, init?: HttpRequestInit) {\r\n return await this.send(path, {\r\n ...init,\r\n method: \"POST\",\r\n body: body\r\n });\r\n }\r\n\r\n async put(path: string, body: RequestBody, init?: HttpRequestInit) {\r\n return await this.send(path, {\r\n ...init,\r\n method: \"PUT\",\r\n body: body\r\n });\r\n }\r\n\r\n async delete(path: string, init?: HttpRequestInit) {\r\n return await this.send(path, {\r\n ...init,\r\n method: \"DELETE\",\r\n });\r\n }\r\n}\r\n\r\nexport default SecurequClient"],
4
+ "sourcesContent": ["import crypto from \"../include/lib/crypto\";\nimport signeture from \"../include/signeture\";\nimport urlpath from \"../include/lib/urlpath\";\nimport { HttpRequestInit, RequestBody, SecurequClientConfig } from \"./types\";\nimport xanFetch from 'xanFetch'\nimport responseValue from \"../include/responseValue\";\nimport SecurequCache from \"../include/lib/cache\";\n\nclass SecurequClient {\n private config: SecurequClientConfig;\n private token: string = '';\n private tokenLoading: boolean = false;\n private Cache = new SecurequCache<Response>({ ttl: 1000 * 60 * 60, limit: 100 });\n\n private secret: string;\n private secret_length: number;\n private signerure: string;\n private reqkey: string = '';\n\n constructor(config: SecurequClientConfig) {\n this.config = { ...config }\n const secret = crypto.makeSecret(config.secret)\n this.config.secret = secret;\n this.secret_length = secret.length - (Math.floor(Math.random() * 11) + 5);\n this.secret = crypto.makeSecret(secret.substring(0, this.secret_length))\n this.signerure = signeture.make(this.secret, this.secret);\n }\n\n private setCache(path: string, method: string, response: any) {\n const cacheKey = `${method}:${path}`;\n if (this.config.cache === true) {\n this.Cache.set(cacheKey, response);\n } else if (this.config.cache) {\n this.config.cache.set(cacheKey, response);\n }\n }\n\n private getCache(path: string, method: string,) {\n const cacheKey = `${method}:${path}`;\n if (this.config.cache === true) {\n return this.Cache.get(cacheKey);\n } else if (this.config.cache) {\n return this.config.cache.get(cacheKey);\n }\n }\n\n private PATH_CACHE = new SecurequCache<string>({ ttl: 1000 * 60 * 60, limit: 100 });\n private path(path: string) {\n let pathKey = path\n let has = this.PATH_CACHE.get(pathKey)\n if (!has) {\n const { search, pathname } = new URL(path, window.location.origin);\n const params = new URLSearchParams(search);\n const paramsObject = Object.fromEntries(params.entries());\n let split = pathname.split(\"/\").map((s) => urlpath.encrypt(s)).filter((s) => s.length > 0);\n path = `${this.config.path}/${split.join(\"/\")}`;\n if (Object.keys(paramsObject).length) {\n for (let key in paramsObject) {\n paramsObject[urlpath.encrypt(key)] = paramsObject[key]\n delete paramsObject[key]\n }\n const string = JSON.stringify(paramsObject)\n const text = encodeURIComponent(crypto.encrypt(string, this.token));\n path += `?${this.reqkey}=${text}`;\n }\n this.PATH_CACHE.set(pathKey, path);\n } else {\n path = has\n }\n return path\n }\n\n private async handshake() {\n this.tokenLoading = true;\n const res = await xanFetch(this.path(`/handshake`), {\n method: \"GET\",\n headers: {\n ...this.config.headers,\n [signeture.key]: this.signerure\n },\n })\n\n const value: any = responseValue.decrypt(await res.text(), this.signerure)\n const token = crypto.decrypt(value, this.secret)\n this.token = token;\n this.reqkey = token.substring(0, token.length / 2);\n this.tokenLoading = false;\n }\n\n async send(path: string, init?: HttpRequestInit): Promise<Response> {\n if (path === '/handshake') {\n throw new Error(\"Path is not allowed\")\n }\n if (this.tokenLoading) {\n await new Promise((resolve) => {\n const interval = setInterval(() => {\n if (!this.tokenLoading) {\n clearInterval(interval);\n resolve(null);\n }\n }, 100);\n })\n }\n\n if (!this.token) {\n await this.handshake();\n }\n\n const info: any = {\n method: \"GET\",\n ...init,\n headers: {\n ...this.config.headers,\n ...init?.headers,\n [signeture.key]: this.signerure\n },\n }\n\n const cache_res = this.getCache(path, info.method);\n if (cache_res) {\n return cache_res.clone();\n }\n\n if (info.body) {\n if (!this.token) throw new Error(\"Token not loaded\")\n const body = new FormData();\n let _data: any = {}\n let hasFile = false;\n for (let key in info.body) {\n let ukey = urlpath.encrypt(key);\n if (info.body[key] instanceof File) {\n body.append(ukey, info.body[key]);\n hasFile = true;\n } else {\n _data[ukey] = info.body[key];\n }\n }\n\n body.append(this.reqkey, crypto.encrypt(_data, this.token));\n\n if (!hasFile) {\n info.body = new URLSearchParams(body as any);\n if (!info.headers['Content-Type']) {\n info.headers['Content-Type'] = 'application/x-www-form-urlencoded';\n }\n } else {\n if (info.method === \"GET\") {\n info.method = \"POST\"\n }\n info.body = body\n if (!info.headers['Content-Type']) {\n info.headers['Content-Type'] = 'multipart/form-data';\n }\n }\n }\n\n const response = await xanFetch(this.path(path), info);\n const res = response.clone();\n const text = await response.text();\n const value: any = responseValue.decrypt(text, this.signerure)\n res.text = async () => value;\n if (this.config.cache === true && res.ok) {\n this.setCache(path, info.method, res.clone());\n }\n return res\n }\n\n async get(path: string, init?: HttpRequestInit) {\n return await this.send(path, init);\n }\n\n async post(path: string, body: RequestBody, init?: HttpRequestInit) {\n return await this.send(path, {\n ...init,\n method: \"POST\",\n body: body\n });\n }\n\n async put(path: string, body: RequestBody, init?: HttpRequestInit) {\n return await this.send(path, {\n ...init,\n method: \"PUT\",\n body: body\n });\n }\n\n async delete(path: string, init?: HttpRequestInit) {\n return await this.send(path, {\n ...init,\n method: \"DELETE\",\n });\n }\n}\n\nexport default SecurequClient"],
5
5
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmB,oCACnBC,EAAsB,mCACtBC,EAAoB,qCAEpBC,EAAqB,uBACrBC,EAA0B,uCAC1BC,EAA0B,mCAE1B,MAAMC,CAAe,CAWlB,YAAYC,EAA8B,CAT1C,KAAQ,MAAgB,GACxB,KAAQ,aAAwB,GAChC,KAAQ,MAAQ,IAAI,EAAAC,QAAwB,CAAE,IAAK,IAAO,GAAK,GAAI,MAAO,GAAI,CAAC,EAK/E,KAAQ,OAAiB,GA6BzB,KAAQ,WAAa,IAAI,EAAAA,QAAsB,CAAE,IAAK,IAAO,GAAK,GAAI,MAAO,GAAI,CAAC,EA1B/E,KAAK,OAAS,CAAE,GAAGD,CAAO,EAC1B,MAAME,EAAS,EAAAC,QAAO,WAAWH,EAAO,MAAM,EAC9C,KAAK,OAAO,OAASE,EACrB,KAAK,cAAgBA,EAAO,QAAU,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,EAAI,GACvE,KAAK,OAAS,EAAAC,QAAO,WAAWD,EAAO,UAAU,EAAG,KAAK,aAAa,CAAC,EACvE,KAAK,UAAY,EAAAE,QAAU,KAAK,KAAK,OAAQ,KAAK,MAAM,CAC3D,CAEQ,SAASC,EAAcC,EAAgBC,EAAe,CAC3D,MAAMC,EAAW,GAAGF,CAAM,IAAID,CAAI,GAC9B,KAAK,OAAO,QAAU,GACvB,KAAK,MAAM,IAAIG,EAAUD,CAAQ,EACzB,KAAK,OAAO,OACpB,KAAK,OAAO,MAAM,IAAIC,EAAUD,CAAQ,CAE9C,CAEQ,SAASF,EAAcC,EAA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AErDC,GAMEJ,EAAK,SAAW,QACjBA,EAAK,OAAS,QAEjBA,EAAK,KAAOE,EACPF,EAAK,QAAQ,cAAc,IAC7BA,EAAK,QAAQ,cAAc,EAAI,yBAVlCA,EAAK,KAAO,IAAI,gBAAgBE,CAAW,EACtCF,EAAK,QAAQ,cAAc,IAC7BA,EAAK,QAAQ,cAAc,EAAI,qCAWxC,CAEA,MAAMtB,EAAW,QAAM,EAAAe,SAAS,KAAK,KAAKjB,CAAI,EAAGwB,CAAI,EAC/CR,EAAMd,EAAS,MAAM,EACrBa,EAAO,MAAMb,EAAS,KAAK,EAC3BgB,EAAa,EAAAC,QAAc,QAAQJ,EAAM,KAAK,SAAS,EAC7D,OAAAC,EAAI,KAAO,SAAYE,EACnB,KAAK,OAAO,QAAU,IAAQF,EAAI,IACnC,KAAK,SAAShB,EAAMwB,EAAK,OAAQR,EAAI,MAAM,CAAC,EAExCA,CACV,CAEA,MAAM,IAAIhB,EAAcqB,EAAwB,CAC7C,OAAO,MAAM,KAAK,KAAKrB,EAAMqB,CAAI,CACpC,CAEA,MAAM,KAAKrB,EAAc0B,EAAmBL,EAAwB,CACjE,OAAO,MAAM,KAAK,KAAKrB,EAAM,CAC1B,GAAGqB,EACH,OAAQ,OACR,KAAMK,CACT,CAAC,CACJ,CAEA,MAAM,IAAI1B,EAAc0B,EAAmBL,EAAwB,CAChE,OAAO,MAAM,KAAK,KAAKrB,EAAM,CAC1B,GAAGqB,EACH,OAAQ,MACR,KAAMK,CACT,CAAC,CACJ,CAEA,MAAM,OAAO1B,EAAcqB,EAAwB,CAChD,OAAO,MAAM,KAAK,KAAKrB,EAAM,CAC1B,GAAGqB,EACH,OAAQ,QACX,CAAC,CACJ,CACH,CAEA,IAAOnC,EAAQQ",
6
6
  "names": ["client_exports", "__export", "client_default", "__toCommonJS", "import_crypto", "import_signeture", "import_urlpath", "import_xanFetch", "import_responseValue", "import_cache", "SecurequClient", "config", "SecurequCache", "secret", "crypto", "signeture", "path", "method", "response", "cacheKey", "pathKey", "has", "search", "pathname", "params", "paramsObject", "split", "s", "urlpath", "key", "string", "text", "res", "xanFetch", "value", "responseValue", "token", "init", "resolve", "interval", "info", "cache_res", "body", "_data", "hasFile", "ukey"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/client/types.ts"],
4
- "sourcesContent": ["export type SecurequClientConfig = {\r\n secret: string;\r\n path?: string;\r\n headers?: Record<string, string>;\r\n cache?: boolean | {\r\n get: (key: string) => any;\r\n set: (key: string, response: Response) => void;\r\n };\r\n}\r\n\r\n\r\nexport type HTTPMethods = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\";\r\n\r\nexport type RequestBody = {\r\n [key: string]: any;\r\n}\r\n\r\nexport type HttpRequestInit = Omit<RequestInit, 'body'> & {\r\n body?: RequestBody;\r\n}\r\n\r\nexport type ResponseError = {\r\n field: string;\r\n message: string;\r\n}\r\n"],
4
+ "sourcesContent": ["export type SecurequClientConfig = {\n secret: string;\n path?: string;\n headers?: Record<string, string>;\n cache?: boolean | {\n get: (key: string) => any;\n set: (key: string, response: Response) => void;\n };\n}\n\n\nexport type HTTPMethods = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\";\n\nexport type RequestBody = {\n [key: string]: any;\n}\n\nexport type HttpRequestInit = Omit<RequestInit, 'body'> & {\n body?: RequestBody;\n}\n\nexport type ResponseError = {\n field: string;\n message: string;\n}\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["types_exports", "__toCommonJS"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/include/lib/base64.ts"],
4
- "sourcesContent": ["/**\r\n * Encodes a Uint8Array to Base64 (for browser or Node.js).\r\n * @param data - The Uint8Array data to encode.\r\n * @returns The Base64-encoded string.\r\n */\r\nfunction encode(data: Uint8Array): string {\r\n let base64 = \"\";\r\n if (typeof window !== \"undefined\") {\r\n base64 = btoa(String.fromCharCode(...Array.from(data)));\r\n } else {\r\n base64 = Buffer.from(data).toString(\"base64\");\r\n }\r\n let paddingCount = (base64.match(/=+$/) || [''])[0].length;\r\n if (paddingCount > 0) {\r\n base64 = base64.replace(/=+$/, () => `$${paddingCount}`);\r\n }\r\n return base64\r\n}\r\n\r\n/**\r\n * Decodes a Base64 string to a Uint8Array (for browser or Node.js).\r\n * @param base64String - The Base64 string to decode.\r\n * @returns The decoded Uint8Array.\r\n */\r\nfunction decode(base64: string): Uint8Array {\r\n try {\r\n base64 = base64.replace(/\\$(\\d)/, (_match, count) => '='.repeat(parseInt(count)));\r\n if (typeof window !== \"undefined\") {\r\n const binaryString = atob(base64);\r\n const byteArray = new Uint8Array(binaryString.length);\r\n for (let i = 0; i < binaryString.length; i++) {\r\n byteArray[i] = binaryString.charCodeAt(i);\r\n }\r\n return byteArray;\r\n } else {\r\n return Uint8Array.from(Buffer.from(base64, \"base64\"));\r\n }\r\n } catch (error) {\r\n throw new Error(\"Invalid Base64 string.\");\r\n }\r\n}\r\n\r\nconst base64 = {\r\n encode,\r\n decode\r\n}\r\n\r\nexport default base64;"],
4
+ "sourcesContent": ["/**\n * Encodes a Uint8Array to Base64 (for browser or Node.js).\n * @param data - The Uint8Array data to encode.\n * @returns The Base64-encoded string.\n */\nfunction encode(data: Uint8Array): string {\n let base64 = \"\";\n if (typeof window !== \"undefined\") {\n base64 = btoa(String.fromCharCode(...Array.from(data)));\n } else {\n base64 = Buffer.from(data).toString(\"base64\");\n }\n let paddingCount = (base64.match(/=+$/) || [''])[0].length;\n if (paddingCount > 0) {\n base64 = base64.replace(/=+$/, () => `$${paddingCount}`);\n }\n return base64\n}\n\n/**\n * Decodes a Base64 string to a Uint8Array (for browser or Node.js).\n * @param base64String - The Base64 string to decode.\n * @returns The decoded Uint8Array.\n */\nfunction decode(base64: string): Uint8Array {\n try {\n base64 = base64.replace(/\\$(\\d)/, (_match, count) => '='.repeat(parseInt(count)));\n if (typeof window !== \"undefined\") {\n const binaryString = atob(base64);\n const byteArray = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n byteArray[i] = binaryString.charCodeAt(i);\n }\n return byteArray;\n } else {\n return Uint8Array.from(Buffer.from(base64, \"base64\"));\n }\n } catch (error) {\n throw new Error(\"Invalid Base64 string.\");\n }\n}\n\nconst base64 = {\n encode,\n decode\n}\n\nexport default base64;"],
5
5
  "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAKA,SAASI,EAAOC,EAA0B,CACvC,IAAIC,EAAS,GACT,OAAO,OAAW,IACnBA,EAAS,KAAK,OAAO,aAAa,GAAG,MAAM,KAAKD,CAAI,CAAC,CAAC,EAEtDC,EAAS,OAAO,KAAKD,CAAI,EAAE,SAAS,QAAQ,EAE/C,IAAIE,GAAgBD,EAAO,MAAM,KAAK,GAAK,CAAC,EAAE,GAAG,CAAC,EAAE,OACpD,OAAIC,EAAe,IAChBD,EAASA,EAAO,QAAQ,MAAO,IAAM,IAAIC,CAAY,EAAE,GAEnDD,CACV,CAOA,SAASE,EAAOF,EAA4B,CACzC,GAAI,CAED,GADAA,EAASA,EAAO,QAAQ,SAAU,CAACG,EAAQC,IAAU,IAAI,OAAO,SAASA,CAAK,CAAC,CAAC,EAC5E,OAAO,OAAW,IAAa,CAChC,MAAMC,EAAe,KAAKL,CAAM,EAC1BM,EAAY,IAAI,WAAWD,EAAa,MAAM,EACpD,QAASE,EAAI,EAAGA,EAAIF,EAAa,OAAQE,IACtCD,EAAUC,CAAC,EAAIF,EAAa,WAAWE,CAAC,EAE3C,OAAOD,CACV,KACG,QAAO,WAAW,KAAK,OAAO,KAAKN,EAAQ,QAAQ,CAAC,CAE1D,MAAgB,CACb,MAAM,IAAI,MAAM,wBAAwB,CAC3C,CACH,CAEA,MAAMA,EAAS,CACZ,OAAAF,EACA,OAAAI,CACH,EAEA,IAAON,EAAQI",
6
6
  "names": ["base64_exports", "__export", "base64_default", "__toCommonJS", "encode", "data", "base64", "paddingCount", "decode", "_match", "count", "binaryString", "byteArray", "i"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/include/lib/cache.ts"],
4
- "sourcesContent": ["class SecurequCache<T> {\r\n private store: Map<string, { value: T; timeout: NodeJS.Timeout; expiresAt: number }>;\r\n private defaultTTL: number; // Global TTL for all cache entries\r\n private limit: number; // Limit on the number of cache entries\r\n\r\n constructor(config: { ttl: number; limit: number }) {\r\n this.store = new Map();\r\n this.defaultTTL = config.ttl;\r\n this.limit = config.limit;\r\n }\r\n\r\n /**\r\n * Set a value in the cache with a global TTL\r\n * @param key - Cache key\r\n * @param value - Cache value\r\n */\r\n set(key: string, value: T): void {\r\n // If the cache exceeds the limit, remove the oldest (least recently used) item\r\n if (this.store.size >= this.limit) {\r\n const firstKey: any = this.store.keys().next().value;\r\n this.store.delete(firstKey);\r\n }\r\n\r\n // If the key already exists, remove the old timeout\r\n if (this.store.has(key)) {\r\n clearTimeout(this.store.get(key)!.timeout);\r\n }\r\n\r\n // Set the new expiration timeout\r\n const timeout = setTimeout(() => {\r\n this.store.delete(key); // Delete expired cache entry\r\n }, this.defaultTTL);\r\n\r\n // Store the value and its expiration info\r\n this.store.set(key, { value, timeout, expiresAt: Date.now() + this.defaultTTL });\r\n }\r\n\r\n /**\r\n * Get a value from the cache and auto-renew the TTL if not expired\r\n * @param key - Cache key\r\n * @returns The cached value or null if expired\r\n */\r\n get(key: string): T | null {\r\n const entry = this.store.get(key);\r\n\r\n if (!entry) {\r\n return null; // No data found in cache\r\n }\r\n\r\n // Check if the cache has expired\r\n if (Date.now() > entry.expiresAt) {\r\n this.store.delete(key); // Automatically delete expired cache entry\r\n return null;\r\n }\r\n\r\n this.set(key, entry.value);\r\n return entry.value;\r\n }\r\n\r\n /**\r\n * Delete a key from the cache\r\n * @param key - Cache key\r\n */\r\n delete(key: string): void {\r\n const entry = this.store.get(key);\r\n if (entry) {\r\n clearTimeout(entry.timeout); // Clear the timeout\r\n this.store.delete(key); // Delete from cache\r\n }\r\n }\r\n\r\n /**\r\n * Clear the entire cache\r\n */\r\n clear(): void {\r\n this.store.forEach((entry) => clearTimeout(entry.timeout)); // Clear all timeouts\r\n this.store.clear(); // Clear the store\r\n }\r\n\r\n /**\r\n * Get the current size of the cache\r\n * @returns The number of items in the cache\r\n */\r\n size(): number {\r\n return this.store.size;\r\n }\r\n}\r\n\r\n\r\nexport default SecurequCache"],
4
+ "sourcesContent": ["class SecurequCache<T> {\n private store: Map<string, { value: T; timeout: NodeJS.Timeout; expiresAt: number }>;\n private defaultTTL: number; // Global TTL for all cache entries\n private limit: number; // Limit on the number of cache entries\n\n constructor(config: { ttl: number; limit: number }) {\n this.store = new Map();\n this.defaultTTL = config.ttl;\n this.limit = config.limit;\n }\n\n /**\n * Set a value in the cache with a global TTL\n * @param key - Cache key\n * @param value - Cache value\n */\n set(key: string, value: T): void {\n // If the cache exceeds the limit, remove the oldest (least recently used) item\n if (this.store.size >= this.limit) {\n const firstKey: any = this.store.keys().next().value;\n this.store.delete(firstKey);\n }\n\n // If the key already exists, remove the old timeout\n if (this.store.has(key)) {\n clearTimeout(this.store.get(key)!.timeout);\n }\n\n // Set the new expiration timeout\n const timeout = setTimeout(() => {\n this.store.delete(key); // Delete expired cache entry\n }, this.defaultTTL);\n\n // Store the value and its expiration info\n this.store.set(key, { value, timeout, expiresAt: Date.now() + this.defaultTTL });\n }\n\n /**\n * Get a value from the cache and auto-renew the TTL if not expired\n * @param key - Cache key\n * @returns The cached value or null if expired\n */\n get(key: string): T | null {\n const entry = this.store.get(key);\n\n if (!entry) {\n return null; // No data found in cache\n }\n\n // Check if the cache has expired\n if (Date.now() > entry.expiresAt) {\n this.store.delete(key); // Automatically delete expired cache entry\n return null;\n }\n\n this.set(key, entry.value);\n return entry.value;\n }\n\n /**\n * Delete a key from the cache\n * @param key - Cache key\n */\n delete(key: string): void {\n const entry = this.store.get(key);\n if (entry) {\n clearTimeout(entry.timeout); // Clear the timeout\n this.store.delete(key); // Delete from cache\n }\n }\n\n /**\n * Clear the entire cache\n */\n clear(): void {\n this.store.forEach((entry) => clearTimeout(entry.timeout)); // Clear all timeouts\n this.store.clear(); // Clear the store\n }\n\n /**\n * Get the current size of the cache\n * @returns The number of items in the cache\n */\n size(): number {\n return this.store.size;\n }\n}\n\n\nexport default SecurequCache"],
5
5
  "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,MAAMI,CAAiB,CAKpB,YAAYC,EAAwC,CACjD,KAAK,MAAQ,IAAI,IACjB,KAAK,WAAaA,EAAO,IACzB,KAAK,MAAQA,EAAO,KACvB,CAOA,IAAIC,EAAaC,EAAgB,CAE9B,GAAI,KAAK,MAAM,MAAQ,KAAK,MAAO,CAChC,MAAMC,EAAgB,KAAK,MAAM,KAAK,EAAE,KAAK,EAAE,MAC/C,KAAK,MAAM,OAAOA,CAAQ,CAC7B,CAGI,KAAK,MAAM,IAAIF,CAAG,GACnB,aAAa,KAAK,MAAM,IAAIA,CAAG,EAAG,OAAO,EAI5C,MAAMG,EAAU,WAAW,IAAM,CAC9B,KAAK,MAAM,OAAOH,CAAG,CACxB,EAAG,KAAK,UAAU,EAGlB,KAAK,MAAM,IAAIA,EAAK,CAAE,MAAAC,EAAO,QAAAE,EAAS,UAAW,KAAK,IAAI,EAAI,KAAK,UAAW,CAAC,CAClF,CAOA,IAAIH,EAAuB,CACxB,MAAMI,EAAQ,KAAK,MAAM,IAAIJ,CAAG,EAEhC,OAAKI,EAKD,KAAK,IAAI,EAAIA,EAAM,WACpB,KAAK,MAAM,OAAOJ,CAAG,EACd,OAGV,KAAK,IAAIA,EAAKI,EAAM,KAAK,EAClBA,EAAM,OAVH,IAWb,CAMA,OAAOJ,EAAmB,CACvB,MAAMI,EAAQ,KAAK,MAAM,IAAIJ,CAAG,EAC5BI,IACD,aAAaA,EAAM,OAAO,EAC1B,KAAK,MAAM,OAAOJ,CAAG,EAE3B,CAKA,OAAc,CACX,KAAK,MAAM,QAASI,GAAU,aAAaA,EAAM,OAAO,CAAC,EACzD,KAAK,MAAM,MAAM,CACpB,CAMA,MAAe,CACZ,OAAO,KAAK,MAAM,IACrB,CACH,CAGA,IAAOR,EAAQE",
6
6
  "names": ["cache_exports", "__export", "cache_default", "__toCommonJS", "SecurequCache", "config", "key", "value", "firstKey", "timeout", "entry"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/include/lib/crypto.ts"],
4
- "sourcesContent": ["import nacl from \"tweetnacl\";\r\nimport base64 from \"./base64\";\r\nimport pako from \"./pako\";\r\n\r\n/**\r\n * Encrypts data using TweetNaCl, compresses it with Pako (Gzip), and encodes it in Base64.\r\n * @param data - The plaintext data to encrypt.\r\n * @param secret - The secret key as a string.\r\n * @returns A Base64 encoded string (nonce + compressed ciphertext).\r\n */\r\nfunction encrypt(data: string | object, secret: string): string {\r\n data = typeof data === \"object\" ? JSON.stringify(data) : data\r\n secret = hash(secret).substring(0, 32)\r\n const key = new TextEncoder().encode(secret);\r\n const nonce = nacl.randomBytes(nacl.secretbox.nonceLength);\r\n const compressed = pako.compress(data, true) as Uint8Array // Ensure it returns Uint8Array\r\n const encrypted = nacl.secretbox(compressed, nonce, key);\r\n return base64.encode(new Uint8Array([...nonce, ...encrypted]));\r\n}\r\n\r\n/**\r\n * Decrypts a Base64-encoded NaCl-encrypted data, decompresses it with Pako (Gzip).\r\n * @param data - The Base64 encoded string (nonce + compressed ciphertext).\r\n * @param secret - The secret key as a string.\r\n * @returns The decrypted plaintext string.\r\n */\r\nfunction decrypt(data: string, secret: string): string {\r\n try {\r\n secret = hash(secret).substring(0, 32)\r\n const key = new TextEncoder().encode(secret);\r\n const encryptedBytes = base64.decode(data);\r\n const nonce = encryptedBytes.slice(0, nacl.secretbox.nonceLength);\r\n const ciphertext = encryptedBytes.slice(nacl.secretbox.nonceLength);\r\n const decrypted = nacl.secretbox.open(ciphertext, nonce, key);\r\n if (!decrypted) throw new Error(\"Decryption failed!\");\r\n const decompressed = pako.decompress(decrypted); // Decompress as string\r\n try {\r\n return JSON.parse(decompressed);\r\n } catch (error) {\r\n return decompressed;\r\n }\r\n } catch (error) {\r\n throw new Error(\"Invalid encrypted data.\");\r\n }\r\n}\r\n\r\n/**\r\n * Hashes a string using NaCl's hash function.\r\n * @param data - The input string to hash.\r\n * @returns The hash of the input string.\r\n */\r\nlet hashed = new Map<string, string>();\r\nfunction hash(data: string): string {\r\n if (hashed.has(data)) return hashed.get(data) as string\r\n const inputBytes = new TextEncoder().encode(data);\r\n const hashedData = nacl.hash(inputBytes);\r\n const d = Array.from(hashedData)\r\n .map(byte => byte.toString(16).padStart(2, '0'))\r\n .join('');\r\n hashed.set(data, d)\r\n return d\r\n}\r\n\r\nconst makeSecret = (secret: string) => {\r\n return hash(secret).substring(0, 32);\r\n}\r\n\r\nconst crypto = {\r\n encrypt,\r\n decrypt,\r\n hash,\r\n makeSecret\r\n};\r\n\r\nexport default crypto;\r\n"],
4
+ "sourcesContent": ["import nacl from \"tweetnacl\";\nimport base64 from \"./base64\";\nimport pako from \"./pako\";\n\n/**\n * Encrypts data using TweetNaCl, compresses it with Pako (Gzip), and encodes it in Base64.\n * @param data - The plaintext data to encrypt.\n * @param secret - The secret key as a string.\n * @returns A Base64 encoded string (nonce + compressed ciphertext).\n */\nfunction encrypt(data: string | object, secret: string): string {\n data = typeof data === \"object\" ? JSON.stringify(data) : data\n secret = hash(secret).substring(0, 32)\n const key = new TextEncoder().encode(secret);\n const nonce = nacl.randomBytes(nacl.secretbox.nonceLength);\n const compressed = pako.compress(data, true) as Uint8Array // Ensure it returns Uint8Array\n const encrypted = nacl.secretbox(compressed, nonce, key);\n return base64.encode(new Uint8Array([...nonce, ...encrypted]));\n}\n\n/**\n * Decrypts a Base64-encoded NaCl-encrypted data, decompresses it with Pako (Gzip).\n * @param data - The Base64 encoded string (nonce + compressed ciphertext).\n * @param secret - The secret key as a string.\n * @returns The decrypted plaintext string.\n */\nfunction decrypt(data: string, secret: string): string {\n try {\n secret = hash(secret).substring(0, 32)\n const key = new TextEncoder().encode(secret);\n const encryptedBytes = base64.decode(data);\n const nonce = encryptedBytes.slice(0, nacl.secretbox.nonceLength);\n const ciphertext = encryptedBytes.slice(nacl.secretbox.nonceLength);\n const decrypted = nacl.secretbox.open(ciphertext, nonce, key);\n if (!decrypted) throw new Error(\"Decryption failed!\");\n const decompressed = pako.decompress(decrypted); // Decompress as string\n try {\n return JSON.parse(decompressed);\n } catch (error) {\n return decompressed;\n }\n } catch (error) {\n throw new Error(\"Invalid encrypted data.\");\n }\n}\n\n/**\n * Hashes a string using NaCl's hash function.\n * @param data - The input string to hash.\n * @returns The hash of the input string.\n */\nlet hashed = new Map<string, string>();\nfunction hash(data: string): string {\n if (hashed.has(data)) return hashed.get(data) as string\n const inputBytes = new TextEncoder().encode(data);\n const hashedData = nacl.hash(inputBytes);\n const d = Array.from(hashedData)\n .map(byte => byte.toString(16).padStart(2, '0'))\n .join('');\n hashed.set(data, d)\n return d\n}\n\nconst makeSecret = (secret: string) => {\n return hash(secret).substring(0, 32);\n}\n\nconst crypto = {\n encrypt,\n decrypt,\n hash,\n makeSecret\n};\n\nexport default crypto;\n"],
5
5
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiB,wBACjBC,EAAmB,uBACnBC,EAAiB,qBAQjB,SAASC,EAAQC,EAAuBC,EAAwB,CAC7DD,EAAO,OAAOA,GAAS,SAAW,KAAK,UAAUA,CAAI,EAAIA,EACzDC,EAASC,EAAKD,CAAM,EAAE,UAAU,EAAG,EAAE,EACrC,MAAME,EAAM,IAAI,YAAY,EAAE,OAAOF,CAAM,EACrCG,EAAQ,EAAAC,QAAK,YAAY,EAAAA,QAAK,UAAU,WAAW,EAC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CoB,EAAS,CACZ,QAAAtB,EACA,QAAAW,EACA,KAAAR,EACA,WAAAkB,CACH,EAEA,IAAO1B,EAAQ2B",
6
6
  "names": ["crypto_exports", "__export", "crypto_default", "__toCommonJS", "import_tweetnacl", "import_base64", "import_pako", "encrypt", "data", "secret", "hash", "key", "nonce", "nacl", "compressed", "pako", "encrypted", "base64", "decrypt", "encryptedBytes", "ciphertext", "decrypted", "decompressed", "hashed", "inputBytes", "hashedData", "d", "byte", "makeSecret", "crypto"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/include/lib/pako.ts"],
4
- "sourcesContent": ["import pako from \"pako\";\r\nimport base64 from \"./base64\";\r\n\r\n/**\r\n * Compresses a string message using Pako (Gzip).\r\n * @param message - The plaintext string message to compress.\r\n * @returns A Base64 encoded string of the compressed data.\r\n */\r\nexport function compress(data: string, returnUnit8?: boolean): string | Uint8Array {\r\n const encoded = new TextEncoder().encode(data);\r\n const compressed = pako.gzip(encoded);\r\n if (returnUnit8) return compressed;\r\n return base64.encode(compressed);\r\n}\r\n\r\n/**\r\n * Decompresses a Base64 encoded compressed message using Pako (Gzip).\r\n * @param data - The Base64 encoded compressed data.\r\n * @returns The decompressed plaintext string.\r\n */\r\nexport function decompress(data: string | Uint8Array): string {\r\n if (typeof data === 'string') {\r\n data = base64.decode(data);\r\n }\r\n const decompressed = pako.ungzip(data);\r\n return new TextDecoder().decode(decompressed);\r\n}\r\n\r\nexport default {\r\n compress,\r\n decompress\r\n}"],
4
+ "sourcesContent": ["import pako from \"pako\";\nimport base64 from \"./base64\";\n\n/**\n * Compresses a string message using Pako (Gzip).\n * @param message - The plaintext string message to compress.\n * @returns A Base64 encoded string of the compressed data.\n */\nexport function compress(data: string, returnUnit8?: boolean): string | Uint8Array {\n const encoded = new TextEncoder().encode(data);\n const compressed = pako.gzip(encoded);\n if (returnUnit8) return compressed;\n return base64.encode(compressed);\n}\n\n/**\n * Decompresses a Base64 encoded compressed message using Pako (Gzip).\n * @param data - The Base64 encoded compressed data.\n * @returns The decompressed plaintext string.\n */\nexport function decompress(data: string | Uint8Array): string {\n if (typeof data === 'string') {\n data = base64.decode(data);\n }\n const decompressed = pako.ungzip(data);\n return new TextDecoder().decode(decompressed);\n}\n\nexport default {\n compress,\n decompress\n}"],
5
5
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,eAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAAiB,mBACjBC,EAAmB,uBAOZ,SAASL,EAASM,EAAcC,EAA4C,CAChF,MAAMC,EAAU,IAAI,YAAY,EAAE,OAAOF,CAAI,EACvCG,EAAa,EAAAC,QAAK,KAAKF,CAAO,EACpC,OAAID,EAAoBE,EACjB,EAAAE,QAAO,OAAOF,CAAU,CAClC,CAOO,SAASR,EAAWK,EAAmC,CACvD,OAAOA,GAAS,WACjBA,EAAO,EAAAK,QAAO,OAAOL,CAAI,GAE5B,MAAMM,EAAe,EAAAF,QAAK,OAAOJ,CAAI,EACrC,OAAO,IAAI,YAAY,EAAE,OAAOM,CAAY,CAC/C,CAEA,IAAOV,EAAQ,CACZ,SAAAF,EACA,WAAAC,CACH",
6
6
  "names": ["pako_exports", "__export", "compress", "decompress", "pako_default", "__toCommonJS", "import_pako", "import_base64", "data", "returnUnit8", "encoded", "compressed", "pako", "base64", "decompressed"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/include/lib/reverser.ts"],
4
- "sourcesContent": ["const substitutionPattern: any = {};\r\nconst alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\nfor (let i = 0; i < alphabet.length; i++) {\r\n substitutionPattern[alphabet[i]] = alphabet[(i + 1) % alphabet.length];\r\n substitutionPattern[alphabet[i].toLowerCase()] = alphabet[(i + 1) % alphabet.length].toLowerCase();\r\n}\r\n\r\nlet speacialCharters = '?.,!@#$%^&*()_+-=[]{}|;:<>/';\r\nfor (let i = 0; i < speacialCharters.length; i++) {\r\n substitutionPattern[speacialCharters[i]] = speacialCharters[i];\r\n}\r\n\r\nconst encrypt = (text: string) => text.split('').map((char) => substitutionPattern[char] || char).join('')\r\nconst decrypt = (text: string) => {\r\n return text.split('').map((char) => {\r\n for (let key in substitutionPattern) {\r\n if (substitutionPattern[key] === char) {\r\n return key;\r\n }\r\n }\r\n return char;\r\n }).join('');\r\n}\r\n\r\nexport default {\r\n encrypt,\r\n decrypt\r\n}"],
4
+ "sourcesContent": ["const substitutionPattern: any = {};\nconst alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nfor (let i = 0; i < alphabet.length; i++) {\n substitutionPattern[alphabet[i]] = alphabet[(i + 1) % alphabet.length];\n substitutionPattern[alphabet[i].toLowerCase()] = alphabet[(i + 1) % alphabet.length].toLowerCase();\n}\n\nlet speacialCharters = '?.,!@#$%^&*()_+-=[]{}|;:<>/';\nfor (let i = 0; i < speacialCharters.length; i++) {\n substitutionPattern[speacialCharters[i]] = speacialCharters[i];\n}\n\nconst encrypt = (text: string) => text.split('').map((char) => substitutionPattern[char] || char).join('')\nconst decrypt = (text: string) => {\n return text.split('').map((char) => {\n for (let key in substitutionPattern) {\n if (substitutionPattern[key] === char) {\n return key;\n }\n }\n return char;\n }).join('');\n}\n\nexport default {\n encrypt,\n decrypt\n}"],
5
5
  "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,MAAMI,EAA2B,CAAC,EAC5BC,EAAW,6BACjB,QAASC,EAAI,EAAGA,EAAID,EAAS,OAAQC,IAClCF,EAAoBC,EAASC,CAAC,CAAC,EAAID,GAAUC,EAAI,GAAKD,EAAS,MAAM,EACrED,EAAoBC,EAASC,CAAC,EAAE,YAAY,CAAC,EAAID,GAAUC,EAAI,GAAKD,EAAS,MAAM,EAAE,YAAY,EAGpG,IAAIE,EAAmB,8BACvB,QAASD,EAAI,EAAGA,EAAIC,EAAiB,OAAQD,IAC1CF,EAAoBG,EAAiBD,CAAC,CAAC,EAAIC,EAAiBD,CAAC,EAGhE,MAAME,EAAWC,GAAiBA,EAAK,MAAM,EAAE,EAAE,IAAKC,GAASN,EAAoBM,CAAI,GAAKA,CAAI,EAAE,KAAK,EAAE,EACnGC,EAAWF,GACPA,EAAK,MAAM,EAAE,EAAE,IAAKC,GAAS,CACjC,QAASE,KAAOR,EACb,GAAIA,EAAoBQ,CAAG,IAAMF,EAC9B,OAAOE,EAGb,OAAOF,CACV,CAAC,EAAE,KAAK,EAAE,EAGb,IAAOR,EAAQ,CACZ,QAAAM,EACA,QAAAG,CACH",
6
6
  "names": ["reverser_exports", "__export", "reverser_default", "__toCommonJS", "substitutionPattern", "alphabet", "i", "speacialCharters", "encrypt", "text", "char", "decrypt", "key"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/include/lib/urlpath.ts"],
4
- "sourcesContent": ["import reverser from \"./reverser\"\r\n\r\nfunction encrypt(input: string): string {\r\n return encodeURIComponent(reverser.encrypt(input.toLowerCase()))\r\n}\r\n\r\nfunction decrypt(encryptedString: string): string {\r\n return reverser.decrypt(decodeURIComponent(encryptedString))\r\n}\r\n\r\nexport default {\r\n encrypt,\r\n decrypt\r\n}"],
4
+ "sourcesContent": ["import reverser from \"./reverser\"\n\nfunction encrypt(input: string): string {\n return encodeURIComponent(reverser.encrypt(input.toLowerCase()))\n}\n\nfunction decrypt(encryptedString: string): string {\n return reverser.decrypt(decodeURIComponent(encryptedString))\n}\n\nexport default {\n encrypt,\n decrypt\n}"],
5
5
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAqB,yBAErB,SAASC,EAAQC,EAAuB,CACrC,OAAO,mBAAmB,EAAAC,QAAS,QAAQD,EAAM,YAAY,CAAC,CAAC,CAClE,CAEA,SAASE,EAAQC,EAAiC,CAC/C,OAAO,EAAAF,QAAS,QAAQ,mBAAmBE,CAAe,CAAC,CAC9D,CAEA,IAAOP,EAAQ,CACZ,QAAAG,EACA,QAAAG,CACH",
6
6
  "names": ["urlpath_exports", "__export", "urlpath_default", "__toCommonJS", "import_reverser", "encrypt", "input", "reverser", "decrypt", "encryptedString"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/include/responseValue.ts"],
4
- "sourcesContent": ["import crypto from \"./lib/crypto\";\r\n\r\nconst encrypt = (data: any, signerure: string): string => {\r\n return crypto.encrypt(data, crypto.makeSecret(signerure))\r\n}\r\n\r\nconst decrypt = (value: string, signerure: string) => {\r\n return crypto.decrypt(value, crypto.makeSecret(signerure))\r\n}\r\n\r\nexport default {\r\n encrypt,\r\n decrypt\r\n}"],
4
+ "sourcesContent": ["import crypto from \"./lib/crypto\";\n\nconst encrypt = (data: any, signerure: string): string => {\n return crypto.encrypt(data, crypto.makeSecret(signerure))\n}\n\nconst decrypt = (value: string, signerure: string) => {\n return crypto.decrypt(value, crypto.makeSecret(signerure))\n}\n\nexport default {\n encrypt,\n decrypt\n}"],
5
5
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmB,2BAEnB,MAAMC,EAAU,CAACC,EAAWC,IAClB,EAAAC,QAAO,QAAQF,EAAM,EAAAE,QAAO,WAAWD,CAAS,CAAC,EAGrDE,EAAU,CAACC,EAAeH,IACtB,EAAAC,QAAO,QAAQE,EAAO,EAAAF,QAAO,WAAWD,CAAS,CAAC,EAG5D,IAAOL,EAAQ,CACZ,QAAAG,EACA,QAAAI,CACH",
6
6
  "names": ["responseValue_exports", "__export", "responseValue_default", "__toCommonJS", "import_crypto", "encrypt", "data", "signerure", "crypto", "decrypt", "value"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/include/signeture.ts"],
4
- "sourcesContent": ["import crypto from \"./lib/crypto\";\r\n\r\nconst make = (val: string, secret: string) => {\r\n const signeture = crypto.encrypt(val, secret);\r\n const signetureHash = crypto.hash(signeture)\r\n const secretEncript = crypto.encrypt(secret, signetureHash);\r\n return `${signeture}.${secretEncript}`;\r\n}\r\n\r\nconst verify = (signerure: string) => {\r\n const [signeture, secretEncript] = signerure.split(\".\");\r\n const signetureHash = crypto.hash(signeture);\r\n const secret = crypto.decrypt(secretEncript, signetureHash);\r\n const secretVal = crypto.decrypt(signeture, secret);\r\n if (secretVal !== secret) throw new Error(\"Invalid Signeture\");\r\n return secretVal;\r\n}\r\n\r\nexport default {\r\n make,\r\n verify,\r\n key: \"x-signeture\"\r\n}"],
4
+ "sourcesContent": ["import crypto from \"./lib/crypto\";\n\nconst make = (val: string, secret: string) => {\n const signeture = crypto.encrypt(val, secret);\n const signetureHash = crypto.hash(signeture)\n const secretEncript = crypto.encrypt(secret, signetureHash);\n return `${signeture}.${secretEncript}`;\n}\n\nconst verify = (signerure: string) => {\n const [signeture, secretEncript] = signerure.split(\".\");\n const signetureHash = crypto.hash(signeture);\n const secret = crypto.decrypt(secretEncript, signetureHash);\n const secretVal = crypto.decrypt(signeture, secret);\n if (secretVal !== secret) throw new Error(\"Invalid Signeture\");\n return secretVal;\n}\n\nexport default {\n make,\n verify,\n key: \"x-signeture\"\n}"],
5
5
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmB,2BAEnB,MAAMC,EAAO,CAACC,EAAaC,IAAmB,CAC3C,MAAMC,EAAY,EAAAC,QAAO,QAAQH,EAAKC,CAAM,EACtCG,EAAgB,EAAAD,QAAO,KAAKD,CAAS,EACrCG,EAAgB,EAAAF,QAAO,QAAQF,EAAQG,CAAa,EAC1D,MAAO,GAAGF,CAAS,IAAIG,CAAa,EACvC,EAEMC,EAAUC,GAAsB,CACnC,KAAM,CAACL,EAAWG,CAAa,EAAIE,EAAU,MAAM,GAAG,EAChDH,EAAgB,EAAAD,QAAO,KAAKD,CAAS,EACrCD,EAAS,EAAAE,QAAO,QAAQE,EAAeD,CAAa,EACpDI,EAAY,EAAAL,QAAO,QAAQD,EAAWD,CAAM,EAClD,GAAIO,IAAcP,EAAQ,MAAM,IAAI,MAAM,mBAAmB,EAC7D,OAAOO,CACV,EAEA,IAAOZ,EAAQ,CACZ,KAAAG,EACA,OAAAO,EACA,IAAK,aACR",
6
6
  "names": ["signeture_exports", "__export", "signeture_default", "__toCommonJS", "import_crypto", "make", "val", "secret", "signeture", "crypto", "signetureHash", "secretEncript", "verify", "signerure", "secretVal"]
7
7
  }
package/cjs/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export { default as SecurequServer } from './server';\r\nexport { default as SecurequClient } from './client';\r\n"],
4
+ "sourcesContent": ["export { default as SecurequServer } from './server';\nexport { default as SecurequClient } from './client';\n"],
5
5
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4EAAAE,EAAAF,GAAA,IAAAG,EAA0C,uBAC1CC,EAA0C",
6
6
  "names": ["index_exports", "__export", "__toCommonJS", "import_server", "import_client"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/server/index.ts"],
4
- "sourcesContent": ["import { match } from \"path-to-regexp\";\r\nimport crypto from \"../include/lib/crypto\";\r\nimport reverser from \"../include/lib/reverser\";\r\nimport responseValue from \"../include/responseValue\";\r\nimport signeture from \"../include/signeture\";\r\nimport { HandlerFunction, HandlerInfo, HTTPMethods, ListenerInfo, RouteFactory, ServerResponse, SecurequServerConfig } from \"./types\";\r\nimport SecurequCache from \"../include/lib/cache\";\r\n\r\n\r\nclass SecurequServer {\r\n private HandlerCache = new SecurequCache<HandlerFunction>({ ttl: 1000 * 60 * 60, limit: 100 });\r\n private routes: RouteFactory = {\r\n GET: {},\r\n POST: {},\r\n PUT: {},\r\n DELETE: {}\r\n };\r\n private config: SecurequServerConfig;\r\n private secret: string = crypto.makeSecret(Math.random().toString(36).substring(7));\r\n\r\n constructor(config: SecurequServerConfig) {\r\n this.config = { ...config }\r\n }\r\n\r\n async addRoute(path: string, method: HTTPMethods, handler: HandlerFunction) {\r\n if (this.routes[method][path]) return\r\n this.routes[method][path] = {\r\n handler,\r\n test: match(path)\r\n }\r\n }\r\n\r\n async get(path: string, handler: HandlerFunction) {\r\n this.addRoute(path, 'GET', handler)\r\n }\r\n\r\n async post(path: string, handler: HandlerFunction) {\r\n this.addRoute(path, 'POST', handler)\r\n }\r\n\r\n async put(path: string, handler: HandlerFunction) {\r\n this.addRoute(path, 'PUT', handler)\r\n }\r\n\r\n async delete(path: string, handler: HandlerFunction) {\r\n this.addRoute(path, 'DELETE', handler)\r\n }\r\n\r\n async handleRequest(info: HandlerInfo, args?: any) {\r\n const { path, method } = info;\r\n let cacheHandler = this.HandlerCache.get(`${method}:${path}`);\r\n if (cacheHandler) {\r\n await cacheHandler(info, args)\r\n return\r\n }\r\n let values: any = Object.values(this.routes[method]);\r\n for (let value of values) {\r\n let { test, handler } = value\r\n const match = test(path)\r\n if (match) {\r\n info.params = match.params;\r\n await handler(info, args)\r\n this.HandlerCache.set(`${method}:${path}`, handler)\r\n }\r\n }\r\n }\r\n\r\n async listen(listenerInfo: ListenerInfo, args?: any): Promise<ServerResponse> {\r\n try {\r\n if (!listenerInfo.signeture || !listenerInfo.path || !listenerInfo.method || !listenerInfo.body) throw new Error(\"Invalid Request\");\r\n\r\n const clientSecret = signeture.verify(listenerInfo.signeture);\r\n const { path, body, method } = listenerInfo;\r\n const url = new URL(path, \"http://localhost\");\r\n\r\n // format the path\r\n url.pathname = url.pathname.replace(this.config.basepath, \"/\")\r\n let split = url.pathname.split(\"/\").map((s) => reverser.decrypt(s)).filter((s) => s.length > 0);\r\n url.pathname = `/${split.join(\"/\")}`;\r\n\r\n // handle handshake \r\n const handshakeSecret = crypto.makeSecret(this.secret + clientSecret);\r\n const reqkey = handshakeSecret.substring(0, handshakeSecret.length / 2);\r\n\r\n if (method === 'GET' && url.pathname === \"/handshake\") {\r\n throw crypto.encrypt(handshakeSecret, clientSecret)\r\n }\r\n\r\n let data: any = {}, searchParams: any = {}\r\n\r\n if (url.searchParams.has(reqkey)) {\r\n let decripted: any = crypto.decrypt(url.searchParams.get(reqkey) as string, handshakeSecret)\r\n for (let key in decripted) {\r\n let ukey = reverser.decrypt(key)\r\n searchParams[ukey] = decripted[key]\r\n }\r\n }\r\n\r\n if (body[reqkey]) {\r\n let decripted: any = crypto.decrypt(body[reqkey], handshakeSecret)\r\n for (let key in decripted) {\r\n let ukey = reverser.decrypt(key)\r\n data[ukey] = decripted[key]\r\n }\r\n }\r\n\r\n // handle the request\r\n await this.handleRequest({\r\n method,\r\n path: url.pathname,\r\n body: data,\r\n searchParams,\r\n params: {}\r\n }, args);\r\n } catch (info: any) {\r\n if (info instanceof Error) {\r\n return {\r\n status: 404,\r\n value: responseValue.encrypt(info.message, listenerInfo.signeture)\r\n }\r\n } else if (info instanceof Response) {\r\n let text = await info.text();\r\n return {\r\n status: info.status,\r\n value: responseValue.encrypt(text, listenerInfo.signeture)\r\n }\r\n }\r\n return {\r\n status: 200,\r\n value: responseValue.encrypt(info, listenerInfo.signeture)\r\n };\r\n }\r\n\r\n return {\r\n status: 404,\r\n value: 'Not Found'\r\n };\r\n }\r\n}\r\n\r\nexport default SecurequServer;"],
4
+ "sourcesContent": ["import { match } from \"path-to-regexp\";\nimport crypto from \"../include/lib/crypto\";\nimport reverser from \"../include/lib/reverser\";\nimport responseValue from \"../include/responseValue\";\nimport signeture from \"../include/signeture\";\nimport { HandlerFunction, HandlerInfo, HTTPMethods, ListenerInfo, RouteFactory, ServerResponse, SecurequServerConfig } from \"./types\";\nimport SecurequCache from \"../include/lib/cache\";\n\n\nclass SecurequServer {\n private HandlerCache = new SecurequCache<HandlerFunction>({ ttl: 1000 * 60 * 60, limit: 100 });\n private routes: RouteFactory = {\n GET: {},\n POST: {},\n PUT: {},\n DELETE: {}\n };\n private config: SecurequServerConfig;\n private secret: string = crypto.makeSecret(Math.random().toString(36).substring(7));\n\n constructor(config: SecurequServerConfig) {\n this.config = { ...config }\n }\n\n async addRoute(path: string, method: HTTPMethods, handler: HandlerFunction) {\n if (this.routes[method][path]) return\n this.routes[method][path] = {\n handler,\n test: match(path)\n }\n }\n\n async get(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'GET', handler)\n }\n\n async post(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'POST', handler)\n }\n\n async put(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'PUT', handler)\n }\n\n async delete(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'DELETE', handler)\n }\n\n async handleRequest(info: HandlerInfo, args?: any) {\n const { path, method } = info;\n let cacheHandler = this.HandlerCache.get(`${method}:${path}`);\n if (cacheHandler) {\n await cacheHandler(info, args)\n return\n }\n let values: any = Object.values(this.routes[method]);\n for (let value of values) {\n let { test, handler } = value\n const match = test(path)\n if (match) {\n info.params = match.params;\n await handler(info, args)\n this.HandlerCache.set(`${method}:${path}`, handler)\n }\n }\n }\n\n async listen(listenerInfo: ListenerInfo, args?: any): Promise<ServerResponse> {\n try {\n if (!listenerInfo.signeture || !listenerInfo.path || !listenerInfo.method || !listenerInfo.body) throw new Error(\"Invalid Request\");\n\n const clientSecret = signeture.verify(listenerInfo.signeture);\n const { path, body, method } = listenerInfo;\n const url = new URL(path, \"http://localhost\");\n\n // format the path\n url.pathname = url.pathname.replace(this.config.basepath, \"/\")\n let split = url.pathname.split(\"/\").map((s) => reverser.decrypt(s)).filter((s) => s.length > 0);\n url.pathname = `/${split.join(\"/\")}`;\n\n // handle handshake \n const handshakeSecret = crypto.makeSecret(this.secret + clientSecret);\n const reqkey = handshakeSecret.substring(0, handshakeSecret.length / 2);\n\n if (method === 'GET' && url.pathname === \"/handshake\") {\n throw crypto.encrypt(handshakeSecret, clientSecret)\n }\n\n let data: any = {}, searchParams: any = {}\n\n if (url.searchParams.has(reqkey)) {\n let decripted: any = crypto.decrypt(url.searchParams.get(reqkey) as string, handshakeSecret)\n for (let key in decripted) {\n let ukey = reverser.decrypt(key)\n searchParams[ukey] = decripted[key]\n }\n }\n\n if (body[reqkey]) {\n let decripted: any = crypto.decrypt(body[reqkey], handshakeSecret)\n for (let key in decripted) {\n let ukey = reverser.decrypt(key)\n data[ukey] = decripted[key]\n }\n }\n\n // handle the request\n await this.handleRequest({\n method,\n path: url.pathname,\n body: data,\n searchParams,\n params: {}\n }, args);\n } catch (info: any) {\n if (info instanceof Error) {\n return {\n status: 404,\n value: responseValue.encrypt(info.message, listenerInfo.signeture)\n }\n } else if (info instanceof Response) {\n let text = await info.text();\n return {\n status: info.status,\n value: responseValue.encrypt(text, listenerInfo.signeture)\n }\n }\n return {\n status: 200,\n value: responseValue.encrypt(info, listenerInfo.signeture)\n };\n }\n\n return {\n status: 404,\n value: 'Not Found'\n };\n }\n}\n\nexport default SecurequServer;"],
5
5
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsB,0BACtBC,EAAmB,oCACnBC,EAAqB,sCACrBC,EAA0B,uCAC1BC,EAAsB,mCAEtBC,EAA0B,mCAG1B,MAAMC,CAAe,CAWlB,YAAYC,EAA8B,CAV1C,KAAQ,aAAe,IAAI,EAAAC,QAA+B,CAAE,IAAK,IAAO,GAAK,GAAI,MAAO,GAAI,CAAC,EAC7F,KAAQ,OAAuB,CAC5B,IAAK,CAAC,EACN,KAAM,CAAC,EACP,IAAK,CAAC,EACN,OAAQ,CAAC,CACZ,EAEA,KAAQ,OAAiB,EAAAC,QAAO,WAAW,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC,CAA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AI,CACV,OAASD,EAAW,CACjB,GAAIA,aAAgB,MACjB,MAAO,CACJ,OAAQ,IACR,MAAO,EAAAsB,QAAc,QAAQtB,EAAK,QAASO,EAAa,SAAS,CACpE,EACI,GAAIP,aAAgB,SAAU,CAClC,IAAIuB,EAAO,MAAMvB,EAAK,KAAK,EAC3B,MAAO,CACJ,OAAQA,EAAK,OACb,MAAO,EAAAsB,QAAc,QAAQC,EAAMhB,EAAa,SAAS,CAC5D,CACH,CACA,MAAO,CACJ,OAAQ,IACR,MAAO,EAAAe,QAAc,QAAQtB,EAAMO,EAAa,SAAS,CAC5D,CACH,CAEA,MAAO,CACJ,OAAQ,IACR,MAAO,WACV,CACH,CACH,CAEA,IAAOtB,EAAQQ",
6
6
  "names": ["server_exports", "__export", "server_default", "__toCommonJS", "import_path_to_regexp", "import_crypto", "import_reverser", "import_responseValue", "import_signeture", "import_cache", "SecurequServer", "config", "SecurequCache", "crypto", "path", "method", "handler", "info", "args", "cacheHandler", "values", "value", "test", "match", "listenerInfo", "clientSecret", "signeture", "body", "url", "split", "s", "reverser", "handshakeSecret", "reqkey", "data", "searchParams", "decripted", "key", "ukey", "responseValue", "text"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/server/types.ts"],
4
- "sourcesContent": ["import { MatchFunction } from \"path-to-regexp\";\r\n\r\nexport type SecurequServerConfig = {\r\n basepath: string;\r\n cache?: boolean | {\r\n get: (key: string) => any;\r\n set: (key: string, response: Response) => void;\r\n };\r\n}\r\n\r\nexport type HTTPMethods = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\";\r\n\r\nexport type ListenerInfo = {\r\n signeture: string;\r\n path: string;\r\n body: any;\r\n method: HTTPMethods;\r\n}\r\n\r\n\r\nexport type HandlerInfo = {\r\n path: string;\r\n body: object;\r\n searchParams: Object;\r\n params: Object;\r\n method: HTTPMethods;\r\n}\r\n\r\n\r\nexport type ServerResponse = {\r\n value: string;\r\n status: number;\r\n}\r\n\r\nexport type HandlerFunction = (info: HandlerInfo, args?: any) => (any | void) | Promise<Partial<any> | void>;\r\n\r\nexport type RouteFactory = {\r\n [key in HTTPMethods]: {\r\n [path: string]: {\r\n handler: HandlerFunction;\r\n test: MatchFunction<{ [key: string]: string }>;\r\n }\r\n }\r\n}"],
4
+ "sourcesContent": ["import { MatchFunction } from \"path-to-regexp\";\n\nexport type SecurequServerConfig = {\n basepath: string;\n cache?: boolean | {\n get: (key: string) => any;\n set: (key: string, response: Response) => void;\n };\n}\n\nexport type HTTPMethods = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\";\n\nexport type ListenerInfo = {\n signeture: string;\n path: string;\n body: any;\n method: HTTPMethods;\n}\n\n\nexport type HandlerInfo = {\n path: string;\n body: object;\n searchParams: Object;\n params: Object;\n method: HTTPMethods;\n}\n\n\nexport type ServerResponse = {\n value: string;\n status: number;\n}\n\nexport type HandlerFunction = (info: HandlerInfo, args?: any) => (any | void) | Promise<Partial<any> | void>;\n\nexport type RouteFactory = {\n [key in HTTPMethods]: {\n [path: string]: {\n handler: HandlerFunction;\n test: MatchFunction<{ [key: string]: string }>;\n }\n }\n}"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["types_exports", "__toCommonJS"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/client/index.ts"],
4
- "sourcesContent": ["import crypto from \"../include/lib/crypto\";\r\nimport signeture from \"../include/signeture\";\r\nimport urlpath from \"../include/lib/urlpath\";\r\nimport { HttpRequestInit, RequestBody, SecurequClientConfig } from \"./types\";\r\nimport xanFetch from 'xanFetch'\r\nimport responseValue from \"../include/responseValue\";\r\nimport SecurequCache from \"../include/lib/cache\";\r\n\r\nclass SecurequClient {\r\n private config: SecurequClientConfig;\r\n private token: string = '';\r\n private tokenLoading: boolean = false;\r\n private Cache = new SecurequCache<Response>({ ttl: 1000 * 60 * 60, limit: 100 });\r\n\r\n private secret: string;\r\n private secret_length: number;\r\n private signerure: string;\r\n private reqkey: string = '';\r\n\r\n constructor(config: SecurequClientConfig) {\r\n this.config = { ...config }\r\n const secret = crypto.makeSecret(config.secret)\r\n this.config.secret = secret;\r\n this.secret_length = secret.length - (Math.floor(Math.random() * 11) + 5);\r\n this.secret = crypto.makeSecret(secret.substring(0, this.secret_length))\r\n this.signerure = signeture.make(this.secret, this.secret);\r\n }\r\n\r\n private setCache(path: string, method: string, response: any) {\r\n const cacheKey = `${method}:${path}`;\r\n if (this.config.cache === true) {\r\n this.Cache.set(cacheKey, response);\r\n } else if (this.config.cache) {\r\n this.config.cache.set(cacheKey, response);\r\n }\r\n }\r\n\r\n private getCache(path: string, method: string,) {\r\n const cacheKey = `${method}:${path}`;\r\n if (this.config.cache === true) {\r\n return this.Cache.get(cacheKey);\r\n } else if (this.config.cache) {\r\n return this.config.cache.get(cacheKey);\r\n }\r\n }\r\n\r\n private PATH_CACHE = new SecurequCache<string>({ ttl: 1000 * 60 * 60, limit: 100 });\r\n private path(path: string) {\r\n let pathKey = path\r\n let has = this.PATH_CACHE.get(pathKey)\r\n if (!has) {\r\n const { search, pathname } = new URL(path, window.location.origin);\r\n const params = new URLSearchParams(search);\r\n const paramsObject = Object.fromEntries(params.entries());\r\n let split = pathname.split(\"/\").map((s) => urlpath.encrypt(s)).filter((s) => s.length > 0);\r\n path = `${this.config.path}/${split.join(\"/\")}`;\r\n if (Object.keys(paramsObject).length) {\r\n for (let key in paramsObject) {\r\n paramsObject[urlpath.encrypt(key)] = paramsObject[key]\r\n delete paramsObject[key]\r\n }\r\n const string = JSON.stringify(paramsObject)\r\n const text = encodeURIComponent(crypto.encrypt(string, this.token));\r\n path += `?${this.reqkey}=${text}`;\r\n }\r\n this.PATH_CACHE.set(pathKey, path);\r\n } else {\r\n path = has\r\n }\r\n return path\r\n }\r\n\r\n private async handshake() {\r\n this.tokenLoading = true;\r\n const res = await xanFetch(this.path(`/handshake`), {\r\n method: \"GET\",\r\n headers: {\r\n ...this.config.headers,\r\n [signeture.key]: this.signerure\r\n },\r\n })\r\n\r\n const value: any = responseValue.decrypt(await res.text(), this.signerure)\r\n const token = crypto.decrypt(value, this.secret)\r\n this.token = token;\r\n this.reqkey = token.substring(0, token.length / 2);\r\n this.tokenLoading = false;\r\n }\r\n\r\n async send(path: string, init?: HttpRequestInit): Promise<Response> {\r\n if (path === '/handshake') {\r\n throw new Error(\"Path is not allowed\")\r\n }\r\n if (this.tokenLoading) {\r\n await new Promise((resolve) => {\r\n const interval = setInterval(() => {\r\n if (!this.tokenLoading) {\r\n clearInterval(interval);\r\n resolve(null);\r\n }\r\n }, 100);\r\n })\r\n }\r\n\r\n if (!this.token) {\r\n await this.handshake();\r\n }\r\n\r\n const info: any = {\r\n method: \"GET\",\r\n ...init,\r\n headers: {\r\n ...this.config.headers,\r\n ...init?.headers,\r\n [signeture.key]: this.signerure\r\n },\r\n }\r\n\r\n const cache_res = this.getCache(path, info.method);\r\n if (cache_res) {\r\n return cache_res.clone();\r\n }\r\n\r\n if (info.body) {\r\n if (!this.token) throw new Error(\"Token not loaded\")\r\n const body = new FormData();\r\n let _data: any = {}\r\n let hasFile = false;\r\n for (let key in info.body) {\r\n let ukey = urlpath.encrypt(key);\r\n if (info.body[key] instanceof File) {\r\n body.append(ukey, info.body[key]);\r\n hasFile = true;\r\n } else {\r\n _data[ukey] = info.body[key];\r\n }\r\n }\r\n\r\n body.append(this.reqkey, crypto.encrypt(_data, this.token));\r\n\r\n if (!hasFile) {\r\n info.body = new URLSearchParams(body as any);\r\n if (!info.headers['Content-Type']) {\r\n info.headers['Content-Type'] = 'application/x-www-form-urlencoded';\r\n }\r\n } else {\r\n if (info.method === \"GET\") {\r\n info.method = \"POST\"\r\n }\r\n info.body = body\r\n if (!info.headers['Content-Type']) {\r\n info.headers['Content-Type'] = 'multipart/form-data';\r\n }\r\n }\r\n }\r\n\r\n const response = await xanFetch(this.path(path), info);\r\n const res = response.clone();\r\n const text = await response.text();\r\n const value: any = responseValue.decrypt(text, this.signerure)\r\n res.text = async () => value;\r\n if (this.config.cache === true && res.ok) {\r\n this.setCache(path, info.method, res.clone());\r\n }\r\n return res\r\n }\r\n\r\n async get(path: string, init?: HttpRequestInit) {\r\n return await this.send(path, init);\r\n }\r\n\r\n async post(path: string, body: RequestBody, init?: HttpRequestInit) {\r\n return await this.send(path, {\r\n ...init,\r\n method: \"POST\",\r\n body: body\r\n });\r\n }\r\n\r\n async put(path: string, body: RequestBody, init?: HttpRequestInit) {\r\n return await this.send(path, {\r\n ...init,\r\n method: \"PUT\",\r\n body: body\r\n });\r\n }\r\n\r\n async delete(path: string, init?: HttpRequestInit) {\r\n return await this.send(path, {\r\n ...init,\r\n method: \"DELETE\",\r\n });\r\n }\r\n}\r\n\r\nexport default SecurequClient"],
4
+ "sourcesContent": ["import crypto from \"../include/lib/crypto\";\nimport signeture from \"../include/signeture\";\nimport urlpath from \"../include/lib/urlpath\";\nimport { HttpRequestInit, RequestBody, SecurequClientConfig } from \"./types\";\nimport xanFetch from 'xanFetch'\nimport responseValue from \"../include/responseValue\";\nimport SecurequCache from \"../include/lib/cache\";\n\nclass SecurequClient {\n private config: SecurequClientConfig;\n private token: string = '';\n private tokenLoading: boolean = false;\n private Cache = new SecurequCache<Response>({ ttl: 1000 * 60 * 60, limit: 100 });\n\n private secret: string;\n private secret_length: number;\n private signerure: string;\n private reqkey: string = '';\n\n constructor(config: SecurequClientConfig) {\n this.config = { ...config }\n const secret = crypto.makeSecret(config.secret)\n this.config.secret = secret;\n this.secret_length = secret.length - (Math.floor(Math.random() * 11) + 5);\n this.secret = crypto.makeSecret(secret.substring(0, this.secret_length))\n this.signerure = signeture.make(this.secret, this.secret);\n }\n\n private setCache(path: string, method: string, response: any) {\n const cacheKey = `${method}:${path}`;\n if (this.config.cache === true) {\n this.Cache.set(cacheKey, response);\n } else if (this.config.cache) {\n this.config.cache.set(cacheKey, response);\n }\n }\n\n private getCache(path: string, method: string,) {\n const cacheKey = `${method}:${path}`;\n if (this.config.cache === true) {\n return this.Cache.get(cacheKey);\n } else if (this.config.cache) {\n return this.config.cache.get(cacheKey);\n }\n }\n\n private PATH_CACHE = new SecurequCache<string>({ ttl: 1000 * 60 * 60, limit: 100 });\n private path(path: string) {\n let pathKey = path\n let has = this.PATH_CACHE.get(pathKey)\n if (!has) {\n const { search, pathname } = new URL(path, window.location.origin);\n const params = new URLSearchParams(search);\n const paramsObject = Object.fromEntries(params.entries());\n let split = pathname.split(\"/\").map((s) => urlpath.encrypt(s)).filter((s) => s.length > 0);\n path = `${this.config.path}/${split.join(\"/\")}`;\n if (Object.keys(paramsObject).length) {\n for (let key in paramsObject) {\n paramsObject[urlpath.encrypt(key)] = paramsObject[key]\n delete paramsObject[key]\n }\n const string = JSON.stringify(paramsObject)\n const text = encodeURIComponent(crypto.encrypt(string, this.token));\n path += `?${this.reqkey}=${text}`;\n }\n this.PATH_CACHE.set(pathKey, path);\n } else {\n path = has\n }\n return path\n }\n\n private async handshake() {\n this.tokenLoading = true;\n const res = await xanFetch(this.path(`/handshake`), {\n method: \"GET\",\n headers: {\n ...this.config.headers,\n [signeture.key]: this.signerure\n },\n })\n\n const value: any = responseValue.decrypt(await res.text(), this.signerure)\n const token = crypto.decrypt(value, this.secret)\n this.token = token;\n this.reqkey = token.substring(0, token.length / 2);\n this.tokenLoading = false;\n }\n\n async send(path: string, init?: HttpRequestInit): Promise<Response> {\n if (path === '/handshake') {\n throw new Error(\"Path is not allowed\")\n }\n if (this.tokenLoading) {\n await new Promise((resolve) => {\n const interval = setInterval(() => {\n if (!this.tokenLoading) {\n clearInterval(interval);\n resolve(null);\n }\n }, 100);\n })\n }\n\n if (!this.token) {\n await this.handshake();\n }\n\n const info: any = {\n method: \"GET\",\n ...init,\n headers: {\n ...this.config.headers,\n ...init?.headers,\n [signeture.key]: this.signerure\n },\n }\n\n const cache_res = this.getCache(path, info.method);\n if (cache_res) {\n return cache_res.clone();\n }\n\n if (info.body) {\n if (!this.token) throw new Error(\"Token not loaded\")\n const body = new FormData();\n let _data: any = {}\n let hasFile = false;\n for (let key in info.body) {\n let ukey = urlpath.encrypt(key);\n if (info.body[key] instanceof File) {\n body.append(ukey, info.body[key]);\n hasFile = true;\n } else {\n _data[ukey] = info.body[key];\n }\n }\n\n body.append(this.reqkey, crypto.encrypt(_data, this.token));\n\n if (!hasFile) {\n info.body = new URLSearchParams(body as any);\n if (!info.headers['Content-Type']) {\n info.headers['Content-Type'] = 'application/x-www-form-urlencoded';\n }\n } else {\n if (info.method === \"GET\") {\n info.method = \"POST\"\n }\n info.body = body\n if (!info.headers['Content-Type']) {\n info.headers['Content-Type'] = 'multipart/form-data';\n }\n }\n }\n\n const response = await xanFetch(this.path(path), info);\n const res = response.clone();\n const text = await response.text();\n const value: any = responseValue.decrypt(text, this.signerure)\n res.text = async () => value;\n if (this.config.cache === true && res.ok) {\n this.setCache(path, info.method, res.clone());\n }\n return res\n }\n\n async get(path: string, init?: HttpRequestInit) {\n return await this.send(path, init);\n }\n\n async post(path: string, body: RequestBody, init?: HttpRequestInit) {\n return await this.send(path, {\n ...init,\n method: \"POST\",\n body: body\n });\n }\n\n async put(path: string, body: RequestBody, init?: HttpRequestInit) {\n return await this.send(path, {\n ...init,\n method: \"PUT\",\n body: body\n });\n }\n\n async delete(path: string, init?: HttpRequestInit) {\n return await this.send(path, {\n ...init,\n method: \"DELETE\",\n });\n }\n}\n\nexport default SecurequClient"],
5
5
  "mappings": "AAAA,OAAOA,MAAY,wBACnB,OAAOC,MAAe,uBACtB,OAAOC,MAAa,yBAEpB,OAAOC,MAAc,WACrB,OAAOC,MAAmB,2BAC1B,OAAOC,MAAmB,uBAE1B,MAAMC,CAAe,CAWlB,YAAYC,EAA8B,CAT1C,KAAQ,MAAgB,GACxB,KAAQ,aAAwB,GAChC,KAAQ,MAAQ,IAAIF,EAAwB,CAAE,IAAK,IAAO,GAAK,GAAI,MAAO,GAAI,CAAC,EAK/E,KAAQ,OAAiB,GA6BzB,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KlB,EAAcuB,EAAmBL,EAAwB,CACjE,OAAO,MAAM,KAAK,KAAKlB,EAAM,CAC1B,GAAGkB,EACH,OAAQ,OACR,KAAMK,CACT,CAAC,CACJ,CAEA,MAAM,IAAIvB,EAAcuB,EAAmBL,EAAwB,CAChE,OAAO,MAAM,KAAK,KAAKlB,EAAM,CAC1B,GAAGkB,EACH,OAAQ,MACR,KAAMK,CACT,CAAC,CACJ,CAEA,MAAM,OAAOvB,EAAckB,EAAwB,CAChD,OAAO,MAAM,KAAK,KAAKlB,EAAM,CAC1B,GAAGkB,EACH,OAAQ,QACX,CAAC,CACJ,CACH,CAEA,IAAOS,EAAQ9B",
6
6
  "names": ["crypto", "signeture", "urlpath", "xanFetch", "responseValue", "SecurequCache", "SecurequClient", "config", "secret", "path", "method", "response", "cacheKey", "pathKey", "has", "search", "pathname", "params", "paramsObject", "split", "s", "key", "string", "text", "res", "value", "token", "init", "resolve", "interval", "info", "cache_res", "body", "_data", "hasFile", "ukey", "client_default"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/include/lib/base64.ts"],
4
- "sourcesContent": ["/**\r\n * Encodes a Uint8Array to Base64 (for browser or Node.js).\r\n * @param data - The Uint8Array data to encode.\r\n * @returns The Base64-encoded string.\r\n */\r\nfunction encode(data: Uint8Array): string {\r\n let base64 = \"\";\r\n if (typeof window !== \"undefined\") {\r\n base64 = btoa(String.fromCharCode(...Array.from(data)));\r\n } else {\r\n base64 = Buffer.from(data).toString(\"base64\");\r\n }\r\n let paddingCount = (base64.match(/=+$/) || [''])[0].length;\r\n if (paddingCount > 0) {\r\n base64 = base64.replace(/=+$/, () => `$${paddingCount}`);\r\n }\r\n return base64\r\n}\r\n\r\n/**\r\n * Decodes a Base64 string to a Uint8Array (for browser or Node.js).\r\n * @param base64String - The Base64 string to decode.\r\n * @returns The decoded Uint8Array.\r\n */\r\nfunction decode(base64: string): Uint8Array {\r\n try {\r\n base64 = base64.replace(/\\$(\\d)/, (_match, count) => '='.repeat(parseInt(count)));\r\n if (typeof window !== \"undefined\") {\r\n const binaryString = atob(base64);\r\n const byteArray = new Uint8Array(binaryString.length);\r\n for (let i = 0; i < binaryString.length; i++) {\r\n byteArray[i] = binaryString.charCodeAt(i);\r\n }\r\n return byteArray;\r\n } else {\r\n return Uint8Array.from(Buffer.from(base64, \"base64\"));\r\n }\r\n } catch (error) {\r\n throw new Error(\"Invalid Base64 string.\");\r\n }\r\n}\r\n\r\nconst base64 = {\r\n encode,\r\n decode\r\n}\r\n\r\nexport default base64;"],
4
+ "sourcesContent": ["/**\n * Encodes a Uint8Array to Base64 (for browser or Node.js).\n * @param data - The Uint8Array data to encode.\n * @returns The Base64-encoded string.\n */\nfunction encode(data: Uint8Array): string {\n let base64 = \"\";\n if (typeof window !== \"undefined\") {\n base64 = btoa(String.fromCharCode(...Array.from(data)));\n } else {\n base64 = Buffer.from(data).toString(\"base64\");\n }\n let paddingCount = (base64.match(/=+$/) || [''])[0].length;\n if (paddingCount > 0) {\n base64 = base64.replace(/=+$/, () => `$${paddingCount}`);\n }\n return base64\n}\n\n/**\n * Decodes a Base64 string to a Uint8Array (for browser or Node.js).\n * @param base64String - The Base64 string to decode.\n * @returns The decoded Uint8Array.\n */\nfunction decode(base64: string): Uint8Array {\n try {\n base64 = base64.replace(/\\$(\\d)/, (_match, count) => '='.repeat(parseInt(count)));\n if (typeof window !== \"undefined\") {\n const binaryString = atob(base64);\n const byteArray = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n byteArray[i] = binaryString.charCodeAt(i);\n }\n return byteArray;\n } else {\n return Uint8Array.from(Buffer.from(base64, \"base64\"));\n }\n } catch (error) {\n throw new Error(\"Invalid Base64 string.\");\n }\n}\n\nconst base64 = {\n encode,\n decode\n}\n\nexport default base64;"],
5
5
  "mappings": "AAKA,SAASA,EAAOC,EAA0B,CACvC,IAAIC,EAAS,GACT,OAAO,OAAW,IACnBA,EAAS,KAAK,OAAO,aAAa,GAAG,MAAM,KAAKD,CAAI,CAAC,CAAC,EAEtDC,EAAS,OAAO,KAAKD,CAAI,EAAE,SAAS,QAAQ,EAE/C,IAAIE,GAAgBD,EAAO,MAAM,KAAK,GAAK,CAAC,EAAE,GAAG,CAAC,EAAE,OACpD,OAAIC,EAAe,IAChBD,EAASA,EAAO,QAAQ,MAAO,IAAM,IAAIC,CAAY,EAAE,GAEnDD,CACV,CAOA,SAASE,EAAOF,EAA4B,CACzC,GAAI,CAED,GADAA,EAASA,EAAO,QAAQ,SAAU,CAACG,EAAQC,IAAU,IAAI,OAAO,SAASA,CAAK,CAAC,CAAC,EAC5E,OAAO,OAAW,IAAa,CAChC,MAAMC,EAAe,KAAKL,CAAM,EAC1BM,EAAY,IAAI,WAAWD,EAAa,MAAM,EACpD,QAASE,EAAI,EAAGA,EAAIF,EAAa,OAAQE,IACtCD,EAAUC,CAAC,EAAIF,EAAa,WAAWE,CAAC,EAE3C,OAAOD,CACV,KACG,QAAO,WAAW,KAAK,OAAO,KAAKN,EAAQ,QAAQ,CAAC,CAE1D,MAAgB,CACb,MAAM,IAAI,MAAM,wBAAwB,CAC3C,CACH,CAEA,MAAMA,EAAS,CACZ,OAAAF,EACA,OAAAI,CACH,EAEA,IAAOM,EAAQR",
6
6
  "names": ["encode", "data", "base64", "paddingCount", "decode", "_match", "count", "binaryString", "byteArray", "i", "base64_default"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/include/lib/cache.ts"],
4
- "sourcesContent": ["class SecurequCache<T> {\r\n private store: Map<string, { value: T; timeout: NodeJS.Timeout; expiresAt: number }>;\r\n private defaultTTL: number; // Global TTL for all cache entries\r\n private limit: number; // Limit on the number of cache entries\r\n\r\n constructor(config: { ttl: number; limit: number }) {\r\n this.store = new Map();\r\n this.defaultTTL = config.ttl;\r\n this.limit = config.limit;\r\n }\r\n\r\n /**\r\n * Set a value in the cache with a global TTL\r\n * @param key - Cache key\r\n * @param value - Cache value\r\n */\r\n set(key: string, value: T): void {\r\n // If the cache exceeds the limit, remove the oldest (least recently used) item\r\n if (this.store.size >= this.limit) {\r\n const firstKey: any = this.store.keys().next().value;\r\n this.store.delete(firstKey);\r\n }\r\n\r\n // If the key already exists, remove the old timeout\r\n if (this.store.has(key)) {\r\n clearTimeout(this.store.get(key)!.timeout);\r\n }\r\n\r\n // Set the new expiration timeout\r\n const timeout = setTimeout(() => {\r\n this.store.delete(key); // Delete expired cache entry\r\n }, this.defaultTTL);\r\n\r\n // Store the value and its expiration info\r\n this.store.set(key, { value, timeout, expiresAt: Date.now() + this.defaultTTL });\r\n }\r\n\r\n /**\r\n * Get a value from the cache and auto-renew the TTL if not expired\r\n * @param key - Cache key\r\n * @returns The cached value or null if expired\r\n */\r\n get(key: string): T | null {\r\n const entry = this.store.get(key);\r\n\r\n if (!entry) {\r\n return null; // No data found in cache\r\n }\r\n\r\n // Check if the cache has expired\r\n if (Date.now() > entry.expiresAt) {\r\n this.store.delete(key); // Automatically delete expired cache entry\r\n return null;\r\n }\r\n\r\n this.set(key, entry.value);\r\n return entry.value;\r\n }\r\n\r\n /**\r\n * Delete a key from the cache\r\n * @param key - Cache key\r\n */\r\n delete(key: string): void {\r\n const entry = this.store.get(key);\r\n if (entry) {\r\n clearTimeout(entry.timeout); // Clear the timeout\r\n this.store.delete(key); // Delete from cache\r\n }\r\n }\r\n\r\n /**\r\n * Clear the entire cache\r\n */\r\n clear(): void {\r\n this.store.forEach((entry) => clearTimeout(entry.timeout)); // Clear all timeouts\r\n this.store.clear(); // Clear the store\r\n }\r\n\r\n /**\r\n * Get the current size of the cache\r\n * @returns The number of items in the cache\r\n */\r\n size(): number {\r\n return this.store.size;\r\n }\r\n}\r\n\r\n\r\nexport default SecurequCache"],
4
+ "sourcesContent": ["class SecurequCache<T> {\n private store: Map<string, { value: T; timeout: NodeJS.Timeout; expiresAt: number }>;\n private defaultTTL: number; // Global TTL for all cache entries\n private limit: number; // Limit on the number of cache entries\n\n constructor(config: { ttl: number; limit: number }) {\n this.store = new Map();\n this.defaultTTL = config.ttl;\n this.limit = config.limit;\n }\n\n /**\n * Set a value in the cache with a global TTL\n * @param key - Cache key\n * @param value - Cache value\n */\n set(key: string, value: T): void {\n // If the cache exceeds the limit, remove the oldest (least recently used) item\n if (this.store.size >= this.limit) {\n const firstKey: any = this.store.keys().next().value;\n this.store.delete(firstKey);\n }\n\n // If the key already exists, remove the old timeout\n if (this.store.has(key)) {\n clearTimeout(this.store.get(key)!.timeout);\n }\n\n // Set the new expiration timeout\n const timeout = setTimeout(() => {\n this.store.delete(key); // Delete expired cache entry\n }, this.defaultTTL);\n\n // Store the value and its expiration info\n this.store.set(key, { value, timeout, expiresAt: Date.now() + this.defaultTTL });\n }\n\n /**\n * Get a value from the cache and auto-renew the TTL if not expired\n * @param key - Cache key\n * @returns The cached value or null if expired\n */\n get(key: string): T | null {\n const entry = this.store.get(key);\n\n if (!entry) {\n return null; // No data found in cache\n }\n\n // Check if the cache has expired\n if (Date.now() > entry.expiresAt) {\n this.store.delete(key); // Automatically delete expired cache entry\n return null;\n }\n\n this.set(key, entry.value);\n return entry.value;\n }\n\n /**\n * Delete a key from the cache\n * @param key - Cache key\n */\n delete(key: string): void {\n const entry = this.store.get(key);\n if (entry) {\n clearTimeout(entry.timeout); // Clear the timeout\n this.store.delete(key); // Delete from cache\n }\n }\n\n /**\n * Clear the entire cache\n */\n clear(): void {\n this.store.forEach((entry) => clearTimeout(entry.timeout)); // Clear all timeouts\n this.store.clear(); // Clear the store\n }\n\n /**\n * Get the current size of the cache\n * @returns The number of items in the cache\n */\n size(): number {\n return this.store.size;\n }\n}\n\n\nexport default SecurequCache"],
5
5
  "mappings": "AAAA,MAAMA,CAAiB,CAKpB,YAAYC,EAAwC,CACjD,KAAK,MAAQ,IAAI,IACjB,KAAK,WAAaA,EAAO,IACzB,KAAK,MAAQA,EAAO,KACvB,CAOA,IAAIC,EAAaC,EAAgB,CAE9B,GAAI,KAAK,MAAM,MAAQ,KAAK,MAAO,CAChC,MAAMC,EAAgB,KAAK,MAAM,KAAK,EAAE,KAAK,EAAE,MAC/C,KAAK,MAAM,OAAOA,CAAQ,CAC7B,CAGI,KAAK,MAAM,IAAIF,CAAG,GACnB,aAAa,KAAK,MAAM,IAAIA,CAAG,EAAG,OAAO,EAI5C,MAAMG,EAAU,WAAW,IAAM,CAC9B,KAAK,MAAM,OAAOH,CAAG,CACxB,EAAG,KAAK,UAAU,EAGlB,KAAK,MAAM,IAAIA,EAAK,CAAE,MAAAC,EAAO,QAAAE,EAAS,UAAW,KAAK,IAAI,EAAI,KAAK,UAAW,CAAC,CAClF,CAOA,IAAIH,EAAuB,CACxB,MAAMI,EAAQ,KAAK,MAAM,IAAIJ,CAAG,EAEhC,OAAKI,EAKD,KAAK,IAAI,EAAIA,EAAM,WACpB,KAAK,MAAM,OAAOJ,CAAG,EACd,OAGV,KAAK,IAAIA,EAAKI,EAAM,KAAK,EAClBA,EAAM,OAVH,IAWb,CAMA,OAAOJ,EAAmB,CACvB,MAAMI,EAAQ,KAAK,MAAM,IAAIJ,CAAG,EAC5BI,IACD,aAAaA,EAAM,OAAO,EAC1B,KAAK,MAAM,OAAOJ,CAAG,EAE3B,CAKA,OAAc,CACX,KAAK,MAAM,QAASI,GAAU,aAAaA,EAAM,OAAO,CAAC,EACzD,KAAK,MAAM,MAAM,CACpB,CAMA,MAAe,CACZ,OAAO,KAAK,MAAM,IACrB,CACH,CAGA,IAAOC,EAAQP",
6
6
  "names": ["SecurequCache", "config", "key", "value", "firstKey", "timeout", "entry", "cache_default"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/include/lib/crypto.ts"],
4
- "sourcesContent": ["import nacl from \"tweetnacl\";\r\nimport base64 from \"./base64\";\r\nimport pako from \"./pako\";\r\n\r\n/**\r\n * Encrypts data using TweetNaCl, compresses it with Pako (Gzip), and encodes it in Base64.\r\n * @param data - The plaintext data to encrypt.\r\n * @param secret - The secret key as a string.\r\n * @returns A Base64 encoded string (nonce + compressed ciphertext).\r\n */\r\nfunction encrypt(data: string | object, secret: string): string {\r\n data = typeof data === \"object\" ? JSON.stringify(data) : data\r\n secret = hash(secret).substring(0, 32)\r\n const key = new TextEncoder().encode(secret);\r\n const nonce = nacl.randomBytes(nacl.secretbox.nonceLength);\r\n const compressed = pako.compress(data, true) as Uint8Array // Ensure it returns Uint8Array\r\n const encrypted = nacl.secretbox(compressed, nonce, key);\r\n return base64.encode(new Uint8Array([...nonce, ...encrypted]));\r\n}\r\n\r\n/**\r\n * Decrypts a Base64-encoded NaCl-encrypted data, decompresses it with Pako (Gzip).\r\n * @param data - The Base64 encoded string (nonce + compressed ciphertext).\r\n * @param secret - The secret key as a string.\r\n * @returns The decrypted plaintext string.\r\n */\r\nfunction decrypt(data: string, secret: string): string {\r\n try {\r\n secret = hash(secret).substring(0, 32)\r\n const key = new TextEncoder().encode(secret);\r\n const encryptedBytes = base64.decode(data);\r\n const nonce = encryptedBytes.slice(0, nacl.secretbox.nonceLength);\r\n const ciphertext = encryptedBytes.slice(nacl.secretbox.nonceLength);\r\n const decrypted = nacl.secretbox.open(ciphertext, nonce, key);\r\n if (!decrypted) throw new Error(\"Decryption failed!\");\r\n const decompressed = pako.decompress(decrypted); // Decompress as string\r\n try {\r\n return JSON.parse(decompressed);\r\n } catch (error) {\r\n return decompressed;\r\n }\r\n } catch (error) {\r\n throw new Error(\"Invalid encrypted data.\");\r\n }\r\n}\r\n\r\n/**\r\n * Hashes a string using NaCl's hash function.\r\n * @param data - The input string to hash.\r\n * @returns The hash of the input string.\r\n */\r\nlet hashed = new Map<string, string>();\r\nfunction hash(data: string): string {\r\n if (hashed.has(data)) return hashed.get(data) as string\r\n const inputBytes = new TextEncoder().encode(data);\r\n const hashedData = nacl.hash(inputBytes);\r\n const d = Array.from(hashedData)\r\n .map(byte => byte.toString(16).padStart(2, '0'))\r\n .join('');\r\n hashed.set(data, d)\r\n return d\r\n}\r\n\r\nconst makeSecret = (secret: string) => {\r\n return hash(secret).substring(0, 32);\r\n}\r\n\r\nconst crypto = {\r\n encrypt,\r\n decrypt,\r\n hash,\r\n makeSecret\r\n};\r\n\r\nexport default crypto;\r\n"],
4
+ "sourcesContent": ["import nacl from \"tweetnacl\";\nimport base64 from \"./base64\";\nimport pako from \"./pako\";\n\n/**\n * Encrypts data using TweetNaCl, compresses it with Pako (Gzip), and encodes it in Base64.\n * @param data - The plaintext data to encrypt.\n * @param secret - The secret key as a string.\n * @returns A Base64 encoded string (nonce + compressed ciphertext).\n */\nfunction encrypt(data: string | object, secret: string): string {\n data = typeof data === \"object\" ? JSON.stringify(data) : data\n secret = hash(secret).substring(0, 32)\n const key = new TextEncoder().encode(secret);\n const nonce = nacl.randomBytes(nacl.secretbox.nonceLength);\n const compressed = pako.compress(data, true) as Uint8Array // Ensure it returns Uint8Array\n const encrypted = nacl.secretbox(compressed, nonce, key);\n return base64.encode(new Uint8Array([...nonce, ...encrypted]));\n}\n\n/**\n * Decrypts a Base64-encoded NaCl-encrypted data, decompresses it with Pako (Gzip).\n * @param data - The Base64 encoded string (nonce + compressed ciphertext).\n * @param secret - The secret key as a string.\n * @returns The decrypted plaintext string.\n */\nfunction decrypt(data: string, secret: string): string {\n try {\n secret = hash(secret).substring(0, 32)\n const key = new TextEncoder().encode(secret);\n const encryptedBytes = base64.decode(data);\n const nonce = encryptedBytes.slice(0, nacl.secretbox.nonceLength);\n const ciphertext = encryptedBytes.slice(nacl.secretbox.nonceLength);\n const decrypted = nacl.secretbox.open(ciphertext, nonce, key);\n if (!decrypted) throw new Error(\"Decryption failed!\");\n const decompressed = pako.decompress(decrypted); // Decompress as string\n try {\n return JSON.parse(decompressed);\n } catch (error) {\n return decompressed;\n }\n } catch (error) {\n throw new Error(\"Invalid encrypted data.\");\n }\n}\n\n/**\n * Hashes a string using NaCl's hash function.\n * @param data - The input string to hash.\n * @returns The hash of the input string.\n */\nlet hashed = new Map<string, string>();\nfunction hash(data: string): string {\n if (hashed.has(data)) return hashed.get(data) as string\n const inputBytes = new TextEncoder().encode(data);\n const hashedData = nacl.hash(inputBytes);\n const d = Array.from(hashedData)\n .map(byte => byte.toString(16).padStart(2, '0'))\n .join('');\n hashed.set(data, d)\n return d\n}\n\nconst makeSecret = (secret: string) => {\n return hash(secret).substring(0, 32);\n}\n\nconst crypto = {\n encrypt,\n decrypt,\n hash,\n makeSecret\n};\n\nexport default crypto;\n"],
5
5
  "mappings": "AAAA,OAAOA,MAAU,YACjB,OAAOC,MAAY,WACnB,OAAOC,MAAU,SAQjB,SAASC,EAAQC,EAAuBC,EAAwB,CAC7DD,EAAO,OAAOA,GAAS,SAAW,KAAK,UAAUA,CAAI,EAAIA,EACzDC,EAASC,EAAKD,CAAM,EAAE,UAAU,EAAG,EAAE,EACrC,MAAME,EAAM,IAAI,YAAY,EAAE,OAAOF,CAAM,EACrCG,EAAQR,EAAK,YAAYA,EAAK,UAAU,WAAW,EACnDS,EAAaP,EAAK,SAASE,EAAM,EAAI,EACrCM,EAAYV,EAAK,UAAUS,EAAYD,EAAOD,CAAG,EACvD,OAAON,EAAO,OAAO,IAAI,WAAW,CAAC,GAAGO,EAAO,GAAGE,CAAS,CAAC,CAAC,CAChE,CAQA,SAASC,EAAQP,EAAcC,EAAwB,CACpD,GAAI,CACDA,EAASC,EAAKD,CAAM,EAAE,UAAU,EAAG,EAAE,EACrC,MAAME,EAAM,IAAI,YAAY,EAAE,OAAOF,CAAM,EACrCO,EAAiBX,EAAO,OAAOG,CAAI,EACnCI,EAAQI,EAAe,MAAM,EAAGZ,EAAK,UAAU,WAAW,EAC1Da,EAAaD,EAAe,MAAMZ,EAAK,UAAU,WAAW,EAC5Dc,EAAYd,EAAK,UAAU,KAAKa,EAAYL,EAAOD,CAAG,EAC5D,GAAI,CAACO,EAAW,MAAM,IAAI,MAAM,oBAAoB,EACpD,MAAMC,EAAeb,EAAK,WAAWY,CAAS,EAC9C,GAAI,CACD,OAAO,KAAK,MAAMC,CAAY,CACjC,MAAgB,CACb,OAAOA,CACV,CACH,MAAgB,CACb,MAAM,IAAI,MAAM,yBAAyB,CAC5C,CACH,CAOA,IAAIC,EAAS,IAAI,IACjB,SAASV,EAAKF,EAAsB,CACjC,GAAIY,EAAO,IAAIZ,CAAI,EAAG,OAAOY,EAAO,IAAIZ,CAAI,EAC5C,MAAMa,EAAa,IAAI,YAAY,EAAE,OAAOb,CAAI,EAC1Cc,EAAalB,EAAK,KAAKiB,CAAU,EACjCE,EAAI,MAAM,KAAKD,CAAU,EAC3B,IAAIE,GAAQA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAC9C,KAAK,EAAE,EACX,OAAAJ,EAAO,IAAIZ,EAAMe,CAAC,EACXA,CACV,CAEA,MAAME,EAAchB,GACVC,EAAKD,CAAM,EAAE,UAAU,EAAG,EAAE,EAGhCiB,EAAS,CACZ,QAAAnB,EACA,QAAAQ,EACA,KAAAL,EACA,WAAAe,CACH,EAEA,IAAOE,EAAQD",
6
6
  "names": ["nacl", "base64", "pako", "encrypt", "data", "secret", "hash", "key", "nonce", "compressed", "encrypted", "decrypt", "encryptedBytes", "ciphertext", "decrypted", "decompressed", "hashed", "inputBytes", "hashedData", "d", "byte", "makeSecret", "crypto", "crypto_default"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/include/lib/pako.ts"],
4
- "sourcesContent": ["import pako from \"pako\";\r\nimport base64 from \"./base64\";\r\n\r\n/**\r\n * Compresses a string message using Pako (Gzip).\r\n * @param message - The plaintext string message to compress.\r\n * @returns A Base64 encoded string of the compressed data.\r\n */\r\nexport function compress(data: string, returnUnit8?: boolean): string | Uint8Array {\r\n const encoded = new TextEncoder().encode(data);\r\n const compressed = pako.gzip(encoded);\r\n if (returnUnit8) return compressed;\r\n return base64.encode(compressed);\r\n}\r\n\r\n/**\r\n * Decompresses a Base64 encoded compressed message using Pako (Gzip).\r\n * @param data - The Base64 encoded compressed data.\r\n * @returns The decompressed plaintext string.\r\n */\r\nexport function decompress(data: string | Uint8Array): string {\r\n if (typeof data === 'string') {\r\n data = base64.decode(data);\r\n }\r\n const decompressed = pako.ungzip(data);\r\n return new TextDecoder().decode(decompressed);\r\n}\r\n\r\nexport default {\r\n compress,\r\n decompress\r\n}"],
4
+ "sourcesContent": ["import pako from \"pako\";\nimport base64 from \"./base64\";\n\n/**\n * Compresses a string message using Pako (Gzip).\n * @param message - The plaintext string message to compress.\n * @returns A Base64 encoded string of the compressed data.\n */\nexport function compress(data: string, returnUnit8?: boolean): string | Uint8Array {\n const encoded = new TextEncoder().encode(data);\n const compressed = pako.gzip(encoded);\n if (returnUnit8) return compressed;\n return base64.encode(compressed);\n}\n\n/**\n * Decompresses a Base64 encoded compressed message using Pako (Gzip).\n * @param data - The Base64 encoded compressed data.\n * @returns The decompressed plaintext string.\n */\nexport function decompress(data: string | Uint8Array): string {\n if (typeof data === 'string') {\n data = base64.decode(data);\n }\n const decompressed = pako.ungzip(data);\n return new TextDecoder().decode(decompressed);\n}\n\nexport default {\n compress,\n decompress\n}"],
5
5
  "mappings": "AAAA,OAAOA,MAAU,OACjB,OAAOC,MAAY,WAOZ,SAASC,EAASC,EAAcC,EAA4C,CAChF,MAAMC,EAAU,IAAI,YAAY,EAAE,OAAOF,CAAI,EACvCG,EAAaN,EAAK,KAAKK,CAAO,EACpC,OAAID,EAAoBE,EACjBL,EAAO,OAAOK,CAAU,CAClC,CAOO,SAASC,EAAWJ,EAAmC,CACvD,OAAOA,GAAS,WACjBA,EAAOF,EAAO,OAAOE,CAAI,GAE5B,MAAMK,EAAeR,EAAK,OAAOG,CAAI,EACrC,OAAO,IAAI,YAAY,EAAE,OAAOK,CAAY,CAC/C,CAEA,IAAOC,EAAQ,CACZ,SAAAP,EACA,WAAAK,CACH",
6
6
  "names": ["pako", "base64", "compress", "data", "returnUnit8", "encoded", "compressed", "decompress", "decompressed", "pako_default"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/include/lib/reverser.ts"],
4
- "sourcesContent": ["const substitutionPattern: any = {};\r\nconst alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\nfor (let i = 0; i < alphabet.length; i++) {\r\n substitutionPattern[alphabet[i]] = alphabet[(i + 1) % alphabet.length];\r\n substitutionPattern[alphabet[i].toLowerCase()] = alphabet[(i + 1) % alphabet.length].toLowerCase();\r\n}\r\n\r\nlet speacialCharters = '?.,!@#$%^&*()_+-=[]{}|;:<>/';\r\nfor (let i = 0; i < speacialCharters.length; i++) {\r\n substitutionPattern[speacialCharters[i]] = speacialCharters[i];\r\n}\r\n\r\nconst encrypt = (text: string) => text.split('').map((char) => substitutionPattern[char] || char).join('')\r\nconst decrypt = (text: string) => {\r\n return text.split('').map((char) => {\r\n for (let key in substitutionPattern) {\r\n if (substitutionPattern[key] === char) {\r\n return key;\r\n }\r\n }\r\n return char;\r\n }).join('');\r\n}\r\n\r\nexport default {\r\n encrypt,\r\n decrypt\r\n}"],
4
+ "sourcesContent": ["const substitutionPattern: any = {};\nconst alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nfor (let i = 0; i < alphabet.length; i++) {\n substitutionPattern[alphabet[i]] = alphabet[(i + 1) % alphabet.length];\n substitutionPattern[alphabet[i].toLowerCase()] = alphabet[(i + 1) % alphabet.length].toLowerCase();\n}\n\nlet speacialCharters = '?.,!@#$%^&*()_+-=[]{}|;:<>/';\nfor (let i = 0; i < speacialCharters.length; i++) {\n substitutionPattern[speacialCharters[i]] = speacialCharters[i];\n}\n\nconst encrypt = (text: string) => text.split('').map((char) => substitutionPattern[char] || char).join('')\nconst decrypt = (text: string) => {\n return text.split('').map((char) => {\n for (let key in substitutionPattern) {\n if (substitutionPattern[key] === char) {\n return key;\n }\n }\n return char;\n }).join('');\n}\n\nexport default {\n encrypt,\n decrypt\n}"],
5
5
  "mappings": "AAAA,MAAMA,EAA2B,CAAC,EAC5BC,EAAW,6BACjB,QAASC,EAAI,EAAGA,EAAID,EAAS,OAAQC,IAClCF,EAAoBC,EAASC,CAAC,CAAC,EAAID,GAAUC,EAAI,GAAKD,EAAS,MAAM,EACrED,EAAoBC,EAASC,CAAC,EAAE,YAAY,CAAC,EAAID,GAAUC,EAAI,GAAKD,EAAS,MAAM,EAAE,YAAY,EAGpG,IAAIE,EAAmB,8BACvB,QAASD,EAAI,EAAGA,EAAIC,EAAiB,OAAQD,IAC1CF,EAAoBG,EAAiBD,CAAC,CAAC,EAAIC,EAAiBD,CAAC,EAGhE,MAAME,EAAWC,GAAiBA,EAAK,MAAM,EAAE,EAAE,IAAKC,GAASN,EAAoBM,CAAI,GAAKA,CAAI,EAAE,KAAK,EAAE,EACnGC,EAAWF,GACPA,EAAK,MAAM,EAAE,EAAE,IAAKC,GAAS,CACjC,QAASE,KAAOR,EACb,GAAIA,EAAoBQ,CAAG,IAAMF,EAC9B,OAAOE,EAGb,OAAOF,CACV,CAAC,EAAE,KAAK,EAAE,EAGb,IAAOG,EAAQ,CACZ,QAAAL,EACA,QAAAG,CACH",
6
6
  "names": ["substitutionPattern", "alphabet", "i", "speacialCharters", "encrypt", "text", "char", "decrypt", "key", "reverser_default"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/include/lib/urlpath.ts"],
4
- "sourcesContent": ["import reverser from \"./reverser\"\r\n\r\nfunction encrypt(input: string): string {\r\n return encodeURIComponent(reverser.encrypt(input.toLowerCase()))\r\n}\r\n\r\nfunction decrypt(encryptedString: string): string {\r\n return reverser.decrypt(decodeURIComponent(encryptedString))\r\n}\r\n\r\nexport default {\r\n encrypt,\r\n decrypt\r\n}"],
4
+ "sourcesContent": ["import reverser from \"./reverser\"\n\nfunction encrypt(input: string): string {\n return encodeURIComponent(reverser.encrypt(input.toLowerCase()))\n}\n\nfunction decrypt(encryptedString: string): string {\n return reverser.decrypt(decodeURIComponent(encryptedString))\n}\n\nexport default {\n encrypt,\n decrypt\n}"],
5
5
  "mappings": "AAAA,OAAOA,MAAc,aAErB,SAASC,EAAQC,EAAuB,CACrC,OAAO,mBAAmBF,EAAS,QAAQE,EAAM,YAAY,CAAC,CAAC,CAClE,CAEA,SAASC,EAAQC,EAAiC,CAC/C,OAAOJ,EAAS,QAAQ,mBAAmBI,CAAe,CAAC,CAC9D,CAEA,IAAOC,EAAQ,CACZ,QAAAJ,EACA,QAAAE,CACH",
6
6
  "names": ["reverser", "encrypt", "input", "decrypt", "encryptedString", "urlpath_default"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/include/responseValue.ts"],
4
- "sourcesContent": ["import crypto from \"./lib/crypto\";\r\n\r\nconst encrypt = (data: any, signerure: string): string => {\r\n return crypto.encrypt(data, crypto.makeSecret(signerure))\r\n}\r\n\r\nconst decrypt = (value: string, signerure: string) => {\r\n return crypto.decrypt(value, crypto.makeSecret(signerure))\r\n}\r\n\r\nexport default {\r\n encrypt,\r\n decrypt\r\n}"],
4
+ "sourcesContent": ["import crypto from \"./lib/crypto\";\n\nconst encrypt = (data: any, signerure: string): string => {\n return crypto.encrypt(data, crypto.makeSecret(signerure))\n}\n\nconst decrypt = (value: string, signerure: string) => {\n return crypto.decrypt(value, crypto.makeSecret(signerure))\n}\n\nexport default {\n encrypt,\n decrypt\n}"],
5
5
  "mappings": "AAAA,OAAOA,MAAY,eAEnB,MAAMC,EAAU,CAACC,EAAWC,IAClBH,EAAO,QAAQE,EAAMF,EAAO,WAAWG,CAAS,CAAC,EAGrDC,EAAU,CAACC,EAAeF,IACtBH,EAAO,QAAQK,EAAOL,EAAO,WAAWG,CAAS,CAAC,EAG5D,IAAOG,EAAQ,CACZ,QAAAL,EACA,QAAAG,CACH",
6
6
  "names": ["crypto", "encrypt", "data", "signerure", "decrypt", "value", "responseValue_default"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/include/signeture.ts"],
4
- "sourcesContent": ["import crypto from \"./lib/crypto\";\r\n\r\nconst make = (val: string, secret: string) => {\r\n const signeture = crypto.encrypt(val, secret);\r\n const signetureHash = crypto.hash(signeture)\r\n const secretEncript = crypto.encrypt(secret, signetureHash);\r\n return `${signeture}.${secretEncript}`;\r\n}\r\n\r\nconst verify = (signerure: string) => {\r\n const [signeture, secretEncript] = signerure.split(\".\");\r\n const signetureHash = crypto.hash(signeture);\r\n const secret = crypto.decrypt(secretEncript, signetureHash);\r\n const secretVal = crypto.decrypt(signeture, secret);\r\n if (secretVal !== secret) throw new Error(\"Invalid Signeture\");\r\n return secretVal;\r\n}\r\n\r\nexport default {\r\n make,\r\n verify,\r\n key: \"x-signeture\"\r\n}"],
4
+ "sourcesContent": ["import crypto from \"./lib/crypto\";\n\nconst make = (val: string, secret: string) => {\n const signeture = crypto.encrypt(val, secret);\n const signetureHash = crypto.hash(signeture)\n const secretEncript = crypto.encrypt(secret, signetureHash);\n return `${signeture}.${secretEncript}`;\n}\n\nconst verify = (signerure: string) => {\n const [signeture, secretEncript] = signerure.split(\".\");\n const signetureHash = crypto.hash(signeture);\n const secret = crypto.decrypt(secretEncript, signetureHash);\n const secretVal = crypto.decrypt(signeture, secret);\n if (secretVal !== secret) throw new Error(\"Invalid Signeture\");\n return secretVal;\n}\n\nexport default {\n make,\n verify,\n key: \"x-signeture\"\n}"],
5
5
  "mappings": "AAAA,OAAOA,MAAY,eAEnB,MAAMC,EAAO,CAACC,EAAaC,IAAmB,CAC3C,MAAMC,EAAYJ,EAAO,QAAQE,EAAKC,CAAM,EACtCE,EAAgBL,EAAO,KAAKI,CAAS,EACrCE,EAAgBN,EAAO,QAAQG,EAAQE,CAAa,EAC1D,MAAO,GAAGD,CAAS,IAAIE,CAAa,EACvC,EAEMC,EAAUC,GAAsB,CACnC,KAAM,CAACJ,EAAWE,CAAa,EAAIE,EAAU,MAAM,GAAG,EAChDH,EAAgBL,EAAO,KAAKI,CAAS,EACrCD,EAASH,EAAO,QAAQM,EAAeD,CAAa,EACpDI,EAAYT,EAAO,QAAQI,EAAWD,CAAM,EAClD,GAAIM,IAAcN,EAAQ,MAAM,IAAI,MAAM,mBAAmB,EAC7D,OAAOM,CACV,EAEA,IAAOC,EAAQ,CACZ,KAAAT,EACA,OAAAM,EACA,IAAK,aACR",
6
6
  "names": ["crypto", "make", "val", "secret", "signeture", "signetureHash", "secretEncript", "verify", "signerure", "secretVal", "signeture_default"]
7
7
  }
package/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["export { default as SecurequServer } from './server';\r\nexport { default as SecurequClient } from './client';\r\n"],
4
+ "sourcesContent": ["export { default as SecurequServer } from './server';\nexport { default as SecurequClient } from './client';\n"],
5
5
  "mappings": "AAAA,OAAoB,WAAXA,MAAiC,WAC1C,OAAoB,WAAXA,MAAiC",
6
6
  "names": ["default"]
7
7
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "securequ",
3
- "version": "1.0.0",
4
- "main": "./index.js",
5
- "module": "./esm/index.js",
3
+ "version": "1.0.2",
4
+ "main": "./cjs/index.js",
5
+ "module": "./index.js",
6
6
  "types": "./types/index.d.ts",
7
7
  "description": "",
8
8
  "keywords": [],
@@ -36,7 +36,7 @@
36
36
  "@types/react": "^19.0.2",
37
37
  "@types/react-dom": "^19.0.2",
38
38
  "express": "latest",
39
- "makepack": "latest",
39
+ "makepack": "^1.5.23",
40
40
  "react": "^19.0.0",
41
41
  "react-dom": "^19.0.0",
42
42
  "typescript": "^4.4.2"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/server/index.ts"],
4
- "sourcesContent": ["import { match } from \"path-to-regexp\";\r\nimport crypto from \"../include/lib/crypto\";\r\nimport reverser from \"../include/lib/reverser\";\r\nimport responseValue from \"../include/responseValue\";\r\nimport signeture from \"../include/signeture\";\r\nimport { HandlerFunction, HandlerInfo, HTTPMethods, ListenerInfo, RouteFactory, ServerResponse, SecurequServerConfig } from \"./types\";\r\nimport SecurequCache from \"../include/lib/cache\";\r\n\r\n\r\nclass SecurequServer {\r\n private HandlerCache = new SecurequCache<HandlerFunction>({ ttl: 1000 * 60 * 60, limit: 100 });\r\n private routes: RouteFactory = {\r\n GET: {},\r\n POST: {},\r\n PUT: {},\r\n DELETE: {}\r\n };\r\n private config: SecurequServerConfig;\r\n private secret: string = crypto.makeSecret(Math.random().toString(36).substring(7));\r\n\r\n constructor(config: SecurequServerConfig) {\r\n this.config = { ...config }\r\n }\r\n\r\n async addRoute(path: string, method: HTTPMethods, handler: HandlerFunction) {\r\n if (this.routes[method][path]) return\r\n this.routes[method][path] = {\r\n handler,\r\n test: match(path)\r\n }\r\n }\r\n\r\n async get(path: string, handler: HandlerFunction) {\r\n this.addRoute(path, 'GET', handler)\r\n }\r\n\r\n async post(path: string, handler: HandlerFunction) {\r\n this.addRoute(path, 'POST', handler)\r\n }\r\n\r\n async put(path: string, handler: HandlerFunction) {\r\n this.addRoute(path, 'PUT', handler)\r\n }\r\n\r\n async delete(path: string, handler: HandlerFunction) {\r\n this.addRoute(path, 'DELETE', handler)\r\n }\r\n\r\n async handleRequest(info: HandlerInfo, args?: any) {\r\n const { path, method } = info;\r\n let cacheHandler = this.HandlerCache.get(`${method}:${path}`);\r\n if (cacheHandler) {\r\n await cacheHandler(info, args)\r\n return\r\n }\r\n let values: any = Object.values(this.routes[method]);\r\n for (let value of values) {\r\n let { test, handler } = value\r\n const match = test(path)\r\n if (match) {\r\n info.params = match.params;\r\n await handler(info, args)\r\n this.HandlerCache.set(`${method}:${path}`, handler)\r\n }\r\n }\r\n }\r\n\r\n async listen(listenerInfo: ListenerInfo, args?: any): Promise<ServerResponse> {\r\n try {\r\n if (!listenerInfo.signeture || !listenerInfo.path || !listenerInfo.method || !listenerInfo.body) throw new Error(\"Invalid Request\");\r\n\r\n const clientSecret = signeture.verify(listenerInfo.signeture);\r\n const { path, body, method } = listenerInfo;\r\n const url = new URL(path, \"http://localhost\");\r\n\r\n // format the path\r\n url.pathname = url.pathname.replace(this.config.basepath, \"/\")\r\n let split = url.pathname.split(\"/\").map((s) => reverser.decrypt(s)).filter((s) => s.length > 0);\r\n url.pathname = `/${split.join(\"/\")}`;\r\n\r\n // handle handshake \r\n const handshakeSecret = crypto.makeSecret(this.secret + clientSecret);\r\n const reqkey = handshakeSecret.substring(0, handshakeSecret.length / 2);\r\n\r\n if (method === 'GET' && url.pathname === \"/handshake\") {\r\n throw crypto.encrypt(handshakeSecret, clientSecret)\r\n }\r\n\r\n let data: any = {}, searchParams: any = {}\r\n\r\n if (url.searchParams.has(reqkey)) {\r\n let decripted: any = crypto.decrypt(url.searchParams.get(reqkey) as string, handshakeSecret)\r\n for (let key in decripted) {\r\n let ukey = reverser.decrypt(key)\r\n searchParams[ukey] = decripted[key]\r\n }\r\n }\r\n\r\n if (body[reqkey]) {\r\n let decripted: any = crypto.decrypt(body[reqkey], handshakeSecret)\r\n for (let key in decripted) {\r\n let ukey = reverser.decrypt(key)\r\n data[ukey] = decripted[key]\r\n }\r\n }\r\n\r\n // handle the request\r\n await this.handleRequest({\r\n method,\r\n path: url.pathname,\r\n body: data,\r\n searchParams,\r\n params: {}\r\n }, args);\r\n } catch (info: any) {\r\n if (info instanceof Error) {\r\n return {\r\n status: 404,\r\n value: responseValue.encrypt(info.message, listenerInfo.signeture)\r\n }\r\n } else if (info instanceof Response) {\r\n let text = await info.text();\r\n return {\r\n status: info.status,\r\n value: responseValue.encrypt(text, listenerInfo.signeture)\r\n }\r\n }\r\n return {\r\n status: 200,\r\n value: responseValue.encrypt(info, listenerInfo.signeture)\r\n };\r\n }\r\n\r\n return {\r\n status: 404,\r\n value: 'Not Found'\r\n };\r\n }\r\n}\r\n\r\nexport default SecurequServer;"],
4
+ "sourcesContent": ["import { match } from \"path-to-regexp\";\nimport crypto from \"../include/lib/crypto\";\nimport reverser from \"../include/lib/reverser\";\nimport responseValue from \"../include/responseValue\";\nimport signeture from \"../include/signeture\";\nimport { HandlerFunction, HandlerInfo, HTTPMethods, ListenerInfo, RouteFactory, ServerResponse, SecurequServerConfig } from \"./types\";\nimport SecurequCache from \"../include/lib/cache\";\n\n\nclass SecurequServer {\n private HandlerCache = new SecurequCache<HandlerFunction>({ ttl: 1000 * 60 * 60, limit: 100 });\n private routes: RouteFactory = {\n GET: {},\n POST: {},\n PUT: {},\n DELETE: {}\n };\n private config: SecurequServerConfig;\n private secret: string = crypto.makeSecret(Math.random().toString(36).substring(7));\n\n constructor(config: SecurequServerConfig) {\n this.config = { ...config }\n }\n\n async addRoute(path: string, method: HTTPMethods, handler: HandlerFunction) {\n if (this.routes[method][path]) return\n this.routes[method][path] = {\n handler,\n test: match(path)\n }\n }\n\n async get(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'GET', handler)\n }\n\n async post(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'POST', handler)\n }\n\n async put(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'PUT', handler)\n }\n\n async delete(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'DELETE', handler)\n }\n\n async handleRequest(info: HandlerInfo, args?: any) {\n const { path, method } = info;\n let cacheHandler = this.HandlerCache.get(`${method}:${path}`);\n if (cacheHandler) {\n await cacheHandler(info, args)\n return\n }\n let values: any = Object.values(this.routes[method]);\n for (let value of values) {\n let { test, handler } = value\n const match = test(path)\n if (match) {\n info.params = match.params;\n await handler(info, args)\n this.HandlerCache.set(`${method}:${path}`, handler)\n }\n }\n }\n\n async listen(listenerInfo: ListenerInfo, args?: any): Promise<ServerResponse> {\n try {\n if (!listenerInfo.signeture || !listenerInfo.path || !listenerInfo.method || !listenerInfo.body) throw new Error(\"Invalid Request\");\n\n const clientSecret = signeture.verify(listenerInfo.signeture);\n const { path, body, method } = listenerInfo;\n const url = new URL(path, \"http://localhost\");\n\n // format the path\n url.pathname = url.pathname.replace(this.config.basepath, \"/\")\n let split = url.pathname.split(\"/\").map((s) => reverser.decrypt(s)).filter((s) => s.length > 0);\n url.pathname = `/${split.join(\"/\")}`;\n\n // handle handshake \n const handshakeSecret = crypto.makeSecret(this.secret + clientSecret);\n const reqkey = handshakeSecret.substring(0, handshakeSecret.length / 2);\n\n if (method === 'GET' && url.pathname === \"/handshake\") {\n throw crypto.encrypt(handshakeSecret, clientSecret)\n }\n\n let data: any = {}, searchParams: any = {}\n\n if (url.searchParams.has(reqkey)) {\n let decripted: any = crypto.decrypt(url.searchParams.get(reqkey) as string, handshakeSecret)\n for (let key in decripted) {\n let ukey = reverser.decrypt(key)\n searchParams[ukey] = decripted[key]\n }\n }\n\n if (body[reqkey]) {\n let decripted: any = crypto.decrypt(body[reqkey], handshakeSecret)\n for (let key in decripted) {\n let ukey = reverser.decrypt(key)\n data[ukey] = decripted[key]\n }\n }\n\n // handle the request\n await this.handleRequest({\n method,\n path: url.pathname,\n body: data,\n searchParams,\n params: {}\n }, args);\n } catch (info: any) {\n if (info instanceof Error) {\n return {\n status: 404,\n value: responseValue.encrypt(info.message, listenerInfo.signeture)\n }\n } else if (info instanceof Response) {\n let text = await info.text();\n return {\n status: info.status,\n value: responseValue.encrypt(text, listenerInfo.signeture)\n }\n }\n return {\n status: 200,\n value: responseValue.encrypt(info, listenerInfo.signeture)\n };\n }\n\n return {\n status: 404,\n value: 'Not Found'\n };\n }\n}\n\nexport default SecurequServer;"],
5
5
  "mappings": "AAAA,OAAS,SAAAA,MAAa,iBACtB,OAAOC,MAAY,wBACnB,OAAOC,MAAc,0BACrB,OAAOC,MAAmB,2BAC1B,OAAOC,MAAe,uBAEtB,OAAOC,MAAmB,uBAG1B,MAAMC,CAAe,CAWlB,YAAYC,EAA8B,CAV1C,KAAQ,aAAe,IAAIF,EAA+B,CAAE,IAAK,IAAO,GAAK,GAAI,MAAO,GAAI,CAAC,EAC7F,KAAQ,OAAuB,CAC5B,IAAK,CAAC,EACN,KAAM,C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Ac,CACtB,OAAAnB,EACA,KAAMW,EAAI,SACV,KAAMK,EACN,aAAAC,EACA,OAAQ,CAAC,CACZ,EAAGd,CAAI,CACV,OAASD,EAAW,CACjB,GAAIA,aAAgB,MACjB,MAAO,CACJ,OAAQ,IACR,MAAOR,EAAc,QAAQQ,EAAK,QAASM,EAAa,SAAS,CACpE,EACI,GAAIN,aAAgB,SAAU,CAClC,IAAImB,EAAO,MAAMnB,EAAK,KAAK,EAC3B,MAAO,CACJ,OAAQA,EAAK,OACb,MAAOR,EAAc,QAAQ2B,EAAMb,EAAa,SAAS,CAC5D,CACH,CACA,MAAO,CACJ,OAAQ,IACR,MAAOd,EAAc,QAAQQ,EAAMM,EAAa,SAAS,CAC5D,CACH,CAEA,MAAO,CACJ,OAAQ,IACR,MAAO,WACV,CACH,CACH,CAEA,IAAOc,EAAQzB",
6
6
  "names": ["match", "crypto", "reverser", "responseValue", "signeture", "SecurequCache", "SecurequServer", "config", "path", "method", "handler", "info", "args", "cacheHandler", "values", "value", "test", "listenerInfo", "clientSecret", "body", "url", "split", "s", "handshakeSecret", "reqkey", "data", "searchParams", "decripted", "key", "ukey", "text", "server_default"]
7
7
  }