@e2b/cli 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -146
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,172 +1,55 @@
|
|
|
1
1
|
# e2b CLI
|
|
2
|
-
CLI for managing Devbook environments.
|
|
3
|
-
|
|
4
|
-
An environment is a virtual machine image that you can customize through our CLI. You can add files, install dependencies, and set env vars in the environment. Then with Devbook, every user visiting your website will get a new copy of the environment they can use.
|
|
5
|
-
|
|
6
|
-
* [Installation](#installation)
|
|
7
|
-
* [Quickstart](#quickstart)
|
|
8
|
-
* [Commands](#commands)
|
|
9
|
-
+ [`devbook env create`](#devbook-env-create)
|
|
10
|
-
+ [`devbook env push`](#devbook-env-push)
|
|
11
|
-
+ [`devbook env publish`](#devbook-env-publish)
|
|
12
|
-
+ [`devbook env delete`](#devbook-env-delete)
|
|
13
|
-
+ [`devbook env use`](#devbook-env-use)
|
|
14
|
-
+ [`devbook env set`](#devbook-env-set)
|
|
15
|
-
+ [`devbook env connect`](#devbook-env-connect)
|
|
16
|
-
+ [`devbook env list`](#devbook-env-list)
|
|
17
|
-
* [`dbk.toml` config](#dbktoml-config)
|
|
18
|
-
+ [`id`](#id)
|
|
19
|
-
+ [`template`](#template)
|
|
20
|
-
+ [`title`](#title)
|
|
21
|
-
+ [`filesystem.local_root`](#filesystemlocal_root)
|
|
22
|
-
* [FAQ](#faq)
|
|
23
|
-
+ [Inspect how a published environment looks like](#inspect-how-a-published-environment-looks-like)
|
|
24
|
-
+ [Delete files from an environment](#delete-files-from-an-environment)
|
|
25
|
-
+ [Inspect files in an environment](#inspect-files-in-an-environment)
|
|
26
|
-
+ [Install dependencies in an environment](#install-dependencies-in-an-environment)
|
|
27
|
-
+ [Upload local files to an environment](#upload-local-files-to-an-environment)
|
|
28
2
|
|
|
3
|
+
Command line interface for [e2b](https://e2b.dev/).
|
|
29
4
|
|
|
30
5
|
## Installation
|
|
6
|
+
|
|
31
7
|
```sh
|
|
32
|
-
npm install -g @
|
|
8
|
+
npm install -g @e2b/cli
|
|
33
9
|
```
|
|
34
10
|
|
|
35
11
|
Then you can use the CLI with
|
|
12
|
+
|
|
36
13
|
```sh
|
|
37
|
-
|
|
14
|
+
e2b --help
|
|
38
15
|
```
|
|
39
16
|
|
|
40
|
-
You will need
|
|
41
|
-
After you get the API key set the `DEVBOOK_KEY` env var in your terminal, or call the CLI with the env var directly
|
|
17
|
+
You will need to authenticate to use the e2b CLI.
|
|
42
18
|
|
|
43
19
|
```sh
|
|
44
|
-
|
|
20
|
+
e2b login
|
|
45
21
|
```
|
|
46
22
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# Create an environment and a dbk.toml config for the environment
|
|
50
|
-
devbook env create
|
|
51
|
-
|
|
52
|
-
# Create a directory for files you want to be in the environment
|
|
53
|
-
mkdir ./files
|
|
23
|
+
<details>
|
|
24
|
+
<summary>🔜 Authenticate without the ability to open browser</summary>
|
|
54
25
|
|
|
55
|
-
# Upload files from the ./files directory to the environment
|
|
56
|
-
devbook env push
|
|
57
26
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
devbook env connect
|
|
27
|
+
To authenticate without the ability to open browser, you can provide E2B_ACCESS_TOKEN as an environment variable.
|
|
28
|
+
Obtain your E2B_ACCESS_TOKEN from at [e2b.dev/docs](https://e2b.dev/docs).
|
|
61
29
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
# To make all the changes you just made published, call the following command
|
|
65
|
-
devbook env publish
|
|
30
|
+
```sh
|
|
31
|
+
E2B_ACCESS_TOKEN=e2b_sk_... e2b login
|
|
66
32
|
```
|
|
67
33
|
|
|
68
|
-
|
|
69
|
-
By default, commands are referring to an environment defined by a `dbk.toml` in a directory where you called the commands.
|
|
70
|
-
|
|
71
|
-
All commands can be called with a `--path <path-to-dir>` flag that changes the directory where the command will be called, without the need to call `cd`.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
The Devbook CLI has following commands
|
|
75
|
-
|
|
76
|
-
### `devbook env create`
|
|
77
|
-
Create a new environment and `dbk.toml` config.
|
|
78
|
-
|
|
79
|
-
You can specify another environment as a template with `--template <existing-environment-id>` flag. This existing environment will be a base of the new environment — all files, env vars and dependencies from the existing environment will be present in the new environment.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
### `devbook env push`
|
|
83
|
-
Upload files from a local directory to an environment. The local directory to upload from is defined by the `filesystem.local_root` field in the `dbk.toml` config (`./files` by default).
|
|
84
|
-
Path of uploaded files in the environment will reflect their paths in the `./files` directory — file `./files/index.ts` will become `/index.ts` in the environment.
|
|
85
|
-
|
|
86
|
-
> Use `devbook env publish --all` to push all environments in subdirectories.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
### `devbook env publish`
|
|
90
|
-
Publish changes you made in an environment (uploaded files, installed depedencies, set env vars).
|
|
91
|
-
Users on your website that use the environment cannot see the new changes you made to the environment until you run `devbook env publish` command.
|
|
92
|
-
|
|
93
|
-
> Use `devbook env publish --all` to publish all environments in subdirectories.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
### `devbook env delete`
|
|
97
|
-
Delete an environment and a `dbk.toml` config for the environment.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
### `devbook env use`
|
|
101
|
-
Create a `dbk.toml` for an existing environment. You can use this to start version tracking environments created through Devbook dashboard.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
### `devbook env set`
|
|
105
|
-
Set env vars inside of an environment.
|
|
106
|
-
For example, to set `FOO` and `BAR` call `devbook env set FOO=1 BAR=2`.
|
|
107
|
-
|
|
108
|
-
> You must set all env vars in one `devbook env set --env-vars <KEY=VALUE...>` call — variables from the previous `devbook env set` calls will be overwritten.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
### `devbook env connect`
|
|
112
|
-
Open a terminal connected to an environment that you can use to configure and inspect the environment.
|
|
34
|
+
</details>
|
|
113
35
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
### `devbook env list`
|
|
118
|
-
List all environments and paths to their `dbk.toml` configs (if the configs are in subdirectories of the current directory).
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
## `dbk.toml` config
|
|
122
|
-
The `dbk.toml` config is used for tracking an environment in version control. It is created automatically by `devbook env create` command.
|
|
123
|
-
|
|
124
|
-
The following fields are in each `dbk.toml` config
|
|
125
|
-
|
|
126
|
-
### `id`
|
|
127
|
-
You **should not edit this field** manually.
|
|
128
|
-
The id of this environment.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
### `template`
|
|
132
|
-
You **should not edit this field** manually.
|
|
133
|
-
The id of the environment that was used as a template for this environment.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
### `title`
|
|
137
|
-
Title of the environment. The title is used for easier navigation and to distinguish between environments.
|
|
138
|
-
|
|
139
|
-
By default the title is the name of the directory where you called `devbook env create` command.
|
|
140
|
-
You can change this field and use `devbook env push` to save the changes.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
### `filesystem.local_root`
|
|
144
|
-
A directory containing files that will be uploaded with `devbook env push` command.
|
|
145
|
-
By default it is `./files` — that means that the `./files` directory next to this `dbk.toml` will be uploaded to the environment when you use `devbook env push`.
|
|
146
|
-
|
|
147
|
-
For example, if you have a `./files/index.ts` file locally and run `devbook env push` the file `/index.ts` will be created and saved in the environment.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
## FAQ
|
|
151
|
-
|
|
152
|
-
### Inspect how a published environment looks like
|
|
153
|
-
Use `devbook env connect --published` to open a terminal connected to a new instace of the environment.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
### Delete files from an environment
|
|
157
|
-
Use `devbook env connect` to open a terminal connected to the environment. Then you can delete the files from the environment with `rm` shell command.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
### Inspect files in an environment
|
|
161
|
-
Use `devbook env connect` to connect your terminal with the environment then use terminal commands like `ls`, `cd`, `cat`, etc. to inspect files.
|
|
36
|
+
## Commands
|
|
162
37
|
|
|
38
|
+
🔜 All commands can be called with a `--path <path-to-dir>` flag that changes the directory where the command will be called, without the need to call `cd`.
|
|
163
39
|
|
|
164
|
-
|
|
165
|
-
|
|
40
|
+
```
|
|
41
|
+
-V, --version Display e2b CLI version
|
|
42
|
+
-h, --help display help for command
|
|
43
|
+
```
|
|
166
44
|
|
|
167
|
-
|
|
45
|
+
```
|
|
46
|
+
help [command] display help for command
|
|
168
47
|
|
|
48
|
+
login Login to e2b
|
|
49
|
+
logout Logout of e2b
|
|
169
50
|
|
|
170
|
-
|
|
171
|
-
Create
|
|
172
|
-
|
|
51
|
+
env|environment Manage e2b environments
|
|
52
|
+
create|cr [options] Create new environment and e2b.json config
|
|
53
|
+
list|ls List environments
|
|
54
|
+
shell|cn [options] [id] Connect terminal to environment
|
|
55
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -79,7 +79,7 @@ Content-Type: ${n.type||"application/octet-stream"}\r
|
|
|
79
79
|
`);return n!==-1&&(e=c4(e,i,a,n)),a+e+i};Object.defineProperties(In.prototype,ui);var $E=In(),EY=In({level:h4?h4.level:0});var nr=$E;o();var Bc=M(r3()),mt=M(require("path")),Pc=M(require("util"));var qr=M(require("fs")),Ic=M(m3()),Lc=M(D3()),kc=M(Nc()),yx=Pc.promisify(Bc.walk);async function Vc(t,e){let r;if(e!=null&&e.respectGitignore){let n=mt.join(t,".gitignore");qr.existsSync(n)&&(r=(0,Ic.default)().add(qr.readFileSync(n).toString()))}let a;if(e!=null&&e.respectDockerignore){let n=mt.join(t,".dockerignore");if(qr.existsSync(n)){let l=qr.readFileSync(n,"utf-8").split(`
|
|
80
80
|
`).map(u=>u.trim());a=(0,Lc.default)().add(l)}}let i=await yx(t,{entryFilter:n=>{var p;return[!!((p=n.stats)!=null&&p.isFile()),e!=null&&e.extension?n.name.endsWith(e.extension):!0,e!=null&&e.name?n.name===e.name:!0,!(r&&r.ignores(mt.relative(t,n.path))),!(a&&a.ignores(mt.relative(t,n.path)))].every(Boolean)},stats:!0});return await Promise.all(i.map(async n=>({path:n.path,rootPath:mt.join("/",mt.relative(t,n.path)),name:n.name})))}function ho(t){let e=process.cwd();return t?mt.isAbsolute(t)?t:mt.resolve(e,t):e}function qc(t){return mt.relative(process.cwd(),t)}var Mc=(t,e,r)=>new Promise((a,i)=>{kc.default.pack(t,{entries:e}).pipe(qr.createWriteStream(r)).on("error",i).on("finish",a)});function Kn(t,e){let r=He(t.id),a=t.template?Cx` [${t.template}]`:"",i=t.title?` ${t.title}`:"",n=e?Ex(" <-> ")+Qn(e):"";return`${r}${a}${i}${n}`}function Mr(t,e){return nr.redBright(`> ${t} ${e?`:
|
|
81
81
|
`+e:""}
|
|
82
|
-
`)}function Ex(t){return nr.dim(t)}function He(t){return nr.bold(t)}function Cx(t,e){return nr.dim(t[0]+e+t[1])}function Do(t){return nr.blue(t)}function Qn(t){return t?Do("./"+qc(t)):""}o();var df=M(nf()),uf=M(of());var ul=M(require("path")),lf=M(require("os")),Sa=M(require("fs")),mf=M(require("http"));var ol={};$p(ol,{author:()=>Gx,bin:()=>tA,bugs:()=>Yx,default:()=>dl,dependencies:()=>rA,description:()=>jx,devDependencies:()=>Xx,engines:()=>aA,files:()=>eA,homepage:()=>Wx,license:()=>zx,name:()=>Hx,publishConfig:()=>Qx,repository:()=>Kx,scripts:()=>Jx,sideEffects:()=>Zx,version:()=>pl});var Hx="@e2b/cli",pl="0.0.
|
|
82
|
+
`)}function Ex(t){return nr.dim(t)}function He(t){return nr.bold(t)}function Cx(t,e){return nr.dim(t[0]+e+t[1])}function Do(t){return nr.blue(t)}function Qn(t){return t?Do("./"+qc(t)):""}o();var df=M(nf()),uf=M(of());var ul=M(require("path")),lf=M(require("os")),Sa=M(require("fs")),mf=M(require("http"));var ol={};$p(ol,{author:()=>Gx,bin:()=>tA,bugs:()=>Yx,default:()=>dl,dependencies:()=>rA,description:()=>jx,devDependencies:()=>Xx,engines:()=>aA,files:()=>eA,homepage:()=>Wx,license:()=>zx,name:()=>Hx,publishConfig:()=>Qx,repository:()=>Kx,scripts:()=>Jx,sideEffects:()=>Zx,version:()=>pl});var Hx="@e2b/cli",pl="0.0.8",jx="CLI for managing e2b environments",Wx="https://usedevbook.com",zx="SEE LICENSE IN LICENSE",Gx={name:"FoundryLabs, Inc.",email:"hello@e2b.dev",url:"https://e2b.dev"},Yx="https://github.com/e2b-dev/e2b/issues",Kx={type:"git",url:"https://github.com/e2b-dev/e2b/tree/main/packages/cli"},Qx={access:"public"},Zx=!1,Jx={prepublishOnly:"pnpm build",build:"rm -rf ./dist && tsup --minify",dev:"tsup --watch",fix:"npx eslint **/src/**/*.{ts,js} --fix",format:"prettier --check --ignore-path .gitignore .","format:fix":"prettier --write --ignore-path .gitignore ."},Xx={"@trivago/prettier-plugin-sort-imports":"^3.3.0","@types/common-tags":"^1.8.2","@types/inquirer":"^8.0.0","@types/node":"16.11","@types/node-fetch":"^2.6.5","@types/parse-gitignore":"^1.0.0","@types/update-notifier":"5.1.0","@typescript-eslint/eslint-plugin":"^5.38.1","@typescript-eslint/parser":"^5.38.1",eslint:"^8.24.0","eslint-config-prettier":"^8.5.0","eslint-plugin-prettier":"^4.2.1","eslint-plugin-unused-imports":"^2.0.0",prettier:"^2.7.1",tsup:"^6.5.0",typescript:"^4.9.3"},eA=["dist","LICENSE","README","package.json"],tA={e2b:"dist/index.js"},rA={"@balena/dockerignore":"^1.0.2","@devbookhq/sdk":"^2.6.88","@iarna/toml":"^2.2.5","@nodelib/fs.walk":"^1.2.8","@types/tar-fs":"^2.0.2","async-listen":"^3.0.1",boxen:"^7.0.0",chalk:"^5.1.2",chokidar:"^3.5.3",commander:"^9.4.1","common-tags":"^1.8.2","docker-names":"^1.2.1","get-port":"^7.0.0",ignore:"^5.2.4",inquirer:"^8.0.0","node-fetch":"^3.3.2",open:"^8.4.2","parse-gitignore":"^2.0.0","tar-fs":"^3.0.4","update-notifier":"5.1.0",yup:"^0.32.11"},aA={node:">=16"},dl={name:Hx,version:pl,description:jx,homepage:Wx,license:zx,author:Gx,bugs:Yx,repository:Kx,publishConfig:Qx,sideEffects:Zx,scripts:Jx,devDependencies:Xx,files:eA,bin:tA,dependencies:rA,engines:aA};var Ei=ul.default.join(lf.homedir(),".e2b","config.json"),pf=process.env.E2B_DOCS_BASE||"https://e2b.dev/docs",cf=new ot("login").description("Login to e2b").action(async()=>{let t;try{t=wo()}catch(e){console.error(Mr("Failed to read user config",e))}if(t){console.log(`Already logged in as ${He(t.email)}, if you want to login as a different user, logout first.`);return}else if(!t){if(console.log("Attempting to login..."),t=await iA(),!t){console.info("Login aborted");return}Sa.default.mkdirSync(ul.default.dirname(Ei),{recursive:!0}),Sa.default.writeFileSync(Ei,JSON.stringify(t,null,2))}console.log(`Logged in as ${He(t.email)}`),process.exit(0)}),ff=new ot("logout").description("Logout of e2b").action(()=>{Sa.default.existsSync(Ei)?(Sa.default.unlinkSync(Ei),console.log("Logged out.")):console.log("Not logged in, nothing to do")});function wo(){return Sa.default.existsSync(Ei)?JSON.parse(Sa.default.readFileSync(Ei,"utf8")):null}async function iA(){let t=mf.default.createServer(),{port:e}=await(0,uf.listen)(t,0,"127.0.0.1"),r=new URL(`${pf}/api/cli`);return r.searchParams.set("next",`http://localhost:${e}`),r.searchParams.set("cliVersion",dl.version),new Promise((a,i)=>(t.once("request",(n,p)=>{p.setHeader("connection","close");let l=new URL(`${pf}/api/cli`),u=new URL(n.url||"/","http://localhost").searchParams,m=Object.fromEntries(u.entries()),{error:f}=m;f?(i(new Error(f)),l.searchParams.set("state","error"),l.searchParams.set("error",f)):(a(m),l.searchParams.set("state","success"),l.searchParams.set("email",m.email)),p.statusCode=302,p.setHeader("location",l.href),p.end()}),(0,df.default)(r.toString())))}var hf="https://ondevbook.com",Fa=process.env.E2B_API_BASE??hf,yo=process.env.E2B_API_KEY,Eo=process.env.E2B_ACCESS_TOKEN;Fa!==hf&&console.warn(`
|
|
83
83
|
Beware: Using custom API base URL: ${He(Fa)}
|
|
84
84
|
`);var Df=Td(`You must be logged in to use this command. Run ${He("e2b login")}.`,{width:70,float:"center",padding:.5,margin:1,borderStyle:"round",borderColor:"redBright"});function gf(){if(!yo){let t=wo();yo=t==null?void 0:t.defaultTeamApiKey}if(!yo)console.error(Df),process.exit(1);else return yo}function Co(){if(!Eo){let t=wo();Eo=t==null?void 0:t.accessToken}if(!Eo)console.error(Df),process.exit(1);else return Eo}o();o();o();o();o();var ll;try{ll=Map}catch{}var ml;try{ml=Set}catch{}function _f(t,e,r){if(!t||typeof t!="object"||typeof t=="function")return t;if(t.nodeType&&"cloneNode"in t)return t.cloneNode(!0);if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return new RegExp(t);if(Array.isArray(t))return t.map(Jn);if(ll&&t instanceof ll)return new Map(Array.from(t.entries()));if(ml&&t instanceof ml)return new Set(Array.from(t.values()));if(t instanceof Object){e.push(t);var a=Object.create(t);r.push(a);for(var i in t){var n=e.findIndex(function(p){return p===t[i]});a[i]=n>-1?r[n]:_f(t[i],e,r)}return a}return t}function Jn(t){return _f(t,[],[])}o();o();var nA=Object.prototype.toString,sA=Error.prototype.toString,oA=RegExp.prototype.toString,pA=typeof Symbol<"u"?Symbol.prototype.toString:()=>"",dA=/^Symbol\((.*)\)(.*)$/;function uA(t){return t!=+t?"NaN":t===0&&1/t<0?"-0":""+t}function vf(t,e=!1){if(t==null||t===!0||t===!1)return""+t;let r=typeof t;if(r==="number")return uA(t);if(r==="string")return e?`"${t}"`:t;if(r==="function")return"[Function "+(t.name||"anonymous")+"]";if(r==="symbol")return pA.call(t).replace(dA,"Symbol($1)");let a=nA.call(t).slice(8,-1);return a==="Date"?isNaN(t.getTime())?""+t:t.toISOString(t):a==="Error"||t instanceof Error?"["+sA.call(t)+"]":a==="RegExp"?oA.call(t):null}function It(t,e){let r=vf(t,e);return r!==null?r:JSON.stringify(t,function(a,i){let n=vf(this[a],e);return n!==null?n:i},2)}var Ur={default:"${path} is invalid",required:"${path} is a required field",oneOf:"${path} must be one of the following values: ${values}",notOneOf:"${path} must not be one of the following values: ${values}",notType:({path:t,type:e,value:r,originalValue:a})=>{let i=a!=null&&a!==r,n=`${t} must be a \`${e}\` type, but the final value was: \`${It(r,!0)}\``+(i?` (cast from the value \`${It(a,!0)}\`).`:".");return r===null&&(n+='\n If "null" is intended as an empty value be sure to mark the schema as `.nullable()`'),n},defined:"${path} must be defined"},yt={length:"${path} must be exactly ${length} characters",min:"${path} must be at least ${min} characters",max:"${path} must be at most ${max} characters",matches:'${path} must match the following: "${regex}"',email:"${path} must be a valid email",url:"${path} must be a valid URL",uuid:"${path} must be a valid UUID",trim:"${path} must be a trimmed string",lowercase:"${path} must be a lowercase string",uppercase:"${path} must be a upper case string"},pr={min:"${path} must be greater than or equal to ${min}",max:"${path} must be less than or equal to ${max}",lessThan:"${path} must be less than ${less}",moreThan:"${path} must be greater than ${more}",positive:"${path} must be a positive number",negative:"${path} must be a negative number",integer:"${path} must be an integer"},So={min:"${path} field must be later than ${min}",max:"${path} field must be at earlier than ${max}"},Fo={isValue:"${path} field must be ${value}"},xo={noUnknown:"${path} field has unspecified keys: ${unknown}"},Xn={min:"${path} field must have at least ${min} items",max:"${path} field must have less than or equal to ${max} items",length:"${path} must have ${length} items"},lA=Object.assign(Object.create(null),{mixed:Ur,string:yt,number:pr,date:So,object:xo,array:Xn,boolean:Fo});o();var c9=M(Po());o();var vO=t=>t&&t.__isYupSchema__,Hr=vO;var El=class{constructor(e,r){if(this.fn=void 0,this.refs=e,this.refs=e,typeof r=="function"){this.fn=r;return}if(!(0,c9.default)(r,"is"))throw new TypeError("`is:` is required for `when()` conditions");if(!r.then&&!r.otherwise)throw new TypeError("either `then:` or `otherwise:` is required for `when()` conditions");let{is:a,then:i,otherwise:n}=r,p=typeof a=="function"?a:(...l)=>l.every(u=>u===a);this.fn=function(...l){let u=l.pop(),m=l.pop(),f=p(...l)?i:n;if(f)return typeof f=="function"?f(m):m.concat(f.resolve(u))}}resolve(e,r){let a=this.refs.map(n=>n.getValue(r==null?void 0:r.value,r==null?void 0:r.parent,r==null?void 0:r.context)),i=this.fn.apply(e,a.concat(e,r));if(i===void 0||i===e)return e;if(!Hr(i))throw new TypeError("conditions must return a schema object");return i.resolve(r)}},f9=El;o();o();o();function os(t){return t==null?[]:[].concat(t)}function Cl(){return Cl=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(t[a]=r[a])}return t},Cl.apply(this,arguments)}var bO=/\$\{\s*(\w+)\s*\}/g,we=class extends Error{static formatError(e,r){let a=r.label||r.path||"this";return a!==r.path&&(r=Cl({},r,{path:a})),typeof e=="string"?e.replace(bO,(i,n)=>It(r[n])):typeof e=="function"?e(r):e}static isError(e){return e&&e.name==="ValidationError"}constructor(e,r,a,i){super(),this.value=void 0,this.path=void 0,this.type=void 0,this.errors=void 0,this.params=void 0,this.inner=void 0,this.name="ValidationError",this.value=r,this.path=a,this.type=i,this.errors=[],this.inner=[],os(e).forEach(n=>{we.isError(n)?(this.errors.push(...n.errors),this.inner=this.inner.concat(n.inner.length?n.inner:n)):this.errors.push(n)}),this.message=this.errors.length>1?`${this.errors.length} errors occurred`:this.errors[0],Error.captureStackTrace&&Error.captureStackTrace(this,we)}};var wO=t=>{let e=!1;return(...r)=>{e||(e=!0,t(...r))}};function jr(t,e){let{endEarly:r,tests:a,args:i,value:n,errors:p,sort:l,path:u}=t,m=wO(e),f=a.length,g=[];if(p=p||[],!f)return p.length?m(new we(p,n,u)):m(null,n);for(let D=0;D<a.length;D++){let v=a[D];v(i,function(S){if(S){if(!we.isError(S))return m(S,n);if(r)return S.value=n,m(S,n);g.push(S)}if(--f<=0){if(g.length&&(l&&g.sort(l),p.length&&g.push(...p),p=g),p.length){m(new we(p,n,u),n);return}m(null,n)}})}}o();var e7=M(jl());o();var Xh=M(ls()),Vo={context:"$",value:"."};var je=class{constructor(e,r={}){if(this.key=void 0,this.isContext=void 0,this.isValue=void 0,this.isSibling=void 0,this.path=void 0,this.getter=void 0,this.map=void 0,typeof e!="string")throw new TypeError("ref must be a string, got: "+e);if(this.key=e.trim(),e==="")throw new TypeError("ref must be a non-empty string");this.isContext=this.key[0]===Vo.context,this.isValue=this.key[0]===Vo.value,this.isSibling=!this.isContext&&!this.isValue;let a=this.isContext?Vo.context:this.isValue?Vo.value:"";this.path=this.key.slice(a.length),this.getter=this.path&&(0,Xh.getter)(this.path,!0),this.map=r.map}getValue(e,r,a){let i=this.isContext?a:this.isValue?e:r;return this.getter&&(i=this.getter(i||{})),this.map&&(i=this.map(i)),i}cast(e,r){return this.getValue(e,r==null?void 0:r.parent,r==null?void 0:r.context)}resolve(){return this}describe(){return{type:"ref",key:this.key}}toString(){return`Ref(${this.key})`}static isRef(e){return e&&e.__isYupRef}};je.prototype.__isYupRef=!0;function qo(){return qo=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(t[a]=r[a])}return t},qo.apply(this,arguments)}function UI(t,e){if(t==null)return{};var r={},a=Object.keys(t),i,n;for(n=0;n<a.length;n++)i=a[n],!(e.indexOf(i)>=0)&&(r[i]=t[i]);return r}function Pi(t){function e(r,a){let{value:i,path:n="",label:p,options:l,originalValue:u,sync:m}=r,f=UI(r,["value","path","label","options","originalValue","sync"]),{name:g,test:D,params:v,message:b}=t,{parent:S,context:x}=l;function R(F){return je.isRef(F)?F.getValue(i,S,x):F}function I(F={}){let B=(0,e7.default)(qo({value:i,originalValue:u,label:p,path:F.path||n},v,F.params),R),E=new we(we.formatError(F.message||b,B),i,B.path,F.type||g);return E.params=B,E}let L=qo({path:n,parent:S,type:g,createError:I,resolve:R,options:l,originalValue:u},f);if(!m){try{Promise.resolve(D.call(L,i,L)).then(F=>{we.isError(F)?a(F):F?a(null,F):a(I())}).catch(a)}catch(F){a(F)}return}let C;try{var A;if(C=D.call(L,i,L),typeof((A=C)==null?void 0:A.then)=="function")throw new Error(`Validation test of type: "${L.type}" returned a Promise during a synchronous validate. This test will finish after the validate call has returned`)}catch(F){a(F);return}we.isError(C)?a(C):C?a(null,C):a(I())}return e.OPTIONS=t,e}o();var t7=M(ls()),$I=t=>t.substr(0,t.length-1).substr(1);function r7(t,e,r,a=r){let i,n,p;return e?((0,t7.forEach)(e,(l,u,m)=>{let f=u?$I(l):l;if(t=t.resolve({context:a,parent:i,value:r}),t.innerType){let g=m?parseInt(f,10):0;if(r&&g>=r.length)throw new Error(`Yup.reach cannot resolve an array item at index: ${l}, in the path: ${e}. because there is no value at that index. `);i=r,r=r&&r[g],t=t.innerType}if(!m){if(!t.fields||!t.fields[f])throw new Error(`The schema does not contain the path: ${e}. (failed at: ${p} which is a type: "${t._type}")`);i=r,r=r&&r[f],t=t.fields[f]}n=f,p=u?"["+l+"]":"."+l}),{schema:t,parent:i,parentPath:n}):{parent:i,parentPath:e,schema:t}}o();var Wr=class{constructor(){this.list=void 0,this.refs=void 0,this.list=new Set,this.refs=new Map}get size(){return this.list.size+this.refs.size}describe(){let e=[];for(let r of this.list)e.push(r);for(let[,r]of this.refs)e.push(r.describe());return e}toArray(){return Array.from(this.list).concat(Array.from(this.refs.values()))}resolveAll(e){return this.toArray().reduce((r,a)=>r.concat(je.isRef(a)?e(a):a),[])}add(e){je.isRef(e)?this.refs.set(e.key,e):this.list.add(e)}delete(e){je.isRef(e)?this.refs.delete(e.key):this.list.delete(e)}clone(){let e=new Wr;return e.list=new Set(this.list),e.refs=new Map(this.refs),e}merge(e,r){let a=this.clone();return e.list.forEach(i=>a.add(i)),e.refs.forEach(i=>a.add(i)),r.list.forEach(i=>a.delete(i)),r.refs.forEach(i=>a.delete(i)),a}};function Et(){return Et=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(t[a]=r[a])}return t},Et.apply(this,arguments)}var ne=class{constructor(e){this.deps=[],this.tests=void 0,this.transforms=void 0,this.conditions=[],this._mutate=void 0,this._typeError=void 0,this._whitelist=new Wr,this._blacklist=new Wr,this.exclusiveTests=Object.create(null),this.spec=void 0,this.tests=[],this.transforms=[],this.withMutation(()=>{this.typeError(Ur.notType)}),this.type=(e==null?void 0:e.type)||"mixed",this.spec=Et({strip:!1,strict:!1,abortEarly:!0,recursive:!0,nullable:!1,presence:"optional"},e==null?void 0:e.spec)}get _type(){return this.type}_typeCheck(e){return!0}clone(e){if(this._mutate)return e&&Object.assign(this.spec,e),this;let r=Object.create(Object.getPrototypeOf(this));return r.type=this.type,r._typeError=this._typeError,r._whitelistError=this._whitelistError,r._blacklistError=this._blacklistError,r._whitelist=this._whitelist.clone(),r._blacklist=this._blacklist.clone(),r.exclusiveTests=Et({},this.exclusiveTests),r.deps=[...this.deps],r.conditions=[...this.conditions],r.tests=[...this.tests],r.transforms=[...this.transforms],r.spec=Jn(Et({},this.spec,e)),r}label(e){let r=this.clone();return r.spec.label=e,r}meta(...e){if(e.length===0)return this.spec.meta;let r=this.clone();return r.spec.meta=Object.assign(r.spec.meta||{},e[0]),r}withMutation(e){let r=this._mutate;this._mutate=!0;let a=e(this);return this._mutate=r,a}concat(e){if(!e||e===this)return this;if(e.type!==this.type&&this.type!=="mixed")throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${e.type}`);let r=this,a=e.clone(),i=Et({},r.spec,a.spec);return a.spec=i,a._typeError||(a._typeError=r._typeError),a._whitelistError||(a._whitelistError=r._whitelistError),a._blacklistError||(a._blacklistError=r._blacklistError),a._whitelist=r._whitelist.merge(e._whitelist,e._blacklist),a._blacklist=r._blacklist.merge(e._blacklist,e._whitelist),a.tests=r.tests,a.exclusiveTests=r.exclusiveTests,a.withMutation(n=>{e.tests.forEach(p=>{n.test(p.OPTIONS)})}),a.transforms=[...r.transforms,...a.transforms],a}isType(e){return this.spec.nullable&&e===null?!0:this._typeCheck(e)}resolve(e){let r=this;if(r.conditions.length){let a=r.conditions;r=r.clone(),r.conditions=[],r=a.reduce((i,n)=>n.resolve(i,e),r),r=r.resolve(e)}return r}cast(e,r={}){let a=this.resolve(Et({value:e},r)),i=a._cast(e,r);if(e!==void 0&&r.assert!==!1&&a.isType(i)!==!0){let n=It(e),p=It(i);throw new TypeError(`The value of ${r.path||"field"} could not be cast to a value that satisfies the schema type: "${a._type}".
|
|
85
85
|
|