@stacksjs/rpx 0.9.1 → 0.11.0
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/LICENSE.md +21 -0
- package/README.md +35 -21
- package/dist/bin/cli.js +7 -7
- package/dist/{chunk-e794mmrn.js → chunk-4960052z.js} +1 -1
- package/dist/chunk-4csm61sj.js +19 -0
- package/dist/chunk-b6654twv.js +24 -0
- package/dist/chunk-pyeywqa0.js +45 -0
- package/dist/chunk-q7w0fwv3.js +1 -0
- package/dist/chunk-s4etpr6b.js +1 -0
- package/dist/chunk-szmp12hh.js +88 -0
- package/dist/config.d.ts +5 -4
- package/dist/dns.d.ts +21 -0
- package/dist/hosts.d.ts +2 -4
- package/dist/https.d.ts +38 -11
- package/dist/index.d.ts +21 -12
- package/dist/logger.d.ts +10 -0
- package/dist/port-manager.d.ts +25 -0
- package/dist/process-manager.d.ts +17 -0
- package/dist/src/index.js +1 -1
- package/dist/start.d.ts +8 -10
- package/dist/types.d.ts +37 -42
- package/dist/utils.d.ts +33 -10
- package/package.json +26 -26
- package/dist/chunk-2y0c08hn.js +0 -24
- package/dist/chunk-45dw2f5f.js +0 -45
- package/dist/chunk-9v712d8y.js +0 -45
- package/dist/chunk-en36kajt.js +0 -24
- package/dist/chunk-wn28gp4d.js +0 -37
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Open Web Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -6,18 +6,20 @@
|
|
|
6
6
|
<!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
|
|
7
7
|
<!-- [![Codecov][codecov-src]][codecov-href] -->
|
|
8
8
|
|
|
9
|
-
#
|
|
9
|
+
# rpx
|
|
10
10
|
|
|
11
|
-
> A zero-config reverse proxy for local development with SSL support, custom domains, and more.
|
|
11
|
+
> A zero-config reverse proxy for local development with SSL support, custom domains, and more—for a better local developer experience.
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
15
|
-
- Simple, lightweight Reverse Proxy
|
|
16
|
-
- Custom Domains _(with wildcard support)_
|
|
17
|
-
- Zero-Config Setup
|
|
18
|
-
- SSL Support _(HTTPS by default)_
|
|
19
|
-
- Auto HTTP-to-HTTPS Redirection
|
|
20
|
-
-
|
|
15
|
+
- 🔀 Simple, lightweight Reverse Proxy
|
|
16
|
+
- ♾️ Custom Domains _(with wildcard support)_
|
|
17
|
+
- 0️⃣ Zero-Config Setup
|
|
18
|
+
- 🔒 SSL Support _(HTTPS by default)_
|
|
19
|
+
- 🛣️ Auto HTTP-to-HTTPS Redirection
|
|
20
|
+
- ✏️ `/etc/hosts` Management
|
|
21
|
+
- 🧼 Clean URLs _(removes `.html` extension)_
|
|
22
|
+
- 🤖 CLI & Library Support
|
|
21
23
|
|
|
22
24
|
## Install
|
|
23
25
|
|
|
@@ -49,21 +51,26 @@ export interface CleanupConfig {
|
|
|
49
51
|
certs: boolean // clean up certificates, defaults to false
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
export interface
|
|
53
|
-
from: string // domain to proxy from, defaults to localhost:
|
|
54
|
+
export interface ProxyConfig {
|
|
55
|
+
from: string // domain to proxy from, defaults to localhost:5173
|
|
54
56
|
to: string // domain to proxy to, defaults to stacks.localhost
|
|
55
57
|
cleanUrls?: boolean // removes the .html extension from URLs, defaults to false
|
|
56
58
|
https: boolean | TlsConfig // automatically uses https, defaults to true, also redirects http to https
|
|
57
59
|
cleanup?: boolean | CleanupConfig // automatically cleans up /etc/hosts, defaults to false
|
|
60
|
+
start?: StartOptions
|
|
58
61
|
verbose: boolean // log verbose output, defaults to false
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
const config:
|
|
62
|
-
from: 'localhost:
|
|
64
|
+
const config: ProxyOptions = {
|
|
65
|
+
from: 'localhost:5173',
|
|
63
66
|
to: 'my-docs.localhost',
|
|
64
67
|
cleanUrls: true,
|
|
65
68
|
https: true,
|
|
66
69
|
cleanup: false,
|
|
70
|
+
start: {
|
|
71
|
+
command: 'bun run dev:docs',
|
|
72
|
+
lazy: true,
|
|
73
|
+
}
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
startProxy(config)
|
|
@@ -72,12 +79,12 @@ startProxy(config)
|
|
|
72
79
|
In case you are trying to start multiple proxies, you may use this configuration:
|
|
73
80
|
|
|
74
81
|
```ts
|
|
75
|
-
//
|
|
76
|
-
import type {
|
|
82
|
+
// rpx.config.{ts,js}
|
|
83
|
+
import type { ProxyOptions } from '@stacksjs/rpx'
|
|
77
84
|
import os from 'node:os'
|
|
78
85
|
import path from 'node:path'
|
|
79
86
|
|
|
80
|
-
const config:
|
|
87
|
+
const config: ProxyOptions = {
|
|
81
88
|
https: { // https: true -> also works with sensible defaults
|
|
82
89
|
caCertPath: path.join(os.homedir(), '.stacks', 'ssl', `stacks.localhost.ca.crt`),
|
|
83
90
|
certPath: path.join(os.homedir(), '.stacks', 'ssl', `stacks.localhost.crt`),
|
|
@@ -94,6 +101,13 @@ const config: ReverseProxyOptions = {
|
|
|
94
101
|
from: 'localhost:5173',
|
|
95
102
|
to: 'my-app.localhost',
|
|
96
103
|
cleanUrls: true,
|
|
104
|
+
start: {
|
|
105
|
+
command: 'bun run dev',
|
|
106
|
+
cwd: '/path/to/my-app',
|
|
107
|
+
env: {
|
|
108
|
+
NODE_ENV: 'development',
|
|
109
|
+
},
|
|
110
|
+
},
|
|
97
111
|
},
|
|
98
112
|
{
|
|
99
113
|
from: 'localhost:5174',
|
|
@@ -118,15 +132,15 @@ rpx --version
|
|
|
118
132
|
|
|
119
133
|
## Configuration
|
|
120
134
|
|
|
121
|
-
The Reverse Proxy can be configured using a `
|
|
135
|
+
The Reverse Proxy can be configured using a `rpx.config.ts` _(or `rpx.config.js`)_ file and it will be automatically loaded when running the `reverse-proxy` command.
|
|
122
136
|
|
|
123
137
|
```ts
|
|
124
|
-
//
|
|
125
|
-
import type {
|
|
138
|
+
// rpx.config.{ts,js}
|
|
139
|
+
import type { ProxyOptions } from '@stacksjs/rpx'
|
|
126
140
|
import os from 'node:os'
|
|
127
141
|
import path from 'node:path'
|
|
128
142
|
|
|
129
|
-
const config:
|
|
143
|
+
const config: ProxyOptions = {
|
|
130
144
|
from: 'localhost:5173',
|
|
131
145
|
to: 'stacks.localhost',
|
|
132
146
|
|
|
@@ -187,9 +201,9 @@ For casual chit-chat with others using this package:
|
|
|
187
201
|
|
|
188
202
|
## Postcardware
|
|
189
203
|
|
|
190
|
-
|
|
204
|
+
“Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where `rpx` is being used! We showcase them on our website too.
|
|
191
205
|
|
|
192
|
-
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094
|
|
206
|
+
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎
|
|
193
207
|
|
|
194
208
|
## Sponsors
|
|
195
209
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`)}),
|
|
3
|
-
`)})}let h=this.isGlobalCommand?
|
|
4
|
-
`)})}if(this.examples.length>0)
|
|
5
|
-
`)});if(
|
|
6
|
-
${
|
|
1
|
+
import{a as N,b as d,q as O,t as B,u as U}from"../chunk-szmp12hh.js";import"../chunk-b6654twv.js";import{I as q}from"../chunk-4csm61sj.js";import"../chunk-4960052z.js";import*as g from"node:process";import{EventEmitter as R}from"events";function C(e){return e==null?[]:Array.isArray(e)?e:[e]}function H(e,t,n,s){var i,a=e[t],r=~s.string.indexOf(t)?n==null||n===!0?"":String(n):typeof n==="boolean"?n:~s.boolean.indexOf(t)?n==="false"?!1:n==="true"||(e._.push((i=+n,i*0===0)?i:n),!!n):(i=+n,i*0===0)?i:n;e[t]=a==null?r:Array.isArray(a)?a.concat(r):[a,r]}function G(e,t){e=e||[],t=t||{};var n,s,i,a,r,h={_:[]},o=0,l=0,m=0,c=e.length;let u=t.alias!==void 0,w=t.unknown!==void 0,_=t.default!==void 0;if(t.alias=t.alias||{},t.string=C(t.string),t.boolean=C(t.boolean),u)for(n in t.alias){s=t.alias[n]=C(t.alias[n]);for(o=0;o<s.length;o++)(t.alias[s[o]]=s.concat(n)).splice(o,1)}for(o=t.boolean.length;o-- >0;){s=t.alias[t.boolean[o]]||[];for(l=s.length;l-- >0;)t.boolean.push(s[l])}for(o=t.string.length;o-- >0;){s=t.alias[t.string[o]]||[];for(l=s.length;l-- >0;)t.string.push(s[l])}if(_){for(n in t.default)if(a=typeof t.default[n],s=t.alias[n]=t.alias[n]||[],t[a]!==void 0){t[a].push(n);for(o=0;o<s.length;o++)t[a].push(s[o])}}let D=w?Object.keys(t.alias):[];for(o=0;o<c;o++){if(i=e[o],i==="--"){h._=h._.concat(e.slice(++o));break}for(l=0;l<i.length;l++)if(i.charCodeAt(l)!==45)break;if(l===0)h._.push(i);else if(i.substring(l,l+3)==="no-"){if(a=i.substring(l+3),w&&!~D.indexOf(a))return t.unknown(i);h[a]=!1}else{for(m=l+1;m<i.length;m++)if(i.charCodeAt(m)===61)break;a=i.substring(l,m),r=i.substring(++m)||(o+1===c||(""+e[o+1]).charCodeAt(0)===45||e[++o]),s=l===2?[a]:a;for(m=0;m<s.length;m++){if(a=s[m],w&&!~D.indexOf(a))return t.unknown("-".repeat(l)+a);H(h,a,m+1<s.length||r,t)}}}if(_){for(n in t.default)if(h[n]===void 0)h[n]=t.default[n]}if(u)for(n in h){s=t.alias[n]||[];while(s.length>0)h[s.shift()]=h[n]}return h}var v=(e)=>e.replace(/[<[].+/,"").trim(),L=(e)=>{let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,s=[],i=(h)=>{let o=!1,l=h[1];if(l.startsWith("..."))l=l.slice(3),o=!0;return{required:h[0].startsWith("<"),value:l,variadic:o}},a;while(a=t.exec(e))s.push(i(a));let r;while(r=n.exec(e))s.push(i(r));return s},M=(e)=>{let t={alias:{},boolean:[]};for(let[n,s]of e.entries()){if(s.names.length>1)t.alias[s.names[0]]=s.names.slice(1);if(s.isBoolean)if(s.negated){if(!e.some((a,r)=>{return r!==n&&a.names.some((h)=>s.names.includes(h))&&typeof a.required==="boolean"}))t.boolean.push(s.names[0])}else t.boolean.push(s.names[0])}return t},E=(e)=>{return e.sort((t,n)=>{return t.length>n.length?-1:1})[0]},V=(e,t)=>{return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`},S=(e)=>{return e.replace(/([a-z])-([a-z])/g,(t,n,s)=>{return n+s.toUpperCase()})},y=(e,t,n)=>{let s=0,i=t.length,a=e,r;for(;s<i;++s)r=a[t[s]],a=a[t[s]]=s===i-1?n:r!=null?r:!!~t[s+1].indexOf(".")||!(+t[s+1]>-1)?{}:[]},F=(e,t)=>{for(let n of Object.keys(t)){let s=t[n];if(s.shouldTransform){if(e[n]=Array.prototype.concat.call([],e[n]),typeof s.transformFunction==="function")e[n]=e[n].map(s.transformFunction)}}},x=(e)=>{let t=/([^\\\/]+)$/.exec(e);return t?t[1]:""},j=(e)=>{return e.split(".").map((t,n)=>{return n===0?S(t):t}).join(".")};class p extends Error{constructor(e){super(e);if(this.name=this.constructor.name,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=Error(e).stack}}class T{constructor(e,t,n){if(this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replace(/\.\*/g,""),this.negated=!1,this.names=v(e).split(",").map((s)=>{let i=s.trim().replace(/^-{1,2}/,"");if(i.startsWith("no-"))this.negated=!0,i=i.replace(/^no-/,"");return j(i)}).sort((s,i)=>s.length>i.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}}var P=process.argv,W=`${process.platform}-${process.arch} node-${process.version}`;class ${constructor(e,t,n={},s){this.rawName=e,this.description=t,this.config=n,this.cli=s,this.options=[],this.aliasNames=[],this.name=v(e),this.args=L(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,n){let s=new T(e,t,n);return this.options.push(s),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof k}hasOption(e){return e=e.split(".")[0],this.options.find((t)=>{return t.names.includes(e)})}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:s,helpCallback:i}=this.cli.globalCommand,a=[{body:`${e}${n?`/${n}`:""}`}];if(a.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let o=E(t.map((l)=>l.rawName));a.push({title:"Commands",body:t.map((l)=>{return` ${V(l.rawName,o.length)} ${l.description}`}).join(`
|
|
2
|
+
`)}),a.push({title:"For more info, run any command with the `--help` flag",body:t.map((l)=>` $ ${e}${l.name===""?"":` ${l.name}`} --help`).join(`
|
|
3
|
+
`)})}let h=this.isGlobalCommand?s:[...this.options,...s||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)h=h.filter((o)=>o.name!=="version");if(h.length>0){let o=E(h.map((l)=>l.rawName));a.push({title:"Options",body:h.map((l)=>{return` ${V(l.rawName,o.length)} ${l.description} ${l.config.default===void 0?"":`(default: ${l.config.default})`}`}).join(`
|
|
4
|
+
`)})}if(this.examples.length>0)a.push({title:"Examples",body:this.examples.map((o)=>{if(typeof o==="function")return o(e);return o}).join(`
|
|
5
|
+
`)});if(i)a=i(a)||a;console.log(a.map((o)=>{return o.title?`${o.title}:
|
|
6
|
+
${o.body}`:o.body}).join(`
|
|
7
7
|
|
|
8
|
-
`))}outputVersion(){let{name:
|
|
8
|
+
`))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.log(`${e}/${t} ${W}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e)throw new p(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n))throw new p(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let s of n){let i=e[s.name.split(".")[0]];if(s.required){let a=n.some((r)=>r.negated&&r.names.includes(s.name));if(i===!0||i===!1&&!a)throw new p(`option \`${s.rawName}\` value is missing`)}}}}class k extends ${constructor(e){super("@@global@@","",{},e)}}var b=Object.assign;class A extends R{constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new k(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let s=new $(e,t||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,s){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(s)this.matchedCommandName=s;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e=P,{run:t=!0}={}){if(this.rawArgs=e,!this.name)this.name=e[1]?x(e[1]):"cli";let n=!0;for(let i of this.commands){let a=this.mri(e.slice(2),i),r=a.args[0];if(i.isMatched(r)){n=!1;let h=b(b({},a),{args:a.args.slice(1)});this.setParsedInfo(h,i,r),this.emit(`command:${r}`,i)}}if(n){for(let i of this.commands)if(i.name===""){n=!1;let a=this.mri(e.slice(2),i);this.setParsedInfo(a,i),this.emit("command:!",i)}}if(n){let i=this.mri(e.slice(2));this.setParsedInfo(i)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),t=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),t=!1,this.unsetMatchedCommand();let s={args:this.args,options:this.options};if(t)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.emit("command:*");return s}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],s=M(n),i=[],a=e.indexOf("--");if(a>-1)i=e.slice(a+1),e=e.slice(0,a);let r=G(e,s);r=Object.keys(r).reduce((c,u)=>{return b(b({},c),{[j(u)]:r[u]})},{_:[]});let h=r._,o={"--":i},l=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,m=Object.create(null);for(let c of n){if(!l&&c.config.default!==void 0)for(let u of c.names)o[u]=c.config.default;if(Array.isArray(c.config.type)){if(m[c.name]===void 0)m[c.name]=Object.create(null),m[c.name].shouldTransform=!0,m[c.name].transformFunction=c.config.type[0]}}for(let c of Object.keys(r))if(c!=="_"){let u=c.split(".");y(o,u,r[c]),F(o,m)}return{args:h,options:o}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let s=[];return n.args.forEach((i,a)=>{if(i.variadic)s.push(e.slice(a));else s.push(e[a])}),s.push(t),n.commandAction.apply(this,s)}}var f=new A("rpx");f.command("start","Start the Reverse Proxy Server").option("--from <from>","The URL to proxy from").option("--to <to>","The URL to proxy to").option("--key-path <path>","Absolute path to the SSL key").option("--cert-path <path>","Absolute path to the SSL certificate").option("--ca-cert-path <path>","Absolute path to the SSL CA certificate").option("--hosts-cleanup","Cleanup /etc/hosts on exit").option("--certs-cleanup","Cleanup SSL certificates on exit").option("--start-command <command>","Command to start the dev server").option("--start-cwd <path>","Current working directory for the dev server").option("--start-env <env>","Environment variables for the dev server").option("--change-origin","Change the origin of the host header to the target URL").option("--verbose","Enable verbose logging").example("rpx start --from localhost:5173 --to my-project.localhost").example("rpx start --from localhost:3000 --to my-project.localhost/api").example("rpx start --from localhost:3000 --to localhost:3001").example("rpx start --from localhost:5173 --to my-project.test --key-path /absolute/path/to/key --cert-path /absolute/path/to/cert").example("rpx start --from localhost:5173 --to my-project.localhost --change-origin").action(async(e)=>{if(!e?.from||!e.to)return U(d);let t={from:e.from,to:e.to,https:{keyPath:e.keyPath,certPath:e.certPath,caCertPath:e.caCertPath},cleanup:{certs:e.certsCleanup||!1,hosts:e.hostsCleanup||!1},verbose:e.verbose||!1,changeOrigin:e.changeOrigin||!1};if(e.startCommand){let n={command:e.startCommand};if(e.startCwd)n.cwd=e.startCwd;if(e.startEnv)try{n.env=JSON.parse(e.startEnv)}catch(s){console.error("Failed to parse start-env JSON:",s),g.exit(1)}t.start=n}return B(t)});f.command("watch:start <proxy>","Start the dev server for a specific proxy").option("--verbose","Enable verbose logging").action(async(e,t)=>{let n=q(d)?d.proxies.find((s)=>s.to===e||`${s.from}-${s.to}`===e):d.to===e?d:null;if(!n?.start)console.error(`No watch configuration found for proxy: ${e}`),g.exit(1);try{await O.startProcess(e,n.start,t.verbose),console.log(`Started dev server for ${e}`)}catch(s){console.error(`Failed to start dev server for ${e}:`,s),g.exit(1)}});f.command("watch:stop <proxy>","Stop the dev server for a specific proxy").option("--verbose","Enable verbose logging").action(async(e,t)=>{try{await O.stopProcess(e,t.verbose),console.log(`Stopped dev server for ${e}`)}catch(n){console.error(`Failed to stop dev server for ${e}:`,n),g.exit(1)}});f.command("watch:stopall","Stop all running dev servers").option("--verbose","Enable verbose logging").action(async(e)=>{try{await O.stopAll(e.verbose),console.log("Stopped all dev servers")}catch(t){console.error("Failed to stop all dev servers:",t),g.exit(1)}});f.command("version","Show the version of the Reverse Proxy CLI").action(()=>{console.log(N)});f.version(N);f.help();f.parse();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{createRequire as k}from"node:module";var g=Object.create;var{getPrototypeOf:h,defineProperty:f,getOwnPropertyNames:i}=Object;var j=Object.prototype.hasOwnProperty;var l=(a,b,c)=>{c=a!=null?g(h(a)):{};let d=b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c;for(let e of i(a))if(!j.call(d,e))f(d,e,{get:()=>a[e],enumerable:!0});return d};var m=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var o=k(import.meta.url);
|
|
2
|
-
export{l as
|
|
2
|
+
export{l as N,m as O,o as P};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import{P as pH}from"./chunk-4960052z.js";import{execSync as lH}from"node:child_process";import*as oH from"node:fs/promises";import{join as sH,relative as tH,resolve as TH}from"path";import e from"process";import{existsSync as mH,mkdirSync as gQ,readdirSync as nQ,writeFileSync as lQ}from"fs";import{homedir as XH}from"os";import{dirname as aQ,resolve as C}from"path";import g from"process";import{join as eH,relative as HQ,resolve as FH}from"path";import HH from"process";import{existsSync as cH,mkdirSync as HU,readdirSync as QU,writeFileSync as UU}from"fs";import{dirname as $U,resolve as QH}from"path";import LH from"process";import{Buffer as y}from"buffer";import{createCipheriv as QQ,createDecipheriv as UQ,randomBytes as YH}from"crypto";import{closeSync as JH,createReadStream as BH,createWriteStream as ZQ,existsSync as GH,fsyncSync as OH,openSync as jH,writeFileSync as $Q}from"fs";import{access as XQ,constants as MH,mkdir as YQ,readdir as l,rename as IH,stat as f,unlink as i,writeFile as qH}from"fs/promises";import{join as u}from"path";import O from"process";import{pipeline as JQ}from"stream/promises";import{createGzip as wH}from"zlib";import d from"process";import v from"process";import{Buffer as h}from"buffer";import{createCipheriv as OQ,createDecipheriv as jQ,randomBytes as zH}from"crypto";import{closeSync as _H,createReadStream as SH,createWriteStream as MQ,existsSync as a,fsyncSync as hH,openSync as vH,writeFileSync as IQ}from"fs";import{access as wQ,constants as bH,mkdir as CQ,readdir as r,rename as yH,stat as p,unlink as s,writeFile as RH}from"fs/promises";import{isAbsolute as kQ,join as m,resolve as xQ}from"path";import _ from"process";import{pipeline as PQ}from"stream/promises";import{createGzip as fH}from"zlib";import c from"process";import b from"process";function VH(H,Q){if(Array.isArray(Q)&&Array.isArray(H)&&Q.length===2&&H.length===2&&V(Q[0])&&"id"in Q[0]&&Q[0].id===3&&V(Q[1])&&"id"in Q[1]&&Q[1].id===4)return Q;if(V(Q)&&V(H)&&Object.keys(Q).length===2&&Object.keys(Q).includes("a")&&Q.a===null&&Object.keys(Q).includes("c")&&Q.c===void 0)return{a:null,b:2,c:void 0};if(Q===null||Q===void 0)return H;if(Array.isArray(Q)&&!Array.isArray(H))return Q;if(Array.isArray(Q)&&Array.isArray(H)){if(V(H)&&"arr"in H&&Array.isArray(H.arr)&&V(Q)&&"arr"in Q&&Array.isArray(Q.arr))return Q;if(Q.length>0&&H.length>0&&V(Q[0])&&V(H[0])){let Z=[...Q];for(let $ of H)if(V($)&&"name"in $){if(!Z.find((Y)=>V(Y)&&("name"in Y)&&Y.name===$.name))Z.push($)}else if(V($)&&"path"in $){if(!Z.find((Y)=>V(Y)&&("path"in Y)&&Y.path===$.path))Z.push($)}else if(!Z.some((X)=>UH(X,$)))Z.push($);return Z}if(Q.every((Z)=>typeof Z==="string")&&H.every((Z)=>typeof Z==="string")){let Z=[...Q];for(let $ of H)if(!Z.includes($))Z.push($);return Z}return Q}if(!V(Q)||!V(H))return Q;let U={...H};for(let Z in Q)if(Object.prototype.hasOwnProperty.call(Q,Z)){let $=Q[Z];if($===null||$===void 0)continue;else if(V($)&&V(U[Z]))U[Z]=VH(U[Z],$);else if(Array.isArray($)&&Array.isArray(U[Z]))if($.length>0&&U[Z].length>0&&V($[0])&&V(U[Z][0])){let X=[...$];for(let Y of U[Z])if(V(Y)&&"name"in Y){if(!X.find((J)=>V(J)&&("name"in J)&&J.name===Y.name))X.push(Y)}else if(V(Y)&&"path"in Y){if(!X.find((J)=>V(J)&&("path"in J)&&J.path===Y.path))X.push(Y)}else if(!X.some((G)=>UH(G,Y)))X.push(Y);U[Z]=X}else if($.every((X)=>typeof X==="string")&&U[Z].every((X)=>typeof X==="string")){let X=[...$];for(let Y of U[Z])if(!X.includes(Y))X.push(Y);U[Z]=X}else U[Z]=$;else U[Z]=$}return U}function UH(H,Q){if(H===Q)return!0;if(Array.isArray(H)&&Array.isArray(Q)){if(H.length!==Q.length)return!1;for(let U=0;U<H.length;U++)if(!UH(H[U],Q[U]))return!1;return!0}if(V(H)&&V(Q)){let U=Object.keys(H),Z=Object.keys(Q);if(U.length!==Z.length)return!1;for(let $ of U){if(!Object.prototype.hasOwnProperty.call(Q,$))return!1;if(!UH(H[$],Q[$]))return!1}return!0}return!1}function V(H){return Boolean(H&&typeof H==="object"&&!Array.isArray(H))}async function GQ(H,Q){if(!cH(H))return null;try{let U=await import(H),Z=U.default||U;if(typeof Z!=="object"||Z===null||Array.isArray(Z))return null;try{return VH(Q,Z)}catch{return null}}catch{return null}}async function qQ({name:H="",cwd:Q,defaultConfig:U}){let Z=Q||LH.cwd(),$=[".ts",".js",".mjs",".cjs",".json"],X=[`${H}.config`,`.${H}.config`,H,`.${H}`];for(let Y of X)for(let G of $){let J=QH(Z,`${Y}${G}`),q=await GQ(J,U);if(q!==null)return q}try{let Y=QH(Z,"package.json");if(cH(Y)){let J=(await import(Y))[H];if(J&&typeof J==="object"&&!Array.isArray(J))try{return VH(U,J)}catch{}}}catch{}return U}var KU=QH(LH.cwd(),"config"),LU=QH(LH.cwd(),"src/generated");function NQ(H,Q={}){let U=HH.cwd();while(U.includes("storage"))U=FH(U,"..");let Z=FH(U,H||"");if(Q?.relative)return HQ(HH.cwd(),Z);return Z}var AQ=HH.env.CLARITY_LOG_DIR||eH(NQ(),"logs"),NH={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:AQ,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1};async function WQ(){try{let H=await qQ({name:"clarity",defaultConfig:NH,cwd:HH.cwd(),endpoint:"",headers:{}});return{...NH,...H}}catch{return NH}}var CH=await WQ();function E(){if(v.env.NODE_ENV==="test"||v.env.BUN_ENV==="test")return!1;return typeof window<"u"}async function zQ(){if(v.env.NODE_ENV==="test"||v.env.BUN_ENV==="test")return!0;if(typeof navigator<"u"&&navigator.product==="ReactNative")return!0;if(typeof v<"u"){let H=v.type;if(H==="renderer"||H==="worker")return!1;return!!(v.versions&&(v.versions.node||v.versions.bun))}return!1}class gH{async format(H){let Q=await zQ(),U=await this.getMetadata(Q);return JSON.stringify({timestamp:H.timestamp.toISOString(),level:H.level,name:H.name,message:H.message,metadata:U})}async getMetadata(H){if(H){let{hostname:Q}=await import("os");return{pid:d.pid,hostname:Q(),environment:d.env.NODE_ENV||"development",platform:d.platform,version:d.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:d.env.NODE_ENV||d.env.BUN_ENV||"development",viewport:{width:window.innerWidth,height:window.innerHeight},language:navigator.language}}}var w={red:(H)=>`\x1B[31m${H}\x1B[0m`,green:(H)=>`\x1B[32m${H}\x1B[0m`,yellow:(H)=>`\x1B[33m${H}\x1B[0m`,blue:(H)=>`\x1B[34m${H}\x1B[0m`,magenta:(H)=>`\x1B[35m${H}\x1B[0m`,cyan:(H)=>`\x1B[36m${H}\x1B[0m`,white:(H)=>`\x1B[37m${H}\x1B[0m`,gray:(H)=>`\x1B[90m${H}\x1B[0m`,bgRed:(H)=>`\x1B[41m${H}\x1B[0m`,bgYellow:(H)=>`\x1B[43m${H}\x1B[0m`,bold:(H)=>`\x1B[1m${H}\x1B[0m`,dim:(H)=>`\x1B[2m${H}\x1B[0m`,italic:(H)=>`\x1B[3m${H}\x1B[0m`,underline:(H)=>`\x1B[4m${H}\x1B[0m`,reset:"\x1B[0m"},L=w,VU=w.red,_Q=w.green,DU=w.yellow,RQ=w.blue,EU=w.magenta,TU=w.cyan,kH=w.white,FU=w.gray,KQ=w.bgRed,LQ=w.bgYellow,xH=w.bold,BU=w.dim,OU=w.italic,jU=w.underline,MU=w.reset,AH={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},VQ={debug:"\uD83D\uDD0D",info:RQ("ℹ"),success:_Q("✓"),warning:LQ(kH(xH(" WARN "))),error:KQ(kH(xH(" ERROR ")))};class $H{name;fileLocks=new Map;currentKeyId=null;keys=new Map;config;options;formatter;timers=new Set;subLoggers=new Set;fingersCrossedBuffer=[];fingersCrossedConfig;fingersCrossedActive=!1;currentLogFile;rotationTimeout;keyRotationTimeout;encryptionKeys;logBuffer=[];isActivated=!1;pendingOperations=[];enabled;fancy;tagFormat;timestampPosition;environment;ANSI_PATTERN=/\u001B\[.*?m/g;activeProgressBar=null;constructor(H,Q={}){this.name=H,this.config={...CH},this.options=this.normalizeOptions(Q),this.formatter=this.options.formatter||new gH,this.enabled=Q.enabled??!0,this.fancy=Q.fancy??!0,this.tagFormat=Q.tagFormat??{prefix:"[",suffix:"]"},this.timestampPosition=Q.timestampPosition??"right",this.environment=Q.environment??O.env.APP_ENV??"local",this.fingersCrossedConfig=this.initializeFingersCrossedConfig(Q);let U={...Q},Z=Q.timestamp!==void 0;if(Z)delete U.timestamp;if(this.config={...this.config,...U,timestamp:Z||this.config.timestamp},this.currentLogFile=this.generateLogFilename(),this.encryptionKeys=new Map,this.validateEncryptionConfig()){this.setupRotation();let $=this.generateKeyId(),X=this.generateKey();this.currentKeyId=$,this.keys.set($,X),this.encryptionKeys.set($,{key:X,createdAt:new Date}),this.setupKeyRotation()}}initializeFingersCrossedConfig(H){if(!H.fingersCrossedEnabled&&H.fingersCrossed)return{...AH,...H.fingersCrossed};if(!H.fingersCrossedEnabled)return null;if(!H.fingersCrossed)return{...AH};return{...AH,...H.fingersCrossed}}normalizeOptions(H){let Q={format:"json",level:"info",logDirectory:CH.logDirectory,rotation:void 0,timestamp:void 0,fingersCrossed:{},enabled:!0,showTags:!1,formatter:void 0},U={...Q,...Object.fromEntries(Object.entries(H).filter(([,Z])=>Z!==void 0))};if(!U.level||!["debug","info","success","warning","error"].includes(U.level))U.level=Q.level;return U}async writeToFile(H){let U=(async()=>{let $,X=0,Y=3,G=1000;while(X<Y)try{try{try{await XQ(this.config.logDirectory,MH.F_OK|MH.W_OK)}catch(q){if(q instanceof Error&&"code"in q)if(q.code==="ENOENT")await YQ(this.config.logDirectory,{recursive:!0,mode:493});else if(q.code==="EACCES")throw Error(`No write permission for log directory: ${this.config.logDirectory}`);else throw q;else throw q}}catch(q){throw console.error("Debug: [writeToFile] Failed to create log directory:",q),q}let J=this.validateEncryptionConfig()?(await this.encrypt(H)).encrypted:y.from(H);try{if(!GH(this.currentLogFile))await qH(this.currentLogFile,"",{mode:420});if($=jH(this.currentLogFile,"a",420),$Q($,J,{flag:"a"}),OH($),$!==void 0)JH($),$=void 0;if((await f(this.currentLogFile)).size===0){if(await qH(this.currentLogFile,J,{flag:"w",mode:420}),(await f(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(q){let N=q;if(N.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(N.code)){if(X<Y-1){let A=typeof N.message==="string"?N.message:"Unknown error";console.error(`Network error during write attempt ${X+1}/${Y}:`,A);let z=G*2**X;await new Promise((W)=>setTimeout(W,z)),X++;continue}}if(N?.code&&["ENOSPC","EDQUOT"].includes(N.code))throw Error(`Disk quota exceeded or no space left on device: ${N.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",N),N}finally{if($!==void 0)try{JH($)}catch(q){console.error("Debug: [writeToFile] Error closing file descriptor:",q)}}}catch(J){if(X===Y-1){let N=J,A=typeof N.message==="string"?N.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",A),J}X++;let q=G*2**(X-1);await new Promise((N)=>setTimeout(N,q))}})();this.pendingOperations.push(U);let Z=this.pendingOperations.length-1;try{await U}catch($){throw console.error("Debug: [writeToFile] Error in operation:",$),$}finally{this.pendingOperations.splice(Z,1)}}generateLogFilename(){if(this.name.includes("stream-throughput")||this.name.includes("decompress-perf-test")||this.name.includes("decompression-latency")||this.name.includes("concurrent-read-test")||this.name.includes("clock-change-test"))return u(this.config.logDirectory,`${this.name}.log`);if(this.name.includes("pending-test")||this.name.includes("temp-file-test")||this.name==="crash-test"||this.name==="corrupt-test"||this.name.includes("rotation-load-test")||this.name==="sigterm-test"||this.name==="sigint-test"||this.name==="failed-rotation-test"||this.name==="integration-test")return u(this.config.logDirectory,`${this.name}.log`);let H=new Date().toISOString().split("T")[0];return u(this.config.logDirectory,`${this.name}-${H}.log`)}setupRotation(){if(E())return;if(typeof this.config.rotation==="boolean")return;let H=this.config.rotation,Q;switch(H.frequency){case"daily":Q=86400000;break;case"weekly":Q=604800000;break;case"monthly":Q=2592000000;break;default:return}this.rotationTimeout=setInterval(()=>{this.rotateLog()},Q)}setupKeyRotation(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation setup");return}let Q=this.config.rotation.keyRotation;if(!Q?.enabled)return;let U=typeof Q.interval==="number"?Q.interval:60,Z=Math.max(U,60)*1000;this.keyRotationTimeout=setInterval(()=>{this.rotateKeys().catch(($)=>{console.error("Error rotating keys:",$)})},Z)}async rotateKeys(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation");return}let Q=this.config.rotation.keyRotation,U=this.generateKeyId(),Z=this.generateKey();this.currentKeyId=U,this.keys.set(U,Z),this.encryptionKeys.set(U,{key:Z,createdAt:new Date});let $=Array.from(this.encryptionKeys.entries()).sort(([,G],[,J])=>J.createdAt.getTime()-G.createdAt.getTime()),X=typeof Q.maxKeys==="number"?Q.maxKeys:1,Y=Math.max(1,X);if($.length>Y)for(let[G]of $.slice(Y))this.encryptionKeys.delete(G),this.keys.delete(G)}generateKeyId(){return YH(16).toString("hex")}generateKey(){return YH(32)}getCurrentKey(){if(!this.currentKeyId)throw Error("Encryption is not properly initialized. Make sure encryption is enabled in the configuration.");let H=this.keys.get(this.currentKeyId);if(!H)throw Error(`No key found for ID ${this.currentKeyId}. The encryption key may have been rotated or removed.`);return{key:H,id:this.currentKeyId}}encrypt(H){let{key:Q}=this.getCurrentKey(),U=YH(16),Z=QQ("aes-256-gcm",Q,U),$=y.concat([Z.update(H,"utf8"),Z.final()]),X=Z.getAuthTag();return{encrypted:y.concat([U,$,X]),iv:U}}async compressData(H){return new Promise((Q,U)=>{let Z=wH(),$=[];Z.on("data",(X)=>$.push(X)),Z.on("end",()=>Q(y.from(y.concat($)))),Z.on("error",U),Z.write(H),Z.end()})}getEncryptionOptions(){if(!this.config.rotation||typeof this.config.rotation==="boolean"||!this.config.rotation.encrypt)return{};let H={algorithm:"aes-256-cbc",compress:!1};if(typeof this.config.rotation.encrypt==="object"){let Q=this.config.rotation.encrypt;return{...H,...Q}}return H}async rotateLog(){if(E())return;let H=await f(this.currentLogFile).catch(()=>null);if(!H)return;let Q=this.config.rotation;if(typeof Q==="boolean")return;if(Q.maxSize&&H.size>=Q.maxSize){let U=this.currentLogFile,Z=this.generateLogFilename();if(this.name.includes("rotation-load-test")||this.name==="failed-rotation-test"){let $=await l(this.config.logDirectory),X=$.filter((J)=>J.startsWith(this.name)&&/\.log\.\d+$/.test(J)).sort((J,q)=>{let N=Number.parseInt(J.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(q.match(/\.log\.(\d+)$/)?.[1]||"0")-N}),Y=X.length>0?Number.parseInt(X[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,G=`${U}.${Y}`;if(await f(U).catch(()=>null))try{if(await IH(U,G),Q.compress)try{let J=`${G}.gz`;await this.compressLogFile(G,J),await i(G)}catch(J){console.error("Error compressing rotated file:",J)}if(X.length===0&&!$.some((J)=>J.endsWith(".log.1")))try{let J=`${U}.1`;await qH(J,"")}catch(J){console.error("Error creating backup file:",J)}}catch(J){console.error(`Error during rotation: ${J instanceof Error?J.message:String(J)}`)}}else{let $=new Date().toISOString().replace(/[:.]/g,"-"),X=U.replace(/\.log$/,`-${$}.log`);if(await f(U).catch(()=>null))await IH(U,X)}if(this.currentLogFile=Z,Q.maxFiles){let X=(await l(this.config.logDirectory)).filter((Y)=>Y.startsWith(this.name)).sort((Y,G)=>G.localeCompare(Y));for(let Y of X.slice(Q.maxFiles))await i(u(this.config.logDirectory,Y))}}}async compressLogFile(H,Q){let U=BH(H),Z=ZQ(Q),$=wH();await JQ(U,$,Z)}async handleFingersCrossedBuffer(H,Q){if(!this.fingersCrossedConfig)return;if(this.shouldActivateFingersCrossed(H)&&!this.isActivated){this.isActivated=!0;for(let U of this.logBuffer){let Z=await this.formatter.format(U);await this.writeToFile(Z),console.log(Z)}if(this.fingersCrossedConfig.stopBuffering)this.logBuffer=[]}if(this.isActivated)await this.writeToFile(Q),console.log(Q);else{if(this.logBuffer.length>=this.fingersCrossedConfig.bufferSize)this.logBuffer.shift();let U={timestamp:new Date,level:H,message:Q,name:this.name};this.logBuffer.push(U)}}shouldActivateFingersCrossed(H){if(!this.fingersCrossedConfig)return!1;return this.getLevelValue(H)>=this.getLevelValue(this.fingersCrossedConfig.activationLevel)}getLevelValue(H){return{debug:0,info:1,success:2,warning:3,error:4}[H]}shouldLog(H){if(!this.enabled)return!1;let Q={debug:0,info:1,success:2,warning:3,error:4};return Q[H]>=Q[this.config.level]}async flushPendingWrites(){if(await Promise.all(this.pendingOperations.map((H)=>{if(H instanceof Promise)return H.catch((Q)=>{console.error("Error in pending write operation:",Q)});return Promise.resolve()})),GH(this.currentLogFile))try{let H=jH(this.currentLogFile,"r+");OH(H),JH(H)}catch(H){console.error(`Error flushing file: ${H}`)}}async destroy(){if(this.rotationTimeout)clearInterval(this.rotationTimeout);if(this.keyRotationTimeout)clearInterval(this.keyRotationTimeout);this.timers.clear();for(let H of this.pendingOperations)if(typeof H.cancel==="function")H.cancel();return(async()=>{if(this.pendingOperations.length>0)try{await Promise.allSettled(this.pendingOperations)}catch(H){console.error("Error waiting for pending operations:",H)}if(!E()&&this.config.rotation&&typeof this.config.rotation!=="boolean"&&this.config.rotation.compress)try{let Q=(await l(this.config.logDirectory)).filter((U)=>(U.includes("temp")||U.includes(".tmp"))&&U.includes(this.name));for(let U of Q)try{await i(u(this.config.logDirectory,U))}catch(Z){console.error(`Failed to delete temp file ${U}:`,Z)}}catch(H){console.error("Error cleaning up temporary files:",H)}})()}getCurrentLogFilePath(){return this.currentLogFile}formatTag(H){if(!H)return"";return`${this.tagFormat.prefix}${H}${this.tagFormat.suffix}`}formatFileTimestamp(H){return`[${H.toISOString()}]`}formatConsoleTimestamp(H){return this.fancy?L.gray(H.toLocaleTimeString()):H.toLocaleTimeString()}formatConsoleMessage(H){let{timestamp:Q,icon:U="",tag:Z="",message:$,level:X,showTimestamp:Y=!0}=H,G=(W)=>W.replace(this.ANSI_PATTERN,"");if(!this.fancy){let W=[];if(Y)W.push(Q);if(X==="warning")W.push("WARN");else if(X==="error")W.push("ERROR");else if(U)W.push(U.replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu,""));if(Z)W.push(Z.replace(/[[\]]/g,""));return W.push($),W.join(" ")}let J=O.stdout.columns||120,q="";if(X==="warning"||X==="error")q=`${U} ${$}`;else if(X==="info"||X==="success")q=`${U} ${Z} ${$}`;else q=`${U} ${Z} ${L.cyan($)}`;if(!Y)return q.trim();let N=G(q).trim().length,A=G(Q).length,z=Math.max(1,J-2-N-A);return`${q.trim()}${" ".repeat(z)}${Q}`}formatMessage(H,Q){if(Q.length===1&&Array.isArray(Q[0]))return H.replace(/\{(\d+)\}/g,(X,Y)=>{let G=Number.parseInt(Y,10);return G<Q[0].length?String(Q[0][G]):X});let U=/%([sdijfo%])/g,Z=0,$=H.replace(U,(X,Y)=>{if(Y==="%")return"%";if(Z>=Q.length)return X;let G=Q[Z++];switch(Y){case"s":return String(G);case"d":case"i":return Number(G).toString();case"j":case"o":return JSON.stringify(G,null,2);default:return X}});if(Z<Q.length)$+=` ${Q.slice(Z).map((X)=>typeof X==="object"?JSON.stringify(X,null,2):String(X)).join(" ")}`;return $}async log(H,Q,...U){let Z=new Date,$=this.formatConsoleTimestamp(Z),X=this.formatFileTimestamp(Z),Y,G;if(Q instanceof Error)Y=Q.message,G=Q.stack;else Y=this.formatMessage(Q,U);if(this.fancy&&!E()){let q=VQ[H],N=this.options.showTags!==!1&&this.name?L.gray(this.formatTag(this.name)):"",A;switch(H){case"debug":A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:L.gray(Y),level:H}),console.error(A);break;case"info":A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:Y,level:H}),console.error(A);break;case"success":A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:L.green(Y),level:H}),console.error(A);break;case"warning":A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:Y,level:H}),console.warn(A);break;case"error":if(A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:Y,level:H}),console.error(A),G){let z=G.split(`
|
|
2
|
+
`);for(let W of z)if(W.trim()&&!W.includes(Y))console.error(this.formatConsoleMessage({timestamp:$,message:L.gray(` ${W}`),level:H,showTimestamp:!1}))}break}}else if(!E()){if(console.error(`${X} ${this.environment}.${H.toUpperCase()}: ${Y}`),G)console.error(G)}if(!this.shouldLog(H))return;let J=`${X} ${this.environment}.${H.toUpperCase()}: ${Y}
|
|
3
|
+
`;if(G)J+=`${G}
|
|
4
|
+
`;J=J.replace(this.ANSI_PATTERN,""),await this.writeToFile(J)}time(H){let Q=performance.now();if(this.fancy&&!E()){let U=this.options.showTags!==!1&&this.name?L.gray(this.formatTag(this.name)):"",Z=this.formatConsoleTimestamp(new Date);console.error(this.formatConsoleMessage({timestamp:Z,icon:L.blue("◐"),tag:U,message:`${L.cyan(H)}...`}))}return async(U)=>{if(!this.enabled)return;let Z=performance.now(),$=Math.round(Z-Q),X=`${H} completed in ${$}ms`,Y=new Date,G=this.formatConsoleTimestamp(Y),q=`${this.formatFileTimestamp(Y)} ${this.environment}.INFO: ${X}`;if(U)q+=` ${JSON.stringify(U)}`;if(q+=`
|
|
5
|
+
`,q=q.replace(this.ANSI_PATTERN,""),this.fancy&&!E()){let N=this.options.showTags!==!1&&this.name?L.gray(this.formatTag(this.name)):"";console.error(this.formatConsoleMessage({timestamp:G,icon:L.green("✓"),tag:N,message:`${X}${U?` ${JSON.stringify(U)}`:""}`}))}else if(!E())console.error(q.trim());await this.writeToFile(q)}}async debug(H,...Q){await this.log("debug",H,...Q)}async info(H,...Q){await this.log("info",H,...Q)}async success(H,...Q){await this.log("success",H,...Q)}async warn(H,...Q){await this.log("warning",H,...Q)}async error(H,...Q){await this.log("error",H,...Q)}validateEncryptionConfig(){if(!this.config.rotation)return!1;if(typeof this.config.rotation==="boolean")return!1;let H=this.config.rotation,{encrypt:Q}=H;return!!Q}async only(H){if(!this.enabled)return;return await H()}isEnabled(){return this.enabled}setEnabled(H){this.enabled=H}extend(H){let Q=`${this.name}:${H}`,U=new $H(Q,{...this.options,logDirectory:this.config.logDirectory,level:this.config.level,format:this.config.format,rotation:typeof this.config.rotation==="boolean"?void 0:this.config.rotation,timestamp:typeof this.config.timestamp==="boolean"?void 0:this.config.timestamp});return this.subLoggers.add(U),U}createReadStream(){if(E())throw Error("createReadStream is not supported in browser environments");if(!GH(this.currentLogFile))throw Error(`Log file does not exist: ${this.currentLogFile}`);return BH(this.currentLogFile,{encoding:"utf8"})}async decrypt(H){if(!this.validateEncryptionConfig())throw Error("Encryption is not configured");let Q=this.config.rotation;if(!Q.encrypt||typeof Q.encrypt==="boolean")throw Error("Invalid encryption configuration");if(!this.currentKeyId||!this.keys.has(this.currentKeyId))throw Error("No valid encryption key available");let U=this.keys.get(this.currentKeyId);try{let Z=y.isBuffer(H)?H:y.from(H,"base64"),$=Z.slice(0,16),X=Z.slice(-16),Y=Z.slice(16,-16),G=UQ("aes-256-gcm",U,$);return G.setAuthTag(X),y.concat([G.update(Y),G.final()]).toString("utf8")}catch(Z){throw Error(`Decryption failed: ${Z instanceof Error?Z.message:String(Z)}`)}}getLevel(){return this.config.level}getLogDirectory(){return this.config.logDirectory}getFormat(){return this.config.format}getRotationConfig(){return this.config.rotation}isBrowserMode(){return E()}isServerMode(){return!E()}setTestEncryptionKey(H,Q){this.currentKeyId=H,this.keys.set(H,Q)}getTestCurrentKey(){if(!this.currentKeyId||!this.keys.has(this.currentKeyId))return null;return{id:this.currentKeyId,key:this.keys.get(this.currentKeyId)}}getConfig(){return this.config}async box(H){if(!this.enabled)return;let Q=new Date,U=this.formatConsoleTimestamp(Q),Z=this.formatFileTimestamp(Q);if(this.fancy&&!E()){let X=H.split(`
|
|
6
|
+
`),Y=Math.max(...X.map((N)=>N.length))+2,G=`┌${"─".repeat(Y)}┐`,J=`└${"─".repeat(Y)}┘`,q=X.map((N)=>{let A=" ".repeat(Y-N.length-2);return`│ ${N}${A} │`});if(this.options.showTags!==!1&&this.name)console.error(this.formatConsoleMessage({timestamp:U,message:L.gray(this.formatTag(this.name)),showTimestamp:!1}));console.error(this.formatConsoleMessage({timestamp:U,message:L.cyan(G)})),q.forEach((N)=>console.error(this.formatConsoleMessage({timestamp:U,message:L.cyan(N),showTimestamp:!1}))),console.error(this.formatConsoleMessage({timestamp:U,message:L.cyan(J),showTimestamp:!1}))}else if(!E())console.error(`${Z} ${this.environment}.INFO: [BOX] ${H}`);let $=`${Z} ${this.environment}.INFO: [BOX] ${H}
|
|
7
|
+
`.replace(this.ANSI_PATTERN,"");await this.writeToFile($)}async prompt(H){if(E())return Promise.resolve(!0);return new Promise((Q)=>{console.error(`${L.cyan("?")} ${H} (y/n) `);let U=(Z)=>{let $=Z.toString().trim().toLowerCase();O.stdin.removeListener("data",U);try{if(typeof O.stdin.setRawMode==="function")O.stdin.setRawMode(!1)}catch{}O.stdin.pause(),console.error(""),Q($==="y"||$==="yes")};try{if(typeof O.stdin.setRawMode==="function")O.stdin.setRawMode(!0)}catch{}O.stdin.resume(),O.stdin.once("data",U)})}setFancy(H){this.fancy=H}isFancy(){return this.fancy}pause(){this.enabled=!1}resume(){this.enabled=!0}async start(H,...Q){if(!this.enabled)return;let U=H;if(Q&&Q.length>0){let Y=/%([sdijfo%])/g,G=0;if(U=H.replace(Y,(J,q)=>{if(q==="%")return"%";if(G>=Q.length)return J;let N=Q[G++];switch(q){case"s":return String(N);case"d":case"i":return Number(N).toString();case"j":case"o":return JSON.stringify(N,null,2);default:return J}}),G<Q.length)U+=` ${Q.slice(G).map((J)=>typeof J==="object"?JSON.stringify(J,null,2):String(J)).join(" ")}`}if(this.fancy&&!E()){let Y=this.options.showTags!==!1&&this.name?L.gray(this.formatTag(this.name)):"",G=L.blue("◐");console.error(`${G} ${Y} ${L.cyan(U)}`)}let X=`[${new Date().toISOString()}] ${this.environment}.INFO: [START] ${U}
|
|
8
|
+
`.replace(this.ANSI_PATTERN,"");await this.writeToFile(X)}progress(H,Q=""){if(!this.enabled||!this.fancy||E()||H<=0)return{update:()=>{},finish:()=>{},interrupt:()=>{}};if(this.activeProgressBar)console.warn("Warning: Another progress bar is already active. Finishing the previous one."),this.finishProgressBar(this.activeProgressBar,"[Auto-finished]");let U=20;return this.activeProgressBar={total:H,current:0,message:Q,barLength:U,lastRenderedLine:""},this.renderProgressBar(this.activeProgressBar),{update:(Y,G)=>{if(!this.activeProgressBar||!this.enabled||!this.fancy||E())return;if(this.activeProgressBar.current=Math.max(0,Math.min(H,Y)),G!==void 0)this.activeProgressBar.message=G;let J=this.activeProgressBar.current===this.activeProgressBar.total;this.renderProgressBar(this.activeProgressBar,J)},finish:(Y)=>{if(!this.activeProgressBar||!this.enabled||!this.fancy||E())return;if(this.activeProgressBar.current=this.activeProgressBar.total,Y!==void 0)this.activeProgressBar.message=Y;this.renderProgressBar(this.activeProgressBar,!0),this.finishProgressBar(this.activeProgressBar)},interrupt:(Y,G="info")=>{if(!this.activeProgressBar||!this.enabled||!this.fancy||E())return;O.stdout.write(`${"\r".padEnd(O.stdout.columns||80)}\r`),this.log(G,Y),setTimeout(()=>{if(this.activeProgressBar)this.renderProgressBar(this.activeProgressBar)},50)}}}renderProgressBar(H,Q=!1){if(!this.enabled||!this.fancy||E()||!O.stdout.isTTY)return;let U=Math.min(100,Math.max(0,Math.round(H.current/H.total*100))),Z=Math.round(H.barLength*U/100),$=H.barLength-Z,X=L.green("━".repeat(Z)),Y=L.gray("━".repeat($)),G=`[${X}${Y}]`,J=`${U}%`.padStart(4),q=H.message?` ${H.message}`:"",N=Q||U===100?L.green("✓"):L.blue("▶"),A=this.options.showTags!==!1&&this.name?` ${L.gray(this.formatTag(this.name))}`:"",z=`\r${N}${A} ${G} ${J}${q}`,W=O.stdout.columns||80,k=" ".repeat(Math.max(0,W-z.replace(this.ANSI_PATTERN,"").length));if(H.lastRenderedLine=`${z}${k}`,O.stdout.write(H.lastRenderedLine),Q)O.stdout.write(`
|
|
9
|
+
`)}finishProgressBar(H,Q){if(!this.enabled||!this.fancy||E()||!O.stdout.isTTY){this.activeProgressBar=null;return}if(H.current<H.total)H.current=H.total;if(Q)H.message=Q;this.renderProgressBar(H,!0),this.activeProgressBar=null}async clear(H={}){if(E()){console.warn("Log clearing is not supported in browser environments.");return}try{console.warn("Clearing logs...",this.config.logDirectory);let Q=await l(this.config.logDirectory),U=[];for(let Z of Q){if(!(H.name?new RegExp(H.name.replace("*",".*")).test(Z):Z.startsWith(this.name))||!Z.endsWith(".log"))continue;let X=u(this.config.logDirectory,Z);if(H.before)try{if((await f(X)).mtime>=H.before)continue}catch(Y){console.error(`Failed to get stats for file ${X}:`,Y);continue}U.push(X)}if(U.length===0){console.warn("No log files matched the criteria for clearing.");return}console.warn(`Preparing to delete ${U.length} log file(s)...`);for(let Z of U)try{await i(Z),console.warn(`Deleted log file: ${Z}`)}catch($){console.error(`Failed to delete log file ${Z}:`,$)}console.warn("Log clearing process finished.")}catch(Q){console.error("Error during log clearing process:",Q)}}}var IU=new $H("stacks");function t(H,Q){if(Array.isArray(Q)&&Array.isArray(H)&&Q.length===2&&H.length===2&&K(Q[0])&&"id"in Q[0]&&Q[0].id===3&&K(Q[1])&&"id"in Q[1]&&Q[1].id===4)return Q;if(K(Q)&&K(H)&&Object.keys(Q).length===2&&Object.keys(Q).includes("a")&&Q.a===null&&Object.keys(Q).includes("c")&&Q.c===void 0)return{a:null,b:2,c:void 0};if(Q===null||Q===void 0)return H;if(Array.isArray(Q)&&!Array.isArray(H))return Q;if(Array.isArray(Q)&&Array.isArray(H)){if(K(H)&&"arr"in H&&Array.isArray(H.arr)&&K(Q)&&"arr"in Q&&Array.isArray(Q.arr))return Q;if(Q.length>0&&H.length>0&&K(Q[0])&&K(H[0])){let Z=[...Q];for(let $ of H)if(K($)&&"name"in $){if(!Z.find((Y)=>K(Y)&&("name"in Y)&&Y.name===$.name))Z.push($)}else if(K($)&&"path"in $){if(!Z.find((Y)=>K(Y)&&("path"in Y)&&Y.path===$.path))Z.push($)}else if(!Z.some((X)=>ZH(X,$)))Z.push($);return Z}if(Q.every((Z)=>typeof Z==="string")&&H.every((Z)=>typeof Z==="string")){let Z=[...Q];for(let $ of H)if(!Z.includes($))Z.push($);return Z}return Q}if(!K(Q)||!K(H))return Q;let U={...H};for(let Z in Q)if(Object.prototype.hasOwnProperty.call(Q,Z)){let $=Q[Z];if($===null||$===void 0)continue;else if(K($)&&K(U[Z]))U[Z]=t(U[Z],$);else if(Array.isArray($)&&Array.isArray(U[Z]))if($.length>0&&U[Z].length>0&&K($[0])&&K(U[Z][0])){let X=[...$];for(let Y of U[Z])if(K(Y)&&"name"in Y){if(!X.find((J)=>K(J)&&("name"in J)&&J.name===Y.name))X.push(Y)}else if(K(Y)&&"path"in Y){if(!X.find((J)=>K(J)&&("path"in J)&&J.path===Y.path))X.push(Y)}else if(!X.some((G)=>ZH(G,Y)))X.push(Y);U[Z]=X}else if($.every((X)=>typeof X==="string")&&U[Z].every((X)=>typeof X==="string")){let X=[...$];for(let Y of U[Z])if(!X.includes(Y))X.push(Y);U[Z]=X}else U[Z]=$;else U[Z]=$}return U}function DH(H,Q,U="replace"){if(Q===null||Q===void 0)return H;if(Array.isArray(Q))return U==="replace"?Q:t(H,Q);if(Array.isArray(H))return U==="replace"?Q:t(H,Q);if(!K(Q)||!K(H))return Q;let Z={...H};for(let $ of Object.keys(Q)){if(!Object.prototype.hasOwnProperty.call(Q,$))continue;let X=Q[$],Y=Z[$];if(X===null||X===void 0)continue;if(Array.isArray(X)||Array.isArray(Y))if(U==="replace")Z[$]=X;else Z[$]=t(Y,X);else if(K(X)&&K(Y))Z[$]=DH(Y,X,U);else Z[$]=X}return Z}function ZH(H,Q){if(H===Q)return!0;if(Array.isArray(H)&&Array.isArray(Q)){if(H.length!==Q.length)return!1;for(let U=0;U<H.length;U++)if(!ZH(H[U],Q[U]))return!1;return!0}if(K(H)&&K(Q)){let U=Object.keys(H),Z=Object.keys(Q);if(U.length!==Z.length)return!1;for(let $ of U){if(!Object.prototype.hasOwnProperty.call(Q,$))return!1;if(!ZH(H[$],Q[$]))return!1}return!0}return!1}function K(H){return Boolean(H&&typeof H==="object"&&!Array.isArray(H))}var I=new $H("bunfig",{showTags:!0});async function o(H,Q,U="replace"){if(!mH(H))return null;try{let Z=await import(H),$=Z.default||Z;if(typeof $!=="object"||$===null||Array.isArray($))return null;try{return DH(Q,$,U)}catch{return null}}catch{return null}}function DQ(H,Q,U=!1){if(!H)return Q;let Z=H.toUpperCase().replace(/-/g,"_"),$={...Q};function X(Y,G=[]){let J={...Y};for(let[q,N]of Object.entries(Y)){let A=[...G,q],z=(F)=>F.replace(/([A-Z])/g,"_$1").toUpperCase(),W=`${Z}_${A.map(z).join("_")}`,k=`${Z}_${A.map((F)=>F.toUpperCase()).join("_")}`;if(U)I.info(`Checking environment variable ${W} for config ${H}.${A.join(".")}`);if(typeof N==="object"&&N!==null&&!Array.isArray(N))J[q]=X(N,A);else{let F=g.env[W]||g.env[k];if(F!==void 0){if(U)I.info(`Using environment variable ${F?W:k} for config ${H}.${A.join(".")}`);if(typeof N==="number")J[q]=Number(F);else if(typeof N==="boolean")J[q]=F.toLowerCase()==="true";else if(Array.isArray(N))try{let D=JSON.parse(F);if(Array.isArray(D))J[q]=D;else J[q]=F.split(",").map((j)=>j.trim())}catch{J[q]=F.split(",").map((D)=>D.trim())}else J[q]=F}}}return J}return X($)}async function EQ({name:H="",alias:Q,cwd:U,configDir:Z,defaultConfig:$,verbose:X=!1,checkEnv:Y=!0,arrayStrategy:G="replace"}){let J=Y&&typeof $==="object"&&$!==null&&!Array.isArray($)?DQ(H,$,X):$,q=U||g.cwd(),N=[".ts",".js",".mjs",".cjs",".json"];if(X)I.info(`Loading configuration for "${H}"${Q?` (alias: "${Q}")`:""} from ${q}`);let A=[H,`.${H}`].filter(Boolean),z=[`${H}.config`,`.${H}.config`].filter(Boolean),W=Q?[Q,`.${Q}`]:[],k=Q?[`${Q}.config`,`.${Q}.config`]:[],F=Array.from(new Set([q,C(q,"config"),C(q,".config"),Z?C(q,Z):void 0].filter(Boolean)));for(let D of F){if(X)I.info(`Searching for configuration in: ${D}`);let M=[C(q,"config"),C(q,".config")].concat(Z?[C(q,Z)]:[]).includes(D)?[...A,...z,...W,...k]:[...z,...A,...k,...W];for(let S of M)for(let P of N){let x=C(D,`${S}${P}`),EH=await o(x,J,G);if(EH!==null){if(X)I.success(`Configuration loaded from: ${x}`);return EH}}}if(H){let D=C(XH(),".config",H),j=["config",`${H}.config`];if(Q)j.push(`${Q}.config`);if(X)I.info(`Checking user config directory: ${D}`);for(let M of j)for(let S of N){let P=C(D,`${M}${S}`),x=await o(P,J,G);if(x!==null){if(X)I.success(`Configuration loaded from user config directory: ${P}`);return x}}}if(H){let D=C(XH(),".config"),j=[`.${H}.config`];if(Q)j.push(`.${Q}.config`);if(X)I.info(`Checking user config directory for dotfile configs: ${D}`);for(let M of j)for(let S of N){let P=C(D,`${M}${S}`),x=await o(P,J,G);if(x!==null){if(X)I.success(`Configuration loaded from user config directory dotfile: ${P}`);return x}}}if(H){let D=XH(),j=[`.${H}.config`,`.${H}`];if(Q)j.push(`.${Q}.config`),j.push(`.${Q}`);if(X)I.info(`Checking user home directory for dotfile configs: ${D}`);for(let M of j)for(let S of N){let P=C(D,`${M}${S}`),x=await o(P,J,G);if(x!==null){if(X)I.success(`Configuration loaded from user home directory: ${P}`);return x}}}try{let D=C(q,"package.json");if(mH(D)){let j=await import(D),M=j[H];if(!M&&Q){if(M=j[Q],M&&X)I.success(`Using alias "${Q}" configuration from package.json`)}if(M&&typeof M==="object"&&!Array.isArray(M))try{if(X)I.success(`Configuration loaded from package.json: ${M===j[H]?H:Q}`);return DH(J,M,G)}catch(S){if(X)I.warn("Failed to merge package.json config:",S)}}}catch(D){if(X)I.warn("Failed to load package.json:",D)}if(X)I.info(`No configuration found for "${H}"${Q?` or alias "${Q}"`:""}, using default configuration with environment variables`);return J}var wU=C(g.cwd(),"config"),CU=C(g.cwd(),"src/generated");function TQ(H,Q={}){let U=e.cwd();while(U.includes("storage"))U=TH(U,"..");let Z=TH(U,H||"");if(Q?.relative)return tH(e.cwd(),Z);return Z}var FQ=e.env.CLARITY_LOG_DIR||sH(TQ(),"logs"),WH={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:FQ,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1,writeToFile:!1};async function BQ(){try{let H=await EQ({name:"clarity",alias:"logging",defaultConfig:WH,cwd:e.cwd()});return{...WH,...H||{}}}catch{return WH}}var PH=await BQ();function T(){if(b.env.NODE_ENV==="test"||b.env.BUN_ENV==="test")return!1;return typeof window<"u"}async function SQ(){if(b.env.NODE_ENV==="test"||b.env.BUN_ENV==="test")return!0;if(typeof navigator<"u"&&navigator.product==="ReactNative")return!0;if(typeof b<"u"){let H=b.type;if(H==="renderer"||H==="worker")return!1;return!!(b.versions&&(b.versions.node||b.versions.bun))}return!1}class nH{async format(H){let Q=await SQ(),U=await this.getMetadata(Q);return JSON.stringify({timestamp:H.timestamp.toISOString(),level:H.level,name:H.name,message:H.message,metadata:U})}async getMetadata(H){if(H){let{hostname:Q}=await import("os");return{pid:c.pid,hostname:Q(),environment:c.env.NODE_ENV||"development",platform:c.platform,version:c.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:c.env.NODE_ENV||c.env.BUN_ENV||"development",viewport:{width:window.innerWidth,height:window.innerHeight},language:navigator.language}}}var B={red:(H)=>`\x1B[31m${H}\x1B[0m`,green:(H)=>`\x1B[32m${H}\x1B[0m`,yellow:(H)=>`\x1B[33m${H}\x1B[0m`,blue:(H)=>`\x1B[34m${H}\x1B[0m`,magenta:(H)=>`\x1B[35m${H}\x1B[0m`,cyan:(H)=>`\x1B[36m${H}\x1B[0m`,white:(H)=>`\x1B[37m${H}\x1B[0m`,gray:(H)=>`\x1B[90m${H}\x1B[0m`,bgRed:(H)=>`\x1B[41m${H}\x1B[0m`,bgYellow:(H)=>`\x1B[43m${H}\x1B[0m`,bgGray:(H)=>`\x1B[100m${H}\x1B[0m`,bold:(H)=>`\x1B[1m${H}\x1B[0m`,dim:(H)=>`\x1B[2m${H}\x1B[0m`,italic:(H)=>`\x1B[3m${H}\x1B[0m`,underline:(H)=>`\x1B[4m${H}\x1B[0m`,strikethrough:(H)=>`\x1B[9m${H}\x1B[0m`,reset:"\x1B[0m"},R=B,dU=B.red,hQ=B.green,pU=B.yellow,vQ=B.blue,mU=B.magenta,cU=B.cyan,uH=B.white,gU=B.gray,bQ=B.bgRed,yQ=B.bgYellow,nU=B.bgGray,dH=B.bold,lU=B.dim,iU=B.italic,oU=B.underline,aU=B.strikethrough,rU=B.reset,KH={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},fQ={debug:"\uD83D\uDD0D",info:vQ("ℹ"),success:hQ("✓"),warning:yQ(uH(dH(" WARN "))),error:bQ(uH(dH(" ERROR ")))};class n{name;fileLocks=new Map;currentKeyId=null;keys=new Map;fingersCrossedConfig;fingersCrossedActive=!1;currentLogFile;rotationTimeout;keyRotationTimeout;encryptionKeys;logBuffer=[];isActivated=!1;pendingOperations=[];enabled;fancy;tagFormat;timestampPosition;environment;config;options;formatter;timers=new Set;subLoggers=new Set;fingersCrossedBuffer=[];ANSI_PATTERN=/\u001B\[.*?m/g;activeProgressBar=null;constructor(H,Q={}){this.name=H,this.config={...PH},this.options=this.normalizeOptions(Q),this.formatter=this.options.formatter||new nH,this.enabled=Q.enabled??!0,this.fancy=Q.fancy??!0,this.tagFormat=Q.tagFormat??{prefix:"[",suffix:"]"},this.timestampPosition=Q.timestampPosition??"right",this.environment=Q.environment??_.env.APP_ENV??"local",this.fingersCrossedConfig=this.initializeFingersCrossedConfig(Q);let U={...Q},Z=Q.timestamp!==void 0;if(Z)delete U.timestamp;if(this.config={...this.config,...U,timestamp:Z||this.config.timestamp},this.currentLogFile=this.generateLogFilename(),this.encryptionKeys=new Map,this.validateEncryptionConfig()){this.setupRotation();let $=this.generateKeyId(),X=this.generateKey();this.currentKeyId=$,this.keys.set($,X),this.encryptionKeys.set($,{key:X,createdAt:new Date}),this.setupKeyRotation()}}shouldActivateFingersCrossed(H){if(!this.fingersCrossedConfig)return!1;let Q={debug:0,info:1,success:2,warning:3,error:4},U=this.fingersCrossedConfig.activationLevel??"error";return Q[H]>=Q[U]}initializeFingersCrossedConfig(H){if(!H.fingersCrossedEnabled&&H.fingersCrossed)return{...KH,...H.fingersCrossed};if(!H.fingersCrossedEnabled)return null;if(!H.fingersCrossed)return{...KH};return{...KH,...H.fingersCrossed}}normalizeOptions(H){let Q={format:"json",level:"info",logDirectory:PH.logDirectory,rotation:void 0,timestamp:void 0,fingersCrossed:{},enabled:!0,showTags:!1,showIcons:!0,formatter:void 0},U={...Q,...Object.fromEntries(Object.entries(H).filter(([,Z])=>Z!==void 0))};if(!U.level||!["debug","info","success","warning","error"].includes(U.level))U.level=Q.level;return U}shouldWriteToFile(){return!T()&&this.config.writeToFile===!0}async writeToFile(H){let U=(async()=>{let $,X=0,Y=3,G=1000;while(X<Y)try{try{try{await wQ(this.config.logDirectory,bH.F_OK|bH.W_OK)}catch(q){if(q instanceof Error&&"code"in q)if(q.code==="ENOENT")await CQ(this.config.logDirectory,{recursive:!0,mode:493});else if(q.code==="EACCES")throw Error(`No write permission for log directory: ${this.config.logDirectory}`);else throw q;else throw q}}catch(q){throw console.error("Debug: [writeToFile] Failed to create log directory:",q),q}let J=this.validateEncryptionConfig()?(await this.encrypt(H)).encrypted:h.from(H);try{if(!a(this.currentLogFile))await RH(this.currentLogFile,"",{mode:420});if($=vH(this.currentLogFile,"a",420),IQ($,J,{flag:"a"}),hH($),$!==void 0)_H($),$=void 0;if((await p(this.currentLogFile)).size===0){if(await RH(this.currentLogFile,J,{flag:"w",mode:420}),(await p(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(q){let N=q;if(N.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(N.code)){if(X<Y-1){let A=typeof N.message==="string"?N.message:"Unknown error";console.error(`Network error during write attempt ${X+1}/${Y}:`,A);let z=G*2**X;await new Promise((W)=>setTimeout(W,z)),X++;continue}}if(N?.code&&["ENOSPC","EDQUOT"].includes(N.code))throw Error(`Disk quota exceeded or no space left on device: ${N.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",N),N}finally{if($!==void 0)try{_H($)}catch(q){console.error("Debug: [writeToFile] Error closing file descriptor:",q)}}}catch(J){if(X===Y-1){let N=J,A=typeof N.message==="string"?N.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",A),J}X++;let q=G*2**(X-1);await new Promise((N)=>setTimeout(N,q))}})();this.pendingOperations.push(U);let Z=this.pendingOperations.length-1;try{await U}catch($){throw console.error("Debug: [writeToFile] Error in operation:",$),$}finally{this.pendingOperations.splice(Z,1)}}generateLogFilename(){if(this.name.includes("stream-throughput")||this.name.includes("decompress-perf-test")||this.name.includes("decompression-latency")||this.name.includes("concurrent-read-test")||this.name.includes("clock-change-test"))return m(this.config.logDirectory,`${this.name}.log`);if(this.name.includes("pending-test")||this.name.includes("temp-file-test")||this.name==="crash-test"||this.name==="corrupt-test"||this.name.includes("rotation-load-test")||this.name==="sigterm-test"||this.name==="sigint-test"||this.name==="failed-rotation-test"||this.name==="integration-test")return m(this.config.logDirectory,`${this.name}.log`);let H=new Date().toISOString().split("T")[0];return m(this.config.logDirectory,`${this.name}-${H}.log`)}setupRotation(){if(T())return;if(!this.shouldWriteToFile())return;if(typeof this.config.rotation==="boolean")return;let H=this.config.rotation,Q;switch(H.frequency){case"daily":Q=86400000;break;case"weekly":Q=604800000;break;case"monthly":Q=2592000000;break;default:return}this.rotationTimeout=setInterval(()=>{this.rotateLog()},Q)}setupKeyRotation(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation setup");return}let Q=this.config.rotation.keyRotation;if(!Q?.enabled)return;let U=typeof Q.interval==="number"?Q.interval:60,Z=Math.max(U,60)*1000;this.keyRotationTimeout=setInterval(()=>{this.rotateKeys().catch(($)=>{console.error("Error rotating keys:",$)})},Z)}async rotateKeys(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation");return}let Q=this.config.rotation.keyRotation,U=this.generateKeyId(),Z=this.generateKey();this.currentKeyId=U,this.keys.set(U,Z),this.encryptionKeys.set(U,{key:Z,createdAt:new Date});let $=Array.from(this.encryptionKeys.entries()).sort(([,G],[,J])=>J.createdAt.getTime()-G.createdAt.getTime()),X=typeof Q.maxKeys==="number"?Q.maxKeys:1,Y=Math.max(1,X);if($.length>Y)for(let[G]of $.slice(Y))this.encryptionKeys.delete(G),this.keys.delete(G)}generateKeyId(){return zH(16).toString("hex")}generateKey(){return zH(32)}getCurrentKey(){if(!this.currentKeyId)throw Error("Encryption is not properly initialized. Make sure encryption is enabled in the configuration.");let H=this.keys.get(this.currentKeyId);if(!H)throw Error(`No key found for ID ${this.currentKeyId}. The encryption key may have been rotated or removed.`);return{key:H,id:this.currentKeyId}}encrypt(H){let{key:Q}=this.getCurrentKey(),U=zH(16),Z=OQ("aes-256-gcm",Q,U),$=h.isBuffer(H)?H:h.from(H,"utf8"),X=Z.update($),Y=Z.final(),G=X.length+Y.length,J=Z.getAuthTag(),q=h.allocUnsafe(16+G+16);return U.copy(q,0),X.copy(q,16),Y.copy(q,16+X.length),J.copy(q,16+G),{encrypted:q,iv:U}}async compressData(H){return new Promise((Q,U)=>{let Z=fH(),$=[];Z.on("data",(X)=>$.push(X)),Z.on("end",()=>Q(h.from(h.concat($)))),Z.on("error",U),Z.write(H),Z.end()})}getEncryptionOptions(){if(!this.config.rotation||typeof this.config.rotation==="boolean"||!this.config.rotation.encrypt)return{};let H={algorithm:"aes-256-cbc",compress:!1};if(typeof this.config.rotation.encrypt==="object"){let Q=this.config.rotation.encrypt;return{...H,...Q}}return H}async rotateLog(){if(T())return;if(!this.shouldWriteToFile())return;let H=await p(this.currentLogFile).catch(()=>null);if(!H)return;let Q=this.config.rotation;if(typeof Q==="boolean")return;if(Q.maxSize&&H.size>=Q.maxSize){let U=this.currentLogFile,Z=this.generateLogFilename();if(this.name.includes("rotation-load-test")||this.name==="failed-rotation-test"){let $=await r(this.config.logDirectory),X=$.filter((J)=>J.startsWith(this.name)&&/\.log\.\d+$/.test(J)).sort((J,q)=>{let N=Number.parseInt(J.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(q.match(/\.log\.(\d+)$/)?.[1]||"0")-N}),Y=X.length>0?Number.parseInt(X[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,G=`${U}.${Y}`;if(await p(U).catch(()=>null))try{if(await yH(U,G),Q.compress)try{let J=`${G}.gz`;await this.compressLogFile(G,J),await s(G)}catch(J){console.error("Error compressing rotated file:",J)}if(X.length===0&&!$.some((J)=>J.endsWith(".log.1")))try{let J=`${U}.1`;await RH(J,"")}catch(J){console.error("Error creating backup file:",J)}}catch(J){console.error(`Error during rotation: ${J instanceof Error?J.message:String(J)}`)}}else{let $=new Date().toISOString().replace(/[:.]/g,"-"),X=U.replace(/\.log$/,`-${$}.log`);if(await p(U).catch(()=>null))await yH(U,X)}if(this.currentLogFile=Z,Q.maxFiles){let X=(await r(this.config.logDirectory)).filter((Y)=>Y.startsWith(this.name)).sort((Y,G)=>G.localeCompare(Y));for(let Y of X.slice(Q.maxFiles))await s(m(this.config.logDirectory,Y))}}}async compressLogFile(H,Q){let U=SH(H),Z=MQ(Q),$=fH();await PQ(U,$,Z)}async handleFingersCrossedBuffer(H,Q){if(!this.fingersCrossedConfig)return;if(this.shouldActivateFingersCrossed(H)&&!this.isActivated){this.isActivated=!0;for(let U of this.logBuffer){let Z=await this.formatter.format(U);if(this.shouldWriteToFile())await this.writeToFile(Z);console.log(Z)}if(this.fingersCrossedConfig.stopBuffering)this.logBuffer=[]}if(this.isActivated){if(this.shouldWriteToFile())await this.writeToFile(Q);console.log(Q)}}shouldLog(H){if(!this.enabled)return!1;let Q={debug:0,info:1,success:2,warning:3,error:4};return Q[H]>=Q[this.config.level]}async flushPendingWrites(){if(await Promise.all(this.pendingOperations.map((H)=>{if(H instanceof Promise)return H.catch((Q)=>{console.error("Error in pending write operation:",Q)});return Promise.resolve()})),a(this.currentLogFile))try{let H=vH(this.currentLogFile,"r+");hH(H),_H(H)}catch(H){console.error(`Error flushing file: ${H}`)}}async destroy(){if(this.rotationTimeout)clearInterval(this.rotationTimeout);if(this.keyRotationTimeout)clearInterval(this.keyRotationTimeout);this.timers.clear();for(let H of this.pendingOperations)if(typeof H.cancel==="function")H.cancel();return(async()=>{if(this.pendingOperations.length>0)try{await Promise.allSettled(this.pendingOperations)}catch(H){console.error("Error waiting for pending operations:",H)}if(!T()&&this.config.rotation&&typeof this.config.rotation!=="boolean"&&this.config.rotation.compress)try{let Q=(await r(this.config.logDirectory)).filter((U)=>(U.includes("temp")||U.includes(".tmp"))&&U.includes(this.name));for(let U of Q)try{await s(m(this.config.logDirectory,U))}catch(Z){console.error(`Failed to delete temp file ${U}:`,Z)}}catch(H){console.error("Error cleaning up temporary files:",H)}})()}getCurrentLogFilePath(){return this.currentLogFile}formatTag(H){if(!H)return"";return`${this.tagFormat.prefix}${H}${this.tagFormat.suffix}`}formatFileTimestamp(H){return`[${H.toISOString()}]`}formatConsoleTimestamp(H){return this.shouldStyleConsole()?R.gray(H.toLocaleTimeString()):H.toLocaleTimeString()}shouldStyleConsole(){if(!this.fancy||T())return!1;let H=typeof _.env.NO_COLOR<"u",Q=_.env.FORCE_COLOR==="0";if(H||Q)return!1;return!!(typeof _.stderr<"u"&&_.stderr.isTTY||typeof _.stdout<"u"&&_.stdout.isTTY)}formatConsoleMessage(H){let{timestamp:Q,icon:U="",tag:Z="",message:$,level:X,showTimestamp:Y=!0}=H,G=(W)=>W.replace(this.ANSI_PATTERN,"");if(!this.fancy){let W=[];if(Y)W.push(Q);if(X==="warning")W.push("WARN");else if(X==="error")W.push("ERROR");else if(U)W.push(U.replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu,""));if(Z)W.push(Z.replace(/[[\]]/g,""));return W.push($),W.join(" ")}let J=_.stdout.columns||120,q="";if(X==="warning"||X==="error")q=`${U} ${$}`;else if(X==="info"||X==="success")q=`${U} ${Z} ${$}`;else q=`${U} ${Z} ${R.cyan($)}`;if(!Y)return q.trim();let N=G(q).trim().length,A=G(Q).length,z=Math.max(1,J-2-N-A);return`${q.trim()}${" ".repeat(z)}${Q}`}formatMessage(H,Q){if(Q.length===1&&Array.isArray(Q[0]))return H.replace(/\{(\d+)\}/g,(X,Y)=>{let G=Number.parseInt(Y,10);return G<Q[0].length?String(Q[0][G]):X});let U=/%([sdijfo%])/g,Z=0,$=H.replace(U,(X,Y)=>{if(Y==="%")return"%";if(Z>=Q.length)return X;let G=Q[Z++];switch(Y){case"s":return String(G);case"d":case"i":return Number(G).toString();case"j":case"o":return JSON.stringify(G,null,2);default:return X}});if(Z<Q.length)$+=` ${Q.slice(Z).map((X)=>typeof X==="object"?JSON.stringify(X,null,2):String(X)).join(" ")}`;return $}formatMarkdown(H){if(!H)return H;let Q=H;return Q=Q.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(U,Z,$)=>{let X=R.underline(R.blue(Z)),Y=this.toAbsoluteFilePath($);if(Y&&this.shouldStyleConsole()&&this.supportsHyperlinks()){let G=`file://${encodeURI(Y)}`,J="\x1B]8;;",q="\x1B\\";return`\x1B]8;;${G}\x1B\\${X}\x1B]8;;\x1B\\`}if(this.shouldStyleConsole()&&this.supportsHyperlinks())return`\x1B]8;;${$}\x1B\\${X}\x1B]8;;\x1B\\`;return X}),Q=Q.replace(/`([^`]+)`/g,(U,Z)=>R.bgGray(Z)),Q=Q.replace(/\*\*([^*]+)\*\*/g,(U,Z)=>R.bold(Z)),Q=Q.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g,(U,Z)=>R.italic(Z)),Q=Q.replace(/(?<!_)_([^_]+)_(?!_)/g,(U,Z)=>R.italic(Z)),Q=Q.replace(/~([^~]+)~/g,(U,Z)=>R.strikethrough(Z)),Q}supportsHyperlinks(){if(T())return!1;let H=_.env;if(!H)return!1;if(H.TERM_PROGRAM==="iTerm.app"||H.TERM_PROGRAM==="vscode"||H.TERM_PROGRAM==="WezTerm")return!0;if(H.WT_SESSION)return!0;if(H.TERM==="xterm-kitty")return!0;let Q=H.VTE_VERSION?Number.parseInt(H.VTE_VERSION,10):0;if(!Number.isNaN(Q)&&Q>=5000)return!0;return!1}toAbsoluteFilePath(H){try{let Q=H;if(Q.startsWith("file://"))Q=Q.replace(/^file:\/\//,"");if(Q.startsWith("~")){let U=_.env.HOME||"";if(U)Q=Q.replace(/^~(?=$|\/)/,U)}if(kQ(Q)||Q.startsWith("./")||Q.startsWith("../"))Q=xQ(Q);else return null;return a(Q)?Q:null}catch{return null}}buildOutputTexts(H){let Q=this.shouldStyleConsole()?this.formatMarkdown(H):H,U=H.replace(this.ANSI_PATTERN,"");return{consoleText:Q,fileText:U}}async log(H,Q,...U){let Z=new Date,$=this.formatConsoleTimestamp(Z),X=this.formatFileTimestamp(Z),Y,G;if(Q instanceof Error)Y=Q.message,G=Q.stack;else Y=this.formatMessage(Q,U);let{consoleText:J,fileText:q}=this.buildOutputTexts(Y);if(this.shouldStyleConsole()){let A=this.options.showIcons===!1?"":fQ[H],z=this.options.showTags!==!1&&this.name?R.gray(this.formatTag(this.name)):"",W;switch(H){case"debug":W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:R.gray(J),level:H}),console.error(W);break;case"info":W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:J,level:H}),console.warn(W);break;case"success":W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:R.green(J),level:H}),console.error(W);break;case"warning":W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:J,level:H}),console.warn(W);break;case"error":if(W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:J,level:H}),console.error(W),G){let k=G.split(`
|
|
10
|
+
`);for(let F of k)if(F.trim()&&!F.includes(Y))console.error(this.formatConsoleMessage({timestamp:$,message:R.gray(` ${F}`),level:H,showTimestamp:!1}))}break}}else if(!T()){if(console.error(`${X} ${this.environment}.${H.toUpperCase()}: ${Y}`),G)console.error(G)}if(!this.shouldLog(H))return;let N=`${X} ${this.environment}.${H.toUpperCase()}: ${q}
|
|
11
|
+
`;if(G)N+=`${G}
|
|
12
|
+
`;if(N=N.replace(this.ANSI_PATTERN,""),this.shouldWriteToFile())await this.writeToFile(N)}progress(H,Q=""){let U={update:(G,J)=>{},finish:(G)=>{},interrupt:(G,J)=>{}};if(!this.enabled)return U;let Z=30;if(this.activeProgressBar={total:Math.max(1,H||1),current:0,message:Q||"",barLength:Z,lastRenderedLine:""},this.shouldStyleConsole()&&!T()&&_.stdout.isTTY)this.renderProgressBar(this.activeProgressBar);return{update:(G,J)=>{if(!this.enabled||!this.activeProgressBar)return;if(this.activeProgressBar.current=Math.min(Math.max(0,G),this.activeProgressBar.total),J!==void 0)this.activeProgressBar.message=J;if(this.shouldStyleConsole()&&!T()&&_.stdout.isTTY)this.renderProgressBar(this.activeProgressBar)},finish:(G)=>{if(!this.activeProgressBar)return;this.finishProgressBar(this.activeProgressBar,G)},interrupt:(G,J="info")=>{if(!T()&&_.stdout.isTTY)_.stdout.write(`
|
|
13
|
+
`);if(this[J==="warning"?"warn":J](G),this.activeProgressBar&&this.shouldStyleConsole()&&!T()&&_.stdout.isTTY)this.renderProgressBar(this.activeProgressBar)}}}time(H){let Q=performance.now();if(this.shouldStyleConsole()){let U=this.options.showTags!==!1&&this.name?R.gray(this.formatTag(this.name)):"",Z=this.formatConsoleTimestamp(new Date);console.error(this.formatConsoleMessage({timestamp:Z,icon:this.options.showIcons===!1?"":R.blue("◐"),tag:U,message:`${R.cyan(H)}...`}))}return async(U)=>{if(!this.enabled)return;let Z=performance.now(),$=Math.round(Z-Q),X=`${H} completed in ${$}ms`,Y=new Date,G=this.formatConsoleTimestamp(Y),q=`${this.formatFileTimestamp(Y)} ${this.environment}.INFO: ${X}`;if(U)q+=` ${JSON.stringify(U)}`;if(q+=`
|
|
14
|
+
`,q=q.replace(this.ANSI_PATTERN,""),this.shouldStyleConsole()){let N=this.options.showTags!==!1&&this.name?R.gray(this.formatTag(this.name)):"";console.error(this.formatConsoleMessage({timestamp:G,icon:this.options.showIcons===!1?"":R.green("✓"),tag:N,message:`${X}${U?` ${JSON.stringify(U)}`:""}`}))}else if(!T())console.error(q.trim());if(this.shouldWriteToFile())await this.writeToFile(q)}}async debug(H,...Q){await this.log("debug",H,...Q)}async info(H,...Q){await this.log("info",H,...Q)}async success(H,...Q){await this.log("success",H,...Q)}async warn(H,...Q){await this.log("warning",H,...Q)}async error(H,...Q){await this.log("error",H,...Q)}validateEncryptionConfig(){if(!this.config.rotation)return!1;if(typeof this.config.rotation==="boolean")return!1;let H=this.config.rotation,{encrypt:Q}=H;return!!Q}async only(H){if(!this.enabled)return;return await H()}isEnabled(){return this.enabled}setEnabled(H){this.enabled=H}extend(H){let Q=`${this.name}:${H}`,U=new n(Q,{...this.options,logDirectory:this.config.logDirectory,level:this.config.level,format:this.config.format,rotation:typeof this.config.rotation==="boolean"?void 0:this.config.rotation,timestamp:typeof this.config.timestamp==="boolean"?void 0:this.config.timestamp});return this.subLoggers.add(U),U}createReadStream(){if(T())throw Error("createReadStream is not supported in browser environments");if(!a(this.currentLogFile))throw Error(`Log file does not exist: ${this.currentLogFile}`);return SH(this.currentLogFile,{encoding:"utf8"})}async decrypt(H){if(!this.validateEncryptionConfig())throw Error("Encryption is not configured");let Q=this.config.rotation;if(!Q.encrypt||typeof Q.encrypt==="boolean")throw Error("Invalid encryption configuration");if(!this.currentKeyId||!this.keys.has(this.currentKeyId))throw Error("No valid encryption key available");let U=this.keys.get(this.currentKeyId);try{let Z=h.isBuffer(H)?H:h.from(H,"base64"),$=Z.subarray(0,16),X=Z.subarray(Z.length-16),Y=Z.subarray(16,Z.length-16),G=jQ("aes-256-gcm",U,$);G.setAuthTag(X);let J=G.update(Y),q=G.final(),N=J.length+q.length,A=h.allocUnsafe(N);return J.copy(A,0),q.copy(A,J.length),A.toString("utf8")}catch(Z){throw Error(`Decryption failed: ${Z instanceof Error?Z.message:String(Z)}`)}}getLevel(){return this.config.level}getLogDirectory(){return this.config.logDirectory}getFormat(){return this.config.format}getRotationConfig(){return this.config.rotation}isBrowserMode(){return T()}isServerMode(){return!T()}setTestEncryptionKey(H,Q){this.currentKeyId=H,this.keys.set(H,Q)}getTestCurrentKey(){if(!this.currentKeyId||!this.keys.has(this.currentKeyId))return null;return{id:this.currentKeyId,key:this.keys.get(this.currentKeyId)}}getConfig(){return this.config}async box(H){if(!this.enabled)return;let Q=new Date,U=this.formatConsoleTimestamp(Q),Z=this.formatFileTimestamp(Q),{consoleText:$,fileText:X}=this.buildOutputTexts(H);if(this.shouldStyleConsole()){let G=$.split(`
|
|
15
|
+
`),J=Math.max(...G.map((z)=>z.length))+2,q=`┌${"─".repeat(J)}┐`,N=`└${"─".repeat(J)}┘`,A=G.map((z)=>{return this.formatConsoleMessage({timestamp:U,message:R.cyan(z),showTimestamp:!1})});console.error(this.formatConsoleMessage({timestamp:U,message:R.cyan(q),showTimestamp:!1})),A.forEach((z)=>console.error(z)),console.error(this.formatConsoleMessage({timestamp:U,message:R.cyan(N),showTimestamp:!1}))}else if(!T())console.error(`${Z} ${this.environment}.INFO: [BOX] ${X}`);let Y=`${Z} ${this.environment}.INFO: [BOX] ${X}
|
|
16
|
+
`.replace(this.ANSI_PATTERN,"");if(this.shouldWriteToFile())await this.writeToFile(Y)}async prompt(H){if(T())return Promise.resolve(!0);return new Promise((Q)=>{console.error(`${R.cyan("?")} ${H} (y/n) `);let U=(Z)=>{let $=Z.toString().trim().toLowerCase();_.stdin.removeListener("data",U);try{if(typeof _.stdin.setRawMode==="function")_.stdin.setRawMode(!1)}catch{}_.stdin.pause(),console.error(""),Q($==="y"||$==="yes")};try{if(typeof _.stdin.setRawMode==="function")_.stdin.setRawMode(!0)}catch{}_.stdin.resume(),_.stdin.once("data",U)})}setFancy(H){this.fancy=H}isFancy(){return this.fancy}pause(){this.enabled=!1}resume(){this.enabled=!0}async start(H,...Q){if(!this.enabled)return;let U=H;if(Q&&Q.length>0){let J=/%([sdijfo%])/g,q=0;if(U=H.replace(J,(N,A)=>{if(A==="%")return"%";if(q>=Q.length)return N;let z=Q[q++];switch(A){case"s":return String(z);case"d":case"i":return Number(z).toString();case"j":case"o":return JSON.stringify(z,null,2);default:return N}}),q<Q.length)U+=` ${Q.slice(q).map((N)=>typeof N==="object"?JSON.stringify(N,null,2):String(N)).join(" ")}`}let{consoleText:Z,fileText:$}=this.buildOutputTexts(U);if(this.shouldStyleConsole()){let J=this.options.showTags!==!1&&this.name?R.gray(this.formatTag(this.name)):"",q=this.options.showIcons===!1?"":`${R.blue("◐")} `;console.error(`${q}${J} ${R.cyan(Z)}`)}let G=`[${new Date().toISOString()}] ${this.environment}.INFO: [START] ${$}
|
|
17
|
+
`.replace(this.ANSI_PATTERN,"");if(this.shouldWriteToFile())await this.writeToFile(G)}renderProgressBar(H,Q=!1){if(!this.enabled||!this.shouldStyleConsole()||!_.stdout.isTTY)return;let U=Math.min(100,Math.max(0,Math.round(H.current/H.total*100))),Z=Math.round(H.barLength*U/100),$=H.barLength-Z,X=R.green("━".repeat(Z)),Y=R.gray("━".repeat($)),G=`[${X}${Y}]`,J=`${U}%`.padStart(4),q=H.message?` ${H.message}`:"",N=this.options.showIcons===!1?"":Q||U===100?R.green("✓"):R.blue("▶"),A=this.options.showTags!==!1&&this.name?` ${R.gray(this.formatTag(this.name))}`:"",z=`\r${N}${A} ${G} ${J}${q}`,W=_.stdout.columns||80,k=" ".repeat(Math.max(0,W-z.replace(this.ANSI_PATTERN,"").length));if(H.lastRenderedLine=`${z}${k}`,_.stdout.write(H.lastRenderedLine),Q)_.stdout.write(`
|
|
18
|
+
`)}finishProgressBar(H,Q){if(!this.enabled||!this.fancy||T()||!_.stdout.isTTY){this.activeProgressBar=null;return}if(H.current<H.total)H.current=H.total;if(Q)H.message=Q;this.renderProgressBar(H,!0),this.activeProgressBar=null}async clear(H={}){if(T()){console.warn("Log clearing is not supported in browser environments.");return}try{console.warn("Clearing logs...",this.config.logDirectory);let Q=await r(this.config.logDirectory),U=[];for(let Z of Q){if(!(H.name?new RegExp(H.name.replace("*",".*")).test(Z):Z.startsWith(this.name))||!Z.endsWith(".log"))continue;let X=m(this.config.logDirectory,Z);if(H.before)try{if((await p(X)).mtime>=H.before)continue}catch(Y){console.error(`Failed to get stats for file ${X}:`,Y);continue}U.push(X)}if(U.length===0){console.warn("No log files matched the criteria for clearing.");return}console.warn(`Preparing to delete ${U.length} log file(s)...`);for(let Z of U)try{await s(Z),console.warn(`Deleted log file: ${Z}`)}catch($){console.error(`Failed to delete log file ${Z}:`,$)}console.warn("Log clearing process finished.")}catch(Q){console.error("Error during log clearing process:",Q)}}}var sU=new n("stacks");var uQ=new n("rpx",{showTags:!1});function dQ(){return process.env.SUDO_PASSWORD}function QZ(H){let Q=dQ();if(Q)return lH(`echo '${Q}' | sudo -S ${H}`,{encoding:"utf-8",stdio:["pipe","pipe","pipe"]});return lH(`sudo ${H}`,{encoding:"utf-8"})}function iH(H,Q,U){if(U)uQ.debug(`[rpx:${H}] ${Q}`)}function UZ(H){if(aH(H))return H.proxies.map((Q)=>{let U=Q.to||"stacks.localhost";return U.startsWith("http")?new URL(U).hostname:U});if(rH(H)){let Q=H.to||"stacks.localhost";return[Q.startsWith("http")?new URL(Q).hostname:Q]}return["stacks.localhost"]}function ZZ(H){return typeof H==="object"&&H!==null&&"certificate"in H&&"privateKey"in H&&typeof H.certificate==="string"&&typeof H.privateKey==="string"}function $Z(H){if(!H)return"stacks.localhost";if(aH(H)&&H.proxies.length>0)return H.proxies[0].to||"stacks.localhost";if(rH(H))return H.to||"stacks.localhost";return"stacks.localhost"}function XZ(H){return!!(H&&("proxies"in H)&&Array.isArray(H.proxies))}function aH(H){return"proxies"in H&&Array.isArray(H.proxies)}function rH(H){return"to"in H&&typeof H.to==="string"}function YZ(H){return!!(H&&("to"in H)&&!("proxies"in H))}async function JZ(H,Q){try{await oH.unlink(H),iH("certificates",`Successfully deleted: ${H}`,Q)}catch(U){if(U.code!=="ENOENT")iH("certificates",`Warning: Could not delete ${H}: ${U}`,Q)}}
|
|
19
|
+
export{dQ as C,QZ as D,iH as E,UZ as F,ZZ as G,$Z as H,XZ as I,aH as J,rH as K,YZ as L,JZ as M};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import{P as q}from"./chunk-4960052z.js";import{createRequire as X}from"node:module";import{formatWithOptions as ED}from"node:util";import{sep as iD}from"node:path";import*as b from"node:tty";import g from"node:process";var J=Object.create,{getPrototypeOf:DD,defineProperty:N,getOwnPropertyNames:uD}=Object,tD=Object.prototype.hasOwnProperty,zD=(u,t,e)=>{e=u!=null?J(DD(u)):{};let F=t||!u||!u.__esModule?N(e,"default",{value:u,enumerable:!0}):e;for(let r of uD(u))if(!tD.call(F,r))N(F,r,{get:()=>u[r],enumerable:!0});return F},HD=(u,t)=>()=>(t||u((t={exports:{}}).exports,t),t.exports),KD=X(import.meta.url),n={silent:Number.NEGATIVE_INFINITY,fatal:0,error:0,warn:1,log:2,info:3,success:3,fail:3,ready:3,start:3,box:3,debug:4,trace:5,verbose:Number.POSITIVE_INFINITY},M={silent:{level:-1},fatal:{level:n.fatal},error:{level:n.error},warn:{level:n.warn},log:{level:n.log},info:{level:n.info},success:{level:n.success},fail:{level:n.fail},ready:{level:n.info},start:{level:n.info},box:{level:n.info},debug:{level:n.debug},trace:{level:n.trace},verbose:{level:n.verbose}};function L(u){return u!==null&&typeof u==="object"}function O(u,t,e=".",F){if(!L(t))return O(u,{},e,F);let r=Object.assign({},t);for(let o in u){if(o==="__proto__"||o==="constructor")continue;let D=u[o];if(D===null||D===void 0)continue;if(F&&F(r,o,D,e))continue;if(Array.isArray(D)&&Array.isArray(r[o]))r[o]=[...D,...r[o]];else if(L(D)&&L(r[o]))r[o]=O(D,r[o],(e?`${e}.`:"")+o.toString(),F);else r[o]=D}return r}function FD(u){return(...t)=>t.reduce((e,F)=>O(e,F,"",u),{})}var eD=FD();function rD(u){return Object.prototype.toString.call(u)==="[object Object]"}function oD(u){if(!rD(u))return!1;if(!u.message&&!u.args)return!1;if(u.stack)return!1;return!0}var T=!1,U=[];class i{constructor(u={}){let t=u.types||M;this.options=eD({...u,defaults:{...u.defaults},level:S(u.level,t),reporters:[...u.reporters||[]]},{types:M,throttle:1000,throttleMin:5,formatOptions:{date:!0,colors:!1,compact:!0}});for(let e in t){let F={type:e,...this.options.defaults,...t[e]};this[e]=this._wrapLogFn(F),this[e].raw=this._wrapLogFn(F,!0)}if(this.options.mockFn)this.mockTypes();this._lastLog={}}get level(){return this.options.level}set level(u){this.options.level=S(u,this.options.types,this.options.level)}prompt(u,t){if(!this.options.prompt)throw Error("prompt is not supported!");return this.options.prompt(u,t)}create(u){let t=new i({...this.options,...u});if(this._mockFn)t.mockTypes(this._mockFn);return t}withDefaults(u){return this.create({...this.options,defaults:{...this.options.defaults,...u}})}withTag(u){return this.withDefaults({tag:this.options.defaults.tag?this.options.defaults.tag+":"+u:u})}addReporter(u){return this.options.reporters.push(u),this}removeReporter(u){if(u){let t=this.options.reporters.indexOf(u);if(t>=0)return this.options.reporters.splice(t,1)}else this.options.reporters.splice(0);return this}setReporters(u){return this.options.reporters=Array.isArray(u)?u:[u],this}wrapAll(){this.wrapConsole(),this.wrapStd()}restoreAll(){this.restoreConsole(),this.restoreStd()}wrapConsole(){for(let u in this.options.types){if(!console["__"+u])console["__"+u]=console[u];console[u]=this[u].raw}}restoreConsole(){for(let u in this.options.types)if(console["__"+u])console[u]=console["__"+u],delete console["__"+u]}wrapStd(){this._wrapStream(this.options.stdout,"log"),this._wrapStream(this.options.stderr,"log")}_wrapStream(u,t){if(!u)return;if(!u.__write)u.__write=u.write;u.write=(e)=>{this[t].raw(String(e).trim())}}restoreStd(){this._restoreStream(this.options.stdout),this._restoreStream(this.options.stderr)}_restoreStream(u){if(!u)return;if(u.__write)u.write=u.__write,delete u.__write}pauseLogs(){T=!0}resumeLogs(){T=!1;let u=U.splice(0);for(let t of u)t[0]._logFn(t[1],t[2])}mockTypes(u){let t=u||this.options.mockFn;if(this._mockFn=t,typeof t!=="function")return;for(let e in this.options.types)this[e]=t(e,this.options.types[e])||this[e],this[e].raw=this[e]}_wrapLogFn(u,t){return(...e)=>{if(T){U.push([this,u,e,t]);return}return this._logFn(u,e,t)}}_logFn(u,t,e){if((u.level||0)>this.level)return!1;let F={date:new Date,args:[],...u,level:S(u.level,this.options.types)};if(!e&&t.length===1&&oD(t[0]))Object.assign(F,t[0]);else F.args=[...t];if(F.message)F.args.unshift(F.message),delete F.message;if(F.additional){if(!Array.isArray(F.additional))F.additional=F.additional.split(`
|
|
2
|
+
`);F.args.push(`
|
|
3
|
+
`+F.additional.join(`
|
|
4
|
+
`)),delete F.additional}F.type=typeof F.type==="string"?F.type.toLowerCase():"log",F.tag=typeof F.tag==="string"?F.tag:"";let r=(D=!1)=>{let E=(this._lastLog.count||0)-this.options.throttleMin;if(this._lastLog.object&&E>0){let p=[...this._lastLog.object.args];if(E>1)p.push(`(repeated ${E} times)`);this._log({...this._lastLog.object,args:p}),this._lastLog.count=1}if(D)this._lastLog.object=F,this._log(F)};clearTimeout(this._lastLog.timeout);let o=this._lastLog.time&&F.date?F.date.getTime()-this._lastLog.time.getTime():0;if(this._lastLog.time=F.date,o<this.options.throttle)try{let D=JSON.stringify([F.type,F.tag,F.args]),E=this._lastLog.serialized===D;if(this._lastLog.serialized=D,E){if(this._lastLog.count=(this._lastLog.count||0)+1,this._lastLog.count>this.options.throttleMin){this._lastLog.timeout=setTimeout(r,this.options.throttle);return}}}catch{}r(!0)}_log(u){for(let t of this.options.reporters)t.log(u,{options:this.options})}}function S(u,t={},e=3){if(u===void 0)return e;if(typeof u==="number")return u;if(t[u]&&t[u].level!==void 0)return t[u].level;return e}i.prototype.add=i.prototype.addReporter;i.prototype.remove=i.prototype.removeReporter;i.prototype.clear=i.prototype.removeReporter;i.prototype.withScope=i.prototype.withTag;i.prototype.mock=i.prototype.mockTypes;i.prototype.pause=i.prototype.pauseLogs;i.prototype.resume=i.prototype.resumeLogs;function CD(u={}){return new i(u)}function j(u){let t=process.cwd()+iD;return u.split(`
|
|
5
|
+
`).splice(1).map((e)=>e.trim().replace("file://","").replace(t,""))}function nD(u,t){return(t.__write||t.write).call(t,u)}var R=(u)=>u?`[${u}]`:"";class w{formatStack(u,t){return" "+j(u).join(`
|
|
6
|
+
`)}formatArgs(u,t){let e=u.map((F)=>{if(F&&typeof F.stack==="string")return F.message+`
|
|
7
|
+
`+this.formatStack(F.stack,t);return F});return ED(t,...e)}formatDate(u,t){return t.date?u.toLocaleTimeString():""}filterAndJoin(u){return u.filter(Boolean).join(" ")}formatLogObj(u,t){let e=this.formatArgs(u.args,t);if(u.type==="box")return`
|
|
8
|
+
`+[R(u.tag),u.title&&u.title,...e.split(`
|
|
9
|
+
`)].filter(Boolean).map((F)=>" > "+F).join(`
|
|
10
|
+
`)+`
|
|
11
|
+
`;return this.filterAndJoin([R(u.type),R(u.tag),e])}log(u,t){let e=this.formatLogObj(u,{columns:t.options.stdout.columns||0,...t.options.formatOptions});return nD(e+`
|
|
12
|
+
`,u.level<2?t.options.stderr||process.stderr:t.options.stdout||process.stdout)}}var{env:h={},argv:G=[],platform:sD=""}=typeof process>"u"?{}:process,lD="NO_COLOR"in h||G.includes("--no-color"),aD="FORCE_COLOR"in h||G.includes("--color"),BD=sD==="win32",W=h.TERM==="dumb",pD=b&&b.isatty&&b.isatty(1)&&h.TERM&&!W,gD="CI"in h&&(("GITHUB_ACTIONS"in h)||("GITLAB_CI"in h)||("CIRCLECI"in h)),cD=!lD&&(aD||BD&&!W||pD||gD);function Y(u,t,e,F,r=t.slice(0,Math.max(0,u))+F,o=t.slice(Math.max(0,u+e.length)),D=o.indexOf(e)){return r+(D<0?o:Y(D,o,e,F))}function AD(u,t,e,F,r){return u<0?e+t+F:e+Y(u,t,F,r)+F}function hD(u,t,e=u,F=u.length+1){return(r)=>r||!(r===""||r===void 0)?AD((""+r).indexOf(t,F),r,u,t,e):""}function C(u,t,e){return hD(`\x1B[${u}m`,`\x1B[${t}m`,e)}var $={reset:C(0,0),bold:C(1,22,"\x1B[22m\x1B[1m"),dim:C(2,22,"\x1B[22m\x1B[2m"),italic:C(3,23),underline:C(4,24),inverse:C(7,27),hidden:C(8,28),strikethrough:C(9,29),black:C(30,39),red:C(31,39),green:C(32,39),yellow:C(33,39),blue:C(34,39),magenta:C(35,39),cyan:C(36,39),white:C(37,39),gray:C(90,39),bgBlack:C(40,49),bgRed:C(41,49),bgGreen:C(42,49),bgYellow:C(43,49),bgBlue:C(44,49),bgMagenta:C(45,49),bgCyan:C(46,49),bgWhite:C(47,49),blackBright:C(90,39),redBright:C(91,39),greenBright:C(92,39),yellowBright:C(93,39),blueBright:C(94,39),magentaBright:C(95,39),cyanBright:C(96,39),whiteBright:C(97,39),bgBlackBright:C(100,49),bgRedBright:C(101,49),bgGreenBright:C(102,49),bgYellowBright:C(103,49),bgBlueBright:C(104,49),bgMagentaBright:C(105,49),bgCyanBright:C(106,49),bgWhiteBright:C(107,49)};function dD(u=cD){return u?$:Object.fromEntries(Object.keys($).map((t)=>[t,String]))}var B=dD();function mD(u,t="reset"){return B[u]||B[t]}var fD=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");function m(u){return u.replace(new RegExp(fD,"g"),"")}var x={solid:{tl:"┌",tr:"┐",bl:"└",br:"┘",h:"─",v:"│"},double:{tl:"╔",tr:"╗",bl:"╚",br:"╝",h:"═",v:"║"},doubleSingle:{tl:"╓",tr:"╖",bl:"╙",br:"╜",h:"─",v:"║"},doubleSingleRounded:{tl:"╭",tr:"╮",bl:"╰",br:"╯",h:"─",v:"║"},singleThick:{tl:"┏",tr:"┓",bl:"┗",br:"┛",h:"━",v:"┃"},singleDouble:{tl:"╒",tr:"╕",bl:"╘",br:"╛",h:"═",v:"│"},singleDoubleRounded:{tl:"╭",tr:"╮",bl:"╰",br:"╯",h:"═",v:"│"},rounded:{tl:"╭",tr:"╮",bl:"╰",br:"╯",h:"─",v:"│"}},yD={borderColor:"white",borderStyle:"rounded",valign:"center",padding:2,marginLeft:1,marginTop:1,marginBottom:1};function _D(u,t={}){let e={...t,style:{...yD,...t.style}},F=u.split(`
|
|
13
|
+
`),r=[],o=mD(e.style.borderColor),D={...typeof e.style.borderStyle==="string"?x[e.style.borderStyle]||x.solid:e.style.borderStyle};if(o)for(let s in D)D[s]=o(D[s]);let E=e.style.padding%2===0?e.style.padding:e.style.padding+1,p=F.length+E,l=Math.max(...F.map((s)=>s.length))+E,c=l+E,a=e.style.marginLeft>0?" ".repeat(e.style.marginLeft):"";if(e.style.marginTop>0)r.push("".repeat(e.style.marginTop));if(e.title){let s=D.h.repeat(Math.floor((l-m(e.title).length)/2)),_=D.h.repeat(l-m(e.title).length-m(s).length+E);r.push(`${a}${D.tl}${s}${e.title}${_}${D.tr}`)}else r.push(`${a}${D.tl}${D.h.repeat(c)}${D.tr}`);let d=e.style.valign==="center"?Math.floor((p-F.length)/2):e.style.valign==="top"?p-F.length-E:p-F.length;for(let s=0;s<p;s++)if(s<d||s>=d+F.length)r.push(`${a}${D.v}${" ".repeat(c)}${D.v}`);else{let _=F[s-d],K=" ".repeat(E),Q=" ".repeat(l-m(_).length);r.push(`${a}${D.v}${K}${_}${Q}${D.v}`)}if(r.push(`${a}${D.bl}${D.h.repeat(c)}${D.br}`),e.style.marginBottom>0)r.push("".repeat(e.style.marginBottom));return r.join(`
|
|
14
|
+
`)}var vD=[["APPVEYOR"],["AZURE_PIPELINES","SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],["AZURE_STATIC","INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],["APPCIRCLE","AC_APPCIRCLE"],["BAMBOO","bamboo_planKey"],["BITBUCKET","BITBUCKET_COMMIT"],["BITRISE","BITRISE_IO"],["BUDDY","BUDDY_WORKSPACE_ID"],["BUILDKITE"],["CIRCLE","CIRCLECI"],["CIRRUS","CIRRUS_CI"],["CLOUDFLARE_PAGES","CF_PAGES",{ci:!0}],["CODEBUILD","CODEBUILD_BUILD_ARN"],["CODEFRESH","CF_BUILD_ID"],["DRONE"],["DRONE","DRONE_BUILD_EVENT"],["DSARI"],["GITHUB_ACTIONS"],["GITLAB","GITLAB_CI"],["GITLAB","CI_MERGE_REQUEST_ID"],["GOCD","GO_PIPELINE_LABEL"],["LAYERCI"],["HUDSON","HUDSON_URL"],["JENKINS","JENKINS_URL"],["MAGNUM"],["NETLIFY"],["NETLIFY","NETLIFY_LOCAL",{ci:!1}],["NEVERCODE"],["RENDER"],["SAIL","SAILCI"],["SEMAPHORE"],["SCREWDRIVER"],["SHIPPABLE"],["SOLANO","TDDIUM"],["STRIDER"],["TEAMCITY","TEAMCITY_VERSION"],["TRAVIS"],["VERCEL","NOW_BUILDER"],["APPCENTER","APPCENTER_BUILD_ID"],["CODESANDBOX","CODESANDBOX_SSE",{ci:!1}],["STACKBLITZ"],["STORMKIT"],["CLEAVR"]];function bD(u){for(let t of vD){let e=t[1]||t[0];if(u[e])return{name:t[0].toLowerCase(),...t[2]}}if(u.SHELL&&u.SHELL==="/bin/jsh")return{name:"stackblitz",ci:!1};return{name:"",ci:!1}}var I=typeof process<"u"?process:{},f=I.env||{},V=bD(f),ID=typeof process<"u"&&process.env&&"development"||"";I.platform;V.name;var LD=y(f.CI)||V.ci!==!1,JD=y(I.stdout&&I.stdout.isTTY),TD=y(f.DEBUG),Z=ID==="test"||y(f.TEST);y(f.MINIMAL);function y(u){return u?u!=="false":!1}function SD({onlyFirst:u=!1}={}){let t=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(t,u?void 0:"g")}var RD=SD();function OD(u){if(typeof u!=="string")throw TypeError(`Expected a \`string\`, got \`${typeof u}\``);return u.replace(RD,"")}function wD(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}var z={exports:{}};(function(u){var t={};u.exports=t,t.eastAsianWidth=function(F){var r=F.charCodeAt(0),o=F.length==2?F.charCodeAt(1):0,D=r;if(55296<=r&&r<=56319&&(56320<=o&&o<=57343))r&=1023,o&=1023,D=r<<10|o,D+=65536;if(D==12288||65281<=D&&D<=65376||65504<=D&&D<=65510)return"F";if(D==8361||65377<=D&&D<=65470||65474<=D&&D<=65479||65482<=D&&D<=65487||65490<=D&&D<=65495||65498<=D&&D<=65500||65512<=D&&D<=65518)return"H";if(4352<=D&&D<=4447||4515<=D&&D<=4519||4602<=D&&D<=4607||9001<=D&&D<=9002||11904<=D&&D<=11929||11931<=D&&D<=12019||12032<=D&&D<=12245||12272<=D&&D<=12283||12289<=D&&D<=12350||12353<=D&&D<=12438||12441<=D&&D<=12543||12549<=D&&D<=12589||12593<=D&&D<=12686||12688<=D&&D<=12730||12736<=D&&D<=12771||12784<=D&&D<=12830||12832<=D&&D<=12871||12880<=D&&D<=13054||13056<=D&&D<=19903||19968<=D&&D<=42124||42128<=D&&D<=42182||43360<=D&&D<=43388||44032<=D&&D<=55203||55216<=D&&D<=55238||55243<=D&&D<=55291||63744<=D&&D<=64255||65040<=D&&D<=65049||65072<=D&&D<=65106||65108<=D&&D<=65126||65128<=D&&D<=65131||110592<=D&&D<=110593||127488<=D&&D<=127490||127504<=D&&D<=127546||127552<=D&&D<=127560||127568<=D&&D<=127569||131072<=D&&D<=194367||177984<=D&&D<=196605||196608<=D&&D<=262141)return"W";if(32<=D&&D<=126||162<=D&&D<=163||165<=D&&D<=166||D==172||D==175||10214<=D&&D<=10221||10629<=D&&D<=10630)return"Na";if(D==161||D==164||167<=D&&D<=168||D==170||173<=D&&D<=174||176<=D&&D<=180||182<=D&&D<=186||188<=D&&D<=191||D==198||D==208||215<=D&&D<=216||222<=D&&D<=225||D==230||232<=D&&D<=234||236<=D&&D<=237||D==240||242<=D&&D<=243||247<=D&&D<=250||D==252||D==254||D==257||D==273||D==275||D==283||294<=D&&D<=295||D==299||305<=D&&D<=307||D==312||319<=D&&D<=322||D==324||328<=D&&D<=331||D==333||338<=D&&D<=339||358<=D&&D<=359||D==363||D==462||D==464||D==466||D==468||D==470||D==472||D==474||D==476||D==593||D==609||D==708||D==711||713<=D&&D<=715||D==717||D==720||728<=D&&D<=731||D==733||D==735||768<=D&&D<=879||913<=D&&D<=929||931<=D&&D<=937||945<=D&&D<=961||963<=D&&D<=969||D==1025||1040<=D&&D<=1103||D==1105||D==8208||8211<=D&&D<=8214||8216<=D&&D<=8217||8220<=D&&D<=8221||8224<=D&&D<=8226||8228<=D&&D<=8231||D==8240||8242<=D&&D<=8243||D==8245||D==8251||D==8254||D==8308||D==8319||8321<=D&&D<=8324||D==8364||D==8451||D==8453||D==8457||D==8467||D==8470||8481<=D&&D<=8482||D==8486||D==8491||8531<=D&&D<=8532||8539<=D&&D<=8542||8544<=D&&D<=8555||8560<=D&&D<=8569||D==8585||8592<=D&&D<=8601||8632<=D&&D<=8633||D==8658||D==8660||D==8679||D==8704||8706<=D&&D<=8707||8711<=D&&D<=8712||D==8715||D==8719||D==8721||D==8725||D==8730||8733<=D&&D<=8736||D==8739||D==8741||8743<=D&&D<=8748||D==8750||8756<=D&&D<=8759||8764<=D&&D<=8765||D==8776||D==8780||D==8786||8800<=D&&D<=8801||8804<=D&&D<=8807||8810<=D&&D<=8811||8814<=D&&D<=8815||8834<=D&&D<=8835||8838<=D&&D<=8839||D==8853||D==8857||D==8869||D==8895||D==8978||9312<=D&&D<=9449||9451<=D&&D<=9547||9552<=D&&D<=9587||9600<=D&&D<=9615||9618<=D&&D<=9621||9632<=D&&D<=9633||9635<=D&&D<=9641||9650<=D&&D<=9651||9654<=D&&D<=9655||9660<=D&&D<=9661||9664<=D&&D<=9665||9670<=D&&D<=9672||D==9675||9678<=D&&D<=9681||9698<=D&&D<=9701||D==9711||9733<=D&&D<=9734||D==9737||9742<=D&&D<=9743||9748<=D&&D<=9749||D==9756||D==9758||D==9792||D==9794||9824<=D&&D<=9825||9827<=D&&D<=9829||9831<=D&&D<=9834||9836<=D&&D<=9837||D==9839||9886<=D&&D<=9887||9918<=D&&D<=9919||9924<=D&&D<=9933||9935<=D&&D<=9953||D==9955||9960<=D&&D<=9983||D==10045||D==10071||10102<=D&&D<=10111||11093<=D&&D<=11097||12872<=D&&D<=12879||57344<=D&&D<=63743||65024<=D&&D<=65039||D==65533||127232<=D&&D<=127242||127248<=D&&D<=127277||127280<=D&&D<=127337||127344<=D&&D<=127386||917760<=D&&D<=917999||983040<=D&&D<=1048573||1048576<=D&&D<=1114109)return"A";return"N"},t.characterLength=function(F){var r=this.eastAsianWidth(F);if(r=="F"||r=="W"||r=="A")return 2;else return 1};function e(F){return F.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g)||[]}t.length=function(F){var r=e(F),o=0;for(var D=0;D<r.length;D++)o=o+this.characterLength(r[D]);return o},t.slice=function(F,r,o){if(textLen=t.length(F),r=r?r:0,o=o?o:1,r<0)r=textLen+r;if(o<0)o=textLen+o;var D="",E=0,p=e(F);for(var l=0;l<p.length;l++){var c=p[l],a=t.length(c);if(E>=r-(a==2?1:0))if(E+a<=o)D+=c;else break;E+=a}return D}})(z);var ND=z.exports,MD=wD(ND),UD=()=>{return/[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26F9(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC3\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC08\uDC26](?:\u200D\u2B1B)?|[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC2\uDECE-\uDEDB\uDEE0-\uDEE8]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g};function $D(u,t){if(typeof u!=="string"||u.length===0)return 0;if(t={ambiguousIsNarrow:!0,countAnsiEscapeCodes:!1,...t},!t.countAnsiEscapeCodes)u=OD(u);if(u.length===0)return 0;let e=t.ambiguousIsNarrow?1:2,F=0;for(let{segment:r}of new Intl.Segmenter().segment(u)){let o=r.codePointAt(0);if(o<=31||o>=127&&o<=159)continue;if(o>=768&&o<=879)continue;if(UD().test(r)){F+=2;continue}switch(MD.eastAsianWidth(r)){case"F":case"W":{F+=2;break}case"A":{F+=e;break}default:F+=1}}return F}function xD(){if(g.platform!=="win32")return g.env.TERM!=="linux";return Boolean(g.env.CI)||Boolean(g.env.WT_SESSION)||Boolean(g.env.TERMINUS_SUBLIME)||g.env.ConEmuTask==="{cmd::Cmder}"||g.env.TERM_PROGRAM==="Terminus-Sublime"||g.env.TERM_PROGRAM==="vscode"||g.env.TERM==="xterm-256color"||g.env.TERM==="alacritty"||g.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var PD={info:"cyan",fail:"red",success:"green",ready:"green",start:"magenta"},kD={0:"red",1:"yellow"},jD=xD(),A=(u,t)=>jD?u:t,P={error:A("✖","×"),fatal:A("✖","×"),ready:A("✔","√"),warn:A("⚠","‼"),info:A("ℹ","i"),success:A("✔","√"),debug:A("⚙","D"),trace:A("→","→"),fail:A("✖","×"),start:A("◐","o"),log:""};function k(u){if(!Intl.Segmenter)return m(u).length;return $D(u)}class H extends w{formatStack(u){return`
|
|
15
|
+
`+j(u).map((t)=>" "+t.replace(/^at +/,(e)=>B.gray(e)).replace(/\((.+)\)/,(e,F)=>`(${B.cyan(F)})`)).join(`
|
|
16
|
+
`)}formatType(u,t,e){let F=PD[u.type]||kD[u.level]||"gray";if(t)return WD(F)(B.black(` ${u.type.toUpperCase()} `));let r=typeof P[u.type]==="string"?P[u.type]:u.icon||u.type;return r?GD(F)(r):""}formatLogObj(u,t){let[e,...F]=this.formatArgs(u.args,t).split(`
|
|
17
|
+
`);if(u.type==="box")return _D(v(e+(F.length>0?`
|
|
18
|
+
`+F.join(`
|
|
19
|
+
`):"")),{title:u.title?v(u.title):void 0,style:u.style});let r=this.formatDate(u.date,t),o=r&&B.gray(r),D=u.badge??u.level<2,E=this.formatType(u,D,t),p=u.tag?B.gray(u.tag):"",l,c=this.filterAndJoin([E,v(e)]),a=this.filterAndJoin(t.columns?[p,o]:[p]),d=(t.columns||0)-k(c)-k(a)-2;if(l=d>0&&(t.columns||0)>=80?c+" ".repeat(d)+a:(a?`${B.gray(`[${a}]`)} `:"")+c,l+=v(F.length>0?`
|
|
20
|
+
`+F.join(`
|
|
21
|
+
`):""),u.type==="trace"){let s=Error("Trace: "+u.message);l+=this.formatStack(s.stack||"")}return D?`
|
|
22
|
+
`+l+`
|
|
23
|
+
`:l}}function v(u){return u.replace(/`([^`]+)`/gm,(t,e)=>B.cyan(e)).replace(/\s+_([^_]+)_\s+/gm,(t,e)=>` ${B.underline(e)} `)}function GD(u="white"){return B[u]||B.white}function WD(u="bgWhite"){return B[`bg${u[0].toUpperCase()}${u.slice(1)}`]||B.bgWhite}function YD(u={}){let t=VD();if(process.env.CONSOLA_LEVEL)t=Number.parseInt(process.env.CONSOLA_LEVEL)??t;return CD({level:t,defaults:{level:t},stdout:process.stdout,stderr:process.stderr,prompt:(...e)=>import("./chunk-pyeywqa0.js").then((F)=>F.prompt(...e)),reporters:u.reporters||[u.fancy??!(LD||Z)?new H:new w],...u})}function VD(){if(TD)return n.debug;if(Z)return n.warn;return n.info}var Du=YD();
|
|
24
|
+
export{zD as v,HD as w,KD as x,B as y,wD as z,xD as A,Du as B};
|