@cybearl/cypack 1.11.9 → 1.11.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -169,6 +169,7 @@ Contains utilities to validate environment variables at startup, with protection
169
169
  A zero-dependency isomorphic Next.js-compatible logger that works in both browser and Node.js. ANSI indicators are automatically suppressed in browser environments.
170
170
  - `nextLogger`: The default logger instance.
171
171
  - `createNextLogger(prefix?, prefixColumnWidth?)`: Creates a new logger instance with an optional default prefix and column width for prefix alignment.
172
+ At least one space is always inserted between the `[prefix]` block and the message, even when `prefixColumnWidth` is `0` or smaller than the prefix.
172
173
  - `.success` / `.info` / `.warn` / `.error` / `.debug`: Log at the respective level.
173
174
  - `.withPrefix(prefix, prefixColumnWidth?)`: Returns a new logger with the given prefix fixed as its default, optionally overriding the parent's column width for prefix alignment.
174
175
  - `generateNextLoggerPrefix(uuid, prefix?)`: Derives a short prefix from a UUID (e.g., `"worker-a1b"`), useful for per-job logger scoping.
package/backend.d.ts CHANGED
@@ -53,23 +53,14 @@ declare class Bench {
53
53
  }
54
54
 
55
55
  /**
56
- * The type for the CGAS status string, it can either be:
57
- * - `enabled`: The application is enabled and available to the public.
58
- * - `disabled`: The application is disabled and not available to the public.
59
- * - `in-maintenance`: The application is in maintenance mode and not available to the public.
60
- * - `in-development`: The application is in development mode and not available to the public.
56
+ * The type for the CGAS status string, only "enabled" makes the application available
57
+ * to the public, "disabled", "in-maintenance" and "in-development" do not.
61
58
  */
62
59
  type CGASStatusString = "enabled" | "disabled" | "in-maintenance" | "in-development"
63
60
 
64
61
  /**
65
- * The Cybearl General API System (CGAS) status response.
66
- *
67
- * About the status of the application (allows to enable/disable the application),
68
- * it can either be:
69
- * - `enabled`: The application is enabled and available to the public.
70
- * - `disabled`: The application is disabled and not available to the public.
71
- * - `in-maintenance`: The application is in maintenance mode and not available to the public.
72
- * - `in-development`: The application is in development mode and not available to the public.
62
+ * The Cybearl General API System (CGAS) status response, its status allows to
63
+ * enable/disable the application (see "CGASStatusString").
73
64
  */
74
65
  type CGASStatus = {
75
66
  status: CGASStatusString
@@ -96,15 +87,23 @@ declare function generateCGASStatus(status: CGASStatusString, marker: string, ve
96
87
 
97
88
  /**
98
89
  * The return type of the `encrypt` function.
99
- * - `iv`: Base64-encoded initialization vector used for encryption (no need to store it securely).
100
- * - `ciphertext`: Base64-encoded ciphertext resulting from the encryption process.
101
- * - `tag`: Authentication tag as a Buffer, used for verifying the integrity of the ciphertext.
102
- * - `payload`: Full payload combining iv, ciphertext, and tag, formatted as "iv.ciphertext.tag".
103
90
  */
104
91
  type CryptoAes256GcmEncryptResult = {
92
+ /**
93
+ * Base64-encoded initialization vector used for encryption (no need to store it securely).
94
+ */
105
95
  iv: string;
96
+ /**
97
+ * Base64-encoded ciphertext resulting from the encryption process.
98
+ */
106
99
  ciphertext: string;
100
+ /**
101
+ * Authentication tag as a Buffer, used for verifying the integrity of the ciphertext.
102
+ */
107
103
  tag: Buffer;
104
+ /**
105
+ * Full payload combining iv, ciphertext, and tag, formatted as "iv.ciphertext.tag".
106
+ */
108
107
  payload: string;
109
108
  };
110
109
  /**
@@ -189,26 +188,17 @@ declare class CyBuffer {
189
188
  * - `arrayBuffer`: The array buffer to use.
190
189
  * - `offset`: The offset in bytes to start reading from (optional, defaults to 0).
191
190
  * - `length`: The length in bytes to read (optional, defaults to the input length).
191
+ * @returns The proxied "CyBuffer" instance.
192
192
  */
193
193
  constructor(length: number, options?: {
194
194
  arrayBuffer: ArrayBuffer;
195
195
  offset?: number;
196
196
  length?: number;
197
197
  });
198
- /**
199
- * ============
200
- * SIGNATURES
201
- * ============
202
- */
203
198
  /**
204
199
  * Signature for the `[]` operator.
205
200
  */
206
201
  [index: number]: number;
207
- /**
208
- * ==================
209
- * INTERNAL METHODS
210
- * ==================
211
- */
212
202
  /**
213
203
  * Get the platform endianness.
214
204
  * @returns The platform endianness.
@@ -217,15 +207,8 @@ declare class CyBuffer {
217
207
  /**
218
208
  * Normalizes the endianness parameter.
219
209
  *
220
- * By default, the extended Uint8Array is written for Little Endian, to keep it consistent,
221
- * if the platform is big endian the endianness parameter is reversed.
222
- *
223
- * - Little endian platform:
224
- * - `LE` read from left to right.
225
- * - `BE` read from right to left.
226
- * - Big endian platform:
227
- * - `LE` read from right to left.
228
- * - `BE` read from left to right.
210
+ * The buffer is written for little endian, so on a big endian platform
211
+ * the endianness parameter is reversed to keep reads and writes consistent.
229
212
  */
230
213
  normalizeEndianness: (endianness: Endianness) => Endianness;
231
214
  /**
@@ -238,11 +221,6 @@ declare class CyBuffer {
238
221
  * @returns The current buffer instance.
239
222
  */
240
223
  check: (offset: number, length: number) => this;
241
- /**
242
- * ================
243
- * STATIC METHODS
244
- * ================
245
- */
246
224
  /**
247
225
  * Creates a new `CyBuffer` instance of the specified length, initially filled with zeros.
248
226
  * @param length The length of the buffer.
@@ -311,11 +289,6 @@ declare class CyBuffer {
311
289
  * @returns A new `CyBuffer` instance.
312
290
  */
313
291
  static fromRange: (start: number, end: number) => CyBuffer;
314
- /**
315
- * ===========
316
- * ACCESSORS
317
- * ===========
318
- */
319
292
  /**
320
293
  * The proxy that allows to access/assign values via the [] operator.
321
294
  * Note that both the getter and setter are safe and never throw.
@@ -333,11 +306,6 @@ declare class CyBuffer {
333
306
  * @returns The generator yielding the index and value of each byte.
334
307
  */
335
308
  entries(): Generator<[number, number]>;
336
- /**
337
- * ===============
338
- * WRITE METHODS
339
- * ===============
340
- */
341
309
  /**
342
310
  * Writes an hexadecimal string to the buffer (supports `0x` prefix).
343
311
  *
@@ -522,16 +490,6 @@ declare class CyBuffer {
522
490
  * @returns The current buffer instance.
523
491
  */
524
492
  writeRange: (start: number, end: number, offset?: number) => this;
525
- /**
526
- * ==============
527
- * READ METHODS
528
- * ==============
529
- *
530
- * Notes:
531
- * - All read methods have the capability to disable the overall check.
532
- * - All of the "endianness sensitive" methods are wrapped within a single
533
- * method with an optional endianness parameter.
534
- */
535
493
  /**
536
494
  * **[LITTLE ENDIAN]** Reads a part of the buffer and returns it as an hexadecimal string (always uppercase).
537
495
  * @param offset The offset to start reading from (optional, defaults to 0).
@@ -686,11 +644,6 @@ declare class CyBuffer {
686
644
  * @returns The big integer.
687
645
  */
688
646
  readBigInt: (offset?: number, length?: number, endianness?: Endianness, check?: boolean) => bigint;
689
- /**
690
- * ====================
691
- * CONVERSION METHODS
692
- * ====================
693
- */
694
647
  /**
695
648
  * Converts the buffer into an hexadecimal string (always uppercase).
696
649
  * @param prefix Whether to prefix the hexadecimal string with `0x` (optional, defaults to `false`).
@@ -737,11 +690,6 @@ declare class CyBuffer {
737
690
  * @returns The big integer.
738
691
  */
739
692
  toBigInt: (endianness?: Endianness) => bigint;
740
- /**
741
- * ===============
742
- * CHECK METHODS
743
- * ===============
744
- */
745
693
  /**
746
694
  * Checks if the current buffer is equal to the specified buffer.
747
695
  * @param buffer The buffer to compare to.
@@ -758,11 +706,6 @@ declare class CyBuffer {
758
706
  * @returns Whether the buffer is full.
759
707
  */
760
708
  isFull: () => boolean;
761
- /**
762
- * ====================
763
- * RANDOMNESS METHODS
764
- * ====================
765
- */
766
709
  /**
767
710
  * Randomly fills the buffer with bytes.
768
711
  *
@@ -781,11 +724,6 @@ declare class CyBuffer {
781
724
  * @param length The length to fill (optional, defaults to the buffer length - offset).
782
725
  */
783
726
  safeRandomFill: (offset?: number, length?: number) => Uint8Array<ArrayBufferLike>;
784
- /**
785
- * =================
786
- * UTILITY METHODS
787
- * =================
788
- */
789
727
  /**
790
728
  * Copies the buffer into a new buffer.
791
729
  * @param offset The offset to start copying at (optional, defaults to 0).
@@ -891,72 +829,46 @@ type Parameters = {
891
829
  };
892
830
  /**
893
831
  * A custom serverLogger instance compatible with both front and back-end, allowing to log messages
894
- * with different levels and colors.
895
- *
896
- * The available levels are:
897
- * - `fatal`
898
- * - `error`
899
- * - `warn`
900
- * - `info`
901
- * - `debug`
902
- * - `trace`
903
- *
904
- * The available parameters are:
905
- * - `setLevel`: Set the serverLogger level (defaults to `"trace"`).
906
- * - `setShowLevel`: Set the serverLogger level display (defaults to `true`).
907
- * - `setShowTimestamp`: Set the serverLogger timestamp display (defaults to `true`).
908
- * - `setForeignObjectStartAtNewLine`: Set the serverLogger foreign object new line display (defaults to `false`).
909
- * - `setForeignObjectPadding`: Set the padding for foreign objects (defaults to `0`).
910
- * - `setForeignObjectIndent`: Set the indent for foreign objects (defaults to `4`).
911
- * - `setAlignForeignObject`: Align any foreign object to the same column (defaults to `false`).
912
- * - `setParameters`: Set all the parameters at once.
913
- * - `resetParameters`: Reset all the parameters to their default values.
832
+ * with different levels ("fatal", "error", "warn", "info", "debug", "trace") and colors,
833
+ * configurable through the setter methods documented below.
914
834
  */
915
835
  declare const serverLogger: pino.Logger & {
916
836
  /**
917
- * Set the serverLogger level, available levels are:
918
- * - `fatal`
919
- * - `error`
920
- * - `warn`
921
- * - `info`
922
- * - `debug`
923
- * - `trace`
924
- *
925
- * The logging level is a **minimum** level. For instance if `serverLogger.level` is `"info"` then all
926
- * `"fatal"`, `"error"`, `"warn"` and `"info"` logs will be enabled.
927
- * @param level The new serverLogger level.
837
+ * Set the serverLogger minimum level (defaults to "trace"), every log at or above this level
838
+ * is enabled (e.g. "info" enables "fatal", "error", "warn" and "info").
839
+ * @param level The new serverLogger level ("fatal", "error", "warn", "info", "debug" or "trace").
928
840
  */
929
841
  setLevel: (level: Parameters["level"]) => void;
930
842
  /**
931
843
  * Set the serverLogger level display.
932
- * @param showLevel Whether to show the level or not.
844
+ * @param showLevel Whether to show the level or not (defaults to true).
933
845
  */
934
846
  setShowLevel: (showLevel: Parameters["showLevel"]) => void;
935
847
  /**
936
848
  * Set the serverLogger timestamp display.
937
- * @param showTimestamp Whether to show the timestamp or not.
849
+ * @param showTimestamp Whether to show the timestamp or not (defaults to true).
938
850
  */
939
851
  setShowTimestamp: (showTimestamp: Parameters["showTimestamp"]) => void;
940
852
  /**
941
853
  * Set the serverLogger foreign object new line display (wether to start the foreign object on a new line or not).
942
- * @param foreignObjectStartAtNewLine Whether to start the foreign object on a new line or not.
854
+ * @param foreignObjectStartAtNewLine Whether to start the foreign object on a new line or not (defaults to false).
943
855
  */
944
856
  setForeignObjectStartAtNewLine: (foreignObjectStartAtNewLine: Parameters["foreignObjectStartAtNewLine"]) => void;
945
857
  /**
946
858
  * Set the padding for foreign objects, it also accepts `"after-timestamp"` and
947
859
  * `"after-level"` to automatically calculate the padding to match the beginning of the
948
860
  * specified element.
949
- * @param padding The padding for foreign objects.
861
+ * @param padding The padding for foreign objects (defaults to 0).
950
862
  */
951
863
  setForeignObjectPadding: (padding: Parameters["foreignObjectPadding"]) => void;
952
864
  /**
953
865
  * Set the indent for foreign objects.
954
- * @param indent The indent for foreign objects.
866
+ * @param indent The indent for foreign objects (defaults to 4).
955
867
  */
956
868
  setForeignObjectIndent: (indent: Parameters["foreignObjectIndent"]) => void;
957
869
  /**
958
870
  * Set whether to align any foreign object to the same column.
959
- * @param alignForeignObject Whether to align any foreign object to the same column.
871
+ * @param alignForeignObject Whether to align any foreign object to the same column (defaults to false).
960
872
  */
961
873
  setAlignForeignObject: (alignForeignObject: Parameters["alignForeignObject"]) => void;
962
874
  /**
@@ -1067,7 +979,7 @@ declare class NextApiWrapper {
1067
979
  */
1068
980
  private _checkDataValidity;
1069
981
  /**
1070
- * Returns a properly formatted success response.
982
+ * Returns a properly formatted success response, without a body for statuses that can't carry one (204, 304).
1071
983
  * @param status Status code to be sent in the response.
1072
984
  * @param data Data to be sent in the response (optional, defaults to `null`).
1073
985
  */
@@ -1077,6 +989,7 @@ declare class NextApiWrapper {
1077
989
  * @param error Error code constant to be sent in the response.
1078
990
  * @param data Additional data to be sent in the response (optional).
1079
991
  * @param message Error message to be sent in the response (optional, defaults to the internal error message).
992
+ * @returns The result of sending the error response.
1080
993
  */
1081
994
  errorResponse(error: ErrorObj, data?: unknown, message?: string): void;
1082
995
  /**
@@ -1087,7 +1000,13 @@ declare class NextApiWrapper {
1087
1000
  */
1088
1001
  private _executeMethod;
1089
1002
  /**
1090
- * Run and route the request to the appropriate method.
1003
+ * Maps each HTTP method to its registered route method.
1004
+ * @returns The route methods, keyed by HTTP method.
1005
+ */
1006
+ private _getMethodsByHttpMethod;
1007
+ /**
1008
+ * Run and route the request to the appropriate method, answering 405 (with an "Allow" header)
1009
+ * when no method is registered for the request's HTTP method.
1091
1010
  * @returns The response from the method.
1092
1011
  */
1093
1012
  run(): Promise<boolean | void>;
@@ -1212,7 +1131,7 @@ declare class NextAuthApiWrapper {
1212
1131
  */
1213
1132
  private _checkDataValidity;
1214
1133
  /**
1215
- * Returns a properly formatted success response.
1134
+ * Returns a properly formatted success response, without a body for statuses that can't carry one (204, 304).
1216
1135
  * @param status Status code to be sent in the response.
1217
1136
  * @param data Data to be sent in the response (optional, defaults to `null`).
1218
1137
  */
@@ -1222,6 +1141,7 @@ declare class NextAuthApiWrapper {
1222
1141
  * @param error Error code constant to be sent in the response.
1223
1142
  * @param data Additional data to be sent in the response (optional).
1224
1143
  * @param message Error message to be sent in the response (optional, defaults to the internal error message).
1144
+ * @returns The result of sending the error response.
1225
1145
  */
1226
1146
  errorResponse(error: ErrorObj, data?: unknown, message?: string): void;
1227
1147
  /**
@@ -1260,7 +1180,13 @@ declare class NextAuthApiWrapper {
1260
1180
  */
1261
1181
  private _executeMethod;
1262
1182
  /**
1263
- * Run and route the request to the appropriate method.
1183
+ * Maps each HTTP method to its registered route method.
1184
+ * @returns The route methods, keyed by HTTP method.
1185
+ */
1186
+ private _getMethodsByHttpMethod;
1187
+ /**
1188
+ * Run and route the request to the appropriate method, answering 405 (with an "Allow" header)
1189
+ * when no method is registered for the request's HTTP method.
1264
1190
  * @returns The response from the method.
1265
1191
  */
1266
1192
  run(): Promise<boolean | void>;
package/backend.js CHANGED
@@ -1,6 +1,6 @@
1
- import F,{masks}from'dateformat';import v from'pino';import C from'pino-pretty';import M from'slugify';import {randomBytes,createCipheriv,createDecipheriv,randomFillSync}from'crypto';import {execSync}from'child_process';import {hostname}from'os';function B(n,t=4){return JSON.stringify(n,(e,r)=>typeof r=="function"||typeof r=="bigint"?r.toString():r,t)}var U={level:process.env.LOG_LEVEL||"trace",showLevel:true,showTimestamp:true,foreignObjectStartAtNewLine:false,foreignObjectPadding:0,foreignObjectIndent:4,alignForeignObject:false},u={...U};function j(n,t){let e={level:n.level,time:n.time,pid:n.pid,hostname:n.hostname,msg:n.msg},r=Object.entries(n).reduce((l,[y,_])=>(Object.keys(e).includes(y)||(l[y]=_),l),{}),i="N/A",s,a;switch(n.level){case 10:case "trace":i="TRACE",a=t.black;break;case 20:case "debug":i="DEBUG",a=t.blue;break;case 30:case "info":i="INFO",a=t.green;break;case 40:case "warn":i="WARN",a=t.yellow;break;case 50:case "error":i="ERROR",a=t.redBright;break;case 60:case "fatal":i="FATAL",s=t.bold,a=t.redBright;break;default:i="N/A",a=t.white;break}let o="";u.showTimestamp&&(o=`[${F(new Date(n.time),masks.isoDateTime)}] `);let c="";u.showLevel&&(c=u.alignForeignObject?`[${i}] `.padEnd(8," "):`[${i}] `);let m="";Object.keys(r).length>0&&(u.foreignObjectPadding==="after-timestamp"?u.foreignObjectPadding=o.length:u.foreignObjectPadding==="after-level"&&(u.foreignObjectPadding=o.length+c.length),m=`${u.foreignObjectStartAtNewLine?`
2
- `:" "}${B(r,u.foreignObjectIndent)}`.split(`
1
+ import P,{masks}from'dateformat';import C from'pino';import H from'pino-pretty';import O from'slugify';import {randomBytes,createCipheriv,createDecipheriv,randomFillSync}from'crypto';import {execSync}from'child_process';import {hostname}from'os';function M(n,t=4){return JSON.stringify(n,(e,r)=>typeof r=="function"||typeof r=="bigint"?r.toString():r,t)}var U={level:process.env.LOG_LEVEL||"trace",showLevel:true,showTimestamp:true,foreignObjectStartAtNewLine:false,foreignObjectPadding:0,foreignObjectIndent:4,alignForeignObject:false},u={...U};function j(n,t){let e={level:n.level,time:n.time,pid:n.pid,hostname:n.hostname,msg:n.msg},r=Object.entries(n).reduce((l,[y,_])=>(Object.keys(e).includes(y)||(l[y]=_),l),{}),i="N/A",s,a;switch(n.level){case 10:case "trace":i="TRACE",a=t.black;break;case 20:case "debug":i="DEBUG",a=t.blue;break;case 30:case "info":i="INFO",a=t.green;break;case 40:case "warn":i="WARN",a=t.yellow;break;case 50:case "error":i="ERROR",a=t.redBright;break;case 60:case "fatal":i="FATAL",s=t.bold,a=t.redBright;break;default:i="N/A",a=t.white;break}let o="";u.showTimestamp&&(o=`[${P(new Date(n.time),masks.isoDateTime)}] `);let c="";u.showLevel&&(c=u.alignForeignObject?`[${i}] `.padEnd(8," "):`[${i}] `);let d="";Object.keys(r).length>0&&(u.foreignObjectPadding==="after-timestamp"?u.foreignObjectPadding=o.length:u.foreignObjectPadding==="after-level"&&(u.foreignObjectPadding=o.length+c.length),d=`${u.foreignObjectStartAtNewLine?`
2
+ `:" "}${M(r,u.foreignObjectIndent)}`.split(`
3
3
  `).map((l,y)=>y===0?l:l.padStart(l.length+u.foreignObjectPadding," ")).join(`
4
- `));let g=a(`${o}${c}${n.msg}${m}`);return s&&(g=s(g)),console.log(g),""}var H=C({crlf:false,colorize:true,sync:true,include:"",messageFormat:(n,t,e,{colors:r})=>j(n,r)}),d=v({level:u.level},H);d.setLevel=n=>{u.level=n,d.level=n;};d.setShowLevel=n=>{u.showLevel=n;};d.setShowTimestamp=n=>{u.showTimestamp=n;};d.setForeignObjectStartAtNewLine=n=>{u.foreignObjectStartAtNewLine=n;};d.setForeignObjectPadding=n=>{u.foreignObjectPadding=n;};d.setForeignObjectIndent=n=>{u.foreignObjectIndent=n;};d.setAlignForeignObject=(n=false)=>{u.alignForeignObject=n;};d.setParameters=n=>{Object.assign(u,n);};d.resetParameters=()=>{Object.assign(u,U);};var E=d;M.default||M;function L(n,t="Op",e="s",r=12,i=true){let s;typeof t=="string"&&typeof e=="string"?s=`${t}/${e}`:typeof t=="string"?s=t:s="";let a=i?" ":"";return n>=10**24?`${(n/10**24).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}Y${s}`.padStart(r," "):n>=10**18?`${(n/10**18).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}E${s}`.padStart(r," "):n>=10**15?`${(n/10**15).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}P${s}`.padStart(r," "):n>=10**12?`${(n/10**12).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}T${s}`.padStart(r," "):n>=10**9?`${(n/10**9).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}G${s}`.padStart(r," "):n>=10**6?`${(n/10**6).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}M${s}`.padStart(r," "):n>=10**3?`${(n/10**3).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}k${s}`.padStart(r," "):`${n.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}${s}`.padStart(r," ")}function I(n,t=8){return n>=3600000000000000n?`${(Number(n)/36e14).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}h`.padStart(t," "):n>=60000000000n?`${(Number(n)/6e10).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}m`.padStart(t," "):n>=1000000000n?`${(Number(n)/1e9).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}s`.padStart(t," "):n>=1000000n?`${(Number(n)/1e6).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}ms`.padStart(t," "):n>=1000n?`${(Number(n)/1e3).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}\xB5s`.padStart(t," "):`${n.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}ns`.padStart(t," ")}function O(n,t=7){return `${n.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}%`.padStart(t," ")}var b=class{benchmarkDuration;results={};constructor(t=256){this.benchmarkDuration=t;}benchmark=(t,e)=>{let i=process.hrtime.bigint(),s=0,a=0,o=0,c=0n,m=0n,g=0n,l=BigInt(this.benchmarkDuration)*1000000n;for(let y=0;y<Number.POSITIVE_INFINITY;y++)if(m=process.hrtime.bigint(),t(),g=process.hrtime.bigint(),c+=g-m,g-i>=l){a=Number(c)/y,s=1e9/a,o=Number(g-i)/a;break}this.results[e]={operationsPerSecond:s,avgExecutionTime:a,operations:o};};print=(t,e=true)=>{let r=t||"RESULTS";E.info(`
5
- ${r.toUpperCase()}:`),E.info("=".repeat(r.length+1));let i=0;for(let a of Object.keys(this.results))a.length>i&&(i=a.length);let s=Object.entries(this.results).sort((a,o)=>o[1].operationsPerSecond-a[1].operationsPerSecond);for(let[a,o]of s){let c=s[0][1].operationsPerSecond,m=o.operationsPerSecond/c*100,g=`>> ${a} `.padEnd(i+4,"\u2550"),l=`AVG TIME: ${I(o.avgExecutionTime)}`,y=`OPS: ${L(o.operationsPerSecond)}`,_=`PERCENTAGE: ${O(m)}`,A=`${g}\u2550> ${l} | ${y} | ${_}`,x=10;m>=90?E.debug(A+"(fastest)".padStart(x," ")):m>=60?E.info(A+"(fast)".padStart(x," ")):m>=30?E.warn(A+"(medium)".padStart(x," ")):m>=10?E.error(A+"(slow)".padStart(x," ")):E.error(A+"(slowest)".padStart(x," "));}e&&(this.results={});}};function G(n,t,e,r,i){return i?t:{status:n,marker:t,timestamp:new Date().toISOString(),version:{raw:e??"unavailable",formatted:e?`v${e}`:"unavailable"},message:r??"The application is running smoothly."}}function z(n,t){let e=Buffer.from(n,"base64");if(e.length!==32)throw new Error(`Invalid key length: expected 32 bytes, got ${e.length}`);let r=randomBytes(12).toString("base64"),i=createCipheriv("aes-256-gcm",e,Buffer.from(r,"base64")),s=i.update(t,"utf8","base64");s+=i.final("base64");let a=i.getAuthTag(),o=`${r}.${s}.${a.toString("base64")}`;return {iv:r,ciphertext:s,tag:a,payload:o}}function $(n,t,e,r){try{let i=createDecipheriv("aes-256-gcm",Buffer.from(n,"base64"),Buffer.from(t,"base64"));i.setAuthTag(Buffer.from(r,"base64"));let s=i.update(e,"base64","utf8");return s+=i.final("utf8"),s}catch{return null}}function X(n,t){let e=t.split(".");if(e.length!==3)throw new Error("Invalid payload format");let[r,i,s]=e;return $(n,r,i,s)}var Z={aes256Gcm:{encrypt:z,decrypt:$,decryptPayload:X}};function h(n,t){return `[CyBuffer - ${n}] ${t}`}var T=(()=>{let n=new Uint8Array(4);return new Uint32Array(n.buffer)[0]=65280,n[0]===255?"BE":"LE"})(),S=class n{platformEndianness;arrayBuffer;array;offset;length;constructor(t,e){if(t<0)throw new RangeError(h("constructor",`Invalid buffer length: '${t}'.`));if(!Number.isInteger(t))throw new TypeError(h("constructor",`Invalid buffer length: '${t}'.`));return this.platformEndianness=T,e?(this.arrayBuffer=e.arrayBuffer,this.offset=e.offset??0,this.length=e.length??t,this.array=new Uint8Array(this.arrayBuffer,this.offset,this.length)):(this.arrayBuffer=new ArrayBuffer(t),this.offset=0,this.length=t,this.array=new Uint8Array(this.arrayBuffer)),this._proxy}getPlatformEndianness=()=>T;normalizeEndianness=t=>this.platformEndianness==="BE"?t==="LE"?"BE":"LE":t;check=(t,e)=>{if(Number.isNaN(t)||Number.isNaN(e))throw new TypeError(h("check",`Invalid offset: '${t}' or length: '${e}'.`));if(t<0||t>=this.length)throw new RangeError(h("check",`Invalid offset: '${t}', it must be >= 0 & < ${this.length}.`));if(e<1||e>this.length)throw new RangeError(h("check",`Invalid length: '${e}', it must be > 0 & <= ${this.length}.`));if(t+e>this.length)throw new RangeError(h("check",`Invalid offset (${t}) + length (${e}): '${t+e}', it must be <= ${this.length}.`));if(t%1!==0)throw new RangeError(h("check",`Invalid offset alignment: '${t}'.`));if(e%1!==0)throw new RangeError(h("check",`Invalid length alignment: '${e}'.`));return this};static alloc=(t,e)=>{let r=new n(t);return e!==void 0&&r.fill(e),r};static fromHexString=t=>{t.startsWith("0x")&&(t=t.slice(2));let e=Math.ceil(t.length/2),r=new n(e);return r.writeHexString(t,0,e),r};static fromUtf8String=t=>{let e=new TextEncoder().encode(t),r=new n(e.byteLength);return r.array.set(e),r};static fromString=(t,e="utf8")=>{if(e==="utf8"){let r=new TextEncoder().encode(t),i=new n(r.byteLength);return i.array.set(r),i}if(e==="hex"){let r=Math.ceil(t.length/2),i=new n(r);return i.writeHexString(t,0,r),i}throw new TypeError(h("fromString",`Invalid encoding: '${e}'.`))};static fromBits=(t,e=true)=>{let r=new n(Math.ceil(t.length/8));return r.writeBits(t,0,t.length,e),r};static fromUint8Array=t=>{let e=new n(t.byteLength);return e.writeUint8Array(t,0,t.byteLength),e};static fromUint16Array=t=>{let e=new n(t.byteLength);return e.writeUint16Array(t,0,t.byteLength),e};static fromUint32Array=t=>{let e=new n(t.byteLength);return e.writeUint32Array(t,0,t.byteLength),e};static fromBigInt=(t,e)=>{if(t<0n)throw new RangeError(h("fromBigInt",`Invalid big integer: '${t}'.`));let r=Math.ceil(t.toString(16).length/2),i=new n(r);return i.writeBigInt(t,0,r,e),i};static fromRange=(t,e)=>{let r=new n(e-t);return r.writeRange(t,e),r};get _proxy(){return new Proxy(this,{get:(t,e)=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return this.check(r,1),t.array[r]}return t[e]},set:(t,e,r)=>{if(typeof e=="string"){let i=Number(e);if(!Number.isNaN(i)){let s=Number(r);if(Number.isNaN(s))throw new TypeError(h("proxy",`Invalid value: '${r}'.`));if(s<0||s>255)throw new RangeError(h("proxy",`Value is out of bounds: '${r}'.`));return this.check(i,1),t.array[i]=r,true}}return t[e]=r,true}})}*[Symbol.iterator](){let t=0;for(;t<this.length;)yield this.array[t++];}*entries(){for(let t=0;t<this.length;t++)yield [t,this.array[t]];}writeHexString=(t,e=0,r=t.length/2)=>{if(r===0)throw new RangeError(h("writeHexString",`Invalid hexadecimal string length: '${r}'.`));if(r%1!==0)throw new RangeError(h("writeHexString",`Invalid hexadecimal string length: '${r}'.`));if(t.length%2!==0)throw new RangeError(h("writeHexString",`Invalid hexadecimal string length: '${t.length}'.`));t.startsWith("0x")&&(r===t.length/2&&(r=(t.length-2)/2),t=t.slice(2)),this.check(e,r);for(let i=0;i<r;i++){let s=t.charCodeAt(i*2)|32,a=t.charCodeAt(i*2+1)|32;this.array[e+i]=s-(s>57?87:48)<<4|a-(a>57?87:48);}return this};writeUtf8String=(t,e=0,r=new TextEncoder().encode(t).byteLength)=>{if(r===0)throw new RangeError(h("writeUtf8String",`Invalid UTF-8 string length: '${r}'.`));let i=new TextEncoder().encode(t);return this.check(e,r),this.array.set(i.subarray(0,r),e),this};writeString=(t,e="utf8",r=0,i)=>{if(e==="utf8"){let s=new TextEncoder().encode(t),a=i??s.byteLength;return this.check(r,a),this.array.set(s.subarray(0,a),r),this}if(e==="hex")return this.writeHexString(t,r,Math.ceil((i??t.length)/2)),this;throw new TypeError(h("writeString",`Invalid encoding: '${e}'.`))};writeBit=(t,e=0,r=true,i=true)=>{if(t<0||t>1)throw new RangeError(h("writeBit",`Value is out of bounds: '${t}'.`));let s=Math.floor(e/8);i&&this.check(s,1);let a=r?7-e%8:e%8;return t===1?this.array[s]|=1<<a:this.array[s]&=~(1<<a),this};writeUint8=(t,e=0,r=true)=>{if(t<0||t>255)throw new RangeError(h("writeUint8",`Value is out of bounds: '${t}'.`));return r&&this.check(e,1),t>>>=0,this.array[e]=t,this};writeUint16LE=(t,e=0,r=true,i=true)=>{if(t<0||t>65535)throw new RangeError(h("writeUint16LE",`Value is out of bounds: '${t}'.`));if(r&&e%2!==0)throw new RangeError(h("writeUint16LE",`Invalid offset alignment: '${e}' (%2).`));return i&&this.check(e,2),t>>>=0,this.array[e]=t&255,this.array[e+1]=t>>8&255,this};writeUint16BE=(t,e=0,r=true,i=true)=>{if(t<0||t>65535)throw new RangeError(h("writeUint16BE",`Value is out of bounds: '${t}'.`));if(r&&e%2!==0)throw new RangeError(h("writeUint16BE",`Invalid offset alignment: '${e}' (%2).`));return i&&this.check(e,2),t>>>=0,this.array[e]=t>>8&255,this.array[e+1]=t&255,this};writeUint16=(t,e=0,r=this.platformEndianness,i=true,s=true)=>this.normalizeEndianness(r)==="LE"?(this.writeUint16LE(t,e,i,s),this):(this.writeUint16BE(t,e,i,s),this);writeUint32LE=(t,e=0,r=true,i=true)=>{if(t<0||t>4294967295)throw new RangeError(h("writeUint32LE",`Value is out of bounds: '${t}'.`));if(r&&e%4!==0)throw new RangeError(h("writeUint32LE",`Invalid offset alignment: '${e}' (%4).`));return i&&this.check(e,4),t>>>=0,this.array[e]=t&255,this.array[e+1]=t>>8&255,this.array[e+2]=t>>16&255,this.array[e+3]=t>>24&255,this};writeUint32BE=(t,e=0,r=true,i=true)=>{if(t<0||t>4294967295)throw new RangeError(h("writeUint32BE",`Value is out of bounds: '${t}'.`));if(r&&e%4!==0)throw new RangeError(h("writeUint32BE",`Invalid offset alignment: '${e}' (%4).`));return i&&this.check(e,4),t>>>=0,this.array[e]=t>>24&255,this.array[e+1]=t>>16&255,this.array[e+2]=t>>8&255,this.array[e+3]=t&255,this};writeUint32=(t,e=0,r=this.platformEndianness,i=true,s=true)=>this.normalizeEndianness(r)==="LE"?(this.writeUint32LE(t,e,i,s),this):(this.writeUint32BE(t,e,i,s),this);writeBits=(t,e=0,r=t.length,i=true)=>{if(!t||!Array.isArray(t))throw new TypeError(h("writeBits",`Invalid array of bits: '${t}'.`));let s=Math.floor(e/8),a=Math.ceil(r/8);this.check(s,a);for(let o=0;o<r;o++)this.writeBit(t[o],e+o,i,false);return this};writeUint8Array=(t,e=0,r=t.byteLength,i=0)=>{if(!t||!(t instanceof Uint8Array))throw new TypeError(h("writeUint8Array",`Invalid Uint8Array: '${t}'.`));return this.check(e,r),this.array.set(t.subarray(i,r),e),this};writeUint16Array=(t,e=0,r=t.byteLength,i=0,s=this.platformEndianness,a=true)=>{if(!t||!(t instanceof Uint16Array))throw new TypeError(h("writeUint16Array",`Invalid Uint16Array: '${t}'.`));if(a&&e%2!==0)throw new RangeError(h("writeUint16Array",`Invalid offset alignment: '${e}' (%2).`));if(this.check(e,r),this.normalizeEndianness(s)==="LE"){for(let o=i;o<r;o+=2)this.writeUint16LE(t[o/2],e-i+o,a,false);return this}for(let o=i;o<r;o+=2)this.writeUint16BE(t[o/2],e-i+o,a,false);return this};writeUint32Array=(t,e=0,r=t.byteLength,i=0,s=this.platformEndianness,a=true)=>{if(!t||!(t instanceof Uint32Array))throw new TypeError(h("writeUint32Array",`Invalid Uint32Array: '${t}'.`));if(a&&e%4!==0)throw new RangeError(h("writeUint32Array",`Invalid offset alignment: '${e}' (%4).`));if(this.check(e,r),this.normalizeEndianness(s)==="LE"){for(let o=i;o<r;o+=4)this.writeUint32LE(t[o/4],e-i+o,a,false);return this}for(let o=i;o<r;o+=4)this.writeUint32BE(t[o/4],e-i+o,a,false);return this};writeBigIntLE=(t,e=0,r=Math.ceil(t.toString(16).length/2))=>{if(t<0n)throw new RangeError(h("writeBigIntLE",`Invalid big integer value: '${t}'.`));this.check(e,r);for(let i=0;i<r;i++)this.array[e+i]=Number(t&BigInt(255)),t>>=BigInt(8);return this};writeBigIntBE=(t,e=0,r=Math.ceil(t.toString(16).length/2))=>{if(t<0n)throw new RangeError(h("writeBigIntBE",`Invalid big integer value: '${t}'.`));this.check(e,r);for(let i=r-1;i>=0;i--)this.array[e+i]=Number(t&BigInt(255)),t>>=BigInt(8);return this};writeBigInt=(t,e=0,r=Math.ceil(t.toString(16).length/2),i=this.platformEndianness)=>this.normalizeEndianness(i)==="LE"?(this.writeBigIntLE(t,e,r),this):(this.writeBigIntBE(t,e,r),this);writeRange=(t,e,r=0)=>{if(t<0||t>255)throw new RangeError(h("writeRange",`Invalid start value: '${t}'.`));if(e<0||e>255)throw new RangeError(h("writeRange",`Invalid end value: '${e}'.`));let i=e-t;this.check(r,i);for(let s=0;s<i;s++)this.array[r+s]=t+s;return this};readHexStringLE=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),Buffer.from(this.arrayBuffer,t,e).toString("hex").toUpperCase());readHexStringBE=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),Buffer.from(this.arrayBuffer,t,e).toString("hex").toUpperCase().match(/.{2}/g).reverse().join(""));readHexString=(t=0,e=this.length-t,r=this.platformEndianness,i=true)=>(i&&this.check(t,e),this.normalizeEndianness(r)==="LE"?this.readHexStringLE(t,e,false):this.readHexStringBE(t,e,false));readUtf8String=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),Buffer.from(this.arrayBuffer,t,e).toString("utf8"));readBit=(t=0,e=true,r=true)=>{let i=Math.floor(t/8);r&&this.check(i,1);let s=e?7-t%8:t%8;return (this.array[i]&1<<s)===0?0:1};readUint8=(t=0,e=true)=>(e&&this.check(t,1),this.array[t]);readUint16LE=(t=0,e=true,r=true)=>{if(e&&t%2!==0)throw new RangeError(h("readUint16LE",`Invalid offset alignment: '${t}' (%2).`));return r&&this.check(t,2),(this.array[t]|this.array[t+1]<<8)>>>0};readUint16BE=(t=0,e=true,r=true)=>{if(e&&t%2!==0)throw new RangeError(h("readUint16BE",`Invalid offset alignment: '${t}' (%2).`));return r&&this.check(t,2),(this.array[t]<<8|this.array[t+1])>>>0};readUint16=(t=0,e=this.platformEndianness,r=true,i=true)=>this.normalizeEndianness(e)==="LE"?this.readUint16LE(t,r,i):this.readUint16BE(t,r,i);readUint32LE=(t=0,e=true,r=true)=>{if(e&&t%4!==0)throw new RangeError(h("readUint32LE",`Invalid offset alignment: '${t}' (%4).`));return r&&this.check(t,4),(this.array[t]|this.array[t+1]<<8|this.array[t+2]<<16|this.array[t+3]<<24)>>>0};readUint32BE=(t=0,e=true,r=true)=>{if(e&&t%4!==0)throw new RangeError(h("readUint32BE",`Invalid offset alignment: '${t}' (%4).`));return r&&this.check(t,4),(this.array[t]<<24|this.array[t+1]<<16|this.array[t+2]<<8|this.array[t+3])>>>0};readUint32=(t=0,e=this.platformEndianness,r=true,i=true)=>this.normalizeEndianness(e)==="LE"?this.readUint32LE(t,r,i):this.readUint32BE(t,r,i);readBits=(t=0,e=this.length*8-t*8,r=true,i=true)=>{if(e===0)return [];let s=Math.floor(t/8),a=Math.ceil((t+e)/8)-s;i&&this.check(s,a);let o=[];for(let c=0;c<e;c++)o.push(this.readBit(t+c,r,false));return o};readUint8Array=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),new Uint8Array(this.arrayBuffer,t??this.offset,e??this.length));readUint16Array=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),new Uint16Array(this.arrayBuffer,t??this.offset,e?e/2:this.length/2));readUint32Array=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),new Uint32Array(this.arrayBuffer,t??this.offset,e?e/4:this.length/4));readBigIntLE=(t=0,e=this.length-t,r=true)=>{r&&this.check(t,e);let i=0n;for(let s=e-1;s>=0;s--)i=i<<8n|BigInt(this.array[t+s]);return i};readBigIntBE=(t=0,e=this.length-t,r=true)=>{r&&this.check(t,e);let i=0n;for(let s=0;s<e;s++)i=i<<8n|BigInt(this.array[t+s]);return i};readBigInt=(t=0,e=this.length-t,r=this.platformEndianness,i=true)=>this.normalizeEndianness(r)==="LE"?this.readBigIntLE(t,e,i):this.readBigIntBE(t,e,i);toHexString=(t=false,e=this.platformEndianness)=>{let r=Buffer.from(this.arrayBuffer,this.offset,this.length).toString("hex").toUpperCase();return this.normalizeEndianness(e)==="BE"&&(r=r.match(/.{2}/g)?.reverse().join("")??""),t?`0x${r}`:r};toUtf8String=()=>Buffer.from(this.arrayBuffer,this.offset,this.length).toString("utf8");toString=(t="hex",e=false)=>t==="utf8"?this.toUtf8String():this.toHexString(e);toBits=(t=true)=>{let e=this.length*8,r=new Array(e);for(let i=0;i<e;i++)r[i]=this.readBit(i,t);return r};toUint8Array=()=>new Uint8Array(this.arrayBuffer,this.offset,this.length);toUint16Array=()=>new Uint16Array(this.arrayBuffer,this.offset,this.length/2);toUint32Array=()=>new Uint32Array(this.arrayBuffer,this.offset,this.length/4);toBigInt=(t=this.platformEndianness)=>this.normalizeEndianness(t)==="LE"?this.readBigIntLE():this.readBigIntBE();equals=t=>{if(this.length!==t.length)return false;for(let e=0;e<this.length;e++)if(this.array[e]!==t[e])return false;return true};isEmpty=()=>{for(let t=0;t<this.length;t++)if(this.array[t]!==0)return false;return true};isFull=()=>{for(let t=0;t<this.length;t++)if(this.array[t]!==255)return false;return true};randomFill=(t=0,e=this.length-t)=>{this.check(t,e);for(let r=0;r<e;r++)this.array[t+r]=Math.floor(Math.random()*256);};safeRandomFill=(t=0,e=this.length)=>randomFillSync(this.array,t,e);copy=(t=0,e=this.length)=>{this.check(t,e);let r=new n(e);return r.array.set(this.array.subarray(t,t+e)),r};subarray=(t=0,e=this.length)=>(this.check(t,e),new n(e,{arrayBuffer:this.arrayBuffer,offset:t,length:e}));swap=(t=0,e=this.length,r=4)=>{if(r<2)throw new RangeError(h("swap",`Invalid word length: '${r}'.`));if(r%2!==0)throw new RangeError(h("swap",`Invalid word length alignment: '${r}'.`));this.check(t,e);for(let i=t;i<t+e;i+=r)for(let s=0;s<r/2;s++){let a=this.array[i+s];this.array[i+s]=this.array[i+r-s-1],this.array[i+r-s-1]=a;}return this};partialReverse=(t=0,e=this.length)=>{this.check(t,e);let r=Math.floor(e/2),i=t+e;for(let s=0;s<r;s++){let a=s+t,o=i-s-1,c=this.array[a];this.array[a]=this.array[o],this.array[o]=c;}return this};reverse=()=>(this.array.reverse(),this);rotateLeft=()=>{let t=this.array[0];for(let e=0;e<this.length-1;e++)this.array[e]=this.array[e+1];return this.array[this.length-1]=t,this};rotateRight=()=>{let t=this.array[this.length-1];for(let e=this.length-1;e>0;e--)this.array[e]=this.array[e-1];return this.array[0]=t,this};shiftLeft=(t=0,e=this.length,r=1)=>{this.check(t,e);for(let i=t;i<t+e-r;i++)this.array[i]=this.array[i+r];for(let i=0;i<r;i++)this.array[t+e-i-1]=0;return this};shiftRight=(t=0,e=this.length,r=1)=>{this.check(t,e);for(let i=t+e-1;i>=t+r;i--)this.array[i]=this.array[i-r];for(let i=0;i<r;i++)this.array[t+i]=0;return this};fill=(t,e=0,r=this.length)=>{if(t<0||t>255)throw new RangeError(h("fill",`Invalid value: '${t}'.`));return this.check(e,r),this.array.fill(t,e,e+r),this};clear=(t=0,e=this.length)=>(this.check(t,e),this.array.fill(0,t,t+e),this)};function Y(n){let t=new Headers;for(let[e,r]of Object.entries(n))if(Array.isArray(r))for(let i of r)t.append(e,i);else r!==void 0&&t.append(e,r);return t}function K(){switch(process.platform){case "win32":return process.env.COMPUTERNAME;case "darwin":return execSync("scutil --get ComputerName").toString().trim();case "linux":{let n=execSync("hostnamectl --pretty").toString().trim();return n===""?hostname():n}default:return hostname()}}var w={BAD_REQUEST:{status:400,name:"BadRequest",message:"Bad request.",data:null},UNAUTHORIZED:{status:401,name:"Unauthorized",message:"Unauthorized.",data:null},PAYMENT_REQUIRED:{status:402,name:"PaymentRequired",message:"Payment required.",data:null},FORBIDDEN:{status:403,name:"Forbidden",message:"Forbidden.",data:null},NOT_FOUND:{status:404,name:"NotFound",message:"Not found.",data:null},METHOD_NOT_ALLOWED:{status:405,name:"MethodNotAllowed",message:"Method not allowed.",data:null},REQUEST_TIMEOUT:{status:408,name:"RequestTimeout",message:"Request timed out.",data:null},CONFLICT:{status:409,name:"Conflict",message:"Conflict.",data:null},INTERNAL_SERVER_ERROR:{status:500,name:"InternalServerError",message:"Internal server error.",data:null},BACKEND_FUNCTION_RUNNING_ON_CLIENT:{status:500,name:"BackendFunctionRunningOnClient",message:"A function reserved for the backend is running on the client.",data:null},NOT_IMPLEMENTED:{status:501,name:"NotImplemented",message:"Not implemented.",data:null},BANDWIDTH_LIMIT_EXCEEDED:{status:509,name:"BandwidthLimitExceeded",message:"Bandwidth limit exceeded.",data:null}};var N=class{_req;_res;_read;_write;_update;_replace;_remove;_options;constructor(t,e,r,i){this.setRequestResponse(t,e),this.setMethods(r||{}),this.setOptions(i||{});}setRequestResponse(t,e){this._req=t,this._res=e;}setMethods(t){this._read=t?.read,this._write=t?.write,this._update=t?.update,this._replace=t?.replace,this._remove=t?.remove;}setOptions(t){this._options={...this._options,...t};}_checkDataValidity(t){return t!=null}successResponse(t,e){return this._res.status(t).send({success:true,data:this._checkDataValidity(e)?e:null})}errorResponse(t,e,r){let i={success:false,message:r||t.message,error:this._checkDataValidity(e)?{...t,data:e}:t};return this._res.status(t.status).send(i)}async _executeMethod(t,e){return typeof t=="function"?(await t(e),true):(await t.method(e),true)}async run(){let t={req:this._req,res:this._res,wrapper:this};try{switch(this._req.method){case "GET":if(this._read)return await this._executeMethod(this._read,t);break;case "POST":if(this._write)return await this._executeMethod(this._write,t);break;case "PATCH":if(this._update)return await this._executeMethod(this._update,t);break;case "PUT":if(this._replace)return await this._executeMethod(this._replace,t);break;case "DELETE":if(this._remove)return await this._executeMethod(this._remove,t);break;default:return this.errorResponse(w.METHOD_NOT_ALLOWED)}}catch(e){return this.errorResponse(w.INTERNAL_SERVER_ERROR,e)}}};var R=class{_req;_res;_read;_write;_update;_replace;_remove;_options;constructor(t,e,r,i){this.setRequestResponse(t,e),this.setMethods(r||{}),this.setOptions(i||{});}setRequestResponse(t,e){this._req=t,this._res=e;}setMethods(t){this._read=t?.read,this._write=t?.write,this._update=t?.update,this._replace=t?.replace,this._remove=t?.remove;}setOptions(t){this._options={...this._options,...t};}_checkDataValidity(t){return t!=null}successResponse(t,e){return this._res.status(t).send({success:true,data:this._checkDataValidity(e)?e:null})}errorResponse(t,e,r){let i={success:false,message:r||t.message,error:this._checkDataValidity(e)?{...t,data:e}:t};return this._res.status(t.status).send(i)}hasRole(t,e){return t.roles?.includes(e)}hasSomeRoles(t,e){return e.some(r=>t.roles?.includes(r))}hasAllRoles(t,e){return e.every(r=>t.roles?.includes(r))}checkAuthOptions(t,e){return e.requireAuth&&!t?(this.errorResponse(w.UNAUTHORIZED),false):e.hasRole&&(!t||!this.hasRole(t.user,e.hasRole))?(this.errorResponse(w.UNAUTHORIZED),false):e.hasSomeRoles&&(!t||!this.hasSomeRoles(t.user,e.hasSomeRoles))?(this.errorResponse(w.UNAUTHORIZED),false):e.hasAllRoles&&(!t||!this.hasAllRoles(t.user,e.hasAllRoles))?(this.errorResponse(w.UNAUTHORIZED),false):true}async _executeMethod(t,e){return typeof t=="function"?(await t(e),true):t.authOptions&&!this.checkAuthOptions(e.session,t.authOptions)?false:(await t.method(e),true)}async run(){let t=this._options.authFunction?await this._options.authFunction(this._req,this._res):null;if(!this.checkAuthOptions(t,this._options))return;let r={req:this._req,res:this._res,session:t,wrapper:this};try{switch(this._req.method){case "GET":if(this._read)return await this._executeMethod(this._read,r);break;case "POST":if(this._write)return await this._executeMethod(this._write,r);break;case "PATCH":if(this._update)return await this._executeMethod(this._update,r);break;case "PUT":if(this._replace)return await this._executeMethod(this._replace,r);break;case "DELETE":if(this._remove)return await this._executeMethod(this._remove,r);break;default:return this.errorResponse(w.METHOD_NOT_ALLOWED)}}catch(i){return this.errorResponse(w.INTERNAL_SERVER_ERROR,i)}}};export{b as Bench,S as CyBuffer,N as NextApiWrapper,R as NextAuthApiWrapper,Y as convertNodeHeadersToWebHeaders,Z as crypto,G as generateCGASStatus,K as getHostname,E as serverLogger};//# sourceMappingURL=backend.js.map
4
+ `));let g=a(`${o}${c}${n.msg}${d}`);return s&&(g=s(g)),console.log(g),""}var G=H({crlf:false,colorize:true,sync:true,include:"",messageFormat:(n,t,e,{colors:r})=>j(n,r)}),m=C({level:u.level},G);m.setLevel=n=>{u.level=n,m.level=n;};m.setShowLevel=n=>{u.showLevel=n;};m.setShowTimestamp=n=>{u.showTimestamp=n;};m.setForeignObjectStartAtNewLine=n=>{u.foreignObjectStartAtNewLine=n;};m.setForeignObjectPadding=n=>{u.foreignObjectPadding=n;};m.setForeignObjectIndent=n=>{u.foreignObjectIndent=n;};m.setAlignForeignObject=(n=false)=>{u.alignForeignObject=n;};m.setParameters=n=>{Object.assign(u,n);};m.resetParameters=()=>{Object.assign(u,U);};var w=m;var W={NO_BODY_HTTP_STATUSES:[204,304]},b=W;O.default||O;function L(n,t="Op",e="s",r=12,i=true){let s;typeof t=="string"&&typeof e=="string"?s=`${t}/${e}`:typeof t=="string"?s=t:s="";let a=i?" ":"";return n>=10**24?`${(n/10**24).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}Y${s}`.padStart(r," "):n>=10**18?`${(n/10**18).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}E${s}`.padStart(r," "):n>=10**15?`${(n/10**15).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}P${s}`.padStart(r," "):n>=10**12?`${(n/10**12).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}T${s}`.padStart(r," "):n>=10**9?`${(n/10**9).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}G${s}`.padStart(r," "):n>=10**6?`${(n/10**6).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}M${s}`.padStart(r," "):n>=10**3?`${(n/10**3).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}k${s}`.padStart(r," "):`${n.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${a}${s}`.padStart(r," ")}function I(n,t=8){return n>=3600000000000000n?`${(Number(n)/36e14).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}h`.padStart(t," "):n>=60000000000n?`${(Number(n)/6e10).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}m`.padStart(t," "):n>=1000000000n?`${(Number(n)/1e9).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}s`.padStart(t," "):n>=1000000n?`${(Number(n)/1e6).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}ms`.padStart(t," "):n>=1000n?`${(Number(n)/1e3).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}\xB5s`.padStart(t," "):`${n.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}ns`.padStart(t," ")}function T(n,t=7){return `${n.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}%`.padStart(t," ")}var S=class{benchmarkDuration;results={};constructor(t=256){this.benchmarkDuration=t;}benchmark=(t,e)=>{let i=process.hrtime.bigint(),s=0,a=0,o=0,c=0n,d=0n,g=0n,l=BigInt(this.benchmarkDuration)*1000000n;for(let y=0;y<Number.POSITIVE_INFINITY;y++)if(d=process.hrtime.bigint(),t(),g=process.hrtime.bigint(),c+=g-d,g-i>=l){a=Number(c)/y,s=1e9/a,o=Number(g-i)/a;break}this.results[e]={operationsPerSecond:s,avgExecutionTime:a,operations:o};};print=(t,e=true)=>{let r=t||"RESULTS";w.info(`
5
+ ${r.toUpperCase()}:`),w.info("=".repeat(r.length+1));let i=0;for(let a of Object.keys(this.results))a.length>i&&(i=a.length);let s=Object.entries(this.results).sort((a,o)=>o[1].operationsPerSecond-a[1].operationsPerSecond);for(let[a,o]of s){let c=s[0][1].operationsPerSecond,d=o.operationsPerSecond/c*100,g=`>> ${a} `.padEnd(i+4,"\u2550"),l=`AVG TIME: ${I(o.avgExecutionTime)}`,y=`OPS: ${L(o.operationsPerSecond)}`,_=`PERCENTAGE: ${T(d)}`,A=`${g}\u2550> ${l} | ${y} | ${_}`,x=10;d>=90?w.debug(A+"(fastest)".padStart(x," ")):d>=60?w.info(A+"(fast)".padStart(x," ")):d>=30?w.warn(A+"(medium)".padStart(x," ")):d>=10?w.error(A+"(slow)".padStart(x," ")):w.error(A+"(slowest)".padStart(x," "));}e&&(this.results={});}};function q(n,t,e,r,i){return i?t:{status:n,marker:t,timestamp:new Date().toISOString(),version:{raw:e??"unavailable",formatted:e?`v${e}`:"unavailable"},message:r??"The application is running smoothly."}}function Y(n,t){let e=Buffer.from(n,"base64");if(e.length!==32)throw new Error(`Invalid key length: expected 32 bytes, got ${e.length}`);let r=randomBytes(12).toString("base64"),i=createCipheriv("aes-256-gcm",e,Buffer.from(r,"base64")),s=i.update(t,"utf8","base64");s+=i.final("base64");let a=i.getAuthTag(),o=`${r}.${s}.${a.toString("base64")}`;return {iv:r,ciphertext:s,tag:a,payload:o}}function $(n,t,e,r){try{let i=createDecipheriv("aes-256-gcm",Buffer.from(n,"base64"),Buffer.from(t,"base64"));i.setAuthTag(Buffer.from(r,"base64"));let s=i.update(e,"base64","utf8");return s+=i.final("utf8"),s}catch{return null}}function Z(n,t){let e=t.split(".");if(e.length!==3)throw new Error("Invalid payload format");let[r,i,s]=e;return $(n,r,i,s)}var Q={aes256Gcm:{encrypt:Y,decrypt:$,decryptPayload:Z}};function h(n,t){return `[CyBuffer - ${n}] ${t}`}var k=(()=>{let n=new Uint8Array(4);return new Uint32Array(n.buffer)[0]=65280,n[0]===255?"BE":"LE"})(),N=class n{platformEndianness;arrayBuffer;array;offset;length;constructor(t,e){if(t<0)throw new RangeError(h("constructor",`Invalid buffer length: '${t}'.`));if(!Number.isInteger(t))throw new TypeError(h("constructor",`Invalid buffer length: '${t}'.`));return this.platformEndianness=k,e?(this.arrayBuffer=e.arrayBuffer,this.offset=e.offset??0,this.length=e.length??t,this.array=new Uint8Array(this.arrayBuffer,this.offset,this.length)):(this.arrayBuffer=new ArrayBuffer(t),this.offset=0,this.length=t,this.array=new Uint8Array(this.arrayBuffer)),this._proxy}getPlatformEndianness=()=>k;normalizeEndianness=t=>this.platformEndianness==="BE"?t==="LE"?"BE":"LE":t;check=(t,e)=>{if(Number.isNaN(t)||Number.isNaN(e))throw new TypeError(h("check",`Invalid offset: '${t}' or length: '${e}'.`));if(t<0||t>=this.length)throw new RangeError(h("check",`Invalid offset: '${t}', it must be >= 0 & < ${this.length}.`));if(e<1||e>this.length)throw new RangeError(h("check",`Invalid length: '${e}', it must be > 0 & <= ${this.length}.`));if(t+e>this.length)throw new RangeError(h("check",`Invalid offset (${t}) + length (${e}): '${t+e}', it must be <= ${this.length}.`));if(t%1!==0)throw new RangeError(h("check",`Invalid offset alignment: '${t}'.`));if(e%1!==0)throw new RangeError(h("check",`Invalid length alignment: '${e}'.`));return this};static alloc=(t,e)=>{let r=new n(t);return e!==void 0&&r.fill(e),r};static fromHexString=t=>{t.startsWith("0x")&&(t=t.slice(2));let e=Math.ceil(t.length/2),r=new n(e);return r.writeHexString(t,0,e),r};static fromUtf8String=t=>{let e=new TextEncoder().encode(t),r=new n(e.byteLength);return r.array.set(e),r};static fromString=(t,e="utf8")=>{if(e==="utf8"){let r=new TextEncoder().encode(t),i=new n(r.byteLength);return i.array.set(r),i}if(e==="hex"){let r=Math.ceil(t.length/2),i=new n(r);return i.writeHexString(t,0,r),i}throw new TypeError(h("fromString",`Invalid encoding: '${e}'.`))};static fromBits=(t,e=true)=>{let r=new n(Math.ceil(t.length/8));return r.writeBits(t,0,t.length,e),r};static fromUint8Array=t=>{let e=new n(t.byteLength);return e.writeUint8Array(t,0,t.byteLength),e};static fromUint16Array=t=>{let e=new n(t.byteLength);return e.writeUint16Array(t,0,t.byteLength),e};static fromUint32Array=t=>{let e=new n(t.byteLength);return e.writeUint32Array(t,0,t.byteLength),e};static fromBigInt=(t,e)=>{if(t<0n)throw new RangeError(h("fromBigInt",`Invalid big integer: '${t}'.`));let r=Math.ceil(t.toString(16).length/2),i=new n(r);return i.writeBigInt(t,0,r,e),i};static fromRange=(t,e)=>{let r=new n(e-t);return r.writeRange(t,e),r};get _proxy(){return new Proxy(this,{get:(t,e)=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return this.check(r,1),t.array[r]}return t[e]},set:(t,e,r)=>{if(typeof e=="string"){let i=Number(e);if(!Number.isNaN(i)){let s=Number(r);if(Number.isNaN(s))throw new TypeError(h("proxy",`Invalid value: '${r}'.`));if(s<0||s>255)throw new RangeError(h("proxy",`Value is out of bounds: '${r}'.`));return this.check(i,1),t.array[i]=r,true}}return t[e]=r,true}})}*[Symbol.iterator](){let t=0;for(;t<this.length;)yield this.array[t++];}*entries(){for(let t=0;t<this.length;t++)yield [t,this.array[t]];}writeHexString=(t,e=0,r=t.length/2)=>{if(r===0)throw new RangeError(h("writeHexString",`Invalid hexadecimal string length: '${r}'.`));if(r%1!==0)throw new RangeError(h("writeHexString",`Invalid hexadecimal string length: '${r}'.`));if(t.length%2!==0)throw new RangeError(h("writeHexString",`Invalid hexadecimal string length: '${t.length}'.`));t.startsWith("0x")&&(r===t.length/2&&(r=(t.length-2)/2),t=t.slice(2)),this.check(e,r);for(let i=0;i<r;i++){let s=t.charCodeAt(i*2)|32,a=t.charCodeAt(i*2+1)|32;this.array[e+i]=s-(s>57?87:48)<<4|a-(a>57?87:48);}return this};writeUtf8String=(t,e=0,r=new TextEncoder().encode(t).byteLength)=>{if(r===0)throw new RangeError(h("writeUtf8String",`Invalid UTF-8 string length: '${r}'.`));let i=new TextEncoder().encode(t);return this.check(e,r),this.array.set(i.subarray(0,r),e),this};writeString=(t,e="utf8",r=0,i)=>{if(e==="utf8"){let s=new TextEncoder().encode(t),a=i??s.byteLength;return this.check(r,a),this.array.set(s.subarray(0,a),r),this}if(e==="hex")return this.writeHexString(t,r,Math.ceil((i??t.length)/2)),this;throw new TypeError(h("writeString",`Invalid encoding: '${e}'.`))};writeBit=(t,e=0,r=true,i=true)=>{if(t<0||t>1)throw new RangeError(h("writeBit",`Value is out of bounds: '${t}'.`));let s=Math.floor(e/8);i&&this.check(s,1);let a=r?7-e%8:e%8;return t===1?this.array[s]|=1<<a:this.array[s]&=~(1<<a),this};writeUint8=(t,e=0,r=true)=>{if(t<0||t>255)throw new RangeError(h("writeUint8",`Value is out of bounds: '${t}'.`));return r&&this.check(e,1),t>>>=0,this.array[e]=t,this};writeUint16LE=(t,e=0,r=true,i=true)=>{if(t<0||t>65535)throw new RangeError(h("writeUint16LE",`Value is out of bounds: '${t}'.`));if(r&&e%2!==0)throw new RangeError(h("writeUint16LE",`Invalid offset alignment: '${e}' (%2).`));return i&&this.check(e,2),t>>>=0,this.array[e]=t&255,this.array[e+1]=t>>8&255,this};writeUint16BE=(t,e=0,r=true,i=true)=>{if(t<0||t>65535)throw new RangeError(h("writeUint16BE",`Value is out of bounds: '${t}'.`));if(r&&e%2!==0)throw new RangeError(h("writeUint16BE",`Invalid offset alignment: '${e}' (%2).`));return i&&this.check(e,2),t>>>=0,this.array[e]=t>>8&255,this.array[e+1]=t&255,this};writeUint16=(t,e=0,r=this.platformEndianness,i=true,s=true)=>this.normalizeEndianness(r)==="LE"?(this.writeUint16LE(t,e,i,s),this):(this.writeUint16BE(t,e,i,s),this);writeUint32LE=(t,e=0,r=true,i=true)=>{if(t<0||t>4294967295)throw new RangeError(h("writeUint32LE",`Value is out of bounds: '${t}'.`));if(r&&e%4!==0)throw new RangeError(h("writeUint32LE",`Invalid offset alignment: '${e}' (%4).`));return i&&this.check(e,4),t>>>=0,this.array[e]=t&255,this.array[e+1]=t>>8&255,this.array[e+2]=t>>16&255,this.array[e+3]=t>>24&255,this};writeUint32BE=(t,e=0,r=true,i=true)=>{if(t<0||t>4294967295)throw new RangeError(h("writeUint32BE",`Value is out of bounds: '${t}'.`));if(r&&e%4!==0)throw new RangeError(h("writeUint32BE",`Invalid offset alignment: '${e}' (%4).`));return i&&this.check(e,4),t>>>=0,this.array[e]=t>>24&255,this.array[e+1]=t>>16&255,this.array[e+2]=t>>8&255,this.array[e+3]=t&255,this};writeUint32=(t,e=0,r=this.platformEndianness,i=true,s=true)=>this.normalizeEndianness(r)==="LE"?(this.writeUint32LE(t,e,i,s),this):(this.writeUint32BE(t,e,i,s),this);writeBits=(t,e=0,r=t.length,i=true)=>{if(!t||!Array.isArray(t))throw new TypeError(h("writeBits",`Invalid array of bits: '${t}'.`));let s=Math.floor(e/8),a=Math.ceil(r/8);this.check(s,a);for(let o=0;o<r;o++)this.writeBit(t[o],e+o,i,false);return this};writeUint8Array=(t,e=0,r=t.byteLength,i=0)=>{if(!t||!(t instanceof Uint8Array))throw new TypeError(h("writeUint8Array",`Invalid Uint8Array: '${t}'.`));return this.check(e,r),this.array.set(t.subarray(i,r),e),this};writeUint16Array=(t,e=0,r=t.byteLength,i=0,s=this.platformEndianness,a=true)=>{if(!t||!(t instanceof Uint16Array))throw new TypeError(h("writeUint16Array",`Invalid Uint16Array: '${t}'.`));if(a&&e%2!==0)throw new RangeError(h("writeUint16Array",`Invalid offset alignment: '${e}' (%2).`));if(this.check(e,r),this.normalizeEndianness(s)==="LE"){for(let o=i;o<r;o+=2)this.writeUint16LE(t[o/2],e-i+o,a,false);return this}for(let o=i;o<r;o+=2)this.writeUint16BE(t[o/2],e-i+o,a,false);return this};writeUint32Array=(t,e=0,r=t.byteLength,i=0,s=this.platformEndianness,a=true)=>{if(!t||!(t instanceof Uint32Array))throw new TypeError(h("writeUint32Array",`Invalid Uint32Array: '${t}'.`));if(a&&e%4!==0)throw new RangeError(h("writeUint32Array",`Invalid offset alignment: '${e}' (%4).`));if(this.check(e,r),this.normalizeEndianness(s)==="LE"){for(let o=i;o<r;o+=4)this.writeUint32LE(t[o/4],e-i+o,a,false);return this}for(let o=i;o<r;o+=4)this.writeUint32BE(t[o/4],e-i+o,a,false);return this};writeBigIntLE=(t,e=0,r=Math.ceil(t.toString(16).length/2))=>{if(t<0n)throw new RangeError(h("writeBigIntLE",`Invalid big integer value: '${t}'.`));this.check(e,r);for(let i=0;i<r;i++)this.array[e+i]=Number(t&BigInt(255)),t>>=BigInt(8);return this};writeBigIntBE=(t,e=0,r=Math.ceil(t.toString(16).length/2))=>{if(t<0n)throw new RangeError(h("writeBigIntBE",`Invalid big integer value: '${t}'.`));this.check(e,r);for(let i=r-1;i>=0;i--)this.array[e+i]=Number(t&BigInt(255)),t>>=BigInt(8);return this};writeBigInt=(t,e=0,r=Math.ceil(t.toString(16).length/2),i=this.platformEndianness)=>this.normalizeEndianness(i)==="LE"?(this.writeBigIntLE(t,e,r),this):(this.writeBigIntBE(t,e,r),this);writeRange=(t,e,r=0)=>{if(t<0||t>255)throw new RangeError(h("writeRange",`Invalid start value: '${t}'.`));if(e<0||e>255)throw new RangeError(h("writeRange",`Invalid end value: '${e}'.`));let i=e-t;this.check(r,i);for(let s=0;s<i;s++)this.array[r+s]=t+s;return this};readHexStringLE=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),Buffer.from(this.arrayBuffer,t,e).toString("hex").toUpperCase());readHexStringBE=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),Buffer.from(this.arrayBuffer,t,e).toString("hex").toUpperCase().match(/.{2}/g).reverse().join(""));readHexString=(t=0,e=this.length-t,r=this.platformEndianness,i=true)=>(i&&this.check(t,e),this.normalizeEndianness(r)==="LE"?this.readHexStringLE(t,e,false):this.readHexStringBE(t,e,false));readUtf8String=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),Buffer.from(this.arrayBuffer,t,e).toString("utf8"));readBit=(t=0,e=true,r=true)=>{let i=Math.floor(t/8);r&&this.check(i,1);let s=e?7-t%8:t%8;return (this.array[i]&1<<s)===0?0:1};readUint8=(t=0,e=true)=>(e&&this.check(t,1),this.array[t]);readUint16LE=(t=0,e=true,r=true)=>{if(e&&t%2!==0)throw new RangeError(h("readUint16LE",`Invalid offset alignment: '${t}' (%2).`));return r&&this.check(t,2),(this.array[t]|this.array[t+1]<<8)>>>0};readUint16BE=(t=0,e=true,r=true)=>{if(e&&t%2!==0)throw new RangeError(h("readUint16BE",`Invalid offset alignment: '${t}' (%2).`));return r&&this.check(t,2),(this.array[t]<<8|this.array[t+1])>>>0};readUint16=(t=0,e=this.platformEndianness,r=true,i=true)=>this.normalizeEndianness(e)==="LE"?this.readUint16LE(t,r,i):this.readUint16BE(t,r,i);readUint32LE=(t=0,e=true,r=true)=>{if(e&&t%4!==0)throw new RangeError(h("readUint32LE",`Invalid offset alignment: '${t}' (%4).`));return r&&this.check(t,4),(this.array[t]|this.array[t+1]<<8|this.array[t+2]<<16|this.array[t+3]<<24)>>>0};readUint32BE=(t=0,e=true,r=true)=>{if(e&&t%4!==0)throw new RangeError(h("readUint32BE",`Invalid offset alignment: '${t}' (%4).`));return r&&this.check(t,4),(this.array[t]<<24|this.array[t+1]<<16|this.array[t+2]<<8|this.array[t+3])>>>0};readUint32=(t=0,e=this.platformEndianness,r=true,i=true)=>this.normalizeEndianness(e)==="LE"?this.readUint32LE(t,r,i):this.readUint32BE(t,r,i);readBits=(t=0,e=this.length*8-t*8,r=true,i=true)=>{if(e===0)return [];let s=Math.floor(t/8),a=Math.ceil((t+e)/8)-s;i&&this.check(s,a);let o=[];for(let c=0;c<e;c++)o.push(this.readBit(t+c,r,false));return o};readUint8Array=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),new Uint8Array(this.arrayBuffer,t??this.offset,e??this.length));readUint16Array=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),new Uint16Array(this.arrayBuffer,t??this.offset,e?e/2:this.length/2));readUint32Array=(t=0,e=this.length-t,r=true)=>(r&&this.check(t,e),new Uint32Array(this.arrayBuffer,t??this.offset,e?e/4:this.length/4));readBigIntLE=(t=0,e=this.length-t,r=true)=>{r&&this.check(t,e);let i=0n;for(let s=e-1;s>=0;s--)i=i<<8n|BigInt(this.array[t+s]);return i};readBigIntBE=(t=0,e=this.length-t,r=true)=>{r&&this.check(t,e);let i=0n;for(let s=0;s<e;s++)i=i<<8n|BigInt(this.array[t+s]);return i};readBigInt=(t=0,e=this.length-t,r=this.platformEndianness,i=true)=>this.normalizeEndianness(r)==="LE"?this.readBigIntLE(t,e,i):this.readBigIntBE(t,e,i);toHexString=(t=false,e=this.platformEndianness)=>{let r=Buffer.from(this.arrayBuffer,this.offset,this.length).toString("hex").toUpperCase();return this.normalizeEndianness(e)==="BE"&&(r=r.match(/.{2}/g)?.reverse().join("")??""),t?`0x${r}`:r};toUtf8String=()=>Buffer.from(this.arrayBuffer,this.offset,this.length).toString("utf8");toString=(t="hex",e=false)=>t==="utf8"?this.toUtf8String():this.toHexString(e);toBits=(t=true)=>{let e=this.length*8,r=new Array(e);for(let i=0;i<e;i++)r[i]=this.readBit(i,t);return r};toUint8Array=()=>new Uint8Array(this.arrayBuffer,this.offset,this.length);toUint16Array=()=>new Uint16Array(this.arrayBuffer,this.offset,this.length/2);toUint32Array=()=>new Uint32Array(this.arrayBuffer,this.offset,this.length/4);toBigInt=(t=this.platformEndianness)=>this.normalizeEndianness(t)==="LE"?this.readBigIntLE():this.readBigIntBE();equals=t=>{if(this.length!==t.length)return false;for(let e=0;e<this.length;e++)if(this.array[e]!==t[e])return false;return true};isEmpty=()=>{for(let t=0;t<this.length;t++)if(this.array[t]!==0)return false;return true};isFull=()=>{for(let t=0;t<this.length;t++)if(this.array[t]!==255)return false;return true};randomFill=(t=0,e=this.length-t)=>{this.check(t,e);for(let r=0;r<e;r++)this.array[t+r]=Math.floor(Math.random()*256);};safeRandomFill=(t=0,e=this.length)=>randomFillSync(this.array,t,e);copy=(t=0,e=this.length)=>{this.check(t,e);let r=new n(e);return r.array.set(this.array.subarray(t,t+e)),r};subarray=(t=0,e=this.length)=>(this.check(t,e),new n(e,{arrayBuffer:this.arrayBuffer,offset:t,length:e}));swap=(t=0,e=this.length,r=4)=>{if(r<2)throw new RangeError(h("swap",`Invalid word length: '${r}'.`));if(r%2!==0)throw new RangeError(h("swap",`Invalid word length alignment: '${r}'.`));this.check(t,e);for(let i=t;i<t+e;i+=r)for(let s=0;s<r/2;s++){let a=this.array[i+s];this.array[i+s]=this.array[i+r-s-1],this.array[i+r-s-1]=a;}return this};partialReverse=(t=0,e=this.length)=>{this.check(t,e);let r=Math.floor(e/2),i=t+e;for(let s=0;s<r;s++){let a=s+t,o=i-s-1,c=this.array[a];this.array[a]=this.array[o],this.array[o]=c;}return this};reverse=()=>(this.array.reverse(),this);rotateLeft=()=>{let t=this.array[0];for(let e=0;e<this.length-1;e++)this.array[e]=this.array[e+1];return this.array[this.length-1]=t,this};rotateRight=()=>{let t=this.array[this.length-1];for(let e=this.length-1;e>0;e--)this.array[e]=this.array[e-1];return this.array[0]=t,this};shiftLeft=(t=0,e=this.length,r=1)=>{this.check(t,e);for(let i=t;i<t+e-r;i++)this.array[i]=this.array[i+r];for(let i=0;i<r;i++)this.array[t+e-i-1]=0;return this};shiftRight=(t=0,e=this.length,r=1)=>{this.check(t,e);for(let i=t+e-1;i>=t+r;i--)this.array[i]=this.array[i-r];for(let i=0;i<r;i++)this.array[t+i]=0;return this};fill=(t,e=0,r=this.length)=>{if(t<0||t>255)throw new RangeError(h("fill",`Invalid value: '${t}'.`));return this.check(e,r),this.array.fill(t,e,e+r),this};clear=(t=0,e=this.length)=>(this.check(t,e),this.array.fill(0,t,t+e),this)};function J(n){let t=new Headers;for(let[e,r]of Object.entries(n))if(Array.isArray(r))for(let i of r)t.append(e,i);else r!==void 0&&t.append(e,r);return t}function tt(){switch(process.platform){case "win32":return process.env.COMPUTERNAME;case "darwin":return execSync("scutil --get ComputerName").toString().trim();case "linux":{let n=execSync("hostnamectl --pretty").toString().trim();return n===""?hostname():n}default:return hostname()}}var E={UNAUTHORIZED:{status:401,name:"Unauthorized",message:"Unauthorized.",data:null},METHOD_NOT_ALLOWED:{status:405,name:"MethodNotAllowed",message:"Method not allowed.",data:null},INTERNAL_SERVER_ERROR:{status:500,name:"InternalServerError",message:"Internal server error.",data:null}};var R=class{_req;_res;_read;_write;_update;_replace;_remove;_options;constructor(t,e,r,i){this.setRequestResponse(t,e),this.setMethods(r||{}),this.setOptions(i||{});}setRequestResponse(t,e){this._req=t,this._res=e;}setMethods(t){this._read=t?.read,this._write=t?.write,this._update=t?.update,this._replace=t?.replace,this._remove=t?.remove;}setOptions(t){this._options={...this._options,...t};}_checkDataValidity(t){return t!=null}successResponse(t,e){if(b.NO_BODY_HTTP_STATUSES.includes(t)){this._res.status(t).end();return}this._res.status(t).send({success:true,data:this._checkDataValidity(e)?e:null});}errorResponse(t,e,r){let i={success:false,message:r||t.message,error:this._checkDataValidity(e)?{...t,data:e}:t};return this._res.status(t.status).send(i)}async _executeMethod(t,e){return typeof t=="function"?(await t(e),true):(await t.method(e),true)}_getMethodsByHttpMethod(){return {GET:this._read,POST:this._write,PATCH:this._update,PUT:this._replace,DELETE:this._remove}}async run(){let t=this._getMethodsByHttpMethod(),e=t[this._req.method??""];if(!e){let i=Object.keys(t).filter(s=>t[s]);return this._res.setHeader("Allow",i.join(", ")),this.errorResponse(E.METHOD_NOT_ALLOWED)}let r={req:this._req,res:this._res,wrapper:this};try{return await this._executeMethod(e,r)}catch(i){return this._res.headersSent?false:this.errorResponse(E.INTERNAL_SERVER_ERROR,i)}}};var B=class{_req;_res;_read;_write;_update;_replace;_remove;_options;constructor(t,e,r,i){this.setRequestResponse(t,e),this.setMethods(r||{}),this.setOptions(i||{});}setRequestResponse(t,e){this._req=t,this._res=e;}setMethods(t){this._read=t?.read,this._write=t?.write,this._update=t?.update,this._replace=t?.replace,this._remove=t?.remove;}setOptions(t){this._options={...this._options,...t};}_checkDataValidity(t){return t!=null}successResponse(t,e){if(b.NO_BODY_HTTP_STATUSES.includes(t)){this._res.status(t).end();return}this._res.status(t).send({success:true,data:this._checkDataValidity(e)?e:null});}errorResponse(t,e,r){let i={success:false,message:r||t.message,error:this._checkDataValidity(e)?{...t,data:e}:t};return this._res.status(t.status).send(i)}hasRole(t,e){return t.roles?.includes(e)}hasSomeRoles(t,e){return e.some(r=>t.roles?.includes(r))}hasAllRoles(t,e){return e.every(r=>t.roles?.includes(r))}checkAuthOptions(t,e){return e.requireAuth&&!t?(this.errorResponse(E.UNAUTHORIZED),false):e.hasRole&&(!t||!this.hasRole(t.user,e.hasRole))?(this.errorResponse(E.UNAUTHORIZED),false):e.hasSomeRoles&&(!t||!this.hasSomeRoles(t.user,e.hasSomeRoles))?(this.errorResponse(E.UNAUTHORIZED),false):e.hasAllRoles&&(!t||!this.hasAllRoles(t.user,e.hasAllRoles))?(this.errorResponse(E.UNAUTHORIZED),false):true}async _executeMethod(t,e){return typeof t=="function"?(await t(e),true):t.authOptions&&!this.checkAuthOptions(e.session,t.authOptions)?false:(await t.method(e),true)}_getMethodsByHttpMethod(){return {GET:this._read,POST:this._write,PATCH:this._update,PUT:this._replace,DELETE:this._remove}}async run(){let t=this._options.authFunction?await this._options.authFunction(this._req,this._res):null;if(!this.checkAuthOptions(t,this._options))return;let r=this._getMethodsByHttpMethod(),i=r[this._req.method??""];if(!i){let a=Object.keys(r).filter(o=>r[o]);return this._res.setHeader("Allow",a.join(", ")),this.errorResponse(E.METHOD_NOT_ALLOWED)}let s={req:this._req,res:this._res,session:t,wrapper:this};try{return await this._executeMethod(i,s)}catch(a){return this._res.headersSent?false:this.errorResponse(E.INTERNAL_SERVER_ERROR,a)}}};export{S as Bench,N as CyBuffer,R as NextApiWrapper,B as NextAuthApiWrapper,J as convertNodeHeadersToWebHeaders,Q as crypto,q as generateCGASStatus,tt as getHostname,w as serverLogger};//# sourceMappingURL=backend.js.map
6
6
  //# sourceMappingURL=backend.js.map